]>
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 | */ | |
71e8a915 | 24 | |
0d75590d | 25 | #include "qemu/osdep.h" |
ab3dd749 | 26 | #include "qemu/units.h" |
da34e65c | 27 | #include "qapi/error.h" |
4771d756 | 28 | #include "cpu.h" |
0d09e41a | 29 | #include "hw/ppc/ppc.h" |
3b09bb0f | 30 | #include "hw/i2c/ppc4xx_i2c.h" |
64552b6b | 31 | #include "hw/irq.h" |
47b43a1f | 32 | #include "ppc405.h" |
0d09e41a | 33 | #include "hw/char/serial.h" |
1de7afc9 | 34 | #include "qemu/timer.h" |
71e8a915 | 35 | #include "sysemu/reset.h" |
9c17d615 | 36 | #include "sysemu/sysemu.h" |
1de7afc9 | 37 | #include "qemu/log.h" |
022c62cb | 38 | #include "exec/address-spaces.h" |
71c3c44b PM |
39 | #include "hw/intc/ppc-uic.h" |
40 | #include "hw/qdev-properties.h" | |
41 | #include "qapi/error.h" | |
8ecc7913 | 42 | |
0d84382e AF |
43 | //#define DEBUG_OPBA |
44 | //#define DEBUG_SDRAM | |
45 | //#define DEBUG_GPIO | |
46 | //#define DEBUG_SERIAL | |
47 | //#define DEBUG_OCM | |
0d84382e | 48 | //#define DEBUG_GPT |
0d84382e | 49 | //#define DEBUG_CLOCKS |
aae9366a | 50 | //#define DEBUG_CLOCKS_LL |
8ecc7913 | 51 | |
e2684c0b | 52 | ram_addr_t ppc405_set_bootinfo (CPUPPCState *env, ppc4xx_bd_info_t *bd, |
b8d3f5d1 | 53 | uint32_t flags) |
04f20795 | 54 | { |
db70b311 | 55 | CPUState *cs = env_cpu(env); |
c227f099 | 56 | ram_addr_t bdloc; |
04f20795 JM |
57 | int i, n; |
58 | ||
59 | /* We put the bd structure at the top of memory */ | |
be58fc7c | 60 | if (bd->bi_memsize >= 0x01000000UL) |
c227f099 | 61 | bdloc = 0x01000000UL - sizeof(struct ppc4xx_bd_info_t); |
be58fc7c | 62 | else |
c227f099 | 63 | bdloc = bd->bi_memsize - sizeof(struct ppc4xx_bd_info_t); |
ab1da857 EI |
64 | stl_be_phys(cs->as, bdloc + 0x00, bd->bi_memstart); |
65 | stl_be_phys(cs->as, bdloc + 0x04, bd->bi_memsize); | |
66 | stl_be_phys(cs->as, bdloc + 0x08, bd->bi_flashstart); | |
67 | stl_be_phys(cs->as, bdloc + 0x0C, bd->bi_flashsize); | |
68 | stl_be_phys(cs->as, bdloc + 0x10, bd->bi_flashoffset); | |
69 | stl_be_phys(cs->as, bdloc + 0x14, bd->bi_sramstart); | |
70 | stl_be_phys(cs->as, bdloc + 0x18, bd->bi_sramsize); | |
71 | stl_be_phys(cs->as, bdloc + 0x1C, bd->bi_bootflags); | |
72 | stl_be_phys(cs->as, bdloc + 0x20, bd->bi_ipaddr); | |
db663d0f | 73 | for (i = 0; i < 6; i++) { |
db3be60d | 74 | stb_phys(cs->as, bdloc + 0x24 + i, bd->bi_enetaddr[i]); |
db663d0f | 75 | } |
5ce5944d | 76 | stw_be_phys(cs->as, bdloc + 0x2A, bd->bi_ethspeed); |
ab1da857 EI |
77 | stl_be_phys(cs->as, bdloc + 0x2C, bd->bi_intfreq); |
78 | stl_be_phys(cs->as, bdloc + 0x30, bd->bi_busfreq); | |
79 | stl_be_phys(cs->as, bdloc + 0x34, bd->bi_baudrate); | |
db663d0f | 80 | for (i = 0; i < 4; i++) { |
db3be60d | 81 | stb_phys(cs->as, bdloc + 0x38 + i, bd->bi_s_version[i]); |
db663d0f | 82 | } |
4508d81a | 83 | for (i = 0; i < 32; i++) { |
db3be60d | 84 | stb_phys(cs->as, bdloc + 0x3C + i, bd->bi_r_version[i]); |
4508d81a | 85 | } |
ab1da857 EI |
86 | stl_be_phys(cs->as, bdloc + 0x5C, bd->bi_plb_busfreq); |
87 | stl_be_phys(cs->as, bdloc + 0x60, bd->bi_pci_busfreq); | |
db663d0f | 88 | for (i = 0; i < 6; i++) { |
db3be60d | 89 | stb_phys(cs->as, bdloc + 0x64 + i, bd->bi_pci_enetaddr[i]); |
db663d0f | 90 | } |
04f20795 | 91 | n = 0x6A; |
b8d3f5d1 | 92 | if (flags & 0x00000001) { |
04f20795 | 93 | for (i = 0; i < 6; i++) |
db3be60d | 94 | stb_phys(cs->as, bdloc + n++, bd->bi_pci_enetaddr2[i]); |
04f20795 | 95 | } |
ab1da857 | 96 | stl_be_phys(cs->as, bdloc + n, bd->bi_opbfreq); |
04f20795 JM |
97 | n += 4; |
98 | for (i = 0; i < 2; i++) { | |
ab1da857 | 99 | stl_be_phys(cs->as, bdloc + n, bd->bi_iic_fast[i]); |
04f20795 JM |
100 | n += 4; |
101 | } | |
102 | ||
103 | return bdloc; | |
104 | } | |
105 | ||
8ecc7913 JM |
106 | /*****************************************************************************/ |
107 | /* Shared peripherals */ | |
108 | ||
8ecc7913 JM |
109 | /*****************************************************************************/ |
110 | /* Peripheral local bus arbitrer */ | |
111 | enum { | |
4c46f372 BZ |
112 | PLB3A0_ACR = 0x077, |
113 | PLB4A0_ACR = 0x081, | |
114 | PLB0_BESR = 0x084, | |
115 | PLB0_BEAR = 0x086, | |
116 | PLB0_ACR = 0x087, | |
117 | PLB4A1_ACR = 0x089, | |
8ecc7913 JM |
118 | }; |
119 | ||
c227f099 AL |
120 | typedef struct ppc4xx_plb_t ppc4xx_plb_t; |
121 | struct ppc4xx_plb_t { | |
8ecc7913 JM |
122 | uint32_t acr; |
123 | uint32_t bear; | |
124 | uint32_t besr; | |
125 | }; | |
126 | ||
73b01960 | 127 | static uint32_t dcr_read_plb (void *opaque, int dcrn) |
8ecc7913 | 128 | { |
c227f099 | 129 | ppc4xx_plb_t *plb; |
73b01960 | 130 | uint32_t ret; |
8ecc7913 JM |
131 | |
132 | plb = opaque; | |
133 | switch (dcrn) { | |
134 | case PLB0_ACR: | |
135 | ret = plb->acr; | |
136 | break; | |
137 | case PLB0_BEAR: | |
138 | ret = plb->bear; | |
139 | break; | |
140 | case PLB0_BESR: | |
141 | ret = plb->besr; | |
142 | break; | |
143 | default: | |
144 | /* Avoid gcc warning */ | |
145 | ret = 0; | |
146 | break; | |
147 | } | |
148 | ||
149 | return ret; | |
150 | } | |
151 | ||
73b01960 | 152 | static void dcr_write_plb (void *opaque, int dcrn, uint32_t val) |
8ecc7913 | 153 | { |
c227f099 | 154 | ppc4xx_plb_t *plb; |
8ecc7913 JM |
155 | |
156 | plb = opaque; | |
157 | switch (dcrn) { | |
158 | case PLB0_ACR: | |
9c02f1a2 JM |
159 | /* We don't care about the actual parameters written as |
160 | * we don't manage any priorities on the bus | |
161 | */ | |
162 | plb->acr = val & 0xF8000000; | |
8ecc7913 JM |
163 | break; |
164 | case PLB0_BEAR: | |
165 | /* Read only */ | |
166 | break; | |
167 | case PLB0_BESR: | |
168 | /* Write-clear */ | |
169 | plb->besr &= ~val; | |
170 | break; | |
171 | } | |
172 | } | |
173 | ||
174 | static void ppc4xx_plb_reset (void *opaque) | |
175 | { | |
c227f099 | 176 | ppc4xx_plb_t *plb; |
8ecc7913 JM |
177 | |
178 | plb = opaque; | |
179 | plb->acr = 0x00000000; | |
180 | plb->bear = 0x00000000; | |
181 | plb->besr = 0x00000000; | |
182 | } | |
183 | ||
97c2acb5 | 184 | void ppc4xx_plb_init(CPUPPCState *env) |
8ecc7913 | 185 | { |
c227f099 | 186 | ppc4xx_plb_t *plb; |
8ecc7913 | 187 | |
7267c094 | 188 | plb = g_malloc0(sizeof(ppc4xx_plb_t)); |
4c46f372 BZ |
189 | ppc_dcr_register(env, PLB3A0_ACR, plb, &dcr_read_plb, &dcr_write_plb); |
190 | ppc_dcr_register(env, PLB4A0_ACR, plb, &dcr_read_plb, &dcr_write_plb); | |
487414f1 AL |
191 | ppc_dcr_register(env, PLB0_ACR, plb, &dcr_read_plb, &dcr_write_plb); |
192 | ppc_dcr_register(env, PLB0_BEAR, plb, &dcr_read_plb, &dcr_write_plb); | |
193 | ppc_dcr_register(env, PLB0_BESR, plb, &dcr_read_plb, &dcr_write_plb); | |
4c46f372 | 194 | ppc_dcr_register(env, PLB4A1_ACR, plb, &dcr_read_plb, &dcr_write_plb); |
a08d4367 | 195 | qemu_register_reset(ppc4xx_plb_reset, plb); |
8ecc7913 JM |
196 | } |
197 | ||
198 | /*****************************************************************************/ | |
199 | /* PLB to OPB bridge */ | |
200 | enum { | |
201 | POB0_BESR0 = 0x0A0, | |
202 | POB0_BESR1 = 0x0A2, | |
203 | POB0_BEAR = 0x0A4, | |
204 | }; | |
205 | ||
c227f099 AL |
206 | typedef struct ppc4xx_pob_t ppc4xx_pob_t; |
207 | struct ppc4xx_pob_t { | |
8ecc7913 | 208 | uint32_t bear; |
5a1972c8 SW |
209 | uint32_t besr0; |
210 | uint32_t besr1; | |
8ecc7913 JM |
211 | }; |
212 | ||
73b01960 | 213 | static uint32_t dcr_read_pob (void *opaque, int dcrn) |
8ecc7913 | 214 | { |
c227f099 | 215 | ppc4xx_pob_t *pob; |
73b01960 | 216 | uint32_t ret; |
8ecc7913 JM |
217 | |
218 | pob = opaque; | |
219 | switch (dcrn) { | |
220 | case POB0_BEAR: | |
221 | ret = pob->bear; | |
222 | break; | |
223 | case POB0_BESR0: | |
5a1972c8 SW |
224 | ret = pob->besr0; |
225 | break; | |
8ecc7913 | 226 | case POB0_BESR1: |
5a1972c8 | 227 | ret = pob->besr1; |
8ecc7913 JM |
228 | break; |
229 | default: | |
230 | /* Avoid gcc warning */ | |
231 | ret = 0; | |
232 | break; | |
233 | } | |
234 | ||
235 | return ret; | |
236 | } | |
237 | ||
73b01960 | 238 | static void dcr_write_pob (void *opaque, int dcrn, uint32_t val) |
8ecc7913 | 239 | { |
c227f099 | 240 | ppc4xx_pob_t *pob; |
8ecc7913 JM |
241 | |
242 | pob = opaque; | |
243 | switch (dcrn) { | |
244 | case POB0_BEAR: | |
245 | /* Read only */ | |
246 | break; | |
247 | case POB0_BESR0: | |
5a1972c8 SW |
248 | /* Write-clear */ |
249 | pob->besr0 &= ~val; | |
250 | break; | |
8ecc7913 JM |
251 | case POB0_BESR1: |
252 | /* Write-clear */ | |
5a1972c8 | 253 | pob->besr1 &= ~val; |
8ecc7913 JM |
254 | break; |
255 | } | |
256 | } | |
257 | ||
258 | static void ppc4xx_pob_reset (void *opaque) | |
259 | { | |
c227f099 | 260 | ppc4xx_pob_t *pob; |
8ecc7913 JM |
261 | |
262 | pob = opaque; | |
263 | /* No error */ | |
264 | pob->bear = 0x00000000; | |
5a1972c8 SW |
265 | pob->besr0 = 0x0000000; |
266 | pob->besr1 = 0x0000000; | |
8ecc7913 JM |
267 | } |
268 | ||
e2684c0b | 269 | static void ppc4xx_pob_init(CPUPPCState *env) |
8ecc7913 | 270 | { |
c227f099 | 271 | ppc4xx_pob_t *pob; |
8ecc7913 | 272 | |
7267c094 | 273 | pob = g_malloc0(sizeof(ppc4xx_pob_t)); |
487414f1 AL |
274 | ppc_dcr_register(env, POB0_BEAR, pob, &dcr_read_pob, &dcr_write_pob); |
275 | ppc_dcr_register(env, POB0_BESR0, pob, &dcr_read_pob, &dcr_write_pob); | |
276 | ppc_dcr_register(env, POB0_BESR1, pob, &dcr_read_pob, &dcr_write_pob); | |
a08d4367 | 277 | qemu_register_reset(ppc4xx_pob_reset, pob); |
8ecc7913 JM |
278 | } |
279 | ||
280 | /*****************************************************************************/ | |
281 | /* OPB arbitrer */ | |
c227f099 AL |
282 | typedef struct ppc4xx_opba_t ppc4xx_opba_t; |
283 | struct ppc4xx_opba_t { | |
9074e0e3 | 284 | MemoryRegion io; |
8ecc7913 JM |
285 | uint8_t cr; |
286 | uint8_t pr; | |
287 | }; | |
288 | ||
69bd18f8 | 289 | static uint64_t opba_readb(void *opaque, hwaddr addr, unsigned size) |
8ecc7913 | 290 | { |
c227f099 | 291 | ppc4xx_opba_t *opba; |
8ecc7913 JM |
292 | uint32_t ret; |
293 | ||
294 | #ifdef DEBUG_OPBA | |
90e189ec | 295 | printf("%s: addr " TARGET_FMT_plx "\n", __func__, addr); |
8ecc7913 JM |
296 | #endif |
297 | opba = opaque; | |
802670e6 | 298 | switch (addr) { |
8ecc7913 JM |
299 | case 0x00: |
300 | ret = opba->cr; | |
301 | break; | |
302 | case 0x01: | |
303 | ret = opba->pr; | |
304 | break; | |
305 | default: | |
306 | ret = 0x00; | |
307 | break; | |
308 | } | |
309 | ||
310 | return ret; | |
311 | } | |
312 | ||
69bd18f8 PM |
313 | static void opba_writeb(void *opaque, hwaddr addr, uint64_t value, |
314 | unsigned size) | |
8ecc7913 | 315 | { |
c227f099 | 316 | ppc4xx_opba_t *opba; |
8ecc7913 JM |
317 | |
318 | #ifdef DEBUG_OPBA | |
90e189ec BS |
319 | printf("%s: addr " TARGET_FMT_plx " val %08" PRIx32 "\n", __func__, addr, |
320 | value); | |
8ecc7913 JM |
321 | #endif |
322 | opba = opaque; | |
802670e6 | 323 | switch (addr) { |
8ecc7913 JM |
324 | case 0x00: |
325 | opba->cr = value & 0xF8; | |
326 | break; | |
327 | case 0x01: | |
328 | opba->pr = value & 0xFF; | |
329 | break; | |
330 | default: | |
331 | break; | |
332 | } | |
333 | } | |
9074e0e3 | 334 | static const MemoryRegionOps opba_ops = { |
69bd18f8 PM |
335 | .read = opba_readb, |
336 | .write = opba_writeb, | |
337 | .impl.min_access_size = 1, | |
338 | .impl.max_access_size = 1, | |
339 | .valid.min_access_size = 1, | |
340 | .valid.max_access_size = 4, | |
341 | .endianness = DEVICE_BIG_ENDIAN, | |
8ecc7913 JM |
342 | }; |
343 | ||
344 | static void ppc4xx_opba_reset (void *opaque) | |
345 | { | |
c227f099 | 346 | ppc4xx_opba_t *opba; |
8ecc7913 JM |
347 | |
348 | opba = opaque; | |
349 | opba->cr = 0x00; /* No dynamic priorities - park disabled */ | |
350 | opba->pr = 0x11; | |
351 | } | |
352 | ||
a8170e5e | 353 | static void ppc4xx_opba_init(hwaddr base) |
8ecc7913 | 354 | { |
c227f099 | 355 | ppc4xx_opba_t *opba; |
8ecc7913 | 356 | |
7267c094 | 357 | opba = g_malloc0(sizeof(ppc4xx_opba_t)); |
8ecc7913 | 358 | #ifdef DEBUG_OPBA |
90e189ec | 359 | printf("%s: offset " TARGET_FMT_plx "\n", __func__, base); |
8ecc7913 | 360 | #endif |
2c9b15ca | 361 | memory_region_init_io(&opba->io, NULL, &opba_ops, opba, "opba", 0x002); |
9074e0e3 | 362 | memory_region_add_subregion(get_system_memory(), base, &opba->io); |
802670e6 | 363 | qemu_register_reset(ppc4xx_opba_reset, opba); |
8ecc7913 JM |
364 | } |
365 | ||
8ecc7913 JM |
366 | /*****************************************************************************/ |
367 | /* Code decompression controller */ | |
368 | /* XXX: TODO */ | |
369 | ||
8ecc7913 JM |
370 | /*****************************************************************************/ |
371 | /* Peripheral controller */ | |
c227f099 AL |
372 | typedef struct ppc4xx_ebc_t ppc4xx_ebc_t; |
373 | struct ppc4xx_ebc_t { | |
8ecc7913 JM |
374 | uint32_t addr; |
375 | uint32_t bcr[8]; | |
376 | uint32_t bap[8]; | |
377 | uint32_t bear; | |
378 | uint32_t besr0; | |
379 | uint32_t besr1; | |
380 | uint32_t cfg; | |
381 | }; | |
382 | ||
383 | enum { | |
384 | EBC0_CFGADDR = 0x012, | |
385 | EBC0_CFGDATA = 0x013, | |
386 | }; | |
387 | ||
73b01960 | 388 | static uint32_t dcr_read_ebc (void *opaque, int dcrn) |
8ecc7913 | 389 | { |
c227f099 | 390 | ppc4xx_ebc_t *ebc; |
73b01960 | 391 | uint32_t ret; |
8ecc7913 JM |
392 | |
393 | ebc = opaque; | |
394 | switch (dcrn) { | |
395 | case EBC0_CFGADDR: | |
396 | ret = ebc->addr; | |
397 | break; | |
398 | case EBC0_CFGDATA: | |
399 | switch (ebc->addr) { | |
400 | case 0x00: /* B0CR */ | |
401 | ret = ebc->bcr[0]; | |
402 | break; | |
403 | case 0x01: /* B1CR */ | |
404 | ret = ebc->bcr[1]; | |
405 | break; | |
406 | case 0x02: /* B2CR */ | |
407 | ret = ebc->bcr[2]; | |
408 | break; | |
409 | case 0x03: /* B3CR */ | |
410 | ret = ebc->bcr[3]; | |
411 | break; | |
412 | case 0x04: /* B4CR */ | |
413 | ret = ebc->bcr[4]; | |
414 | break; | |
415 | case 0x05: /* B5CR */ | |
416 | ret = ebc->bcr[5]; | |
417 | break; | |
418 | case 0x06: /* B6CR */ | |
419 | ret = ebc->bcr[6]; | |
420 | break; | |
421 | case 0x07: /* B7CR */ | |
422 | ret = ebc->bcr[7]; | |
423 | break; | |
424 | case 0x10: /* B0AP */ | |
425 | ret = ebc->bap[0]; | |
426 | break; | |
427 | case 0x11: /* B1AP */ | |
428 | ret = ebc->bap[1]; | |
429 | break; | |
430 | case 0x12: /* B2AP */ | |
431 | ret = ebc->bap[2]; | |
432 | break; | |
433 | case 0x13: /* B3AP */ | |
434 | ret = ebc->bap[3]; | |
435 | break; | |
436 | case 0x14: /* B4AP */ | |
437 | ret = ebc->bap[4]; | |
438 | break; | |
439 | case 0x15: /* B5AP */ | |
440 | ret = ebc->bap[5]; | |
441 | break; | |
442 | case 0x16: /* B6AP */ | |
443 | ret = ebc->bap[6]; | |
444 | break; | |
445 | case 0x17: /* B7AP */ | |
446 | ret = ebc->bap[7]; | |
447 | break; | |
448 | case 0x20: /* BEAR */ | |
449 | ret = ebc->bear; | |
450 | break; | |
451 | case 0x21: /* BESR0 */ | |
452 | ret = ebc->besr0; | |
453 | break; | |
454 | case 0x22: /* BESR1 */ | |
455 | ret = ebc->besr1; | |
456 | break; | |
457 | case 0x23: /* CFG */ | |
458 | ret = ebc->cfg; | |
459 | break; | |
460 | default: | |
461 | ret = 0x00000000; | |
462 | break; | |
463 | } | |
9fad3eb7 | 464 | break; |
8ecc7913 JM |
465 | default: |
466 | ret = 0x00000000; | |
467 | break; | |
468 | } | |
469 | ||
470 | return ret; | |
471 | } | |
472 | ||
73b01960 | 473 | static void dcr_write_ebc (void *opaque, int dcrn, uint32_t val) |
8ecc7913 | 474 | { |
c227f099 | 475 | ppc4xx_ebc_t *ebc; |
8ecc7913 JM |
476 | |
477 | ebc = opaque; | |
478 | switch (dcrn) { | |
479 | case EBC0_CFGADDR: | |
480 | ebc->addr = val; | |
481 | break; | |
482 | case EBC0_CFGDATA: | |
483 | switch (ebc->addr) { | |
484 | case 0x00: /* B0CR */ | |
485 | break; | |
486 | case 0x01: /* B1CR */ | |
487 | break; | |
488 | case 0x02: /* B2CR */ | |
489 | break; | |
490 | case 0x03: /* B3CR */ | |
491 | break; | |
492 | case 0x04: /* B4CR */ | |
493 | break; | |
494 | case 0x05: /* B5CR */ | |
495 | break; | |
496 | case 0x06: /* B6CR */ | |
497 | break; | |
498 | case 0x07: /* B7CR */ | |
499 | break; | |
500 | case 0x10: /* B0AP */ | |
501 | break; | |
502 | case 0x11: /* B1AP */ | |
503 | break; | |
504 | case 0x12: /* B2AP */ | |
505 | break; | |
506 | case 0x13: /* B3AP */ | |
507 | break; | |
508 | case 0x14: /* B4AP */ | |
509 | break; | |
510 | case 0x15: /* B5AP */ | |
511 | break; | |
512 | case 0x16: /* B6AP */ | |
513 | break; | |
514 | case 0x17: /* B7AP */ | |
515 | break; | |
516 | case 0x20: /* BEAR */ | |
517 | break; | |
518 | case 0x21: /* BESR0 */ | |
519 | break; | |
520 | case 0x22: /* BESR1 */ | |
521 | break; | |
522 | case 0x23: /* CFG */ | |
523 | break; | |
524 | default: | |
525 | break; | |
526 | } | |
527 | break; | |
528 | default: | |
529 | break; | |
530 | } | |
531 | } | |
532 | ||
533 | static void ebc_reset (void *opaque) | |
534 | { | |
c227f099 | 535 | ppc4xx_ebc_t *ebc; |
8ecc7913 JM |
536 | int i; |
537 | ||
538 | ebc = opaque; | |
539 | ebc->addr = 0x00000000; | |
540 | ebc->bap[0] = 0x7F8FFE80; | |
541 | ebc->bcr[0] = 0xFFE28000; | |
542 | for (i = 0; i < 8; i++) { | |
543 | ebc->bap[i] = 0x00000000; | |
544 | ebc->bcr[i] = 0x00000000; | |
545 | } | |
546 | ebc->besr0 = 0x00000000; | |
547 | ebc->besr1 = 0x00000000; | |
9c02f1a2 | 548 | ebc->cfg = 0x80400000; |
8ecc7913 JM |
549 | } |
550 | ||
97c2acb5 | 551 | void ppc405_ebc_init(CPUPPCState *env) |
8ecc7913 | 552 | { |
c227f099 | 553 | ppc4xx_ebc_t *ebc; |
8ecc7913 | 554 | |
7267c094 | 555 | ebc = g_malloc0(sizeof(ppc4xx_ebc_t)); |
a08d4367 | 556 | qemu_register_reset(&ebc_reset, ebc); |
487414f1 AL |
557 | ppc_dcr_register(env, EBC0_CFGADDR, |
558 | ebc, &dcr_read_ebc, &dcr_write_ebc); | |
559 | ppc_dcr_register(env, EBC0_CFGDATA, | |
560 | ebc, &dcr_read_ebc, &dcr_write_ebc); | |
8ecc7913 JM |
561 | } |
562 | ||
563 | /*****************************************************************************/ | |
564 | /* DMA controller */ | |
565 | enum { | |
566 | DMA0_CR0 = 0x100, | |
567 | DMA0_CT0 = 0x101, | |
568 | DMA0_DA0 = 0x102, | |
569 | DMA0_SA0 = 0x103, | |
570 | DMA0_SG0 = 0x104, | |
571 | DMA0_CR1 = 0x108, | |
572 | DMA0_CT1 = 0x109, | |
573 | DMA0_DA1 = 0x10A, | |
574 | DMA0_SA1 = 0x10B, | |
575 | DMA0_SG1 = 0x10C, | |
576 | DMA0_CR2 = 0x110, | |
577 | DMA0_CT2 = 0x111, | |
578 | DMA0_DA2 = 0x112, | |
579 | DMA0_SA2 = 0x113, | |
580 | DMA0_SG2 = 0x114, | |
581 | DMA0_CR3 = 0x118, | |
582 | DMA0_CT3 = 0x119, | |
583 | DMA0_DA3 = 0x11A, | |
584 | DMA0_SA3 = 0x11B, | |
585 | DMA0_SG3 = 0x11C, | |
586 | DMA0_SR = 0x120, | |
587 | DMA0_SGC = 0x123, | |
588 | DMA0_SLP = 0x125, | |
589 | DMA0_POL = 0x126, | |
590 | }; | |
591 | ||
c227f099 AL |
592 | typedef struct ppc405_dma_t ppc405_dma_t; |
593 | struct ppc405_dma_t { | |
8ecc7913 JM |
594 | qemu_irq irqs[4]; |
595 | uint32_t cr[4]; | |
596 | uint32_t ct[4]; | |
597 | uint32_t da[4]; | |
598 | uint32_t sa[4]; | |
599 | uint32_t sg[4]; | |
600 | uint32_t sr; | |
601 | uint32_t sgc; | |
602 | uint32_t slp; | |
603 | uint32_t pol; | |
604 | }; | |
605 | ||
73b01960 | 606 | static uint32_t dcr_read_dma (void *opaque, int dcrn) |
8ecc7913 | 607 | { |
8ecc7913 JM |
608 | return 0; |
609 | } | |
610 | ||
73b01960 | 611 | static void dcr_write_dma (void *opaque, int dcrn, uint32_t val) |
8ecc7913 | 612 | { |
8ecc7913 JM |
613 | } |
614 | ||
615 | static void ppc405_dma_reset (void *opaque) | |
616 | { | |
c227f099 | 617 | ppc405_dma_t *dma; |
8ecc7913 JM |
618 | int i; |
619 | ||
620 | dma = opaque; | |
621 | for (i = 0; i < 4; i++) { | |
622 | dma->cr[i] = 0x00000000; | |
623 | dma->ct[i] = 0x00000000; | |
624 | dma->da[i] = 0x00000000; | |
625 | dma->sa[i] = 0x00000000; | |
626 | dma->sg[i] = 0x00000000; | |
627 | } | |
628 | dma->sr = 0x00000000; | |
629 | dma->sgc = 0x00000000; | |
630 | dma->slp = 0x7C000000; | |
631 | dma->pol = 0x00000000; | |
632 | } | |
633 | ||
e2684c0b | 634 | static void ppc405_dma_init(CPUPPCState *env, qemu_irq irqs[4]) |
8ecc7913 | 635 | { |
c227f099 | 636 | ppc405_dma_t *dma; |
8ecc7913 | 637 | |
7267c094 | 638 | dma = g_malloc0(sizeof(ppc405_dma_t)); |
487414f1 | 639 | memcpy(dma->irqs, irqs, 4 * sizeof(qemu_irq)); |
a08d4367 | 640 | qemu_register_reset(&ppc405_dma_reset, dma); |
487414f1 AL |
641 | ppc_dcr_register(env, DMA0_CR0, |
642 | dma, &dcr_read_dma, &dcr_write_dma); | |
643 | ppc_dcr_register(env, DMA0_CT0, | |
644 | dma, &dcr_read_dma, &dcr_write_dma); | |
645 | ppc_dcr_register(env, DMA0_DA0, | |
646 | dma, &dcr_read_dma, &dcr_write_dma); | |
647 | ppc_dcr_register(env, DMA0_SA0, | |
648 | dma, &dcr_read_dma, &dcr_write_dma); | |
649 | ppc_dcr_register(env, DMA0_SG0, | |
650 | dma, &dcr_read_dma, &dcr_write_dma); | |
651 | ppc_dcr_register(env, DMA0_CR1, | |
652 | dma, &dcr_read_dma, &dcr_write_dma); | |
653 | ppc_dcr_register(env, DMA0_CT1, | |
654 | dma, &dcr_read_dma, &dcr_write_dma); | |
655 | ppc_dcr_register(env, DMA0_DA1, | |
656 | dma, &dcr_read_dma, &dcr_write_dma); | |
657 | ppc_dcr_register(env, DMA0_SA1, | |
658 | dma, &dcr_read_dma, &dcr_write_dma); | |
659 | ppc_dcr_register(env, DMA0_SG1, | |
660 | dma, &dcr_read_dma, &dcr_write_dma); | |
661 | ppc_dcr_register(env, DMA0_CR2, | |
662 | dma, &dcr_read_dma, &dcr_write_dma); | |
663 | ppc_dcr_register(env, DMA0_CT2, | |
664 | dma, &dcr_read_dma, &dcr_write_dma); | |
665 | ppc_dcr_register(env, DMA0_DA2, | |
666 | dma, &dcr_read_dma, &dcr_write_dma); | |
667 | ppc_dcr_register(env, DMA0_SA2, | |
668 | dma, &dcr_read_dma, &dcr_write_dma); | |
669 | ppc_dcr_register(env, DMA0_SG2, | |
670 | dma, &dcr_read_dma, &dcr_write_dma); | |
671 | ppc_dcr_register(env, DMA0_CR3, | |
672 | dma, &dcr_read_dma, &dcr_write_dma); | |
673 | ppc_dcr_register(env, DMA0_CT3, | |
674 | dma, &dcr_read_dma, &dcr_write_dma); | |
675 | ppc_dcr_register(env, DMA0_DA3, | |
676 | dma, &dcr_read_dma, &dcr_write_dma); | |
677 | ppc_dcr_register(env, DMA0_SA3, | |
678 | dma, &dcr_read_dma, &dcr_write_dma); | |
679 | ppc_dcr_register(env, DMA0_SG3, | |
680 | dma, &dcr_read_dma, &dcr_write_dma); | |
681 | ppc_dcr_register(env, DMA0_SR, | |
682 | dma, &dcr_read_dma, &dcr_write_dma); | |
683 | ppc_dcr_register(env, DMA0_SGC, | |
684 | dma, &dcr_read_dma, &dcr_write_dma); | |
685 | ppc_dcr_register(env, DMA0_SLP, | |
686 | dma, &dcr_read_dma, &dcr_write_dma); | |
687 | ppc_dcr_register(env, DMA0_POL, | |
688 | dma, &dcr_read_dma, &dcr_write_dma); | |
8ecc7913 JM |
689 | } |
690 | ||
691 | /*****************************************************************************/ | |
692 | /* GPIO */ | |
c227f099 AL |
693 | typedef struct ppc405_gpio_t ppc405_gpio_t; |
694 | struct ppc405_gpio_t { | |
9074e0e3 | 695 | MemoryRegion io; |
8ecc7913 JM |
696 | uint32_t or; |
697 | uint32_t tcr; | |
698 | uint32_t osrh; | |
699 | uint32_t osrl; | |
700 | uint32_t tsrh; | |
701 | uint32_t tsrl; | |
702 | uint32_t odr; | |
703 | uint32_t ir; | |
704 | uint32_t rr1; | |
705 | uint32_t isr1h; | |
706 | uint32_t isr1l; | |
707 | }; | |
708 | ||
69bd18f8 | 709 | static uint64_t ppc405_gpio_read(void *opaque, hwaddr addr, unsigned size) |
8ecc7913 | 710 | { |
8ecc7913 | 711 | #ifdef DEBUG_GPIO |
69bd18f8 | 712 | printf("%s: addr " TARGET_FMT_plx " size %d\n", __func__, addr, size); |
8ecc7913 JM |
713 | #endif |
714 | ||
715 | return 0; | |
716 | } | |
717 | ||
69bd18f8 PM |
718 | static void ppc405_gpio_write(void *opaque, hwaddr addr, uint64_t value, |
719 | unsigned size) | |
8ecc7913 | 720 | { |
8ecc7913 | 721 | #ifdef DEBUG_GPIO |
69bd18f8 PM |
722 | printf("%s: addr " TARGET_FMT_plx " size %d val %08" PRIx32 "\n", |
723 | __func__, addr, size, value); | |
8ecc7913 JM |
724 | #endif |
725 | } | |
726 | ||
9074e0e3 | 727 | static const MemoryRegionOps ppc405_gpio_ops = { |
69bd18f8 PM |
728 | .read = ppc405_gpio_read, |
729 | .write = ppc405_gpio_write, | |
9074e0e3 | 730 | .endianness = DEVICE_NATIVE_ENDIAN, |
8ecc7913 JM |
731 | }; |
732 | ||
733 | static void ppc405_gpio_reset (void *opaque) | |
734 | { | |
8ecc7913 JM |
735 | } |
736 | ||
a8170e5e | 737 | static void ppc405_gpio_init(hwaddr base) |
8ecc7913 | 738 | { |
c227f099 | 739 | ppc405_gpio_t *gpio; |
8ecc7913 | 740 | |
7267c094 | 741 | gpio = g_malloc0(sizeof(ppc405_gpio_t)); |
8ecc7913 | 742 | #ifdef DEBUG_GPIO |
90e189ec | 743 | printf("%s: offset " TARGET_FMT_plx "\n", __func__, base); |
8ecc7913 | 744 | #endif |
2c9b15ca | 745 | memory_region_init_io(&gpio->io, NULL, &ppc405_gpio_ops, gpio, "pgio", 0x038); |
9074e0e3 | 746 | memory_region_add_subregion(get_system_memory(), base, &gpio->io); |
802670e6 | 747 | qemu_register_reset(&ppc405_gpio_reset, gpio); |
8ecc7913 JM |
748 | } |
749 | ||
750 | /*****************************************************************************/ | |
751 | /* On Chip Memory */ | |
752 | enum { | |
753 | OCM0_ISARC = 0x018, | |
754 | OCM0_ISACNTL = 0x019, | |
755 | OCM0_DSARC = 0x01A, | |
756 | OCM0_DSACNTL = 0x01B, | |
757 | }; | |
758 | ||
c227f099 AL |
759 | typedef struct ppc405_ocm_t ppc405_ocm_t; |
760 | struct ppc405_ocm_t { | |
9074e0e3 AK |
761 | MemoryRegion ram; |
762 | MemoryRegion isarc_ram; | |
763 | MemoryRegion dsarc_ram; | |
8ecc7913 JM |
764 | uint32_t isarc; |
765 | uint32_t isacntl; | |
766 | uint32_t dsarc; | |
767 | uint32_t dsacntl; | |
768 | }; | |
769 | ||
c227f099 | 770 | static void ocm_update_mappings (ppc405_ocm_t *ocm, |
8ecc7913 JM |
771 | uint32_t isarc, uint32_t isacntl, |
772 | uint32_t dsarc, uint32_t dsacntl) | |
773 | { | |
774 | #ifdef DEBUG_OCM | |
aae9366a JM |
775 | printf("OCM update ISA %08" PRIx32 " %08" PRIx32 " (%08" PRIx32 |
776 | " %08" PRIx32 ") DSA %08" PRIx32 " %08" PRIx32 | |
777 | " (%08" PRIx32 " %08" PRIx32 ")\n", | |
8ecc7913 JM |
778 | isarc, isacntl, dsarc, dsacntl, |
779 | ocm->isarc, ocm->isacntl, ocm->dsarc, ocm->dsacntl); | |
780 | #endif | |
781 | if (ocm->isarc != isarc || | |
782 | (ocm->isacntl & 0x80000000) != (isacntl & 0x80000000)) { | |
783 | if (ocm->isacntl & 0x80000000) { | |
784 | /* Unmap previously assigned memory region */ | |
aae9366a | 785 | printf("OCM unmap ISA %08" PRIx32 "\n", ocm->isarc); |
9074e0e3 | 786 | memory_region_del_subregion(get_system_memory(), &ocm->isarc_ram); |
8ecc7913 JM |
787 | } |
788 | if (isacntl & 0x80000000) { | |
789 | /* Map new instruction memory region */ | |
790 | #ifdef DEBUG_OCM | |
aae9366a | 791 | printf("OCM map ISA %08" PRIx32 "\n", isarc); |
8ecc7913 | 792 | #endif |
9074e0e3 AK |
793 | memory_region_add_subregion(get_system_memory(), isarc, |
794 | &ocm->isarc_ram); | |
8ecc7913 JM |
795 | } |
796 | } | |
797 | if (ocm->dsarc != dsarc || | |
798 | (ocm->dsacntl & 0x80000000) != (dsacntl & 0x80000000)) { | |
799 | if (ocm->dsacntl & 0x80000000) { | |
800 | /* Beware not to unmap the region we just mapped */ | |
801 | if (!(isacntl & 0x80000000) || ocm->dsarc != isarc) { | |
802 | /* Unmap previously assigned memory region */ | |
803 | #ifdef DEBUG_OCM | |
aae9366a | 804 | printf("OCM unmap DSA %08" PRIx32 "\n", ocm->dsarc); |
8ecc7913 | 805 | #endif |
9074e0e3 AK |
806 | memory_region_del_subregion(get_system_memory(), |
807 | &ocm->dsarc_ram); | |
8ecc7913 JM |
808 | } |
809 | } | |
810 | if (dsacntl & 0x80000000) { | |
811 | /* Beware not to remap the region we just mapped */ | |
812 | if (!(isacntl & 0x80000000) || dsarc != isarc) { | |
813 | /* Map new data memory region */ | |
814 | #ifdef DEBUG_OCM | |
aae9366a | 815 | printf("OCM map DSA %08" PRIx32 "\n", dsarc); |
8ecc7913 | 816 | #endif |
9074e0e3 AK |
817 | memory_region_add_subregion(get_system_memory(), dsarc, |
818 | &ocm->dsarc_ram); | |
8ecc7913 JM |
819 | } |
820 | } | |
821 | } | |
822 | } | |
823 | ||
73b01960 | 824 | static uint32_t dcr_read_ocm (void *opaque, int dcrn) |
8ecc7913 | 825 | { |
c227f099 | 826 | ppc405_ocm_t *ocm; |
73b01960 | 827 | uint32_t ret; |
8ecc7913 JM |
828 | |
829 | ocm = opaque; | |
830 | switch (dcrn) { | |
831 | case OCM0_ISARC: | |
832 | ret = ocm->isarc; | |
833 | break; | |
834 | case OCM0_ISACNTL: | |
835 | ret = ocm->isacntl; | |
836 | break; | |
837 | case OCM0_DSARC: | |
838 | ret = ocm->dsarc; | |
839 | break; | |
840 | case OCM0_DSACNTL: | |
841 | ret = ocm->dsacntl; | |
842 | break; | |
843 | default: | |
844 | ret = 0; | |
845 | break; | |
846 | } | |
847 | ||
848 | return ret; | |
849 | } | |
850 | ||
73b01960 | 851 | static void dcr_write_ocm (void *opaque, int dcrn, uint32_t val) |
8ecc7913 | 852 | { |
c227f099 | 853 | ppc405_ocm_t *ocm; |
8ecc7913 JM |
854 | uint32_t isarc, dsarc, isacntl, dsacntl; |
855 | ||
856 | ocm = opaque; | |
857 | isarc = ocm->isarc; | |
858 | dsarc = ocm->dsarc; | |
859 | isacntl = ocm->isacntl; | |
860 | dsacntl = ocm->dsacntl; | |
861 | switch (dcrn) { | |
862 | case OCM0_ISARC: | |
863 | isarc = val & 0xFC000000; | |
864 | break; | |
865 | case OCM0_ISACNTL: | |
866 | isacntl = val & 0xC0000000; | |
867 | break; | |
868 | case OCM0_DSARC: | |
869 | isarc = val & 0xFC000000; | |
870 | break; | |
871 | case OCM0_DSACNTL: | |
872 | isacntl = val & 0xC0000000; | |
873 | break; | |
874 | } | |
875 | ocm_update_mappings(ocm, isarc, isacntl, dsarc, dsacntl); | |
876 | ocm->isarc = isarc; | |
877 | ocm->dsarc = dsarc; | |
878 | ocm->isacntl = isacntl; | |
879 | ocm->dsacntl = dsacntl; | |
880 | } | |
881 | ||
882 | static void ocm_reset (void *opaque) | |
883 | { | |
c227f099 | 884 | ppc405_ocm_t *ocm; |
8ecc7913 JM |
885 | uint32_t isarc, dsarc, isacntl, dsacntl; |
886 | ||
887 | ocm = opaque; | |
888 | isarc = 0x00000000; | |
889 | isacntl = 0x00000000; | |
890 | dsarc = 0x00000000; | |
891 | dsacntl = 0x00000000; | |
892 | ocm_update_mappings(ocm, isarc, isacntl, dsarc, dsacntl); | |
893 | ocm->isarc = isarc; | |
894 | ocm->dsarc = dsarc; | |
895 | ocm->isacntl = isacntl; | |
896 | ocm->dsacntl = dsacntl; | |
897 | } | |
898 | ||
e2684c0b | 899 | static void ppc405_ocm_init(CPUPPCState *env) |
8ecc7913 | 900 | { |
c227f099 | 901 | ppc405_ocm_t *ocm; |
8ecc7913 | 902 | |
7267c094 | 903 | ocm = g_malloc0(sizeof(ppc405_ocm_t)); |
9074e0e3 | 904 | /* XXX: Size is 4096 or 0x04000000 */ |
ab3dd749 | 905 | memory_region_init_ram(&ocm->isarc_ram, NULL, "ppc405.ocm", 4 * KiB, |
f8ed85ac | 906 | &error_fatal); |
ab3dd749 PMD |
907 | memory_region_init_alias(&ocm->dsarc_ram, NULL, "ppc405.dsarc", |
908 | &ocm->isarc_ram, 0, 4 * KiB); | |
a08d4367 | 909 | qemu_register_reset(&ocm_reset, ocm); |
487414f1 AL |
910 | ppc_dcr_register(env, OCM0_ISARC, |
911 | ocm, &dcr_read_ocm, &dcr_write_ocm); | |
912 | ppc_dcr_register(env, OCM0_ISACNTL, | |
913 | ocm, &dcr_read_ocm, &dcr_write_ocm); | |
914 | ppc_dcr_register(env, OCM0_DSARC, | |
915 | ocm, &dcr_read_ocm, &dcr_write_ocm); | |
916 | ppc_dcr_register(env, OCM0_DSACNTL, | |
917 | ocm, &dcr_read_ocm, &dcr_write_ocm); | |
8ecc7913 JM |
918 | } |
919 | ||
9c02f1a2 JM |
920 | /*****************************************************************************/ |
921 | /* General purpose timers */ | |
c227f099 AL |
922 | typedef struct ppc4xx_gpt_t ppc4xx_gpt_t; |
923 | struct ppc4xx_gpt_t { | |
9074e0e3 | 924 | MemoryRegion iomem; |
9c02f1a2 JM |
925 | int64_t tb_offset; |
926 | uint32_t tb_freq; | |
1246b259 | 927 | QEMUTimer *timer; |
9c02f1a2 JM |
928 | qemu_irq irqs[5]; |
929 | uint32_t oe; | |
930 | uint32_t ol; | |
931 | uint32_t im; | |
932 | uint32_t is; | |
933 | uint32_t ie; | |
934 | uint32_t comp[5]; | |
935 | uint32_t mask[5]; | |
936 | }; | |
937 | ||
c227f099 | 938 | static int ppc4xx_gpt_compare (ppc4xx_gpt_t *gpt, int n) |
9c02f1a2 JM |
939 | { |
940 | /* XXX: TODO */ | |
941 | return 0; | |
942 | } | |
943 | ||
c227f099 | 944 | static void ppc4xx_gpt_set_output (ppc4xx_gpt_t *gpt, int n, int level) |
9c02f1a2 JM |
945 | { |
946 | /* XXX: TODO */ | |
947 | } | |
948 | ||
c227f099 | 949 | static void ppc4xx_gpt_set_outputs (ppc4xx_gpt_t *gpt) |
9c02f1a2 JM |
950 | { |
951 | uint32_t mask; | |
952 | int i; | |
953 | ||
954 | mask = 0x80000000; | |
955 | for (i = 0; i < 5; i++) { | |
956 | if (gpt->oe & mask) { | |
957 | /* Output is enabled */ | |
958 | if (ppc4xx_gpt_compare(gpt, i)) { | |
959 | /* Comparison is OK */ | |
960 | ppc4xx_gpt_set_output(gpt, i, gpt->ol & mask); | |
961 | } else { | |
962 | /* Comparison is KO */ | |
963 | ppc4xx_gpt_set_output(gpt, i, gpt->ol & mask ? 0 : 1); | |
964 | } | |
965 | } | |
966 | mask = mask >> 1; | |
967 | } | |
9c02f1a2 JM |
968 | } |
969 | ||
c227f099 | 970 | static void ppc4xx_gpt_set_irqs (ppc4xx_gpt_t *gpt) |
9c02f1a2 JM |
971 | { |
972 | uint32_t mask; | |
973 | int i; | |
974 | ||
975 | mask = 0x00008000; | |
976 | for (i = 0; i < 5; i++) { | |
977 | if (gpt->is & gpt->im & mask) | |
978 | qemu_irq_raise(gpt->irqs[i]); | |
979 | else | |
980 | qemu_irq_lower(gpt->irqs[i]); | |
981 | mask = mask >> 1; | |
982 | } | |
9c02f1a2 JM |
983 | } |
984 | ||
c227f099 | 985 | static void ppc4xx_gpt_compute_timer (ppc4xx_gpt_t *gpt) |
9c02f1a2 JM |
986 | { |
987 | /* XXX: TODO */ | |
988 | } | |
989 | ||
69bd18f8 | 990 | static uint64_t ppc4xx_gpt_read(void *opaque, hwaddr addr, unsigned size) |
9c02f1a2 | 991 | { |
c227f099 | 992 | ppc4xx_gpt_t *gpt; |
9c02f1a2 JM |
993 | uint32_t ret; |
994 | int idx; | |
995 | ||
996 | #ifdef DEBUG_GPT | |
90e189ec | 997 | printf("%s: addr " TARGET_FMT_plx "\n", __func__, addr); |
9c02f1a2 JM |
998 | #endif |
999 | gpt = opaque; | |
802670e6 | 1000 | switch (addr) { |
9c02f1a2 JM |
1001 | case 0x00: |
1002 | /* Time base counter */ | |
bc72ad67 | 1003 | ret = muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + gpt->tb_offset, |
73bcb24d | 1004 | gpt->tb_freq, NANOSECONDS_PER_SECOND); |
9c02f1a2 JM |
1005 | break; |
1006 | case 0x10: | |
1007 | /* Output enable */ | |
1008 | ret = gpt->oe; | |
1009 | break; | |
1010 | case 0x14: | |
1011 | /* Output level */ | |
1012 | ret = gpt->ol; | |
1013 | break; | |
1014 | case 0x18: | |
1015 | /* Interrupt mask */ | |
1016 | ret = gpt->im; | |
1017 | break; | |
1018 | case 0x1C: | |
1019 | case 0x20: | |
1020 | /* Interrupt status */ | |
1021 | ret = gpt->is; | |
1022 | break; | |
1023 | case 0x24: | |
1024 | /* Interrupt enable */ | |
1025 | ret = gpt->ie; | |
1026 | break; | |
1027 | case 0x80 ... 0x90: | |
1028 | /* Compare timer */ | |
802670e6 | 1029 | idx = (addr - 0x80) >> 2; |
9c02f1a2 JM |
1030 | ret = gpt->comp[idx]; |
1031 | break; | |
1032 | case 0xC0 ... 0xD0: | |
1033 | /* Compare mask */ | |
802670e6 | 1034 | idx = (addr - 0xC0) >> 2; |
9c02f1a2 JM |
1035 | ret = gpt->mask[idx]; |
1036 | break; | |
1037 | default: | |
1038 | ret = -1; | |
1039 | break; | |
1040 | } | |
1041 | ||
1042 | return ret; | |
1043 | } | |
1044 | ||
69bd18f8 PM |
1045 | static void ppc4xx_gpt_write(void *opaque, hwaddr addr, uint64_t value, |
1046 | unsigned size) | |
9c02f1a2 | 1047 | { |
c227f099 | 1048 | ppc4xx_gpt_t *gpt; |
9c02f1a2 JM |
1049 | int idx; |
1050 | ||
1051 | #ifdef DEBUG_I2C | |
90e189ec BS |
1052 | printf("%s: addr " TARGET_FMT_plx " val %08" PRIx32 "\n", __func__, addr, |
1053 | value); | |
9c02f1a2 JM |
1054 | #endif |
1055 | gpt = opaque; | |
802670e6 | 1056 | switch (addr) { |
9c02f1a2 JM |
1057 | case 0x00: |
1058 | /* Time base counter */ | |
73bcb24d | 1059 | gpt->tb_offset = muldiv64(value, NANOSECONDS_PER_SECOND, gpt->tb_freq) |
bc72ad67 | 1060 | - qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); |
9c02f1a2 JM |
1061 | ppc4xx_gpt_compute_timer(gpt); |
1062 | break; | |
1063 | case 0x10: | |
1064 | /* Output enable */ | |
1065 | gpt->oe = value & 0xF8000000; | |
1066 | ppc4xx_gpt_set_outputs(gpt); | |
1067 | break; | |
1068 | case 0x14: | |
1069 | /* Output level */ | |
1070 | gpt->ol = value & 0xF8000000; | |
1071 | ppc4xx_gpt_set_outputs(gpt); | |
1072 | break; | |
1073 | case 0x18: | |
1074 | /* Interrupt mask */ | |
1075 | gpt->im = value & 0x0000F800; | |
1076 | break; | |
1077 | case 0x1C: | |
1078 | /* Interrupt status set */ | |
1079 | gpt->is |= value & 0x0000F800; | |
1080 | ppc4xx_gpt_set_irqs(gpt); | |
1081 | break; | |
1082 | case 0x20: | |
1083 | /* Interrupt status clear */ | |
1084 | gpt->is &= ~(value & 0x0000F800); | |
1085 | ppc4xx_gpt_set_irqs(gpt); | |
1086 | break; | |
1087 | case 0x24: | |
1088 | /* Interrupt enable */ | |
1089 | gpt->ie = value & 0x0000F800; | |
1090 | ppc4xx_gpt_set_irqs(gpt); | |
1091 | break; | |
1092 | case 0x80 ... 0x90: | |
1093 | /* Compare timer */ | |
802670e6 | 1094 | idx = (addr - 0x80) >> 2; |
9c02f1a2 JM |
1095 | gpt->comp[idx] = value & 0xF8000000; |
1096 | ppc4xx_gpt_compute_timer(gpt); | |
1097 | break; | |
1098 | case 0xC0 ... 0xD0: | |
1099 | /* Compare mask */ | |
802670e6 | 1100 | idx = (addr - 0xC0) >> 2; |
9c02f1a2 JM |
1101 | gpt->mask[idx] = value & 0xF8000000; |
1102 | ppc4xx_gpt_compute_timer(gpt); | |
1103 | break; | |
1104 | } | |
1105 | } | |
1106 | ||
9074e0e3 | 1107 | static const MemoryRegionOps gpt_ops = { |
69bd18f8 PM |
1108 | .read = ppc4xx_gpt_read, |
1109 | .write = ppc4xx_gpt_write, | |
1110 | .valid.min_access_size = 4, | |
1111 | .valid.max_access_size = 4, | |
9074e0e3 | 1112 | .endianness = DEVICE_NATIVE_ENDIAN, |
9c02f1a2 JM |
1113 | }; |
1114 | ||
1115 | static void ppc4xx_gpt_cb (void *opaque) | |
1116 | { | |
c227f099 | 1117 | ppc4xx_gpt_t *gpt; |
9c02f1a2 JM |
1118 | |
1119 | gpt = opaque; | |
1120 | ppc4xx_gpt_set_irqs(gpt); | |
1121 | ppc4xx_gpt_set_outputs(gpt); | |
1122 | ppc4xx_gpt_compute_timer(gpt); | |
1123 | } | |
1124 | ||
1125 | static void ppc4xx_gpt_reset (void *opaque) | |
1126 | { | |
c227f099 | 1127 | ppc4xx_gpt_t *gpt; |
9c02f1a2 JM |
1128 | int i; |
1129 | ||
1130 | gpt = opaque; | |
bc72ad67 | 1131 | timer_del(gpt->timer); |
9c02f1a2 JM |
1132 | gpt->oe = 0x00000000; |
1133 | gpt->ol = 0x00000000; | |
1134 | gpt->im = 0x00000000; | |
1135 | gpt->is = 0x00000000; | |
1136 | gpt->ie = 0x00000000; | |
1137 | for (i = 0; i < 5; i++) { | |
1138 | gpt->comp[i] = 0x00000000; | |
1139 | gpt->mask[i] = 0x00000000; | |
1140 | } | |
1141 | } | |
1142 | ||
a8170e5e | 1143 | static void ppc4xx_gpt_init(hwaddr base, qemu_irq irqs[5]) |
9c02f1a2 | 1144 | { |
c227f099 | 1145 | ppc4xx_gpt_t *gpt; |
9c02f1a2 JM |
1146 | int i; |
1147 | ||
7267c094 | 1148 | gpt = g_malloc0(sizeof(ppc4xx_gpt_t)); |
802670e6 | 1149 | for (i = 0; i < 5; i++) { |
487414f1 | 1150 | gpt->irqs[i] = irqs[i]; |
802670e6 | 1151 | } |
bc72ad67 | 1152 | gpt->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, &ppc4xx_gpt_cb, gpt); |
9c02f1a2 | 1153 | #ifdef DEBUG_GPT |
90e189ec | 1154 | printf("%s: offset " TARGET_FMT_plx "\n", __func__, base); |
9c02f1a2 | 1155 | #endif |
2c9b15ca | 1156 | memory_region_init_io(&gpt->iomem, NULL, &gpt_ops, gpt, "gpt", 0x0d4); |
9074e0e3 | 1157 | memory_region_add_subregion(get_system_memory(), base, &gpt->iomem); |
a08d4367 | 1158 | qemu_register_reset(ppc4xx_gpt_reset, gpt); |
9c02f1a2 JM |
1159 | } |
1160 | ||
8ecc7913 JM |
1161 | /*****************************************************************************/ |
1162 | /* PowerPC 405EP */ | |
1163 | /* CPU control */ | |
1164 | enum { | |
1165 | PPC405EP_CPC0_PLLMR0 = 0x0F0, | |
1166 | PPC405EP_CPC0_BOOT = 0x0F1, | |
1167 | PPC405EP_CPC0_EPCTL = 0x0F3, | |
1168 | PPC405EP_CPC0_PLLMR1 = 0x0F4, | |
1169 | PPC405EP_CPC0_UCR = 0x0F5, | |
1170 | PPC405EP_CPC0_SRR = 0x0F6, | |
1171 | PPC405EP_CPC0_JTAGID = 0x0F7, | |
1172 | PPC405EP_CPC0_PCI = 0x0F9, | |
9c02f1a2 JM |
1173 | #if 0 |
1174 | PPC405EP_CPC0_ER = xxx, | |
1175 | PPC405EP_CPC0_FR = xxx, | |
1176 | PPC405EP_CPC0_SR = xxx, | |
1177 | #endif | |
8ecc7913 JM |
1178 | }; |
1179 | ||
04f20795 JM |
1180 | enum { |
1181 | PPC405EP_CPU_CLK = 0, | |
1182 | PPC405EP_PLB_CLK = 1, | |
1183 | PPC405EP_OPB_CLK = 2, | |
1184 | PPC405EP_EBC_CLK = 3, | |
1185 | PPC405EP_MAL_CLK = 4, | |
1186 | PPC405EP_PCI_CLK = 5, | |
1187 | PPC405EP_UART0_CLK = 6, | |
1188 | PPC405EP_UART1_CLK = 7, | |
1189 | PPC405EP_CLK_NB = 8, | |
1190 | }; | |
1191 | ||
c227f099 AL |
1192 | typedef struct ppc405ep_cpc_t ppc405ep_cpc_t; |
1193 | struct ppc405ep_cpc_t { | |
8ecc7913 | 1194 | uint32_t sysclk; |
c227f099 | 1195 | clk_setup_t clk_setup[PPC405EP_CLK_NB]; |
8ecc7913 JM |
1196 | uint32_t boot; |
1197 | uint32_t epctl; | |
1198 | uint32_t pllmr[2]; | |
1199 | uint32_t ucr; | |
1200 | uint32_t srr; | |
1201 | uint32_t jtagid; | |
1202 | uint32_t pci; | |
9c02f1a2 JM |
1203 | /* Clock and power management */ |
1204 | uint32_t er; | |
1205 | uint32_t fr; | |
1206 | uint32_t sr; | |
8ecc7913 JM |
1207 | }; |
1208 | ||
c227f099 | 1209 | static void ppc405ep_compute_clocks (ppc405ep_cpc_t *cpc) |
8ecc7913 JM |
1210 | { |
1211 | uint32_t CPU_clk, PLB_clk, OPB_clk, EBC_clk, MAL_clk, PCI_clk; | |
1212 | uint32_t UART0_clk, UART1_clk; | |
1213 | uint64_t VCO_out, PLL_out; | |
1214 | int M, D; | |
1215 | ||
1216 | VCO_out = 0; | |
1217 | if ((cpc->pllmr[1] & 0x80000000) && !(cpc->pllmr[1] & 0x40000000)) { | |
1218 | M = (((cpc->pllmr[1] >> 20) - 1) & 0xF) + 1; /* FBMUL */ | |
aae9366a JM |
1219 | #ifdef DEBUG_CLOCKS_LL |
1220 | printf("FBMUL %01" PRIx32 " %d\n", (cpc->pllmr[1] >> 20) & 0xF, M); | |
1221 | #endif | |
8ecc7913 | 1222 | D = 8 - ((cpc->pllmr[1] >> 16) & 0x7); /* FWDA */ |
aae9366a JM |
1223 | #ifdef DEBUG_CLOCKS_LL |
1224 | printf("FWDA %01" PRIx32 " %d\n", (cpc->pllmr[1] >> 16) & 0x7, D); | |
1225 | #endif | |
fb6971c1 | 1226 | VCO_out = (uint64_t)cpc->sysclk * M * D; |
8ecc7913 JM |
1227 | if (VCO_out < 500000000UL || VCO_out > 1000000000UL) { |
1228 | /* Error - unlock the PLL */ | |
1229 | printf("VCO out of range %" PRIu64 "\n", VCO_out); | |
1230 | #if 0 | |
1231 | cpc->pllmr[1] &= ~0x80000000; | |
1232 | goto pll_bypass; | |
1233 | #endif | |
1234 | } | |
1235 | PLL_out = VCO_out / D; | |
9c02f1a2 JM |
1236 | /* Pretend the PLL is locked */ |
1237 | cpc->boot |= 0x00000001; | |
8ecc7913 JM |
1238 | } else { |
1239 | #if 0 | |
1240 | pll_bypass: | |
1241 | #endif | |
1242 | PLL_out = cpc->sysclk; | |
9c02f1a2 JM |
1243 | if (cpc->pllmr[1] & 0x40000000) { |
1244 | /* Pretend the PLL is not locked */ | |
1245 | cpc->boot &= ~0x00000001; | |
1246 | } | |
8ecc7913 JM |
1247 | } |
1248 | /* Now, compute all other clocks */ | |
1249 | D = ((cpc->pllmr[0] >> 20) & 0x3) + 1; /* CCDV */ | |
aae9366a JM |
1250 | #ifdef DEBUG_CLOCKS_LL |
1251 | printf("CCDV %01" PRIx32 " %d\n", (cpc->pllmr[0] >> 20) & 0x3, D); | |
8ecc7913 JM |
1252 | #endif |
1253 | CPU_clk = PLL_out / D; | |
1254 | D = ((cpc->pllmr[0] >> 16) & 0x3) + 1; /* CBDV */ | |
aae9366a JM |
1255 | #ifdef DEBUG_CLOCKS_LL |
1256 | printf("CBDV %01" PRIx32 " %d\n", (cpc->pllmr[0] >> 16) & 0x3, D); | |
8ecc7913 JM |
1257 | #endif |
1258 | PLB_clk = CPU_clk / D; | |
1259 | D = ((cpc->pllmr[0] >> 12) & 0x3) + 1; /* OPDV */ | |
aae9366a JM |
1260 | #ifdef DEBUG_CLOCKS_LL |
1261 | printf("OPDV %01" PRIx32 " %d\n", (cpc->pllmr[0] >> 12) & 0x3, D); | |
8ecc7913 JM |
1262 | #endif |
1263 | OPB_clk = PLB_clk / D; | |
1264 | D = ((cpc->pllmr[0] >> 8) & 0x3) + 2; /* EPDV */ | |
aae9366a JM |
1265 | #ifdef DEBUG_CLOCKS_LL |
1266 | printf("EPDV %01" PRIx32 " %d\n", (cpc->pllmr[0] >> 8) & 0x3, D); | |
8ecc7913 JM |
1267 | #endif |
1268 | EBC_clk = PLB_clk / D; | |
1269 | D = ((cpc->pllmr[0] >> 4) & 0x3) + 1; /* MPDV */ | |
aae9366a JM |
1270 | #ifdef DEBUG_CLOCKS_LL |
1271 | printf("MPDV %01" PRIx32 " %d\n", (cpc->pllmr[0] >> 4) & 0x3, D); | |
8ecc7913 JM |
1272 | #endif |
1273 | MAL_clk = PLB_clk / D; | |
1274 | D = (cpc->pllmr[0] & 0x3) + 1; /* PPDV */ | |
aae9366a JM |
1275 | #ifdef DEBUG_CLOCKS_LL |
1276 | printf("PPDV %01" PRIx32 " %d\n", cpc->pllmr[0] & 0x3, D); | |
8ecc7913 JM |
1277 | #endif |
1278 | PCI_clk = PLB_clk / D; | |
1279 | D = ((cpc->ucr - 1) & 0x7F) + 1; /* U0DIV */ | |
aae9366a JM |
1280 | #ifdef DEBUG_CLOCKS_LL |
1281 | printf("U0DIV %01" PRIx32 " %d\n", cpc->ucr & 0x7F, D); | |
8ecc7913 JM |
1282 | #endif |
1283 | UART0_clk = PLL_out / D; | |
1284 | D = (((cpc->ucr >> 8) - 1) & 0x7F) + 1; /* U1DIV */ | |
aae9366a JM |
1285 | #ifdef DEBUG_CLOCKS_LL |
1286 | printf("U1DIV %01" PRIx32 " %d\n", (cpc->ucr >> 8) & 0x7F, D); | |
8ecc7913 JM |
1287 | #endif |
1288 | UART1_clk = PLL_out / D; | |
1289 | #ifdef DEBUG_CLOCKS | |
aae9366a | 1290 | printf("Setup PPC405EP clocks - sysclk %" PRIu32 " VCO %" PRIu64 |
8ecc7913 | 1291 | " PLL out %" PRIu64 " Hz\n", cpc->sysclk, VCO_out, PLL_out); |
aae9366a JM |
1292 | printf("CPU %" PRIu32 " PLB %" PRIu32 " OPB %" PRIu32 " EBC %" PRIu32 |
1293 | " MAL %" PRIu32 " PCI %" PRIu32 " UART0 %" PRIu32 | |
1294 | " UART1 %" PRIu32 "\n", | |
8ecc7913 JM |
1295 | CPU_clk, PLB_clk, OPB_clk, EBC_clk, MAL_clk, PCI_clk, |
1296 | UART0_clk, UART1_clk); | |
1297 | #endif | |
1298 | /* Setup CPU clocks */ | |
04f20795 | 1299 | clk_setup(&cpc->clk_setup[PPC405EP_CPU_CLK], CPU_clk); |
8ecc7913 | 1300 | /* Setup PLB clock */ |
04f20795 | 1301 | clk_setup(&cpc->clk_setup[PPC405EP_PLB_CLK], PLB_clk); |
8ecc7913 | 1302 | /* Setup OPB clock */ |
04f20795 | 1303 | clk_setup(&cpc->clk_setup[PPC405EP_OPB_CLK], OPB_clk); |
8ecc7913 | 1304 | /* Setup external clock */ |
04f20795 | 1305 | clk_setup(&cpc->clk_setup[PPC405EP_EBC_CLK], EBC_clk); |
8ecc7913 | 1306 | /* Setup MAL clock */ |
04f20795 | 1307 | clk_setup(&cpc->clk_setup[PPC405EP_MAL_CLK], MAL_clk); |
8ecc7913 | 1308 | /* Setup PCI clock */ |
04f20795 | 1309 | clk_setup(&cpc->clk_setup[PPC405EP_PCI_CLK], PCI_clk); |
8ecc7913 | 1310 | /* Setup UART0 clock */ |
04f20795 | 1311 | clk_setup(&cpc->clk_setup[PPC405EP_UART0_CLK], UART0_clk); |
8ecc7913 | 1312 | /* Setup UART1 clock */ |
04f20795 | 1313 | clk_setup(&cpc->clk_setup[PPC405EP_UART1_CLK], UART1_clk); |
8ecc7913 JM |
1314 | } |
1315 | ||
73b01960 | 1316 | static uint32_t dcr_read_epcpc (void *opaque, int dcrn) |
8ecc7913 | 1317 | { |
c227f099 | 1318 | ppc405ep_cpc_t *cpc; |
73b01960 | 1319 | uint32_t ret; |
8ecc7913 JM |
1320 | |
1321 | cpc = opaque; | |
1322 | switch (dcrn) { | |
1323 | case PPC405EP_CPC0_BOOT: | |
1324 | ret = cpc->boot; | |
1325 | break; | |
1326 | case PPC405EP_CPC0_EPCTL: | |
1327 | ret = cpc->epctl; | |
1328 | break; | |
1329 | case PPC405EP_CPC0_PLLMR0: | |
1330 | ret = cpc->pllmr[0]; | |
1331 | break; | |
1332 | case PPC405EP_CPC0_PLLMR1: | |
1333 | ret = cpc->pllmr[1]; | |
1334 | break; | |
1335 | case PPC405EP_CPC0_UCR: | |
1336 | ret = cpc->ucr; | |
1337 | break; | |
1338 | case PPC405EP_CPC0_SRR: | |
1339 | ret = cpc->srr; | |
1340 | break; | |
1341 | case PPC405EP_CPC0_JTAGID: | |
1342 | ret = cpc->jtagid; | |
1343 | break; | |
1344 | case PPC405EP_CPC0_PCI: | |
1345 | ret = cpc->pci; | |
1346 | break; | |
1347 | default: | |
1348 | /* Avoid gcc warning */ | |
1349 | ret = 0; | |
1350 | break; | |
1351 | } | |
1352 | ||
1353 | return ret; | |
1354 | } | |
1355 | ||
73b01960 | 1356 | static void dcr_write_epcpc (void *opaque, int dcrn, uint32_t val) |
8ecc7913 | 1357 | { |
c227f099 | 1358 | ppc405ep_cpc_t *cpc; |
8ecc7913 JM |
1359 | |
1360 | cpc = opaque; | |
1361 | switch (dcrn) { | |
1362 | case PPC405EP_CPC0_BOOT: | |
1363 | /* Read-only register */ | |
1364 | break; | |
1365 | case PPC405EP_CPC0_EPCTL: | |
1366 | /* Don't care for now */ | |
1367 | cpc->epctl = val & 0xC00000F3; | |
1368 | break; | |
1369 | case PPC405EP_CPC0_PLLMR0: | |
1370 | cpc->pllmr[0] = val & 0x00633333; | |
1371 | ppc405ep_compute_clocks(cpc); | |
1372 | break; | |
1373 | case PPC405EP_CPC0_PLLMR1: | |
1374 | cpc->pllmr[1] = val & 0xC0F73FFF; | |
1375 | ppc405ep_compute_clocks(cpc); | |
1376 | break; | |
1377 | case PPC405EP_CPC0_UCR: | |
1378 | /* UART control - don't care for now */ | |
1379 | cpc->ucr = val & 0x003F7F7F; | |
1380 | break; | |
1381 | case PPC405EP_CPC0_SRR: | |
1382 | cpc->srr = val; | |
1383 | break; | |
1384 | case PPC405EP_CPC0_JTAGID: | |
1385 | /* Read-only */ | |
1386 | break; | |
1387 | case PPC405EP_CPC0_PCI: | |
1388 | cpc->pci = val; | |
1389 | break; | |
1390 | } | |
1391 | } | |
1392 | ||
1393 | static void ppc405ep_cpc_reset (void *opaque) | |
1394 | { | |
c227f099 | 1395 | ppc405ep_cpc_t *cpc = opaque; |
8ecc7913 JM |
1396 | |
1397 | cpc->boot = 0x00000010; /* Boot from PCI - IIC EEPROM disabled */ | |
1398 | cpc->epctl = 0x00000000; | |
1399 | cpc->pllmr[0] = 0x00011010; | |
1400 | cpc->pllmr[1] = 0x40000000; | |
1401 | cpc->ucr = 0x00000000; | |
1402 | cpc->srr = 0x00040000; | |
1403 | cpc->pci = 0x00000000; | |
9c02f1a2 JM |
1404 | cpc->er = 0x00000000; |
1405 | cpc->fr = 0x00000000; | |
1406 | cpc->sr = 0x00000000; | |
8ecc7913 JM |
1407 | ppc405ep_compute_clocks(cpc); |
1408 | } | |
1409 | ||
1410 | /* XXX: sysclk should be between 25 and 100 MHz */ | |
e2684c0b | 1411 | static void ppc405ep_cpc_init (CPUPPCState *env, clk_setup_t clk_setup[8], |
8ecc7913 JM |
1412 | uint32_t sysclk) |
1413 | { | |
c227f099 | 1414 | ppc405ep_cpc_t *cpc; |
8ecc7913 | 1415 | |
7267c094 | 1416 | cpc = g_malloc0(sizeof(ppc405ep_cpc_t)); |
487414f1 | 1417 | memcpy(cpc->clk_setup, clk_setup, |
c227f099 | 1418 | PPC405EP_CLK_NB * sizeof(clk_setup_t)); |
487414f1 AL |
1419 | cpc->jtagid = 0x20267049; |
1420 | cpc->sysclk = sysclk; | |
a08d4367 | 1421 | qemu_register_reset(&ppc405ep_cpc_reset, cpc); |
487414f1 AL |
1422 | ppc_dcr_register(env, PPC405EP_CPC0_BOOT, cpc, |
1423 | &dcr_read_epcpc, &dcr_write_epcpc); | |
1424 | ppc_dcr_register(env, PPC405EP_CPC0_EPCTL, cpc, | |
1425 | &dcr_read_epcpc, &dcr_write_epcpc); | |
1426 | ppc_dcr_register(env, PPC405EP_CPC0_PLLMR0, cpc, | |
1427 | &dcr_read_epcpc, &dcr_write_epcpc); | |
1428 | ppc_dcr_register(env, PPC405EP_CPC0_PLLMR1, cpc, | |
1429 | &dcr_read_epcpc, &dcr_write_epcpc); | |
1430 | ppc_dcr_register(env, PPC405EP_CPC0_UCR, cpc, | |
1431 | &dcr_read_epcpc, &dcr_write_epcpc); | |
1432 | ppc_dcr_register(env, PPC405EP_CPC0_SRR, cpc, | |
1433 | &dcr_read_epcpc, &dcr_write_epcpc); | |
1434 | ppc_dcr_register(env, PPC405EP_CPC0_JTAGID, cpc, | |
1435 | &dcr_read_epcpc, &dcr_write_epcpc); | |
1436 | ppc_dcr_register(env, PPC405EP_CPC0_PCI, cpc, | |
1437 | &dcr_read_epcpc, &dcr_write_epcpc); | |
9c02f1a2 | 1438 | #if 0 |
487414f1 AL |
1439 | ppc_dcr_register(env, PPC405EP_CPC0_ER, cpc, |
1440 | &dcr_read_epcpc, &dcr_write_epcpc); | |
1441 | ppc_dcr_register(env, PPC405EP_CPC0_FR, cpc, | |
1442 | &dcr_read_epcpc, &dcr_write_epcpc); | |
1443 | ppc_dcr_register(env, PPC405EP_CPC0_SR, cpc, | |
1444 | &dcr_read_epcpc, &dcr_write_epcpc); | |
9c02f1a2 | 1445 | #endif |
8ecc7913 JM |
1446 | } |
1447 | ||
e2684c0b | 1448 | CPUPPCState *ppc405ep_init(MemoryRegion *address_space_mem, |
52ce55a1 | 1449 | MemoryRegion ram_memories[2], |
a8170e5e AK |
1450 | hwaddr ram_bases[2], |
1451 | hwaddr ram_sizes[2], | |
71c3c44b | 1452 | uint32_t sysclk, DeviceState **uicdevp, |
52ce55a1 | 1453 | int do_init) |
8ecc7913 | 1454 | { |
c227f099 | 1455 | clk_setup_t clk_setup[PPC405EP_CLK_NB], tlb_clk_setup; |
9c02f1a2 | 1456 | qemu_irq dma_irqs[4], gpt_irqs[5], mal_irqs[4]; |
2f9859fb | 1457 | PowerPCCPU *cpu; |
e2684c0b | 1458 | CPUPPCState *env; |
71c3c44b PM |
1459 | DeviceState *uicdev; |
1460 | SysBusDevice *uicsbd; | |
8ecc7913 JM |
1461 | |
1462 | memset(clk_setup, 0, sizeof(clk_setup)); | |
1463 | /* init CPUs */ | |
9391b8c5 IM |
1464 | cpu = ppc4xx_init(POWERPC_CPU_TYPE_NAME("405ep"), |
1465 | &clk_setup[PPC405EP_CPU_CLK], | |
9c02f1a2 | 1466 | &tlb_clk_setup, sysclk); |
2f9859fb | 1467 | env = &cpu->env; |
9c02f1a2 JM |
1468 | clk_setup[PPC405EP_CPU_CLK].cb = tlb_clk_setup.cb; |
1469 | clk_setup[PPC405EP_CPU_CLK].opaque = tlb_clk_setup.opaque; | |
8ecc7913 JM |
1470 | /* Internal devices init */ |
1471 | /* Memory mapped devices registers */ | |
8ecc7913 JM |
1472 | /* PLB arbitrer */ |
1473 | ppc4xx_plb_init(env); | |
1474 | /* PLB to OPB bridge */ | |
1475 | ppc4xx_pob_init(env); | |
1476 | /* OBP arbitrer */ | |
802670e6 | 1477 | ppc4xx_opba_init(0xef600600); |
d715ea96 | 1478 | /* Initialize timers */ |
a34a92b9 | 1479 | ppc_booke_timers_init(cpu, sysclk, 0); |
8ecc7913 | 1480 | /* Universal interrupt controller */ |
71c3c44b PM |
1481 | uicdev = qdev_new(TYPE_PPC_UIC); |
1482 | uicsbd = SYS_BUS_DEVICE(uicdev); | |
1483 | ||
1484 | object_property_set_link(OBJECT(uicdev), "cpu", OBJECT(cpu), | |
1485 | &error_fatal); | |
1486 | sysbus_realize_and_unref(uicsbd, &error_fatal); | |
1487 | ||
1488 | sysbus_connect_irq(uicsbd, PPCUIC_OUTPUT_INT, | |
1489 | ((qemu_irq *)env->irq_inputs)[PPC40x_INPUT_INT]); | |
1490 | sysbus_connect_irq(uicsbd, PPCUIC_OUTPUT_CINT, | |
1491 | ((qemu_irq *)env->irq_inputs)[PPC40x_INPUT_CINT]); | |
1492 | ||
1493 | *uicdevp = uicdev; | |
1494 | ||
8ecc7913 | 1495 | /* SDRAM controller */ |
7d37435b | 1496 | /* XXX 405EP has no ECC interrupt */ |
71c3c44b | 1497 | ppc4xx_sdram_init(env, qdev_get_gpio_in(uicdev, 17), 2, ram_memories, |
b6dcbe08 | 1498 | ram_bases, ram_sizes, do_init); |
8ecc7913 JM |
1499 | /* External bus controller */ |
1500 | ppc405_ebc_init(env); | |
1501 | /* DMA controller */ | |
71c3c44b PM |
1502 | dma_irqs[0] = qdev_get_gpio_in(uicdev, 5); |
1503 | dma_irqs[1] = qdev_get_gpio_in(uicdev, 6); | |
1504 | dma_irqs[2] = qdev_get_gpio_in(uicdev, 7); | |
1505 | dma_irqs[3] = qdev_get_gpio_in(uicdev, 8); | |
8ecc7913 JM |
1506 | ppc405_dma_init(env, dma_irqs); |
1507 | /* IIC controller */ | |
71c3c44b PM |
1508 | sysbus_create_simple(TYPE_PPC4xx_I2C, 0xef600500, |
1509 | qdev_get_gpio_in(uicdev, 2)); | |
8ecc7913 | 1510 | /* GPIO */ |
802670e6 | 1511 | ppc405_gpio_init(0xef600700); |
8ecc7913 | 1512 | /* Serial ports */ |
9bca0edb | 1513 | if (serial_hd(0) != NULL) { |
71c3c44b PM |
1514 | serial_mm_init(address_space_mem, 0xef600300, 0, |
1515 | qdev_get_gpio_in(uicdev, 0), | |
9bca0edb | 1516 | PPC_SERIAL_MM_BAUDBASE, serial_hd(0), |
39186d8a | 1517 | DEVICE_BIG_ENDIAN); |
8ecc7913 | 1518 | } |
9bca0edb | 1519 | if (serial_hd(1) != NULL) { |
71c3c44b PM |
1520 | serial_mm_init(address_space_mem, 0xef600400, 0, |
1521 | qdev_get_gpio_in(uicdev, 1), | |
9bca0edb | 1522 | PPC_SERIAL_MM_BAUDBASE, serial_hd(1), |
39186d8a | 1523 | DEVICE_BIG_ENDIAN); |
8ecc7913 JM |
1524 | } |
1525 | /* OCM */ | |
5c130f65 | 1526 | ppc405_ocm_init(env); |
9c02f1a2 | 1527 | /* GPT */ |
71c3c44b PM |
1528 | gpt_irqs[0] = qdev_get_gpio_in(uicdev, 19); |
1529 | gpt_irqs[1] = qdev_get_gpio_in(uicdev, 20); | |
1530 | gpt_irqs[2] = qdev_get_gpio_in(uicdev, 21); | |
1531 | gpt_irqs[3] = qdev_get_gpio_in(uicdev, 22); | |
1532 | gpt_irqs[4] = qdev_get_gpio_in(uicdev, 23); | |
802670e6 | 1533 | ppc4xx_gpt_init(0xef600000, gpt_irqs); |
8ecc7913 | 1534 | /* PCI */ |
71c3c44b | 1535 | /* Uses UIC IRQs 3, 16, 18 */ |
9c02f1a2 | 1536 | /* MAL */ |
71c3c44b PM |
1537 | mal_irqs[0] = qdev_get_gpio_in(uicdev, 11); |
1538 | mal_irqs[1] = qdev_get_gpio_in(uicdev, 12); | |
1539 | mal_irqs[2] = qdev_get_gpio_in(uicdev, 13); | |
1540 | mal_irqs[3] = qdev_get_gpio_in(uicdev, 14); | |
04534280 | 1541 | ppc4xx_mal_init(env, 4, 2, mal_irqs); |
9c02f1a2 | 1542 | /* Ethernet */ |
71c3c44b | 1543 | /* Uses UIC IRQs 9, 15, 17 */ |
8ecc7913 JM |
1544 | /* CPU control */ |
1545 | ppc405ep_cpc_init(env, clk_setup, sysclk); | |
8ecc7913 JM |
1546 | |
1547 | return env; | |
1548 | } |