Skip to contentSkip to conversation

spapr: bootindex support

PATCH In review Alexey Kardashevskiy 2 participants 8 messages Mar 17, 2014 – Mar 20, 2014

lore
Share & tools
lore
#0 lore raw

v7 cover spapr: bootindex support

Rebased on top of 2.0-rc0 so the only change was the way of QEMUMachine's object creation. Too late/raw/controversial for 2.0? Thanks.

Alexey Kardashevskiy (5):
boot: extend get_boot_devices_list() to ignore suffixes
spapr-llan: add to boot device list
spapr-vio: fix firmware names
spapr: QOM'fy machine
spapr: define interface to fix device pathname

Paolo Bonzini (1):
qdev: introduce FWPathProvider interface

 hw/core/Makefile.objs         |   1 +
 hw/core/fw-path-provider.c    |  51 ++++++++++++++++++++
 hw/core/qdev.c                |  18 ++++++-
 hw/net/spapr_llan.c           |   3 ++
 hw/nvram/fw_cfg.c             |   2 +-
 hw/ppc/spapr.c                | 108 +++++++++++++++++++++++++++++++++++++++++-
 hw/ppc/spapr_vio.c            |   3 ++
 include/hw/fw-path-provider.h |  47 ++++++++++++++++++
 include/sysemu/sysemu.h       |   2 +-
 tests/Makefile                |   1 +
 vl.c                          |   8 ++--
 11 files changed, 237 insertions(+), 7 deletions(-)
 create mode 100644 hw/core/fw-path-provider.c
 create mode 100644 include/hw/fw-path-provider.h
Signature · 1 line
1.8.4.rc4
#1 lore raw

PATCH v7 1/6 boot: extend get_boot_devices_list() to ignore suffixes

As suffixes do not make sense for sPAPR's device tree and there is no way to filter them out on the BusState::get_fw_dev_path level, let's add an ability for the external caller to specify whether to apply suffixes or not.

We could handle suffixes in SLOF (ignore for now) but this would require serious rework in the node opening code in SLOF which has no obvious benefit for the currently emulated sPAPR machine.

---
Changes:
v4:
* changed commit message about not having plans in SLOF rework as it is scary :)

---
 hw/nvram/fw_cfg.c       | 2 +-
 include/sysemu/sysemu.h | 2 +-
 vl.c                    | 8 +++++---
 3 files changed, 7 insertions(+), 5 deletions(-)
hw/nvram/fw_cfg.c +1 -1
index cb36dc2..282341a 100644
@@ -504,7 +504,7 @@ static void fw_cfg_machine_ready(struct Notifier *n, void *data)
 {
     size_t len;
     FWCfgState *s = container_of(n, FWCfgState, machine_ready);
-    char *bootindex = get_boot_devices_list(&len);
+    char *bootindex = get_boot_devices_list(&len, false);
 
     fw_cfg_add_file(s, "bootorder", (uint8_t*)bootindex, len);
 }
include/sysemu/sysemu.h +1 -1
index c01304d..3915ce3 100644
@@ -186,7 +186,7 @@ void rtc_change_mon_event(struct tm *tm);
 
 void add_boot_device_path(int32_t bootindex, DeviceState *dev,
                           const char *suffix);
-char *get_boot_devices_list(size_t *size);
+char *get_boot_devices_list(size_t *size, bool ignore_suffixes);
 
 DeviceState *get_boot_device(uint32_t position);
 
vl.c +5 -3
index 842e897..19b4842 100644
@@ -1206,7 +1206,7 @@ DeviceState *get_boot_device(uint32_t position)
  * memory pointed by "size" is assigned total length of the array in bytes
  *
  */
-char *get_boot_devices_list(size_t *size)
+char *get_boot_devices_list(size_t *size, bool ignore_suffixes)
 {
     FWBootEntry *i;
     size_t total = 0;
@@ -1221,7 +1221,7 @@ char *get_boot_devices_list(size_t *size)
             assert(devpath);
         }
 
-        if (i->suffix && devpath) {
+        if (i->suffix && !ignore_suffixes && devpath) {
             size_t bootpathlen = strlen(devpath) + strlen(i->suffix) + 1;
 
             bootpath = g_malloc(bootpathlen);
@@ -1229,9 +1229,11 @@ char *get_boot_devices_list(size_t *size)
             g_free(devpath);
         } else if (devpath) {
             bootpath = devpath;
-        } else {
+        } else if (!ignore_suffixes) {
             assert(i->suffix);
             bootpath = g_strdup(i->suffix);
+        } else {
+            bootpath = g_strdup("");
         }
 
         if (total) {
Signature · 1 line
1.8.4.rc4
#2 lore raw

PATCH v7 2/6 qdev: introduce FWPathProvider interface

In reply to Alexey Kardashevskiy

From: Paolo Bonzini <[email protected]>

QEMU supports firmware names for all devices in the QEMU tree but some architectures expect some parts of firmware path names in different format.

This introduces a firmware-pathname-change interface definition. If some machines needs to redefine the firmware path format, it has to add the TYPE_FW_PATH_PROVIDER interface to an object that is above the device on the QOM tree (typically /machine).

---
Changes:
v6:
* fixed "sob" order in the commit message :)
* remove cut-n-paste leftovers

v5:
* fixed code design
* added license headers

v4:
* added fw-path-provider.o into tests/Makefile
* fixed 80chars warning from checkpatch.pl

---
 hw/core/Makefile.objs         |  1 +
 hw/core/fw-path-provider.c    | 51 +++++++++++++++++++++++++++++++++++++++++++
 hw/core/qdev.c                | 18 ++++++++++++++-
 include/hw/fw-path-provider.h | 47 +++++++++++++++++++++++++++++++++++++++
 tests/Makefile                |  1 +
 5 files changed, 117 insertions(+), 1 deletion(-)
 create mode 100644 hw/core/fw-path-provider.c
 create mode 100644 include/hw/fw-path-provider.h
hw/core/Makefile.objs +1 -0
index 981593c..5377d05 100644
@@ -1,5 +1,6 @@
 # core qdev-related obj files, also used by *-user:
 common-obj-y += qdev.o qdev-properties.o
+common-obj-y += fw-path-provider.o
 # irq.o needed for qdev GPIO handling:
 common-obj-y += irq.o
 common-obj-y += hotplug.o
hw/core/fw-path-provider.c new file +51 -0

51 lines not on this page · raw message

hw/core/qdev.c +17 -1
index 9f0a522..cd09cd4 100644
@@ -26,6 +26,7 @@
    this API directly.  */
 
 #include "hw/qdev.h"
+#include "hw/fw-path-provider.h"
 #include "sysemu/sysemu.h"
 #include "qapi/error.h"
 #include "qapi/qmp/qerror.h"
@@ -568,6 +569,18 @@ static char *bus_get_fw_dev_path(BusState *bus, DeviceState *dev)
     return NULL;
 }
 
