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
25 #include "qemu/osdep.h"
26 #include "qemu/units.h"
27 #include "qapi/error.h"
29 #include "hw/ppc/ppc.h"
30 #include "hw/i2c/ppc4xx_i2c.h"
33 #include "hw/char/serial.h"
34 #include "qemu/timer.h"
35 #include "sysemu/reset.h"
36 #include "sysemu/sysemu.h"
38 #include "exec/address-spaces.h"
43 //#define DEBUG_SERIAL
46 //#define DEBUG_CLOCKS
47 //#define DEBUG_CLOCKS_LL
49 ram_addr_t
ppc405_set_bootinfo (CPUPPCState
*env
, ppc4xx_bd_info_t
*bd
,
52 CPUState
*cs
= env_cpu(env
);
56 /* We put the bd structure at the top of memory */
57 if (bd
->bi_memsize
>= 0x01000000UL
)
58 bdloc
= 0x01000000UL
- sizeof(struct ppc4xx_bd_info_t
);
60 bdloc
= bd
->bi_memsize
- sizeof(struct ppc4xx_bd_info_t
);
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
);
70 for (i
= 0; i
< 6; i
++) {
71 stb_phys(cs
->as
, bdloc
+ 0x24 + i
, bd
->bi_enetaddr
[i
]);
73 stw_be_phys(cs
->as
, bdloc
+ 0x2A, bd
->bi_ethspeed
);
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
);
77 for (i
= 0; i
< 4; i
++) {
78 stb_phys(cs
->as
, bdloc
+ 0x38 + i
, bd
->bi_s_version
[i
]);
80 for (i
= 0; i
< 32; i
++) {
81 stb_phys(cs
->as
, bdloc
+ 0x3C + i
, bd
->bi_r_version
[i
]);
83 stl_be_phys(cs
->as
, bdloc
+ 0x5C, bd
->bi_plb_busfreq
);
84 stl_be_phys(cs
->as
, bdloc
+ 0x60, bd
->bi_pci_busfreq
);
85 for (i
= 0; i
< 6; i
++) {
86 stb_phys(cs
->as
, bdloc
+ 0x64 + i
, bd
->bi_pci_enetaddr
[i
]);
89 if (flags
& 0x00000001) {
90 for (i
= 0; i
< 6; i
++)
91 stb_phys(cs
->as
, bdloc
+ n
++, bd
->bi_pci_enetaddr2
[i
]);
93 stl_be_phys(cs
->as
, bdloc
+ n
, bd
->bi_opbfreq
);
95 for (i
= 0; i
< 2; i
++) {
96 stl_be_phys(cs
->as
, bdloc
+ n
, bd
->bi_iic_fast
[i
]);
103 /*****************************************************************************/
104 /* Shared peripherals */
106 /*****************************************************************************/
107 /* Peripheral local bus arbitrer */
117 typedef struct ppc4xx_plb_t ppc4xx_plb_t
;
118 struct ppc4xx_plb_t
{
124 static uint32_t dcr_read_plb (void *opaque
, int dcrn
)
141 /* Avoid gcc warning */
149 static void dcr_write_plb (void *opaque
, int dcrn
, uint32_t val
)
156 /* We don't care about the actual parameters written as
157 * we don't manage any priorities on the bus
159 plb
->acr
= val
& 0xF8000000;
171 static void ppc4xx_plb_reset (void *opaque
)
176 plb
->acr
= 0x00000000;
177 plb
->bear
= 0x00000000;
178 plb
->besr
= 0x00000000;
181 void ppc4xx_plb_init(CPUPPCState
*env
)
185 plb
= g_malloc0(sizeof(ppc4xx_plb_t
));
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
);
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
);
191 ppc_dcr_register(env
, PLB4A1_ACR
, plb
, &dcr_read_plb
, &dcr_write_plb
);
192 qemu_register_reset(ppc4xx_plb_reset
, plb
);
195 /*****************************************************************************/
196 /* PLB to OPB bridge */
203 typedef struct ppc4xx_pob_t ppc4xx_pob_t
;
204 struct ppc4xx_pob_t
{
210 static uint32_t dcr_read_pob (void *opaque
, int dcrn
)
227 /* Avoid gcc warning */
235 static void dcr_write_pob (void *opaque
, int dcrn
, uint32_t val
)
255 static void ppc4xx_pob_reset (void *opaque
)
261 pob
->bear
= 0x00000000;
262 pob
->besr0
= 0x0000000;
263 pob
->besr1
= 0x0000000;
266 static void ppc4xx_pob_init(CPUPPCState
*env
)
270 pob
= g_malloc0(sizeof(ppc4xx_pob_t
));
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
);
274 qemu_register_reset(ppc4xx_pob_reset
, pob
);
277 /*****************************************************************************/
279 typedef struct ppc4xx_opba_t ppc4xx_opba_t
;
280 struct ppc4xx_opba_t
{
286 static uint64_t opba_readb(void *opaque
, hwaddr addr
, unsigned size
)
292 printf("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
310 static void opba_writeb(void *opaque
, hwaddr addr
, uint64_t value
,
316 printf("%s: addr " TARGET_FMT_plx
" val %08" PRIx32
"\n", __func__
, addr
,
322 opba
->cr
= value
& 0xF8;
325 opba
->pr
= value
& 0xFF;
331 static const MemoryRegionOps opba_ops
= {
333 .write
= opba_writeb
,
334 .impl
.min_access_size
= 1,
335 .impl
.max_access_size
= 1,
336 .valid
.min_access_size
= 1,
337 .valid
.max_access_size
= 4,
338 .endianness
= DEVICE_BIG_ENDIAN
,
341 static void ppc4xx_opba_reset (void *opaque
)
346 opba
->cr
= 0x00; /* No dynamic priorities - park disabled */
350 static void ppc4xx_opba_init(hwaddr base
)
354 opba
= g_malloc0(sizeof(ppc4xx_opba_t
));
356 printf("%s: offset " TARGET_FMT_plx
"\n", __func__
, base
);
358 memory_region_init_io(&opba
->io
, NULL
, &opba_ops
, opba
, "opba", 0x002);
359 memory_region_add_subregion(get_system_memory(), base
, &opba
->io
);
360 qemu_register_reset(ppc4xx_opba_reset
, opba
);
363 /*****************************************************************************/
364 /* Code decompression controller */
367 /*****************************************************************************/
368 /* Peripheral controller */
369 typedef struct ppc4xx_ebc_t ppc4xx_ebc_t
;
370 struct ppc4xx_ebc_t
{
381 EBC0_CFGADDR
= 0x012,
382 EBC0_CFGDATA
= 0x013,
385 static uint32_t dcr_read_ebc (void *opaque
, int dcrn
)
397 case 0x00: /* B0CR */
400 case 0x01: /* B1CR */
403 case 0x02: /* B2CR */
406 case 0x03: /* B3CR */
409 case 0x04: /* B4CR */
412 case 0x05: /* B5CR */
415 case 0x06: /* B6CR */
418 case 0x07: /* B7CR */
421 case 0x10: /* B0AP */
424 case 0x11: /* B1AP */
427 case 0x12: /* B2AP */
430 case 0x13: /* B3AP */
433 case 0x14: /* B4AP */
436 case 0x15: /* B5AP */
439 case 0x16: /* B6AP */
442 case 0x17: /* B7AP */
445 case 0x20: /* BEAR */
448 case 0x21: /* BESR0 */
451 case 0x22: /* BESR1 */
470 static void dcr_write_ebc (void *opaque
, int dcrn
, uint32_t val
)
481 case 0x00: /* B0CR */
483 case 0x01: /* B1CR */
485 case 0x02: /* B2CR */
487 case 0x03: /* B3CR */
489 case 0x04: /* B4CR */
491 case 0x05: /* B5CR */
493 case 0x06: /* B6CR */
495 case 0x07: /* B7CR */
497 case 0x10: /* B0AP */
499 case 0x11: /* B1AP */
501 case 0x12: /* B2AP */
503 case 0x13: /* B3AP */
505 case 0x14: /* B4AP */
507 case 0x15: /* B5AP */
509 case 0x16: /* B6AP */
511 case 0x17: /* B7AP */
513 case 0x20: /* BEAR */
515 case 0x21: /* BESR0 */
517 case 0x22: /* BESR1 */
530 static void ebc_reset (void *opaque
)
536 ebc
->addr
= 0x00000000;
537 ebc
->bap
[0] = 0x7F8FFE80;
538 ebc
->bcr
[0] = 0xFFE28000;
539 for (i
= 0; i
< 8; i
++) {
540 ebc
->bap
[i
] = 0x00000000;
541 ebc
->bcr
[i
] = 0x00000000;
543 ebc
->besr0
= 0x00000000;
544 ebc
->besr1
= 0x00000000;
545 ebc
->cfg
= 0x80400000;
548 void ppc405_ebc_init(CPUPPCState
*env
)
552 ebc
= g_malloc0(sizeof(ppc4xx_ebc_t
));
553 qemu_register_reset(&ebc_reset
, ebc
);
554 ppc_dcr_register(env
, EBC0_CFGADDR
,
555 ebc
, &dcr_read_ebc
, &dcr_write_ebc
);
556 ppc_dcr_register(env
, EBC0_CFGDATA
,
557 ebc
, &dcr_read_ebc
, &dcr_write_ebc
);
560 /*****************************************************************************/
589 typedef struct ppc405_dma_t ppc405_dma_t
;
590 struct ppc405_dma_t
{
603 static uint32_t dcr_read_dma (void *opaque
, int dcrn
)
608 static void dcr_write_dma (void *opaque
, int dcrn
, uint32_t val
)
612 static void ppc405_dma_reset (void *opaque
)
618 for (i
= 0; i
< 4; i
++) {
619 dma
->cr
[i
] = 0x00000000;
620 dma
->ct
[i
] = 0x00000000;
621 dma
->da
[i
] = 0x00000000;
622 dma
->sa
[i
] = 0x00000000;
623 dma
->sg
[i
] = 0x00000000;
625 dma
->sr
= 0x00000000;
626 dma
->sgc
= 0x00000000;
627 dma
->slp
= 0x7C000000;
628 dma
->pol
= 0x00000000;
631 static void ppc405_dma_init(CPUPPCState
*env
, qemu_irq irqs
[4])
635 dma
= g_malloc0(sizeof(ppc405_dma_t
));
636 memcpy(dma
->irqs
, irqs
, 4 * sizeof(qemu_irq
));
637 qemu_register_reset(&ppc405_dma_reset
, dma
);
638 ppc_dcr_register(env
, DMA0_CR0
,
639 dma
, &dcr_read_dma
, &dcr_write_dma
);
640 ppc_dcr_register(env
, DMA0_CT0
,
641 dma
, &dcr_read_dma
, &dcr_write_dma
);
642 ppc_dcr_register(env
, DMA0_DA0
,
643 dma
, &dcr_read_dma
, &dcr_write_dma
);
644 ppc_dcr_register(env
, DMA0_SA0
,
645 dma
, &dcr_read_dma
, &dcr_write_dma
);
646 ppc_dcr_register(env
, DMA0_SG0
,
647 dma
, &dcr_read_dma
, &dcr_write_dma
);
648 ppc_dcr_register(env
, DMA0_CR1
,
649 dma
, &dcr_read_dma
, &dcr_write_dma
);
650 ppc_dcr_register(env
, DMA0_CT1
,
651 dma
, &dcr_read_dma
, &dcr_write_dma
);
652 ppc_dcr_register(env
, DMA0_DA1
,
653 dma
, &dcr_read_dma
, &dcr_write_dma
);
654 ppc_dcr_register(env
, DMA0_SA1
,
655 dma
, &dcr_read_dma
, &dcr_write_dma
);
656 ppc_dcr_register(env
, DMA0_SG1
,
657 dma
, &dcr_read_dma
, &dcr_write_dma
);
658 ppc_dcr_register(env
, DMA0_CR2
,
659 dma
, &dcr_read_dma
, &dcr_write_dma
);
660 ppc_dcr_register(env
, DMA0_CT2
,
661 dma
, &dcr_read_dma
, &dcr_write_dma
);
662 ppc_dcr_register(env
, DMA0_DA2
,
663 dma
, &dcr_read_dma
, &dcr_write_dma
);
664 ppc_dcr_register(env
, DMA0_SA2
,
665 dma
, &dcr_read_dma
, &dcr_write_dma
);
666 ppc_dcr_register(env
, DMA0_SG2
,
667 dma
, &dcr_read_dma
, &dcr_write_dma
);
668 ppc_dcr_register(env
, DMA0_CR3
,
669 dma
, &dcr_read_dma
, &dcr_write_dma
);
670 ppc_dcr_register(env
, DMA0_CT3
,
671 dma
, &dcr_read_dma
, &dcr_write_dma
);
672 ppc_dcr_register(env
, DMA0_DA3
,
673 dma
, &dcr_read_dma
, &dcr_write_dma
);
674 ppc_dcr_register(env
, DMA0_SA3
,
675 dma
, &dcr_read_dma
, &dcr_write_dma
);
676 ppc_dcr_register(env
, DMA0_SG3
,
677 dma
, &dcr_read_dma
, &dcr_write_dma
);
678 ppc_dcr_register(env
, DMA0_SR
,
679 dma
, &dcr_read_dma
, &dcr_write_dma
);
680 ppc_dcr_register(env
, DMA0_SGC
,
681 dma
, &dcr_read_dma
, &dcr_write_dma
);
682 ppc_dcr_register(env
, DMA0_SLP
,
683 dma
, &dcr_read_dma
, &dcr_write_dma
);
684 ppc_dcr_register(env
, DMA0_POL
,
685 dma
, &dcr_read_dma
, &dcr_write_dma
);
688 /*****************************************************************************/
690 typedef struct ppc405_gpio_t ppc405_gpio_t
;
691 struct ppc405_gpio_t
{
706 static uint64_t ppc405_gpio_read(void *opaque
, hwaddr addr
, unsigned size
)
709 printf("%s: addr " TARGET_FMT_plx
" size %d\n", __func__
, addr
, size
);
715 static void ppc405_gpio_write(void *opaque
, hwaddr addr
, uint64_t value
,
719 printf("%s: addr " TARGET_FMT_plx
" size %d val %08" PRIx32
"\n",
720 __func__
, addr
, size
, value
);
724 static const MemoryRegionOps ppc405_gpio_ops
= {
725 .read
= ppc405_gpio_read
,
726 .write
= ppc405_gpio_write
,
727 .endianness
= DEVICE_NATIVE_ENDIAN
,
730 static void ppc405_gpio_reset (void *opaque
)
734 static void ppc405_gpio_init(hwaddr base
)
738 gpio
= g_malloc0(sizeof(ppc405_gpio_t
));
740 printf("%s: offset " TARGET_FMT_plx
"\n", __func__
, base
);
742 memory_region_init_io(&gpio
->io
, NULL
, &ppc405_gpio_ops
, gpio
, "pgio", 0x038);
743 memory_region_add_subregion(get_system_memory(), base
, &gpio
->io
);
744 qemu_register_reset(&ppc405_gpio_reset
, gpio
);
747 /*****************************************************************************/
751 OCM0_ISACNTL
= 0x019,
753 OCM0_DSACNTL
= 0x01B,
756 typedef struct ppc405_ocm_t ppc405_ocm_t
;
757 struct ppc405_ocm_t
{
759 MemoryRegion isarc_ram
;
760 MemoryRegion dsarc_ram
;
767 static void ocm_update_mappings (ppc405_ocm_t
*ocm
,
768 uint32_t isarc
, uint32_t isacntl
,
769 uint32_t dsarc
, uint32_t dsacntl
)
772 printf("OCM update ISA %08" PRIx32
" %08" PRIx32
" (%08" PRIx32
773 " %08" PRIx32
") DSA %08" PRIx32
" %08" PRIx32
774 " (%08" PRIx32
" %08" PRIx32
")\n",
775 isarc
, isacntl
, dsarc
, dsacntl
,
776 ocm
->isarc
, ocm
->isacntl
, ocm
->dsarc
, ocm
->dsacntl
);
778 if (ocm
->isarc
!= isarc
||
779 (ocm
->isacntl
& 0x80000000) != (isacntl
& 0x80000000)) {
780 if (ocm
->isacntl
& 0x80000000) {
781 /* Unmap previously assigned memory region */
782 printf("OCM unmap ISA %08" PRIx32
"\n", ocm
->isarc
);
783 memory_region_del_subregion(get_system_memory(), &ocm
->isarc_ram
);
785 if (isacntl
& 0x80000000) {
786 /* Map new instruction memory region */
788 printf("OCM map ISA %08" PRIx32
"\n", isarc
);
790 memory_region_add_subregion(get_system_memory(), isarc
,
794 if (ocm
->dsarc
!= dsarc
||
795 (ocm
->dsacntl
& 0x80000000) != (dsacntl
& 0x80000000)) {
796 if (ocm
->dsacntl
& 0x80000000) {
797 /* Beware not to unmap the region we just mapped */
798 if (!(isacntl
& 0x80000000) || ocm
->dsarc
!= isarc
) {
799 /* Unmap previously assigned memory region */
801 printf("OCM unmap DSA %08" PRIx32
"\n", ocm
->dsarc
);
803 memory_region_del_subregion(get_system_memory(),
807 if (dsacntl
& 0x80000000) {
808 /* Beware not to remap the region we just mapped */
809 if (!(isacntl
& 0x80000000) || dsarc
!= isarc
) {
810 /* Map new data memory region */
812 printf("OCM map DSA %08" PRIx32
"\n", dsarc
);
814 memory_region_add_subregion(get_system_memory(), dsarc
,
821 static uint32_t dcr_read_ocm (void *opaque
, int dcrn
)
848 static void dcr_write_ocm (void *opaque
, int dcrn
, uint32_t val
)
851 uint32_t isarc
, dsarc
, isacntl
, dsacntl
;
856 isacntl
= ocm
->isacntl
;
857 dsacntl
= ocm
->dsacntl
;
860 isarc
= val
& 0xFC000000;
863 isacntl
= val
& 0xC0000000;
866 isarc
= val
& 0xFC000000;
869 isacntl
= val
& 0xC0000000;
872 ocm_update_mappings(ocm
, isarc
, isacntl
, dsarc
, dsacntl
);
875 ocm
->isacntl
= isacntl
;
876 ocm
->dsacntl
= dsacntl
;
879 static void ocm_reset (void *opaque
)
882 uint32_t isarc
, dsarc
, isacntl
, dsacntl
;
886 isacntl
= 0x00000000;
888 dsacntl
= 0x00000000;
889 ocm_update_mappings(ocm
, isarc
, isacntl
, dsarc
, dsacntl
);
892 ocm
->isacntl
= isacntl
;
893 ocm
->dsacntl
= dsacntl
;
896 static void ppc405_ocm_init(CPUPPCState
*env
)
900 ocm
= g_malloc0(sizeof(ppc405_ocm_t
));
901 /* XXX: Size is 4096 or 0x04000000 */
902 memory_region_init_ram(&ocm
->isarc_ram
, NULL
, "ppc405.ocm", 4 * KiB
,
904 memory_region_init_alias(&ocm
->dsarc_ram
, NULL
, "ppc405.dsarc",
905 &ocm
->isarc_ram
, 0, 4 * KiB
);
906 qemu_register_reset(&ocm_reset
, ocm
);
907 ppc_dcr_register(env
, OCM0_ISARC
,
908 ocm
, &dcr_read_ocm
, &dcr_write_ocm
);
909 ppc_dcr_register(env
, OCM0_ISACNTL
,
910 ocm
, &dcr_read_ocm
, &dcr_write_ocm
);
911 ppc_dcr_register(env
, OCM0_DSARC
,
912 ocm
, &dcr_read_ocm
, &dcr_write_ocm
);
913 ppc_dcr_register(env
, OCM0_DSACNTL
,
914 ocm
, &dcr_read_ocm
, &dcr_write_ocm
);
917 /*****************************************************************************/
918 /* General purpose timers */
919 typedef struct ppc4xx_gpt_t ppc4xx_gpt_t
;
920 struct ppc4xx_gpt_t
{
935 static int ppc4xx_gpt_compare (ppc4xx_gpt_t
*gpt
, int n
)
941 static void ppc4xx_gpt_set_output (ppc4xx_gpt_t
*gpt
, int n
, int level
)
946 static void ppc4xx_gpt_set_outputs (ppc4xx_gpt_t
*gpt
)
952 for (i
= 0; i
< 5; i
++) {
953 if (gpt
->oe
& mask
) {
954 /* Output is enabled */
955 if (ppc4xx_gpt_compare(gpt
, i
)) {
956 /* Comparison is OK */
957 ppc4xx_gpt_set_output(gpt
, i
, gpt
->ol
& mask
);
959 /* Comparison is KO */
960 ppc4xx_gpt_set_output(gpt
, i
, gpt
->ol
& mask
? 0 : 1);
967 static void ppc4xx_gpt_set_irqs (ppc4xx_gpt_t
*gpt
)
973 for (i
= 0; i
< 5; i
++) {
974 if (gpt
->is
& gpt
->im
& mask
)
975 qemu_irq_raise(gpt
->irqs
[i
]);
977 qemu_irq_lower(gpt
->irqs
[i
]);
982 static void ppc4xx_gpt_compute_timer (ppc4xx_gpt_t
*gpt
)
987 static uint64_t ppc4xx_gpt_read(void *opaque
, hwaddr addr
, unsigned size
)
994 printf("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
999 /* Time base counter */
1000 ret
= muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
) + gpt
->tb_offset
,
1001 gpt
->tb_freq
, NANOSECONDS_PER_SECOND
);
1012 /* Interrupt mask */
1017 /* Interrupt status */
1021 /* Interrupt enable */
1026 idx
= (addr
- 0x80) >> 2;
1027 ret
= gpt
->comp
[idx
];
1031 idx
= (addr
- 0xC0) >> 2;
1032 ret
= gpt
->mask
[idx
];
1042 static void ppc4xx_gpt_write(void *opaque
, hwaddr addr
, uint64_t value
,
1049 printf("%s: addr " TARGET_FMT_plx
" val %08" PRIx32
"\n", __func__
, addr
,
1055 /* Time base counter */
1056 gpt
->tb_offset
= muldiv64(value
, NANOSECONDS_PER_SECOND
, gpt
->tb_freq
)
1057 - qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
);
1058 ppc4xx_gpt_compute_timer(gpt
);
1062 gpt
->oe
= value
& 0xF8000000;
1063 ppc4xx_gpt_set_outputs(gpt
);
1067 gpt
->ol
= value
& 0xF8000000;
1068 ppc4xx_gpt_set_outputs(gpt
);
1071 /* Interrupt mask */
1072 gpt
->im
= value
& 0x0000F800;
1075 /* Interrupt status set */
1076 gpt
->is
|= value
& 0x0000F800;
1077 ppc4xx_gpt_set_irqs(gpt
);
1080 /* Interrupt status clear */
1081 gpt
->is
&= ~(value
& 0x0000F800);
1082 ppc4xx_gpt_set_irqs(gpt
);
1085 /* Interrupt enable */
1086 gpt
->ie
= value
& 0x0000F800;
1087 ppc4xx_gpt_set_irqs(gpt
);
1091 idx
= (addr
- 0x80) >> 2;
1092 gpt
->comp
[idx
] = value
& 0xF8000000;
1093 ppc4xx_gpt_compute_timer(gpt
);
1097 idx
= (addr
- 0xC0) >> 2;
1098 gpt
->mask
[idx
] = value
& 0xF8000000;
1099 ppc4xx_gpt_compute_timer(gpt
);
1104 static const MemoryRegionOps gpt_ops
= {
1105 .read
= ppc4xx_gpt_read
,
1106 .write
= ppc4xx_gpt_write
,
1107 .valid
.min_access_size
= 4,
1108 .valid
.max_access_size
= 4,
1109 .endianness
= DEVICE_NATIVE_ENDIAN
,
1112 static void ppc4xx_gpt_cb (void *opaque
)
1117 ppc4xx_gpt_set_irqs(gpt
);
1118 ppc4xx_gpt_set_outputs(gpt
);
1119 ppc4xx_gpt_compute_timer(gpt
);
1122 static void ppc4xx_gpt_reset (void *opaque
)
1128 timer_del(gpt
->timer
);
1129 gpt
->oe
= 0x00000000;
1130 gpt
->ol
= 0x00000000;
1131 gpt
->im
= 0x00000000;
1132 gpt
->is
= 0x00000000;
1133 gpt
->ie
= 0x00000000;
1134 for (i
= 0; i
< 5; i
++) {
1135 gpt
->comp
[i
] = 0x00000000;
1136 gpt
->mask
[i
] = 0x00000000;
1140 static void ppc4xx_gpt_init(hwaddr base
, qemu_irq irqs
[5])
1145 gpt
= g_malloc0(sizeof(ppc4xx_gpt_t
));
1146 for (i
= 0; i
< 5; i
++) {
1147 gpt
->irqs
[i
] = irqs
[i
];
1149 gpt
->timer
= timer_new_ns(QEMU_CLOCK_VIRTUAL
, &ppc4xx_gpt_cb
, gpt
);
1151 printf("%s: offset " TARGET_FMT_plx
"\n", __func__
, base
);
1153 memory_region_init_io(&gpt
->iomem
, NULL
, &gpt_ops
, gpt
, "gpt", 0x0d4);
1154 memory_region_add_subregion(get_system_memory(), base
, &gpt
->iomem
);
1155 qemu_register_reset(ppc4xx_gpt_reset
, gpt
);
1158 /*****************************************************************************/
1161 PPC405CR_CPC0_PLLMR
= 0x0B0,
1162 PPC405CR_CPC0_CR0
= 0x0B1,
1163 PPC405CR_CPC0_CR1
= 0x0B2,
1164 PPC405CR_CPC0_PSR
= 0x0B4,
1165 PPC405CR_CPC0_JTAGID
= 0x0B5,
1166 PPC405CR_CPC0_ER
= 0x0B9,
1167 PPC405CR_CPC0_FR
= 0x0BA,
1168 PPC405CR_CPC0_SR
= 0x0BB,
1172 PPC405CR_CPU_CLK
= 0,
1173 PPC405CR_TMR_CLK
= 1,
1174 PPC405CR_PLB_CLK
= 2,
1175 PPC405CR_SDRAM_CLK
= 3,
1176 PPC405CR_OPB_CLK
= 4,
1177 PPC405CR_EXT_CLK
= 5,
1178 PPC405CR_UART_CLK
= 6,
1179 PPC405CR_CLK_NB
= 7,
1182 typedef struct ppc405cr_cpc_t ppc405cr_cpc_t
;
1183 struct ppc405cr_cpc_t
{
1184 clk_setup_t clk_setup
[PPC405CR_CLK_NB
];
1195 static void ppc405cr_clk_setup (ppc405cr_cpc_t
*cpc
)
1197 uint64_t VCO_out
, PLL_out
;
1198 uint32_t CPU_clk
, TMR_clk
, SDRAM_clk
, PLB_clk
, OPB_clk
, EXT_clk
, UART_clk
;
1201 D0
= ((cpc
->pllmr
>> 26) & 0x3) + 1; /* CBDV */
1202 if (cpc
->pllmr
& 0x80000000) {
1203 D1
= (((cpc
->pllmr
>> 20) - 1) & 0xF) + 1; /* FBDV */
1204 D2
= 8 - ((cpc
->pllmr
>> 16) & 0x7); /* FWDVA */
1206 VCO_out
= (uint64_t)cpc
->sysclk
* M
;
1207 if (VCO_out
< 400000000 || VCO_out
> 800000000) {
1208 /* PLL cannot lock */
1209 cpc
->pllmr
&= ~0x80000000;
1212 PLL_out
= VCO_out
/ D2
;
1217 PLL_out
= (uint64_t)cpc
->sysclk
* M
;
1220 if (cpc
->cr1
& 0x00800000)
1221 TMR_clk
= cpc
->sysclk
; /* Should have a separate clock */
1224 PLB_clk
= CPU_clk
/ D0
;
1225 SDRAM_clk
= PLB_clk
;
1226 D0
= ((cpc
->pllmr
>> 10) & 0x3) + 1;
1227 OPB_clk
= PLB_clk
/ D0
;
1228 D0
= ((cpc
->pllmr
>> 24) & 0x3) + 2;
1229 EXT_clk
= PLB_clk
/ D0
;
1230 D0
= ((cpc
->cr0
>> 1) & 0x1F) + 1;
1231 UART_clk
= CPU_clk
/ D0
;
1232 /* Setup CPU clocks */
1233 clk_setup(&cpc
->clk_setup
[PPC405CR_CPU_CLK
], CPU_clk
);
1234 /* Setup time-base clock */
1235 clk_setup(&cpc
->clk_setup
[PPC405CR_TMR_CLK
], TMR_clk
);
1236 /* Setup PLB clock */
1237 clk_setup(&cpc
->clk_setup
[PPC405CR_PLB_CLK
], PLB_clk
);
1238 /* Setup SDRAM clock */
1239 clk_setup(&cpc
->clk_setup
[PPC405CR_SDRAM_CLK
], SDRAM_clk
);
1240 /* Setup OPB clock */
1241 clk_setup(&cpc
->clk_setup
[PPC405CR_OPB_CLK
], OPB_clk
);
1242 /* Setup external clock */
1243 clk_setup(&cpc
->clk_setup
[PPC405CR_EXT_CLK
], EXT_clk
);
1244 /* Setup UART clock */
1245 clk_setup(&cpc
->clk_setup
[PPC405CR_UART_CLK
], UART_clk
);
1248 static uint32_t dcr_read_crcpc (void *opaque
, int dcrn
)
1250 ppc405cr_cpc_t
*cpc
;
1255 case PPC405CR_CPC0_PLLMR
:
1258 case PPC405CR_CPC0_CR0
:
1261 case PPC405CR_CPC0_CR1
:
1264 case PPC405CR_CPC0_PSR
:
1267 case PPC405CR_CPC0_JTAGID
:
1270 case PPC405CR_CPC0_ER
:
1273 case PPC405CR_CPC0_FR
:
1276 case PPC405CR_CPC0_SR
:
1277 ret
= ~(cpc
->er
| cpc
->fr
) & 0xFFFF0000;
1280 /* Avoid gcc warning */
1288 static void dcr_write_crcpc (void *opaque
, int dcrn
, uint32_t val
)
1290 ppc405cr_cpc_t
*cpc
;
1294 case PPC405CR_CPC0_PLLMR
:
1295 cpc
->pllmr
= val
& 0xFFF77C3F;
1297 case PPC405CR_CPC0_CR0
:
1298 cpc
->cr0
= val
& 0x0FFFFFFE;
1300 case PPC405CR_CPC0_CR1
:
1301 cpc
->cr1
= val
& 0x00800000;
1303 case PPC405CR_CPC0_PSR
:
1306 case PPC405CR_CPC0_JTAGID
:
1309 case PPC405CR_CPC0_ER
:
1310 cpc
->er
= val
& 0xBFFC0000;
1312 case PPC405CR_CPC0_FR
:
1313 cpc
->fr
= val
& 0xBFFC0000;
1315 case PPC405CR_CPC0_SR
:
1321 static void ppc405cr_cpc_reset (void *opaque
)
1323 ppc405cr_cpc_t
*cpc
;
1327 /* Compute PLLMR value from PSR settings */
1328 cpc
->pllmr
= 0x80000000;
1330 switch ((cpc
->psr
>> 30) & 3) {
1333 cpc
->pllmr
&= ~0x80000000;
1337 cpc
->pllmr
|= 5 << 16;
1341 cpc
->pllmr
|= 4 << 16;
1345 cpc
->pllmr
|= 2 << 16;
1349 D
= (cpc
->psr
>> 28) & 3;
1350 cpc
->pllmr
|= (D
+ 1) << 20;
1352 D
= (cpc
->psr
>> 25) & 7;
1367 D
= (cpc
->psr
>> 23) & 3;
1368 cpc
->pllmr
|= D
<< 26;
1370 D
= (cpc
->psr
>> 21) & 3;
1371 cpc
->pllmr
|= D
<< 10;
1373 D
= (cpc
->psr
>> 17) & 3;
1374 cpc
->pllmr
|= D
<< 24;
1375 cpc
->cr0
= 0x0000003C;
1376 cpc
->cr1
= 0x2B0D8800;
1377 cpc
->er
= 0x00000000;
1378 cpc
->fr
= 0x00000000;
1379 ppc405cr_clk_setup(cpc
);
1382 static void ppc405cr_clk_init (ppc405cr_cpc_t
*cpc
)
1386 /* XXX: this should be read from IO pins */
1387 cpc
->psr
= 0x00000000; /* 8 bits ROM */
1389 D
= 0x2; /* Divide by 4 */
1390 cpc
->psr
|= D
<< 30;
1392 D
= 0x1; /* Divide by 2 */
1393 cpc
->psr
|= D
<< 28;
1395 D
= 0x1; /* Divide by 2 */
1396 cpc
->psr
|= D
<< 23;
1398 D
= 0x5; /* M = 16 */
1399 cpc
->psr
|= D
<< 25;
1401 D
= 0x1; /* Divide by 2 */
1402 cpc
->psr
|= D
<< 21;
1404 D
= 0x2; /* Divide by 4 */
1405 cpc
->psr
|= D
<< 17;
1408 static void ppc405cr_cpc_init (CPUPPCState
*env
, clk_setup_t clk_setup
[7],
1411 ppc405cr_cpc_t
*cpc
;
1413 cpc
= g_malloc0(sizeof(ppc405cr_cpc_t
));
1414 memcpy(cpc
->clk_setup
, clk_setup
,
1415 PPC405CR_CLK_NB
* sizeof(clk_setup_t
));
1416 cpc
->sysclk
= sysclk
;
1417 cpc
->jtagid
= 0x42051049;
1418 ppc_dcr_register(env
, PPC405CR_CPC0_PSR
, cpc
,
1419 &dcr_read_crcpc
, &dcr_write_crcpc
);
1420 ppc_dcr_register(env
, PPC405CR_CPC0_CR0
, cpc
,
1421 &dcr_read_crcpc
, &dcr_write_crcpc
);
1422 ppc_dcr_register(env
, PPC405CR_CPC0_CR1
, cpc
,
1423 &dcr_read_crcpc
, &dcr_write_crcpc
);
1424 ppc_dcr_register(env
, PPC405CR_CPC0_JTAGID
, cpc
,
1425 &dcr_read_crcpc
, &dcr_write_crcpc
);
1426 ppc_dcr_register(env
, PPC405CR_CPC0_PLLMR
, cpc
,
1427 &dcr_read_crcpc
, &dcr_write_crcpc
);
1428 ppc_dcr_register(env
, PPC405CR_CPC0_ER
, cpc
,
1429 &dcr_read_crcpc
, &dcr_write_crcpc
);
1430 ppc_dcr_register(env
, PPC405CR_CPC0_FR
, cpc
,
1431 &dcr_read_crcpc
, &dcr_write_crcpc
);
1432 ppc_dcr_register(env
, PPC405CR_CPC0_SR
, cpc
,
1433 &dcr_read_crcpc
, &dcr_write_crcpc
);
1434 ppc405cr_clk_init(cpc
);
1435 qemu_register_reset(ppc405cr_cpc_reset
, cpc
);
1438 CPUPPCState
*ppc405cr_init(MemoryRegion
*address_space_mem
,
1439 MemoryRegion ram_memories
[4],
1440 hwaddr ram_bases
[4],
1441 hwaddr ram_sizes
[4],
1442 uint32_t sysclk
, qemu_irq
**picp
,
1445 clk_setup_t clk_setup
[PPC405CR_CLK_NB
];
1446 qemu_irq dma_irqs
[4];
1449 qemu_irq
*pic
, *irqs
;
1451 memset(clk_setup
, 0, sizeof(clk_setup
));
1452 cpu
= ppc4xx_init(POWERPC_CPU_TYPE_NAME("405crc"),
1453 &clk_setup
[PPC405CR_CPU_CLK
],
1454 &clk_setup
[PPC405CR_TMR_CLK
], sysclk
);
1456 /* Memory mapped devices registers */
1458 ppc4xx_plb_init(env
);
1459 /* PLB to OPB bridge */
1460 ppc4xx_pob_init(env
);
1462 ppc4xx_opba_init(0xef600600);
1463 /* Universal interrupt controller */
1464 irqs
= g_new0(qemu_irq
, PPCUIC_OUTPUT_NB
);
1465 irqs
[PPCUIC_OUTPUT_INT
] =
1466 ((qemu_irq
*)env
->irq_inputs
)[PPC40x_INPUT_INT
];
1467 irqs
[PPCUIC_OUTPUT_CINT
] =
1468 ((qemu_irq
*)env
->irq_inputs
)[PPC40x_INPUT_CINT
];
1469 pic
= ppcuic_init(env
, irqs
, 0x0C0, 0, 1);
1471 /* SDRAM controller */
1472 ppc4xx_sdram_init(env
, pic
[14], 1, ram_memories
,
1473 ram_bases
, ram_sizes
, do_init
);
1474 /* External bus controller */
1475 ppc405_ebc_init(env
);
1476 /* DMA controller */
1477 dma_irqs
[0] = pic
[26];
1478 dma_irqs
[1] = pic
[25];
1479 dma_irqs
[2] = pic
[24];
1480 dma_irqs
[3] = pic
[23];
1481 ppc405_dma_init(env
, dma_irqs
);
1483 if (serial_hd(0) != NULL
) {
1484 serial_mm_init(address_space_mem
, 0xef600300, 0, pic
[0],
1485 PPC_SERIAL_MM_BAUDBASE
, serial_hd(0),
1488 if (serial_hd(1) != NULL
) {
1489 serial_mm_init(address_space_mem
, 0xef600400, 0, pic
[1],
1490 PPC_SERIAL_MM_BAUDBASE
, serial_hd(1),
1493 /* IIC controller */
1494 sysbus_create_simple(TYPE_PPC4xx_I2C
, 0xef600500, pic
[2]);
1496 ppc405_gpio_init(0xef600700);
1498 ppc405cr_cpc_init(env
, clk_setup
, sysclk
);
1503 /*****************************************************************************/
1507 PPC405EP_CPC0_PLLMR0
= 0x0F0,
1508 PPC405EP_CPC0_BOOT
= 0x0F1,
1509 PPC405EP_CPC0_EPCTL
= 0x0F3,
1510 PPC405EP_CPC0_PLLMR1
= 0x0F4,
1511 PPC405EP_CPC0_UCR
= 0x0F5,
1512 PPC405EP_CPC0_SRR
= 0x0F6,
1513 PPC405EP_CPC0_JTAGID
= 0x0F7,
1514 PPC405EP_CPC0_PCI
= 0x0F9,
1516 PPC405EP_CPC0_ER
= xxx
,
1517 PPC405EP_CPC0_FR
= xxx
,
1518 PPC405EP_CPC0_SR
= xxx
,
1523 PPC405EP_CPU_CLK
= 0,
1524 PPC405EP_PLB_CLK
= 1,
1525 PPC405EP_OPB_CLK
= 2,
1526 PPC405EP_EBC_CLK
= 3,
1527 PPC405EP_MAL_CLK
= 4,
1528 PPC405EP_PCI_CLK
= 5,
1529 PPC405EP_UART0_CLK
= 6,
1530 PPC405EP_UART1_CLK
= 7,
1531 PPC405EP_CLK_NB
= 8,
1534 typedef struct ppc405ep_cpc_t ppc405ep_cpc_t
;
1535 struct ppc405ep_cpc_t
{
1537 clk_setup_t clk_setup
[PPC405EP_CLK_NB
];
1545 /* Clock and power management */
1551 static void ppc405ep_compute_clocks (ppc405ep_cpc_t
*cpc
)
1553 uint32_t CPU_clk
, PLB_clk
, OPB_clk
, EBC_clk
, MAL_clk
, PCI_clk
;
1554 uint32_t UART0_clk
, UART1_clk
;
1555 uint64_t VCO_out
, PLL_out
;
1559 if ((cpc
->pllmr
[1] & 0x80000000) && !(cpc
->pllmr
[1] & 0x40000000)) {
1560 M
= (((cpc
->pllmr
[1] >> 20) - 1) & 0xF) + 1; /* FBMUL */
1561 #ifdef DEBUG_CLOCKS_LL
1562 printf("FBMUL %01" PRIx32
" %d\n", (cpc
->pllmr
[1] >> 20) & 0xF, M
);
1564 D
= 8 - ((cpc
->pllmr
[1] >> 16) & 0x7); /* FWDA */
1565 #ifdef DEBUG_CLOCKS_LL
1566 printf("FWDA %01" PRIx32
" %d\n", (cpc
->pllmr
[1] >> 16) & 0x7, D
);
1568 VCO_out
= (uint64_t)cpc
->sysclk
* M
* D
;
1569 if (VCO_out
< 500000000UL || VCO_out
> 1000000000UL) {
1570 /* Error - unlock the PLL */
1571 printf("VCO out of range %" PRIu64
"\n", VCO_out
);
1573 cpc
->pllmr
[1] &= ~0x80000000;
1577 PLL_out
= VCO_out
/ D
;
1578 /* Pretend the PLL is locked */
1579 cpc
->boot
|= 0x00000001;
1584 PLL_out
= cpc
->sysclk
;
1585 if (cpc
->pllmr
[1] & 0x40000000) {
1586 /* Pretend the PLL is not locked */
1587 cpc
->boot
&= ~0x00000001;
1590 /* Now, compute all other clocks */
1591 D
= ((cpc
->pllmr
[0] >> 20) & 0x3) + 1; /* CCDV */
1592 #ifdef DEBUG_CLOCKS_LL
1593 printf("CCDV %01" PRIx32
" %d\n", (cpc
->pllmr
[0] >> 20) & 0x3, D
);
1595 CPU_clk
= PLL_out
/ D
;
1596 D
= ((cpc
->pllmr
[0] >> 16) & 0x3) + 1; /* CBDV */
1597 #ifdef DEBUG_CLOCKS_LL
1598 printf("CBDV %01" PRIx32
" %d\n", (cpc
->pllmr
[0] >> 16) & 0x3, D
);
1600 PLB_clk
= CPU_clk
/ D
;
1601 D
= ((cpc
->pllmr
[0] >> 12) & 0x3) + 1; /* OPDV */
1602 #ifdef DEBUG_CLOCKS_LL
1603 printf("OPDV %01" PRIx32
" %d\n", (cpc
->pllmr
[0] >> 12) & 0x3, D
);
1605 OPB_clk
= PLB_clk
/ D
;
1606 D
= ((cpc
->pllmr
[0] >> 8) & 0x3) + 2; /* EPDV */
1607 #ifdef DEBUG_CLOCKS_LL
1608 printf("EPDV %01" PRIx32
" %d\n", (cpc
->pllmr
[0] >> 8) & 0x3, D
);
1610 EBC_clk
= PLB_clk
/ D
;
1611 D
= ((cpc
->pllmr
[0] >> 4) & 0x3) + 1; /* MPDV */
1612 #ifdef DEBUG_CLOCKS_LL
1613 printf("MPDV %01" PRIx32
" %d\n", (cpc
->pllmr
[0] >> 4) & 0x3, D
);
1615 MAL_clk
= PLB_clk
/ D
;
1616 D
= (cpc
->pllmr
[0] & 0x3) + 1; /* PPDV */
1617 #ifdef DEBUG_CLOCKS_LL
1618 printf("PPDV %01" PRIx32
" %d\n", cpc
->pllmr
[0] & 0x3, D
);
1620 PCI_clk
= PLB_clk
/ D
;
1621 D
= ((cpc
->ucr
- 1) & 0x7F) + 1; /* U0DIV */
1622 #ifdef DEBUG_CLOCKS_LL
1623 printf("U0DIV %01" PRIx32
" %d\n", cpc
->ucr
& 0x7F, D
);
1625 UART0_clk
= PLL_out
/ D
;
1626 D
= (((cpc
->ucr
>> 8) - 1) & 0x7F) + 1; /* U1DIV */
1627 #ifdef DEBUG_CLOCKS_LL
1628 printf("U1DIV %01" PRIx32
" %d\n", (cpc
->ucr
>> 8) & 0x7F, D
);
1630 UART1_clk
= PLL_out
/ D
;
1632 printf("Setup PPC405EP clocks - sysclk %" PRIu32
" VCO %" PRIu64
1633 " PLL out %" PRIu64
" Hz\n", cpc
->sysclk
, VCO_out
, PLL_out
);
1634 printf("CPU %" PRIu32
" PLB %" PRIu32
" OPB %" PRIu32
" EBC %" PRIu32
1635 " MAL %" PRIu32
" PCI %" PRIu32
" UART0 %" PRIu32
1636 " UART1 %" PRIu32
"\n",
1637 CPU_clk
, PLB_clk
, OPB_clk
, EBC_clk
, MAL_clk
, PCI_clk
,
1638 UART0_clk
, UART1_clk
);
1640 /* Setup CPU clocks */
1641 clk_setup(&cpc
->clk_setup
[PPC405EP_CPU_CLK
], CPU_clk
);
1642 /* Setup PLB clock */
1643 clk_setup(&cpc
->clk_setup
[PPC405EP_PLB_CLK
], PLB_clk
);
1644 /* Setup OPB clock */
1645 clk_setup(&cpc
->clk_setup
[PPC405EP_OPB_CLK
], OPB_clk
);
1646 /* Setup external clock */
1647 clk_setup(&cpc
->clk_setup
[PPC405EP_EBC_CLK
], EBC_clk
);
1648 /* Setup MAL clock */
1649 clk_setup(&cpc
->clk_setup
[PPC405EP_MAL_CLK
], MAL_clk
);
1650 /* Setup PCI clock */
1651 clk_setup(&cpc
->clk_setup
[PPC405EP_PCI_CLK
], PCI_clk
);
1652 /* Setup UART0 clock */
1653 clk_setup(&cpc
->clk_setup
[PPC405EP_UART0_CLK
], UART0_clk
);
1654 /* Setup UART1 clock */
1655 clk_setup(&cpc
->clk_setup
[PPC405EP_UART1_CLK
], UART1_clk
);
1658 static uint32_t dcr_read_epcpc (void *opaque
, int dcrn
)
1660 ppc405ep_cpc_t
*cpc
;
1665 case PPC405EP_CPC0_BOOT
:
1668 case PPC405EP_CPC0_EPCTL
:
1671 case PPC405EP_CPC0_PLLMR0
:
1672 ret
= cpc
->pllmr
[0];
1674 case PPC405EP_CPC0_PLLMR1
:
1675 ret
= cpc
->pllmr
[1];
1677 case PPC405EP_CPC0_UCR
:
1680 case PPC405EP_CPC0_SRR
:
1683 case PPC405EP_CPC0_JTAGID
:
1686 case PPC405EP_CPC0_PCI
:
1690 /* Avoid gcc warning */
1698 static void dcr_write_epcpc (void *opaque
, int dcrn
, uint32_t val
)
1700 ppc405ep_cpc_t
*cpc
;
1704 case PPC405EP_CPC0_BOOT
:
1705 /* Read-only register */
1707 case PPC405EP_CPC0_EPCTL
:
1708 /* Don't care for now */
1709 cpc
->epctl
= val
& 0xC00000F3;
1711 case PPC405EP_CPC0_PLLMR0
:
1712 cpc
->pllmr
[0] = val
& 0x00633333;
1713 ppc405ep_compute_clocks(cpc
);
1715 case PPC405EP_CPC0_PLLMR1
:
1716 cpc
->pllmr
[1] = val
& 0xC0F73FFF;
1717 ppc405ep_compute_clocks(cpc
);
1719 case PPC405EP_CPC0_UCR
:
1720 /* UART control - don't care for now */
1721 cpc
->ucr
= val
& 0x003F7F7F;
1723 case PPC405EP_CPC0_SRR
:
1726 case PPC405EP_CPC0_JTAGID
:
1729 case PPC405EP_CPC0_PCI
:
1735 static void ppc405ep_cpc_reset (void *opaque
)
1737 ppc405ep_cpc_t
*cpc
= opaque
;
1739 cpc
->boot
= 0x00000010; /* Boot from PCI - IIC EEPROM disabled */
1740 cpc
->epctl
= 0x00000000;
1741 cpc
->pllmr
[0] = 0x00011010;
1742 cpc
->pllmr
[1] = 0x40000000;
1743 cpc
->ucr
= 0x00000000;
1744 cpc
->srr
= 0x00040000;
1745 cpc
->pci
= 0x00000000;
1746 cpc
->er
= 0x00000000;
1747 cpc
->fr
= 0x00000000;
1748 cpc
->sr
= 0x00000000;
1749 ppc405ep_compute_clocks(cpc
);
1752 /* XXX: sysclk should be between 25 and 100 MHz */
1753 static void ppc405ep_cpc_init (CPUPPCState
*env
, clk_setup_t clk_setup
[8],
1756 ppc405ep_cpc_t
*cpc
;
1758 cpc
= g_malloc0(sizeof(ppc405ep_cpc_t
));
1759 memcpy(cpc
->clk_setup
, clk_setup
,
1760 PPC405EP_CLK_NB
* sizeof(clk_setup_t
));
1761 cpc
->jtagid
= 0x20267049;
1762 cpc
->sysclk
= sysclk
;
1763 qemu_register_reset(&ppc405ep_cpc_reset
, cpc
);
1764 ppc_dcr_register(env
, PPC405EP_CPC0_BOOT
, cpc
,
1765 &dcr_read_epcpc
, &dcr_write_epcpc
);
1766 ppc_dcr_register(env
, PPC405EP_CPC0_EPCTL
, cpc
,
1767 &dcr_read_epcpc
, &dcr_write_epcpc
);
1768 ppc_dcr_register(env
, PPC405EP_CPC0_PLLMR0
, cpc
,
1769 &dcr_read_epcpc
, &dcr_write_epcpc
);
1770 ppc_dcr_register(env
, PPC405EP_CPC0_PLLMR1
, cpc
,
1771 &dcr_read_epcpc
, &dcr_write_epcpc
);
1772 ppc_dcr_register(env
, PPC405EP_CPC0_UCR
, cpc
,
1773 &dcr_read_epcpc
, &dcr_write_epcpc
);
1774 ppc_dcr_register(env
, PPC405EP_CPC0_SRR
, cpc
,
1775 &dcr_read_epcpc
, &dcr_write_epcpc
);
1776 ppc_dcr_register(env
, PPC405EP_CPC0_JTAGID
, cpc
,
1777 &dcr_read_epcpc
, &dcr_write_epcpc
);
1778 ppc_dcr_register(env
, PPC405EP_CPC0_PCI
, cpc
,
1779 &dcr_read_epcpc
, &dcr_write_epcpc
);
1781 ppc_dcr_register(env
, PPC405EP_CPC0_ER
, cpc
,
1782 &dcr_read_epcpc
, &dcr_write_epcpc
);
1783 ppc_dcr_register(env
, PPC405EP_CPC0_FR
, cpc
,
1784 &dcr_read_epcpc
, &dcr_write_epcpc
);
1785 ppc_dcr_register(env
, PPC405EP_CPC0_SR
, cpc
,
1786 &dcr_read_epcpc
, &dcr_write_epcpc
);
1790 CPUPPCState
*ppc405ep_init(MemoryRegion
*address_space_mem
,
1791 MemoryRegion ram_memories
[2],
1792 hwaddr ram_bases
[2],
1793 hwaddr ram_sizes
[2],
1794 uint32_t sysclk
, qemu_irq
**picp
,
1797 clk_setup_t clk_setup
[PPC405EP_CLK_NB
], tlb_clk_setup
;
1798 qemu_irq dma_irqs
[4], gpt_irqs
[5], mal_irqs
[4];
1801 qemu_irq
*pic
, *irqs
;
1803 memset(clk_setup
, 0, sizeof(clk_setup
));
1805 cpu
= ppc4xx_init(POWERPC_CPU_TYPE_NAME("405ep"),
1806 &clk_setup
[PPC405EP_CPU_CLK
],
1807 &tlb_clk_setup
, sysclk
);
1809 clk_setup
[PPC405EP_CPU_CLK
].cb
= tlb_clk_setup
.cb
;
1810 clk_setup
[PPC405EP_CPU_CLK
].opaque
= tlb_clk_setup
.opaque
;
1811 /* Internal devices init */
1812 /* Memory mapped devices registers */
1814 ppc4xx_plb_init(env
);
1815 /* PLB to OPB bridge */
1816 ppc4xx_pob_init(env
);
1818 ppc4xx_opba_init(0xef600600);
1819 /* Initialize timers */
1820 ppc_booke_timers_init(cpu
, sysclk
, 0);
1821 /* Universal interrupt controller */
1822 irqs
= g_new0(qemu_irq
, PPCUIC_OUTPUT_NB
);
1823 irqs
[PPCUIC_OUTPUT_INT
] =
1824 ((qemu_irq
*)env
->irq_inputs
)[PPC40x_INPUT_INT
];
1825 irqs
[PPCUIC_OUTPUT_CINT
] =
1826 ((qemu_irq
*)env
->irq_inputs
)[PPC40x_INPUT_CINT
];
1827 pic
= ppcuic_init(env
, irqs
, 0x0C0, 0, 1);
1829 /* SDRAM controller */
1830 /* XXX 405EP has no ECC interrupt */
1831 ppc4xx_sdram_init(env
, pic
[17], 2, ram_memories
,
1832 ram_bases
, ram_sizes
, do_init
);
1833 /* External bus controller */
1834 ppc405_ebc_init(env
);
1835 /* DMA controller */
1836 dma_irqs
[0] = pic
[5];
1837 dma_irqs
[1] = pic
[6];
1838 dma_irqs
[2] = pic
[7];
1839 dma_irqs
[3] = pic
[8];
1840 ppc405_dma_init(env
, dma_irqs
);
1841 /* IIC controller */
1842 sysbus_create_simple(TYPE_PPC4xx_I2C
, 0xef600500, pic
[2]);
1844 ppc405_gpio_init(0xef600700);
1846 if (serial_hd(0) != NULL
) {
1847 serial_mm_init(address_space_mem
, 0xef600300, 0, pic
[0],
1848 PPC_SERIAL_MM_BAUDBASE
, serial_hd(0),
1851 if (serial_hd(1) != NULL
) {
1852 serial_mm_init(address_space_mem
, 0xef600400, 0, pic
[1],
1853 PPC_SERIAL_MM_BAUDBASE
, serial_hd(1),
1857 ppc405_ocm_init(env
);
1859 gpt_irqs
[0] = pic
[19];
1860 gpt_irqs
[1] = pic
[20];
1861 gpt_irqs
[2] = pic
[21];
1862 gpt_irqs
[3] = pic
[22];
1863 gpt_irqs
[4] = pic
[23];
1864 ppc4xx_gpt_init(0xef600000, gpt_irqs
);
1866 /* Uses pic[3], pic[16], pic[18] */
1868 mal_irqs
[0] = pic
[11];
1869 mal_irqs
[1] = pic
[12];
1870 mal_irqs
[2] = pic
[13];
1871 mal_irqs
[3] = pic
[14];
1872 ppc4xx_mal_init(env
, 4, 2, mal_irqs
);
1874 /* Uses pic[9], pic[15], pic[17] */
1876 ppc405ep_cpc_init(env
, clk_setup
, sysclk
);