Skip to contentSkip to conversation

Can we kill f inb_p, outb_p and other random I/O on port 0x80, in 2.6?

DISCUSSION Eric W. Biederman 4 participants 4 messages Sep 22, 2003 – Sep 24, 2003 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 12 lines · [email protected] writes:
Quoted 11 lines

inb_p and outb_p issue outb's to port 0x80 to achieve a short delay. In a reasonable system there is nothing listening to port 0x80 or there is a post card, but there are no other devices there.

On a modern system with no post card the outb travels it's way down to the LPC bus, and the outb is terminated by an abort because nothing is listening.

So far so good. Except for the fact that recent high volume ROM chips get confused when they see an abort on the LPC bus. Making it problematic to update the ROM from under Linux.

Quoted 5 lines

Juts when we think we've found a safe time delay, somebody goes and screws it up.

1) Could you specify the ROM chips concerned? Is it possible to unconfuse them in software as a workaround?

SST. And they don't stay confused. They just drop whatever
command you were sending them. And dropping writes to a ROM chip is very nasty. If you don't catch and fix it your system will not boot the next time.

Quoted 3 lines

2) Do the BIOSes not write to port 0x80 themselves? The port was chosen precisely because most current BIOSes write boot progress indicators there, so Linux shouldn't be doing anything new.

I think they do. I have not been able to hook up a post card to
check. The difference is that they don't do it while talking
to the ROM chip.

Quoted 9 lines
Quoted 2 lines

I don't know if there are other buggy LPC devices or not. But I do know that it is generally bad form do I/O to a random port.

It's bad form to do I/O on a *random* port because you don't know what might be listening. It's *not* bad form to write to a known unused I/O port. On the original ISA bus, that's harmless, and the LPC bus is supposed to emulate that.

And, as I mentioned, most BIOSes write to that port periodically.

Yes. There are a few boards and few weird cases where 0x80 is not safe. This just adds to the list of problematic cases.

Quoted 10 lines
Quoted 2 lines

So can we gradually kill inb_p, outb_p in 2.6? An the other miscellaneous users of I/O port 0x80 for I/O delays?

Actually, It's not easy. The issue got debated a lot a few years ago. A read is also acceptable, and allows a few more ports to be potentially used, but that corrupts %al and thus bloats the code.

Quoted 2 lines

Or possibly rewriting outb_p to look something like:
outb(); udelay(200); or whatever the appropriate delay is?

Quoted 7 lines

As Alan points out, udelay() requires either using the 8254 PIT or knowing at least one system clock speed to calibrate a bogomips-style delay loop. All of the known clock frequencies are on ISA-bus peripherals. So we have to access them BEFORE udelay() is calibrated.

And the 8254 is one of the chips which requires the pause. This creates a significant boot-order challenge.

Yes, I agree. And during bootstrap the 0x80 case does not cause me problems. But when the system is running I either need cli();
......
sti();
pairs in my code, a global lpc bus lock, or I need to avoid the writes to port 0x80. I can't even use cli()/sti() because they have been removed in 2.6.

Quoted 8 lines
Quoted 3 lines

When debugging this I modified arch/i386/io.h to read:
#define __SLOW_DOWN_IO__ ""
Which totally removed the delay and the system ran fine.

Yes, in 98% of modern boards it *does* work fine to just omit the delays entirely, because the motherboard chipset emulation can cope. But the original chip specs call for the delay, and the kernel has a hard time figuring out what's what early in the boot process.

Right. So this does need to be handled and delicately.

My main goal is to remove the deep magic voodoo in place. I would object less if the code was clearly commented and isolated, to those few places that need it.

Eric

#2 lore raw
Quoted 6 lines · [email protected] writes:
Quoted 2 lines

So can we gradually kill inb_p, outb_p in 2.6? An the other miscellaneous users of I/O port 0x80 for I/O delays?

Actually, It's not easy. The issue got debated a lot a few years ago. A read is also acceptable, and allows a few more ports to be potentially used, but that corrupts %al and thus bloats the code.

It bloats the code a lot less than udelay() calls or any other solution which keeps the delay!

In the worst case, the bloat from a read _should_ be two bytes: "push %eax; inb $80,%al; pop %eax". Whereas a call to udelay is 5 bytes, for a call instruction.

-- Jamie

#3 lore raw

In article <[email protected]>, Jamie Lokier <[email protected]> wrote:

| [email protected] writes:
| > > So can we gradually kill inb_p, outb_p in 2.6?  An the other
| > > miscellaneous users of I/O port 0x80 for I/O delays?
| > 
| > Actually, It's not easy.  The issue got debated a lot a few years ago.
| > A read is also acceptable, and allows a few more ports to be
| > potentially used, but that corrupts %al and thus bloats the code.
| 
| It bloats the code a lot less than udelay() calls or any other
| solution which keeps the delay!
| 
| In the worst case, the bloat from a read _should_ be two bytes: "push
| %eax; inb $80,%al; pop %eax".  Whereas a call to udelay is 5 bytes,
| for a call instruction.

Isn't one of the benefits of a rethink not to use any i/o bus cycles?

Signature · 3 lines
bill davidsen <[email protected]>
  CTO, TMR Associates, Inc
Doing interesting things with little computers since 1979.
#4 lore raw
Quoted 2 lines · bill davidsen

Isn't one of the benefits of a rethink not to use any i/o bus cycles?

I wouldn't worry about the bloat as much as I do about synchronization.

Doing an IO to an ISA device not just causes a delay, but tends to actually force the PCI forwarding buffers to flush.

Of course, IOIO shouldn't be buffered anyway, and if we wanted to flush stuff we'd actually be better with a read, so..

But what we _could_ do is to make "inb_p()" be more like this

        #define inb_p(port) ({ unsigned char val; \
                asm volatile("call __inb_p" \
                        :"=a" (val) \
                        :"d" ((unsigned short)(port))); \
                val; })

where we call to an out-of-line function with a magic calling convention (so that it doesn't flush the register state like a normal call would).

That would likely shrink the code, and it would mean that we could more easily play with what we do in the delay case (including deciding the code at boot-time).

Anybody want to try that?

Linus