VirtualBox

Changeset 44856 in vbox for trunk


Ignore:
Timestamp:
Feb 27, 2013 10:45:10 PM (12 years ago)
Author:
vboxsync
Message:

DevVirtioNet.cpp: Callback table for I/O port handlers instead of pushing 2-6 ffunction pointers on the stack for every port access.

Location:
trunk/src/VBox/Devices
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Network/DevVirtioNet.cpp

    r44852 r44856  
    367367}
    368368
    369 static uint32_t vnetGetHostFeatures(void *pvState)
     369static DECLCALLBACK(uint32_t) vnetIoCb_GetHostFeatures(void *pvState)
    370370{
    371371    /* We support:
     
    397397}
    398398
    399 static uint32_t vnetGetHostMinimalFeatures(void *pvState)
     399static DECLCALLBACK(uint32_t) vnetIoCb_GetHostMinimalFeatures(void *pvState)
    400400{
    401401    return VNET_F_MAC;
    402402}
    403403
    404 static void vnetSetHostFeatures(void *pvState, uint32_t fFeatures)
     404static DECLCALLBACK(void) vnetIoCb_SetHostFeatures(void *pvState, uint32_t fFeatures)
    405405{
    406406    /** @todo Nothing to do here yet */
    407407    PVNETSTATE pThis = (PVNETSTATE)pvState;
    408     LogFlow(("%s vnetSetHostFeatures: uFeatures=%x\n", INSTANCE(pThis), fFeatures));
     408    LogFlow(("%s vnetIoCb_SetHostFeatures: uFeatures=%x\n", INSTANCE(pThis), fFeatures));
    409409    vnetPrintFeatures(pThis, fFeatures, "The guest negotiated the following features");
    410410}
    411411
    412 static int vnetGetConfig(void *pvState, uint32_t port, uint32_t cb, void *data)
     412static DECLCALLBACK(int) vnetIoCb_GetConfig(void *pvState, uint32_t offCfg, uint32_t cb, void *data)
    413413{
    414414    PVNETSTATE pThis = (PVNETSTATE)pvState;
    415     if (port + cb > sizeof(struct VNetPCIConfig))
    416     {
    417         Log(("%s vnetGetConfig: Read beyond the config structure is attempted (port=%RTiop cb=%x).\n", INSTANCE(pThis), port, cb));
     415    if (offCfg + cb > sizeof(struct VNetPCIConfig))
     416    {
     417        Log(("%s vnetIoCb_GetConfig: Read beyond the config structure is attempted (offCfg=%#x cb=%x).\n", INSTANCE(pThis), offCfg, cb));
    418418        return VERR_IOM_IOPORT_UNUSED;
    419419    }
    420     memcpy(data, ((uint8_t*)&pThis->config) + port, cb);
     420    memcpy(data, (uint8_t *)&pThis->config + offCfg, cb);
    421421    return VINF_SUCCESS;
    422422}
    423423
    424 static int vnetSetConfig(void *pvState, uint32_t port, uint32_t cb, void *data)
     424static DECLCALLBACK(int) vnetIoCb_SetConfig(void *pvState, uint32_t offCfg, uint32_t cb, void *data)
    425425{
    426426    PVNETSTATE pThis = (PVNETSTATE)pvState;
    427     if (port + cb > sizeof(struct VNetPCIConfig))
    428     {
    429         Log(("%s vnetGetConfig: Write beyond the config structure is attempted (port=%RTiop cb=%x).\n", INSTANCE(pThis), port, cb));
    430         if (port < sizeof(struct VNetPCIConfig))
    431             memcpy(((uint8_t*)&pThis->config) + port, data,
    432                    sizeof(struct VNetPCIConfig) - port);
     427    if (offCfg + cb > sizeof(struct VNetPCIConfig))
     428    {
     429        Log(("%s vnetIoCb_SetConfig: Write beyond the config structure is attempted (offCfg=%#x cb=%x).\n", INSTANCE(pThis), offCfg, cb));
     430        if (offCfg < sizeof(struct VNetPCIConfig))
     431            memcpy((uint8_t *)&pThis->config + offCfg, data,
     432                   sizeof(struct VNetPCIConfig) - offCfg);
    433433        return VINF_SUCCESS;
    434434    }
    435     memcpy(((uint8_t*)&pThis->config) + port, data, cb);
     435    memcpy((uint8_t *)&pThis->config + offCfg, data, cb);
    436436    return VINF_SUCCESS;
    437437}
     
    442442 * @param   pThis      The device state structure.
    443443 */
    444 static int vnetReset(void *pvState)
     444static DECLCALLBACK(int) vnetIoCb_Reset(void *pvState)
    445445{
    446446    PVNETSTATE pThis = (PVNETSTATE)pvState;
     
    450450    if (RT_UNLIKELY(rc != VINF_SUCCESS))
    451451    {
    452         LogRel(("vnetReset failed to enter RX critical section!\n"));
     452        LogRel(("vnetIoCb_Reset failed to enter RX critical section!\n"));
    453453        return rc;
    454454    }
     
    532532 * @param   pThis      The device state structure.
    533533 */
    534 static void vnetReady(void *pvState)
     534static void vnetIoCb_Ready(void *pvState)
    535535{
    536536    PVNETSTATE pThis = (PVNETSTATE)pvState;
     
    545545}
    546546
     547
     548/**
     549 * I/O port callbacks.
     550 */
     551static const VPCIIOCALLBACKS g_IOCallbacks =
     552{
     553     vnetIoCb_GetHostFeatures,
     554     vnetIoCb_GetHostMinimalFeatures,
     555     vnetIoCb_SetHostFeatures,
     556     vnetIoCb_GetConfig,
     557     vnetIoCb_SetConfig,
     558     vnetIoCb_Reset,
     559     vnetIoCb_Ready,
     560};
     561
     562
    547563/**
    548564 * @callback_method_impl{FNIOMIOPORTIN}
     
    550566PDMBOTHCBDECL(int) vnetIOPortIn(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT port, uint32_t *pu32, unsigned cb)
    551567{
    552     return vpciIOPortIn(pDevIns, pvUser, port, pu32, cb,
    553                         vnetGetHostFeatures,
    554                         vnetGetConfig);
     568    return vpciIOPortIn(pDevIns, pvUser, port, pu32, cb, &g_IOCallbacks);
    555569}
    556570
     
    561575PDMBOTHCBDECL(int) vnetIOPortOut(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT port, uint32_t u32, unsigned cb)
    562576{
    563     return vpciIOPortOut(pDevIns, pvUser, port, u32, cb,
    564                          vnetGetHostMinimalFeatures,
    565                          vnetGetHostFeatures,
    566                          vnetSetHostFeatures,
    567                          vnetReset,
    568                          vnetReady,
    569                          vnetSetConfig);
     577    return vpciIOPortOut(pDevIns, pvUser, port, u32, cb, &g_IOCallbacks);
    570578}
    571579
     
    19761984
    19771985
    1978     vnetPrintFeatures(pThis, vnetGetHostFeatures(pThis), "Device supports the following features");
     1986    vnetPrintFeatures(pThis, vnetIoCb_GetHostFeatures(pThis), "Device supports the following features");
    19791987
    19801988    /* Initialize PCI config space */
     
    20722080        return rc;
    20732081
    2074     rc = vnetReset(pThis);
     2082    rc = vnetIoCb_Reset(pThis);
    20752083    AssertRC(rc);
    20762084
  • trunk/src/VBox/Devices/VirtIO/Virtio.cpp

    r44854 r44856  
    55
    66/*
    7  * Copyright (C) 2009-2012 Oracle Corporation
     7 * Copyright (C) 2009-2013 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    3232#ifdef LOG_ENABLED
    3333# define QUEUENAME(s, q) (q->pcszName)
    34 #endif /* DEBUG */
     34#endif
    3535
    3636
     
    314314 * @param   pu32        Where to store the result.
    315315 * @param   cb          Number of bytes read.
     316 * @param   pCallbacks  Pointer to the callbacks.
    316317 * @thread  EMT
    317318 */
     
    321322                 uint32_t          *pu32,
    322323                 unsigned           cb,
    323                  PFNGETHOSTFEATURES pfnGetHostFeatures,
    324                  PFNGETCONFIG       pfnGetConfig)
     324                 PCVPCIIOCALLBACKS  pCallbacks)
    325325{
    326326    VPCISTATE  *pState = PDMINS_2_DATA(pDevIns, VPCISTATE *);
     
    349349        case VPCI_HOST_FEATURES:
    350350            /* Tell the guest what features we support. */
    351             *pu32 = vpciGetHostFeatures(pState, pfnGetHostFeatures)
     351            *pu32 = vpciGetHostFeatures(pState, pCallbacks->pfnGetHostFeatures)
    352352                    | VPCI_F_BAD_FEATURE;
    353353            break;
     
    385385        default:
    386386            if (Port >= VPCI_CONFIG)
    387                 rc = pfnGetConfig(pState, Port - VPCI_CONFIG, cb, pu32);
     387                rc = pCallbacks->pfnGetConfig(pState, Port - VPCI_CONFIG, cb, pu32);
    388388            else
    389389            {
     
    411411 * @param   u32         The value to output.
    412412 * @param   cb          The value size in bytes.
    413  * @todo    r=bird: Use a callback table instead of passing 6 function pointers
    414  *          for potential operations with each I/O port write.
     413 * @param   pCallbacks  Pointer to the callbacks.
    415414 * @thread  EMT
    416415 */
     
    420419                  uint32_t                  u32,
    421420                  unsigned                  cb,
    422                   PFNGETHOSTMINIMALFEATURES pfnGetHostMinimalFeatures,
    423                   PFNGETHOSTFEATURES        pfnGetHostFeatures,
    424                   PFNSETHOSTFEATURES        pfnSetHostFeatures,
    425                   PFNRESET                  pfnReset,
    426                   PFNREADY                  pfnReady,
    427                   PFNSETCONFIG              pfnSetConfig)
    428 
     421                  PCVPCIIOCALLBACKS         pCallbacks)
    429422{
    430423    VPCISTATE  *pState = PDMINS_2_DATA(pDevIns, VPCISTATE *);
     
    444437                Log(("%s WARNING! Guest failed to negotiate properly (guest=%x)\n",
    445438                     INSTANCE(pState), u32));
    446                 pState->uGuestFeatures = pfnGetHostMinimalFeatures(pState);
     439                pState->uGuestFeatures = pCallbacks->pfnGetHostMinimalFeatures(pState);
    447440            }
    448441            /* The guest may potentially desire features we don't support! */
    449             else if (~vpciGetHostFeatures(pState, pfnGetHostFeatures) & u32)
     442            else if (~vpciGetHostFeatures(pState, pCallbacks->pfnGetHostFeatures) & u32)
    450443            {
    451444                Log(("%s Guest asked for features host does not support! (host=%x guest=%x)\n",
    452445                     INSTANCE(pState),
    453                      vpciGetHostFeatures(pState, pfnGetHostFeatures), u32));
     446                     vpciGetHostFeatures(pState, pCallbacks->pfnGetHostFeatures), u32));
    454447                pState->uGuestFeatures =
    455                     vpciGetHostFeatures(pState, pfnGetHostFeatures);
     448                    vpciGetHostFeatures(pState, pCallbacks->pfnGetHostFeatures);
    456449            }
    457450            else
    458451                pState->uGuestFeatures = u32;
    459             pfnSetHostFeatures(pState, pState->uGuestFeatures);
     452            pCallbacks->pfnSetHostFeatures(pState, pState->uGuestFeatures);
    460453            break;
    461454
     
    471464                vqueueInit(&pState->Queues[pState->uQueueSelector], u32);
    472465            else
    473                 rc = pfnReset(pState);
     466                rc = pCallbacks->pfnReset(pState);
    474467            break;
    475468
     
    514507            /* Writing 0 to the status port triggers device reset. */
    515508            if (u32 == 0)
    516                 rc = pfnReset(pState);
     509                rc = pCallbacks->pfnReset(pState);
    517510            else if (fHasBecomeReady)
    518                 pfnReady(pState);
     511                pCallbacks->pfnReady(pState);
    519512            break;
    520513
    521514        default:
    522515            if (Port >= VPCI_CONFIG)
    523                 rc = pfnSetConfig(pState, Port - VPCI_CONFIG, cb, &u32);
     516                rc = pCallbacks->pfnSetConfig(pState, Port - VPCI_CONFIG, cb, &u32);
    524517            else
    525518                rc = PDMDevHlpDBGFStop(pDevIns, RT_SRC_POS, "%s vpciIOPortOut: no valid port at offset Port=%RTiop cb=%08x\n",
  • trunk/src/VBox/Devices/VirtIO/Virtio.h

    r44854 r44856  
    221221typedef VPCISTATE *PVPCISTATE;
    222222
    223 /** @name Callbacks
     223typedef DECLCALLBACK(uint32_t) FNGETHOSTFEATURES(void *pvState);
     224typedef FNGETHOSTFEATURES *PFNGETHOSTFEATURES;
     225
     226/** @name VirtIO port I/O callbacks.
    224227 * @{ */
    225 typedef uint32_t (*PFNGETHOSTFEATURES)(void *pState);
    226 typedef uint32_t (*PFNGETHOSTMINIMALFEATURES)(void *pState);
    227 typedef void     (*PFNSETHOSTFEATURES)(void *pState, uint32_t uFeatures);
    228 typedef int      (*PFNGETCONFIG)(void *pState, uint32_t port, uint32_t cb, void *data);
    229 typedef int      (*PFNSETCONFIG)(void *pState, uint32_t port, uint32_t cb, void *data);
    230 typedef int      (*PFNRESET)(void *pState);
    231 typedef void     (*PFNREADY)(void *pState);
     228typedef struct VPCIIOCALLBACKS
     229{
     230     DECLCALLBACKMEMBER(uint32_t, pfnGetHostFeatures)(void *pvState);
     231     DECLCALLBACKMEMBER(uint32_t, pfnGetHostMinimalFeatures)(void *pvState);
     232     DECLCALLBACKMEMBER(void,     pfnSetHostFeatures)(void *pvState, uint32_t fFeatures);
     233     DECLCALLBACKMEMBER(int,      pfnGetConfig)(void *pvState, uint32_t offCfg, uint32_t cb, void *pvData);
     234     DECLCALLBACKMEMBER(int,      pfnSetConfig)(void *pvState, uint32_t offCfg, uint32_t cb, void *pvData);
     235     DECLCALLBACKMEMBER(int,      pfnReset)(void *pvState);
     236     DECLCALLBACKMEMBER(void,     pfnReady)(void *pvState);
     237} VPCIIOCALLBACKS;
     238/** Pointer to a const VirtIO port I/O callback structure. */
     239typedef const VPCIIOCALLBACKS *PCVPCIIOCALLBACKS;
    232240/** @} */
    233241
     
    238246                 uint32_t          *pu32,
    239247                 unsigned           cb,
    240                  PFNGETHOSTFEATURES pfnGetHostFeatures,
    241                  PFNGETCONFIG       pfnGetConfig);
     248                 PCVPCIIOCALLBACKS  pCallbacks);
    242249
    243250int vpciIOPortOut(PPDMDEVINS                pDevIns,
     
    246253                  uint32_t                  u32,
    247254                  unsigned                  cb,
    248                   PFNGETHOSTMINIMALFEATURES pfnGetHostMinimalFeatures,
    249                   PFNGETHOSTFEATURES        pfnGetHostFeatures,
    250                   PFNSETHOSTFEATURES        pfnSetHostFeatures,
    251                   PFNRESET                  pfnReset,
    252                   PFNREADY                  pfnReady,
    253                   PFNSETCONFIG              pfnSetConfig);
     255                  PCVPCIIOCALLBACKS         pCallbacks);
    254256
    255257void  vpciSetWriteLed(PVPCISTATE pState, bool fOn);
    256258void  vpciSetReadLed(PVPCISTATE pState, bool fOn);
    257259int   vpciSaveExec(PVPCISTATE pState, PSSMHANDLE pSSM);
    258 int   vpciLoadExec(PVPCISTATE pState, PSSMHANDLE pSSM,
    259                    uint32_t uVersion, uint32_t uPass,
    260                    uint32_t nQueues);
    261 int   vpciConstruct(PPDMDEVINS pDevIns, VPCISTATE *pState,
    262                     int iInstance, const char *pcszNameFmt,
    263                     uint16_t uSubsystemId, uint16_t uClass,
    264                     uint32_t nQueues);
     260int   vpciLoadExec(PVPCISTATE pState, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass, uint32_t nQueues);
     261int   vpciConstruct(PPDMDEVINS pDevIns, VPCISTATE *pState, int iInstance, const char *pcszNameFmt,
     262                    uint16_t uSubsystemId, uint16_t uClass, uint32_t nQueues);
    265263int   vpciDestruct(VPCISTATE* pState);
    266264void  vpciRelocate(PPDMDEVINS pDevIns, RTGCINTPTR offDelta);
    267265void  vpciReset(PVPCISTATE pState);
    268266void *vpciQueryInterface(struct PDMIBASE *pInterface, const char *pszIID);
    269 PVQUEUE vpciAddQueue(VPCISTATE* pState, unsigned uSize,
    270                      void (*pfnCallback)(void *pvState, PVQUEUE pQueue),
    271                      const char *pcszName);
     267PVQUEUE vpciAddQueue(VPCISTATE* pState, unsigned uSize, PFNVPCIQUEUECALLBACK pfnCallback, const char *pcszName);
    272268
    273269#define VPCI_CS
    274 DECLINLINE(int) vpciCsEnter(VPCISTATE *pState, int iBusyRc)
     270DECLINLINE(int) vpciCsEnter(VPCISTATE *pState, int rcBusy)
    275271{
    276272#ifdef VPCI_CS
    277273    STAM_PROFILE_START(&pState->CTXSUFF(StatCs), a);
    278     int rc = PDMCritSectEnter(&pState->cs, iBusyRc);
     274    int rc = PDMCritSectEnter(&pState->cs, rcBusy);
    279275    STAM_PROFILE_STOP(&pState->CTXSUFF(StatCs), a);
    280276    return rc;
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