Skip to contentSkip to conversation

RFC: i8259.c cleanup

PATCH [email protected] 5 participants 10 messages Nov 6, 2001 – Nov 7, 2001

lore
Share & tools
lore
#0 lore raw

i8259.c hasn't worked right for a long time on IBM PReP's, which crippled those that use IDE ("hda: lost interrupt" forever). I sent a note about this a while back
(http://lists.linuxppc.org/linuxppc-workstation/200109/msg00030.html) but never got any answers...

Anyways, by reading from 0xbffffff0 we can get the active irq without having to play with the 8259 directly (which we were doing wrong; see above URL). This is true on the IBM PReP's because the 8259's are implemented in the Fire Coral SIO bridge (which is on the PCI bus), so it can respond to the PHB's interrupt request. (Unless I'm mistaken it's the PHB, in this case MPC105, which decodes 0xbffffff0 and asks the system interrupt controller to supply the active irq number.)

The following patch (to linuxppc_2_4_devel) does exactly that - it reads from 0xbffffff0 instead of the 8259 directly. This seems to have completely fixed the lost irq problems that we (IBM PReP users) have been having for a long time. This patch has only been tested on a 6050 so far, but that should cover all the Carolina's.

I'm not positive this trick will work on every board that has an 8259. The PReP spec calls for it, and anything with an MPC105/106 should support it. I'm really hoping that covers everyone...

Also, with this trick our i8259.c could be made almost identical to i386/mips/alpha, which already know the irq vector entering mask_and_ack(). A lot of our boards call i8259_irq() directly though, which would have to be changed. I only suggest it because the i386 folks apparently know 8259's better than we do... :) Oh, and alpha uses the rotating priority feature which sounds cool. :)

The patch also cleans up some whitespace (parts of i8259.c were apparently copied and pasted from one xterm to another), adds a few comments, and adds resource_request's for both 8259's.

i8259_irq() (called from a variety of embedded files) is passed a single argument, int cpu. This argument is never used and should probably be deleted?

I have one other question, regarding spin_lock vs spin_lock_irqsave. We use both in different places in i8259.c ("_irqsave" is commented out in some places). i386 and mips use irqsave in their i8259.c's, alpha does not. Which is appropriate here?

-Hollis

===== arch/ppc/kernel/i8259.c 1.10 vs edited =====

arch/ppc/kernel/i8259.c +81 -76
@@ -4,11 +4,14 @@
 
 #include <linux/stddef.h>
 #include <linux/init.h>
+#include <linux/ioport.h>
 #include <linux/sched.h>
 #include <linux/signal.h>
 #include <asm/io.h>
 #include <asm/i8259.h>
 
+static volatile char *pci_intack; /* RO, gives us the irq vector */
+
 unsigned char cached_8259[2] = { 0xff, 0xff };
 #define cached_A1 (cached_8259[0])
 #define cached_21 (cached_8259[1])
@@ -22,30 +25,19 @@
 	int irq;
 
 	spin_lock/*_irqsave*/(&i8259_lock/*, flags*/);
-        /*
-         * Perform an interrupt acknowledge cycle on controller 1
-         */
-        outb(0x0C, 0x20);
-        irq = inb(0x20) & 7;
-        if (irq == 2)
-        {
-                /*
-                 * Interrupt is cascaded so perform interrupt
-                 * acknowledge on controller 2
-                 */
-                outb(0x0C, 0xA0);
-                irq = (inb(0xA0) & 7) + 8;
-        }
-        else if (irq==7)
-        {
-                /*
-                 * This may be a spurious interrupt
-                 *
-                 * Read the interrupt status register. If the most
-                 * significant bit is not set then there is no valid
+	/*
+	 * Perform an interrupt acknowledge cycle on controller 1
+	 */
+	irq = *pci_intack & 0xff;
+	if (irq == 7) {
+		/*
+		 * This may be a spurious interrupt
+		 *
+		 * Read the interrupt status register. If the most
+		 * significant bit is not set then there is no valid
 		 * interrupt
 		 */
-		outb(0x0b, 0x20);
+		outb(0x0b, 0x20); /* select ISR */
 		if(~inb(0x20)&0x80) {
 			spin_unlock/*_irqrestore*/(&i8259_lock/*, flags*/);
 			return -1;
@@ -60,28 +52,28 @@
 	unsigned long flags;
 
 	spin_lock_irqsave(&i8259_lock, flags);
-        if ( irq_nr >= i8259_pic_irq_offset )
-                irq_nr -= i8259_pic_irq_offset;
+	if ( irq_nr >= i8259_pic_irq_offset )
+		irq_nr -= i8259_pic_irq_offset;
 
-        if (irq_nr > 7) {
-                cached_A1 |= 1 << (irq_nr-8);
-                inb(0xA1);      /* DUMMY */
-                outb(cached_A1,0xA1);
-                outb(0x20,0xA0);        /* Non-specific EOI */
-                outb(0x20,0x20);        /* Non-specific EOI to cascade */
-        } else {
-                cached_21 |= 1 << irq_nr;
-                inb(0x21);      /* DUMMY */
-                outb(cached_21,0x21);
-                outb(0x20,0x20);        /* Non-specific EOI */
-        }
+	if (irq_nr > 7) {
+		cached_A1 |= 1 << (irq_nr-8);
+		inb(0xA1); /* DUMMY */
+		outb(cached_A1,0xA1);
+		outb(0x20,0xA0); /* Non-specific EOI */
+		outb(0x20,0x20); /* Non-specific EOI to cascade */
+	} else {
+		cached_21 |= 1 << irq_nr;
+		inb(0x21); /* DUMMY */
+		outb(cached_21,0x21);
+		outb(0x20,0x20); /* Non-specific EOI */
+	}
 	spin_unlock_irqrestore(&i8259_lock, flags);
 }
 
 static void i8259_set_irq_mask(int irq_nr)
 {
-        outb(cached_A1,0xA1);
-        outb(cached_21,0x21);
+	outb(cached_A1,0xA1);
+	outb(cached_21,0x21);
 }
 
 static void i8259_mask_irq(unsigned int irq_nr)
@@ -89,13 +81,13 @@
 	unsigned long flags;
 
 	spin_lock_irqsave(&i8259_lock, flags);
-        if ( irq_nr >= i8259_pic_irq_offset )
-                irq_nr -= i8259_pic_irq_offset;
-        if ( irq_nr < 8 )
-                cached_21 |= 1 << irq_nr;
-        else
-                cached_A1 |= 1 << (irq_nr-8);
-        i8259_set_irq_mask(irq_nr);
+	if ( irq_nr >= i8259_pic_irq_offset )
+		irq_nr -= i8259_pic_irq_offset;
+	if ( irq_nr < 8 )
+		cached_21 |= 1 << irq_nr;
+	else
+		cached_A1 |= 1 << (irq_nr-8);
+	i8259_set_irq_mask(irq_nr);
 	spin_unlock_irqrestore(&i8259_lock, flags);
 }
 
@@ -104,13 +96,13 @@
 	unsigned long flags;
 
 	spin_lock_irqsave(&i8259_lock, flags);
-        if ( irq_nr >= i8259_pic_irq_offset )
-                irq_nr -= i8259_pic_irq_offset;
-        if ( irq_nr < 8 )
-                cached_21 &= ~(1 << irq_nr);
-        else
-                cached_A1 &= ~(1 << (irq_nr-8));
-        i8259_set_irq_mask(irq_nr);
+	if ( irq_nr >= i8259_pic_irq_offset )
+		irq_nr -= i8259_pic_irq_offset;
+	if ( irq_nr < 8 )
+		cached_21 &= ~(1 << irq_nr);
+	else
+		cached_A1 &= ~(1 << (irq_nr-8));
+	i8259_set_irq_mask(irq_nr);
 	spin_unlock_irqrestore(&i8259_lock, flags);
 }
 
@@ -121,14 +113,22 @@
 }
 
 struct hw_interrupt_type i8259_pic = {
-        " i8259    ",
-        NULL,
-        NULL,
-        i8259_unmask_irq,
-        i8259_mask_irq,
-        i8259_mask_and_ack_irq,
-        i8259_end_irq,
-        NULL
+	" i8259    ",
+	NULL,
+	NULL,
+	i8259_unmask_irq,
+	i8259_mask_irq,
+	i8259_mask_and_ack_irq,
+	i8259_end_irq,
+	NULL
+};
+
+static struct resource pic1_io_resource = {
+	"pic1", 0x20, 0x3f, IORESOURCE_BUSY
+};
+
+static struct resource pic2_io_resource = {
+	"pic2", 0xa0, 0xbf, IORESOURCE_BUSY
 };
 
 void __init i8259_init(void)
