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