RP2040 APB peripherals share atomic XOR, SET and CLEAR alias windows.
Add common constants and an inline update helper so individual device
models do not duplicate this behavior.

Signed-off-by: Gilles Grimaud <[email protected]>
---
 MAINTAINERS              |  7 +++++++
 include/hw/misc/rp2040.h | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 39 insertions(+)
 create mode 100644 include/hw/misc/rp2040.h

diff --git a/MAINTAINERS b/MAINTAINERS
index 15c9b8bf2c..962988f94d 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1026,6 +1026,13 @@ F: docs/system/arm/raspi.rst
 F: tests/functional/arm/test_raspi2.py
 F: tests/functional/aarch64/test_raspi*.py
 
+Raspberry Pi Pico / RP2040
+M: Gilles Grimaud <[email protected]>
+L: [email protected]
+S: Maintained
+F: hw/*/rp2040*
+F: include/hw/*/rp2040*
+
 Real View
 M: Peter Maydell <[email protected]>
 L: [email protected]
diff --git a/include/hw/misc/rp2040.h b/include/hw/misc/rp2040.h
new file mode 100644
index 0000000000..13e05c9526
--- /dev/null
+++ b/include/hw/misc/rp2040.h
@@ -0,0 +1,32 @@
+/*
+ * RP2040 common peripheral helpers
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef HW_MISC_RP2040_H
+#define HW_MISC_RP2040_H
+
+#include "exec/hwaddr.h"
+
+#define RP2040_ATOMIC_ALIAS_MASK 0x3000
+#define RP2040_ATOMIC_XOR        0x1000
+#define RP2040_ATOMIC_SET        0x2000
+#define RP2040_ATOMIC_CLR        0x3000
+
+static inline uint32_t rp2040_atomic_update(uint32_t old, uint32_t value,
+                                            hwaddr alias)
+{
+    switch (alias) {
+    case RP2040_ATOMIC_XOR:
+        return old ^ value;
+    case RP2040_ATOMIC_SET:
+        return old | value;
+    case RP2040_ATOMIC_CLR:
+        return old & ~value;
+    default:
+        return value;
+    }
+}
+
+#endif
-- 
2.55.0


Reply via email to