spapr: Implement Open Firmware client interface
[qemu/ar7.git] / hw / ppc / spapr_vof.c
blob131a03fec0a20fca73753f927cf38f8dae6a883f
1 /*
2 * SPAPR machine hooks to Virtual Open Firmware,
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/fdt.h"
12 #include "hw/ppc/vof.h"
13 #include "sysemu/sysemu.h"
14 #include "qom/qom-qobject.h"
15 #include "trace.h"
17 target_ulong spapr_h_vof_client(PowerPCCPU *cpu, SpaprMachineState *spapr,
18 target_ulong opcode, target_ulong *_args)
20 int ret = vof_client_call(MACHINE(spapr), spapr->vof, spapr->fdt_blob,
21 ppc64_phys_to_real(_args[0]));
23 if (ret) {
24 return H_PARAMETER;
26 return H_SUCCESS;
29 void spapr_vof_client_dt_finalize(SpaprMachineState *spapr, void *fdt)
31 char *stdout_path = spapr_vio_stdout_path(spapr->vio_bus);
32 int chosen;
34 vof_build_dt(fdt, spapr->vof);
36 _FDT(chosen = fdt_path_offset(fdt, "/chosen"));
37 _FDT(fdt_setprop_string(fdt, chosen, "bootargs",
38 spapr->vof->bootargs ? : ""));
41 * SLOF-less setup requires an open instance of stdout for early
42 * kernel printk. By now all phandles are settled so we can open
43 * the default serial console.
45 if (stdout_path) {
46 _FDT(vof_client_open_store(fdt, spapr->vof, "/chosen", "stdout",
47 stdout_path));
51 void spapr_vof_reset(SpaprMachineState *spapr, void *fdt,
52 target_ulong *stack_ptr, Error **errp)
54 Vof *vof = spapr->vof;
56 vof_init(vof, spapr->rma_size, errp);
58 *stack_ptr = vof_claim(vof, 0, VOF_STACK_SIZE, VOF_STACK_SIZE);
59 if (*stack_ptr == -1) {
60 error_setg(errp, "Memory allocation for stack failed");
61 return;
63 /* Stack grows downwards plus reserve space for the minimum stack frame */
64 *stack_ptr += VOF_STACK_SIZE - 0x20;
66 if (spapr->kernel_size &&
67 vof_claim(vof, spapr->kernel_addr, spapr->kernel_size, 0) == -1) {
68 error_setg(errp, "Memory for kernel is in use");
69 return;
72 if (spapr->initrd_size &&
73 vof_claim(vof, spapr->initrd_base, spapr->initrd_size, 0) == -1) {
74 error_setg(errp, "Memory for initramdisk is in use");
75 return;
78 spapr_vof_client_dt_finalize(spapr, fdt);
81 * At this point the expected allocation map is:
83 * 0..c38 - the initial firmware
84 * 8000..10000 - stack
85 * 400000.. - kernel
86 * 3ea0000.. - initramdisk
88 * We skip writing FDT as nothing expects it; OF client interface is
89 * going to be used for reading the device tree.
93 void spapr_vof_quiesce(MachineState *ms)
95 SpaprMachineState *spapr = SPAPR_MACHINE(ms);
97 spapr->fdt_size = fdt_totalsize(spapr->fdt_blob);
98 spapr->fdt_initial_size = spapr->fdt_size;
101 bool spapr_vof_setprop(MachineState *ms, const char *path, const char *propname,
102 void *val, int vallen)
104 SpaprMachineState *spapr = SPAPR_MACHINE(ms);
107 * We only allow changing properties which we know how to update in QEMU
108 * OR
109 * the ones which we know that they need to survive during "quiesce".
112 if (strcmp(path, "/rtas") == 0) {
113 if (strcmp(propname, "linux,rtas-base") == 0 ||
114 strcmp(propname, "linux,rtas-entry") == 0) {
115 /* These need to survive quiesce so let them store in the FDT */
116 return true;
120 if (strcmp(path, "/chosen") == 0) {
121 if (strcmp(propname, "bootargs") == 0) {
122 Vof *vof = spapr->vof;
124 g_free(vof->bootargs);
125 vof->bootargs = g_strndup(val, vallen);
126 return true;
128 if (strcmp(propname, "linux,initrd-start") == 0) {
129 if (vallen == sizeof(uint32_t)) {
130 spapr->initrd_base = ldl_be_p(val);
131 return true;
133 if (vallen == sizeof(uint64_t)) {
134 spapr->initrd_base = ldq_be_p(val);
135 return true;
137 return false;
139 if (strcmp(propname, "linux,initrd-end") == 0) {
140 if (vallen == sizeof(uint32_t)) {
141 spapr->initrd_size = ldl_be_p(val) - spapr->initrd_base;
142 return true;
144 if (vallen == sizeof(uint64_t)) {
145 spapr->initrd_size = ldq_be_p(val) - spapr->initrd_base;
146 return true;
148 return false;
152 return true;