Skip to content

Commit f4a719b

Browse files
committed
device/pci: Misc fixes
1 parent 401bcf0 commit f4a719b

3 files changed

Lines changed: 22 additions & 32 deletions

File tree

kernel/src/device/acpi/uacpi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ extern "C" fn uacpi_kernel_pci_device_open(
7878

7979
#[unsafe(no_mangle)]
8080
extern "C" fn uacpi_kernel_pci_device_close(arg1: uacpi_handle) {
81-
// This function intentionally left blank.
81+
drop(unsafe { Box::from_raw(arg1 as *mut Address) });
8282
}
8383

8484
fn pci_access_from_address(address: Address) -> Option<&'static dyn Access> {

kernel/src/device/pci/device.rs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,7 @@
11
use super::config::Address;
2-
use crate::{posix::errno::EResult, util::mutex::spin::SpinMutex};
2+
use crate::util::mutex::spin::SpinMutex;
33
use alloc::vec::Vec;
44

5-
pub trait Device {
6-
/// Returns the PCI address of this device.
7-
fn address(&self) -> Address;
8-
9-
/// Called when a device is put to sleep.
10-
fn suspend(&self) -> EResult<()> {
11-
Ok(())
12-
}
13-
14-
/// Called when a device is woken up.
15-
fn resume(&self) -> EResult<()> {
16-
Ok(())
17-
}
18-
}
19-
205
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
216
pub enum PciBar {
227
Mmio32 {

kernel/src/device/pci/driver.rs

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
use super::{ACCESS, DeviceView, config, device::PCI_DEVICES};
1+
use super::{DeviceView, config, device::PCI_DEVICES};
22
use crate::{
3+
device::pci::ACCESS,
34
memory::view::MemoryView,
45
posix::errno::{EResult, Errno},
56
util::mutex::spin::SpinMutex,
@@ -83,22 +84,24 @@ static DRIVERS: SpinMutex<BTreeMap<&'static str, Driver>> = SpinMutex::new(BTree
8384

8485
impl Driver {
8586
pub fn register(self) -> EResult<()> {
86-
let mut drivers = DRIVERS.lock();
87+
{
88+
let mut drivers = DRIVERS.lock();
8789

88-
if drivers.contains_key(self.name) {
89-
warn!("Driver {} is already registered", self.name);
90-
return Err(Errno::EEXIST);
91-
}
90+
if drivers.contains_key(self.name) {
91+
warn!("Driver {} is already registered", self.name);
92+
return Err(Errno::EEXIST);
93+
}
9294

93-
if self.variants.is_empty() {
94-
warn!(
95-
"PCI Driver \"{}\" does not define any variants, ignoring",
96-
self.name
97-
);
98-
return Ok(());
99-
}
95+
if self.variants.is_empty() {
96+
warn!(
97+
"PCI Driver \"{}\" does not define any variants, ignoring",
98+
self.name
99+
);
100+
return Ok(());
101+
}
100102

101-
drivers.insert(self.name, self);
103+
drivers.insert(self.name, self);
104+
}
102105

103106
log!(
104107
"Registered new PCI driver \"{}\" with {} variant(s)",
@@ -132,7 +135,9 @@ impl Driver {
132135
&& v.sub_class.is_none_or(|x| x == sub_class)
133136
&& v.class.is_none_or(|x| x == class)
134137
}) {
135-
(self.probe)(variant, view)?;
138+
if let Err(e) = (self.probe)(variant, view) {
139+
warn!("{}: {} failed to probe: {:?}", addr, self.name, e);
140+
}
136141
}
137142
}
138143

0 commit comments

Comments
 (0)