Changeset 40585 in vbox for trunk/src/VBox/Devices
- Timestamp:
- Mar 23, 2012 8:55:22 AM (13 years ago)
- Location:
- trunk/src/VBox/Devices
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Makefile.kmk
r40522 r40585 636 636 VBoxDD_SOURCES.win += \ 637 637 Audio/dsoundaudio.c \ 638 Serial/DrvHostSerial.cpp 638 Serial/DrvHostSerial.cpp 639 ifdef VBOX_WITH_WIN_PARPORT_SUP 640 VBoxDD_SOURCES.win += Parallel/DrvHostParallel.cpp 641 endif 639 642 640 643 if defined(VBOX_WITH_NETFLT) … … 905 908 VBoxDDR0_DEFS = IN_RT_R0 VBOX_WITH_HGCM # - WTF is IN_RT_R0 doing here? 906 909 VBoxDDR0_INCS = build 910 VBoxDDR0_SDKS.win = WINPSDK W2K3DDK 907 911 VBoxDDR0_SOURCES = \ 908 912 build/VBoxDDR0.cpp \ … … 923 927 Serial/DevSerial.cpp \ 924 928 Parallel/DevParallel.cpp \ 929 Parallel/DrvHostParallel.cpp \ 925 930 VMMDev/VMMDevTesting.cpp \ 926 931 \ -
trunk/src/VBox/Devices/Parallel/DrvHostParallel.cpp
r40282 r40585 31 31 #include <iprt/stream.h> 32 32 #include <iprt/uuid.h> 33 #include <iprt/cdefs.h> 34 #include <iprt/ctype.h> 33 35 34 36 #ifdef RT_OS_LINUX … … 44 46 #endif 45 47 48 49 /** @todo r=bird: The following indicator is neccessary to select the right 50 * code. */ 51 /** @def VBOX_WITH_WIN_PARPORT_SUP * 52 * Indicates whether to use the generic direct hardware access or host specific 53 * code to access the parallel port. 54 */ 55 #if defined(RT_OS_LINUX) 56 # undef VBOX_WITH_WIN_PARPORT_SUP 57 #elif defined(RT_OS_WINDOWS) 58 //# define VBOX_WITH_WIN_PARPORT_SUP 59 #else 60 # error "Not ported" 61 #endif 62 63 #if defined(VBOX_WITH_WIN_PARPORT_SUP) && defined(IN_RING0) /** @todo r=bird: only needed in ring-0. Avoid unnecessary includes. */ 64 # include <Wdm.h> 65 # include <parallel.h> 66 # include <iprt/asm-amd64-x86.h> 67 #endif 68 69 #if defined(VBOX_WITH_WIN_PARPORT_SUP) && defined(IN_RING3) 70 #include <stdio.h> 71 #include <windows.h> 72 #include <devguid.h> 73 #include <setupapi.h> 74 #include <regstr.h> 75 #include<string.h> 76 #include <cfgmgr32.h> 77 #include <iprt/mem.h> 78 #endif 79 46 80 #include "VBoxDD.h" 47 48 81 49 82 /******************************************************************************* … … 58 91 /** Pointer to the driver instance structure. */ 59 92 PPDMDRVINS pDrvIns; 93 /** Pointer to the driver instance. */ 94 PPDMDRVINSR3 pDrvInsR3; 95 PPDMDRVINSR0 pDrvInsR0; 60 96 /** Pointer to the char port interface of the driver/device above us. */ 61 97 PPDMIHOSTPARALLELPORT pDrvHostParallelPort; 62 98 /** Our host device interface. */ 63 99 PDMIHOSTPARALLELCONNECTOR IHostParallelConnector; 100 /** Our host device interface. */ 101 PDMIHOSTPARALLELCONNECTOR IHostParallelConnectorR3; 102 /** Ring-3 base interface for the ring-0 context. */ 103 PDMIBASER0 IBaseR0; 64 104 /** Device Path */ 65 105 char *pszDevicePath; … … 74 114 /** Current mode the parallel port is in. */ 75 115 PDMPARALLELPORTMODE enmModeCur; 116 117 #ifdef VBOX_WITH_WIN_PARPORT_SUP 118 119 uint32_t u32LptAddr; 120 uint32_t u32LptAddrStatus; 121 uint32_t u32LptAddrControl; 122 uint8_t bReadIn; 123 uint8_t bReadInControl; 124 uint8_t bReadInStatus; 125 uint8_t bParportAvail; 126 #ifdef IN_RING0 127 128 typedef struct DEVICE_EXTNESION 129 { 130 PPARALLEL_PORT_INFORMATION pParallelInfo; 131 PPARALLEL_PNP_INFORMATION pPnpInfo; 132 UNICODE_STRING uniName; 133 PFILE_OBJECT FileObj; 134 PDEVICE_OBJECT pParallelDeviceObject; 135 }DEVICE_EXTENSION, *PDEVICE_EXTENSION; 136 PDEVICE_EXTENSION pDevExtn; 137 #endif 138 #endif 139 76 140 } DRVHOSTPARALLEL, *PDRVHOSTPARALLEL; 77 141 142 143 /** 144 * Ring-0 operations. 145 */ 146 typedef enum DRVHOSTPARALLELR0OP 147 { 148 /** Invalid zero value.. */ 149 DRVHOSTPARALLELR0OP_INVALID = 0, 150 /** Perform DrvHostparallel R0 initialization stuff */ 151 DRVHOSTPARALLELR0OP_INITR0STUFF, 152 /** To read a byte from parallel port. */ 153 DRVHOSTPARALLELR0OP_READ, 154 /**Read status register */ 155 DRVHOSTPARALLELR0OP_READSTATUS, 156 /**Read control register */ 157 DRVHOSTPARALLELR0OP_READCONTROL, 158 /** To write a byte to parallel port. */ 159 DRVHOSTPARALLELR0OP_WRITE, 160 /**Write to control register. */ 161 DRVHOSTPARALLELR0OP_WRITECONTROL, 162 /**Set Port Direciton */ 163 DRVHOSTPARALLELR0OP_SETPORTDIRECTION 164 } DRVHOSTPARALLELR0OP; 165 78 166 /** Converts a pointer to DRVHOSTPARALLEL::IHostDeviceConnector to a PDRHOSTPARALLEL. */ 79 #define PDMIHOSTPARALLELCONNECTOR_2_DRVHOSTPARALLEL(pInterface) ( (PDRVHOSTPARALLEL)((uintptr_t)pInterface - RT_OFFSETOF(DRVHOSTPARALLEL, IHostParallelConnector)) ) 167 #define PDMIHOSTPARALLELCONNECTOR_2_DRVHOSTPARALLEL(pInterface) ( (PDRVHOSTPARALLEL)((uintptr_t)pInterface - RT_OFFSETOF(DRVHOSTPARALLEL, CTX_SUFF(IHostParallelConnector))) ) 168 169 #ifdef VBOX_WITH_WIN_PARPORT_SUP 170 #ifdef IN_RING0 171 /** 172 * R0 mode function to write byte value to data port. 173 * @returns VBox status code.. 174 * @param pDrvIns Driver instance, 175 * @param u64Arg data to be written to parallel port data 176 * register 177 */ 178 PDMBOTHCBDECL(int) drvR0HostParallelReqWrite(PPDMDRVINS pDrvIns, uint64_t u64Arg) 179 { 180 PDRVHOSTPARALLEL pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTPARALLEL); 181 LogFlow(("%s Write to PPort = %x data = %x\n", __FUNCTION__, pThis->u32LptAddr, u64Arg)); 182 ASMOutU8(pThis->u32LptAddr, (uint8_t)(u64Arg)); 183 return VINF_SUCCESS; 184 } 185 186 /** 187 * R0 mode function to write byte value to paralell port control 188 * register . 189 * @returns VBox status code.. 190 * @param pDrvIns Driver instance, 191 * @param u64Arg data to be written 192 */ 193 PDMBOTHCBDECL(int) drvR0HostParallelReqWriteControl(PPDMDRVINS pDrvIns, uint64_t u64Arg) 194 { 195 PDRVHOSTPARALLEL pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTPARALLEL); 196 LogFlow(("%s Write to Ctrl PPort = %x data = %x\n", __FUNCTION__, pThis->u32LptAddrControl, u64Arg)); 197 ASMOutU8(pThis->u32LptAddrControl, (uint8_t)(u64Arg)); 198 return VINF_SUCCESS; 199 } 200 201 /** 202 * R0 mode function to ready byte value from the parallel port 203 * data register 204 * @returns VBox status code.. 205 * @param pDrvIns Driver instance, 206 * @param u64Arg 0 (not used) 207 */ 208 PDMBOTHCBDECL(int) drvR0HostParallelReqRead(PPDMDRVINS pDrvIns, uint64_t u64Arg) 209 { 210 uint8_t u8Data; 211 LogFlow(("%s Read from PPort\n", __FUNCTION__)); 212 PDRVHOSTPARALLEL pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTPARALLEL); 213 u8Data = ASMInU8(pThis->u32LptAddr); 214 LogFlow(("Data Read from PPort = %x", u8Data)); 215 pThis->bReadIn = u8Data; 216 return VINF_SUCCESS; 217 } 218 219 220 /** 221 * R0 mode function to ready byte value from the parallel port 222 * control register 223 * @returns VBox status code.. 224 * @param pDrvIns Driver instance, 225 * @param u64Arg 0 (not used) 226 */ 227 PDMBOTHCBDECL(int) drvR0HostParallelReqReadControl(PPDMDRVINS pDrvIns, uint64_t u64Arg) 228 { 229 uint8_t u8Data; 230 LogFlow(("%s Read from PPort control\n", __FUNCTION__)); 231 PDRVHOSTPARALLEL pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTPARALLEL); 232 u8Data = ASMInU8(pThis->u32LptAddrControl); 233 LogFlow(("Data Read from PPort = %x\n", u8Data)); 234 pThis->bReadInControl = u8Data; 235 return VINF_SUCCESS; 236 } 237 238 /** 239 * R0 mode function to ready byte value from the parallel port 240 * status register 241 * @returns VBox status code.. 242 * @param pDrvIns Driver instance, 243 * @param u64Arg 0 (not used) 244 */ 245 PDMBOTHCBDECL(int) drvR0HostParallelReqReadStatus(PPDMDRVINS pDrvIns, uint64_t u64Arg) 246 { 247 uint8_t u8Data; 248 LogFlow(("%s Read from PPort Status\n", __FUNCTION__)); 249 PDRVHOSTPARALLEL pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTPARALLEL); 250 u8Data = ASMInU8(pThis->u32LptAddrStatus); 251 LogFlow(("Data Read from PPort = %x\n", u8Data)); 252 pThis->bReadInStatus = u8Data; 253 return VINF_SUCCESS; 254 } 255 /** 256 * R0 mode function to set the direction of parallel port - 257 * operate in bidirectional mode or single direction 258 * @returns VBox status code.. 259 * @param pDrvIns Driver instance, 260 * @param u64Arg mode 261 */ 262 PDMBOTHCBDECL(int) drvR0HostParallelReqSetPortDir(PPDMDRVINS pDrvIns, uint64_t u64Arg) 263 { 264 uint8_t u8ReadControlVal; 265 uint8_t u8WriteControlVal; 266 uint8_t u8TmpData; 267 PDRVHOSTPARALLEL pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTPARALLEL); 268 269 if(u64Arg) { 270 u8TmpData = 0x08; /**setting the control bit*/ 271 u8ReadControlVal = ASMInU8(pThis->u32LptAddrControl); 272 u8WriteControlVal = u8ReadControlVal | u8TmpData; 273 ASMOutU8(pThis->u32LptAddrControl, u8WriteControlVal); 274 } 275 else 276 { 277 u8TmpData = 0xF7; /** clearing the control register 5th bit*/ 278 u8ReadControlVal = ASMInU8(pThis->u32LptAddrControl); 279 u8WriteControlVal = u8ReadControlVal & u8TmpData; 280 ASMOutU8(pThis->u32LptAddrControl, u8WriteControlVal); 281 } 282 return VINF_SUCCESS; 283 284 } 285 286 287 /** 288 * @interface_method_impl{FNPDMDRVREQHANDLERR0} 289 */ 290 PDMBOTHCBDECL(int) drvR0HostParallelReqHandler(PPDMDRVINS pDrvIns, uint32_t uOperation, uint64_t u64Arg) 291 { 292 LogFlow(("Requst Handler\n")); 293 switch ((DRVHOSTPARALLELR0OP)uOperation) 294 { 295 case DRVHOSTPARALLELR0OP_READ: 296 LogFlow(("Read Op\n")); 297 return drvR0HostParallelReqRead(pDrvIns, u64Arg); 298 break; 299 case DRVHOSTPARALLELR0OP_READSTATUS: 300 LogFlow(("Read Status \n")); 301 return drvR0HostParallelReqReadStatus(pDrvIns, u64Arg); 302 break; 303 case DRVHOSTPARALLELR0OP_READCONTROL: 304 LogFlow(("Read CTRL\n")); 305 return drvR0HostParallelReqReadControl(pDrvIns, u64Arg); 306 break; 307 case DRVHOSTPARALLELR0OP_WRITE: 308 LogFlow(("Write Ope\n")); 309 return drvR0HostParallelReqWrite(pDrvIns, u64Arg); 310 break; 311 case DRVHOSTPARALLELR0OP_WRITECONTROL: 312 LogFlow(("Write CTRL\n")); 313 return drvR0HostParallelReqWriteControl(pDrvIns, u64Arg); 314 break; 315 case DRVHOSTPARALLELR0OP_SETPORTDIRECTION: 316 LogFlow(("Set Port Direction")); 317 return drvR0HostParallelReqSetPortDir(pDrvIns, u64Arg); 318 default: 319 return 0; 320 /** Not Supported. */ 321 } 322 } 323 #endif /**IN_RING0*/ 324 #endif /**VBOX_WITH_WIN_PARPORT_SUP*/ 325 326 #ifdef IN_RING3 327 #ifdef VBOX_WITH_WIN_PARPORT_SUP 328 /** 329 * Find IO port range for the parallel port and return the lower 330 * address. 331 * @returns parallel port IO address. 332 * @param DevInst Device Instance for parallel port. 333 */ 334 static uint32_t FindIORangeResource(const DEVINST DevInst) 335 { 336 uint8_t *pBuf = NULL; 337 short wHeaderSize; 338 uint32_t u32Size; 339 CONFIGRET cmRet; 340 LOG_CONF firstLogConf; 341 LOG_CONF nextLogConf; 342 RES_DES rdPrevResDes; 343 uint32_t u32ParportAddr; 344 345 wHeaderSize = sizeof(IO_DES); 346 cmRet = CM_Get_First_Log_Conf(&firstLogConf, DevInst, ALLOC_LOG_CONF); 347 if (cmRet != CR_SUCCESS) 348 { 349 cmRet = CM_Get_First_Log_Conf(&firstLogConf, DevInst, BOOT_LOG_CONF); 350 if (cmRet != CR_SUCCESS) 351 return 0; 352 } 353 cmRet = CM_Get_Next_Res_Des(&nextLogConf, firstLogConf, 2, 0L,0L); 354 if (cmRet != CR_SUCCESS) 355 { 356 CM_Free_Res_Des_Handle(firstLogConf); 357 return 0; 358 } 359 while (1) 360 { 361 u32Size = 0; 362 cmRet = CM_Get_Res_Des_Data_Size((PULONG)(&u32Size), nextLogConf, 0L); 363 if (cmRet != CR_SUCCESS) 364 { 365 CM_Free_Res_Des_Handle(nextLogConf); 366 break; 367 } 368 pBuf = (uint8_t *)((char*)RTMemAlloc(u32Size+1)); 369 if (!pBuf) 370 { 371 CM_Free_Res_Des_Handle(nextLogConf); 372 break; 373 }; 374 cmRet = CM_Get_Res_Des_Data(nextLogConf, pBuf, u32Size, 0L); 375 if (cmRet != CR_SUCCESS) 376 { 377 CM_Free_Res_Des_Handle(nextLogConf); 378 LocalFree(pBuf); 379 break; 380 } 381 LogFlow(("Call GetIOResource\n")); 382 u32ParportAddr = ((IO_DES*)(pBuf))->IOD_Alloc_Base; 383 LogFlow(("Called GetIOResource. Ret = %x\n", u32ParportAddr)); 384 rdPrevResDes = 0; 385 cmRet = CM_Get_Next_Res_Des(&rdPrevResDes, 386 nextLogConf, 387 2, 388 0L, 389 0L); 390 RTMemFree(pBuf); 391 if (cmRet != CR_SUCCESS) 392 break; 393 else 394 { 395 CM_Free_Res_Des_Handle(nextLogConf); 396 nextLogConf = rdPrevResDes; 397 } 398 } 399 CM_Free_Res_Des_Handle(nextLogConf); 400 LogFlow(("Return u32ParportAddr=%x", u32ParportAddr)); 401 return u32ParportAddr; 402 } 403 404 /** 405 * Get Parallel port address and update the shared data 406 * structure. 407 * @returns VBox status code. 408 * @param pThis The host parallel port instance data. 409 */ 410 static int drvHostParallelGetParportAddr(PDRVHOSTPARALLEL pThis) 411 { 412 HDEVINFO hDevInfo; 413 SP_DEVINFO_DATA DeviceInfoData; 414 uint32_t u32Idx; 415 uint32_t u32ParportAddr; 416 int rc = VINF_SUCCESS; 417 418 hDevInfo = SetupDiGetClassDevs(NULL,0, 0, DIGCF_PRESENT | DIGCF_ALLCLASSES ); 419 if (hDevInfo == INVALID_HANDLE_VALUE) 420 return VERR_INVALID_HANDLE; 421 422 // Enumerate through all devices in Set. 423 DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA); 424 for (u32Idx=0;SetupDiEnumDeviceInfo(hDevInfo,u32Idx,&DeviceInfoData);u32Idx++) 425 { 426 uint32_t u32DataType; 427 uint8_t *pBuf = NULL; 428 uint32_t u32BufSize = 0; 429 430 while (!SetupDiGetDeviceRegistryProperty(hDevInfo,&DeviceInfoData, SPDRP_FRIENDLYNAME,(PDWORD)&u32DataType,(uint8_t *)pBuf, 431 u32BufSize,(PDWORD)&u32BufSize)) 432 { 433 if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) 434 { 435 if (pBuf) 436 RTMemFree(pBuf); 437 /**Max size will never reach more than 2048 bytes */ 438 pBuf = (uint8_t *)((char*)RTMemAlloc(u32BufSize * 2)); 439 } 440 else 441 break; 442 } 443 444 if(pBuf) 445 { 446 LogFlow(("Buffer = %s\n", pBuf)); 447 if(strstr((char*)pBuf, "LPT")) 448 { 449 LogFlow(("Found parallel port\n")); 450 u32ParportAddr = FindIORangeResource(DeviceInfoData.DevInst); 451 if(u32ParportAddr) 452 { 453 pThis->bParportAvail = true; 454 pThis->u32LptAddr = u32ParportAddr; 455 pThis->u32LptAddrControl = pThis->u32LptAddr +2; 456 pThis->u32LptAddrStatus = pThis->u32LptAddr + 1; 457 } 458 if(pThis->bParportAvail) 459 break; 460 } 461 } 462 if (pBuf) /**cleanup*/ 463 RTMemFree(pBuf); 464 if(pThis->bParportAvail) { 465 /**parport address has been found. No Need to iterate 466 * further. */ 467 break; 468 } 469 } 470 471 if ( GetLastError()!=NO_ERROR &&GetLastError()!=ERROR_NO_MORE_ITEMS ) 472 { 473 rc = VERR_GENERAL_FAILURE;; 474 } 475 SetupDiDestroyDeviceInfoList(hDevInfo); 476 return rc; 477 478 } 479 #endif /**VBOX_WITH_WIN_PARPORT_SUP*/ 80 480 81 481 /** … … 90 490 int iMode = 0; 91 491 int rc = VINF_SUCCESS; 492 LogFlow(("%s: mode=%d\n", __FUNCTION__, enmMode)); 493 #ifndef VBOX_WITH_WIN_PARPORT_SUP 92 494 int rcLnx; 93 94 LogFlow(("%s: mode=%d\n", __FUNCTION__, enmMode));95 96 495 if (pThis->enmModeCur != enmMode) 97 496 { … … 121 520 122 521 return rc; 522 #else /* VBOX_WITH_WIN_PARPORT_SUP */ 523 return VINF_SUCCESS; 524 #endif /* VBOX_WITH_WIN_PARPORT_SUP */ 123 525 } 124 526 … … 134 536 135 537 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase); 136 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIHOSTPARALLELCONNECTOR, &pThis-> IHostParallelConnector);538 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIHOSTPARALLELCONNECTOR, &pThis->CTX_SUFF(IHostParallelConnector)); 137 539 return NULL; 138 540 } 541 139 542 140 543 /* -=-=-=-=- IHostDeviceConnector -=-=-=-=- */ … … 143 546 static DECLCALLBACK(int) drvHostParallelWrite(PPDMIHOSTPARALLELCONNECTOR pInterface, const void *pvBuf, size_t cbWrite, PDMPARALLELPORTMODE enmMode) 144 547 { 145 PDRVHOSTPARALLEL pThis = PDMIHOSTPARALLELCONNECTOR_2_DRVHOSTPARALLEL(pInterface); 548 PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface); 549 //PDRVHOSTPARALLEL pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTPARALLEL); 550 PDRVHOSTPARALLEL pThis = RT_FROM_MEMBER(pInterface, DRVHOSTPARALLEL, CTX_SUFF(IHostParallelConnector)); 146 551 int rc = VINF_SUCCESS; 147 552 int rcLnx = 0; … … 152 557 if (RT_FAILURE(rc)) 153 558 return rc; 154 559 #ifndef VBOX_WITH_WIN_PARPORT_SUP 155 560 if (enmMode == PDM_PARALLEL_PORT_MODE_SPP) 156 561 { … … 164 569 } 165 570 if (RT_UNLIKELY(rcLnx < 0)) 166 rc = RTErrConvertFromErrno(errno); 167 571 rc = RTErrConvertFromErrno(errno); 572 #else /*VBOX_WITH_WIN_PARPORT_SUP*/ 573 uint64_t u64Data; 574 u64Data = (uint8_t) *((uint8_t *)(pvBuf)); 575 LogFlow(("%s: Calling R0 to write to parallel port. Data is %d\n", __FUNCTION__, u64Data)); 576 if(pThis->bParportAvail) 577 { 578 rc = PDMDrvHlpCallR0(pThis->CTX_SUFF(pDrvIns), DRVHOSTPARALLELR0OP_WRITE, u64Data); 579 if (RT_FAILURE(rc)) 580 AssertRC(rc); 581 } 582 #endif /* VBOX_WITH_WIN_PARPORT_SUP */ 168 583 return rc; 169 584 } 170 585 586 /** 587 * @interface_method_impl{PDMIBASE,pfnRead} 588 */ 171 589 static DECLCALLBACK(int) drvHostParallelRead(PPDMIHOSTPARALLELCONNECTOR pInterface, void *pvBuf, size_t cbRead, PDMPARALLELPORTMODE enmMode) 172 { 173 PDRVHOSTPARALLEL pThis = PDMIHOSTPARALLELCONNECTOR_2_DRVHOSTPARALLEL(pInterface);590 { 591 PDRVHOSTPARALLEL pThis = RT_FROM_MEMBER(pInterface, DRVHOSTPARALLEL, CTX_SUFF(IHostParallelConnector)); 174 592 int rc = VINF_SUCCESS; 593 594 #ifndef VBOX_WITH_WIN_PARPORT_SUP 175 595 int rcLnx = 0; 176 177 596 LogFlow(("%s: pvBuf=%#p cbRead=%d\n", __FUNCTION__, pvBuf, cbRead)); 178 597 … … 193 612 if (RT_UNLIKELY(rcLnx < 0)) 194 613 rc = RTErrConvertFromErrno(errno); 195 614 #else /* VBOX_WITH_WIN_PARPORT_SUP */ 615 *((uint8_t*)(pvBuf)) = 0; /** initialize the buffer*/ 616 LogFlow(("%s: Calling R0 to Read from PPort\n", __FUNCTION__)); 617 if(pThis->bParportAvail) 618 { 619 int rc = PDMDrvHlpCallR0(pThis->CTX_SUFF(pDrvIns), DRVHOSTPARALLELR0OP_READ, 0); 620 if (RT_FAILURE(rc)) 621 AssertRC(rc); 622 *((uint8_t*)(pvBuf)) = (uint8_t)pThis->bReadIn; 623 } 624 #endif 196 625 return rc; 197 626 } … … 199 628 static DECLCALLBACK(int) drvHostParallelSetPortDirection(PPDMIHOSTPARALLELCONNECTOR pInterface, bool fForward) 200 629 { 201 PDRVHOSTPARALLEL pThis = PDMIHOSTPARALLELCONNECTOR_2_DRVHOSTPARALLEL(pInterface);630 PDRVHOSTPARALLEL pThis = RT_FROM_MEMBER(pInterface, DRVHOSTPARALLEL, CTX_SUFF(IHostParallelConnector)); 202 631 int rc = VINF_SUCCESS; 203 632 int rcLnx = 0; … … 206 635 if (!fForward) 207 636 iMode = 1; 208 637 #ifndef VBOX_WITH_WIN_PARPORT_SUP 209 638 rcLnx = ioctl(RTFileToNative(pThis->hFileDevice), PPDATADIR, &iMode); 210 639 if (RT_UNLIKELY(rcLnx < 0)) 211 640 rc = RTErrConvertFromErrno(errno); 212 641 #else /* VBOX_WITH_WIN_PARPORT_SUP */ 642 uint64_t u64Data; 643 u64Data = (uint8_t)iMode; 644 LogFlow(("%s: Calling R0 to write CTRL . Data is %x\n", __FUNCTION__, u64Data)); 645 if(pThis->bParportAvail) 646 { 647 rc = PDMDrvHlpCallR0(pThis->CTX_SUFF(pDrvIns), DRVHOSTPARALLELR0OP_SETPORTDIRECTION, u64Data); 648 if (RT_FAILURE(rc)) 649 AssertRC(rc); 650 } 651 #endif /* VBOX_WITH_WIN_PARPORT_SUP */ 213 652 return rc; 214 653 } 215 654 655 /** 656 * @interface_method_impl{PDMIBASE,pfnWriteControl} 657 */ 216 658 static DECLCALLBACK(int) drvHostParallelWriteControl(PPDMIHOSTPARALLELCONNECTOR pInterface, uint8_t fReg) 217 659 { 218 PDRVHOSTPARALLEL pThis = PDMIHOSTPARALLELCONNECTOR_2_DRVHOSTPARALLEL(pInterface);660 PDRVHOSTPARALLEL pThis = RT_FROM_MEMBER(pInterface, DRVHOSTPARALLEL, CTX_SUFF(IHostParallelConnector)); 219 661 int rc = VINF_SUCCESS; 220 662 int rcLnx = 0; 221 663 222 664 LogFlow(("%s: fReg=%d\n", __FUNCTION__, fReg)); 665 # ifndef VBOX_WITH_WIN_PARPORT_SUP 223 666 rcLnx = ioctl(RTFileToNative(pThis->hFileDevice), PPWCONTROL, &fReg); 224 667 if (RT_UNLIKELY(rcLnx < 0)) 225 668 rc = RTErrConvertFromErrno(errno); 226 669 #else /* VBOX_WITH_WIN_PARPORT_SUP */ 670 uint64_t u64Data; 671 u64Data = (uint8_t)fReg; 672 LogFlow(("%s: Calling R0 to write CTRL . Data is %x\n", __FUNCTION__, u64Data)); 673 if(pThis->bParportAvail) 674 { 675 rc = PDMDrvHlpCallR0(pThis->CTX_SUFF(pDrvIns), DRVHOSTPARALLELR0OP_WRITECONTROL, u64Data); 676 if (RT_FAILURE(rc)) 677 AssertRC(rc); 678 } 679 #endif /* VBOX_WITH_WIN_PARPORT_SUP */ 227 680 return rc; 228 681 } 229 682 683 684 /** 685 * @interface_method_impl{PDMIBASE,pfnReadControl} 686 */ 230 687 static DECLCALLBACK(int) drvHostParallelReadControl(PPDMIHOSTPARALLELCONNECTOR pInterface, uint8_t *pfReg) 231 688 { 232 PDRVHOSTPARALLEL pThis = PDMIHOSTPARALLELCONNECTOR_2_DRVHOSTPARALLEL(pInterface);689 PDRVHOSTPARALLEL pThis = RT_FROM_MEMBER(pInterface, DRVHOSTPARALLEL, CTX_SUFF(IHostParallelConnector)); 233 690 int rc = VINF_SUCCESS; 234 691 int rcLnx = 0; 235 692 uint8_t fReg = 0; 236 693 694 #ifndef VBOX_WITH_WIN_PARPORT_SUP 237 695 rcLnx = ioctl(RTFileToNative(pThis->hFileDevice), PPRCONTROL, &fReg); 238 696 if (RT_UNLIKELY(rcLnx < 0)) … … 243 701 *pfReg = fReg; 244 702 } 245 703 #else /* VBOX_WITH_WIN_PARPORT_SUP */ 704 *pfReg = 0; /** initialize the buffer*/ 705 if(pThis->bParportAvail) 706 { 707 LogFlow(("%s: Calling R0 to Read Control from PPort\n", __FUNCTION__)); 708 rc = PDMDrvHlpCallR0(pThis-> CTX_SUFF(pDrvIns), DRVHOSTPARALLELR0OP_READCONTROL, 0); 709 if (RT_FAILURE(rc)) 710 AssertRC(rc); 711 *pfReg = pThis->bReadInControl; 712 } 713 #endif /* VBOX_WITH_WIN_PARPORT_SUP */ 246 714 return rc; 247 715 } 248 716 717 /** 718 * @interface_method_impl{PDMIBASE,pfnReadStatus} 719 */ 249 720 static DECLCALLBACK(int) drvHostParallelReadStatus(PPDMIHOSTPARALLELCONNECTOR pInterface, uint8_t *pfReg) 250 721 { 251 PDRVHOSTPARALLEL pThis = PDMIHOSTPARALLELCONNECTOR_2_DRVHOSTPARALLEL(pInterface);722 PDRVHOSTPARALLEL pThis = RT_FROM_MEMBER(pInterface, DRVHOSTPARALLEL, CTX_SUFF(IHostParallelConnector)); 252 723 int rc = VINF_SUCCESS; 253 724 int rcLnx = 0; 254 725 uint8_t fReg = 0; 255 726 #ifndef VBOX_WITH_WIN_PARPORT_SUP 256 727 rcLnx = ioctl(RTFileToNative(pThis->hFileDevice), PPRSTATUS, &fReg); 257 728 if (RT_UNLIKELY(rcLnx < 0)) … … 262 733 *pfReg = fReg; 263 734 } 264 735 #else /* VBOX_WITH_WIN_PARPORT_SUP */ 736 *pfReg = 0; /**intialize the buffer*/ 737 if(pThis->bParportAvail) 738 { 739 LogFlow(("%s: Calling R0 to Read Status from Pport\n", __FUNCTION__)); 740 rc = PDMDrvHlpCallR0(pThis->CTX_SUFF(pDrvIns), DRVHOSTPARALLELR0OP_READSTATUS, 0); 741 if (RT_FAILURE(rc)) 742 AssertRC(rc); 743 *pfReg = pThis->bReadInStatus; 744 } 745 #endif /* VBOX_WITH_WIN_PARPORT_SUP */ 265 746 return rc; 266 747 } … … 269 750 { 270 751 PDRVHOSTPARALLEL pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTPARALLEL); 752 753 #ifndef VBOX_WITH_WIN_PARPORT_SUP 271 754 struct pollfd aFDs[2]; 272 273 755 /* 274 756 * We can wait for interrupts using poll on linux hosts. … … 308 790 AssertRC(rc); 309 791 } 792 #else /* VBOX_WITH_WIN_PARPORT_SUP */ 793 #endif /* VBOX_WITH_WIN_PARPORT_SUP */ 310 794 311 795 return VINF_SUCCESS; … … 339 823 LogFlow(("%s: iInstance=%d\n", __FUNCTION__, pDrvIns->iInstance)); 340 824 PDMDRV_CHECK_VERSIONS_RETURN_VOID(pDrvIns); 825 #ifndef VBOX_WITH_WIN_PARPORT_SUP 826 341 827 int rc; 342 828 … … 358 844 pThis->pszDevicePath = NULL; 359 845 } 846 #else /* VBOX_WITH_WIN_PARPORT_SUP */ 847 #endif /* VBOX_WITH_WIN_PARPORT_SUP */ 360 848 } 361 849 … … 369 857 PDRVHOSTPARALLEL pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTPARALLEL); 370 858 LogFlow(("%s: iInstance=%d\n", __FUNCTION__, pDrvIns->iInstance)); 859 371 860 PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns); 372 861 … … 380 869 pThis->hWakeupPipeW = NIL_RTPIPE; 381 870 871 pThis->pDrvInsR3 = pDrvIns; 872 #ifdef VBOX_WITH_DRVINTNET_IN_R0 873 pThis->pDrvInsR0 = PDMDRVINS_2_R0PTR(pDrvIns); 874 #endif 875 382 876 /* IBase. */ 383 877 pDrvIns->IBase.pfnQueryInterface = drvHostParallelQueryInterface; 384 878 /* IHostParallelConnector. */ 385 pThis->IHostParallelConnector .pfnWrite = drvHostParallelWrite;386 pThis->IHostParallelConnector .pfnRead = drvHostParallelRead;387 pThis->IHostParallelConnector .pfnSetPortDirection = drvHostParallelSetPortDirection;388 pThis->IHostParallelConnector .pfnWriteControl = drvHostParallelWriteControl;389 pThis->IHostParallelConnector .pfnReadControl = drvHostParallelReadControl;390 pThis->IHostParallelConnector .pfnReadStatus = drvHostParallelReadStatus;391 879 pThis->IHostParallelConnectorR3.pfnWrite = drvHostParallelWrite; 880 pThis->IHostParallelConnectorR3.pfnRead = drvHostParallelRead; 881 pThis->IHostParallelConnectorR3.pfnSetPortDirection = drvHostParallelSetPortDirection; 882 pThis->IHostParallelConnectorR3.pfnWriteControl = drvHostParallelWriteControl; 883 pThis->IHostParallelConnectorR3.pfnReadControl = drvHostParallelReadControl; 884 pThis->IHostParallelConnectorR3.pfnReadStatus = drvHostParallelReadStatus; 885 392 886 /* 393 887 * Validate the config. … … 415 909 return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS, N_("Parallel#%d could not open '%s'"), 416 910 pDrvIns->iInstance, pThis->pszDevicePath); 417 911 #ifndef VBOX_WITH_WIN_PARPORT_SUP 418 912 /* 419 913 * Try to get exclusive access to parallel port … … 461 955 * Start waiting for interrupts. 462 956 */ 463 rc = PDMDrvHlpThreadCreate(pDrvIns, &pThis->pMonitorThread, pThis, drvHostParallelMonitorThread, drvHostParallelWakeupMonitorThread, 0,957 rc = PDMDrvHlpThreadCreate(pDrvIns, &pThis->pMonitorThread, pThis, drvHostParallelMonitorThread, drvHostParallelWakeupMonitorThread, 0, 464 958 RTTHREADTYPE_IO, "ParMon"); 465 959 if (RT_FAILURE(rc)) 466 960 return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS, N_("HostParallel#%d cannot create monitor thread"), pDrvIns->iInstance); 467 468 961 962 #else /* VBOX_WITH_WIN_PARPORT_SUP */ 963 /**intialize with parallel port availability = false */ 964 pThis->bParportAvail = false; 965 /**initialize parallel port data register address to NULL */ 966 pThis->u32LptAddr =0L; 967 /**initialize parallel port control register address to NULL */ 968 pThis->u32LptAddrControl = 0L; 969 /**initialize parallel port Status register address to NULL */ 970 pThis->u32LptAddrStatus = 0L; 971 rc = drvHostParallelGetParportAddr(pThis); 972 return rc; 973 HANDLE hPort; 974 hPort = CreateFile("LPT1", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, 975 NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); 976 if (INVALID_HANDLE_VALUE == hPort) { 977 LogFlow(("Failed to get exclusive access to parallel port\n")); 978 return (GetLastError()); 979 } 980 #endif /* VBOX_WITH_WIN_PARPORT_SUP */ 469 981 return VINF_SUCCESS; 470 982 } 983 471 984 472 985 /** … … 482 995 "", 483 996 /* szR0Mod */ 484 " ",997 "VBoxDDR0.r0", 485 998 /* pszDescription */ 486 999 "Parallel host driver.", 487 1000 /* fFlags */ 1001 #if defined(VBOX_WITH_WIN_PARPORT_SUP) 1002 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT| PDM_DRVREG_FLAGS_R0, 1003 #else 488 1004 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT, 1005 #endif 489 1006 /* fClass. */ 490 1007 PDM_DRVREG_CLASS_CHAR, … … 520 1037 PDM_DRVREG_VERSION 521 1038 }; 522 1039 #endif /*IN_RING3*/ 1040 1041 -
trunk/src/VBox/Devices/build/VBoxDD.cpp
r38913 r40585 282 282 if (RT_FAILURE(rc)) 283 283 return rc; 284 285 #if defined(RT_OS_LINUX) 284 #if defined(RT_OS_LINUX) || defined(VBOX_WITH_WIN_PARPORT_SUP) 286 285 rc = pCallbacks->pfnRegister(pCallbacks, &g_DrvHostParallel); 287 286 if (RT_FAILURE(rc)) 288 287 return rc; 289 288 #endif 289 290 290 291 291 292 #if defined(RT_OS_DARWIN) || defined(RT_OS_LINUX) || defined(RT_OS_SOLARIS) || defined(RT_OS_WINDOWS) || defined(RT_OS_FREEBSD)
Note:
See TracChangeset
for help on using the changeset viewer.