Unverified Commit 34aab179 authored by zyno42's avatar zyno42
Browse files

Fix `libtapasco` for `snafu` crate version bump to 0.7.0

From `snafu-upgrade-assistant`:
In SNAFU 0.7, generated context selectors now have the Snafu suffix to help de-mystify the generated code.

From SNAFU's Changelog:
- Generated context selectors now have the suffix Snafu. This is a breaking change.
- Minimum supported version of Rust is now 1.34.
parent c7784931
......@@ -488,7 +488,7 @@ impl Allocator for DriverAllocator {
sz: 0,
dev_addr: ptr,
};
unsafe { tlkm_ioctl_free(self.tlkm_file.as_raw_fd(), &mut cmd).context(IOCTLFree)? };
unsafe { tlkm_ioctl_free(self.tlkm_file.as_raw_fd(), &mut cmd).context(IOCTLFreeSnafu)? };
Ok(())
}
}
......
......@@ -276,10 +276,10 @@ impl Device {
"{}{:02}",
settings
.get_str("tlkm.device_driver_file")
.context(ConfigError)?,
.context(ConfigSnafu)?,
id
))
.context(DeviceUnavailable { id })?,
.context(DeviceUnavailableSnafu { id })?,
);
trace!("Mapping status core.");
......@@ -289,7 +289,7 @@ impl Device {
.len(8192)
.offset(0)
.map(&tlkm_dma_file)
.context(DeviceUnavailable { id })?
.context(DeviceUnavailableSnafu { id })?
};
trace!("Mapped status core: {}", mmap[0]);
......@@ -302,7 +302,7 @@ impl Device {
mmap_cpy[i] = mmap[i];
}
status::Status::decode_length_delimited(&mmap_cpy[..]).context(StatusCoreDecoding)?
status::Status::decode_length_delimited(&mmap_cpy[..]).context(StatusCoreDecodingSnafu)?
};
trace!("Status core decoded: {:?}", s);
......@@ -321,7 +321,7 @@ impl Device {
.len(platform_size as usize)
.offset(8192)
.map_mut(&tlkm_dma_file)
.context(DeviceUnavailable { id })?
.context(DeviceUnavailableSnafu { id })?
});
let arch_size = match &s.arch_base {
......@@ -336,7 +336,7 @@ impl Device {
.len(arch_size as usize)
.offset(4096)
.map_mut(&tlkm_dma_file)
.context(DeviceUnavailable { id })?
.context(DeviceUnavailableSnafu { id })?
});
// Initialize the global memories.
......@@ -385,7 +385,7 @@ impl Device {
allocator.push(Arc::new(OffchipMemory {
allocator: Mutex::new(Box::new(
GenericAllocator::new(0, 4 * 1024 * 1024 * 1024, 64).context(AllocatorError)?,
GenericAllocator::new(0, 4 * 1024 * 1024 * 1024, 64).context(AllocatorSnafu)?,
)),
dma: Box::new(
UserSpaceDMA::new(
......@@ -396,18 +396,18 @@ impl Device {
&platform,
settings
.get::<usize>("dma.read_buffer_size")
.context(ConfigError)?,
.context(ConfigSnafu)?,
settings
.get::<usize>("dma.read_buffers")
.context(ConfigError)?,
.context(ConfigSnafu)?,
settings
.get::<usize>("dma.write_buffer_size")
.context(ConfigError)?,
.context(ConfigSnafu)?,
settings
.get::<usize>("dma.write_buffers")
.context(ConfigError)?,
.context(ConfigSnafu)?,
)
.context(DMAError)?,
.context(DMASnafu)?,
),
}));
} else {
......@@ -419,7 +419,7 @@ impl Device {
tlkm_ioctl_svm_launch(
tlkm_dma_file.as_raw_fd(),
&mut init_cmd,
).context(SVMInitError)?;
).context(SVMInitSnafu)?;
}
allocator.push(Arc::new(OffchipMemory {
allocator: Mutex::new(Box::new(DummyAllocator::new())),
......@@ -430,18 +430,18 @@ impl Device {
info!("Using driver allocation for Zynq/ZynqMP based platform.");
allocator.push(Arc::new(OffchipMemory {
allocator: Mutex::new(Box::new(
DriverAllocator::new(&tlkm_dma_file).context(AllocatorError)?,
DriverAllocator::new(&tlkm_dma_file).context(AllocatorSnafu)?,
)),
dma: Box::new(DriverDMA::new(&tlkm_dma_file)),
}));
} else if name == "zynqmp" {
info!("Using VFIO mode for ZynqMP based platform.");
let vfio_dev = Arc::new(init_vfio(settings)
.context(VfioInitError)?
.context(VfioInitSnafu)?
);
allocator.push(Arc::new(OffchipMemory {
allocator: Mutex::new(Box::new(
VfioAllocator::new(&vfio_dev).context(AllocatorError)?,
VfioAllocator::new(&vfio_dev).context(AllocatorSnafu)?,
)),
dma: Box::new(VfioDMA::new(&vfio_dev)),
}));
......@@ -457,7 +457,7 @@ impl Device {
Some(l) => {
pe_local_memories.push_back(Arc::new(OffchipMemory {
allocator: Mutex::new(Box::new(
GenericAllocator::new(0, l.size, 1).context(AllocatorError)?,
GenericAllocator::new(0, l.size, 1).context(AllocatorSnafu)?,
)),
dma: Box::new(DirectDMA::new(l.base, l.size, arch.clone())),
}));
......@@ -480,7 +480,7 @@ impl Device {
is_pcie,
svm_in_use,
)
.context(SchedulerError)?,
.context(SchedulerSnafu)?,
);
trace!("Device creation completed.");
......@@ -514,7 +514,7 @@ impl Device {
pub fn acquire_pe(&self, id: PEId) -> Result<Job> {
self.check_exclusive_access()?;
trace!("Trying to acquire PE of type {}.", id);
let pe = self.scheduler.acquire_pe(id).context(SchedulerError)?;
let pe = self.scheduler.acquire_pe(id).context(SchedulerSnafu)?;
trace!("Successfully acquired PE of type {}.", id);
Ok(Job::new(pe, &self.scheduler))
}
......@@ -569,7 +569,7 @@ impl Device {
trace!("Device {}: Trying to change mode to {:?}", self.id, access,);
unsafe {
tlkm_ioctl_create(self.tlkm_file.as_raw_fd(), &mut request).context(IOCTLCreate {
tlkm_ioctl_create(self.tlkm_file.as_raw_fd(), &mut request).context(IOCTLCreateSnafu {
access,
id: self.id,
})?;
......@@ -579,7 +579,7 @@ impl Device {
if access == tlkm_access::TlkmAccessExclusive {
trace!("Access changed to exclusive, resetting all interrupts.");
self.scheduler.reset_interrupts().context(SchedulerError)?;
self.scheduler.reset_interrupts().context(SchedulerSnafu)?;
}
trace!("Successfully acquired access.");
......@@ -596,7 +596,7 @@ impl Device {
};
unsafe {
tlkm_ioctl_destroy(self.tlkm_file.as_raw_fd(), &mut request)
.context(IOCTLDestroy { id: self.id })?;
.context(IOCTLDestroySnafu { id: self.id })?;
}
self.access = tlkm_access::TlkmAccessTypes;
}
......@@ -663,7 +663,7 @@ impl Device {
/// Return the PEId of the PE with the given name
pub fn get_pe_id(&self, name: &str) -> Result<PEId> {
self.scheduler.get_pe_id(name).context(SchedulerError)
self.scheduler.get_pe_id(name).context(SchedulerSnafu)
}
/// Get a list of platform components names available on this device
......
......@@ -119,7 +119,7 @@ impl DMAControl for DriverDMA {
user_addr: data.as_ptr(),
},
)
.context(DMAToDevice)?;
.context(DMAToDeviceSnafu)?;
};
Ok(())
}
......@@ -140,7 +140,7 @@ impl DMAControl for DriverDMA {
user_addr: data.as_mut_ptr(),
},
)
.context(DMAFromDevice)?;
.context(DMAFromDeviceSnafu)?;
};
Ok(())
}
......@@ -175,7 +175,7 @@ impl DMAControl for VfioDMA {
let iova_start = to_page_boundary(iova);
let map_len = self.vfio_dev
.get_region_size(iova_start)
.context(VfioError)?;
.context(VfioSnafu)?;
trace!(
"Copy Host({:?}) -> Device(0x{:x}) ({} Bytes). Map va=0x{:x} -> iova=0x{:x} len=0x{:x}",
......@@ -306,7 +306,7 @@ impl DMAControl for SVMDMA {
vaddr: base,
size,
},
).context(DMAToDevice)?;
).context(DMAToDeviceSnafu)?;
}
trace!("Migration to device memory complete.");
Ok(())
......@@ -323,7 +323,7 @@ impl DMAControl for SVMDMA {
vaddr: base,
size,
},
).context(DMAFromDevice)?;
).context(DMAFromDeviceSnafu)?;
}
trace!("Migration to host memory complete.");
Ok(())
......
......@@ -20,11 +20,11 @@
use crate::device::DeviceAddress;
use crate::device::DeviceSize;
use crate::dma::DMABufferAllocate;
use crate::dma::DMABufferAllocateSnafu;
use crate::dma::DMAControl;
use crate::dma::Error;
use crate::dma::ErrorInterrupt;
use crate::dma::FailedMMapDMA;
use crate::dma::ErrorInterruptSnafu;
use crate::dma::FailedMMapDMASnafu;
use crate::interrupt::Interrupt;
use crate::tlkm::tlkm_dma_buffer_allocate;
use crate::tlkm::tlkm_dma_buffer_op;
......@@ -121,7 +121,7 @@ impl UserSpaceDMA {
};
unsafe {
tlkm_ioctl_dma_buffer_allocate(tlkm_file.as_raw_fd(), &mut to_dev_buf)
.context(DMABufferAllocate)?;
.context(DMABufferAllocateSnafu)?;
};
trace!("Retrieved {:?} for to_dev_buffer.", to_dev_buf);
......@@ -135,7 +135,7 @@ impl UserSpaceDMA {
.len(write_buf_size)
.offset(((4 + to_dev_buf.buffer_id) * 4096) as u64)
.map_mut(tlkm_file)
.context(FailedMMapDMA)?
.context(FailedMMapDMASnafu)?
},
});
}
......@@ -149,7 +149,7 @@ impl UserSpaceDMA {
};
unsafe {
tlkm_ioctl_dma_buffer_allocate(tlkm_file.as_raw_fd(), &mut from_dev_buf)
.context(DMABufferAllocate)?;
.context(DMABufferAllocateSnafu)?;
};
trace!("Retrieved {:?} for from_dev_buffer.", from_dev_buf);
......@@ -163,7 +163,7 @@ impl UserSpaceDMA {
.len(read_buf_size)
.offset(((4 + from_dev_buf.buffer_id) * 4096) as u64)
.map_mut(tlkm_file)
.context(FailedMMapDMA)?
.context(FailedMMapDMASnafu)?
},
});
}
......@@ -174,8 +174,8 @@ impl UserSpaceDMA {
engine_offset: offset,
to_dev_buffer: write_map,
from_dev_buffer: read_map,
read_int: Interrupt::new(tlkm_file, read_interrupt, false).context(ErrorInterrupt)?,
write_int: Interrupt::new(tlkm_file, write_interrupt, false).context(ErrorInterrupt)?,
read_int: Interrupt::new(tlkm_file, read_interrupt, false).context(ErrorInterruptSnafu)?,
write_int: Interrupt::new(tlkm_file, write_interrupt, false).context(ErrorInterruptSnafu)?,
write_out: Queue::new(),
write_cntr: AtomicU64::new(0),
write_int_cntr: AtomicU64::new(0),
......@@ -228,7 +228,7 @@ impl UserSpaceDMA {
let n = self
.write_int
.check_for_interrupt()
.context(ErrorInterrupt)?;
.context(ErrorInterruptSnafu)?;
for _ in 0..n {
self.write_int_cntr.fetch_add(1, Ordering::Relaxed);
match self.write_out.pop() {
......@@ -250,7 +250,7 @@ impl UserSpaceDMA {
let n = self
.read_int
.check_for_interrupt()
.context(ErrorInterrupt)?;
.context(ErrorInterruptSnafu)?;
self.read_int_cntr.fetch_add(n, Ordering::Relaxed);
Ok(())
......@@ -269,7 +269,7 @@ impl UserSpaceDMA {
self.tlkm_file.as_raw_fd(),
&mut tlkm_dma_buffer_op { buffer_id: buf.id },
)
.context(DMABufferAllocate)?;
.context(DMABufferAllocateSnafu)?;
};
data[offset..offset + btt].copy_from_slice(&buf.mapped[0..btt]);
......@@ -333,7 +333,7 @@ impl DMAControl for UserSpaceDMA {
buffer_id: buffer.id,
},
)
.context(DMABufferAllocate)?;
.context(DMABufferAllocateSnafu)?;
};
buffer.mapped[0..btt_this].copy_from_slice(&data[ptr_buffer..ptr_buffer + btt_this]);
......@@ -345,7 +345,7 @@ impl DMAControl for UserSpaceDMA {
buffer_id: buffer.id,
},
)
.context(DMABufferAllocate)?;
.context(DMABufferAllocateSnafu)?;
};
{
......@@ -407,7 +407,7 @@ impl DMAControl for UserSpaceDMA {
buffer_id: buffer.id,
},
)
.context(DMABufferAllocate)?;
.context(DMABufferAllocateSnafu)?;
};
let cntr = {
......
......@@ -172,7 +172,7 @@ pub extern "C" fn tapasco_init_logging() {
// Generates a new driver access which can be used to query verison information and devices
#[no_mangle]
pub extern "C" fn tapasco_tlkm_new() -> *mut TLKM {
match TLKM::new().context(TLKMError) {
match TLKM::new().context(TLKMSnafu) {
Ok(x) => std::boxed::Box::<TLKM>::into_raw(Box::new(x)),
Err(e) => {
update_last_error(e);
......@@ -199,7 +199,7 @@ pub unsafe extern "C" fn tapasco_tlkm_version(t: *const TLKM, vers: *mut c_char,
}
let tl = &*t;
match tl.version().context(TLKMError) {
match tl.version().context(TLKMSnafu) {
Ok(x) => {
let is = slice::from_raw_parts_mut(vers as *mut u8, len);
if len < x.len() {
......@@ -228,7 +228,7 @@ pub unsafe extern "C" fn tapasco_tlkm_device_len(t: *const TLKM) -> isize {
}
let tl = &*t;
match tl.device_enum_len().context(TLKMError) {
match tl.device_enum_len().context(TLKMSnafu) {
Ok(x) => {
x as isize
}
......@@ -250,7 +250,7 @@ pub unsafe extern "C" fn tapasco_tlkm_devices(t: *const TLKM, di: *mut DeviceInf
}
let tl = &*t;
match tl.device_enum_info().context(TLKMError) {
match tl.device_enum_info().context(TLKMSnafu) {
Ok(x) => {
if len < x.len() {
update_last_error(Error::DeviceInfoToShort { len });
......@@ -296,7 +296,7 @@ pub unsafe extern "C" fn tapasco_tlkm_device_alloc(t: *const TLKM, id: DeviceId)
}
let tl = &*t;
match tl.device_alloc(id, &HashMap::new()).context(TLKMError) {
match tl.device_alloc(id, &HashMap::new()).context(TLKMSnafu) {
Ok(x) => std::boxed::Box::<Device>::into_raw(Box::new(x)),
Err(e) => {
update_last_error(e);
......@@ -410,7 +410,7 @@ pub unsafe extern "C" fn tapasco_job_param_alloc(
let d = &mut *dev;
let mem = match d.default_memory().context(RetrieveDefaultMemory) {
let mem = match d.default_memory().context(RetrieveDefaultMemorySnafu) {
Ok(x) => x,
Err(e) => {
warn!("Failed to retrieve default memory from device.");
......@@ -496,7 +496,7 @@ pub unsafe extern "C" fn tapasco_job_param_prealloc(
let d = &mut *dev;
let mem = match d.default_memory().context(RetrieveDefaultMemory) {
let mem = match d.default_memory().context(RetrieveDefaultMemorySnafu) {
Ok(x) => x,
Err(e) => {
warn!("Failed to retrieve default memory from device.");
......@@ -549,7 +549,7 @@ pub unsafe extern "C" fn tapasco_device_access(dev: *mut Device, access: tlkm_ac
}
let tl = &mut *dev;
match tl.change_access(access).context(DeviceError) {
match tl.change_access(access).context(DeviceSnafu) {
Ok(_) => 0,
Err(e) => {
update_last_error(e);
......@@ -593,7 +593,7 @@ pub unsafe extern "C" fn tapasco_device_get_pe_id(dev: *mut Device, name: *const
let tl = &mut *dev;
match tl.get_pe_id(name_r).context(DeviceError) {
match tl.get_pe_id(name_r).context(DeviceSnafu) {
Ok(x) => x,
Err(e) => {
update_last_error(e);
......@@ -617,7 +617,7 @@ pub unsafe extern "C" fn tapasco_device_acquire_pe(dev: *mut Device, id: PEId) -
}
let tl = &mut *dev;
match tl.acquire_pe(id).context(DeviceError) {
match tl.acquire_pe(id).context(DeviceSnafu) {
Ok(x) => std::boxed::Box::<Job>::into_raw(Box::new(x)),
Err(e) => {
update_last_error(e);
......@@ -657,7 +657,7 @@ pub unsafe extern "C" fn tapasco_job_start(job: *mut Job, params: *mut *mut JobL
let jl = *jl;
let tl = &mut *job;
match tl.start(jl).context(JobError) {
match tl.start(jl).context(JobSnafu) {
Ok(x) => {
for d in x {
// Make sure Rust doesn't release the memory received from C
......@@ -694,7 +694,7 @@ pub unsafe extern "C" fn tapasco_job_release(
let tl = &mut *job;
match tl
.release(release, !return_value.is_null())
.context(JobError)
.context(JobSnafu)
{
Ok(x) => {
for d in x.1 {
......@@ -730,7 +730,7 @@ pub unsafe extern "C" fn tapasco_get_default_memory(dev: *mut Device) -> *mut Ta
}
let tl = &mut *dev;
match tl.default_memory().context(DeviceError) {
match tl.default_memory().context(DeviceSnafu) {
Ok(x) => Box::into_raw(Box::new(x)),
Err(e) => {
update_last_error(e);
......@@ -764,7 +764,7 @@ pub unsafe extern "C" fn tapasco_memory_copy_to(
let s = slice::from_raw_parts(data, len);
let tl = &mut *mem;
match tl.dma().copy_to(s, addr).context(DMAError) {
match tl.dma().copy_to(s, addr).context(DMASnafu) {
Ok(_x) => 0,
Err(e) => {
update_last_error(e);
......@@ -791,7 +791,7 @@ pub unsafe extern "C" fn tapasco_memory_copy_from(
let s = slice::from_raw_parts_mut(data, len);
let tl = &mut *mem;
match tl.dma().copy_from(addr, s).context(DMAError) {
match tl.dma().copy_from(addr, s).context(DMASnafu) {
Ok(_x) => 0,
Err(e) => {
update_last_error(e);
......@@ -819,7 +819,7 @@ pub unsafe extern "C" fn tapasco_memory_allocate(
.lock()
.unwrap()
.allocate(len as u64, None)
.context(AllocatorError)
.context(AllocatorSnafu)
{
Ok(x) => x,
Err(e) => {
......@@ -849,7 +849,7 @@ pub unsafe extern "C" fn tapasco_memory_allocate_fixed(
.lock()
.unwrap()
.allocate_fixed(len as u64, offset as u64)
.context(AllocatorError)
.context(AllocatorSnafu)
{
Ok(x) => x,
Err(e) => {
......@@ -878,7 +878,7 @@ pub unsafe extern "C" fn tapasco_memory_free(
.lock()
.unwrap()
.free(addr)
.context(AllocatorError)
.context(AllocatorSnafu)
{
Ok(_x) => 0,
Err(e) => {
......@@ -903,7 +903,7 @@ pub unsafe extern "C" fn tapasco_device_design_frequency(dev: *mut Device) -> f3
}
let tl = &mut *dev;
match tl.design_frequency_mhz().context(DeviceError) {
match tl.design_frequency_mhz().context(DeviceSnafu) {
Ok(x) => x,
Err(e) => {
update_last_error(e);
......
......@@ -61,9 +61,9 @@ impl Drop for Interrupt {
impl Interrupt {
pub fn new(tlkm_file: &File, interrupt_id: usize, blocking: bool) -> Result<Self> {
let fd = if blocking {
eventfd(0, EfdFlags::empty()).context(ErrorEventFD)?
eventfd(0, EfdFlags::empty()).context(ErrorEventFDSnafu)?
} else {
eventfd(0, EfdFlags::EFD_NONBLOCK).context(ErrorEventFD)?
eventfd(0, EfdFlags::EFD_NONBLOCK).context(ErrorEventFDSnafu)?
};
let mut ioctl_fd = tlkm_register_interrupt {
fd,
......@@ -72,7 +72,7 @@ impl Interrupt {
unsafe {
tlkm_ioctl_reg_interrupt(tlkm_file.as_raw_fd(), &mut ioctl_fd)
.context(ErrorEventFDRegister)?;
.context(ErrorEventFDRegisterSnafu)?;
};
Ok(Self { interrupt: fd })
......
......@@ -154,13 +154,13 @@ impl Job {
.allocator()
.lock()?
.allocate_fixed(x.data.len() as u64, offset)
.context(AllocatorError)?,
.context(AllocatorSnafu)?,
None => x
.memory
.allocator()
.lock()?
.allocate(x.data.len() as u64, Some(x.data.as_ptr() as u64))
.context(AllocatorError)?,
.context(AllocatorSnafu)?,
}
};
......@@ -197,7 +197,7 @@ impl Job {
x.memory
.dma()
.copy_to(&x.data[..], x.device_address)
.context(DMAError)?;
.context(DMASnafu)?;
}
xs.push(PEParameter::DeviceAddress(x.device_address));
......@@ -258,20 +258,20 @@ impl Job {
trace!("Setting argument {} => {:?}.", i, arg);
match arg {
PEParameter::Single32(_) => {
self.pe.as_ref().unwrap().set_arg(i, arg).context(PEError)?;
self.pe.as_ref().unwrap().set_arg(i, arg).context(PESnafu)?;
}
PEParameter::Single64(_) => {
self.pe.as_ref().unwrap().set_arg(i, arg).context(PEError)?;
self.pe.as_ref().unwrap().set_arg(i, arg).context(PESnafu)?;
}
PEParameter::DeviceAddress(x) => self
.pe
.as_ref()
.unwrap()
.set_arg(i, PEParameter::Single64(x))
.context(PEError)?,
.context(PESnafu)?,
PEParameter::VirtualAddress(p) => {
if *self.pe.as_ref().unwrap().svm_in_use() {
self.pe.as_ref().unwrap().set_arg(i, PEParameter::Single64(p as u64)).context(PEError)?;
self.pe.as_ref().unwrap().set_arg(i, PEParameter::Single64(p as u64)).context(PESnafu)?;
} else {
return Err(Error::UnsupportedSVMParameter { arg })
}
......@@ -281,7 +281,7 @@ impl Job {
}
trace!("Arguments set.");
trace!("Starting PE {} execution.", self.pe.as_ref().unwrap().id());
self.pe.as_mut().unwrap().start().context(PEError)?;
self.pe.as_mut().unwrap().start().context(PESnafu)?;
trace!("PE {} started.", self.pe.as_ref().unwrap().id());
Ok(unused_mem)
}
......@@ -289,7 +289,7 @@ impl Job {
/// Just wait for a PE's completion. Useful for measuring execution time.
pub fn wait_for_completion(&mut self) -> Result<()> {
if self.pe.is_some() {
self.pe.as_mut().unwrap().wait_for_completion().context(PEError)
self.pe.as_mut().unwrap().wait_for_completion().context(PESnafu)
} else {
Err(Error::NoPEtoRelease {})
}
......@@ -317,13 +317,13 @@ impl Job {
.as_mut()
.unwrap()
.release(return_value)
.context(PEError)?;
.context(PESnafu)?;
trace!("PE is idle.");
if release_pe {
self.scheduler
.release_pe(self.pe.take().unwrap())
.context(SchedulerError)?;
.context(SchedulerSnafu)?;
}
trace!("Release successful.");
match copyback {
......@@ -337,19 +337,19 @@ impl Job {
.memory
.dma()
.copy_from(transfer.device_address, &mut transfer.data[..])
.context(DMAError)?;
.context(DMASnafu)?;
if transfer.free {
transfer
.memory
.allocator()
.lock()?
.free(transfer.device_address)