]>
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 | */ | |
0d75590d | 24 | #include "qemu/osdep.h" |
ab3dd749 | 25 | #include "qemu/units.h" |
da34e65c | 26 | #include "qapi/error.h" |
4771d756 PB |
27 | #include "qemu-common.h" |
28 | #include "cpu.h" | |
83c9f4ca | 29 | #include "hw/hw.h" |
0d09e41a | 30 | #include "hw/ppc/ppc.h" |
e938ba0c | 31 | #include "hw/boards.h" |
3b09bb0f | 32 | #include "hw/i2c/ppc4xx_i2c.h" |
47b43a1f | 33 | #include "ppc405.h" |
0d09e41a | 34 | #include "hw/char/serial.h" |
1de7afc9 | 35 | #include "qemu/timer.h" |
9c17d615 | 36 | #include "sysemu/sysemu.h" |
1de7afc9 | 37 | #include "qemu/log.h" |
022c62cb | 38 | #include "exec/address-spaces.h" |
8ecc7913 | 39 | |
0d84382e AF |
40 | //#define DEBUG_OPBA |
41 | //#define DEBUG_SDRAM | |
42 | //#define DEBUG_GPIO | |
43 | //#define DEBUG_SERIAL | |
44 | //#define DEBUG_OCM | |
0d84382e | 45 | //#define DEBUG_GPT |
0d84382e | 46 | //#define DEBUG_CLOCKS |
aae9366a | 47 | //#define DEBUG_CLOCKS_LL |
8ecc7913 | 48 | |
e2684c0b | 49 | ram_addr_t ppc405_set_bootinfo (CPUPPCState *env, ppc4xx_bd_info_t *bd, |
b8d3f5d1 | 50 | uint32_t flags) |
04f20795 | 51 | { |
33276f1b | 52 | CPUState *cs = CPU(ppc_env_get_cpu(env)); |
c227f099 | 53 | ram_addr_t bdloc; |
04f20795 JM |
54 | int i, n; |
55 | ||
56 | /* We put the bd structure at the top of memory */ | |
be58fc7c | 57 | if (bd->bi_memsize >= 0x01000000UL) |
c227f099 | 58 | bdloc = 0x01000000UL - sizeof(struct ppc4xx_bd_info_t); |
be58fc7c | 59 | else |
c227f099 | 60 | bdloc = bd->bi_memsize - sizeof(struct ppc4xx_bd_info_t); |
ab1da857 EI |
61 | stl_be_phys(cs->as, bdloc + 0x00, bd->bi_memstart); |
62 | stl_be_phys(cs->as, bdloc + 0x04, bd->bi_memsize); | |
63 | stl_be_phys(cs->as, bdloc + 0x08, bd->bi_flashstart); | |
64 | stl_be_phys(cs->as, bdloc + 0x0C, bd->bi_flashsize); | |
65 | stl_be_phys(cs->as, bdloc + 0x10, bd->bi_flashoffset); | |
66 | stl_be_phys(cs->as, bdloc + 0x14, bd->bi_sramstart); | |
67 | stl_be_phys(cs->as, bdloc + 0x18, bd->bi_sramsize); | |
68 | stl_be_phys(cs->as, bdloc + 0x1C, bd->bi_bootflags); | |
69 | stl_be_phys(cs->as, bdloc + 0x20, bd->bi_ipaddr); | |
db663d0f | 70 | for (i = 0; i < 6; i++) { |
db3be60d | 71 | stb_phys(cs->as, bdloc + 0x24 + i, bd->bi_enetaddr[i]); |
db663d0f | 72 | } |
5ce5944d | 73 | stw_be_phys(cs->as, bdloc + 0x2A, bd->bi_ethspeed); |
ab1da857 EI |
74 | stl_be_phys(cs->as, bdloc + 0x2C, bd->bi_intfreq); |
75 | stl_be_phys(cs->as, bdloc + 0x30, bd->bi_busfreq); | |
76 | stl_be_phys(cs->as, bdloc + 0x34, bd->bi_baudrate); | |
db663d0f | 77 | for (i = 0; i < 4; i++) { |
db3be60d | 78 | stb_phys(cs->as, bdloc + 0x38 + i, bd->bi_s_version[i]); |
db663d0f | 79 | } |
4508d81a | 80 | for (i = 0; i < 32; i++) { |
db3be60d | 81 | stb_phys(cs->as, bdloc + 0x3C + i, bd->bi_r_version[i]); |
4508d81a | 82 | } |
ab1da857 EI |
83 | stl_be_phys(cs->as, bdloc + 0x5C, bd->bi_plb_busfreq); |
84 | stl_be_phys(cs->as, bdloc + 0x60, bd->bi_pci_busfreq); | |
db663d0f | 85 | for (i = 0; i < 6; i++) { |
db3be60d | 86 | stb_phys(cs->as, bdloc + 0x64 + i, bd->bi_pci_enetaddr[i]); |
db663d0f | 87 | } |
04f20795 | 88 | n = 0x6A; |
b8d3f5d1 | 89 | if (flags & 0x00000001) { |
04f20795 | 90 | for (i = 0; i < 6; i++) |
db3be60d | 91 | stb_phys(cs->as, bdloc + n++, bd->bi_pci_enetaddr2[i]); |
04f20795 | 92 | } |
ab1da857 | 93 | stl_be_phys(cs->as, bdloc + n, bd->bi_opbfreq); |
04f20795 JM |
94 | n += 4; |
95 | for (i = 0; i < 2; i++) { | |
ab1da857 | 96 | stl_be_phys(cs->as, bdloc + n, bd->bi_iic_fast[i]); |
04f20795 JM |
97 | n += 4; |
98 | } | |
99 | ||
100 | return bdloc; | |
101 | } | |
102 | ||
8ecc7913 JM |
103 | /*****************************************************************************/ |
104 | /* Shared peripherals */ | |
105 | ||
8ecc7913 JM |
106 | /*****************************************************************************/ |
107 | /* Peripheral local bus arbitrer */ | |
108 | enum { | |
4c46f372 BZ |
109 | PLB3A0_ACR = 0x077, |
110 | PLB4A0_ACR = 0x081, | |
111 | PLB0_BESR = 0x084, | |
112 | PLB0_BEAR = 0x086, | |
113 | PLB0_ACR = 0x087, | |
114 | PLB4A1_ACR = 0x089, | |
8ecc7913 JM |
115 | }; |
116 | ||
c227f099 AL |
117 | typedef struct ppc4xx_plb_t ppc4xx_plb_t; |
118 | struct ppc4xx_plb_t { | |
8ecc7913 JM |
119 | uint32_t acr; |
120 | uint32_t bear; | |
121 | uint32_t besr; | |
122 | }; | |
123 | ||
73b01960 | 124 | static uint32_t dcr_read_plb (void *opaque, int dcrn) |
8ecc7913 | 125 | { |
c227f099 | 126 | ppc4xx_plb_t *plb; |
73b01960 | 127 | uint32_t ret; |
8ecc7913 JM |
128 | |
129 | plb = opaque; | |
130 | switch (dcrn) { | |
131 | case PLB0_ACR: | |
132 | ret = plb->acr; | |
133 | break; | |
134 | case PLB0_BEAR: | |
135 | ret = plb->bear; | |
136 | break; | |
137 | case PLB0_BESR: | |
138 | ret = plb->besr; | |
139 | break; | |
140 | default: | |
141 | /* Avoid gcc warning */ | |
142 | ret = 0; | |
143 | break; | |
144 | } | |
145 | ||
146 | return ret; | |
147 | } | |
148 | ||
73b01960 | 149 | static void dcr_write_plb (void *opaque, int dcrn, uint32_t val) |
8ecc7913 | 150 | { |
c227f099 | 151 | ppc4xx_plb_t *plb; |
8ecc7913 JM |
152 | |
153 | plb = opaque; | |
154 | switch (dcrn) { | |
155 | case PLB0_ACR: | |
9c02f1a2 JM |
156 | /* We don't care about the actual parameters written as |
157 | * we don't manage any priorities on the bus | |
158 | */ | |
159 | plb->acr = val & 0xF8000000; | |
8ecc7913 JM |
160 | break; |
161 | case PLB0_BEAR: | |
162 | /* Read only */ | |
163 | break; | |
164 | case PLB0_BESR: | |
165 | /* Write-clear */ | |
166 | plb->besr &= ~val; | |
167 | break; | |
168 | } | |
169 | } | |
170 | ||
171 | static void ppc4xx_plb_reset (void *opaque) | |
172 | { | |
c227f099 | 173 | ppc4xx_plb_t *plb; |
8ecc7913 JM |
174 | |
175 | plb = opaque; | |
176 | plb->acr = 0x00000000; | |
177 | plb->bear = 0x00000000; | |
178 | plb->besr = 0x00000000; | |
179 | } | |
180 | ||
97c2acb5 | 181 | void ppc4xx_plb_init(CPUPPCState *env) |
8ecc7913 | 182 | { |
c227f099 | 183 | ppc4xx_plb_t *plb; |
8ecc7913 | 184 | |
7267c094 | 185 | plb = g_malloc0(sizeof(ppc4xx_plb_t)); |
4c46f372 BZ |
186 | ppc_dcr_register(env, PLB3A0_ACR, plb, &dcr_read_plb, &dcr_write_plb); |
187 | ppc_dcr_register(env, PLB4A0_ACR, plb, &dcr_read_plb, &dcr_write_plb); | |
487414f1 AL |
188 | ppc_dcr_register(env, PLB0_ACR, plb, &dcr_read_plb, &dcr_write_plb); |
189 | ppc_dcr_register(env, PLB0_BEAR, plb, &dcr_read_plb, &dcr_write_plb); | |
190 | ppc_dcr_register(env, PLB0_BESR, plb, &dcr_read_plb, &dcr_write_plb); | |
4c46f372 | 191 | ppc_dcr_register(env, PLB4A1_ACR, plb, &dcr_read_plb, &dcr_write_plb); |
a08d4367 | 192 | qemu_register_reset(ppc4xx_plb_reset, plb); |
8ecc7913 JM |
193 | } |
194 | ||
195 | /*****************************************************************************/ | |
196 | /* PLB to OPB bridge */ | |
197 | enum { | |
198 | POB0_BESR0 = 0x0A0, | |
199 | POB0_BESR1 = 0x0A2, | |
200 | POB0_BEAR = 0x0A4, | |
201 | }; | |
202 | ||
c227f099 AL |
203 | typedef struct ppc4xx_pob_t ppc4xx_pob_t; |
204 | struct ppc4xx_pob_t { | |
8ecc7913 | 205 | uint32_t bear; |
5a1972c8 SW |
206 | uint32_t besr0; |
207 | uint32_t besr1; | |
8ecc7913 JM |
208 | }; |
209 | ||
73b01960 | 210 | static uint32_t dcr_read_pob (void *opaque, int dcrn) |
8ecc7913 | 211 | { |
c227f099 | 212 | ppc4xx_pob_t *pob; |
73b01960 | 213 | uint32_t ret; |
8ecc7913 JM |
214 | |
215 | pob = opaque; | |
216 | switch (dcrn) { | |
217 | case POB0_BEAR: | |
218 | ret = pob->bear; | |
219 | break; | |
220 | case POB0_BESR0: | |
5a1972c8 SW |
221 | ret = pob->besr0; |
222 | break; | |
8ecc7913 | 223 | case POB0_BESR1: |
5a1972c8 | 224 | ret = pob->besr1; |
8ecc7913 JM |
225 | break; |
226 | default: | |
227 | /* Avoid gcc warning */ | |
228 | ret = 0; | |
229 | break; | |
230 | } | |
231 | ||
232 | return ret; | |
233 | } | |
234 | ||
73b01960 | 235 | static void dcr_write_pob (void *opaque, int dcrn, uint32_t val) |
8ecc7913 | 236 | { |
c227f099 | 237 | ppc4xx_pob_t *pob; |
8ecc7913 JM |
238 | |
239 | pob = opaque; | |
240 | switch (dcrn) { | |
241 | case POB0_BEAR: | |
242 | /* Read only */ | |
243 | break; | |
244 | case POB0_BESR0: | |
5a1972c8 SW |
245 | /* Write-clear */ |
246 | pob->besr0 &= ~val; | |
247 | break; | |
8ecc7913 JM |
248 | case POB0_BESR1: |
249 | /* Write-clear */ | |
5a1972c8 | 250 | pob->besr1 &= ~val; |
8ecc7913 JM |
251 | break; |
252 | } | |
253 | } | |
254 | ||
255 | static void ppc4xx_pob_reset (void *opaque) | |
256 | { | |
c227f099 | 257 | ppc4xx_pob_t *pob; |
8ecc7913 JM |
258 | |
259 | pob = opaque; | |
260 | /* No error */ | |
261 | pob->bear = 0x00000000; | |
5a1972c8 SW |
262 | pob->besr0 = 0x0000000; |
263 | pob->besr1 = 0x0000000; | |
8ecc7913 JM |
264 | } |
265 | ||
e2684c0b | 266 | static void ppc4xx_pob_init(CPUPPCState *env) |
8ecc7913 | 267 | { |
c227f099 | 268 | ppc4xx_pob_t *pob; |
8ecc7913 | 269 | |
7267c094 | 270 | pob = g_malloc0(sizeof(ppc4xx_pob_t)); |
487414f1 AL |
271 | ppc_dcr_register(env, POB0_BEAR, pob, &dcr_read_pob, &dcr_write_pob); |
272 | ppc_dcr_register(env, POB0_BESR0, pob, &dcr_read_pob, &dcr_write_pob); | |
273 | ppc_dcr_register(env, POB0_BESR1, pob, &dcr_read_pob, &dcr_write_pob); | |
a08d4367 | 274 | qemu_register_reset(ppc4xx_pob_reset, pob); |
8ecc7913 JM |
275 | } |
276 | ||
277 | /*****************************************************************************/ | |
278 | /* OPB arbitrer */ | |
c227f099 AL |
279 | typedef struct ppc4xx_opba_t ppc4xx_opba_t; |
280 | struct ppc4xx_opba_t { | |
9074e0e3 | 281 | MemoryRegion io; |
8ecc7913 JM |
282 | uint8_t cr; |
283 | uint8_t pr; | |
284 | }; | |
285 | ||
a8170e5e | 286 | static uint32_t opba_readb (void *opaque, hwaddr addr) |
8ecc7913 | 287 | { |
c227f099 | 288 | ppc4xx_opba_t *opba; |
8ecc7913 JM |
289 | uint32_t ret; |
290 | ||
291 | #ifdef DEBUG_OPBA | |
90e189ec | 292 | printf("%s: addr " TARGET_FMT_plx "\n", __func__, addr); |
8ecc7913 JM |
293 | #endif |
294 | opba = opaque; | |
802670e6 | 295 | switch (addr) { |
8ecc7913 JM |
296 | case 0x00: |
297 | ret = opba->cr; | |
298 | break; | |
299 | case 0x01: | |
300 | ret = opba->pr; | |
301 | break; | |
302 | default: | |
303 | ret = 0x00; | |
304 | break; | |
305 | } | |
306 | ||
307 | return ret; | |
308 | } | |
309 | ||
310 | static void opba_writeb (void *opaque, | |
a8170e5e | 311 | hwaddr addr, uint32_t value) |
8ecc7913 | 312 | { |
c227f099 | 313 | ppc4xx_opba_t *opba; |
8ecc7913 JM |
314 | |
315 | #ifdef DEBUG_OPBA | |
90e189ec BS |
316 | printf("%s: addr " TARGET_FMT_plx " val %08" PRIx32 "\n", __func__, addr, |
317 | value); | |
8ecc7913 JM |
318 | #endif |
319 | opba = opaque; | |
802670e6 | 320 | switch (addr) { |
8ecc7913 JM |
321 | case 0x00: |
322 | opba->cr = value & 0xF8; | |
323 | break; | |
324 | case 0x01: | |
325 | opba->pr = value & 0xFF; | |
326 | break; | |
327 | default: | |
328 | break; | |
329 | } | |
330 | } | |
331 | ||
a8170e5e | 332 | static uint32_t opba_readw (void *opaque, hwaddr addr) |
8ecc7913 JM |
333 | { |
334 | uint32_t ret; | |
335 | ||
336 | #ifdef DEBUG_OPBA | |
90e189ec | 337 | printf("%s: addr " TARGET_FMT_plx "\n", __func__, addr); |
8ecc7913 JM |
338 | #endif |
339 | ret = opba_readb(opaque, addr) << 8; | |
340 | ret |= opba_readb(opaque, addr + 1); | |
341 | ||
342 | return ret; | |
343 | } | |
344 | ||
345 | static void opba_writew (void *opaque, | |
a8170e5e | 346 | hwaddr addr, uint32_t value) |
8ecc7913 JM |
347 | { |
348 | #ifdef DEBUG_OPBA | |
90e189ec BS |
349 | printf("%s: addr " TARGET_FMT_plx " val %08" PRIx32 "\n", __func__, addr, |
350 | value); | |
8ecc7913 JM |
351 | #endif |
352 | opba_writeb(opaque, addr, value >> 8); | |
353 | opba_writeb(opaque, addr + 1, value); | |
354 | } | |
355 | ||
a8170e5e | 356 | static uint32_t opba_readl (void *opaque, hwaddr addr) |
8ecc7913 JM |
357 | { |
358 | uint32_t ret; | |
359 | ||
360 | #ifdef DEBUG_OPBA | |
90e189ec | 361 | printf("%s: addr " TARGET_FMT_plx "\n", __func__, addr); |
8ecc7913 JM |
362 | #endif |
363 | ret = opba_readb(opaque, addr) << 24; | |
364 | ret |= opba_readb(opaque, addr + 1) << 16; | |
365 | ||
366 | return ret; | |
367 | } | |
368 | ||
369 | static void opba_writel (void *opaque, | |
a8170e5e | 370 | hwaddr addr, uint32_t value) |
8ecc7913 JM |
371 | { |
372 | #ifdef DEBUG_OPBA | |
90e189ec BS |
373 | printf("%s: addr " TARGET_FMT_plx " val %08" PRIx32 "\n", __func__, addr, |
374 | value); | |
8ecc7913 JM |
375 | #endif |
376 | opba_writeb(opaque, addr, value >> 24); | |
377 | opba_writeb(opaque, addr + 1, value >> 16); | |
378 | } | |
379 | ||
9074e0e3 AK |
380 | static const MemoryRegionOps opba_ops = { |
381 | .old_mmio = { | |
382 | .read = { opba_readb, opba_readw, opba_readl, }, | |
383 | .write = { opba_writeb, opba_writew, opba_writel, }, | |
384 | }, | |
385 | .endianness = DEVICE_NATIVE_ENDIAN, | |
8ecc7913 JM |
386 | }; |
387 | ||
388 | static void ppc4xx_opba_reset (void *opaque) | |
389 | { | |
c227f099 | 390 | ppc4xx_opba_t *opba; |
8ecc7913 JM |
391 | |
392 | opba = opaque; | |
393 | opba->cr = 0x00; /* No dynamic priorities - park disabled */ | |
394 | opba->pr = 0x11; | |
395 | } | |
396 | ||
a8170e5e | 397 | static void ppc4xx_opba_init(hwaddr base) |
8ecc7913 | 398 | { |
c227f099 | 399 | ppc4xx_opba_t *opba; |
8ecc7913 | 400 | |
7267c094 | 401 | opba = g_malloc0(sizeof(ppc4xx_opba_t)); |
8ecc7913 | 402 | #ifdef DEBUG_OPBA |
90e189ec | 403 | printf("%s: offset " TARGET_FMT_plx "\n", __func__, base); |
8ecc7913 | 404 | #endif |
2c9b15ca | 405 | memory_region_init_io(&opba->io, NULL, &opba_ops, opba, "opba", 0x002); |
9074e0e3 | 406 | memory_region_add_subregion(get_system_memory(), base, &opba->io); |
802670e6 | 407 | qemu_register_reset(ppc4xx_opba_reset, opba); |
8ecc7913 JM |
408 | } |
409 | ||
8ecc7913 JM |
410 | /*****************************************************************************/ |
411 | /* Code decompression controller */ | |
412 | /* XXX: TODO */ | |
413 | ||
8ecc7913 JM |
414 | /*****************************************************************************/ |
415 | /* Peripheral controller */ | |
c227f099 AL |
416 | typedef struct ppc4xx_ebc_t ppc4xx_ebc_t; |
417 | struct ppc4xx_ebc_t { | |
8ecc7913 JM |
418 | uint32_t addr; |
419 | uint32_t bcr[8]; | |
420 | uint32_t bap[8]; | |
421 | uint32_t bear; | |
422 | uint32_t besr0; | |
423 | uint32_t besr1; | |
424 | uint32_t cfg; | |
425 | }; | |
426 | ||
427 | enum { | |
428 | EBC0_CFGADDR = 0x012, | |
429 | EBC0_CFGDATA = 0x013, | |
430 | }; | |
431 | ||
73b01960 | 432 | static uint32_t dcr_read_ebc (void *opaque, int dcrn) |
8ecc7913 | 433 | { |
c227f099 | 434 | ppc4xx_ebc_t *ebc; |
73b01960 | 435 | uint32_t ret; |
8ecc7913 JM |
436 | |
437 | ebc = opaque; | |
438 | switch (dcrn) { | |
439 | case EBC0_CFGADDR: | |
440 | ret = ebc->addr; | |
441 | break; | |
442 | case EBC0_CFGDATA: | |
443 | switch (ebc->addr) { | |
444 | case 0x00: /* B0CR */ | |
445 | ret = ebc->bcr[0]; | |
446 | break; | |
447 | case 0x01: /* B1CR */ | |
448 | ret = ebc->bcr[1]; | |
449 | break; | |
450 | case 0x02: /* B2CR */ | |
451 | ret = ebc->bcr[2]; | |
452 | break; | |
453 | case 0x03: /* B3CR */ | |
454 | ret = ebc->bcr[3]; | |
455 | break; | |
456 | case 0x04: /* B4CR */ | |
457 | ret = ebc->bcr[4]; | |
458 | break; | |
459 | case 0x05: /* B5CR */ | |
460 | ret = ebc->bcr[5]; | |
461 | break; | |
462 | case 0x06: /* B6CR */ | |
463 | ret = ebc->bcr[6]; | |
464 | break; | |
465 | case 0x07: /* B7CR */ | |
466 | ret = ebc->bcr[7]; | |
467 | break; | |
468 | case 0x10: /* B0AP */ | |
469 | ret = ebc->bap[0]; | |
470 | break; | |
471 | case 0x11: /* B1AP */ | |
472 | ret = ebc->bap[1]; | |
473 | break; | |
474 | case 0x12: /* B2AP */ | |
475 | ret = ebc->bap[2]; | |
476 | break; | |
477 | case 0x13: /* B3AP */ | |
478 | ret = ebc->bap[3]; | |
479 | break; | |
480 | case 0x14: /* B4AP */ | |
481 | ret = ebc->bap[4]; | |
482 | break; | |
483 | case 0x15: /* B5AP */ | |
484 | ret = ebc->bap[5]; | |
485 | break; | |
486 | case 0x16: /* B6AP */ | |
487 | ret = ebc->bap[6]; | |
488 | break; | |
489 | case 0x17: /* B7AP */ | |
490 | ret = ebc->bap[7]; | |
491 | break; | |
492 | case 0x20: /* BEAR */ | |
493 | ret = ebc->bear; | |
494 | break; | |
495 | case 0x21: /* BESR0 */ | |
496 | ret = ebc->besr0; | |
497 | break; | |
498 | case 0x22: /* BESR1 */ | |
499 | ret = ebc->besr1; | |
500 | break; | |
501 | case 0x23: /* CFG */ | |
502 | ret = ebc->cfg; | |
503 | break; | |
504 | default: | |
505 | ret = 0x00000000; | |
506 | break; | |
507 | } | |
9fad3eb7 | 508 | break; |
8ecc7913 JM |
509 | default: |
510 | ret = 0x00000000; | |
511 | break; | |
512 | } | |
513 | ||
514 | return ret; | |
515 | } | |
516 | ||
73b01960 | 517 | static void dcr_write_ebc (void *opaque, int dcrn, uint32_t val) |
8ecc7913 | 518 | { |
c227f099 | 519 | ppc4xx_ebc_t *ebc; |
8ecc7913 JM |
520 | |
521 | ebc = opaque; | |
522 | switch (dcrn) { | |
523 | case EBC0_CFGADDR: | |
524 | ebc->addr = val; | |
525 | break; | |
526 | case EBC0_CFGDATA: | |
527 | switch (ebc->addr) { | |
528 | case 0x00: /* B0CR */ | |
529 | break; | |
530 | case 0x01: /* B1CR */ | |
531 | break; | |
532 | case 0x02: /* B2CR */ | |
533 | break; | |
534 | case 0x03: /* B3CR */ | |
535 | break; | |
536 | case 0x04: /* B4CR */ | |
537 | break; | |
538 | case 0x05: /* B5CR */ | |
539 | break; | |
540 | case 0x06: /* B6CR */ | |
541 | break; | |
542 | case 0x07: /* B7CR */ | |
543 | break; | |
544 | case 0x10: /* B0AP */ | |
545 | break; | |
546 | case 0x11: /* B1AP */ | |
547 | break; | |
548 | case 0x12: /* B2AP */ | |
549 | break; | |
550 | case 0x13: /* B3AP */ | |
551 | break; | |
552 | case 0x14: /* B4AP */ | |
553 | break; | |
554 | case 0x15: /* B5AP */ | |
555 | break; | |
556 | case 0x16: /* B6AP */ | |
557 | break; | |
558 | case 0x17: /* B7AP */ | |
559 | break; | |
560 | case 0x20: /* BEAR */ | |
561 | break; | |
562 | case 0x21: /* BESR0 */ | |
563 | break; | |
564 | case 0x22: /* BESR1 */ | |
565 | break; | |
566 | case 0x23: /* CFG */ | |
567 | break; | |
568 | default: | |
569 | break; | |
570 | } | |
571 | break; | |
572 | default: | |
573 | break; | |
574 | } | |
575 | } | |
576 | ||
577 | static void ebc_reset (void *opaque) | |
578 | { | |
c227f099 | 579 | ppc4xx_ebc_t *ebc; |
8ecc7913 JM |
580 | int i; |
581 | ||
582 | ebc = opaque; | |
583 | ebc->addr = 0x00000000; | |
584 | ebc->bap[0] = 0x7F8FFE80; | |
585 | ebc->bcr[0] = 0xFFE28000; | |
586 | for (i = 0; i < 8; i++) { | |
587 | ebc->bap[i] = 0x00000000; | |
588 | ebc->bcr[i] = 0x00000000; | |
589 | } | |
590 | ebc->besr0 = 0x00000000; | |
591 | ebc->besr1 = 0x00000000; | |
9c02f1a2 | 592 | ebc->cfg = 0x80400000; |
8ecc7913 JM |
593 | } |
594 | ||
97c2acb5 | 595 | void ppc405_ebc_init(CPUPPCState *env) |
8ecc7913 | 596 | { |
c227f099 | 597 | ppc4xx_ebc_t *ebc; |
8ecc7913 | 598 | |
7267c094 | 599 | ebc = g_malloc0(sizeof(ppc4xx_ebc_t)); |
a08d4367 | 600 | qemu_register_reset(&ebc_reset, ebc); |
487414f1 AL |
601 | ppc_dcr_register(env, EBC0_CFGADDR, |
602 | ebc, &dcr_read_ebc, &dcr_write_ebc); | |
603 | ppc_dcr_register(env, EBC0_CFGDATA, | |
604 | ebc, &dcr_read_ebc, &dcr_write_ebc); | |
8ecc7913 JM |
605 | } |
606 | ||
607 | /*****************************************************************************/ | |
608 | /* DMA controller */ | |
609 | enum { | |
610 | DMA0_CR0 = 0x100, | |
611 | DMA0_CT0 = 0x101, | |
612 | DMA0_DA0 = 0x102, | |
613 | DMA0_SA0 = 0x103, | |
614 | DMA0_SG0 = 0x104, | |
615 | DMA0_CR1 = 0x108, | |
616 | DMA0_CT1 = 0x109, | |
617 | DMA0_DA1 = 0x10A, | |
618 | DMA0_SA1 = 0x10B, | |
619 | DMA0_SG1 = 0x10C, | |
620 | DMA0_CR2 = 0x110, | |
621 | DMA0_CT2 = 0x111, | |
622 | DMA0_DA2 = 0x112, | |
623 | DMA0_SA2 = 0x113, | |
624 | DMA0_SG2 = 0x114, | |
625 | DMA0_CR3 = 0x118, | |
626 | DMA0_CT3 = 0x119, | |
627 | DMA0_DA3 = 0x11A, | |
628 | DMA0_SA3 = 0x11B, | |
629 | DMA0_SG3 = 0x11C, | |
630 | DMA0_SR = 0x120, | |
631 | DMA0_SGC = 0x123, | |
632 | DMA0_SLP = 0x125, | |
633 | DMA0_POL = 0x126, | |
634 | }; | |
635 | ||
c227f099 AL |
636 | typedef struct ppc405_dma_t ppc405_dma_t; |
637 | struct ppc405_dma_t { | |
8ecc7913 JM |
638 | qemu_irq irqs[4]; |
639 | uint32_t cr[4]; | |
640 | uint32_t ct[4]; | |
641 | uint32_t da[4]; | |
642 | uint32_t sa[4]; | |
643 | uint32_t sg[4]; | |
644 | uint32_t sr; | |
645 | uint32_t sgc; | |
646 | uint32_t slp; | |
647 | uint32_t pol; | |
648 | }; | |
649 | ||
73b01960 | 650 | static uint32_t dcr_read_dma (void *opaque, int dcrn) |
8ecc7913 | 651 | { |
8ecc7913 JM |
652 | return 0; |
653 | } | |
654 | ||
73b01960 | 655 | static void dcr_write_dma (void *opaque, int dcrn, uint32_t val) |
8ecc7913 | 656 | { |
8ecc7913 JM |
657 | } |
658 | ||
659 | static void ppc405_dma_reset (void *opaque) | |
660 | { | |
c227f099 | 661 | ppc405_dma_t *dma; |
8ecc7913 JM |
662 | int i; |
663 | ||
664 | dma = opaque; | |
665 | for (i = 0; i < 4; i++) { | |
666 | dma->cr[i] = 0x00000000; | |
667 | dma->ct[i] = 0x00000000; | |
668 | dma->da[i] = 0x00000000; | |
669 | dma->sa[i] = 0x00000000; | |
670 | dma->sg[i] = 0x00000000; | |
671 | } | |
672 | dma->sr = 0x00000000; | |
673 | dma->sgc = 0x00000000; | |
674 | dma->slp = 0x7C000000; | |
675 | dma->pol = 0x00000000; | |
676 | } | |
677 | ||
e2684c0b | 678 | static void ppc405_dma_init(CPUPPCState *env, qemu_irq irqs[4]) |
8ecc7913 | 679 | { |
c227f099 | 680 | ppc405_dma_t *dma; |
8ecc7913 | 681 | |
7267c094 | 682 | dma = g_malloc0(sizeof(ppc405_dma_t)); |
487414f1 | 683 | memcpy(dma->irqs, irqs, 4 * sizeof(qemu_irq)); |
a08d4367 | 684 | qemu_register_reset(&ppc405_dma_reset, dma); |
487414f1 AL |
685 | ppc_dcr_register(env, DMA0_CR0, |
686 | dma, &dcr_read_dma, &dcr_write_dma); | |
687 | ppc_dcr_register(env, DMA0_CT0, | |
688 | dma, &dcr_read_dma, &dcr_write_dma); | |
689 | ppc_dcr_register(env, DMA0_DA0, | |
690 | dma, &dcr_read_dma, &dcr_write_dma); | |
691 | ppc_dcr_register(env, DMA0_SA0, | |
692 | dma, &dcr_read_dma, &dcr_write_dma); | |
693 | ppc_dcr_register(env, DMA0_SG0, | |
694 | dma, &dcr_read_dma, &dcr_write_dma); | |
695 | ppc_dcr_register(env, DMA0_CR1, | |
696 | dma, &dcr_read_dma, &dcr_write_dma); | |
697 | ppc_dcr_register(env, DMA0_CT1, | |
698 | dma, &dcr_read_dma, &dcr_write_dma); | |
699 | ppc_dcr_register(env, DMA0_DA1, | |
700 | dma, &dcr_read_dma, &dcr_write_dma); | |
701 | ppc_dcr_register(env, DMA0_SA1, | |
702 | dma, &dcr_read_dma, &dcr_write_dma); | |
703 | ppc_dcr_register(env, DMA0_SG1, | |
704 | dma, &dcr_read_dma, &dcr_write_dma); | |
705 | ppc_dcr_register(env, DMA0_CR2, | |
706 | dma, &dcr_read_dma, &dcr_write_dma); | |
707 | ppc_dcr_register(env, DMA0_CT2, | |
708 | dma, &dcr_read_dma, &dcr_write_dma); | |
709 | ppc_dcr_register(env, DMA0_DA2, | |
710 | dma, &dcr_read_dma, &dcr_write_dma); | |
711 | ppc_dcr_register(env, DMA0_SA2, | |
712 | dma, &dcr_read_dma, &dcr_write_dma); | |
713 | ppc_dcr_register(env, DMA0_SG2, | |
714 | dma, &dcr_read_dma, &dcr_write_dma); | |
715 | ppc_dcr_register(env, DMA0_CR3, | |
716 | dma, &dcr_read_dma, &dcr_write_dma); | |
717 | ppc_dcr_register(env, DMA0_CT3, | |
718 | dma, &dcr_read_dma, &dcr_write_dma); | |
719 | ppc_dcr_register(env, DMA0_DA3, | |
720 | dma, &dcr_read_dma, &dcr_write_dma); | |
721 | ppc_dcr_register(env, DMA0_SA3, | |
722 | dma, &dcr_read_dma, &dcr_write_dma); | |
723 | ppc_dcr_register(env, DMA0_SG3, | |
724 | dma, &dcr_read_dma, &dcr_write_dma); | |
725 | ppc_dcr_register(env, DMA0_SR, | |
726 | dma, &dcr_read_dma, &dcr_write_dma); | |
727 | ppc_dcr_register(env, DMA0_SGC, | |
728 | dma, &dcr_read_dma, &dcr_write_dma); | |
729 | ppc_dcr_register(env, DMA0_SLP, | |
730 | dma, &dcr_read_dma, &dcr_write_dma); | |
731 | ppc_dcr_register(env, DMA0_POL, | |
732 | dma, &dcr_read_dma, &dcr_write_dma); | |
8ecc7913 JM |
733 | } |
734 | ||
735 | /*****************************************************************************/ | |
736 | /* GPIO */ | |
c227f099 AL |
737 | typedef struct ppc405_gpio_t ppc405_gpio_t; |
738 | struct ppc405_gpio_t { | |
9074e0e3 | 739 | MemoryRegion io; |
8ecc7913 JM |
740 | uint32_t or; |
741 | uint32_t tcr; | |
742 | uint32_t osrh; | |
743 | uint32_t osrl; | |
744 | uint32_t tsrh; | |
745 | uint32_t tsrl; | |
746 | uint32_t odr; | |
747 | uint32_t ir; | |
748 | uint32_t rr1; | |
749 | uint32_t isr1h; | |
750 | uint32_t isr1l; | |
751 | }; | |
752 | ||
a8170e5e | 753 | static uint32_t ppc405_gpio_readb (void *opaque, hwaddr 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_writeb (void *opaque, | |
a8170e5e | 763 | hwaddr 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 | ||
a8170e5e | 771 | static uint32_t ppc405_gpio_readw (void *opaque, hwaddr 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_writew (void *opaque, | |
a8170e5e | 781 | hwaddr 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 | ||
a8170e5e | 789 | static uint32_t ppc405_gpio_readl (void *opaque, hwaddr addr) |
8ecc7913 | 790 | { |
8ecc7913 | 791 | #ifdef DEBUG_GPIO |
90e189ec | 792 | printf("%s: addr " TARGET_FMT_plx "\n", __func__, addr); |
8ecc7913 JM |
793 | #endif |
794 | ||
795 | return 0; | |
796 | } | |
797 | ||
798 | static void ppc405_gpio_writel (void *opaque, | |
a8170e5e | 799 | hwaddr addr, uint32_t value) |
8ecc7913 | 800 | { |
8ecc7913 | 801 | #ifdef DEBUG_GPIO |
90e189ec BS |
802 | printf("%s: addr " TARGET_FMT_plx " val %08" PRIx32 "\n", __func__, addr, |
803 | value); | |
8ecc7913 JM |
804 | #endif |
805 | } | |
806 | ||
9074e0e3 AK |
807 | static const MemoryRegionOps ppc405_gpio_ops = { |
808 | .old_mmio = { | |
809 | .read = { ppc405_gpio_readb, ppc405_gpio_readw, ppc405_gpio_readl, }, | |
810 | .write = { ppc405_gpio_writeb, ppc405_gpio_writew, ppc405_gpio_writel, }, | |
811 | }, | |
812 | .endianness = DEVICE_NATIVE_ENDIAN, | |
8ecc7913 JM |
813 | }; |
814 | ||
815 | static void ppc405_gpio_reset (void *opaque) | |
816 | { | |
8ecc7913 JM |
817 | } |
818 | ||
a8170e5e | 819 | static void ppc405_gpio_init(hwaddr base) |
8ecc7913 | 820 | { |
c227f099 | 821 | ppc405_gpio_t *gpio; |
8ecc7913 | 822 | |
7267c094 | 823 | gpio = g_malloc0(sizeof(ppc405_gpio_t)); |
8ecc7913 | 824 | #ifdef DEBUG_GPIO |
90e189ec | 825 | printf("%s: offset " TARGET_FMT_plx "\n", __func__, base); |
8ecc7913 | 826 | #endif |
2c9b15ca | 827 | memory_region_init_io(&gpio->io, NULL, &ppc405_gpio_ops, gpio, "pgio", 0x038); |
9074e0e3 | 828 | memory_region_add_subregion(get_system_memory(), base, &gpio->io); |
802670e6 | 829 | qemu_register_reset(&ppc405_gpio_reset, gpio); |
8ecc7913 JM |
830 | } |
831 | ||
832 | /*****************************************************************************/ | |
833 | /* On Chip Memory */ | |
834 | enum { | |
835 | OCM0_ISARC = 0x018, | |
836 | OCM0_ISACNTL = 0x019, | |
837 | OCM0_DSARC = 0x01A, | |
838 | OCM0_DSACNTL = 0x01B, | |
839 | }; | |
840 | ||
c227f099 AL |
841 | typedef struct ppc405_ocm_t ppc405_ocm_t; |
842 | struct ppc405_ocm_t { | |
9074e0e3 AK |
843 | MemoryRegion ram; |
844 | MemoryRegion isarc_ram; | |
845 | MemoryRegion dsarc_ram; | |
8ecc7913 JM |
846 | uint32_t isarc; |
847 | uint32_t isacntl; | |
848 | uint32_t dsarc; | |
849 | uint32_t dsacntl; | |
850 | }; | |
851 | ||
c227f099 | 852 | static void ocm_update_mappings (ppc405_ocm_t *ocm, |
8ecc7913 JM |
853 | uint32_t isarc, uint32_t isacntl, |
854 | uint32_t dsarc, uint32_t dsacntl) | |
855 | { | |
856 | #ifdef DEBUG_OCM | |
aae9366a JM |
857 | printf("OCM update ISA %08" PRIx32 " %08" PRIx32 " (%08" PRIx32 |
858 | " %08" PRIx32 ") DSA %08" PRIx32 " %08" PRIx32 | |
859 | " (%08" PRIx32 " %08" PRIx32 ")\n", | |
8ecc7913 JM |
860 | isarc, isacntl, dsarc, dsacntl, |
861 | ocm->isarc, ocm->isacntl, ocm->dsarc, ocm->dsacntl); | |
862 | #endif | |
863 | if (ocm->isarc != isarc || | |
864 | (ocm->isacntl & 0x80000000) != (isacntl & 0x80000000)) { | |
865 | if (ocm->isacntl & 0x80000000) { | |
866 | /* Unmap previously assigned memory region */ | |
aae9366a | 867 | printf("OCM unmap ISA %08" PRIx32 "\n", ocm->isarc); |
9074e0e3 | 868 | memory_region_del_subregion(get_system_memory(), &ocm->isarc_ram); |
8ecc7913 JM |
869 | } |
870 | if (isacntl & 0x80000000) { | |
871 | /* Map new instruction memory region */ | |
872 | #ifdef DEBUG_OCM | |
aae9366a | 873 | printf("OCM map ISA %08" PRIx32 "\n", isarc); |
8ecc7913 | 874 | #endif |
9074e0e3 AK |
875 | memory_region_add_subregion(get_system_memory(), isarc, |
876 | &ocm->isarc_ram); | |
8ecc7913 JM |
877 | } |
878 | } | |
879 | if (ocm->dsarc != dsarc || | |
880 | (ocm->dsacntl & 0x80000000) != (dsacntl & 0x80000000)) { | |
881 | if (ocm->dsacntl & 0x80000000) { | |
882 | /* Beware not to unmap the region we just mapped */ | |
883 | if (!(isacntl & 0x80000000) || ocm->dsarc != isarc) { | |
884 | /* Unmap previously assigned memory region */ | |
885 | #ifdef DEBUG_OCM | |
aae9366a | 886 | printf("OCM unmap DSA %08" PRIx32 "\n", ocm->dsarc); |
8ecc7913 | 887 | #endif |
9074e0e3 AK |
888 | memory_region_del_subregion(get_system_memory(), |
889 | &ocm->dsarc_ram); | |
8ecc7913 JM |
890 | } |
891 | } | |
892 | if (dsacntl & 0x80000000) { | |
893 | /* Beware not to remap the region we just mapped */ | |
894 | if (!(isacntl & 0x80000000) || dsarc != isarc) { | |
895 | /* Map new data memory region */ | |
896 | #ifdef DEBUG_OCM | |
aae9366a | 897 | printf("OCM map DSA %08" PRIx32 "\n", dsarc); |
8ecc7913 | 898 | #endif |
9074e0e3 AK |
899 | memory_region_add_subregion(get_system_memory(), dsarc, |
900 | &ocm->dsarc_ram); | |
8ecc7913 JM |
901 | } |
902 | } | |
903 | } | |
904 | } | |
905 | ||
73b01960 | 906 | static uint32_t dcr_read_ocm (void *opaque, int dcrn) |
8ecc7913 | 907 | { |
c227f099 | 908 | ppc405_ocm_t *ocm; |
73b01960 | 909 | uint32_t ret; |
8ecc7913 JM |
910 | |
911 | ocm = opaque; | |
912 | switch (dcrn) { | |
913 | case OCM0_ISARC: | |
914 | ret = ocm->isarc; | |
915 | break; | |
916 | case OCM0_ISACNTL: | |
917 | ret = ocm->isacntl; | |
918 | break; | |
919 | case OCM0_DSARC: | |
920 | ret = ocm->dsarc; | |
921 | break; | |
922 | case OCM0_DSACNTL: | |
923 | ret = ocm->dsacntl; | |
924 | break; | |
925 | default: | |
926 | ret = 0; | |
927 | break; | |
928 | } | |
929 | ||
930 | return ret; | |
931 | } | |
932 | ||
73b01960 | 933 | static void dcr_write_ocm (void *opaque, int dcrn, uint32_t val) |
8ecc7913 | 934 | { |
c227f099 | 935 | ppc405_ocm_t *ocm; |
8ecc7913 JM |
936 | uint32_t isarc, dsarc, isacntl, dsacntl; |
937 | ||
938 | ocm = opaque; | |
939 | isarc = ocm->isarc; | |
940 | dsarc = ocm->dsarc; | |
941 | isacntl = ocm->isacntl; | |
942 | dsacntl = ocm->dsacntl; | |
943 | switch (dcrn) { | |
944 | case OCM0_ISARC: | |
945 | isarc = val & 0xFC000000; | |
946 | break; | |
947 | case OCM0_ISACNTL: | |
948 | isacntl = val & 0xC0000000; | |
949 | break; | |
950 | case OCM0_DSARC: | |
951 | isarc = val & 0xFC000000; | |
952 | break; | |
953 | case OCM0_DSACNTL: | |
954 | isacntl = val & 0xC0000000; | |
955 | break; | |
956 | } | |
957 | ocm_update_mappings(ocm, isarc, isacntl, dsarc, dsacntl); | |
958 | ocm->isarc = isarc; | |
959 | ocm->dsarc = dsarc; | |
960 | ocm->isacntl = isacntl; | |
961 | ocm->dsacntl = dsacntl; | |
962 | } | |
963 | ||
964 | static void ocm_reset (void *opaque) | |
965 | { | |
c227f099 | 966 | ppc405_ocm_t *ocm; |
8ecc7913 JM |
967 | uint32_t isarc, dsarc, isacntl, dsacntl; |
968 | ||
969 | ocm = opaque; | |
970 | isarc = 0x00000000; | |
971 | isacntl = 0x00000000; | |
972 | dsarc = 0x00000000; | |
973 | dsacntl = 0x00000000; | |
974 | ocm_update_mappings(ocm, isarc, isacntl, dsarc, dsacntl); | |
975 | ocm->isarc = isarc; | |
976 | ocm->dsarc = dsarc; | |
977 | ocm->isacntl = isacntl; | |
978 | ocm->dsacntl = dsacntl; | |
979 | } | |
980 | ||
e2684c0b | 981 | static void ppc405_ocm_init(CPUPPCState *env) |
8ecc7913 | 982 | { |
c227f099 | 983 | ppc405_ocm_t *ocm; |
8ecc7913 | 984 | |
7267c094 | 985 | ocm = g_malloc0(sizeof(ppc405_ocm_t)); |
9074e0e3 | 986 | /* XXX: Size is 4096 or 0x04000000 */ |
ab3dd749 | 987 | memory_region_init_ram(&ocm->isarc_ram, NULL, "ppc405.ocm", 4 * KiB, |
f8ed85ac | 988 | &error_fatal); |
ab3dd749 PMD |
989 | memory_region_init_alias(&ocm->dsarc_ram, NULL, "ppc405.dsarc", |
990 | &ocm->isarc_ram, 0, 4 * KiB); | |
a08d4367 | 991 | qemu_register_reset(&ocm_reset, ocm); |
487414f1 AL |
992 | ppc_dcr_register(env, OCM0_ISARC, |
993 | ocm, &dcr_read_ocm, &dcr_write_ocm); | |
994 | ppc_dcr_register(env, OCM0_ISACNTL, | |
995 | ocm, &dcr_read_ocm, &dcr_write_ocm); | |
996 | ppc_dcr_register(env, OCM0_DSARC, | |
997 | ocm, &dcr_read_ocm, &dcr_write_ocm); | |
998 | ppc_dcr_register(env, OCM0_DSACNTL, | |
999 | ocm, &dcr_read_ocm, &dcr_write_ocm); | |
8ecc7913 JM |
1000 | } |
1001 | ||
9c02f1a2 JM |
1002 | /*****************************************************************************/ |
1003 | /* General purpose timers */ | |
c227f099 AL |
1004 | typedef struct ppc4xx_gpt_t ppc4xx_gpt_t; |
1005 | struct ppc4xx_gpt_t { | |
9074e0e3 | 1006 | MemoryRegion iomem; |
9c02f1a2 JM |
1007 | int64_t tb_offset; |
1008 | uint32_t tb_freq; | |
1246b259 | 1009 | QEMUTimer *timer; |
9c02f1a2 JM |
1010 | qemu_irq irqs[5]; |
1011 | uint32_t oe; | |
1012 | uint32_t ol; | |
1013 | uint32_t im; | |
1014 | uint32_t is; | |
1015 | uint32_t ie; | |
1016 | uint32_t comp[5]; | |
1017 | uint32_t mask[5]; | |
1018 | }; | |
1019 | ||
a8170e5e | 1020 | static uint32_t ppc4xx_gpt_readb (void *opaque, hwaddr addr) |
9c02f1a2 JM |
1021 | { |
1022 | #ifdef DEBUG_GPT | |
90e189ec | 1023 | printf("%s: addr " TARGET_FMT_plx "\n", __func__, addr); |
9c02f1a2 JM |
1024 | #endif |
1025 | /* XXX: generate a bus fault */ | |
1026 | return -1; | |
1027 | } | |
1028 | ||
1029 | static void ppc4xx_gpt_writeb (void *opaque, | |
a8170e5e | 1030 | hwaddr addr, uint32_t value) |
9c02f1a2 JM |
1031 | { |
1032 | #ifdef DEBUG_I2C | |
90e189ec BS |
1033 | printf("%s: addr " TARGET_FMT_plx " val %08" PRIx32 "\n", __func__, addr, |
1034 | value); | |
9c02f1a2 JM |
1035 | #endif |
1036 | /* XXX: generate a bus fault */ | |
1037 | } | |
1038 | ||
a8170e5e | 1039 | static uint32_t ppc4xx_gpt_readw (void *opaque, hwaddr addr) |
9c02f1a2 JM |
1040 | { |
1041 | #ifdef DEBUG_GPT | |
90e189ec | 1042 | printf("%s: addr " TARGET_FMT_plx "\n", __func__, addr); |
9c02f1a2 JM |
1043 | #endif |
1044 | /* XXX: generate a bus fault */ | |
1045 | return -1; | |
1046 | } | |
1047 | ||
1048 | static void ppc4xx_gpt_writew (void *opaque, | |
a8170e5e | 1049 | hwaddr addr, uint32_t value) |
9c02f1a2 JM |
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 | /* XXX: generate a bus fault */ | |
1056 | } | |
1057 | ||
c227f099 | 1058 | static int ppc4xx_gpt_compare (ppc4xx_gpt_t *gpt, int n) |
9c02f1a2 JM |
1059 | { |
1060 | /* XXX: TODO */ | |
1061 | return 0; | |
1062 | } | |
1063 | ||
c227f099 | 1064 | static void ppc4xx_gpt_set_output (ppc4xx_gpt_t *gpt, int n, int level) |
9c02f1a2 JM |
1065 | { |
1066 | /* XXX: TODO */ | |
1067 | } | |
1068 | ||
c227f099 | 1069 | static void ppc4xx_gpt_set_outputs (ppc4xx_gpt_t *gpt) |
9c02f1a2 JM |
1070 | { |
1071 | uint32_t mask; | |
1072 | int i; | |
1073 | ||
1074 | mask = 0x80000000; | |
1075 | for (i = 0; i < 5; i++) { | |
1076 | if (gpt->oe & mask) { | |
1077 | /* Output is enabled */ | |
1078 | if (ppc4xx_gpt_compare(gpt, i)) { | |
1079 | /* Comparison is OK */ | |
1080 | ppc4xx_gpt_set_output(gpt, i, gpt->ol & mask); | |
1081 | } else { | |
1082 | /* Comparison is KO */ | |
1083 | ppc4xx_gpt_set_output(gpt, i, gpt->ol & mask ? 0 : 1); | |
1084 | } | |
1085 | } | |
1086 | mask = mask >> 1; | |
1087 | } | |
9c02f1a2 JM |
1088 | } |
1089 | ||
c227f099 | 1090 | static void ppc4xx_gpt_set_irqs (ppc4xx_gpt_t *gpt) |
9c02f1a2 JM |
1091 | { |
1092 | uint32_t mask; | |
1093 | int i; | |
1094 | ||
1095 | mask = 0x00008000; | |
1096 | for (i = 0; i < 5; i++) { | |
1097 | if (gpt->is & gpt->im & mask) | |
1098 | qemu_irq_raise(gpt->irqs[i]); | |
1099 | else | |
1100 | qemu_irq_lower(gpt->irqs[i]); | |
1101 | mask = mask >> 1; | |
1102 | } | |
9c02f1a2 JM |
1103 | } |
1104 | ||
c227f099 | 1105 | static void ppc4xx_gpt_compute_timer (ppc4xx_gpt_t *gpt) |
9c02f1a2 JM |
1106 | { |
1107 | /* XXX: TODO */ | |
1108 | } | |
1109 | ||
a8170e5e | 1110 | static uint32_t ppc4xx_gpt_readl (void *opaque, hwaddr addr) |
9c02f1a2 | 1111 | { |
c227f099 | 1112 | ppc4xx_gpt_t *gpt; |
9c02f1a2 JM |
1113 | uint32_t ret; |
1114 | int idx; | |
1115 | ||
1116 | #ifdef DEBUG_GPT | |
90e189ec | 1117 | printf("%s: addr " TARGET_FMT_plx "\n", __func__, addr); |
9c02f1a2 JM |
1118 | #endif |
1119 | gpt = opaque; | |
802670e6 | 1120 | switch (addr) { |
9c02f1a2 JM |
1121 | case 0x00: |
1122 | /* Time base counter */ | |
bc72ad67 | 1123 | ret = muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + gpt->tb_offset, |
73bcb24d | 1124 | gpt->tb_freq, NANOSECONDS_PER_SECOND); |
9c02f1a2 JM |
1125 | break; |
1126 | case 0x10: | |
1127 | /* Output enable */ | |
1128 | ret = gpt->oe; | |
1129 | break; | |
1130 | case 0x14: | |
1131 | /* Output level */ | |
1132 | ret = gpt->ol; | |
1133 | break; | |
1134 | case 0x18: | |
1135 | /* Interrupt mask */ | |
1136 | ret = gpt->im; | |
1137 | break; | |
1138 | case 0x1C: | |
1139 | case 0x20: | |
1140 | /* Interrupt status */ | |
1141 | ret = gpt->is; | |
1142 | break; | |
1143 | case 0x24: | |
1144 | /* Interrupt enable */ | |
1145 | ret = gpt->ie; | |
1146 | break; | |
1147 | case 0x80 ... 0x90: | |
1148 | /* Compare timer */ | |
802670e6 | 1149 | idx = (addr - 0x80) >> 2; |
9c02f1a2 JM |
1150 | ret = gpt->comp[idx]; |
1151 | break; | |
1152 | case 0xC0 ... 0xD0: | |
1153 | /* Compare mask */ | |
802670e6 | 1154 | idx = (addr - 0xC0) >> 2; |
9c02f1a2 JM |
1155 | ret = gpt->mask[idx]; |
1156 | break; | |
1157 | default: | |
1158 | ret = -1; | |
1159 | break; | |
1160 | } | |
1161 | ||
1162 | return ret; | |
1163 | } | |
1164 | ||
1165 | static void ppc4xx_gpt_writel (void *opaque, | |
a8170e5e | 1166 | hwaddr addr, uint32_t value) |
9c02f1a2 | 1167 | { |
c227f099 | 1168 | ppc4xx_gpt_t *gpt; |
9c02f1a2 JM |
1169 | int idx; |
1170 | ||
1171 | #ifdef DEBUG_I2C | |
90e189ec BS |
1172 | printf("%s: addr " TARGET_FMT_plx " val %08" PRIx32 "\n", __func__, addr, |
1173 | value); | |
9c02f1a2 JM |
1174 | #endif |
1175 | gpt = opaque; | |
802670e6 | 1176 | switch (addr) { |
9c02f1a2 JM |
1177 | case 0x00: |
1178 | /* Time base counter */ | |
73bcb24d | 1179 | gpt->tb_offset = muldiv64(value, NANOSECONDS_PER_SECOND, gpt->tb_freq) |
bc72ad67 | 1180 | - qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); |
9c02f1a2 JM |
1181 | ppc4xx_gpt_compute_timer(gpt); |
1182 | break; | |
1183 | case 0x10: | |
1184 | /* Output enable */ | |
1185 | gpt->oe = value & 0xF8000000; | |
1186 | ppc4xx_gpt_set_outputs(gpt); | |
1187 | break; | |
1188 | case 0x14: | |
1189 | /* Output level */ | |
1190 | gpt->ol = value & 0xF8000000; | |
1191 | ppc4xx_gpt_set_outputs(gpt); | |
1192 | break; | |
1193 | case 0x18: | |
1194 | /* Interrupt mask */ | |
1195 | gpt->im = value & 0x0000F800; | |
1196 | break; | |
1197 | case 0x1C: | |
1198 | /* Interrupt status set */ | |
1199 | gpt->is |= value & 0x0000F800; | |
1200 | ppc4xx_gpt_set_irqs(gpt); | |
1201 | break; | |
1202 | case 0x20: | |
1203 | /* Interrupt status clear */ | |
1204 | gpt->is &= ~(value & 0x0000F800); | |
1205 | ppc4xx_gpt_set_irqs(gpt); | |
1206 | break; | |
1207 | case 0x24: | |
1208 | /* Interrupt enable */ | |
1209 | gpt->ie = value & 0x0000F800; | |
1210 | ppc4xx_gpt_set_irqs(gpt); | |
1211 | break; | |
1212 | case 0x80 ... 0x90: | |
1213 | /* Compare timer */ | |
802670e6 | 1214 | idx = (addr - 0x80) >> 2; |
9c02f1a2 JM |
1215 | gpt->comp[idx] = value & 0xF8000000; |
1216 | ppc4xx_gpt_compute_timer(gpt); | |
1217 | break; | |
1218 | case 0xC0 ... 0xD0: | |
1219 | /* Compare mask */ | |
802670e6 | 1220 | idx = (addr - 0xC0) >> 2; |
9c02f1a2 JM |
1221 | gpt->mask[idx] = value & 0xF8000000; |
1222 | ppc4xx_gpt_compute_timer(gpt); | |
1223 | break; | |
1224 | } | |
1225 | } | |
1226 | ||
9074e0e3 AK |
1227 | static const MemoryRegionOps gpt_ops = { |
1228 | .old_mmio = { | |
1229 | .read = { ppc4xx_gpt_readb, ppc4xx_gpt_readw, ppc4xx_gpt_readl, }, | |
1230 | .write = { ppc4xx_gpt_writeb, ppc4xx_gpt_writew, ppc4xx_gpt_writel, }, | |
1231 | }, | |
1232 | .endianness = DEVICE_NATIVE_ENDIAN, | |
9c02f1a2 JM |
1233 | }; |
1234 | ||
1235 | static void ppc4xx_gpt_cb (void *opaque) | |
1236 | { | |
c227f099 | 1237 | ppc4xx_gpt_t *gpt; |
9c02f1a2 JM |
1238 | |
1239 | gpt = opaque; | |
1240 | ppc4xx_gpt_set_irqs(gpt); | |
1241 | ppc4xx_gpt_set_outputs(gpt); | |
1242 | ppc4xx_gpt_compute_timer(gpt); | |
1243 | } | |
1244 | ||
1245 | static void ppc4xx_gpt_reset (void *opaque) | |
1246 | { | |
c227f099 | 1247 | ppc4xx_gpt_t *gpt; |
9c02f1a2 JM |
1248 | int i; |
1249 | ||
1250 | gpt = opaque; | |
bc72ad67 | 1251 | timer_del(gpt->timer); |
9c02f1a2 JM |
1252 | gpt->oe = 0x00000000; |
1253 | gpt->ol = 0x00000000; | |
1254 | gpt->im = 0x00000000; | |
1255 | gpt->is = 0x00000000; | |
1256 | gpt->ie = 0x00000000; | |
1257 | for (i = 0; i < 5; i++) { | |
1258 | gpt->comp[i] = 0x00000000; | |
1259 | gpt->mask[i] = 0x00000000; | |
1260 | } | |
1261 | } | |
1262 | ||
a8170e5e | 1263 | static void ppc4xx_gpt_init(hwaddr base, qemu_irq irqs[5]) |
9c02f1a2 | 1264 | { |
c227f099 | 1265 | ppc4xx_gpt_t *gpt; |
9c02f1a2 JM |
1266 | int i; |
1267 | ||
7267c094 | 1268 | gpt = g_malloc0(sizeof(ppc4xx_gpt_t)); |
802670e6 | 1269 | for (i = 0; i < 5; i++) { |
487414f1 | 1270 | gpt->irqs[i] = irqs[i]; |
802670e6 | 1271 | } |
bc72ad67 | 1272 | gpt->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, &ppc4xx_gpt_cb, gpt); |
9c02f1a2 | 1273 | #ifdef DEBUG_GPT |
90e189ec | 1274 | printf("%s: offset " TARGET_FMT_plx "\n", __func__, base); |
9c02f1a2 | 1275 | #endif |
2c9b15ca | 1276 | memory_region_init_io(&gpt->iomem, NULL, &gpt_ops, gpt, "gpt", 0x0d4); |
9074e0e3 | 1277 | memory_region_add_subregion(get_system_memory(), base, &gpt->iomem); |
a08d4367 | 1278 | qemu_register_reset(ppc4xx_gpt_reset, gpt); |
9c02f1a2 JM |
1279 | } |
1280 | ||
8ecc7913 JM |
1281 | /*****************************************************************************/ |
1282 | /* SPR */ | |
f3273ba6 | 1283 | void ppc40x_core_reset(PowerPCCPU *cpu) |
8ecc7913 | 1284 | { |
f3273ba6 | 1285 | CPUPPCState *env = &cpu->env; |
8ecc7913 JM |
1286 | target_ulong dbsr; |
1287 | ||
1288 | printf("Reset PowerPC core\n"); | |
c3affe56 | 1289 | cpu_interrupt(CPU(cpu), CPU_INTERRUPT_RESET); |
8ecc7913 JM |
1290 | dbsr = env->spr[SPR_40x_DBSR]; |
1291 | dbsr &= ~0x00000300; | |
1292 | dbsr |= 0x00000100; | |
1293 | env->spr[SPR_40x_DBSR] = dbsr; | |
8ecc7913 JM |
1294 | } |
1295 | ||
f3273ba6 | 1296 | void ppc40x_chip_reset(PowerPCCPU *cpu) |
8ecc7913 | 1297 | { |
f3273ba6 | 1298 | CPUPPCState *env = &cpu->env; |
8ecc7913 JM |
1299 | target_ulong dbsr; |
1300 | ||
1301 | printf("Reset PowerPC chip\n"); | |
c3affe56 | 1302 | cpu_interrupt(CPU(cpu), CPU_INTERRUPT_RESET); |
8ecc7913 JM |
1303 | /* XXX: TODO reset all internal peripherals */ |
1304 | dbsr = env->spr[SPR_40x_DBSR]; | |
1305 | dbsr &= ~0x00000300; | |
04f20795 | 1306 | dbsr |= 0x00000200; |
8ecc7913 | 1307 | env->spr[SPR_40x_DBSR] = dbsr; |
8ecc7913 JM |
1308 | } |
1309 | ||
f3273ba6 | 1310 | void ppc40x_system_reset(PowerPCCPU *cpu) |
8ecc7913 JM |
1311 | { |
1312 | printf("Reset PowerPC system\n"); | |
cf83f140 | 1313 | qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET); |
8ecc7913 JM |
1314 | } |
1315 | ||
e2684c0b | 1316 | void store_40x_dbcr0 (CPUPPCState *env, uint32_t val) |
8ecc7913 | 1317 | { |
f3273ba6 AF |
1318 | PowerPCCPU *cpu = ppc_env_get_cpu(env); |
1319 | ||
8ecc7913 JM |
1320 | switch ((val >> 28) & 0x3) { |
1321 | case 0x0: | |
1322 | /* No action */ | |
1323 | break; | |
1324 | case 0x1: | |
1325 | /* Core reset */ | |
f3273ba6 | 1326 | ppc40x_core_reset(cpu); |
8ecc7913 JM |
1327 | break; |
1328 | case 0x2: | |
1329 | /* Chip reset */ | |
f3273ba6 | 1330 | ppc40x_chip_reset(cpu); |
8ecc7913 JM |
1331 | break; |
1332 | case 0x3: | |
1333 | /* System reset */ | |
f3273ba6 | 1334 | ppc40x_system_reset(cpu); |
8ecc7913 JM |
1335 | break; |
1336 | } | |
1337 | } | |
1338 | ||
1339 | /*****************************************************************************/ | |
1340 | /* PowerPC 405CR */ | |
1341 | enum { | |
1342 | PPC405CR_CPC0_PLLMR = 0x0B0, | |
1343 | PPC405CR_CPC0_CR0 = 0x0B1, | |
1344 | PPC405CR_CPC0_CR1 = 0x0B2, | |
1345 | PPC405CR_CPC0_PSR = 0x0B4, | |
1346 | PPC405CR_CPC0_JTAGID = 0x0B5, | |
1347 | PPC405CR_CPC0_ER = 0x0B9, | |
1348 | PPC405CR_CPC0_FR = 0x0BA, | |
1349 | PPC405CR_CPC0_SR = 0x0BB, | |
1350 | }; | |
1351 | ||
04f20795 JM |
1352 | enum { |
1353 | PPC405CR_CPU_CLK = 0, | |
1354 | PPC405CR_TMR_CLK = 1, | |
1355 | PPC405CR_PLB_CLK = 2, | |
1356 | PPC405CR_SDRAM_CLK = 3, | |
1357 | PPC405CR_OPB_CLK = 4, | |
1358 | PPC405CR_EXT_CLK = 5, | |
1359 | PPC405CR_UART_CLK = 6, | |
1360 | PPC405CR_CLK_NB = 7, | |
1361 | }; | |
1362 | ||
c227f099 AL |
1363 | typedef struct ppc405cr_cpc_t ppc405cr_cpc_t; |
1364 | struct ppc405cr_cpc_t { | |
1365 | clk_setup_t clk_setup[PPC405CR_CLK_NB]; | |
8ecc7913 JM |
1366 | uint32_t sysclk; |
1367 | uint32_t psr; | |
1368 | uint32_t cr0; | |
1369 | uint32_t cr1; | |
1370 | uint32_t jtagid; | |
1371 | uint32_t pllmr; | |
1372 | uint32_t er; | |
1373 | uint32_t fr; | |
1374 | }; | |
1375 | ||
c227f099 | 1376 | static void ppc405cr_clk_setup (ppc405cr_cpc_t *cpc) |
8ecc7913 JM |
1377 | { |
1378 | uint64_t VCO_out, PLL_out; | |
1379 | uint32_t CPU_clk, TMR_clk, SDRAM_clk, PLB_clk, OPB_clk, EXT_clk, UART_clk; | |
1380 | int M, D0, D1, D2; | |
1381 | ||
1382 | D0 = ((cpc->pllmr >> 26) & 0x3) + 1; /* CBDV */ | |
1383 | if (cpc->pllmr & 0x80000000) { | |
1384 | D1 = (((cpc->pllmr >> 20) - 1) & 0xF) + 1; /* FBDV */ | |
1385 | D2 = 8 - ((cpc->pllmr >> 16) & 0x7); /* FWDVA */ | |
1386 | M = D0 * D1 * D2; | |
fb6971c1 | 1387 | VCO_out = (uint64_t)cpc->sysclk * M; |
8ecc7913 JM |
1388 | if (VCO_out < 400000000 || VCO_out > 800000000) { |
1389 | /* PLL cannot lock */ | |
1390 | cpc->pllmr &= ~0x80000000; | |
1391 | goto bypass_pll; | |
1392 | } | |
1393 | PLL_out = VCO_out / D2; | |
1394 | } else { | |
1395 | /* Bypass PLL */ | |
1396 | bypass_pll: | |
1397 | M = D0; | |
fb6971c1 | 1398 | PLL_out = (uint64_t)cpc->sysclk * M; |
8ecc7913 JM |
1399 | } |
1400 | CPU_clk = PLL_out; | |
1401 | if (cpc->cr1 & 0x00800000) | |
1402 | TMR_clk = cpc->sysclk; /* Should have a separate clock */ | |
1403 | else | |
1404 | TMR_clk = CPU_clk; | |
1405 | PLB_clk = CPU_clk / D0; | |
1406 | SDRAM_clk = PLB_clk; | |
1407 | D0 = ((cpc->pllmr >> 10) & 0x3) + 1; | |
1408 | OPB_clk = PLB_clk / D0; | |
1409 | D0 = ((cpc->pllmr >> 24) & 0x3) + 2; | |
1410 | EXT_clk = PLB_clk / D0; | |
1411 | D0 = ((cpc->cr0 >> 1) & 0x1F) + 1; | |
1412 | UART_clk = CPU_clk / D0; | |
1413 | /* Setup CPU clocks */ | |
04f20795 | 1414 | clk_setup(&cpc->clk_setup[PPC405CR_CPU_CLK], CPU_clk); |
8ecc7913 | 1415 | /* Setup time-base clock */ |
04f20795 | 1416 | clk_setup(&cpc->clk_setup[PPC405CR_TMR_CLK], TMR_clk); |
8ecc7913 | 1417 | /* Setup PLB clock */ |
04f20795 | 1418 | clk_setup(&cpc->clk_setup[PPC405CR_PLB_CLK], PLB_clk); |
8ecc7913 | 1419 | /* Setup SDRAM clock */ |
04f20795 | 1420 | clk_setup(&cpc->clk_setup[PPC405CR_SDRAM_CLK], SDRAM_clk); |
8ecc7913 | 1421 | /* Setup OPB clock */ |
04f20795 | 1422 | clk_setup(&cpc->clk_setup[PPC405CR_OPB_CLK], OPB_clk); |
8ecc7913 | 1423 | /* Setup external clock */ |
04f20795 | 1424 | clk_setup(&cpc->clk_setup[PPC405CR_EXT_CLK], EXT_clk); |
8ecc7913 | 1425 | /* Setup UART clock */ |
04f20795 | 1426 | clk_setup(&cpc->clk_setup[PPC405CR_UART_CLK], UART_clk); |
8ecc7913 JM |
1427 | } |
1428 | ||
73b01960 | 1429 | static uint32_t dcr_read_crcpc (void *opaque, int dcrn) |
8ecc7913 | 1430 | { |
c227f099 | 1431 | ppc405cr_cpc_t *cpc; |
73b01960 | 1432 | uint32_t ret; |
8ecc7913 JM |
1433 | |
1434 | cpc = opaque; | |
1435 | switch (dcrn) { | |
1436 | case PPC405CR_CPC0_PLLMR: | |
1437 | ret = cpc->pllmr; | |
1438 | break; | |
1439 | case PPC405CR_CPC0_CR0: | |
1440 | ret = cpc->cr0; | |
1441 | break; | |
1442 | case PPC405CR_CPC0_CR1: | |
1443 | ret = cpc->cr1; | |
1444 | break; | |
1445 | case PPC405CR_CPC0_PSR: | |
1446 | ret = cpc->psr; | |
1447 | break; | |
1448 | case PPC405CR_CPC0_JTAGID: | |
1449 | ret = cpc->jtagid; | |
1450 | break; | |
1451 | case PPC405CR_CPC0_ER: | |
1452 | ret = cpc->er; | |
1453 | break; | |
1454 | case PPC405CR_CPC0_FR: | |
1455 | ret = cpc->fr; | |
1456 | break; | |
1457 | case PPC405CR_CPC0_SR: | |
1458 | ret = ~(cpc->er | cpc->fr) & 0xFFFF0000; | |
1459 | break; | |
1460 | default: | |
1461 | /* Avoid gcc warning */ | |
1462 | ret = 0; | |
1463 | break; | |
1464 | } | |
1465 | ||
1466 | return ret; | |
1467 | } | |
1468 | ||
73b01960 | 1469 | static void dcr_write_crcpc (void *opaque, int dcrn, uint32_t val) |
8ecc7913 | 1470 | { |
c227f099 | 1471 | ppc405cr_cpc_t *cpc; |
8ecc7913 JM |
1472 | |
1473 | cpc = opaque; | |
1474 | switch (dcrn) { | |
1475 | case PPC405CR_CPC0_PLLMR: | |
1476 | cpc->pllmr = val & 0xFFF77C3F; | |
1477 | break; | |
1478 | case PPC405CR_CPC0_CR0: | |
1479 | cpc->cr0 = val & 0x0FFFFFFE; | |
1480 | break; | |
1481 | case PPC405CR_CPC0_CR1: | |
1482 | cpc->cr1 = val & 0x00800000; | |
1483 | break; | |
1484 | case PPC405CR_CPC0_PSR: | |
1485 | /* Read-only */ | |
1486 | break; | |
1487 | case PPC405CR_CPC0_JTAGID: | |
1488 | /* Read-only */ | |
1489 | break; | |
1490 | case PPC405CR_CPC0_ER: | |
1491 | cpc->er = val & 0xBFFC0000; | |
1492 | break; | |
1493 | case PPC405CR_CPC0_FR: | |
1494 | cpc->fr = val & 0xBFFC0000; | |
1495 | break; | |
1496 | case PPC405CR_CPC0_SR: | |
1497 | /* Read-only */ | |
1498 | break; | |
1499 | } | |
1500 | } | |
1501 | ||
1502 | static void ppc405cr_cpc_reset (void *opaque) | |
1503 | { | |
c227f099 | 1504 | ppc405cr_cpc_t *cpc; |
8ecc7913 JM |
1505 | int D; |
1506 | ||
1507 | cpc = opaque; | |
1508 | /* Compute PLLMR value from PSR settings */ | |
1509 | cpc->pllmr = 0x80000000; | |
1510 | /* PFWD */ | |
1511 | switch ((cpc->psr >> 30) & 3) { | |
1512 | case 0: | |
1513 | /* Bypass */ | |
1514 | cpc->pllmr &= ~0x80000000; | |
1515 | break; | |
1516 | case 1: | |
1517 | /* Divide by 3 */ | |
1518 | cpc->pllmr |= 5 << 16; | |
1519 | break; | |
1520 | case 2: | |
1521 | /* Divide by 4 */ | |
1522 | cpc->pllmr |= 4 << 16; | |
1523 | break; | |
1524 | case 3: | |
1525 | /* Divide by 6 */ | |
1526 | cpc->pllmr |= 2 << 16; | |
1527 | break; | |
1528 | } | |
1529 | /* PFBD */ | |
1530 | D = (cpc->psr >> 28) & 3; | |
1531 | cpc->pllmr |= (D + 1) << 20; | |
1532 | /* PT */ | |
1533 | D = (cpc->psr >> 25) & 7; | |
1534 | switch (D) { | |
1535 | case 0x2: | |
1536 | cpc->pllmr |= 0x13; | |
1537 | break; | |
1538 | case 0x4: | |
1539 | cpc->pllmr |= 0x15; | |
1540 | break; | |
1541 | case 0x5: | |
1542 | cpc->pllmr |= 0x16; | |
1543 | break; | |
1544 | default: | |
1545 | break; | |
1546 | } | |
1547 | /* PDC */ | |
1548 | D = (cpc->psr >> 23) & 3; | |
1549 | cpc->pllmr |= D << 26; | |
1550 | /* ODP */ | |
1551 | D = (cpc->psr >> 21) & 3; | |
1552 | cpc->pllmr |= D << 10; | |
1553 | /* EBPD */ | |
1554 | D = (cpc->psr >> 17) & 3; | |
1555 | cpc->pllmr |= D << 24; | |
1556 | cpc->cr0 = 0x0000003C; | |
1557 | cpc->cr1 = 0x2B0D8800; | |
1558 | cpc->er = 0x00000000; | |
1559 | cpc->fr = 0x00000000; | |
1560 | ppc405cr_clk_setup(cpc); | |
1561 | } | |
1562 | ||
c227f099 | 1563 | static void ppc405cr_clk_init (ppc405cr_cpc_t *cpc) |
8ecc7913 JM |
1564 | { |
1565 | int D; | |
1566 | ||
1567 | /* XXX: this should be read from IO pins */ | |
1568 | cpc->psr = 0x00000000; /* 8 bits ROM */ | |
1569 | /* PFWD */ | |
1570 | D = 0x2; /* Divide by 4 */ | |
1571 | cpc->psr |= D << 30; | |
1572 | /* PFBD */ | |
1573 | D = 0x1; /* Divide by 2 */ | |
1574 | cpc->psr |= D << 28; | |
1575 | /* PDC */ | |
1576 | D = 0x1; /* Divide by 2 */ | |
1577 | cpc->psr |= D << 23; | |
1578 | /* PT */ | |
1579 | D = 0x5; /* M = 16 */ | |
1580 | cpc->psr |= D << 25; | |
1581 | /* ODP */ | |
1582 | D = 0x1; /* Divide by 2 */ | |
1583 | cpc->psr |= D << 21; | |
1584 | /* EBDP */ | |
1585 | D = 0x2; /* Divide by 4 */ | |
1586 | cpc->psr |= D << 17; | |
1587 | } | |
1588 | ||
e2684c0b | 1589 | static void ppc405cr_cpc_init (CPUPPCState *env, clk_setup_t clk_setup[7], |
8ecc7913 JM |
1590 | uint32_t sysclk) |
1591 | { | |
c227f099 | 1592 | ppc405cr_cpc_t *cpc; |
8ecc7913 | 1593 | |
7267c094 | 1594 | cpc = g_malloc0(sizeof(ppc405cr_cpc_t)); |
487414f1 | 1595 | memcpy(cpc->clk_setup, clk_setup, |
c227f099 | 1596 | PPC405CR_CLK_NB * sizeof(clk_setup_t)); |
487414f1 AL |
1597 | cpc->sysclk = sysclk; |
1598 | cpc->jtagid = 0x42051049; | |
1599 | ppc_dcr_register(env, PPC405CR_CPC0_PSR, cpc, | |
1600 | &dcr_read_crcpc, &dcr_write_crcpc); | |
1601 | ppc_dcr_register(env, PPC405CR_CPC0_CR0, cpc, | |
1602 | &dcr_read_crcpc, &dcr_write_crcpc); | |
1603 | ppc_dcr_register(env, PPC405CR_CPC0_CR1, cpc, | |
1604 | &dcr_read_crcpc, &dcr_write_crcpc); | |
1605 | ppc_dcr_register(env, PPC405CR_CPC0_JTAGID, cpc, | |
1606 | &dcr_read_crcpc, &dcr_write_crcpc); | |
1607 | ppc_dcr_register(env, PPC405CR_CPC0_PLLMR, cpc, | |
1608 | &dcr_read_crcpc, &dcr_write_crcpc); | |
1609 | ppc_dcr_register(env, PPC405CR_CPC0_ER, cpc, | |
1610 | &dcr_read_crcpc, &dcr_write_crcpc); | |
1611 | ppc_dcr_register(env, PPC405CR_CPC0_FR, cpc, | |
1612 | &dcr_read_crcpc, &dcr_write_crcpc); | |
1613 | ppc_dcr_register(env, PPC405CR_CPC0_SR, cpc, | |
1614 | &dcr_read_crcpc, &dcr_write_crcpc); | |
1615 | ppc405cr_clk_init(cpc); | |
a08d4367 | 1616 | qemu_register_reset(ppc405cr_cpc_reset, cpc); |
8ecc7913 JM |
1617 | } |
1618 | ||
e2684c0b | 1619 | CPUPPCState *ppc405cr_init(MemoryRegion *address_space_mem, |
52ce55a1 | 1620 | MemoryRegion ram_memories[4], |
a8170e5e AK |
1621 | hwaddr ram_bases[4], |
1622 | hwaddr ram_sizes[4], | |
52ce55a1 RH |
1623 | uint32_t sysclk, qemu_irq **picp, |
1624 | int do_init) | |
8ecc7913 | 1625 | { |
c227f099 | 1626 | clk_setup_t clk_setup[PPC405CR_CLK_NB]; |
8ecc7913 | 1627 | qemu_irq dma_irqs[4]; |
2f9859fb | 1628 | PowerPCCPU *cpu; |
e2684c0b | 1629 | CPUPPCState *env; |
8ecc7913 | 1630 | qemu_irq *pic, *irqs; |
8ecc7913 JM |
1631 | |
1632 | memset(clk_setup, 0, sizeof(clk_setup)); | |
9391b8c5 IM |
1633 | cpu = ppc4xx_init(POWERPC_CPU_TYPE_NAME("405crc"), |
1634 | &clk_setup[PPC405CR_CPU_CLK], | |
04f20795 | 1635 | &clk_setup[PPC405CR_TMR_CLK], sysclk); |
2f9859fb | 1636 | env = &cpu->env; |
8ecc7913 | 1637 | /* Memory mapped devices registers */ |
8ecc7913 JM |
1638 | /* PLB arbitrer */ |
1639 | ppc4xx_plb_init(env); | |
1640 | /* PLB to OPB bridge */ | |
1641 | ppc4xx_pob_init(env); | |
1642 | /* OBP arbitrer */ | |
802670e6 | 1643 | ppc4xx_opba_init(0xef600600); |
8ecc7913 | 1644 | /* Universal interrupt controller */ |
7267c094 | 1645 | irqs = g_malloc0(sizeof(qemu_irq) * PPCUIC_OUTPUT_NB); |
8ecc7913 | 1646 | irqs[PPCUIC_OUTPUT_INT] = |
b48d7d69 | 1647 | ((qemu_irq *)env->irq_inputs)[PPC40x_INPUT_INT]; |
8ecc7913 | 1648 | irqs[PPCUIC_OUTPUT_CINT] = |
b48d7d69 | 1649 | ((qemu_irq *)env->irq_inputs)[PPC40x_INPUT_CINT]; |
8ecc7913 JM |
1650 | pic = ppcuic_init(env, irqs, 0x0C0, 0, 1); |
1651 | *picp = pic; | |
1652 | /* SDRAM controller */ | |
b6dcbe08 AK |
1653 | ppc4xx_sdram_init(env, pic[14], 1, ram_memories, |
1654 | ram_bases, ram_sizes, do_init); | |
8ecc7913 JM |
1655 | /* External bus controller */ |
1656 | ppc405_ebc_init(env); | |
1657 | /* DMA controller */ | |
04f20795 JM |
1658 | dma_irqs[0] = pic[26]; |
1659 | dma_irqs[1] = pic[25]; | |
1660 | dma_irqs[2] = pic[24]; | |
1661 | dma_irqs[3] = pic[23]; | |
8ecc7913 JM |
1662 | ppc405_dma_init(env, dma_irqs); |
1663 | /* Serial ports */ | |
9bca0edb | 1664 | if (serial_hd(0) != NULL) { |
52ce55a1 | 1665 | serial_mm_init(address_space_mem, 0xef600300, 0, pic[0], |
9bca0edb | 1666 | PPC_SERIAL_MM_BAUDBASE, serial_hd(0), |
39186d8a | 1667 | DEVICE_BIG_ENDIAN); |
8ecc7913 | 1668 | } |
9bca0edb | 1669 | if (serial_hd(1) != NULL) { |
52ce55a1 | 1670 | serial_mm_init(address_space_mem, 0xef600400, 0, pic[1], |
9bca0edb | 1671 | PPC_SERIAL_MM_BAUDBASE, serial_hd(1), |
39186d8a | 1672 | DEVICE_BIG_ENDIAN); |
8ecc7913 JM |
1673 | } |
1674 | /* IIC controller */ | |
3b09bb0f | 1675 | sysbus_create_simple(TYPE_PPC4xx_I2C, 0xef600500, pic[2]); |
8ecc7913 | 1676 | /* GPIO */ |
802670e6 | 1677 | ppc405_gpio_init(0xef600700); |
8ecc7913 JM |
1678 | /* CPU control */ |
1679 | ppc405cr_cpc_init(env, clk_setup, sysclk); | |
8ecc7913 JM |
1680 | |
1681 | return env; | |
1682 | } | |
1683 | ||
1684 | /*****************************************************************************/ | |
1685 | /* PowerPC 405EP */ | |
1686 | /* CPU control */ | |
1687 | enum { | |
1688 | PPC405EP_CPC0_PLLMR0 = 0x0F0, | |
1689 | PPC405EP_CPC0_BOOT = 0x0F1, | |
1690 | PPC405EP_CPC0_EPCTL = 0x0F3, | |
1691 | PPC405EP_CPC0_PLLMR1 = 0x0F4, | |
1692 | PPC405EP_CPC0_UCR = 0x0F5, | |
1693 | PPC405EP_CPC0_SRR = 0x0F6, | |
1694 | PPC405EP_CPC0_JTAGID = 0x0F7, | |
1695 | PPC405EP_CPC0_PCI = 0x0F9, | |
9c02f1a2 JM |
1696 | #if 0 |
1697 | PPC405EP_CPC0_ER = xxx, | |
1698 | PPC405EP_CPC0_FR = xxx, | |
1699 | PPC405EP_CPC0_SR = xxx, | |
1700 | #endif | |
8ecc7913 JM |
1701 | }; |
1702 | ||
04f20795 JM |
1703 | enum { |
1704 | PPC405EP_CPU_CLK = 0, | |
1705 | PPC405EP_PLB_CLK = 1, | |
1706 | PPC405EP_OPB_CLK = 2, | |
1707 | PPC405EP_EBC_CLK = 3, | |
1708 | PPC405EP_MAL_CLK = 4, | |
1709 | PPC405EP_PCI_CLK = 5, | |
1710 | PPC405EP_UART0_CLK = 6, | |
1711 | PPC405EP_UART1_CLK = 7, | |
1712 | PPC405EP_CLK_NB = 8, | |
1713 | }; | |
1714 | ||
c227f099 AL |
1715 | typedef struct ppc405ep_cpc_t ppc405ep_cpc_t; |
1716 | struct ppc405ep_cpc_t { | |
8ecc7913 | 1717 | uint32_t sysclk; |
c227f099 | 1718 | clk_setup_t clk_setup[PPC405EP_CLK_NB]; |
8ecc7913 JM |
1719 | uint32_t boot; |
1720 | uint32_t epctl; | |
1721 | uint32_t pllmr[2]; | |
1722 | uint32_t ucr; | |
1723 | uint32_t srr; | |
1724 | uint32_t jtagid; | |
1725 | uint32_t pci; | |
9c02f1a2 JM |
1726 | /* Clock and power management */ |
1727 | uint32_t er; | |
1728 | uint32_t fr; | |
1729 | uint32_t sr; | |
8ecc7913 JM |
1730 | }; |
1731 | ||
c227f099 | 1732 | static void ppc405ep_compute_clocks (ppc405ep_cpc_t *cpc) |
8ecc7913 JM |
1733 | { |
1734 | uint32_t CPU_clk, PLB_clk, OPB_clk, EBC_clk, MAL_clk, PCI_clk; | |
1735 | uint32_t UART0_clk, UART1_clk; | |
1736 | uint64_t VCO_out, PLL_out; | |
1737 | int M, D; | |
1738 | ||
1739 | VCO_out = 0; | |
1740 | if ((cpc->pllmr[1] & 0x80000000) && !(cpc->pllmr[1] & 0x40000000)) { | |
1741 | M = (((cpc->pllmr[1] >> 20) - 1) & 0xF) + 1; /* FBMUL */ | |
aae9366a JM |
1742 | #ifdef DEBUG_CLOCKS_LL |
1743 | printf("FBMUL %01" PRIx32 " %d\n", (cpc->pllmr[1] >> 20) & 0xF, M); | |
1744 | #endif | |
8ecc7913 | 1745 | D = 8 - ((cpc->pllmr[1] >> 16) & 0x7); /* FWDA */ |
aae9366a JM |
1746 | #ifdef DEBUG_CLOCKS_LL |
1747 | printf("FWDA %01" PRIx32 " %d\n", (cpc->pllmr[1] >> 16) & 0x7, D); | |
1748 | #endif | |
fb6971c1 | 1749 | VCO_out = (uint64_t)cpc->sysclk * M * D; |
8ecc7913 JM |
1750 | if (VCO_out < 500000000UL || VCO_out > 1000000000UL) { |
1751 | /* Error - unlock the PLL */ | |
1752 | printf("VCO out of range %" PRIu64 "\n", VCO_out); | |
1753 | #if 0 | |
1754 | cpc->pllmr[1] &= ~0x80000000; | |
1755 | goto pll_bypass; | |
1756 | #endif | |
1757 | } | |
1758 | PLL_out = VCO_out / D; | |
9c02f1a2 JM |
1759 | /* Pretend the PLL is locked */ |
1760 | cpc->boot |= 0x00000001; | |
8ecc7913 JM |
1761 | } else { |
1762 | #if 0 | |
1763 | pll_bypass: | |
1764 | #endif | |
1765 | PLL_out = cpc->sysclk; | |
9c02f1a2 JM |
1766 | if (cpc->pllmr[1] & 0x40000000) { |
1767 | /* Pretend the PLL is not locked */ | |
1768 | cpc->boot &= ~0x00000001; | |
1769 | } | |
8ecc7913 JM |
1770 | } |
1771 | /* Now, compute all other clocks */ | |
1772 | D = ((cpc->pllmr[0] >> 20) & 0x3) + 1; /* CCDV */ | |
aae9366a JM |
1773 | #ifdef DEBUG_CLOCKS_LL |
1774 | printf("CCDV %01" PRIx32 " %d\n", (cpc->pllmr[0] >> 20) & 0x3, D); | |
8ecc7913 JM |
1775 | #endif |
1776 | CPU_clk = PLL_out / D; | |
1777 | D = ((cpc->pllmr[0] >> 16) & 0x3) + 1; /* CBDV */ | |
aae9366a JM |
1778 | #ifdef DEBUG_CLOCKS_LL |
1779 | printf("CBDV %01" PRIx32 " %d\n", (cpc->pllmr[0] >> 16) & 0x3, D); | |
8ecc7913 JM |
1780 | #endif |
1781 | PLB_clk = CPU_clk / D; | |
1782 | D = ((cpc->pllmr[0] >> 12) & 0x3) + 1; /* OPDV */ | |
aae9366a JM |
1783 | #ifdef DEBUG_CLOCKS_LL |
1784 | printf("OPDV %01" PRIx32 " %d\n", (cpc->pllmr[0] >> 12) & 0x3, D); | |
8ecc7913 JM |
1785 | #endif |
1786 | OPB_clk = PLB_clk / D; | |
1787 | D = ((cpc->pllmr[0] >> 8) & 0x3) + 2; /* EPDV */ | |
aae9366a JM |
1788 | #ifdef DEBUG_CLOCKS_LL |
1789 | printf("EPDV %01" PRIx32 " %d\n", (cpc->pllmr[0] >> 8) & 0x3, D); | |
8ecc7913 JM |
1790 | #endif |
1791 | EBC_clk = PLB_clk / D; | |
1792 | D = ((cpc->pllmr[0] >> 4) & 0x3) + 1; /* MPDV */ | |
aae9366a JM |
1793 | #ifdef DEBUG_CLOCKS_LL |
1794 | printf("MPDV %01" PRIx32 " %d\n", (cpc->pllmr[0] >> 4) & 0x3, D); | |
8ecc7913 JM |
1795 | #endif |
1796 | MAL_clk = PLB_clk / D; | |
1797 | D = (cpc->pllmr[0] & 0x3) + 1; /* PPDV */ | |
aae9366a JM |
1798 | #ifdef DEBUG_CLOCKS_LL |
1799 | printf("PPDV %01" PRIx32 " %d\n", cpc->pllmr[0] & 0x3, D); | |
8ecc7913 JM |
1800 | #endif |
1801 | PCI_clk = PLB_clk / D; | |
1802 | D = ((cpc->ucr - 1) & 0x7F) + 1; /* U0DIV */ | |
aae9366a JM |
1803 | #ifdef DEBUG_CLOCKS_LL |
1804 | printf("U0DIV %01" PRIx32 " %d\n", cpc->ucr & 0x7F, D); | |
8ecc7913 JM |
1805 | #endif |
1806 | UART0_clk = PLL_out / D; | |
1807 | D = (((cpc->ucr >> 8) - 1) & 0x7F) + 1; /* U1DIV */ | |
aae9366a JM |
1808 | #ifdef DEBUG_CLOCKS_LL |
1809 | printf("U1DIV %01" PRIx32 " %d\n", (cpc->ucr >> 8) & 0x7F, D); | |
8ecc7913 JM |
1810 | #endif |
1811 | UART1_clk = PLL_out / D; | |
1812 | #ifdef DEBUG_CLOCKS | |
aae9366a | 1813 | printf("Setup PPC405EP clocks - sysclk %" PRIu32 " VCO %" PRIu64 |
8ecc7913 | 1814 | " PLL out %" PRIu64 " Hz\n", cpc->sysclk, VCO_out, PLL_out); |
aae9366a JM |
1815 | printf("CPU %" PRIu32 " PLB %" PRIu32 " OPB %" PRIu32 " EBC %" PRIu32 |
1816 | " MAL %" PRIu32 " PCI %" PRIu32 " UART0 %" PRIu32 | |
1817 | " UART1 %" PRIu32 "\n", | |
8ecc7913 JM |
1818 | CPU_clk, PLB_clk, OPB_clk, EBC_clk, MAL_clk, PCI_clk, |
1819 | UART0_clk, UART1_clk); | |
1820 | #endif | |
1821 | /* Setup CPU clocks */ | |
04f20795 | 1822 | clk_setup(&cpc->clk_setup[PPC405EP_CPU_CLK], CPU_clk); |
8ecc7913 | 1823 | /* Setup PLB clock */ |
04f20795 | 1824 | clk_setup(&cpc->clk_setup[PPC405EP_PLB_CLK], PLB_clk); |
8ecc7913 | 1825 | /* Setup OPB clock */ |
04f20795 | 1826 | clk_setup(&cpc->clk_setup[PPC405EP_OPB_CLK], OPB_clk); |
8ecc7913 | 1827 | /* Setup external clock */ |
04f20795 | 1828 | clk_setup(&cpc->clk_setup[PPC405EP_EBC_CLK], EBC_clk); |
8ecc7913 | 1829 | /* Setup MAL clock */ |
04f20795 | 1830 | clk_setup(&cpc->clk_setup[PPC405EP_MAL_CLK], MAL_clk); |
8ecc7913 | 1831 | /* Setup PCI clock */ |
04f20795 | 1832 | clk_setup(&cpc->clk_setup[PPC405EP_PCI_CLK], PCI_clk); |
8ecc7913 | 1833 | /* Setup UART0 clock */ |
04f20795 | 1834 | clk_setup(&cpc->clk_setup[PPC405EP_UART0_CLK], UART0_clk); |
8ecc7913 | 1835 | /* Setup UART1 clock */ |
04f20795 | 1836 | clk_setup(&cpc->clk_setup[PPC405EP_UART1_CLK], UART1_clk); |
8ecc7913 JM |
1837 | } |
1838 | ||
73b01960 | 1839 | static uint32_t dcr_read_epcpc (void *opaque, int dcrn) |
8ecc7913 | 1840 | { |
c227f099 | 1841 | ppc405ep_cpc_t *cpc; |
73b01960 | 1842 | uint32_t ret; |
8ecc7913 JM |
1843 | |
1844 | cpc = opaque; | |
1845 | switch (dcrn) { | |
1846 | case PPC405EP_CPC0_BOOT: | |
1847 | ret = cpc->boot; | |
1848 | break; | |
1849 | case PPC405EP_CPC0_EPCTL: | |
1850 | ret = cpc->epctl; | |
1851 | break; | |
1852 | case PPC405EP_CPC0_PLLMR0: | |
1853 | ret = cpc->pllmr[0]; | |
1854 | break; | |
1855 | case PPC405EP_CPC0_PLLMR1: | |
1856 | ret = cpc->pllmr[1]; | |
1857 | break; | |
1858 | case PPC405EP_CPC0_UCR: | |
1859 | ret = cpc->ucr; | |
1860 | break; | |
1861 | case PPC405EP_CPC0_SRR: | |
1862 | ret = cpc->srr; | |
1863 | break; | |
1864 | case PPC405EP_CPC0_JTAGID: | |
1865 | ret = cpc->jtagid; | |
1866 | break; | |
1867 | case PPC405EP_CPC0_PCI: | |
1868 | ret = cpc->pci; | |
1869 | break; | |
1870 | default: | |
1871 | /* Avoid gcc warning */ | |
1872 | ret = 0; | |
1873 | break; | |
1874 | } | |
1875 | ||
1876 | return ret; | |
1877 | } | |
1878 | ||
73b01960 | 1879 | static void dcr_write_epcpc (void *opaque, int dcrn, uint32_t val) |
8ecc7913 | 1880 | { |
c227f099 | 1881 | ppc405ep_cpc_t *cpc; |
8ecc7913 JM |
1882 | |
1883 | cpc = opaque; | |
1884 | switch (dcrn) { | |
1885 | case PPC405EP_CPC0_BOOT: | |
1886 | /* Read-only register */ | |
1887 | break; | |
1888 | case PPC405EP_CPC0_EPCTL: | |
1889 | /* Don't care for now */ | |
1890 | cpc->epctl = val & 0xC00000F3; | |
1891 | break; | |
1892 | case PPC405EP_CPC0_PLLMR0: | |
1893 | cpc->pllmr[0] = val & 0x00633333; | |
1894 | ppc405ep_compute_clocks(cpc); | |
1895 | break; | |
1896 | case PPC405EP_CPC0_PLLMR1: | |
1897 | cpc->pllmr[1] = val & 0xC0F73FFF; | |
1898 | ppc405ep_compute_clocks(cpc); | |
1899 | break; | |
1900 | case PPC405EP_CPC0_UCR: | |
1901 | /* UART control - don't care for now */ | |
1902 | cpc->ucr = val & 0x003F7F7F; | |
1903 | break; | |
1904 | case PPC405EP_CPC0_SRR: | |
1905 | cpc->srr = val; | |
1906 | break; | |
1907 | case PPC405EP_CPC0_JTAGID: | |
1908 | /* Read-only */ | |
1909 | break; | |
1910 | case PPC405EP_CPC0_PCI: | |
1911 | cpc->pci = val; | |
1912 | break; | |
1913 | } | |
1914 | } | |
1915 | ||
1916 | static void ppc405ep_cpc_reset (void *opaque) | |
1917 | { | |
c227f099 | 1918 | ppc405ep_cpc_t *cpc = opaque; |
8ecc7913 JM |
1919 | |
1920 | cpc->boot = 0x00000010; /* Boot from PCI - IIC EEPROM disabled */ | |
1921 | cpc->epctl = 0x00000000; | |
1922 | cpc->pllmr[0] = 0x00011010; | |
1923 | cpc->pllmr[1] = 0x40000000; | |
1924 | cpc->ucr = 0x00000000; | |
1925 | cpc->srr = 0x00040000; | |
1926 | cpc->pci = 0x00000000; | |
9c02f1a2 JM |
1927 | cpc->er = 0x00000000; |
1928 | cpc->fr = 0x00000000; | |
1929 | cpc->sr = 0x00000000; | |
8ecc7913 JM |
1930 | ppc405ep_compute_clocks(cpc); |
1931 | } | |
1932 | ||
1933 | /* XXX: sysclk should be between 25 and 100 MHz */ | |
e2684c0b | 1934 | static void ppc405ep_cpc_init (CPUPPCState *env, clk_setup_t clk_setup[8], |
8ecc7913 JM |
1935 | uint32_t sysclk) |
1936 | { | |
c227f099 | 1937 | ppc405ep_cpc_t *cpc; |
8ecc7913 | 1938 | |
7267c094 | 1939 | cpc = g_malloc0(sizeof(ppc405ep_cpc_t)); |
487414f1 | 1940 | memcpy(cpc->clk_setup, clk_setup, |
c227f099 | 1941 | PPC405EP_CLK_NB * sizeof(clk_setup_t)); |
487414f1 AL |
1942 | cpc->jtagid = 0x20267049; |
1943 | cpc->sysclk = sysclk; | |
a08d4367 | 1944 | qemu_register_reset(&ppc405ep_cpc_reset, cpc); |
487414f1 AL |
1945 | ppc_dcr_register(env, PPC405EP_CPC0_BOOT, cpc, |
1946 | &dcr_read_epcpc, &dcr_write_epcpc); | |
1947 | ppc_dcr_register(env, PPC405EP_CPC0_EPCTL, cpc, | |
1948 | &dcr_read_epcpc, &dcr_write_epcpc); | |
1949 | ppc_dcr_register(env, PPC405EP_CPC0_PLLMR0, cpc, | |
1950 | &dcr_read_epcpc, &dcr_write_epcpc); | |
1951 | ppc_dcr_register(env, PPC405EP_CPC0_PLLMR1, cpc, | |
1952 | &dcr_read_epcpc, &dcr_write_epcpc); | |
1953 | ppc_dcr_register(env, PPC405EP_CPC0_UCR, cpc, | |
1954 | &dcr_read_epcpc, &dcr_write_epcpc); | |
1955 | ppc_dcr_register(env, PPC405EP_CPC0_SRR, cpc, | |
1956 | &dcr_read_epcpc, &dcr_write_epcpc); | |
1957 | ppc_dcr_register(env, PPC405EP_CPC0_JTAGID, cpc, | |
1958 | &dcr_read_epcpc, &dcr_write_epcpc); | |
1959 | ppc_dcr_register(env, PPC405EP_CPC0_PCI, cpc, | |
1960 | &dcr_read_epcpc, &dcr_write_epcpc); | |
9c02f1a2 | 1961 | #if 0 |
487414f1 AL |
1962 | ppc_dcr_register(env, PPC405EP_CPC0_ER, cpc, |
1963 | &dcr_read_epcpc, &dcr_write_epcpc); | |
1964 | ppc_dcr_register(env, PPC405EP_CPC0_FR, cpc, | |
1965 | &dcr_read_epcpc, &dcr_write_epcpc); | |
1966 | ppc_dcr_register(env, PPC405EP_CPC0_SR, cpc, | |
1967 | &dcr_read_epcpc, &dcr_write_epcpc); | |
9c02f1a2 | 1968 | #endif |
8ecc7913 JM |
1969 | } |
1970 | ||
e2684c0b | 1971 | CPUPPCState *ppc405ep_init(MemoryRegion *address_space_mem, |
52ce55a1 | 1972 | MemoryRegion ram_memories[2], |
a8170e5e AK |
1973 | hwaddr ram_bases[2], |
1974 | hwaddr ram_sizes[2], | |
52ce55a1 RH |
1975 | uint32_t sysclk, qemu_irq **picp, |
1976 | int do_init) | |
8ecc7913 | 1977 | { |
c227f099 | 1978 | clk_setup_t clk_setup[PPC405EP_CLK_NB], tlb_clk_setup; |
9c02f1a2 | 1979 | qemu_irq dma_irqs[4], gpt_irqs[5], mal_irqs[4]; |
2f9859fb | 1980 | PowerPCCPU *cpu; |
e2684c0b | 1981 | CPUPPCState *env; |
8ecc7913 | 1982 | qemu_irq *pic, *irqs; |
8ecc7913 JM |
1983 | |
1984 | memset(clk_setup, 0, sizeof(clk_setup)); | |
1985 | /* init CPUs */ | |
9391b8c5 IM |
1986 | cpu = ppc4xx_init(POWERPC_CPU_TYPE_NAME("405ep"), |
1987 | &clk_setup[PPC405EP_CPU_CLK], | |
9c02f1a2 | 1988 | &tlb_clk_setup, sysclk); |
2f9859fb | 1989 | env = &cpu->env; |
9c02f1a2 JM |
1990 | clk_setup[PPC405EP_CPU_CLK].cb = tlb_clk_setup.cb; |
1991 | clk_setup[PPC405EP_CPU_CLK].opaque = tlb_clk_setup.opaque; | |
8ecc7913 JM |
1992 | /* Internal devices init */ |
1993 | /* Memory mapped devices registers */ | |
8ecc7913 JM |
1994 | /* PLB arbitrer */ |
1995 | ppc4xx_plb_init(env); | |
1996 | /* PLB to OPB bridge */ | |
1997 | ppc4xx_pob_init(env); | |
1998 | /* OBP arbitrer */ | |
802670e6 | 1999 | ppc4xx_opba_init(0xef600600); |
d715ea96 | 2000 | /* Initialize timers */ |
a34a92b9 | 2001 | ppc_booke_timers_init(cpu, sysclk, 0); |
8ecc7913 | 2002 | /* Universal interrupt controller */ |
7267c094 | 2003 | irqs = g_malloc0(sizeof(qemu_irq) * PPCUIC_OUTPUT_NB); |
8ecc7913 | 2004 | irqs[PPCUIC_OUTPUT_INT] = |
b48d7d69 | 2005 | ((qemu_irq *)env->irq_inputs)[PPC40x_INPUT_INT]; |
8ecc7913 | 2006 | irqs[PPCUIC_OUTPUT_CINT] = |
b48d7d69 | 2007 | ((qemu_irq *)env->irq_inputs)[PPC40x_INPUT_CINT]; |
8ecc7913 JM |
2008 | pic = ppcuic_init(env, irqs, 0x0C0, 0, 1); |
2009 | *picp = pic; | |
2010 | /* SDRAM controller */ | |
923e5e33 | 2011 | /* XXX 405EP has no ECC interrupt */ |
b6dcbe08 AK |
2012 | ppc4xx_sdram_init(env, pic[17], 2, ram_memories, |
2013 | ram_bases, ram_sizes, do_init); | |
8ecc7913 JM |
2014 | /* External bus controller */ |
2015 | ppc405_ebc_init(env); | |
2016 | /* DMA controller */ | |
923e5e33 AJ |
2017 | dma_irqs[0] = pic[5]; |
2018 | dma_irqs[1] = pic[6]; | |
2019 | dma_irqs[2] = pic[7]; | |
2020 | dma_irqs[3] = pic[8]; | |
8ecc7913 JM |
2021 | ppc405_dma_init(env, dma_irqs); |
2022 | /* IIC controller */ | |
3b09bb0f | 2023 | sysbus_create_simple(TYPE_PPC4xx_I2C, 0xef600500, pic[2]); |
8ecc7913 | 2024 | /* GPIO */ |
802670e6 | 2025 | ppc405_gpio_init(0xef600700); |
8ecc7913 | 2026 | /* Serial ports */ |
9bca0edb | 2027 | if (serial_hd(0) != NULL) { |
52ce55a1 | 2028 | serial_mm_init(address_space_mem, 0xef600300, 0, pic[0], |
9bca0edb | 2029 | PPC_SERIAL_MM_BAUDBASE, serial_hd(0), |
39186d8a | 2030 | DEVICE_BIG_ENDIAN); |
8ecc7913 | 2031 | } |
9bca0edb | 2032 | if (serial_hd(1) != NULL) { |
52ce55a1 | 2033 | serial_mm_init(address_space_mem, 0xef600400, 0, pic[1], |
9bca0edb | 2034 | PPC_SERIAL_MM_BAUDBASE, serial_hd(1), |
39186d8a | 2035 | DEVICE_BIG_ENDIAN); |
8ecc7913 JM |
2036 | } |
2037 | /* OCM */ | |
5c130f65 | 2038 | ppc405_ocm_init(env); |
9c02f1a2 | 2039 | /* GPT */ |
923e5e33 AJ |
2040 | gpt_irqs[0] = pic[19]; |
2041 | gpt_irqs[1] = pic[20]; | |
2042 | gpt_irqs[2] = pic[21]; | |
2043 | gpt_irqs[3] = pic[22]; | |
2044 | gpt_irqs[4] = pic[23]; | |
802670e6 | 2045 | ppc4xx_gpt_init(0xef600000, gpt_irqs); |
8ecc7913 | 2046 | /* PCI */ |
923e5e33 | 2047 | /* Uses pic[3], pic[16], pic[18] */ |
9c02f1a2 | 2048 | /* MAL */ |
923e5e33 AJ |
2049 | mal_irqs[0] = pic[11]; |
2050 | mal_irqs[1] = pic[12]; | |
2051 | mal_irqs[2] = pic[13]; | |
2052 | mal_irqs[3] = pic[14]; | |
04534280 | 2053 | ppc4xx_mal_init(env, 4, 2, mal_irqs); |
9c02f1a2 | 2054 | /* Ethernet */ |
923e5e33 | 2055 | /* Uses pic[9], pic[15], pic[17] */ |
8ecc7913 JM |
2056 | /* CPU control */ |
2057 | ppc405ep_cpc_init(env, clk_setup, sysclk); | |
8ecc7913 JM |
2058 | |
2059 | return env; | |
2060 | } |