ostd/bus/pci/mod.rs
1// SPDX-License-Identifier: MPL-2.0
2//! PCI bus
3//!
4//! Users can implement the bus under the `PciDriver` to the PCI bus to register devices,
5//! when the physical device and the driver match successfully, it will be provided through the driver `construct` function
6//! to construct a structure that implements the `PciDevice` trait. And in the end,
7//! PCI bus will store a reference to the structure and finally call the driver's probe function to remind the driver of a new device access.
8//!
9//! Use case:
10//!
11//! ```rust no_run
12//! #[derive(Debug)]
13//! pub struct PciDeviceA {
14//! common_device: PciCommonDevice,
15//! }
16//!
17//! impl PciDevice for PciDeviceA {
18//! fn device_id(&self) -> PciDeviceId {
19//! self.common_device.device_id().clone()
20//! }
21//! }
22//!
23//! #[derive(Debug)]
24//! pub struct PciDriverA {
25//! devices: Mutex<Vec<Arc<PciDeviceA>>>,
26//! }
27//!
28//! impl PciDriver for PciDriverA {
29//! fn probe(
30//! &self,
31//! device: PciCommonDevice,
32//! ) -> Result<Arc<dyn PciDevice>, (PciDriverProbeError, PciCommonDevice)> {
33//! if device.device_id().vendor_id != 0x1234 {
34//! return Err((PciDriverProbeError::DeviceNotMatch, device));
35//! }
36//! let device = Arc::new(PciDeviceA {
37//! common_device: device,
38//! });
39//! self.devices.lock().push(device.clone());
40//! Ok(device)
41//! }
42//! }
43//!
44//! pub fn driver_a_init() {
45//! let driver_a = Arc::new(PciDriverA {
46//! devices: Mutex::new(Vec::new()),
47//! });
48//! PCI_BUS.lock().register_driver(driver_a);
49//! }
50//! ```
51/*pub mod bus;*/
52pub mod capability;
53pub mod cfg_space;
54/*pub mod common_device;*/
55mod device_info;
56
57pub use device_info::{/* PciDeviceId, */ PciDeviceLocation};
58
59/*
60use self::{bus::PciBus, common_device::PciCommonDevice};
61use crate::{arch::pci::has_pci_bus, sync::Mutex};
62
63/// PCI bus instance
64pub static PCI_BUS: Mutex<PciBus> = Mutex::new(PciBus::new());
65
66pub(crate) fn init() {
67 if !has_pci_bus() {
68 return;
69 }
70
71 let mut lock = PCI_BUS.lock();
72 for location in PciDeviceLocation::all() {
73 let Some(device) = PciCommonDevice::new(location) else {
74 continue;
75 };
76 lock.register_common_device(device);
77 }
78}
79*/