Page 1 of 1

PS2 Device Reset on 2nd port always produces success.

Posted: Sun Mar 20, 2016 5:29 pm
by alwaysnub
I have been working on a PS2 driver for my OS and ran into an interesting result.

On my Older desktop, When i attempt to Reset the device on the 2nd port, i always get a success response regardless of whether there is a device connected to it.
I know what your thinking... SEND COMMAND D4!. Yes im doing that. Even if i have both ports unplugged, the 2nd port still reports success.
I have tested my PS2 init procedure on 2 desktop machines and this only happens on the older one.
When i have a mouse connected to the 2nd port, i get data as expected.

Anyone have any ideals why the controller might pretend there's a device connected? Or perhaps the response is coming from a USB controller, though i Don't have any USB devices connected...

Here are my logging's for Device Reset on 2 different desktop PCs:
PC1 is a slightly newer system.

No Device
PC1 - Endless 0xFE (Resend Command)
PC2 - 0xFA (ACK) Followed By 0xFC (Self Test Failed). 2nd Port always Success...

With Device Connected
PC1 - 0xFA (ACK) Followed By 0xAA (Self Test Passed)
PC2 - 0xFA (ACK) Followed By 0xAA (Self Test Passed)

On the "8042" PS/2 Controller wiki page, sortie commented:
Potential wiki error, the 0xFF reset device command seems to respond 0xAA and then 0xFA on self-test success, and PS/2_Keyboard agrees. --Sortie 14:15, 27 April 2015 (CDT)
I think the wiki page should probably be updated to say the Reset Device command may send its response in any order, since it seems that's the case.

Re: PS2 Device Reset on 2nd port always produces success.

Posted: Mon Mar 21, 2016 4:18 am
by Octocontrabass
alwaysnub wrote:Anyone have any ideals why the controller might pretend there's a device connected?
The PS/2 controller may be running faulty code. The fault may even be intentional; some versions of Windows require a reboot to use a PS/2 mouse if one wasn't detected during boot.
alwaysnub wrote:Or perhaps the response is coming from a USB controller, though i Don't have any USB devices connected...
If the chipset supports USB PS/2 emulation, and that emulation is enabled by the BIOS, it will affect all accesses of the PS/2 controller even if no USB devices are connected. You need to either initialize the USB controllers or disable USB PS/2 emulation in the BIOS. (If you decide to change the BIOS settings, make sure you have a PS/2 keyboard - the BIOS may stop responding to USB keyboards.)

Re: PS2 Device Reset on 2nd port always produces success.

Posted: Tue Mar 22, 2016 12:00 pm
by alwaysnub
You need to either initialize the USB controllers or disable USB PS/2 emulation in the BIOS.
I have initialized the USB controllers and the 2nd port has stopped responding with success when there is No device connected.
Both ports now respond with endless 0xFE (Resend) when no device is connected. USB is indeed to blame here.

I have noted some more interesting behavior though:

If a keyboard is plugged into the 2nd port and nothing into the 1st port, the 2nd ports interrupt line is routed to IRQ1 instead of IRQ12.
If you hot plug Another keyboard into the 1st port, the 2nd port will now be routed to IRQ12 instead of IRQ1.
If however, you have a mouse plugged into the 2nd port and nothing into the 1st port, the 2nd ports interrupt line is routed to IRQ12 as expected.

If a mouse is plugged into the 1st port and nothing into the 2nd port, the 1st ports interrupt line is routed to IRQ12 instead of IRQ1.
If you hot plug Another mouse into the 2nd port, the 1st ports interrupt line will now be routed to IRQ1 instead of IRQ12.


Not only are the interrupt lines effected, but the same effect is applied when sending commands (ie, Device Reset).

Conclusion:
If you have a mouse or keyboard plugged in, the mouse is routed to IRQ12 (Port 2) and the keyboard to IRQ1 (Port 1) regardless of the ports they are connected to.
If you have 2 devices of the same type plugged in, they are routed to their correct interrupt lines/ports (ONLY IF both devices plugged in).

Re: PS2 Device Reset on 2nd port always produces success.

Posted: Tue Mar 22, 2016 12:54 pm
by ~
Just be careful when hot plugging.

I once mistakenly plugged the keyboard into the PS/2 mouse port and it got burned because of the added consumption due to the LEDs and probably because of the different circuitry.

It was an XCel2000 Pentium III 500MHz.

There are some Pentium 4 PC-Chips machines from 2003-2004 that can swap PS/2 ports interchangeably for the mouse and keyboard, but it's risky to plug them the other way around. If they get burned they will no longer work if they are soldered on the motherboard and also integrated into the chipset-wide Super I/O circuit, so it most likely couldn't be replaced to repair it.