Crate axdriver

source ·
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, AxNetDevice will be an alias of VirtioNetDev if the virtio-net feature 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, AxNetDevice will be Box<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 CategoryCargo FeatureDescription
BlockramdiskA RAM disk that stores data in a vector
Blockvirtio-blkVirtIO block device
Networkvirtio-netVirtIO network device
Displayvirtio-gpuVirtIO 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 of virtio-blk, virtio-net or virtio-gpu is 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 for AxNetDevice.
  • block: use block storage devices. Similar to the net feature.
  • display: use graphics display devices. Similar to the net feature.

Modules

  • Device driver prelude that includes some traits and types.

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

Type Aliases