Skip to contentSkip to conversation

Add IPIC MSI interrupt support

PATCH In review Li Li 6 participants 13 messages Nov 30, 2007 – Dec 4, 2007

Subsystems (3)
lore
Share & tools
lore

Li Li

author
#0 lore raw

PATCH 1/1 Add IPIC MSI interrupt support

The IPIC MSI is introduced on MPC837x chip. Implements the IPIC MSI as two level interrupt controller.

---
 arch/powerpc/boot/dts/mpc8377_mds.dts     |   14 ++
 arch/powerpc/boot/dts/mpc8378_mds.dts     |   14 ++
 arch/powerpc/boot/dts/mpc8379_mds.dts     |   14 ++
 arch/powerpc/platforms/83xx/Kconfig       |    6 +
 arch/powerpc/platforms/83xx/mpc837x_mds.c |   11 +
 arch/powerpc/sysdev/Makefile              |    1 +
 arch/powerpc/sysdev/ipic_msi.c            |  359 +++++++++++++++++++++++++++++
 include/asm-powerpc/ipic_msi.h            |   54 +++++
 8 files changed, 473 insertions(+), 0 deletions(-)
 create mode 100644 arch/powerpc/sysdev/ipic_msi.c
 create mode 100644 include/asm-powerpc/ipic_msi.h
arch/powerpc/boot/dts/mpc8377_mds.dts +14 -0
index 1f7819e..1068fe2 100644
@@ -210,6 +210,20 @@
 			#interrupt-cells = <2>;
 			reg = <700 100>;
 		};
+
+		ipic-msi@7c0 {
+			compatible = "fsl,ipic-msi";
+			reg = <7c0 40>;
+			interrupts = < 43 8
+				       4  8
+				       51 8
+				       52 8
+				       56 8
+				       57 8
+				       58 8
+				       59 8 >;
+			interrupt-parent = < &ipic >;
+		};
 	};
 
 	pci@e0008500 {
arch/powerpc/boot/dts/mpc8378_mds.dts +14 -0
index 1503ae3..f12658f 100644
@@ -192,6 +192,20 @@
 			#interrupt-cells = <2>;
 			reg = <700 100>;
 		};
+
+		ipic-msi@7c0 {
+			compatible = "fsl,ipic-msi";
+			reg = <7c0 40>;
+			interrupts = < 43 8
+				       4  8
+				       51 8
+				       52 8
+				       56 8
+				       57 8
+				       58 8
+				       59 8 >;
+			interrupt-parent = < &ipic >;
+		};
 	};
 
 	pci@e0008500 {
arch/powerpc/boot/dts/mpc8379_mds.dts +14 -0
index cdb4426..9fe4bd2 100644
@@ -236,6 +236,20 @@
 			#interrupt-cells = <2>;
 			reg = <700 100>;
 		};
+
+		ipic-msi@7c0 {
+			compatible = "fsl,ipic-msi";
+			reg = <7c0 40>;
+			interrupts = < 43 8
+				       4  8
+				       51 8
+				       52 8
+				       56 8
+				       57 8
+				       58 8
+				       59 8 >;
+			interrupt-parent = < &ipic >;
+		};
 	};
 
 	pci@e0008500 {
arch/powerpc/platforms/83xx/Kconfig +6 -0
index 00154c5..4c51f78 100644
@@ -88,6 +88,12 @@ config PPC_MPC837x
 	select FSL_SERDES
 	default y if MPC837x_MDS
 
+config IPIC_MSI
+	bool
+	depends on PCI_MSI
+	default y if PPC_MPC837x
+	default n
+
 config PPC_MPC83XX_PCIE
 	bool "MPC837X PCI Express support"
 	depends on PCIEPORTBUS && PPC_MPC837x
arch/powerpc/platforms/83xx/mpc837x_mds.c +11 -0
index 6048f1b..dbea34b 100644
@@ -17,6 +17,9 @@
 
 #include <asm/time.h>
 #include <asm/ipic.h>
+#if CONFIG_IPIC_MSI
+#include <asm/ipic_msi.h>
+#endif
 #include <asm/udbg.h>
 #include <asm/prom.h>
 
@@ -84,6 +87,14 @@ static void __init mpc837x_mds_init_IRQ(void)
 	 * in case the boot rom changed something on us.
 	 */
 	ipic_set_default_priority();
+
+#if CONFIG_IPIC_MSI
+	np = of_find_compatible_node(NULL, NULL, "fsl,ipic-msi");
+	if (!np)
+		return;
+
+	ipic_msi_init(np, ipic_msi_cascade);
+#endif
 }
 
 /*
arch/powerpc/sysdev/Makefile +1 -0
index 99a77d7..5946b6a 100644
@@ -25,6 +25,7 @@ ifeq ($(CONFIG_PPC_MERGE),y)
 obj-$(CONFIG_PPC_INDIRECT_PCI)	+= indirect_pci.o
 obj-$(CONFIG_PPC_I8259)		+= i8259.o
 obj-$(CONFIG_PPC_83xx)		+= ipic.o
+obj-$(CONFIG_IPIC_MSI)		+= ipic_msi.o
 obj-$(CONFIG_4xx)		+= uic.o
 obj-$(CONFIG_XILINX_VIRTEX)	+= xilinx_intc.o
 endif
arch/powerpc/sysdev/ipic_msi.c new file +359 -0

359 lines not on this page · raw message

include/asm-powerpc/ipic_msi.h new file +54 -0

54 lines not on this page · raw message

Signature · 1 line
1.5.2
#1 lore raw
Quoted 29 lines · Li Li

The IPIC MSI is introduced on MPC837x chip. Implements the IPIC MSI as two level interrupt controller.

---
 arch/powerpc/boot/dts/mpc8377_mds.dts     |   14 ++
 arch/powerpc/boot/dts/mpc8378_mds.dts     |   14 ++
 arch/powerpc/boot/dts/mpc8379_mds.dts     |   14 ++
 arch/powerpc/platforms/83xx/Kconfig       |    6 +
 arch/powerpc/platforms/83xx/mpc837x_mds.c |   11 +
 arch/powerpc/sysdev/Makefile              |    1 +
 arch/powerpc/sysdev/ipic_msi.c            |  359 +++++++++++++++++++++++++++++
 include/asm-powerpc/ipic_msi.h            |   54 +++++
 8 files changed, 473 insertions(+), 0 deletions(-)
 create mode 100644 arch/powerpc/sysdev/ipic_msi.c
 create mode 100644 include/asm-powerpc/ipic_msi.h
arch/powerpc/boot/dts/mpc8377_mds.dts +4 -0
index 1f7819e..1068fe2 100644
@@ -210,6 +210,20 @@
 			#interrupt-cells = <2>;
 			reg = <700 100>;
 		};
+
+		ipic-msi@7c0 {
+			compatible = "fsl,ipic-msi";
+			reg = <7c0 40>;

arch/powerpc/boot/dts/mpc8377_mds.dts line 226

Quoted 10 lines
arch/powerpc/boot/dts/mpc8377_mds.dts +10 -0
+			interrupts = < 43 8
+				       4  8
+				       51 8
+				       52 8
+				       56 8
+				       57 8
+				       58 8
+				       59 8 >;
+			interrupt-parent = < &ipic >;
+		};

I'm not sure why the MSI needs a device node of its own. What actual piece of hardware is this representing?

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
author
#2 lore raw
Quoted 37 lines · David Gibson
Quoted 4 lines · Li Li

The IPIC MSI is introduced on MPC837x chip. Implements the IPIC MSI as two level interrupt controller.

Quoted 8 lines

---

 arch/powerpc/boot/dts/mpc8377_mds.dts     |   14 ++ 
 arch/powerpc/boot/dts/mpc8378_mds.dts     |   14 ++ 
 arch/powerpc/boot/dts/mpc8379_mds.dts     |   14 ++ 
 arch/powerpc/platforms/83xx/Kconfig       |    6 + 
 arch/powerpc/platforms/83xx/mpc837x_mds.c |   11 + 
 arch/powerpc/sysdev/Makefile              |    1 + 
 arch/powerpc/sysdev/ipic_msi.c            |  359

+++++++++++++++++++++++++++++

Review

Quoted 6 lines
 include/asm-powerpc/ipic_msi.h            |   54 +++++ 
 8 files changed, 473 insertions(+), 0 deletions(-) 
 create mode 100644 arch/powerpc/sysdev/ipic_msi.c 
 create mode 100644 include/asm-powerpc/ipic_msi.h 
(quoted diff) +0 -0

b/arch/powerpc/boot/dts/mpc8377_mds.dts

Quoted 16 lines

index 1f7819e..1068fe2 100644

arch/powerpc/boot/dts/mpc8377_mds.dts +9 -0
@@ -210,6 +210,20 @@ 
                      #interrupt-cells = <2>; 
                      reg = <700 100>; 
              }; 
+ 
+             ipic-msi@7c0 { 
+                     compatible = "fsl,ipic-msi"; 
+                     reg = <7c0 40>; 
+                     interrupts = < 43 8 
+                                    4  8 
+                                    51 8 
+                                    52 8 
+                                    56 8 
Quoted 9 lines

arch/powerpc/boot/dts/mpc8377_mds.dts line 226

Quoted 5 lines
arch/powerpc/boot/dts/mpc8377_mds.dts +5 -0
+                                    57 8 
+                                    58 8 
+                                    59 8 >; 
+                     interrupt-parent = < &ipic >; 
+             };

I'm not sure why the MSI needs a device node of its own. What actual piece of hardware is this representing?

The IPIC MSI has its own registers which control the mask and ack of MSI interrupt. Furthermore, IPIC MSI is the second level interrupt coontorller which connected to IPIC, to compatible with IPIC OF routine interface, we need a device node.

Quoted 8 lines
Signature · 6 lines
David Gibson                    | I'll have my music baroque, and my
code 
david AT gibson.dropbear.id.au  | minimalist, thank you.  NOT _the_
_other_ 
                                | _way_ _around_! 
http://www.ozlabs.org/~dgibson

- Tony

#3 lore raw
In reply to Li Li

Hi r64360,

A few comments below :)

Quoted 114 lines · Li Li

The IPIC MSI is introduced on MPC837x chip. Implements the IPIC MSI as two level interrupt controller.

---
 arch/powerpc/boot/dts/mpc8377_mds.dts     |   14 ++
 arch/powerpc/boot/dts/mpc8378_mds.dts     |   14 ++
 arch/powerpc/boot/dts/mpc8379_mds.dts     |   14 ++
 arch/powerpc/platforms/83xx/Kconfig       |    6 +
 arch/powerpc/platforms/83xx/mpc837x_mds.c |   11 +
 arch/powerpc/sysdev/Makefile              |    1 +
 arch/powerpc/sysdev/ipic_msi.c            |  359 +++++++++++++++++++++++++++++
 include/asm-powerpc/ipic_msi.h            |   54 +++++
 8 files changed, 473 insertions(+), 0 deletions(-)
 create mode 100644 arch/powerpc/sysdev/ipic_msi.c
 create mode 100644 include/asm-powerpc/ipic_msi.h
arch/powerpc/boot/dts/mpc8377_mds.dts +14 -0
index 1f7819e..1068fe2 100644
@@ -210,6 +210,20 @@
 			#interrupt-cells = <2>;
 			reg = <700 100>;
 		};
+
+		ipic-msi@7c0 {
+			compatible = "fsl,ipic-msi";
+			reg = <7c0 40>;
+			interrupts = < 43 8
+				       4  8
+				       51 8
+				       52 8
+				       56 8
+				       57 8
+				       58 8
+				       59 8 >;
+			interrupt-parent = < &ipic >;
+		};
 	};
 
 	pci@e0008500 {
arch/powerpc/boot/dts/mpc8378_mds.dts +14 -0
index 1503ae3..f12658f 100644
@@ -192,6 +192,20 @@
 			#interrupt-cells = <2>;
 			reg = <700 100>;
 		};
+
+		ipic-msi@7c0 {
+			compatible = "fsl,ipic-msi";
+			reg = <7c0 40>;
+			interrupts = < 43 8
+				       4  8
+				       51 8
+				       52 8
+				       56 8
+				       57 8
+				       58 8
+				       59 8 >;
+			interrupt-parent = < &ipic >;
+		};
 	};
 
 	pci@e0008500 {
arch/powerpc/boot/dts/mpc8379_mds.dts +14 -0
index cdb4426..9fe4bd2 100644
@@ -236,6 +236,20 @@
 			#interrupt-cells = <2>;
 			reg = <700 100>;
 		};
+
+		ipic-msi@7c0 {
+			compatible = "fsl,ipic-msi";
+			reg = <7c0 40>;
+			interrupts = < 43 8
+				       4  8
+				       51 8
+				       52 8
+				       56 8
+				       57 8
+				       58 8
+				       59 8 >;
+			interrupt-parent = < &ipic >;
+		};
 	};
 
 	pci@e0008500 {
arch/powerpc/platforms/83xx/Kconfig +6 -0
index 00154c5..4c51f78 100644
@@ -88,6 +88,12 @@ config PPC_MPC837x
 	select FSL_SERDES
 	default y if MPC837x_MDS
 
+config IPIC_MSI
+	bool
+	depends on PCI_MSI
+	default y if PPC_MPC837x
+	default n
+
 config PPC_MPC83XX_PCIE
 	bool "MPC837X PCI Express support"
 	depends on PCIEPORTBUS && PPC_MPC837x
arch/powerpc/platforms/83xx/mpc837x_mds.c +0 -0
index 6048f1b..dbea34b 100644

arch/powerpc/platforms/83xx/mpc837x_mds.c line 24

Quoted 8 lines
arch/powerpc/platforms/83xx/mpc837x_mds.c +3 -0
@@ -17,6 +17,9 @@
 
 #include <asm/time.h>
 #include <asm/ipic.h>
+#if CONFIG_IPIC_MSI
+#include <asm/ipic_msi.h>
+#endif
 #include <asm/udbg.h>
 #include <asm/prom.h>

I'd rather you just include it unconditionally.

arch/powerpc/platforms/83xx/mpc837x_mds.c static void __init mpc837x_mds_init_IRQ(void) · line 97

Quoted 12 lines
arch/powerpc/platforms/83xx/mpc837x_mds.c +8 -0
@@ -84,6 +87,14 @@ static void __init mpc837x_mds_init_IRQ(void)
 	 * in case the boot rom changed something on us.
 	 */
 	ipic_set_default_priority();
+
+#if CONFIG_IPIC_MSI
+	np = of_find_compatible_node(NULL, NULL, "fsl,ipic-msi");
+	if (!np)
+		return;
+
+	ipic_msi_init(np, ipic_msi_cascade);
+#endif

If you have a no-op version of ipic_msi_init() in your header file then you can remove the #ifdef in the C code - which I think is nicer.

Why do you pass the handler into the init routine, rather than have the init routine just set the handler. Then you could make the handler static.

Quoted 64 lines
arch/powerpc/platforms/83xx/mpc837x_mds.c +0 -0
 }
 
 /*
arch/powerpc/sysdev/Makefile +1 -0
index 99a77d7..5946b6a 100644
@@ -25,6 +25,7 @@ ifeq ($(CONFIG_PPC_MERGE),y)
 obj-$(CONFIG_PPC_INDIRECT_PCI)	+= indirect_pci.o
 obj-$(CONFIG_PPC_I8259)		+= i8259.o
 obj-$(CONFIG_PPC_83xx)		+= ipic.o
+obj-$(CONFIG_IPIC_MSI)		+= ipic_msi.o
 obj-$(CONFIG_4xx)		+= uic.o
 obj-$(CONFIG_XILINX_VIRTEX)	+= xilinx_intc.o
 endif
arch/powerpc/sysdev/ipic_msi.c new file +43 -0
new file mode 100644
index 0000000..57758f7
@@ -0,0 +1,359 @@
+/*
+ * arch/powerpc/sysdev/ipic_msi.c
+ *
+ * IPIC MSI routines implementations.
+ *
+ * Auther: Tony Li <[email protected]>
+ *
+ * Copyright (c) 2007 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute  it and/or modify it
+ * under  the terms of  the GNU General  Public License as published by the
+ * Free Software Foundation;  either version 2 of the  License, or (at your
+ * option) any later version.
+ */
+
+
+#include <linux/pci.h>
+#include <linux/msi.h>
+#include <linux/irq.h>
+
+#include <asm/ipic_msi.h>
+
+#define MSIR0	0x43
+#define MSIR1	0x4
+#define MSIR2	0x51
+#define MSIR3	0x52
+#define MSIR4	0x56
+#define MSIR5	0x57
+#define MSIR6	0x58
+#define MSIR7	0x59
+
+
+static struct ipic_msi *ipic_msi;
+static DEFINE_SPINLOCK(ipic_msi_lock);
+static DEFINE_SPINLOCK(ipic_msi_bitmap_lock);
+
+static inline u32 ipic_msi_read(volatile u32 __iomem *base, unsigned int reg)
+{
+	return in_be32(base + (reg >> 2));
+}
+
+static inline void ipic_msi_write(volatile u32 __iomem *base,
+					unsigned int reg, u32 value)

arch/powerpc/sysdev/ipic_msi.c line 53

Quoted 10 lines
arch/powerpc/sysdev/ipic_msi.c new file +10 -0
+{
+	out_be32(base + (reg >> 2), value);
+}
+
+static struct ipic_msi * ipic_msi_from_irq(unsigned int virq)
+{
+	return ipic_msi;
+}
+
+#define	ipic_msi_irq_to_hw(virq)	((unsigned int)irq_map[virq].hwirq)

What's wrong with virq_to_hw() ?

Quoted 108 lines
arch/powerpc/sysdev/ipic_msi.c new file +108 -0
+static void ipic_msi_unmask(unsigned int virq)
+{
+	struct ipic_msi *msi = ipic_msi_from_irq(virq);
+	unsigned int src = ipic_msi_irq_to_hw(virq);
+	unsigned long flags;
+	u32 temp;
+
+	spin_lock_irqsave(&ipic_msi_lock, flags);
+	temp = ipic_msi_read(msi->regs, IPIC_MSIMR);
+	ipic_msi_write(msi->regs, IPIC_MSIMR,
+		temp & ~(1 << (src / msi->int_per_msir)));
+
+	spin_unlock_irqrestore(&ipic_msi_lock, flags);
+}
+
+static void ipic_msi_mask(unsigned int virq)
+{
+	struct ipic_msi *msi = ipic_msi_from_irq(virq);
+	unsigned int src = ipic_msi_irq_to_hw(virq);
+	unsigned long flags;
+	u32 temp;
+
+	spin_lock_irqsave(&ipic_msi_lock, flags);
+
+	temp = ipic_msi_read(msi->regs, IPIC_MSIMR);
+	ipic_msi_write(msi->regs, IPIC_MSIMR,
+		temp | (1 << (src / msi->int_per_msir)));
+
+	spin_unlock_irqrestore(&ipic_msi_lock, flags);
+}
+/*
+ * We do not need this actually. The MSIR register has been read once
+ * in ipic_msi_get_irq. So, this MSI interrupt has been acked
+ */
+static void ipic_msi_ack(unsigned int virq)
+{
+	struct ipic_msi *msi = ipic_msi_from_irq(virq);
+	unsigned int src = ipic_msi_irq_to_hw(virq);
+	unsigned long flags;
+
+	spin_lock_irqsave(&ipic_msi_lock, flags);
+
+	ipic_msi_read(msi->regs, IPIC_MSIR0 + (4 * (src / msi->int_per_msir)));
+
+	spin_unlock_irqrestore(&ipic_msi_lock,flags);
+}
+
+static struct irq_chip ipic_msi_chip = {
+	.typename = " IPIC MSI ",
+	.unmask = ipic_msi_unmask,
+	.mask = ipic_msi_mask,
+	.ack = ipic_msi_ack,
+};
+
+static int ipic_msi_host_map(struct irq_host *h, unsigned int virq,
+				irq_hw_number_t hw)
+{
+	struct ipic_msi *msi = h->host_data;
+	struct irq_chip *chip = msi->hc_irq;
+
+	set_irq_chip_data(virq, msi);
+	get_irq_desc(virq)->status |= IRQ_TYPE_EDGE_FALLING;
+
+	set_irq_chip_and_handler(virq, chip, handle_edge_irq);
+	return 0;
+}
+
+static struct irq_host_ops ipic_msi_host_ops = {
+	.map = ipic_msi_host_map,
+};
+
+irq_hw_number_t ipic_msi_alloc_hwirqs(struct ipic_msi *msi, int num)
+{
+	unsigned long flags;
+	int offset, order = get_count_order(num);
+
+	spin_lock_irqsave(&ipic_msi_bitmap_lock, flags);
+
+	offset = bitmap_find_free_region(msi->ipic_msi_bitmap,
+			msi->nr_msir * msi->int_per_msir, order);
+
+	spin_unlock_irqrestore(&ipic_msi_bitmap_lock, flags);
+
+	pr_debug("%s: allocated 0x%x (2^%d) at offset 0x%x\n",
+		__FUNCTION__, num, order, offset);
+
+	return offset;
+}
+
+void ipic_msi_free_hwirqs(struct ipic_msi *msi, int offset, int num)
+{
+	unsigned long flags;
+	int order = get_count_order(num);
+
+	pr_debug("%s: freeing 0x%x (2^%d) at offset 0x%x\n",
+		__FUNCTION__, num, order, offset);
+
+	spin_lock_irqsave(&ipic_msi_bitmap_lock, flags);
+	bitmap_release_region(msi->ipic_msi_bitmap, offset, order);
+	spin_unlock_irqrestore(&ipic_msi_bitmap_lock, flags);
+}
+
+static int ipic_msi_init_allocator(struct ipic_msi *msi)
+{
+	int size;
+
+	size = BITS_TO_LONGS(msi->nr_msir * msi->int_per_msir) * sizeof(long);
+	msi->ipic_msi_bitmap = alloc_maybe_bootmem(size, GFP_KERNEL);

arch/powerpc/sysdev/ipic_msi.c line 171

Quoted 10 lines
arch/powerpc/sysdev/ipic_msi.c new file +10 -0
+
+	if (msi->ipic_msi_bitmap == NULL) {
+		pr_debug("%s: ENOMEM allocating allocator bitmap!\n",
+				__FUNCTION__);
+		return -ENOMEM;
+	}
+	memset(msi->ipic_msi_bitmap, 0, size);
+
+	return 0;
+}

The last three routines are almost identical to the mpic_msi.c ones, if in future we have a third implementation that looks almost identical maybe we should consolidate them.

Quoted 39 lines
arch/powerpc/sysdev/ipic_msi.c new file +39 -0
+
+static void ipic_msi_compose_msg(struct ipic_msi *msi, int hwirq,
+						struct msi_msg *msg)
+{
+	unsigned int srs;
+	unsigned int ibs;
+
+	srs = hwirq / msi->int_per_msir;
+	ibs = hwirq - srs * msi->int_per_msir;
+
+	msg->address_lo = msi->msi_addr_lo;
+	msg->address_hi = msi->msi_addr_hi;
+	msg->data = (srs << 5) | (ibs & 0x1F);
+
+	pr_debug("%s: allocated srs: %d, ibs: %d\n",
+		__FUNCTION__, srs, ibs);
+
+}
+
+static int ipic_msi_setup_irqs(struct pci_dev *pdev, int nvec, int type)
+{
+	struct ipic_msi *msi = ipic_msi;
+	irq_hw_number_t hwirq;
+	unsigned int virq;
+	struct msi_desc *entry;
+	struct msi_msg msg;
+
+	list_for_each_entry(entry, &pdev->msi_list, list) {
+		hwirq = ipic_msi_alloc_hwirqs(msi, 1);
+		if (hwirq < 0) {
+			pr_debug("%s: fail allocating msi interrupt\n",
+					__FUNCTION__);
+			return hwirq;
+		}
+
+		/* This hwirq belongs to the irq_host other than irq_host of IPIC
+ 		 * So, it is independent to hwirq of IPIC */
+		virq = irq_create_mapping(msi->irqhost, hwirq);
+		if (virq == NO_IRQ) {

arch/powerpc/sysdev/ipic_msi.c line 220

Quoted 10 lines
arch/powerpc/sysdev/ipic_msi.c new file +10 -0
+			pr_debug("%s: fail mapping hwirq 0x%lx\n",
+					__FUNCTION__, hwirq);
+			ipic_msi_free_hwirqs(msi, hwirq, 1);
+			return -ENOSPC;
+		}
+		set_irq_msi(virq, entry);
+		ipic_msi_compose_msg(msi, hwirq, &msg);
+		write_msi_msg(virq, &msg);
+
+		hwirq++;

^^^^ this looks like my bug

Quoted 59 lines
arch/powerpc/sysdev/ipic_msi.c new file +59 -0
+	}
+
+	return 0;
+}
+
+static void ipic_msi_teardown_irqs(struct pci_dev *pdev)
+{
+	struct msi_desc *entry;
+	struct ipic_msi *msi = ipic_msi;
+
+	list_for_each_entry(entry, &pdev->msi_list, list) {
+		if (entry->irq == NO_IRQ)
+			continue;
+		set_irq_msi(entry->irq, NULL);
+		ipic_msi_free_hwirqs(msi, virq_to_hw(entry->irq), 1);
+		irq_dispose_mapping(entry->irq);
+	}
+
+	return;
+}
+
+void __init ipic_msi_init(struct device_node *node,
+			void (*handler)(unsigned int irq, struct irq_desc *desc))
+{
+	struct ipic_msi *msi;
+	struct resource res;
+	int i;
+	int rc = 0;
+
+	msi = alloc_maybe_bootmem(sizeof(*msi), GFP_KERNEL);
+	if (msi == NULL)
+		return;
+
+	memset(msi, 0, sizeof(*msi));
+
+
+	msi->irqhost = irq_alloc_host(of_node_get(node), IRQ_HOST_MAP_LINEAR,
+					NR_MSIR, &ipic_msi_host_ops, 0);
+	if (msi->irqhost == NULL) {
+		of_node_put(node);
+		goto out;
+	}
+
+	rc = of_address_to_resource(node, 0, &res);
+	if (rc) {
+		of_node_put(node);
+		goto out;
+	}
+
+	msi->regs = ioremap(res.start, res.end - res.start + 1);
+	msi->irqhost->host_data = msi;
+	msi->hc_irq = &ipic_msi_chip;
+
+	msi->msi_addr_lo = 0xE00007F8;
+	msi->msi_addr_hi = 0;
+	msi->nr_msir = ARRAY_SIZE(msi->msir);
+	msi->int_per_msir = 32;
+	for (i = 0; i < msi->nr_msir; i++) {
+		unsigned int virt_msir = irq_of_parse_and_map(node, i);

arch/powerpc/sysdev/ipic_msi.c line 289

Quoted 10 lines
arch/powerpc/sysdev/ipic_msi.c new file +10 -0
+		if (virt_msir != NO_IRQ) {
+			set_irq_data(virt_msir, msi);
+			set_irq_chained_handler(virt_msir, handler);
+			msi->msir[i] = virt_msir;
+		} else
+			msi->msir[i] = NO_IRQ;
+	}
+
+	rc = ipic_msi_init_allocator(msi);
+	if (rc)
		< missing of_node_put() ? >

arch/powerpc/sysdev/ipic_msi.c line 297

Quoted 8 lines
arch/powerpc/sysdev/ipic_msi.c new file +8 -0
+		goto out;
+
+	ipic_msi = msi;
+
+	WARN_ON(ppc_md.setup_msi_irqs);
+	ppc_md.setup_msi_irqs = ipic_msi_setup_irqs;
+	ppc_md.teardown_msi_irqs = ipic_msi_teardown_irqs;
+

return ?

Quoted 52 lines
arch/powerpc/sysdev/ipic_msi.c new file +52 -0
+out:
+	if (mem_init_done)
+		kfree(msi);
+
+	return;
+}
+
+static int ipic_msi_get_irq(struct ipic_msi *msi, int virt_msir)
+{
+	int msir = -1;
+	unsigned int temp;
+	unsigned int offset;
+	int i;
+
+	for (i = 0; i < msi->nr_msir; i++)
+		if (virt_msir == msi->msir[i]) {
+			msir = i;
+			break;
+		}
+
+	if (i >= msi->nr_msir)
+		return NO_IRQ;
+
+	temp = ipic_msi_read(msi->regs, IPIC_MSIR0 + (i * 4));
+	offset = ffs(temp) - 1;
+
+	return irq_linear_revmap(msi->irqhost, (msir * msi->int_per_msir + offset));
+}
+
+void ipic_msi_cascade(unsigned int irq, struct irq_desc *desc)
+{
+	struct ipic_msi *msi;
+	unsigned int cascade_irq;
+
+	spin_lock(&desc->lock);
+	if (desc->chip->mask_ack)
+		desc->chip->mask_ack(irq);
+	else {
+		desc->chip->mask(irq);
+		desc->chip->ack(irq);
+	}
+
+	if (unlikely(desc->status & IRQ_INPROGRESS))
+		goto unlock;
+
+	desc->status |= IRQ_INPROGRESS;
+	msi = desc->handler_data;
+	cascade_irq = ipic_msi_get_irq(msi, irq);
+
+	spin_unlock(&desc->lock);
+
+	if (cascade_irq != NO_IRQ)

arch/powerpc/sysdev/ipic_msi.c line 359

Quoted 10 lines
arch/powerpc/sysdev/ipic_msi.c new file +10 -0
+		generic_handle_irq(cascade_irq);
+
+	spin_lock(&desc->lock);
+	desc->status &= ~IRQ_INPROGRESS;
+	if (!(desc->status & IRQ_DISABLED) && desc->chip->unmask)
+		desc->chip->unmask(irq);
+
+unlock:
+	spin_unlock(&desc->lock);
+}

I don't know your hardware, but this looks a bit weird. Doesn't the upstream handler do most of this logic for you?

cheers

Signature · 8 lines
Michael Ellerman
OzLabs, IBM Australia Development Lab

wwweb: http://michael.ellerman.id.au
phone: +61 2 6212 1183 (tie line 70 21183)

We do not inherit the earth from our ancestors,
we borrow it from our children. - S.M.A.R.T Person
author
#4 lore raw

Hi Michael,

I emulate mpic to write this IPIC MSI routines. :)

Quoted 6 lines
Quoted 6 lines
arch/powerpc/platforms/83xx/mpc837x_mds.c +0 -0
index 6048f1b..dbea34b 100644
@@ -17,6 +17,9 @@
 
Quoted 9 lines

arch/powerpc/platforms/83xx/mpc837x_mds.c line 24

Quoted 7 lines
arch/powerpc/platforms/83xx/mpc837x_mds.c +3 -0
 #include <asm/time.h>
 #include <asm/ipic.h>
+#if CONFIG_IPIC_MSI
+#include <asm/ipic_msi.h>
+#endif
 #include <asm/udbg.h>
 #include <asm/prom.h>

I'd rather you just include it unconditionally.

Yes. that is ok for me.

Quoted 17 lines

arch/powerpc/platforms/83xx/mpc837x_mds.c static void __init mpc837x_mds_init_IRQ(void) · line 97

