Skip to contentSkip to conversation

2.6 kernel won't reboot on AMD system - 8042 problem?

DISCUSSION Dmitry Torokhov 4 participants 9 messages Aug 11, 2004 – Aug 13, 2004

lore
Share & tools
lore
#0 lore raw

Sorry for breaking the thread....

Quoted 12 lines · Sascha Wilde
Quoted 5 lines · Vojtech Pavlik
Quoted 4 lines · Dmitry Torokhov
Quoted 3 lines · David N. Welton

By putting a series of 'crashme/reboot' calls into the kernel, I narrowed a possibl cause of it down to this bit of code in drivers/input/serio.c:753

[...]

Quoted 5 lines
Quoted 4 lines

Could you please try the patch below? I am interested in tests both with and without keyboard/mouse. The main idea is to leave ports that have been disabled by BIOS alone... The patch compiles but otherwise untested. Against 2.6.7.

Quoted 6 lines
Quoted 3 lines

Well, this has a problem - plugging a mouse later will never work, as the interface will be disabled by the BIOS if a mouse is not present at boot.

Is PS/2 supposed to support hotpluging at all? I guess it's not, but I may be wrong...

Yes it is, at least with newer (or rather not ancient) hardware...

Quoted 1 line

From what I can see 2.4 does not have this problem because before

toucing the control register it tries to reset the keyboard and stops if there is not response. I think this also menas that 2.4 does not support keyboard hot-plugging. In 2.6 we do not make any assumptions on what kind of hardware attached to a port (KBD, mouse) so reset test probably won't work...

I wonder if simply resetting controller (by passing i8042.reset) would help in your case?

--
Dmitry

#1 lore raw
Quoted 15 lines · Dmitry Torokhov

Sorry for breaking the thread....

Quoted 12 lines · Sascha Wilde
Quoted 5 lines · Vojtech Pavlik
Quoted 4 lines · Dmitry Torokhov
Quoted 3 lines · David N. Welton

By putting a series of 'crashme/reboot' calls into the kernel, I narrowed a possibl cause of it down to this bit of code in drivers/input/serio.c:753

[...]

Quoted 5 lines
Quoted 4 lines

Could you please try the patch below? I am interested in tests both with and without keyboard/mouse. The main idea is to leave ports that have been disabled by BIOS alone... The patch compiles but otherwise untested. Against 2.6.7.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Well, this has a problem - plugging a mouse later will never work, as the interface will be disabled by the BIOS if a mouse is not present at boot.

Is PS/2 supposed to support hotpluging at all? I guess it's not, but I may be wrong...

Yes it is, at least with newer (or rather not ancient) hardware...

well, so the patch obviously can't be a final solution...

Quoted 9 lines

From what I can see 2.4 does not have this problem because before toucing the control register it tries to reset the keyboard and stops if there is not response. I think this also menas that 2.4 does not support keyboard hot-plugging. In 2.6 we do not make any assumptions on what kind of hardware attached to a port (KBD, mouse) so reset test probably won't work...

I wonder if simply resetting controller (by passing i8042.reset) would help in your case?

It helps in a sense, as rebooting works with this option -- unfortunately when passing i8042.reset on boottime the keyboard is dead, so it doesn't help.

cheers

Signature · 4 lines
Sascha Wilde
... mein Opa [...]  würde an dieser Stelle zu Dir sagen: Junge, such Dir 
ne Frau, bau Dir ein Haus, mach ein Kind und laß' die Finger von dem Zeug,
das Du gerade machst. -- Michael Winklhofer in d.a.e.auktionshaeuser
#2 lore raw
Quoted 7 lines · Sascha Wilde
Quoted 4 lines
Quoted 2 lines

Is PS/2 supposed to support hotpluging at all? I guess it's not,
but I may be wrong...

Yes it is, at least with newer (or rather not ancient) hardware...

well, so the patch obviously can't be a final solution...

Yes, it doesn't strike me as being ideal.

More playing with the triple fault leads me to this:

static int i8042_command(unsigned char *param, int command)

