Skip to content

Commit

Permalink
Merge pull request #1266 from hermit-os/pci-types-0.9
Browse files Browse the repository at this point in the history
build(deps): update pci_types to 0.9
  • Loading branch information
mkroening authored Jun 10, 2024
2 parents 9794e14 + c5ed7d9 commit fba7b64
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 33 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ num = { version = "0.4", default-features = false }
num-derive = "0.4"
num-traits = { version = "0.2", default-features = false }
pci-ids = { version = "0.2", optional = true }
pci_types = { version = "0.7" }
pci_types = { version = "0.9" }
rand_chacha = { version = "0.3", default-features = false }
shell-words = { version = "1.1", default-features = false }
simple-shell = { version = "0.0.1", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion src/arch/aarch64/kernel/pci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ pub fn init() {
let pci_address = PciAddress::new(0, bus.try_into().unwrap(), device, 0);
let header = PciHeader::new(pci_address);

let (device_id, vendor_id) = header.id(&pci_config);
let (device_id, vendor_id) = header.id(pci_config);
if device_id != u16::MAX && vendor_id != u16::MAX {
let dev = PciDevice::new(pci_address, pci_config);

Expand Down
2 changes: 1 addition & 1 deletion src/arch/x86_64/kernel/pci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub(crate) fn init() {
let pci_address = PciAddress::new(0, bus, device, 0);
let header = PciHeader::new(pci_address);

let (device_id, vendor_id) = header.id(&pci_config);
let (device_id, vendor_id) = header.id(pci_config);
if device_id != u16::MAX && vendor_id != u16::MAX {
unsafe {
PCI_DEVICES.push(PciDevice::new(pci_address, pci_config));
Expand Down
28 changes: 5 additions & 23 deletions src/drivers/pci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,8 @@ impl<T: ConfigRegionAccess> PciDevice<T> {

/// Set flag to the command register
pub fn set_command(&self, cmd: CommandRegister) {
// TODO: don't convert to bits once one of the following PRs is released:
// - https://github.com/rust-osdev/pci_types/pull/15
// - https://github.com/rust-osdev/pci_types/pull/20
let cmd = cmd.bits();
self.header().update_command(&self.access, |command| {
command | CommandRegister::from_bits_retain(cmd)
});
self.header()
.update_command(&self.access, |command| command | cmd);
}

/// Get value of the command register
Expand Down Expand Up @@ -229,21 +224,8 @@ impl<T: ConfigRegionAccess> PciDevice<T> {
}

pub fn set_irq(&self, pin: InterruptPin, line: InterruptLine) {
// TODO: implement with `EndpointHeader::update_interrupt` and remove `DeviceHeader` once merged:
// https://github.com/rust-osdev/pci_types/pull/21
unsafe {
let mut command = self
.access
.read(self.address, DeviceHeader::PCI_INTERRUPT_REGISTER.into());
command &= 0xFFFF_0000u32;
command |= u32::from(line);
command |= u32::from(pin) << 8;
self.access.write(
self.address,
DeviceHeader::PCI_INTERRUPT_REGISTER.into(),
command,
);
}
let mut header = EndpointHeader::from_header(self.header(), &self.access).unwrap();
header.update_interrupt(&self.access, |(_pin, _line)| (pin, line));
}

pub fn bus(&self) -> u8 {
Expand Down Expand Up @@ -272,7 +254,7 @@ impl<T: ConfigRegionAccess> PciDevice<T> {
self.header().status(&self.access)
}

pub fn capabilities(&self) -> Option<CapabilityIterator<'_, T>> {
pub fn capabilities(&self) -> Option<CapabilityIterator<&T>> {
EndpointHeader::from_header(self.header(), &self.access)
.map(|header| header.capabilities(&self.access))
}
Expand Down
2 changes: 1 addition & 1 deletion src/drivers/virtio/transport/pci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ fn read_caps(
PciCapability::Vendor(capability) => Some(capability),
_ => None,
})
.map(|addr| CapData::read(addr.clone(), device.access()).unwrap())
.map(|addr| CapData::read(addr, device.access()).unwrap())
.filter(|cap| cap.cfg_type != CapCfgType::Pci)
.map(|cap| PciCap {
bar: *bars.iter().find(|bar| bar.index == cap.bar).unwrap(),
Expand Down
2 changes: 1 addition & 1 deletion virtio-spec/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ categories = ["no-std", "no-std::no-alloc"]
bitflags = "2"
endian-num = { version = "0.1", features = ["bitflags", "linux-types"] }
num_enum = { version = "0.7", default-features = false }
pci_types = "0.7"
pci_types = "0.9"
volatile = "0.6"
volatile-macro = "0.6"
zerocopy = { version = "0.7", optional = true, default-features = false }
Expand Down
6 changes: 3 additions & 3 deletions virtio-spec/src/pci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ pub struct Cap {
}

impl Cap {
pub fn read(addr: PciCapabilityAddress, access: &impl ConfigRegionAccess) -> Option<Self> {
pub fn read(addr: PciCapabilityAddress, access: impl ConfigRegionAccess) -> Option<Self> {
let data = unsafe { access.read(addr.address, addr.offset) };
let [cap_vndr, _cap_next, cap_len, _cfg_type] = data.to_ne_bytes();

Expand Down Expand Up @@ -205,8 +205,8 @@ pub struct CapData {
}

impl CapData {
pub fn read(addr: PciCapabilityAddress, access: &impl ConfigRegionAccess) -> Option<Self> {
let cap = Cap::read(addr.clone(), access)?;
pub fn read(addr: PciCapabilityAddress, access: impl ConfigRegionAccess) -> Option<Self> {
let cap = Cap::read(addr, &access)?;
let cfg_type = CapCfgType::from(cap.cfg_type);

let (offset, length) = match cfg_type {
Expand Down

0 comments on commit fba7b64

Please sign in to comment.