Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e1c4bbe

Browse filesBrowse files
committed
uefi: Make PciIoAddress orderable
1 parent 70a63b8 commit e1c4bbe
Copy full SHA for e1c4bbe

File tree

Expand file treeCollapse file tree

1 file changed

+42
-1
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+42
-1
lines changed

‎uefi/src/proto/pci/mod.rs

Copy file name to clipboardExpand all lines: uefi/src/proto/pci/mod.rs
+42-1Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
//! PCI Bus specific protocols.
44
5+
use core::cmp::Ordering;
6+
57
use uefi_raw::protocol::pci::root_bridge::PciRootBridgeIoProtocolWidth;
68

79
pub mod root_bridge;
810

911
/// IO Address for PCI/register IO operations
1012
#[repr(C, packed)]
11-
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
13+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1214
pub struct PciIoAddress {
1315
/// Register number within the PCI device.
1416
pub reg: u8,
@@ -54,12 +56,30 @@ impl PciIoAddress {
5456
}
5557
}
5658

59+
impl From<u64> for PciIoAddress {
60+
fn from(value: u64) -> Self {
61+
unsafe { core::mem::transmute(value) }
62+
}
63+
}
64+
5765
impl From<PciIoAddress> for u64 {
5866
fn from(value: PciIoAddress) -> Self {
5967
unsafe { core::mem::transmute(value) }
6068
}
6169
}
6270

71+
impl PartialOrd for PciIoAddress {
72+
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
73+
Some(self.cmp(other))
74+
}
75+
}
76+
77+
impl Ord for PciIoAddress {
78+
fn cmp(&self, other: &Self) -> Ordering {
79+
u64::from(*self).cmp(&u64::from(*other))
80+
}
81+
}
82+
6383
/// Trait implemented by all data types that can natively be read from a PCI device.
6484
/// Note: Not all of them have to actually be supported by the hardware at hand.
6585
pub trait PciIoUnit: Sized + Default {}
@@ -95,3 +115,24 @@ fn encode_io_mode_and_unit<U: PciIoUnit>(mode: PciIoMode) -> PciRootBridgeIoProt
95115
_ => unreachable!("Illegal PCI IO-Mode / Unit combination"),
96116
}
97117
}
118+
119+
#[cfg(test)]
120+
mod tests {
121+
use super::PciIoAddress;
122+
use core::mem;
123+
124+
#[test]
125+
fn test_pci_ioaddr_raw_conversion() {
126+
assert_eq!(mem::size_of::<u64>(), mem::size_of::<PciIoAddress>());
127+
let srcaddr = PciIoAddress {
128+
reg: 0x11,
129+
fun: 0x33,
130+
dev: 0x55,
131+
bus: 0x77,
132+
ext_reg: 0x99bbddff,
133+
};
134+
let rawaddr: u64 = srcaddr.into();
135+
let dstaddr = PciIoAddress::from(rawaddr);
136+
assert_eq!(srcaddr, dstaddr);
137+
}
138+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.