+static char *qdev_get_fw_dev_path_from_handler(BusState *bus, DeviceState *dev)
+{
+    Object *obj = OBJECT(dev);
+    char *d = NULL;
+
+    while (!d && obj->parent) {
+        obj = obj->parent;
+        d = fw_path_provider_try_get_dev_path(obj, bus, dev);
+    }
+    return d;
+}
+
 static int qdev_get_fw_dev_path_helper(DeviceState *dev, char *p, int size)
 {
     int l = 0;
@@ -575,7 +588,10 @@ static int qdev_get_fw_dev_path_helper(DeviceState *dev, char *p, int size)
     if (dev && dev->parent_bus) {
         char *d;
         l = qdev_get_fw_dev_path_helper(dev->parent_bus->parent, p, size);
-        d = bus_get_fw_dev_path(dev->parent_bus, dev);
+        d = qdev_get_fw_dev_path_from_handler(dev->parent_bus, dev);
+        if (!d) {
+            d = bus_get_fw_dev_path(dev->parent_bus, dev);
+        }
         if (d) {
             l += snprintf(p + l, size - l, "%s", d);
             g_free(d);
include/hw/fw-path-provider.h new file +47 -0

47 lines not on this page · raw message

tests/Makefile +1 -0
index 471b4c8..2d021fb 100644
@@ -206,6 +206,7 @@ tests/test-int128$(EXESUF): tests/test-int128.o
 tests/test-qdev-global-props$(EXESUF): tests/test-qdev-global-props.o \
 	hw/core/qdev.o hw/core/qdev-properties.o hw/core/hotplug.o\
 	hw/core/irq.o \
+	hw/core/fw-path-provider.o \
 	$(qom-core-obj) \
 	$(test-qapi-obj-y) \
 	libqemuutil.a libqemustub.a
Signature · 1 line
1.8.4.rc4
#3 lore raw

PATCH v7 3/6 spapr-llan: add to boot device list

In reply to Alexey Kardashevskiy
---
 hw/net/spapr_llan.c | 3 +++
 1 file changed, 3 insertions(+)
hw/net/spapr_llan.c +3 -0
index f6fbcb5..c433337 100644
@@ -29,6 +29,7 @@
 #include "hw/qdev.h"
 #include "hw/ppc/spapr.h"
 #include "hw/ppc/spapr_vio.h"
+#include "sysemu/sysemu.h"
 
 #include <libfdt.h>
 
@@ -213,6 +214,8 @@ static int spapr_vlan_init(VIOsPAPRDevice *sdev)
                             object_get_typename(OBJECT(sdev)), sdev->qdev.id, dev);
     qemu_format_nic_info_str(qemu_get_queue(dev->nic), dev->nicconf.macaddr.a);
 
+    add_boot_device_path(dev->nicconf.bootindex, DEVICE(dev), "");
+
     return 0;
 }
 
Signature · 1 line
1.8.4.rc4
#4 lore raw

PATCH v7 4/6 spapr-vio: fix firmware names

In reply to Alexey Kardashevskiy

This changes VIO bridge fw name from spapr-vio-bridge to vdevice and vscsi/veth node names from QEMU object names to VIO specific device tree names.

---
 hw/ppc/spapr_vio.c | 3 +++
 1 file changed, 3 insertions(+)
hw/ppc/spapr_vio.c +3 -0
index 4e33f46..2ae06a3 100644
@@ -68,6 +68,7 @@ static void spapr_vio_bus_class_init(ObjectClass *klass, void *data)
     BusClass *k = BUS_CLASS(klass);
 
     k->get_dev_path = spapr_vio_get_dev_name;
+    k->get_fw_dev_path = spapr_vio_get_dev_name;
 }
 
 static const TypeInfo spapr_vio_bus_info = {
@@ -529,7 +530,9 @@ static int spapr_vio_bridge_init(SysBusDevice *dev)
 static void spapr_vio_bridge_class_init(ObjectClass *klass, void *data)
 {
     SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+    DeviceClass *dc = DEVICE_CLASS(klass);
 
+    dc->fw_name = "vdevice";
     k->init = spapr_vio_bridge_init;
 }
 
Signature · 1 line
1.8.4.rc4
#5 lore raw

PATCH v7 5/6 spapr: QOM'fy machine

In reply to Alexey Kardashevskiy

---
Changes:
v8:
* QOM'ed according to the latest rules from 2.0-rc0.

---
 hw/ppc/spapr.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
hw/ppc/spapr.c +23 -0
index 5c9a154..43b9fcb 100644
@@ -81,6 +81,8 @@
 
 #define HTAB_SIZE(spapr)        (1ULL << ((spapr)->htab_shift))
 
+#define TYPE_SPAPR_MACHINE      "machine-spapr"
+
 sPAPREnvironment *spapr;
 
 int spapr_allocate_irq(int hint, bool lsi)
@@ -1416,3 +1418,24 @@ static void spapr_machine_init(void)
 }
 
 machine_init(spapr_machine_init);
