2 * QEMU PowerPC 405 embedded processors emulation
4 * Copyright (c) 2007 Jocelyn Mayer
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28 #include "qemu-timer.h"
41 //#define DEBUG_CLOCKS_LL
43 ram_addr_t
ppc405_set_bootinfo (CPUState
*env
, ppc4xx_bd_info_t
*bd
,
49 /* We put the bd structure at the top of memory */
50 if (bd
->bi_memsize
>= 0x01000000UL
)
51 bdloc
= 0x01000000UL
- sizeof(struct ppc4xx_bd_info_t
);
53 bdloc
= bd
->bi_memsize
- sizeof(struct ppc4xx_bd_info_t
);
54 stl_phys(bdloc
+ 0x00, bd
->bi_memstart
);
55 stl_phys(bdloc
+ 0x04, bd
->bi_memsize
);
56 stl_phys(bdloc
+ 0x08, bd
->bi_flashstart
);
57 stl_phys(bdloc
+ 0x0C, bd
->bi_flashsize
);
58 stl_phys(bdloc
+ 0x10, bd
->bi_flashoffset
);
59 stl_phys(bdloc
+ 0x14, bd
->bi_sramstart
);
60 stl_phys(bdloc
+ 0x18, bd
->bi_sramsize
);
61 stl_phys(bdloc
+ 0x1C, bd
->bi_bootflags
);
62 stl_phys(bdloc
+ 0x20, bd
->bi_ipaddr
);
63 for (i
= 0; i
< 6; i
++)
64 stb_phys(bdloc
+ 0x24 + i
, bd
->bi_enetaddr
[i
]);
65 stw_phys(bdloc
+ 0x2A, bd
->bi_ethspeed
);
66 stl_phys(bdloc
+ 0x2C, bd
->bi_intfreq
);
67 stl_phys(bdloc
+ 0x30, bd
->bi_busfreq
);
68 stl_phys(bdloc
+ 0x34, bd
->bi_baudrate
);
69 for (i
= 0; i
< 4; i
++)
70 stb_phys(bdloc
+ 0x38 + i
, bd
->bi_s_version
[i
]);
71 for (i
= 0; i
< 32; i
++)
72 stb_phys(bdloc
+ 0x3C + i
, bd
->bi_s_version
[i
]);
73 stl_phys(bdloc
+ 0x5C, bd
->bi_plb_busfreq
);
74 stl_phys(bdloc
+ 0x60, bd
->bi_pci_busfreq
);
75 for (i
= 0; i
< 6; i
++)
76 stb_phys(bdloc
+ 0x64 + i
, bd
->bi_pci_enetaddr
[i
]);
78 if (flags
& 0x00000001) {
79 for (i
= 0; i
< 6; i
++)
80 stb_phys(bdloc
+ n
++, bd
->bi_pci_enetaddr2
[i
]);
82 stl_phys(bdloc
+ n
, bd
->bi_opbfreq
);
84 for (i
= 0; i
< 2; i
++) {
85 stl_phys(bdloc
+ n
, bd
->bi_iic_fast
[i
]);
92 /*****************************************************************************/
93 /* Shared peripherals */
95 /*****************************************************************************/
96 /* Peripheral local bus arbitrer */
103 typedef struct ppc4xx_plb_t ppc4xx_plb_t
;
104 struct ppc4xx_plb_t
{
110 static target_ulong
dcr_read_plb (void *opaque
, int dcrn
)
127 /* Avoid gcc warning */
135 static void dcr_write_plb (void *opaque
, int dcrn
, target_ulong val
)
142 /* We don't care about the actual parameters written as
143 * we don't manage any priorities on the bus
145 plb
->acr
= val
& 0xF8000000;
157 static void ppc4xx_plb_reset (void *opaque
)
162 plb
->acr
= 0x00000000;
163 plb
->bear
= 0x00000000;
164 plb
->besr
= 0x00000000;
167 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 ppc4xx_plb_reset(plb
);
176 qemu_register_reset(ppc4xx_plb_reset
, plb
);
179 /*****************************************************************************/
180 /* PLB to OPB bridge */
187 typedef struct ppc4xx_pob_t ppc4xx_pob_t
;
188 struct ppc4xx_pob_t
{
193 static target_ulong
dcr_read_pob (void *opaque
, int dcrn
)
205 ret
= pob
->besr
[dcrn
- POB0_BESR0
];
208 /* Avoid gcc warning */
216 static void dcr_write_pob (void *opaque
, int dcrn
, target_ulong val
)
228 pob
->besr
[dcrn
- POB0_BESR0
] &= ~val
;
233 static void ppc4xx_pob_reset (void *opaque
)
239 pob
->bear
= 0x00000000;
240 pob
->besr
[0] = 0x0000000;
241 pob
->besr
[1] = 0x0000000;
244 static void ppc4xx_pob_init(CPUState
*env
)
248 pob
= qemu_mallocz(sizeof(ppc4xx_pob_t
));
249 ppc_dcr_register(env
, POB0_BEAR
, pob
, &dcr_read_pob
, &dcr_write_pob
);
250 ppc_dcr_register(env
, POB0_BESR0
, pob
, &dcr_read_pob
, &dcr_write_pob
);
251 ppc_dcr_register(env
, POB0_BESR1
, pob
, &dcr_read_pob
, &dcr_write_pob
);
252 qemu_register_reset(ppc4xx_pob_reset
, pob
);
253 ppc4xx_pob_reset(pob
);
256 /*****************************************************************************/
258 typedef struct ppc4xx_opba_t ppc4xx_opba_t
;
259 struct ppc4xx_opba_t
{
264 static uint32_t opba_readb (void *opaque
, target_phys_addr_t addr
)
270 printf("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
288 static void opba_writeb (void *opaque
,
289 target_phys_addr_t addr
, uint32_t value
)
294 printf("%s: addr " TARGET_FMT_plx
" val %08" PRIx32
"\n", __func__
, addr
,
300 opba
->cr
= value
& 0xF8;
303 opba
->pr
= value
& 0xFF;
310 static uint32_t opba_readw (void *opaque
, target_phys_addr_t addr
)
315 printf("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
317 ret
= opba_readb(opaque
, addr
) << 8;
318 ret
|= opba_readb(opaque
, addr
+ 1);
323 static void opba_writew (void *opaque
,
324 target_phys_addr_t addr
, uint32_t value
)
327 printf("%s: addr " TARGET_FMT_plx
" val %08" PRIx32
"\n", __func__
, addr
,
330 opba_writeb(opaque
, addr
, value
>> 8);
331 opba_writeb(opaque
, addr
+ 1, value
);
334 static uint32_t opba_readl (void *opaque
, target_phys_addr_t addr
)
339 printf("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
341 ret
= opba_readb(opaque
, addr
) << 24;
342 ret
|= opba_readb(opaque
, addr
+ 1) << 16;
347 static void opba_writel (void *opaque
,
348 target_phys_addr_t addr
, uint32_t value
)
351 printf("%s: addr " TARGET_FMT_plx
" val %08" PRIx32
"\n", __func__
, addr
,
354 opba_writeb(opaque
, addr
, value
>> 24);
355 opba_writeb(opaque
, addr
+ 1, value
>> 16);
358 static CPUReadMemoryFunc
* const opba_read
[] = {
364 static CPUWriteMemoryFunc
* const opba_write
[] = {
370 static void ppc4xx_opba_reset (void *opaque
)
375 opba
->cr
= 0x00; /* No dynamic priorities - park disabled */
379 static void ppc4xx_opba_init(target_phys_addr_t base
)
384 opba
= qemu_mallocz(sizeof(ppc4xx_opba_t
));
386 printf("%s: offset " TARGET_FMT_plx
"\n", __func__
, base
);
388 io
= cpu_register_io_memory(opba_read
, opba_write
, opba
);
389 cpu_register_physical_memory(base
, 0x002, io
);
390 ppc4xx_opba_reset(opba
);
391 qemu_register_reset(ppc4xx_opba_reset
, opba
);
394 /*****************************************************************************/
395 /* Code decompression controller */
398 /*****************************************************************************/
399 /* Peripheral controller */
400 typedef struct ppc4xx_ebc_t ppc4xx_ebc_t
;
401 struct ppc4xx_ebc_t
{
412 EBC0_CFGADDR
= 0x012,
413 EBC0_CFGDATA
= 0x013,
416 static target_ulong
dcr_read_ebc (void *opaque
, int dcrn
)
428 case 0x00: /* B0CR */
431 case 0x01: /* B1CR */
434 case 0x02: /* B2CR */
437 case 0x03: /* B3CR */
440 case 0x04: /* B4CR */
443 case 0x05: /* B5CR */
446 case 0x06: /* B6CR */
449 case 0x07: /* B7CR */
452 case 0x10: /* B0AP */
455 case 0x11: /* B1AP */
458 case 0x12: /* B2AP */
461 case 0x13: /* B3AP */
464 case 0x14: /* B4AP */
467 case 0x15: /* B5AP */
470 case 0x16: /* B6AP */
473 case 0x17: /* B7AP */
476 case 0x20: /* BEAR */
479 case 0x21: /* BESR0 */
482 case 0x22: /* BESR1 */
500 static void dcr_write_ebc (void *opaque
, int dcrn
, target_ulong val
)
511 case 0x00: /* B0CR */
513 case 0x01: /* B1CR */
515 case 0x02: /* B2CR */
517 case 0x03: /* B3CR */
519 case 0x04: /* B4CR */
521 case 0x05: /* B5CR */
523 case 0x06: /* B6CR */
525 case 0x07: /* B7CR */
527 case 0x10: /* B0AP */
529 case 0x11: /* B1AP */
531 case 0x12: /* B2AP */
533 case 0x13: /* B3AP */
535 case 0x14: /* B4AP */
537 case 0x15: /* B5AP */
539 case 0x16: /* B6AP */
541 case 0x17: /* B7AP */
543 case 0x20: /* BEAR */
545 case 0x21: /* BESR0 */
547 case 0x22: /* BESR1 */
560 static void ebc_reset (void *opaque
)
566 ebc
->addr
= 0x00000000;
567 ebc
->bap
[0] = 0x7F8FFE80;
568 ebc
->bcr
[0] = 0xFFE28000;
569 for (i
= 0; i
< 8; i
++) {
570 ebc
->bap
[i
] = 0x00000000;
571 ebc
->bcr
[i
] = 0x00000000;
573 ebc
->besr0
= 0x00000000;
574 ebc
->besr1
= 0x00000000;
575 ebc
->cfg
= 0x80400000;
578 static void ppc405_ebc_init(CPUState
*env
)
582 ebc
= qemu_mallocz(sizeof(ppc4xx_ebc_t
));
584 qemu_register_reset(&ebc_reset
, ebc
);
585 ppc_dcr_register(env
, EBC0_CFGADDR
,
586 ebc
, &dcr_read_ebc
, &dcr_write_ebc
);
587 ppc_dcr_register(env
, EBC0_CFGDATA
,
588 ebc
, &dcr_read_ebc
, &dcr_write_ebc
);
591 /*****************************************************************************/
620 typedef struct ppc405_dma_t ppc405_dma_t
;
621 struct ppc405_dma_t
{
634 static target_ulong
dcr_read_dma (void *opaque
, int dcrn
)
643 static void dcr_write_dma (void *opaque
, int dcrn
, target_ulong val
)
650 static void ppc405_dma_reset (void *opaque
)
656 for (i
= 0; i
< 4; i
++) {
657 dma
->cr
[i
] = 0x00000000;
658 dma
->ct
[i
] = 0x00000000;
659 dma
->da
[i
] = 0x00000000;
660 dma
->sa
[i
] = 0x00000000;
661 dma
->sg
[i
] = 0x00000000;
663 dma
->sr
= 0x00000000;
664 dma
->sgc
= 0x00000000;
665 dma
->slp
= 0x7C000000;
666 dma
->pol
= 0x00000000;
669 static void ppc405_dma_init(CPUState
*env
, qemu_irq irqs
[4])
673 dma
= qemu_mallocz(sizeof(ppc405_dma_t
));
674 memcpy(dma
->irqs
, irqs
, 4 * sizeof(qemu_irq
));
675 ppc405_dma_reset(dma
);
676 qemu_register_reset(&ppc405_dma_reset
, dma
);
677 ppc_dcr_register(env
, DMA0_CR0
,
678 dma
, &dcr_read_dma
, &dcr_write_dma
);
679 ppc_dcr_register(env
, DMA0_CT0
,
680 dma
, &dcr_read_dma
, &dcr_write_dma
);
681 ppc_dcr_register(env
, DMA0_DA0
,
682 dma
, &dcr_read_dma
, &dcr_write_dma
);
683 ppc_dcr_register(env
, DMA0_SA0
,
684 dma
, &dcr_read_dma
, &dcr_write_dma
);
685 ppc_dcr_register(env
, DMA0_SG0
,
686 dma
, &dcr_read_dma
, &dcr_write_dma
);
687 ppc_dcr_register(env
, DMA0_CR1
,
688 dma
, &dcr_read_dma
, &dcr_write_dma
);
689 ppc_dcr_register(env
, DMA0_CT1
,
690 dma
, &dcr_read_dma
, &dcr_write_dma
);
691 ppc_dcr_register(env
, DMA0_DA1
,
692 dma
, &dcr_read_dma
, &dcr_write_dma
);
693 ppc_dcr_register(env
, DMA0_SA1
,
694 dma
, &dcr_read_dma
, &dcr_write_dma
);
695 ppc_dcr_register(env
, DMA0_SG1
,
696 dma
, &dcr_read_dma
, &dcr_write_dma
);
697 ppc_dcr_register(env
, DMA0_CR2
,
698 dma
, &dcr_read_dma
, &dcr_write_dma
);
699 ppc_dcr_register(env
, DMA0_CT2
,
700 dma
, &dcr_read_dma
, &dcr_write_dma
);
701 ppc_dcr_register(env
, DMA0_DA2
,
702 dma
, &dcr_read_dma
, &dcr_write_dma
);
703 ppc_dcr_register(env
, DMA0_SA2
,
704 dma
, &dcr_read_dma
, &dcr_write_dma
);
705 ppc_dcr_register(env
, DMA0_SG2
,
706 dma
, &dcr_read_dma
, &dcr_write_dma
);
707 ppc_dcr_register(env
, DMA0_CR3
,
708 dma
, &dcr_read_dma
, &dcr_write_dma
);
709 ppc_dcr_register(env
, DMA0_CT3
,
710 dma
, &dcr_read_dma
, &dcr_write_dma
);
711 ppc_dcr_register(env
, DMA0_DA3
,
712 dma
, &dcr_read_dma
, &dcr_write_dma
);
713 ppc_dcr_register(env
, DMA0_SA3
,
714 dma
, &dcr_read_dma
, &dcr_write_dma
);
715 ppc_dcr_register(env
, DMA0_SG3
,
716 dma
, &dcr_read_dma
, &dcr_write_dma
);
717 ppc_dcr_register(env
, DMA0_SR
,
718 dma
, &dcr_read_dma
, &dcr_write_dma
);
719 ppc_dcr_register(env
, DMA0_SGC
,
720 dma
, &dcr_read_dma
, &dcr_write_dma
);
721 ppc_dcr_register(env
, DMA0_SLP
,
722 dma
, &dcr_read_dma
, &dcr_write_dma
);
723 ppc_dcr_register(env
, DMA0_POL
,
724 dma
, &dcr_read_dma
, &dcr_write_dma
);
727 /*****************************************************************************/
729 typedef struct ppc405_gpio_t ppc405_gpio_t
;
730 struct ppc405_gpio_t
{
744 static uint32_t ppc405_gpio_readb (void *opaque
, target_phys_addr_t addr
)
750 printf("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
756 static void ppc405_gpio_writeb (void *opaque
,
757 target_phys_addr_t addr
, uint32_t value
)
763 printf("%s: addr " TARGET_FMT_plx
" val %08" PRIx32
"\n", __func__
, addr
,
768 static uint32_t ppc405_gpio_readw (void *opaque
, target_phys_addr_t addr
)
774 printf("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
780 static void ppc405_gpio_writew (void *opaque
,
781 target_phys_addr_t addr
, uint32_t value
)
787 printf("%s: addr " TARGET_FMT_plx
" val %08" PRIx32
"\n", __func__
, addr
,
792 static uint32_t ppc405_gpio_readl (void *opaque
, target_phys_addr_t addr
)
798 printf("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
804 static void ppc405_gpio_writel (void *opaque
,
805 target_phys_addr_t addr
, uint32_t value
)
811 printf("%s: addr " TARGET_FMT_plx
" val %08" PRIx32
"\n", __func__
, addr
,
816 static CPUReadMemoryFunc
* const ppc405_gpio_read
[] = {
822 static CPUWriteMemoryFunc
* const ppc405_gpio_write
[] = {
828 static void ppc405_gpio_reset (void *opaque
)
835 static void ppc405_gpio_init(target_phys_addr_t base
)
840 gpio
= qemu_mallocz(sizeof(ppc405_gpio_t
));
842 printf("%s: offset " TARGET_FMT_plx
"\n", __func__
, base
);
844 io
= cpu_register_io_memory(ppc405_gpio_read
, ppc405_gpio_write
, gpio
);
845 cpu_register_physical_memory(base
, 0x038, io
);
846 ppc405_gpio_reset(gpio
);
847 qemu_register_reset(&ppc405_gpio_reset
, gpio
);
850 /*****************************************************************************/
854 OCM0_ISACNTL
= 0x019,
856 OCM0_DSACNTL
= 0x01B,
859 typedef struct ppc405_ocm_t ppc405_ocm_t
;
860 struct ppc405_ocm_t
{
868 static void ocm_update_mappings (ppc405_ocm_t
*ocm
,
869 uint32_t isarc
, uint32_t isacntl
,
870 uint32_t dsarc
, uint32_t dsacntl
)
873 printf("OCM update ISA %08" PRIx32
" %08" PRIx32
" (%08" PRIx32
874 " %08" PRIx32
") DSA %08" PRIx32
" %08" PRIx32
875 " (%08" PRIx32
" %08" PRIx32
")\n",
876 isarc
, isacntl
, dsarc
, dsacntl
,
877 ocm
->isarc
, ocm
->isacntl
, ocm
->dsarc
, ocm
->dsacntl
);
879 if (ocm
->isarc
!= isarc
||
880 (ocm
->isacntl
& 0x80000000) != (isacntl
& 0x80000000)) {
881 if (ocm
->isacntl
& 0x80000000) {
882 /* Unmap previously assigned memory region */
883 printf("OCM unmap ISA %08" PRIx32
"\n", ocm
->isarc
);
884 cpu_register_physical_memory(ocm
->isarc
, 0x04000000,
887 if (isacntl
& 0x80000000) {
888 /* Map new instruction memory region */
890 printf("OCM map ISA %08" PRIx32
"\n", isarc
);
892 cpu_register_physical_memory(isarc
, 0x04000000,
893 ocm
->offset
| IO_MEM_RAM
);
896 if (ocm
->dsarc
!= dsarc
||
897 (ocm
->dsacntl
& 0x80000000) != (dsacntl
& 0x80000000)) {
898 if (ocm
->dsacntl
& 0x80000000) {
899 /* Beware not to unmap the region we just mapped */
900 if (!(isacntl
& 0x80000000) || ocm
->dsarc
!= isarc
) {
901 /* Unmap previously assigned memory region */
903 printf("OCM unmap DSA %08" PRIx32
"\n", ocm
->dsarc
);
905 cpu_register_physical_memory(ocm
->dsarc
, 0x04000000,
909 if (dsacntl
& 0x80000000) {
910 /* Beware not to remap the region we just mapped */
911 if (!(isacntl
& 0x80000000) || dsarc
!= isarc
) {
912 /* Map new data memory region */
914 printf("OCM map DSA %08" PRIx32
"\n", dsarc
);
916 cpu_register_physical_memory(dsarc
, 0x04000000,
917 ocm
->offset
| IO_MEM_RAM
);
923 static target_ulong
dcr_read_ocm (void *opaque
, int dcrn
)
950 static void dcr_write_ocm (void *opaque
, int dcrn
, target_ulong val
)
953 uint32_t isarc
, dsarc
, isacntl
, dsacntl
;
958 isacntl
= ocm
->isacntl
;
959 dsacntl
= ocm
->dsacntl
;
962 isarc
= val
& 0xFC000000;
965 isacntl
= val
& 0xC0000000;
968 isarc
= val
& 0xFC000000;
971 isacntl
= val
& 0xC0000000;
974 ocm_update_mappings(ocm
, isarc
, isacntl
, dsarc
, dsacntl
);
977 ocm
->isacntl
= isacntl
;
978 ocm
->dsacntl
= dsacntl
;
981 static void ocm_reset (void *opaque
)
984 uint32_t isarc
, dsarc
, isacntl
, dsacntl
;
988 isacntl
= 0x00000000;
990 dsacntl
= 0x00000000;
991 ocm_update_mappings(ocm
, isarc
, isacntl
, dsarc
, dsacntl
);
994 ocm
->isacntl
= isacntl
;
995 ocm
->dsacntl
= dsacntl
;
998 static void ppc405_ocm_init(CPUState
*env
)
1002 ocm
= qemu_mallocz(sizeof(ppc405_ocm_t
));
1003 ocm
->offset
= qemu_ram_alloc(4096);
1005 qemu_register_reset(&ocm_reset
, ocm
);
1006 ppc_dcr_register(env
, OCM0_ISARC
,
1007 ocm
, &dcr_read_ocm
, &dcr_write_ocm
);
1008 ppc_dcr_register(env
, OCM0_ISACNTL
,
1009 ocm
, &dcr_read_ocm
, &dcr_write_ocm
);
1010 ppc_dcr_register(env
, OCM0_DSARC
,
1011 ocm
, &dcr_read_ocm
, &dcr_write_ocm
);
1012 ppc_dcr_register(env
, OCM0_DSACNTL
,
1013 ocm
, &dcr_read_ocm
, &dcr_write_ocm
);
1016 /*****************************************************************************/
1017 /* I2C controller */
1018 typedef struct ppc4xx_i2c_t ppc4xx_i2c_t
;
1019 struct ppc4xx_i2c_t
{
1038 static uint32_t ppc4xx_i2c_readb (void *opaque
, target_phys_addr_t addr
)
1044 printf("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
1049 // i2c_readbyte(&i2c->mdata);
1089 ret
= i2c
->xtcntlss
;
1092 ret
= i2c
->directcntl
;
1099 printf("%s: addr " TARGET_FMT_plx
" %02" PRIx32
"\n", __func__
, addr
, ret
);
1105 static void ppc4xx_i2c_writeb (void *opaque
,
1106 target_phys_addr_t addr
, uint32_t value
)
1111 printf("%s: addr " TARGET_FMT_plx
" val %08" PRIx32
"\n", __func__
, addr
,
1118 // i2c_sendbyte(&i2c->mdata);
1133 i2c
->mdcntl
= value
& 0xDF;
1136 i2c
->sts
&= ~(value
& 0x0A);
1139 i2c
->extsts
&= ~(value
& 0x8F);
1148 i2c
->clkdiv
= value
;
1151 i2c
->intrmsk
= value
;
1154 i2c
->xfrcnt
= value
& 0x77;
1157 i2c
->xtcntlss
= value
;
1160 i2c
->directcntl
= value
& 0x7;
1165 static uint32_t ppc4xx_i2c_readw (void *opaque
, target_phys_addr_t addr
)
1170 printf("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
1172 ret
= ppc4xx_i2c_readb(opaque
, addr
) << 8;
1173 ret
|= ppc4xx_i2c_readb(opaque
, addr
+ 1);
1178 static void ppc4xx_i2c_writew (void *opaque
,
1179 target_phys_addr_t addr
, uint32_t value
)
1182 printf("%s: addr " TARGET_FMT_plx
" val %08" PRIx32
"\n", __func__
, addr
,
1185 ppc4xx_i2c_writeb(opaque
, addr
, value
>> 8);
1186 ppc4xx_i2c_writeb(opaque
, addr
+ 1, value
);
1189 static uint32_t ppc4xx_i2c_readl (void *opaque
, target_phys_addr_t addr
)
1194 printf("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
1196 ret
= ppc4xx_i2c_readb(opaque
, addr
) << 24;
1197 ret
|= ppc4xx_i2c_readb(opaque
, addr
+ 1) << 16;
1198 ret
|= ppc4xx_i2c_readb(opaque
, addr
+ 2) << 8;
1199 ret
|= ppc4xx_i2c_readb(opaque
, addr
+ 3);
1204 static void ppc4xx_i2c_writel (void *opaque
,
1205 target_phys_addr_t addr
, uint32_t value
)
1208 printf("%s: addr " TARGET_FMT_plx
" val %08" PRIx32
"\n", __func__
, addr
,
1211 ppc4xx_i2c_writeb(opaque
, addr
, value
>> 24);
1212 ppc4xx_i2c_writeb(opaque
, addr
+ 1, value
>> 16);
1213 ppc4xx_i2c_writeb(opaque
, addr
+ 2, value
>> 8);
1214 ppc4xx_i2c_writeb(opaque
, addr
+ 3, value
);
1217 static CPUReadMemoryFunc
* const i2c_read
[] = {
1223 static CPUWriteMemoryFunc
* const i2c_write
[] = {
1229 static void ppc4xx_i2c_reset (void *opaque
)
1242 i2c
->directcntl
= 0x0F;
1245 static void ppc405_i2c_init(target_phys_addr_t base
, qemu_irq irq
)
1250 i2c
= qemu_mallocz(sizeof(ppc4xx_i2c_t
));
1253 printf("%s: offset " TARGET_FMT_plx
"\n", __func__
, base
);
1255 io
= cpu_register_io_memory(i2c_read
, i2c_write
, i2c
);
1256 cpu_register_physical_memory(base
, 0x011, io
);
1257 ppc4xx_i2c_reset(i2c
);
1258 qemu_register_reset(ppc4xx_i2c_reset
, i2c
);
1261 /*****************************************************************************/
1262 /* General purpose timers */
1263 typedef struct ppc4xx_gpt_t ppc4xx_gpt_t
;
1264 struct ppc4xx_gpt_t
{
1267 struct QEMUTimer
*timer
;
1278 static uint32_t ppc4xx_gpt_readb (void *opaque
, target_phys_addr_t addr
)
1281 printf("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
1283 /* XXX: generate a bus fault */
1287 static void ppc4xx_gpt_writeb (void *opaque
,
1288 target_phys_addr_t addr
, uint32_t value
)
1291 printf("%s: addr " TARGET_FMT_plx
" val %08" PRIx32
"\n", __func__
, addr
,
1294 /* XXX: generate a bus fault */
1297 static uint32_t ppc4xx_gpt_readw (void *opaque
, target_phys_addr_t addr
)
1300 printf("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
1302 /* XXX: generate a bus fault */
1306 static void ppc4xx_gpt_writew (void *opaque
,
1307 target_phys_addr_t addr
, uint32_t value
)
1310 printf("%s: addr " TARGET_FMT_plx
" val %08" PRIx32
"\n", __func__
, addr
,
1313 /* XXX: generate a bus fault */
1316 static int ppc4xx_gpt_compare (ppc4xx_gpt_t
*gpt
, int n
)
1322 static void ppc4xx_gpt_set_output (ppc4xx_gpt_t
*gpt
, int n
, int level
)
1327 static void ppc4xx_gpt_set_outputs (ppc4xx_gpt_t
*gpt
)
1333 for (i
= 0; i
< 5; i
++) {
1334 if (gpt
->oe
& mask
) {
1335 /* Output is enabled */
1336 if (ppc4xx_gpt_compare(gpt
, i
)) {
1337 /* Comparison is OK */
1338 ppc4xx_gpt_set_output(gpt
, i
, gpt
->ol
& mask
);
1340 /* Comparison is KO */
1341 ppc4xx_gpt_set_output(gpt
, i
, gpt
->ol
& mask
? 0 : 1);
1348 static void ppc4xx_gpt_set_irqs (ppc4xx_gpt_t
*gpt
)
1354 for (i
= 0; i
< 5; i
++) {
1355 if (gpt
->is
& gpt
->im
& mask
)
1356 qemu_irq_raise(gpt
->irqs
[i
]);
1358 qemu_irq_lower(gpt
->irqs
[i
]);
1363 static void ppc4xx_gpt_compute_timer (ppc4xx_gpt_t
*gpt
)
1368 static uint32_t ppc4xx_gpt_readl (void *opaque
, target_phys_addr_t addr
)
1375 printf("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
1380 /* Time base counter */
1381 ret
= muldiv64(qemu_get_clock(vm_clock
) + gpt
->tb_offset
,
1382 gpt
->tb_freq
, get_ticks_per_sec());
1393 /* Interrupt mask */
1398 /* Interrupt status */
1402 /* Interrupt enable */
1407 idx
= (addr
- 0x80) >> 2;
1408 ret
= gpt
->comp
[idx
];
1412 idx
= (addr
- 0xC0) >> 2;
1413 ret
= gpt
->mask
[idx
];
1423 static void ppc4xx_gpt_writel (void *opaque
,
1424 target_phys_addr_t addr
, uint32_t value
)
1430 printf("%s: addr " TARGET_FMT_plx
" val %08" PRIx32
"\n", __func__
, addr
,
1436 /* Time base counter */
1437 gpt
->tb_offset
= muldiv64(value
, get_ticks_per_sec(), gpt
->tb_freq
)
1438 - qemu_get_clock(vm_clock
);
1439 ppc4xx_gpt_compute_timer(gpt
);
1443 gpt
->oe
= value
& 0xF8000000;
1444 ppc4xx_gpt_set_outputs(gpt
);
1448 gpt
->ol
= value
& 0xF8000000;
1449 ppc4xx_gpt_set_outputs(gpt
);
1452 /* Interrupt mask */
1453 gpt
->im
= value
& 0x0000F800;
1456 /* Interrupt status set */
1457 gpt
->is
|= value
& 0x0000F800;
1458 ppc4xx_gpt_set_irqs(gpt
);
1461 /* Interrupt status clear */
1462 gpt
->is
&= ~(value
& 0x0000F800);
1463 ppc4xx_gpt_set_irqs(gpt
);
1466 /* Interrupt enable */
1467 gpt
->ie
= value
& 0x0000F800;
1468 ppc4xx_gpt_set_irqs(gpt
);
1472 idx
= (addr
- 0x80) >> 2;
1473 gpt
->comp
[idx
] = value
& 0xF8000000;
1474 ppc4xx_gpt_compute_timer(gpt
);
1478 idx
= (addr
- 0xC0) >> 2;
1479 gpt
->mask
[idx
] = value
& 0xF8000000;
1480 ppc4xx_gpt_compute_timer(gpt
);
1485 static CPUReadMemoryFunc
* const gpt_read
[] = {
1491 static CPUWriteMemoryFunc
* const gpt_write
[] = {
1497 static void ppc4xx_gpt_cb (void *opaque
)
1502 ppc4xx_gpt_set_irqs(gpt
);
1503 ppc4xx_gpt_set_outputs(gpt
);
1504 ppc4xx_gpt_compute_timer(gpt
);
1507 static void ppc4xx_gpt_reset (void *opaque
)
1513 qemu_del_timer(gpt
->timer
);
1514 gpt
->oe
= 0x00000000;
1515 gpt
->ol
= 0x00000000;
1516 gpt
->im
= 0x00000000;
1517 gpt
->is
= 0x00000000;
1518 gpt
->ie
= 0x00000000;
1519 for (i
= 0; i
< 5; i
++) {
1520 gpt
->comp
[i
] = 0x00000000;
1521 gpt
->mask
[i
] = 0x00000000;
1525 static void ppc4xx_gpt_init(target_phys_addr_t base
, qemu_irq irqs
[5])
1531 gpt
= qemu_mallocz(sizeof(ppc4xx_gpt_t
));
1532 for (i
= 0; i
< 5; i
++) {
1533 gpt
->irqs
[i
] = irqs
[i
];
1535 gpt
->timer
= qemu_new_timer(vm_clock
, &ppc4xx_gpt_cb
, gpt
);
1537 printf("%s: offset " TARGET_FMT_plx
"\n", __func__
, base
);
1539 io
= cpu_register_io_memory(gpt_read
, gpt_write
, gpt
);
1540 cpu_register_physical_memory(base
, 0x0d4, io
);
1541 qemu_register_reset(ppc4xx_gpt_reset
, gpt
);
1542 ppc4xx_gpt_reset(gpt
);
1545 /*****************************************************************************/
1551 MAL0_TXCASR
= 0x184,
1552 MAL0_TXCARR
= 0x185,
1553 MAL0_TXEOBISR
= 0x186,
1554 MAL0_TXDEIR
= 0x187,
1555 MAL0_RXCASR
= 0x190,
1556 MAL0_RXCARR
= 0x191,
1557 MAL0_RXEOBISR
= 0x192,
1558 MAL0_RXDEIR
= 0x193,
1559 MAL0_TXCTP0R
= 0x1A0,
1560 MAL0_TXCTP1R
= 0x1A1,
1561 MAL0_TXCTP2R
= 0x1A2,
1562 MAL0_TXCTP3R
= 0x1A3,
1563 MAL0_RXCTP0R
= 0x1C0,
1564 MAL0_RXCTP1R
= 0x1C1,
1569 typedef struct ppc40x_mal_t ppc40x_mal_t
;
1570 struct ppc40x_mal_t
{
1588 static void ppc40x_mal_reset (void *opaque
);
1590 static target_ulong
dcr_read_mal (void *opaque
, int dcrn
)
1613 ret
= mal
->txeobisr
;
1625 ret
= mal
->rxeobisr
;
1631 ret
= mal
->txctpr
[0];
1634 ret
= mal
->txctpr
[1];
1637 ret
= mal
->txctpr
[2];
1640 ret
= mal
->txctpr
[3];
1643 ret
= mal
->rxctpr
[0];
1646 ret
= mal
->rxctpr
[1];
1662 static void dcr_write_mal (void *opaque
, int dcrn
, target_ulong val
)
1670 if (val
& 0x80000000)
1671 ppc40x_mal_reset(mal
);
1672 mal
->cfg
= val
& 0x00FFC087;
1679 mal
->ier
= val
& 0x0000001F;
1682 mal
->txcasr
= val
& 0xF0000000;
1685 mal
->txcarr
= val
& 0xF0000000;
1689 mal
->txeobisr
&= ~val
;
1693 mal
->txdeir
&= ~val
;
1696 mal
->rxcasr
= val
& 0xC0000000;
1699 mal
->rxcarr
= val
& 0xC0000000;
1703 mal
->rxeobisr
&= ~val
;
1707 mal
->rxdeir
&= ~val
;
1721 mal
->txctpr
[idx
] = val
;
1729 mal
->rxctpr
[idx
] = val
;
1733 goto update_rx_size
;
1737 mal
->rcbs
[idx
] = val
& 0x000000FF;
1742 static void ppc40x_mal_reset (void *opaque
)
1747 mal
->cfg
= 0x0007C000;
1748 mal
->esr
= 0x00000000;
1749 mal
->ier
= 0x00000000;
1750 mal
->rxcasr
= 0x00000000;
1751 mal
->rxdeir
= 0x00000000;
1752 mal
->rxeobisr
= 0x00000000;
1753 mal
->txcasr
= 0x00000000;
1754 mal
->txdeir
= 0x00000000;
1755 mal
->txeobisr
= 0x00000000;
1758 static void ppc405_mal_init(CPUState
*env
, qemu_irq irqs
[4])
1763 mal
= qemu_mallocz(sizeof(ppc40x_mal_t
));
1764 for (i
= 0; i
< 4; i
++)
1765 mal
->irqs
[i
] = irqs
[i
];
1766 ppc40x_mal_reset(mal
);
1767 qemu_register_reset(&ppc40x_mal_reset
, mal
);
1768 ppc_dcr_register(env
, MAL0_CFG
,
1769 mal
, &dcr_read_mal
, &dcr_write_mal
);
1770 ppc_dcr_register(env
, MAL0_ESR
,
1771 mal
, &dcr_read_mal
, &dcr_write_mal
);
1772 ppc_dcr_register(env
, MAL0_IER
,
1773 mal
, &dcr_read_mal
, &dcr_write_mal
);
1774 ppc_dcr_register(env
, MAL0_TXCASR
,
1775 mal
, &dcr_read_mal
, &dcr_write_mal
);
1776 ppc_dcr_register(env
, MAL0_TXCARR
,
1777 mal
, &dcr_read_mal
, &dcr_write_mal
);
1778 ppc_dcr_register(env
, MAL0_TXEOBISR
,
1779 mal
, &dcr_read_mal
, &dcr_write_mal
);
1780 ppc_dcr_register(env
, MAL0_TXDEIR
,
1781 mal
, &dcr_read_mal
, &dcr_write_mal
);
1782 ppc_dcr_register(env
, MAL0_RXCASR
,
1783 mal
, &dcr_read_mal
, &dcr_write_mal
);
1784 ppc_dcr_register(env
, MAL0_RXCARR
,
1785 mal
, &dcr_read_mal
, &dcr_write_mal
);
1786 ppc_dcr_register(env
, MAL0_RXEOBISR
,
1787 mal
, &dcr_read_mal
, &dcr_write_mal
);
1788 ppc_dcr_register(env
, MAL0_RXDEIR
,
1789 mal
, &dcr_read_mal
, &dcr_write_mal
);
1790 ppc_dcr_register(env
, MAL0_TXCTP0R
,
1791 mal
, &dcr_read_mal
, &dcr_write_mal
);
1792 ppc_dcr_register(env
, MAL0_TXCTP1R
,
1793 mal
, &dcr_read_mal
, &dcr_write_mal
);
1794 ppc_dcr_register(env
, MAL0_TXCTP2R
,
1795 mal
, &dcr_read_mal
, &dcr_write_mal
);
1796 ppc_dcr_register(env
, MAL0_TXCTP3R
,
1797 mal
, &dcr_read_mal
, &dcr_write_mal
);
1798 ppc_dcr_register(env
, MAL0_RXCTP0R
,
1799 mal
, &dcr_read_mal
, &dcr_write_mal
);
1800 ppc_dcr_register(env
, MAL0_RXCTP1R
,
1801 mal
, &dcr_read_mal
, &dcr_write_mal
);
1802 ppc_dcr_register(env
, MAL0_RCBS0
,
1803 mal
, &dcr_read_mal
, &dcr_write_mal
);
1804 ppc_dcr_register(env
, MAL0_RCBS1
,
1805 mal
, &dcr_read_mal
, &dcr_write_mal
);
1808 /*****************************************************************************/
1810 void ppc40x_core_reset (CPUState
*env
)
1814 printf("Reset PowerPC core\n");
1815 env
->interrupt_request
|= CPU_INTERRUPT_EXITTB
;
1820 qemu_system_reset_request();
1822 dbsr
= env
->spr
[SPR_40x_DBSR
];
1823 dbsr
&= ~0x00000300;
1825 env
->spr
[SPR_40x_DBSR
] = dbsr
;
1828 void ppc40x_chip_reset (CPUState
*env
)
1832 printf("Reset PowerPC chip\n");
1833 env
->interrupt_request
|= CPU_INTERRUPT_EXITTB
;
1838 qemu_system_reset_request();
1840 /* XXX: TODO reset all internal peripherals */
1841 dbsr
= env
->spr
[SPR_40x_DBSR
];
1842 dbsr
&= ~0x00000300;
1844 env
->spr
[SPR_40x_DBSR
] = dbsr
;
1847 void ppc40x_system_reset (CPUState
*env
)
1849 printf("Reset PowerPC system\n");
1850 qemu_system_reset_request();
1853 void store_40x_dbcr0 (CPUState
*env
, uint32_t val
)
1855 switch ((val
>> 28) & 0x3) {
1861 ppc40x_core_reset(env
);
1865 ppc40x_chip_reset(env
);
1869 ppc40x_system_reset(env
);
1874 /*****************************************************************************/
1877 PPC405CR_CPC0_PLLMR
= 0x0B0,
1878 PPC405CR_CPC0_CR0
= 0x0B1,
1879 PPC405CR_CPC0_CR1
= 0x0B2,
1880 PPC405CR_CPC0_PSR
= 0x0B4,
1881 PPC405CR_CPC0_JTAGID
= 0x0B5,
1882 PPC405CR_CPC0_ER
= 0x0B9,
1883 PPC405CR_CPC0_FR
= 0x0BA,
1884 PPC405CR_CPC0_SR
= 0x0BB,
1888 PPC405CR_CPU_CLK
= 0,
1889 PPC405CR_TMR_CLK
= 1,
1890 PPC405CR_PLB_CLK
= 2,
1891 PPC405CR_SDRAM_CLK
= 3,
1892 PPC405CR_OPB_CLK
= 4,
1893 PPC405CR_EXT_CLK
= 5,
1894 PPC405CR_UART_CLK
= 6,
1895 PPC405CR_CLK_NB
= 7,
1898 typedef struct ppc405cr_cpc_t ppc405cr_cpc_t
;
1899 struct ppc405cr_cpc_t
{
1900 clk_setup_t clk_setup
[PPC405CR_CLK_NB
];
1911 static void ppc405cr_clk_setup (ppc405cr_cpc_t
*cpc
)
1913 uint64_t VCO_out
, PLL_out
;
1914 uint32_t CPU_clk
, TMR_clk
, SDRAM_clk
, PLB_clk
, OPB_clk
, EXT_clk
, UART_clk
;
1917 D0
= ((cpc
->pllmr
>> 26) & 0x3) + 1; /* CBDV */
1918 if (cpc
->pllmr
& 0x80000000) {
1919 D1
= (((cpc
->pllmr
>> 20) - 1) & 0xF) + 1; /* FBDV */
1920 D2
= 8 - ((cpc
->pllmr
>> 16) & 0x7); /* FWDVA */
1922 VCO_out
= cpc
->sysclk
* M
;
1923 if (VCO_out
< 400000000 || VCO_out
> 800000000) {
1924 /* PLL cannot lock */
1925 cpc
->pllmr
&= ~0x80000000;
1928 PLL_out
= VCO_out
/ D2
;
1933 PLL_out
= cpc
->sysclk
* M
;
1936 if (cpc
->cr1
& 0x00800000)
1937 TMR_clk
= cpc
->sysclk
; /* Should have a separate clock */
1940 PLB_clk
= CPU_clk
/ D0
;
1941 SDRAM_clk
= PLB_clk
;
1942 D0
= ((cpc
->pllmr
>> 10) & 0x3) + 1;
1943 OPB_clk
= PLB_clk
/ D0
;
1944 D0
= ((cpc
->pllmr
>> 24) & 0x3) + 2;
1945 EXT_clk
= PLB_clk
/ D0
;
1946 D0
= ((cpc
->cr0
>> 1) & 0x1F) + 1;
1947 UART_clk
= CPU_clk
/ D0
;
1948 /* Setup CPU clocks */
1949 clk_setup(&cpc
->clk_setup
[PPC405CR_CPU_CLK
], CPU_clk
);
1950 /* Setup time-base clock */
1951 clk_setup(&cpc
->clk_setup
[PPC405CR_TMR_CLK
], TMR_clk
);
1952 /* Setup PLB clock */
1953 clk_setup(&cpc
->clk_setup
[PPC405CR_PLB_CLK
], PLB_clk
);
1954 /* Setup SDRAM clock */
1955 clk_setup(&cpc
->clk_setup
[PPC405CR_SDRAM_CLK
], SDRAM_clk
);
1956 /* Setup OPB clock */
1957 clk_setup(&cpc
->clk_setup
[PPC405CR_OPB_CLK
], OPB_clk
);
1958 /* Setup external clock */
1959 clk_setup(&cpc
->clk_setup
[PPC405CR_EXT_CLK
], EXT_clk
);
1960 /* Setup UART clock */
1961 clk_setup(&cpc
->clk_setup
[PPC405CR_UART_CLK
], UART_clk
);
1964 static target_ulong
dcr_read_crcpc (void *opaque
, int dcrn
)
1966 ppc405cr_cpc_t
*cpc
;
1971 case PPC405CR_CPC0_PLLMR
:
1974 case PPC405CR_CPC0_CR0
:
1977 case PPC405CR_CPC0_CR1
:
1980 case PPC405CR_CPC0_PSR
:
1983 case PPC405CR_CPC0_JTAGID
:
1986 case PPC405CR_CPC0_ER
:
1989 case PPC405CR_CPC0_FR
:
1992 case PPC405CR_CPC0_SR
:
1993 ret
= ~(cpc
->er
| cpc
->fr
) & 0xFFFF0000;
1996 /* Avoid gcc warning */
2004 static void dcr_write_crcpc (void *opaque
, int dcrn
, target_ulong val
)
2006 ppc405cr_cpc_t
*cpc
;
2010 case PPC405CR_CPC0_PLLMR
:
2011 cpc
->pllmr
= val
& 0xFFF77C3F;
2013 case PPC405CR_CPC0_CR0
:
2014 cpc
->cr0
= val
& 0x0FFFFFFE;
2016 case PPC405CR_CPC0_CR1
:
2017 cpc
->cr1
= val
& 0x00800000;
2019 case PPC405CR_CPC0_PSR
:
2022 case PPC405CR_CPC0_JTAGID
:
2025 case PPC405CR_CPC0_ER
:
2026 cpc
->er
= val
& 0xBFFC0000;
2028 case PPC405CR_CPC0_FR
:
2029 cpc
->fr
= val
& 0xBFFC0000;
2031 case PPC405CR_CPC0_SR
:
2037 static void ppc405cr_cpc_reset (void *opaque
)
2039 ppc405cr_cpc_t
*cpc
;
2043 /* Compute PLLMR value from PSR settings */
2044 cpc
->pllmr
= 0x80000000;
2046 switch ((cpc
->psr
>> 30) & 3) {
2049 cpc
->pllmr
&= ~0x80000000;
2053 cpc
->pllmr
|= 5 << 16;
2057 cpc
->pllmr
|= 4 << 16;
2061 cpc
->pllmr
|= 2 << 16;
2065 D
= (cpc
->psr
>> 28) & 3;
2066 cpc
->pllmr
|= (D
+ 1) << 20;
2068 D
= (cpc
->psr
>> 25) & 7;
2083 D
= (cpc
->psr
>> 23) & 3;
2084 cpc
->pllmr
|= D
<< 26;
2086 D
= (cpc
->psr
>> 21) & 3;
2087 cpc
->pllmr
|= D
<< 10;
2089 D
= (cpc
->psr
>> 17) & 3;
2090 cpc
->pllmr
|= D
<< 24;
2091 cpc
->cr0
= 0x0000003C;
2092 cpc
->cr1
= 0x2B0D8800;
2093 cpc
->er
= 0x00000000;
2094 cpc
->fr
= 0x00000000;
2095 ppc405cr_clk_setup(cpc
);
2098 static void ppc405cr_clk_init (ppc405cr_cpc_t
*cpc
)
2102 /* XXX: this should be read from IO pins */
2103 cpc
->psr
= 0x00000000; /* 8 bits ROM */
2105 D
= 0x2; /* Divide by 4 */
2106 cpc
->psr
|= D
<< 30;
2108 D
= 0x1; /* Divide by 2 */
2109 cpc
->psr
|= D
<< 28;
2111 D
= 0x1; /* Divide by 2 */
2112 cpc
->psr
|= D
<< 23;
2114 D
= 0x5; /* M = 16 */
2115 cpc
->psr
|= D
<< 25;
2117 D
= 0x1; /* Divide by 2 */
2118 cpc
->psr
|= D
<< 21;
2120 D
= 0x2; /* Divide by 4 */
2121 cpc
->psr
|= D
<< 17;
2124 static void ppc405cr_cpc_init (CPUState
*env
, clk_setup_t clk_setup
[7],
2127 ppc405cr_cpc_t
*cpc
;
2129 cpc
= qemu_mallocz(sizeof(ppc405cr_cpc_t
));
2130 memcpy(cpc
->clk_setup
, clk_setup
,
2131 PPC405CR_CLK_NB
* sizeof(clk_setup_t
));
2132 cpc
->sysclk
= sysclk
;
2133 cpc
->jtagid
= 0x42051049;
2134 ppc_dcr_register(env
, PPC405CR_CPC0_PSR
, cpc
,
2135 &dcr_read_crcpc
, &dcr_write_crcpc
);
2136 ppc_dcr_register(env
, PPC405CR_CPC0_CR0
, cpc
,
2137 &dcr_read_crcpc
, &dcr_write_crcpc
);
2138 ppc_dcr_register(env
, PPC405CR_CPC0_CR1
, cpc
,
2139 &dcr_read_crcpc
, &dcr_write_crcpc
);
2140 ppc_dcr_register(env
, PPC405CR_CPC0_JTAGID
, cpc
,
2141 &dcr_read_crcpc
, &dcr_write_crcpc
);
2142 ppc_dcr_register(env
, PPC405CR_CPC0_PLLMR
, cpc
,
2143 &dcr_read_crcpc
, &dcr_write_crcpc
);
2144 ppc_dcr_register(env
, PPC405CR_CPC0_ER
, cpc
,
2145 &dcr_read_crcpc
, &dcr_write_crcpc
);
2146 ppc_dcr_register(env
, PPC405CR_CPC0_FR
, cpc
,
2147 &dcr_read_crcpc
, &dcr_write_crcpc
);
2148 ppc_dcr_register(env
, PPC405CR_CPC0_SR
, cpc
,
2149 &dcr_read_crcpc
, &dcr_write_crcpc
);
2150 ppc405cr_clk_init(cpc
);
2151 qemu_register_reset(ppc405cr_cpc_reset
, cpc
);
2152 ppc405cr_cpc_reset(cpc
);
2155 CPUState
*ppc405cr_init (target_phys_addr_t ram_bases
[4],
2156 target_phys_addr_t ram_sizes
[4],
2157 uint32_t sysclk
, qemu_irq
**picp
,
2160 clk_setup_t clk_setup
[PPC405CR_CLK_NB
];
2161 qemu_irq dma_irqs
[4];
2163 qemu_irq
*pic
, *irqs
;
2165 memset(clk_setup
, 0, sizeof(clk_setup
));
2166 env
= ppc4xx_init("405cr", &clk_setup
[PPC405CR_CPU_CLK
],
2167 &clk_setup
[PPC405CR_TMR_CLK
], sysclk
);
2168 /* Memory mapped devices registers */
2170 ppc4xx_plb_init(env
);
2171 /* PLB to OPB bridge */
2172 ppc4xx_pob_init(env
);
2174 ppc4xx_opba_init(0xef600600);
2175 /* Universal interrupt controller */
2176 irqs
= qemu_mallocz(sizeof(qemu_irq
) * PPCUIC_OUTPUT_NB
);
2177 irqs
[PPCUIC_OUTPUT_INT
] =
2178 ((qemu_irq
*)env
->irq_inputs
)[PPC40x_INPUT_INT
];
2179 irqs
[PPCUIC_OUTPUT_CINT
] =
2180 ((qemu_irq
*)env
->irq_inputs
)[PPC40x_INPUT_CINT
];
2181 pic
= ppcuic_init(env
, irqs
, 0x0C0, 0, 1);
2183 /* SDRAM controller */
2184 ppc4xx_sdram_init(env
, pic
[14], 1, ram_bases
, ram_sizes
, do_init
);
2185 /* External bus controller */
2186 ppc405_ebc_init(env
);
2187 /* DMA controller */
2188 dma_irqs
[0] = pic
[26];
2189 dma_irqs
[1] = pic
[25];
2190 dma_irqs
[2] = pic
[24];
2191 dma_irqs
[3] = pic
[23];
2192 ppc405_dma_init(env
, dma_irqs
);
2194 if (serial_hds
[0] != NULL
) {
2195 serial_mm_init(0xef600300, 0, pic
[0], PPC_SERIAL_MM_BAUDBASE
,
2198 if (serial_hds
[1] != NULL
) {
2199 serial_mm_init(0xef600400, 0, pic
[1], PPC_SERIAL_MM_BAUDBASE
,
2202 /* IIC controller */
2203 ppc405_i2c_init(0xef600500, pic
[2]);
2205 ppc405_gpio_init(0xef600700);
2207 ppc405cr_cpc_init(env
, clk_setup
, sysclk
);
2212 /*****************************************************************************/
2216 PPC405EP_CPC0_PLLMR0
= 0x0F0,
2217 PPC405EP_CPC0_BOOT
= 0x0F1,
2218 PPC405EP_CPC0_EPCTL
= 0x0F3,
2219 PPC405EP_CPC0_PLLMR1
= 0x0F4,
2220 PPC405EP_CPC0_UCR
= 0x0F5,
2221 PPC405EP_CPC0_SRR
= 0x0F6,
2222 PPC405EP_CPC0_JTAGID
= 0x0F7,
2223 PPC405EP_CPC0_PCI
= 0x0F9,
2225 PPC405EP_CPC0_ER
= xxx
,
2226 PPC405EP_CPC0_FR
= xxx
,
2227 PPC405EP_CPC0_SR
= xxx
,
2232 PPC405EP_CPU_CLK
= 0,
2233 PPC405EP_PLB_CLK
= 1,
2234 PPC405EP_OPB_CLK
= 2,
2235 PPC405EP_EBC_CLK
= 3,
2236 PPC405EP_MAL_CLK
= 4,
2237 PPC405EP_PCI_CLK
= 5,
2238 PPC405EP_UART0_CLK
= 6,
2239 PPC405EP_UART1_CLK
= 7,
2240 PPC405EP_CLK_NB
= 8,
2243 typedef struct ppc405ep_cpc_t ppc405ep_cpc_t
;
2244 struct ppc405ep_cpc_t
{
2246 clk_setup_t clk_setup
[PPC405EP_CLK_NB
];
2254 /* Clock and power management */
2260 static void ppc405ep_compute_clocks (ppc405ep_cpc_t
*cpc
)
2262 uint32_t CPU_clk
, PLB_clk
, OPB_clk
, EBC_clk
, MAL_clk
, PCI_clk
;
2263 uint32_t UART0_clk
, UART1_clk
;
2264 uint64_t VCO_out
, PLL_out
;
2268 if ((cpc
->pllmr
[1] & 0x80000000) && !(cpc
->pllmr
[1] & 0x40000000)) {
2269 M
= (((cpc
->pllmr
[1] >> 20) - 1) & 0xF) + 1; /* FBMUL */
2270 #ifdef DEBUG_CLOCKS_LL
2271 printf("FBMUL %01" PRIx32
" %d\n", (cpc
->pllmr
[1] >> 20) & 0xF, M
);
2273 D
= 8 - ((cpc
->pllmr
[1] >> 16) & 0x7); /* FWDA */
2274 #ifdef DEBUG_CLOCKS_LL
2275 printf("FWDA %01" PRIx32
" %d\n", (cpc
->pllmr
[1] >> 16) & 0x7, D
);
2277 VCO_out
= cpc
->sysclk
* M
* D
;
2278 if (VCO_out
< 500000000UL || VCO_out
> 1000000000UL) {
2279 /* Error - unlock the PLL */
2280 printf("VCO out of range %" PRIu64
"\n", VCO_out
);
2282 cpc
->pllmr
[1] &= ~0x80000000;
2286 PLL_out
= VCO_out
/ D
;
2287 /* Pretend the PLL is locked */
2288 cpc
->boot
|= 0x00000001;
2293 PLL_out
= cpc
->sysclk
;
2294 if (cpc
->pllmr
[1] & 0x40000000) {
2295 /* Pretend the PLL is not locked */
2296 cpc
->boot
&= ~0x00000001;
2299 /* Now, compute all other clocks */
2300 D
= ((cpc
->pllmr
[0] >> 20) & 0x3) + 1; /* CCDV */
2301 #ifdef DEBUG_CLOCKS_LL
2302 printf("CCDV %01" PRIx32
" %d\n", (cpc
->pllmr
[0] >> 20) & 0x3, D
);
2304 CPU_clk
= PLL_out
/ D
;
2305 D
= ((cpc
->pllmr
[0] >> 16) & 0x3) + 1; /* CBDV */
2306 #ifdef DEBUG_CLOCKS_LL
2307 printf("CBDV %01" PRIx32
" %d\n", (cpc
->pllmr
[0] >> 16) & 0x3, D
);
2309 PLB_clk
= CPU_clk
/ D
;
2310 D
= ((cpc
->pllmr
[0] >> 12) & 0x3) + 1; /* OPDV */
2311 #ifdef DEBUG_CLOCKS_LL
2312 printf("OPDV %01" PRIx32
" %d\n", (cpc
->pllmr
[0] >> 12) & 0x3, D
);
2314 OPB_clk
= PLB_clk
/ D
;
2315 D
= ((cpc
->pllmr
[0] >> 8) & 0x3) + 2; /* EPDV */
2316 #ifdef DEBUG_CLOCKS_LL
2317 printf("EPDV %01" PRIx32
" %d\n", (cpc
->pllmr
[0] >> 8) & 0x3, D
);
2319 EBC_clk
= PLB_clk
/ D
;
2320 D
= ((cpc
->pllmr
[0] >> 4) & 0x3) + 1; /* MPDV */
2321 #ifdef DEBUG_CLOCKS_LL
2322 printf("MPDV %01" PRIx32
" %d\n", (cpc
->pllmr
[0] >> 4) & 0x3, D
);
2324 MAL_clk
= PLB_clk
/ D
;
2325 D
= (cpc
->pllmr
[0] & 0x3) + 1; /* PPDV */
2326 #ifdef DEBUG_CLOCKS_LL
2327 printf("PPDV %01" PRIx32
" %d\n", cpc
->pllmr
[0] & 0x3, D
);
2329 PCI_clk
= PLB_clk
/ D
;
2330 D
= ((cpc
->ucr
- 1) & 0x7F) + 1; /* U0DIV */
2331 #ifdef DEBUG_CLOCKS_LL
2332 printf("U0DIV %01" PRIx32
" %d\n", cpc
->ucr
& 0x7F, D
);
2334 UART0_clk
= PLL_out
/ D
;
2335 D
= (((cpc
->ucr
>> 8) - 1) & 0x7F) + 1; /* U1DIV */
2336 #ifdef DEBUG_CLOCKS_LL
2337 printf("U1DIV %01" PRIx32
" %d\n", (cpc
->ucr
>> 8) & 0x7F, D
);
2339 UART1_clk
= PLL_out
/ D
;
2341 printf("Setup PPC405EP clocks - sysclk %" PRIu32
" VCO %" PRIu64
2342 " PLL out %" PRIu64
" Hz\n", cpc
->sysclk
, VCO_out
, PLL_out
);
2343 printf("CPU %" PRIu32
" PLB %" PRIu32
" OPB %" PRIu32
" EBC %" PRIu32
2344 " MAL %" PRIu32
" PCI %" PRIu32
" UART0 %" PRIu32
2345 " UART1 %" PRIu32
"\n",
2346 CPU_clk
, PLB_clk
, OPB_clk
, EBC_clk
, MAL_clk
, PCI_clk
,
2347 UART0_clk
, UART1_clk
);
2349 /* Setup CPU clocks */
2350 clk_setup(&cpc
->clk_setup
[PPC405EP_CPU_CLK
], CPU_clk
);
2351 /* Setup PLB clock */
2352 clk_setup(&cpc
->clk_setup
[PPC405EP_PLB_CLK
], PLB_clk
);
2353 /* Setup OPB clock */
2354 clk_setup(&cpc
->clk_setup
[PPC405EP_OPB_CLK
], OPB_clk
);
2355 /* Setup external clock */
2356 clk_setup(&cpc
->clk_setup
[PPC405EP_EBC_CLK
], EBC_clk
);
2357 /* Setup MAL clock */
2358 clk_setup(&cpc
->clk_setup
[PPC405EP_MAL_CLK
], MAL_clk
);
2359 /* Setup PCI clock */
2360 clk_setup(&cpc
->clk_setup
[PPC405EP_PCI_CLK
], PCI_clk
);
2361 /* Setup UART0 clock */
2362 clk_setup(&cpc
->clk_setup
[PPC405EP_UART0_CLK
], UART0_clk
);
2363 /* Setup UART1 clock */
2364 clk_setup(&cpc
->clk_setup
[PPC405EP_UART1_CLK
], UART1_clk
);
2367 static target_ulong
dcr_read_epcpc (void *opaque
, int dcrn
)
2369 ppc405ep_cpc_t
*cpc
;
2374 case PPC405EP_CPC0_BOOT
:
2377 case PPC405EP_CPC0_EPCTL
:
2380 case PPC405EP_CPC0_PLLMR0
:
2381 ret
= cpc
->pllmr
[0];
2383 case PPC405EP_CPC0_PLLMR1
:
2384 ret
= cpc
->pllmr
[1];
2386 case PPC405EP_CPC0_UCR
:
2389 case PPC405EP_CPC0_SRR
:
2392 case PPC405EP_CPC0_JTAGID
:
2395 case PPC405EP_CPC0_PCI
:
2399 /* Avoid gcc warning */
2407 static void dcr_write_epcpc (void *opaque
, int dcrn
, target_ulong val
)
2409 ppc405ep_cpc_t
*cpc
;
2413 case PPC405EP_CPC0_BOOT
:
2414 /* Read-only register */
2416 case PPC405EP_CPC0_EPCTL
:
2417 /* Don't care for now */
2418 cpc
->epctl
= val
& 0xC00000F3;
2420 case PPC405EP_CPC0_PLLMR0
:
2421 cpc
->pllmr
[0] = val
& 0x00633333;
2422 ppc405ep_compute_clocks(cpc
);
2424 case PPC405EP_CPC0_PLLMR1
:
2425 cpc
->pllmr
[1] = val
& 0xC0F73FFF;
2426 ppc405ep_compute_clocks(cpc
);
2428 case PPC405EP_CPC0_UCR
:
2429 /* UART control - don't care for now */
2430 cpc
->ucr
= val
& 0x003F7F7F;
2432 case PPC405EP_CPC0_SRR
:
2435 case PPC405EP_CPC0_JTAGID
:
2438 case PPC405EP_CPC0_PCI
:
2444 static void ppc405ep_cpc_reset (void *opaque
)
2446 ppc405ep_cpc_t
*cpc
= opaque
;
2448 cpc
->boot
= 0x00000010; /* Boot from PCI - IIC EEPROM disabled */
2449 cpc
->epctl
= 0x00000000;
2450 cpc
->pllmr
[0] = 0x00011010;
2451 cpc
->pllmr
[1] = 0x40000000;
2452 cpc
->ucr
= 0x00000000;
2453 cpc
->srr
= 0x00040000;
2454 cpc
->pci
= 0x00000000;
2455 cpc
->er
= 0x00000000;
2456 cpc
->fr
= 0x00000000;
2457 cpc
->sr
= 0x00000000;
2458 ppc405ep_compute_clocks(cpc
);
2461 /* XXX: sysclk should be between 25 and 100 MHz */
2462 static void ppc405ep_cpc_init (CPUState
*env
, clk_setup_t clk_setup
[8],
2465 ppc405ep_cpc_t
*cpc
;
2467 cpc
= qemu_mallocz(sizeof(ppc405ep_cpc_t
));
2468 memcpy(cpc
->clk_setup
, clk_setup
,
2469 PPC405EP_CLK_NB
* sizeof(clk_setup_t
));
2470 cpc
->jtagid
= 0x20267049;
2471 cpc
->sysclk
= sysclk
;
2472 ppc405ep_cpc_reset(cpc
);
2473 qemu_register_reset(&ppc405ep_cpc_reset
, cpc
);
2474 ppc_dcr_register(env
, PPC405EP_CPC0_BOOT
, cpc
,
2475 &dcr_read_epcpc
, &dcr_write_epcpc
);
2476 ppc_dcr_register(env
, PPC405EP_CPC0_EPCTL
, cpc
,
2477 &dcr_read_epcpc
, &dcr_write_epcpc
);
2478 ppc_dcr_register(env
, PPC405EP_CPC0_PLLMR0
, cpc
,
2479 &dcr_read_epcpc
, &dcr_write_epcpc
);
2480 ppc_dcr_register(env
, PPC405EP_CPC0_PLLMR1
, cpc
,
2481 &dcr_read_epcpc
, &dcr_write_epcpc
);
2482 ppc_dcr_register(env
, PPC405EP_CPC0_UCR
, cpc
,
2483 &dcr_read_epcpc
, &dcr_write_epcpc
);
2484 ppc_dcr_register(env
, PPC405EP_CPC0_SRR
, cpc
,
2485 &dcr_read_epcpc
, &dcr_write_epcpc
);
2486 ppc_dcr_register(env
, PPC405EP_CPC0_JTAGID
, cpc
,
2487 &dcr_read_epcpc
, &dcr_write_epcpc
);
2488 ppc_dcr_register(env
, PPC405EP_CPC0_PCI
, cpc
,
2489 &dcr_read_epcpc
, &dcr_write_epcpc
);
2491 ppc_dcr_register(env
, PPC405EP_CPC0_ER
, cpc
,
2492 &dcr_read_epcpc
, &dcr_write_epcpc
);
2493 ppc_dcr_register(env
, PPC405EP_CPC0_FR
, cpc
,
2494 &dcr_read_epcpc
, &dcr_write_epcpc
);
2495 ppc_dcr_register(env
, PPC405EP_CPC0_SR
, cpc
,
2496 &dcr_read_epcpc
, &dcr_write_epcpc
);
2500 CPUState
*ppc405ep_init (target_phys_addr_t ram_bases
[2],
2501 target_phys_addr_t ram_sizes
[2],
2502 uint32_t sysclk
, qemu_irq
**picp
,
2505 clk_setup_t clk_setup
[PPC405EP_CLK_NB
], tlb_clk_setup
;
2506 qemu_irq dma_irqs
[4], gpt_irqs
[5], mal_irqs
[4];
2508 qemu_irq
*pic
, *irqs
;
2510 memset(clk_setup
, 0, sizeof(clk_setup
));
2512 env
= ppc4xx_init("405ep", &clk_setup
[PPC405EP_CPU_CLK
],
2513 &tlb_clk_setup
, sysclk
);
2514 clk_setup
[PPC405EP_CPU_CLK
].cb
= tlb_clk_setup
.cb
;
2515 clk_setup
[PPC405EP_CPU_CLK
].opaque
= tlb_clk_setup
.opaque
;
2516 /* Internal devices init */
2517 /* Memory mapped devices registers */
2519 ppc4xx_plb_init(env
);
2520 /* PLB to OPB bridge */
2521 ppc4xx_pob_init(env
);
2523 ppc4xx_opba_init(0xef600600);
2524 /* Universal interrupt controller */
2525 irqs
= qemu_mallocz(sizeof(qemu_irq
) * PPCUIC_OUTPUT_NB
);
2526 irqs
[PPCUIC_OUTPUT_INT
] =
2527 ((qemu_irq
*)env
->irq_inputs
)[PPC40x_INPUT_INT
];
2528 irqs
[PPCUIC_OUTPUT_CINT
] =
2529 ((qemu_irq
*)env
->irq_inputs
)[PPC40x_INPUT_CINT
];
2530 pic
= ppcuic_init(env
, irqs
, 0x0C0, 0, 1);
2532 /* SDRAM controller */
2533 /* XXX 405EP has no ECC interrupt */
2534 ppc4xx_sdram_init(env
, pic
[17], 2, ram_bases
, ram_sizes
, do_init
);
2535 /* External bus controller */
2536 ppc405_ebc_init(env
);
2537 /* DMA controller */
2538 dma_irqs
[0] = pic
[5];
2539 dma_irqs
[1] = pic
[6];
2540 dma_irqs
[2] = pic
[7];
2541 dma_irqs
[3] = pic
[8];
2542 ppc405_dma_init(env
, dma_irqs
);
2543 /* IIC controller */
2544 ppc405_i2c_init(0xef600500, pic
[2]);
2546 ppc405_gpio_init(0xef600700);
2548 if (serial_hds
[0] != NULL
) {
2549 serial_mm_init(0xef600300, 0, pic
[0], PPC_SERIAL_MM_BAUDBASE
,
2552 if (serial_hds
[1] != NULL
) {
2553 serial_mm_init(0xef600400, 0, pic
[1], PPC_SERIAL_MM_BAUDBASE
,
2557 ppc405_ocm_init(env
);
2559 gpt_irqs
[0] = pic
[19];
2560 gpt_irqs
[1] = pic
[20];
2561 gpt_irqs
[2] = pic
[21];
2562 gpt_irqs
[3] = pic
[22];
2563 gpt_irqs
[4] = pic
[23];
2564 ppc4xx_gpt_init(0xef600000, gpt_irqs
);
2566 /* Uses pic[3], pic[16], pic[18] */
2568 mal_irqs
[0] = pic
[11];
2569 mal_irqs
[1] = pic
[12];
2570 mal_irqs
[2] = pic
[13];
2571 mal_irqs
[3] = pic
[14];
2572 ppc405_mal_init(env
, mal_irqs
);
2574 /* Uses pic[9], pic[15], pic[17] */
2576 ppc405ep_cpc_init(env
, clk_setup
, sysclk
);