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 <aliceryhl@google.com> 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 <dakr@kernel.org>
This commit is contained in:
committed by
Danilo Krummrich
parent
ee2776e54b
commit
dd6ff5cf56
@@ -52,8 +52,20 @@ struct Inner<T: Send> {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```no_run
|
||||
/// # use kernel::{bindings, device::{Bound, Device}, devres::Devres, io::{Io, IoRaw}};
|
||||
/// # use core::ops::Deref;
|
||||
/// use kernel::{
|
||||
/// bindings,
|
||||
/// device::{
|
||||
/// Bound,
|
||||
/// Device,
|
||||
/// },
|
||||
/// devres::Devres,
|
||||
/// io::{
|
||||
/// Io,
|
||||
/// IoRaw,
|
||||
/// PhysAddr,
|
||||
/// },
|
||||
/// };
|
||||
/// use core::ops::Deref;
|
||||
///
|
||||
/// // See also [`pci::Bar`] for a real example.
|
||||
/// struct IoMem<const SIZE: usize>(IoRaw<SIZE>);
|
||||
@@ -66,7 +78,7 @@ struct Inner<T: Send> {
|
||||
/// unsafe fn new(paddr: usize) -> Result<Self>{
|
||||
/// // 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);
|
||||
/// }
|
||||
|
||||
@@ -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<const SIZE: usize> IoRaw<SIZE> {
|
||||
/// # 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<const SIZE: usize>(IoRaw<SIZE>);
|
||||
@@ -84,7 +98,7 @@ impl<const SIZE: usize> IoRaw<SIZE> {
|
||||
/// unsafe fn new(paddr: usize) -> Result<Self>{
|
||||
/// // 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);
|
||||
/// }
|
||||
|
||||
@@ -16,7 +16,10 @@ use crate::{
|
||||
types::Opaque, //
|
||||
};
|
||||
|
||||
pub use super::ResourceSize;
|
||||
pub use super::{
|
||||
PhysAddr,
|
||||
ResourceSize, //
|
||||
};
|
||||
|
||||
/// A region allocated from a parent [`Resource`].
|
||||
///
|
||||
@@ -97,7 +100,7 @@ impl Resource {
|
||||
/// the region, or a part of it, is already in use.
|
||||
pub fn request_region(
|
||||
&self,
|
||||
start: ResourceSize,
|
||||
start: PhysAddr,
|
||||
size: ResourceSize,
|
||||
name: CString,
|
||||
flags: Flags,
|
||||
@@ -131,7 +134,7 @@ impl Resource {
|
||||
}
|
||||
|
||||
/// Returns the start address of the resource.
|
||||
pub fn start(&self) -> ResourceSize {
|
||||
pub fn start(&self) -> PhysAddr {
|
||||
let inner = self.0.get();
|
||||
// SAFETY: Safe as per the invariants of `Resource`.
|
||||
unsafe { (*inner).start }
|
||||
|
||||
Reference in New Issue
Block a user