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