Expand description
ArceOS device drivers.
Usage
All detected devices are composed into a large struct AllDevices
and returned by the init_drivers function. The upperlayer subsystems
(e.g., the network stack) may unpack the struct to get the specified device
driver they want.
For each device category (i.e., net, block, display, etc.), an unified type
is used to represent all devices in that category. Currently, there are 3
categories: AxNetDevice, AxBlockDevice, and AxDisplayDevice.
Concepts
This crate supports two device models depending on the dyn feature:
- Static: The type of all devices is static, it is determined at compile
time by corresponding cargo features. For example,
AxNetDevicewill be an alias ofVirtioNetDevif thevirtio-netfeature is enabled. This model provides the best performance as it avoids dynamic dispatch. But on limitation, only one device instance is supported for each device category. - Dynamic: All device instance is using trait objects and wrapped in a
Box<dyn Trait>. For example,AxNetDevicewill beBox<dyn NetDriverOps>. When call a method provided by the device, it uses dynamic dispatch that may introduce a little overhead. But on the other hand, it is more flexible, multiple instances of each device category are supported.
Supported Devices
| Device Category | Cargo Feature | Description |
|---|---|---|
| Block | ramdisk | A RAM disk that stores data in a vector |
| Block | virtio-blk | VirtIO block device |
| Network | virtio-net | VirtIO network device |
| Display | virtio-gpu | VirtIO graphics device |
Other Cargo Features
dyn: use the dynamic device model (see above).bus-mmio: use device tree to probe all MMIO devices. This feature is enabeld by default.bus-pci: use PCI bus to probe all PCI devices.virtio: use VirtIO devices. This is enabled if any ofvirtio-blk,virtio-netorvirtio-gpuis enabled.net: use network devices. This is enabled if any feature of network devices is selected. If this feature is enabled without any network device features, a dummy struct is used forAxNetDevice.block: use block storage devices. Similar to thenetfeature.display: use graphics display devices. Similar to thenetfeature.
Modules
- Device driver prelude that includes some traits and types.
Macros
- Register an interrupt handler for the device.
Structs
- A structure that contains all device drivers, organized by their category.
- A structure that contains all device drivers of a certain category.
Enums
- A unified enum that represents different categories of devices.
Functions
- Probes and initializes all device drivers, returns the
AllDevicesstruct.
Type Definitions
- AxBlockDevice
blockThe unified type of the block storage devices. - AxDisplayDevice
displayThe unified type of the graphics display devices. - AxNetDevice
netThe unified type of the NIC devices.