~ubuntu-branches/ubuntu/trusty/virtualbox-ose/trusty

« back to all changes in this revision

Viewing changes to src/VBox/Devices/Serial/DrvHostSerial.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2009-12-18 16:44:29 UTC
  • mfrom: (0.3.3 upstream) (0.4.6 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091218164429-jd34ccexpv5na11a
Tags: 3.1.2-dfsg-1ubuntu1
* Merge from Debian unstable (LP: #498219), remaining changes:
  - Disable update action
    - debian/patches/u01-disable-update-action.dpatch
  - VirtualBox should go in Accessories, not in System tools (LP: #288590)
    - debian/virtualbox-ose-qt.files/virtualbox-ose.desktop
  - Add Apport hook
    - debian/virtualbox-ose.files/source_virtualbox-ose.py
    - debian/virtualbox-ose.install
  - Add Launchpad integration
    - debian/control
    - debian/lpi-bug.xpm
    - debian/patches/u02-lp-integration.dpatch
* Fixes the following bugs:
  - Kernel module fails to build with Linux >= 2.6.32 (LP: #474625)
  - X.Org drivers need to be rebuilt against X-Server 1.7 (LP: #495935)
  - The *-source packages try to build the kernel modules even though the
    kernel headers aren't available (LP: #473334)
* Replace *-source packages with transitional packages for *-dkms.
* Adapt u01-disable-update-action.dpatch and u02-lp-integration.dpatch for
  new upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
#include <iprt/file.h>
38
38
#include <iprt/alloc.h>
39
39
 
40
 
#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS)
 
40
#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
41
41
# include <errno.h>
42
42
# ifdef RT_OS_SOLARIS
43
43
#  include <sys/termios.h>
113
113
    /** the device path */
114
114
    char                        *pszDevicePath;
115
115
 
116
 
#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS)
 
116
#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
117
117
    /** the device handle */
118
118
    RTFILE                      DeviceFile;
119
119
# ifdef RT_OS_DARWIN
244
244
static DECLCALLBACK(int) drvHostSerialSetParameters(PPDMICHAR pInterface, unsigned Bps, char chParity, unsigned cDataBits, unsigned cStopBits)
245
245
{
246
246
    PDRVHOSTSERIAL pThis = PDMICHAR_2_DRVHOSTSERIAL(pInterface);
247
 
#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS)
 
247
#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
248
248
    struct termios *termiosSetup;
249
249
    int baud_rate;
250
250
#elif defined(RT_OS_WINDOWS)
517
517
#ifdef DEBUG
518
518
            uint64_t volatile u64Now = RTTimeNanoTS(); NOREF(u64Now);
519
519
#endif
520
 
#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS)
 
520
#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
521
521
 
522
522
            size_t cbWritten;
523
523
            rc = RTFileWrite(pThis->DeviceFile, abBuf, cb, &cbWritten);
598
598
            uint8_t abBuf[1];
599
599
            abBuf[0] = pThis->aSendQueue[iTail];
600
600
 
601
 
#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS)
 
601
#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
602
602
 
603
603
            rc = RTFileWrite(pThis->DeviceFile, abBuf, cbProcessed, NULL);
604
604
 
763
763
            }
764
764
            cbRemaining = cbRead;
765
765
 
766
 
#elif defined(RT_OS_LINUX) || defined(RT_OS_SOLARIS)
 
766
#elif defined(RT_OS_LINUX) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
767
767
 
768
768
            size_t cbRead;
769
769
            struct pollfd aFDs[2];
848
848
                }
849
849
                cbRemaining = dwNumberOfBytesTransferred;
850
850
            }
 
851
            else if (dwEventMask & EV_BREAK)
 
852
            {
 
853
                Log(("HostSerial#%d: Detected break\n"));
 
854
                rc = pThis->pDrvCharPort->pfnNotifyBreak(pThis->pDrvCharPort);
 
855
            }
851
856
            else
852
857
            {
853
858
                /* The status lines have changed. Notify the device. */
923
928
static DECLCALLBACK(int) drvHostSerialWakeupRecvThread(PPDMDRVINS pDrvIns, PPDMTHREAD pThread)
924
929
{
925
930
    PDRVHOSTSERIAL pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTSERIAL);
926
 
#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS)
 
931
#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
927
932
    return RTFileWrite(pThis->WakeupPipeW, "", 1, NULL);
928
933
#elif defined(RT_OS_WINDOWS)
929
934
    if (!SetEvent(pThis->hHaltEventSem))
934
939
#endif
935
940
}
936
941
 
937
 
#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS)
 
942
#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
938
943
/* -=-=-=-=- Monitor thread -=-=-=-=- */
939
944
 
940
945
/**
1139
1144
{
1140
1145
    PDRVHOSTSERIAL pThis = PDMICHAR_2_DRVHOSTSERIAL(pInterface);
1141
1146
 
1142
 
#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS)
 
1147
#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
1143
1148
    int modemStateSet = 0;
1144
1149
    int modemStateClear = 0;
1145
1150
 
1173
1178
    return VINF_SUCCESS;
1174
1179
}
1175
1180
 
 
1181
/**
 
1182
 * Sets the TD line into break condition.
 
1183
 *
 
1184
 * @returns VBox status code.
 
1185
 * @param   pInterface  Pointer to the interface structure containing the called function pointer.
 
1186
 * @param   fBreak      Set to true to let the device send a break false to put into normal operation.
 
1187
 * @thread  Any thread.
 
1188
 */
 
1189
static DECLCALLBACK(int) drvHostSerialSetBreak(PPDMICHAR pInterface, bool fBreak)
 
1190
{
 
1191
    PDRVHOSTSERIAL pThis = PDMICHAR_2_DRVHOSTSERIAL(pInterface);
 
1192
 
 
1193
#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
 
1194
    if (fBreak)
 
1195
        ioctl(pThis->DeviceFile, TIOCSBRK);
 
1196
    else
 
1197
        ioctl(pThis->DeviceFile, TIOCCBRK);
 
1198
 
 
1199
#elif defined(RT_OS_WINDOWS)
 
1200
    if (fBreak)
 
1201
        SetCommBreak(pThis->hDeviceFile);
 
1202
    else
 
1203
        ClearCommBreak(pThis->hDeviceFile);
 
1204
#endif
 
1205
 
 
1206
    return VINF_SUCCESS;
 
1207
}
 
1208
 
1176
1209
/* -=-=-=-=- driver interface -=-=-=-=- */
1177
1210
 
1178
1211
/**
1179
1212
 * Construct a char driver instance.
1180
1213
 *
1181
 
 * @returns VBox status.
1182
 
 * @param   pDrvIns     The driver instance data.
1183
 
 *                      If the registration structure is needed,
1184
 
 *                      pDrvIns->pDrvReg points to it.
1185
 
 * @param   pCfgHandle  Configuration node handle for the driver. Use this to
1186
 
 *                      obtain the configuration of the driver instance. It's
1187
 
 *                      also found in pDrvIns->pCfgHandle as it's expected to
1188
 
 *                      be used frequently in this function.
 
1214
 * @copydoc FNPDMDRVCONSTRUCT
1189
1215
 */
1190
 
static DECLCALLBACK(int) drvHostSerialConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfgHandle)
 
1216
static DECLCALLBACK(int) drvHostSerialConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfgHandle, uint32_t fFlags)
1191
1217
{
1192
1218
    PDRVHOSTSERIAL pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTSERIAL);
1193
1219
    LogFlow(("%s: iInstance=%d\n", __FUNCTION__, pDrvIns->iInstance));
1195
1221
    /*
1196
1222
     * Init basic data members and interfaces.
1197
1223
     */
1198
 
#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS)
 
1224
#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
1199
1225
    pThis->DeviceFile  = NIL_RTFILE;
1200
1226
# ifdef RT_OS_DARWIN
1201
1227
    pThis->DeviceFileR = NIL_RTFILE;
1204
1230
    pThis->WakeupPipeW = NIL_RTFILE;
1205
1231
#endif
1206
1232
    /* IBase. */
1207
 
    pDrvIns->IBase.pfnQueryInterface        = drvHostSerialQueryInterface;
 
1233
    pDrvIns->IBase.pfnQueryInterface = drvHostSerialQueryInterface;
1208
1234
    /* IChar. */
1209
 
    pThis->IChar.pfnWrite                   = drvHostSerialWrite;
1210
 
    pThis->IChar.pfnSetParameters           = drvHostSerialSetParameters;
1211
 
    pThis->IChar.pfnSetModemLines           = drvHostSerialSetModemLines;
 
1235
    pThis->IChar.pfnWrite            = drvHostSerialWrite;
 
1236
    pThis->IChar.pfnSetParameters    = drvHostSerialSetParameters;
 
1237
    pThis->IChar.pfnSetModemLines    = drvHostSerialSetModemLines;
 
1238
    pThis->IChar.pfnSetBreak         = drvHostSerialSetBreak;
1212
1239
 
1213
1240
/** @todo Initialize all members with NIL values!! The destructor is ALWAYS called. */
1214
1241
 
1260
1287
 
1261
1288
#else
1262
1289
 
1263
 
    rc = RTFileOpen(&pThis->DeviceFile, pThis->pszDevicePath, RTFILE_O_OPEN | RTFILE_O_READWRITE);
 
1290
    rc = RTFileOpen(&pThis->DeviceFile, pThis->pszDevicePath, RTFILE_O_READWRITE | RTFILE_O_OPEN | RTFILE_O_DENY_NONE);
1264
1291
# ifdef RT_OS_DARWIN
1265
1292
    if (RT_SUCCESS(rc))
1266
 
        rc = RTFileOpen(&pThis->DeviceFileR, pThis->pszDevicePath, RTFILE_O_OPEN | RTFILE_O_READ);
 
1293
        rc = RTFileOpen(&pThis->DeviceFileR, pThis->pszDevicePath, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE);
1267
1294
# endif
1268
1295
 
1269
1296
 
1276
1303
        {
1277
1304
            case VERR_ACCESS_DENIED:
1278
1305
                return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS,
1279
 
#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS)
 
1306
#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
1280
1307
                                           N_("Cannot open host device '%s' for read/write access. Check the permissions "
1281
1308
                                              "of that device ('/bin/ls -l %s'): Most probably you need to be member "
1282
1309
                                              "of the device group. Make sure that you logout/login after changing "
1294
1321
    }
1295
1322
 
1296
1323
    /* Set to non blocking I/O */
1297
 
#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS)
 
1324
#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
1298
1325
 
1299
1326
    fcntl(pThis->DeviceFile, F_SETFL, O_NONBLOCK);
1300
1327
# ifdef RT_OS_DARWIN
1346
1373
    if (RT_FAILURE(rc))
1347
1374
        return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS, N_("HostSerial#%d cannot create send thread"), pDrvIns->iInstance);
1348
1375
 
1349
 
#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS)
 
1376
#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
1350
1377
    /* Linux & darwin needs a separate thread which monitors the status lines. */
1351
1378
# ifndef RT_OS_LINUX
1352
1379
    ioctl(pThis->DeviceFile, TIOCMGET, &pThis->fStatusLines);
1389
1416
    RTSemEventDestroy(pThis->SendSem);
1390
1417
    pThis->SendSem = NIL_RTSEMEVENT;
1391
1418
 
1392
 
#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS)
 
1419
#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
1393
1420
 
1394
1421
    if (pThis->WakeupPipeW != NIL_RTFILE)
1395
1422
    {
1464
1491
    NULL,
1465
1492
    /* pfnResume */
1466
1493
    NULL,
 
1494
    /* pfnAttach */
 
1495
    NULL,
1467
1496
    /* pfnDetach */
1468
1497
    NULL,
1469
 
    /** pfnPowerOff */
1470
 
    NULL
 
1498
    /* pfnPowerOff */
 
1499
    NULL,
 
1500
    /* pfnSoftReset */
 
1501
    NULL,
 
1502
    /* u32EndVersion */
 
1503
    PDM_DRVREG_VERSION
1471
1504
};
1472
1505