summaryrefslogtreecommitdiff
path: root/rust/kernel/platform.rs
diff options
context:
space:
mode:
Diffstat (limited to 'rust/kernel/platform.rs')
-rw-r--r--rust/kernel/platform.rs64
1 files changed, 40 insertions, 24 deletions
diff --git a/rust/kernel/platform.rs b/rust/kernel/platform.rs
index 9b362e0495d3..ac0a012ae1bb 100644
--- a/rust/kernel/platform.rs
+++ b/rust/kernel/platform.rs
@@ -17,10 +17,7 @@ use crate::{
from_result,
to_result, //
},
- io::{
- mem::IoRequest,
- Resource, //
- },
+ io::Resource,
irq::{
self,
IrqRequest, //
@@ -31,6 +28,9 @@ use crate::{
ThisModule, //
};
+#[cfg(CONFIG_HAS_IOMEM)]
+use crate::io::mem::IoRequest;
+
use core::{
marker::PhantomData,
mem::offset_of,
@@ -83,7 +83,7 @@ unsafe impl<T: Driver> driver::RegistrationOps for Adapter<T> {
// SAFETY: `pdrv` is guaranteed to be a valid `DriverType`.
to_result(unsafe {
- bindings::__platform_driver_register(pdrv.get(), module.0, name.as_char_ptr())
+ bindings::__platform_driver_register(pdrv.get(), module.as_ptr(), name.as_char_ptr())
})
}
@@ -100,7 +100,8 @@ impl<T: Driver> Adapter<T> {
//
// INVARIANT: `pdev` is valid for the duration of `probe_callback()`.
let pdev = unsafe { &*pdev.cast::<Device<device::CoreInternal<'_>>>() };
- let info = <Self as driver::Adapter>::id_info(pdev.as_ref());
+ // SAFETY: `pdev` matched data is of type `Self::IdInfo`.
+ let info = unsafe { <Self as driver::Adapter>::id_info(pdev.as_ref()) };
from_result(|| {
let data = T::probe(pdev, info);
@@ -176,7 +177,6 @@ macro_rules! module_platform_driver {
///
/// kernel::of_device_table!(
/// OF_TABLE,
-/// MODULE_OF_TABLE,
/// <MyDriver as platform::Driver>::IdInfo,
/// [
/// (of::DeviceId::new(c"test,device"), ())
@@ -185,7 +185,6 @@ macro_rules! module_platform_driver {
///
/// kernel::acpi_device_table!(
/// ACPI_TABLE,
-/// MODULE_ACPI_TABLE,
/// <MyDriver as platform::Driver>::IdInfo,
/// [
/// (acpi::DeviceId::new(c"LNUXBEEF"), ())
@@ -307,6 +306,7 @@ impl<Ctx: device::DeviceContext> Device<Ctx> {
}
}
+#[cfg(CONFIG_HAS_IOMEM)]
impl Device<Bound> {
/// Returns an `IoRequest` for the resource at `index`, if any.
pub fn io_request_by_index(&self, index: u32) -> Option<IoRequest<'_>> {
@@ -339,22 +339,30 @@ macro_rules! define_irq_accessor_by_index {
$handler_trait:ident
) => {
$(#[$meta])*
- pub fn $fn_name<'a, T: irq::$handler_trait + 'static>(
+ ///
+ /// # Safety
+ ///
+ /// Callers must not `mem::forget()` the resulting registration or otherwise prevent its
+ /// [`Drop`] implementation from running.
+ pub unsafe fn $fn_name<'a, T: irq::$handler_trait + 'a>(
&'a self,
flags: irq::Flags,
index: u32,
name: &'static CStr,
handler: impl PinInit<T, Error> + 'a,
- ) -> impl PinInit<irq::$reg_type<T>, Error> + 'a {
+ ) -> impl PinInit<irq::$reg_type<'a, T>, Error> + 'a {
pin_init::pin_init_scope(move || {
let request = self.$request_fn(index)?;
- Ok(irq::$reg_type::<T>::new(
- request,
- flags,
- name,
- handler,
- ))
+ // SAFETY: Caller guarantees the Registration will not be leaked.
+ Ok(unsafe {
+ irq::$reg_type::<T>::new(
+ request,
+ flags,
+ name,
+ handler,
+ )
+ })
})
}
};
@@ -368,22 +376,30 @@ macro_rules! define_irq_accessor_by_name {
$handler_trait:ident
) => {
$(#[$meta])*
- pub fn $fn_name<'a, T: irq::$handler_trait + 'static>(
+ ///
+ /// # Safety
+ ///
+ /// Callers must not `mem::forget()` the resulting registration or otherwise prevent its
+ /// [`Drop`] implementation from running.
+ pub unsafe fn $fn_name<'a, T: irq::$handler_trait + 'a>(
&'a self,
flags: irq::Flags,
irq_name: &'a CStr,
name: &'static CStr,
handler: impl PinInit<T, Error> + 'a,
- ) -> impl PinInit<irq::$reg_type<T>, Error> + 'a {
+ ) -> impl PinInit<irq::$reg_type<'a, T>, Error> + 'a {
pin_init::pin_init_scope(move || {
let request = self.$request_fn(irq_name)?;
- Ok(irq::$reg_type::<T>::new(
- request,
- flags,
- name,
- handler,
- ))
+ // SAFETY: Caller guarantees the Registration will not be leaked.
+ Ok(unsafe {
+ irq::$reg_type::<T>::new(
+ request,
+ flags,
+ name,
+ handler,
+ )
+ })
})
}
};