VirtualBox

Changeset 40639 in vbox for trunk/src/VBox/Devices/Parallel


Ignore:
Timestamp:
Mar 26, 2012 12:49:47 PM (13 years ago)
Author:
vboxsync
Message:

Devices/Parallel/DrvHostParallel: add some review comments, variable naming conventions, logging cleanup, use offset and bit definitions, whitespace cleanup

File:
1 edited

Legend:

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

    r40591 r40639  
    33 * VirtualBox Host Parallel Port Driver.
    44 *
    5  * Contributed by: Alexander Eichner
     5 * Initial Linux-only code contributed by: Alexander Eichner
    66 */
    77
    88/*
    9  * Copyright (C) 2006-2010 Oracle Corporation
     9 * Copyright (C) 2006-2012 Oracle Corporation
    1010 *
    1111 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    6161#endif
    6262
    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)
    6464# include <Wdm.h>
    6565# include <parallel.h>
     
    6868
    6969#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>
    7878#endif
    7979
     
    123123    uint32_t                      u32LptAddrControl;
    124124    /** Data read buffer. */
    125     uint8_t                       bReadIn;
     125    uint8_t                       u8ReadIn;
    126126    /** Control read buffer. */
    127     uint8_t                       bReadInControl;
     127    uint8_t                       u8ReadInControl;
    128128    /** Status read buffer. */
    129     uint8_t                       bReadInStatus;
     129    uint8_t                       u8ReadInStatus;
    130130    /** Whether the parallel port is available or not. */
    131     uint8_t                       bParportAvail;
     131    bool                          fParportAvail;
    132132# ifdef IN_RING0
    133133    typedef struct DEVICE_EXTENSION
     
    183183{
    184184    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));
    186186    ASMOutU8(pThis->u32LptAddr, (uint8_t)(u64Arg));
    187187    return VINF_SUCCESS;
     
    189189
    190190/**
    191  * R0 mode function to write byte value to paralell port control
     191 * R0 mode function to write byte value to parallel port control
    192192 * register.
    193193 * @returns VBox status code.
     
    198198{
    199199    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));
    201201    ASMOutU8(pThis->u32LptAddrControl, (uint8_t)(u64Arg));
    202202    return VINF_SUCCESS;
     
    213213{
    214214    uint8_t u8Data;
    215     LogFlow(("%s Read from PPort\n", __FUNCTION__));
    216215    PDRVHOSTPARALLEL pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTPARALLEL);
    217216    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;
    220219    return VINF_SUCCESS;
    221220}
     
    231230{
    232231    uint8_t u8Data;
    233     LogFlow(("%s Read from PPort control\n", __FUNCTION__));
    234232    PDRVHOSTPARALLEL pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTPARALLEL);
    235233    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;
    238236    return VINF_SUCCESS;
    239237}
     
    249247{
    250248    uint8_t u8Data;
    251     LogFlow(("%s Read from PPort Status\n", __FUNCTION__));
    252249    PDRVHOSTPARALLEL pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTPARALLEL);
    253250    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;
    256253    return VINF_SUCCESS;
    257254}
     
    268265    uint8_t u8ReadControlVal;
    269266    uint8_t u8WriteControlVal;
    270     uint8_t u8TmpData;
    271267    PDRVHOSTPARALLEL pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTPARALLEL);
    272268
    273269    if (u64Arg)
    274270    {
    275        u8TmpData = 0x08; /* Set the control bit */
    276271       u8ReadControlVal = ASMInU8(pThis->u32LptAddrControl);
    277        u8WriteControlVal = u8ReadControlVal | u8TmpData;
     272       u8WriteControlVal = u8ReadControlVal | DCR_DIRECTION; /* enable input direction */
    278273       ASMOutU8(pThis->u32LptAddrControl, u8WriteControlVal);
    279274    }
    280275    else
    281276    {
    282         u8TmpData = 0xF7; /* Clear the control register 5th bit */
    283277        u8ReadControlVal = ASMInU8(pThis->u32LptAddrControl);
    284         u8WriteControlVal = u8ReadControlVal & u8TmpData;
     278        u8WriteControlVal = u8ReadControlVal & ~DCR_DIRECTION; /* disable input direction */
    285279        ASMOutU8(pThis->u32LptAddrControl, u8WriteControlVal);
    286280    }
     
    293287PDMBOTHCBDECL(int) drvR0HostParallelReqHandler(PPDMDRVINS pDrvIns, uint32_t uOperation, uint64_t u64Arg)
    294288{
    295     LogFlow(("Requst Handler\n"));
     289    int rc;
     290
     291    LogFlowFuncEnter();
    296292    switch ((DRVHOSTPARALLELR0OP)uOperation)
    297293    {
    298294        case DRVHOSTPARALLELR0OP_READ:
    299             LogFlow(("Read Op\n"));
    300             return drvR0HostParallelReqRead(pDrvIns, u64Arg);
     295            rc = drvR0HostParallelReqRead(pDrvIns, u64Arg);
    301296
    302297        case DRVHOSTPARALLELR0OP_READSTATUS:
    303             LogFlow(("Read Status \n"));
    304             return drvR0HostParallelReqReadStatus(pDrvIns, u64Arg);
     298            rc = drvR0HostParallelReqReadStatus(pDrvIns, u64Arg);
    305299
    306300        case DRVHOSTPARALLELR0OP_READCONTROL:
    307             LogFlow(("Read CTRL\n"));
    308             return drvR0HostParallelReqReadControl(pDrvIns, u64Arg);
     301            rc = drvR0HostParallelReqReadControl(pDrvIns, u64Arg);
    309302
    310303        case DRVHOSTPARALLELR0OP_WRITE:
    311             LogFlow(("Write Ope\n"));
    312             return drvR0HostParallelReqWrite(pDrvIns, u64Arg);
     304            rc = drvR0HostParallelReqWrite(pDrvIns, u64Arg);
    313305
    314306        case DRVHOSTPARALLELR0OP_WRITECONTROL:
    315             LogFlow(("Write CTRL\n"));
    316             return drvR0HostParallelReqWriteControl(pDrvIns, u64Arg);
     307            rc = drvR0HostParallelReqWriteControl(pDrvIns, u64Arg);
    317308
    318309        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;
    325317}
    326318#endif /**IN_RING0*/
     
    375367            CM_Free_Res_Des_Handle(nextLogConf);
    376368            break;
    377         };  /** @todo Is this semicolon intended? */
     369        }
    378370        cmRet = CM_Get_Res_Des_Data(nextLogConf, pBuf, u32Size, 0L);
    379371        if (cmRet != CR_SUCCESS)
     
    383375            break;
    384376        }
    385         LogFlow(("Call GetIOResource\n"));
     377        LogFlowFunc(("call GetIOResource\n"));
    386378        u32ParportAddr = ((IO_DES*)(pBuf))->IOD_Alloc_Base;
    387         LogFlow(("Called GetIOResource. Ret = %x\n", u32ParportAddr));
     379        LogFlowFunc(("called GetIOResource, ret=%#x\n", u32ParportAddr));
    388380        rdPrevResDes = 0;
    389381        cmRet = CM_Get_Next_Res_Des(&rdPrevResDes,
     
    402394    }
    403395    CM_Free_Res_Des_Handle(nextLogConf);
    404     LogFlow(("Return u32ParportAddr=%x", u32ParportAddr));
     396    LogFlowFunc(("return u32ParportAddr=%#x", u32ParportAddr));
    405397    return u32ParportAddr;
    406398}
     
    448440        if (pBuf)
    449441        {
    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. */
    452444             {
    453                  LogFlow(("Found parallel port\n"));
     445                 LogFlowFunc(("found parallel port\n"));
    454446                 u32ParportAddr = FindIORangeResource(DeviceInfoData.DevInst);
    455447                 if (u32ParportAddr)
    456448                 {
    457                      pThis->bParportAvail = true;
     449                     pThis->fParportAvail = true;
    458450                     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;
    461453                 }
    462                  if (pThis->bParportAvail)
     454                 if (pThis->fParportAvail)
    463455                     break;
    464456             }
     
    466458        if (pBuf)
    467459            RTMemFree(pBuf);
    468         if (pThis->bParportAvail)
     460        if (pThis->fParportAvail)
    469461        {
    470             /* Parport address has been found. No Need to iterate further. */
     462            /* Parallel port address has been found. No need to iterate further. */
    471463            break;
    472464        }
     
    474466
    475467    if (GetLastError() != NO_ERROR && GetLastError() != ERROR_NO_MORE_ITEMS)
    476         rc =  VERR_GENERAL_FAILURE;;
     468        rc =  VERR_GENERAL_FAILURE;
    477469
    478470    SetupDiDestroyDeviceInfoList(hDevInfo);
     
    493485    int iMode = 0;
    494486    int rc = VINF_SUCCESS;
    495     LogFlow(("%s: mode=%d\n", __FUNCTION__, enmMode));
     487    LogFlowFunc(("mode=%d\n", enmMode));
    496488
    497489#ifndef VBOX_WITH_WIN_PARPORT_SUP
     
    556548    int rcLnx = 0;
    557549
    558     LogFlow(("%s: pvBuf=%#p cbWrite=%d\n", __FUNCTION__, pvBuf, cbWrite));
     550    LogFlowFunc(("pvBuf=%#p cbWrite=%d\n", pvBuf, cbWrite));
    559551
    560552    rc = drvHostParallelSetMode(pThis, enmMode);
     
    575567        rc = RTErrConvertFromErrno(errno);
    576568#else /*VBOX_WITH_WIN_PARPORT_SUP*/
     569    /** @todo r=klaus this code assumes cbWrite==1, which may not be guaranteed forever */
    577570    uint64_t u64Data;
    578571    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)
    581574    {
    582575        rc = PDMDrvHlpCallR0(pThis->CTX_SUFF(pDrvIns), DRVHOSTPARALLELR0OP_WRITE, u64Data);
    583         if (RT_FAILURE(rc))
    584             AssertRC(rc);
     576        AssertRC(rc);
    585577    }
    586578#endif /* VBOX_WITH_WIN_PARPORT_SUP */
     
    598590#ifndef VBOX_WITH_WIN_PARPORT_SUP
    599591    int rcLnx = 0;
    600     LogFlow(("%s: pvBuf=%#p cbRead=%d\n", __FUNCTION__, pvBuf, cbRead));
     592    LogFlowFunc(("pvBuf=%#p cbRead=%d\n", pvBuf, cbRead));
    601593
    602594    rc = drvHostParallelSetMode(pThis, enmMode);
     
    617609        rc = RTErrConvertFromErrno(errno);
    618610#else /* VBOX_WITH_WIN_PARPORT_SUP */
     611    /** @todo r=klaus this code assumes cbRead==1, which may not be guaranteed forever */
    619612    *((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)
    622615    {
    623616        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;
    627619    }
    628620#endif
     
    646638    uint64_t u64Data;
    647639    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)
    650642    {
    651643        rc = PDMDrvHlpCallR0(pThis->CTX_SUFF(pDrvIns), DRVHOSTPARALLELR0OP_SETPORTDIRECTION, u64Data);
    652         if (RT_FAILURE(rc))
    653             AssertRC(rc);
     644        AssertRC(rc);
    654645    }
    655646#endif /* VBOX_WITH_WIN_PARPORT_SUP */
     
    666657    int rcLnx = 0;
    667658
    668     LogFlow(("%s: fReg=%d\n", __FUNCTION__, fReg));
     659    LogFlowFunc(("fReg=%#x\n", fReg));
    669660# ifndef VBOX_WITH_WIN_PARPORT_SUP
    670661    rcLnx = ioctl(RTFileToNative(pThis->hFileDevice), PPWCONTROL, &fReg);
     
    674665    uint64_t u64Data;
    675666    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)
    678669    {
    679670        rc = PDMDrvHlpCallR0(pThis->CTX_SUFF(pDrvIns), DRVHOSTPARALLELR0OP_WRITECONTROL, u64Data);
    680         if (RT_FAILURE(rc))
    681             AssertRC(rc);
     671        AssertRC(rc);
    682672    }
    683673#endif /* VBOX_WITH_WIN_PARPORT_SUP */
     
    702692    else
    703693    {
    704         LogFlow(("%s: fReg=%d\n", __FUNCTION__, fReg));
     694        LogFlowFunc(("fReg=%#x\n", fReg));
    705695        *pfReg = fReg;
    706696    }
    707697#else /* VBOX_WITH_WIN_PARPORT_SUP */
    708698    *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"));
    712702        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;
    716705    }
    717706#endif /* VBOX_WITH_WIN_PARPORT_SUP */
     
    734723    else
    735724    {
    736         LogFlow(("%s: fReg=%d\n", __FUNCTION__, fReg));
     725        LogFlowFunc(("fReg=%#x\n", fReg));
    737726        *pfReg = fReg;
    738727    }
    739728#else /* VBOX_WITH_WIN_PARPORT_SUP */
    740729    *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"));
    744733        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;
    748736    }
    749737#endif /* VBOX_WITH_WIN_PARPORT_SUP */
     
    825813{
    826814    PDRVHOSTPARALLEL pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTPARALLEL);
    827     LogFlow(("%s: iInstance=%d\n", __FUNCTION__, pDrvIns->iInstance));
     815    LogFlowFunc(("iInstance=%d\n", pDrvIns->iInstance));
    828816    PDMDRV_CHECK_VERSIONS_RETURN_VOID(pDrvIns);
    829817
     
    860848{
    861849    PDRVHOSTPARALLEL pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTPARALLEL);
    862     LogFlow(("%s: iInstance=%d\n", __FUNCTION__, pDrvIns->iInstance));
     850    LogFlowFunc(("iInstance=%d\n", pDrvIns->iInstance));
    863851
    864852    PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns);
     
    966954
    967955#else /* VBOX_WITH_WIN_PARPORT_SUP */
    968     pThis->bParportAvail = false;
     956    pThis->fParportAvail = false;
    969957    pThis->u32LptAddr = 0L;
    970958    pThis->u32LptAddrControl = 0L;
     
    972960    rc = drvHostParallelGetParportAddr(pThis);
    973961    return rc;
    974     /** @todo code after unconditional return? Either #if 0 it or remove. */
    975962    HANDLE hPort;
     963    /** @todo r=klaus convert to IPRT */
    976964    hPort = CreateFile("LPT1", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ,
    977965                NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
    978966    if (INVALID_HANDLE_VALUE == hPort)
    979967    {
    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();
    982973    }
    983974#endif /* VBOX_WITH_WIN_PARPORT_SUP  */
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