From patchwork Thu Aug 17 23:36:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksandr Bezzubikov X-Patchwork-Id: 9907353 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 4585F6024A for ; Thu, 17 Aug 2017 23:40:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 37ECF28C09 for ; Thu, 17 Aug 2017 23:40:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2C72C28C10; Thu, 17 Aug 2017 23:40:10 +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 AC68928C1A for ; Thu, 17 Aug 2017 23:40:09 +0000 (UTC) Received: from localhost ([::1]:58659 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diUOX-0002tU-08 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 17 Aug 2017 19:40:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50747) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diULU-00017H-GS for qemu-devel@nongnu.org; Thu, 17 Aug 2017 19:37:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1diULT-0001oJ-3V for qemu-devel@nongnu.org; Thu, 17 Aug 2017 19:37:00 -0400 Received: from mail-lf0-x243.google.com ([2a00:1450:4010:c07::243]:36422) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1diULS-0001n4-Ri for qemu-devel@nongnu.org; Thu, 17 Aug 2017 19:36:59 -0400 Received: by mail-lf0-x243.google.com with SMTP id t128so5267141lff.3 for ; Thu, 17 Aug 2017 16:36:58 -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=4PaU3I+M2PeTeskvPFhgE9451D/rXcihg6IsfQMCYD8=; b=dck7PCsttfObTTgkQmC7CPqxTDQqRoQuhdGAl4CcZ5q+T6AtPgCiG0wczCxY3IxR7x x9XiJ4YxOrDLl+5Szx6rT/xTtFluZ4hnsrIA3qPpaatpT4pKK1qYH8XDn26WU42l7ytb NJ59iWvZqCcFuws7tsKdxGxf8Ua6ZXdHcha2A6IRjJlZZoPeV06RSu9XSe/4Tan6PBGM UktWdyHmOc7TwNZfS6s6tRPgOaRDItHPMCfSkz8x7STtvSbVtCosLjZuHbhjGiplV+ij Lwuw8eWvrQR4HDj3rCn4DZgqjYib7hFRZUvofiJZdNDihZfGyEI+CzGPbeDTcJ7IhKEb 8+GA== 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=4PaU3I+M2PeTeskvPFhgE9451D/rXcihg6IsfQMCYD8=; b=sJkLpoDSPL3vyuY3+FZXJxAkVdWPTfTP4A9bKAtHkqdk11ft8P3v42pFJOiDUCCGma oZ/xyXpYpCu7RT6gIusC17w9tUrGRS5k6iWWFy0vbbl2BKaVahXhu2YrkgWoyNBeVSmb PDYI73ggidre86By35Wp+oqJZy8eFciA00GpGl0Epn/J11pL0sPSFlR/a4XCqIBmvmYq yad1S2UN8Dx7s3gnzg/lDNYqAl3QzISpi7NKhN6bReomNikgmYEZdK0m5/k5m/1hgCXS uCBul5IuweAz72C5SsSuSAFQzud4bD5oEMMYRgkOxy0UV3mGIVDpbX1Fs3v8sykSPWHC Oxng== X-Gm-Message-State: AHYfb5gbrllVow450X5kfrgWPyc8oOcWsacori+6GDhnn/7lKPPV7iA6 fqu98r4uokhlNUO5ulg= X-Received: by 10.25.209.148 with SMTP id i142mr2189054lfg.135.1503013017343; Thu, 17 Aug 2017 16:36:57 -0700 (PDT) Received: from localhost.localdomain ([93.185.28.201]) by smtp.gmail.com with ESMTPSA id y1sm903381lja.86.2017.08.17.16.36.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 17 Aug 2017 16:36:56 -0700 (PDT) From: Aleksandr Bezzubikov To: qemu-devel@nongnu.org Date: Fri, 18 Aug 2017 02:36:48 +0300 Message-Id: <1503013010-11500-3-git-send-email-zuban32s@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1503013010-11500-1-git-send-email-zuban32s@gmail.com> References: <1503013010-11500-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 v7 2/4] hw/pci: introduce bridge-only vendor-specific capability to provide some hints to firmware 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: marcel@redhat.com, seabios@seabios.org, lersek@redhat.com, Aleksandr Bezzubikov , mst@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP On PCI init PCI bridges may need some extra info about bus number, IO, memory and prefetchable memory to reserve. QEMU can provide this with a special vendor-specific PCI capability. Signed-off-by: Aleksandr Bezzubikov Reviewed-by: Marcel Apfelbaum --- hw/pci/pci_bridge.c | 46 +++++++++++++++++++++++++++++++++++++++++++++ include/hw/pci/pci_bridge.h | 25 ++++++++++++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/hw/pci/pci_bridge.c b/hw/pci/pci_bridge.c index 720119b..17feae5 100644 --- a/hw/pci/pci_bridge.c +++ b/hw/pci/pci_bridge.c @@ -408,6 +408,52 @@ void pci_bridge_map_irq(PCIBridge *br, const char* bus_name, br->bus_name = bus_name; } + +int pci_bridge_qemu_reserve_cap_init(PCIDevice *dev, int cap_offset, + uint32_t bus_reserve, uint64_t io_reserve, + uint32_t mem_non_pref_reserve, + uint32_t mem_pref_32_reserve, + uint64_t mem_pref_64_reserve, + Error **errp) +{ + if (mem_pref_32_reserve != (uint32_t)-1 && + mem_pref_64_reserve != (uint64_t)-1) { + error_setg(errp, + "PCI resource reserve cap: PREF32 and PREF64 conflict"); + return -EINVAL; + } + + if (bus_reserve == (uint32_t)-1 && + io_reserve == (uint64_t)-1 && + mem_non_pref_reserve == (uint32_t)-1 && + mem_pref_32_reserve == (uint32_t)-1 && + mem_pref_64_reserve == (uint64_t)-1) { + return 0; + } + + size_t cap_len = sizeof(PCIBridgeQemuCap); + PCIBridgeQemuCap cap = { + .len = cap_len, + .type = REDHAT_PCI_CAP_RESOURCE_RESERVE, + .bus_res = bus_reserve, + .io = io_reserve, + .mem = mem_non_pref_reserve, + .mem_pref_32 = mem_pref_32_reserve, + .mem_pref_64 = mem_pref_64_reserve + }; + + int offset = pci_add_capability(dev, PCI_CAP_ID_VNDR, + cap_offset, cap_len, errp); + if (offset < 0) { + return offset; + } + + memcpy(dev->config + offset + PCI_CAP_FLAGS, + (char *)&cap + PCI_CAP_FLAGS, + cap_len - PCI_CAP_FLAGS); + return 0; +} + static const TypeInfo pci_bridge_type_info = { .name = TYPE_PCI_BRIDGE, .parent = TYPE_PCI_DEVICE, diff --git a/include/hw/pci/pci_bridge.h b/include/hw/pci/pci_bridge.h index ff7cbaa..1acadc2 100644 --- a/include/hw/pci/pci_bridge.h +++ b/include/hw/pci/pci_bridge.h @@ -67,4 +67,29 @@ void pci_bridge_map_irq(PCIBridge *br, const char* bus_name, #define PCI_BRIDGE_CTL_DISCARD_STATUS 0x400 /* Discard timer status */ #define PCI_BRIDGE_CTL_DISCARD_SERR 0x800 /* Discard timer SERR# enable */ +typedef struct PCIBridgeQemuCap { + uint8_t id; /* Standard PCI capability header field */ + uint8_t next; /* Standard PCI capability header field */ + uint8_t len; /* Standard PCI vendor-specific capability header field */ + uint8_t type; /* Red Hat vendor-specific capability type. + Types are defined with REDHAT_PCI_CAP_ prefix */ + + uint32_t bus_res; /* Minimum number of buses to reserve */ + uint64_t io; /* IO space to reserve */ + uint32_t mem; /* Non-prefetchable memory to reserve */ + /* At most one of the following two fields may be set to a value + * different from -1 */ + uint32_t mem_pref_32; /* Prefetchable memory to reserve (32-bit MMIO) */ + uint64_t mem_pref_64; /* Prefetchable memory to reserve (64-bit MMIO) */ +} PCIBridgeQemuCap; + +#define REDHAT_PCI_CAP_RESOURCE_RESERVE 1 + +int pci_bridge_qemu_reserve_cap_init(PCIDevice *dev, int cap_offset, + uint32_t bus_reserve, uint64_t io_reserve, + uint32_t mem_non_pref_reserve, + uint32_t mem_pref_32_reserve, + uint64_t mem_pref_64_reserve, + Error **errp); + #endif /* QEMU_PCI_BRIDGE_H */