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
28 #include "qemu-timer.h"
41 //#define DEBUG_CLOCKS_LL
43 ram_addr_t
ppc405_set_bootinfo (CPUState
*env
, ppc4xx_bd_info_t
*bd
,
49 /* We put the bd structure at the top of memory */
50 if (bd
->bi_memsize
>= 0x01000000UL
)
51 bdloc
= 0x01000000UL
- sizeof(struct ppc4xx_bd_info_t
);
53 bdloc
= bd
->bi_memsize
- sizeof(struct ppc4xx_bd_info_t
);
54 stl_raw(phys_ram_base
+ bdloc
+ 0x00, bd
->bi_memstart
);
55 stl_raw(phys_ram_base
+ bdloc
+ 0x04, bd
->bi_memsize
);
56 stl_raw(phys_ram_base
+ bdloc
+ 0x08, bd
->bi_flashstart
);
57 stl_raw(phys_ram_base
+ bdloc
+ 0x0C, bd
->bi_flashsize
);
58 stl_raw(phys_ram_base
+ bdloc
+ 0x10, bd
->bi_flashoffset
);
59 stl_raw(phys_ram_base
+ bdloc
+ 0x14, bd
->bi_sramstart
);
60 stl_raw(phys_ram_base
+ bdloc
+ 0x18, bd
->bi_sramsize
);
61 stl_raw(phys_ram_base
+ bdloc
+ 0x1C, bd
->bi_bootflags
);
62 stl_raw(phys_ram_base
+ bdloc
+ 0x20, bd
->bi_ipaddr
);
63 for (i
= 0; i
< 6; i
++)
64 stb_raw(phys_ram_base
+ bdloc
+ 0x24 + i
, bd
->bi_enetaddr
[i
]);
65 stw_raw(phys_ram_base
+ bdloc
+ 0x2A, bd
->bi_ethspeed
);
66 stl_raw(phys_ram_base
+ bdloc
+ 0x2C, bd
->bi_intfreq
);
67 stl_raw(phys_ram_base
+ bdloc
+ 0x30, bd
->bi_busfreq
);
68 stl_raw(phys_ram_base
+ bdloc
+ 0x34, bd
->bi_baudrate
);
69 for (i
= 0; i
< 4; i
++)
70 stb_raw(phys_ram_base
+ bdloc
+ 0x38 + i
, bd
->bi_s_version
[i
]);
71 for (i
= 0; i
< 32; i
++)
72 stb_raw(phys_ram_base
+ bdloc
+ 0x3C + i
, bd
->bi_s_version
[i
]);
73 stl_raw(phys_ram_base
+ bdloc
+ 0x5C, bd
->bi_plb_busfreq
);
74 stl_raw(phys_ram_base
+ bdloc
+ 0x60, bd
->bi_pci_busfreq
);
75 for (i
= 0; i
< 6; i
++)
76 stb_raw(phys_ram_base
+ bdloc
+ 0x64 + i
, bd
->bi_pci_enetaddr
[i
]);
78 if (flags
& 0x00000001) {
79 for (i
= 0; i
< 6; i
++)
80 stb_raw(phys_ram_base
+ bdloc
+ n
++, bd
->bi_pci_enetaddr2
[i
]);
82 stl_raw(phys_ram_base
+ bdloc
+ n
, bd
->bi_opbfreq
);
84 for (i
= 0; i
< 2; i
++) {
85 stl_raw(phys_ram_base
+ bdloc
+ n
, bd
->bi_iic_fast
[i
]);
92 /*****************************************************************************/
93 /* Shared peripherals */
95 /*****************************************************************************/
96 /* Peripheral local bus arbitrer */
103 typedef struct ppc4xx_plb_t ppc4xx_plb_t
;
104 struct ppc4xx_plb_t
{
110 static target_ulong
dcr_read_plb (void *opaque
, int dcrn
)
127 /* Avoid gcc warning */
135 static void dcr_write_plb (void *opaque
, int dcrn
, target_ulong val
)
142 /* We don't care about the actual parameters written as
143 * we don't manage any priorities on the bus
145 plb
->acr
= val
& 0xF8000000;
157 static void ppc4xx_plb_reset (void *opaque
)
162 plb
->acr
= 0x00000000;
163 plb
->bear
= 0x00000000;
164 plb
->besr
= 0x00000000;
167 void ppc4xx_plb_init (CPUState
*env
)
171 plb
= qemu_mallocz(sizeof(ppc4xx_plb_t
));
173 ppc_dcr_register(env
, PLB0_ACR
, plb
, &dcr_read_plb
, &dcr_write_plb
);
174 ppc_dcr_register(env
, PLB0_BEAR
, plb
, &dcr_read_plb
, &dcr_write_plb
);
175 ppc_dcr_register(env
, PLB0_BESR
, plb
, &dcr_read_plb
, &dcr_write_plb
);
176 ppc4xx_plb_reset(plb
);
177 qemu_register_reset(ppc4xx_plb_reset
, plb
);
181 /*****************************************************************************/
182 /* PLB to OPB bridge */
189 typedef struct ppc4xx_pob_t ppc4xx_pob_t
;
190 struct ppc4xx_pob_t
{
195 static target_ulong
dcr_read_pob (void *opaque
, int dcrn
)
207 ret
= pob
->besr
[dcrn
- POB0_BESR0
];
210 /* Avoid gcc warning */
218 static void dcr_write_pob (void *opaque
, int dcrn
, target_ulong val
)
230 pob
->besr
[dcrn
- POB0_BESR0
] &= ~val
;
235 static void ppc4xx_pob_reset (void *opaque
)
241 pob
->bear
= 0x00000000;
242 pob
->besr
[0] = 0x0000000;
243 pob
->besr
[1] = 0x0000000;
246 void ppc4xx_pob_init (CPUState
*env
)
250 pob
= qemu_mallocz(sizeof(ppc4xx_pob_t
));
252 ppc_dcr_register(env
, POB0_BEAR
, pob
, &dcr_read_pob
, &dcr_write_pob
);
253 ppc_dcr_register(env
, POB0_BESR0
, pob
, &dcr_read_pob
, &dcr_write_pob
);
254 ppc_dcr_register(env
, POB0_BESR1
, pob
, &dcr_read_pob
, &dcr_write_pob
);
255 qemu_register_reset(ppc4xx_pob_reset
, pob
);
256 ppc4xx_pob_reset(env
);
260 /*****************************************************************************/
262 typedef struct ppc4xx_opba_t ppc4xx_opba_t
;
263 struct ppc4xx_opba_t
{
264 target_phys_addr_t base
;
269 static uint32_t opba_readb (void *opaque
, target_phys_addr_t addr
)
275 printf("%s: addr " PADDRX
"\n", __func__
, addr
);
278 switch (addr
- opba
->base
) {
293 static void opba_writeb (void *opaque
,
294 target_phys_addr_t addr
, uint32_t value
)
299 printf("%s: addr " PADDRX
" val %08" PRIx32
"\n", __func__
, addr
, value
);
302 switch (addr
- opba
->base
) {
304 opba
->cr
= value
& 0xF8;
307 opba
->pr
= value
& 0xFF;
314 static uint32_t opba_readw (void *opaque
, target_phys_addr_t addr
)
319 printf("%s: addr " PADDRX
"\n", __func__
, addr
);
321 ret
= opba_readb(opaque
, addr
) << 8;
322 ret
|= opba_readb(opaque
, addr
+ 1);
327 static void opba_writew (void *opaque
,
328 target_phys_addr_t addr
, uint32_t value
)
331 printf("%s: addr " PADDRX
" val %08" PRIx32
"\n", __func__
, addr
, value
);
333 opba_writeb(opaque
, addr
, value
>> 8);
334 opba_writeb(opaque
, addr
+ 1, value
);
337 static uint32_t opba_readl (void *opaque
, target_phys_addr_t addr
)
342 printf("%s: addr " PADDRX
"\n", __func__
, addr
);
344 ret
= opba_readb(opaque
, addr
) << 24;
345 ret
|= opba_readb(opaque
, addr
+ 1) << 16;
350 static void opba_writel (void *opaque
,
351 target_phys_addr_t addr
, uint32_t value
)
354 printf("%s: addr " PADDRX
" val %08" PRIx32
"\n", __func__
, addr
, value
);
356 opba_writeb(opaque
, addr
, value
>> 24);
357 opba_writeb(opaque
, addr
+ 1, value
>> 16);
360 static CPUReadMemoryFunc
*opba_read
[] = {
366 static CPUWriteMemoryFunc
*opba_write
[] = {
372 static void ppc4xx_opba_reset (void *opaque
)
377 opba
->cr
= 0x00; /* No dynamic priorities - park disabled */
381 void ppc4xx_opba_init (CPUState
*env
, ppc4xx_mmio_t
*mmio
,
382 target_phys_addr_t offset
)
386 opba
= qemu_mallocz(sizeof(ppc4xx_opba_t
));
390 printf("%s: offset " PADDRX
"\n", __func__
, offset
);
392 ppc4xx_mmio_register(env
, mmio
, offset
, 0x002,
393 opba_read
, opba_write
, opba
);
394 qemu_register_reset(ppc4xx_opba_reset
, opba
);
395 ppc4xx_opba_reset(opba
);
399 /*****************************************************************************/
400 /* Code decompression controller */
403 /*****************************************************************************/
404 /* SDRAM controller */
405 typedef struct ppc4xx_sdram_t ppc4xx_sdram_t
;
406 struct ppc4xx_sdram_t
{
409 target_phys_addr_t ram_bases
[4];
410 target_phys_addr_t ram_sizes
[4];
426 SDRAM0_CFGADDR
= 0x010,
427 SDRAM0_CFGDATA
= 0x011,
430 /* XXX: TOFIX: some patches have made this code become inconsistent:
431 * there are type inconsistencies, mixing target_phys_addr_t, target_ulong
434 static uint32_t sdram_bcr (target_phys_addr_t ram_base
,
435 target_phys_addr_t ram_size
)
440 case (4 * 1024 * 1024):
443 case (8 * 1024 * 1024):
446 case (16 * 1024 * 1024):
449 case (32 * 1024 * 1024):
452 case (64 * 1024 * 1024):
455 case (128 * 1024 * 1024):
458 case (256 * 1024 * 1024):
462 printf("%s: invalid RAM size " PADDRX
"\n", __func__
, ram_size
);
465 bcr
|= ram_base
& 0xFF800000;
471 static always_inline target_phys_addr_t
sdram_base (uint32_t bcr
)
473 return bcr
& 0xFF800000;
476 static target_ulong
sdram_size (uint32_t bcr
)
481 sh
= (bcr
>> 17) & 0x7;
485 size
= (4 * 1024 * 1024) << sh
;
490 static void sdram_set_bcr (uint32_t *bcrp
, uint32_t bcr
, int enabled
)
492 if (*bcrp
& 0x00000001) {
495 printf("%s: unmap RAM area " PADDRX
" " ADDRX
"\n",
496 __func__
, sdram_base(*bcrp
), sdram_size(*bcrp
));
498 cpu_register_physical_memory(sdram_base(*bcrp
), sdram_size(*bcrp
),
501 *bcrp
= bcr
& 0xFFDEE001;
502 if (enabled
&& (bcr
& 0x00000001)) {
504 printf("%s: Map RAM area " PADDRX
" " ADDRX
"\n",
505 __func__
, sdram_base(bcr
), sdram_size(bcr
));
507 cpu_register_physical_memory(sdram_base(bcr
), sdram_size(bcr
),
508 sdram_base(bcr
) | IO_MEM_RAM
);
512 static void sdram_map_bcr (ppc4xx_sdram_t
*sdram
)
516 for (i
= 0; i
< sdram
->nbanks
; i
++) {
517 if (sdram
->ram_sizes
[i
] != 0) {
518 sdram_set_bcr(&sdram
->bcr
[i
],
519 sdram_bcr(sdram
->ram_bases
[i
], sdram
->ram_sizes
[i
]),
522 sdram_set_bcr(&sdram
->bcr
[i
], 0x00000000, 0);
527 static void sdram_unmap_bcr (ppc4xx_sdram_t
*sdram
)
531 for (i
= 0; i
< sdram
->nbanks
; i
++) {
533 printf("%s: Unmap RAM area " PADDRX
" " ADDRX
"\n",
534 __func__
, sdram_base(sdram
->bcr
[i
]), sdram_size(sdram
->bcr
[i
]));
536 cpu_register_physical_memory(sdram_base(sdram
->bcr
[i
]),
537 sdram_size(sdram
->bcr
[i
]),
542 static target_ulong
dcr_read_sdram (void *opaque
, int dcrn
)
544 ppc4xx_sdram_t
*sdram
;
553 switch (sdram
->addr
) {
554 case 0x00: /* SDRAM_BESR0 */
557 case 0x08: /* SDRAM_BESR1 */
560 case 0x10: /* SDRAM_BEAR */
563 case 0x20: /* SDRAM_CFG */
566 case 0x24: /* SDRAM_STATUS */
569 case 0x30: /* SDRAM_RTR */
572 case 0x34: /* SDRAM_PMIT */
575 case 0x40: /* SDRAM_B0CR */
578 case 0x44: /* SDRAM_B1CR */
581 case 0x48: /* SDRAM_B2CR */
584 case 0x4C: /* SDRAM_B3CR */
587 case 0x80: /* SDRAM_TR */
590 case 0x94: /* SDRAM_ECCCFG */
593 case 0x98: /* SDRAM_ECCESR */
602 /* Avoid gcc warning */
610 static void dcr_write_sdram (void *opaque
, int dcrn
, target_ulong val
)
612 ppc4xx_sdram_t
*sdram
;
620 switch (sdram
->addr
) {
621 case 0x00: /* SDRAM_BESR0 */
622 sdram
->besr0
&= ~val
;
624 case 0x08: /* SDRAM_BESR1 */
625 sdram
->besr1
&= ~val
;
627 case 0x10: /* SDRAM_BEAR */
630 case 0x20: /* SDRAM_CFG */
632 if (!(sdram
->cfg
& 0x80000000) && (val
& 0x80000000)) {
634 printf("%s: enable SDRAM controller\n", __func__
);
636 /* validate all RAM mappings */
637 sdram_map_bcr(sdram
);
638 sdram
->status
&= ~0x80000000;
639 } else if ((sdram
->cfg
& 0x80000000) && !(val
& 0x80000000)) {
641 printf("%s: disable SDRAM controller\n", __func__
);
643 /* invalidate all RAM mappings */
644 sdram_unmap_bcr(sdram
);
645 sdram
->status
|= 0x80000000;
647 if (!(sdram
->cfg
& 0x40000000) && (val
& 0x40000000))
648 sdram
->status
|= 0x40000000;
649 else if ((sdram
->cfg
& 0x40000000) && !(val
& 0x40000000))
650 sdram
->status
&= ~0x40000000;
653 case 0x24: /* SDRAM_STATUS */
654 /* Read-only register */
656 case 0x30: /* SDRAM_RTR */
657 sdram
->rtr
= val
& 0x3FF80000;
659 case 0x34: /* SDRAM_PMIT */
660 sdram
->pmit
= (val
& 0xF8000000) | 0x07C00000;
662 case 0x40: /* SDRAM_B0CR */
663 sdram_set_bcr(&sdram
->bcr
[0], val
, sdram
->cfg
& 0x80000000);
665 case 0x44: /* SDRAM_B1CR */
666 sdram_set_bcr(&sdram
->bcr
[1], val
, sdram
->cfg
& 0x80000000);
668 case 0x48: /* SDRAM_B2CR */
669 sdram_set_bcr(&sdram
->bcr
[2], val
, sdram
->cfg
& 0x80000000);
671 case 0x4C: /* SDRAM_B3CR */
672 sdram_set_bcr(&sdram
->bcr
[3], val
, sdram
->cfg
& 0x80000000);
674 case 0x80: /* SDRAM_TR */
675 sdram
->tr
= val
& 0x018FC01F;
677 case 0x94: /* SDRAM_ECCCFG */
678 sdram
->ecccfg
= val
& 0x00F00000;
680 case 0x98: /* SDRAM_ECCESR */
682 if (sdram
->eccesr
== 0 && val
!= 0)
683 qemu_irq_raise(sdram
->irq
);
684 else if (sdram
->eccesr
!= 0 && val
== 0)
685 qemu_irq_lower(sdram
->irq
);
695 static void sdram_reset (void *opaque
)
697 ppc4xx_sdram_t
*sdram
;
700 sdram
->addr
= 0x00000000;
701 sdram
->bear
= 0x00000000;
702 sdram
->besr0
= 0x00000000; /* No error */
703 sdram
->besr1
= 0x00000000; /* No error */
704 sdram
->cfg
= 0x00000000;
705 sdram
->ecccfg
= 0x00000000; /* No ECC */
706 sdram
->eccesr
= 0x00000000; /* No error */
707 sdram
->pmit
= 0x07C00000;
708 sdram
->rtr
= 0x05F00000;
709 sdram
->tr
= 0x00854009;
710 /* We pre-initialize RAM banks */
711 sdram
->status
= 0x00000000;
712 sdram
->cfg
= 0x00800000;
713 sdram_unmap_bcr(sdram
);
716 void ppc405_sdram_init (CPUState
*env
, qemu_irq irq
, int nbanks
,
717 target_phys_addr_t
*ram_bases
,
718 target_phys_addr_t
*ram_sizes
,
721 ppc4xx_sdram_t
*sdram
;
723 sdram
= qemu_mallocz(sizeof(ppc4xx_sdram_t
));
726 sdram
->nbanks
= nbanks
;
727 memset(sdram
->ram_bases
, 0, 4 * sizeof(target_phys_addr_t
));
728 memcpy(sdram
->ram_bases
, ram_bases
,
729 nbanks
* sizeof(target_phys_addr_t
));
730 memset(sdram
->ram_sizes
, 0, 4 * sizeof(target_phys_addr_t
));
731 memcpy(sdram
->ram_sizes
, ram_sizes
,
732 nbanks
* sizeof(target_phys_addr_t
));
734 qemu_register_reset(&sdram_reset
, sdram
);
735 ppc_dcr_register(env
, SDRAM0_CFGADDR
,
736 sdram
, &dcr_read_sdram
, &dcr_write_sdram
);
737 ppc_dcr_register(env
, SDRAM0_CFGDATA
,
738 sdram
, &dcr_read_sdram
, &dcr_write_sdram
);
740 sdram_map_bcr(sdram
);
744 /*****************************************************************************/
745 /* Peripheral controller */
746 typedef struct ppc4xx_ebc_t ppc4xx_ebc_t
;
747 struct ppc4xx_ebc_t
{
758 EBC0_CFGADDR
= 0x012,
759 EBC0_CFGDATA
= 0x013,
762 static target_ulong
dcr_read_ebc (void *opaque
, int dcrn
)
774 case 0x00: /* B0CR */
777 case 0x01: /* B1CR */
780 case 0x02: /* B2CR */
783 case 0x03: /* B3CR */
786 case 0x04: /* B4CR */
789 case 0x05: /* B5CR */
792 case 0x06: /* B6CR */
795 case 0x07: /* B7CR */
798 case 0x10: /* B0AP */
801 case 0x11: /* B1AP */
804 case 0x12: /* B2AP */
807 case 0x13: /* B3AP */
810 case 0x14: /* B4AP */
813 case 0x15: /* B5AP */
816 case 0x16: /* B6AP */
819 case 0x17: /* B7AP */
822 case 0x20: /* BEAR */
825 case 0x21: /* BESR0 */
828 case 0x22: /* BESR1 */
846 static void dcr_write_ebc (void *opaque
, int dcrn
, target_ulong val
)
857 case 0x00: /* B0CR */
859 case 0x01: /* B1CR */
861 case 0x02: /* B2CR */
863 case 0x03: /* B3CR */
865 case 0x04: /* B4CR */
867 case 0x05: /* B5CR */
869 case 0x06: /* B6CR */
871 case 0x07: /* B7CR */
873 case 0x10: /* B0AP */
875 case 0x11: /* B1AP */
877 case 0x12: /* B2AP */
879 case 0x13: /* B3AP */
881 case 0x14: /* B4AP */
883 case 0x15: /* B5AP */
885 case 0x16: /* B6AP */
887 case 0x17: /* B7AP */
889 case 0x20: /* BEAR */
891 case 0x21: /* BESR0 */
893 case 0x22: /* BESR1 */
906 static void ebc_reset (void *opaque
)
912 ebc
->addr
= 0x00000000;
913 ebc
->bap
[0] = 0x7F8FFE80;
914 ebc
->bcr
[0] = 0xFFE28000;
915 for (i
= 0; i
< 8; i
++) {
916 ebc
->bap
[i
] = 0x00000000;
917 ebc
->bcr
[i
] = 0x00000000;
919 ebc
->besr0
= 0x00000000;
920 ebc
->besr1
= 0x00000000;
921 ebc
->cfg
= 0x80400000;
924 void ppc405_ebc_init (CPUState
*env
)
928 ebc
= qemu_mallocz(sizeof(ppc4xx_ebc_t
));
931 qemu_register_reset(&ebc_reset
, ebc
);
932 ppc_dcr_register(env
, EBC0_CFGADDR
,
933 ebc
, &dcr_read_ebc
, &dcr_write_ebc
);
934 ppc_dcr_register(env
, EBC0_CFGDATA
,
935 ebc
, &dcr_read_ebc
, &dcr_write_ebc
);
939 /*****************************************************************************/
968 typedef struct ppc405_dma_t ppc405_dma_t
;
969 struct ppc405_dma_t
{
982 static target_ulong
dcr_read_dma (void *opaque
, int dcrn
)
991 static void dcr_write_dma (void *opaque
, int dcrn
, target_ulong val
)
998 static void ppc405_dma_reset (void *opaque
)
1004 for (i
= 0; i
< 4; i
++) {
1005 dma
->cr
[i
] = 0x00000000;
1006 dma
->ct
[i
] = 0x00000000;
1007 dma
->da
[i
] = 0x00000000;
1008 dma
->sa
[i
] = 0x00000000;
1009 dma
->sg
[i
] = 0x00000000;
1011 dma
->sr
= 0x00000000;
1012 dma
->sgc
= 0x00000000;
1013 dma
->slp
= 0x7C000000;
1014 dma
->pol
= 0x00000000;
1017 void ppc405_dma_init (CPUState
*env
, qemu_irq irqs
[4])
1021 dma
= qemu_mallocz(sizeof(ppc405_dma_t
));
1023 memcpy(dma
->irqs
, irqs
, 4 * sizeof(qemu_irq
));
1024 ppc405_dma_reset(dma
);
1025 qemu_register_reset(&ppc405_dma_reset
, dma
);
1026 ppc_dcr_register(env
, DMA0_CR0
,
1027 dma
, &dcr_read_dma
, &dcr_write_dma
);
1028 ppc_dcr_register(env
, DMA0_CT0
,
1029 dma
, &dcr_read_dma
, &dcr_write_dma
);
1030 ppc_dcr_register(env
, DMA0_DA0
,
1031 dma
, &dcr_read_dma
, &dcr_write_dma
);
1032 ppc_dcr_register(env
, DMA0_SA0
,
1033 dma
, &dcr_read_dma
, &dcr_write_dma
);
1034 ppc_dcr_register(env
, DMA0_SG0
,
1035 dma
, &dcr_read_dma
, &dcr_write_dma
);
1036 ppc_dcr_register(env
, DMA0_CR1
,
1037 dma
, &dcr_read_dma
, &dcr_write_dma
);
1038 ppc_dcr_register(env
, DMA0_CT1
,
1039 dma
, &dcr_read_dma
, &dcr_write_dma
);
1040 ppc_dcr_register(env
, DMA0_DA1
,
1041 dma
, &dcr_read_dma
, &dcr_write_dma
);
1042 ppc_dcr_register(env
, DMA0_SA1
,
1043 dma
, &dcr_read_dma
, &dcr_write_dma
);
1044 ppc_dcr_register(env
, DMA0_SG1
,
1045 dma
, &dcr_read_dma
, &dcr_write_dma
);
1046 ppc_dcr_register(env
, DMA0_CR2
,
1047 dma
, &dcr_read_dma
, &dcr_write_dma
);
1048 ppc_dcr_register(env
, DMA0_CT2
,
1049 dma
, &dcr_read_dma
, &dcr_write_dma
);
1050 ppc_dcr_register(env
, DMA0_DA2
,
1051 dma
, &dcr_read_dma
, &dcr_write_dma
);
1052 ppc_dcr_register(env
, DMA0_SA2
,
1053 dma
, &dcr_read_dma
, &dcr_write_dma
);
1054 ppc_dcr_register(env
, DMA0_SG2
,
1055 dma
, &dcr_read_dma
, &dcr_write_dma
);
1056 ppc_dcr_register(env
, DMA0_CR3
,
1057 dma
, &dcr_read_dma
, &dcr_write_dma
);
1058 ppc_dcr_register(env
, DMA0_CT3
,
1059 dma
, &dcr_read_dma
, &dcr_write_dma
);
1060 ppc_dcr_register(env
, DMA0_DA3
,
1061 dma
, &dcr_read_dma
, &dcr_write_dma
);
1062 ppc_dcr_register(env
, DMA0_SA3
,
1063 dma
, &dcr_read_dma
, &dcr_write_dma
);
1064 ppc_dcr_register(env
, DMA0_SG3
,
1065 dma
, &dcr_read_dma
, &dcr_write_dma
);
1066 ppc_dcr_register(env
, DMA0_SR
,
1067 dma
, &dcr_read_dma
, &dcr_write_dma
);
1068 ppc_dcr_register(env
, DMA0_SGC
,
1069 dma
, &dcr_read_dma
, &dcr_write_dma
);
1070 ppc_dcr_register(env
, DMA0_SLP
,
1071 dma
, &dcr_read_dma
, &dcr_write_dma
);
1072 ppc_dcr_register(env
, DMA0_POL
,
1073 dma
, &dcr_read_dma
, &dcr_write_dma
);
1077 /*****************************************************************************/
1079 typedef struct ppc405_gpio_t ppc405_gpio_t
;
1080 struct ppc405_gpio_t
{
1081 target_phys_addr_t base
;
1095 static uint32_t ppc405_gpio_readb (void *opaque
, target_phys_addr_t addr
)
1097 ppc405_gpio_t
*gpio
;
1101 printf("%s: addr " PADDRX
"\n", __func__
, addr
);
1107 static void ppc405_gpio_writeb (void *opaque
,
1108 target_phys_addr_t addr
, uint32_t value
)
1110 ppc405_gpio_t
*gpio
;
1114 printf("%s: addr " PADDRX
" val %08" PRIx32
"\n", __func__
, addr
, value
);
1118 static uint32_t ppc405_gpio_readw (void *opaque
, target_phys_addr_t addr
)
1120 ppc405_gpio_t
*gpio
;
1124 printf("%s: addr " PADDRX
"\n", __func__
, addr
);
1130 static void ppc405_gpio_writew (void *opaque
,
1131 target_phys_addr_t addr
, uint32_t value
)
1133 ppc405_gpio_t
*gpio
;
1137 printf("%s: addr " PADDRX
" val %08" PRIx32
"\n", __func__
, addr
, value
);
1141 static uint32_t ppc405_gpio_readl (void *opaque
, target_phys_addr_t addr
)
1143 ppc405_gpio_t
*gpio
;
1147 printf("%s: addr " PADDRX
"\n", __func__
, addr
);
1153 static void ppc405_gpio_writel (void *opaque
,
1154 target_phys_addr_t addr
, uint32_t value
)
1156 ppc405_gpio_t
*gpio
;
1160 printf("%s: addr " PADDRX
" val %08" PRIx32
"\n", __func__
, addr
, value
);
1164 static CPUReadMemoryFunc
*ppc405_gpio_read
[] = {
1170 static CPUWriteMemoryFunc
*ppc405_gpio_write
[] = {
1171 &ppc405_gpio_writeb
,
1172 &ppc405_gpio_writew
,
1173 &ppc405_gpio_writel
,
1176 static void ppc405_gpio_reset (void *opaque
)
1178 ppc405_gpio_t
*gpio
;
1183 void ppc405_gpio_init (CPUState
*env
, ppc4xx_mmio_t
*mmio
,
1184 target_phys_addr_t offset
)
1186 ppc405_gpio_t
*gpio
;
1188 gpio
= qemu_mallocz(sizeof(ppc405_gpio_t
));
1190 gpio
->base
= offset
;
1191 ppc405_gpio_reset(gpio
);
1192 qemu_register_reset(&ppc405_gpio_reset
, gpio
);
1194 printf("%s: offset " PADDRX
"\n", __func__
, offset
);
1196 ppc4xx_mmio_register(env
, mmio
, offset
, 0x038,
1197 ppc405_gpio_read
, ppc405_gpio_write
, gpio
);
1201 /*****************************************************************************/
1203 static CPUReadMemoryFunc
*serial_mm_read
[] = {
1209 static CPUWriteMemoryFunc
*serial_mm_write
[] = {
1215 void ppc405_serial_init (CPUState
*env
, ppc4xx_mmio_t
*mmio
,
1216 target_phys_addr_t offset
, qemu_irq irq
,
1217 CharDriverState
*chr
)
1222 printf("%s: offset " PADDRX
"\n", __func__
, offset
);
1224 serial
= serial_mm_init(offset
, 0, irq
, 399193, chr
, 0);
1225 ppc4xx_mmio_register(env
, mmio
, offset
, 0x008,
1226 serial_mm_read
, serial_mm_write
, serial
);
1229 /*****************************************************************************/
1230 /* On Chip Memory */
1233 OCM0_ISACNTL
= 0x019,
1235 OCM0_DSACNTL
= 0x01B,
1238 typedef struct ppc405_ocm_t ppc405_ocm_t
;
1239 struct ppc405_ocm_t
{
1240 target_ulong offset
;
1247 static void ocm_update_mappings (ppc405_ocm_t
*ocm
,
1248 uint32_t isarc
, uint32_t isacntl
,
1249 uint32_t dsarc
, uint32_t dsacntl
)
1252 printf("OCM update ISA %08" PRIx32
" %08" PRIx32
" (%08" PRIx32
1253 " %08" PRIx32
") DSA %08" PRIx32
" %08" PRIx32
1254 " (%08" PRIx32
" %08" PRIx32
")\n",
1255 isarc
, isacntl
, dsarc
, dsacntl
,
1256 ocm
->isarc
, ocm
->isacntl
, ocm
->dsarc
, ocm
->dsacntl
);
1258 if (ocm
->isarc
!= isarc
||
1259 (ocm
->isacntl
& 0x80000000) != (isacntl
& 0x80000000)) {
1260 if (ocm
->isacntl
& 0x80000000) {
1261 /* Unmap previously assigned memory region */
1262 printf("OCM unmap ISA %08" PRIx32
"\n", ocm
->isarc
);
1263 cpu_register_physical_memory(ocm
->isarc
, 0x04000000,
1266 if (isacntl
& 0x80000000) {
1267 /* Map new instruction memory region */
1269 printf("OCM map ISA %08" PRIx32
"\n", isarc
);
1271 cpu_register_physical_memory(isarc
, 0x04000000,
1272 ocm
->offset
| IO_MEM_RAM
);
1275 if (ocm
->dsarc
!= dsarc
||
1276 (ocm
->dsacntl
& 0x80000000) != (dsacntl
& 0x80000000)) {
1277 if (ocm
->dsacntl
& 0x80000000) {
1278 /* Beware not to unmap the region we just mapped */
1279 if (!(isacntl
& 0x80000000) || ocm
->dsarc
!= isarc
) {
1280 /* Unmap previously assigned memory region */
1282 printf("OCM unmap DSA %08" PRIx32
"\n", ocm
->dsarc
);
1284 cpu_register_physical_memory(ocm
->dsarc
, 0x04000000,
1288 if (dsacntl
& 0x80000000) {
1289 /* Beware not to remap the region we just mapped */
1290 if (!(isacntl
& 0x80000000) || dsarc
!= isarc
) {
1291 /* Map new data memory region */
1293 printf("OCM map DSA %08" PRIx32
"\n", dsarc
);
1295 cpu_register_physical_memory(dsarc
, 0x04000000,
1296 ocm
->offset
| IO_MEM_RAM
);
1302 static target_ulong
dcr_read_ocm (void *opaque
, int dcrn
)
1329 static void dcr_write_ocm (void *opaque
, int dcrn
, target_ulong val
)
1332 uint32_t isarc
, dsarc
, isacntl
, dsacntl
;
1337 isacntl
= ocm
->isacntl
;
1338 dsacntl
= ocm
->dsacntl
;
1341 isarc
= val
& 0xFC000000;
1344 isacntl
= val
& 0xC0000000;
1347 isarc
= val
& 0xFC000000;
1350 isacntl
= val
& 0xC0000000;
1353 ocm_update_mappings(ocm
, isarc
, isacntl
, dsarc
, dsacntl
);
1356 ocm
->isacntl
= isacntl
;
1357 ocm
->dsacntl
= dsacntl
;
1360 static void ocm_reset (void *opaque
)
1363 uint32_t isarc
, dsarc
, isacntl
, dsacntl
;
1367 isacntl
= 0x00000000;
1369 dsacntl
= 0x00000000;
1370 ocm_update_mappings(ocm
, isarc
, isacntl
, dsarc
, dsacntl
);
1373 ocm
->isacntl
= isacntl
;
1374 ocm
->dsacntl
= dsacntl
;
1377 void ppc405_ocm_init (CPUState
*env
, unsigned long offset
)
1381 ocm
= qemu_mallocz(sizeof(ppc405_ocm_t
));
1383 ocm
->offset
= offset
;
1385 qemu_register_reset(&ocm_reset
, ocm
);
1386 ppc_dcr_register(env
, OCM0_ISARC
,
1387 ocm
, &dcr_read_ocm
, &dcr_write_ocm
);
1388 ppc_dcr_register(env
, OCM0_ISACNTL
,
1389 ocm
, &dcr_read_ocm
, &dcr_write_ocm
);
1390 ppc_dcr_register(env
, OCM0_DSARC
,
1391 ocm
, &dcr_read_ocm
, &dcr_write_ocm
);
1392 ppc_dcr_register(env
, OCM0_DSACNTL
,
1393 ocm
, &dcr_read_ocm
, &dcr_write_ocm
);
1397 /*****************************************************************************/
1398 /* I2C controller */
1399 typedef struct ppc4xx_i2c_t ppc4xx_i2c_t
;
1400 struct ppc4xx_i2c_t
{
1401 target_phys_addr_t base
;
1420 static uint32_t ppc4xx_i2c_readb (void *opaque
, target_phys_addr_t addr
)
1426 printf("%s: addr " PADDRX
"\n", __func__
, addr
);
1429 switch (addr
- i2c
->base
) {
1431 // i2c_readbyte(&i2c->mdata);
1471 ret
= i2c
->xtcntlss
;
1474 ret
= i2c
->directcntl
;
1481 printf("%s: addr " PADDRX
" %02" PRIx32
"\n", __func__
, addr
, ret
);
1487 static void ppc4xx_i2c_writeb (void *opaque
,
1488 target_phys_addr_t addr
, uint32_t value
)
1493 printf("%s: addr " PADDRX
" val %08" PRIx32
"\n", __func__
, addr
, value
);
1496 switch (addr
- i2c
->base
) {
1499 // i2c_sendbyte(&i2c->mdata);
1514 i2c
->mdcntl
= value
& 0xDF;
1517 i2c
->sts
&= ~(value
& 0x0A);
1520 i2c
->extsts
&= ~(value
& 0x8F);
1529 i2c
->clkdiv
= value
;
1532 i2c
->intrmsk
= value
;
1535 i2c
->xfrcnt
= value
& 0x77;
1538 i2c
->xtcntlss
= value
;
1541 i2c
->directcntl
= value
& 0x7;
1546 static uint32_t ppc4xx_i2c_readw (void *opaque
, target_phys_addr_t addr
)
1551 printf("%s: addr " PADDRX
"\n", __func__
, addr
);
1553 ret
= ppc4xx_i2c_readb(opaque
, addr
) << 8;
1554 ret
|= ppc4xx_i2c_readb(opaque
, addr
+ 1);
1559 static void ppc4xx_i2c_writew (void *opaque
,
1560 target_phys_addr_t addr
, uint32_t value
)
1563 printf("%s: addr " PADDRX
" val %08" PRIx32
"\n", __func__
, addr
, value
);
1565 ppc4xx_i2c_writeb(opaque
, addr
, value
>> 8);
1566 ppc4xx_i2c_writeb(opaque
, addr
+ 1, value
);
1569 static uint32_t ppc4xx_i2c_readl (void *opaque
, target_phys_addr_t addr
)
1574 printf("%s: addr " PADDRX
"\n", __func__
, addr
);
1576 ret
= ppc4xx_i2c_readb(opaque
, addr
) << 24;
1577 ret
|= ppc4xx_i2c_readb(opaque
, addr
+ 1) << 16;
1578 ret
|= ppc4xx_i2c_readb(opaque
, addr
+ 2) << 8;
1579 ret
|= ppc4xx_i2c_readb(opaque
, addr
+ 3);
1584 static void ppc4xx_i2c_writel (void *opaque
,
1585 target_phys_addr_t addr
, uint32_t value
)
1588 printf("%s: addr " PADDRX
" val %08" PRIx32
"\n", __func__
, addr
, value
);
1590 ppc4xx_i2c_writeb(opaque
, addr
, value
>> 24);
1591 ppc4xx_i2c_writeb(opaque
, addr
+ 1, value
>> 16);
1592 ppc4xx_i2c_writeb(opaque
, addr
+ 2, value
>> 8);
1593 ppc4xx_i2c_writeb(opaque
, addr
+ 3, value
);
1596 static CPUReadMemoryFunc
*i2c_read
[] = {
1602 static CPUWriteMemoryFunc
*i2c_write
[] = {
1608 static void ppc4xx_i2c_reset (void *opaque
)
1621 i2c
->directcntl
= 0x0F;
1624 void ppc405_i2c_init (CPUState
*env
, ppc4xx_mmio_t
*mmio
,
1625 target_phys_addr_t offset
, qemu_irq irq
)
1629 i2c
= qemu_mallocz(sizeof(ppc4xx_i2c_t
));
1633 ppc4xx_i2c_reset(i2c
);
1635 printf("%s: offset " PADDRX
"\n", __func__
, offset
);
1637 ppc4xx_mmio_register(env
, mmio
, offset
, 0x011,
1638 i2c_read
, i2c_write
, i2c
);
1639 qemu_register_reset(ppc4xx_i2c_reset
, i2c
);
1643 /*****************************************************************************/
1644 /* General purpose timers */
1645 typedef struct ppc4xx_gpt_t ppc4xx_gpt_t
;
1646 struct ppc4xx_gpt_t
{
1647 target_phys_addr_t base
;
1650 struct QEMUTimer
*timer
;
1661 static uint32_t ppc4xx_gpt_readb (void *opaque
, target_phys_addr_t addr
)
1664 printf("%s: addr " PADDRX
"\n", __func__
, addr
);
1666 /* XXX: generate a bus fault */
1670 static void ppc4xx_gpt_writeb (void *opaque
,
1671 target_phys_addr_t addr
, uint32_t value
)
1674 printf("%s: addr " PADDRX
" val %08" PRIx32
"\n", __func__
, addr
, value
);
1676 /* XXX: generate a bus fault */
1679 static uint32_t ppc4xx_gpt_readw (void *opaque
, target_phys_addr_t addr
)
1682 printf("%s: addr " PADDRX
"\n", __func__
, addr
);
1684 /* XXX: generate a bus fault */
1688 static void ppc4xx_gpt_writew (void *opaque
,
1689 target_phys_addr_t addr
, uint32_t value
)
1692 printf("%s: addr " PADDRX
" val %08" PRIx32
"\n", __func__
, addr
, value
);
1694 /* XXX: generate a bus fault */
1697 static int ppc4xx_gpt_compare (ppc4xx_gpt_t
*gpt
, int n
)
1703 static void ppc4xx_gpt_set_output (ppc4xx_gpt_t
*gpt
, int n
, int level
)
1708 static void ppc4xx_gpt_set_outputs (ppc4xx_gpt_t
*gpt
)
1714 for (i
= 0; i
< 5; i
++) {
1715 if (gpt
->oe
& mask
) {
1716 /* Output is enabled */
1717 if (ppc4xx_gpt_compare(gpt
, i
)) {
1718 /* Comparison is OK */
1719 ppc4xx_gpt_set_output(gpt
, i
, gpt
->ol
& mask
);
1721 /* Comparison is KO */
1722 ppc4xx_gpt_set_output(gpt
, i
, gpt
->ol
& mask
? 0 : 1);
1729 static void ppc4xx_gpt_set_irqs (ppc4xx_gpt_t
*gpt
)
1735 for (i
= 0; i
< 5; i
++) {
1736 if (gpt
->is
& gpt
->im
& mask
)
1737 qemu_irq_raise(gpt
->irqs
[i
]);
1739 qemu_irq_lower(gpt
->irqs
[i
]);
1744 static void ppc4xx_gpt_compute_timer (ppc4xx_gpt_t
*gpt
)
1749 static uint32_t ppc4xx_gpt_readl (void *opaque
, target_phys_addr_t addr
)
1756 printf("%s: addr " PADDRX
"\n", __func__
, addr
);
1759 switch (addr
- gpt
->base
) {
1761 /* Time base counter */
1762 ret
= muldiv64(qemu_get_clock(vm_clock
) + gpt
->tb_offset
,
1763 gpt
->tb_freq
, ticks_per_sec
);
1774 /* Interrupt mask */
1779 /* Interrupt status */
1783 /* Interrupt enable */
1788 idx
= ((addr
- gpt
->base
) - 0x80) >> 2;
1789 ret
= gpt
->comp
[idx
];
1793 idx
= ((addr
- gpt
->base
) - 0xC0) >> 2;
1794 ret
= gpt
->mask
[idx
];
1804 static void ppc4xx_gpt_writel (void *opaque
,
1805 target_phys_addr_t addr
, uint32_t value
)
1811 printf("%s: addr " PADDRX
" val %08" PRIx32
"\n", __func__
, addr
, value
);
1814 switch (addr
- gpt
->base
) {
1816 /* Time base counter */
1817 gpt
->tb_offset
= muldiv64(value
, ticks_per_sec
, gpt
->tb_freq
)
1818 - qemu_get_clock(vm_clock
);
1819 ppc4xx_gpt_compute_timer(gpt
);
1823 gpt
->oe
= value
& 0xF8000000;
1824 ppc4xx_gpt_set_outputs(gpt
);
1828 gpt
->ol
= value
& 0xF8000000;
1829 ppc4xx_gpt_set_outputs(gpt
);
1832 /* Interrupt mask */
1833 gpt
->im
= value
& 0x0000F800;
1836 /* Interrupt status set */
1837 gpt
->is
|= value
& 0x0000F800;
1838 ppc4xx_gpt_set_irqs(gpt
);
1841 /* Interrupt status clear */
1842 gpt
->is
&= ~(value
& 0x0000F800);
1843 ppc4xx_gpt_set_irqs(gpt
);
1846 /* Interrupt enable */
1847 gpt
->ie
= value
& 0x0000F800;
1848 ppc4xx_gpt_set_irqs(gpt
);
1852 idx
= ((addr
- gpt
->base
) - 0x80) >> 2;
1853 gpt
->comp
[idx
] = value
& 0xF8000000;
1854 ppc4xx_gpt_compute_timer(gpt
);
1858 idx
= ((addr
- gpt
->base
) - 0xC0) >> 2;
1859 gpt
->mask
[idx
] = value
& 0xF8000000;
1860 ppc4xx_gpt_compute_timer(gpt
);
1865 static CPUReadMemoryFunc
*gpt_read
[] = {
1871 static CPUWriteMemoryFunc
*gpt_write
[] = {
1877 static void ppc4xx_gpt_cb (void *opaque
)
1882 ppc4xx_gpt_set_irqs(gpt
);
1883 ppc4xx_gpt_set_outputs(gpt
);
1884 ppc4xx_gpt_compute_timer(gpt
);
1887 static void ppc4xx_gpt_reset (void *opaque
)
1893 qemu_del_timer(gpt
->timer
);
1894 gpt
->oe
= 0x00000000;
1895 gpt
->ol
= 0x00000000;
1896 gpt
->im
= 0x00000000;
1897 gpt
->is
= 0x00000000;
1898 gpt
->ie
= 0x00000000;
1899 for (i
= 0; i
< 5; i
++) {
1900 gpt
->comp
[i
] = 0x00000000;
1901 gpt
->mask
[i
] = 0x00000000;
1905 void ppc4xx_gpt_init (CPUState
*env
, ppc4xx_mmio_t
*mmio
,
1906 target_phys_addr_t offset
, qemu_irq irqs
[5])
1911 gpt
= qemu_mallocz(sizeof(ppc4xx_gpt_t
));
1914 for (i
= 0; i
< 5; i
++)
1915 gpt
->irqs
[i
] = irqs
[i
];
1916 gpt
->timer
= qemu_new_timer(vm_clock
, &ppc4xx_gpt_cb
, gpt
);
1917 ppc4xx_gpt_reset(gpt
);
1919 printf("%s: offset " PADDRX
"\n", __func__
, offset
);
1921 ppc4xx_mmio_register(env
, mmio
, offset
, 0x0D4,
1922 gpt_read
, gpt_write
, gpt
);
1923 qemu_register_reset(ppc4xx_gpt_reset
, gpt
);
1927 /*****************************************************************************/
1933 MAL0_TXCASR
= 0x184,
1934 MAL0_TXCARR
= 0x185,
1935 MAL0_TXEOBISR
= 0x186,
1936 MAL0_TXDEIR
= 0x187,
1937 MAL0_RXCASR
= 0x190,
1938 MAL0_RXCARR
= 0x191,
1939 MAL0_RXEOBISR
= 0x192,
1940 MAL0_RXDEIR
= 0x193,
1941 MAL0_TXCTP0R
= 0x1A0,
1942 MAL0_TXCTP1R
= 0x1A1,
1943 MAL0_TXCTP2R
= 0x1A2,
1944 MAL0_TXCTP3R
= 0x1A3,
1945 MAL0_RXCTP0R
= 0x1C0,
1946 MAL0_RXCTP1R
= 0x1C1,
1951 typedef struct ppc40x_mal_t ppc40x_mal_t
;
1952 struct ppc40x_mal_t
{
1970 static void ppc40x_mal_reset (void *opaque
);
1972 static target_ulong
dcr_read_mal (void *opaque
, int dcrn
)
1995 ret
= mal
->txeobisr
;
2007 ret
= mal
->rxeobisr
;
2013 ret
= mal
->txctpr
[0];
2016 ret
= mal
->txctpr
[1];
2019 ret
= mal
->txctpr
[2];
2022 ret
= mal
->txctpr
[3];
2025 ret
= mal
->rxctpr
[0];
2028 ret
= mal
->rxctpr
[1];
2044 static void dcr_write_mal (void *opaque
, int dcrn
, target_ulong val
)
2052 if (val
& 0x80000000)
2053 ppc40x_mal_reset(mal
);
2054 mal
->cfg
= val
& 0x00FFC087;
2061 mal
->ier
= val
& 0x0000001F;
2064 mal
->txcasr
= val
& 0xF0000000;
2067 mal
->txcarr
= val
& 0xF0000000;
2071 mal
->txeobisr
&= ~val
;
2075 mal
->txdeir
&= ~val
;
2078 mal
->rxcasr
= val
& 0xC0000000;
2081 mal
->rxcarr
= val
& 0xC0000000;
2085 mal
->rxeobisr
&= ~val
;
2089 mal
->rxdeir
&= ~val
;
2103 mal
->txctpr
[idx
] = val
;
2111 mal
->rxctpr
[idx
] = val
;
2115 goto update_rx_size
;
2119 mal
->rcbs
[idx
] = val
& 0x000000FF;
2124 static void ppc40x_mal_reset (void *opaque
)
2129 mal
->cfg
= 0x0007C000;
2130 mal
->esr
= 0x00000000;
2131 mal
->ier
= 0x00000000;
2132 mal
->rxcasr
= 0x00000000;
2133 mal
->rxdeir
= 0x00000000;
2134 mal
->rxeobisr
= 0x00000000;
2135 mal
->txcasr
= 0x00000000;
2136 mal
->txdeir
= 0x00000000;
2137 mal
->txeobisr
= 0x00000000;
2140 void ppc405_mal_init (CPUState
*env
, qemu_irq irqs
[4])
2145 mal
= qemu_mallocz(sizeof(ppc40x_mal_t
));
2147 for (i
= 0; i
< 4; i
++)
2148 mal
->irqs
[i
] = irqs
[i
];
2149 ppc40x_mal_reset(mal
);
2150 qemu_register_reset(&ppc40x_mal_reset
, mal
);
2151 ppc_dcr_register(env
, MAL0_CFG
,
2152 mal
, &dcr_read_mal
, &dcr_write_mal
);
2153 ppc_dcr_register(env
, MAL0_ESR
,
2154 mal
, &dcr_read_mal
, &dcr_write_mal
);
2155 ppc_dcr_register(env
, MAL0_IER
,
2156 mal
, &dcr_read_mal
, &dcr_write_mal
);
2157 ppc_dcr_register(env
, MAL0_TXCASR
,
2158 mal
, &dcr_read_mal
, &dcr_write_mal
);
2159 ppc_dcr_register(env
, MAL0_TXCARR
,
2160 mal
, &dcr_read_mal
, &dcr_write_mal
);
2161 ppc_dcr_register(env
, MAL0_TXEOBISR
,
2162 mal
, &dcr_read_mal
, &dcr_write_mal
);
2163 ppc_dcr_register(env
, MAL0_TXDEIR
,
2164 mal
, &dcr_read_mal
, &dcr_write_mal
);
2165 ppc_dcr_register(env
, MAL0_RXCASR
,
2166 mal
, &dcr_read_mal
, &dcr_write_mal
);
2167 ppc_dcr_register(env
, MAL0_RXCARR
,
2168 mal
, &dcr_read_mal
, &dcr_write_mal
);
2169 ppc_dcr_register(env
, MAL0_RXEOBISR
,
2170 mal
, &dcr_read_mal
, &dcr_write_mal
);
2171 ppc_dcr_register(env
, MAL0_RXDEIR
,
2172 mal
, &dcr_read_mal
, &dcr_write_mal
);
2173 ppc_dcr_register(env
, MAL0_TXCTP0R
,
2174 mal
, &dcr_read_mal
, &dcr_write_mal
);
2175 ppc_dcr_register(env
, MAL0_TXCTP1R
,
2176 mal
, &dcr_read_mal
, &dcr_write_mal
);
2177 ppc_dcr_register(env
, MAL0_TXCTP2R
,
2178 mal
, &dcr_read_mal
, &dcr_write_mal
);
2179 ppc_dcr_register(env
, MAL0_TXCTP3R
,
2180 mal
, &dcr_read_mal
, &dcr_write_mal
);
2181 ppc_dcr_register(env
, MAL0_RXCTP0R
,
2182 mal
, &dcr_read_mal
, &dcr_write_mal
);
2183 ppc_dcr_register(env
, MAL0_RXCTP1R
,
2184 mal
, &dcr_read_mal
, &dcr_write_mal
);
2185 ppc_dcr_register(env
, MAL0_RCBS0
,
2186 mal
, &dcr_read_mal
, &dcr_write_mal
);
2187 ppc_dcr_register(env
, MAL0_RCBS1
,
2188 mal
, &dcr_read_mal
, &dcr_write_mal
);
2192 /*****************************************************************************/
2194 void ppc40x_core_reset (CPUState
*env
)
2198 printf("Reset PowerPC core\n");
2199 env
->interrupt_request
|= CPU_INTERRUPT_EXITTB
;
2204 qemu_system_reset_request();
2206 dbsr
= env
->spr
[SPR_40x_DBSR
];
2207 dbsr
&= ~0x00000300;
2209 env
->spr
[SPR_40x_DBSR
] = dbsr
;
2212 void ppc40x_chip_reset (CPUState
*env
)
2216 printf("Reset PowerPC chip\n");
2217 env
->interrupt_request
|= CPU_INTERRUPT_EXITTB
;
2222 qemu_system_reset_request();
2224 /* XXX: TODO reset all internal peripherals */
2225 dbsr
= env
->spr
[SPR_40x_DBSR
];
2226 dbsr
&= ~0x00000300;
2228 env
->spr
[SPR_40x_DBSR
] = dbsr
;
2231 void ppc40x_system_reset (CPUState
*env
)
2233 printf("Reset PowerPC system\n");
2234 qemu_system_reset_request();
2237 void store_40x_dbcr0 (CPUState
*env
, uint32_t val
)
2239 switch ((val
>> 28) & 0x3) {
2245 ppc40x_core_reset(env
);
2249 ppc40x_chip_reset(env
);
2253 ppc40x_system_reset(env
);
2258 /*****************************************************************************/
2261 PPC405CR_CPC0_PLLMR
= 0x0B0,
2262 PPC405CR_CPC0_CR0
= 0x0B1,
2263 PPC405CR_CPC0_CR1
= 0x0B2,
2264 PPC405CR_CPC0_PSR
= 0x0B4,
2265 PPC405CR_CPC0_JTAGID
= 0x0B5,
2266 PPC405CR_CPC0_ER
= 0x0B9,
2267 PPC405CR_CPC0_FR
= 0x0BA,
2268 PPC405CR_CPC0_SR
= 0x0BB,
2272 PPC405CR_CPU_CLK
= 0,
2273 PPC405CR_TMR_CLK
= 1,
2274 PPC405CR_PLB_CLK
= 2,
2275 PPC405CR_SDRAM_CLK
= 3,
2276 PPC405CR_OPB_CLK
= 4,
2277 PPC405CR_EXT_CLK
= 5,
2278 PPC405CR_UART_CLK
= 6,
2279 PPC405CR_CLK_NB
= 7,
2282 typedef struct ppc405cr_cpc_t ppc405cr_cpc_t
;
2283 struct ppc405cr_cpc_t
{
2284 clk_setup_t clk_setup
[PPC405CR_CLK_NB
];
2295 static void ppc405cr_clk_setup (ppc405cr_cpc_t
*cpc
)
2297 uint64_t VCO_out
, PLL_out
;
2298 uint32_t CPU_clk
, TMR_clk
, SDRAM_clk
, PLB_clk
, OPB_clk
, EXT_clk
, UART_clk
;
2301 D0
= ((cpc
->pllmr
>> 26) & 0x3) + 1; /* CBDV */
2302 if (cpc
->pllmr
& 0x80000000) {
2303 D1
= (((cpc
->pllmr
>> 20) - 1) & 0xF) + 1; /* FBDV */
2304 D2
= 8 - ((cpc
->pllmr
>> 16) & 0x7); /* FWDVA */
2306 VCO_out
= cpc
->sysclk
* M
;
2307 if (VCO_out
< 400000000 || VCO_out
> 800000000) {
2308 /* PLL cannot lock */
2309 cpc
->pllmr
&= ~0x80000000;
2312 PLL_out
= VCO_out
/ D2
;
2317 PLL_out
= cpc
->sysclk
* M
;
2320 if (cpc
->cr1
& 0x00800000)
2321 TMR_clk
= cpc
->sysclk
; /* Should have a separate clock */
2324 PLB_clk
= CPU_clk
/ D0
;
2325 SDRAM_clk
= PLB_clk
;
2326 D0
= ((cpc
->pllmr
>> 10) & 0x3) + 1;
2327 OPB_clk
= PLB_clk
/ D0
;
2328 D0
= ((cpc
->pllmr
>> 24) & 0x3) + 2;
2329 EXT_clk
= PLB_clk
/ D0
;
2330 D0
= ((cpc
->cr0
>> 1) & 0x1F) + 1;
2331 UART_clk
= CPU_clk
/ D0
;
2332 /* Setup CPU clocks */
2333 clk_setup(&cpc
->clk_setup
[PPC405CR_CPU_CLK
], CPU_clk
);
2334 /* Setup time-base clock */
2335 clk_setup(&cpc
->clk_setup
[PPC405CR_TMR_CLK
], TMR_clk
);
2336 /* Setup PLB clock */
2337 clk_setup(&cpc
->clk_setup
[PPC405CR_PLB_CLK
], PLB_clk
);
2338 /* Setup SDRAM clock */
2339 clk_setup(&cpc
->clk_setup
[PPC405CR_SDRAM_CLK
], SDRAM_clk
);
2340 /* Setup OPB clock */
2341 clk_setup(&cpc
->clk_setup
[PPC405CR_OPB_CLK
], OPB_clk
);
2342 /* Setup external clock */
2343 clk_setup(&cpc
->clk_setup
[PPC405CR_EXT_CLK
], EXT_clk
);
2344 /* Setup UART clock */
2345 clk_setup(&cpc
->clk_setup
[PPC405CR_UART_CLK
], UART_clk
);
2348 static target_ulong
dcr_read_crcpc (void *opaque
, int dcrn
)
2350 ppc405cr_cpc_t
*cpc
;
2355 case PPC405CR_CPC0_PLLMR
:
2358 case PPC405CR_CPC0_CR0
:
2361 case PPC405CR_CPC0_CR1
:
2364 case PPC405CR_CPC0_PSR
:
2367 case PPC405CR_CPC0_JTAGID
:
2370 case PPC405CR_CPC0_ER
:
2373 case PPC405CR_CPC0_FR
:
2376 case PPC405CR_CPC0_SR
:
2377 ret
= ~(cpc
->er
| cpc
->fr
) & 0xFFFF0000;
2380 /* Avoid gcc warning */
2388 static void dcr_write_crcpc (void *opaque
, int dcrn
, target_ulong val
)
2390 ppc405cr_cpc_t
*cpc
;
2394 case PPC405CR_CPC0_PLLMR
:
2395 cpc
->pllmr
= val
& 0xFFF77C3F;
2397 case PPC405CR_CPC0_CR0
:
2398 cpc
->cr0
= val
& 0x0FFFFFFE;
2400 case PPC405CR_CPC0_CR1
:
2401 cpc
->cr1
= val
& 0x00800000;
2403 case PPC405CR_CPC0_PSR
:
2406 case PPC405CR_CPC0_JTAGID
:
2409 case PPC405CR_CPC0_ER
:
2410 cpc
->er
= val
& 0xBFFC0000;
2412 case PPC405CR_CPC0_FR
:
2413 cpc
->fr
= val
& 0xBFFC0000;
2415 case PPC405CR_CPC0_SR
:
2421 static void ppc405cr_cpc_reset (void *opaque
)
2423 ppc405cr_cpc_t
*cpc
;
2427 /* Compute PLLMR value from PSR settings */
2428 cpc
->pllmr
= 0x80000000;
2430 switch ((cpc
->psr
>> 30) & 3) {
2433 cpc
->pllmr
&= ~0x80000000;
2437 cpc
->pllmr
|= 5 << 16;
2441 cpc
->pllmr
|= 4 << 16;
2445 cpc
->pllmr
|= 2 << 16;
2449 D
= (cpc
->psr
>> 28) & 3;
2450 cpc
->pllmr
|= (D
+ 1) << 20;
2452 D
= (cpc
->psr
>> 25) & 7;
2467 D
= (cpc
->psr
>> 23) & 3;
2468 cpc
->pllmr
|= D
<< 26;
2470 D
= (cpc
->psr
>> 21) & 3;
2471 cpc
->pllmr
|= D
<< 10;
2473 D
= (cpc
->psr
>> 17) & 3;
2474 cpc
->pllmr
|= D
<< 24;
2475 cpc
->cr0
= 0x0000003C;
2476 cpc
->cr1
= 0x2B0D8800;
2477 cpc
->er
= 0x00000000;
2478 cpc
->fr
= 0x00000000;
2479 ppc405cr_clk_setup(cpc
);
2482 static void ppc405cr_clk_init (ppc405cr_cpc_t
*cpc
)
2486 /* XXX: this should be read from IO pins */
2487 cpc
->psr
= 0x00000000; /* 8 bits ROM */
2489 D
= 0x2; /* Divide by 4 */
2490 cpc
->psr
|= D
<< 30;
2492 D
= 0x1; /* Divide by 2 */
2493 cpc
->psr
|= D
<< 28;
2495 D
= 0x1; /* Divide by 2 */
2496 cpc
->psr
|= D
<< 23;
2498 D
= 0x5; /* M = 16 */
2499 cpc
->psr
|= D
<< 25;
2501 D
= 0x1; /* Divide by 2 */
2502 cpc
->psr
|= D
<< 21;
2504 D
= 0x2; /* Divide by 4 */
2505 cpc
->psr
|= D
<< 17;
2508 static void ppc405cr_cpc_init (CPUState
*env
, clk_setup_t clk_setup
[7],
2511 ppc405cr_cpc_t
*cpc
;
2513 cpc
= qemu_mallocz(sizeof(ppc405cr_cpc_t
));
2515 memcpy(cpc
->clk_setup
, clk_setup
,
2516 PPC405CR_CLK_NB
* sizeof(clk_setup_t
));
2517 cpc
->sysclk
= sysclk
;
2518 cpc
->jtagid
= 0x42051049;
2519 ppc_dcr_register(env
, PPC405CR_CPC0_PSR
, cpc
,
2520 &dcr_read_crcpc
, &dcr_write_crcpc
);
2521 ppc_dcr_register(env
, PPC405CR_CPC0_CR0
, cpc
,
2522 &dcr_read_crcpc
, &dcr_write_crcpc
);
2523 ppc_dcr_register(env
, PPC405CR_CPC0_CR1
, cpc
,
2524 &dcr_read_crcpc
, &dcr_write_crcpc
);
2525 ppc_dcr_register(env
, PPC405CR_CPC0_JTAGID
, cpc
,
2526 &dcr_read_crcpc
, &dcr_write_crcpc
);
2527 ppc_dcr_register(env
, PPC405CR_CPC0_PLLMR
, cpc
,
2528 &dcr_read_crcpc
, &dcr_write_crcpc
);
2529 ppc_dcr_register(env
, PPC405CR_CPC0_ER
, cpc
,
2530 &dcr_read_crcpc
, &dcr_write_crcpc
);
2531 ppc_dcr_register(env
, PPC405CR_CPC0_FR
, cpc
,
2532 &dcr_read_crcpc
, &dcr_write_crcpc
);
2533 ppc_dcr_register(env
, PPC405CR_CPC0_SR
, cpc
,
2534 &dcr_read_crcpc
, &dcr_write_crcpc
);
2535 ppc405cr_clk_init(cpc
);
2536 qemu_register_reset(ppc405cr_cpc_reset
, cpc
);
2537 ppc405cr_cpc_reset(cpc
);
2541 CPUState
*ppc405cr_init (target_phys_addr_t ram_bases
[4],
2542 target_phys_addr_t ram_sizes
[4],
2543 uint32_t sysclk
, qemu_irq
**picp
,
2544 ram_addr_t
*offsetp
, int do_init
)
2546 clk_setup_t clk_setup
[PPC405CR_CLK_NB
];
2547 qemu_irq dma_irqs
[4];
2549 ppc4xx_mmio_t
*mmio
;
2550 qemu_irq
*pic
, *irqs
;
2554 memset(clk_setup
, 0, sizeof(clk_setup
));
2555 env
= ppc4xx_init("405cr", &clk_setup
[PPC405CR_CPU_CLK
],
2556 &clk_setup
[PPC405CR_TMR_CLK
], sysclk
);
2557 /* Memory mapped devices registers */
2558 mmio
= ppc4xx_mmio_init(env
, 0xEF600000);
2560 ppc4xx_plb_init(env
);
2561 /* PLB to OPB bridge */
2562 ppc4xx_pob_init(env
);
2564 ppc4xx_opba_init(env
, mmio
, 0x600);
2565 /* Universal interrupt controller */
2566 irqs
= qemu_mallocz(sizeof(qemu_irq
) * PPCUIC_OUTPUT_NB
);
2567 irqs
[PPCUIC_OUTPUT_INT
] =
2568 ((qemu_irq
*)env
->irq_inputs
)[PPC40x_INPUT_INT
];
2569 irqs
[PPCUIC_OUTPUT_CINT
] =
2570 ((qemu_irq
*)env
->irq_inputs
)[PPC40x_INPUT_CINT
];
2571 pic
= ppcuic_init(env
, irqs
, 0x0C0, 0, 1);
2573 /* SDRAM controller */
2574 ppc405_sdram_init(env
, pic
[14], 1, ram_bases
, ram_sizes
, do_init
);
2576 for (i
= 0; i
< 4; i
++)
2577 offset
+= ram_sizes
[i
];
2578 /* External bus controller */
2579 ppc405_ebc_init(env
);
2580 /* DMA controller */
2581 dma_irqs
[0] = pic
[26];
2582 dma_irqs
[1] = pic
[25];
2583 dma_irqs
[2] = pic
[24];
2584 dma_irqs
[3] = pic
[23];
2585 ppc405_dma_init(env
, dma_irqs
);
2587 if (serial_hds
[0] != NULL
) {
2588 ppc405_serial_init(env
, mmio
, 0x300, pic
[0], serial_hds
[0]);
2590 if (serial_hds
[1] != NULL
) {
2591 ppc405_serial_init(env
, mmio
, 0x400, pic
[1], serial_hds
[1]);
2593 /* IIC controller */
2594 ppc405_i2c_init(env
, mmio
, 0x500, pic
[2]);
2596 ppc405_gpio_init(env
, mmio
, 0x700);
2598 ppc405cr_cpc_init(env
, clk_setup
, sysclk
);
2604 /*****************************************************************************/
2608 PPC405EP_CPC0_PLLMR0
= 0x0F0,
2609 PPC405EP_CPC0_BOOT
= 0x0F1,
2610 PPC405EP_CPC0_EPCTL
= 0x0F3,
2611 PPC405EP_CPC0_PLLMR1
= 0x0F4,
2612 PPC405EP_CPC0_UCR
= 0x0F5,
2613 PPC405EP_CPC0_SRR
= 0x0F6,
2614 PPC405EP_CPC0_JTAGID
= 0x0F7,
2615 PPC405EP_CPC0_PCI
= 0x0F9,
2617 PPC405EP_CPC0_ER
= xxx
,
2618 PPC405EP_CPC0_FR
= xxx
,
2619 PPC405EP_CPC0_SR
= xxx
,
2624 PPC405EP_CPU_CLK
= 0,
2625 PPC405EP_PLB_CLK
= 1,
2626 PPC405EP_OPB_CLK
= 2,
2627 PPC405EP_EBC_CLK
= 3,
2628 PPC405EP_MAL_CLK
= 4,
2629 PPC405EP_PCI_CLK
= 5,
2630 PPC405EP_UART0_CLK
= 6,
2631 PPC405EP_UART1_CLK
= 7,
2632 PPC405EP_CLK_NB
= 8,
2635 typedef struct ppc405ep_cpc_t ppc405ep_cpc_t
;
2636 struct ppc405ep_cpc_t
{
2638 clk_setup_t clk_setup
[PPC405EP_CLK_NB
];
2646 /* Clock and power management */
2652 static void ppc405ep_compute_clocks (ppc405ep_cpc_t
*cpc
)
2654 uint32_t CPU_clk
, PLB_clk
, OPB_clk
, EBC_clk
, MAL_clk
, PCI_clk
;
2655 uint32_t UART0_clk
, UART1_clk
;
2656 uint64_t VCO_out
, PLL_out
;
2660 if ((cpc
->pllmr
[1] & 0x80000000) && !(cpc
->pllmr
[1] & 0x40000000)) {
2661 M
= (((cpc
->pllmr
[1] >> 20) - 1) & 0xF) + 1; /* FBMUL */
2662 #ifdef DEBUG_CLOCKS_LL
2663 printf("FBMUL %01" PRIx32
" %d\n", (cpc
->pllmr
[1] >> 20) & 0xF, M
);
2665 D
= 8 - ((cpc
->pllmr
[1] >> 16) & 0x7); /* FWDA */
2666 #ifdef DEBUG_CLOCKS_LL
2667 printf("FWDA %01" PRIx32
" %d\n", (cpc
->pllmr
[1] >> 16) & 0x7, D
);
2669 VCO_out
= cpc
->sysclk
* M
* D
;
2670 if (VCO_out
< 500000000UL || VCO_out
> 1000000000UL) {
2671 /* Error - unlock the PLL */
2672 printf("VCO out of range %" PRIu64
"\n", VCO_out
);
2674 cpc
->pllmr
[1] &= ~0x80000000;
2678 PLL_out
= VCO_out
/ D
;
2679 /* Pretend the PLL is locked */
2680 cpc
->boot
|= 0x00000001;
2685 PLL_out
= cpc
->sysclk
;
2686 if (cpc
->pllmr
[1] & 0x40000000) {
2687 /* Pretend the PLL is not locked */
2688 cpc
->boot
&= ~0x00000001;
2691 /* Now, compute all other clocks */
2692 D
= ((cpc
->pllmr
[0] >> 20) & 0x3) + 1; /* CCDV */
2693 #ifdef DEBUG_CLOCKS_LL
2694 printf("CCDV %01" PRIx32
" %d\n", (cpc
->pllmr
[0] >> 20) & 0x3, D
);
2696 CPU_clk
= PLL_out
/ D
;
2697 D
= ((cpc
->pllmr
[0] >> 16) & 0x3) + 1; /* CBDV */
2698 #ifdef DEBUG_CLOCKS_LL
2699 printf("CBDV %01" PRIx32
" %d\n", (cpc
->pllmr
[0] >> 16) & 0x3, D
);
2701 PLB_clk
= CPU_clk
/ D
;
2702 D
= ((cpc
->pllmr
[0] >> 12) & 0x3) + 1; /* OPDV */
2703 #ifdef DEBUG_CLOCKS_LL
2704 printf("OPDV %01" PRIx32
" %d\n", (cpc
->pllmr
[0] >> 12) & 0x3, D
);
2706 OPB_clk
= PLB_clk
/ D
;
2707 D
= ((cpc
->pllmr
[0] >> 8) & 0x3) + 2; /* EPDV */
2708 #ifdef DEBUG_CLOCKS_LL
2709 printf("EPDV %01" PRIx32
" %d\n", (cpc
->pllmr
[0] >> 8) & 0x3, D
);
2711 EBC_clk
= PLB_clk
/ D
;
2712 D
= ((cpc
->pllmr
[0] >> 4) & 0x3) + 1; /* MPDV */
2713 #ifdef DEBUG_CLOCKS_LL
2714 printf("MPDV %01" PRIx32
" %d\n", (cpc
->pllmr
[0] >> 4) & 0x3, D
);
2716 MAL_clk
= PLB_clk
/ D
;
2717 D
= (cpc
->pllmr
[0] & 0x3) + 1; /* PPDV */
2718 #ifdef DEBUG_CLOCKS_LL
2719 printf("PPDV %01" PRIx32
" %d\n", cpc
->pllmr
[0] & 0x3, D
);
2721 PCI_clk
= PLB_clk
/ D
;
2722 D
= ((cpc
->ucr
- 1) & 0x7F) + 1; /* U0DIV */
2723 #ifdef DEBUG_CLOCKS_LL
2724 printf("U0DIV %01" PRIx32
" %d\n", cpc
->ucr
& 0x7F, D
);
2726 UART0_clk
= PLL_out
/ D
;
2727 D
= (((cpc
->ucr
>> 8) - 1) & 0x7F) + 1; /* U1DIV */
2728 #ifdef DEBUG_CLOCKS_LL
2729 printf("U1DIV %01" PRIx32
" %d\n", (cpc
->ucr
>> 8) & 0x7F, D
);
2731 UART1_clk
= PLL_out
/ D
;
2733 printf("Setup PPC405EP clocks - sysclk %" PRIu32
" VCO %" PRIu64
2734 " PLL out %" PRIu64
" Hz\n", cpc
->sysclk
, VCO_out
, PLL_out
);
2735 printf("CPU %" PRIu32
" PLB %" PRIu32
" OPB %" PRIu32
" EBC %" PRIu32
2736 " MAL %" PRIu32
" PCI %" PRIu32
" UART0 %" PRIu32
2737 " UART1 %" PRIu32
"\n",
2738 CPU_clk
, PLB_clk
, OPB_clk
, EBC_clk
, MAL_clk
, PCI_clk
,
2739 UART0_clk
, UART1_clk
);
2741 /* Setup CPU clocks */
2742 clk_setup(&cpc
->clk_setup
[PPC405EP_CPU_CLK
], CPU_clk
);
2743 /* Setup PLB clock */
2744 clk_setup(&cpc
->clk_setup
[PPC405EP_PLB_CLK
], PLB_clk
);
2745 /* Setup OPB clock */
2746 clk_setup(&cpc
->clk_setup
[PPC405EP_OPB_CLK
], OPB_clk
);
2747 /* Setup external clock */
2748 clk_setup(&cpc
->clk_setup
[PPC405EP_EBC_CLK
], EBC_clk
);
2749 /* Setup MAL clock */
2750 clk_setup(&cpc
->clk_setup
[PPC405EP_MAL_CLK
], MAL_clk
);
2751 /* Setup PCI clock */
2752 clk_setup(&cpc
->clk_setup
[PPC405EP_PCI_CLK
], PCI_clk
);
2753 /* Setup UART0 clock */
2754 clk_setup(&cpc
->clk_setup
[PPC405EP_UART0_CLK
], UART0_clk
);
2755 /* Setup UART1 clock */
2756 clk_setup(&cpc
->clk_setup
[PPC405EP_UART1_CLK
], UART1_clk
);
2759 static target_ulong
dcr_read_epcpc (void *opaque
, int dcrn
)
2761 ppc405ep_cpc_t
*cpc
;
2766 case PPC405EP_CPC0_BOOT
:
2769 case PPC405EP_CPC0_EPCTL
:
2772 case PPC405EP_CPC0_PLLMR0
:
2773 ret
= cpc
->pllmr
[0];
2775 case PPC405EP_CPC0_PLLMR1
:
2776 ret
= cpc
->pllmr
[1];
2778 case PPC405EP_CPC0_UCR
:
2781 case PPC405EP_CPC0_SRR
:
2784 case PPC405EP_CPC0_JTAGID
:
2787 case PPC405EP_CPC0_PCI
:
2791 /* Avoid gcc warning */
2799 static void dcr_write_epcpc (void *opaque
, int dcrn
, target_ulong val
)
2801 ppc405ep_cpc_t
*cpc
;
2805 case PPC405EP_CPC0_BOOT
:
2806 /* Read-only register */
2808 case PPC405EP_CPC0_EPCTL
:
2809 /* Don't care for now */
2810 cpc
->epctl
= val
& 0xC00000F3;
2812 case PPC405EP_CPC0_PLLMR0
:
2813 cpc
->pllmr
[0] = val
& 0x00633333;
2814 ppc405ep_compute_clocks(cpc
);
2816 case PPC405EP_CPC0_PLLMR1
:
2817 cpc
->pllmr
[1] = val
& 0xC0F73FFF;
2818 ppc405ep_compute_clocks(cpc
);
2820 case PPC405EP_CPC0_UCR
:
2821 /* UART control - don't care for now */
2822 cpc
->ucr
= val
& 0x003F7F7F;
2824 case PPC405EP_CPC0_SRR
:
2827 case PPC405EP_CPC0_JTAGID
:
2830 case PPC405EP_CPC0_PCI
:
2836 static void ppc405ep_cpc_reset (void *opaque
)
2838 ppc405ep_cpc_t
*cpc
= opaque
;
2840 cpc
->boot
= 0x00000010; /* Boot from PCI - IIC EEPROM disabled */
2841 cpc
->epctl
= 0x00000000;
2842 cpc
->pllmr
[0] = 0x00011010;
2843 cpc
->pllmr
[1] = 0x40000000;
2844 cpc
->ucr
= 0x00000000;
2845 cpc
->srr
= 0x00040000;
2846 cpc
->pci
= 0x00000000;
2847 cpc
->er
= 0x00000000;
2848 cpc
->fr
= 0x00000000;
2849 cpc
->sr
= 0x00000000;
2850 ppc405ep_compute_clocks(cpc
);
2853 /* XXX: sysclk should be between 25 and 100 MHz */
2854 static void ppc405ep_cpc_init (CPUState
*env
, clk_setup_t clk_setup
[8],
2857 ppc405ep_cpc_t
*cpc
;
2859 cpc
= qemu_mallocz(sizeof(ppc405ep_cpc_t
));
2861 memcpy(cpc
->clk_setup
, clk_setup
,
2862 PPC405EP_CLK_NB
* sizeof(clk_setup_t
));
2863 cpc
->jtagid
= 0x20267049;
2864 cpc
->sysclk
= sysclk
;
2865 ppc405ep_cpc_reset(cpc
);
2866 qemu_register_reset(&ppc405ep_cpc_reset
, cpc
);
2867 ppc_dcr_register(env
, PPC405EP_CPC0_BOOT
, cpc
,
2868 &dcr_read_epcpc
, &dcr_write_epcpc
);
2869 ppc_dcr_register(env
, PPC405EP_CPC0_EPCTL
, cpc
,
2870 &dcr_read_epcpc
, &dcr_write_epcpc
);
2871 ppc_dcr_register(env
, PPC405EP_CPC0_PLLMR0
, cpc
,
2872 &dcr_read_epcpc
, &dcr_write_epcpc
);
2873 ppc_dcr_register(env
, PPC405EP_CPC0_PLLMR1
, cpc
,
2874 &dcr_read_epcpc
, &dcr_write_epcpc
);
2875 ppc_dcr_register(env
, PPC405EP_CPC0_UCR
, cpc
,
2876 &dcr_read_epcpc
, &dcr_write_epcpc
);
2877 ppc_dcr_register(env
, PPC405EP_CPC0_SRR
, cpc
,
2878 &dcr_read_epcpc
, &dcr_write_epcpc
);
2879 ppc_dcr_register(env
, PPC405EP_CPC0_JTAGID
, cpc
,
2880 &dcr_read_epcpc
, &dcr_write_epcpc
);
2881 ppc_dcr_register(env
, PPC405EP_CPC0_PCI
, cpc
,
2882 &dcr_read_epcpc
, &dcr_write_epcpc
);
2884 ppc_dcr_register(env
, PPC405EP_CPC0_ER
, cpc
,
2885 &dcr_read_epcpc
, &dcr_write_epcpc
);
2886 ppc_dcr_register(env
, PPC405EP_CPC0_FR
, cpc
,
2887 &dcr_read_epcpc
, &dcr_write_epcpc
);
2888 ppc_dcr_register(env
, PPC405EP_CPC0_SR
, cpc
,
2889 &dcr_read_epcpc
, &dcr_write_epcpc
);
2894 CPUState
*ppc405ep_init (target_phys_addr_t ram_bases
[2],
2895 target_phys_addr_t ram_sizes
[2],
2896 uint32_t sysclk
, qemu_irq
**picp
,
2897 ram_addr_t
*offsetp
, int do_init
)
2899 clk_setup_t clk_setup
[PPC405EP_CLK_NB
], tlb_clk_setup
;
2900 qemu_irq dma_irqs
[4], gpt_irqs
[5], mal_irqs
[4];
2902 ppc4xx_mmio_t
*mmio
;
2903 qemu_irq
*pic
, *irqs
;
2907 memset(clk_setup
, 0, sizeof(clk_setup
));
2909 env
= ppc4xx_init("405ep", &clk_setup
[PPC405EP_CPU_CLK
],
2910 &tlb_clk_setup
, sysclk
);
2911 clk_setup
[PPC405EP_CPU_CLK
].cb
= tlb_clk_setup
.cb
;
2912 clk_setup
[PPC405EP_CPU_CLK
].opaque
= tlb_clk_setup
.opaque
;
2913 /* Internal devices init */
2914 /* Memory mapped devices registers */
2915 mmio
= ppc4xx_mmio_init(env
, 0xEF600000);
2917 ppc4xx_plb_init(env
);
2918 /* PLB to OPB bridge */
2919 ppc4xx_pob_init(env
);
2921 ppc4xx_opba_init(env
, mmio
, 0x600);
2922 /* Universal interrupt controller */
2923 irqs
= qemu_mallocz(sizeof(qemu_irq
) * PPCUIC_OUTPUT_NB
);
2924 irqs
[PPCUIC_OUTPUT_INT
] =
2925 ((qemu_irq
*)env
->irq_inputs
)[PPC40x_INPUT_INT
];
2926 irqs
[PPCUIC_OUTPUT_CINT
] =
2927 ((qemu_irq
*)env
->irq_inputs
)[PPC40x_INPUT_CINT
];
2928 pic
= ppcuic_init(env
, irqs
, 0x0C0, 0, 1);
2930 /* SDRAM controller */
2931 /* XXX 405EP has no ECC interrupt */
2932 ppc405_sdram_init(env
, pic
[17], 2, ram_bases
, ram_sizes
, do_init
);
2934 for (i
= 0; i
< 2; i
++)
2935 offset
+= ram_sizes
[i
];
2936 /* External bus controller */
2937 ppc405_ebc_init(env
);
2938 /* DMA controller */
2939 dma_irqs
[0] = pic
[5];
2940 dma_irqs
[1] = pic
[6];
2941 dma_irqs
[2] = pic
[7];
2942 dma_irqs
[3] = pic
[8];
2943 ppc405_dma_init(env
, dma_irqs
);
2944 /* IIC controller */
2945 ppc405_i2c_init(env
, mmio
, 0x500, pic
[2]);
2947 ppc405_gpio_init(env
, mmio
, 0x700);
2949 if (serial_hds
[0] != NULL
) {
2950 ppc405_serial_init(env
, mmio
, 0x300, pic
[0], serial_hds
[0]);
2952 if (serial_hds
[1] != NULL
) {
2953 ppc405_serial_init(env
, mmio
, 0x400, pic
[1], serial_hds
[1]);
2956 ppc405_ocm_init(env
, ram_sizes
[0] + ram_sizes
[1]);
2959 gpt_irqs
[0] = pic
[19];
2960 gpt_irqs
[1] = pic
[20];
2961 gpt_irqs
[2] = pic
[21];
2962 gpt_irqs
[3] = pic
[22];
2963 gpt_irqs
[4] = pic
[23];
2964 ppc4xx_gpt_init(env
, mmio
, 0x000, gpt_irqs
);
2966 /* Uses pic[3], pic[16], pic[18] */
2968 mal_irqs
[0] = pic
[11];
2969 mal_irqs
[1] = pic
[12];
2970 mal_irqs
[2] = pic
[13];
2971 mal_irqs
[3] = pic
[14];
2972 ppc405_mal_init(env
, mal_irqs
);
2974 /* Uses pic[9], pic[15], pic[17] */
2976 ppc405ep_cpc_init(env
, clk_setup
, sysclk
);