From: Andrew Ballance <andrewjballance@gmail.com>
To: dakr@kernel.org, a.hindborg@kernel.org, airlied@gmail.com,
akpm@linux-foundation.org, alex.gaynor@gmail.com,
aliceryhl@google.com, andrewjballance@gmail.com,
andriy.shevchenko@linux.intel.com, arnd@arndb.de,
benno.lossin@proton.me, bhelgaas@google.com,
bjorn3_gh@protonmail.com, boqun.feng@gmail.com,
daniel.almeida@collabora.com, fujita.tomonori@gmail.com,
gary@garyguo.net, gregkh@linuxfoundation.org,
kwilczynski@kernel.org, me@kloenk.dev, ojeda@kernel.org,
raag.jadav@intel.com, rafael@kernel.org, simona@ffwll.ch,
tmgross@umich.edu
Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
linux-pci@vger.kernel.org, nouveau@lists.freedesktop.org,
rust-for-linux@vger.kernel.org
Subject: [PATCH v2 1/6] rust: helpers: io: use macro to generate io accessor functions
Date: Wed, 14 May 2025 05:57:29 -0500 [thread overview]
Message-ID: <20250514105734.3898411-2-andrewjballance@gmail.com> (raw)
In-Reply-To: <20250514105734.3898411-1-andrewjballance@gmail.com>
From: Fiona Behrens <me@kloenk.dev>
Generate the `rust_helper_read{b,w,l,q}`, `rust_helper_write{b,w,l,q}`
and the relaxed version using a C macro.
This removes a lot of redundant code and is in preparation for pio
functions which uses a similar C macro.
Signed-off-by: Fiona Behrens <me@kloenk.dev>
Signed-off-by: Andrew Ballance <andrewjballance@gmail.com>
---
rust/helpers/io.c | 105 +++++++++++++---------------------------------
1 file changed, 29 insertions(+), 76 deletions(-)
diff --git a/rust/helpers/io.c b/rust/helpers/io.c
index 15ea187c5466..d419b5b3b7c7 100644
--- a/rust/helpers/io.c
+++ b/rust/helpers/io.c
@@ -12,90 +12,43 @@ void rust_helper_iounmap(void __iomem *addr)
iounmap(addr);
}
-u8 rust_helper_readb(const void __iomem *addr)
-{
- return readb(addr);
-}
-
-u16 rust_helper_readw(const void __iomem *addr)
-{
- return readw(addr);
-}
-
-u32 rust_helper_readl(const void __iomem *addr)
-{
- return readl(addr);
-}
-
+#define define_rust_io_read_helper(rust_name, name, type) \
+ type rust_name(void __iomem *addr) \
+ { \
+ return name(addr); \
+ }
+
+#define define_rust_io_write_helper(rust_name, name, type) \
+ void rust_name(type value, void __iomem *addr) \
+ { \
+ name(value, addr); \
+ }
+
+define_rust_io_read_helper(rust_helper_readb, readb, u8);
+define_rust_io_read_helper(rust_helper_readw, readw, u16);
+define_rust_io_read_helper(rust_helper_readl, readl, u32);
#ifdef CONFIG_64BIT
-u64 rust_helper_readq(const void __iomem *addr)
-{
- return readq(addr);
-}
+define_rust_io_read_helper(rust_helper_readq, readq, u64);
#endif
-void rust_helper_writeb(u8 value, void __iomem *addr)
-{
- writeb(value, addr);
-}
-
-void rust_helper_writew(u16 value, void __iomem *addr)
-{
- writew(value, addr);
-}
-
-void rust_helper_writel(u32 value, void __iomem *addr)
-{
- writel(value, addr);
-}
-
+define_rust_io_write_helper(rust_helper_writeb, writeb, u8);
+define_rust_io_write_helper(rust_helper_writew, writew, u16);
+define_rust_io_write_helper(rust_helper_writel, writel, u32);
#ifdef CONFIG_64BIT
-void rust_helper_writeq(u64 value, void __iomem *addr)
-{
- writeq(value, addr);
-}
+define_rust_io_write_helper(rust_helper_writeq, writeq, u64);
#endif
-u8 rust_helper_readb_relaxed(const void __iomem *addr)
-{
- return readb_relaxed(addr);
-}
-
-u16 rust_helper_readw_relaxed(const void __iomem *addr)
-{
- return readw_relaxed(addr);
-}
-
-u32 rust_helper_readl_relaxed(const void __iomem *addr)
-{
- return readl_relaxed(addr);
-}
-
+define_rust_io_read_helper(rust_helper_readb_relaxed, readb_relaxed, u8);
+define_rust_io_read_helper(rust_helper_readw_relaxed, readw_relaxed, u16);
+define_rust_io_read_helper(rust_helper_readl_relaxed, readl_relaxed, u32);
#ifdef CONFIG_64BIT
-u64 rust_helper_readq_relaxed(const void __iomem *addr)
-{
- return readq_relaxed(addr);
-}
+define_rust_io_read_helper(rust_helper_readq_relaxed, readq_relaxed, u64);
#endif
-void rust_helper_writeb_relaxed(u8 value, void __iomem *addr)
-{
- writeb_relaxed(value, addr);
-}
-
-void rust_helper_writew_relaxed(u16 value, void __iomem *addr)
-{
- writew_relaxed(value, addr);
-}
-
-void rust_helper_writel_relaxed(u32 value, void __iomem *addr)
-{
- writel_relaxed(value, addr);
-}
-
+define_rust_io_write_helper(rust_helper_writeb_relaxed, writeb_relaxed, u8);
+define_rust_io_write_helper(rust_helper_writew_relaxed, writew_relaxed, u16);
+define_rust_io_write_helper(rust_helper_writel_relaxed, writel_relaxed, u32);
#ifdef CONFIG_64BIT
-void rust_helper_writeq_relaxed(u64 value, void __iomem *addr)
-{
- writeq_relaxed(value, addr);
-}
+define_rust_io_write_helper(rust_helper_writeq_relaxed, writeq_relaxed, u64);
#endif
+
--
2.49.0
next prev parent reply other threads:[~2025-05-14 10:58 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-14 10:57 [PATCH v2 0/6] rust: add support for port io Andrew Ballance
2025-05-14 10:57 ` Andrew Ballance [this message]
2025-05-14 10:57 ` [PATCH v2 2/6] rust: io: make Io use IoAccess trait Andrew Ballance
2025-05-14 10:57 ` [PATCH v2 3/6] rust: io: add new Io type Andrew Ballance
2025-05-14 10:57 ` [PATCH v2 4/6] rust: io: implement Debug for IoRaw and add some doctests Andrew Ballance
2025-05-14 10:57 ` [PATCH v2 5/6] rust: io: add from_raw_cookie functions Andrew Ballance
2025-05-14 10:57 ` [PATCH v2 6/6] rust: pci: make Bar generic over Io Andrew Ballance
2025-06-16 8:03 ` [PATCH v2 0/6] rust: add support for port io Alice Ryhl
2025-06-16 9:04 ` Danilo Krummrich
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=20250514105734.3898411-2-andrewjballance@gmail.com \
--to=andrewjballance@gmail.com \
--cc=a.hindborg@kernel.org \
--cc=airlied@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=arnd@arndb.de \
--cc=benno.lossin@proton.me \
--cc=bhelgaas@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=fujita.tomonori@gmail.com \
--cc=gary@garyguo.net \
--cc=gregkh@linuxfoundation.org \
--cc=kwilczynski@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=me@kloenk.dev \
--cc=nouveau@lists.freedesktop.org \
--cc=ojeda@kernel.org \
--cc=raag.jadav@intel.com \
--cc=rafael@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=simona@ffwll.ch \
--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
all inboxes | Powered by JetHome®