[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 2/3] include: Add a header to define host PCI MMIO functions
From: |
Farhan Ali |
Subject: |
[PATCH v3 2/3] include: Add a header to define host PCI MMIO functions |
Date: |
Tue, 1 Apr 2025 10:22:45 -0700 |
Add a generic API for host PCI MMIO reads/writes
(e.g. Linux VFIO BAR accesses). The functions access
little endian memory and returns the result in
host cpu endianness.
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Farhan Ali <alifm@linux.ibm.com>
---
include/qemu/host-pci-mmio.h | 116 +++++++++++++++++++++++++++++++++++
1 file changed, 116 insertions(+)
create mode 100644 include/qemu/host-pci-mmio.h
diff --git a/include/qemu/host-pci-mmio.h b/include/qemu/host-pci-mmio.h
new file mode 100644
index 0000000000..c26426524f
--- /dev/null
+++ b/include/qemu/host-pci-mmio.h
@@ -0,0 +1,116 @@
+/*
+ * API for host PCI MMIO accesses (e.g. Linux VFIO BARs)
+ *
+ * Copyright 2025 IBM Corp.
+ * Author(s): Farhan Ali <alifm@linux.ibm.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef HOST_PCI_MMIO_H
+#define HOST_PCI_MMIO_H
+
+#include "qemu/bswap.h"
+#include "qemu/s390x_pci_mmio.h"
+
+
+static inline uint8_t host_pci_mmio_read_8(const void *ioaddr)
+{
+ uint8_t ret = 0;
+#ifdef __s390x__
+ ret = s390x_pci_mmio_read_8(ioaddr);
+#else
+ /* Prevent the compiler from optimizing away the load */
+ ret = *((volatile uint8_t *)ioaddr);
+#endif
+
+ return ret;
+}
+
+static inline uint16_t host_pci_mmio_read_16(const void *ioaddr)
+{
+ uint16_t ret = 0;
+#ifdef __s390x__
+ ret = s390x_pci_mmio_read_16(ioaddr);
+#else
+ /* Prevent the compiler from optimizing away the load */
+ ret = *((volatile uint16_t *)ioaddr);
+#endif
+
+ return le16_to_cpu(ret);
+}
+
+static inline uint32_t host_pci_mmio_read_32(const void *ioaddr)
+{
+ uint32_t ret = 0;
+#ifdef __s390x__
+ ret = s390x_pci_mmio_read_32(ioaddr);
+#else
+ /* Prevent the compiler from optimizing away the load */
+ ret = *((volatile uint32_t *)ioaddr);
+#endif
+
+ return le32_to_cpu(ret);
+}
+
+static inline uint64_t host_pci_mmio_read_64(const void *ioaddr)
+{
+ uint64_t ret = 0;
+#ifdef __s390x__
+ ret = s390x_pci_mmio_read_64(ioaddr);
+#else
+ /* Prevent the compiler from optimizing away the load */
+ ret = *((volatile uint64_t *)ioaddr);
+#endif
+
+ return le64_to_cpu(ret);
+}
+
+static inline void host_pci_mmio_write_8(void *ioaddr, uint8_t val)
+{
+
+#ifdef __s390x__
+ s390x_pci_mmio_write_8(ioaddr, val);
+#else
+ /* Prevent the compiler from optimizing away the store */
+ *((volatile uint8_t *)ioaddr) = val;
+#endif
+}
+
+static inline void host_pci_mmio_write_16(void *ioaddr, uint16_t val)
+{
+ val = cpu_to_le16(val);
+
+#ifdef __s390x__
+ s390x_pci_mmio_write_16(ioaddr, val);
+#else
+ /* Prevent the compiler from optimizing away the store */
+ *((volatile uint16_t *)ioaddr) = val;
+#endif
+}
+
+static inline void host_pci_mmio_write_32(void *ioaddr, uint32_t val)
+{
+ val = cpu_to_le32(val);
+
+#ifdef __s390x__
+ s390x_pci_mmio_write_32(ioaddr, val);
+#else
+ /* Prevent the compiler from optimizing away the store */
+ *((volatile uint32_t *)ioaddr) = val;
+#endif
+}
+
+static inline void host_pci_mmio_write_64(void *ioaddr, uint64_t val)
+{
+ val = cpu_to_le64(val);
+
+#ifdef __s390x__
+ s390x_pci_mmio_write_64(ioaddr, val);
+#else
+ /* Prevent the compiler from optimizing away the store */
+ *((volatile uint64_t *)ioaddr) = val;
+#endif
+}
+
+#endif
--
2.43.0
- [PATCH v3 0/3] Enable QEMU NVMe userspace driver on s390x, Farhan Ali, 2025/04/01
- [PATCH v3 1/3] util: Add functions for s390x mmio read/write, Farhan Ali, 2025/04/01
- [PATCH v3 2/3] include: Add a header to define host PCI MMIO functions,
Farhan Ali <=
- [PATCH v3 3/3] block/nvme: Use host PCI MMIO API, Farhan Ali, 2025/04/01
- Re: [PATCH v3 0/3] Enable QEMU NVMe userspace driver on s390x, Stefan Hajnoczi, 2025/04/02
- Re: [PATCH v3 0/3] Enable QEMU NVMe userspace driver on s390x, Niklas Schnelle, 2025/04/03
- Re: [PATCH v3 0/3] Enable QEMU NVMe userspace driver on s390x, Stefan Hajnoczi, 2025/04/03
- Re: [PATCH v3 0/3] Enable QEMU NVMe userspace driver on s390x, Alex Williamson, 2025/04/03
- Re: [PATCH v3 0/3] Enable QEMU NVMe userspace driver on s390x, Farhan Ali, 2025/04/03
- Re: [PATCH v3 0/3] Enable QEMU NVMe userspace driver on s390x, Alex Williamson, 2025/04/03
- Re: [PATCH v3 0/3] Enable QEMU NVMe userspace driver on s390x, Farhan Ali, 2025/04/03
- Re: [PATCH v3 0/3] Enable QEMU NVMe userspace driver on s390x, Alex Williamson, 2025/04/03