Skip to content

Commit b35f742

Browse files
ZR233IsaacWoods
authored andcommitted
Add set bus number funcs
1 parent 1138b2e commit b35f742

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/lib.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,30 @@ impl PciPciBridgeHeader {
531531
let data = unsafe { access.read(self.0, 0x18).get_bits(16..24) };
532532
data as u8
533533
}
534+
535+
pub fn update_bus_number<F>(&self, access: impl ConfigRegionAccess, f: F)
536+
where
537+
F: FnOnce(BusNumber) -> BusNumber,
538+
{
539+
let mut data = unsafe { access.read(self.0, 0x18) };
540+
let new_bus = f(BusNumber {
541+
primary: data.get_bits(0..8) as u8,
542+
secondary: data.get_bits(8..16) as u8,
543+
subordinate: data.get_bits(16..24) as u8,
544+
});
545+
data.set_bits(16..24, new_bus.subordinate.into());
546+
data.set_bits(8..16, new_bus.secondary.into());
547+
data.set_bits(0..8, new_bus.primary.into());
548+
unsafe {
549+
access.write(self.0, 0x18, data);
550+
}
551+
}
552+
}
553+
554+
pub struct BusNumber {
555+
pub primary: u8,
556+
pub secondary: u8,
557+
pub subordinate: u8,
534558
}
535559

536560
pub const MAX_BARS: usize = 6;

0 commit comments

Comments
 (0)