Rust for Linux List
 help / color / mirror / Atom feed
From: Daniel Almeida <daniel.almeida@collabora.com>
To: Fiona Behrens <me@kloenk.dev>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
	"Alex Gaynor" <alex.gaynor@gmail.com>,
	"Pavel Machek" <pavel@ucw.cz>, "Lee Jones" <lee@kernel.org>,
	"Jean Delvare" <jdelvare@suse.com>,
	"Boqun Feng" <boqun.feng@gmail.com>,
	"Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <benno.lossin@proton.me>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Mark Pearson" <mpearson-lenovo@squebb.ca>,
	"Peter Koch" <pkoch@lenovo.com>,
	rust-for-linux@vger.kernel.org, linux-leds@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 4/5] rust: add I/O port abstractions with resource management
Date: Mon, 13 Jan 2025 10:15:35 -0300	[thread overview]
Message-ID: <9C204B39-B714-452D-8F90-8FE426470244@collabora.com> (raw)
In-Reply-To: <20250113121620.21598-5-me@kloenk.dev>

Hi Fiona,

> On 13 Jan 2025, at 09:16, Fiona Behrens <me@kloenk.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@kloenk.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]

[0]: https://lore.kernel.org/rust-for-linux/20250109133057.243751-1-daniel.almeida@collabora.com/

— Daniel

  reply	other threads:[~2025-01-13 13:16 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-13 12:16 [PATCH v2 0/5] Rust LED Driver Abstractions and Lenovo SE10 Driver with DMI and I/O Port Support Fiona Behrens
2025-01-13 12:16 ` [PATCH v2 1/5] rust: dmi: Add abstractions for DMI Fiona Behrens
2025-01-13 12:16 ` [PATCH v2 2/5] rust: leds: Add Rust bindings for LED subsystem Fiona Behrens
2025-01-13 13:10   ` Miguel Ojeda
2025-01-13 12:16 ` [PATCH v2 3/5] rust: leds: Add hardware trigger support for hardware-controlled LEDs Fiona Behrens
2025-01-20 10:35   ` Marek Behún
2025-01-20 10:59     ` Fiona Behrens
2025-01-20 14:18       ` Marek Behún
2025-01-13 12:16 ` [PATCH v2 4/5] rust: add I/O port abstractions with resource management Fiona Behrens
2025-01-13 13:15   ` Daniel Almeida [this message]
2025-01-13 13:28     ` Fiona Behrens
2025-01-13 12:16 ` [PATCH v2 5/5] leds: leds_lenovo_se10: LED driver for Lenovo SE10 platform Fiona Behrens
2025-01-17 17:21   ` Mark Pearson
2025-01-17 17:31     ` Fiona Behrens
2025-01-17 18:02       ` Mark Pearson
2025-01-17 17:43     ` Miguel Ojeda
2025-01-20 10:47   ` Marek Behún

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9C204B39-B714-452D-8F90-8FE426470244@collabora.com \
    --to=daniel.almeida@collabora.com \
    --cc=a.hindborg@kernel.org \
    --cc=alex.gaynor@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=benno.lossin@proton.me \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=gary@garyguo.net \
    --cc=jdelvare@suse.com \
    --cc=lee@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=me@kloenk.dev \
    --cc=mpearson-lenovo@squebb.ca \
    --cc=ojeda@kernel.org \
    --cc=pavel@ucw.cz \
    --cc=pkoch@lenovo.com \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tmgross@umich.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox