VirtualBox

Changeset 40665 in vbox for trunk/src


Ignore:
Timestamp:
Mar 27, 2012 1:52:22 PM (13 years ago)
Author:
vboxsync
Message:

Device/Parallel: incorporation of the review comments

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Parallel/DrvHostParallel.cpp

    r40662 r40665  
    4747
    4848
    49 /** @todo r=bird: The following indicator is neccessary to select the right
    50  *        code. */
    5149/** @def VBOX_WITH_WIN_PARPORT_SUP *
    5250 * Indicates whether to use the generic direct hardware access or host specific
     
    7674# include <cfgmgr32.h>
    7775# include <iprt/mem.h>
     76# define CTRL_REG_OFFSET 2
     77# define STATUS_REG_OFFSET  1
    7878#endif
    7979
     
    101101    /** Our host device interface. */
    102102    PDMIHOSTPARALLELCONNECTOR     IHostParallelConnectorR3;
    103     /** Ring-3 base interface for the ring-0 context. */
    104     PDMIBASER0                    IBaseR0;
    105103    /** Device Path */
    106104    char                         *pszDevicePath;
    107105    /** Device Handle */
    108106    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
    110108    /** Thread waiting for interrupts. */
    111109    PPDMTHREAD                    pMonitorThread;
     
    114112    /** Wakeup pipe write end. */
    115113    RTPIPE                        hWakeupPipeW;
    116 #endif
    117114    /** Current mode the parallel port is in. */
    118115    PDMPARALLELPORTMODE           enmModeCur;
     116#endif
     117
    119118#ifdef VBOX_WITH_WIN_PARPORT_SUP
    120119    /** Data register. */
     
    130129    /** Status read buffer. */
    131130    uint8_t                       u8ReadInStatus;
     131        /** Parallel port name */
     132    uint8_t                       u8ParportName[6];
    132133    /** Whether the parallel port is available or not. */
    133134    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_EXTENSION
    136     {
    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 # endif
    145135#endif /* VBOX_WITH_WIN_PARPORT_SUP */
    146136} DRVHOSTPARALLEL, *PDRVHOSTPARALLEL;
     
    182172 *
    183173 */
    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! */
     174static int drvR0HostParallelReqWrite(PPDMDRVINS pDrvIns, uint64_t u64Arg)
    185175{
    186176    PDRVHOSTPARALLEL pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTPARALLEL);
     
    292282
    293283    LogFlowFuncEnter();
     284    /* I have included break after each case. Need to work on this. */
    294285    switch ((DRVHOSTPARALLELR0OP)uOperation)
    295286    {
    296287        case DRVHOSTPARALLELR0OP_READ:
    297288            rc = drvR0HostParallelReqRead(pDrvIns, u64Arg);
    298 
     289            break;
    299290        case DRVHOSTPARALLELR0OP_READSTATUS:
    300291            rc = drvR0HostParallelReqReadStatus(pDrvIns, u64Arg);
    301 
     292            break;
    302293        case DRVHOSTPARALLELR0OP_READCONTROL:
    303294            rc = drvR0HostParallelReqReadControl(pDrvIns, u64Arg);
    304 
     295            break;
    305296        case DRVHOSTPARALLELR0OP_WRITE:
    306297            rc = drvR0HostParallelReqWrite(pDrvIns, u64Arg);
    307 
     298            break;
    308299        case DRVHOSTPARALLELR0OP_WRITECONTROL:
    309300            rc = drvR0HostParallelReqWriteControl(pDrvIns, u64Arg);
    310 
     301            break;
    311302        case DRVHOSTPARALLELR0OP_SETPORTDIRECTION:
    312303            rc = drvR0HostParallelReqSetPortDir(pDrvIns, u64Arg);
    313 
     304            break;
    314305        default:        /* not supported */
    315306            rc = VERR_NOT_SUPPORTED;
     
    329320 * @param   DevInst    Device Instance for parallel port.
    330321 */
    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'. */
     322static uint32_t drvHostWinFindIORangeResource(const DEVINST DevInst)
    332323{
    333324    uint8_t  *pBuf  = NULL;
     
    389380        if (cmRet != CR_SUCCESS)
    390381           break;
    391         /** @todo r=bird: No need to else soemthing when the 'then' clause
    392          *        returned or broke ouf of the loop. */
     382
    393383        CM_Free_Res_Des_Handle(nextLogConf);
    394384        nextLogConf = rdPrevResDes;
     
    405395 * @param   pThis    The host parallel port instance data.
    406396 */
    407 static int drvHostParallelGetParportAddr(PDRVHOSTPARALLEL pThis)
     397static int drvWinHostGetparportAddr(PDRVHOSTPARALLEL pThis)
    408398{
    409399    HDEVINFO hDevInfo;
     
    433423                     RTMemFree(pBuf);
    434424                /* Max size will never be more than 2048 bytes */
    435                 /** @todo r=bird: Too many parentheses and casts: (uint8_t *)((char*)RTMemAlloc(u32BufSize * 2)) */
    436425                pBuf = (uint8_t *)RTMemAlloc(u32BufSize * 2);
    437426            }
     
    442431        if (pBuf) /** @todo r=bird: You're not checking errors here. */
    443432        {
    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? */
    446436             {
    447                  LogFlowFunc(("found parallel port\n"));
    448437                 u32ParportAddr = drvHostWinFindIORangeResource(DeviceInfoData.DevInst);
    449438                 if (u32ParportAddr)
    450439                 {
     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                     }
    451465                     pThis->fParportAvail = true;
    452466                     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;
    455469                 }
    456470                 if (pThis->fParportAvail)
     
    618632        int rc = PDMDrvHlpCallR0(pThis->CTX_SUFF(pDrvIns), DRVHOSTPARALLELR0OP_READ, 0);
    619633        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;
    621635    }
    622636# endif /* VBOX_WITH_WIN_PARPORT_SUP */
     
    740754}
    741755
    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
    743757
    744758static DECLCALLBACK(int) drvHostParallelMonitorThread(PPDMDRVINS pDrvIns, PPDMTHREAD pThread)
     
    958972
    959973#else /* VBOX_WITH_WIN_PARPORT_SUP */
     974    HANDLE hPort;
    960975    pThis->fParportAvail = false;
    961976    pThis->u32LptAddr = 0L;
    962977    pThis->u32LptAddrControl = 0L;
    963978    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  */
    980998    return VINF_SUCCESS;
    981999}
     
    9981016    "Parallel host driver.",
    9991017    /* fFlags */
    1000 #if defined(VBOX_WITH_WIN_PARPORT_SUP)
     1018# if defined(VBOX_WITH_WIN_PARPORT_SUP)
    10011019    PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT | PDM_DRVREG_FLAGS_R0,
    1002 #else
     1020# else
    10031021    PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
    1004 #endif
     1022# endif
    10051023    /* fClass. */
    10061024    PDM_DRVREG_CLASS_CHAR,
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette