system/memory: Clean ups around address_space_ldst() endian variants
v5 cover system/memory: Clean ups around address_space_ldst() endian variants
Missing review: 2, 12, 20
Since v4:
- No change (RESEND)
Since v3:
- Assign device_endian enums (Richard)
- Add/use ldm_p() and stm_p() helpers (Paolo)
Since v2:
- Changed opt-out to opt-in approach (Pierrick)
- Split big patches in smaller ones
- Mark ioport little-endian
Philippe Mathieu-Daudé (22):
MAINTAINERS: Cover 'system/memory_ldst*.h.inc' files
util: Introduce ldm_p() and stm_p() load/store helpers system/physmem: Inline and remove leul_to_cpu() system/physmem: Convert DEBUG_SUBPAGE printf() to trace events system/memory: Split MemoryRegionCache API to 'memory_cached.h' system/memory: Inline address_space_stq_internal() system/memory: Define address_space_ldst[W] endian variants via
template
system/memory: Define address_space_ldst[L] endian variants via
template
system/memory: Define address_space_ldst[Q] endian variants via
template
system/memory: Factor address_space_ldst[M]_internal() helper out system/memory: Pass device_endian argument as MemOp bit system/memory: Use ldm_p() and stm_p() helpers system/memory: Directly call address_space_ldst[M]_internal() helper
system: Allow restricting the legacy ld/st_phys() 'native-endian' API
system: Allow restricting legacy address_space_ldst() native-endian
API
system: Allow restricting the legacy cpu_ld/st() 'native-endian' API
system: Allow restricting the legacy translator_ld() 'native-endian'
API
system: Allow restricting the legacy tswap() 'native-endian' API
system: Allow restricting the legacy MO_TE* 'native-endian'
definitions
system: Allow restricting the legacy DEVICE_NATIVE_ENDIAN definition system/ioport: Declare x86-specific I/O port in little-endian order system/ioport: Do not open-code address_space_ld/st_le() methods
MAINTAINERS | 4 + include/accel/tcg/cpu-ldst.h | 2 + include/exec/memop.h | 4 + include/exec/translator.h | 5 +- include/exec/tswap.h | 3 + include/hw/virtio/virtio-access.h | 1 + include/qemu/bswap.h | 11 - include/qemu/ldst_unaligned.h | 25 ++ include/system/memory.h | 193 +------- include/system/memory_cached.h | 212 +++++++++ system/memory-internal.h | 2 + include/system/memory_ldst.h.inc | 52 +-- include/system/memory_ldst_endian.h.inc | 33 ++ include/system/memory_ldst_phys.h.inc | 113 +---- include/system/memory_ldst_phys_endian.h.inc | 57 +++ system/ioport.c | 34 +- system/physmem.c | 35 +- tests/qtest/endianness-test.c | 10 +- tests/qtest/libqtest.c | 13 +- util/ldst.c | 69 +++ system/memory_ldst.c.inc | 449 ++----------------- system/memory_ldst_endian.c.inc | 70 +++ scripts/make-config-poison.sh | 1 + system/trace-events | 6 + util/meson.build | 1 + 25 files changed, 599 insertions(+), 806 deletions(-) create mode 100644 include/system/memory_cached.h create mode 100644 include/system/memory_ldst_endian.h.inc create mode 100644 include/system/memory_ldst_phys_endian.h.inc create mode 100644 util/ldst.c create mode 100644 system/memory_ldst_endian.c.inc
Signature · 1 line
2.52.0
PATCH v5 1/22 MAINTAINERS: Cover 'system/memory_ldst*.h.inc' files
Missed in commit c611228c0ed ("include: move memory_ldst* to include/system").
--- MAINTAINERS | 1 + 1 file changed, 1 insertion(+)
MAINTAINERS +1 -0
@@ -3260,6 +3260,7 @@ F: include/exec/memop.h F: include/qemu/ldst_unaligned.h F: include/system/ram_addr.h F: include/system/memory.h +F: include/system/memory_ldst* F: include/system/physmem.h F: include/system/ramblock.h F: include/system/memory_mapping.h
Signature · 1 line
2.52.0
PATCH v5 2/22 util: Introduce ldm_p() and stm_p() load/store helpers
In reply to Philippe Mathieu-DaudéIntroduce load/store helpers which take a MemOp argument.
--- MAINTAINERS | 1 + include/qemu/ldst_unaligned.h | 25 +++++++++++++ util/ldst.c | 69 +++++++++++++++++++++++++++++++++++ util/meson.build | 1 + 4 files changed, 96 insertions(+) create mode 100644 util/ldst.c
MAINTAINERS +1 -0
@@ -3272,6 +3272,7 @@ F: system/physmem.c F: system/memory-internal.h F: system/ram-block-attributes.c F: scripts/coccinelle/memory-region-housekeeping.cocci +F: util/ldst.c Memory devices M: David Hildenbrand <[email protected]>
include/qemu/ldst_unaligned.h +25 -0
@@ -6,6 +6,8 @@#ifndef QEMU_LDST_UNALIGNED_H #define QEMU_LDST_UNALIGNED_H +#include "exec/memop.h" +/* * Any compiler worth its salt will turn these memcpy into native unaligned * operations. Thus we don't need to play games with packed attributes, or
@@ -64,4 +66,27 @@ static inline void stq_unaligned_p(void *ptr, uint64_t v) __builtin_memcpy(ptr, &v, sizeof(v)); } +/** +* ldm_p: Load value from host memory (byteswapping if necessary) +* +* @ptr: the host pointer to be accessed +* @mop: #MemOp mask containing access size and optional byteswapping +* +* Convert the value stored at @ptr in host memory and byteswap if necessary. +* +* Returns: the converted value. +*/ +uint64_t ldm_p (const void *ptr,MemOp mop); + +/** +* stm_p: Store value to host memory (byteswapping if necessary) +* +* @ptr: the host pointer to be accessed +* @mop: #MemOp mask containing access size and optional byteswapping +* @val: the value to store +* +* Convert the value (byteswap if necessary) and stored at @ptr in host memory. +*/ +void stm_p (void *ptr,MemOp mop,uint64_t val); +#endif
util/ldst.c new file +69 -0
69 lines not on this page · raw message
util/meson.build +1 -0
@@ -38,6 +38,7 @@ util_ss.add(files('envlist.c', 'path.c', 'module.c')) util_ss.add(files('event.c')) util_ss.add(files('host-utils.c')) util_ss.add(files('bitmap.c', 'bitops.c')) +util_ss.add(files('ldst.c')) util_ss.add(files('fifo8.c')) util_ss.add(files('cacheflush.c')) util_ss.add(files('error.c', 'error-report.c'))
Signature · 1 line
2.52.0
Re: [PATCH v5 02/22] util: Introduce ldm_p() and stm_p() load/store helpers
Il ven 9 gen 2026, 17:51 Philippe Mathieu-Daudé <[email protected]> ha scritto:
Quoted 4 lines
Introduce load/store helpers which take a MemOp argument.
Inspired-by Paolo Bonzini <[email protected]>
That's a new one. :)
I think they should be inline and so should be address_space_{ld,st}m_internal (maybe even always_inline). The amount of optimization enabled by constant MemOp is huge.
One other small change:
+ const unsigned size = memop_size(mop);
Quoted 2 lines
+
uint64_tval;
This must be initialized to zero.
Otherwise the whole series looks great, thanks. Sorry again for delaying my review.
Paolo
+ uint8_t *pval = (uint8_t *)&val;
Quoted 66 lines
util/ldst.c new file +50
-0+ +if (HOST_BIG_ENDIAN ) { + pval +=sizeof (val) - size; + } + +__builtin_memcpy (pval, ptr, size); +if (unlikely (mop &MO_BSWAP )) { +switch (size) { +case sizeof (uint16_t ): + val =__builtin_bswap16 (val); +break ; +case sizeof (uint32_t ): + val =__builtin_bswap32 (val); +break ; +case sizeof (uint64_t ): + val =__builtin_bswap64 (val); +break ; +default : +g_assert_not_reached (); + } + } +return val; +} + +void stm_p (void *ptr,MemOp mop,uint64_t val) +{ +const unsigned size =memop_size (mop); +const uint8_t *pval = (const uint8_t *)&val; + +if (HOST_BIG_ENDIAN ) { + pval +=sizeof (val) - size; + } + +if (unlikely (mop &MO_BSWAP )) { +switch (size) { +case sizeof (uint16_t ): + val =__builtin_bswap16 (val); +break ; +case sizeof (uint32_t ): + val =__builtin_bswap32 (val); +break ; +case sizeof (uint64_t ): + val =__builtin_bswap64 (val); +break ; +default : +g_assert_not_reached (); + } + } +__builtin_memcpy (ptr, pval, size); +}util/meson.build +1
-1@@ -38,6 +38,7 @@ util_ss.add(files('envlist.c', 'path.c', 'module.c')) util_ss.add(files('event.c')) util_ss.add(files('host-utils.c')) util_ss.add(files('bitmap.c', 'bitops.c')) +util_ss.add(files('ldst.c')) util_ss.add(files('fifo8.c')) util_ss.add(files('cacheflush.c')) util_ss.add(files('error.c', 'error-report.c')) --2.52.0
Re: [PATCH v5 02/22] util: Introduce ldm_p() and stm_p() load/store helpers
Quoted 4 lines · Paolo Bonzini
Il ven 9 gen 2026, 17:51 Philippe Mathieu-Daudé <[email protected] <mailto:[email protected]>> ha scritto:
Quoted 8 lines
Introduce load/store helpers which take a MemOp argument.
Inspired-by Paolo Bonzini <[email protected] <mailto:[email protected]>>That's a new one. :)
I think they should be inline and so should be address_space_{ld,st}m_internal (maybe even
always_inline). The amount of optimization enabled by constant MemOp is huge.
When are we going to have constant MemOp?
r~
Re: [PATCH v5 02/22] util: Introduce ldm_p() and stm_p() load/store helpers
Quoted 7 lines · Richard Henderson
Quoted 6 lines · Paolo Bonzini
Il ven 9 gen 2026, 17:51 Philippe Mathieu-Daudé <[email protected] <mailto:[email protected]>> ha scritto:
Introduce load/store helpers which take a MemOp argument.
Quoted 8 lines
Quoted 6 lines
Inspired-by Paolo Bonzini <[email protected] <mailto:[email protected]>>That's a new one. :)
I think they should be inline and so should be address_space_{ld,st}
m_internal(maybe evenalways_inline). The amount of optimization enabled by constant MemOp is huge.When are we going to have constant MemOp?
Every time address_space_{ld,st}m_internal is called, it's done with constant MemOp. For example:
uint16_t ADDRESS_SPACE_LD(uw)(ARG1_DECL, hwaddr addr,
MemTxAttrs attrs, MemTxResult *result)
{
return ADDRESS_SPACE_LD_INTERNAL(m)(ARG1, MO_ENDIAN | MO_16,
addr, attrs, result);
}
Paolo
Re: [PATCH v5 02/22] util: Introduce ldm_p() and stm_p() load/store helpers
In reply to Philippe Mathieu-DaudéQuoted 18 lines · Philippe Mathieu-Daudé
util/ldst.c new file +18
-0+uint64_t ldm_p (const void *ptr,MemOp mop) +{ +const unsigned size =memop_size (mop); +uint64_t val; +uint8_t *pval = (uint8_t *)&val; + +if (HOST_BIG_ENDIAN ) { + pval +=sizeof (val) - size; + } + +__builtin_memcpy (pval, ptr, size); +if (unlikely (mop &MO_BSWAP )) { +switch (size) { +case sizeof (uint16_t ): + val =__builtin_bswap16 (val); +break ; +case sizeof (uint32_t ): + val =__builtin_bswap32 (val);
util/ldst.c line 42
Quoted 10 lines
util/ldst.c new file +10
-0+break ; +case sizeof (uint64_t ): + val =__builtin_bswap64 (val); +break ; +default : +g_assert_not_reached (); + } + } +return val; +}
I'm not fond of the pointer arithmetic or the code structure.
Perhaps better as
switch (mop & (MO_BSWAP | MO_SIZE)) {
case MO_LEUW:
return lduw_le_p(ptr);
case MO_BEUW:
return lduw_be_p(ptr);
...
default:
g_assert_not_reached();
}which would hopefully compile to host endian-swapping load insns like
.L1:
mov (ptr), %eax ret .L2: movbe (ptr), %eax ret .L3: mov (ptr), %rax ret .L4: movbe (ptr), %rax ret
etc.
And the default case assert makes sure that we're not passing garbage, or too large MO_SIZE.
r~
Re: [PATCH v5 02/22] util: Introduce ldm_p() and stm_p() load/store helpers
Quoted 14 lines · Richard Henderson
I'm not fond of the pointer arithmetic or the code structure.
Perhaps better as
switch (mop & (
MO_BSWAP|MO_SIZE)) {
caseMO_LEUW:
returnlduw_le_p(ptr);
caseMO_BEUW:
returnlduw_be_p(ptr);
...
default:
g_assert_not_reached();
}
Quoted 8 lines
which would hopefully compile to host endian-swapping load insns like
.L1:
mov (ptr), %eax ret .L2: movbe (ptr), %eax ret
It only might do so for 32-bits, because movbe also bundles a free 32->64-bit zero extension, but not for the smaller ones. Thinking about which, I think ldm_p also needs to handle MO_SIGN? It can be done all in one with
static inline uint64_t ldm_p(const void *ptr, MemOp mop)
{
const unsigned size = memop_size(mop);
uint64_t val;
uint8_t *pval = (uint8_t *)&val;
if (HOST_BIG_ENDIAN) {
pval += sizeof(val) - size;
}
assert(size < 8);
__builtin_memcpy(pval, ptr, size);
if (mop & MO_BSWAP) {
val = __builtin_bswap64(val);
} else if (mop & MO_SIGN) {
val <<= (64 - 8 * size);
} else {
return val;
}
if (mop & MO_SIGN) {
return ((int64_t) val) >> (64 - 8 * size);
} else {
return val >> (64 - 8 * size);
}
}static inline void stm_p(void *ptr, uint64_t val, MemOp mop)
{
const unsigned size = memop_size(mop);
uint8_t *pval = (uint8_t *)&val;
assert(size < 8);
if ((mop & MO_BSWAP)) {
val = __builtin_bswap64(val) >> (64 - size * 8);
}
if (HOST_BIG_ENDIAN) {
pval += sizeof(val) - size;
}
__builtin_memcpy(ptr, pval, size);
}When inlining ldm_p, GCC is able to generate movzx/movsx instruction but doesn't recognize bswap64 + right shift as a smaller-width bswap + zero extension; clang does. Neither is able to generate movbe instructions, though.
I attach a standalone file I played with.
Paolo
#include <stdint.h>
#include <assert.h>
typedef enum MemOp {
MO_16 = 1,
MO_32 = 2,
MO_SIZE = 7,
MO_SIGN = 8,
MO_BSWAP = 16,
} MemOp;extern void __attribute__((noreturn)) g_assert_not_reached(void);
static inline int memop_size(MemOp x)
{
return 1 << (x & MO_SIZE);
}static inline uint64_t ldm_p(const void *ptr, MemOp mop)
{
const unsigned size = memop_size(mop);
uint64_t val;
uint8_t *pval = (uint8_t *)&val;
assert(size < 8);
__builtin_memcpy(pval, ptr, size);
if (mop & MO_BSWAP) {
val = __builtin_bswap64(val);
} else if (mop & MO_SIGN) {
val <<= (64 - 8 * size);
} else {
return val;
}
if (mop & MO_SIGN) {
return ((int64_t) val) >> (64 - 8 * size);
} else {
return val >> (64 - 8 * size);
}
}static inline void stm_p(void *ptr, uint64_t val, MemOp mop)
{
const unsigned size = memop_size(mop);
uint8_t *pval = (uint8_t *)&val;
assert(size < 8);
if ((mop & MO_BSWAP)) {
val = __builtin_bswap64(val) >> (64 - size * 8);
}
__builtin_memcpy(ptr, pval, size);
}uint32_t lduw_be_p(const void *ptr)
{
return ldm_p(ptr, MO_16 | MO_BSWAP);
}uint32_t ldsw_le_p(const void *ptr)
{
return ldm_p(ptr, MO_16 | MO_SIGN);
}uint32_t ldsl_be_p(const void *ptr)
{
return ldm_p(ptr, MO_32 | MO_BSWAP | MO_SIGN);
}void stl_be_p(void *ptr, uint32_t val)
{
stm_p(ptr, val, MO_32 | MO_BSWAP | MO_SIGN);
}Re: [PATCH v5 02/22] util: Introduce ldm_p() and stm_p() load/store helpers
Quoted 38 lines · Paolo Bonzini
Quoted 14 lines · Richard Henderson
I'm not fond of the pointer arithmetic or the code structure.
Perhaps better as
switch (mop & (
MO_BSWAP|MO_SIZE)) {
caseMO_LEUW:
returnlduw_le_p(ptr);
caseMO_BEUW:
returnlduw_be_p(ptr);
...
default:
g_assert_not_reached();
}Quoted 8 lines
which would hopefully compile to host endian-swapping load insns like
.L1:
mov (ptr), %eax
ret
.L2:
movbe (ptr), %eax
retIt only might do so for 32-bits, because movbe also bundles a free 32-
Quoted 1 line
64-bit zero extension, but not for the smaller ones. Thinking about
which, I think
ldm_palso needs to handle MO_SIGN? It can be done all in one withstatic inline
uint64_tldm_p(const void *ptr, MemOp mop){
const unsigned size =memop_size(mop);uint64_tval;
uint8_t*pval = (uint8_t*)&val;if (
HOST_BIG_ENDIAN) {
pval += sizeof(val) - size;
}
Quoted 6 lines
assert(size < 8);
__builtin_memcpy(pval, ptr, size);if (mop &
MO_BSWAP) {
val =__builtin_bswap64(val);
} else if (mop &MO_SIGN) {
Can't we have both MO_BSWAP && MO_SIGN bits set?
Quoted 34 lines
val <<= (64 - 8 * size);
} else {
return val;
}if (mop &
MO_SIGN) {
return ((int64_t) val) >> (64 - 8 * size); } else {
return val >> (64 - 8 * size);
}
}static inline void
stm_p(void *ptr, uint64_t val, MemOp mop){
const unsigned size =memop_size(mop);uint8_t*pval = (uint8_t*)&val;assert(size < 8);
if ((mop &MO_BSWAP)) {
val =__builtin_bswap64(val)>> (64 - size * 8); }if (
HOST_BIG_ENDIAN) {
pval += sizeof(val) - size;
}
__builtin_memcpy(ptr, pval, size);
}When inlining
ldm_p, GCC is able to generate movzx/movsx instruction but doesn't recognize bswap64 + right shift as a smaller-width bswap + zero extension; clang does. Neither is able to generate movbe instructions, though.I attach a standalone file I played with.
Paolo
Re: [PATCH v5 02/22] util: Introduce ldm_p() and stm_p() load/store helpers
Quoted 37 lines · Philippe Mathieu-Daudé
Quoted 36 lines · Paolo Bonzini
Quoted 14 lines · Richard Henderson
I'm not fond of the pointer arithmetic or the code structure.
Perhaps better as
switch (mop & (
MO_BSWAP|MO_SIZE)) {
caseMO_LEUW:
returnlduw_le_p(ptr);
caseMO_BEUW:
returnlduw_be_p(ptr);
...
default:
g_assert_not_reached();
}Quoted 8 lines
which would hopefully compile to host endian-swapping load insns like
.L1:
mov (ptr), %eax
ret
.L2:
movbe (ptr), %eax
retIt only might do so for 32-bits, because movbe also bundles a free 32- >64-bit zero extension, but not for the smaller ones. Thinking about which, I think
ldm_palso needs to handle MO_SIGN? It can be done all in one withstatic inline
uint64_tldm_p(const void *ptr, MemOp mop){
const unsigned size =memop_size(mop);uint64_tval;
uint8_t*pval = (uint8_t*)&val;if (
HOST_BIG_ENDIAN) {
pval += sizeof(val) - size;
}
Quoted 19 lines
Quoted 6 lines
assert(size < 8);
__builtin_memcpy(pval, ptr, size);if (mop &
MO_BSWAP) {
val =__builtin_bswap64(val);
} else if (mop &MO_SIGN) {Can't we have both
MO_BSWAP&&MO_SIGNbits set?Quoted 10 lines
val <<= (64 - 8 * size);
} else {
return val;
}if (mop &
MO_SIGN) {
return ((int64_t) val) >> (64 - 8 * size); } else {
return val >> (64 - 8 * size);
}
Yes, but that's handled by always using bswap64 so that the lsb ends up at the msb, and the shift takes care of the sign extend.
r~
PATCH v5 3/22 system/physmem: Inline and remove leul_to_cpu()
In reply to Philippe Mathieu-Daudéleul_to_cpu() is only used within physmem.c: inline it and remove.
Since @bitmap is of 'unsigned long' type, use its size with ldn_le_p() instead of using HOST_LONG_BITS.
--- include/qemu/bswap.h | 11 ----------- system/physmem.c | 5 +++-- 2 files changed, 3 insertions(+), 13 deletions(-)
include/qemu/bswap.h +0 -11
@@ -315,17 +315,6 @@ static inline void stq_be_p(void *ptr, uint64_t v)stq_unaligned_p (ptr,be_bswap (v,64 )); } -static inline unsigned long leul_to_cpu (unsigned long v) -{ -#if HOST_LONG_BITS ==32 -return le_bswap (v,32 ); -#elif HOST_LONG_BITS ==64 -return le_bswap (v,64 ); -#else -# error Unknown sizeof long -#endif -} -/* Store v to p as a sz byte value in host order */ #define DO_STN_LDN_P (END ) \ static inline void stn_## END ## _p(void *ptr, int sz, uint64_t v) \
system/physmem.c +3 -2
@@ -1272,7 +1272,8 @@ uint64_t physical_memory_set_dirty_lebitmap(unsigned long *bitmap,for (k =0 ; k < nr; k++) {if (bitmap[k]) { -unsigned long temp =leul_to_cpu (bitmap[k]); +unsigned long temp =ldn_le_p (&bitmap[k], +sizeof (bitmap[k])); nbits =ctpopl (temp);qatomic_or (&blocks[DIRTY_MEMORY_VGA ][idx][offset], temp);
@@ -1319,7 +1320,7 @@ uint64_t physical_memory_set_dirty_lebitmap(unsigned long *bitmap,*/ for (i =0 ; i < len; i++) {if (bitmap[i] !=0 ) { - c =leul_to_cpu (bitmap[i]); + c =ldn_le_p (&bitmap[i],sizeof (bitmap[i])); nbits =ctpopl (c);if (unlikely (global_dirty_tracking &GLOBAL_DIRTY_DIRTY_RATE )) { total_dirty_pages += nbits;
Signature · 1 line
2.52.0
PATCH v5 4/22 system/physmem: Convert DEBUG_SUBPAGE printf() to trace events
In reply to Philippe Mathieu-DaudéDefining DEBUG_SUBPAGE allows to use raw printf() statements to print information about some events; convert these to tracepoints.
--- system/physmem.c | 29 ++++++----------------------- system/trace-events | 6 ++++++ 2 files changed, 12 insertions(+), 23 deletions(-)
system/physmem.c +6 -23
@@ -91,8 +91,6 @@#include "memory-internal.h" -//#define DEBUG_SUBPAGE -/* ram_list is read under rcu_read_lock()/rcu_read_unlock(). Writes * are protected by the ramlist lock. */
@@ -2921,10 +2919,7 @@ static MemTxResult subpage_read(void *opaque, hwaddr addr, uint64_t *data,uint8_t buf[8 ];MemTxResult res; -#if defined(DEBUG_SUBPAGE ) -printf ("%s: subpage %p len %u addr " HWADDR_FMT_plx"\n" , __func__, - subpage, len, addr); -#endif +trace_subpage_read (subpage, len, addr); res =flatview_read (subpage->fv, addr + subpage->base, attrs, buf, len);if (res) {return res;
@@ -2939,11 +2934,7 @@ static MemTxResult subpage_write(void *opaque, hwaddr addr,subpage_t *subpage = opaque;uint8_t buf[8 ]; -#if defined(DEBUG_SUBPAGE ) -printf ("%s: subpage %p len %u addr " HWADDR_FMT_plx -" value %" PRIx64"\n" , - __func__, subpage, len, addr, value); -#endif +trace_subpage_write (subpage, len, addr, value);stn_p (buf, len, value);return flatview_write (subpage->fv, addr + subpage->base, attrs, buf, len); }
@@ -2953,10 +2944,8 @@ static bool subpage_accepts(void *opaque, hwaddr addr, MemTxAttrs attrs) {subpage_t *subpage = opaque; -#if defined(DEBUG_SUBPAGE ) -printf ("%s: subpage %p %c len %u addr " HWADDR_FMT_plx"\n" , - __func__, subpage, is_write ?'w' :'r' , len, addr); -#endif + +trace_subpage_accepts (subpage, is_write ?'w' :'r' , len, addr);return flatview_access_valid (subpage->fv, addr + subpage->base, len, is_write, attrs);
@@ -2982,10 +2971,7 @@ static int subpage_register(subpage_t *mmio, uint32_t start, uint32_t end,return -1 ; idx =SUBPAGE_IDX (start); eidx =SUBPAGE_IDX (end); -#if defined(DEBUG_SUBPAGE ) -printf ("%s: %p start %08x end %08x idx %08x eidx %08x section %d\n" , - __func__, mmio, start, end, idx, eidx, section); -#endif +trace_subpage_register (mmio, start, end, idx, eidx, section);for (; idx <= eidx; idx++) { mmio->sub_section[idx] = section; }
@@ -3004,10 +2990,7 @@ static subpage_t *subpage_init(FlatView *fv, hwaddr base)memory_region_init_io (&mmio->iomem,NULL , &subpage_ops, mmio,NULL ,TARGET_PAGE_SIZE ); mmio->iomem.subpage = true; -#if defined(DEBUG_SUBPAGE ) -printf ("%s: %p base " HWADDR_FMT_plx" len %08x\n" , __func__, - mmio, base,TARGET_PAGE_SIZE ); -#endif +trace_subpage_init (mmio, base,TARGET_PAGE_SIZE );return mmio; }
system/trace-events +6 -0
@@ -35,6 +35,12 @@ find_ram_offset_loop(uint64_t size, uint64_t candidate, uint64_t offset, uint64_ ram_block_discard_range(const char *rbname, void *hva, size_t length, bool need_madvise, bool need_fallocate, int ret) "%s@%p + 0x%zx: madvise: %d fallocate: %d ret: %d" qemu_ram_alloc_shared(const char *name, size_t size, size_t max_size, int fd, void *host) "%s size %zu max_size %zu fd %d host %p" +subpage_register(void *subpage, uint32_t start, uint32_t end, int idx, int eidx, uint16_t section) "subpage %p start 0x%08x end 0x%08x idx 0x%08x eidx 0x%08x section %u" +subpage_init(void *subpage, uint64_t base, uint64_t len) "subpage %p base 0x%08" PRIx64 " len 0x%08" PRIx64 +subpage_accepts(void *subpage, char access, unsigned len, uint64_t addr) "subpage %p %c len %u addr 0x%" PRIx64 +subpage_read(void *subpage, unsigned len, uint64_t addr) "subpage %p len %u addr 0x%" PRIx64 +subpage_write(void *subpage, unsigned len, uint64_t addr, uint64_t value) "subpage %p len %u addr 0x%" PRIx64 " value 0x%" PRIx64 + # cpus.c vm_stop_flush_all(int ret) "ret %d"
Signature · 1 line
2.52.0
PATCH v5 5/22 system/memory: Split MemoryRegionCache API to 'memory_cached.h'
In reply to Philippe Mathieu-DaudéWe have 115 direct inclusions of "system/memory.h", and 91 headers in include/ use it: hundreds of files have to process it. However only one single header really uses the MemoryRegionCache
API: "hw/virtio/virtio-access.h". Split it out to a new header, avoiding processing unused inlined functions hundreds of times.
--- MAINTAINERS | 1 + include/hw/virtio/virtio-access.h | 1 + include/system/memory.h | 185 -------------------------- include/system/memory_cached.h | 210 ++++++++++++++++++++++++++++++ system/physmem.c | 1 + 5 files changed, 213 insertions(+), 185 deletions(-) create mode 100644 include/system/memory_cached.h
MAINTAINERS +1 -0
@@ -3260,6 +3260,7 @@ F: include/exec/memop.h F: include/qemu/ldst_unaligned.h F: include/system/ram_addr.h F: include/system/memory.h +F: include/system/memory_cached.h F: include/system/memory_ldst* F: include/system/physmem.h F: include/system/ramblock.h
include/hw/virtio/virtio-access.h +1 -0
@@ -17,6 +17,7 @@#define QEMU_VIRTIO_ACCESS_H #include "exec/hwaddr.h" +#include "system/memory_cached.h" #include "hw/virtio/virtio.h" #include "hw/virtio/virtio-bus.h"
include/system/memory.h +0 -185
203 lines not on this page · raw message
include/system/memory_cached.h new file +210 -0
210 lines not on this page · raw message
system/physmem.c +1 -0
@@ -53,6 +53,7 @@#include "qemu/memalign.h" #include "qemu/memfd.h" #include "system/memory.h" +#include "system/memory_cached.h" #include "system/ioport.h" #include "system/dma.h" #include "system/hostmem.h"
Signature · 1 line
2.52.0
PATCH v5 6/22 system/memory: Inline address_space_stq_internal()
In reply to Philippe Mathieu-DaudéAs its name suggests, address_space_stq_internal() is an internal method which can be inlined like all the other ones in this file.
--- system/memory_ldst.c.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
system/memory_ldst.c.inc +1 -1
@@ -422,7 +422,7 @@ void glue(address_space_stw_be, SUFFIX)(ARG1_DECL, DEVICE_BIG_ENDIAN); } -static void glue(address_space_stq_internal, SUFFIX)(ARG1_DECL, +static inline void glue(address_space_stq_internal, SUFFIX)(ARG1_DECL, hwaddr addr, uint64_t val, MemTxAttrs attrs, MemTxResult *result, enum device_endian endian) {
Signature · 1 line
2.52.0
PATCH v5 7/22 system/memory: Define address_space_ldst[W] endian variants via template
In reply to Philippe Mathieu-Daudé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.
--- MAINTAINERS | 1 + include/system/memory_ldst.h.inc | 21 ++++---- include/system/memory_ldst_endian.h.inc | 25 +++++++++ include/system/memory_ldst_phys.h.inc | 45 ++++------------ include/system/memory_ldst_phys_endian.h.inc | 37 ++++++++++++++ system/memory_ldst.c.inc | 54 +++++--------------- system/memory_ldst_endian.c.inc | 42 +++++++++++++++ 7 files changed, 135 insertions(+), 90 deletions(-) create mode 100644 include/system/memory_ldst_endian.h.inc create mode 100644 include/system/memory_ldst_phys_endian.h.inc create mode 100644 system/memory_ldst_endian.c.inc
MAINTAINERS +1 -0
@@ -3270,6 +3270,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
include/system/memory_ldst.h.inc +9 -12
@@ -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
include/system/memory_ldst_endian.h.inc new file +25 -0
@@ -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
include/system/memory_ldst_phys.h.inc +9 -36
75 lines not on this page · raw message
include/system/memory_ldst_phys_endian.h.inc new file +37 -0
@@ -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
system/memory_ldst.c.inc +12 -42
72 lines not on this page · raw message
system/memory_ldst_endian.c.inc new file +42 -0
42 lines not on this page · raw message
Signature · 1 line
2.52.0
PATCH v5 8/22 system/memory: Define address_space_ldst[L] endian variants via template
In reply to Philippe Mathieu-DaudéDefine address_space_ldst[L] endian variants via template.
--- include/system/memory_ldst.h.inc | 12 ------ include/system/memory_ldst_endian.h.inc | 4 ++ include/system/memory_ldst_phys.h.inc | 36 ----------------- include/system/memory_ldst_phys_endian.h.inc | 10 +++++ system/memory_ldst.c.inc | 42 -------------------- system/memory_ldst_endian.c.inc | 14 +++++++ 6 files changed, 28 insertions(+), 90 deletions(-)
include/system/memory_ldst.h.inc +0 -12
@@ -19,30 +19,18 @@ * License along with this library; if not, see <http://www.gnu.org/licenses/>. */ -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_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); -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, - hwaddr addr, MemTxAttrs attrs, MemTxResult *result); uint64_t glue(address_space_ldq_le, SUFFIX)(ARG1_DECL, hwaddr addr, MemTxAttrs attrs, MemTxResult *result); 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_stl_le, SUFFIX)(ARG1_DECL, - hwaddr addr, uint32_t val, MemTxAttrs attrs, MemTxResult *result); -void glue(address_space_stl_be, SUFFIX)(ARG1_DECL, - hwaddr addr, uint32_t val, MemTxAttrs attrs, MemTxResult *result); void glue(address_space_stq_le, SUFFIX)(ARG1_DECL, hwaddr addr, uint64_t val, MemTxAttrs attrs, MemTxResult *result); void glue(address_space_stq_be, SUFFIX)(ARG1_DECL,
include/system/memory_ldst_endian.h.inc +4 -0
@@ -16,8 +16,12 @@ uint16_t ADDRESS_SPACE_LD(uw)(ARG1_DECL, hwaddr addr, MemTxAttrs attrs, MemTxResult *result); +uint32_t ADDRESS_SPACE_LD(l)(ARG1_DECL, hwaddr addr, + MemTxAttrs attrs, MemTxResult *result); void ADDRESS_SPACE_ST(w)(ARG1_DECL, hwaddr addr, uint16_t val, MemTxAttrs attrs, MemTxResult *result); +void ADDRESS_SPACE_ST(l)(ARG1_DECL, hwaddr addr, uint32_t val, + MemTxAttrs attrs, MemTxResult *result); #undef ADDRESS_SPACE_LD #undef ADDRESS_SPACE_ST
include/system/memory_ldst_phys.h.inc +0 -36
@@ -19,24 +19,12 @@ * License along with this library; if not, see <http://www.gnu.org/licenses/>. */ -static inline uint32_t glue(ldl_phys, SUFFIX)(ARG1_DECL, hwaddr addr) -{ - return glue(address_space_ldl, SUFFIX)(ARG1, addr, - MEMTXATTRS_UNSPECIFIED, NULL); -} - static inline uint64_t glue(ldq_phys, SUFFIX)(ARG1_DECL, hwaddr addr) { return glue(address_space_ldq, SUFFIX)(ARG1, addr, 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, - MEMTXATTRS_UNSPECIFIED, NULL); -} - static inline void glue(stq_phys, SUFFIX)(ARG1_DECL, hwaddr addr, uint64_t val) { glue(address_space_stq, SUFFIX)(ARG1, addr, val,
@@ -49,18 +37,6 @@ static inline uint8_t glue(ldub_phys, SUFFIX)(ARG1_DECL, hwaddr 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, - MEMTXATTRS_UNSPECIFIED, NULL); -} - -static inline uint32_t glue(ldl_be_phys, SUFFIX)(ARG1_DECL, hwaddr addr) -{ - return glue(address_space_ldl_be, SUFFIX)(ARG1, addr, - MEMTXATTRS_UNSPECIFIED, NULL); -} - static inline uint64_t glue(ldq_le_phys, SUFFIX)(ARG1_DECL, hwaddr addr) { return glue(address_space_ldq_le, SUFFIX)(ARG1, addr,
@@ -79,18 +55,6 @@ static inline void glue(stb_phys, SUFFIX)(ARG1_DECL, hwaddr addr, uint8_t 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, - MEMTXATTRS_UNSPECIFIED, NULL); -} - -static inline void glue(stl_be_phys, SUFFIX)(ARG1_DECL, hwaddr addr, uint32_t val) -{ - glue(address_space_stl_be, SUFFIX)(ARG1, addr, val, - MEMTXATTRS_UNSPECIFIED, NULL); -} - static inline void glue(stq_le_phys, SUFFIX)(ARG1_DECL, hwaddr addr, uint64_t val) { glue(address_space_stq_le, SUFFIX)(ARG1, addr, val,
include/system/memory_ldst_phys_endian.h.inc +10 -0
@@ -24,11 +24,21 @@ static inline uint16_t LD_PHYS(uw)(ARG1_DECL, hwaddr addr) return ADDRESS_SPACE_LD(uw)(ARG1, addr, MEMTXATTRS_UNSPECIFIED, NULL); } +static inline uint32_t LD_PHYS(l)(ARG1_DECL, hwaddr addr) +{ + return ADDRESS_SPACE_LD(l)(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); } +static inline void ST_PHYS(l)(ARG1_DECL, hwaddr addr, uint32_t val) +{ + ADDRESS_SPACE_ST(l)(ARG1, addr, val, MEMTXATTRS_UNSPECIFIED, NULL); +} + #undef LD_PHYS #undef ST_PHYS #undef ADDRESS_SPACE_LD
system/memory_ldst.c.inc +0 -42
54 lines not on this page · raw message
system/memory_ldst_endian.c.inc +14 -0
@@ -26,6 +26,13 @@ uint16_t ADDRESS_SPACE_LD(uw)(ARG1_DECL, hwaddr addr, DEVICE_ENDIANNESS); } +uint32_t ADDRESS_SPACE_LD(l)(ARG1_DECL, hwaddr addr, + MemTxAttrs attrs, MemTxResult *result) +{ + return ADDRESS_SPACE_LD_INTERNAL(l)(ARG1, addr, attrs, result, + DEVICE_ENDIANNESS); +} + void ADDRESS_SPACE_ST(w)(ARG1_DECL, hwaddr addr, uint16_t val, MemTxAttrs attrs, MemTxResult *result) {
@@ -33,6 +40,13 @@ void ADDRESS_SPACE_ST(w)(ARG1_DECL, hwaddr addr, uint16_t val, DEVICE_ENDIANNESS); } +void ADDRESS_SPACE_ST(l)(ARG1_DECL, hwaddr addr, uint32_t val, + MemTxAttrs attrs, MemTxResult *result) +{ + ADDRESS_SPACE_ST_INTERNAL(l)(ARG1, addr, val, attrs, result, + DEVICE_ENDIANNESS); +} + #undef ADDRESS_SPACE_LD #undef ADDRESS_SPACE_LD_INTERNAL #undef ADDRESS_SPACE_ST
Signature · 1 line
2.52.0
PATCH v5 9/22 system/memory: Define address_space_ldst[Q] endian variants via template
In reply to Philippe Mathieu-DaudéDefine address_space_ldst[Q] endian variants via template.
--- include/system/memory_ldst.h.inc | 17 ++------ include/system/memory_ldst_endian.h.inc | 4 ++ include/system/memory_ldst_phys.h.inc | 36 ----------------- include/system/memory_ldst_phys_endian.h.inc | 10 +++++ system/memory_ldst.c.inc | 42 -------------------- system/memory_ldst_endian.c.inc | 14 +++++++ 6 files changed, 31 insertions(+), 92 deletions(-)
include/system/memory_ldst.h.inc +3 -14
@@ -19,22 +19,11 @@ * License along with this library; if not, see <http://www.gnu.org/licenses/>. */ -uint64_t glue(address_space_ldq, SUFFIX)(ARG1_DECL, - hwaddr addr, 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); -uint64_t glue(address_space_ldq_le, SUFFIX)(ARG1_DECL, - hwaddr addr, MemTxAttrs attrs, MemTxResult *result); -uint64_t glue(address_space_ldq_be, SUFFIX)(ARG1_DECL, - hwaddr addr, MemTxAttrs attrs, MemTxResult *result); + 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_stq_le, SUFFIX)(ARG1_DECL, - hwaddr addr, uint64_t val, MemTxAttrs attrs, MemTxResult *result); -void glue(address_space_stq_be, SUFFIX)(ARG1_DECL, - hwaddr addr, uint64_t val, MemTxAttrs attrs, MemTxResult *result); + hwaddr addr, uint8_t val, MemTxAttrs attrs, MemTxResult *result); #define ENDIANNESS #include "system/memory_ldst_endian.h.inc"
include/system/memory_ldst_endian.h.inc +4 -0
@@ -18,10 +18,14 @@ uint16_t ADDRESS_SPACE_LD(uw)(ARG1_DECL, hwaddr addr, MemTxAttrs attrs, MemTxResult *result); uint32_t ADDRESS_SPACE_LD(l)(ARG1_DECL, hwaddr addr, MemTxAttrs attrs, MemTxResult *result); +uint64_t ADDRESS_SPACE_LD(q)(ARG1_DECL, hwaddr addr, + MemTxAttrs attrs, MemTxResult *result); void ADDRESS_SPACE_ST(w)(ARG1_DECL, hwaddr addr, uint16_t val, MemTxAttrs attrs, MemTxResult *result); void ADDRESS_SPACE_ST(l)(ARG1_DECL, hwaddr addr, uint32_t val, MemTxAttrs attrs, MemTxResult *result); +void ADDRESS_SPACE_ST(q)(ARG1_DECL, hwaddr addr, uint64_t val, + MemTxAttrs attrs, MemTxResult *result); #undef ADDRESS_SPACE_LD #undef ADDRESS_SPACE_ST
include/system/memory_ldst_phys.h.inc +0 -36
@@ -19,54 +19,18 @@ * License along with this library; if not, see <http://www.gnu.org/licenses/>. */ -static inline uint64_t glue(ldq_phys, SUFFIX)(ARG1_DECL, hwaddr addr) -{ - return glue(address_space_ldq, SUFFIX)(ARG1, addr, - MEMTXATTRS_UNSPECIFIED, NULL); -} - -static inline void glue(stq_phys, SUFFIX)(ARG1_DECL, hwaddr addr, uint64_t val) -{ - glue(address_space_stq, SUFFIX)(ARG1, addr, val, - MEMTXATTRS_UNSPECIFIED, NULL); -} - static inline uint8_t glue(ldub_phys, SUFFIX)(ARG1_DECL, hwaddr addr) { return glue(address_space_ldub, SUFFIX)(ARG1, addr, MEMTXATTRS_UNSPECIFIED, NULL); } -static inline uint64_t glue(ldq_le_phys, SUFFIX)(ARG1_DECL, hwaddr addr) -{ - return glue(address_space_ldq_le, SUFFIX)(ARG1, addr, - MEMTXATTRS_UNSPECIFIED, NULL); -} - -static inline uint64_t glue(ldq_be_phys, SUFFIX)(ARG1_DECL, hwaddr addr) -{ - return glue(address_space_ldq_be, SUFFIX)(ARG1, addr, - MEMTXATTRS_UNSPECIFIED, NULL); -} - static inline void glue(stb_phys, SUFFIX)(ARG1_DECL, hwaddr addr, uint8_t val) { glue(address_space_stb, SUFFIX)(ARG1, addr, val, MEMTXATTRS_UNSPECIFIED, NULL); } -static inline void glue(stq_le_phys, SUFFIX)(ARG1_DECL, hwaddr addr, uint64_t val) -{ - glue(address_space_stq_le, SUFFIX)(ARG1, addr, val, - MEMTXATTRS_UNSPECIFIED, NULL); -} - -static inline void glue(stq_be_phys, SUFFIX)(ARG1_DECL, hwaddr addr, uint64_t val) -{ - glue(address_space_stq_be, SUFFIX)(ARG1, addr, val, - MEMTXATTRS_UNSPECIFIED, NULL); -} - #define ENDIANNESS #include "system/memory_ldst_phys_endian.h.inc"
include/system/memory_ldst_phys_endian.h.inc +10 -0
@@ -29,6 +29,11 @@ static inline uint32_t LD_PHYS(l)(ARG1_DECL, hwaddr addr) return ADDRESS_SPACE_LD(l)(ARG1, addr, MEMTXATTRS_UNSPECIFIED, NULL); } +static inline uint64_t LD_PHYS(q)(ARG1_DECL, hwaddr addr) +{ + return ADDRESS_SPACE_LD(q)(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);
@@ -39,6 +44,11 @@ static inline void ST_PHYS(l)(ARG1_DECL, hwaddr addr, uint32_t val) ADDRESS_SPACE_ST(l)(ARG1, addr, val, MEMTXATTRS_UNSPECIFIED, NULL); } +static inline void ST_PHYS(q)(ARG1_DECL, hwaddr addr, uint64_t val) +{ + ADDRESS_SPACE_ST(q)(ARG1, addr, val, MEMTXATTRS_UNSPECIFIED, NULL); +} + #undef LD_PHYS #undef ST_PHYS #undef ADDRESS_SPACE_LD
system/memory_ldst.c.inc +0 -42
54 lines not on this page · raw message
system/memory_ldst_endian.c.inc +14 -0
@@ -33,6 +33,13 @@ uint32_t ADDRESS_SPACE_LD(l)(ARG1_DECL, hwaddr addr, DEVICE_ENDIANNESS); } +uint64_t ADDRESS_SPACE_LD(q)(ARG1_DECL, hwaddr addr, + MemTxAttrs attrs, MemTxResult *result) +{ + return ADDRESS_SPACE_LD_INTERNAL(q)(ARG1, addr, attrs, result, + DEVICE_ENDIANNESS); +} + void ADDRESS_SPACE_ST(w)(ARG1_DECL, hwaddr addr, uint16_t val, MemTxAttrs attrs, MemTxResult *result) {
@@ -47,6 +54,13 @@ void ADDRESS_SPACE_ST(l)(ARG1_DECL, hwaddr addr, uint32_t val, DEVICE_ENDIANNESS); } +void ADDRESS_SPACE_ST(q)(ARG1_DECL, hwaddr addr, uint64_t val, + MemTxAttrs attrs, MemTxResult *result) +{ + ADDRESS_SPACE_ST_INTERNAL(q)(ARG1, addr, val, attrs, result, + DEVICE_ENDIANNESS); +} + #undef ADDRESS_SPACE_LD #undef ADDRESS_SPACE_LD_INTERNAL #undef ADDRESS_SPACE_ST
Signature · 1 line
2.52.0
PATCH v5 10/22 system/memory: Factor address_space_ldst[M]_internal() helper out
In reply to Philippe Mathieu-DaudéAll the LD/ST[W,L,Q] variants use the same template, only modifying the access size used. Unify as a single pair of LD/ST methods taking a MemOp argument. Thus use the 'm' suffix for MemOp.
Keep the pre-existing "warning: addr must be aligned" comment.
We leave the wonder about why we aren't asserting alignment for later.
--- system/memory_ldst.c.inc | 298 +++++++++------------------------------ 1 file changed, 63 insertions(+), 235 deletions(-)
system/memory_ldst.c.inc +63 -235
@@ -20,39 +20,43 @@ */ /* warning: addr must be aligned */ -static inline uint32_t glue(address_space_ldl_internal, SUFFIX)(ARG1_DECL, - hwaddr addr, MemTxAttrs attrs, MemTxResult *result, - enum device_endian endian) +static inline +uint64_t glue(address_space_ldm_internal, SUFFIX)(ARG1_DECL, MemOp mop, + hwaddr addr, + MemTxAttrs attrs, + MemTxResult *result, + enum device_endian endian) { + const unsigned size = memop_size(mop); uint8_t *ptr; uint64_t val; MemoryRegion *mr; - hwaddr l = 4; + hwaddr l = size; hwaddr addr1; MemTxResult r; bool release_lock = false; RCU_READ_LOCK(); mr = TRANSLATE(addr, &addr1, &l, false, attrs); - if (l < 4 || !memory_access_is_direct(mr, false, attrs)) { + if (l < size || !memory_access_is_direct(mr, false, attrs)) { release_lock |= prepare_mmio_access(mr); /* I/O case */ r = memory_region_dispatch_read(mr, addr1, &val, - MO_32 | devend_memop(endian), attrs); + mop | devend_memop(endian), attrs); } else { /* RAM case */ - fuzz_dma_read_cb(addr, 4, mr); + fuzz_dma_read_cb(addr, size, mr); ptr = qemu_map_ram_ptr(mr->ram_block, addr1); switch (endian) { case DEVICE_LITTLE_ENDIAN: - val = ldl_le_p(ptr); + val = ldn_le_p(ptr, size); break; case DEVICE_BIG_ENDIAN: - val = ldl_be_p(ptr); + val = ldn_be_p(ptr, size); break; default: - val = ldl_p(ptr); + val = ldn_p(ptr, size); break; } r = MEMTX_OK;
@@ -67,87 +71,30 @@ static inline uint32_t glue(address_space_ldl_internal, SUFFIX)(ARG1_DECL, return val; } +/* warning: addr must be aligned */ +static inline uint32_t glue(address_space_ldl_internal, SUFFIX)(ARG1_DECL, + hwaddr addr, MemTxAttrs attrs, MemTxResult *result, + enum device_endian endian) +{ + return glue(address_space_ldm_internal, SUFFIX)(ARG1, MO_32, addr, + attrs, result, endian); +} + /* warning: addr must be aligned */ static inline uint64_t glue(address_space_ldq_internal, SUFFIX)(ARG1_DECL, hwaddr addr, MemTxAttrs attrs, MemTxResult *result, enum device_endian endian) { - uint8_t *ptr; - uint64_t val; - MemoryRegion *mr; - hwaddr l = 8; - hwaddr addr1; - MemTxResult r; - bool release_lock = false; - - RCU_READ_LOCK(); - mr = TRANSLATE(addr, &addr1, &l, false, attrs); - if (l < 8 || !memory_access_is_direct(mr, false, attrs)) { - release_lock |= prepare_mmio_access(mr); - - /* I/O case */ - r = memory_region_dispatch_read(mr, addr1, &val, - MO_64 | devend_memop(endian), attrs); - } else { - /* RAM case */ - fuzz_dma_read_cb(addr, 8, mr); - ptr = qemu_map_ram_ptr(mr->ram_block, addr1); - switch (endian) { - case DEVICE_LITTLE_ENDIAN: - val = ldq_le_p(ptr); - break; - case DEVICE_BIG_ENDIAN: - val = ldq_be_p(ptr); - break; - default: - val = ldq_p(ptr); - break; - } - r = MEMTX_OK; - } - if (result) { - *result = r; - } - if (release_lock) { - bql_unlock(); - } - RCU_READ_UNLOCK(); - return val; + return glue(address_space_ldm_internal, SUFFIX)(ARG1, MO_64, addr, + attrs, result, endian); } -uint8_t glue(address_space_ldub, SUFFIX)(ARG1_DECL, - hwaddr addr, MemTxAttrs attrs, MemTxResult *result) +uint8_t glue(address_space_ldub, SUFFIX)(ARG1_DECL, hwaddr addr, + MemTxAttrs attrs, MemTxResult *result) { - uint8_t *ptr; - uint64_t val; - MemoryRegion *mr; - hwaddr l = 1; - hwaddr addr1; - MemTxResult r; - bool release_lock = false; - - RCU_READ_LOCK(); - mr = TRANSLATE(addr, &addr1, &l, false, attrs); - if (!memory_access_is_direct(mr, false, attrs)) { - release_lock |= prepare_mmio_access(mr); - - /* I/O case */ - r = memory_region_dispatch_read(mr, addr1, &val, MO_8, attrs); - } else { - /* RAM case */ - fuzz_dma_read_cb(addr, 1, mr); - ptr = qemu_map_ram_ptr(mr->ram_block, addr1); - val = ldub_p(ptr); - r = MEMTX_OK; - } - if (result) { - *result = r; - } - if (release_lock) { - bql_unlock(); - } - RCU_READ_UNLOCK(); - return val; + return glue(address_space_ldm_internal, SUFFIX)(ARG1, MO_8, addr, + attrs, result, + DEVICE_NATIVE_ENDIAN); } /* warning: addr must be aligned */
@@ -155,37 +102,47 @@ static inline uint16_t glue(address_space_lduw_internal, SUFFIX)(ARG1_DECL, hwaddr addr, MemTxAttrs attrs, MemTxResult *result, enum device_endian endian) { + return glue(address_space_ldm_internal, SUFFIX)(ARG1, MO_16, addr, + attrs, result, endian); +} + +/* warning: addr must be aligned */ +static inline +void glue(address_space_stm_internal, SUFFIX)(ARG1_DECL, MemOp mop, + hwaddr addr, uint64_t val, + MemTxAttrs attrs, + MemTxResult *result, + enum device_endian endian) +{ + const unsigned size = memop_size(mop); uint8_t *ptr; - uint64_t val; MemoryRegion *mr; - hwaddr l = 2; + hwaddr l = size; hwaddr addr1; MemTxResult r; bool release_lock = false; RCU_READ_LOCK(); - mr = TRANSLATE(addr, &addr1, &l, false, attrs); - if (l < 2 || !memory_access_is_direct(mr, false, attrs)) { + mr = TRANSLATE(addr, &addr1, &l, true, attrs); + if (l < size || !memory_access_is_direct(mr, true, attrs)) { release_lock |= prepare_mmio_access(mr); - - /* I/O case */ - r = memory_region_dispatch_read(mr, addr1, &val, - MO_16 | devend_memop(endian), attrs); + r = memory_region_dispatch_write(mr, addr1, val, + mop | devend_memop(endian), attrs); } else { /* RAM case */ - fuzz_dma_read_cb(addr, 2, mr); ptr = qemu_map_ram_ptr(mr->ram_block, addr1); switch (endian) { case DEVICE_LITTLE_ENDIAN: - val = lduw_le_p(ptr); + stn_le_p(ptr, size, val); break; case DEVICE_BIG_ENDIAN: - val = lduw_be_p(ptr); + stn_be_p(ptr, size, val); break; default: - val = lduw_p(ptr); + stn_p(ptr, size, val); break; } + invalidate_and_set_dirty(mr, addr1, size); r = MEMTX_OK; } if (result) {
@@ -195,7 +152,6 @@ static inline uint16_t glue(address_space_lduw_internal, SUFFIX)(ARG1_DECL, bql_unlock(); } RCU_READ_UNLOCK(); - return val; } /* warning: addr must be aligned */
@@ -203,74 +159,16 @@ static inline void glue(address_space_stl_internal, SUFFIX)(ARG1_DECL, hwaddr addr, uint32_t val, MemTxAttrs attrs, MemTxResult *result, enum device_endian endian) { - uint8_t *ptr; - MemoryRegion *mr; - hwaddr l = 4; - hwaddr addr1; - MemTxResult r; - bool release_lock = false; - - RCU_READ_LOCK(); - mr = TRANSLATE(addr, &addr1, &l, true, attrs); - if (l < 4 || !memory_access_is_direct(mr, true, attrs)) { - release_lock |= prepare_mmio_access(mr); - r = memory_region_dispatch_write(mr, addr1, val, - MO_32 | devend_memop(endian), attrs); - } else { - /* RAM case */ - ptr = qemu_map_ram_ptr(mr->ram_block, addr1); - switch (endian) { - case DEVICE_LITTLE_ENDIAN: - stl_le_p(ptr, val); - break; - case DEVICE_BIG_ENDIAN: - stl_be_p(ptr, val); - break; - default: - stl_p(ptr, val); - break; - } - invalidate_and_set_dirty(mr, addr1, 4); - r = MEMTX_OK; - } - if (result) { - *result = r; - } - if (release_lock) { - bql_unlock(); - } - RCU_READ_UNLOCK(); + glue(address_space_stm_internal, SUFFIX)(ARG1, MO_32, addr, val, + attrs, result, endian); } -void glue(address_space_stb, SUFFIX)(ARG1_DECL, - hwaddr addr, uint8_t val, MemTxAttrs attrs, MemTxResult *result) +void glue(address_space_stb, SUFFIX)(ARG1_DECL, hwaddr addr, uint8_t val, + MemTxAttrs attrs, MemTxResult *result) { - uint8_t *ptr; - MemoryRegion *mr; - hwaddr l = 1; - hwaddr addr1; - MemTxResult r; - bool release_lock = false; - - RCU_READ_LOCK(); - mr = TRANSLATE(addr, &addr1, &l, true, attrs); - if (!memory_access_is_direct(mr, true, attrs)) { - release_lock |= prepare_mmio_access(mr); - r = memory_region_dispatch_write(mr, addr1, val, MO_8, attrs); - } else { - /* RAM case */ - ptr = qemu_map_ram_ptr(mr->ram_block, addr1); - stb_p(ptr, val); - invalidate_and_set_dirty(mr, addr1, 1); - r = MEMTX_OK; - } - if (result) { - *result = r; - } - if (release_lock) { - bql_unlock(); - } - RCU_READ_UNLOCK(); + glue(address_space_stm_internal, SUFFIX)(ARG1, MO_8, addr, val, + attrs, result, + DEVICE_NATIVE_ENDIAN); } /* warning: addr must be aligned */
@@ -278,86 +176,16 @@ static inline void glue(address_space_stw_internal, SUFFIX)(ARG1_DECL, hwaddr addr, uint16_t val, MemTxAttrs attrs, MemTxResult *result, enum device_endian endian) { - uint8_t *ptr; - MemoryRegion *mr; - hwaddr l = 2; - hwaddr addr1; - MemTxResult r; - bool release_lock = false; - - RCU_READ_LOCK(); - mr = TRANSLATE(addr, &addr1, &l, true, attrs); - if (l < 2 || !memory_access_is_direct(mr, true, attrs)) { - release_lock |= prepare_mmio_access(mr); - r = memory_region_dispatch_write(mr, addr1, val, - MO_16 | devend_memop(endian), attrs); - } else { - /* RAM case */ - ptr = qemu_map_ram_ptr(mr->ram_block, addr1); - switch (endian) { - case DEVICE_LITTLE_ENDIAN: - stw_le_p(ptr, val); - break; - case DEVICE_BIG_ENDIAN: - stw_be_p(ptr, val); - break; - default: - stw_p(ptr, val); - break; - } - invalidate_and_set_dirty(mr, addr1, 2); - r = MEMTX_OK; - } - if (result) { - *result = r; - } - if (release_lock) { - bql_unlock(); - } - RCU_READ_UNLOCK(); + glue(address_space_stm_internal, SUFFIX)(ARG1, MO_16, addr, val, + attrs, result, 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) { - uint8_t *ptr; - MemoryRegion *mr; - hwaddr l = 8; - hwaddr addr1; - MemTxResult r; - bool release_lock = false; - - RCU_READ_LOCK(); - mr = TRANSLATE(addr, &addr1, &l, true, attrs); - if (l < 8 || !memory_access_is_direct(mr, true, attrs)) { - release_lock |= prepare_mmio_access(mr); - r = memory_region_dispatch_write(mr, addr1, val, - MO_64 | devend_memop(endian), attrs); - } else { - /* RAM case */ - ptr = qemu_map_ram_ptr(mr->ram_block, addr1); - switch (endian) { - case DEVICE_LITTLE_ENDIAN: - stq_le_p(ptr, val); - break; - case DEVICE_BIG_ENDIAN: - stq_be_p(ptr, val); - break; - default: - stq_p(ptr, val); - break; - } - invalidate_and_set_dirty(mr, addr1, 8); - r = MEMTX_OK; - } - if (result) { - *result = r; - } - if (release_lock) { - bql_unlock(); - } - RCU_READ_UNLOCK(); + glue(address_space_stm_internal, SUFFIX)(ARG1, MO_64, addr, val, + attrs, result, endian); } #define ENDIANNESS
Signature · 1 line
2.52.0
PATCH v5 11/22 system/memory: Pass device_endian argument as MemOp bit
In reply to Philippe Mathieu-DaudéUse the MemOp argument to hold both the access size and its endianness.
--- system/memory_ldst.c.inc | 86 ++++++++++++--------------------- system/memory_ldst_endian.c.inc | 26 +++++----- 2 files changed, 44 insertions(+), 68 deletions(-)
system/memory_ldst.c.inc +31 -55
@@ -24,8 +24,7 @@ static inline uint64_t glue(address_space_ldm_internal, SUFFIX)(ARG1_DECL, MemOp mop, hwaddr addr, MemTxAttrs attrs, - MemTxResult *result, - enum device_endian endian) + MemTxResult *result) { const unsigned size = memop_size(mop); uint8_t *ptr;
@@ -42,22 +41,15 @@ uint64_t glue(address_space_ldm_internal, SUFFIX)(ARG1_DECL, MemOp mop, release_lock |= prepare_mmio_access(mr); /* I/O case */ - r = memory_region_dispatch_read(mr, addr1, &val, - mop | devend_memop(endian), attrs); + r = memory_region_dispatch_read(mr, addr1, &val, mop, attrs); } else { /* RAM case */ fuzz_dma_read_cb(addr, size, mr); ptr = qemu_map_ram_ptr(mr->ram_block, addr1); - switch (endian) { - case DEVICE_LITTLE_ENDIAN: + if ((mop & MO_BSWAP) == MO_LE) { val = ldn_le_p(ptr, size); - break; - case DEVICE_BIG_ENDIAN: + } else { val = ldn_be_p(ptr, size); - break; - default: - val = ldn_p(ptr, size); - break; } r = MEMTX_OK; }
@@ -73,37 +65,33 @@ uint64_t glue(address_space_ldm_internal, SUFFIX)(ARG1_DECL, MemOp mop, /* warning: addr must be aligned */ static inline uint32_t glue(address_space_ldl_internal, SUFFIX)(ARG1_DECL, - hwaddr addr, MemTxAttrs attrs, MemTxResult *result, - enum device_endian endian) + MemOp mop, hwaddr addr, MemTxAttrs attrs, MemTxResult *result) { - return glue(address_space_ldm_internal, SUFFIX)(ARG1, MO_32, addr, - attrs, result, endian); + return glue(address_space_ldm_internal, SUFFIX)(ARG1, mop | MO_32, addr, + attrs, result); } /* warning: addr must be aligned */ static inline uint64_t glue(address_space_ldq_internal, SUFFIX)(ARG1_DECL, - hwaddr addr, MemTxAttrs attrs, MemTxResult *result, - enum device_endian endian) + MemOp mop, hwaddr addr, MemTxAttrs attrs, MemTxResult *result) { - return glue(address_space_ldm_internal, SUFFIX)(ARG1, MO_64, addr, - attrs, result, endian); + return glue(address_space_ldm_internal, SUFFIX)(ARG1, mop | MO_64, addr, + attrs, result); } uint8_t glue(address_space_ldub, SUFFIX)(ARG1_DECL, hwaddr addr, MemTxAttrs attrs, MemTxResult *result) { return glue(address_space_ldm_internal, SUFFIX)(ARG1, MO_8, addr, - attrs, result, - DEVICE_NATIVE_ENDIAN); + attrs, result); } /* warning: addr must be aligned */ static inline uint16_t glue(address_space_lduw_internal, SUFFIX)(ARG1_DECL, - hwaddr addr, MemTxAttrs attrs, MemTxResult *result, - enum device_endian endian) + MemOp mop, hwaddr addr, MemTxAttrs attrs, MemTxResult *result) { - return glue(address_space_ldm_internal, SUFFIX)(ARG1, MO_16, addr, - attrs, result, endian); + return glue(address_space_ldm_internal, SUFFIX)(ARG1, mop | MO_16, addr, + attrs, result); } /* warning: addr must be aligned */
@@ -111,8 +99,7 @@ static inline void glue(address_space_stm_internal, SUFFIX)(ARG1_DECL, MemOp mop, hwaddr addr, uint64_t val, MemTxAttrs attrs, - MemTxResult *result, - enum device_endian endian) + MemTxResult *result) { const unsigned size = memop_size(mop); uint8_t *ptr;
@@ -126,21 +113,14 @@ void glue(address_space_stm_internal, SUFFIX)(ARG1_DECL, MemOp mop, mr = TRANSLATE(addr, &addr1, &l, true, attrs); if (l < size || !memory_access_is_direct(mr, true, attrs)) { release_lock |= prepare_mmio_access(mr); - r = memory_region_dispatch_write(mr, addr1, val, - mop | devend_memop(endian), attrs); + r = memory_region_dispatch_write(mr, addr1, val, mop, attrs); } else { /* RAM case */ ptr = qemu_map_ram_ptr(mr->ram_block, addr1); - switch (endian) { - case DEVICE_LITTLE_ENDIAN: + if ((mop & MO_BSWAP) == MO_LE) { stn_le_p(ptr, size, val); - break; - case DEVICE_BIG_ENDIAN: + } else { stn_be_p(ptr, size, val); - break; - default: - stn_p(ptr, size, val); - break; } invalidate_and_set_dirty(mr, addr1, size); r = MEMTX_OK;
@@ -156,48 +136,44 @@ void glue(address_space_stm_internal, SUFFIX)(ARG1_DECL, MemOp mop, /* warning: addr must be aligned */ static inline void glue(address_space_stl_internal, SUFFIX)(ARG1_DECL, - hwaddr addr, uint32_t val, MemTxAttrs attrs, - MemTxResult *result, enum device_endian endian) + MemOp mop, hwaddr addr, uint32_t val, MemTxAttrs attrs, MemTxResult *result) { - glue(address_space_stm_internal, SUFFIX)(ARG1, MO_32, addr, val, - attrs, result, endian); + glue(address_space_stm_internal, SUFFIX)(ARG1, mop | MO_32, addr, val, + attrs, result); } void glue(address_space_stb, SUFFIX)(ARG1_DECL, hwaddr addr, uint8_t val, MemTxAttrs attrs, MemTxResult *result) { glue(address_space_stm_internal, SUFFIX)(ARG1, MO_8, addr, val, - attrs, result, - DEVICE_NATIVE_ENDIAN); + attrs, result); } /* warning: addr must be aligned */ static inline void glue(address_space_stw_internal, SUFFIX)(ARG1_DECL, - hwaddr addr, uint16_t val, MemTxAttrs attrs, - MemTxResult *result, enum device_endian endian) + MemOp mop, hwaddr addr, uint16_t val, MemTxAttrs attrs, MemTxResult *result) { - glue(address_space_stm_internal, SUFFIX)(ARG1, MO_16, addr, val, - attrs, result, endian); + glue(address_space_stm_internal, SUFFIX)(ARG1, mop | MO_16, addr, val, + attrs, result); } static inline void glue(address_space_stq_internal, SUFFIX)(ARG1_DECL, - hwaddr addr, uint64_t val, MemTxAttrs attrs, - MemTxResult *result, enum device_endian endian) + MemOp mop, hwaddr addr, uint64_t val, MemTxAttrs attrs, MemTxResult *result) { - glue(address_space_stm_internal, SUFFIX)(ARG1, MO_64, addr, val, - attrs, result, endian); + glue(address_space_stm_internal, SUFFIX)(ARG1, mop | MO_64, addr, val, + attrs, result); } #define ENDIANNESS -#define DEVICE_ENDIANNESS DEVICE_NATIVE_ENDIAN +#define MO_ENDIAN (target_big_endian() ? MO_BE : MO_LE) #include "memory_ldst_endian.c.inc" #define ENDIANNESS _le -#define DEVICE_ENDIANNESS DEVICE_LITTLE_ENDIAN +#define MO_ENDIAN MO_LE #include "memory_ldst_endian.c.inc" #define ENDIANNESS _be -#define DEVICE_ENDIANNESS DEVICE_BIG_ENDIAN +#define MO_ENDIAN MO_BE #include "memory_ldst_endian.c.inc" #undef ARG1_DECL
system/memory_ldst_endian.c.inc +13 -13
@@ -22,43 +22,43 @@ 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); + return ADDRESS_SPACE_LD_INTERNAL(uw)(ARG1, MO_ENDIAN, + addr, attrs, result); } uint32_t ADDRESS_SPACE_LD(l)(ARG1_DECL, hwaddr addr, MemTxAttrs attrs, MemTxResult *result) { - return ADDRESS_SPACE_LD_INTERNAL(l)(ARG1, addr, attrs, result, - DEVICE_ENDIANNESS); + return ADDRESS_SPACE_LD_INTERNAL(l)(ARG1, MO_ENDIAN, + addr, attrs, result); } uint64_t ADDRESS_SPACE_LD(q)(ARG1_DECL, hwaddr addr, MemTxAttrs attrs, MemTxResult *result) { - return ADDRESS_SPACE_LD_INTERNAL(q)(ARG1, addr, attrs, result, - DEVICE_ENDIANNESS); + return ADDRESS_SPACE_LD_INTERNAL(q)(ARG1, MO_ENDIAN, + addr, attrs, result); } 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); + ADDRESS_SPACE_ST_INTERNAL(w)(ARG1, MO_ENDIAN, + addr, val, attrs, result); } void ADDRESS_SPACE_ST(l)(ARG1_DECL, hwaddr addr, uint32_t val, MemTxAttrs attrs, MemTxResult *result) { - ADDRESS_SPACE_ST_INTERNAL(l)(ARG1, addr, val, attrs, result, - DEVICE_ENDIANNESS); + ADDRESS_SPACE_ST_INTERNAL(l)(ARG1, MO_ENDIAN, + addr, val, attrs, result); } void ADDRESS_SPACE_ST(q)(ARG1_DECL, hwaddr addr, uint64_t val, MemTxAttrs attrs, MemTxResult *result) { - ADDRESS_SPACE_ST_INTERNAL(q)(ARG1, addr, val, attrs, result, - DEVICE_ENDIANNESS); + ADDRESS_SPACE_ST_INTERNAL(q)(ARG1, MO_ENDIAN, + addr, val, attrs, result); } #undef ADDRESS_SPACE_LD
@@ -67,4 +67,4 @@ void ADDRESS_SPACE_ST(q)(ARG1_DECL, hwaddr addr, uint64_t val, #undef ADDRESS_SPACE_ST_INTERNAL #undef ENDIANNESS -#undef DEVICE_ENDIANNESS +#undef MO_ENDIAN
Signature · 1 line
2.52.0
PATCH v5 12/22 system/memory: Use ldm_p() and stm_p() helpers
In reply to Philippe Mathieu-Daudéaddress_space_{ld,st}m_internal() take a MemOp argument so can directly use the {ld,st}m_p() helpers.
--- system/memory_ldst.c.inc | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-)
system/memory_ldst.c.inc +2 -14
@@ -27,7 +27,6 @@ uint64_t glue(address_space_ldm_internal, SUFFIX)(ARG1_DECL, MemOp mop, MemTxResult *result) { const unsigned size = memop_size(mop); - uint8_t *ptr; uint64_t val; MemoryRegion *mr; hwaddr l = size;
@@ -45,12 +44,7 @@ uint64_t glue(address_space_ldm_internal, SUFFIX)(ARG1_DECL, MemOp mop, } else { /* RAM case */ fuzz_dma_read_cb(addr, size, mr); - ptr = qemu_map_ram_ptr(mr->ram_block, addr1); - if ((mop & MO_BSWAP) == MO_LE) { - val = ldn_le_p(ptr, size); - } else { - val = ldn_be_p(ptr, size); - } + val = ldm_p(qemu_map_ram_ptr(mr->ram_block, addr1), mop); r = MEMTX_OK; } if (result) {
@@ -102,7 +96,6 @@ void glue(address_space_stm_internal, SUFFIX)(ARG1_DECL, MemOp mop, MemTxResult *result) { const unsigned size = memop_size(mop); - uint8_t *ptr; MemoryRegion *mr; hwaddr l = size; hwaddr addr1;
@@ -116,12 +109,7 @@ void glue(address_space_stm_internal, SUFFIX)(ARG1_DECL, MemOp mop, r = memory_region_dispatch_write(mr, addr1, val, mop, attrs); } else { /* RAM case */ - ptr = qemu_map_ram_ptr(mr->ram_block, addr1); - if ((mop & MO_BSWAP) == MO_LE) { - stn_le_p(ptr, size, val); - } else { - stn_be_p(ptr, size, val); - } + stm_p(qemu_map_ram_ptr(mr->ram_block, addr1), mop, val); invalidate_and_set_dirty(mr, addr1, size); r = MEMTX_OK; }
Signature · 1 line
2.52.0
Re: [PATCH v5 12/22] system/memory: Use ldm_p() and stm_p() helpers
Quoted 8 lines · Philippe Mathieu-Daudé
address_space_{ld,st}m_internal() take a MemOp argument so can directly use the {ld,st}m_p() helpers.
Suggested-by Paolo Bonzini<[email protected]>Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- system/memory_ldst.c.inc | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-)
r~
PATCH v5 13/22 system/memory: Directly call address_space_ldst[M]_internal() helper
In reply to Philippe Mathieu-DaudéInline internal address_space_ld/st[L,D,Q] helpers, directly calling address_space_ldst[M]_internal().
--- system/memory_ldst.c.inc | 47 --------------------------------- system/memory_ldst_endian.c.inc | 12 ++++----- 2 files changed, 6 insertions(+), 53 deletions(-)
system/memory_ldst.c.inc +0 -47
@@ -57,22 +57,6 @@ uint64_t glue(address_space_ldm_internal, SUFFIX)(ARG1_DECL, MemOp mop, return val; } -/* warning: addr must be aligned */ -static inline uint32_t glue(address_space_ldl_internal, SUFFIX)(ARG1_DECL, - MemOp mop, hwaddr addr, MemTxAttrs attrs, MemTxResult *result) -{ - return glue(address_space_ldm_internal, SUFFIX)(ARG1, mop | MO_32, addr, - attrs, result); -} - -/* warning: addr must be aligned */ -static inline uint64_t glue(address_space_ldq_internal, SUFFIX)(ARG1_DECL, - MemOp mop, hwaddr addr, MemTxAttrs attrs, MemTxResult *result) -{ - return glue(address_space_ldm_internal, SUFFIX)(ARG1, mop | MO_64, addr, - attrs, result); -} - uint8_t glue(address_space_ldub, SUFFIX)(ARG1_DECL, hwaddr addr, MemTxAttrs attrs, MemTxResult *result) {
@@ -80,14 +64,6 @@ uint8_t glue(address_space_ldub, SUFFIX)(ARG1_DECL, hwaddr addr, attrs, result); } -/* warning: addr must be aligned */ -static inline uint16_t glue(address_space_lduw_internal, SUFFIX)(ARG1_DECL, - MemOp mop, hwaddr addr, MemTxAttrs attrs, MemTxResult *result) -{ - return glue(address_space_ldm_internal, SUFFIX)(ARG1, mop | MO_16, addr, - attrs, result); -} - /* warning: addr must be aligned */ static inline void glue(address_space_stm_internal, SUFFIX)(ARG1_DECL, MemOp mop,
@@ -122,14 +98,6 @@ void glue(address_space_stm_internal, SUFFIX)(ARG1_DECL, MemOp mop, RCU_READ_UNLOCK(); } -/* warning: addr must be aligned */ -static inline void glue(address_space_stl_internal, SUFFIX)(ARG1_DECL, - MemOp mop, hwaddr addr, uint32_t val, MemTxAttrs attrs, MemTxResult *result) -{ - glue(address_space_stm_internal, SUFFIX)(ARG1, mop | MO_32, addr, val, - attrs, result); -} - void glue(address_space_stb, SUFFIX)(ARG1_DECL, hwaddr addr, uint8_t val, MemTxAttrs attrs, MemTxResult *result) {
@@ -137,21 +105,6 @@ void glue(address_space_stb, SUFFIX)(ARG1_DECL, hwaddr addr, uint8_t val, attrs, result); } -/* warning: addr must be aligned */ -static inline void glue(address_space_stw_internal, SUFFIX)(ARG1_DECL, - MemOp mop, hwaddr addr, uint16_t val, MemTxAttrs attrs, MemTxResult *result) -{ - glue(address_space_stm_internal, SUFFIX)(ARG1, mop | MO_16, addr, val, - attrs, result); -} - -static inline void glue(address_space_stq_internal, SUFFIX)(ARG1_DECL, - MemOp mop, hwaddr addr, uint64_t val, MemTxAttrs attrs, MemTxResult *result) -{ - glue(address_space_stm_internal, SUFFIX)(ARG1, mop | MO_64, addr, val, - attrs, result); -} - #define ENDIANNESS #define MO_ENDIAN (target_big_endian() ? MO_BE : MO_LE) #include "memory_ldst_endian.c.inc"
system/memory_ldst_endian.c.inc +6 -6
@@ -22,42 +22,42 @@ uint16_t ADDRESS_SPACE_LD(uw)(ARG1_DECL, hwaddr addr, MemTxAttrs attrs, MemTxResult *result) { - return ADDRESS_SPACE_LD_INTERNAL(uw)(ARG1, MO_ENDIAN, + return ADDRESS_SPACE_LD_INTERNAL(m)(ARG1, MO_ENDIAN | MO_16, addr, attrs, result); } uint32_t ADDRESS_SPACE_LD(l)(ARG1_DECL, hwaddr addr, MemTxAttrs attrs, MemTxResult *result) { - return ADDRESS_SPACE_LD_INTERNAL(l)(ARG1, MO_ENDIAN, + return ADDRESS_SPACE_LD_INTERNAL(m)(ARG1, MO_ENDIAN | MO_32, addr, attrs, result); } uint64_t ADDRESS_SPACE_LD(q)(ARG1_DECL, hwaddr addr, MemTxAttrs attrs, MemTxResult *result) { - return ADDRESS_SPACE_LD_INTERNAL(q)(ARG1, MO_ENDIAN, + return ADDRESS_SPACE_LD_INTERNAL(m)(ARG1, MO_ENDIAN | MO_64, addr, attrs, result); } void ADDRESS_SPACE_ST(w)(ARG1_DECL, hwaddr addr, uint16_t val, MemTxAttrs attrs, MemTxResult *result) { - ADDRESS_SPACE_ST_INTERNAL(w)(ARG1, MO_ENDIAN, + ADDRESS_SPACE_ST_INTERNAL(m)(ARG1, MO_ENDIAN | MO_16, addr, val, attrs, result); } void ADDRESS_SPACE_ST(l)(ARG1_DECL, hwaddr addr, uint32_t val, MemTxAttrs attrs, MemTxResult *result) { - ADDRESS_SPACE_ST_INTERNAL(l)(ARG1, MO_ENDIAN, + ADDRESS_SPACE_ST_INTERNAL(m)(ARG1, MO_ENDIAN | MO_32, addr, val, attrs, result); } void ADDRESS_SPACE_ST(q)(ARG1_DECL, hwaddr addr, uint64_t val, MemTxAttrs attrs, MemTxResult *result) { - ADDRESS_SPACE_ST_INTERNAL(q)(ARG1, MO_ENDIAN, + ADDRESS_SPACE_ST_INTERNAL(m)(ARG1, MO_ENDIAN | MO_64, addr, val, attrs, result); }
Signature · 1 line
2.52.0
PATCH v5 14/22 system: Allow restricting the legacy ld/st_phys() 'native-endian' API
In reply to Philippe Mathieu-DaudéGuard the native endian APIs we want to remove by surrounding them with TARGET_NOT_USING_LEGACY_NATIVE_ENDIAN_API #ifdef'ry.
Since all targets can check the definition, do not poison it.
Once a target gets cleaned we'll set the definition in the target config, then the target won't be able to use the legacy API anymore.
--- include/system/memory_ldst_phys.h.inc | 2 ++ scripts/make-config-poison.sh | 1 + 2 files changed, 3 insertions(+)
include/system/memory_ldst_phys.h.inc +2 -0
@@ -31,8 +31,10 @@ static inline void glue(stb_phys, SUFFIX)(ARG1_DECL, hwaddr addr, uint8_t val) MEMTXATTRS_UNSPECIFIED, NULL); } +#ifndef TARGET_NOT_USING_LEGACY_NATIVE_ENDIAN_API #define ENDIANNESS #include "system/memory_ldst_phys_endian.h.inc" +#endif /* TARGET_NOT_USING_LEGACY_NATIVE_ENDIAN_API */ #define ENDIANNESS _le #include "system/memory_ldst_phys_endian.h.inc"
scripts/make-config-poison.sh +1 -0
@@ -11,6 +11,7 @@ exec sed -n \ -e '/CONFIG_USER_ONLY/d' \ -e '/CONFIG_SOFTMMU/d' \ -e '/TARGET_NOT_USING_LEGACY_LDST_PHYS_API/d' \ + -e '/TARGET_NOT_USING_LEGACY_NATIVE_ENDIAN_API/d' \ -e '/^#define / {' \ -e 's///' \ -e 's/ .*//' \
Signature · 1 line
2.52.0
PATCH v5 15/22 system: Allow restricting legacy address_space_ldst() native-endian API
In reply to Philippe Mathieu-DaudéGuard the native endian APIs we want to remove by surrounding them with TARGET_NOT_USING_LEGACY_NATIVE_ENDIAN_API #ifdef'ry.
Once a target gets cleaned we'll set the definition in the target config, then the target won't be able to use the legacy API anymore.
--- include/system/memory_cached.h | 2 ++ include/system/memory_ldst.h.inc | 2 ++ system/memory_ldst.c.inc | 2 ++ 3 files changed, 6 insertions(+)
include/system/memory_cached.h +2 -0
@@ -80,8 +80,10 @@ void address_space_stb_cached(MemoryRegionCache *cache, } } +#ifndef TARGET_NOT_USING_LEGACY_NATIVE_ENDIAN_API #define ENDIANNESS #include "system/memory_ldst_cached.h.inc" +#endif #define ENDIANNESS _le#include "system/memory_ldst_cached.h.inc"
include/system/memory_ldst.h.inc +2 -0
@@ -25,8 +25,10 @@ uint8_t glue(address_space_ldub, SUFFIX)(ARG1_DECL, void glue(address_space_stb, SUFFIX)(ARG1_DECL, hwaddr addr, uint8_t val, MemTxAttrs attrs, MemTxResult *result); +#ifndef TARGET_NOT_USING_LEGACY_NATIVE_ENDIAN_API #define ENDIANNESS #include "system/memory_ldst_endian.h.inc" +#endif /* TARGET_NOT_USING_LEGACY_NATIVE_ENDIAN_API */ #define ENDIANNESS _le #include "system/memory_ldst_endian.h.inc"
system/memory_ldst.c.inc +2 -0
@@ -105,9 +105,11 @@ void glue(address_space_stb, SUFFIX)(ARG1_DECL, hwaddr addr, uint8_t val, attrs, result); } +#ifndef TARGET_NOT_USING_LEGACY_NATIVE_ENDIAN_API #define ENDIANNESS #define MO_ENDIAN (target_big_endian() ? MO_BE : MO_LE) #include "memory_ldst_endian.c.inc" +#endif /* TARGET_NOT_USING_LEGACY_NATIVE_ENDIAN_API */ #define ENDIANNESS _le #define MO_ENDIAN MO_LE
Signature · 1 line
2.52.0
PATCH v5 16/22 system: Allow restricting the legacy cpu_ld/st() 'native-endian' API
In reply to Philippe Mathieu-DaudéGuard the native endian APIs we want to remove by surrounding them with TARGET_NOT_USING_LEGACY_NATIVE_ENDIAN_API #ifdef'ry.
Once a target gets cleaned we'll set the definition in the target config, then the target won't be able to use the legacy API anymore.
--- include/accel/tcg/cpu-ldst.h | 2 ++ 1 file changed, 2 insertions(+)
include/accel/tcg/cpu-ldst.h +2 -0
@@ -428,6 +428,7 @@ cpu_stq_le_data(CPUArchState *env, abi_ptr addr, uint64_t val)cpu_stq_le_data_ra (env, addr, val,0 ); } +#ifndef TARGET_NOT_USING_LEGACY_NATIVE_ENDIAN_API #if TARGET_BIG_ENDIAN # define cpu_lduw_data cpu_lduw_be_data# define cpu_ldsw_data cpu_ldsw_be_data
@@ -501,5 +502,6 @@ static inline uint64_t cpu_ldq_code(CPUArchState *env, abi_ptr addr)MemOpIdx oi =make_memop_idx (MO_TEUQ ,cpu_mmu_index (cs, true));return cpu_ldq_code_mmu (env, addr, oi,0 ); } +#endif /* TARGET_NOT_USING_LEGACY_NATIVE_ENDIAN_API */ #endif /* ACCEL_TCG_CPU_LDST_H */
Signature · 1 line
2.52.0
PATCH v5 17/22 system: Allow restricting the legacy translator_ld() 'native-endian' API
In reply to Philippe Mathieu-DaudéGuard the native endian APIs we want to remove by surrounding them with TARGET_NOT_USING_LEGACY_NATIVE_ENDIAN_API #ifdef'ry.
Once a target gets cleaned we'll set the definition in the target config, then the target won't be able to use the legacy API anymore.
--- include/exec/translator.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
include/exec/translator.h +3 -2
@@ -188,7 +188,8 @@ uint32_t translator_ldl_end(CPUArchState *env, DisasContextBase *db,uint64_t translator_ldq_end (CPUArchState *env,DisasContextBase *db,vaddr pc,MemOp endian); -#ifdef COMPILING_PER_TARGET +#if !defined(TARGET_NOT_USING_LEGACY_NATIVE_ENDIAN_API ) \ + && defined(COMPILING_PER_TARGET )static inline uint16_t translator_lduw (CPUArchState *env,DisasContextBase *db,vaddr pc) {
@@ -227,7 +228,7 @@ translator_ldq_swap(CPUArchState *env, DisasContextBase *db, {return translator_ldq_end (env, db, pc,MO_TE ^ (do_swap *MO_BSWAP )); } -#endif /* COMPILING_PER_TARGET */ +#endif /* !TARGET_NOT_USING_LEGACY_NATIVE_ENDIAN_API && COMPILING_PER_TARGET */ /** * translator_fake_ld - fake instruction load
Signature · 1 line
2.52.0
PATCH v5 18/22 system: Allow restricting the legacy tswap() 'native-endian' API
In reply to Philippe Mathieu-DaudéGuard the native endian APIs we want to remove by surrounding them with TARGET_NOT_USING_LEGACY_NATIVE_ENDIAN_API #ifdef'ry.
Once a target gets cleaned we'll set the definition in the target config, then the target won't be able to use the legacy API anymore.
--- include/exec/tswap.h | 3 +++ 1 file changed, 3 insertions(+)
include/exec/tswap.h +3 -0
@@ -21,6 +21,8 @@#define target_needs_bswap () (HOST_BIG_ENDIAN != target_big_endian())#endif /* COMPILING_PER_TARGET */ +#if defined(CONFIG_USER_ONLY ) \ + || !defined(TARGET_NOT_USING_LEGACY_NATIVE_ENDIAN_API )static inline uint16_t tswap16 (uint16_t s) {if (target_needs_bswap ()) {
@@ -68,5 +70,6 @@ static inline void tswap64s(uint64_t *s) *s =bswap64 (*s); } } +#endif #endif /* TSWAP_H */
Signature · 1 line
2.52.0
PATCH v5 19/22 system: Allow restricting the legacy MO_TE* 'native-endian' definitions
In reply to Philippe Mathieu-DaudéGuard the native endian definitions we want to remove by surrounding them with TARGET_NOT_USING_LEGACY_NATIVE_ENDIAN_API #ifdef'ry.
Once a target gets cleaned we'll set the definition in the target config, then the target won't be able to use the legacy API anymore.
--- include/exec/memop.h | 4 ++++ 1 file changed, 4 insertions(+)
include/exec/memop.h +4 -0
@@ -36,11 +36,13 @@ typedef enum MemOp { MO_BE = MO_BSWAP,#endif #ifdef COMPILING_PER_TARGET +#ifndef TARGET_NOT_USING_LEGACY_NATIVE_ENDIAN_API #if TARGET_BIG_ENDIAN MO_TE = MO_BE, #else MO_TE = MO_LE,#endif +#endif #endif /*
@@ -150,6 +152,7 @@ typedef enum MemOp { MO_BESQ = MO_BE | MO_SQ,#ifdef COMPILING_PER_TARGET +#ifndef TARGET_NOT_USING_LEGACY_NATIVE_ENDIAN_API MO_TEUW =MO_TE |MO_UW ,MO_TEUL =MO_TE |MO_UL , MO_TEUQ = MO_TE | MO_UQ,
@@ -157,6 +160,7 @@ typedef enum MemOp { MO_TESW = MO_TE | MO_SW, MO_TESL = MO_TE | MO_SL, MO_TESQ = MO_TE | MO_SQ, +#endif #endif MO_SSIZE = MO_SIZE | MO_SIGN,
Signature · 1 line
2.52.0
PATCH v5 20/22 system: Allow restricting the legacy DEVICE_NATIVE_ENDIAN definition
In reply to Philippe Mathieu-DaudéGuard the native endian definition we want to remove by surrounding it with TARGET_NOT_USING_LEGACY_NATIVE_ENDIAN_API #ifdef'ry. Assign values to the enumerators so they stay unchanged.
Once a target gets cleaned we'll set the definition in the target config, then the target won't be able to use the legacy API anymore.
--- include/system/memory.h | 8 +++++--- system/memory-internal.h | 2 ++ 2 files changed, 7 insertions(+), 3 deletions(-)
include/system/memory.h +5 -3
@@ -27,9 +27,11 @@#include "qemu/rcu.h" enum device_endian { -DEVICE_NATIVE_ENDIAN , -DEVICE_BIG_ENDIAN , -DEVICE_LITTLE_ENDIAN , +#ifndef TARGET_NOT_USING_LEGACY_NATIVE_ENDIAN_API +DEVICE_NATIVE_ENDIAN =0 , +#endif +DEVICE_BIG_ENDIAN =1 , +DEVICE_LITTLE_ENDIAN =2 , };#define RAM_ADDR_INVALID (~(ram_addr_t)0)
system/memory-internal.h +2 -0
@@ -41,9 +41,11 @@ void mtree_print_dispatch(struct AddressSpaceDispatch *d,/* returns true if end is big endian. */ static inline bool devend_big_endian (enum device_endian end) { +#ifndef TARGET_NOT_USING_LEGACY_NATIVE_ENDIAN_API if (end ==DEVICE_NATIVE_ENDIAN ) {return target_big_endian (); } +#endif return end ==DEVICE_BIG_ENDIAN ; }
Signature · 1 line
2.52.0
Re: [PATCH v5 20/22] system: Allow restricting the legacy DEVICE_NATIVE_ENDIAN definition
Quoted 4 lines · Philippe Mathieu-Daudé
Guard the native endian definition we want to remove by surrounding it with
TARGET_NOT_USING_LEGACY_NATIVE_ENDIAN_API#ifdef'ry. Assign values to the enumerators so they stay unchanged.
Quoted 8 lines
Once a target gets cleaned we'll set the definition in the target config, then the target won't be able to use the legacy API anymore.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/system/memory.h | 8 +++++--- system/memory-internal.h | 2 ++ 2 files changed, 7 insertions(+), 3 deletions(-)
r~
Quoted 36 lines
include/system/memory.h +5
-3@@ -27,9 +27,11 @@#include "qemu/rcu.h" enum device_endian { -DEVICE_NATIVE_ENDIAN , -DEVICE_BIG_ENDIAN , -DEVICE_LITTLE_ENDIAN , +#ifndef TARGET_NOT_USING_LEGACY_NATIVE_ENDIAN_API +DEVICE_NATIVE_ENDIAN =0 , +#endif +DEVICE_BIG_ENDIAN =1 , +DEVICE_LITTLE_ENDIAN =2 , };#define RAM_ADDR_INVALID (~(ram_addr_t)0)system/memory-internal.h +2
-0@@ -41,9 +41,11 @@ void mtree_print_dispatch(struct AddressSpaceDispatch *d,/* returns true if end is big endian. */ static inline bool devend_big_endian (enum device_endian end) { +#ifndef TARGET_NOT_USING_LEGACY_NATIVE_ENDIAN_API if (end ==DEVICE_NATIVE_ENDIAN ) {return target_big_endian (); } +#endif return end ==DEVICE_BIG_ENDIAN ; }
PATCH v5 21/22 system/ioport: Declare x86-specific I/O port in little-endian order
In reply to Philippe Mathieu-DaudéX86 in/out port (related to ISA bus) uses little endianness:
- enforce little endianness in x86 cpu_in/out() accessors,
- serialize QTest in/out port accesses as little-endian.
--- system/ioport.c | 10 +++++----- tests/qtest/endianness-test.c | 10 ++++++---- tests/qtest/libqtest.c | 13 +++++++++---- 3 files changed, 20 insertions(+), 13 deletions(-)
system/ioport.c +5 -5
@@ -56,7 +56,7 @@ static void unassigned_io_write(void *opaque, hwaddr addr, uint64_t val,const MemoryRegionOps unassigned_io_ops = { .read = unassigned_io_read, .write = unassigned_io_write, - .endianness =DEVICE_NATIVE_ENDIAN , + .endianness =DEVICE_LITTLE_ENDIAN , };void cpu_outb (uint32_t addr,uint8_t val)
@@ -71,7 +71,7 @@ void cpu_outw(uint32_t addr, uint16_t val)uint8_t buf[2 ];trace_cpu_out (addr,'w' , val); -stw_p (buf, val); +stw_le_p (buf, val);address_space_write (&address_space_io, addr,MEMTXATTRS_UNSPECIFIED , buf,2 ); }
@@ -81,7 +81,7 @@ void cpu_outl(uint32_t addr, uint32_t val)uint8_t buf[4 ];trace_cpu_out (addr,'l' , val); -stl_p (buf, val); +stl_le_p (buf, val);address_space_write (&address_space_io, addr,MEMTXATTRS_UNSPECIFIED , buf,4 ); }
@@ -102,7 +102,7 @@ uint16_t cpu_inw(uint32_t addr)uint16_t val;address_space_read (&address_space_io, addr,MEMTXATTRS_UNSPECIFIED , buf,2 ); - val =lduw_p (buf); + val =lduw_le_p (buf);trace_cpu_in (addr,'w' , val);return val; }
@@ -113,7 +113,7 @@ uint32_t cpu_inl(uint32_t addr)uint32_t val;address_space_read (&address_space_io, addr,MEMTXATTRS_UNSPECIFIED , buf,4 ); - val =ldl_p (buf); + val =ldl_le_p (buf);trace_cpu_in (addr,'l' , val);return val; }
tests/qtest/endianness-test.c +6 -4
@@ -65,8 +65,9 @@ static uint16_t isa_inw(QTestState *qts, const TestCase *test, uint16_t addr) value =qtest_inw (qts, addr); }else { value =qtest_readw (qts, test->isa_base + addr); + value = test->bswap ?bswap16 (value) : value; } -return test->bswap ?bswap16 (value) : value; +return value; }static uint32_t isa_inl (QTestState *qts,const TestCase *test,uint16_t addr)
@@ -76,8 +77,9 @@ static uint32_t isa_inl(QTestState *qts, const TestCase *test, uint16_t addr) value =qtest_inl (qts, addr); }else { value =qtest_readl (qts, test->isa_base + addr); + value = test->bswap ?bswap32 (value) : value; } -return test->bswap ?bswap32 (value) : value; +return value; } static void isa_outb(QTestState *qts, const TestCase *test, uint16_t addr,
@@ -93,10 +95,10 @@ static void isa_outb(QTestState *qts, const TestCase *test, uint16_t addr,static void isa_outw (QTestState *qts,const TestCase *test,uint16_t addr,uint16_t value) { - value = test->bswap ?bswap16 (value) : value;if (test->isa_base ==-1 ) {qtest_outw (qts, addr, value); }else { + value = test->bswap ?bswap16 (value) : value;qtest_writew (qts, test->isa_base + addr, value); } }
@@ -104,10 +106,10 @@ static void isa_outw(QTestState *qts, const TestCase *test, uint16_t addr,static void isa_outl (QTestState *qts,const TestCase *test,uint16_t addr,uint32_t value) { - value = test->bswap ?bswap32 (value) : value;if (test->isa_base ==-1 ) {qtest_outl (qts, addr, value); }else { + value = test->bswap ?bswap32 (value) : value;qtest_writel (qts, test->isa_base + addr, value); } }
tests/qtest/libqtest.c +9 -4
@@ -31,6 +31,7 @@#include "libqtest.h" #include "libqmp.h" #include "qemu/accel.h" +#include "qemu/bswap.h" #include "qemu/ctype.h" #include "qemu/cutils.h" #include "qemu/exit-with-parent.h"
@@ -1190,12 +1191,12 @@ void qtest_outb(QTestState *s, uint16_t addr, uint8_t value)void qtest_outw (QTestState *s,uint16_t addr,uint16_t value) { -qtest_out (s,"outw" , addr, value); +qtest_out (s,"outw" , addr,qtest_big_endian (s) ?bswap16 (value) : value); }void qtest_outl (QTestState *s,uint16_t addr,uint32_t value) { -qtest_out (s,"outl" , addr, value); +qtest_out (s,"outl" , addr,qtest_big_endian (s) ?bswap32 (value) : value); }static uint32_t qtest_in (QTestState *s,const char *cmd,uint16_t addr)
@@ -1220,12 +1221,16 @@ uint8_t qtest_inb(QTestState *s, uint16_t addr)uint16_t qtest_inw (QTestState *s,uint16_t addr) { -return qtest_in (s,"inw" , addr); +uint16_t v =qtest_in (s,"inw" , addr); + +return qtest_big_endian (s) ?bswap16 (v) : v; }uint32_t qtest_inl (QTestState *s,uint16_t addr) { -return qtest_in (s,"inl" , addr); +uint32_t v =qtest_in (s,"inl" , addr); + +return qtest_big_endian (s) ?bswap32 (v) : v; } static void qtest_write(QTestState *s, const char *cmd, uint64_t addr,
Signature · 1 line
2.52.0
PATCH v5 22/22 system/ioport: Do not open-code address_space_ld/st_le() methods
In reply to Philippe Mathieu-DaudéWhen a variable size is known, prefer the address_space_ld/st() API. Keep address_space_read/write() for blobs.
--- system/ioport.c | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-)
system/ioport.c +12 -20
@@ -62,58 +62,50 @@ const MemoryRegionOps unassigned_io_ops = {void cpu_outb (uint32_t addr,uint8_t val) {trace_cpu_out (addr,'b' , val); -address_space_write (&address_space_io, addr,MEMTXATTRS_UNSPECIFIED , - &val,1 ); +address_space_stb (&address_space_io, addr, val, +MEMTXATTRS_UNSPECIFIED ,NULL ); }void cpu_outw (uint32_t addr,uint16_t val) { -uint8_t buf[2 ]; -trace_cpu_out (addr,'w' , val); -stw_le_p (buf, val); -address_space_write (&address_space_io, addr,MEMTXATTRS_UNSPECIFIED , - buf,2 ); +address_space_stw_le (&address_space_io, addr, val, +MEMTXATTRS_UNSPECIFIED ,NULL ); }void cpu_outl (uint32_t addr,uint32_t val) { -uint8_t buf[4 ]; -trace_cpu_out (addr,'l' , val); -stl_le_p (buf, val); -address_space_write (&address_space_io, addr,MEMTXATTRS_UNSPECIFIED , - buf,4 ); +address_space_stl_le (&address_space_io, addr, val, +MEMTXATTRS_UNSPECIFIED ,NULL ); }uint8_t cpu_inb (uint32_t addr) {uint8_t val; -address_space_read (&address_space_io, addr,MEMTXATTRS_UNSPECIFIED , - &val,1 ); + val =address_space_ldub (&address_space_io, addr, +MEMTXATTRS_UNSPECIFIED ,NULL );trace_cpu_in (addr,'b' , val);return val; }uint16_t cpu_inw (uint32_t addr) { -uint8_t buf[2 ];uint16_t val; -address_space_read (&address_space_io, addr,MEMTXATTRS_UNSPECIFIED , buf,2 ); - val =lduw_le_p (buf); + val =address_space_lduw_le (&address_space_io, addr, +MEMTXATTRS_UNSPECIFIED ,NULL );trace_cpu_in (addr,'w' , val);return val; }uint32_t cpu_inl (uint32_t addr) { -uint8_t buf[4 ];uint32_t val; -address_space_read (&address_space_io, addr,MEMTXATTRS_UNSPECIFIED , buf,4 ); - val =ldl_le_p (buf); + val =address_space_ldl_le (&address_space_io, addr, +MEMTXATTRS_UNSPECIFIED ,NULL );trace_cpu_in (addr,'l' , val);return val; }
Signature · 1 line
2.52.0
Il ven 9 gen 2026, 17:51 Philippe Mathieu-Daudé <[email protected]> ha scritto:
Quoted 5 lines
Missing review: 2, 12, 20
Since v4:
- No change (RESEND)
For subpages, are you leaving for later the switch away from DEVICE_NATIVE_ENDIAN?
Paolo
Since v3:
Quoted 74 lines
- Assign
device_endianenums (Richard)
- Add/useldm_p()andstm_p()helpers (Paolo)Since v2:
- Changed opt-out to opt-in approach (Pierrick)
- Split big patches in smaller ones
- Mark ioport little-endianPhilippe Mathieu-Daudé (22):
MAINTAINERS: Cover 'system/memory_ldst*.h.inc' files
util: Introduceldm_p()andstm_p()load/store helpers system/physmem: Inline and removeleul_to_cpu()system/physmem: ConvertDEBUG_SUBPAGEprintf()to trace events system/memory: Split MemoryRegionCache API to 'memory_cached.h' system/memory: Inlineaddress_space_stq_internal()system/memory: Define address_space_ldst[W] endian variants via
template
system/memory: Define address_space_ldst[L] endian variants via
template
system/memory: Define address_space_ldst[Q] endian variants via
template
system/memory: Factor address_space_ldst[M]_internal() helper out system/memory: Passdevice_endianargument as MemOp bit system/memory: Useldm_p()andstm_p()helpers system/memory: Directly call address_space_ldst[M]_internal() helper
system: Allow restricting the legacy ld/st_phys() 'native-endian' API
system: Allow restricting legacyaddress_space_ldst()native-endian
API
system: Allow restricting the legacy cpu_ld/st() 'native-endian' API
system: Allow restricting the legacytranslator_ld()'native-endian'
API
system: Allow restricting the legacytswap()'native-endian' API
system: Allow restricting the legacy MO_TE* 'native-endian'
definitions
system: Allow restricting the legacyDEVICE_NATIVE_ENDIANdefinition system/ioport: Declare x86-specific I/O port in little-endian order system/ioport: Do not open-code address_space_ld/st_le() methodsMAINTAINERS | 4 + include/accel/tcg/cpu-ldst.h | 2 + include/exec/memop.h | 4 + include/exec/translator.h | 5 +- include/exec/tswap.h | 3 + include/hw/virtio/virtio-access.h | 1 + include/qemu/bswap.h | 11 - include/qemu/ldst_unaligned.h | 25 ++ include/system/memory.h | 193 +------- include/system/memory_cached.h | 212 +++++++++ system/memory-internal.h | 2 + include/system/memory_ldst.h.inc | 52 +-- include/system/memory_ldst_endian.h.inc | 33 ++ include/system/memory_ldst_phys.h.inc | 113 +---- include/system/memory_ldst_phys_endian.h.inc | 57 +++ system/ioport.c | 34 +- system/physmem.c | 35 +- tests/qtest/endianness-test.c | 10 +- tests/qtest/libqtest.c | 13 +- util/ldst.c | 69 +++ system/memory_ldst.c.inc | 449 ++----------------- system/memory_ldst_endian.c.inc | 70 +++ scripts/make-config-poison.sh | 1 + system/trace-events | 6 + util/meson.build | 1 + 25 files changed, 599 insertions(+), 806 deletions(-) create mode 100644 include/system/memory_cached.h create mode 100644 include/system/memory_ldst_endian.h.inc create mode 100644 include/system/memory_ldst_phys_endian.h.inc create mode 100644 util/ldst.c create mode 100644 system/memory_ldst_endian.c.inc--
2.52.0
Quoted 11 lines · Paolo Bonzini
Il ven 9 gen 2026, 17:51 Philippe Mathieu-Daudé <[email protected] <mailto:[email protected]>> ha scritto:
Missing review: 2, 12, 20
Since v4:
- No change (RESEND)For subpages, are you leaving for later the switch away from
DEVICE_NATIVE_ENDIAN?
Yes, this can be done later (I rather not delay the rest).
Quoted 2 lines
Paolo