sbi.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * QEMU Sparc SBI interrupt controller emulation
  3. *
  4. * Based on slavio_intctl, copyright (c) 2003-2005 Fabrice Bellard
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. * THE SOFTWARE.
  23. */
  24. #include "sysbus.h"
  25. //#define DEBUG_IRQ
  26. #ifdef DEBUG_IRQ
  27. #define DPRINTF(fmt, ...) \
  28. do { printf("IRQ: " fmt , ## __VA_ARGS__); } while (0)
  29. #else
  30. #define DPRINTF(fmt, ...)
  31. #endif
  32. #define MAX_CPUS 16
  33. #define SBI_NREGS 16
  34. typedef struct SBIState {
  35. SysBusDevice busdev;
  36. MemoryRegion iomem;
  37. uint32_t regs[SBI_NREGS];
  38. uint32_t intreg_pending[MAX_CPUS];
  39. qemu_irq cpu_irqs[MAX_CPUS];
  40. uint32_t pil_out[MAX_CPUS];
  41. } SBIState;
  42. #define SBI_SIZE (SBI_NREGS * 4)
  43. static void sbi_set_irq(void *opaque, int irq, int level)
  44. {
  45. }
  46. static uint64_t sbi_mem_read(void *opaque, hwaddr addr,
  47. unsigned size)
  48. {
  49. SBIState *s = opaque;
  50. uint32_t saddr, ret;
  51. saddr = addr >> 2;
  52. switch (saddr) {
  53. default:
  54. ret = s->regs[saddr];
  55. break;
  56. }
  57. DPRINTF("read system reg 0x" TARGET_FMT_plx " = %x\n", addr, ret);
  58. return ret;
  59. }
  60. static void sbi_mem_write(void *opaque, hwaddr addr,
  61. uint64_t val, unsigned dize)
  62. {
  63. SBIState *s = opaque;
  64. uint32_t saddr;
  65. saddr = addr >> 2;
  66. DPRINTF("write system reg 0x" TARGET_FMT_plx " = %x\n", addr, (int)val);
  67. switch (saddr) {
  68. default:
  69. s->regs[saddr] = val;
  70. break;
  71. }
  72. }
  73. static const MemoryRegionOps sbi_mem_ops = {
  74. .read = sbi_mem_read,
  75. .write = sbi_mem_write,
  76. .endianness = DEVICE_NATIVE_ENDIAN,
  77. .valid = {
  78. .min_access_size = 4,
  79. .max_access_size = 4,
  80. },
  81. };
  82. static const VMStateDescription vmstate_sbi = {
  83. .name ="sbi",
  84. .version_id = 1,
  85. .minimum_version_id = 1,
  86. .minimum_version_id_old = 1,
  87. .fields = (VMStateField []) {
  88. VMSTATE_UINT32_ARRAY(intreg_pending, SBIState, MAX_CPUS),
  89. VMSTATE_END_OF_LIST()
  90. }
  91. };
  92. static void sbi_reset(DeviceState *d)
  93. {
  94. SBIState *s = container_of(d, SBIState, busdev.qdev);
  95. unsigned int i;
  96. for (i = 0; i < MAX_CPUS; i++) {
  97. s->intreg_pending[i] = 0;
  98. }
  99. }
  100. static int sbi_init1(SysBusDevice *dev)
  101. {
  102. SBIState *s = FROM_SYSBUS(SBIState, dev);
  103. unsigned int i;
  104. qdev_init_gpio_in(&dev->qdev, sbi_set_irq, 32 + MAX_CPUS);
  105. for (i = 0; i < MAX_CPUS; i++) {
  106. sysbus_init_irq(dev, &s->cpu_irqs[i]);
  107. }
  108. memory_region_init_io(&s->iomem, &sbi_mem_ops, s, "sbi", SBI_SIZE);
  109. sysbus_init_mmio(dev, &s->iomem);
  110. return 0;
  111. }
  112. static void sbi_class_init(ObjectClass *klass, void *data)
  113. {
  114. DeviceClass *dc = DEVICE_CLASS(klass);
  115. SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
  116. k->init = sbi_init1;
  117. dc->reset = sbi_reset;
  118. dc->vmsd = &vmstate_sbi;
  119. }
  120. static const TypeInfo sbi_info = {
  121. .name = "sbi",
  122. .parent = TYPE_SYS_BUS_DEVICE,
  123. .instance_size = sizeof(SBIState),
  124. .class_init = sbi_class_init,
  125. };
  126. static void sbi_register_types(void)
  127. {
  128. type_register_static(&sbi_info);
  129. }
  130. type_init(sbi_register_types)