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 uint32_t dcr_read_plb (void *opaque
, int dcrn
)
127 /* Avoid gcc warning */
135 static void dcr_write_plb (void *opaque
, int dcrn
, uint32_t 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 static 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 qemu_register_reset(ppc4xx_plb_reset
, plb
);
178 /*****************************************************************************/
179 /* PLB to OPB bridge */
186 typedef struct ppc4xx_pob_t ppc4xx_pob_t
;
187 struct ppc4xx_pob_t
{
192 static uint32_t dcr_read_pob (void *opaque
, int dcrn
)
204 ret
= pob
->besr
[dcrn
- POB0_BESR0
];
207 /* Avoid gcc warning */
215 static void dcr_write_pob (void *opaque
, int dcrn
, uint32_t val
)
227 pob
->besr
[dcrn
- POB0_BESR0
] &= ~val
;
232 static void ppc4xx_pob_reset (void *opaque
)
238 pob
->bear
= 0x00000000;
239 pob
->besr
[0] = 0x0000000;
240 pob
->besr
[1] = 0x0000000;
243 static void ppc4xx_pob_init(CPUState
*env
)
247 pob
= qemu_mallocz(sizeof(ppc4xx_pob_t
));
248 ppc_dcr_register(env
, POB0_BEAR
, pob
, &dcr_read_pob
, &dcr_write_pob
);
249 ppc_dcr_register(env
, POB0_BESR0
, pob
, &dcr_read_pob
, &dcr_write_pob
);
250 ppc_dcr_register(env
, POB0_BESR1
, pob
, &dcr_read_pob
, &dcr_write_pob
);
251 qemu_register_reset(ppc4xx_pob_reset
, pob
);
254 /*****************************************************************************/
256 typedef struct ppc4xx_opba_t ppc4xx_opba_t
;
257 struct ppc4xx_opba_t
{
262 static uint32_t opba_readb (void *opaque
, target_phys_addr_t addr
)
268 printf("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
286 static void opba_writeb (void *opaque
,
287 target_phys_addr_t addr
, uint32_t value
)
292 printf("%s: addr " TARGET_FMT_plx
" val %08" PRIx32
"\n", __func__
, addr
,
298 opba
->cr
= value
& 0xF8;
301 opba
->pr
= value
& 0xFF;
308 static uint32_t opba_readw (void *opaque
, target_phys_addr_t addr
)
313 printf("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
315 ret
= opba_readb(opaque
, addr
) << 8;
316 ret
|= opba_readb(opaque
, addr
+ 1);
321 static void opba_writew (void *opaque
,
322 target_phys_addr_t addr
, uint32_t value
)
325 printf("%s: addr " TARGET_FMT_plx
" val %08" PRIx32
"\n", __func__
, addr
,
328 opba_writeb(opaque
, addr
, value
>> 8);
329 opba_writeb(opaque
, addr
+ 1, value
);
332 static uint32_t opba_readl (void *opaque
, target_phys_addr_t addr
)
337 printf("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
339 ret
= opba_readb(opaque
, addr
) << 24;
340 ret
|= opba_readb(opaque
, addr
+ 1) << 16;
345 static void opba_writel (void *opaque
,
346 target_phys_addr_t addr
, uint32_t value
)
349 printf("%s: addr " TARGET_FMT_plx
" val %08" PRIx32
"\n", __func__
, addr
,
352 opba_writeb(opaque
, addr
, value
>> 24);
353 opba_writeb(opaque
, addr
+ 1, value
>> 16);
356 static CPUReadMemoryFunc
* const opba_read
[] = {
362 static CPUWriteMemoryFunc
* const opba_write
[] = {
368 static void ppc4xx_opba_reset (void *opaque
)
373 opba
->cr
= 0x00; /* No dynamic priorities - park disabled */
377 static void ppc4xx_opba_init(target_phys_addr_t base
)
382 opba
= qemu_mallocz(sizeof(ppc4xx_opba_t
));
384 printf("%s: offset " TARGET_FMT_plx
"\n", __func__
, base
);
386 io
= cpu_register_io_memory(opba_read
, opba_write
, opba
);
387 cpu_register_physical_memory(base
, 0x002, io
);
388 qemu_register_reset(ppc4xx_opba_reset
, opba
);
391 /*****************************************************************************/
392 /* Code decompression controller */
395 /*****************************************************************************/
396 /* Peripheral controller */
397 typedef struct ppc4xx_ebc_t ppc4xx_ebc_t
;
398 struct ppc4xx_ebc_t
{
409 EBC0_CFGADDR
= 0x012,
410 EBC0_CFGDATA
= 0x013,
413 static uint32_t dcr_read_ebc (void *opaque
, int dcrn
)
425 case 0x00: /* B0CR */
428 case 0x01: /* B1CR */
431 case 0x02: /* B2CR */
434 case 0x03: /* B3CR */
437 case 0x04: /* B4CR */
440 case 0x05: /* B5CR */
443 case 0x06: /* B6CR */
446 case 0x07: /* B7CR */
449 case 0x10: /* B0AP */
452 case 0x11: /* B1AP */
455 case 0x12: /* B2AP */
458 case 0x13: /* B3AP */
461 case 0x14: /* B4AP */
464 case 0x15: /* B5AP */
467 case 0x16: /* B6AP */
470 case 0x17: /* B7AP */
473 case 0x20: /* BEAR */
476 case 0x21: /* BESR0 */
479 case 0x22: /* BESR1 */
498 static void dcr_write_ebc (void *opaque
, int dcrn
, uint32_t val
)
509 case 0x00: /* B0CR */
511 case 0x01: /* B1CR */
513 case 0x02: /* B2CR */
515 case 0x03: /* B3CR */
517 case 0x04: /* B4CR */
519 case 0x05: /* B5CR */
521 case 0x06: /* B6CR */
523 case 0x07: /* B7CR */
525 case 0x10: /* B0AP */
527 case 0x11: /* B1AP */
529 case 0x12: /* B2AP */
531 case 0x13: /* B3AP */
533 case 0x14: /* B4AP */
535 case 0x15: /* B5AP */
537 case 0x16: /* B6AP */
539 case 0x17: /* B7AP */
541 case 0x20: /* BEAR */
543 case 0x21: /* BESR0 */
545 case 0x22: /* BESR1 */
558 static void ebc_reset (void *opaque
)
564 ebc
->addr
= 0x00000000;
565 ebc
->bap
[0] = 0x7F8FFE80;
566 ebc
->bcr
[0] = 0xFFE28000;
567 for (i
= 0; i
< 8; i
++) {
568 ebc
->bap
[i
] = 0x00000000;
569 ebc
->bcr
[i
] = 0x00000000;
571 ebc
->besr0
= 0x00000000;
572 ebc
->besr1
= 0x00000000;
573 ebc
->cfg
= 0x80400000;
576 static void ppc405_ebc_init(CPUState
*env
)
580 ebc
= qemu_mallocz(sizeof(ppc4xx_ebc_t
));
581 qemu_register_reset(&ebc_reset
, ebc
);
582 ppc_dcr_register(env
, EBC0_CFGADDR
,
583 ebc
, &dcr_read_ebc
, &dcr_write_ebc
);
584 ppc_dcr_register(env
, EBC0_CFGDATA
,
585 ebc
, &dcr_read_ebc
, &dcr_write_ebc
);
588 /*****************************************************************************/
617 typedef struct ppc405_dma_t ppc405_dma_t
;
618 struct ppc405_dma_t
{
631 static uint32_t dcr_read_dma (void *opaque
, int dcrn
)
640 static void dcr_write_dma (void *opaque
, int dcrn
, uint32_t val
)
647 static void ppc405_dma_reset (void *opaque
)
653 for (i
= 0; i
< 4; i
++) {
654 dma
->cr
[i
] = 0x00000000;
655 dma
->ct
[i
] = 0x00000000;
656 dma
->da
[i
] = 0x00000000;
657 dma
->sa
[i
] = 0x00000000;
658 dma
->sg
[i
] = 0x00000000;
660 dma
->sr
= 0x00000000;
661 dma
->sgc
= 0x00000000;
662 dma
->slp
= 0x7C000000;
663 dma
->pol
= 0x00000000;
666 static void ppc405_dma_init(CPUState
*env
, qemu_irq irqs
[4])
670 dma
= qemu_mallocz(sizeof(ppc405_dma_t
));
671 memcpy(dma
->irqs
, irqs
, 4 * sizeof(qemu_irq
));
672 qemu_register_reset(&ppc405_dma_reset
, dma
);
673 ppc_dcr_register(env
, DMA0_CR0
,
674 dma
, &dcr_read_dma
, &dcr_write_dma
);
675 ppc_dcr_register(env
, DMA0_CT0
,
676 dma
, &dcr_read_dma
, &dcr_write_dma
);
677 ppc_dcr_register(env
, DMA0_DA0
,
678 dma
, &dcr_read_dma
, &dcr_write_dma
);
679 ppc_dcr_register(env
, DMA0_SA0
,
680 dma
, &dcr_read_dma
, &dcr_write_dma
);
681 ppc_dcr_register(env
, DMA0_SG0
,
682 dma
, &dcr_read_dma
, &dcr_write_dma
);
683 ppc_dcr_register(env
, DMA0_CR1
,
684 dma
, &dcr_read_dma
, &dcr_write_dma
);
685 ppc_dcr_register(env
, DMA0_CT1
,
686 dma
, &dcr_read_dma
, &dcr_write_dma
);
687 ppc_dcr_register(env
, DMA0_DA1
,
688 dma
, &dcr_read_dma
, &dcr_write_dma
);
689 ppc_dcr_register(env
, DMA0_SA1
,
690 dma
, &dcr_read_dma
, &dcr_write_dma
);
691 ppc_dcr_register(env
, DMA0_SG1
,
692 dma
, &dcr_read_dma
, &dcr_write_dma
);
693 ppc_dcr_register(env
, DMA0_CR2
,
694 dma
, &dcr_read_dma
, &dcr_write_dma
);
695 ppc_dcr_register(env
, DMA0_CT2
,
696 dma
, &dcr_read_dma
, &dcr_write_dma
);
697 ppc_dcr_register(env
, DMA0_DA2
,
698 dma
, &dcr_read_dma
, &dcr_write_dma
);
699 ppc_dcr_register(env
, DMA0_SA2
,
700 dma
, &dcr_read_dma
, &dcr_write_dma
);
701 ppc_dcr_register(env
, DMA0_SG2
,
702 dma
, &dcr_read_dma
, &dcr_write_dma
);
703 ppc_dcr_register(env
, DMA0_CR3
,
704 dma
, &dcr_read_dma
, &dcr_write_dma
);
705 ppc_dcr_register(env
, DMA0_CT3
,
706 dma
, &dcr_read_dma
, &dcr_write_dma
);
707 ppc_dcr_register(env
, DMA0_DA3
,
708 dma
, &dcr_read_dma
, &dcr_write_dma
);
709 ppc_dcr_register(env
, DMA0_SA3
,
710 dma
, &dcr_read_dma
, &dcr_write_dma
);
711 ppc_dcr_register(env
, DMA0_SG3
,
712 dma
, &dcr_read_dma
, &dcr_write_dma
);
713 ppc_dcr_register(env
, DMA0_SR
,
714 dma
, &dcr_read_dma
, &dcr_write_dma
);
715 ppc_dcr_register(env
, DMA0_SGC
,
716 dma
, &dcr_read_dma
, &dcr_write_dma
);
717 ppc_dcr_register(env
, DMA0_SLP
,
718 dma
, &dcr_read_dma
, &dcr_write_dma
);
719 ppc_dcr_register(env
, DMA0_POL
,
720 dma
, &dcr_read_dma
, &dcr_write_dma
);
723 /*****************************************************************************/
725 typedef struct ppc405_gpio_t ppc405_gpio_t
;
726 struct ppc405_gpio_t
{
740 static uint32_t ppc405_gpio_readb (void *opaque
, target_phys_addr_t addr
)
746 printf("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
752 static void ppc405_gpio_writeb (void *opaque
,
753 target_phys_addr_t addr
, uint32_t value
)
759 printf("%s: addr " TARGET_FMT_plx
" val %08" PRIx32
"\n", __func__
, addr
,
764 static uint32_t ppc405_gpio_readw (void *opaque
, target_phys_addr_t addr
)
770 printf("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
776 static void ppc405_gpio_writew (void *opaque
,
777 target_phys_addr_t addr
, uint32_t value
)
783 printf("%s: addr " TARGET_FMT_plx
" val %08" PRIx32
"\n", __func__
, addr
,
788 static uint32_t ppc405_gpio_readl (void *opaque
, target_phys_addr_t addr
)
794 printf("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
800 static void ppc405_gpio_writel (void *opaque
,
801 target_phys_addr_t addr
, uint32_t value
)
807 printf("%s: addr " TARGET_FMT_plx
" val %08" PRIx32
"\n", __func__
, addr
,
812 static CPUReadMemoryFunc
* const ppc405_gpio_read
[] = {
818 static CPUWriteMemoryFunc
* const ppc405_gpio_write
[] = {
824 static void ppc405_gpio_reset (void *opaque
)
831 static void ppc405_gpio_init(target_phys_addr_t base
)
836 gpio
= qemu_mallocz(sizeof(ppc405_gpio_t
));
838 printf("%s: offset " TARGET_FMT_plx
"\n", __func__
, base
);
840 io
= cpu_register_io_memory(ppc405_gpio_read
, ppc405_gpio_write
, gpio
);
841 cpu_register_physical_memory(base
, 0x038, io
);
842 qemu_register_reset(&ppc405_gpio_reset
, gpio
);
845 /*****************************************************************************/
849 OCM0_ISACNTL
= 0x019,
851 OCM0_DSACNTL
= 0x01B,
854 typedef struct ppc405_ocm_t ppc405_ocm_t
;
855 struct ppc405_ocm_t
{
863 static void ocm_update_mappings (ppc405_ocm_t
*ocm
,
864 uint32_t isarc
, uint32_t isacntl
,
865 uint32_t dsarc
, uint32_t dsacntl
)
868 printf("OCM update ISA %08" PRIx32
" %08" PRIx32
" (%08" PRIx32
869 " %08" PRIx32
") DSA %08" PRIx32
" %08" PRIx32
870 " (%08" PRIx32
" %08" PRIx32
")\n",
871 isarc
, isacntl
, dsarc
, dsacntl
,
872 ocm
->isarc
, ocm
->isacntl
, ocm
->dsarc
, ocm
->dsacntl
);
874 if (ocm
->isarc
!= isarc
||
875 (ocm
->isacntl
& 0x80000000) != (isacntl
& 0x80000000)) {
876 if (ocm
->isacntl
& 0x80000000) {
877 /* Unmap previously assigned memory region */
878 printf("OCM unmap ISA %08" PRIx32
"\n", ocm
->isarc
);
879 cpu_register_physical_memory(ocm
->isarc
, 0x04000000,
882 if (isacntl
& 0x80000000) {
883 /* Map new instruction memory region */
885 printf("OCM map ISA %08" PRIx32
"\n", isarc
);
887 cpu_register_physical_memory(isarc
, 0x04000000,
888 ocm
->offset
| IO_MEM_RAM
);
891 if (ocm
->dsarc
!= dsarc
||
892 (ocm
->dsacntl
& 0x80000000) != (dsacntl
& 0x80000000)) {
893 if (ocm
->dsacntl
& 0x80000000) {
894 /* Beware not to unmap the region we just mapped */
895 if (!(isacntl
& 0x80000000) || ocm
->dsarc
!= isarc
) {
896 /* Unmap previously assigned memory region */
898 printf("OCM unmap DSA %08" PRIx32
"\n", ocm
->dsarc
);
900 cpu_register_physical_memory(ocm
->dsarc
, 0x04000000,
904 if (dsacntl
& 0x80000000) {
905 /* Beware not to remap the region we just mapped */
906 if (!(isacntl
& 0x80000000) || dsarc
!= isarc
) {
907 /* Map new data memory region */
909 printf("OCM map DSA %08" PRIx32
"\n", dsarc
);
911 cpu_register_physical_memory(dsarc
, 0x04000000,
912 ocm
->offset
| IO_MEM_RAM
);
918 static uint32_t dcr_read_ocm (void *opaque
, int dcrn
)
945 static void dcr_write_ocm (void *opaque
, int dcrn
, uint32_t val
)
948 uint32_t isarc
, dsarc
, isacntl
, dsacntl
;
953 isacntl
= ocm
->isacntl
;
954 dsacntl
= ocm
->dsacntl
;
957 isarc
= val
& 0xFC000000;
960 isacntl
= val
& 0xC0000000;
963 isarc
= val
& 0xFC000000;
966 isacntl
= val
& 0xC0000000;
969 ocm_update_mappings(ocm
, isarc
, isacntl
, dsarc
, dsacntl
);
972 ocm
->isacntl
= isacntl
;
973 ocm
->dsacntl
= dsacntl
;
976 static void ocm_reset (void *opaque
)
979 uint32_t isarc
, dsarc
, isacntl
, dsacntl
;
983 isacntl
= 0x00000000;
985 dsacntl
= 0x00000000;
986 ocm_update_mappings(ocm
, isarc
, isacntl
, dsarc
, dsacntl
);
989 ocm
->isacntl
= isacntl
;
990 ocm
->dsacntl
= dsacntl
;
993 static void ppc405_ocm_init(CPUState
*env
)
997 ocm
= qemu_mallocz(sizeof(ppc405_ocm_t
));
998 ocm
->offset
= qemu_ram_alloc(4096);
999 qemu_register_reset(&ocm_reset
, ocm
);
1000 ppc_dcr_register(env
, OCM0_ISARC
,
1001 ocm
, &dcr_read_ocm
, &dcr_write_ocm
);
1002 ppc_dcr_register(env
, OCM0_ISACNTL
,
1003 ocm
, &dcr_read_ocm
, &dcr_write_ocm
);
1004 ppc_dcr_register(env
, OCM0_DSARC
,
1005 ocm
, &dcr_read_ocm
, &dcr_write_ocm
);
1006 ppc_dcr_register(env
, OCM0_DSACNTL
,
1007 ocm
, &dcr_read_ocm
, &dcr_write_ocm
);
1010 /*****************************************************************************/
1011 /* I2C controller */
1012 typedef struct ppc4xx_i2c_t ppc4xx_i2c_t
;
1013 struct ppc4xx_i2c_t
{
1032 static uint32_t ppc4xx_i2c_readb (void *opaque
, target_phys_addr_t addr
)
1038 printf("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
1043 // i2c_readbyte(&i2c->mdata);
1083 ret
= i2c
->xtcntlss
;
1086 ret
= i2c
->directcntl
;
1093 printf("%s: addr " TARGET_FMT_plx
" %02" PRIx32
"\n", __func__
, addr
, ret
);
1099 static void ppc4xx_i2c_writeb (void *opaque
,
1100 target_phys_addr_t addr
, uint32_t value
)
1105 printf("%s: addr " TARGET_FMT_plx
" val %08" PRIx32
"\n", __func__
, addr
,
1112 // i2c_sendbyte(&i2c->mdata);
1127 i2c
->mdcntl
= value
& 0xDF;
1130 i2c
->sts
&= ~(value
& 0x0A);
1133 i2c
->extsts
&= ~(value
& 0x8F);
1142 i2c
->clkdiv
= value
;
1145 i2c
->intrmsk
= value
;
1148 i2c
->xfrcnt
= value
& 0x77;
1151 i2c
->xtcntlss
= value
;
1154 i2c
->directcntl
= value
& 0x7;
1159 static uint32_t ppc4xx_i2c_readw (void *opaque
, target_phys_addr_t addr
)
1164 printf("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
1166 ret
= ppc4xx_i2c_readb(opaque
, addr
) << 8;
1167 ret
|= ppc4xx_i2c_readb(opaque
, addr
+ 1);
1172 static void ppc4xx_i2c_writew (void *opaque
,
1173 target_phys_addr_t addr
, uint32_t value
)
1176 printf("%s: addr " TARGET_FMT_plx
" val %08" PRIx32
"\n", __func__
, addr
,
1179 ppc4xx_i2c_writeb(opaque
, addr
, value
>> 8);
1180 ppc4xx_i2c_writeb(opaque
, addr
+ 1, value
);
1183 static uint32_t ppc4xx_i2c_readl (void *opaque
, target_phys_addr_t addr
)
1188 printf("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
1190 ret
= ppc4xx_i2c_readb(opaque
, addr
) << 24;
1191 ret
|= ppc4xx_i2c_readb(opaque
, addr
+ 1) << 16;
1192 ret
|= ppc4xx_i2c_readb(opaque
, addr
+ 2) << 8;
1193 ret
|= ppc4xx_i2c_readb(opaque
, addr
+ 3);
1198 static void ppc4xx_i2c_writel (void *opaque
,
1199 target_phys_addr_t addr
, uint32_t value
)
1202 printf("%s: addr " TARGET_FMT_plx
" val %08" PRIx32
"\n", __func__
, addr
,
1205 ppc4xx_i2c_writeb(opaque
, addr
, value
>> 24);
1206 ppc4xx_i2c_writeb(opaque
, addr
+ 1, value
>> 16);
1207 ppc4xx_i2c_writeb(opaque
, addr
+ 2, value
>> 8);
1208 ppc4xx_i2c_writeb(opaque
, addr
+ 3, value
);
1211 static CPUReadMemoryFunc
* const i2c_read
[] = {
1217 static CPUWriteMemoryFunc
* const i2c_write
[] = {
1223 static void ppc4xx_i2c_reset (void *opaque
)
1236 i2c
->directcntl
= 0x0F;
1239 static void ppc405_i2c_init(target_phys_addr_t base
, qemu_irq irq
)
1244 i2c
= qemu_mallocz(sizeof(ppc4xx_i2c_t
));
1247 printf("%s: offset " TARGET_FMT_plx
"\n", __func__
, base
);
1249 io
= cpu_register_io_memory(i2c_read
, i2c_write
, i2c
);
1250 cpu_register_physical_memory(base
, 0x011, io
);
1251 qemu_register_reset(ppc4xx_i2c_reset
, i2c
);
1254 /*****************************************************************************/
1255 /* General purpose timers */
1256 typedef struct ppc4xx_gpt_t ppc4xx_gpt_t
;
1257 struct ppc4xx_gpt_t
{
1260 struct QEMUTimer
*timer
;
1271 static uint32_t ppc4xx_gpt_readb (void *opaque
, target_phys_addr_t addr
)
1274 printf("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
1276 /* XXX: generate a bus fault */
1280 static void ppc4xx_gpt_writeb (void *opaque
,
1281 target_phys_addr_t addr
, uint32_t value
)
1284 printf("%s: addr " TARGET_FMT_plx
" val %08" PRIx32
"\n", __func__
, addr
,
1287 /* XXX: generate a bus fault */
1290 static uint32_t ppc4xx_gpt_readw (void *opaque
, target_phys_addr_t addr
)
1293 printf("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
1295 /* XXX: generate a bus fault */
1299 static void ppc4xx_gpt_writew (void *opaque
,
1300 target_phys_addr_t addr
, uint32_t value
)
1303 printf("%s: addr " TARGET_FMT_plx
" val %08" PRIx32
"\n", __func__
, addr
,
1306 /* XXX: generate a bus fault */
1309 static int ppc4xx_gpt_compare (ppc4xx_gpt_t
*gpt
, int n
)
1315 static void ppc4xx_gpt_set_output (ppc4xx_gpt_t
*gpt
, int n
, int level
)
1320 static void ppc4xx_gpt_set_outputs (ppc4xx_gpt_t
*gpt
)
1326 for (i
= 0; i
< 5; i
++) {
1327 if (gpt
->oe
& mask
) {
1328 /* Output is enabled */
1329 if (ppc4xx_gpt_compare(gpt
, i
)) {
1330 /* Comparison is OK */
1331 ppc4xx_gpt_set_output(gpt
, i
, gpt
->ol
& mask
);
1333 /* Comparison is KO */
1334 ppc4xx_gpt_set_output(gpt
, i
, gpt
->ol
& mask
? 0 : 1);
1341 static void ppc4xx_gpt_set_irqs (ppc4xx_gpt_t
*gpt
)
1347 for (i
= 0; i
< 5; i
++) {
1348 if (gpt
->is
& gpt
->im
& mask
)
1349 qemu_irq_raise(gpt
->irqs
[i
]);
1351 qemu_irq_lower(gpt
->irqs
[i
]);
1356 static void ppc4xx_gpt_compute_timer (ppc4xx_gpt_t
*gpt
)
1361 static uint32_t ppc4xx_gpt_readl (void *opaque
, target_phys_addr_t addr
)
1368 printf("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
1373 /* Time base counter */
1374 ret
= muldiv64(qemu_get_clock(vm_clock
) + gpt
->tb_offset
,
1375 gpt
->tb_freq
, get_ticks_per_sec());
1386 /* Interrupt mask */
1391 /* Interrupt status */
1395 /* Interrupt enable */
1400 idx
= (addr
- 0x80) >> 2;
1401 ret
= gpt
->comp
[idx
];
1405 idx
= (addr
- 0xC0) >> 2;
1406 ret
= gpt
->mask
[idx
];
1416 static void ppc4xx_gpt_writel (void *opaque
,
1417 target_phys_addr_t addr
, uint32_t value
)
1423 printf("%s: addr " TARGET_FMT_plx
" val %08" PRIx32
"\n", __func__
, addr
,
1429 /* Time base counter */
1430 gpt
->tb_offset
= muldiv64(value
, get_ticks_per_sec(), gpt
->tb_freq
)
1431 - qemu_get_clock(vm_clock
);
1432 ppc4xx_gpt_compute_timer(gpt
);
1436 gpt
->oe
= value
& 0xF8000000;
1437 ppc4xx_gpt_set_outputs(gpt
);
1441 gpt
->ol
= value
& 0xF8000000;
1442 ppc4xx_gpt_set_outputs(gpt
);
1445 /* Interrupt mask */
1446 gpt
->im
= value
& 0x0000F800;
1449 /* Interrupt status set */
1450 gpt
->is
|= value
& 0x0000F800;
1451 ppc4xx_gpt_set_irqs(gpt
);
1454 /* Interrupt status clear */
1455 gpt
->is
&= ~(value
& 0x0000F800);
1456 ppc4xx_gpt_set_irqs(gpt
);
1459 /* Interrupt enable */
1460 gpt
->ie
= value
& 0x0000F800;
1461 ppc4xx_gpt_set_irqs(gpt
);
1465 idx
= (addr
- 0x80) >> 2;
1466 gpt
->comp
[idx
] = value
& 0xF8000000;
1467 ppc4xx_gpt_compute_timer(gpt
);
1471 idx
= (addr
- 0xC0) >> 2;
1472 gpt
->mask
[idx
] = value
& 0xF8000000;
1473 ppc4xx_gpt_compute_timer(gpt
);
1478 static CPUReadMemoryFunc
* const gpt_read
[] = {
1484 static CPUWriteMemoryFunc
* const gpt_write
[] = {
1490 static void ppc4xx_gpt_cb (void *opaque
)
1495 ppc4xx_gpt_set_irqs(gpt
);
1496 ppc4xx_gpt_set_outputs(gpt
);
1497 ppc4xx_gpt_compute_timer(gpt
);
1500 static void ppc4xx_gpt_reset (void *opaque
)
1506 qemu_del_timer(gpt
->timer
);
1507 gpt
->oe
= 0x00000000;
1508 gpt
->ol
= 0x00000000;
1509 gpt
->im
= 0x00000000;
1510 gpt
->is
= 0x00000000;
1511 gpt
->ie
= 0x00000000;
1512 for (i
= 0; i
< 5; i
++) {
1513 gpt
->comp
[i
] = 0x00000000;
1514 gpt
->mask
[i
] = 0x00000000;
1518 static void ppc4xx_gpt_init(target_phys_addr_t base
, qemu_irq irqs
[5])
1524 gpt
= qemu_mallocz(sizeof(ppc4xx_gpt_t
));
1525 for (i
= 0; i
< 5; i
++) {
1526 gpt
->irqs
[i
] = irqs
[i
];
1528 gpt
->timer
= qemu_new_timer(vm_clock
, &ppc4xx_gpt_cb
, gpt
);
1530 printf("%s: offset " TARGET_FMT_plx
"\n", __func__
, base
);
1532 io
= cpu_register_io_memory(gpt_read
, gpt_write
, gpt
);
1533 cpu_register_physical_memory(base
, 0x0d4, io
);
1534 qemu_register_reset(ppc4xx_gpt_reset
, gpt
);
1537 /*****************************************************************************/
1543 MAL0_TXCASR
= 0x184,
1544 MAL0_TXCARR
= 0x185,
1545 MAL0_TXEOBISR
= 0x186,
1546 MAL0_TXDEIR
= 0x187,
1547 MAL0_RXCASR
= 0x190,
1548 MAL0_RXCARR
= 0x191,
1549 MAL0_RXEOBISR
= 0x192,
1550 MAL0_RXDEIR
= 0x193,
1551 MAL0_TXCTP0R
= 0x1A0,
1552 MAL0_TXCTP1R
= 0x1A1,
1553 MAL0_TXCTP2R
= 0x1A2,
1554 MAL0_TXCTP3R
= 0x1A3,
1555 MAL0_RXCTP0R
= 0x1C0,
1556 MAL0_RXCTP1R
= 0x1C1,
1561 typedef struct ppc40x_mal_t ppc40x_mal_t
;
1562 struct ppc40x_mal_t
{
1580 static void ppc40x_mal_reset (void *opaque
);
1582 static uint32_t dcr_read_mal (void *opaque
, int dcrn
)
1605 ret
= mal
->txeobisr
;
1617 ret
= mal
->rxeobisr
;
1623 ret
= mal
->txctpr
[0];
1626 ret
= mal
->txctpr
[1];
1629 ret
= mal
->txctpr
[2];
1632 ret
= mal
->txctpr
[3];
1635 ret
= mal
->rxctpr
[0];
1638 ret
= mal
->rxctpr
[1];
1654 static void dcr_write_mal (void *opaque
, int dcrn
, uint32_t val
)
1662 if (val
& 0x80000000)
1663 ppc40x_mal_reset(mal
);
1664 mal
->cfg
= val
& 0x00FFC087;
1671 mal
->ier
= val
& 0x0000001F;
1674 mal
->txcasr
= val
& 0xF0000000;
1677 mal
->txcarr
= val
& 0xF0000000;
1681 mal
->txeobisr
&= ~val
;
1685 mal
->txdeir
&= ~val
;
1688 mal
->rxcasr
= val
& 0xC0000000;
1691 mal
->rxcarr
= val
& 0xC0000000;
1695 mal
->rxeobisr
&= ~val
;
1699 mal
->rxdeir
&= ~val
;
1713 mal
->txctpr
[idx
] = val
;
1721 mal
->rxctpr
[idx
] = val
;
1725 goto update_rx_size
;
1729 mal
->rcbs
[idx
] = val
& 0x000000FF;
1734 static void ppc40x_mal_reset (void *opaque
)
1739 mal
->cfg
= 0x0007C000;
1740 mal
->esr
= 0x00000000;
1741 mal
->ier
= 0x00000000;
1742 mal
->rxcasr
= 0x00000000;
1743 mal
->rxdeir
= 0x00000000;
1744 mal
->rxeobisr
= 0x00000000;
1745 mal
->txcasr
= 0x00000000;
1746 mal
->txdeir
= 0x00000000;
1747 mal
->txeobisr
= 0x00000000;
1750 static void ppc405_mal_init(CPUState
*env
, qemu_irq irqs
[4])
1755 mal
= qemu_mallocz(sizeof(ppc40x_mal_t
));
1756 for (i
= 0; i
< 4; i
++)
1757 mal
->irqs
[i
] = irqs
[i
];
1758 qemu_register_reset(&ppc40x_mal_reset
, mal
);
1759 ppc_dcr_register(env
, MAL0_CFG
,
1760 mal
, &dcr_read_mal
, &dcr_write_mal
);
1761 ppc_dcr_register(env
, MAL0_ESR
,
1762 mal
, &dcr_read_mal
, &dcr_write_mal
);
1763 ppc_dcr_register(env
, MAL0_IER
,
1764 mal
, &dcr_read_mal
, &dcr_write_mal
);
1765 ppc_dcr_register(env
, MAL0_TXCASR
,
1766 mal
, &dcr_read_mal
, &dcr_write_mal
);
1767 ppc_dcr_register(env
, MAL0_TXCARR
,
1768 mal
, &dcr_read_mal
, &dcr_write_mal
);
1769 ppc_dcr_register(env
, MAL0_TXEOBISR
,
1770 mal
, &dcr_read_mal
, &dcr_write_mal
);
1771 ppc_dcr_register(env
, MAL0_TXDEIR
,
1772 mal
, &dcr_read_mal
, &dcr_write_mal
);
1773 ppc_dcr_register(env
, MAL0_RXCASR
,
1774 mal
, &dcr_read_mal
, &dcr_write_mal
);
1775 ppc_dcr_register(env
, MAL0_RXCARR
,
1776 mal
, &dcr_read_mal
, &dcr_write_mal
);
1777 ppc_dcr_register(env
, MAL0_RXEOBISR
,
1778 mal
, &dcr_read_mal
, &dcr_write_mal
);
1779 ppc_dcr_register(env
, MAL0_RXDEIR
,
1780 mal
, &dcr_read_mal
, &dcr_write_mal
);
1781 ppc_dcr_register(env
, MAL0_TXCTP0R
,
1782 mal
, &dcr_read_mal
, &dcr_write_mal
);
1783 ppc_dcr_register(env
, MAL0_TXCTP1R
,
1784 mal
, &dcr_read_mal
, &dcr_write_mal
);
1785 ppc_dcr_register(env
, MAL0_TXCTP2R
,
1786 mal
, &dcr_read_mal
, &dcr_write_mal
);
1787 ppc_dcr_register(env
, MAL0_TXCTP3R
,
1788 mal
, &dcr_read_mal
, &dcr_write_mal
);
1789 ppc_dcr_register(env
, MAL0_RXCTP0R
,
1790 mal
, &dcr_read_mal
, &dcr_write_mal
);
1791 ppc_dcr_register(env
, MAL0_RXCTP1R
,
1792 mal
, &dcr_read_mal
, &dcr_write_mal
);
1793 ppc_dcr_register(env
, MAL0_RCBS0
,
1794 mal
, &dcr_read_mal
, &dcr_write_mal
);
1795 ppc_dcr_register(env
, MAL0_RCBS1
,
1796 mal
, &dcr_read_mal
, &dcr_write_mal
);
1799 /*****************************************************************************/
1801 void ppc40x_core_reset (CPUState
*env
)
1805 printf("Reset PowerPC core\n");
1806 env
->interrupt_request
|= CPU_INTERRUPT_EXITTB
;
1811 qemu_system_reset_request();
1813 dbsr
= env
->spr
[SPR_40x_DBSR
];
1814 dbsr
&= ~0x00000300;
1816 env
->spr
[SPR_40x_DBSR
] = dbsr
;
1819 void ppc40x_chip_reset (CPUState
*env
)
1823 printf("Reset PowerPC chip\n");
1824 env
->interrupt_request
|= CPU_INTERRUPT_EXITTB
;
1829 qemu_system_reset_request();
1831 /* XXX: TODO reset all internal peripherals */
1832 dbsr
= env
->spr
[SPR_40x_DBSR
];
1833 dbsr
&= ~0x00000300;
1835 env
->spr
[SPR_40x_DBSR
] = dbsr
;
1838 void ppc40x_system_reset (CPUState
*env
)
1840 printf("Reset PowerPC system\n");
1841 qemu_system_reset_request();
1844 void store_40x_dbcr0 (CPUState
*env
, uint32_t val
)
1846 switch ((val
>> 28) & 0x3) {
1852 ppc40x_core_reset(env
);
1856 ppc40x_chip_reset(env
);
1860 ppc40x_system_reset(env
);
1865 /*****************************************************************************/
1868 PPC405CR_CPC0_PLLMR
= 0x0B0,
1869 PPC405CR_CPC0_CR0
= 0x0B1,
1870 PPC405CR_CPC0_CR1
= 0x0B2,
1871 PPC405CR_CPC0_PSR
= 0x0B4,
1872 PPC405CR_CPC0_JTAGID
= 0x0B5,
1873 PPC405CR_CPC0_ER
= 0x0B9,
1874 PPC405CR_CPC0_FR
= 0x0BA,
1875 PPC405CR_CPC0_SR
= 0x0BB,
1879 PPC405CR_CPU_CLK
= 0,
1880 PPC405CR_TMR_CLK
= 1,
1881 PPC405CR_PLB_CLK
= 2,
1882 PPC405CR_SDRAM_CLK
= 3,
1883 PPC405CR_OPB_CLK
= 4,
1884 PPC405CR_EXT_CLK
= 5,
1885 PPC405CR_UART_CLK
= 6,
1886 PPC405CR_CLK_NB
= 7,
1889 typedef struct ppc405cr_cpc_t ppc405cr_cpc_t
;
1890 struct ppc405cr_cpc_t
{
1891 clk_setup_t clk_setup
[PPC405CR_CLK_NB
];
1902 static void ppc405cr_clk_setup (ppc405cr_cpc_t
*cpc
)
1904 uint64_t VCO_out
, PLL_out
;
1905 uint32_t CPU_clk
, TMR_clk
, SDRAM_clk
, PLB_clk
, OPB_clk
, EXT_clk
, UART_clk
;
1908 D0
= ((cpc
->pllmr
>> 26) & 0x3) + 1; /* CBDV */
1909 if (cpc
->pllmr
& 0x80000000) {
1910 D1
= (((cpc
->pllmr
>> 20) - 1) & 0xF) + 1; /* FBDV */
1911 D2
= 8 - ((cpc
->pllmr
>> 16) & 0x7); /* FWDVA */
1913 VCO_out
= cpc
->sysclk
* M
;
1914 if (VCO_out
< 400000000 || VCO_out
> 800000000) {
1915 /* PLL cannot lock */
1916 cpc
->pllmr
&= ~0x80000000;
1919 PLL_out
= VCO_out
/ D2
;
1924 PLL_out
= cpc
->sysclk
* M
;
1927 if (cpc
->cr1
& 0x00800000)
1928 TMR_clk
= cpc
->sysclk
; /* Should have a separate clock */
1931 PLB_clk
= CPU_clk
/ D0
;
1932 SDRAM_clk
= PLB_clk
;
1933 D0
= ((cpc
->pllmr
>> 10) & 0x3) + 1;
1934 OPB_clk
= PLB_clk
/ D0
;
1935 D0
= ((cpc
->pllmr
>> 24) & 0x3) + 2;
1936 EXT_clk
= PLB_clk
/ D0
;
1937 D0
= ((cpc
->cr0
>> 1) & 0x1F) + 1;
1938 UART_clk
= CPU_clk
/ D0
;
1939 /* Setup CPU clocks */
1940 clk_setup(&cpc
->clk_setup
[PPC405CR_CPU_CLK
], CPU_clk
);
1941 /* Setup time-base clock */
1942 clk_setup(&cpc
->clk_setup
[PPC405CR_TMR_CLK
], TMR_clk
);
1943 /* Setup PLB clock */
1944 clk_setup(&cpc
->clk_setup
[PPC405CR_PLB_CLK
], PLB_clk
);
1945 /* Setup SDRAM clock */
1946 clk_setup(&cpc
->clk_setup
[PPC405CR_SDRAM_CLK
], SDRAM_clk
);
1947 /* Setup OPB clock */
1948 clk_setup(&cpc
->clk_setup
[PPC405CR_OPB_CLK
], OPB_clk
);
1949 /* Setup external clock */
1950 clk_setup(&cpc
->clk_setup
[PPC405CR_EXT_CLK
], EXT_clk
);
1951 /* Setup UART clock */
1952 clk_setup(&cpc
->clk_setup
[PPC405CR_UART_CLK
], UART_clk
);
1955 static uint32_t dcr_read_crcpc (void *opaque
, int dcrn
)
1957 ppc405cr_cpc_t
*cpc
;
1962 case PPC405CR_CPC0_PLLMR
:
1965 case PPC405CR_CPC0_CR0
:
1968 case PPC405CR_CPC0_CR1
:
1971 case PPC405CR_CPC0_PSR
:
1974 case PPC405CR_CPC0_JTAGID
:
1977 case PPC405CR_CPC0_ER
:
1980 case PPC405CR_CPC0_FR
:
1983 case PPC405CR_CPC0_SR
:
1984 ret
= ~(cpc
->er
| cpc
->fr
) & 0xFFFF0000;
1987 /* Avoid gcc warning */
1995 static void dcr_write_crcpc (void *opaque
, int dcrn
, uint32_t val
)
1997 ppc405cr_cpc_t
*cpc
;
2001 case PPC405CR_CPC0_PLLMR
:
2002 cpc
->pllmr
= val
& 0xFFF77C3F;
2004 case PPC405CR_CPC0_CR0
:
2005 cpc
->cr0
= val
& 0x0FFFFFFE;
2007 case PPC405CR_CPC0_CR1
:
2008 cpc
->cr1
= val
& 0x00800000;
2010 case PPC405CR_CPC0_PSR
:
2013 case PPC405CR_CPC0_JTAGID
:
2016 case PPC405CR_CPC0_ER
:
2017 cpc
->er
= val
& 0xBFFC0000;
2019 case PPC405CR_CPC0_FR
:
2020 cpc
->fr
= val
& 0xBFFC0000;
2022 case PPC405CR_CPC0_SR
:
2028 static void ppc405cr_cpc_reset (void *opaque
)
2030 ppc405cr_cpc_t
*cpc
;
2034 /* Compute PLLMR value from PSR settings */
2035 cpc
->pllmr
= 0x80000000;
2037 switch ((cpc
->psr
>> 30) & 3) {
2040 cpc
->pllmr
&= ~0x80000000;
2044 cpc
->pllmr
|= 5 << 16;
2048 cpc
->pllmr
|= 4 << 16;
2052 cpc
->pllmr
|= 2 << 16;
2056 D
= (cpc
->psr
>> 28) & 3;
2057 cpc
->pllmr
|= (D
+ 1) << 20;
2059 D
= (cpc
->psr
>> 25) & 7;
2074 D
= (cpc
->psr
>> 23) & 3;
2075 cpc
->pllmr
|= D
<< 26;
2077 D
= (cpc
->psr
>> 21) & 3;
2078 cpc
->pllmr
|= D
<< 10;
2080 D
= (cpc
->psr
>> 17) & 3;
2081 cpc
->pllmr
|= D
<< 24;
2082 cpc
->cr0
= 0x0000003C;
2083 cpc
->cr1
= 0x2B0D8800;
2084 cpc
->er
= 0x00000000;
2085 cpc
->fr
= 0x00000000;
2086 ppc405cr_clk_setup(cpc
);
2089 static void ppc405cr_clk_init (ppc405cr_cpc_t
*cpc
)
2093 /* XXX: this should be read from IO pins */
2094 cpc
->psr
= 0x00000000; /* 8 bits ROM */
2096 D
= 0x2; /* Divide by 4 */
2097 cpc
->psr
|= D
<< 30;
2099 D
= 0x1; /* Divide by 2 */
2100 cpc
->psr
|= D
<< 28;
2102 D
= 0x1; /* Divide by 2 */
2103 cpc
->psr
|= D
<< 23;
2105 D
= 0x5; /* M = 16 */
2106 cpc
->psr
|= D
<< 25;
2108 D
= 0x1; /* Divide by 2 */
2109 cpc
->psr
|= D
<< 21;
2111 D
= 0x2; /* Divide by 4 */
2112 cpc
->psr
|= D
<< 17;
2115 static void ppc405cr_cpc_init (CPUState
*env
, clk_setup_t clk_setup
[7],
2118 ppc405cr_cpc_t
*cpc
;
2120 cpc
= qemu_mallocz(sizeof(ppc405cr_cpc_t
));
2121 memcpy(cpc
->clk_setup
, clk_setup
,
2122 PPC405CR_CLK_NB
* sizeof(clk_setup_t
));
2123 cpc
->sysclk
= sysclk
;
2124 cpc
->jtagid
= 0x42051049;
2125 ppc_dcr_register(env
, PPC405CR_CPC0_PSR
, cpc
,
2126 &dcr_read_crcpc
, &dcr_write_crcpc
);
2127 ppc_dcr_register(env
, PPC405CR_CPC0_CR0
, cpc
,
2128 &dcr_read_crcpc
, &dcr_write_crcpc
);
2129 ppc_dcr_register(env
, PPC405CR_CPC0_CR1
, cpc
,
2130 &dcr_read_crcpc
, &dcr_write_crcpc
);
2131 ppc_dcr_register(env
, PPC405CR_CPC0_JTAGID
, cpc
,
2132 &dcr_read_crcpc
, &dcr_write_crcpc
);
2133 ppc_dcr_register(env
, PPC405CR_CPC0_PLLMR
, cpc
,
2134 &dcr_read_crcpc
, &dcr_write_crcpc
);
2135 ppc_dcr_register(env
, PPC405CR_CPC0_ER
, cpc
,
2136 &dcr_read_crcpc
, &dcr_write_crcpc
);
2137 ppc_dcr_register(env
, PPC405CR_CPC0_FR
, cpc
,
2138 &dcr_read_crcpc
, &dcr_write_crcpc
);
2139 ppc_dcr_register(env
, PPC405CR_CPC0_SR
, cpc
,
2140 &dcr_read_crcpc
, &dcr_write_crcpc
);
2141 ppc405cr_clk_init(cpc
);
2142 qemu_register_reset(ppc405cr_cpc_reset
, cpc
);
2145 CPUState
*ppc405cr_init (target_phys_addr_t ram_bases
[4],
2146 target_phys_addr_t ram_sizes
[4],
2147 uint32_t sysclk
, qemu_irq
**picp
,
2150 clk_setup_t clk_setup
[PPC405CR_CLK_NB
];
2151 qemu_irq dma_irqs
[4];
2153 qemu_irq
*pic
, *irqs
;
2155 memset(clk_setup
, 0, sizeof(clk_setup
));
2156 env
= ppc4xx_init("405cr", &clk_setup
[PPC405CR_CPU_CLK
],
2157 &clk_setup
[PPC405CR_TMR_CLK
], sysclk
);
2158 /* Memory mapped devices registers */
2160 ppc4xx_plb_init(env
);
2161 /* PLB to OPB bridge */
2162 ppc4xx_pob_init(env
);
2164 ppc4xx_opba_init(0xef600600);
2165 /* Universal interrupt controller */
2166 irqs
= qemu_mallocz(sizeof(qemu_irq
) * PPCUIC_OUTPUT_NB
);
2167 irqs
[PPCUIC_OUTPUT_INT
] =
2168 ((qemu_irq
*)env
->irq_inputs
)[PPC40x_INPUT_INT
];
2169 irqs
[PPCUIC_OUTPUT_CINT
] =
2170 ((qemu_irq
*)env
->irq_inputs
)[PPC40x_INPUT_CINT
];
2171 pic
= ppcuic_init(env
, irqs
, 0x0C0, 0, 1);
2173 /* SDRAM controller */
2174 ppc4xx_sdram_init(env
, pic
[14], 1, ram_bases
, ram_sizes
, do_init
);
2175 /* External bus controller */
2176 ppc405_ebc_init(env
);
2177 /* DMA controller */
2178 dma_irqs
[0] = pic
[26];
2179 dma_irqs
[1] = pic
[25];
2180 dma_irqs
[2] = pic
[24];
2181 dma_irqs
[3] = pic
[23];
2182 ppc405_dma_init(env
, dma_irqs
);
2184 if (serial_hds
[0] != NULL
) {
2185 serial_mm_init(0xef600300, 0, pic
[0], PPC_SERIAL_MM_BAUDBASE
,
2186 serial_hds
[0], 1, 1);
2188 if (serial_hds
[1] != NULL
) {
2189 serial_mm_init(0xef600400, 0, pic
[1], PPC_SERIAL_MM_BAUDBASE
,
2190 serial_hds
[1], 1, 1);
2192 /* IIC controller */
2193 ppc405_i2c_init(0xef600500, pic
[2]);
2195 ppc405_gpio_init(0xef600700);
2197 ppc405cr_cpc_init(env
, clk_setup
, sysclk
);
2202 /*****************************************************************************/
2206 PPC405EP_CPC0_PLLMR0
= 0x0F0,
2207 PPC405EP_CPC0_BOOT
= 0x0F1,
2208 PPC405EP_CPC0_EPCTL
= 0x0F3,
2209 PPC405EP_CPC0_PLLMR1
= 0x0F4,
2210 PPC405EP_CPC0_UCR
= 0x0F5,
2211 PPC405EP_CPC0_SRR
= 0x0F6,
2212 PPC405EP_CPC0_JTAGID
= 0x0F7,
2213 PPC405EP_CPC0_PCI
= 0x0F9,
2215 PPC405EP_CPC0_ER
= xxx
,
2216 PPC405EP_CPC0_FR
= xxx
,
2217 PPC405EP_CPC0_SR
= xxx
,
2222 PPC405EP_CPU_CLK
= 0,
2223 PPC405EP_PLB_CLK
= 1,
2224 PPC405EP_OPB_CLK
= 2,
2225 PPC405EP_EBC_CLK
= 3,
2226 PPC405EP_MAL_CLK
= 4,
2227 PPC405EP_PCI_CLK
= 5,
2228 PPC405EP_UART0_CLK
= 6,
2229 PPC405EP_UART1_CLK
= 7,
2230 PPC405EP_CLK_NB
= 8,
2233 typedef struct ppc405ep_cpc_t ppc405ep_cpc_t
;
2234 struct ppc405ep_cpc_t
{
2236 clk_setup_t clk_setup
[PPC405EP_CLK_NB
];
2244 /* Clock and power management */
2250 static void ppc405ep_compute_clocks (ppc405ep_cpc_t
*cpc
)
2252 uint32_t CPU_clk
, PLB_clk
, OPB_clk
, EBC_clk
, MAL_clk
, PCI_clk
;
2253 uint32_t UART0_clk
, UART1_clk
;
2254 uint64_t VCO_out
, PLL_out
;
2258 if ((cpc
->pllmr
[1] & 0x80000000) && !(cpc
->pllmr
[1] & 0x40000000)) {
2259 M
= (((cpc
->pllmr
[1] >> 20) - 1) & 0xF) + 1; /* FBMUL */
2260 #ifdef DEBUG_CLOCKS_LL
2261 printf("FBMUL %01" PRIx32
" %d\n", (cpc
->pllmr
[1] >> 20) & 0xF, M
);
2263 D
= 8 - ((cpc
->pllmr
[1] >> 16) & 0x7); /* FWDA */
2264 #ifdef DEBUG_CLOCKS_LL
2265 printf("FWDA %01" PRIx32
" %d\n", (cpc
->pllmr
[1] >> 16) & 0x7, D
);
2267 VCO_out
= cpc
->sysclk
* M
* D
;
2268 if (VCO_out
< 500000000UL || VCO_out
> 1000000000UL) {
2269 /* Error - unlock the PLL */
2270 printf("VCO out of range %" PRIu64
"\n", VCO_out
);
2272 cpc
->pllmr
[1] &= ~0x80000000;
2276 PLL_out
= VCO_out
/ D
;
2277 /* Pretend the PLL is locked */
2278 cpc
->boot
|= 0x00000001;
2283 PLL_out
= cpc
->sysclk
;
2284 if (cpc
->pllmr
[1] & 0x40000000) {
2285 /* Pretend the PLL is not locked */
2286 cpc
->boot
&= ~0x00000001;
2289 /* Now, compute all other clocks */
2290 D
= ((cpc
->pllmr
[0] >> 20) & 0x3) + 1; /* CCDV */
2291 #ifdef DEBUG_CLOCKS_LL
2292 printf("CCDV %01" PRIx32
" %d\n", (cpc
->pllmr
[0] >> 20) & 0x3, D
);
2294 CPU_clk
= PLL_out
/ D
;
2295 D
= ((cpc
->pllmr
[0] >> 16) & 0x3) + 1; /* CBDV */
2296 #ifdef DEBUG_CLOCKS_LL
2297 printf("CBDV %01" PRIx32
" %d\n", (cpc
->pllmr
[0] >> 16) & 0x3, D
);
2299 PLB_clk
= CPU_clk
/ D
;
2300 D
= ((cpc
->pllmr
[0] >> 12) & 0x3) + 1; /* OPDV */
2301 #ifdef DEBUG_CLOCKS_LL
2302 printf("OPDV %01" PRIx32
" %d\n", (cpc
->pllmr
[0] >> 12) & 0x3, D
);
2304 OPB_clk
= PLB_clk
/ D
;
2305 D
= ((cpc
->pllmr
[0] >> 8) & 0x3) + 2; /* EPDV */
2306 #ifdef DEBUG_CLOCKS_LL
2307 printf("EPDV %01" PRIx32
" %d\n", (cpc
->pllmr
[0] >> 8) & 0x3, D
);
2309 EBC_clk
= PLB_clk
/ D
;
2310 D
= ((cpc
->pllmr
[0] >> 4) & 0x3) + 1; /* MPDV */
2311 #ifdef DEBUG_CLOCKS_LL
2312 printf("MPDV %01" PRIx32
" %d\n", (cpc
->pllmr
[0] >> 4) & 0x3, D
);
2314 MAL_clk
= PLB_clk
/ D
;
2315 D
= (cpc
->pllmr
[0] & 0x3) + 1; /* PPDV */
2316 #ifdef DEBUG_CLOCKS_LL
2317 printf("PPDV %01" PRIx32
" %d\n", cpc
->pllmr
[0] & 0x3, D
);
2319 PCI_clk
= PLB_clk
/ D
;
2320 D
= ((cpc
->ucr
- 1) & 0x7F) + 1; /* U0DIV */
2321 #ifdef DEBUG_CLOCKS_LL
2322 printf("U0DIV %01" PRIx32
" %d\n", cpc
->ucr
& 0x7F, D
);
2324 UART0_clk
= PLL_out
/ D
;
2325 D
= (((cpc
->ucr
>> 8) - 1) & 0x7F) + 1; /* U1DIV */
2326 #ifdef DEBUG_CLOCKS_LL
2327 printf("U1DIV %01" PRIx32
" %d\n", (cpc
->ucr
>> 8) & 0x7F, D
);
2329 UART1_clk
= PLL_out
/ D
;
2331 printf("Setup PPC405EP clocks - sysclk %" PRIu32
" VCO %" PRIu64
2332 " PLL out %" PRIu64
" Hz\n", cpc
->sysclk
, VCO_out
, PLL_out
);
2333 printf("CPU %" PRIu32
" PLB %" PRIu32
" OPB %" PRIu32
" EBC %" PRIu32
2334 " MAL %" PRIu32
" PCI %" PRIu32
" UART0 %" PRIu32
2335 " UART1 %" PRIu32
"\n",
2336 CPU_clk
, PLB_clk
, OPB_clk
, EBC_clk
, MAL_clk
, PCI_clk
,
2337 UART0_clk
, UART1_clk
);
2339 /* Setup CPU clocks */
2340 clk_setup(&cpc
->clk_setup
[PPC405EP_CPU_CLK
], CPU_clk
);
2341 /* Setup PLB clock */
2342 clk_setup(&cpc
->clk_setup
[PPC405EP_PLB_CLK
], PLB_clk
);
2343 /* Setup OPB clock */
2344 clk_setup(&cpc
->clk_setup
[PPC405EP_OPB_CLK
], OPB_clk
);
2345 /* Setup external clock */
2346 clk_setup(&cpc
->clk_setup
[PPC405EP_EBC_CLK
], EBC_clk
);
2347 /* Setup MAL clock */
2348 clk_setup(&cpc
->clk_setup
[PPC405EP_MAL_CLK
], MAL_clk
);
2349 /* Setup PCI clock */
2350 clk_setup(&cpc
->clk_setup
[PPC405EP_PCI_CLK
], PCI_clk
);
2351 /* Setup UART0 clock */
2352 clk_setup(&cpc
->clk_setup
[PPC405EP_UART0_CLK
], UART0_clk
);
2353 /* Setup UART1 clock */
2354 clk_setup(&cpc
->clk_setup
[PPC405EP_UART1_CLK
], UART1_clk
);
2357 static uint32_t dcr_read_epcpc (void *opaque
, int dcrn
)
2359 ppc405ep_cpc_t
*cpc
;
2364 case PPC405EP_CPC0_BOOT
:
2367 case PPC405EP_CPC0_EPCTL
:
2370 case PPC405EP_CPC0_PLLMR0
:
2371 ret
= cpc
->pllmr
[0];
2373 case PPC405EP_CPC0_PLLMR1
:
2374 ret
= cpc
->pllmr
[1];
2376 case PPC405EP_CPC0_UCR
:
2379 case PPC405EP_CPC0_SRR
:
2382 case PPC405EP_CPC0_JTAGID
:
2385 case PPC405EP_CPC0_PCI
:
2389 /* Avoid gcc warning */
2397 static void dcr_write_epcpc (void *opaque
, int dcrn
, uint32_t val
)
2399 ppc405ep_cpc_t
*cpc
;
2403 case PPC405EP_CPC0_BOOT
:
2404 /* Read-only register */
2406 case PPC405EP_CPC0_EPCTL
:
2407 /* Don't care for now */
2408 cpc
->epctl
= val
& 0xC00000F3;
2410 case PPC405EP_CPC0_PLLMR0
:
2411 cpc
->pllmr
[0] = val
& 0x00633333;
2412 ppc405ep_compute_clocks(cpc
);
2414 case PPC405EP_CPC0_PLLMR1
:
2415 cpc
->pllmr
[1] = val
& 0xC0F73FFF;
2416 ppc405ep_compute_clocks(cpc
);
2418 case PPC405EP_CPC0_UCR
:
2419 /* UART control - don't care for now */
2420 cpc
->ucr
= val
& 0x003F7F7F;
2422 case PPC405EP_CPC0_SRR
:
2425 case PPC405EP_CPC0_JTAGID
:
2428 case PPC405EP_CPC0_PCI
:
2434 static void ppc405ep_cpc_reset (void *opaque
)
2436 ppc405ep_cpc_t
*cpc
= opaque
;
2438 cpc
->boot
= 0x00000010; /* Boot from PCI - IIC EEPROM disabled */
2439 cpc
->epctl
= 0x00000000;
2440 cpc
->pllmr
[0] = 0x00011010;
2441 cpc
->pllmr
[1] = 0x40000000;
2442 cpc
->ucr
= 0x00000000;
2443 cpc
->srr
= 0x00040000;
2444 cpc
->pci
= 0x00000000;
2445 cpc
->er
= 0x00000000;
2446 cpc
->fr
= 0x00000000;
2447 cpc
->sr
= 0x00000000;
2448 ppc405ep_compute_clocks(cpc
);
2451 /* XXX: sysclk should be between 25 and 100 MHz */
2452 static void ppc405ep_cpc_init (CPUState
*env
, clk_setup_t clk_setup
[8],
2455 ppc405ep_cpc_t
*cpc
;
2457 cpc
= qemu_mallocz(sizeof(ppc405ep_cpc_t
));
2458 memcpy(cpc
->clk_setup
, clk_setup
,
2459 PPC405EP_CLK_NB
* sizeof(clk_setup_t
));
2460 cpc
->jtagid
= 0x20267049;
2461 cpc
->sysclk
= sysclk
;
2462 qemu_register_reset(&ppc405ep_cpc_reset
, cpc
);
2463 ppc_dcr_register(env
, PPC405EP_CPC0_BOOT
, cpc
,
2464 &dcr_read_epcpc
, &dcr_write_epcpc
);
2465 ppc_dcr_register(env
, PPC405EP_CPC0_EPCTL
, cpc
,
2466 &dcr_read_epcpc
, &dcr_write_epcpc
);
2467 ppc_dcr_register(env
, PPC405EP_CPC0_PLLMR0
, cpc
,
2468 &dcr_read_epcpc
, &dcr_write_epcpc
);
2469 ppc_dcr_register(env
, PPC405EP_CPC0_PLLMR1
, cpc
,
2470 &dcr_read_epcpc
, &dcr_write_epcpc
);
2471 ppc_dcr_register(env
, PPC405EP_CPC0_UCR
, cpc
,
2472 &dcr_read_epcpc
, &dcr_write_epcpc
);
2473 ppc_dcr_register(env
, PPC405EP_CPC0_SRR
, cpc
,
2474 &dcr_read_epcpc
, &dcr_write_epcpc
);
2475 ppc_dcr_register(env
, PPC405EP_CPC0_JTAGID
, cpc
,
2476 &dcr_read_epcpc
, &dcr_write_epcpc
);
2477 ppc_dcr_register(env
, PPC405EP_CPC0_PCI
, cpc
,
2478 &dcr_read_epcpc
, &dcr_write_epcpc
);
2480 ppc_dcr_register(env
, PPC405EP_CPC0_ER
, cpc
,
2481 &dcr_read_epcpc
, &dcr_write_epcpc
);
2482 ppc_dcr_register(env
, PPC405EP_CPC0_FR
, cpc
,
2483 &dcr_read_epcpc
, &dcr_write_epcpc
);
2484 ppc_dcr_register(env
, PPC405EP_CPC0_SR
, cpc
,
2485 &dcr_read_epcpc
, &dcr_write_epcpc
);
2489 CPUState
*ppc405ep_init (target_phys_addr_t ram_bases
[2],
2490 target_phys_addr_t ram_sizes
[2],
2491 uint32_t sysclk
, qemu_irq
**picp
,
2494 clk_setup_t clk_setup
[PPC405EP_CLK_NB
], tlb_clk_setup
;
2495 qemu_irq dma_irqs
[4], gpt_irqs
[5], mal_irqs
[4];
2497 qemu_irq
*pic
, *irqs
;
2499 memset(clk_setup
, 0, sizeof(clk_setup
));
2501 env
= ppc4xx_init("405ep", &clk_setup
[PPC405EP_CPU_CLK
],
2502 &tlb_clk_setup
, sysclk
);
2503 clk_setup
[PPC405EP_CPU_CLK
].cb
= tlb_clk_setup
.cb
;
2504 clk_setup
[PPC405EP_CPU_CLK
].opaque
= tlb_clk_setup
.opaque
;
2505 /* Internal devices init */
2506 /* Memory mapped devices registers */
2508 ppc4xx_plb_init(env
);
2509 /* PLB to OPB bridge */
2510 ppc4xx_pob_init(env
);
2512 ppc4xx_opba_init(0xef600600);
2513 /* Universal interrupt controller */
2514 irqs
= qemu_mallocz(sizeof(qemu_irq
) * PPCUIC_OUTPUT_NB
);
2515 irqs
[PPCUIC_OUTPUT_INT
] =
2516 ((qemu_irq
*)env
->irq_inputs
)[PPC40x_INPUT_INT
];
2517 irqs
[PPCUIC_OUTPUT_CINT
] =
2518 ((qemu_irq
*)env
->irq_inputs
)[PPC40x_INPUT_CINT
];
2519 pic
= ppcuic_init(env
, irqs
, 0x0C0, 0, 1);
2521 /* SDRAM controller */
2522 /* XXX 405EP has no ECC interrupt */
2523 ppc4xx_sdram_init(env
, pic
[17], 2, ram_bases
, ram_sizes
, do_init
);
2524 /* External bus controller */
2525 ppc405_ebc_init(env
);
2526 /* DMA controller */
2527 dma_irqs
[0] = pic
[5];
2528 dma_irqs
[1] = pic
[6];
2529 dma_irqs
[2] = pic
[7];
2530 dma_irqs
[3] = pic
[8];
2531 ppc405_dma_init(env
, dma_irqs
);
2532 /* IIC controller */
2533 ppc405_i2c_init(0xef600500, pic
[2]);
2535 ppc405_gpio_init(0xef600700);
2537 if (serial_hds
[0] != NULL
) {
2538 serial_mm_init(0xef600300, 0, pic
[0], PPC_SERIAL_MM_BAUDBASE
,
2539 serial_hds
[0], 1, 1);
2541 if (serial_hds
[1] != NULL
) {
2542 serial_mm_init(0xef600400, 0, pic
[1], PPC_SERIAL_MM_BAUDBASE
,
2543 serial_hds
[1], 1, 1);
2546 ppc405_ocm_init(env
);
2548 gpt_irqs
[0] = pic
[19];
2549 gpt_irqs
[1] = pic
[20];
2550 gpt_irqs
[2] = pic
[21];
2551 gpt_irqs
[3] = pic
[22];
2552 gpt_irqs
[4] = pic
[23];
2553 ppc4xx_gpt_init(0xef600000, gpt_irqs
);
2555 /* Uses pic[3], pic[16], pic[18] */
2557 mal_irqs
[0] = pic
[11];
2558 mal_irqs
[1] = pic
[12];
2559 mal_irqs
[2] = pic
[13];
2560 mal_irqs
[3] = pic
[14];
2561 ppc405_mal_init(env
, mal_irqs
);
2563 /* Uses pic[9], pic[15], pic[17] */
2565 ppc405ep_cpc_init(env
, clk_setup
, sysclk
);