OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Apr 19, 2024 5:28 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: GNU-EFI No mouse input detected in QEMU-X86-64
PostPosted: Fri Oct 13, 2023 5:11 pm 
Offline
User avatar

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


Top
 Profile  
 
 Post subject: Re: GNU-EFI No mouse input detected in QEMU-X86-64
PostPosted: Sat Oct 14, 2023 5:14 am 
Offline
Member
Member

Joined: Wed Mar 30, 2011 12:31 am
Posts: 676
OVMF doesn't have mouse drivers.

Quote:
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.

_________________
toaruos on github | toaruos.org | gitlab | twitter | bim - a text editor


Top
 Profile  
 
 Post subject: Re: GNU-EFI No mouse input detected in QEMU-X86-64
PostPosted: Sat Oct 14, 2023 5:15 am 
Offline
User avatar

Joined: Thu Oct 12, 2023 1:49 pm
Posts: 4
klange wrote:
OVMF doesn't have mouse drivers.

Quote:
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


Top
 Profile  
 
 Post subject: Re: GNU-EFI No mouse input detected in QEMU-X86-64
PostPosted: Sat Oct 14, 2023 5:32 am 
Offline
Member
Member

Joined: Wed Mar 30, 2011 12:31 am
Posts: 676
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.

_________________
toaruos on github | toaruos.org | gitlab | twitter | bim - a text editor


Top
 Profile  
 
 Post subject: Re: GNU-EFI No mouse input detected in QEMU-X86-64
PostPosted: Sat Oct 14, 2023 5:44 am 
Offline
User avatar

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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 161 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group