Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 09 Sep 2009 21:24:15 +0200
From:      Fredrik Lindberg <fli@shapeshifter.se>
To:        vbox-dev@virtualbox.org, freebsd-emulation@freebsd.org
Subject:   Enable DrvHostSerial on FreeBSD
Message-ID:  <4AA800DF.2090904@shapeshifter.se>

next in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.
--------------090606070406050409060306
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

The existing code for the host serial device (DrvHostSerial.cpp)
works on FreeBSD, it's just disabled by ifdefs.

Attached is a patch to enable it, MIT license or whatever you want.
Compile-tested on FreeBSD 7 and 8, runtime tested on FreeBSD 8.

I've tested it with a cross-over serial cable (null modem) connected
between two (physical) machines. Used cu and minicom inside guest
to connect to another cu/minicom-instance running on the second
machine.
My testing has been limited to this as I really don't have any other
fancy serial equipment :)

Notes to people trying this with the ports version, the patch
does not apply cleanly and you'll have to modify 
src/VBox/Devices/Makefile.kmk by hand.

Fredrik

--------------090606070406050409060306
Content-Type: text/plain;
 name="vbox-drvhostserial-freebsd-20090909.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
	filename="vbox-drvhostserial-freebsd-20090909.patch"

Index: src/VBox/Devices/Builtins.cpp
===================================================================
--- src/VBox/Devices/Builtins.cpp	(revision 22813)
+++ src/VBox/Devices/Builtins.cpp	(working copy)
@@ -269,7 +269,7 @@
         return rc;
 #endif
 
-#if defined(RT_OS_DARWIN) || defined(RT_OS_LINUX) || defined(RT_OS_SOLARIS) || defined(RT_OS_WINDOWS)
+#if defined(RT_OS_DARWIN) || defined(RT_OS_LINUX) || defined(RT_OS_SOLARIS) || defined(RT_OS_WINDOWS) || defined(RT_OS_FREEBSD)
     rc = pCallbacks->pfnRegister(pCallbacks, &g_DrvHostSerial);
     if (RT_FAILURE(rc))
         return rc;
Index: src/VBox/Devices/Serial/DrvHostSerial.cpp
===================================================================
--- src/VBox/Devices/Serial/DrvHostSerial.cpp	(revision 22864)
+++ src/VBox/Devices/Serial/DrvHostSerial.cpp	(working copy)
@@ -37,7 +37,7 @@
 #include <iprt/file.h>
 #include <iprt/alloc.h>
 
-#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS)
+#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
 # include <errno.h>
 # ifdef RT_OS_SOLARIS
 #  include <sys/termios.h>
@@ -113,7 +113,7 @@
     /** the device path */
     char                        *pszDevicePath;
 
-#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS)
+#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
     /** the device handle */
     RTFILE                      DeviceFile;
 # ifdef RT_OS_DARWIN
@@ -244,7 +244,7 @@
 static DECLCALLBACK(int) drvHostSerialSetParameters(PPDMICHAR pInterface, unsigned Bps, char chParity, unsigned cDataBits, unsigned cStopBits)
 {
     PDRVHOSTSERIAL pThis = PDMICHAR_2_DRVHOSTSERIAL(pInterface);
-#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS)
+#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
     struct termios *termiosSetup;
     int baud_rate;
 #elif defined(RT_OS_WINDOWS)
@@ -253,7 +253,7 @@
 
     LogFlow(("%s: Bps=%u chParity=%c cDataBits=%u cStopBits=%u\n", __FUNCTION__, Bps, chParity, cDataBits, cStopBits));
 
-#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS)
+#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
     termiosSetup = (struct termios *)RTMemTmpAllocZ(sizeof(struct termios));
 
     /* Enable receiver */
@@ -517,7 +517,7 @@
 #ifdef DEBUG
             uint64_t volatile u64Now = RTTimeNanoTS(); NOREF(u64Now);
 #endif
-#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS)
+#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
 
             size_t cbWritten;
             rc = RTFileWrite(pThis->DeviceFile, abBuf, cb, &cbWritten);
@@ -598,7 +598,7 @@
             uint8_t abBuf[1];
             abBuf[0] = pThis->aSendQueue[iTail];
 
-#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS)
+#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
 
             rc = RTFileWrite(pThis->DeviceFile, abBuf, cbProcessed, NULL);
 
@@ -763,7 +763,7 @@
             }
             cbRemaining = cbRead;
 
