xref: /qemu/include/hw/arm/allwinner-r40.h (revision 2a02da74)
1 /*
2  * Allwinner R40/A40i/T3 System on Chip emulation
3  *
4  * Copyright (C) 2023 qianfan Zhao <qianfanguijin@163.com>
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef HW_ARM_ALLWINNER_R40_H
21 #define HW_ARM_ALLWINNER_R40_H
22 
23 #include "qom/object.h"
24 #include "hw/timer/allwinner-a10-pit.h"
25 #include "hw/ide/ahci.h"
26 #include "hw/intc/arm_gic.h"
27 #include "hw/sd/allwinner-sdhost.h"
28 #include "hw/misc/allwinner-r40-ccu.h"
29 #include "hw/misc/allwinner-r40-dramc.h"
30 #include "hw/misc/allwinner-sramc.h"
31 #include "hw/i2c/allwinner-i2c.h"
32 #include "hw/net/allwinner_emac.h"
33 #include "hw/net/allwinner-sun8i-emac.h"
34 #include "hw/usb/hcd-ohci.h"
35 #include "hw/usb/hcd-ehci.h"
36 #include "target/arm/cpu.h"
37 #include "sysemu/block-backend.h"
38 
39 enum {
40     AW_R40_DEV_SRAM_A1,
41     AW_R40_DEV_SRAM_A2,
42     AW_R40_DEV_SRAM_A3,
43     AW_R40_DEV_SRAM_A4,
44     AW_R40_DEV_SRAMC,
45     AW_R40_DEV_EMAC,
46     AW_R40_DEV_MMC0,
47     AW_R40_DEV_MMC1,
48     AW_R40_DEV_MMC2,
49     AW_R40_DEV_MMC3,
50     AW_R40_DEV_AHCI,
51     AW_R40_DEV_EHCI1,
52     AW_R40_DEV_OHCI1,
53     AW_R40_DEV_EHCI2,
54     AW_R40_DEV_OHCI2,
55     AW_R40_DEV_CCU,
56     AW_R40_DEV_PIT,
57     AW_R40_DEV_UART0,
58     AW_R40_DEV_UART1,
59     AW_R40_DEV_UART2,
60     AW_R40_DEV_UART3,
61     AW_R40_DEV_UART4,
62     AW_R40_DEV_UART5,
63     AW_R40_DEV_UART6,
64     AW_R40_DEV_UART7,
65     AW_R40_DEV_TWI0,
66     AW_R40_DEV_GMAC,
67     AW_R40_DEV_GIC_DIST,
68     AW_R40_DEV_GIC_CPU,
69     AW_R40_DEV_GIC_HYP,
70     AW_R40_DEV_GIC_VCPU,
71     AW_R40_DEV_SDRAM,
72     AW_R40_DEV_DRAMCOM,
73     AW_R40_DEV_DRAMCTL,
74     AW_R40_DEV_DRAMPHY,
75 };
76 
77 #define AW_R40_NUM_CPUS      (4)
78 
79 /**
80  * Allwinner R40 object model
81  * @{
82  */
83 
84 /** Object type for the Allwinner R40 SoC */
85 #define TYPE_AW_R40 "allwinner-r40"
86 
87 /** Convert input object to Allwinner R40 state object */
88 OBJECT_DECLARE_SIMPLE_TYPE(AwR40State, AW_R40)
89 
90 /** @} */
91 
92 /**
93  * Allwinner R40 object
94  *
95  * This struct contains the state of all the devices
96  * which are currently emulated by the R40 SoC code.
97  */
98 #define AW_R40_NUM_MMCS         4
99 #define AW_R40_NUM_USB          2
100 #define AW_R40_NUM_UARTS        8
101 
102 struct AwR40State {
103     /*< private >*/
104     DeviceState parent_obj;
105     /*< public >*/
106 
107     /** Physical base address for start of RAM */
108     hwaddr ram_addr;
109 
110     /** Total RAM size in megabytes */
111     uint32_t ram_size;
112 
113     ARMCPU cpus[AW_R40_NUM_CPUS];
114     const hwaddr *memmap;
115     AwSRAMCState sramc;
116     AwA10PITState timer;
117     AllwinnerAHCIState sata;
118     AwSdHostState mmc[AW_R40_NUM_MMCS];
119     EHCISysBusState ehci[AW_R40_NUM_USB];
120     OHCISysBusState ohci[AW_R40_NUM_USB];
121     AwR40ClockCtlState ccu;
122     AwR40DramCtlState dramc;
123     AWI2CState i2c0;
124     AwEmacState emac;
125     AwSun8iEmacState gmac;
126     GICState gic;
127     MemoryRegion sram_a1;
128     MemoryRegion sram_a2;
129     MemoryRegion sram_a3;
130     MemoryRegion sram_a4;
131 };
132 
133 /**
134  * Emulate Boot ROM firmware setup functionality.
135  *
136  * A real Allwinner R40 SoC contains a Boot ROM
137  * which is the first code that runs right after
138  * the SoC is powered on. The Boot ROM is responsible
139  * for loading user code (e.g. a bootloader) from any
140  * of the supported external devices and writing the
141  * downloaded code to internal SRAM. After loading the SoC
142  * begins executing the code written to SRAM.
143  *
144  * This function emulates the Boot ROM by copying 32 KiB
145  * of data from the given block device and writes it to
146  * the start of the first internal SRAM memory.
147  *
148  * @s: Allwinner R40 state object pointer
149  * @blk: Block backend device object pointer
150  * @unit: the mmc control's unit
151  */
152 bool allwinner_r40_bootrom_setup(AwR40State *s, BlockBackend *blk, int unit);
153 
154 #endif /* HW_ARM_ALLWINNER_R40_H */
155