15dd883abSJamin Lin /* 25dd883abSJamin Lin * ASPEED SoC 27x0 family 35dd883abSJamin Lin * 45dd883abSJamin Lin * Copyright (C) 2024 ASPEED Technology Inc. 55dd883abSJamin Lin * 65dd883abSJamin Lin * This code is licensed under the GPL version 2 or later. See 75dd883abSJamin Lin * the COPYING file in the top-level directory. 85dd883abSJamin Lin * 95dd883abSJamin Lin * Implementation extracted from the AST2600 and adapted for AST27x0. 105dd883abSJamin Lin */ 115dd883abSJamin Lin 125dd883abSJamin Lin #include "qemu/osdep.h" 135dd883abSJamin Lin #include "qapi/error.h" 145dd883abSJamin Lin #include "hw/misc/unimp.h" 155dd883abSJamin Lin #include "hw/arm/aspeed_soc.h" 165dd883abSJamin Lin #include "qemu/module.h" 175dd883abSJamin Lin #include "qemu/error-report.h" 185dd883abSJamin Lin #include "hw/i2c/aspeed_i2c.h" 195dd883abSJamin Lin #include "net/net.h" 205dd883abSJamin Lin #include "sysemu/sysemu.h" 215dd883abSJamin Lin #include "hw/intc/arm_gicv3.h" 225dd883abSJamin Lin #include "qapi/qmp/qlist.h" 237436db10SJamin Lin #include "qemu/log.h" 245dd883abSJamin Lin 255dd883abSJamin Lin static const hwaddr aspeed_soc_ast2700_memmap[] = { 265dd883abSJamin Lin [ASPEED_DEV_SPI_BOOT] = 0x400000000, 275dd883abSJamin Lin [ASPEED_DEV_SRAM] = 0x10000000, 285dd883abSJamin Lin [ASPEED_DEV_SDMC] = 0x12C00000, 295dd883abSJamin Lin [ASPEED_DEV_SCU] = 0x12C02000, 305dd883abSJamin Lin [ASPEED_DEV_SCUIO] = 0x14C02000, 315dd883abSJamin Lin [ASPEED_DEV_UART0] = 0X14C33000, 325dd883abSJamin Lin [ASPEED_DEV_UART1] = 0X14C33100, 335dd883abSJamin Lin [ASPEED_DEV_UART2] = 0X14C33200, 345dd883abSJamin Lin [ASPEED_DEV_UART3] = 0X14C33300, 355dd883abSJamin Lin [ASPEED_DEV_UART4] = 0X12C1A000, 365dd883abSJamin Lin [ASPEED_DEV_UART5] = 0X14C33400, 375dd883abSJamin Lin [ASPEED_DEV_UART6] = 0X14C33500, 385dd883abSJamin Lin [ASPEED_DEV_UART7] = 0X14C33600, 395dd883abSJamin Lin [ASPEED_DEV_UART8] = 0X14C33700, 405dd883abSJamin Lin [ASPEED_DEV_UART9] = 0X14C33800, 415dd883abSJamin Lin [ASPEED_DEV_UART10] = 0X14C33900, 425dd883abSJamin Lin [ASPEED_DEV_UART11] = 0X14C33A00, 435dd883abSJamin Lin [ASPEED_DEV_UART12] = 0X14C33B00, 445dd883abSJamin Lin [ASPEED_DEV_WDT] = 0x14C37000, 455dd883abSJamin Lin [ASPEED_DEV_VUART] = 0X14C30000, 465dd883abSJamin Lin [ASPEED_DEV_FMC] = 0x14000000, 475dd883abSJamin Lin [ASPEED_DEV_SPI0] = 0x14010000, 485dd883abSJamin Lin [ASPEED_DEV_SPI1] = 0x14020000, 495dd883abSJamin Lin [ASPEED_DEV_SPI2] = 0x14030000, 505dd883abSJamin Lin [ASPEED_DEV_SDRAM] = 0x400000000, 515dd883abSJamin Lin [ASPEED_DEV_MII1] = 0x14040000, 525dd883abSJamin Lin [ASPEED_DEV_MII2] = 0x14040008, 535dd883abSJamin Lin [ASPEED_DEV_MII3] = 0x14040010, 545dd883abSJamin Lin [ASPEED_DEV_ETH1] = 0x14050000, 555dd883abSJamin Lin [ASPEED_DEV_ETH2] = 0x14060000, 565dd883abSJamin Lin [ASPEED_DEV_ETH3] = 0x14070000, 575dd883abSJamin Lin [ASPEED_DEV_EMMC] = 0x12090000, 585dd883abSJamin Lin [ASPEED_DEV_INTC] = 0x12100000, 595dd883abSJamin Lin [ASPEED_DEV_SLI] = 0x12C17000, 605dd883abSJamin Lin [ASPEED_DEV_SLIIO] = 0x14C1E000, 615dd883abSJamin Lin [ASPEED_GIC_DIST] = 0x12200000, 625dd883abSJamin Lin [ASPEED_GIC_REDIST] = 0x12280000, 635dd883abSJamin Lin }; 645dd883abSJamin Lin 655dd883abSJamin Lin #define AST2700_MAX_IRQ 288 665dd883abSJamin Lin 675dd883abSJamin Lin /* Shared Peripheral Interrupt values below are offset by -32 from datasheet */ 685dd883abSJamin Lin static const int aspeed_soc_ast2700_irqmap[] = { 695dd883abSJamin Lin [ASPEED_DEV_UART0] = 132, 705dd883abSJamin Lin [ASPEED_DEV_UART1] = 132, 715dd883abSJamin Lin [ASPEED_DEV_UART2] = 132, 725dd883abSJamin Lin [ASPEED_DEV_UART3] = 132, 735dd883abSJamin Lin [ASPEED_DEV_UART4] = 8, 745dd883abSJamin Lin [ASPEED_DEV_UART5] = 132, 755dd883abSJamin Lin [ASPEED_DEV_UART6] = 132, 765dd883abSJamin Lin [ASPEED_DEV_UART7] = 132, 775dd883abSJamin Lin [ASPEED_DEV_UART8] = 132, 785dd883abSJamin Lin [ASPEED_DEV_UART9] = 132, 795dd883abSJamin Lin [ASPEED_DEV_UART10] = 132, 805dd883abSJamin Lin [ASPEED_DEV_UART11] = 132, 815dd883abSJamin Lin [ASPEED_DEV_UART12] = 132, 825dd883abSJamin Lin [ASPEED_DEV_FMC] = 131, 835dd883abSJamin Lin [ASPEED_DEV_SDMC] = 0, 845dd883abSJamin Lin [ASPEED_DEV_SCU] = 12, 855dd883abSJamin Lin [ASPEED_DEV_ADC] = 130, 865dd883abSJamin Lin [ASPEED_DEV_XDMA] = 5, 875dd883abSJamin Lin [ASPEED_DEV_EMMC] = 15, 885dd883abSJamin Lin [ASPEED_DEV_GPIO] = 11, 895dd883abSJamin Lin [ASPEED_DEV_GPIO_1_8V] = 130, 905dd883abSJamin Lin [ASPEED_DEV_RTC] = 13, 915dd883abSJamin Lin [ASPEED_DEV_TIMER1] = 16, 925dd883abSJamin Lin [ASPEED_DEV_TIMER2] = 17, 935dd883abSJamin Lin [ASPEED_DEV_TIMER3] = 18, 945dd883abSJamin Lin [ASPEED_DEV_TIMER4] = 19, 955dd883abSJamin Lin [ASPEED_DEV_TIMER5] = 20, 965dd883abSJamin Lin [ASPEED_DEV_TIMER6] = 21, 975dd883abSJamin Lin [ASPEED_DEV_TIMER7] = 22, 985dd883abSJamin Lin [ASPEED_DEV_TIMER8] = 23, 995dd883abSJamin Lin [ASPEED_DEV_WDT] = 131, 1005dd883abSJamin Lin [ASPEED_DEV_PWM] = 131, 1015dd883abSJamin Lin [ASPEED_DEV_LPC] = 128, 1025dd883abSJamin Lin [ASPEED_DEV_IBT] = 128, 1035dd883abSJamin Lin [ASPEED_DEV_I2C] = 130, 1045dd883abSJamin Lin [ASPEED_DEV_PECI] = 133, 1055dd883abSJamin Lin [ASPEED_DEV_ETH1] = 132, 1065dd883abSJamin Lin [ASPEED_DEV_ETH2] = 132, 1075dd883abSJamin Lin [ASPEED_DEV_ETH3] = 132, 1085dd883abSJamin Lin [ASPEED_DEV_HACE] = 4, 1095dd883abSJamin Lin [ASPEED_DEV_KCS] = 128, 1105dd883abSJamin Lin [ASPEED_DEV_DP] = 28, 1115dd883abSJamin Lin [ASPEED_DEV_I3C] = 131, 1125dd883abSJamin Lin }; 1135dd883abSJamin Lin 1145dd883abSJamin Lin /* GICINT 128 */ 1155dd883abSJamin Lin static const int aspeed_soc_ast2700_gic128_intcmap[] = { 1165dd883abSJamin Lin [ASPEED_DEV_LPC] = 0, 1175dd883abSJamin Lin [ASPEED_DEV_IBT] = 2, 1185dd883abSJamin Lin [ASPEED_DEV_KCS] = 4, 1195dd883abSJamin Lin }; 1205dd883abSJamin Lin 1215dd883abSJamin Lin /* GICINT 130 */ 1225dd883abSJamin Lin static const int aspeed_soc_ast2700_gic130_intcmap[] = { 1235dd883abSJamin Lin [ASPEED_DEV_I2C] = 0, 1245dd883abSJamin Lin [ASPEED_DEV_ADC] = 16, 1255dd883abSJamin Lin [ASPEED_DEV_GPIO_1_8V] = 18, 1265dd883abSJamin Lin }; 1275dd883abSJamin Lin 1285dd883abSJamin Lin /* GICINT 131 */ 1295dd883abSJamin Lin static const int aspeed_soc_ast2700_gic131_intcmap[] = { 1305dd883abSJamin Lin [ASPEED_DEV_I3C] = 0, 1315dd883abSJamin Lin [ASPEED_DEV_WDT] = 16, 1325dd883abSJamin Lin [ASPEED_DEV_FMC] = 25, 1335dd883abSJamin Lin [ASPEED_DEV_PWM] = 29, 1345dd883abSJamin Lin }; 1355dd883abSJamin Lin 1365dd883abSJamin Lin /* GICINT 132 */ 1375dd883abSJamin Lin static const int aspeed_soc_ast2700_gic132_intcmap[] = { 1385dd883abSJamin Lin [ASPEED_DEV_ETH1] = 0, 1395dd883abSJamin Lin [ASPEED_DEV_ETH2] = 1, 1405dd883abSJamin Lin [ASPEED_DEV_ETH3] = 2, 1415dd883abSJamin Lin [ASPEED_DEV_UART0] = 7, 1425dd883abSJamin Lin [ASPEED_DEV_UART1] = 8, 1435dd883abSJamin Lin [ASPEED_DEV_UART2] = 9, 1445dd883abSJamin Lin [ASPEED_DEV_UART3] = 10, 1455dd883abSJamin Lin [ASPEED_DEV_UART5] = 11, 1465dd883abSJamin Lin [ASPEED_DEV_UART6] = 12, 1475dd883abSJamin Lin [ASPEED_DEV_UART7] = 13, 1485dd883abSJamin Lin [ASPEED_DEV_UART8] = 14, 1495dd883abSJamin Lin [ASPEED_DEV_UART9] = 15, 1505dd883abSJamin Lin [ASPEED_DEV_UART10] = 16, 1515dd883abSJamin Lin [ASPEED_DEV_UART11] = 17, 1525dd883abSJamin Lin [ASPEED_DEV_UART12] = 18, 1535dd883abSJamin Lin }; 1545dd883abSJamin Lin 1555dd883abSJamin Lin /* GICINT 133 */ 1565dd883abSJamin Lin static const int aspeed_soc_ast2700_gic133_intcmap[] = { 1575dd883abSJamin Lin [ASPEED_DEV_PECI] = 4, 1585dd883abSJamin Lin }; 1595dd883abSJamin Lin 1605dd883abSJamin Lin /* GICINT 128 ~ 136 */ 1615dd883abSJamin Lin struct gic_intc_irq_info { 1625dd883abSJamin Lin int irq; 1635dd883abSJamin Lin const int *ptr; 1645dd883abSJamin Lin }; 1655dd883abSJamin Lin 1665dd883abSJamin Lin static const struct gic_intc_irq_info aspeed_soc_ast2700_gic_intcmap[] = { 1675dd883abSJamin Lin {128, aspeed_soc_ast2700_gic128_intcmap}, 1685dd883abSJamin Lin {129, NULL}, 1695dd883abSJamin Lin {130, aspeed_soc_ast2700_gic130_intcmap}, 1705dd883abSJamin Lin {131, aspeed_soc_ast2700_gic131_intcmap}, 1715dd883abSJamin Lin {132, aspeed_soc_ast2700_gic132_intcmap}, 1725dd883abSJamin Lin {133, aspeed_soc_ast2700_gic133_intcmap}, 1735dd883abSJamin Lin {134, NULL}, 1745dd883abSJamin Lin {135, NULL}, 1755dd883abSJamin Lin {136, NULL}, 1765dd883abSJamin Lin }; 1775dd883abSJamin Lin 1785dd883abSJamin Lin static qemu_irq aspeed_soc_ast2700_get_irq(AspeedSoCState *s, int dev) 1795dd883abSJamin Lin { 1805dd883abSJamin Lin Aspeed27x0SoCState *a = ASPEED27X0_SOC(s); 1815dd883abSJamin Lin AspeedSoCClass *sc = ASPEED_SOC_GET_CLASS(s); 1825dd883abSJamin Lin int i; 1835dd883abSJamin Lin 1845dd883abSJamin Lin for (i = 0; i < ARRAY_SIZE(aspeed_soc_ast2700_gic_intcmap); i++) { 1855dd883abSJamin Lin if (sc->irqmap[dev] == aspeed_soc_ast2700_gic_intcmap[i].irq) { 1865dd883abSJamin Lin assert(aspeed_soc_ast2700_gic_intcmap[i].ptr); 1875dd883abSJamin Lin return qdev_get_gpio_in(DEVICE(&a->intc.orgates[i]), 1885dd883abSJamin Lin aspeed_soc_ast2700_gic_intcmap[i].ptr[dev]); 1895dd883abSJamin Lin } 1905dd883abSJamin Lin } 1915dd883abSJamin Lin 1925dd883abSJamin Lin return qdev_get_gpio_in(DEVICE(&a->gic), sc->irqmap[dev]); 1935dd883abSJamin Lin } 1945dd883abSJamin Lin 1957436db10SJamin Lin static uint64_t aspeed_ram_capacity_read(void *opaque, hwaddr addr, 1967436db10SJamin Lin unsigned int size) 1977436db10SJamin Lin { 1987436db10SJamin Lin qemu_log_mask(LOG_GUEST_ERROR, 1997436db10SJamin Lin "%s: DRAM read out of ram size, addr:0x%" PRIx64 "\n", 2007436db10SJamin Lin __func__, addr); 2017436db10SJamin Lin return 0; 2027436db10SJamin Lin } 2037436db10SJamin Lin 2047436db10SJamin Lin static void aspeed_ram_capacity_write(void *opaque, hwaddr addr, uint64_t data, 2057436db10SJamin Lin unsigned int size) 2067436db10SJamin Lin { 2077436db10SJamin Lin AspeedSoCState *s = ASPEED_SOC(opaque); 2087436db10SJamin Lin ram_addr_t ram_size; 2097436db10SJamin Lin MemTxResult result; 2107436db10SJamin Lin 2117436db10SJamin Lin ram_size = object_property_get_uint(OBJECT(&s->sdmc), "ram-size", 2127436db10SJamin Lin &error_abort); 2137436db10SJamin Lin 214*5c065dfcSJamin Lin assert(ram_size > 0); 215*5c065dfcSJamin Lin 2167436db10SJamin Lin /* 2177436db10SJamin Lin * Emulate ddr capacity hardware behavior. 2187436db10SJamin Lin * If writes the data to the address which is beyond the ram size, 2197436db10SJamin Lin * it would write the data to the "address % ram_size". 2207436db10SJamin Lin */ 2217436db10SJamin Lin result = address_space_write(&s->dram_as, addr % ram_size, 2227436db10SJamin Lin MEMTXATTRS_UNSPECIFIED, &data, 4); 2237436db10SJamin Lin if (result != MEMTX_OK) { 2247436db10SJamin Lin qemu_log_mask(LOG_GUEST_ERROR, 2257436db10SJamin Lin "%s: DRAM write failed, addr:0x%" HWADDR_PRIx 2267436db10SJamin Lin ", data :0x%" PRIx64 "\n", 2277436db10SJamin Lin __func__, addr % ram_size, data); 2287436db10SJamin Lin } 2297436db10SJamin Lin } 2307436db10SJamin Lin 2317436db10SJamin Lin static const MemoryRegionOps aspeed_ram_capacity_ops = { 2327436db10SJamin Lin .read = aspeed_ram_capacity_read, 2337436db10SJamin Lin .write = aspeed_ram_capacity_write, 2347436db10SJamin Lin .endianness = DEVICE_LITTLE_ENDIAN, 2357436db10SJamin Lin .valid = { 2367436db10SJamin Lin .min_access_size = 1, 2377436db10SJamin Lin .max_access_size = 8, 2387436db10SJamin Lin }, 2397436db10SJamin Lin }; 2407436db10SJamin Lin 2417436db10SJamin Lin /* 2427436db10SJamin Lin * SDMC should be realized first to get correct RAM size and max size 2437436db10SJamin Lin * values 2447436db10SJamin Lin */ 2457436db10SJamin Lin static bool aspeed_soc_ast2700_dram_init(DeviceState *dev, Error **errp) 2467436db10SJamin Lin { 2477436db10SJamin Lin ram_addr_t ram_size, max_ram_size; 2487436db10SJamin Lin Aspeed27x0SoCState *a = ASPEED27X0_SOC(dev); 2497436db10SJamin Lin AspeedSoCState *s = ASPEED_SOC(dev); 2507436db10SJamin Lin AspeedSoCClass *sc = ASPEED_SOC_GET_CLASS(s); 2517436db10SJamin Lin 2527436db10SJamin Lin ram_size = object_property_get_uint(OBJECT(&s->sdmc), "ram-size", 2537436db10SJamin Lin &error_abort); 2547436db10SJamin Lin max_ram_size = object_property_get_uint(OBJECT(&s->sdmc), "max-ram-size", 2557436db10SJamin Lin &error_abort); 2567436db10SJamin Lin 2577436db10SJamin Lin memory_region_init(&s->dram_container, OBJECT(s), "ram-container", 2587436db10SJamin Lin ram_size); 2597436db10SJamin Lin memory_region_add_subregion(&s->dram_container, 0, s->dram_mr); 2607436db10SJamin Lin address_space_init(&s->dram_as, s->dram_mr, "dram"); 2617436db10SJamin Lin 2627436db10SJamin Lin /* 2637436db10SJamin Lin * Add a memory region beyond the RAM region to emulate 2647436db10SJamin Lin * ddr capacity hardware behavior. 2657436db10SJamin Lin */ 2667436db10SJamin Lin if (ram_size < max_ram_size) { 2677436db10SJamin Lin memory_region_init_io(&a->dram_empty, OBJECT(s), 2687436db10SJamin Lin &aspeed_ram_capacity_ops, s, 2697436db10SJamin Lin "ram-empty", max_ram_size - ram_size); 2707436db10SJamin Lin 2717436db10SJamin Lin memory_region_add_subregion(s->memory, 2727436db10SJamin Lin sc->memmap[ASPEED_DEV_SDRAM] + ram_size, 2737436db10SJamin Lin &a->dram_empty); 2747436db10SJamin Lin } 2757436db10SJamin Lin 2767436db10SJamin Lin memory_region_add_subregion(s->memory, 2777436db10SJamin Lin sc->memmap[ASPEED_DEV_SDRAM], &s->dram_container); 2787436db10SJamin Lin return true; 2797436db10SJamin Lin } 2807436db10SJamin Lin 2815dd883abSJamin Lin static void aspeed_soc_ast2700_init(Object *obj) 2825dd883abSJamin Lin { 2835dd883abSJamin Lin Aspeed27x0SoCState *a = ASPEED27X0_SOC(obj); 2845dd883abSJamin Lin AspeedSoCState *s = ASPEED_SOC(obj); 2855dd883abSJamin Lin AspeedSoCClass *sc = ASPEED_SOC_GET_CLASS(s); 2865dd883abSJamin Lin int i; 2875dd883abSJamin Lin char socname[8]; 2885dd883abSJamin Lin char typename[64]; 2895dd883abSJamin Lin 2905dd883abSJamin Lin if (sscanf(sc->name, "%7s", socname) != 1) { 2915dd883abSJamin Lin g_assert_not_reached(); 2925dd883abSJamin Lin } 2935dd883abSJamin Lin 2945dd883abSJamin Lin for (i = 0; i < sc->num_cpus; i++) { 2955dd883abSJamin Lin object_initialize_child(obj, "cpu[*]", &a->cpu[i], 2965dd883abSJamin Lin aspeed_soc_cpu_type(sc)); 2975dd883abSJamin Lin } 2985dd883abSJamin Lin 2995dd883abSJamin Lin object_initialize_child(obj, "gic", &a->gic, gicv3_class_name()); 3005dd883abSJamin Lin 3015dd883abSJamin Lin object_initialize_child(obj, "scu", &s->scu, TYPE_ASPEED_2700_SCU); 3025dd883abSJamin Lin qdev_prop_set_uint32(DEVICE(&s->scu), "silicon-rev", 3035dd883abSJamin Lin sc->silicon_rev); 3045dd883abSJamin Lin object_property_add_alias(obj, "hw-strap1", OBJECT(&s->scu), 3055dd883abSJamin Lin "hw-strap1"); 3065dd883abSJamin Lin object_property_add_alias(obj, "hw-strap2", OBJECT(&s->scu), 3075dd883abSJamin Lin "hw-strap2"); 3085dd883abSJamin Lin object_property_add_alias(obj, "hw-prot-key", OBJECT(&s->scu), 3095dd883abSJamin Lin "hw-prot-key"); 3105dd883abSJamin Lin 3115dd883abSJamin Lin object_initialize_child(obj, "scuio", &s->scuio, TYPE_ASPEED_2700_SCUIO); 3125dd883abSJamin Lin qdev_prop_set_uint32(DEVICE(&s->scuio), "silicon-rev", 3135dd883abSJamin Lin sc->silicon_rev); 3145dd883abSJamin Lin 3155dd883abSJamin Lin snprintf(typename, sizeof(typename), "aspeed.fmc-%s", socname); 3165dd883abSJamin Lin object_initialize_child(obj, "fmc", &s->fmc, typename); 3175dd883abSJamin Lin 3185dd883abSJamin Lin for (i = 0; i < sc->spis_num; i++) { 3195dd883abSJamin Lin snprintf(typename, sizeof(typename), "aspeed.spi%d-%s", i, socname); 3205dd883abSJamin Lin object_initialize_child(obj, "spi[*]", &s->spi[i], typename); 3215dd883abSJamin Lin } 3225dd883abSJamin Lin 3235dd883abSJamin Lin snprintf(typename, sizeof(typename), "aspeed.sdmc-%s", socname); 3245dd883abSJamin Lin object_initialize_child(obj, "sdmc", &s->sdmc, typename); 3255dd883abSJamin Lin object_property_add_alias(obj, "ram-size", OBJECT(&s->sdmc), 3265dd883abSJamin Lin "ram-size"); 3275dd883abSJamin Lin 3285dd883abSJamin Lin for (i = 0; i < sc->wdts_num; i++) { 3295dd883abSJamin Lin snprintf(typename, sizeof(typename), "aspeed.wdt-%s", socname); 3305dd883abSJamin Lin object_initialize_child(obj, "wdt[*]", &s->wdt[i], typename); 3315dd883abSJamin Lin } 3325dd883abSJamin Lin 3335dd883abSJamin Lin for (i = 0; i < sc->macs_num; i++) { 3345dd883abSJamin Lin object_initialize_child(obj, "ftgmac100[*]", &s->ftgmac100[i], 3355dd883abSJamin Lin TYPE_FTGMAC100); 3365dd883abSJamin Lin 3375dd883abSJamin Lin object_initialize_child(obj, "mii[*]", &s->mii[i], TYPE_ASPEED_MII); 3385dd883abSJamin Lin } 3395dd883abSJamin Lin 3405dd883abSJamin Lin for (i = 0; i < sc->uarts_num; i++) { 3415dd883abSJamin Lin object_initialize_child(obj, "uart[*]", &s->uart[i], TYPE_SERIAL_MM); 3425dd883abSJamin Lin } 3435dd883abSJamin Lin 3445dd883abSJamin Lin object_initialize_child(obj, "sli", &s->sli, TYPE_ASPEED_2700_SLI); 3455dd883abSJamin Lin object_initialize_child(obj, "sliio", &s->sliio, TYPE_ASPEED_2700_SLIIO); 3465dd883abSJamin Lin object_initialize_child(obj, "intc", &a->intc, TYPE_ASPEED_2700_INTC); 3475dd883abSJamin Lin } 3485dd883abSJamin Lin 3495dd883abSJamin Lin /* 3505dd883abSJamin Lin * ASPEED ast2700 has 0x0 as cluster ID 3515dd883abSJamin Lin * 3525dd883abSJamin Lin * https://developer.arm.com/documentation/100236/0100/register-descriptions/aarch64-system-registers/multiprocessor-affinity-register--el1 3535dd883abSJamin Lin */ 3545dd883abSJamin Lin static uint64_t aspeed_calc_affinity(int cpu) 3555dd883abSJamin Lin { 3565dd883abSJamin Lin return (0x0 << ARM_AFF1_SHIFT) | cpu; 3575dd883abSJamin Lin } 3585dd883abSJamin Lin 3595dd883abSJamin Lin static bool aspeed_soc_ast2700_gic_realize(DeviceState *dev, Error **errp) 3605dd883abSJamin Lin { 3615dd883abSJamin Lin Aspeed27x0SoCState *a = ASPEED27X0_SOC(dev); 3625dd883abSJamin Lin AspeedSoCState *s = ASPEED_SOC(dev); 3635dd883abSJamin Lin AspeedSoCClass *sc = ASPEED_SOC_GET_CLASS(s); 3645dd883abSJamin Lin SysBusDevice *gicbusdev; 3655dd883abSJamin Lin DeviceState *gicdev; 3665dd883abSJamin Lin QList *redist_region_count; 3675dd883abSJamin Lin int i; 3685dd883abSJamin Lin 3695dd883abSJamin Lin gicbusdev = SYS_BUS_DEVICE(&a->gic); 3705dd883abSJamin Lin gicdev = DEVICE(&a->gic); 3715dd883abSJamin Lin qdev_prop_set_uint32(gicdev, "revision", 3); 3725dd883abSJamin Lin qdev_prop_set_uint32(gicdev, "num-cpu", sc->num_cpus); 3735dd883abSJamin Lin qdev_prop_set_uint32(gicdev, "num-irq", AST2700_MAX_IRQ); 3745dd883abSJamin Lin 3755dd883abSJamin Lin redist_region_count = qlist_new(); 3765dd883abSJamin Lin qlist_append_int(redist_region_count, sc->num_cpus); 3775dd883abSJamin Lin qdev_prop_set_array(gicdev, "redist-region-count", redist_region_count); 3785dd883abSJamin Lin 3795dd883abSJamin Lin if (!sysbus_realize(gicbusdev, errp)) { 3805dd883abSJamin Lin return false; 3815dd883abSJamin Lin } 3825dd883abSJamin Lin sysbus_mmio_map(gicbusdev, 0, sc->memmap[ASPEED_GIC_DIST]); 3835dd883abSJamin Lin sysbus_mmio_map(gicbusdev, 1, sc->memmap[ASPEED_GIC_REDIST]); 3845dd883abSJamin Lin 3855dd883abSJamin Lin for (i = 0; i < sc->num_cpus; i++) { 3865dd883abSJamin Lin DeviceState *cpudev = DEVICE(&a->cpu[i]); 3875dd883abSJamin Lin int NUM_IRQS = 256, ARCH_GIC_MAINT_IRQ = 9, VIRTUAL_PMU_IRQ = 7; 3885dd883abSJamin Lin int ppibase = NUM_IRQS + i * GIC_INTERNAL + GIC_NR_SGIS; 3895dd883abSJamin Lin 3905dd883abSJamin Lin const int timer_irq[] = { 3915dd883abSJamin Lin [GTIMER_PHYS] = 14, 3925dd883abSJamin Lin [GTIMER_VIRT] = 11, 3935dd883abSJamin Lin [GTIMER_HYP] = 10, 3945dd883abSJamin Lin [GTIMER_SEC] = 13, 3955dd883abSJamin Lin }; 3965dd883abSJamin Lin int j; 3975dd883abSJamin Lin 3985dd883abSJamin Lin for (j = 0; j < ARRAY_SIZE(timer_irq); j++) { 3995dd883abSJamin Lin qdev_connect_gpio_out(cpudev, j, 4005dd883abSJamin Lin qdev_get_gpio_in(gicdev, ppibase + timer_irq[j])); 4015dd883abSJamin Lin } 4025dd883abSJamin Lin 4035dd883abSJamin Lin qemu_irq irq = qdev_get_gpio_in(gicdev, 4045dd883abSJamin Lin ppibase + ARCH_GIC_MAINT_IRQ); 4055dd883abSJamin Lin qdev_connect_gpio_out_named(cpudev, "gicv3-maintenance-interrupt", 4065dd883abSJamin Lin 0, irq); 4075dd883abSJamin Lin qdev_connect_gpio_out_named(cpudev, "pmu-interrupt", 0, 4085dd883abSJamin Lin qdev_get_gpio_in(gicdev, ppibase + VIRTUAL_PMU_IRQ)); 4095dd883abSJamin Lin 4105dd883abSJamin Lin sysbus_connect_irq(gicbusdev, i, qdev_get_gpio_in(cpudev, ARM_CPU_IRQ)); 4115dd883abSJamin Lin sysbus_connect_irq(gicbusdev, i + sc->num_cpus, 4125dd883abSJamin Lin qdev_get_gpio_in(cpudev, ARM_CPU_FIQ)); 4135dd883abSJamin Lin sysbus_connect_irq(gicbusdev, i + 2 * sc->num_cpus, 4145dd883abSJamin Lin qdev_get_gpio_in(cpudev, ARM_CPU_VIRQ)); 4155dd883abSJamin Lin sysbus_connect_irq(gicbusdev, i + 3 * sc->num_cpus, 4165dd883abSJamin Lin qdev_get_gpio_in(cpudev, ARM_CPU_VFIQ)); 4175dd883abSJamin Lin } 4185dd883abSJamin Lin 4195dd883abSJamin Lin return true; 4205dd883abSJamin Lin } 4215dd883abSJamin Lin 4225dd883abSJamin Lin static void aspeed_soc_ast2700_realize(DeviceState *dev, Error **errp) 4235dd883abSJamin Lin { 4245dd883abSJamin Lin int i; 4255dd883abSJamin Lin Aspeed27x0SoCState *a = ASPEED27X0_SOC(dev); 4265dd883abSJamin Lin AspeedSoCState *s = ASPEED_SOC(dev); 4275dd883abSJamin Lin AspeedSoCClass *sc = ASPEED_SOC_GET_CLASS(s); 4285dd883abSJamin Lin AspeedINTCClass *ic = ASPEED_INTC_GET_CLASS(&a->intc); 4295dd883abSJamin Lin g_autofree char *sram_name = NULL; 4305dd883abSJamin Lin 4315dd883abSJamin Lin /* Default boot region (SPI memory or ROMs) */ 4325dd883abSJamin Lin memory_region_init(&s->spi_boot_container, OBJECT(s), 4335dd883abSJamin Lin "aspeed.spi_boot_container", 0x400000000); 4345dd883abSJamin Lin memory_region_add_subregion(s->memory, sc->memmap[ASPEED_DEV_SPI_BOOT], 4355dd883abSJamin Lin &s->spi_boot_container); 4365dd883abSJamin Lin 4375dd883abSJamin Lin /* CPU */ 4385dd883abSJamin Lin for (i = 0; i < sc->num_cpus; i++) { 4395dd883abSJamin Lin object_property_set_int(OBJECT(&a->cpu[i]), "mp-affinity", 4405dd883abSJamin Lin aspeed_calc_affinity(i), &error_abort); 4415dd883abSJamin Lin 4425dd883abSJamin Lin object_property_set_int(OBJECT(&a->cpu[i]), "cntfrq", 1125000000, 4435dd883abSJamin Lin &error_abort); 4445dd883abSJamin Lin object_property_set_link(OBJECT(&a->cpu[i]), "memory", 4455dd883abSJamin Lin OBJECT(s->memory), &error_abort); 4465dd883abSJamin Lin 4475dd883abSJamin Lin if (!qdev_realize(DEVICE(&a->cpu[i]), NULL, errp)) { 4485dd883abSJamin Lin return; 4495dd883abSJamin Lin } 4505dd883abSJamin Lin } 4515dd883abSJamin Lin 4525dd883abSJamin Lin /* GIC */ 4535dd883abSJamin Lin if (!aspeed_soc_ast2700_gic_realize(dev, errp)) { 4545dd883abSJamin Lin return; 4555dd883abSJamin Lin } 4565dd883abSJamin Lin 4575dd883abSJamin Lin /* INTC */ 4585dd883abSJamin Lin if (!sysbus_realize(SYS_BUS_DEVICE(&a->intc), errp)) { 4595dd883abSJamin Lin return; 4605dd883abSJamin Lin } 4615dd883abSJamin Lin 4625dd883abSJamin Lin aspeed_mmio_map(s, SYS_BUS_DEVICE(&a->intc), 0, 4635dd883abSJamin Lin sc->memmap[ASPEED_DEV_INTC]); 4645dd883abSJamin Lin 4655dd883abSJamin Lin /* GICINT orgates -> INTC -> GIC */ 4665dd883abSJamin Lin for (i = 0; i < ic->num_ints; i++) { 4675dd883abSJamin Lin qdev_connect_gpio_out(DEVICE(&a->intc.orgates[i]), 0, 4685dd883abSJamin Lin qdev_get_gpio_in(DEVICE(&a->intc), i)); 4695dd883abSJamin Lin sysbus_connect_irq(SYS_BUS_DEVICE(&a->intc), i, 4705dd883abSJamin Lin qdev_get_gpio_in(DEVICE(&a->gic), 4715dd883abSJamin Lin aspeed_soc_ast2700_gic_intcmap[i].irq)); 4725dd883abSJamin Lin } 4735dd883abSJamin Lin 4745dd883abSJamin Lin /* SRAM */ 4755dd883abSJamin Lin sram_name = g_strdup_printf("aspeed.sram.%d", CPU(&a->cpu[0])->cpu_index); 4765dd883abSJamin Lin if (!memory_region_init_ram(&s->sram, OBJECT(s), sram_name, sc->sram_size, 4775dd883abSJamin Lin errp)) { 4785dd883abSJamin Lin return; 4795dd883abSJamin Lin } 4805dd883abSJamin Lin memory_region_add_subregion(s->memory, 4815dd883abSJamin Lin sc->memmap[ASPEED_DEV_SRAM], &s->sram); 4825dd883abSJamin Lin 4835dd883abSJamin Lin /* SCU */ 4845dd883abSJamin Lin if (!sysbus_realize(SYS_BUS_DEVICE(&s->scu), errp)) { 4855dd883abSJamin Lin return; 4865dd883abSJamin Lin } 4875dd883abSJamin Lin aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->scu), 0, sc->memmap[ASPEED_DEV_SCU]); 4885dd883abSJamin Lin 4895dd883abSJamin Lin /* SCU1 */ 4905dd883abSJamin Lin if (!sysbus_realize(SYS_BUS_DEVICE(&s->scuio), errp)) { 4915dd883abSJamin Lin return; 4925dd883abSJamin Lin } 4935dd883abSJamin Lin aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->scuio), 0, 4945dd883abSJamin Lin sc->memmap[ASPEED_DEV_SCUIO]); 4955dd883abSJamin Lin 4965dd883abSJamin Lin /* UART */ 4975dd883abSJamin Lin if (!aspeed_soc_uart_realize(s, errp)) { 4985dd883abSJamin Lin return; 4995dd883abSJamin Lin } 5005dd883abSJamin Lin 5015dd883abSJamin Lin /* FMC, The number of CS is set at the board level */ 5025dd883abSJamin Lin object_property_set_int(OBJECT(&s->fmc), "dram-base", 5035dd883abSJamin Lin sc->memmap[ASPEED_DEV_SDRAM], 5045dd883abSJamin Lin &error_abort); 5055dd883abSJamin Lin object_property_set_link(OBJECT(&s->fmc), "dram", OBJECT(s->dram_mr), 5065dd883abSJamin Lin &error_abort); 5075dd883abSJamin Lin if (!sysbus_realize(SYS_BUS_DEVICE(&s->fmc), errp)) { 5085dd883abSJamin Lin return; 5095dd883abSJamin Lin } 5105dd883abSJamin Lin aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->fmc), 0, sc->memmap[ASPEED_DEV_FMC]); 5115dd883abSJamin Lin aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->fmc), 1, 5125dd883abSJamin Lin ASPEED_SMC_GET_CLASS(&s->fmc)->flash_window_base); 5135dd883abSJamin Lin sysbus_connect_irq(SYS_BUS_DEVICE(&s->fmc), 0, 5145dd883abSJamin Lin aspeed_soc_get_irq(s, ASPEED_DEV_FMC)); 5155dd883abSJamin Lin 5165dd883abSJamin Lin /* Set up an alias on the FMC CE0 region (boot default) */ 5175dd883abSJamin Lin MemoryRegion *fmc0_mmio = &s->fmc.flashes[0].mmio; 5185dd883abSJamin Lin memory_region_init_alias(&s->spi_boot, OBJECT(s), "aspeed.spi_boot", 5195dd883abSJamin Lin fmc0_mmio, 0, memory_region_size(fmc0_mmio)); 5205dd883abSJamin Lin memory_region_add_subregion(&s->spi_boot_container, 0x0, &s->spi_boot); 5215dd883abSJamin Lin 5225dd883abSJamin Lin /* SPI */ 5235dd883abSJamin Lin for (i = 0; i < sc->spis_num; i++) { 5245dd883abSJamin Lin object_property_set_link(OBJECT(&s->spi[i]), "dram", 5255dd883abSJamin Lin OBJECT(s->dram_mr), &error_abort); 5265dd883abSJamin Lin if (!sysbus_realize(SYS_BUS_DEVICE(&s->spi[i]), errp)) { 5275dd883abSJamin Lin return; 5285dd883abSJamin Lin } 5295dd883abSJamin Lin aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->spi[i]), 0, 5305dd883abSJamin Lin sc->memmap[ASPEED_DEV_SPI0 + i]); 5315dd883abSJamin Lin aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->spi[i]), 1, 5325dd883abSJamin Lin ASPEED_SMC_GET_CLASS(&s->spi[i])->flash_window_base); 5335dd883abSJamin Lin } 5345dd883abSJamin Lin 5355dd883abSJamin Lin /* 5365dd883abSJamin Lin * SDMC - SDRAM Memory Controller 5375dd883abSJamin Lin * The SDMC controller is unlocked at SPL stage. 5385dd883abSJamin Lin * At present, only supports to emulate booting 5395dd883abSJamin Lin * start from u-boot stage. Set SDMC controller 5405dd883abSJamin Lin * unlocked by default. It is a temporarily solution. 5415dd883abSJamin Lin */ 5425dd883abSJamin Lin object_property_set_bool(OBJECT(&s->sdmc), "unlocked", true, 5435dd883abSJamin Lin &error_abort); 5445dd883abSJamin Lin if (!sysbus_realize(SYS_BUS_DEVICE(&s->sdmc), errp)) { 5455dd883abSJamin Lin return; 5465dd883abSJamin Lin } 5475dd883abSJamin Lin aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->sdmc), 0, 5485dd883abSJamin Lin sc->memmap[ASPEED_DEV_SDMC]); 5495dd883abSJamin Lin 5505dd883abSJamin Lin /* RAM */ 5517436db10SJamin Lin if (!aspeed_soc_ast2700_dram_init(dev, errp)) { 5525dd883abSJamin Lin return; 5535dd883abSJamin Lin } 5545dd883abSJamin Lin 5555dd883abSJamin Lin for (i = 0; i < sc->macs_num; i++) { 5565dd883abSJamin Lin object_property_set_bool(OBJECT(&s->ftgmac100[i]), "aspeed", true, 5575dd883abSJamin Lin &error_abort); 5585dd883abSJamin Lin if (!sysbus_realize(SYS_BUS_DEVICE(&s->ftgmac100[i]), errp)) { 5595dd883abSJamin Lin return; 5605dd883abSJamin Lin } 5615dd883abSJamin Lin aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->ftgmac100[i]), 0, 5625dd883abSJamin Lin sc->memmap[ASPEED_DEV_ETH1 + i]); 5635dd883abSJamin Lin sysbus_connect_irq(SYS_BUS_DEVICE(&s->ftgmac100[i]), 0, 5645dd883abSJamin Lin aspeed_soc_get_irq(s, ASPEED_DEV_ETH1 + i)); 5655dd883abSJamin Lin 5665dd883abSJamin Lin object_property_set_link(OBJECT(&s->mii[i]), "nic", 5675dd883abSJamin Lin OBJECT(&s->ftgmac100[i]), &error_abort); 5685dd883abSJamin Lin if (!sysbus_realize(SYS_BUS_DEVICE(&s->mii[i]), errp)) { 5695dd883abSJamin Lin return; 5705dd883abSJamin Lin } 5715dd883abSJamin Lin 5725dd883abSJamin Lin aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->mii[i]), 0, 5735dd883abSJamin Lin sc->memmap[ASPEED_DEV_MII1 + i]); 5745dd883abSJamin Lin } 5755dd883abSJamin Lin 5765dd883abSJamin Lin /* Watch dog */ 5775dd883abSJamin Lin for (i = 0; i < sc->wdts_num; i++) { 5785dd883abSJamin Lin AspeedWDTClass *awc = ASPEED_WDT_GET_CLASS(&s->wdt[i]); 5795dd883abSJamin Lin hwaddr wdt_offset = sc->memmap[ASPEED_DEV_WDT] + i * awc->iosize; 5805dd883abSJamin Lin 5815dd883abSJamin Lin object_property_set_link(OBJECT(&s->wdt[i]), "scu", OBJECT(&s->scu), 5825dd883abSJamin Lin &error_abort); 5835dd883abSJamin Lin if (!sysbus_realize(SYS_BUS_DEVICE(&s->wdt[i]), errp)) { 5845dd883abSJamin Lin return; 5855dd883abSJamin Lin } 5865dd883abSJamin Lin aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->wdt[i]), 0, wdt_offset); 5875dd883abSJamin Lin } 5885dd883abSJamin Lin 5895dd883abSJamin Lin /* SLI */ 5905dd883abSJamin Lin if (!sysbus_realize(SYS_BUS_DEVICE(&s->sli), errp)) { 5915dd883abSJamin Lin return; 5925dd883abSJamin Lin } 5935dd883abSJamin Lin aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->sli), 0, sc->memmap[ASPEED_DEV_SLI]); 5945dd883abSJamin Lin 5955dd883abSJamin Lin if (!sysbus_realize(SYS_BUS_DEVICE(&s->sliio), errp)) { 5965dd883abSJamin Lin return; 5975dd883abSJamin Lin } 5985dd883abSJamin Lin aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->sliio), 0, 5995dd883abSJamin Lin sc->memmap[ASPEED_DEV_SLIIO]); 6005dd883abSJamin Lin 6015dd883abSJamin Lin create_unimplemented_device("ast2700.dpmcu", 0x11000000, 0x40000); 6025dd883abSJamin Lin create_unimplemented_device("ast2700.iomem0", 0x12000000, 0x01000000); 6035dd883abSJamin Lin create_unimplemented_device("ast2700.iomem1", 0x14000000, 0x01000000); 6045dd883abSJamin Lin create_unimplemented_device("ast2700.ltpi", 0x30000000, 0x1000000); 6055dd883abSJamin Lin create_unimplemented_device("ast2700.io", 0x0, 0x4000000); 6065dd883abSJamin Lin } 6075dd883abSJamin Lin 6085dd883abSJamin Lin static void aspeed_soc_ast2700_class_init(ObjectClass *oc, void *data) 6095dd883abSJamin Lin { 6105dd883abSJamin Lin static const char * const valid_cpu_types[] = { 6115dd883abSJamin Lin ARM_CPU_TYPE_NAME("cortex-a35"), 6125dd883abSJamin Lin NULL 6135dd883abSJamin Lin }; 6145dd883abSJamin Lin DeviceClass *dc = DEVICE_CLASS(oc); 6155dd883abSJamin Lin AspeedSoCClass *sc = ASPEED_SOC_CLASS(oc); 6165dd883abSJamin Lin 6175dd883abSJamin Lin /* Reason: The Aspeed SoC can only be instantiated from a board */ 6185dd883abSJamin Lin dc->user_creatable = false; 6195dd883abSJamin Lin dc->realize = aspeed_soc_ast2700_realize; 6205dd883abSJamin Lin 6215dd883abSJamin Lin sc->name = "ast2700-a0"; 6225dd883abSJamin Lin sc->valid_cpu_types = valid_cpu_types; 6235dd883abSJamin Lin sc->silicon_rev = AST2700_A0_SILICON_REV; 6245dd883abSJamin Lin sc->sram_size = 0x20000; 6255dd883abSJamin Lin sc->spis_num = 3; 6265dd883abSJamin Lin sc->wdts_num = 8; 6275dd883abSJamin Lin sc->macs_num = 1; 6285dd883abSJamin Lin sc->uarts_num = 13; 6295dd883abSJamin Lin sc->num_cpus = 4; 6305dd883abSJamin Lin sc->uarts_base = ASPEED_DEV_UART0; 6315dd883abSJamin Lin sc->irqmap = aspeed_soc_ast2700_irqmap; 6325dd883abSJamin Lin sc->memmap = aspeed_soc_ast2700_memmap; 6335dd883abSJamin Lin sc->get_irq = aspeed_soc_ast2700_get_irq; 6345dd883abSJamin Lin } 6355dd883abSJamin Lin 6365dd883abSJamin Lin static const TypeInfo aspeed_soc_ast27x0_types[] = { 6375dd883abSJamin Lin { 6385dd883abSJamin Lin .name = TYPE_ASPEED27X0_SOC, 6395dd883abSJamin Lin .parent = TYPE_ASPEED_SOC, 6405dd883abSJamin Lin .instance_size = sizeof(Aspeed27x0SoCState), 6415dd883abSJamin Lin .abstract = true, 6425dd883abSJamin Lin }, { 6435dd883abSJamin Lin .name = "ast2700-a0", 6445dd883abSJamin Lin .parent = TYPE_ASPEED27X0_SOC, 6455dd883abSJamin Lin .instance_init = aspeed_soc_ast2700_init, 6465dd883abSJamin Lin .class_init = aspeed_soc_ast2700_class_init, 6475dd883abSJamin Lin }, 6485dd883abSJamin Lin }; 6495dd883abSJamin Lin 6505dd883abSJamin Lin DEFINE_TYPES(aspeed_soc_ast27x0_types) 651