Page 1 of 1

Checking if PS/2 controller exists

Posted: Fri Nov 27, 2020 1:06 pm
by md37
Hi.
I am writing a PS/2 keyboard writer. I disabled all of the USB legacy support. Now I'm trying to detect presence of the PS/2 controller. Wiki says, that I need to check bit 1 of the IA-PC Boot Architecture Flags in FADT, but this method doesn't work on some computers, on which I tested my OS. For example, on my DELL laptop the internal keyboard is connected over PS/2 (I know that, because after disabling USB legacy only that keyboard is working, the USB ones stop), it does have PS/2 controller, but IA-PC Flags are all zero.
So, is there any other reliable method of detecting PS/2 controller?

Re: Checking if PS/2 controller exists

Posted: Fri Nov 27, 2020 1:46 pm
by Octocontrabass
Did you check the version of the FADT? The IA-PC boot architecture flags only exist on versions 3 and up. If it's version 1, the PS/2 controller exists. (ACPI does not specify version 2.)

Re: Checking if PS/2 controller exists

Posted: Fri Nov 27, 2020 2:03 pm
by md37
I checked that now. I'm checking offset 8 in FADT (Major field). In QEMU Major version of FADT is 1, but on my laptop it's 2.

Re: Checking if PS/2 controller exists

Posted: Fri Nov 27, 2020 2:22 pm
by Octocontrabass
That's less than 3, so a PS/2 controller exists.

Re: Checking if PS/2 controller exists

Posted: Fri Nov 27, 2020 4:27 pm
by BenLunt
If you wish to detect the hardware using the hardware, Volume 4 of my book series shows this in detail, with source code, more specifically, line 217 in ps2share.c.

If the test passes, even if it is emulated by the USB, you can pretty much assume that all other function is emulated correctly.

Ben

Re: Checking if PS/2 controller exists

Posted: Fri Nov 27, 2020 4:38 pm
by Octocontrabass
If ACPI says there's no PS/2 controller and you try to access it anyway, the PC might hang. (For example, try an x86 Mac.)

Re: Checking if PS/2 controller exists

Posted: Sat Nov 28, 2020 3:50 am
by md37
Is there FADT version 5 and 6? (Maybe I'm reading wrong field).
I tested my OS on 4 computers. Here are the results:
1. FADT version 2, IA Flags 0x03
2. (That DELL) FADT version 2, IA Flags 0x00
3. FADT version 5, IA Flags 0x13
4. FADT version 6, IA Flags 0x03
So, why first computer has proper IA Flags even though it has FADT v2?
Also, where in the ACPI specification is located info about FADT versions? I'd like to read about it.

[EDIT]
I found that in ACPI 2.0 FADT version is 3, and in ACPI 1.0 version is 1. So why I have ACPI 2.0 and FADT v2? As you said, ACPI doesn't specify FADT v2.

Re: Checking if PS/2 controller exists

Posted: Sat Nov 28, 2020 6:08 pm
by Octocontrabass
md37 wrote:Is there FADT version 5 and 6?
Yes.
md37 wrote:So, why first computer has proper IA Flags even though it has FADT v2?
The firmware developer may have been working from a draft specification, or it could just be a typo. ACPICA ignores the version and uses the length of the FADT to figure out what version it's supposed to be.
md37 wrote:Also, where in the ACPI specification is located info about FADT versions?
You have to look at older versions of the ACPI specification to see older versions of the FADT.
md37 wrote:So why I have ACPI 2.0 and FADT v2?
It's common for firmware to use older versions of tables when they don't need to use features that are only present in newer versions of those tables. It's also common for firmware to be awful and buggy, especially old firmware using early versions of ACPI.