Quoted 13 lines
arch/powerpc/platforms/83xx/mpc837x_mds.c +8 -0
@@ -84,6 +87,14 @@ static void __init mpc837x_mds_init_IRQ(void)
 	 * in case the boot rom changed something on us.
 	 */
 	ipic_set_default_priority();
+
+#if CONFIG_IPIC_MSI
+	np = of_find_compatible_node(NULL, NULL, "fsl,ipic-msi");
+	if (!np)
+		return;
+
+	ipic_msi_init(np, ipic_msi_cascade);
+#endif

If you have a no-op version of ipic_msi_init() in your header file then you can remove the #ifdef in the C code - which I think is nicer.

Seems you do not like #ifdef. :) I agree it.
So, I move this #ifdef into header file.

Quoted 4 lines

Why do you pass the handler into the init routine, rather than have the init routine just set the handler. Then you could make the handler static.

In IPIC, the 8 MSI interrupts is handled as level intrrupt. I just provide a versatile in case it is changed.

Quoted 68 lines
Quoted 68 lines
arch/powerpc/platforms/83xx/mpc837x_mds.c +0 -0
 }
 
 /*
arch/powerpc/sysdev/Makefile +1 -0
index 99a77d7..5946b6a 100644
@@ -25,6 +25,7 @@ ifeq ($(CONFIG_PPC_MERGE),y)
 obj-$(CONFIG_PPC_INDIRECT_PCI)	+= indirect_pci.o
 obj-$(CONFIG_PPC_I8259)		+= i8259.o
 obj-$(CONFIG_PPC_83xx)		+= ipic.o
+obj-$(CONFIG_IPIC_MSI)		+= ipic_msi.o
 obj-$(CONFIG_4xx)		+= uic.o
 obj-$(CONFIG_XILINX_VIRTEX)	+= xilinx_intc.o
 endif
arch/powerpc/sysdev/ipic_msi.c new file +47 -0
new file mode 100644
index 0000000..57758f7
@@ -0,0 +1,359 @@
+/*
+ * arch/powerpc/sysdev/ipic_msi.c
+ *
+ * IPIC MSI routines implementations.
+ *
+ * Auther: Tony Li <[email protected]>
+ *
+ * Copyright (c) 2007 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute  it and/or modify it
+ * under  the terms of  the GNU General  Public License as published by the
+ * Free Software Foundation;  either version 2 of the  License, or (at your
+ * option) any later version.
+ */
+
+
+#include <linux/pci.h>
+#include <linux/msi.h>
+#include <linux/irq.h>
+
+#include <asm/ipic_msi.h>
+
+#define MSIR0	0x43
+#define MSIR1	0x4
+#define MSIR2	0x51
+#define MSIR3	0x52
+#define MSIR4	0x56
+#define MSIR5	0x57
+#define MSIR6	0x58
+#define MSIR7	0x59
+
+
+static struct ipic_msi *ipic_msi;
+static DEFINE_SPINLOCK(ipic_msi_lock);
+static DEFINE_SPINLOCK(ipic_msi_bitmap_lock);
+
+static inline u32 ipic_msi_read(volatile u32 __iomem *base, unsigned int reg)
+{
+	return in_be32(base + (reg >> 2));
+}
+
+static inline void ipic_msi_write(volatile u32 __iomem *base,
+					unsigned int reg, u32 value)
+{
+	out_be32(base + (reg >> 2), value);
+}
+
Quoted 9 lines

arch/powerpc/sysdev/ipic_msi.c line 53

Quoted 6 lines
arch/powerpc/sysdev/ipic_msi.c new file +6 -0
+static struct ipic_msi * ipic_msi_from_irq(unsigned int virq)
+{
+	return ipic_msi;
+}
+
+#define	ipic_msi_irq_to_hw(virq)	((unsigned int)irq_map[virq].hwirq)

What's wrong with virq_to_hw() ?

viqr_to_hw is not __inline__.

Quoted 115 lines
Quoted 115 lines
arch/powerpc/sysdev/ipic_msi.c new file +114 -0
+static void ipic_msi_unmask(unsigned int virq)
+{
+	struct ipic_msi *msi = ipic_msi_from_irq(virq);
+	unsigned int src = ipic_msi_irq_to_hw(virq);
+	unsigned long flags;
+	u32 temp;
+
+	spin_lock_irqsave(&ipic_msi_lock, flags);
+	temp = ipic_msi_read(msi->regs, IPIC_MSIMR);
+	ipic_msi_write(msi->regs, IPIC_MSIMR,
+		temp & ~(1 << (src / msi->int_per_msir)));
+
+	spin_unlock_irqrestore(&ipic_msi_lock, flags);
+}
+
+static void ipic_msi_mask(unsigned int virq)
+{
+	struct ipic_msi *msi = ipic_msi_from_irq(virq);
+	unsigned int src = ipic_msi_irq_to_hw(virq);
+	unsigned long flags;
+	u32 temp;
+
+	spin_lock_irqsave(&ipic_msi_lock, flags);
+
+	temp = ipic_msi_read(msi->regs, IPIC_MSIMR);
+	ipic_msi_write(msi->regs, IPIC_MSIMR,
+		temp | (1 << (src / msi->int_per_msir)));
+
+	spin_unlock_irqrestore(&ipic_msi_lock, flags);
+}
+/*
+ * We do not need this actually. The MSIR register has been read once
+ * in ipic_msi_get_irq. So, this MSI interrupt has been acked
+ */
+static void ipic_msi_ack(unsigned int virq)
+{
+	struct ipic_msi *msi = ipic_msi_from_irq(virq);
+	unsigned int src = ipic_msi_irq_to_hw(virq);
+	unsigned long flags;
+
+	spin_lock_irqsave(&ipic_msi_lock, flags);
+
+	ipic_msi_read(msi->regs, IPIC_MSIR0 + (4 * (src / msi->int_per_msir)));
+
+	spin_unlock_irqrestore(&ipic_msi_lock,flags);
+}
+
+static struct irq_chip ipic_msi_chip = {
+	.typename = " IPIC MSI ",
+	.unmask = ipic_msi_unmask,
+	.mask = ipic_msi_mask,
+	.ack = ipic_msi_ack,
+};
+
+static int ipic_msi_host_map(struct irq_host *h, unsigned int virq,
+				irq_hw_number_t hw)
+{
+	struct ipic_msi *msi = h->host_data;
+	struct irq_chip *chip = msi->hc_irq;
+
+	set_irq_chip_data(virq, msi);
+	get_irq_desc(virq)->status |= IRQ_TYPE_EDGE_FALLING;
+
+	set_irq_chip_and_handler(virq, chip, handle_edge_irq);
+	return 0;
+}
+
+static struct irq_host_ops ipic_msi_host_ops = {
+	.map = ipic_msi_host_map,
+};
+
+irq_hw_number_t ipic_msi_alloc_hwirqs(struct ipic_msi *msi, int num)
+{
+	unsigned long flags;
+	int offset, order = get_count_order(num);
+
+	spin_lock_irqsave(&ipic_msi_bitmap_lock, flags);
+
+	offset = bitmap_find_free_region(msi->ipic_msi_bitmap,
+			msi->nr_msir * msi->int_per_msir, order);
+
+	spin_unlock_irqrestore(&ipic_msi_bitmap_lock, flags);
+
+	pr_debug("%s: allocated 0x%x (2^%d) at offset 0x%x\n",
+		__FUNCTION__, num, order, offset);
+
+	return offset;
+}
+
+void ipic_msi_free_hwirqs(struct ipic_msi *msi, int offset, int num)
+{
+	unsigned long flags;
+	int order = get_count_order(num);
+
+	pr_debug("%s: freeing 0x%x (2^%d) at offset 0x%x\n",
+		__FUNCTION__, num, order, offset);
+
+	spin_lock_irqsave(&ipic_msi_bitmap_lock, flags);
+	bitmap_release_region(msi->ipic_msi_bitmap, offset, order);
+	spin_unlock_irqrestore(&ipic_msi_bitmap_lock, flags);
+}
+
+static int ipic_msi_init_allocator(struct ipic_msi *msi)
+{
+	int size;
+
+	size = BITS_TO_LONGS(msi->nr_msir * msi->int_per_msir) * sizeof(long);
+	msi->ipic_msi_bitmap = alloc_maybe_bootmem(size, GFP_KERNEL);
+
+	if (msi->ipic_msi_bitmap == NULL) {
+		pr_debug("%s: ENOMEM allocating allocator bitmap!\n",
+				__FUNCTION__);
+		return -ENOMEM;
+	}
Quoted 9 lines

arch/powerpc/sysdev/ipic_msi.c line 171

Quoted 4 lines
arch/powerpc/sysdev/ipic_msi.c new file +4 -0
+	memset(msi->ipic_msi_bitmap, 0, size);
+
+	return 0;
+}

