From patchwork Fri Apr 12 22:44:18 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yinghai Lu X-Patchwork-Id: 2438521 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 442653FD1A for ; Fri, 12 Apr 2013 22:47:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757830Ab3DLWrq (ORCPT ); Fri, 12 Apr 2013 18:47:46 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:47878 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757803Ab3DLWrp (ORCPT ); Fri, 12 Apr 2013 18:47:45 -0400 Received: from ucsinet21.oracle.com (ucsinet21.oracle.com [156.151.31.93]) by userp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id r3CMilAJ032635 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 12 Apr 2013 22:44:48 GMT Received: from acsmt358.oracle.com (acsmt358.oracle.com [141.146.40.158]) by ucsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r3CMikeh023947 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 12 Apr 2013 22:44:47 GMT Received: from abhmt115.oracle.com (abhmt115.oracle.com [141.146.116.67]) by acsmt358.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id r3CMik1q001670; Fri, 12 Apr 2013 17:44:46 -0500 Received: from linux-siqj.site (/10.132.126.191) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 12 Apr 2013 15:44:46 -0700 From: Yinghai Lu To: Bjorn Helgaas , Ram Pai Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Yinghai Lu Subject: [PATCH v4 04/29] PCI: Add pci_dev_resource_idx() helper Date: Fri, 12 Apr 2013 15:44:18 -0700 Message-Id: <1365806683-26717-5-git-send-email-yinghai@kernel.org> X-Mailer: git-send-email 1.8.1.4 In-Reply-To: <1365806683-26717-1-git-send-email-yinghai@kernel.org> References: <1365806683-26717-1-git-send-email-yinghai@kernel.org> X-Source-IP: ucsinet21.oracle.com [156.151.31.93] Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Use resource pointer to get index in pci resources array/list. -v2: export symbol for acpiphp compiling error, found by Steven Newbury Signed-off-by: Yinghai Lu --- drivers/pci/probe.c | 9 +++++++++ include/linux/pci.h | 1 + 2 files changed, 10 insertions(+) diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index 9cb3eb3..1df75f7 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -114,6 +114,15 @@ struct resource *pci_dev_resource_n(struct pci_dev *dev, int n) } EXPORT_SYMBOL(pci_dev_resource_n); +int pci_dev_resource_idx(struct pci_dev *dev, struct resource *res) +{ + if (res >= dev->resource && + res <= dev->resource + (PCI_NUM_RESOURCES - 1)) + return res - dev->resource; + + return -1; +} + static u64 pci_size(u64 base, u64 maxbase, u64 mask) { u64 size = mask & maxbase; /* Find the significant bits */ diff --git a/include/linux/pci.h b/include/linux/pci.h index 6d450d2..f4da78d 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -354,6 +354,7 @@ struct pci_dev { }; struct resource *pci_dev_resource_n(struct pci_dev *dev, int n); +int pci_dev_resource_idx(struct pci_dev *dev, struct resource *res); static inline struct pci_dev *pci_physfn(struct pci_dev *dev) {