{
	unsigned long flags;
	int retval = 0, i = 0;

	spin_lock_irqsave(&i8042_lock, flags);

	retval = i8042_wait_write();
	if (!retval) {
		dbg("%02x -> i8042 (command)", command & 0xff);
		i8042_write_command(command & 0xff);
	}

=====> A

	if (!retval)
		for (i = 0; i < ((command >> 12) & 0xf); i++) {
			if ((retval = i8042_wait_write())) break;
			dbg("%02x -> i8042 (parameter)", param[i]);
			i8042_write_data(param[i]);
		}

=====> B

Point 'B' is the "point of no reboot", at A we can still triple fault it and get a nice normal reboot, so it's the parameter that it's writing that it causing it to go funny.

I noticed something odd though... I reported this in another email:

*With keyboard* :

mice: PS/2 mouse device common for all mice drivers/input/serio/i8042.c: 20 -> i8042 (command) [0] drivers/input/serio/i8042.c: 65 <- i8042 (return) [0]

*Without keyboard* :

mice: PS/2 mouse device common for all mice drivers/input/serio/i8042.c: fa <- i8042 (flush, aux) [0] drivers/input/serio/i8042.c: 20 -> i8042 (command) [0] drivers/input/serio/i8042.c: 9a <- i8042 (return) [0]

I noticed that
0x9a is the 'inverse' of 0x65. If I set it to 0x65 and write that out, it still reboots afterwards! Hrm. I don't know what that means exactly, but apparently it *is* possible to write something to the controller and have it keep going.

Sascha, if you want to test it out, try this in i8042_controller_init, at about line 724 (near this: i8042_initial_ctr = i8042_ctr;)

	{
	    unsigned char pram;
	    pram = (~i8042_ctr) & 0xff ;
	    i8042_command(&pram, I8042_CMD_CTL_WCTR);
	}

	{
	    static struct
	    {
		unsigned short       size __attribute__ ((packed));
		unsigned long long * base __attribute__ ((packed));
	    } no_idt = { 0, 0 };

	    __asm__ __volatile__("lidt %0": :"m" (no_idt));
	    __asm__ __volatile__("int3");
	}

It reboots!

Signature · 2 lines
David N. Welton
[email protected]
#3 lore raw
Quoted 8 lines · David N. Welton

Sascha, if you want to test it out, try this in i8042_controller_init, at about line 724 (near this: i8042_initial_ctr = i8042_ctr;)

    {
        unsigned char pram;
        pram = (~i8042_ctr) & 0xff ;
        i8042_command(&pram, I8042_CMD_CTL_WCTR);
    }

In fact, it's enough to fix the problem on my machine! I can even plug the keyboard back in and it works.

--- /home/davidw/linux-2.6.7/drivers/input/serio/i8042.c 2004-06-16 07:18 :57.000000000 +0200
+++ drivers/input/serio/i8042.c 2004-08-12 19:05:17.000000000 +0200 @@ -710,6 +710,9 @@

                return -1;
        }

+
+ i8042_ctr = (~i8042_ctr) & 0xff;
+

        i8042_initial_ctr = i8042_ctr;

Try that and see how it works for you (sorry 'bout the formatting... at work I have Mozilla Thunderbird).

Now... I guess the problem is: 1) why the heck does that work? 2) How to integrate it into the kernel? I don't suppose everyone else wants their register values inverted.

Signature · 2 lines
David N. Welton
[email protected]
#4 lore raw
Quoted 27 lines · David N. Welton
Quoted 8 lines · David N. Welton

Sascha, if you want to test it out, try this in i8042_controller_init, at about line 724 (near this: i8042_initial_ctr = i8042_ctr;)

   {
       unsigned char pram;
       pram = (~i8042_ctr) & 0xff ;
       i8042_command(&pram, I8042_CMD_CTL_WCTR);
   }

In fact, it's enough to fix the problem on my machine! I can even plug the keyboard back in and it works.

--- /home/davidw/linux-2.6.7/drivers/input/serio/i8042.c 2004-06-16 07:18
:57.000000000 +0200
+++ drivers/input/serio/i8042.c 2004-08-12 19:05:17.000000000 +0200

