From patchwork Sun Aug 13 15:49:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksandr Bezzubikov X-Patchwork-Id: 9897961 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 BB7EC60351 for ; Sun, 13 Aug 2017 15:51:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B505027FBA for ; Sun, 13 Aug 2017 15:51:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A9DDB284AF; Sun, 13 Aug 2017 15:51:48 +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 39BA027FBA for ; Sun, 13 Aug 2017 15:51:48 +0000 (UTC) Received: from localhost ([::1]:34649 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dgvB5-0003JB-DY for patchwork-qemu-devel@patchwork.kernel.org; Sun, 13 Aug 2017 11:51:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36671) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dgv9M-0002nC-Vx for qemu-devel@nongnu.org; Sun, 13 Aug 2017 11:50:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dgv9K-0004zh-N7 for qemu-devel@nongnu.org; Sun, 13 Aug 2017 11:50:01 -0400 Received: from mail-lf0-x243.google.com ([2a00:1450:4010:c07::243]:38713) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dgv9K-0004z7-Fx for qemu-devel@nongnu.org; Sun, 13 Aug 2017 11:49:58 -0400 Received: by mail-lf0-x243.google.com with SMTP id y15so5151788lfd.5 for ; Sun, 13 Aug 2017 08:49: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=GY1TGV3ah6tgopylObiNc3PBiiyZRQDBFdSJ/pic9cK6ynr7jROrX3jrWInBUuZmY3 7u7d2VDGbyOESEbqSIXznTpjEPrA2GTgzgtMDCOfdj//ppRbD+bRWmyz93Nzcn2pYg5e RNaU3YoKZ+CUG062PiuO5olJhjDMC5znIhUX5qQoJgFAzT12IblyF7Ckyd2M4RI1FC3g prX8V4MgfwPE8vd3vHvnBDvw7MhrtlhiaSCz09PewFMnAYCKYfU++ZIyg2U2vBeQlN/N 9W07p+jXkl4a4eo36Wj84G055NgeuZeCt1SnY58uO7w4zCBTi6R99boVgZ5DJoE2ARs/ oTvQ== 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=ax5YBDBUQKKo1995N1W4ZIRBbobyWt4xaFnjjrhklGKDHMBqn54xQJsd38QMkaKWTA /oh+aJ24/0Kv8S6JcygoPnAM3sjUwLGry3VJ9vVMjPdScoWqvcTmIMXed1EqB6X5Ckbm wIa/KED0g0I24JCaQs9lQfQP/evG2dNXEKNEdle7yxb2DeuVAPZrHZCWdgr3wOclJNEh DbR52v+JEEMXqL/KY9WJgg/F80iBO5yfsRWA6wJb2XQvXxCGE5DM5P2czo8N19WzgGOF nKAzRJULiLXSjvQlFz4UcE5lgjgEo0kxKhGvtTIUjrpAL0QlIcx5ZmrmH+Nv7UjunYSs CV/w== X-Gm-Message-State: AHYfb5gSjKc6WLb6QsbTvOtq0nQHlmqR5m+olt1Y8gybxtH4cOEcvvC/ JlH0wz1j2iSpS6F7 X-Received: by 10.25.148.145 with SMTP id o17mr2912654lfk.200.1502639396908; Sun, 13 Aug 2017 08:49:56 -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 15sm833283ljw.35.2017.08.13.08.49.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 13 Aug 2017 08:49:56 -0700 (PDT) From: Aleksandr Bezzubikov To: qemu-devel@nongnu.org Date: Sun, 13 Aug 2017 18:49:46 +0300 Message-Id: <1502639388-12580-3-git-send-email-zuban32s@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1502639388-12580-1-git-send-email-zuban32s@gmail.com> References: <1502639388-12580-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 v6 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 */