system/memory: Define address_space_ldst[W] endian variants via template
Like we do for other LD/ST APIs, use one template to declare and define all endianness variants of the address_space_ldst[W] methods. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Message-ID: <20260109165058.59144-8-philmd@linaro.org>
This commit is contained in:
@@ -3305,6 +3305,7 @@ F: system/ioport.c
|
||||
F: system/memory.c
|
||||
F: system/memory_mapping.c
|
||||
F: system/physmem.c
|
||||
F: system/memory_ldst*
|
||||
F: system/memory-internal.h
|
||||
F: system/ram-block-attributes.c
|
||||
F: scripts/coccinelle/memory-region-housekeeping.cocci
|
||||
|
||||
@@ -19,24 +19,16 @@
|
||||
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
uint16_t glue(address_space_lduw, SUFFIX)(ARG1_DECL,
|
||||
hwaddr addr, MemTxAttrs attrs, MemTxResult *result);
|
||||
uint32_t glue(address_space_ldl, SUFFIX)(ARG1_DECL,
|
||||
hwaddr addr, MemTxAttrs attrs, MemTxResult *result);
|
||||
uint64_t glue(address_space_ldq, SUFFIX)(ARG1_DECL,
|
||||
hwaddr addr, MemTxAttrs attrs, MemTxResult *result);
|
||||
void glue(address_space_stw, SUFFIX)(ARG1_DECL,
|
||||
hwaddr addr, uint16_t val, MemTxAttrs attrs, MemTxResult *result);
|
||||
void glue(address_space_stl, SUFFIX)(ARG1_DECL,
|
||||
hwaddr addr, uint32_t val, MemTxAttrs attrs, MemTxResult *result);
|
||||
void glue(address_space_stq, SUFFIX)(ARG1_DECL,
|
||||
hwaddr addr, uint64_t val, MemTxAttrs attrs, MemTxResult *result);
|
||||
uint8_t glue(address_space_ldub, SUFFIX)(ARG1_DECL,
|
||||
hwaddr addr, MemTxAttrs attrs, MemTxResult *result);
|
||||
uint16_t glue(address_space_lduw_le, SUFFIX)(ARG1_DECL,
|
||||
hwaddr addr, MemTxAttrs attrs, MemTxResult *result);
|
||||
uint16_t glue(address_space_lduw_be, SUFFIX)(ARG1_DECL,
|
||||
hwaddr addr, MemTxAttrs attrs, MemTxResult *result);
|
||||
uint32_t glue(address_space_ldl_le, SUFFIX)(ARG1_DECL,
|
||||
hwaddr addr, MemTxAttrs attrs, MemTxResult *result);
|
||||
uint32_t glue(address_space_ldl_be, SUFFIX)(ARG1_DECL,
|
||||
@@ -47,10 +39,6 @@ uint64_t glue(address_space_ldq_be, SUFFIX)(ARG1_DECL,
|
||||
hwaddr addr, MemTxAttrs attrs, MemTxResult *result);
|
||||
void glue(address_space_stb, SUFFIX)(ARG1_DECL,
|
||||
hwaddr addr, uint8_t val, MemTxAttrs attrs, MemTxResult *result);
|
||||
void glue(address_space_stw_le, SUFFIX)(ARG1_DECL,
|
||||
hwaddr addr, uint16_t val, MemTxAttrs attrs, MemTxResult *result);
|
||||
void glue(address_space_stw_be, SUFFIX)(ARG1_DECL,
|
||||
hwaddr addr, uint16_t val, MemTxAttrs attrs, MemTxResult *result);
|
||||
void glue(address_space_stl_le, SUFFIX)(ARG1_DECL,
|
||||
hwaddr addr, uint32_t val, MemTxAttrs attrs, MemTxResult *result);
|
||||
void glue(address_space_stl_be, SUFFIX)(ARG1_DECL,
|
||||
@@ -60,6 +48,15 @@ void glue(address_space_stq_le, SUFFIX)(ARG1_DECL,
|
||||
void glue(address_space_stq_be, SUFFIX)(ARG1_DECL,
|
||||
hwaddr addr, uint64_t val, MemTxAttrs attrs, MemTxResult *result);
|
||||
|
||||
#define ENDIANNESS
|
||||
#include "system/memory_ldst_endian.h.inc"
|
||||
|
||||
#define ENDIANNESS _le
|
||||
#include "system/memory_ldst_endian.h.inc"
|
||||
|
||||
#define ENDIANNESS _be
|
||||
#include "system/memory_ldst_endian.h.inc"
|
||||
|
||||
#undef ARG1_DECL
|
||||
#undef ARG1
|
||||
#undef SUFFIX
|
||||
|
||||
25
include/system/memory_ldst_endian.h.inc
Normal file
25
include/system/memory_ldst_endian.h.inc
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Physical memory access endian templates
|
||||
*
|
||||
* Copyright (c) 2003 Fabrice Bellard
|
||||
* Copyright (c) 2015 Linaro, Inc.
|
||||
* Copyright (c) 2016 Red Hat, Inc.
|
||||
* Copyright (c) 2025 Linaro Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#define ADDRESS_SPACE_LD(size) \
|
||||
glue(glue(address_space_ld, size), glue(ENDIANNESS, SUFFIX))
|
||||
#define ADDRESS_SPACE_ST(size) \
|
||||
glue(glue(address_space_st, size), glue(ENDIANNESS, SUFFIX))
|
||||
|
||||
uint16_t ADDRESS_SPACE_LD(uw)(ARG1_DECL, hwaddr addr,
|
||||
MemTxAttrs attrs, MemTxResult *result);
|
||||
void ADDRESS_SPACE_ST(w)(ARG1_DECL, hwaddr addr, uint16_t val,
|
||||
MemTxAttrs attrs, MemTxResult *result);
|
||||
|
||||
#undef ADDRESS_SPACE_LD
|
||||
#undef ADDRESS_SPACE_ST
|
||||
|
||||
#undef ENDIANNESS
|
||||
@@ -19,12 +19,6 @@
|
||||
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
static inline uint16_t glue(lduw_phys, SUFFIX)(ARG1_DECL, hwaddr addr)
|
||||
{
|
||||
return glue(address_space_lduw, SUFFIX)(ARG1, addr,
|
||||
MEMTXATTRS_UNSPECIFIED, NULL);
|
||||
}
|
||||
|
||||
static inline uint32_t glue(ldl_phys, SUFFIX)(ARG1_DECL, hwaddr addr)
|
||||
{
|
||||
return glue(address_space_ldl, SUFFIX)(ARG1, addr,
|
||||
@@ -37,12 +31,6 @@ static inline uint64_t glue(ldq_phys, SUFFIX)(ARG1_DECL, hwaddr addr)
|
||||
MEMTXATTRS_UNSPECIFIED, NULL);
|
||||
}
|
||||
|
||||
static inline void glue(stw_phys, SUFFIX)(ARG1_DECL, hwaddr addr, uint16_t val)
|
||||
{
|
||||
glue(address_space_stw, SUFFIX)(ARG1, addr, val,
|
||||
MEMTXATTRS_UNSPECIFIED, NULL);
|
||||
}
|
||||
|
||||
static inline void glue(stl_phys, SUFFIX)(ARG1_DECL, hwaddr addr, uint32_t val)
|
||||
{
|
||||
glue(address_space_stl, SUFFIX)(ARG1, addr, val,
|
||||
@@ -61,18 +49,6 @@ static inline uint8_t glue(ldub_phys, SUFFIX)(ARG1_DECL, hwaddr addr)
|
||||
MEMTXATTRS_UNSPECIFIED, NULL);
|
||||
}
|
||||
|
||||
static inline uint16_t glue(lduw_le_phys, SUFFIX)(ARG1_DECL, hwaddr addr)
|
||||
{
|
||||
return glue(address_space_lduw_le, SUFFIX)(ARG1, addr,
|
||||
MEMTXATTRS_UNSPECIFIED, NULL);
|
||||
}
|
||||
|
||||
static inline uint16_t glue(lduw_be_phys, SUFFIX)(ARG1_DECL, hwaddr addr)
|
||||
{
|
||||
return glue(address_space_lduw_be, SUFFIX)(ARG1, addr,
|
||||
MEMTXATTRS_UNSPECIFIED, NULL);
|
||||
}
|
||||
|
||||
static inline uint32_t glue(ldl_le_phys, SUFFIX)(ARG1_DECL, hwaddr addr)
|
||||
{
|
||||
return glue(address_space_ldl_le, SUFFIX)(ARG1, addr,
|
||||
@@ -103,18 +79,6 @@ static inline void glue(stb_phys, SUFFIX)(ARG1_DECL, hwaddr addr, uint8_t val)
|
||||
MEMTXATTRS_UNSPECIFIED, NULL);
|
||||
}
|
||||
|
||||
static inline void glue(stw_le_phys, SUFFIX)(ARG1_DECL, hwaddr addr, uint16_t val)
|
||||
{
|
||||
glue(address_space_stw_le, SUFFIX)(ARG1, addr, val,
|
||||
MEMTXATTRS_UNSPECIFIED, NULL);
|
||||
}
|
||||
|
||||
static inline void glue(stw_be_phys, SUFFIX)(ARG1_DECL, hwaddr addr, uint16_t val)
|
||||
{
|
||||
glue(address_space_stw_be, SUFFIX)(ARG1, addr, val,
|
||||
MEMTXATTRS_UNSPECIFIED, NULL);
|
||||
}
|
||||
|
||||
static inline void glue(stl_le_phys, SUFFIX)(ARG1_DECL, hwaddr addr, uint32_t val)
|
||||
{
|
||||
glue(address_space_stl_le, SUFFIX)(ARG1, addr, val,
|
||||
@@ -139,6 +103,15 @@ static inline void glue(stq_be_phys, SUFFIX)(ARG1_DECL, hwaddr addr, uint64_t va
|
||||
MEMTXATTRS_UNSPECIFIED, NULL);
|
||||
}
|
||||
|
||||
#define ENDIANNESS
|
||||
#include "system/memory_ldst_phys_endian.h.inc"
|
||||
|
||||
#define ENDIANNESS _le
|
||||
#include "system/memory_ldst_phys_endian.h.inc"
|
||||
|
||||
#define ENDIANNESS _be
|
||||
#include "system/memory_ldst_phys_endian.h.inc"
|
||||
|
||||
#undef ARG1_DECL
|
||||
#undef ARG1
|
||||
#undef SUFFIX
|
||||
|
||||
37
include/system/memory_ldst_phys_endian.h.inc
Normal file
37
include/system/memory_ldst_phys_endian.h.inc
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Physical memory access endian templates
|
||||
*
|
||||
* Copyright (c) 2003 Fabrice Bellard
|
||||
* Copyright (c) 2015 Linaro, Inc.
|
||||
* Copyright (c) 2016 Red Hat, Inc.
|
||||
* Copyright (c) 2025 Linaro Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#define LD_PHYS(size) \
|
||||
glue(glue(ld, size), glue(ENDIANNESS, glue(_phys, SUFFIX)))
|
||||
#define ADDRESS_SPACE_LD(size) \
|
||||
glue(glue(address_space_ld, size), glue(ENDIANNESS, SUFFIX))
|
||||
|
||||
#define ST_PHYS(size) \
|
||||
glue(glue(st, size), glue(ENDIANNESS, glue(_phys, SUFFIX)))
|
||||
#define ADDRESS_SPACE_ST(size) \
|
||||
glue(glue(address_space_st, size), glue(ENDIANNESS, SUFFIX))
|
||||
|
||||
static inline uint16_t LD_PHYS(uw)(ARG1_DECL, hwaddr addr)
|
||||
{
|
||||
return ADDRESS_SPACE_LD(uw)(ARG1, addr, MEMTXATTRS_UNSPECIFIED, NULL);
|
||||
}
|
||||
|
||||
static inline void ST_PHYS(w)(ARG1_DECL, hwaddr addr, uint16_t val)
|
||||
{
|
||||
ADDRESS_SPACE_ST(w)(ARG1, addr, val, MEMTXATTRS_UNSPECIFIED, NULL);
|
||||
}
|
||||
|
||||
#undef LD_PHYS
|
||||
#undef ST_PHYS
|
||||
#undef ADDRESS_SPACE_LD
|
||||
#undef ADDRESS_SPACE_ST
|
||||
|
||||
#undef ENDIANNESS
|
||||
@@ -240,27 +240,6 @@ static inline uint16_t glue(address_space_lduw_internal, SUFFIX)(ARG1_DECL,
|
||||
return val;
|
||||
}
|
||||
|
||||
uint16_t glue(address_space_lduw, SUFFIX)(ARG1_DECL,
|
||||
hwaddr addr, MemTxAttrs attrs, MemTxResult *result)
|
||||
{
|
||||
return glue(address_space_lduw_internal, SUFFIX)(ARG1, addr, attrs, result,
|
||||
DEVICE_NATIVE_ENDIAN);
|
||||
}
|
||||
|
||||
uint16_t glue(address_space_lduw_le, SUFFIX)(ARG1_DECL,
|
||||
hwaddr addr, MemTxAttrs attrs, MemTxResult *result)
|
||||
{
|
||||
return glue(address_space_lduw_internal, SUFFIX)(ARG1, addr, attrs, result,
|
||||
DEVICE_LITTLE_ENDIAN);
|
||||
}
|
||||
|
||||
uint16_t glue(address_space_lduw_be, SUFFIX)(ARG1_DECL,
|
||||
hwaddr addr, MemTxAttrs attrs, MemTxResult *result)
|
||||
{
|
||||
return glue(address_space_lduw_internal, SUFFIX)(ARG1, addr, attrs, result,
|
||||
DEVICE_BIG_ENDIAN);
|
||||
}
|
||||
|
||||
/* warning: addr must be aligned */
|
||||
static inline void glue(address_space_stl_internal, SUFFIX)(ARG1_DECL,
|
||||
hwaddr addr, uint32_t val, MemTxAttrs attrs,
|
||||
@@ -401,27 +380,6 @@ static inline void glue(address_space_stw_internal, SUFFIX)(ARG1_DECL,
|
||||
RCU_READ_UNLOCK();
|
||||
}
|
||||
|
||||
void glue(address_space_stw, SUFFIX)(ARG1_DECL,
|
||||
hwaddr addr, uint16_t val, MemTxAttrs attrs, MemTxResult *result)
|
||||
{
|
||||
glue(address_space_stw_internal, SUFFIX)(ARG1, addr, val, attrs, result,
|
||||
DEVICE_NATIVE_ENDIAN);
|
||||
}
|
||||
|
||||
void glue(address_space_stw_le, SUFFIX)(ARG1_DECL,
|
||||
hwaddr addr, uint16_t val, MemTxAttrs attrs, MemTxResult *result)
|
||||
{
|
||||
glue(address_space_stw_internal, SUFFIX)(ARG1, addr, val, attrs, result,
|
||||
DEVICE_LITTLE_ENDIAN);
|
||||
}
|
||||
|
||||
void glue(address_space_stw_be, SUFFIX)(ARG1_DECL,
|
||||
hwaddr addr, uint16_t val, MemTxAttrs attrs, MemTxResult *result)
|
||||
{
|
||||
glue(address_space_stw_internal, SUFFIX)(ARG1, addr, val, attrs, result,
|
||||
DEVICE_BIG_ENDIAN);
|
||||
}
|
||||
|
||||
static inline void glue(address_space_stq_internal, SUFFIX)(ARG1_DECL,
|
||||
hwaddr addr, uint64_t val, MemTxAttrs attrs,
|
||||
MemTxResult *result, enum device_endian endian)
|
||||
@@ -486,6 +444,18 @@ void glue(address_space_stq_be, SUFFIX)(ARG1_DECL,
|
||||
DEVICE_BIG_ENDIAN);
|
||||
}
|
||||
|
||||
#define ENDIANNESS
|
||||
#define DEVICE_ENDIANNESS DEVICE_NATIVE_ENDIAN
|
||||
#include "memory_ldst_endian.c.inc"
|
||||
|
||||
#define ENDIANNESS _le
|
||||
#define DEVICE_ENDIANNESS DEVICE_LITTLE_ENDIAN
|
||||
#include "memory_ldst_endian.c.inc"
|
||||
|
||||
#define ENDIANNESS _be
|
||||
#define DEVICE_ENDIANNESS DEVICE_BIG_ENDIAN
|
||||
#include "memory_ldst_endian.c.inc"
|
||||
|
||||
#undef ARG1_DECL
|
||||
#undef ARG1
|
||||
#undef SUFFIX
|
||||
|
||||
42
system/memory_ldst_endian.c.inc
Normal file
42
system/memory_ldst_endian.c.inc
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Physical memory access endian templates
|
||||
*
|
||||
* Copyright (c) 2003 Fabrice Bellard
|
||||
* Copyright (c) 2015 Linaro, Inc.
|
||||
* Copyright (c) 2016 Red Hat, Inc.
|
||||
* Copyright (c) 2025 Linaro Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#define ADDRESS_SPACE_LD(size) \
|
||||
glue(glue(address_space_ld, size), glue(ENDIANNESS, SUFFIX))
|
||||
#define ADDRESS_SPACE_LD_INTERNAL(size) \
|
||||
glue(glue(address_space_ld, size), glue(_internal, SUFFIX))
|
||||
|
||||
#define ADDRESS_SPACE_ST(size) \
|
||||
glue(glue(address_space_st, size), glue(ENDIANNESS, SUFFIX))
|
||||
#define ADDRESS_SPACE_ST_INTERNAL(size) \
|
||||
glue(glue(address_space_st, size), glue(_internal, SUFFIX))
|
||||
|
||||
uint16_t ADDRESS_SPACE_LD(uw)(ARG1_DECL, hwaddr addr,
|
||||
MemTxAttrs attrs, MemTxResult *result)
|
||||
{
|
||||
return ADDRESS_SPACE_LD_INTERNAL(uw)(ARG1, addr, attrs, result,
|
||||
DEVICE_ENDIANNESS);
|
||||
}
|
||||
|
||||
void ADDRESS_SPACE_ST(w)(ARG1_DECL, hwaddr addr, uint16_t val,
|
||||
MemTxAttrs attrs, MemTxResult *result)
|
||||
{
|
||||
ADDRESS_SPACE_ST_INTERNAL(w)(ARG1, addr, val, attrs, result,
|
||||
DEVICE_ENDIANNESS);
|
||||
}
|
||||
|
||||
#undef ADDRESS_SPACE_LD
|
||||
#undef ADDRESS_SPACE_LD_INTERNAL
|
||||
#undef ADDRESS_SPACE_ST
|
||||
#undef ADDRESS_SPACE_ST_INTERNAL
|
||||
|
||||
#undef ENDIANNESS
|
||||
#undef DEVICE_ENDIANNESS
|
||||
Reference in New Issue
Block a user