memory_ldst_cached.h.inc 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * Memory access templates for MemoryRegionCache
  3. *
  4. * Copyright (c) 2018 Red Hat, Inc.
  5. *
  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.
  10. *
  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.
  15. *
  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/>.
  18. */
  19. #define ADDRESS_SPACE_LD_CACHED(size) \
  20. glue(glue(address_space_ld, size), glue(ENDIANNESS, _cached))
  21. #define ADDRESS_SPACE_LD_CACHED_SLOW(size) \
  22. glue(glue(address_space_ld, size), glue(ENDIANNESS, _cached_slow))
  23. #define LD_P(size) \
  24. glue(glue(ld, size), glue(ENDIANNESS, _p))
  25. static inline uint16_t ADDRESS_SPACE_LD_CACHED(uw)(MemoryRegionCache *cache,
  26. hwaddr addr, MemTxAttrs attrs, MemTxResult *result)
  27. {
  28. assert(addr < cache->len && 2 <= cache->len - addr);
  29. fuzz_dma_read_cb(cache->xlat + addr, 2, cache->mrs.mr);
  30. if (likely(cache->ptr)) {
  31. return LD_P(uw)(cache->ptr + addr);
  32. } else {
  33. return ADDRESS_SPACE_LD_CACHED_SLOW(uw)(cache, addr, attrs, result);
  34. }
  35. }
  36. static inline uint32_t ADDRESS_SPACE_LD_CACHED(l)(MemoryRegionCache *cache,
  37. hwaddr addr, MemTxAttrs attrs, MemTxResult *result)
  38. {
  39. assert(addr < cache->len && 4 <= cache->len - addr);
  40. fuzz_dma_read_cb(cache->xlat + addr, 4, cache->mrs.mr);
  41. if (likely(cache->ptr)) {
  42. return LD_P(l)(cache->ptr + addr);
  43. } else {
  44. return ADDRESS_SPACE_LD_CACHED_SLOW(l)(cache, addr, attrs, result);
  45. }
  46. }
  47. static inline uint64_t ADDRESS_SPACE_LD_CACHED(q)(MemoryRegionCache *cache,
  48. hwaddr addr, MemTxAttrs attrs, MemTxResult *result)
  49. {
  50. assert(addr < cache->len && 8 <= cache->len - addr);
  51. fuzz_dma_read_cb(cache->xlat + addr, 8, cache->mrs.mr);
  52. if (likely(cache->ptr)) {
  53. return LD_P(q)(cache->ptr + addr);
  54. } else {
  55. return ADDRESS_SPACE_LD_CACHED_SLOW(q)(cache, addr, attrs, result);
  56. }
  57. }
  58. #undef ADDRESS_SPACE_LD_CACHED
  59. #undef ADDRESS_SPACE_LD_CACHED_SLOW
  60. #undef LD_P
  61. #define ADDRESS_SPACE_ST_CACHED(size) \
  62. glue(glue(address_space_st, size), glue(ENDIANNESS, _cached))
  63. #define ADDRESS_SPACE_ST_CACHED_SLOW(size) \
  64. glue(glue(address_space_st, size), glue(ENDIANNESS, _cached_slow))
  65. #define ST_P(size) \
  66. glue(glue(st, size), glue(ENDIANNESS, _p))
  67. static inline void ADDRESS_SPACE_ST_CACHED(w)(MemoryRegionCache *cache,
  68. hwaddr addr, uint16_t val, MemTxAttrs attrs, MemTxResult *result)
  69. {
  70. assert(addr < cache->len && 2 <= cache->len - addr);
  71. if (likely(cache->ptr)) {
  72. ST_P(w)(cache->ptr + addr, val);
  73. } else {
  74. ADDRESS_SPACE_ST_CACHED_SLOW(w)(cache, addr, val, attrs, result);
  75. }
  76. }
  77. static inline void ADDRESS_SPACE_ST_CACHED(l)(MemoryRegionCache *cache,
  78. hwaddr addr, uint32_t val, MemTxAttrs attrs, MemTxResult *result)
  79. {
  80. assert(addr < cache->len && 4 <= cache->len - addr);
  81. if (likely(cache->ptr)) {
  82. ST_P(l)(cache->ptr + addr, val);
  83. } else {
  84. ADDRESS_SPACE_ST_CACHED_SLOW(l)(cache, addr, val, attrs, result);
  85. }
  86. }
  87. static inline void ADDRESS_SPACE_ST_CACHED(q)(MemoryRegionCache *cache,
  88. hwaddr addr, uint64_t val, MemTxAttrs attrs, MemTxResult *result)
  89. {
  90. assert(addr < cache->len && 8 <= cache->len - addr);
  91. if (likely(cache->ptr)) {
  92. ST_P(q)(cache->ptr + addr, val);
  93. } else {
  94. ADDRESS_SPACE_ST_CACHED_SLOW(q)(cache, addr, val, attrs, result);
  95. }
  96. }
  97. #undef ADDRESS_SPACE_ST_CACHED
  98. #undef ADDRESS_SPACE_ST_CACHED_SLOW
  99. #undef ST_P
  100. #undef ENDIANNESS