3
3
//! PCI Root Bridge protocol.
4
4
5
5
use super :: { PciIoUnit , encode_io_mode_and_unit} ;
6
+ use crate :: Status ;
6
7
use crate :: StatusExt ;
7
8
use crate :: proto:: pci:: buffer:: PciBuffer ;
8
9
use crate :: proto:: pci:: region:: PciMappedRegion ;
@@ -18,17 +19,13 @@ use log::debug;
18
19
use uefi:: proto:: pci:: PciIoMode ;
19
20
use uefi:: proto:: pci:: root_bridge:: io_access:: IoAccessType ;
20
21
use uefi_macros:: unsafe_protocol;
21
- use uefi_raw:: Status ;
22
22
use uefi_raw:: protocol:: pci:: resource:: QWordAddressSpaceDescriptor ;
23
23
use uefi_raw:: protocol:: pci:: root_bridge:: {
24
24
PciRootBridgeIoAccess , PciRootBridgeIoProtocol , PciRootBridgeIoProtocolAttribute ,
25
25
PciRootBridgeIoProtocolOperation ,
26
26
} ;
27
27
use uefi_raw:: table:: boot:: { AllocateType , MemoryType , PAGE_SIZE } ;
28
28
29
- #[ cfg( doc) ]
30
- use crate :: Status ;
31
-
32
29
/// Protocol that provides access to the PCI Root Bridge I/O protocol.
33
30
///
34
31
/// # UEFI Spec Description
@@ -42,12 +39,13 @@ pub struct PciRootBridgeIo(PciRootBridgeIoProtocol);
42
39
impl PciRootBridgeIo {
43
40
/// Get the segment number where this PCI root bridge resides.
44
41
#[ must_use]
45
- pub fn segment_nr ( & self ) -> u32 {
42
+ pub const fn segment_nr ( & self ) -> u32 {
46
43
self . 0 . segment_number
47
44
}
48
45
49
46
/// Access PCI operations on this root bridge.
50
- pub fn pci ( & self ) -> PciIoAccessPci < ' _ , io_access:: Pci > {
47
+ #[ must_use]
48
+ pub const fn pci ( & self ) -> PciIoAccessPci < ' _ , io_access:: Pci > {
51
49
PciIoAccessPci {
52
50
proto : ptr:: from_ref ( & self . 0 ) . cast_mut ( ) ,
53
51
io_access : & self . 0 . pci ,
@@ -56,7 +54,8 @@ impl PciRootBridgeIo {
56
54
}
57
55
58
56
/// Access I/O operations on this root bridge.
59
- pub fn io ( & self ) -> PciIoAccessPci < ' _ , io_access:: Io > {
57
+ #[ must_use]
58
+ pub const fn io ( & self ) -> PciIoAccessPci < ' _ , io_access:: Io > {
60
59
PciIoAccessPci {
61
60
proto : ptr:: from_ref ( & self . 0 ) . cast_mut ( ) ,
62
61
io_access : & self . 0 . io ,
@@ -65,7 +64,8 @@ impl PciRootBridgeIo {
65
64
}
66
65
67
66
/// Access memory operations on this root bridge.
68
- pub fn mem ( & self ) -> PciIoAccessPci < ' _ , io_access:: Mem > {
67
+ #[ must_use]
68
+ pub const fn mem ( & self ) -> PciIoAccessPci < ' _ , io_access:: Mem > {
69
69
PciIoAccessPci {
70
70
proto : ptr:: from_ref ( & self . 0 ) . cast_mut ( ) ,
71
71
io_access : & self . 0 . mem ,
@@ -88,9 +88,9 @@ impl PciRootBridgeIo {
88
88
/// # Errors
89
89
/// - [`Status::INVALID_PARAMETER`] MemoryType is invalid.
90
90
/// - [`Status::UNSUPPORTED`] Attributes is unsupported. The only legal attribute bits are:
91
- /// - [`PciRootBridgeIoProtocolAttribute::PCI_ATTRIBUTE_MEMORY_WRITE_COMBINE `]
92
- /// - [`PciRootBridgeIoProtocolAttribute::PCI_ATTRIBUTE_MEMORY_CACHED `]
93
- /// - [`PciRootBridgeIoProtocolAttribute::PCI_ATTRIBUTE_DUAL_ADDRESS_CYCLE `]
91
+ /// - [`PciRootBridgeIoProtocolAttribute::MEMORY_WRITE_COMBINE `]
92
+ /// - [`PciRootBridgeIoProtocolAttribute::MEMORY_CACHED `]
93
+ /// - [`PciRootBridgeIoProtocolAttribute::DUAL_ADDRESS_CYCLE `]
94
94
/// - [`Status::OUT_OF_RESOURCES`] The memory pages could not be allocated.
95
95
#[ cfg( feature = "alloc" ) ]
96
96
pub fn allocate_buffer < T > (
@@ -207,7 +207,7 @@ impl PciRootBridgeIo {
207
207
208
208
let status = unsafe {
209
209
( self . 0 . copy_mem ) (
210
- ( ( & self . 0 ) as * const PciRootBridgeIoProtocol ) . cast_mut ( ) ,
210
+ ptr :: from_ref :: < PciRootBridgeIoProtocol > ( & self . 0 ) . cast_mut ( ) ,
211
211
width,
212
212
destination. as_ptr ( ) . addr ( ) as u64 ,
213
213
source. as_ptr ( ) . addr ( ) as u64 ,
@@ -237,7 +237,7 @@ impl PciRootBridgeIo {
237
237
let configuration_status = unsafe {
238
238
( self . 0 . configuration ) (
239
239
& self . 0 ,
240
- ( ( & mut configuration_address) as * mut u64 ) . cast :: < * const c_void > ( ) ,
240
+ ptr :: from_mut :: < u64 > ( & mut configuration_address) . cast :: < * const c_void > ( ) ,
241
241
)
242
242
} ;
243
243
match configuration_status {
@@ -371,6 +371,7 @@ impl PciRootBridgeIo {
371
371
///
372
372
/// # Returns
373
373
/// Both supported and used attribute will be returned in struct [`AttributeReport`]
374
+ #[ must_use]
374
375
pub fn get_attributes ( & self ) -> AttributeReport {
375
376
let mut supports = PciRootBridgeIoProtocolAttribute :: empty ( ) ;
376
377
let mut attributes = PciRootBridgeIoProtocolAttribute :: empty ( ) ;
@@ -398,11 +399,10 @@ impl PciRootBridgeIo {
398
399
///
399
400
/// # Returns
400
401
/// [`Ok`]: Optional resource range. It will only be available when resource
401
- /// parameter is Some and one of:
402
+ /// parameter is Some and contains one of:
402
403
/// - [`PciRootBridgeIoProtocolAttribute::MEMORY_WRITE_COMBINE`]
403
404
/// - [`PciRootBridgeIoProtocolAttribute::MEMORY_CACHED`]
404
405
/// - [`PciRootBridgeIoProtocolAttribute::MEMORY_DISABLE`]
405
- /// is set.
406
406
///
407
407
/// [`Err`]: Possible error cases:
408
408
/// - [`Status::UNSUPPORTED`]: A bit is set in Attributes that is not supported by the PCI Root Bridge.
0 commit comments