From patchwork Wed Jul 19 13:20:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksandr Bezzubikov X-Patchwork-Id: 9852019 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 54776602C8 for ; Wed, 19 Jul 2017 13:21:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 42EB3285F0 for ; Wed, 19 Jul 2017 13:21:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 37AC42867F; Wed, 19 Jul 2017 13:21:38 +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 DB4BB285F0 for ; Wed, 19 Jul 2017 13:21:37 +0000 (UTC) Received: from localhost ([::1]:33454 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXov3-000789-4W for patchwork-qemu-devel@patchwork.kernel.org; Wed, 19 Jul 2017 09:21:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38834) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXou0-00075M-0c for qemu-devel@nongnu.org; Wed, 19 Jul 2017 09:20:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dXotv-0006DQ-AZ for qemu-devel@nongnu.org; Wed, 19 Jul 2017 09:20:32 -0400 Received: from mail-lf0-x242.google.com ([2a00:1450:4010:c07::242]:33620) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dXotv-0006CI-3i for qemu-devel@nongnu.org; Wed, 19 Jul 2017 09:20:27 -0400 Received: by mail-lf0-x242.google.com with SMTP id t72so4308340lff.0 for ; Wed, 19 Jul 2017 06:20:25 -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=hXT/RcM25hb7HQyY+MfGQuIQ/PhxWfwZ8gW2c/ejC6M=; b=r66H96KqepMsVEthzS6DK63a6c33w9LAcskuggKAmPBXGJ704wu3Dkv0g7TKu7XT9D tQLTyCNOUNDf7m4lP2OA6X15v0cdZ3v483vgC7OjJOuFKkEoyuQWzMrgLa578jkNXw1g h4CFzh/TaKKA5B6+vvDDDJRIqmU7hNE+MGhwdeMbBC92gf3wTk04JPWIunoqhZW5mxbk R+YzPUE+x4eJGImzuOfIm8xjPSc9KFZaL79DmXZh/5j2GVMV6oRByMdFtVHnU9iKqGuN Uo7ntWBP0fIXW0Eu0JZMiW0oP2x94UpBbyQtsW9ytrUADalxcDFMM29Px22vvm463Jdf quvg== 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=hXT/RcM25hb7HQyY+MfGQuIQ/PhxWfwZ8gW2c/ejC6M=; b=q2MZge0lZh7HojKzYXDLSbIyePXZQMuCuCxH2UqNYeuVkZCSR35f4f9LW0es2wMib1 LJAgH4TY9Yy6RvKN5aGfJnlSUR9Bj1Um8woTiQhJlntf/mJeZHJrOTajGcc0RmTmu7Ua 1VsSA3Xf3fFeX1meuxn5o8ZycbAvdrfRn+l28zX54O9e1jAOASrW9vbgKRMpCfgTdpd+ j5r7YzQrHh2aGtaw70yYnbXo3lrKXBs6XsYz2CD0v7MbS/uEv12eFq6vmG0vW1om6H40 BxQFqomPEhDwj96VfBimdsXJOI+VY5yEgdPAGrcyDF6xNnSm+pLlc/rHEg+mWmfgWkJx SuGQ== X-Gm-Message-State: AIVw111fALyQLydgPDVSDzUTYBqzzHPJ13fIeHPZJqCW7Nnf/73VibQk HoMdCD+zZuKi9g== X-Received: by 10.46.82.142 with SMTP id n14mr33086lje.0.1500470424481; Wed, 19 Jul 2017 06:20:24 -0700 (PDT) Received: from zuban32-isp.intra.ispras.ru (bran.ispras.ru. [83.149.199.196]) by smtp.gmail.com with ESMTPSA id 62sm6826lfz.20.2017.07.19.06.20.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 19 Jul 2017 06:20:23 -0700 (PDT) From: Aleksandr Bezzubikov To: seabios@seabios.org Date: Wed, 19 Jul 2017 16:20:13 +0300 Message-Id: <1500470414-7911-2-git-send-email-zuban32s@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1500470414-7911-1-git-send-email-zuban32s@gmail.com> References: <1500470414-7911-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 1/2] pci: add support for direct usage of bdf for capability lookup 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, qemu-devel@nongnu.org, Aleksandr Bezzubikov Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Add a capability lookup function which gets bdf instead of pci_device as its first argument. It may be useful when we have bdf, but don't have the whole pci_device structure. Signed-off-by: Aleksandr Bezzubikov --- src/hw/pcidevice.c | 24 ++++++++++++++++++++++++ src/hw/pcidevice.h | 1 + 2 files changed, 25 insertions(+) diff --git a/src/hw/pcidevice.c b/src/hw/pcidevice.c index cfebf66..3fa240e 100644 --- a/src/hw/pcidevice.c +++ b/src/hw/pcidevice.c @@ -158,6 +158,30 @@ u8 pci_find_capability(struct pci_device *pci, u8 cap_id, u8 cap) return 0; } +u8 pci_find_capability_bdf(int bdf, u8 cap_id, u8 cap) +{ + int i; + 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(bdf, PCI_CAPABILITY_LIST); + } else { + /* find next */ + cap = pci_config_readb(bdf, cap + PCI_CAP_LIST_NEXT); + } + for (i = 0; cap && i <= 0xff; i++) { + if (pci_config_readb(bdf, cap + PCI_CAP_LIST_ID) == cap_id) + return cap; + cap = pci_config_readb(bdf, cap + PCI_CAP_LIST_NEXT); + } + + return 0; +} + // Enable PCI bus-mastering (ie, DMA) support on a pci device void pci_enable_busmaster(struct pci_device *pci) diff --git a/src/hw/pcidevice.h b/src/hw/pcidevice.h index 354b549..e4ed5cf 100644 --- a/src/hw/pcidevice.h +++ b/src/hw/pcidevice.h @@ -70,6 +70,7 @@ int pci_init_device(const struct pci_device_id *ids 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_bdf(int 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);