xref: /openbmc/qemu/hw/arm/aspeed_ast27x0.c (revision 2f95279a)
1 /*
2  * ASPEED SoC 27x0 family
3  *
4  * Copyright (C) 2024 ASPEED Technology Inc.
5  *
6  * This code is licensed under the GPL version 2 or later.  See
7  * the COPYING file in the top-level directory.
8  *
9  * Implementation extracted from the AST2600 and adapted for AST27x0.
10  */
11 
12 #include "qemu/osdep.h"
13 #include "qapi/error.h"
14 #include "hw/misc/unimp.h"
15 #include "hw/arm/aspeed_soc.h"
16 #include "qemu/module.h"
17 #include "qemu/error-report.h"
18 #include "hw/i2c/aspeed_i2c.h"
19 #include "net/net.h"
20 #include "sysemu/sysemu.h"
21 #include "hw/intc/arm_gicv3.h"
22 #include "qapi/qmp/qlist.h"
23 #include "qemu/log.h"
24 
25 static const hwaddr aspeed_soc_ast2700_memmap[] = {
26     [ASPEED_DEV_SPI_BOOT]  =  0x400000000,
27     [ASPEED_DEV_SRAM]      =  0x10000000,
28     [ASPEED_DEV_SDMC]      =  0x12C00000,
29     [ASPEED_DEV_SCU]       =  0x12C02000,
30     [ASPEED_DEV_SCUIO]     =  0x14C02000,
31     [ASPEED_DEV_UART0]     =  0X14C33000,
32     [ASPEED_DEV_UART1]     =  0X14C33100,
33     [ASPEED_DEV_UART2]     =  0X14C33200,
34     [ASPEED_DEV_UART3]     =  0X14C33300,
35     [ASPEED_DEV_UART4]     =  0X12C1A000,
36     [ASPEED_DEV_UART5]     =  0X14C33400,
37     [ASPEED_DEV_UART6]     =  0X14C33500,
38     [ASPEED_DEV_UART7]     =  0X14C33600,
39     [ASPEED_DEV_UART8]     =  0X14C33700,
40     [ASPEED_DEV_UART9]     =  0X14C33800,
41     [ASPEED_DEV_UART10]    =  0X14C33900,
42     [ASPEED_DEV_UART11]    =  0X14C33A00,
43     [ASPEED_DEV_UART12]    =  0X14C33B00,
44     [ASPEED_DEV_WDT]       =  0x14C37000,
45     [ASPEED_DEV_VUART]     =  0X14C30000,
46     [ASPEED_DEV_FMC]       =  0x14000000,
47     [ASPEED_DEV_SPI0]      =  0x14010000,
48     [ASPEED_DEV_SPI1]      =  0x14020000,
49     [ASPEED_DEV_SPI2]      =  0x14030000,
50     [ASPEED_DEV_SDRAM]     =  0x400000000,
51     [ASPEED_DEV_MII1]      =  0x14040000,
52     [ASPEED_DEV_MII2]      =  0x14040008,
53     [ASPEED_DEV_MII3]      =  0x14040010,
54     [ASPEED_DEV_ETH1]      =  0x14050000,
55     [ASPEED_DEV_ETH2]      =  0x14060000,
56     [ASPEED_DEV_ETH3]      =  0x14070000,
57     [ASPEED_DEV_EMMC]      =  0x12090000,
58     [ASPEED_DEV_INTC]      =  0x12100000,
59     [ASPEED_DEV_SLI]       =  0x12C17000,
60     [ASPEED_DEV_SLIIO]     =  0x14C1E000,
61     [ASPEED_GIC_DIST]      =  0x12200000,
62     [ASPEED_GIC_REDIST]    =  0x12280000,
63 };
64 
65 #define AST2700_MAX_IRQ 288
66 
67 /* Shared Peripheral Interrupt values below are offset by -32 from datasheet */
68 static const int aspeed_soc_ast2700_irqmap[] = {
69     [ASPEED_DEV_UART0]     = 132,
70     [ASPEED_DEV_UART1]     = 132,
71     [ASPEED_DEV_UART2]     = 132,
72     [ASPEED_DEV_UART3]     = 132,
73     [ASPEED_DEV_UART4]     = 8,
74     [ASPEED_DEV_UART5]     = 132,
75     [ASPEED_DEV_UART6]     = 132,
76     [ASPEED_DEV_UART7]     = 132,
77     [ASPEED_DEV_UART8]     = 132,
78     [ASPEED_DEV_UART9]     = 132,
79     [ASPEED_DEV_UART10]    = 132,
80     [ASPEED_DEV_UART11]    = 132,
81     [ASPEED_DEV_UART12]    = 132,
82     [ASPEED_DEV_FMC]       = 131,
83     [ASPEED_DEV_SDMC]      = 0,
84     [ASPEED_DEV_SCU]       = 12,
85     [ASPEED_DEV_ADC]       = 130,
86     [ASPEED_DEV_XDMA]      = 5,
87     [ASPEED_DEV_EMMC]      = 15,
88     [ASPEED_DEV_GPIO]      = 11,
89     [ASPEED_DEV_GPIO_1_8V] = 130,
90     [ASPEED_DEV_RTC]       = 13,
91     [ASPEED_DEV_TIMER1]    = 16,
92     [ASPEED_DEV_TIMER2]    = 17,
93     [ASPEED_DEV_TIMER3]    = 18,
94     [ASPEED_DEV_TIMER4]    = 19,
95     [ASPEED_DEV_TIMER5]    = 20,
96     [ASPEED_DEV_TIMER6]    = 21,
97     [ASPEED_DEV_TIMER7]    = 22,
98     [ASPEED_DEV_TIMER8]    = 23,
99     [ASPEED_DEV_WDT]       = 131,
100     [ASPEED_DEV_PWM]       = 131,
101     [ASPEED_DEV_LPC]       = 128,
102     [ASPEED_DEV_IBT]       = 128,
103     [ASPEED_DEV_I2C]       = 130,
104     [ASPEED_DEV_PECI]      = 133,
105     [ASPEED_DEV_ETH1]      = 132,
106     [ASPEED_DEV_ETH2]      = 132,
107     [ASPEED_DEV_ETH3]      = 132,
108     [ASPEED_DEV_HACE]      = 4,
109     [ASPEED_DEV_KCS]       = 128,
110     [ASPEED_DEV_DP]        = 28,
111     [ASPEED_DEV_I3C]       = 131,
112 };
113 
114 /* GICINT 128 */
115 static const int aspeed_soc_ast2700_gic128_intcmap[] = {
116     [ASPEED_DEV_LPC]       = 0,
117     [ASPEED_DEV_IBT]       = 2,
118     [ASPEED_DEV_KCS]       = 4,
119 };
120 
121 /* GICINT 130 */
122 static const int aspeed_soc_ast2700_gic130_intcmap[] = {
123     [ASPEED_DEV_I2C]        = 0,
124     [ASPEED_DEV_ADC]        = 16,
125     [ASPEED_DEV_GPIO_1_8V]  = 18,
126 };
127 
128 /* GICINT 131 */
129 static const int aspeed_soc_ast2700_gic131_intcmap[] = {
130     [ASPEED_DEV_I3C]       = 0,
131     [ASPEED_DEV_WDT]       = 16,
132     [ASPEED_DEV_FMC]       = 25,
133     [ASPEED_DEV_PWM]       = 29,
134 };
135 
136 /* GICINT 132 */
137 static const int aspeed_soc_ast2700_gic132_intcmap[] = {
138     [ASPEED_DEV_ETH1]      = 0,
139     [ASPEED_DEV_ETH2]      = 1,
140     [ASPEED_DEV_ETH3]      = 2,
141     [ASPEED_DEV_UART0]     = 7,
142     [ASPEED_DEV_UART1]     = 8,
143     [ASPEED_DEV_UART2]     = 9,
144     [ASPEED_DEV_UART3]     = 10,
145     [ASPEED_DEV_UART5]     = 11,
146     [ASPEED_DEV_UART6]     = 12,
147     [ASPEED_DEV_UART7]     = 13,
148     [ASPEED_DEV_UART8]     = 14,
149     [ASPEED_DEV_UART9]     = 15,
150     [ASPEED_DEV_UART10]    = 16,
151     [ASPEED_DEV_UART11]    = 17,
152     [ASPEED_DEV_UART12]    = 18,
153 };
154 
155 /* GICINT 133 */
156 static const int aspeed_soc_ast2700_gic133_intcmap[] = {
157     [ASPEED_DEV_PECI]      = 4,
158 };
159 
160 /* GICINT 128 ~ 136 */
161 struct gic_intc_irq_info {
162     int irq;
163     const int *ptr;
164 };
165 
166 static const struct gic_intc_irq_info aspeed_soc_ast2700_gic_intcmap[] = {
167     {128,  aspeed_soc_ast2700_gic128_intcmap},
168     {129,  NULL},
169     {130,  aspeed_soc_ast2700_gic130_intcmap},
170     {131,  aspeed_soc_ast2700_gic131_intcmap},
171     {132,  aspeed_soc_ast2700_gic132_intcmap},
172     {133,  aspeed_soc_ast2700_gic133_intcmap},
173     {134,  NULL},
174     {135,  NULL},
175     {136,  NULL},
176 };
177 
178 static qemu_irq aspeed_soc_ast2700_get_irq(AspeedSoCState *s, int dev)
179 {
180     Aspeed27x0SoCState *a = ASPEED27X0_SOC(s);
181     AspeedSoCClass *sc = ASPEED_SOC_GET_CLASS(s);
182     int i;
183 
184     for (i = 0; i < ARRAY_SIZE(aspeed_soc_ast2700_gic_intcmap); i++) {
185         if (sc->irqmap[dev] == aspeed_soc_ast2700_gic_intcmap[i].irq) {
186             assert(aspeed_soc_ast2700_gic_intcmap[i].ptr);
187             return qdev_get_gpio_in(DEVICE(&a->intc.orgates[i]),
188                 aspeed_soc_ast2700_gic_intcmap[i].ptr[dev]);
189         }
190     }
191 
192     return qdev_get_gpio_in(DEVICE(&a->gic), sc->irqmap[dev]);
193 }
194 
195 static uint64_t aspeed_ram_capacity_read(void *opaque, hwaddr addr,
196                                                     unsigned int size)
197 {
198     qemu_log_mask(LOG_GUEST_ERROR,
199                   "%s: DRAM read out of ram size, addr:0x%" PRIx64 "\n",
200                    __func__, addr);
201     return 0;
202 }
203 
204 static void aspeed_ram_capacity_write(void *opaque, hwaddr addr, uint64_t data,
205                                                 unsigned int size)
206 {
207     AspeedSoCState *s = ASPEED_SOC(opaque);
208     ram_addr_t ram_size;
209     MemTxResult result;
210 
211     ram_size = object_property_get_uint(OBJECT(&s->sdmc), "ram-size",
212                                         &error_abort);
213 
214     /*
215      * Emulate ddr capacity hardware behavior.
216      * If writes the data to the address which is beyond the ram size,
217      * it would write the data to the "address % ram_size".
218      */
219     result = address_space_write(&s->dram_as, addr % ram_size,
220                                  MEMTXATTRS_UNSPECIFIED, &data, 4);
221     if (result != MEMTX_OK) {
222         qemu_log_mask(LOG_GUEST_ERROR,
223                       "%s: DRAM write failed, addr:0x%" HWADDR_PRIx
224                       ", data :0x%" PRIx64  "\n",
225                       __func__, addr % ram_size, data);
226     }
227 }
228 
229 static const MemoryRegionOps aspeed_ram_capacity_ops = {
230     .read = aspeed_ram_capacity_read,
231     .write = aspeed_ram_capacity_write,
232     .endianness = DEVICE_LITTLE_ENDIAN,
233     .valid = {
234         .min_access_size = 1,
235         .max_access_size = 8,
236     },
237 };
238 
239 /*
240  * SDMC should be realized first to get correct RAM size and max size
241  * values
242  */
243 static bool aspeed_soc_ast2700_dram_init(DeviceState *dev, Error **errp)
244 {
245     ram_addr_t ram_size, max_ram_size;
246     Aspeed27x0SoCState *a = ASPEED27X0_SOC(dev);
247     AspeedSoCState *s = ASPEED_SOC(dev);
248     AspeedSoCClass *sc = ASPEED_SOC_GET_CLASS(s);
249 
250     ram_size = object_property_get_uint(OBJECT(&s->sdmc), "ram-size",
251                                         &error_abort);
252     max_ram_size = object_property_get_uint(OBJECT(&s->sdmc), "max-ram-size",
253                                             &error_abort);
254 
255     memory_region_init(&s->dram_container, OBJECT(s), "ram-container",
256                        ram_size);
257     memory_region_add_subregion(&s->dram_container, 0, s->dram_mr);
258     address_space_init(&s->dram_as, s->dram_mr, "dram");
259 
260     /*
261      * Add a memory region beyond the RAM region to emulate
262      * ddr capacity hardware behavior.
263      */
264     if (ram_size < max_ram_size) {
265         memory_region_init_io(&a->dram_empty, OBJECT(s),
266                               &aspeed_ram_capacity_ops, s,
267                               "ram-empty", max_ram_size - ram_size);
268 
269         memory_region_add_subregion(s->memory,
270                                     sc->memmap[ASPEED_DEV_SDRAM] + ram_size,
271                                     &a->dram_empty);
272     }
273 
274     memory_region_add_subregion(s->memory,
275                       sc->memmap[ASPEED_DEV_SDRAM], &s->dram_container);
276     return true;
277 }
278 
279 static void aspeed_soc_ast2700_init(Object *obj)
280 {
281     Aspeed27x0SoCState *a = ASPEED27X0_SOC(obj);
282     AspeedSoCState *s = ASPEED_SOC(obj);
283     AspeedSoCClass *sc = ASPEED_SOC_GET_CLASS(s);
284     int i;
285     char socname[8];
286     char typename[64];
287 
288     if (sscanf(sc->name, "%7s", socname) != 1) {
289         g_assert_not_reached();
290     }
291 
292     for (i = 0; i < sc->num_cpus; i++) {
293         object_initialize_child(obj, "cpu[*]", &a->cpu[i],
294                                 aspeed_soc_cpu_type(sc));
295     }
296 
297     object_initialize_child(obj, "gic", &a->gic, gicv3_class_name());
298 
299     object_initialize_child(obj, "scu", &s->scu, TYPE_ASPEED_2700_SCU);
300     qdev_prop_set_uint32(DEVICE(&s->scu), "silicon-rev",
301                          sc->silicon_rev);
302     object_property_add_alias(obj, "hw-strap1", OBJECT(&s->scu),
303                               "hw-strap1");
304     object_property_add_alias(obj, "hw-strap2", OBJECT(&s->scu),
305                               "hw-strap2");
306     object_property_add_alias(obj, "hw-prot-key", OBJECT(&s->scu),
307                               "hw-prot-key");
308 
309     object_initialize_child(obj, "scuio", &s->scuio, TYPE_ASPEED_2700_SCUIO);
310     qdev_prop_set_uint32(DEVICE(&s->scuio), "silicon-rev",
311                          sc->silicon_rev);
312 
313     snprintf(typename, sizeof(typename), "aspeed.fmc-%s", socname);
314     object_initialize_child(obj, "fmc", &s->fmc, typename);
315 
316     for (i = 0; i < sc->spis_num; i++) {
317         snprintf(typename, sizeof(typename), "aspeed.spi%d-%s", i, socname);
318         object_initialize_child(obj, "spi[*]", &s->spi[i], typename);
319     }
320 
321     snprintf(typename, sizeof(typename), "aspeed.sdmc-%s", socname);
322     object_initialize_child(obj, "sdmc", &s->sdmc, typename);
323     object_property_add_alias(obj, "ram-size", OBJECT(&s->sdmc),
324                               "ram-size");
325 
326     for (i = 0; i < sc->wdts_num; i++) {
327         snprintf(typename, sizeof(typename), "aspeed.wdt-%s", socname);
328         object_initialize_child(obj, "wdt[*]", &s->wdt[i], typename);
329     }
330 
331     for (i = 0; i < sc->macs_num; i++) {
332         object_initialize_child(obj, "ftgmac100[*]", &s->ftgmac100[i],
333                                 TYPE_FTGMAC100);
334 
335         object_initialize_child(obj, "mii[*]", &s->mii[i], TYPE_ASPEED_MII);
336     }
337 
338     for (i = 0; i < sc->uarts_num; i++) {
339         object_initialize_child(obj, "uart[*]", &s->uart[i], TYPE_SERIAL_MM);
340     }
341 
342     object_initialize_child(obj, "sli", &s->sli, TYPE_ASPEED_2700_SLI);
343     object_initialize_child(obj, "sliio", &s->sliio, TYPE_ASPEED_2700_SLIIO);
344     object_initialize_child(obj, "intc", &a->intc, TYPE_ASPEED_2700_INTC);
345 }
346 
347 /*
348  * ASPEED ast2700 has 0x0 as cluster ID
349  *
350  * https://developer.arm.com/documentation/100236/0100/register-descriptions/aarch64-system-registers/multiprocessor-affinity-register--el1
351  */
352 static uint64_t aspeed_calc_affinity(int cpu)
353 {
354     return (0x0 << ARM_AFF1_SHIFT) | cpu;
355 }
356 
357 static bool aspeed_soc_ast2700_gic_realize(DeviceState *dev, Error **errp)
358 {
359     Aspeed27x0SoCState *a = ASPEED27X0_SOC(dev);
360     AspeedSoCState *s = ASPEED_SOC(dev);
361     AspeedSoCClass *sc = ASPEED_SOC_GET_CLASS(s);
362     SysBusDevice *gicbusdev;
363     DeviceState *gicdev;
364     QList *redist_region_count;
365     int i;
366 
367     gicbusdev = SYS_BUS_DEVICE(&a->gic);
368     gicdev = DEVICE(&a->gic);
369     qdev_prop_set_uint32(gicdev, "revision", 3);
370     qdev_prop_set_uint32(gicdev, "num-cpu", sc->num_cpus);
371     qdev_prop_set_uint32(gicdev, "num-irq", AST2700_MAX_IRQ);
372 
373     redist_region_count = qlist_new();
374     qlist_append_int(redist_region_count, sc->num_cpus);
375     qdev_prop_set_array(gicdev, "redist-region-count", redist_region_count);
376 
377     if (!sysbus_realize(gicbusdev, errp)) {
378         return false;
379     }
380     sysbus_mmio_map(gicbusdev, 0, sc->memmap[ASPEED_GIC_DIST]);
381     sysbus_mmio_map(gicbusdev, 1, sc->memmap[ASPEED_GIC_REDIST]);
382 
383     for (i = 0; i < sc->num_cpus; i++) {
384         DeviceState *cpudev = DEVICE(&a->cpu[i]);
385         int NUM_IRQS = 256, ARCH_GIC_MAINT_IRQ = 9, VIRTUAL_PMU_IRQ = 7;
386         int ppibase = NUM_IRQS + i * GIC_INTERNAL + GIC_NR_SGIS;
387 
388         const int timer_irq[] = {
389             [GTIMER_PHYS] = 14,
390             [GTIMER_VIRT] = 11,
391             [GTIMER_HYP]  = 10,
392             [GTIMER_SEC]  = 13,
393         };
394         int j;
395 
396         for (j = 0; j < ARRAY_SIZE(timer_irq); j++) {
397             qdev_connect_gpio_out(cpudev, j,
398                     qdev_get_gpio_in(gicdev, ppibase + timer_irq[j]));
399         }
400 
401         qemu_irq irq = qdev_get_gpio_in(gicdev,
402                                         ppibase + ARCH_GIC_MAINT_IRQ);
403         qdev_connect_gpio_out_named(cpudev, "gicv3-maintenance-interrupt",
404                                     0, irq);
405         qdev_connect_gpio_out_named(cpudev, "pmu-interrupt", 0,
406                 qdev_get_gpio_in(gicdev, ppibase + VIRTUAL_PMU_IRQ));
407 
408         sysbus_connect_irq(gicbusdev, i, qdev_get_gpio_in(cpudev, ARM_CPU_IRQ));
409         sysbus_connect_irq(gicbusdev, i + sc->num_cpus,
410                            qdev_get_gpio_in(cpudev, ARM_CPU_FIQ));
411         sysbus_connect_irq(gicbusdev, i + 2 * sc->num_cpus,
412                            qdev_get_gpio_in(cpudev, ARM_CPU_VIRQ));
413         sysbus_connect_irq(gicbusdev, i + 3 * sc->num_cpus,
414                            qdev_get_gpio_in(cpudev, ARM_CPU_VFIQ));
415     }
416 
417     return true;
418 }
419 
420 static void aspeed_soc_ast2700_realize(DeviceState *dev, Error **errp)
421 {
422     int i;
423     Aspeed27x0SoCState *a = ASPEED27X0_SOC(dev);
424     AspeedSoCState *s = ASPEED_SOC(dev);
425     AspeedSoCClass *sc = ASPEED_SOC_GET_CLASS(s);
426     AspeedINTCClass *ic = ASPEED_INTC_GET_CLASS(&a->intc);
427     g_autofree char *sram_name = NULL;
428 
429     /* Default boot region (SPI memory or ROMs) */
430     memory_region_init(&s->spi_boot_container, OBJECT(s),
431                        "aspeed.spi_boot_container", 0x400000000);
432     memory_region_add_subregion(s->memory, sc->memmap[ASPEED_DEV_SPI_BOOT],
433                                 &s->spi_boot_container);
434 
435     /* CPU */
436     for (i = 0; i < sc->num_cpus; i++) {
437         object_property_set_int(OBJECT(&a->cpu[i]), "mp-affinity",
438                                 aspeed_calc_affinity(i), &error_abort);
439 
440         object_property_set_int(OBJECT(&a->cpu[i]), "cntfrq", 1125000000,
441                                 &error_abort);
442         object_property_set_link(OBJECT(&a->cpu[i]), "memory",
443                                  OBJECT(s->memory), &error_abort);
444 
445         if (!qdev_realize(DEVICE(&a->cpu[i]), NULL, errp)) {
446             return;
447         }
448     }
449 
450     /* GIC */
451     if (!aspeed_soc_ast2700_gic_realize(dev, errp)) {
452         return;
453     }
454 
455     /* INTC */
456     if (!sysbus_realize(SYS_BUS_DEVICE(&a->intc), errp)) {
457         return;
458     }
459 
460     aspeed_mmio_map(s, SYS_BUS_DEVICE(&a->intc), 0,
461                     sc->memmap[ASPEED_DEV_INTC]);
462 
463     /* GICINT orgates -> INTC -> GIC */
464     for (i = 0; i < ic->num_ints; i++) {
465         qdev_connect_gpio_out(DEVICE(&a->intc.orgates[i]), 0,
466                                 qdev_get_gpio_in(DEVICE(&a->intc), i));
467         sysbus_connect_irq(SYS_BUS_DEVICE(&a->intc), i,
468                            qdev_get_gpio_in(DEVICE(&a->gic),
469                                 aspeed_soc_ast2700_gic_intcmap[i].irq));
470     }
471 
472     /* SRAM */
473     sram_name = g_strdup_printf("aspeed.sram.%d", CPU(&a->cpu[0])->cpu_index);
474     if (!memory_region_init_ram(&s->sram, OBJECT(s), sram_name, sc->sram_size,
475                                  errp)) {
476         return;
477     }
478     memory_region_add_subregion(s->memory,
479                                 sc->memmap[ASPEED_DEV_SRAM], &s->sram);
480 
481     /* SCU */
482     if (!sysbus_realize(SYS_BUS_DEVICE(&s->scu), errp)) {
483         return;
484     }
485     aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->scu), 0, sc->memmap[ASPEED_DEV_SCU]);
486 
487     /* SCU1 */
488     if (!sysbus_realize(SYS_BUS_DEVICE(&s->scuio), errp)) {
489         return;
490     }
491     aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->scuio), 0,
492                     sc->memmap[ASPEED_DEV_SCUIO]);
493 
494     /* UART */
495     if (!aspeed_soc_uart_realize(s, errp)) {
496         return;
497     }
498 
499     /* FMC, The number of CS is set at the board level */
500     object_property_set_int(OBJECT(&s->fmc), "dram-base",
501                             sc->memmap[ASPEED_DEV_SDRAM],
502                             &error_abort);
503     object_property_set_link(OBJECT(&s->fmc), "dram", OBJECT(s->dram_mr),
504                              &error_abort);
505     if (!sysbus_realize(SYS_BUS_DEVICE(&s->fmc), errp)) {
506         return;
507     }
508     aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->fmc), 0, sc->memmap[ASPEED_DEV_FMC]);
509     aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->fmc), 1,
510                     ASPEED_SMC_GET_CLASS(&s->fmc)->flash_window_base);
511     sysbus_connect_irq(SYS_BUS_DEVICE(&s->fmc), 0,
512                        aspeed_soc_get_irq(s, ASPEED_DEV_FMC));
513 
514     /* Set up an alias on the FMC CE0 region (boot default) */
515     MemoryRegion *fmc0_mmio = &s->fmc.flashes[0].mmio;
516     memory_region_init_alias(&s->spi_boot, OBJECT(s), "aspeed.spi_boot",
517                              fmc0_mmio, 0, memory_region_size(fmc0_mmio));
518     memory_region_add_subregion(&s->spi_boot_container, 0x0, &s->spi_boot);
519 
520     /* SPI */
521     for (i = 0; i < sc->spis_num; i++) {
522         object_property_set_link(OBJECT(&s->spi[i]), "dram",
523                                  OBJECT(s->dram_mr), &error_abort);
524         if (!sysbus_realize(SYS_BUS_DEVICE(&s->spi[i]), errp)) {
525             return;
526         }
527         aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->spi[i]), 0,
528                         sc->memmap[ASPEED_DEV_SPI0 + i]);
529         aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->spi[i]), 1,
530                         ASPEED_SMC_GET_CLASS(&s->spi[i])->flash_window_base);
531     }
532 
533     /*
534      * SDMC - SDRAM Memory Controller
535      * The SDMC controller is unlocked at SPL stage.
536      * At present, only supports to emulate booting
537      * start from u-boot stage. Set SDMC controller
538      * unlocked by default. It is a temporarily solution.
539      */
540     object_property_set_bool(OBJECT(&s->sdmc), "unlocked", true,
541                                  &error_abort);
542     if (!sysbus_realize(SYS_BUS_DEVICE(&s->sdmc), errp)) {
543         return;
544     }
545     aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->sdmc), 0,
546                     sc->memmap[ASPEED_DEV_SDMC]);
547 
548     /* RAM */
549     if (!aspeed_soc_ast2700_dram_init(dev, errp)) {
550         return;
551     }
552 
553     for (i = 0; i < sc->macs_num; i++) {
554         object_property_set_bool(OBJECT(&s->ftgmac100[i]), "aspeed", true,
555                                  &error_abort);
556         if (!sysbus_realize(SYS_BUS_DEVICE(&s->ftgmac100[i]), errp)) {
557             return;
558         }
559         aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->ftgmac100[i]), 0,
560                         sc->memmap[ASPEED_DEV_ETH1 + i]);
561         sysbus_connect_irq(SYS_BUS_DEVICE(&s->ftgmac100[i]), 0,
562                            aspeed_soc_get_irq(s, ASPEED_DEV_ETH1 + i));
563 
564         object_property_set_link(OBJECT(&s->mii[i]), "nic",
565                                  OBJECT(&s->ftgmac100[i]), &error_abort);
566         if (!sysbus_realize(SYS_BUS_DEVICE(&s->mii[i]), errp)) {
567             return;
568         }
569 
570         aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->mii[i]), 0,
571                         sc->memmap[ASPEED_DEV_MII1 + i]);
572     }
573 
574     /* Watch dog */
575     for (i = 0; i < sc->wdts_num; i++) {
576         AspeedWDTClass *awc = ASPEED_WDT_GET_CLASS(&s->wdt[i]);
577         hwaddr wdt_offset = sc->memmap[ASPEED_DEV_WDT] + i * awc->iosize;
578 
579         object_property_set_link(OBJECT(&s->wdt[i]), "scu", OBJECT(&s->scu),
580                                  &error_abort);
581         if (!sysbus_realize(SYS_BUS_DEVICE(&s->wdt[i]), errp)) {
582             return;
583         }
584         aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->wdt[i]), 0, wdt_offset);
585     }
586 
587     /* SLI */
588     if (!sysbus_realize(SYS_BUS_DEVICE(&s->sli), errp)) {
589         return;
590     }
591     aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->sli), 0, sc->memmap[ASPEED_DEV_SLI]);
592 
593     if (!sysbus_realize(SYS_BUS_DEVICE(&s->sliio), errp)) {
594         return;
595     }
596     aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->sliio), 0,
597                     sc->memmap[ASPEED_DEV_SLIIO]);
598 
599     create_unimplemented_device("ast2700.dpmcu", 0x11000000, 0x40000);
600     create_unimplemented_device("ast2700.iomem0", 0x12000000, 0x01000000);
601     create_unimplemented_device("ast2700.iomem1", 0x14000000, 0x01000000);
602     create_unimplemented_device("ast2700.ltpi", 0x30000000, 0x1000000);
603     create_unimplemented_device("ast2700.io", 0x0, 0x4000000);
604 }
605 
606 static void aspeed_soc_ast2700_class_init(ObjectClass *oc, void *data)
607 {
608     static const char * const valid_cpu_types[] = {
609         ARM_CPU_TYPE_NAME("cortex-a35"),
610         NULL
611     };
612     DeviceClass *dc = DEVICE_CLASS(oc);
613     AspeedSoCClass *sc = ASPEED_SOC_CLASS(oc);
614 
615     /* Reason: The Aspeed SoC can only be instantiated from a board */
616     dc->user_creatable = false;
617     dc->realize      = aspeed_soc_ast2700_realize;
618 
619     sc->name         = "ast2700-a0";
620     sc->valid_cpu_types = valid_cpu_types;
621     sc->silicon_rev  = AST2700_A0_SILICON_REV;
622     sc->sram_size    = 0x20000;
623     sc->spis_num     = 3;
624     sc->wdts_num     = 8;
625     sc->macs_num     = 1;
626     sc->uarts_num    = 13;
627     sc->num_cpus     = 4;
628     sc->uarts_base   = ASPEED_DEV_UART0;
629     sc->irqmap       = aspeed_soc_ast2700_irqmap;
630     sc->memmap       = aspeed_soc_ast2700_memmap;
631     sc->get_irq      = aspeed_soc_ast2700_get_irq;
632 }
633 
634 static const TypeInfo aspeed_soc_ast27x0_types[] = {
635     {
636         .name           = TYPE_ASPEED27X0_SOC,
637         .parent         = TYPE_ASPEED_SOC,
638         .instance_size  = sizeof(Aspeed27x0SoCState),
639         .abstract       = true,
640     }, {
641         .name           = "ast2700-a0",
642         .parent         = TYPE_ASPEED27X0_SOC,
643         .instance_init  = aspeed_soc_ast2700_init,
644         .class_init     = aspeed_soc_ast2700_class_init,
645     },
646 };
647 
648 DEFINE_TYPES(aspeed_soc_ast27x0_types)
649