@@ -136,21 +136,26 @@
 	unsigned long flags;
 
 	spin_lock_irqsave(&i8259_lock, flags);
-        /* init master interrupt controller */
-        outb(0x11, 0x20); /* Start init sequence */
-        outb(0x00, 0x21); /* Vector base */
-        outb(0x04, 0x21); /* edge tiggered, Cascade (slave) on IRQ2 */
-        outb(0x01, 0x21); /* Select 8086 mode */
-        outb(0xFF, 0x21); /* Mask all */
-        /* init slave interrupt controller */
-        outb(0x11, 0xA0); /* Start init sequence */
-        outb(0x08, 0xA1); /* Vector base */
-        outb(0x02, 0xA1); /* edge triggered, Cascade (slave) on IRQ2 */
-        outb(0x01, 0xA1); /* Select 8086 mode */
-        outb(0xFF, 0xA1); /* Mask all */
-        outb(cached_A1, 0xA1);
-        outb(cached_21, 0x21);
+	/* init master interrupt controller */
+	outb(0x11, 0x20); /* Start init sequence */
+	outb(0x00, 0x21); /* Vector base */
+	outb(0x04, 0x21); /* edge tiggered, Cascade (slave) on IRQ2 */
+	outb(0x01, 0x21); /* Select 8086 mode */
+	outb(0xFF, 0x21); /* Mask all */
+	/* init slave interrupt controller */
+	outb(0x11, 0xA0); /* Start init sequence */
+	outb(0x08, 0xA1); /* Vector base */
+	outb(0x02, 0xA1); /* edge triggered, Cascade (slave) on IRQ2 */
+	outb(0x01, 0xA1); /* Select 8086 mode */
+	outb(0xFF, 0xA1); /* Mask all */
+	outb(cached_A1, 0xA1);
+	outb(cached_21, 0x21);
 	spin_unlock_irqrestore(&i8259_lock, flags);
