VirtualBox

Changeset 38649 in vbox for trunk/src/VBox/Additions


Ignore:
Timestamp:
Sep 5, 2011 9:57:01 PM (13 years ago)
Author:
vboxsync
Message:

Additions/common: more Linux input driver work

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuest-linux.c

    r38596 r38649  
    138138
    139139/** The input device handle */
     140#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 15)
     141static struct input_dev         g_InputDevice;
     142#endif
    140143static struct input_dev        *g_pInputDevice = NULL;
    141144/** Is the input device registered? */
     
    391394
    392395
     396/** Calls the kernel IOCtl to report mouse status to the host on behalf of
     397 * our kernel session. */
    393398static int vboxguestLinuxSetMouseStatus(uint32_t fStatus)
    394399{
     
    399404
    400405
     406/** Called when the input device is first opened.  Sets up absolute reporting.
     407 */
     408static int vboxguestOpenInputDevice(struct input_dev *pDev)
     409{
     410    NOREF(pDev);
     411    if (RT_FAILURE(vboxguestLinuxSetMouseStatus
     412                                   (  VMMDEV_MOUSE_GUEST_CAN_ABSOLUTE
     413                                    | VMMDEV_MOUSE_NEW_PROTOCOL)))
     414        return ENODEV;
     415    return 0;
     416}
     417
     418
     419/** Called if all open handles to the device are closed, disables absolute
     420 * reporting. */
     421static void vboxguestCloseInputDevice(struct input_dev *pDev)
     422{
     423    NOREF(pDev);
     424    vboxguestLinuxSetMouseStatus(0);
     425}
     426
     427
    401428/**
    402429 * Creates the kernel input device.
     
    404431static int __init vboxguestLinuxCreateInputDevice(void)
    405432{
    406     int rc;
    407 
     433#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 29)
     434# define INPUT_DEV_ID(val) id.val
     435#else
     436# define INPUT_DEV_ID(val) id##val
     437#endif
     438
     439#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 15)
    408440    g_pInputDevice = input_allocate_device();
    409441    if (!g_pInputDevice)
    410442        return -ENOMEM;
    411     g_pInputDevice->id.bustype = BUS_PCI;
    412     g_pInputDevice->id.vendor  = VMMDEV_VENDORID;
    413     g_pInputDevice->id.product = VMMDEV_DEVICEID;
    414     g_pInputDevice->id.version =   (VBOX_VERSION_MAJOR << 11)
    415                                  + (VBOX_VERSION_MINOR << 6)
    416                                  + VBOX_VERSION_BUILD;  /** @todo */
     443    g_pInputDevice->INPUT_DEV_ID(bustype) = BUS_PCI;
     444#else
     445    g_pInputDevice = &g_InputDevice;
     446    g_pInputDevice->INPUT_DEV_ID(bus)     = BUS_PCI;
     447#endif
     448    g_pInputDevice->INPUT_DEV_ID(vendor)  = VMMDEV_VENDORID;
     449    g_pInputDevice->INPUT_DEV_ID(product) = VMMDEV_DEVICEID;
     450    g_pInputDevice->INPUT_DEV_ID(version) =   (VBOX_VERSION_MAJOR << 11)
     451                                            + (VBOX_VERSION_MINOR << 6)
     452                                            + VBOX_VERSION_BUILD;  /** @todo */
     453    g_pInputDevice->open                  = vboxguestOpenInputDevice;
     454    g_pInputDevice->close                 = vboxguestCloseInputDevice;
    417455    /** @todo parent (PCI?) device in device model view. */
    418456    /* g_pInputDevice->dev.parent = */
    419     rc = input_register_device(g_pInputDevice);
    420     if (!rc)
    421         g_fInputDeviceRegistered = true;
    422     else
    423         return rc;
     457#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 15)
     458    {
     459        int rc = input_register_device(g_pInputDevice);
     460        if (rc)
     461        {
     462            input_free_device(g_pInputDevice);
     463            return rc;
     464        }
     465    }
     466#else
     467    input_register_device(g_pInputDevice);
     468#endif
    424469    /* Do what one of our competitors apparently does as that works. */
    425     g_pInputDevice->evbit[0] = RT_BIT(EV_ABS) | RT_BIT(EV_KEY);
    426     __set_bit(BTN_MOUSE, g_pInputDevice->keybit);
     470    ASMBitSet(g_pInputDevice->evbit, EV_ABS);
     471    ASMBitSet(g_pInputDevice->evbit, EV_KEY);
     472#ifdef EV_SYN
     473    ASMBitSet(g_pInputDevice->evbit, EV_SYN);
     474#endif
     475#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 7)
    427476    input_set_abs_params(g_pInputDevice, ABS_X, RANGE_MIN, RANGE_MAX, 0, 0);
    428477    input_set_abs_params(g_pInputDevice, ABS_Y, RANGE_MIN, RANGE_MAX, 0, 0);
     478#else
     479    ASMBitSet(g_pInputDevice->absbit, ABS_X);
     480    ASMBitSet(g_pInputDevice->absbit, ABS_Y);
     481    ASMBitSet(g_pInputDevice->keybit, BTN_MOUSE);
     482    g_pInputDevice->absmin[ABS_X] = g_pInputDevice->absmin[ABS_Y] = RANGE_MIN;
     483    g_pInputDevice->absmax[ABS_X] = g_pInputDevice->absmax[ABS_Y] = RANGE_MAX;
     484#endif
    429485    /** @todo this string should be in a header file somewhere. */
    430486    g_pInputDevice->name = "VirtualBox mouse integration";
    431     vboxguestLinuxSetMouseStatus(  VMMDEV_MOUSE_GUEST_CAN_ABSOLUTE
    432                                  | VMMDEV_MOUSE_NEW_PROTOCOL);
    433     return rc;
     487    return 0;
     488#undef INPUT_DEV_ID
    434489}
    435490
     
    440495static void vboxguestLinuxTermInputDevice(void)
    441496{
    442     vboxguestLinuxSetMouseStatus(0);
    443     if (g_fInputDeviceRegistered)
     497    if (g_pInputDevice)
    444498    {
    445499        input_unregister_device(g_pInputDevice);
    446         g_fInputDeviceRegistered = false;
    447     }
    448     if (g_pInputDevice)
    449     {
     500#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 15)
    450501        input_free_device(g_pInputDevice);
     502#endif
    451503        g_pInputDevice = NULL;
    452504    }
     
    900952        input_report_abs(g_pInputDevice, ABS_X, pReq->pointerXPos);
    901953        input_report_abs(g_pInputDevice, ABS_Y, pReq->pointerYPos);
     954#ifdef EV_SYN
     955        input_sync(g_pInputDevice);
     956#endif
    902957        VbglGRFree(&pReq->header);
    903958    }
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette