From patchwork Tue May 5 08:53: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: 467951 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 BB74814099F for ; Tue, 5 May 2015 18:58:27 +1000 (AEST) Received: from localhost ([::1]:37585 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YpYgM-0001dm-03 for incoming@patchwork.ozlabs.org; Tue, 05 May 2015 04:58:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34362) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YpYdK-0004kX-Fk for qemu-devel@nongnu.org; Tue, 05 May 2015 04:55:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YpYdG-00085t-75 for qemu-devel@nongnu.org; Tue, 05 May 2015 04:55:18 -0400 Received: from e23smtp03.au.ibm.com ([202.81.31.145]:47988) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YpYdF-00084z-Jh for qemu-devel@nongnu.org; Tue, 05 May 2015 04:55:14 -0400 Received: from /spool/local by e23smtp03.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 5 May 2015 18:55:11 +1000 Received: from d23dlp03.au.ibm.com (202.81.31.214) by e23smtp03.au.ibm.com (202.81.31.209) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 5 May 2015 18:55:08 +1000 Received: from d23relay08.au.ibm.com (d23relay08.au.ibm.com [9.185.71.33]) by d23dlp03.au.ibm.com (Postfix) with ESMTP id B11013578048; Tue, 5 May 2015 18:55:07 +1000 (EST) Received: from d23av04.au.ibm.com (d23av04.au.ibm.com [9.190.235.139]) by d23relay08.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t458sxjm32833738; Tue, 5 May 2015 18:55:07 +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 t458sYaf018511; Tue, 5 May 2015 18:54:35 +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 t458sLOq017866; Tue, 5 May 2015 18:54:33 +1000 From: Nikunj A Dadhania To: qemu-devel@nongnu.org, david@gibson.dropbear.id.au Date: Tue, 5 May 2015 14:23:56 +0530 Message-Id: <1430816036-26408-7-git-send-email-nikunj@linux.vnet.ibm.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1430816036-26408-1-git-send-email-nikunj@linux.vnet.ibm.com> References: <1430816036-26408-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: 15050508-0009-0000-0000-00000157B982 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 202.81.31.145 Cc: aik@ozlabs.ru, qemu-ppc@nongnu.org, agraf@suse.de, nikunj@linux.vnet.ibm.com, mdroth@linux.vnet.ibm.com Subject: [Qemu-devel] [PATCH v3 6/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. 2) Emulated devices encode as following: qemu_::. Signed-off-by: Nikunj A Dadhania --- hw/ppc/spapr_pci.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 75 insertions(+), 11 deletions(-) diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c index cbd5661..eacf0bd 100644 --- a/hw/ppc/spapr_pci.c +++ b/hw/ppc/spapr_pci.c @@ -744,6 +744,70 @@ static AddressSpace *spapr_pci_dma_iommu(PCIBus *bus, void *opaque, int devfn) return &phb->iommu_as; } +static bool spapr_phb_vfio_get_devspec_value(PCIDevice *pdev, char **value) +{ + char *host; + char path[PATH_MAX]; + + host = object_property_get_str(OBJECT(pdev), "host", NULL); + if (!host) { + return false; + } + + snprintf(path, sizeof(path), "/sys/bus/pci/devices/%s/devspec", host); + g_free(host); + + return g_file_get_contents(path, value, NULL, NULL); +} + +static char *spapr_phb_vfio_get_loc_code(sPAPRPHBState *sphb, PCIDevice *pdev) +{ + char path[PATH_MAX], *buf = NULL; + + /* We have a vfio host bridge lets get the path. */ + if (!spapr_phb_vfio_get_devspec_value(pdev, &buf)) { + return NULL; + } + + snprintf(path, sizeof(path), "/proc/device-tree%s/ibm,loc-code", buf); + g_free(buf); + + if (g_file_get_contents(path, &buf, NULL, NULL)) { + return buf; + } else { + return NULL; + } +} + +static char *spapr_phb_get_loc_code(sPAPRPHBState *sphb, PCIDevice *pdev) +{ + char *path = g_malloc(PATH_MAX); + + if (!path) { + return NULL; + } + + /* + * For non-vfio devices and failures make up the location code out + * of the name, slot and function. + * + * qemu_::. + */ + snprintf(path, PATH_MAX, "qemu_%s:%02d:%02d.%1d", pdev->name, + sphb->index, PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn)); + return path; +} + + +static char *spapr_ibm_get_loc_code(sPAPRPHBState *sphb, PCIDevice *pdev) +{ + if (object_dynamic_cast(OBJECT(pdev), "vfio-pci") != NULL) { + return spapr_phb_vfio_get_loc_code(sphb, pdev); + } else { + return spapr_phb_get_loc_code(sphb, pdev); + } +} + /* 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 */ @@ -881,12 +945,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 *phb, int drc_index) { 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) { @@ -947,9 +1011,10 @@ 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_ibm_get_loc_code(phb, dev); + if (buf) { + _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)); @@ -988,8 +1053,7 @@ static void *spapr_create_pci_child_dt(sPAPRPHBState *phb, PCIDevice *dev, sprintf(nodename, "pci@%d", slot); } offset = fdt_add_subnode(fdt, 0, nodename); - ret = spapr_populate_pci_child_dt(dev, fdt, offset, phb->index, drc_index, - drc_name); + ret = spapr_populate_pci_child_dt(dev, fdt, offset, phb, drc_index); g_assert(!ret); *dt_offset = offset; @@ -1502,7 +1566,7 @@ static uint32_t spapr_phb_get_pci_drc_index(sPAPRPHBState *phb, typedef struct sPAPRFDT { void *fdt; int node_off; - uint32_t index; + sPAPRPHBState *sphb; } sPAPRFDT; static void spapr_populate_pci_devices_dt(PCIBus *bus, PCIDevice *pdev, @@ -1523,7 +1587,7 @@ static void spapr_populate_pci_devices_dt(PCIBus *bus, PCIDevice *pdev, sprintf(nodename, "pci@%d", slot); } offset = fdt_add_subnode(p->fdt, p->node_off, nodename); - ret = spapr_populate_pci_child_dt(pdev, p->fdt, offset, p->index, drc_index, NULL); + ret = spapr_populate_pci_child_dt(pdev, p->fdt, offset, p->sphb, drc_index); g_assert(!ret); if ((pci_default_read_config(pdev, PCI_HEADER_TYPE, 1) != @@ -1538,7 +1602,7 @@ static void spapr_populate_pci_devices_dt(PCIBus *bus, PCIDevice *pdev, s_fdt.fdt = p->fdt; s_fdt.node_off = offset; - s_fdt.index = p->index; + s_fdt.sphb = p->sphb; pci_for_each_device(sec_bus, pci_bus_num(sec_bus), spapr_populate_pci_devices_dt, &s_fdt); @@ -1680,7 +1744,7 @@ int spapr_populate_pci_dt(sPAPRPHBState *phb, /* Populate tree nodes with PCI devices attached */ s_fdt.fdt = fdt; s_fdt.node_off = bus_off; - s_fdt.index = phb->index; + s_fdt.sphb = phb; pci_for_each_device(bus, pci_bus_num(bus), spapr_populate_pci_devices_dt, &s_fdt);