(quoted diff) +3 -0
@@ -710,6 +710,9 @@
                return -1;
        }
 
+
+       i8042_ctr = (~i8042_ctr) & 0xff;
+
        i8042_initial_ctr = i8042_ctr;
 
Quoted 1 line

Try that and see how it works for you

This works for me too. Thanks!

I hadn't had the time to read the rest of the thread in full detail, but it seem, that we are geting closer to a solution.

cheers
sascha

Signature · 2 lines
Sascha Wilde
"Gimme about 10 seconds to think for a minute..."
#5 lore raw
In reply to David N. Welton
Quoted 28 lines · David N. Welton
Quoted 7 lines · Sascha Wilde
Quoted 4 lines
Quoted 2 lines

Is PS/2 supposed to support hotpluging at all? I guess it's not, but I may be wrong...

Yes it is, at least with newer (or rather not ancient) hardware...

well, so the patch obviously can't be a final solution...

Yes, it doesn't strike me as being ideal.

I noticed something odd though... I reported this in another email:

*With keyboard* :

mice: PS/2 mouse device common for all mice drivers/input/serio/i8042.c: 20 -> i8042 (command) [0] drivers/input/serio/i8042.c: 65 <- i8042 (return) [0]

*Without keyboard* :

mice: PS/2 mouse device common for all mice drivers/input/serio/i8042.c: fa <- i8042 (flush, aux) [0] drivers/input/serio/i8042.c: 20 -> i8042 (command) [0] drivers/input/serio/i8042.c: 9a <- i8042 (return) [0]

Quoted 5 lines

I noticed that
0x9a is the 'inverse' of 0x65. If I set it to 0x65 and write that out, it still reboots afterwards! Hrm. I don't know what that means exactly, but apparently it *is* possible to write something to the controller and have it keep going.

0x65:
Reserved bit is zero (must be)
Scancode translation enabled
AUX interface disabled
KBD interface enabled
Keylock not ignored
Selftest OK
AUX interrupt disabled
KBD interrupt enabled

All in all, 0x65 is what one would expect to be in the CTR register after boot on a normal machine without a PS/2 mouse installed.

0x9a doesn't make sense _AT_ALL_, though!

And there comes a thought ...

In i8042_command(), we do this:

      if (!retval)
                for (i = 0; i < ((command >> 8) & 0xf); i++) {
                        if ((retval = i8042_wait_read())) break;
                        if (i8042_read_status() & I8042_STR_AUXDATA)
                                param[i] = ~i8042_read_data();
                        else
                                param[i] = i8042_read_data();
                        dbg("%02x <- i8042 (return)", param[i]);
                }

to distinguish whether a response came from the AUX interface instead of the KBD or controller itself. We _negate_ the value if the AUXDATA bit is set in he status register.

So I think what happens is that the controller sets the AUXDATA bit for some reason (or at least we read a status byte with the AUXDATA bit set), which negates the value when we read the initial CTR.

Then when we write that nonsensical CTR back to the controller on reboot, we're screwed, since the i8042 is the more important CPU in the system and can do many nasty things to it. ;)

Now, the question is, where does that AUXDATA bit come from?

Signature · 2 lines
Vojtech Pavlik
SuSE Labs, SuSE CR
#6 lore raw
Quoted 2 lines · Vojtech Pavlik

All in all, 0x65 is what one would expect to be in the CTR register after boot on a normal machine without a PS/2 mouse installed.

Sure, if you search google on the results from the 20 command, you see a lot of things like 0x64 0x64 0x75 0x74 and similar values.

Quoted 1 line

0x9a doesn't make sense _AT_ALL_, though!

Right.

Quoted 14 lines

And there comes a thought ...

In i8042_command(), we do this:

      if (!retval)
                for (i = 0; i < ((command >> 8) & 0xf); i++) {
                        if ((retval = i8042_wait_read())) break;
                        if (i8042_read_status() & I8042_STR_AUXDATA)
                                param[i] = ~i8042_read_data();
                        else
                                param[i] = i8042_read_data();
                        dbg("%02x <- i8042 (return)", param[i]);
                }
