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 /* Peripheral controller */
405 typedef struct ppc4xx_ebc_t ppc4xx_ebc_t
;
406 struct ppc4xx_ebc_t
{
417 EBC0_CFGADDR
= 0x012,
418 EBC0_CFGDATA
= 0x013,
421 static target_ulong
dcr_read_ebc (void *opaque
, int dcrn
)
433 case 0x00: /* B0CR */
436 case 0x01: /* B1CR */
439 case 0x02: /* B2CR */
442 case 0x03: /* B3CR */
445 case 0x04: /* B4CR */
448 case 0x05: /* B5CR */
451 case 0x06: /* B6CR */
454 case 0x07: /* B7CR */
457 case 0x10: /* B0AP */
460 case 0x11: /* B1AP */
463 case 0x12: /* B2AP */
466 case 0x13: /* B3AP */
469 case 0x14: /* B4AP */
472 case 0x15: /* B5AP */
475 case 0x16: /* B6AP */
478 case 0x17: /* B7AP */
481 case 0x20: /* BEAR */
484 case 0x21: /* BESR0 */
487 case 0x22: /* BESR1 */
505 static void dcr_write_ebc (void *opaque
, int dcrn
, target_ulong val
)
516 case 0x00: /* B0CR */
518 case 0x01: /* B1CR */
520 case 0x02: /* B2CR */
522 case 0x03: /* B3CR */
524 case 0x04: /* B4CR */
526 case 0x05: /* B5CR */
528 case 0x06: /* B6CR */
530 case 0x07: /* B7CR */
532 case 0x10: /* B0AP */
534 case 0x11: /* B1AP */
536 case 0x12: /* B2AP */
538 case 0x13: /* B3AP */
540 case 0x14: /* B4AP */
542 case 0x15: /* B5AP */
544 case 0x16: /* B6AP */
546 case 0x17: /* B7AP */
548 case 0x20: /* BEAR */
550 case 0x21: /* BESR0 */
552 case 0x22: /* BESR1 */
565 static void ebc_reset (void *opaque
)
571 ebc
->addr
= 0x00000000;
572 ebc
->bap
[0] = 0x7F8FFE80;
573 ebc
->bcr
[0] = 0xFFE28000;
574 for (i
= 0; i
< 8; i
++) {
575 ebc
->bap
[i
] = 0x00000000;
576 ebc
->bcr
[i
] = 0x00000000;
578 ebc
->besr0
= 0x00000000;
579 ebc
->besr1
= 0x00000000;
580 ebc
->cfg
= 0x80400000;
583 void ppc405_ebc_init (CPUState
*env
)
587 ebc
= qemu_mallocz(sizeof(ppc4xx_ebc_t
));
590 qemu_register_reset(&ebc_reset
, ebc
);
591 ppc_dcr_register(env
, EBC0_CFGADDR
,
592 ebc
, &dcr_read_ebc
, &dcr_write_ebc
);
593 ppc_dcr_register(env
, EBC0_CFGDATA
,
594 ebc
, &dcr_read_ebc
, &dcr_write_ebc
);
598 /*****************************************************************************/
627 typedef struct ppc405_dma_t ppc405_dma_t
;
628 struct ppc405_dma_t
{
641 static target_ulong
dcr_read_dma (void *opaque
, int dcrn
)
650 static void dcr_write_dma (void *opaque
, int dcrn
, target_ulong val
)
657 static void ppc405_dma_reset (void *opaque
)
663 for (i
= 0; i
< 4; i
++) {
664 dma
->cr
[i
] = 0x00000000;
665 dma
->ct
[i
] = 0x00000000;
666 dma
->da
[i
] = 0x00000000;
667 dma
->sa
[i
] = 0x00000000;
668 dma
->sg
[i
] = 0x00000000;
670 dma
->sr
= 0x00000000;
671 dma
->sgc
= 0x00000000;
672 dma
->slp
= 0x7C000000;
673 dma
->pol
= 0x00000000;
676 void ppc405_dma_init (CPUState
*env
, qemu_irq irqs
[4])
680 dma
= qemu_mallocz(sizeof(ppc405_dma_t
));
682 memcpy(dma
->irqs
, irqs
, 4 * sizeof(qemu_irq
));
683 ppc405_dma_reset(dma
);
684 qemu_register_reset(&ppc405_dma_reset
, dma
);
685 ppc_dcr_register(env
, DMA0_CR0
,
686 dma
, &dcr_read_dma
, &dcr_write_dma
);
687 ppc_dcr_register(env
, DMA0_CT0
,
688 dma
, &dcr_read_dma
, &dcr_write_dma
);
689 ppc_dcr_register(env
, DMA0_DA0
,
690 dma
, &dcr_read_dma
, &dcr_write_dma
);
691 ppc_dcr_register(env
, DMA0_SA0
,
692 dma
, &dcr_read_dma
, &dcr_write_dma
);
693 ppc_dcr_register(env
, DMA0_SG0
,
694 dma
, &dcr_read_dma
, &dcr_write_dma
);
695 ppc_dcr_register(env
, DMA0_CR1
,
696 dma
, &dcr_read_dma
, &dcr_write_dma
);
697 ppc_dcr_register(env
, DMA0_CT1
,
698 dma
, &dcr_read_dma
, &dcr_write_dma
);
699 ppc_dcr_register(env
, DMA0_DA1
,
700 dma
, &dcr_read_dma
, &dcr_write_dma
);
701 ppc_dcr_register(env
, DMA0_SA1
,
702 dma
, &dcr_read_dma
, &dcr_write_dma
);
703 ppc_dcr_register(env
, DMA0_SG1
,
704 dma
, &dcr_read_dma
, &dcr_write_dma
);
705 ppc_dcr_register(env
, DMA0_CR2
,
706 dma
, &dcr_read_dma
, &dcr_write_dma
);
707 ppc_dcr_register(env
, DMA0_CT2
,
708 dma
, &dcr_read_dma
, &dcr_write_dma
);
709 ppc_dcr_register(env
, DMA0_DA2
,
710 dma
, &dcr_read_dma
, &dcr_write_dma
);
711 ppc_dcr_register(env
, DMA0_SA2
,
712 dma
, &dcr_read_dma
, &dcr_write_dma
);
713 ppc_dcr_register(env
, DMA0_SG2
,
714 dma
, &dcr_read_dma
, &dcr_write_dma
);
715 ppc_dcr_register(env
, DMA0_CR3
,
716 dma
, &dcr_read_dma
, &dcr_write_dma
);
717 ppc_dcr_register(env
, DMA0_CT3
,
718 dma
, &dcr_read_dma
, &dcr_write_dma
);
719 ppc_dcr_register(env
, DMA0_DA3
,
720 dma
, &dcr_read_dma
, &dcr_write_dma
);
721 ppc_dcr_register(env
, DMA0_SA3
,
722 dma
, &dcr_read_dma
, &dcr_write_dma
);
723 ppc_dcr_register(env
, DMA0_SG3
,
724 dma
, &dcr_read_dma
, &dcr_write_dma
);
725 ppc_dcr_register(env
, DMA0_SR
,
726 dma
, &dcr_read_dma
, &dcr_write_dma
);
727 ppc_dcr_register(env
, DMA0_SGC
,
728 dma
, &dcr_read_dma
, &dcr_write_dma
);
729 ppc_dcr_register(env
, DMA0_SLP
,
730 dma
, &dcr_read_dma
, &dcr_write_dma
);
731 ppc_dcr_register(env
, DMA0_POL
,
732 dma
, &dcr_read_dma
, &dcr_write_dma
);
736 /*****************************************************************************/
738 typedef struct ppc405_gpio_t ppc405_gpio_t
;
739 struct ppc405_gpio_t
{
740 target_phys_addr_t base
;
754 static uint32_t ppc405_gpio_readb (void *opaque
, target_phys_addr_t addr
)
760 printf("%s: addr " PADDRX
"\n", __func__
, addr
);
766 static void ppc405_gpio_writeb (void *opaque
,
767 target_phys_addr_t addr
, uint32_t value
)
773 printf("%s: addr " PADDRX
" val %08" PRIx32
"\n", __func__
, addr
, value
);
777 static uint32_t ppc405_gpio_readw (void *opaque
, target_phys_addr_t addr
)
783 printf("%s: addr " PADDRX
"\n", __func__
, addr
);
789 static void ppc405_gpio_writew (void *opaque
,
790 target_phys_addr_t addr
, uint32_t value
)
796 printf("%s: addr " PADDRX
" val %08" PRIx32
"\n", __func__
, addr
, value
);
800 static uint32_t ppc405_gpio_readl (void *opaque
, target_phys_addr_t addr
)
806 printf("%s: addr " PADDRX
"\n", __func__
, addr
);
812 static void ppc405_gpio_writel (void *opaque
,
813 target_phys_addr_t addr
, uint32_t value
)
819 printf("%s: addr " PADDRX
" val %08" PRIx32
"\n", __func__
, addr
, value
);
823 static CPUReadMemoryFunc
*ppc405_gpio_read
[] = {
829 static CPUWriteMemoryFunc
*ppc405_gpio_write
[] = {
835 static void ppc405_gpio_reset (void *opaque
)
842 void ppc405_gpio_init (CPUState
*env
, ppc4xx_mmio_t
*mmio
,
843 target_phys_addr_t offset
)
847 gpio
= qemu_mallocz(sizeof(ppc405_gpio_t
));
850 ppc405_gpio_reset(gpio
);
851 qemu_register_reset(&ppc405_gpio_reset
, gpio
);
853 printf("%s: offset " PADDRX
"\n", __func__
, offset
);
855 ppc4xx_mmio_register(env
, mmio
, offset
, 0x038,
856 ppc405_gpio_read
, ppc405_gpio_write
, gpio
);
860 /*****************************************************************************/
862 static CPUReadMemoryFunc
*serial_mm_read
[] = {
868 static CPUWriteMemoryFunc
*serial_mm_write
[] = {
874 void ppc405_serial_init (CPUState
*env
, ppc4xx_mmio_t
*mmio
,
875 target_phys_addr_t offset
, qemu_irq irq
,
876 CharDriverState
*chr
)
881 printf("%s: offset " PADDRX
"\n", __func__
, offset
);
883 serial
= serial_mm_init(offset
, 0, irq
, 399193, chr
, 0);
884 ppc4xx_mmio_register(env
, mmio
, offset
, 0x008,
885 serial_mm_read
, serial_mm_write
, serial
);
888 /*****************************************************************************/
892 OCM0_ISACNTL
= 0x019,
894 OCM0_DSACNTL
= 0x01B,
897 typedef struct ppc405_ocm_t ppc405_ocm_t
;
898 struct ppc405_ocm_t
{
906 static void ocm_update_mappings (ppc405_ocm_t
*ocm
,
907 uint32_t isarc
, uint32_t isacntl
,
908 uint32_t dsarc
, uint32_t dsacntl
)
911 printf("OCM update ISA %08" PRIx32
" %08" PRIx32
" (%08" PRIx32
912 " %08" PRIx32
") DSA %08" PRIx32
" %08" PRIx32
913 " (%08" PRIx32
" %08" PRIx32
")\n",
914 isarc
, isacntl
, dsarc
, dsacntl
,
915 ocm
->isarc
, ocm
->isacntl
, ocm
->dsarc
, ocm
->dsacntl
);
917 if (ocm
->isarc
!= isarc
||
918 (ocm
->isacntl
& 0x80000000) != (isacntl
& 0x80000000)) {
919 if (ocm
->isacntl
& 0x80000000) {
920 /* Unmap previously assigned memory region */
921 printf("OCM unmap ISA %08" PRIx32
"\n", ocm
->isarc
);
922 cpu_register_physical_memory(ocm
->isarc
, 0x04000000,
925 if (isacntl
& 0x80000000) {
926 /* Map new instruction memory region */
928 printf("OCM map ISA %08" PRIx32
"\n", isarc
);
930 cpu_register_physical_memory(isarc
, 0x04000000,
931 ocm
->offset
| IO_MEM_RAM
);
934 if (ocm
->dsarc
!= dsarc
||
935 (ocm
->dsacntl
& 0x80000000) != (dsacntl
& 0x80000000)) {
936 if (ocm
->dsacntl
& 0x80000000) {
937 /* Beware not to unmap the region we just mapped */
938 if (!(isacntl
& 0x80000000) || ocm
->dsarc
!= isarc
) {
939 /* Unmap previously assigned memory region */
941 printf("OCM unmap DSA %08" PRIx32
"\n", ocm
->dsarc
);
943 cpu_register_physical_memory(ocm
->dsarc
, 0x04000000,
947 if (dsacntl
& 0x80000000) {
948 /* Beware not to remap the region we just mapped */
949 if (!(isacntl
& 0x80000000) || dsarc
!= isarc
) {
950 /* Map new data memory region */
952 printf("OCM map DSA %08" PRIx32
"\n", dsarc
);
954 cpu_register_physical_memory(dsarc
, 0x04000000,
955 ocm
->offset
| IO_MEM_RAM
);
961 static target_ulong
dcr_read_ocm (void *opaque
, int dcrn
)
988 static void dcr_write_ocm (void *opaque
, int dcrn
, target_ulong val
)
991 uint32_t isarc
, dsarc
, isacntl
, dsacntl
;
996 isacntl
= ocm
->isacntl
;
997 dsacntl
= ocm
->dsacntl
;
1000 isarc
= val
& 0xFC000000;
1003 isacntl
= val
& 0xC0000000;
1006 isarc
= val
& 0xFC000000;
1009 isacntl
= val
& 0xC0000000;
1012 ocm_update_mappings(ocm
, isarc
, isacntl
, dsarc
, dsacntl
);
1015 ocm
->isacntl
= isacntl
;
1016 ocm
->dsacntl
= dsacntl
;
1019 static void ocm_reset (void *opaque
)
1022 uint32_t isarc
, dsarc
, isacntl
, dsacntl
;
1026 isacntl
= 0x00000000;
1028 dsacntl
= 0x00000000;
1029 ocm_update_mappings(ocm
, isarc
, isacntl
, dsarc
, dsacntl
);
1032 ocm
->isacntl
= isacntl
;
1033 ocm
->dsacntl
= dsacntl
;
1036 void ppc405_ocm_init (CPUState
*env
, unsigned long offset
)
1040 ocm
= qemu_mallocz(sizeof(ppc405_ocm_t
));
1042 ocm
->offset
= offset
;
1044 qemu_register_reset(&ocm_reset
, ocm
);
1045 ppc_dcr_register(env
, OCM0_ISARC
,
1046 ocm
, &dcr_read_ocm
, &dcr_write_ocm
);
1047 ppc_dcr_register(env
, OCM0_ISACNTL
,
1048 ocm
, &dcr_read_ocm
, &dcr_write_ocm
);
1049 ppc_dcr_register(env
, OCM0_DSARC
,
1050 ocm
, &dcr_read_ocm
, &dcr_write_ocm
);
1051 ppc_dcr_register(env
, OCM0_DSACNTL
,
1052 ocm
, &dcr_read_ocm
, &dcr_write_ocm
);
1056 /*****************************************************************************/
1057 /* I2C controller */
1058 typedef struct ppc4xx_i2c_t ppc4xx_i2c_t
;
1059 struct ppc4xx_i2c_t
{
1060 target_phys_addr_t base
;
1079 static uint32_t ppc4xx_i2c_readb (void *opaque
, target_phys_addr_t addr
)
1085 printf("%s: addr " PADDRX
"\n", __func__
, addr
);
1088 switch (addr
- i2c
->base
) {
1090 // i2c_readbyte(&i2c->mdata);
1130 ret
= i2c
->xtcntlss
;
1133 ret
= i2c
->directcntl
;
1140 printf("%s: addr " PADDRX
" %02" PRIx32
"\n", __func__
, addr
, ret
);
1146 static void ppc4xx_i2c_writeb (void *opaque
,
1147 target_phys_addr_t addr
, uint32_t value
)
1152 printf("%s: addr " PADDRX
" val %08" PRIx32
"\n", __func__
, addr
, value
);
1155 switch (addr
- i2c
->base
) {
1158 // i2c_sendbyte(&i2c->mdata);
1173 i2c
->mdcntl
= value
& 0xDF;
1176 i2c
->sts
&= ~(value
& 0x0A);
1179 i2c
->extsts
&= ~(value
& 0x8F);
1188 i2c
->clkdiv
= value
;
1191 i2c
->intrmsk
= value
;
1194 i2c
->xfrcnt
= value
& 0x77;
1197 i2c
->xtcntlss
= value
;
1200 i2c
->directcntl
= value
& 0x7;
1205 static uint32_t ppc4xx_i2c_readw (void *opaque
, target_phys_addr_t addr
)
1210 printf("%s: addr " PADDRX
"\n", __func__
, addr
);
1212 ret
= ppc4xx_i2c_readb(opaque
, addr
) << 8;
1213 ret
|= ppc4xx_i2c_readb(opaque
, addr
+ 1);
1218 static void ppc4xx_i2c_writew (void *opaque
,
1219 target_phys_addr_t addr
, uint32_t value
)
1222 printf("%s: addr " PADDRX
" val %08" PRIx32
"\n", __func__
, addr
, value
);
1224 ppc4xx_i2c_writeb(opaque
, addr
, value
>> 8);
1225 ppc4xx_i2c_writeb(opaque
, addr
+ 1, value
);
1228 static uint32_t ppc4xx_i2c_readl (void *opaque
, target_phys_addr_t addr
)
1233 printf("%s: addr " PADDRX
"\n", __func__
, addr
);
1235 ret
= ppc4xx_i2c_readb(opaque
, addr
) << 24;
1236 ret
|= ppc4xx_i2c_readb(opaque
, addr
+ 1) << 16;
1237 ret
|= ppc4xx_i2c_readb(opaque
, addr
+ 2) << 8;
1238 ret
|= ppc4xx_i2c_readb(opaque
, addr
+ 3);
1243 static void ppc4xx_i2c_writel (void *opaque
,
1244 target_phys_addr_t addr
, uint32_t value
)
1247 printf("%s: addr " PADDRX
" val %08" PRIx32
"\n", __func__
, addr
, value
);
1249 ppc4xx_i2c_writeb(opaque
, addr
, value
>> 24);
1250 ppc4xx_i2c_writeb(opaque
, addr
+ 1, value
>> 16);
1251 ppc4xx_i2c_writeb(opaque
, addr
+ 2, value
>> 8);
1252 ppc4xx_i2c_writeb(opaque
, addr
+ 3, value
);
1255 static CPUReadMemoryFunc
*i2c_read
[] = {
1261 static CPUWriteMemoryFunc
*i2c_write
[] = {
1267 static void ppc4xx_i2c_reset (void *opaque
)
1280 i2c
->directcntl
= 0x0F;
1283 void ppc405_i2c_init (CPUState
*env
, ppc4xx_mmio_t
*mmio
,
1284 target_phys_addr_t offset
, qemu_irq irq
)
1288 i2c
= qemu_mallocz(sizeof(ppc4xx_i2c_t
));
1292 ppc4xx_i2c_reset(i2c
);
1294 printf("%s: offset " PADDRX
"\n", __func__
, offset
);
1296 ppc4xx_mmio_register(env
, mmio
, offset
, 0x011,
1297 i2c_read
, i2c_write
, i2c
);
1298 qemu_register_reset(ppc4xx_i2c_reset
, i2c
);
1302 /*****************************************************************************/
1303 /* General purpose timers */
1304 typedef struct ppc4xx_gpt_t ppc4xx_gpt_t
;
1305 struct ppc4xx_gpt_t
{
1306 target_phys_addr_t base
;
1309 struct QEMUTimer
*timer
;
1320 static uint32_t ppc4xx_gpt_readb (void *opaque
, target_phys_addr_t addr
)
1323 printf("%s: addr " PADDRX
"\n", __func__
, addr
);
1325 /* XXX: generate a bus fault */
1329 static void ppc4xx_gpt_writeb (void *opaque
,
1330 target_phys_addr_t addr
, uint32_t value
)
1333 printf("%s: addr " PADDRX
" val %08" PRIx32
"\n", __func__
, addr
, value
);
1335 /* XXX: generate a bus fault */
1338 static uint32_t ppc4xx_gpt_readw (void *opaque
, target_phys_addr_t addr
)
1341 printf("%s: addr " PADDRX
"\n", __func__
, addr
);
1343 /* XXX: generate a bus fault */
1347 static void ppc4xx_gpt_writew (void *opaque
,
1348 target_phys_addr_t addr
, uint32_t value
)
1351 printf("%s: addr " PADDRX
" val %08" PRIx32
"\n", __func__
, addr
, value
);
1353 /* XXX: generate a bus fault */
1356 static int ppc4xx_gpt_compare (ppc4xx_gpt_t
*gpt
, int n
)
1362 static void ppc4xx_gpt_set_output (ppc4xx_gpt_t
*gpt
, int n
, int level
)
1367 static void ppc4xx_gpt_set_outputs (ppc4xx_gpt_t
*gpt
)
1373 for (i
= 0; i
< 5; i
++) {
1374 if (gpt
->oe
& mask
) {
1375 /* Output is enabled */
1376 if (ppc4xx_gpt_compare(gpt
, i
)) {
1377 /* Comparison is OK */
1378 ppc4xx_gpt_set_output(gpt
, i
, gpt
->ol
& mask
);
1380 /* Comparison is KO */
1381 ppc4xx_gpt_set_output(gpt
, i
, gpt
->ol
& mask
? 0 : 1);
1388 static void ppc4xx_gpt_set_irqs (ppc4xx_gpt_t
*gpt
)
1394 for (i
= 0; i
< 5; i
++) {
1395 if (gpt
->is
& gpt
->im
& mask
)
1396 qemu_irq_raise(gpt
->irqs
[i
]);
1398 qemu_irq_lower(gpt
->irqs
[i
]);
1403 static void ppc4xx_gpt_compute_timer (ppc4xx_gpt_t
*gpt
)
1408 static uint32_t ppc4xx_gpt_readl (void *opaque
, target_phys_addr_t addr
)
1415 printf("%s: addr " PADDRX
"\n", __func__
, addr
);
1418 switch (addr
- gpt
->base
) {
1420 /* Time base counter */
1421 ret
= muldiv64(qemu_get_clock(vm_clock
) + gpt
->tb_offset
,
1422 gpt
->tb_freq
, ticks_per_sec
);
1433 /* Interrupt mask */
1438 /* Interrupt status */
1442 /* Interrupt enable */
1447 idx
= ((addr
- gpt
->base
) - 0x80) >> 2;
1448 ret
= gpt
->comp
[idx
];
1452 idx
= ((addr
- gpt
->base
) - 0xC0) >> 2;
1453 ret
= gpt
->mask
[idx
];
1463 static void ppc4xx_gpt_writel (void *opaque
,
1464 target_phys_addr_t addr
, uint32_t value
)
1470 printf("%s: addr " PADDRX
" val %08" PRIx32
"\n", __func__
, addr
, value
);
1473 switch (addr
- gpt
->base
) {
1475 /* Time base counter */
1476 gpt
->tb_offset
= muldiv64(value
, ticks_per_sec
, gpt
->tb_freq
)
1477 - qemu_get_clock(vm_clock
);
1478 ppc4xx_gpt_compute_timer(gpt
);
1482 gpt
->oe
= value
& 0xF8000000;
1483 ppc4xx_gpt_set_outputs(gpt
);
1487 gpt
->ol
= value
& 0xF8000000;
1488 ppc4xx_gpt_set_outputs(gpt
);
1491 /* Interrupt mask */
1492 gpt
->im
= value
& 0x0000F800;
1495 /* Interrupt status set */
1496 gpt
->is
|= value
& 0x0000F800;
1497 ppc4xx_gpt_set_irqs(gpt
);
1500 /* Interrupt status clear */
1501 gpt
->is
&= ~(value
& 0x0000F800);
1502 ppc4xx_gpt_set_irqs(gpt
);
1505 /* Interrupt enable */
1506 gpt
->ie
= value
& 0x0000F800;
1507 ppc4xx_gpt_set_irqs(gpt
);
1511 idx
= ((addr
- gpt
->base
) - 0x80) >> 2;
1512 gpt
->comp
[idx
] = value
& 0xF8000000;
1513 ppc4xx_gpt_compute_timer(gpt
);
1517 idx
= ((addr
- gpt
->base
) - 0xC0) >> 2;
1518 gpt
->mask
[idx
] = value
& 0xF8000000;
1519 ppc4xx_gpt_compute_timer(gpt
);
1524 static CPUReadMemoryFunc
*gpt_read
[] = {
1530 static CPUWriteMemoryFunc
*gpt_write
[] = {
1536 static void ppc4xx_gpt_cb (void *opaque
)
1541 ppc4xx_gpt_set_irqs(gpt
);
1542 ppc4xx_gpt_set_outputs(gpt
);
1543 ppc4xx_gpt_compute_timer(gpt
);
1546 static void ppc4xx_gpt_reset (void *opaque
)
1552 qemu_del_timer(gpt
->timer
);
1553 gpt
->oe
= 0x00000000;
1554 gpt
->ol
= 0x00000000;
1555 gpt
->im
= 0x00000000;
1556 gpt
->is
= 0x00000000;
1557 gpt
->ie
= 0x00000000;
1558 for (i
= 0; i
< 5; i
++) {
1559 gpt
->comp
[i
] = 0x00000000;
1560 gpt
->mask
[i
] = 0x00000000;
1564 void ppc4xx_gpt_init (CPUState
*env
, ppc4xx_mmio_t
*mmio
,
1565 target_phys_addr_t offset
, qemu_irq irqs
[5])
1570 gpt
= qemu_mallocz(sizeof(ppc4xx_gpt_t
));
1573 for (i
= 0; i
< 5; i
++)
1574 gpt
->irqs
[i
] = irqs
[i
];
1575 gpt
->timer
= qemu_new_timer(vm_clock
, &ppc4xx_gpt_cb
, gpt
);
1576 ppc4xx_gpt_reset(gpt
);
1578 printf("%s: offset " PADDRX
"\n", __func__
, offset
);
1580 ppc4xx_mmio_register(env
, mmio
, offset
, 0x0D4,
1581 gpt_read
, gpt_write
, gpt
);
1582 qemu_register_reset(ppc4xx_gpt_reset
, gpt
);
1586 /*****************************************************************************/
1592 MAL0_TXCASR
= 0x184,
1593 MAL0_TXCARR
= 0x185,
1594 MAL0_TXEOBISR
= 0x186,
1595 MAL0_TXDEIR
= 0x187,
1596 MAL0_RXCASR
= 0x190,
1597 MAL0_RXCARR
= 0x191,
1598 MAL0_RXEOBISR
= 0x192,
1599 MAL0_RXDEIR
= 0x193,
1600 MAL0_TXCTP0R
= 0x1A0,
1601 MAL0_TXCTP1R
= 0x1A1,
1602 MAL0_TXCTP2R
= 0x1A2,
1603 MAL0_TXCTP3R
= 0x1A3,
1604 MAL0_RXCTP0R
= 0x1C0,
1605 MAL0_RXCTP1R
= 0x1C1,
1610 typedef struct ppc40x_mal_t ppc40x_mal_t
;
1611 struct ppc40x_mal_t
{
1629 static void ppc40x_mal_reset (void *opaque
);
1631 static target_ulong
dcr_read_mal (void *opaque
, int dcrn
)
1654 ret
= mal
->txeobisr
;
1666 ret
= mal
->rxeobisr
;
1672 ret
= mal
->txctpr
[0];
1675 ret
= mal
->txctpr
[1];
1678 ret
= mal
->txctpr
[2];
1681 ret
= mal
->txctpr
[3];
1684 ret
= mal
->rxctpr
[0];
1687 ret
= mal
->rxctpr
[1];
1703 static void dcr_write_mal (void *opaque
, int dcrn
, target_ulong val
)
1711 if (val
& 0x80000000)
1712 ppc40x_mal_reset(mal
);
1713 mal
->cfg
= val
& 0x00FFC087;
1720 mal
->ier
= val
& 0x0000001F;
1723 mal
->txcasr
= val
& 0xF0000000;
1726 mal
->txcarr
= val
& 0xF0000000;
1730 mal
->txeobisr
&= ~val
;
1734 mal
->txdeir
&= ~val
;
1737 mal
->rxcasr
= val
& 0xC0000000;
1740 mal
->rxcarr
= val
& 0xC0000000;
1744 mal
->rxeobisr
&= ~val
;
1748 mal
->rxdeir
&= ~val
;
1762 mal
->txctpr
[idx
] = val
;
1770 mal
->rxctpr
[idx
] = val
;
1774 goto update_rx_size
;
1778 mal
->rcbs
[idx
] = val
& 0x000000FF;
1783 static void ppc40x_mal_reset (void *opaque
)
1788 mal
->cfg
= 0x0007C000;
1789 mal
->esr
= 0x00000000;
1790 mal
->ier
= 0x00000000;
1791 mal
->rxcasr
= 0x00000000;
1792 mal
->rxdeir
= 0x00000000;
1793 mal
->rxeobisr
= 0x00000000;
1794 mal
->txcasr
= 0x00000000;
1795 mal
->txdeir
= 0x00000000;
1796 mal
->txeobisr
= 0x00000000;
1799 void ppc405_mal_init (CPUState
*env
, qemu_irq irqs
[4])
1804 mal
= qemu_mallocz(sizeof(ppc40x_mal_t
));
1806 for (i
= 0; i
< 4; i
++)
1807 mal
->irqs
[i
] = irqs
[i
];
1808 ppc40x_mal_reset(mal
);
1809 qemu_register_reset(&ppc40x_mal_reset
, mal
);
1810 ppc_dcr_register(env
, MAL0_CFG
,
1811 mal
, &dcr_read_mal
, &dcr_write_mal
);
1812 ppc_dcr_register(env
, MAL0_ESR
,
1813 mal
, &dcr_read_mal
, &dcr_write_mal
);
1814 ppc_dcr_register(env
, MAL0_IER
,
1815 mal
, &dcr_read_mal
, &dcr_write_mal
);
1816 ppc_dcr_register(env
, MAL0_TXCASR
,
1817 mal
, &dcr_read_mal
, &dcr_write_mal
);
1818 ppc_dcr_register(env
, MAL0_TXCARR
,
1819 mal
, &dcr_read_mal
, &dcr_write_mal
);
1820 ppc_dcr_register(env
, MAL0_TXEOBISR
,
1821 mal
, &dcr_read_mal
, &dcr_write_mal
);
1822 ppc_dcr_register(env
, MAL0_TXDEIR
,
1823 mal
, &dcr_read_mal
, &dcr_write_mal
);
1824 ppc_dcr_register(env
, MAL0_RXCASR
,
1825 mal
, &dcr_read_mal
, &dcr_write_mal
);
1826 ppc_dcr_register(env
, MAL0_RXCARR
,
1827 mal
, &dcr_read_mal
, &dcr_write_mal
);
1828 ppc_dcr_register(env
, MAL0_RXEOBISR
,
1829 mal
, &dcr_read_mal
, &dcr_write_mal
);
1830 ppc_dcr_register(env
, MAL0_RXDEIR
,
1831 mal
, &dcr_read_mal
, &dcr_write_mal
);
1832 ppc_dcr_register(env
, MAL0_TXCTP0R
,
1833 mal
, &dcr_read_mal
, &dcr_write_mal
);
1834 ppc_dcr_register(env
, MAL0_TXCTP1R
,
1835 mal
, &dcr_read_mal
, &dcr_write_mal
);
1836 ppc_dcr_register(env
, MAL0_TXCTP2R
,
1837 mal
, &dcr_read_mal
, &dcr_write_mal
);
1838 ppc_dcr_register(env
, MAL0_TXCTP3R
,
1839 mal
, &dcr_read_mal
, &dcr_write_mal
);
1840 ppc_dcr_register(env
, MAL0_RXCTP0R
,
1841 mal
, &dcr_read_mal
, &dcr_write_mal
);
1842 ppc_dcr_register(env
, MAL0_RXCTP1R
,
1843 mal
, &dcr_read_mal
, &dcr_write_mal
);
1844 ppc_dcr_register(env
, MAL0_RCBS0
,
1845 mal
, &dcr_read_mal
, &dcr_write_mal
);
1846 ppc_dcr_register(env
, MAL0_RCBS1
,
1847 mal
, &dcr_read_mal
, &dcr_write_mal
);
1851 /*****************************************************************************/
1853 void ppc40x_core_reset (CPUState
*env
)
1857 printf("Reset PowerPC core\n");
1858 env
->interrupt_request
|= CPU_INTERRUPT_EXITTB
;
1863 qemu_system_reset_request();
1865 dbsr
= env
->spr
[SPR_40x_DBSR
];
1866 dbsr
&= ~0x00000300;
1868 env
->spr
[SPR_40x_DBSR
] = dbsr
;
1871 void ppc40x_chip_reset (CPUState
*env
)
1875 printf("Reset PowerPC chip\n");
1876 env
->interrupt_request
|= CPU_INTERRUPT_EXITTB
;
1881 qemu_system_reset_request();
1883 /* XXX: TODO reset all internal peripherals */
1884 dbsr
= env
->spr
[SPR_40x_DBSR
];
1885 dbsr
&= ~0x00000300;
1887 env
->spr
[SPR_40x_DBSR
] = dbsr
;
1890 void ppc40x_system_reset (CPUState
*env
)
1892 printf("Reset PowerPC system\n");
1893 qemu_system_reset_request();
1896 void store_40x_dbcr0 (CPUState
*env
, uint32_t val
)
1898 switch ((val
>> 28) & 0x3) {
1904 ppc40x_core_reset(env
);
1908 ppc40x_chip_reset(env
);
1912 ppc40x_system_reset(env
);
1917 /*****************************************************************************/
1920 PPC405CR_CPC0_PLLMR
= 0x0B0,
1921 PPC405CR_CPC0_CR0
= 0x0B1,
1922 PPC405CR_CPC0_CR1
= 0x0B2,
1923 PPC405CR_CPC0_PSR
= 0x0B4,
1924 PPC405CR_CPC0_JTAGID
= 0x0B5,
1925 PPC405CR_CPC0_ER
= 0x0B9,
1926 PPC405CR_CPC0_FR
= 0x0BA,
1927 PPC405CR_CPC0_SR
= 0x0BB,
1931 PPC405CR_CPU_CLK
= 0,
1932 PPC405CR_TMR_CLK
= 1,
1933 PPC405CR_PLB_CLK
= 2,
1934 PPC405CR_SDRAM_CLK
= 3,
1935 PPC405CR_OPB_CLK
= 4,
1936 PPC405CR_EXT_CLK
= 5,
1937 PPC405CR_UART_CLK
= 6,
1938 PPC405CR_CLK_NB
= 7,
1941 typedef struct ppc405cr_cpc_t ppc405cr_cpc_t
;
1942 struct ppc405cr_cpc_t
{
1943 clk_setup_t clk_setup
[PPC405CR_CLK_NB
];
1954 static void ppc405cr_clk_setup (ppc405cr_cpc_t
*cpc
)
1956 uint64_t VCO_out
, PLL_out
;
1957 uint32_t CPU_clk
, TMR_clk
, SDRAM_clk
, PLB_clk
, OPB_clk
, EXT_clk
, UART_clk
;
1960 D0
= ((cpc
->pllmr
>> 26) & 0x3) + 1; /* CBDV */
1961 if (cpc
->pllmr
& 0x80000000) {
1962 D1
= (((cpc
->pllmr
>> 20) - 1) & 0xF) + 1; /* FBDV */
1963 D2
= 8 - ((cpc
->pllmr
>> 16) & 0x7); /* FWDVA */
1965 VCO_out
= cpc
->sysclk
* M
;
1966 if (VCO_out
< 400000000 || VCO_out
> 800000000) {
1967 /* PLL cannot lock */
1968 cpc
->pllmr
&= ~0x80000000;
1971 PLL_out
= VCO_out
/ D2
;
1976 PLL_out
= cpc
->sysclk
* M
;
1979 if (cpc
->cr1
& 0x00800000)
1980 TMR_clk
= cpc
->sysclk
; /* Should have a separate clock */
1983 PLB_clk
= CPU_clk
/ D0
;
1984 SDRAM_clk
= PLB_clk
;
1985 D0
= ((cpc
->pllmr
>> 10) & 0x3) + 1;
1986 OPB_clk
= PLB_clk
/ D0
;
1987 D0
= ((cpc
->pllmr
>> 24) & 0x3) + 2;
1988 EXT_clk
= PLB_clk
/ D0
;
1989 D0
= ((cpc
->cr0
>> 1) & 0x1F) + 1;
1990 UART_clk
= CPU_clk
/ D0
;
1991 /* Setup CPU clocks */
1992 clk_setup(&cpc
->clk_setup
[PPC405CR_CPU_CLK
], CPU_clk
);
1993 /* Setup time-base clock */
1994 clk_setup(&cpc
->clk_setup
[PPC405CR_TMR_CLK
], TMR_clk
);
1995 /* Setup PLB clock */
1996 clk_setup(&cpc
->clk_setup
[PPC405CR_PLB_CLK
], PLB_clk
);
1997 /* Setup SDRAM clock */
1998 clk_setup(&cpc
->clk_setup
[PPC405CR_SDRAM_CLK
], SDRAM_clk
);
1999 /* Setup OPB clock */
2000 clk_setup(&cpc
->clk_setup
[PPC405CR_OPB_CLK
], OPB_clk
);
2001 /* Setup external clock */
2002 clk_setup(&cpc
->clk_setup
[PPC405CR_EXT_CLK
], EXT_clk
);
2003 /* Setup UART clock */
2004 clk_setup(&cpc
->clk_setup
[PPC405CR_UART_CLK
], UART_clk
);
2007 static target_ulong
dcr_read_crcpc (void *opaque
, int dcrn
)
2009 ppc405cr_cpc_t
*cpc
;
2014 case PPC405CR_CPC0_PLLMR
:
2017 case PPC405CR_CPC0_CR0
:
2020 case PPC405CR_CPC0_CR1
:
2023 case PPC405CR_CPC0_PSR
:
2026 case PPC405CR_CPC0_JTAGID
:
2029 case PPC405CR_CPC0_ER
:
2032 case PPC405CR_CPC0_FR
:
2035 case PPC405CR_CPC0_SR
:
2036 ret
= ~(cpc
->er
| cpc
->fr
) & 0xFFFF0000;
2039 /* Avoid gcc warning */
2047 static void dcr_write_crcpc (void *opaque
, int dcrn
, target_ulong val
)
2049 ppc405cr_cpc_t
*cpc
;
2053 case PPC405CR_CPC0_PLLMR
:
2054 cpc
->pllmr
= val
& 0xFFF77C3F;
2056 case PPC405CR_CPC0_CR0
:
2057 cpc
->cr0
= val
& 0x0FFFFFFE;
2059 case PPC405CR_CPC0_CR1
:
2060 cpc
->cr1
= val
& 0x00800000;
2062 case PPC405CR_CPC0_PSR
:
2065 case PPC405CR_CPC0_JTAGID
:
2068 case PPC405CR_CPC0_ER
:
2069 cpc
->er
= val
& 0xBFFC0000;
2071 case PPC405CR_CPC0_FR
:
2072 cpc
->fr
= val
& 0xBFFC0000;
2074 case PPC405CR_CPC0_SR
:
2080 static void ppc405cr_cpc_reset (void *opaque
)
2082 ppc405cr_cpc_t
*cpc
;
2086 /* Compute PLLMR value from PSR settings */
2087 cpc
->pllmr
= 0x80000000;
2089 switch ((cpc
->psr
>> 30) & 3) {
2092 cpc
->pllmr
&= ~0x80000000;
2096 cpc
->pllmr
|= 5 << 16;
2100 cpc
->pllmr
|= 4 << 16;
2104 cpc
->pllmr
|= 2 << 16;
2108 D
= (cpc
->psr
>> 28) & 3;
2109 cpc
->pllmr
|= (D
+ 1) << 20;
2111 D
= (cpc
->psr
>> 25) & 7;
2126 D
= (cpc
->psr
>> 23) & 3;
2127 cpc
->pllmr
|= D
<< 26;
2129 D
= (cpc
->psr
>> 21) & 3;
2130 cpc
->pllmr
|= D
<< 10;
2132 D
= (cpc
->psr
>> 17) & 3;
2133 cpc
->pllmr
|= D
<< 24;
2134 cpc
->cr0
= 0x0000003C;
2135 cpc
->cr1
= 0x2B0D8800;
2136 cpc
->er
= 0x00000000;
2137 cpc
->fr
= 0x00000000;
2138 ppc405cr_clk_setup(cpc
);
2141 static void ppc405cr_clk_init (ppc405cr_cpc_t
*cpc
)
2145 /* XXX: this should be read from IO pins */
2146 cpc
->psr
= 0x00000000; /* 8 bits ROM */
2148 D
= 0x2; /* Divide by 4 */
2149 cpc
->psr
|= D
<< 30;
2151 D
= 0x1; /* Divide by 2 */
2152 cpc
->psr
|= D
<< 28;
2154 D
= 0x1; /* Divide by 2 */
2155 cpc
->psr
|= D
<< 23;
2157 D
= 0x5; /* M = 16 */
2158 cpc
->psr
|= D
<< 25;
2160 D
= 0x1; /* Divide by 2 */
2161 cpc
->psr
|= D
<< 21;
2163 D
= 0x2; /* Divide by 4 */
2164 cpc
->psr
|= D
<< 17;
2167 static void ppc405cr_cpc_init (CPUState
*env
, clk_setup_t clk_setup
[7],
2170 ppc405cr_cpc_t
*cpc
;
2172 cpc
= qemu_mallocz(sizeof(ppc405cr_cpc_t
));
2174 memcpy(cpc
->clk_setup
, clk_setup
,
2175 PPC405CR_CLK_NB
* sizeof(clk_setup_t
));
2176 cpc
->sysclk
= sysclk
;
2177 cpc
->jtagid
= 0x42051049;
2178 ppc_dcr_register(env
, PPC405CR_CPC0_PSR
, cpc
,
2179 &dcr_read_crcpc
, &dcr_write_crcpc
);
2180 ppc_dcr_register(env
, PPC405CR_CPC0_CR0
, cpc
,
2181 &dcr_read_crcpc
, &dcr_write_crcpc
);
2182 ppc_dcr_register(env
, PPC405CR_CPC0_CR1
, cpc
,
2183 &dcr_read_crcpc
, &dcr_write_crcpc
);
2184 ppc_dcr_register(env
, PPC405CR_CPC0_JTAGID
, cpc
,
2185 &dcr_read_crcpc
, &dcr_write_crcpc
);
2186 ppc_dcr_register(env
, PPC405CR_CPC0_PLLMR
, cpc
,
2187 &dcr_read_crcpc
, &dcr_write_crcpc
);
2188 ppc_dcr_register(env
, PPC405CR_CPC0_ER
, cpc
,
2189 &dcr_read_crcpc
, &dcr_write_crcpc
);
2190 ppc_dcr_register(env
, PPC405CR_CPC0_FR
, cpc
,
2191 &dcr_read_crcpc
, &dcr_write_crcpc
);
2192 ppc_dcr_register(env
, PPC405CR_CPC0_SR
, cpc
,
2193 &dcr_read_crcpc
, &dcr_write_crcpc
);
2194 ppc405cr_clk_init(cpc
);
2195 qemu_register_reset(ppc405cr_cpc_reset
, cpc
);
2196 ppc405cr_cpc_reset(cpc
);
2200 CPUState
*ppc405cr_init (target_phys_addr_t ram_bases
[4],
2201 target_phys_addr_t ram_sizes
[4],
2202 uint32_t sysclk
, qemu_irq
**picp
,
2203 ram_addr_t
*offsetp
, int do_init
)
2205 clk_setup_t clk_setup
[PPC405CR_CLK_NB
];
2206 qemu_irq dma_irqs
[4];
2208 ppc4xx_mmio_t
*mmio
;
2209 qemu_irq
*pic
, *irqs
;
2213 memset(clk_setup
, 0, sizeof(clk_setup
));
2214 env
= ppc4xx_init("405cr", &clk_setup
[PPC405CR_CPU_CLK
],
2215 &clk_setup
[PPC405CR_TMR_CLK
], sysclk
);
2216 /* Memory mapped devices registers */
2217 mmio
= ppc4xx_mmio_init(env
, 0xEF600000);
2219 ppc4xx_plb_init(env
);
2220 /* PLB to OPB bridge */
2221 ppc4xx_pob_init(env
);
2223 ppc4xx_opba_init(env
, mmio
, 0x600);
2224 /* Universal interrupt controller */
2225 irqs
= qemu_mallocz(sizeof(qemu_irq
) * PPCUIC_OUTPUT_NB
);
2226 irqs
[PPCUIC_OUTPUT_INT
] =
2227 ((qemu_irq
*)env
->irq_inputs
)[PPC40x_INPUT_INT
];
2228 irqs
[PPCUIC_OUTPUT_CINT
] =
2229 ((qemu_irq
*)env
->irq_inputs
)[PPC40x_INPUT_CINT
];
2230 pic
= ppcuic_init(env
, irqs
, 0x0C0, 0, 1);
2232 /* SDRAM controller */
2233 ppc4xx_sdram_init(env
, pic
[14], 1, ram_bases
, ram_sizes
, do_init
);
2235 for (i
= 0; i
< 4; i
++)
2236 offset
+= ram_sizes
[i
];
2237 /* External bus controller */
2238 ppc405_ebc_init(env
);
2239 /* DMA controller */
2240 dma_irqs
[0] = pic
[26];
2241 dma_irqs
[1] = pic
[25];
2242 dma_irqs
[2] = pic
[24];
2243 dma_irqs
[3] = pic
[23];
2244 ppc405_dma_init(env
, dma_irqs
);
2246 if (serial_hds
[0] != NULL
) {
2247 ppc405_serial_init(env
, mmio
, 0x300, pic
[0], serial_hds
[0]);
2249 if (serial_hds
[1] != NULL
) {
2250 ppc405_serial_init(env
, mmio
, 0x400, pic
[1], serial_hds
[1]);
2252 /* IIC controller */
2253 ppc405_i2c_init(env
, mmio
, 0x500, pic
[2]);
2255 ppc405_gpio_init(env
, mmio
, 0x700);
2257 ppc405cr_cpc_init(env
, clk_setup
, sysclk
);
2263 /*****************************************************************************/
2267 PPC405EP_CPC0_PLLMR0
= 0x0F0,
2268 PPC405EP_CPC0_BOOT
= 0x0F1,
2269 PPC405EP_CPC0_EPCTL
= 0x0F3,
2270 PPC405EP_CPC0_PLLMR1
= 0x0F4,
2271 PPC405EP_CPC0_UCR
= 0x0F5,
2272 PPC405EP_CPC0_SRR
= 0x0F6,
2273 PPC405EP_CPC0_JTAGID
= 0x0F7,
2274 PPC405EP_CPC0_PCI
= 0x0F9,
2276 PPC405EP_CPC0_ER
= xxx
,
2277 PPC405EP_CPC0_FR
= xxx
,
2278 PPC405EP_CPC0_SR
= xxx
,
2283 PPC405EP_CPU_CLK
= 0,
2284 PPC405EP_PLB_CLK
= 1,
2285 PPC405EP_OPB_CLK
= 2,
2286 PPC405EP_EBC_CLK
= 3,
2287 PPC405EP_MAL_CLK
= 4,
2288 PPC405EP_PCI_CLK
= 5,
2289 PPC405EP_UART0_CLK
= 6,
2290 PPC405EP_UART1_CLK
= 7,
2291 PPC405EP_CLK_NB
= 8,
2294 typedef struct ppc405ep_cpc_t ppc405ep_cpc_t
;
2295 struct ppc405ep_cpc_t
{
2297 clk_setup_t clk_setup
[PPC405EP_CLK_NB
];
2305 /* Clock and power management */
2311 static void ppc405ep_compute_clocks (ppc405ep_cpc_t
*cpc
)
2313 uint32_t CPU_clk
, PLB_clk
, OPB_clk
, EBC_clk
, MAL_clk
, PCI_clk
;
2314 uint32_t UART0_clk
, UART1_clk
;
2315 uint64_t VCO_out
, PLL_out
;
2319 if ((cpc
->pllmr
[1] & 0x80000000) && !(cpc
->pllmr
[1] & 0x40000000)) {
2320 M
= (((cpc
->pllmr
[1] >> 20) - 1) & 0xF) + 1; /* FBMUL */
2321 #ifdef DEBUG_CLOCKS_LL
2322 printf("FBMUL %01" PRIx32
" %d\n", (cpc
->pllmr
[1] >> 20) & 0xF, M
);
2324 D
= 8 - ((cpc
->pllmr
[1] >> 16) & 0x7); /* FWDA */
2325 #ifdef DEBUG_CLOCKS_LL
2326 printf("FWDA %01" PRIx32
" %d\n", (cpc
->pllmr
[1] >> 16) & 0x7, D
);
2328 VCO_out
= cpc
->sysclk
* M
* D
;
2329 if (VCO_out
< 500000000UL || VCO_out
> 1000000000UL) {
2330 /* Error - unlock the PLL */
2331 printf("VCO out of range %" PRIu64
"\n", VCO_out
);
2333 cpc
->pllmr
[1] &= ~0x80000000;
2337 PLL_out
= VCO_out
/ D
;
2338 /* Pretend the PLL is locked */
2339 cpc
->boot
|= 0x00000001;
2344 PLL_out
= cpc
->sysclk
;
2345 if (cpc
->pllmr
[1] & 0x40000000) {
2346 /* Pretend the PLL is not locked */
2347 cpc
->boot
&= ~0x00000001;
2350 /* Now, compute all other clocks */
2351 D
= ((cpc
->pllmr
[0] >> 20) & 0x3) + 1; /* CCDV */
2352 #ifdef DEBUG_CLOCKS_LL
2353 printf("CCDV %01" PRIx32
" %d\n", (cpc
->pllmr
[0] >> 20) & 0x3, D
);
2355 CPU_clk
= PLL_out
/ D
;
2356 D
= ((cpc
->pllmr
[0] >> 16) & 0x3) + 1; /* CBDV */
2357 #ifdef DEBUG_CLOCKS_LL
2358 printf("CBDV %01" PRIx32
" %d\n", (cpc
->pllmr
[0] >> 16) & 0x3, D
);
2360 PLB_clk
= CPU_clk
/ D
;
2361 D
= ((cpc
->pllmr
[0] >> 12) & 0x3) + 1; /* OPDV */
2362 #ifdef DEBUG_CLOCKS_LL
2363 printf("OPDV %01" PRIx32
" %d\n", (cpc
->pllmr
[0] >> 12) & 0x3, D
);
2365 OPB_clk
= PLB_clk
/ D
;
2366 D
= ((cpc
->pllmr
[0] >> 8) & 0x3) + 2; /* EPDV */
2367 #ifdef DEBUG_CLOCKS_LL
2368 printf("EPDV %01" PRIx32
" %d\n", (cpc
->pllmr
[0] >> 8) & 0x3, D
);
2370 EBC_clk
= PLB_clk
/ D
;
2371 D
= ((cpc
->pllmr
[0] >> 4) & 0x3) + 1; /* MPDV */
2372 #ifdef DEBUG_CLOCKS_LL
2373 printf("MPDV %01" PRIx32
" %d\n", (cpc
->pllmr
[0] >> 4) & 0x3, D
);
2375 MAL_clk
= PLB_clk
/ D
;
2376 D
= (cpc
->pllmr
[0] & 0x3) + 1; /* PPDV */
2377 #ifdef DEBUG_CLOCKS_LL
2378 printf("PPDV %01" PRIx32
" %d\n", cpc
->pllmr
[0] & 0x3, D
);
2380 PCI_clk
= PLB_clk
/ D
;
2381 D
= ((cpc
->ucr
- 1) & 0x7F) + 1; /* U0DIV */
2382 #ifdef DEBUG_CLOCKS_LL
2383 printf("U0DIV %01" PRIx32
" %d\n", cpc
->ucr
& 0x7F, D
);
2385 UART0_clk
= PLL_out
/ D
;
2386 D
= (((cpc
->ucr
>> 8) - 1) & 0x7F) + 1; /* U1DIV */
2387 #ifdef DEBUG_CLOCKS_LL
2388 printf("U1DIV %01" PRIx32
" %d\n", (cpc
->ucr
>> 8) & 0x7F, D
);
2390 UART1_clk
= PLL_out
/ D
;
2392 printf("Setup PPC405EP clocks - sysclk %" PRIu32
" VCO %" PRIu64
2393 " PLL out %" PRIu64
" Hz\n", cpc
->sysclk
, VCO_out
, PLL_out
);
2394 printf("CPU %" PRIu32
" PLB %" PRIu32
" OPB %" PRIu32
" EBC %" PRIu32
2395 " MAL %" PRIu32
" PCI %" PRIu32
" UART0 %" PRIu32
2396 " UART1 %" PRIu32
"\n",
2397 CPU_clk
, PLB_clk
, OPB_clk
, EBC_clk
, MAL_clk
, PCI_clk
,
2398 UART0_clk
, UART1_clk
);
2400 /* Setup CPU clocks */
2401 clk_setup(&cpc
->clk_setup
[PPC405EP_CPU_CLK
], CPU_clk
);
2402 /* Setup PLB clock */
2403 clk_setup(&cpc
->clk_setup
[PPC405EP_PLB_CLK
], PLB_clk
);
2404 /* Setup OPB clock */
2405 clk_setup(&cpc
->clk_setup
[PPC405EP_OPB_CLK
], OPB_clk
);
2406 /* Setup external clock */
2407 clk_setup(&cpc
->clk_setup
[PPC405EP_EBC_CLK
], EBC_clk
);
2408 /* Setup MAL clock */
2409 clk_setup(&cpc
->clk_setup
[PPC405EP_MAL_CLK
], MAL_clk
);
2410 /* Setup PCI clock */
2411 clk_setup(&cpc
->clk_setup
[PPC405EP_PCI_CLK
], PCI_clk
);
2412 /* Setup UART0 clock */
2413 clk_setup(&cpc
->clk_setup
[PPC405EP_UART0_CLK
], UART0_clk
);
2414 /* Setup UART1 clock */
2415 clk_setup(&cpc
->clk_setup
[PPC405EP_UART1_CLK
], UART1_clk
);
2418 static target_ulong
dcr_read_epcpc (void *opaque
, int dcrn
)
2420 ppc405ep_cpc_t
*cpc
;
2425 case PPC405EP_CPC0_BOOT
:
2428 case PPC405EP_CPC0_EPCTL
:
2431 case PPC405EP_CPC0_PLLMR0
:
2432 ret
= cpc
->pllmr
[0];
2434 case PPC405EP_CPC0_PLLMR1
:
2435 ret
= cpc
->pllmr
[1];
2437 case PPC405EP_CPC0_UCR
:
2440 case PPC405EP_CPC0_SRR
:
2443 case PPC405EP_CPC0_JTAGID
:
2446 case PPC405EP_CPC0_PCI
:
2450 /* Avoid gcc warning */
2458 static void dcr_write_epcpc (void *opaque
, int dcrn
, target_ulong val
)
2460 ppc405ep_cpc_t
*cpc
;
2464 case PPC405EP_CPC0_BOOT
:
2465 /* Read-only register */
2467 case PPC405EP_CPC0_EPCTL
:
2468 /* Don't care for now */
2469 cpc
->epctl
= val
& 0xC00000F3;
2471 case PPC405EP_CPC0_PLLMR0
:
2472 cpc
->pllmr
[0] = val
& 0x00633333;
2473 ppc405ep_compute_clocks(cpc
);
2475 case PPC405EP_CPC0_PLLMR1
:
2476 cpc
->pllmr
[1] = val
& 0xC0F73FFF;
2477 ppc405ep_compute_clocks(cpc
);
2479 case PPC405EP_CPC0_UCR
:
2480 /* UART control - don't care for now */
2481 cpc
->ucr
= val
& 0x003F7F7F;
2483 case PPC405EP_CPC0_SRR
:
2486 case PPC405EP_CPC0_JTAGID
:
2489 case PPC405EP_CPC0_PCI
:
2495 static void ppc405ep_cpc_reset (void *opaque
)
2497 ppc405ep_cpc_t
*cpc
= opaque
;
2499 cpc
->boot
= 0x00000010; /* Boot from PCI - IIC EEPROM disabled */
2500 cpc
->epctl
= 0x00000000;
2501 cpc
->pllmr
[0] = 0x00011010;
2502 cpc
->pllmr
[1] = 0x40000000;
2503 cpc
->ucr
= 0x00000000;
2504 cpc
->srr
= 0x00040000;
2505 cpc
->pci
= 0x00000000;
2506 cpc
->er
= 0x00000000;
2507 cpc
->fr
= 0x00000000;
2508 cpc
->sr
= 0x00000000;
2509 ppc405ep_compute_clocks(cpc
);
2512 /* XXX: sysclk should be between 25 and 100 MHz */
2513 static void ppc405ep_cpc_init (CPUState
*env
, clk_setup_t clk_setup
[8],
2516 ppc405ep_cpc_t
*cpc
;
2518 cpc
= qemu_mallocz(sizeof(ppc405ep_cpc_t
));
2520 memcpy(cpc
->clk_setup
, clk_setup
,
2521 PPC405EP_CLK_NB
* sizeof(clk_setup_t
));
2522 cpc
->jtagid
= 0x20267049;
2523 cpc
->sysclk
= sysclk
;
2524 ppc405ep_cpc_reset(cpc
);
2525 qemu_register_reset(&ppc405ep_cpc_reset
, cpc
);
2526 ppc_dcr_register(env
, PPC405EP_CPC0_BOOT
, cpc
,
2527 &dcr_read_epcpc
, &dcr_write_epcpc
);
2528 ppc_dcr_register(env
, PPC405EP_CPC0_EPCTL
, cpc
,
2529 &dcr_read_epcpc
, &dcr_write_epcpc
);
2530 ppc_dcr_register(env
, PPC405EP_CPC0_PLLMR0
, cpc
,
2531 &dcr_read_epcpc
, &dcr_write_epcpc
);
2532 ppc_dcr_register(env
, PPC405EP_CPC0_PLLMR1
, cpc
,
2533 &dcr_read_epcpc
, &dcr_write_epcpc
);
2534 ppc_dcr_register(env
, PPC405EP_CPC0_UCR
, cpc
,
2535 &dcr_read_epcpc
, &dcr_write_epcpc
);
2536 ppc_dcr_register(env
, PPC405EP_CPC0_SRR
, cpc
,
2537 &dcr_read_epcpc
, &dcr_write_epcpc
);
2538 ppc_dcr_register(env
, PPC405EP_CPC0_JTAGID
, cpc
,
2539 &dcr_read_epcpc
, &dcr_write_epcpc
);
2540 ppc_dcr_register(env
, PPC405EP_CPC0_PCI
, cpc
,
2541 &dcr_read_epcpc
, &dcr_write_epcpc
);
2543 ppc_dcr_register(env
, PPC405EP_CPC0_ER
, cpc
,
2544 &dcr_read_epcpc
, &dcr_write_epcpc
);
2545 ppc_dcr_register(env
, PPC405EP_CPC0_FR
, cpc
,
2546 &dcr_read_epcpc
, &dcr_write_epcpc
);
2547 ppc_dcr_register(env
, PPC405EP_CPC0_SR
, cpc
,
2548 &dcr_read_epcpc
, &dcr_write_epcpc
);
2553 CPUState
*ppc405ep_init (target_phys_addr_t ram_bases
[2],
2554 target_phys_addr_t ram_sizes
[2],
2555 uint32_t sysclk
, qemu_irq
**picp
,
2556 ram_addr_t
*offsetp
, int do_init
)
2558 clk_setup_t clk_setup
[PPC405EP_CLK_NB
], tlb_clk_setup
;
2559 qemu_irq dma_irqs
[4], gpt_irqs
[5], mal_irqs
[4];
2561 ppc4xx_mmio_t
*mmio
;
2562 qemu_irq
*pic
, *irqs
;
2566 memset(clk_setup
, 0, sizeof(clk_setup
));
2568 env
= ppc4xx_init("405ep", &clk_setup
[PPC405EP_CPU_CLK
],
2569 &tlb_clk_setup
, sysclk
);
2570 clk_setup
[PPC405EP_CPU_CLK
].cb
= tlb_clk_setup
.cb
;
2571 clk_setup
[PPC405EP_CPU_CLK
].opaque
= tlb_clk_setup
.opaque
;
2572 /* Internal devices init */
2573 /* Memory mapped devices registers */
2574 mmio
= ppc4xx_mmio_init(env
, 0xEF600000);
2576 ppc4xx_plb_init(env
);
2577 /* PLB to OPB bridge */
2578 ppc4xx_pob_init(env
);
2580 ppc4xx_opba_init(env
, mmio
, 0x600);
2581 /* Universal interrupt controller */
2582 irqs
= qemu_mallocz(sizeof(qemu_irq
) * PPCUIC_OUTPUT_NB
);
2583 irqs
[PPCUIC_OUTPUT_INT
] =
2584 ((qemu_irq
*)env
->irq_inputs
)[PPC40x_INPUT_INT
];
2585 irqs
[PPCUIC_OUTPUT_CINT
] =
2586 ((qemu_irq
*)env
->irq_inputs
)[PPC40x_INPUT_CINT
];
2587 pic
= ppcuic_init(env
, irqs
, 0x0C0, 0, 1);
2589 /* SDRAM controller */
2590 /* XXX 405EP has no ECC interrupt */
2591 ppc4xx_sdram_init(env
, pic
[17], 2, ram_bases
, ram_sizes
, do_init
);
2593 for (i
= 0; i
< 2; i
++)
2594 offset
+= ram_sizes
[i
];
2595 /* External bus controller */
2596 ppc405_ebc_init(env
);
2597 /* DMA controller */
2598 dma_irqs
[0] = pic
[5];
2599 dma_irqs
[1] = pic
[6];
2600 dma_irqs
[2] = pic
[7];
2601 dma_irqs
[3] = pic
[8];
2602 ppc405_dma_init(env
, dma_irqs
);
2603 /* IIC controller */
2604 ppc405_i2c_init(env
, mmio
, 0x500, pic
[2]);
2606 ppc405_gpio_init(env
, mmio
, 0x700);
2608 if (serial_hds
[0] != NULL
) {
2609 ppc405_serial_init(env
, mmio
, 0x300, pic
[0], serial_hds
[0]);
2611 if (serial_hds
[1] != NULL
) {
2612 ppc405_serial_init(env
, mmio
, 0x400, pic
[1], serial_hds
[1]);
2615 ppc405_ocm_init(env
, ram_sizes
[0] + ram_sizes
[1]);
2618 gpt_irqs
[0] = pic
[19];
2619 gpt_irqs
[1] = pic
[20];
2620 gpt_irqs
[2] = pic
[21];
2621 gpt_irqs
[3] = pic
[22];
2622 gpt_irqs
[4] = pic
[23];
2623 ppc4xx_gpt_init(env
, mmio
, 0x000, gpt_irqs
);
2625 /* Uses pic[3], pic[16], pic[18] */
2627 mal_irqs
[0] = pic
[11];
2628 mal_irqs
[1] = pic
[12];
2629 mal_irqs
[2] = pic
[13];
2630 mal_irqs
[3] = pic
[14];
2631 ppc405_mal_init(env
, mal_irqs
);
2633 /* Uses pic[9], pic[15], pic[17] */
2635 ppc405ep_cpc_init(env
, clk_setup
, sysclk
);