VirtualBox

Ticket #2306: VBoxGuest-linux.c.patch

File VBoxGuest-linux.c.patch, 7.7 KB (added by Michael Thayer, 12 years ago)

Patch to make mouse integration work in Fedora 17

  • src/VBox/Additions/common/VBoxGuest/VBoxGuest-linux.c

     
    5858#define DEVICE_NAME             "vboxguest"
    5959/** The device name for the device node open to everyone.. */
    6060#define DEVICE_NAME_USER        "vboxuser"
     61/** The name of the PCI driver */
     62#define DRIVER_NAME             DEVICE_NAME
    6163
    6264
    63 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 20)
    64 # define PCI_DEV_GET(v,d,p)     pci_get_device(v,d,p)
    65 # define PCI_DEV_PUT(x)         pci_dev_put(x)
    66 #else
    67 # define PCI_DEV_GET(v,d,p)     pci_find_device(v,d,p)
    68 # define PCI_DEV_PUT(x)         do {} while(0)
    69 #endif
    70 
    7165/* 2.4.x compatibility macros that may or may not be defined. */
    7266#ifndef IRQ_RETVAL
    7367# define irqreturn_t            void
     
    7872/*******************************************************************************
    7973*   Internal Functions                                                         *
    8074*******************************************************************************/
     75static void vboxguestLinuxTermPci(struct pci_dev *pPciDev);
    8176static int  vboxguestLinuxModInit(void);
    8277static void vboxguestLinuxModExit(void);
    8378static int  vboxguestLinuxOpen(struct inode *pInode, struct file *pFilp);
     
    10095 */
    10196static VBOXGUESTDEVEXT          g_DevExt;
    10297/** The PCI device. */
    103 static struct pci_dev          *g_pPciDev;
     98static struct pci_dev          *g_pPciDev = NULL;
    10499/** The base of the I/O port range. */
    105100static RTIOPORT                 g_IOPortBase;
    106101/** The base of the MMIO range. */
     
    252247 *
    253248 * @returns 0 on success, negated errno on failure.
    254249 */
    255 static int __init vboxguestLinuxInitPci(void)
     250static int vboxguestLinuxProbePci(struct pci_dev *pPciDev,
     251                                  const struct pci_device_id *id)
    256252{
    257     struct pci_dev *pPciDev;
    258253    int             rc;
    259254
    260     pPciDev = PCI_DEV_GET(VMMDEV_VENDORID, VMMDEV_DEVICEID, NULL);
    261     if (pPciDev)
     255    NOREF(id);
     256    AssertReturn(!g_pPciDev, -EINVAL);
     257    rc = pci_enable_device(pPciDev);
     258    if (rc >= 0)
    262259    {
    263         rc = pci_enable_device(pPciDev);
    264         if (rc >= 0)
     260        /* I/O Ports are mandatory, the MMIO bit is not. */
     261        g_IOPortBase = pci_resource_start(pPciDev, 0);
     262        if (g_IOPortBase != 0)
    265263        {
    266             /* I/O Ports are mandatory, the MMIO bit is not. */
    267             g_IOPortBase = pci_resource_start(pPciDev, 0);
    268             if (g_IOPortBase != 0)
     264            /*
     265             * Map the register address space.
     266             */
     267            g_MMIOPhysAddr = pci_resource_start(pPciDev, 1);
     268            g_cbMMIO       = pci_resource_len(pPciDev, 1);
     269            if (request_mem_region(g_MMIOPhysAddr, g_cbMMIO, DEVICE_NAME) != NULL)
    269270            {
    270                 /*
    271                  * Map the register address space.
    272                  */
    273                 g_MMIOPhysAddr = pci_resource_start(pPciDev, 1);
    274                 g_cbMMIO       = pci_resource_len(pPciDev, 1);
    275                 if (request_mem_region(g_MMIOPhysAddr, g_cbMMIO, DEVICE_NAME) != NULL)
     271                g_pvMMIOBase = ioremap(g_MMIOPhysAddr, g_cbMMIO);
     272                if (g_pvMMIOBase)
    276273                {
    277                     g_pvMMIOBase = ioremap(g_MMIOPhysAddr, g_cbMMIO);
    278                     if (g_pvMMIOBase)
    279                     {
    280                         /** @todo why aren't we requesting ownership of the I/O ports as well? */
    281                         g_pPciDev = pPciDev;
    282                         return 0;
    283                     }
    284 
    285                     /* failure cleanup path */
    286                     LogRel((DEVICE_NAME ": ioremap failed; MMIO Addr=%RHp cb=%#x\n", g_MMIOPhysAddr, g_cbMMIO));
    287                     rc = -ENOMEM;
    288                     release_mem_region(g_MMIOPhysAddr, g_cbMMIO);
     274                    /** @todo why aren't we requesting ownership of the I/O ports as well? */
     275                    g_pPciDev = pPciDev;
     276                    return 0;
    289277                }
    290                 else
    291                 {
    292                     LogRel((DEVICE_NAME ": failed to obtain adapter memory\n"));
    293                     rc = -EBUSY;
    294                 }
    295                 g_MMIOPhysAddr = NIL_RTHCPHYS;
    296                 g_cbMMIO       = 0;
    297                 g_IOPortBase   = 0;
     278
     279                /* failure cleanup path */
     280                LogRel((DEVICE_NAME ": ioremap failed; MMIO Addr=%RHp cb=%#x\n", g_MMIOPhysAddr, g_cbMMIO));
     281                rc = -ENOMEM;
     282                release_mem_region(g_MMIOPhysAddr, g_cbMMIO);
    298283            }
    299284            else
    300285            {
    301                 LogRel((DEVICE_NAME ": did not find expected hardware resources\n"));
    302                 rc = -ENXIO;
     286                LogRel((DEVICE_NAME ": failed to obtain adapter memory\n"));
     287                rc = -EBUSY;
    303288            }
    304             pci_disable_device(pPciDev);
     289            g_MMIOPhysAddr = NIL_RTHCPHYS;
     290            g_cbMMIO       = 0;
     291            g_IOPortBase   = 0;
    305292        }
    306293        else
    307             LogRel((DEVICE_NAME ": could not enable device: %d\n", rc));
    308         PCI_DEV_PUT(pPciDev);
     294        {
     295            LogRel((DEVICE_NAME ": did not find expected hardware resources\n"));
     296            rc = -ENXIO;
     297        }
     298        pci_disable_device(pPciDev);
    309299    }
    310300    else
    311     {
    312         printk(KERN_ERR DEVICE_NAME ": VirtualBox Guest PCI device not found.\n");
    313         rc = -ENODEV;
    314     }
     301        LogRel((DEVICE_NAME ": could not enable device: %d\n", rc));
    315302    return rc;
    316303}
    317304
     
    319306/**
    320307 * Clean up the usage of the PCI device.
    321308 */
    322 static void vboxguestLinuxTermPci(void)
     309static void vboxguestLinuxTermPci(struct pci_dev *pPciDev)
    323310{
    324     struct pci_dev *pPciDev = g_pPciDev;
    325311    g_pPciDev = NULL;
    326312    if (pPciDev)
    327313    {
     
    337323}
    338324
    339325
     326/** Structure for registering the PCI driver. */
     327static struct pci_driver  g_PciDriver =
     328{
     329    name:           DRIVER_NAME,
     330    id_table:       g_VBoxGuestPciId,
     331    probe:          vboxguestLinuxProbePci,
     332    remove:         vboxguestLinuxTermPci
     333};
     334
     335
    340336/**
    341337 * Interrupt service routine.
    342338 *
     
    459455    g_pInputDevice->id.version = VBOX_SHORT_VERSION;
    460456    g_pInputDevice->open       = vboxguestOpenInputDevice;
    461457    g_pInputDevice->close      = vboxguestCloseInputDevice;
    462 #if 0  /* The device registration code was not backported */
    463458# if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 22)
    464459    g_pInputDevice->cdev.dev   = &g_pPciDev->dev;
    465460# else
    466461    g_pInputDevice->dev.parent = &g_pPciDev->dev;
    467462# endif
    468 #endif
    469463    {
    470464        int rc = input_register_device(g_pInputDevice);
    471465        if (rc)
     
    609603    /*
    610604     * Locate and initialize the PCI device.
    611605     */
    612     rc = vboxguestLinuxInitPci();
    613     if (rc >= 0)
     606    rc = pci_register_driver(&g_PciDriver);
     607    if (rc >= 0 && g_pPciDev)
    614608    {
    615609        /*
    616610         * Register the interrupt service routine for it.
     
    691685            }
    692686            vboxguestLinuxTermISR();
    693687        }
    694         vboxguestLinuxTermPci();
    695688    }
     689    else
     690    {
     691        LogRel((DEVICE_NAME ": PCI device not found, probably running on physical hardware.\n"));
     692        rc = -ENODEV;
     693    }
     694    pci_unregister_driver(&g_PciDriver);
    696695    RTLogDestroy(RTLogRelSetDefaultInstance(NULL));
    697696    RTLogDestroy(RTLogSetDefaultInstance(NULL));
    698697    RTR0Term();
     
    715714    VBoxGuestCloseSession(&g_DevExt, g_pKernelSession);
    716715    VBoxGuestDeleteDevExt(&g_DevExt);
    717716    vboxguestLinuxTermISR();
    718     vboxguestLinuxTermPci();
     717    pci_unregister_driver(&g_PciDriver);
    719718    RTLogDestroy(RTLogRelSetDefaultInstance(NULL));
    720719    RTLogDestroy(RTLogSetDefaultInstance(NULL));
    721720    RTR0Term();

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