Skip to contentSkip to conversation

Clean up IRQ mapping code

PATCH New Paul Mackerras 1 participant 1 message Feb 25, 2004

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Clean up IRQ mapping code

On the larger ppc64 machines we remap the interrupt numbers used by the hardware/firmware to virtual IRQ numbers < NR_IRQS. Up until now we have used an array for the "real" (hardware) -> virtual IRQ number mapping, but with new machines coming out that will have 24-bit hardware IRQ numbers, this will break. However, in fact it is only the XICS interrupt controller which cares about this mapping. This patch moves that side of the mapping (real -> virtual) into the XICS code and makes it use a radix tree.

On iSeries we have a similar issue, where the "real" IRQ numbers that we need are in fact an encoding of the bus/device/function address of the device. This patch fixes iSeries to use the virt->real IRQ mapping, allowing us to support larger iSeries machines. This patch also gets rid of the temporary hack that Stephen Rothwell submitted.

On machines with OpenPIC (including the G5) the mapping is explicitly 1-1, and that hasn't changed. For other machines this patch cleans up and simplifies the code that sets up the virtual->real mapping.

I have tested this code and verified that G5, pSeries and iSeries boot and run correctly with this patch.

Please apply.

Thanks,
Paul.

arch/ppc64/kernel/iSeries_irq.c +33 -31
diff -urN linux-2.5/arch/ppc64/kernel/iSeries_irq.c test/arch/ppc64/kernel/iSeries_irq.c
@@ -55,19 +55,18 @@
 	.end = iSeries_end_IRQ
 };
 
-void iSeries_init_irq_desc(irq_desc_t *desc)
-{
-	desc->handler = &iSeries_IRQ_handler;
-}
+/* This maps virtual irq numbers to real irqs */
+unsigned int virt_irq_to_real_map[NR_IRQS];
+
+/* The next available virtual irq number */
+/* Note: the pcnet32 driver assumes irq numbers < 2 aren't valid. :( */
+static int next_virtual_irq = 2;
 
 /* This is called by init_IRQ.  set in ppc_md.init_IRQ by iSeries_setup.c */
 void __init iSeries_init_IRQ(void)
 {
 	/* Register PCI event handler and open an event path */
-	PPCDBG(PPCDBG_BUSWALK,
-			"Register PCI event handler and open an event path\n");
 	XmPciLpEvent_init();
-	return;
 }
 
 /*
@@ -78,25 +77,32 @@
 int __init iSeries_allocate_IRQ(HvBusNumber busNumber,
 		HvSubBusNumber subBusNumber, HvAgentId deviceId)
 {
+	unsigned int realirq, virtirq;
 	u8 idsel = (deviceId >> 4);
 	u8 function = deviceId & 7;
 
-	return ((busNumber - 1) << 6) + ((idsel - 1) << 3) + function + 1;
+	virtirq = next_virtual_irq++;
+	realirq = ((busNumber - 1) << 6) + ((idsel - 1) << 3) + function;
+	virt_irq_to_real_map[virtirq] = realirq;
+
+	irq_desc[virtirq].handler = &iSeries_IRQ_handler;
+	return virtirq;
 }
 
-#define IRQ_TO_BUS(irq)		(((((irq) - 1) >> 6) & 0xff) + 1)
-#define IRQ_TO_IDSEL(irq)	(((((irq) - 1) >> 3) & 7) + 1)
-#define IRQ_TO_FUNC(irq)	(((irq) - 1) & 7)
+#define REAL_IRQ_TO_BUS(irq)	((((irq) >> 6) & 0xff) + 1)
+#define REAL_IRQ_TO_IDSEL(irq)	((((irq) >> 3) & 7) + 1)
+#define REAL_IRQ_TO_FUNC(irq)	((irq) & 7)
 
 /* This is called by iSeries_activate_IRQs */
 static unsigned int iSeries_startup_IRQ(unsigned int irq)
 {
 	u32 bus, deviceId, function, mask;
 	const u32 subBus = 0;
+	unsigned int rirq = virt_irq_to_real_map[irq];
 
-	bus = IRQ_TO_BUS(irq);
-	function = IRQ_TO_FUNC(irq);
-	deviceId = (IRQ_TO_IDSEL(irq) << 4) + function;
+	bus = REAL_IRQ_TO_BUS(rirq);
+	function = REAL_IRQ_TO_FUNC(rirq);
+	deviceId = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function;
 
 	/* Link the IRQ number to the bridge */
 	HvCallXm_connectBusUnit(bus, subBus, deviceId, irq);
@@ -104,17 +110,10 @@
 	/* Unmask bridge interrupts in the FISR */
 	mask = 0x01010000 << function;
 	HvCallPci_unmaskFisr(bus, subBus, deviceId, mask);
-	PPCDBG(PPCDBG_BUSWALK, "iSeries_activate_IRQ 0x%02X.%02X.%02X  Irq:0x%02X\n",
-				bus, subBus, deviceId, irq);
 	return 0;
 }
 
 /*
- * Temporary hack
- */
-#define get_irq_desc(irq)	&irq_desc[(irq)]
-
-/*
  * This is called out of iSeries_fixup to activate interrupt
  * generation for usable slots
  */
