From patchwork Wed Jun 3 11:25:56 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Nikunj A Dadhania X-Patchwork-Id: 479885 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id E5785140218 for ; Wed, 3 Jun 2015 21:28:24 +1000 (AEST) Received: from localhost ([::1]:34704 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z06qN-0005mL-32 for incoming@patchwork.ozlabs.org; Wed, 03 Jun 2015 07:28:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34905) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z06pM-000487-D8 for qemu-devel@nongnu.org; Wed, 03 Jun 2015 07:27:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z06pJ-0002xI-6d for qemu-devel@nongnu.org; Wed, 03 Jun 2015 07:27:20 -0400 Received: from e23smtp07.au.ibm.com ([202.81.31.140]:60519) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z06pI-0002v2-Jm for qemu-devel@nongnu.org; Wed, 03 Jun 2015 07:27:17 -0400 Received: from /spool/local by e23smtp07.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 3 Jun 2015 21:27:14 +1000 Received: from d23dlp03.au.ibm.com (202.81.31.214) by e23smtp07.au.ibm.com (202.81.31.204) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 3 Jun 2015 21:27:11 +1000 Received: from d23relay10.au.ibm.com (d23relay10.au.ibm.com [9.190.26.77]) by d23dlp03.au.ibm.com (Postfix) with ESMTP id 11E27357805B; Wed, 3 Jun 2015 21:27:11 +1000 (EST) Received: from d23av04.au.ibm.com (d23av04.au.ibm.com [9.190.235.139]) by d23relay10.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t53BR2cC26017858; Wed, 3 Jun 2015 21:27:10 +1000 Received: from d23av04.au.ibm.com (localhost [127.0.0.1]) by d23av04.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t53BQc7h021302; Wed, 3 Jun 2015 21:26:38 +1000 Received: from abhimanyu.in.ibm.com (abhimanyu.in.ibm.com [9.124.35.239]) by d23av04.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id t53BQOnG019905; Wed, 3 Jun 2015 21:26:36 +1000 From: Nikunj A Dadhania To: qemu-ppc@nongnu.org, david@gibson.dropbear.id.au Date: Wed, 3 Jun 2015 16:55:56 +0530 Message-Id: <1433330757-6043-6-git-send-email-nikunj@linux.vnet.ibm.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1433330757-6043-1-git-send-email-nikunj@linux.vnet.ibm.com> References: <1433330757-6043-1-git-send-email-nikunj@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15060311-0025-0000-0000-0000019B56D4 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 202.81.31.140 Cc: agraf@suse.de, thuth@redhat.com, nikunj@linux.vnet.ibm.com, aik@ozlabs.ru, mdroth@linux.vnet.ibm.com, qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH v6 5/6] spapr_pci: populate ibm,loc-code X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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_:::. 2) Emulated devices encode as following: qemu_:::. Signed-off-by: Nikunj A Dadhania --- hw/ppc/spapr_pci.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 68 insertions(+), 10 deletions(-) diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c index 4226468..986bb21 100644 --- a/hw/ppc/spapr_pci.c +++ b/hw/ppc/spapr_pci.c @@ -746,6 +746,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 */ @@ -884,11 +938,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; + char *buf = NULL; if (pci_default_read_config(dev, PCI_HEADER_TYPE, 1) == PCI_HEADER_TYPE_BRIDGE) { @@ -949,10 +1004,15 @@ 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")); - if (drc_name) { - _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; } + + _FDT(fdt_setprop_string(fdt, offset, "ibm,loc-code", buf)); + g_free(buf); + if (drc_index) { _FDT(fdt_setprop_cell(fdt, offset, "ibm,my-drc-index", drc_index)); } @@ -982,8 +1042,7 @@ static uint32_t spapr_phb_get_pci_drc_index(sPAPRPHBState *phb, PCIDevice *pdev); /* create OF node for pci device and required OF DT properties */ -static int spapr_create_pci_child_dt(PCIDevice *dev, sPAPRFDT *p, - const char *drc_name) +static int spapr_create_pci_child_dt(PCIDevice *dev, sPAPRFDT *p) { int offset, ret; int slot = PCI_SLOT(dev->devfn); @@ -998,7 +1057,7 @@ static int spapr_create_pci_child_dt(PCIDevice *dev, sPAPRFDT *p, } offset = fdt_add_subnode(p->fdt, p->node_off, nodename); ret = spapr_populate_pci_child_dt(dev, p->fdt, offset, p->sphb->index, - drc_index, drc_name); + drc_index, p->sphb); g_assert(!ret); if (ret) { return 0; @@ -1013,7 +1072,6 @@ static void spapr_phb_add_pci_device(sPAPRDRConnector *drc, { sPAPRDRConnectorClass *drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc); DeviceState *dev = DEVICE(pdev); - const char *drc_name = drck->get_name(drc); int fdt_start_offset = 0, fdt_size; sPAPRFDT s_fdt = {NULL, 0, NULL}; @@ -1021,7 +1079,7 @@ static void spapr_phb_add_pci_device(sPAPRDRConnector *drc, s_fdt.fdt = create_device_tree(&fdt_size); s_fdt.sphb = phb; s_fdt.node_off = 0; - fdt_start_offset = spapr_create_pci_child_dt(pdev, &s_fdt, drc_name); + fdt_start_offset = spapr_create_pci_child_dt(pdev, &s_fdt); if (!fdt_start_offset) { error_setg(errp, "Failed to create pci child device tree node"); goto out; @@ -1523,7 +1581,7 @@ static void spapr_populate_pci_devices_dt(PCIBus *bus, PCIDevice *pdev, int offset; sPAPRFDT s_fdt; - offset = spapr_create_pci_child_dt(pdev, p, NULL); + offset = spapr_create_pci_child_dt(pdev, p); if (!offset) { error_report("Failed to create pci child device tree node"); return;