blueswir1 | 7d85892 | 2007-12-28 20:57:43 +0000 | [diff] [blame] | 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 | */ |
Blue Swirl | 7fc0673 | 2009-07-21 19:25:59 +0000 | [diff] [blame] | 24 | |
Blue Swirl | 7fc0673 | 2009-07-21 19:25:59 +0000 | [diff] [blame] | 25 | #include "sysbus.h" |
blueswir1 | 7d85892 | 2007-12-28 20:57:43 +0000 | [diff] [blame] | 26 | |
| 27 | //#define DEBUG_IRQ |
| 28 | |
| 29 | #ifdef DEBUG_IRQ |
Blue Swirl | 001faf3 | 2009-05-13 17:53:17 +0000 | [diff] [blame] | 30 | #define DPRINTF(fmt, ...) \ |
| 31 | do { printf("IRQ: " fmt , ## __VA_ARGS__); } while (0) |
blueswir1 | 7d85892 | 2007-12-28 20:57:43 +0000 | [diff] [blame] | 32 | #else |
Blue Swirl | 001faf3 | 2009-05-13 17:53:17 +0000 | [diff] [blame] | 33 | #define DPRINTF(fmt, ...) |
blueswir1 | 7d85892 | 2007-12-28 20:57:43 +0000 | [diff] [blame] | 34 | #endif |
| 35 | |
| 36 | #define MAX_CPUS 16 |
| 37 | |
| 38 | #define SBI_NREGS 16 |
| 39 | |
| 40 | typedef struct SBIState { |
Blue Swirl | 7fc0673 | 2009-07-21 19:25:59 +0000 | [diff] [blame] | 41 | SysBusDevice busdev; |
Avi Kivity | cfee758 | 2011-10-16 16:11:06 +0200 | [diff] [blame] | 42 | MemoryRegion iomem; |
blueswir1 | 7d85892 | 2007-12-28 20:57:43 +0000 | [diff] [blame] | 43 | uint32_t regs[SBI_NREGS]; |
| 44 | uint32_t intreg_pending[MAX_CPUS]; |
Blue Swirl | 7fc0673 | 2009-07-21 19:25:59 +0000 | [diff] [blame] | 45 | qemu_irq cpu_irqs[MAX_CPUS]; |
blueswir1 | 7d85892 | 2007-12-28 20:57:43 +0000 | [diff] [blame] | 46 | uint32_t pil_out[MAX_CPUS]; |
| 47 | } SBIState; |
| 48 | |
| 49 | #define SBI_SIZE (SBI_NREGS * 4) |
blueswir1 | 7d85892 | 2007-12-28 20:57:43 +0000 | [diff] [blame] | 50 | |
blueswir1 | 7d85892 | 2007-12-28 20:57:43 +0000 | [diff] [blame] | 51 | static void sbi_set_irq(void *opaque, int irq, int level) |
| 52 | { |
| 53 | } |
| 54 | |
Avi Kivity | cfee758 | 2011-10-16 16:11:06 +0200 | [diff] [blame] | 55 | static uint64_t sbi_mem_read(void *opaque, target_phys_addr_t addr, |
| 56 | unsigned size) |
blueswir1 | 7d85892 | 2007-12-28 20:57:43 +0000 | [diff] [blame] | 57 | { |
| 58 | SBIState *s = opaque; |
| 59 | uint32_t saddr, ret; |
| 60 | |
blueswir1 | e64d7d5 | 2008-12-02 17:47:02 +0000 | [diff] [blame] | 61 | saddr = addr >> 2; |
blueswir1 | 7d85892 | 2007-12-28 20:57:43 +0000 | [diff] [blame] | 62 | switch (saddr) { |
| 63 | default: |
| 64 | ret = s->regs[saddr]; |
| 65 | break; |
| 66 | } |
| 67 | DPRINTF("read system reg 0x" TARGET_FMT_plx " = %x\n", addr, ret); |
| 68 | |
| 69 | return ret; |
| 70 | } |
| 71 | |
Avi Kivity | cfee758 | 2011-10-16 16:11:06 +0200 | [diff] [blame] | 72 | static void sbi_mem_write(void *opaque, target_phys_addr_t addr, |
| 73 | uint64_t val, unsigned dize) |
blueswir1 | 7d85892 | 2007-12-28 20:57:43 +0000 | [diff] [blame] | 74 | { |
| 75 | SBIState *s = opaque; |
| 76 | uint32_t saddr; |
| 77 | |
blueswir1 | e64d7d5 | 2008-12-02 17:47:02 +0000 | [diff] [blame] | 78 | saddr = addr >> 2; |
Avi Kivity | cfee758 | 2011-10-16 16:11:06 +0200 | [diff] [blame] | 79 | DPRINTF("write system reg 0x" TARGET_FMT_plx " = %x\n", addr, (int)val); |
blueswir1 | 7d85892 | 2007-12-28 20:57:43 +0000 | [diff] [blame] | 80 | switch (saddr) { |
| 81 | default: |
| 82 | s->regs[saddr] = val; |
| 83 | break; |
| 84 | } |
| 85 | } |
| 86 | |
Avi Kivity | cfee758 | 2011-10-16 16:11:06 +0200 | [diff] [blame] | 87 | static const MemoryRegionOps sbi_mem_ops = { |
| 88 | .read = sbi_mem_read, |
| 89 | .write = sbi_mem_write, |
| 90 | .endianness = DEVICE_NATIVE_ENDIAN, |
| 91 | .valid = { |
| 92 | .min_access_size = 4, |
| 93 | .max_access_size = 4, |
| 94 | }, |
blueswir1 | 7d85892 | 2007-12-28 20:57:43 +0000 | [diff] [blame] | 95 | }; |
| 96 | |
Blue Swirl | b280fcd | 2009-10-24 20:08:43 +0000 | [diff] [blame] | 97 | static const VMStateDescription vmstate_sbi = { |
| 98 | .name ="sbi", |
| 99 | .version_id = 1, |
| 100 | .minimum_version_id = 1, |
| 101 | .minimum_version_id_old = 1, |
| 102 | .fields = (VMStateField []) { |
| 103 | VMSTATE_UINT32_ARRAY(intreg_pending, SBIState, MAX_CPUS), |
| 104 | VMSTATE_END_OF_LIST() |
blueswir1 | 7d85892 | 2007-12-28 20:57:43 +0000 | [diff] [blame] | 105 | } |
Blue Swirl | b280fcd | 2009-10-24 20:08:43 +0000 | [diff] [blame] | 106 | }; |
blueswir1 | 7d85892 | 2007-12-28 20:57:43 +0000 | [diff] [blame] | 107 | |
Blue Swirl | b280fcd | 2009-10-24 20:08:43 +0000 | [diff] [blame] | 108 | static void sbi_reset(DeviceState *d) |
blueswir1 | 7d85892 | 2007-12-28 20:57:43 +0000 | [diff] [blame] | 109 | { |
Blue Swirl | b280fcd | 2009-10-24 20:08:43 +0000 | [diff] [blame] | 110 | SBIState *s = container_of(d, SBIState, busdev.qdev); |
blueswir1 | 7d85892 | 2007-12-28 20:57:43 +0000 | [diff] [blame] | 111 | unsigned int i; |
| 112 | |
| 113 | for (i = 0; i < MAX_CPUS; i++) { |
| 114 | s->intreg_pending[i] = 0; |
| 115 | } |
blueswir1 | 7d85892 | 2007-12-28 20:57:43 +0000 | [diff] [blame] | 116 | } |
| 117 | |
Gerd Hoffmann | 81a322d | 2009-08-14 10:36:05 +0200 | [diff] [blame] | 118 | static int sbi_init1(SysBusDevice *dev) |
Blue Swirl | 7fc0673 | 2009-07-21 19:25:59 +0000 | [diff] [blame] | 119 | { |
| 120 | SBIState *s = FROM_SYSBUS(SBIState, dev); |
Blue Swirl | 7fc0673 | 2009-07-21 19:25:59 +0000 | [diff] [blame] | 121 | unsigned int i; |
| 122 | |
| 123 | qdev_init_gpio_in(&dev->qdev, sbi_set_irq, 32 + MAX_CPUS); |
| 124 | for (i = 0; i < MAX_CPUS; i++) { |
| 125 | sysbus_init_irq(dev, &s->cpu_irqs[i]); |
blueswir1 | 7d85892 | 2007-12-28 20:57:43 +0000 | [diff] [blame] | 126 | } |
| 127 | |
Avi Kivity | cfee758 | 2011-10-16 16:11:06 +0200 | [diff] [blame] | 128 | memory_region_init_io(&s->iomem, &sbi_mem_ops, s, "sbi", SBI_SIZE); |
Avi Kivity | 750ecd4 | 2011-11-27 11:38:10 +0200 | [diff] [blame] | 129 | sysbus_init_mmio(dev, &s->iomem); |
blueswir1 | 7d85892 | 2007-12-28 20:57:43 +0000 | [diff] [blame] | 130 | |
Gerd Hoffmann | 81a322d | 2009-08-14 10:36:05 +0200 | [diff] [blame] | 131 | return 0; |
blueswir1 | 7d85892 | 2007-12-28 20:57:43 +0000 | [diff] [blame] | 132 | } |
Blue Swirl | 7fc0673 | 2009-07-21 19:25:59 +0000 | [diff] [blame] | 133 | |
Anthony Liguori | 999e12b | 2012-01-24 13:12:29 -0600 | [diff] [blame] | 134 | static void sbi_class_init(ObjectClass *klass, void *data) |
| 135 | { |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 136 | DeviceClass *dc = DEVICE_CLASS(klass); |
Anthony Liguori | 999e12b | 2012-01-24 13:12:29 -0600 | [diff] [blame] | 137 | SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); |
| 138 | |
| 139 | k->init = sbi_init1; |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 140 | dc->reset = sbi_reset; |
| 141 | dc->vmsd = &vmstate_sbi; |
Anthony Liguori | 999e12b | 2012-01-24 13:12:29 -0600 | [diff] [blame] | 142 | } |
| 143 | |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 144 | static TypeInfo sbi_info = { |
| 145 | .name = "sbi", |
| 146 | .parent = TYPE_SYS_BUS_DEVICE, |
| 147 | .instance_size = sizeof(SBIState), |
| 148 | .class_init = sbi_class_init, |
Blue Swirl | 7fc0673 | 2009-07-21 19:25:59 +0000 | [diff] [blame] | 149 | }; |
| 150 | |
Andreas Färber | 83f7d43 | 2012-02-09 15:20:55 +0100 | [diff] [blame] | 151 | static void sbi_register_types(void) |
Blue Swirl | 7fc0673 | 2009-07-21 19:25:59 +0000 | [diff] [blame] | 152 | { |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 153 | type_register_static(&sbi_info); |
Blue Swirl | 7fc0673 | 2009-07-21 19:25:59 +0000 | [diff] [blame] | 154 | } |
| 155 | |
Andreas Färber | 83f7d43 | 2012-02-09 15:20:55 +0100 | [diff] [blame] | 156 | type_init(sbi_register_types) |