root / hw / ppc4xx_devs.c @ 4487fd34
History | View | Annotate | Download (14.6 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 | aae9366a | j_mayer | //#define DEBUG_UNASSIGNED
|
34 | 008ff9d7 | j_mayer | #define DEBUG_UIC
|
35 | 008ff9d7 | j_mayer | |
36 | 008ff9d7 | j_mayer | /*****************************************************************************/
|
37 | 008ff9d7 | j_mayer | /* Generic PowerPC 4xx processor instanciation */
|
38 | 008ff9d7 | j_mayer | CPUState *ppc4xx_init (const unsigned char *cpu_model, |
39 | 008ff9d7 | j_mayer | clk_setup_t *cpu_clk, clk_setup_t *tb_clk, |
40 | 008ff9d7 | j_mayer | uint32_t sysclk) |
41 | 008ff9d7 | j_mayer | { |
42 | 008ff9d7 | j_mayer | CPUState *env; |
43 | 008ff9d7 | j_mayer | |
44 | 008ff9d7 | j_mayer | /* init CPUs */
|
45 | aaed909a | bellard | env = cpu_init(cpu_model); |
46 | aaed909a | bellard | if (!env) {
|
47 | aaed909a | bellard | fprintf(stderr, "Unable to find PowerPC %s CPU definition\n",
|
48 | aaed909a | bellard | cpu_model); |
49 | aaed909a | bellard | exit(1);
|
50 | 008ff9d7 | j_mayer | } |
51 | 008ff9d7 | j_mayer | cpu_clk->cb = NULL; /* We don't care about CPU clock frequency changes */ |
52 | 008ff9d7 | j_mayer | cpu_clk->opaque = env; |
53 | 008ff9d7 | j_mayer | /* Set time-base frequency to sysclk */
|
54 | 008ff9d7 | j_mayer | tb_clk->cb = ppc_emb_timers_init(env, sysclk); |
55 | 008ff9d7 | j_mayer | tb_clk->opaque = env; |
56 | 008ff9d7 | j_mayer | ppc_dcr_init(env, NULL, NULL); |
57 | 008ff9d7 | j_mayer | /* Register qemu callbacks */
|
58 | 008ff9d7 | j_mayer | qemu_register_reset(&cpu_ppc_reset, 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 | aae9366a | j_mayer | printf("%s: mmio %p len %d addr " PADDRX " idx %d value %08" PRIx32 "\n", |
140 | aae9366a | j_mayer | __func__, 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 | aae9366a | j_mayer | printf("%s: addr " PADDRX " val %08" PRIx32 "\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 | aae9366a | j_mayer | printf("%s: addr " PADDRX " val %08" PRIx32 "\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 | aae9366a | j_mayer | printf("%s: addr " PADDRX " val %08" PRIx32 "\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 | aae9366a | j_mayer | target_phys_addr_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 | aae9366a | j_mayer | printf("%s: offset " PADDRX " len %08" PRIx32 " " PADDRX " %d %d\n", |
227 | aae9366a | j_mayer | __func__, offset, len, 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 | aae9366a | j_mayer | printf("%s: base " PADDRX " len %08x %d\n", __func__, |
249 | aae9366a | j_mayer | 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 | 4c54e875 | aurel32 | uint32_t level; /* Remembers the state of level-triggered interrupts. */
|
281 | 008ff9d7 | j_mayer | uint32_t uicsr; /* Status register */
|
282 | 008ff9d7 | j_mayer | uint32_t uicer; /* Enable register */
|
283 | 008ff9d7 | j_mayer | uint32_t uiccr; /* Critical register */
|
284 | 008ff9d7 | j_mayer | uint32_t uicpr; /* Polarity register */
|
285 | 008ff9d7 | j_mayer | uint32_t uictr; /* Triggering register */
|
286 | 008ff9d7 | j_mayer | uint32_t uicvcr; /* Vector configuration register */
|
287 | 008ff9d7 | j_mayer | uint32_t uicvr; |
288 | 008ff9d7 | j_mayer | qemu_irq *irqs; |
289 | 008ff9d7 | j_mayer | }; |
290 | 008ff9d7 | j_mayer | |
291 | 008ff9d7 | j_mayer | static void ppcuic_trigger_irq (ppcuic_t *uic) |
292 | 008ff9d7 | j_mayer | { |
293 | 008ff9d7 | j_mayer | uint32_t ir, cr; |
294 | 008ff9d7 | j_mayer | int start, end, inc, i;
|
295 | 008ff9d7 | j_mayer | |
296 | 008ff9d7 | j_mayer | /* Trigger interrupt if any is pending */
|
297 | 008ff9d7 | j_mayer | ir = uic->uicsr & uic->uicer & (~uic->uiccr); |
298 | 008ff9d7 | j_mayer | cr = uic->uicsr & uic->uicer & uic->uiccr; |
299 | 008ff9d7 | j_mayer | #ifdef DEBUG_UIC
|
300 | 008ff9d7 | j_mayer | if (loglevel & CPU_LOG_INT) {
|
301 | aae9366a | j_mayer | fprintf(logfile, "%s: uicsr %08" PRIx32 " uicer %08" PRIx32 |
302 | aae9366a | j_mayer | " uiccr %08" PRIx32 "\n" |
303 | aae9366a | j_mayer | " %08" PRIx32 " ir %08" PRIx32 " cr %08" PRIx32 "\n", |
304 | aae9366a | j_mayer | __func__, uic->uicsr, uic->uicer, uic->uiccr, |
305 | 008ff9d7 | j_mayer | uic->uicsr & uic->uicer, ir, cr); |
306 | 008ff9d7 | j_mayer | } |
307 | 008ff9d7 | j_mayer | #endif
|
308 | 008ff9d7 | j_mayer | if (ir != 0x0000000) { |
309 | 008ff9d7 | j_mayer | #ifdef DEBUG_UIC
|
310 | 008ff9d7 | j_mayer | if (loglevel & CPU_LOG_INT) {
|
311 | 008ff9d7 | j_mayer | fprintf(logfile, "Raise UIC interrupt\n");
|
312 | 008ff9d7 | j_mayer | } |
313 | 008ff9d7 | j_mayer | #endif
|
314 | 008ff9d7 | j_mayer | qemu_irq_raise(uic->irqs[PPCUIC_OUTPUT_INT]); |
315 | 008ff9d7 | j_mayer | } else {
|
316 | 008ff9d7 | j_mayer | #ifdef DEBUG_UIC
|
317 | 008ff9d7 | j_mayer | if (loglevel & CPU_LOG_INT) {
|
318 | 008ff9d7 | j_mayer | fprintf(logfile, "Lower UIC interrupt\n");
|
319 | 008ff9d7 | j_mayer | } |
320 | 008ff9d7 | j_mayer | #endif
|
321 | 008ff9d7 | j_mayer | qemu_irq_lower(uic->irqs[PPCUIC_OUTPUT_INT]); |
322 | 008ff9d7 | j_mayer | } |
323 | 008ff9d7 | j_mayer | /* Trigger critical interrupt if any is pending and update vector */
|
324 | 008ff9d7 | j_mayer | if (cr != 0x0000000) { |
325 | 008ff9d7 | j_mayer | qemu_irq_raise(uic->irqs[PPCUIC_OUTPUT_CINT]); |
326 | 008ff9d7 | j_mayer | if (uic->use_vectors) {
|
327 | 008ff9d7 | j_mayer | /* Compute critical IRQ vector */
|
328 | 008ff9d7 | j_mayer | if (uic->uicvcr & 1) { |
329 | 008ff9d7 | j_mayer | start = 31;
|
330 | 008ff9d7 | j_mayer | end = 0;
|
331 | 008ff9d7 | j_mayer | inc = -1;
|
332 | 008ff9d7 | j_mayer | } else {
|
333 | 008ff9d7 | j_mayer | start = 0;
|
334 | 008ff9d7 | j_mayer | end = 31;
|
335 | 008ff9d7 | j_mayer | inc = 1;
|
336 | 008ff9d7 | j_mayer | } |
337 | 008ff9d7 | j_mayer | uic->uicvr = uic->uicvcr & 0xFFFFFFFC;
|
338 | 008ff9d7 | j_mayer | for (i = start; i <= end; i += inc) {
|
339 | 008ff9d7 | j_mayer | if (cr & (1 << i)) { |
340 | 008ff9d7 | j_mayer | uic->uicvr += (i - start) * 512 * inc;
|
341 | 008ff9d7 | j_mayer | break;
|
342 | 008ff9d7 | j_mayer | } |
343 | 008ff9d7 | j_mayer | } |
344 | 008ff9d7 | j_mayer | } |
345 | 008ff9d7 | j_mayer | #ifdef DEBUG_UIC
|
346 | 008ff9d7 | j_mayer | if (loglevel & CPU_LOG_INT) {
|
347 | aae9366a | j_mayer | fprintf(logfile, "Raise UIC critical interrupt - "
|
348 | aae9366a | j_mayer | "vector %08" PRIx32 "\n", uic->uicvr); |
349 | 008ff9d7 | j_mayer | } |
350 | 008ff9d7 | j_mayer | #endif
|
351 | 008ff9d7 | j_mayer | } else {
|
352 | 008ff9d7 | j_mayer | #ifdef DEBUG_UIC
|
353 | 008ff9d7 | j_mayer | if (loglevel & CPU_LOG_INT) {
|
354 | 008ff9d7 | j_mayer | fprintf(logfile, "Lower UIC critical interrupt\n");
|
355 | 008ff9d7 | j_mayer | } |
356 | 008ff9d7 | j_mayer | #endif
|
357 | 008ff9d7 | j_mayer | qemu_irq_lower(uic->irqs[PPCUIC_OUTPUT_CINT]); |
358 | 008ff9d7 | j_mayer | uic->uicvr = 0x00000000;
|
359 | 008ff9d7 | j_mayer | } |
360 | 008ff9d7 | j_mayer | } |
361 | 008ff9d7 | j_mayer | |
362 | 008ff9d7 | j_mayer | static void ppcuic_set_irq (void *opaque, int irq_num, int level) |
363 | 008ff9d7 | j_mayer | { |
364 | 008ff9d7 | j_mayer | ppcuic_t *uic; |
365 | 008ff9d7 | j_mayer | uint32_t mask, sr; |
366 | 008ff9d7 | j_mayer | |
367 | 008ff9d7 | j_mayer | uic = opaque; |
368 | 923e5e33 | aurel32 | mask = 1 << (31-irq_num); |
369 | 008ff9d7 | j_mayer | #ifdef DEBUG_UIC
|
370 | 008ff9d7 | j_mayer | if (loglevel & CPU_LOG_INT) {
|
371 | aae9366a | j_mayer | fprintf(logfile, "%s: irq %d level %d uicsr %08" PRIx32
|
372 | aae9366a | j_mayer | " mask %08" PRIx32 " => %08" PRIx32 " %08" PRIx32 "\n", |
373 | aae9366a | j_mayer | __func__, irq_num, level, |
374 | 008ff9d7 | j_mayer | uic->uicsr, mask, uic->uicsr & mask, level << irq_num); |
375 | 008ff9d7 | j_mayer | } |
376 | 008ff9d7 | j_mayer | #endif
|
377 | 008ff9d7 | j_mayer | if (irq_num < 0 || irq_num > 31) |
378 | 008ff9d7 | j_mayer | return;
|
379 | 008ff9d7 | j_mayer | sr = uic->uicsr; |
380 | 50bf72b3 | aurel32 | |
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 | 4c54e875 | aurel32 | if (level == 1) { |
389 | 008ff9d7 | j_mayer | uic->uicsr |= mask; |
390 | 4c54e875 | aurel32 | uic->level |= mask; |
391 | 4c54e875 | aurel32 | } else {
|
392 | 008ff9d7 | j_mayer | uic->uicsr &= ~mask; |
393 | 4c54e875 | aurel32 | uic->level &= ~mask; |
394 | 4c54e875 | aurel32 | } |
395 | 008ff9d7 | j_mayer | } |
396 | 008ff9d7 | j_mayer | #ifdef DEBUG_UIC
|
397 | 008ff9d7 | j_mayer | if (loglevel & CPU_LOG_INT) {
|
398 | aae9366a | j_mayer | fprintf(logfile, "%s: irq %d level %d sr %" PRIx32 " => " |
399 | aae9366a | j_mayer | "%08" PRIx32 "\n", __func__, irq_num, level, uic->uicsr, sr); |
400 | 008ff9d7 | j_mayer | } |
401 | 008ff9d7 | j_mayer | #endif
|
402 | 008ff9d7 | j_mayer | if (sr != uic->uicsr)
|
403 | 008ff9d7 | j_mayer | ppcuic_trigger_irq(uic); |
404 | 008ff9d7 | j_mayer | } |
405 | 008ff9d7 | j_mayer | |
406 | 008ff9d7 | j_mayer | static target_ulong dcr_read_uic (void *opaque, int dcrn) |
407 | 008ff9d7 | j_mayer | { |
408 | 008ff9d7 | j_mayer | ppcuic_t *uic; |
409 | 008ff9d7 | j_mayer | target_ulong ret; |
410 | 008ff9d7 | j_mayer | |
411 | 008ff9d7 | j_mayer | uic = opaque; |
412 | 008ff9d7 | j_mayer | dcrn -= uic->dcr_base; |
413 | 008ff9d7 | j_mayer | switch (dcrn) {
|
414 | 008ff9d7 | j_mayer | case DCR_UICSR:
|
415 | 008ff9d7 | j_mayer | case DCR_UICSRS:
|
416 | 008ff9d7 | j_mayer | ret = uic->uicsr; |
417 | 008ff9d7 | j_mayer | break;
|
418 | 008ff9d7 | j_mayer | case DCR_UICER:
|
419 | 008ff9d7 | j_mayer | ret = uic->uicer; |
420 | 008ff9d7 | j_mayer | break;
|
421 | 008ff9d7 | j_mayer | case DCR_UICCR:
|
422 | 008ff9d7 | j_mayer | ret = uic->uiccr; |
423 | 008ff9d7 | j_mayer | break;
|
424 | 008ff9d7 | j_mayer | case DCR_UICPR:
|
425 | 008ff9d7 | j_mayer | ret = uic->uicpr; |
426 | 008ff9d7 | j_mayer | break;
|
427 | 008ff9d7 | j_mayer | case DCR_UICTR:
|
428 | 008ff9d7 | j_mayer | ret = uic->uictr; |
429 | 008ff9d7 | j_mayer | break;
|
430 | 008ff9d7 | j_mayer | case DCR_UICMSR:
|
431 | 008ff9d7 | j_mayer | ret = uic->uicsr & uic->uicer; |
432 | 008ff9d7 | j_mayer | break;
|
433 | 008ff9d7 | j_mayer | case DCR_UICVR:
|
434 | 008ff9d7 | j_mayer | if (!uic->use_vectors)
|
435 | 008ff9d7 | j_mayer | goto no_read;
|
436 | 008ff9d7 | j_mayer | ret = uic->uicvr; |
437 | 008ff9d7 | j_mayer | break;
|
438 | 008ff9d7 | j_mayer | case DCR_UICVCR:
|
439 | 008ff9d7 | j_mayer | if (!uic->use_vectors)
|
440 | 008ff9d7 | j_mayer | goto no_read;
|
441 | 008ff9d7 | j_mayer | ret = uic->uicvcr; |
442 | 008ff9d7 | j_mayer | break;
|
443 | 008ff9d7 | j_mayer | default:
|
444 | 008ff9d7 | j_mayer | no_read:
|
445 | 008ff9d7 | j_mayer | ret = 0x00000000;
|
446 | 008ff9d7 | j_mayer | break;
|
447 | 008ff9d7 | j_mayer | } |
448 | 008ff9d7 | j_mayer | |
449 | 008ff9d7 | j_mayer | return ret;
|
450 | 008ff9d7 | j_mayer | } |
451 | 008ff9d7 | j_mayer | |
452 | 008ff9d7 | j_mayer | static void dcr_write_uic (void *opaque, int dcrn, target_ulong val) |
453 | 008ff9d7 | j_mayer | { |
454 | 008ff9d7 | j_mayer | ppcuic_t *uic; |
455 | 008ff9d7 | j_mayer | |
456 | 008ff9d7 | j_mayer | uic = opaque; |
457 | 008ff9d7 | j_mayer | dcrn -= uic->dcr_base; |
458 | 008ff9d7 | j_mayer | #ifdef DEBUG_UIC
|
459 | 008ff9d7 | j_mayer | if (loglevel & CPU_LOG_INT) {
|
460 | 008ff9d7 | j_mayer | fprintf(logfile, "%s: dcr %d val " ADDRX "\n", __func__, dcrn, val); |
461 | 008ff9d7 | j_mayer | } |
462 | 008ff9d7 | j_mayer | #endif
|
463 | 008ff9d7 | j_mayer | switch (dcrn) {
|
464 | 008ff9d7 | j_mayer | case DCR_UICSR:
|
465 | 008ff9d7 | j_mayer | uic->uicsr &= ~val; |
466 | 4c54e875 | aurel32 | uic->uicsr |= uic->level; |
467 | 008ff9d7 | j_mayer | ppcuic_trigger_irq(uic); |
468 | 008ff9d7 | j_mayer | break;
|
469 | 008ff9d7 | j_mayer | case DCR_UICSRS:
|
470 | 008ff9d7 | j_mayer | uic->uicsr |= val; |
471 | 008ff9d7 | j_mayer | ppcuic_trigger_irq(uic); |
472 | 008ff9d7 | j_mayer | break;
|
473 | 008ff9d7 | j_mayer | case DCR_UICER:
|
474 | 008ff9d7 | j_mayer | uic->uicer = val; |
475 | 008ff9d7 | j_mayer | ppcuic_trigger_irq(uic); |
476 | 008ff9d7 | j_mayer | break;
|
477 | 008ff9d7 | j_mayer | case DCR_UICCR:
|
478 | 008ff9d7 | j_mayer | uic->uiccr = val; |
479 | 008ff9d7 | j_mayer | ppcuic_trigger_irq(uic); |
480 | 008ff9d7 | j_mayer | break;
|
481 | 008ff9d7 | j_mayer | case DCR_UICPR:
|
482 | 008ff9d7 | j_mayer | uic->uicpr = val; |
483 | 008ff9d7 | j_mayer | break;
|
484 | 008ff9d7 | j_mayer | case DCR_UICTR:
|
485 | 008ff9d7 | j_mayer | uic->uictr = val; |
486 | 008ff9d7 | j_mayer | ppcuic_trigger_irq(uic); |
487 | 008ff9d7 | j_mayer | break;
|
488 | 008ff9d7 | j_mayer | case DCR_UICMSR:
|
489 | 008ff9d7 | j_mayer | break;
|
490 | 008ff9d7 | j_mayer | case DCR_UICVR:
|
491 | 008ff9d7 | j_mayer | break;
|
492 | 008ff9d7 | j_mayer | case DCR_UICVCR:
|
493 | 008ff9d7 | j_mayer | uic->uicvcr = val & 0xFFFFFFFD;
|
494 | 008ff9d7 | j_mayer | ppcuic_trigger_irq(uic); |
495 | 008ff9d7 | j_mayer | break;
|
496 | 008ff9d7 | j_mayer | } |
497 | 008ff9d7 | j_mayer | } |
498 | 008ff9d7 | j_mayer | |
499 | 008ff9d7 | j_mayer | static void ppcuic_reset (void *opaque) |
500 | 008ff9d7 | j_mayer | { |
501 | 008ff9d7 | j_mayer | ppcuic_t *uic; |
502 | 008ff9d7 | j_mayer | |
503 | 008ff9d7 | j_mayer | uic = opaque; |
504 | 008ff9d7 | j_mayer | uic->uiccr = 0x00000000;
|
505 | 008ff9d7 | j_mayer | uic->uicer = 0x00000000;
|
506 | 008ff9d7 | j_mayer | uic->uicpr = 0x00000000;
|
507 | 008ff9d7 | j_mayer | uic->uicsr = 0x00000000;
|
508 | 008ff9d7 | j_mayer | uic->uictr = 0x00000000;
|
509 | 008ff9d7 | j_mayer | if (uic->use_vectors) {
|
510 | 008ff9d7 | j_mayer | uic->uicvcr = 0x00000000;
|
511 | 008ff9d7 | j_mayer | uic->uicvr = 0x0000000;
|
512 | 008ff9d7 | j_mayer | } |
513 | 008ff9d7 | j_mayer | } |
514 | 008ff9d7 | j_mayer | |
515 | 008ff9d7 | j_mayer | qemu_irq *ppcuic_init (CPUState *env, qemu_irq *irqs, |
516 | 008ff9d7 | j_mayer | uint32_t dcr_base, int has_ssr, int has_vr) |
517 | 008ff9d7 | j_mayer | { |
518 | 008ff9d7 | j_mayer | ppcuic_t *uic; |
519 | 008ff9d7 | j_mayer | int i;
|
520 | 008ff9d7 | j_mayer | |
521 | 008ff9d7 | j_mayer | uic = qemu_mallocz(sizeof(ppcuic_t));
|
522 | 008ff9d7 | j_mayer | if (uic != NULL) { |
523 | 008ff9d7 | j_mayer | uic->dcr_base = dcr_base; |
524 | 008ff9d7 | j_mayer | uic->irqs = irqs; |
525 | 008ff9d7 | j_mayer | if (has_vr)
|
526 | 008ff9d7 | j_mayer | uic->use_vectors = 1;
|
527 | 008ff9d7 | j_mayer | for (i = 0; i < DCR_UICMAX; i++) { |
528 | 008ff9d7 | j_mayer | ppc_dcr_register(env, dcr_base + i, uic, |
529 | 008ff9d7 | j_mayer | &dcr_read_uic, &dcr_write_uic); |
530 | 008ff9d7 | j_mayer | } |
531 | 008ff9d7 | j_mayer | qemu_register_reset(ppcuic_reset, uic); |
532 | 008ff9d7 | j_mayer | ppcuic_reset(uic); |
533 | 008ff9d7 | j_mayer | } |
534 | 008ff9d7 | j_mayer | |
535 | 008ff9d7 | j_mayer | return qemu_allocate_irqs(&ppcuic_set_irq, uic, UIC_MAX_IRQ);
|
536 | 008ff9d7 | j_mayer | } |