From patchwork Thu Feb 3 23:24:13 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduard - Gabriel Munteanu X-Patchwork-Id: 81741 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 73CC6B70E7 for ; Fri, 4 Feb 2011 10:28:55 +1100 (EST) Received: from localhost ([127.0.0.1]:36697 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Pl8aS-0003mD-VC for incoming@patchwork.ozlabs.org; Thu, 03 Feb 2011 18:27:41 -0500 Received: from [140.186.70.92] (port=47886 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Pl8XX-0002wl-QN for qemu-devel@nongnu.org; Thu, 03 Feb 2011 18:24:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Pl8XU-0006gX-EW for qemu-devel@nongnu.org; Thu, 03 Feb 2011 18:24:38 -0500 Received: from mail-fx0-f45.google.com ([209.85.161.45]:46451) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Pl8XU-0006fw-9x for qemu-devel@nongnu.org; Thu, 03 Feb 2011 18:24:36 -0500 Received: by mail-fx0-f45.google.com with SMTP id 12so1833048fxm.4 for ; Thu, 03 Feb 2011 15:24:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:sender:from:to:cc:subject:date:message-id :x-mailer:in-reply-to:references:in-reply-to:references; bh=XAIMot6ML1aBrMvGUHYSnZIBXrYAafAOBsGoN2cgXG0=; b=SEMUbMfex16v1Z/sMnh6zXvTn+hqsgyifPdLtnd8gsxWnL7v4/GKOCU3CtNCD0+Ezr c7hmx4B+vaCaE3TyhSyPRkolZZkvlJ9vdGzWjbyBwtYUpuCETol9m2uWK5+Up1sqYzTe lnhh+pL7WuXpr3xq8P8IbgU9RemRHNzwYS098= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; b=ZJHRxMtD95wdl7+BE+oOaD509UleMQRTlETKdCapLSj8iKQezzBWvwP/Ebb1+SG3LF grqO57Q1adnbBHAdFcnbYECUGf5PV5hNDb9qUDvGDGTt7WcUMGGOvVl+2nS+StuH43uV SLO+Uqz+oTvj9WYdFi5uz5T08N3FLRQYl0dA4= Received: by 10.223.112.79 with SMTP id v15mr10627830fap.143.1296775475936; Thu, 03 Feb 2011 15:24:35 -0800 (PST) Received: from localhost.localdomain ([188.25.245.29]) by mx.google.com with ESMTPS id b7sm15819faa.42.2011.02.03.15.24.32 (version=SSLv3 cipher=RC4-MD5); Thu, 03 Feb 2011 15:24:33 -0800 (PST) From: Eduard - Gabriel Munteanu To: seabios@seabios.org Date: Fri, 4 Feb 2011 01:24:13 +0200 Message-Id: X-Mailer: git-send-email 1.7.3.4 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.161.45 Cc: kvm@vger.kernel.org, mst@redhat.com, joro@8bytes.org, qemu-devel@nongnu.org, blauwirbel@gmail.com, yamahata@valinux.co.jp, kevin@koconnor.net, avi@redhat.com, Eduard - Gabriel Munteanu , paul@codesourcery.com Subject: [Qemu-devel] [PATCH 1/3] pci: add pci_find_capability() helper X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org pci_find_capability() looks up a given capability and returns its offset. This is needed by AMD IOMMU initialization code. Signed-off-by: Eduard - Gabriel Munteanu --- src/pci.c | 15 +++++++++++++++ src/pci.h | 1 + 2 files changed, 16 insertions(+), 0 deletions(-) diff --git a/src/pci.c b/src/pci.c index 944a393..57caba6 100644 --- a/src/pci.c +++ b/src/pci.c @@ -185,6 +185,21 @@ pci_find_class(u16 classid) return -1; } +int pci_find_capability(int bdf, u8 capid) +{ + int ptr, cap; + + ptr = PCI_CAPABILITY_LIST; + do { + cap = pci_config_readb(bdf, ptr); + if (pci_config_readb(bdf, cap) == capid) + return cap; + ptr = cap + PCI_CAP_LIST_NEXT; + } while (cap); + + return -1; +} + int *PCIpaths; // Build the PCI path designations. diff --git a/src/pci.h b/src/pci.h index 9869a26..bf0d1b8 100644 --- a/src/pci.h +++ b/src/pci.h @@ -46,6 +46,7 @@ void pci_config_maskw(u16 bdf, u32 addr, u16 off, u16 on); int pci_find_vga(void); int pci_find_device(u16 vendid, u16 devid); int pci_find_class(u16 classid); +int pci_find_capability(int bdf, u8 capid); #define PP_ROOT (1<<17) #define PP_PCIBRIDGE (1<<18)