From nobody Sun Nov 9 16:05:47 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1551158800199198.71596470397935; Mon, 25 Feb 2019 21:26:40 -0800 (PST) Received: from localhost ([127.0.0.1]:49354 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyVGJ-0005GB-2j for importer@patchew.org; Tue, 26 Feb 2019 00:26:39 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58112) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyUlH-0005PE-IM for qemu-devel@nongnu.org; Mon, 25 Feb 2019 23:54:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gyUlF-0002tl-H2 for qemu-devel@nongnu.org; Mon, 25 Feb 2019 23:54:35 -0500 Received: from ozlabs.org ([203.11.71.1]:55525) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gyUlA-0002U8-Mm; Mon, 25 Feb 2019 23:54:32 -0500 Received: by ozlabs.org (Postfix, from userid 1007) id 447mfM5FkNz9sNy; Tue, 26 Feb 2019 15:53:14 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1551156795; bh=aCSXH12GEL4xODQVybvspOng7EuUiH3zx/moZ3ytSAk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Mt/1cgVyVykt+yH3we+7HgaLNZTdVFKdx8MM1HlFddhqpt9z42wkyjkDuQV0wNT3p dcinXICl0SWt3xNNhjbGzTyQVVGrK58nL4tL1OvriQtsaDKctRzKPcbDdo0GEX3Ccr FxXiMoLIFGmm5Xp9iTpZhtkyuUAYDqKQSJSgp6Ug= From: David Gibson To: peter.maydell@linaro.org Date: Tue, 26 Feb 2019 15:52:43 +1100 Message-Id: <20190226045304.25618-30-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190226045304.25618-1-david@gibson.dropbear.id.au> References: <20190226045304.25618-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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] [PULL 29/50] spapr_drc: Allow FDT fragment to be added later 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: lvivier@redhat.com, gkurz@kaod.org, Greg Kurz , qemu-devel@nongnu.org, qemu-ppc@nongnu.org, clg@kaod.org, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Greg Kurz The current logic is to provide the FDT fragment when attaching a device to a DRC. This works perfectly fine for our current hotplug support, but soon we will add support for PHB hotplug which has some constraints, that CPU, PCI and LMB devices don't seem to have. The first constraint is that the "ibm,dma-window" property of the PHB node requires the IOMMU to be configured, ie, spapr_tce_table_enable() has been called, which happens during PHB reset. It is okay in the case of hotplug since the device is reset before the hotplug handler is called. On the contrary with coldplug, the hotplug handler is called first and device is only reset during the initial system reset. Trying to create the FDT fragment on the hotplug path in this case, would result in somthing like this: ibm,dma-window =3D < 0x80000000 0x00 0x00 0x00 0x00 >; This will cause linux in the guest to panic, by simply removing and re-adding the PHB using the drmgr command: page =3D alloc_pages_node(nid, GFP_KERNEL, get_order(sz)); if (!page) panic("iommu_init_table: Can't allocate %ld bytes\n", sz); The second and maybe more problematic constraint is that the "interrupt-map" property needs to reference the interrupt controller node using the very same phandle that SLOF has already exposed to the guest. QEMU requires SLOF to call the private KVMPPC_H_UPDATE_DT hcall at some point to know about this phandle. With the latest QEMU and SLOF, this happens when SLOF gets quiesced. This means that if the PHB gets hotplugged after CAS but before SLOF quiesce, then we're sure that the phandle is not known when the hotplug handler is called. The FDT is only needed when the guest first invokes RTAS to configure the connector actually, long after SLOF quiesce. Let's postpone the creation of FDT fragments for PHBs to rtas_ibm_configure_connector(). Since we only need this for PHBs, introduce a new method in the base DRC class for that. DRC subtypes will be converted to use it in subsequent patches. Allow spapr_drc_attach() to be passed a NULL fdt argument if the method is available. When all DRC subtypes have been converted, the fdt argument will eventually disappear. Signed-off-by: Greg Kurz Message-Id: <155059665823.1466090.18358845122627355537.stgit@bahia.lab.toul= ouse-stg.fr.ibm.com> Signed-off-by: David Gibson --- hw/ppc/spapr_drc.c | 36 +++++++++++++++++++++++++++++++----- include/hw/ppc/spapr_drc.h | 6 ++++++ 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c index 2edb7d1e9c..66b965a0a7 100644 --- a/hw/ppc/spapr_drc.c +++ b/hw/ppc/spapr_drc.c @@ -22,6 +22,7 @@ #include "qemu/error-report.h" #include "hw/ppc/spapr.h" /* for RTAS return codes */ #include "hw/pci-host/spapr.h" /* spapr_phb_remove_pci_device_cb callback = */ +#include "sysemu/device_tree.h" #include "trace.h" =20 #define DRC_CONTAINER_PATH "/dr-connector" @@ -376,6 +377,8 @@ static void prop_get_fdt(Object *obj, Visitor *v, const= char *name, void spapr_drc_attach(sPAPRDRConnector *drc, DeviceState *d, void *fdt, int fdt_start_offset, Error **errp) { + sPAPRDRConnectorClass *drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); + trace_spapr_drc_attach(spapr_drc_index(drc)); =20 if (drc->dev) { @@ -384,11 +387,14 @@ void spapr_drc_attach(sPAPRDRConnector *drc, DeviceSt= ate *d, void *fdt, } g_assert((drc->state =3D=3D SPAPR_DRC_STATE_LOGICAL_UNUSABLE) || (drc->state =3D=3D SPAPR_DRC_STATE_PHYSICAL_POWERON)); - g_assert(fdt); + g_assert(fdt || drck->dt_populate); =20 drc->dev =3D d; - drc->fdt =3D fdt; - drc->fdt_start_offset =3D fdt_start_offset; + + if (fdt) { + drc->fdt =3D fdt; + drc->fdt_start_offset =3D fdt_start_offset; + } =20 object_property_add_link(OBJECT(drc), "device", object_get_typename(OBJECT(drc->dev)), @@ -1102,10 +1108,30 @@ static void rtas_ibm_configure_connector(PowerPCCPU= *cpu, goto out; } =20 - g_assert(drc->fdt); - drck =3D SPAPR_DR_CONNECTOR_GET_CLASS(drc); =20 + g_assert(drc->fdt || drck->dt_populate); + + if (!drc->fdt) { + Error *local_err =3D NULL; + void *fdt; + int fdt_size; + + fdt =3D create_device_tree(&fdt_size); + + if (drck->dt_populate(drc, spapr, fdt, &drc->fdt_start_offset, + &local_err)) { + g_free(fdt); + error_free(local_err); + rc =3D SPAPR_DR_CC_RESPONSE_ERROR; + goto out; + } + + drc->fdt =3D fdt; + drc->ccs_offset =3D drc->fdt_start_offset; + drc->ccs_depth =3D 0; + } + do { uint32_t tag; const char *name; diff --git a/include/hw/ppc/spapr_drc.h b/include/hw/ppc/spapr_drc.h index f6ff32e7e2..2aa919f0cf 100644 --- a/include/hw/ppc/spapr_drc.h +++ b/include/hw/ppc/spapr_drc.h @@ -18,6 +18,7 @@ #include "qom/object.h" #include "sysemu/sysemu.h" #include "hw/qdev.h" +#include "qapi/error.h" =20 #define TYPE_SPAPR_DR_CONNECTOR "spapr-dr-connector" #define SPAPR_DR_CONNECTOR_GET_CLASS(obj) \ @@ -213,6 +214,8 @@ typedef struct sPAPRDRConnector { int fdt_start_offset; } sPAPRDRConnector; =20 +struct sPAPRMachineState; + typedef struct sPAPRDRConnectorClass { /*< private >*/ DeviceClass parent; @@ -228,6 +231,9 @@ typedef struct sPAPRDRConnectorClass { uint32_t (*isolate)(sPAPRDRConnector *drc); uint32_t (*unisolate)(sPAPRDRConnector *drc); void (*release)(DeviceState *dev); + + int (*dt_populate)(sPAPRDRConnector *drc, struct sPAPRMachineState *sp= apr, + void *fdt, int *fdt_start_offset, Error **errp); } sPAPRDRConnectorClass; =20 typedef struct sPAPRDRCPhysical { --=20 2.20.1