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

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
koki1019
Posts: 4
Joined: Thu Oct 12, 2023 1:49 pm

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

Post 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 ...
    }
}
Image
klange
Member
Member
Posts: 679
Joined: Wed Mar 30, 2011 12:31 am
Libera.chat IRC: klange
Discord: klange

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

Post 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.
User avatar
koki1019
Posts: 4
Joined: Thu Oct 12, 2023 1:49 pm

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

Post 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
Image
klange
Member
Member
Posts: 679
Joined: Wed Mar 30, 2011 12:31 am
Libera.chat IRC: klange
Discord: klange

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

Post 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.
User avatar
koki1019
Posts: 4
Joined: Thu Oct 12, 2023 1:49 pm

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

Post 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
Image
Post Reply