The last three routines are almost identical to the mpic_msi.c ones, if in future we have a third implementation that looks almost identical maybe we should consolidate them.

Yes. I agree.

Quoted 43 lines
Quoted 43 lines
arch/powerpc/sysdev/ipic_msi.c new file +43 -0
+
+static void ipic_msi_compose_msg(struct ipic_msi *msi, int hwirq,
+						struct msi_msg *msg)
+{
+	unsigned int srs;
+	unsigned int ibs;
+
+	srs = hwirq / msi->int_per_msir;
+	ibs = hwirq - srs * msi->int_per_msir;
+
+	msg->address_lo = msi->msi_addr_lo;
+	msg->address_hi = msi->msi_addr_hi;
+	msg->data = (srs << 5) | (ibs & 0x1F);
+
+	pr_debug("%s: allocated srs: %d, ibs: %d\n",
+		__FUNCTION__, srs, ibs);
+
+}
+
+static int ipic_msi_setup_irqs(struct pci_dev *pdev, int nvec, int type)
+{
+	struct ipic_msi *msi = ipic_msi;
+	irq_hw_number_t hwirq;
+	unsigned int virq;
+	struct msi_desc *entry;
+	struct msi_msg msg;
+
+	list_for_each_entry(entry, &pdev->msi_list, list) {
+		hwirq = ipic_msi_alloc_hwirqs(msi, 1);
+		if (hwirq < 0) {
+			pr_debug("%s: fail allocating msi interrupt\n",
+					__FUNCTION__);
+			return hwirq;
+		}
+
+		/* This hwirq belongs to the irq_host other than irq_host of IPIC
+ 		 * So, it is independent to hwirq of IPIC */
+		virq = irq_create_mapping(msi->irqhost, hwirq);
+		if (virq == NO_IRQ) {
+			pr_debug("%s: fail mapping hwirq 0x%lx\n",
+					__FUNCTION__, hwirq);
+			ipic_msi_free_hwirqs(msi, hwirq, 1);
+			return -ENOSPC;
Quoted 8 lines

arch/powerpc/sysdev/ipic_msi.c line 220

Quoted 6 lines
arch/powerpc/sysdev/ipic_msi.c new file +6 -0
+		}
+		set_irq_msi(virq, entry);
+		ipic_msi_compose_msg(msi, hwirq, &msg);
+		write_msi_msg(virq, &msg);
+
+		hwirq++;

^^^^ this looks like my bug

I have a question here. Do we support more MSI interrupts on ONE pci device?

Quoted 71 lines
Quoted 60 lines
arch/powerpc/sysdev/ipic_msi.c new file +59 -0
+	}
+
+	return 0;
+}
+
+static void ipic_msi_teardown_irqs(struct pci_dev *pdev)
+{
+	struct msi_desc *entry;
+	struct ipic_msi *msi = ipic_msi;
+
+	list_for_each_entry(entry, &pdev->msi_list, list) {
+		if (entry->irq == NO_IRQ)
+			continue;
+		set_irq_msi(entry->irq, NULL);
+		ipic_msi_free_hwirqs(msi, virq_to_hw(entry->irq), 1);
+		irq_dispose_mapping(entry->irq);
+	}
+
+	return;
+}
+
+void __init ipic_msi_init(struct device_node *node,
+			void (*handler)(unsigned int irq, struct irq_desc *desc))
+{
+	struct ipic_msi *msi;
+	struct resource res;
+	int i;
+	int rc = 0;
+
+	msi = alloc_maybe_bootmem(sizeof(*msi), GFP_KERNEL);
+	if (msi == NULL)
+		return;
+
+	memset(msi, 0, sizeof(*msi));
+
+
+	msi->irqhost = irq_alloc_host(of_node_get(node), IRQ_HOST_MAP_LINEAR,
+					NR_MSIR, &ipic_msi_host_ops, 0);
+	if (msi->irqhost == NULL) {
+		of_node_put(node);
+		goto out;
+	}
+
+	rc = of_address_to_resource(node, 0, &res);
+	if (rc) {
+		of_node_put(node);
+		goto out;
+	}
+
+	msi->regs = ioremap(res.start, res.end - res.start + 1);
+	msi->irqhost->host_data = msi;
+	msi->hc_irq = &ipic_msi_chip;
+
+	msi->msi_addr_lo = 0xE00007F8;
+	msi->msi_addr_hi = 0;
+	msi->nr_msir = ARRAY_SIZE(msi->msir);
+	msi->int_per_msir = 32;
+	for (i = 0; i < msi->nr_msir; i++) {
+		unsigned int virt_msir = irq_of_parse_and_map(node, i);

arch/powerpc/sysdev/ipic_msi.c line 289

Quoted 10 lines
arch/powerpc/sysdev/ipic_msi.c new file +10 -0
+		if (virt_msir != NO_IRQ) {
+			set_irq_data(virt_msir, msi);
+			set_irq_chained_handler(virt_msir, handler);
+			msi->msir[i] = virt_msir;
+		} else
+			msi->msir[i] = NO_IRQ;
+	}
+
+	rc = ipic_msi_init_allocator(msi);
+	if (rc)
		< missing of_node_put() ? >
Quoted 10 lines

arch/powerpc/sysdev/ipic_msi.c line 297

Quoted 8 lines
arch/powerpc/sysdev/ipic_msi.c new file +8 -0
+		goto out;
+
+	ipic_msi = msi;
+
+	WARN_ON(ppc_md.setup_msi_irqs);
+	ppc_md.setup_msi_irqs = ipic_msi_setup_irqs;
+	ppc_md.teardown_msi_irqs = ipic_msi_teardown_irqs;
+

return ?

Sorry for that. It is a mistake.

Quoted 57 lines
Quoted 57 lines
arch/powerpc/sysdev/ipic_msi.c new file +57 -0
+out:
+	if (mem_init_done)
+		kfree(msi);
+
+	return;
+}
+
+static int ipic_msi_get_irq(struct ipic_msi *msi, int virt_msir)
+{
+	int msir = -1;
+	unsigned int temp;
+	unsigned int offset;
+	int i;
+
+	for (i = 0; i < msi->nr_msir; i++)
+		if (virt_msir == msi->msir[i]) {
+			msir = i;
+			break;
+		}
+
+	if (i >= msi->nr_msir)
+		return NO_IRQ;
+
+	temp = ipic_msi_read(msi->regs, IPIC_MSIR0 + (i * 4));
+	offset = ffs(temp) - 1;
+
+	return irq_linear_revmap(msi->irqhost, (msir * msi->int_per_msir + offset));
+}
+
+void ipic_msi_cascade(unsigned int irq, struct irq_desc *desc)
+{
+	struct ipic_msi *msi;
+	unsigned int cascade_irq;
+
+	spin_lock(&desc->lock);
+	if (desc->chip->mask_ack)
+		desc->chip->mask_ack(irq);
+	else {
+		desc->chip->mask(irq);
+		desc->chip->ack(irq);
+	}
+
+	if (unlikely(desc->status & IRQ_INPROGRESS))
+		goto unlock;
+
+	desc->status |= IRQ_INPROGRESS;
+	msi = desc->handler_data;
+	cascade_irq = ipic_msi_get_irq(msi, irq);
+
+	spin_unlock(&desc->lock);
+
+	if (cascade_irq != NO_IRQ)
+		generic_handle_irq(cascade_irq);
+
+	spin_lock(&desc->lock);
+	desc->status &= ~IRQ_INPROGRESS;
+	if (!(desc->status & IRQ_DISABLED) && desc->chip->unmask)
Quoted 9 lines

arch/powerpc/sysdev/ipic_msi.c line 359

Quoted 5 lines
arch/powerpc/sysdev/ipic_msi.c new file +5 -0
+		desc->chip->unmask(irq);
+
+unlock:
+	spin_unlock(&desc->lock);
+}

I don't know your hardware, but this looks a bit weird. Doesn't the upstream handler do most of this logic for you?

I just emulate the handle_level_irq to write this.
But I need get irq number from MSI controller (ipic_msi_get_irq) and then call interrupt routine of that irq number.

- Tony

#5 lore raw
Quoted 3 lines · Li Li

In IPIC, the 8 MSI interrupts is handled as level intrrupt. I just provide a versatile in case it is changed.

Level ? Are you sure ? MSIs are by definition edge interrupts... Or do you have some weird logic that asserts a level input until you go ack something ? Sounds weird...

Ben.

author
#6 lore raw
Quoted 11 lines · Benjamin Herrenschmidt
Quoted 3 lines · Li Li

In IPIC, the 8 MSI interrupts is handled as level intrrupt. I just provide a versatile in case it is changed.

Level ? Are you sure ? MSIs are by definition edge interrupts... Or do
you have some weird logic that asserts a level input until you go ack something ? Sounds weird...

The second one.
The MSI is edge interrupt. The 256 MSI interrupts are divided into 8 groups. Each group can generate a interrupt to core. This interrupts are level and asserted untile ack MSI interrupt. A little weird.

Quoted 3 lines

Ben.

- Tony

#7 lore raw
In reply to Li Li
Quoted 10 lines · Li Li

Hi Michael,

I emulate mpic to write this IPIC MSI routines. :)

Quoted 4 lines
Quoted 4 lines
arch/powerpc/platforms/83xx/mpc837x_mds.c +0 -0
index 6048f1b..dbea34b 100644
Quoted 7 lines
Quoted 5 lines

arch/powerpc/platforms/83xx/mpc837x_mds.c

Quoted 2 lines
arch/powerpc/platforms/83xx/mpc837x_mds.c +2 -0
+
+#define	ipic_msi_irq_to_hw(virq)	((unsigned int)irq_map[virq].hwirq)

What's wrong with virq_to_hw() ?

viqr_to_hw is not __inline__.

Hmm, ok. The three places you use it you also take a spin lock, so I'm not sure the function call's really going to kill you performance wise.

