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