4 * Andrew Jeffery <andrew@aj.id.au>
5 * Jeremy Kerr <jk@ozlabs.org>
7 * Copyright 2016 IBM Corp.
9 * This code is licensed under the GPL version 2 or later. See
10 * the COPYING file in the top-level directory.
13 #include "qemu/osdep.h"
14 #include "qapi/error.h"
16 #include "exec/address-spaces.h"
17 #include "hw/misc/unimp.h"
18 #include "hw/arm/aspeed_soc.h"
19 #include "hw/char/serial.h"
21 #include "qemu/module.h"
22 #include "qemu/error-report.h"
23 #include "hw/i2c/aspeed_i2c.h"
25 #include "sysemu/sysemu.h"
27 #define ASPEED_SOC_IOMEM_SIZE 0x00200000
29 static const hwaddr aspeed_soc_ast2400_memmap
[] = {
30 [ASPEED_IOMEM
] = 0x1E600000,
31 [ASPEED_FMC
] = 0x1E620000,
32 [ASPEED_SPI1
] = 0x1E630000,
33 [ASPEED_EHCI1
] = 0x1E6A1000,
34 [ASPEED_VIC
] = 0x1E6C0000,
35 [ASPEED_SDMC
] = 0x1E6E0000,
36 [ASPEED_SCU
] = 0x1E6E2000,
37 [ASPEED_XDMA
] = 0x1E6E7000,
38 [ASPEED_VIDEO
] = 0x1E700000,
39 [ASPEED_ADC
] = 0x1E6E9000,
40 [ASPEED_SRAM
] = 0x1E720000,
41 [ASPEED_SDHCI
] = 0x1E740000,
42 [ASPEED_GPIO
] = 0x1E780000,
43 [ASPEED_RTC
] = 0x1E781000,
44 [ASPEED_TIMER1
] = 0x1E782000,
45 [ASPEED_WDT
] = 0x1E785000,
46 [ASPEED_PWM
] = 0x1E786000,
47 [ASPEED_LPC
] = 0x1E789000,
48 [ASPEED_IBT
] = 0x1E789140,
49 [ASPEED_I2C
] = 0x1E78A000,
50 [ASPEED_ETH1
] = 0x1E660000,
51 [ASPEED_ETH2
] = 0x1E680000,
52 [ASPEED_UART1
] = 0x1E783000,
53 [ASPEED_UART5
] = 0x1E784000,
54 [ASPEED_VUART
] = 0x1E787000,
55 [ASPEED_SDRAM
] = 0x40000000,
58 static const hwaddr aspeed_soc_ast2500_memmap
[] = {
59 [ASPEED_IOMEM
] = 0x1E600000,
60 [ASPEED_FMC
] = 0x1E620000,
61 [ASPEED_SPI1
] = 0x1E630000,
62 [ASPEED_SPI2
] = 0x1E631000,
63 [ASPEED_EHCI1
] = 0x1E6A1000,
64 [ASPEED_EHCI2
] = 0x1E6A3000,
65 [ASPEED_VIC
] = 0x1E6C0000,
66 [ASPEED_SDMC
] = 0x1E6E0000,
67 [ASPEED_SCU
] = 0x1E6E2000,
68 [ASPEED_XDMA
] = 0x1E6E7000,
69 [ASPEED_ADC
] = 0x1E6E9000,
70 [ASPEED_VIDEO
] = 0x1E700000,
71 [ASPEED_SRAM
] = 0x1E720000,
72 [ASPEED_SDHCI
] = 0x1E740000,
73 [ASPEED_GPIO
] = 0x1E780000,
74 [ASPEED_RTC
] = 0x1E781000,
75 [ASPEED_TIMER1
] = 0x1E782000,
76 [ASPEED_WDT
] = 0x1E785000,
77 [ASPEED_PWM
] = 0x1E786000,
78 [ASPEED_LPC
] = 0x1E789000,
79 [ASPEED_IBT
] = 0x1E789140,
80 [ASPEED_I2C
] = 0x1E78A000,
81 [ASPEED_ETH1
] = 0x1E660000,
82 [ASPEED_ETH2
] = 0x1E680000,
83 [ASPEED_UART1
] = 0x1E783000,
84 [ASPEED_UART5
] = 0x1E784000,
85 [ASPEED_VUART
] = 0x1E787000,
86 [ASPEED_SDRAM
] = 0x80000000,
89 static const int aspeed_soc_ast2400_irqmap
[] = {
104 [ASPEED_TIMER1
] = 16,
105 [ASPEED_TIMER2
] = 17,
106 [ASPEED_TIMER3
] = 18,
107 [ASPEED_TIMER4
] = 35,
108 [ASPEED_TIMER5
] = 36,
109 [ASPEED_TIMER6
] = 37,
110 [ASPEED_TIMER7
] = 38,
111 [ASPEED_TIMER8
] = 39,
115 [ASPEED_IBT
] = 8, /* LPC */
123 #define aspeed_soc_ast2500_irqmap aspeed_soc_ast2400_irqmap
125 static qemu_irq
aspeed_soc_get_irq(AspeedSoCState
*s
, int ctrl
)
127 AspeedSoCClass
*sc
= ASPEED_SOC_GET_CLASS(s
);
129 return qdev_get_gpio_in(DEVICE(&s
->vic
), sc
->irqmap
[ctrl
]);
132 static void aspeed_soc_init(Object
*obj
)
134 AspeedSoCState
*s
= ASPEED_SOC(obj
);
135 AspeedSoCClass
*sc
= ASPEED_SOC_GET_CLASS(s
);
140 if (sscanf(sc
->name
, "%7s", socname
) != 1) {
141 g_assert_not_reached();
144 for (i
= 0; i
< sc
->num_cpus
; i
++) {
145 object_initialize_child(obj
, "cpu[*]", OBJECT(&s
->cpu
[i
]),
146 sizeof(s
->cpu
[i
]), sc
->cpu_type
,
150 snprintf(typename
, sizeof(typename
), "aspeed.scu-%s", socname
);
151 sysbus_init_child_obj(obj
, "scu", OBJECT(&s
->scu
), sizeof(s
->scu
),
153 qdev_prop_set_uint32(DEVICE(&s
->scu
), "silicon-rev",
155 object_property_add_alias(obj
, "hw-strap1", OBJECT(&s
->scu
),
156 "hw-strap1", &error_abort
);
157 object_property_add_alias(obj
, "hw-strap2", OBJECT(&s
->scu
),
158 "hw-strap2", &error_abort
);
159 object_property_add_alias(obj
, "hw-prot-key", OBJECT(&s
->scu
),
160 "hw-prot-key", &error_abort
);
162 sysbus_init_child_obj(obj
, "vic", OBJECT(&s
->vic
), sizeof(s
->vic
),
165 sysbus_init_child_obj(obj
, "rtc", OBJECT(&s
->rtc
), sizeof(s
->rtc
),
168 snprintf(typename
, sizeof(typename
), "aspeed.timer-%s", socname
);
169 sysbus_init_child_obj(obj
, "timerctrl", OBJECT(&s
->timerctrl
),
170 sizeof(s
->timerctrl
), typename
);
172 snprintf(typename
, sizeof(typename
), "aspeed.i2c-%s", socname
);
173 sysbus_init_child_obj(obj
, "i2c", OBJECT(&s
->i2c
), sizeof(s
->i2c
),
176 snprintf(typename
, sizeof(typename
), "aspeed.fmc-%s", socname
);
177 sysbus_init_child_obj(obj
, "fmc", OBJECT(&s
->fmc
), sizeof(s
->fmc
),
179 object_property_add_alias(obj
, "num-cs", OBJECT(&s
->fmc
), "num-cs",
182 for (i
= 0; i
< sc
->spis_num
; i
++) {
183 snprintf(typename
, sizeof(typename
), "aspeed.spi%d-%s", i
+ 1, socname
);
184 sysbus_init_child_obj(obj
, "spi[*]", OBJECT(&s
->spi
[i
]),
185 sizeof(s
->spi
[i
]), typename
);
188 for (i
= 0; i
< sc
->ehcis_num
; i
++) {
189 sysbus_init_child_obj(obj
, "ehci[*]", OBJECT(&s
->ehci
[i
]),
190 sizeof(s
->ehci
[i
]), TYPE_PLATFORM_EHCI
);
193 snprintf(typename
, sizeof(typename
), "aspeed.sdmc-%s", socname
);
194 sysbus_init_child_obj(obj
, "sdmc", OBJECT(&s
->sdmc
), sizeof(s
->sdmc
),
196 object_property_add_alias(obj
, "ram-size", OBJECT(&s
->sdmc
),
197 "ram-size", &error_abort
);
198 object_property_add_alias(obj
, "max-ram-size", OBJECT(&s
->sdmc
),
199 "max-ram-size", &error_abort
);
201 for (i
= 0; i
< sc
->wdts_num
; i
++) {
202 snprintf(typename
, sizeof(typename
), "aspeed.wdt-%s", socname
);
203 sysbus_init_child_obj(obj
, "wdt[*]", OBJECT(&s
->wdt
[i
]),
204 sizeof(s
->wdt
[i
]), typename
);
207 for (i
= 0; i
< sc
->macs_num
; i
++) {
208 sysbus_init_child_obj(obj
, "ftgmac100[*]", OBJECT(&s
->ftgmac100
[i
]),
209 sizeof(s
->ftgmac100
[i
]), TYPE_FTGMAC100
);
212 sysbus_init_child_obj(obj
, "xdma", OBJECT(&s
->xdma
), sizeof(s
->xdma
),
215 snprintf(typename
, sizeof(typename
), "aspeed.gpio-%s", socname
);
216 sysbus_init_child_obj(obj
, "gpio", OBJECT(&s
->gpio
), sizeof(s
->gpio
),
219 sysbus_init_child_obj(obj
, "sdc", OBJECT(&s
->sdhci
), sizeof(s
->sdhci
),
222 object_property_set_int(OBJECT(&s
->sdhci
), 2, "num-slots", &error_abort
);
224 /* Init sd card slot class here so that they're under the correct parent */
225 for (i
= 0; i
< ASPEED_SDHCI_NUM_SLOTS
; ++i
) {
226 sysbus_init_child_obj(obj
, "sdhci[*]", OBJECT(&s
->sdhci
.slots
[i
]),
227 sizeof(s
->sdhci
.slots
[i
]), TYPE_SYSBUS_SDHCI
);
231 static void aspeed_soc_realize(DeviceState
*dev
, Error
**errp
)
234 AspeedSoCState
*s
= ASPEED_SOC(dev
);
235 AspeedSoCClass
*sc
= ASPEED_SOC_GET_CLASS(s
);
236 Error
*err
= NULL
, *local_err
= NULL
;
239 create_unimplemented_device("aspeed_soc.io", sc
->memmap
[ASPEED_IOMEM
],
240 ASPEED_SOC_IOMEM_SIZE
);
242 /* Video engine stub */
243 create_unimplemented_device("aspeed.video", sc
->memmap
[ASPEED_VIDEO
],
246 if (s
->num_cpus
> sc
->num_cpus
) {
247 warn_report("%s: invalid number of CPUs %d, using default %d",
248 sc
->name
, s
->num_cpus
, sc
->num_cpus
);
249 s
->num_cpus
= sc
->num_cpus
;
253 for (i
= 0; i
< s
->num_cpus
; i
++) {
254 object_property_set_bool(OBJECT(&s
->cpu
[i
]), true, "realized", &err
);
256 error_propagate(errp
, err
);
262 memory_region_init_ram(&s
->sram
, OBJECT(dev
), "aspeed.sram",
263 sc
->sram_size
, &err
);
265 error_propagate(errp
, err
);
268 memory_region_add_subregion(get_system_memory(),
269 sc
->memmap
[ASPEED_SRAM
], &s
->sram
);
272 object_property_set_bool(OBJECT(&s
->scu
), true, "realized", &err
);
274 error_propagate(errp
, err
);
277 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->scu
), 0, sc
->memmap
[ASPEED_SCU
]);
280 object_property_set_bool(OBJECT(&s
->vic
), true, "realized", &err
);
282 error_propagate(errp
, err
);
285 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->vic
), 0, sc
->memmap
[ASPEED_VIC
]);
286 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->vic
), 0,
287 qdev_get_gpio_in(DEVICE(&s
->cpu
), ARM_CPU_IRQ
));
288 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->vic
), 1,
289 qdev_get_gpio_in(DEVICE(&s
->cpu
), ARM_CPU_FIQ
));
292 object_property_set_bool(OBJECT(&s
->rtc
), true, "realized", &err
);
294 error_propagate(errp
, err
);
297 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->rtc
), 0, sc
->memmap
[ASPEED_RTC
]);
298 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->rtc
), 0,
299 aspeed_soc_get_irq(s
, ASPEED_RTC
));
302 object_property_set_link(OBJECT(&s
->timerctrl
),
303 OBJECT(&s
->scu
), "scu", &error_abort
);
304 object_property_set_bool(OBJECT(&s
->timerctrl
), true, "realized", &err
);
306 error_propagate(errp
, err
);
309 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->timerctrl
), 0,
310 sc
->memmap
[ASPEED_TIMER1
]);
311 for (i
= 0; i
< ASPEED_TIMER_NR_TIMERS
; i
++) {
312 qemu_irq irq
= aspeed_soc_get_irq(s
, ASPEED_TIMER1
+ i
);
313 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->timerctrl
), i
, irq
);
316 /* UART - attach an 8250 to the IO space as our UART5 */
318 qemu_irq uart5
= aspeed_soc_get_irq(s
, ASPEED_UART5
);
319 serial_mm_init(get_system_memory(), sc
->memmap
[ASPEED_UART5
], 2,
320 uart5
, 38400, serial_hd(0), DEVICE_LITTLE_ENDIAN
);
324 object_property_set_link(OBJECT(&s
->i2c
), OBJECT(s
->dram_mr
), "dram", &err
);
326 error_propagate(errp
, err
);
329 object_property_set_bool(OBJECT(&s
->i2c
), true, "realized", &err
);
331 error_propagate(errp
, err
);
334 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->i2c
), 0, sc
->memmap
[ASPEED_I2C
]);
335 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->i2c
), 0,
336 aspeed_soc_get_irq(s
, ASPEED_I2C
));
338 /* FMC, The number of CS is set at the board level */
339 object_property_set_link(OBJECT(&s
->fmc
), OBJECT(s
->dram_mr
), "dram", &err
);
341 error_propagate(errp
, err
);
344 object_property_set_int(OBJECT(&s
->fmc
), sc
->memmap
[ASPEED_SDRAM
],
347 error_propagate(errp
, err
);
350 object_property_set_bool(OBJECT(&s
->fmc
), true, "realized", &err
);
352 error_propagate(errp
, err
);
355 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->fmc
), 0, sc
->memmap
[ASPEED_FMC
]);
356 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->fmc
), 1,
357 s
->fmc
.ctrl
->flash_window_base
);
358 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->fmc
), 0,
359 aspeed_soc_get_irq(s
, ASPEED_FMC
));
362 for (i
= 0; i
< sc
->spis_num
; i
++) {
363 object_property_set_int(OBJECT(&s
->spi
[i
]), 1, "num-cs", &err
);
364 object_property_set_bool(OBJECT(&s
->spi
[i
]), true, "realized",
366 error_propagate(&err
, local_err
);
368 error_propagate(errp
, err
);
371 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->spi
[i
]), 0,
372 sc
->memmap
[ASPEED_SPI1
+ i
]);
373 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->spi
[i
]), 1,
374 s
->spi
[i
].ctrl
->flash_window_base
);
378 for (i
= 0; i
< sc
->ehcis_num
; i
++) {
379 object_property_set_bool(OBJECT(&s
->ehci
[i
]), true, "realized", &err
);
381 error_propagate(errp
, err
);
384 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->ehci
[i
]), 0,
385 sc
->memmap
[ASPEED_EHCI1
+ i
]);
386 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->ehci
[i
]), 0,
387 aspeed_soc_get_irq(s
, ASPEED_EHCI1
+ i
));
390 /* SDMC - SDRAM Memory Controller */
391 object_property_set_bool(OBJECT(&s
->sdmc
), true, "realized", &err
);
393 error_propagate(errp
, err
);
396 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->sdmc
), 0, sc
->memmap
[ASPEED_SDMC
]);
399 for (i
= 0; i
< sc
->wdts_num
; i
++) {
400 AspeedWDTClass
*awc
= ASPEED_WDT_GET_CLASS(&s
->wdt
[i
]);
402 object_property_set_link(OBJECT(&s
->wdt
[i
]),
403 OBJECT(&s
->scu
), "scu", &error_abort
);
404 object_property_set_bool(OBJECT(&s
->wdt
[i
]), true, "realized", &err
);
406 error_propagate(errp
, err
);
409 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->wdt
[i
]), 0,
410 sc
->memmap
[ASPEED_WDT
] + i
* awc
->offset
);
414 for (i
= 0; i
< nb_nics
&& i
< sc
->macs_num
; i
++) {
415 qdev_set_nic_properties(DEVICE(&s
->ftgmac100
[i
]), &nd_table
[i
]);
416 object_property_set_bool(OBJECT(&s
->ftgmac100
[i
]), true, "aspeed",
418 object_property_set_bool(OBJECT(&s
->ftgmac100
[i
]), true, "realized",
420 error_propagate(&err
, local_err
);
422 error_propagate(errp
, err
);
425 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->ftgmac100
[i
]), 0,
426 sc
->memmap
[ASPEED_ETH1
+ i
]);
427 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->ftgmac100
[i
]), 0,
428 aspeed_soc_get_irq(s
, ASPEED_ETH1
+ i
));
432 object_property_set_bool(OBJECT(&s
->xdma
), true, "realized", &err
);
434 error_propagate(errp
, err
);
437 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->xdma
), 0,
438 sc
->memmap
[ASPEED_XDMA
]);
439 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->xdma
), 0,
440 aspeed_soc_get_irq(s
, ASPEED_XDMA
));
443 object_property_set_bool(OBJECT(&s
->gpio
), true, "realized", &err
);
445 error_propagate(errp
, err
);
448 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->gpio
), 0, sc
->memmap
[ASPEED_GPIO
]);
449 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->gpio
), 0,
450 aspeed_soc_get_irq(s
, ASPEED_GPIO
));
453 object_property_set_bool(OBJECT(&s
->sdhci
), true, "realized", &err
);
455 error_propagate(errp
, err
);
458 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->sdhci
), 0,
459 sc
->memmap
[ASPEED_SDHCI
]);
460 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->sdhci
), 0,
461 aspeed_soc_get_irq(s
, ASPEED_SDHCI
));
463 static Property aspeed_soc_properties
[] = {
464 DEFINE_PROP_UINT32("num-cpus", AspeedSoCState
, num_cpus
, 0),
465 DEFINE_PROP_LINK("dram", AspeedSoCState
, dram_mr
, TYPE_MEMORY_REGION
,
467 DEFINE_PROP_END_OF_LIST(),
470 static void aspeed_soc_class_init(ObjectClass
*oc
, void *data
)
472 DeviceClass
*dc
= DEVICE_CLASS(oc
);
474 dc
->realize
= aspeed_soc_realize
;
475 /* Reason: Uses serial_hds and nd_table in realize() directly */
476 dc
->user_creatable
= false;
477 device_class_set_props(dc
, aspeed_soc_properties
);
480 static const TypeInfo aspeed_soc_type_info
= {
481 .name
= TYPE_ASPEED_SOC
,
482 .parent
= TYPE_DEVICE
,
483 .instance_size
= sizeof(AspeedSoCState
),
484 .class_size
= sizeof(AspeedSoCClass
),
485 .class_init
= aspeed_soc_class_init
,
489 static void aspeed_soc_ast2400_class_init(ObjectClass
*oc
, void *data
)
491 AspeedSoCClass
*sc
= ASPEED_SOC_CLASS(oc
);
493 sc
->name
= "ast2400-a1";
494 sc
->cpu_type
= ARM_CPU_TYPE_NAME("arm926");
495 sc
->silicon_rev
= AST2400_A1_SILICON_REV
;
496 sc
->sram_size
= 0x8000;
501 sc
->irqmap
= aspeed_soc_ast2400_irqmap
;
502 sc
->memmap
= aspeed_soc_ast2400_memmap
;
506 static const TypeInfo aspeed_soc_ast2400_type_info
= {
507 .name
= "ast2400-a1",
508 .parent
= TYPE_ASPEED_SOC
,
509 .instance_init
= aspeed_soc_init
,
510 .instance_size
= sizeof(AspeedSoCState
),
511 .class_init
= aspeed_soc_ast2400_class_init
,
514 static void aspeed_soc_ast2500_class_init(ObjectClass
*oc
, void *data
)
516 AspeedSoCClass
*sc
= ASPEED_SOC_CLASS(oc
);
518 sc
->name
= "ast2500-a1";
519 sc
->cpu_type
= ARM_CPU_TYPE_NAME("arm1176");
520 sc
->silicon_rev
= AST2500_A1_SILICON_REV
;
521 sc
->sram_size
= 0x9000;
526 sc
->irqmap
= aspeed_soc_ast2500_irqmap
;
527 sc
->memmap
= aspeed_soc_ast2500_memmap
;
531 static const TypeInfo aspeed_soc_ast2500_type_info
= {
532 .name
= "ast2500-a1",
533 .parent
= TYPE_ASPEED_SOC
,
534 .instance_init
= aspeed_soc_init
,
535 .instance_size
= sizeof(AspeedSoCState
),
536 .class_init
= aspeed_soc_ast2500_class_init
,
538 static void aspeed_soc_register_types(void)
540 type_register_static(&aspeed_soc_type_info
);
541 type_register_static(&aspeed_soc_ast2400_type_info
);
542 type_register_static(&aspeed_soc_ast2500_type_info
);
545 type_init(aspeed_soc_register_types
)