- Timestamp:
- Aug 1, 2023 10:34:42 AM (17 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Misc/DevFlashCFI.cpp
r100762 r100765 323 323 324 324 325 /** 326 * Saves the flash content to NVRAM storage. 327 * 328 * @returns VBox status code. 329 * @param pDevIns The device instance. 330 */ 331 static int flashR3SaveToNvram(PPDMDEVINS pDevIns) 325 /* -=-=-=-=-=-=-=-=- Saved State -=-=-=-=-=-=-=-=- */ 326 327 /** 328 * @callback_method_impl{FNSSMDEVLIVEEXEC} 329 */ 330 static DECLCALLBACK(int) flashR3LiveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uPass) 331 { 332 PDEVFLASHCFI pThis = PDMDEVINS_2_DATA(pDevIns, PDEVFLASHCFI); 333 PCPDMDEVHLPR3 pHlp = pDevIns->pHlpR3; 334 RT_NOREF(uPass); 335 336 pHlp->pfnSSMPutGCPhys(pSSM, pThis->GCPhysFlashBase); 337 pHlp->pfnSSMPutU32( pSSM, pThis->cbFlashSize); 338 pHlp->pfnSSMPutU16( pSSM, pThis->u16FlashId); 339 pHlp->pfnSSMPutU16( pSSM, pThis->cbBlockSize); 340 return VINF_SSM_DONT_CALL_AGAIN; 341 } 342 343 344 /** 345 * @callback_method_impl{FNSSMDEVSAVEEXEC} 346 */ 347 static DECLCALLBACK(int) flashR3SaveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM) 348 { 349 PDEVFLASHCFI pThis = PDMDEVINS_2_DATA(pDevIns, PDEVFLASHCFI); 350 PCPDMDEVHLPR3 pHlp = pDevIns->pHlpR3; 351 352 /* The config. */ 353 flashR3LiveExec(pDevIns, pSSM, SSM_PASS_FINAL); 354 355 /* The state. */ 356 pHlp->pfnSSMPutU16(pSSM, pThis->u16Cmd); 357 pHlp->pfnSSMPutU8( pSSM, pThis->bStatus); 358 pHlp->pfnSSMPutU8( pSSM, pThis->cBusCycle); 359 pHlp->pfnSSMPutU8( pSSM, pThis->cWordsTransfered); 360 pHlp->pfnSSMPutMem(pSSM, pThis->pbFlash, pThis->cbFlashSize); 361 pHlp->pfnSSMPutU32(pSSM, pThis->offBlock); 362 pHlp->pfnSSMPutU32(pSSM, pThis->cbWrite); 363 pHlp->pfnSSMPutMem(pSSM, &pThis->abProgramBuf[0], sizeof(pThis->abProgramBuf)); 364 365 pThis->fStateSaved = true; 366 return pHlp->pfnSSMPutU32(pSSM, UINT32_MAX); /* sanity/terminator */ 367 } 368 369 370 /** 371 * @callback_method_impl{FNSSMDEVLOADEXEC} 372 */ 373 static DECLCALLBACK(int) flashR3LoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass) 374 { 375 PDEVFLASHCFI pThis = PDMDEVINS_2_DATA(pDevIns, PDEVFLASHCFI); 376 PCPDMDEVHLPR3 pHlp = pDevIns->pHlpR3; 377 378 /* Fend off unsupported versions. */ 379 if (uVersion != FLASH_SAVED_STATE_VERSION) 380 return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION; 381 382 /* The config. */ 383 RTGCPHYS GCPhysFlashBase; 384 int rc = pHlp->pfnSSMGetGCPhys(pSSM, &GCPhysFlashBase); 385 AssertRCReturn(rc, rc); 386 if (GCPhysFlashBase != pThis->GCPhysFlashBase) 387 return pHlp->pfnSSMSetCfgError(pSSM, RT_SRC_POS, N_("Config mismatch - GCPhysFlashBase: saved=%RGp config=%RGp"), 388 GCPhysFlashBase, pThis->GCPhysFlashBase); 389 390 uint32_t cbFlashSize; 391 rc = pHlp->pfnSSMGetU32(pSSM, &cbFlashSize); 392 AssertRCReturn(rc, rc); 393 if (cbFlashSize != pThis->cbFlashSize) 394 return pHlp->pfnSSMSetCfgError(pSSM, RT_SRC_POS, N_("Config mismatch - cbFlashSize: saved=%#x config=%#x"), 395 cbFlashSize, pThis->cbFlashSize); 396 397 uint16_t u16FlashId; 398 rc = pHlp->pfnSSMGetU16(pSSM, &u16FlashId); 399 AssertRCReturn(rc, rc); 400 if (u16FlashId != pThis->u16FlashId) 401 return pHlp->pfnSSMSetCfgError(pSSM, RT_SRC_POS, N_("Config mismatch - u16FlashId: saved=%#x config=%#x"), 402 u16FlashId, pThis->u16FlashId); 403 404 uint16_t cbBlockSize; 405 rc = pHlp->pfnSSMGetU16(pSSM, &cbBlockSize); 406 AssertRCReturn(rc, rc); 407 if (cbBlockSize != pThis->cbBlockSize) 408 return pHlp->pfnSSMSetCfgError(pSSM, RT_SRC_POS, N_("Config mismatch - cbBlockSize: saved=%#x config=%#x"), 409 cbBlockSize, pThis->cbBlockSize); 410 411 if (uPass != SSM_PASS_FINAL) 412 return VINF_SUCCESS; 413 414 /* The state. */ 415 pHlp->pfnSSMGetU16(pSSM, &pThis->u16Cmd); 416 pHlp->pfnSSMGetU8( pSSM, &pThis->bStatus); 417 pHlp->pfnSSMGetU8( pSSM, &pThis->cBusCycle); 418 pHlp->pfnSSMGetU8( pSSM, &pThis->cWordsTransfered); 419 pHlp->pfnSSMGetMem(pSSM, pThis->pbFlash, pThis->cbFlashSize); 420 pHlp->pfnSSMGetU32(pSSM, &pThis->offBlock); 421 pHlp->pfnSSMGetU32(pSSM, &pThis->cbWrite); 422 pHlp->pfnSSMGetMem(pSSM, &pThis->abProgramBuf[0], sizeof(pThis->abProgramBuf)); 423 424 /* The marker. */ 425 uint32_t u32; 426 rc = pHlp->pfnSSMGetU32(pSSM, &u32); 427 AssertRCReturn(rc, rc); 428 AssertMsgReturn(u32 == UINT32_MAX, ("%#x\n", u32), VERR_SSM_DATA_UNIT_FORMAT_CHANGED); 429 430 return VINF_SUCCESS; 431 } 432 433 434 /** 435 * @interface_method_impl{PDMDEVREG,pfnReset} 436 */ 437 static DECLCALLBACK(void) flashR3Reset(PPDMDEVINS pDevIns) 438 { 439 PDEVFLASHCFI pThis = PDMDEVINS_2_DATA(pDevIns, PDEVFLASHCFI); 440 441 /* 442 * Initialize the device state. 443 */ 444 pThis->u16Cmd = FLASH_CFI_CMD_ARRAY_READ; 445 pThis->bStatus = FLASH_CFI_SR_PROGRAM_ERASE; /* Prgram/Erase controller is inactive. */ 446 pThis->cBusCycle = 0; 447 } 448 449 450 /** 451 * @interface_method_impl{PDMDEVREG,pfnPowerOff} 452 */ 453 static DECLCALLBACK(void) flashR3PowerOff(PPDMDEVINS pDevIns) 332 454 { 333 455 PDEVFLASHCFI pThis = PDMDEVINS_2_DATA(pDevIns, PDEVFLASHCFI); … … 360 482 } 361 483 } 362 363 return rc;364 }365 366 367 /* -=-=-=-=-=-=-=-=- Saved State -=-=-=-=-=-=-=-=- */368 369 /**370 * @callback_method_impl{FNSSMDEVLIVEEXEC}371 */372 static DECLCALLBACK(int) flashR3LiveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uPass)373 {374 PDEVFLASHCFI pThis = PDMDEVINS_2_DATA(pDevIns, PDEVFLASHCFI);375 PCPDMDEVHLPR3 pHlp = pDevIns->pHlpR3;376 RT_NOREF(uPass);377 378 pHlp->pfnSSMPutGCPhys(pSSM, pThis->GCPhysFlashBase);379 pHlp->pfnSSMPutU32( pSSM, pThis->cbFlashSize);380 pHlp->pfnSSMPutU16( pSSM, pThis->u16FlashId);381 pHlp->pfnSSMPutU16( pSSM, pThis->cbBlockSize);382 return VINF_SSM_DONT_CALL_AGAIN;383 }384 385 386 /**387 * @callback_method_impl{FNSSMDEVSAVEEXEC}388 */389 static DECLCALLBACK(int) flashR3SaveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)390 {391 PDEVFLASHCFI pThis = PDMDEVINS_2_DATA(pDevIns, PDEVFLASHCFI);392 PCPDMDEVHLPR3 pHlp = pDevIns->pHlpR3;393 394 /* The config. */395 flashR3LiveExec(pDevIns, pSSM, SSM_PASS_FINAL);396 397 /* The state. */398 pHlp->pfnSSMPutU16(pSSM, pThis->u16Cmd);399 pHlp->pfnSSMPutU8( pSSM, pThis->bStatus);400 pHlp->pfnSSMPutU8( pSSM, pThis->cBusCycle);401 pHlp->pfnSSMPutU8( pSSM, pThis->cWordsTransfered);402 pHlp->pfnSSMPutMem(pSSM, pThis->pbFlash, pThis->cbFlashSize);403 pHlp->pfnSSMPutU32(pSSM, pThis->offBlock);404 pHlp->pfnSSMPutU32(pSSM, pThis->cbWrite);405 pHlp->pfnSSMPutMem(pSSM, &pThis->abProgramBuf[0], sizeof(pThis->abProgramBuf));406 407 pThis->fStateSaved = true;408 return pHlp->pfnSSMPutU32(pSSM, UINT32_MAX); /* sanity/terminator */409 }410 411 412 /**413 * @callback_method_impl{FNSSMDEVLOADEXEC}414 */415 static DECLCALLBACK(int) flashR3LoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)416 {417 PDEVFLASHCFI pThis = PDMDEVINS_2_DATA(pDevIns, PDEVFLASHCFI);418 PCPDMDEVHLPR3 pHlp = pDevIns->pHlpR3;419 420 /* Fend off unsupported versions. */421 if (uVersion != FLASH_SAVED_STATE_VERSION)422 return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;423 424 /* The config. */425 RTGCPHYS GCPhysFlashBase;426 int rc = pHlp->pfnSSMGetGCPhys(pSSM, &GCPhysFlashBase);427 AssertRCReturn(rc, rc);428 if (GCPhysFlashBase != pThis->GCPhysFlashBase)429 return pHlp->pfnSSMSetCfgError(pSSM, RT_SRC_POS, N_("Config mismatch - GCPhysFlashBase: saved=%RGp config=%RGp"),430 GCPhysFlashBase, pThis->GCPhysFlashBase);431 432 uint32_t cbFlashSize;433 rc = pHlp->pfnSSMGetU32(pSSM, &cbFlashSize);434 AssertRCReturn(rc, rc);435 if (cbFlashSize != pThis->cbFlashSize)436 return pHlp->pfnSSMSetCfgError(pSSM, RT_SRC_POS, N_("Config mismatch - cbFlashSize: saved=%#x config=%#x"),437 cbFlashSize, pThis->cbFlashSize);438 439 uint16_t u16FlashId;440 rc = pHlp->pfnSSMGetU16(pSSM, &u16FlashId);441 AssertRCReturn(rc, rc);442 if (u16FlashId != pThis->u16FlashId)443 return pHlp->pfnSSMSetCfgError(pSSM, RT_SRC_POS, N_("Config mismatch - u16FlashId: saved=%#x config=%#x"),444 u16FlashId, pThis->u16FlashId);445 446 uint16_t cbBlockSize;447 rc = pHlp->pfnSSMGetU16(pSSM, &cbBlockSize);448 AssertRCReturn(rc, rc);449 if (cbBlockSize != pThis->cbBlockSize)450 return pHlp->pfnSSMSetCfgError(pSSM, RT_SRC_POS, N_("Config mismatch - cbBlockSize: saved=%#x config=%#x"),451 cbBlockSize, pThis->cbBlockSize);452 453 if (uPass != SSM_PASS_FINAL)454 return VINF_SUCCESS;455 456 /* The state. */457 pHlp->pfnSSMGetU16(pSSM, &pThis->u16Cmd);458 pHlp->pfnSSMGetU8( pSSM, &pThis->bStatus);459 pHlp->pfnSSMGetU8( pSSM, &pThis->cBusCycle);460 pHlp->pfnSSMGetU8( pSSM, &pThis->cWordsTransfered);461 pHlp->pfnSSMGetMem(pSSM, pThis->pbFlash, pThis->cbFlashSize);462 pHlp->pfnSSMGetU32(pSSM, &pThis->offBlock);463 pHlp->pfnSSMGetU32(pSSM, &pThis->cbWrite);464 pHlp->pfnSSMGetMem(pSSM, &pThis->abProgramBuf[0], sizeof(pThis->abProgramBuf));465 466 /* The marker. */467 uint32_t u32;468 rc = pHlp->pfnSSMGetU32(pSSM, &u32);469 AssertRCReturn(rc, rc);470 AssertMsgReturn(u32 == UINT32_MAX, ("%#x\n", u32), VERR_SSM_DATA_UNIT_FORMAT_CHANGED);471 472 return VINF_SUCCESS;473 }474 475 476 /**477 * @interface_method_impl{PDMDEVREG,pfnReset}478 */479 static DECLCALLBACK(void) flashR3Reset(PPDMDEVINS pDevIns)480 {481 PDEVFLASHCFI pThis = PDMDEVINS_2_DATA(pDevIns, PDEVFLASHCFI);482 483 /*484 * Initialize the device state.485 */486 pThis->u16Cmd = FLASH_CFI_CMD_ARRAY_READ;487 pThis->bStatus = FLASH_CFI_SR_PROGRAM_ERASE; /* Prgram/Erase controller is inactive. */488 pThis->cBusCycle = 0;489 }490 491 492 /**493 * @interface_method_impl{PDMDEVREG,pfnPowerOff}494 */495 static DECLCALLBACK(void) flashR3PowerOff(PPDMDEVINS pDevIns)496 {497 int rc = flashR3SaveToNvram(pDevIns);498 AssertRC(rc);499 484 } 500 485 … … 507 492 PDMDEV_CHECK_VERSIONS_RETURN_QUIET(pDevIns); 508 493 PDEVFLASHCFI pThis = PDMDEVINS_2_DATA(pDevIns, PDEVFLASHCFI); 509 510 int rc = flashR3SaveToNvram(pDevIns);511 AssertRCReturn(rc, rc);512 494 513 495 if (pThis->pbFlash)
Note:
See TracChangeset
for help on using the changeset viewer.