- Timestamp:
- Jul 13, 2012 7:31:42 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Parallel/DrvHostParallel.cpp
r40707 r42152 60 60 61 61 #if defined(VBOX_WITH_WIN_PARPORT_SUP) && defined(IN_RING0) 62 # include <Wdm.h>63 # include <parallel.h>64 62 # include <iprt/asm-amd64-x86.h> 65 63 #endif 66 64 67 65 #if defined(VBOX_WITH_WIN_PARPORT_SUP) && defined(IN_RING3) 68 # include <stdio.h> 69 # include <windows.h> 70 # include <devguid.h> 66 # include <Windows.h> 71 67 # include <setupapi.h> 72 # include <regstr.h>73 # include <string.h>74 68 # include <cfgmgr32.h> 75 69 # include <iprt/mem.h> 76 # define CTRL_REG_OFFSET 2 77 # define STATUS_REG_OFFSET 1 70 # include <iprt/string.h> 78 71 #endif 79 72 … … 130 123 uint8_t u8ReadInStatus; 131 124 /** Parallel port name */ 125 /** @todo r=bird: This is an array, they start with 'a'. However, this seems 126 * to be a string, and they are not uint8_t but char and are prefixed with 'sz' 127 * in char array form. 128 * 129 * Also, the use of tabs as indentation in anything but Makefiles is 130 * forbidden. That is not a guideline, it's the law. :-) (See above line.) */ 132 131 uint8_t u8ParportName[6]; 133 132 /** Whether the parallel port is available or not. */ … … 163 162 #define PDMIHOSTPARALLELCONNECTOR_2_DRVHOSTPARALLEL(pInterface) ( (PDRVHOSTPARALLEL)((uintptr_t)pInterface - RT_OFFSETOF(DRVHOSTPARALLEL, CTX_SUFF(IHostParallelConnector))) ) 164 163 164 165 /******************************************************************************* 166 * Defined Constants And Macros * 167 *******************************************************************************/ 168 #define CTRL_REG_OFFSET 2 169 #define STATUS_REG_OFFSET 1 170 #define LPT_CONTROL_ENABLE_BIDIRECT 0x20 171 172 173 165 174 #ifdef VBOX_WITH_WIN_PARPORT_SUP 166 #ifdef IN_RING0 175 # ifdef IN_RING0 176 167 177 /** 168 178 * R0 mode function to write byte value to data port. … … 262 272 { 263 273 u8ReadControlVal = ASMInU8(pThis->u32LptAddrControl); 264 u8WriteControlVal = u8ReadControlVal | DCR_DIRECTION; /* enable input direction */274 u8WriteControlVal = u8ReadControlVal | LPT_CONTROL_ENABLE_BIDIRECT; /* enable input direction */ 265 275 ASMOutU8(pThis->u32LptAddrControl, u8WriteControlVal); 266 276 } … … 268 278 { 269 279 u8ReadControlVal = ASMInU8(pThis->u32LptAddrControl); 270 u8WriteControlVal = u8ReadControlVal & ~ DCR_DIRECTION; /* disable input direction */280 u8WriteControlVal = u8ReadControlVal & ~LPT_CONTROL_ENABLE_BIDIRECT; /* disable input direction */ 271 281 ASMOutU8(pThis->u32LptAddrControl, u8WriteControlVal); 272 282 } … … 309 319 return rc; 310 320 } 311 #endif /* IN_RING0 */ 321 322 # endif /* IN_RING0 */ 312 323 #endif /* VBOX_WITH_WIN_PARPORT_SUP */ 313 324 314 325 #ifdef IN_RING3 315 326 # ifdef VBOX_WITH_WIN_PARPORT_SUP 327 316 328 /** 317 329 * Find IO port range for the parallel port and return the lower address. … … 411 423 for (u32Idx = 0; SetupDiEnumDeviceInfo(hDevInfo, u32Idx, &DeviceInfoData); u32Idx++) 412 424 { 413 uint32_t u32DataType; 425 uint32_t u32DataType; /** @todo r=bird: why do you use uint32_t here when the function wants a DWORD? */ 414 426 uint8_t *pBuf = NULL; 415 uint32_t u32BufSize = 0; 416 417 while (!SetupDiGetDeviceRegistryProperty(hDevInfo, &DeviceInfoData, SPDRP_FRIENDLYNAME, (PDWORD)&u32DataType, (uint8_t *)pBuf, 418 u32BufSize, (PDWORD)&u32BufSize)) 427 uint32_t u32BufSize = 0; /** @todo r=bird: ditto */ 428 429 while (!SetupDiGetDeviceRegistryProperty(hDevInfo, &DeviceInfoData, SPDRP_FRIENDLYNAME, 430 (PDWORD)&u32DataType, (uint8_t *)pBuf, 431 u32BufSize, (PDWORD)&u32BufSize) 432 && GetLastError() == ERROR_INSUFFICIENT_BUFFER) 419 433 { 420 if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) 421 { 422 if (pBuf) 423 RTMemFree(pBuf); 424 /* Max size will never be more than 2048 bytes */ 425 pBuf = (uint8_t *)RTMemAlloc(u32BufSize * 2); 426 } 427 else 428 break; 434 if (pBuf) 435 RTMemFree(pBuf); 436 /* Max size will never be more than 2048 bytes */ 437 pBuf = (uint8_t *)RTMemAlloc(u32BufSize * 2); 429 438 } 430 439 431 440 if (pBuf) /** @todo r=bird: You're not checking errors here. */ 432 441 { 442 /** @todo r=bird: The indent of the block is wrong... More importantely, the 443 * scope and purpose of the two variables would be clearer if you moved them 444 * to the RTStrStr calls further down. */ 433 445 char *pCh = NULL; 434 446 char* pTmpCh = NULL; … … 449 461 } 450 462 if (((pTmpCh - (char *)pBuf) - (pCh - (char *)pBuf)) < 0) { 451 LogFlowFunc(("Parallel port string not properly formatted. 463 LogFlowFunc(("Parallel port string not properly formatted.\n")); 452 464 return VERR_NOT_FOUND; 453 465 } … … 456 468 pCh+1, ((pTmpCh - (char *)pBuf) - (pCh - (char *)pBuf)) - 1)) 457 469 { 458 LogFlowFunc(("Parallel Port Not Found. 470 LogFlowFunc(("Parallel Port Not Found.\n")); 459 471 return VERR_NOT_FOUND; 460 472 } … … 463 475 /* checking again to make sure that we have got a valid name and in valid format too. */ 464 476 if (RTStrNCmp((char *)pThis->u8ParportName, "LPT", 3)) { 465 LogFlowFunc(("Parallel Port name \"LPT\" Not Found. 477 LogFlowFunc(("Parallel Port name \"LPT\" Not Found.\n")); 466 478 return VERR_NOT_FOUND; 467 479 } 468 480 481 /** @todo r=bird: Multiline expressions starts the next line with the 482 * operator, (instead of the previous line ending with an operator like you do 483 * here). 484 * 485 * Also, note that the opening curly brackets have it's own line in this 486 * file, so you do the same as the original author(s) of the file. */ 469 487 if (!RTStrStr((char *)pThis->u8ParportName, "LPT") || 470 488 !(pThis->u8ParportName[3] >= '0' && pThis->u8ParportName[3] <= '9')) { 471 489 RT_BZERO(pThis->u8ParportName, sizeof(pThis->u8ParportName)); 472 LogFlowFunc(("Printer Port Name Not Found. 490 LogFlowFunc(("Printer Port Name Not Found.\n")); 473 491 return VERR_NOT_FOUND; 474 492 } 475 pThis->fParportAvail = true;476 pThis->u32LptAddr = u32ParportAddr;493 pThis->fParportAvail = true; 494 pThis->u32LptAddr = u32ParportAddr; 477 495 pThis->u32LptAddrControl = pThis->u32LptAddr + CTRL_REG_OFFSET; 478 pThis->u32LptAddrStatus = pThis->u32LptAddr + STATUS_REG_OFFSET;496 pThis->u32LptAddrStatus = pThis->u32LptAddr + STATUS_REG_OFFSET; 479 497 } 480 498 if (pThis->fParportAvail) … … 983 1001 #else /* VBOX_WITH_WIN_PARPORT_SUP */ 984 1002 HANDLE hPort; 985 pThis->fParportAvail = false;986 pThis->u32LptAddr = 0L;987 pThis->u32LptAddrControl = 0 L;988 pThis->u32LptAddrStatus = 0L;1003 pThis->fParportAvail = false; 1004 pThis->u32LptAddr = 0; 1005 pThis->u32LptAddrControl = 0; 1006 pThis->u32LptAddrStatus = 0; 989 1007 rc = drvWinHostGetparportAddr(pThis); 990 1008 … … 992 1010 Read and write will be done only if addresses are available 993 1011 */ 994 if (pThis->u8ParportName) { 1012 if (pThis->u8ParportName) 1013 { 995 1014 LogFlowFunc(("Get the Handle to Printer Port =%s\n", (char *)pThis->u8ParportName)); 996 1015 /** @todo r=klaus convert to IPRT */
Note:
See TracChangeset
for help on using the changeset viewer.