+
+static void spapr_machine_class_init(ObjectClass *oc, void *data)
+{
+    MachineClass *mc = MACHINE_CLASS(oc);
+
+    mc->qemu_machine = data;
+}
+
+static const TypeInfo spapr_machine_info = {
+    .name          = TYPE_SPAPR_MACHINE,
+    .parent        = TYPE_MACHINE,
+    .class_init    = spapr_machine_class_init,
+    .class_data    = &spapr_machine,
+};
+
+static void spapr_machine_register_types(void)
+{
+    type_register_static(&spapr_machine_info);
+}
+
+type_init(spapr_machine_register_types)
Signature · 1 line
1.8.4.rc4
#6 lore raw

Re: [Qemu-devel] [PATCH v7 5/6] spapr: QOM'fy machine

Am 17.03.2014 03:40, schrieb Alexey Kardashevskiy:

Quoted 5 lines

---
Changes:
v8:
* QOM'ed according to the latest rules from 2.0-rc0.

Fixing up as follows:

hw/ppc/spapr.c +1 -8
index 43b9fcb..170e083 100644
@@ -81,7 +81,7 @@
 
 #define HTAB_SIZE(spapr)        (1ULL << ((spapr)->htab_shift))
 
-#define TYPE_SPAPR_MACHINE      "machine-spapr"
+#define TYPE_SPAPR_MACHINE      "spapr-machine"
 
 sPAPREnvironment *spapr;
 
@@ -1412,13 +1412,6 @@ static QEMUMachine spapr_machine = {
     .kvm_type = spapr_kvm_type,
 };
 
-static void spapr_machine_init(void)
-{
-    qemu_register_machine(&spapr_machine);
-}
-
-machine_init(spapr_machine_init);
-
 static void spapr_machine_class_init(ObjectClass *oc, void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);

Regards,
Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#7 lore raw

PATCH v7 6/6 spapr: define interface to fix device pathname

In reply to Alexey Kardashevskiy

This defines an object with the interface to fix firmware pathnames for devices which have @bootindex property.

This fixes SCSI disks device node names (which are wildcard nodes in the device-tree), for spapr-vsci, virtio-scsi and usb-storage.

This fixes PHB name from "pci" to "pci@XXXX" where XXXX is a BUID as there is no bus on top of sPAPRPHBState where PHB firmware name could be fixed using the BusClass::get_fw_dev_path mechanism.

This stores the boot list in the /chosen/qemu,boot-list property of the device tree. "\n" are replaced by spaces to support OF1275. SLOF needs an update in order to support the boot list.

---
Changes:
v6:
* moved QOM'fication piece to a separate patch

v5:
* addev virtio and usb handling

v2:
* added special handling for virtio-scsi and USB as they use different LUN encoding in SLOF

---
 hw/ppc/spapr.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 84 insertions(+), 1 deletion(-)
hw/ppc/spapr.c +84 -1
index 43b9fcb..553b5a1 100644
@@ -26,6 +26,7 @@
  */
 #include "sysemu/sysemu.h"
 #include "hw/hw.h"
+#include "hw/fw-path-provider.h"
 #include "elf.h"
 #include "net/net.h"
 #include "sysemu/blockdev.h"
@@ -45,6 +46,8 @@
 #include "hw/pci/msi.h"
 
 #include "hw/pci/pci.h"
+#include "hw/scsi/scsi.h"
+#include "hw/virtio/virtio-scsi.h"
 
 #include "exec/address-spaces.h"
 #include "hw/usb.h"
