- Timestamp:
- Mar 27, 2012 1:52:22 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Parallel/DrvHostParallel.cpp
r40662 r40665 47 47 48 48 49 /** @todo r=bird: The following indicator is neccessary to select the right50 * code. */51 49 /** @def VBOX_WITH_WIN_PARPORT_SUP * 52 50 * Indicates whether to use the generic direct hardware access or host specific … … 76 74 # include <cfgmgr32.h> 77 75 # include <iprt/mem.h> 76 # define CTRL_REG_OFFSET 2 77 # define STATUS_REG_OFFSET 1 78 78 #endif 79 79 … … 101 101 /** Our host device interface. */ 102 102 PDMIHOSTPARALLELCONNECTOR IHostParallelConnectorR3; 103 /** Ring-3 base interface for the ring-0 context. */104 PDMIBASER0 IBaseR0;105 103 /** Device Path */ 106 104 char *pszDevicePath; 107 105 /** Device Handle */ 108 106 RTFILE hFileDevice; 109 #ifndef VBOX_WITH_WIN_PARPORT_SUP /** @todo r=bird: Eliminate thing not needed, it rules out things you might have missed. */107 #ifndef VBOX_WITH_WIN_PARPORT_SUP 110 108 /** Thread waiting for interrupts. */ 111 109 PPDMTHREAD pMonitorThread; … … 114 112 /** Wakeup pipe write end. */ 115 113 RTPIPE hWakeupPipeW; 116 #endif117 114 /** Current mode the parallel port is in. */ 118 115 PDMPARALLELPORTMODE enmModeCur; 116 #endif 117 119 118 #ifdef VBOX_WITH_WIN_PARPORT_SUP 120 119 /** Data register. */ … … 130 129 /** Status read buffer. */ 131 130 uint8_t u8ReadInStatus; 131 /** Parallel port name */ 132 uint8_t u8ParportName[6]; 132 133 /** Whether the parallel port is available or not. */ 133 134 bool fParportAvail; 134 # ifdef IN_RING0 /** @todo r=bird: This isn't needed and will not work as you always need to declare all structure members in all contexts. (Size will differer between ring-3 and ring-0 now, meaning you'll corrupt heap because ring-3 does the alloc.) */135 typedef struct DEVICE_EXTENSION136 {137 PPARALLEL_PORT_INFORMATION pParallelInfo;138 PPARALLEL_PNP_INFORMATION pPnpInfo;139 UNICODE_STRING uniName;140 PFILE_OBJECT FileObj;141 PDEVICE_OBJECT pParallelDeviceObject;142 } DEVICE_EXTENSION, *PDEVICE_EXTENSION;143 PDEVICE_EXTENSION pDevExtn;144 # endif145 135 #endif /* VBOX_WITH_WIN_PARPORT_SUP */ 146 136 } DRVHOSTPARALLEL, *PDRVHOSTPARALLEL; … … 182 172 * 183 173 */ 184 static int drvR0HostParallelReqWrite(PPDMDRVINS pDrvIns, uint64_t u64Arg) /** @todo r=bird: PDMBOTHCBDECL is only required for entry points. Everything which doesn't need to be globally visible shall be static! */174 static int drvR0HostParallelReqWrite(PPDMDRVINS pDrvIns, uint64_t u64Arg) 185 175 { 186 176 PDRVHOSTPARALLEL pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTPARALLEL); … … 292 282 293 283 LogFlowFuncEnter(); 284 /* I have included break after each case. Need to work on this. */ 294 285 switch ((DRVHOSTPARALLELR0OP)uOperation) 295 286 { 296 287 case DRVHOSTPARALLELR0OP_READ: 297 288 rc = drvR0HostParallelReqRead(pDrvIns, u64Arg); 298 289 break; 299 290 case DRVHOSTPARALLELR0OP_READSTATUS: 300 291 rc = drvR0HostParallelReqReadStatus(pDrvIns, u64Arg); 301 292 break; 302 293 case DRVHOSTPARALLELR0OP_READCONTROL: 303 294 rc = drvR0HostParallelReqReadControl(pDrvIns, u64Arg); 304 295 break; 305 296 case DRVHOSTPARALLELR0OP_WRITE: 306 297 rc = drvR0HostParallelReqWrite(pDrvIns, u64Arg); 307 298 break; 308 299 case DRVHOSTPARALLELR0OP_WRITECONTROL: 309 300 rc = drvR0HostParallelReqWriteControl(pDrvIns, u64Arg); 310 301 break; 311 302 case DRVHOSTPARALLELR0OP_SETPORTDIRECTION: 312 303 rc = drvR0HostParallelReqSetPortDir(pDrvIns, u64Arg); 313 304 break; 314 305 default: /* not supported */ 315 306 rc = VERR_NOT_SUPPORTED; … … 329 320 * @param DevInst Device Instance for parallel port. 330 321 */ 331 static uint32_t drvHostWinFindIORangeResource(const DEVINST DevInst) /** @todo r=bird: Prefix methods like in the rest of the file, since windows specific, throw in a 'Win'. */322 static uint32_t drvHostWinFindIORangeResource(const DEVINST DevInst) 332 323 { 333 324 uint8_t *pBuf = NULL; … … 389 380 if (cmRet != CR_SUCCESS) 390 381 break; 391 /** @todo r=bird: No need to else soemthing when the 'then' clause 392 * returned or broke ouf of the loop. */ 382 393 383 CM_Free_Res_Des_Handle(nextLogConf); 394 384 nextLogConf = rdPrevResDes; … … 405 395 * @param pThis The host parallel port instance data. 406 396 */ 407 static int drv HostParallelGetParportAddr(PDRVHOSTPARALLEL pThis)397 static int drvWinHostGetparportAddr(PDRVHOSTPARALLEL pThis) 408 398 { 409 399 HDEVINFO hDevInfo; … … 433 423 RTMemFree(pBuf); 434 424 /* Max size will never be more than 2048 bytes */ 435 /** @todo r=bird: Too many parentheses and casts: (uint8_t *)((char*)RTMemAlloc(u32BufSize * 2)) */436 425 pBuf = (uint8_t *)RTMemAlloc(u32BufSize * 2); 437 426 } … … 442 431 if (pBuf) /** @todo r=bird: You're not checking errors here. */ 443 432 { 444 LogFlowFunc(("device name=%s\n", pBuf)); 445 if (strstr((char*)pBuf, "LPT")) /** @todo Use IPRT equivalent? r=klaus: make check much more precise, must be LPT + number (>= 1), without anything else before or after. */ 433 char *pCh = NULL; 434 char* pTmpCh = NULL; 435 if (strstr((char*)pBuf, "LPT")) /** @todo Use IPRT equivalent? */ 446 436 { 447 LogFlowFunc(("found parallel port\n"));448 437 u32ParportAddr = drvHostWinFindIORangeResource(DeviceInfoData.DevInst); 449 438 if (u32ParportAddr) 450 439 { 440 /* Find parallel port name and update the shared data struncture */ 441 pCh = strstr((char*)pBuf, "("); 442 pTmpCh = strstr((char *)pBuf, ")"); 443 /* check for the confirmation for the availability of parallel port */ 444 if (!(pCh && pTmpCh)) 445 { 446 LogFlowFunc(("Parallel port Not Found \n")); 447 return VERR_NOT_FOUND; 448 449 } 450 /* check for the confirmation for the availability of parallel port */ 451 if (!strncpy((char *)(pThis->u8ParportName), pCh+1, ((pTmpCh - (char *)pBuf) - 452 (pCh - (char *)pBuf)) - 1)) 453 { 454 LogFlowFunc(("Parallel Port Not Found\n")); 455 return VERR_NOT_FOUND; 456 } 457 *((char *)pThis->u8ParportName + (pTmpCh - (char *)pBuf) - (pCh - (char *)pBuf) + 1 ) = '\0'; 458 /* checking again to make sure that we have got a valid name and in valid format too. */ 459 if (!strstr((char *)pThis->u8ParportName, "LPT") || 460 !(pThis->u8ParportName[3] >= '0' && pThis->u8ParportName[3] <= '9')) { 461 pThis->u8ParportName[0] = '\0'; 462 LogFlowFunc(("Printer Port Name Not Found\n")); 463 return VERR_NOT_FOUND; 464 } 451 465 pThis->fParportAvail = true; 452 466 pThis->u32LptAddr = u32ParportAddr; 453 pThis->u32LptAddrControl = pThis->u32LptAddr + DCR_OFFSET;454 pThis->u32LptAddrStatus = pThis->u32LptAddr + DSR_OFFSET;467 pThis->u32LptAddrControl = pThis->u32LptAddr + CTRL_REG_OFFSET; 468 pThis->u32LptAddrStatus = pThis->u32LptAddr + STATUS_REG_OFFSET; 455 469 } 456 470 if (pThis->fParportAvail) … … 618 632 int rc = PDMDrvHlpCallR0(pThis->CTX_SUFF(pDrvIns), DRVHOSTPARALLELR0OP_READ, 0); 619 633 AssertRC(rc); 620 *(uint8_t *)pvBuf = (uint8_t)pThis->u8ReadIn; /** r=bird: *((uint8_t *)(pvBuf)) is too many parentheses. Heaping them up make the code harder to read. Please check C++ operator precedence rules. */634 *(uint8_t *)pvBuf = (uint8_t)pThis->u8ReadIn; 621 635 } 622 636 # endif /* VBOX_WITH_WIN_PARPORT_SUP */ … … 740 754 } 741 755 742 # ifndef VBOX_WITH_WIN_PARPORT_SUP /** @todo r=bird: This whole function is unused in the direct access path. */756 # ifndef VBOX_WITH_WIN_PARPORT_SUP 743 757 744 758 static DECLCALLBACK(int) drvHostParallelMonitorThread(PPDMDRVINS pDrvIns, PPDMTHREAD pThread) … … 958 972 959 973 #else /* VBOX_WITH_WIN_PARPORT_SUP */ 974 HANDLE hPort; 960 975 pThis->fParportAvail = false; 961 976 pThis->u32LptAddr = 0L; 962 977 pThis->u32LptAddrControl = 0L; 963 978 pThis->u32LptAddrStatus = 0L; 964 rc = drvHostParallelGetParportAddr(pThis); 965 return rc; 966 /**@todo r=bird: Just remove or #if 0 this code.*/ 967 HANDLE hPort; 968 /** @todo r=klaus convert to IPRT */ 969 hPort = CreateFile("LPT1", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, 970 NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); /** @todo r=bird: Continuation indent under start parentheses like the rest of the file. */ 971 if (hPort == INVALID_HANDLE_VALUE) /** @todo r=bird: Please, variable == constant, not the other way around. Just learn to not make accidental assignments in conditionals! */ 972 { 973 /** @todo r=klaus probably worth a nicely formatted release log entry, 974 * pointing to the device name etc etc. */ 975 LogFlowFunc(("failed to get exclusive access to parallel port\n")); 976 /** @todo r=klaus wrong kind of error code, must be IPRT error code */ 977 return GetLastError(); 978 } 979 #endif /* VBOX_WITH_WIN_PARPORT_SUP */ 979 rc = drvWinHostGetparportAddr(pThis); 980 981 /* If we have the char port availabe use it , else I am not getting exclusive access to parallel port. 982 Read and write will be done only if addresses are availabel 983 */ 984 if (pThis->u8ParportName) { 985 LogFlowFunc(("Get the Handle to Printer Port =%s\n", (char *)pThis->u8ParportName)); 986 /** @todo r=klaus convert to IPRT */ 987 hPort = CreateFile((char *)pThis->u8ParportName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, 988 NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); 989 } 990 /** @todo amakkar: handle the case if hPort is NULL */ 991 # if 0 992 if (hPort == INVALID_HANDLE_VALUE) 993 { 994 LogFlow(("Failed to get exclusive access to parallel port\n")); 995 rc = VERR_INVALID_HANDLE; 996 }*/ 997 # endif /* VBOX_WITH_WIN_PARPORT_SUP */ 980 998 return VINF_SUCCESS; 981 999 } … … 998 1016 "Parallel host driver.", 999 1017 /* fFlags */ 1000 # if defined(VBOX_WITH_WIN_PARPORT_SUP)1018 # if defined(VBOX_WITH_WIN_PARPORT_SUP) 1001 1019 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT | PDM_DRVREG_FLAGS_R0, 1002 # else1020 # else 1003 1021 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT, 1004 # endif1022 # endif 1005 1023 /* fClass. */ 1006 1024 PDM_DRVREG_CLASS_CHAR,
Note:
See TracChangeset
for help on using the changeset viewer.