diff --git a/src/transport/mod.rs b/src/transport/mod.rs index f04fe61f..7d456764 100644 --- a/src/transport/mod.rs +++ b/src/transport/mod.rs @@ -6,7 +6,10 @@ pub mod mmio; pub mod pci; mod some; -use crate::{PhysAddr, Result, PAGE_SIZE}; +use crate::{ + volatile::{VolatileReadable, VolatileWritable}, + PhysAddr, Result, PAGE_SIZE, +}; use bitflags::{bitflags, Flags}; use core::{fmt::Debug, ops::BitAnd}; use log::debug; @@ -235,23 +238,29 @@ impl From for DeviceType { /// Wrapper for Transport::read_config_space with an extra dummy parameter to force the correct type /// to be inferred. #[inline(always)] -pub(crate) fn read_help( - transport: &T, - offset: usize, - _dummy_v: Option, -) -> Result { +pub(crate) fn read_help(transport: &T, offset: usize, _dummy_r: Option) -> Result +where + T: Transport, + V: FromBytes, + *const R: VolatileReadable, +{ transport.read_config_space(offset) } /// Wrapper for Transport::write_config_space with an extra dummy parameter to force the correct /// type to be inferred. #[inline(always)] -pub(crate) fn write_help( +pub(crate) fn write_help( transport: &mut T, offset: usize, value: V, - _dummy_v: Option, -) -> Result<()> { + _dummy_w: Option, +) -> Result<()> +where + T: Transport, + V: Immutable + IntoBytes, + *mut W: VolatileWritable, +{ transport.write_config_space(offset, value) } @@ -259,8 +268,12 @@ pub(crate) fn write_help( macro_rules! read_config { ($transport:expr, $struct:ty, $field:ident) => {{ let dummy_struct: Option<$struct> = None; - let dummy_v = dummy_struct.map(|s| s.$field.0); - crate::transport::read_help(&$transport, core::mem::offset_of!($struct, $field), dummy_v) + let dummy_field = dummy_struct.map(|s| s.$field); + crate::transport::read_help( + &$transport, + core::mem::offset_of!($struct, $field), + dummy_field, + ) }}; } @@ -268,12 +281,12 @@ macro_rules! read_config { macro_rules! write_config { ($transport:expr, $struct:ty, $field:ident, $value:expr) => {{ let dummy_struct: Option<$struct> = None; - let dummy_v = dummy_struct.map(|s| s.$field.0); + let dummy_field = dummy_struct.map(|s| s.$field); crate::transport::write_help( &mut $transport, core::mem::offset_of!($struct, $field), $value, - dummy_v, + dummy_field, ) }}; } diff --git a/src/volatile.rs b/src/volatile.rs index 0acbad24..74f527b3 100644 --- a/src/volatile.rs +++ b/src/volatile.rs @@ -18,7 +18,7 @@ pub struct WriteOnly(pub(crate) T); /// An MMIO register which may be both read and written. #[derive(Default)] #[repr(transparent)] -pub struct Volatile(pub(crate) T); +pub struct Volatile(T); impl Volatile { /// Construct a new instance for testing.