2 * Memory access templates for MemoryRegionCache
4 * Copyright (c) 2018 Red Hat, Inc.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
20 #define ADDRESS_SPACE_LD_CACHED(size) \
21 glue(glue(address_space_ld, size), glue(ENDIANNESS, _cached))
22 #define ADDRESS_SPACE_LD_CACHED_SLOW(size) \
23 glue(glue(address_space_ld, size), glue(ENDIANNESS, _cached_slow))
25 glue(glue(ld, size), glue(ENDIANNESS, _p))
27 static inline uint16_t ADDRESS_SPACE_LD_CACHED(uw)(MemoryRegionCache *cache,
28 hwaddr addr, MemTxAttrs attrs, MemTxResult *result)
30 assert(addr < cache->len && 2 <= cache->len - addr);
31 fuzz_dma_read_cb(cache->xlat + addr, 2, cache->mrs.mr);
32 if (likely(cache->ptr)) {
33 return LD_P(uw)(cache->ptr + addr);
35 return ADDRESS_SPACE_LD_CACHED_SLOW(uw)(cache, addr, attrs, result);
39 static inline uint32_t ADDRESS_SPACE_LD_CACHED(l)(MemoryRegionCache *cache,
40 hwaddr addr, MemTxAttrs attrs, MemTxResult *result)
42 assert(addr < cache->len && 4 <= cache->len - addr);
43 fuzz_dma_read_cb(cache->xlat + addr, 4, cache->mrs.mr);
44 if (likely(cache->ptr)) {
45 return LD_P(l)(cache->ptr + addr);
47 return ADDRESS_SPACE_LD_CACHED_SLOW(l)(cache, addr, attrs, result);
51 static inline uint64_t ADDRESS_SPACE_LD_CACHED(q)(MemoryRegionCache *cache,
52 hwaddr addr, MemTxAttrs attrs, MemTxResult *result)
54 assert(addr < cache->len && 8 <= cache->len - addr);
55 fuzz_dma_read_cb(cache->xlat + addr, 8, cache->mrs.mr);
56 if (likely(cache->ptr)) {
57 return LD_P(q)(cache->ptr + addr);
59 return ADDRESS_SPACE_LD_CACHED_SLOW(q)(cache, addr, attrs, result);
63 #undef ADDRESS_SPACE_LD_CACHED
64 #undef ADDRESS_SPACE_LD_CACHED_SLOW
67 #define ADDRESS_SPACE_ST_CACHED(size) \
68 glue(glue(address_space_st, size), glue(ENDIANNESS, _cached))
69 #define ADDRESS_SPACE_ST_CACHED_SLOW(size) \
70 glue(glue(address_space_st, size), glue(ENDIANNESS, _cached_slow))
72 glue(glue(st, size), glue(ENDIANNESS, _p))
74 static inline void ADDRESS_SPACE_ST_CACHED(w)(MemoryRegionCache *cache,
75 hwaddr addr, uint16_t val, MemTxAttrs attrs, MemTxResult *result)
77 assert(addr < cache->len && 2 <= cache->len - addr);
78 if (likely(cache->ptr)) {
79 ST_P(w)(cache->ptr + addr, val);
81 ADDRESS_SPACE_ST_CACHED_SLOW(w)(cache, addr, val, attrs, result);
85 static inline void ADDRESS_SPACE_ST_CACHED(l)(MemoryRegionCache *cache,
86 hwaddr addr, uint32_t val, MemTxAttrs attrs, MemTxResult *result)
88 assert(addr < cache->len && 4 <= cache->len - addr);
89 if (likely(cache->ptr)) {
90 ST_P(l)(cache->ptr + addr, val);
92 ADDRESS_SPACE_ST_CACHED_SLOW(l)(cache, addr, val, attrs, result);
96 static inline void ADDRESS_SPACE_ST_CACHED(q)(MemoryRegionCache *cache,
97 hwaddr addr, uint64_t val, MemTxAttrs attrs, MemTxResult *result)
99 assert(addr < cache->len && 8 <= cache->len - addr);
100 if (likely(cache->ptr)) {
101 ST_P(q)(cache->ptr + addr, val);
103 ADDRESS_SPACE_ST_CACHED_SLOW(q)(cache, addr, val, attrs, result);
107 #undef ADDRESS_SPACE_ST_CACHED
108 #undef ADDRESS_SPACE_ST_CACHED_SLOW