macro_rules! module_phy_driver {
(@replace_expr $_t:tt $sub:expr) => { ... };
(@count_devices $($x:expr),*) => { ... };
(@device_table [$($dev:expr),+]) => { ... };
(drivers: [$($driver:ident),+ $(,)?], device_table: [$($dev:expr),+ $(,)?], $($f:tt)*) => { ... };
}
Expand description
Declares a kernel module for PHYs drivers.
This creates a static array of kernel’s struct phy_driver
and registers it.
This also corresponds to the kernel’s MODULE_DEVICE_TABLE
macro, which embeds the information
for module loading into the module binary file. Every driver needs an entry in device_table
.
§Examples
use kernel::c_str;
use kernel::net::phy::{self, DeviceId};
use kernel::prelude::*;
kernel::module_phy_driver! {
drivers: [PhySample],
device_table: [
DeviceId::new_with_driver::<PhySample>()
],
name: "rust_sample_phy",
authors: ["Rust for Linux Contributors"],
description: "Rust sample PHYs driver",
license: "GPL",
}
struct PhySample;
#[vtable]
impl phy::Driver for PhySample {
const NAME: &'static CStr = c_str!("PhySample");
const PHY_DEVICE_ID: phy::DeviceId = phy::DeviceId::new_with_exact_mask(0x00000001);
}
This expands to the following code:
ⓘ
use kernel::c_str;
use kernel::net::phy::{self, DeviceId};
use kernel::prelude::*;
struct Module {
_reg: ::kernel::net::phy::Registration,
}
module! {
type: Module,
name: "rust_sample_phy",
authors: ["Rust for Linux Contributors"],
description: "Rust sample PHYs driver",
license: "GPL",
}
struct PhySample;
#[vtable]
impl phy::Driver for PhySample {
const NAME: &'static CStr = c_str!("PhySample");
const PHY_DEVICE_ID: phy::DeviceId = phy::DeviceId::new_with_exact_mask(0x00000001);
}
const _: () = {
static mut DRIVERS: [::kernel::net::phy::DriverVTable; 1] =
[::kernel::net::phy::create_phy_driver::<PhySample>()];
impl ::kernel::Module for Module {
fn init(module: &'static ::kernel::ThisModule) -> Result<Self> {
let drivers = unsafe { &mut DRIVERS };
let mut reg = ::kernel::net::phy::Registration::register(
module,
::core::pin::Pin::static_mut(drivers),
)?;
Ok(Module { _reg: reg })
}
}
};
const N: usize = 1;
const TABLE: ::kernel::device_id::IdArray<::kernel::net::phy::DeviceId, (), N> =
::kernel::device_id::IdArray::new_without_index([
::kernel::net::phy::DeviceId(
::kernel::bindings::mdio_device_id {
phy_id: 0x00000001,
phy_id_mask: 0xffffffff,
}),
]);
::kernel::module_device_table!("mdio", phydev, TABLE);