From patchwork Thu Aug 16 04:11:03 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yinghai Lu X-Patchwork-Id: 1329681 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 9B0723FC81 for ; Thu, 16 Aug 2012 04:11:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750950Ab2HPELG (ORCPT ); Thu, 16 Aug 2012 00:11:06 -0400 Received: from mail-vc0-f174.google.com ([209.85.220.174]:54305 "EHLO mail-vc0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750829Ab2HPELF (ORCPT ); Thu, 16 Aug 2012 00:11:05 -0400 Received: by vcbfk26 with SMTP id fk26so2076128vcb.19 for ; Wed, 15 Aug 2012 21:11:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; bh=kFWrfSXMXcsLdGlvmAXhdA8uGKYHyusJl9d52H1E0kM=; b=iGsHDE4KLkaz5ItgdCTA6XHSXUt/f/WflFkFvFb/yUQbKop7Q6qDQ1MG4gWGxElRNW YqWmFYPxXqddAwaTBLpWXeo/PUjvuNenQ6213AtKg7CY6kDMojUOoNNTg9xaPsqHKLiD uphj99FLU8ngtxjZ71Q+tgGtuWu9u6FlRrf1Av8rQ5gp/JBesvF+nO6lUW0Ca5k9/Ghb ER4AsbsRMc61JJCShTia1aigB+QhueS9i2BwdlNWHtzuKBB+9Yopn54/5BM0iLIvSnmm bsEx1gdKwik1+cV/ygDbYjRDdO1tSa86aNQj+CWD4hRtbHGOW9fWUvIU4gfdmCONA4xv 3roQ== MIME-Version: 1.0 Received: by 10.220.248.69 with SMTP id mf5mr14013973vcb.42.1345090263869; Wed, 15 Aug 2012 21:11:03 -0700 (PDT) Received: by 10.52.37.9 with HTTP; Wed, 15 Aug 2012 21:11:03 -0700 (PDT) In-Reply-To: <20120816032602.GN2449@ram-ThinkPad-T61> References: <20120618050333.GA13469@ram-ThinkPad-T61> <20120816032602.GN2449@ram-ThinkPad-T61> Date: Wed, 15 Aug 2012 21:11:03 -0700 X-Google-Sender-Auth: Z4wxZW7PYShTlH4QZy0TUtnESQk Message-ID: Subject: Re: [RFC PATCH] methods to access resources of a struct pci_dev From: Yinghai Lu To: Ram Pai Cc: Bjorn Helgaas , linux-pci@vger.kernel.org Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org On Wed, Aug 15, 2012 at 8:26 PM, Ram Pai wrote: > On Wed, Aug 15, 2012 at 03:25:06PM -0600, Bjorn Helgaas wrote: > > I am fine with this approach. I have never encountered the need for 'no' > based iterator like 'for_each_pci_dev_noiov_resource' or > 'for_each_pci_dev_base_norom_resource'. While abstracting the code and > replacing explicit references to the resources in various peices of code > including the drivers, I just encountered the need for the 'yes' based > iterators like the one that I added. > > However if there is a need for 'no' based iterators, it should be easy > to incorporate them using flags. Something like > > for_each_pci_resource(dev, res, i, flags) > > where flags can be > #define PCI_STD_RES 0x01 > #define PCI_ROM_RES 0x02 > #define PCI_BRIDGE_RES 0x04 > #define PCI_IOV_RES 0x08 > #define PCI_ALL_RES PCI_STD_RES|PCI_ROM_RES|PCI_BRIDGE_RES|PCI_IOV_RES > #define PCI_NOSTD_RES PCI_ALL_RES&(^PCI_STD_RES) > #define PCI_NOIOV_RES PCI_ALL_RES&(^PCI_IOV_RES) > so on and so forth > > Yinghai if you are ok with this approach, let me code up all the > iterators. You can incorporate your patches based on those iterators and > I can change all my 40+ patches that change various driver sources to > use this iterator. Do you mean that you will have updated patch for http://git.kernel.org/?p=linux/kernel/git/yinghai/linux-yinghai.git;a=commitdiff;h=cd192f0ed93203ef6bac2a44c138899190fb5793 ? if it is that case, i am ok, and then I could use scripts to update following patches. From cd192f0ed93203ef6bac2a44c138899190fb5793 Mon Sep 17 00:00:00 2001 From: Yinghai Lu Date: Tue, 26 Jun 2012 17:02:04 -0700 Subject: [PATCH] PCI: Add for_each_resource helpers to make resource loop easier. Signed-off-by: Yinghai Lu --- include/linux/pci.h | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 55 insertions(+), 0 deletions(-) { #ifdef CONFIG_PCI_IOV diff --git a/include/linux/pci.h b/include/linux/pci.h index 77778cb..dd577e3 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -363,6 +363,61 @@ struct pci_dev { struct resource *pci_dev_resource_n(struct pci_dev *dev, int n); +#define resno_is_for_bridge(n) \ + ((n) >= PCI_BRIDGE_RESOURCES && (n) <= PCI_BRIDGE_RESOURCE_END) + +/* all (include bridge) resources */ +#define for_each_pci_dev_all_resource(dev, res, i) \ + for (i = 0; \ + (res = pci_dev_resource_n(dev, i)) || i < PCI_NUM_RESOURCES; \ + i++) +/* exclude bridge resources */ +#define for_each_pci_dev_nobridge_resource(dev, res, i) \ + for (i = 0; \ + (res = pci_dev_resource_n(dev, i)) || i < PCI_NUM_RESOURCES; \ + i = (i != (PCI_BRIDGE_RESOURCES - 1)) ? (i+1) : PCI_NUM_RESOURCES) +/* exclude bridge and IOV resources */ +#define for_each_pci_dev_base_resource(dev, res, i) \ + for (i = 0; \ + (res = pci_dev_resource_n(dev, i)) || i < PCI_NUM_RESOURCES; \ + i = (i != PCI_ROM_RESOURCE) ? (i+1) : PCI_NUM_RESOURCES) +/* exclude ROM and bridge and IOV resources */ +#define for_each_pci_dev_base_norom_resource(dev, res, i) \ + for (i = 0; \ + (res = pci_dev_resource_n(dev, i)) || i < PCI_NUM_RESOURCES; \ + i = (i != (PCI_ROM_RESOURCE-1)) ? (i+1) : PCI_NUM_RESOURCES) +/* exclude ROM and bridge resources */ +#define for_each_pci_dev_base_iov_norom_resource(dev, res, i) \ + for (i = 0; \ + (res = pci_dev_resource_n(dev, i)) || i < PCI_NUM_RESOURCES; \ + i = (i != (PCI_ROM_RESOURCE-1) && i != (PCI_BRIDGE_RESOURCES-1)) ? (i+1) : \ + ((i == PCI_ROM_RESOURCE-1) ? (PCI_ROM_RESOURCE+1) : PCI_NUM_RESOURCES)) +/* exclude IOV resources */ +#define for_each_pci_dev_noiov_resource(dev, res, i) \ + for (i = 0; \ + (res = pci_dev_resource_n(dev, i)) || i < PCI_NUM_RESOURCES; \ + i = (i != PCI_ROM_RESOURCE) ? (i+1) : PCI_BRIDGE_RESOURCES) +/* only std resources */ +#define for_each_pci_dev_std_resource(dev, res, i) \ + for (i = PCI_STD_RESOURCES; \ + (res = pci_dev_resource_n(dev, i)) && i < (PCI_STD_RESOURCE_END+1); \ + i++) +/* only IOV resources */ +#define for_each_pci_dev_iov_resource(dev, res, i) \ + for (i = PCI_IOV_RESOURCES; \ + (res = pci_dev_resource_n(dev, i)) && i < (PCI_IOV_RESOURCE_END+1); \ + i++) +/* only bridge resources */ +#define for_each_pci_dev_bridge_resource(dev, res, i) \ + for (i = PCI_BRIDGE_RESOURCES; \ + (res = pci_dev_resource_n(dev, i)) && i < (PCI_BRIDGE_RESOURCE_END+1); \ + i++) +/* only addon resources */ +#define for_each_pci_dev_addon_resource(dev, res, i) \ + for (i = PCI_NUM_RESOURCES; \ + (res = pci_dev_resource_n(dev, i)); \ + i++) + static inline struct pci_dev *pci_physfn(struct pci_dev *dev)