@@ -124,7 +123,7 @@
 	unsigned long flags;
 
 	for (irq = 0; irq < NR_IRQS; irq++) {
-		irq_desc_t *desc = get_irq_desc(irq);
+		irq_desc_t *desc = &irq_desc[irq];
 
 		if (desc && desc->handler && desc->handler->startup) {
 			spin_lock_irqsave(&desc->lock, flags);
@@ -139,11 +138,12 @@
 {
 	u32 bus, deviceId, function, mask;
 	const u32 subBus = 0;
+	unsigned int rirq = virt_irq_to_real_map[irq];
 
 	/* irq should be locked by the caller */
-	bus = IRQ_TO_BUS(irq);
-	function = IRQ_TO_FUNC(irq);
-	deviceId = (IRQ_TO_IDSEL(irq) << 4) + function;
+	bus = REAL_IRQ_TO_BUS(rirq);
+	function = REAL_IRQ_TO_FUNC(rirq);
+	deviceId = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function;
 
 	/* Invalidate the IRQ number in the bridge */
 	HvCallXm_connectBusUnit(bus, subBus, deviceId, 0);
@@ -161,11 +161,12 @@
 {
 	u32 bus, deviceId, function, mask;
 	const u32 subBus = 0;
+	unsigned int rirq = virt_irq_to_real_map[irq];
 
 	/* The IRQ has already been locked by the caller */
-	bus = IRQ_TO_BUS(irq);
-	function = IRQ_TO_FUNC(irq);
-	deviceId = (IRQ_TO_IDSEL(irq) << 4) + function;
+	bus = REAL_IRQ_TO_BUS(rirq);
+	function = REAL_IRQ_TO_FUNC(rirq);
+	deviceId = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function;
 
 	/* Mask secondary INTA   */
 	mask = 0x80000000;
@@ -182,11 +183,12 @@
 {
 	u32 bus, deviceId, function, mask;
 	const u32 subBus = 0;
+	unsigned int rirq = virt_irq_to_real_map[irq];
 
 	/* The IRQ has already been locked by the caller */
-	bus = IRQ_TO_BUS(irq);
-	function = IRQ_TO_FUNC(irq);
-	deviceId = (IRQ_TO_IDSEL(irq) << 4) + function;
+	bus = REAL_IRQ_TO_BUS(rirq);
+	function = REAL_IRQ_TO_FUNC(rirq);
+	deviceId = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function;
 
 	/* Unmask secondary INTA */
 	mask = 0x80000000;
arch/ppc64/kernel/iSeries_pci.c +3 -4
diff -urN linux-2.5/arch/ppc64/kernel/iSeries_pci.c test/arch/ppc64/kernel/iSeries_pci.c
@@ -277,6 +277,7 @@
 		} else
 			printk("PCI: Device Tree not found for 0x%016lX\n",
 					(unsigned long)pdev);
+		pdev->irq = node->Irq;
 	}
 	iSeries_IoMmTable_Status();
 	iSeries_activate_IRQs();
@@ -423,8 +424,6 @@
 					      Bus, SubBus, AgentId, HvRc);
 				continue;
 			}
-			printk("connected bus unit at bus %d subbus 0x%x agentid 0x%x (idsel=%d func=%d)\n",
-			       Bus, SubBus, AgentId, IdSel, Function);
 
 			HvRc = HvCallPci_configLoad16(Bus, SubBus, AgentId,
 						      PCI_VENDOR_ID, &VendorId);
@@ -437,8 +436,8 @@
 
 			/* FoundDevice: 0x18.28.10 = 0x12AE */
 			PPCDBG(PPCDBG_BUSWALK,
-			       "PCI:- FoundDevice: 0x%02X.%02X.%02X = 0x%04X\n",
-			       Bus, SubBus, AgentId, VendorId);
+			       "PCI:- FoundDevice: 0x%02X.%02X.%02X = 0x%04X, irq %d\n",
+			       Bus, SubBus, AgentId, VendorId, Irq);
 			HvRc = HvCallPci_configStore8(Bus, SubBus, AgentId,
 						      PCI_INTERRUPT_LINE, Irq);  
 			if (HvRc != 0)
