All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yinghai Lu <yinghai@kernel.org>
To: Ram Pai <linuxram@us.ibm.com>
Cc: linux-pci@vger.kernel.org, Bjorn Helgaas <bhelgaas@google.com>
Subject: Re: [RFC PATCH v2 ]pci: pci resource iterator
Date: Tue, 21 Aug 2012 16:22:52 -0700	[thread overview]
Message-ID: <CAE9FiQUW2rB8X18=X6hVb-ZV8AnoL4RA+8P7897vHxwjj63bsg@mail.gmail.com> (raw)
In-Reply-To: <20120821151245.GA2356@ram-ThinkPad-T61>

[-- Attachment #1: Type: text/plain, Size: 2007 bytes --]

On Tue, Aug 21, 2012 at 8:13 AM, Ram Pai <linuxram@us.ibm.com> wrote:
> PCI: pci resource iterator
>
> Currently pci_dev structure holds an array of 17 PCI resources; six base
> BARs, one ROM BAR, four BRIDGE BARs, six sriov BARs.  This is wasteful.
> A bridge device just needs the 4 bridge resources. A non-bridge device
> just needs the six base resources and one ROM resource. The sriov
> resources are needed only if the device has SRIOV capability.
>
> The pci_dev structure needs to be re-organized to avoid unnecessary
> bloating.  However too much code outside the pci-bus driver, assumes the
> internal details of the pci_dev structure, thus making it hard to
> re-organize the datastructure.
>
> As a first step this patch provides generic methods to access the
> resource structure of the pci_dev.
>
> Once this patch is accepted, I have another 40+ patches that modify all
> the files that directly access the resource structure, to use the new
> methods provided in the first step.
>
> Finally we can re-organize the resource structure in the pci_dev
> structure and correspondingly update the methods.
>
> This patch is compile tested only.
>
> Changelog:
>         Consolidated iterator interface as per Bjorn's suggestion.
>
> +#define for_each_pci_resource(dev, res, flag) \
> +       for (res = pci_next_resource(dev, NULL, flag); res; \
> +                       res = pci_next_resource(dev, res, flag))
> +

We may need to keep the idx, so we could make the converting more granularity.

because some loop body is still using the idx.

also there is some abusing pci bridge resource as addon resources.
and we need to remove the abusing at first ---
that is addressed by:
http://git.kernel.org/?p=linux/kernel/git/yinghai/linux-yinghai.git;a=commitdiff;h=5eb48c3c998257386f67a7570778872ec600138f

 PCI: Add addon_resource support for pci_dev

and later we may remove the idx in the for_each_pci_resource()

Please check updated version of your patch that keep the idx.

Thanks

Yinghai

[-- Attachment #2: ram_pci_it_v3.patch --]
[-- Type: application/octet-stream, Size: 3340 bytes --]

From: Ram Pai <linuxram@us.ibm.com>
To: linux-pci@vger.kernel.org
Cc: Yinghai Lu <yinghai@kernel.org>, Bjorn Helgaas <bhelgaas@google.com>
Subject: [RFC PATCH v3]pci: pci resource iterator

Currently pci_dev structure holds an array of 17 PCI resources; six base
BARs, one ROM BAR, four BRIDGE BARs, six sriov BARs.  This is wasteful.
A bridge device just needs the 4 bridge resources. A non-bridge device
just needs the six base resources and one ROM resource. The sriov
resources are needed only if the device has SRIOV capability.

The pci_dev structure needs to be re-organized to avoid unnecessary
bloating.  However too much code outside the pci-bus driver, assumes the
internal details of the pci_dev structure, thus making it hard to
re-organize the datastructure.

As a first step this patch provides generic methods to access the
resource structure of the pci_dev.

Once this patch is accepted, I have another 40+ patches that modify all
the files that directly access the resource structure, to use the new
methods provided in the first step.

Finally we can re-organize the resource structure in the pci_dev
structure and correspondingly update the methods.

This patch is compile tested only.

Changelog:
	Consolidated iterator interface as per Bjorn's suggestion.

-v3: add the idx back

Signed-off-by: Ram Pai <linuxram@us.ibm.com>

---
 include/linux/pci.h |   41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

Index: linux-2.6/include/linux/pci.h
===================================================================
--- linux-2.6.orig/include/linux/pci.h
+++ linux-2.6/include/linux/pci.h
@@ -1410,6 +1410,47 @@ static inline struct pci_dev *pci_dev_ge
 	 (pci_resource_end((dev), (bar)) -		\
 	  pci_resource_start((dev), (bar)) + 1))
 
+#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)
+#define PCI_NOROM_RES		(PCI_ALL_RES & ^PCI_ROM_RES)
+#define PCI_NOBRIDGE_RES	(PCI_ALL_RES & ^PCI_BRIDGE_RES)
+#define PCI_STD_ROM_RES		(PCI_STD_RES | PCI_ROM_RES)
+#define PCI_STD_IOV_RES		(PCI_STD_RES | PCI_IOV_RES)
+#define PCI_STD_ROM_IOV_RES	(PCI_STD_RES | PCI_ROM_RES | PCI_IOV_RES)
+
+static inline struct resource *pci_next_resource(struct pci_dev *pdev,
+			struct resource *res, int flag, int *next_i)
+{
+	int i = *next_i;
+
+	while (++i < PCI_NUM_RESOURCES) {
+		if ((i >= 0 && i < PCI_ROM_RESOURCE) && (flag & PCI_STD_RES))
+			goto found;
+		else if ((i == PCI_ROM_RESOURCE) && (flag & PCI_ROM_RES))
+			goto found;
+		else if ((i <= PCI_IOV_RESOURCE_END) && (flag & PCI_IOV_RES))
+			goto found;
+		else if ((i <= PCI_BRIDGE_RESOURCE_END) && (flag & PCI_BRIDGE_RES))
+			goto found;
+	}
+
+	*next_id = -1;
+	return NULL;
+
+found:
+	*next_id = i;
+	return pci_dev_resource_n(i);
+}
+
+#define for_each_pci_resource(dev, res, i, flag) \
+	for (i = -1, res = pci_next_resource(dev, NULL, flag, &i); res; \
+			res = pci_next_resource(dev, res, flag, &i))
+
 /* Similar to the helpers above, these manipulate per-pci_dev
  * driver-specific data.  They are really just a wrapper around
  * the generic device structure functions of these calls.

  reply	other threads:[~2012-08-21 23:22 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-18  5:03 [RFC PATCH] methods to access resources of a struct pci_dev Ram Pai
2012-06-18 18:30 ` Yinghai Lu
2012-06-19  1:46   ` Ram Pai
2012-06-19  2:57     ` Yinghai Lu
2012-08-15 21:25   ` Bjorn Helgaas
2012-08-16  3:26     ` Ram Pai
2012-08-16  4:11       ` Yinghai Lu
2012-08-16  4:41         ` Ram Pai
2012-08-21 15:13           ` [RFC PATCH v2 ]pci: pci resource iterator Ram Pai
2012-08-21 23:22             ` Yinghai Lu [this message]
2012-08-22 10:15               ` Ram Pai
2012-08-22 17:31                 ` Yinghai Lu
2012-08-22 17:35                   ` Yinghai Lu
2012-08-23  0:28                     ` Yinghai Lu
2012-08-23  5:09                       ` [RFC PATCH v3 " Ram Pai
2012-08-23 19:30                         ` Yinghai Lu
2012-08-27  7:33                           ` Ram Pai
2012-09-03  8:07                             ` Yinghai Lu
2012-09-03  9:08                               ` Ram Pai
2012-09-03 18:20                                 ` Yinghai Lu
2012-09-04  3:27                                   ` Ram Pai
2012-09-18  0:03                                     ` Yinghai Lu
2012-09-21  6:18                                       ` Ram Pai
2012-09-21  6:27                                         ` Yinghai Lu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAE9FiQUW2rB8X18=X6hVb-ZV8AnoL4RA+8P7897vHxwjj63bsg@mail.gmail.com' \
    --to=yinghai@kernel.org \
    --cc=bhelgaas@google.com \
    --cc=linux-pci@vger.kernel.org \
    --cc=linuxram@us.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.