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 DEVICE_NATIVE_ENDIAN
);
388 cpu_register_physical_memory(base
, 0x002, io
);
389 qemu_register_reset(ppc4xx_opba_reset
, opba
);
392 /*****************************************************************************/
393 /* Code decompression controller */
396 /*****************************************************************************/
397 /* Peripheral controller */
398 typedef struct ppc4xx_ebc_t ppc4xx_ebc_t
;
399 struct ppc4xx_ebc_t
{
410 EBC0_CFGADDR
= 0x012,
411 EBC0_CFGDATA
= 0x013,
414 static uint32_t dcr_read_ebc (void *opaque
, int dcrn
)
426 case 0x00: /* B0CR */
429 case 0x01: /* B1CR */
432 case 0x02: /* B2CR */
435 case 0x03: /* B3CR */
438 case 0x04: /* B4CR */
441 case 0x05: /* B5CR */
444 case 0x06: /* B6CR */
447 case 0x07: /* B7CR */
450 case 0x10: /* B0AP */
453 case 0x11: /* B1AP */
456 case 0x12: /* B2AP */
459 case 0x13: /* B3AP */
462 case 0x14: /* B4AP */
465 case 0x15: /* B5AP */
468 case 0x16: /* B6AP */
471 case 0x17: /* B7AP */
474 case 0x20: /* BEAR */
477 case 0x21: /* BESR0 */
480 case 0x22: /* BESR1 */
499 static void dcr_write_ebc (void *opaque
, int dcrn
, uint32_t val
)
510 case 0x00: /* B0CR */
512 case 0x01: /* B1CR */
514 case 0x02: /* B2CR */
516 case 0x03: /* B3CR */
518 case 0x04: /* B4CR */
520 case 0x05: /* B5CR */
522 case 0x06: /* B6CR */
524 case 0x07: /* B7CR */
526 case 0x10: /* B0AP */
528 case 0x11: /* B1AP */
530 case 0x12: /* B2AP */
532 case 0x13: /* B3AP */
534 case 0x14: /* B4AP */
536 case 0x15: /* B5AP */
538 case 0x16: /* B6AP */
540 case 0x17: /* B7AP */
542 case 0x20: /* BEAR */
544 case 0x21: /* BESR0 */
546 case 0x22: /* BESR1 */
559 static void ebc_reset (void *opaque
)
565 ebc
->addr
= 0x00000000;
566 ebc
->bap
[0] = 0x7F8FFE80;
567 ebc
->bcr
[0] = 0xFFE28000;
568 for (i
= 0; i
< 8; i
++) {
569 ebc
->bap
[i
] = 0x00000000;
570 ebc
->bcr
[i
] = 0x00000000;
572 ebc
->besr0
= 0x00000000;
573 ebc
->besr1
= 0x00000000;
574 ebc
->cfg
= 0x80400000;
577 static void ppc405_ebc_init(CPUState
*env
)
581 ebc
= qemu_mallocz(sizeof(ppc4xx_ebc_t
));
582 qemu_register_reset(&ebc_reset
, ebc
);
583 ppc_dcr_register(env
, EBC0_CFGADDR
,
584 ebc
, &dcr_read_ebc
, &dcr_write_ebc
);
585 ppc_dcr_register(env
, EBC0_CFGDATA
,
586 ebc
, &dcr_read_ebc
, &dcr_write_ebc
);
589 /*****************************************************************************/
618 typedef struct ppc405_dma_t ppc405_dma_t
;
619 struct ppc405_dma_t
{
632 static uint32_t dcr_read_dma (void *opaque
, int dcrn
)
637 static void dcr_write_dma (void *opaque
, int dcrn
, uint32_t val
)
641 static void ppc405_dma_reset (void *opaque
)
647 for (i
= 0; i
< 4; i
++) {
648 dma
->cr
[i
] = 0x00000000;
649 dma
->ct
[i
] = 0x00000000;
650 dma
->da
[i
] = 0x00000000;
651 dma
->sa
[i
] = 0x00000000;
652 dma
->sg
[i
] = 0x00000000;
654 dma
->sr
= 0x00000000;
655 dma
->sgc
= 0x00000000;
656 dma
->slp
= 0x7C000000;
657 dma
->pol
= 0x00000000;
660 static void ppc405_dma_init(CPUState
*env
, qemu_irq irqs
[4])
664 dma
= qemu_mallocz(sizeof(ppc405_dma_t
));
665 memcpy(dma
->irqs
, irqs
, 4 * sizeof(qemu_irq
));
666 qemu_register_reset(&ppc405_dma_reset
, dma
);
667 ppc_dcr_register(env
, DMA0_CR0
,
668 dma
, &dcr_read_dma
, &dcr_write_dma
);
669 ppc_dcr_register(env
, DMA0_CT0
,
670 dma
, &dcr_read_dma
, &dcr_write_dma
);
671 ppc_dcr_register(env
, DMA0_DA0
,
672 dma
, &dcr_read_dma
, &dcr_write_dma
);
673 ppc_dcr_register(env
, DMA0_SA0
,
674 dma
, &dcr_read_dma
, &dcr_write_dma
);
675 ppc_dcr_register(env
, DMA0_SG0
,
676 dma
, &dcr_read_dma
, &dcr_write_dma
);
677 ppc_dcr_register(env
, DMA0_CR1
,
678 dma
, &dcr_read_dma
, &dcr_write_dma
);
679 ppc_dcr_register(env
, DMA0_CT1
,
680 dma
, &dcr_read_dma
, &dcr_write_dma
);
681 ppc_dcr_register(env
, DMA0_DA1
,
682 dma
, &dcr_read_dma
, &dcr_write_dma
);
683 ppc_dcr_register(env
, DMA0_SA1
,
684 dma
, &dcr_read_dma
, &dcr_write_dma
);
685 ppc_dcr_register(env
, DMA0_SG1
,
686 dma
, &dcr_read_dma
, &dcr_write_dma
);
687 ppc_dcr_register(env
, DMA0_CR2
,
688 dma
, &dcr_read_dma
, &dcr_write_dma
);
689 ppc_dcr_register(env
, DMA0_CT2
,
690 dma
, &dcr_read_dma
, &dcr_write_dma
);
691 ppc_dcr_register(env
, DMA0_DA2
,
692 dma
, &dcr_read_dma
, &dcr_write_dma
);
693 ppc_dcr_register(env
, DMA0_SA2
,
694 dma
, &dcr_read_dma
, &dcr_write_dma
);
695 ppc_dcr_register(env
, DMA0_SG2
,
696 dma
, &dcr_read_dma
, &dcr_write_dma
);
697 ppc_dcr_register(env
, DMA0_CR3
,
698 dma
, &dcr_read_dma
, &dcr_write_dma
);
699 ppc_dcr_register(env
, DMA0_CT3
,
700 dma
, &dcr_read_dma
, &dcr_write_dma
);
701 ppc_dcr_register(env
, DMA0_DA3
,
702 dma
, &dcr_read_dma
, &dcr_write_dma
);
703 ppc_dcr_register(env
, DMA0_SA3
,
704 dma
, &dcr_read_dma
, &dcr_write_dma
);
705 ppc_dcr_register(env
, DMA0_SG3
,
706 dma
, &dcr_read_dma
, &dcr_write_dma
);
707 ppc_dcr_register(env
, DMA0_SR
,
708 dma
, &dcr_read_dma
, &dcr_write_dma
);
709 ppc_dcr_register(env
, DMA0_SGC
,
710 dma
, &dcr_read_dma
, &dcr_write_dma
);
711 ppc_dcr_register(env
, DMA0_SLP
,
712 dma
, &dcr_read_dma
, &dcr_write_dma
);
713 ppc_dcr_register(env
, DMA0_POL
,
714 dma
, &dcr_read_dma
, &dcr_write_dma
);
717 /*****************************************************************************/
719 typedef struct ppc405_gpio_t ppc405_gpio_t
;
720 struct ppc405_gpio_t
{
734 static uint32_t ppc405_gpio_readb (void *opaque
, target_phys_addr_t addr
)
737 printf("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
743 static void ppc405_gpio_writeb (void *opaque
,
744 target_phys_addr_t addr
, uint32_t value
)
747 printf("%s: addr " TARGET_FMT_plx
" val %08" PRIx32
"\n", __func__
, addr
,
752 static uint32_t ppc405_gpio_readw (void *opaque
, target_phys_addr_t addr
)
755 printf("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
761 static void ppc405_gpio_writew (void *opaque
,
762 target_phys_addr_t addr
, uint32_t value
)
765 printf("%s: addr " TARGET_FMT_plx
" val %08" PRIx32
"\n", __func__
, addr
,
770 static uint32_t ppc405_gpio_readl (void *opaque
, target_phys_addr_t addr
)
773 printf("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
779 static void ppc405_gpio_writel (void *opaque
,
780 target_phys_addr_t addr
, uint32_t value
)
783 printf("%s: addr " TARGET_FMT_plx
" val %08" PRIx32
"\n", __func__
, addr
,
788 static CPUReadMemoryFunc
* const ppc405_gpio_read
[] = {
794 static CPUWriteMemoryFunc
* const ppc405_gpio_write
[] = {
800 static void ppc405_gpio_reset (void *opaque
)
804 static void ppc405_gpio_init(target_phys_addr_t base
)
809 gpio
= qemu_mallocz(sizeof(ppc405_gpio_t
));
811 printf("%s: offset " TARGET_FMT_plx
"\n", __func__
, base
);
813 io
= cpu_register_io_memory(ppc405_gpio_read
, ppc405_gpio_write
, gpio
,
814 DEVICE_NATIVE_ENDIAN
);
815 cpu_register_physical_memory(base
, 0x038, io
);
816 qemu_register_reset(&ppc405_gpio_reset
, gpio
);
819 /*****************************************************************************/
823 OCM0_ISACNTL
= 0x019,
825 OCM0_DSACNTL
= 0x01B,
828 typedef struct ppc405_ocm_t ppc405_ocm_t
;
829 struct ppc405_ocm_t
{
837 static void ocm_update_mappings (ppc405_ocm_t
*ocm
,
838 uint32_t isarc
, uint32_t isacntl
,
839 uint32_t dsarc
, uint32_t dsacntl
)
842 printf("OCM update ISA %08" PRIx32
" %08" PRIx32
" (%08" PRIx32
843 " %08" PRIx32
") DSA %08" PRIx32
" %08" PRIx32
844 " (%08" PRIx32
" %08" PRIx32
")\n",
845 isarc
, isacntl
, dsarc
, dsacntl
,
846 ocm
->isarc
, ocm
->isacntl
, ocm
->dsarc
, ocm
->dsacntl
);
848 if (ocm
->isarc
!= isarc
||
849 (ocm
->isacntl
& 0x80000000) != (isacntl
& 0x80000000)) {
850 if (ocm
->isacntl
& 0x80000000) {
851 /* Unmap previously assigned memory region */
852 printf("OCM unmap ISA %08" PRIx32
"\n", ocm
->isarc
);
853 cpu_register_physical_memory(ocm
->isarc
, 0x04000000,
856 if (isacntl
& 0x80000000) {
857 /* Map new instruction memory region */
859 printf("OCM map ISA %08" PRIx32
"\n", isarc
);
861 cpu_register_physical_memory(isarc
, 0x04000000,
862 ocm
->offset
| IO_MEM_RAM
);
865 if (ocm
->dsarc
!= dsarc
||
866 (ocm
->dsacntl
& 0x80000000) != (dsacntl
& 0x80000000)) {
867 if (ocm
->dsacntl
& 0x80000000) {
868 /* Beware not to unmap the region we just mapped */
869 if (!(isacntl
& 0x80000000) || ocm
->dsarc
!= isarc
) {
870 /* Unmap previously assigned memory region */
872 printf("OCM unmap DSA %08" PRIx32
"\n", ocm
->dsarc
);
874 cpu_register_physical_memory(ocm
->dsarc
, 0x04000000,
878 if (dsacntl
& 0x80000000) {
879 /* Beware not to remap the region we just mapped */
880 if (!(isacntl
& 0x80000000) || dsarc
!= isarc
) {
881 /* Map new data memory region */
883 printf("OCM map DSA %08" PRIx32
"\n", dsarc
);
885 cpu_register_physical_memory(dsarc
, 0x04000000,
886 ocm
->offset
| IO_MEM_RAM
);
892 static uint32_t dcr_read_ocm (void *opaque
, int dcrn
)
919 static void dcr_write_ocm (void *opaque
, int dcrn
, uint32_t val
)
922 uint32_t isarc
, dsarc
, isacntl
, dsacntl
;
927 isacntl
= ocm
->isacntl
;
928 dsacntl
= ocm
->dsacntl
;
931 isarc
= val
& 0xFC000000;
934 isacntl
= val
& 0xC0000000;
937 isarc
= val
& 0xFC000000;
940 isacntl
= val
& 0xC0000000;
943 ocm_update_mappings(ocm
, isarc
, isacntl
, dsarc
, dsacntl
);
946 ocm
->isacntl
= isacntl
;
947 ocm
->dsacntl
= dsacntl
;
950 static void ocm_reset (void *opaque
)
953 uint32_t isarc
, dsarc
, isacntl
, dsacntl
;
957 isacntl
= 0x00000000;
959 dsacntl
= 0x00000000;
960 ocm_update_mappings(ocm
, isarc
, isacntl
, dsarc
, dsacntl
);
963 ocm
->isacntl
= isacntl
;
964 ocm
->dsacntl
= dsacntl
;
967 static void ppc405_ocm_init(CPUState
*env
)
971 ocm
= qemu_mallocz(sizeof(ppc405_ocm_t
));
972 ocm
->offset
= qemu_ram_alloc(NULL
, "ppc405.ocm", 4096);
973 qemu_register_reset(&ocm_reset
, ocm
);
974 ppc_dcr_register(env
, OCM0_ISARC
,
975 ocm
, &dcr_read_ocm
, &dcr_write_ocm
);
976 ppc_dcr_register(env
, OCM0_ISACNTL
,
977 ocm
, &dcr_read_ocm
, &dcr_write_ocm
);
978 ppc_dcr_register(env
, OCM0_DSARC
,
979 ocm
, &dcr_read_ocm
, &dcr_write_ocm
);
980 ppc_dcr_register(env
, OCM0_DSACNTL
,
981 ocm
, &dcr_read_ocm
, &dcr_write_ocm
);
984 /*****************************************************************************/
986 typedef struct ppc4xx_i2c_t ppc4xx_i2c_t
;
987 struct ppc4xx_i2c_t
{
1006 static uint32_t ppc4xx_i2c_readb (void *opaque
, target_phys_addr_t addr
)
1012 printf("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
1017 // i2c_readbyte(&i2c->mdata);
1057 ret
= i2c
->xtcntlss
;
1060 ret
= i2c
->directcntl
;
1067 printf("%s: addr " TARGET_FMT_plx
" %02" PRIx32
"\n", __func__
, addr
, ret
);
1073 static void ppc4xx_i2c_writeb (void *opaque
,
1074 target_phys_addr_t addr
, uint32_t value
)
1079 printf("%s: addr " TARGET_FMT_plx
" val %08" PRIx32
"\n", __func__
, addr
,
1086 // i2c_sendbyte(&i2c->mdata);
1101 i2c
->mdcntl
= value
& 0xDF;
1104 i2c
->sts
&= ~(value
& 0x0A);
1107 i2c
->extsts
&= ~(value
& 0x8F);
1116 i2c
->clkdiv
= value
;
1119 i2c
->intrmsk
= value
;
1122 i2c
->xfrcnt
= value
& 0x77;
1125 i2c
->xtcntlss
= value
;
1128 i2c
->directcntl
= value
& 0x7;
1133 static uint32_t ppc4xx_i2c_readw (void *opaque
, target_phys_addr_t addr
)
1138 printf("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
1140 ret
= ppc4xx_i2c_readb(opaque
, addr
) << 8;
1141 ret
|= ppc4xx_i2c_readb(opaque
, addr
+ 1);
1146 static void ppc4xx_i2c_writew (void *opaque
,
1147 target_phys_addr_t addr
, uint32_t value
)
1150 printf("%s: addr " TARGET_FMT_plx
" val %08" PRIx32
"\n", __func__
, addr
,
1153 ppc4xx_i2c_writeb(opaque
, addr
, value
>> 8);
1154 ppc4xx_i2c_writeb(opaque
, addr
+ 1, value
);
1157 static uint32_t ppc4xx_i2c_readl (void *opaque
, target_phys_addr_t addr
)
1162 printf("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
1164 ret
= ppc4xx_i2c_readb(opaque
, addr
) << 24;
1165 ret
|= ppc4xx_i2c_readb(opaque
, addr
+ 1) << 16;
1166 ret
|= ppc4xx_i2c_readb(opaque
, addr
+ 2) << 8;
1167 ret
|= ppc4xx_i2c_readb(opaque
, addr
+ 3);
1172 static void ppc4xx_i2c_writel (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
>> 24);
1180 ppc4xx_i2c_writeb(opaque
, addr
+ 1, value
>> 16);
1181 ppc4xx_i2c_writeb(opaque
, addr
+ 2, value
>> 8);
1182 ppc4xx_i2c_writeb(opaque
, addr
+ 3, value
);
1185 static CPUReadMemoryFunc
* const i2c_read
[] = {
1191 static CPUWriteMemoryFunc
* const i2c_write
[] = {
1197 static void ppc4xx_i2c_reset (void *opaque
)
1210 i2c
->directcntl
= 0x0F;
1213 static void ppc405_i2c_init(target_phys_addr_t base
, qemu_irq irq
)
1218 i2c
= qemu_mallocz(sizeof(ppc4xx_i2c_t
));
1221 printf("%s: offset " TARGET_FMT_plx
"\n", __func__
, base
);
1223 io
= cpu_register_io_memory(i2c_read
, i2c_write
, i2c
,
1224 DEVICE_NATIVE_ENDIAN
);
1225 cpu_register_physical_memory(base
, 0x011, io
);
1226 qemu_register_reset(ppc4xx_i2c_reset
, i2c
);
1229 /*****************************************************************************/
1230 /* General purpose timers */
1231 typedef struct ppc4xx_gpt_t ppc4xx_gpt_t
;
1232 struct ppc4xx_gpt_t
{
1235 struct QEMUTimer
*timer
;
1246 static uint32_t ppc4xx_gpt_readb (void *opaque
, target_phys_addr_t addr
)
1249 printf("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
1251 /* XXX: generate a bus fault */
1255 static void ppc4xx_gpt_writeb (void *opaque
,
1256 target_phys_addr_t addr
, uint32_t value
)
1259 printf("%s: addr " TARGET_FMT_plx
" val %08" PRIx32
"\n", __func__
, addr
,
1262 /* XXX: generate a bus fault */
1265 static uint32_t ppc4xx_gpt_readw (void *opaque
, target_phys_addr_t addr
)
1268 printf("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
1270 /* XXX: generate a bus fault */
1274 static void ppc4xx_gpt_writew (void *opaque
,
1275 target_phys_addr_t addr
, uint32_t value
)
1278 printf("%s: addr " TARGET_FMT_plx
" val %08" PRIx32
"\n", __func__
, addr
,
1281 /* XXX: generate a bus fault */
1284 static int ppc4xx_gpt_compare (ppc4xx_gpt_t
*gpt
, int n
)
1290 static void ppc4xx_gpt_set_output (ppc4xx_gpt_t
*gpt
, int n
, int level
)
1295 static void ppc4xx_gpt_set_outputs (ppc4xx_gpt_t
*gpt
)
1301 for (i
= 0; i
< 5; i
++) {
1302 if (gpt
->oe
& mask
) {
1303 /* Output is enabled */
1304 if (ppc4xx_gpt_compare(gpt
, i
)) {
1305 /* Comparison is OK */
1306 ppc4xx_gpt_set_output(gpt
, i
, gpt
->ol
& mask
);
1308 /* Comparison is KO */
1309 ppc4xx_gpt_set_output(gpt
, i
, gpt
->ol
& mask
? 0 : 1);
1316 static void ppc4xx_gpt_set_irqs (ppc4xx_gpt_t
*gpt
)
1322 for (i
= 0; i
< 5; i
++) {
1323 if (gpt
->is
& gpt
->im
& mask
)
1324 qemu_irq_raise(gpt
->irqs
[i
]);
1326 qemu_irq_lower(gpt
->irqs
[i
]);
1331 static void ppc4xx_gpt_compute_timer (ppc4xx_gpt_t
*gpt
)
1336 static uint32_t ppc4xx_gpt_readl (void *opaque
, target_phys_addr_t addr
)
1343 printf("%s: addr " TARGET_FMT_plx
"\n", __func__
, addr
);
1348 /* Time base counter */
1349 ret
= muldiv64(qemu_get_clock(vm_clock
) + gpt
->tb_offset
,
1350 gpt
->tb_freq
, get_ticks_per_sec());
1361 /* Interrupt mask */
1366 /* Interrupt status */
1370 /* Interrupt enable */
1375 idx
= (addr
- 0x80) >> 2;
1376 ret
= gpt
->comp
[idx
];
1380 idx
= (addr
- 0xC0) >> 2;
1381 ret
= gpt
->mask
[idx
];
1391 static void ppc4xx_gpt_writel (void *opaque
,
1392 target_phys_addr_t addr
, uint32_t value
)
1398 printf("%s: addr " TARGET_FMT_plx
" val %08" PRIx32
"\n", __func__
, addr
,
1404 /* Time base counter */
1405 gpt
->tb_offset
= muldiv64(value
, get_ticks_per_sec(), gpt
->tb_freq
)
1406 - qemu_get_clock(vm_clock
);
1407 ppc4xx_gpt_compute_timer(gpt
);
1411 gpt
->oe
= value
& 0xF8000000;
1412 ppc4xx_gpt_set_outputs(gpt
);
1416 gpt
->ol
= value
& 0xF8000000;
1417 ppc4xx_gpt_set_outputs(gpt
);
1420 /* Interrupt mask */
1421 gpt
->im
= value
& 0x0000F800;
1424 /* Interrupt status set */
1425 gpt
->is
|= value
& 0x0000F800;
1426 ppc4xx_gpt_set_irqs(gpt
);
1429 /* Interrupt status clear */
1430 gpt
->is
&= ~(value
& 0x0000F800);
1431 ppc4xx_gpt_set_irqs(gpt
);
1434 /* Interrupt enable */
1435 gpt
->ie
= value
& 0x0000F800;
1436 ppc4xx_gpt_set_irqs(gpt
);
1440 idx
= (addr
- 0x80) >> 2;
1441 gpt
->comp
[idx
] = value
& 0xF8000000;
1442 ppc4xx_gpt_compute_timer(gpt
);
1446 idx
= (addr
- 0xC0) >> 2;
1447 gpt
->mask
[idx
] = value
& 0xF8000000;
1448 ppc4xx_gpt_compute_timer(gpt
);
1453 static CPUReadMemoryFunc
* const gpt_read
[] = {
1459 static CPUWriteMemoryFunc
* const gpt_write
[] = {
1465 static void ppc4xx_gpt_cb (void *opaque
)
1470 ppc4xx_gpt_set_irqs(gpt
);
1471 ppc4xx_gpt_set_outputs(gpt
);
1472 ppc4xx_gpt_compute_timer(gpt
);
1475 static void ppc4xx_gpt_reset (void *opaque
)
1481 qemu_del_timer(gpt
->timer
);
1482 gpt
->oe
= 0x00000000;
1483 gpt
->ol
= 0x00000000;
1484 gpt
->im
= 0x00000000;
1485 gpt
->is
= 0x00000000;
1486 gpt
->ie
= 0x00000000;
1487 for (i
= 0; i
< 5; i
++) {
1488 gpt
->comp
[i
] = 0x00000000;
1489 gpt
->mask
[i
] = 0x00000000;
1493 static void ppc4xx_gpt_init(target_phys_addr_t base
, qemu_irq irqs
[5])
1499 gpt
= qemu_mallocz(sizeof(ppc4xx_gpt_t
));
1500 for (i
= 0; i
< 5; i
++) {
1501 gpt
->irqs
[i
] = irqs
[i
];
1503 gpt
->timer
= qemu_new_timer(vm_clock
, &ppc4xx_gpt_cb
, gpt
);
1505 printf("%s: offset " TARGET_FMT_plx
"\n", __func__
, base
);
1507 io
= cpu_register_io_memory(gpt_read
, gpt_write
, gpt
, DEVICE_NATIVE_ENDIAN
);
1508 cpu_register_physical_memory(base
, 0x0d4, io
);
1509 qemu_register_reset(ppc4xx_gpt_reset
, gpt
);
1512 /*****************************************************************************/
1518 MAL0_TXCASR
= 0x184,
1519 MAL0_TXCARR
= 0x185,
1520 MAL0_TXEOBISR
= 0x186,
1521 MAL0_TXDEIR
= 0x187,
1522 MAL0_RXCASR
= 0x190,
1523 MAL0_RXCARR
= 0x191,
1524 MAL0_RXEOBISR
= 0x192,
1525 MAL0_RXDEIR
= 0x193,
1526 MAL0_TXCTP0R
= 0x1A0,
1527 MAL0_TXCTP1R
= 0x1A1,
1528 MAL0_TXCTP2R
= 0x1A2,
1529 MAL0_TXCTP3R
= 0x1A3,
1530 MAL0_RXCTP0R
= 0x1C0,
1531 MAL0_RXCTP1R
= 0x1C1,
1536 typedef struct ppc40x_mal_t ppc40x_mal_t
;
1537 struct ppc40x_mal_t
{
1555 static void ppc40x_mal_reset (void *opaque
);
1557 static uint32_t dcr_read_mal (void *opaque
, int dcrn
)
1580 ret
= mal
->txeobisr
;
1592 ret
= mal
->rxeobisr
;
1598 ret
= mal
->txctpr
[0];
1601 ret
= mal
->txctpr
[1];
1604 ret
= mal
->txctpr
[2];
1607 ret
= mal
->txctpr
[3];
1610 ret
= mal
->rxctpr
[0];
1613 ret
= mal
->rxctpr
[1];
1629 static void dcr_write_mal (void *opaque
, int dcrn
, uint32_t val
)
1637 if (val
& 0x80000000)
1638 ppc40x_mal_reset(mal
);
1639 mal
->cfg
= val
& 0x00FFC087;
1646 mal
->ier
= val
& 0x0000001F;
1649 mal
->txcasr
= val
& 0xF0000000;
1652 mal
->txcarr
= val
& 0xF0000000;
1656 mal
->txeobisr
&= ~val
;
1660 mal
->txdeir
&= ~val
;
1663 mal
->rxcasr
= val
& 0xC0000000;
1666 mal
->rxcarr
= val
& 0xC0000000;
1670 mal
->rxeobisr
&= ~val
;
1674 mal
->rxdeir
&= ~val
;
1688 mal
->txctpr
[idx
] = val
;
1696 mal
->rxctpr
[idx
] = val
;
1700 goto update_rx_size
;
1704 mal
->rcbs
[idx
] = val
& 0x000000FF;
1709 static void ppc40x_mal_reset (void *opaque
)
1714 mal
->cfg
= 0x0007C000;
1715 mal
->esr
= 0x00000000;
1716 mal
->ier
= 0x00000000;
1717 mal
->rxcasr
= 0x00000000;
1718 mal
->rxdeir
= 0x00000000;
1719 mal
->rxeobisr
= 0x00000000;
1720 mal
->txcasr
= 0x00000000;
1721 mal
->txdeir
= 0x00000000;
1722 mal
->txeobisr
= 0x00000000;
1725 static void ppc405_mal_init(CPUState
*env
, qemu_irq irqs
[4])
1730 mal
= qemu_mallocz(sizeof(ppc40x_mal_t
));
1731 for (i
= 0; i
< 4; i
++)
1732 mal
->irqs
[i
] = irqs
[i
];
1733 qemu_register_reset(&ppc40x_mal_reset
, mal
);
1734 ppc_dcr_register(env
, MAL0_CFG
,
1735 mal
, &dcr_read_mal
, &dcr_write_mal
);
1736 ppc_dcr_register(env
, MAL0_ESR
,
1737 mal
, &dcr_read_mal
, &dcr_write_mal
);
1738 ppc_dcr_register(env
, MAL0_IER
,
1739 mal
, &dcr_read_mal
, &dcr_write_mal
);
1740 ppc_dcr_register(env
, MAL0_TXCASR
,
1741 mal
, &dcr_read_mal
, &dcr_write_mal
);
1742 ppc_dcr_register(env
, MAL0_TXCARR
,
1743 mal
, &dcr_read_mal
, &dcr_write_mal
);
1744 ppc_dcr_register(env
, MAL0_TXEOBISR
,
1745 mal
, &dcr_read_mal
, &dcr_write_mal
);
1746 ppc_dcr_register(env
, MAL0_TXDEIR
,
1747 mal
, &dcr_read_mal
, &dcr_write_mal
);
1748 ppc_dcr_register(env
, MAL0_RXCASR
,
1749 mal
, &dcr_read_mal
, &dcr_write_mal
);
1750 ppc_dcr_register(env
, MAL0_RXCARR
,
1751 mal
, &dcr_read_mal
, &dcr_write_mal
);
1752 ppc_dcr_register(env
, MAL0_RXEOBISR
,
1753 mal
, &dcr_read_mal
, &dcr_write_mal
);
1754 ppc_dcr_register(env
, MAL0_RXDEIR
,
1755 mal
, &dcr_read_mal
, &dcr_write_mal
);
1756 ppc_dcr_register(env
, MAL0_TXCTP0R
,
1757 mal
, &dcr_read_mal
, &dcr_write_mal
);
1758 ppc_dcr_register(env
, MAL0_TXCTP1R
,
1759 mal
, &dcr_read_mal
, &dcr_write_mal
);
1760 ppc_dcr_register(env
, MAL0_TXCTP2R
,
1761 mal
, &dcr_read_mal
, &dcr_write_mal
);
1762 ppc_dcr_register(env
, MAL0_TXCTP3R
,
1763 mal
, &dcr_read_mal
, &dcr_write_mal
);
1764 ppc_dcr_register(env
, MAL0_RXCTP0R
,
1765 mal
, &dcr_read_mal
, &dcr_write_mal
);
1766 ppc_dcr_register(env
, MAL0_RXCTP1R
,
1767 mal
, &dcr_read_mal
, &dcr_write_mal
);
1768 ppc_dcr_register(env
, MAL0_RCBS0
,
1769 mal
, &dcr_read_mal
, &dcr_write_mal
);
1770 ppc_dcr_register(env
, MAL0_RCBS1
,
1771 mal
, &dcr_read_mal
, &dcr_write_mal
);
1774 /*****************************************************************************/
1776 void ppc40x_core_reset (CPUState
*env
)
1780 printf("Reset PowerPC core\n");
1781 env
->interrupt_request
|= CPU_INTERRUPT_EXITTB
;
1786 qemu_system_reset_request();
1788 dbsr
= env
->spr
[SPR_40x_DBSR
];
1789 dbsr
&= ~0x00000300;
1791 env
->spr
[SPR_40x_DBSR
] = dbsr
;
1794 void ppc40x_chip_reset (CPUState
*env
)
1798 printf("Reset PowerPC chip\n");
1799 env
->interrupt_request
|= CPU_INTERRUPT_EXITTB
;
1804 qemu_system_reset_request();
1806 /* XXX: TODO reset all internal peripherals */
1807 dbsr
= env
->spr
[SPR_40x_DBSR
];
1808 dbsr
&= ~0x00000300;
1810 env
->spr
[SPR_40x_DBSR
] = dbsr
;
1813 void ppc40x_system_reset (CPUState
*env
)
1815 printf("Reset PowerPC system\n");
1816 qemu_system_reset_request();
1819 void store_40x_dbcr0 (CPUState
*env
, uint32_t val
)
1821 switch ((val
>> 28) & 0x3) {
1827 ppc40x_core_reset(env
);
1831 ppc40x_chip_reset(env
);
1835 ppc40x_system_reset(env
);
1840 /*****************************************************************************/
1843 PPC405CR_CPC0_PLLMR
= 0x0B0,
1844 PPC405CR_CPC0_CR0
= 0x0B1,
1845 PPC405CR_CPC0_CR1
= 0x0B2,
1846 PPC405CR_CPC0_PSR
= 0x0B4,
1847 PPC405CR_CPC0_JTAGID
= 0x0B5,
1848 PPC405CR_CPC0_ER
= 0x0B9,
1849 PPC405CR_CPC0_FR
= 0x0BA,
1850 PPC405CR_CPC0_SR
= 0x0BB,
1854 PPC405CR_CPU_CLK
= 0,
1855 PPC405CR_TMR_CLK
= 1,
1856 PPC405CR_PLB_CLK
= 2,
1857 PPC405CR_SDRAM_CLK
= 3,
1858 PPC405CR_OPB_CLK
= 4,
1859 PPC405CR_EXT_CLK
= 5,
1860 PPC405CR_UART_CLK
= 6,
1861 PPC405CR_CLK_NB
= 7,
1864 typedef struct ppc405cr_cpc_t ppc405cr_cpc_t
;
1865 struct ppc405cr_cpc_t
{
1866 clk_setup_t clk_setup
[PPC405CR_CLK_NB
];
1877 static void ppc405cr_clk_setup (ppc405cr_cpc_t
*cpc
)
1879 uint64_t VCO_out
, PLL_out
;
1880 uint32_t CPU_clk
, TMR_clk
, SDRAM_clk
, PLB_clk
, OPB_clk
, EXT_clk
, UART_clk
;
1883 D0
= ((cpc
->pllmr
>> 26) & 0x3) + 1; /* CBDV */
1884 if (cpc
->pllmr
& 0x80000000) {
1885 D1
= (((cpc
->pllmr
>> 20) - 1) & 0xF) + 1; /* FBDV */
1886 D2
= 8 - ((cpc
->pllmr
>> 16) & 0x7); /* FWDVA */
1888 VCO_out
= cpc
->sysclk
* M
;
1889 if (VCO_out
< 400000000 || VCO_out
> 800000000) {
1890 /* PLL cannot lock */
1891 cpc
->pllmr
&= ~0x80000000;
1894 PLL_out
= VCO_out
/ D2
;
1899 PLL_out
= cpc
->sysclk
* M
;
1902 if (cpc
->cr1
& 0x00800000)
1903 TMR_clk
= cpc
->sysclk
; /* Should have a separate clock */
1906 PLB_clk
= CPU_clk
/ D0
;
1907 SDRAM_clk
= PLB_clk
;
1908 D0
= ((cpc
->pllmr
>> 10) & 0x3) + 1;
1909 OPB_clk
= PLB_clk
/ D0
;
1910 D0
= ((cpc
->pllmr
>> 24) & 0x3) + 2;
1911 EXT_clk
= PLB_clk
/ D0
;
1912 D0
= ((cpc
->cr0
>> 1) & 0x1F) + 1;
1913 UART_clk
= CPU_clk
/ D0
;
1914 /* Setup CPU clocks */
1915 clk_setup(&cpc
->clk_setup
[PPC405CR_CPU_CLK
], CPU_clk
);
1916 /* Setup time-base clock */
1917 clk_setup(&cpc
->clk_setup
[PPC405CR_TMR_CLK
], TMR_clk
);
1918 /* Setup PLB clock */
1919 clk_setup(&cpc
->clk_setup
[PPC405CR_PLB_CLK
], PLB_clk
);
1920 /* Setup SDRAM clock */
1921 clk_setup(&cpc
->clk_setup
[PPC405CR_SDRAM_CLK
], SDRAM_clk
);
1922 /* Setup OPB clock */
1923 clk_setup(&cpc
->clk_setup
[PPC405CR_OPB_CLK
], OPB_clk
);
1924 /* Setup external clock */
1925 clk_setup(&cpc
->clk_setup
[PPC405CR_EXT_CLK
], EXT_clk
);
1926 /* Setup UART clock */
1927 clk_setup(&cpc
->clk_setup
[PPC405CR_UART_CLK
], UART_clk
);
1930 static uint32_t dcr_read_crcpc (void *opaque
, int dcrn
)
1932 ppc405cr_cpc_t
*cpc
;
1937 case PPC405CR_CPC0_PLLMR
:
1940 case PPC405CR_CPC0_CR0
:
1943 case PPC405CR_CPC0_CR1
:
1946 case PPC405CR_CPC0_PSR
:
1949 case PPC405CR_CPC0_JTAGID
:
1952 case PPC405CR_CPC0_ER
:
1955 case PPC405CR_CPC0_FR
:
1958 case PPC405CR_CPC0_SR
:
1959 ret
= ~(cpc
->er
| cpc
->fr
) & 0xFFFF0000;
1962 /* Avoid gcc warning */
1970 static void dcr_write_crcpc (void *opaque
, int dcrn
, uint32_t val
)
1972 ppc405cr_cpc_t
*cpc
;
1976 case PPC405CR_CPC0_PLLMR
:
1977 cpc
->pllmr
= val
& 0xFFF77C3F;
1979 case PPC405CR_CPC0_CR0
:
1980 cpc
->cr0
= val
& 0x0FFFFFFE;
1982 case PPC405CR_CPC0_CR1
:
1983 cpc
->cr1
= val
& 0x00800000;
1985 case PPC405CR_CPC0_PSR
:
1988 case PPC405CR_CPC0_JTAGID
:
1991 case PPC405CR_CPC0_ER
:
1992 cpc
->er
= val
& 0xBFFC0000;
1994 case PPC405CR_CPC0_FR
:
1995 cpc
->fr
= val
& 0xBFFC0000;
1997 case PPC405CR_CPC0_SR
:
2003 static void ppc405cr_cpc_reset (void *opaque
)
2005 ppc405cr_cpc_t
*cpc
;
2009 /* Compute PLLMR value from PSR settings */
2010 cpc
->pllmr
= 0x80000000;
2012 switch ((cpc
->psr
>> 30) & 3) {
2015 cpc
->pllmr
&= ~0x80000000;
2019 cpc
->pllmr
|= 5 << 16;
2023 cpc
->pllmr
|= 4 << 16;
2027 cpc
->pllmr
|= 2 << 16;
2031 D
= (cpc
->psr
>> 28) & 3;
2032 cpc
->pllmr
|= (D
+ 1) << 20;
2034 D
= (cpc
->psr
>> 25) & 7;
2049 D
= (cpc
->psr
>> 23) & 3;
2050 cpc
->pllmr
|= D
<< 26;
2052 D
= (cpc
->psr
>> 21) & 3;
2053 cpc
->pllmr
|= D
<< 10;
2055 D
= (cpc
->psr
>> 17) & 3;
2056 cpc
->pllmr
|= D
<< 24;
2057 cpc
->cr0
= 0x0000003C;
2058 cpc
->cr1
= 0x2B0D8800;
2059 cpc
->er
= 0x00000000;
2060 cpc
->fr
= 0x00000000;
2061 ppc405cr_clk_setup(cpc
);
2064 static void ppc405cr_clk_init (ppc405cr_cpc_t
*cpc
)
2068 /* XXX: this should be read from IO pins */
2069 cpc
->psr
= 0x00000000; /* 8 bits ROM */
2071 D
= 0x2; /* Divide by 4 */
2072 cpc
->psr
|= D
<< 30;
2074 D
= 0x1; /* Divide by 2 */
2075 cpc
->psr
|= D
<< 28;
2077 D
= 0x1; /* Divide by 2 */
2078 cpc
->psr
|= D
<< 23;
2080 D
= 0x5; /* M = 16 */
2081 cpc
->psr
|= D
<< 25;
2083 D
= 0x1; /* Divide by 2 */
2084 cpc
->psr
|= D
<< 21;
2086 D
= 0x2; /* Divide by 4 */
2087 cpc
->psr
|= D
<< 17;
2090 static void ppc405cr_cpc_init (CPUState
*env
, clk_setup_t clk_setup
[7],
2093 ppc405cr_cpc_t
*cpc
;
2095 cpc
= qemu_mallocz(sizeof(ppc405cr_cpc_t
));
2096 memcpy(cpc
->clk_setup
, clk_setup
,
2097 PPC405CR_CLK_NB
* sizeof(clk_setup_t
));
2098 cpc
->sysclk
= sysclk
;
2099 cpc
->jtagid
= 0x42051049;
2100 ppc_dcr_register(env
, PPC405CR_CPC0_PSR
, cpc
,
2101 &dcr_read_crcpc
, &dcr_write_crcpc
);
2102 ppc_dcr_register(env
, PPC405CR_CPC0_CR0
, cpc
,
2103 &dcr_read_crcpc
, &dcr_write_crcpc
);
2104 ppc_dcr_register(env
, PPC405CR_CPC0_CR1
, cpc
,
2105 &dcr_read_crcpc
, &dcr_write_crcpc
);
2106 ppc_dcr_register(env
, PPC405CR_CPC0_JTAGID
, cpc
,
2107 &dcr_read_crcpc
, &dcr_write_crcpc
);
2108 ppc_dcr_register(env
, PPC405CR_CPC0_PLLMR
, cpc
,
2109 &dcr_read_crcpc
, &dcr_write_crcpc
);
2110 ppc_dcr_register(env
, PPC405CR_CPC0_ER
, cpc
,
2111 &dcr_read_crcpc
, &dcr_write_crcpc
);
2112 ppc_dcr_register(env
, PPC405CR_CPC0_FR
, cpc
,
2113 &dcr_read_crcpc
, &dcr_write_crcpc
);
2114 ppc_dcr_register(env
, PPC405CR_CPC0_SR
, cpc
,
2115 &dcr_read_crcpc
, &dcr_write_crcpc
);
2116 ppc405cr_clk_init(cpc
);
2117 qemu_register_reset(ppc405cr_cpc_reset
, cpc
);
2120 CPUState
*ppc405cr_init (target_phys_addr_t ram_bases
[4],
2121 target_phys_addr_t ram_sizes
[4],
2122 uint32_t sysclk
, qemu_irq
**picp
,
2125 clk_setup_t clk_setup
[PPC405CR_CLK_NB
];
2126 qemu_irq dma_irqs
[4];
2128 qemu_irq
*pic
, *irqs
;
2130 memset(clk_setup
, 0, sizeof(clk_setup
));
2131 env
= ppc4xx_init("405cr", &clk_setup
[PPC405CR_CPU_CLK
],
2132 &clk_setup
[PPC405CR_TMR_CLK
], sysclk
);
2133 /* Memory mapped devices registers */
2135 ppc4xx_plb_init(env
);
2136 /* PLB to OPB bridge */
2137 ppc4xx_pob_init(env
);
2139 ppc4xx_opba_init(0xef600600);
2140 /* Universal interrupt controller */
2141 irqs
= qemu_mallocz(sizeof(qemu_irq
) * PPCUIC_OUTPUT_NB
);
2142 irqs
[PPCUIC_OUTPUT_INT
] =
2143 ((qemu_irq
*)env
->irq_inputs
)[PPC40x_INPUT_INT
];
2144 irqs
[PPCUIC_OUTPUT_CINT
] =
2145 ((qemu_irq
*)env
->irq_inputs
)[PPC40x_INPUT_CINT
];
2146 pic
= ppcuic_init(env
, irqs
, 0x0C0, 0, 1);
2148 /* SDRAM controller */
2149 ppc4xx_sdram_init(env
, pic
[14], 1, ram_bases
, ram_sizes
, do_init
);
2150 /* External bus controller */
2151 ppc405_ebc_init(env
);
2152 /* DMA controller */
2153 dma_irqs
[0] = pic
[26];
2154 dma_irqs
[1] = pic
[25];
2155 dma_irqs
[2] = pic
[24];
2156 dma_irqs
[3] = pic
[23];
2157 ppc405_dma_init(env
, dma_irqs
);
2159 if (serial_hds
[0] != NULL
) {
2160 serial_mm_init(0xef600300, 0, pic
[0], PPC_SERIAL_MM_BAUDBASE
,
2161 serial_hds
[0], 1, 1);
2163 if (serial_hds
[1] != NULL
) {
2164 serial_mm_init(0xef600400, 0, pic
[1], PPC_SERIAL_MM_BAUDBASE
,
2165 serial_hds
[1], 1, 1);
2167 /* IIC controller */
2168 ppc405_i2c_init(0xef600500, pic
[2]);
2170 ppc405_gpio_init(0xef600700);
2172 ppc405cr_cpc_init(env
, clk_setup
, sysclk
);
2177 /*****************************************************************************/
2181 PPC405EP_CPC0_PLLMR0
= 0x0F0,
2182 PPC405EP_CPC0_BOOT
= 0x0F1,
2183 PPC405EP_CPC0_EPCTL
= 0x0F3,
2184 PPC405EP_CPC0_PLLMR1
= 0x0F4,
2185 PPC405EP_CPC0_UCR
= 0x0F5,
2186 PPC405EP_CPC0_SRR
= 0x0F6,
2187 PPC405EP_CPC0_JTAGID
= 0x0F7,
2188 PPC405EP_CPC0_PCI
= 0x0F9,
2190 PPC405EP_CPC0_ER
= xxx
,
2191 PPC405EP_CPC0_FR
= xxx
,
2192 PPC405EP_CPC0_SR
= xxx
,
2197 PPC405EP_CPU_CLK
= 0,
2198 PPC405EP_PLB_CLK
= 1,
2199 PPC405EP_OPB_CLK
= 2,
2200 PPC405EP_EBC_CLK
= 3,
2201 PPC405EP_MAL_CLK
= 4,
2202 PPC405EP_PCI_CLK
= 5,
2203 PPC405EP_UART0_CLK
= 6,
2204 PPC405EP_UART1_CLK
= 7,
2205 PPC405EP_CLK_NB
= 8,
2208 typedef struct ppc405ep_cpc_t ppc405ep_cpc_t
;
2209 struct ppc405ep_cpc_t
{
2211 clk_setup_t clk_setup
[PPC405EP_CLK_NB
];
2219 /* Clock and power management */
2225 static void ppc405ep_compute_clocks (ppc405ep_cpc_t
*cpc
)
2227 uint32_t CPU_clk
, PLB_clk
, OPB_clk
, EBC_clk
, MAL_clk
, PCI_clk
;
2228 uint32_t UART0_clk
, UART1_clk
;
2229 uint64_t VCO_out
, PLL_out
;
2233 if ((cpc
->pllmr
[1] & 0x80000000) && !(cpc
->pllmr
[1] & 0x40000000)) {
2234 M
= (((cpc
->pllmr
[1] >> 20) - 1) & 0xF) + 1; /* FBMUL */
2235 #ifdef DEBUG_CLOCKS_LL
2236 printf("FBMUL %01" PRIx32
" %d\n", (cpc
->pllmr
[1] >> 20) & 0xF, M
);
2238 D
= 8 - ((cpc
->pllmr
[1] >> 16) & 0x7); /* FWDA */
2239 #ifdef DEBUG_CLOCKS_LL
2240 printf("FWDA %01" PRIx32
" %d\n", (cpc
->pllmr
[1] >> 16) & 0x7, D
);
2242 VCO_out
= cpc
->sysclk
* M
* D
;
2243 if (VCO_out
< 500000000UL || VCO_out
> 1000000000UL) {
2244 /* Error - unlock the PLL */
2245 printf("VCO out of range %" PRIu64
"\n", VCO_out
);
2247 cpc
->pllmr
[1] &= ~0x80000000;
2251 PLL_out
= VCO_out
/ D
;
2252 /* Pretend the PLL is locked */
2253 cpc
->boot
|= 0x00000001;
2258 PLL_out
= cpc
->sysclk
;
2259 if (cpc
->pllmr
[1] & 0x40000000) {
2260 /* Pretend the PLL is not locked */
2261 cpc
->boot
&= ~0x00000001;
2264 /* Now, compute all other clocks */
2265 D
= ((cpc
->pllmr
[0] >> 20) & 0x3) + 1; /* CCDV */
2266 #ifdef DEBUG_CLOCKS_LL
2267 printf("CCDV %01" PRIx32
" %d\n", (cpc
->pllmr
[0] >> 20) & 0x3, D
);
2269 CPU_clk
= PLL_out
/ D
;
2270 D
= ((cpc
->pllmr
[0] >> 16) & 0x3) + 1; /* CBDV */
2271 #ifdef DEBUG_CLOCKS_LL
2272 printf("CBDV %01" PRIx32
" %d\n", (cpc
->pllmr
[0] >> 16) & 0x3, D
);
2274 PLB_clk
= CPU_clk
/ D
;
2275 D
= ((cpc
->pllmr
[0] >> 12) & 0x3) + 1; /* OPDV */
2276 #ifdef DEBUG_CLOCKS_LL
2277 printf("OPDV %01" PRIx32
" %d\n", (cpc
->pllmr
[0] >> 12) & 0x3, D
);
2279 OPB_clk
= PLB_clk
/ D
;
2280 D
= ((cpc
->pllmr
[0] >> 8) & 0x3) + 2; /* EPDV */
2281 #ifdef DEBUG_CLOCKS_LL
2282 printf("EPDV %01" PRIx32
" %d\n", (cpc
->pllmr
[0] >> 8) & 0x3, D
);
2284 EBC_clk
= PLB_clk
/ D
;
2285 D
= ((cpc
->pllmr
[0] >> 4) & 0x3) + 1; /* MPDV */
2286 #ifdef DEBUG_CLOCKS_LL
2287 printf("MPDV %01" PRIx32
" %d\n", (cpc
->pllmr
[0] >> 4) & 0x3, D
);
2289 MAL_clk
= PLB_clk
/ D
;
2290 D
= (cpc
->pllmr
[0] & 0x3) + 1; /* PPDV */
2291 #ifdef DEBUG_CLOCKS_LL
2292 printf("PPDV %01" PRIx32
" %d\n", cpc
->pllmr
[0] & 0x3, D
);
2294 PCI_clk
= PLB_clk
/ D
;
2295 D
= ((cpc
->ucr
- 1) & 0x7F) + 1; /* U0DIV */
2296 #ifdef DEBUG_CLOCKS_LL
2297 printf("U0DIV %01" PRIx32
" %d\n", cpc
->ucr
& 0x7F, D
);
2299 UART0_clk
= PLL_out
/ D
;
2300 D
= (((cpc
->ucr
>> 8) - 1) & 0x7F) + 1; /* U1DIV */
2301 #ifdef DEBUG_CLOCKS_LL
2302 printf("U1DIV %01" PRIx32
" %d\n", (cpc
->ucr
>> 8) & 0x7F, D
);
2304 UART1_clk
= PLL_out
/ D
;
2306 printf("Setup PPC405EP clocks - sysclk %" PRIu32
" VCO %" PRIu64
2307 " PLL out %" PRIu64
" Hz\n", cpc
->sysclk
, VCO_out
, PLL_out
);
2308 printf("CPU %" PRIu32
" PLB %" PRIu32
" OPB %" PRIu32
" EBC %" PRIu32
2309 " MAL %" PRIu32
" PCI %" PRIu32
" UART0 %" PRIu32
2310 " UART1 %" PRIu32
"\n",
2311 CPU_clk
, PLB_clk
, OPB_clk
, EBC_clk
, MAL_clk
, PCI_clk
,
2312 UART0_clk
, UART1_clk
);
2314 /* Setup CPU clocks */
2315 clk_setup(&cpc
->clk_setup
[PPC405EP_CPU_CLK
], CPU_clk
);
2316 /* Setup PLB clock */
2317 clk_setup(&cpc
->clk_setup
[PPC405EP_PLB_CLK
], PLB_clk
);
2318 /* Setup OPB clock */
2319 clk_setup(&cpc
->clk_setup
[PPC405EP_OPB_CLK
], OPB_clk
);
2320 /* Setup external clock */
2321 clk_setup(&cpc
->clk_setup
[PPC405EP_EBC_CLK
], EBC_clk
);
2322 /* Setup MAL clock */
2323 clk_setup(&cpc
->clk_setup
[PPC405EP_MAL_CLK
], MAL_clk
);
2324 /* Setup PCI clock */
2325 clk_setup(&cpc
->clk_setup
[PPC405EP_PCI_CLK
], PCI_clk
);
2326 /* Setup UART0 clock */
2327 clk_setup(&cpc
->clk_setup
[PPC405EP_UART0_CLK
], UART0_clk
);
2328 /* Setup UART1 clock */
2329 clk_setup(&cpc
->clk_setup
[PPC405EP_UART1_CLK
], UART1_clk
);
2332 static uint32_t dcr_read_epcpc (void *opaque
, int dcrn
)
2334 ppc405ep_cpc_t
*cpc
;
2339 case PPC405EP_CPC0_BOOT
:
2342 case PPC405EP_CPC0_EPCTL
:
2345 case PPC405EP_CPC0_PLLMR0
:
2346 ret
= cpc
->pllmr
[0];
2348 case PPC405EP_CPC0_PLLMR1
:
2349 ret
= cpc
->pllmr
[1];
2351 case PPC405EP_CPC0_UCR
:
2354 case PPC405EP_CPC0_SRR
:
2357 case PPC405EP_CPC0_JTAGID
:
2360 case PPC405EP_CPC0_PCI
:
2364 /* Avoid gcc warning */
2372 static void dcr_write_epcpc (void *opaque
, int dcrn
, uint32_t val
)
2374 ppc405ep_cpc_t
*cpc
;
2378 case PPC405EP_CPC0_BOOT
:
2379 /* Read-only register */
2381 case PPC405EP_CPC0_EPCTL
:
2382 /* Don't care for now */
2383 cpc
->epctl
= val
& 0xC00000F3;
2385 case PPC405EP_CPC0_PLLMR0
:
2386 cpc
->pllmr
[0] = val
& 0x00633333;
2387 ppc405ep_compute_clocks(cpc
);
2389 case PPC405EP_CPC0_PLLMR1
:
2390 cpc
->pllmr
[1] = val
& 0xC0F73FFF;
2391 ppc405ep_compute_clocks(cpc
);
2393 case PPC405EP_CPC0_UCR
:
2394 /* UART control - don't care for now */
2395 cpc
->ucr
= val
& 0x003F7F7F;
2397 case PPC405EP_CPC0_SRR
:
2400 case PPC405EP_CPC0_JTAGID
:
2403 case PPC405EP_CPC0_PCI
:
2409 static void ppc405ep_cpc_reset (void *opaque
)
2411 ppc405ep_cpc_t
*cpc
= opaque
;
2413 cpc
->boot
= 0x00000010; /* Boot from PCI - IIC EEPROM disabled */
2414 cpc
->epctl
= 0x00000000;
2415 cpc
->pllmr
[0] = 0x00011010;
2416 cpc
->pllmr
[1] = 0x40000000;
2417 cpc
->ucr
= 0x00000000;
2418 cpc
->srr
= 0x00040000;
2419 cpc
->pci
= 0x00000000;
2420 cpc
->er
= 0x00000000;
2421 cpc
->fr
= 0x00000000;
2422 cpc
->sr
= 0x00000000;
2423 ppc405ep_compute_clocks(cpc
);
2426 /* XXX: sysclk should be between 25 and 100 MHz */
2427 static void ppc405ep_cpc_init (CPUState
*env
, clk_setup_t clk_setup
[8],
2430 ppc405ep_cpc_t
*cpc
;
2432 cpc
= qemu_mallocz(sizeof(ppc405ep_cpc_t
));
2433 memcpy(cpc
->clk_setup
, clk_setup
,
2434 PPC405EP_CLK_NB
* sizeof(clk_setup_t
));
2435 cpc
->jtagid
= 0x20267049;
2436 cpc
->sysclk
= sysclk
;
2437 qemu_register_reset(&ppc405ep_cpc_reset
, cpc
);
2438 ppc_dcr_register(env
, PPC405EP_CPC0_BOOT
, cpc
,
2439 &dcr_read_epcpc
, &dcr_write_epcpc
);
2440 ppc_dcr_register(env
, PPC405EP_CPC0_EPCTL
, cpc
,
2441 &dcr_read_epcpc
, &dcr_write_epcpc
);
2442 ppc_dcr_register(env
, PPC405EP_CPC0_PLLMR0
, cpc
,
2443 &dcr_read_epcpc
, &dcr_write_epcpc
);
2444 ppc_dcr_register(env
, PPC405EP_CPC0_PLLMR1
, cpc
,
2445 &dcr_read_epcpc
, &dcr_write_epcpc
);
2446 ppc_dcr_register(env
, PPC405EP_CPC0_UCR
, cpc
,
2447 &dcr_read_epcpc
, &dcr_write_epcpc
);
2448 ppc_dcr_register(env
, PPC405EP_CPC0_SRR
, cpc
,
2449 &dcr_read_epcpc
, &dcr_write_epcpc
);
2450 ppc_dcr_register(env
, PPC405EP_CPC0_JTAGID
, cpc
,
2451 &dcr_read_epcpc
, &dcr_write_epcpc
);
2452 ppc_dcr_register(env
, PPC405EP_CPC0_PCI
, cpc
,
2453 &dcr_read_epcpc
, &dcr_write_epcpc
);
2455 ppc_dcr_register(env
, PPC405EP_CPC0_ER
, cpc
,
2456 &dcr_read_epcpc
, &dcr_write_epcpc
);
2457 ppc_dcr_register(env
, PPC405EP_CPC0_FR
, cpc
,
2458 &dcr_read_epcpc
, &dcr_write_epcpc
);
2459 ppc_dcr_register(env
, PPC405EP_CPC0_SR
, cpc
,
2460 &dcr_read_epcpc
, &dcr_write_epcpc
);
2464 CPUState
*ppc405ep_init (target_phys_addr_t ram_bases
[2],
2465 target_phys_addr_t ram_sizes
[2],
2466 uint32_t sysclk
, qemu_irq
**picp
,
2469 clk_setup_t clk_setup
[PPC405EP_CLK_NB
], tlb_clk_setup
;
2470 qemu_irq dma_irqs
[4], gpt_irqs
[5], mal_irqs
[4];
2472 qemu_irq
*pic
, *irqs
;
2474 memset(clk_setup
, 0, sizeof(clk_setup
));
2476 env
= ppc4xx_init("405ep", &clk_setup
[PPC405EP_CPU_CLK
],
2477 &tlb_clk_setup
, sysclk
);
2478 clk_setup
[PPC405EP_CPU_CLK
].cb
= tlb_clk_setup
.cb
;
2479 clk_setup
[PPC405EP_CPU_CLK
].opaque
= tlb_clk_setup
.opaque
;
2480 /* Internal devices init */
2481 /* Memory mapped devices registers */
2483 ppc4xx_plb_init(env
);
2484 /* PLB to OPB bridge */
2485 ppc4xx_pob_init(env
);
2487 ppc4xx_opba_init(0xef600600);
2488 /* Universal interrupt controller */
2489 irqs
= qemu_mallocz(sizeof(qemu_irq
) * PPCUIC_OUTPUT_NB
);
2490 irqs
[PPCUIC_OUTPUT_INT
] =
2491 ((qemu_irq
*)env
->irq_inputs
)[PPC40x_INPUT_INT
];
2492 irqs
[PPCUIC_OUTPUT_CINT
] =
2493 ((qemu_irq
*)env
->irq_inputs
)[PPC40x_INPUT_CINT
];
2494 pic
= ppcuic_init(env
, irqs
, 0x0C0, 0, 1);
2496 /* SDRAM controller */
2497 /* XXX 405EP has no ECC interrupt */
2498 ppc4xx_sdram_init(env
, pic
[17], 2, ram_bases
, ram_sizes
, do_init
);
2499 /* External bus controller */
2500 ppc405_ebc_init(env
);
2501 /* DMA controller */
2502 dma_irqs
[0] = pic
[5];
2503 dma_irqs
[1] = pic
[6];
2504 dma_irqs
[2] = pic
[7];
2505 dma_irqs
[3] = pic
[8];
2506 ppc405_dma_init(env
, dma_irqs
);
2507 /* IIC controller */
2508 ppc405_i2c_init(0xef600500, pic
[2]);
2510 ppc405_gpio_init(0xef600700);
2512 if (serial_hds
[0] != NULL
) {
2513 serial_mm_init(0xef600300, 0, pic
[0], PPC_SERIAL_MM_BAUDBASE
,
2514 serial_hds
[0], 1, 1);
2516 if (serial_hds
[1] != NULL
) {
2517 serial_mm_init(0xef600400, 0, pic
[1], PPC_SERIAL_MM_BAUDBASE
,
2518 serial_hds
[1], 1, 1);
2521 ppc405_ocm_init(env
);
2523 gpt_irqs
[0] = pic
[19];
2524 gpt_irqs
[1] = pic
[20];
2525 gpt_irqs
[2] = pic
[21];
2526 gpt_irqs
[3] = pic
[22];
2527 gpt_irqs
[4] = pic
[23];
2528 ppc4xx_gpt_init(0xef600000, gpt_irqs
);
2530 /* Uses pic[3], pic[16], pic[18] */
2532 mal_irqs
[0] = pic
[11];
2533 mal_irqs
[1] = pic
[12];
2534 mal_irqs
[2] = pic
[13];
2535 mal_irqs
[3] = pic
[14];
2536 ppc405_mal_init(env
, mal_irqs
);
2538 /* Uses pic[9], pic[15], pic[17] */
2540 ppc405ep_cpc_init(env
, clk_setup
, sysclk
);