From patchwork Thu May 23 05:29:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gibson X-Patchwork-Id: 10956909 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3796713AD for ; Thu, 23 May 2019 05:36:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1223727F81 for ; Thu, 23 May 2019 05:36:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0246727FA8; Thu, 23 May 2019 05:36:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8C67727F81 for ; Thu, 23 May 2019 05:36:22 +0000 (UTC) Received: from localhost ([127.0.0.1]:58004 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTgOr-0004ns-MT for patchwork-qemu-devel@patchwork.kernel.org; Thu, 23 May 2019 01:36:21 -0400 Received: from eggs.gnu.org ([209.51.188.92]:41284) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTgIM-00080J-Gj for qemu-devel@nongnu.org; Thu, 23 May 2019 01:29:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTgII-0005hN-NL for qemu-devel@nongnu.org; Thu, 23 May 2019 01:29:38 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:52941) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hTgIF-0005em-EA; Thu, 23 May 2019 01:29:33 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 458dNL3ZWLz9s6w; Thu, 23 May 2019 15:29:21 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1558589362; bh=gs+yX4Rpc3mi9205nXqZ5YZPkPALH1nmnc7QtQ5Y84A=; h=From:To:Cc:Subject:Date:From; b=fxy8AIYOGyegWUqWWNpsPQ3AOOh1inQeTIlpQLQRXe0iAFYAfMhQOiFTgljOILKr/ IFp2619X0l04Gy9kIFREYk/ORU1TiJMz0xj3LIzfM0tNOnTr/cN2u3Jtdeb8EPQfza 4pVY32c/oEX4+us5pwW3IzZHLmcpuWXFVqpybwpU= From: David Gibson To: qemu-ppc@nongnu.org Date: Thu, 23 May 2019 15:29:11 +1000 Message-Id: <20190523052918.1129-1-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2401:3900:2:1::2 Subject: [Qemu-devel] [PATCH 1/8] spapr: Clean up device node name generation for PCI devices X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mst@redhat.com, qemu-devel@nongnu.org, groug@kaod.org, clg@kaod.org, mdroth@linux.ibm.com, David Gibson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP spapr_populate_pci_child_dt() adds a 'name' property to the device tree node for PCI devices. This is never necessary for a flattened device tree, it is implicit in the name added when the node is constructed. In fact anything we do add to a 'name' property will be overwritten with something derived from the structural name in the guest firmware (but in fact it is exactly the same bytes). So, remove that. In addition, pci_get_node_name() is very simple, so fold it into its (also simple) sole caller spapr_create_pci_child_dt(). While we're there rename pci_find_device_name() to the shorter and more accurate dt_name_from_class(). Signed-off-by: David Gibson Reviewed-by: Greg Kurz Acked-by: Michael S. Tsirkin --- hw/ppc/spapr_pci.c | 43 +++++++++++++++++-------------------------- 1 file changed, 17 insertions(+), 26 deletions(-) diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c index 97961b0128..b2db46ef1d 100644 --- a/hw/ppc/spapr_pci.c +++ b/hw/ppc/spapr_pci.c @@ -1173,8 +1173,8 @@ static const PCIClass pci_classes[] = { { "data-processing-controller", spc_subclass }, }; -static const char *pci_find_device_name(uint8_t class, uint8_t subclass, - uint8_t iface) +static const char *dt_name_from_class(uint8_t class, uint8_t subclass, + uint8_t iface) { const PCIClass *pclass; const PCISubClass *psubclass; @@ -1216,23 +1216,6 @@ static const char *pci_find_device_name(uint8_t class, uint8_t subclass, return name; } -static gchar *pci_get_node_name(PCIDevice *dev) -{ - int slot = PCI_SLOT(dev->devfn); - int func = PCI_FUNC(dev->devfn); - uint32_t ccode = pci_default_read_config(dev, PCI_CLASS_PROG, 3); - const char *name; - - name = pci_find_device_name((ccode >> 16) & 0xff, (ccode >> 8) & 0xff, - ccode & 0xff); - - if (func != 0) { - return g_strdup_printf("%s@%x,%x", name, slot, func); - } else { - return g_strdup_printf("%s@%x", name, slot); - } -} - static uint32_t spapr_phb_get_pci_drc_index(SpaprPhbState *phb, PCIDevice *pdev); @@ -1300,11 +1283,6 @@ static void spapr_populate_pci_child_dt(PCIDevice *dev, void *fdt, int offset, _FDT(fdt_setprop(fdt, offset, "udf-supported", NULL, 0)); } - _FDT(fdt_setprop_string(fdt, offset, "name", - pci_find_device_name((ccode >> 16) & 0xff, - (ccode >> 8) & 0xff, - ccode & 0xff))); - buf = spapr_phb_get_loc_code(sphb, dev); _FDT(fdt_setprop_string(fdt, offset, "ibm,loc-code", buf)); g_free(buf); @@ -1348,10 +1326,23 @@ static int spapr_create_pci_child_dt(SpaprPhbState *phb, PCIDevice *dev, void *fdt, int node_offset) { int offset; - gchar *nodename; + const gchar *basename; + char *nodename; + int slot = PCI_SLOT(dev->devfn); + int func = PCI_FUNC(dev->devfn); + uint32_t ccode = pci_default_read_config(dev, PCI_CLASS_PROG, 3); + + basename = dt_name_from_class((ccode >> 16) & 0xff, (ccode >> 8) & 0xff, + ccode & 0xff); + + if (func != 0) { + nodename = g_strdup_printf("%s@%x,%x", basename, slot, func); + } else { + nodename = g_strdup_printf("%s@%x", basename, slot); + } - nodename = pci_get_node_name(dev); _FDT(offset = fdt_add_subnode(fdt, node_offset, nodename)); + g_free(nodename); spapr_populate_pci_child_dt(dev, fdt, offset, phb); From patchwork Thu May 23 05:29:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gibson X-Patchwork-Id: 10956911 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 115C0112C for ; Thu, 23 May 2019 05:37:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DB94527F89 for ; Thu, 23 May 2019 05:37:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C8ED827FC0; Thu, 23 May 2019 05:37:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B880F27F89 for ; Thu, 23 May 2019 05:37:35 +0000 (UTC) Received: from localhost ([127.0.0.1]:58010 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTgQ3-0005OK-22 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 23 May 2019 01:37:35 -0400 Received: from eggs.gnu.org ([209.51.188.92]:41257) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTgIK-00080I-QL for qemu-devel@nongnu.org; Thu, 23 May 2019 01:29:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTgII-0005hk-U8 for qemu-devel@nongnu.org; Thu, 23 May 2019 01:29:36 -0400 Received: from bilbo.ozlabs.org ([2401:3900:2:1::2]:47945 helo=ozlabs.org) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hTgIH-0005eu-3G; Thu, 23 May 2019 01:29:34 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 458dNL5hBBz9s3l; Thu, 23 May 2019 15:29:22 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1558589362; bh=6fqGLI8ZRatU3Q/dmXpXtP9f7RvLplVbARfRl18Pp9A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ip2G9e4ocpSWn57EaavBZnU1sHRK5yhhmpPhbPwLSVbOM+TlJ/pMBwHIegCR1K++m 0Ad0oNeJzJk2JkLOTHEI2Y+sP9fULcJLWg4OuVrxaFaCOdlOdyyQhv50xKjMXzbJPt +RsvaQPONbtyAgyrt8WvOnYcEJDJYnzdEezuO85c= From: David Gibson To: qemu-ppc@nongnu.org Date: Thu, 23 May 2019 15:29:12 +1000 Message-Id: <20190523052918.1129-2-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190523052918.1129-1-david@gibson.dropbear.id.au> References: <20190523052918.1129-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2401:3900:2:1::2 Subject: [Qemu-devel] [PATCH 2/8] spapr: Clean up device tree construction for PCI devices X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mst@redhat.com, qemu-devel@nongnu.org, groug@kaod.org, clg@kaod.org, mdroth@linux.ibm.com, David Gibson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP spapr_create_pci_child_dt() is a trivial wrapper around spapr_populate_pci_child_dt(), but is the latter's only caller. So fold them together into spapr_dt_pci_device(), which closer matches our modern naming convention. While there, make a number of cleanups to the function itself. This is mostly using more temporary locals to avoid awkwardly long lines, and in some cases avoiding double reads of PCI config space variables. Signed-off-by: David Gibson Reviewed-by: Greg Kurz --- hw/ppc/spapr_pci.c | 119 +++++++++++++++++++++------------------------ 1 file changed, 55 insertions(+), 64 deletions(-) diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c index b2db46ef1d..4075b433fd 100644 --- a/hw/ppc/spapr_pci.c +++ b/hw/ppc/spapr_pci.c @@ -1219,57 +1219,75 @@ static const char *dt_name_from_class(uint8_t class, uint8_t subclass, static uint32_t spapr_phb_get_pci_drc_index(SpaprPhbState *phb, PCIDevice *pdev); -static void spapr_populate_pci_child_dt(PCIDevice *dev, void *fdt, int offset, - SpaprPhbState *sphb) +/* create OF node for pci device and required OF DT properties */ +static int spapr_dt_pci_device(SpaprPhbState *sphb, PCIDevice *dev, + void *fdt, int parent_offset) { + int offset; + const gchar *basename; + char *nodename; + int slot = PCI_SLOT(dev->devfn); + int func = PCI_FUNC(dev->devfn); ResourceProps rp; - bool is_bridge = false; - int pci_status; - char *buf = NULL; uint32_t drc_index = spapr_phb_get_pci_drc_index(sphb, dev); + uint32_t header_type = pci_default_read_config(dev, PCI_HEADER_TYPE, 1); + bool is_bridge = (header_type == PCI_HEADER_TYPE_BRIDGE); + uint32_t vendor_id = pci_default_read_config(dev, PCI_VENDOR_ID, 2); + uint32_t device_id = pci_default_read_config(dev, PCI_DEVICE_ID, 2); + uint32_t revision_id = pci_default_read_config(dev, PCI_REVISION_ID, 1); uint32_t ccode = pci_default_read_config(dev, PCI_CLASS_PROG, 3); - uint32_t max_msi, max_msix; + uint32_t irq_pin = pci_default_read_config(dev, PCI_INTERRUPT_PIN, 1); + uint32_t subsystem_id = pci_default_read_config(dev, PCI_SUBSYSTEM_ID, 2); + uint32_t subsystem_vendor_id = + pci_default_read_config(dev, PCI_SUBSYSTEM_VENDOR_ID, 2); + uint32_t cache_line_size = + pci_default_read_config(dev, PCI_CACHE_LINE_SIZE, 1); + uint32_t pci_status = pci_default_read_config(dev, PCI_STATUS, 2); + gchar *loc_code; + + basename = dt_name_from_class((ccode >> 16) & 0xff, (ccode >> 8) & 0xff, + ccode & 0xff); - if (pci_default_read_config(dev, PCI_HEADER_TYPE, 1) == - PCI_HEADER_TYPE_BRIDGE) { - is_bridge = true; + if (func != 0) { + nodename = g_strdup_printf("%s@%x,%x", basename, slot, func); + } else { + nodename = g_strdup_printf("%s@%x", basename, slot); } + _FDT(offset = fdt_add_subnode(fdt, parent_offset, nodename)); + + g_free(nodename); + /* in accordance with PAPR+ v2.7 13.6.3, Table 181 */ - _FDT(fdt_setprop_cell(fdt, offset, "vendor-id", - pci_default_read_config(dev, PCI_VENDOR_ID, 2))); - _FDT(fdt_setprop_cell(fdt, offset, "device-id", - pci_default_read_config(dev, PCI_DEVICE_ID, 2))); - _FDT(fdt_setprop_cell(fdt, offset, "revision-id", - pci_default_read_config(dev, PCI_REVISION_ID, 1))); + _FDT(fdt_setprop_cell(fdt, offset, "vendor-id", vendor_id)); + _FDT(fdt_setprop_cell(fdt, offset, "device-id", device_id)); + _FDT(fdt_setprop_cell(fdt, offset, "revision-id", revision_id)); + _FDT(fdt_setprop_cell(fdt, offset, "class-code", ccode)); - if (pci_default_read_config(dev, PCI_INTERRUPT_PIN, 1)) { - _FDT(fdt_setprop_cell(fdt, offset, "interrupts", - pci_default_read_config(dev, PCI_INTERRUPT_PIN, 1))); + if (irq_pin) { + _FDT(fdt_setprop_cell(fdt, offset, "interrupts", irq_pin)); } if (!is_bridge) { - _FDT(fdt_setprop_cell(fdt, offset, "min-grant", - pci_default_read_config(dev, PCI_MIN_GNT, 1))); - _FDT(fdt_setprop_cell(fdt, offset, "max-latency", - pci_default_read_config(dev, PCI_MAX_LAT, 1))); + uint32_t min_grant = pci_default_read_config(dev, PCI_MIN_GNT, 1); + uint32_t max_latency = pci_default_read_config(dev, PCI_MAX_LAT, 1); + _FDT(fdt_setprop_cell(fdt, offset, "min-grant", min_grant)); + _FDT(fdt_setprop_cell(fdt, offset, "max-latency", max_latency)); } - if (pci_default_read_config(dev, PCI_SUBSYSTEM_ID, 2)) { - _FDT(fdt_setprop_cell(fdt, offset, "subsystem-id", - pci_default_read_config(dev, PCI_SUBSYSTEM_ID, 2))); + if (subsystem_id) { + _FDT(fdt_setprop_cell(fdt, offset, "subsystem-id", subsystem_id)); } - if (pci_default_read_config(dev, PCI_SUBSYSTEM_VENDOR_ID, 2)) { + if (subsystem_vendor_id) { _FDT(fdt_setprop_cell(fdt, offset, "subsystem-vendor-id", - pci_default_read_config(dev, PCI_SUBSYSTEM_VENDOR_ID, 2))); + subsystem_vendor_id)); } - _FDT(fdt_setprop_cell(fdt, offset, "cache-line-size", - pci_default_read_config(dev, PCI_CACHE_LINE_SIZE, 1))); + _FDT(fdt_setprop_cell(fdt, offset, "cache-line-size", cache_line_size)); + /* the following fdt cells are masked off the pci status register */ - pci_status = pci_default_read_config(dev, PCI_STATUS, 2); _FDT(fdt_setprop_cell(fdt, offset, "devsel-speed", PCI_STATUS_DEVSEL_MASK & pci_status)); @@ -1283,9 +1301,9 @@ static void spapr_populate_pci_child_dt(PCIDevice *dev, void *fdt, int offset, _FDT(fdt_setprop(fdt, offset, "udf-supported", NULL, 0)); } - buf = spapr_phb_get_loc_code(sphb, dev); - _FDT(fdt_setprop_string(fdt, offset, "ibm,loc-code", buf)); - g_free(buf); + loc_code = spapr_phb_get_loc_code(sphb, dev); + _FDT(fdt_setprop_string(fdt, offset, "ibm,loc-code", loc_code)); + g_free(loc_code); if (drc_index) { _FDT(fdt_setprop_cell(fdt, offset, "ibm,my-drc-index", drc_index)); @@ -1297,13 +1315,13 @@ static void spapr_populate_pci_child_dt(PCIDevice *dev, void *fdt, int offset, RESOURCE_CELLS_SIZE)); if (msi_present(dev)) { - max_msi = msi_nr_vectors_allocated(dev); + uint32_t max_msi = msi_nr_vectors_allocated(dev); if (max_msi) { _FDT(fdt_setprop_cell(fdt, offset, "ibm,req#msi", max_msi)); } } if (msix_present(dev)) { - max_msix = dev->msix_entries_nr; + uint32_t max_msix = dev->msix_entries_nr; if (max_msix) { _FDT(fdt_setprop_cell(fdt, offset, "ibm,req#msi-x", max_msix)); } @@ -1319,33 +1337,6 @@ static void spapr_populate_pci_child_dt(PCIDevice *dev, void *fdt, int offset, } spapr_phb_nvgpu_populate_pcidev_dt(dev, fdt, offset, sphb); -} - -/* create OF node for pci device and required OF DT properties */ -static int spapr_create_pci_child_dt(SpaprPhbState *phb, PCIDevice *dev, - void *fdt, int node_offset) -{ - int offset; - const gchar *basename; - char *nodename; - int slot = PCI_SLOT(dev->devfn); - int func = PCI_FUNC(dev->devfn); - uint32_t ccode = pci_default_read_config(dev, PCI_CLASS_PROG, 3); - - basename = dt_name_from_class((ccode >> 16) & 0xff, (ccode >> 8) & 0xff, - ccode & 0xff); - - if (func != 0) { - nodename = g_strdup_printf("%s@%x,%x", basename, slot, func); - } else { - nodename = g_strdup_printf("%s@%x", basename, slot); - } - - _FDT(offset = fdt_add_subnode(fdt, node_offset, nodename)); - - g_free(nodename); - - spapr_populate_pci_child_dt(dev, fdt, offset, phb); return offset; } @@ -1393,7 +1384,7 @@ int spapr_pci_dt_populate(SpaprDrc *drc, SpaprMachineState *spapr, SpaprPhbState *sphb = SPAPR_PCI_HOST_BRIDGE(plug_handler); PCIDevice *pdev = PCI_DEVICE(drc->dev); - *fdt_start_offset = spapr_create_pci_child_dt(sphb, pdev, fdt, 0); + *fdt_start_offset = spapr_dt_pci_device(sphb, pdev, fdt, 0); return 0; } @@ -2086,7 +2077,7 @@ static void spapr_populate_pci_devices_dt(PCIBus *bus, PCIDevice *pdev, int offset; SpaprFdt s_fdt; - offset = spapr_create_pci_child_dt(p->sphb, pdev, p->fdt, p->node_off); + offset = spapr_dt_pci_device(p->sphb, pdev, p->fdt, p->node_off); if (!offset) { error_report("Failed to create pci child device tree node"); return; From patchwork Thu May 23 05:29:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gibson X-Patchwork-Id: 10956897 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6AD66112C for ; Thu, 23 May 2019 05:31:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3862D27FA8 for ; Thu, 23 May 2019 05:31:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2C96E27FC0; Thu, 23 May 2019 05:31:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C0F8627FA8 for ; Thu, 23 May 2019 05:31:13 +0000 (UTC) Received: from localhost ([127.0.0.1]:57924 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTgJs-0000pf-GG for patchwork-qemu-devel@patchwork.kernel.org; Thu, 23 May 2019 01:31:12 -0400 Received: from eggs.gnu.org ([209.51.188.92]:41252) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTgIK-00080G-PN for qemu-devel@nongnu.org; Thu, 23 May 2019 01:29:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTgII-0005hD-Mi for qemu-devel@nongnu.org; Thu, 23 May 2019 01:29:36 -0400 Received: from ozlabs.org ([203.11.71.1]:54665) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hTgIF-0005eS-8E; Thu, 23 May 2019 01:29:33 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 458dNL6gYjz9s9T; Thu, 23 May 2019 15:29:22 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1558589362; bh=++2hRuLAmTthhYEBcebKO3KnjRkOhQh3lcruno8xPDk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z/Oa4ynimzhi/Q8KW2O4tgQXnaoXXpLe5PBSp9dQMRnoubij9iS6pAJhhzWEGpTzw unR2a5pY6pE4JC9FFEcLQ/gpMO9jLY50bKCL1O4TRTDB1FfEpoY7sB+K0C/A2tLdyu 3mdH1gzm1tgvSVGNSL39dxp9m2arncfTa+iijXL0= From: David Gibson To: qemu-ppc@nongnu.org Date: Thu, 23 May 2019 15:29:13 +1000 Message-Id: <20190523052918.1129-3-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190523052918.1129-1-david@gibson.dropbear.id.au> References: <20190523052918.1129-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 203.11.71.1 Subject: [Qemu-devel] [PATCH 3/8] spapr: Clean up dt creation for PCI buses X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mst@redhat.com, qemu-devel@nongnu.org, groug@kaod.org, clg@kaod.org, mdroth@linux.ibm.com, David Gibson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Device nodes for PCI bridges (both host and P2P) describe both the bridge device itself and the bus hanging off it, handling of this is a bit of a mess. spapr_dt_pci_device() has a few things it only adds for non-bridges, but always adds #address-cells and #size-cells which should only appear for bridges. But the walking down the subordinate PCI bus is done in one of its callers spapr_populate_pci_devices_dt(). The PHB dt creation in spapr_populate_pci_dt() open codes some similar logic to the bridge case. This patch consolidates things in a bunch of ways: * Bus specific dt info is now created in spapr_dt_pci_bus() used for both P2P bridges and the host bridge. This includes walking subordinate devices * spapr_dt_pci_device() now calls spapr_dt_pci_bus() when called on a P2P bridge * We do detection of bridges with the is_bridge field of the device class, rather than checking PCI config space directly, for consistency with qemu's core PCI code. * Several things are renamed for brevity and clarity Signed-off-by: David Gibson --- hw/ppc/spapr.c | 7 +- hw/ppc/spapr_pci.c | 140 +++++++++++++++++++----------------- include/hw/pci-host/spapr.h | 4 +- 3 files changed, 79 insertions(+), 72 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index e2b33e5890..44573adce7 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -1309,8 +1309,7 @@ static void *spapr_build_fdt(SpaprMachineState *spapr) } QLIST_FOREACH(phb, &spapr->phbs, list) { - ret = spapr_populate_pci_dt(phb, PHANDLE_INTC, fdt, - spapr->irq->nr_msis, NULL); + ret = spapr_dt_phb(phb, PHANDLE_INTC, fdt, spapr->irq->nr_msis, NULL); if (ret < 0) { error_report("couldn't setup PCI devices in fdt"); exit(1); @@ -3917,8 +3916,8 @@ int spapr_phb_dt_populate(SpaprDrc *drc, SpaprMachineState *spapr, return -1; } - if (spapr_populate_pci_dt(sphb, intc_phandle, fdt, spapr->irq->nr_msis, - fdt_start_offset)) { + if (spapr_dt_phb(sphb, intc_phandle, fdt, spapr->irq->nr_msis, + fdt_start_offset)) { error_setg(errp, "unable to create FDT node for PHB %d", sphb->index); return -1; } diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c index 4075b433fd..c166df4145 100644 --- a/hw/ppc/spapr_pci.c +++ b/hw/ppc/spapr_pci.c @@ -1219,6 +1219,60 @@ static const char *dt_name_from_class(uint8_t class, uint8_t subclass, static uint32_t spapr_phb_get_pci_drc_index(SpaprPhbState *phb, PCIDevice *pdev); +typedef struct PciWalkFdt { + void *fdt; + int offset; + SpaprPhbState *sphb; + int err; +} PciWalkFdt; + +static int spapr_dt_pci_device(SpaprPhbState *sphb, PCIDevice *dev, + void *fdt, int parent_offset); + +static void spapr_dt_pci_device_cb(PCIBus *bus, PCIDevice *pdev, + void *opaque) +{ + PciWalkFdt *p = opaque; + int err; + + if (p->err) { + /* Something's already broken, don't keep going */ + return; + } + + err = spapr_dt_pci_device(p->sphb, pdev, p->fdt, p->offset); + if (err < 0) { + p->err = err; + } +} + +/* Augment PCI device node with bridge specific information */ +static int spapr_dt_pci_bus(SpaprPhbState *sphb, PCIBus *bus, + void *fdt, int offset) +{ + PciWalkFdt cbinfo = { + .fdt = fdt, + .offset = offset, + .sphb = sphb, + .err = 0, + }; + + _FDT(fdt_setprop_cell(fdt, offset, "#address-cells", + RESOURCE_CELLS_ADDRESS)); + _FDT(fdt_setprop_cell(fdt, offset, "#size-cells", + RESOURCE_CELLS_SIZE)); + + if (bus) { + pci_for_each_device_reverse(bus, pci_bus_num(bus), + spapr_dt_pci_device_cb, &cbinfo); + if (cbinfo.err) { + return cbinfo.err; + } + } + + return offset; +} + /* create OF node for pci device and required OF DT properties */ static int spapr_dt_pci_device(SpaprPhbState *sphb, PCIDevice *dev, void *fdt, int parent_offset) @@ -1228,10 +1282,9 @@ static int spapr_dt_pci_device(SpaprPhbState *sphb, PCIDevice *dev, char *nodename; int slot = PCI_SLOT(dev->devfn); int func = PCI_FUNC(dev->devfn); + PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(dev); ResourceProps rp; uint32_t drc_index = spapr_phb_get_pci_drc_index(sphb, dev); - uint32_t header_type = pci_default_read_config(dev, PCI_HEADER_TYPE, 1); - bool is_bridge = (header_type == PCI_HEADER_TYPE_BRIDGE); uint32_t vendor_id = pci_default_read_config(dev, PCI_VENDOR_ID, 2); uint32_t device_id = pci_default_read_config(dev, PCI_DEVICE_ID, 2); uint32_t revision_id = pci_default_read_config(dev, PCI_REVISION_ID, 1); @@ -1268,13 +1321,6 @@ static int spapr_dt_pci_device(SpaprPhbState *sphb, PCIDevice *dev, _FDT(fdt_setprop_cell(fdt, offset, "interrupts", irq_pin)); } - if (!is_bridge) { - uint32_t min_grant = pci_default_read_config(dev, PCI_MIN_GNT, 1); - uint32_t max_latency = pci_default_read_config(dev, PCI_MAX_LAT, 1); - _FDT(fdt_setprop_cell(fdt, offset, "min-grant", min_grant)); - _FDT(fdt_setprop_cell(fdt, offset, "max-latency", max_latency)); - } - if (subsystem_id) { _FDT(fdt_setprop_cell(fdt, offset, "subsystem-id", subsystem_id)); } @@ -1309,11 +1355,6 @@ static int spapr_dt_pci_device(SpaprPhbState *sphb, PCIDevice *dev, _FDT(fdt_setprop_cell(fdt, offset, "ibm,my-drc-index", drc_index)); } - _FDT(fdt_setprop_cell(fdt, offset, "#address-cells", - RESOURCE_CELLS_ADDRESS)); - _FDT(fdt_setprop_cell(fdt, offset, "#size-cells", - RESOURCE_CELLS_SIZE)); - if (msi_present(dev)) { uint32_t max_msi = msi_nr_vectors_allocated(dev); if (max_msi) { @@ -1338,7 +1379,18 @@ static int spapr_dt_pci_device(SpaprPhbState *sphb, PCIDevice *dev, spapr_phb_nvgpu_populate_pcidev_dt(dev, fdt, offset, sphb); - return offset; + if (!pc->is_bridge) { + /* Properties only for non-bridges */ + uint32_t min_grant = pci_default_read_config(dev, PCI_MIN_GNT, 1); + uint32_t max_latency = pci_default_read_config(dev, PCI_MAX_LAT, 1); + _FDT(fdt_setprop_cell(fdt, offset, "min-grant", min_grant)); + _FDT(fdt_setprop_cell(fdt, offset, "max-latency", max_latency)); + return offset; + } else { + PCIBus *sec_bus = pci_bridge_get_sec_bus(PCI_BRIDGE(dev)); + + return spapr_dt_pci_bus(sphb, sec_bus, fdt, offset); + } } /* Callback to be called during DRC release. */ @@ -2063,44 +2115,6 @@ static const TypeInfo spapr_phb_info = { } }; -typedef struct SpaprFdt { - void *fdt; - int node_off; - SpaprPhbState *sphb; -} SpaprFdt; - -static void spapr_populate_pci_devices_dt(PCIBus *bus, PCIDevice *pdev, - void *opaque) -{ - PCIBus *sec_bus; - SpaprFdt *p = opaque; - int offset; - SpaprFdt s_fdt; - - offset = spapr_dt_pci_device(p->sphb, pdev, p->fdt, p->node_off); - if (!offset) { - error_report("Failed to create pci child device tree node"); - return; - } - - if ((pci_default_read_config(pdev, PCI_HEADER_TYPE, 1) != - PCI_HEADER_TYPE_BRIDGE)) { - return; - } - - sec_bus = pci_bridge_get_sec_bus(PCI_BRIDGE(pdev)); - if (!sec_bus) { - return; - } - - s_fdt.fdt = p->fdt; - s_fdt.node_off = offset; - s_fdt.sphb = p->sphb; - pci_for_each_device_reverse(sec_bus, pci_bus_num(sec_bus), - spapr_populate_pci_devices_dt, - &s_fdt); -} - static void spapr_phb_pci_enumerate_bridge(PCIBus *bus, PCIDevice *pdev, void *opaque) { @@ -2138,8 +2152,8 @@ static void spapr_phb_pci_enumerate(SpaprPhbState *phb) } -int spapr_populate_pci_dt(SpaprPhbState *phb, uint32_t intc_phandle, void *fdt, - uint32_t nr_msis, int *node_offset) +int spapr_dt_phb(SpaprPhbState *phb, uint32_t intc_phandle, void *fdt, + uint32_t nr_msis, int *node_offset) { int bus_off, i, j, ret; uint32_t bus_range[] = { cpu_to_be32(0), cpu_to_be32(0xff) }; @@ -2186,8 +2200,6 @@ int spapr_populate_pci_dt(SpaprPhbState *phb, uint32_t intc_phandle, void *fdt, cpu_to_be32(0x0), cpu_to_be32(phb->numa_node)}; SpaprTceTable *tcet; - PCIBus *bus = PCI_HOST_BRIDGE(phb)->bus; - SpaprFdt s_fdt; SpaprDrc *drc; Error *errp = NULL; @@ -2200,8 +2212,6 @@ int spapr_populate_pci_dt(SpaprPhbState *phb, uint32_t intc_phandle, void *fdt, /* Write PHB properties */ _FDT(fdt_setprop_string(fdt, bus_off, "device_type", "pci")); _FDT(fdt_setprop_string(fdt, bus_off, "compatible", "IBM,Logical_PHB")); - _FDT(fdt_setprop_cell(fdt, bus_off, "#address-cells", 0x3)); - _FDT(fdt_setprop_cell(fdt, bus_off, "#size-cells", 0x2)); _FDT(fdt_setprop_cell(fdt, bus_off, "#interrupt-cells", 0x1)); _FDT(fdt_setprop(fdt, bus_off, "used-by-rtas", NULL, 0)); _FDT(fdt_setprop(fdt, bus_off, "bus-range", &bus_range, sizeof(bus_range))); @@ -2266,13 +2276,11 @@ int spapr_populate_pci_dt(SpaprPhbState *phb, uint32_t intc_phandle, void *fdt, spapr_phb_pci_enumerate(phb); _FDT(fdt_setprop_cell(fdt, bus_off, "qemu,phb-enumerated", 0x1)); - /* Populate tree nodes with PCI devices attached */ - s_fdt.fdt = fdt; - s_fdt.node_off = bus_off; - s_fdt.sphb = phb; - pci_for_each_device_reverse(bus, pci_bus_num(bus), - spapr_populate_pci_devices_dt, - &s_fdt); + /* Walk the bridge and subordinate buses */ + ret = spapr_dt_pci_bus(phb, PCI_HOST_BRIDGE(phb)->bus, fdt, bus_off); + if (ret) { + return ret; + } ret = spapr_drc_populate_dt(fdt, bus_off, OBJECT(phb), SPAPR_DR_CONNECTOR_TYPE_PCI); diff --git a/include/hw/pci-host/spapr.h b/include/hw/pci-host/spapr.h index 53519c835e..1b61162f91 100644 --- a/include/hw/pci-host/spapr.h +++ b/include/hw/pci-host/spapr.h @@ -131,8 +131,8 @@ static inline qemu_irq spapr_phb_lsi_qirq(struct SpaprPhbState *phb, int pin) return spapr_qirq(spapr, phb->lsi_table[pin].irq); } -int spapr_populate_pci_dt(SpaprPhbState *phb, uint32_t intc_phandle, void *fdt, - uint32_t nr_msis, int *node_offset); +int spapr_dt_phb(SpaprPhbState *phb, uint32_t intc_phandle, void *fdt, + uint32_t nr_msis, int *node_offset); void spapr_pci_rtas_init(void); From patchwork Thu May 23 05:29:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gibson X-Patchwork-Id: 10956905 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5E3BD112C for ; Thu, 23 May 2019 05:34:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 33D7627FA8 for ; Thu, 23 May 2019 05:34:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 276FD27FB7; Thu, 23 May 2019 05:34:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9925227FA8 for ; Thu, 23 May 2019 05:34:17 +0000 (UTC) Received: from localhost ([127.0.0.1]:57956 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTgMq-0003IK-Uw for patchwork-qemu-devel@patchwork.kernel.org; Thu, 23 May 2019 01:34:16 -0400 Received: from eggs.gnu.org ([209.51.188.92]:41251) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTgIK-00080F-PI for qemu-devel@nongnu.org; Thu, 23 May 2019 01:29:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTgII-0005hU-P7 for qemu-devel@nongnu.org; Thu, 23 May 2019 01:29:36 -0400 Received: from bilbo.ozlabs.org ([2401:3900:2:1::2]:46377 helo=ozlabs.org) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hTgIG-0005eq-Sy; Thu, 23 May 2019 01:29:34 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 458dNM1cfDz9sBV; Thu, 23 May 2019 15:29:22 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1558589363; bh=wlcVpy0sbRd29hFk1MbdfxHd4sEwdHTcHO9jwTKHELc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ll88wXPaUY6Y0K9apcMfZbHyPEhPOulAbUL9qLVLSFukOqLYuCwigRelOw8vSEKgK f3qTh2pTxibYeowkPzOglxTJ2q9rMGsgfq3RBqAb7FjlSudHnvUPPuoP/bOPu7Pj0X Ry4lfljL8Zs0Q/UfeQqew6eM30sdpRmeO6L2GssI= From: David Gibson To: qemu-ppc@nongnu.org Date: Thu, 23 May 2019 15:29:14 +1000 Message-Id: <20190523052918.1129-4-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190523052918.1129-1-david@gibson.dropbear.id.au> References: <20190523052918.1129-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2401:3900:2:1::2 Subject: [Qemu-devel] [PATCH 4/8] spapr: Clean up spapr_drc_populate_dt() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mst@redhat.com, qemu-devel@nongnu.org, groug@kaod.org, clg@kaod.org, mdroth@linux.ibm.com, David Gibson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This makes some minor cleanups to spapr_drc_populate_dt(), renaming it to the shorter and more idiomatic spapr_dt_drc() along the way. Signed-off-by: David Gibson Reviewed-by: Greg Kurz --- hw/ppc/spapr.c | 7 +++---- hw/ppc/spapr_drc.c | 13 ++++++------- hw/ppc/spapr_pci.c | 3 +-- include/hw/ppc/spapr_drc.h | 3 +-- 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 44573adce7..507fd50dd5 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -1320,13 +1320,12 @@ static void *spapr_build_fdt(SpaprMachineState *spapr) spapr_populate_cpus_dt_node(fdt, spapr); if (smc->dr_lmb_enabled) { - _FDT(spapr_drc_populate_dt(fdt, 0, NULL, SPAPR_DR_CONNECTOR_TYPE_LMB)); + _FDT(spapr_dt_drc(fdt, 0, NULL, SPAPR_DR_CONNECTOR_TYPE_LMB)); } if (mc->has_hotpluggable_cpus) { int offset = fdt_path_offset(fdt, "/cpus"); - ret = spapr_drc_populate_dt(fdt, offset, NULL, - SPAPR_DR_CONNECTOR_TYPE_CPU); + ret = spapr_dt_drc(fdt, offset, NULL, SPAPR_DR_CONNECTOR_TYPE_CPU); if (ret < 0) { error_report("Couldn't set up CPU DR device tree properties"); exit(1); @@ -1363,7 +1362,7 @@ static void *spapr_build_fdt(SpaprMachineState *spapr) } if (smc->dr_phb_enabled) { - ret = spapr_drc_populate_dt(fdt, 0, NULL, SPAPR_DR_CONNECTOR_TYPE_PHB); + ret = spapr_dt_drc(fdt, 0, NULL, SPAPR_DR_CONNECTOR_TYPE_PHB); if (ret < 0) { error_report("Couldn't set up PHB DR device tree properties"); exit(1); diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c index 597f236b9c..bacadfcac5 100644 --- a/hw/ppc/spapr_drc.c +++ b/hw/ppc/spapr_drc.c @@ -781,7 +781,7 @@ SpaprDrc *spapr_drc_by_id(const char *type, uint32_t id) } /** - * spapr_drc_populate_dt + * spapr_dt_drc * * @fdt: libfdt device tree * @path: path in the DT to generate properties @@ -794,8 +794,7 @@ SpaprDrc *spapr_drc_by_id(const char *type, uint32_t id) * * as documented in PAPR+ v2.1, 13.5.2 */ -int spapr_drc_populate_dt(void *fdt, int fdt_offset, Object *owner, - uint32_t drc_type_mask) +int spapr_dt_drc(void *fdt, int offset, Object *owner, uint32_t drc_type_mask) { Object *root_container; ObjectProperty *prop; @@ -873,7 +872,7 @@ int spapr_drc_populate_dt(void *fdt, int fdt_offset, Object *owner, *(uint32_t *)drc_names->str = cpu_to_be32(drc_count); *(uint32_t *)drc_types->str = cpu_to_be32(drc_count); - ret = fdt_setprop(fdt, fdt_offset, "ibm,drc-indexes", + ret = fdt_setprop(fdt, offset, "ibm,drc-indexes", drc_indexes->data, drc_indexes->len * sizeof(uint32_t)); if (ret) { @@ -881,7 +880,7 @@ int spapr_drc_populate_dt(void *fdt, int fdt_offset, Object *owner, goto out; } - ret = fdt_setprop(fdt, fdt_offset, "ibm,drc-power-domains", + ret = fdt_setprop(fdt, offset, "ibm,drc-power-domains", drc_power_domains->data, drc_power_domains->len * sizeof(uint32_t)); if (ret) { @@ -889,14 +888,14 @@ int spapr_drc_populate_dt(void *fdt, int fdt_offset, Object *owner, goto out; } - ret = fdt_setprop(fdt, fdt_offset, "ibm,drc-names", + ret = fdt_setprop(fdt, offset, "ibm,drc-names", drc_names->str, drc_names->len); if (ret) { error_report("Couldn't finalize ibm,drc-names property"); goto out; } - ret = fdt_setprop(fdt, fdt_offset, "ibm,drc-types", + ret = fdt_setprop(fdt, offset, "ibm,drc-types", drc_types->str, drc_types->len); if (ret) { error_report("Couldn't finalize ibm,drc-types property"); diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c index c166df4145..04855d3125 100644 --- a/hw/ppc/spapr_pci.c +++ b/hw/ppc/spapr_pci.c @@ -2282,8 +2282,7 @@ int spapr_dt_phb(SpaprPhbState *phb, uint32_t intc_phandle, void *fdt, return ret; } - ret = spapr_drc_populate_dt(fdt, bus_off, OBJECT(phb), - SPAPR_DR_CONNECTOR_TYPE_PCI); + ret = spapr_dt_drc(fdt, bus_off, OBJECT(phb), SPAPR_DR_CONNECTOR_TYPE_PCI); if (ret) { return ret; } diff --git a/include/hw/ppc/spapr_drc.h b/include/hw/ppc/spapr_drc.h index fad0a887f9..c2c543a591 100644 --- a/include/hw/ppc/spapr_drc.h +++ b/include/hw/ppc/spapr_drc.h @@ -266,8 +266,7 @@ SpaprDrc *spapr_dr_connector_new(Object *owner, const char *type, uint32_t id); SpaprDrc *spapr_drc_by_index(uint32_t index); SpaprDrc *spapr_drc_by_id(const char *type, uint32_t id); -int spapr_drc_populate_dt(void *fdt, int fdt_offset, Object *owner, - uint32_t drc_type_mask); +int spapr_dt_drc(void *fdt, int offset, Object *owner, uint32_t drc_type_mask); void spapr_drc_attach(SpaprDrc *drc, DeviceState *d, Error **errp); void spapr_drc_detach(SpaprDrc *drc); From patchwork Thu May 23 05:29:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gibson X-Patchwork-Id: 10956899 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F2D3D112C for ; Thu, 23 May 2019 05:31:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CCD6E27FA8 for ; Thu, 23 May 2019 05:31:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BE46627FC0; Thu, 23 May 2019 05:31:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1B0F627FA8 for ; Thu, 23 May 2019 05:31:41 +0000 (UTC) Received: from localhost ([127.0.0.1]:57926 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTgKK-0001EY-9c for patchwork-qemu-devel@patchwork.kernel.org; Thu, 23 May 2019 01:31:40 -0400 Received: from eggs.gnu.org ([209.51.188.92]:41253) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTgIK-00080H-PS for qemu-devel@nongnu.org; Thu, 23 May 2019 01:29:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTgII-0005hH-Mz for qemu-devel@nongnu.org; Thu, 23 May 2019 01:29:36 -0400 Received: from ozlabs.org ([203.11.71.1]:38483) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hTgIF-0005eP-7q; Thu, 23 May 2019 01:29:33 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 458dNM0wh6z9s9y; Thu, 23 May 2019 15:29:22 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1558589363; bh=fT2wZ0CY2xyh0IA/lNK7JougwtDvFHGZG6nrpkSyQ+o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hzdMxLQ+jkCL/8c3CRoSQvq5rj6UAIBkyTVEavuaijHPk7aTiDNXWkg+aPhvm+Vkj zakt9yCvBEIoTaAbzzTj6ZC7oMVVzzC/2GVWvahlaUa8XaoiIiGYCQt3e5A2N7od// N4cUneahgwbGakGJpyDB2sk6cTxmGiXE77d9M7Jk= From: David Gibson To: qemu-ppc@nongnu.org Date: Thu, 23 May 2019 15:29:15 +1000 Message-Id: <20190523052918.1129-5-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190523052918.1129-1-david@gibson.dropbear.id.au> References: <20190523052918.1129-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 203.11.71.1 Subject: [Qemu-devel] [PATCH 5/8] spapr: Clean up DRC index construction X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mst@redhat.com, qemu-devel@nongnu.org, groug@kaod.org, clg@kaod.org, mdroth@linux.ibm.com, David Gibson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP spapr_pci.c currently has several confusingly similarly named functions for various conversions between representations of DRCs. Make things clearer by renaming things in a more consistent XXX_from_YYY() manner and remove some called-only-once variants in favour of open coding. While we're at it, move this code together in the file to avoid some extra forward references, and split out construction and removal of DRCs for the host bridge into helper functions. Signed-off-by: David Gibson --- hw/ppc/spapr_pci.c | 124 +++++++++++++++++++++++++-------------------- 1 file changed, 68 insertions(+), 56 deletions(-) diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c index 04855d3125..f799f8b423 100644 --- a/hw/ppc/spapr_pci.c +++ b/hw/ppc/spapr_pci.c @@ -1216,8 +1216,60 @@ static const char *dt_name_from_class(uint8_t class, uint8_t subclass, return name; } -static uint32_t spapr_phb_get_pci_drc_index(SpaprPhbState *phb, - PCIDevice *pdev); +/* + * DRC helper functions + */ + +static uint32_t drc_id_from_devfn(SpaprPhbState *phb, + uint32_t busnr, + int32_t devfn) +{ + return (phb->index << 16) | (busnr << 8) | devfn; +} + +static SpaprDrc *drc_from_devfn(SpaprPhbState *phb, + uint32_t busnr, int32_t devfn) +{ + return spapr_drc_by_id(TYPE_SPAPR_DRC_PCI, + drc_id_from_devfn(phb, busnr, devfn)); +} + +static SpaprDrc *drc_from_dev(SpaprPhbState *phb, PCIDevice *dev) +{ + uint32_t busnr = pci_bus_num(PCI_BUS(qdev_get_parent_bus(DEVICE(dev)))); + return drc_from_devfn(phb, busnr, dev->devfn); +} + +static void add_drcs(SpaprPhbState *phb) +{ + int i; + + if (!phb->dr_enabled) { + return; + } + + for (i = 0; i < PCI_SLOT_MAX * PCI_FUNC_MAX; i++) { + spapr_dr_connector_new(OBJECT(phb), TYPE_SPAPR_DRC_PCI, + drc_id_from_devfn(phb, 0, i)); + } +} + +static void remove_drcs(SpaprPhbState *phb) +{ + int i; + + if (!phb->dr_enabled) { + return; + } + + for (i = PCI_SLOT_MAX * PCI_FUNC_MAX - 1; i >= 0; i--) { + SpaprDrc *drc = drc_from_devfn(phb, 0, i); + + if (drc) { + object_unparent(OBJECT(drc)); + } + } +} typedef struct PciWalkFdt { void *fdt; @@ -1284,7 +1336,7 @@ static int spapr_dt_pci_device(SpaprPhbState *sphb, PCIDevice *dev, int func = PCI_FUNC(dev->devfn); PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(dev); ResourceProps rp; - uint32_t drc_index = spapr_phb_get_pci_drc_index(sphb, dev); + SpaprDrc *drc = drc_from_dev(sphb, dev); uint32_t vendor_id = pci_default_read_config(dev, PCI_VENDOR_ID, 2); uint32_t device_id = pci_default_read_config(dev, PCI_DEVICE_ID, 2); uint32_t revision_id = pci_default_read_config(dev, PCI_REVISION_ID, 1); @@ -1351,8 +1403,9 @@ static int spapr_dt_pci_device(SpaprPhbState *sphb, PCIDevice *dev, _FDT(fdt_setprop_string(fdt, offset, "ibm,loc-code", loc_code)); g_free(loc_code); - if (drc_index) { - _FDT(fdt_setprop_cell(fdt, offset, "ibm,my-drc-index", drc_index)); + if (drc) { + _FDT(fdt_setprop_cell(fdt, offset, "ibm,my-drc-index", + spapr_drc_index(drc))); } if (msi_present(dev)) { @@ -1402,33 +1455,6 @@ void spapr_phb_remove_pci_device_cb(DeviceState *dev) object_unparent(OBJECT(dev)); } -static SpaprDrc *spapr_phb_get_pci_func_drc(SpaprPhbState *phb, - uint32_t busnr, - int32_t devfn) -{ - return spapr_drc_by_id(TYPE_SPAPR_DRC_PCI, - (phb->index << 16) | (busnr << 8) | devfn); -} - -static SpaprDrc *spapr_phb_get_pci_drc(SpaprPhbState *phb, - PCIDevice *pdev) -{ - uint32_t busnr = pci_bus_num(PCI_BUS(qdev_get_parent_bus(DEVICE(pdev)))); - return spapr_phb_get_pci_func_drc(phb, busnr, pdev->devfn); -} - -static uint32_t spapr_phb_get_pci_drc_index(SpaprPhbState *phb, - PCIDevice *pdev) -{ - SpaprDrc *drc = spapr_phb_get_pci_drc(phb, pdev); - - if (!drc) { - return 0; - } - - return spapr_drc_index(drc); -} - int spapr_pci_dt_populate(SpaprDrc *drc, SpaprMachineState *spapr, void *fdt, int *fdt_start_offset, Error **errp) { @@ -1445,7 +1471,7 @@ static void spapr_pci_plug(HotplugHandler *plug_handler, { SpaprPhbState *phb = SPAPR_PCI_HOST_BRIDGE(DEVICE(plug_handler)); PCIDevice *pdev = PCI_DEVICE(plugged_dev); - SpaprDrc *drc = spapr_phb_get_pci_drc(phb, pdev); + SpaprDrc *drc = drc_from_dev(phb, pdev); Error *local_err = NULL; PCIBus *bus = PCI_BUS(qdev_get_parent_bus(DEVICE(pdev))); uint32_t slotnr = PCI_SLOT(pdev->devfn); @@ -1496,8 +1522,8 @@ static void spapr_pci_plug(HotplugHandler *plug_handler, SpaprDrcClass *func_drck; SpaprDREntitySense state; - func_drc = spapr_phb_get_pci_func_drc(phb, pci_bus_num(bus), - PCI_DEVFN(slotnr, i)); + func_drc = drc_from_devfn(phb, pci_bus_num(bus), + PCI_DEVFN(slotnr, i)); func_drck = SPAPR_DR_CONNECTOR_GET_CLASS(func_drc); state = func_drck->dr_entity_sense(func_drc); @@ -1533,7 +1559,7 @@ static void spapr_pci_unplug_request(HotplugHandler *plug_handler, { SpaprPhbState *phb = SPAPR_PCI_HOST_BRIDGE(DEVICE(plug_handler)); PCIDevice *pdev = PCI_DEVICE(plugged_dev); - SpaprDrc *drc = spapr_phb_get_pci_drc(phb, pdev); + SpaprDrc *drc = drc_from_dev(phb, pdev); if (!phb->dr_enabled) { error_setg(errp, QERR_BUS_NO_HOTPLUG, @@ -1555,8 +1581,8 @@ static void spapr_pci_unplug_request(HotplugHandler *plug_handler, /* ensure any other present functions are pending unplug */ if (PCI_FUNC(pdev->devfn) == 0) { for (i = 1; i < 8; i++) { - func_drc = spapr_phb_get_pci_func_drc(phb, pci_bus_num(bus), - PCI_DEVFN(slotnr, i)); + func_drc = drc_from_devfn(phb, pci_bus_num(bus), + PCI_DEVFN(slotnr, i)); func_drck = SPAPR_DR_CONNECTOR_GET_CLASS(func_drc); state = func_drck->dr_entity_sense(func_drc); if (state == SPAPR_DR_ENTITY_SENSE_PRESENT @@ -1577,8 +1603,8 @@ static void spapr_pci_unplug_request(HotplugHandler *plug_handler, */ if (PCI_FUNC(pdev->devfn) == 0) { for (i = 7; i >= 0; i--) { - func_drc = spapr_phb_get_pci_func_drc(phb, pci_bus_num(bus), - PCI_DEVFN(slotnr, i)); + func_drc = drc_from_devfn(phb, pci_bus_num(bus), + PCI_DEVFN(slotnr, i)); func_drck = SPAPR_DR_CONNECTOR_GET_CLASS(func_drc); state = func_drck->dr_entity_sense(func_drc); if (state == SPAPR_DR_ENTITY_SENSE_PRESENT) { @@ -1626,16 +1652,7 @@ static void spapr_phb_unrealize(DeviceState *dev, Error **errp) } } - if (sphb->dr_enabled) { - for (i = PCI_SLOT_MAX * 8 - 1; i >= 0; i--) { - SpaprDrc *drc = spapr_drc_by_id(TYPE_SPAPR_DRC_PCI, - (sphb->index << 16) | i); - - if (drc) { - object_unparent(OBJECT(drc)); - } - } - } + remove_drcs(sphb); for (i = PCI_NUM_PINS - 1; i >= 0; i--) { if (sphb->lsi_table[i].irq) { @@ -1861,12 +1878,7 @@ static void spapr_phb_realize(DeviceState *dev, Error **errp) } /* allocate connectors for child PCI devices */ - if (sphb->dr_enabled) { - for (i = 0; i < PCI_SLOT_MAX * 8; i++) { - spapr_dr_connector_new(OBJECT(phb), TYPE_SPAPR_DRC_PCI, - (sphb->index << 16) | i); - } - } + add_drcs(sphb); /* DMA setup */ for (i = 0; i < windows_supported; ++i) { From patchwork Thu May 23 05:29:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gibson X-Patchwork-Id: 10956903 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 699D515A6 for ; Thu, 23 May 2019 05:31:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 44EC827FC0 for ; Thu, 23 May 2019 05:31:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2FDC227FA9; Thu, 23 May 2019 05:31:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 99B1C27FB7 for ; Thu, 23 May 2019 05:31:48 +0000 (UTC) Received: from localhost ([127.0.0.1]:57930 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTgKR-0001Ub-T4 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 23 May 2019 01:31:47 -0400 Received: from eggs.gnu.org ([209.51.188.92]:41345) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTgIQ-00080l-GW for qemu-devel@nongnu.org; Thu, 23 May 2019 01:29:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTgIN-0005kK-Ea for qemu-devel@nongnu.org; Thu, 23 May 2019 01:29:42 -0400 Received: from ozlabs.org ([203.11.71.1]:55457) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hTgIK-0005hr-QO; Thu, 23 May 2019 01:29:38 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 458dNM2dFzz9sBK; Thu, 23 May 2019 15:29:23 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1558589363; bh=ClDTaKnH+f6JP4SlotEDr0uf2Ec7eFg7MaLVeZqMCSw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ThgBYcANrgD5S92UOI4LzaKOWnrq7xfAhmIFmQgbocJG7c3FNZgCZuAVzZCNtSnSt sq1y8FpEm4nPpkDF+UmQ/6dcBW1LRcAsDN1m2e4+qw9mePZoY64THUT2UElu4XDLD/ XE3+3E9y9b0S+94IdWYMD9dh3lQva7HEvBawk8Xk= From: David Gibson To: qemu-ppc@nongnu.org Date: Thu, 23 May 2019 15:29:16 +1000 Message-Id: <20190523052918.1129-6-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190523052918.1129-1-david@gibson.dropbear.id.au> References: <20190523052918.1129-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 203.11.71.1 Subject: [Qemu-devel] [PATCH 6/8] spapr: Don't use bus number for building DRC ids X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mst@redhat.com, qemu-devel@nongnu.org, groug@kaod.org, clg@kaod.org, mdroth@linux.ibm.com, David Gibson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP DRC ids are more or less arbitrary, as long as they're consistent. For PCI, we notionally build them from the phb's index along with PCI bus number, slot and function number. Using bus number is broken, however, because it can change if the guest re-enumerates the PCI topology for whatever reason (e.g. due to hotplug of a bridge, which we don't support yet but want to). Fortunately, there's an alternative. Bridges are required to have a unique non-zero "chassis number" that we can use instead. Adjust the code to use that instead. This looks like it would introduce a guest visible breaking change, but in fact it does not because we don't yet ever use non-zero bus numbers. Both chassis and bus number are always 0 for the root bus, so there's no change for the existing cases. Signed-off-by: David Gibson --- hw/ppc/spapr_pci.c | 54 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 40 insertions(+), 14 deletions(-) diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c index f799f8b423..94691fcfc2 100644 --- a/hw/ppc/spapr_pci.c +++ b/hw/ppc/spapr_pci.c @@ -1221,23 +1221,40 @@ static const char *dt_name_from_class(uint8_t class, uint8_t subclass, */ static uint32_t drc_id_from_devfn(SpaprPhbState *phb, - uint32_t busnr, - int32_t devfn) + uint8_t chassis, int32_t devfn) { - return (phb->index << 16) | (busnr << 8) | devfn; + return (phb->index << 16) | (chassis << 8) | devfn; } static SpaprDrc *drc_from_devfn(SpaprPhbState *phb, - uint32_t busnr, int32_t devfn) + uint8_t chassis, int32_t devfn) { return spapr_drc_by_id(TYPE_SPAPR_DRC_PCI, - drc_id_from_devfn(phb, busnr, devfn)); + drc_id_from_devfn(phb, chassis, devfn)); +} + +static uint8_t chassis_from_bus(PCIBus *bus, Error **errp) +{ + if (pci_bus_is_root(bus)) { + return 0; + } else { + PCIDevice *bridge = pci_bridge_get_device(bus); + + return object_property_get_uint(OBJECT(bridge), "chassis_nr", errp); + } } static SpaprDrc *drc_from_dev(SpaprPhbState *phb, PCIDevice *dev) { - uint32_t busnr = pci_bus_num(PCI_BUS(qdev_get_parent_bus(DEVICE(dev)))); - return drc_from_devfn(phb, busnr, dev->devfn); + Error *local_err = NULL; + uint8_t chassis = chassis_from_bus(pci_get_bus(dev), &local_err); + + if (local_err) { + error_report_err(local_err); + return NULL; + } + + return drc_from_devfn(phb, chassis, dev->devfn); } static void add_drcs(SpaprPhbState *phb) @@ -1516,14 +1533,19 @@ static void spapr_pci_plug(HotplugHandler *plug_handler, spapr_drc_reset(drc); } else if (PCI_FUNC(pdev->devfn) == 0) { int i; + uint8_t chassis = chassis_from_bus(pci_get_bus(pdev), &local_err); + + if (local_err) { + error_propagate(errp, local_err); + return; + } for (i = 0; i < 8; i++) { SpaprDrc *func_drc; SpaprDrcClass *func_drck; SpaprDREntitySense state; - func_drc = drc_from_devfn(phb, pci_bus_num(bus), - PCI_DEVFN(slotnr, i)); + func_drc = drc_from_devfn(phb, chassis, PCI_DEVFN(slotnr, i)); func_drck = SPAPR_DR_CONNECTOR_GET_CLASS(func_drc); state = func_drck->dr_entity_sense(func_drc); @@ -1571,18 +1593,23 @@ static void spapr_pci_unplug_request(HotplugHandler *plug_handler, g_assert(drc->dev == plugged_dev); if (!spapr_drc_unplug_requested(drc)) { - PCIBus *bus = PCI_BUS(qdev_get_parent_bus(DEVICE(pdev))); uint32_t slotnr = PCI_SLOT(pdev->devfn); SpaprDrc *func_drc; SpaprDrcClass *func_drck; SpaprDREntitySense state; int i; + Error *local_err = NULL; + uint8_t chassis = chassis_from_bus(pci_get_bus(pdev), &local_err); + + if (local_err) { + error_propagate(errp, local_err); + return; + } /* ensure any other present functions are pending unplug */ if (PCI_FUNC(pdev->devfn) == 0) { for (i = 1; i < 8; i++) { - func_drc = drc_from_devfn(phb, pci_bus_num(bus), - PCI_DEVFN(slotnr, i)); + func_drc = drc_from_devfn(phb, chassis, PCI_DEVFN(slotnr, i)); func_drck = SPAPR_DR_CONNECTOR_GET_CLASS(func_drc); state = func_drck->dr_entity_sense(func_drc); if (state == SPAPR_DR_ENTITY_SENSE_PRESENT @@ -1603,8 +1630,7 @@ static void spapr_pci_unplug_request(HotplugHandler *plug_handler, */ if (PCI_FUNC(pdev->devfn) == 0) { for (i = 7; i >= 0; i--) { - func_drc = drc_from_devfn(phb, pci_bus_num(bus), - PCI_DEVFN(slotnr, i)); + func_drc = drc_from_devfn(phb, chassis, PCI_DEVFN(slotnr, i)); func_drck = SPAPR_DR_CONNECTOR_GET_CLASS(func_drc); state = func_drck->dr_entity_sense(func_drc); if (state == SPAPR_DR_ENTITY_SENSE_PRESENT) { From patchwork Thu May 23 05:29:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gibson X-Patchwork-Id: 10956907 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id ABEF5112C for ; Thu, 23 May 2019 05:34:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 85CD327FA8 for ; Thu, 23 May 2019 05:34:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 78C6D27FB7; Thu, 23 May 2019 05:34:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2F29E27FA8 for ; Thu, 23 May 2019 05:34:34 +0000 (UTC) Received: from localhost ([127.0.0.1]:57958 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTgN7-0003Qd-H2 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 23 May 2019 01:34:33 -0400 Received: from eggs.gnu.org ([209.51.188.92]:41313) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTgIO-00080i-F2 for qemu-devel@nongnu.org; Thu, 23 May 2019 01:29:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTgIM-0005jc-Hq for qemu-devel@nongnu.org; Thu, 23 May 2019 01:29:40 -0400 Received: from ozlabs.org ([203.11.71.1]:52855) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hTgIK-0005hs-RR; Thu, 23 May 2019 01:29:38 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 458dNM3kl4z9sDX; Thu, 23 May 2019 15:29:23 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1558589363; bh=AW77xSAKbMiDidstLqWSYFs3Idt3X/vhTJyEOA0oYfY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OEqKriCPGaUmkaQdMd+OcUFPS4Yz1XSzrOKpSnjjL5h1LrexgWM/wjghHiIok1OxS BuSZIZBY/IbZn3jN5zMjFGVuJHo2WXwguq68cOkZfzXCIJ/yVtyelqzPqgfufRbCH+ Y52UkPLHlr9rz3XlHZbysa4BJnLaIay6Qv+yIwZ0= From: David Gibson To: qemu-ppc@nongnu.org Date: Thu, 23 May 2019 15:29:17 +1000 Message-Id: <20190523052918.1129-7-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190523052918.1129-1-david@gibson.dropbear.id.au> References: <20190523052918.1129-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 203.11.71.1 Subject: [Qemu-devel] [PATCH 7/8] spapr: Direct all PCI hotplug to host bridge, rather than P2P bridge X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mst@redhat.com, qemu-devel@nongnu.org, groug@kaod.org, clg@kaod.org, mdroth@linux.ibm.com, David Gibson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP A P2P bridge will attempt to handle the hotplug with SHPC, which doesn't work in the PAPR environment. Instead we want to direct all PCI hotplug actions to the PAPR specific host bridge which will use the PAPR hotplug mechanism. Signed-off-by: David Gibson --- hw/ppc/spapr.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 507fd50dd5..6dd8aaac33 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -4094,6 +4094,17 @@ static HotplugHandler *spapr_get_hotplug_handler(MachineState *machine, object_dynamic_cast(OBJECT(dev), TYPE_SPAPR_PCI_HOST_BRIDGE)) { return HOTPLUG_HANDLER(machine); } + if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE)) { + PCIDevice *pcidev = PCI_DEVICE(dev); + PCIBus *root = pci_device_root_bus(pcidev); + SpaprPhbState *phb = + (SpaprPhbState *)object_dynamic_cast(OBJECT(BUS(root)->parent), + TYPE_SPAPR_PCI_HOST_BRIDGE); + + if (phb) { + return HOTPLUG_HANDLER(phb); + } + } return NULL; } From patchwork Thu May 23 05:29:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gibson X-Patchwork-Id: 10956901 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0398F112C for ; Thu, 23 May 2019 05:31:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D30B427FA8 for ; Thu, 23 May 2019 05:31:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C732727FC0; Thu, 23 May 2019 05:31:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1E64727FA8 for ; Thu, 23 May 2019 05:31:44 +0000 (UTC) Received: from localhost ([127.0.0.1]:57928 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTgKN-0001QH-Bw for patchwork-qemu-devel@patchwork.kernel.org; Thu, 23 May 2019 01:31:43 -0400 Received: from eggs.gnu.org ([209.51.188.92]:41329) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTgIP-00080k-Bv for qemu-devel@nongnu.org; Thu, 23 May 2019 01:29:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTgIM-0005jw-Mx for qemu-devel@nongnu.org; Thu, 23 May 2019 01:29:40 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:42073) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hTgIL-0005hz-2P; Thu, 23 May 2019 01:29:38 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 458dNM3BjTz9sBb; Thu, 23 May 2019 15:29:23 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1558589363; bh=6+yFFKzxCwb7KFLMf7OJjNXUm4RPq6kPWKgMltQOp3E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KdqarK2HGcHpAHgrWdxi2C6JbZ6pm0IF0nvCwVk4G0Z9jdozawx1Ot6eekLHMajwp 5RbE8WyFA42JyRwDziKnJFCCn1+tyoO8Rc7BhZTNKCM07F5HHBf0f15xWI+aS8y13r 5QWuH9SbfhQImxMDJ+6QxEYMXFSexWgvyhyTquUE= From: David Gibson To: qemu-ppc@nongnu.org Date: Thu, 23 May 2019 15:29:18 +1000 Message-Id: <20190523052918.1129-8-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190523052918.1129-1-david@gibson.dropbear.id.au> References: <20190523052918.1129-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2401:3900:2:1::2 Subject: [Qemu-devel] [PATCH 8/8] spapr: Allow hot plug/unplug of PCI bridges and devices under PCI bridges X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mst@redhat.com, qemu-devel@nongnu.org, groug@kaod.org, clg@kaod.org, mdroth@linux.ibm.com, David Gibson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The pseries machine type already allows PCI hotplug and unplug via the PAPR mechanism, but only on the root bus of each PHB. This patch extends this to allow PCI to PCI bridges to be hotplugged, and devices to be hotplugged or unplugged under P2P bridges. For now we disallow hot unplugging P2P bridges. I tried doing that, but haven't managed to get it working, I think due to some guest side problems that need further investigation. To do this we dynamically construct DRCs when bridges are hot (or cold) added, which can in turn be used to hotplug devices under the bridge. Signed-off-by: David Gibson --- hw/ppc/spapr_pci.c | 115 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 102 insertions(+), 13 deletions(-) diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c index 94691fcfc2..a4d5e46525 100644 --- a/hw/ppc/spapr_pci.c +++ b/hw/ppc/spapr_pci.c @@ -1257,30 +1257,53 @@ static SpaprDrc *drc_from_dev(SpaprPhbState *phb, PCIDevice *dev) return drc_from_devfn(phb, chassis, dev->devfn); } -static void add_drcs(SpaprPhbState *phb) +static void add_drcs(SpaprPhbState *phb, PCIBus *bus, Error **errp) { + Object *owner; int i; + uint8_t chassis; + Error *local_err = NULL; if (!phb->dr_enabled) { return; } + chassis = chassis_from_bus(bus, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } + + if (pci_bus_is_root(bus)) { + owner = OBJECT(phb); + } else { + owner = OBJECT(pci_bridge_get_device(bus)); + } + for (i = 0; i < PCI_SLOT_MAX * PCI_FUNC_MAX; i++) { - spapr_dr_connector_new(OBJECT(phb), TYPE_SPAPR_DRC_PCI, - drc_id_from_devfn(phb, 0, i)); + spapr_dr_connector_new(owner, TYPE_SPAPR_DRC_PCI, + drc_id_from_devfn(phb, chassis, i)); } } -static void remove_drcs(SpaprPhbState *phb) +static void remove_drcs(SpaprPhbState *phb, PCIBus *bus, Error **errp) { int i; + uint8_t chassis; + Error *local_err = NULL; if (!phb->dr_enabled) { return; } + chassis = chassis_from_bus(bus, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } + for (i = PCI_SLOT_MAX * PCI_FUNC_MAX - 1; i >= 0; i--) { - SpaprDrc *drc = drc_from_devfn(phb, 0, i); + SpaprDrc *drc = drc_from_devfn(phb, chassis, i); if (drc) { object_unparent(OBJECT(drc)); @@ -1325,6 +1348,7 @@ static int spapr_dt_pci_bus(SpaprPhbState *sphb, PCIBus *bus, .sphb = sphb, .err = 0, }; + int ret; _FDT(fdt_setprop_cell(fdt, offset, "#address-cells", RESOURCE_CELLS_ADDRESS)); @@ -1339,6 +1363,12 @@ static int spapr_dt_pci_bus(SpaprPhbState *sphb, PCIBus *bus, } } + ret = spapr_dt_drc(fdt, offset, OBJECT(bus->parent_dev), + SPAPR_DR_CONNECTOR_TYPE_PCI); + if (ret) { + return ret; + } + return offset; } @@ -1483,11 +1513,26 @@ int spapr_pci_dt_populate(SpaprDrc *drc, SpaprMachineState *spapr, return 0; } +static void spapr_pci_bridge_plug(SpaprPhbState *phb, + PCIBridge *bridge, + Error **errp) +{ + Error *local_err = NULL; + PCIBus *bus = pci_bridge_get_sec_bus(bridge); + + add_drcs(phb, bus, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } +} + static void spapr_pci_plug(HotplugHandler *plug_handler, DeviceState *plugged_dev, Error **errp) { SpaprPhbState *phb = SPAPR_PCI_HOST_BRIDGE(DEVICE(plug_handler)); PCIDevice *pdev = PCI_DEVICE(plugged_dev); + PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(plugged_dev); SpaprDrc *drc = drc_from_dev(phb, pdev); Error *local_err = NULL; PCIBus *bus = PCI_BUS(qdev_get_parent_bus(DEVICE(pdev))); @@ -1509,6 +1554,14 @@ static void spapr_pci_plug(HotplugHandler *plug_handler, g_assert(drc); + if (pc->is_bridge) { + spapr_pci_bridge_plug(phb, PCI_BRIDGE(plugged_dev), &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } + } + /* Following the QEMU convention used for PCIe multifunction * hotplug, we do not allow functions to be hotplugged to a * slot that already has function 0 present @@ -1559,9 +1612,26 @@ out: error_propagate(errp, local_err); } +static void spapr_pci_bridge_unplug(SpaprPhbState *phb, + PCIBridge *bridge, + Error **errp) +{ + Error *local_err = NULL; + PCIBus *bus = pci_bridge_get_sec_bus(bridge); + + remove_drcs(phb, bus, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } +} + static void spapr_pci_unplug(HotplugHandler *plug_handler, DeviceState *plugged_dev, Error **errp) { + PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(plugged_dev); + SpaprPhbState *phb = SPAPR_PCI_HOST_BRIDGE(DEVICE(plug_handler)); + /* some version guests do not wait for completion of a device * cleanup (generally done asynchronously by the kernel) before * signaling to QEMU that the device is safe, but instead sleep @@ -1573,6 +1643,16 @@ static void spapr_pci_unplug(HotplugHandler *plug_handler, * an 'idle' state, as the device cleanup code expects. */ pci_device_reset(PCI_DEVICE(plugged_dev)); + + if (pc->is_bridge) { + Error *local_err = NULL; + spapr_pci_bridge_unplug(phb, PCI_BRIDGE(plugged_dev), &local_err); + if (local_err) { + error_propagate(errp, local_err); + } + return; + } + object_property_set_bool(OBJECT(plugged_dev), false, "realized", NULL); } @@ -1593,6 +1673,7 @@ static void spapr_pci_unplug_request(HotplugHandler *plug_handler, g_assert(drc->dev == plugged_dev); if (!spapr_drc_unplug_requested(drc)) { + PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(plugged_dev); uint32_t slotnr = PCI_SLOT(pdev->devfn); SpaprDrc *func_drc; SpaprDrcClass *func_drck; @@ -1606,6 +1687,10 @@ static void spapr_pci_unplug_request(HotplugHandler *plug_handler, return; } + if (pc->is_bridge) { + error_setg(errp, "PCI: Hot unplug of PCI bridges not supported"); + } + /* ensure any other present functions are pending unplug */ if (PCI_FUNC(pdev->devfn) == 0) { for (i = 1; i < 8; i++) { @@ -1658,6 +1743,7 @@ static void spapr_phb_unrealize(DeviceState *dev, Error **errp) SpaprTceTable *tcet; int i; const unsigned windows_supported = spapr_phb_windows_supported(sphb); + Error *local_err = NULL; spapr_phb_nvgpu_free(sphb); @@ -1678,7 +1764,11 @@ static void spapr_phb_unrealize(DeviceState *dev, Error **errp) } } - remove_drcs(sphb); + remove_drcs(sphb, phb->bus, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } for (i = PCI_NUM_PINS - 1; i >= 0; i--) { if (sphb->lsi_table[i].irq) { @@ -1743,6 +1833,7 @@ static void spapr_phb_realize(DeviceState *dev, Error **errp) uint64_t msi_window_size = 4096; SpaprTceTable *tcet; const unsigned windows_supported = spapr_phb_windows_supported(sphb); + Error *local_err = NULL; if (!spapr) { error_setg(errp, TYPE_SPAPR_PCI_HOST_BRIDGE " needs a pseries machine"); @@ -1879,7 +1970,6 @@ static void spapr_phb_realize(DeviceState *dev, Error **errp) /* Initialize the LSI table */ for (i = 0; i < PCI_NUM_PINS; i++) { uint32_t irq = SPAPR_IRQ_PCI_LSI + sphb->index * PCI_NUM_PINS + i; - Error *local_err = NULL; if (smc->legacy_irq_allocation) { irq = spapr_irq_findone(spapr, &local_err); @@ -1904,7 +1994,11 @@ static void spapr_phb_realize(DeviceState *dev, Error **errp) } /* allocate connectors for child PCI devices */ - add_drcs(sphb); + add_drcs(sphb, phb->bus, &local_err); + if (local_err) { + error_propagate(errp, local_err); + goto unrealize; + } /* DMA setup */ for (i = 0; i < windows_supported; ++i) { @@ -2320,11 +2414,6 @@ int spapr_dt_phb(SpaprPhbState *phb, uint32_t intc_phandle, void *fdt, return ret; } - ret = spapr_dt_drc(fdt, bus_off, OBJECT(phb), SPAPR_DR_CONNECTOR_TYPE_PCI); - if (ret) { - return ret; - } - spapr_phb_nvgpu_populate_dt(phb, fdt, bus_off, &errp); if (errp) { error_report_err(errp);