From mboxrd@z Thu Jan 1 00:00:00 1970 From: Bjorn Helgaas Subject: Re: [PATCH 05/12] PCI: add pci_swizzle_interrupt_pin() Date: Thu, 11 Dec 2008 09:48:19 -0700 Message-ID: <200812110948.20563.bjorn.helgaas@hp.com> References: <20081209231202.18153.60227.stgit@bob.kio> <20081209231037.18153.86962.stgit@bob.kio> <23213.1229007624@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-15" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <23213.1229007624@redhat.com> Content-Disposition: inline Sender: linux-pci-owner@vger.kernel.org To: David Howells Cc: Jesse Barnes , linux-pci@vger.kernel.org, linux-arch@vger.kernel.org, Ivan Kokshaysky , Russell King , Ralf Baechle , Kyle McMartin , Matthew Wilcox , Grant Grundler , Paul Mackerras , Benjamin Herrenschmidt , Paul Mundt , Thomas Gleixner , Ingo Molnar , hpa@zytor.com List-Id: linux-arch.vger.kernel.org On Thursday 11 December 2008 08:00:24 am David Howells wrote: > Bjorn Helgaas wrote: > > > > > +u8 pci_swizzle_interrupt_pin(struct pci_dev *dev, u8 pin) > > +{ > > + /* This implements Table 9-1 of the PCI-to-PCI bridge spec */ > > + return (((pin - 1) + PCI_SLOT(dev->devfn)) % 4) + 1; > > +} > > + > > Can you please add a banner comment to this function that gives at least a > quick description of what this function is meant to do? Feel free to use > kerneldoc. I'm not really a fan of comments that are bigger than the code and add little or no information, but if you like the following better, use it instead :-) PCI: add pci_swizzle_interrupt_pin() From: Bjorn Helgaas This patch adds pci_swizzle_interrupt_pin(), which implements the INTx swizzling algorithm specified in Table 9-1 of the "PCI-to-PCI Bridge Architecture Specification," revision 1.2. There are many architecture-specific implementations of this swizzle that can be replaced by this common one. Signed-off-by: Bjorn Helgaas --- drivers/pci/pci.c | 17 ++++++++++++++++- include/linux/pci.h | 1 + 2 files changed, 17 insertions(+), 1 deletions(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 46f6821..c14a6b6 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -1337,6 +1337,21 @@ void pci_enable_ari(struct pci_dev *dev) bridge->ari_enabled = 1; } +/** + * pci_swizzle_interrupt_pin - swizzle INTx for device behind bridge + * @dev: the PCI device + * @pin: the INTx pin (1=INTA, 2=INTB, 3=INTD, 4=INTD) + * + * The PCI-to-PCI bridge specification requires INTx swizzling for + * devices behind bridges on add-in cards. This performs the swizzle + * for one level of bridge. + */ +u8 pci_swizzle_interrupt_pin(struct pci_dev *dev, u8 pin) +{ + /* This implements Table 9-1 of the PCI-to-PCI bridge spec */ + return (((pin - 1) + PCI_SLOT(dev->devfn)) % 4) + 1; +} + int pci_get_interrupt_pin(struct pci_dev *dev, struct pci_dev **bridge) { @@ -1347,7 +1362,7 @@ pci_get_interrupt_pin(struct pci_dev *dev, struct pci_dev **bridge) return -1; while (dev->bus->self) { - pin = (((pin - 1) + PCI_SLOT(dev->devfn)) % 4) + 1; + pin = pci_swizzle_interrupt_pin(dev, pin); dev = dev->bus->self; } *bridge = dev; diff --git a/include/linux/pci.h b/include/linux/pci.h index feb4657..4be596f 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -527,6 +527,7 @@ int __must_check pci_bus_add_device(struct pci_dev *dev); void pci_read_bridge_bases(struct pci_bus *child); struct resource *pci_find_parent_resource(const struct pci_dev *dev, struct resource *res); +u8 pci_swizzle_interrupt_pin(struct pci_dev *dev, u8 pin); int pci_get_interrupt_pin(struct pci_dev *dev, struct pci_dev **bridge); extern struct pci_dev *pci_dev_get(struct pci_dev *dev); extern void pci_dev_put(struct pci_dev *dev); From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from g4t0014.houston.hp.com ([15.201.24.17]:46936 "EHLO g4t0014.houston.hp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755779AbYLKQs1 (ORCPT ); Thu, 11 Dec 2008 11:48:27 -0500 From: Bjorn Helgaas Subject: Re: [PATCH 05/12] PCI: add pci_swizzle_interrupt_pin() Date: Thu, 11 Dec 2008 09:48:19 -0700 References: <20081209231202.18153.60227.stgit@bob.kio> <20081209231037.18153.86962.stgit@bob.kio> <23213.1229007624@redhat.com> In-Reply-To: <23213.1229007624@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-15" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-ID: <200812110948.20563.bjorn.helgaas@hp.com> Sender: linux-arch-owner@vger.kernel.org List-ID: To: David Howells Cc: Jesse Barnes , linux-pci@vger.kernel.org, linux-arch@vger.kernel.org, Ivan Kokshaysky , Russell King , Ralf Baechle , Kyle McMartin , Matthew Wilcox , Grant Grundler , Paul Mackerras , Benjamin Herrenschmidt , Paul Mundt , Thomas Gleixner , Ingo Molnar , hpa@zytor.com Message-ID: <20081211164819.UpsXUNO29EIZOK7hShLstImOqzo2GEC-CbsfWuGCxzE@z> On Thursday 11 December 2008 08:00:24 am David Howells wrote: > Bjorn Helgaas wrote: > > > > > +u8 pci_swizzle_interrupt_pin(struct pci_dev *dev, u8 pin) > > +{ > > + /* This implements Table 9-1 of the PCI-to-PCI bridge spec */ > > + return (((pin - 1) + PCI_SLOT(dev->devfn)) % 4) + 1; > > +} > > + > > Can you please add a banner comment to this function that gives at least a > quick description of what this function is meant to do? Feel free to use > kerneldoc. I'm not really a fan of comments that are bigger than the code and add little or no information, but if you like the following better, use it instead :-) PCI: add pci_swizzle_interrupt_pin() From: Bjorn Helgaas This patch adds pci_swizzle_interrupt_pin(), which implements the INTx swizzling algorithm specified in Table 9-1 of the "PCI-to-PCI Bridge Architecture Specification," revision 1.2. There are many architecture-specific implementations of this swizzle that can be replaced by this common one. Signed-off-by: Bjorn Helgaas --- drivers/pci/pci.c | 17 ++++++++++++++++- include/linux/pci.h | 1 + 2 files changed, 17 insertions(+), 1 deletions(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 46f6821..c14a6b6 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -1337,6 +1337,21 @@ void pci_enable_ari(struct pci_dev *dev) bridge->ari_enabled = 1; } +/** + * pci_swizzle_interrupt_pin - swizzle INTx for device behind bridge + * @dev: the PCI device + * @pin: the INTx pin (1=INTA, 2=INTB, 3=INTD, 4=INTD) + * + * The PCI-to-PCI bridge specification requires INTx swizzling for + * devices behind bridges on add-in cards. This performs the swizzle + * for one level of bridge. + */ +u8 pci_swizzle_interrupt_pin(struct pci_dev *dev, u8 pin) +{ + /* This implements Table 9-1 of the PCI-to-PCI bridge spec */ + return (((pin - 1) + PCI_SLOT(dev->devfn)) % 4) + 1; +} + int pci_get_interrupt_pin(struct pci_dev *dev, struct pci_dev **bridge) { @@ -1347,7 +1362,7 @@ pci_get_interrupt_pin(struct pci_dev *dev, struct pci_dev **bridge) return -1; while (dev->bus->self) { - pin = (((pin - 1) + PCI_SLOT(dev->devfn)) % 4) + 1; + pin = pci_swizzle_interrupt_pin(dev, pin); dev = dev->bus->self; } *bridge = dev; diff --git a/include/linux/pci.h b/include/linux/pci.h index feb4657..4be596f 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -527,6 +527,7 @@ int __must_check pci_bus_add_device(struct pci_dev *dev); void pci_read_bridge_bases(struct pci_bus *child); struct resource *pci_find_parent_resource(const struct pci_dev *dev, struct resource *res); +u8 pci_swizzle_interrupt_pin(struct pci_dev *dev, u8 pin); int pci_get_interrupt_pin(struct pci_dev *dev, struct pci_dev **bridge); extern struct pci_dev *pci_dev_get(struct pci_dev *dev); extern void pci_dev_put(struct pci_dev *dev);