arch/ppc64/kernel/irq.c +78 -0

87 lines not on this page · raw message

arch/ppc64/kernel/prom.c +15 -48

99 lines not on this page · raw message

arch/ppc64/kernel/ras.c +15 -2
diff -urN linux-2.5/arch/ppc64/kernel/ras.c test/arch/ppc64/kernel/ras.c
@@ -69,12 +69,19 @@
 {
 	struct device_node *np;
 	unsigned int *ireg, len, i;
+	int virq;
 
 	if ((np = of_find_node_by_path("/event-sources/internal-errors")) &&
 	    (ireg = (unsigned int *)get_property(np, "open-pic-interrupt",
 						 &len))) {
 		for (i=0; i<(len / sizeof(*ireg)); i++) {
-			request_irq(virt_irq_create_mapping(*(ireg)) + NUM_8259_INTERRUPTS, 
+			virq = virt_irq_create_mapping(*(ireg));
+			if (virq == NO_IRQ) {
+				printk(KERN_ERR "Unable to allocate interrupt "
+				       "number for %s\n", np->full_name);
+				break;
+			}
+			request_irq(virq + NUM_8259_INTERRUPTS, 
 				    ras_error_interrupt, 0, 
 				    "RAS_ERROR", NULL);
 			ireg++;
@@ -86,7 +93,13 @@
 	    (ireg = (unsigned int *)get_property(np, "open-pic-interrupt",
 						 &len))) {
 		for (i=0; i<(len / sizeof(*ireg)); i++) {
-			request_irq(virt_irq_create_mapping(*(ireg)) + NUM_8259_INTERRUPTS, 
+			virq = virt_irq_create_mapping(*(ireg));
+			if (virq == NO_IRQ) {
+				printk(KERN_ERR "Unable to allocate interrupt "
+				       " number for %s\n", np->full_name);
+				break;
+			}
+			request_irq(virq + NUM_8259_INTERRUPTS, 
 				    ras_epow_interrupt, 0, 
 				    "RAS_EPOW", NULL);
 			ireg++;
arch/ppc64/kernel/vio.c +7 -2
diff -urN linux-2.5/arch/ppc64/kernel/vio.c test/arch/ppc64/kernel/vio.c
@@ -242,10 +242,15 @@
 	viodev->unit_address = *unit_address;
 	viodev->tce_table = vio_build_tce_table(viodev);
 
-	viodev->irq = (unsigned int) -1;
+	viodev->irq = NO_IRQ;
 	irq_p = (unsigned int *)get_property(of_node, "interrupts", 0);
 	if (irq_p) {
-		viodev->irq = openpic_to_irq(virt_irq_create_mapping(*irq_p));
+		int virq = virt_irq_create_mapping(*irq_p);
+		if (virq == NO_IRQ) {
+			printk(KERN_ERR "Unable to allocate interrupt "
+			       "number for %s\n", of_node->full_name);
+		} else
+			viodev->irq = openpic_to_irq(virq);
 	}
 
 	/* init generic 'struct device' fields: */
arch/ppc64/kernel/xics.c +81 -47

236 lines not on this page · raw message

include/asm-ppc64/irq.h +9 -9
diff -urN linux-2.5/include/asm-ppc64/irq.h test/include/asm-ppc64/irq.h
@@ -15,6 +15,9 @@
 extern void disable_irq_nosync(unsigned int);
 extern void enable_irq(unsigned int);
 
+/* this number is used when no interrupt has been assigned */
+#define NO_IRQ			(-1)
+
 /*
  * this is the maximum number of virtual irqs we will use.
  */
@@ -25,19 +28,16 @@
 /* Interrupt numbers are virtual in case they are sparsely
  * distributed by the hardware.
  */
-#define NR_HW_IRQS		8192
-extern unsigned short real_irq_to_virt_map[NR_HW_IRQS];
-extern unsigned short virt_irq_to_real_map[NR_IRQS];
+extern unsigned int virt_irq_to_real_map[NR_IRQS];
+
 /* Create a mapping for a real_irq if it doesn't already exist.
  * Return the virtual irq as a convenience.
  */
-unsigned long virt_irq_create_mapping(unsigned long real_irq);
+int virt_irq_create_mapping(unsigned int real_irq);
+void virt_irq_init(void);
 
-/* These funcs map irqs between real and virtual */
-static inline unsigned long real_irq_to_virt(unsigned long real_irq) {
-	return real_irq_to_virt_map[real_irq];
-}
-static inline unsigned long virt_irq_to_real(unsigned long virt_irq) {
+static inline unsigned int virt_irq_to_real(unsigned int virt_irq)
+{
 	return virt_irq_to_real_map[virt_irq];
 }