xref: /openbmc/qemu/hw/arm/aspeed.c (revision 2f35254aa0403ed527fc8ec379e5f7fdf2184e85)
1 /*
2  * OpenPOWER Palmetto BMC
3  *
4  * Andrew Jeffery <andrew@aj.id.au>
5  *
6  * Copyright 2016 IBM Corp.
7  *
8  * This code is licensed under the GPL version 2 or later.  See
9  * the COPYING file in the top-level directory.
10  */
11 
12 #include "qemu/osdep.h"
13 #include "qapi/error.h"
14 #include "cpu.h"
15 #include "exec/address-spaces.h"
16 #include "hw/arm/boot.h"
17 #include "hw/arm/aspeed.h"
18 #include "hw/arm/aspeed_soc.h"
19 #include "hw/boards.h"
20 #include "hw/i2c/smbus_eeprom.h"
21 #include "hw/misc/pca9552.h"
22 #include "hw/misc/tmp105.h"
23 #include "hw/qdev-properties.h"
24 #include "qemu/log.h"
25 #include "sysemu/block-backend.h"
26 #include "sysemu/sysemu.h"
27 #include "hw/loader.h"
28 #include "qemu/error-report.h"
29 #include "qemu/units.h"
30 
31 static struct arm_boot_info aspeed_board_binfo = {
32     .board_id = -1, /* device-tree-only board */
33 };
34 
35 struct AspeedBoardState {
36     AspeedSoCState soc;
37     MemoryRegion ram_container;
38     MemoryRegion max_ram;
39 };
40 
41 /* Palmetto hardware value: 0x120CE416 */
42 #define PALMETTO_BMC_HW_STRAP1 (                                        \
43         SCU_AST2400_HW_STRAP_DRAM_SIZE(DRAM_SIZE_256MB) |               \
44         SCU_AST2400_HW_STRAP_DRAM_CONFIG(2 /* DDR3 with CL=6, CWL=5 */) | \
45         SCU_AST2400_HW_STRAP_ACPI_DIS |                                 \
46         SCU_AST2400_HW_STRAP_SET_CLK_SOURCE(AST2400_CLK_48M_IN) |       \
47         SCU_HW_STRAP_VGA_CLASS_CODE |                                   \
48         SCU_HW_STRAP_LPC_RESET_PIN |                                    \
49         SCU_HW_STRAP_SPI_MODE(SCU_HW_STRAP_SPI_M_S_EN) |                \
50         SCU_AST2400_HW_STRAP_SET_CPU_AHB_RATIO(AST2400_CPU_AHB_RATIO_2_1) | \
51         SCU_HW_STRAP_SPI_WIDTH |                                        \
52         SCU_HW_STRAP_VGA_SIZE_SET(VGA_16M_DRAM) |                       \
53         SCU_AST2400_HW_STRAP_BOOT_MODE(AST2400_SPI_BOOT))
54 
55 /* AST2500 evb hardware value: 0xF100C2E6 */
56 #define AST2500_EVB_HW_STRAP1 ((                                        \
57         AST2500_HW_STRAP1_DEFAULTS |                                    \
58         SCU_AST2500_HW_STRAP_SPI_AUTOFETCH_ENABLE |                     \
59         SCU_AST2500_HW_STRAP_GPIO_STRAP_ENABLE |                        \
60         SCU_AST2500_HW_STRAP_UART_DEBUG |                               \
61         SCU_AST2500_HW_STRAP_DDR4_ENABLE |                              \
62         SCU_HW_STRAP_MAC1_RGMII |                                       \
63         SCU_HW_STRAP_MAC0_RGMII) &                                      \
64         ~SCU_HW_STRAP_2ND_BOOT_WDT)
65 
66 /* Romulus hardware value: 0xF10AD206 */
67 #define ROMULUS_BMC_HW_STRAP1 (                                         \
68         AST2500_HW_STRAP1_DEFAULTS |                                    \
69         SCU_AST2500_HW_STRAP_SPI_AUTOFETCH_ENABLE |                     \
70         SCU_AST2500_HW_STRAP_GPIO_STRAP_ENABLE |                        \
71         SCU_AST2500_HW_STRAP_UART_DEBUG |                               \
72         SCU_AST2500_HW_STRAP_DDR4_ENABLE |                              \
73         SCU_AST2500_HW_STRAP_ACPI_ENABLE |                              \
74         SCU_HW_STRAP_SPI_MODE(SCU_HW_STRAP_SPI_MASTER))
75 
76 /* Sonorapass hardware value: 0xF100D216 */
77 #define SONORAPASS_BMC_HW_STRAP1 (                                      \
78         SCU_AST2500_HW_STRAP_SPI_AUTOFETCH_ENABLE |                     \
79         SCU_AST2500_HW_STRAP_GPIO_STRAP_ENABLE |                        \
80         SCU_AST2500_HW_STRAP_UART_DEBUG |                               \
81         SCU_AST2500_HW_STRAP_RESERVED28 |                               \
82         SCU_AST2500_HW_STRAP_DDR4_ENABLE |                              \
83         SCU_HW_STRAP_VGA_CLASS_CODE |                                   \
84         SCU_HW_STRAP_LPC_RESET_PIN |                                    \
85         SCU_HW_STRAP_SPI_MODE(SCU_HW_STRAP_SPI_MASTER) |                \
86         SCU_AST2500_HW_STRAP_SET_AXI_AHB_RATIO(AXI_AHB_RATIO_2_1) |     \
87         SCU_HW_STRAP_VGA_BIOS_ROM |                                     \
88         SCU_HW_STRAP_VGA_SIZE_SET(VGA_16M_DRAM) |                       \
89         SCU_AST2500_HW_STRAP_RESERVED1)
90 
91 /* Swift hardware value: 0xF11AD206 */
92 #define SWIFT_BMC_HW_STRAP1 (                                           \
93         AST2500_HW_STRAP1_DEFAULTS |                                    \
94         SCU_AST2500_HW_STRAP_SPI_AUTOFETCH_ENABLE |                     \
95         SCU_AST2500_HW_STRAP_GPIO_STRAP_ENABLE |                        \
96         SCU_AST2500_HW_STRAP_UART_DEBUG |                               \
97         SCU_AST2500_HW_STRAP_DDR4_ENABLE |                              \
98         SCU_H_PLL_BYPASS_EN |                                           \
99         SCU_AST2500_HW_STRAP_ACPI_ENABLE |                              \
100         SCU_HW_STRAP_SPI_MODE(SCU_HW_STRAP_SPI_MASTER))
101 
102 /* Witherspoon hardware value: 0xF10AD216 (but use romulus definition) */
103 #define WITHERSPOON_BMC_HW_STRAP1 ROMULUS_BMC_HW_STRAP1
104 
105 /* AST2600 evb hardware value */
106 #define AST2600_EVB_HW_STRAP1 0x000000C0
107 #define AST2600_EVB_HW_STRAP2 0x00000003
108 
109 /* Tacoma hardware value */
110 #define TACOMA_BMC_HW_STRAP1  0x00000000
111 #define TACOMA_BMC_HW_STRAP2  0x00000040
112 
113 /*
114  * The max ram region is for firmwares that scan the address space
115  * with load/store to guess how much RAM the SoC has.
116  */
117 static uint64_t max_ram_read(void *opaque, hwaddr offset, unsigned size)
118 {
119     return 0;
120 }
121 
122 static void max_ram_write(void *opaque, hwaddr offset, uint64_t value,
123                            unsigned size)
124 {
125     /* Discard writes */
126 }
127 
128 static const MemoryRegionOps max_ram_ops = {
129     .read = max_ram_read,
130     .write = max_ram_write,
131     .endianness = DEVICE_NATIVE_ENDIAN,
132 };
133 
134 #define AST_SMP_MAILBOX_BASE            0x1e6e2180
135 #define AST_SMP_MBOX_FIELD_ENTRY        (AST_SMP_MAILBOX_BASE + 0x0)
136 #define AST_SMP_MBOX_FIELD_GOSIGN       (AST_SMP_MAILBOX_BASE + 0x4)
137 #define AST_SMP_MBOX_FIELD_READY        (AST_SMP_MAILBOX_BASE + 0x8)
138 #define AST_SMP_MBOX_FIELD_POLLINSN     (AST_SMP_MAILBOX_BASE + 0xc)
139 #define AST_SMP_MBOX_CODE               (AST_SMP_MAILBOX_BASE + 0x10)
140 #define AST_SMP_MBOX_GOSIGN             0xabbaab00
141 
142 static void aspeed_write_smpboot(ARMCPU *cpu,
143                                  const struct arm_boot_info *info)
144 {
145     static const uint32_t poll_mailbox_ready[] = {
146         /*
147          * r2 = per-cpu go sign value
148          * r1 = AST_SMP_MBOX_FIELD_ENTRY
149          * r0 = AST_SMP_MBOX_FIELD_GOSIGN
150          */
151         0xee100fb0,  /* mrc     p15, 0, r0, c0, c0, 5 */
152         0xe21000ff,  /* ands    r0, r0, #255          */
153         0xe59f201c,  /* ldr     r2, [pc, #28]         */
154         0xe1822000,  /* orr     r2, r2, r0            */
155 
156         0xe59f1018,  /* ldr     r1, [pc, #24]         */
157         0xe59f0018,  /* ldr     r0, [pc, #24]         */
158 
159         0xe320f002,  /* wfe                           */
160         0xe5904000,  /* ldr     r4, [r0]              */
161         0xe1520004,  /* cmp     r2, r4                */
162         0x1afffffb,  /* bne     <wfe>                 */
163         0xe591f000,  /* ldr     pc, [r1]              */
164         AST_SMP_MBOX_GOSIGN,
165         AST_SMP_MBOX_FIELD_ENTRY,
166         AST_SMP_MBOX_FIELD_GOSIGN,
167     };
168 
169     rom_add_blob_fixed("aspeed.smpboot", poll_mailbox_ready,
170                        sizeof(poll_mailbox_ready),
171                        info->smp_loader_start);
172 }
173 
174 static void aspeed_reset_secondary(ARMCPU *cpu,
175                                    const struct arm_boot_info *info)
176 {
177     AddressSpace *as = arm_boot_address_space(cpu, info);
178     CPUState *cs = CPU(cpu);
179 
180     /* info->smp_bootreg_addr */
181     address_space_stl_notdirty(as, AST_SMP_MBOX_FIELD_GOSIGN, 0,
182                                MEMTXATTRS_UNSPECIFIED, NULL);
183     cpu_set_pc(cs, info->smp_loader_start);
184 }
185 
186 #define FIRMWARE_ADDR 0x0
187 
188 static void write_boot_rom(DriveInfo *dinfo, hwaddr addr, size_t rom_size,
189                            Error **errp)
190 {
191     BlockBackend *blk = blk_by_legacy_dinfo(dinfo);
192     uint8_t *storage;
193     int64_t size;
194 
195     /* The block backend size should have already been 'validated' by
196      * the creation of the m25p80 object.
197      */
198     size = blk_getlength(blk);
199     if (size <= 0) {
200         error_setg(errp, "failed to get flash size");
201         return;
202     }
203 
204     if (rom_size > size) {
205         rom_size = size;
206     }
207 
208     storage = g_new0(uint8_t, rom_size);
209     if (blk_pread(blk, 0, storage, rom_size) < 0) {
210         error_setg(errp, "failed to read the initial flash content");
211         return;
212     }
213 
214     rom_add_blob_fixed("aspeed.boot_rom", storage, rom_size, addr);
215     g_free(storage);
216 }
217 
218 static void aspeed_board_init_flashes(AspeedSMCState *s, const char *flashtype,
219                                       Error **errp)
220 {
221     int i ;
222 
223     for (i = 0; i < s->num_cs; ++i) {
224         AspeedSMCFlash *fl = &s->flashes[i];
225         DriveInfo *dinfo = drive_get_next(IF_MTD);
226         qemu_irq cs_line;
227 
228         fl->flash = ssi_create_slave_no_init(s->spi, flashtype);
229         if (dinfo) {
230             qdev_prop_set_drive(fl->flash, "drive", blk_by_legacy_dinfo(dinfo),
231                                 errp);
232         }
233         qdev_init_nofail(fl->flash);
234 
235         cs_line = qdev_get_gpio_in_named(fl->flash, SSI_GPIO_CS, 0);
236         sysbus_connect_irq(SYS_BUS_DEVICE(s), i + 1, cs_line);
237     }
238 }
239 
240 static void sdhci_attach_drive(SDHCIState *sdhci, DriveInfo *dinfo)
241 {
242         DeviceState *card;
243 
244         card = qdev_create(qdev_get_child_bus(DEVICE(sdhci), "sd-bus"),
245                            TYPE_SD_CARD);
246         if (dinfo) {
247             qdev_prop_set_drive(card, "drive", blk_by_legacy_dinfo(dinfo),
248                                 &error_fatal);
249         }
250         object_property_set_bool(OBJECT(card), true, "realized", &error_fatal);
251 }
252 
253 static void aspeed_machine_init(MachineState *machine)
254 {
255     AspeedBoardState *bmc;
256     AspeedMachineClass *amc = ASPEED_MACHINE_GET_CLASS(machine);
257     AspeedSoCClass *sc;
258     DriveInfo *drive0 = drive_get(IF_MTD, 0, 0);
259     ram_addr_t max_ram_size;
260     int i;
261     NICInfo *nd = &nd_table[0];
262 
263     bmc = g_new0(AspeedBoardState, 1);
264 
265     memory_region_init(&bmc->ram_container, NULL, "aspeed-ram-container",
266                        4 * GiB);
267     memory_region_add_subregion(&bmc->ram_container, 0, machine->ram);
268 
269     object_initialize_child(OBJECT(machine), "soc", &bmc->soc,
270                             (sizeof(bmc->soc)), amc->soc_name, &error_abort,
271                             NULL);
272 
273     sc = ASPEED_SOC_GET_CLASS(&bmc->soc);
274 
275     /*
276      * This will error out if isize is not supported by memory controller.
277      */
278     object_property_set_uint(OBJECT(&bmc->soc), ram_size, "ram-size",
279                              &error_fatal);
280 
281     for (i = 0; i < sc->macs_num; i++) {
282         if ((amc->macs_mask & (1 << i)) && nd->used) {
283             qemu_check_nic_model(nd, TYPE_FTGMAC100);
284             qdev_set_nic_properties(DEVICE(&bmc->soc.ftgmac100[i]), nd);
285             nd++;
286         }
287     }
288 
289     object_property_set_int(OBJECT(&bmc->soc), amc->hw_strap1, "hw-strap1",
290                             &error_abort);
291     object_property_set_int(OBJECT(&bmc->soc), amc->hw_strap2, "hw-strap2",
292                             &error_abort);
293     object_property_set_int(OBJECT(&bmc->soc), amc->num_cs, "num-cs",
294                             &error_abort);
295     object_property_set_link(OBJECT(&bmc->soc), OBJECT(&bmc->ram_container),
296                              "dram", &error_abort);
297     if (machine->kernel_filename) {
298         /*
299          * When booting with a -kernel command line there is no u-boot
300          * that runs to unlock the SCU. In this case set the default to
301          * be unlocked as the kernel expects
302          */
303         object_property_set_int(OBJECT(&bmc->soc), ASPEED_SCU_PROT_KEY,
304                                 "hw-prot-key", &error_abort);
305     }
306     object_property_set_bool(OBJECT(&bmc->soc), true, "realized",
307                              &error_abort);
308 
309     memory_region_add_subregion(get_system_memory(),
310                                 sc->memmap[ASPEED_SDRAM],
311                                 &bmc->ram_container);
312 
313     max_ram_size = object_property_get_uint(OBJECT(&bmc->soc), "max-ram-size",
314                                             &error_abort);
315     memory_region_init_io(&bmc->max_ram, NULL, &max_ram_ops, NULL,
316                           "max_ram", max_ram_size  - ram_size);
317     memory_region_add_subregion(&bmc->ram_container, ram_size, &bmc->max_ram);
318 
319     aspeed_board_init_flashes(&bmc->soc.fmc, amc->fmc_model, &error_abort);
320     aspeed_board_init_flashes(&bmc->soc.spi[0], amc->spi_model, &error_abort);
321 
322     /* Install first FMC flash content as a boot rom. */
323     if (drive0) {
324         AspeedSMCFlash *fl = &bmc->soc.fmc.flashes[0];
325         MemoryRegion *boot_rom = g_new(MemoryRegion, 1);
326 
327         /*
328          * create a ROM region using the default mapping window size of
329          * the flash module. The window size is 64MB for the AST2400
330          * SoC and 128MB for the AST2500 SoC, which is twice as big as
331          * needed by the flash modules of the Aspeed machines.
332          */
333         if (ASPEED_MACHINE(machine)->mmio_exec) {
334             memory_region_init_alias(boot_rom, OBJECT(bmc), "aspeed.boot_rom",
335                                      &fl->mmio, 0, fl->size);
336             memory_region_add_subregion(get_system_memory(), FIRMWARE_ADDR,
337                                         boot_rom);
338         } else {
339             memory_region_init_rom(boot_rom, OBJECT(bmc), "aspeed.boot_rom",
340                                    fl->size, &error_abort);
341             memory_region_add_subregion(get_system_memory(), FIRMWARE_ADDR,
342                                         boot_rom);
343             write_boot_rom(drive0, FIRMWARE_ADDR, fl->size, &error_abort);
344         }
345     }
346 
347     if (machine->kernel_filename && sc->num_cpus > 1) {
348         /* With no u-boot we must set up a boot stub for the secondary CPU */
349         MemoryRegion *smpboot = g_new(MemoryRegion, 1);
350         memory_region_init_ram(smpboot, OBJECT(bmc), "aspeed.smpboot",
351                                0x80, &error_abort);
352         memory_region_add_subregion(get_system_memory(),
353                                     AST_SMP_MAILBOX_BASE, smpboot);
354 
355         aspeed_board_binfo.write_secondary_boot = aspeed_write_smpboot;
356         aspeed_board_binfo.secondary_cpu_reset_hook = aspeed_reset_secondary;
357         aspeed_board_binfo.smp_loader_start = AST_SMP_MBOX_CODE;
358     }
359 
360     aspeed_board_binfo.ram_size = ram_size;
361     aspeed_board_binfo.loader_start = sc->memmap[ASPEED_SDRAM];
362     aspeed_board_binfo.nb_cpus = sc->num_cpus;
363 
364     if (amc->i2c_init) {
365         amc->i2c_init(bmc);
366     }
367 
368     for (i = 0; i < bmc->soc.sdhci.num_slots; i++) {
369         sdhci_attach_drive(&bmc->soc.sdhci.slots[i], drive_get_next(IF_SD));
370     }
371 
372     if (bmc->soc.emmc.num_slots) {
373         sdhci_attach_drive(&bmc->soc.emmc.slots[0], drive_get_next(IF_SD));
374     }
375 
376     arm_load_kernel(ARM_CPU(first_cpu), machine, &aspeed_board_binfo);
377 }
378 
379 static void palmetto_bmc_i2c_init(AspeedBoardState *bmc)
380 {
381     AspeedSoCState *soc = &bmc->soc;
382     DeviceState *dev;
383     uint8_t *eeprom_buf = g_malloc0(32 * 1024);
384 
385     /* The palmetto platform expects a ds3231 RTC but a ds1338 is
386      * enough to provide basic RTC features. Alarms will be missing */
387     i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 0), "ds1338", 0x68);
388 
389     smbus_eeprom_init_one(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 0), 0x50,
390                           eeprom_buf);
391 
392     /* add a TMP423 temperature sensor */
393     dev = i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 2),
394                            "tmp423", 0x4c);
395     object_property_set_int(OBJECT(dev), 31000, "temperature0", &error_abort);
396     object_property_set_int(OBJECT(dev), 28000, "temperature1", &error_abort);
397     object_property_set_int(OBJECT(dev), 20000, "temperature2", &error_abort);
398     object_property_set_int(OBJECT(dev), 110000, "temperature3", &error_abort);
399 }
400 
401 static void ast2500_evb_i2c_init(AspeedBoardState *bmc)
402 {
403     AspeedSoCState *soc = &bmc->soc;
404     uint8_t *eeprom_buf = g_malloc0(8 * 1024);
405 
406     smbus_eeprom_init_one(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 3), 0x50,
407                           eeprom_buf);
408 
409     /* The AST2500 EVB expects a LM75 but a TMP105 is compatible */
410     i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 7),
411                      TYPE_TMP105, 0x4d);
412 
413     /* The AST2500 EVB does not have an RTC. Let's pretend that one is
414      * plugged on the I2C bus header */
415     i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 11), "ds1338", 0x32);
416 }
417 
418 static void ast2600_evb_i2c_init(AspeedBoardState *bmc)
419 {
420     /* Start with some devices on our I2C busses */
421     ast2500_evb_i2c_init(bmc);
422 }
423 
424 static void romulus_bmc_i2c_init(AspeedBoardState *bmc)
425 {
426     AspeedSoCState *soc = &bmc->soc;
427 
428     /* The romulus board expects Epson RX8900 I2C RTC but a ds1338 is
429      * good enough */
430     i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 11), "ds1338", 0x32);
431 }
432 
433 static void swift_bmc_i2c_init(AspeedBoardState *bmc)
434 {
435     AspeedSoCState *soc = &bmc->soc;
436 
437     i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 3), "pca9552", 0x60);
438 
439     /* The swift board expects a TMP275 but a TMP105 is compatible */
440     i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 7), "tmp105", 0x48);
441     /* The swift board expects a pca9551 but a pca9552 is compatible */
442     i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 7), "pca9552", 0x60);
443 
444     /* The swift board expects an Epson RX8900 RTC but a ds1338 is compatible */
445     i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 8), "ds1338", 0x32);
446     i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 8), "pca9552", 0x60);
447 
448     i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 9), "tmp423", 0x4c);
449     /* The swift board expects a pca9539 but a pca9552 is compatible */
450     i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 9), "pca9552", 0x74);
451 
452     i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 10), "tmp423", 0x4c);
453     /* The swift board expects a pca9539 but a pca9552 is compatible */
454     i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 10), "pca9552",
455                      0x74);
456 
457     /* The swift board expects a TMP275 but a TMP105 is compatible */
458     i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 12), "tmp105", 0x48);
459     i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 12), "tmp105", 0x4a);
460 }
461 
462 static void sonorapass_bmc_i2c_init(AspeedBoardState *bmc)
463 {
464     AspeedSoCState *soc = &bmc->soc;
465 
466     /* bus 2 : */
467     i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 2), "tmp105", 0x48);
468     i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 2), "tmp105", 0x49);
469     /* bus 2 : pca9546 @ 0x73 */
470 
471     /* bus 3 : pca9548 @ 0x70 */
472 
473     /* bus 4 : */
474     uint8_t *eeprom4_54 = g_malloc0(8 * 1024);
475     smbus_eeprom_init_one(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 4), 0x54,
476                           eeprom4_54);
477     /* PCA9539 @ 0x76, but PCA9552 is compatible */
478     i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 4), "pca9552", 0x76);
479     /* PCA9539 @ 0x77, but PCA9552 is compatible */
480     i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 4), "pca9552", 0x77);
481 
482     /* bus 6 : */
483     i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 6), "tmp105", 0x48);
484     i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 6), "tmp105", 0x49);
485     /* bus 6 : pca9546 @ 0x73 */
486 
487     /* bus 8 : */
488     uint8_t *eeprom8_56 = g_malloc0(8 * 1024);
489     smbus_eeprom_init_one(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 8), 0x56,
490                           eeprom8_56);
491     i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 8), "pca9552", 0x60);
492     i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 8), "pca9552", 0x61);
493     /* bus 8 : adc128d818 @ 0x1d */
494     /* bus 8 : adc128d818 @ 0x1f */
495 
496     /*
497      * bus 13 : pca9548 @ 0x71
498      *      - channel 3:
499      *          - tmm421 @ 0x4c
500      *          - tmp421 @ 0x4e
501      *          - tmp421 @ 0x4f
502      */
503 
504 }
505 
506 static void witherspoon_bmc_i2c_init(AspeedBoardState *bmc)
507 {
508     AspeedSoCState *soc = &bmc->soc;
509     uint8_t *eeprom_buf = g_malloc0(8 * 1024);
510 
511     /* Bus 3: TODO bmp280@77 */
512     /* Bus 3: TODO max31785@52 */
513     /* Bus 3: TODO dps310@76 */
514     i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 3), TYPE_PCA9552,
515                      0x60);
516 
517     i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 4), "tmp423", 0x4c);
518     i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 5), "tmp423", 0x4c);
519 
520     /* The Witherspoon expects a TMP275 but a TMP105 is compatible */
521     i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 9), TYPE_TMP105,
522                      0x4a);
523 
524     /* The witherspoon board expects Epson RX8900 I2C RTC but a ds1338 is
525      * good enough */
526     i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 11), "ds1338", 0x32);
527 
528     smbus_eeprom_init_one(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 11), 0x51,
529                           eeprom_buf);
530     i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 11), TYPE_PCA9552,
531                      0x60);
532     /* Bus 11: TODO ucd90160@64 */
533 }
534 
535 static bool aspeed_get_mmio_exec(Object *obj, Error **errp)
536 {
537     return ASPEED_MACHINE(obj)->mmio_exec;
538 }
539 
540 static void aspeed_set_mmio_exec(Object *obj, bool value, Error **errp)
541 {
542     ASPEED_MACHINE(obj)->mmio_exec = value;
543 }
544 
545 static void aspeed_machine_instance_init(Object *obj)
546 {
547     ASPEED_MACHINE(obj)->mmio_exec = false;
548 }
549 
550 static void aspeed_machine_class_props_init(ObjectClass *oc)
551 {
552     object_class_property_add_bool(oc, "execute-in-place",
553                                    aspeed_get_mmio_exec,
554                                    aspeed_set_mmio_exec);
555     object_class_property_set_description(oc, "execute-in-place",
556                            "boot directly from CE0 flash device");
557 }
558 
559 static int aspeed_soc_num_cpus(const char *soc_name)
560 {
561    AspeedSoCClass *sc = ASPEED_SOC_CLASS(object_class_by_name(soc_name));
562    return sc->num_cpus;
563 }
564 
565 static void aspeed_machine_class_init(ObjectClass *oc, void *data)
566 {
567     MachineClass *mc = MACHINE_CLASS(oc);
568     AspeedMachineClass *amc = ASPEED_MACHINE_CLASS(oc);
569 
570     mc->init = aspeed_machine_init;
571     mc->no_floppy = 1;
572     mc->no_cdrom = 1;
573     mc->no_parallel = 1;
574     mc->default_ram_id = "ram";
575     amc->macs_mask = ASPEED_MAC0_ON;
576 
577     aspeed_machine_class_props_init(oc);
578 }
579 
580 static void aspeed_machine_palmetto_class_init(ObjectClass *oc, void *data)
581 {
582     MachineClass *mc = MACHINE_CLASS(oc);
583     AspeedMachineClass *amc = ASPEED_MACHINE_CLASS(oc);
584 
585     mc->desc       = "OpenPOWER Palmetto BMC (ARM926EJ-S)";
586     amc->soc_name  = "ast2400-a1";
587     amc->hw_strap1 = PALMETTO_BMC_HW_STRAP1;
588     amc->fmc_model = "n25q256a";
589     amc->spi_model = "mx25l25635e";
590     amc->num_cs    = 1;
591     amc->i2c_init  = palmetto_bmc_i2c_init;
592     mc->default_ram_size       = 256 * MiB;
593     mc->default_cpus = mc->min_cpus = mc->max_cpus =
594         aspeed_soc_num_cpus(amc->soc_name);
595 };
596 
597 static void aspeed_machine_ast2500_evb_class_init(ObjectClass *oc, void *data)
598 {
599     MachineClass *mc = MACHINE_CLASS(oc);
600     AspeedMachineClass *amc = ASPEED_MACHINE_CLASS(oc);
601 
602     mc->desc       = "Aspeed AST2500 EVB (ARM1176)";
603     amc->soc_name  = "ast2500-a1";
604     amc->hw_strap1 = AST2500_EVB_HW_STRAP1;
605     amc->fmc_model = "w25q256";
606     amc->spi_model = "mx25l25635e";
607     amc->num_cs    = 1;
608     amc->i2c_init  = ast2500_evb_i2c_init;
609     mc->default_ram_size       = 512 * MiB;
610     mc->default_cpus = mc->min_cpus = mc->max_cpus =
611         aspeed_soc_num_cpus(amc->soc_name);
612 };
613 
614 static void aspeed_machine_romulus_class_init(ObjectClass *oc, void *data)
615 {
616     MachineClass *mc = MACHINE_CLASS(oc);
617     AspeedMachineClass *amc = ASPEED_MACHINE_CLASS(oc);
618 
619     mc->desc       = "OpenPOWER Romulus BMC (ARM1176)";
620     amc->soc_name  = "ast2500-a1";
621     amc->hw_strap1 = ROMULUS_BMC_HW_STRAP1;
622     amc->fmc_model = "n25q256a";
623     amc->spi_model = "mx66l1g45g";
624     amc->num_cs    = 2;
625     amc->i2c_init  = romulus_bmc_i2c_init;
626     mc->default_ram_size       = 512 * MiB;
627     mc->default_cpus = mc->min_cpus = mc->max_cpus =
628         aspeed_soc_num_cpus(amc->soc_name);
629 };
630 
631 static void aspeed_machine_sonorapass_class_init(ObjectClass *oc, void *data)
632 {
633     MachineClass *mc = MACHINE_CLASS(oc);
634     AspeedMachineClass *amc = ASPEED_MACHINE_CLASS(oc);
635 
636     mc->desc       = "OCP SonoraPass BMC (ARM1176)";
637     amc->soc_name  = "ast2500-a1";
638     amc->hw_strap1 = SONORAPASS_BMC_HW_STRAP1;
639     amc->fmc_model = "mx66l1g45g";
640     amc->spi_model = "mx66l1g45g";
641     amc->num_cs    = 2;
642     amc->i2c_init  = sonorapass_bmc_i2c_init;
643     mc->default_ram_size       = 512 * MiB;
644     mc->default_cpus = mc->min_cpus = mc->max_cpus =
645         aspeed_soc_num_cpus(amc->soc_name);
646 };
647 
648 static void aspeed_machine_swift_class_init(ObjectClass *oc, void *data)
649 {
650     MachineClass *mc = MACHINE_CLASS(oc);
651     AspeedMachineClass *amc = ASPEED_MACHINE_CLASS(oc);
652 
653     mc->desc       = "OpenPOWER Swift BMC (ARM1176)";
654     amc->soc_name  = "ast2500-a1";
655     amc->hw_strap1 = SWIFT_BMC_HW_STRAP1;
656     amc->fmc_model = "mx66l1g45g";
657     amc->spi_model = "mx66l1g45g";
658     amc->num_cs    = 2;
659     amc->i2c_init  = swift_bmc_i2c_init;
660     mc->default_ram_size       = 512 * MiB;
661     mc->default_cpus = mc->min_cpus = mc->max_cpus =
662         aspeed_soc_num_cpus(amc->soc_name);
663 };
664 
665 static void aspeed_machine_witherspoon_class_init(ObjectClass *oc, void *data)
666 {
667     MachineClass *mc = MACHINE_CLASS(oc);
668     AspeedMachineClass *amc = ASPEED_MACHINE_CLASS(oc);
669 
670     mc->desc       = "OpenPOWER Witherspoon BMC (ARM1176)";
671     amc->soc_name  = "ast2500-a1";
672     amc->hw_strap1 = WITHERSPOON_BMC_HW_STRAP1;
673     amc->fmc_model = "mx25l25635e";
674     amc->spi_model = "mx66l1g45g";
675     amc->num_cs    = 2;
676     amc->i2c_init  = witherspoon_bmc_i2c_init;
677     mc->default_ram_size = 512 * MiB;
678     mc->default_cpus = mc->min_cpus = mc->max_cpus =
679         aspeed_soc_num_cpus(amc->soc_name);
680 };
681 
682 static void aspeed_machine_ast2600_evb_class_init(ObjectClass *oc, void *data)
683 {
684     MachineClass *mc = MACHINE_CLASS(oc);
685     AspeedMachineClass *amc = ASPEED_MACHINE_CLASS(oc);
686 
687     mc->desc       = "Aspeed AST2600 EVB (Cortex A7)";
688     amc->soc_name  = "ast2600-a1";
689     amc->hw_strap1 = AST2600_EVB_HW_STRAP1;
690     amc->hw_strap2 = AST2600_EVB_HW_STRAP2;
691     amc->fmc_model = "w25q512jv";
692     amc->spi_model = "mx66u51235f";
693     amc->num_cs    = 1;
694     amc->macs_mask  = ASPEED_MAC1_ON | ASPEED_MAC2_ON | ASPEED_MAC3_ON;
695     amc->i2c_init  = ast2600_evb_i2c_init;
696     mc->default_ram_size = 1 * GiB;
697     mc->default_cpus = mc->min_cpus = mc->max_cpus =
698         aspeed_soc_num_cpus(amc->soc_name);
699 };
700 
701 static void aspeed_machine_tacoma_class_init(ObjectClass *oc, void *data)
702 {
703     MachineClass *mc = MACHINE_CLASS(oc);
704     AspeedMachineClass *amc = ASPEED_MACHINE_CLASS(oc);
705 
706     mc->desc       = "OpenPOWER Tacoma BMC (Cortex A7)";
707     amc->soc_name  = "ast2600-a1";
708     amc->hw_strap1 = TACOMA_BMC_HW_STRAP1;
709     amc->hw_strap2 = TACOMA_BMC_HW_STRAP2;
710     amc->fmc_model = "mx66l1g45g";
711     amc->spi_model = "mx66l1g45g";
712     amc->num_cs    = 2;
713     amc->macs_mask  = ASPEED_MAC2_ON;
714     amc->i2c_init  = witherspoon_bmc_i2c_init; /* Same board layout */
715     mc->default_ram_size = 1 * GiB;
716     mc->default_cpus = mc->min_cpus = mc->max_cpus =
717         aspeed_soc_num_cpus(amc->soc_name);
718 };
719 
720 static const TypeInfo aspeed_machine_types[] = {
721     {
722         .name          = MACHINE_TYPE_NAME("palmetto-bmc"),
723         .parent        = TYPE_ASPEED_MACHINE,
724         .class_init    = aspeed_machine_palmetto_class_init,
725     }, {
726         .name          = MACHINE_TYPE_NAME("ast2500-evb"),
727         .parent        = TYPE_ASPEED_MACHINE,
728         .class_init    = aspeed_machine_ast2500_evb_class_init,
729     }, {
730         .name          = MACHINE_TYPE_NAME("romulus-bmc"),
731         .parent        = TYPE_ASPEED_MACHINE,
732         .class_init    = aspeed_machine_romulus_class_init,
733     }, {
734         .name          = MACHINE_TYPE_NAME("swift-bmc"),
735         .parent        = TYPE_ASPEED_MACHINE,
736         .class_init    = aspeed_machine_swift_class_init,
737     }, {
738         .name          = MACHINE_TYPE_NAME("sonorapass-bmc"),
739         .parent        = TYPE_ASPEED_MACHINE,
740         .class_init    = aspeed_machine_sonorapass_class_init,
741     }, {
742         .name          = MACHINE_TYPE_NAME("witherspoon-bmc"),
743         .parent        = TYPE_ASPEED_MACHINE,
744         .class_init    = aspeed_machine_witherspoon_class_init,
745     }, {
746         .name          = MACHINE_TYPE_NAME("ast2600-evb"),
747         .parent        = TYPE_ASPEED_MACHINE,
748         .class_init    = aspeed_machine_ast2600_evb_class_init,
749     }, {
750         .name          = MACHINE_TYPE_NAME("tacoma-bmc"),
751         .parent        = TYPE_ASPEED_MACHINE,
752         .class_init    = aspeed_machine_tacoma_class_init,
753     }, {
754         .name          = TYPE_ASPEED_MACHINE,
755         .parent        = TYPE_MACHINE,
756         .instance_size = sizeof(AspeedMachine),
757         .instance_init = aspeed_machine_instance_init,
758         .class_size    = sizeof(AspeedMachineClass),
759         .class_init    = aspeed_machine_class_init,
760         .abstract      = true,
761     }
762 };
763 
764 DEFINE_TYPES(aspeed_machine_types)
765