See patch.

Uwe.
-- 
http://hermann-uwe.de     | http://sigrok.org
http://randomprojects.org | http://unmaintained-free-software.org
Small refactoring in ioapic.c to simplify the code.

 - Factor out ioapic_set_ioredtbl(), which sets one entry.

 - Factor out ioapic_num_interrupts() which returns the number of
   interrupts supported by this IOAPIC.

 - Remove some no longer needed local variables.

Signed-off-by: Uwe Hermann <[email protected]>

Index: src/arch/i386/lib/ioapic.c
===================================================================
--- src/arch/i386/lib/ioapic.c	(Revision 5954)
+++ src/arch/i386/lib/ioapic.c	(Arbeitskopie)
@@ -34,30 +34,37 @@
 	write32(ioapic_base + 0x10, value);
 }
 
-void clear_ioapic(u32 ioapic_base)
+static void ioapic_set_ioredtbl(u32 ioapic_base, int i, u32 low, u32 high)
 {
-	u32 low, high;
-	u32 i, ioapic_interrupts;
+	io_apic_write(ioapic_base, i * 2 + 0x10, low);
+	io_apic_write(ioapic_base, i * 2 + 0x11, high);
 
-	printk(BIOS_DEBUG, "IOAPIC: Clearing IOAPIC at 0x%08x\n", ioapic_base);
+	printk(BIOS_SPEW, "IOAPIC: reg 0x%08x value 0x%08x 0x%08x\n",
+	       i, high, low);
+}
 
-	/* Read the available number of interrupts. */
+/* Read the available number of interrupts. */
+static u32 ioapic_num_interrupts(u32 ioapic_base)
+{
+	u32 ioapic_interrupts;
+
 	ioapic_interrupts = (io_apic_read(ioapic_base, 0x01) >> 16) & 0xff;
 	if (!ioapic_interrupts || ioapic_interrupts == 0xff)
 		ioapic_interrupts = 24;
 	printk(BIOS_DEBUG, "IOAPIC: %d interrupts\n", ioapic_interrupts);
 
-	low = DISABLED;
-	high = NONE;
+	return ioapic_interrupts;
+}
 
-	for (i = 0; i < ioapic_interrupts; i++) {
-		io_apic_write(ioapic_base, i * 2 + 0x10, low);
-		io_apic_write(ioapic_base, i * 2 + 0x11, high);
+void clear_ioapic(u32 ioapic_base)
+{
+	u32 i;
 
-		printk(BIOS_SPEW, "IOAPIC: reg 0x%08x value 0x%08x 0x%08x\n",
-		       i, high, low);
-	}
+	printk(BIOS_DEBUG, "IOAPIC: Clearing IOAPIC at 0x%08x\n", ioapic_base);
 
+	for (i = 0; i < ioapic_num_interrupts(ioapic_base); i++)
+		ioapic_set_ioredtbl(ioapic_base, i, DISABLED, NONE);
+
 	if (io_apic_read(ioapic_base, 0x10) == 0xffffffff) {
 		printk(BIOS_WARNING, "IOAPIC not responding.\n");
 		return;
@@ -67,8 +74,7 @@
 void setup_ioapic(u32 ioapic_base, u8 ioapic_id)
 {
 	u32 bsp_lapicid = lapicid();
-	u32 low, high;
-	u32 i, ioapic_interrupts;
+	u32 low, high, i;
 
 	printk(BIOS_DEBUG, "IOAPIC: Initializing IOAPIC at 0x%08x\n",
 	       ioapic_base);
@@ -83,12 +89,6 @@
 			(ioapic_id << 24));
 	}
 
-	/* Read the available number of interrupts. */
-	ioapic_interrupts = (io_apic_read(ioapic_base, 0x01) >> 16) & 0xff;
-	if (!ioapic_interrupts || ioapic_interrupts == 0xff)
-		ioapic_interrupts = 24;
-	printk(BIOS_DEBUG, "IOAPIC: %d interrupts\n", ioapic_interrupts);
-
 // XXX this decision should probably be made elsewhere, and
 // it's the C3, not the EPIA this depends on.
 #if defined(CONFIG_EPIA_VT8237R_INIT) && CONFIG_EPIA_VT8237R_INIT
@@ -114,26 +114,13 @@
 	/* Enable Virtual Wire Mode. */
 	low = ENABLED | TRIGGER_EDGE | POLARITY_HIGH | PHYSICAL_DEST | ExtINT;
 	high = bsp_lapicid << (56 - 32);
+	ioapic_set_ioredtbl(ioapic_base, 0, low, high);
 
-	io_apic_write(ioapic_base, 0x10, low);
-	io_apic_write(ioapic_base, 0x11, high);
-
 	if (io_apic_read(ioapic_base, 0x10) == 0xffffffff) {
 		printk(BIOS_WARNING, "IOAPIC not responding.\n");
 		return;
 	}
 
-	printk(BIOS_SPEW, "IOAPIC: reg 0x%08x value 0x%08x 0x%08x\n",
-	       0, high, low);
-
-	low = DISABLED;
-	high = NONE;
-
-	for (i = 1; i < ioapic_interrupts; i++) {
-		io_apic_write(ioapic_base, i * 2 + 0x10, low);
-		io_apic_write(ioapic_base, i * 2 + 0x11, high);
-
-		printk(BIOS_SPEW, "IOAPIC: reg 0x%08x value 0x%08x 0x%08x\n",
-		       i, high, low);
-	}
+	for (i = 1; i < ioapic_num_interrupts(ioapic_base); i++)
+		ioapic_set_ioredtbl(ioapic_base, i, DISABLED, NONE);
 }
-- 
coreboot mailing list: [email protected]
http://www.coreboot.org/mailman/listinfo/coreboot

Reply via email to