summaryrefslogtreecommitdiffstats
path: root/lib/physmem-access.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--lib/physmem-access.h52
1 files changed, 52 insertions, 0 deletions
diff --git a/lib/physmem-access.h b/lib/physmem-access.h
new file mode 100644
index 0000000..a4e9744
--- /dev/null
+++ b/lib/physmem-access.h
@@ -0,0 +1,52 @@
+/*
+ * The PCI Library -- Compiler-specific wrappers for memory mapped I/O
+ *
+ * Copyright (c) 2023 Pali Rohár <pali@kernel.org>
+ *
+ * Can be freely distributed and used under the terms of the GNU GPL v2+
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+/*
+ * FIXME
+ * Unfortunately gcc does not provide architecture independent way to read from
+ * or write to memory mapped I/O. The best approximation is to use volatile and
+ * for the write operation follow it by the read operation from the same address.
+ */
+
+static inline void
+physmem_writeb(unsigned char value, volatile void *ptr)
+{
+ *(volatile unsigned char *)ptr = value;
+}
+
+static inline void
+physmem_writew(unsigned short value, volatile void *ptr)
+{
+ *(volatile unsigned short *)ptr = value;
+}
+
+static inline void
+physmem_writel(u32 value, volatile void *ptr)
+{
+ *(volatile u32 *)ptr = value;
+}
+
+static inline unsigned char
+physmem_readb(volatile void *ptr)
+{
+ return *(volatile unsigned char *)ptr;
+}
+
+static inline unsigned short
+physmem_readw(volatile void *ptr)
+{
+ return *(volatile unsigned short *)ptr;
+}
+
+static inline u32
+physmem_readl(volatile void *ptr)
+{
+ return *(volatile u32 *)ptr;
+}