diff mbox series

[RFC,v2,05/23] hw: add register access utility functions

Message ID 20240817102606.3996242-6-tavip@google.com (mailing list archive)
State New, archived
Headers show
Series NXP i.MX RT595, ARM SVD and device model unit tests | expand

Commit Message

Octavian Purdila Aug. 17, 2024, 10:25 a.m. UTC
Add register access utility functions for device models, like checking
aligned access.

Signed-off-by: Octavian Purdila <tavip@google.com>
---
 include/hw/regs.h | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
 create mode 100644 include/hw/regs.h
diff mbox series

Patch

diff --git a/include/hw/regs.h b/include/hw/regs.h
new file mode 100644
index 0000000000..692428af12
--- /dev/null
+++ b/include/hw/regs.h
@@ -0,0 +1,34 @@ 
+/*
+ * Useful macros/functions for register handling.
+ *
+ * Copyright (c) 2021 Google LLC
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#ifndef HW_REGS_H
+#define HW_REGS_H
+
+#include "exec/hwaddr.h"
+
+/*
+ * reg32_aligned_access
+ * @addr: address to check
+ * @size: size of access
+ *
+ * Check if access to a hardware address is 32bit aligned.
+ *
+ * Returns: true if access is 32bit aligned, false otherwise
+ */
+static inline bool reg32_aligned_access(hwaddr addr, unsigned size)
+{
+    if (size != 4 || addr % 4 != 0) {
+        return false;
+    }
+    return true;
+}
+
+#endif /* HW_REGS_H */