spapr: Kill SLOF
PATCH v3 1/1 spapr: Kill SLOF
The Petitboot bootloader is way more advanced than SLOF is ever going to be as Petitboot comes with the full-featured Linux kernel with all the drivers, and initramdisk with quite user friendly interface. The problem with ditching SLOF is that an unmodified pseries kernel can either start via:
1. kexec, this requires presence of RTAS and skips ibm,client-architecture-support entirely;
2. normal boot, this heavily relies on the OF1275 client interface to fetch the device tree and do early setup (claim memory).
This adds a new bios-less mode to the pseries machine: "bios=on|off". When enabled, QEMU does not load SLOF and jumps to the kernel from "-kernel".
The client interface is implemented exactly as RTAS - a 20 bytes blob, right next after the RTAS blob. The entry point is passed to the kernel via GPR5.
This implements a handful of client interface methods just to get going. In particular, this implements the device tree fetching, ibm,client-architecture-support and instantiate-rtas.
This implements changing FDT properties for RTAS (for vmlinux and zImage) and initramdisk location (for zImage). To make this work, this skips fdt_pack() when bios=off as not packing the blob leaves some room for appending.
This assigns "phandles" to device tree nodes as there is no more SLOF and OF nodes addresses of which served as phandle values. This keeps predefined nodes (such as XICS/NVLINK/...) unchanged. phandles are regenerated at every FDT rebuild.
This defines phandles for VIO devices to have phandle assigned to the default stdout device at the point when we write "/chosen/stdout" which an ihandle which the OS uses to write to the console.
When bios=off, this adds "/chosen" every time QEMU builds a tree.
This implements "claim" which the client (Linux) uses for memory allocation; this is also used by QEMU for claiming kernel/initrd images, client interface entry point, RTAS and the initial stack.
While at this, add a "kernel-addr" machine parameter to allow moving the kernel in memory. This is useful for debugging if the kernel is loaded at @0, although not necessary.
This adds very basic instances support which are managed by a hashmap ihandle->phandle.
Note that a 64bit PCI fix is required for Linux:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=df5be5be8735e
The test command line:
qemu-system-ppc64 \
-nodefaults \
-chardev stdio,id=STDIO0,signal=off,mux=on \
-device spapr-vty,id=svty0,reg=0x71000110,chardev=STDIO0 \
-mon id=MON0,chardev=STDIO0,mode=readline \
-nographic \
-vga none \
-kernel pbuild/kernel-le-guest/arch/powerpc/boot/zImage.pseries \
-machine pseries,bios=off,cap-cfpc=broken,cap-sbbc=broken,cap-ibs=broken \
-m 4G \
-enable-kvm \
-initrd pb/rootfs.cpio.xz \
-device nec-usb-xhci,id=nec-usb-xhci0 \
-netdev tap,id=TAP0,helper=/home/aik/qemu-bridge-helper --br=br0 \
-device virtio-net-pci,id=vnet0,netdev=TAP0 img/f30le.qcow2 \
-snapshot \
-smp 8,threads=8 \
-trace events=qemu_trace_events \
-d guest_errors \
-chardev socket,id=SOCKET0,server,nowait,path=qemu.mon.ssh54088 \
-mon chardev=SOCKET0,mode=control
---
Changes:
v3:
* fixed phandles allocation
* s/__be32/uint32_t/ as we do not normally have __be32 type in qemu
* fixed size of /chosen/stdout
* bunch of renames
* do not create rtas properties at all, let the client deal with it; instead setprop allows changing these in the FDT
* no more packing FDT when bios=off - nobody needs it and getprop does not work otherwise
* allow updating initramdisk device tree properties (for zImage)
* added instances
* fixed stdout on OF's "write"
* removed special handling for stdout in OF client, spapr-vty handles it instead
v2:
* fixed claim()
* added "setprop"
* cleaner client interface and RTAS blobs management
* boots to petitboot and further to the target system
* more trace points
--- hw/ppc/Makefile.objs | 1 + include/hw/ppc/spapr.h | 28 +- include/hw/ppc/spapr_vio.h | 5 + hw/char/spapr_vty.c | 14 + hw/ppc/spapr.c | 250 ++++++++++++++++-- hw/ppc/spapr_hcall.c | 74 ++++-- hw/ppc/spapr_of_client.c | 527 +++++++++++++++++++++++++++++++++++++ hw/ppc/spapr_vio.c | 27 +- hw/ppc/trace-events | 10 + 9 files changed, 882 insertions(+), 54 deletions(-) create mode 100644 hw/ppc/spapr_of_client.c
hw/ppc/Makefile.objs +1 -0
@@ -6,6 +6,7 @@ obj-$(CONFIG_PSERIES) += spapr_hcall.o spapr_iommu.o spapr_rtas.o obj-$(CONFIG_PSERIES) += spapr_pci.o spapr_rtc.o spapr_drc.o obj-$(CONFIG_PSERIES) += spapr_cpu_core.o spapr_ovec.o spapr_irq.o obj-$(CONFIG_PSERIES) += spapr_tpm_proxy.o +obj-$(CONFIG_PSERIES) += spapr_of_client.o obj-$(CONFIG_SPAPR_RNG) += spapr_rng.o # IBM PowerNV obj-$(CONFIG_POWERNV) += pnv.o pnv_xscom.o pnv_core.o pnv_lpc.o pnv_psi.o pnv_occ.o pnv_bmc.o
include/hw/ppc/spapr.h +27 -1
@@ -105,6 +105,11 @@ struct SpaprCapabilities {uint8_t caps[SPAPR_CAP_NUM ]; }; +typedef struct { +uint64_t start; +uint64_t size; +}SpaprOfClaimed ; +/** * SpaprMachineClass: */
@@ -160,6 +165,13 @@ struct SpaprMachineState {void *fdt_blob;long kernel_size;bool kernel_le; +uint64_t kernel_addr; +bool bios_enabled; +uint32_t rtas_base; +GArray *claimed;/* array of SpaprOfClaimed */ +uint64_t claimed_base; +GHashTable *of_instances;/* ihandle -> phandle map */ +uint32_t of_instance_last;uint32_t initrd_base;long initrd_size;uint64_t rtc_offset;/* Now used only during incoming migration */
@@ -510,7 +522,8 @@ struct SpaprMachineState {/* Client Architecture support */ #define KVMPPC_H_CAS (KVMPPC_HCALL_BASE + 0x2)#define KVMPPC_H_UPDATE_DT (KVMPPC_HCALL_BASE + 0x3) -#define KVMPPC_HCALL_MAX KVMPPC_H_UPDATE_DT +#define KVMPPC_H_CLIENT (KVMPPC_HCALL_BASE + 0x5) +#define KVMPPC_HCALL_MAX KVMPPC_H_CLIENT/* * The hcall range 0xEF00 to 0xEF80 is reserved for use in facilitating
@@ -538,6 +551,11 @@ void spapr_register_hypercall(target_ulong opcode, spapr_hcall_fn fn);target_ulong spapr_hypercall (PowerPCCPU *cpu,target_ulong opcode,target_ulong *args); +target_ulong do_client_architecture_support (PowerPCCPU *cpu, +SpaprMachineState *spapr, +target_ulong addr, +target_ulong fdt_bufsize); +/* Virtual Processor Area structure constants */ #define VPA_MIN_SIZE 640#define VPA_SIZE_OFFSET 0x4
@@ -769,6 +787,11 @@ struct SpaprEventLogEntry {void *spapr_build_fdt (SpaprMachineState *spapr,bool reset,size_t space);void spapr_events_init (SpaprMachineState *sm);void spapr_dt_events (SpaprMachineState *sm,void *fdt); +uint64_t spapr_do_of_client_claim (SpaprMachineState *spapr,uint64_t virt, +uint64_t size,uint64_t align); + +uint32_t spapr_of_client_open (SpaprMachineState *spapr,uint32_t phandle); +int spapr_h_client (SpaprMachineState *spapr,target_ulong client_args);void close_htab_fd (SpaprMachineState *spapr);void spapr_setup_hpt_and_vrma (SpaprMachineState *spapr);void spapr_free_hpt (SpaprMachineState *spapr);
@@ -891,4 +914,7 @@ void spapr_check_pagesize(SpaprMachineState *spapr, hwaddr pagesize,#define SPAPR_OV5_XIVE_BOTH 0x80/* Only to advertise on the platform */ void spapr_set_all_lpcrs (target_ulong value,target_ulong mask); + +void spapr_instantiate_rtas (SpaprMachineState *spapr,uint32_t base); +#endif /* HW_SPAPR_H */
include/hw/ppc/spapr_vio.h +5 -0
@@ -64,6 +64,7 @@ struct SpaprVioDevice {DeviceState qdev;uint32_t reg;uint32_t irq; +uint32_t phandle;uint64_t signal_state;SpaprVioCrq crq;AddressSpace as;
@@ -78,10 +79,12 @@ struct SpaprVioDevice {struct SpaprVioBus {BusState bus;uint32_t next_reg; +uint32_t next_phandle; };SpaprVioBus *spapr_vio_bus_init (void );SpaprVioDevice *spapr_vio_find_by_reg (SpaprVioBus *bus,uint32_t reg); +SpaprVioDevice *spapr_vio_find_by_phandle (SpaprVioBus *bus,uint32_t phandle);void spapr_dt_vdevice (SpaprVioBus *bus,void *fdt);gchar *spapr_vio_stdout_path (SpaprVioBus *bus);
@@ -128,6 +131,8 @@ static inline int spapr_vio_dma_set(SpaprVioDevice *dev, uint64_t taddr,int spapr_vio_send_crq (SpaprVioDevice *dev,uint8_t *crq);SpaprVioDevice *vty_lookup (SpaprMachineState *spapr,target_ulong reg); +SpaprVioDevice *vty_lookup_phandle (SpaprMachineState *spapr, +uint32_t phandle);void vty_putchars (SpaprVioDevice *sdev,uint8_t *buf,int len);void spapr_vty_create (SpaprVioBus *bus,Chardev *chardev);void spapr_vlan_create (SpaprVioBus *bus,NICInfo *nd);
hw/char/spapr_vty.c +14 -0
@@ -262,6 +262,20 @@ SpaprVioDevice *vty_lookup(SpaprMachineState *spapr, target_ulong reg)return sdev; } +SpaprVioDevice *vty_lookup_phandle (SpaprMachineState *spapr, +uint32_t phandle) +{ +SpaprVioDevice *sdev; + + sdev =spapr_vio_find_by_phandle (spapr->vio_bus, phandle); +if (!sdev || + !object_dynamic_cast (OBJECT (sdev),TYPE_VIO_SPAPR_VTY_DEVICE )) { +return NULL ; + } + +return sdev; +} +static void spapr_vty_register_types (void ) {spapr_register_hypercall (H_PUT_TERM_CHAR , h_put_term_char);
hw/ppc/spapr.c +223 -27
340 lines not on this page · raw message
hw/ppc/spapr_hcall.c +50 -24
111 lines not on this page · raw message
hw/ppc/spapr_of_client.c new file +527 -0
527 lines not on this page · raw message
hw/ppc/spapr_vio.c +25 -2
@@ -41,6 +41,7 @@#include <libfdt.h> #define SPAPR_VIO_REG_BASE 0x71000000 +#define PHANDLE_SPAPR_VIO_BASE 0x0000F000static char *spapr_vio_get_dev_name (DeviceState *qdev) {
@@ -81,6 +82,21 @@ SpaprVioDevice *spapr_vio_find_by_reg(SpaprVioBus *bus, uint32_t reg)return NULL ; } +SpaprVioDevice *spapr_vio_find_by_phandle (SpaprVioBus *bus,uint32_t phandle) +{ +BusChild *kid; +SpaprVioDevice *dev =NULL ; + + QTAILQ_FOREACH(kid, &bus->bus.children, sibling) { + dev = (SpaprVioDevice *)kid->child; +if (dev->phandle && dev->phandle == phandle) { +return dev; + } + } + +return NULL ; +} +static int vio_make_devnode (SpaprVioDevice *dev,void *fdt) {
@@ -105,6 +121,11 @@ static int vio_make_devnode(SpaprVioDevice *dev,return ret; } + ret =fdt_setprop_cell (fdt, node_off,"phandle" , dev->phandle); +if (ret <0 ) { +return ret; + } +if (pc->dt_type) { ret =fdt_setprop_string (fdt, node_off,"device_type" , pc->dt_type);
@@ -468,6 +489,7 @@ static void spapr_vio_busdev_realize(DeviceState *qdev, Error **errp)SpaprVioDeviceClass *pc =VIO_SPAPR_DEVICE_GET_CLASS (dev);char *id;Error *local_err =NULL ; +SpaprVioBus *bus =SPAPR_VIO_BUS (dev->qdev.parent_bus);if (dev->reg !=-1 ) {/*
@@ -487,13 +509,13 @@ static void spapr_vio_busdev_realize(DeviceState *qdev, Error **errp) } }else {/* Need to assign an address */ -SpaprVioBus *bus =SPAPR_VIO_BUS (dev->qdev.parent_bus); -do { dev->reg = bus->next_reg++; }while (reg_conflict (dev)); } + dev->phandle = bus->next_phandle++; +/* Don't overwrite ids assigned on the command line */ if (!dev->qdev.id) { id =spapr_vio_get_dev_name (DEVICE (dev));
@@ -576,6 +598,7 @@ SpaprVioBus *spapr_vio_bus_init(void) qbus =qbus_create (TYPE_SPAPR_VIO_BUS , dev,"spapr-vio" ); bus =SPAPR_VIO_BUS (qbus); bus->next_reg =SPAPR_VIO_REG_BASE ; + bus->next_phandle =PHANDLE_SPAPR_VIO_BASE ;/* hcall-vio */ spapr_register_hypercall (H_VIO_SIGNAL , h_vio_signal);
hw/ppc/trace-events +10 -0
@@ -21,6 +21,16 @@ spapr_update_dt(unsigned cb) "New blob %u bytes" spapr_update_dt_failed_size(unsigned cbold, unsigned cbnew, unsigned magic) "Old blob %u bytes, new blob %u bytes, magic 0x%x" spapr_update_dt_failed_check(unsigned cbold, unsigned cbnew, unsigned magic) "Old blob %u bytes, new blob %u bytes, magic 0x%x" +# spapr_client.c +spapr_of_client_error_param(const char *method, int nargscheck, int nretcheck, int nargs, int nret) "%s takes/returns %d/%d, not %d/%d" +spapr_of_client_error_unknown_service(const char *service, int nargs, int nret) "%s args=%d rets=%d" +spapr_of_client_error_unknown_method(const char *method) "%s" +spapr_of_client_error_unknown_ihandle_close(uint32_t ihandle) "0x%x" +spapr_of_client_claim(uint32_t virt, uint32_t size, uint32_t align, uint32_t ret) "virt=0x%x size=0x%x align=0x%x => 0x%x" +spapr_of_client_method(const char *method, uint32_t param1, uint32_t param2, uint32_t ret) "%s(0x%x, 0x%x) => 0x%x" +spapr_of_client_getprop(uint32_t ph, const char *prop, uint32_t ret) "phandle=0x%x \"%s\" => 0x%x" +spapr_of_client_setprop(uint32_t ph, const char *prop, uint32_t ret) "phandle=0x%x \"%s\" => 0x%x" + # spapr_hcall_tpm.c spapr_h_tpm_comm(const char *device_path, uint64_t operation) "tpm_device_path=%s operation=0x%"PRIu64 spapr_tpm_execute(uint64_t data_in, uint64_t data_in_sz, uint64_t data_out, uint64_t data_out_sz) "data_in=0x%"PRIx64", data_in_sz=%"PRIu64", data_out=0x%"PRIx64", data_out_sz=%"PRIu64
Signature · 1 line
2.17.1
hw/ppc/spapr_of_client.c line 235
Quoted 2 lines · Alexey Kardashevskiy
hw/ppc/spapr_of_client.c new file +2
-0+ +uint32_t spapr_of_client_open (SpaprMachineState *spapr,uint32_t phandle)
Ooops, this should have been an address of a path, not a phandle.
Quoted 9 lines
hw/ppc/spapr_of_client.c new file +9
-0+{ +g_assert (spapr->of_instance_last !=0xFFFFFFFF ); + ++spapr->of_instance_last; +g_hash_table_insert (spapr->of_instances, +GINT_TO_POINTER (spapr->of_instance_last), +GINT_TO_POINTER (phandle)); + +return spapr->of_instance_last; +}
Signature · 1 line
Alexey