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"
43 //#define DEBUG_CLOCKS_LL
45 ram_addr_t
ppc405_set_bootinfo (CPUState
*env
, ppc4xx_bd_info_t
*bd
,
51 /* We put the bd structure at the top of memory */
52 if (bd
->bi_memsize
>= 0x01000000UL
)
53 bdloc
= 0x01000000UL
- sizeof(struct ppc4xx_bd_info_t
);
55 bdloc
= bd
->bi_memsize
- sizeof(struct ppc4xx_bd_info_t
);
56 stl_raw(phys_ram_base
+ bdloc
+ 0x00, bd
->bi_memstart
);
57 stl_raw(phys_ram_base
+ bdloc
+ 0x04, bd
->bi_memsize
);
58 stl_raw(phys_ram_base
+ bdloc
+ 0x08, bd
->bi_flashstart
);
59 stl_raw(phys_ram_base
+ bdloc
+ 0x0C, bd
->bi_flashsize
);
60 stl_raw(phys_ram_base
+ bdloc
+ 0x10, bd
->bi_flashoffset
);
61 stl_raw(phys_ram_base
+ bdloc
+ 0x14, bd
->bi_sramstart
);
62 stl_raw(phys_ram_base
+ bdloc
+ 0x18, bd
->bi_sramsize
);
63 stl_raw(phys_ram_base
+ bdloc
+ 0x1C, bd
->bi_bootflags
);
64 stl_raw(phys_ram_base
+ bdloc
+ 0x20, bd
->bi_ipaddr
);
65 for (i
= 0; i
< 6; i
++)
66 stb_raw(phys_ram_base
+ bdloc
+ 0x24 + i
, bd
->bi_enetaddr
[i
]);
67 stw_raw(phys_ram_base
+ bdloc
+ 0x2A, bd
->bi_ethspeed
);
68 stl_raw(phys_ram_base
+ bdloc
+ 0x2C, bd
->bi_intfreq
);
69 stl_raw(phys_ram_base
+ bdloc
+ 0x30, bd
->bi_busfreq
);
70 stl_raw(phys_ram_base
+ bdloc
+ 0x34, bd
->bi_baudrate
);
71 for (i
= 0; i
< 4; i
++)
72 stb_raw(phys_ram_base
+ bdloc
+ 0x38 + i
, bd
->bi_s_version
[i
]);
73 for (i
= 0; i
< 32; i
++)
74 stb_raw(phys_ram_base
+ bdloc
+ 0x3C + i
, bd
->bi_s_version
[i
]);
75 stl_raw(phys_ram_base
+ bdloc
+ 0x5C, bd
->bi_plb_busfreq
);
76 stl_raw(phys_ram_base
+ bdloc
+ 0x60, bd
->bi_pci_busfreq
);
77 for (i
= 0; i
< 6; i
++)
78 stb_raw(phys_ram_base
+ bdloc
+ 0x64 + i
, bd
->bi_pci_enetaddr
[i
]);
80 if (flags
& 0x00000001) {
81 for (i
= 0; i
< 6; i
++)
82 stb_raw(phys_ram_base
+ bdloc
+ n
++, bd
->bi_pci_enetaddr2
[i
]);
84 stl_raw(phys_ram_base
+ bdloc
+ n
, bd
->bi_opbfreq
);
86 for (i
= 0; i
< 2; i
++) {
87 stl_raw(phys_ram_base
+ bdloc
+ n
, bd
->bi_iic_fast
[i
]);
94 /*****************************************************************************/
95 /* Shared peripherals */
97 /*****************************************************************************/
98 /* Peripheral local bus arbitrer */
105 typedef struct ppc4xx_plb_t ppc4xx_plb_t
;
106 struct ppc4xx_plb_t
{
112 static target_ulong
dcr_read_plb (void *opaque
, int dcrn
)
129 /* Avoid gcc warning */
137 static void dcr_write_plb (void *opaque
, int dcrn
, target_ulong val
)
144 /* We don't care about the actual parameters written as
145 * we don't manage any priorities on the bus
147 plb
->acr
= val
& 0xF8000000;
159 static void ppc4xx_plb_reset (void *opaque
)
164 plb
->acr
= 0x00000000;
165 plb
->bear
= 0x00000000;
166 plb
->besr
= 0x00000000;
169 void ppc4xx_plb_init (CPUState
*env
)
173 plb
= qemu_mallocz(sizeof(ppc4xx_plb_t
));
175 ppc_dcr_register(env
, PLB0_ACR
, plb
, &dcr_read_plb
, &dcr_write_plb
);
176 ppc_dcr_register(env
, PLB0_BEAR
, plb
, &dcr_read_plb
, &dcr_write_plb
);
177 ppc_dcr_register(env
, PLB0_BESR
, plb
, &dcr_read_plb
, &dcr_write_plb
);
178 ppc4xx_plb_reset(plb
);
179 qemu_register_reset(ppc4xx_plb_reset
, plb
);
183 /*****************************************************************************/
184 /* PLB to OPB bridge */
191 typedef struct ppc4xx_pob_t ppc4xx_pob_t
;
192 struct ppc4xx_pob_t
{
197 static target_ulong
dcr_read_pob (void *opaque
, int dcrn
)
209 ret
= pob
->besr
[dcrn
- POB0_BESR0
];
212 /* Avoid gcc warning */
220 static void dcr_write_pob (void *opaque
, int dcrn
, target_ulong val
)
232 pob
->besr
[dcrn
- POB0_BESR0
] &= ~val
;
237 static void ppc4xx_pob_reset (void *opaque
)
243 pob
->bear
= 0x00000000;
244 pob
->besr
[0] = 0x0000000;
245 pob
->besr
[1] = 0x0000000;
248 void ppc4xx_pob_init (CPUState
*env
)
252 pob
= qemu_mallocz(sizeof(ppc4xx_pob_t
));
254 ppc_dcr_register(env
, POB0_BEAR
, pob
, &dcr_read_pob
, &dcr_write_pob
);
255 ppc_dcr_register(env
, POB0_BESR0
, pob
, &dcr_read_pob
, &dcr_write_pob
);
256 ppc_dcr_register(env
, POB0_BESR1
, pob
, &dcr_read_pob
, &dcr_write_pob
);
257 qemu_register_reset(ppc4xx_pob_reset
, pob
);
258 ppc4xx_pob_reset(env
);
262 /*****************************************************************************/
264 typedef struct ppc4xx_opba_t ppc4xx_opba_t
;
265 struct ppc4xx_opba_t
{
266 target_phys_addr_t base
;
271 static uint32_t opba_readb (void *opaque
, target_phys_addr_t addr
)
277 printf("%s: addr " PADDRX
"\n", __func__
, addr
);
280 switch (addr
- opba
->base
) {
295 static void opba_writeb (void *opaque
,
296 target_phys_addr_t addr
, uint32_t value
)
301 printf("%s: addr " PADDRX
" val %08" PRIx32
"\n", __func__
, addr
, value
);
304 switch (addr
- opba
->base
) {
306 opba
->cr
= value
& 0xF8;
309 opba
->pr
= value
& 0xFF;
316 static uint32_t opba_readw (void *opaque
, target_phys_addr_t addr
)
321 printf("%s: addr " PADDRX
"\n", __func__
, addr
);
323 ret
= opba_readb(opaque
, addr
) << 8;
324 ret
|= opba_readb(opaque
, addr
+ 1);
329 static void opba_writew (void *opaque
,
330 target_phys_addr_t addr
, uint32_t value
)
333 printf("%s: addr " PADDRX
" val %08" PRIx32
"\n", __func__
, addr
, value
);
335 opba_writeb(opaque
, addr
, value
>> 8);
336 opba_writeb(opaque
, addr
+ 1, value
);
339 static uint32_t opba_readl (void *opaque
, target_phys_addr_t addr
)
344 printf("%s: addr " PADDRX
"\n", __func__
, addr
);
346 ret
= opba_readb(opaque
, addr
) << 24;
347 ret
|= opba_readb(opaque
, addr
+ 1) << 16;
352 static void opba_writel (void *opaque
,
353 target_phys_addr_t addr
, uint32_t value
)
356 printf("%s: addr " PADDRX
" val %08" PRIx32
"\n", __func__
, addr
, value
);
358 opba_writeb(opaque
, addr
, value
>> 24);
359 opba_writeb(opaque
, addr
+ 1, value
>> 16);
362 static CPUReadMemoryFunc
*opba_read
[] = {
368 static CPUWriteMemoryFunc
*opba_write
[] = {
374 static void ppc4xx_opba_reset (void *opaque
)
379 opba
->cr
= 0x00; /* No dynamic priorities - park disabled */
383 void ppc4xx_opba_init (CPUState
*env
, ppc4xx_mmio_t
*mmio
,
384 target_phys_addr_t offset
)
388 opba
= qemu_mallocz(sizeof(ppc4xx_opba_t
));
392 printf("%s: offset " PADDRX
"\n", __func__
, offset
);
394 ppc4xx_mmio_register(env
, mmio
, offset
, 0x002,
395 opba_read
, opba_write
, opba
);
396 qemu_register_reset(ppc4xx_opba_reset
, opba
);
397 ppc4xx_opba_reset(opba
);
401 /*****************************************************************************/
402 /* Code decompression controller */
405 /*****************************************************************************/
406 /* SDRAM controller */
407 typedef struct ppc4xx_sdram_t ppc4xx_sdram_t
;
408 struct ppc4xx_sdram_t
{
411 target_phys_addr_t ram_bases
[4];
412 target_phys_addr_t ram_sizes
[4];
428 SDRAM0_CFGADDR
= 0x010,
429 SDRAM0_CFGDATA
= 0x011,
432 /* XXX: TOFIX: some patches have made this code become inconsistent:
433 * there are type inconsistencies, mixing target_phys_addr_t, target_ulong
436 static uint32_t sdram_bcr (target_phys_addr_t ram_base
,
437 target_phys_addr_t ram_size
)
442 case (4 * 1024 * 1024):
445 case (8 * 1024 * 1024):
448 case (16 * 1024 * 1024):
451 case (32 * 1024 * 1024):
454 case (64 * 1024 * 1024):
457 case (128 * 1024 * 1024):
460 case (256 * 1024 * 1024):
464 printf("%s: invalid RAM size " PADDRX
"\n", __func__
, ram_size
);
467 bcr
|= ram_base
& 0xFF800000;
473 static always_inline target_phys_addr_t
sdram_base (uint32_t bcr
)
475 return bcr
& 0xFF800000;
478 static target_ulong
sdram_size (uint32_t bcr
)
483 sh
= (bcr
>> 17) & 0x7;
487 size
= (4 * 1024 * 1024) << sh
;
492 static void sdram_set_bcr (uint32_t *bcrp
, uint32_t bcr
, int enabled
)
494 if (*bcrp
& 0x00000001) {
497 printf("%s: unmap RAM area " PADDRX
" " ADDRX
"\n",
498 __func__
, sdram_base(*bcrp
), sdram_size(*bcrp
));
500 cpu_register_physical_memory(sdram_base(*bcrp
), sdram_size(*bcrp
),
503 *bcrp
= bcr
& 0xFFDEE001;
504 if (enabled
&& (bcr
& 0x00000001)) {
506 printf("%s: Map RAM area " PADDRX
" " ADDRX
"\n",
507 __func__
, sdram_base(bcr
), sdram_size(bcr
));
509 cpu_register_physical_memory(sdram_base(bcr
), sdram_size(bcr
),
510 sdram_base(bcr
) | IO_MEM_RAM
);
514 static void sdram_map_bcr (ppc4xx_sdram_t
*sdram
)
518 for (i
= 0; i
< sdram
->nbanks
; i
++) {
519 if (sdram
->ram_sizes
[i
] != 0) {
520 sdram_set_bcr(&sdram
->bcr
[i
],
521 sdram_bcr(sdram
->ram_bases
[i
], sdram
->ram_sizes
[i
]),
524 sdram_set_bcr(&sdram
->bcr
[i
], 0x00000000, 0);
529 static void sdram_unmap_bcr (ppc4xx_sdram_t
*sdram
)
533 for (i
= 0; i
< sdram
->nbanks
; i
++) {
535 printf("%s: Unmap RAM area " PADDRX
" " ADDRX
"\n",
536 __func__
, sdram_base(sdram
->bcr
[i
]), sdram_size(sdram
->bcr
[i
]));
538 cpu_register_physical_memory(sdram_base(sdram
->bcr
[i
]),
539 sdram_size(sdram
->bcr
[i
]),
544 static target_ulong
dcr_read_sdram (void *opaque
, int dcrn
)
546 ppc4xx_sdram_t
*sdram
;
555 switch (sdram
->addr
) {
556 case 0x00: /* SDRAM_BESR0 */
559 case 0x08: /* SDRAM_BESR1 */
562 case 0x10: /* SDRAM_BEAR */
565 case 0x20: /* SDRAM_CFG */
568 case 0x24: /* SDRAM_STATUS */
571 case 0x30: /* SDRAM_RTR */
574 case 0x34: /* SDRAM_PMIT */
577 case 0x40: /* SDRAM_B0CR */
580 case 0x44: /* SDRAM_B1CR */
583 case 0x48: /* SDRAM_B2CR */
586 case 0x4C: /* SDRAM_B3CR */
589 case 0x80: /* SDRAM_TR */
592 case 0x94: /* SDRAM_ECCCFG */
595 case 0x98: /* SDRAM_ECCESR */
604 /* Avoid gcc warning */
612 static void dcr_write_sdram (void *opaque
, int dcrn
, target_ulong val
)
614 ppc4xx_sdram_t
*sdram
;
622 switch (sdram
->addr
) {
623 case 0x00: /* SDRAM_BESR0 */
624 sdram
->besr0
&= ~val
;
626 case 0x08: /* SDRAM_BESR1 */
627 sdram
->besr1
&= ~val
;
629 case 0x10: /* SDRAM_BEAR */
632 case 0x20: /* SDRAM_CFG */
634 if (!(sdram
->cfg
& 0x80000000) && (val
& 0x80000000)) {
636 printf("%s: enable SDRAM controller\n", __func__
);
638 /* validate all RAM mappings */
639 sdram_map_bcr(sdram
);
640 sdram
->status
&= ~0x80000000;
641 } else if ((sdram
->cfg
& 0x80000000) && !(val
& 0x80000000)) {
643 printf("%s: disable SDRAM controller\n", __func__
);
645 /* invalidate all RAM mappings */
646 sdram_unmap_bcr(sdram
);
647 sdram
->status
|= 0x80000000;
649 if (!(sdram
->cfg
& 0x40000000) && (val
& 0x40000000))
650 sdram
->status
|= 0x40000000;
651 else if ((sdram
->cfg
& 0x40000000) && !(val
& 0x40000000))
652 sdram
->status
&= ~0x40000000;
655 case 0x24: /* SDRAM_STATUS */
656 /* Read-only register */
658 case 0x30: /* SDRAM_RTR */
659 sdram
->rtr
= val
& 0x3FF80000;
661 case 0x34: /* SDRAM_PMIT */
662 sdram
->pmit
= (val
& 0xF8000000) | 0x07C00000;
664 case 0x40: /* SDRAM_B0CR */
665 sdram_set_bcr(&sdram
->bcr
[0], val
, sdram
->cfg
& 0x80000000);
667 case 0x44: /* SDRAM_B1CR */
668 sdram_set_bcr(&sdram
->bcr
[1], val
, sdram
->cfg
& 0x80000000);
670 case 0x48: /* SDRAM_B2CR */
671 sdram_set_bcr(&sdram
->bcr
[2], val
, sdram
->cfg
& 0x80000000);
673 case 0x4C: /* SDRAM_B3CR */
674 sdram_set_bcr(&sdram
->bcr
[3], val
, sdram
->cfg
& 0x80000000);
676 case 0x80: /* SDRAM_TR */
677 sdram
->tr
= val
& 0x018FC01F;
679 case 0x94: /* SDRAM_ECCCFG */
680 sdram
->ecccfg
= val
& 0x00F00000;
682 case 0x98: /* SDRAM_ECCESR */
684 if (sdram
->eccesr
== 0 && val
!= 0)
685 qemu_irq_raise(sdram
->irq
);
686 else if (sdram
->eccesr
!= 0 && val
== 0)
687 qemu_irq_lower(sdram
->irq
);
697 static void sdram_reset (void *opaque
)
699 ppc4xx_sdram_t
*sdram
;
702 sdram
->addr
= 0x00000000;
703 sdram
->bear
= 0x00000000;
704 sdram
->besr0
= 0x00000000; /* No error */
705 sdram
->besr1
= 0x00000000; /* No error */
706 sdram
->cfg
= 0x00000000;
707 sdram
->ecccfg
= 0x00000000; /* No ECC */
708 sdram
->eccesr
= 0x00000000; /* No error */
709 sdram
->pmit
= 0x07C00000;
710 sdram
->rtr
= 0x05F00000;
711 sdram
->tr
= 0x00854009;
712 /* We pre-initialize RAM banks */
713 sdram
->status
= 0x00000000;
714 sdram
->cfg
= 0x00800000;
715 sdram_unmap_bcr(sdram
);
718 void ppc405_sdram_init (CPUState
*env
, qemu_irq irq
, int nbanks
,
719 target_phys_addr_t
*ram_bases
,
720 target_phys_addr_t
*ram_sizes
,
723 ppc4xx_sdram_t
*sdram
;
725 sdram
= qemu_mallocz(sizeof(ppc4xx_sdram_t
));
728 sdram
->nbanks
= nbanks
;
729 memset(sdram
->ram_bases
, 0, 4 * sizeof(target_phys_addr_t
));
730 memcpy(sdram
->ram_bases
, ram_bases
,
731 nbanks
* sizeof(target_phys_addr_t
));
732 memset(sdram
->ram_sizes
, 0, 4 * sizeof(target_phys_addr_t
));
733 memcpy(sdram
->ram_sizes
, ram_sizes
,
734 nbanks
* sizeof(target_phys_addr_t
));
736 qemu_register_reset(&sdram_reset
, sdram
);
737 ppc_dcr_register(env
, SDRAM0_CFGADDR
,
738 sdram
, &dcr_read_sdram
, &dcr_write_sdram
);
739 ppc_dcr_register(env
, SDRAM0_CFGDATA
,
740 sdram
, &dcr_read_sdram
, &dcr_write_sdram
);
742 sdram_map_bcr(sdram
);
746 /*****************************************************************************/
747 /* Peripheral controller */
748 typedef struct ppc4xx_ebc_t ppc4xx_ebc_t
;
749 struct ppc4xx_ebc_t
{
760 EBC0_CFGADDR
= 0x012,
761 EBC0_CFGDATA
= 0x013,
764 static target_ulong
dcr_read_ebc (void *opaque
, int dcrn
)
776 case 0x00: /* B0CR */
779 case 0x01: /* B1CR */
782 case 0x02: /* B2CR */
785 case 0x03: /* B3CR */
788 case 0x04: /* B4CR */
791 case 0x05: /* B5CR */
794 case 0x06: /* B6CR */
797 case 0x07: /* B7CR */
800 case 0x10: /* B0AP */
803 case 0x11: /* B1AP */
806 case 0x12: /* B2AP */
809 case 0x13: /* B3AP */
812 case 0x14: /* B4AP */
815 case 0x15: /* B5AP */
818 case 0x16: /* B6AP */
821 case 0x17: /* B7AP */
824 case 0x20: /* BEAR */
827 case 0x21: /* BESR0 */
830 case 0x22: /* BESR1 */
848 static void dcr_write_ebc (void *opaque
, int dcrn
, target_ulong val
)
859 case 0x00: /* B0CR */
861 case 0x01: /* B1CR */
863 case 0x02: /* B2CR */
865 case 0x03: /* B3CR */
867 case 0x04: /* B4CR */
869 case 0x05: /* B5CR */
871 case 0x06: /* B6CR */
873 case 0x07: /* B7CR */
875 case 0x10: /* B0AP */
877 case 0x11: /* B1AP */
879 case 0x12: /* B2AP */
881 case 0x13: /* B3AP */
883 case 0x14: /* B4AP */
885 case 0x15: /* B5AP */
887 case 0x16: /* B6AP */
889 case 0x17: /* B7AP */
891 case 0x20: /* BEAR */
893 case 0x21: /* BESR0 */
895 case 0x22: /* BESR1 */
908 static void ebc_reset (void *opaque
)
914 ebc
->addr
= 0x00000000;
915 ebc
->bap
[0] = 0x7F8FFE80;
916 ebc
->bcr
[0] = 0xFFE28000;
917 for (i
= 0; i
< 8; i
++) {
918 ebc
->bap
[i
] = 0x00000000;
919 ebc
->bcr
[i
] = 0x00000000;
921 ebc
->besr0
= 0x00000000;
922 ebc
->besr1
= 0x00000000;
923 ebc
->cfg
= 0x80400000;
926 void ppc405_ebc_init (CPUState
*env
)
930 ebc
= qemu_mallocz(sizeof(ppc4xx_ebc_t
));
933 qemu_register_reset(&ebc_reset
, ebc
);
934 ppc_dcr_register(env
, EBC0_CFGADDR
,
935 ebc
, &dcr_read_ebc
, &dcr_write_ebc
);
936 ppc_dcr_register(env
, EBC0_CFGDATA
,
937 ebc
, &dcr_read_ebc
, &dcr_write_ebc
);
941 /*****************************************************************************/
970 typedef struct ppc405_dma_t ppc405_dma_t
;
971 struct ppc405_dma_t
{
984 static target_ulong
dcr_read_dma (void *opaque
, int dcrn
)
993 static void dcr_write_dma (void *opaque
, int dcrn
, target_ulong val
)
1000 static void ppc405_dma_reset (void *opaque
)
1006 for (i
= 0; i
< 4; i
++) {
1007 dma
->cr
[i
] = 0x00000000;
1008 dma
->ct
[i
] = 0x00000000;
1009 dma
->da
[i
] = 0x00000000;
1010 dma
->sa
[i
] = 0x00000000;
1011 dma
->sg
[i
] = 0x00000000;
1013 dma
->sr
= 0x00000000;
1014 dma
->sgc
= 0x00000000;
1015 dma
->slp
= 0x7C000000;
1016 dma
->pol
= 0x00000000;
1019 void ppc405_dma_init (CPUState
*env
, qemu_irq irqs
[4])
1023 dma
= qemu_mallocz(sizeof(ppc405_dma_t
));
1025 memcpy(dma
->irqs
, irqs
, 4 * sizeof(qemu_irq
));
1026 ppc405_dma_reset(dma
);
1027 qemu_register_reset(&ppc405_dma_reset
, dma
);
1028 ppc_dcr_register(env
, DMA0_CR0
,
1029 dma
, &dcr_read_dma
, &dcr_write_dma
);
1030 ppc_dcr_register(env
, DMA0_CT0
,
1031 dma
, &dcr_read_dma
, &dcr_write_dma
);
1032 ppc_dcr_register(env
, DMA0_DA0
,
1033 dma
, &dcr_read_dma
, &dcr_write_dma
);
1034 ppc_dcr_register(env
, DMA0_SA0
,
1035 dma
, &dcr_read_dma
, &dcr_write_dma
);
1036 ppc_dcr_register(env
, DMA0_SG0
,
1037 dma
, &dcr_read_dma
, &dcr_write_dma
);
1038 ppc_dcr_register(env
, DMA0_CR1
,
1039 dma
, &dcr_read_dma
, &dcr_write_dma
);
1040 ppc_dcr_register(env
, DMA0_CT1
,
1041 dma
, &dcr_read_dma
, &dcr_write_dma
);
1042 ppc_dcr_register(env
, DMA0_DA1
,
1043 dma
, &dcr_read_dma
, &dcr_write_dma
);
1044 ppc_dcr_register(env
, DMA0_SA1
,
1045 dma
, &dcr_read_dma
, &dcr_write_dma
);
1046 ppc_dcr_register(env
, DMA0_SG1
,
1047 dma
, &dcr_read_dma
, &dcr_write_dma
);
1048 ppc_dcr_register(env
, DMA0_CR2
,
1049 dma
, &dcr_read_dma
, &dcr_write_dma
);
1050 ppc_dcr_register(env
, DMA0_CT2
,
1051 dma
, &dcr_read_dma
, &dcr_write_dma
);
1052 ppc_dcr_register(env
, DMA0_DA2
,
1053 dma
, &dcr_read_dma
, &dcr_write_dma
);
1054 ppc_dcr_register(env
, DMA0_SA2
,
1055 dma
, &dcr_read_dma
, &dcr_write_dma
);
1056 ppc_dcr_register(env
, DMA0_SG2
,
1057 dma
, &dcr_read_dma
, &dcr_write_dma
);
1058 ppc_dcr_register(env
, DMA0_CR3
,
1059 dma
, &dcr_read_dma
, &dcr_write_dma
);
1060 ppc_dcr_register(env
, DMA0_CT3
,
1061 dma
, &dcr_read_dma
, &dcr_write_dma
);
1062 ppc_dcr_register(env
, DMA0_DA3
,
1063 dma
, &dcr_read_dma
, &dcr_write_dma
);
1064 ppc_dcr_register(env
, DMA0_SA3
,
1065 dma
, &dcr_read_dma
, &dcr_write_dma
);
1066 ppc_dcr_register(env
, DMA0_SG3
,
1067 dma
, &dcr_read_dma
, &dcr_write_dma
);
1068 ppc_dcr_register(env
, DMA0_SR
,
1069 dma
, &dcr_read_dma
, &dcr_write_dma
);
1070 ppc_dcr_register(env
, DMA0_SGC
,
1071 dma
, &dcr_read_dma
, &dcr_write_dma
);
1072 ppc_dcr_register(env
, DMA0_SLP
,
1073 dma
, &dcr_read_dma
, &dcr_write_dma
);
1074 ppc_dcr_register(env
, DMA0_POL
,
1075 dma
, &dcr_read_dma
, &dcr_write_dma
);
1079 /*****************************************************************************/
1081 typedef struct ppc405_gpio_t ppc405_gpio_t
;
1082 struct ppc405_gpio_t
{
1083 target_phys_addr_t base
;
1097 static uint32_t ppc405_gpio_readb (void *opaque
, target_phys_addr_t addr
)
1099 ppc405_gpio_t
*gpio
;
1103 printf("%s: addr " PADDRX
"\n", __func__
, addr
);
1109 static void ppc405_gpio_writeb (void *opaque
,
1110 target_phys_addr_t addr
, uint32_t value
)
1112 ppc405_gpio_t
*gpio
;
1116 printf("%s: addr " PADDRX
" val %08" PRIx32
"\n", __func__
, addr
, value
);
1120 static uint32_t ppc405_gpio_readw (void *opaque
, target_phys_addr_t addr
)
1122 ppc405_gpio_t
*gpio
;
1126 printf("%s: addr " PADDRX
"\n", __func__
, addr
);
1132 static void ppc405_gpio_writew (void *opaque
,
1133 target_phys_addr_t addr
, uint32_t value
)
1135 ppc405_gpio_t
*gpio
;
1139 printf("%s: addr " PADDRX
" val %08" PRIx32
"\n", __func__
, addr
, value
);
1143 static uint32_t ppc405_gpio_readl (void *opaque
, target_phys_addr_t addr
)
1145 ppc405_gpio_t
*gpio
;
1149 printf("%s: addr " PADDRX
"\n", __func__
, addr
);
1155 static void ppc405_gpio_writel (void *opaque
,
1156 target_phys_addr_t addr
, uint32_t value
)
1158 ppc405_gpio_t
*gpio
;
1162 printf("%s: addr " PADDRX
" val %08" PRIx32
"\n", __func__
, addr
, value
);
1166 static CPUReadMemoryFunc
*ppc405_gpio_read
[] = {
1172 static CPUWriteMemoryFunc
*ppc405_gpio_write
[] = {
1173 &ppc405_gpio_writeb
,
1174 &ppc405_gpio_writew
,
1175 &ppc405_gpio_writel
,
1178 static void ppc405_gpio_reset (void *opaque
)
1180 ppc405_gpio_t
*gpio
;
1185 void ppc405_gpio_init (CPUState
*env
, ppc4xx_mmio_t
*mmio
,
1186 target_phys_addr_t offset
)
1188 ppc405_gpio_t
*gpio
;
1190 gpio
= qemu_mallocz(sizeof(ppc405_gpio_t
));
1192 gpio
->base
= offset
;
1193 ppc405_gpio_reset(gpio
);
1194 qemu_register_reset(&ppc405_gpio_reset
, gpio
);
1196 printf("%s: offset " PADDRX
"\n", __func__
, offset
);
1198 ppc4xx_mmio_register(env
, mmio
, offset
, 0x038,
1199 ppc405_gpio_read
, ppc405_gpio_write
, gpio
);
1203 /*****************************************************************************/
1205 static CPUReadMemoryFunc
*serial_mm_read
[] = {
1211 static CPUWriteMemoryFunc
*serial_mm_write
[] = {
1217 void ppc405_serial_init (CPUState
*env
, ppc4xx_mmio_t
*mmio
,
1218 target_phys_addr_t offset
, qemu_irq irq
,
1219 CharDriverState
*chr
)
1224 printf("%s: offset " PADDRX
"\n", __func__
, offset
);
1226 serial
= serial_mm_init(offset
, 0, irq
, 399193, chr
, 0);
1227 ppc4xx_mmio_register(env
, mmio
, offset
, 0x008,
1228 serial_mm_read
, serial_mm_write
, serial
);
1231 /*****************************************************************************/
1232 /* On Chip Memory */
1235 OCM0_ISACNTL
= 0x019,
1237 OCM0_DSACNTL
= 0x01B,
1240 typedef struct ppc405_ocm_t ppc405_ocm_t
;
1241 struct ppc405_ocm_t
{
1242 target_ulong offset
;
1249 static void ocm_update_mappings (ppc405_ocm_t
*ocm
,
1250 uint32_t isarc
, uint32_t isacntl
,
1251 uint32_t dsarc
, uint32_t dsacntl
)
1254 printf("OCM update ISA %08" PRIx32
" %08" PRIx32
" (%08" PRIx32
1255 " %08" PRIx32
") DSA %08" PRIx32
" %08" PRIx32
1256 " (%08" PRIx32
" %08" PRIx32
")\n",
1257 isarc
, isacntl
, dsarc
, dsacntl
,
1258 ocm
->isarc
, ocm
->isacntl
, ocm
->dsarc
, ocm
->dsacntl
);
1260 if (ocm
->isarc
!= isarc
||
1261 (ocm
->isacntl
& 0x80000000) != (isacntl
& 0x80000000)) {
1262 if (ocm
->isacntl
& 0x80000000) {
1263 /* Unmap previously assigned memory region */
1264 printf("OCM unmap ISA %08" PRIx32
"\n", ocm
->isarc
);
1265 cpu_register_physical_memory(ocm
->isarc
, 0x04000000,
1268 if (isacntl
& 0x80000000) {
1269 /* Map new instruction memory region */
1271 printf("OCM map ISA %08" PRIx32
"\n", isarc
);
1273 cpu_register_physical_memory(isarc
, 0x04000000,
1274 ocm
->offset
| IO_MEM_RAM
);
1277 if (ocm
->dsarc
!= dsarc
||
1278 (ocm
->dsacntl
& 0x80000000) != (dsacntl
& 0x80000000)) {
1279 if (ocm
->dsacntl
& 0x80000000) {
1280 /* Beware not to unmap the region we just mapped */
1281 if (!(isacntl
& 0x80000000) || ocm
->dsarc
!= isarc
) {
1282 /* Unmap previously assigned memory region */
1284 printf("OCM unmap DSA %08" PRIx32
"\n", ocm
->dsarc
);
1286 cpu_register_physical_memory(ocm
->dsarc
, 0x04000000,
1290 if (dsacntl
& 0x80000000) {
1291 /* Beware not to remap the region we just mapped */
1292 if (!(isacntl
& 0x80000000) || dsarc
!= isarc
) {
1293 /* Map new data memory region */
1295 printf("OCM map DSA %08" PRIx32
"\n", dsarc
);
1297 cpu_register_physical_memory(dsarc
, 0x04000000,
1298 ocm
->offset
| IO_MEM_RAM
);
1304 static target_ulong
dcr_read_ocm (void *opaque
, int dcrn
)
1331 static void dcr_write_ocm (void *opaque
, int dcrn
, target_ulong val
)
1334 uint32_t isarc
, dsarc
, isacntl
, dsacntl
;
1339 isacntl
= ocm
->isacntl
;
1340 dsacntl
= ocm
->dsacntl
;
1343 isarc
= val
& 0xFC000000;
1346 isacntl
= val
& 0xC0000000;
1349 isarc
= val
& 0xFC000000;
1352 isacntl
= val
& 0xC0000000;
1355 ocm_update_mappings(ocm
, isarc
, isacntl
, dsarc
, dsacntl
);
1358 ocm
->isacntl
= isacntl
;
1359 ocm
->dsacntl
= dsacntl
;
1362 static void ocm_reset (void *opaque
)
1365 uint32_t isarc
, dsarc
, isacntl
, dsacntl
;
1369 isacntl
= 0x00000000;
1371 dsacntl
= 0x00000000;
1372 ocm_update_mappings(ocm
, isarc
, isacntl
, dsarc
, dsacntl
);
1375 ocm
->isacntl
= isacntl
;
1376 ocm
->dsacntl
= dsacntl
;
1379 void ppc405_ocm_init (CPUState
*env
, unsigned long offset
)
1383 ocm
= qemu_mallocz(sizeof(ppc405_ocm_t
));
1385 ocm
->offset
= offset
;
1387 qemu_register_reset(&ocm_reset
, ocm
);
1388 ppc_dcr_register(env
, OCM0_ISARC
,
1389 ocm
, &dcr_read_ocm
, &dcr_write_ocm
);
1390 ppc_dcr_register(env
, OCM0_ISACNTL
,
1391 ocm
, &dcr_read_ocm
, &dcr_write_ocm
);
1392 ppc_dcr_register(env
, OCM0_DSARC
,
1393 ocm
, &dcr_read_ocm
, &dcr_write_ocm
);
1394 ppc_dcr_register(env
, OCM0_DSACNTL
,
1395 ocm
, &dcr_read_ocm
, &dcr_write_ocm
);
1399 /*****************************************************************************/
1400 /* I2C controller */
1401 typedef struct ppc4xx_i2c_t ppc4xx_i2c_t
;
1402 struct ppc4xx_i2c_t
{
1403 target_phys_addr_t base
;
1422 static uint32_t ppc4xx_i2c_readb (void *opaque
, target_phys_addr_t addr
)
1428 printf("%s: addr " PADDRX
"\n", __func__
, addr
);
1431 switch (addr
- i2c
->base
) {
1433 // i2c_readbyte(&i2c->mdata);
1473 ret
= i2c
->xtcntlss
;
1476 ret
= i2c
->directcntl
;
1483 printf("%s: addr " PADDRX
" %02" PRIx32
"\n", __func__
, addr
, ret
);
1489 static void ppc4xx_i2c_writeb (void *opaque
,
1490 target_phys_addr_t addr
, uint32_t value
)
1495 printf("%s: addr " PADDRX
" val %08" PRIx32
"\n", __func__
, addr
, value
);
1498 switch (addr
- i2c
->base
) {
1501 // i2c_sendbyte(&i2c->mdata);
1516 i2c
->mdcntl
= value
& 0xDF;
1519 i2c
->sts
&= ~(value
& 0x0A);
1522 i2c
->extsts
&= ~(value
& 0x8F);
1531 i2c
->clkdiv
= value
;
1534 i2c
->intrmsk
= value
;
1537 i2c
->xfrcnt
= value
& 0x77;
1540 i2c
->xtcntlss
= value
;
1543 i2c
->directcntl
= value
& 0x7;
1548 static uint32_t ppc4xx_i2c_readw (void *opaque
, target_phys_addr_t addr
)
1553 printf("%s: addr " PADDRX
"\n", __func__
, addr
);
1555 ret
= ppc4xx_i2c_readb(opaque
, addr
) << 8;
1556 ret
|= ppc4xx_i2c_readb(opaque
, addr
+ 1);
1561 static void ppc4xx_i2c_writew (void *opaque
,
1562 target_phys_addr_t addr
, uint32_t value
)
1565 printf("%s: addr " PADDRX
" val %08" PRIx32
"\n", __func__
, addr
, value
);
1567 ppc4xx_i2c_writeb(opaque
, addr
, value
>> 8);
1568 ppc4xx_i2c_writeb(opaque
, addr
+ 1, value
);
1571 static uint32_t ppc4xx_i2c_readl (void *opaque
, target_phys_addr_t addr
)
1576 printf("%s: addr " PADDRX
"\n", __func__
, addr
);
1578 ret
= ppc4xx_i2c_readb(opaque
, addr
) << 24;
1579 ret
|= ppc4xx_i2c_readb(opaque
, addr
+ 1) << 16;
1580 ret
|= ppc4xx_i2c_readb(opaque
, addr
+ 2) << 8;
1581 ret
|= ppc4xx_i2c_readb(opaque
, addr
+ 3);
1586 static void ppc4xx_i2c_writel (void *opaque
,
1587 target_phys_addr_t addr
, uint32_t value
)
1590 printf("%s: addr " PADDRX
" val %08" PRIx32
"\n", __func__
, addr
, value
);
1592 ppc4xx_i2c_writeb(opaque
, addr
, value
>> 24);
1593 ppc4xx_i2c_writeb(opaque
, addr
+ 1, value
>> 16);
1594 ppc4xx_i2c_writeb(opaque
, addr
+ 2, value
>> 8);
1595 ppc4xx_i2c_writeb(opaque
, addr
+ 3, value
);
1598 static CPUReadMemoryFunc
*i2c_read
[] = {
1604 static CPUWriteMemoryFunc
*i2c_write
[] = {
1610 static void ppc4xx_i2c_reset (void *opaque
)
1623 i2c
->directcntl
= 0x0F;
1626 void ppc405_i2c_init (CPUState
*env
, ppc4xx_mmio_t
*mmio
,
1627 target_phys_addr_t offset
, qemu_irq irq
)
1631 i2c
= qemu_mallocz(sizeof(ppc4xx_i2c_t
));
1635 ppc4xx_i2c_reset(i2c
);
1637 printf("%s: offset " PADDRX
"\n", __func__
, offset
);
1639 ppc4xx_mmio_register(env
, mmio
, offset
, 0x011,
1640 i2c_read
, i2c_write
, i2c
);
1641 qemu_register_reset(ppc4xx_i2c_reset
, i2c
);
1645 /*****************************************************************************/
1646 /* General purpose timers */
1647 typedef struct ppc4xx_gpt_t ppc4xx_gpt_t
;
1648 struct ppc4xx_gpt_t
{
1649 target_phys_addr_t base
;
1652 struct QEMUTimer
*timer
;
1663 static uint32_t ppc4xx_gpt_readb (void *opaque
, target_phys_addr_t addr
)
1666 printf("%s: addr " PADDRX
"\n", __func__
, addr
);
1668 /* XXX: generate a bus fault */
1672 static void ppc4xx_gpt_writeb (void *opaque
,
1673 target_phys_addr_t addr
, uint32_t value
)
1676 printf("%s: addr " PADDRX
" val %08" PRIx32
"\n", __func__
, addr
, value
);
1678 /* XXX: generate a bus fault */
1681 static uint32_t ppc4xx_gpt_readw (void *opaque
, target_phys_addr_t addr
)
1684 printf("%s: addr " PADDRX
"\n", __func__
, addr
);
1686 /* XXX: generate a bus fault */
1690 static void ppc4xx_gpt_writew (void *opaque
,
1691 target_phys_addr_t addr
, uint32_t value
)
1694 printf("%s: addr " PADDRX
" val %08" PRIx32
"\n", __func__
, addr
, value
);
1696 /* XXX: generate a bus fault */
1699 static int ppc4xx_gpt_compare (ppc4xx_gpt_t
*gpt
, int n
)
1705 static void ppc4xx_gpt_set_output (ppc4xx_gpt_t
*gpt
, int n
, int level
)
1710 static void ppc4xx_gpt_set_outputs (ppc4xx_gpt_t
*gpt
)
1716 for (i
= 0; i
< 5; i
++) {
1717 if (gpt
->oe
& mask
) {
1718 /* Output is enabled */
1719 if (ppc4xx_gpt_compare(gpt
, i
)) {
1720 /* Comparison is OK */
1721 ppc4xx_gpt_set_output(gpt
, i
, gpt
->ol
& mask
);
1723 /* Comparison is KO */
1724 ppc4xx_gpt_set_output(gpt
, i
, gpt
->ol
& mask
? 0 : 1);
1731 static void ppc4xx_gpt_set_irqs (ppc4xx_gpt_t
*gpt
)
1737 for (i
= 0; i
< 5; i
++) {
1738 if (gpt
->is
& gpt
->im
& mask
)
1739 qemu_irq_raise(gpt
->irqs
[i
]);
1741 qemu_irq_lower(gpt
->irqs
[i
]);
1746 static void ppc4xx_gpt_compute_timer (ppc4xx_gpt_t
*gpt
)
1751 static uint32_t ppc4xx_gpt_readl (void *opaque
, target_phys_addr_t addr
)
1758 printf("%s: addr " PADDRX
"\n", __func__
, addr
);
1761 switch (addr
- gpt
->base
) {
1763 /* Time base counter */
1764 ret
= muldiv64(qemu_get_clock(vm_clock
) + gpt
->tb_offset
,
1765 gpt
->tb_freq
, ticks_per_sec
);
1776 /* Interrupt mask */
1781 /* Interrupt status */
1785 /* Interrupt enable */
1790 idx
= ((addr
- gpt
->base
) - 0x80) >> 2;
1791 ret
= gpt
->comp
[idx
];
1795 idx
= ((addr
- gpt
->base
) - 0xC0) >> 2;
1796 ret
= gpt
->mask
[idx
];
1806 static void ppc4xx_gpt_writel (void *opaque
,
1807 target_phys_addr_t addr
, uint32_t value
)
1813 printf("%s: addr " PADDRX
" val %08" PRIx32
"\n", __func__
, addr
, value
);
1816 switch (addr
- gpt
->base
) {
1818 /* Time base counter */
1819 gpt
->tb_offset
= muldiv64(value
, ticks_per_sec
, gpt
->tb_freq
)
1820 - qemu_get_clock(vm_clock
);
1821 ppc4xx_gpt_compute_timer(gpt
);
1825 gpt
->oe
= value
& 0xF8000000;
1826 ppc4xx_gpt_set_outputs(gpt
);
1830 gpt
->ol
= value
& 0xF8000000;
1831 ppc4xx_gpt_set_outputs(gpt
);
1834 /* Interrupt mask */
1835 gpt
->im
= value
& 0x0000F800;
1838 /* Interrupt status set */
1839 gpt
->is
|= value
& 0x0000F800;
1840 ppc4xx_gpt_set_irqs(gpt
);
1843 /* Interrupt status clear */
1844 gpt
->is
&= ~(value
& 0x0000F800);
1845 ppc4xx_gpt_set_irqs(gpt
);
1848 /* Interrupt enable */
1849 gpt
->ie
= value
& 0x0000F800;
1850 ppc4xx_gpt_set_irqs(gpt
);
1854 idx
= ((addr
- gpt
->base
) - 0x80) >> 2;
1855 gpt
->comp
[idx
] = value
& 0xF8000000;
1856 ppc4xx_gpt_compute_timer(gpt
);
1860 idx
= ((addr
- gpt
->base
) - 0xC0) >> 2;
1861 gpt
->mask
[idx
] = value
& 0xF8000000;
1862 ppc4xx_gpt_compute_timer(gpt
);
1867 static CPUReadMemoryFunc
*gpt_read
[] = {
1873 static CPUWriteMemoryFunc
*gpt_write
[] = {
1879 static void ppc4xx_gpt_cb (void *opaque
)
1884 ppc4xx_gpt_set_irqs(gpt
);
1885 ppc4xx_gpt_set_outputs(gpt
);
1886 ppc4xx_gpt_compute_timer(gpt
);
1889 static void ppc4xx_gpt_reset (void *opaque
)
1895 qemu_del_timer(gpt
->timer
);
1896 gpt
->oe
= 0x00000000;
1897 gpt
->ol
= 0x00000000;
1898 gpt
->im
= 0x00000000;
1899 gpt
->is
= 0x00000000;
1900 gpt
->ie
= 0x00000000;
1901 for (i
= 0; i
< 5; i
++) {
1902 gpt
->comp
[i
] = 0x00000000;
1903 gpt
->mask
[i
] = 0x00000000;
1907 void ppc4xx_gpt_init (CPUState
*env
, ppc4xx_mmio_t
*mmio
,
1908 target_phys_addr_t offset
, qemu_irq irqs
[5])
1913 gpt
= qemu_mallocz(sizeof(ppc4xx_gpt_t
));
1916 for (i
= 0; i
< 5; i
++)
1917 gpt
->irqs
[i
] = irqs
[i
];
1918 gpt
->timer
= qemu_new_timer(vm_clock
, &ppc4xx_gpt_cb
, gpt
);
1919 ppc4xx_gpt_reset(gpt
);
1921 printf("%s: offset " PADDRX
"\n", __func__
, offset
);
1923 ppc4xx_mmio_register(env
, mmio
, offset
, 0x0D4,
1924 gpt_read
, gpt_write
, gpt
);
1925 qemu_register_reset(ppc4xx_gpt_reset
, gpt
);
1929 /*****************************************************************************/
1935 MAL0_TXCASR
= 0x184,
1936 MAL0_TXCARR
= 0x185,
1937 MAL0_TXEOBISR
= 0x186,
1938 MAL0_TXDEIR
= 0x187,
1939 MAL0_RXCASR
= 0x190,
1940 MAL0_RXCARR
= 0x191,
1941 MAL0_RXEOBISR
= 0x192,
1942 MAL0_RXDEIR
= 0x193,
1943 MAL0_TXCTP0R
= 0x1A0,
1944 MAL0_TXCTP1R
= 0x1A1,
1945 MAL0_TXCTP2R
= 0x1A2,
1946 MAL0_TXCTP3R
= 0x1A3,
1947 MAL0_RXCTP0R
= 0x1C0,
1948 MAL0_RXCTP1R
= 0x1C1,
1953 typedef struct ppc40x_mal_t ppc40x_mal_t
;
1954 struct ppc40x_mal_t
{
1972 static void ppc40x_mal_reset (void *opaque
);
1974 static target_ulong
dcr_read_mal (void *opaque
, int dcrn
)
1997 ret
= mal
->txeobisr
;
2009 ret
= mal
->rxeobisr
;
2015 ret
= mal
->txctpr
[0];
2018 ret
= mal
->txctpr
[1];
2021 ret
= mal
->txctpr
[2];
2024 ret
= mal
->txctpr
[3];
2027 ret
= mal
->rxctpr
[0];
2030 ret
= mal
->rxctpr
[1];
2046 static void dcr_write_mal (void *opaque
, int dcrn
, target_ulong val
)
2054 if (val
& 0x80000000)
2055 ppc40x_mal_reset(mal
);
2056 mal
->cfg
= val
& 0x00FFC087;
2063 mal
->ier
= val
& 0x0000001F;
2066 mal
->txcasr
= val
& 0xF0000000;
2069 mal
->txcarr
= val
& 0xF0000000;
2073 mal
->txeobisr
&= ~val
;
2077 mal
->txdeir
&= ~val
;
2080 mal
->rxcasr
= val
& 0xC0000000;
2083 mal
->rxcarr
= val
& 0xC0000000;
2087 mal
->rxeobisr
&= ~val
;
2091 mal
->rxdeir
&= ~val
;
2105 mal
->txctpr
[idx
] = val
;
2113 mal
->rxctpr
[idx
] = val
;
2117 goto update_rx_size
;
2121 mal
->rcbs
[idx
] = val
& 0x000000FF;
2126 static void ppc40x_mal_reset (void *opaque
)
2131 mal
->cfg
= 0x0007C000;
2132 mal
->esr
= 0x00000000;
2133 mal
->ier
= 0x00000000;
2134 mal
->rxcasr
= 0x00000000;
2135 mal
->rxdeir
= 0x00000000;
2136 mal
->rxeobisr
= 0x00000000;
2137 mal
->txcasr
= 0x00000000;
2138 mal
->txdeir
= 0x00000000;
2139 mal
->txeobisr
= 0x00000000;
2142 void ppc405_mal_init (CPUState
*env
, qemu_irq irqs
[4])
2147 mal
= qemu_mallocz(sizeof(ppc40x_mal_t
));
2149 for (i
= 0; i
< 4; i
++)
2150 mal
->irqs
[i
] = irqs
[i
];
2151 ppc40x_mal_reset(mal
);
2152 qemu_register_reset(&ppc40x_mal_reset
, mal
);
2153 ppc_dcr_register(env
, MAL0_CFG
,
2154 mal
, &dcr_read_mal
, &dcr_write_mal
);
2155 ppc_dcr_register(env
, MAL0_ESR
,
2156 mal
, &dcr_read_mal
, &dcr_write_mal
);
2157 ppc_dcr_register(env
, MAL0_IER
,
2158 mal
, &dcr_read_mal
, &dcr_write_mal
);
2159 ppc_dcr_register(env
, MAL0_TXCASR
,
2160 mal
, &dcr_read_mal
, &dcr_write_mal
);
2161 ppc_dcr_register(env
, MAL0_TXCARR
,
2162 mal
, &dcr_read_mal
, &dcr_write_mal
);
2163 ppc_dcr_register(env
, MAL0_TXEOBISR
,
2164 mal
, &dcr_read_mal
, &dcr_write_mal
);
2165 ppc_dcr_register(env
, MAL0_TXDEIR
,
2166 mal
, &dcr_read_mal
, &dcr_write_mal
);
2167 ppc_dcr_register(env
, MAL0_RXCASR
,
2168 mal
, &dcr_read_mal
, &dcr_write_mal
);
2169 ppc_dcr_register(env
, MAL0_RXCARR
,
2170 mal
, &dcr_read_mal
, &dcr_write_mal
);
2171 ppc_dcr_register(env
, MAL0_RXEOBISR
,
2172 mal
, &dcr_read_mal
, &dcr_write_mal
);
2173 ppc_dcr_register(env
, MAL0_RXDEIR
,
2174 mal
, &dcr_read_mal
, &dcr_write_mal
);
2175 ppc_dcr_register(env
, MAL0_TXCTP0R
,
2176 mal
, &dcr_read_mal
, &dcr_write_mal
);
2177 ppc_dcr_register(env
, MAL0_TXCTP1R
,
2178 mal
, &dcr_read_mal
, &dcr_write_mal
);
2179 ppc_dcr_register(env
, MAL0_TXCTP2R
,
2180 mal
, &dcr_read_mal
, &dcr_write_mal
);
2181 ppc_dcr_register(env
, MAL0_TXCTP3R
,
2182 mal
, &dcr_read_mal
, &dcr_write_mal
);
2183 ppc_dcr_register(env
, MAL0_RXCTP0R
,
2184 mal
, &dcr_read_mal
, &dcr_write_mal
);
2185 ppc_dcr_register(env
, MAL0_RXCTP1R
,
2186 mal
, &dcr_read_mal
, &dcr_write_mal
);
2187 ppc_dcr_register(env
, MAL0_RCBS0
,
2188 mal
, &dcr_read_mal
, &dcr_write_mal
);
2189 ppc_dcr_register(env
, MAL0_RCBS1
,
2190 mal
, &dcr_read_mal
, &dcr_write_mal
);
2194 /*****************************************************************************/
2196 void ppc40x_core_reset (CPUState
*env
)
2200 printf("Reset PowerPC core\n");
2201 env
->interrupt_request
|= CPU_INTERRUPT_EXITTB
;
2206 qemu_system_reset_request();
2208 dbsr
= env
->spr
[SPR_40x_DBSR
];
2209 dbsr
&= ~0x00000300;
2211 env
->spr
[SPR_40x_DBSR
] = dbsr
;
2214 void ppc40x_chip_reset (CPUState
*env
)
2218 printf("Reset PowerPC chip\n");
2219 env
->interrupt_request
|= CPU_INTERRUPT_EXITTB
;
2224 qemu_system_reset_request();
2226 /* XXX: TODO reset all internal peripherals */
2227 dbsr
= env
->spr
[SPR_40x_DBSR
];
2228 dbsr
&= ~0x00000300;
2230 env
->spr
[SPR_40x_DBSR
] = dbsr
;
2233 void ppc40x_system_reset (CPUState
*env
)
2235 printf("Reset PowerPC system\n");
2236 qemu_system_reset_request();
2239 void store_40x_dbcr0 (CPUState
*env
, uint32_t val
)
2241 switch ((val
>> 28) & 0x3) {
2247 ppc40x_core_reset(env
);
2251 ppc40x_chip_reset(env
);
2255 ppc40x_system_reset(env
);
2260 /*****************************************************************************/
2263 PPC405CR_CPC0_PLLMR
= 0x0B0,
2264 PPC405CR_CPC0_CR0
= 0x0B1,
2265 PPC405CR_CPC0_CR1
= 0x0B2,
2266 PPC405CR_CPC0_PSR
= 0x0B4,
2267 PPC405CR_CPC0_JTAGID
= 0x0B5,
2268 PPC405CR_CPC0_ER
= 0x0B9,
2269 PPC405CR_CPC0_FR
= 0x0BA,
2270 PPC405CR_CPC0_SR
= 0x0BB,
2274 PPC405CR_CPU_CLK
= 0,
2275 PPC405CR_TMR_CLK
= 1,
2276 PPC405CR_PLB_CLK
= 2,
2277 PPC405CR_SDRAM_CLK
= 3,
2278 PPC405CR_OPB_CLK
= 4,
2279 PPC405CR_EXT_CLK
= 5,
2280 PPC405CR_UART_CLK
= 6,
2281 PPC405CR_CLK_NB
= 7,
2284 typedef struct ppc405cr_cpc_t ppc405cr_cpc_t
;
2285 struct ppc405cr_cpc_t
{
2286 clk_setup_t clk_setup
[PPC405CR_CLK_NB
];
2297 static void ppc405cr_clk_setup (ppc405cr_cpc_t
*cpc
)
2299 uint64_t VCO_out
, PLL_out
;
2300 uint32_t CPU_clk
, TMR_clk
, SDRAM_clk
, PLB_clk
, OPB_clk
, EXT_clk
, UART_clk
;
2303 D0
= ((cpc
->pllmr
>> 26) & 0x3) + 1; /* CBDV */
2304 if (cpc
->pllmr
& 0x80000000) {
2305 D1
= (((cpc
->pllmr
>> 20) - 1) & 0xF) + 1; /* FBDV */
2306 D2
= 8 - ((cpc
->pllmr
>> 16) & 0x7); /* FWDVA */
2308 VCO_out
= cpc
->sysclk
* M
;
2309 if (VCO_out
< 400000000 || VCO_out
> 800000000) {
2310 /* PLL cannot lock */
2311 cpc
->pllmr
&= ~0x80000000;
2314 PLL_out
= VCO_out
/ D2
;
2319 PLL_out
= cpc
->sysclk
* M
;
2322 if (cpc
->cr1
& 0x00800000)
2323 TMR_clk
= cpc
->sysclk
; /* Should have a separate clock */
2326 PLB_clk
= CPU_clk
/ D0
;
2327 SDRAM_clk
= PLB_clk
;
2328 D0
= ((cpc
->pllmr
>> 10) & 0x3) + 1;
2329 OPB_clk
= PLB_clk
/ D0
;
2330 D0
= ((cpc
->pllmr
>> 24) & 0x3) + 2;
2331 EXT_clk
= PLB_clk
/ D0
;
2332 D0
= ((cpc
->cr0
>> 1) & 0x1F) + 1;
2333 UART_clk
= CPU_clk
/ D0
;
2334 /* Setup CPU clocks */
2335 clk_setup(&cpc
->clk_setup
[PPC405CR_CPU_CLK
], CPU_clk
);
2336 /* Setup time-base clock */
2337 clk_setup(&cpc
->clk_setup
[PPC405CR_TMR_CLK
], TMR_clk
);
2338 /* Setup PLB clock */
2339 clk_setup(&cpc
->clk_setup
[PPC405CR_PLB_CLK
], PLB_clk
);
2340 /* Setup SDRAM clock */
2341 clk_setup(&cpc
->clk_setup
[PPC405CR_SDRAM_CLK
], SDRAM_clk
);
2342 /* Setup OPB clock */
2343 clk_setup(&cpc
->clk_setup
[PPC405CR_OPB_CLK
], OPB_clk
);
2344 /* Setup external clock */
2345 clk_setup(&cpc
->clk_setup
[PPC405CR_EXT_CLK
], EXT_clk
);
2346 /* Setup UART clock */
2347 clk_setup(&cpc
->clk_setup
[PPC405CR_UART_CLK
], UART_clk
);
2350 static target_ulong
dcr_read_crcpc (void *opaque
, int dcrn
)
2352 ppc405cr_cpc_t
*cpc
;
2357 case PPC405CR_CPC0_PLLMR
:
2360 case PPC405CR_CPC0_CR0
:
2363 case PPC405CR_CPC0_CR1
:
2366 case PPC405CR_CPC0_PSR
:
2369 case PPC405CR_CPC0_JTAGID
:
2372 case PPC405CR_CPC0_ER
:
2375 case PPC405CR_CPC0_FR
:
2378 case PPC405CR_CPC0_SR
:
2379 ret
= ~(cpc
->er
| cpc
->fr
) & 0xFFFF0000;
2382 /* Avoid gcc warning */
2390 static void dcr_write_crcpc (void *opaque
, int dcrn
, target_ulong val
)
2392 ppc405cr_cpc_t
*cpc
;
2396 case PPC405CR_CPC0_PLLMR
:
2397 cpc
->pllmr
= val
& 0xFFF77C3F;
2399 case PPC405CR_CPC0_CR0
:
2400 cpc
->cr0
= val
& 0x0FFFFFFE;
2402 case PPC405CR_CPC0_CR1
:
2403 cpc
->cr1
= val
& 0x00800000;
2405 case PPC405CR_CPC0_PSR
:
2408 case PPC405CR_CPC0_JTAGID
:
2411 case PPC405CR_CPC0_ER
:
2412 cpc
->er
= val
& 0xBFFC0000;
2414 case PPC405CR_CPC0_FR
:
2415 cpc
->fr
= val
& 0xBFFC0000;
2417 case PPC405CR_CPC0_SR
:
2423 static void ppc405cr_cpc_reset (void *opaque
)
2425 ppc405cr_cpc_t
*cpc
;
2429 /* Compute PLLMR value from PSR settings */
2430 cpc
->pllmr
= 0x80000000;
2432 switch ((cpc
->psr
>> 30) & 3) {
2435 cpc
->pllmr
&= ~0x80000000;
2439 cpc
->pllmr
|= 5 << 16;
2443 cpc
->pllmr
|= 4 << 16;
2447 cpc
->pllmr
|= 2 << 16;
2451 D
= (cpc
->psr
>> 28) & 3;
2452 cpc
->pllmr
|= (D
+ 1) << 20;
2454 D
= (cpc
->psr
>> 25) & 7;
2469 D
= (cpc
->psr
>> 23) & 3;
2470 cpc
->pllmr
|= D
<< 26;
2472 D
= (cpc
->psr
>> 21) & 3;
2473 cpc
->pllmr
|= D
<< 10;
2475 D
= (cpc
->psr
>> 17) & 3;
2476 cpc
->pllmr
|= D
<< 24;
2477 cpc
->cr0
= 0x0000003C;
2478 cpc
->cr1
= 0x2B0D8800;
2479 cpc
->er
= 0x00000000;
2480 cpc
->fr
= 0x00000000;
2481 ppc405cr_clk_setup(cpc
);
2484 static void ppc405cr_clk_init (ppc405cr_cpc_t
*cpc
)
2488 /* XXX: this should be read from IO pins */
2489 cpc
->psr
= 0x00000000; /* 8 bits ROM */
2491 D
= 0x2; /* Divide by 4 */
2492 cpc
->psr
|= D
<< 30;
2494 D
= 0x1; /* Divide by 2 */
2495 cpc
->psr
|= D
<< 28;
2497 D
= 0x1; /* Divide by 2 */
2498 cpc
->psr
|= D
<< 23;
2500 D
= 0x5; /* M = 16 */
2501 cpc
->psr
|= D
<< 25;
2503 D
= 0x1; /* Divide by 2 */
2504 cpc
->psr
|= D
<< 21;
2506 D
= 0x2; /* Divide by 4 */
2507 cpc
->psr
|= D
<< 17;
2510 static void ppc405cr_cpc_init (CPUState
*env
, clk_setup_t clk_setup
[7],
2513 ppc405cr_cpc_t
*cpc
;
2515 cpc
= qemu_mallocz(sizeof(ppc405cr_cpc_t
));
2517 memcpy(cpc
->clk_setup
, clk_setup
,
2518 PPC405CR_CLK_NB
* sizeof(clk_setup_t
));
2519 cpc
->sysclk
= sysclk
;
2520 cpc
->jtagid
= 0x42051049;
2521 ppc_dcr_register(env
, PPC405CR_CPC0_PSR
, cpc
,
2522 &dcr_read_crcpc
, &dcr_write_crcpc
);
2523 ppc_dcr_register(env
, PPC405CR_CPC0_CR0
, cpc
,
2524 &dcr_read_crcpc
, &dcr_write_crcpc
);
2525 ppc_dcr_register(env
, PPC405CR_CPC0_CR1
, cpc
,
2526 &dcr_read_crcpc
, &dcr_write_crcpc
);
2527 ppc_dcr_register(env
, PPC405CR_CPC0_JTAGID
, cpc
,
2528 &dcr_read_crcpc
, &dcr_write_crcpc
);
2529 ppc_dcr_register(env
, PPC405CR_CPC0_PLLMR
, cpc
,
2530 &dcr_read_crcpc
, &dcr_write_crcpc
);
2531 ppc_dcr_register(env
, PPC405CR_CPC0_ER
, cpc
,
2532 &dcr_read_crcpc
, &dcr_write_crcpc
);
2533 ppc_dcr_register(env
, PPC405CR_CPC0_FR
, cpc
,
2534 &dcr_read_crcpc
, &dcr_write_crcpc
);
2535 ppc_dcr_register(env
, PPC405CR_CPC0_SR
, cpc
,
2536 &dcr_read_crcpc
, &dcr_write_crcpc
);
2537 ppc405cr_clk_init(cpc
);
2538 qemu_register_reset(ppc405cr_cpc_reset
, cpc
);
2539 ppc405cr_cpc_reset(cpc
);
2543 CPUState
*ppc405cr_init (target_phys_addr_t ram_bases
[4],
2544 target_phys_addr_t ram_sizes
[4],
2545 uint32_t sysclk
, qemu_irq
**picp
,
2546 ram_addr_t
*offsetp
, int do_init
)
2548 clk_setup_t clk_setup
[PPC405CR_CLK_NB
];
2549 qemu_irq dma_irqs
[4];
2551 ppc4xx_mmio_t
*mmio
;
2552 qemu_irq
*pic
, *irqs
;
2556 memset(clk_setup
, 0, sizeof(clk_setup
));
2557 env
= ppc4xx_init("405cr", &clk_setup
[PPC405CR_CPU_CLK
],
2558 &clk_setup
[PPC405CR_TMR_CLK
], sysclk
);
2559 /* Memory mapped devices registers */
2560 mmio
= ppc4xx_mmio_init(env
, 0xEF600000);
2562 ppc4xx_plb_init(env
);
2563 /* PLB to OPB bridge */
2564 ppc4xx_pob_init(env
);
2566 ppc4xx_opba_init(env
, mmio
, 0x600);
2567 /* Universal interrupt controller */
2568 irqs
= qemu_mallocz(sizeof(qemu_irq
) * PPCUIC_OUTPUT_NB
);
2569 irqs
[PPCUIC_OUTPUT_INT
] =
2570 ((qemu_irq
*)env
->irq_inputs
)[PPC40x_INPUT_INT
];
2571 irqs
[PPCUIC_OUTPUT_CINT
] =
2572 ((qemu_irq
*)env
->irq_inputs
)[PPC40x_INPUT_CINT
];
2573 pic
= ppcuic_init(env
, irqs
, 0x0C0, 0, 1);
2575 /* SDRAM controller */
2576 ppc405_sdram_init(env
, pic
[14], 1, ram_bases
, ram_sizes
, do_init
);
2578 for (i
= 0; i
< 4; i
++)
2579 offset
+= ram_sizes
[i
];
2580 /* External bus controller */
2581 ppc405_ebc_init(env
);
2582 /* DMA controller */
2583 dma_irqs
[0] = pic
[26];
2584 dma_irqs
[1] = pic
[25];
2585 dma_irqs
[2] = pic
[24];
2586 dma_irqs
[3] = pic
[23];
2587 ppc405_dma_init(env
, dma_irqs
);
2589 if (serial_hds
[0] != NULL
) {
2590 ppc405_serial_init(env
, mmio
, 0x300, pic
[0], serial_hds
[0]);
2592 if (serial_hds
[1] != NULL
) {
2593 ppc405_serial_init(env
, mmio
, 0x400, pic
[1], serial_hds
[1]);
2595 /* IIC controller */
2596 ppc405_i2c_init(env
, mmio
, 0x500, pic
[2]);
2598 ppc405_gpio_init(env
, mmio
, 0x700);
2600 ppc405cr_cpc_init(env
, clk_setup
, sysclk
);
2606 /*****************************************************************************/
2610 PPC405EP_CPC0_PLLMR0
= 0x0F0,
2611 PPC405EP_CPC0_BOOT
= 0x0F1,
2612 PPC405EP_CPC0_EPCTL
= 0x0F3,
2613 PPC405EP_CPC0_PLLMR1
= 0x0F4,
2614 PPC405EP_CPC0_UCR
= 0x0F5,
2615 PPC405EP_CPC0_SRR
= 0x0F6,
2616 PPC405EP_CPC0_JTAGID
= 0x0F7,
2617 PPC405EP_CPC0_PCI
= 0x0F9,
2619 PPC405EP_CPC0_ER
= xxx
,
2620 PPC405EP_CPC0_FR
= xxx
,
2621 PPC405EP_CPC0_SR
= xxx
,
2626 PPC405EP_CPU_CLK
= 0,
2627 PPC405EP_PLB_CLK
= 1,
2628 PPC405EP_OPB_CLK
= 2,
2629 PPC405EP_EBC_CLK
= 3,
2630 PPC405EP_MAL_CLK
= 4,
2631 PPC405EP_PCI_CLK
= 5,
2632 PPC405EP_UART0_CLK
= 6,
2633 PPC405EP_UART1_CLK
= 7,
2634 PPC405EP_CLK_NB
= 8,
2637 typedef struct ppc405ep_cpc_t ppc405ep_cpc_t
;
2638 struct ppc405ep_cpc_t
{
2640 clk_setup_t clk_setup
[PPC405EP_CLK_NB
];
2648 /* Clock and power management */
2654 static void ppc405ep_compute_clocks (ppc405ep_cpc_t
*cpc
)
2656 uint32_t CPU_clk
, PLB_clk
, OPB_clk
, EBC_clk
, MAL_clk
, PCI_clk
;
2657 uint32_t UART0_clk
, UART1_clk
;
2658 uint64_t VCO_out
, PLL_out
;
2662 if ((cpc
->pllmr
[1] & 0x80000000) && !(cpc
->pllmr
[1] & 0x40000000)) {
2663 M
= (((cpc
->pllmr
[1] >> 20) - 1) & 0xF) + 1; /* FBMUL */
2664 #ifdef DEBUG_CLOCKS_LL
2665 printf("FBMUL %01" PRIx32
" %d\n", (cpc
->pllmr
[1] >> 20) & 0xF, M
);
2667 D
= 8 - ((cpc
->pllmr
[1] >> 16) & 0x7); /* FWDA */
2668 #ifdef DEBUG_CLOCKS_LL
2669 printf("FWDA %01" PRIx32
" %d\n", (cpc
->pllmr
[1] >> 16) & 0x7, D
);
2671 VCO_out
= cpc
->sysclk
* M
* D
;
2672 if (VCO_out
< 500000000UL || VCO_out
> 1000000000UL) {
2673 /* Error - unlock the PLL */
2674 printf("VCO out of range %" PRIu64
"\n", VCO_out
);
2676 cpc
->pllmr
[1] &= ~0x80000000;
2680 PLL_out
= VCO_out
/ D
;
2681 /* Pretend the PLL is locked */
2682 cpc
->boot
|= 0x00000001;
2687 PLL_out
= cpc
->sysclk
;
2688 if (cpc
->pllmr
[1] & 0x40000000) {
2689 /* Pretend the PLL is not locked */
2690 cpc
->boot
&= ~0x00000001;
2693 /* Now, compute all other clocks */
2694 D
= ((cpc
->pllmr
[0] >> 20) & 0x3) + 1; /* CCDV */
2695 #ifdef DEBUG_CLOCKS_LL
2696 printf("CCDV %01" PRIx32
" %d\n", (cpc
->pllmr
[0] >> 20) & 0x3, D
);
2698 CPU_clk
= PLL_out
/ D
;
2699 D
= ((cpc
->pllmr
[0] >> 16) & 0x3) + 1; /* CBDV */
2700 #ifdef DEBUG_CLOCKS_LL
2701 printf("CBDV %01" PRIx32
" %d\n", (cpc
->pllmr
[0] >> 16) & 0x3, D
);
2703 PLB_clk
= CPU_clk
/ D
;
2704 D
= ((cpc
->pllmr
[0] >> 12) & 0x3) + 1; /* OPDV */
2705 #ifdef DEBUG_CLOCKS_LL
2706 printf("OPDV %01" PRIx32
" %d\n", (cpc
->pllmr
[0] >> 12) & 0x3, D
);
2708 OPB_clk
= PLB_clk
/ D
;
2709 D
= ((cpc
->pllmr
[0] >> 8) & 0x3) + 2; /* EPDV */
2710 #ifdef DEBUG_CLOCKS_LL
2711 printf("EPDV %01" PRIx32
" %d\n", (cpc
->pllmr
[0] >> 8) & 0x3, D
);
2713 EBC_clk
= PLB_clk
/ D
;
2714 D
= ((cpc
->pllmr
[0] >> 4) & 0x3) + 1; /* MPDV */
2715 #ifdef DEBUG_CLOCKS_LL
2716 printf("MPDV %01" PRIx32
" %d\n", (cpc
->pllmr
[0] >> 4) & 0x3, D
);
2718 MAL_clk
= PLB_clk
/ D
;
2719 D
= (cpc
->pllmr
[0] & 0x3) + 1; /* PPDV */
2720 #ifdef DEBUG_CLOCKS_LL
2721 printf("PPDV %01" PRIx32
" %d\n", cpc
->pllmr
[0] & 0x3, D
);
2723 PCI_clk
= PLB_clk
/ D
;
2724 D
= ((cpc
->ucr
- 1) & 0x7F) + 1; /* U0DIV */
2725 #ifdef DEBUG_CLOCKS_LL
2726 printf("U0DIV %01" PRIx32
" %d\n", cpc
->ucr
& 0x7F, D
);
2728 UART0_clk
= PLL_out
/ D
;
2729 D
= (((cpc
->ucr
>> 8) - 1) & 0x7F) + 1; /* U1DIV */
2730 #ifdef DEBUG_CLOCKS_LL
2731 printf("U1DIV %01" PRIx32
" %d\n", (cpc
->ucr
>> 8) & 0x7F, D
);
2733 UART1_clk
= PLL_out
/ D
;
2735 printf("Setup PPC405EP clocks - sysclk %" PRIu32
" VCO %" PRIu64
2736 " PLL out %" PRIu64
" Hz\n", cpc
->sysclk
, VCO_out
, PLL_out
);
2737 printf("CPU %" PRIu32
" PLB %" PRIu32
" OPB %" PRIu32
" EBC %" PRIu32
2738 " MAL %" PRIu32
" PCI %" PRIu32
" UART0 %" PRIu32
2739 " UART1 %" PRIu32
"\n",
2740 CPU_clk
, PLB_clk
, OPB_clk
, EBC_clk
, MAL_clk
, PCI_clk
,
2741 UART0_clk
, UART1_clk
);
2743 /* Setup CPU clocks */
2744 clk_setup(&cpc
->clk_setup
[PPC405EP_CPU_CLK
], CPU_clk
);
2745 /* Setup PLB clock */
2746 clk_setup(&cpc
->clk_setup
[PPC405EP_PLB_CLK
], PLB_clk
);
2747 /* Setup OPB clock */
2748 clk_setup(&cpc
->clk_setup
[PPC405EP_OPB_CLK
], OPB_clk
);
2749 /* Setup external clock */
2750 clk_setup(&cpc
->clk_setup
[PPC405EP_EBC_CLK
], EBC_clk
);
2751 /* Setup MAL clock */
2752 clk_setup(&cpc
->clk_setup
[PPC405EP_MAL_CLK
], MAL_clk
);
2753 /* Setup PCI clock */
2754 clk_setup(&cpc
->clk_setup
[PPC405EP_PCI_CLK
], PCI_clk
);
2755 /* Setup UART0 clock */
2756 clk_setup(&cpc
->clk_setup
[PPC405EP_UART0_CLK
], UART0_clk
);
2757 /* Setup UART1 clock */
2758 clk_setup(&cpc
->clk_setup
[PPC405EP_UART1_CLK
], UART1_clk
);
2761 static target_ulong
dcr_read_epcpc (void *opaque
, int dcrn
)
2763 ppc405ep_cpc_t
*cpc
;
2768 case PPC405EP_CPC0_BOOT
:
2771 case PPC405EP_CPC0_EPCTL
:
2774 case PPC405EP_CPC0_PLLMR0
:
2775 ret
= cpc
->pllmr
[0];
2777 case PPC405EP_CPC0_PLLMR1
:
2778 ret
= cpc
->pllmr
[1];
2780 case PPC405EP_CPC0_UCR
:
2783 case PPC405EP_CPC0_SRR
:
2786 case PPC405EP_CPC0_JTAGID
:
2789 case PPC405EP_CPC0_PCI
:
2793 /* Avoid gcc warning */
2801 static void dcr_write_epcpc (void *opaque
, int dcrn
, target_ulong val
)
2803 ppc405ep_cpc_t
*cpc
;
2807 case PPC405EP_CPC0_BOOT
:
2808 /* Read-only register */
2810 case PPC405EP_CPC0_EPCTL
:
2811 /* Don't care for now */
2812 cpc
->epctl
= val
& 0xC00000F3;
2814 case PPC405EP_CPC0_PLLMR0
:
2815 cpc
->pllmr
[0] = val
& 0x00633333;
2816 ppc405ep_compute_clocks(cpc
);
2818 case PPC405EP_CPC0_PLLMR1
:
2819 cpc
->pllmr
[1] = val
& 0xC0F73FFF;
2820 ppc405ep_compute_clocks(cpc
);
2822 case PPC405EP_CPC0_UCR
:
2823 /* UART control - don't care for now */
2824 cpc
->ucr
= val
& 0x003F7F7F;
2826 case PPC405EP_CPC0_SRR
:
2829 case PPC405EP_CPC0_JTAGID
:
2832 case PPC405EP_CPC0_PCI
:
2838 static void ppc405ep_cpc_reset (void *opaque
)
2840 ppc405ep_cpc_t
*cpc
= opaque
;
2842 cpc
->boot
= 0x00000010; /* Boot from PCI - IIC EEPROM disabled */
2843 cpc
->epctl
= 0x00000000;
2844 cpc
->pllmr
[0] = 0x00011010;
2845 cpc
->pllmr
[1] = 0x40000000;
2846 cpc
->ucr
= 0x00000000;
2847 cpc
->srr
= 0x00040000;
2848 cpc
->pci
= 0x00000000;
2849 cpc
->er
= 0x00000000;
2850 cpc
->fr
= 0x00000000;
2851 cpc
->sr
= 0x00000000;
2852 ppc405ep_compute_clocks(cpc
);
2855 /* XXX: sysclk should be between 25 and 100 MHz */
2856 static void ppc405ep_cpc_init (CPUState
*env
, clk_setup_t clk_setup
[8],
2859 ppc405ep_cpc_t
*cpc
;
2861 cpc
= qemu_mallocz(sizeof(ppc405ep_cpc_t
));
2863 memcpy(cpc
->clk_setup
, clk_setup
,
2864 PPC405EP_CLK_NB
* sizeof(clk_setup_t
));
2865 cpc
->jtagid
= 0x20267049;
2866 cpc
->sysclk
= sysclk
;
2867 ppc405ep_cpc_reset(cpc
);
2868 qemu_register_reset(&ppc405ep_cpc_reset
, cpc
);
2869 ppc_dcr_register(env
, PPC405EP_CPC0_BOOT
, cpc
,
2870 &dcr_read_epcpc
, &dcr_write_epcpc
);
2871 ppc_dcr_register(env
, PPC405EP_CPC0_EPCTL
, cpc
,
2872 &dcr_read_epcpc
, &dcr_write_epcpc
);
2873 ppc_dcr_register(env
, PPC405EP_CPC0_PLLMR0
, cpc
,
2874 &dcr_read_epcpc
, &dcr_write_epcpc
);
2875 ppc_dcr_register(env
, PPC405EP_CPC0_PLLMR1
, cpc
,
2876 &dcr_read_epcpc
, &dcr_write_epcpc
);
2877 ppc_dcr_register(env
, PPC405EP_CPC0_UCR
, cpc
,
2878 &dcr_read_epcpc
, &dcr_write_epcpc
);
2879 ppc_dcr_register(env
, PPC405EP_CPC0_SRR
, cpc
,
2880 &dcr_read_epcpc
, &dcr_write_epcpc
);
2881 ppc_dcr_register(env
, PPC405EP_CPC0_JTAGID
, cpc
,
2882 &dcr_read_epcpc
, &dcr_write_epcpc
);
2883 ppc_dcr_register(env
, PPC405EP_CPC0_PCI
, cpc
,
2884 &dcr_read_epcpc
, &dcr_write_epcpc
);
2886 ppc_dcr_register(env
, PPC405EP_CPC0_ER
, cpc
,
2887 &dcr_read_epcpc
, &dcr_write_epcpc
);
2888 ppc_dcr_register(env
, PPC405EP_CPC0_FR
, cpc
,
2889 &dcr_read_epcpc
, &dcr_write_epcpc
);
2890 ppc_dcr_register(env
, PPC405EP_CPC0_SR
, cpc
,
2891 &dcr_read_epcpc
, &dcr_write_epcpc
);
2896 CPUState
*ppc405ep_init (target_phys_addr_t ram_bases
[2],
2897 target_phys_addr_t ram_sizes
[2],
2898 uint32_t sysclk
, qemu_irq
**picp
,
2899 ram_addr_t
*offsetp
, int do_init
)
2901 clk_setup_t clk_setup
[PPC405EP_CLK_NB
], tlb_clk_setup
;
2902 qemu_irq dma_irqs
[4], gpt_irqs
[5], mal_irqs
[4];
2904 ppc4xx_mmio_t
*mmio
;
2905 qemu_irq
*pic
, *irqs
;
2909 memset(clk_setup
, 0, sizeof(clk_setup
));
2911 env
= ppc4xx_init("405ep", &clk_setup
[PPC405EP_CPU_CLK
],
2912 &tlb_clk_setup
, sysclk
);
2913 clk_setup
[PPC405EP_CPU_CLK
].cb
= tlb_clk_setup
.cb
;
2914 clk_setup
[PPC405EP_CPU_CLK
].opaque
= tlb_clk_setup
.opaque
;
2915 /* Internal devices init */
2916 /* Memory mapped devices registers */
2917 mmio
= ppc4xx_mmio_init(env
, 0xEF600000);
2919 ppc4xx_plb_init(env
);
2920 /* PLB to OPB bridge */
2921 ppc4xx_pob_init(env
);
2923 ppc4xx_opba_init(env
, mmio
, 0x600);
2924 /* Universal interrupt controller */
2925 irqs
= qemu_mallocz(sizeof(qemu_irq
) * PPCUIC_OUTPUT_NB
);
2926 irqs
[PPCUIC_OUTPUT_INT
] =
2927 ((qemu_irq
*)env
->irq_inputs
)[PPC40x_INPUT_INT
];
2928 irqs
[PPCUIC_OUTPUT_CINT
] =
2929 ((qemu_irq
*)env
->irq_inputs
)[PPC40x_INPUT_CINT
];
2930 pic
= ppcuic_init(env
, irqs
, 0x0C0, 0, 1);
2932 /* SDRAM controller */
2933 /* XXX 405EP has no ECC interrupt */
2934 ppc405_sdram_init(env
, pic
[17], 2, ram_bases
, ram_sizes
, do_init
);
2936 for (i
= 0; i
< 2; i
++)
2937 offset
+= ram_sizes
[i
];
2938 /* External bus controller */
2939 ppc405_ebc_init(env
);
2940 /* DMA controller */
2941 dma_irqs
[0] = pic
[5];
2942 dma_irqs
[1] = pic
[6];
2943 dma_irqs
[2] = pic
[7];
2944 dma_irqs
[3] = pic
[8];
2945 ppc405_dma_init(env
, dma_irqs
);
2946 /* IIC controller */
2947 ppc405_i2c_init(env
, mmio
, 0x500, pic
[2]);
2949 ppc405_gpio_init(env
, mmio
, 0x700);
2951 if (serial_hds
[0] != NULL
) {
2952 ppc405_serial_init(env
, mmio
, 0x300, pic
[0], serial_hds
[0]);
2954 if (serial_hds
[1] != NULL
) {
2955 ppc405_serial_init(env
, mmio
, 0x400, pic
[1], serial_hds
[1]);
2958 ppc405_ocm_init(env
, ram_sizes
[0] + ram_sizes
[1]);
2961 gpt_irqs
[0] = pic
[19];
2962 gpt_irqs
[1] = pic
[20];
2963 gpt_irqs
[2] = pic
[21];
2964 gpt_irqs
[3] = pic
[22];
2965 gpt_irqs
[4] = pic
[23];
2966 ppc4xx_gpt_init(env
, mmio
, 0x000, gpt_irqs
);
2968 /* Uses pic[3], pic[16], pic[18] */
2970 mal_irqs
[0] = pic
[11];
2971 mal_irqs
[1] = pic
[12];
2972 mal_irqs
[2] = pic
[13];
2973 mal_irqs
[3] = pic
[14];
2974 ppc405_mal_init(env
, mal_irqs
);
2976 /* Uses pic[9], pic[15], pic[17] */
2978 ppc405ep_cpc_init(env
, clk_setup
, sysclk
);