- Timestamp:
- Apr 19, 2008 8:27:39 PM (17 years ago)
- Location:
- trunk/src/VBox/Additions
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuest-freebsd.c
r8155 r8188 49 49 #include <iprt/process.h> 50 50 #include <iprt/mem.h> 51 #include <iprt/asm.h> 51 52 52 53 /** The module name. */ 53 #define DEVICE_NAME 54 #define DEVICE_NAME "vboxguest" 54 55 55 56 struct VBoxGuestDeviceState 56 57 { 57 58 /** file node minor code */ 58 unsigned minor; 59 /** first IO port */ 60 int io_port_resid; 61 struct resource *io_port; 62 bus_space_tag_t io_port_tag; 63 bus_space_handle_t io_port_handle; 64 /** IO Port. */ 59 unsigned uMinor; 60 /** Resource ID of the I/O port */ 61 int iIOPortResId; 62 /** Pointer to the I/O port resource. */ 63 struct resource *pIOPortRes; 64 /** Start address of the IO Port. */ 65 65 uint16_t uIOPortBase; 66 /** device memory resources*/67 int vmmdevmem_resid;68 struct resource *vmmdevmem;69 bus_space_tag_t vmmdevmem_tag;70 bus_space_handle_t vmmdevmem_handle;71 bus_s ize_t vmmdevmem_size;72 /** physical address of adapter memory*/73 uint32_t vmmdevmem_addr;66 /** Resource ID of the MMIO area */ 67 int iVMMDevMemResId; 68 /** Pointer to the MMIO resource. */ 69 struct resource *pVMMDevMemRes; 70 /** Handle of the MMIO resource. */ 71 bus_space_handle_t VMMDevMemHandle; 72 /** Size of the memory area. */ 73 bus_size_t VMMDevMemSize; 74 74 /** Mapping of the register space */ 75 75 void *pMMIOBase; 76 76 /** IRQ number */ 77 int irq_resid; 78 struct resource *irq; 79 void *irq_handler; 77 int iIrqResId; 78 /** IRQ resource handle. */ 79 struct resource *pIrqRes; 80 /** Pointer to the IRQ handler. */ 81 void *pfnIrqHandler; 80 82 /** VMMDev version */ 81 83 uint32_t u32Version; … … 84 86 static MALLOC_DEFINE(M_VBOXDEV, "vboxdev_pci", "VirtualBox Guest driver PCI"); 85 87 86 #if FreeBSD >= 700 87 static int VBoxGuestFreeBSDOpen(struct cdev *dev, int flags, int fmt, struct thread *td, struct file *pFd); 88 #else 89 static int VBoxGuestFreeBSDOpen(struct cdev *dev, int flags, int fmt, struct thread *td); 90 #endif 91 static int VBoxGuestFreeBSDClose(struct cdev *dev, int flags, int fmt, struct thread *td); 92 static int VBoxGuestFreeBSDIOCtl(struct cdev *dev, u_long cmd, caddr_t data, 93 int fflag, struct thread *td); 94 static ssize_t VBoxGuestFreeBSDWrite (struct cdev *dev, struct uio *uio, int ioflag); 95 static ssize_t VBoxGuestFreeBSDRead (struct cdev *dev, struct uio *uio, int ioflag); 96 static void VBoxGuestFreeBSDRemoveIRQ(device_t self, void *pvState); 97 static int VBoxGuestFreeBSDAddIRQ(device_t self, void *pvState); 98 int VBoxGuestFreeBSDISR(void *pvState); 99 DECLVBGL(int) VBoxGuestFreeBSDServiceCall(void *pvSession, unsigned iCmd, void *pvData, size_t cbData, size_t *pcbDataReturned); 88 /* 89 * Character device file handlers. 90 */ 91 static d_fdopen_t VBoxGuestFreeBSDOpen; 92 static d_close_t VBoxGuestFreeBSDClose; 93 static d_ioctl_t VBoxGuestFreeBSDIOCtl; 94 static d_write_t VBoxGuestFreeBSDWrite; 95 static d_read_t VBoxGuestFreeBSDRead; 96 97 /* 98 * IRQ related functions. 99 */ 100 static void VBoxGuestFreeBSDRemoveIRQ(device_t pDevice, void *pvState); 101 static int VBoxGuestFreeBSDAddIRQ(device_t pDevice, void *pvState); 102 static int VBoxGuestFreeBSDISR(void *pvState); 103 104 /* 105 * Available functions for kernel drivers. 106 */ 107 DECLVBGL(int) VBoxGuestFreeBSDServiceCall(void *pvSession, unsigned uCmd, void *pvData, size_t cbData, size_t *pcbDataReturned); 100 108 DECLVBGL(void *) VBoxGuestFreeBSDServiceOpen(uint32_t *pu32Version); 101 DECLVBGL(int) VBoxGuestFreeBSDServiceClose(void *pvSession);109 DECLVBGL(int) VBoxGuestFreeBSDServiceClose(void *pvSession); 102 110 103 111 /* 104 112 * Device node entry points. 105 113 */ 106 static struct cdevsw g_VBox AddFreeBSDChrDevSW =114 static struct cdevsw g_VBoxGuestFreeBSDChrDevSW = 107 115 { 108 116 .d_version = D_VERSION, 109 117 .d_flags = D_TRACKCLOSE, 110 .d_ open =VBoxGuestFreeBSDOpen,118 .d_fdopen = VBoxGuestFreeBSDOpen, 111 119 .d_close = VBoxGuestFreeBSDClose, 112 120 .d_ioctl = VBoxGuestFreeBSDIOCtl, … … 116 124 }; 117 125 118 /** The make_dev result. */119 static struct cdev *g_pVBoxAddFreeBSDChrDev;120 126 /** Device extention & session data association structure. */ 121 127 static VBOXGUESTDEVEXT g_DevExt; 122 /** Spinlock protecting g_apSessionHashTab. */ 123 static RTSPINLOCK g_Spinlock = NIL_RTSPINLOCK; 124 /** Hash table */ 125 static PVBOXGUESTSESSION g_apSessionHashTab[19]; 126 /** Calculates the index into g_apSessionHashTab.*/ 127 #define SESSION_HASH(sfn) ((sfn) % RT_ELEMENTS(g_apSessionHashTab)) 128 129 /** @todo r=bird: fork() and session hash table didn't work well for solaris, so I doubt it works for 130 * FreeBSD... A different solution is needed unless the current can be improved. */ 128 /** List of cloned device. Managed by the kernel. */ 129 static struct clonedevs *g_pVBoxGuestFreeBSDClones; 130 /** The dev_clone event handler tag. */ 131 static eventhandler_tag g_VBoxGuestFreeBSDEHTag; 131 132 132 133 /** … … 135 136 * @returns VBox error code. 136 137 * @param pvSession Opaque pointer to the session. 137 * @param iCmd Requested function.138 * @param uCmd Requested function. 138 139 * @param pvData IO data buffer. 139 140 * @param cbData Size of the data buffer. 140 141 * @param pcbDataReturned Where to store the amount of returned data. 141 142 */ 142 DECLVBGL(int) VBoxGuestFreeBSDServiceCall(void *pvSession, unsigned iCmd, void *pvData, size_t cbData, size_t *pcbDataReturned)143 { 144 LogFlow((DEVICE_NAME ":VBoxGuest SolarisServiceCall %pvSesssion=%p Cmd=%u pvData=%p cbData=%d\n", pvSession, iCmd, pvData, cbData));143 DECLVBGL(int) VBoxGuestFreeBSDServiceCall(void *pvSession, unsigned uCmd, void *pvData, size_t cbData, size_t *pcbDataReturned) 144 { 145 LogFlow((DEVICE_NAME ":VBoxGuestFreeBSDServiceCall %pvSesssion=%p uCmd=%u pvData=%p cbData=%d\n", pvSession, uCmd, pvData, cbData)); 145 146 146 147 PVBOXGUESTSESSION pSession = (PVBOXGUESTSESSION)pvSession; … … 149 150 ("SC: %p != %p\n", pSession->pDevExt, &g_DevExt), VERR_INVALID_HANDLE); 150 151 151 return VBoxGuestCommonIOCtl( iCmd, &g_DevExt, pSession, pvData, cbData, pcbDataReturned);152 return VBoxGuestCommonIOCtl(uCmd, &g_DevExt, pSession, pvData, cbData, pcbDataReturned); 152 153 } 153 154 … … 161 162 DECLVBGL(void *) VBoxGuestFreeBSDServiceOpen(uint32_t *pu32Version) 162 163 { 163 LogFlow((DEVICE_NAME ":VBoxGuest SolarisServiceOpen\n"));164 LogFlow((DEVICE_NAME ":VBoxGuestFreeBSDServiceOpen\n")); 164 165 165 166 AssertPtrReturn(pu32Version, NULL); … … 184 185 DECLVBGL(int) VBoxGuestFreeBSDServiceClose(void *pvSession) 185 186 { 186 LogFlow((DEVICE_NAME ":VBoxGuest SolarisServiceClose\n"));187 LogFlow((DEVICE_NAME ":VBoxGuestFreeBSDServiceClose\n")); 187 188 188 189 PVBOXGUESTSESSION pSession = (PVBOXGUESTSESSION)pvSession; … … 198 199 199 200 /** 201 * DEVFS event handler. 202 */ 203 static void VBoxGuestFreeBSDClone(void *pvArg, struct ucred *pCred, char *pszName, int cchName, struct cdev **ppDev) 204 { 205 int iUnit; 206 int rc; 207 208 Log(("VBoxGuestFreeBSDClone: pszName=%s ppDev=%p\n", pszName, ppDev)); 209 210 /* 211 * One device node per user, si_drv1 points to the session. 212 * /dev/vboxguest<N> where N = {0...255}. 213 */ 214 if (!ppDev) 215 return; 216 if (dev_stdclone(pszName, NULL, "vboxguest", &iUnit) != 1) 217 return; 218 if (iUnit >= 256 || iUnit < 0) 219 { 220 Log(("VBoxGuestFreeBSDClone: iUnit=%d >= 256 - rejected\n", iUnit)); 221 return; 222 } 223 224 Log(("VBoxGuestFreeBSDClone: pszName=%s iUnit=%d\n", pszName, iUnit)); 225 226 rc = clone_create(&g_pVBoxGuestFreeBSDClones, &g_VBoxGuestFreeBSDChrDevSW, &iUnit, ppDev, 0); 227 Log(("VBoxGuestFreeBSDClone: clone_create -> %d; iUnit=%d\n", rc, iUnit)); 228 if (rc) 229 { 230 *ppDev = make_dev(&g_VBoxGuestFreeBSDChrDevSW, 231 unit2minor(iUnit), 232 UID_ROOT, 233 GID_WHEEL, 234 0644, 235 "vboxguest%d", iUnit); 236 if (*ppDev) 237 { 238 dev_ref(*ppDev); 239 (*ppDev)->si_flags |= SI_CHEAPCLONE; 240 Log(("VBoxGuestFreeBSDClone: Created *ppDev=%p iUnit=%d si_drv1=%p si_drv2=%p\n", 241 *ppDev, iUnit, (*ppDev)->si_drv1, (*ppDev)->si_drv2)); 242 (*ppDev)->si_drv1 = (*ppDev)->si_drv2 = NULL; 243 } 244 else 245 Log(("VBoxGuestFreeBSDClone: make_dev iUnit=%d failed\n", iUnit)); 246 } 247 else 248 Log(("VBoxGuestFreeBSDClone: Existing *ppDev=%p iUnit=%d si_drv1=%p si_drv2=%p\n", 249 *ppDev, iUnit, (*ppDev)->si_drv1, (*ppDev)->si_drv2)); 250 } 251 252 /** 200 253 * File open handler 201 254 * 202 255 */ 203 #if FreeBSD >= 700204 static int VBoxGuestFreeBSDOpen(struct cdev * dev, int flags, int fmt, struct thread *td, struct file *pFd)256 #if __FreeBSD_version >= 700000 257 static int VBoxGuestFreeBSDOpen(struct cdev *pDev, int fOpen, struct thread *pTd, struct file *pFd) 205 258 #else 206 static int VBoxGuestFreeBSDOpen(struct cdev * dev, int flags, int fmt, struct thread *td)259 static int VBoxGuestFreeBSDOpen(struct cdev *pDev, int fOpen, struct thread *pTd) 207 260 #endif 208 261 { … … 213 266 214 267 /* 268 * Try grab it (we don't grab the giant, remember). 269 */ 270 if (!ASMAtomicCmpXchgPtr(&pDev->si_drv1, (void *)0x42, NULL)) 271 return EBUSY; 272 273 /* 215 274 * Create a new session. 216 275 */ … … 218 277 if (RT_SUCCESS(rc)) 219 278 { 220 /* 221 * Insert it into the hash table. 222 */ 223 unsigned iHash = SESSION_HASH(pSession->Process); 224 RTSPINLOCKTMP Tmp = RTSPINLOCKTMP_INITIALIZER; 225 RTSpinlockAcquireNoInts(g_Spinlock, &Tmp); 226 pSession->pNextHash = g_apSessionHashTab[iHash]; 227 g_apSessionHashTab[iHash] = pSession; 228 RTSpinlockReleaseNoInts(g_Spinlock, &Tmp); 229 230 Log((DEVICE_NAME ":VBoxGuestFreeBSDOpen success: g_DevExt=%p pSession=%p rc=%d pid=%d\n", &g_DevExt, pSession, rc, (int)RTProcSelf())); 231 return 0; 232 } 233 234 LogRel((DEVICE_NAME ":VBoxGuestFreeBSDOpen: VBoxGuestCreateUserSession failed. rc=%d\n", rc)); 235 return EFAULT; 279 if (ASMAtomicCmpXchgPtr(&pDev->si_drv1, pSession, (void *)0x42)) 280 { 281 Log((DEVICE_NAME ":VBoxGuestFreeBSDOpen success: g_DevExt=%p pSession=%p rc=%d pid=%d\n", &g_DevExt, pSession, rc, (int)RTProcSelf())); 282 return 0; 283 } 284 285 VBoxGuestCloseSession(&g_DevExt, pSession); 286 } 287 288 LogRel((DEVICE_NAME ":VBoxGuestFreeBSDOpen: failed. rc=%d\n", rc)); 289 return RTErrConvertToErrno(rc); 236 290 } 237 291 … … 240 294 * 241 295 */ 242 static int VBoxGuestFreeBSDClose(struct cdev *dev, int flags, int fmt, struct thread *td) 243 { 244 LogFlow((DEVICE_NAME ":VBoxGuestFreeBSDClose pid=%d\n", (int)RTProcSelf())); 245 246 /* 247 * Remove from the hash table. 248 */ 249 PVBOXGUESTSESSION pSession; 250 const RTPROCESS Process = RTProcSelf(); 251 const unsigned iHash = SESSION_HASH(Process); 252 RTSPINLOCKTMP Tmp = RTSPINLOCKTMP_INITIALIZER; 253 RTSpinlockAcquireNoInts(g_Spinlock, &Tmp); 254 255 pSession = g_apSessionHashTab[iHash]; 256 if (pSession) 257 { 258 if (pSession->Process == Process) 259 { 260 g_apSessionHashTab[iHash] = pSession->pNextHash; 261 pSession->pNextHash = NULL; 262 } 263 else 264 { 265 PVBOXGUESTSESSION pPrev = pSession; 266 pSession = pSession->pNextHash; 267 while (pSession) 268 { 269 if (pSession->Process == Process) 270 { 271 pPrev->pNextHash = pSession->pNextHash; 272 pSession->pNextHash = NULL; 273 break; 274 } 275 276 /* next */ 277 pPrev = pSession; 278 pSession = pSession->pNextHash; 279 } 280 } 281 } 282 RTSpinlockReleaseNoInts(g_Spinlock, &Tmp); 283 if (!pSession) 284 { 285 Log((DEVICE_NAME ":VBoxGuestFreeBSDClose: WHUT?!? pSession == NULL! This must be a mistake... pid=%d", (int)Process)); 286 return EFAULT; 287 } 288 Log((DEVICE_NAME ":VBoxGuestFreeBSDClose: pid=%d\n", (int)Process)); 289 290 /* 291 * Close the session. 292 */ 293 VBoxGuestCloseSession(&g_DevExt, pSession); 296 static int VBoxGuestFreeBSDClose(struct cdev *pDev, int fFile, int DevType, struct thread *pTd) 297 { 298 PVBOXGUESTSESSION pSession = (PVBOXGUESTSESSION)pDev->si_drv1; 299 Log(("VBoxGuestFreeBSDClose: fFile=%#x iUnit=%d pSession=%p\n", fFile, minor2unit(minor(pDev)), pSession)); 300 301 /* 302 * Close the session if it's still hanging on to the device... 303 */ 304 if (VALID_PTR(pSession)) 305 { 306 VBoxGuestCloseSession(&g_DevExt, pSession); 307 if (!ASMAtomicCmpXchgPtr(&pDev->si_drv1, NULL, pSession)) 308 Log(("VBoxGuestFreeBSDClose: si_drv1=%p expected %p!\n", pDev->si_drv1, pSession)); 309 } 310 else 311 Log(("VBoxGuestFreeBSDClose: si_drv1=%p!\n", pSession)); 294 312 return 0; 295 313 } … … 299 317 * 300 318 */ 301 static int VBoxGuestFreeBSDIOCtl(struct cdev *dev, u_long cmd, caddr_t data, 302 int fflag, struct thread *td) 319 static int VBoxGuestFreeBSDIOCtl(struct cdev *pDev, u_long ulCmd, caddr_t pvData, int fFile, struct thread *pTd) 303 320 { 304 321 LogFlow((DEVICE_NAME ":VBoxGuestFreeBSDIOCtl\n")); 305 322 306 RTSPINLOCKTMP Tmp = RTSPINLOCKTMP_INITIALIZER; 307 const RTPROCESS Process = RTProcSelf(); 308 const unsigned iHash = SESSION_HASH(Process); 309 PVBOXGUESTSESSION pSession; 310 int rc = 0; 311 312 /* 313 * Find the session. 314 */ 315 RTSpinlockAcquireNoInts(g_Spinlock, &Tmp); 316 pSession = g_apSessionHashTab[iHash]; 317 if (pSession && pSession->Process != Process) 318 { 319 do pSession = pSession->pNextHash; 320 while (pSession && pSession->Process != Process); 321 } 322 RTSpinlockReleaseNoInts(g_Spinlock, &Tmp); 323 if (!pSession) 324 { 325 Log((DEVICE_NAME ":VBoxGuestFreeBSDIOCtl: WHAT?!? pSession == NULL! This must be a mistake... pid=%d iCmd=%#lx\n", (int)Process, cmd)); 323 int rc = 0; 324 325 /* 326 * Validate the input. 327 */ 328 PVBOXGUESTSESSION pSession = (PVBOXGUESTSESSION)pDev->si_drv1; 329 if (RT_UNLIKELY(!VALID_PTR(pSession))) 326 330 return EINVAL; 327 }328 331 329 332 /* 330 333 * Validate the request wrapper. 331 334 */ 332 if (IOCPARM_LEN( cmd) != sizeof(VBGLBIGREQ))333 { 334 Log((DEVICE_NAME ": VBoxGuestFreeBSDIOCtl: bad request %lu size=%lu expected=%d\n", cmd, IOCPARM_LEN(cmd), sizeof(VBGLBIGREQ)));335 if (IOCPARM_LEN(ulCmd) != sizeof(VBGLBIGREQ)) 336 { 337 Log((DEVICE_NAME ": VBoxGuestFreeBSDIOCtl: bad request %lu size=%lu expected=%d\n", ulCmd, IOCPARM_LEN(ulCmd), sizeof(VBGLBIGREQ))); 335 338 return ENOTTY; 336 339 } 337 340 338 PVBGLBIGREQ ReqWrap = (PVBGLBIGREQ) data;341 PVBGLBIGREQ ReqWrap = (PVBGLBIGREQ)pvData; 339 342 if (ReqWrap->u32Magic != VBGLBIGREQ_MAGIC) 340 343 { 341 Log((DEVICE_NAME ": VBoxGuestFreeBSDIOCtl: bad magic %#x; pArg=%p Cmd=%lu.\n", ReqWrap->u32Magic, data, cmd));344 Log((DEVICE_NAME ": VBoxGuestFreeBSDIOCtl: bad magic %#x; pArg=%p Cmd=%lu.\n", ReqWrap->u32Magic, pvData, ulCmd)); 342 345 return EINVAL; 343 346 } … … 345 348 || ReqWrap->cbData > _1M*16)) 346 349 { 347 printf(DEVICE_NAME ": VBoxGuestFreeBSDIOCtl: bad size %#x; pArg=%p Cmd=%lu.\n", ReqWrap->cbData, data, cmd);350 printf(DEVICE_NAME ": VBoxGuestFreeBSDIOCtl: bad size %#x; pArg=%p Cmd=%lu.\n", ReqWrap->cbData, pvData, ulCmd); 348 351 return EINVAL; 349 352 } … … 363 366 { 364 367 RTMemTmpFree(pvBuf); 365 Log((DEVICE_NAME ":VBoxGuestFreeBSDIOCtl: copyin failed; pvBuf=%p pArg=%p Cmd=%lu. rc=%d\n", pvBuf, data, cmd, rc));368 Log((DEVICE_NAME ":VBoxGuestFreeBSDIOCtl: copyin failed; pvBuf=%p pArg=%p Cmd=%lu. rc=%d\n", pvBuf, pvData, ulCmd, rc)); 366 369 return EFAULT; 367 370 } … … 379 382 */ 380 383 size_t cbDataReturned; 381 rc = VBoxGuestCommonIOCtl( cmd, &g_DevExt, pSession, pvBuf, ReqWrap->cbData, &cbDataReturned);384 rc = VBoxGuestCommonIOCtl(ulCmd, &g_DevExt, pSession, pvBuf, ReqWrap->cbData, &cbDataReturned); 382 385 if (RT_SUCCESS(rc)) 383 386 { … … 393 396 if (RT_UNLIKELY(rc)) 394 397 { 395 Log((DEVICE_NAME ":VBoxGuestFreeBSDIOCtl: copyout failed; pvBuf=%p pArg=%p Cmd=%lu. rc=%d\n", pvBuf, data, cmd, rc));398 Log((DEVICE_NAME ":VBoxGuestFreeBSDIOCtl: copyout failed; pvBuf=%p pArg=%p Cmd=%lu. rc=%d\n", pvBuf, pvData, ulCmd, rc)); 396 399 rc = EFAULT; 397 400 } … … 407 410 } 408 411 409 static ssize_t VBoxGuestFreeBSDWrite (struct cdev * dev, struct uio *uio, int ioflag)412 static ssize_t VBoxGuestFreeBSDWrite (struct cdev *pDev, struct uio *pUio, int fIo) 410 413 { 411 414 return 0; 412 415 } 413 416 414 static ssize_t VBoxGuestFreeBSDRead (struct cdev * dev, struct uio *uio, int ioflag)417 static ssize_t VBoxGuestFreeBSDRead (struct cdev *pDev, struct uio *pUio, int fIo) 415 418 { 416 419 return 0; 417 420 } 418 421 419 static int VBoxGuestFreeBSDDetach(device_t self) 420 { 421 struct VBoxGuestDeviceState *pState = (struct VBoxGuestDeviceState *)device_get_softc(self); 422 423 VBoxGuestFreeBSDRemoveIRQ(self, pState); 424 425 if (pState->vmmdevmem) 426 bus_release_resource(self, SYS_RES_MEMORY, pState->vmmdevmem_resid, pState->vmmdevmem); 427 if (pState->io_port) 428 bus_release_resource(self, SYS_RES_IOPORT, pState->io_port_resid, pState->io_port); 422 static int VBoxGuestFreeBSDDetach(device_t pDevice) 423 { 424 struct VBoxGuestDeviceState *pState = (struct VBoxGuestDeviceState *)device_get_softc(pDevice); 425 426 /* 427 * Reserve what we did in VBoxGuestFreeBSDAttach. 428 */ 429 clone_cleanup(&g_pVBoxGuestFreeBSDClones); 430 431 VBoxGuestFreeBSDRemoveIRQ(pDevice, pState); 432 433 if (pState->pVMMDevMemRes) 434 bus_release_resource(pDevice, SYS_RES_MEMORY, pState->iVMMDevMemResId, pState->pVMMDevMemRes); 435 if (pState->pIOPortRes) 436 bus_release_resource(pDevice, SYS_RES_IOPORT, pState->iIOPortResId, pState->pIOPortRes); 429 437 430 438 VBoxGuestDeleteDevExt(&g_DevExt); 431 432 RTSpinlockDestroy(g_Spinlock);433 g_Spinlock = NIL_RTSPINLOCK;434 439 435 440 free(pState, M_VBOXDEV); … … 445 450 * @param pvState Opaque pointer to the device state. 446 451 */ 447 int VBoxGuestFreeBSDISR(void *pvState)452 static int VBoxGuestFreeBSDISR(void *pvState) 448 453 { 449 454 LogFlow((DEVICE_NAME ":VBoxGuestFreeBSDISR pvState=%p\n", pvState)); … … 458 463 * 459 464 * @returns FreeBSD error code. 460 * @param selfPointer to the device info structure.465 * @param pDevice Pointer to the device info structure. 461 466 * @param pvState Pointer to the state info structure. 462 467 */ 463 static int VBoxGuestFreeBSDAddIRQ(device_t self, void *pvState)464 { 465 int res_id = 0;468 static int VBoxGuestFreeBSDAddIRQ(device_t pDevice, void *pvState) 469 { 470 int iResId = 0; 466 471 int rc = 0; 467 472 struct VBoxGuestDeviceState *pState = (struct VBoxGuestDeviceState *)pvState; 468 473 469 pState-> irq = bus_alloc_resource_any(self, SYS_RES_IRQ, &res_id, RF_SHAREABLE | RF_ACTIVE);474 pState->pIrqRes = bus_alloc_resource_any(pDevice, SYS_RES_IRQ, &iResId, RF_SHAREABLE | RF_ACTIVE); 470 475 471 476 #if __FreeBSD_version >= 700000 472 rc = bus_setup_intr( self, pState->irq, INTR_TYPE_BIO, NULL, (driver_intr_t *)VBoxGuestFreeBSDISR, pState, &pState->irq_handler);477 rc = bus_setup_intr(pDevice, pState->pIrqRes, INTR_TYPE_BIO, NULL, (driver_intr_t *)VBoxGuestFreeBSDISR, pState, &pState->pfnIrqHandler); 473 478 #else 474 rc = bus_setup_intr( self, pState->irq, INTR_TYPE_BIO, (driver_intr_t *)VBoxGuestFreeBSDISR, pState, &pState->irq_handler);479 rc = bus_setup_intr(pDevice, pState->pIrqRes, INTR_TYPE_BIO, (driver_intr_t *)VBoxGuestFreeBSDISR, pState, &pState->pfnIrqHandler); 475 480 #endif 476 481 477 482 if (rc) 478 483 { 479 pState-> irq_handler = NULL;484 pState->pfnIrqHandler = NULL; 480 485 return VERR_DEV_IO_ERROR; 481 486 } 482 487 483 pState->i rq_resid = res_id;488 pState->iIrqResId = iResId; 484 489 485 490 return VINF_SUCCESS; … … 489 494 * Removes IRQ for VMMDev. 490 495 * 491 * @param selfPointer to the device info structure.496 * @param pDevice Pointer to the device info structure. 492 497 * @param pvState Opaque pointer to the state info structure. 493 498 */ 494 static void VBoxGuestFreeBSDRemoveIRQ(device_t self, void *pvState)499 static void VBoxGuestFreeBSDRemoveIRQ(device_t pDevice, void *pvState) 495 500 { 496 501 struct VBoxGuestDeviceState *pState = (struct VBoxGuestDeviceState *)pvState; 497 502 498 if (pState-> irq)499 { 500 bus_teardown_intr( self, pState->irq, pState->irq_handler);501 bus_release_resource( self, SYS_RES_IRQ, 0, pState->irq);502 } 503 } 504 505 static int VBoxGuestFreeBSDAttach(device_t self)503 if (pState->pIrqRes) 504 { 505 bus_teardown_intr(pDevice, pState->pIrqRes, pState->pfnIrqHandler); 506 bus_release_resource(pDevice, SYS_RES_IRQ, 0, pState->pIrqRes); 507 } 508 } 509 510 static int VBoxGuestFreeBSDAttach(device_t pDevice) 506 511 { 507 512 int rc = VINF_SUCCESS; 508 int res_id = 0;513 int iResId = 0; 509 514 struct VBoxGuestDeviceState *pState = NULL; 510 515 … … 519 524 } 520 525 521 pState = device_get_softc( self);526 pState = device_get_softc(pDevice); 522 527 if (!pState) 523 528 { … … 526 531 return ENOMEM; 527 532 528 device_set_softc(self, pState); 529 } 530 531 /* 532 * Initialize the session hash table. 533 */ 534 rc = RTSpinlockCreate(&g_Spinlock); 535 if (RT_SUCCESS(rc)) 533 device_set_softc(pDevice, pState); 534 } 535 536 /* 537 * Allocate I/O port resource. 538 */ 539 iResId = PCIR_BAR(0); 540 pState->pIOPortRes = bus_alloc_resource_any(pDevice, SYS_RES_IOPORT, &iResId, RF_ACTIVE); 541 pState->uIOPortBase = bus_get_resource_start(pDevice, SYS_RES_IOPORT, iResId); 542 pState->iIOPortResId = iResId; 543 if (pState->uIOPortBase) 536 544 { 537 545 /* 538 * Map the register address space.546 * Map the MMIO region. 539 547 */ 540 res_id = PCIR_BAR(0); 541 pState->io_port = bus_alloc_resource_any(self, SYS_RES_IOPORT, &res_id, RF_ACTIVE); 542 pState->io_port_tag = rman_get_bustag(pState->io_port); 543 pState->io_port_handle = rman_get_bushandle(pState->io_port); 544 pState->uIOPortBase = bus_get_resource_start(self, SYS_RES_IOPORT, res_id); 545 pState->io_port_resid = res_id; 546 if (pState->uIOPortBase) 548 iResId = PCIR_BAR(1); 549 pState->pVMMDevMemRes = bus_alloc_resource_any(pDevice, SYS_RES_MEMORY, &iResId, RF_ACTIVE); 550 pState->VMMDevMemHandle = rman_get_bushandle(pState->pVMMDevMemRes); 551 pState->VMMDevMemSize = bus_get_resource_count(pDevice, SYS_RES_MEMORY, iResId); 552 553 pState->pMMIOBase = (void *)pState->VMMDevMemHandle; 554 pState->iVMMDevMemResId = iResId; 555 if (pState->pMMIOBase) 547 556 { 548 557 /* 549 * Map the MMIO region.558 * Add IRQ of VMMDev. 550 559 */ 551 res_id = PCIR_BAR(1); 552 pState->vmmdevmem = bus_alloc_resource_any(self, SYS_RES_MEMORY, &res_id, RF_ACTIVE); 553 pState->vmmdevmem_tag = rman_get_bustag(pState->vmmdevmem); 554 pState->vmmdevmem_handle = rman_get_bushandle(pState->vmmdevmem); 555 pState->vmmdevmem_addr = bus_get_resource_start(self, SYS_RES_MEMORY, res_id); 556 pState->vmmdevmem_size = bus_get_resource_count(self, SYS_RES_MEMORY, res_id); 557 558 pState->pMMIOBase = (void *)pState->vmmdevmem_handle; 559 pState->vmmdevmem_resid = res_id; 560 if (pState->pMMIOBase) 560 rc = VBoxGuestFreeBSDAddIRQ(pDevice, pState); 561 if (RT_SUCCESS(rc)) 561 562 { 562 563 /* 563 * Add IRQ of VMMDev.564 * Call the common device extension initializer. 564 565 */ 565 rc = VBoxGuestFreeBSDAddIRQ(self, pState); 566 rc = VBoxGuestInitDevExt(&g_DevExt, pState->uIOPortBase, pState->pMMIOBase, 567 pState->VMMDevMemSize, VBOXOSTYPE_FreeBSD); 566 568 if (RT_SUCCESS(rc)) 567 569 { 568 570 /* 569 * C all the common device extension initializer.571 * Configure device cloning. 570 572 */ 571 rc = VBoxGuestInitDevExt(&g_DevExt, pState->uIOPortBase, pState->pMMIOBase, 572 pState->vmmdevmem_size, VBOXOSTYPE_FreeBSD); 573 printf("rc=%d\n", rc); 574 if (RT_SUCCESS(rc)) 573 clone_setup(&g_pVBoxGuestFreeBSDClones); 574 g_VBoxGuestFreeBSDEHTag = EVENTHANDLER_REGISTER(dev_clone, VBoxGuestFreeBSDClone, 0, 1000); 575 if (g_VBoxGuestFreeBSDEHTag) 575 576 { 576 /* 577 * Create device node. 578 */ 579 g_pVBoxAddFreeBSDChrDev = make_dev(&g_VBoxAddFreeBSDChrDevSW, 580 0, 581 UID_ROOT, 582 GID_WHEEL, 583 0666, 584 DEVICE_NAME); 585 g_pVBoxAddFreeBSDChrDev->si_drv1 = self; 577 printf(DEVICE_NAME ": loaded successfully\n"); 586 578 return 0; 587 579 } 588 else 589 printf((DEVICE_NAME ":VBoxGuestInitDevExt failed.\n")); 590 VBoxGuestFreeBSDRemoveIRQ(self, pState); 580 581 printf("vboxdrv: EVENTHANDLER_REGISTER(dev_clone,,,) failed\n"); 582 clone_cleanup(&g_pVBoxGuestFreeBSDClones); 583 VBoxGuestDeleteDevExt(&g_DevExt); 591 584 } 592 585 else 593 printf((DEVICE_NAME ":VBoxGuestFreeBSDAddIRQ failed.\n")); 586 printf((DEVICE_NAME ":VBoxGuestInitDevExt failed.\n")); 587 VBoxGuestFreeBSDRemoveIRQ(pDevice, pState); 594 588 } 595 589 else 596 printf((DEVICE_NAME ": MMIO region setupfailed.\n"));590 printf((DEVICE_NAME ":VBoxGuestFreeBSDAddIRQ failed.\n")); 597 591 } 598 592 else 599 printf((DEVICE_NAME ":IOport setup failed.\n")); 600 RTSpinlockDestroy(g_Spinlock); 601 g_Spinlock = NIL_RTSPINLOCK; 593 printf((DEVICE_NAME ":MMIO region setup failed.\n")); 602 594 } 603 595 else 604 printf((DEVICE_NAME ": RTSpinlockCreatefailed.\n"));596 printf((DEVICE_NAME ":IOport setup failed.\n")); 605 597 606 598 RTR0Term(); … … 608 600 } 609 601 610 static int VBoxGuestFreeBSDProbe(device_t self) 611 { 612 if ((pci_get_vendor(self) == VMMDEV_VENDORID) && (pci_get_device(self) == VMMDEV_DEVICEID)) 613 { 614 Log(("Found VBox device\n")); 602 static int VBoxGuestFreeBSDProbe(device_t pDevice) 603 { 604 if ((pci_get_vendor(pDevice) == VMMDEV_VENDORID) && (pci_get_device(pDevice) == VMMDEV_DEVICEID)) 615 605 return 0; 616 }617 606 618 607 return ENXIO; … … 622 611 { 623 612 /* Device interface. */ 624 DEVMETHOD(device_probe, VBoxGuestFreeBSDProbe),613 DEVMETHOD(device_probe, VBoxGuestFreeBSDProbe), 625 614 DEVMETHOD(device_attach, VBoxGuestFreeBSDAttach), 626 615 DEVMETHOD(device_detach, VBoxGuestFreeBSDDetach), -
trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3Lib.cpp
r8155 r8188 151 151 g_File = hf; 152 152 153 #elif defined(VBOX_VBGLR3_XFREE86) 153 #elif defined(VBOX_VBGLR3_XFREE86) && !defined(RT_OS_FREEBSD) 154 154 int File = xf86open(VBOXGUEST_DEVICE_NAME, XF86_O_RDWR); 155 155 if (File == -1) … … 157 157 g_File = File; 158 158 159 #elif defined(RT_OS_FREEBSD) 160 /* 161 * Try open the BSD device. 162 */ 163 #if defined(VBOX_VBGLR3_XFREE86) 164 int File = 0; 165 #else 166 RTFILE File = 0; 167 #endif 168 int rc; 169 char szDevice[sizeof(VBOXGUEST_DEVICE_NAME) + 16]; 170 for (unsigned iUnit = 0; iUnit < 1024; iUnit++) 171 { 172 RTStrPrintf(szDevice, sizeof(szDevice), VBOXGUEST_DEVICE_NAME "%d", iUnit); 173 #if defined(VBOX_VBGLR3_XFREE86) 174 File = xf86open(szDevice, XF86_O_RDWR); 175 if (File >= 0) 176 break; 177 #else 178 rc = RTFileOpen(&File, szDevice, RTFILE_O_READWRITE | RTFILE_O_OPEN | RTFILE_O_DENY_NONE); 179 if (RT_SUCCESS(rc)) 180 break; 181 #endif 182 } 183 184 #if defined(VBOX_VBGLR3_XFREE86) 185 if (File == -1) 186 return VERR_OPEN_FAILED; 187 #else 188 if (RT_FAILURE(rc)) 189 return rc; 190 #endif 191 192 g_File = File; 159 193 #else 160 194 /* the default implemenation. (linux, solaris) */ -
trunk/src/VBox/Additions/freebsd/vboxvfs/vboxvfs_vfsops.c
r8155 r8188 71 71 MODULE_DEPEND(vboxvfs, vboxguest, 1, 1, 1); 72 72 73 static int 74 vboxvfs_cmount(struct mntarg *ma, void * data, int flags, struct thread *td) 73 static int vboxvfs_cmount(struct mntarg *ma, void * data, int flags, struct thread *td) 75 74 { 76 75 struct vboxvfs_mount_info args; … … 213 212 } 214 213 215 static int vboxvfs_quotactl(mp, cmd, uid, arg, td) 216 struct mount *mp; 217 int cmd; 218 uid_t uid; 219 void *arg; 220 struct thread *td; 214 static int vboxvfs_quotactl(struct mount *mp, int cmd, uid_t uid, void *arg, struct thread *td) 221 215 { 222 216 return EOPNOTSUPP; … … 230 224 rc = vboxInit(); 231 225 if (VBOX_FAILURE(rc)) 232 226 return ENXIO; 233 227 234 228 /* Connect to the host service. */ … … 236 230 if (VBOX_FAILURE(rc)) 237 231 { 238 239 240 232 printf("Failed to get connection to host! rc=%d\n", rc); 233 vboxUninit(); 234 return ENXIO; 241 235 } 242 236 … … 245 239 { 246 240 printf("vboxCallSetUtf8 failed, rc=%d\n", rc); 247 248 249 241 vboxDisconnect(&g_vboxSFClient); 242 vboxUninit(); 243 return EPROTO; 250 244 } 251 245
Note:
See TracChangeset
for help on using the changeset viewer.