[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <A0B919A0-5B44-4298-8696-026BCB96ED56@kloenk.dev>
Date: Mon, 13 Jan 2025 14:28:10 +0100
From: Fiona Behrens <me@...enk.dev>
To: Daniel Almeida <daniel.almeida@...labora.com>
Cc: Miguel Ojeda <ojeda@...nel.org>, Alex Gaynor <alex.gaynor@...il.com>,
Pavel Machek <pavel@....cz>, Lee Jones <lee@...nel.org>,
Jean Delvare <jdelvare@...e.com>, Boqun Feng <boqun.feng@...il.com>,
Gary Guo <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Benno Lossin <benno.lossin@...ton.me>,
Andreas Hindborg <a.hindborg@...nel.org>, Alice Ryhl <aliceryhl@...gle.com>,
Trevor Gross <tmgross@...ch.edu>, Mark Pearson <mpearson-lenovo@...ebb.ca>,
Peter Koch <pkoch@...ovo.com>, rust-for-linux@...r.kernel.org,
linux-leds@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2 4/5] rust: add I/O port abstractions with resource
management
Hi,
On 13 Jan 2025, at 14:15, Daniel Almeida wrote:
> Hi Fiona,
>
>> On 13 Jan 2025, at 09:16, Fiona Behrens <me@...enk.dev> wrote:
>>
>> This patch introduces abstractions for working with I/O port resources,
>> including the `Resource` and `Region` types. These abstractions facilitate
>> interaction with `ioport_resource`, enabling safe management of resource
>> reservations and memory accesses.
>>
>> Additionally, helper functions such as `outb`, `outw`, and `outl` have been
>> provided to write values to these resources, with matching read functions
>> such as `inb`, `inw`, and `inl` for accessing the port memory.
>>
>> Signed-off-by: Fiona Behrens <me@...enk.dev>
>> ---
>> rust/helpers/helpers.c | 1 +
>> rust/helpers/ioport.c | 42 ++++++++++
>> rust/kernel/ioport.rs | 169 +++++++++++++++++++++++++++++++++++++++++
>> rust/kernel/lib.rs | 2 +
>> 4 files changed, 214 insertions(+)
>> create mode 100644 rust/helpers/ioport.c
>> create mode 100644 rust/kernel/ioport.rs
>>
>> diff --git a/rust/helpers/helpers.c b/rust/helpers/helpers.c
>> index dcf827a61b52..b40aee82fa0f 100644
>> --- a/rust/helpers/helpers.c
>> +++ b/rust/helpers/helpers.c
>> @@ -14,6 +14,7 @@
>> #include "cred.c"
>> #include "err.c"
>> #include "fs.c"
>> +#include "ioport.c"
>> #include "jump_label.c"
>> #include "kunit.c"
>> #include "mutex.c"
>> diff --git a/rust/helpers/ioport.c b/rust/helpers/ioport.c
>> new file mode 100644
>> index 000000000000..d9c9e2093b98
>> --- /dev/null
>> +++ b/rust/helpers/ioport.c
>> @@ -0,0 +1,42 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +
>> +#include <linux/ioport.h>
>> +#include <linux/io.h>
>> +
>> +struct resource *rust_helper_request_region(resource_size_t start,
>> + resource_size_t n, const char *name)
>> +{
>> + return request_region(start, n, name);
>> +}
>> +
>> +struct resource *rust_helper_request_muxed_region(resource_size_t start,
>> + resource_size_t n,
>> + const char *name)
>> +{
>> + return request_muxed_region(start, n, name);
>> +}
>> +
>> +void rust_helper_release_region(resource_size_t start, resource_size_t n)
>> +{
>> + release_region(start, n);
>> +}
>> +
>> +#define define_rust_helper_out(name, type) \
>> + void rust_helper_##name(type value, unsigned long addr) \
>> + { \
>> + (name)(value, addr); \
>> + }
>> +
>> +define_rust_helper_out(outb, u8);
>> +define_rust_helper_out(outw, u16);
>> +define_rust_helper_out(outl, u32);
>> +
>> +#define define_rust_helper_in(name, type) \
>> + type rust_helper_##name(unsigned long addr) \
>> + { \
>> + return (name)(addr); \
>> + }
>> +
>> +define_rust_helper_in(inb, u8);
>> +define_rust_helper_in(inw, u16);
>> +define_rust_helper_in(inl, u32);
>> diff --git a/rust/kernel/ioport.rs b/rust/kernel/ioport.rs
>> new file mode 100644
>> index 000000000000..9bc342cb4663
>> --- /dev/null
>> +++ b/rust/kernel/ioport.rs
>> @@ -0,0 +1,169 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +
>> +//! Abstractions of routines for detecting, reserving and
>> +//! allocating system resources.
>> +//!
>> +//! C header: [`include/linux/ioport.h`](srctree/include/linux/ioport.h)
>> +
>> +use core::ops::Deref;
>> +use core::ptr;
>> +
>> +use crate::prelude::*;
>> +use crate::types::Opaque;
>> +
>> +/// Resource Size type.
>> +/// This is a type alias to `u64`
>> +/// depending on the config option `CONFIG_PHYS_ADDR_T_64BIT`.
>> +#[cfg(CONFIG_PHYS_ADDR_T_64BIT)]
>> +pub type ResourceSize = u64;
>> +
>> +/// Resource Size type.
>> +/// This is a type alias to `u32`
>> +/// depending on the config option `CONFIG_PHYS_ADDR_T_64BIT`.
>> +#[cfg(not(CONFIG_PHYS_ADDR_T_64BIT))]
>> +pub type ResourceSize = u32;
>> +
>> +/// Resource node.
>> +#[repr(transparent)]
>> +pub struct Resource(Opaque<bindings::resource>);
>
> This is a conflict with [0]
Ah missed that, only saw the IO abstraction in the same series but it did not work for my use case, and then somehow missed this, will rework to use that as base in the next version
Thanks
Fiona
>
> [0]: https://lore.kernel.org/rust-for-linux/20250109133057.243751-1-daniel.almeida@collabora.com/
>
> — Daniel
Powered by blists - more mailing lists