[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 21/22] spapr_pci: populate ibm,loc-code
From: |
David Gibson |
Subject: |
[Qemu-devel] [PATCH 21/22] spapr_pci: populate ibm,loc-code |
Date: |
Wed, 24 Jun 2015 16:30:35 +1000 |
From: Nikunj A Dadhania <address@hidden>
Each hardware instance has a platform unique location code. The OF
device tree that describes a part of a hardware entity must include
the “ibm,loc-code” property with a value that represents the location
code for that hardware entity.
Populate ibm,loc-code.
1) PCI passthru devices need to identify with its own ibm,loc-code
available on the host. In failure cases use:
vfio_<name>:<phb-index>:<bus>:<slot>.<fn>
2) Emulated devices encode as following:
qemu_<name>:<phb-index>:<bus>:<slot>.<fn>
Signed-off-by: Nikunj A Dadhania <address@hidden>
Signed-off-by: David Gibson <address@hidden>
---
hw/ppc/spapr_pci.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 71 insertions(+), 6 deletions(-)
diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c
index 7c3621c..7585983 100644
--- a/hw/ppc/spapr_pci.c
+++ b/hw/ppc/spapr_pci.c
@@ -747,6 +747,60 @@ static AddressSpace *spapr_pci_dma_iommu(PCIBus *bus, void
*opaque, int devfn)
return &phb->iommu_as;
}
+static char *spapr_phb_vfio_get_loc_code(sPAPRPHBState *sphb, PCIDevice *pdev)
+{
+ char *path = NULL, *buf = NULL, *host = NULL;
+
+ /* Get the PCI VFIO host id */
+ host = object_property_get_str(OBJECT(pdev), "host", NULL);
+ if (!host) {
+ goto err_out;
+ }
+
+ /* Construct the path of the file that will give us the DT location */
+ path = g_strdup_printf("/sys/bus/pci/devices/%s/devspec", host);
+ g_free(host);
+ if (!path || !g_file_get_contents(path, &buf, NULL, NULL)) {
+ goto err_out;
+ }
+ g_free(path);
+
+ /* Construct and read from host device tree the loc-code */
+ path = g_strdup_printf("/proc/device-tree%s/ibm,loc-code", buf);
+ g_free(buf);
+ if (!path || !g_file_get_contents(path, &buf, NULL, NULL)) {
+ goto err_out;
+ }
+ return buf;
+
+err_out:
+ g_free(path);
+ return NULL;
+}
+
+static char *spapr_phb_get_loc_code(sPAPRPHBState *sphb, PCIDevice *pdev)
+{
+ char *buf;
+ const char *devtype = "qemu";
+ uint32_t busnr = pci_bus_num(PCI_BUS(qdev_get_parent_bus(DEVICE(pdev))));
+
+ if (object_dynamic_cast(OBJECT(pdev), "vfio-pci")) {
+ buf = spapr_phb_vfio_get_loc_code(sphb, pdev);
+ if (buf) {
+ return buf;
+ }
+ devtype = "vfio";
+ }
+ /*
+ * For emulated devices and VFIO-failure case, make up
+ * the loc-code.
+ */
+ buf = g_strdup_printf("%s_%s:%04x:%02x:%02x.%x",
+ devtype, pdev->name, sphb->index, busnr,
+ PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
+ return buf;
+}
+
/* Macros to operate with address in OF binding to PCI */
#define b_x(x, p, l) (((x) & ((1<<(l))-1)) << (p))
#define b_n(x) b_x((x), 31, 1) /* 0 if relocatable */
@@ -885,11 +939,12 @@ static void populate_resource_props(PCIDevice *d,
ResourceProps *rp)
static int spapr_populate_pci_child_dt(PCIDevice *dev, void *fdt, int offset,
int phb_index, int drc_index,
- const char *drc_name)
+ sPAPRPHBState *sphb)
{
ResourceProps rp;
bool is_bridge = false;
- int pci_status;
+ int pci_status, err;
+ char *buf = NULL;
if (pci_default_read_config(dev, PCI_HEADER_TYPE, 1) ==
PCI_HEADER_TYPE_BRIDGE) {
@@ -950,7 +1005,18 @@ static int spapr_populate_pci_child_dt(PCIDevice *dev,
void *fdt, int offset,
* processed by OF beforehand
*/
_FDT(fdt_setprop_string(fdt, offset, "name", "pci"));
- _FDT(fdt_setprop(fdt, offset, "ibm,loc-code", drc_name, strlen(drc_name)));
+ buf = spapr_phb_get_loc_code(sphb, dev);
+ if (!buf) {
+ error_report("Failed setting the ibm,loc-code");
+ return -1;
+ }
+
+ err = fdt_setprop_string(fdt, offset, "ibm,loc-code", buf);
+ g_free(buf);
+ if (err < 0) {
+ return err;
+ }
+
_FDT(fdt_setprop_cell(fdt, offset, "ibm,my-drc-index", drc_index));
_FDT(fdt_setprop_cell(fdt, offset, "#address-cells",
@@ -988,7 +1054,7 @@ static int spapr_create_pci_child_dt(sPAPRPHBState *phb,
PCIDevice *dev,
}
offset = fdt_add_subnode(fdt, node_offset, nodename);
ret = spapr_populate_pci_child_dt(dev, fdt, offset, phb->index, drc_index,
- drc_name);
+ phb);
g_assert(!ret);
if (ret) {
return 0;
@@ -1004,14 +1070,13 @@ static void spapr_phb_add_pci_device(sPAPRDRConnector
*drc,
sPAPRDRConnectorClass *drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc);
DeviceState *dev = DEVICE(pdev);
int drc_index = drck->get_index(drc);
- const char *drc_name = drck->get_name(drc);
void *fdt = NULL;
int fdt_start_offset = 0, fdt_size;
if (dev->hotplugged) {
fdt = create_device_tree(&fdt_size);
fdt_start_offset = spapr_create_pci_child_dt(phb, pdev,
- drc_index, drc_name,
+ drc_index, NULL,
fdt, 0);
if (!fdt_start_offset) {
error_setg(errp, "Failed to create pci child device tree node");
--
2.4.3
- [Qemu-devel] [PATCH 04/22] spapr: Remove obsolete ram_limit field from sPAPRMachineState, (continued)
- [Qemu-devel] [PATCH 04/22] spapr: Remove obsolete ram_limit field from sPAPRMachineState, David Gibson, 2015/06/24
- [Qemu-devel] [PATCH 08/22] spapr_pci: encode class code including Prog IF register, David Gibson, 2015/06/24
- [Qemu-devel] [PATCH 03/22] spapr: Merge sPAPREnvironment into sPAPRMachineState, David Gibson, 2015/06/24
- [Qemu-devel] [PATCH 02/22] pseries: Update SLOF firmware image to qemu-slof-20150429, David Gibson, 2015/06/24
- [Qemu-devel] [PATCH 01/22] spapr: ensure we have at least one XICS server, David Gibson, 2015/06/24
- [Qemu-devel] [PATCH 15/22] cpus: Add a macro to walk CPUs in reverse, David Gibson, 2015/06/24
- [Qemu-devel] [PATCH 17/22] spapr: Consolidate cpu init code into a routine, David Gibson, 2015/06/24
- [Qemu-devel] [PATCH 18/22] ppc: Update cpu_model in MachineState, David Gibson, 2015/06/24
- [Qemu-devel] [PATCH 22/22] spapr_pci: drop redundant args in spapr_[populate, create]_pci_child_dt, David Gibson, 2015/06/24
- [Qemu-devel] [PATCH 19/22] xics_kvm: Don't enable KVM_CAP_IRQ_XICS if already enabled, David Gibson, 2015/06/24
- [Qemu-devel] [PATCH 21/22] spapr_pci: populate ibm,loc-code,
David Gibson <=
- [Qemu-devel] [PATCH 20/22] spapr_pci: enumerate and add PCI device tree, David Gibson, 2015/06/24
- [Qemu-devel] [PATCH 16/22] spapr: Reorganize CPU dt generation code, David Gibson, 2015/06/24
- Re: [Qemu-devel] [PATCH 00/22] sPAPR updates 2015-06-24, David Gibson, 2015/06/24