VirtualBox

Changeset 21095 in vbox for trunk


Ignore:
Timestamp:
Jun 30, 2009 6:54:01 PM (16 years ago)
Author:
vboxsync
Message:

VBoxGuest (common): mouse polling.

Location:
trunk/src/VBox/Additions/common/VBoxGuest
Files:
3 edited

Legend:

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

    r21069 r21095  
    4141#include "the-linux-kernel.h"
    4242#include <linux/miscdevice.h>
     43#include <linux/poll.h>
    4344#include "version-generated.h"
    4445
    4546#include <iprt/assert.h>
     47#include <iprt/asm.h>
     48#include <iprt/err.h>
     49#include <iprt/initterm.h>
     50#include <iprt/mem.h>
     51#include <iprt/mp.h>
     52#include <iprt/process.h>
    4653#include <iprt/spinlock.h>
    4754#include <iprt/semaphore.h>
    48 #include <iprt/initterm.h>
    49 #include <iprt/process.h>
    50 #include <iprt/err.h>
    51 #include <iprt/mem.h>
    5255#include <VBox/log.h>
    53 #include <iprt/mp.h>
    54 #include <iprt/mem.h>
    55 
    56 
    57 #define xstr(s) str(s)
    58 #define str(s) #s
    59 
     56
     57
     58/*******************************************************************************
     59*   Defined Constants And Macros                                               *
     60*******************************************************************************/
    6061/** The device name. */
    6162#define DEVICE_NAME             "vboxguest"
     
    9192static int  vboxguestLinuxIOCtl(struct inode *pInode, struct file *pFilp, unsigned int uCmd, unsigned long ulArg);
    9293#endif
     94static int  vboxguestFAsync(int fd, struct file *pFile, int fOn);
     95static unsigned int vboxguestPoll(struct file *pFile, poll_table *pPt);
     96static ssize_t vboxguestRead(struct file *pFile, char *pbBuf, size_t cbRead, loff_t *poff);
    9397
    9498
     
    110114/** The pointer to the mapping of the MMIO range. */
    111115static void                    *g_pvMMIOBase;
     116/** Wait queue used by polling. */
     117static wait_queue_head_t        g_PollEventQueue;
     118/** Asynchronous notification stuff.  */
     119static struct fasync_struct    *g_pFAsyncQueue;
    112120
    113121/** Our file node major id.
     
    118126static unsigned int             g_iModuleMajor = 0;
    119127#endif
    120 
    121128
    122129/** The file_operations structure. */
     
    131138    ioctl:          vboxguestLinuxIOCtl,
    132139#endif
     140    read:           vboxguestRead,
     141    poll:           vboxguestPoll,
     142    fasync:         vboxguestFAsync,
    133143};
    134144
     
    442452    if (RT_FAILURE(rc))
    443453    {
    444         Log((DEVICE_NAME ": RTR0Init failed.\n"));
     454        printk(KERN_ERR DEVICE_NAME ": RTR0Init failed, rc=%d.\n", rc);
    445455        return -EINVAL;
    446456    }
     
    487497                {
    488498                    /* some useful information for the user but don't show this on the console */
    489                     LogRel(("VirtualBox device settings: major %d, IRQ %d, I/O port 0x%x, MMIO at 0x%x (size 0x%x)\n",
     499                    LogRel((DEVICE_NAME ": major %d, IRQ %d, I/O port 0x%x, MMIO at 0x%x (size 0x%x)\n",
    490500                            g_iModuleMajor, g_pPciDev->irq, g_IOPortBase, g_MMIOPhysAddr, g_cbMMIO));
    491501                    printk(KERN_DEBUG DEVICE_NAME ": Successfully loaded version "
    492                             VBOX_VERSION_STRING " (interface " xstr(VMMDEV_VERSION) ")\n");
     502                            VBOX_VERSION_STRING " (interface " RT_XSTR(VMMDEV_VERSION) ")\n");
    493503                    return rc;
    494504                }
     
    499509            else
    500510            {
    501                 LogRel(( DEVICE_NAME ": VBoxGuestInitDevExt failed with rc=%Rrc\n", rc));
     511                LogRel((DEVICE_NAME ": VBoxGuestInitDevExt failed with rc=%Rrc\n", rc));
    502512                rc = RTErrConvertFromErrno(rc);
    503513            }
     
    657667}
    658668
     669
     670/**
     671 * Poll function.
     672 *
     673 * This returns ready to read if the mouse pointer mode or the pointer position
     674 * has changed since last call to read.
     675 *
     676 * @returns 0 if no changes, POLLIN | POLLRDNORM if there are unseen changes.
     677 *
     678 * @param   pFile       The file structure.
     679 * @param   pPt         The poll table.
     680 */
     681static unsigned int vboxguestPoll(struct file *pFile, poll_table *pPt)
     682{
     683    PVBOXGUESTSESSION   pSession  = (PVBOXGUESTSESSION)pFile->private_data;
     684    uint32_t            u32CurSeq = ASMAtomicUoReadU32(&g_DevExt.u32MousePosChangedSeq);
     685    unsigned int        fMask     = pSession->u32MousePosChangedSeq != u32CurSeq
     686                                  ? POLLIN | POLLRDNORM
     687                                  : 0;
     688#if 1 /** @todo this isn't quite right... but it's what we used to do. */
     689    pSession->u32MousePosChangedSeq = u32CurSeq;
     690#endif
     691    poll_wait(pFile, &g_PollEventQueue, pPt);
     692    return fMask;
     693}
     694
     695
     696/**
     697 * Asynchronous notification activation method.
     698 *
     699 * @returns 0 on success, negative errno on failure.
     700 *
     701 * @param   fd          The file descriptor.
     702 * @param   pFile       The file structure.
     703 * @param   fOn         On/off indicator.
     704 */
     705static int vboxguestFAsync(int fd, struct file *pFile, int fOn)
     706{
     707    return fasync_helper(fd, pFile, fOn, &g_pFAsyncQueue);
     708}
     709
     710
     711/**
     712 * Read to go with our poll/fasync response.
     713 *
     714 * @returns 1 or -EINVAL.
     715 *
     716 * @param   pFile       The file structure.
     717 * @param   pbBuf       The buffer to read into.
     718 * @param   cbRead      The max number of bytes to read.
     719 * @param   poff        The current file position.
     720 */
     721static ssize_t vboxguestRead(struct file *pFile, char *pbBuf, size_t cbRead, loff_t *poff)
     722{
     723    if (*poff != 0)
     724        return -EINVAL;
     725
     726    if (cbRead > 0)
     727    {
     728        /* Indicate that we're up to speed. */
     729        PVBOXGUESTSESSION   pSession    = (PVBOXGUESTSESSION)pFile->private_data;
     730        uint32_t            u32CurSeq   = ASMAtomicUoReadU32(&g_DevExt.u32MousePosChangedSeq);
     731        pSession->u32MousePosChangedSeq = u32CurSeq;
     732
     733        pbBuf[0] = 0;
     734        return 1;
     735    }
     736
     737#if 1 /** @todo This is wrong, see man 2 read. Does it server any purpose? */
     738    return -EINVAL;
     739#else
     740    return 0;
     741#endif
     742}
     743
     744
     745void VBoxGuestNativeISRMousePollEvent(PVBOXGUESTDEVEXT pDevExt)
     746{
     747    NOREF(pDevExt);
     748
     749    /*
     750     * Wake up everyone that's in a poll() and post anyone that has
     751     * subscribed to async notifications.
     752     */
     753    wake_up_all(&g_PollEventQueue);
     754    kill_fasync(&g_pFAsyncQueue, SIGIO, POLL_IN);
     755}
     756
     757
    659758/* Common code that depend on g_DevExt. */
    660759#include "VBoxGuestIDC-unix.c.h"
     
    671770MODULE_LICENSE("GPL");
    672771#ifdef MODULE_VERSION
    673 MODULE_VERSION(VBOX_VERSION_STRING " (" xstr(SUPDRV_IOC_VERSION) ")");
    674 #endif
    675 
     772MODULE_VERSION(VBOX_VERSION_STRING " (" RT_XSTR(SUPDRV_IOC_VERSION) ")");
     773#endif
     774
  • trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuest.cpp

    r21071 r21095  
    11/* $Id$ */
    22/** @file
    3  * VBoxGuest - Guest Additions Driver.
     3 * VBoxGuest - Guest Additions Driver, Common Code.
    44 */
    55
    66/*
    7  * Copyright (C) 2007 Sun Microsystems, Inc.
     7 * Copyright (C) 2007-2009 Sun Microsystems, Inc.
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    14111411            RTSpinlockAcquireNoInts(pDevExt->WaitSpinlock, &Tmp);
    14121412
     1413            /** @todo This looks wrong: Seems like VMMDEV_EVENT_HGCM will always be set in
     1414             *        f32PendingEvents... */
    14131415#ifdef VBOX_WITH_HGCM
    14141416            /* The HGCM event/list is kind of different in that we evaluate all entries. */
     
    14231425#endif
    14241426
     1427            /* VMMDEV_EVENT_MOUSE_POSITION_CHANGED can only be polled for. */
     1428#if defined(RT_OS_LINUX)
     1429            if (fEvents & VMMDEV_EVENT_MOUSE_POSITION_CHANGED)
     1430            {
     1431                pDevExt->u32MousePosChangedSeq++;
     1432                VBoxGuestNativeISRMousePollEvent(pDevExt);
     1433            }
     1434#endif
     1435            fEvents &= ~VMMDEV_EVENT_MOUSE_POSITION_CHANGED;
     1436
    14251437            /* Normal FIFO evaluation. */
    14261438            fEvents |= pDevExt->f32PendingEvents;
  • trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuestInternal.h

    r21069 r21095  
    9797    /** Mask of pending events. */
    9898    uint32_t volatile           f32PendingEvents;
     99    /** Current VMMDEV_EVENT_MOUSE_POSITION_CHANGED sequence number.
     100     * Used to implement polling.  */
     101    uint32_t volatile           u32MousePosChangedSeq;
    99102
    100103    /** Spinlock various items in the VBOXGUESTSESSION. */
     
    144147    uint32_t volatile           aHGCMClientIds[8];
    145148#endif
     149
     150    /** The last consumed VMMDEV_EVENT_MOUSE_POSITION_CHANGED sequence number.
     151     * Used to implement polling.  */
     152    uint32_t volatile           u32MousePosChangedSeq;
    146153} VBOXGUESTSESSION;
    147154
     
    170177#endif
    171178
     179/**
     180 * ISR callback for notifying threads polling for mouse events.
     181 *
     182 * @param   pDevExt     The device extension.
     183 */
     184void VBoxGuestNativeISRMousePollEvent(PVBOXGUESTDEVEXT pDevExt);
     185
    172186RT_C_DECLS_END
    173187
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