From aed9ad855c825d8f013b79a176b99349757b9bb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Tue, 4 Jun 2024 17:13:49 +0200 Subject: [PATCH] refactor(pci): set command using `PciHeader::update_command` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kröning --- src/drivers/pci.rs | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/src/drivers/pci.rs b/src/drivers/pci.rs index 6f39132ed7..0d8d2ae391 100644 --- a/src/drivers/pci.rs +++ b/src/drivers/pci.rs @@ -132,28 +132,16 @@ impl PciDevice { /// Set flag to the command register pub fn set_command(&self, cmd: CommandRegister) { - unsafe { - let mut command = self - .access - .read(self.address, DeviceHeader::PCI_COMMAND_REGISTER.into()); - command |= cmd.bits() as u32; - self.access.write( - self.address, - DeviceHeader::PCI_COMMAND_REGISTER.into(), - command, - ) - } + // 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)); } /// Get value of the command register pub fn get_command(&self) -> CommandRegister { - unsafe { - CommandRegister::from_bits( - self.access - .read(self.address, DeviceHeader::PCI_COMMAND_REGISTER.into()) as u16, - ) - .unwrap() - } + self.header().command(&self.access) } /// Returns the bar at bar-register `slot`.