2014-06-24 19:39:55 +02:00
|
|
|
/*
|
|
|
|
* Virtio Accessor Support: In case your target can change endian.
|
|
|
|
*
|
|
|
|
* Copyright IBM, Corp. 2013
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Rusty Russell <rusty@au.ibm.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
*/
|
2016-06-29 13:47:03 +02:00
|
|
|
|
|
|
|
#ifndef QEMU_VIRTIO_ACCESS_H
|
|
|
|
#define QEMU_VIRTIO_ACCESS_H
|
|
|
|
|
2019-08-12 07:23:31 +02:00
|
|
|
#include "exec/hwaddr.h"
|
2014-06-24 19:39:55 +02:00
|
|
|
#include "hw/virtio/virtio.h"
|
2016-12-30 11:09:10 +01:00
|
|
|
#include "hw/virtio/virtio-bus.h"
|
2014-06-24 19:39:55 +02:00
|
|
|
|
2016-05-31 10:09:54 +02:00
|
|
|
#if defined(TARGET_PPC64) || defined(TARGET_ARM)
|
|
|
|
#define LEGACY_VIRTIO_IS_BIENDIAN 1
|
|
|
|
#endif
|
|
|
|
|
2014-06-24 19:39:55 +02:00
|
|
|
static inline bool virtio_access_is_big_endian(VirtIODevice *vdev)
|
|
|
|
{
|
2016-05-31 10:09:54 +02:00
|
|
|
#if defined(LEGACY_VIRTIO_IS_BIENDIAN)
|
2016-02-05 11:46:18 +01:00
|
|
|
return virtio_is_big_endian(vdev);
|
2022-03-23 16:57:18 +01:00
|
|
|
#elif TARGET_BIG_ENDIAN
|
2015-08-17 11:48:29 +02:00
|
|
|
if (virtio_vdev_has_feature(vdev, VIRTIO_F_VERSION_1)) {
|
2015-06-04 12:34:11 +02:00
|
|
|
/* Devices conforming to VIRTIO 1.0 or later are always LE. */
|
|
|
|
return false;
|
|
|
|
}
|
2014-06-24 19:39:55 +02:00
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint16_t virtio_lduw_phys(VirtIODevice *vdev, hwaddr pa)
|
|
|
|
{
|
2016-12-30 11:09:10 +01:00
|
|
|
AddressSpace *dma_as = vdev->dma_as;
|
|
|
|
|
2014-06-24 19:39:55 +02:00
|
|
|
if (virtio_access_is_big_endian(vdev)) {
|
2016-12-30 11:09:10 +01:00
|
|
|
return lduw_be_phys(dma_as, pa);
|
2014-06-24 19:39:55 +02:00
|
|
|
}
|
2016-12-30 11:09:10 +01:00
|
|
|
return lduw_le_phys(dma_as, pa);
|
2014-06-24 19:39:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint32_t virtio_ldl_phys(VirtIODevice *vdev, hwaddr pa)
|
|
|
|
{
|
2016-12-30 11:09:10 +01:00
|
|
|
AddressSpace *dma_as = vdev->dma_as;
|
|
|
|
|
2014-06-24 19:39:55 +02:00
|
|
|
if (virtio_access_is_big_endian(vdev)) {
|
2016-12-30 11:09:10 +01:00
|
|
|
return ldl_be_phys(dma_as, pa);
|
2014-06-24 19:39:55 +02:00
|
|
|
}
|
2016-12-30 11:09:10 +01:00
|
|
|
return ldl_le_phys(dma_as, pa);
|
2014-06-24 19:39:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint64_t virtio_ldq_phys(VirtIODevice *vdev, hwaddr pa)
|
|
|
|
{
|
2016-12-30 11:09:10 +01:00
|
|
|
AddressSpace *dma_as = vdev->dma_as;
|
|
|
|
|
2014-06-24 19:39:55 +02:00
|
|
|
if (virtio_access_is_big_endian(vdev)) {
|
2016-12-30 11:09:10 +01:00
|
|
|
return ldq_be_phys(dma_as, pa);
|
2014-06-24 19:39:55 +02:00
|
|
|
}
|
2016-12-30 11:09:10 +01:00
|
|
|
return ldq_le_phys(dma_as, pa);
|
2014-06-24 19:39:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void virtio_stw_phys(VirtIODevice *vdev, hwaddr pa,
|
|
|
|
uint16_t value)
|
|
|
|
{
|
2016-12-30 11:09:10 +01:00
|
|
|
AddressSpace *dma_as = vdev->dma_as;
|
|
|
|
|
2014-06-24 19:39:55 +02:00
|
|
|
if (virtio_access_is_big_endian(vdev)) {
|
2016-12-30 11:09:10 +01:00
|
|
|
stw_be_phys(dma_as, pa, value);
|
2014-06-24 19:39:55 +02:00
|
|
|
} else {
|
2016-12-30 11:09:10 +01:00
|
|
|
stw_le_phys(dma_as, pa, value);
|
2014-06-24 19:39:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void virtio_stl_phys(VirtIODevice *vdev, hwaddr pa,
|
|
|
|
uint32_t value)
|
|
|
|
{
|
2016-12-30 11:09:10 +01:00
|
|
|
AddressSpace *dma_as = vdev->dma_as;
|
|
|
|
|
2014-06-24 19:39:55 +02:00
|
|
|
if (virtio_access_is_big_endian(vdev)) {
|
2016-12-30 11:09:10 +01:00
|
|
|
stl_be_phys(dma_as, pa, value);
|
2014-06-24 19:39:55 +02:00
|
|
|
} else {
|
2016-12-30 11:09:10 +01:00
|
|
|
stl_le_phys(dma_as, pa, value);
|
2014-06-24 19:39:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void virtio_stw_p(VirtIODevice *vdev, void *ptr, uint16_t v)
|
|
|
|
{
|
|
|
|
if (virtio_access_is_big_endian(vdev)) {
|
|
|
|
stw_be_p(ptr, v);
|
|
|
|
} else {
|
|
|
|
stw_le_p(ptr, v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void virtio_stl_p(VirtIODevice *vdev, void *ptr, uint32_t v)
|
|
|
|
{
|
|
|
|
if (virtio_access_is_big_endian(vdev)) {
|
|
|
|
stl_be_p(ptr, v);
|
|
|
|
} else {
|
|
|
|
stl_le_p(ptr, v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void virtio_stq_p(VirtIODevice *vdev, void *ptr, uint64_t v)
|
|
|
|
{
|
|
|
|
if (virtio_access_is_big_endian(vdev)) {
|
|
|
|
stq_be_p(ptr, v);
|
|
|
|
} else {
|
|
|
|
stq_le_p(ptr, v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int virtio_lduw_p(VirtIODevice *vdev, const void *ptr)
|
|
|
|
{
|
|
|
|
if (virtio_access_is_big_endian(vdev)) {
|
|
|
|
return lduw_be_p(ptr);
|
|
|
|
} else {
|
|
|
|
return lduw_le_p(ptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int virtio_ldl_p(VirtIODevice *vdev, const void *ptr)
|
|
|
|
{
|
|
|
|
if (virtio_access_is_big_endian(vdev)) {
|
|
|
|
return ldl_be_p(ptr);
|
|
|
|
} else {
|
|
|
|
return ldl_le_p(ptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint64_t virtio_ldq_p(VirtIODevice *vdev, const void *ptr)
|
|
|
|
{
|
|
|
|
if (virtio_access_is_big_endian(vdev)) {
|
|
|
|
return ldq_be_p(ptr);
|
|
|
|
} else {
|
|
|
|
return ldq_le_p(ptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint16_t virtio_tswap16(VirtIODevice *vdev, uint16_t s)
|
|
|
|
{
|
2022-03-23 16:57:17 +01:00
|
|
|
#if HOST_BIG_ENDIAN
|
2014-06-24 19:39:55 +02:00
|
|
|
return virtio_access_is_big_endian(vdev) ? s : bswap16(s);
|
|
|
|
#else
|
|
|
|
return virtio_access_is_big_endian(vdev) ? bswap16(s) : s;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-01-27 16:40:13 +01:00
|
|
|
static inline uint16_t virtio_lduw_phys_cached(VirtIODevice *vdev,
|
|
|
|
MemoryRegionCache *cache,
|
|
|
|
hwaddr pa)
|
|
|
|
{
|
|
|
|
if (virtio_access_is_big_endian(vdev)) {
|
|
|
|
return lduw_be_phys_cached(cache, pa);
|
|
|
|
}
|
|
|
|
return lduw_le_phys_cached(cache, pa);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint32_t virtio_ldl_phys_cached(VirtIODevice *vdev,
|
|
|
|
MemoryRegionCache *cache,
|
|
|
|
hwaddr pa)
|
|
|
|
{
|
|
|
|
if (virtio_access_is_big_endian(vdev)) {
|
|
|
|
return ldl_be_phys_cached(cache, pa);
|
|
|
|
}
|
|
|
|
return ldl_le_phys_cached(cache, pa);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint64_t virtio_ldq_phys_cached(VirtIODevice *vdev,
|
|
|
|
MemoryRegionCache *cache,
|
|
|
|
hwaddr pa)
|
|
|
|
{
|
|
|
|
if (virtio_access_is_big_endian(vdev)) {
|
|
|
|
return ldq_be_phys_cached(cache, pa);
|
|
|
|
}
|
|
|
|
return ldq_le_phys_cached(cache, pa);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void virtio_stw_phys_cached(VirtIODevice *vdev,
|
|
|
|
MemoryRegionCache *cache,
|
|
|
|
hwaddr pa, uint16_t value)
|
|
|
|
{
|
|
|
|
if (virtio_access_is_big_endian(vdev)) {
|
|
|
|
stw_be_phys_cached(cache, pa, value);
|
|
|
|
} else {
|
|
|
|
stw_le_phys_cached(cache, pa, value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void virtio_stl_phys_cached(VirtIODevice *vdev,
|
|
|
|
MemoryRegionCache *cache,
|
|
|
|
hwaddr pa, uint32_t value)
|
|
|
|
{
|
|
|
|
if (virtio_access_is_big_endian(vdev)) {
|
|
|
|
stl_be_phys_cached(cache, pa, value);
|
|
|
|
} else {
|
|
|
|
stl_le_phys_cached(cache, pa, value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-24 19:39:55 +02:00
|
|
|
static inline void virtio_tswap16s(VirtIODevice *vdev, uint16_t *s)
|
|
|
|
{
|
|
|
|
*s = virtio_tswap16(vdev, *s);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint32_t virtio_tswap32(VirtIODevice *vdev, uint32_t s)
|
|
|
|
{
|
2022-03-23 16:57:17 +01:00
|
|
|
#if HOST_BIG_ENDIAN
|
2014-06-24 19:39:55 +02:00
|
|
|
return virtio_access_is_big_endian(vdev) ? s : bswap32(s);
|
|
|
|
#else
|
|
|
|
return virtio_access_is_big_endian(vdev) ? bswap32(s) : s;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void virtio_tswap32s(VirtIODevice *vdev, uint32_t *s)
|
|
|
|
{
|
|
|
|
*s = virtio_tswap32(vdev, *s);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint64_t virtio_tswap64(VirtIODevice *vdev, uint64_t s)
|
|
|
|
{
|
2022-03-23 16:57:17 +01:00
|
|
|
#if HOST_BIG_ENDIAN
|
2014-06-24 19:39:55 +02:00
|
|
|
return virtio_access_is_big_endian(vdev) ? s : bswap64(s);
|
|
|
|
#else
|
|
|
|
return virtio_access_is_big_endian(vdev) ? bswap64(s) : s;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void virtio_tswap64s(VirtIODevice *vdev, uint64_t *s)
|
|
|
|
{
|
|
|
|
*s = virtio_tswap64(vdev, *s);
|
|
|
|
}
|
2016-06-29 13:47:03 +02:00
|
|
|
#endif /* QEMU_VIRTIO_ACCESS_H */
|