omap_l4.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. * TI OMAP L4 interconnect emulation.
  3. *
  4. * Copyright (C) 2007-2009 Nokia Corporation
  5. * Written by Andrzej Zaborowski <andrew@openedhand.com>
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 or
  10. * (at your option) any later version of the License.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along
  18. * with this program; if not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #include "qemu/osdep.h"
  21. #include "hw/arm/omap.h"
  22. struct omap_l4_s {
  23. MemoryRegion *address_space;
  24. hwaddr base;
  25. int ta_num;
  26. struct omap_target_agent_s ta[];
  27. };
  28. struct omap_l4_s *omap_l4_init(MemoryRegion *address_space,
  29. hwaddr base, int ta_num)
  30. {
  31. struct omap_l4_s *bus = g_malloc0(
  32. sizeof(*bus) + ta_num * sizeof(*bus->ta));
  33. bus->address_space = address_space;
  34. bus->ta_num = ta_num;
  35. bus->base = base;
  36. return bus;
  37. }
  38. hwaddr omap_l4_region_base(struct omap_target_agent_s *ta,
  39. int region)
  40. {
  41. return ta->bus->base + ta->start[region].offset;
  42. }
  43. hwaddr omap_l4_region_size(struct omap_target_agent_s *ta,
  44. int region)
  45. {
  46. return ta->start[region].size;
  47. }
  48. static uint64_t omap_l4ta_read(void *opaque, hwaddr addr, unsigned size)
  49. {
  50. struct omap_target_agent_s *s = opaque;
  51. if (size != 2) {
  52. return omap_badwidth_read16(opaque, addr);
  53. }
  54. switch (addr) {
  55. case 0x00: /* COMPONENT */
  56. return s->component;
  57. case 0x20: /* AGENT_CONTROL */
  58. return s->control;
  59. case 0x28: /* AGENT_STATUS */
  60. return s->status;
  61. }
  62. OMAP_BAD_REG(addr);
  63. return 0;
  64. }
  65. static void omap_l4ta_write(void *opaque, hwaddr addr,
  66. uint64_t value, unsigned size)
  67. {
  68. struct omap_target_agent_s *s = opaque;
  69. if (size != 4) {
  70. omap_badwidth_write32(opaque, addr, value);
  71. return;
  72. }
  73. switch (addr) {
  74. case 0x00: /* COMPONENT */
  75. case 0x28: /* AGENT_STATUS */
  76. OMAP_RO_REG(addr);
  77. break;
  78. case 0x20: /* AGENT_CONTROL */
  79. s->control = value & 0x01000700;
  80. if (value & 1) /* OCP_RESET */
  81. s->status &= ~1; /* REQ_TIMEOUT */
  82. break;
  83. default:
  84. OMAP_BAD_REG(addr);
  85. }
  86. }
  87. static const MemoryRegionOps omap_l4ta_ops = {
  88. .read = omap_l4ta_read,
  89. .write = omap_l4ta_write,
  90. .endianness = DEVICE_NATIVE_ENDIAN,
  91. };
  92. struct omap_target_agent_s *omap_l4ta_get(struct omap_l4_s *bus,
  93. const struct omap_l4_region_s *regions,
  94. const struct omap_l4_agent_info_s *agents,
  95. int cs)
  96. {
  97. int i;
  98. struct omap_target_agent_s *ta = NULL;
  99. const struct omap_l4_agent_info_s *info = NULL;
  100. for (i = 0; i < bus->ta_num; i ++)
  101. if (agents[i].ta == cs) {
  102. ta = &bus->ta[i];
  103. info = &agents[i];
  104. break;
  105. }
  106. if (!ta) {
  107. fprintf(stderr, "%s: bad target agent (%i)\n", __func__, cs);
  108. exit(-1);
  109. }
  110. ta->bus = bus;
  111. ta->start = &regions[info->region];
  112. ta->regions = info->regions;
  113. ta->component = ('Q' << 24) | ('E' << 16) | ('M' << 8) | ('U' << 0);
  114. ta->status = 0x00000000;
  115. ta->control = 0x00000200; /* XXX 01000200 for L4TAO */
  116. memory_region_init_io(&ta->iomem, NULL, &omap_l4ta_ops, ta, "omap.l4ta",
  117. omap_l4_region_size(ta, info->ta_region));
  118. omap_l4_attach(ta, info->ta_region, &ta->iomem);
  119. return ta;
  120. }
  121. hwaddr omap_l4_attach(struct omap_target_agent_s *ta,
  122. int region, MemoryRegion *mr)
  123. {
  124. hwaddr base;
  125. if (region < 0 || region >= ta->regions) {
  126. fprintf(stderr, "%s: bad io region (%i)\n", __func__, region);
  127. exit(-1);
  128. }
  129. base = ta->bus->base + ta->start[region].offset;
  130. if (mr) {
  131. memory_region_add_subregion(ta->bus->address_space, base, mr);
  132. }
  133. return base;
  134. }