From: Oleksii Kurochko <oleksii.kurochko@gmail.com>
To: xen-devel@lists.xenproject.org
Cc: Oleksii Kurochko <oleksii.kurochko@gmail.com>,
Alistair Francis <alistair.francis@wdc.com>,
Bob Eshleman <bobbyeshleman@gmail.com>,
Connor Davis <connojdavis@gmail.com>,
Andrew Cooper <andrew.cooper3@citrix.com>,
George Dunlap <george.dunlap@citrix.com>,
Jan Beulich <jbeulich@suse.com>, Julien Grall <julien@xen.org>,
Stefano Stabellini <sstabellini@kernel.org>
Subject: [PATCH v10 04/14] xen/riscv: introduce bitops.h
Date: Fri, 17 May 2024 15:54:53 +0200 [thread overview]
Message-ID: <91a359cb03c150ca01b52bfcab696612a847d283.1715952103.git.oleksii.kurochko@gmail.com> (raw)
In-Reply-To: <cover.1715952103.git.oleksii.kurochko@gmail.com>
Taken from Linux-6.4.0-rc1
Xen's bitops.h consists of several Linux's headers:
* linux/arch/include/asm/bitops.h:
* The following function were removed as they aren't used in Xen:
* test_and_set_bit_lock
* clear_bit_unlock
* __clear_bit_unlock
* The following functions were renamed in the way how they are
used by common code:
* __test_and_set_bit
* __test_and_clear_bit
* The declaration and implementation of the following functios
were updated to make Xen build happy:
* clear_bit
* set_bit
* __test_and_clear_bit
* __test_and_set_bit
Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
---
Changes in V10:
- update the error message BITS_PER_LONG -> BITOP_BITS_PER_WORD
---
Changes in V9:
- add Acked-by: Jan Beulich <jbeulich@suse.com>
- drop redefinition of bitop_uint_t in asm/types.h as some operation in Xen common code expects
to work with 32-bit quantities.
- s/BITS_PER_LONG/BITOP_BITS_PER_WORD in asm/bitops.h around __AMO() macros.
---
Changes in V8:
- define bitop_uint_t in <asm/types.h> after the changes in patch related to introduction of
"introduce generic non-atomic test_*bit()".
- drop duplicated __set_bit() and __clear_bit().
- drop duplicated comment: /* Based on linux/arch/include/asm/bitops.h */.
- update type of res and mask in test_and_op_bit_ord(): unsigned long -> bitop_uint_t.
- drop 1 padding blank in test_and_op_bit_ord().
- update definition of test_and_set_bit(),test_and_clear_bit(),test_and_change_bit:
change return type to bool.
- change addr argument type of test_and_change_bit(): unsigned long * -> void *.
- move test_and_change_bit() closer to other test_and-s function.
- Code style fixes: tabs -> space.
- s/#undef __op_bit/#undef op_bit.
- update the commit message: delete information about generic-non-atomic.h changes as now
it is a separate patch.
---
Changes in V7:
- Update the commit message.
- Drop "__" for __op_bit and __op_bit_ord as they are atomic.
- add comment above __set_bit and __clear_bit about why they are defined as atomic.
- align bitops_uint_t with __AMO().
- make changes after generic non-atomic test_*bit() were changed.
- s/__asm__ __volatile__/asm volatile
---
Changes in V6:
- rebase clean ups were done: drop unused asm-generic includes
---
Changes in V5:
- new patch
---
xen/arch/riscv/include/asm/bitops.h | 137 ++++++++++++++++++++++++++++
1 file changed, 137 insertions(+)
create mode 100644 xen/arch/riscv/include/asm/bitops.h
diff --git a/xen/arch/riscv/include/asm/bitops.h b/xen/arch/riscv/include/asm/bitops.h
new file mode 100644
index 0000000000..7f7af3fda1
--- /dev/null
+++ b/xen/arch/riscv/include/asm/bitops.h
@@ -0,0 +1,137 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (C) 2012 Regents of the University of California */
+
+#ifndef _ASM_RISCV_BITOPS_H
+#define _ASM_RISCV_BITOPS_H
+
+#include <asm/system.h>
+
+#if BITOP_BITS_PER_WORD == 64
+#define __AMO(op) "amo" #op ".d"
+#elif BITOP_BITS_PER_WORD == 32
+#define __AMO(op) "amo" #op ".w"
+#else
+#error "Unexpected BITOP_BITS_PER_WORD"
+#endif
+
+/* Based on linux/arch/include/asm/bitops.h */
+
+/*
+ * Non-atomic bit manipulation.
+ *
+ * Implemented using atomics to be interrupt safe. Could alternatively
+ * implement with local interrupt masking.
+ */
+#define __set_bit(n, p) set_bit(n, p)
+#define __clear_bit(n, p) clear_bit(n, p)
+
+#define test_and_op_bit_ord(op, mod, nr, addr, ord) \
+({ \
+ bitop_uint_t res, mask; \
+ mask = BITOP_MASK(nr); \
+ asm volatile ( \
+ __AMO(op) #ord " %0, %2, %1" \
+ : "=r" (res), "+A" (addr[BITOP_WORD(nr)]) \
+ : "r" (mod(mask)) \
+ : "memory"); \
+ ((res & mask) != 0); \
+})
+
+#define op_bit_ord(op, mod, nr, addr, ord) \
+ asm volatile ( \
+ __AMO(op) #ord " zero, %1, %0" \
+ : "+A" (addr[BITOP_WORD(nr)]) \
+ : "r" (mod(BITOP_MASK(nr))) \
+ : "memory");
+
+#define test_and_op_bit(op, mod, nr, addr) \
+ test_and_op_bit_ord(op, mod, nr, addr, .aqrl)
+#define op_bit(op, mod, nr, addr) \
+ op_bit_ord(op, mod, nr, addr, )
+
+/* Bitmask modifiers */
+#define NOP(x) (x)
+#define NOT(x) (~(x))
+
+/**
+ * test_and_set_bit - Set a bit and return its old value
+ * @nr: Bit to set
+ * @addr: Address to count from
+ */
+static inline bool test_and_set_bit(int nr, volatile void *p)
+{
+ volatile bitop_uint_t *addr = p;
+
+ return test_and_op_bit(or, NOP, nr, addr);
+}
+
+/**
+ * test_and_clear_bit - Clear a bit and return its old value
+ * @nr: Bit to clear
+ * @addr: Address to count from
+ */
+static inline bool test_and_clear_bit(int nr, volatile void *p)
+{
+ volatile bitop_uint_t *addr = p;
+
+ return test_and_op_bit(and, NOT, nr, addr);
+}
+
+/**
+ * test_and_change_bit - Toggle (change) a bit and return its old value
+ * @nr: Bit to change
+ * @addr: Address to count from
+ *
+ * This operation is atomic and cannot be reordered.
+ * It also implies a memory barrier.
+ */
+static inline bool test_and_change_bit(int nr, volatile void *p)
+{
+ volatile bitop_uint_t *addr = p;
+
+ return test_and_op_bit(xor, NOP, nr, addr);
+}
+
+/**
+ * set_bit - Atomically set a bit in memory
+ * @nr: the bit to set
+ * @addr: the address to start counting from
+ *
+ * Note that @nr may be almost arbitrarily large; this function is not
+ * restricted to acting on a single-word quantity.
+ */
+static inline void set_bit(int nr, volatile void *p)
+{
+ volatile bitop_uint_t *addr = p;
+
+ op_bit(or, NOP, nr, addr);
+}
+
+/**
+ * clear_bit - Clears a bit in memory
+ * @nr: Bit to clear
+ * @addr: Address to start counting from
+ */
+static inline void clear_bit(int nr, volatile void *p)
+{
+ volatile bitop_uint_t *addr = p;
+
+ op_bit(and, NOT, nr, addr);
+}
+
+#undef test_and_op_bit
+#undef op_bit
+#undef NOP
+#undef NOT
+#undef __AMO
+
+#endif /* _ASM_RISCV_BITOPS_H */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
--
2.45.0
next prev parent reply other threads:[~2024-05-17 13:55 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-17 13:54 [PATCH v10 00/14] Enable build of full Xen for RISC-V Oleksii Kurochko
2024-05-17 13:54 ` [PATCH v10 01/14] xen/riscv: disable unnecessary configs Oleksii Kurochko
2024-05-17 13:54 ` [PATCH v10 02/14] xen: introduce generic non-atomic test_*bit() Oleksii Kurochko
2024-05-21 11:10 ` Jan Beulich
2024-05-23 13:00 ` Julien Grall
2024-05-23 14:11 ` Oleksii K.
2024-05-23 14:33 ` Julien Grall
2024-05-23 16:40 ` Oleksii K.
2024-05-24 6:48 ` Jan Beulich
2024-05-24 7:25 ` Oleksii K.
2024-05-24 7:35 ` Jan Beulich
2024-05-24 8:06 ` Oleksii K.
2024-05-24 8:58 ` Oleksii K.
2024-05-24 9:17 ` Julien Grall
2024-05-17 13:54 ` [PATCH v10 03/14] xen/bitops: implement fls{l}() in common logic Oleksii Kurochko
2024-05-21 11:18 ` Jan Beulich
2024-05-22 7:37 ` Oleksii K.
2024-05-22 8:15 ` Jan Beulich
2024-05-23 13:21 ` Julien Grall
2024-05-17 13:54 ` Oleksii Kurochko [this message]
2024-05-17 13:54 ` [PATCH v10 05/14] xen/riscv: introduce cmpxchg.h Oleksii Kurochko
2024-05-17 13:54 ` [PATCH v10 06/14] xen/riscv: introduce atomic.h Oleksii Kurochko
2024-05-17 13:54 ` [PATCH v10 07/14] xen/riscv: introduce monitor.h Oleksii Kurochko
2024-05-18 1:11 ` Tamas K Lengyel
2024-05-17 13:54 ` [PATCH v10 08/14] xen/riscv: add definition of __read_mostly Oleksii Kurochko
2024-05-17 13:54 ` [PATCH v10 09/14] xen/riscv: add required things to current.h Oleksii Kurochko
2024-05-17 13:54 ` [PATCH v10 10/14] xen/riscv: add minimal stuff to mm.h to build full Xen Oleksii Kurochko
2024-05-17 13:55 ` [PATCH v10 11/14] xen/riscv: introduce vm_event_*() functions Oleksii Kurochko
2024-05-18 1:12 ` Tamas K Lengyel
2024-05-17 13:55 ` [PATCH v10 12/14] xen/riscv: add minimal amount of stubs to build full Xen Oleksii Kurochko
2024-05-17 13:55 ` [PATCH v10 13/14] xen/riscv: enable full Xen build Oleksii Kurochko
2024-05-17 13:55 ` [PATCH v10 14/14] xen/README: add compiler and binutils versions for RISC-V64 Oleksii Kurochko
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=91a359cb03c150ca01b52bfcab696612a847d283.1715952103.git.oleksii.kurochko@gmail.com \
--to=oleksii.kurochko@gmail.com \
--cc=alistair.francis@wdc.com \
--cc=andrew.cooper3@citrix.com \
--cc=bobbyeshleman@gmail.com \
--cc=connojdavis@gmail.com \
--cc=george.dunlap@citrix.com \
--cc=jbeulich@suse.com \
--cc=julien@xen.org \
--cc=sstabellini@kernel.org \
--cc=xen-devel@lists.xenproject.org \
/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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).