From patchwork Fri Jul 28 23:37:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksandr Bezzubikov X-Patchwork-Id: 9869683 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 AD60A6038F for ; Fri, 28 Jul 2017 23:45:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A2C5C2889C for ; Fri, 28 Jul 2017 23:45:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9546D288E5; Fri, 28 Jul 2017 23:45:55 +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 1A7E82889C for ; Fri, 28 Jul 2017 23:45:54 +0000 (UTC) Received: from localhost ([::1]:50590 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dbEwV-0003qd-Sn for patchwork-qemu-devel@patchwork.kernel.org; Fri, 28 Jul 2017 19:45:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59294) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dbEpY-0004AM-Lr for qemu-devel@nongnu.org; Fri, 28 Jul 2017 19:38:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dbEpX-0002QK-F5 for qemu-devel@nongnu.org; Fri, 28 Jul 2017 19:38:04 -0400 Received: from mail-lf0-x241.google.com ([2a00:1450:4010:c07::241]:33692) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dbEpX-0002Pb-5S for qemu-devel@nongnu.org; Fri, 28 Jul 2017 19:38:03 -0400 Received: by mail-lf0-x241.google.com with SMTP id 65so7022429lfa.0 for ; Fri, 28 Jul 2017 16:38:02 -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=Bw3NM/OhB/t10s8w4nv7tzL1p8wu17CGVQKoWKt5CC8=; b=MjErMsHUEIJ06CvtgzM17zUaGbf3tRy6qNfxwpGVY8plMTUqjmENApYucIUWygUHnt lelGHVmgEnTfJg4pHRtO5dway5rZvEw1fqlJ6Nr1pQTE9q9qLq2H2FFNwVP0GLtigzoZ XSQ9EuB2Tdiwr0/WmplmBvDv30smwXv9PAmwojfo2bvxtwoHFeVxyssnUqDpIzEllYEF I70eJhHdj0kcLOD4vdK/fOxcDU7gNGrSWiCOMZ0tAfUq0/6pKXQFEt2EXOeBLZXRW7MC J61GiWfgJPOWE8RNNZRr0vZKBZDIuxTAdRZHgUDiEmJBRy0GV9n5x78jRoqg6+mjtMjb vZkQ== 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=Bw3NM/OhB/t10s8w4nv7tzL1p8wu17CGVQKoWKt5CC8=; b=jK+G0ZaBdTS4T4vVzfIhwYy8cRRTgLPsk16pbT3dXsIcFhPrvOLjGwzlqJWHXt4JvB fYAW5ttehnswbPqYxZDIn50PVRGOiwM208j8ekBf/g0dnasvTHN/tbLmk6J32c1W4e1f wCHvUi7nc2wAmzLjASz3CjDKa5AGC1Uc/R5KJYzZLvjR8R3xCucYOS0k4GFwtHkCv93N tD5zGNNbAMEwts5IIBZ4NXDAR+jxQ8JMOoe5wTFc+QtPQlYHU3inGE9MJJP5jQ+Tjn02 qlHg7Fex5yklefYh3psxodZDlGtxMt9Rt/SlrV7KhyQypmETxlaE1tSHMqVe/00wtQ34 l9ow== X-Gm-Message-State: AIVw113JkcaIkqyhksAz13m34d3ZeREaOArFJzhGhRtq8YaahbURkniq xAoeZCQA2UYdJB/xeC4= X-Received: by 10.46.83.17 with SMTP id h17mr1961116ljb.186.1501285081534; Fri, 28 Jul 2017 16:38:01 -0700 (PDT) Received: from localhost.localdomain (broadband-95-84-133-8.moscow.rt.ru. [95.84.133.8]) by smtp.gmail.com with ESMTPSA id v126sm732360lfa.21.2017.07.28.16.38.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 28 Jul 2017 16:38:00 -0700 (PDT) From: Aleksandr Bezzubikov To: qemu-devel@nongnu.org Date: Sat, 29 Jul 2017 02:37:51 +0300 Message-Id: <1501285073-2215-4-git-send-email-zuban32s@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1501285073-2215-1-git-send-email-zuban32s@gmail.com> References: <1501285073-2215-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 v3 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 to reserve, IO, memory and prefetchable memory limits. QEMU can provide this with a special vendor-specific PCI capability. Signed-off-by: Aleksandr Bezzubikov --- hw/pci/pci_bridge.c | 37 +++++++++++++++++++++++++++++++++++++ include/hw/pci/pci_bridge.h | 28 ++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/hw/pci/pci_bridge.c b/hw/pci/pci_bridge.c index 720119b..e9f12d6 100644 --- a/hw/pci/pci_bridge.c +++ b/hw/pci/pci_bridge.c @@ -408,6 +408,43 @@ void pci_bridge_map_irq(PCIBridge *br, const char* bus_name, br->bus_name = bus_name; } + +int pci_bridge_qemu_cap_init(PCIDevice *dev, int cap_offset, + uint8_t bus_reserve, uint32_t io_reserve, + uint16_t non_pref_reserve, uint64_t pref_reserve, + Error **errp) +{ + size_t cap_len = sizeof(PCIBridgeQemuCap); + PCIBridgeQemuCap cap = { + .len = cap_len, + .type = REDHAT_PCI_CAP_QEMU, + .bus_res = bus_reserve, + .non_pref_16 = non_pref_reserve + }; + + if ((uint8_t)io_reserve == io_reserve) { + cap.io_8 = io_reserve; + } else { + cap.io_32 = io_reserve; + } + if ((uint16_t)pref_reserve == pref_reserve) { + cap.pref_32 = pref_reserve; + } else { + cap.pref_64 = pref_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..e9b7cf4 100644 --- a/include/hw/pci/pci_bridge.h +++ b/include/hw/pci/pci_bridge.h @@ -67,4 +67,32 @@ 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 */ + + uint16_t non_pref_16; /* Non-prefetchable memory limit */ + uint8_t bus_res; /* Minimum number of buses to reserve */ + uint8_t io_8; /* IO space limit in case of 8-bit value */ + uint32_t io_32; /* IO space limit in case of 32-bit value + This 2 values are mutually exclusive, + i.e. they can't be >0 both*/ + uint32_t pref_32; /* Prefetchable memory limit + in case of 32-bit value */ + uint64_t pref_64; /* Prefetchable memory limit + in case of 64-bit value + This 2 values are mutually exclusive (just as + IO limit), i.e. they can't be >0 both */ +} PCIBridgeQemuCap; + +#define REDHAT_PCI_CAP_QEMU 1 + +int pci_bridge_qemu_cap_init(PCIDevice *dev, int cap_offset, + uint8_t bus_reserve, uint32_t io_reserve, + uint16_t mem_reserve, uint64_t pref_reserve, + Error **errp); + #endif /* QEMU_PCI_BRIDGE_H */