Quoted 3 lines

to distinguish whether a response came from the AUX interface instead of the KBD or controller itself. We _negate_ the value if the AUXDATA bit is set in he status register.

Oh, yep, there we go... that's what's switching it around.

Quoted 9 lines

So I think what happens is that the controller sets the AUXDATA bit for some reason (or at least we read a status byte with the AUXDATA bit set), which negates the value when we read the initial CTR.

Then when we write that nonsensical CTR back to the controller on reboot, we're screwed, since the i8042 is the more important CPU in the system and can do many nasty things to it. ;)

Now, the question is, where does that AUXDATA bit come from?

I noticed that the FreeBSD folks attempt to flush both kbd and aux:

http://fxr.watson.org/fxr/source/dev/kbd/atkbdc.c#L790

I tried doing that like so:

	while ((i8042_read_status() & (I8042_STR_OBF | I8042_STR_AUXDATA)) && 
(i++ < I8042_BUFFER_SIZE)) {
		data = i8042_read_data();
		dbg("%02x <- i8042 (flush, %s)", data,
			i8042_read_status() & I8042_STR_AUXDATA ? "aux" : "kbd");
	}

with different variations, and it seems as if it will go on reading forever if you let it. So it keeps reporting AUXDATA as being present... Hrm...

Signature · 2 lines
David N. Welton
[email protected]
#7 lore raw
Quoted 26 lines · David N. Welton

Oh, yep, there we go... that's what's switching it around.

Quoted 9 lines

So I think what happens is that the controller sets the AUXDATA bit for some reason (or at least we read a status byte with the AUXDATA bit set), which negates the value when we read the initial CTR.

Then when we write that nonsensical CTR back to the controller on reboot, we're screwed, since the i8042 is the more important CPU in the system and can do many nasty things to it. ;)

Now, the question is, where does that AUXDATA bit come from?

I noticed that the FreeBSD folks attempt to flush both kbd and aux:

http://fxr.watson.org/fxr/source/dev/kbd/atkbdc.c#L790

I tried doing that like so:

	while ((i8042_read_status() & (I8042_STR_OBF | I8042_STR_AUXDATA)) 
	&& (i++ < I8042_BUFFER_SIZE)) {
		data = i8042_read_data();
		dbg("%02x <- i8042 (flush, %s)", data,
			i8042_read_status() & I8042_STR_AUXDATA ? "aux" : 
			"kbd");
	}
Quoted 3 lines

with different variations, and it seems as if it will go on reading forever if you let it. So it keeps reporting AUXDATA as being present... Hrm...

There is only one queue in the i8042, shared for KBD and AUX. To see if any data is present, you check the I8042_STR_IBF bit. The I8042_STR_AUXDATA bit then says which device the data came from.

You can't choose which device you want to read from.

Now I think the problem lies in that that on your i8042 issuing a command doesn't clear the AUXDATA bit. It's only cleared by data from the keyboard.

