From nobody Mon Apr 29 09:51:19 2024 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; 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 ARC-Seal: i=1; a=rsa-sha256; t=1569217979; cv=none; d=zoho.com; s=zohoarc; b=fQuWwGIocd1De7fhpKk3z0N5Ja281qWVVzRVxuy5Xj/MvsVheft7YEiMiS4dOlCHPv79xH4E6C2WAo+PL2NdXpVYHnBOUWlX/nx33zfU0dE5nxgp9IN3/Gf+5AirgQ9mjMZmGB53XqE9bwHR4urIgV8bGJI8qLk72FJtP992OEw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569217979; h=Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=ubyvwsPU4YdNfpI2mdAfOn5P65tQ2cykP/tcl8xu8qg=; b=dcDcOcJXbZPIPtleQ6ljdGUU+GK+1Q5Ig9BipxNWKaT3urL8EO8N41TlceLX7LQIXADbuOd/DLBm5cZJyIE6s4fSbbMnUzxDX46a1qm5rCMNU3sDR0Xy+v106VMFjBom6Im39M2WVP1yqMMTxKGluril43EvFtEgeC2SnOkomXc= ARC-Authentication-Results: i=1; mx.zoho.com; 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 1569217979271797.5863652718423; Sun, 22 Sep 2019 22:52:59 -0700 (PDT) Received: from localhost ([::1]:52380 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCHHO-0002Tc-Ba for importer@patchew.org; Mon, 23 Sep 2019 01:52:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50379) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCHGP-0001Yg-Dw for qemu-devel@nongnu.org; Mon, 23 Sep 2019 01:51:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iCHGN-0007XH-Px for qemu-devel@nongnu.org; Mon, 23 Sep 2019 01:51:56 -0400 Received: from ozlabs.ru ([107.173.13.209]:35942) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1iCHGN-0007Vt-J0; Mon, 23 Sep 2019 01:51:55 -0400 Received: from fstn1-p1.ozlabs.ibm.com (localhost [IPv6:::1]) by ozlabs.ru (Postfix) with ESMTP id 111DDAE807F4; Mon, 23 Sep 2019 01:50:48 -0400 (EDT) From: Alexey Kardashevskiy To: qemu-devel@nongnu.org Subject: [PATCH qemu] spapr-pci: Provide either correct assigned-addresses or none Date: Mon, 23 Sep 2019 15:51:19 +1000 Message-Id: <20190923055119.31683-1-aik@ozlabs.ru> X-Mailer: git-send-email 2.17.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 107.173.13.209 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexey Kardashevskiy , Sam Bobroff , qemu-ppc@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" QEMU stores current BAR assignments in 2 places - in the raw config space array and io_regions structs. Once set, the config space array remembers these but BARs in io_regions are reset/restored every time the device is disabled/enabled, i.e. when MMIO bit in the command register is flipped. A sPAPR guest OS normally expects BARs to be assigned by the firmware and reported to the guest via the "assigned-addresses" property (below - "aa"). For hotplug devices QEMU creates "aa" and it only does so if the device is enabled which is odd and relies on the guest linux kernel ability to assign unassigned resources; other OSes may not do this. For coldplugged devices QEMU does not provide "aa" as SLOF does BAR allocation and creates "aa" from the config space values which is ok for now but since we are going to implement full device tree update on "ibm,client-architecture-support", we will be having transitions between QEMU/SLOF/GRUB/Linux and we need to preserve BAR allocations done by SLOF. This uses non-zero BAR addresses for "aa" ("Unimplemented Base Address registers are hardwired to zero" says the PCI spec") which preserves BARs during the boot process. This only creates "aa" if any BAR was assigned. This violates the "PCI Bus Binding to Open Firmware" spec from the last millennia which states: "If no resources were assigned address space, the "assigned-addresses" property shall have a prop-encoded-array of zero length". However this allows older guests to try allocating BARs if for some reason QEMU or SLOF failed to do so. Signed-off-by: Alexey Kardashevskiy --- hw/ppc/spapr_pci.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c index 7b71ad7c74f1..2e5f5c52a33a 100644 --- a/hw/ppc/spapr_pci.c +++ b/hw/ppc/spapr_pci.c @@ -925,13 +925,17 @@ static void populate_resource_props(PCIDevice *d, Res= ourceProps *rp) reg->size_lo =3D 0; =20 for (i =3D 0; i < PCI_NUM_REGIONS; i++) { + hwaddr addr; + int bar; + if (!d->io_regions[i].size) { continue; } =20 + bar =3D pci_bar(d, i); reg =3D &rp->reg[reg_idx++]; =20 - reg->phys_hi =3D cpu_to_be32(dev_id | b_rrrrrrrr(pci_bar(d, i))); + reg->phys_hi =3D cpu_to_be32(dev_id | b_rrrrrrrr(bar)); if (d->io_regions[i].type & PCI_BASE_ADDRESS_SPACE_IO) { reg->phys_hi |=3D cpu_to_be32(b_ss(1)); } else if (d->io_regions[i].type & PCI_BASE_ADDRESS_MEM_TYPE_64) { @@ -944,14 +948,15 @@ static void populate_resource_props(PCIDevice *d, Res= ourceProps *rp) reg->size_hi =3D cpu_to_be32(d->io_regions[i].size >> 32); reg->size_lo =3D cpu_to_be32(d->io_regions[i].size); =20 - if (d->io_regions[i].addr =3D=3D PCI_BAR_UNMAPPED) { + addr =3D pci_get_long(d->config + bar) & ~(d->io_regions[i].size -= 1); + if (!addr) { continue; } =20 assigned =3D &rp->assigned[assigned_idx++]; assigned->phys_hi =3D cpu_to_be32(be32_to_cpu(reg->phys_hi) | b_n(= 1)); - assigned->phys_mid =3D cpu_to_be32(d->io_regions[i].addr >> 32); - assigned->phys_lo =3D cpu_to_be32(d->io_regions[i].addr); + assigned->phys_mid =3D cpu_to_be32(addr >> 32); + assigned->phys_lo =3D cpu_to_be32(addr); assigned->size_hi =3D reg->size_hi; assigned->size_lo =3D reg->size_lo; } @@ -1471,8 +1476,10 @@ static int spapr_dt_pci_device(SpaprPhbState *sphb, = PCIDevice *dev, =20 populate_resource_props(dev, &rp); _FDT(fdt_setprop(fdt, offset, "reg", (uint8_t *)rp.reg, rp.reg_len)); - _FDT(fdt_setprop(fdt, offset, "assigned-addresses", - (uint8_t *)rp.assigned, rp.assigned_len)); + if (rp.assigned_len) { + _FDT(fdt_setprop(fdt, offset, "assigned-addresses", + (uint8_t *)rp.assigned, rp.assigned_len)); + } =20 if (sphb->pcie_ecs && pci_is_express(dev)) { _FDT(fdt_setprop_cell(fdt, offset, "ibm,pci-config-space-type", 0x= 1)); --=20 2.17.1