-        request_irq( i8259_pic_irq_offset + 2, no_action, SA_INTERRUPT,
-                     "82c59 secondary cascade", NULL );
+
+	request_irq( i8259_pic_irq_offset + 2, no_action, SA_INTERRUPT,
+				"82c59 secondary cascade", NULL );
+	request_resource(&ioport_resource, &pic1_io_resource);
+	request_resource(&ioport_resource, &pic2_io_resource);
+
+	pci_intack = ioremap(0xbffffff0, 1);
 }
#1 lore raw
Quoted 2 lines · [email protected] wrote:

The following patch (to linuxppc_2_4_devel) does exactly that - it reads from 0xbffffff0 instead of the 8259 directly.

Ummmmm.....this probably works OK on PReP, but I don't think it is going to have the desired effect on other systems using an 8259 :-). You need to find a way to to make the code you changed unique to PReP.

Thanks.

	-- Dan

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

#2 lore raw
Quoted 7 lines · Dan Malek
Quoted 2 lines · [email protected] wrote:

The following patch (to linuxppc_2_4_devel) does exactly that - it reads from 0xbffffff0 instead of the 8259 directly.

Ummmmm.....this probably works OK on PReP, but I don't think it is going to have the desired effect on other systems using an 8259 :-). You need to find a way to to make the code you changed unique to PReP.

