VirtualBox

Changeset 22575 in vbox


Ignore:
Timestamp:
Aug 30, 2009 8:02:08 PM (15 years ago)
Author:
vboxsync
Message:

Additions/FreeBSD: Fixes several problems. The X11 part is mostly working now for FreeBSD 7.x and 8. Contributed by Alexander Kabaev.

Location:
trunk/src/VBox/Additions
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuest-freebsd.c

    r21170 r22575  
    2727#include <sys/param.h>
    2828#include <sys/systm.h>
     29#include <sys/conf.h>
    2930#include <sys/kernel.h>
    3031#include <sys/module.h>
    3132#include <sys/bus.h>
     33#include <sys/poll.h>
     34#include <sys/selinfo.h>
    3235#include <sys/queue.h>
     36#include <sys/lock.h>
    3337#include <sys/lockmgr.h>
    3438#include <sys/types.h>
     
    3741#include <sys/uio.h>
    3842#include <sys/file.h>
     43#include <sys/rman.h>
    3944#include <machine/bus.h>
    40 #include <sys/rman.h>
    4145#include <machine/resource.h>
    4246#include <dev/pci/pcivar.h>
    4347#include <dev/pci/pcireg.h>
    4448
     49#ifdef PVM
     50#  undef PVM
     51#endif
    4552#include "VBoxGuestInternal.h"
    4653#include <VBox/log.h>
     
    5663struct VBoxGuestDeviceState
    5764{
    58     /** file node minor code */
    59     unsigned           uMinor;
    6065    /** Resource ID of the I/O port */
    6166    int                iIOPortResId;
     
    9499static d_write_t  VBoxGuestFreeBSDWrite;
    95100static d_read_t   VBoxGuestFreeBSDRead;
     101static d_poll_t   VBoxGuestFreeBSDPoll;
    96102
    97103/*
     
    109115DECLVBGL(int)    VBoxGuestFreeBSDServiceClose(void *pvSession);
    110116
     117#ifndef D_NEEDMINOR
     118# define D_NEEDMINOR 0
     119#endif
     120
    111121/*
    112122 * Device node entry points.
     
    115125{
    116126    .d_version =        D_VERSION,
    117     .d_flags =          D_TRACKCLOSE,
     127    .d_flags =          D_TRACKCLOSE | D_NEEDMINOR,
    118128    .d_fdopen =         VBoxGuestFreeBSDOpen,
    119129    .d_close =          VBoxGuestFreeBSDClose,
     
    121131    .d_read =           VBoxGuestFreeBSDRead,
    122132    .d_write =          VBoxGuestFreeBSDWrite,
     133    .d_poll =           VBoxGuestFreeBSDPoll,
    123134    .d_name =           DEVICE_NAME
    124135};
     
    130141/** The dev_clone event handler tag. */
    131142static eventhandler_tag     g_VBoxGuestFreeBSDEHTag;
    132 
     143/** Reference counter */
     144static volatile uint32_t    cUsers;
     145/** selinfo structure used for polling. */
     146static struct selinfo       g_SelInfo;
    133147
    134148/**
     
    148162    if (!ppDev)
    149163        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)
    151167        return;
    152     if (iUnit >= 256 || iUnit < 0)
     168    if (iUnit >= 256)
    153169    {
    154170        Log(("VBoxGuestFreeBSDClone: iUnit=%d >= 256 - rejected\n", iUnit));
     
    163179    {
    164180        *ppDev = make_dev(&g_VBoxGuestFreeBSDChrDevSW,
    165                           unit2minor(iUnit),
     181                          iUnit,
    166182                          UID_ROOT,
    167183                          GID_WHEEL,
     
    214230        {
    215231            Log((DEVICE_NAME ":VBoxGuestFreeBSDOpen success: g_DevExt=%p pSession=%p rc=%d pid=%d\n", &g_DevExt, pSession, rc, (int)RTProcSelf()));
     232            ASMAtomicIncU32(&cUsers);
    216233            return 0;
    217234        }
     
    241258        if (!ASMAtomicCmpXchgPtr(&pDev->si_drv1, NULL, pSession))
    242259            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);
    243263    }
    244264    else
     
    344364}
    345365
    346 static ssize_t VBoxGuestFreeBSDWrite (struct cdev *pDev, struct uio *pUio, int fIo)
     366static 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
     394static int VBoxGuestFreeBSDWrite (struct cdev *pDev, struct uio *pUio, int fIo)
    347395{
    348396    return 0;
    349397}
    350398
    351 static ssize_t VBoxGuestFreeBSDRead (struct cdev *pDev, struct uio *pUio, int fIo)
     399static int VBoxGuestFreeBSDRead (struct cdev *pDev, struct uio *pUio, int fIo)
    352400{
    353401    return 0;
     
    356404static int VBoxGuestFreeBSDDetach(device_t pDevice)
    357405{
    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
    363417    clone_cleanup(&g_pVBoxGuestFreeBSDClones);
    364418
     
    372426    VBoxGuestDeleteDevExt(&g_DevExt);
    373427
    374     free(pState, M_VBOXDEV);
    375428    RTR0Term();
    376429
     
    391444
    392445    return fOurIRQ ? 0 : 1;
     446}
     447
     448void VBoxGuestNativeISRMousePollEvent(PVBOXGUESTDEVEXT pDevExt)
     449{
     450    LogFlow((DEVICE_NAME "::NativeISRMousePollEvent:\n"));
     451
     452    /*
     453     * Wake up poll waiters.
     454     */
     455    selwakeup(&g_SelInfo);
    393456}
    394457
     
    409472
    410473#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);
    412476#else
    413477    rc = bus_setup_intr(pDevice, pState->pIrqRes, INTR_TYPE_BIO, (driver_intr_t *)VBoxGuestFreeBSDISR, pState, &pState->pfnIrqHandler);
     
    448512    struct VBoxGuestDeviceState *pState = NULL;
    449513
     514    cUsers = 0;
     515
    450516    /*
    451517     * Initialize IPRT R0 driver, which internally calls OS-specific r0 init.
     
    459525
    460526    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     }
    469527
    470528    /*
     
    473531    iResId                 = PCIR_BAR(0);
    474532    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);
    476534    pState->iIOPortResId   = iResId;
    477535    if (pState->uIOPortBase)
     
    483541        pState->pVMMDevMemRes    = bus_alloc_resource_any(pDevice, SYS_RES_MEMORY, &iResId, RF_ACTIVE);
    484542        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);
    488546        pState->iVMMDevMemResId = iResId;
    489547        if (pState->pMMIOBase)
     
    492550             * Call the common device extension initializer.
    493551             */
    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);
    496555            if (RT_SUCCESS(rc))
    497556            {
     
    563622MODULE_VERSION(vboxguest, 1);
    564623
    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 #endif
    568 
    569 
    570624/* Common code that depend on g_DevExt. */
    571625#include "VBoxGuestIDC-unix.c.h"
  • trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3Lib.cpp

    r21211 r22575  
    187187    g_File = hf;
    188188
    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)
    225190    int File = xf86open(pszDeviceName, XF86_O_RDWR);
    226191    if (File == -1)
     
    230195#else
    231196
    232     /* The default implemenation. (linux, solaris) */
     197    /* The default implemenation. (linux, solaris, freebsd) */
    233198    RTFILE File;
    234199    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  
    3434# include <arpa/inet.h>
    3535# include <errno.h>
    36 # include <net/if.h>
    3736# include <netinet/in.h>
    3837# include <sys/ioctl.h>
    3938# include <sys/socket.h>
     39# include <net/if.h>
    4040# include <unistd.h>
    4141# include <utmp.h>
     
    236236        ::LsaFreeReturnBuffer(pSessions);
    237237 #endif /* TARGET_NT4 */
     238#elif defined(RT_OS_FREEBSD)
     239        /* TODO: Port me */
    238240#else
    239241        utmp* ut_user;
     
    378380                return -1;
    379381            }
    380  #ifdef RT_OS_SOLARIS
     382 #if defined(RT_OS_SOLARIS)  || defined(RT_OS_FREEBSD)
    381383            pAddress = (sockaddr_in *)&ifrequest[i].ifr_addr;
    382384 #else
  • trunk/src/VBox/Additions/freebsd/Makefile.kmk

    r16995 r22575  
    2828
    2929# 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
    3132
    3233# Globals
     
    6061                $(VBOX_PATH_X11_ADDITION_INSTALLER)/x11config.pl \
    6162                $(PATH_BIN)/additions/vboxguest.ko \
     63                $(PATH_BIN)/additions/vboxvideo.ko \
     64                $(PATH_BIN)/additions/vboxvfs.ko \
    6265                $(PATH_BIN)/additions/VBoxClient \
    6366                $(PATH_BIN)/additions/VBoxService \
Note: See TracChangeset for help on using the changeset viewer.

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