Lines Matching defs:FtwDevice
54 @param FtwDevice The private data of FTW driver
65 IN EFI_FTW_DEVICE *FtwDevice,
82 @param FtwDevice The private data of FTW driver
98 IN EFI_FTW_DEVICE *FtwDevice
101 return FtwDevice->FtwBackupFvb->EraseBlocks (
102 FtwDevice->FtwBackupFvb,
103 FtwDevice->FtwSpareLba,
104 FtwDevice->NumberOfSpareBlock,
113 @param FtwDevice The private data of FTW driver
122 EFI_FTW_DEVICE *FtwDevice,
134 (FvBlock == FtwDevice->FtwFvBlock) &&
135 (Lba >= FtwDevice->FtwWorkBlockLba) &&
136 (Lba <= FtwDevice->FtwWorkSpaceLba)
217 @param FtwDevice The private data of FTW driver
225 EFI_FTW_DEVICE *FtwDevice,
301 @param FtwDevice The private data of FTW driver
311 EFI_FTW_DEVICE *FtwDevice
339 Length = FtwDevice->SpareAreaLength;
358 if (GetFvbByAddress (FtwDevice->SpareAreaAddress + FtwDevice->SpareAreaLength, &BootFvb) == NULL) {
367 for (Index = 0; Index < FtwDevice->NumberOfSpareBlock; Index += 1) {
368 Count = FtwDevice->SpareBlockSize;
388 for (Index = 0; Index < FtwDevice->NumberOfSpareBlock; Index += 1) {
389 Count = FtwDevice->SpareBlockSize;
390 Status = FtwDevice->FtwBackupFvb->Read (
391 FtwDevice->FtwBackupFvb,
392 FtwDevice->FtwSpareLba + Index,
417 Status = FtwEraseSpareBlock (FtwDevice);
426 for (Index = 0; Index < FtwDevice->NumberOfSpareBlock; Index += 1) {
427 Count = FtwDevice->SpareBlockSize;
428 Status = FtwDevice->FtwBackupFvb->Write (
429 FtwDevice->FtwBackupFvb,
430 FtwDevice->FtwSpareLba + Index,
460 @param FtwDevice The private data of FTW driver
474 EFI_FTW_DEVICE *FtwDevice,
488 if ((FtwDevice == NULL) || (FvBlock == NULL)) {
494 Length = FtwDevice->SpareAreaLength;
503 for (Index = 0; Index < FtwDevice->NumberOfSpareBlock; Index += 1) {
504 Count = FtwDevice->SpareBlockSize;
505 Status = FtwDevice->FtwBackupFvb->Read (
506 FtwDevice->FtwBackupFvb,
507 FtwDevice->FtwSpareLba + Index,
522 Status = FtwEraseBlock (FtwDevice, FvBlock, Lba, NumberOfBlocks);
551 FtwDevice->FtwSpareLba.
553 FtwDevice
559 @param FtwDevice The private data of FTW driver
568 EFI_FTW_DEVICE *FtwDevice
582 Length = FtwDevice->SpareAreaLength;
596 FtwDevice->FtwBackupFvb,
597 FtwDevice->SpareBlockSize,
598 FtwDevice->FtwSpareLba + FtwDevice->FtwWorkSpaceLbaInSpare,
599 FtwDevice->FtwWorkSpaceBaseInSpare + sizeof (EFI_GUID) + sizeof (UINT32),
606 for (Index = 0; Index < FtwDevice->NumberOfSpareBlock; Index += 1) {
607 Count = FtwDevice->SpareBlockSize;
608 Status = FtwDevice->FtwBackupFvb->Read (
609 FtwDevice->FtwBackupFvb,
610 FtwDevice->FtwSpareLba + Index,
625 WorkingBlockHeader = (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER *) (Buffer + (UINTN) FtwDevice->FtwWorkSpaceLbaInSpare * FtwDevice->SpareBlockSize + FtwDevice->FtwWorkSpaceBaseInSpare);
641 FtwDevice->FtwFvBlock,
642 FtwDevice->WorkBlockSize,
643 FtwDevice->FtwWorkSpaceLba,
644 FtwDevice->FtwWorkSpaceBase + sizeof (EFI_GUID) + sizeof (UINT32),
652 FtwDevice->FtwWorkSpaceHeader->WorkingBlockInvalid = FTW_VALID_STATE;
657 Status = FtwEraseBlock (FtwDevice, FtwDevice->FtwFvBlock, FtwDevice->FtwWorkBlockLba, FtwDevice->NumberOfWorkBlock);
666 for (Index = 0; Index < FtwDevice->NumberOfWorkBlock; Index += 1) {
667 Count = FtwDevice->WorkBlockSize;
668 Status = FtwDevice->FtwFvBlock->Write (
669 FtwDevice->FtwFvBlock,
670 FtwDevice->FtwWorkBlockLba + Index,
695 FtwDevice->FtwFvBlock,
696 FtwDevice->WorkBlockSize,
697 FtwDevice->FtwWorkSpaceLba,
698 FtwDevice->FtwWorkSpaceBase + sizeof (EFI_GUID) + sizeof (UINT32),
705 FtwDevice->FtwWorkSpaceHeader->WorkingBlockInvalid = FTW_INVALID_STATE;
706 FtwDevice->FtwWorkSpaceHeader->WorkingBlockValid = FTW_VALID_STATE;
976 EFI_FTW_DEVICE *FtwDevice;
982 FtwDevice = AllocateZeroPool (sizeof (EFI_FTW_DEVICE) + PcdGet32 (PcdFlashNvStorageFtwWorkingSize));
983 if (FtwDevice == NULL) {
990 FtwDevice->WorkSpaceLength = (UINTN) PcdGet32 (PcdFlashNvStorageFtwWorkingSize);
991 FtwDevice->SpareAreaLength = (UINTN) PcdGet32 (PcdFlashNvStorageFtwSpareSize);
992 if ((FtwDevice->WorkSpaceLength == 0) || (FtwDevice->SpareAreaLength == 0)) {
994 FreePool (FtwDevice);
998 FtwDevice->Signature = FTW_DEVICE_SIGNATURE;
999 FtwDevice->FtwFvBlock = NULL;
1000 FtwDevice->FtwBackupFvb = NULL;
1001 FtwDevice->FtwWorkSpaceLba = (EFI_LBA) (-1);
1002 FtwDevice->FtwSpareLba = (EFI_LBA) (-1);
1004 FtwDevice->WorkSpaceAddress = (EFI_PHYSICAL_ADDRESS) PcdGet64 (PcdFlashNvStorageFtwWorkingBase64);
1005 if (FtwDevice->WorkSpaceAddress == 0) {
1006 FtwDevice->WorkSpaceAddress = (EFI_PHYSICAL_ADDRESS) PcdGet32 (PcdFlashNvStorageFtwWorkingBase);
1009 FtwDevice->SpareAreaAddress = (EFI_PHYSICAL_ADDRESS) PcdGet64 (PcdFlashNvStorageFtwSpareBase64);
1010 if (FtwDevice->SpareAreaAddress == 0) {
1011 FtwDevice->SpareAreaAddress = (EFI_PHYSICAL_ADDRESS) PcdGet32 (PcdFlashNvStorageFtwSpareBase);
1014 *FtwData = FtwDevice;
1022 @param[in, out] FtwDevice Pointer to the FTW device structure
1031 IN OUT EFI_FTW_DEVICE *FtwDevice
1089 if ((FtwDevice->FtwFvBlock == NULL) && (FtwDevice->WorkSpaceAddress >= FvbBaseAddress) &&
1090 ((FtwDevice->WorkSpaceAddress + FtwDevice->WorkSpaceLength) <= (FvbBaseAddress + BlockSize * NumberOfBlocks))) {
1091 FtwDevice->FtwFvBlock = Fvb;
1096 if ((FtwDevice->WorkSpaceAddress >= (FvbBaseAddress + BlockSize * (LbaIndex - 1)))
1097 && (FtwDevice->WorkSpaceAddress < (FvbBaseAddress + BlockSize * LbaIndex))) {
1098 FtwDevice->FtwWorkSpaceLba = LbaIndex - 1;
1102 FtwDevice->FtwWorkSpaceSize = FtwDevice->WorkSpaceLength;
1103 FtwDevice->WorkBlockSize = BlockSize;
1104 FtwDevice->FtwWorkSpaceBase = (UINTN) (FtwDevice->WorkSpaceAddress - (FvbBaseAddress + FtwDevice->WorkBlockSize * (LbaIndex - 1)));
1105 FtwDevice->NumberOfWorkSpaceBlock = FTW_BLOCKS (FtwDevice->FtwWorkSpaceBase + FtwDevice->FtwWorkSpaceSize, FtwDevice->WorkBlockSize);
1106 if (FtwDevice->FtwWorkSpaceSize >= FtwDevice->WorkBlockSize) {
1110 if (((FtwDevice->WorkSpaceAddress & (FtwDevice->WorkBlockSize - 1)) != 0) ||
1111 ((FtwDevice->WorkSpaceLength & (FtwDevice->WorkBlockSize - 1)) != 0)) {
1117 } else if ((FtwDevice->FtwWorkSpaceBase + FtwDevice->FtwWorkSpaceSize) > FtwDevice->WorkBlockSize) {
1128 if ((FtwDevice->FtwBackupFvb == NULL) && (FtwDevice->SpareAreaAddress >= FvbBaseAddress) &&
1129 ((FtwDevice->SpareAreaAddress + FtwDevice->SpareAreaLength) <= (FvbBaseAddress + BlockSize * NumberOfBlocks))) {
1130 FtwDevice->FtwBackupFvb = Fvb;
1135 if ((FtwDevice->SpareAreaAddress >= (FvbBaseAddress + BlockSize * (LbaIndex - 1)))
1136 && (FtwDevice->SpareAreaAddress < (FvbBaseAddress + BlockSize * LbaIndex))) {
1140 FtwDevice->FtwSpareLba = LbaIndex - 1;
1141 FtwDevice->SpareBlockSize = BlockSize;
1142 FtwDevice->NumberOfSpareBlock = FtwDevice->SpareAreaLength / FtwDevice->SpareBlockSize;
1146 if ((FtwDevice->FtwSpareLba + FtwDevice->NumberOfSpareBlock) > NumberOfBlocks) {
1155 if (((FtwDevice->SpareAreaAddress & (FtwDevice->SpareBlockSize - 1)) != 0) ||
1156 ((FtwDevice->SpareAreaLength & (FtwDevice->SpareBlockSize - 1)) != 0)) {
1173 if ((FtwDevice->FtwBackupFvb == NULL) || (FtwDevice->FtwFvBlock == NULL) ||
1174 (FtwDevice->FtwWorkSpaceLba == (EFI_LBA) (-1)) || (FtwDevice->FtwSpareLba == (EFI_LBA) (-1))) {
1177 DEBUG ((EFI_D_INFO, "Ftw: FtwWorkSpaceLba - 0x%lx, WorkBlockSize - 0x%x, FtwWorkSpaceBase - 0x%x\n", FtwDevice->FtwWorkSpaceLba, FtwDevice->WorkBlockSize, FtwDevice->FtwWorkSpaceBase));
1178 DEBUG ((EFI_D_INFO, "Ftw: FtwSpareLba - 0x%lx, SpareBlockSize - 0x%x\n", FtwDevice->FtwSpareLba, FtwDevice->SpareBlockSize));
1187 @param[in, out] FtwDevice Pointer to the FTW device structure
1195 IN OUT EFI_FTW_DEVICE *FtwDevice
1208 Status = FindFvbForFtw (FtwDevice);
1216 if (FtwDevice->FtwWorkSpaceSize >= FtwDevice->WorkBlockSize) {
1220 FtwDevice->NumberOfWorkBlock = FtwDevice->NumberOfWorkSpaceBlock;
1228 FtwDevice->NumberOfWorkBlock = (UINTN) (FtwDevice->FtwWorkSpaceLba + FtwDevice->NumberOfWorkSpaceBlock);
1229 while (FtwDevice->NumberOfWorkBlock * FtwDevice->WorkBlockSize > FtwDevice->SpareAreaLength) {
1230 FtwDevice->NumberOfWorkBlock--;
1233 FtwDevice->FtwWorkBlockLba = FtwDevice->FtwWorkSpaceLba + FtwDevice->NumberOfWorkSpaceBlock - FtwDevice->NumberOfWorkBlock;
1234 DEBUG ((EFI_D_INFO, "Ftw: NumberOfWorkBlock - 0x%x, FtwWorkBlockLba - 0x%lx\n", FtwDevice->NumberOfWorkBlock, FtwDevice->FtwWorkBlockLba));
1240 WorkSpaceLbaOffset = FtwDevice->FtwWorkSpaceLba - FtwDevice->FtwWorkBlockLba;
1241 FtwDevice->FtwWorkSpaceLbaInSpare = (EFI_LBA) (((UINTN) WorkSpaceLbaOffset * FtwDevice->WorkBlockSize + FtwDevice->FtwWorkSpaceBase) / FtwDevice->SpareBlockSize);
1242 FtwDevice->FtwWorkSpaceBaseInSpare = ((UINTN) WorkSpaceLbaOffset * FtwDevice->WorkBlockSize + FtwDevice->FtwWorkSpaceBase) % FtwDevice->SpareBlockSize;
1243 DEBUG ((EFI_D_INFO, "Ftw: WorkSpaceLbaInSpare - 0x%lx, WorkSpaceBaseInSpare - 0x%x\n", FtwDevice->FtwWorkSpaceLbaInSpare, FtwDevice->FtwWorkSpaceBaseInSpare));
1248 FtwDevice->FtwWorkSpace = (UINT8 *) (FtwDevice + 1);
1249 FtwDevice->FtwWorkSpaceHeader = (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER *) FtwDevice->FtwWorkSpace;
1251 FtwDevice->FtwLastWriteHeader = NULL;
1252 FtwDevice->FtwLastWriteRecord = NULL;
1259 Status = WorkSpaceRefresh (FtwDevice);
1264 if (!IsValidWorkSpace (FtwDevice->FtwWorkSpaceHeader)) {
1269 FtwDevice->FtwBackupFvb,
1270 FtwDevice->SpareBlockSize,
1271 FtwDevice->FtwSpareLba + FtwDevice->FtwWorkSpaceLbaInSpare,
1272 FtwDevice->FtwWorkSpaceBaseInSpare,
1273 FtwDevice->FtwWorkSpaceSize,
1274 FtwDevice->FtwWorkSpace
1281 if (IsValidWorkSpace (FtwDevice->FtwWorkSpaceHeader)) {
1282 Status = FlushSpareBlockToWorkingBlock (FtwDevice);
1285 FtwAbort (&FtwDevice->FtwInstance);
1289 Status = WorkSpaceRefresh (FtwDevice);
1298 FtwDevice->FtwWorkSpace,
1299 FtwDevice->FtwWorkSpaceSize,
1302 InitWorkSpaceHeader (FtwDevice->FtwWorkSpaceHeader);
1306 Status = FtwReclaimWorkSpace (FtwDevice, FALSE);
1311 // If the FtwDevice->FtwLastWriteRecord is 1st record of write header &&
1314 if ((FtwDevice->FtwLastWriteHeader->HeaderAllocated == FTW_VALID_STATE) &&
1315 (FtwDevice->FtwLastWriteRecord->SpareComplete != FTW_VALID_STATE) &&
1316 IsFirstRecordOfWrites (FtwDevice->FtwLastWriteHeader, FtwDevice->FtwLastWriteRecord)
1319 FtwAbort (&FtwDevice->FtwInstance);
1325 if ((FtwDevice->FtwLastWriteHeader->Complete != FTW_VALID_STATE) &&
1326 (FtwDevice->FtwLastWriteRecord->DestinationComplete == FTW_VALID_STATE) &&
1327 IsLastRecordOfWrites (FtwDevice->FtwLastWriteHeader, FtwDevice->FtwLastWriteRecord)
1330 FtwAbort (&FtwDevice->FtwInstance);
1336 FtwHeader = FtwDevice->FtwLastWriteHeader;
1337 Offset = (UINT8 *) FtwHeader - FtwDevice->FtwWorkSpace;
1338 if (FtwDevice->FtwWorkSpace[Offset] != FTW_ERASED_BYTE) {
1342 if (!IsErasedFlashBuffer (FtwDevice->FtwWorkSpace + Offset, FtwDevice->FtwWorkSpaceSize - Offset)) {
1343 Status = FtwReclaimWorkSpace (FtwDevice, TRUE);
1350 if ((FtwDevice->FtwLastWriteHeader->Complete != FTW_VALID_STATE) &&
1351 (FtwDevice->FtwLastWriteRecord->SpareComplete == FTW_VALID_STATE)
1353 if (FtwDevice->FtwLastWriteRecord->BootBlockUpdate == FTW_VALID_STATE) {
1354 Status = FlushSpareBlockToBootBlock (FtwDevice);
1357 FtwAbort (&FtwDevice->FtwInstance);
1363 FvbHandle = GetFvbByAddress ((EFI_PHYSICAL_ADDRESS) (UINTN) ((INT64) FtwDevice->SpareAreaAddress + FtwDevice->FtwLastWriteRecord->RelativeOffset), &Fvb);
1365 Status = FtwRestart (&FtwDevice->FtwInstance, FvbHandle);
1369 FtwAbort (&FtwDevice->FtwInstance);
1375 FtwDevice->FtwInstance.GetMaxBlockSize = FtwGetMaxBlockSize;
1376 FtwDevice->FtwInstance.Allocate = FtwAllocate;
1377 FtwDevice->FtwInstance.Write = FtwWrite;
1378 FtwDevice->FtwInstance.Restart = FtwRestart;
1379 FtwDevice->FtwInstance.Abort = FtwAbort;
1380 FtwDevice->FtwInstance.GetLastWrite = FtwGetLastWrite;