Page 1 of 1

GNU-EFI No mouse input detected in QEMU-X86-64

Posted: Fri Oct 13, 2023 5:11 pm
by koki1019
Hello!, I'm pretty new to OSDev so sorry if i sound like a total noob (im well experienced with low level programming tho i've made game engines softwares and programs in assembly before)

I'm trying to get mouse events & inputs working in my UEFI Kernel (made with GNU-EFI)
The thing is, it doesn't work at all in QEMU but when i test it on real hardware it works just fine!
I've tried adding the mouse to the qemu like this: -usb -device usb-host,hostbus=1,hostaddr=3
lsusb lists this as my mouse: Bus 001 Device 003: ID 1532:0078 Razer USA, Ltd Viper (wired) (my mouse is razer viper so this is the mouse)
when i add this option the mouse becomes completely unusable outside and inside of QEMU, i cannot move it or click anything so i have to force shutdown QEMU for my mouse to work again

Sorry again if this sounds such a noob post, really couldn't find anything about this on google :cry:

Code:

Code: Select all

EFI_SIMPLE_POINTER_PROTOCOL *mouse;
EFI_SIMPLE_POINTER_STATE State;
EFI_GUID pointer_guid = EFI_SIMPLE_POINTER_PROTOCOL_GUID;

void pointer_mouse_setup() {
    uefi_call_wrapper(ST->BootServices->LocateProtocol, 3, &pointer_guid, NULL, (VOID **)&mouse);
    uefi_call_wrapper(mouse->Reset, 2, mouse, true);
}

EFI_STATUS EFIAPI efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) {
    InitializeLib(ImageHandle, SystemTable);
    // Print(L"Hello, World!\n");
    EFI_INPUT_KEY key;
    __volume = __getvolume(ImageHandle);
    UINTN key_event = 0;

    pointer_mouse_setup();

    ST = SystemTable;
    // ...
    UINTN index;
    EFI_EVENT Events[2] = {mouse->WaitForInput, ST->ConIn->WaitForKey};

    while(!exit) {
          uefi_call_wrapper(ST->BootServices->WaitForEvent, 3, 2, Events, &index);
          if (index == 0) {
                // THIS DOES NOT Get called in the qemu at all while it works just fine when tested on real hardware!
                EFI_STATUS x = uefi_call_wrapper(mouse->GetState, 2, mouse, &State); // This says not ready on QEMU too btw!
                Print(L"X:%d Y:%d Z:%d L:%d R:%d\n",
                      State.RelativeMovementX,
                      State.RelativeMovementY,
                      State.RelativeMovementZ,
                      State.LeftButton,
                      State.RightButton);
          }
          // keyboard input ...
    }
}

Re: GNU-EFI No mouse input detected in QEMU-X86-64

Posted: Sat Oct 14, 2023 5:14 am
by klange
OVMF doesn't have mouse drivers.
when i add this option the mouse becomes completely unusable outside and inside of QEMU, i cannot move it or click anything so i have to force shutdown QEMU for my mouse to work again
That is a natural result of using USB passthrough to the provide the device to VM.

Re: GNU-EFI No mouse input detected in QEMU-X86-64

Posted: Sat Oct 14, 2023 5:15 am
by koki1019
klange wrote:OVMF doesn't have mouse drivers.
when i add this option the mouse becomes completely unusable outside and inside of QEMU, i cannot move it or click anything so i have to force shutdown QEMU for my mouse to work again
That is a natural result of using USB passthrough to the provide the device to VM.
ah didn't knew that, thanks

Re: GNU-EFI No mouse input detected in QEMU-X86-64

Posted: Sat Oct 14, 2023 5:32 am
by klange
EDK2 does have a USB HID mouse driver that should provide the simple pointer protocol: https://github.com/tianocore/edk2/tree/ ... sbMouseDxe

You can try to build and install the DXE. OVMF should already come with USB host controller support.

Re: GNU-EFI No mouse input detected in QEMU-X86-64

Posted: Sat Oct 14, 2023 5:44 am
by koki1019
klange wrote:EDK2 does have a USB HID mouse driver that should provide the simple pointer protocol: https://github.com/tianocore/edk2/tree/ ... sbMouseDxe

You can try to build and install the DXE. OVMF should already come with USB host controller support.
Alright will check it out! :D