root / hw / ppc4xx_devs.c @ f9d43072
History | View | Annotate | Download (14.3 kB)
1 | 008ff9d7 | j_mayer | /*
|
---|---|---|---|
2 | 008ff9d7 | j_mayer | * QEMU PowerPC 4xx embedded processors shared devices emulation
|
3 | 008ff9d7 | j_mayer | *
|
4 | 008ff9d7 | j_mayer | * Copyright (c) 2007 Jocelyn Mayer
|
5 | 008ff9d7 | j_mayer | *
|
6 | 008ff9d7 | j_mayer | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 | 008ff9d7 | j_mayer | * of this software and associated documentation files (the "Software"), to deal
|
8 | 008ff9d7 | j_mayer | * in the Software without restriction, including without limitation the rights
|
9 | 008ff9d7 | j_mayer | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 | 008ff9d7 | j_mayer | * copies of the Software, and to permit persons to whom the Software is
|
11 | 008ff9d7 | j_mayer | * furnished to do so, subject to the following conditions:
|
12 | 008ff9d7 | j_mayer | *
|
13 | 008ff9d7 | j_mayer | * The above copyright notice and this permission notice shall be included in
|
14 | 008ff9d7 | j_mayer | * all copies or substantial portions of the Software.
|
15 | 008ff9d7 | j_mayer | *
|
16 | 008ff9d7 | j_mayer | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 | 008ff9d7 | j_mayer | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 | 008ff9d7 | j_mayer | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19 | 008ff9d7 | j_mayer | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 | 008ff9d7 | j_mayer | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 | 008ff9d7 | j_mayer | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 | 008ff9d7 | j_mayer | * THE SOFTWARE.
|
23 | 008ff9d7 | j_mayer | */
|
24 | 87ecb68b | pbrook | #include "hw.h" |
25 | 87ecb68b | pbrook | #include "ppc.h" |
26 | 008ff9d7 | j_mayer | #include "ppc4xx.h" |
27 | 87ecb68b | pbrook | #include "sysemu.h" |
28 | 008ff9d7 | j_mayer | |
29 | 008ff9d7 | j_mayer | extern int loglevel; |
30 | 008ff9d7 | j_mayer | extern FILE *logfile;
|
31 | 008ff9d7 | j_mayer | |
32 | 008ff9d7 | j_mayer | //#define DEBUG_MMIO
|
33 | 008ff9d7 | j_mayer | #define DEBUG_UIC
|
34 | 008ff9d7 | j_mayer | |
35 | 008ff9d7 | j_mayer | /*****************************************************************************/
|
36 | 008ff9d7 | j_mayer | /* Generic PowerPC 4xx processor instanciation */
|
37 | 008ff9d7 | j_mayer | CPUState *ppc4xx_init (const unsigned char *cpu_model, |
38 | 008ff9d7 | j_mayer | clk_setup_t *cpu_clk, clk_setup_t *tb_clk, |
39 | 008ff9d7 | j_mayer | uint32_t sysclk) |
40 | 008ff9d7 | j_mayer | { |
41 | 008ff9d7 | j_mayer | CPUState *env; |
42 | 008ff9d7 | j_mayer | |
43 | 008ff9d7 | j_mayer | /* init CPUs */
|
44 | aaed909a | bellard | env = cpu_init(cpu_model); |
45 | aaed909a | bellard | if (!env) {
|
46 | aaed909a | bellard | fprintf(stderr, "Unable to find PowerPC %s CPU definition\n",
|
47 | aaed909a | bellard | cpu_model); |
48 | aaed909a | bellard | exit(1);
|
49 | 008ff9d7 | j_mayer | } |
50 | 008ff9d7 | j_mayer | cpu_clk->cb = NULL; /* We don't care about CPU clock frequency changes */ |
51 | 008ff9d7 | j_mayer | cpu_clk->opaque = env; |
52 | 008ff9d7 | j_mayer | /* Set time-base frequency to sysclk */
|
53 | 008ff9d7 | j_mayer | tb_clk->cb = ppc_emb_timers_init(env, sysclk); |
54 | 008ff9d7 | j_mayer | tb_clk->opaque = env; |
55 | 008ff9d7 | j_mayer | ppc_dcr_init(env, NULL, NULL); |
56 | 008ff9d7 | j_mayer | /* Register qemu callbacks */
|
57 | 008ff9d7 | j_mayer | qemu_register_reset(&cpu_ppc_reset, env); |
58 | 008ff9d7 | j_mayer | register_savevm("cpu", 0, 3, cpu_save, cpu_load, env); |
59 | 008ff9d7 | j_mayer | |
60 | 008ff9d7 | j_mayer | return env;
|
61 | 008ff9d7 | j_mayer | } |
62 | 008ff9d7 | j_mayer | |
63 | 008ff9d7 | j_mayer | /*****************************************************************************/
|
64 | 008ff9d7 | j_mayer | /* Fake device used to map multiple devices in a single memory page */
|
65 | 008ff9d7 | j_mayer | #define MMIO_AREA_BITS 8 |
66 | 008ff9d7 | j_mayer | #define MMIO_AREA_LEN (1 << MMIO_AREA_BITS) |
67 | 008ff9d7 | j_mayer | #define MMIO_AREA_NB (1 << (TARGET_PAGE_BITS - MMIO_AREA_BITS)) |
68 | 008ff9d7 | j_mayer | #define MMIO_IDX(addr) (((addr) >> MMIO_AREA_BITS) & (MMIO_AREA_NB - 1)) |
69 | 008ff9d7 | j_mayer | struct ppc4xx_mmio_t {
|
70 | 008ff9d7 | j_mayer | target_phys_addr_t base; |
71 | 008ff9d7 | j_mayer | CPUReadMemoryFunc **mem_read[MMIO_AREA_NB]; |
72 | 008ff9d7 | j_mayer | CPUWriteMemoryFunc **mem_write[MMIO_AREA_NB]; |
73 | 008ff9d7 | j_mayer | void *opaque[MMIO_AREA_NB];
|
74 | 008ff9d7 | j_mayer | }; |
75 | 008ff9d7 | j_mayer | |
76 | 008ff9d7 | j_mayer | static uint32_t unassigned_mmio_readb (void *opaque, target_phys_addr_t addr) |
77 | 008ff9d7 | j_mayer | { |
78 | 008ff9d7 | j_mayer | #ifdef DEBUG_UNASSIGNED
|
79 | 008ff9d7 | j_mayer | ppc4xx_mmio_t *mmio; |
80 | 008ff9d7 | j_mayer | |
81 | 008ff9d7 | j_mayer | mmio = opaque; |
82 | 008ff9d7 | j_mayer | printf("Unassigned mmio read 0x" PADDRX " base " PADDRX "\n", |
83 | 008ff9d7 | j_mayer | addr, mmio->base); |
84 | 008ff9d7 | j_mayer | #endif
|
85 | 008ff9d7 | j_mayer | |
86 | 008ff9d7 | j_mayer | return 0; |
87 | 008ff9d7 | j_mayer | } |
88 | 008ff9d7 | j_mayer | |
89 | 008ff9d7 | j_mayer | static void unassigned_mmio_writeb (void *opaque, |
90 | 008ff9d7 | j_mayer | target_phys_addr_t addr, uint32_t val) |
91 | 008ff9d7 | j_mayer | { |
92 | 008ff9d7 | j_mayer | #ifdef DEBUG_UNASSIGNED
|
93 | 008ff9d7 | j_mayer | ppc4xx_mmio_t *mmio; |
94 | 008ff9d7 | j_mayer | |
95 | 008ff9d7 | j_mayer | mmio = opaque; |
96 | 008ff9d7 | j_mayer | printf("Unassigned mmio write 0x" PADDRX " = 0x%x base " PADDRX "\n", |
97 | 008ff9d7 | j_mayer | addr, val, mmio->base); |
98 | 008ff9d7 | j_mayer | #endif
|
99 | 008ff9d7 | j_mayer | } |
100 | 008ff9d7 | j_mayer | |
101 | 008ff9d7 | j_mayer | static CPUReadMemoryFunc *unassigned_mmio_read[3] = { |
102 | 008ff9d7 | j_mayer | unassigned_mmio_readb, |
103 | 008ff9d7 | j_mayer | unassigned_mmio_readb, |
104 | 008ff9d7 | j_mayer | unassigned_mmio_readb, |
105 | 008ff9d7 | j_mayer | }; |
106 | 008ff9d7 | j_mayer | |
107 | 008ff9d7 | j_mayer | static CPUWriteMemoryFunc *unassigned_mmio_write[3] = { |
108 | 008ff9d7 | j_mayer | unassigned_mmio_writeb, |
109 | 008ff9d7 | j_mayer | unassigned_mmio_writeb, |
110 | 008ff9d7 | j_mayer | unassigned_mmio_writeb, |
111 | 008ff9d7 | j_mayer | }; |
112 | 008ff9d7 | j_mayer | |
113 | 008ff9d7 | j_mayer | static uint32_t mmio_readlen (ppc4xx_mmio_t *mmio,
|
114 | 008ff9d7 | j_mayer | target_phys_addr_t addr, int len)
|
115 | 008ff9d7 | j_mayer | { |
116 | 008ff9d7 | j_mayer | CPUReadMemoryFunc **mem_read; |
117 | 008ff9d7 | j_mayer | uint32_t ret; |
118 | 008ff9d7 | j_mayer | int idx;
|
119 | 008ff9d7 | j_mayer | |
120 | 008ff9d7 | j_mayer | idx = MMIO_IDX(addr - mmio->base); |
121 | 008ff9d7 | j_mayer | #if defined(DEBUG_MMIO)
|
122 | 008ff9d7 | j_mayer | printf("%s: mmio %p len %d addr " PADDRX " idx %d\n", __func__, |
123 | 008ff9d7 | j_mayer | mmio, len, addr, idx); |
124 | 008ff9d7 | j_mayer | #endif
|
125 | 008ff9d7 | j_mayer | mem_read = mmio->mem_read[idx]; |
126 | 008ff9d7 | j_mayer | ret = (*mem_read[len])(mmio->opaque[idx], addr - mmio->base); |
127 | 008ff9d7 | j_mayer | |
128 | 008ff9d7 | j_mayer | return ret;
|
129 | 008ff9d7 | j_mayer | } |
130 | 008ff9d7 | j_mayer | |
131 | 008ff9d7 | j_mayer | static void mmio_writelen (ppc4xx_mmio_t *mmio, |
132 | 008ff9d7 | j_mayer | target_phys_addr_t addr, uint32_t value, int len)
|
133 | 008ff9d7 | j_mayer | { |
134 | 008ff9d7 | j_mayer | CPUWriteMemoryFunc **mem_write; |
135 | 008ff9d7 | j_mayer | int idx;
|
136 | 008ff9d7 | j_mayer | |
137 | 008ff9d7 | j_mayer | idx = MMIO_IDX(addr - mmio->base); |
138 | 008ff9d7 | j_mayer | #if defined(DEBUG_MMIO)
|
139 | 008ff9d7 | j_mayer | printf("%s: mmio %p len %d addr " PADDRX " idx %d value %08x\n", __func__, |
140 | 008ff9d7 | j_mayer | mmio, len, addr, idx, value); |
141 | 008ff9d7 | j_mayer | #endif
|
142 | 008ff9d7 | j_mayer | mem_write = mmio->mem_write[idx]; |
143 | 008ff9d7 | j_mayer | (*mem_write[len])(mmio->opaque[idx], addr - mmio->base, value); |
144 | 008ff9d7 | j_mayer | } |
145 | 008ff9d7 | j_mayer | |
146 | 008ff9d7 | j_mayer | static uint32_t mmio_readb (void *opaque, target_phys_addr_t addr) |
147 | 008ff9d7 | j_mayer | { |
148 | 008ff9d7 | j_mayer | #if defined(DEBUG_MMIO)
|
149 | 008ff9d7 | j_mayer | printf("%s: addr " PADDRX "\n", __func__, addr); |
150 | 008ff9d7 | j_mayer | #endif
|
151 | 008ff9d7 | j_mayer | |
152 | 008ff9d7 | j_mayer | return mmio_readlen(opaque, addr, 0); |
153 | 008ff9d7 | j_mayer | } |
154 | 008ff9d7 | j_mayer | |
155 | 008ff9d7 | j_mayer | static void mmio_writeb (void *opaque, |
156 | 008ff9d7 | j_mayer | target_phys_addr_t addr, uint32_t value) |
157 | 008ff9d7 | j_mayer | { |
158 | 008ff9d7 | j_mayer | #if defined(DEBUG_MMIO)
|
159 | 008ff9d7 | j_mayer | printf("%s: addr " PADDRX " val %08x\n", __func__, addr, value); |
160 | 008ff9d7 | j_mayer | #endif
|
161 | 008ff9d7 | j_mayer | mmio_writelen(opaque, addr, value, 0);
|
162 | 008ff9d7 | j_mayer | } |
163 | 008ff9d7 | j_mayer | |
164 | 008ff9d7 | j_mayer | static uint32_t mmio_readw (void *opaque, target_phys_addr_t addr) |
165 | 008ff9d7 | j_mayer | { |
166 | 008ff9d7 | j_mayer | #if defined(DEBUG_MMIO)
|
167 | 008ff9d7 | j_mayer | printf("%s: addr " PADDRX "\n", __func__, addr); |
168 | 008ff9d7 | j_mayer | #endif
|
169 | 008ff9d7 | j_mayer | |
170 | 008ff9d7 | j_mayer | return mmio_readlen(opaque, addr, 1); |
171 | 008ff9d7 | j_mayer | } |
172 | 008ff9d7 | j_mayer | |
173 | 008ff9d7 | j_mayer | static void mmio_writew (void *opaque, |
174 | 008ff9d7 | j_mayer | target_phys_addr_t addr, uint32_t value) |
175 | 008ff9d7 | j_mayer | { |
176 | 008ff9d7 | j_mayer | #if defined(DEBUG_MMIO)
|
177 | 008ff9d7 | j_mayer | printf("%s: addr " PADDRX " val %08x\n", __func__, addr, value); |
178 | 008ff9d7 | j_mayer | #endif
|
179 | 008ff9d7 | j_mayer | mmio_writelen(opaque, addr, value, 1);
|
180 | 008ff9d7 | j_mayer | } |
181 | 008ff9d7 | j_mayer | |
182 | 008ff9d7 | j_mayer | static uint32_t mmio_readl (void *opaque, target_phys_addr_t addr) |
183 | 008ff9d7 | j_mayer | { |
184 | 008ff9d7 | j_mayer | #if defined(DEBUG_MMIO)
|
185 | 008ff9d7 | j_mayer | printf("%s: addr " PADDRX "\n", __func__, addr); |
186 | 008ff9d7 | j_mayer | #endif
|
187 | 008ff9d7 | j_mayer | |
188 | 008ff9d7 | j_mayer | return mmio_readlen(opaque, addr, 2); |
189 | 008ff9d7 | j_mayer | } |
190 | 008ff9d7 | j_mayer | |
191 | 008ff9d7 | j_mayer | static void mmio_writel (void *opaque, |
192 | 008ff9d7 | j_mayer | target_phys_addr_t addr, uint32_t value) |
193 | 008ff9d7 | j_mayer | { |
194 | 008ff9d7 | j_mayer | #if defined(DEBUG_MMIO)
|
195 | 008ff9d7 | j_mayer | printf("%s: addr " PADDRX " val %08x\n", __func__, addr, value); |
196 | 008ff9d7 | j_mayer | #endif
|
197 | 008ff9d7 | j_mayer | mmio_writelen(opaque, addr, value, 2);
|
198 | 008ff9d7 | j_mayer | } |
199 | 008ff9d7 | j_mayer | |
200 | 008ff9d7 | j_mayer | static CPUReadMemoryFunc *mmio_read[] = {
|
201 | 008ff9d7 | j_mayer | &mmio_readb, |
202 | 008ff9d7 | j_mayer | &mmio_readw, |
203 | 008ff9d7 | j_mayer | &mmio_readl, |
204 | 008ff9d7 | j_mayer | }; |
205 | 008ff9d7 | j_mayer | |
206 | 008ff9d7 | j_mayer | static CPUWriteMemoryFunc *mmio_write[] = {
|
207 | 008ff9d7 | j_mayer | &mmio_writeb, |
208 | 008ff9d7 | j_mayer | &mmio_writew, |
209 | 008ff9d7 | j_mayer | &mmio_writel, |
210 | 008ff9d7 | j_mayer | }; |
211 | 008ff9d7 | j_mayer | |
212 | 008ff9d7 | j_mayer | int ppc4xx_mmio_register (CPUState *env, ppc4xx_mmio_t *mmio,
|
213 | 008ff9d7 | j_mayer | target_phys_addr_t offset, uint32_t len, |
214 | 008ff9d7 | j_mayer | CPUReadMemoryFunc **mem_read, |
215 | 008ff9d7 | j_mayer | CPUWriteMemoryFunc **mem_write, void *opaque)
|
216 | 008ff9d7 | j_mayer | { |
217 | 008ff9d7 | j_mayer | uint32_t end; |
218 | 008ff9d7 | j_mayer | int idx, eidx;
|
219 | 008ff9d7 | j_mayer | |
220 | 008ff9d7 | j_mayer | if ((offset + len) > TARGET_PAGE_SIZE)
|
221 | 008ff9d7 | j_mayer | return -1; |
222 | 008ff9d7 | j_mayer | idx = MMIO_IDX(offset); |
223 | 008ff9d7 | j_mayer | end = offset + len - 1;
|
224 | 008ff9d7 | j_mayer | eidx = MMIO_IDX(end); |
225 | 008ff9d7 | j_mayer | #if defined(DEBUG_MMIO)
|
226 | 008ff9d7 | j_mayer | printf("%s: offset %08x len %08x %08x %d %d\n", __func__, offset, len,
|
227 | 008ff9d7 | j_mayer | end, idx, eidx); |
228 | 008ff9d7 | j_mayer | #endif
|
229 | 008ff9d7 | j_mayer | for (; idx <= eidx; idx++) {
|
230 | 008ff9d7 | j_mayer | mmio->mem_read[idx] = mem_read; |
231 | 008ff9d7 | j_mayer | mmio->mem_write[idx] = mem_write; |
232 | 008ff9d7 | j_mayer | mmio->opaque[idx] = opaque; |
233 | 008ff9d7 | j_mayer | } |
234 | 008ff9d7 | j_mayer | |
235 | 008ff9d7 | j_mayer | return 0; |
236 | 008ff9d7 | j_mayer | } |
237 | 008ff9d7 | j_mayer | |
238 | 008ff9d7 | j_mayer | ppc4xx_mmio_t *ppc4xx_mmio_init (CPUState *env, target_phys_addr_t base) |
239 | 008ff9d7 | j_mayer | { |
240 | 008ff9d7 | j_mayer | ppc4xx_mmio_t *mmio; |
241 | 008ff9d7 | j_mayer | int mmio_memory;
|
242 | 008ff9d7 | j_mayer | |
243 | 008ff9d7 | j_mayer | mmio = qemu_mallocz(sizeof(ppc4xx_mmio_t));
|
244 | 008ff9d7 | j_mayer | if (mmio != NULL) { |
245 | 008ff9d7 | j_mayer | mmio->base = base; |
246 | 008ff9d7 | j_mayer | mmio_memory = cpu_register_io_memory(0, mmio_read, mmio_write, mmio);
|
247 | 008ff9d7 | j_mayer | #if defined(DEBUG_MMIO)
|
248 | 008ff9d7 | j_mayer | printf("%s: %p base %08x len %08x %d\n", __func__,
|
249 | 008ff9d7 | j_mayer | mmio, base, TARGET_PAGE_SIZE, mmio_memory); |
250 | 008ff9d7 | j_mayer | #endif
|
251 | 008ff9d7 | j_mayer | cpu_register_physical_memory(base, TARGET_PAGE_SIZE, mmio_memory); |
252 | 008ff9d7 | j_mayer | ppc4xx_mmio_register(env, mmio, 0, TARGET_PAGE_SIZE,
|
253 | 008ff9d7 | j_mayer | unassigned_mmio_read, unassigned_mmio_write, |
254 | 008ff9d7 | j_mayer | mmio); |
255 | 008ff9d7 | j_mayer | } |
256 | 008ff9d7 | j_mayer | |
257 | 008ff9d7 | j_mayer | return mmio;
|
258 | 008ff9d7 | j_mayer | } |
259 | 008ff9d7 | j_mayer | |
260 | 008ff9d7 | j_mayer | /*****************************************************************************/
|
261 | 008ff9d7 | j_mayer | /* "Universal" Interrupt controller */
|
262 | 008ff9d7 | j_mayer | enum {
|
263 | 008ff9d7 | j_mayer | DCR_UICSR = 0x000,
|
264 | 008ff9d7 | j_mayer | DCR_UICSRS = 0x001,
|
265 | 008ff9d7 | j_mayer | DCR_UICER = 0x002,
|
266 | 008ff9d7 | j_mayer | DCR_UICCR = 0x003,
|
267 | 008ff9d7 | j_mayer | DCR_UICPR = 0x004,
|
268 | 008ff9d7 | j_mayer | DCR_UICTR = 0x005,
|
269 | 008ff9d7 | j_mayer | DCR_UICMSR = 0x006,
|
270 | 008ff9d7 | j_mayer | DCR_UICVR = 0x007,
|
271 | 008ff9d7 | j_mayer | DCR_UICVCR = 0x008,
|
272 | 008ff9d7 | j_mayer | DCR_UICMAX = 0x009,
|
273 | 008ff9d7 | j_mayer | }; |
274 | 008ff9d7 | j_mayer | |
275 | 008ff9d7 | j_mayer | #define UIC_MAX_IRQ 32 |
276 | 008ff9d7 | j_mayer | typedef struct ppcuic_t ppcuic_t; |
277 | 008ff9d7 | j_mayer | struct ppcuic_t {
|
278 | 008ff9d7 | j_mayer | uint32_t dcr_base; |
279 | 008ff9d7 | j_mayer | int use_vectors;
|
280 | 008ff9d7 | j_mayer | uint32_t uicsr; /* Status register */
|
281 | 008ff9d7 | j_mayer | uint32_t uicer; /* Enable register */
|
282 | 008ff9d7 | j_mayer | uint32_t uiccr; /* Critical register */
|
283 | 008ff9d7 | j_mayer | uint32_t uicpr; /* Polarity register */
|
284 | 008ff9d7 | j_mayer | uint32_t uictr; /* Triggering register */
|
285 | 008ff9d7 | j_mayer | uint32_t uicvcr; /* Vector configuration register */
|
286 | 008ff9d7 | j_mayer | uint32_t uicvr; |
287 | 008ff9d7 | j_mayer | qemu_irq *irqs; |
288 | 008ff9d7 | j_mayer | }; |
289 | 008ff9d7 | j_mayer | |
290 | 008ff9d7 | j_mayer | static void ppcuic_trigger_irq (ppcuic_t *uic) |
291 | 008ff9d7 | j_mayer | { |
292 | 008ff9d7 | j_mayer | uint32_t ir, cr; |
293 | 008ff9d7 | j_mayer | int start, end, inc, i;
|
294 | 008ff9d7 | j_mayer | |
295 | 008ff9d7 | j_mayer | /* Trigger interrupt if any is pending */
|
296 | 008ff9d7 | j_mayer | ir = uic->uicsr & uic->uicer & (~uic->uiccr); |
297 | 008ff9d7 | j_mayer | cr = uic->uicsr & uic->uicer & uic->uiccr; |
298 | 008ff9d7 | j_mayer | #ifdef DEBUG_UIC
|
299 | 008ff9d7 | j_mayer | if (loglevel & CPU_LOG_INT) {
|
300 | 008ff9d7 | j_mayer | fprintf(logfile, "%s: uicsr %08x uicer %08x uiccr %08x\n"
|
301 | 008ff9d7 | j_mayer | " %08x ir %08x cr %08x\n", __func__,
|
302 | 008ff9d7 | j_mayer | uic->uicsr, uic->uicer, uic->uiccr, |
303 | 008ff9d7 | j_mayer | uic->uicsr & uic->uicer, ir, cr); |
304 | 008ff9d7 | j_mayer | } |
305 | 008ff9d7 | j_mayer | #endif
|
306 | 008ff9d7 | j_mayer | if (ir != 0x0000000) { |
307 | 008ff9d7 | j_mayer | #ifdef DEBUG_UIC
|
308 | 008ff9d7 | j_mayer | if (loglevel & CPU_LOG_INT) {
|
309 | 008ff9d7 | j_mayer | fprintf(logfile, "Raise UIC interrupt\n");
|
310 | 008ff9d7 | j_mayer | } |
311 | 008ff9d7 | j_mayer | #endif
|
312 | 008ff9d7 | j_mayer | qemu_irq_raise(uic->irqs[PPCUIC_OUTPUT_INT]); |
313 | 008ff9d7 | j_mayer | } else {
|
314 | 008ff9d7 | j_mayer | #ifdef DEBUG_UIC
|
315 | 008ff9d7 | j_mayer | if (loglevel & CPU_LOG_INT) {
|
316 | 008ff9d7 | j_mayer | fprintf(logfile, "Lower UIC interrupt\n");
|
317 | 008ff9d7 | j_mayer | } |
318 | 008ff9d7 | j_mayer | #endif
|
319 | 008ff9d7 | j_mayer | qemu_irq_lower(uic->irqs[PPCUIC_OUTPUT_INT]); |
320 | 008ff9d7 | j_mayer | } |
321 | 008ff9d7 | j_mayer | /* Trigger critical interrupt if any is pending and update vector */
|
322 | 008ff9d7 | j_mayer | if (cr != 0x0000000) { |
323 | 008ff9d7 | j_mayer | qemu_irq_raise(uic->irqs[PPCUIC_OUTPUT_CINT]); |
324 | 008ff9d7 | j_mayer | if (uic->use_vectors) {
|
325 | 008ff9d7 | j_mayer | /* Compute critical IRQ vector */
|
326 | 008ff9d7 | j_mayer | if (uic->uicvcr & 1) { |
327 | 008ff9d7 | j_mayer | start = 31;
|
328 | 008ff9d7 | j_mayer | end = 0;
|
329 | 008ff9d7 | j_mayer | inc = -1;
|
330 | 008ff9d7 | j_mayer | } else {
|
331 | 008ff9d7 | j_mayer | start = 0;
|
332 | 008ff9d7 | j_mayer | end = 31;
|
333 | 008ff9d7 | j_mayer | inc = 1;
|
334 | 008ff9d7 | j_mayer | } |
335 | 008ff9d7 | j_mayer | uic->uicvr = uic->uicvcr & 0xFFFFFFFC;
|
336 | 008ff9d7 | j_mayer | for (i = start; i <= end; i += inc) {
|
337 | 008ff9d7 | j_mayer | if (cr & (1 << i)) { |
338 | 008ff9d7 | j_mayer | uic->uicvr += (i - start) * 512 * inc;
|
339 | 008ff9d7 | j_mayer | break;
|
340 | 008ff9d7 | j_mayer | } |
341 | 008ff9d7 | j_mayer | } |
342 | 008ff9d7 | j_mayer | } |
343 | 008ff9d7 | j_mayer | #ifdef DEBUG_UIC
|
344 | 008ff9d7 | j_mayer | if (loglevel & CPU_LOG_INT) {
|
345 | 008ff9d7 | j_mayer | fprintf(logfile, "Raise UIC critical interrupt - vector %08x\n",
|
346 | 008ff9d7 | j_mayer | uic->uicvr); |
347 | 008ff9d7 | j_mayer | } |
348 | 008ff9d7 | j_mayer | #endif
|
349 | 008ff9d7 | j_mayer | } else {
|
350 | 008ff9d7 | j_mayer | #ifdef DEBUG_UIC
|
351 | 008ff9d7 | j_mayer | if (loglevel & CPU_LOG_INT) {
|
352 | 008ff9d7 | j_mayer | fprintf(logfile, "Lower UIC critical interrupt\n");
|
353 | 008ff9d7 | j_mayer | } |
354 | 008ff9d7 | j_mayer | #endif
|
355 | 008ff9d7 | j_mayer | qemu_irq_lower(uic->irqs[PPCUIC_OUTPUT_CINT]); |
356 | 008ff9d7 | j_mayer | uic->uicvr = 0x00000000;
|
357 | 008ff9d7 | j_mayer | } |
358 | 008ff9d7 | j_mayer | } |
359 | 008ff9d7 | j_mayer | |
360 | 008ff9d7 | j_mayer | static void ppcuic_set_irq (void *opaque, int irq_num, int level) |
361 | 008ff9d7 | j_mayer | { |
362 | 008ff9d7 | j_mayer | ppcuic_t *uic; |
363 | 008ff9d7 | j_mayer | uint32_t mask, sr; |
364 | 008ff9d7 | j_mayer | |
365 | 008ff9d7 | j_mayer | uic = opaque; |
366 | 008ff9d7 | j_mayer | mask = 1 << irq_num;
|
367 | 008ff9d7 | j_mayer | #ifdef DEBUG_UIC
|
368 | 008ff9d7 | j_mayer | if (loglevel & CPU_LOG_INT) {
|
369 | 008ff9d7 | j_mayer | fprintf(logfile, "%s: irq %d level %d uicsr %08x mask %08x => %08x "
|
370 | 008ff9d7 | j_mayer | "%08x\n", __func__, irq_num, level,
|
371 | 008ff9d7 | j_mayer | uic->uicsr, mask, uic->uicsr & mask, level << irq_num); |
372 | 008ff9d7 | j_mayer | } |
373 | 008ff9d7 | j_mayer | #endif
|
374 | 008ff9d7 | j_mayer | if (irq_num < 0 || irq_num > 31) |
375 | 008ff9d7 | j_mayer | return;
|
376 | 008ff9d7 | j_mayer | sr = uic->uicsr; |
377 | 008ff9d7 | j_mayer | if (!(uic->uicpr & mask)) {
|
378 | 008ff9d7 | j_mayer | /* Negatively asserted IRQ */
|
379 | 008ff9d7 | j_mayer | level = level == 0 ? 1 : 0; |
380 | 008ff9d7 | j_mayer | } |
381 | 008ff9d7 | j_mayer | /* Update status register */
|
382 | 008ff9d7 | j_mayer | if (uic->uictr & mask) {
|
383 | 008ff9d7 | j_mayer | /* Edge sensitive interrupt */
|
384 | 008ff9d7 | j_mayer | if (level == 1) |
385 | 008ff9d7 | j_mayer | uic->uicsr |= mask; |
386 | 008ff9d7 | j_mayer | } else {
|
387 | 008ff9d7 | j_mayer | /* Level sensitive interrupt */
|
388 | 008ff9d7 | j_mayer | if (level == 1) |
389 | 008ff9d7 | j_mayer | uic->uicsr |= mask; |
390 | 008ff9d7 | j_mayer | else
|
391 | 008ff9d7 | j_mayer | uic->uicsr &= ~mask; |
392 | 008ff9d7 | j_mayer | } |
393 | 008ff9d7 | j_mayer | #ifdef DEBUG_UIC
|
394 | 008ff9d7 | j_mayer | if (loglevel & CPU_LOG_INT) {
|
395 | 008ff9d7 | j_mayer | fprintf(logfile, "%s: irq %d level %d sr %08x => %08x\n", __func__,
|
396 | 008ff9d7 | j_mayer | irq_num, level, uic->uicsr, sr); |
397 | 008ff9d7 | j_mayer | } |
398 | 008ff9d7 | j_mayer | #endif
|
399 | 008ff9d7 | j_mayer | if (sr != uic->uicsr)
|
400 | 008ff9d7 | j_mayer | ppcuic_trigger_irq(uic); |
401 | 008ff9d7 | j_mayer | } |
402 | 008ff9d7 | j_mayer | |
403 | 008ff9d7 | j_mayer | static target_ulong dcr_read_uic (void *opaque, int dcrn) |
404 | 008ff9d7 | j_mayer | { |
405 | 008ff9d7 | j_mayer | ppcuic_t *uic; |
406 | 008ff9d7 | j_mayer | target_ulong ret; |
407 | 008ff9d7 | j_mayer | |
408 | 008ff9d7 | j_mayer | uic = opaque; |
409 | 008ff9d7 | j_mayer | dcrn -= uic->dcr_base; |
410 | 008ff9d7 | j_mayer | switch (dcrn) {
|
411 | 008ff9d7 | j_mayer | case DCR_UICSR:
|
412 | 008ff9d7 | j_mayer | case DCR_UICSRS:
|
413 | 008ff9d7 | j_mayer | ret = uic->uicsr; |
414 | 008ff9d7 | j_mayer | break;
|
415 | 008ff9d7 | j_mayer | case DCR_UICER:
|
416 | 008ff9d7 | j_mayer | ret = uic->uicer; |
417 | 008ff9d7 | j_mayer | break;
|
418 | 008ff9d7 | j_mayer | case DCR_UICCR:
|
419 | 008ff9d7 | j_mayer | ret = uic->uiccr; |
420 | 008ff9d7 | j_mayer | break;
|
421 | 008ff9d7 | j_mayer | case DCR_UICPR:
|
422 | 008ff9d7 | j_mayer | ret = uic->uicpr; |
423 | 008ff9d7 | j_mayer | break;
|
424 | 008ff9d7 | j_mayer | case DCR_UICTR:
|
425 | 008ff9d7 | j_mayer | ret = uic->uictr; |
426 | 008ff9d7 | j_mayer | break;
|
427 | 008ff9d7 | j_mayer | case DCR_UICMSR:
|
428 | 008ff9d7 | j_mayer | ret = uic->uicsr & uic->uicer; |
429 | 008ff9d7 | j_mayer | break;
|
430 | 008ff9d7 | j_mayer | case DCR_UICVR:
|
431 | 008ff9d7 | j_mayer | if (!uic->use_vectors)
|
432 | 008ff9d7 | j_mayer | goto no_read;
|
433 | 008ff9d7 | j_mayer | ret = uic->uicvr; |
434 | 008ff9d7 | j_mayer | break;
|
435 | 008ff9d7 | j_mayer | case DCR_UICVCR:
|
436 | 008ff9d7 | j_mayer | if (!uic->use_vectors)
|
437 | 008ff9d7 | j_mayer | goto no_read;
|
438 | 008ff9d7 | j_mayer | ret = uic->uicvcr; |
439 | 008ff9d7 | j_mayer | break;
|
440 | 008ff9d7 | j_mayer | default:
|
441 | 008ff9d7 | j_mayer | no_read:
|
442 | 008ff9d7 | j_mayer | ret = 0x00000000;
|
443 | 008ff9d7 | j_mayer | break;
|
444 | 008ff9d7 | j_mayer | } |
445 | 008ff9d7 | j_mayer | |
446 | 008ff9d7 | j_mayer | return ret;
|
447 | 008ff9d7 | j_mayer | } |
448 | 008ff9d7 | j_mayer | |
449 | 008ff9d7 | j_mayer | static void dcr_write_uic (void *opaque, int dcrn, target_ulong val) |
450 | 008ff9d7 | j_mayer | { |
451 | 008ff9d7 | j_mayer | ppcuic_t *uic; |
452 | 008ff9d7 | j_mayer | |
453 | 008ff9d7 | j_mayer | uic = opaque; |
454 | 008ff9d7 | j_mayer | dcrn -= uic->dcr_base; |
455 | 008ff9d7 | j_mayer | #ifdef DEBUG_UIC
|
456 | 008ff9d7 | j_mayer | if (loglevel & CPU_LOG_INT) {
|
457 | 008ff9d7 | j_mayer | fprintf(logfile, "%s: dcr %d val " ADDRX "\n", __func__, dcrn, val); |
458 | 008ff9d7 | j_mayer | } |
459 | 008ff9d7 | j_mayer | #endif
|
460 | 008ff9d7 | j_mayer | switch (dcrn) {
|
461 | 008ff9d7 | j_mayer | case DCR_UICSR:
|
462 | 008ff9d7 | j_mayer | uic->uicsr &= ~val; |
463 | 008ff9d7 | j_mayer | ppcuic_trigger_irq(uic); |
464 | 008ff9d7 | j_mayer | break;
|
465 | 008ff9d7 | j_mayer | case DCR_UICSRS:
|
466 | 008ff9d7 | j_mayer | uic->uicsr |= val; |
467 | 008ff9d7 | j_mayer | ppcuic_trigger_irq(uic); |
468 | 008ff9d7 | j_mayer | break;
|
469 | 008ff9d7 | j_mayer | case DCR_UICER:
|
470 | 008ff9d7 | j_mayer | uic->uicer = val; |
471 | 008ff9d7 | j_mayer | ppcuic_trigger_irq(uic); |
472 | 008ff9d7 | j_mayer | break;
|
473 | 008ff9d7 | j_mayer | case DCR_UICCR:
|
474 | 008ff9d7 | j_mayer | uic->uiccr = val; |
475 | 008ff9d7 | j_mayer | ppcuic_trigger_irq(uic); |
476 | 008ff9d7 | j_mayer | break;
|
477 | 008ff9d7 | j_mayer | case DCR_UICPR:
|
478 | 008ff9d7 | j_mayer | uic->uicpr = val; |
479 | 008ff9d7 | j_mayer | ppcuic_trigger_irq(uic); |
480 | 008ff9d7 | j_mayer | break;
|
481 | 008ff9d7 | j_mayer | case DCR_UICTR:
|
482 | 008ff9d7 | j_mayer | uic->uictr = val; |
483 | 008ff9d7 | j_mayer | ppcuic_trigger_irq(uic); |
484 | 008ff9d7 | j_mayer | break;
|
485 | 008ff9d7 | j_mayer | case DCR_UICMSR:
|
486 | 008ff9d7 | j_mayer | break;
|
487 | 008ff9d7 | j_mayer | case DCR_UICVR:
|
488 | 008ff9d7 | j_mayer | break;
|
489 | 008ff9d7 | j_mayer | case DCR_UICVCR:
|
490 | 008ff9d7 | j_mayer | uic->uicvcr = val & 0xFFFFFFFD;
|
491 | 008ff9d7 | j_mayer | ppcuic_trigger_irq(uic); |
492 | 008ff9d7 | j_mayer | break;
|
493 | 008ff9d7 | j_mayer | } |
494 | 008ff9d7 | j_mayer | } |
495 | 008ff9d7 | j_mayer | |
496 | 008ff9d7 | j_mayer | static void ppcuic_reset (void *opaque) |
497 | 008ff9d7 | j_mayer | { |
498 | 008ff9d7 | j_mayer | ppcuic_t *uic; |
499 | 008ff9d7 | j_mayer | |
500 | 008ff9d7 | j_mayer | uic = opaque; |
501 | 008ff9d7 | j_mayer | uic->uiccr = 0x00000000;
|
502 | 008ff9d7 | j_mayer | uic->uicer = 0x00000000;
|
503 | 008ff9d7 | j_mayer | uic->uicpr = 0x00000000;
|
504 | 008ff9d7 | j_mayer | uic->uicsr = 0x00000000;
|
505 | 008ff9d7 | j_mayer | uic->uictr = 0x00000000;
|
506 | 008ff9d7 | j_mayer | if (uic->use_vectors) {
|
507 | 008ff9d7 | j_mayer | uic->uicvcr = 0x00000000;
|
508 | 008ff9d7 | j_mayer | uic->uicvr = 0x0000000;
|
509 | 008ff9d7 | j_mayer | } |
510 | 008ff9d7 | j_mayer | } |
511 | 008ff9d7 | j_mayer | |
512 | 008ff9d7 | j_mayer | qemu_irq *ppcuic_init (CPUState *env, qemu_irq *irqs, |
513 | 008ff9d7 | j_mayer | uint32_t dcr_base, int has_ssr, int has_vr) |
514 | 008ff9d7 | j_mayer | { |
515 | 008ff9d7 | j_mayer | ppcuic_t *uic; |
516 | 008ff9d7 | j_mayer | int i;
|
517 | 008ff9d7 | j_mayer | |
518 | 008ff9d7 | j_mayer | uic = qemu_mallocz(sizeof(ppcuic_t));
|
519 | 008ff9d7 | j_mayer | if (uic != NULL) { |
520 | 008ff9d7 | j_mayer | uic->dcr_base = dcr_base; |
521 | 008ff9d7 | j_mayer | uic->irqs = irqs; |
522 | 008ff9d7 | j_mayer | if (has_vr)
|
523 | 008ff9d7 | j_mayer | uic->use_vectors = 1;
|
524 | 008ff9d7 | j_mayer | for (i = 0; i < DCR_UICMAX; i++) { |
525 | 008ff9d7 | j_mayer | ppc_dcr_register(env, dcr_base + i, uic, |
526 | 008ff9d7 | j_mayer | &dcr_read_uic, &dcr_write_uic); |
527 | 008ff9d7 | j_mayer | } |
528 | 008ff9d7 | j_mayer | qemu_register_reset(ppcuic_reset, uic); |
529 | 008ff9d7 | j_mayer | ppcuic_reset(uic); |
530 | 008ff9d7 | j_mayer | } |
531 | 008ff9d7 | j_mayer | |
532 | 008ff9d7 | j_mayer | return qemu_allocate_irqs(&ppcuic_set_irq, uic, UIC_MAX_IRQ);
|
533 | 008ff9d7 | j_mayer | } |