From patchwork Sat Jul 22 22:11:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksandr Bezzubikov X-Patchwork-Id: 9858225 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 5B90260393 for ; Sat, 22 Jul 2017 22:13:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4ACB12850E for ; Sat, 22 Jul 2017 22:13:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3ADF82851E; Sat, 22 Jul 2017 22:13:27 +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 B624E28509 for ; Sat, 22 Jul 2017 22:13:26 +0000 (UTC) Received: from localhost ([::1]:48496 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dZ2eK-0000Rm-05 for patchwork-qemu-devel@patchwork.kernel.org; Sat, 22 Jul 2017 18:13:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59907) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dZ2dD-0000Qi-UE for qemu-devel@nongnu.org; Sat, 22 Jul 2017 18:12:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dZ2dB-0006kf-HG for qemu-devel@nongnu.org; Sat, 22 Jul 2017 18:12:15 -0400 Received: from mail-lf0-x242.google.com ([2a00:1450:4010:c07::242]:36879) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dZ2dB-0006kQ-9l for qemu-devel@nongnu.org; Sat, 22 Jul 2017 18:12:13 -0400 Received: by mail-lf0-x242.google.com with SMTP id x16so861235lfb.4 for ; Sat, 22 Jul 2017 15:12:13 -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=CmOZwW4vOVXjo1EUJyHCnxM0Fzt7UWfVLonZFjhFXqg=; b=aJjQ10xIoKi82nx50/XffaBRQbCLrnZiT42U+Ihu5ZUtvb9fM/YNfPtkVIG+vru7BR FREQjBpYadYRJc+E16/nbOSKborl6hNSFsQhYIvypZ/sv8/siFUjHYswKxUzysrQ2x2D AFZM9Umf0cqNAYuSAKNwALFbN+3ehp7QYZ8edTTBL45T25xWdc7tkGntW0cDSrwVLYqk 0VeXlnGaYhMJ8S5yaDI2EelcKHYC9AeNVmKGc1qyBqN0EsnpW2SvN9C+y8Cict3oMg3q bJEL98rnPE0mba9H2Rqbc5lGegNlxDmprhEk1oKQPOdNO7OP4NuFTQXRZ2+LnXQcC09O nOoA== 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=CmOZwW4vOVXjo1EUJyHCnxM0Fzt7UWfVLonZFjhFXqg=; b=ZPOcLgyBcBzbiDNs+ntfUSi6ZStGTmipiciJILyMidQzxI4ejN27ZbeQ0i8ahyzF2M A8DtrunimWL6+fruJe9XVKuPZ4jqXGNfZ3rcoQ5c4//DdGD+SLIhco5dPP/cIdvbvIDU qK7TCPh2Tl+PWet8h3AkAperS1cx8SpVb7vTTQiwpHC8u7ubnlXakb5WL4kcLrH6RKnD IdlwV+uaWjDEHvjvxYTkZIxd/5EifWKn3TAwwNDXv2u3j0Hv3v11fD1q+k03m0wTyOoR P0/baxhZJw1DSnqKb0ILMnFj3Ob96Dr4XTRQvl1o50sgqNAfwLrsFMOpahJF4qj0Af0P 3VIg== X-Gm-Message-State: AIVw110OeUsMNE3hJ0BinigkByHp7OFsFLYGC0McGy35nbbosJwbnHAM bF9T3l/D7EKjFg== X-Received: by 10.25.28.77 with SMTP id c74mr3258272lfc.32.1500761532066; Sat, 22 Jul 2017 15:12:12 -0700 (PDT) Received: from localhost.localdomain (broadband-178-140-16-138.moscow.rt.ru. [178.140.16.138]) by smtp.gmail.com with ESMTPSA id s134sm1604053lfe.27.2017.07.22.15.12.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 22 Jul 2017 15:12:10 -0700 (PDT) From: Aleksandr Bezzubikov To: seabios@seabios.org Date: Sun, 23 Jul 2017 01:11:47 +0300 Message-Id: <1500761510-1556-2-git-send-email-zuban32s@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1500761510-1556-1-git-send-email-zuban32s@gmail.com> References: <1500761510-1556-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] [RFC PATCH v2 1/4] pci: refactor pci_find_capapibilty to get bdf as the first argument instead of the whole pci_device 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: konrad.wilk@oracle.com, mst@redhat.com, qemu-devel@nongnu.org, Aleksandr Bezzubikov , kevin@koconnor.net, kraxel@redhat.com, marcel@redhat.com, lersek@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Refactor pci_find_capability function to get bdf instead of a whole pci_device* as the only necessary field for this function is still bdf. It greatly helps when we have bdf but not pci_device. Signed-off-by: Aleksandr Bezzubikov Reviewed-by: Marcel Apfelbaum --- src/fw/pciinit.c | 4 ++-- src/hw/pcidevice.c | 12 ++++++------ src/hw/pcidevice.h | 2 +- src/hw/virtio-pci.c | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/fw/pciinit.c b/src/fw/pciinit.c index 08221e6..864954f 100644 --- a/src/fw/pciinit.c +++ b/src/fw/pciinit.c @@ -762,7 +762,7 @@ static int pci_bus_hotplug_support(struct pci_bus *bus, u8 pcie_cap) return downstream_port && slot_implemented; } - shpc_cap = pci_find_capability(bus->bus_dev, PCI_CAP_ID_SHPC, 0); + shpc_cap = pci_find_capability(bus->bus_dev->bdf, PCI_CAP_ID_SHPC, 0); return !!shpc_cap; } @@ -844,7 +844,7 @@ static int pci_bios_check_devices(struct pci_bus *busses) */ parent = &busses[0]; int type; - u8 pcie_cap = pci_find_capability(s->bus_dev, PCI_CAP_ID_EXP, 0); + u8 pcie_cap = pci_find_capability(s->bus_dev->bdf, PCI_CAP_ID_EXP, 0); int hotplug_support = pci_bus_hotplug_support(s, pcie_cap); for (type = 0; type < PCI_REGION_TYPE_COUNT; type++) { u64 align = (type == PCI_REGION_TYPE_IO) ? diff --git a/src/hw/pcidevice.c b/src/hw/pcidevice.c index cfebf66..d01e27b 100644 --- a/src/hw/pcidevice.c +++ b/src/hw/pcidevice.c @@ -134,25 +134,25 @@ pci_find_init_device(const struct pci_device_id *ids, void *arg) return NULL; } -u8 pci_find_capability(struct pci_device *pci, u8 cap_id, u8 cap) +u8 pci_find_capability(u16 bdf, u8 cap_id, u8 cap) { int i; - u16 status = pci_config_readw(pci->bdf, PCI_STATUS); + u16 status = pci_config_readw(bdf, PCI_STATUS); if (!(status & PCI_STATUS_CAP_LIST)) return 0; if (cap == 0) { /* find first */ - cap = pci_config_readb(pci->bdf, PCI_CAPABILITY_LIST); + cap = pci_config_readb(bdf, PCI_CAPABILITY_LIST); } else { /* find next */ - cap = pci_config_readb(pci->bdf, cap + PCI_CAP_LIST_NEXT); + cap = pci_config_readb(bdf, cap + PCI_CAP_LIST_NEXT); } for (i = 0; cap && i <= 0xff; i++) { - if (pci_config_readb(pci->bdf, cap + PCI_CAP_LIST_ID) == cap_id) + if (pci_config_readb(bdf, cap + PCI_CAP_LIST_ID) == cap_id) return cap; - cap = pci_config_readb(pci->bdf, cap + PCI_CAP_LIST_NEXT); + cap = pci_config_readb(bdf, cap + PCI_CAP_LIST_NEXT); } return 0; diff --git a/src/hw/pcidevice.h b/src/hw/pcidevice.h index 354b549..adcc75a 100644 --- a/src/hw/pcidevice.h +++ b/src/hw/pcidevice.h @@ -69,7 +69,7 @@ int pci_init_device(const struct pci_device_id *ids , struct pci_device *pci, void *arg); struct pci_device *pci_find_init_device(const struct pci_device_id *ids , void *arg); -u8 pci_find_capability(struct pci_device *pci, u8 cap_id, u8 cap); +u8 pci_find_capability(u16 bdf, u8 cap_id, u8 cap); void pci_enable_busmaster(struct pci_device *pci); u16 pci_enable_iobar(struct pci_device *pci, u32 addr); void *pci_enable_membar(struct pci_device *pci, u32 addr); diff --git a/src/hw/virtio-pci.c b/src/hw/virtio-pci.c index e5c2c33..4e33033 100644 --- a/src/hw/virtio-pci.c +++ b/src/hw/virtio-pci.c @@ -381,7 +381,7 @@ fail: void vp_init_simple(struct vp_device *vp, struct pci_device *pci) { - u8 cap = pci_find_capability(pci, PCI_CAP_ID_VNDR, 0); + u8 cap = pci_find_capability(pci->bdf, PCI_CAP_ID_VNDR, 0); struct vp_cap *vp_cap; const char *mode; u32 offset, base, mul; @@ -479,7 +479,7 @@ void vp_init_simple(struct vp_device *vp, struct pci_device *pci) vp_cap->cap, type, vp_cap->bar, addr, offset, mode); } - cap = pci_find_capability(pci, PCI_CAP_ID_VNDR, cap); + cap = pci_find_capability(pci->bdf, PCI_CAP_ID_VNDR, cap); } if (vp->common.cap && vp->notify.cap && vp->isr.cap && vp->device.cap) {