mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-03 07:43:54 -06:00
include: Add a header to define host PCI MMIO functions
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: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Farhan Ali <alifm@linux.ibm.com> Reviewed-by: Thomas Huth <thuth@redhat.com> Message-id: 20250430185012.2303-3-alifm@linux.ibm.com Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
parent
b17d69a1da
commit
40f940923f
1 changed files with 136 additions and 0 deletions
136
include/qemu/host-pci-mmio.h
Normal file
136
include/qemu/host-pci-mmio.h
Normal file
|
@ -0,0 +1,136 @@
|
|||
/*
|
||||
* 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_ldub_p(const void *ioaddr)
|
||||
{
|
||||
uint8_t ret = 0;
|
||||
#ifdef __s390x__
|
||||
ret = s390x_pci_mmio_read_8(ioaddr);
|
||||
#else
|
||||
ret = ldub_p(ioaddr);
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline uint16_t host_pci_lduw_le_p(const void *ioaddr)
|
||||
{
|
||||
uint16_t ret = 0;
|
||||
#ifdef __s390x__
|
||||
ret = le16_to_cpu(s390x_pci_mmio_read_16(ioaddr));
|
||||
#else
|
||||
ret = lduw_le_p(ioaddr);
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline uint32_t host_pci_ldl_le_p(const void *ioaddr)
|
||||
{
|
||||
uint32_t ret = 0;
|
||||
#ifdef __s390x__
|
||||
ret = le32_to_cpu(s390x_pci_mmio_read_32(ioaddr));
|
||||
#else
|
||||
ret = ldl_le_p(ioaddr);
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline uint64_t host_pci_ldq_le_p(const void *ioaddr)
|
||||
{
|
||||
uint64_t ret = 0;
|
||||
#ifdef __s390x__
|
||||
ret = le64_to_cpu(s390x_pci_mmio_read_64(ioaddr));
|
||||
#else
|
||||
ret = ldq_le_p(ioaddr);
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline void host_pci_stb_p(void *ioaddr, uint8_t val)
|
||||
{
|
||||
#ifdef __s390x__
|
||||
s390x_pci_mmio_write_8(ioaddr, val);
|
||||
#else
|
||||
stb_p(ioaddr, val);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void host_pci_stw_le_p(void *ioaddr, uint16_t val)
|
||||
{
|
||||
#ifdef __s390x__
|
||||
s390x_pci_mmio_write_16(ioaddr, cpu_to_le16(val));
|
||||
#else
|
||||
stw_le_p(ioaddr, val);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void host_pci_stl_le_p(void *ioaddr, uint32_t val)
|
||||
{
|
||||
#ifdef __s390x__
|
||||
s390x_pci_mmio_write_32(ioaddr, cpu_to_le32(val));
|
||||
#else
|
||||
stl_le_p(ioaddr, val);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void host_pci_stq_le_p(void *ioaddr, uint64_t val)
|
||||
{
|
||||
#ifdef __s390x__
|
||||
s390x_pci_mmio_write_64(ioaddr, cpu_to_le64(val));
|
||||
#else
|
||||
stq_le_p(ioaddr, val);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline uint64_t host_pci_ldn_le_p(const void *ioaddr, int sz)
|
||||
{
|
||||
switch (sz) {
|
||||
case 1:
|
||||
return host_pci_ldub_p(ioaddr);
|
||||
case 2:
|
||||
return host_pci_lduw_le_p(ioaddr);
|
||||
case 4:
|
||||
return host_pci_ldl_le_p(ioaddr);
|
||||
case 8:
|
||||
return host_pci_ldq_le_p(ioaddr);
|
||||
default:
|
||||
g_assert_not_reached();
|
||||
}
|
||||
}
|
||||
|
||||
static inline void host_pci_stn_le_p(void *ioaddr, int sz, uint64_t v)
|
||||
{
|
||||
switch (sz) {
|
||||
case 1:
|
||||
host_pci_stb_p(ioaddr, v);
|
||||
break;
|
||||
case 2:
|
||||
host_pci_stw_le_p(ioaddr, v);
|
||||
break;
|
||||
case 4:
|
||||
host_pci_stl_le_p(ioaddr, v);
|
||||
break;
|
||||
case 8:
|
||||
host_pci_stq_le_p(ioaddr, v);
|
||||
break;
|
||||
default:
|
||||
g_assert_not_reached();
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue