VirtualBox

Changeset 29521 in vbox


Ignore:
Timestamp:
May 17, 2010 10:14:22 AM (15 years ago)
Author:
vboxsync
Message:

PDM: Added PDMDevHlpCallR0 and PDMDEV_VALIDATE_CONFIG_RETURN.

Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/pdmapi.h

    r28801 r29521  
    88
    99/*
    10  * Copyright (C) 2006-2007 Oracle Corporation
     10 * Copyright (C) 2006-2010 Oracle Corporation
    1111 *
    1212 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    3333#include <VBox/types.h>
    3434#include <VBox/sup.h>
     35#include <VBox/pdmcommon.h>
    3536
    3637RT_C_DECLS_BEGIN
     
    167168VMMR0_INT_DECL(int) PDMR0DriverCallReqHandler(PVM pVM, PPDMDRIVERCALLREQHANDLERREQ pReq);
    168169
     170/**
     171 * Request buffer for PDMR0DeviceCallReqHandler / VMMR0_DO_PDM_DEVICE_CALL_REQ_HANDLER.
     172 * @see PDMR0DeviceCallReqHandler.
     173 */
     174typedef struct PDMDEVICECALLREQHANDLERREQ
     175{
     176    /** The header. */
     177    SUPVMMR0REQHDR          Hdr;
     178    /** The device instance. */
     179    PPDMDEVINSR0            pDevInsR0;
     180    /** The request handler for the device. */
     181    PFNPDMDEVREQHANDLERR0   pfnReqHandlerR0;
     182    /** The operation. */
     183    uint32_t                uOperation;
     184    /** Explicit alignment padding. */
     185    uint32_t                u32Alignment;
     186    /** Optional 64-bit integer argument. */
     187    uint64_t                u64Arg;
     188} PDMDEVICECALLREQHANDLERREQ;
     189/** Pointer to a PDMR0DeviceCallReqHandler /
     190 * VMMR0_DO_PDM_DEVICE_CALL_REQ_HANDLER request buffer. */
     191typedef PDMDEVICECALLREQHANDLERREQ *PPDMDEVICECALLREQHANDLERREQ;
     192
     193VMMR0_INT_DECL(int) PDMR0DeviceCallReqHandler(PVM pVM, PPDMDEVICECALLREQHANDLERREQ pReq);
     194
    169195/** @} */
    170196
  • trunk/include/VBox/pdmcommon.h

    r28800 r29521  
    44
    55/*
    6  * Copyright (C) 2006-2007 Oracle Corporation
     6 * Copyright (C) 2006-2010 Oracle Corporation
    77 *
    88 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    132132typedef FNPDMDRVASYNCNOTIFY *PFNPDMDRVASYNCNOTIFY;
    133133
     134
    134135/**
    135  * The ring-0 driver request handle.
     136 * The ring-0 driver request handler.
     137 *
     138 * @returns VBox status code. PDMDevHlpCallR0 will return this.
     139 * @param   pDevIns     The device instance (the ring-0 mapping).
     140 * @param   uOperation  The operation.
     141 * @param   u64Arg      Optional integer argument for the operation.
     142 */
     143typedef DECLCALLBACK(int) FNPDMDEVREQHANDLERR0(PPDMDEVINS pDevIns, uint32_t uOperation, uint64_t u64Arg);
     144/** Ring-0 pointer to a FNPDMDEVREQHANDLERR0. */
     145typedef R0PTRTYPE(FNPDMDEVREQHANDLERR0 *) PFNPDMDEVREQHANDLERR0;
     146
     147/**
     148 * The ring-0 driver request handler.
    136149 *
    137150 * @returns VBox status code. PDMDrvHlpCallR0 will return this.
     
    144157typedef R0PTRTYPE(FNPDMDRVREQHANDLERR0 *) PFNPDMDRVREQHANDLERR0;
    145158
     159
    146160/** @} */
    147161
  • trunk/include/VBox/pdmdev.h

    r28800 r29521  
    29952995                                                           const char *pszSymPrefix, const char *pszSymList));
    29962996
     2997    /**
     2998     * Call the ring-0 request handler routine of the device.
     2999     *
     3000     * For this to work, the device must be ring-0 enabled and export a request
     3001     * handler function.  The name of the function must be the device name in
     3002     * the PDMDRVREG struct prefixed with 'drvR0' and suffixed with
     3003     * 'ReqHandler'.  The device name will be captialized.  It shall take the
     3004     * exact same arguments as this function and be declared using
     3005     * PDMBOTHCBDECL. See FNPDMDEVREQHANDLERR0.
     3006     *
     3007     * Unlike PDMDrvHlpCallR0, this is current unsuitable for more than a call
     3008     * or two as the handler address will be resolved on each invocation.  This
     3009     * is the reason for the EMT only restriction as well.
     3010     *
     3011     * @returns VBox status code.
     3012     * @retval  VERR_SYMBOL_NOT_FOUND if the device doesn't export the required
     3013     *          handler function.
     3014     * @retval  VERR_ACCESS_DENIED if the device isn't ring-0 capable.
     3015     *
     3016     * @param   pDevIns             The device instance.
     3017     * @param   uOperation          The operation to perform.
     3018     * @param   u64Arg              64-bit integer argument.
     3019     * @thread  EMT
     3020     */
     3021    DECLR3CALLBACKMEMBER(int, pfnCallR0,(PPDMDEVINS pDevIns, uint32_t uOperation, uint64_t u64Arg));
     3022
    29973023    /** Space reserved for future members.
    29983024     * @{ */
     
    35643590                        || !PDM_VERSION_ARE_COMPATIBLE((pDevIns)->pHlpR3->u32Version, PDM_DEVHLPR3_VERSION) )) \
    35653591            return VERR_VERSION_MISMATCH; \
     3592    } while (0)
     3593
     3594/**
     3595 * Wrapper around CFGMR3ValidateConfig for the root config for use in the
     3596 * constructor - returns on failure.
     3597 *
     3598 * This should be invoked after having initialized the instance data
     3599 * sufficiently for the correct operation of the destructor.  The destructor is
     3600 * always called!
     3601 *
     3602 * @param   pDevIns             Pointer to the PDM device instance.
     3603 * @param   pszValidValues      Patterns describing the valid value names.  See
     3604 *                              RTStrSimplePatternMultiMatch for details on the
     3605 *                              pattern syntax.
     3606 * @param   pszValidNodes       Patterns describing the valid node (key) names.
     3607 *                              Pass empty string if no valid nodess.
     3608 */
     3609#define PDMDEV_VALIDATE_CONFIG_RETURN(pDevIns, pszValidValues, pszValidNodes) \
     3610    do \
     3611    { \
     3612        int rcValCfg = CFGMR3ValidateConfig((pDevIns)->pCfg, "/", pszValidValues, pszValidNodes, \
     3613                                            (pDevIns)->pReg->szName, (pDevIns)->iInstance); \
     3614        if (RT_FAILURE(rcValCfg)) \
     3615            return rcValCfg; \
    35663616    } while (0)
    35673617
     
    42894339}
    42904340
     4341/**
     4342 * @copydoc PDMDEVHLP::pfnCallR0
     4343 */
     4344DECLINLINE(int) PDMDevHlpCallR0(PPDMDEVINS pDevIns, uint32_t uOperation, uint64_t u64Arg)
     4345{
     4346    return pDevIns->pHlpR3->pfnCallR0(pDevIns, uOperation, u64Arg);
     4347}
     4348
    42914349#endif /* IN_RING3 */
    42924350
  • trunk/include/VBox/pdmdrv.h

    r28800 r29521  
    11621162     *
    11631163     * @returns VBox status code.
    1164      * @param   pDevIns             The device instance.
     1164     * @param   pDrvIns             The driver instance.
    11651165     * @param   pCritSect           Pointer to the critical section.
    11661166     * @param   RT_SRC_POS_DECL     Use RT_SRC_POS.
     
    11791179     * For this to work, the driver must be ring-0 enabled and export a request
    11801180     * handler function.  The name of the function must be the driver name in the
    1181      * PDMDRVREG struct prefixed with 'drvR0' and suffixed with 'ReqHandler'.  It
    1182      * shall take the exact same arguments as this function and be declared using
    1183      * PDMBOTHCBDECL.  See FNPDMDRVREQHANDLERR0.
     1181     * PDMDRVREG struct prefixed with 'drvR0' and suffixed with 'ReqHandler'.
     1182     * The driver name will be capitalized.  It shall take the exact same
     1183     * arguments as this function and be declared using PDMBOTHCBDECL.  See
     1184     * FNPDMDRVREQHANDLERR0.
    11841185     *
    11851186     * @returns VBox status code.
     
    11881189     * @retval  VERR_ACCESS_DENIED if the driver isn't ring-0 capable.
    11891190     *
    1190      * @param   pDevIns             The device instance.
     1191     * @param   pDrvIns             The driver instance.
    11911192     * @param   uOperation          The operation to perform.
    11921193     * @param   u64Arg              64-bit integer argument.
  • trunk/include/VBox/vmm.h

    r29424 r29521  
    44
    55/*
    6  * Copyright (C) 2006-2007 Oracle Corporation
     6 * Copyright (C) 2006-2010 Oracle Corporation
    77 *
    88 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    322322    /** Call PDMR0DriverCallReqHandler. */
    323323    VMMR0_DO_PDM_DRIVER_CALL_REQ_HANDLER,
     324    /** Call PDMR0DeviceCallReqHandler. */
     325    VMMR0_DO_PDM_DEVICE_CALL_REQ_HANDLER,
    324326
    325327    /** The start of the R0 service operations. */
  • trunk/src/VBox/VMM/PDMDevHlp.cpp

    r28800 r29521  
    3636#include <iprt/asm.h>
    3737#include <iprt/assert.h>
     38#include <iprt/ctype.h>
    3839#include <iprt/string.h>
    3940#include <iprt/thread.h>
     
    18471848
    18481849    LogFlow(("pdmR3DevHlp_PDMLdrGetR0InterfaceSymbols: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName,
     1850             pDevIns->iInstance, rc));
     1851    return rc;
     1852}
     1853
     1854
     1855/** @interface_method_impl{PDMDEVHLP,pfnCallR0} */
     1856static DECLCALLBACK(int) pdmR3DevHlp_CallR0(PPDMDEVINS pDevIns, uint32_t uOperation, uint64_t u64Arg)
     1857{
     1858    PDMDEV_ASSERT_DEVINS(pDevIns);
     1859    PVM pVM = pDevIns->Internal.s.pVMR3;
     1860    VM_ASSERT_EMT(pDevIns->Internal.s.pVMR3);
     1861    LogFlow(("pdmR3DevHlp_CallR0: caller='%s'/%d: uOperation=%#x u64Arg=%#RX64\n",
     1862             pDevIns->pReg->szName, pDevIns->iInstance, uOperation, u64Arg));
     1863
     1864    /*
     1865     * Resolve the ring-0 entry point.  There is not need to remember this like
     1866     * we do for drivers since this is mainly for construction time hacks and
     1867     * other things that aren't performance critical.
     1868     */
     1869    int rc;
     1870    if (pDevIns->pReg->fFlags & PDM_DEVREG_FLAGS_R0)
     1871    {
     1872        char szSymbol[          sizeof("devR0") + sizeof(pDevIns->pReg->szName) + sizeof("ReqHandler")];
     1873        strcat(strcat(strcpy(szSymbol, "devR0"),         pDevIns->pReg->szName),         "ReqHandler");
     1874        szSymbol[sizeof("devR0") - 1] = RT_C_TO_UPPER(szSymbol[sizeof("devR0") - 1]);
     1875
     1876        PFNPDMDRVREQHANDLERR0 pfnReqHandlerR0;
     1877        rc = PDMR3LdrGetSymbolR0Lazy(pVM, pDevIns->pReg->szR0Mod, szSymbol, &pfnReqHandlerR0);
     1878        if (RT_SUCCESS(rc))
     1879        {
     1880            /*
     1881             * Make the ring-0 call.
     1882             */
     1883            PDMDEVICECALLREQHANDLERREQ Req;
     1884            Req.Hdr.u32Magic    = SUPVMMR0REQHDR_MAGIC;
     1885            Req.Hdr.cbReq       = sizeof(Req);
     1886            Req.pDevInsR0       = PDMDEVINS_2_R0PTR(pDevIns);
     1887            Req.pfnReqHandlerR0 = pfnReqHandlerR0;
     1888            Req.uOperation      = uOperation;
     1889            Req.u32Alignment    = 0;
     1890            Req.u64Arg          = u64Arg;
     1891            rc = SUPR3CallVMMR0Ex(pVM->pVMR0, NIL_VMCPUID, VMMR0_DO_PDM_DEVICE_CALL_REQ_HANDLER, 0, &Req.Hdr);
     1892        }
     1893        else
     1894            pfnReqHandlerR0 = NIL_RTR0PTR;
     1895    }
     1896    else
     1897        rc = VERR_ACCESS_DENIED;
     1898    LogFlow(("pdmR3DevHlp_CallR0: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName,
    18491899             pDevIns->iInstance, rc));
    18501900    return rc;
     
    29282978    pdmR3DevHlp_LdrGetRCInterfaceSymbols,
    29292979    pdmR3DevHlp_LdrGetR0InterfaceSymbols,
     2980    pdmR3DevHlp_CallR0,
    29302981    0,
    29312982    0,
     
    31233174    pdmR3DevHlp_LdrGetRCInterfaceSymbols,
    31243175    pdmR3DevHlp_LdrGetR0InterfaceSymbols,
     3176    pdmR3DevHlp_CallR0,
    31253177    0,
    31263178    0,
  • trunk/src/VBox/VMM/PDMDriver.cpp

    r28853 r29521  
    3333#include <VBox/log.h>
    3434#include <iprt/assert.h>
     35#include <iprt/asm.h>
     36#include <iprt/ctype.h>
     37#include <iprt/mem.h>
    3538#include <iprt/thread.h>
     39#include <iprt/path.h>
    3640#include <iprt/string.h>
    37 #include <iprt/asm.h>
    38 #include <iprt/alloc.h>
    39 #include <iprt/path.h>
    4041
    4142
     
    13191320            char szSymbol[          sizeof("drvR0") + sizeof(pDrvIns->pReg->szName) + sizeof("ReqHandler")];
    13201321            strcat(strcat(strcpy(szSymbol, "drvR0"),         pDrvIns->pReg->szName),         "ReqHandler");
     1322            szSymbol[sizeof("drvR0") - 1] = RT_C_TO_UPPER(szSymbol[sizeof("drvR0") - 1]);
     1323
    13211324            rc = PDMR3LdrGetSymbolR0Lazy(pVM, pDrvIns->pReg->szR0Mod, szSymbol, &pfnReqHandlerR0);
    13221325            if (RT_SUCCESS(rc))
  • trunk/src/VBox/VMM/PDMInternal.h

    r28800 r29521  
    55
    66/*
    7  * Copyright (C) 2006-2007 Oracle Corporation
     7 * Copyright (C) 2006-2010 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
  • trunk/src/VBox/VMM/VMMR0/PDMR0Device.cpp

    r28800 r29521  
    718718
    719719/**
    720  * The Raw-Mode Context Driver Helper Callbacks.
     720 * The Ring-0 Context Driver Helper Callbacks.
    721721 */
    722722extern DECLEXPORT(const PDMDRVHLPR0) g_pdmR0DrvHlp =
     
    809809    }
    810810}
     811
     812
     813/**
     814 * PDMDevHlpCallR0 helper.
     815 *
     816 * @returns See PFNPDMDEVREQHANDLERR0.
     817 * @param   pVM                 The VM handle (for validation).
     818 * @param   pReq                The request buffer.
     819 */
     820VMMR0_INT_DECL(int) PDMR0DeviceCallReqHandler(PVM pVM, PPDMDEVICECALLREQHANDLERREQ pReq)
     821{
     822    /*
     823     * Validate input and make the call.
     824     */
     825    AssertPtrReturn(pVM, VERR_INVALID_POINTER);
     826    AssertPtrReturn(pReq, VERR_INVALID_POINTER);
     827    AssertMsgReturn(pReq->Hdr.cbReq == sizeof(*pReq), ("%#x != %#x\n", pReq->Hdr.cbReq, sizeof(*pReq)), VERR_INVALID_PARAMETER);
     828
     829    PPDMDEVINS pDevIns = pReq->pDevInsR0;
     830    AssertPtrReturn(pDevIns, VERR_INVALID_POINTER);
     831    AssertReturn(pDevIns->Internal.s.pVMR0 == pVM, VERR_INVALID_PARAMETER);
     832
     833    PFNPDMDEVREQHANDLERR0 pfnReqHandlerR0 = pReq->pfnReqHandlerR0;
     834    AssertPtrReturn(pfnReqHandlerR0, VERR_INVALID_POINTER);
     835
     836    return pfnReqHandlerR0(pDevIns, pReq->uOperation, pReq->u64Arg);
     837}
     838
  • trunk/src/VBox/VMM/VMMR0/VMMR0.cpp

    r29458 r29521  
    55
    66/*
    7  * Copyright (C) 2006-2007 Oracle Corporation
     7 * Copyright (C) 2006-2010 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    10151015        }
    10161016
     1017        case VMMR0_DO_PDM_DEVICE_CALL_REQ_HANDLER:
     1018        {
     1019            if (!pVM || !pReqHdr || u64Arg || idCpu != NIL_VMCPUID)
     1020                return VERR_INVALID_PARAMETER;
     1021            return PDMR0DeviceCallReqHandler(pVM, (PPDMDEVICECALLREQHANDLERREQ)pReqHdr);
     1022        }
     1023
    10171024        /*
    10181025         * Requests to the internal networking service.
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