]>
Commit | Line | Data |
---|---|---|
8ecc7913 JM |
1 | /* |
2 | * QEMU PowerPC 405 embedded processors emulation | |
5fafdf24 | 3 | * |
8ecc7913 | 4 | * Copyright (c) 2007 Jocelyn Mayer |
5fafdf24 | 5 | * |
8ecc7913 JM |
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 | */ | |
87ecb68b PB |
24 | #include "hw.h" |
25 | #include "ppc.h" | |
04f20795 | 26 | #include "ppc405.h" |
87ecb68b PB |
27 | #include "pc.h" |
28 | #include "qemu-timer.h" | |
29 | #include "sysemu.h" | |
3b3fb322 | 30 | #include "qemu-log.h" |
8ecc7913 | 31 | |
8ecc7913 JM |
32 | #define DEBUG_OPBA |
33 | #define DEBUG_SDRAM | |
34 | #define DEBUG_GPIO | |
35 | #define DEBUG_SERIAL | |
36 | #define DEBUG_OCM | |
9c02f1a2 JM |
37 | //#define DEBUG_I2C |
38 | #define DEBUG_GPT | |
39 | #define DEBUG_MAL | |
8ecc7913 | 40 | #define DEBUG_CLOCKS |
aae9366a | 41 | //#define DEBUG_CLOCKS_LL |
8ecc7913 | 42 | |
c227f099 | 43 | ram_addr_t ppc405_set_bootinfo (CPUState *env, ppc4xx_bd_info_t *bd, |
b8d3f5d1 | 44 | uint32_t flags) |
04f20795 | 45 | { |
c227f099 | 46 | ram_addr_t bdloc; |
04f20795 JM |
47 | int i, n; |
48 | ||
49 | /* We put the bd structure at the top of memory */ | |
be58fc7c | 50 | if (bd->bi_memsize >= 0x01000000UL) |
c227f099 | 51 | bdloc = 0x01000000UL - sizeof(struct ppc4xx_bd_info_t); |
be58fc7c | 52 | else |
c227f099 | 53 | bdloc = bd->bi_memsize - sizeof(struct ppc4xx_bd_info_t); |
5c130f65 PB |
54 | stl_phys(bdloc + 0x00, bd->bi_memstart); |
55 | stl_phys(bdloc + 0x04, bd->bi_memsize); | |
56 | stl_phys(bdloc + 0x08, bd->bi_flashstart); | |
57 | stl_phys(bdloc + 0x0C, bd->bi_flashsize); | |
58 | stl_phys(bdloc + 0x10, bd->bi_flashoffset); | |
59 | stl_phys(bdloc + 0x14, bd->bi_sramstart); | |
60 | stl_phys(bdloc + 0x18, bd->bi_sramsize); | |
61 | stl_phys(bdloc + 0x1C, bd->bi_bootflags); | |
62 | stl_phys(bdloc + 0x20, bd->bi_ipaddr); | |
04f20795 | 63 | for (i = 0; i < 6; i++) |
5c130f65 PB |
64 | stb_phys(bdloc + 0x24 + i, bd->bi_enetaddr[i]); |
65 | stw_phys(bdloc + 0x2A, bd->bi_ethspeed); | |
66 | stl_phys(bdloc + 0x2C, bd->bi_intfreq); | |
67 | stl_phys(bdloc + 0x30, bd->bi_busfreq); | |
68 | stl_phys(bdloc + 0x34, bd->bi_baudrate); | |
04f20795 | 69 | for (i = 0; i < 4; i++) |
5c130f65 | 70 | stb_phys(bdloc + 0x38 + i, bd->bi_s_version[i]); |
04f20795 | 71 | for (i = 0; i < 32; i++) |
5c130f65 PB |
72 | stb_phys(bdloc + 0x3C + i, bd->bi_s_version[i]); |
73 | stl_phys(bdloc + 0x5C, bd->bi_plb_busfreq); | |
74 | stl_phys(bdloc + 0x60, bd->bi_pci_busfreq); | |
04f20795 | 75 | for (i = 0; i < 6; i++) |
5c130f65 | 76 | stb_phys(bdloc + 0x64 + i, bd->bi_pci_enetaddr[i]); |
04f20795 | 77 | n = 0x6A; |
b8d3f5d1 | 78 | if (flags & 0x00000001) { |
04f20795 | 79 | for (i = 0; i < 6; i++) |
5c130f65 | 80 | stb_phys(bdloc + n++, bd->bi_pci_enetaddr2[i]); |
04f20795 | 81 | } |
5c130f65 | 82 | stl_phys(bdloc + n, bd->bi_opbfreq); |
04f20795 JM |
83 | n += 4; |
84 | for (i = 0; i < 2; i++) { | |
5c130f65 | 85 | stl_phys(bdloc + n, bd->bi_iic_fast[i]); |
04f20795 JM |
86 | n += 4; |
87 | } | |
88 | ||
89 | return bdloc; | |
90 | } | |
91 | ||
8ecc7913 JM |
92 | /*****************************************************************************/ |
93 | /* Shared peripherals */ | |
94 | ||
8ecc7913 JM |
95 | /*****************************************************************************/ |
96 | /* Peripheral local bus arbitrer */ | |
97 | enum { | |
98 | PLB0_BESR = 0x084, | |
99 | PLB0_BEAR = 0x086, | |
100 | PLB0_ACR = 0x087, | |
101 | }; | |
102 | ||
c227f099 AL |
103 | typedef struct ppc4xx_plb_t ppc4xx_plb_t; |
104 | struct ppc4xx_plb_t { | |
8ecc7913 JM |
105 | uint32_t acr; |
106 | uint32_t bear; | |
107 | uint32_t besr; | |
108 | }; | |
109 | ||
110 | static target_ulong dcr_read_plb (void *opaque, int dcrn) | |
111 | { | |
c227f099 | 112 | ppc4xx_plb_t *plb; |
8ecc7913 JM |
113 | target_ulong ret; |
114 | ||
115 | plb = opaque; | |
116 | switch (dcrn) { | |
117 | case PLB0_ACR: | |
118 | ret = plb->acr; | |
119 | break; | |
120 | case PLB0_BEAR: | |
121 | ret = plb->bear; | |
122 | break; | |
123 | case PLB0_BESR: | |
124 | ret = plb->besr; | |
125 | break; | |
126 | default: | |
127 | /* Avoid gcc warning */ | |
128 | ret = 0; | |
129 | break; | |
130 | } | |
131 | ||
132 | return ret; | |
133 | } | |
134 | ||
135 | static void dcr_write_plb (void *opaque, int dcrn, target_ulong val) | |
136 | { | |
c227f099 | 137 | ppc4xx_plb_t *plb; |
8ecc7913 JM |
138 | |
139 | plb = opaque; | |
140 | switch (dcrn) { | |
141 | case PLB0_ACR: | |
9c02f1a2 JM |
142 | /* We don't care about the actual parameters written as |
143 | * we don't manage any priorities on the bus | |
144 | */ | |
145 | plb->acr = val & 0xF8000000; | |
8ecc7913 JM |
146 | break; |
147 | case PLB0_BEAR: | |
148 | /* Read only */ | |
149 | break; | |
150 | case PLB0_BESR: | |
151 | /* Write-clear */ | |
152 | plb->besr &= ~val; | |
153 | break; | |
154 | } | |
155 | } | |
156 | ||
157 | static void ppc4xx_plb_reset (void *opaque) | |
158 | { | |
c227f099 | 159 | ppc4xx_plb_t *plb; |
8ecc7913 JM |
160 | |
161 | plb = opaque; | |
162 | plb->acr = 0x00000000; | |
163 | plb->bear = 0x00000000; | |
164 | plb->besr = 0x00000000; | |
165 | } | |
166 | ||
802670e6 | 167 | static void ppc4xx_plb_init(CPUState *env) |
8ecc7913 | 168 | { |
c227f099 | 169 | ppc4xx_plb_t *plb; |
8ecc7913 | 170 | |
c227f099 | 171 | plb = qemu_mallocz(sizeof(ppc4xx_plb_t)); |
487414f1 AL |
172 | ppc_dcr_register(env, PLB0_ACR, plb, &dcr_read_plb, &dcr_write_plb); |
173 | ppc_dcr_register(env, PLB0_BEAR, plb, &dcr_read_plb, &dcr_write_plb); | |
174 | ppc_dcr_register(env, PLB0_BESR, plb, &dcr_read_plb, &dcr_write_plb); | |
a08d4367 | 175 | qemu_register_reset(ppc4xx_plb_reset, plb); |
8ecc7913 JM |
176 | } |
177 | ||
178 | /*****************************************************************************/ | |
179 | /* PLB to OPB bridge */ | |
180 | enum { | |
181 | POB0_BESR0 = 0x0A0, | |
182 | POB0_BESR1 = 0x0A2, | |
183 | POB0_BEAR = 0x0A4, | |
184 | }; | |
185 | ||
c227f099 AL |
186 | typedef struct ppc4xx_pob_t ppc4xx_pob_t; |
187 | struct ppc4xx_pob_t { | |
8ecc7913 JM |
188 | uint32_t bear; |
189 | uint32_t besr[2]; | |
190 | }; | |
191 | ||
192 | static target_ulong dcr_read_pob (void *opaque, int dcrn) | |
193 | { | |
c227f099 | 194 | ppc4xx_pob_t *pob; |
8ecc7913 JM |
195 | target_ulong ret; |
196 | ||
197 | pob = opaque; | |
198 | switch (dcrn) { | |
199 | case POB0_BEAR: | |
200 | ret = pob->bear; | |
201 | break; | |
202 | case POB0_BESR0: | |
203 | case POB0_BESR1: | |
204 | ret = pob->besr[dcrn - POB0_BESR0]; | |
205 | break; | |
206 | default: | |
207 | /* Avoid gcc warning */ | |
208 | ret = 0; | |
209 | break; | |
210 | } | |
211 | ||
212 | return ret; | |
213 | } | |
214 | ||
215 | static void dcr_write_pob (void *opaque, int dcrn, target_ulong val) | |
216 | { | |
c227f099 | 217 | ppc4xx_pob_t *pob; |
8ecc7913 JM |
218 | |
219 | pob = opaque; | |
220 | switch (dcrn) { | |
221 | case POB0_BEAR: | |
222 | /* Read only */ | |
223 | break; | |
224 | case POB0_BESR0: | |
225 | case POB0_BESR1: | |
226 | /* Write-clear */ | |
227 | pob->besr[dcrn - POB0_BESR0] &= ~val; | |
228 | break; | |
229 | } | |
230 | } | |
231 | ||
232 | static void ppc4xx_pob_reset (void *opaque) | |
233 | { | |
c227f099 | 234 | ppc4xx_pob_t *pob; |
8ecc7913 JM |
235 | |
236 | pob = opaque; | |
237 | /* No error */ | |
238 | pob->bear = 0x00000000; | |
239 | pob->besr[0] = 0x0000000; | |
240 | pob->besr[1] = 0x0000000; | |
241 | } | |
242 | ||
802670e6 | 243 | static void ppc4xx_pob_init(CPUState *env) |
8ecc7913 | 244 | { |
c227f099 | 245 | ppc4xx_pob_t *pob; |
8ecc7913 | 246 | |
c227f099 | 247 | pob = qemu_mallocz(sizeof(ppc4xx_pob_t)); |
487414f1 AL |
248 | ppc_dcr_register(env, POB0_BEAR, pob, &dcr_read_pob, &dcr_write_pob); |
249 | ppc_dcr_register(env, POB0_BESR0, pob, &dcr_read_pob, &dcr_write_pob); | |
250 | ppc_dcr_register(env, POB0_BESR1, pob, &dcr_read_pob, &dcr_write_pob); | |
a08d4367 | 251 | qemu_register_reset(ppc4xx_pob_reset, pob); |
8ecc7913 JM |
252 | } |
253 | ||
254 | /*****************************************************************************/ | |
255 | /* OPB arbitrer */ | |
c227f099 AL |
256 | typedef struct ppc4xx_opba_t ppc4xx_opba_t; |
257 | struct ppc4xx_opba_t { | |
8ecc7913 JM |
258 | uint8_t cr; |
259 | uint8_t pr; | |
260 | }; | |
261 | ||
c227f099 | 262 | static uint32_t opba_readb (void *opaque, target_phys_addr_t addr) |
8ecc7913 | 263 | { |
c227f099 | 264 | ppc4xx_opba_t *opba; |
8ecc7913 JM |
265 | uint32_t ret; |
266 | ||
267 | #ifdef DEBUG_OPBA | |
90e189ec | 268 | printf("%s: addr " TARGET_FMT_plx "\n", __func__, addr); |
8ecc7913 JM |
269 | #endif |
270 | opba = opaque; | |
802670e6 | 271 | switch (addr) { |
8ecc7913 JM |
272 | case 0x00: |
273 | ret = opba->cr; | |
274 | break; | |
275 | case 0x01: | |
276 | ret = opba->pr; | |
277 | break; | |
278 | default: | |
279 | ret = 0x00; | |
280 | break; | |
281 | } | |
282 | ||
283 | return ret; | |
284 | } | |
285 | ||
286 | static void opba_writeb (void *opaque, | |
c227f099 | 287 | target_phys_addr_t addr, uint32_t value) |
8ecc7913 | 288 | { |
c227f099 | 289 | ppc4xx_opba_t *opba; |
8ecc7913 JM |
290 | |
291 | #ifdef DEBUG_OPBA | |
90e189ec BS |
292 | printf("%s: addr " TARGET_FMT_plx " val %08" PRIx32 "\n", __func__, addr, |
293 | value); | |
8ecc7913 JM |
294 | #endif |
295 | opba = opaque; | |
802670e6 | 296 | switch (addr) { |
8ecc7913 JM |
297 | case 0x00: |
298 | opba->cr = value & 0xF8; | |
299 | break; | |
300 | case 0x01: | |
301 | opba->pr = value & 0xFF; | |
302 | break; | |
303 | default: | |
304 | break; | |
305 | } | |
306 | } | |
307 | ||
c227f099 | 308 | static uint32_t opba_readw (void *opaque, target_phys_addr_t addr) |
8ecc7913 JM |
309 | { |
310 | uint32_t ret; | |
311 | ||
312 | #ifdef DEBUG_OPBA | |
90e189ec | 313 | printf("%s: addr " TARGET_FMT_plx "\n", __func__, addr); |
8ecc7913 JM |
314 | #endif |
315 | ret = opba_readb(opaque, addr) << 8; | |
316 | ret |= opba_readb(opaque, addr + 1); | |
317 | ||
318 | return ret; | |
319 | } | |
320 | ||
321 | static void opba_writew (void *opaque, | |
c227f099 | 322 | target_phys_addr_t addr, uint32_t value) |
8ecc7913 JM |
323 | { |
324 | #ifdef DEBUG_OPBA | |
90e189ec BS |
325 | printf("%s: addr " TARGET_FMT_plx " val %08" PRIx32 "\n", __func__, addr, |
326 | value); | |
8ecc7913 JM |
327 | #endif |
328 | opba_writeb(opaque, addr, value >> 8); | |
329 | opba_writeb(opaque, addr + 1, value); | |
330 | } | |
331 | ||
c227f099 | 332 | static uint32_t opba_readl (void *opaque, target_phys_addr_t addr) |
8ecc7913 JM |
333 | { |
334 | uint32_t ret; | |
335 | ||
336 | #ifdef DEBUG_OPBA | |
90e189ec | 337 | printf("%s: addr " TARGET_FMT_plx "\n", __func__, addr); |
8ecc7913 JM |
338 | #endif |
339 | ret = opba_readb(opaque, addr) << 24; | |
340 | ret |= opba_readb(opaque, addr + 1) << 16; | |
341 | ||
342 | return ret; | |
343 | } | |
344 | ||
345 | static void opba_writel (void *opaque, | |
c227f099 | 346 | target_phys_addr_t addr, uint32_t value) |
8ecc7913 JM |
347 | { |
348 | #ifdef DEBUG_OPBA | |
90e189ec BS |
349 | printf("%s: addr " TARGET_FMT_plx " val %08" PRIx32 "\n", __func__, addr, |
350 | value); | |
8ecc7913 JM |
351 | #endif |
352 | opba_writeb(opaque, addr, value >> 24); | |
353 | opba_writeb(opaque, addr + 1, value >> 16); | |
354 | } | |
355 | ||
d60efc6b | 356 | static CPUReadMemoryFunc * const opba_read[] = { |
8ecc7913 JM |
357 | &opba_readb, |
358 | &opba_readw, | |
359 | &opba_readl, | |
360 | }; | |
361 | ||
d60efc6b | 362 | static CPUWriteMemoryFunc * const opba_write[] = { |
8ecc7913 JM |
363 | &opba_writeb, |
364 | &opba_writew, | |
365 | &opba_writel, | |
366 | }; | |
367 | ||
368 | static void ppc4xx_opba_reset (void *opaque) | |
369 | { | |
c227f099 | 370 | ppc4xx_opba_t *opba; |
8ecc7913 JM |
371 | |
372 | opba = opaque; | |
373 | opba->cr = 0x00; /* No dynamic priorities - park disabled */ | |
374 | opba->pr = 0x11; | |
375 | } | |
376 | ||
c227f099 | 377 | static void ppc4xx_opba_init(target_phys_addr_t base) |
8ecc7913 | 378 | { |
c227f099 | 379 | ppc4xx_opba_t *opba; |
802670e6 | 380 | int io; |
8ecc7913 | 381 | |
c227f099 | 382 | opba = qemu_mallocz(sizeof(ppc4xx_opba_t)); |
8ecc7913 | 383 | #ifdef DEBUG_OPBA |
90e189ec | 384 | printf("%s: offset " TARGET_FMT_plx "\n", __func__, base); |
8ecc7913 | 385 | #endif |
802670e6 BS |
386 | io = cpu_register_io_memory(opba_read, opba_write, opba); |
387 | cpu_register_physical_memory(base, 0x002, io); | |
802670e6 | 388 | qemu_register_reset(ppc4xx_opba_reset, opba); |
8ecc7913 JM |
389 | } |
390 | ||
8ecc7913 JM |
391 | /*****************************************************************************/ |
392 | /* Code decompression controller */ | |
393 | /* XXX: TODO */ | |
394 | ||
8ecc7913 JM |
395 | /*****************************************************************************/ |
396 | /* Peripheral controller */ | |
c227f099 AL |
397 | typedef struct ppc4xx_ebc_t ppc4xx_ebc_t; |
398 | struct ppc4xx_ebc_t { | |
8ecc7913 JM |
399 | uint32_t addr; |
400 | uint32_t bcr[8]; | |
401 | uint32_t bap[8]; | |
402 | uint32_t bear; | |
403 | uint32_t besr0; | |
404 | uint32_t besr1; | |
405 | uint32_t cfg; | |
406 | }; | |
407 | ||
408 | enum { | |
409 | EBC0_CFGADDR = 0x012, | |
410 | EBC0_CFGDATA = 0x013, | |
411 | }; | |
412 | ||
413 | static target_ulong dcr_read_ebc (void *opaque, int dcrn) | |
414 | { | |
c227f099 | 415 | ppc4xx_ebc_t *ebc; |
8ecc7913 JM |
416 | target_ulong ret; |
417 | ||
418 | ebc = opaque; | |
419 | switch (dcrn) { | |
420 | case EBC0_CFGADDR: | |
421 | ret = ebc->addr; | |
422 | break; | |
423 | case EBC0_CFGDATA: | |
424 | switch (ebc->addr) { | |
425 | case 0x00: /* B0CR */ | |
426 | ret = ebc->bcr[0]; | |
427 | break; | |
428 | case 0x01: /* B1CR */ | |
429 | ret = ebc->bcr[1]; | |
430 | break; | |
431 | case 0x02: /* B2CR */ | |
432 | ret = ebc->bcr[2]; | |
433 | break; | |
434 | case 0x03: /* B3CR */ | |
435 | ret = ebc->bcr[3]; | |
436 | break; | |
437 | case 0x04: /* B4CR */ | |
438 | ret = ebc->bcr[4]; | |
439 | break; | |
440 | case 0x05: /* B5CR */ | |
441 | ret = ebc->bcr[5]; | |
442 | break; | |
443 | case 0x06: /* B6CR */ | |
444 | ret = ebc->bcr[6]; | |
445 | break; | |
446 | case 0x07: /* B7CR */ | |
447 | ret = ebc->bcr[7]; | |
448 | break; | |
449 | case 0x10: /* B0AP */ | |
450 | ret = ebc->bap[0]; | |
451 | break; | |
452 | case 0x11: /* B1AP */ | |
453 | ret = ebc->bap[1]; | |
454 | break; | |
455 | case 0x12: /* B2AP */ | |
456 | ret = ebc->bap[2]; | |
457 | break; | |
458 | case 0x13: /* B3AP */ | |
459 | ret = ebc->bap[3]; | |
460 | break; | |
461 | case 0x14: /* B4AP */ | |
462 | ret = ebc->bap[4]; | |
463 | break; | |
464 | case 0x15: /* B5AP */ | |
465 | ret = ebc->bap[5]; | |
466 | break; | |
467 | case 0x16: /* B6AP */ | |
468 | ret = ebc->bap[6]; | |
469 | break; | |
470 | case 0x17: /* B7AP */ | |
471 | ret = ebc->bap[7]; | |
472 | break; | |
473 | case 0x20: /* BEAR */ | |
474 | ret = ebc->bear; | |
475 | break; | |
476 | case 0x21: /* BESR0 */ | |
477 | ret = ebc->besr0; | |
478 | break; | |
479 | case 0x22: /* BESR1 */ | |
480 | ret = ebc->besr1; | |
481 | break; | |
482 | case 0x23: /* CFG */ | |
483 | ret = ebc->cfg; | |
484 | break; | |
485 | default: | |
486 | ret = 0x00000000; | |
487 | break; | |
488 | } | |
489 | default: | |
490 | ret = 0x00000000; | |
491 | break; | |
492 | } | |
493 | ||
494 | return ret; | |
495 | } | |
496 | ||
497 | static void dcr_write_ebc (void *opaque, int dcrn, target_ulong val) | |
498 | { | |
c227f099 | 499 | ppc4xx_ebc_t *ebc; |
8ecc7913 JM |
500 | |
501 | ebc = opaque; | |
502 | switch (dcrn) { | |
503 | case EBC0_CFGADDR: | |
504 | ebc->addr = val; | |
505 | break; | |
506 | case EBC0_CFGDATA: | |
507 | switch (ebc->addr) { | |
508 | case 0x00: /* B0CR */ | |
509 | break; | |
510 | case 0x01: /* B1CR */ | |
511 | break; | |
512 | case 0x02: /* B2CR */ | |
513 | break; | |
514 | case 0x03: /* B3CR */ | |
515 | break; | |
516 | case 0x04: /* B4CR */ | |
517 | break; | |
518 | case 0x05: /* B5CR */ | |
519 | break; | |
520 | case 0x06: /* B6CR */ | |
521 | break; | |
522 | case 0x07: /* B7CR */ | |
523 | break; | |
524 | case 0x10: /* B0AP */ | |
525 | break; | |
526 | case 0x11: /* B1AP */ | |
527 | break; | |
528 | case 0x12: /* B2AP */ | |
529 | break; | |
530 | case 0x13: /* B3AP */ | |
531 | break; | |
532 | case 0x14: /* B4AP */ | |
533 | break; | |
534 | case 0x15: /* B5AP */ | |
535 | break; | |
536 | case 0x16: /* B6AP */ | |
537 | break; | |
538 | case 0x17: /* B7AP */ | |
539 | break; | |
540 | case 0x20: /* BEAR */ | |
541 | break; | |
542 | case 0x21: /* BESR0 */ | |
543 | break; | |
544 | case 0x22: /* BESR1 */ | |
545 | break; | |
546 | case 0x23: /* CFG */ | |
547 | break; | |
548 | default: | |
549 | break; | |
550 | } | |
551 | break; | |
552 | default: | |
553 | break; | |
554 | } | |
555 | } | |
556 | ||
557 | static void ebc_reset (void *opaque) | |
558 | { | |
c227f099 | 559 | ppc4xx_ebc_t *ebc; |
8ecc7913 JM |
560 | int i; |
561 | ||
562 | ebc = opaque; | |
563 | ebc->addr = 0x00000000; | |
564 | ebc->bap[0] = 0x7F8FFE80; | |
565 | ebc->bcr[0] = 0xFFE28000; | |
566 | for (i = 0; i < 8; i++) { | |
567 | ebc->bap[i] = 0x00000000; | |
568 | ebc->bcr[i] = 0x00000000; | |
569 | } | |
570 | ebc->besr0 = 0x00000000; | |
571 | ebc->besr1 = 0x00000000; | |
9c02f1a2 | 572 | ebc->cfg = 0x80400000; |
8ecc7913 JM |
573 | } |
574 | ||
802670e6 | 575 | static void ppc405_ebc_init(CPUState *env) |
8ecc7913 | 576 | { |
c227f099 | 577 | ppc4xx_ebc_t *ebc; |
8ecc7913 | 578 | |
c227f099 | 579 | ebc = qemu_mallocz(sizeof(ppc4xx_ebc_t)); |
a08d4367 | 580 | qemu_register_reset(&ebc_reset, ebc); |
487414f1 AL |
581 | ppc_dcr_register(env, EBC0_CFGADDR, |
582 | ebc, &dcr_read_ebc, &dcr_write_ebc); | |
583 | ppc_dcr_register(env, EBC0_CFGDATA, | |
584 | ebc, &dcr_read_ebc, &dcr_write_ebc); | |
8ecc7913 JM |
585 | } |
586 | ||
587 | /*****************************************************************************/ | |
588 | /* DMA controller */ | |
589 | enum { | |
590 | DMA0_CR0 = 0x100, | |
591 | DMA0_CT0 = 0x101, | |
592 | DMA0_DA0 = 0x102, | |
593 | DMA0_SA0 = 0x103, | |
594 | DMA0_SG0 = 0x104, | |
595 | DMA0_CR1 = 0x108, | |
596 | DMA0_CT1 = 0x109, | |
597 | DMA0_DA1 = 0x10A, | |
598 | DMA0_SA1 = 0x10B, | |
599 | DMA0_SG1 = 0x10C, | |
600 | DMA0_CR2 = 0x110, | |
601 | DMA0_CT2 = 0x111, | |
602 | DMA0_DA2 = 0x112, | |
603 | DMA0_SA2 = 0x113, | |
604 | DMA0_SG2 = 0x114, | |
605 | DMA0_CR3 = 0x118, | |
606 | DMA0_CT3 = 0x119, | |
607 | DMA0_DA3 = 0x11A, | |
608 | DMA0_SA3 = 0x11B, | |
609 | DMA0_SG3 = 0x11C, | |
610 | DMA0_SR = 0x120, | |
611 | DMA0_SGC = 0x123, | |
612 | DMA0_SLP = 0x125, | |
613 | DMA0_POL = 0x126, | |
614 | }; | |
615 | ||
c227f099 AL |
616 | typedef struct ppc405_dma_t ppc405_dma_t; |
617 | struct ppc405_dma_t { | |
8ecc7913 JM |
618 | qemu_irq irqs[4]; |
619 | uint32_t cr[4]; | |
620 | uint32_t ct[4]; | |
621 | uint32_t da[4]; | |
622 | uint32_t sa[4]; | |
623 | uint32_t sg[4]; | |
624 | uint32_t sr; | |
625 | uint32_t sgc; | |
626 | uint32_t slp; | |
627 | uint32_t pol; | |
628 | }; | |
629 | ||
630 | static target_ulong dcr_read_dma (void *opaque, int dcrn) | |
631 | { | |
c227f099 | 632 | ppc405_dma_t *dma; |
8ecc7913 JM |
633 | |
634 | dma = opaque; | |
635 | ||
636 | return 0; | |
637 | } | |
638 | ||
639 | static void dcr_write_dma (void *opaque, int dcrn, target_ulong val) | |
640 | { | |
c227f099 | 641 | ppc405_dma_t *dma; |
8ecc7913 JM |
642 | |
643 | dma = opaque; | |
644 | } | |
645 | ||
646 | static void ppc405_dma_reset (void *opaque) | |
647 | { | |
c227f099 | 648 | ppc405_dma_t *dma; |
8ecc7913 JM |
649 | int i; |
650 | ||
651 | dma = opaque; | |
652 | for (i = 0; i < 4; i++) { | |
653 | dma->cr[i] = 0x00000000; | |
654 | dma->ct[i] = 0x00000000; | |
655 | dma->da[i] = 0x00000000; | |
656 | dma->sa[i] = 0x00000000; | |
657 | dma->sg[i] = 0x00000000; | |
658 | } | |
659 | dma->sr = 0x00000000; | |
660 | dma->sgc = 0x00000000; | |
661 | dma->slp = 0x7C000000; | |
662 | dma->pol = 0x00000000; | |
663 | } | |
664 | ||
802670e6 | 665 | static void ppc405_dma_init(CPUState *env, qemu_irq irqs[4]) |
8ecc7913 | 666 | { |
c227f099 | 667 | ppc405_dma_t *dma; |
8ecc7913 | 668 | |
c227f099 | 669 | dma = qemu_mallocz(sizeof(ppc405_dma_t)); |
487414f1 | 670 | memcpy(dma->irqs, irqs, 4 * sizeof(qemu_irq)); |
a08d4367 | 671 | qemu_register_reset(&ppc405_dma_reset, dma); |
487414f1 AL |
672 | ppc_dcr_register(env, DMA0_CR0, |
673 | dma, &dcr_read_dma, &dcr_write_dma); | |
674 | ppc_dcr_register(env, DMA0_CT0, | |
675 | dma, &dcr_read_dma, &dcr_write_dma); | |
676 | ppc_dcr_register(env, DMA0_DA0, | |
677 | dma, &dcr_read_dma, &dcr_write_dma); | |
678 | ppc_dcr_register(env, DMA0_SA0, | |
679 | dma, &dcr_read_dma, &dcr_write_dma); | |
680 | ppc_dcr_register(env, DMA0_SG0, | |
681 | dma, &dcr_read_dma, &dcr_write_dma); | |
682 | ppc_dcr_register(env, DMA0_CR1, | |
683 | dma, &dcr_read_dma, &dcr_write_dma); | |
684 | ppc_dcr_register(env, DMA0_CT1, | |
685 | dma, &dcr_read_dma, &dcr_write_dma); | |
686 | ppc_dcr_register(env, DMA0_DA1, | |
687 | dma, &dcr_read_dma, &dcr_write_dma); | |
688 | ppc_dcr_register(env, DMA0_SA1, | |
689 | dma, &dcr_read_dma, &dcr_write_dma); | |
690 | ppc_dcr_register(env, DMA0_SG1, | |
691 | dma, &dcr_read_dma, &dcr_write_dma); | |
692 | ppc_dcr_register(env, DMA0_CR2, | |
693 | dma, &dcr_read_dma, &dcr_write_dma); | |
694 | ppc_dcr_register(env, DMA0_CT2, | |
695 | dma, &dcr_read_dma, &dcr_write_dma); | |
696 | ppc_dcr_register(env, DMA0_DA2, | |
697 | dma, &dcr_read_dma, &dcr_write_dma); | |
698 | ppc_dcr_register(env, DMA0_SA2, | |
699 | dma, &dcr_read_dma, &dcr_write_dma); | |
700 | ppc_dcr_register(env, DMA0_SG2, | |
701 | dma, &dcr_read_dma, &dcr_write_dma); | |
702 | ppc_dcr_register(env, DMA0_CR3, | |
703 | dma, &dcr_read_dma, &dcr_write_dma); | |
704 | ppc_dcr_register(env, DMA0_CT3, | |
705 | dma, &dcr_read_dma, &dcr_write_dma); | |
706 | ppc_dcr_register(env, DMA0_DA3, | |
707 | dma, &dcr_read_dma, &dcr_write_dma); | |
708 | ppc_dcr_register(env, DMA0_SA3, | |
709 | dma, &dcr_read_dma, &dcr_write_dma); | |
710 | ppc_dcr_register(env, DMA0_SG3, | |
711 | dma, &dcr_read_dma, &dcr_write_dma); | |
712 | ppc_dcr_register(env, DMA0_SR, | |
713 | dma, &dcr_read_dma, &dcr_write_dma); | |
714 | ppc_dcr_register(env, DMA0_SGC, | |
715 | dma, &dcr_read_dma, &dcr_write_dma); | |
716 | ppc_dcr_register(env, DMA0_SLP, | |
717 | dma, &dcr_read_dma, &dcr_write_dma); | |
718 | ppc_dcr_register(env, DMA0_POL, | |
719 | dma, &dcr_read_dma, &dcr_write_dma); | |
8ecc7913 JM |
720 | } |
721 | ||
722 | /*****************************************************************************/ | |
723 | /* GPIO */ | |
c227f099 AL |
724 | typedef struct ppc405_gpio_t ppc405_gpio_t; |
725 | struct ppc405_gpio_t { | |
8ecc7913 JM |
726 | uint32_t or; |
727 | uint32_t tcr; | |
728 | uint32_t osrh; | |
729 | uint32_t osrl; | |
730 | uint32_t tsrh; | |
731 | uint32_t tsrl; | |
732 | uint32_t odr; | |
733 | uint32_t ir; | |
734 | uint32_t rr1; | |
735 | uint32_t isr1h; | |
736 | uint32_t isr1l; | |
737 | }; | |
738 | ||
c227f099 | 739 | static uint32_t ppc405_gpio_readb (void *opaque, target_phys_addr_t addr) |
8ecc7913 | 740 | { |
c227f099 | 741 | ppc405_gpio_t *gpio; |
8ecc7913 JM |
742 | |
743 | gpio = opaque; | |
744 | #ifdef DEBUG_GPIO | |
90e189ec | 745 | printf("%s: addr " TARGET_FMT_plx "\n", __func__, addr); |
8ecc7913 JM |
746 | #endif |
747 | ||
748 | return 0; | |
749 | } | |
750 | ||
751 | static void ppc405_gpio_writeb (void *opaque, | |
c227f099 | 752 | target_phys_addr_t addr, uint32_t value) |
8ecc7913 | 753 | { |
c227f099 | 754 | ppc405_gpio_t *gpio; |
8ecc7913 JM |
755 | |
756 | gpio = opaque; | |
757 | #ifdef DEBUG_GPIO | |
90e189ec BS |
758 | printf("%s: addr " TARGET_FMT_plx " val %08" PRIx32 "\n", __func__, addr, |
759 | value); | |
8ecc7913 JM |
760 | #endif |
761 | } | |
762 | ||
c227f099 | 763 | static uint32_t ppc405_gpio_readw (void *opaque, target_phys_addr_t addr) |
8ecc7913 | 764 | { |
c227f099 | 765 | ppc405_gpio_t *gpio; |
8ecc7913 JM |
766 | |
767 | gpio = opaque; | |
768 | #ifdef DEBUG_GPIO | |
90e189ec | 769 | printf("%s: addr " TARGET_FMT_plx "\n", __func__, addr); |
8ecc7913 JM |
770 | #endif |
771 | ||
772 | return 0; | |
773 | } | |
774 | ||
775 | static void ppc405_gpio_writew (void *opaque, | |
c227f099 | 776 | target_phys_addr_t addr, uint32_t value) |
8ecc7913 | 777 | { |
c227f099 | 778 | ppc405_gpio_t *gpio; |
8ecc7913 JM |
779 | |
780 | gpio = opaque; | |
781 | #ifdef DEBUG_GPIO | |
90e189ec BS |
782 | printf("%s: addr " TARGET_FMT_plx " val %08" PRIx32 "\n", __func__, addr, |
783 | value); | |
8ecc7913 JM |
784 | #endif |
785 | } | |
786 | ||
c227f099 | 787 | static uint32_t ppc405_gpio_readl (void *opaque, target_phys_addr_t addr) |
8ecc7913 | 788 | { |
c227f099 | 789 | ppc405_gpio_t *gpio; |
8ecc7913 JM |
790 | |
791 | gpio = opaque; | |
792 | #ifdef DEBUG_GPIO | |
90e189ec | 793 | printf("%s: addr " TARGET_FMT_plx "\n", __func__, addr); |
8ecc7913 JM |
794 | #endif |
795 | ||
796 | return 0; | |
797 | } | |
798 | ||
799 | static void ppc405_gpio_writel (void *opaque, | |
c227f099 | 800 | target_phys_addr_t addr, uint32_t value) |
8ecc7913 | 801 | { |
c227f099 | 802 | ppc405_gpio_t *gpio; |
8ecc7913 JM |
803 | |
804 | gpio = opaque; | |
805 | #ifdef DEBUG_GPIO | |
90e189ec BS |
806 | printf("%s: addr " TARGET_FMT_plx " val %08" PRIx32 "\n", __func__, addr, |
807 | value); | |
8ecc7913 JM |
808 | #endif |
809 | } | |
810 | ||
d60efc6b | 811 | static CPUReadMemoryFunc * const ppc405_gpio_read[] = { |
8ecc7913 JM |
812 | &ppc405_gpio_readb, |
813 | &ppc405_gpio_readw, | |
814 | &ppc405_gpio_readl, | |
815 | }; | |
816 | ||
d60efc6b | 817 | static CPUWriteMemoryFunc * const ppc405_gpio_write[] = { |
8ecc7913 JM |
818 | &ppc405_gpio_writeb, |
819 | &ppc405_gpio_writew, | |
820 | &ppc405_gpio_writel, | |
821 | }; | |
822 | ||
823 | static void ppc405_gpio_reset (void *opaque) | |
824 | { | |
c227f099 | 825 | ppc405_gpio_t *gpio; |
8ecc7913 JM |
826 | |
827 | gpio = opaque; | |
828 | } | |
829 | ||
c227f099 | 830 | static void ppc405_gpio_init(target_phys_addr_t base) |
8ecc7913 | 831 | { |
c227f099 | 832 | ppc405_gpio_t *gpio; |
802670e6 | 833 | int io; |
8ecc7913 | 834 | |
c227f099 | 835 | gpio = qemu_mallocz(sizeof(ppc405_gpio_t)); |
8ecc7913 | 836 | #ifdef DEBUG_GPIO |
90e189ec | 837 | printf("%s: offset " TARGET_FMT_plx "\n", __func__, base); |
8ecc7913 | 838 | #endif |
802670e6 BS |
839 | io = cpu_register_io_memory(ppc405_gpio_read, ppc405_gpio_write, gpio); |
840 | cpu_register_physical_memory(base, 0x038, io); | |
802670e6 | 841 | qemu_register_reset(&ppc405_gpio_reset, gpio); |
8ecc7913 JM |
842 | } |
843 | ||
844 | /*****************************************************************************/ | |
845 | /* On Chip Memory */ | |
846 | enum { | |
847 | OCM0_ISARC = 0x018, | |
848 | OCM0_ISACNTL = 0x019, | |
849 | OCM0_DSARC = 0x01A, | |
850 | OCM0_DSACNTL = 0x01B, | |
851 | }; | |
852 | ||
c227f099 AL |
853 | typedef struct ppc405_ocm_t ppc405_ocm_t; |
854 | struct ppc405_ocm_t { | |
8ecc7913 JM |
855 | target_ulong offset; |
856 | uint32_t isarc; | |
857 | uint32_t isacntl; | |
858 | uint32_t dsarc; | |
859 | uint32_t dsacntl; | |
860 | }; | |
861 | ||
c227f099 | 862 | static void ocm_update_mappings (ppc405_ocm_t *ocm, |
8ecc7913 JM |
863 | uint32_t isarc, uint32_t isacntl, |
864 | uint32_t dsarc, uint32_t dsacntl) | |
865 | { | |
866 | #ifdef DEBUG_OCM | |
aae9366a JM |
867 | printf("OCM update ISA %08" PRIx32 " %08" PRIx32 " (%08" PRIx32 |
868 | " %08" PRIx32 ") DSA %08" PRIx32 " %08" PRIx32 | |
869 | " (%08" PRIx32 " %08" PRIx32 ")\n", | |
8ecc7913 JM |
870 | isarc, isacntl, dsarc, dsacntl, |
871 | ocm->isarc, ocm->isacntl, ocm->dsarc, ocm->dsacntl); | |
872 | #endif | |
873 | if (ocm->isarc != isarc || | |
874 | (ocm->isacntl & 0x80000000) != (isacntl & 0x80000000)) { | |
875 | if (ocm->isacntl & 0x80000000) { | |
876 | /* Unmap previously assigned memory region */ | |
aae9366a | 877 | printf("OCM unmap ISA %08" PRIx32 "\n", ocm->isarc); |
8ecc7913 JM |
878 | cpu_register_physical_memory(ocm->isarc, 0x04000000, |
879 | IO_MEM_UNASSIGNED); | |
880 | } | |
881 | if (isacntl & 0x80000000) { | |
882 | /* Map new instruction memory region */ | |
883 | #ifdef DEBUG_OCM | |
aae9366a | 884 | printf("OCM map ISA %08" PRIx32 "\n", isarc); |
8ecc7913 JM |
885 | #endif |
886 | cpu_register_physical_memory(isarc, 0x04000000, | |
887 | ocm->offset | IO_MEM_RAM); | |
888 | } | |
889 | } | |
890 | if (ocm->dsarc != dsarc || | |
891 | (ocm->dsacntl & 0x80000000) != (dsacntl & 0x80000000)) { | |
892 | if (ocm->dsacntl & 0x80000000) { | |
893 | /* Beware not to unmap the region we just mapped */ | |
894 | if (!(isacntl & 0x80000000) || ocm->dsarc != isarc) { | |
895 | /* Unmap previously assigned memory region */ | |
896 | #ifdef DEBUG_OCM | |
aae9366a | 897 | printf("OCM unmap DSA %08" PRIx32 "\n", ocm->dsarc); |
8ecc7913 JM |
898 | #endif |
899 | cpu_register_physical_memory(ocm->dsarc, 0x04000000, | |
900 | IO_MEM_UNASSIGNED); | |
901 | } | |
902 | } | |
903 | if (dsacntl & 0x80000000) { | |
904 | /* Beware not to remap the region we just mapped */ | |
905 | if (!(isacntl & 0x80000000) || dsarc != isarc) { | |
906 | /* Map new data memory region */ | |
907 | #ifdef DEBUG_OCM | |
aae9366a | 908 | printf("OCM map DSA %08" PRIx32 "\n", dsarc); |
8ecc7913 JM |
909 | #endif |
910 | cpu_register_physical_memory(dsarc, 0x04000000, | |
911 | ocm->offset | IO_MEM_RAM); | |
912 | } | |
913 | } | |
914 | } | |
915 | } | |
916 | ||
917 | static target_ulong dcr_read_ocm (void *opaque, int dcrn) | |
918 | { | |
c227f099 | 919 | ppc405_ocm_t *ocm; |
8ecc7913 JM |
920 | target_ulong ret; |
921 | ||
922 | ocm = opaque; | |
923 | switch (dcrn) { | |
924 | case OCM0_ISARC: | |
925 | ret = ocm->isarc; | |
926 | break; | |
927 | case OCM0_ISACNTL: | |
928 | ret = ocm->isacntl; | |
929 | break; | |
930 | case OCM0_DSARC: | |
931 | ret = ocm->dsarc; | |
932 | break; | |
933 | case OCM0_DSACNTL: | |
934 | ret = ocm->dsacntl; | |
935 | break; | |
936 | default: | |
937 | ret = 0; | |
938 | break; | |
939 | } | |
940 | ||
941 | return ret; | |
942 | } | |
943 | ||
944 | static void dcr_write_ocm (void *opaque, int dcrn, target_ulong val) | |
945 | { | |
c227f099 | 946 | ppc405_ocm_t *ocm; |
8ecc7913 JM |
947 | uint32_t isarc, dsarc, isacntl, dsacntl; |
948 | ||
949 | ocm = opaque; | |
950 | isarc = ocm->isarc; | |
951 | dsarc = ocm->dsarc; | |
952 | isacntl = ocm->isacntl; | |
953 | dsacntl = ocm->dsacntl; | |
954 | switch (dcrn) { | |
955 | case OCM0_ISARC: | |
956 | isarc = val & 0xFC000000; | |
957 | break; | |
958 | case OCM0_ISACNTL: | |
959 | isacntl = val & 0xC0000000; | |
960 | break; | |
961 | case OCM0_DSARC: | |
962 | isarc = val & 0xFC000000; | |
963 | break; | |
964 | case OCM0_DSACNTL: | |
965 | isacntl = val & 0xC0000000; | |
966 | break; | |
967 | } | |
968 | ocm_update_mappings(ocm, isarc, isacntl, dsarc, dsacntl); | |
969 | ocm->isarc = isarc; | |
970 | ocm->dsarc = dsarc; | |
971 | ocm->isacntl = isacntl; | |
972 | ocm->dsacntl = dsacntl; | |
973 | } | |
974 | ||
975 | static void ocm_reset (void *opaque) | |
976 | { | |
c227f099 | 977 | ppc405_ocm_t *ocm; |
8ecc7913 JM |
978 | uint32_t isarc, dsarc, isacntl, dsacntl; |
979 | ||
980 | ocm = opaque; | |
981 | isarc = 0x00000000; | |
982 | isacntl = 0x00000000; | |
983 | dsarc = 0x00000000; | |
984 | dsacntl = 0x00000000; | |
985 | ocm_update_mappings(ocm, isarc, isacntl, dsarc, dsacntl); | |
986 | ocm->isarc = isarc; | |
987 | ocm->dsarc = dsarc; | |
988 | ocm->isacntl = isacntl; | |
989 | ocm->dsacntl = dsacntl; | |
990 | } | |
991 | ||
802670e6 | 992 | static void ppc405_ocm_init(CPUState *env) |
8ecc7913 | 993 | { |
c227f099 | 994 | ppc405_ocm_t *ocm; |
8ecc7913 | 995 | |
c227f099 | 996 | ocm = qemu_mallocz(sizeof(ppc405_ocm_t)); |
5c130f65 | 997 | ocm->offset = qemu_ram_alloc(4096); |
a08d4367 | 998 | qemu_register_reset(&ocm_reset, ocm); |
487414f1 AL |
999 | ppc_dcr_register(env, OCM0_ISARC, |
1000 | ocm, &dcr_read_ocm, &dcr_write_ocm); | |
1001 | ppc_dcr_register(env, OCM0_ISACNTL, | |
1002 | ocm, &dcr_read_ocm, &dcr_write_ocm); | |
1003 | ppc_dcr_register(env, OCM0_DSARC, | |
1004 | ocm, &dcr_read_ocm, &dcr_write_ocm); | |
1005 | ppc_dcr_register(env, OCM0_DSACNTL, | |
1006 | ocm, &dcr_read_ocm, &dcr_write_ocm); | |
8ecc7913 JM |
1007 | } |
1008 | ||
1009 | /*****************************************************************************/ | |
1010 | /* I2C controller */ | |
c227f099 AL |
1011 | typedef struct ppc4xx_i2c_t ppc4xx_i2c_t; |
1012 | struct ppc4xx_i2c_t { | |
9c02f1a2 | 1013 | qemu_irq irq; |
8ecc7913 JM |
1014 | uint8_t mdata; |
1015 | uint8_t lmadr; | |
1016 | uint8_t hmadr; | |
1017 | uint8_t cntl; | |
1018 | uint8_t mdcntl; | |
1019 | uint8_t sts; | |
1020 | uint8_t extsts; | |
1021 | uint8_t sdata; | |
1022 | uint8_t lsadr; | |
1023 | uint8_t hsadr; | |
1024 | uint8_t clkdiv; | |
1025 | uint8_t intrmsk; | |
1026 | uint8_t xfrcnt; | |
1027 | uint8_t xtcntlss; | |
1028 | uint8_t directcntl; | |
1029 | }; | |
1030 | ||
c227f099 | 1031 | static uint32_t ppc4xx_i2c_readb (void *opaque, target_phys_addr_t addr) |
8ecc7913 | 1032 | { |
c227f099 | 1033 | ppc4xx_i2c_t *i2c; |
8ecc7913 JM |
1034 | uint32_t ret; |
1035 | ||
1036 | #ifdef DEBUG_I2C | |
90e189ec | 1037 | printf("%s: addr " TARGET_FMT_plx "\n", __func__, addr); |
8ecc7913 JM |
1038 | #endif |
1039 | i2c = opaque; | |
802670e6 | 1040 | switch (addr) { |
8ecc7913 JM |
1041 | case 0x00: |
1042 | // i2c_readbyte(&i2c->mdata); | |
1043 | ret = i2c->mdata; | |
1044 | break; | |
1045 | case 0x02: | |
1046 | ret = i2c->sdata; | |
1047 | break; | |
1048 | case 0x04: | |
1049 | ret = i2c->lmadr; | |
1050 | break; | |
1051 | case 0x05: | |
1052 | ret = i2c->hmadr; | |
1053 | break; | |
1054 | case 0x06: | |
1055 | ret = i2c->cntl; | |
1056 | break; | |
1057 | case 0x07: | |
1058 | ret = i2c->mdcntl; | |
1059 | break; | |
1060 | case 0x08: | |
1061 | ret = i2c->sts; | |
1062 | break; | |
1063 | case 0x09: | |
1064 | ret = i2c->extsts; | |
1065 | break; | |
1066 | case 0x0A: | |
1067 | ret = i2c->lsadr; | |
1068 | break; | |
1069 | case 0x0B: | |
1070 | ret = i2c->hsadr; | |
1071 | break; | |
1072 | case 0x0C: | |
1073 | ret = i2c->clkdiv; | |
1074 | break; | |
1075 | case 0x0D: | |
1076 | ret = i2c->intrmsk; | |
1077 | break; | |
1078 | case 0x0E: | |
1079 | ret = i2c->xfrcnt; | |
1080 | break; | |
1081 | case 0x0F: | |
1082 | ret = i2c->xtcntlss; | |
1083 | break; | |
1084 | case 0x10: | |
1085 | ret = i2c->directcntl; | |
1086 | break; | |
1087 | default: | |
1088 | ret = 0x00; | |
1089 | break; | |
1090 | } | |
1091 | #ifdef DEBUG_I2C | |
90e189ec | 1092 | printf("%s: addr " TARGET_FMT_plx " %02" PRIx32 "\n", __func__, addr, ret); |
8ecc7913 JM |
1093 | #endif |
1094 | ||
1095 | return ret; | |
1096 | } | |
1097 | ||
1098 | static void ppc4xx_i2c_writeb (void *opaque, | |
c227f099 | 1099 | target_phys_addr_t addr, uint32_t value) |
8ecc7913 | 1100 | { |
c227f099 | 1101 | ppc4xx_i2c_t *i2c; |
8ecc7913 JM |
1102 | |
1103 | #ifdef DEBUG_I2C | |
90e189ec BS |
1104 | printf("%s: addr " TARGET_FMT_plx " val %08" PRIx32 "\n", __func__, addr, |
1105 | value); | |
8ecc7913 JM |
1106 | #endif |
1107 | i2c = opaque; | |
802670e6 | 1108 | switch (addr) { |
8ecc7913 JM |
1109 | case 0x00: |
1110 | i2c->mdata = value; | |
1111 | // i2c_sendbyte(&i2c->mdata); | |
1112 | break; | |
1113 | case 0x02: | |
1114 | i2c->sdata = value; | |
1115 | break; | |
1116 | case 0x04: | |
1117 | i2c->lmadr = value; | |
1118 | break; | |
1119 | case 0x05: | |
1120 | i2c->hmadr = value; | |
1121 | break; | |
1122 | case 0x06: | |
1123 | i2c->cntl = value; | |
1124 | break; | |
1125 | case 0x07: | |
1126 | i2c->mdcntl = value & 0xDF; | |
1127 | break; | |
1128 | case 0x08: | |
1129 | i2c->sts &= ~(value & 0x0A); | |
1130 | break; | |
1131 | case 0x09: | |
1132 | i2c->extsts &= ~(value & 0x8F); | |
1133 | break; | |
1134 | case 0x0A: | |
1135 | i2c->lsadr = value; | |
1136 | break; | |
1137 | case 0x0B: | |
1138 | i2c->hsadr = value; | |
1139 | break; | |
1140 | case 0x0C: | |
1141 | i2c->clkdiv = value; | |
1142 | break; | |
1143 | case 0x0D: | |
1144 | i2c->intrmsk = value; | |
1145 | break; | |
1146 | case 0x0E: | |
1147 | i2c->xfrcnt = value & 0x77; | |
1148 | break; | |
1149 | case 0x0F: | |
1150 | i2c->xtcntlss = value; | |
1151 | break; | |
1152 | case 0x10: | |
1153 | i2c->directcntl = value & 0x7; | |
1154 | break; | |
1155 | } | |
1156 | } | |
1157 | ||
c227f099 | 1158 | static uint32_t ppc4xx_i2c_readw (void *opaque, target_phys_addr_t addr) |
8ecc7913 JM |
1159 | { |
1160 | uint32_t ret; | |
1161 | ||
1162 | #ifdef DEBUG_I2C | |
90e189ec | 1163 | printf("%s: addr " TARGET_FMT_plx "\n", __func__, addr); |
8ecc7913 JM |
1164 | #endif |
1165 | ret = ppc4xx_i2c_readb(opaque, addr) << 8; | |
1166 | ret |= ppc4xx_i2c_readb(opaque, addr + 1); | |
1167 | ||
1168 | return ret; | |
1169 | } | |
1170 | ||
1171 | static void ppc4xx_i2c_writew (void *opaque, | |
c227f099 | 1172 | target_phys_addr_t addr, uint32_t value) |
8ecc7913 JM |
1173 | { |
1174 | #ifdef DEBUG_I2C | |
90e189ec BS |
1175 | printf("%s: addr " TARGET_FMT_plx " val %08" PRIx32 "\n", __func__, addr, |
1176 | value); | |
8ecc7913 JM |
1177 | #endif |
1178 | ppc4xx_i2c_writeb(opaque, addr, value >> 8); | |
1179 | ppc4xx_i2c_writeb(opaque, addr + 1, value); | |
1180 | } | |
1181 | ||
c227f099 | 1182 | static uint32_t ppc4xx_i2c_readl (void *opaque, target_phys_addr_t addr) |
8ecc7913 JM |
1183 | { |
1184 | uint32_t ret; | |
1185 | ||
1186 | #ifdef DEBUG_I2C | |
90e189ec | 1187 | printf("%s: addr " TARGET_FMT_plx "\n", __func__, addr); |
8ecc7913 JM |
1188 | #endif |
1189 | ret = ppc4xx_i2c_readb(opaque, addr) << 24; | |
1190 | ret |= ppc4xx_i2c_readb(opaque, addr + 1) << 16; | |
1191 | ret |= ppc4xx_i2c_readb(opaque, addr + 2) << 8; | |
1192 | ret |= ppc4xx_i2c_readb(opaque, addr + 3); | |
1193 | ||
1194 | return ret; | |
1195 | } | |
1196 | ||
1197 | static void ppc4xx_i2c_writel (void *opaque, | |
c227f099 | 1198 | target_phys_addr_t addr, uint32_t value) |
8ecc7913 JM |
1199 | { |
1200 | #ifdef DEBUG_I2C | |
90e189ec BS |
1201 | printf("%s: addr " TARGET_FMT_plx " val %08" PRIx32 "\n", __func__, addr, |
1202 | value); | |
8ecc7913 JM |
1203 | #endif |
1204 | ppc4xx_i2c_writeb(opaque, addr, value >> 24); | |
1205 | ppc4xx_i2c_writeb(opaque, addr + 1, value >> 16); | |
1206 | ppc4xx_i2c_writeb(opaque, addr + 2, value >> 8); | |
1207 | ppc4xx_i2c_writeb(opaque, addr + 3, value); | |
1208 | } | |
1209 | ||
d60efc6b | 1210 | static CPUReadMemoryFunc * const i2c_read[] = { |
8ecc7913 JM |
1211 | &ppc4xx_i2c_readb, |
1212 | &ppc4xx_i2c_readw, | |
1213 | &ppc4xx_i2c_readl, | |
1214 | }; | |
1215 | ||
d60efc6b | 1216 | static CPUWriteMemoryFunc * const i2c_write[] = { |
8ecc7913 JM |
1217 | &ppc4xx_i2c_writeb, |
1218 | &ppc4xx_i2c_writew, | |
1219 | &ppc4xx_i2c_writel, | |
1220 | }; | |
1221 | ||
1222 | static void ppc4xx_i2c_reset (void *opaque) | |
1223 | { | |
c227f099 | 1224 | ppc4xx_i2c_t *i2c; |
8ecc7913 JM |
1225 | |
1226 | i2c = opaque; | |
1227 | i2c->mdata = 0x00; | |
1228 | i2c->sdata = 0x00; | |
1229 | i2c->cntl = 0x00; | |
1230 | i2c->mdcntl = 0x00; | |
1231 | i2c->sts = 0x00; | |
1232 | i2c->extsts = 0x00; | |
1233 | i2c->clkdiv = 0x00; | |
1234 | i2c->xfrcnt = 0x00; | |
1235 | i2c->directcntl = 0x0F; | |
1236 | } | |
1237 | ||
c227f099 | 1238 | static void ppc405_i2c_init(target_phys_addr_t base, qemu_irq irq) |
8ecc7913 | 1239 | { |
c227f099 | 1240 | ppc4xx_i2c_t *i2c; |
802670e6 | 1241 | int io; |
8ecc7913 | 1242 | |
c227f099 | 1243 | i2c = qemu_mallocz(sizeof(ppc4xx_i2c_t)); |
487414f1 | 1244 | i2c->irq = irq; |
8ecc7913 | 1245 | #ifdef DEBUG_I2C |
90e189ec | 1246 | printf("%s: offset " TARGET_FMT_plx "\n", __func__, base); |
8ecc7913 | 1247 | #endif |
802670e6 BS |
1248 | io = cpu_register_io_memory(i2c_read, i2c_write, i2c); |
1249 | cpu_register_physical_memory(base, 0x011, io); | |
a08d4367 | 1250 | qemu_register_reset(ppc4xx_i2c_reset, i2c); |
8ecc7913 JM |
1251 | } |
1252 | ||
9c02f1a2 JM |
1253 | /*****************************************************************************/ |
1254 | /* General purpose timers */ | |
c227f099 AL |
1255 | typedef struct ppc4xx_gpt_t ppc4xx_gpt_t; |
1256 | struct ppc4xx_gpt_t { | |
9c02f1a2 JM |
1257 | int64_t tb_offset; |
1258 | uint32_t tb_freq; | |
1259 | struct QEMUTimer *timer; | |
1260 | qemu_irq irqs[5]; | |
1261 | uint32_t oe; | |
1262 | uint32_t ol; | |
1263 | uint32_t im; | |
1264 | uint32_t is; | |
1265 | uint32_t ie; | |
1266 | uint32_t comp[5]; | |
1267 | uint32_t mask[5]; | |
1268 | }; | |
1269 | ||
c227f099 | 1270 | static uint32_t ppc4xx_gpt_readb (void *opaque, target_phys_addr_t addr) |
9c02f1a2 JM |
1271 | { |
1272 | #ifdef DEBUG_GPT | |
90e189ec | 1273 | printf("%s: addr " TARGET_FMT_plx "\n", __func__, addr); |
9c02f1a2 JM |
1274 | #endif |
1275 | /* XXX: generate a bus fault */ | |
1276 | return -1; | |
1277 | } | |
1278 | ||
1279 | static void ppc4xx_gpt_writeb (void *opaque, | |
c227f099 | 1280 | target_phys_addr_t addr, uint32_t value) |
9c02f1a2 JM |
1281 | { |
1282 | #ifdef DEBUG_I2C | |
90e189ec BS |
1283 | printf("%s: addr " TARGET_FMT_plx " val %08" PRIx32 "\n", __func__, addr, |
1284 | value); | |
9c02f1a2 JM |
1285 | #endif |
1286 | /* XXX: generate a bus fault */ | |
1287 | } | |
1288 | ||
c227f099 | 1289 | static uint32_t ppc4xx_gpt_readw (void *opaque, target_phys_addr_t addr) |
9c02f1a2 JM |
1290 | { |
1291 | #ifdef DEBUG_GPT | |
90e189ec | 1292 | printf("%s: addr " TARGET_FMT_plx "\n", __func__, addr); |
9c02f1a2 JM |
1293 | #endif |
1294 | /* XXX: generate a bus fault */ | |
1295 | return -1; | |
1296 | } | |
1297 | ||
1298 | static void ppc4xx_gpt_writew (void *opaque, | |
c227f099 | 1299 | target_phys_addr_t addr, uint32_t value) |
9c02f1a2 JM |
1300 | { |
1301 | #ifdef DEBUG_I2C | |
90e189ec BS |
1302 | printf("%s: addr " TARGET_FMT_plx " val %08" PRIx32 "\n", __func__, addr, |
1303 | value); | |
9c02f1a2 JM |
1304 | #endif |
1305 | /* XXX: generate a bus fault */ | |
1306 | } | |
1307 | ||
c227f099 | 1308 | static int ppc4xx_gpt_compare (ppc4xx_gpt_t *gpt, int n) |
9c02f1a2 JM |
1309 | { |
1310 | /* XXX: TODO */ | |
1311 | return 0; | |
1312 | } | |
1313 | ||
c227f099 | 1314 | static void ppc4xx_gpt_set_output (ppc4xx_gpt_t *gpt, int n, int level) |
9c02f1a2 JM |
1315 | { |
1316 | /* XXX: TODO */ | |
1317 | } | |
1318 | ||
c227f099 | 1319 | static void ppc4xx_gpt_set_outputs (ppc4xx_gpt_t *gpt) |
9c02f1a2 JM |
1320 | { |
1321 | uint32_t mask; | |
1322 | int i; | |
1323 | ||
1324 | mask = 0x80000000; | |
1325 | for (i = 0; i < 5; i++) { | |
1326 | if (gpt->oe & mask) { | |
1327 | /* Output is enabled */ | |
1328 | if (ppc4xx_gpt_compare(gpt, i)) { | |
1329 | /* Comparison is OK */ | |
1330 | ppc4xx_gpt_set_output(gpt, i, gpt->ol & mask); | |
1331 | } else { | |
1332 | /* Comparison is KO */ | |
1333 | ppc4xx_gpt_set_output(gpt, i, gpt->ol & mask ? 0 : 1); | |
1334 | } | |
1335 | } | |
1336 | mask = mask >> 1; | |
1337 | } | |
9c02f1a2 JM |
1338 | } |
1339 | ||
c227f099 | 1340 | static void ppc4xx_gpt_set_irqs (ppc4xx_gpt_t *gpt) |
9c02f1a2 JM |
1341 | { |
1342 | uint32_t mask; | |
1343 | int i; | |
1344 | ||
1345 | mask = 0x00008000; | |
1346 | for (i = 0; i < 5; i++) { | |
1347 | if (gpt->is & gpt->im & mask) | |
1348 | qemu_irq_raise(gpt->irqs[i]); | |
1349 | else | |
1350 | qemu_irq_lower(gpt->irqs[i]); | |
1351 | mask = mask >> 1; | |
1352 | } | |
9c02f1a2 JM |
1353 | } |
1354 | ||
c227f099 | 1355 | static void ppc4xx_gpt_compute_timer (ppc4xx_gpt_t *gpt) |
9c02f1a2 JM |
1356 | { |
1357 | /* XXX: TODO */ | |
1358 | } | |
1359 | ||
c227f099 | 1360 | static uint32_t ppc4xx_gpt_readl (void *opaque, target_phys_addr_t addr) |
9c02f1a2 | 1361 | { |
c227f099 | 1362 | ppc4xx_gpt_t *gpt; |
9c02f1a2 JM |
1363 | uint32_t ret; |
1364 | int idx; | |
1365 | ||
1366 | #ifdef DEBUG_GPT | |
90e189ec | 1367 | printf("%s: addr " TARGET_FMT_plx "\n", __func__, addr); |
9c02f1a2 JM |
1368 | #endif |
1369 | gpt = opaque; | |
802670e6 | 1370 | switch (addr) { |
9c02f1a2 JM |
1371 | case 0x00: |
1372 | /* Time base counter */ | |
1373 | ret = muldiv64(qemu_get_clock(vm_clock) + gpt->tb_offset, | |
6ee093c9 | 1374 | gpt->tb_freq, get_ticks_per_sec()); |
9c02f1a2 JM |
1375 | break; |
1376 | case 0x10: | |
1377 | /* Output enable */ | |
1378 | ret = gpt->oe; | |
1379 | break; | |
1380 | case 0x14: | |
1381 | /* Output level */ | |
1382 | ret = gpt->ol; | |
1383 | break; | |
1384 | case 0x18: | |
1385 | /* Interrupt mask */ | |
1386 | ret = gpt->im; | |
1387 | break; | |
1388 | case 0x1C: | |
1389 | case 0x20: | |
1390 | /* Interrupt status */ | |
1391 | ret = gpt->is; | |
1392 | break; | |
1393 | case 0x24: | |
1394 | /* Interrupt enable */ | |
1395 | ret = gpt->ie; | |
1396 | break; | |
1397 | case 0x80 ... 0x90: | |
1398 | /* Compare timer */ | |
802670e6 | 1399 | idx = (addr - 0x80) >> 2; |
9c02f1a2 JM |
1400 | ret = gpt->comp[idx]; |
1401 | break; | |
1402 | case 0xC0 ... 0xD0: | |
1403 | /* Compare mask */ | |
802670e6 | 1404 | idx = (addr - 0xC0) >> 2; |
9c02f1a2 JM |
1405 | ret = gpt->mask[idx]; |
1406 | break; | |
1407 | default: | |
1408 | ret = -1; | |
1409 | break; | |
1410 | } | |
1411 | ||
1412 | return ret; | |
1413 | } | |
1414 | ||
1415 | static void ppc4xx_gpt_writel (void *opaque, | |
c227f099 | 1416 | target_phys_addr_t addr, uint32_t value) |
9c02f1a2 | 1417 | { |
c227f099 | 1418 | ppc4xx_gpt_t *gpt; |
9c02f1a2 JM |
1419 | int idx; |
1420 | ||
1421 | #ifdef DEBUG_I2C | |
90e189ec BS |
1422 | printf("%s: addr " TARGET_FMT_plx " val %08" PRIx32 "\n", __func__, addr, |
1423 | value); | |
9c02f1a2 JM |
1424 | #endif |
1425 | gpt = opaque; | |
802670e6 | 1426 | switch (addr) { |
9c02f1a2 JM |
1427 | case 0x00: |
1428 | /* Time base counter */ | |
6ee093c9 | 1429 | gpt->tb_offset = muldiv64(value, get_ticks_per_sec(), gpt->tb_freq) |
9c02f1a2 JM |
1430 | - qemu_get_clock(vm_clock); |
1431 | ppc4xx_gpt_compute_timer(gpt); | |
1432 | break; | |
1433 | case 0x10: | |
1434 | /* Output enable */ | |
1435 | gpt->oe = value & 0xF8000000; | |
1436 | ppc4xx_gpt_set_outputs(gpt); | |
1437 | break; | |
1438 | case 0x14: | |
1439 | /* Output level */ | |
1440 | gpt->ol = value & 0xF8000000; | |
1441 | ppc4xx_gpt_set_outputs(gpt); | |
1442 | break; | |
1443 | case 0x18: | |
1444 | /* Interrupt mask */ | |
1445 | gpt->im = value & 0x0000F800; | |
1446 | break; | |
1447 | case 0x1C: | |
1448 | /* Interrupt status set */ | |
1449 | gpt->is |= value & 0x0000F800; | |
1450 | ppc4xx_gpt_set_irqs(gpt); | |
1451 | break; | |
1452 | case 0x20: | |
1453 | /* Interrupt status clear */ | |
1454 | gpt->is &= ~(value & 0x0000F800); | |
1455 | ppc4xx_gpt_set_irqs(gpt); | |
1456 | break; | |
1457 | case 0x24: | |
1458 | /* Interrupt enable */ | |
1459 | gpt->ie = value & 0x0000F800; | |
1460 | ppc4xx_gpt_set_irqs(gpt); | |
1461 | break; | |
1462 | case 0x80 ... 0x90: | |
1463 | /* Compare timer */ | |
802670e6 | 1464 | idx = (addr - 0x80) >> 2; |
9c02f1a2 JM |
1465 | gpt->comp[idx] = value & 0xF8000000; |
1466 | ppc4xx_gpt_compute_timer(gpt); | |
1467 | break; | |
1468 | case 0xC0 ... 0xD0: | |
1469 | /* Compare mask */ | |
802670e6 | 1470 | idx = (addr - 0xC0) >> 2; |
9c02f1a2 JM |
1471 | gpt->mask[idx] = value & 0xF8000000; |
1472 | ppc4xx_gpt_compute_timer(gpt); | |
1473 | break; | |
1474 | } | |
1475 | } | |
1476 | ||
d60efc6b | 1477 | static CPUReadMemoryFunc * const gpt_read[] = { |
9c02f1a2 JM |
1478 | &ppc4xx_gpt_readb, |
1479 | &ppc4xx_gpt_readw, | |
1480 | &ppc4xx_gpt_readl, | |
1481 | }; | |
1482 | ||
d60efc6b | 1483 | static CPUWriteMemoryFunc * const gpt_write[] = { |
9c02f1a2 JM |
1484 | &ppc4xx_gpt_writeb, |
1485 | &ppc4xx_gpt_writew, | |
1486 | &ppc4xx_gpt_writel, | |
1487 | }; | |
1488 | ||
1489 | static void ppc4xx_gpt_cb (void *opaque) | |
1490 | { | |
c227f099 | 1491 | ppc4xx_gpt_t *gpt; |
9c02f1a2 JM |
1492 | |
1493 | gpt = opaque; | |
1494 | ppc4xx_gpt_set_irqs(gpt); | |
1495 | ppc4xx_gpt_set_outputs(gpt); | |
1496 | ppc4xx_gpt_compute_timer(gpt); | |
1497 | } | |
1498 | ||
1499 | static void ppc4xx_gpt_reset (void *opaque) | |
1500 | { | |
c227f099 | 1501 | ppc4xx_gpt_t *gpt; |
9c02f1a2 JM |
1502 | int i; |
1503 | ||
1504 | gpt = opaque; | |
1505 | qemu_del_timer(gpt->timer); | |
1506 | gpt->oe = 0x00000000; | |
1507 | gpt->ol = 0x00000000; | |
1508 | gpt->im = 0x00000000; | |
1509 | gpt->is = 0x00000000; | |
1510 | gpt->ie = 0x00000000; | |
1511 | for (i = 0; i < 5; i++) { | |
1512 | gpt->comp[i] = 0x00000000; | |
1513 | gpt->mask[i] = 0x00000000; | |
1514 | } | |
1515 | } | |
1516 | ||
c227f099 | 1517 | static void ppc4xx_gpt_init(target_phys_addr_t base, qemu_irq irqs[5]) |
9c02f1a2 | 1518 | { |
c227f099 | 1519 | ppc4xx_gpt_t *gpt; |
9c02f1a2 | 1520 | int i; |
802670e6 | 1521 | int io; |
9c02f1a2 | 1522 | |
c227f099 | 1523 | gpt = qemu_mallocz(sizeof(ppc4xx_gpt_t)); |
802670e6 | 1524 | for (i = 0; i < 5; i++) { |
487414f1 | 1525 | gpt->irqs[i] = irqs[i]; |
802670e6 | 1526 | } |
487414f1 | 1527 | gpt->timer = qemu_new_timer(vm_clock, &ppc4xx_gpt_cb, gpt); |
9c02f1a2 | 1528 | #ifdef DEBUG_GPT |
90e189ec | 1529 | printf("%s: offset " TARGET_FMT_plx "\n", __func__, base); |
9c02f1a2 | 1530 | #endif |
802670e6 BS |
1531 | io = cpu_register_io_memory(gpt_read, gpt_write, gpt); |
1532 | cpu_register_physical_memory(base, 0x0d4, io); | |
a08d4367 | 1533 | qemu_register_reset(ppc4xx_gpt_reset, gpt); |
9c02f1a2 JM |
1534 | } |
1535 | ||
1536 | /*****************************************************************************/ | |
1537 | /* MAL */ | |
1538 | enum { | |
1539 | MAL0_CFG = 0x180, | |
1540 | MAL0_ESR = 0x181, | |
1541 | MAL0_IER = 0x182, | |
1542 | MAL0_TXCASR = 0x184, | |
1543 | MAL0_TXCARR = 0x185, | |
1544 | MAL0_TXEOBISR = 0x186, | |
1545 | MAL0_TXDEIR = 0x187, | |
1546 | MAL0_RXCASR = 0x190, | |
1547 | MAL0_RXCARR = 0x191, | |
1548 | MAL0_RXEOBISR = 0x192, | |
1549 | MAL0_RXDEIR = 0x193, | |
1550 | MAL0_TXCTP0R = 0x1A0, | |
1551 | MAL0_TXCTP1R = 0x1A1, | |
1552 | MAL0_TXCTP2R = 0x1A2, | |
1553 | MAL0_TXCTP3R = 0x1A3, | |
1554 | MAL0_RXCTP0R = 0x1C0, | |
1555 | MAL0_RXCTP1R = 0x1C1, | |
1556 | MAL0_RCBS0 = 0x1E0, | |
1557 | MAL0_RCBS1 = 0x1E1, | |
1558 | }; | |
1559 | ||
c227f099 AL |
1560 | typedef struct ppc40x_mal_t ppc40x_mal_t; |
1561 | struct ppc40x_mal_t { | |
9c02f1a2 JM |
1562 | qemu_irq irqs[4]; |
1563 | uint32_t cfg; | |
1564 | uint32_t esr; | |
1565 | uint32_t ier; | |
1566 | uint32_t txcasr; | |
1567 | uint32_t txcarr; | |
1568 | uint32_t txeobisr; | |
1569 | uint32_t txdeir; | |
1570 | uint32_t rxcasr; | |
1571 | uint32_t rxcarr; | |
1572 | uint32_t rxeobisr; | |
1573 | uint32_t rxdeir; | |
1574 | uint32_t txctpr[4]; | |
1575 | uint32_t rxctpr[2]; | |
1576 | uint32_t rcbs[2]; | |
1577 | }; | |
1578 | ||
1579 | static void ppc40x_mal_reset (void *opaque); | |
1580 | ||
1581 | static target_ulong dcr_read_mal (void *opaque, int dcrn) | |
1582 | { | |
c227f099 | 1583 | ppc40x_mal_t *mal; |
9c02f1a2 JM |
1584 | target_ulong ret; |
1585 | ||
1586 | mal = opaque; | |
1587 | switch (dcrn) { | |
1588 | case MAL0_CFG: | |
1589 | ret = mal->cfg; | |
1590 | break; | |
1591 | case MAL0_ESR: | |
1592 | ret = mal->esr; | |
1593 | break; | |
1594 | case MAL0_IER: | |
1595 | ret = mal->ier; | |
1596 | break; | |
1597 | case MAL0_TXCASR: | |
1598 | ret = mal->txcasr; | |
1599 | break; | |
1600 | case MAL0_TXCARR: | |
1601 | ret = mal->txcarr; | |
1602 | break; | |
1603 | case MAL0_TXEOBISR: | |
1604 | ret = mal->txeobisr; | |
1605 | break; | |
1606 | case MAL0_TXDEIR: | |
1607 | ret = mal->txdeir; | |
1608 | break; | |
1609 | case MAL0_RXCASR: | |
1610 | ret = mal->rxcasr; | |
1611 | break; | |
1612 | case MAL0_RXCARR: | |
1613 | ret = mal->rxcarr; | |
1614 | break; | |
1615 | case MAL0_RXEOBISR: | |
1616 | ret = mal->rxeobisr; | |
1617 | break; | |
1618 | case MAL0_RXDEIR: | |
1619 | ret = mal->rxdeir; | |
1620 | break; | |
1621 | case MAL0_TXCTP0R: | |
1622 | ret = mal->txctpr[0]; | |
1623 | break; | |
1624 | case MAL0_TXCTP1R: | |
1625 | ret = mal->txctpr[1]; | |
1626 | break; | |
1627 | case MAL0_TXCTP2R: | |
1628 | ret = mal->txctpr[2]; | |
1629 | break; | |
1630 | case MAL0_TXCTP3R: | |
1631 | ret = mal->txctpr[3]; | |
1632 | break; | |
1633 | case MAL0_RXCTP0R: | |
1634 | ret = mal->rxctpr[0]; | |
1635 | break; | |
1636 | case MAL0_RXCTP1R: | |
1637 | ret = mal->rxctpr[1]; | |
1638 | break; | |
1639 | case MAL0_RCBS0: | |
1640 | ret = mal->rcbs[0]; | |
1641 | break; | |
1642 | case MAL0_RCBS1: | |
1643 | ret = mal->rcbs[1]; | |
1644 | break; | |
1645 | default: | |
1646 | ret = 0; | |
1647 | break; | |
1648 | } | |
1649 | ||
1650 | return ret; | |
1651 | } | |
1652 | ||
1653 | static void dcr_write_mal (void *opaque, int dcrn, target_ulong val) | |
1654 | { | |
c227f099 | 1655 | ppc40x_mal_t *mal; |
9c02f1a2 JM |
1656 | int idx; |
1657 | ||
1658 | mal = opaque; | |
1659 | switch (dcrn) { | |
1660 | case MAL0_CFG: | |
1661 | if (val & 0x80000000) | |
1662 | ppc40x_mal_reset(mal); | |
1663 | mal->cfg = val & 0x00FFC087; | |
1664 | break; | |
1665 | case MAL0_ESR: | |
1666 | /* Read/clear */ | |
1667 | mal->esr &= ~val; | |
1668 | break; | |
1669 | case MAL0_IER: | |
1670 | mal->ier = val & 0x0000001F; | |
1671 | break; | |
1672 | case MAL0_TXCASR: | |
1673 | mal->txcasr = val & 0xF0000000; | |
1674 | break; | |
1675 | case MAL0_TXCARR: | |
1676 | mal->txcarr = val & 0xF0000000; | |
1677 | break; | |
1678 | case MAL0_TXEOBISR: | |
1679 | /* Read/clear */ | |
1680 | mal->txeobisr &= ~val; | |
1681 | break; | |
1682 | case MAL0_TXDEIR: | |
1683 | /* Read/clear */ | |
1684 | mal->txdeir &= ~val; | |
1685 | break; | |
1686 | case MAL0_RXCASR: | |
1687 | mal->rxcasr = val & 0xC0000000; | |
1688 | break; | |
1689 | case MAL0_RXCARR: | |
1690 | mal->rxcarr = val & 0xC0000000; | |
1691 | break; | |
1692 | case MAL0_RXEOBISR: | |
1693 | /* Read/clear */ | |
1694 | mal->rxeobisr &= ~val; | |
1695 | break; | |
1696 | case MAL0_RXDEIR: | |
1697 | /* Read/clear */ | |
1698 | mal->rxdeir &= ~val; | |
1699 | break; | |
1700 | case MAL0_TXCTP0R: | |
1701 | idx = 0; | |
1702 | goto update_tx_ptr; | |
1703 | case MAL0_TXCTP1R: | |
1704 | idx = 1; | |
1705 | goto update_tx_ptr; | |
1706 | case MAL0_TXCTP2R: | |
1707 | idx = 2; | |
1708 | goto update_tx_ptr; | |
1709 | case MAL0_TXCTP3R: | |
1710 | idx = 3; | |
1711 | update_tx_ptr: | |
1712 | mal->txctpr[idx] = val; | |
1713 | break; | |
1714 | case MAL0_RXCTP0R: | |
1715 | idx = 0; | |
1716 | goto update_rx_ptr; | |
1717 | case MAL0_RXCTP1R: | |
1718 | idx = 1; | |
1719 | update_rx_ptr: | |
1720 | mal->rxctpr[idx] = val; | |
1721 | break; | |
1722 | case MAL0_RCBS0: | |
1723 | idx = 0; | |
1724 | goto update_rx_size; | |
1725 | case MAL0_RCBS1: | |
1726 | idx = 1; | |
1727 | update_rx_size: | |
1728 | mal->rcbs[idx] = val & 0x000000FF; | |
1729 | break; | |
1730 | } | |
1731 | } | |
1732 | ||
1733 | static void ppc40x_mal_reset (void *opaque) | |
1734 | { | |
c227f099 | 1735 | ppc40x_mal_t *mal; |
9c02f1a2 JM |
1736 | |
1737 | mal = opaque; | |
1738 | mal->cfg = 0x0007C000; | |
1739 | mal->esr = 0x00000000; | |
1740 | mal->ier = 0x00000000; | |
1741 | mal->rxcasr = 0x00000000; | |
1742 | mal->rxdeir = 0x00000000; | |
1743 | mal->rxeobisr = 0x00000000; | |
1744 | mal->txcasr = 0x00000000; | |
1745 | mal->txdeir = 0x00000000; | |
1746 | mal->txeobisr = 0x00000000; | |
1747 | } | |
1748 | ||
802670e6 | 1749 | static void ppc405_mal_init(CPUState *env, qemu_irq irqs[4]) |
9c02f1a2 | 1750 | { |
c227f099 | 1751 | ppc40x_mal_t *mal; |
9c02f1a2 JM |
1752 | int i; |
1753 | ||
c227f099 | 1754 | mal = qemu_mallocz(sizeof(ppc40x_mal_t)); |
487414f1 AL |
1755 | for (i = 0; i < 4; i++) |
1756 | mal->irqs[i] = irqs[i]; | |
a08d4367 | 1757 | qemu_register_reset(&ppc40x_mal_reset, mal); |
487414f1 AL |
1758 | ppc_dcr_register(env, MAL0_CFG, |
1759 | mal, &dcr_read_mal, &dcr_write_mal); | |
1760 | ppc_dcr_register(env, MAL0_ESR, | |
1761 | mal, &dcr_read_mal, &dcr_write_mal); | |
1762 | ppc_dcr_register(env, MAL0_IER, | |
1763 | mal, &dcr_read_mal, &dcr_write_mal); | |
1764 | ppc_dcr_register(env, MAL0_TXCASR, | |
1765 | mal, &dcr_read_mal, &dcr_write_mal); | |
1766 | ppc_dcr_register(env, MAL0_TXCARR, | |
1767 | mal, &dcr_read_mal, &dcr_write_mal); | |
1768 | ppc_dcr_register(env, MAL0_TXEOBISR, | |
1769 | mal, &dcr_read_mal, &dcr_write_mal); | |
1770 | ppc_dcr_register(env, MAL0_TXDEIR, | |
1771 | mal, &dcr_read_mal, &dcr_write_mal); | |
1772 | ppc_dcr_register(env, MAL0_RXCASR, | |
1773 | mal, &dcr_read_mal, &dcr_write_mal); | |
1774 | ppc_dcr_register(env, MAL0_RXCARR, | |
1775 | mal, &dcr_read_mal, &dcr_write_mal); | |
1776 | ppc_dcr_register(env, MAL0_RXEOBISR, | |
1777 | mal, &dcr_read_mal, &dcr_write_mal); | |
1778 | ppc_dcr_register(env, MAL0_RXDEIR, | |
1779 | mal, &dcr_read_mal, &dcr_write_mal); | |
1780 | ppc_dcr_register(env, MAL0_TXCTP0R, | |
1781 | mal, &dcr_read_mal, &dcr_write_mal); | |
1782 | ppc_dcr_register(env, MAL0_TXCTP1R, | |
1783 | mal, &dcr_read_mal, &dcr_write_mal); | |
1784 | ppc_dcr_register(env, MAL0_TXCTP2R, | |
1785 | mal, &dcr_read_mal, &dcr_write_mal); | |
1786 | ppc_dcr_register(env, MAL0_TXCTP3R, | |
1787 | mal, &dcr_read_mal, &dcr_write_mal); | |
1788 | ppc_dcr_register(env, MAL0_RXCTP0R, | |
1789 | mal, &dcr_read_mal, &dcr_write_mal); | |
1790 | ppc_dcr_register(env, MAL0_RXCTP1R, | |
1791 | mal, &dcr_read_mal, &dcr_write_mal); | |
1792 | ppc_dcr_register(env, MAL0_RCBS0, | |
1793 | mal, &dcr_read_mal, &dcr_write_mal); | |
1794 | ppc_dcr_register(env, MAL0_RCBS1, | |
1795 | mal, &dcr_read_mal, &dcr_write_mal); | |
9c02f1a2 JM |
1796 | } |
1797 | ||
8ecc7913 JM |
1798 | /*****************************************************************************/ |
1799 | /* SPR */ | |
1800 | void ppc40x_core_reset (CPUState *env) | |
1801 | { | |
1802 | target_ulong dbsr; | |
1803 | ||
1804 | printf("Reset PowerPC core\n"); | |
ef397e88 JM |
1805 | env->interrupt_request |= CPU_INTERRUPT_EXITTB; |
1806 | /* XXX: TOFIX */ | |
1807 | #if 0 | |
d84bda46 | 1808 | cpu_reset(env); |
ef397e88 JM |
1809 | #else |
1810 | qemu_system_reset_request(); | |
1811 | #endif | |
8ecc7913 JM |
1812 | dbsr = env->spr[SPR_40x_DBSR]; |
1813 | dbsr &= ~0x00000300; | |
1814 | dbsr |= 0x00000100; | |
1815 | env->spr[SPR_40x_DBSR] = dbsr; | |
8ecc7913 JM |
1816 | } |
1817 | ||
1818 | void ppc40x_chip_reset (CPUState *env) | |
1819 | { | |
1820 | target_ulong dbsr; | |
1821 | ||
1822 | printf("Reset PowerPC chip\n"); | |
ef397e88 JM |
1823 | env->interrupt_request |= CPU_INTERRUPT_EXITTB; |
1824 | /* XXX: TOFIX */ | |
1825 | #if 0 | |
d84bda46 | 1826 | cpu_reset(env); |
ef397e88 JM |
1827 | #else |
1828 | qemu_system_reset_request(); | |
1829 | #endif | |
8ecc7913 JM |
1830 | /* XXX: TODO reset all internal peripherals */ |
1831 | dbsr = env->spr[SPR_40x_DBSR]; | |
1832 | dbsr &= ~0x00000300; | |
04f20795 | 1833 | dbsr |= 0x00000200; |
8ecc7913 | 1834 | env->spr[SPR_40x_DBSR] = dbsr; |
8ecc7913 JM |
1835 | } |
1836 | ||
1837 | void ppc40x_system_reset (CPUState *env) | |
1838 | { | |
1839 | printf("Reset PowerPC system\n"); | |
1840 | qemu_system_reset_request(); | |
1841 | } | |
1842 | ||
1843 | void store_40x_dbcr0 (CPUState *env, uint32_t val) | |
1844 | { | |
1845 | switch ((val >> 28) & 0x3) { | |
1846 | case 0x0: | |
1847 | /* No action */ | |
1848 | break; | |
1849 | case 0x1: | |
1850 | /* Core reset */ | |
1851 | ppc40x_core_reset(env); | |
1852 | break; | |
1853 | case 0x2: | |
1854 | /* Chip reset */ | |
1855 | ppc40x_chip_reset(env); | |
1856 | break; | |
1857 | case 0x3: | |
1858 | /* System reset */ | |
1859 | ppc40x_system_reset(env); | |
1860 | break; | |
1861 | } | |
1862 | } | |
1863 | ||
1864 | /*****************************************************************************/ | |
1865 | /* PowerPC 405CR */ | |
1866 | enum { | |
1867 | PPC405CR_CPC0_PLLMR = 0x0B0, | |
1868 | PPC405CR_CPC0_CR0 = 0x0B1, | |
1869 | PPC405CR_CPC0_CR1 = 0x0B2, | |
1870 | PPC405CR_CPC0_PSR = 0x0B4, | |
1871 | PPC405CR_CPC0_JTAGID = 0x0B5, | |
1872 | PPC405CR_CPC0_ER = 0x0B9, | |
1873 | PPC405CR_CPC0_FR = 0x0BA, | |
1874 | PPC405CR_CPC0_SR = 0x0BB, | |
1875 | }; | |
1876 | ||
04f20795 JM |
1877 | enum { |
1878 | PPC405CR_CPU_CLK = 0, | |
1879 | PPC405CR_TMR_CLK = 1, | |
1880 | PPC405CR_PLB_CLK = 2, | |
1881 | PPC405CR_SDRAM_CLK = 3, | |
1882 | PPC405CR_OPB_CLK = 4, | |
1883 | PPC405CR_EXT_CLK = 5, | |
1884 | PPC405CR_UART_CLK = 6, | |
1885 | PPC405CR_CLK_NB = 7, | |
1886 | }; | |
1887 | ||
c227f099 AL |
1888 | typedef struct ppc405cr_cpc_t ppc405cr_cpc_t; |
1889 | struct ppc405cr_cpc_t { | |
1890 | clk_setup_t clk_setup[PPC405CR_CLK_NB]; | |
8ecc7913 JM |
1891 | uint32_t sysclk; |
1892 | uint32_t psr; | |
1893 | uint32_t cr0; | |
1894 | uint32_t cr1; | |
1895 | uint32_t jtagid; | |
1896 | uint32_t pllmr; | |
1897 | uint32_t er; | |
1898 | uint32_t fr; | |
1899 | }; | |
1900 | ||
c227f099 | 1901 | static void ppc405cr_clk_setup (ppc405cr_cpc_t *cpc) |
8ecc7913 JM |
1902 | { |
1903 | uint64_t VCO_out, PLL_out; | |
1904 | uint32_t CPU_clk, TMR_clk, SDRAM_clk, PLB_clk, OPB_clk, EXT_clk, UART_clk; | |
1905 | int M, D0, D1, D2; | |
1906 | ||
1907 | D0 = ((cpc->pllmr >> 26) & 0x3) + 1; /* CBDV */ | |
1908 | if (cpc->pllmr & 0x80000000) { | |
1909 | D1 = (((cpc->pllmr >> 20) - 1) & 0xF) + 1; /* FBDV */ | |
1910 | D2 = 8 - ((cpc->pllmr >> 16) & 0x7); /* FWDVA */ | |
1911 | M = D0 * D1 * D2; | |
1912 | VCO_out = cpc->sysclk * M; | |
1913 | if (VCO_out < 400000000 || VCO_out > 800000000) { | |
1914 | /* PLL cannot lock */ | |
1915 | cpc->pllmr &= ~0x80000000; | |
1916 | goto bypass_pll; | |
1917 | } | |
1918 | PLL_out = VCO_out / D2; | |
1919 | } else { | |
1920 | /* Bypass PLL */ | |
1921 | bypass_pll: | |
1922 | M = D0; | |
1923 | PLL_out = cpc->sysclk * M; | |
1924 | } | |
1925 | CPU_clk = PLL_out; | |
1926 | if (cpc->cr1 & 0x00800000) | |
1927 | TMR_clk = cpc->sysclk; /* Should have a separate clock */ | |
1928 | else | |
1929 | TMR_clk = CPU_clk; | |
1930 | PLB_clk = CPU_clk / D0; | |
1931 | SDRAM_clk = PLB_clk; | |
1932 | D0 = ((cpc->pllmr >> 10) & 0x3) + 1; | |
1933 | OPB_clk = PLB_clk / D0; | |
1934 | D0 = ((cpc->pllmr >> 24) & 0x3) + 2; | |
1935 | EXT_clk = PLB_clk / D0; | |
1936 | D0 = ((cpc->cr0 >> 1) & 0x1F) + 1; | |
1937 | UART_clk = CPU_clk / D0; | |
1938 | /* Setup CPU clocks */ | |
04f20795 | 1939 | clk_setup(&cpc->clk_setup[PPC405CR_CPU_CLK], CPU_clk); |
8ecc7913 | 1940 | /* Setup time-base clock */ |
04f20795 | 1941 | clk_setup(&cpc->clk_setup[PPC405CR_TMR_CLK], TMR_clk); |
8ecc7913 | 1942 | /* Setup PLB clock */ |
04f20795 | 1943 | clk_setup(&cpc->clk_setup[PPC405CR_PLB_CLK], PLB_clk); |
8ecc7913 | 1944 | /* Setup SDRAM clock */ |
04f20795 | 1945 | clk_setup(&cpc->clk_setup[PPC405CR_SDRAM_CLK], SDRAM_clk); |
8ecc7913 | 1946 | /* Setup OPB clock */ |
04f20795 | 1947 | clk_setup(&cpc->clk_setup[PPC405CR_OPB_CLK], OPB_clk); |
8ecc7913 | 1948 | /* Setup external clock */ |
04f20795 | 1949 | clk_setup(&cpc->clk_setup[PPC405CR_EXT_CLK], EXT_clk); |
8ecc7913 | 1950 | /* Setup UART clock */ |
04f20795 | 1951 | clk_setup(&cpc->clk_setup[PPC405CR_UART_CLK], UART_clk); |
8ecc7913 JM |
1952 | } |
1953 | ||
1954 | static target_ulong dcr_read_crcpc (void *opaque, int dcrn) | |
1955 | { | |
c227f099 | 1956 | ppc405cr_cpc_t *cpc; |
8ecc7913 JM |
1957 | target_ulong ret; |
1958 | ||
1959 | cpc = opaque; | |
1960 | switch (dcrn) { | |
1961 | case PPC405CR_CPC0_PLLMR: | |
1962 | ret = cpc->pllmr; | |
1963 | break; | |
1964 | case PPC405CR_CPC0_CR0: | |
1965 | ret = cpc->cr0; | |
1966 | break; | |
1967 | case PPC405CR_CPC0_CR1: | |
1968 | ret = cpc->cr1; | |
1969 | break; | |
1970 | case PPC405CR_CPC0_PSR: | |
1971 | ret = cpc->psr; | |
1972 | break; | |
1973 | case PPC405CR_CPC0_JTAGID: | |
1974 | ret = cpc->jtagid; | |
1975 | break; | |
1976 | case PPC405CR_CPC0_ER: | |
1977 | ret = cpc->er; | |
1978 | break; | |
1979 | case PPC405CR_CPC0_FR: | |
1980 | ret = cpc->fr; | |
1981 | break; | |
1982 | case PPC405CR_CPC0_SR: | |
1983 | ret = ~(cpc->er | cpc->fr) & 0xFFFF0000; | |
1984 | break; | |
1985 | default: | |
1986 | /* Avoid gcc warning */ | |
1987 | ret = 0; | |
1988 | break; | |
1989 | } | |
1990 | ||
1991 | return ret; | |
1992 | } | |
1993 | ||
1994 | static void dcr_write_crcpc (void *opaque, int dcrn, target_ulong val) | |
1995 | { | |
c227f099 | 1996 | ppc405cr_cpc_t *cpc; |
8ecc7913 JM |
1997 | |
1998 | cpc = opaque; | |
1999 | switch (dcrn) { | |
2000 | case PPC405CR_CPC0_PLLMR: | |
2001 | cpc->pllmr = val & 0xFFF77C3F; | |
2002 | break; | |
2003 | case PPC405CR_CPC0_CR0: | |
2004 | cpc->cr0 = val & 0x0FFFFFFE; | |
2005 | break; | |
2006 | case PPC405CR_CPC0_CR1: | |
2007 | cpc->cr1 = val & 0x00800000; | |
2008 | break; | |
2009 | case PPC405CR_CPC0_PSR: | |
2010 | /* Read-only */ | |
2011 | break; | |
2012 | case PPC405CR_CPC0_JTAGID: | |
2013 | /* Read-only */ | |
2014 | break; | |
2015 | case PPC405CR_CPC0_ER: | |
2016 | cpc->er = val & 0xBFFC0000; | |
2017 | break; | |
2018 | case PPC405CR_CPC0_FR: | |
2019 | cpc->fr = val & 0xBFFC0000; | |
2020 | break; | |
2021 | case PPC405CR_CPC0_SR: | |
2022 | /* Read-only */ | |
2023 | break; | |
2024 | } | |
2025 | } | |
2026 | ||
2027 | static void ppc405cr_cpc_reset (void *opaque) | |
2028 | { | |
c227f099 | 2029 | ppc405cr_cpc_t *cpc; |
8ecc7913 JM |
2030 | int D; |
2031 | ||
2032 | cpc = opaque; | |
2033 | /* Compute PLLMR value from PSR settings */ | |
2034 | cpc->pllmr = 0x80000000; | |
2035 | /* PFWD */ | |
2036 | switch ((cpc->psr >> 30) & 3) { | |
2037 | case 0: | |
2038 | /* Bypass */ | |
2039 | cpc->pllmr &= ~0x80000000; | |
2040 | break; | |
2041 | case 1: | |
2042 | /* Divide by 3 */ | |
2043 | cpc->pllmr |= 5 << 16; | |
2044 | break; | |
2045 | case 2: | |
2046 | /* Divide by 4 */ | |
2047 | cpc->pllmr |= 4 << 16; | |
2048 | break; | |
2049 | case 3: | |
2050 | /* Divide by 6 */ | |
2051 | cpc->pllmr |= 2 << 16; | |
2052 | break; | |
2053 | } | |
2054 | /* PFBD */ | |
2055 | D = (cpc->psr >> 28) & 3; | |
2056 | cpc->pllmr |= (D + 1) << 20; | |
2057 | /* PT */ | |
2058 | D = (cpc->psr >> 25) & 7; | |
2059 | switch (D) { | |
2060 | case 0x2: | |
2061 | cpc->pllmr |= 0x13; | |
2062 | break; | |
2063 | case 0x4: | |
2064 | cpc->pllmr |= 0x15; | |
2065 | break; | |
2066 | case 0x5: | |
2067 | cpc->pllmr |= 0x16; | |
2068 | break; | |
2069 | default: | |
2070 | break; | |
2071 | } | |
2072 | /* PDC */ | |
2073 | D = (cpc->psr >> 23) & 3; | |
2074 | cpc->pllmr |= D << 26; | |
2075 | /* ODP */ | |
2076 | D = (cpc->psr >> 21) & 3; | |
2077 | cpc->pllmr |= D << 10; | |
2078 | /* EBPD */ | |
2079 | D = (cpc->psr >> 17) & 3; | |
2080 | cpc->pllmr |= D << 24; | |
2081 | cpc->cr0 = 0x0000003C; | |
2082 | cpc->cr1 = 0x2B0D8800; | |
2083 | cpc->er = 0x00000000; | |
2084 | cpc->fr = 0x00000000; | |
2085 | ppc405cr_clk_setup(cpc); | |
2086 | } | |
2087 | ||
c227f099 | 2088 | static void ppc405cr_clk_init (ppc405cr_cpc_t *cpc) |
8ecc7913 JM |
2089 | { |
2090 | int D; | |
2091 | ||
2092 | /* XXX: this should be read from IO pins */ | |
2093 | cpc->psr = 0x00000000; /* 8 bits ROM */ | |
2094 | /* PFWD */ | |
2095 | D = 0x2; /* Divide by 4 */ | |
2096 | cpc->psr |= D << 30; | |
2097 | /* PFBD */ | |
2098 | D = 0x1; /* Divide by 2 */ | |
2099 | cpc->psr |= D << 28; | |
2100 | /* PDC */ | |
2101 | D = 0x1; /* Divide by 2 */ | |
2102 | cpc->psr |= D << 23; | |
2103 | /* PT */ | |
2104 | D = 0x5; /* M = 16 */ | |
2105 | cpc->psr |= D << 25; | |
2106 | /* ODP */ | |
2107 | D = 0x1; /* Divide by 2 */ | |
2108 | cpc->psr |= D << 21; | |
2109 | /* EBDP */ | |
2110 | D = 0x2; /* Divide by 4 */ | |
2111 | cpc->psr |= D << 17; | |
2112 | } | |
2113 | ||
c227f099 | 2114 | static void ppc405cr_cpc_init (CPUState *env, clk_setup_t clk_setup[7], |
8ecc7913 JM |
2115 | uint32_t sysclk) |
2116 | { | |
c227f099 | 2117 | ppc405cr_cpc_t *cpc; |
8ecc7913 | 2118 | |
c227f099 | 2119 | cpc = qemu_mallocz(sizeof(ppc405cr_cpc_t)); |
487414f1 | 2120 | memcpy(cpc->clk_setup, clk_setup, |
c227f099 | 2121 | PPC405CR_CLK_NB * sizeof(clk_setup_t)); |
487414f1 AL |
2122 | cpc->sysclk = sysclk; |
2123 | cpc->jtagid = 0x42051049; | |
2124 | ppc_dcr_register(env, PPC405CR_CPC0_PSR, cpc, | |
2125 | &dcr_read_crcpc, &dcr_write_crcpc); | |
2126 | ppc_dcr_register(env, PPC405CR_CPC0_CR0, cpc, | |
2127 | &dcr_read_crcpc, &dcr_write_crcpc); | |
2128 | ppc_dcr_register(env, PPC405CR_CPC0_CR1, cpc, | |
2129 | &dcr_read_crcpc, &dcr_write_crcpc); | |
2130 | ppc_dcr_register(env, PPC405CR_CPC0_JTAGID, cpc, | |
2131 | &dcr_read_crcpc, &dcr_write_crcpc); | |
2132 | ppc_dcr_register(env, PPC405CR_CPC0_PLLMR, cpc, | |
2133 | &dcr_read_crcpc, &dcr_write_crcpc); | |
2134 | ppc_dcr_register(env, PPC405CR_CPC0_ER, cpc, | |
2135 | &dcr_read_crcpc, &dcr_write_crcpc); | |
2136 | ppc_dcr_register(env, PPC405CR_CPC0_FR, cpc, | |
2137 | &dcr_read_crcpc, &dcr_write_crcpc); | |
2138 | ppc_dcr_register(env, PPC405CR_CPC0_SR, cpc, | |
2139 | &dcr_read_crcpc, &dcr_write_crcpc); | |
2140 | ppc405cr_clk_init(cpc); | |
a08d4367 | 2141 | qemu_register_reset(ppc405cr_cpc_reset, cpc); |
8ecc7913 JM |
2142 | } |
2143 | ||
c227f099 AL |
2144 | CPUState *ppc405cr_init (target_phys_addr_t ram_bases[4], |
2145 | target_phys_addr_t ram_sizes[4], | |
8ecc7913 | 2146 | uint32_t sysclk, qemu_irq **picp, |
5c130f65 | 2147 | int do_init) |
8ecc7913 | 2148 | { |
c227f099 | 2149 | clk_setup_t clk_setup[PPC405CR_CLK_NB]; |
8ecc7913 JM |
2150 | qemu_irq dma_irqs[4]; |
2151 | CPUState *env; | |
8ecc7913 | 2152 | qemu_irq *pic, *irqs; |
8ecc7913 JM |
2153 | |
2154 | memset(clk_setup, 0, sizeof(clk_setup)); | |
008ff9d7 | 2155 | env = ppc4xx_init("405cr", &clk_setup[PPC405CR_CPU_CLK], |
04f20795 | 2156 | &clk_setup[PPC405CR_TMR_CLK], sysclk); |
8ecc7913 | 2157 | /* Memory mapped devices registers */ |
8ecc7913 JM |
2158 | /* PLB arbitrer */ |
2159 | ppc4xx_plb_init(env); | |
2160 | /* PLB to OPB bridge */ | |
2161 | ppc4xx_pob_init(env); | |
2162 | /* OBP arbitrer */ | |
802670e6 | 2163 | ppc4xx_opba_init(0xef600600); |
8ecc7913 JM |
2164 | /* Universal interrupt controller */ |
2165 | irqs = qemu_mallocz(sizeof(qemu_irq) * PPCUIC_OUTPUT_NB); | |
2166 | irqs[PPCUIC_OUTPUT_INT] = | |
b48d7d69 | 2167 | ((qemu_irq *)env->irq_inputs)[PPC40x_INPUT_INT]; |
8ecc7913 | 2168 | irqs[PPCUIC_OUTPUT_CINT] = |
b48d7d69 | 2169 | ((qemu_irq *)env->irq_inputs)[PPC40x_INPUT_CINT]; |
8ecc7913 JM |
2170 | pic = ppcuic_init(env, irqs, 0x0C0, 0, 1); |
2171 | *picp = pic; | |
2172 | /* SDRAM controller */ | |
80e8bd2b | 2173 | ppc4xx_sdram_init(env, pic[14], 1, ram_bases, ram_sizes, do_init); |
8ecc7913 JM |
2174 | /* External bus controller */ |
2175 | ppc405_ebc_init(env); | |
2176 | /* DMA controller */ | |
04f20795 JM |
2177 | dma_irqs[0] = pic[26]; |
2178 | dma_irqs[1] = pic[25]; | |
2179 | dma_irqs[2] = pic[24]; | |
2180 | dma_irqs[3] = pic[23]; | |
8ecc7913 JM |
2181 | ppc405_dma_init(env, dma_irqs); |
2182 | /* Serial ports */ | |
2183 | if (serial_hds[0] != NULL) { | |
802670e6 BS |
2184 | serial_mm_init(0xef600300, 0, pic[0], PPC_SERIAL_MM_BAUDBASE, |
2185 | serial_hds[0], 1); | |
8ecc7913 JM |
2186 | } |
2187 | if (serial_hds[1] != NULL) { | |
802670e6 BS |
2188 | serial_mm_init(0xef600400, 0, pic[1], PPC_SERIAL_MM_BAUDBASE, |
2189 | serial_hds[1], 1); | |
8ecc7913 JM |
2190 | } |
2191 | /* IIC controller */ | |
802670e6 | 2192 | ppc405_i2c_init(0xef600500, pic[2]); |
8ecc7913 | 2193 | /* GPIO */ |
802670e6 | 2194 | ppc405_gpio_init(0xef600700); |
8ecc7913 JM |
2195 | /* CPU control */ |
2196 | ppc405cr_cpc_init(env, clk_setup, sysclk); | |
8ecc7913 JM |
2197 | |
2198 | return env; | |
2199 | } | |
2200 | ||
2201 | /*****************************************************************************/ | |
2202 | /* PowerPC 405EP */ | |
2203 | /* CPU control */ | |
2204 | enum { | |
2205 | PPC405EP_CPC0_PLLMR0 = 0x0F0, | |
2206 | PPC405EP_CPC0_BOOT = 0x0F1, | |
2207 | PPC405EP_CPC0_EPCTL = 0x0F3, | |
2208 | PPC405EP_CPC0_PLLMR1 = 0x0F4, | |
2209 | PPC405EP_CPC0_UCR = 0x0F5, | |
2210 | PPC405EP_CPC0_SRR = 0x0F6, | |
2211 | PPC405EP_CPC0_JTAGID = 0x0F7, | |
2212 | PPC405EP_CPC0_PCI = 0x0F9, | |
9c02f1a2 JM |
2213 | #if 0 |
2214 | PPC405EP_CPC0_ER = xxx, | |
2215 | PPC405EP_CPC0_FR = xxx, | |
2216 | PPC405EP_CPC0_SR = xxx, | |
2217 | #endif | |
8ecc7913 JM |
2218 | }; |
2219 | ||
04f20795 JM |
2220 | enum { |
2221 | PPC405EP_CPU_CLK = 0, | |
2222 | PPC405EP_PLB_CLK = 1, | |
2223 | PPC405EP_OPB_CLK = 2, | |
2224 | PPC405EP_EBC_CLK = 3, | |
2225 | PPC405EP_MAL_CLK = 4, | |
2226 | PPC405EP_PCI_CLK = 5, | |
2227 | PPC405EP_UART0_CLK = 6, | |
2228 | PPC405EP_UART1_CLK = 7, | |
2229 | PPC405EP_CLK_NB = 8, | |
2230 | }; | |
2231 | ||
c227f099 AL |
2232 | typedef struct ppc405ep_cpc_t ppc405ep_cpc_t; |
2233 | struct ppc405ep_cpc_t { | |
8ecc7913 | 2234 | uint32_t sysclk; |
c227f099 | 2235 | clk_setup_t clk_setup[PPC405EP_CLK_NB]; |
8ecc7913 JM |
2236 | uint32_t boot; |
2237 | uint32_t epctl; | |
2238 | uint32_t pllmr[2]; | |
2239 | uint32_t ucr; | |
2240 | uint32_t srr; | |
2241 | uint32_t jtagid; | |
2242 | uint32_t pci; | |
9c02f1a2 JM |
2243 | /* Clock and power management */ |
2244 | uint32_t er; | |
2245 | uint32_t fr; | |
2246 | uint32_t sr; | |
8ecc7913 JM |
2247 | }; |
2248 | ||
c227f099 | 2249 | static void ppc405ep_compute_clocks (ppc405ep_cpc_t *cpc) |
8ecc7913 JM |
2250 | { |
2251 | uint32_t CPU_clk, PLB_clk, OPB_clk, EBC_clk, MAL_clk, PCI_clk; | |
2252 | uint32_t UART0_clk, UART1_clk; | |
2253 | uint64_t VCO_out, PLL_out; | |
2254 | int M, D; | |
2255 | ||
2256 | VCO_out = 0; | |
2257 | if ((cpc->pllmr[1] & 0x80000000) && !(cpc->pllmr[1] & 0x40000000)) { | |
2258 | M = (((cpc->pllmr[1] >> 20) - 1) & 0xF) + 1; /* FBMUL */ | |
aae9366a JM |
2259 | #ifdef DEBUG_CLOCKS_LL |
2260 | printf("FBMUL %01" PRIx32 " %d\n", (cpc->pllmr[1] >> 20) & 0xF, M); | |
2261 | #endif | |
8ecc7913 | 2262 | D = 8 - ((cpc->pllmr[1] >> 16) & 0x7); /* FWDA */ |
aae9366a JM |
2263 | #ifdef DEBUG_CLOCKS_LL |
2264 | printf("FWDA %01" PRIx32 " %d\n", (cpc->pllmr[1] >> 16) & 0x7, D); | |
2265 | #endif | |
8ecc7913 JM |
2266 | VCO_out = cpc->sysclk * M * D; |
2267 | if (VCO_out < 500000000UL || VCO_out > 1000000000UL) { | |
2268 | /* Error - unlock the PLL */ | |
2269 | printf("VCO out of range %" PRIu64 "\n", VCO_out); | |
2270 | #if 0 | |
2271 | cpc->pllmr[1] &= ~0x80000000; | |
2272 | goto pll_bypass; | |
2273 | #endif | |
2274 | } | |
2275 | PLL_out = VCO_out / D; | |
9c02f1a2 JM |
2276 | /* Pretend the PLL is locked */ |
2277 | cpc->boot |= 0x00000001; | |
8ecc7913 JM |
2278 | } else { |
2279 | #if 0 | |
2280 | pll_bypass: | |
2281 | #endif | |
2282 | PLL_out = cpc->sysclk; | |
9c02f1a2 JM |
2283 | if (cpc->pllmr[1] & 0x40000000) { |
2284 | /* Pretend the PLL is not locked */ | |
2285 | cpc->boot &= ~0x00000001; | |
2286 | } | |
8ecc7913 JM |
2287 | } |
2288 | /* Now, compute all other clocks */ | |
2289 | D = ((cpc->pllmr[0] >> 20) & 0x3) + 1; /* CCDV */ | |
aae9366a JM |
2290 | #ifdef DEBUG_CLOCKS_LL |
2291 | printf("CCDV %01" PRIx32 " %d\n", (cpc->pllmr[0] >> 20) & 0x3, D); | |
8ecc7913 JM |
2292 | #endif |
2293 | CPU_clk = PLL_out / D; | |
2294 | D = ((cpc->pllmr[0] >> 16) & 0x3) + 1; /* CBDV */ | |
aae9366a JM |
2295 | #ifdef DEBUG_CLOCKS_LL |
2296 | printf("CBDV %01" PRIx32 " %d\n", (cpc->pllmr[0] >> 16) & 0x3, D); | |
8ecc7913 JM |
2297 | #endif |
2298 | PLB_clk = CPU_clk / D; | |
2299 | D = ((cpc->pllmr[0] >> 12) & 0x3) + 1; /* OPDV */ | |
aae9366a JM |
2300 | #ifdef DEBUG_CLOCKS_LL |
2301 | printf("OPDV %01" PRIx32 " %d\n", (cpc->pllmr[0] >> 12) & 0x3, D); | |
8ecc7913 JM |
2302 | #endif |
2303 | OPB_clk = PLB_clk / D; | |
2304 | D = ((cpc->pllmr[0] >> 8) & 0x3) + 2; /* EPDV */ | |
aae9366a JM |
2305 | #ifdef DEBUG_CLOCKS_LL |
2306 | printf("EPDV %01" PRIx32 " %d\n", (cpc->pllmr[0] >> 8) & 0x3, D); | |
8ecc7913 JM |
2307 | #endif |
2308 | EBC_clk = PLB_clk / D; | |
2309 | D = ((cpc->pllmr[0] >> 4) & 0x3) + 1; /* MPDV */ | |
aae9366a JM |
2310 | #ifdef DEBUG_CLOCKS_LL |
2311 | printf("MPDV %01" PRIx32 " %d\n", (cpc->pllmr[0] >> 4) & 0x3, D); | |
8ecc7913 JM |
2312 | #endif |
2313 | MAL_clk = PLB_clk / D; | |
2314 | D = (cpc->pllmr[0] & 0x3) + 1; /* PPDV */ | |
aae9366a JM |
2315 | #ifdef DEBUG_CLOCKS_LL |
2316 | printf("PPDV %01" PRIx32 " %d\n", cpc->pllmr[0] & 0x3, D); | |
8ecc7913 JM |
2317 | #endif |
2318 | PCI_clk = PLB_clk / D; | |
2319 | D = ((cpc->ucr - 1) & 0x7F) + 1; /* U0DIV */ | |
aae9366a JM |
2320 | #ifdef DEBUG_CLOCKS_LL |
2321 | printf("U0DIV %01" PRIx32 " %d\n", cpc->ucr & 0x7F, D); | |
8ecc7913 JM |
2322 | #endif |
2323 | UART0_clk = PLL_out / D; | |
2324 | D = (((cpc->ucr >> 8) - 1) & 0x7F) + 1; /* U1DIV */ | |
aae9366a JM |
2325 | #ifdef DEBUG_CLOCKS_LL |
2326 | printf("U1DIV %01" PRIx32 " %d\n", (cpc->ucr >> 8) & 0x7F, D); | |
8ecc7913 JM |
2327 | #endif |
2328 | UART1_clk = PLL_out / D; | |
2329 | #ifdef DEBUG_CLOCKS | |
aae9366a | 2330 | printf("Setup PPC405EP clocks - sysclk %" PRIu32 " VCO %" PRIu64 |
8ecc7913 | 2331 | " PLL out %" PRIu64 " Hz\n", cpc->sysclk, VCO_out, PLL_out); |
aae9366a JM |
2332 | printf("CPU %" PRIu32 " PLB %" PRIu32 " OPB %" PRIu32 " EBC %" PRIu32 |
2333 | " MAL %" PRIu32 " PCI %" PRIu32 " UART0 %" PRIu32 | |
2334 | " UART1 %" PRIu32 "\n", | |
8ecc7913 JM |
2335 | CPU_clk, PLB_clk, OPB_clk, EBC_clk, MAL_clk, PCI_clk, |
2336 | UART0_clk, UART1_clk); | |
2337 | #endif | |
2338 | /* Setup CPU clocks */ | |
04f20795 | 2339 | clk_setup(&cpc->clk_setup[PPC405EP_CPU_CLK], CPU_clk); |
8ecc7913 | 2340 | /* Setup PLB clock */ |
04f20795 | 2341 | clk_setup(&cpc->clk_setup[PPC405EP_PLB_CLK], PLB_clk); |
8ecc7913 | 2342 | /* Setup OPB clock */ |
04f20795 | 2343 | clk_setup(&cpc->clk_setup[PPC405EP_OPB_CLK], OPB_clk); |
8ecc7913 | 2344 | /* Setup external clock */ |
04f20795 | 2345 | clk_setup(&cpc->clk_setup[PPC405EP_EBC_CLK], EBC_clk); |
8ecc7913 | 2346 | /* Setup MAL clock */ |
04f20795 | 2347 | clk_setup(&cpc->clk_setup[PPC405EP_MAL_CLK], MAL_clk); |
8ecc7913 | 2348 | /* Setup PCI clock */ |
04f20795 | 2349 | clk_setup(&cpc->clk_setup[PPC405EP_PCI_CLK], PCI_clk); |
8ecc7913 | 2350 | /* Setup UART0 clock */ |
04f20795 | 2351 | clk_setup(&cpc->clk_setup[PPC405EP_UART0_CLK], UART0_clk); |
8ecc7913 | 2352 | /* Setup UART1 clock */ |
04f20795 | 2353 | clk_setup(&cpc->clk_setup[PPC405EP_UART1_CLK], UART1_clk); |
8ecc7913 JM |
2354 | } |
2355 | ||
2356 | static target_ulong dcr_read_epcpc (void *opaque, int dcrn) | |
2357 | { | |
c227f099 | 2358 | ppc405ep_cpc_t *cpc; |
8ecc7913 JM |
2359 | target_ulong ret; |
2360 | ||
2361 | cpc = opaque; | |
2362 | switch (dcrn) { | |
2363 | case PPC405EP_CPC0_BOOT: | |
2364 | ret = cpc->boot; | |
2365 | break; | |
2366 | case PPC405EP_CPC0_EPCTL: | |
2367 | ret = cpc->epctl; | |
2368 | break; | |
2369 | case PPC405EP_CPC0_PLLMR0: | |
2370 | ret = cpc->pllmr[0]; | |
2371 | break; | |
2372 | case PPC405EP_CPC0_PLLMR1: | |
2373 | ret = cpc->pllmr[1]; | |
2374 | break; | |
2375 | case PPC405EP_CPC0_UCR: | |
2376 | ret = cpc->ucr; | |
2377 | break; | |
2378 | case PPC405EP_CPC0_SRR: | |
2379 | ret = cpc->srr; | |
2380 | break; | |
2381 | case PPC405EP_CPC0_JTAGID: | |
2382 | ret = cpc->jtagid; | |
2383 | break; | |
2384 | case PPC405EP_CPC0_PCI: | |
2385 | ret = cpc->pci; | |
2386 | break; | |
2387 | default: | |
2388 | /* Avoid gcc warning */ | |
2389 | ret = 0; | |
2390 | break; | |
2391 | } | |
2392 | ||
2393 | return ret; | |
2394 | } | |
2395 | ||
2396 | static void dcr_write_epcpc (void *opaque, int dcrn, target_ulong val) | |
2397 | { | |
c227f099 | 2398 | ppc405ep_cpc_t *cpc; |
8ecc7913 JM |
2399 | |
2400 | cpc = opaque; | |
2401 | switch (dcrn) { | |
2402 | case PPC405EP_CPC0_BOOT: | |
2403 | /* Read-only register */ | |
2404 | break; | |
2405 | case PPC405EP_CPC0_EPCTL: | |
2406 | /* Don't care for now */ | |
2407 | cpc->epctl = val & 0xC00000F3; | |
2408 | break; | |
2409 | case PPC405EP_CPC0_PLLMR0: | |
2410 | cpc->pllmr[0] = val & 0x00633333; | |
2411 | ppc405ep_compute_clocks(cpc); | |
2412 | break; | |
2413 | case PPC405EP_CPC0_PLLMR1: | |
2414 | cpc->pllmr[1] = val & 0xC0F73FFF; | |
2415 | ppc405ep_compute_clocks(cpc); | |
2416 | break; | |
2417 | case PPC405EP_CPC0_UCR: | |
2418 | /* UART control - don't care for now */ | |
2419 | cpc->ucr = val & 0x003F7F7F; | |
2420 | break; | |
2421 | case PPC405EP_CPC0_SRR: | |
2422 | cpc->srr = val; | |
2423 | break; | |
2424 | case PPC405EP_CPC0_JTAGID: | |
2425 | /* Read-only */ | |
2426 | break; | |
2427 | case PPC405EP_CPC0_PCI: | |
2428 | cpc->pci = val; | |
2429 | break; | |
2430 | } | |
2431 | } | |
2432 | ||
2433 | static void ppc405ep_cpc_reset (void *opaque) | |
2434 | { | |
c227f099 | 2435 | ppc405ep_cpc_t *cpc = opaque; |
8ecc7913 JM |
2436 | |
2437 | cpc->boot = 0x00000010; /* Boot from PCI - IIC EEPROM disabled */ | |
2438 | cpc->epctl = 0x00000000; | |
2439 | cpc->pllmr[0] = 0x00011010; | |
2440 | cpc->pllmr[1] = 0x40000000; | |
2441 | cpc->ucr = 0x00000000; | |
2442 | cpc->srr = 0x00040000; | |
2443 | cpc->pci = 0x00000000; | |
9c02f1a2 JM |
2444 | cpc->er = 0x00000000; |
2445 | cpc->fr = 0x00000000; | |
2446 | cpc->sr = 0x00000000; | |
8ecc7913 JM |
2447 | ppc405ep_compute_clocks(cpc); |
2448 | } | |
2449 | ||
2450 | /* XXX: sysclk should be between 25 and 100 MHz */ | |
c227f099 | 2451 | static void ppc405ep_cpc_init (CPUState *env, clk_setup_t clk_setup[8], |
8ecc7913 JM |
2452 | uint32_t sysclk) |
2453 | { | |
c227f099 | 2454 | ppc405ep_cpc_t *cpc; |
8ecc7913 | 2455 | |
c227f099 | 2456 | cpc = qemu_mallocz(sizeof(ppc405ep_cpc_t)); |
487414f1 | 2457 | memcpy(cpc->clk_setup, clk_setup, |
c227f099 | 2458 | PPC405EP_CLK_NB * sizeof(clk_setup_t)); |
487414f1 AL |
2459 | cpc->jtagid = 0x20267049; |
2460 | cpc->sysclk = sysclk; | |
a08d4367 | 2461 | qemu_register_reset(&ppc405ep_cpc_reset, cpc); |
487414f1 AL |
2462 | ppc_dcr_register(env, PPC405EP_CPC0_BOOT, cpc, |
2463 | &dcr_read_epcpc, &dcr_write_epcpc); | |
2464 | ppc_dcr_register(env, PPC405EP_CPC0_EPCTL, cpc, | |
2465 | &dcr_read_epcpc, &dcr_write_epcpc); | |
2466 | ppc_dcr_register(env, PPC405EP_CPC0_PLLMR0, cpc, | |
2467 | &dcr_read_epcpc, &dcr_write_epcpc); | |
2468 | ppc_dcr_register(env, PPC405EP_CPC0_PLLMR1, cpc, | |
2469 | &dcr_read_epcpc, &dcr_write_epcpc); | |
2470 | ppc_dcr_register(env, PPC405EP_CPC0_UCR, cpc, | |
2471 | &dcr_read_epcpc, &dcr_write_epcpc); | |
2472 | ppc_dcr_register(env, PPC405EP_CPC0_SRR, cpc, | |
2473 | &dcr_read_epcpc, &dcr_write_epcpc); | |
2474 | ppc_dcr_register(env, PPC405EP_CPC0_JTAGID, cpc, | |
2475 | &dcr_read_epcpc, &dcr_write_epcpc); | |
2476 | ppc_dcr_register(env, PPC405EP_CPC0_PCI, cpc, | |
2477 | &dcr_read_epcpc, &dcr_write_epcpc); | |
9c02f1a2 | 2478 | #if 0 |
487414f1 AL |
2479 | ppc_dcr_register(env, PPC405EP_CPC0_ER, cpc, |
2480 | &dcr_read_epcpc, &dcr_write_epcpc); | |
2481 | ppc_dcr_register(env, PPC405EP_CPC0_FR, cpc, | |
2482 | &dcr_read_epcpc, &dcr_write_epcpc); | |
2483 | ppc_dcr_register(env, PPC405EP_CPC0_SR, cpc, | |
2484 | &dcr_read_epcpc, &dcr_write_epcpc); | |
9c02f1a2 | 2485 | #endif |
8ecc7913 JM |
2486 | } |
2487 | ||
c227f099 AL |
2488 | CPUState *ppc405ep_init (target_phys_addr_t ram_bases[2], |
2489 | target_phys_addr_t ram_sizes[2], | |
8ecc7913 | 2490 | uint32_t sysclk, qemu_irq **picp, |
5c130f65 | 2491 | int do_init) |
8ecc7913 | 2492 | { |
c227f099 | 2493 | clk_setup_t clk_setup[PPC405EP_CLK_NB], tlb_clk_setup; |
9c02f1a2 | 2494 | qemu_irq dma_irqs[4], gpt_irqs[5], mal_irqs[4]; |
8ecc7913 | 2495 | CPUState *env; |
8ecc7913 | 2496 | qemu_irq *pic, *irqs; |
8ecc7913 JM |
2497 | |
2498 | memset(clk_setup, 0, sizeof(clk_setup)); | |
2499 | /* init CPUs */ | |
008ff9d7 | 2500 | env = ppc4xx_init("405ep", &clk_setup[PPC405EP_CPU_CLK], |
9c02f1a2 JM |
2501 | &tlb_clk_setup, sysclk); |
2502 | clk_setup[PPC405EP_CPU_CLK].cb = tlb_clk_setup.cb; | |
2503 | clk_setup[PPC405EP_CPU_CLK].opaque = tlb_clk_setup.opaque; | |
8ecc7913 JM |
2504 | /* Internal devices init */ |
2505 | /* Memory mapped devices registers */ | |
8ecc7913 JM |
2506 | /* PLB arbitrer */ |
2507 | ppc4xx_plb_init(env); | |
2508 | /* PLB to OPB bridge */ | |
2509 | ppc4xx_pob_init(env); | |
2510 | /* OBP arbitrer */ | |
802670e6 | 2511 | ppc4xx_opba_init(0xef600600); |
8ecc7913 JM |
2512 | /* Universal interrupt controller */ |
2513 | irqs = qemu_mallocz(sizeof(qemu_irq) * PPCUIC_OUTPUT_NB); | |
2514 | irqs[PPCUIC_OUTPUT_INT] = | |
b48d7d69 | 2515 | ((qemu_irq *)env->irq_inputs)[PPC40x_INPUT_INT]; |
8ecc7913 | 2516 | irqs[PPCUIC_OUTPUT_CINT] = |
b48d7d69 | 2517 | ((qemu_irq *)env->irq_inputs)[PPC40x_INPUT_CINT]; |
8ecc7913 JM |
2518 | pic = ppcuic_init(env, irqs, 0x0C0, 0, 1); |
2519 | *picp = pic; | |
2520 | /* SDRAM controller */ | |
923e5e33 | 2521 | /* XXX 405EP has no ECC interrupt */ |
80e8bd2b | 2522 | ppc4xx_sdram_init(env, pic[17], 2, ram_bases, ram_sizes, do_init); |
8ecc7913 JM |
2523 | /* External bus controller */ |
2524 | ppc405_ebc_init(env); | |
2525 | /* DMA controller */ | |
923e5e33 AJ |
2526 | dma_irqs[0] = pic[5]; |
2527 | dma_irqs[1] = pic[6]; | |
2528 | dma_irqs[2] = pic[7]; | |
2529 | dma_irqs[3] = pic[8]; | |
8ecc7913 JM |
2530 | ppc405_dma_init(env, dma_irqs); |
2531 | /* IIC controller */ | |
802670e6 | 2532 | ppc405_i2c_init(0xef600500, pic[2]); |
8ecc7913 | 2533 | /* GPIO */ |
802670e6 | 2534 | ppc405_gpio_init(0xef600700); |
8ecc7913 JM |
2535 | /* Serial ports */ |
2536 | if (serial_hds[0] != NULL) { | |
802670e6 BS |
2537 | serial_mm_init(0xef600300, 0, pic[0], PPC_SERIAL_MM_BAUDBASE, |
2538 | serial_hds[0], 1); | |
8ecc7913 JM |
2539 | } |
2540 | if (serial_hds[1] != NULL) { | |
802670e6 BS |
2541 | serial_mm_init(0xef600400, 0, pic[1], PPC_SERIAL_MM_BAUDBASE, |
2542 | serial_hds[1], 1); | |
8ecc7913 JM |
2543 | } |
2544 | /* OCM */ | |
5c130f65 | 2545 | ppc405_ocm_init(env); |
9c02f1a2 | 2546 | /* GPT */ |
923e5e33 AJ |
2547 | gpt_irqs[0] = pic[19]; |
2548 | gpt_irqs[1] = pic[20]; | |
2549 | gpt_irqs[2] = pic[21]; | |
2550 | gpt_irqs[3] = pic[22]; | |
2551 | gpt_irqs[4] = pic[23]; | |
802670e6 | 2552 | ppc4xx_gpt_init(0xef600000, gpt_irqs); |
8ecc7913 | 2553 | /* PCI */ |
923e5e33 | 2554 | /* Uses pic[3], pic[16], pic[18] */ |
9c02f1a2 | 2555 | /* MAL */ |
923e5e33 AJ |
2556 | mal_irqs[0] = pic[11]; |
2557 | mal_irqs[1] = pic[12]; | |
2558 | mal_irqs[2] = pic[13]; | |
2559 | mal_irqs[3] = pic[14]; | |
9c02f1a2 JM |
2560 | ppc405_mal_init(env, mal_irqs); |
2561 | /* Ethernet */ | |
923e5e33 | 2562 | /* Uses pic[9], pic[15], pic[17] */ |
8ecc7913 JM |
2563 | /* CPU control */ |
2564 | ppc405ep_cpc_init(env, clk_setup, sysclk); | |
8ecc7913 JM |
2565 | |
2566 | return env; | |
2567 | } |