sbi.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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 "hw.h"
  25. #include "sun4m.h"
  26. #include "console.h"
  27. //#define DEBUG_IRQ
  28. #ifdef DEBUG_IRQ
  29. #define DPRINTF(fmt, args...) \
  30. do { printf("IRQ: " fmt , ##args); } while (0)
  31. #else
  32. #define DPRINTF(fmt, args...)
  33. #endif
  34. #define MAX_CPUS 16
  35. #define SBI_NREGS 16
  36. typedef struct SBIState {
  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_check_interrupts(void *opaque)
  44. {
  45. }
  46. static void sbi_set_irq(void *opaque, int irq, int level)
  47. {
  48. }
  49. static void sbi_set_timer_irq_cpu(void *opaque, int cpu, int level)
  50. {
  51. }
  52. static uint32_t sbi_mem_readl(void *opaque, target_phys_addr_t addr)
  53. {
  54. SBIState *s = opaque;
  55. uint32_t saddr, ret;
  56. saddr = addr >> 2;
  57. switch (saddr) {
  58. default:
  59. ret = s->regs[saddr];
  60. break;
  61. }
  62. DPRINTF("read system reg 0x" TARGET_FMT_plx " = %x\n", addr, ret);
  63. return ret;
  64. }
  65. static void sbi_mem_writel(void *opaque, target_phys_addr_t addr, uint32_t val)
  66. {
  67. SBIState *s = opaque;
  68. uint32_t saddr;
  69. saddr = addr >> 2;
  70. DPRINTF("write system reg 0x" TARGET_FMT_plx " = %x\n", addr, val);
  71. switch (saddr) {
  72. default:
  73. s->regs[saddr] = val;
  74. break;
  75. }
  76. }
  77. static CPUReadMemoryFunc *sbi_mem_read[3] = {
  78. NULL,
  79. NULL,
  80. sbi_mem_readl,
  81. };
  82. static CPUWriteMemoryFunc *sbi_mem_write[3] = {
  83. NULL,
  84. NULL,
  85. sbi_mem_writel,
  86. };
  87. static void sbi_save(QEMUFile *f, void *opaque)
  88. {
  89. SBIState *s = opaque;
  90. unsigned int i;
  91. for (i = 0; i < MAX_CPUS; i++) {
  92. qemu_put_be32s(f, &s->intreg_pending[i]);
  93. }
  94. }
  95. static int sbi_load(QEMUFile *f, void *opaque, int version_id)
  96. {
  97. SBIState *s = opaque;
  98. unsigned int i;
  99. if (version_id != 1)
  100. return -EINVAL;
  101. for (i = 0; i < MAX_CPUS; i++) {
  102. qemu_get_be32s(f, &s->intreg_pending[i]);
  103. }
  104. sbi_check_interrupts(s);
  105. return 0;
  106. }
  107. static void sbi_reset(void *opaque)
  108. {
  109. SBIState *s = opaque;
  110. unsigned int i;
  111. for (i = 0; i < MAX_CPUS; i++) {
  112. s->intreg_pending[i] = 0;
  113. }
  114. sbi_check_interrupts(s);
  115. }
  116. void *sbi_init(target_phys_addr_t addr, qemu_irq **irq, qemu_irq **cpu_irq,
  117. qemu_irq **parent_irq)
  118. {
  119. unsigned int i;
  120. int sbi_io_memory;
  121. SBIState *s;
  122. s = qemu_mallocz(sizeof(SBIState));
  123. for (i = 0; i < MAX_CPUS; i++) {
  124. s->cpu_irqs[i] = parent_irq[i];
  125. }
  126. sbi_io_memory = cpu_register_io_memory(0, sbi_mem_read, sbi_mem_write, s);
  127. cpu_register_physical_memory(addr, SBI_SIZE, sbi_io_memory);
  128. register_savevm("sbi", addr, 1, sbi_save, sbi_load, s);
  129. qemu_register_reset(sbi_reset, s);
  130. *irq = qemu_allocate_irqs(sbi_set_irq, s, 32);
  131. *cpu_irq = qemu_allocate_irqs(sbi_set_timer_irq_cpu, s, MAX_CPUS);
  132. sbi_reset(s);
  133. return s;
  134. }