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_be_phys(bdloc
+ 0x00, bd
->bi_memstart
);
55 stl_be_phys(bdloc
+ 0x04, bd
->bi_memsize
);
56 stl_be_phys(bdloc
+ 0x08, bd
->bi_flashstart
);
57 stl_be_phys(bdloc
+ 0x0C, bd
->bi_flashsize
);
58 stl_be_phys(bdloc
+ 0x10, bd
->bi_flashoffset
);
59 stl_be_phys(bdloc
+ 0x14, bd
->bi_sramstart
);
60 stl_be_phys(bdloc
+ 0x18, bd
->bi_sramsize
);
61 stl_be_phys(bdloc
+ 0x1C, bd
->bi_bootflags
);
62 stl_be_phys(bdloc
+ 0x20, bd
->bi_ipaddr
);
63 for (i
= 0; i
< 6; i
++) {
64 stb_phys(bdloc
+ 0x24 + i
, bd
->bi_enetaddr
[i
]);
66 stw_be_phys(bdloc
+ 0x2A, bd
->bi_ethspeed
);
67 stl_be_phys(bdloc
+ 0x2C, bd
->bi_intfreq
);
68 stl_be_phys(bdloc
+ 0x30, bd
->bi_busfreq
);
69 stl_be_phys(bdloc
+ 0x34, bd
->bi_baudrate
);
70 for (i
= 0; i
< 4; i
++) {
71 stb_phys(bdloc
+ 0x38 + i
, bd
->bi_s_version
[i
]);
73 for (i
= 0; i
< 32; i
++) {
74 stb_phys(bdloc
+ 0x3C + i
, bd
->bi_r_version
[i
]);
76 stl_be_phys(bdloc
+ 0x5C, bd
->bi_plb_busfreq
);
77 stl_be_phys(bdloc
+ 0x60, bd
->bi_pci_busfreq
);
78 for (i
= 0; i
< 6; i
++) {
79 stb_phys(bdloc
+ 0x64 + i
, bd
->bi_pci_enetaddr
[i
]);
82 if (flags
& 0x00000001) {
83 for (i
= 0; i
< 6; i
++)
84 stb_phys(bdloc
+ n
++, bd
->bi_pci_enetaddr2
[i
]);
86 stl_be_phys(bdloc
+ n
, bd
->bi_opbfreq
);
88 for (i
= 0; i
< 2; i
++) {
89 stl_be_phys(bdloc
+ n
, bd
->bi_iic_fast
[i
]);
96 /*****************************************************************************/
97 /* Shared peripherals */
99 /*****************************************************************************/
100 /* Peripheral local bus arbitrer */
107 typedef struct ppc4xx_plb_t ppc4xx_plb_t
;
108 struct ppc4xx_plb_t
{
114 static uint32_t dcr_read_plb (void *opaque
, int dcrn
)
131 /* Avoid gcc warning */
139 static void dcr_write_plb (void *opaque
, int dcrn
, uint32_t val
)
146 /* We don't care about the actual parameters written as
147 * we don't manage any priorities on the bus
149 plb
->acr
= val
& 0xF8000000;
161 static void ppc4xx_plb_reset (void *opaque
)
166 plb
->acr
= 0x00000000;
167 plb
->bear
= 0x00000000;
168 plb
->besr
= 0x00000000;
171 static void ppc4xx_plb_init(CPUState
*env
)
175 plb
= qemu_mallocz(sizeof(ppc4xx_plb_t
));
176 ppc_dcr_register(env
, PLB0_ACR
, plb
, &dcr_read_plb
, &dcr_write_plb
);
177 ppc_dcr_register(env
, PLB0_BEAR
, plb
, &dcr_read_plb
, &dcr_write_plb
);
178 ppc_dcr_register(env
, PLB0_BESR
, plb
, &dcr_read_plb
, &dcr_write_plb
);
179 qemu_register_reset(ppc4xx_plb_reset
, plb
);
182 /*****************************************************************************/
183 /* PLB to OPB bridge */
190 typedef struct ppc4xx_pob_t ppc4xx_pob_t
;
191 struct ppc4xx_pob_t
{
196 static uint32_t dcr_read_pob (void *opaque
, int dcrn
)
208 ret
= pob
->besr
[dcrn
- POB0_BESR0
];
211 /* Avoid gcc warning */
219 static void dcr_write_pob (void *opaque
, int dcrn
, uint32_t val
)
231 pob
->besr
[dcrn
- POB0_BESR0
] &= ~val
;
236 static void ppc4xx_pob_reset (void *opaque
)
242 pob
->bear
= 0x00000000;
243 pob
->besr
[0] = 0x0000000;
244 pob
->besr
[1] = 0x0000000;
247 static void ppc4xx_pob_init(CPUState
*env
)
251 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
);
258 /*****************************************************************************/
260 typedef struct ppc4xx_opba_t ppc4xx_opba_t
;
261 struct ppc4xx_opba_t
{
266 static uint32_t opba_readb (void *opaque
, target_phys_addr_t addr
)
272 printf("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
290 static void opba_writeb (void *opaque
,
291 target_phys_addr_t addr
, uint32_t value
)
296 printf("%s: addr " TARGET_FMT_plx
" val %08" PRIx32
"\n", __func__
, addr
,
302 opba
->cr
= value
& 0xF8;
305 opba
->pr
= value
& 0xFF;
312 static uint32_t opba_readw (void *opaque
, target_phys_addr_t addr
)
317 printf("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
319 ret
= opba_readb(opaque
, addr
) << 8;
320 ret
|= opba_readb(opaque
, addr
+ 1);
325 static void opba_writew (void *opaque
,
326 target_phys_addr_t addr
, uint32_t value
)
329 printf("%s: addr " TARGET_FMT_plx
" val %08" PRIx32
"\n", __func__
, addr
,
332 opba_writeb(opaque
, addr
, value
>> 8);
333 opba_writeb(opaque
, addr
+ 1, value
);
336 static uint32_t opba_readl (void *opaque
, target_phys_addr_t addr
)
341 printf("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
343 ret
= opba_readb(opaque
, addr
) << 24;
344 ret
|= opba_readb(opaque
, addr
+ 1) << 16;
349 static void opba_writel (void *opaque
,
350 target_phys_addr_t addr
, uint32_t value
)
353 printf("%s: addr " TARGET_FMT_plx
" val %08" PRIx32
"\n", __func__
, addr
,
356 opba_writeb(opaque
, addr
, value
>> 24);
357 opba_writeb(opaque
, addr
+ 1, value
>> 16);
360 static CPUReadMemoryFunc
* const opba_read
[] = {
366 static CPUWriteMemoryFunc
* const opba_write
[] = {
372 static void ppc4xx_opba_reset (void *opaque
)
377 opba
->cr
= 0x00; /* No dynamic priorities - park disabled */
381 static void ppc4xx_opba_init(target_phys_addr_t base
)
386 opba
= qemu_mallocz(sizeof(ppc4xx_opba_t
));
388 printf("%s: offset " TARGET_FMT_plx
"\n", __func__
, base
);
390 io
= cpu_register_io_memory(opba_read
, opba_write
, opba
,
391 DEVICE_NATIVE_ENDIAN
);
392 cpu_register_physical_memory(base
, 0x002, io
);
393 qemu_register_reset(ppc4xx_opba_reset
, opba
);
396 /*****************************************************************************/
397 /* Code decompression controller */
400 /*****************************************************************************/
401 /* Peripheral controller */
402 typedef struct ppc4xx_ebc_t ppc4xx_ebc_t
;
403 struct ppc4xx_ebc_t
{
414 EBC0_CFGADDR
= 0x012,
415 EBC0_CFGDATA
= 0x013,
418 static uint32_t dcr_read_ebc (void *opaque
, int dcrn
)
430 case 0x00: /* B0CR */
433 case 0x01: /* B1CR */
436 case 0x02: /* B2CR */
439 case 0x03: /* B3CR */
442 case 0x04: /* B4CR */
445 case 0x05: /* B5CR */
448 case 0x06: /* B6CR */
451 case 0x07: /* B7CR */
454 case 0x10: /* B0AP */
457 case 0x11: /* B1AP */
460 case 0x12: /* B2AP */
463 case 0x13: /* B3AP */
466 case 0x14: /* B4AP */
469 case 0x15: /* B5AP */
472 case 0x16: /* B6AP */
475 case 0x17: /* B7AP */
478 case 0x20: /* BEAR */
481 case 0x21: /* BESR0 */
484 case 0x22: /* BESR1 */
503 static void dcr_write_ebc (void *opaque
, int dcrn
, uint32_t val
)
514 case 0x00: /* B0CR */
516 case 0x01: /* B1CR */
518 case 0x02: /* B2CR */
520 case 0x03: /* B3CR */
522 case 0x04: /* B4CR */
524 case 0x05: /* B5CR */
526 case 0x06: /* B6CR */
528 case 0x07: /* B7CR */
530 case 0x10: /* B0AP */
532 case 0x11: /* B1AP */
534 case 0x12: /* B2AP */
536 case 0x13: /* B3AP */
538 case 0x14: /* B4AP */
540 case 0x15: /* B5AP */
542 case 0x16: /* B6AP */
544 case 0x17: /* B7AP */
546 case 0x20: /* BEAR */
548 case 0x21: /* BESR0 */
550 case 0x22: /* BESR1 */
563 static void ebc_reset (void *opaque
)
569 ebc
->addr
= 0x00000000;
570 ebc
->bap
[0] = 0x7F8FFE80;
571 ebc
->bcr
[0] = 0xFFE28000;
572 for (i
= 0; i
< 8; i
++) {
573 ebc
->bap
[i
] = 0x00000000;
574 ebc
->bcr
[i
] = 0x00000000;
576 ebc
->besr0
= 0x00000000;
577 ebc
->besr1
= 0x00000000;
578 ebc
->cfg
= 0x80400000;
581 static void ppc405_ebc_init(CPUState
*env
)
585 ebc
= qemu_mallocz(sizeof(ppc4xx_ebc_t
));
586 qemu_register_reset(&ebc_reset
, ebc
);
587 ppc_dcr_register(env
, EBC0_CFGADDR
,
588 ebc
, &dcr_read_ebc
, &dcr_write_ebc
);
589 ppc_dcr_register(env
, EBC0_CFGDATA
,
590 ebc
, &dcr_read_ebc
, &dcr_write_ebc
);
593 /*****************************************************************************/
622 typedef struct ppc405_dma_t ppc405_dma_t
;
623 struct ppc405_dma_t
{
636 static uint32_t dcr_read_dma (void *opaque
, int dcrn
)
641 static void dcr_write_dma (void *opaque
, int dcrn
, uint32_t val
)
645 static void ppc405_dma_reset (void *opaque
)
651 for (i
= 0; i
< 4; i
++) {
652 dma
->cr
[i
] = 0x00000000;
653 dma
->ct
[i
] = 0x00000000;
654 dma
->da
[i
] = 0x00000000;
655 dma
->sa
[i
] = 0x00000000;
656 dma
->sg
[i
] = 0x00000000;
658 dma
->sr
= 0x00000000;
659 dma
->sgc
= 0x00000000;
660 dma
->slp
= 0x7C000000;
661 dma
->pol
= 0x00000000;
664 static void ppc405_dma_init(CPUState
*env
, qemu_irq irqs
[4])
668 dma
= qemu_mallocz(sizeof(ppc405_dma_t
));
669 memcpy(dma
->irqs
, irqs
, 4 * sizeof(qemu_irq
));
670 qemu_register_reset(&ppc405_dma_reset
, dma
);
671 ppc_dcr_register(env
, DMA0_CR0
,
672 dma
, &dcr_read_dma
, &dcr_write_dma
);
673 ppc_dcr_register(env
, DMA0_CT0
,
674 dma
, &dcr_read_dma
, &dcr_write_dma
);
675 ppc_dcr_register(env
, DMA0_DA0
,
676 dma
, &dcr_read_dma
, &dcr_write_dma
);
677 ppc_dcr_register(env
, DMA0_SA0
,
678 dma
, &dcr_read_dma
, &dcr_write_dma
);
679 ppc_dcr_register(env
, DMA0_SG0
,
680 dma
, &dcr_read_dma
, &dcr_write_dma
);
681 ppc_dcr_register(env
, DMA0_CR1
,
682 dma
, &dcr_read_dma
, &dcr_write_dma
);
683 ppc_dcr_register(env
, DMA0_CT1
,
684 dma
, &dcr_read_dma
, &dcr_write_dma
);
685 ppc_dcr_register(env
, DMA0_DA1
,
686 dma
, &dcr_read_dma
, &dcr_write_dma
);
687 ppc_dcr_register(env
, DMA0_SA1
,
688 dma
, &dcr_read_dma
, &dcr_write_dma
);
689 ppc_dcr_register(env
, DMA0_SG1
,
690 dma
, &dcr_read_dma
, &dcr_write_dma
);
691 ppc_dcr_register(env
, DMA0_CR2
,
692 dma
, &dcr_read_dma
, &dcr_write_dma
);
693 ppc_dcr_register(env
, DMA0_CT2
,
694 dma
, &dcr_read_dma
, &dcr_write_dma
);
695 ppc_dcr_register(env
, DMA0_DA2
,
696 dma
, &dcr_read_dma
, &dcr_write_dma
);
697 ppc_dcr_register(env
, DMA0_SA2
,
698 dma
, &dcr_read_dma
, &dcr_write_dma
);
699 ppc_dcr_register(env
, DMA0_SG2
,
700 dma
, &dcr_read_dma
, &dcr_write_dma
);
701 ppc_dcr_register(env
, DMA0_CR3
,
702 dma
, &dcr_read_dma
, &dcr_write_dma
);
703 ppc_dcr_register(env
, DMA0_CT3
,
704 dma
, &dcr_read_dma
, &dcr_write_dma
);
705 ppc_dcr_register(env
, DMA0_DA3
,
706 dma
, &dcr_read_dma
, &dcr_write_dma
);
707 ppc_dcr_register(env
, DMA0_SA3
,
708 dma
, &dcr_read_dma
, &dcr_write_dma
);
709 ppc_dcr_register(env
, DMA0_SG3
,
710 dma
, &dcr_read_dma
, &dcr_write_dma
);
711 ppc_dcr_register(env
, DMA0_SR
,
712 dma
, &dcr_read_dma
, &dcr_write_dma
);
713 ppc_dcr_register(env
, DMA0_SGC
,
714 dma
, &dcr_read_dma
, &dcr_write_dma
);
715 ppc_dcr_register(env
, DMA0_SLP
,
716 dma
, &dcr_read_dma
, &dcr_write_dma
);
717 ppc_dcr_register(env
, DMA0_POL
,
718 dma
, &dcr_read_dma
, &dcr_write_dma
);
721 /*****************************************************************************/
723 typedef struct ppc405_gpio_t ppc405_gpio_t
;
724 struct ppc405_gpio_t
{
738 static uint32_t ppc405_gpio_readb (void *opaque
, target_phys_addr_t addr
)
741 printf("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
747 static void ppc405_gpio_writeb (void *opaque
,
748 target_phys_addr_t addr
, uint32_t value
)
751 printf("%s: addr " TARGET_FMT_plx
" val %08" PRIx32
"\n", __func__
, addr
,
756 static uint32_t ppc405_gpio_readw (void *opaque
, target_phys_addr_t addr
)
759 printf("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
765 static void ppc405_gpio_writew (void *opaque
,
766 target_phys_addr_t addr
, uint32_t value
)
769 printf("%s: addr " TARGET_FMT_plx
" val %08" PRIx32
"\n", __func__
, addr
,
774 static uint32_t ppc405_gpio_readl (void *opaque
, target_phys_addr_t addr
)
777 printf("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
783 static void ppc405_gpio_writel (void *opaque
,
784 target_phys_addr_t addr
, uint32_t value
)
787 printf("%s: addr " TARGET_FMT_plx
" val %08" PRIx32
"\n", __func__
, addr
,
792 static CPUReadMemoryFunc
* const ppc405_gpio_read
[] = {
798 static CPUWriteMemoryFunc
* const ppc405_gpio_write
[] = {
804 static void ppc405_gpio_reset (void *opaque
)
808 static void ppc405_gpio_init(target_phys_addr_t base
)
813 gpio
= qemu_mallocz(sizeof(ppc405_gpio_t
));
815 printf("%s: offset " TARGET_FMT_plx
"\n", __func__
, base
);
817 io
= cpu_register_io_memory(ppc405_gpio_read
, ppc405_gpio_write
, gpio
,
818 DEVICE_NATIVE_ENDIAN
);
819 cpu_register_physical_memory(base
, 0x038, io
);
820 qemu_register_reset(&ppc405_gpio_reset
, gpio
);
823 /*****************************************************************************/
827 OCM0_ISACNTL
= 0x019,
829 OCM0_DSACNTL
= 0x01B,
832 typedef struct ppc405_ocm_t ppc405_ocm_t
;
833 struct ppc405_ocm_t
{
841 static void ocm_update_mappings (ppc405_ocm_t
*ocm
,
842 uint32_t isarc
, uint32_t isacntl
,
843 uint32_t dsarc
, uint32_t dsacntl
)
846 printf("OCM update ISA %08" PRIx32
" %08" PRIx32
" (%08" PRIx32
847 " %08" PRIx32
") DSA %08" PRIx32
" %08" PRIx32
848 " (%08" PRIx32
" %08" PRIx32
")\n",
849 isarc
, isacntl
, dsarc
, dsacntl
,
850 ocm
->isarc
, ocm
->isacntl
, ocm
->dsarc
, ocm
->dsacntl
);
852 if (ocm
->isarc
!= isarc
||
853 (ocm
->isacntl
& 0x80000000) != (isacntl
& 0x80000000)) {
854 if (ocm
->isacntl
& 0x80000000) {
855 /* Unmap previously assigned memory region */
856 printf("OCM unmap ISA %08" PRIx32
"\n", ocm
->isarc
);
857 cpu_register_physical_memory(ocm
->isarc
, 0x04000000,
860 if (isacntl
& 0x80000000) {
861 /* Map new instruction memory region */
863 printf("OCM map ISA %08" PRIx32
"\n", isarc
);
865 cpu_register_physical_memory(isarc
, 0x04000000,
866 ocm
->offset
| IO_MEM_RAM
);
869 if (ocm
->dsarc
!= dsarc
||
870 (ocm
->dsacntl
& 0x80000000) != (dsacntl
& 0x80000000)) {
871 if (ocm
->dsacntl
& 0x80000000) {
872 /* Beware not to unmap the region we just mapped */
873 if (!(isacntl
& 0x80000000) || ocm
->dsarc
!= isarc
) {
874 /* Unmap previously assigned memory region */
876 printf("OCM unmap DSA %08" PRIx32
"\n", ocm
->dsarc
);
878 cpu_register_physical_memory(ocm
->dsarc
, 0x04000000,
882 if (dsacntl
& 0x80000000) {
883 /* Beware not to remap the region we just mapped */
884 if (!(isacntl
& 0x80000000) || dsarc
!= isarc
) {
885 /* Map new data memory region */
887 printf("OCM map DSA %08" PRIx32
"\n", dsarc
);
889 cpu_register_physical_memory(dsarc
, 0x04000000,
890 ocm
->offset
| IO_MEM_RAM
);
896 static uint32_t dcr_read_ocm (void *opaque
, int dcrn
)
923 static void dcr_write_ocm (void *opaque
, int dcrn
, uint32_t val
)
926 uint32_t isarc
, dsarc
, isacntl
, dsacntl
;
931 isacntl
= ocm
->isacntl
;
932 dsacntl
= ocm
->dsacntl
;
935 isarc
= val
& 0xFC000000;
938 isacntl
= val
& 0xC0000000;
941 isarc
= val
& 0xFC000000;
944 isacntl
= val
& 0xC0000000;
947 ocm_update_mappings(ocm
, isarc
, isacntl
, dsarc
, dsacntl
);
950 ocm
->isacntl
= isacntl
;
951 ocm
->dsacntl
= dsacntl
;
954 static void ocm_reset (void *opaque
)
957 uint32_t isarc
, dsarc
, isacntl
, dsacntl
;
961 isacntl
= 0x00000000;
963 dsacntl
= 0x00000000;
964 ocm_update_mappings(ocm
, isarc
, isacntl
, dsarc
, dsacntl
);
967 ocm
->isacntl
= isacntl
;
968 ocm
->dsacntl
= dsacntl
;
971 static void ppc405_ocm_init(CPUState
*env
)
975 ocm
= qemu_mallocz(sizeof(ppc405_ocm_t
));
976 ocm
->offset
= qemu_ram_alloc(NULL
, "ppc405.ocm", 4096);
977 qemu_register_reset(&ocm_reset
, ocm
);
978 ppc_dcr_register(env
, OCM0_ISARC
,
979 ocm
, &dcr_read_ocm
, &dcr_write_ocm
);
980 ppc_dcr_register(env
, OCM0_ISACNTL
,
981 ocm
, &dcr_read_ocm
, &dcr_write_ocm
);
982 ppc_dcr_register(env
, OCM0_DSARC
,
983 ocm
, &dcr_read_ocm
, &dcr_write_ocm
);
984 ppc_dcr_register(env
, OCM0_DSACNTL
,
985 ocm
, &dcr_read_ocm
, &dcr_write_ocm
);
988 /*****************************************************************************/
990 typedef struct ppc4xx_i2c_t ppc4xx_i2c_t
;
991 struct ppc4xx_i2c_t
{
1010 static uint32_t ppc4xx_i2c_readb (void *opaque
, target_phys_addr_t addr
)
1016 printf("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
1021 // i2c_readbyte(&i2c->mdata);
1061 ret
= i2c
->xtcntlss
;
1064 ret
= i2c
->directcntl
;
1071 printf("%s: addr " TARGET_FMT_plx
" %02" PRIx32
"\n", __func__
, addr
, ret
);
1077 static void ppc4xx_i2c_writeb (void *opaque
,
1078 target_phys_addr_t addr
, uint32_t value
)
1083 printf("%s: addr " TARGET_FMT_plx
" val %08" PRIx32
"\n", __func__
, addr
,
1090 // i2c_sendbyte(&i2c->mdata);
1105 i2c
->mdcntl
= value
& 0xDF;
1108 i2c
->sts
&= ~(value
& 0x0A);
1111 i2c
->extsts
&= ~(value
& 0x8F);
1120 i2c
->clkdiv
= value
;
1123 i2c
->intrmsk
= value
;
1126 i2c
->xfrcnt
= value
& 0x77;
1129 i2c
->xtcntlss
= value
;
1132 i2c
->directcntl
= value
& 0x7;
1137 static uint32_t ppc4xx_i2c_readw (void *opaque
, target_phys_addr_t addr
)
1142 printf("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
1144 ret
= ppc4xx_i2c_readb(opaque
, addr
) << 8;
1145 ret
|= ppc4xx_i2c_readb(opaque
, addr
+ 1);
1150 static void ppc4xx_i2c_writew (void *opaque
,
1151 target_phys_addr_t addr
, uint32_t value
)
1154 printf("%s: addr " TARGET_FMT_plx
" val %08" PRIx32
"\n", __func__
, addr
,
1157 ppc4xx_i2c_writeb(opaque
, addr
, value
>> 8);
1158 ppc4xx_i2c_writeb(opaque
, addr
+ 1, value
);
1161 static uint32_t ppc4xx_i2c_readl (void *opaque
, target_phys_addr_t addr
)
1166 printf("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
1168 ret
= ppc4xx_i2c_readb(opaque
, addr
) << 24;
1169 ret
|= ppc4xx_i2c_readb(opaque
, addr
+ 1) << 16;
1170 ret
|= ppc4xx_i2c_readb(opaque
, addr
+ 2) << 8;
1171 ret
|= ppc4xx_i2c_readb(opaque
, addr
+ 3);
1176 static void ppc4xx_i2c_writel (void *opaque
,
1177 target_phys_addr_t addr
, uint32_t value
)
1180 printf("%s: addr " TARGET_FMT_plx
" val %08" PRIx32
"\n", __func__
, addr
,
1183 ppc4xx_i2c_writeb(opaque
, addr
, value
>> 24);
1184 ppc4xx_i2c_writeb(opaque
, addr
+ 1, value
>> 16);
1185 ppc4xx_i2c_writeb(opaque
, addr
+ 2, value
>> 8);
1186 ppc4xx_i2c_writeb(opaque
, addr
+ 3, value
);
1189 static CPUReadMemoryFunc
* const i2c_read
[] = {
1195 static CPUWriteMemoryFunc
* const i2c_write
[] = {
1201 static void ppc4xx_i2c_reset (void *opaque
)
1214 i2c
->directcntl
= 0x0F;
1217 static void ppc405_i2c_init(target_phys_addr_t base
, qemu_irq irq
)
1222 i2c
= qemu_mallocz(sizeof(ppc4xx_i2c_t
));
1225 printf("%s: offset " TARGET_FMT_plx
"\n", __func__
, base
);
1227 io
= cpu_register_io_memory(i2c_read
, i2c_write
, i2c
,
1228 DEVICE_NATIVE_ENDIAN
);
1229 cpu_register_physical_memory(base
, 0x011, io
);
1230 qemu_register_reset(ppc4xx_i2c_reset
, i2c
);
1233 /*****************************************************************************/
1234 /* General purpose timers */
1235 typedef struct ppc4xx_gpt_t ppc4xx_gpt_t
;
1236 struct ppc4xx_gpt_t
{
1239 struct QEMUTimer
*timer
;
1250 static uint32_t ppc4xx_gpt_readb (void *opaque
, target_phys_addr_t addr
)
1253 printf("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
1255 /* XXX: generate a bus fault */
1259 static void ppc4xx_gpt_writeb (void *opaque
,
1260 target_phys_addr_t addr
, uint32_t value
)
1263 printf("%s: addr " TARGET_FMT_plx
" val %08" PRIx32
"\n", __func__
, addr
,
1266 /* XXX: generate a bus fault */
1269 static uint32_t ppc4xx_gpt_readw (void *opaque
, target_phys_addr_t addr
)
1272 printf("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
1274 /* XXX: generate a bus fault */
1278 static void ppc4xx_gpt_writew (void *opaque
,
1279 target_phys_addr_t addr
, uint32_t value
)
1282 printf("%s: addr " TARGET_FMT_plx
" val %08" PRIx32
"\n", __func__
, addr
,
1285 /* XXX: generate a bus fault */
1288 static int ppc4xx_gpt_compare (ppc4xx_gpt_t
*gpt
, int n
)
1294 static void ppc4xx_gpt_set_output (ppc4xx_gpt_t
*gpt
, int n
, int level
)
1299 static void ppc4xx_gpt_set_outputs (ppc4xx_gpt_t
*gpt
)
1305 for (i
= 0; i
< 5; i
++) {
1306 if (gpt
->oe
& mask
) {
1307 /* Output is enabled */
1308 if (ppc4xx_gpt_compare(gpt
, i
)) {
1309 /* Comparison is OK */
1310 ppc4xx_gpt_set_output(gpt
, i
, gpt
->ol
& mask
);
1312 /* Comparison is KO */
1313 ppc4xx_gpt_set_output(gpt
, i
, gpt
->ol
& mask
? 0 : 1);
1320 static void ppc4xx_gpt_set_irqs (ppc4xx_gpt_t
*gpt
)
1326 for (i
= 0; i
< 5; i
++) {
1327 if (gpt
->is
& gpt
->im
& mask
)
1328 qemu_irq_raise(gpt
->irqs
[i
]);
1330 qemu_irq_lower(gpt
->irqs
[i
]);
1335 static void ppc4xx_gpt_compute_timer (ppc4xx_gpt_t
*gpt
)
1340 static uint32_t ppc4xx_gpt_readl (void *opaque
, target_phys_addr_t addr
)
1347 printf("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
1352 /* Time base counter */
1353 ret
= muldiv64(qemu_get_clock_ns(vm_clock
) + gpt
->tb_offset
,
1354 gpt
->tb_freq
, get_ticks_per_sec());
1365 /* Interrupt mask */
1370 /* Interrupt status */
1374 /* Interrupt enable */
1379 idx
= (addr
- 0x80) >> 2;
1380 ret
= gpt
->comp
[idx
];
1384 idx
= (addr
- 0xC0) >> 2;
1385 ret
= gpt
->mask
[idx
];
1395 static void ppc4xx_gpt_writel (void *opaque
,
1396 target_phys_addr_t addr
, uint32_t value
)
1402 printf("%s: addr " TARGET_FMT_plx
" val %08" PRIx32
"\n", __func__
, addr
,
1408 /* Time base counter */
1409 gpt
->tb_offset
= muldiv64(value
, get_ticks_per_sec(), gpt
->tb_freq
)
1410 - qemu_get_clock_ns(vm_clock
);
1411 ppc4xx_gpt_compute_timer(gpt
);
1415 gpt
->oe
= value
& 0xF8000000;
1416 ppc4xx_gpt_set_outputs(gpt
);
1420 gpt
->ol
= value
& 0xF8000000;
1421 ppc4xx_gpt_set_outputs(gpt
);
1424 /* Interrupt mask */
1425 gpt
->im
= value
& 0x0000F800;
1428 /* Interrupt status set */
1429 gpt
->is
|= value
& 0x0000F800;
1430 ppc4xx_gpt_set_irqs(gpt
);
1433 /* Interrupt status clear */
1434 gpt
->is
&= ~(value
& 0x0000F800);
1435 ppc4xx_gpt_set_irqs(gpt
);
1438 /* Interrupt enable */
1439 gpt
->ie
= value
& 0x0000F800;
1440 ppc4xx_gpt_set_irqs(gpt
);
1444 idx
= (addr
- 0x80) >> 2;
1445 gpt
->comp
[idx
] = value
& 0xF8000000;
1446 ppc4xx_gpt_compute_timer(gpt
);
1450 idx
= (addr
- 0xC0) >> 2;
1451 gpt
->mask
[idx
] = value
& 0xF8000000;
1452 ppc4xx_gpt_compute_timer(gpt
);
1457 static CPUReadMemoryFunc
* const gpt_read
[] = {
1463 static CPUWriteMemoryFunc
* const gpt_write
[] = {
1469 static void ppc4xx_gpt_cb (void *opaque
)
1474 ppc4xx_gpt_set_irqs(gpt
);
1475 ppc4xx_gpt_set_outputs(gpt
);
1476 ppc4xx_gpt_compute_timer(gpt
);
1479 static void ppc4xx_gpt_reset (void *opaque
)
1485 qemu_del_timer(gpt
->timer
);
1486 gpt
->oe
= 0x00000000;
1487 gpt
->ol
= 0x00000000;
1488 gpt
->im
= 0x00000000;
1489 gpt
->is
= 0x00000000;
1490 gpt
->ie
= 0x00000000;
1491 for (i
= 0; i
< 5; i
++) {
1492 gpt
->comp
[i
] = 0x00000000;
1493 gpt
->mask
[i
] = 0x00000000;
1497 static void ppc4xx_gpt_init(target_phys_addr_t base
, qemu_irq irqs
[5])
1503 gpt
= qemu_mallocz(sizeof(ppc4xx_gpt_t
));
1504 for (i
= 0; i
< 5; i
++) {
1505 gpt
->irqs
[i
] = irqs
[i
];
1507 gpt
->timer
= qemu_new_timer_ns(vm_clock
, &ppc4xx_gpt_cb
, gpt
);
1509 printf("%s: offset " TARGET_FMT_plx
"\n", __func__
, base
);
1511 io
= cpu_register_io_memory(gpt_read
, gpt_write
, gpt
, DEVICE_NATIVE_ENDIAN
);
1512 cpu_register_physical_memory(base
, 0x0d4, io
);
1513 qemu_register_reset(ppc4xx_gpt_reset
, gpt
);
1516 /*****************************************************************************/
1522 MAL0_TXCASR
= 0x184,
1523 MAL0_TXCARR
= 0x185,
1524 MAL0_TXEOBISR
= 0x186,
1525 MAL0_TXDEIR
= 0x187,
1526 MAL0_RXCASR
= 0x190,
1527 MAL0_RXCARR
= 0x191,
1528 MAL0_RXEOBISR
= 0x192,
1529 MAL0_RXDEIR
= 0x193,
1530 MAL0_TXCTP0R
= 0x1A0,
1531 MAL0_TXCTP1R
= 0x1A1,
1532 MAL0_TXCTP2R
= 0x1A2,
1533 MAL0_TXCTP3R
= 0x1A3,
1534 MAL0_RXCTP0R
= 0x1C0,
1535 MAL0_RXCTP1R
= 0x1C1,
1540 typedef struct ppc40x_mal_t ppc40x_mal_t
;
1541 struct ppc40x_mal_t
{
1559 static void ppc40x_mal_reset (void *opaque
);
1561 static uint32_t dcr_read_mal (void *opaque
, int dcrn
)
1584 ret
= mal
->txeobisr
;
1596 ret
= mal
->rxeobisr
;
1602 ret
= mal
->txctpr
[0];
1605 ret
= mal
->txctpr
[1];
1608 ret
= mal
->txctpr
[2];
1611 ret
= mal
->txctpr
[3];
1614 ret
= mal
->rxctpr
[0];
1617 ret
= mal
->rxctpr
[1];
1633 static void dcr_write_mal (void *opaque
, int dcrn
, uint32_t val
)
1641 if (val
& 0x80000000)
1642 ppc40x_mal_reset(mal
);
1643 mal
->cfg
= val
& 0x00FFC087;
1650 mal
->ier
= val
& 0x0000001F;
1653 mal
->txcasr
= val
& 0xF0000000;
1656 mal
->txcarr
= val
& 0xF0000000;
1660 mal
->txeobisr
&= ~val
;
1664 mal
->txdeir
&= ~val
;
1667 mal
->rxcasr
= val
& 0xC0000000;
1670 mal
->rxcarr
= val
& 0xC0000000;
1674 mal
->rxeobisr
&= ~val
;
1678 mal
->rxdeir
&= ~val
;
1692 mal
->txctpr
[idx
] = val
;
1700 mal
->rxctpr
[idx
] = val
;
1704 goto update_rx_size
;
1708 mal
->rcbs
[idx
] = val
& 0x000000FF;
1713 static void ppc40x_mal_reset (void *opaque
)
1718 mal
->cfg
= 0x0007C000;
1719 mal
->esr
= 0x00000000;
1720 mal
->ier
= 0x00000000;
1721 mal
->rxcasr
= 0x00000000;
1722 mal
->rxdeir
= 0x00000000;
1723 mal
->rxeobisr
= 0x00000000;
1724 mal
->txcasr
= 0x00000000;
1725 mal
->txdeir
= 0x00000000;
1726 mal
->txeobisr
= 0x00000000;
1729 static void ppc405_mal_init(CPUState
*env
, qemu_irq irqs
[4])
1734 mal
= qemu_mallocz(sizeof(ppc40x_mal_t
));
1735 for (i
= 0; i
< 4; i
++)
1736 mal
->irqs
[i
] = irqs
[i
];
1737 qemu_register_reset(&ppc40x_mal_reset
, mal
);
1738 ppc_dcr_register(env
, MAL0_CFG
,
1739 mal
, &dcr_read_mal
, &dcr_write_mal
);
1740 ppc_dcr_register(env
, MAL0_ESR
,
1741 mal
, &dcr_read_mal
, &dcr_write_mal
);
1742 ppc_dcr_register(env
, MAL0_IER
,
1743 mal
, &dcr_read_mal
, &dcr_write_mal
);
1744 ppc_dcr_register(env
, MAL0_TXCASR
,
1745 mal
, &dcr_read_mal
, &dcr_write_mal
);
1746 ppc_dcr_register(env
, MAL0_TXCARR
,
1747 mal
, &dcr_read_mal
, &dcr_write_mal
);
1748 ppc_dcr_register(env
, MAL0_TXEOBISR
,
1749 mal
, &dcr_read_mal
, &dcr_write_mal
);
1750 ppc_dcr_register(env
, MAL0_TXDEIR
,
1751 mal
, &dcr_read_mal
, &dcr_write_mal
);
1752 ppc_dcr_register(env
, MAL0_RXCASR
,
1753 mal
, &dcr_read_mal
, &dcr_write_mal
);
1754 ppc_dcr_register(env
, MAL0_RXCARR
,
1755 mal
, &dcr_read_mal
, &dcr_write_mal
);
1756 ppc_dcr_register(env
, MAL0_RXEOBISR
,
1757 mal
, &dcr_read_mal
, &dcr_write_mal
);
1758 ppc_dcr_register(env
, MAL0_RXDEIR
,
1759 mal
, &dcr_read_mal
, &dcr_write_mal
);
1760 ppc_dcr_register(env
, MAL0_TXCTP0R
,
1761 mal
, &dcr_read_mal
, &dcr_write_mal
);
1762 ppc_dcr_register(env
, MAL0_TXCTP1R
,
1763 mal
, &dcr_read_mal
, &dcr_write_mal
);
1764 ppc_dcr_register(env
, MAL0_TXCTP2R
,
1765 mal
, &dcr_read_mal
, &dcr_write_mal
);
1766 ppc_dcr_register(env
, MAL0_TXCTP3R
,
1767 mal
, &dcr_read_mal
, &dcr_write_mal
);
1768 ppc_dcr_register(env
, MAL0_RXCTP0R
,
1769 mal
, &dcr_read_mal
, &dcr_write_mal
);
1770 ppc_dcr_register(env
, MAL0_RXCTP1R
,
1771 mal
, &dcr_read_mal
, &dcr_write_mal
);
1772 ppc_dcr_register(env
, MAL0_RCBS0
,
1773 mal
, &dcr_read_mal
, &dcr_write_mal
);
1774 ppc_dcr_register(env
, MAL0_RCBS1
,
1775 mal
, &dcr_read_mal
, &dcr_write_mal
);
1778 /*****************************************************************************/
1780 void ppc40x_core_reset (CPUState
*env
)
1784 printf("Reset PowerPC core\n");
1785 env
->interrupt_request
|= CPU_INTERRUPT_EXITTB
;
1790 qemu_system_reset_request();
1792 dbsr
= env
->spr
[SPR_40x_DBSR
];
1793 dbsr
&= ~0x00000300;
1795 env
->spr
[SPR_40x_DBSR
] = dbsr
;
1798 void ppc40x_chip_reset (CPUState
*env
)
1802 printf("Reset PowerPC chip\n");
1803 env
->interrupt_request
|= CPU_INTERRUPT_EXITTB
;
1808 qemu_system_reset_request();
1810 /* XXX: TODO reset all internal peripherals */
1811 dbsr
= env
->spr
[SPR_40x_DBSR
];
1812 dbsr
&= ~0x00000300;
1814 env
->spr
[SPR_40x_DBSR
] = dbsr
;
1817 void ppc40x_system_reset (CPUState
*env
)
1819 printf("Reset PowerPC system\n");
1820 qemu_system_reset_request();
1823 void store_40x_dbcr0 (CPUState
*env
, uint32_t val
)
1825 switch ((val
>> 28) & 0x3) {
1831 ppc40x_core_reset(env
);
1835 ppc40x_chip_reset(env
);
1839 ppc40x_system_reset(env
);
1844 /*****************************************************************************/
1847 PPC405CR_CPC0_PLLMR
= 0x0B0,
1848 PPC405CR_CPC0_CR0
= 0x0B1,
1849 PPC405CR_CPC0_CR1
= 0x0B2,
1850 PPC405CR_CPC0_PSR
= 0x0B4,
1851 PPC405CR_CPC0_JTAGID
= 0x0B5,
1852 PPC405CR_CPC0_ER
= 0x0B9,
1853 PPC405CR_CPC0_FR
= 0x0BA,
1854 PPC405CR_CPC0_SR
= 0x0BB,
1858 PPC405CR_CPU_CLK
= 0,
1859 PPC405CR_TMR_CLK
= 1,
1860 PPC405CR_PLB_CLK
= 2,
1861 PPC405CR_SDRAM_CLK
= 3,
1862 PPC405CR_OPB_CLK
= 4,
1863 PPC405CR_EXT_CLK
= 5,
1864 PPC405CR_UART_CLK
= 6,
1865 PPC405CR_CLK_NB
= 7,
1868 typedef struct ppc405cr_cpc_t ppc405cr_cpc_t
;
1869 struct ppc405cr_cpc_t
{
1870 clk_setup_t clk_setup
[PPC405CR_CLK_NB
];
1881 static void ppc405cr_clk_setup (ppc405cr_cpc_t
*cpc
)
1883 uint64_t VCO_out
, PLL_out
;
1884 uint32_t CPU_clk
, TMR_clk
, SDRAM_clk
, PLB_clk
, OPB_clk
, EXT_clk
, UART_clk
;
1887 D0
= ((cpc
->pllmr
>> 26) & 0x3) + 1; /* CBDV */
1888 if (cpc
->pllmr
& 0x80000000) {
1889 D1
= (((cpc
->pllmr
>> 20) - 1) & 0xF) + 1; /* FBDV */
1890 D2
= 8 - ((cpc
->pllmr
>> 16) & 0x7); /* FWDVA */
1892 VCO_out
= cpc
->sysclk
* M
;
1893 if (VCO_out
< 400000000 || VCO_out
> 800000000) {
1894 /* PLL cannot lock */
1895 cpc
->pllmr
&= ~0x80000000;
1898 PLL_out
= VCO_out
/ D2
;
1903 PLL_out
= cpc
->sysclk
* M
;
1906 if (cpc
->cr1
& 0x00800000)
1907 TMR_clk
= cpc
->sysclk
; /* Should have a separate clock */
1910 PLB_clk
= CPU_clk
/ D0
;
1911 SDRAM_clk
= PLB_clk
;
1912 D0
= ((cpc
->pllmr
>> 10) & 0x3) + 1;
1913 OPB_clk
= PLB_clk
/ D0
;
1914 D0
= ((cpc
->pllmr
>> 24) & 0x3) + 2;
1915 EXT_clk
= PLB_clk
/ D0
;
1916 D0
= ((cpc
->cr0
>> 1) & 0x1F) + 1;
1917 UART_clk
= CPU_clk
/ D0
;
1918 /* Setup CPU clocks */
1919 clk_setup(&cpc
->clk_setup
[PPC405CR_CPU_CLK
], CPU_clk
);
1920 /* Setup time-base clock */
1921 clk_setup(&cpc
->clk_setup
[PPC405CR_TMR_CLK
], TMR_clk
);
1922 /* Setup PLB clock */
1923 clk_setup(&cpc
->clk_setup
[PPC405CR_PLB_CLK
], PLB_clk
);
1924 /* Setup SDRAM clock */
1925 clk_setup(&cpc
->clk_setup
[PPC405CR_SDRAM_CLK
], SDRAM_clk
);
1926 /* Setup OPB clock */
1927 clk_setup(&cpc
->clk_setup
[PPC405CR_OPB_CLK
], OPB_clk
);
1928 /* Setup external clock */
1929 clk_setup(&cpc
->clk_setup
[PPC405CR_EXT_CLK
], EXT_clk
);
1930 /* Setup UART clock */
1931 clk_setup(&cpc
->clk_setup
[PPC405CR_UART_CLK
], UART_clk
);
1934 static uint32_t dcr_read_crcpc (void *opaque
, int dcrn
)
1936 ppc405cr_cpc_t
*cpc
;
1941 case PPC405CR_CPC0_PLLMR
:
1944 case PPC405CR_CPC0_CR0
:
1947 case PPC405CR_CPC0_CR1
:
1950 case PPC405CR_CPC0_PSR
:
1953 case PPC405CR_CPC0_JTAGID
:
1956 case PPC405CR_CPC0_ER
:
1959 case PPC405CR_CPC0_FR
:
1962 case PPC405CR_CPC0_SR
:
1963 ret
= ~(cpc
->er
| cpc
->fr
) & 0xFFFF0000;
1966 /* Avoid gcc warning */
1974 static void dcr_write_crcpc (void *opaque
, int dcrn
, uint32_t val
)
1976 ppc405cr_cpc_t
*cpc
;
1980 case PPC405CR_CPC0_PLLMR
:
1981 cpc
->pllmr
= val
& 0xFFF77C3F;
1983 case PPC405CR_CPC0_CR0
:
1984 cpc
->cr0
= val
& 0x0FFFFFFE;
1986 case PPC405CR_CPC0_CR1
:
1987 cpc
->cr1
= val
& 0x00800000;
1989 case PPC405CR_CPC0_PSR
:
1992 case PPC405CR_CPC0_JTAGID
:
1995 case PPC405CR_CPC0_ER
:
1996 cpc
->er
= val
& 0xBFFC0000;
1998 case PPC405CR_CPC0_FR
:
1999 cpc
->fr
= val
& 0xBFFC0000;
2001 case PPC405CR_CPC0_SR
:
2007 static void ppc405cr_cpc_reset (void *opaque
)
2009 ppc405cr_cpc_t
*cpc
;
2013 /* Compute PLLMR value from PSR settings */
2014 cpc
->pllmr
= 0x80000000;
2016 switch ((cpc
->psr
>> 30) & 3) {
2019 cpc
->pllmr
&= ~0x80000000;
2023 cpc
->pllmr
|= 5 << 16;
2027 cpc
->pllmr
|= 4 << 16;
2031 cpc
->pllmr
|= 2 << 16;
2035 D
= (cpc
->psr
>> 28) & 3;
2036 cpc
->pllmr
|= (D
+ 1) << 20;
2038 D
= (cpc
->psr
>> 25) & 7;
2053 D
= (cpc
->psr
>> 23) & 3;
2054 cpc
->pllmr
|= D
<< 26;
2056 D
= (cpc
->psr
>> 21) & 3;
2057 cpc
->pllmr
|= D
<< 10;
2059 D
= (cpc
->psr
>> 17) & 3;
2060 cpc
->pllmr
|= D
<< 24;
2061 cpc
->cr0
= 0x0000003C;
2062 cpc
->cr1
= 0x2B0D8800;
2063 cpc
->er
= 0x00000000;
2064 cpc
->fr
= 0x00000000;
2065 ppc405cr_clk_setup(cpc
);
2068 static void ppc405cr_clk_init (ppc405cr_cpc_t
*cpc
)
2072 /* XXX: this should be read from IO pins */
2073 cpc
->psr
= 0x00000000; /* 8 bits ROM */
2075 D
= 0x2; /* Divide by 4 */
2076 cpc
->psr
|= D
<< 30;
2078 D
= 0x1; /* Divide by 2 */
2079 cpc
->psr
|= D
<< 28;
2081 D
= 0x1; /* Divide by 2 */
2082 cpc
->psr
|= D
<< 23;
2084 D
= 0x5; /* M = 16 */
2085 cpc
->psr
|= D
<< 25;
2087 D
= 0x1; /* Divide by 2 */
2088 cpc
->psr
|= D
<< 21;
2090 D
= 0x2; /* Divide by 4 */
2091 cpc
->psr
|= D
<< 17;
2094 static void ppc405cr_cpc_init (CPUState
*env
, clk_setup_t clk_setup
[7],
2097 ppc405cr_cpc_t
*cpc
;
2099 cpc
= qemu_mallocz(sizeof(ppc405cr_cpc_t
));
2100 memcpy(cpc
->clk_setup
, clk_setup
,
2101 PPC405CR_CLK_NB
* sizeof(clk_setup_t
));
2102 cpc
->sysclk
= sysclk
;
2103 cpc
->jtagid
= 0x42051049;
2104 ppc_dcr_register(env
, PPC405CR_CPC0_PSR
, cpc
,
2105 &dcr_read_crcpc
, &dcr_write_crcpc
);
2106 ppc_dcr_register(env
, PPC405CR_CPC0_CR0
, cpc
,
2107 &dcr_read_crcpc
, &dcr_write_crcpc
);
2108 ppc_dcr_register(env
, PPC405CR_CPC0_CR1
, cpc
,
2109 &dcr_read_crcpc
, &dcr_write_crcpc
);
2110 ppc_dcr_register(env
, PPC405CR_CPC0_JTAGID
, cpc
,
2111 &dcr_read_crcpc
, &dcr_write_crcpc
);
2112 ppc_dcr_register(env
, PPC405CR_CPC0_PLLMR
, cpc
,
2113 &dcr_read_crcpc
, &dcr_write_crcpc
);
2114 ppc_dcr_register(env
, PPC405CR_CPC0_ER
, cpc
,
2115 &dcr_read_crcpc
, &dcr_write_crcpc
);
2116 ppc_dcr_register(env
, PPC405CR_CPC0_FR
, cpc
,
2117 &dcr_read_crcpc
, &dcr_write_crcpc
);
2118 ppc_dcr_register(env
, PPC405CR_CPC0_SR
, cpc
,
2119 &dcr_read_crcpc
, &dcr_write_crcpc
);
2120 ppc405cr_clk_init(cpc
);
2121 qemu_register_reset(ppc405cr_cpc_reset
, cpc
);
2124 CPUState
*ppc405cr_init (target_phys_addr_t ram_bases
[4],
2125 target_phys_addr_t ram_sizes
[4],
2126 uint32_t sysclk
, qemu_irq
**picp
,
2129 clk_setup_t clk_setup
[PPC405CR_CLK_NB
];
2130 qemu_irq dma_irqs
[4];
2132 qemu_irq
*pic
, *irqs
;
2134 memset(clk_setup
, 0, sizeof(clk_setup
));
2135 env
= ppc4xx_init("405cr", &clk_setup
[PPC405CR_CPU_CLK
],
2136 &clk_setup
[PPC405CR_TMR_CLK
], sysclk
);
2137 /* Memory mapped devices registers */
2139 ppc4xx_plb_init(env
);
2140 /* PLB to OPB bridge */
2141 ppc4xx_pob_init(env
);
2143 ppc4xx_opba_init(0xef600600);
2144 /* Universal interrupt controller */
2145 irqs
= qemu_mallocz(sizeof(qemu_irq
) * PPCUIC_OUTPUT_NB
);
2146 irqs
[PPCUIC_OUTPUT_INT
] =
2147 ((qemu_irq
*)env
->irq_inputs
)[PPC40x_INPUT_INT
];
2148 irqs
[PPCUIC_OUTPUT_CINT
] =
2149 ((qemu_irq
*)env
->irq_inputs
)[PPC40x_INPUT_CINT
];
2150 pic
= ppcuic_init(env
, irqs
, 0x0C0, 0, 1);
2152 /* SDRAM controller */
2153 ppc4xx_sdram_init(env
, pic
[14], 1, ram_bases
, ram_sizes
, do_init
);
2154 /* External bus controller */
2155 ppc405_ebc_init(env
);
2156 /* DMA controller */
2157 dma_irqs
[0] = pic
[26];
2158 dma_irqs
[1] = pic
[25];
2159 dma_irqs
[2] = pic
[24];
2160 dma_irqs
[3] = pic
[23];
2161 ppc405_dma_init(env
, dma_irqs
);
2163 if (serial_hds
[0] != NULL
) {
2164 serial_mm_init(0xef600300, 0, pic
[0], PPC_SERIAL_MM_BAUDBASE
,
2165 serial_hds
[0], 1, 1);
2167 if (serial_hds
[1] != NULL
) {
2168 serial_mm_init(0xef600400, 0, pic
[1], PPC_SERIAL_MM_BAUDBASE
,
2169 serial_hds
[1], 1, 1);
2171 /* IIC controller */
2172 ppc405_i2c_init(0xef600500, pic
[2]);
2174 ppc405_gpio_init(0xef600700);
2176 ppc405cr_cpc_init(env
, clk_setup
, sysclk
);
2181 /*****************************************************************************/
2185 PPC405EP_CPC0_PLLMR0
= 0x0F0,
2186 PPC405EP_CPC0_BOOT
= 0x0F1,
2187 PPC405EP_CPC0_EPCTL
= 0x0F3,
2188 PPC405EP_CPC0_PLLMR1
= 0x0F4,
2189 PPC405EP_CPC0_UCR
= 0x0F5,
2190 PPC405EP_CPC0_SRR
= 0x0F6,
2191 PPC405EP_CPC0_JTAGID
= 0x0F7,
2192 PPC405EP_CPC0_PCI
= 0x0F9,
2194 PPC405EP_CPC0_ER
= xxx
,
2195 PPC405EP_CPC0_FR
= xxx
,
2196 PPC405EP_CPC0_SR
= xxx
,
2201 PPC405EP_CPU_CLK
= 0,
2202 PPC405EP_PLB_CLK
= 1,
2203 PPC405EP_OPB_CLK
= 2,
2204 PPC405EP_EBC_CLK
= 3,
2205 PPC405EP_MAL_CLK
= 4,
2206 PPC405EP_PCI_CLK
= 5,
2207 PPC405EP_UART0_CLK
= 6,
2208 PPC405EP_UART1_CLK
= 7,
2209 PPC405EP_CLK_NB
= 8,
2212 typedef struct ppc405ep_cpc_t ppc405ep_cpc_t
;
2213 struct ppc405ep_cpc_t
{
2215 clk_setup_t clk_setup
[PPC405EP_CLK_NB
];
2223 /* Clock and power management */
2229 static void ppc405ep_compute_clocks (ppc405ep_cpc_t
*cpc
)
2231 uint32_t CPU_clk
, PLB_clk
, OPB_clk
, EBC_clk
, MAL_clk
, PCI_clk
;
2232 uint32_t UART0_clk
, UART1_clk
;
2233 uint64_t VCO_out
, PLL_out
;
2237 if ((cpc
->pllmr
[1] & 0x80000000) && !(cpc
->pllmr
[1] & 0x40000000)) {
2238 M
= (((cpc
->pllmr
[1] >> 20) - 1) & 0xF) + 1; /* FBMUL */
2239 #ifdef DEBUG_CLOCKS_LL
2240 printf("FBMUL %01" PRIx32
" %d\n", (cpc
->pllmr
[1] >> 20) & 0xF, M
);
2242 D
= 8 - ((cpc
->pllmr
[1] >> 16) & 0x7); /* FWDA */
2243 #ifdef DEBUG_CLOCKS_LL
2244 printf("FWDA %01" PRIx32
" %d\n", (cpc
->pllmr
[1] >> 16) & 0x7, D
);
2246 VCO_out
= cpc
->sysclk
* M
* D
;
2247 if (VCO_out
< 500000000UL || VCO_out
> 1000000000UL) {
2248 /* Error - unlock the PLL */
2249 printf("VCO out of range %" PRIu64
"\n", VCO_out
);
2251 cpc
->pllmr
[1] &= ~0x80000000;
2255 PLL_out
= VCO_out
/ D
;
2256 /* Pretend the PLL is locked */
2257 cpc
->boot
|= 0x00000001;
2262 PLL_out
= cpc
->sysclk
;
2263 if (cpc
->pllmr
[1] & 0x40000000) {
2264 /* Pretend the PLL is not locked */
2265 cpc
->boot
&= ~0x00000001;
2268 /* Now, compute all other clocks */
2269 D
= ((cpc
->pllmr
[0] >> 20) & 0x3) + 1; /* CCDV */
2270 #ifdef DEBUG_CLOCKS_LL
2271 printf("CCDV %01" PRIx32
" %d\n", (cpc
->pllmr
[0] >> 20) & 0x3, D
);
2273 CPU_clk
= PLL_out
/ D
;
2274 D
= ((cpc
->pllmr
[0] >> 16) & 0x3) + 1; /* CBDV */
2275 #ifdef DEBUG_CLOCKS_LL
2276 printf("CBDV %01" PRIx32
" %d\n", (cpc
->pllmr
[0] >> 16) & 0x3, D
);
2278 PLB_clk
= CPU_clk
/ D
;
2279 D
= ((cpc
->pllmr
[0] >> 12) & 0x3) + 1; /* OPDV */
2280 #ifdef DEBUG_CLOCKS_LL
2281 printf("OPDV %01" PRIx32
" %d\n", (cpc
->pllmr
[0] >> 12) & 0x3, D
);
2283 OPB_clk
= PLB_clk
/ D
;
2284 D
= ((cpc
->pllmr
[0] >> 8) & 0x3) + 2; /* EPDV */
2285 #ifdef DEBUG_CLOCKS_LL
2286 printf("EPDV %01" PRIx32
" %d\n", (cpc
->pllmr
[0] >> 8) & 0x3, D
);
2288 EBC_clk
= PLB_clk
/ D
;
2289 D
= ((cpc
->pllmr
[0] >> 4) & 0x3) + 1; /* MPDV */
2290 #ifdef DEBUG_CLOCKS_LL
2291 printf("MPDV %01" PRIx32
" %d\n", (cpc
->pllmr
[0] >> 4) & 0x3, D
);
2293 MAL_clk
= PLB_clk
/ D
;
2294 D
= (cpc
->pllmr
[0] & 0x3) + 1; /* PPDV */
2295 #ifdef DEBUG_CLOCKS_LL
2296 printf("PPDV %01" PRIx32
" %d\n", cpc
->pllmr
[0] & 0x3, D
);
2298 PCI_clk
= PLB_clk
/ D
;
2299 D
= ((cpc
->ucr
- 1) & 0x7F) + 1; /* U0DIV */
2300 #ifdef DEBUG_CLOCKS_LL
2301 printf("U0DIV %01" PRIx32
" %d\n", cpc
->ucr
& 0x7F, D
);
2303 UART0_clk
= PLL_out
/ D
;
2304 D
= (((cpc
->ucr
>> 8) - 1) & 0x7F) + 1; /* U1DIV */
2305 #ifdef DEBUG_CLOCKS_LL
2306 printf("U1DIV %01" PRIx32
" %d\n", (cpc
->ucr
>> 8) & 0x7F, D
);
2308 UART1_clk
= PLL_out
/ D
;
2310 printf("Setup PPC405EP clocks - sysclk %" PRIu32
" VCO %" PRIu64
2311 " PLL out %" PRIu64
" Hz\n", cpc
->sysclk
, VCO_out
, PLL_out
);
2312 printf("CPU %" PRIu32
" PLB %" PRIu32
" OPB %" PRIu32
" EBC %" PRIu32
2313 " MAL %" PRIu32
" PCI %" PRIu32
" UART0 %" PRIu32
2314 " UART1 %" PRIu32
"\n",
2315 CPU_clk
, PLB_clk
, OPB_clk
, EBC_clk
, MAL_clk
, PCI_clk
,
2316 UART0_clk
, UART1_clk
);
2318 /* Setup CPU clocks */
2319 clk_setup(&cpc
->clk_setup
[PPC405EP_CPU_CLK
], CPU_clk
);
2320 /* Setup PLB clock */
2321 clk_setup(&cpc
->clk_setup
[PPC405EP_PLB_CLK
], PLB_clk
);
2322 /* Setup OPB clock */
2323 clk_setup(&cpc
->clk_setup
[PPC405EP_OPB_CLK
], OPB_clk
);
2324 /* Setup external clock */
2325 clk_setup(&cpc
->clk_setup
[PPC405EP_EBC_CLK
], EBC_clk
);
2326 /* Setup MAL clock */
2327 clk_setup(&cpc
->clk_setup
[PPC405EP_MAL_CLK
], MAL_clk
);
2328 /* Setup PCI clock */
2329 clk_setup(&cpc
->clk_setup
[PPC405EP_PCI_CLK
], PCI_clk
);
2330 /* Setup UART0 clock */
2331 clk_setup(&cpc
->clk_setup
[PPC405EP_UART0_CLK
], UART0_clk
);
2332 /* Setup UART1 clock */
2333 clk_setup(&cpc
->clk_setup
[PPC405EP_UART1_CLK
], UART1_clk
);
2336 static uint32_t dcr_read_epcpc (void *opaque
, int dcrn
)
2338 ppc405ep_cpc_t
*cpc
;
2343 case PPC405EP_CPC0_BOOT
:
2346 case PPC405EP_CPC0_EPCTL
:
2349 case PPC405EP_CPC0_PLLMR0
:
2350 ret
= cpc
->pllmr
[0];
2352 case PPC405EP_CPC0_PLLMR1
:
2353 ret
= cpc
->pllmr
[1];
2355 case PPC405EP_CPC0_UCR
:
2358 case PPC405EP_CPC0_SRR
:
2361 case PPC405EP_CPC0_JTAGID
:
2364 case PPC405EP_CPC0_PCI
:
2368 /* Avoid gcc warning */
2376 static void dcr_write_epcpc (void *opaque
, int dcrn
, uint32_t val
)
2378 ppc405ep_cpc_t
*cpc
;
2382 case PPC405EP_CPC0_BOOT
:
2383 /* Read-only register */
2385 case PPC405EP_CPC0_EPCTL
:
2386 /* Don't care for now */
2387 cpc
->epctl
= val
& 0xC00000F3;
2389 case PPC405EP_CPC0_PLLMR0
:
2390 cpc
->pllmr
[0] = val
& 0x00633333;
2391 ppc405ep_compute_clocks(cpc
);
2393 case PPC405EP_CPC0_PLLMR1
:
2394 cpc
->pllmr
[1] = val
& 0xC0F73FFF;
2395 ppc405ep_compute_clocks(cpc
);
2397 case PPC405EP_CPC0_UCR
:
2398 /* UART control - don't care for now */
2399 cpc
->ucr
= val
& 0x003F7F7F;
2401 case PPC405EP_CPC0_SRR
:
2404 case PPC405EP_CPC0_JTAGID
:
2407 case PPC405EP_CPC0_PCI
:
2413 static void ppc405ep_cpc_reset (void *opaque
)
2415 ppc405ep_cpc_t
*cpc
= opaque
;
2417 cpc
->boot
= 0x00000010; /* Boot from PCI - IIC EEPROM disabled */
2418 cpc
->epctl
= 0x00000000;
2419 cpc
->pllmr
[0] = 0x00011010;
2420 cpc
->pllmr
[1] = 0x40000000;
2421 cpc
->ucr
= 0x00000000;
2422 cpc
->srr
= 0x00040000;
2423 cpc
->pci
= 0x00000000;
2424 cpc
->er
= 0x00000000;
2425 cpc
->fr
= 0x00000000;
2426 cpc
->sr
= 0x00000000;
2427 ppc405ep_compute_clocks(cpc
);
2430 /* XXX: sysclk should be between 25 and 100 MHz */
2431 static void ppc405ep_cpc_init (CPUState
*env
, clk_setup_t clk_setup
[8],
2434 ppc405ep_cpc_t
*cpc
;
2436 cpc
= qemu_mallocz(sizeof(ppc405ep_cpc_t
));
2437 memcpy(cpc
->clk_setup
, clk_setup
,
2438 PPC405EP_CLK_NB
* sizeof(clk_setup_t
));
2439 cpc
->jtagid
= 0x20267049;
2440 cpc
->sysclk
= sysclk
;
2441 qemu_register_reset(&ppc405ep_cpc_reset
, cpc
);
2442 ppc_dcr_register(env
, PPC405EP_CPC0_BOOT
, cpc
,
2443 &dcr_read_epcpc
, &dcr_write_epcpc
);
2444 ppc_dcr_register(env
, PPC405EP_CPC0_EPCTL
, cpc
,
2445 &dcr_read_epcpc
, &dcr_write_epcpc
);
2446 ppc_dcr_register(env
, PPC405EP_CPC0_PLLMR0
, cpc
,
2447 &dcr_read_epcpc
, &dcr_write_epcpc
);
2448 ppc_dcr_register(env
, PPC405EP_CPC0_PLLMR1
, cpc
,
2449 &dcr_read_epcpc
, &dcr_write_epcpc
);
2450 ppc_dcr_register(env
, PPC405EP_CPC0_UCR
, cpc
,
2451 &dcr_read_epcpc
, &dcr_write_epcpc
);
2452 ppc_dcr_register(env
, PPC405EP_CPC0_SRR
, cpc
,
2453 &dcr_read_epcpc
, &dcr_write_epcpc
);
2454 ppc_dcr_register(env
, PPC405EP_CPC0_JTAGID
, cpc
,
2455 &dcr_read_epcpc
, &dcr_write_epcpc
);
2456 ppc_dcr_register(env
, PPC405EP_CPC0_PCI
, cpc
,
2457 &dcr_read_epcpc
, &dcr_write_epcpc
);
2459 ppc_dcr_register(env
, PPC405EP_CPC0_ER
, cpc
,
2460 &dcr_read_epcpc
, &dcr_write_epcpc
);
2461 ppc_dcr_register(env
, PPC405EP_CPC0_FR
, cpc
,
2462 &dcr_read_epcpc
, &dcr_write_epcpc
);
2463 ppc_dcr_register(env
, PPC405EP_CPC0_SR
, cpc
,
2464 &dcr_read_epcpc
, &dcr_write_epcpc
);
2468 CPUState
*ppc405ep_init (target_phys_addr_t ram_bases
[2],
2469 target_phys_addr_t ram_sizes
[2],
2470 uint32_t sysclk
, qemu_irq
**picp
,
2473 clk_setup_t clk_setup
[PPC405EP_CLK_NB
], tlb_clk_setup
;
2474 qemu_irq dma_irqs
[4], gpt_irqs
[5], mal_irqs
[4];
2476 qemu_irq
*pic
, *irqs
;
2478 memset(clk_setup
, 0, sizeof(clk_setup
));
2480 env
= ppc4xx_init("405ep", &clk_setup
[PPC405EP_CPU_CLK
],
2481 &tlb_clk_setup
, sysclk
);
2482 clk_setup
[PPC405EP_CPU_CLK
].cb
= tlb_clk_setup
.cb
;
2483 clk_setup
[PPC405EP_CPU_CLK
].opaque
= tlb_clk_setup
.opaque
;
2484 /* Internal devices init */
2485 /* Memory mapped devices registers */
2487 ppc4xx_plb_init(env
);
2488 /* PLB to OPB bridge */
2489 ppc4xx_pob_init(env
);
2491 ppc4xx_opba_init(0xef600600);
2492 /* Universal interrupt controller */
2493 irqs
= qemu_mallocz(sizeof(qemu_irq
) * PPCUIC_OUTPUT_NB
);
2494 irqs
[PPCUIC_OUTPUT_INT
] =
2495 ((qemu_irq
*)env
->irq_inputs
)[PPC40x_INPUT_INT
];
2496 irqs
[PPCUIC_OUTPUT_CINT
] =
2497 ((qemu_irq
*)env
->irq_inputs
)[PPC40x_INPUT_CINT
];
2498 pic
= ppcuic_init(env
, irqs
, 0x0C0, 0, 1);
2500 /* SDRAM controller */
2501 /* XXX 405EP has no ECC interrupt */
2502 ppc4xx_sdram_init(env
, pic
[17], 2, ram_bases
, ram_sizes
, do_init
);
2503 /* External bus controller */
2504 ppc405_ebc_init(env
);
2505 /* DMA controller */
2506 dma_irqs
[0] = pic
[5];
2507 dma_irqs
[1] = pic
[6];
2508 dma_irqs
[2] = pic
[7];
2509 dma_irqs
[3] = pic
[8];
2510 ppc405_dma_init(env
, dma_irqs
);
2511 /* IIC controller */
2512 ppc405_i2c_init(0xef600500, pic
[2]);
2514 ppc405_gpio_init(0xef600700);
2516 if (serial_hds
[0] != NULL
) {
2517 serial_mm_init(0xef600300, 0, pic
[0], PPC_SERIAL_MM_BAUDBASE
,
2518 serial_hds
[0], 1, 1);
2520 if (serial_hds
[1] != NULL
) {
2521 serial_mm_init(0xef600400, 0, pic
[1], PPC_SERIAL_MM_BAUDBASE
,
2522 serial_hds
[1], 1, 1);
2525 ppc405_ocm_init(env
);
2527 gpt_irqs
[0] = pic
[19];
2528 gpt_irqs
[1] = pic
[20];
2529 gpt_irqs
[2] = pic
[21];
2530 gpt_irqs
[3] = pic
[22];
2531 gpt_irqs
[4] = pic
[23];
2532 ppc4xx_gpt_init(0xef600000, gpt_irqs
);
2534 /* Uses pic[3], pic[16], pic[18] */
2536 mal_irqs
[0] = pic
[11];
2537 mal_irqs
[1] = pic
[12];
2538 mal_irqs
[2] = pic
[13];
2539 mal_irqs
[3] = pic
[14];
2540 ppc405_mal_init(env
, mal_irqs
);
2542 /* Uses pic[9], pic[15], pic[17] */
2544 ppc405ep_cpc_init(env
, clk_setup
, sysclk
);