From patchwork Thu Aug 10 23:31:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksandr Bezzubikov X-Patchwork-Id: 9894713 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 4433460348 for ; Thu, 10 Aug 2017 23:35:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3643428BB7 for ; Thu, 10 Aug 2017 23:35:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 33DD728BBB; Thu, 10 Aug 2017 23:35:02 +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 AB45328BCC for ; Thu, 10 Aug 2017 23:35:01 +0000 (UTC) Received: from localhost ([::1]:58536 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dfwyi-0002tV-M5 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 10 Aug 2017 19:35:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45584) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dfwv2-0000Kj-PP for qemu-devel@nongnu.org; Thu, 10 Aug 2017 19:31:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dfwv1-0001Yq-Ic for qemu-devel@nongnu.org; Thu, 10 Aug 2017 19:31:12 -0400 Received: from mail-lf0-x241.google.com ([2a00:1450:4010:c07::241]:35614) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dfwv1-0001Vo-7Z for qemu-devel@nongnu.org; Thu, 10 Aug 2017 19:31:11 -0400 Received: by mail-lf0-x241.google.com with SMTP id w199so1376426lff.2 for ; Thu, 10 Aug 2017 16:31:11 -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=B+JDj4ugisiiik8NKv5iZtaF40rXEJDE/MswXZ1qp0I=; b=MxVL006ATUDfpeNh3nn9MR2eBhhFRz16PnEeELxddW2bxZKEZi8rak7LNpAJQcdIrI 5Mas9SQFdM/seBxUluxrRbWDV4gSJhrEtrs+aoeSuX07LEtP9gYJZFz/Nt0EDu+Fjiwh jj4UEB+AbxDGOyZnpZjXXKh+PiqPp9wDhIctNUa83uPVZZ5FN1bgomg/U9Kq0S/NoY2I BoAUSfmPXP183sUMc6Hps1xfjS9e8sH0McOnauONRU+yVfpfavpqK072up3wL/Ln9/vI EtOosL+jhxjjTuT0vc0abVQnvkP1xJZLS1avNotPe7SVhBmRt5fgh1eAoGwgi7C+go6l yxeQ== 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=B+JDj4ugisiiik8NKv5iZtaF40rXEJDE/MswXZ1qp0I=; b=o6zKmh1DOWF/Ur7ype8IRAGI0tfrjwWHyaQ3USJ3j8mq4XJQvBrjPanAeGevV7Nt3N 1xPubrjpnu/3JmilJnf+yvICBw0WEODQuTfoelTVvAxi4rViS/w0VWW5NU31jnHsHEml wEoJ11oNvxvqeO60ksU2GShYakGAHOGJ/ePfcX3kvOJKEN2eFK7KVXV5Ayrm6F5MqSYn i/eJmH/prE7//1w6PVFbILCKDi9yxDnw6RwKZGLN1SLe28NJ0pN2728naKRzSO8gZfw4 z3t6DE2mgYv+ovdO97+JXz5A0n1CrBBLtao7zQyG8QZfjpS6jCLUzXprJW8k090ekEO5 eM4g== X-Gm-Message-State: AHYfb5hc54HXOtTT969alQP5EaP53MQa09uRYBfgxkjhNAm+3Ww4yboR IK/6O0zT+ltMb/0t X-Received: by 10.25.37.14 with SMTP id l14mr5319435lfl.177.1502407869666; Thu, 10 Aug 2017 16:31:09 -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 c64sm1411547lfc.4.2017.08.10.16.31.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 10 Aug 2017 16:31:08 -0700 (PDT) From: Aleksandr Bezzubikov To: qemu-devel@nongnu.org Date: Fri, 11 Aug 2017 02:31:01 +0300 Message-Id: <1502407863-23182-3-git-send-email-zuban32s@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1502407863-23182-1-git-send-email-zuban32s@gmail.com> References: <1502407863-23182-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::241 Subject: [Qemu-devel] [PATCH v5 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, 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 | 54 +++++++++++++++++++++++++++++++++++++++++++++ include/hw/pci/pci_bridge.h | 24 ++++++++++++++++++++ 2 files changed, 78 insertions(+) diff --git a/hw/pci/pci_bridge.c b/hw/pci/pci_bridge.c index 720119b..2495a51 100644 --- a/hw/pci/pci_bridge.c +++ b/hw/pci/pci_bridge.c @@ -408,6 +408,60 @@ 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 = (uint32_t)-1, + .mem_pref_64 = (uint64_t)-1 + }; + + if (mem_pref_32_reserve != (uint32_t)-1 && + mem_pref_64_reserve == (uint64_t)-1) { + cap.mem_pref_32 = mem_pref_32_reserve; + } else if (mem_pref_32_reserve == (uint32_t)-1 && + mem_pref_64_reserve != (uint64_t)-1) { + cap.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..2d8c635 100644 --- a/include/hw/pci/pci_bridge.h +++ b/include/hw/pci/pci_bridge.h @@ -67,4 +67,28 @@ 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 */ + /* This two fields are mutually exclusive */ + 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 */