Changeset 40639 in vbox for trunk/src/VBox/Devices/Parallel
- Timestamp:
- Mar 26, 2012 12:49:47 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Parallel/DrvHostParallel.cpp
r40591 r40639 3 3 * VirtualBox Host Parallel Port Driver. 4 4 * 5 * Contributed by: Alexander Eichner5 * Initial Linux-only code contributed by: Alexander Eichner 6 6 */ 7 7 8 8 /* 9 * Copyright (C) 2006-201 0Oracle Corporation9 * Copyright (C) 2006-2012 Oracle Corporation 10 10 * 11 11 * This file is part of VirtualBox Open Source Edition (OSE), as … … 61 61 #endif 62 62 63 #if defined(VBOX_WITH_WIN_PARPORT_SUP) && defined(IN_RING0) /** @todo r=bird: only needed in ring-0. Avoid unnecessary includes. */63 #if defined(VBOX_WITH_WIN_PARPORT_SUP) && defined(IN_RING0) 64 64 # include <Wdm.h> 65 65 # include <parallel.h> … … 68 68 69 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>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 78 #endif 79 79 … … 123 123 uint32_t u32LptAddrControl; 124 124 /** Data read buffer. */ 125 uint8_t bReadIn;125 uint8_t u8ReadIn; 126 126 /** Control read buffer. */ 127 uint8_t bReadInControl;127 uint8_t u8ReadInControl; 128 128 /** Status read buffer. */ 129 uint8_t bReadInStatus;129 uint8_t u8ReadInStatus; 130 130 /** Whether the parallel port is available or not. */ 131 uint8_t bParportAvail;131 bool fParportAvail; 132 132 # ifdef IN_RING0 133 133 typedef struct DEVICE_EXTENSION … … 183 183 { 184 184 PDRVHOSTPARALLEL pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTPARALLEL); 185 LogFlow (("%s Write to PPort = %x data = %x\n", __FUNCTION__, pThis->u32LptAddr, u64Arg));185 LogFlowFunc(("write to data port=%#x val=%#x\n", pThis->u32LptAddr, u64Arg)); 186 186 ASMOutU8(pThis->u32LptAddr, (uint8_t)(u64Arg)); 187 187 return VINF_SUCCESS; … … 189 189 190 190 /** 191 * R0 mode function to write byte value to paral ell port control191 * R0 mode function to write byte value to parallel port control 192 192 * register. 193 193 * @returns VBox status code. … … 198 198 { 199 199 PDRVHOSTPARALLEL pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTPARALLEL); 200 LogFlow (("%s Write to Ctrl PPort = %x data = %x\n", __FUNCTION__, pThis->u32LptAddrControl, u64Arg));200 LogFlowFunc(("write to ctrl port=%#x val=%#x\n", pThis->u32LptAddrControl, u64Arg)); 201 201 ASMOutU8(pThis->u32LptAddrControl, (uint8_t)(u64Arg)); 202 202 return VINF_SUCCESS; … … 213 213 { 214 214 uint8_t u8Data; 215 LogFlow(("%s Read from PPort\n", __FUNCTION__));216 215 PDRVHOSTPARALLEL pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTPARALLEL); 217 216 u8Data = ASMInU8(pThis->u32LptAddr); 218 LogFlow (("Data Read from PPort = %x", u8Data));219 pThis-> bReadIn = u8Data;217 LogFlowFunc(("read from data port=%#x val=%#x\n", pThis->u32LptAddr, u8Data)); 218 pThis->u8ReadIn = u8Data; 220 219 return VINF_SUCCESS; 221 220 } … … 231 230 { 232 231 uint8_t u8Data; 233 LogFlow(("%s Read from PPort control\n", __FUNCTION__));234 232 PDRVHOSTPARALLEL pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTPARALLEL); 235 233 u8Data = ASMInU8(pThis->u32LptAddrControl); 236 LogFlow (("Data Read from PPort = %x\n", u8Data));237 pThis-> bReadInControl = u8Data;234 LogFlowFunc(("read from ctrl port=%#x val=%#x\n", pThis->u32LptAddr, u8Data)); 235 pThis->u8ReadInControl = u8Data; 238 236 return VINF_SUCCESS; 239 237 } … … 249 247 { 250 248 uint8_t u8Data; 251 LogFlow(("%s Read from PPort Status\n", __FUNCTION__));252 249 PDRVHOSTPARALLEL pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTPARALLEL); 253 250 u8Data = ASMInU8(pThis->u32LptAddrStatus); 254 LogFlow (("Data Read from PPort = %x\n", u8Data));255 pThis-> bReadInStatus = u8Data;251 LogFlowFunc(("read from status port=%#x val=%#x\n", pThis->u32LptAddr, u8Data)); 252 pThis->u8ReadInStatus = u8Data; 256 253 return VINF_SUCCESS; 257 254 } … … 268 265 uint8_t u8ReadControlVal; 269 266 uint8_t u8WriteControlVal; 270 uint8_t u8TmpData;271 267 PDRVHOSTPARALLEL pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTPARALLEL); 272 268 273 269 if (u64Arg) 274 270 { 275 u8TmpData = 0x08; /* Set the control bit */276 271 u8ReadControlVal = ASMInU8(pThis->u32LptAddrControl); 277 u8WriteControlVal = u8ReadControlVal | u8TmpData;272 u8WriteControlVal = u8ReadControlVal | DCR_DIRECTION; /* enable input direction */ 278 273 ASMOutU8(pThis->u32LptAddrControl, u8WriteControlVal); 279 274 } 280 275 else 281 276 { 282 u8TmpData = 0xF7; /* Clear the control register 5th bit */283 277 u8ReadControlVal = ASMInU8(pThis->u32LptAddrControl); 284 u8WriteControlVal = u8ReadControlVal & u8TmpData;278 u8WriteControlVal = u8ReadControlVal & ~DCR_DIRECTION; /* disable input direction */ 285 279 ASMOutU8(pThis->u32LptAddrControl, u8WriteControlVal); 286 280 } … … 293 287 PDMBOTHCBDECL(int) drvR0HostParallelReqHandler(PPDMDRVINS pDrvIns, uint32_t uOperation, uint64_t u64Arg) 294 288 { 295 LogFlow(("Requst Handler\n")); 289 int rc; 290 291 LogFlowFuncEnter(); 296 292 switch ((DRVHOSTPARALLELR0OP)uOperation) 297 293 { 298 294 case DRVHOSTPARALLELR0OP_READ: 299 LogFlow(("Read Op\n")); 300 return drvR0HostParallelReqRead(pDrvIns, u64Arg); 295 rc = drvR0HostParallelReqRead(pDrvIns, u64Arg); 301 296 302 297 case DRVHOSTPARALLELR0OP_READSTATUS: 303 LogFlow(("Read Status \n")); 304 return drvR0HostParallelReqReadStatus(pDrvIns, u64Arg); 298 rc = drvR0HostParallelReqReadStatus(pDrvIns, u64Arg); 305 299 306 300 case DRVHOSTPARALLELR0OP_READCONTROL: 307 LogFlow(("Read CTRL\n")); 308 return drvR0HostParallelReqReadControl(pDrvIns, u64Arg); 301 rc = drvR0HostParallelReqReadControl(pDrvIns, u64Arg); 309 302 310 303 case DRVHOSTPARALLELR0OP_WRITE: 311 LogFlow(("Write Ope\n")); 312 return drvR0HostParallelReqWrite(pDrvIns, u64Arg); 304 rc = drvR0HostParallelReqWrite(pDrvIns, u64Arg); 313 305 314 306 case DRVHOSTPARALLELR0OP_WRITECONTROL: 315 LogFlow(("Write CTRL\n")); 316 return drvR0HostParallelReqWriteControl(pDrvIns, u64Arg); 307 rc = drvR0HostParallelReqWriteControl(pDrvIns, u64Arg); 317 308 318 309 case DRVHOSTPARALLELR0OP_SETPORTDIRECTION: 319 LogFlow(("Set Port Direction")); 320 return drvR0HostParallelReqSetPortDir(pDrvIns, u64Arg); 321 322 default: /* Not Supported. */ 323 return 0; /** @todo is this correct for not supported case? */ 324 } 310 rc = drvR0HostParallelReqSetPortDir(pDrvIns, u64Arg); 311 312 default: /* not supported */ 313 rc = VERR_NOT_SUPPORTED; 314 } 315 LogFlowFuncLeave(); 316 return rc; 325 317 } 326 318 #endif /**IN_RING0*/ … … 375 367 CM_Free_Res_Des_Handle(nextLogConf); 376 368 break; 377 } ; /** @todo Is this semicolon intended? */369 } 378 370 cmRet = CM_Get_Res_Des_Data(nextLogConf, pBuf, u32Size, 0L); 379 371 if (cmRet != CR_SUCCESS) … … 383 375 break; 384 376 } 385 LogFlow (("Call GetIOResource\n"));377 LogFlowFunc(("call GetIOResource\n")); 386 378 u32ParportAddr = ((IO_DES*)(pBuf))->IOD_Alloc_Base; 387 LogFlow (("Called GetIOResource. Ret = %x\n", u32ParportAddr));379 LogFlowFunc(("called GetIOResource, ret=%#x\n", u32ParportAddr)); 388 380 rdPrevResDes = 0; 389 381 cmRet = CM_Get_Next_Res_Des(&rdPrevResDes, … … 402 394 } 403 395 CM_Free_Res_Des_Handle(nextLogConf); 404 LogFlow (("Return u32ParportAddr=%x", u32ParportAddr));396 LogFlowFunc(("return u32ParportAddr=%#x", u32ParportAddr)); 405 397 return u32ParportAddr; 406 398 } … … 448 440 if (pBuf) 449 441 { 450 LogFlow (("Buffer =%s\n", pBuf));451 if (strstr((char*)pBuf, "LPT")) /** @todo Use IPRT equivalent? */442 LogFlowFunc(("device name=%s\n", pBuf)); 443 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. */ 452 444 { 453 LogFlow (("Found parallel port\n"));445 LogFlowFunc(("found parallel port\n")); 454 446 u32ParportAddr = FindIORangeResource(DeviceInfoData.DevInst); 455 447 if (u32ParportAddr) 456 448 { 457 pThis-> bParportAvail = true;449 pThis->fParportAvail = true; 458 450 pThis->u32LptAddr = u32ParportAddr; 459 pThis->u32LptAddrControl = pThis->u32LptAddr + 2;460 pThis->u32LptAddrStatus = pThis->u32LptAddr + 1;451 pThis->u32LptAddrControl = pThis->u32LptAddr + DCR_OFFSET; 452 pThis->u32LptAddrStatus = pThis->u32LptAddr + DSR_OFFSET; 461 453 } 462 if (pThis-> bParportAvail)454 if (pThis->fParportAvail) 463 455 break; 464 456 } … … 466 458 if (pBuf) 467 459 RTMemFree(pBuf); 468 if (pThis-> bParportAvail)460 if (pThis->fParportAvail) 469 461 { 470 /* Par port address has been found. No Need to iterate further. */462 /* Parallel port address has been found. No need to iterate further. */ 471 463 break; 472 464 } … … 474 466 475 467 if (GetLastError() != NO_ERROR && GetLastError() != ERROR_NO_MORE_ITEMS) 476 rc = VERR_GENERAL_FAILURE; ;468 rc = VERR_GENERAL_FAILURE; 477 469 478 470 SetupDiDestroyDeviceInfoList(hDevInfo); … … 493 485 int iMode = 0; 494 486 int rc = VINF_SUCCESS; 495 LogFlow (("%s: mode=%d\n", __FUNCTION__, enmMode));487 LogFlowFunc(("mode=%d\n", enmMode)); 496 488 497 489 #ifndef VBOX_WITH_WIN_PARPORT_SUP … … 556 548 int rcLnx = 0; 557 549 558 LogFlow (("%s: pvBuf=%#p cbWrite=%d\n", __FUNCTION__, pvBuf, cbWrite));550 LogFlowFunc(("pvBuf=%#p cbWrite=%d\n", pvBuf, cbWrite)); 559 551 560 552 rc = drvHostParallelSetMode(pThis, enmMode); … … 575 567 rc = RTErrConvertFromErrno(errno); 576 568 #else /*VBOX_WITH_WIN_PARPORT_SUP*/ 569 /** @todo r=klaus this code assumes cbWrite==1, which may not be guaranteed forever */ 577 570 uint64_t u64Data; 578 571 u64Data = (uint8_t) *((uint8_t *)(pvBuf)); 579 LogFlow (("%s: Calling R0 to write to parallel port. Data is %d\n", __FUNCTION__, u64Data));580 if (pThis-> bParportAvail)572 LogFlowFunc(("calling R0 to write to parallel port, data=%#x\n", u64Data)); 573 if (pThis->fParportAvail) 581 574 { 582 575 rc = PDMDrvHlpCallR0(pThis->CTX_SUFF(pDrvIns), DRVHOSTPARALLELR0OP_WRITE, u64Data); 583 if (RT_FAILURE(rc)) 584 AssertRC(rc); 576 AssertRC(rc); 585 577 } 586 578 #endif /* VBOX_WITH_WIN_PARPORT_SUP */ … … 598 590 #ifndef VBOX_WITH_WIN_PARPORT_SUP 599 591 int rcLnx = 0; 600 LogFlow (("%s: pvBuf=%#p cbRead=%d\n", __FUNCTION__, pvBuf, cbRead));592 LogFlowFunc(("pvBuf=%#p cbRead=%d\n", pvBuf, cbRead)); 601 593 602 594 rc = drvHostParallelSetMode(pThis, enmMode); … … 617 609 rc = RTErrConvertFromErrno(errno); 618 610 #else /* VBOX_WITH_WIN_PARPORT_SUP */ 611 /** @todo r=klaus this code assumes cbRead==1, which may not be guaranteed forever */ 619 612 *((uint8_t*)(pvBuf)) = 0; /* Initialize the buffer. */ 620 LogFlow (("%s: Calling R0 to Read from PPort\n", __FUNCTION__));621 if (pThis-> bParportAvail)613 LogFlowFunc(("calling R0 to read from parallel port\n")); 614 if (pThis->fParportAvail) 622 615 { 623 616 int rc = PDMDrvHlpCallR0(pThis->CTX_SUFF(pDrvIns), DRVHOSTPARALLELR0OP_READ, 0); 624 if (RT_FAILURE(rc)) 625 AssertRC(rc); 626 *((uint8_t*)(pvBuf)) = (uint8_t)pThis->bReadIn; 617 AssertRC(rc); 618 *((uint8_t*)(pvBuf)) = (uint8_t)pThis->u8ReadIn; 627 619 } 628 620 #endif … … 646 638 uint64_t u64Data; 647 639 u64Data = (uint8_t)iMode; 648 LogFlow (("%s: Calling R0 to write CTRL . Data is %x\n", __FUNCTION__, u64Data));649 if (pThis-> bParportAvail)640 LogFlowFunc(("calling R0 to write CTRL, data=%#x\n", u64Data)); 641 if (pThis->fParportAvail) 650 642 { 651 643 rc = PDMDrvHlpCallR0(pThis->CTX_SUFF(pDrvIns), DRVHOSTPARALLELR0OP_SETPORTDIRECTION, u64Data); 652 if (RT_FAILURE(rc)) 653 AssertRC(rc); 644 AssertRC(rc); 654 645 } 655 646 #endif /* VBOX_WITH_WIN_PARPORT_SUP */ … … 666 657 int rcLnx = 0; 667 658 668 LogFlow (("%s: fReg=%d\n", __FUNCTION__, fReg));659 LogFlowFunc(("fReg=%#x\n", fReg)); 669 660 # ifndef VBOX_WITH_WIN_PARPORT_SUP 670 661 rcLnx = ioctl(RTFileToNative(pThis->hFileDevice), PPWCONTROL, &fReg); … … 674 665 uint64_t u64Data; 675 666 u64Data = (uint8_t)fReg; 676 LogFlow (("%s: Calling R0 to write CTRL . Data is %x\n", __FUNCTION__, u64Data));677 if (pThis-> bParportAvail)667 LogFlowFunc(("calling R0 to write CTRL, data=%#x\n", u64Data)); 668 if (pThis->fParportAvail) 678 669 { 679 670 rc = PDMDrvHlpCallR0(pThis->CTX_SUFF(pDrvIns), DRVHOSTPARALLELR0OP_WRITECONTROL, u64Data); 680 if (RT_FAILURE(rc)) 681 AssertRC(rc); 671 AssertRC(rc); 682 672 } 683 673 #endif /* VBOX_WITH_WIN_PARPORT_SUP */ … … 702 692 else 703 693 { 704 LogFlow (("%s: fReg=%d\n", __FUNCTION__, fReg));694 LogFlowFunc(("fReg=%#x\n", fReg)); 705 695 *pfReg = fReg; 706 696 } 707 697 #else /* VBOX_WITH_WIN_PARPORT_SUP */ 708 698 *pfReg = 0; /* Initialize the buffer*/ 709 if (pThis-> bParportAvail)710 { 711 LogFlow (("%s: Calling R0 to Read Control from PPort\n", __FUNCTION__));699 if (pThis->fParportAvail) 700 { 701 LogFlowFunc(("calling R0 to read control from parallel port\n")); 712 702 rc = PDMDrvHlpCallR0(pThis-> CTX_SUFF(pDrvIns), DRVHOSTPARALLELR0OP_READCONTROL, 0); 713 if (RT_FAILURE(rc)) 714 AssertRC(rc); 715 *pfReg = pThis->bReadInControl; 703 AssertRC(rc); 704 *pfReg = pThis->u8ReadInControl; 716 705 } 717 706 #endif /* VBOX_WITH_WIN_PARPORT_SUP */ … … 734 723 else 735 724 { 736 LogFlow (("%s: fReg=%d\n", __FUNCTION__, fReg));725 LogFlowFunc(("fReg=%#x\n", fReg)); 737 726 *pfReg = fReg; 738 727 } 739 728 #else /* VBOX_WITH_WIN_PARPORT_SUP */ 740 729 *pfReg = 0; /* Intialize the buffer. */ 741 if (pThis-> bParportAvail)742 { 743 LogFlow (("%s: Calling R0 to Read Status from Pport\n", __FUNCTION__));730 if (pThis->fParportAvail) 731 { 732 LogFlowFunc(("calling R0 to read status from parallel port\n")); 744 733 rc = PDMDrvHlpCallR0(pThis->CTX_SUFF(pDrvIns), DRVHOSTPARALLELR0OP_READSTATUS, 0); 745 if (RT_FAILURE(rc)) 746 AssertRC(rc); 747 *pfReg = pThis->bReadInStatus; 734 AssertRC(rc); 735 *pfReg = pThis->u8ReadInStatus; 748 736 } 749 737 #endif /* VBOX_WITH_WIN_PARPORT_SUP */ … … 825 813 { 826 814 PDRVHOSTPARALLEL pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTPARALLEL); 827 LogFlow (("%s: iInstance=%d\n", __FUNCTION__, pDrvIns->iInstance));815 LogFlowFunc(("iInstance=%d\n", pDrvIns->iInstance)); 828 816 PDMDRV_CHECK_VERSIONS_RETURN_VOID(pDrvIns); 829 817 … … 860 848 { 861 849 PDRVHOSTPARALLEL pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTPARALLEL); 862 LogFlow (("%s: iInstance=%d\n", __FUNCTION__, pDrvIns->iInstance));850 LogFlowFunc(("iInstance=%d\n", pDrvIns->iInstance)); 863 851 864 852 PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns); … … 966 954 967 955 #else /* VBOX_WITH_WIN_PARPORT_SUP */ 968 pThis-> bParportAvail = false;956 pThis->fParportAvail = false; 969 957 pThis->u32LptAddr = 0L; 970 958 pThis->u32LptAddrControl = 0L; … … 972 960 rc = drvHostParallelGetParportAddr(pThis); 973 961 return rc; 974 /** @todo code after unconditional return? Either #if 0 it or remove. */975 962 HANDLE hPort; 963 /** @todo r=klaus convert to IPRT */ 976 964 hPort = CreateFile("LPT1", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, 977 965 NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); 978 966 if (INVALID_HANDLE_VALUE == hPort) 979 967 { 980 LogFlow(("Failed to get exclusive access to parallel port\n")); 981 return (GetLastError()); 968 /** @todo r=klaus probably worth a nicely formatted release log entry, 969 * pointing to the device name etc etc. */ 970 LogFlowFunc(("failed to get exclusive access to parallel port\n")); 971 /** @todo r=klaus wrong kind of error code, must be IPRT error code */ 972 return GetLastError(); 982 973 } 983 974 #endif /* VBOX_WITH_WIN_PARPORT_SUP */
Note:
See TracChangeset
for help on using the changeset viewer.