Ticket #2306: VBoxGuest-linux.c.patch
| File VBoxGuest-linux.c.patch, 7.7 KB (added by , 12 years ago) |
|---|
-
src/VBox/Additions/common/VBoxGuest/VBoxGuest-linux.c
58 58 #define DEVICE_NAME "vboxguest" 59 59 /** The device name for the device node open to everyone.. */ 60 60 #define DEVICE_NAME_USER "vboxuser" 61 /** The name of the PCI driver */ 62 #define DRIVER_NAME DEVICE_NAME 61 63 62 64 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 #else67 # define PCI_DEV_GET(v,d,p) pci_find_device(v,d,p)68 # define PCI_DEV_PUT(x) do {} while(0)69 #endif70 71 65 /* 2.4.x compatibility macros that may or may not be defined. */ 72 66 #ifndef IRQ_RETVAL 73 67 # define irqreturn_t void … … 78 72 /******************************************************************************* 79 73 * Internal Functions * 80 74 *******************************************************************************/ 75 static void vboxguestLinuxTermPci(struct pci_dev *pPciDev); 81 76 static int vboxguestLinuxModInit(void); 82 77 static void vboxguestLinuxModExit(void); 83 78 static int vboxguestLinuxOpen(struct inode *pInode, struct file *pFilp); … … 100 95 */ 101 96 static VBOXGUESTDEVEXT g_DevExt; 102 97 /** The PCI device. */ 103 static struct pci_dev *g_pPciDev ;98 static struct pci_dev *g_pPciDev = NULL; 104 99 /** The base of the I/O port range. */ 105 100 static RTIOPORT g_IOPortBase; 106 101 /** The base of the MMIO range. */ … … 252 247 * 253 248 * @returns 0 on success, negated errno on failure. 254 249 */ 255 static int __init vboxguestLinuxInitPci(void) 250 static int vboxguestLinuxProbePci(struct pci_dev *pPciDev, 251 const struct pci_device_id *id) 256 252 { 257 struct pci_dev *pPciDev;258 253 int rc; 259 254 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) 262 259 { 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) 265 263 { 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) 269 270 { 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) 276 273 { 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; 289 277 } 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); 298 283 } 299 284 else 300 285 { 301 LogRel((DEVICE_NAME ": did not find expected hardware resources\n"));302 rc = -E NXIO;286 LogRel((DEVICE_NAME ": failed to obtain adapter memory\n")); 287 rc = -EBUSY; 303 288 } 304 pci_disable_device(pPciDev); 289 g_MMIOPhysAddr = NIL_RTHCPHYS; 290 g_cbMMIO = 0; 291 g_IOPortBase = 0; 305 292 } 306 293 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); 309 299 } 310 300 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)); 315 302 return rc; 316 303 } 317 304 … … 319 306 /** 320 307 * Clean up the usage of the PCI device. 321 308 */ 322 static void vboxguestLinuxTermPci( void)309 static void vboxguestLinuxTermPci(struct pci_dev *pPciDev) 323 310 { 324 struct pci_dev *pPciDev = g_pPciDev;325 311 g_pPciDev = NULL; 326 312 if (pPciDev) 327 313 { … … 337 323 } 338 324 339 325 326 /** Structure for registering the PCI driver. */ 327 static struct pci_driver g_PciDriver = 328 { 329 name: DRIVER_NAME, 330 id_table: g_VBoxGuestPciId, 331 probe: vboxguestLinuxProbePci, 332 remove: vboxguestLinuxTermPci 333 }; 334 335 340 336 /** 341 337 * Interrupt service routine. 342 338 * … … 459 455 g_pInputDevice->id.version = VBOX_SHORT_VERSION; 460 456 g_pInputDevice->open = vboxguestOpenInputDevice; 461 457 g_pInputDevice->close = vboxguestCloseInputDevice; 462 #if 0 /* The device registration code was not backported */463 458 # if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 22) 464 459 g_pInputDevice->cdev.dev = &g_pPciDev->dev; 465 460 # else 466 461 g_pInputDevice->dev.parent = &g_pPciDev->dev; 467 462 # endif 468 #endif469 463 { 470 464 int rc = input_register_device(g_pInputDevice); 471 465 if (rc) … … 609 603 /* 610 604 * Locate and initialize the PCI device. 611 605 */ 612 rc = vboxguestLinuxInitPci();613 if (rc >= 0 )606 rc = pci_register_driver(&g_PciDriver); 607 if (rc >= 0 && g_pPciDev) 614 608 { 615 609 /* 616 610 * Register the interrupt service routine for it. … … 691 685 } 692 686 vboxguestLinuxTermISR(); 693 687 } 694 vboxguestLinuxTermPci();695 688 } 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); 696 695 RTLogDestroy(RTLogRelSetDefaultInstance(NULL)); 697 696 RTLogDestroy(RTLogSetDefaultInstance(NULL)); 698 697 RTR0Term(); … … 715 714 VBoxGuestCloseSession(&g_DevExt, g_pKernelSession); 716 715 VBoxGuestDeleteDevExt(&g_DevExt); 717 716 vboxguestLinuxTermISR(); 718 vboxguestLinuxTermPci();717 pci_unregister_driver(&g_PciDriver); 719 718 RTLogDestroy(RTLogRelSetDefaultInstance(NULL)); 720 719 RTLogDestroy(RTLogSetDefaultInstance(NULL)); 721 720 RTR0Term();