Note that CHRP already has such a thing (chrp_int_ack_special), to be used with OpenPIC (it's passed to openpic_init()).

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

#4 lore raw
In reply to [email protected]
Quoted 6 lines · On Tue, 6 Nov 2001 [email protected] wrote:

i8259.c hasn't worked right for a long time on IBM PReP's, which crippled those that use IDE ("hda: lost interrupt" forever). I sent a note about this a while back
(http://lists.linuxppc.org/linuxppc-workstation/200109/msg00030.html) but never got any answers...

Quoted 7 lines

Anyways, by reading from 0xbffffff0 we can get the active irq without having to play with the 8259 directly (which we were doing wrong; see above URL). This is true on the IBM PReP's because the 8259's are implemented in the Fire Coral SIO bridge (which is on the PCI bus), so it can respond to the PHB's interrupt request. (Unless I'm mistaken it's the PHB, in this case MPC105, which decodes 0xbffffff0 and asks the system interrupt controller to supply the active irq number.)

The address is not always 0xbffffff0, it is bridge dependent. However this address is normally found in OF device tree, in residual data and as a last resort could be made host bridge dependent. It has to be ioremapped anyway...

For example on OpenPIC with cascaded 8259 like Motorola MVME/MTX, the address is 0xfeff0030 (doesn't even need a PTE if you put a large enough BAT with CHRP mappings since it's just above PCI I/O space).

Quoted 6 lines

The following patch (to linuxppc_2_4_devel) does exactly that - it reads from 0xbffffff0 instead of the 8259 directly. This seems to have completely fixed the lost irq problems that we (IBM PReP users) have been having for a long time. This patch has only been tested on a 6050 so far, but that should cover all the Carolina's.

The question is why the polling code did not work, subtle timing problems or is the code plain wrong ? I suspect that some 8259 accesses were not serialized well enough.

Quoted 4 lines

I'm not positive this trick will work on every board that has an 8259. The PReP spec calls for it, and anything with an MPC105/106 should support it. I'm really hoping that covers everyone...

No, it won't work for everybody.

Quoted 11 lines

Also, with this trick our i8259.c could be made almost identical to i386/mips/alpha, which already know the irq vector entering mask_and_ack(). A lot of our boards call i8259_irq() directly though, which would have to be changed. I only suggest it because the i386 folks apparently know 8259's better than we do... :) Oh, and alpha uses the rotating priority feature which sounds cool. :)

The patch also cleans up some whitespace (parts of i8259.c were apparently copied and pasted from one xterm to another), adds a few comments, and adds resource_request's for both 8259's.

Good, but you should add resource request for the edge/level control register while you are at it (0x4d0/4d1). And you should not require 32 bytes for the 8259. On my boards, the super I/O control port is 0x2e-ox2f.

BTW, if you have an MTX or MVME board just try to do inl(0x20): instant lockup, no machine check, nothing. It might lock up other boards too. Bad hardware design, I find it scary for some of my applications.

Quoted 4 lines

I have one other question, regarding spin_lock vs spin_lock_irqsave. We use both in different places in i8259.c ("_irqsave" is commented out in some places). i386 and mips use irqsave in their i8259.c's, alpha does not. Which is appropriate here?

You should not need irqsave variants, once the interrupt is acked and masked you can reenable interrupts explicitly with __sti if the interrupt flags allow this (doing like i386 is probably the best). But you have to check the interaction with the OpenPIC when cascaded. I actually wonder whether it would be better to split it in two cases:

- 8259 is the only interrupt controller in the system

- 8259 is cascaded interrupt controller on an openpic

Regards,
Gabriel.

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

#3 lore raw
In reply to Geert Uytterhoeven
Quoted 6 lines · Geert Uytterhoeven
Quoted 4 lines · Dan Malek
Quoted 2 lines · [email protected] wrote:

The following patch (to linuxppc_2_4_devel) does exactly that - it reads from 0xbffffff0 instead of the 8259 directly.

Quoted 6 lines
Quoted 3 lines

Ummmmm.....this probably works OK on PReP, but I don't think it is going to have the desired effect on other systems using an 8259 :-). You need to find a way to to make the code you changed unique to PReP.

Note that CHRP already has such a thing (chrp_int_ack_special), to be used with OpenPIC (it's passed to openpic_init()).

Indeed, what the 8259.c code might do is use the hardware address and fall back to polling if the address is NULL. But to avoid run time checking and minmize icache footprint, the two cases could be considered as different interrupt controllers.

Regards,
Gabriel.

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

#5 lore raw
In reply to Gabriel Paubert
Quoted 4 lines · Gabriel Paubert

The question is why the polling code did not work, subtle timing problems or is the code plain wrong ? I suspect that some 8259 accesses were not serialized well enough.

I laid out what I saw in
http://lists.linuxppc.org/linuxppc-workstation/200109/msg00030.html . I could be wrong, but our code doesn't seem to match the datasheet very well.

I think fixing what we have is the least intrusive, but I tried and failed, so it was nice to write code that actually worked. :) I guess the PCI intack stuff is too varied to be useful though...

Would you say poking the 8259 directly is more "right" than using 0xbffffff0 (or equivalent)?

Quoted 8 lines
Quoted 3 lines

The patch also cleans up some whitespace (parts of i8259.c were apparently copied and pasted from one xterm to another), adds a few comments, and adds resource_request's for both 8259's.

Good, but you should add resource request for the edge/level control register while you are at it (0x4d0/4d1). And you should not require 32 bytes for the 8259. On my boards, the super I/O control port is 0x2e-ox2f.

That's what I forgot... that code requests directly from ioport_resource, which is what gets us into trouble on vgacon. We should use request_region instead of request_resource. Unfortunately vgacon is initialized before the VMM, and since request_region calls kmalloc we die very early. :/ I didn't check to see if that's a problem here.

The problem with using request_resource(&ioport_resource) in vgacon is that our PHB's initialize later, try to reserve their own IO regions (eg 0x0->0xffffffff), and fail because vgacon already took 0x3c0 or so.

-Hollis

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

#6 lore raw
Quoted 9 lines · On Wed, 7 Nov 2001 [email protected] wrote:
Quoted 3 lines · Gabriel Paubert

The question is why the polling code did not work, subtle timing problems or is the code plain wrong ? I suspect that some 8259 accesses were not serialized well enough.

I laid out what I saw in
http://lists.linuxppc.org/linuxppc-workstation/200109/msg00030.html . I could be wrong, but our code doesn't seem to match the datasheet very well.

Quoted 6 lines

I think fixing what we have is the least intrusive, but I tried and failed, so it was nice to write code that actually worked. :) I guess the PCI intack stuff is too varied to be useful though...

Would you say poking the 8259 directly is more "right" than using 0xbffffff0 (or equivalent)?

I remember some interrupt-related problems went away on my LongTrail after I started using the interrupt acknowledge register on the host bridge instead of the plain i8259 stuff.

Quoted 9 lines
Quoted 8 lines
Quoted 3 lines

The patch also cleans up some whitespace (parts of i8259.c were apparently copied and pasted from one xterm to another), adds a few comments, and adds resource_request's for both 8259's.

Good, but you should add resource request for the edge/level control register while you are at it (0x4d0/4d1). And you should not require 32 bytes for the 8259. On my boards, the super I/O control port is 0x2e-ox2f.

Quoted 5 lines

That's what I forgot... that code requests directly from ioport_resource, which is what gets us into trouble on vgacon. We should use request_region instead of request_resource. Unfortunately vgacon is initialized before the VMM, and since request_region calls kmalloc we die very early. :/ I didn't check to see if that's a problem here.

Or we need a request_resource() that doesn't try to attach to the passed parent, but walks the list (starting from the passed parent) to hook in at the right spot. (*)

Quoted 3 lines

The problem with using request_resource(&ioport_resource) in vgacon is that our PHB's initialize later, try to reserve their own IO regions (eg 0x0->0xffffffff), and fail because vgacon already took 0x3c0 or so.

Yes, so either we have to delay the request_resource() and use the scheme above (*), or we need a request_resource_and_take_over() call to register the PHB resources, which reshuffles the already allocated legacy resources.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

#9 lore raw
In reply to [email protected]

While y'all are mucking around in there, you might have a chance to fix my pet peeve: if you have an OpenPIC, you don't necessarily have an i8259 also. Gemini doesn't have an i8259, but it either has to ifdef out the i8259 code or include the i8259.o object.

The whole i8259/OpenPIC interface could use some redesign, actually. But it works, hey...

-VAL

Quoted 256 lines · On Tue, Nov 06, 2001 at 05:15:59PM -0600, [email protected] wrote:

i8259.c hasn't worked right for a long time on IBM PReP's, which crippled those that use IDE ("hda: lost interrupt" forever). I sent a note about this a while back
(http://lists.linuxppc.org/linuxppc-workstation/200109/msg00030.html) but never got any answers...

Anyways, by reading from 0xbffffff0 we can get the active irq without having to play with the 8259 directly (which we were doing wrong; see above URL). This is true on the IBM PReP's because the 8259's are implemented in the Fire Coral SIO bridge (which is on the PCI bus), so it can respond to the PHB's interrupt request. (Unless I'm mistaken it's the PHB, in this case MPC105, which decodes 0xbffffff0 and asks the system interrupt controller to supply the active irq number.)

The following patch (to linuxppc_2_4_devel) does exactly that - it reads from 0xbffffff0 instead of the 8259 directly. This seems to have completely fixed the lost irq problems that we (IBM PReP users) have been having for a long time. This patch has only been tested on a 6050 so far, but that should cover all the Carolina's.

I'm not positive this trick will work on every board that has an 8259. The PReP spec calls for it, and anything with an MPC105/106 should support it. I'm really hoping that covers everyone...

Also, with this trick our i8259.c could be made almost identical to i386/mips/alpha, which already know the irq vector entering mask_and_ack(). A lot of our boards call i8259_irq() directly though, which would have to be changed. I only suggest it because the i386 folks apparently know 8259's better than we do... :) Oh, and alpha uses the rotating priority feature which sounds cool. :)

The patch also cleans up some whitespace (parts of i8259.c were apparently copied and pasted from one xterm to another), adds a few comments, and adds resource_request's for both 8259's.

i8259_irq() (called from a variety of embedded files) is passed a single argument, int cpu. This argument is never used and should probably be deleted?

I have one other question, regarding spin_lock vs spin_lock_irqsave. We use both in different places in i8259.c ("_irqsave" is commented out in some places). i386 and mips use irqsave in their i8259.c's, alpha does not. Which is appropriate here?

-Hollis

===== arch/ppc/kernel/i8259.c 1.10 vs edited =====

arch/ppc/kernel/i8259.c +74 -74
@@ -4,11 +4,14 @@
 
 #include <linux/stddef.h>
 #include <linux/init.h>
+#include <linux/ioport.h>
 #include <linux/sched.h>
 #include <linux/signal.h>
 #include <asm/io.h>
 #include <asm/i8259.h>
 
+static volatile char *pci_intack; /* RO, gives us the irq vector */
+
 unsigned char cached_8259[2] = { 0xff, 0xff };
 #define cached_A1 (cached_8259[0])
 #define cached_21 (cached_8259[1])
@@ -22,30 +25,19 @@
 	int irq;
 
 	spin_lock/*_irqsave*/(&i8259_lock/*, flags*/);
-        /*
-         * Perform an interrupt acknowledge cycle on controller 1
-         */
-        outb(0x0C, 0x20);
-        irq = inb(0x20) & 7;
-        if (irq == 2)
-        {
-                /*
-                 * Interrupt is cascaded so perform interrupt
-                 * acknowledge on controller 2
-                 */
-                outb(0x0C, 0xA0);
-                irq = (inb(0xA0) & 7) + 8;
-        }
-        else if (irq==7)
-        {
-                /*
-                 * This may be a spurious interrupt
-                 *
-                 * Read the interrupt status register. If the most
-                 * significant bit is not set then there is no valid
+	/*
+	 * Perform an interrupt acknowledge cycle on controller 1
+	 */
+	irq = *pci_intack & 0xff;
+	if (irq == 7) {
+		/*
+		 * This may be a spurious interrupt
+		 *
+		 * Read the interrupt status register. If the most
+		 * significant bit is not set then there is no valid
 		 * interrupt
 		 */
-		outb(0x0b, 0x20);
+		outb(0x0b, 0x20); /* select ISR */
 		if(~inb(0x20)&0x80) {
 			spin_unlock/*_irqrestore*/(&i8259_lock/*, flags*/);
 			return -1;
@@ -60,28 +52,28 @@
 	unsigned long flags;
 
 	spin_lock_irqsave(&i8259_lock, flags);
-        if ( irq_nr >= i8259_pic_irq_offset )
-                irq_nr -= i8259_pic_irq_offset;
+	if ( irq_nr >= i8259_pic_irq_offset )
+		irq_nr -= i8259_pic_irq_offset;
 
-        if (irq_nr > 7) {
-                cached_A1 |= 1 << (irq_nr-8);
-                inb(0xA1);      /* DUMMY */
-                outb(cached_A1,0xA1);
-                outb(0x20,0xA0);        /* Non-specific EOI */
-                outb(0x20,0x20);        /* Non-specific EOI to cascade */
-        } else {
-                cached_21 |= 1 << irq_nr;
-                inb(0x21);      /* DUMMY */
-                outb(cached_21,0x21);
-                outb(0x20,0x20);        /* Non-specific EOI */
-        }
+	if (irq_nr > 7) {
+		cached_A1 |= 1 << (irq_nr-8);
+		inb(0xA1); /* DUMMY */
+		outb(cached_A1,0xA1);
+		outb(0x20,0xA0); /* Non-specific EOI */
+		outb(0x20,0x20); /* Non-specific EOI to cascade */
+	} else {
+		cached_21 |= 1 << irq_nr;
+		inb(0x21); /* DUMMY */
+		outb(cached_21,0x21);
+		outb(0x20,0x20); /* Non-specific EOI */
+	}
 	spin_unlock_irqrestore(&i8259_lock, flags);
 }
 
 static void i8259_set_irq_mask(int irq_nr)
 {
-        outb(cached_A1,0xA1);
-        outb(cached_21,0x21);
+	outb(cached_A1,0xA1);
+	outb(cached_21,0x21);
 }
 
 static void i8259_mask_irq(unsigned int irq_nr)
@@ -89,13 +81,13 @@
 	unsigned long flags;
 
 	spin_lock_irqsave(&i8259_lock, flags);
-        if ( irq_nr >= i8259_pic_irq_offset )
-                irq_nr -= i8259_pic_irq_offset;
-        if ( irq_nr < 8 )
-                cached_21 |= 1 << irq_nr;
-        else
-                cached_A1 |= 1 << (irq_nr-8);
-        i8259_set_irq_mask(irq_nr);
+	if ( irq_nr >= i8259_pic_irq_offset )
+		irq_nr -= i8259_pic_irq_offset;
+	if ( irq_nr < 8 )
+		cached_21 |= 1 << irq_nr;
+	else
+		cached_A1 |= 1 << (irq_nr-8);
+	i8259_set_irq_mask(irq_nr);
 	spin_unlock_irqrestore(&i8259_lock, flags);
 }
 
@@ -104,13 +96,13 @@
 	unsigned long flags;
 
 	spin_lock_irqsave(&i8259_lock, flags);
-        if ( irq_nr >= i8259_pic_irq_offset )
-                irq_nr -= i8259_pic_irq_offset;
-        if ( irq_nr < 8 )
-                cached_21 &= ~(1 << irq_nr);
-        else
-                cached_A1 &= ~(1 << (irq_nr-8));
-        i8259_set_irq_mask(irq_nr);
+	if ( irq_nr >= i8259_pic_irq_offset )
+		irq_nr -= i8259_pic_irq_offset;
+	if ( irq_nr < 8 )
+		cached_21 &= ~(1 << irq_nr);
+	else
+		cached_A1 &= ~(1 << (irq_nr-8));
+	i8259_set_irq_mask(irq_nr);
 	spin_unlock_irqrestore(&i8259_lock, flags);
 }
 
@@ -121,14 +113,22 @@
 }
 
 struct hw_interrupt_type i8259_pic = {
-        " i8259    ",
-        NULL,
-        NULL,
-        i8259_unmask_irq,
-        i8259_mask_irq,
-        i8259_mask_and_ack_irq,
-        i8259_end_irq,
-        NULL
+	" i8259    ",
+	NULL,
+	NULL,
+	i8259_unmask_irq,
+	i8259_mask_irq,
+	i8259_mask_and_ack_irq,
+	i8259_end_irq,
+	NULL
+};
+
+static struct resource pic1_io_resource = {
+	"pic1", 0x20, 0x3f, IORESOURCE_BUSY
+};
+
+static struct resource pic2_io_resource = {
+	"pic2", 0xa0, 0xbf, IORESOURCE_BUSY
 };
 
 void __init i8259_init(void)
@@ -136,21 +136,26 @@
 	unsigned long flags;
 
 	spin_lock_irqsave(&i8259_lock, flags);
-        /* init master interrupt controller */
-        outb(0x11, 0x20); /* Start init sequence */
-        outb(0x00, 0x21); /* Vector base */
-        outb(0x04, 0x21); /* edge tiggered, Cascade (slave) on IRQ2 */
-        outb(0x01, 0x21); /* Select 8086 mode */
-        outb(0xFF, 0x21); /* Mask all */
-        /* init slave interrupt controller */
-        outb(0x11, 0xA0); /* Start init sequence */
-        outb(0x08, 0xA1); /* Vector base */
-        outb(0x02, 0xA1); /* edge triggered, Cascade (slave) on IRQ2 */
-        outb(0x01, 0xA1); /* Select 8086 mode */
-        outb(0xFF, 0xA1); /* Mask all */
-        outb(cached_A1, 0xA1);
-        outb(cached_21, 0x21);
+	/* init master interrupt controller */
+	outb(0x11, 0x20); /* Start init sequence */
+	outb(0x00, 0x21); /* Vector base */
+	outb(0x04, 0x21); /* edge tiggered, Cascade (slave) on IRQ2 */
+	outb(0x01, 0x21); /* Select 8086 mode */
+	outb(0xFF, 0x21); /* Mask all */
+	/* init slave interrupt controller */
+	outb(0x11, 0xA0); /* Start init sequence */
+	outb(0x08, 0xA1); /* Vector base */
+	outb(0x02, 0xA1); /* edge triggered, Cascade (slave) on IRQ2 */
+	outb(0x01, 0xA1); /* Select 8086 mode */
+	outb(0xFF, 0xA1); /* Mask all */
+	outb(cached_A1, 0xA1);
+	outb(cached_21, 0x21);
 	spin_unlock_irqrestore(&i8259_lock, flags);

arch/ppc/kernel/i8259.c line 161

Quoted 10 lines
arch/ppc/kernel/i8259.c +7 -2
-        request_irq( i8259_pic_irq_offset + 2, no_action, SA_INTERRUPT,
-                     "82c59 secondary cascade", NULL );
+
+	request_irq( i8259_pic_irq_offset + 2, no_action, SA_INTERRUPT,
+				"82c59 secondary cascade", NULL );
+	request_resource(&ioport_resource, &pic1_io_resource);
+	request_resource(&ioport_resource, &pic2_io_resource);
+
+	pci_intack = ioremap(0xbffffff0, 1);
 }

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

