2
0

arm_l2x0.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /*
  2. * ARM dummy L210, L220, PL310 cache controller.
  3. *
  4. * Copyright (c) 2010-2012 Calxeda
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms and conditions of the GNU General Public License,
  8. * version 2 or any later version, as published by the Free Software
  9. * Foundation.
  10. *
  11. * This program is distributed in the hope it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along with
  17. * this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. */
  20. #include "qemu/osdep.h"
  21. #include "hw/qdev-properties.h"
  22. #include "hw/sysbus.h"
  23. #include "migration/vmstate.h"
  24. #include "qemu/log.h"
  25. #include "qemu/module.h"
  26. #include "qom/object.h"
  27. /* L2C-310 r3p2 */
  28. #define CACHE_ID 0x410000c8
  29. #define TYPE_ARM_L2X0 "l2x0"
  30. OBJECT_DECLARE_SIMPLE_TYPE(L2x0State, ARM_L2X0)
  31. struct L2x0State {
  32. SysBusDevice parent_obj;
  33. MemoryRegion iomem;
  34. uint32_t cache_type;
  35. uint32_t ctrl;
  36. uint32_t aux_ctrl;
  37. uint32_t data_ctrl;
  38. uint32_t tag_ctrl;
  39. uint32_t filter_start;
  40. uint32_t filter_end;
  41. };
  42. static const VMStateDescription vmstate_l2x0 = {
  43. .name = "l2x0",
  44. .version_id = 1,
  45. .minimum_version_id = 1,
  46. .fields = (VMStateField[]) {
  47. VMSTATE_UINT32(ctrl, L2x0State),
  48. VMSTATE_UINT32(aux_ctrl, L2x0State),
  49. VMSTATE_UINT32(data_ctrl, L2x0State),
  50. VMSTATE_UINT32(tag_ctrl, L2x0State),
  51. VMSTATE_UINT32(filter_start, L2x0State),
  52. VMSTATE_UINT32(filter_end, L2x0State),
  53. VMSTATE_END_OF_LIST()
  54. }
  55. };
  56. static uint64_t l2x0_priv_read(void *opaque, hwaddr offset,
  57. unsigned size)
  58. {
  59. uint32_t cache_data;
  60. L2x0State *s = (L2x0State *)opaque;
  61. offset &= 0xfff;
  62. if (offset >= 0x730 && offset < 0x800) {
  63. return 0; /* cache ops complete */
  64. }
  65. switch (offset) {
  66. case 0:
  67. return CACHE_ID;
  68. case 0x4:
  69. /* aux_ctrl values affect cache_type values */
  70. cache_data = (s->aux_ctrl & (7 << 17)) >> 15;
  71. cache_data |= (s->aux_ctrl & (1 << 16)) >> 16;
  72. return s->cache_type |= (cache_data << 18) | (cache_data << 6);
  73. case 0x100:
  74. return s->ctrl;
  75. case 0x104:
  76. return s->aux_ctrl;
  77. case 0x108:
  78. return s->tag_ctrl;
  79. case 0x10C:
  80. return s->data_ctrl;
  81. case 0xC00:
  82. return s->filter_start;
  83. case 0xC04:
  84. return s->filter_end;
  85. case 0xF40:
  86. return 0;
  87. case 0xF60:
  88. return 0;
  89. case 0xF80:
  90. return 0;
  91. default:
  92. qemu_log_mask(LOG_GUEST_ERROR,
  93. "l2x0_priv_read: Bad offset %x\n", (int)offset);
  94. break;
  95. }
  96. return 0;
  97. }
  98. static void l2x0_priv_write(void *opaque, hwaddr offset,
  99. uint64_t value, unsigned size)
  100. {
  101. L2x0State *s = (L2x0State *)opaque;
  102. offset &= 0xfff;
  103. if (offset >= 0x730 && offset < 0x800) {
  104. /* ignore */
  105. return;
  106. }
  107. switch (offset) {
  108. case 0x100:
  109. s->ctrl = value & 1;
  110. break;
  111. case 0x104:
  112. s->aux_ctrl = value;
  113. break;
  114. case 0x108:
  115. s->tag_ctrl = value;
  116. break;
  117. case 0x10C:
  118. s->data_ctrl = value;
  119. break;
  120. case 0xC00:
  121. s->filter_start = value;
  122. break;
  123. case 0xC04:
  124. s->filter_end = value;
  125. break;
  126. case 0xF40:
  127. return;
  128. case 0xF60:
  129. return;
  130. case 0xF80:
  131. return;
  132. default:
  133. qemu_log_mask(LOG_GUEST_ERROR,
  134. "l2x0_priv_write: Bad offset %x\n", (int)offset);
  135. break;
  136. }
  137. }
  138. static void l2x0_priv_reset(DeviceState *dev)
  139. {
  140. L2x0State *s = ARM_L2X0(dev);
  141. s->ctrl = 0;
  142. s->aux_ctrl = 0x02020000;
  143. s->tag_ctrl = 0;
  144. s->data_ctrl = 0;
  145. s->filter_start = 0;
  146. s->filter_end = 0;
  147. }
  148. static const MemoryRegionOps l2x0_mem_ops = {
  149. .read = l2x0_priv_read,
  150. .write = l2x0_priv_write,
  151. .endianness = DEVICE_NATIVE_ENDIAN,
  152. };
  153. static void l2x0_priv_init(Object *obj)
  154. {
  155. L2x0State *s = ARM_L2X0(obj);
  156. SysBusDevice *dev = SYS_BUS_DEVICE(obj);
  157. memory_region_init_io(&s->iomem, obj, &l2x0_mem_ops, s,
  158. "l2x0_cc", 0x1000);
  159. sysbus_init_mmio(dev, &s->iomem);
  160. }
  161. static Property l2x0_properties[] = {
  162. DEFINE_PROP_UINT32("cache-type", L2x0State, cache_type, 0x1c100100),
  163. DEFINE_PROP_END_OF_LIST(),
  164. };
  165. static void l2x0_class_init(ObjectClass *klass, void *data)
  166. {
  167. DeviceClass *dc = DEVICE_CLASS(klass);
  168. dc->vmsd = &vmstate_l2x0;
  169. device_class_set_props(dc, l2x0_properties);
  170. dc->reset = l2x0_priv_reset;
  171. }
  172. static const TypeInfo l2x0_info = {
  173. .name = TYPE_ARM_L2X0,
  174. .parent = TYPE_SYS_BUS_DEVICE,
  175. .instance_size = sizeof(L2x0State),
  176. .instance_init = l2x0_priv_init,
  177. .class_init = l2x0_class_init,
  178. };
  179. static void l2x0_register_types(void)
  180. {
  181. type_register_static(&l2x0_info);
  182. }
  183. type_init(l2x0_register_types)