axdriver/
macros.rs

1//! TODO: generate registered drivers in `for_each_drivers!` automatically.
2
3#![allow(unused_macros)]
4
5macro_rules! register_net_driver {
6    ($driver_type:ty, $device_type:ty) => {
7        /// The unified type of the NIC devices.
8        #[cfg(not(feature = "dyn"))]
9        pub type AxNetDevice = $device_type;
10    };
11}
12
13macro_rules! register_block_driver {
14    ($driver_type:ty, $device_type:ty) => {
15        /// The unified type of the NIC devices.
16        #[cfg(not(feature = "dyn"))]
17        pub type AxBlockDevice = $device_type;
18    };
19}
20
21macro_rules! register_display_driver {
22    ($driver_type:ty, $device_type:ty) => {
23        /// The unified type of the NIC devices.
24        #[cfg(not(feature = "dyn"))]
25        pub type AxDisplayDevice = $device_type;
26    };
27}
28
29macro_rules! for_each_drivers {
30    (type $drv_type:ident, $code:block) => {{
31        #[allow(unused_imports)]
32        use crate::drivers::DriverProbe;
33        #[cfg(feature = "virtio")]
34        #[allow(unused_imports)]
35        use crate::virtio::{self, VirtIoDevMeta};
36
37        #[cfg(net_dev = "virtio-net")]
38        {
39            type $drv_type = <virtio::VirtIoNet as VirtIoDevMeta>::Driver;
40            $code
41        }
42        #[cfg(block_dev = "virtio-blk")]
43        {
44            type $drv_type = <virtio::VirtIoBlk as VirtIoDevMeta>::Driver;
45            $code
46        }
47        #[cfg(display_dev = "virtio-gpu")]
48        {
49            type $drv_type = <virtio::VirtIoGpu as VirtIoDevMeta>::Driver;
50            $code
51        }
52        #[cfg(block_dev = "ramdisk")]
53        {
54            type $drv_type = crate::drivers::RamDiskDriver;
55            $code
56        }
57        #[cfg(block_dev = "bcm2835-sdhci")]
58        {
59            type $drv_type = crate::drivers::BcmSdhciDriver;
60            $code
61        }
62        #[cfg(net_dev = "ixgbe")]
63        {
64            type $drv_type = crate::drivers::IxgbeDriver;
65            $code
66        }
67        #[cfg(net_dev = "fxmac")]
68        {
69            type $drv_type = crate::drivers::FXmacDriver;
70            $code
71        }
72    }};
73}