#7 lore raw
In reply to [email protected]
Quoted 3 lines · On Wed, 7 Nov 2001 [email protected] wrote:

I laid out what I saw in
http://lists.linuxppc.org/linuxppc-workstation/200109/msg00030.html . I could be wrong, but our code doesn't seem to match the datasheet very well.

Have you ever see code matching the datasheet, or a chip matching the datasheet for that matter ? :-)

Oh, and I don't think that there is any integrated 8259 in a chipset which completely follows the implementation of the discrete part.

Quoted 7 lines

I think fixing what we have is the least intrusive, but I tried and failed, so it was nice to write code that actually worked. :) I guess the PCI intack stuff is too varied to be useful though...

Would you say poking the 8259 directly is more "right" than using 0xbffffff0 (or equivalent)?

Certainly not. Most ISA bridges (which are the part which contains the dual 8259 Pathetic Interrupt Controller), are tested in an x86 environment, which generate PCI interrupt acknowledge cycles. So hitting hardware bugs is much less likely than with polling.

Quoted 11 lines
Quoted 4 lines

Good, but you should add resource request for the edge/level control register while you are at it (0x4d0/4d1). And you should not require 32 bytes for the 8259. On my boards, the super I/O control port is 0x2e-ox2f.

That's what I forgot... that code requests directly from ioport_resource, which is what gets us into trouble on vgacon. We should use request_region instead of request_resource. Unfortunately vgacon is initialized before the VMM, and since request_region calls kmalloc we die very early. :/ I didn't check to see if that's a problem here.

