Skip to content

Commit e1201d7

Browse files
committed
Untie accessor from the actual PciHeader type
I don't know why we didn't do this in the first place - there's no reason to not do it like this.
1 parent e70b983 commit e1201d7

1 file changed

Lines changed: 10 additions & 22 deletions

File tree

src/lib.rs

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,7 @@ impl PciAddress {
4545

4646
impl fmt::Display for PciAddress {
4747
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
48-
write!(
49-
f,
50-
"{:02x}-{:02x}:{:02x}.{}",
51-
self.segment(),
52-
self.bus(),
53-
self.device(),
54-
self.function()
55-
)
48+
write!(f, "{:02x}-{:02x}:{:02x}.{}", self.segment(), self.bus(), self.device(), self.function())
5649
}
5750
}
5851

@@ -133,32 +126,27 @@ pub trait ConfigRegionAccess: Send {
133126
/// | | | line | line |
134127
/// +--------------+--------------+--------------+--------------+
135128
/// ```
136-
pub struct PciHeader<A>(PciAddress, PhantomData<A>)
137-
where
138-
A: ConfigRegionAccess;
139-
140-
impl<A> PciHeader<A>
141-
where
142-
A: ConfigRegionAccess,
143-
{
144-
pub fn new(address: PciAddress) -> PciHeader<A> {
145-
PciHeader(address, PhantomData)
129+
pub struct PciHeader(PciAddress);
130+
131+
impl PciHeader {
132+
pub fn new(address: PciAddress) -> PciHeader {
133+
PciHeader(address)
146134
}
147135

148-
pub fn id(&self, access: &A) -> (VendorId, DeviceId) {
136+
pub fn id(&self, access: &impl ConfigRegionAccess) -> (VendorId, DeviceId) {
149137
let id = unsafe { access.read(self.0, 0x00) };
150138
(id.get_bits(0..16) as u16, id.get_bits(16..32) as u16)
151139
}
152140

153-
pub fn header_type(&self, access: &A) -> u8 {
141+
pub fn header_type(&self, access: &impl ConfigRegionAccess) -> u8 {
154142
/*
155143
* Read bits 0..=6 of the Header Type. Bit 7 dictates whether the device has multiple functions and so
156144
* isn't read here.
157145
*/
158146
unsafe { access.read(self.0, 0x0c) }.get_bits(16..23) as u8
159147
}
160148

161-
pub fn has_multiple_functions(&self, access: &A) -> bool {
149+
pub fn has_multiple_functions(&self, access: &impl ConfigRegionAccess) -> bool {
162150
/*
163151
* Reads bit 7 of the Header Type, which is 1 if the device has multiple functions.
164152
*/
@@ -167,7 +155,7 @@ where
167155

168156
pub fn revision_and_class(
169157
&self,
170-
access: &A,
158+
access: &impl ConfigRegionAccess,
171159
) -> (DeviceRevision, BaseClass, SubClass, Interface) {
172160
let field = unsafe { access.read(self.0, 0x08) };
173161
(

0 commit comments

Comments
 (0)