@@ -600,7 +603,9 @@ static void spapr_finalize_fdt(sPAPREnvironment *spapr,
                                hwaddr rtas_addr,
                                hwaddr rtas_size)
 {
-    int ret;
+    int ret, i;
+    size_t cb = 0;
+    char *bootlist;
     void *fdt;
     sPAPRPHBState *phb;
 
@@ -642,6 +647,21 @@ static void spapr_finalize_fdt(sPAPREnvironment *spapr,
         fprintf(stderr, "Couldn't finalize CPU device tree properties\n");
     }
 
+    bootlist = get_boot_devices_list(&cb, true);
+    if (cb && bootlist) {
+        int offset = fdt_path_offset(fdt, "/chosen");
+        if (offset < 0) {
+            exit(1);
+        }
+        for (i = 0; i < cb; i++) {
+            if (bootlist[i] == '\n') {
+                bootlist[i] = ' ';
+            }
+
+        }
+        ret = fdt_setprop_string(fdt, offset, "qemu,boot-list", bootlist);
+    }
+
     if (!spapr->has_graphics) {
         spapr_populate_chosen_stdout(fdt, spapr->vio_bus);
     }
@@ -1419,11 +1439,70 @@ static void spapr_machine_init(void)
 
 machine_init(spapr_machine_init);
 
+/*
+ * Implementation of an interface to adjust firmware patch
+ * for the bootindex property handling.
+ */
+static char *spapr_get_fw_dev_path(FWPathProvider *p, BusState *bus,
+                                   DeviceState *dev)
+{
+#define CAST(type, obj, name) \
+    ((type *)object_dynamic_cast(OBJECT(obj), (name)))
+    SCSIDevice *d = CAST(SCSIDevice,  dev, TYPE_SCSI_DEVICE);
+    sPAPRPHBState *phb = CAST(sPAPRPHBState, dev, TYPE_SPAPR_PCI_HOST_BRIDGE);
+
+    if (d) {
+        void *spapr = CAST(void, bus->parent, "spapr-vscsi");
+        VirtIOSCSI *virtio = CAST(VirtIOSCSI, bus->parent, TYPE_VIRTIO_SCSI);
+        USBDevice *usb = CAST(USBDevice, bus->parent, TYPE_USB_DEVICE);
+
+        if (spapr) {
+            /*
+             * Replace "channel@0/disk@0,0" with "disk@8000000000000000":
+             * We use SRP luns of the form 8000 | (bus << 8) | (id << 5) | lun
+             * in the top 16 bits of the 64-bit LUN
+             */
+            unsigned id = 0x8000 | (d->id << 8) | d->lun;
+            return g_strdup_printf("%s@%"PRIX64, qdev_fw_name(dev),
+                                   (uint64_t)id << 48);
+        } else if (virtio) {
+            /*
+             * We use SRP luns of the form 01000000 | (target << 8) | lun
+             * in the top 32 bits of the 64-bit LUN
+             * Note: the quote above is from SLOF and it is wrong,
+             * the actual binding is:
+             * swap 0100 or 10 << or 20 << ( target lun-id -- srplun )
+             */
+            unsigned id = 0x1000000 | (d->id << 16) | d->lun;
+            return g_strdup_printf("%s@%"PRIX64, qdev_fw_name(dev),
+                                   (uint64_t)id << 32);
+        } else if (usb) {
+            /*
+             * We use SRP luns of the form 01000000 | (usb-port << 16) | lun
+             * in the top 32 bits of the 64-bit LUN
+             */
+            unsigned usb_port = atoi(usb->port->path);
+            unsigned id = 0x1000000 | (usb_port << 16) | d->lun;
+            return g_strdup_printf("%s@%"PRIX64, qdev_fw_name(dev),
+                                   (uint64_t)id << 32);
+        }
+    }
+
+    if (phb) {
+        /* Replace "pci" with "pci@800000020000000" */
+        return g_strdup_printf("pci@%"PRIX64, phb->buid);
+    }
+
+    return NULL;
+}
+
 static void spapr_machine_class_init(ObjectClass *oc, void *data)
 {
     MachineClass *mc = MACHINE_CLASS(oc);
+    FWPathProviderClass *fwc = FW_PATH_PROVIDER_CLASS(oc);
 
     mc->qemu_machine = data;
+    fwc->get_dev_path = spapr_get_fw_dev_path;
 }
 
 static const TypeInfo spapr_machine_info = {
@@ -1431,6 +1510,10 @@ static const TypeInfo spapr_machine_info = {
     .parent        = TYPE_MACHINE,
     .class_init    = spapr_machine_class_init,
     .class_data    = &spapr_machine,
+    .interfaces = (InterfaceInfo[]) {
+            { TYPE_FW_PATH_PROVIDER },
+            { }
+    }
 };
 
 static void spapr_machine_register_types(void)
Signature · 1 line
1.8.4.rc4