omap_l4.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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,
  49. unsigned size)
  50. {
  51. struct omap_target_agent_s *s = (struct omap_target_agent_s *) opaque;
  52. if (size != 2) {
  53. return omap_badwidth_read16(opaque, addr);
  54. }
  55. switch (addr) {
  56. case 0x00: /* COMPONENT */
  57. return s->component;
  58. case 0x20: /* AGENT_CONTROL */
  59. return s->control;
  60. case 0x28: /* AGENT_STATUS */
  61. return s->status;
  62. }
  63. OMAP_BAD_REG(addr);
  64. return 0;
  65. }
  66. static void omap_l4ta_write(void *opaque, hwaddr addr,
  67. uint64_t value, unsigned size)
  68. {
  69. struct omap_target_agent_s *s = (struct omap_target_agent_s *) opaque;
  70. if (size != 4) {
  71. omap_badwidth_write32(opaque, addr, value);
  72. return;
  73. }
  74. switch (addr) {
  75. case 0x00: /* COMPONENT */
  76. case 0x28: /* AGENT_STATUS */
  77. OMAP_RO_REG(addr);
  78. break;
  79. case 0x20: /* AGENT_CONTROL */
  80. s->control = value & 0x01000700;
  81. if (value & 1) /* OCP_RESET */
  82. s->status &= ~1; /* REQ_TIMEOUT */
  83. break;
  84. default:
  85. OMAP_BAD_REG(addr);
  86. }
  87. }
  88. static const MemoryRegionOps omap_l4ta_ops = {
  89. .read = omap_l4ta_read,
  90. .write = omap_l4ta_write,
  91. .endianness = DEVICE_NATIVE_ENDIAN,
  92. };
  93. struct omap_target_agent_s *omap_l4ta_get(struct omap_l4_s *bus,
  94. const struct omap_l4_region_s *regions,
  95. const struct omap_l4_agent_info_s *agents,
  96. int cs)
  97. {
  98. int i;
  99. struct omap_target_agent_s *ta = NULL;
  100. const struct omap_l4_agent_info_s *info = NULL;
  101. for (i = 0; i < bus->ta_num; i ++)
  102. if (agents[i].ta == cs) {
  103. ta = &bus->ta[i];
  104. info = &agents[i];
  105. break;
  106. }
  107. if (!ta) {
  108. fprintf(stderr, "%s: bad target agent (%i)\n", __func__, cs);
  109. exit(-1);
  110. }
  111. ta->bus = bus;
  112. ta->start = &regions[info->region];
  113. ta->regions = info->regions;
  114. ta->component = ('Q' << 24) | ('E' << 16) | ('M' << 8) | ('U' << 0);
  115. ta->status = 0x00000000;
  116. ta->control = 0x00000200; /* XXX 01000200 for L4TAO */
  117. memory_region_init_io(&ta->iomem, NULL, &omap_l4ta_ops, ta, "omap.l4ta",
  118. omap_l4_region_size(ta, info->ta_region));
  119. omap_l4_attach(ta, info->ta_region, &ta->iomem);
  120. return ta;
  121. }
  122. hwaddr omap_l4_attach(struct omap_target_agent_s *ta,
  123. int region, MemoryRegion *mr)
  124. {
  125. hwaddr base;
  126. if (region < 0 || region >= ta->regions) {
  127. fprintf(stderr, "%s: bad io region (%i)\n", __func__, region);
  128. exit(-1);
  129. }
  130. base = ta->bus->base + ta->start[region].offset;
  131. if (mr) {
  132. memory_region_add_subregion(ta->bus->address_space, base, mr);
  133. }
  134. return base;
  135. }