From bdd7cd50731510efebb91ccbf8f16b7dc8baebbd Mon Sep 17 00:00:00 2001 From: Andrew Walbran Date: Fri, 6 Dec 2024 15:21:44 +0000 Subject: [PATCH 1/3] Document fake. --- src/transport/fake.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/transport/fake.rs b/src/transport/fake.rs index dd7ecd37..d223562e 100644 --- a/src/transport/fake.rs +++ b/src/transport/fake.rs @@ -1,3 +1,5 @@ +//! A fake implementation of `Transport` for unit tests. + use super::{DeviceStatus, DeviceType, Transport}; use crate::{ queue::{fake_read_write_queue, Descriptor}, @@ -173,6 +175,7 @@ impl Debug for State { } impl State { + /// Creates a state for a fake transport, with the given queues and VirtIO configuration space. pub const fn new(queues: Vec, config_space: C) -> Self { Self { status: DeviceStatus::empty(), @@ -266,11 +269,17 @@ impl State { } } +/// The status of a fake virtqueue. #[derive(Debug, Default)] pub struct QueueStatus { + /// The size of the fake virtqueue. pub size: u32, + /// The physical address set for the queue's descriptors. pub descriptors: PhysAddr, + /// The physical address set for the queue's driver area. pub driver_area: PhysAddr, + /// The physical address set for the queue's device area. pub device_area: PhysAddr, + /// Whether the queue has been notified by the driver since last we checked. pub notified: AtomicBool, } From 5bc53a116bbfaead60e8075c1159287da3474262 Mon Sep 17 00:00:00 2001 From: Andrew Walbran Date: Fri, 6 Dec 2024 15:21:56 +0000 Subject: [PATCH 2/3] Use &raw rather than addr_of macros. --- src/transport/pci.rs | 4 ++-- src/volatile.rs | 7 ++----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/transport/pci.rs b/src/transport/pci.rs index 044ac9e0..c33e87cf 100644 --- a/src/transport/pci.rs +++ b/src/transport/pci.rs @@ -16,7 +16,7 @@ use crate::{ }; use core::{ mem::{align_of, size_of}, - ptr::{addr_of_mut, NonNull}, + ptr::NonNull, }; use zerocopy::{FromBytes, Immutable, IntoBytes}; @@ -256,7 +256,7 @@ impl Transport for PciTransport { let offset_bytes = usize::from(queue_notify_off) * self.notify_off_multiplier as usize; let index = offset_bytes / size_of::(); - addr_of_mut!((*self.notify_region.as_ptr())[index]).vwrite(queue); + (&raw mut (*self.notify_region.as_ptr())[index]).vwrite(queue); } } diff --git a/src/volatile.rs b/src/volatile.rs index 74f527b3..16110cb9 100644 --- a/src/volatile.rs +++ b/src/volatile.rs @@ -78,7 +78,7 @@ impl VolatileWritable for *mut Volatile { /// ``` macro_rules! volread { ($nonnull:expr, $field:ident) => { - $crate::volatile::VolatileReadable::vread(core::ptr::addr_of!((*$nonnull.as_ptr()).$field)) + $crate::volatile::VolatileReadable::vread((&raw const (*$nonnull.as_ptr()).$field)) }; } @@ -97,10 +97,7 @@ macro_rules! volread { /// ``` macro_rules! volwrite { ($nonnull:expr, $field:ident, $value:expr) => { - $crate::volatile::VolatileWritable::vwrite( - core::ptr::addr_of_mut!((*$nonnull.as_ptr()).$field), - $value, - ) + $crate::volatile::VolatileWritable::vwrite((&raw mut (*$nonnull.as_ptr()).$field), $value) }; } From 8f378112f728284ecb8d0d4f99673d04fc42205a Mon Sep 17 00:00:00 2001 From: Andrew Walbran Date: Fri, 6 Dec 2024 15:36:55 +0000 Subject: [PATCH 3/3] Fix clippy lint warnings. --- src/lib.rs | 2 +- src/queue.rs | 2 +- src/transport/pci/bus.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 0d38c94b..a1ff9720 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -122,7 +122,7 @@ fn align_up(size: usize) -> usize { /// The number of pages required to store `size` bytes, rounded up to a whole number of pages. fn pages(size: usize) -> usize { - (size + PAGE_SIZE - 1) / PAGE_SIZE + size.div_ceil(PAGE_SIZE) } // TODO: Use NonNull::slice_from_raw_parts once it is stable. diff --git a/src/queue.rs b/src/queue.rs index a4e01548..e363f0dc 100644 --- a/src/queue.rs +++ b/src/queue.rs @@ -811,7 +811,7 @@ impl<'a, 'b> InputOutputIter<'a, 'b> { } } -impl<'a, 'b> Iterator for InputOutputIter<'a, 'b> { +impl Iterator for InputOutputIter<'_, '_> { type Item = (NonNull<[u8]>, BufferDirection); fn next(&mut self) -> Option { diff --git a/src/transport/pci/bus.rs b/src/transport/pci/bus.rs index ac6e30da..9bdfea98 100644 --- a/src/transport/pci/bus.rs +++ b/src/transport/pci/bus.rs @@ -486,7 +486,7 @@ pub struct CapabilityIterator<'a, C: ConfigurationAccess> { next_capability_offset: Option, } -impl<'a, C: ConfigurationAccess> Iterator for CapabilityIterator<'a, C> { +impl Iterator for CapabilityIterator<'_, C> { type Item = CapabilityInfo; fn next(&mut self) -> Option {