summaryrefslogtreecommitdiffstats
path: root/lib/physmem-access.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 18:30:56 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 18:30:56 +0000
commitd3114e0edc60508fc1e44e6cd2733fb2a97cdaca (patch)
tree82d66db664dea6ee75010455b98b04f47fcc4a90 /lib/physmem-access.h
parentInitial commit. (diff)
downloadpciutils-d3114e0edc60508fc1e44e6cd2733fb2a97cdaca.tar.xz
pciutils-d3114e0edc60508fc1e44e6cd2733fb2a97cdaca.zip
Adding upstream version 1:3.11.1.upstream/1%3.11.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'lib/physmem-access.h')
-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;
+}