@samitouri / QOSamiQemu / commits / 77293ecc95

system/memory: Constify various MemoryRegionCache arguments

Mark the MemoryRegionCache structure const when it is only accessed read-only. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org> Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Message-Id: <20260616020359.18627-7-philmd@oss.qualcomm.com>

Philippe Mathieu-Daudé committed Mar 19, 2026 at 13:38 UTC 77293ecc95dbf038405e71197e6d57aabfbadddc
3 files changed +23 -20
include/system/memory_cached.h
+9 -9
@@ -51,12 +51,12 @@ struct MemoryRegionCache {
51
52 #define SUFFIX _cached_slow
53 #define ARG1 cache
54 -#define ARG1_DECL MemoryRegionCache *cache
54 +#define ARG1_DECL const MemoryRegionCache *cache
55 #include "system/memory_ldst.h.inc"
56
57 /* Inline fast path for direct RAM access. */
58 static inline
59 -uint8_t address_space_ldub_cached(MemoryRegionCache *cache, hwaddr addr,
59 +uint8_t address_space_ldub_cached(const MemoryRegionCache *cache, hwaddr addr,
60 MemTxAttrs attrs, MemTxResult *result)
61 {
62 assert(addr < cache->len);
@@ -68,7 +68,7 @@ uint8_t address_space_ldub_cached(MemoryRegionCache *cache, hwaddr addr,
68 }
69
70 static inline
71 -void address_space_stb_cached(MemoryRegionCache *cache,
71 +void address_space_stb_cached(const MemoryRegionCache *cache,
72 hwaddr addr, uint8_t val,
73 MemTxAttrs attrs, MemTxResult *result)
74 {
@@ -93,7 +93,7 @@ void address_space_stb_cached(MemoryRegionCache *cache,
93
94 #define SUFFIX _cached
95 #define ARG1 cache
96 -#define ARG1_DECL MemoryRegionCache *cache
96 +#define ARG1_DECL const MemoryRegionCache *cache
97 #include "system/memory_ldst_phys.h.inc"
98
99 /**
@@ -145,7 +145,7 @@ static inline void address_space_cache_init_empty(MemoryRegionCache *cache)
145 * address that was passed to @address_space_cache_init.
146 * @access_len: The number of bytes that were written starting at @addr.
147 */
148 -void address_space_cache_invalidate(MemoryRegionCache *cache,
148 +void address_space_cache_invalidate(const MemoryRegionCache *cache,
149 hwaddr addr,
150 hwaddr access_len);
151
@@ -160,9 +160,9 @@ void address_space_cache_destroy(MemoryRegionCache *cache);
160 * Internal functions, part of the implementation of address_space_read_cached
161 * and address_space_write_cached.
162 */
163 -MemTxResult address_space_read_cached_slow(MemoryRegionCache *cache,
163 +MemTxResult address_space_read_cached_slow(const MemoryRegionCache *cache,
164 hwaddr addr, void *buf, hwaddr len);
165 -MemTxResult address_space_write_cached_slow(MemoryRegionCache *cache,
165 +MemTxResult address_space_write_cached_slow(const MemoryRegionCache *cache,
166 hwaddr addr, const void *buf,
167 hwaddr len);
168
@@ -175,7 +175,7 @@ MemTxResult address_space_write_cached_slow(MemoryRegionCache *cache,
175 * @len: length of the data transferred
176 */
177 static inline MemTxResult
178 -address_space_read_cached(MemoryRegionCache *cache, hwaddr addr,
178 +address_space_read_cached(const MemoryRegionCache *cache, hwaddr addr,
179 void *buf, hwaddr len)
180 {
181 assert(addr < cache->len && len <= cache->len - addr);
@@ -197,7 +197,7 @@ address_space_read_cached(MemoryRegionCache *cache, hwaddr addr,
197 * @len: length of the data transferred
198 */
199 static inline MemTxResult
200 -address_space_write_cached(MemoryRegionCache *cache, hwaddr addr,
200 +address_space_write_cached(const MemoryRegionCache *cache, hwaddr addr,
201 const void *buf, hwaddr len)
202 {
203 assert(addr < cache->len && len <= cache->len - addr);
include/system/memory_ldst_cached.h.inc
+9 -6
@@ -24,7 +24,8 @@
24 #define LD_P(size) \
25 glue(glue(ld, size), glue(ENDIANNESS, _p))
26
27 -static inline uint16_t ADDRESS_SPACE_LD_CACHED(uw)(MemoryRegionCache *cache,
27 +static inline
28 +uint16_t ADDRESS_SPACE_LD_CACHED(uw)(const MemoryRegionCache *cache,
29 hwaddr addr, MemTxAttrs attrs, MemTxResult *result)
30 {
31 assert(addr < cache->len && 2 <= cache->len - addr);
@@ -36,7 +37,8 @@ static inline uint16_t ADDRESS_SPACE_LD_CACHED(uw)(MemoryRegionCache *cache,
37 }
38 }
39
39 -static inline uint32_t ADDRESS_SPACE_LD_CACHED(l)(MemoryRegionCache *cache,
40 +static inline
41 +uint32_t ADDRESS_SPACE_LD_CACHED(l)(const MemoryRegionCache *cache,
42 hwaddr addr, MemTxAttrs attrs, MemTxResult *result)
43 {
44 assert(addr < cache->len && 4 <= cache->len - addr);
@@ -48,7 +50,8 @@ static inline uint32_t ADDRESS_SPACE_LD_CACHED(l)(MemoryRegionCache *cache,
50 }
51 }
52
51 -static inline uint64_t ADDRESS_SPACE_LD_CACHED(q)(MemoryRegionCache *cache,
53 +static inline
54 +uint64_t ADDRESS_SPACE_LD_CACHED(q)(const MemoryRegionCache *cache,
55 hwaddr addr, MemTxAttrs attrs, MemTxResult *result)
56 {
57 assert(addr < cache->len && 8 <= cache->len - addr);
@@ -71,7 +74,7 @@ static inline uint64_t ADDRESS_SPACE_LD_CACHED(q)(MemoryRegionCache *cache,
74 #define ST_P(size) \
75 glue(glue(st, size), glue(ENDIANNESS, _p))
76
74 -static inline void ADDRESS_SPACE_ST_CACHED(w)(MemoryRegionCache *cache,
77 +static inline void ADDRESS_SPACE_ST_CACHED(w)(const MemoryRegionCache *cache,
78 hwaddr addr, uint16_t val, MemTxAttrs attrs, MemTxResult *result)
79 {
80 assert(addr < cache->len && 2 <= cache->len - addr);
@@ -82,7 +85,7 @@ static inline void ADDRESS_SPACE_ST_CACHED(w)(MemoryRegionCache *cache,
85 }
86 }
87
85 -static inline void ADDRESS_SPACE_ST_CACHED(l)(MemoryRegionCache *cache,
88 +static inline void ADDRESS_SPACE_ST_CACHED(l)(const MemoryRegionCache *cache,
89 hwaddr addr, uint32_t val, MemTxAttrs attrs, MemTxResult *result)
90 {
91 assert(addr < cache->len && 4 <= cache->len - addr);
@@ -93,7 +96,7 @@ static inline void ADDRESS_SPACE_ST_CACHED(l)(MemoryRegionCache *cache,
96 }
97 }
98
96 -static inline void ADDRESS_SPACE_ST_CACHED(q)(MemoryRegionCache *cache,
99 +static inline void ADDRESS_SPACE_ST_CACHED(q)(const MemoryRegionCache *cache,
100 hwaddr addr, uint64_t val, MemTxAttrs attrs, MemTxResult *result)
101 {
102 assert(addr < cache->len && 8 <= cache->len - addr);
system/physmem.c
+5 -5
@@ -3878,7 +3878,7 @@ int64_t address_space_cache_init(MemoryRegionCache *cache,
3878 return l;
3879 }
3880
3881 -void address_space_cache_invalidate(MemoryRegionCache *cache,
3881 +void address_space_cache_invalidate(const MemoryRegionCache *cache,
3882 hwaddr addr,
3883 hwaddr access_len)
3884 {
@@ -3909,7 +3909,7 @@ void address_space_cache_destroy(MemoryRegionCache *cache)
3909 * address_space_cache_init.
3910 */
3911 static inline MemoryRegion *address_space_translate_cached(
3912 - MemoryRegionCache *cache, hwaddr addr, hwaddr *xlat,
3912 + const MemoryRegionCache *cache, hwaddr addr, hwaddr *xlat,
3913 hwaddr *plen, bool is_write, MemTxAttrs attrs)
3914 {
3915 MemoryRegionSection section;
@@ -3990,7 +3990,7 @@ static MemTxResult address_space_read_continue_cached(MemTxAttrs attrs,
3990 * out of line function when the target is an MMIO or IOMMU region.
3991 */
3992 MemTxResult
3993 -address_space_read_cached_slow(MemoryRegionCache *cache, hwaddr addr,
3993 +address_space_read_cached_slow(const MemoryRegionCache *cache, hwaddr addr,
3994 void *buf, hwaddr len)
3995 {
3996 hwaddr mr_addr, l;
@@ -4007,7 +4007,7 @@ address_space_read_cached_slow(MemoryRegionCache *cache, hwaddr addr,
4007 * out of line function when the target is an MMIO or IOMMU region.
4008 */
4009 MemTxResult
4010 -address_space_write_cached_slow(MemoryRegionCache *cache, hwaddr addr,
4010 +address_space_write_cached_slow(const MemoryRegionCache *cache, hwaddr addr,
4011 const void *buf, hwaddr len)
4012 {
4013 hwaddr mr_addr, l;
@@ -4020,7 +4020,7 @@ address_space_write_cached_slow(MemoryRegionCache *cache, hwaddr addr,
4020 buf, len, mr_addr, l, mr);
4021 }
4022
4023 -#define ARG1_DECL MemoryRegionCache *cache
4023 +#define ARG1_DECL const MemoryRegionCache *cache
4024 #define ARG1 cache
4025 #define SUFFIX _cached_slow
4026 #define TRANSLATE(...) address_space_translate_cached(cache, __VA_ARGS__)