From patchwork Sat Aug 5 20:27:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksandr Bezzubikov X-Patchwork-Id: 9883295 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 4BF16603B4 for ; Sat, 5 Aug 2017 20:31:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3DDD32858D for ; Sat, 5 Aug 2017 20:31:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 26A982872D; Sat, 5 Aug 2017 20:31:41 +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 BF4B5285E7 for ; Sat, 5 Aug 2017 20:31:40 +0000 (UTC) Received: from localhost ([::1]:58643 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1de5jX-0008Oo-VX for patchwork-qemu-devel@patchwork.kernel.org; Sat, 05 Aug 2017 16:31:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56937) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1de5g2-0006AK-DQ for qemu-devel@nongnu.org; Sat, 05 Aug 2017 16:28:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1de5g0-00054v-Do for qemu-devel@nongnu.org; Sat, 05 Aug 2017 16:28:02 -0400 Received: from mail-lf0-x242.google.com ([2a00:1450:4010:c07::242]:33914) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1de5g0-00053l-6d for qemu-devel@nongnu.org; Sat, 05 Aug 2017 16:28:00 -0400 Received: by mail-lf0-x242.google.com with SMTP id o85so3072389lff.1 for ; Sat, 05 Aug 2017 13:28:00 -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=PL8+xV0F7+Aeqbl11BcoYp+Li+2ISLsndy0/X6SE358=; b=i8HYhbpcbKkU2tszZC1gkPCPJTkzHWLq5LyhSyZLWcO9ABrfZfzfJpm8cNszXk+pmd PJ8G5EZ9K/1I4uZ9gj9HdWOcH/ZF48ag96ngH5BeBE7Xo+rL0dlthBr3BGmwQNd0fD5H nO9WBShu6ptlK6JiH/+koHrldFHq1eGd16PR8ZoQcyPZrShFSxymUE3TqFUvnjjzA2om TJkq1JSZQX1AytgDS+ofPD0SS5LmMR/t7v0aYmZxX1QPoZvEQWKBc6KfpBYpqrHfxa3Y Bk6bGFw80jNB5iJ/ApKNCoXlC83kij3ZQQ3xz3b34yKYf0VWHNeqrU+HztpC5O1PsQXc 1rdw== 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=PL8+xV0F7+Aeqbl11BcoYp+Li+2ISLsndy0/X6SE358=; b=TFi8l/vB5vSSCbXj8NIw2s4gjAunU7es+u4mpIRh1r8IR5h2TwKZpMqljrIQX0XXtl QfSoa3xXuWe4F46mxuMmUwgfFuX0dJCV/ZkrbCUpz+aBayDLwyPy1uGILxzulPbXm1BJ Q6XmTB/RWLeUpb58ZFLLeBTXB+K1IyAWdu8BdPiqdQky9fISHeHB8/oHRLrAhcOcPxtF zODYlS3PqEyu9ZvgAxbrEuYdn+YOCgTSildiEgmXnnZRfTq1gHe8GUJcoj0OQEYlC3eS cgQ3M/nJo82rd5WTEpo9751UkhK83kE/qYd0QyqsXQJBUR+VebLeqSiVX3Rohmv6egAp UWXA== X-Gm-Message-State: AHYfb5jF8CGDjedMZVQJpt76K8OG9kN7nrHITBzJI/dW7zjYtPcTAXfG xn6bBhjrHO1XxGO/JnA= X-Received: by 10.46.77.77 with SMTP id a74mr2184986ljb.53.1501964878633; Sat, 05 Aug 2017 13:27:58 -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 e42sm1978197lji.81.2017.08.05.13.27.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 05 Aug 2017 13:27:56 -0700 (PDT) From: Aleksandr Bezzubikov To: qemu-devel@nongnu.org Date: Sat, 5 Aug 2017 23:27:36 +0300 Message-Id: <1501964858-5159-4-git-send-email-zuban32s@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1501964858-5159-1-git-send-email-zuban32s@gmail.com> References: <1501964858-5159-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::242 Subject: [Qemu-devel] [PATCH v4 3/5] 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: ehabkost@redhat.com, mst@redhat.com, seabios@seabios.org, Aleksandr Bezzubikov , kevin@koconnor.net, kraxel@redhat.com, pbonzini@redhat.com, marcel@redhat.com, imammedo@redhat.com, lersek@redhat.com, rth@twiddle.net 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 --- hw/pci/pci_bridge.c | 29 +++++++++++++++++++++++++++++ include/hw/pci/pci_bridge.h | 21 +++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/hw/pci/pci_bridge.c b/hw/pci/pci_bridge.c index 720119b..889950d 100644 --- a/hw/pci/pci_bridge.c +++ b/hw/pci/pci_bridge.c @@ -408,6 +408,35 @@ 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, + uint64_t non_pref_mem_reserve, + uint64_t pref_mem_reserve, + Error **errp) +{ + size_t cap_len = sizeof(PCIBridgeQemuCap); + PCIBridgeQemuCap cap = { + .len = cap_len, + .type = REDHAT_PCI_CAP_QEMU_RESERVE, + .bus_res = bus_reserve, + .io = io_reserve, + .mem = non_pref_mem_reserve, + .mem_pref = pref_mem_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..be565f7 100644 --- a/include/hw/pci/pci_bridge.h +++ b/include/hw/pci/pci_bridge.h @@ -67,4 +67,25 @@ 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 */ + uint64_t mem; /* Non-prefetchable memory to reserve */ + uint64_t mem_pref; /* Prefetchable memory to reserve */ +} PCIBridgeQemuCap; + +#define REDHAT_PCI_CAP_QEMU_RESERVE 1 + +int pci_bridge_qemu_reserve_cap_init(PCIDevice *dev, int cap_offset, + uint32_t bus_reserve, uint64_t io_reserve, + uint64_t non_pref_mem_reserve, + uint64_t pref_mem_reserve, + Error **errp); + #endif /* QEMU_PCI_BRIDGE_H */