From 095780f5e3ea256da950117c86d3bb91b0b5a869 Mon Sep 17 00:00:00 2001 From: Alexandru Radovici Date: Mon, 27 Oct 2025 00:31:50 +0200 Subject: [PATCH] add a function that that returns a reference to the IoPort Resource --- rust/kernel/io/resource.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/rust/kernel/io/resource.rs b/rust/kernel/io/resource.rs index bea3ee0ed87b51..b7d74673676d0e 100644 --- a/rust/kernel/io/resource.rs +++ b/rust/kernel/io/resource.rs @@ -18,6 +18,13 @@ use crate::types::Opaque; /// `CONFIG_PHYS_ADDR_T_64BIT`, and it can be a u64 even on 32-bit architectures. pub type ResourceSize = bindings::phys_addr_t; +#[cfg(CONFIG_HAS_IOPORT)] +/// Returns a reference to the global `ioport_resource` variable. +pub fn ioport_resource() -> &'static Resource { + // SAFETY: `bindings::ioport_resoure` has global lifetime and is of type Resource. + unsafe { Resource::from_raw(&raw mut bindings::ioport_resource) } +} + /// A region allocated from a parent [`Resource`]. /// /// # Invariants