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" 23*7436db10SJamin 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 195*7436db10SJamin Lin static uint64_t aspeed_ram_capacity_read(void *opaque, hwaddr addr, 196*7436db10SJamin Lin unsigned int size) 197*7436db10SJamin Lin { 198*7436db10SJamin Lin qemu_log_mask(LOG_GUEST_ERROR, 199*7436db10SJamin Lin "%s: DRAM read out of ram size, addr:0x%" PRIx64 "\n", 200*7436db10SJamin Lin __func__, addr); 201*7436db10SJamin Lin return 0; 202*7436db10SJamin Lin } 203*7436db10SJamin Lin 204*7436db10SJamin Lin static void aspeed_ram_capacity_write(void *opaque, hwaddr addr, uint64_t data, 205*7436db10SJamin Lin unsigned int size) 206*7436db10SJamin Lin { 207*7436db10SJamin Lin AspeedSoCState *s = ASPEED_SOC(opaque); 208*7436db10SJamin Lin ram_addr_t ram_size; 209*7436db10SJamin Lin MemTxResult result; 210*7436db10SJamin Lin 211*7436db10SJamin Lin ram_size = object_property_get_uint(OBJECT(&s->sdmc), "ram-size", 212*7436db10SJamin Lin &error_abort); 213*7436db10SJamin Lin 214*7436db10SJamin Lin /* 215*7436db10SJamin Lin * Emulate ddr capacity hardware behavior. 216*7436db10SJamin Lin * If writes the data to the address which is beyond the ram size, 217*7436db10SJamin Lin * it would write the data to the "address % ram_size". 218*7436db10SJamin Lin */ 219*7436db10SJamin Lin result = address_space_write(&s->dram_as, addr % ram_size, 220*7436db10SJamin Lin MEMTXATTRS_UNSPECIFIED, &data, 4); 221*7436db10SJamin Lin if (result != MEMTX_OK) { 222*7436db10SJamin Lin qemu_log_mask(LOG_GUEST_ERROR, 223*7436db10SJamin Lin "%s: DRAM write failed, addr:0x%" HWADDR_PRIx 224*7436db10SJamin Lin ", data :0x%" PRIx64 "\n", 225*7436db10SJamin Lin __func__, addr % ram_size, data); 226*7436db10SJamin Lin } 227*7436db10SJamin Lin } 228*7436db10SJamin Lin 229*7436db10SJamin Lin static const MemoryRegionOps aspeed_ram_capacity_ops = { 230*7436db10SJamin Lin .read = aspeed_ram_capacity_read, 231*7436db10SJamin Lin .write = aspeed_ram_capacity_write, 232*7436db10SJamin Lin .endianness = DEVICE_LITTLE_ENDIAN, 233*7436db10SJamin Lin .valid = { 234*7436db10SJamin Lin .min_access_size = 1, 235*7436db10SJamin Lin .max_access_size = 8, 236*7436db10SJamin Lin }, 237*7436db10SJamin Lin }; 238*7436db10SJamin Lin 239*7436db10SJamin Lin /* 240*7436db10SJamin Lin * SDMC should be realized first to get correct RAM size and max size 241*7436db10SJamin Lin * values 242*7436db10SJamin Lin */ 243*7436db10SJamin Lin static bool aspeed_soc_ast2700_dram_init(DeviceState *dev, Error **errp) 244*7436db10SJamin Lin { 245*7436db10SJamin Lin ram_addr_t ram_size, max_ram_size; 246*7436db10SJamin Lin Aspeed27x0SoCState *a = ASPEED27X0_SOC(dev); 247*7436db10SJamin Lin AspeedSoCState *s = ASPEED_SOC(dev); 248*7436db10SJamin Lin AspeedSoCClass *sc = ASPEED_SOC_GET_CLASS(s); 249*7436db10SJamin Lin 250*7436db10SJamin Lin ram_size = object_property_get_uint(OBJECT(&s->sdmc), "ram-size", 251*7436db10SJamin Lin &error_abort); 252*7436db10SJamin Lin max_ram_size = object_property_get_uint(OBJECT(&s->sdmc), "max-ram-size", 253*7436db10SJamin Lin &error_abort); 254*7436db10SJamin Lin 255*7436db10SJamin Lin memory_region_init(&s->dram_container, OBJECT(s), "ram-container", 256*7436db10SJamin Lin ram_size); 257*7436db10SJamin Lin memory_region_add_subregion(&s->dram_container, 0, s->dram_mr); 258*7436db10SJamin Lin address_space_init(&s->dram_as, s->dram_mr, "dram"); 259*7436db10SJamin Lin 260*7436db10SJamin Lin /* 261*7436db10SJamin Lin * Add a memory region beyond the RAM region to emulate 262*7436db10SJamin Lin * ddr capacity hardware behavior. 263*7436db10SJamin Lin */ 264*7436db10SJamin Lin if (ram_size < max_ram_size) { 265*7436db10SJamin Lin memory_region_init_io(&a->dram_empty, OBJECT(s), 266*7436db10SJamin Lin &aspeed_ram_capacity_ops, s, 267*7436db10SJamin Lin "ram-empty", max_ram_size - ram_size); 268*7436db10SJamin Lin 269*7436db10SJamin Lin memory_region_add_subregion(s->memory, 270*7436db10SJamin Lin sc->memmap[ASPEED_DEV_SDRAM] + ram_size, 271*7436db10SJamin Lin &a->dram_empty); 272*7436db10SJamin Lin } 273*7436db10SJamin Lin 274*7436db10SJamin Lin memory_region_add_subregion(s->memory, 275*7436db10SJamin Lin sc->memmap[ASPEED_DEV_SDRAM], &s->dram_container); 276*7436db10SJamin Lin return true; 277*7436db10SJamin Lin } 278*7436db10SJamin Lin 2795dd883abSJamin Lin static void aspeed_soc_ast2700_init(Object *obj) 2805dd883abSJamin Lin { 2815dd883abSJamin Lin Aspeed27x0SoCState *a = ASPEED27X0_SOC(obj); 2825dd883abSJamin Lin AspeedSoCState *s = ASPEED_SOC(obj); 2835dd883abSJamin Lin AspeedSoCClass *sc = ASPEED_SOC_GET_CLASS(s); 2845dd883abSJamin Lin int i; 2855dd883abSJamin Lin char socname[8]; 2865dd883abSJamin Lin char typename[64]; 2875dd883abSJamin Lin 2885dd883abSJamin Lin if (sscanf(sc->name, "%7s", socname) != 1) { 2895dd883abSJamin Lin g_assert_not_reached(); 2905dd883abSJamin Lin } 2915dd883abSJamin Lin 2925dd883abSJamin Lin for (i = 0; i < sc->num_cpus; i++) { 2935dd883abSJamin Lin object_initialize_child(obj, "cpu[*]", &a->cpu[i], 2945dd883abSJamin Lin aspeed_soc_cpu_type(sc)); 2955dd883abSJamin Lin } 2965dd883abSJamin Lin 2975dd883abSJamin Lin object_initialize_child(obj, "gic", &a->gic, gicv3_class_name()); 2985dd883abSJamin Lin 2995dd883abSJamin Lin object_initialize_child(obj, "scu", &s->scu, TYPE_ASPEED_2700_SCU); 3005dd883abSJamin Lin qdev_prop_set_uint32(DEVICE(&s->scu), "silicon-rev", 3015dd883abSJamin Lin sc->silicon_rev); 3025dd883abSJamin Lin object_property_add_alias(obj, "hw-strap1", OBJECT(&s->scu), 3035dd883abSJamin Lin "hw-strap1"); 3045dd883abSJamin Lin object_property_add_alias(obj, "hw-strap2", OBJECT(&s->scu), 3055dd883abSJamin Lin "hw-strap2"); 3065dd883abSJamin Lin object_property_add_alias(obj, "hw-prot-key", OBJECT(&s->scu), 3075dd883abSJamin Lin "hw-prot-key"); 3085dd883abSJamin Lin 3095dd883abSJamin Lin object_initialize_child(obj, "scuio", &s->scuio, TYPE_ASPEED_2700_SCUIO); 3105dd883abSJamin Lin qdev_prop_set_uint32(DEVICE(&s->scuio), "silicon-rev", 3115dd883abSJamin Lin sc->silicon_rev); 3125dd883abSJamin Lin 3135dd883abSJamin Lin snprintf(typename, sizeof(typename), "aspeed.fmc-%s", socname); 3145dd883abSJamin Lin object_initialize_child(obj, "fmc", &s->fmc, typename); 3155dd883abSJamin Lin 3165dd883abSJamin Lin for (i = 0; i < sc->spis_num; i++) { 3175dd883abSJamin Lin snprintf(typename, sizeof(typename), "aspeed.spi%d-%s", i, socname); 3185dd883abSJamin Lin object_initialize_child(obj, "spi[*]", &s->spi[i], typename); 3195dd883abSJamin Lin } 3205dd883abSJamin Lin 3215dd883abSJamin Lin snprintf(typename, sizeof(typename), "aspeed.sdmc-%s", socname); 3225dd883abSJamin Lin object_initialize_child(obj, "sdmc", &s->sdmc, typename); 3235dd883abSJamin Lin object_property_add_alias(obj, "ram-size", OBJECT(&s->sdmc), 3245dd883abSJamin Lin "ram-size"); 3255dd883abSJamin Lin 3265dd883abSJamin Lin for (i = 0; i < sc->wdts_num; i++) { 3275dd883abSJamin Lin snprintf(typename, sizeof(typename), "aspeed.wdt-%s", socname); 3285dd883abSJamin Lin object_initialize_child(obj, "wdt[*]", &s->wdt[i], typename); 3295dd883abSJamin Lin } 3305dd883abSJamin Lin 3315dd883abSJamin Lin for (i = 0; i < sc->macs_num; i++) { 3325dd883abSJamin Lin object_initialize_child(obj, "ftgmac100[*]", &s->ftgmac100[i], 3335dd883abSJamin Lin TYPE_FTGMAC100); 3345dd883abSJamin Lin 3355dd883abSJamin Lin object_initialize_child(obj, "mii[*]", &s->mii[i], TYPE_ASPEED_MII); 3365dd883abSJamin Lin } 3375dd883abSJamin Lin 3385dd883abSJamin Lin for (i = 0; i < sc->uarts_num; i++) { 3395dd883abSJamin Lin object_initialize_child(obj, "uart[*]", &s->uart[i], TYPE_SERIAL_MM); 3405dd883abSJamin Lin } 3415dd883abSJamin Lin 3425dd883abSJamin Lin object_initialize_child(obj, "sli", &s->sli, TYPE_ASPEED_2700_SLI); 3435dd883abSJamin Lin object_initialize_child(obj, "sliio", &s->sliio, TYPE_ASPEED_2700_SLIIO); 3445dd883abSJamin Lin object_initialize_child(obj, "intc", &a->intc, TYPE_ASPEED_2700_INTC); 3455dd883abSJamin Lin } 3465dd883abSJamin Lin 3475dd883abSJamin Lin /* 3485dd883abSJamin Lin * ASPEED ast2700 has 0x0 as cluster ID 3495dd883abSJamin Lin * 3505dd883abSJamin Lin * https://developer.arm.com/documentation/100236/0100/register-descriptions/aarch64-system-registers/multiprocessor-affinity-register--el1 3515dd883abSJamin Lin */ 3525dd883abSJamin Lin static uint64_t aspeed_calc_affinity(int cpu) 3535dd883abSJamin Lin { 3545dd883abSJamin Lin return (0x0 << ARM_AFF1_SHIFT) | cpu; 3555dd883abSJamin Lin } 3565dd883abSJamin Lin 3575dd883abSJamin Lin static bool aspeed_soc_ast2700_gic_realize(DeviceState *dev, Error **errp) 3585dd883abSJamin Lin { 3595dd883abSJamin Lin Aspeed27x0SoCState *a = ASPEED27X0_SOC(dev); 3605dd883abSJamin Lin AspeedSoCState *s = ASPEED_SOC(dev); 3615dd883abSJamin Lin AspeedSoCClass *sc = ASPEED_SOC_GET_CLASS(s); 3625dd883abSJamin Lin SysBusDevice *gicbusdev; 3635dd883abSJamin Lin DeviceState *gicdev; 3645dd883abSJamin Lin QList *redist_region_count; 3655dd883abSJamin Lin int i; 3665dd883abSJamin Lin 3675dd883abSJamin Lin gicbusdev = SYS_BUS_DEVICE(&a->gic); 3685dd883abSJamin Lin gicdev = DEVICE(&a->gic); 3695dd883abSJamin Lin qdev_prop_set_uint32(gicdev, "revision", 3); 3705dd883abSJamin Lin qdev_prop_set_uint32(gicdev, "num-cpu", sc->num_cpus); 3715dd883abSJamin Lin qdev_prop_set_uint32(gicdev, "num-irq", AST2700_MAX_IRQ); 3725dd883abSJamin Lin 3735dd883abSJamin Lin redist_region_count = qlist_new(); 3745dd883abSJamin Lin qlist_append_int(redist_region_count, sc->num_cpus); 3755dd883abSJamin Lin qdev_prop_set_array(gicdev, "redist-region-count", redist_region_count); 3765dd883abSJamin Lin 3775dd883abSJamin Lin if (!sysbus_realize(gicbusdev, errp)) { 3785dd883abSJamin Lin return false; 3795dd883abSJamin Lin } 3805dd883abSJamin Lin sysbus_mmio_map(gicbusdev, 0, sc->memmap[ASPEED_GIC_DIST]); 3815dd883abSJamin Lin sysbus_mmio_map(gicbusdev, 1, sc->memmap[ASPEED_GIC_REDIST]); 3825dd883abSJamin Lin 3835dd883abSJamin Lin for (i = 0; i < sc->num_cpus; i++) { 3845dd883abSJamin Lin DeviceState *cpudev = DEVICE(&a->cpu[i]); 3855dd883abSJamin Lin int NUM_IRQS = 256, ARCH_GIC_MAINT_IRQ = 9, VIRTUAL_PMU_IRQ = 7; 3865dd883abSJamin Lin int ppibase = NUM_IRQS + i * GIC_INTERNAL + GIC_NR_SGIS; 3875dd883abSJamin Lin 3885dd883abSJamin Lin const int timer_irq[] = { 3895dd883abSJamin Lin [GTIMER_PHYS] = 14, 3905dd883abSJamin Lin [GTIMER_VIRT] = 11, 3915dd883abSJamin Lin [GTIMER_HYP] = 10, 3925dd883abSJamin Lin [GTIMER_SEC] = 13, 3935dd883abSJamin Lin }; 3945dd883abSJamin Lin int j; 3955dd883abSJamin Lin 3965dd883abSJamin Lin for (j = 0; j < ARRAY_SIZE(timer_irq); j++) { 3975dd883abSJamin Lin qdev_connect_gpio_out(cpudev, j, 3985dd883abSJamin Lin qdev_get_gpio_in(gicdev, ppibase + timer_irq[j])); 3995dd883abSJamin Lin } 4005dd883abSJamin Lin 4015dd883abSJamin Lin qemu_irq irq = qdev_get_gpio_in(gicdev, 4025dd883abSJamin Lin ppibase + ARCH_GIC_MAINT_IRQ); 4035dd883abSJamin Lin qdev_connect_gpio_out_named(cpudev, "gicv3-maintenance-interrupt", 4045dd883abSJamin Lin 0, irq); 4055dd883abSJamin Lin qdev_connect_gpio_out_named(cpudev, "pmu-interrupt", 0, 4065dd883abSJamin Lin qdev_get_gpio_in(gicdev, ppibase + VIRTUAL_PMU_IRQ)); 4075dd883abSJamin Lin 4085dd883abSJamin Lin sysbus_connect_irq(gicbusdev, i, qdev_get_gpio_in(cpudev, ARM_CPU_IRQ)); 4095dd883abSJamin Lin sysbus_connect_irq(gicbusdev, i + sc->num_cpus, 4105dd883abSJamin Lin qdev_get_gpio_in(cpudev, ARM_CPU_FIQ)); 4115dd883abSJamin Lin sysbus_connect_irq(gicbusdev, i + 2 * sc->num_cpus, 4125dd883abSJamin Lin qdev_get_gpio_in(cpudev, ARM_CPU_VIRQ)); 4135dd883abSJamin Lin sysbus_connect_irq(gicbusdev, i + 3 * sc->num_cpus, 4145dd883abSJamin Lin qdev_get_gpio_in(cpudev, ARM_CPU_VFIQ)); 4155dd883abSJamin Lin } 4165dd883abSJamin Lin 4175dd883abSJamin Lin return true; 4185dd883abSJamin Lin } 4195dd883abSJamin Lin 4205dd883abSJamin Lin static void aspeed_soc_ast2700_realize(DeviceState *dev, Error **errp) 4215dd883abSJamin Lin { 4225dd883abSJamin Lin int i; 4235dd883abSJamin Lin Aspeed27x0SoCState *a = ASPEED27X0_SOC(dev); 4245dd883abSJamin Lin AspeedSoCState *s = ASPEED_SOC(dev); 4255dd883abSJamin Lin AspeedSoCClass *sc = ASPEED_SOC_GET_CLASS(s); 4265dd883abSJamin Lin AspeedINTCClass *ic = ASPEED_INTC_GET_CLASS(&a->intc); 4275dd883abSJamin Lin g_autofree char *sram_name = NULL; 4285dd883abSJamin Lin 4295dd883abSJamin Lin /* Default boot region (SPI memory or ROMs) */ 4305dd883abSJamin Lin memory_region_init(&s->spi_boot_container, OBJECT(s), 4315dd883abSJamin Lin "aspeed.spi_boot_container", 0x400000000); 4325dd883abSJamin Lin memory_region_add_subregion(s->memory, sc->memmap[ASPEED_DEV_SPI_BOOT], 4335dd883abSJamin Lin &s->spi_boot_container); 4345dd883abSJamin Lin 4355dd883abSJamin Lin /* CPU */ 4365dd883abSJamin Lin for (i = 0; i < sc->num_cpus; i++) { 4375dd883abSJamin Lin object_property_set_int(OBJECT(&a->cpu[i]), "mp-affinity", 4385dd883abSJamin Lin aspeed_calc_affinity(i), &error_abort); 4395dd883abSJamin Lin 4405dd883abSJamin Lin object_property_set_int(OBJECT(&a->cpu[i]), "cntfrq", 1125000000, 4415dd883abSJamin Lin &error_abort); 4425dd883abSJamin Lin object_property_set_link(OBJECT(&a->cpu[i]), "memory", 4435dd883abSJamin Lin OBJECT(s->memory), &error_abort); 4445dd883abSJamin Lin 4455dd883abSJamin Lin if (!qdev_realize(DEVICE(&a->cpu[i]), NULL, errp)) { 4465dd883abSJamin Lin return; 4475dd883abSJamin Lin } 4485dd883abSJamin Lin } 4495dd883abSJamin Lin 4505dd883abSJamin Lin /* GIC */ 4515dd883abSJamin Lin if (!aspeed_soc_ast2700_gic_realize(dev, errp)) { 4525dd883abSJamin Lin return; 4535dd883abSJamin Lin } 4545dd883abSJamin Lin 4555dd883abSJamin Lin /* INTC */ 4565dd883abSJamin Lin if (!sysbus_realize(SYS_BUS_DEVICE(&a->intc), errp)) { 4575dd883abSJamin Lin return; 4585dd883abSJamin Lin } 4595dd883abSJamin Lin 4605dd883abSJamin Lin aspeed_mmio_map(s, SYS_BUS_DEVICE(&a->intc), 0, 4615dd883abSJamin Lin sc->memmap[ASPEED_DEV_INTC]); 4625dd883abSJamin Lin 4635dd883abSJamin Lin /* GICINT orgates -> INTC -> GIC */ 4645dd883abSJamin Lin for (i = 0; i < ic->num_ints; i++) { 4655dd883abSJamin Lin qdev_connect_gpio_out(DEVICE(&a->intc.orgates[i]), 0, 4665dd883abSJamin Lin qdev_get_gpio_in(DEVICE(&a->intc), i)); 4675dd883abSJamin Lin sysbus_connect_irq(SYS_BUS_DEVICE(&a->intc), i, 4685dd883abSJamin Lin qdev_get_gpio_in(DEVICE(&a->gic), 4695dd883abSJamin Lin aspeed_soc_ast2700_gic_intcmap[i].irq)); 4705dd883abSJamin Lin } 4715dd883abSJamin Lin 4725dd883abSJamin Lin /* SRAM */ 4735dd883abSJamin Lin sram_name = g_strdup_printf("aspeed.sram.%d", CPU(&a->cpu[0])->cpu_index); 4745dd883abSJamin Lin if (!memory_region_init_ram(&s->sram, OBJECT(s), sram_name, sc->sram_size, 4755dd883abSJamin Lin errp)) { 4765dd883abSJamin Lin return; 4775dd883abSJamin Lin } 4785dd883abSJamin Lin memory_region_add_subregion(s->memory, 4795dd883abSJamin Lin sc->memmap[ASPEED_DEV_SRAM], &s->sram); 4805dd883abSJamin Lin 4815dd883abSJamin Lin /* SCU */ 4825dd883abSJamin Lin if (!sysbus_realize(SYS_BUS_DEVICE(&s->scu), errp)) { 4835dd883abSJamin Lin return; 4845dd883abSJamin Lin } 4855dd883abSJamin Lin aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->scu), 0, sc->memmap[ASPEED_DEV_SCU]); 4865dd883abSJamin Lin 4875dd883abSJamin Lin /* SCU1 */ 4885dd883abSJamin Lin if (!sysbus_realize(SYS_BUS_DEVICE(&s->scuio), errp)) { 4895dd883abSJamin Lin return; 4905dd883abSJamin Lin } 4915dd883abSJamin Lin aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->scuio), 0, 4925dd883abSJamin Lin sc->memmap[ASPEED_DEV_SCUIO]); 4935dd883abSJamin Lin 4945dd883abSJamin Lin /* UART */ 4955dd883abSJamin Lin if (!aspeed_soc_uart_realize(s, errp)) { 4965dd883abSJamin Lin return; 4975dd883abSJamin Lin } 4985dd883abSJamin Lin 4995dd883abSJamin Lin /* FMC, The number of CS is set at the board level */ 5005dd883abSJamin Lin object_property_set_int(OBJECT(&s->fmc), "dram-base", 5015dd883abSJamin Lin sc->memmap[ASPEED_DEV_SDRAM], 5025dd883abSJamin Lin &error_abort); 5035dd883abSJamin Lin object_property_set_link(OBJECT(&s->fmc), "dram", OBJECT(s->dram_mr), 5045dd883abSJamin Lin &error_abort); 5055dd883abSJamin Lin if (!sysbus_realize(SYS_BUS_DEVICE(&s->fmc), errp)) { 5065dd883abSJamin Lin return; 5075dd883abSJamin Lin } 5085dd883abSJamin Lin aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->fmc), 0, sc->memmap[ASPEED_DEV_FMC]); 5095dd883abSJamin Lin aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->fmc), 1, 5105dd883abSJamin Lin ASPEED_SMC_GET_CLASS(&s->fmc)->flash_window_base); 5115dd883abSJamin Lin sysbus_connect_irq(SYS_BUS_DEVICE(&s->fmc), 0, 5125dd883abSJamin Lin aspeed_soc_get_irq(s, ASPEED_DEV_FMC)); 5135dd883abSJamin Lin 5145dd883abSJamin Lin /* Set up an alias on the FMC CE0 region (boot default) */ 5155dd883abSJamin Lin MemoryRegion *fmc0_mmio = &s->fmc.flashes[0].mmio; 5165dd883abSJamin Lin memory_region_init_alias(&s->spi_boot, OBJECT(s), "aspeed.spi_boot", 5175dd883abSJamin Lin fmc0_mmio, 0, memory_region_size(fmc0_mmio)); 5185dd883abSJamin Lin memory_region_add_subregion(&s->spi_boot_container, 0x0, &s->spi_boot); 5195dd883abSJamin Lin 5205dd883abSJamin Lin /* SPI */ 5215dd883abSJamin Lin for (i = 0; i < sc->spis_num; i++) { 5225dd883abSJamin Lin object_property_set_link(OBJECT(&s->spi[i]), "dram", 5235dd883abSJamin Lin OBJECT(s->dram_mr), &error_abort); 5245dd883abSJamin Lin if (!sysbus_realize(SYS_BUS_DEVICE(&s->spi[i]), errp)) { 5255dd883abSJamin Lin return; 5265dd883abSJamin Lin } 5275dd883abSJamin Lin aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->spi[i]), 0, 5285dd883abSJamin Lin sc->memmap[ASPEED_DEV_SPI0 + i]); 5295dd883abSJamin Lin aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->spi[i]), 1, 5305dd883abSJamin Lin ASPEED_SMC_GET_CLASS(&s->spi[i])->flash_window_base); 5315dd883abSJamin Lin } 5325dd883abSJamin Lin 5335dd883abSJamin Lin /* 5345dd883abSJamin Lin * SDMC - SDRAM Memory Controller 5355dd883abSJamin Lin * The SDMC controller is unlocked at SPL stage. 5365dd883abSJamin Lin * At present, only supports to emulate booting 5375dd883abSJamin Lin * start from u-boot stage. Set SDMC controller 5385dd883abSJamin Lin * unlocked by default. It is a temporarily solution. 5395dd883abSJamin Lin */ 5405dd883abSJamin Lin object_property_set_bool(OBJECT(&s->sdmc), "unlocked", true, 5415dd883abSJamin Lin &error_abort); 5425dd883abSJamin Lin if (!sysbus_realize(SYS_BUS_DEVICE(&s->sdmc), errp)) { 5435dd883abSJamin Lin return; 5445dd883abSJamin Lin } 5455dd883abSJamin Lin aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->sdmc), 0, 5465dd883abSJamin Lin sc->memmap[ASPEED_DEV_SDMC]); 5475dd883abSJamin Lin 5485dd883abSJamin Lin /* RAM */ 549*7436db10SJamin Lin if (!aspeed_soc_ast2700_dram_init(dev, errp)) { 5505dd883abSJamin Lin return; 5515dd883abSJamin Lin } 5525dd883abSJamin Lin 5535dd883abSJamin Lin for (i = 0; i < sc->macs_num; i++) { 5545dd883abSJamin Lin object_property_set_bool(OBJECT(&s->ftgmac100[i]), "aspeed", true, 5555dd883abSJamin Lin &error_abort); 5565dd883abSJamin Lin if (!sysbus_realize(SYS_BUS_DEVICE(&s->ftgmac100[i]), errp)) { 5575dd883abSJamin Lin return; 5585dd883abSJamin Lin } 5595dd883abSJamin Lin aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->ftgmac100[i]), 0, 5605dd883abSJamin Lin sc->memmap[ASPEED_DEV_ETH1 + i]); 5615dd883abSJamin Lin sysbus_connect_irq(SYS_BUS_DEVICE(&s->ftgmac100[i]), 0, 5625dd883abSJamin Lin aspeed_soc_get_irq(s, ASPEED_DEV_ETH1 + i)); 5635dd883abSJamin Lin 5645dd883abSJamin Lin object_property_set_link(OBJECT(&s->mii[i]), "nic", 5655dd883abSJamin Lin OBJECT(&s->ftgmac100[i]), &error_abort); 5665dd883abSJamin Lin if (!sysbus_realize(SYS_BUS_DEVICE(&s->mii[i]), errp)) { 5675dd883abSJamin Lin return; 5685dd883abSJamin Lin } 5695dd883abSJamin Lin 5705dd883abSJamin Lin aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->mii[i]), 0, 5715dd883abSJamin Lin sc->memmap[ASPEED_DEV_MII1 + i]); 5725dd883abSJamin Lin } 5735dd883abSJamin Lin 5745dd883abSJamin Lin /* Watch dog */ 5755dd883abSJamin Lin for (i = 0; i < sc->wdts_num; i++) { 5765dd883abSJamin Lin AspeedWDTClass *awc = ASPEED_WDT_GET_CLASS(&s->wdt[i]); 5775dd883abSJamin Lin hwaddr wdt_offset = sc->memmap[ASPEED_DEV_WDT] + i * awc->iosize; 5785dd883abSJamin Lin 5795dd883abSJamin Lin object_property_set_link(OBJECT(&s->wdt[i]), "scu", OBJECT(&s->scu), 5805dd883abSJamin Lin &error_abort); 5815dd883abSJamin Lin if (!sysbus_realize(SYS_BUS_DEVICE(&s->wdt[i]), errp)) { 5825dd883abSJamin Lin return; 5835dd883abSJamin Lin } 5845dd883abSJamin Lin aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->wdt[i]), 0, wdt_offset); 5855dd883abSJamin Lin } 5865dd883abSJamin Lin 5875dd883abSJamin Lin /* SLI */ 5885dd883abSJamin Lin if (!sysbus_realize(SYS_BUS_DEVICE(&s->sli), errp)) { 5895dd883abSJamin Lin return; 5905dd883abSJamin Lin } 5915dd883abSJamin Lin aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->sli), 0, sc->memmap[ASPEED_DEV_SLI]); 5925dd883abSJamin Lin 5935dd883abSJamin Lin if (!sysbus_realize(SYS_BUS_DEVICE(&s->sliio), errp)) { 5945dd883abSJamin Lin return; 5955dd883abSJamin Lin } 5965dd883abSJamin Lin aspeed_mmio_map(s, SYS_BUS_DEVICE(&s->sliio), 0, 5975dd883abSJamin Lin sc->memmap[ASPEED_DEV_SLIIO]); 5985dd883abSJamin Lin 5995dd883abSJamin Lin create_unimplemented_device("ast2700.dpmcu", 0x11000000, 0x40000); 6005dd883abSJamin Lin create_unimplemented_device("ast2700.iomem0", 0x12000000, 0x01000000); 6015dd883abSJamin Lin create_unimplemented_device("ast2700.iomem1", 0x14000000, 0x01000000); 6025dd883abSJamin Lin create_unimplemented_device("ast2700.ltpi", 0x30000000, 0x1000000); 6035dd883abSJamin Lin create_unimplemented_device("ast2700.io", 0x0, 0x4000000); 6045dd883abSJamin Lin } 6055dd883abSJamin Lin 6065dd883abSJamin Lin static void aspeed_soc_ast2700_class_init(ObjectClass *oc, void *data) 6075dd883abSJamin Lin { 6085dd883abSJamin Lin static const char * const valid_cpu_types[] = { 6095dd883abSJamin Lin ARM_CPU_TYPE_NAME("cortex-a35"), 6105dd883abSJamin Lin NULL 6115dd883abSJamin Lin }; 6125dd883abSJamin Lin DeviceClass *dc = DEVICE_CLASS(oc); 6135dd883abSJamin Lin AspeedSoCClass *sc = ASPEED_SOC_CLASS(oc); 6145dd883abSJamin Lin 6155dd883abSJamin Lin /* Reason: The Aspeed SoC can only be instantiated from a board */ 6165dd883abSJamin Lin dc->user_creatable = false; 6175dd883abSJamin Lin dc->realize = aspeed_soc_ast2700_realize; 6185dd883abSJamin Lin 6195dd883abSJamin Lin sc->name = "ast2700-a0"; 6205dd883abSJamin Lin sc->valid_cpu_types = valid_cpu_types; 6215dd883abSJamin Lin sc->silicon_rev = AST2700_A0_SILICON_REV; 6225dd883abSJamin Lin sc->sram_size = 0x20000; 6235dd883abSJamin Lin sc->spis_num = 3; 6245dd883abSJamin Lin sc->wdts_num = 8; 6255dd883abSJamin Lin sc->macs_num = 1; 6265dd883abSJamin Lin sc->uarts_num = 13; 6275dd883abSJamin Lin sc->num_cpus = 4; 6285dd883abSJamin Lin sc->uarts_base = ASPEED_DEV_UART0; 6295dd883abSJamin Lin sc->irqmap = aspeed_soc_ast2700_irqmap; 6305dd883abSJamin Lin sc->memmap = aspeed_soc_ast2700_memmap; 6315dd883abSJamin Lin sc->get_irq = aspeed_soc_ast2700_get_irq; 6325dd883abSJamin Lin } 6335dd883abSJamin Lin 6345dd883abSJamin Lin static const TypeInfo aspeed_soc_ast27x0_types[] = { 6355dd883abSJamin Lin { 6365dd883abSJamin Lin .name = TYPE_ASPEED27X0_SOC, 6375dd883abSJamin Lin .parent = TYPE_ASPEED_SOC, 6385dd883abSJamin Lin .instance_size = sizeof(Aspeed27x0SoCState), 6395dd883abSJamin Lin .abstract = true, 6405dd883abSJamin Lin }, { 6415dd883abSJamin Lin .name = "ast2700-a0", 6425dd883abSJamin Lin .parent = TYPE_ASPEED27X0_SOC, 6435dd883abSJamin Lin .instance_init = aspeed_soc_ast2700_init, 6445dd883abSJamin Lin .class_init = aspeed_soc_ast2700_class_init, 6455dd883abSJamin Lin }, 6465dd883abSJamin Lin }; 6475dd883abSJamin Lin 6485dd883abSJamin Lin DEFINE_TYPES(aspeed_soc_ast27x0_types) 649