pegasos2.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957
  1. /*
  2. * QEMU PowerPC CHRP (Genesi/bPlan Pegasos II) hardware System Emulator
  3. *
  4. * Copyright (c) 2018-2021 BALATON Zoltan
  5. *
  6. * This work is licensed under the GNU GPL license version 2 or later.
  7. *
  8. */
  9. #include "qemu/osdep.h"
  10. #include "qemu/units.h"
  11. #include "qapi/error.h"
  12. #include "hw/hw.h"
  13. #include "hw/ppc/ppc.h"
  14. #include "hw/sysbus.h"
  15. #include "hw/pci/pci_host.h"
  16. #include "hw/irq.h"
  17. #include "hw/pci-host/mv64361.h"
  18. #include "hw/isa/vt82c686.h"
  19. #include "hw/ide/pci.h"
  20. #include "hw/i2c/smbus_eeprom.h"
  21. #include "hw/qdev-properties.h"
  22. #include "sysemu/reset.h"
  23. #include "sysemu/runstate.h"
  24. #include "sysemu/qtest.h"
  25. #include "hw/boards.h"
  26. #include "hw/loader.h"
  27. #include "hw/fw-path-provider.h"
  28. #include "elf.h"
  29. #include "qemu/log.h"
  30. #include "qemu/error-report.h"
  31. #include "sysemu/kvm.h"
  32. #include "kvm_ppc.h"
  33. #include "exec/address-spaces.h"
  34. #include "qom/qom-qobject.h"
  35. #include "qapi/qmp/qdict.h"
  36. #include "trace.h"
  37. #include "qemu/datadir.h"
  38. #include "sysemu/device_tree.h"
  39. #include "hw/ppc/vof.h"
  40. #include <libfdt.h>
  41. #define PROM_FILENAME "vof.bin"
  42. #define PROM_ADDR 0xfff00000
  43. #define PROM_SIZE 0x80000
  44. #define KVMPPC_HCALL_BASE 0xf000
  45. #define KVMPPC_H_RTAS (KVMPPC_HCALL_BASE + 0x0)
  46. #define KVMPPC_H_VOF_CLIENT (KVMPPC_HCALL_BASE + 0x5)
  47. #define H_SUCCESS 0
  48. #define H_PRIVILEGE -3 /* Caller not privileged */
  49. #define H_PARAMETER -4 /* Parameter invalid, out-of-range or conflicting */
  50. #define BUS_FREQ_HZ 133333333
  51. #define PCI0_CFG_ADDR 0xcf8
  52. #define PCI0_MEM_BASE 0xc0000000
  53. #define PCI0_MEM_SIZE 0x20000000
  54. #define PCI0_IO_BASE 0xf8000000
  55. #define PCI0_IO_SIZE 0x10000
  56. #define PCI1_CFG_ADDR 0xc78
  57. #define PCI1_MEM_BASE 0x80000000
  58. #define PCI1_MEM_SIZE 0x40000000
  59. #define PCI1_IO_BASE 0xfe000000
  60. #define PCI1_IO_SIZE 0x10000
  61. #define TYPE_PEGASOS2_MACHINE MACHINE_TYPE_NAME("pegasos2")
  62. OBJECT_DECLARE_TYPE(Pegasos2MachineState, MachineClass, PEGASOS2_MACHINE)
  63. struct Pegasos2MachineState {
  64. MachineState parent_obj;
  65. PowerPCCPU *cpu;
  66. DeviceState *mv;
  67. Vof *vof;
  68. void *fdt_blob;
  69. uint64_t kernel_addr;
  70. uint64_t kernel_entry;
  71. uint64_t kernel_size;
  72. };
  73. static void *build_fdt(MachineState *machine, int *fdt_size);
  74. static void pegasos2_cpu_reset(void *opaque)
  75. {
  76. PowerPCCPU *cpu = opaque;
  77. Pegasos2MachineState *pm = PEGASOS2_MACHINE(current_machine);
  78. cpu_reset(CPU(cpu));
  79. cpu->env.spr[SPR_HID1] = 7ULL << 28;
  80. if (pm->vof) {
  81. cpu->env.gpr[1] = 2 * VOF_STACK_SIZE - 0x20;
  82. cpu->env.nip = 0x100;
  83. }
  84. }
  85. static void pegasos2_init(MachineState *machine)
  86. {
  87. Pegasos2MachineState *pm = PEGASOS2_MACHINE(machine);
  88. CPUPPCState *env;
  89. MemoryRegion *rom = g_new(MemoryRegion, 1);
  90. PCIBus *pci_bus;
  91. PCIDevice *dev;
  92. I2CBus *i2c_bus;
  93. const char *fwname = machine->firmware ?: PROM_FILENAME;
  94. char *filename;
  95. int sz;
  96. uint8_t *spd_data;
  97. /* init CPU */
  98. pm->cpu = POWERPC_CPU(cpu_create(machine->cpu_type));
  99. env = &pm->cpu->env;
  100. if (PPC_INPUT(env) != PPC_FLAGS_INPUT_6xx) {
  101. error_report("Incompatible CPU, only 6xx bus supported");
  102. exit(1);
  103. }
  104. /* Set time-base frequency */
  105. cpu_ppc_tb_init(env, BUS_FREQ_HZ / 4);
  106. qemu_register_reset(pegasos2_cpu_reset, pm->cpu);
  107. /* RAM */
  108. if (machine->ram_size > 2 * GiB) {
  109. error_report("RAM size more than 2 GiB is not supported");
  110. exit(1);
  111. }
  112. memory_region_add_subregion(get_system_memory(), 0, machine->ram);
  113. /* allocate and load firmware */
  114. filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, fwname);
  115. if (!filename) {
  116. error_report("Could not find firmware '%s'", fwname);
  117. exit(1);
  118. }
  119. if (!machine->firmware && !pm->vof) {
  120. pm->vof = g_malloc0(sizeof(*pm->vof));
  121. }
  122. memory_region_init_rom(rom, NULL, "pegasos2.rom", PROM_SIZE, &error_fatal);
  123. memory_region_add_subregion(get_system_memory(), PROM_ADDR, rom);
  124. sz = load_elf(filename, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1,
  125. PPC_ELF_MACHINE, 0, 0);
  126. if (sz <= 0) {
  127. sz = load_image_targphys(filename, pm->vof ? 0 : PROM_ADDR, PROM_SIZE);
  128. }
  129. if (sz <= 0 || sz > PROM_SIZE) {
  130. error_report("Could not load firmware '%s'", filename);
  131. exit(1);
  132. }
  133. g_free(filename);
  134. if (pm->vof) {
  135. pm->vof->fw_size = sz;
  136. }
  137. /* Marvell Discovery II system controller */
  138. pm->mv = DEVICE(sysbus_create_simple(TYPE_MV64361, -1,
  139. ((qemu_irq *)env->irq_inputs)[PPC6xx_INPUT_INT]));
  140. pci_bus = mv64361_get_pci_bus(pm->mv, 1);
  141. /* VIA VT8231 South Bridge (multifunction PCI device) */
  142. /* VT8231 function 0: PCI-to-ISA Bridge */
  143. dev = pci_create_simple_multifunction(pci_bus, PCI_DEVFN(12, 0), true,
  144. TYPE_VT8231_ISA);
  145. qdev_connect_gpio_out(DEVICE(dev), 0,
  146. qdev_get_gpio_in_named(pm->mv, "gpp", 31));
  147. /* VT8231 function 1: IDE Controller */
  148. dev = pci_create_simple(pci_bus, PCI_DEVFN(12, 1), "via-ide");
  149. pci_ide_create_devs(dev);
  150. /* VT8231 function 2-3: USB Ports */
  151. pci_create_simple(pci_bus, PCI_DEVFN(12, 2), "vt82c686b-usb-uhci");
  152. pci_create_simple(pci_bus, PCI_DEVFN(12, 3), "vt82c686b-usb-uhci");
  153. /* VT8231 function 4: Power Management Controller */
  154. dev = pci_create_simple(pci_bus, PCI_DEVFN(12, 4), TYPE_VT8231_PM);
  155. i2c_bus = I2C_BUS(qdev_get_child_bus(DEVICE(dev), "i2c"));
  156. spd_data = spd_data_generate(DDR, machine->ram_size);
  157. smbus_eeprom_init_one(i2c_bus, 0x57, spd_data);
  158. /* VT8231 function 5-6: AC97 Audio & Modem */
  159. pci_create_simple(pci_bus, PCI_DEVFN(12, 5), TYPE_VIA_AC97);
  160. pci_create_simple(pci_bus, PCI_DEVFN(12, 6), TYPE_VIA_MC97);
  161. /* other PC hardware */
  162. pci_vga_init(pci_bus);
  163. if (machine->kernel_filename) {
  164. sz = load_elf(machine->kernel_filename, NULL, NULL, NULL,
  165. &pm->kernel_entry, &pm->kernel_addr, NULL, NULL, 1,
  166. PPC_ELF_MACHINE, 0, 0);
  167. if (sz <= 0) {
  168. error_report("Could not load kernel '%s'",
  169. machine->kernel_filename);
  170. exit(1);
  171. }
  172. pm->kernel_size = sz;
  173. if (!pm->vof) {
  174. warn_report("Option -kernel may be ineffective with -bios.");
  175. }
  176. } else if (pm->vof && !qtest_enabled()) {
  177. warn_report("Using Virtual OpenFirmware but no -kernel option.");
  178. }
  179. if (!pm->vof && machine->kernel_cmdline && machine->kernel_cmdline[0]) {
  180. warn_report("Option -append may be ineffective with -bios.");
  181. }
  182. }
  183. static uint32_t pegasos2_mv_reg_read(Pegasos2MachineState *pm,
  184. uint32_t addr, uint32_t len)
  185. {
  186. MemoryRegion *r = sysbus_mmio_get_region(SYS_BUS_DEVICE(pm->mv), 0);
  187. uint64_t val = 0xffffffffULL;
  188. memory_region_dispatch_read(r, addr, &val, size_memop(len) | MO_LE,
  189. MEMTXATTRS_UNSPECIFIED);
  190. return val;
  191. }
  192. static void pegasos2_mv_reg_write(Pegasos2MachineState *pm, uint32_t addr,
  193. uint32_t len, uint32_t val)
  194. {
  195. MemoryRegion *r = sysbus_mmio_get_region(SYS_BUS_DEVICE(pm->mv), 0);
  196. memory_region_dispatch_write(r, addr, val, size_memop(len) | MO_LE,
  197. MEMTXATTRS_UNSPECIFIED);
  198. }
  199. static uint32_t pegasos2_pci_config_read(Pegasos2MachineState *pm, int bus,
  200. uint32_t addr, uint32_t len)
  201. {
  202. hwaddr pcicfg = bus ? PCI1_CFG_ADDR : PCI0_CFG_ADDR;
  203. uint64_t val = 0xffffffffULL;
  204. if (len <= 4) {
  205. pegasos2_mv_reg_write(pm, pcicfg, 4, addr | BIT(31));
  206. val = pegasos2_mv_reg_read(pm, pcicfg + 4, len);
  207. }
  208. return val;
  209. }
  210. static void pegasos2_pci_config_write(Pegasos2MachineState *pm, int bus,
  211. uint32_t addr, uint32_t len, uint32_t val)
  212. {
  213. hwaddr pcicfg = bus ? PCI1_CFG_ADDR : PCI0_CFG_ADDR;
  214. pegasos2_mv_reg_write(pm, pcicfg, 4, addr | BIT(31));
  215. pegasos2_mv_reg_write(pm, pcicfg + 4, len, val);
  216. }
  217. static void pegasos2_machine_reset(MachineState *machine)
  218. {
  219. Pegasos2MachineState *pm = PEGASOS2_MACHINE(machine);
  220. void *fdt;
  221. uint64_t d[2];
  222. int sz;
  223. qemu_devices_reset();
  224. if (!pm->vof) {
  225. return; /* Firmware should set up machine so nothing to do */
  226. }
  227. /* Otherwise, set up devices that board firmware would normally do */
  228. pegasos2_mv_reg_write(pm, 0, 4, 0x28020ff);
  229. pegasos2_mv_reg_write(pm, 0x278, 4, 0xa31fc);
  230. pegasos2_mv_reg_write(pm, 0xf300, 4, 0x11ff0400);
  231. pegasos2_mv_reg_write(pm, 0xf10c, 4, 0x80000000);
  232. pegasos2_mv_reg_write(pm, 0x1c, 4, 0x8000000);
  233. pegasos2_pci_config_write(pm, 0, PCI_COMMAND, 2, PCI_COMMAND_IO |
  234. PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
  235. pegasos2_pci_config_write(pm, 1, PCI_COMMAND, 2, PCI_COMMAND_IO |
  236. PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
  237. pegasos2_pci_config_write(pm, 1, (PCI_DEVFN(12, 0) << 8) |
  238. PCI_INTERRUPT_LINE, 2, 0x9);
  239. pegasos2_pci_config_write(pm, 1, (PCI_DEVFN(12, 0) << 8) |
  240. 0x50, 1, 0x2);
  241. pegasos2_pci_config_write(pm, 1, (PCI_DEVFN(12, 1) << 8) |
  242. PCI_INTERRUPT_LINE, 2, 0x109);
  243. pegasos2_pci_config_write(pm, 1, (PCI_DEVFN(12, 1) << 8) |
  244. PCI_CLASS_PROG, 1, 0xf);
  245. pegasos2_pci_config_write(pm, 1, (PCI_DEVFN(12, 1) << 8) |
  246. 0x40, 1, 0xb);
  247. pegasos2_pci_config_write(pm, 1, (PCI_DEVFN(12, 1) << 8) |
  248. 0x50, 4, 0x17171717);
  249. pegasos2_pci_config_write(pm, 1, (PCI_DEVFN(12, 1) << 8) |
  250. PCI_COMMAND, 2, 0x87);
  251. pegasos2_pci_config_write(pm, 1, (PCI_DEVFN(12, 2) << 8) |
  252. PCI_INTERRUPT_LINE, 2, 0x409);
  253. pegasos2_pci_config_write(pm, 1, (PCI_DEVFN(12, 3) << 8) |
  254. PCI_INTERRUPT_LINE, 2, 0x409);
  255. pegasos2_pci_config_write(pm, 1, (PCI_DEVFN(12, 4) << 8) |
  256. PCI_INTERRUPT_LINE, 2, 0x9);
  257. pegasos2_pci_config_write(pm, 1, (PCI_DEVFN(12, 4) << 8) |
  258. 0x48, 4, 0xf00);
  259. pegasos2_pci_config_write(pm, 1, (PCI_DEVFN(12, 4) << 8) |
  260. 0x40, 4, 0x558020);
  261. pegasos2_pci_config_write(pm, 1, (PCI_DEVFN(12, 4) << 8) |
  262. 0x90, 4, 0xd00);
  263. pegasos2_pci_config_write(pm, 1, (PCI_DEVFN(12, 5) << 8) |
  264. PCI_INTERRUPT_LINE, 2, 0x309);
  265. pegasos2_pci_config_write(pm, 1, (PCI_DEVFN(12, 6) << 8) |
  266. PCI_INTERRUPT_LINE, 2, 0x309);
  267. /* Device tree and VOF set up */
  268. vof_init(pm->vof, machine->ram_size, &error_fatal);
  269. if (vof_claim(pm->vof, 0, VOF_STACK_SIZE, VOF_STACK_SIZE) == -1) {
  270. error_report("Memory allocation for stack failed");
  271. exit(1);
  272. }
  273. if (pm->kernel_size &&
  274. vof_claim(pm->vof, pm->kernel_addr, pm->kernel_size, 0) == -1) {
  275. error_report("Memory for kernel is in use");
  276. exit(1);
  277. }
  278. fdt = build_fdt(machine, &sz);
  279. /* FIXME: VOF assumes entry is same as load address */
  280. d[0] = cpu_to_be64(pm->kernel_entry);
  281. d[1] = cpu_to_be64(pm->kernel_size - (pm->kernel_entry - pm->kernel_addr));
  282. qemu_fdt_setprop(fdt, "/chosen", "qemu,boot-kernel", d, sizeof(d));
  283. qemu_fdt_dumpdtb(fdt, fdt_totalsize(fdt));
  284. g_free(pm->fdt_blob);
  285. pm->fdt_blob = fdt;
  286. vof_build_dt(fdt, pm->vof);
  287. vof_client_open_store(fdt, pm->vof, "/chosen", "stdout", "/failsafe");
  288. pm->cpu->vhyp = PPC_VIRTUAL_HYPERVISOR(machine);
  289. }
  290. enum pegasos2_rtas_tokens {
  291. RTAS_RESTART_RTAS = 0,
  292. RTAS_NVRAM_FETCH = 1,
  293. RTAS_NVRAM_STORE = 2,
  294. RTAS_GET_TIME_OF_DAY = 3,
  295. RTAS_SET_TIME_OF_DAY = 4,
  296. RTAS_EVENT_SCAN = 6,
  297. RTAS_CHECK_EXCEPTION = 7,
  298. RTAS_READ_PCI_CONFIG = 8,
  299. RTAS_WRITE_PCI_CONFIG = 9,
  300. RTAS_DISPLAY_CHARACTER = 10,
  301. RTAS_SET_INDICATOR = 11,
  302. RTAS_POWER_OFF = 17,
  303. RTAS_SUSPEND = 18,
  304. RTAS_HIBERNATE = 19,
  305. RTAS_SYSTEM_REBOOT = 20,
  306. };
  307. static target_ulong pegasos2_rtas(PowerPCCPU *cpu, Pegasos2MachineState *pm,
  308. target_ulong args_real)
  309. {
  310. AddressSpace *as = CPU(cpu)->as;
  311. uint32_t token = ldl_be_phys(as, args_real);
  312. uint32_t nargs = ldl_be_phys(as, args_real + 4);
  313. uint32_t nrets = ldl_be_phys(as, args_real + 8);
  314. uint32_t args = args_real + 12;
  315. uint32_t rets = args_real + 12 + nargs * 4;
  316. if (nrets < 1) {
  317. qemu_log_mask(LOG_GUEST_ERROR, "Too few return values in RTAS call\n");
  318. return H_PARAMETER;
  319. }
  320. switch (token) {
  321. case RTAS_GET_TIME_OF_DAY:
  322. {
  323. QObject *qo = object_property_get_qobject(qdev_get_machine(),
  324. "rtc-time", &error_fatal);
  325. QDict *qd = qobject_to(QDict, qo);
  326. if (nargs != 0 || nrets != 8 || !qd) {
  327. stl_be_phys(as, rets, -1);
  328. qobject_unref(qo);
  329. return H_PARAMETER;
  330. }
  331. stl_be_phys(as, rets, 0);
  332. stl_be_phys(as, rets + 4, qdict_get_int(qd, "tm_year") + 1900);
  333. stl_be_phys(as, rets + 8, qdict_get_int(qd, "tm_mon") + 1);
  334. stl_be_phys(as, rets + 12, qdict_get_int(qd, "tm_mday"));
  335. stl_be_phys(as, rets + 16, qdict_get_int(qd, "tm_hour"));
  336. stl_be_phys(as, rets + 20, qdict_get_int(qd, "tm_min"));
  337. stl_be_phys(as, rets + 24, qdict_get_int(qd, "tm_sec"));
  338. stl_be_phys(as, rets + 28, 0);
  339. qobject_unref(qo);
  340. return H_SUCCESS;
  341. }
  342. case RTAS_READ_PCI_CONFIG:
  343. {
  344. uint32_t addr, len, val;
  345. if (nargs != 2 || nrets != 2) {
  346. stl_be_phys(as, rets, -1);
  347. return H_PARAMETER;
  348. }
  349. addr = ldl_be_phys(as, args);
  350. len = ldl_be_phys(as, args + 4);
  351. val = pegasos2_pci_config_read(pm, !(addr >> 24),
  352. addr & 0x0fffffff, len);
  353. stl_be_phys(as, rets, 0);
  354. stl_be_phys(as, rets + 4, val);
  355. return H_SUCCESS;
  356. }
  357. case RTAS_WRITE_PCI_CONFIG:
  358. {
  359. uint32_t addr, len, val;
  360. if (nargs != 3 || nrets != 1) {
  361. stl_be_phys(as, rets, -1);
  362. return H_PARAMETER;
  363. }
  364. addr = ldl_be_phys(as, args);
  365. len = ldl_be_phys(as, args + 4);
  366. val = ldl_be_phys(as, args + 8);
  367. pegasos2_pci_config_write(pm, !(addr >> 24),
  368. addr & 0x0fffffff, len, val);
  369. stl_be_phys(as, rets, 0);
  370. return H_SUCCESS;
  371. }
  372. case RTAS_DISPLAY_CHARACTER:
  373. if (nargs != 1 || nrets != 1) {
  374. stl_be_phys(as, rets, -1);
  375. return H_PARAMETER;
  376. }
  377. qemu_log_mask(LOG_UNIMP, "%c", ldl_be_phys(as, args));
  378. stl_be_phys(as, rets, 0);
  379. return H_SUCCESS;
  380. case RTAS_POWER_OFF:
  381. {
  382. if (nargs != 2 || nrets != 1) {
  383. stl_be_phys(as, rets, -1);
  384. return H_PARAMETER;
  385. }
  386. qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
  387. stl_be_phys(as, rets, 0);
  388. return H_SUCCESS;
  389. }
  390. default:
  391. qemu_log_mask(LOG_UNIMP, "Unknown RTAS token %u (args=%u, rets=%u)\n",
  392. token, nargs, nrets);
  393. stl_be_phys(as, rets, 0);
  394. return H_SUCCESS;
  395. }
  396. }
  397. static bool pegasos2_cpu_in_nested(PowerPCCPU *cpu)
  398. {
  399. return false;
  400. }
  401. static void pegasos2_hypercall(PPCVirtualHypervisor *vhyp, PowerPCCPU *cpu)
  402. {
  403. Pegasos2MachineState *pm = PEGASOS2_MACHINE(vhyp);
  404. CPUPPCState *env = &cpu->env;
  405. /* The TCG path should also be holding the BQL at this point */
  406. g_assert(qemu_mutex_iothread_locked());
  407. if (msr_pr) {
  408. qemu_log_mask(LOG_GUEST_ERROR, "Hypercall made with MSR[PR]=1\n");
  409. env->gpr[3] = H_PRIVILEGE;
  410. } else if (env->gpr[3] == KVMPPC_H_RTAS) {
  411. env->gpr[3] = pegasos2_rtas(cpu, pm, env->gpr[4]);
  412. } else if (env->gpr[3] == KVMPPC_H_VOF_CLIENT) {
  413. int ret = vof_client_call(MACHINE(pm), pm->vof, pm->fdt_blob,
  414. env->gpr[4]);
  415. env->gpr[3] = (ret ? H_PARAMETER : H_SUCCESS);
  416. } else {
  417. qemu_log_mask(LOG_GUEST_ERROR, "Unsupported hypercall " TARGET_FMT_lx
  418. "\n", env->gpr[3]);
  419. env->gpr[3] = -1;
  420. }
  421. }
  422. static void vhyp_nop(PPCVirtualHypervisor *vhyp, PowerPCCPU *cpu)
  423. {
  424. }
  425. static target_ulong vhyp_encode_hpt_for_kvm_pr(PPCVirtualHypervisor *vhyp)
  426. {
  427. return POWERPC_CPU(current_cpu)->env.spr[SPR_SDR1];
  428. }
  429. static bool pegasos2_setprop(MachineState *ms, const char *path,
  430. const char *propname, void *val, int vallen)
  431. {
  432. return true;
  433. }
  434. static void pegasos2_machine_class_init(ObjectClass *oc, void *data)
  435. {
  436. MachineClass *mc = MACHINE_CLASS(oc);
  437. PPCVirtualHypervisorClass *vhc = PPC_VIRTUAL_HYPERVISOR_CLASS(oc);
  438. VofMachineIfClass *vmc = VOF_MACHINE_CLASS(oc);
  439. mc->desc = "Genesi/bPlan Pegasos II";
  440. mc->init = pegasos2_init;
  441. mc->reset = pegasos2_machine_reset;
  442. mc->block_default_type = IF_IDE;
  443. mc->default_boot_order = "cd";
  444. mc->default_display = "std";
  445. mc->default_cpu_type = POWERPC_CPU_TYPE_NAME("7400_v2.9");
  446. mc->default_ram_id = "pegasos2.ram";
  447. mc->default_ram_size = 512 * MiB;
  448. vhc->cpu_in_nested = pegasos2_cpu_in_nested;
  449. vhc->hypercall = pegasos2_hypercall;
  450. vhc->cpu_exec_enter = vhyp_nop;
  451. vhc->cpu_exec_exit = vhyp_nop;
  452. vhc->encode_hpt_for_kvm_pr = vhyp_encode_hpt_for_kvm_pr;
  453. vmc->setprop = pegasos2_setprop;
  454. }
  455. static const TypeInfo pegasos2_machine_info = {
  456. .name = TYPE_PEGASOS2_MACHINE,
  457. .parent = TYPE_MACHINE,
  458. .class_init = pegasos2_machine_class_init,
  459. .instance_size = sizeof(Pegasos2MachineState),
  460. .interfaces = (InterfaceInfo[]) {
  461. { TYPE_PPC_VIRTUAL_HYPERVISOR },
  462. { TYPE_VOF_MACHINE_IF },
  463. { }
  464. },
  465. };
  466. static void pegasos2_machine_register_types(void)
  467. {
  468. type_register_static(&pegasos2_machine_info);
  469. }
  470. type_init(pegasos2_machine_register_types)
  471. /* FDT creation for passing to firmware */
  472. typedef struct {
  473. void *fdt;
  474. const char *path;
  475. } FDTInfo;
  476. /* We do everything in reverse order so it comes out right in the tree */
  477. static void dt_ide(PCIBus *bus, PCIDevice *d, FDTInfo *fi)
  478. {
  479. qemu_fdt_setprop_string(fi->fdt, fi->path, "device_type", "spi");
  480. }
  481. static void dt_usb(PCIBus *bus, PCIDevice *d, FDTInfo *fi)
  482. {
  483. qemu_fdt_setprop_cell(fi->fdt, fi->path, "#size-cells", 0);
  484. qemu_fdt_setprop_cell(fi->fdt, fi->path, "#address-cells", 1);
  485. qemu_fdt_setprop_string(fi->fdt, fi->path, "device_type", "usb");
  486. }
  487. static void dt_isa(PCIBus *bus, PCIDevice *d, FDTInfo *fi)
  488. {
  489. GString *name = g_string_sized_new(64);
  490. uint32_t cells[3];
  491. qemu_fdt_setprop_cell(fi->fdt, fi->path, "#size-cells", 1);
  492. qemu_fdt_setprop_cell(fi->fdt, fi->path, "#address-cells", 2);
  493. qemu_fdt_setprop_string(fi->fdt, fi->path, "device_type", "isa");
  494. qemu_fdt_setprop_string(fi->fdt, fi->path, "name", "isa");
  495. /* addional devices */
  496. g_string_printf(name, "%s/lpt@i3bc", fi->path);
  497. qemu_fdt_add_subnode(fi->fdt, name->str);
  498. qemu_fdt_setprop_cell(fi->fdt, name->str, "clock-frequency", 0);
  499. cells[0] = cpu_to_be32(7);
  500. cells[1] = 0;
  501. qemu_fdt_setprop(fi->fdt, name->str, "interrupts",
  502. cells, 2 * sizeof(cells[0]));
  503. cells[0] = cpu_to_be32(1);
  504. cells[1] = cpu_to_be32(0x3bc);
  505. cells[2] = cpu_to_be32(8);
  506. qemu_fdt_setprop(fi->fdt, name->str, "reg", cells, 3 * sizeof(cells[0]));
  507. qemu_fdt_setprop_string(fi->fdt, name->str, "device_type", "lpt");
  508. qemu_fdt_setprop_string(fi->fdt, name->str, "name", "lpt");
  509. g_string_printf(name, "%s/fdc@i3f0", fi->path);
  510. qemu_fdt_add_subnode(fi->fdt, name->str);
  511. qemu_fdt_setprop_cell(fi->fdt, name->str, "clock-frequency", 0);
  512. cells[0] = cpu_to_be32(6);
  513. cells[1] = 0;
  514. qemu_fdt_setprop(fi->fdt, name->str, "interrupts",
  515. cells, 2 * sizeof(cells[0]));
  516. cells[0] = cpu_to_be32(1);
  517. cells[1] = cpu_to_be32(0x3f0);
  518. cells[2] = cpu_to_be32(8);
  519. qemu_fdt_setprop(fi->fdt, name->str, "reg", cells, 3 * sizeof(cells[0]));
  520. qemu_fdt_setprop_string(fi->fdt, name->str, "device_type", "fdc");
  521. qemu_fdt_setprop_string(fi->fdt, name->str, "name", "fdc");
  522. g_string_printf(name, "%s/timer@i40", fi->path);
  523. qemu_fdt_add_subnode(fi->fdt, name->str);
  524. qemu_fdt_setprop_cell(fi->fdt, name->str, "clock-frequency", 0);
  525. cells[0] = cpu_to_be32(1);
  526. cells[1] = cpu_to_be32(0x40);
  527. cells[2] = cpu_to_be32(8);
  528. qemu_fdt_setprop(fi->fdt, name->str, "reg", cells, 3 * sizeof(cells[0]));
  529. qemu_fdt_setprop_string(fi->fdt, name->str, "device_type", "timer");
  530. qemu_fdt_setprop_string(fi->fdt, name->str, "name", "timer");
  531. g_string_printf(name, "%s/rtc@i70", fi->path);
  532. qemu_fdt_add_subnode(fi->fdt, name->str);
  533. qemu_fdt_setprop_string(fi->fdt, name->str, "compatible", "ds1385-rtc");
  534. qemu_fdt_setprop_cell(fi->fdt, name->str, "clock-frequency", 0);
  535. cells[0] = cpu_to_be32(8);
  536. cells[1] = 0;
  537. qemu_fdt_setprop(fi->fdt, name->str, "interrupts",
  538. cells, 2 * sizeof(cells[0]));
  539. cells[0] = cpu_to_be32(1);
  540. cells[1] = cpu_to_be32(0x70);
  541. cells[2] = cpu_to_be32(2);
  542. qemu_fdt_setprop(fi->fdt, name->str, "reg", cells, 3 * sizeof(cells[0]));
  543. qemu_fdt_setprop_string(fi->fdt, name->str, "device_type", "rtc");
  544. qemu_fdt_setprop_string(fi->fdt, name->str, "name", "rtc");
  545. g_string_printf(name, "%s/keyboard@i60", fi->path);
  546. qemu_fdt_add_subnode(fi->fdt, name->str);
  547. cells[0] = cpu_to_be32(1);
  548. cells[1] = 0;
  549. qemu_fdt_setprop(fi->fdt, name->str, "interrupts",
  550. cells, 2 * sizeof(cells[0]));
  551. cells[0] = cpu_to_be32(1);
  552. cells[1] = cpu_to_be32(0x60);
  553. cells[2] = cpu_to_be32(5);
  554. qemu_fdt_setprop(fi->fdt, name->str, "reg", cells, 3 * sizeof(cells[0]));
  555. qemu_fdt_setprop_string(fi->fdt, name->str, "device_type", "keyboard");
  556. qemu_fdt_setprop_string(fi->fdt, name->str, "name", "keyboard");
  557. g_string_printf(name, "%s/8042@i60", fi->path);
  558. qemu_fdt_add_subnode(fi->fdt, name->str);
  559. qemu_fdt_setprop_cell(fi->fdt, name->str, "#interrupt-cells", 2);
  560. qemu_fdt_setprop_cell(fi->fdt, name->str, "#size-cells", 0);
  561. qemu_fdt_setprop_cell(fi->fdt, name->str, "#address-cells", 1);
  562. qemu_fdt_setprop_string(fi->fdt, name->str, "interrupt-controller", "");
  563. qemu_fdt_setprop_cell(fi->fdt, name->str, "clock-frequency", 0);
  564. cells[0] = cpu_to_be32(1);
  565. cells[1] = cpu_to_be32(0x60);
  566. cells[2] = cpu_to_be32(5);
  567. qemu_fdt_setprop(fi->fdt, name->str, "reg", cells, 3 * sizeof(cells[0]));
  568. qemu_fdt_setprop_string(fi->fdt, name->str, "device_type", "");
  569. qemu_fdt_setprop_string(fi->fdt, name->str, "name", "8042");
  570. g_string_printf(name, "%s/serial@i2f8", fi->path);
  571. qemu_fdt_add_subnode(fi->fdt, name->str);
  572. qemu_fdt_setprop_cell(fi->fdt, name->str, "clock-frequency", 0);
  573. cells[0] = cpu_to_be32(3);
  574. cells[1] = 0;
  575. qemu_fdt_setprop(fi->fdt, name->str, "interrupts",
  576. cells, 2 * sizeof(cells[0]));
  577. cells[0] = cpu_to_be32(1);
  578. cells[1] = cpu_to_be32(0x2f8);
  579. cells[2] = cpu_to_be32(8);
  580. qemu_fdt_setprop(fi->fdt, name->str, "reg", cells, 3 * sizeof(cells[0]));
  581. qemu_fdt_setprop_string(fi->fdt, name->str, "device_type", "serial");
  582. qemu_fdt_setprop_string(fi->fdt, name->str, "name", "serial");
  583. g_string_free(name, TRUE);
  584. }
  585. static struct {
  586. const char *id;
  587. const char *name;
  588. void (*dtf)(PCIBus *bus, PCIDevice *d, FDTInfo *fi);
  589. } device_map[] = {
  590. { "pci11ab,6460", "host", NULL },
  591. { "pci1106,8231", "isa", dt_isa },
  592. { "pci1106,571", "ide", dt_ide },
  593. { "pci1106,3044", "firewire", NULL },
  594. { "pci1106,3038", "usb", dt_usb },
  595. { "pci1106,8235", "other", NULL },
  596. { "pci1106,3058", "sound", NULL },
  597. { NULL, NULL }
  598. };
  599. static void add_pci_device(PCIBus *bus, PCIDevice *d, void *opaque)
  600. {
  601. FDTInfo *fi = opaque;
  602. GString *node = g_string_new(NULL);
  603. uint32_t cells[(PCI_NUM_REGIONS + 1) * 5];
  604. int i, j;
  605. const char *name = NULL;
  606. g_autofree const gchar *pn = g_strdup_printf("pci%x,%x",
  607. pci_get_word(&d->config[PCI_VENDOR_ID]),
  608. pci_get_word(&d->config[PCI_DEVICE_ID]));
  609. for (i = 0; device_map[i].id; i++) {
  610. if (!strcmp(pn, device_map[i].id)) {
  611. name = device_map[i].name;
  612. break;
  613. }
  614. }
  615. g_string_printf(node, "%s/%s@%x", fi->path, (name ?: pn),
  616. PCI_SLOT(d->devfn));
  617. if (PCI_FUNC(d->devfn)) {
  618. g_string_append_printf(node, ",%x", PCI_FUNC(d->devfn));
  619. }
  620. qemu_fdt_add_subnode(fi->fdt, node->str);
  621. if (device_map[i].dtf) {
  622. FDTInfo cfi = { fi->fdt, node->str };
  623. device_map[i].dtf(bus, d, &cfi);
  624. }
  625. cells[0] = cpu_to_be32(d->devfn << 8);
  626. cells[1] = 0;
  627. cells[2] = 0;
  628. cells[3] = 0;
  629. cells[4] = 0;
  630. j = 5;
  631. for (i = 0; i < PCI_NUM_REGIONS; i++) {
  632. if (!d->io_regions[i].size) {
  633. continue;
  634. }
  635. cells[j] = cpu_to_be32(d->devfn << 8 | (PCI_BASE_ADDRESS_0 + i * 4));
  636. if (d->io_regions[i].type & PCI_BASE_ADDRESS_SPACE_IO) {
  637. cells[j] |= cpu_to_be32(1 << 24);
  638. } else {
  639. cells[j] |= cpu_to_be32(2 << 24);
  640. if (d->io_regions[i].type & PCI_BASE_ADDRESS_MEM_PREFETCH) {
  641. cells[j] |= cpu_to_be32(4 << 28);
  642. }
  643. }
  644. cells[j + 1] = 0;
  645. cells[j + 2] = 0;
  646. cells[j + 3] = cpu_to_be32(d->io_regions[i].size >> 32);
  647. cells[j + 4] = cpu_to_be32(d->io_regions[i].size);
  648. j += 5;
  649. }
  650. qemu_fdt_setprop(fi->fdt, node->str, "reg", cells, j * sizeof(cells[0]));
  651. qemu_fdt_setprop_string(fi->fdt, node->str, "name", name ?: pn);
  652. if (pci_get_byte(&d->config[PCI_INTERRUPT_PIN])) {
  653. qemu_fdt_setprop_cell(fi->fdt, node->str, "interrupts",
  654. pci_get_byte(&d->config[PCI_INTERRUPT_PIN]));
  655. }
  656. /* Pegasos2 firmware has subsystem-id amd subsystem-vendor-id swapped */
  657. qemu_fdt_setprop_cell(fi->fdt, node->str, "subsystem-vendor-id",
  658. pci_get_word(&d->config[PCI_SUBSYSTEM_ID]));
  659. qemu_fdt_setprop_cell(fi->fdt, node->str, "subsystem-id",
  660. pci_get_word(&d->config[PCI_SUBSYSTEM_VENDOR_ID]));
  661. cells[0] = pci_get_long(&d->config[PCI_CLASS_REVISION]);
  662. qemu_fdt_setprop_cell(fi->fdt, node->str, "class-code", cells[0] >> 8);
  663. qemu_fdt_setprop_cell(fi->fdt, node->str, "revision-id", cells[0] & 0xff);
  664. qemu_fdt_setprop_cell(fi->fdt, node->str, "device-id",
  665. pci_get_word(&d->config[PCI_DEVICE_ID]));
  666. qemu_fdt_setprop_cell(fi->fdt, node->str, "vendor-id",
  667. pci_get_word(&d->config[PCI_VENDOR_ID]));
  668. g_string_free(node, TRUE);
  669. }
  670. static void *build_fdt(MachineState *machine, int *fdt_size)
  671. {
  672. Pegasos2MachineState *pm = PEGASOS2_MACHINE(machine);
  673. PowerPCCPU *cpu = pm->cpu;
  674. PCIBus *pci_bus;
  675. FDTInfo fi;
  676. uint32_t cells[16];
  677. void *fdt = create_device_tree(fdt_size);
  678. fi.fdt = fdt;
  679. /* root node */
  680. qemu_fdt_setprop_string(fdt, "/", "CODEGEN,description",
  681. "Pegasos CHRP PowerPC System");
  682. qemu_fdt_setprop_string(fdt, "/", "CODEGEN,board", "Pegasos2");
  683. qemu_fdt_setprop_string(fdt, "/", "CODEGEN,vendor", "bplan GmbH");
  684. qemu_fdt_setprop_string(fdt, "/", "revision", "2B");
  685. qemu_fdt_setprop_string(fdt, "/", "model", "Pegasos2");
  686. qemu_fdt_setprop_string(fdt, "/", "device_type", "chrp");
  687. qemu_fdt_setprop_cell(fdt, "/", "#address-cells", 1);
  688. qemu_fdt_setprop_string(fdt, "/", "name", "bplan,Pegasos2");
  689. /* pci@c0000000 */
  690. qemu_fdt_add_subnode(fdt, "/pci@c0000000");
  691. cells[0] = 0;
  692. cells[1] = 0;
  693. qemu_fdt_setprop(fdt, "/pci@c0000000", "bus-range",
  694. cells, 2 * sizeof(cells[0]));
  695. qemu_fdt_setprop_cell(fdt, "/pci@c0000000", "pci-bridge-number", 1);
  696. cells[0] = cpu_to_be32(PCI0_MEM_BASE);
  697. cells[1] = cpu_to_be32(PCI0_MEM_SIZE);
  698. qemu_fdt_setprop(fdt, "/pci@c0000000", "reg", cells, 2 * sizeof(cells[0]));
  699. cells[0] = cpu_to_be32(0x01000000);
  700. cells[1] = 0;
  701. cells[2] = 0;
  702. cells[3] = cpu_to_be32(PCI0_IO_BASE);
  703. cells[4] = 0;
  704. cells[5] = cpu_to_be32(PCI0_IO_SIZE);
  705. cells[6] = cpu_to_be32(0x02000000);
  706. cells[7] = 0;
  707. cells[8] = cpu_to_be32(PCI0_MEM_BASE);
  708. cells[9] = cpu_to_be32(PCI0_MEM_BASE);
  709. cells[10] = 0;
  710. cells[11] = cpu_to_be32(PCI0_MEM_SIZE);
  711. qemu_fdt_setprop(fdt, "/pci@c0000000", "ranges",
  712. cells, 12 * sizeof(cells[0]));
  713. qemu_fdt_setprop_cell(fdt, "/pci@c0000000", "#size-cells", 2);
  714. qemu_fdt_setprop_cell(fdt, "/pci@c0000000", "#address-cells", 3);
  715. qemu_fdt_setprop_string(fdt, "/pci@c0000000", "device_type", "pci");
  716. qemu_fdt_setprop_string(fdt, "/pci@c0000000", "name", "pci");
  717. fi.path = "/pci@c0000000";
  718. pci_bus = mv64361_get_pci_bus(pm->mv, 0);
  719. pci_for_each_device_reverse(pci_bus, 0, add_pci_device, &fi);
  720. /* pci@80000000 */
  721. qemu_fdt_add_subnode(fdt, "/pci@80000000");
  722. cells[0] = 0;
  723. cells[1] = 0;
  724. qemu_fdt_setprop(fdt, "/pci@80000000", "bus-range",
  725. cells, 2 * sizeof(cells[0]));
  726. qemu_fdt_setprop_cell(fdt, "/pci@80000000", "pci-bridge-number", 0);
  727. cells[0] = cpu_to_be32(PCI1_MEM_BASE);
  728. cells[1] = cpu_to_be32(PCI1_MEM_SIZE);
  729. qemu_fdt_setprop(fdt, "/pci@80000000", "reg", cells, 2 * sizeof(cells[0]));
  730. qemu_fdt_setprop_cell(fdt, "/pci@80000000", "8259-interrupt-acknowledge",
  731. 0xf1000cb4);
  732. cells[0] = cpu_to_be32(0x01000000);
  733. cells[1] = 0;
  734. cells[2] = 0;
  735. cells[3] = cpu_to_be32(PCI1_IO_BASE);
  736. cells[4] = 0;
  737. cells[5] = cpu_to_be32(PCI1_IO_SIZE);
  738. cells[6] = cpu_to_be32(0x02000000);
  739. cells[7] = 0;
  740. cells[8] = cpu_to_be32(PCI1_MEM_BASE);
  741. cells[9] = cpu_to_be32(PCI1_MEM_BASE);
  742. cells[10] = 0;
  743. cells[11] = cpu_to_be32(PCI1_MEM_SIZE);
  744. qemu_fdt_setprop(fdt, "/pci@80000000", "ranges",
  745. cells, 12 * sizeof(cells[0]));
  746. qemu_fdt_setprop_cell(fdt, "/pci@80000000", "#size-cells", 2);
  747. qemu_fdt_setprop_cell(fdt, "/pci@80000000", "#address-cells", 3);
  748. qemu_fdt_setprop_string(fdt, "/pci@80000000", "device_type", "pci");
  749. qemu_fdt_setprop_string(fdt, "/pci@80000000", "name", "pci");
  750. fi.path = "/pci@80000000";
  751. pci_bus = mv64361_get_pci_bus(pm->mv, 1);
  752. pci_for_each_device_reverse(pci_bus, 0, add_pci_device, &fi);
  753. qemu_fdt_add_subnode(fdt, "/failsafe");
  754. qemu_fdt_setprop_string(fdt, "/failsafe", "device_type", "serial");
  755. qemu_fdt_setprop_string(fdt, "/failsafe", "name", "failsafe");
  756. qemu_fdt_add_subnode(fdt, "/rtas");
  757. qemu_fdt_setprop_cell(fdt, "/rtas", "system-reboot", RTAS_SYSTEM_REBOOT);
  758. qemu_fdt_setprop_cell(fdt, "/rtas", "hibernate", RTAS_HIBERNATE);
  759. qemu_fdt_setprop_cell(fdt, "/rtas", "suspend", RTAS_SUSPEND);
  760. qemu_fdt_setprop_cell(fdt, "/rtas", "power-off", RTAS_POWER_OFF);
  761. qemu_fdt_setprop_cell(fdt, "/rtas", "set-indicator", RTAS_SET_INDICATOR);
  762. qemu_fdt_setprop_cell(fdt, "/rtas", "display-character",
  763. RTAS_DISPLAY_CHARACTER);
  764. qemu_fdt_setprop_cell(fdt, "/rtas", "write-pci-config",
  765. RTAS_WRITE_PCI_CONFIG);
  766. qemu_fdt_setprop_cell(fdt, "/rtas", "read-pci-config",
  767. RTAS_READ_PCI_CONFIG);
  768. /* Pegasos2 firmware misspells check-exception and guests use that */
  769. qemu_fdt_setprop_cell(fdt, "/rtas", "check-execption",
  770. RTAS_CHECK_EXCEPTION);
  771. qemu_fdt_setprop_cell(fdt, "/rtas", "event-scan", RTAS_EVENT_SCAN);
  772. qemu_fdt_setprop_cell(fdt, "/rtas", "set-time-of-day",
  773. RTAS_SET_TIME_OF_DAY);
  774. qemu_fdt_setprop_cell(fdt, "/rtas", "get-time-of-day",
  775. RTAS_GET_TIME_OF_DAY);
  776. qemu_fdt_setprop_cell(fdt, "/rtas", "nvram-store", RTAS_NVRAM_STORE);
  777. qemu_fdt_setprop_cell(fdt, "/rtas", "nvram-fetch", RTAS_NVRAM_FETCH);
  778. qemu_fdt_setprop_cell(fdt, "/rtas", "restart-rtas", RTAS_RESTART_RTAS);
  779. qemu_fdt_setprop_cell(fdt, "/rtas", "rtas-error-log-max", 0);
  780. qemu_fdt_setprop_cell(fdt, "/rtas", "rtas-event-scan-rate", 0);
  781. qemu_fdt_setprop_cell(fdt, "/rtas", "rtas-display-device", 0);
  782. qemu_fdt_setprop_cell(fdt, "/rtas", "rtas-size", 20);
  783. qemu_fdt_setprop_cell(fdt, "/rtas", "rtas-version", 1);
  784. /* cpus */
  785. qemu_fdt_add_subnode(fdt, "/cpus");
  786. qemu_fdt_setprop_cell(fdt, "/cpus", "#cpus", 1);
  787. qemu_fdt_setprop_cell(fdt, "/cpus", "#address-cells", 1);
  788. qemu_fdt_setprop_cell(fdt, "/cpus", "#size-cells", 0);
  789. qemu_fdt_setprop_string(fdt, "/cpus", "name", "cpus");
  790. /* FIXME Get CPU name from CPU object */
  791. const char *cp = "/cpus/PowerPC,G4";
  792. qemu_fdt_add_subnode(fdt, cp);
  793. qemu_fdt_setprop_cell(fdt, cp, "l2cr", 0);
  794. qemu_fdt_setprop_cell(fdt, cp, "d-cache-size", 0x8000);
  795. qemu_fdt_setprop_cell(fdt, cp, "d-cache-block-size",
  796. cpu->env.dcache_line_size);
  797. qemu_fdt_setprop_cell(fdt, cp, "d-cache-line-size",
  798. cpu->env.dcache_line_size);
  799. qemu_fdt_setprop_cell(fdt, cp, "i-cache-size", 0x8000);
  800. qemu_fdt_setprop_cell(fdt, cp, "i-cache-block-size",
  801. cpu->env.icache_line_size);
  802. qemu_fdt_setprop_cell(fdt, cp, "i-cache-line-size",
  803. cpu->env.icache_line_size);
  804. if (cpu->env.id_tlbs) {
  805. qemu_fdt_setprop_cell(fdt, cp, "i-tlb-sets", cpu->env.nb_ways);
  806. qemu_fdt_setprop_cell(fdt, cp, "i-tlb-size", cpu->env.tlb_per_way);
  807. qemu_fdt_setprop_cell(fdt, cp, "d-tlb-sets", cpu->env.nb_ways);
  808. qemu_fdt_setprop_cell(fdt, cp, "d-tlb-size", cpu->env.tlb_per_way);
  809. qemu_fdt_setprop_string(fdt, cp, "tlb-split", "");
  810. }
  811. qemu_fdt_setprop_cell(fdt, cp, "tlb-sets", cpu->env.nb_ways);
  812. qemu_fdt_setprop_cell(fdt, cp, "tlb-size", cpu->env.nb_tlb);
  813. qemu_fdt_setprop_string(fdt, cp, "state", "running");
  814. if (cpu->env.insns_flags & PPC_ALTIVEC) {
  815. qemu_fdt_setprop_string(fdt, cp, "altivec", "");
  816. qemu_fdt_setprop_string(fdt, cp, "data-streams", "");
  817. }
  818. /*
  819. * FIXME What flags do data-streams, external-control and
  820. * performance-monitor depend on?
  821. */
  822. qemu_fdt_setprop_string(fdt, cp, "external-control", "");
  823. if (cpu->env.insns_flags & PPC_FLOAT_FSQRT) {
  824. qemu_fdt_setprop_string(fdt, cp, "general-purpose", "");
  825. }
  826. qemu_fdt_setprop_string(fdt, cp, "performance-monitor", "");
  827. if (cpu->env.insns_flags & PPC_FLOAT_FRES) {
  828. qemu_fdt_setprop_string(fdt, cp, "graphics", "");
  829. }
  830. qemu_fdt_setprop_cell(fdt, cp, "reservation-granule-size", 4);
  831. qemu_fdt_setprop_cell(fdt, cp, "timebase-frequency",
  832. cpu->env.tb_env->tb_freq);
  833. qemu_fdt_setprop_cell(fdt, cp, "bus-frequency", BUS_FREQ_HZ);
  834. qemu_fdt_setprop_cell(fdt, cp, "clock-frequency", BUS_FREQ_HZ * 7.5);
  835. qemu_fdt_setprop_cell(fdt, cp, "cpu-version", cpu->env.spr[SPR_PVR]);
  836. cells[0] = 0;
  837. cells[1] = 0;
  838. qemu_fdt_setprop(fdt, cp, "reg", cells, 2 * sizeof(cells[0]));
  839. qemu_fdt_setprop_string(fdt, cp, "device_type", "cpu");
  840. qemu_fdt_setprop_string(fdt, cp, "name", strrchr(cp, '/') + 1);
  841. /* memory */
  842. qemu_fdt_add_subnode(fdt, "/memory@0");
  843. cells[0] = 0;
  844. cells[1] = cpu_to_be32(machine->ram_size);
  845. qemu_fdt_setprop(fdt, "/memory@0", "reg", cells, 2 * sizeof(cells[0]));
  846. qemu_fdt_setprop_string(fdt, "/memory@0", "device_type", "memory");
  847. qemu_fdt_setprop_string(fdt, "/memory@0", "name", "memory");
  848. qemu_fdt_add_subnode(fdt, "/chosen");
  849. qemu_fdt_setprop_string(fdt, "/chosen", "bootargs",
  850. machine->kernel_cmdline ?: "");
  851. qemu_fdt_setprop_string(fdt, "/chosen", "name", "chosen");
  852. qemu_fdt_add_subnode(fdt, "/openprom");
  853. qemu_fdt_setprop_string(fdt, "/openprom", "model", "Pegasos2,1.1");
  854. return fdt;
  855. }