Do you have any further comment for this patch?<br><br><div class="gmail_quote">On Mon, Mar 19, 2012 at 10:59 AM, Mai La <span dir="ltr"><<a href="mailto:mla@apm.com">mla@apm.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
This patch consists of:<br>
- Enable PCI MSI as default for Bluestone board<br>
- Change definition of number of MSI interrupts as it depends on SoC<br>
- Fix returning ENODEV as finding MSI node<br>
- Fix MSI physical high and low address<br>
- Keep MSI data logically<br>
<br>
Signed-off-by: Mai La <<a href="mailto:mla@apm.com">mla@apm.com</a>><br>
<br>
---<br>
v4:<br>
Per Josh Boyer's comment:<br>
* Declare msi_irqs as static<br>
* Handle error if allocation of MSI vitual interrupts fails<br>
* Return ENODEV if counting MSI interrupts fails<br>
v3:<br>
* Use upper_32_bits() / lower_32_bits() consistently as Wolfgang Denk recomments<br>
v2:<br>
* Change definition of number of MSI interrupt from config to count interrupts in device tree<br>
<br>
---<br>
arch/powerpc/platforms/44x/Kconfig | 2 +<br>
arch/powerpc/sysdev/ppc4xx_msi.c | 42 ++++++++++++++++++++++++------------<br>
2 files changed, 30 insertions(+), 14 deletions(-)<br>
<br>
diff --git a/arch/powerpc/platforms/44x/Kconfig b/arch/powerpc/platforms/44x/Kconfig<br>
index fcf6bf2..9f04ce3 100644<br>
--- a/arch/powerpc/platforms/44x/Kconfig<br>
+++ b/arch/powerpc/platforms/44x/Kconfig<br>
@@ -23,6 +23,8 @@ config BLUESTONE<br>
default n<br>
select PPC44x_SIMPLE<br>
select APM821xx<br>
+ select PCI_MSI<br>
+ select PPC4xx_MSI<br>
select IBM_EMAC_RGMII<br>
help<br>
This option enables support for the APM APM821xx Evaluation board.<br>
diff --git a/arch/powerpc/sysdev/ppc4xx_msi.c b/arch/powerpc/sysdev/ppc4xx_msi.c<br>
index 1c2d7af..cc17f59 100644<br>
--- a/arch/powerpc/sysdev/ppc4xx_msi.c<br>
+++ b/arch/powerpc/sysdev/ppc4xx_msi.c<br>
@@ -28,10 +28,11 @@<br>
#include <linux/of_platform.h><br>
#include <linux/interrupt.h><br>
#include <linux/export.h><br>
+#include <linux/kernel.h><br>
#include <asm/prom.h><br>
#include <asm/hw_irq.h><br>
#include <asm/ppc-pci.h><br>
-#include <boot/dcr.h><br>
+#include <asm/dcr.h><br>
#include <asm/dcr-regs.h><br>
#include <asm/msi_bitmap.h><br>
<br>
@@ -43,13 +44,14 @@<br>
#define PEIH_FLUSH0 0x30<br>
#define PEIH_FLUSH1 0x38<br>
#define PEIH_CNTRST 0x48<br>
-#define NR_MSI_IRQS 4<br>
+<br>
+static int msi_irqs;<br>
<br>
struct ppc4xx_msi {<br>
u32 msi_addr_lo;<br>
u32 msi_addr_hi;<br>
void __iomem *msi_regs;<br>
- int msi_virqs[NR_MSI_IRQS];<br>
+ int *msi_virqs;<br>
struct msi_bitmap bitmap;<br>
struct device_node *msi_dev;<br>
};<br>
@@ -61,7 +63,7 @@ static int ppc4xx_msi_init_allocator(struct platform_device *dev,<br>
{<br>
int err;<br>
<br>
- err = msi_bitmap_alloc(&msi_data->bitmap, NR_MSI_IRQS,<br>
+ err = msi_bitmap_alloc(&msi_data->bitmap, msi_irqs,<br>
dev->dev.of_node);<br>
if (err)<br>
return err;<br>
@@ -83,6 +85,11 @@ static int ppc4xx_setup_msi_irqs(struct pci_dev *dev, int nvec, int type)<br>
struct msi_desc *entry;<br>
struct ppc4xx_msi *msi_data = &ppc4xx_msi;<br>
<br>
+ msi_data->msi_virqs = kmalloc((msi_irqs) * sizeof(int),<br>
+ GFP_KERNEL);<br>
+ if (!msi_data->msi_virqs)<br>
+ return -ENOMEM;<br>
+<br>
list_for_each_entry(entry, &dev->msi_list, list) {<br>
int_no = msi_bitmap_alloc_hwirqs(&msi_data->bitmap, 1);<br>
if (int_no >= 0)<br>
@@ -150,12 +157,11 @@ static int ppc4xx_setup_pcieh_hw(struct platform_device *dev,<br>
if (!sdr_addr)<br>
return -1;<br>
<br>
- SDR0_WRITE(sdr_addr, (u64)res.start >> 32); /*HIGH addr */<br>
- SDR0_WRITE(sdr_addr + 1, res.start & 0xFFFFFFFF); /* Low addr */<br>
-<br>
+ mtdcri(SDR0, *sdr_addr, upper_32_bits(res.start)); /*HIGH addr */<br>
+ mtdcri(SDR0, *sdr_addr + 1, lower_32_bits(res.start)); /* Low addr */<br>
<br>
msi->msi_dev = of_find_node_by_name(NULL, "ppc4xx-msi");<br>
- if (msi->msi_dev)<br>
+ if (!msi->msi_dev)<br>
return -ENODEV;<br>
<br>
msi->msi_regs = of_iomap(msi->msi_dev, 0);<br>
@@ -167,9 +173,12 @@ static int ppc4xx_setup_pcieh_hw(struct platform_device *dev,<br>
(u32) (msi->msi_regs + PEIH_TERMADH), (u32) (msi->msi_regs));<br>
<br>
msi_virt = dma_alloc_coherent(&dev->dev, 64, &msi_phys, GFP_KERNEL);<br>
- msi->msi_addr_hi = 0x0;<br>
- msi->msi_addr_lo = (u32) msi_phys;<br>
- dev_dbg(&dev->dev, "PCIE-MSI: msi address 0x%x\n", msi->msi_addr_lo);<br>
+ if (!msi_virt)<br>
+ return -ENOMEM;<br>
+ msi->msi_addr_hi = (u32)(msi_phys >> 32);<br>
+ msi->msi_addr_lo = (u32)(msi_phys & 0xffffffff);<br>
+ dev_dbg(&dev->dev, "PCIE-MSI: msi address high 0x%x, low 0x%x\n",<br>
+ msi->msi_addr_hi, msi->msi_addr_lo);<br>
<br>
/* Progam the Interrupt handler Termination addr registers */<br>
out_be32(msi->msi_regs + PEIH_TERMADH, msi->msi_addr_hi);<br>
@@ -185,6 +194,8 @@ static int ppc4xx_setup_pcieh_hw(struct platform_device *dev,<br>
out_be32(msi->msi_regs + PEIH_MSIED, *msi_data);<br>
out_be32(msi->msi_regs + PEIH_MSIMK, *msi_mask);<br>
<br>
+ dma_free_coherent(&dev->dev, 64, msi_virt, msi_phys);<br>
+<br>
return 0;<br>
}<br>
<br>
@@ -194,7 +205,7 @@ static int ppc4xx_of_msi_remove(struct platform_device *dev)<br>
int i;<br>
int virq;<br>
<br>
- for (i = 0; i < NR_MSI_IRQS; i++) {<br>
+ for (i = 0; i < msi_irqs; i++) {<br>
virq = msi->msi_virqs[i];<br>
if (virq != NO_IRQ)<br>
irq_dispose_mapping(virq);<br>
@@ -215,8 +226,6 @@ static int __devinit ppc4xx_msi_probe(struct platform_device *dev)<br>
struct resource res;<br>
int err = 0;<br>
<br>
- msi = &ppc4xx_msi;/*keep the msi data for further use*/<br>
-<br>
dev_dbg(&dev->dev, "PCIE-MSI: Setting up MSI support...\n");<br>
<br>
msi = kzalloc(sizeof(struct ppc4xx_msi), GFP_KERNEL);<br>
@@ -234,6 +243,10 @@ static int __devinit ppc4xx_msi_probe(struct platform_device *dev)<br>
goto error_out;<br>
}<br>
<br>
+ msi_irqs = of_irq_count(dev->dev.of_node);<br>
+ if (!msi_irqs)<br>
+ return -ENODEV;<br>
+<br>
if (ppc4xx_setup_pcieh_hw(dev, res, msi))<br>
goto error_out;<br>
<br>
@@ -242,6 +255,7 @@ static int __devinit ppc4xx_msi_probe(struct platform_device *dev)<br>
dev_err(&dev->dev, "Error allocating MSI bitmap\n");<br>
goto error_out;<br>
}<br>
+ ppc4xx_msi = *msi;<br>
<br>
ppc_md.setup_msi_irqs = ppc4xx_setup_msi_irqs;<br>
ppc_md.teardown_msi_irqs = ppc4xx_teardown_msi_irqs;<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.7.3.4<br>
<br>
</font></span></blockquote></div><br>