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: Wed, 22 Aug 2012 17:28:32 -0700 [thread overview]
Message-ID: <CAE9FiQXyVB5AGGOd+a-SatL+dEo7Nvx=zPswtZ1QLk5QSLMm4Q@mail.gmail.com> (raw)
In-Reply-To: <CAE9FiQW5KkgszD2F4aez-jtXABkiPmUDVqTiFF8MDNKxWLopxA@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 964 bytes --]
On Wed, Aug 22, 2012 at 10:35 AM, Yinghai Lu <yinghai@kernel.org> wrote:
> On Wed, Aug 22, 2012 at 10:31 AM, Yinghai Lu <yinghai@kernel.org> wrote:
>>
> keep the idx would make thing simple for referencing and converting.
>
> pci_dev_resource_n() would be wrapper to from idx to real resource pointer.
> we just need to change &dev->resource[i] referencing to
> pci_dev_resource_n(dev, i) instead.
>
> We did that before for irq_desc storage converting, and now we have
> for_each_irq_desc(irq, desc)
>
> later for the resource allocation, I will change resource member from
> struct resource resource[DEVICE_COUNT_RESOURCE];
> to
> struct resource std_res[7];
> struct resource *iov_res;
> struct resource *bridge_res;
> and allocate iov_res and bridge array as needed.
>
> anyway keep the overalll idx is good way to go and follow.
>
Like to suggest two versions that only handle idx...
Thanks
Yinghai
[-- Attachment #2: ram_pci_it_v4.patch --]
[-- Type: application/octet-stream, Size: 2246 bytes --]
---
include/linux/pci.h | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 54 insertions(+)
Index: linux-2.6/include/linux/pci.h
===================================================================
--- linux-2.6.orig/include/linux/pci.h
+++ linux-2.6/include/linux/pci.h
@@ -373,6 +373,60 @@ 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);
+#define PCI_STD_RES (1<<0)
+#define PCI_ROM_RES (1<<1)
+#define PCI_BRIDGE_RES (1<<2)
+#define PCI_IOV_RES (1<<3)
+
+#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 void __prepare_idx_bitmap(unsigned long *mask, int flag)
+{
+ bitmap_zero(mask, PCI_NUM_RESOURCES);
+ if (flag & PCI_STD_RES)
+ bitmap_set(mask, PCI_STD_RESOURCES,
+ PCI_STD_RESOURCE_END - PCI_STD_RESOURCES + 1);
+ if (flag & PCI_ROM_RES)
+ bitmap_set(mask, PCI_ROM_RESOURCE, 1);
+#ifdef CONFIG_PCI_IOV
+ if (flag & PCI_IOV_RES)
+ bitmap_set(mask, PCI_IOV_RESOURCES,
+ PCI_IOV_RESOURCE_END - PCI_IOV_RESOURCES + 1);
+#endif
+ if (flag & PCI_BRIDGE_RES)
+ bitmap_set(mask, PCI_BRIDGE_RESOURCES,
+ PCI_BRIDGE_RESOURCE_END - PCI_BRIDGE_RESOURCES + 1);
+};
+
+static inline int pci_next_resource_idx(int i, int flag)
+{
+ DECLARE_BITMAP(mask, PCI_NUM_RESOURCES);
+
+ __prepare_idx_bitmap(mask, flag);
+
+ i++;
+ i = find_next_bit(mask, PCI_NUM_RESOURCES, i);
+
+ if (i < PCI_NUM_RESOURCES)
+ return i;
+
+ return -1;
+}
+
+#define for_each_pci_resource(dev, res, i, flag) \
+ for (i = pci_next_resource_idx(-1, flag), \
+ res = pci_dev_resource_n(dev, i); \
+ res; \
+ i = pci_next_resource_idx(i, flag), \
+ res = pci_dev_resource_n(dev, i))
+
static inline struct pci_dev *pci_physfn(struct pci_dev *dev)
{
#ifdef CONFIG_PCI_IOV
[-- Attachment #3: ram_pci_it_v4_x.patch --]
[-- Type: application/octet-stream, Size: 1862 bytes --]
---
include/linux/pci.h | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
Index: linux-2.6/include/linux/pci.h
===================================================================
--- linux-2.6.orig/include/linux/pci.h
+++ linux-2.6/include/linux/pci.h
@@ -373,6 +373,43 @@ 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);
+#define PCI_STD_RES (1<<0)
+#define PCI_ROM_RES (1<<1)
+#define PCI_BRIDGE_RES (1<<2)
+#define PCI_IOV_RES (1<<3)
+
+#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 int pci_next_resource_idx(int i, int flag)
+{
+ while (++i < PCI_NUM_RESOURCES) {
+ if ((i >= 0 && i < PCI_ROM_RESOURCE) && (flag & PCI_STD_RES))
+ return i;
+ else if ((i == PCI_ROM_RESOURCE) && (flag & PCI_ROM_RES))
+ return i;
+#ifdef CONFIG_PCI_IOV
+ else if ((i <= PCI_IOV_RESOURCE_END) && (flag & PCI_IOV_RES))
+ return i;
+#endif
+ else if ((i <= PCI_BRIDGE_RESOURCE_END) && (flag & PCI_BRIDGE_RES))
+ return i;
+ }
+
+ return -1;
+}
+
+#define for_each_pci_resource(dev, res, i, flag) \
+ for (i = pci_next_resource_idx(-1, flag), res = pci_dev_resource_n(dev, i);\
+ res; \
+ i = pci_next_resource_idx(i, flag), res = pci_dev_resource_n(dev, i))
+
static inline struct pci_dev *pci_physfn(struct pci_dev *dev)
{
#ifdef CONFIG_PCI_IOV
next prev parent reply other threads:[~2012-08-23 0:28 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
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 [this message]
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='CAE9FiQXyVB5AGGOd+a-SatL+dEo7Nvx=zPswtZ1QLk5QSLMm4Q@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).