2 * QEMU PowerPC 405 embedded processors emulation
4 * Copyright (c) 2007 Jocelyn Mayer
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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
24 #include "qemu/osdep.h"
25 #include "qapi/error.h"
26 #include "qemu-common.h"
29 #include "hw/ppc/ppc.h"
30 #include "hw/boards.h"
31 #include "hw/i2c/ppc4xx_i2c.h"
33 #include "hw/char/serial.h"
34 #include "qemu/timer.h"
35 #include "sysemu/sysemu.h"
37 #include "exec/address-spaces.h"
42 //#define DEBUG_SERIAL
45 //#define DEBUG_CLOCKS
46 //#define DEBUG_CLOCKS_LL
48 ram_addr_t
ppc405_set_bootinfo (CPUPPCState
*env
, ppc4xx_bd_info_t
*bd
,
51 CPUState
*cs
= CPU(ppc_env_get_cpu(env
));
55 /* We put the bd structure at the top of memory */
56 if (bd
->bi_memsize
>= 0x01000000UL
)
57 bdloc
= 0x01000000UL
- sizeof(struct ppc4xx_bd_info_t
);
59 bdloc
= bd
->bi_memsize
- sizeof(struct ppc4xx_bd_info_t
);
60 stl_be_phys(cs
->as
, bdloc
+ 0x00, bd
->bi_memstart
);
61 stl_be_phys(cs
->as
, bdloc
+ 0x04, bd
->bi_memsize
);
62 stl_be_phys(cs
->as
, bdloc
+ 0x08, bd
->bi_flashstart
);
63 stl_be_phys(cs
->as
, bdloc
+ 0x0C, bd
->bi_flashsize
);
64 stl_be_phys(cs
->as
, bdloc
+ 0x10, bd
->bi_flashoffset
);
65 stl_be_phys(cs
->as
, bdloc
+ 0x14, bd
->bi_sramstart
);
66 stl_be_phys(cs
->as
, bdloc
+ 0x18, bd
->bi_sramsize
);
67 stl_be_phys(cs
->as
, bdloc
+ 0x1C, bd
->bi_bootflags
);
68 stl_be_phys(cs
->as
, bdloc
+ 0x20, bd
->bi_ipaddr
);
69 for (i
= 0; i
< 6; i
++) {
70 stb_phys(cs
->as
, bdloc
+ 0x24 + i
, bd
->bi_enetaddr
[i
]);
72 stw_be_phys(cs
->as
, bdloc
+ 0x2A, bd
->bi_ethspeed
);
73 stl_be_phys(cs
->as
, bdloc
+ 0x2C, bd
->bi_intfreq
);
74 stl_be_phys(cs
->as
, bdloc
+ 0x30, bd
->bi_busfreq
);
75 stl_be_phys(cs
->as
, bdloc
+ 0x34, bd
->bi_baudrate
);
76 for (i
= 0; i
< 4; i
++) {
77 stb_phys(cs
->as
, bdloc
+ 0x38 + i
, bd
->bi_s_version
[i
]);
79 for (i
= 0; i
< 32; i
++) {
80 stb_phys(cs
->as
, bdloc
+ 0x3C + i
, bd
->bi_r_version
[i
]);
82 stl_be_phys(cs
->as
, bdloc
+ 0x5C, bd
->bi_plb_busfreq
);
83 stl_be_phys(cs
->as
, bdloc
+ 0x60, bd
->bi_pci_busfreq
);
84 for (i
= 0; i
< 6; i
++) {
85 stb_phys(cs
->as
, bdloc
+ 0x64 + i
, bd
->bi_pci_enetaddr
[i
]);
88 if (flags
& 0x00000001) {
89 for (i
= 0; i
< 6; i
++)
90 stb_phys(cs
->as
, bdloc
+ n
++, bd
->bi_pci_enetaddr2
[i
]);
92 stl_be_phys(cs
->as
, bdloc
+ n
, bd
->bi_opbfreq
);
94 for (i
= 0; i
< 2; i
++) {
95 stl_be_phys(cs
->as
, bdloc
+ n
, bd
->bi_iic_fast
[i
]);
102 /*****************************************************************************/
103 /* Shared peripherals */
105 /*****************************************************************************/
106 /* Peripheral local bus arbitrer */
116 typedef struct ppc4xx_plb_t ppc4xx_plb_t
;
117 struct ppc4xx_plb_t
{
123 static uint32_t dcr_read_plb (void *opaque
, int dcrn
)
140 /* Avoid gcc warning */
148 static void dcr_write_plb (void *opaque
, int dcrn
, uint32_t val
)
155 /* We don't care about the actual parameters written as
156 * we don't manage any priorities on the bus
158 plb
->acr
= val
& 0xF8000000;
170 static void ppc4xx_plb_reset (void *opaque
)
175 plb
->acr
= 0x00000000;
176 plb
->bear
= 0x00000000;
177 plb
->besr
= 0x00000000;
180 void ppc4xx_plb_init(CPUPPCState
*env
)
184 plb
= g_malloc0(sizeof(ppc4xx_plb_t
));
185 ppc_dcr_register(env
, PLB3A0_ACR
, plb
, &dcr_read_plb
, &dcr_write_plb
);
186 ppc_dcr_register(env
, PLB4A0_ACR
, plb
, &dcr_read_plb
, &dcr_write_plb
);
187 ppc_dcr_register(env
, PLB0_ACR
, plb
, &dcr_read_plb
, &dcr_write_plb
);
188 ppc_dcr_register(env
, PLB0_BEAR
, plb
, &dcr_read_plb
, &dcr_write_plb
);
189 ppc_dcr_register(env
, PLB0_BESR
, plb
, &dcr_read_plb
, &dcr_write_plb
);
190 ppc_dcr_register(env
, PLB4A1_ACR
, plb
, &dcr_read_plb
, &dcr_write_plb
);
191 qemu_register_reset(ppc4xx_plb_reset
, plb
);
194 /*****************************************************************************/
195 /* PLB to OPB bridge */
202 typedef struct ppc4xx_pob_t ppc4xx_pob_t
;
203 struct ppc4xx_pob_t
{
209 static uint32_t dcr_read_pob (void *opaque
, int dcrn
)
226 /* Avoid gcc warning */
234 static void dcr_write_pob (void *opaque
, int dcrn
, uint32_t val
)
254 static void ppc4xx_pob_reset (void *opaque
)
260 pob
->bear
= 0x00000000;
261 pob
->besr0
= 0x0000000;
262 pob
->besr1
= 0x0000000;
265 static void ppc4xx_pob_init(CPUPPCState
*env
)
269 pob
= g_malloc0(sizeof(ppc4xx_pob_t
));
270 ppc_dcr_register(env
, POB0_BEAR
, pob
, &dcr_read_pob
, &dcr_write_pob
);
271 ppc_dcr_register(env
, POB0_BESR0
, pob
, &dcr_read_pob
, &dcr_write_pob
);
272 ppc_dcr_register(env
, POB0_BESR1
, pob
, &dcr_read_pob
, &dcr_write_pob
);
273 qemu_register_reset(ppc4xx_pob_reset
, pob
);
276 /*****************************************************************************/
278 typedef struct ppc4xx_opba_t ppc4xx_opba_t
;
279 struct ppc4xx_opba_t
{
285 static uint32_t opba_readb (void *opaque
, hwaddr addr
)
291 printf("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
309 static void opba_writeb (void *opaque
,
310 hwaddr addr
, uint32_t value
)
315 printf("%s: addr " TARGET_FMT_plx
" val %08" PRIx32
"\n", __func__
, addr
,
321 opba
->cr
= value
& 0xF8;
324 opba
->pr
= value
& 0xFF;
331 static uint32_t opba_readw (void *opaque
, hwaddr addr
)
336 printf("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
338 ret
= opba_readb(opaque
, addr
) << 8;
339 ret
|= opba_readb(opaque
, addr
+ 1);
344 static void opba_writew (void *opaque
,
345 hwaddr addr
, uint32_t value
)
348 printf("%s: addr " TARGET_FMT_plx
" val %08" PRIx32
"\n", __func__
, addr
,
351 opba_writeb(opaque
, addr
, value
>> 8);
352 opba_writeb(opaque
, addr
+ 1, value
);
355 static uint32_t opba_readl (void *opaque
, hwaddr addr
)
360 printf("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
362 ret
= opba_readb(opaque
, addr
) << 24;
363 ret
|= opba_readb(opaque
, addr
+ 1) << 16;
368 static void opba_writel (void *opaque
,
369 hwaddr addr
, uint32_t value
)
372 printf("%s: addr " TARGET_FMT_plx
" val %08" PRIx32
"\n", __func__
, addr
,
375 opba_writeb(opaque
, addr
, value
>> 24);
376 opba_writeb(opaque
, addr
+ 1, value
>> 16);
379 static const MemoryRegionOps opba_ops
= {
381 .read
= { opba_readb
, opba_readw
, opba_readl
, },
382 .write
= { opba_writeb
, opba_writew
, opba_writel
, },
384 .endianness
= DEVICE_NATIVE_ENDIAN
,
387 static void ppc4xx_opba_reset (void *opaque
)
392 opba
->cr
= 0x00; /* No dynamic priorities - park disabled */
396 static void ppc4xx_opba_init(hwaddr base
)
400 opba
= g_malloc0(sizeof(ppc4xx_opba_t
));
402 printf("%s: offset " TARGET_FMT_plx
"\n", __func__
, base
);
404 memory_region_init_io(&opba
->io
, NULL
, &opba_ops
, opba
, "opba", 0x002);
405 memory_region_add_subregion(get_system_memory(), base
, &opba
->io
);
406 qemu_register_reset(ppc4xx_opba_reset
, opba
);
409 /*****************************************************************************/
410 /* Code decompression controller */
413 /*****************************************************************************/
414 /* Peripheral controller */
415 typedef struct ppc4xx_ebc_t ppc4xx_ebc_t
;
416 struct ppc4xx_ebc_t
{
427 EBC0_CFGADDR
= 0x012,
428 EBC0_CFGDATA
= 0x013,
431 static uint32_t dcr_read_ebc (void *opaque
, int dcrn
)
443 case 0x00: /* B0CR */
446 case 0x01: /* B1CR */
449 case 0x02: /* B2CR */
452 case 0x03: /* B3CR */
455 case 0x04: /* B4CR */
458 case 0x05: /* B5CR */
461 case 0x06: /* B6CR */
464 case 0x07: /* B7CR */
467 case 0x10: /* B0AP */
470 case 0x11: /* B1AP */
473 case 0x12: /* B2AP */
476 case 0x13: /* B3AP */
479 case 0x14: /* B4AP */
482 case 0x15: /* B5AP */
485 case 0x16: /* B6AP */
488 case 0x17: /* B7AP */
491 case 0x20: /* BEAR */
494 case 0x21: /* BESR0 */
497 case 0x22: /* BESR1 */
516 static void dcr_write_ebc (void *opaque
, int dcrn
, uint32_t val
)
527 case 0x00: /* B0CR */
529 case 0x01: /* B1CR */
531 case 0x02: /* B2CR */
533 case 0x03: /* B3CR */
535 case 0x04: /* B4CR */
537 case 0x05: /* B5CR */
539 case 0x06: /* B6CR */
541 case 0x07: /* B7CR */
543 case 0x10: /* B0AP */
545 case 0x11: /* B1AP */
547 case 0x12: /* B2AP */
549 case 0x13: /* B3AP */
551 case 0x14: /* B4AP */
553 case 0x15: /* B5AP */
555 case 0x16: /* B6AP */
557 case 0x17: /* B7AP */
559 case 0x20: /* BEAR */
561 case 0x21: /* BESR0 */
563 case 0x22: /* BESR1 */
576 static void ebc_reset (void *opaque
)
582 ebc
->addr
= 0x00000000;
583 ebc
->bap
[0] = 0x7F8FFE80;
584 ebc
->bcr
[0] = 0xFFE28000;
585 for (i
= 0; i
< 8; i
++) {
586 ebc
->bap
[i
] = 0x00000000;
587 ebc
->bcr
[i
] = 0x00000000;
589 ebc
->besr0
= 0x00000000;
590 ebc
->besr1
= 0x00000000;
591 ebc
->cfg
= 0x80400000;
594 void ppc405_ebc_init(CPUPPCState
*env
)
598 ebc
= g_malloc0(sizeof(ppc4xx_ebc_t
));
599 qemu_register_reset(&ebc_reset
, ebc
);
600 ppc_dcr_register(env
, EBC0_CFGADDR
,
601 ebc
, &dcr_read_ebc
, &dcr_write_ebc
);
602 ppc_dcr_register(env
, EBC0_CFGDATA
,
603 ebc
, &dcr_read_ebc
, &dcr_write_ebc
);
606 /*****************************************************************************/
635 typedef struct ppc405_dma_t ppc405_dma_t
;
636 struct ppc405_dma_t
{
649 static uint32_t dcr_read_dma (void *opaque
, int dcrn
)
654 static void dcr_write_dma (void *opaque
, int dcrn
, uint32_t val
)
658 static void ppc405_dma_reset (void *opaque
)
664 for (i
= 0; i
< 4; i
++) {
665 dma
->cr
[i
] = 0x00000000;
666 dma
->ct
[i
] = 0x00000000;
667 dma
->da
[i
] = 0x00000000;
668 dma
->sa
[i
] = 0x00000000;
669 dma
->sg
[i
] = 0x00000000;
671 dma
->sr
= 0x00000000;
672 dma
->sgc
= 0x00000000;
673 dma
->slp
= 0x7C000000;
674 dma
->pol
= 0x00000000;
677 static void ppc405_dma_init(CPUPPCState
*env
, qemu_irq irqs
[4])
681 dma
= g_malloc0(sizeof(ppc405_dma_t
));
682 memcpy(dma
->irqs
, irqs
, 4 * sizeof(qemu_irq
));
683 qemu_register_reset(&ppc405_dma_reset
, dma
);
684 ppc_dcr_register(env
, DMA0_CR0
,
685 dma
, &dcr_read_dma
, &dcr_write_dma
);
686 ppc_dcr_register(env
, DMA0_CT0
,
687 dma
, &dcr_read_dma
, &dcr_write_dma
);
688 ppc_dcr_register(env
, DMA0_DA0
,
689 dma
, &dcr_read_dma
, &dcr_write_dma
);
690 ppc_dcr_register(env
, DMA0_SA0
,
691 dma
, &dcr_read_dma
, &dcr_write_dma
);
692 ppc_dcr_register(env
, DMA0_SG0
,
693 dma
, &dcr_read_dma
, &dcr_write_dma
);
694 ppc_dcr_register(env
, DMA0_CR1
,
695 dma
, &dcr_read_dma
, &dcr_write_dma
);
696 ppc_dcr_register(env
, DMA0_CT1
,
697 dma
, &dcr_read_dma
, &dcr_write_dma
);
698 ppc_dcr_register(env
, DMA0_DA1
,
699 dma
, &dcr_read_dma
, &dcr_write_dma
);
700 ppc_dcr_register(env
, DMA0_SA1
,
701 dma
, &dcr_read_dma
, &dcr_write_dma
);
702 ppc_dcr_register(env
, DMA0_SG1
,
703 dma
, &dcr_read_dma
, &dcr_write_dma
);
704 ppc_dcr_register(env
, DMA0_CR2
,
705 dma
, &dcr_read_dma
, &dcr_write_dma
);
706 ppc_dcr_register(env
, DMA0_CT2
,
707 dma
, &dcr_read_dma
, &dcr_write_dma
);
708 ppc_dcr_register(env
, DMA0_DA2
,
709 dma
, &dcr_read_dma
, &dcr_write_dma
);
710 ppc_dcr_register(env
, DMA0_SA2
,
711 dma
, &dcr_read_dma
, &dcr_write_dma
);
712 ppc_dcr_register(env
, DMA0_SG2
,
713 dma
, &dcr_read_dma
, &dcr_write_dma
);
714 ppc_dcr_register(env
, DMA0_CR3
,
715 dma
, &dcr_read_dma
, &dcr_write_dma
);
716 ppc_dcr_register(env
, DMA0_CT3
,
717 dma
, &dcr_read_dma
, &dcr_write_dma
);
718 ppc_dcr_register(env
, DMA0_DA3
,
719 dma
, &dcr_read_dma
, &dcr_write_dma
);
720 ppc_dcr_register(env
, DMA0_SA3
,
721 dma
, &dcr_read_dma
, &dcr_write_dma
);
722 ppc_dcr_register(env
, DMA0_SG3
,
723 dma
, &dcr_read_dma
, &dcr_write_dma
);
724 ppc_dcr_register(env
, DMA0_SR
,
725 dma
, &dcr_read_dma
, &dcr_write_dma
);
726 ppc_dcr_register(env
, DMA0_SGC
,
727 dma
, &dcr_read_dma
, &dcr_write_dma
);
728 ppc_dcr_register(env
, DMA0_SLP
,
729 dma
, &dcr_read_dma
, &dcr_write_dma
);
730 ppc_dcr_register(env
, DMA0_POL
,
731 dma
, &dcr_read_dma
, &dcr_write_dma
);
734 /*****************************************************************************/
736 typedef struct ppc405_gpio_t ppc405_gpio_t
;
737 struct ppc405_gpio_t
{
752 static uint32_t ppc405_gpio_readb (void *opaque
, hwaddr addr
)
755 printf("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
761 static void ppc405_gpio_writeb (void *opaque
,
762 hwaddr addr
, uint32_t value
)
765 printf("%s: addr " TARGET_FMT_plx
" val %08" PRIx32
"\n", __func__
, addr
,
770 static uint32_t ppc405_gpio_readw (void *opaque
, hwaddr addr
)
773 printf("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
779 static void ppc405_gpio_writew (void *opaque
,
780 hwaddr addr
, uint32_t value
)
783 printf("%s: addr " TARGET_FMT_plx
" val %08" PRIx32
"\n", __func__
, addr
,
788 static uint32_t ppc405_gpio_readl (void *opaque
, hwaddr addr
)
791 printf("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
797 static void ppc405_gpio_writel (void *opaque
,
798 hwaddr addr
, uint32_t value
)
801 printf("%s: addr " TARGET_FMT_plx
" val %08" PRIx32
"\n", __func__
, addr
,
806 static const MemoryRegionOps ppc405_gpio_ops
= {
808 .read
= { ppc405_gpio_readb
, ppc405_gpio_readw
, ppc405_gpio_readl
, },
809 .write
= { ppc405_gpio_writeb
, ppc405_gpio_writew
, ppc405_gpio_writel
, },
811 .endianness
= DEVICE_NATIVE_ENDIAN
,
814 static void ppc405_gpio_reset (void *opaque
)
818 static void ppc405_gpio_init(hwaddr base
)
822 gpio
= g_malloc0(sizeof(ppc405_gpio_t
));
824 printf("%s: offset " TARGET_FMT_plx
"\n", __func__
, base
);
826 memory_region_init_io(&gpio
->io
, NULL
, &ppc405_gpio_ops
, gpio
, "pgio", 0x038);
827 memory_region_add_subregion(get_system_memory(), base
, &gpio
->io
);
828 qemu_register_reset(&ppc405_gpio_reset
, gpio
);
831 /*****************************************************************************/
835 OCM0_ISACNTL
= 0x019,
837 OCM0_DSACNTL
= 0x01B,
840 typedef struct ppc405_ocm_t ppc405_ocm_t
;
841 struct ppc405_ocm_t
{
843 MemoryRegion isarc_ram
;
844 MemoryRegion dsarc_ram
;
851 static void ocm_update_mappings (ppc405_ocm_t
*ocm
,
852 uint32_t isarc
, uint32_t isacntl
,
853 uint32_t dsarc
, uint32_t dsacntl
)
856 printf("OCM update ISA %08" PRIx32
" %08" PRIx32
" (%08" PRIx32
857 " %08" PRIx32
") DSA %08" PRIx32
" %08" PRIx32
858 " (%08" PRIx32
" %08" PRIx32
")\n",
859 isarc
, isacntl
, dsarc
, dsacntl
,
860 ocm
->isarc
, ocm
->isacntl
, ocm
->dsarc
, ocm
->dsacntl
);
862 if (ocm
->isarc
!= isarc
||
863 (ocm
->isacntl
& 0x80000000) != (isacntl
& 0x80000000)) {
864 if (ocm
->isacntl
& 0x80000000) {
865 /* Unmap previously assigned memory region */
866 printf("OCM unmap ISA %08" PRIx32
"\n", ocm
->isarc
);
867 memory_region_del_subregion(get_system_memory(), &ocm
->isarc_ram
);
869 if (isacntl
& 0x80000000) {
870 /* Map new instruction memory region */
872 printf("OCM map ISA %08" PRIx32
"\n", isarc
);
874 memory_region_add_subregion(get_system_memory(), isarc
,
878 if (ocm
->dsarc
!= dsarc
||
879 (ocm
->dsacntl
& 0x80000000) != (dsacntl
& 0x80000000)) {
880 if (ocm
->dsacntl
& 0x80000000) {
881 /* Beware not to unmap the region we just mapped */
882 if (!(isacntl
& 0x80000000) || ocm
->dsarc
!= isarc
) {
883 /* Unmap previously assigned memory region */
885 printf("OCM unmap DSA %08" PRIx32
"\n", ocm
->dsarc
);
887 memory_region_del_subregion(get_system_memory(),
891 if (dsacntl
& 0x80000000) {
892 /* Beware not to remap the region we just mapped */
893 if (!(isacntl
& 0x80000000) || dsarc
!= isarc
) {
894 /* Map new data memory region */
896 printf("OCM map DSA %08" PRIx32
"\n", dsarc
);
898 memory_region_add_subregion(get_system_memory(), dsarc
,
905 static uint32_t dcr_read_ocm (void *opaque
, int dcrn
)
932 static void dcr_write_ocm (void *opaque
, int dcrn
, uint32_t val
)
935 uint32_t isarc
, dsarc
, isacntl
, dsacntl
;
940 isacntl
= ocm
->isacntl
;
941 dsacntl
= ocm
->dsacntl
;
944 isarc
= val
& 0xFC000000;
947 isacntl
= val
& 0xC0000000;
950 isarc
= val
& 0xFC000000;
953 isacntl
= val
& 0xC0000000;
956 ocm_update_mappings(ocm
, isarc
, isacntl
, dsarc
, dsacntl
);
959 ocm
->isacntl
= isacntl
;
960 ocm
->dsacntl
= dsacntl
;
963 static void ocm_reset (void *opaque
)
966 uint32_t isarc
, dsarc
, isacntl
, dsacntl
;
970 isacntl
= 0x00000000;
972 dsacntl
= 0x00000000;
973 ocm_update_mappings(ocm
, isarc
, isacntl
, dsarc
, dsacntl
);
976 ocm
->isacntl
= isacntl
;
977 ocm
->dsacntl
= dsacntl
;
980 static void ppc405_ocm_init(CPUPPCState
*env
)
984 ocm
= g_malloc0(sizeof(ppc405_ocm_t
));
985 /* XXX: Size is 4096 or 0x04000000 */
986 memory_region_init_ram(&ocm
->isarc_ram
, NULL
, "ppc405.ocm", 4096,
988 memory_region_init_alias(&ocm
->dsarc_ram
, NULL
, "ppc405.dsarc", &ocm
->isarc_ram
,
990 qemu_register_reset(&ocm_reset
, ocm
);
991 ppc_dcr_register(env
, OCM0_ISARC
,
992 ocm
, &dcr_read_ocm
, &dcr_write_ocm
);
993 ppc_dcr_register(env
, OCM0_ISACNTL
,
994 ocm
, &dcr_read_ocm
, &dcr_write_ocm
);
995 ppc_dcr_register(env
, OCM0_DSARC
,
996 ocm
, &dcr_read_ocm
, &dcr_write_ocm
);
997 ppc_dcr_register(env
, OCM0_DSACNTL
,
998 ocm
, &dcr_read_ocm
, &dcr_write_ocm
);
1001 /*****************************************************************************/
1002 /* General purpose timers */
1003 typedef struct ppc4xx_gpt_t ppc4xx_gpt_t
;
1004 struct ppc4xx_gpt_t
{
1019 static uint32_t ppc4xx_gpt_readb (void *opaque
, hwaddr addr
)
1022 printf("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
1024 /* XXX: generate a bus fault */
1028 static void ppc4xx_gpt_writeb (void *opaque
,
1029 hwaddr addr
, uint32_t value
)
1032 printf("%s: addr " TARGET_FMT_plx
" val %08" PRIx32
"\n", __func__
, addr
,
1035 /* XXX: generate a bus fault */
1038 static uint32_t ppc4xx_gpt_readw (void *opaque
, hwaddr addr
)
1041 printf("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
1043 /* XXX: generate a bus fault */
1047 static void ppc4xx_gpt_writew (void *opaque
,
1048 hwaddr addr
, uint32_t value
)
1051 printf("%s: addr " TARGET_FMT_plx
" val %08" PRIx32
"\n", __func__
, addr
,
1054 /* XXX: generate a bus fault */
1057 static int ppc4xx_gpt_compare (ppc4xx_gpt_t
*gpt
, int n
)
1063 static void ppc4xx_gpt_set_output (ppc4xx_gpt_t
*gpt
, int n
, int level
)
1068 static void ppc4xx_gpt_set_outputs (ppc4xx_gpt_t
*gpt
)
1074 for (i
= 0; i
< 5; i
++) {
1075 if (gpt
->oe
& mask
) {
1076 /* Output is enabled */
1077 if (ppc4xx_gpt_compare(gpt
, i
)) {
1078 /* Comparison is OK */
1079 ppc4xx_gpt_set_output(gpt
, i
, gpt
->ol
& mask
);
1081 /* Comparison is KO */
1082 ppc4xx_gpt_set_output(gpt
, i
, gpt
->ol
& mask
? 0 : 1);
1089 static void ppc4xx_gpt_set_irqs (ppc4xx_gpt_t
*gpt
)
1095 for (i
= 0; i
< 5; i
++) {
1096 if (gpt
->is
& gpt
->im
& mask
)
1097 qemu_irq_raise(gpt
->irqs
[i
]);
1099 qemu_irq_lower(gpt
->irqs
[i
]);
1104 static void ppc4xx_gpt_compute_timer (ppc4xx_gpt_t
*gpt
)
1109 static uint32_t ppc4xx_gpt_readl (void *opaque
, hwaddr addr
)
1116 printf("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
1121 /* Time base counter */
1122 ret
= muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
) + gpt
->tb_offset
,
1123 gpt
->tb_freq
, NANOSECONDS_PER_SECOND
);
1134 /* Interrupt mask */
1139 /* Interrupt status */
1143 /* Interrupt enable */
1148 idx
= (addr
- 0x80) >> 2;
1149 ret
= gpt
->comp
[idx
];
1153 idx
= (addr
- 0xC0) >> 2;
1154 ret
= gpt
->mask
[idx
];
1164 static void ppc4xx_gpt_writel (void *opaque
,
1165 hwaddr addr
, uint32_t value
)
1171 printf("%s: addr " TARGET_FMT_plx
" val %08" PRIx32
"\n", __func__
, addr
,
1177 /* Time base counter */
1178 gpt
->tb_offset
= muldiv64(value
, NANOSECONDS_PER_SECOND
, gpt
->tb_freq
)
1179 - qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
);
1180 ppc4xx_gpt_compute_timer(gpt
);
1184 gpt
->oe
= value
& 0xF8000000;
1185 ppc4xx_gpt_set_outputs(gpt
);
1189 gpt
->ol
= value
& 0xF8000000;
1190 ppc4xx_gpt_set_outputs(gpt
);
1193 /* Interrupt mask */
1194 gpt
->im
= value
& 0x0000F800;
1197 /* Interrupt status set */
1198 gpt
->is
|= value
& 0x0000F800;
1199 ppc4xx_gpt_set_irqs(gpt
);
1202 /* Interrupt status clear */
1203 gpt
->is
&= ~(value
& 0x0000F800);
1204 ppc4xx_gpt_set_irqs(gpt
);
1207 /* Interrupt enable */
1208 gpt
->ie
= value
& 0x0000F800;
1209 ppc4xx_gpt_set_irqs(gpt
);
1213 idx
= (addr
- 0x80) >> 2;
1214 gpt
->comp
[idx
] = value
& 0xF8000000;
1215 ppc4xx_gpt_compute_timer(gpt
);
1219 idx
= (addr
- 0xC0) >> 2;
1220 gpt
->mask
[idx
] = value
& 0xF8000000;
1221 ppc4xx_gpt_compute_timer(gpt
);
1226 static const MemoryRegionOps gpt_ops
= {
1228 .read
= { ppc4xx_gpt_readb
, ppc4xx_gpt_readw
, ppc4xx_gpt_readl
, },
1229 .write
= { ppc4xx_gpt_writeb
, ppc4xx_gpt_writew
, ppc4xx_gpt_writel
, },
1231 .endianness
= DEVICE_NATIVE_ENDIAN
,
1234 static void ppc4xx_gpt_cb (void *opaque
)
1239 ppc4xx_gpt_set_irqs(gpt
);
1240 ppc4xx_gpt_set_outputs(gpt
);
1241 ppc4xx_gpt_compute_timer(gpt
);
1244 static void ppc4xx_gpt_reset (void *opaque
)
1250 timer_del(gpt
->timer
);
1251 gpt
->oe
= 0x00000000;
1252 gpt
->ol
= 0x00000000;
1253 gpt
->im
= 0x00000000;
1254 gpt
->is
= 0x00000000;
1255 gpt
->ie
= 0x00000000;
1256 for (i
= 0; i
< 5; i
++) {
1257 gpt
->comp
[i
] = 0x00000000;
1258 gpt
->mask
[i
] = 0x00000000;
1262 static void ppc4xx_gpt_init(hwaddr base
, qemu_irq irqs
[5])
1267 gpt
= g_malloc0(sizeof(ppc4xx_gpt_t
));
1268 for (i
= 0; i
< 5; i
++) {
1269 gpt
->irqs
[i
] = irqs
[i
];
1271 gpt
->timer
= timer_new_ns(QEMU_CLOCK_VIRTUAL
, &ppc4xx_gpt_cb
, gpt
);
1273 printf("%s: offset " TARGET_FMT_plx
"\n", __func__
, base
);
1275 memory_region_init_io(&gpt
->iomem
, NULL
, &gpt_ops
, gpt
, "gpt", 0x0d4);
1276 memory_region_add_subregion(get_system_memory(), base
, &gpt
->iomem
);
1277 qemu_register_reset(ppc4xx_gpt_reset
, gpt
);
1280 /*****************************************************************************/
1282 void ppc40x_core_reset(PowerPCCPU
*cpu
)
1284 CPUPPCState
*env
= &cpu
->env
;
1287 printf("Reset PowerPC core\n");
1288 cpu_interrupt(CPU(cpu
), CPU_INTERRUPT_RESET
);
1289 dbsr
= env
->spr
[SPR_40x_DBSR
];
1290 dbsr
&= ~0x00000300;
1292 env
->spr
[SPR_40x_DBSR
] = dbsr
;
1295 void ppc40x_chip_reset(PowerPCCPU
*cpu
)
1297 CPUPPCState
*env
= &cpu
->env
;
1300 printf("Reset PowerPC chip\n");
1301 cpu_interrupt(CPU(cpu
), CPU_INTERRUPT_RESET
);
1302 /* XXX: TODO reset all internal peripherals */
1303 dbsr
= env
->spr
[SPR_40x_DBSR
];
1304 dbsr
&= ~0x00000300;
1306 env
->spr
[SPR_40x_DBSR
] = dbsr
;
1309 void ppc40x_system_reset(PowerPCCPU
*cpu
)
1311 printf("Reset PowerPC system\n");
1312 qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET
);
1315 void store_40x_dbcr0 (CPUPPCState
*env
, uint32_t val
)
1317 PowerPCCPU
*cpu
= ppc_env_get_cpu(env
);
1319 switch ((val
>> 28) & 0x3) {
1325 ppc40x_core_reset(cpu
);
1329 ppc40x_chip_reset(cpu
);
1333 ppc40x_system_reset(cpu
);
1338 /*****************************************************************************/
1341 PPC405CR_CPC0_PLLMR
= 0x0B0,
1342 PPC405CR_CPC0_CR0
= 0x0B1,
1343 PPC405CR_CPC0_CR1
= 0x0B2,
1344 PPC405CR_CPC0_PSR
= 0x0B4,
1345 PPC405CR_CPC0_JTAGID
= 0x0B5,
1346 PPC405CR_CPC0_ER
= 0x0B9,
1347 PPC405CR_CPC0_FR
= 0x0BA,
1348 PPC405CR_CPC0_SR
= 0x0BB,
1352 PPC405CR_CPU_CLK
= 0,
1353 PPC405CR_TMR_CLK
= 1,
1354 PPC405CR_PLB_CLK
= 2,
1355 PPC405CR_SDRAM_CLK
= 3,
1356 PPC405CR_OPB_CLK
= 4,
1357 PPC405CR_EXT_CLK
= 5,
1358 PPC405CR_UART_CLK
= 6,
1359 PPC405CR_CLK_NB
= 7,
1362 typedef struct ppc405cr_cpc_t ppc405cr_cpc_t
;
1363 struct ppc405cr_cpc_t
{
1364 clk_setup_t clk_setup
[PPC405CR_CLK_NB
];
1375 static void ppc405cr_clk_setup (ppc405cr_cpc_t
*cpc
)
1377 uint64_t VCO_out
, PLL_out
;
1378 uint32_t CPU_clk
, TMR_clk
, SDRAM_clk
, PLB_clk
, OPB_clk
, EXT_clk
, UART_clk
;
1381 D0
= ((cpc
->pllmr
>> 26) & 0x3) + 1; /* CBDV */
1382 if (cpc
->pllmr
& 0x80000000) {
1383 D1
= (((cpc
->pllmr
>> 20) - 1) & 0xF) + 1; /* FBDV */
1384 D2
= 8 - ((cpc
->pllmr
>> 16) & 0x7); /* FWDVA */
1386 VCO_out
= (uint64_t)cpc
->sysclk
* M
;
1387 if (VCO_out
< 400000000 || VCO_out
> 800000000) {
1388 /* PLL cannot lock */
1389 cpc
->pllmr
&= ~0x80000000;
1392 PLL_out
= VCO_out
/ D2
;
1397 PLL_out
= (uint64_t)cpc
->sysclk
* M
;
1400 if (cpc
->cr1
& 0x00800000)
1401 TMR_clk
= cpc
->sysclk
; /* Should have a separate clock */
1404 PLB_clk
= CPU_clk
/ D0
;
1405 SDRAM_clk
= PLB_clk
;
1406 D0
= ((cpc
->pllmr
>> 10) & 0x3) + 1;
1407 OPB_clk
= PLB_clk
/ D0
;
1408 D0
= ((cpc
->pllmr
>> 24) & 0x3) + 2;
1409 EXT_clk
= PLB_clk
/ D0
;
1410 D0
= ((cpc
->cr0
>> 1) & 0x1F) + 1;
1411 UART_clk
= CPU_clk
/ D0
;
1412 /* Setup CPU clocks */
1413 clk_setup(&cpc
->clk_setup
[PPC405CR_CPU_CLK
], CPU_clk
);
1414 /* Setup time-base clock */
1415 clk_setup(&cpc
->clk_setup
[PPC405CR_TMR_CLK
], TMR_clk
);
1416 /* Setup PLB clock */
1417 clk_setup(&cpc
->clk_setup
[PPC405CR_PLB_CLK
], PLB_clk
);
1418 /* Setup SDRAM clock */
1419 clk_setup(&cpc
->clk_setup
[PPC405CR_SDRAM_CLK
], SDRAM_clk
);
1420 /* Setup OPB clock */
1421 clk_setup(&cpc
->clk_setup
[PPC405CR_OPB_CLK
], OPB_clk
);
1422 /* Setup external clock */
1423 clk_setup(&cpc
->clk_setup
[PPC405CR_EXT_CLK
], EXT_clk
);
1424 /* Setup UART clock */
1425 clk_setup(&cpc
->clk_setup
[PPC405CR_UART_CLK
], UART_clk
);
1428 static uint32_t dcr_read_crcpc (void *opaque
, int dcrn
)
1430 ppc405cr_cpc_t
*cpc
;
1435 case PPC405CR_CPC0_PLLMR
:
1438 case PPC405CR_CPC0_CR0
:
1441 case PPC405CR_CPC0_CR1
:
1444 case PPC405CR_CPC0_PSR
:
1447 case PPC405CR_CPC0_JTAGID
:
1450 case PPC405CR_CPC0_ER
:
1453 case PPC405CR_CPC0_FR
:
1456 case PPC405CR_CPC0_SR
:
1457 ret
= ~(cpc
->er
| cpc
->fr
) & 0xFFFF0000;
1460 /* Avoid gcc warning */
1468 static void dcr_write_crcpc (void *opaque
, int dcrn
, uint32_t val
)
1470 ppc405cr_cpc_t
*cpc
;
1474 case PPC405CR_CPC0_PLLMR
:
1475 cpc
->pllmr
= val
& 0xFFF77C3F;
1477 case PPC405CR_CPC0_CR0
:
1478 cpc
->cr0
= val
& 0x0FFFFFFE;
1480 case PPC405CR_CPC0_CR1
:
1481 cpc
->cr1
= val
& 0x00800000;
1483 case PPC405CR_CPC0_PSR
:
1486 case PPC405CR_CPC0_JTAGID
:
1489 case PPC405CR_CPC0_ER
:
1490 cpc
->er
= val
& 0xBFFC0000;
1492 case PPC405CR_CPC0_FR
:
1493 cpc
->fr
= val
& 0xBFFC0000;
1495 case PPC405CR_CPC0_SR
:
1501 static void ppc405cr_cpc_reset (void *opaque
)
1503 ppc405cr_cpc_t
*cpc
;
1507 /* Compute PLLMR value from PSR settings */
1508 cpc
->pllmr
= 0x80000000;
1510 switch ((cpc
->psr
>> 30) & 3) {
1513 cpc
->pllmr
&= ~0x80000000;
1517 cpc
->pllmr
|= 5 << 16;
1521 cpc
->pllmr
|= 4 << 16;
1525 cpc
->pllmr
|= 2 << 16;
1529 D
= (cpc
->psr
>> 28) & 3;
1530 cpc
->pllmr
|= (D
+ 1) << 20;
1532 D
= (cpc
->psr
>> 25) & 7;
1547 D
= (cpc
->psr
>> 23) & 3;
1548 cpc
->pllmr
|= D
<< 26;
1550 D
= (cpc
->psr
>> 21) & 3;
1551 cpc
->pllmr
|= D
<< 10;
1553 D
= (cpc
->psr
>> 17) & 3;
1554 cpc
->pllmr
|= D
<< 24;
1555 cpc
->cr0
= 0x0000003C;
1556 cpc
->cr1
= 0x2B0D8800;
1557 cpc
->er
= 0x00000000;
1558 cpc
->fr
= 0x00000000;
1559 ppc405cr_clk_setup(cpc
);
1562 static void ppc405cr_clk_init (ppc405cr_cpc_t
*cpc
)
1566 /* XXX: this should be read from IO pins */
1567 cpc
->psr
= 0x00000000; /* 8 bits ROM */
1569 D
= 0x2; /* Divide by 4 */
1570 cpc
->psr
|= D
<< 30;
1572 D
= 0x1; /* Divide by 2 */
1573 cpc
->psr
|= D
<< 28;
1575 D
= 0x1; /* Divide by 2 */
1576 cpc
->psr
|= D
<< 23;
1578 D
= 0x5; /* M = 16 */
1579 cpc
->psr
|= D
<< 25;
1581 D
= 0x1; /* Divide by 2 */
1582 cpc
->psr
|= D
<< 21;
1584 D
= 0x2; /* Divide by 4 */
1585 cpc
->psr
|= D
<< 17;
1588 static void ppc405cr_cpc_init (CPUPPCState
*env
, clk_setup_t clk_setup
[7],
1591 ppc405cr_cpc_t
*cpc
;
1593 cpc
= g_malloc0(sizeof(ppc405cr_cpc_t
));
1594 memcpy(cpc
->clk_setup
, clk_setup
,
1595 PPC405CR_CLK_NB
* sizeof(clk_setup_t
));
1596 cpc
->sysclk
= sysclk
;
1597 cpc
->jtagid
= 0x42051049;
1598 ppc_dcr_register(env
, PPC405CR_CPC0_PSR
, cpc
,
1599 &dcr_read_crcpc
, &dcr_write_crcpc
);
1600 ppc_dcr_register(env
, PPC405CR_CPC0_CR0
, cpc
,
1601 &dcr_read_crcpc
, &dcr_write_crcpc
);
1602 ppc_dcr_register(env
, PPC405CR_CPC0_CR1
, cpc
,
1603 &dcr_read_crcpc
, &dcr_write_crcpc
);
1604 ppc_dcr_register(env
, PPC405CR_CPC0_JTAGID
, cpc
,
1605 &dcr_read_crcpc
, &dcr_write_crcpc
);
1606 ppc_dcr_register(env
, PPC405CR_CPC0_PLLMR
, cpc
,
1607 &dcr_read_crcpc
, &dcr_write_crcpc
);
1608 ppc_dcr_register(env
, PPC405CR_CPC0_ER
, cpc
,
1609 &dcr_read_crcpc
, &dcr_write_crcpc
);
1610 ppc_dcr_register(env
, PPC405CR_CPC0_FR
, cpc
,
1611 &dcr_read_crcpc
, &dcr_write_crcpc
);
1612 ppc_dcr_register(env
, PPC405CR_CPC0_SR
, cpc
,
1613 &dcr_read_crcpc
, &dcr_write_crcpc
);
1614 ppc405cr_clk_init(cpc
);
1615 qemu_register_reset(ppc405cr_cpc_reset
, cpc
);
1618 CPUPPCState
*ppc405cr_init(MemoryRegion
*address_space_mem
,
1619 MemoryRegion ram_memories
[4],
1620 hwaddr ram_bases
[4],
1621 hwaddr ram_sizes
[4],
1622 uint32_t sysclk
, qemu_irq
**picp
,
1625 clk_setup_t clk_setup
[PPC405CR_CLK_NB
];
1626 qemu_irq dma_irqs
[4];
1629 qemu_irq
*pic
, *irqs
;
1631 memset(clk_setup
, 0, sizeof(clk_setup
));
1632 cpu
= ppc4xx_init(POWERPC_CPU_TYPE_NAME("405crc"),
1633 &clk_setup
[PPC405CR_CPU_CLK
],
1634 &clk_setup
[PPC405CR_TMR_CLK
], sysclk
);
1636 /* Memory mapped devices registers */
1638 ppc4xx_plb_init(env
);
1639 /* PLB to OPB bridge */
1640 ppc4xx_pob_init(env
);
1642 ppc4xx_opba_init(0xef600600);
1643 /* Universal interrupt controller */
1644 irqs
= g_malloc0(sizeof(qemu_irq
) * PPCUIC_OUTPUT_NB
);
1645 irqs
[PPCUIC_OUTPUT_INT
] =
1646 ((qemu_irq
*)env
->irq_inputs
)[PPC40x_INPUT_INT
];
1647 irqs
[PPCUIC_OUTPUT_CINT
] =
1648 ((qemu_irq
*)env
->irq_inputs
)[PPC40x_INPUT_CINT
];
1649 pic
= ppcuic_init(env
, irqs
, 0x0C0, 0, 1);
1651 /* SDRAM controller */
1652 ppc4xx_sdram_init(env
, pic
[14], 1, ram_memories
,
1653 ram_bases
, ram_sizes
, do_init
);
1654 /* External bus controller */
1655 ppc405_ebc_init(env
);
1656 /* DMA controller */
1657 dma_irqs
[0] = pic
[26];
1658 dma_irqs
[1] = pic
[25];
1659 dma_irqs
[2] = pic
[24];
1660 dma_irqs
[3] = pic
[23];
1661 ppc405_dma_init(env
, dma_irqs
);
1663 if (serial_hd(0) != NULL
) {
1664 serial_mm_init(address_space_mem
, 0xef600300, 0, pic
[0],
1665 PPC_SERIAL_MM_BAUDBASE
, serial_hd(0),
1668 if (serial_hd(1) != NULL
) {
1669 serial_mm_init(address_space_mem
, 0xef600400, 0, pic
[1],
1670 PPC_SERIAL_MM_BAUDBASE
, serial_hd(1),
1673 /* IIC controller */
1674 sysbus_create_simple(TYPE_PPC4xx_I2C
, 0xef600500, pic
[2]);
1676 ppc405_gpio_init(0xef600700);
1678 ppc405cr_cpc_init(env
, clk_setup
, sysclk
);
1683 /*****************************************************************************/
1687 PPC405EP_CPC0_PLLMR0
= 0x0F0,
1688 PPC405EP_CPC0_BOOT
= 0x0F1,
1689 PPC405EP_CPC0_EPCTL
= 0x0F3,
1690 PPC405EP_CPC0_PLLMR1
= 0x0F4,
1691 PPC405EP_CPC0_UCR
= 0x0F5,
1692 PPC405EP_CPC0_SRR
= 0x0F6,
1693 PPC405EP_CPC0_JTAGID
= 0x0F7,
1694 PPC405EP_CPC0_PCI
= 0x0F9,
1696 PPC405EP_CPC0_ER
= xxx
,
1697 PPC405EP_CPC0_FR
= xxx
,
1698 PPC405EP_CPC0_SR
= xxx
,
1703 PPC405EP_CPU_CLK
= 0,
1704 PPC405EP_PLB_CLK
= 1,
1705 PPC405EP_OPB_CLK
= 2,
1706 PPC405EP_EBC_CLK
= 3,
1707 PPC405EP_MAL_CLK
= 4,
1708 PPC405EP_PCI_CLK
= 5,
1709 PPC405EP_UART0_CLK
= 6,
1710 PPC405EP_UART1_CLK
= 7,
1711 PPC405EP_CLK_NB
= 8,
1714 typedef struct ppc405ep_cpc_t ppc405ep_cpc_t
;
1715 struct ppc405ep_cpc_t
{
1717 clk_setup_t clk_setup
[PPC405EP_CLK_NB
];
1725 /* Clock and power management */
1731 static void ppc405ep_compute_clocks (ppc405ep_cpc_t
*cpc
)
1733 uint32_t CPU_clk
, PLB_clk
, OPB_clk
, EBC_clk
, MAL_clk
, PCI_clk
;
1734 uint32_t UART0_clk
, UART1_clk
;
1735 uint64_t VCO_out
, PLL_out
;
1739 if ((cpc
->pllmr
[1] & 0x80000000) && !(cpc
->pllmr
[1] & 0x40000000)) {
1740 M
= (((cpc
->pllmr
[1] >> 20) - 1) & 0xF) + 1; /* FBMUL */
1741 #ifdef DEBUG_CLOCKS_LL
1742 printf("FBMUL %01" PRIx32
" %d\n", (cpc
->pllmr
[1] >> 20) & 0xF, M
);
1744 D
= 8 - ((cpc
->pllmr
[1] >> 16) & 0x7); /* FWDA */
1745 #ifdef DEBUG_CLOCKS_LL
1746 printf("FWDA %01" PRIx32
" %d\n", (cpc
->pllmr
[1] >> 16) & 0x7, D
);
1748 VCO_out
= (uint64_t)cpc
->sysclk
* M
* D
;
1749 if (VCO_out
< 500000000UL || VCO_out
> 1000000000UL) {
1750 /* Error - unlock the PLL */
1751 printf("VCO out of range %" PRIu64
"\n", VCO_out
);
1753 cpc
->pllmr
[1] &= ~0x80000000;
1757 PLL_out
= VCO_out
/ D
;
1758 /* Pretend the PLL is locked */
1759 cpc
->boot
|= 0x00000001;
1764 PLL_out
= cpc
->sysclk
;
1765 if (cpc
->pllmr
[1] & 0x40000000) {
1766 /* Pretend the PLL is not locked */
1767 cpc
->boot
&= ~0x00000001;
1770 /* Now, compute all other clocks */
1771 D
= ((cpc
->pllmr
[0] >> 20) & 0x3) + 1; /* CCDV */
1772 #ifdef DEBUG_CLOCKS_LL
1773 printf("CCDV %01" PRIx32
" %d\n", (cpc
->pllmr
[0] >> 20) & 0x3, D
);
1775 CPU_clk
= PLL_out
/ D
;
1776 D
= ((cpc
->pllmr
[0] >> 16) & 0x3) + 1; /* CBDV */
1777 #ifdef DEBUG_CLOCKS_LL
1778 printf("CBDV %01" PRIx32
" %d\n", (cpc
->pllmr
[0] >> 16) & 0x3, D
);
1780 PLB_clk
= CPU_clk
/ D
;
1781 D
= ((cpc
->pllmr
[0] >> 12) & 0x3) + 1; /* OPDV */
1782 #ifdef DEBUG_CLOCKS_LL
1783 printf("OPDV %01" PRIx32
" %d\n", (cpc
->pllmr
[0] >> 12) & 0x3, D
);
1785 OPB_clk
= PLB_clk
/ D
;
1786 D
= ((cpc
->pllmr
[0] >> 8) & 0x3) + 2; /* EPDV */
1787 #ifdef DEBUG_CLOCKS_LL
1788 printf("EPDV %01" PRIx32
" %d\n", (cpc
->pllmr
[0] >> 8) & 0x3, D
);
1790 EBC_clk
= PLB_clk
/ D
;
1791 D
= ((cpc
->pllmr
[0] >> 4) & 0x3) + 1; /* MPDV */
1792 #ifdef DEBUG_CLOCKS_LL
1793 printf("MPDV %01" PRIx32
" %d\n", (cpc
->pllmr
[0] >> 4) & 0x3, D
);
1795 MAL_clk
= PLB_clk
/ D
;
1796 D
= (cpc
->pllmr
[0] & 0x3) + 1; /* PPDV */
1797 #ifdef DEBUG_CLOCKS_LL
1798 printf("PPDV %01" PRIx32
" %d\n", cpc
->pllmr
[0] & 0x3, D
);
1800 PCI_clk
= PLB_clk
/ D
;
1801 D
= ((cpc
->ucr
- 1) & 0x7F) + 1; /* U0DIV */
1802 #ifdef DEBUG_CLOCKS_LL
1803 printf("U0DIV %01" PRIx32
" %d\n", cpc
->ucr
& 0x7F, D
);
1805 UART0_clk
= PLL_out
/ D
;
1806 D
= (((cpc
->ucr
>> 8) - 1) & 0x7F) + 1; /* U1DIV */
1807 #ifdef DEBUG_CLOCKS_LL
1808 printf("U1DIV %01" PRIx32
" %d\n", (cpc
->ucr
>> 8) & 0x7F, D
);
1810 UART1_clk
= PLL_out
/ D
;
1812 printf("Setup PPC405EP clocks - sysclk %" PRIu32
" VCO %" PRIu64
1813 " PLL out %" PRIu64
" Hz\n", cpc
->sysclk
, VCO_out
, PLL_out
);
1814 printf("CPU %" PRIu32
" PLB %" PRIu32
" OPB %" PRIu32
" EBC %" PRIu32
1815 " MAL %" PRIu32
" PCI %" PRIu32
" UART0 %" PRIu32
1816 " UART1 %" PRIu32
"\n",
1817 CPU_clk
, PLB_clk
, OPB_clk
, EBC_clk
, MAL_clk
, PCI_clk
,
1818 UART0_clk
, UART1_clk
);
1820 /* Setup CPU clocks */
1821 clk_setup(&cpc
->clk_setup
[PPC405EP_CPU_CLK
], CPU_clk
);
1822 /* Setup PLB clock */
1823 clk_setup(&cpc
->clk_setup
[PPC405EP_PLB_CLK
], PLB_clk
);
1824 /* Setup OPB clock */
1825 clk_setup(&cpc
->clk_setup
[PPC405EP_OPB_CLK
], OPB_clk
);
1826 /* Setup external clock */
1827 clk_setup(&cpc
->clk_setup
[PPC405EP_EBC_CLK
], EBC_clk
);
1828 /* Setup MAL clock */
1829 clk_setup(&cpc
->clk_setup
[PPC405EP_MAL_CLK
], MAL_clk
);
1830 /* Setup PCI clock */
1831 clk_setup(&cpc
->clk_setup
[PPC405EP_PCI_CLK
], PCI_clk
);
1832 /* Setup UART0 clock */
1833 clk_setup(&cpc
->clk_setup
[PPC405EP_UART0_CLK
], UART0_clk
);
1834 /* Setup UART1 clock */
1835 clk_setup(&cpc
->clk_setup
[PPC405EP_UART1_CLK
], UART1_clk
);
1838 static uint32_t dcr_read_epcpc (void *opaque
, int dcrn
)
1840 ppc405ep_cpc_t
*cpc
;
1845 case PPC405EP_CPC0_BOOT
:
1848 case PPC405EP_CPC0_EPCTL
:
1851 case PPC405EP_CPC0_PLLMR0
:
1852 ret
= cpc
->pllmr
[0];
1854 case PPC405EP_CPC0_PLLMR1
:
1855 ret
= cpc
->pllmr
[1];
1857 case PPC405EP_CPC0_UCR
:
1860 case PPC405EP_CPC0_SRR
:
1863 case PPC405EP_CPC0_JTAGID
:
1866 case PPC405EP_CPC0_PCI
:
1870 /* Avoid gcc warning */
1878 static void dcr_write_epcpc (void *opaque
, int dcrn
, uint32_t val
)
1880 ppc405ep_cpc_t
*cpc
;
1884 case PPC405EP_CPC0_BOOT
:
1885 /* Read-only register */
1887 case PPC405EP_CPC0_EPCTL
:
1888 /* Don't care for now */
1889 cpc
->epctl
= val
& 0xC00000F3;
1891 case PPC405EP_CPC0_PLLMR0
:
1892 cpc
->pllmr
[0] = val
& 0x00633333;
1893 ppc405ep_compute_clocks(cpc
);
1895 case PPC405EP_CPC0_PLLMR1
:
1896 cpc
->pllmr
[1] = val
& 0xC0F73FFF;
1897 ppc405ep_compute_clocks(cpc
);
1899 case PPC405EP_CPC0_UCR
:
1900 /* UART control - don't care for now */
1901 cpc
->ucr
= val
& 0x003F7F7F;
1903 case PPC405EP_CPC0_SRR
:
1906 case PPC405EP_CPC0_JTAGID
:
1909 case PPC405EP_CPC0_PCI
:
1915 static void ppc405ep_cpc_reset (void *opaque
)
1917 ppc405ep_cpc_t
*cpc
= opaque
;
1919 cpc
->boot
= 0x00000010; /* Boot from PCI - IIC EEPROM disabled */
1920 cpc
->epctl
= 0x00000000;
1921 cpc
->pllmr
[0] = 0x00011010;
1922 cpc
->pllmr
[1] = 0x40000000;
1923 cpc
->ucr
= 0x00000000;
1924 cpc
->srr
= 0x00040000;
1925 cpc
->pci
= 0x00000000;
1926 cpc
->er
= 0x00000000;
1927 cpc
->fr
= 0x00000000;
1928 cpc
->sr
= 0x00000000;
1929 ppc405ep_compute_clocks(cpc
);
1932 /* XXX: sysclk should be between 25 and 100 MHz */
1933 static void ppc405ep_cpc_init (CPUPPCState
*env
, clk_setup_t clk_setup
[8],
1936 ppc405ep_cpc_t
*cpc
;
1938 cpc
= g_malloc0(sizeof(ppc405ep_cpc_t
));
1939 memcpy(cpc
->clk_setup
, clk_setup
,
1940 PPC405EP_CLK_NB
* sizeof(clk_setup_t
));
1941 cpc
->jtagid
= 0x20267049;
1942 cpc
->sysclk
= sysclk
;
1943 qemu_register_reset(&ppc405ep_cpc_reset
, cpc
);
1944 ppc_dcr_register(env
, PPC405EP_CPC0_BOOT
, cpc
,
1945 &dcr_read_epcpc
, &dcr_write_epcpc
);
1946 ppc_dcr_register(env
, PPC405EP_CPC0_EPCTL
, cpc
,
1947 &dcr_read_epcpc
, &dcr_write_epcpc
);
1948 ppc_dcr_register(env
, PPC405EP_CPC0_PLLMR0
, cpc
,
1949 &dcr_read_epcpc
, &dcr_write_epcpc
);
1950 ppc_dcr_register(env
, PPC405EP_CPC0_PLLMR1
, cpc
,
1951 &dcr_read_epcpc
, &dcr_write_epcpc
);
1952 ppc_dcr_register(env
, PPC405EP_CPC0_UCR
, cpc
,
1953 &dcr_read_epcpc
, &dcr_write_epcpc
);
1954 ppc_dcr_register(env
, PPC405EP_CPC0_SRR
, cpc
,
1955 &dcr_read_epcpc
, &dcr_write_epcpc
);
1956 ppc_dcr_register(env
, PPC405EP_CPC0_JTAGID
, cpc
,
1957 &dcr_read_epcpc
, &dcr_write_epcpc
);
1958 ppc_dcr_register(env
, PPC405EP_CPC0_PCI
, cpc
,
1959 &dcr_read_epcpc
, &dcr_write_epcpc
);
1961 ppc_dcr_register(env
, PPC405EP_CPC0_ER
, cpc
,
1962 &dcr_read_epcpc
, &dcr_write_epcpc
);
1963 ppc_dcr_register(env
, PPC405EP_CPC0_FR
, cpc
,
1964 &dcr_read_epcpc
, &dcr_write_epcpc
);
1965 ppc_dcr_register(env
, PPC405EP_CPC0_SR
, cpc
,
1966 &dcr_read_epcpc
, &dcr_write_epcpc
);
1970 CPUPPCState
*ppc405ep_init(MemoryRegion
*address_space_mem
,
1971 MemoryRegion ram_memories
[2],
1972 hwaddr ram_bases
[2],
1973 hwaddr ram_sizes
[2],
1974 uint32_t sysclk
, qemu_irq
**picp
,
1977 clk_setup_t clk_setup
[PPC405EP_CLK_NB
], tlb_clk_setup
;
1978 qemu_irq dma_irqs
[4], gpt_irqs
[5], mal_irqs
[4];
1981 qemu_irq
*pic
, *irqs
;
1983 memset(clk_setup
, 0, sizeof(clk_setup
));
1985 cpu
= ppc4xx_init(POWERPC_CPU_TYPE_NAME("405ep"),
1986 &clk_setup
[PPC405EP_CPU_CLK
],
1987 &tlb_clk_setup
, sysclk
);
1989 clk_setup
[PPC405EP_CPU_CLK
].cb
= tlb_clk_setup
.cb
;
1990 clk_setup
[PPC405EP_CPU_CLK
].opaque
= tlb_clk_setup
.opaque
;
1991 /* Internal devices init */
1992 /* Memory mapped devices registers */
1994 ppc4xx_plb_init(env
);
1995 /* PLB to OPB bridge */
1996 ppc4xx_pob_init(env
);
1998 ppc4xx_opba_init(0xef600600);
1999 /* Initialize timers */
2000 ppc_booke_timers_init(cpu
, sysclk
, 0);
2001 /* Universal interrupt controller */
2002 irqs
= g_malloc0(sizeof(qemu_irq
) * PPCUIC_OUTPUT_NB
);
2003 irqs
[PPCUIC_OUTPUT_INT
] =
2004 ((qemu_irq
*)env
->irq_inputs
)[PPC40x_INPUT_INT
];
2005 irqs
[PPCUIC_OUTPUT_CINT
] =
2006 ((qemu_irq
*)env
->irq_inputs
)[PPC40x_INPUT_CINT
];
2007 pic
= ppcuic_init(env
, irqs
, 0x0C0, 0, 1);
2009 /* SDRAM controller */
2010 /* XXX 405EP has no ECC interrupt */
2011 ppc4xx_sdram_init(env
, pic
[17], 2, ram_memories
,
2012 ram_bases
, ram_sizes
, do_init
);
2013 /* External bus controller */
2014 ppc405_ebc_init(env
);
2015 /* DMA controller */
2016 dma_irqs
[0] = pic
[5];
2017 dma_irqs
[1] = pic
[6];
2018 dma_irqs
[2] = pic
[7];
2019 dma_irqs
[3] = pic
[8];
2020 ppc405_dma_init(env
, dma_irqs
);
2021 /* IIC controller */
2022 sysbus_create_simple(TYPE_PPC4xx_I2C
, 0xef600500, pic
[2]);
2024 ppc405_gpio_init(0xef600700);
2026 if (serial_hd(0) != NULL
) {
2027 serial_mm_init(address_space_mem
, 0xef600300, 0, pic
[0],
2028 PPC_SERIAL_MM_BAUDBASE
, serial_hd(0),
2031 if (serial_hd(1) != NULL
) {
2032 serial_mm_init(address_space_mem
, 0xef600400, 0, pic
[1],
2033 PPC_SERIAL_MM_BAUDBASE
, serial_hd(1),
2037 ppc405_ocm_init(env
);
2039 gpt_irqs
[0] = pic
[19];
2040 gpt_irqs
[1] = pic
[20];
2041 gpt_irqs
[2] = pic
[21];
2042 gpt_irqs
[3] = pic
[22];
2043 gpt_irqs
[4] = pic
[23];
2044 ppc4xx_gpt_init(0xef600000, gpt_irqs
);
2046 /* Uses pic[3], pic[16], pic[18] */
2048 mal_irqs
[0] = pic
[11];
2049 mal_irqs
[1] = pic
[12];
2050 mal_irqs
[2] = pic
[13];
2051 mal_irqs
[3] = pic
[14];
2052 ppc4xx_mal_init(env
, 4, 2, mal_irqs
);
2054 /* Uses pic[9], pic[15], pic[17] */
2056 ppc405ep_cpc_init(env
, clk_setup
, sysclk
);