aspeed.c 29 KB

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