-#elif defined(RT_OS_LINUX) || defined(RT_OS_SOLARIS)
+#elif defined(RT_OS_LINUX) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
 
             size_t cbRead;
             struct pollfd aFDs[2];
@@ -923,7 +923,7 @@
 static DECLCALLBACK(int) drvHostSerialWakeupRecvThread(PPDMDRVINS pDrvIns, PPDMTHREAD pThread)
 {
     PDRVHOSTSERIAL pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTSERIAL);
-#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS)
+#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
     return RTFileWrite(pThis->WakeupPipeW, "", 1, NULL);
 #elif defined(RT_OS_WINDOWS)
     if (!SetEvent(pThis->hHaltEventSem))
@@ -934,7 +934,7 @@
 #endif
 }
 
-#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS)
+#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
 /* -=-=-=-=- Monitor thread -=-=-=-=- */
 
 /**
@@ -1139,7 +1139,7 @@
 {
     PDRVHOSTSERIAL pThis = PDMICHAR_2_DRVHOSTSERIAL(pInterface);
 
-#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS)
+#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
     int modemStateSet = 0;
     int modemStateClear = 0;
 
@@ -1188,7 +1188,7 @@
     /*
      * Init basic data members and interfaces.
      */
-#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS)
+#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
     pThis->DeviceFile  = NIL_RTFILE;
 # ifdef RT_OS_DARWIN
     pThis->DeviceFileR = NIL_RTFILE;
@@ -1269,7 +1269,7 @@
         {
             case VERR_ACCESS_DENIED:
                 return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS,
-#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS)
+#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
                                            N_("Cannot open host device '%s' for read/write access. Check the permissions "
                                               "of that device ('/bin/ls -l %s'): Most probably you need to be member "
                                               "of the device group. Make sure that you logout/login after changing "
@@ -1287,7 +1287,7 @@
     }
 
     /* Set to non blocking I/O */
-#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS)
+#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
 
     fcntl(pThis->DeviceFile, F_SETFL, O_NONBLOCK);
 # ifdef RT_OS_DARWIN
@@ -1339,7 +1339,7 @@
     if (RT_FAILURE(rc))
         return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS, N_("HostSerial#%d cannot create send thread"), pDrvIns->iInstance);
 
-#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS)
+#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
     /* Linux & darwin needs a separate thread which monitors the status lines. */
 # ifndef RT_OS_LINUX
     ioctl(pThis->DeviceFile, TIOCMGET, &pThis->fStatusLines);
@@ -1382,7 +1382,7 @@
     RTSemEventDestroy(pThis->SendSem);
     pThis->SendSem = NIL_RTSEMEVENT;
 
-#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS)
+#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
 
     if (pThis->WakeupPipeW != NIL_RTFILE)
     {
Index: src/VBox/Devices/Makefile.kmk
===================================================================
--- src/VBox/Devices/Makefile.kmk	(revision 22813)
+++ src/VBox/Devices/Makefile.kmk	(working copy)
@@ -803,7 +803,8 @@
 	, $(Drivers_SOURCES)) \
 	Audio/ossaudio.c
 Drivers_SOURCES.freebsd = \
-	Network/DrvTAP.cpp
+	Network/DrvTAP.cpp \
+	Serial/DrvHostSerial.cpp
 endif # freebsd
 
 

--------------090606070406050409060306--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4AA800DF.2090904>