1 /* 2 * SPAPR machine hooks to Virtual Open Firmware, 3 * 4 * SPDX-License-Identifier: GPL-2.0-or-later 5 */ 6 #include "qemu/osdep.h" 7 #include "qemu-common.h" 8 #include "qapi/error.h" 9 #include "hw/ppc/spapr.h" 10 #include "hw/ppc/spapr_vio.h" 11 #include "hw/ppc/spapr_cpu_core.h" 12 #include "hw/ppc/fdt.h" 13 #include "hw/ppc/vof.h" 14 #include "sysemu/sysemu.h" 15 #include "qom/qom-qobject.h" 16 #include "trace.h" 17 18 target_ulong spapr_h_vof_client(PowerPCCPU *cpu, SpaprMachineState *spapr, 19 target_ulong opcode, target_ulong *_args) 20 { 21 int ret = vof_client_call(MACHINE(spapr), spapr->vof, spapr->fdt_blob, 22 ppc64_phys_to_real(_args[0])); 23 24 if (ret) { 25 return H_PARAMETER; 26 } 27 return H_SUCCESS; 28 } 29 30 void spapr_vof_client_dt_finalize(SpaprMachineState *spapr, void *fdt) 31 { 32 char *stdout_path = spapr_vio_stdout_path(spapr->vio_bus); 33 34 vof_build_dt(fdt, spapr->vof); 35 36 if (spapr->vof->bootargs) { 37 int chosen; 38 39 _FDT(chosen = fdt_path_offset(fdt, "/chosen")); 40 /* 41 * If the client did not change "bootargs", spapr_dt_chosen() must have 42 * stored machine->kernel_cmdline in it before getting here. 43 */ 44 _FDT(fdt_setprop_string(fdt, chosen, "bootargs", spapr->vof->bootargs)); 45 } 46 47 /* 48 * SLOF-less setup requires an open instance of stdout for early 49 * kernel printk. By now all phandles are settled so we can open 50 * the default serial console. 51 */ 52 if (stdout_path) { 53 _FDT(vof_client_open_store(fdt, spapr->vof, "/chosen", "stdout", 54 stdout_path)); 55 } 56 } 57 58 void spapr_vof_reset(SpaprMachineState *spapr, void *fdt, Error **errp) 59 { 60 target_ulong stack_ptr; 61 Vof *vof = spapr->vof; 62 PowerPCCPU *first_ppc_cpu = POWERPC_CPU(first_cpu); 63 64 vof_init(vof, spapr->rma_size, errp); 65 66 stack_ptr = vof_claim(vof, 0, VOF_STACK_SIZE, VOF_STACK_SIZE); 67 if (stack_ptr == -1) { 68 error_setg(errp, "Memory allocation for stack failed"); 69 return; 70 } 71 /* Stack grows downwards plus reserve space for the minimum stack frame */ 72 stack_ptr += VOF_STACK_SIZE - 0x20; 73 74 if (spapr->kernel_size && 75 vof_claim(vof, spapr->kernel_addr, spapr->kernel_size, 0) == -1) { 76 error_setg(errp, "Memory for kernel is in use"); 77 return; 78 } 79 80 if (spapr->initrd_size && 81 vof_claim(vof, spapr->initrd_base, spapr->initrd_size, 0) == -1) { 82 error_setg(errp, "Memory for initramdisk is in use"); 83 return; 84 } 85 86 spapr_vof_client_dt_finalize(spapr, fdt); 87 88 spapr_cpu_set_entry_state(first_ppc_cpu, SPAPR_ENTRY_POINT, 89 stack_ptr, spapr->initrd_base, 90 spapr->initrd_size); 91 92 /* 93 * At this point the expected allocation map is: 94 * 95 * 0..c38 - the initial firmware 96 * 8000..10000 - stack 97 * 400000.. - kernel 98 * 3ea0000.. - initramdisk 99 * 100 * We skip writing FDT as nothing expects it; OF client interface is 101 * going to be used for reading the device tree. 102 */ 103 } 104 105 void spapr_vof_quiesce(MachineState *ms) 106 { 107 SpaprMachineState *spapr = SPAPR_MACHINE(ms); 108 109 spapr->fdt_size = fdt_totalsize(spapr->fdt_blob); 110 spapr->fdt_initial_size = spapr->fdt_size; 111 } 112 113 bool spapr_vof_setprop(MachineState *ms, const char *path, const char *propname, 114 void *val, int vallen) 115 { 116 SpaprMachineState *spapr = SPAPR_MACHINE(ms); 117 118 /* 119 * We only allow changing properties which we know how to update in QEMU 120 * OR 121 * the ones which we know that they need to survive during "quiesce". 122 */ 123 124 if (strcmp(path, "/rtas") == 0) { 125 if (strcmp(propname, "linux,rtas-base") == 0 || 126 strcmp(propname, "linux,rtas-entry") == 0) { 127 /* These need to survive quiesce so let them store in the FDT */ 128 return true; 129 } 130 } 131 132 if (strcmp(path, "/chosen") == 0) { 133 if (strcmp(propname, "bootargs") == 0) { 134 Vof *vof = spapr->vof; 135 136 g_free(vof->bootargs); 137 vof->bootargs = g_strndup(val, vallen); 138 return true; 139 } 140 if (strcmp(propname, "linux,initrd-start") == 0) { 141 if (vallen == sizeof(uint32_t)) { 142 spapr->initrd_base = ldl_be_p(val); 143 return true; 144 } 145 if (vallen == sizeof(uint64_t)) { 146 spapr->initrd_base = ldq_be_p(val); 147 return true; 148 } 149 return false; 150 } 151 if (strcmp(propname, "linux,initrd-end") == 0) { 152 if (vallen == sizeof(uint32_t)) { 153 spapr->initrd_size = ldl_be_p(val) - spapr->initrd_base; 154 return true; 155 } 156 if (vallen == sizeof(uint64_t)) { 157 spapr->initrd_size = ldq_be_p(val) - spapr->initrd_base; 158 return true; 159 } 160 return false; 161 } 162 } 163 164 return true; 165 } 166