Quoted 52 lines
Quoted 43 lines
Quoted 43 lines
arch/powerpc/platforms/83xx/mpc837x_mds.c +43 -0
+
+static void ipic_msi_compose_msg(struct ipic_msi *msi, int hwirq,
+						struct msi_msg *msg)
+{
+	unsigned int srs;
+	unsigned int ibs;
+
+	srs = hwirq / msi->int_per_msir;
+	ibs = hwirq - srs * msi->int_per_msir;
+
+	msg->address_lo = msi->msi_addr_lo;
+	msg->address_hi = msi->msi_addr_hi;
+	msg->data = (srs << 5) | (ibs & 0x1F);
+
+	pr_debug("%s: allocated srs: %d, ibs: %d\n",
+		__FUNCTION__, srs, ibs);
+
+}
+
+static int ipic_msi_setup_irqs(struct pci_dev *pdev, int nvec, int type)
+{
+	struct ipic_msi *msi = ipic_msi;
+	irq_hw_number_t hwirq;
+	unsigned int virq;
+	struct msi_desc *entry;
+	struct msi_msg msg;
+
+	list_for_each_entry(entry, &pdev->msi_list, list) {
+		hwirq = ipic_msi_alloc_hwirqs(msi, 1);
+		if (hwirq < 0) {
+			pr_debug("%s: fail allocating msi interrupt\n",
+					__FUNCTION__);
+			return hwirq;
+		}
+
+		/* This hwirq belongs to the irq_host other than irq_host of IPIC
+ 		 * So, it is independent to hwirq of IPIC */
+		virq = irq_create_mapping(msi->irqhost, hwirq);
+		if (virq == NO_IRQ) {
+			pr_debug("%s: fail mapping hwirq 0x%lx\n",
+					__FUNCTION__, hwirq);
+			ipic_msi_free_hwirqs(msi, hwirq, 1);
+			return -ENOSPC;
Quoted 8 lines

arch/powerpc/platforms/83xx/mpc837x_mds.c

Quoted 6 lines
arch/powerpc/platforms/83xx/mpc837x_mds.c +6 -0
+		}
+		set_irq_msi(virq, entry);
+		ipic_msi_compose_msg(msi, hwirq, &msg);
+		write_msi_msg(virq, &msg);
+
+		hwirq++;

^^^^ this looks like my bug

Quoted 2 lines

I have a question here. Do we support more MSI interrupts on ONE pci device?

I'm not sure what you mean? For MSI there is only one MSI per device, but this code is used also for MSI-X which supports > 1 MSI per device.

Either way we shouldn't be incrementing hwirq by hand, it's reassigned at the top of the loop. I think that's left over from old code that allocated nvec hwirqs in a block and then created virq mappings for each one, whereas the new code allocates each hwirq separately.

cheers

Signature · 8 lines
Michael Ellerman
OzLabs, IBM Australia Development Lab

wwweb: http://michael.ellerman.id.au
phone: +61 2 6212 1183 (tie line 70 21183)

We do not inherit the earth from our ancestors,
we borrow it from our children. - S.M.A.R.T Person
#8 lore raw
Quoted 2 lines

I'm not sure what you mean? For MSI there is only one MSI per device, but this code is used also for MSI-X which supports > 1 MSI per device.

Or more specifically, for MSI, -linux- supports only one per device (in theory, it's possible to have multiple MSI non-X but it's a mess).

Quoted 11 lines

Either way we shouldn't be incrementing hwirq by hand, it's reassigned at the top of the loop. I think that's left over from old code that allocated nvec hwirqs in a block and then created virq mappings for each one, whereas the new code allocates each hwirq separately.

cheers

_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://ozlabs.org/mailman/listinfo/linuxppc-dev

author
#9 lore raw

Yes. According to the PCI spec, a PCI device can request multi MSI interrupts and require that interrupts are consecutive.
But it is ok if only allocate one to it.
Anyway, the hwirq should be allocated from bitmap instead of increment by hand.

I will correct this and resend the patch.

- Tony

Quoted 23 lines · Benjamin Herrenschmidt
Quoted 1 line

I'm not sure what you mean? For MSI there is only one MSI per

device,

Quoted 1 line

but this code is used also for MSI-X which supports > 1 MSI per

device.

Or more specifically, for MSI, -linux- supports only one per device (in
theory, it's possible to have multiple MSI non-X but it's a mess).

Quoted 1 line

Either way we shouldn't be incrementing hwirq by hand, it's

reassigned

Quoted 2 lines

at the top of the loop. I think that's left over from old code that allocated nvec hwirqs in a block and then created virq mappings for

each

Quoted 8 lines

one, whereas the new code allocates each hwirq separately.

cheers

_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://ozlabs.org/mailman/listinfo/linuxppc-dev

#10 lore raw
In reply to Michael Ellerman

=20

Quoted 25 lines

-----Original Message-----
From: Michael Ellerman [mailto:[email protected]]=20
Sent: 2007=C4=EA12=D4=C24=C8=D5 13:38
To: Li Tony
Cc: Li Tony; Gala Kumar; linuxppc-dev
Subject: Re: [PATCH] Add IPIC MSI interrupt support =20

Quoted 10 lines · Li Li

Hi Michael,
=20
I emulate mpic to write this IPIC MSI routines. :) =20
=20

Quoted 5 lines

arch/powerpc/platforms/83xx/mpc837x_mds.c

Quoted 5 lines
arch/powerpc/platforms/83xx/mpc837x_mds.c +0 -0
index 6048f1b..dbea34b 100644

=20

Quoted 2 lines
Quoted 2 lines

arch/powerpc/platforms/83xx/mpc837x_mds.c

Quoted 2 lines
arch/powerpc/platforms/83xx/mpc837x_mds.c +2 -0
+
+#define	ipic_msi_irq_to_hw(virq)=09

((unsigned int)irq_map[virq].hwirq)

Quoted 3 lines
Quoted 3 lines

=20
What's wrong with virq_to_hw() ?
=20

Quoted 7 lines
Quoted 2 lines

=20
viqr_to_hw is not __inline__.

=20
Hmm, ok. The three places you use it you also take a spin=20 lock, so I'm not sure the function call's really going to=20 kill you performance wise.
=20

I am not very sure about spin_lock influence.
But maybe somebody will change the virq_to_hw implementation. I will take virq_to_hw instead.=20

I see that the virq_to_hw is do inline in 2.6.22.
Why remove it?

Quoted 83 lines
Quoted 2 lines
Quoted 2 lines

arch/powerpc/platforms/83xx/mpc837x_mds.c

Quoted 2 lines
arch/powerpc/platforms/83xx/mpc837x_mds.c +2 -0
+
+static void ipic_msi_compose_msg(struct ipic_msi *msi,=20

int hwirq,

Quoted 1 line
Quoted 1 line

arch/powerpc/platforms/83xx/mpc837x_mds.c

Quoted 1 line
arch/powerpc/platforms/83xx/mpc837x_mds.c +1 -0
+						struct=20

msi_msg *msg)

Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
arch/powerpc/platforms/83xx/mpc837x_mds.c +20 -0
+{
+	unsigned int srs;
+	unsigned int ibs;
+
+	srs =3D hwirq / msi->int_per_msir;
+	ibs =3D hwirq - srs * msi->int_per_msir;
+
+	msg->address_lo =3D msi->msi_addr_lo;
+	msg->address_hi =3D msi->msi_addr_hi;
+	msg->data =3D (srs << 5) | (ibs & 0x1F);
+
+	pr_debug("%s: allocated srs: %d, ibs: %d\n",
+		__FUNCTION__, srs, ibs);
+
+}
+
+static int ipic_msi_setup_irqs(struct pci_dev *pdev, int nvec,=20
+int type) {
+	struct ipic_msi *msi =3D ipic_msi;
+	irq_hw_number_t hwirq;
Quoted 8 lines
Quoted 8 lines

arch/powerpc/platforms/83xx/mpc837x_mds.c

Quoted 8 lines
arch/powerpc/platforms/83xx/mpc837x_mds.c +8 -0
+	unsigned int virq;
+	struct msi_desc *entry;
+	struct msi_msg msg;
+
+	list_for_each_entry(entry, &pdev->msi_list, list) {
+		hwirq =3D ipic_msi_alloc_hwirqs(msi, 1);
+		if (hwirq < 0) {
+			pr_debug("%s: fail allocating=20

msi interrupt\n",

Quoted 5 lines
Quoted 5 lines

arch/powerpc/platforms/83xx/mpc837x_mds.c

Quoted 5 lines
arch/powerpc/platforms/83xx/mpc837x_mds.c +5 -0
+					__FUNCTION__);
+			return hwirq;
+		}
+
+		/* This hwirq belongs to the irq_host=20

other than irq_host of IPIC

Quoted 4 lines
Quoted 4 lines

arch/powerpc/platforms/83xx/mpc837x_mds.c

Quoted 4 lines
arch/powerpc/platforms/83xx/mpc837x_mds.c +4 -0
+ 		 * So, it is independent to hwirq of IPIC */
+		virq =3D irq_create_mapping(msi->irqhost, hwirq);
+		if (virq =3D=3D NO_IRQ) {
+			pr_debug("%s: fail mapping=20

hwirq 0x%lx\n",

Quoted 11 lines
Quoted 11 lines

arch/powerpc/platforms/83xx/mpc837x_mds.c

Quoted 9 lines
arch/powerpc/platforms/83xx/mpc837x_mds.c +9 -0
+					__FUNCTION__, hwirq);
+			ipic_msi_free_hwirqs(msi, hwirq, 1);
+			return -ENOSPC;
+		}
+		set_irq_msi(virq, entry);
+		ipic_msi_compose_msg(msi, hwirq, &msg);
+		write_msi_msg(virq, &msg);
+
+		hwirq++;

=20
^^^^ this looks like my bug

Quoted 2 lines

=20
I have a question here. Do we support more MSI interrupts=20

on ONE pci=20

Quoted 1 line

device?

=20
I'm not sure what you mean? For MSI there is only one MSI per=20 device, but this code is used also for MSI-X which supports >=20 1 MSI per device.
=20
Either way we shouldn't be incrementing hwirq by hand, it's=20 reassigned at the top of the loop. I think that's left over=20 from old code that allocated nvec hwirqs in a block and then=20 created virq mappings for each one, whereas the new code=20 allocates each hwirq separately.
=20
cheers
=20
--
Michael Ellerman
OzLabs, IBM Australia Development Lab
=20
wwweb: http://michael.ellerman.id.au
phone: +61 2 6212 1183 (tie line 70 21183)
=20
We do not inherit the earth from our ancestors, we borrow it=20 from our children. - S.M.A.R.T Person
=20

#11 lore raw
Quoted 27 lines · Li Tony
Quoted 27 lines

From: Michael Ellerman [mailto:[email protected]]
Sent: 2007年12月4日 13:38
To: Li Tony
Cc: Li Tony; Gala Kumar; linuxppc-dev
Subject: Re: [PATCH] Add IPIC MSI interrupt support

Quoted 5 lines · Li Li

Hi Michael,

I emulate mpic to write this IPIC MSI routines. :)

Quoted 8 lines
Quoted 8 lines

arch/powerpc/platforms/83xx/mpc837x_mds.c

Quoted 8 lines
arch/powerpc/platforms/83xx/mpc837x_mds.c +2 -0
index 6048f1b..dbea34b 100644
 
+
+#define	ipic_msi_irq_to_hw(virq)	

((unsigned int)irq_map[virq].hwirq)

Quoted 5 lines
Quoted 3 lines

What's wrong with virq_to_hw() ?

viqr_to_hw is not __inline__.

Quoted 8 lines
Quoted 4 lines

Hmm, ok. The three places you use it you also take a spin lock, so I'm not sure the function call's really going to kill you performance wise.

I am not very sure about spin_lock influence.
But maybe somebody will change the virq_to_hw implementation. I will take virq_to_hw instead.

I mean the time to take the function call should be pretty small compared to taking and releasing a spinlock - but if you have performance numbers to prove otherwise let me know :)

Quoted 2 lines

I see that the virq_to_hw is do inline in 2.6.22.
Why remove it?

It was made non-inline because modules want to use it, and we didn't want to export the irq_map to modules as well.

cheers

Signature · 8 lines
Michael Ellerman
OzLabs, IBM Australia Development Lab

wwweb: http://michael.ellerman.id.au
phone: +61 2 6212 1183 (tie line 70 21183)

We do not inherit the earth from our ancestors,
we borrow it from our children. - S.M.A.R.T Person
#12 lore raw
Quoted 8 lines · Michael Ellerman
Quoted 3 lines · Li Tony

I am not very sure about spin_lock influence.
But maybe somebody will change the virq_to_hw implementation. I will take virq_to_hw instead.

I mean the time to take the function call should be pretty small compared to taking and releasing a spinlock - but if you have performance numbers to prove otherwise let me know :)

I don't think the IPIC is used on any SMP platforms at the moment, so there's no spinlock overhead other than disabling interrupts...

That said, it's not worth reimplementing to avoid a function call.

-Scott