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_phys(bdloc
+ 0x00, bd
->bi_memstart
);
55 stl_phys(bdloc
+ 0x04, bd
->bi_memsize
);
56 stl_phys(bdloc
+ 0x08, bd
->bi_flashstart
);
57 stl_phys(bdloc
+ 0x0C, bd
->bi_flashsize
);
58 stl_phys(bdloc
+ 0x10, bd
->bi_flashoffset
);
59 stl_phys(bdloc
+ 0x14, bd
->bi_sramstart
);
60 stl_phys(bdloc
+ 0x18, bd
->bi_sramsize
);
61 stl_phys(bdloc
+ 0x1C, bd
->bi_bootflags
);
62 stl_phys(bdloc
+ 0x20, bd
->bi_ipaddr
);
63 for (i
= 0; i
< 6; i
++)
64 stb_phys(bdloc
+ 0x24 + i
, bd
->bi_enetaddr
[i
]);
65 stw_phys(bdloc
+ 0x2A, bd
->bi_ethspeed
);
66 stl_phys(bdloc
+ 0x2C, bd
->bi_intfreq
);
67 stl_phys(bdloc
+ 0x30, bd
->bi_busfreq
);
68 stl_phys(bdloc
+ 0x34, bd
->bi_baudrate
);
69 for (i
= 0; i
< 4; i
++)
70 stb_phys(bdloc
+ 0x38 + i
, bd
->bi_s_version
[i
]);
71 for (i
= 0; i
< 32; i
++)
72 stb_phys(bdloc
+ 0x3C + i
, bd
->bi_s_version
[i
]);
73 stl_phys(bdloc
+ 0x5C, bd
->bi_plb_busfreq
);
74 stl_phys(bdloc
+ 0x60, bd
->bi_pci_busfreq
);
75 for (i
= 0; i
< 6; i
++)
76 stb_phys(bdloc
+ 0x64 + i
, bd
->bi_pci_enetaddr
[i
]);
78 if (flags
& 0x00000001) {
79 for (i
= 0; i
< 6; i
++)
80 stb_phys(bdloc
+ n
++, bd
->bi_pci_enetaddr2
[i
]);
82 stl_phys(bdloc
+ n
, bd
->bi_opbfreq
);
84 for (i
= 0; i
< 2; i
++) {
85 stl_phys(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
));
172 ppc_dcr_register(env
, PLB0_ACR
, plb
, &dcr_read_plb
, &dcr_write_plb
);
173 ppc_dcr_register(env
, PLB0_BEAR
, plb
, &dcr_read_plb
, &dcr_write_plb
);
174 ppc_dcr_register(env
, PLB0_BESR
, plb
, &dcr_read_plb
, &dcr_write_plb
);
175 ppc4xx_plb_reset(plb
);
176 qemu_register_reset(ppc4xx_plb_reset
, plb
);
179 /*****************************************************************************/
180 /* PLB to OPB bridge */
187 typedef struct ppc4xx_pob_t ppc4xx_pob_t
;
188 struct ppc4xx_pob_t
{
193 static target_ulong
dcr_read_pob (void *opaque
, int dcrn
)
205 ret
= pob
->besr
[dcrn
- POB0_BESR0
];
208 /* Avoid gcc warning */
216 static void dcr_write_pob (void *opaque
, int dcrn
, target_ulong val
)
228 pob
->besr
[dcrn
- POB0_BESR0
] &= ~val
;
233 static void ppc4xx_pob_reset (void *opaque
)
239 pob
->bear
= 0x00000000;
240 pob
->besr
[0] = 0x0000000;
241 pob
->besr
[1] = 0x0000000;
244 void ppc4xx_pob_init (CPUState
*env
)
248 pob
= qemu_mallocz(sizeof(ppc4xx_pob_t
));
249 ppc_dcr_register(env
, POB0_BEAR
, pob
, &dcr_read_pob
, &dcr_write_pob
);
250 ppc_dcr_register(env
, POB0_BESR0
, pob
, &dcr_read_pob
, &dcr_write_pob
);
251 ppc_dcr_register(env
, POB0_BESR1
, pob
, &dcr_read_pob
, &dcr_write_pob
);
252 qemu_register_reset(ppc4xx_pob_reset
, pob
);
253 ppc4xx_pob_reset(env
);
256 /*****************************************************************************/
258 typedef struct ppc4xx_opba_t ppc4xx_opba_t
;
259 struct ppc4xx_opba_t
{
260 target_phys_addr_t base
;
265 static uint32_t opba_readb (void *opaque
, target_phys_addr_t addr
)
271 printf("%s: addr " PADDRX
"\n", __func__
, addr
);
274 switch (addr
- opba
->base
) {
289 static void opba_writeb (void *opaque
,
290 target_phys_addr_t addr
, uint32_t value
)
295 printf("%s: addr " PADDRX
" val %08" PRIx32
"\n", __func__
, addr
, value
);
298 switch (addr
- opba
->base
) {
300 opba
->cr
= value
& 0xF8;
303 opba
->pr
= value
& 0xFF;
310 static uint32_t opba_readw (void *opaque
, target_phys_addr_t addr
)
315 printf("%s: addr " PADDRX
"\n", __func__
, addr
);
317 ret
= opba_readb(opaque
, addr
) << 8;
318 ret
|= opba_readb(opaque
, addr
+ 1);
323 static void opba_writew (void *opaque
,
324 target_phys_addr_t addr
, uint32_t value
)
327 printf("%s: addr " PADDRX
" val %08" PRIx32
"\n", __func__
, addr
, value
);
329 opba_writeb(opaque
, addr
, value
>> 8);
330 opba_writeb(opaque
, addr
+ 1, value
);
333 static uint32_t opba_readl (void *opaque
, target_phys_addr_t addr
)
338 printf("%s: addr " PADDRX
"\n", __func__
, addr
);
340 ret
= opba_readb(opaque
, addr
) << 24;
341 ret
|= opba_readb(opaque
, addr
+ 1) << 16;
346 static void opba_writel (void *opaque
,
347 target_phys_addr_t addr
, uint32_t value
)
350 printf("%s: addr " PADDRX
" val %08" PRIx32
"\n", __func__
, addr
, value
);
352 opba_writeb(opaque
, addr
, value
>> 24);
353 opba_writeb(opaque
, addr
+ 1, value
>> 16);
356 static CPUReadMemoryFunc
*opba_read
[] = {
362 static CPUWriteMemoryFunc
*opba_write
[] = {
368 static void ppc4xx_opba_reset (void *opaque
)
373 opba
->cr
= 0x00; /* No dynamic priorities - park disabled */
377 void ppc4xx_opba_init (CPUState
*env
, ppc4xx_mmio_t
*mmio
,
378 target_phys_addr_t offset
)
382 opba
= qemu_mallocz(sizeof(ppc4xx_opba_t
));
385 printf("%s: offset " PADDRX
"\n", __func__
, offset
);
387 ppc4xx_mmio_register(env
, mmio
, offset
, 0x002,
388 opba_read
, opba_write
, opba
);
389 qemu_register_reset(ppc4xx_opba_reset
, opba
);
390 ppc4xx_opba_reset(opba
);
393 /*****************************************************************************/
394 /* Code decompression controller */
397 /*****************************************************************************/
398 /* Peripheral controller */
399 typedef struct ppc4xx_ebc_t ppc4xx_ebc_t
;
400 struct ppc4xx_ebc_t
{
411 EBC0_CFGADDR
= 0x012,
412 EBC0_CFGDATA
= 0x013,
415 static target_ulong
dcr_read_ebc (void *opaque
, int dcrn
)
427 case 0x00: /* B0CR */
430 case 0x01: /* B1CR */
433 case 0x02: /* B2CR */
436 case 0x03: /* B3CR */
439 case 0x04: /* B4CR */
442 case 0x05: /* B5CR */
445 case 0x06: /* B6CR */
448 case 0x07: /* B7CR */
451 case 0x10: /* B0AP */
454 case 0x11: /* B1AP */
457 case 0x12: /* B2AP */
460 case 0x13: /* B3AP */
463 case 0x14: /* B4AP */
466 case 0x15: /* B5AP */
469 case 0x16: /* B6AP */
472 case 0x17: /* B7AP */
475 case 0x20: /* BEAR */
478 case 0x21: /* BESR0 */
481 case 0x22: /* BESR1 */
499 static void dcr_write_ebc (void *opaque
, int dcrn
, target_ulong val
)
510 case 0x00: /* B0CR */
512 case 0x01: /* B1CR */
514 case 0x02: /* B2CR */
516 case 0x03: /* B3CR */
518 case 0x04: /* B4CR */
520 case 0x05: /* B5CR */
522 case 0x06: /* B6CR */
524 case 0x07: /* B7CR */
526 case 0x10: /* B0AP */
528 case 0x11: /* B1AP */
530 case 0x12: /* B2AP */
532 case 0x13: /* B3AP */
534 case 0x14: /* B4AP */
536 case 0x15: /* B5AP */
538 case 0x16: /* B6AP */
540 case 0x17: /* B7AP */
542 case 0x20: /* BEAR */
544 case 0x21: /* BESR0 */
546 case 0x22: /* BESR1 */
559 static void ebc_reset (void *opaque
)
565 ebc
->addr
= 0x00000000;
566 ebc
->bap
[0] = 0x7F8FFE80;
567 ebc
->bcr
[0] = 0xFFE28000;
568 for (i
= 0; i
< 8; i
++) {
569 ebc
->bap
[i
] = 0x00000000;
570 ebc
->bcr
[i
] = 0x00000000;
572 ebc
->besr0
= 0x00000000;
573 ebc
->besr1
= 0x00000000;
574 ebc
->cfg
= 0x80400000;
577 void ppc405_ebc_init (CPUState
*env
)
581 ebc
= qemu_mallocz(sizeof(ppc4xx_ebc_t
));
583 qemu_register_reset(&ebc_reset
, ebc
);
584 ppc_dcr_register(env
, EBC0_CFGADDR
,
585 ebc
, &dcr_read_ebc
, &dcr_write_ebc
);
586 ppc_dcr_register(env
, EBC0_CFGDATA
,
587 ebc
, &dcr_read_ebc
, &dcr_write_ebc
);
590 /*****************************************************************************/
619 typedef struct ppc405_dma_t ppc405_dma_t
;
620 struct ppc405_dma_t
{
633 static target_ulong
dcr_read_dma (void *opaque
, int dcrn
)
642 static void dcr_write_dma (void *opaque
, int dcrn
, target_ulong val
)
649 static void ppc405_dma_reset (void *opaque
)
655 for (i
= 0; i
< 4; i
++) {
656 dma
->cr
[i
] = 0x00000000;
657 dma
->ct
[i
] = 0x00000000;
658 dma
->da
[i
] = 0x00000000;
659 dma
->sa
[i
] = 0x00000000;
660 dma
->sg
[i
] = 0x00000000;
662 dma
->sr
= 0x00000000;
663 dma
->sgc
= 0x00000000;
664 dma
->slp
= 0x7C000000;
665 dma
->pol
= 0x00000000;
668 void ppc405_dma_init (CPUState
*env
, qemu_irq irqs
[4])
672 dma
= qemu_mallocz(sizeof(ppc405_dma_t
));
673 memcpy(dma
->irqs
, irqs
, 4 * sizeof(qemu_irq
));
674 ppc405_dma_reset(dma
);
675 qemu_register_reset(&ppc405_dma_reset
, dma
);
676 ppc_dcr_register(env
, DMA0_CR0
,
677 dma
, &dcr_read_dma
, &dcr_write_dma
);
678 ppc_dcr_register(env
, DMA0_CT0
,
679 dma
, &dcr_read_dma
, &dcr_write_dma
);
680 ppc_dcr_register(env
, DMA0_DA0
,
681 dma
, &dcr_read_dma
, &dcr_write_dma
);
682 ppc_dcr_register(env
, DMA0_SA0
,
683 dma
, &dcr_read_dma
, &dcr_write_dma
);
684 ppc_dcr_register(env
, DMA0_SG0
,
685 dma
, &dcr_read_dma
, &dcr_write_dma
);
686 ppc_dcr_register(env
, DMA0_CR1
,
687 dma
, &dcr_read_dma
, &dcr_write_dma
);
688 ppc_dcr_register(env
, DMA0_CT1
,
689 dma
, &dcr_read_dma
, &dcr_write_dma
);
690 ppc_dcr_register(env
, DMA0_DA1
,
691 dma
, &dcr_read_dma
, &dcr_write_dma
);
692 ppc_dcr_register(env
, DMA0_SA1
,
693 dma
, &dcr_read_dma
, &dcr_write_dma
);
694 ppc_dcr_register(env
, DMA0_SG1
,
695 dma
, &dcr_read_dma
, &dcr_write_dma
);
696 ppc_dcr_register(env
, DMA0_CR2
,
697 dma
, &dcr_read_dma
, &dcr_write_dma
);
698 ppc_dcr_register(env
, DMA0_CT2
,
699 dma
, &dcr_read_dma
, &dcr_write_dma
);
700 ppc_dcr_register(env
, DMA0_DA2
,
701 dma
, &dcr_read_dma
, &dcr_write_dma
);
702 ppc_dcr_register(env
, DMA0_SA2
,
703 dma
, &dcr_read_dma
, &dcr_write_dma
);
704 ppc_dcr_register(env
, DMA0_SG2
,
705 dma
, &dcr_read_dma
, &dcr_write_dma
);
706 ppc_dcr_register(env
, DMA0_CR3
,
707 dma
, &dcr_read_dma
, &dcr_write_dma
);
708 ppc_dcr_register(env
, DMA0_CT3
,
709 dma
, &dcr_read_dma
, &dcr_write_dma
);
710 ppc_dcr_register(env
, DMA0_DA3
,
711 dma
, &dcr_read_dma
, &dcr_write_dma
);
712 ppc_dcr_register(env
, DMA0_SA3
,
713 dma
, &dcr_read_dma
, &dcr_write_dma
);
714 ppc_dcr_register(env
, DMA0_SG3
,
715 dma
, &dcr_read_dma
, &dcr_write_dma
);
716 ppc_dcr_register(env
, DMA0_SR
,
717 dma
, &dcr_read_dma
, &dcr_write_dma
);
718 ppc_dcr_register(env
, DMA0_SGC
,
719 dma
, &dcr_read_dma
, &dcr_write_dma
);
720 ppc_dcr_register(env
, DMA0_SLP
,
721 dma
, &dcr_read_dma
, &dcr_write_dma
);
722 ppc_dcr_register(env
, DMA0_POL
,
723 dma
, &dcr_read_dma
, &dcr_write_dma
);
726 /*****************************************************************************/
728 typedef struct ppc405_gpio_t ppc405_gpio_t
;
729 struct ppc405_gpio_t
{
730 target_phys_addr_t base
;
744 static uint32_t ppc405_gpio_readb (void *opaque
, target_phys_addr_t addr
)
750 printf("%s: addr " PADDRX
"\n", __func__
, addr
);
756 static void ppc405_gpio_writeb (void *opaque
,
757 target_phys_addr_t addr
, uint32_t value
)
763 printf("%s: addr " PADDRX
" val %08" PRIx32
"\n", __func__
, addr
, value
);
767 static uint32_t ppc405_gpio_readw (void *opaque
, target_phys_addr_t addr
)
773 printf("%s: addr " PADDRX
"\n", __func__
, addr
);
779 static void ppc405_gpio_writew (void *opaque
,
780 target_phys_addr_t addr
, uint32_t value
)
786 printf("%s: addr " PADDRX
" val %08" PRIx32
"\n", __func__
, addr
, value
);
790 static uint32_t ppc405_gpio_readl (void *opaque
, target_phys_addr_t addr
)
796 printf("%s: addr " PADDRX
"\n", __func__
, addr
);
802 static void ppc405_gpio_writel (void *opaque
,
803 target_phys_addr_t addr
, uint32_t value
)
809 printf("%s: addr " PADDRX
" val %08" PRIx32
"\n", __func__
, addr
, value
);
813 static CPUReadMemoryFunc
*ppc405_gpio_read
[] = {
819 static CPUWriteMemoryFunc
*ppc405_gpio_write
[] = {
825 static void ppc405_gpio_reset (void *opaque
)
832 void ppc405_gpio_init (CPUState
*env
, ppc4xx_mmio_t
*mmio
,
833 target_phys_addr_t offset
)
837 gpio
= qemu_mallocz(sizeof(ppc405_gpio_t
));
839 ppc405_gpio_reset(gpio
);
840 qemu_register_reset(&ppc405_gpio_reset
, gpio
);
842 printf("%s: offset " PADDRX
"\n", __func__
, offset
);
844 ppc4xx_mmio_register(env
, mmio
, offset
, 0x038,
845 ppc405_gpio_read
, ppc405_gpio_write
, gpio
);
848 /*****************************************************************************/
850 static CPUReadMemoryFunc
*serial_mm_read
[] = {
856 static CPUWriteMemoryFunc
*serial_mm_write
[] = {
862 void ppc405_serial_init (CPUState
*env
, ppc4xx_mmio_t
*mmio
,
863 target_phys_addr_t offset
, qemu_irq irq
,
864 CharDriverState
*chr
)
869 printf("%s: offset " PADDRX
"\n", __func__
, offset
);
871 serial
= serial_mm_init(offset
, 0, irq
, 399193, chr
, 0);
872 ppc4xx_mmio_register(env
, mmio
, offset
, 0x008,
873 serial_mm_read
, serial_mm_write
, serial
);
876 /*****************************************************************************/
880 OCM0_ISACNTL
= 0x019,
882 OCM0_DSACNTL
= 0x01B,
885 typedef struct ppc405_ocm_t ppc405_ocm_t
;
886 struct ppc405_ocm_t
{
894 static void ocm_update_mappings (ppc405_ocm_t
*ocm
,
895 uint32_t isarc
, uint32_t isacntl
,
896 uint32_t dsarc
, uint32_t dsacntl
)
899 printf("OCM update ISA %08" PRIx32
" %08" PRIx32
" (%08" PRIx32
900 " %08" PRIx32
") DSA %08" PRIx32
" %08" PRIx32
901 " (%08" PRIx32
" %08" PRIx32
")\n",
902 isarc
, isacntl
, dsarc
, dsacntl
,
903 ocm
->isarc
, ocm
->isacntl
, ocm
->dsarc
, ocm
->dsacntl
);
905 if (ocm
->isarc
!= isarc
||
906 (ocm
->isacntl
& 0x80000000) != (isacntl
& 0x80000000)) {
907 if (ocm
->isacntl
& 0x80000000) {
908 /* Unmap previously assigned memory region */
909 printf("OCM unmap ISA %08" PRIx32
"\n", ocm
->isarc
);
910 cpu_register_physical_memory(ocm
->isarc
, 0x04000000,
913 if (isacntl
& 0x80000000) {
914 /* Map new instruction memory region */
916 printf("OCM map ISA %08" PRIx32
"\n", isarc
);
918 cpu_register_physical_memory(isarc
, 0x04000000,
919 ocm
->offset
| IO_MEM_RAM
);
922 if (ocm
->dsarc
!= dsarc
||
923 (ocm
->dsacntl
& 0x80000000) != (dsacntl
& 0x80000000)) {
924 if (ocm
->dsacntl
& 0x80000000) {
925 /* Beware not to unmap the region we just mapped */
926 if (!(isacntl
& 0x80000000) || ocm
->dsarc
!= isarc
) {
927 /* Unmap previously assigned memory region */
929 printf("OCM unmap DSA %08" PRIx32
"\n", ocm
->dsarc
);
931 cpu_register_physical_memory(ocm
->dsarc
, 0x04000000,
935 if (dsacntl
& 0x80000000) {
936 /* Beware not to remap the region we just mapped */
937 if (!(isacntl
& 0x80000000) || dsarc
!= isarc
) {
938 /* Map new data memory region */
940 printf("OCM map DSA %08" PRIx32
"\n", dsarc
);
942 cpu_register_physical_memory(dsarc
, 0x04000000,
943 ocm
->offset
| IO_MEM_RAM
);
949 static target_ulong
dcr_read_ocm (void *opaque
, int dcrn
)
976 static void dcr_write_ocm (void *opaque
, int dcrn
, target_ulong val
)
979 uint32_t isarc
, dsarc
, isacntl
, dsacntl
;
984 isacntl
= ocm
->isacntl
;
985 dsacntl
= ocm
->dsacntl
;
988 isarc
= val
& 0xFC000000;
991 isacntl
= val
& 0xC0000000;
994 isarc
= val
& 0xFC000000;
997 isacntl
= val
& 0xC0000000;
1000 ocm_update_mappings(ocm
, isarc
, isacntl
, dsarc
, dsacntl
);
1003 ocm
->isacntl
= isacntl
;
1004 ocm
->dsacntl
= dsacntl
;
1007 static void ocm_reset (void *opaque
)
1010 uint32_t isarc
, dsarc
, isacntl
, dsacntl
;
1014 isacntl
= 0x00000000;
1016 dsacntl
= 0x00000000;
1017 ocm_update_mappings(ocm
, isarc
, isacntl
, dsarc
, dsacntl
);
1020 ocm
->isacntl
= isacntl
;
1021 ocm
->dsacntl
= dsacntl
;
1024 void ppc405_ocm_init (CPUState
*env
)
1028 ocm
= qemu_mallocz(sizeof(ppc405_ocm_t
));
1029 ocm
->offset
= qemu_ram_alloc(4096);
1031 qemu_register_reset(&ocm_reset
, ocm
);
1032 ppc_dcr_register(env
, OCM0_ISARC
,
1033 ocm
, &dcr_read_ocm
, &dcr_write_ocm
);
1034 ppc_dcr_register(env
, OCM0_ISACNTL
,
1035 ocm
, &dcr_read_ocm
, &dcr_write_ocm
);
1036 ppc_dcr_register(env
, OCM0_DSARC
,
1037 ocm
, &dcr_read_ocm
, &dcr_write_ocm
);
1038 ppc_dcr_register(env
, OCM0_DSACNTL
,
1039 ocm
, &dcr_read_ocm
, &dcr_write_ocm
);
1042 /*****************************************************************************/
1043 /* I2C controller */
1044 typedef struct ppc4xx_i2c_t ppc4xx_i2c_t
;
1045 struct ppc4xx_i2c_t
{
1046 target_phys_addr_t base
;
1065 static uint32_t ppc4xx_i2c_readb (void *opaque
, target_phys_addr_t addr
)
1071 printf("%s: addr " PADDRX
"\n", __func__
, addr
);
1074 switch (addr
- i2c
->base
) {
1076 // i2c_readbyte(&i2c->mdata);
1116 ret
= i2c
->xtcntlss
;
1119 ret
= i2c
->directcntl
;
1126 printf("%s: addr " PADDRX
" %02" PRIx32
"\n", __func__
, addr
, ret
);
1132 static void ppc4xx_i2c_writeb (void *opaque
,
1133 target_phys_addr_t addr
, uint32_t value
)
1138 printf("%s: addr " PADDRX
" val %08" PRIx32
"\n", __func__
, addr
, value
);
1141 switch (addr
- i2c
->base
) {
1144 // i2c_sendbyte(&i2c->mdata);
1159 i2c
->mdcntl
= value
& 0xDF;
1162 i2c
->sts
&= ~(value
& 0x0A);
1165 i2c
->extsts
&= ~(value
& 0x8F);
1174 i2c
->clkdiv
= value
;
1177 i2c
->intrmsk
= value
;
1180 i2c
->xfrcnt
= value
& 0x77;
1183 i2c
->xtcntlss
= value
;
1186 i2c
->directcntl
= value
& 0x7;
1191 static uint32_t ppc4xx_i2c_readw (void *opaque
, target_phys_addr_t addr
)
1196 printf("%s: addr " PADDRX
"\n", __func__
, addr
);
1198 ret
= ppc4xx_i2c_readb(opaque
, addr
) << 8;
1199 ret
|= ppc4xx_i2c_readb(opaque
, addr
+ 1);
1204 static void ppc4xx_i2c_writew (void *opaque
,
1205 target_phys_addr_t addr
, uint32_t value
)
1208 printf("%s: addr " PADDRX
" val %08" PRIx32
"\n", __func__
, addr
, value
);
1210 ppc4xx_i2c_writeb(opaque
, addr
, value
>> 8);
1211 ppc4xx_i2c_writeb(opaque
, addr
+ 1, value
);
1214 static uint32_t ppc4xx_i2c_readl (void *opaque
, target_phys_addr_t addr
)
1219 printf("%s: addr " PADDRX
"\n", __func__
, addr
);
1221 ret
= ppc4xx_i2c_readb(opaque
, addr
) << 24;
1222 ret
|= ppc4xx_i2c_readb(opaque
, addr
+ 1) << 16;
1223 ret
|= ppc4xx_i2c_readb(opaque
, addr
+ 2) << 8;
1224 ret
|= ppc4xx_i2c_readb(opaque
, addr
+ 3);
1229 static void ppc4xx_i2c_writel (void *opaque
,
1230 target_phys_addr_t addr
, uint32_t value
)
1233 printf("%s: addr " PADDRX
" val %08" PRIx32
"\n", __func__
, addr
, value
);
1235 ppc4xx_i2c_writeb(opaque
, addr
, value
>> 24);
1236 ppc4xx_i2c_writeb(opaque
, addr
+ 1, value
>> 16);
1237 ppc4xx_i2c_writeb(opaque
, addr
+ 2, value
>> 8);
1238 ppc4xx_i2c_writeb(opaque
, addr
+ 3, value
);
1241 static CPUReadMemoryFunc
*i2c_read
[] = {
1247 static CPUWriteMemoryFunc
*i2c_write
[] = {
1253 static void ppc4xx_i2c_reset (void *opaque
)
1266 i2c
->directcntl
= 0x0F;
1269 void ppc405_i2c_init (CPUState
*env
, ppc4xx_mmio_t
*mmio
,
1270 target_phys_addr_t offset
, qemu_irq irq
)
1274 i2c
= qemu_mallocz(sizeof(ppc4xx_i2c_t
));
1277 ppc4xx_i2c_reset(i2c
);
1279 printf("%s: offset " PADDRX
"\n", __func__
, offset
);
1281 ppc4xx_mmio_register(env
, mmio
, offset
, 0x011,
1282 i2c_read
, i2c_write
, i2c
);
1283 qemu_register_reset(ppc4xx_i2c_reset
, i2c
);
1286 /*****************************************************************************/
1287 /* General purpose timers */
1288 typedef struct ppc4xx_gpt_t ppc4xx_gpt_t
;
1289 struct ppc4xx_gpt_t
{
1290 target_phys_addr_t base
;
1293 struct QEMUTimer
*timer
;
1304 static uint32_t ppc4xx_gpt_readb (void *opaque
, target_phys_addr_t addr
)
1307 printf("%s: addr " PADDRX
"\n", __func__
, addr
);
1309 /* XXX: generate a bus fault */
1313 static void ppc4xx_gpt_writeb (void *opaque
,
1314 target_phys_addr_t addr
, uint32_t value
)
1317 printf("%s: addr " PADDRX
" val %08" PRIx32
"\n", __func__
, addr
, value
);
1319 /* XXX: generate a bus fault */
1322 static uint32_t ppc4xx_gpt_readw (void *opaque
, target_phys_addr_t addr
)
1325 printf("%s: addr " PADDRX
"\n", __func__
, addr
);
1327 /* XXX: generate a bus fault */
1331 static void ppc4xx_gpt_writew (void *opaque
,
1332 target_phys_addr_t addr
, uint32_t value
)
1335 printf("%s: addr " PADDRX
" val %08" PRIx32
"\n", __func__
, addr
, value
);
1337 /* XXX: generate a bus fault */
1340 static int ppc4xx_gpt_compare (ppc4xx_gpt_t
*gpt
, int n
)
1346 static void ppc4xx_gpt_set_output (ppc4xx_gpt_t
*gpt
, int n
, int level
)
1351 static void ppc4xx_gpt_set_outputs (ppc4xx_gpt_t
*gpt
)
1357 for (i
= 0; i
< 5; i
++) {
1358 if (gpt
->oe
& mask
) {
1359 /* Output is enabled */
1360 if (ppc4xx_gpt_compare(gpt
, i
)) {
1361 /* Comparison is OK */
1362 ppc4xx_gpt_set_output(gpt
, i
, gpt
->ol
& mask
);
1364 /* Comparison is KO */
1365 ppc4xx_gpt_set_output(gpt
, i
, gpt
->ol
& mask
? 0 : 1);
1372 static void ppc4xx_gpt_set_irqs (ppc4xx_gpt_t
*gpt
)
1378 for (i
= 0; i
< 5; i
++) {
1379 if (gpt
->is
& gpt
->im
& mask
)
1380 qemu_irq_raise(gpt
->irqs
[i
]);
1382 qemu_irq_lower(gpt
->irqs
[i
]);
1387 static void ppc4xx_gpt_compute_timer (ppc4xx_gpt_t
*gpt
)
1392 static uint32_t ppc4xx_gpt_readl (void *opaque
, target_phys_addr_t addr
)
1399 printf("%s: addr " PADDRX
"\n", __func__
, addr
);
1402 switch (addr
- gpt
->base
) {
1404 /* Time base counter */
1405 ret
= muldiv64(qemu_get_clock(vm_clock
) + gpt
->tb_offset
,
1406 gpt
->tb_freq
, ticks_per_sec
);
1417 /* Interrupt mask */
1422 /* Interrupt status */
1426 /* Interrupt enable */
1431 idx
= ((addr
- gpt
->base
) - 0x80) >> 2;
1432 ret
= gpt
->comp
[idx
];
1436 idx
= ((addr
- gpt
->base
) - 0xC0) >> 2;
1437 ret
= gpt
->mask
[idx
];
1447 static void ppc4xx_gpt_writel (void *opaque
,
1448 target_phys_addr_t addr
, uint32_t value
)
1454 printf("%s: addr " PADDRX
" val %08" PRIx32
"\n", __func__
, addr
, value
);
1457 switch (addr
- gpt
->base
) {
1459 /* Time base counter */
1460 gpt
->tb_offset
= muldiv64(value
, ticks_per_sec
, gpt
->tb_freq
)
1461 - qemu_get_clock(vm_clock
);
1462 ppc4xx_gpt_compute_timer(gpt
);
1466 gpt
->oe
= value
& 0xF8000000;
1467 ppc4xx_gpt_set_outputs(gpt
);
1471 gpt
->ol
= value
& 0xF8000000;
1472 ppc4xx_gpt_set_outputs(gpt
);
1475 /* Interrupt mask */
1476 gpt
->im
= value
& 0x0000F800;
1479 /* Interrupt status set */
1480 gpt
->is
|= value
& 0x0000F800;
1481 ppc4xx_gpt_set_irqs(gpt
);
1484 /* Interrupt status clear */
1485 gpt
->is
&= ~(value
& 0x0000F800);
1486 ppc4xx_gpt_set_irqs(gpt
);
1489 /* Interrupt enable */
1490 gpt
->ie
= value
& 0x0000F800;
1491 ppc4xx_gpt_set_irqs(gpt
);
1495 idx
= ((addr
- gpt
->base
) - 0x80) >> 2;
1496 gpt
->comp
[idx
] = value
& 0xF8000000;
1497 ppc4xx_gpt_compute_timer(gpt
);
1501 idx
= ((addr
- gpt
->base
) - 0xC0) >> 2;
1502 gpt
->mask
[idx
] = value
& 0xF8000000;
1503 ppc4xx_gpt_compute_timer(gpt
);
1508 static CPUReadMemoryFunc
*gpt_read
[] = {
1514 static CPUWriteMemoryFunc
*gpt_write
[] = {
1520 static void ppc4xx_gpt_cb (void *opaque
)
1525 ppc4xx_gpt_set_irqs(gpt
);
1526 ppc4xx_gpt_set_outputs(gpt
);
1527 ppc4xx_gpt_compute_timer(gpt
);
1530 static void ppc4xx_gpt_reset (void *opaque
)
1536 qemu_del_timer(gpt
->timer
);
1537 gpt
->oe
= 0x00000000;
1538 gpt
->ol
= 0x00000000;
1539 gpt
->im
= 0x00000000;
1540 gpt
->is
= 0x00000000;
1541 gpt
->ie
= 0x00000000;
1542 for (i
= 0; i
< 5; i
++) {
1543 gpt
->comp
[i
] = 0x00000000;
1544 gpt
->mask
[i
] = 0x00000000;
1548 void ppc4xx_gpt_init (CPUState
*env
, ppc4xx_mmio_t
*mmio
,
1549 target_phys_addr_t offset
, qemu_irq irqs
[5])
1554 gpt
= qemu_mallocz(sizeof(ppc4xx_gpt_t
));
1556 for (i
= 0; i
< 5; i
++)
1557 gpt
->irqs
[i
] = irqs
[i
];
1558 gpt
->timer
= qemu_new_timer(vm_clock
, &ppc4xx_gpt_cb
, gpt
);
1559 ppc4xx_gpt_reset(gpt
);
1561 printf("%s: offset " PADDRX
"\n", __func__
, offset
);
1563 ppc4xx_mmio_register(env
, mmio
, offset
, 0x0D4,
1564 gpt_read
, gpt_write
, gpt
);
1565 qemu_register_reset(ppc4xx_gpt_reset
, gpt
);
1568 /*****************************************************************************/
1574 MAL0_TXCASR
= 0x184,
1575 MAL0_TXCARR
= 0x185,
1576 MAL0_TXEOBISR
= 0x186,
1577 MAL0_TXDEIR
= 0x187,
1578 MAL0_RXCASR
= 0x190,
1579 MAL0_RXCARR
= 0x191,
1580 MAL0_RXEOBISR
= 0x192,
1581 MAL0_RXDEIR
= 0x193,
1582 MAL0_TXCTP0R
= 0x1A0,
1583 MAL0_TXCTP1R
= 0x1A1,
1584 MAL0_TXCTP2R
= 0x1A2,
1585 MAL0_TXCTP3R
= 0x1A3,
1586 MAL0_RXCTP0R
= 0x1C0,
1587 MAL0_RXCTP1R
= 0x1C1,
1592 typedef struct ppc40x_mal_t ppc40x_mal_t
;
1593 struct ppc40x_mal_t
{
1611 static void ppc40x_mal_reset (void *opaque
);
1613 static target_ulong
dcr_read_mal (void *opaque
, int dcrn
)
1636 ret
= mal
->txeobisr
;
1648 ret
= mal
->rxeobisr
;
1654 ret
= mal
->txctpr
[0];
1657 ret
= mal
->txctpr
[1];
1660 ret
= mal
->txctpr
[2];
1663 ret
= mal
->txctpr
[3];
1666 ret
= mal
->rxctpr
[0];
1669 ret
= mal
->rxctpr
[1];
1685 static void dcr_write_mal (void *opaque
, int dcrn
, target_ulong val
)
1693 if (val
& 0x80000000)
1694 ppc40x_mal_reset(mal
);
1695 mal
->cfg
= val
& 0x00FFC087;
1702 mal
->ier
= val
& 0x0000001F;
1705 mal
->txcasr
= val
& 0xF0000000;
1708 mal
->txcarr
= val
& 0xF0000000;
1712 mal
->txeobisr
&= ~val
;
1716 mal
->txdeir
&= ~val
;
1719 mal
->rxcasr
= val
& 0xC0000000;
1722 mal
->rxcarr
= val
& 0xC0000000;
1726 mal
->rxeobisr
&= ~val
;
1730 mal
->rxdeir
&= ~val
;
1744 mal
->txctpr
[idx
] = val
;
1752 mal
->rxctpr
[idx
] = val
;
1756 goto update_rx_size
;
1760 mal
->rcbs
[idx
] = val
& 0x000000FF;
1765 static void ppc40x_mal_reset (void *opaque
)
1770 mal
->cfg
= 0x0007C000;
1771 mal
->esr
= 0x00000000;
1772 mal
->ier
= 0x00000000;
1773 mal
->rxcasr
= 0x00000000;
1774 mal
->rxdeir
= 0x00000000;
1775 mal
->rxeobisr
= 0x00000000;
1776 mal
->txcasr
= 0x00000000;
1777 mal
->txdeir
= 0x00000000;
1778 mal
->txeobisr
= 0x00000000;
1781 void ppc405_mal_init (CPUState
*env
, qemu_irq irqs
[4])
1786 mal
= qemu_mallocz(sizeof(ppc40x_mal_t
));
1787 for (i
= 0; i
< 4; i
++)
1788 mal
->irqs
[i
] = irqs
[i
];
1789 ppc40x_mal_reset(mal
);
1790 qemu_register_reset(&ppc40x_mal_reset
, mal
);
1791 ppc_dcr_register(env
, MAL0_CFG
,
1792 mal
, &dcr_read_mal
, &dcr_write_mal
);
1793 ppc_dcr_register(env
, MAL0_ESR
,
1794 mal
, &dcr_read_mal
, &dcr_write_mal
);
1795 ppc_dcr_register(env
, MAL0_IER
,
1796 mal
, &dcr_read_mal
, &dcr_write_mal
);
1797 ppc_dcr_register(env
, MAL0_TXCASR
,
1798 mal
, &dcr_read_mal
, &dcr_write_mal
);
1799 ppc_dcr_register(env
, MAL0_TXCARR
,
1800 mal
, &dcr_read_mal
, &dcr_write_mal
);
1801 ppc_dcr_register(env
, MAL0_TXEOBISR
,
1802 mal
, &dcr_read_mal
, &dcr_write_mal
);
1803 ppc_dcr_register(env
, MAL0_TXDEIR
,
1804 mal
, &dcr_read_mal
, &dcr_write_mal
);
1805 ppc_dcr_register(env
, MAL0_RXCASR
,
1806 mal
, &dcr_read_mal
, &dcr_write_mal
);
1807 ppc_dcr_register(env
, MAL0_RXCARR
,
1808 mal
, &dcr_read_mal
, &dcr_write_mal
);
1809 ppc_dcr_register(env
, MAL0_RXEOBISR
,
1810 mal
, &dcr_read_mal
, &dcr_write_mal
);
1811 ppc_dcr_register(env
, MAL0_RXDEIR
,
1812 mal
, &dcr_read_mal
, &dcr_write_mal
);
1813 ppc_dcr_register(env
, MAL0_TXCTP0R
,
1814 mal
, &dcr_read_mal
, &dcr_write_mal
);
1815 ppc_dcr_register(env
, MAL0_TXCTP1R
,
1816 mal
, &dcr_read_mal
, &dcr_write_mal
);
1817 ppc_dcr_register(env
, MAL0_TXCTP2R
,
1818 mal
, &dcr_read_mal
, &dcr_write_mal
);
1819 ppc_dcr_register(env
, MAL0_TXCTP3R
,
1820 mal
, &dcr_read_mal
, &dcr_write_mal
);
1821 ppc_dcr_register(env
, MAL0_RXCTP0R
,
1822 mal
, &dcr_read_mal
, &dcr_write_mal
);
1823 ppc_dcr_register(env
, MAL0_RXCTP1R
,
1824 mal
, &dcr_read_mal
, &dcr_write_mal
);
1825 ppc_dcr_register(env
, MAL0_RCBS0
,
1826 mal
, &dcr_read_mal
, &dcr_write_mal
);
1827 ppc_dcr_register(env
, MAL0_RCBS1
,
1828 mal
, &dcr_read_mal
, &dcr_write_mal
);
1831 /*****************************************************************************/
1833 void ppc40x_core_reset (CPUState
*env
)
1837 printf("Reset PowerPC core\n");
1838 env
->interrupt_request
|= CPU_INTERRUPT_EXITTB
;
1843 qemu_system_reset_request();
1845 dbsr
= env
->spr
[SPR_40x_DBSR
];
1846 dbsr
&= ~0x00000300;
1848 env
->spr
[SPR_40x_DBSR
] = dbsr
;
1851 void ppc40x_chip_reset (CPUState
*env
)
1855 printf("Reset PowerPC chip\n");
1856 env
->interrupt_request
|= CPU_INTERRUPT_EXITTB
;
1861 qemu_system_reset_request();
1863 /* XXX: TODO reset all internal peripherals */
1864 dbsr
= env
->spr
[SPR_40x_DBSR
];
1865 dbsr
&= ~0x00000300;
1867 env
->spr
[SPR_40x_DBSR
] = dbsr
;
1870 void ppc40x_system_reset (CPUState
*env
)
1872 printf("Reset PowerPC system\n");
1873 qemu_system_reset_request();
1876 void store_40x_dbcr0 (CPUState
*env
, uint32_t val
)
1878 switch ((val
>> 28) & 0x3) {
1884 ppc40x_core_reset(env
);
1888 ppc40x_chip_reset(env
);
1892 ppc40x_system_reset(env
);
1897 /*****************************************************************************/
1900 PPC405CR_CPC0_PLLMR
= 0x0B0,
1901 PPC405CR_CPC0_CR0
= 0x0B1,
1902 PPC405CR_CPC0_CR1
= 0x0B2,
1903 PPC405CR_CPC0_PSR
= 0x0B4,
1904 PPC405CR_CPC0_JTAGID
= 0x0B5,
1905 PPC405CR_CPC0_ER
= 0x0B9,
1906 PPC405CR_CPC0_FR
= 0x0BA,
1907 PPC405CR_CPC0_SR
= 0x0BB,
1911 PPC405CR_CPU_CLK
= 0,
1912 PPC405CR_TMR_CLK
= 1,
1913 PPC405CR_PLB_CLK
= 2,
1914 PPC405CR_SDRAM_CLK
= 3,
1915 PPC405CR_OPB_CLK
= 4,
1916 PPC405CR_EXT_CLK
= 5,
1917 PPC405CR_UART_CLK
= 6,
1918 PPC405CR_CLK_NB
= 7,
1921 typedef struct ppc405cr_cpc_t ppc405cr_cpc_t
;
1922 struct ppc405cr_cpc_t
{
1923 clk_setup_t clk_setup
[PPC405CR_CLK_NB
];
1934 static void ppc405cr_clk_setup (ppc405cr_cpc_t
*cpc
)
1936 uint64_t VCO_out
, PLL_out
;
1937 uint32_t CPU_clk
, TMR_clk
, SDRAM_clk
, PLB_clk
, OPB_clk
, EXT_clk
, UART_clk
;
1940 D0
= ((cpc
->pllmr
>> 26) & 0x3) + 1; /* CBDV */
1941 if (cpc
->pllmr
& 0x80000000) {
1942 D1
= (((cpc
->pllmr
>> 20) - 1) & 0xF) + 1; /* FBDV */
1943 D2
= 8 - ((cpc
->pllmr
>> 16) & 0x7); /* FWDVA */
1945 VCO_out
= cpc
->sysclk
* M
;
1946 if (VCO_out
< 400000000 || VCO_out
> 800000000) {
1947 /* PLL cannot lock */
1948 cpc
->pllmr
&= ~0x80000000;
1951 PLL_out
= VCO_out
/ D2
;
1956 PLL_out
= cpc
->sysclk
* M
;
1959 if (cpc
->cr1
& 0x00800000)
1960 TMR_clk
= cpc
->sysclk
; /* Should have a separate clock */
1963 PLB_clk
= CPU_clk
/ D0
;
1964 SDRAM_clk
= PLB_clk
;
1965 D0
= ((cpc
->pllmr
>> 10) & 0x3) + 1;
1966 OPB_clk
= PLB_clk
/ D0
;
1967 D0
= ((cpc
->pllmr
>> 24) & 0x3) + 2;
1968 EXT_clk
= PLB_clk
/ D0
;
1969 D0
= ((cpc
->cr0
>> 1) & 0x1F) + 1;
1970 UART_clk
= CPU_clk
/ D0
;
1971 /* Setup CPU clocks */
1972 clk_setup(&cpc
->clk_setup
[PPC405CR_CPU_CLK
], CPU_clk
);
1973 /* Setup time-base clock */
1974 clk_setup(&cpc
->clk_setup
[PPC405CR_TMR_CLK
], TMR_clk
);
1975 /* Setup PLB clock */
1976 clk_setup(&cpc
->clk_setup
[PPC405CR_PLB_CLK
], PLB_clk
);
1977 /* Setup SDRAM clock */
1978 clk_setup(&cpc
->clk_setup
[PPC405CR_SDRAM_CLK
], SDRAM_clk
);
1979 /* Setup OPB clock */
1980 clk_setup(&cpc
->clk_setup
[PPC405CR_OPB_CLK
], OPB_clk
);
1981 /* Setup external clock */
1982 clk_setup(&cpc
->clk_setup
[PPC405CR_EXT_CLK
], EXT_clk
);
1983 /* Setup UART clock */
1984 clk_setup(&cpc
->clk_setup
[PPC405CR_UART_CLK
], UART_clk
);
1987 static target_ulong
dcr_read_crcpc (void *opaque
, int dcrn
)
1989 ppc405cr_cpc_t
*cpc
;
1994 case PPC405CR_CPC0_PLLMR
:
1997 case PPC405CR_CPC0_CR0
:
2000 case PPC405CR_CPC0_CR1
:
2003 case PPC405CR_CPC0_PSR
:
2006 case PPC405CR_CPC0_JTAGID
:
2009 case PPC405CR_CPC0_ER
:
2012 case PPC405CR_CPC0_FR
:
2015 case PPC405CR_CPC0_SR
:
2016 ret
= ~(cpc
->er
| cpc
->fr
) & 0xFFFF0000;
2019 /* Avoid gcc warning */
2027 static void dcr_write_crcpc (void *opaque
, int dcrn
, target_ulong val
)
2029 ppc405cr_cpc_t
*cpc
;
2033 case PPC405CR_CPC0_PLLMR
:
2034 cpc
->pllmr
= val
& 0xFFF77C3F;
2036 case PPC405CR_CPC0_CR0
:
2037 cpc
->cr0
= val
& 0x0FFFFFFE;
2039 case PPC405CR_CPC0_CR1
:
2040 cpc
->cr1
= val
& 0x00800000;
2042 case PPC405CR_CPC0_PSR
:
2045 case PPC405CR_CPC0_JTAGID
:
2048 case PPC405CR_CPC0_ER
:
2049 cpc
->er
= val
& 0xBFFC0000;
2051 case PPC405CR_CPC0_FR
:
2052 cpc
->fr
= val
& 0xBFFC0000;
2054 case PPC405CR_CPC0_SR
:
2060 static void ppc405cr_cpc_reset (void *opaque
)
2062 ppc405cr_cpc_t
*cpc
;
2066 /* Compute PLLMR value from PSR settings */
2067 cpc
->pllmr
= 0x80000000;
2069 switch ((cpc
->psr
>> 30) & 3) {
2072 cpc
->pllmr
&= ~0x80000000;
2076 cpc
->pllmr
|= 5 << 16;
2080 cpc
->pllmr
|= 4 << 16;
2084 cpc
->pllmr
|= 2 << 16;
2088 D
= (cpc
->psr
>> 28) & 3;
2089 cpc
->pllmr
|= (D
+ 1) << 20;
2091 D
= (cpc
->psr
>> 25) & 7;
2106 D
= (cpc
->psr
>> 23) & 3;
2107 cpc
->pllmr
|= D
<< 26;
2109 D
= (cpc
->psr
>> 21) & 3;
2110 cpc
->pllmr
|= D
<< 10;
2112 D
= (cpc
->psr
>> 17) & 3;
2113 cpc
->pllmr
|= D
<< 24;
2114 cpc
->cr0
= 0x0000003C;
2115 cpc
->cr1
= 0x2B0D8800;
2116 cpc
->er
= 0x00000000;
2117 cpc
->fr
= 0x00000000;
2118 ppc405cr_clk_setup(cpc
);
2121 static void ppc405cr_clk_init (ppc405cr_cpc_t
*cpc
)
2125 /* XXX: this should be read from IO pins */
2126 cpc
->psr
= 0x00000000; /* 8 bits ROM */
2128 D
= 0x2; /* Divide by 4 */
2129 cpc
->psr
|= D
<< 30;
2131 D
= 0x1; /* Divide by 2 */
2132 cpc
->psr
|= D
<< 28;
2134 D
= 0x1; /* Divide by 2 */
2135 cpc
->psr
|= D
<< 23;
2137 D
= 0x5; /* M = 16 */
2138 cpc
->psr
|= D
<< 25;
2140 D
= 0x1; /* Divide by 2 */
2141 cpc
->psr
|= D
<< 21;
2143 D
= 0x2; /* Divide by 4 */
2144 cpc
->psr
|= D
<< 17;
2147 static void ppc405cr_cpc_init (CPUState
*env
, clk_setup_t clk_setup
[7],
2150 ppc405cr_cpc_t
*cpc
;
2152 cpc
= qemu_mallocz(sizeof(ppc405cr_cpc_t
));
2153 memcpy(cpc
->clk_setup
, clk_setup
,
2154 PPC405CR_CLK_NB
* sizeof(clk_setup_t
));
2155 cpc
->sysclk
= sysclk
;
2156 cpc
->jtagid
= 0x42051049;
2157 ppc_dcr_register(env
, PPC405CR_CPC0_PSR
, cpc
,
2158 &dcr_read_crcpc
, &dcr_write_crcpc
);
2159 ppc_dcr_register(env
, PPC405CR_CPC0_CR0
, cpc
,
2160 &dcr_read_crcpc
, &dcr_write_crcpc
);
2161 ppc_dcr_register(env
, PPC405CR_CPC0_CR1
, cpc
,
2162 &dcr_read_crcpc
, &dcr_write_crcpc
);
2163 ppc_dcr_register(env
, PPC405CR_CPC0_JTAGID
, cpc
,
2164 &dcr_read_crcpc
, &dcr_write_crcpc
);
2165 ppc_dcr_register(env
, PPC405CR_CPC0_PLLMR
, cpc
,
2166 &dcr_read_crcpc
, &dcr_write_crcpc
);
2167 ppc_dcr_register(env
, PPC405CR_CPC0_ER
, cpc
,
2168 &dcr_read_crcpc
, &dcr_write_crcpc
);
2169 ppc_dcr_register(env
, PPC405CR_CPC0_FR
, cpc
,
2170 &dcr_read_crcpc
, &dcr_write_crcpc
);
2171 ppc_dcr_register(env
, PPC405CR_CPC0_SR
, cpc
,
2172 &dcr_read_crcpc
, &dcr_write_crcpc
);
2173 ppc405cr_clk_init(cpc
);
2174 qemu_register_reset(ppc405cr_cpc_reset
, cpc
);
2175 ppc405cr_cpc_reset(cpc
);
2178 CPUState
*ppc405cr_init (target_phys_addr_t ram_bases
[4],
2179 target_phys_addr_t ram_sizes
[4],
2180 uint32_t sysclk
, qemu_irq
**picp
,
2183 clk_setup_t clk_setup
[PPC405CR_CLK_NB
];
2184 qemu_irq dma_irqs
[4];
2186 ppc4xx_mmio_t
*mmio
;
2187 qemu_irq
*pic
, *irqs
;
2189 memset(clk_setup
, 0, sizeof(clk_setup
));
2190 env
= ppc4xx_init("405cr", &clk_setup
[PPC405CR_CPU_CLK
],
2191 &clk_setup
[PPC405CR_TMR_CLK
], sysclk
);
2192 /* Memory mapped devices registers */
2193 mmio
= ppc4xx_mmio_init(env
, 0xEF600000);
2195 ppc4xx_plb_init(env
);
2196 /* PLB to OPB bridge */
2197 ppc4xx_pob_init(env
);
2199 ppc4xx_opba_init(env
, mmio
, 0x600);
2200 /* Universal interrupt controller */
2201 irqs
= qemu_mallocz(sizeof(qemu_irq
) * PPCUIC_OUTPUT_NB
);
2202 irqs
[PPCUIC_OUTPUT_INT
] =
2203 ((qemu_irq
*)env
->irq_inputs
)[PPC40x_INPUT_INT
];
2204 irqs
[PPCUIC_OUTPUT_CINT
] =
2205 ((qemu_irq
*)env
->irq_inputs
)[PPC40x_INPUT_CINT
];
2206 pic
= ppcuic_init(env
, irqs
, 0x0C0, 0, 1);
2208 /* SDRAM controller */
2209 ppc4xx_sdram_init(env
, pic
[14], 1, ram_bases
, ram_sizes
, do_init
);
2210 /* External bus controller */
2211 ppc405_ebc_init(env
);
2212 /* DMA controller */
2213 dma_irqs
[0] = pic
[26];
2214 dma_irqs
[1] = pic
[25];
2215 dma_irqs
[2] = pic
[24];
2216 dma_irqs
[3] = pic
[23];
2217 ppc405_dma_init(env
, dma_irqs
);
2219 if (serial_hds
[0] != NULL
) {
2220 ppc405_serial_init(env
, mmio
, 0x300, pic
[0], serial_hds
[0]);
2222 if (serial_hds
[1] != NULL
) {
2223 ppc405_serial_init(env
, mmio
, 0x400, pic
[1], serial_hds
[1]);
2225 /* IIC controller */
2226 ppc405_i2c_init(env
, mmio
, 0x500, pic
[2]);
2228 ppc405_gpio_init(env
, mmio
, 0x700);
2230 ppc405cr_cpc_init(env
, clk_setup
, sysclk
);
2235 /*****************************************************************************/
2239 PPC405EP_CPC0_PLLMR0
= 0x0F0,
2240 PPC405EP_CPC0_BOOT
= 0x0F1,
2241 PPC405EP_CPC0_EPCTL
= 0x0F3,
2242 PPC405EP_CPC0_PLLMR1
= 0x0F4,
2243 PPC405EP_CPC0_UCR
= 0x0F5,
2244 PPC405EP_CPC0_SRR
= 0x0F6,
2245 PPC405EP_CPC0_JTAGID
= 0x0F7,
2246 PPC405EP_CPC0_PCI
= 0x0F9,
2248 PPC405EP_CPC0_ER
= xxx
,
2249 PPC405EP_CPC0_FR
= xxx
,
2250 PPC405EP_CPC0_SR
= xxx
,
2255 PPC405EP_CPU_CLK
= 0,
2256 PPC405EP_PLB_CLK
= 1,
2257 PPC405EP_OPB_CLK
= 2,
2258 PPC405EP_EBC_CLK
= 3,
2259 PPC405EP_MAL_CLK
= 4,
2260 PPC405EP_PCI_CLK
= 5,
2261 PPC405EP_UART0_CLK
= 6,
2262 PPC405EP_UART1_CLK
= 7,
2263 PPC405EP_CLK_NB
= 8,
2266 typedef struct ppc405ep_cpc_t ppc405ep_cpc_t
;
2267 struct ppc405ep_cpc_t
{
2269 clk_setup_t clk_setup
[PPC405EP_CLK_NB
];
2277 /* Clock and power management */
2283 static void ppc405ep_compute_clocks (ppc405ep_cpc_t
*cpc
)
2285 uint32_t CPU_clk
, PLB_clk
, OPB_clk
, EBC_clk
, MAL_clk
, PCI_clk
;
2286 uint32_t UART0_clk
, UART1_clk
;
2287 uint64_t VCO_out
, PLL_out
;
2291 if ((cpc
->pllmr
[1] & 0x80000000) && !(cpc
->pllmr
[1] & 0x40000000)) {
2292 M
= (((cpc
->pllmr
[1] >> 20) - 1) & 0xF) + 1; /* FBMUL */
2293 #ifdef DEBUG_CLOCKS_LL
2294 printf("FBMUL %01" PRIx32
" %d\n", (cpc
->pllmr
[1] >> 20) & 0xF, M
);
2296 D
= 8 - ((cpc
->pllmr
[1] >> 16) & 0x7); /* FWDA */
2297 #ifdef DEBUG_CLOCKS_LL
2298 printf("FWDA %01" PRIx32
" %d\n", (cpc
->pllmr
[1] >> 16) & 0x7, D
);
2300 VCO_out
= cpc
->sysclk
* M
* D
;
2301 if (VCO_out
< 500000000UL || VCO_out
> 1000000000UL) {
2302 /* Error - unlock the PLL */
2303 printf("VCO out of range %" PRIu64
"\n", VCO_out
);
2305 cpc
->pllmr
[1] &= ~0x80000000;
2309 PLL_out
= VCO_out
/ D
;
2310 /* Pretend the PLL is locked */
2311 cpc
->boot
|= 0x00000001;
2316 PLL_out
= cpc
->sysclk
;
2317 if (cpc
->pllmr
[1] & 0x40000000) {
2318 /* Pretend the PLL is not locked */
2319 cpc
->boot
&= ~0x00000001;
2322 /* Now, compute all other clocks */
2323 D
= ((cpc
->pllmr
[0] >> 20) & 0x3) + 1; /* CCDV */
2324 #ifdef DEBUG_CLOCKS_LL
2325 printf("CCDV %01" PRIx32
" %d\n", (cpc
->pllmr
[0] >> 20) & 0x3, D
);
2327 CPU_clk
= PLL_out
/ D
;
2328 D
= ((cpc
->pllmr
[0] >> 16) & 0x3) + 1; /* CBDV */
2329 #ifdef DEBUG_CLOCKS_LL
2330 printf("CBDV %01" PRIx32
" %d\n", (cpc
->pllmr
[0] >> 16) & 0x3, D
);
2332 PLB_clk
= CPU_clk
/ D
;
2333 D
= ((cpc
->pllmr
[0] >> 12) & 0x3) + 1; /* OPDV */
2334 #ifdef DEBUG_CLOCKS_LL
2335 printf("OPDV %01" PRIx32
" %d\n", (cpc
->pllmr
[0] >> 12) & 0x3, D
);
2337 OPB_clk
= PLB_clk
/ D
;
2338 D
= ((cpc
->pllmr
[0] >> 8) & 0x3) + 2; /* EPDV */
2339 #ifdef DEBUG_CLOCKS_LL
2340 printf("EPDV %01" PRIx32
" %d\n", (cpc
->pllmr
[0] >> 8) & 0x3, D
);
2342 EBC_clk
= PLB_clk
/ D
;
2343 D
= ((cpc
->pllmr
[0] >> 4) & 0x3) + 1; /* MPDV */
2344 #ifdef DEBUG_CLOCKS_LL
2345 printf("MPDV %01" PRIx32
" %d\n", (cpc
->pllmr
[0] >> 4) & 0x3, D
);
2347 MAL_clk
= PLB_clk
/ D
;
2348 D
= (cpc
->pllmr
[0] & 0x3) + 1; /* PPDV */
2349 #ifdef DEBUG_CLOCKS_LL
2350 printf("PPDV %01" PRIx32
" %d\n", cpc
->pllmr
[0] & 0x3, D
);
2352 PCI_clk
= PLB_clk
/ D
;
2353 D
= ((cpc
->ucr
- 1) & 0x7F) + 1; /* U0DIV */
2354 #ifdef DEBUG_CLOCKS_LL
2355 printf("U0DIV %01" PRIx32
" %d\n", cpc
->ucr
& 0x7F, D
);
2357 UART0_clk
= PLL_out
/ D
;
2358 D
= (((cpc
->ucr
>> 8) - 1) & 0x7F) + 1; /* U1DIV */
2359 #ifdef DEBUG_CLOCKS_LL
2360 printf("U1DIV %01" PRIx32
" %d\n", (cpc
->ucr
>> 8) & 0x7F, D
);
2362 UART1_clk
= PLL_out
/ D
;
2364 printf("Setup PPC405EP clocks - sysclk %" PRIu32
" VCO %" PRIu64
2365 " PLL out %" PRIu64
" Hz\n", cpc
->sysclk
, VCO_out
, PLL_out
);
2366 printf("CPU %" PRIu32
" PLB %" PRIu32
" OPB %" PRIu32
" EBC %" PRIu32
2367 " MAL %" PRIu32
" PCI %" PRIu32
" UART0 %" PRIu32
2368 " UART1 %" PRIu32
"\n",
2369 CPU_clk
, PLB_clk
, OPB_clk
, EBC_clk
, MAL_clk
, PCI_clk
,
2370 UART0_clk
, UART1_clk
);
2372 /* Setup CPU clocks */
2373 clk_setup(&cpc
->clk_setup
[PPC405EP_CPU_CLK
], CPU_clk
);
2374 /* Setup PLB clock */
2375 clk_setup(&cpc
->clk_setup
[PPC405EP_PLB_CLK
], PLB_clk
);
2376 /* Setup OPB clock */
2377 clk_setup(&cpc
->clk_setup
[PPC405EP_OPB_CLK
], OPB_clk
);
2378 /* Setup external clock */
2379 clk_setup(&cpc
->clk_setup
[PPC405EP_EBC_CLK
], EBC_clk
);
2380 /* Setup MAL clock */
2381 clk_setup(&cpc
->clk_setup
[PPC405EP_MAL_CLK
], MAL_clk
);
2382 /* Setup PCI clock */
2383 clk_setup(&cpc
->clk_setup
[PPC405EP_PCI_CLK
], PCI_clk
);
2384 /* Setup UART0 clock */
2385 clk_setup(&cpc
->clk_setup
[PPC405EP_UART0_CLK
], UART0_clk
);
2386 /* Setup UART1 clock */
2387 clk_setup(&cpc
->clk_setup
[PPC405EP_UART1_CLK
], UART1_clk
);
2390 static target_ulong
dcr_read_epcpc (void *opaque
, int dcrn
)
2392 ppc405ep_cpc_t
*cpc
;
2397 case PPC405EP_CPC0_BOOT
:
2400 case PPC405EP_CPC0_EPCTL
:
2403 case PPC405EP_CPC0_PLLMR0
:
2404 ret
= cpc
->pllmr
[0];
2406 case PPC405EP_CPC0_PLLMR1
:
2407 ret
= cpc
->pllmr
[1];
2409 case PPC405EP_CPC0_UCR
:
2412 case PPC405EP_CPC0_SRR
:
2415 case PPC405EP_CPC0_JTAGID
:
2418 case PPC405EP_CPC0_PCI
:
2422 /* Avoid gcc warning */
2430 static void dcr_write_epcpc (void *opaque
, int dcrn
, target_ulong val
)
2432 ppc405ep_cpc_t
*cpc
;
2436 case PPC405EP_CPC0_BOOT
:
2437 /* Read-only register */
2439 case PPC405EP_CPC0_EPCTL
:
2440 /* Don't care for now */
2441 cpc
->epctl
= val
& 0xC00000F3;
2443 case PPC405EP_CPC0_PLLMR0
:
2444 cpc
->pllmr
[0] = val
& 0x00633333;
2445 ppc405ep_compute_clocks(cpc
);
2447 case PPC405EP_CPC0_PLLMR1
:
2448 cpc
->pllmr
[1] = val
& 0xC0F73FFF;
2449 ppc405ep_compute_clocks(cpc
);
2451 case PPC405EP_CPC0_UCR
:
2452 /* UART control - don't care for now */
2453 cpc
->ucr
= val
& 0x003F7F7F;
2455 case PPC405EP_CPC0_SRR
:
2458 case PPC405EP_CPC0_JTAGID
:
2461 case PPC405EP_CPC0_PCI
:
2467 static void ppc405ep_cpc_reset (void *opaque
)
2469 ppc405ep_cpc_t
*cpc
= opaque
;
2471 cpc
->boot
= 0x00000010; /* Boot from PCI - IIC EEPROM disabled */
2472 cpc
->epctl
= 0x00000000;
2473 cpc
->pllmr
[0] = 0x00011010;
2474 cpc
->pllmr
[1] = 0x40000000;
2475 cpc
->ucr
= 0x00000000;
2476 cpc
->srr
= 0x00040000;
2477 cpc
->pci
= 0x00000000;
2478 cpc
->er
= 0x00000000;
2479 cpc
->fr
= 0x00000000;
2480 cpc
->sr
= 0x00000000;
2481 ppc405ep_compute_clocks(cpc
);
2484 /* XXX: sysclk should be between 25 and 100 MHz */
2485 static void ppc405ep_cpc_init (CPUState
*env
, clk_setup_t clk_setup
[8],
2488 ppc405ep_cpc_t
*cpc
;
2490 cpc
= qemu_mallocz(sizeof(ppc405ep_cpc_t
));
2491 memcpy(cpc
->clk_setup
, clk_setup
,
2492 PPC405EP_CLK_NB
* sizeof(clk_setup_t
));
2493 cpc
->jtagid
= 0x20267049;
2494 cpc
->sysclk
= sysclk
;
2495 ppc405ep_cpc_reset(cpc
);
2496 qemu_register_reset(&ppc405ep_cpc_reset
, cpc
);
2497 ppc_dcr_register(env
, PPC405EP_CPC0_BOOT
, cpc
,
2498 &dcr_read_epcpc
, &dcr_write_epcpc
);
2499 ppc_dcr_register(env
, PPC405EP_CPC0_EPCTL
, cpc
,
2500 &dcr_read_epcpc
, &dcr_write_epcpc
);
2501 ppc_dcr_register(env
, PPC405EP_CPC0_PLLMR0
, cpc
,
2502 &dcr_read_epcpc
, &dcr_write_epcpc
);
2503 ppc_dcr_register(env
, PPC405EP_CPC0_PLLMR1
, cpc
,
2504 &dcr_read_epcpc
, &dcr_write_epcpc
);
2505 ppc_dcr_register(env
, PPC405EP_CPC0_UCR
, cpc
,
2506 &dcr_read_epcpc
, &dcr_write_epcpc
);
2507 ppc_dcr_register(env
, PPC405EP_CPC0_SRR
, cpc
,
2508 &dcr_read_epcpc
, &dcr_write_epcpc
);
2509 ppc_dcr_register(env
, PPC405EP_CPC0_JTAGID
, cpc
,
2510 &dcr_read_epcpc
, &dcr_write_epcpc
);
2511 ppc_dcr_register(env
, PPC405EP_CPC0_PCI
, cpc
,
2512 &dcr_read_epcpc
, &dcr_write_epcpc
);
2514 ppc_dcr_register(env
, PPC405EP_CPC0_ER
, cpc
,
2515 &dcr_read_epcpc
, &dcr_write_epcpc
);
2516 ppc_dcr_register(env
, PPC405EP_CPC0_FR
, cpc
,
2517 &dcr_read_epcpc
, &dcr_write_epcpc
);
2518 ppc_dcr_register(env
, PPC405EP_CPC0_SR
, cpc
,
2519 &dcr_read_epcpc
, &dcr_write_epcpc
);
2523 CPUState
*ppc405ep_init (target_phys_addr_t ram_bases
[2],
2524 target_phys_addr_t ram_sizes
[2],
2525 uint32_t sysclk
, qemu_irq
**picp
,
2528 clk_setup_t clk_setup
[PPC405EP_CLK_NB
], tlb_clk_setup
;
2529 qemu_irq dma_irqs
[4], gpt_irqs
[5], mal_irqs
[4];
2531 ppc4xx_mmio_t
*mmio
;
2532 qemu_irq
*pic
, *irqs
;
2534 memset(clk_setup
, 0, sizeof(clk_setup
));
2536 env
= ppc4xx_init("405ep", &clk_setup
[PPC405EP_CPU_CLK
],
2537 &tlb_clk_setup
, sysclk
);
2538 clk_setup
[PPC405EP_CPU_CLK
].cb
= tlb_clk_setup
.cb
;
2539 clk_setup
[PPC405EP_CPU_CLK
].opaque
= tlb_clk_setup
.opaque
;
2540 /* Internal devices init */
2541 /* Memory mapped devices registers */
2542 mmio
= ppc4xx_mmio_init(env
, 0xEF600000);
2544 ppc4xx_plb_init(env
);
2545 /* PLB to OPB bridge */
2546 ppc4xx_pob_init(env
);
2548 ppc4xx_opba_init(env
, mmio
, 0x600);
2549 /* Universal interrupt controller */
2550 irqs
= qemu_mallocz(sizeof(qemu_irq
) * PPCUIC_OUTPUT_NB
);
2551 irqs
[PPCUIC_OUTPUT_INT
] =
2552 ((qemu_irq
*)env
->irq_inputs
)[PPC40x_INPUT_INT
];
2553 irqs
[PPCUIC_OUTPUT_CINT
] =
2554 ((qemu_irq
*)env
->irq_inputs
)[PPC40x_INPUT_CINT
];
2555 pic
= ppcuic_init(env
, irqs
, 0x0C0, 0, 1);
2557 /* SDRAM controller */
2558 /* XXX 405EP has no ECC interrupt */
2559 ppc4xx_sdram_init(env
, pic
[17], 2, ram_bases
, ram_sizes
, do_init
);
2560 /* External bus controller */
2561 ppc405_ebc_init(env
);
2562 /* DMA controller */
2563 dma_irqs
[0] = pic
[5];
2564 dma_irqs
[1] = pic
[6];
2565 dma_irqs
[2] = pic
[7];
2566 dma_irqs
[3] = pic
[8];
2567 ppc405_dma_init(env
, dma_irqs
);
2568 /* IIC controller */
2569 ppc405_i2c_init(env
, mmio
, 0x500, pic
[2]);
2571 ppc405_gpio_init(env
, mmio
, 0x700);
2573 if (serial_hds
[0] != NULL
) {
2574 ppc405_serial_init(env
, mmio
, 0x300, pic
[0], serial_hds
[0]);
2576 if (serial_hds
[1] != NULL
) {
2577 ppc405_serial_init(env
, mmio
, 0x400, pic
[1], serial_hds
[1]);
2580 ppc405_ocm_init(env
);
2582 gpt_irqs
[0] = pic
[19];
2583 gpt_irqs
[1] = pic
[20];
2584 gpt_irqs
[2] = pic
[21];
2585 gpt_irqs
[3] = pic
[22];
2586 gpt_irqs
[4] = pic
[23];
2587 ppc4xx_gpt_init(env
, mmio
, 0x000, gpt_irqs
);
2589 /* Uses pic[3], pic[16], pic[18] */
2591 mal_irqs
[0] = pic
[11];
2592 mal_irqs
[1] = pic
[12];
2593 mal_irqs
[2] = pic
[13];
2594 mal_irqs
[3] = pic
[14];
2595 ppc405_mal_init(env
, mal_irqs
);
2597 /* Uses pic[9], pic[15], pic[17] */
2599 ppc405ep_cpc_init(env
, clk_setup
, sysclk
);