From 9d39842f6afcd0438c8353a9764d624eef2d160a Mon Sep 17 00:00:00 2001 From: Danilo Krummrich Date: Tue, 4 Nov 2025 14:32:54 +0100 Subject: rust: io: cleanup imports and use "kernel vertical" style Commit 46f045db5a94 ("rust: Add read_poll_timeout_atomic function") initiated the first import change in the I/O module using the agreed "kernel vertical" import style [1]. For consistency throughout the module, adjust all other imports accordingly. While at it, drop unnecessary imports covered by prelude::*. Link: https://docs.kernel.org/rust/coding-guidelines.html#imports [1] Reviewed-by: Zhi Wang Link: https://patch.msgid.link/20251104133301.59402-1-dakr@kernel.org [ Use prelude::* in io/poll.rs. - Danilo ] Signed-off-by: Danilo Krummrich --- rust/kernel/io.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'rust/kernel/io.rs') diff --git a/rust/kernel/io.rs b/rust/kernel/io.rs index ee182b0b5452..1aa9495f7774 100644 --- a/rust/kernel/io.rs +++ b/rust/kernel/io.rs @@ -4,8 +4,10 @@ //! //! C header: [`include/asm-generic/io.h`](srctree/include/asm-generic/io.h) -use crate::error::{code::EINVAL, Result}; -use crate::{bindings, build_assert, ffi::c_void}; +use crate::{ + bindings, + prelude::*, // +}; pub mod mem; pub mod poll; -- cgit From dfd67993044f507ba8fd6ee9956f923ba4b7e851 Mon Sep 17 00:00:00 2001 From: Alice Ryhl Date: Wed, 12 Nov 2025 09:48:33 +0000 Subject: rust: io: move ResourceSize to top-level io module Resource sizes are a general concept for dealing with physical addresses, and not specific to the Resource type, which is just one way to access physical addresses. Thus, move the typedef to the io module. Still keep a re-export under resource. This avoids this commit from being a flag-day, but I also think it's a useful re-export in general so that you can import use kernel::io::resource::{Resource, ResourceSize}; instead of having to write use kernel::io::{ resource::Resource, ResourceSize, }; in the specific cases where you need ResourceSize because you are using the Resource type. Therefore I think it makes sense to keep this re-export indefinitely and it is *not* intended as a temporary re-export for migration purposes. Cc: stable@vger.kernel.org # for v6.18 [1] Signed-off-by: Alice Ryhl Link: https://patch.msgid.link/20251112-resource-phys-typedefs-v2-2-538307384f82@google.com Link: https://lore.kernel.org/all/20251112-resource-phys-typedefs-v2-0-538307384f82@google.com/ [1] Signed-off-by: Danilo Krummrich --- rust/kernel/io.rs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'rust/kernel/io.rs') diff --git a/rust/kernel/io.rs b/rust/kernel/io.rs index 1aa9495f7774..b8d0fb27f6ae 100644 --- a/rust/kernel/io.rs +++ b/rust/kernel/io.rs @@ -15,6 +15,12 @@ pub mod resource; pub use resource::Resource; +/// Resource Size type. +/// +/// This is a type alias to either `u32` or `u64` depending on the config option +/// `CONFIG_PHYS_ADDR_T_64BIT`, and it can be a u64 even on 32-bit architectures. +pub type ResourceSize = bindings::resource_size_t; + /// Raw representation of an MMIO region. /// /// By itself, the existence of an instance of this structure does not provide any guarantees that -- cgit From dd6ff5cf56fb183fce605ca6a5bfce228cd8888b Mon Sep 17 00:00:00 2001 From: Alice Ryhl Date: Wed, 12 Nov 2025 09:48:35 +0000 Subject: rust: io: add typedef for phys_addr_t The C typedef phys_addr_t is missing an analogue in Rust, meaning that we end up using bindings::phys_addr_t or ResourceSize as a replacement in various places throughout the kernel. Fix that by introducing a new typedef on the Rust side. Place it next to the existing ResourceSize typedef since they're quite related to each other. Cc: stable@vger.kernel.org # for v6.18 [1] Signed-off-by: Alice Ryhl Link: https://patch.msgid.link/20251112-resource-phys-typedefs-v2-4-538307384f82@google.com Link: https://lore.kernel.org/all/20251112-resource-phys-typedefs-v2-0-538307384f82@google.com/ [1] Signed-off-by: Danilo Krummrich --- rust/kernel/io.rs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'rust/kernel/io.rs') diff --git a/rust/kernel/io.rs b/rust/kernel/io.rs index b8d0fb27f6ae..98e8b84e68d1 100644 --- a/rust/kernel/io.rs +++ b/rust/kernel/io.rs @@ -15,6 +15,12 @@ pub mod resource; pub use resource::Resource; +/// Physical address type. +/// +/// This is a type alias to either `u32` or `u64` depending on the config option +/// `CONFIG_PHYS_ADDR_T_64BIT`, and it can be a u64 even on 32-bit architectures. +pub type PhysAddr = bindings::phys_addr_t; + /// Resource Size type. /// /// This is a type alias to either `u32` or `u64` depending on the config option @@ -70,8 +76,16 @@ impl IoRaw { /// # Examples /// /// ```no_run -/// # use kernel::{bindings, ffi::c_void, io::{Io, IoRaw}}; -/// # use core::ops::Deref; +/// use kernel::{ +/// bindings, +/// ffi::c_void, +/// io::{ +/// Io, +/// IoRaw, +/// PhysAddr, +/// }, +/// }; +/// use core::ops::Deref; /// /// // See also [`pci::Bar`] for a real example. /// struct IoMem(IoRaw); @@ -84,7 +98,7 @@ impl IoRaw { /// unsafe fn new(paddr: usize) -> Result{ /// // SAFETY: By the safety requirements of this function [`paddr`, `paddr` + `SIZE`) is /// // valid for `ioremap`. -/// let addr = unsafe { bindings::ioremap(paddr as bindings::phys_addr_t, SIZE) }; +/// let addr = unsafe { bindings::ioremap(paddr as PhysAddr, SIZE) }; /// if addr.is_null() { /// return Err(ENOMEM); /// } -- cgit