Quoted 3 lines

The problem with using request_resource(&ioport_resource) in vgacon is that our PHB's initialize later, try to reserve their own IO regions (eg 0x0->0xffffffff), and fail because vgacon already took 0x3c0 or so.

I'd say that the problem is that the PHB is initialized too late while it should be one of the first things to be initialized.

I know that there are interactions with debugging/early console. I did something like this for my MVME boards, switching the host bridge from PreP to CHRP mappings. There is a transient period in which any kind of debugging is impossible: you don't have any I/O accessible. But in any case this kind of remapping is much better done early, actually before giving control to the kernel in my bootloader...

Gabriel.

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

#8 lore raw
Quoted 10 lines · Gabriel Paubert
Quoted 4 lines · On Wed, 7 Nov 2001 [email protected] wrote:

I laid out what I saw in
http://lists.linuxppc.org/linuxppc-workstation/200109/msg00030.html . I could be wrong, but our code doesn't seem to match the datasheet very well.

Have you ever see code matching the datasheet, or a chip matching the datasheet for that matter ? :-)

To be honest I think I was wrong. Reading the 8259 datasheet yet again has enlightened me as the the exact nature of "INTA" and polling. What I thought were ISR/IRR reads were actually INTA's (returning the ISR in the process).

So the stock code is definately funny (there's no need at all to explicitly switch between the ISR and IRR), but correct AFAICS. Which is unfortunate for me... :/

I've changed it a little to avoid this ISR selection and it's more robust (I can boot), but still falls over pretty easily. All routines are spin_lock() protected though; I'm not sure what sort of timing problem I might look for.

Quoted 7 lines
Quoted 2 lines

Would you say poking the 8259 directly is more "right" than using 0xbffffff0 (or equivalent)?

Certainly not. Most ISA bridges (which are the part which contains the dual 8259 Pathetic Interrupt Controller), are tested in an x86 environment, which generate PCI interrupt acknowledge cycles. So hitting hardware bugs is much less likely than with polling.

I'm worried this is my problem. I'm looking at the "Poll Command" section of the 8259 docs, and i8259.c seems completely legit...

-Hollis

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/