Changeset 38721 in vbox for trunk/src/VBox
- Timestamp:
- Sep 13, 2011 7:04:13 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuest-linux.c
r38649 r38721 52 52 /** The device name for the device node open to everyone.. */ 53 53 #define DEVICE_NAME_USER "vboxuser" 54 55 56 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 20) 57 # define PCI_DEV_GET(v,d,p) pci_get_device(v,d,p) 58 # define PCI_DEV_PUT(x) pci_dev_put(x) 59 #else 60 # define PCI_DEV_GET(v,d,p) pci_find_device(v,d,p) 61 # define PCI_DEV_PUT(x) do {} while(0) 62 #endif 54 /** The name of the PCI driver */ 55 #define DRIVER_NAME DEVICE_NAME 56 63 57 64 58 /* 2.4.x compatibility macros that may or may not be defined. */ … … 72 66 * Internal Functions * 73 67 *******************************************************************************/ 68 static void vboxguestLinuxTermPci(struct pci_dev *pPciDev); 74 69 static int vboxguestLinuxModInit(void); 75 70 static void vboxguestLinuxModExit(void); … … 94 89 static VBOXGUESTDEVEXT g_DevExt; 95 90 /** The PCI device. */ 96 static struct pci_dev *g_pPciDev ;91 static struct pci_dev *g_pPciDev = NULL; 97 92 /** The base of the I/O port range. */ 98 93 static RTIOPORT g_IOPortBase; … … 244 239 * @returns 0 on success, negated errno on failure. 245 240 */ 246 static int __init vboxguestLinuxInitPci(void)247 { 248 struct pci_dev *pPciDev; 241 static int vboxguestLinuxProbePci(struct pci_dev *pPciDev, 242 const struct pci_device_id *id) 243 { 249 244 int rc; 250 245 251 pPciDev = PCI_DEV_GET(VMMDEV_VENDORID, VMMDEV_DEVICEID, NULL); 252 if (pPciDev) 253 { 254 rc = pci_enable_device(pPciDev); 255 if (rc >= 0) 246 NOREF(id); 247 AssertReturn(!g_pPciDev, -EINVAL); 248 rc = pci_enable_device(pPciDev); 249 if (rc >= 0) 250 { 251 /* I/O Ports are mandatory, the MMIO bit is not. */ 252 g_IOPortBase = pci_resource_start(pPciDev, 0); 253 if (g_IOPortBase != 0) 256 254 { 257 /* I/O Ports are mandatory, the MMIO bit is not. */ 258 g_IOPortBase = pci_resource_start(pPciDev, 0); 259 if (g_IOPortBase != 0) 255 /* 256 * Map the register address space. 257 */ 258 g_MMIOPhysAddr = pci_resource_start(pPciDev, 1); 259 g_cbMMIO = pci_resource_len(pPciDev, 1); 260 if (request_mem_region(g_MMIOPhysAddr, g_cbMMIO, DEVICE_NAME) != NULL) 260 261 { 261 /* 262 * Map the register address space. 263 */ 264 g_MMIOPhysAddr = pci_resource_start(pPciDev, 1); 265 g_cbMMIO = pci_resource_len(pPciDev, 1); 266 if (request_mem_region(g_MMIOPhysAddr, g_cbMMIO, DEVICE_NAME) != NULL) 262 g_pvMMIOBase = ioremap(g_MMIOPhysAddr, g_cbMMIO); 263 if (g_pvMMIOBase) 267 264 { 268 g_pvMMIOBase = ioremap(g_MMIOPhysAddr, g_cbMMIO); 269 if (g_pvMMIOBase) 270 { 271 /** @todo why aren't we requesting ownership of the I/O ports as well? */ 272 g_pPciDev = pPciDev; 273 return 0; 274 } 275 276 /* failure cleanup path */ 277 LogRel((DEVICE_NAME ": ioremap failed; MMIO Addr=%RHp cb=%#x\n", g_MMIOPhysAddr, g_cbMMIO)); 278 rc = -ENOMEM; 279 release_mem_region(g_MMIOPhysAddr, g_cbMMIO); 265 /** @todo why aren't we requesting ownership of the I/O ports as well? */ 266 g_pPciDev = pPciDev; 267 return 0; 280 268 } 281 else 282 { 283 LogRel((DEVICE_NAME ": failed to obtain adapter memory\n")); 284 rc = -EBUSY; 285 } 286 g_MMIOPhysAddr = NIL_RTHCPHYS; 287 g_cbMMIO = 0; 288 g_IOPortBase = 0; 269 270 /* failure cleanup path */ 271 LogRel((DEVICE_NAME ": ioremap failed; MMIO Addr=%RHp cb=%#x\n", g_MMIOPhysAddr, g_cbMMIO)); 272 rc = -ENOMEM; 273 release_mem_region(g_MMIOPhysAddr, g_cbMMIO); 289 274 } 290 275 else 291 276 { 292 LogRel((DEVICE_NAME ": did not find expected hardware resources\n"));293 rc = -E NXIO;277 LogRel((DEVICE_NAME ": failed to obtain adapter memory\n")); 278 rc = -EBUSY; 294 279 } 295 pci_disable_device(pPciDev); 280 g_MMIOPhysAddr = NIL_RTHCPHYS; 281 g_cbMMIO = 0; 282 g_IOPortBase = 0; 296 283 } 297 284 else 298 LogRel((DEVICE_NAME ": could not enable device: %d\n", rc)); 299 PCI_DEV_PUT(pPciDev); 285 { 286 LogRel((DEVICE_NAME ": did not find expected hardware resources\n")); 287 rc = -ENXIO; 288 } 289 pci_disable_device(pPciDev); 300 290 } 301 291 else 302 { 303 printk(KERN_ERR DEVICE_NAME ": VirtualBox Guest PCI device not found.\n"); 304 rc = -ENODEV; 305 } 292 LogRel((DEVICE_NAME ": could not enable device: %d\n", rc)); 306 293 return rc; 307 294 } … … 311 298 * Clean up the usage of the PCI device. 312 299 */ 313 static void vboxguestLinuxTermPci(void) 314 { 315 struct pci_dev *pPciDev = g_pPciDev; 300 static void vboxguestLinuxTermPci(struct pci_dev *pPciDev) 301 { 316 302 g_pPciDev = NULL; 317 303 if (pPciDev) … … 327 313 } 328 314 } 315 316 317 /** Structure for registering the PCI driver. */ 318 static struct pci_driver g_PciDriver = 319 { 320 name: DRIVER_NAME, 321 id_table: g_VBoxGuestPciId, 322 probe: vboxguestLinuxProbePci, 323 remove: vboxguestLinuxTermPci 324 }; 329 325 330 326 … … 453 449 g_pInputDevice->open = vboxguestOpenInputDevice; 454 450 g_pInputDevice->close = vboxguestCloseInputDevice; 455 /** @todo parent (PCI?) device in device model view. */ 456 /* g_pInputDevice->dev.parent = */ 451 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 2) 452 # if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 15) 453 g_pInputDevice->dev->dev = &g_pPciDev->dev; 454 # elif LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 22) 455 g_pInputDevice->cdev.dev = &g_pPciDev->dev; 456 # else 457 g_pInputDevice->dev.parent = &g_pPciDev->dev; 458 #endif 459 #endif 457 460 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 15) 458 461 { … … 613 616 * Locate and initialize the PCI device. 614 617 */ 615 rc = vboxguestLinuxInitPci();616 if (rc >= 0 )618 rc = pci_register_driver(&g_PciDriver); 619 if (rc >= 0 && g_pPciDev) 617 620 { 618 621 /* … … 691 694 vboxguestLinuxTermISR(); 692 695 } 693 vboxguestLinuxTermPci(); 696 pci_unregister_driver(&g_PciDriver); 697 } 698 else 699 { 700 LogRel((DEVICE_NAME ": PCI device registration failed (pci_register_device returned %d)\n", rc)); 701 rc = -EINVAL; 694 702 } 695 703 RTLogDestroy(RTLogRelSetDefaultInstance(NULL)); … … 713 721 VBoxGuestDeleteDevExt(&g_DevExt); 714 722 vboxguestLinuxTermISR(); 715 vboxguestLinuxTermPci();723 pci_unregister_driver(&g_PciDriver); 716 724 RTLogDestroy(RTLogRelSetDefaultInstance(NULL)); 717 725 RTLogDestroy(RTLogSetDefaultInstance(NULL));
Note:
See TracChangeset
for help on using the changeset viewer.