Skip to content

Commit 78e0b04

Browse files
committed
Simplified PCI device driver interface
Signed-off-by: SlyMarbo <[email protected]>
1 parent 1abcb48 commit 78e0b04

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

kernel/src/drivers/mod.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,19 @@
33
44
use crate::pci;
55

6+
/// PciDeviceDriver takes ownership of a PCI device.
7+
///
8+
pub type PciDeviceDriver = fn(device: pci::Device);
9+
610
/// device_supported is a callback called by the PCI module
711
/// for each PCI device discovered. If the device is supported
812
/// by a device driver, device_supported returns true and
913
/// the device is passed to register_device, so the driver
1014
/// can take ownership.
1115
///
12-
pub fn device_supported(device: &pci::Device) -> bool {
13-
// TODO: once we have device drivers, ask them here.
14-
false
15-
}
16+
pub fn device_supported(_device: &pci::Device) -> Option<PciDeviceDriver> {
17+
// TODO: once we have device drivers, ask them here,
18+
// returning their driver if so.
1619

17-
/// register_device is a callback called by the PCI module
18-
/// for each PCI device discovered. If the device can be
19-
/// identified as a supported device, the corresponding
20-
/// driver is used to initialise the device.
21-
///
22-
pub fn register_device(device: pci::Device) {
23-
// TODO: once we have device drivers, initialise them here.
20+
None
2421
}

kernel/src/pci.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,8 @@ fn scan_slot(bus: u8, slot: u8) {
216216
devtype,
217217
};
218218

219-
if drivers::device_supported(&dev) {
220-
drivers::register_device(dev);
219+
if let Some(driver) = drivers::device_supported(&dev) {
220+
driver(dev);
221221
} else {
222222
UNKNOWN_DEVICES.lock().push(dev);
223223
}

0 commit comments

Comments
 (0)