This is likely a bug in you i8042 firmware (or hw, if it's just an ASIC).

I suppose we can get rid of the checking of data source and negation and be done with it.

Signature · 2 lines
Vojtech Pavlik
SuSE Labs, SuSE CR
#8 lore raw
Quoted 6 lines · Vojtech Pavlik

Now I think the problem lies in that that on your i8042 issuing a command doesn't clear the AUXDATA bit. It's only cleared by data from the keyboard.

This is likely a bug in you i8042 firmware (or hw, if it's just an ASIC).

Well, that has always seemed likely to me, given that rebooting without a keyboard is something that works on pretty much everyone else's machines! But to some degree the bug ought to be worked around.

Quoted 2 lines

I suppose we can get rid of the checking of data source and negation and be done with it.

That helps, but there are still situation(s?) where it's not a complete solution. It's good enough for what I need, though.

Starting with no keyboard, plug one in:

$ drivers/input/serio/i8042.c: aa <- i8042 (interrupt, aux, 0) [161928] 

drivers/input/serio/i8042.c: 60 -> i8042 (command) [162009]

drivers/input/serio/i8042.c: 46 -> i8042 (parameter) [162009]

drivers/input/serio/i8042.c: d4 -> i8042 (command) [162151]

drivers/input/serio/i8042.c: f2 -> i8042 (parameter) [162151]

drivers/input/serio/i8042.c: fe <- i8042 (interrupt, aux, 0) [162343]

drivers/input/serio/i8042.c: d4 -> i8042 (command) [162424]

drivers/input/serio/i8042.c: ed -> i8042 (parameter) [162424]

drivers/input/serio/i8042.c: fe <- i8042 (interrupt, aux, 0) [162616]

drivers/input/serio/i8042.c: 60 -> i8042 (command) [162697]

drivers/input/serio/i8042.c: 44 -> i8042 (parameter) [162697]

drivers/input/serio/i8042.c: aa <- i8042 (interrupt, aux, 0) [162989]

drivers/input/serio/i8042.c: 60 -> i8042 (command) [163070]

drivers/input/serio/i8042.c: 46 -> i8042 (parameter) [163070]

drivers/input/serio/i8042.c: d4 -> i8042 (command) [163212]

drivers/input/serio/i8042.c: f2 -> i8042 (parameter) [163212]

drivers/input/serio/i8042.c: fa <- i8042 (interrupt, kbd, 0) [163404]

drivers/input/serio/i8042.c: ab <- i8042 (interrupt, kbd, 0) [163485]

drivers/input/serio/i8042.c: 41 <- i8042 (interrupt, kbd, 0) [163566]

drivers/input/serio/i8042.c: d4 -> i8042 (command) [163792]

drivers/input/serio/i8042.c: ed -> i8042 (parameter) [163792]

drivers/input/serio/i8042.c: fa <- i8042 (interrupt, kbd, 0) [163983]

drivers/input/serio/i8042.c: 60 -> i8042 (command) [164209]

drivers/input/serio/i8042.c: 44 -> i8042 (parameter) [164209]

Oops, it doesn't respond to anything... We unplug it and plug it back in again. This time it's ok:

$ drivers/input/serio/i8042.c: aa <- i8042 (interrupt, kbd, 0) [191951] 

drivers/input/serio/i8042.c: 60 -> i8042 (command) [192032]

drivers/input/serio/i8042.c: 45 -> i8042 (parameter) [192032]

drivers/input/serio/i8042.c: f2 -> i8042 (kbd-data) [192174]

drivers/input/serio/i8042.c: fa <- i8042 (interrupt, kbd, 1) [192247]

drivers/input/serio/i8042.c: ab <- i8042 (interrupt, kbd, 1) [192329]

drivers/input/serio/i8042.c: 41 <- i8042 (interrupt, kbd, 1) [192410]

drivers/input/serio/i8042.c: ed -> i8042 (kbd-data) [192491]

drivers/input/serio/i8042.c: fa <- i8042 (interrupt, kbd, 1) [192565]

drivers/input/serio/i8042.c: 00 -> i8042 (kbd-data) [192646]

drivers/input/serio/i8042.c: fa <- i8042 (interrupt, kbd, 1) [192719]

drivers/input/serio/i8042.c: f3 -> i8042 (kbd-data) [192801]

drivers/input/serio/i8042.c: fa <- i8042 (interrupt, kbd, 1) [192874]

drivers/input/serio/i8042.c: 00 -> i8042 (kbd-data) [192956]

drivers/input/serio/i8042.c: fa <- i8042 (interrupt, kbd, 1) [193029]

drivers/input/serio/i8042.c: f4 -> i8042 (kbd-data) [193110]

drivers/input/serio/i8042.c: fa <- i8042 (interrupt, kbd, 1) [193184]

input: AT Translated Set 2 keyboard on isa0060/serio0

This, because it checks in i8042_interrupt to see if the nefarious STR_AUXDATA is set, which it is... According to your hypothesis, plugging the keyboard in and hitting a few keys would have cleared the AUXDATA bit, so the next time around it works fine.

Thanks,

Signature · 2 lines
David N. Welton
[email protected]