@@ -36,11 +36,30 @@ impl PciRootBridgeIo {
3636 self . 0 . segment_number
3737 }
3838
39- /// Access PCI I/O operations on this root bridge.
40- pub const fn pci ( & mut self ) -> PciIoAccessPci < ' _ > {
41- PciIoAccessPci {
39+ /// Access PCI controller registers in the configuration space on this root bridge.
40+ pub const fn pci ( & mut self ) -> PciIoAccess < ' _ , PciConfigurationSpace > {
41+ PciIoAccess {
4242 proto : & mut self . 0 ,
4343 io_access : & mut self . 0 . pci ,
44+ _address_space : PciConfigurationSpace ,
45+ }
46+ }
47+
48+ /// Access PCI controller registers in the memory space on this root bridge.
49+ pub const fn memory ( & mut self ) -> PciIoAccess < ' _ , PciMemorySpace > {
50+ PciIoAccess {
51+ proto : & mut self . 0 ,
52+ io_access : & mut self . 0 . mem ,
53+ _address_space : PciMemorySpace ,
54+ }
55+ }
56+
57+ /// Access PCI controller registers in the I/O space on this root bridge.
58+ pub const fn io ( & mut self ) -> PciIoAccess < ' _ , PciIoSpace > {
59+ PciIoAccess {
60+ proto : & mut self . 0 ,
61+ io_access : & mut self . 0 . io ,
62+ _address_space : PciIoSpace ,
4463 }
4564 }
4665
@@ -117,8 +136,6 @@ impl PciRootBridgeIo {
117136 }
118137
119138 // TODO: poll I/O
120- // TODO: mem I/O access
121- // TODO: io I/O access
122139 // TODO: map & unmap & copy memory
123140 // TODO: buffer management
124141
@@ -154,7 +171,7 @@ impl PciRootBridgeIo {
154171 /// An ordered list of addresses containing all present devices below this RootBridge.
155172 ///
156173 /// # Errors
157- /// This can basically fail with all the IO errors found in [`PciIoAccessPci `] methods.
174+ /// This can basically fail with all the IO errors found in [`PciIoAccess `] methods.
158175 #[ cfg( feature = "alloc" ) ]
159176 pub fn enumerate ( & mut self ) -> crate :: Result < super :: enumeration:: PciTree > {
160177 use super :: enumeration:: { self , PciTree } ;
@@ -182,12 +199,13 @@ impl PciRootBridgeIo {
182199
183200/// Struct for performing PCI I/O operations on a root bridge.
184201#[ derive( Debug ) ]
185- pub struct PciIoAccessPci < ' a > {
202+ pub struct PciIoAccess < ' a , S : PciIoAddressSpace > {
186203 proto : * mut PciRootBridgeIoProtocol ,
187204 io_access : & ' a mut PciRootBridgeIoAccess ,
205+ _address_space : S ,
188206}
189207
190- impl PciIoAccessPci < ' _ > {
208+ impl < S : PciIoAddressSpace > PciIoAccess < ' _ , S > {
191209 /// Reads a single value of type `U` from the specified PCI address.
192210 ///
193211 /// # Arguments
@@ -199,7 +217,7 @@ impl PciIoAccessPci<'_> {
199217 /// # Errors
200218 /// - [`Status::INVALID_PARAMETER`] The requested width is invalid for this PCI root bridge.
201219 /// - [`Status::OUT_OF_RESOURCES`] The read request could not be completed due to a lack of resources.
202- pub fn read_one < U : PciIoUnit > ( & self , addr : PciIoAddress ) -> crate :: Result < U > {
220+ pub fn read_one < U : PciIoUnit > ( & self , addr : S :: Address ) -> crate :: Result < U > {
203221 let width_mode = encode_io_mode_and_unit :: < U > ( super :: PciIoMode :: Normal ) ;
204222 let mut result = U :: default ( ) ;
205223 unsafe {
@@ -223,7 +241,7 @@ impl PciIoAccessPci<'_> {
223241 /// # Errors
224242 /// - [`Status::INVALID_PARAMETER`] The requested width is invalid for this PCI root bridge.
225243 /// - [`Status::OUT_OF_RESOURCES`] The write request could not be completed due to a lack of resources.
226- pub fn write_one < U : PciIoUnit > ( & self , addr : PciIoAddress , data : U ) -> crate :: Result < ( ) > {
244+ pub fn write_one < U : PciIoUnit > ( & self , addr : S :: Address , data : U ) -> crate :: Result < ( ) > {
227245 let width_mode = encode_io_mode_and_unit :: < U > ( super :: PciIoMode :: Normal ) ;
228246 unsafe {
229247 ( self . io_access . write ) (
@@ -246,7 +264,7 @@ impl PciIoAccessPci<'_> {
246264 /// # Errors
247265 /// - [`Status::INVALID_PARAMETER`] The requested width is invalid for this PCI root bridge.
248266 /// - [`Status::OUT_OF_RESOURCES`] The read operation could not be completed due to a lack of resources.
249- pub fn read < U : PciIoUnit > ( & self , addr : PciIoAddress , data : & mut [ U ] ) -> crate :: Result < ( ) > {
267+ pub fn read < U : PciIoUnit > ( & self , addr : S :: Address , data : & mut [ U ] ) -> crate :: Result < ( ) > {
250268 let width_mode = encode_io_mode_and_unit :: < U > ( super :: PciIoMode :: Normal ) ;
251269 unsafe {
252270 ( self . io_access . read ) (
@@ -269,7 +287,7 @@ impl PciIoAccessPci<'_> {
269287 /// # Errors
270288 /// - [`Status::INVALID_PARAMETER`] The requested width is invalid for this PCI root bridge.
271289 /// - [`Status::OUT_OF_RESOURCES`] The write operation could not be completed due to a lack of resources.
272- pub fn write < U : PciIoUnit > ( & self , addr : PciIoAddress , data : & [ U ] ) -> crate :: Result < ( ) > {
290+ pub fn write < U : PciIoUnit > ( & self , addr : S :: Address , data : & [ U ] ) -> crate :: Result < ( ) > {
273291 let width_mode = encode_io_mode_and_unit :: < U > ( super :: PciIoMode :: Normal ) ;
274292 unsafe {
275293 ( self . io_access . write ) (
@@ -295,7 +313,7 @@ impl PciIoAccessPci<'_> {
295313 /// - [`Status::OUT_OF_RESOURCES`] The operation could not be completed due to a lack of resources.
296314 pub fn fill_write < U : PciIoUnit > (
297315 & self ,
298- addr : PciIoAddress ,
316+ addr : S :: Address ,
299317 count : usize ,
300318 data : U ,
301319 ) -> crate :: Result < ( ) > {
@@ -325,7 +343,7 @@ impl PciIoAccessPci<'_> {
325343 /// # Errors
326344 /// - [`Status::INVALID_PARAMETER`] The requested width is invalid for this PCI root bridge.
327345 /// - [`Status::OUT_OF_RESOURCES`] The read operation could not be completed due to a lack of resources.
328- pub fn fifo_read < U : PciIoUnit > ( & self , addr : PciIoAddress , data : & mut [ U ] ) -> crate :: Result < ( ) > {
346+ pub fn fifo_read < U : PciIoUnit > ( & self , addr : S :: Address , data : & mut [ U ] ) -> crate :: Result < ( ) > {
329347 let width_mode = encode_io_mode_and_unit :: < U > ( super :: PciIoMode :: Fifo ) ;
330348 unsafe {
331349 ( self . io_access . read ) (
@@ -352,7 +370,7 @@ impl PciIoAccessPci<'_> {
352370 /// # Errors
353371 /// - [`Status::INVALID_PARAMETER`] The requested width is invalid for this PCI root bridge.
354372 /// - [`Status::OUT_OF_RESOURCES`] The write operation could not be completed due to a lack of resources.
355- pub fn fifo_write < U : PciIoUnit > ( & self , addr : PciIoAddress , data : & [ U ] ) -> crate :: Result < ( ) > {
373+ pub fn fifo_write < U : PciIoUnit > ( & self , addr : S :: Address , data : & [ U ] ) -> crate :: Result < ( ) > {
356374 let width_mode = encode_io_mode_and_unit :: < U > ( super :: PciIoMode :: Fifo ) ;
357375 unsafe {
358376 ( self . io_access . write ) (
@@ -366,3 +384,41 @@ impl PciIoAccessPci<'_> {
366384 }
367385 }
368386}
387+
388+ /// Marker struct for the PCI memory space.
389+ #[ derive( Clone , Copy , Debug , PartialEq , Eq , PartialOrd , Ord ) ]
390+ pub struct PciMemorySpace ;
391+
392+ impl private:: Sealed for PciMemorySpace { }
393+ impl PciIoAddressSpace for PciMemorySpace {
394+ type Address = u64 ;
395+ }
396+
397+ /// Marker struct for the PCI I/O space.
398+ #[ derive( Clone , Copy , Debug , PartialEq , Eq , PartialOrd , Ord ) ]
399+ pub struct PciIoSpace ;
400+
401+ impl private:: Sealed for PciIoSpace { }
402+ impl PciIoAddressSpace for PciIoSpace {
403+ type Address = u32 ;
404+ }
405+
406+ /// Marker struct for the PCI configuration space.
407+ #[ derive( Clone , Copy , Debug , PartialEq , Eq , PartialOrd , Ord ) ]
408+ pub struct PciConfigurationSpace ;
409+
410+ impl private:: Sealed for PciConfigurationSpace { }
411+ impl PciIoAddressSpace for PciConfigurationSpace {
412+ type Address = PciIoAddress ;
413+ }
414+
415+ /// Trait representing how to convert from the address type expected for the address space and the
416+ /// raw address space.
417+ pub trait PciIoAddressSpace : private:: Sealed {
418+ /// Specifies the type of the address space addresses.
419+ type Address : Into < u64 > ;
420+ }
421+
422+ mod private {
423+ pub trait Sealed { }
424+ }
0 commit comments