From: Jared Rossi <[email protected]> The loadparm is required on s390x to pass the information to the boot loader such as which kernel should be started or whether the boot menu should be shown.
Because PCI devices do not naturally allocate space for this, the property is added on an architecture specific basis for supported device types. Reviewed-by: Thomas Huth <[email protected]> Signed-off-by: Jared Rossi <[email protected]> --- hw/pci/pci.c | 38 +++++++++++++++++++++++++++++++++++++ hw/s390x/ipl.c | 11 +++++++++-- hw/virtio/virtio-blk-pci.c | 1 + include/hw/pci/pci.h | 1 + include/hw/pci/pci_device.h | 3 +++ 5 files changed, 52 insertions(+), 2 deletions(-) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 6399ebd41c..2c3657d00d 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -36,6 +36,7 @@ #include "migration/qemu-file-types.h" #include "migration/vmstate.h" #include "net/net.h" +#include "system/arch_init.h" #include "system/numa.h" #include "system/runstate.h" #include "system/system.h" @@ -2843,6 +2844,43 @@ int pci_qdev_find_device(const char *id, PCIDevice **pdev) return rc; } +static char *pci_qdev_property_get_loadparm(Object *obj, Error **errp) +{ + return g_strdup(PCI_DEVICE(obj)->loadparm); +} + +static void pci_qdev_property_set_loadparm(Object *obj, const char *value, + Error **errp) +{ + void *lp_str; + + if (object_property_get_int(obj, "bootindex", NULL) < 0) { + error_setg(errp, "'loadparm' is only valid for boot devices"); + return; + } + + lp_str = g_malloc0(strlen(value) + 1); + if (!qdev_prop_sanitize_s390x_loadparm(lp_str, value, errp)) { + g_free(lp_str); + return; + } + PCI_DEVICE(obj)->loadparm = lp_str; +} + +void pci_qdev_property_add_specifics(DeviceClass *dc) +{ + ObjectClass *oc = OBJECT_CLASS(dc); + + /* The loadparm property is only supported on s390x */ + if (target_s390x()) { + object_class_property_add_str(oc, "loadparm", + pci_qdev_property_get_loadparm, + pci_qdev_property_set_loadparm); + object_class_property_set_description(oc, "loadparm", + "load parameter (s390x only)"); + } +} + MemoryRegion *pci_address_space(PCIDevice *dev) { return pci_get_bus(dev)->address_space_mem; diff --git a/hw/s390x/ipl.c b/hw/s390x/ipl.c index 53dd3deafa..c231084c18 100644 --- a/hw/s390x/ipl.c +++ b/hw/s390x/ipl.c @@ -461,6 +461,7 @@ static bool s390_build_iplb(DeviceState *dev_st, IplParameterBlock *iplb) int devtype; uint8_t *lp; g_autofree void *scsi_lp = NULL; + g_autofree void *pci_lp = NULL; ccw_dev = s390_get_ccw_device(dev_st, &devtype); if (ccw_dev) { @@ -513,6 +514,14 @@ static bool s390_build_iplb(DeviceState *dev_st, IplParameterBlock *iplb) pbdev = s390_get_pci_device(dev_st, &devtype); if (pbdev) { + pci_lp = object_property_get_str(OBJECT(pbdev->pdev), "loadparm", NULL); + if (pci_lp && strlen(pci_lp) > 0) { + lp = pci_lp; + } else { + /* Use machine loadparm as a place holder if PCI LP is unset */ + lp = S390_CCW_MACHINE(qdev_get_machine())->loadparm; + } + switch (devtype) { case PCI_DEVTYPE_VIRTIO: iplb->len = S390_IPLB_MIN_PCI_LEN; @@ -523,8 +532,6 @@ static bool s390_build_iplb(DeviceState *dev_st, IplParameterBlock *iplb) return false; } - /* Per-device loadparm not yet supported for non-ccw IPL */ - lp = S390_CCW_MACHINE(qdev_get_machine())->loadparm; s390_ipl_convert_loadparm((char *)lp, iplb->loadparm); iplb->flags |= DIAG308_FLAGS_LP_VALID; diff --git a/hw/virtio/virtio-blk-pci.c b/hw/virtio/virtio-blk-pci.c index 64a434c81b..3eecc23a65 100644 --- a/hw/virtio/virtio-blk-pci.c +++ b/hw/virtio/virtio-blk-pci.c @@ -71,6 +71,7 @@ static void virtio_blk_pci_class_init(ObjectClass *klass, const void *data) set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); device_class_set_props(dc, virtio_blk_pci_properties); + pci_qdev_property_add_specifics(dc); k->realize = virtio_blk_pci_realize; pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET; pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_BLOCK; diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index 64141e92fe..5b179091de 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -380,6 +380,7 @@ const char *pci_root_bus_path(PCIDevice *dev); bool pci_bus_bypass_iommu(PCIBus *bus); PCIDevice *pci_find_device(PCIBus *bus, int bus_num, uint8_t devfn); int pci_qdev_find_device(const char *id, PCIDevice **pdev); +void pci_qdev_property_add_specifics(DeviceClass *dc); void pci_bus_get_w64_range(PCIBus *bus, Range *range); void pci_device_deassert_intx(PCIDevice *dev); diff --git a/include/hw/pci/pci_device.h b/include/hw/pci/pci_device.h index 88ccea5011..5cac6e1688 100644 --- a/include/hw/pci/pci_device.h +++ b/include/hw/pci/pci_device.h @@ -62,6 +62,9 @@ struct PCIDevice { bool partially_hotplugged; bool enabled; + /* only for s390x */ + char *loadparm; + /* PCI config space */ uint8_t *config; -- 2.52.0
