Changeset 22575 in vbox
- Timestamp:
- Aug 30, 2009 8:02:08 PM (15 years ago)
- Location:
- trunk/src/VBox/Additions
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuest-freebsd.c
r21170 r22575 27 27 #include <sys/param.h> 28 28 #include <sys/systm.h> 29 #include <sys/conf.h> 29 30 #include <sys/kernel.h> 30 31 #include <sys/module.h> 31 32 #include <sys/bus.h> 33 #include <sys/poll.h> 34 #include <sys/selinfo.h> 32 35 #include <sys/queue.h> 36 #include <sys/lock.h> 33 37 #include <sys/lockmgr.h> 34 38 #include <sys/types.h> … … 37 41 #include <sys/uio.h> 38 42 #include <sys/file.h> 43 #include <sys/rman.h> 39 44 #include <machine/bus.h> 40 #include <sys/rman.h>41 45 #include <machine/resource.h> 42 46 #include <dev/pci/pcivar.h> 43 47 #include <dev/pci/pcireg.h> 44 48 49 #ifdef PVM 50 # undef PVM 51 #endif 45 52 #include "VBoxGuestInternal.h" 46 53 #include <VBox/log.h> … … 56 63 struct VBoxGuestDeviceState 57 64 { 58 /** file node minor code */59 unsigned uMinor;60 65 /** Resource ID of the I/O port */ 61 66 int iIOPortResId; … … 94 99 static d_write_t VBoxGuestFreeBSDWrite; 95 100 static d_read_t VBoxGuestFreeBSDRead; 101 static d_poll_t VBoxGuestFreeBSDPoll; 96 102 97 103 /* … … 109 115 DECLVBGL(int) VBoxGuestFreeBSDServiceClose(void *pvSession); 110 116 117 #ifndef D_NEEDMINOR 118 # define D_NEEDMINOR 0 119 #endif 120 111 121 /* 112 122 * Device node entry points. … … 115 125 { 116 126 .d_version = D_VERSION, 117 .d_flags = D_TRACKCLOSE ,127 .d_flags = D_TRACKCLOSE | D_NEEDMINOR, 118 128 .d_fdopen = VBoxGuestFreeBSDOpen, 119 129 .d_close = VBoxGuestFreeBSDClose, … … 121 131 .d_read = VBoxGuestFreeBSDRead, 122 132 .d_write = VBoxGuestFreeBSDWrite, 133 .d_poll = VBoxGuestFreeBSDPoll, 123 134 .d_name = DEVICE_NAME 124 135 }; … … 130 141 /** The dev_clone event handler tag. */ 131 142 static eventhandler_tag g_VBoxGuestFreeBSDEHTag; 132 143 /** Reference counter */ 144 static volatile uint32_t cUsers; 145 /** selinfo structure used for polling. */ 146 static struct selinfo g_SelInfo; 133 147 134 148 /** … … 148 162 if (!ppDev) 149 163 return; 150 if (dev_stdclone(pszName, NULL, "vboxguest", &iUnit) != 1) 164 if (strcmp(pszName, "vboxguest") == 0) 165 iUnit = -1; 166 else if (dev_stdclone(pszName, NULL, "vboxguest", &iUnit) != 1) 151 167 return; 152 if (iUnit >= 256 || iUnit < 0)168 if (iUnit >= 256) 153 169 { 154 170 Log(("VBoxGuestFreeBSDClone: iUnit=%d >= 256 - rejected\n", iUnit)); … … 163 179 { 164 180 *ppDev = make_dev(&g_VBoxGuestFreeBSDChrDevSW, 165 unit2minor(iUnit),181 iUnit, 166 182 UID_ROOT, 167 183 GID_WHEEL, … … 214 230 { 215 231 Log((DEVICE_NAME ":VBoxGuestFreeBSDOpen success: g_DevExt=%p pSession=%p rc=%d pid=%d\n", &g_DevExt, pSession, rc, (int)RTProcSelf())); 232 ASMAtomicIncU32(&cUsers); 216 233 return 0; 217 234 } … … 241 258 if (!ASMAtomicCmpXchgPtr(&pDev->si_drv1, NULL, pSession)) 242 259 Log(("VBoxGuestFreeBSDClose: si_drv1=%p expected %p!\n", pDev->si_drv1, pSession)); 260 ASMAtomicDecU32(&cUsers); 261 /* Don't use destroy_dev here because it may sleep resulting in a hanging user process. */ 262 destroy_dev_sched(pDev); 243 263 } 244 264 else … … 344 364 } 345 365 346 static ssize_t VBoxGuestFreeBSDWrite (struct cdev *pDev, struct uio *pUio, int fIo) 366 static int VBoxGuestFreeBSDPoll (struct cdev *pDev, int fEvents, struct thread *td) 367 { 368 int fEventsProcessed; 369 370 LogFlow((DEVICE_NAME "::Poll: fEvents=%d\n", fEvents)); 371 372 PVBOXGUESTSESSION pSession = (PVBOXGUESTSESSION)pDev->si_drv1; 373 if (RT_UNLIKELY(!VALID_PTR(pSession))) { 374 Log((DEVICE_NAME "::Poll: no state data for %s\n", devtoname(pDev))); 375 return (fEvents & (POLLHUP|POLLIN|POLLRDNORM|POLLOUT|POLLWRNORM)); 376 } 377 378 uint32_t u32CurSeq = ASMAtomicUoReadU32(&g_DevExt.u32MousePosChangedSeq); 379 if (pSession->u32MousePosChangedSeq != u32CurSeq) 380 { 381 fEventsProcessed = fEvents & (POLLIN | POLLRDNORM); 382 pSession->u32MousePosChangedSeq = u32CurSeq; 383 } 384 else 385 { 386 fEventsProcessed = 0; 387 388 selrecord(td, &g_SelInfo); 389 } 390 391 return fEventsProcessed; 392 } 393 394 static int VBoxGuestFreeBSDWrite (struct cdev *pDev, struct uio *pUio, int fIo) 347 395 { 348 396 return 0; 349 397 } 350 398 351 static ssize_t VBoxGuestFreeBSDRead (struct cdev *pDev, struct uio *pUio, int fIo)399 static int VBoxGuestFreeBSDRead (struct cdev *pDev, struct uio *pUio, int fIo) 352 400 { 353 401 return 0; … … 356 404 static int VBoxGuestFreeBSDDetach(device_t pDevice) 357 405 { 358 struct VBoxGuestDeviceState *pState = (struct VBoxGuestDeviceState *)device_get_softc(pDevice); 359 360 /* 361 * Reserve what we did in VBoxGuestFreeBSDAttach. 362 */ 406 struct VBoxGuestDeviceState *pState = device_get_softc(pDevice); 407 408 if (cUsers > 0) 409 return EBUSY; 410 411 /* 412 * Reverse what we did in VBoxGuestFreeBSDAttach. 413 */ 414 if (g_VBoxGuestFreeBSDEHTag != NULL) 415 EVENTHANDLER_DEREGISTER(dev_clone, g_VBoxGuestFreeBSDEHTag); 416 363 417 clone_cleanup(&g_pVBoxGuestFreeBSDClones); 364 418 … … 372 426 VBoxGuestDeleteDevExt(&g_DevExt); 373 427 374 free(pState, M_VBOXDEV);375 428 RTR0Term(); 376 429 … … 391 444 392 445 return fOurIRQ ? 0 : 1; 446 } 447 448 void VBoxGuestNativeISRMousePollEvent(PVBOXGUESTDEVEXT pDevExt) 449 { 450 LogFlow((DEVICE_NAME "::NativeISRMousePollEvent:\n")); 451 452 /* 453 * Wake up poll waiters. 454 */ 455 selwakeup(&g_SelInfo); 393 456 } 394 457 … … 409 472 410 473 #if __FreeBSD_version >= 700000 411 rc = bus_setup_intr(pDevice, pState->pIrqRes, INTR_TYPE_BIO, NULL, (driver_intr_t *)VBoxGuestFreeBSDISR, pState, &pState->pfnIrqHandler); 474 rc = bus_setup_intr(pDevice, pState->pIrqRes, INTR_TYPE_BIO | INTR_MPSAFE, NULL, (driver_intr_t *)VBoxGuestFreeBSDISR, pState, 475 &pState->pfnIrqHandler); 412 476 #else 413 477 rc = bus_setup_intr(pDevice, pState->pIrqRes, INTR_TYPE_BIO, (driver_intr_t *)VBoxGuestFreeBSDISR, pState, &pState->pfnIrqHandler); … … 448 512 struct VBoxGuestDeviceState *pState = NULL; 449 513 514 cUsers = 0; 515 450 516 /* 451 517 * Initialize IPRT R0 driver, which internally calls OS-specific r0 init. … … 459 525 460 526 pState = device_get_softc(pDevice); 461 if (!pState)462 {463 pState = malloc(sizeof(struct VBoxGuestDeviceState), M_VBOXDEV, M_NOWAIT | M_ZERO);464 if (!pState)465 return ENOMEM;466 467 device_set_softc(pDevice, pState);468 }469 527 470 528 /* … … 473 531 iResId = PCIR_BAR(0); 474 532 pState->pIOPortRes = bus_alloc_resource_any(pDevice, SYS_RES_IOPORT, &iResId, RF_ACTIVE); 475 pState->uIOPortBase = bus_get_resource_start(pDevice, SYS_RES_IOPORT, iResId);533 pState->uIOPortBase = rman_get_start(pState->pIOPortRes); 476 534 pState->iIOPortResId = iResId; 477 535 if (pState->uIOPortBase) … … 483 541 pState->pVMMDevMemRes = bus_alloc_resource_any(pDevice, SYS_RES_MEMORY, &iResId, RF_ACTIVE); 484 542 pState->VMMDevMemHandle = rman_get_bushandle(pState->pVMMDevMemRes); 485 pState->VMMDevMemSize = bus_get_resource_count(pDevice, SYS_RES_MEMORY, iResId);486 487 pState->pMMIOBase = (void *)pState->VMMDevMemHandle;543 pState->VMMDevMemSize = rman_get_size(pState->pVMMDevMemRes); 544 545 pState->pMMIOBase = rman_get_virtual(pState->pVMMDevMemRes); 488 546 pState->iVMMDevMemResId = iResId; 489 547 if (pState->pMMIOBase) … … 492 550 * Call the common device extension initializer. 493 551 */ 494 rc = VBoxGuestInitDevExt(&g_DevExt, pState->uIOPortBase, pState->pMMIOBase, 495 pState->VMMDevMemSize, VBOXOSTYPE_FreeBSD, 0); 552 rc = VBoxGuestInitDevExt(&g_DevExt, pState->uIOPortBase, 553 pState->pMMIOBase, pState->VMMDevMemSize, 554 VBOXOSTYPE_FreeBSD, VMMDEV_EVENT_MOUSE_POSITION_CHANGED); 496 555 if (RT_SUCCESS(rc)) 497 556 { … … 563 622 MODULE_VERSION(vboxguest, 1); 564 623 565 #if 0/** @todo This shouldn't be needed. if it is, that means exceptions hasn't been disabled correctly. */566 int __gxx_personality_v0 = 0xdeadbeef;567 #endif568 569 570 624 /* Common code that depend on g_DevExt. */ 571 625 #include "VBoxGuestIDC-unix.c.h" -
trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3Lib.cpp
r21211 r22575 187 187 g_File = hf; 188 188 189 #elif defined(RT_OS_FREEBSD) 190 /* 191 * Try open the BSD device. The device cloning makes this a bit of work. 192 */ 193 # if defined(VBOX_VBGLR3_XFREE86) 194 int File = 0; 195 # else 196 RTFILE File = 0; 197 # endif 198 int rc; 199 char szDevice[RT_MAX(sizeof(VBOXGUEST_DEVICE_NAME), sizeof(VBOXGUEST_USER_DEVICE_NAME)) + 16]; 200 for (unsigned iUnit = 0; iUnit < 1024; iUnit++) 201 { 202 RTStrPrintf(szDevice, sizeof(szDevice), pszDeviceName "%d", iUnit); 203 # if defined(VBOX_VBGLR3_XFREE86) 204 File = xf86open(szDevice, XF86_O_RDWR); 205 if (File >= 0) 206 break; 207 # else 208 rc = RTFileOpen(&File, szDevice, RTFILE_O_READWRITE | RTFILE_O_OPEN | RTFILE_O_DENY_NONE); 209 if (RT_SUCCESS(rc)) 210 break; 211 # endif 212 } 213 214 # if defined(VBOX_VBGLR3_XFREE86) 215 if (File == -1) 216 return VERR_OPEN_FAILED; 217 # else 218 if (RT_FAILURE(rc)) 219 return rc; 220 # endif 221 222 g_File = File; 223 224 #elif defined(VBOX_VBGLR3_XFREE86) && !defined(RT_OS_FREEBSD) 189 #elif defined(VBOX_VBGLR3_XFREE86) 225 190 int File = xf86open(pszDeviceName, XF86_O_RDWR); 226 191 if (File == -1) … … 230 195 #else 231 196 232 /* The default implemenation. (linux, solaris ) */197 /* The default implemenation. (linux, solaris, freebsd) */ 233 198 RTFILE File; 234 199 int rc = RTFileOpen(&File, pszDeviceName, RTFILE_O_READWRITE | RTFILE_O_OPEN | RTFILE_O_DENY_NONE); -
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceVMInfo.cpp
r21980 r22575 34 34 # include <arpa/inet.h> 35 35 # include <errno.h> 36 # include <net/if.h>37 36 # include <netinet/in.h> 38 37 # include <sys/ioctl.h> 39 38 # include <sys/socket.h> 39 # include <net/if.h> 40 40 # include <unistd.h> 41 41 # include <utmp.h> … … 236 236 ::LsaFreeReturnBuffer(pSessions); 237 237 #endif /* TARGET_NT4 */ 238 #elif defined(RT_OS_FREEBSD) 239 /* TODO: Port me */ 238 240 #else 239 241 utmp* ut_user; … … 378 380 return -1; 379 381 } 380 #if def RT_OS_SOLARIS382 #if defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) 381 383 pAddress = (sockaddr_in *)&ifrequest[i].ifr_addr; 382 384 #else -
trunk/src/VBox/Additions/freebsd/Makefile.kmk
r16995 r22575 28 28 29 29 # Include sub-makefiles. 30 include $(PATH_SUB_CURRENT)/vboxvfs/Makefile.kmk 30 #include $(PATH_SUB_CURRENT)/vboxvfs/Makefile.kmk 31 #include $(PATH_SUB_CURRENT)/drm/Makefile.kmk 31 32 32 33 # Globals … … 60 61 $(VBOX_PATH_X11_ADDITION_INSTALLER)/x11config.pl \ 61 62 $(PATH_BIN)/additions/vboxguest.ko \ 63 $(PATH_BIN)/additions/vboxvideo.ko \ 64 $(PATH_BIN)/additions/vboxvfs.ko \ 62 65 $(PATH_BIN)/additions/VBoxClient \ 63 66 $(PATH_BIN)/additions/VBoxService \
Note:
See TracChangeset
for help on using the changeset viewer.