- Timestamp:
- Feb 27, 2013 10:45:10 PM (12 years ago)
- Location:
- trunk/src/VBox/Devices
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Network/DevVirtioNet.cpp
r44852 r44856 367 367 } 368 368 369 static uint32_t vnetGetHostFeatures(void *pvState)369 static DECLCALLBACK(uint32_t) vnetIoCb_GetHostFeatures(void *pvState) 370 370 { 371 371 /* We support: … … 397 397 } 398 398 399 static uint32_t vnetGetHostMinimalFeatures(void *pvState)399 static DECLCALLBACK(uint32_t) vnetIoCb_GetHostMinimalFeatures(void *pvState) 400 400 { 401 401 return VNET_F_MAC; 402 402 } 403 403 404 static void vnetSetHostFeatures(void *pvState, uint32_t fFeatures)404 static DECLCALLBACK(void) vnetIoCb_SetHostFeatures(void *pvState, uint32_t fFeatures) 405 405 { 406 406 /** @todo Nothing to do here yet */ 407 407 PVNETSTATE pThis = (PVNETSTATE)pvState; 408 LogFlow(("%s vnet SetHostFeatures: uFeatures=%x\n", INSTANCE(pThis), fFeatures));408 LogFlow(("%s vnetIoCb_SetHostFeatures: uFeatures=%x\n", INSTANCE(pThis), fFeatures)); 409 409 vnetPrintFeatures(pThis, fFeatures, "The guest negotiated the following features"); 410 410 } 411 411 412 static int vnetGetConfig(void *pvState, uint32_t port, uint32_t cb, void *data)412 static DECLCALLBACK(int) vnetIoCb_GetConfig(void *pvState, uint32_t offCfg, uint32_t cb, void *data) 413 413 { 414 414 PVNETSTATE pThis = (PVNETSTATE)pvState; 415 if ( port+ cb > sizeof(struct VNetPCIConfig))416 { 417 Log(("%s vnet GetConfig: 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)); 418 418 return VERR_IOM_IOPORT_UNUSED; 419 419 } 420 memcpy(data, ( (uint8_t*)&pThis->config) + port, cb);420 memcpy(data, (uint8_t *)&pThis->config + offCfg, cb); 421 421 return VINF_SUCCESS; 422 422 } 423 423 424 static int vnetSetConfig(void *pvState, uint32_t port, uint32_t cb, void *data)424 static DECLCALLBACK(int) vnetIoCb_SetConfig(void *pvState, uint32_t offCfg, uint32_t cb, void *data) 425 425 { 426 426 PVNETSTATE pThis = (PVNETSTATE)pvState; 427 if ( port+ cb > sizeof(struct VNetPCIConfig))428 { 429 Log(("%s vnet GetConfig: 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); 433 433 return VINF_SUCCESS; 434 434 } 435 memcpy(( (uint8_t*)&pThis->config) + port, data, cb);435 memcpy((uint8_t *)&pThis->config + offCfg, data, cb); 436 436 return VINF_SUCCESS; 437 437 } … … 442 442 * @param pThis The device state structure. 443 443 */ 444 static int vnetReset(void *pvState)444 static DECLCALLBACK(int) vnetIoCb_Reset(void *pvState) 445 445 { 446 446 PVNETSTATE pThis = (PVNETSTATE)pvState; … … 450 450 if (RT_UNLIKELY(rc != VINF_SUCCESS)) 451 451 { 452 LogRel(("vnet Reset failed to enter RX critical section!\n"));452 LogRel(("vnetIoCb_Reset failed to enter RX critical section!\n")); 453 453 return rc; 454 454 } … … 532 532 * @param pThis The device state structure. 533 533 */ 534 static void vnet Ready(void *pvState)534 static void vnetIoCb_Ready(void *pvState) 535 535 { 536 536 PVNETSTATE pThis = (PVNETSTATE)pvState; … … 545 545 } 546 546 547 548 /** 549 * I/O port callbacks. 550 */ 551 static 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 547 563 /** 548 564 * @callback_method_impl{FNIOMIOPORTIN} … … 550 566 PDMBOTHCBDECL(int) vnetIOPortIn(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT port, uint32_t *pu32, unsigned cb) 551 567 { 552 return vpciIOPortIn(pDevIns, pvUser, port, pu32, cb, 553 vnetGetHostFeatures, 554 vnetGetConfig); 568 return vpciIOPortIn(pDevIns, pvUser, port, pu32, cb, &g_IOCallbacks); 555 569 } 556 570 … … 561 575 PDMBOTHCBDECL(int) vnetIOPortOut(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT port, uint32_t u32, unsigned cb) 562 576 { 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); 570 578 } 571 579 … … 1976 1984 1977 1985 1978 vnetPrintFeatures(pThis, vnet GetHostFeatures(pThis), "Device supports the following features");1986 vnetPrintFeatures(pThis, vnetIoCb_GetHostFeatures(pThis), "Device supports the following features"); 1979 1987 1980 1988 /* Initialize PCI config space */ … … 2072 2080 return rc; 2073 2081 2074 rc = vnet Reset(pThis);2082 rc = vnetIoCb_Reset(pThis); 2075 2083 AssertRC(rc); 2076 2084 -
trunk/src/VBox/Devices/VirtIO/Virtio.cpp
r44854 r44856 5 5 6 6 /* 7 * Copyright (C) 2009-201 2Oracle Corporation7 * Copyright (C) 2009-2013 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 32 32 #ifdef LOG_ENABLED 33 33 # define QUEUENAME(s, q) (q->pcszName) 34 #endif /* DEBUG */34 #endif 35 35 36 36 … … 314 314 * @param pu32 Where to store the result. 315 315 * @param cb Number of bytes read. 316 * @param pCallbacks Pointer to the callbacks. 316 317 * @thread EMT 317 318 */ … … 321 322 uint32_t *pu32, 322 323 unsigned cb, 323 PFNGETHOSTFEATURES pfnGetHostFeatures, 324 PFNGETCONFIG pfnGetConfig) 324 PCVPCIIOCALLBACKS pCallbacks) 325 325 { 326 326 VPCISTATE *pState = PDMINS_2_DATA(pDevIns, VPCISTATE *); … … 349 349 case VPCI_HOST_FEATURES: 350 350 /* Tell the guest what features we support. */ 351 *pu32 = vpciGetHostFeatures(pState, p fnGetHostFeatures)351 *pu32 = vpciGetHostFeatures(pState, pCallbacks->pfnGetHostFeatures) 352 352 | VPCI_F_BAD_FEATURE; 353 353 break; … … 385 385 default: 386 386 if (Port >= VPCI_CONFIG) 387 rc = p fnGetConfig(pState, Port - VPCI_CONFIG, cb, pu32);387 rc = pCallbacks->pfnGetConfig(pState, Port - VPCI_CONFIG, cb, pu32); 388 388 else 389 389 { … … 411 411 * @param u32 The value to output. 412 412 * @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. 415 414 * @thread EMT 416 415 */ … … 420 419 uint32_t u32, 421 420 unsigned cb, 422 PFNGETHOSTMINIMALFEATURES pfnGetHostMinimalFeatures, 423 PFNGETHOSTFEATURES pfnGetHostFeatures, 424 PFNSETHOSTFEATURES pfnSetHostFeatures, 425 PFNRESET pfnReset, 426 PFNREADY pfnReady, 427 PFNSETCONFIG pfnSetConfig) 428 421 PCVPCIIOCALLBACKS pCallbacks) 429 422 { 430 423 VPCISTATE *pState = PDMINS_2_DATA(pDevIns, VPCISTATE *); … … 444 437 Log(("%s WARNING! Guest failed to negotiate properly (guest=%x)\n", 445 438 INSTANCE(pState), u32)); 446 pState->uGuestFeatures = p fnGetHostMinimalFeatures(pState);439 pState->uGuestFeatures = pCallbacks->pfnGetHostMinimalFeatures(pState); 447 440 } 448 441 /* The guest may potentially desire features we don't support! */ 449 else if (~vpciGetHostFeatures(pState, p fnGetHostFeatures) & u32)442 else if (~vpciGetHostFeatures(pState, pCallbacks->pfnGetHostFeatures) & u32) 450 443 { 451 444 Log(("%s Guest asked for features host does not support! (host=%x guest=%x)\n", 452 445 INSTANCE(pState), 453 vpciGetHostFeatures(pState, p fnGetHostFeatures), u32));446 vpciGetHostFeatures(pState, pCallbacks->pfnGetHostFeatures), u32)); 454 447 pState->uGuestFeatures = 455 vpciGetHostFeatures(pState, p fnGetHostFeatures);448 vpciGetHostFeatures(pState, pCallbacks->pfnGetHostFeatures); 456 449 } 457 450 else 458 451 pState->uGuestFeatures = u32; 459 p fnSetHostFeatures(pState, pState->uGuestFeatures);452 pCallbacks->pfnSetHostFeatures(pState, pState->uGuestFeatures); 460 453 break; 461 454 … … 471 464 vqueueInit(&pState->Queues[pState->uQueueSelector], u32); 472 465 else 473 rc = p fnReset(pState);466 rc = pCallbacks->pfnReset(pState); 474 467 break; 475 468 … … 514 507 /* Writing 0 to the status port triggers device reset. */ 515 508 if (u32 == 0) 516 rc = p fnReset(pState);509 rc = pCallbacks->pfnReset(pState); 517 510 else if (fHasBecomeReady) 518 p fnReady(pState);511 pCallbacks->pfnReady(pState); 519 512 break; 520 513 521 514 default: 522 515 if (Port >= VPCI_CONFIG) 523 rc = p fnSetConfig(pState, Port - VPCI_CONFIG, cb, &u32);516 rc = pCallbacks->pfnSetConfig(pState, Port - VPCI_CONFIG, cb, &u32); 524 517 else 525 518 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 221 221 typedef VPCISTATE *PVPCISTATE; 222 222 223 /** @name Callbacks 223 typedef DECLCALLBACK(uint32_t) FNGETHOSTFEATURES(void *pvState); 224 typedef FNGETHOSTFEATURES *PFNGETHOSTFEATURES; 225 226 /** @name VirtIO port I/O callbacks. 224 227 * @{ */ 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); 228 typedef 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. */ 239 typedef const VPCIIOCALLBACKS *PCVPCIIOCALLBACKS; 232 240 /** @} */ 233 241 … … 238 246 uint32_t *pu32, 239 247 unsigned cb, 240 PFNGETHOSTFEATURES pfnGetHostFeatures, 241 PFNGETCONFIG pfnGetConfig); 248 PCVPCIIOCALLBACKS pCallbacks); 242 249 243 250 int vpciIOPortOut(PPDMDEVINS pDevIns, … … 246 253 uint32_t u32, 247 254 unsigned cb, 248 PFNGETHOSTMINIMALFEATURES pfnGetHostMinimalFeatures, 249 PFNGETHOSTFEATURES pfnGetHostFeatures, 250 PFNSETHOSTFEATURES pfnSetHostFeatures, 251 PFNRESET pfnReset, 252 PFNREADY pfnReady, 253 PFNSETCONFIG pfnSetConfig); 255 PCVPCIIOCALLBACKS pCallbacks); 254 256 255 257 void vpciSetWriteLed(PVPCISTATE pState, bool fOn); 256 258 void vpciSetReadLed(PVPCISTATE pState, bool fOn); 257 259 int 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); 260 int vpciLoadExec(PVPCISTATE pState, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass, uint32_t nQueues); 261 int vpciConstruct(PPDMDEVINS pDevIns, VPCISTATE *pState, int iInstance, const char *pcszNameFmt, 262 uint16_t uSubsystemId, uint16_t uClass, uint32_t nQueues); 265 263 int vpciDestruct(VPCISTATE* pState); 266 264 void vpciRelocate(PPDMDEVINS pDevIns, RTGCINTPTR offDelta); 267 265 void vpciReset(PVPCISTATE pState); 268 266 void *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); 267 PVQUEUE vpciAddQueue(VPCISTATE* pState, unsigned uSize, PFNVPCIQUEUECALLBACK pfnCallback, const char *pcszName); 272 268 273 269 #define VPCI_CS 274 DECLINLINE(int) vpciCsEnter(VPCISTATE *pState, int iBusyRc)270 DECLINLINE(int) vpciCsEnter(VPCISTATE *pState, int rcBusy) 275 271 { 276 272 #ifdef VPCI_CS 277 273 STAM_PROFILE_START(&pState->CTXSUFF(StatCs), a); 278 int rc = PDMCritSectEnter(&pState->cs, iBusyRc);274 int rc = PDMCritSectEnter(&pState->cs, rcBusy); 279 275 STAM_PROFILE_STOP(&pState->CTXSUFF(StatCs), a); 280 276 return rc;
Note:
See TracChangeset
for help on using the changeset viewer.