From nobody Sat May 10 07:10:28 2025 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 80.81.252.135 is neither permitted nor denied by domain of seabios.org) client-ip=80.81.252.135; envelope-from=seabios-bounces@seabios.org; helo=mail.coreboot.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 80.81.252.135 is neither permitted nor denied by domain of seabios.org) smtp.mailfrom=seabios-bounces@seabios.org Return-Path: Received: from mail.coreboot.org (mail.coreboot.org [80.81.252.135]) by mx.zohomail.com with SMTPS id 1502640258188917.5826805603268; Sun, 13 Aug 2017 09:04:18 -0700 (PDT) Received: from [127.0.0.1] (helo=ra.coresystems.de) by mail.coreboot.org with esmtp (Exim 4.86_2) (envelope-from ) id 1dgvKK-0005tJ-N0; Sun, 13 Aug 2017 18:01:20 +0200 Received: from mail-lf0-f65.google.com ([209.85.215.65]) by mail.coreboot.org with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.86_2) (envelope-from ) id 1dgvK4-0004lk-7R for seabios@seabios.org; Sun, 13 Aug 2017 18:01:19 +0200 Received: by mail-lf0-f65.google.com with SMTP id w199so5169642lff.2 for ; Sun, 13 Aug 2017 09:03:39 -0700 (PDT) Received: from localhost.localdomain (broadband-109-173-19-108.moscow.rt.ru. [109.173.19.108]) by smtp.gmail.com with ESMTPSA id r196sm1050903lfe.38.2017.08.13.09.03.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 13 Aug 2017 09:03:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=RxuzuKlbY5jUGDFVGopDeH790Z7KC8uatBTACO88EKU=; b=pVDuhIHw5C9fcAFMLy3wJn4ocj0Er1liRaVaB3xCNyhOTHALnsiJdiX8F7LFP9BsbU T8karEen55A995qMrlk+1xXD4B7wYOxrccUmiP29EPi5qPORyKEaYQ04x+8rSkSYlZER Q6oFhtgfhxdztTJsgoF4J9vdUxrp3gf7GjpL1j31eH/b7t2lXdps1hCzl23qkLKv0nh5 QcPtlbrFQQlgJXXOjYvGUdNpvtHGEnPMxlDmHZ8Rrfk++friMjEpFCi2mdA9rSgLmwNG j4qKfwuMIgF2U0UMjLKUK3F/6h3BTcbBRkEoQz66oqovafWlfea0q3ilKekIqhHdYPp7 TqFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=RxuzuKlbY5jUGDFVGopDeH790Z7KC8uatBTACO88EKU=; b=rKnC+Yh/mI9Z2jZH7Ah4XEi2Djkr4R+b7jt+zw5E/JpB07a4wcIxEjRwoAh1xaeiui QA/3QaRf0NZ8Iha04Rky762aj+XBnwkZ4Rt47hKPak7cXs1SIusfeJHAvPmuKqpxalg6 5SXVkAeGDBAXw5QlXIoFENXSdXeJS01lNHPzn88oRXOL+pEf1JKdkbxzh93Ni7xHzni4 VyNWcSgo4o5kEvmSa3e+Jp0lSW3/MHwpnUH3BcTTAZz7n5d2W81LtAfsxVQS0CkSQOL6 bCxZ/cv3gwW3Z7qBalU1x5kG5b4vcV5tSZUzSVEZwLWUOigAbvhc9yS0Ubkyv/CU53zV gvGA== X-Gm-Message-State: AHYfb5iqrcvDip21w7vZe6+/hjDpoYjYTjQN4MuVDA46nj+Y0gNOdE5q j6PXhTMBwhMUBccF X-Received: by 10.46.19.9 with SMTP id 9mr7055186ljt.179.1502640217845; Sun, 13 Aug 2017 09:03:37 -0700 (PDT) From: Aleksandr Bezzubikov To: seabios@seabios.org Date: Sun, 13 Aug 2017 19:03:23 +0300 Message-Id: <1502640203-15577-4-git-send-email-zuban32s@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1502640203-15577-1-git-send-email-zuban32s@gmail.com> References: <1502640203-15577-1-git-send-email-zuban32s@gmail.com> X-Spam-Score: -2.6 (--) Subject: [SeaBIOS] [PATCH v6 3/3] pci: enable RedHat PCI bridges to reserve additional resource on PCI init X-BeenThere: seabios@seabios.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SeaBIOS mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mst@redhat.com, qemu-devel@nongnu.org, kraxel@redhat.com, marcel@redhat.com, lersek@redhat.com MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: seabios-bounces@seabios.org Sender: "SeaBIOS" X-Duff: Orig. Duff, Duff Lite, Duff Dry, Duff Dark, Raspberry Duff, Lady Duff, Red Duff, Tartar Control Duff X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" In case of Red Hat Generic PCIE Root Port reserve additional buses and/or IO/MEM/PREF space, which values are provided in a vendor-specific ca= pability. Signed-off-by: Aleksandr Bezzubikov Reviewed-by: Marcel Apfelbaum --- src/fw/pciinit.c | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++= +--- src/hw/pci_ids.h | 3 ++ 2 files changed, 98 insertions(+), 4 deletions(-) diff --git a/src/fw/pciinit.c b/src/fw/pciinit.c index 864954f..620b187 100644 --- a/src/fw/pciinit.c +++ b/src/fw/pciinit.c @@ -15,6 +15,7 @@ #include "hw/pcidevice.h" // pci_probe_devices #include "hw/pci_ids.h" // PCI_VENDOR_ID_INTEL #include "hw/pci_regs.h" // PCI_COMMAND +#include "fw/dev-pci.h" // REDHAT_CAP_RESOURCE_RESERVE #include "list.h" // struct hlist_node #include "malloc.h" // free #include "output.h" // dprintf @@ -522,6 +523,32 @@ static void pci_bios_init_platform(void) } } =20 +static u8 pci_find_resource_reserve_capability(u16 bdf) +{ + if (pci_config_readw(bdf, PCI_VENDOR_ID) =3D=3D PCI_VENDOR_ID_REDHAT && + pci_config_readw(bdf, PCI_DEVICE_ID) =3D=3D + PCI_DEVICE_ID_REDHAT_ROOT_PORT) { + u8 cap =3D 0; + do { + cap =3D pci_find_capability(bdf, PCI_CAP_ID_VNDR, cap); + } while (cap && + pci_config_readb(bdf, cap + PCI_CAP_REDHAT_TYPE_OFFSET) != =3D + REDHAT_CAP_RESOURCE_RESERVE); + if (cap) { + u8 cap_len =3D pci_config_readb(bdf, cap + PCI_CAP_FLAGS); + if (cap_len < RES_RESERVE_CAP_SIZE) { + dprintf(1, "PCI: QEMU resource reserve cap length %d is in= valid\n", + cap_len); + } + } else { + dprintf(1, "PCI: invalid QEMU resource reserve cap offset\n"); + } + return cap; + } else { + dprintf(1, "PCI: QEMU resource reserve cap not found\n"); + return 0; + } +} =20 /**************************************************************** * Bus initialization @@ -578,9 +605,28 @@ pci_bios_init_bus_rec(int bus, u8 *pci_bus) pci_bios_init_bus_rec(secbus, pci_bus); =20 if (subbus !=3D *pci_bus) { + u8 res_bus =3D 0; + u8 cap =3D pci_find_resource_reserve_capability(bdf); + + if (cap) { + u32 tmp_res_bus =3D pci_config_readl(bdf, + cap + RES_RESERVE_BUS_RES); + if (tmp_res_bus !=3D (u32)-1) { + res_bus =3D tmp_res_bus & 0xFF; + if ((u8)(res_bus + secbus) < secbus || + (u8)(res_bus + secbus) < res_bus) { + dprintf(1, "PCI: bus_reserve value %d is invalid\n= ", + res_bus); + res_bus =3D 0; + } + } + res_bus =3D (*pci_bus > secbus + res_bus) ? *pci_bus + : secbus + res_bus; + } dprintf(1, "PCI: subordinate bus =3D 0x%x -> 0x%x\n", - subbus, *pci_bus); - subbus =3D *pci_bus; + subbus, res_bus); + subbus =3D res_bus; + *pci_bus =3D res_bus; } else { dprintf(1, "PCI: subordinate bus =3D 0x%x\n", subbus); } @@ -844,20 +890,65 @@ static int pci_bios_check_devices(struct pci_bus *bus= ses) */ parent =3D &busses[0]; int type; - u8 pcie_cap =3D pci_find_capability(s->bus_dev->bdf, PCI_CAP_ID_EX= P, 0); + u16 bdf =3D s->bus_dev->bdf; + u8 pcie_cap =3D pci_find_capability(bdf, PCI_CAP_ID_EXP, 0); + u8 qemu_cap =3D pci_find_resource_reserve_capability(bdf); + int hotplug_support =3D pci_bus_hotplug_support(s, pcie_cap); for (type =3D 0; type < PCI_REGION_TYPE_COUNT; type++) { u64 align =3D (type =3D=3D PCI_REGION_TYPE_IO) ? PCI_BRIDGE_IO_MIN : PCI_BRIDGE_MEM_MIN; if (!pci_bridge_has_region(s->bus_dev, type)) continue; + u64 size =3D 0; + if (qemu_cap) { + u32 tmp_size; + u64 tmp_size_64; + switch(type) { + case PCI_REGION_TYPE_IO: + tmp_size_64 =3D (pci_config_readl(bdf, qemu_cap + RES_= RESERVE_IO) | + (u64)pci_config_readl(bdf, qemu_cap + RES_RESE= RVE_IO + 4) << 32); + if (tmp_size_64 !=3D (u64)-1) { + size =3D tmp_size_64; + } + break; + case PCI_REGION_TYPE_MEM: + tmp_size =3D pci_config_readl(bdf, qemu_cap + RES_RESE= RVE_MEM); + if (tmp_size !=3D (u32)-1) { + size =3D tmp_size; + } + break; + case PCI_REGION_TYPE_PREFMEM: + tmp_size =3D pci_config_readl(bdf, qemu_cap + RES_RESE= RVE_PREF_MEM_32); + tmp_size_64 =3D (pci_config_readl(bdf, qemu_cap + RES_= RESERVE_PREF_MEM_64) | + (u64)pci_config_readl(bdf, qemu_cap + RES_RESE= RVE_PREF_MEM_64 + 4) << 32); + if (tmp_size !=3D (u32)-1 && tmp_size_64 =3D=3D (u64)-= 1) { + size =3D tmp_size; + } else if (tmp_size =3D=3D (u32)-1 && tmp_size_64 !=3D= (u64)-1) { + size =3D tmp_size_64; + } else if (tmp_size !=3D (u32)-1 && tmp_size_64 !=3D (= u64)-1) { + dprintf(1, "PCI: resource reserve cap PREF32 and P= REF64" + " conflict\n"); + } + break; + default: + break; + } + } if (pci_region_align(&s->r[type]) > align) align =3D pci_region_align(&s->r[type]); u64 sum =3D pci_region_sum(&s->r[type]); int resource_optional =3D pcie_cap && (type =3D=3D PCI_REGION_= TYPE_IO); if (!sum && hotplug_support && !resource_optional) sum =3D align; /* reserve min size for hot-plug */ - u64 size =3D ALIGN(sum, align); + if (size > sum) { + dprintf(1, "PCI: QEMU resource reserve cap: " + "size %08llx type %s\n", + size, region_type_name[type]); + } else { + size =3D sum; + } + size =3D ALIGN(size, align); int is64 =3D pci_bios_bridge_region_is64(&s->r[type], s->bus_dev, type); // entry->bar is -1 if the entry represents a bridge region diff --git a/src/hw/pci_ids.h b/src/hw/pci_ids.h index 4ac73b4..38fa2ca 100644 --- a/src/hw/pci_ids.h +++ b/src/hw/pci_ids.h @@ -2263,6 +2263,9 @@ #define PCI_DEVICE_ID_KORENIX_JETCARDF0 0x1600 #define PCI_DEVICE_ID_KORENIX_JETCARDF1 0x16ff =20 +#define PCI_VENDOR_ID_REDHAT 0x1b36 +#define PCI_DEVICE_ID_REDHAT_ROOT_PORT 0x000C + #define PCI_VENDOR_ID_TEKRAM 0x1de1 #define PCI_DEVICE_ID_TEKRAM_DC290 0xdc29 =20 --=20 2.7.4 _______________________________________________ SeaBIOS mailing list SeaBIOS@seabios.org https://mail.coreboot.org/mailman/listinfo/seabios