spapr: Implement Open Firmware client interface
The PAPR platform describes an OS environment that's presented by a combination of a hypervisor and firmware. The features it specifies require collaboration between the firmware and the hypervisor. Since the beginning, the runtime component of the firmware (RTAS) has been implemented as a 20 byte shim which simply forwards it to a hypercall implemented in qemu. The boot time firmware component is SLOF - but a build that's specific to qemu, and has always needed to be updated in sync with it. Even though we've managed to limit the amount of runtime communication we need between qemu and SLOF, there's some, and it has become increasingly awkward to handle as we've implemented new features. This implements a boot time OF client interface (CI) which is enabled by a new "x-vof" pseries machine option (stands for "Virtual Open Firmware). When enabled, QEMU implements the custom H_OF_CLIENT hcall which implements Open Firmware Client Interface (OF CI). This allows using a smaller stateless firmware which does not have to manage the device tree. The new "vof.bin" firmware image is included with source code under pc-bios/. It also includes RTAS blob. This implements a handful of CI methods just to get -kernel/-initrd working. In particular, this implements the device tree fetching and simple memory allocator - "claim" (an OF CI memory allocator) and updates "/memory@0/available" to report the client about available memory. This implements changing some device tree properties which we know how to deal with, the rest is ignored. To allow changes, this skips fdt_pack() when x-vof=on as not packing the blob leaves some room for appending. In absence of SLOF, this assigns phandles to device tree nodes to make device tree traversing work. When x-vof=on, this adds "/chosen" every time QEMU (re)builds a tree. This adds basic instances support which are managed by a hash map ihandle -> [phandle]. Before the guest started, the used memory is: 0..e60 - the initial firmware 8000..10000 - stack 400000.. - kernel 3ea0000.. - initramdisk This OF CI does not implement "interpret". Unlike SLOF, this does not format uninitialized nvram. Instead, this includes a disk image with pre-formatted nvram. With this basic support, this can only boot into kernel directly. However this is just enough for the petitboot kernel and initradmdisk to boot from any possible source. Note this requires reasonably recent guest kernel with: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=df5be5be8735 The immediate benefit is much faster booting time which especially crucial with fully emulated early CPU bring up environments. Also this may come handy when/if GRUB-in-the-userspace sees light of the day. This separates VOF and sPAPR in a hope that VOF bits may be reused by other POWERPC boards which do not support pSeries. This assumes potential support for booting from QEMU backends such as blockdev or netdev without devices/drivers used. Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru> Message-Id: <20210625055155.2252896-1-aik@ozlabs.ru> Reviewed-by: BALATON Zoltan <balaton@eik.bme.hu> [dwg: Adjusted some includes which broke compile in some more obscure compilation setups] Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
parent
ea41397055
commit
fc8c745d50
12
MAINTAINERS
12
MAINTAINERS
|
@ -1360,6 +1360,18 @@ F: hw/pci-host/mv64361.c
|
||||||
F: hw/pci-host/mv643xx.h
|
F: hw/pci-host/mv643xx.h
|
||||||
F: include/hw/pci-host/mv64361.h
|
F: include/hw/pci-host/mv64361.h
|
||||||
|
|
||||||
|
Virtual Open Firmware (VOF)
|
||||||
|
M: Alexey Kardashevskiy <aik@ozlabs.ru>
|
||||||
|
M: David Gibson <david@gibson.dropbear.id.au>
|
||||||
|
M: Greg Kurz <groug@kaod.org>
|
||||||
|
L: qemu-ppc@nongnu.org
|
||||||
|
S: Maintained
|
||||||
|
F: hw/ppc/spapr_vof*
|
||||||
|
F: hw/ppc/vof*
|
||||||
|
F: include/hw/ppc/vof*
|
||||||
|
F: pc-bios/vof/*
|
||||||
|
F: pc-bios/vof*
|
||||||
|
|
||||||
RISC-V Machines
|
RISC-V Machines
|
||||||
---------------
|
---------------
|
||||||
OpenTitan
|
OpenTitan
|
||||||
|
|
|
@ -13,6 +13,7 @@ config PSERIES
|
||||||
select MSI_NONBROKEN
|
select MSI_NONBROKEN
|
||||||
select FDT_PPC
|
select FDT_PPC
|
||||||
select CHRP_NVRAM
|
select CHRP_NVRAM
|
||||||
|
select VOF
|
||||||
|
|
||||||
config SPAPR_RNG
|
config SPAPR_RNG
|
||||||
bool
|
bool
|
||||||
|
@ -144,3 +145,6 @@ config FW_CFG_PPC
|
||||||
|
|
||||||
config FDT_PPC
|
config FDT_PPC
|
||||||
bool
|
bool
|
||||||
|
|
||||||
|
config VOF
|
||||||
|
bool
|
||||||
|
|
|
@ -84,4 +84,7 @@ ppc_ss.add(when: 'CONFIG_VIRTEX', if_true: files('virtex_ml507.c'))
|
||||||
# Pegasos2
|
# Pegasos2
|
||||||
ppc_ss.add(when: 'CONFIG_PEGASOS2', if_true: files('pegasos2.c'))
|
ppc_ss.add(when: 'CONFIG_PEGASOS2', if_true: files('pegasos2.c'))
|
||||||
|
|
||||||
|
ppc_ss.add(when: 'CONFIG_VOF', if_true: files('vof.c'))
|
||||||
|
ppc_ss.add(when: ['CONFIG_VOF', 'CONFIG_PSERIES'], if_true: files('spapr_vof.c'))
|
||||||
|
|
||||||
hw_arch += {'ppc': ppc_ss}
|
hw_arch += {'ppc': ppc_ss}
|
||||||
|
|
|
@ -101,6 +101,7 @@
|
||||||
#define FDT_MAX_ADDR 0x80000000 /* FDT must stay below that */
|
#define FDT_MAX_ADDR 0x80000000 /* FDT must stay below that */
|
||||||
#define FW_MAX_SIZE 0x400000
|
#define FW_MAX_SIZE 0x400000
|
||||||
#define FW_FILE_NAME "slof.bin"
|
#define FW_FILE_NAME "slof.bin"
|
||||||
|
#define FW_FILE_NAME_VOF "vof.bin"
|
||||||
#define FW_OVERHEAD 0x2800000
|
#define FW_OVERHEAD 0x2800000
|
||||||
#define KERNEL_LOAD_ADDR FW_MAX_SIZE
|
#define KERNEL_LOAD_ADDR FW_MAX_SIZE
|
||||||
|
|
||||||
|
@ -1643,22 +1644,37 @@ static void spapr_machine_reset(MachineState *machine)
|
||||||
fdt_addr = MIN(spapr->rma_size, FDT_MAX_ADDR) - FDT_MAX_SIZE;
|
fdt_addr = MIN(spapr->rma_size, FDT_MAX_ADDR) - FDT_MAX_SIZE;
|
||||||
|
|
||||||
fdt = spapr_build_fdt(spapr, true, FDT_MAX_SIZE);
|
fdt = spapr_build_fdt(spapr, true, FDT_MAX_SIZE);
|
||||||
|
if (spapr->vof) {
|
||||||
|
target_ulong stack_ptr = 0;
|
||||||
|
|
||||||
|
spapr_vof_reset(spapr, fdt, &stack_ptr, &error_fatal);
|
||||||
|
|
||||||
|
spapr_cpu_set_entry_state(first_ppc_cpu, SPAPR_ENTRY_POINT,
|
||||||
|
stack_ptr, spapr->initrd_base,
|
||||||
|
spapr->initrd_size);
|
||||||
|
/* VOF is 32bit BE so enforce MSR here */
|
||||||
|
first_ppc_cpu->env.msr &= ~((1ULL << MSR_SF) | (1ULL << MSR_LE));
|
||||||
|
/*
|
||||||
|
* Do not pack the FDT as the client may change properties.
|
||||||
|
* VOF client does not expect the FDT so we do not load it to the VM.
|
||||||
|
*/
|
||||||
|
} else {
|
||||||
rc = fdt_pack(fdt);
|
rc = fdt_pack(fdt);
|
||||||
|
|
||||||
/* Should only fail if we've built a corrupted tree */
|
/* Should only fail if we've built a corrupted tree */
|
||||||
assert(rc == 0);
|
assert(rc == 0);
|
||||||
|
|
||||||
/* Load the fdt */
|
spapr_cpu_set_entry_state(first_ppc_cpu, SPAPR_ENTRY_POINT,
|
||||||
qemu_fdt_dumpdtb(fdt, fdt_totalsize(fdt));
|
0, fdt_addr, 0);
|
||||||
cpu_physical_memory_write(fdt_addr, fdt, fdt_totalsize(fdt));
|
cpu_physical_memory_write(fdt_addr, fdt, fdt_totalsize(fdt));
|
||||||
|
}
|
||||||
|
qemu_fdt_dumpdtb(fdt, fdt_totalsize(fdt));
|
||||||
|
|
||||||
g_free(spapr->fdt_blob);
|
g_free(spapr->fdt_blob);
|
||||||
spapr->fdt_size = fdt_totalsize(fdt);
|
spapr->fdt_size = fdt_totalsize(fdt);
|
||||||
spapr->fdt_initial_size = spapr->fdt_size;
|
spapr->fdt_initial_size = spapr->fdt_size;
|
||||||
spapr->fdt_blob = fdt;
|
spapr->fdt_blob = fdt;
|
||||||
|
|
||||||
/* Set up the entry state */
|
/* Set up the entry state */
|
||||||
spapr_cpu_set_entry_state(first_ppc_cpu, SPAPR_ENTRY_POINT, 0, fdt_addr, 0);
|
|
||||||
first_ppc_cpu->env.gpr[5] = 0;
|
first_ppc_cpu->env.gpr[5] = 0;
|
||||||
|
|
||||||
spapr->fwnmi_system_reset_addr = -1;
|
spapr->fwnmi_system_reset_addr = -1;
|
||||||
|
@ -2661,7 +2677,8 @@ static void spapr_machine_init(MachineState *machine)
|
||||||
SpaprMachineState *spapr = SPAPR_MACHINE(machine);
|
SpaprMachineState *spapr = SPAPR_MACHINE(machine);
|
||||||
SpaprMachineClass *smc = SPAPR_MACHINE_GET_CLASS(machine);
|
SpaprMachineClass *smc = SPAPR_MACHINE_GET_CLASS(machine);
|
||||||
MachineClass *mc = MACHINE_GET_CLASS(machine);
|
MachineClass *mc = MACHINE_GET_CLASS(machine);
|
||||||
const char *bios_name = machine->firmware ?: FW_FILE_NAME;
|
const char *bios_default = spapr->vof ? FW_FILE_NAME_VOF : FW_FILE_NAME;
|
||||||
|
const char *bios_name = machine->firmware ?: bios_default;
|
||||||
const char *kernel_filename = machine->kernel_filename;
|
const char *kernel_filename = machine->kernel_filename;
|
||||||
const char *initrd_filename = machine->initrd_filename;
|
const char *initrd_filename = machine->initrd_filename;
|
||||||
PCIHostState *phb;
|
PCIHostState *phb;
|
||||||
|
@ -3018,6 +3035,10 @@ static void spapr_machine_init(MachineState *machine)
|
||||||
}
|
}
|
||||||
|
|
||||||
qemu_cond_init(&spapr->fwnmi_machine_check_interlock_cond);
|
qemu_cond_init(&spapr->fwnmi_machine_check_interlock_cond);
|
||||||
|
if (spapr->vof) {
|
||||||
|
spapr->vof->fw_size = fw_size; /* for claim() on itself */
|
||||||
|
spapr_register_hypercall(KVMPPC_H_VOF_CLIENT, spapr_h_vof_client);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define DEFAULT_KVM_TYPE "auto"
|
#define DEFAULT_KVM_TYPE "auto"
|
||||||
|
@ -3208,6 +3229,28 @@ static void spapr_set_resize_hpt(Object *obj, const char *value, Error **errp)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool spapr_get_vof(Object *obj, Error **errp)
|
||||||
|
{
|
||||||
|
SpaprMachineState *spapr = SPAPR_MACHINE(obj);
|
||||||
|
|
||||||
|
return spapr->vof != NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void spapr_set_vof(Object *obj, bool value, Error **errp)
|
||||||
|
{
|
||||||
|
SpaprMachineState *spapr = SPAPR_MACHINE(obj);
|
||||||
|
|
||||||
|
if (spapr->vof) {
|
||||||
|
vof_cleanup(spapr->vof);
|
||||||
|
g_free(spapr->vof);
|
||||||
|
spapr->vof = NULL;
|
||||||
|
}
|
||||||
|
if (!value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
spapr->vof = g_malloc0(sizeof(*spapr->vof));
|
||||||
|
}
|
||||||
|
|
||||||
static char *spapr_get_ic_mode(Object *obj, Error **errp)
|
static char *spapr_get_ic_mode(Object *obj, Error **errp)
|
||||||
{
|
{
|
||||||
SpaprMachineState *spapr = SPAPR_MACHINE(obj);
|
SpaprMachineState *spapr = SPAPR_MACHINE(obj);
|
||||||
|
@ -3333,6 +3376,11 @@ static void spapr_instance_init(Object *obj)
|
||||||
stringify(KERNEL_LOAD_ADDR)
|
stringify(KERNEL_LOAD_ADDR)
|
||||||
" for -kernel is the default");
|
" for -kernel is the default");
|
||||||
spapr->kernel_addr = KERNEL_LOAD_ADDR;
|
spapr->kernel_addr = KERNEL_LOAD_ADDR;
|
||||||
|
|
||||||
|
object_property_add_bool(obj, "x-vof", spapr_get_vof, spapr_set_vof);
|
||||||
|
object_property_set_description(obj, "x-vof",
|
||||||
|
"Enable Virtual Open Firmware (experimental)");
|
||||||
|
|
||||||
/* The machine class defines the default interrupt controller mode */
|
/* The machine class defines the default interrupt controller mode */
|
||||||
spapr->irq = smc->irq;
|
spapr->irq = smc->irq;
|
||||||
object_property_add_str(obj, "ic-mode", spapr_get_ic_mode,
|
object_property_add_str(obj, "ic-mode", spapr_get_ic_mode,
|
||||||
|
@ -4496,6 +4544,7 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data)
|
||||||
XICSFabricClass *xic = XICS_FABRIC_CLASS(oc);
|
XICSFabricClass *xic = XICS_FABRIC_CLASS(oc);
|
||||||
InterruptStatsProviderClass *ispc = INTERRUPT_STATS_PROVIDER_CLASS(oc);
|
InterruptStatsProviderClass *ispc = INTERRUPT_STATS_PROVIDER_CLASS(oc);
|
||||||
XiveFabricClass *xfc = XIVE_FABRIC_CLASS(oc);
|
XiveFabricClass *xfc = XIVE_FABRIC_CLASS(oc);
|
||||||
|
VofMachineIfClass *vmc = VOF_MACHINE_CLASS(oc);
|
||||||
|
|
||||||
mc->desc = "pSeries Logical Partition (PAPR compliant)";
|
mc->desc = "pSeries Logical Partition (PAPR compliant)";
|
||||||
mc->ignore_boot_device_suffixes = true;
|
mc->ignore_boot_device_suffixes = true;
|
||||||
|
@ -4584,6 +4633,9 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data)
|
||||||
smc->smp_threads_vsmt = true;
|
smc->smp_threads_vsmt = true;
|
||||||
smc->nr_xirqs = SPAPR_NR_XIRQS;
|
smc->nr_xirqs = SPAPR_NR_XIRQS;
|
||||||
xfc->match_nvt = spapr_match_nvt;
|
xfc->match_nvt = spapr_match_nvt;
|
||||||
|
vmc->client_architecture_support = spapr_vof_client_architecture_support;
|
||||||
|
vmc->quiesce = spapr_vof_quiesce;
|
||||||
|
vmc->setprop = spapr_vof_setprop;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const TypeInfo spapr_machine_info = {
|
static const TypeInfo spapr_machine_info = {
|
||||||
|
@ -4603,6 +4655,7 @@ static const TypeInfo spapr_machine_info = {
|
||||||
{ TYPE_XICS_FABRIC },
|
{ TYPE_XICS_FABRIC },
|
||||||
{ TYPE_INTERRUPT_STATS_PROVIDER },
|
{ TYPE_INTERRUPT_STATS_PROVIDER },
|
||||||
{ TYPE_XIVE_FABRIC },
|
{ TYPE_XIVE_FABRIC },
|
||||||
|
{ TYPE_VOF_MACHINE_IF },
|
||||||
{ }
|
{ }
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -1080,7 +1080,7 @@ target_ulong do_client_architecture_support(PowerPCCPU *cpu,
|
||||||
SpaprOptionVector *ov1_guest, *ov5_guest;
|
SpaprOptionVector *ov1_guest, *ov5_guest;
|
||||||
bool guest_radix;
|
bool guest_radix;
|
||||||
bool raw_mode_supported = false;
|
bool raw_mode_supported = false;
|
||||||
bool guest_xive;
|
bool guest_xive, reset_fdt = false;
|
||||||
CPUState *cs;
|
CPUState *cs;
|
||||||
void *fdt;
|
void *fdt;
|
||||||
uint32_t max_compat = spapr->max_compat_pvr;
|
uint32_t max_compat = spapr->max_compat_pvr;
|
||||||
|
@ -1233,8 +1233,8 @@ target_ulong do_client_architecture_support(PowerPCCPU *cpu,
|
||||||
spapr_setup_hpt(spapr);
|
spapr_setup_hpt(spapr);
|
||||||
}
|
}
|
||||||
|
|
||||||
fdt = spapr_build_fdt(spapr, false, fdt_bufsize);
|
reset_fdt = spapr->vof != NULL;
|
||||||
|
fdt = spapr_build_fdt(spapr, reset_fdt, fdt_bufsize);
|
||||||
g_free(spapr->fdt_blob);
|
g_free(spapr->fdt_blob);
|
||||||
spapr->fdt_size = fdt_totalsize(fdt);
|
spapr->fdt_size = fdt_totalsize(fdt);
|
||||||
spapr->fdt_initial_size = spapr->fdt_size;
|
spapr->fdt_initial_size = spapr->fdt_size;
|
||||||
|
@ -1277,6 +1277,25 @@ static target_ulong h_client_architecture_support(PowerPCCPU *cpu,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
target_ulong spapr_vof_client_architecture_support(MachineState *ms,
|
||||||
|
CPUState *cs,
|
||||||
|
target_ulong ovec_addr)
|
||||||
|
{
|
||||||
|
SpaprMachineState *spapr = SPAPR_MACHINE(ms);
|
||||||
|
|
||||||
|
target_ulong ret = do_client_architecture_support(POWERPC_CPU(cs), spapr,
|
||||||
|
ovec_addr, FDT_MAX_SIZE);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This adds stdout and generates phandles for boottime and CAS FDTs.
|
||||||
|
* It is alright to update the FDT here as do_client_architecture_support()
|
||||||
|
* does not pack it.
|
||||||
|
*/
|
||||||
|
spapr_vof_client_dt_finalize(spapr, spapr->fdt_blob);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static target_ulong h_get_cpu_characteristics(PowerPCCPU *cpu,
|
static target_ulong h_get_cpu_characteristics(PowerPCCPU *cpu,
|
||||||
SpaprMachineState *spapr,
|
SpaprMachineState *spapr,
|
||||||
target_ulong opcode,
|
target_ulong opcode,
|
||||||
|
|
|
@ -0,0 +1,153 @@
|
||||||
|
/*
|
||||||
|
* SPAPR machine hooks to Virtual Open Firmware,
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
*/
|
||||||
|
#include "qemu/osdep.h"
|
||||||
|
#include "qemu-common.h"
|
||||||
|
#include "qapi/error.h"
|
||||||
|
#include "hw/ppc/spapr.h"
|
||||||
|
#include "hw/ppc/spapr_vio.h"
|
||||||
|
#include "hw/ppc/fdt.h"
|
||||||
|
#include "hw/ppc/vof.h"
|
||||||
|
#include "sysemu/sysemu.h"
|
||||||
|
#include "qom/qom-qobject.h"
|
||||||
|
#include "trace.h"
|
||||||
|
|
||||||
|
target_ulong spapr_h_vof_client(PowerPCCPU *cpu, SpaprMachineState *spapr,
|
||||||
|
target_ulong opcode, target_ulong *_args)
|
||||||
|
{
|
||||||
|
int ret = vof_client_call(MACHINE(spapr), spapr->vof, spapr->fdt_blob,
|
||||||
|
ppc64_phys_to_real(_args[0]));
|
||||||
|
|
||||||
|
if (ret) {
|
||||||
|
return H_PARAMETER;
|
||||||
|
}
|
||||||
|
return H_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
void spapr_vof_client_dt_finalize(SpaprMachineState *spapr, void *fdt)
|
||||||
|
{
|
||||||
|
char *stdout_path = spapr_vio_stdout_path(spapr->vio_bus);
|
||||||
|
int chosen;
|
||||||
|
|
||||||
|
vof_build_dt(fdt, spapr->vof);
|
||||||
|
|
||||||
|
_FDT(chosen = fdt_path_offset(fdt, "/chosen"));
|
||||||
|
_FDT(fdt_setprop_string(fdt, chosen, "bootargs",
|
||||||
|
spapr->vof->bootargs ? : ""));
|
||||||
|
|
||||||
|
/*
|
||||||
|
* SLOF-less setup requires an open instance of stdout for early
|
||||||
|
* kernel printk. By now all phandles are settled so we can open
|
||||||
|
* the default serial console.
|
||||||
|
*/
|
||||||
|
if (stdout_path) {
|
||||||
|
_FDT(vof_client_open_store(fdt, spapr->vof, "/chosen", "stdout",
|
||||||
|
stdout_path));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void spapr_vof_reset(SpaprMachineState *spapr, void *fdt,
|
||||||
|
target_ulong *stack_ptr, Error **errp)
|
||||||
|
{
|
||||||
|
Vof *vof = spapr->vof;
|
||||||
|
|
||||||
|
vof_init(vof, spapr->rma_size, errp);
|
||||||
|
|
||||||
|
*stack_ptr = vof_claim(vof, 0, VOF_STACK_SIZE, VOF_STACK_SIZE);
|
||||||
|
if (*stack_ptr == -1) {
|
||||||
|
error_setg(errp, "Memory allocation for stack failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
/* Stack grows downwards plus reserve space for the minimum stack frame */
|
||||||
|
*stack_ptr += VOF_STACK_SIZE - 0x20;
|
||||||
|
|
||||||
|
if (spapr->kernel_size &&
|
||||||
|
vof_claim(vof, spapr->kernel_addr, spapr->kernel_size, 0) == -1) {
|
||||||
|
error_setg(errp, "Memory for kernel is in use");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (spapr->initrd_size &&
|
||||||
|
vof_claim(vof, spapr->initrd_base, spapr->initrd_size, 0) == -1) {
|
||||||
|
error_setg(errp, "Memory for initramdisk is in use");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
spapr_vof_client_dt_finalize(spapr, fdt);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* At this point the expected allocation map is:
|
||||||
|
*
|
||||||
|
* 0..c38 - the initial firmware
|
||||||
|
* 8000..10000 - stack
|
||||||
|
* 400000.. - kernel
|
||||||
|
* 3ea0000.. - initramdisk
|
||||||
|
*
|
||||||
|
* We skip writing FDT as nothing expects it; OF client interface is
|
||||||
|
* going to be used for reading the device tree.
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
void spapr_vof_quiesce(MachineState *ms)
|
||||||
|
{
|
||||||
|
SpaprMachineState *spapr = SPAPR_MACHINE(ms);
|
||||||
|
|
||||||
|
spapr->fdt_size = fdt_totalsize(spapr->fdt_blob);
|
||||||
|
spapr->fdt_initial_size = spapr->fdt_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool spapr_vof_setprop(MachineState *ms, const char *path, const char *propname,
|
||||||
|
void *val, int vallen)
|
||||||
|
{
|
||||||
|
SpaprMachineState *spapr = SPAPR_MACHINE(ms);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We only allow changing properties which we know how to update in QEMU
|
||||||
|
* OR
|
||||||
|
* the ones which we know that they need to survive during "quiesce".
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (strcmp(path, "/rtas") == 0) {
|
||||||
|
if (strcmp(propname, "linux,rtas-base") == 0 ||
|
||||||
|
strcmp(propname, "linux,rtas-entry") == 0) {
|
||||||
|
/* These need to survive quiesce so let them store in the FDT */
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strcmp(path, "/chosen") == 0) {
|
||||||
|
if (strcmp(propname, "bootargs") == 0) {
|
||||||
|
Vof *vof = spapr->vof;
|
||||||
|
|
||||||
|
g_free(vof->bootargs);
|
||||||
|
vof->bootargs = g_strndup(val, vallen);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (strcmp(propname, "linux,initrd-start") == 0) {
|
||||||
|
if (vallen == sizeof(uint32_t)) {
|
||||||
|
spapr->initrd_base = ldl_be_p(val);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (vallen == sizeof(uint64_t)) {
|
||||||
|
spapr->initrd_base = ldq_be_p(val);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (strcmp(propname, "linux,initrd-end") == 0) {
|
||||||
|
if (vallen == sizeof(uint32_t)) {
|
||||||
|
spapr->initrd_size = ldl_be_p(val) - spapr->initrd_base;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (vallen == sizeof(uint64_t)) {
|
||||||
|
spapr->initrd_size = ldq_be_p(val) - spapr->initrd_base;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
|
@ -71,6 +71,30 @@ spapr_rtas_ibm_configure_connector_invalid(uint32_t index) "DRC index: 0x%"PRIx3
|
||||||
spapr_vio_h_reg_crq(uint64_t reg, uint64_t queue_addr, uint64_t queue_len) "CRQ for dev 0x%" PRIx64 " registered at 0x%" PRIx64 "/0x%" PRIx64
|
spapr_vio_h_reg_crq(uint64_t reg, uint64_t queue_addr, uint64_t queue_len) "CRQ for dev 0x%" PRIx64 " registered at 0x%" PRIx64 "/0x%" PRIx64
|
||||||
spapr_vio_free_crq(uint32_t reg) "CRQ for dev 0x%" PRIx32 " freed"
|
spapr_vio_free_crq(uint32_t reg) "CRQ for dev 0x%" PRIx32 " freed"
|
||||||
|
|
||||||
|
# vof.c
|
||||||
|
vof_error_str_truncated(const char *s, int len) "%s truncated to %d"
|
||||||
|
vof_error_param(const char *method, int nargscheck, int nretcheck, int nargs, int nret) "%s takes/returns %d/%d, not %d/%d"
|
||||||
|
vof_error_unknown_service(const char *service, int nargs, int nret) "\"%s\" args=%d rets=%d"
|
||||||
|
vof_error_unknown_method(const char *method) "\"%s\""
|
||||||
|
vof_error_unknown_ihandle_close(uint32_t ih) "ih=0x%x"
|
||||||
|
vof_error_unknown_path(const char *path) "\"%s\""
|
||||||
|
vof_error_write(uint32_t ih) "ih=0x%x"
|
||||||
|
vof_finddevice(const char *path, uint32_t ph) "\"%s\" => ph=0x%x"
|
||||||
|
vof_claim(uint32_t virt, uint32_t size, uint32_t align, uint32_t ret) "virt=0x%x size=0x%x align=0x%x => 0x%x"
|
||||||
|
vof_release(uint32_t virt, uint32_t size, uint32_t ret) "virt=0x%x size=0x%x => 0x%x"
|
||||||
|
vof_method(uint32_t ihandle, const char *method, uint32_t param, uint32_t ret, uint32_t ret2) "ih=0x%x \"%s\"(0x%x) => 0x%x 0x%x"
|
||||||
|
vof_getprop(uint32_t ph, const char *prop, uint32_t ret, const char *val) "ph=0x%x \"%s\" => len=%d [%s]"
|
||||||
|
vof_getproplen(uint32_t ph, const char *prop, uint32_t ret) "ph=0x%x \"%s\" => len=%d"
|
||||||
|
vof_setprop(uint32_t ph, const char *prop, const char *val, uint32_t vallen, uint32_t ret) "ph=0x%x \"%s\" [%s] len=%d => ret=%d"
|
||||||
|
vof_open(const char *path, uint32_t ph, uint32_t ih) "%s ph=0x%x => ih=0x%x"
|
||||||
|
vof_interpret(const char *cmd, uint32_t param1, uint32_t param2, uint32_t ret, uint32_t ret2) "[%s] 0x%x 0x%x => 0x%x 0x%x"
|
||||||
|
vof_package_to_path(uint32_t ph, const char *tmp, uint32_t ret) "ph=0x%x => %s len=%d"
|
||||||
|
vof_instance_to_path(uint32_t ih, uint32_t ph, const char *tmp, uint32_t ret) "ih=0x%x ph=0x%x => %s len=%d"
|
||||||
|
vof_instance_to_package(uint32_t ih, uint32_t ph) "ih=0x%x => ph=0x%x"
|
||||||
|
vof_write(uint32_t ih, unsigned cb, const char *msg) "ih=0x%x [%u] \"%s\""
|
||||||
|
vof_avail(uint64_t start, uint64_t end, uint64_t size) "0x%"PRIx64"..0x%"PRIx64" size=0x%"PRIx64
|
||||||
|
vof_claimed(uint64_t start, uint64_t end, uint64_t size) "0x%"PRIx64"..0x%"PRIx64" size=0x%"PRIx64
|
||||||
|
|
||||||
# ppc.c
|
# ppc.c
|
||||||
ppc_tb_adjust(uint64_t offs1, uint64_t offs2, int64_t diff, int64_t seconds) "adjusted from 0x%"PRIx64" to 0x%"PRIx64", diff %"PRId64" (%"PRId64"s)"
|
ppc_tb_adjust(uint64_t offs1, uint64_t offs2, int64_t diff, int64_t seconds) "adjusted from 0x%"PRIx64" to 0x%"PRIx64", diff %"PRId64" (%"PRId64"s)"
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -12,6 +12,7 @@
|
||||||
#include "hw/ppc/spapr_xive.h" /* For SpaprXive */
|
#include "hw/ppc/spapr_xive.h" /* For SpaprXive */
|
||||||
#include "hw/ppc/xics.h" /* For ICSState */
|
#include "hw/ppc/xics.h" /* For ICSState */
|
||||||
#include "hw/ppc/spapr_tpm_proxy.h"
|
#include "hw/ppc/spapr_tpm_proxy.h"
|
||||||
|
#include "hw/ppc/vof.h"
|
||||||
|
|
||||||
struct SpaprVioBus;
|
struct SpaprVioBus;
|
||||||
struct SpaprPhbState;
|
struct SpaprPhbState;
|
||||||
|
@ -180,6 +181,7 @@ struct SpaprMachineState {
|
||||||
uint64_t kernel_addr;
|
uint64_t kernel_addr;
|
||||||
uint32_t initrd_base;
|
uint32_t initrd_base;
|
||||||
long initrd_size;
|
long initrd_size;
|
||||||
|
Vof *vof;
|
||||||
uint64_t rtc_offset; /* Now used only during incoming migration */
|
uint64_t rtc_offset; /* Now used only during incoming migration */
|
||||||
struct PPCTimebase tb;
|
struct PPCTimebase tb;
|
||||||
bool has_graphics;
|
bool has_graphics;
|
||||||
|
@ -558,7 +560,9 @@ struct SpaprMachineState {
|
||||||
/* Client Architecture support */
|
/* Client Architecture support */
|
||||||
#define KVMPPC_H_CAS (KVMPPC_HCALL_BASE + 0x2)
|
#define KVMPPC_H_CAS (KVMPPC_HCALL_BASE + 0x2)
|
||||||
#define KVMPPC_H_UPDATE_DT (KVMPPC_HCALL_BASE + 0x3)
|
#define KVMPPC_H_UPDATE_DT (KVMPPC_HCALL_BASE + 0x3)
|
||||||
#define KVMPPC_HCALL_MAX KVMPPC_H_UPDATE_DT
|
/* 0x4 was used for KVMPPC_H_UPDATE_PHANDLE in SLOF */
|
||||||
|
#define KVMPPC_H_VOF_CLIENT (KVMPPC_HCALL_BASE + 0x5)
|
||||||
|
#define KVMPPC_HCALL_MAX KVMPPC_H_VOF_CLIENT
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The hcall range 0xEF00 to 0xEF80 is reserved for use in facilitating
|
* The hcall range 0xEF00 to 0xEF80 is reserved for use in facilitating
|
||||||
|
@ -956,4 +960,17 @@ bool spapr_check_pagesize(SpaprMachineState *spapr, hwaddr pagesize,
|
||||||
void spapr_set_all_lpcrs(target_ulong value, target_ulong mask);
|
void spapr_set_all_lpcrs(target_ulong value, target_ulong mask);
|
||||||
hwaddr spapr_get_rtas_addr(void);
|
hwaddr spapr_get_rtas_addr(void);
|
||||||
bool spapr_memory_hot_unplug_supported(SpaprMachineState *spapr);
|
bool spapr_memory_hot_unplug_supported(SpaprMachineState *spapr);
|
||||||
|
|
||||||
|
void spapr_vof_reset(SpaprMachineState *spapr, void *fdt,
|
||||||
|
target_ulong *stack_ptr, Error **errp);
|
||||||
|
void spapr_vof_quiesce(MachineState *ms);
|
||||||
|
bool spapr_vof_setprop(MachineState *ms, const char *path, const char *propname,
|
||||||
|
void *val, int vallen);
|
||||||
|
target_ulong spapr_h_vof_client(PowerPCCPU *cpu, SpaprMachineState *spapr,
|
||||||
|
target_ulong opcode, target_ulong *args);
|
||||||
|
target_ulong spapr_vof_client_architecture_support(MachineState *ms,
|
||||||
|
CPUState *cs,
|
||||||
|
target_ulong ovec_addr);
|
||||||
|
void spapr_vof_client_dt_finalize(SpaprMachineState *spapr, void *fdt);
|
||||||
|
|
||||||
#endif /* HW_SPAPR_H */
|
#endif /* HW_SPAPR_H */
|
||||||
|
|
|
@ -0,0 +1,58 @@
|
||||||
|
/*
|
||||||
|
* Virtual Open Firmware
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
*/
|
||||||
|
#ifndef HW_VOF_H
|
||||||
|
#define HW_VOF_H
|
||||||
|
|
||||||
|
typedef struct Vof {
|
||||||
|
uint64_t top_addr; /* copied from rma_size */
|
||||||
|
GArray *claimed; /* array of SpaprOfClaimed */
|
||||||
|
uint64_t claimed_base;
|
||||||
|
GHashTable *of_instances; /* ihandle -> SpaprOfInstance */
|
||||||
|
uint32_t of_instance_last;
|
||||||
|
char *bootargs;
|
||||||
|
long fw_size;
|
||||||
|
} Vof;
|
||||||
|
|
||||||
|
int vof_client_call(MachineState *ms, Vof *vof, void *fdt,
|
||||||
|
target_ulong args_real);
|
||||||
|
uint64_t vof_claim(Vof *vof, uint64_t virt, uint64_t size, uint64_t align);
|
||||||
|
void vof_init(Vof *vof, uint64_t top_addr, Error **errp);
|
||||||
|
void vof_cleanup(Vof *vof);
|
||||||
|
void vof_build_dt(void *fdt, Vof *vof);
|
||||||
|
uint32_t vof_client_open_store(void *fdt, Vof *vof, const char *nodename,
|
||||||
|
const char *prop, const char *path);
|
||||||
|
|
||||||
|
#define TYPE_VOF_MACHINE_IF "vof-machine-if"
|
||||||
|
|
||||||
|
typedef struct VofMachineIfClass VofMachineIfClass;
|
||||||
|
DECLARE_CLASS_CHECKERS(VofMachineIfClass, VOF_MACHINE, TYPE_VOF_MACHINE_IF)
|
||||||
|
|
||||||
|
struct VofMachineIfClass {
|
||||||
|
InterfaceClass parent;
|
||||||
|
target_ulong (*client_architecture_support)(MachineState *ms, CPUState *cs,
|
||||||
|
target_ulong vec);
|
||||||
|
void (*quiesce)(MachineState *ms);
|
||||||
|
bool (*setprop)(MachineState *ms, const char *path, const char *propname,
|
||||||
|
void *val, int vallen);
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Initial stack size is from
|
||||||
|
* https://www.devicetree.org/open-firmware/bindings/ppc/release/ppc-2_1.html#REF27292
|
||||||
|
*
|
||||||
|
* "Client programs shall be invoked with a valid stack pointer (r1) with
|
||||||
|
* at least 32K bytes of memory available for stack growth".
|
||||||
|
*/
|
||||||
|
#define VOF_STACK_SIZE 0x8000
|
||||||
|
|
||||||
|
#define VOF_MEM_READ(pa, buf, size) \
|
||||||
|
address_space_read(&address_space_memory, \
|
||||||
|
(pa), MEMTXATTRS_UNSPECIFIED, (buf), (size))
|
||||||
|
#define VOF_MEM_WRITE(pa, buf, size) \
|
||||||
|
address_space_write(&address_space_memory, \
|
||||||
|
(pa), MEMTXATTRS_UNSPECIFIED, (buf), (size))
|
||||||
|
|
||||||
|
#endif /* HW_VOF_H */
|
|
@ -16,6 +16,10 @@
|
||||||
https://github.com/aik/SLOF, and the image currently in qemu is
|
https://github.com/aik/SLOF, and the image currently in qemu is
|
||||||
built from git tag qemu-slof-20210217.
|
built from git tag qemu-slof-20210217.
|
||||||
|
|
||||||
|
- VOF (Virtual Open Firmware) is a minimalistic firmware to work with
|
||||||
|
-machine pseries,x-vof=on. When enabled, the firmware acts as a slim shim and
|
||||||
|
QEMU implements parts of the IEEE 1275 Open Firmware interface.
|
||||||
|
|
||||||
- sgabios (the Serial Graphics Adapter option ROM) provides a means for
|
- sgabios (the Serial Graphics Adapter option ROM) provides a means for
|
||||||
legacy x86 software to communicate with an attached serial console as
|
legacy x86 software to communicate with an attached serial console as
|
||||||
if a video card were attached. The master sources reside in a subversion
|
if a video card were attached. The master sources reside in a subversion
|
||||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,23 @@
|
||||||
|
all: build-all
|
||||||
|
|
||||||
|
build-all: vof.bin
|
||||||
|
|
||||||
|
CROSS ?=
|
||||||
|
CC = $(CROSS)gcc
|
||||||
|
LD = $(CROSS)ld
|
||||||
|
OBJCOPY = $(CROSS)objcopy
|
||||||
|
|
||||||
|
%.o: %.S
|
||||||
|
$(CC) -m32 -mbig-endian -mcpu=power4 -c -o $@ $<
|
||||||
|
|
||||||
|
%.o: %.c
|
||||||
|
$(CC) -m32 -mbig-endian -mcpu=power4 -c -fno-stack-protector -o $@ $<
|
||||||
|
|
||||||
|
vof.elf: entry.o main.o ci.o bootmem.o libc.o
|
||||||
|
$(LD) -nostdlib -e_start -Tvof.lds -EB -o $@ $^
|
||||||
|
|
||||||
|
%.bin: %.elf
|
||||||
|
$(OBJCOPY) -O binary -j .text -j .data -j .toc -j .got2 $^ $@
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f *.o vof.bin vof.elf *~
|
|
@ -0,0 +1,14 @@
|
||||||
|
#include "vof.h"
|
||||||
|
|
||||||
|
void boot_from_memory(uint64_t initrd, uint64_t initrdsize)
|
||||||
|
{
|
||||||
|
uint64_t kern[2];
|
||||||
|
phandle chosen = ci_finddevice("/chosen");
|
||||||
|
|
||||||
|
if (ci_getprop(chosen, "qemu,boot-kernel", kern, sizeof(kern)) !=
|
||||||
|
sizeof(kern)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
do_boot(kern[0], initrd, initrdsize);
|
||||||
|
}
|
|
@ -0,0 +1,91 @@
|
||||||
|
#include "vof.h"
|
||||||
|
|
||||||
|
struct prom_args {
|
||||||
|
uint32_t service;
|
||||||
|
uint32_t nargs;
|
||||||
|
uint32_t nret;
|
||||||
|
uint32_t args[10];
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef unsigned long prom_arg_t;
|
||||||
|
|
||||||
|
#define ADDR(x) (uint32_t)(x)
|
||||||
|
|
||||||
|
static int prom_handle(struct prom_args *pargs)
|
||||||
|
{
|
||||||
|
void *rtasbase;
|
||||||
|
uint32_t rtassize = 0;
|
||||||
|
phandle rtas;
|
||||||
|
|
||||||
|
if (strcmp("call-method", (void *)(unsigned long)pargs->service)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strcmp("instantiate-rtas", (void *)(unsigned long)pargs->args[0])) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
rtas = ci_finddevice("/rtas");
|
||||||
|
/* rtas-size is set by QEMU depending of FWNMI support */
|
||||||
|
ci_getprop(rtas, "rtas-size", &rtassize, sizeof(rtassize));
|
||||||
|
if (rtassize < hv_rtas_size) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
rtasbase = (void *)(unsigned long) pargs->args[2];
|
||||||
|
|
||||||
|
memcpy(rtasbase, hv_rtas, hv_rtas_size);
|
||||||
|
pargs->args[pargs->nargs] = 0;
|
||||||
|
pargs->args[pargs->nargs + 1] = pargs->args[2];
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void prom_entry(uint32_t args)
|
||||||
|
{
|
||||||
|
if (prom_handle((void *)(unsigned long) args)) {
|
||||||
|
ci_entry(args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int call_ci(const char *service, int nargs, int nret, ...)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
struct prom_args args;
|
||||||
|
va_list list;
|
||||||
|
|
||||||
|
args.service = ADDR(service);
|
||||||
|
args.nargs = nargs;
|
||||||
|
args.nret = nret;
|
||||||
|
|
||||||
|
va_start(list, nret);
|
||||||
|
for (i = 0; i < nargs; i++) {
|
||||||
|
args.args[i] = va_arg(list, prom_arg_t);
|
||||||
|
}
|
||||||
|
va_end(list);
|
||||||
|
|
||||||
|
for (i = 0; i < nret; i++) {
|
||||||
|
args.args[nargs + i] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ci_entry((uint32_t)(&args)) < 0) {
|
||||||
|
return PROM_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (nret > 0) ? args.args[nargs] : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ci_panic(const char *str)
|
||||||
|
{
|
||||||
|
call_ci("exit", 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
phandle ci_finddevice(const char *path)
|
||||||
|
{
|
||||||
|
return call_ci("finddevice", 1, 1, path);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t ci_getprop(phandle ph, const char *propname, void *prop, int len)
|
||||||
|
{
|
||||||
|
return call_ci("getprop", 4, 1, ph, propname, prop, len);
|
||||||
|
}
|
|
@ -0,0 +1,49 @@
|
||||||
|
#define LOAD32(rn, name) \
|
||||||
|
lis rn,name##@h; \
|
||||||
|
ori rn,rn,name##@l
|
||||||
|
|
||||||
|
#define ENTRY(func_name) \
|
||||||
|
.text; \
|
||||||
|
.align 2; \
|
||||||
|
.globl .func_name; \
|
||||||
|
.func_name: \
|
||||||
|
.globl func_name; \
|
||||||
|
func_name:
|
||||||
|
|
||||||
|
#define KVMPPC_HCALL_BASE 0xf000
|
||||||
|
#define KVMPPC_H_RTAS (KVMPPC_HCALL_BASE + 0x0)
|
||||||
|
#define KVMPPC_H_VOF_CLIENT (KVMPPC_HCALL_BASE + 0x5)
|
||||||
|
|
||||||
|
. = 0x100 /* Do exactly as SLOF does */
|
||||||
|
|
||||||
|
ENTRY(_start)
|
||||||
|
LOAD32(2, __toc_start)
|
||||||
|
b entry_c
|
||||||
|
|
||||||
|
ENTRY(_prom_entry)
|
||||||
|
LOAD32(2, __toc_start)
|
||||||
|
stwu %r1,-112(%r1)
|
||||||
|
stw %r31,104(%r1)
|
||||||
|
mflr %r31
|
||||||
|
bl prom_entry
|
||||||
|
nop
|
||||||
|
mtlr %r31
|
||||||
|
lwz %r31,104(%r1)
|
||||||
|
addi %r1,%r1,112
|
||||||
|
blr
|
||||||
|
|
||||||
|
ENTRY(ci_entry)
|
||||||
|
mr 4,3
|
||||||
|
LOAD32(3,KVMPPC_H_VOF_CLIENT)
|
||||||
|
sc 1
|
||||||
|
blr
|
||||||
|
|
||||||
|
/* This is the actual RTAS blob copied to the OS at instantiate-rtas */
|
||||||
|
ENTRY(hv_rtas)
|
||||||
|
mr %r4,%r3
|
||||||
|
LOAD32(3,KVMPPC_H_RTAS)
|
||||||
|
sc 1
|
||||||
|
blr
|
||||||
|
.globl hv_rtas_size
|
||||||
|
hv_rtas_size:
|
||||||
|
.long . - hv_rtas;
|
|
@ -0,0 +1,92 @@
|
||||||
|
#include "vof.h"
|
||||||
|
|
||||||
|
int strlen(const char *s)
|
||||||
|
{
|
||||||
|
int len = 0;
|
||||||
|
|
||||||
|
while (*s != 0) {
|
||||||
|
len += 1;
|
||||||
|
s += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
int strcmp(const char *s1, const char *s2)
|
||||||
|
{
|
||||||
|
while (*s1 != 0 && *s2 != 0) {
|
||||||
|
if (*s1 != *s2) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
s1 += 1;
|
||||||
|
s2 += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return *s1 - *s2;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *memcpy(void *dest, const void *src, size_t n)
|
||||||
|
{
|
||||||
|
char *cdest;
|
||||||
|
const char *csrc = src;
|
||||||
|
|
||||||
|
cdest = dest;
|
||||||
|
while (n-- > 0) {
|
||||||
|
*cdest++ = *csrc++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return dest;
|
||||||
|
}
|
||||||
|
|
||||||
|
int memcmp(const void *ptr1, const void *ptr2, size_t n)
|
||||||
|
{
|
||||||
|
const unsigned char *p1 = ptr1;
|
||||||
|
const unsigned char *p2 = ptr2;
|
||||||
|
|
||||||
|
while (n-- > 0) {
|
||||||
|
if (*p1 != *p2) {
|
||||||
|
return *p1 - *p2;
|
||||||
|
}
|
||||||
|
p1 += 1;
|
||||||
|
p2 += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *memmove(void *dest, const void *src, size_t n)
|
||||||
|
{
|
||||||
|
char *cdest;
|
||||||
|
const char *csrc;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
/* Do the buffers overlap in a bad way? */
|
||||||
|
if (src < dest && src + n >= dest) {
|
||||||
|
/* Copy from end to start */
|
||||||
|
cdest = dest + n - 1;
|
||||||
|
csrc = src + n - 1;
|
||||||
|
for (i = 0; i < n; i++) {
|
||||||
|
*cdest-- = *csrc--;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/* Normal copy is possible */
|
||||||
|
cdest = dest;
|
||||||
|
csrc = src;
|
||||||
|
for (i = 0; i < n; i++) {
|
||||||
|
*cdest++ = *csrc++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return dest;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *memset(void *dest, int c, size_t size)
|
||||||
|
{
|
||||||
|
unsigned char *d = (unsigned char *)dest;
|
||||||
|
|
||||||
|
while (size-- > 0) {
|
||||||
|
*d++ = (unsigned char)c;
|
||||||
|
}
|
||||||
|
|
||||||
|
return dest;
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
#include "vof.h"
|
||||||
|
|
||||||
|
void do_boot(unsigned long addr, unsigned long _r3, unsigned long _r4)
|
||||||
|
{
|
||||||
|
register unsigned long r3 __asm__("r3") = _r3;
|
||||||
|
register unsigned long r4 __asm__("r4") = _r4;
|
||||||
|
register unsigned long r5 __asm__("r5") = (unsigned long) _prom_entry;
|
||||||
|
|
||||||
|
((client *)(uint32_t)addr)();
|
||||||
|
}
|
||||||
|
|
||||||
|
void entry_c(void)
|
||||||
|
{
|
||||||
|
register unsigned long r3 __asm__("r3");
|
||||||
|
register unsigned long r4 __asm__("r4");
|
||||||
|
register unsigned long r5 __asm__("r5");
|
||||||
|
uint64_t initrd = r3, initrdsize = r4;
|
||||||
|
|
||||||
|
boot_from_memory(initrd, initrdsize);
|
||||||
|
ci_panic("*** No boot target ***\n");
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
/*
|
||||||
|
* Virtual Open Firmware
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
*/
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
typedef unsigned char uint8_t;
|
||||||
|
typedef unsigned short uint16_t;
|
||||||
|
typedef unsigned long uint32_t;
|
||||||
|
typedef unsigned long long uint64_t;
|
||||||
|
#define NULL (0)
|
||||||
|
#define PROM_ERROR (-1u)
|
||||||
|
typedef unsigned long ihandle;
|
||||||
|
typedef unsigned long phandle;
|
||||||
|
typedef int size_t;
|
||||||
|
typedef void client(void);
|
||||||
|
|
||||||
|
/* globals */
|
||||||
|
extern void _prom_entry(void); /* OF CI entry point (i.e. this firmware) */
|
||||||
|
|
||||||
|
void do_boot(unsigned long addr, unsigned long r3, unsigned long r4);
|
||||||
|
|
||||||
|
/* libc */
|
||||||
|
int strlen(const char *s);
|
||||||
|
int strcmp(const char *s1, const char *s2);
|
||||||
|
void *memcpy(void *dest, const void *src, size_t n);
|
||||||
|
int memcmp(const void *ptr1, const void *ptr2, size_t n);
|
||||||
|
void *memmove(void *dest, const void *src, size_t n);
|
||||||
|
void *memset(void *dest, int c, size_t size);
|
||||||
|
|
||||||
|
/* CI wrappers */
|
||||||
|
void ci_panic(const char *str);
|
||||||
|
phandle ci_finddevice(const char *path);
|
||||||
|
uint32_t ci_getprop(phandle ph, const char *propname, void *prop, int len);
|
||||||
|
|
||||||
|
/* booting from -kernel */
|
||||||
|
void boot_from_memory(uint64_t initrd, uint64_t initrdsize);
|
||||||
|
|
||||||
|
/* Entry points for CI and RTAS */
|
||||||
|
extern uint32_t ci_entry(uint32_t params);
|
||||||
|
extern unsigned long hv_rtas(unsigned long params);
|
||||||
|
extern unsigned int hv_rtas_size;
|
|
@ -0,0 +1,48 @@
|
||||||
|
OUTPUT_FORMAT("elf32-powerpc")
|
||||||
|
OUTPUT_ARCH(powerpc:common)
|
||||||
|
|
||||||
|
/* set the entry point */
|
||||||
|
ENTRY ( __start )
|
||||||
|
|
||||||
|
SECTIONS {
|
||||||
|
__executable_start = .;
|
||||||
|
|
||||||
|
.text : {
|
||||||
|
*(.text)
|
||||||
|
}
|
||||||
|
|
||||||
|
__etext = .;
|
||||||
|
|
||||||
|
. = ALIGN(8);
|
||||||
|
|
||||||
|
.data : {
|
||||||
|
*(.data)
|
||||||
|
*(.rodata .rodata.*)
|
||||||
|
*(.got1)
|
||||||
|
*(.sdata)
|
||||||
|
*(.opd)
|
||||||
|
}
|
||||||
|
|
||||||
|
/* FIXME bss at end ??? */
|
||||||
|
|
||||||
|
. = ALIGN(8);
|
||||||
|
__bss_start = .;
|
||||||
|
.bss : {
|
||||||
|
*(.sbss) *(.scommon)
|
||||||
|
*(.dynbss)
|
||||||
|
*(.bss)
|
||||||
|
}
|
||||||
|
|
||||||
|
. = ALIGN(8);
|
||||||
|
__bss_end = .;
|
||||||
|
__bss_size = (__bss_end - __bss_start);
|
||||||
|
|
||||||
|
. = ALIGN(256);
|
||||||
|
__toc_start = DEFINED (.TOC.) ? .TOC. : ADDR (.got) + 0x8000;
|
||||||
|
.got :
|
||||||
|
{
|
||||||
|
*(.toc .got)
|
||||||
|
}
|
||||||
|
. = ALIGN(8);
|
||||||
|
__toc_end = .;
|
||||||
|
}
|
|
@ -5,7 +5,7 @@
|
||||||
#include "libqos/libqos-spapr.h"
|
#include "libqos/libqos-spapr.h"
|
||||||
#include "libqos/rtas.h"
|
#include "libqos/rtas.h"
|
||||||
|
|
||||||
static void test_rtas_get_time_of_day(void)
|
static void run_test_rtas_get_time_of_day(const char *machine)
|
||||||
{
|
{
|
||||||
QOSState *qs;
|
QOSState *qs;
|
||||||
struct tm tm;
|
struct tm tm;
|
||||||
|
@ -13,7 +13,7 @@ static void test_rtas_get_time_of_day(void)
|
||||||
uint64_t ret;
|
uint64_t ret;
|
||||||
time_t t1, t2;
|
time_t t1, t2;
|
||||||
|
|
||||||
qs = qtest_spapr_boot("-machine pseries");
|
qs = qtest_spapr_boot(machine);
|
||||||
|
|
||||||
t1 = time(NULL);
|
t1 = time(NULL);
|
||||||
ret = qrtas_get_time_of_day(qs->qts, &qs->alloc, &tm, &ns);
|
ret = qrtas_get_time_of_day(qs->qts, &qs->alloc, &tm, &ns);
|
||||||
|
@ -24,6 +24,16 @@ static void test_rtas_get_time_of_day(void)
|
||||||
qtest_shutdown(qs);
|
qtest_shutdown(qs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_rtas_get_time_of_day(void)
|
||||||
|
{
|
||||||
|
run_test_rtas_get_time_of_day("-machine pseries");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_rtas_get_time_of_day_vof(void)
|
||||||
|
{
|
||||||
|
run_test_rtas_get_time_of_day("-machine pseries,x-vof=on");
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
const char *arch = qtest_get_arch();
|
const char *arch = qtest_get_arch();
|
||||||
|
@ -35,6 +45,7 @@ int main(int argc, char *argv[])
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
qtest_add_func("rtas/get-time-of-day", test_rtas_get_time_of_day);
|
qtest_add_func("rtas/get-time-of-day", test_rtas_get_time_of_day);
|
||||||
|
qtest_add_func("rtas/get-time-of-day-vof", test_rtas_get_time_of_day_vof);
|
||||||
|
|
||||||
return g_test_run();
|
return g_test_run();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue