Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,30 @@ impl PciPciBridgeHeader {
let data = unsafe { access.read(self.0, 0x18).get_bits(16..24) };
data as u8
}

pub fn update_bus_number<F>(&self, access: impl ConfigRegionAccess, f: F)
where
F: FnOnce(BusNumber) -> BusNumber,
{
let mut data = unsafe { access.read(self.0, 0x18) };
let new_bus = f(BusNumber {
primary: data.get_bits(0..8) as u8,
secondary: data.get_bits(8..16) as u8,
subordinate: data.get_bits(16..24) as u8,
});
data.set_bits(16..24, new_bus.subordinate.into());
data.set_bits(8..16, new_bus.secondary.into());
data.set_bits(0..8, new_bus.primary.into());
unsafe {
access.write(self.0, 0x18, data);
}
}
}

pub struct BusNumber {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can merge without this for now, but this should probably derive Clone, Copy, PartialEq, Debug or something

pub primary: u8,
pub secondary: u8,
pub subordinate: u8,
}

pub const MAX_BARS: usize = 6;
Expand Down