Changeset 40658 in vbox
- Timestamp:
- Mar 27, 2012 10:22:07 AM (13 years ago)
- svn:sync-xref-src-repo-rev:
- 77092
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Parallel/DrvHostParallel.cpp
r40639 r40658 107 107 /** Device Handle */ 108 108 RTFILE hFileDevice; 109 #ifndef VBOX_WITH_WIN_PARPORT_SUP /** @todo r=bird: Eliminate thing not needed, it rules out things you might have missed. */ 109 110 /** Thread waiting for interrupts. */ 110 111 PPDMTHREAD pMonitorThread; … … 113 114 /** Wakeup pipe write end. */ 114 115 RTPIPE hWakeupPipeW; 116 #endif 115 117 /** Current mode the parallel port is in. */ 116 118 PDMPARALLELPORTMODE enmModeCur; … … 130 132 /** Whether the parallel port is available or not. */ 131 133 bool fParportAvail; 132 # ifdef IN_RING0 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.) */ 133 135 typedef struct DEVICE_EXTENSION 134 136 { … … 141 143 PDEVICE_EXTENSION pDevExtn; 142 144 # endif 143 #endif 145 #endif /* VBOX_WITH_WIN_PARPORT_SUP */ 144 146 } DRVHOSTPARALLEL, *PDRVHOSTPARALLEL; 145 147 … … 180 182 * 181 183 */ 182 PDMBOTHCBDECL(int) drvR0HostParallelReqWrite(PPDMDRVINS pDrvIns, uint64_t u64Arg) 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! */ 183 185 { 184 186 PDRVHOSTPARALLEL pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTPARALLEL); … … 195 197 * @param u64Arg Data to be written to control register. 196 198 */ 197 PDMBOTHCBDECL(int)drvR0HostParallelReqWriteControl(PPDMDRVINS pDrvIns, uint64_t u64Arg)199 static int drvR0HostParallelReqWriteControl(PPDMDRVINS pDrvIns, uint64_t u64Arg) 198 200 { 199 201 PDRVHOSTPARALLEL pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTPARALLEL); … … 210 212 * @param u64Arg Not used. 211 213 */ 212 PDMBOTHCBDECL(int)drvR0HostParallelReqRead(PPDMDRVINS pDrvIns, uint64_t u64Arg)214 static int drvR0HostParallelReqRead(PPDMDRVINS pDrvIns, uint64_t u64Arg) 213 215 { 214 216 uint8_t u8Data; … … 227 229 * @param u64Arg Not used. 228 230 */ 229 PDMBOTHCBDECL(int)drvR0HostParallelReqReadControl(PPDMDRVINS pDrvIns, uint64_t u64Arg)231 static int drvR0HostParallelReqReadControl(PPDMDRVINS pDrvIns, uint64_t u64Arg) 230 232 { 231 233 uint8_t u8Data; … … 244 246 * @param u64Arg Not used. 245 247 */ 246 PDMBOTHCBDECL(int)drvR0HostParallelReqReadStatus(PPDMDRVINS pDrvIns, uint64_t u64Arg)248 static int drvR0HostParallelReqReadStatus(PPDMDRVINS pDrvIns, uint64_t u64Arg) 247 249 { 248 250 uint8_t u8Data; … … 261 263 * @param u64Arg Mode. 262 264 */ 263 PDMBOTHCBDECL(int) drvR0HostParallelReqSetPortDir(PPDMDRVINS pDrvIns, uint64_t u64Arg) 264 { 265 static int drvR0HostParallelReqSetPortDir(PPDMDRVINS pDrvIns, uint64_t u64Arg) 266 { 267 PDRVHOSTPARALLEL pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTPARALLEL); 265 268 uint8_t u8ReadControlVal; 266 269 uint8_t u8WriteControlVal; 267 PDRVHOSTPARALLEL pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTPARALLEL);268 270 269 271 if (u64Arg) … … 316 318 return rc; 317 319 } 318 #endif /* *IN_RING0*/319 #endif /* *VBOX_WITH_WIN_PARPORT_SUP*/320 #endif /* IN_RING0 */ 321 #endif /* VBOX_WITH_WIN_PARPORT_SUP */ 320 322 321 323 #ifdef IN_RING3 322 # ifdef VBOX_WITH_WIN_PARPORT_SUP323 /** 324 * Find IO port range for the parallel port and return the lower 325 * address.324 # ifdef VBOX_WITH_WIN_PARPORT_SUP 325 /** 326 * Find IO port range for the parallel port and return the lower address. 327 * 326 328 * @returns parallel port IO address. 327 329 * @param DevInst Device Instance for parallel port. 328 330 */ 329 static uint32_t FindIORangeResource(const DEVINST DevInst)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'. */ 330 332 { 331 333 uint8_t *pBuf = NULL; … … 356 358 { 357 359 u32Size = 0; 358 cmRet = CM_Get_Res_Des_Data_Size((PULONG)(&u32Size), nextLogConf, 0L); 360 cmRet = CM_Get_Res_Des_Data_Size((PULONG)(&u32Size), nextLogConf, 0L); /** @todo r=bird: (PULONG)(&u32Size) - generally a bad idea, but not really a problem here though... Why don't you use ULONG for the size variable? Like 'ULONG cbBuf;'? */ 359 361 if (cmRet != CR_SUCCESS) 360 362 { 361 CM_Free_Res_Des_Handle(nextLogConf); 363 CM_Free_Res_Des_Handle(nextLogConf); /** @todo r=bird: Why are you doing this twice in this code path? */ 362 364 break; 363 365 } 364 pBuf = (uint8_t *) ((char*)RTMemAlloc(u32Size + 1));366 pBuf = (uint8_t *)RTMemAlloc(u32Size + 1); 365 367 if (!pBuf) 366 368 { 367 CM_Free_Res_Des_Handle(nextLogConf); 369 CM_Free_Res_Des_Handle(nextLogConf); /** @todo r=bird: Ditto above. */ 368 370 break; 369 371 } … … 372 374 { 373 375 CM_Free_Res_Des_Handle(nextLogConf); 374 LocalFree(pBuf);376 RTMemFree(pBuf); /** @todo r=bird: LocalFree(pBuf) was the wrong free function! */ 375 377 break; 376 378 } 377 379 LogFlowFunc(("call GetIOResource\n")); 378 u32ParportAddr = ((IO_DES *)(pBuf))->IOD_Alloc_Base;380 u32ParportAddr = ((IO_DES *)pBuf)->IOD_Alloc_Base; 379 381 LogFlowFunc(("called GetIOResource, ret=%#x\n", u32ParportAddr)); 380 382 rdPrevResDes = 0; … … 387 389 if (cmRet != CR_SUCCESS) 388 390 break; 389 else 390 { 391 CM_Free_Res_Des_Handle(nextLogConf); 392 nextLogConf = rdPrevResDes; 393 } 391 /** @todo r=bird: No need to else soemthing when the 'then' clause 392 * returned or broke ouf of the loop. */ 393 CM_Free_Res_Des_Handle(nextLogConf); 394 nextLogConf = rdPrevResDes; 394 395 } 395 396 CM_Free_Res_Des_Handle(nextLogConf); … … 432 433 RTMemFree(pBuf); 433 434 /* Max size will never be more than 2048 bytes */ 434 pBuf = (uint8_t *)((char*)RTMemAlloc(u32BufSize * 2)); 435 /** @todo r=bird: Too many parentheses and casts: (uint8_t *)((char*)RTMemAlloc(u32BufSize * 2)) */ 436 pBuf = (uint8_t *)RTMemAlloc(u32BufSize * 2); 435 437 } 436 438 else … … 438 440 } 439 441 440 if (pBuf) 442 if (pBuf) /** @todo r=bird: You're not checking errors here. */ 441 443 { 442 444 LogFlowFunc(("device name=%s\n", pBuf)); … … 444 446 { 445 447 LogFlowFunc(("found parallel port\n")); 446 u32ParportAddr = FindIORangeResource(DeviceInfoData.DevInst);448 u32ParportAddr = drvHostWinFindIORangeResource(DeviceInfoData.DevInst); 447 449 if (u32ParportAddr) 448 450 { … … 472 474 473 475 } 474 # endif /**VBOX_WITH_WIN_PARPORT_SUP*/476 # endif /* VBOX_WITH_WIN_PARPORT_SUP */ 475 477 476 478 /** … … 487 489 LogFlowFunc(("mode=%d\n", enmMode)); 488 490 489 # ifndef VBOX_WITH_WIN_PARPORT_SUP491 # ifndef VBOX_WITH_WIN_PARPORT_SUP 490 492 int rcLnx; 491 493 if (pThis->enmModeCur != enmMode) … … 516 518 517 519 return rc; 518 # else/* VBOX_WITH_WIN_PARPORT_SUP */520 # else /* VBOX_WITH_WIN_PARPORT_SUP */ 519 521 return VINF_SUCCESS; 520 # endif /* VBOX_WITH_WIN_PARPORT_SUP */522 # endif /* VBOX_WITH_WIN_PARPORT_SUP */ 521 523 } 522 524 … … 553 555 if (RT_FAILURE(rc)) 554 556 return rc; 555 # ifndef VBOX_WITH_WIN_PARPORT_SUP557 # ifndef VBOX_WITH_WIN_PARPORT_SUP 556 558 if (enmMode == PDM_PARALLEL_PORT_MODE_SPP) 557 559 { … … 566 568 if (RT_UNLIKELY(rcLnx < 0)) 567 569 rc = RTErrConvertFromErrno(errno); 568 # else /*VBOX_WITH_WIN_PARPORT_SUP*/570 # else /* VBOX_WITH_WIN_PARPORT_SUP */ 569 571 /** @todo r=klaus this code assumes cbWrite==1, which may not be guaranteed forever */ 570 572 uint64_t u64Data; … … 576 578 AssertRC(rc); 577 579 } 578 # endif /* VBOX_WITH_WIN_PARPORT_SUP */580 # endif /* VBOX_WITH_WIN_PARPORT_SUP */ 579 581 return rc; 580 582 } … … 588 590 int rc = VINF_SUCCESS; 589 591 590 # ifndef VBOX_WITH_WIN_PARPORT_SUP592 # ifndef VBOX_WITH_WIN_PARPORT_SUP 591 593 int rcLnx = 0; 592 594 LogFlowFunc(("pvBuf=%#p cbRead=%d\n", pvBuf, cbRead)); … … 608 610 if (RT_UNLIKELY(rcLnx < 0)) 609 611 rc = RTErrConvertFromErrno(errno); 610 # else/* VBOX_WITH_WIN_PARPORT_SUP */612 # else /* VBOX_WITH_WIN_PARPORT_SUP */ 611 613 /** @todo r=klaus this code assumes cbRead==1, which may not be guaranteed forever */ 612 614 *((uint8_t*)(pvBuf)) = 0; /* Initialize the buffer. */ … … 616 618 int rc = PDMDrvHlpCallR0(pThis->CTX_SUFF(pDrvIns), DRVHOSTPARALLELR0OP_READ, 0); 617 619 AssertRC(rc); 618 *( (uint8_t*)(pvBuf)) = (uint8_t)pThis->u8ReadIn;619 } 620 # endif620 *(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. */ 621 } 622 # endif /* VBOX_WITH_WIN_PARPORT_SUP */ 621 623 return rc; 622 624 } … … 626 628 PDRVHOSTPARALLEL pThis = RT_FROM_MEMBER(pInterface, DRVHOSTPARALLEL, CTX_SUFF(IHostParallelConnector)); 627 629 int rc = VINF_SUCCESS; 628 int rcLnx = 0;629 int iMode = 0;630 630 631 631 if (!fForward) 632 632 iMode = 1; 633 #ifndef VBOX_WITH_WIN_PARPORT_SUP 634 rcLnx = ioctl(RTFileToNative(pThis->hFileDevice), PPDATADIR, &iMode); 633 # ifndef VBOX_WITH_WIN_PARPORT_SUP 634 int iMode = 0; /** @todo r=bird: unused . */ 635 int rcLnx = ioctl(RTFileToNative(pThis->hFileDevice), PPDATADIR, &iMode); 635 636 if (RT_UNLIKELY(rcLnx < 0)) 636 637 rc = RTErrConvertFromErrno(errno); 637 #else /* VBOX_WITH_WIN_PARPORT_SUP */ 638 639 # else /* VBOX_WITH_WIN_PARPORT_SUP */ 638 640 uint64_t u64Data; 639 641 u64Data = (uint8_t)iMode; … … 644 646 AssertRC(rc); 645 647 } 646 # endif /* VBOX_WITH_WIN_PARPORT_SUP */648 # endif /* VBOX_WITH_WIN_PARPORT_SUP */ 647 649 return rc; 648 650 } … … 662 664 if (RT_UNLIKELY(rcLnx < 0)) 663 665 rc = RTErrConvertFromErrno(errno); 664 # else /* VBOX_WITH_WIN_PARPORT_SUP */666 # else /* VBOX_WITH_WIN_PARPORT_SUP */ 665 667 uint64_t u64Data; 666 668 u64Data = (uint8_t)fReg; … … 671 673 AssertRC(rc); 672 674 } 673 # endif /* VBOX_WITH_WIN_PARPORT_SUP */675 # endif /* VBOX_WITH_WIN_PARPORT_SUP */ 674 676 return rc; 675 677 } … … 686 688 uint8_t fReg = 0; 687 689 688 # ifndef VBOX_WITH_WIN_PARPORT_SUP690 # ifndef VBOX_WITH_WIN_PARPORT_SUP 689 691 rcLnx = ioctl(RTFileToNative(pThis->hFileDevice), PPRCONTROL, &fReg); 690 692 if (RT_UNLIKELY(rcLnx < 0)) … … 695 697 *pfReg = fReg; 696 698 } 697 # else /* VBOX_WITH_WIN_PARPORT_SUP */699 # else /* VBOX_WITH_WIN_PARPORT_SUP */ 698 700 *pfReg = 0; /* Initialize the buffer*/ 699 701 if (pThis->fParportAvail) … … 704 706 *pfReg = pThis->u8ReadInControl; 705 707 } 706 # endif /* VBOX_WITH_WIN_PARPORT_SUP */708 # endif /* VBOX_WITH_WIN_PARPORT_SUP */ 707 709 return rc; 708 710 } … … 717 719 int rcLnx = 0; 718 720 uint8_t fReg = 0; 719 # ifndef VBOX_WITH_WIN_PARPORT_SUP721 # ifndef VBOX_WITH_WIN_PARPORT_SUP 720 722 rcLnx = ioctl(RTFileToNative(pThis->hFileDevice), PPRSTATUS, &fReg); 721 723 if (RT_UNLIKELY(rcLnx < 0)) … … 726 728 *pfReg = fReg; 727 729 } 728 # else /* VBOX_WITH_WIN_PARPORT_SUP */730 # else /* VBOX_WITH_WIN_PARPORT_SUP */ 729 731 *pfReg = 0; /* Intialize the buffer. */ 730 732 if (pThis->fParportAvail) … … 735 737 *pfReg = pThis->u8ReadInStatus; 736 738 } 737 # endif /* VBOX_WITH_WIN_PARPORT_SUP */739 # endif /* VBOX_WITH_WIN_PARPORT_SUP */ 738 740 return rc; 739 741 } 740 742 743 # ifndef VBOX_WITH_WIN_PARPORT_SUP /** @todo r=bird: This whole function is unused in the direct access path. */ 744 741 745 static DECLCALLBACK(int) drvHostParallelMonitorThread(PPDMDRVINS pDrvIns, PPDMTHREAD pThread) 742 746 { 743 747 PDRVHOSTPARALLEL pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTPARALLEL); 744 745 #ifndef VBOX_WITH_WIN_PARPORT_SUP746 748 struct pollfd aFDs[2]; 747 749 … … 783 785 AssertRC(rc); 784 786 } 785 #endif /* VBOX_WITH_WIN_PARPORT_SUP */786 787 787 788 return VINF_SUCCESS; … … 801 802 return RTPipeWrite(pThis->hWakeupPipeW, "", 1, &cbIgnored); 802 803 } 804 805 # endif /* VBOX_WITH_WIN_PARPORT_SUP */ 803 806 804 807 /** … … 829 832 pThis->hWakeupPipeR = NIL_RTPIPE; 830 833 831 rc = RTFileClose(pThis->hFileDevice); AssertRC(rc); 834 rc = RTFileClose(pThis->hFileDevice); AssertRC(rc); /** @todo r=bird: Why aren't this closed on Windows? */ 832 835 pThis->hFileDevice = NIL_RTFILE; 833 836 … … 858 861 */ 859 862 pThis->hFileDevice = NIL_RTFILE; 863 #ifndef VBOX_WITH_WIN_PARPORT_SUP 860 864 pThis->hWakeupPipeR = NIL_RTPIPE; 861 865 pThis->hWakeupPipeW = NIL_RTPIPE; 866 #endif 862 867 863 868 pThis->pDrvInsR3 = pDrvIns; … … 960 965 rc = drvHostParallelGetParportAddr(pThis); 961 966 return rc; 967 /**@todo r=bird: Just remove or #if 0 this code.*/ 962 968 HANDLE hPort; 963 969 /** @todo r=klaus convert to IPRT */ 964 970 hPort = CreateFile("LPT1", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, 965 NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); 966 if ( INVALID_HANDLE_VALUE == hPort)971 NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); /** @todo r=bird: Continuation indent under start parentheses like the rest of the file. */ 972 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! */ 967 973 { 968 974 /** @todo r=klaus probably worth a nicely formatted release log entry,
Note:
See TracChangeset
for help on using the changeset viewer.