From patchwork Thu Aug 17 23:33:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksandr Bezzubikov X-Patchwork-Id: 9907345 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6C8386024A for ; Thu, 17 Aug 2017 23:34:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5EDD328BEF for ; Thu, 17 Aug 2017 23:34:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 53B2928C04; Thu, 17 Aug 2017 23:34:50 +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=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BAEBD28BEF for ; Thu, 17 Aug 2017 23:34:49 +0000 (UTC) Received: from localhost ([::1]:58364 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diUJM-0006u7-WF for patchwork-qemu-devel@patchwork.kernel.org; Thu, 17 Aug 2017 19:34:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50013) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diUIA-0006qo-0s for qemu-devel@nongnu.org; Thu, 17 Aug 2017 19:33:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1diUI8-0008SD-OE for qemu-devel@nongnu.org; Thu, 17 Aug 2017 19:33:34 -0400 Received: from mail-lf0-x243.google.com ([2a00:1450:4010:c07::243]:33356) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1diUI8-0008RX-C1 for qemu-devel@nongnu.org; Thu, 17 Aug 2017 19:33:32 -0400 Received: by mail-lf0-x243.google.com with SMTP id f7so432495lfg.0 for ; Thu, 17 Aug 2017 16:33:32 -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=XVrjkMjSBHGU3vTwqeeaEJwQuYGMHj1tzF9U3+/6BnE=; b=uipRK2nNpZRy+UuFmL4l+6kZV7HQVjzjA2LeapwYr9TlTTQlrBa2zVXy+j3Q5zlMSc 49IfRp8hP3ZCOnEWbVYjvxPpVtd4N7mbpjeWWijXdCdNW2URfy5uIFhIY/7+6Tu5njcX EICU3bAX3ecGWWJiKhIl0N9u6qcpyaPTPrj+g9hmMhcvctEUJUSQD86LRT/ZLruHXxHU Gk5/JWSWhI53NofaXy0IJo0wPLpRykpJEyqtVLs6MtKT116qxpJFn4KT6x2uo/MnwkuP K6ts1lO3eYqXzOIOG9peqsQScMJ2CvDjwQlalXzam8zirojFxgqBia3NGJF68ZrdrxhI F1VA== 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=XVrjkMjSBHGU3vTwqeeaEJwQuYGMHj1tzF9U3+/6BnE=; b=KqVMPc43h98FtrKtcJRfey+fcAG2VrL6qFI5rbjw+mL/ghbszqOqJDBLjGx/ilWlty 8qTHj055jsBmoQvNPDAIuK5gw1i+UzmlIRgkJ7S4suByAIwWoCdzuIRvnB4dVPLn/V7n TYWGnUfppE2zDqTFlggp8YwpvPppjnLesgPMLCRqPQeCoSs0GjGzetCqe+DORJgbG8KY KGsN9Qflu9Mpa3mC11iFzuTCMqHq69JejZXDu2zuaS/oWfGjy+YAqACvZweY9LwNdw3m n1Is4h/yKZtldINz2lfJVbfMP6XBEIKBiIq7nnOOsWjHtJQMmlabBH0S8YCmCblvz+3M AbKw== X-Gm-Message-State: AHYfb5hpP11/1ZS4C4t7I6IgGgTCzEBq8qOq8hIaMoDEk+53PDkFe9d0 0cWRCG1yVJFTuAZcIGc= X-Received: by 10.46.64.74 with SMTP id n71mr2595248lja.69.1503012811131; Thu, 17 Aug 2017 16:33:31 -0700 (PDT) Received: from localhost.localdomain ([93.185.28.201]) by smtp.gmail.com with ESMTPSA id 96sm925433ljb.60.2017.08.17.16.33.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 17 Aug 2017 16:33:30 -0700 (PDT) From: Aleksandr Bezzubikov To: seabios@seabios.org Date: Fri, 18 Aug 2017 02:33:21 +0300 Message-Id: <1503012801-10855-4-git-send-email-zuban32s@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1503012801-10855-1-git-send-email-zuban32s@gmail.com> References: <1503012801-10855-1-git-send-email-zuban32s@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4010:c07::243 Subject: [Qemu-devel] [PATCH RESEND v7 3/3] pci: enable RedHat PCI bridges to reserve additional resources on PCI init 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, Aleksandr Bezzubikov , kevin@koconnor.net, kraxel@redhat.com, marcel@redhat.com, lersek@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 capability. Signed-off-by: Aleksandr Bezzubikov Reviewed-by: Marcel Apfelbaum --- src/fw/pciinit.c | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- src/hw/pci_ids.h | 3 ++ 2 files changed, 105 insertions(+), 4 deletions(-) diff --git a/src/fw/pciinit.c b/src/fw/pciinit.c index 864954f..7f0e439 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) } } +static u8 pci_find_resource_reserve_capability(u16 bdf) +{ + if (pci_config_readw(bdf, PCI_VENDOR_ID) == PCI_VENDOR_ID_REDHAT && + pci_config_readw(bdf, PCI_DEVICE_ID) == + PCI_DEVICE_ID_REDHAT_ROOT_PORT) { + u8 cap = 0; + do { + cap = pci_find_capability(bdf, PCI_CAP_ID_VNDR, cap); + } while (cap && + pci_config_readb(bdf, cap + PCI_CAP_REDHAT_TYPE_OFFSET) != + REDHAT_CAP_RESOURCE_RESERVE); + if (cap) { + u8 cap_len = 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 invalid\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; + } +} /**************************************************************** * Bus initialization @@ -578,9 +605,33 @@ pci_bios_init_bus_rec(int bus, u8 *pci_bus) pci_bios_init_bus_rec(secbus, pci_bus); if (subbus != *pci_bus) { + u8 res_bus = *pci_bus; + u8 cap = pci_find_resource_reserve_capability(bdf); + + if (cap) { + u32 tmp_res_bus = pci_config_readl(bdf, + cap + RES_RESERVE_BUS_RES); + if (tmp_res_bus != (u32)-1) { + res_bus = 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 = 0; + } + } + if (secbus + res_bus > *pci_bus) { + dprintf(1, "PCI: QEMU resource reserve cap: bus = %u\n", + res_bus); + res_bus = secbus + res_bus; + } else { + res_bus = *pci_bus; + } + } dprintf(1, "PCI: subordinate bus = 0x%x -> 0x%x\n", - subbus, *pci_bus); - subbus = *pci_bus; + subbus, res_bus); + subbus = res_bus; + *pci_bus = res_bus; } else { dprintf(1, "PCI: subordinate bus = 0x%x\n", subbus); } @@ -844,20 +895,67 @@ static int pci_bios_check_devices(struct pci_bus *busses) */ parent = &busses[0]; int type; - u8 pcie_cap = pci_find_capability(s->bus_dev->bdf, PCI_CAP_ID_EXP, 0); + u16 bdf = s->bus_dev->bdf; + u8 pcie_cap = pci_find_capability(bdf, PCI_CAP_ID_EXP, 0); + u8 qemu_cap = pci_find_resource_reserve_capability(bdf); + int hotplug_support = pci_bus_hotplug_support(s, pcie_cap); for (type = 0; type < PCI_REGION_TYPE_COUNT; type++) { u64 align = (type == PCI_REGION_TYPE_IO) ? PCI_BRIDGE_IO_MIN : PCI_BRIDGE_MEM_MIN; if (!pci_bridge_has_region(s->bus_dev, type)) continue; + u64 size = 0; + if (qemu_cap) { + u32 tmp_size; + u64 tmp_size_64; + switch(type) { + case PCI_REGION_TYPE_IO: + tmp_size_64 = (pci_config_readl(bdf, qemu_cap + RES_RESERVE_IO) | + (u64)pci_config_readl(bdf, qemu_cap + RES_RESERVE_IO + 4) << 32); + if (tmp_size_64 != (u64)-1) { + size = tmp_size_64; + } + break; + case PCI_REGION_TYPE_MEM: + tmp_size = pci_config_readl(bdf, qemu_cap + RES_RESERVE_MEM); + if (tmp_size != (u32)-1) { + size = tmp_size; + } + break; + case PCI_REGION_TYPE_PREFMEM: + tmp_size = pci_config_readl(bdf, qemu_cap + RES_RESERVE_PREF_MEM_32); + tmp_size_64 = (pci_config_readl(bdf, qemu_cap + RES_RESERVE_PREF_MEM_64) | + (u64)pci_config_readl(bdf, qemu_cap + RES_RESERVE_PREF_MEM_64 + 4) << 32); + if (tmp_size != (u32)-1 && tmp_size_64 == (u64)-1) { + size = tmp_size; + } else if (tmp_size == (u32)-1 && tmp_size_64 != (u64)-1) { + size = tmp_size_64; + } else if (tmp_size != (u32)-1 && tmp_size_64 != (u64)-1) { + dprintf(1, "PCI: resource reserve cap PREF32 and PREF64" + " conflict\n"); + } + break; + default: + break; + } + } if (pci_region_align(&s->r[type]) > align) align = pci_region_align(&s->r[type]); u64 sum = pci_region_sum(&s->r[type]); int resource_optional = pcie_cap && (type == PCI_REGION_TYPE_IO); if (!sum && hotplug_support && !resource_optional) sum = align; /* reserve min size for hot-plug */ - u64 size = ALIGN(sum, align); + if (size > sum) { + dprintf(1, "PCI: QEMU resource reserve cap: " + "size %08llx type %s\n", + size, region_type_name[type]); + if (type != PCI_REGION_TYPE_IO) { + size = ALIGN(size, align); + } + } else { + size = ALIGN(sum, align); + } int is64 = 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 +#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