powerpc/44x: Fix PCI MSI support for Maui APM821xx SoC and Bluestone board
Subsystems (2)
PATCH v3 1/2 powerpc/44x: Fix PCI MSI support for Maui APM821xx SoC and Bluestone board
This patch consists of:
- Enable PCI MSI as default for Bluestone board
- Change definition of number of MSI interrupt as it depends on SoC
- Fix returning ENODEV as finding MSI node
- Fix MSI physical high and low address
- Keep MSI data logically
---
v3:
* Use upper_32_bits() / lower_32_bits() consistently as Wolfgang Denk recomments v2:
* Change definition of number of MSI interrupt from config to count interrupts in device tree
--- arch/powerpc/platforms/44x/Kconfig | 2 + arch/powerpc/sysdev/ppc4xx_msi.c | 40 +++++++++++++++++++++++------------ 2 files changed, 28 insertions(+), 14 deletions(-)
arch/powerpc/platforms/44x/Kconfig +2 -0
@@ -23,6 +23,8 @@ config BLUESTONE default n select PPC44x_SIMPLE select APM821xx + select PCI_MSI + select PPC4xx_MSI select IBM_EMAC_RGMII help This option enables support for the APM APM821xx Evaluation board.
arch/powerpc/sysdev/ppc4xx_msi.c +26 -14
@@ -28,10 +28,11 @@#include <linux/of_platform.h> #include <linux/interrupt.h> #include <linux/export.h> +#include <linux/kernel.h> #include <asm/prom.h> #include <asm/hw_irq.h> #include <asm/ppc-pci.h> -#include <boot/dcr.h> +#include <asm/dcr.h> #include <asm/dcr-regs.h> #include <asm/msi_bitmap.h>
@@ -43,13 +44,14 @@#define PEIH_FLUSH0 0x30#define PEIH_FLUSH1 0x38#define PEIH_CNTRST 0x48 -#define NR_MSI_IRQS 4 + +int msi_irqs;struct ppc4xx_msi {u32 msi_addr_lo;u32 msi_addr_hi;void __iomem *msi_regs; -int msi_virqs[NR_MSI_IRQS ]; +int *msi_virqs;struct msi_bitmap bitmap;struct device_node *msi_dev; };
@@ -61,7 +63,7 @@ static int ppc4xx_msi_init_allocator(struct platform_device *dev, {int err; - err =msi_bitmap_alloc (&msi_data->bitmap,NR_MSI_IRQS , + err =msi_bitmap_alloc (&msi_data->bitmap, msi_irqs, dev->dev.of_node);if (err)return err;
@@ -83,6 +85,9 @@ static int ppc4xx_setup_msi_irqs(struct pci_dev *dev, int nvec, int type)struct msi_desc *entry;struct ppc4xx_msi *msi_data = &ppc4xx_msi; + msi_data->msi_virqs =kmalloc ((msi_irqs) *sizeof (int ), +GFP_KERNEL ); +list_for_each_entry (entry, &dev->msi_list, list) { int_no =msi_bitmap_alloc_hwirqs (&msi_data->bitmap,1 );if (int_no >=0 )
@@ -150,12 +155,11 @@ static int ppc4xx_setup_pcieh_hw(struct platform_device *dev,if (!sdr_addr)return -1 ; -SDR0_WRITE (sdr_addr, (u64 )res.start >>32 );/*HIGH addr */ -SDR0_WRITE (sdr_addr +1 , res.start &0xFFFFFFFF );/* Low addr */ - +mtdcri (SDR0 , *sdr_addr,upper_32_bits (res.start));/*HIGH addr */ +mtdcri (SDR0 , *sdr_addr +1 ,lower_32_bits (res.start));/* Low addr */ msi->msi_dev =of_find_node_by_name (NULL ,"ppc4xx-msi" ); -if (msi->msi_dev) +if (!msi->msi_dev)return -ENODEV ; msi->msi_regs =of_iomap (msi->msi_dev,0 );
@@ -167,9 +171,12 @@ static int ppc4xx_setup_pcieh_hw(struct platform_device *dev, (u32) (msi->msi_regs + PEIH_TERMADH), (u32) (msi->msi_regs)); msi_virt =dma_alloc_coherent (&dev->dev,64 , &msi_phys,GFP_KERNEL ); - msi->msi_addr_hi =0x0 ; - msi->msi_addr_lo = (u32 ) msi_phys; -dev_dbg (&dev->dev,"PCIE-MSI: msi address 0x%x\n" , msi->msi_addr_lo); +if (!msi_virt) +return -ENOMEM ; + msi->msi_addr_hi =upper_32_bits (msi_phys); + msi->msi_addr_lo =lower_32_bits (msi_phys); +dev_dbg (&dev->dev,"PCIE-MSI: msi address high 0x%x, low 0x%x\n" , + msi->msi_addr_hi, msi->msi_addr_lo);/* Progam the Interrupt handler Termination addr registers */ out_be32 (msi->msi_regs +PEIH_TERMADH , msi->msi_addr_hi);
@@ -185,6 +192,8 @@ static int ppc4xx_setup_pcieh_hw(struct platform_device *dev,out_be32 (msi->msi_regs +PEIH_MSIED , *msi_data);out_be32 (msi->msi_regs +PEIH_MSIMK , *msi_mask); +dma_free_coherent (&dev->dev,64 , msi_virt, msi_phys); +return 0 ; }
@@ -194,7 +203,7 @@ static int ppc4xx_of_msi_remove(struct platform_device *dev)int i;int virq; -for (i =0 ; i <NR_MSI_IRQS ; i++) { +for (i =0 ; i < msi_irqs; i++) { virq = msi->msi_virqs[i];if (virq !=NO_IRQ )irq_dispose_mapping (virq);
@@ -215,8 +224,6 @@ static int __devinit ppc4xx_msi_probe(struct platform_device *dev)struct resource res;int err =0 ; - msi = &ppc4xx_msi;/*keep the msi data for further use*/ -dev_dbg (&dev->dev,"PCIE-MSI: Setting up MSI support...\n" ); msi =kzalloc (sizeof (struct ppc4xx_msi ),GFP_KERNEL );
@@ -234,6 +241,10 @@ static int __devinit ppc4xx_msi_probe(struct platform_device *dev) goto error_out; } + msi_irqs =of_irq_count (dev->dev.of_node); +if (!msi_irqs) +return -1 ; +if (ppc4xx_setup_pcieh_hw (dev, res, msi)) goto error_out;
@@ -242,6 +253,7 @@ static int __devinit ppc4xx_msi_probe(struct platform_device *dev)dev_err (&dev->dev,"Error allocating MSI bitmap\n" ); goto error_out; } + ppc4xx_msi = *msi; ppc_md.setup_msi_irqs = ppc4xx_setup_msi_irqs; ppc_md.teardown_msi_irqs = ppc4xx_teardown_msi_irqs;
Signature · 1 line
1.7.3.4
arch/powerpc/sysdev/ppc4x=
Quoted 1 line · Mai La
arch/powerpc/sysdev/ppc4x= renamed from arch/powerpc/sysdev/ppc4xx_msi.c +0
-0
x_msi.c
Quoted 20 lines
index 1c2d7af..63989d0 100644
arch/powerpc/sysdev/ppc4xx_msi.c +0
-0@@ -28,10 +28,11 @@=A0#include <
linux/of_platform.h>
=A0#include <linux/interrupt.h>
=A0#include <linux/export.h>
+#include <linux/kernel.h>
=A0#include <asm/prom.h>
=A0#include <asm/hw_irq.h>
=A0#include <asm/ppc-pci.h>arch/powerpc/sysdev/ppc4xx_msi.c +1
-1-#include <boot/dcr.h> +#include <asm/dcr.h> =A0#include <
asm/dcr-regs.h>
=A0#include <asm/msi_bitmap.h>arch/powerpc/sysdev/ppc4xx_msi.c +0
-0@@ -43,13 +44,14 @@=A0#define
PEIH_FLUSH0=A0 =A00x30
=A0#definePEIH_FLUSH1=A0 =A00x38
=A0#definePEIH_CNTRST=A0 =A00x48
arch/powerpc/sysdev/ppc4xx_msi.c line 48
Quoted 3 lines
arch/powerpc/sysdev/ppc4xx_msi.c +2
-1-#define NR_MSI_IRQS =A0 =A04 + +int msi_irqs;
This should be static.
arch/powerpc/sysdev/ppc4xx_msi.c static int ppc4xx_msi_init_allocator(struct platform_de=
Quoted 10 lines
=A0struct
ppc4xx_msi{
=A0 =A0 =A0 =A0u32msi_addr_lo;
=A0 =A0 =A0 =A0u32msi_addr_hi;
=A0 =A0 =A0 =A0void__iomem*msi_regs;
- =A0 =A0 =A0 int msi_virqs[NR_MSI_IRQS];
+ =A0 =A0 =A0 int*msi_virqs;
=A0 =A0 =A0 =A0structmsi_bitmapbitmap;
=A0 =A0 =A0 =A0structdevice_node*msi_dev;
=A0};arch/powerpc/sysdev/ppc4xx_msi.c +0
-0@@ -61,7 +63,7 @@ static int ppc4xx_msi_init_allocator(struct platform_de=
vice *dev,
Quoted 6 lines
arch/powerpc/sysdev/ppc4xx_msi.c +1
-1=A0{ =A0 =A0 =A0 =A0int err; - =A0 =A0 =A0 err =3D msi_bitmap_alloc(&msi_data->bitmap, NR_MSI_IRQS, + =A0 =A0 =A0 err =3D msi_bitmap_alloc(&msi_data->bitmap, msi_irqs,=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0dev->dev.of_no=
de);
arch/powerpc/sysdev/ppc4xx_msi.c static int ppc4xx_setup_msi_irqs(struct pci_dev *dev, i=
Quoted 3 lines
=A0 =A0 =A0 =A0if (err)
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return err;arch/powerpc/sysdev/ppc4xx_msi.c +0
-0@@ -83,6 +85,9 @@ static int ppc4xx_setup_msi_irqs(struct pci_dev *dev, i=
nt nvec, int type)
arch/powerpc/sysdev/ppc4xx_msi.c static int ppc4xx_setup_msi_irqs(struct pci_dev *dev, i= · line 89
Quoted 5 lines
arch/powerpc/sysdev/ppc4xx_msi.c +2
-0=A0 =A0 =A0 =A0struct msi_desc *entry; =A0 =A0 =A0 =A0struct ppc4xx_msi *msi_data =3D &ppc4xx_msi; + =A0 =A0 =A0 msi_data->msi_virqs =3D kmalloc((msi_irqs) * sizeof(int), + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
=A0 =A0 =A0 GFP_KERNEL);
arch/powerpc/sysdev/ppc4xx_msi.c static int ppc4xx_setup_msi_irqs(struct pci_dev *dev, i= · line 90
Quoted 1 line
arch/powerpc/sysdev/ppc4xx_msi.c +1
-0+
What happens if this allocation fails? Unlikely perhaps, but we should sti= ll
probably try and handle the error.
Quoted 2 lines
arch/powerpc/sysdev/ppc4xx_msi.c +0
-0=A0 =A0 =A0 =A0list_for_each_entry(entry, &dev->msi_list, list) {=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0int_no =3D msi_bitmap_alloc_hwirqs(&msi_da=
ta->bitmap, 1);
Quoted 1 line
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (
int_no>=3D 0)
<snip>
arch/powerpc/sysdev/ppc4xx_msi.c static int __devinit ppc4xx_msi_probe(struct platfor=
Quoted 1 line
arch/powerpc/sysdev/ppc4xx_msi.c +0
-0@@ -234,6 +241,10 @@ static int __devinit ppc4xx_msi_probe(struct platfor=
m_device *dev)
arch/powerpc/sysdev/ppc4xx_msi.c static int __devinit ppc4xx_msi_probe(struct platfor= · line 247
Quoted 7 lines
arch/powerpc/sysdev/ppc4xx_msi.c +4
-0=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0goto error_out; =A0 =A0 =A0 =A0} + =A0 =A0 =A0 msi_irqs =3D of_irq_count(dev->dev.of_node); + =A0 =A0 =A0 if (!msi_irqs) + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return -1; +
Maybe return -ENODEV here instead of -1? It probably doesn't matter at the moment, but if anything actually checked why the probe function failed, tha= t
would be more descriptive.
josh