46 IN UINT32 FastReadInstruction,
47 IN UINT32 FastReadModeClk,
48 IN UINT32 FastReadDummyClk
54 if (CapabilityEntry ==
NULL) {
55 DEBUG ((DEBUG_ERROR,
"%a: Failed to create fast read table\n", __func__));
62 CapabilityEntry->
ModeClocks = (UINT8)FastReadModeClk;
63 CapabilityEntry->
WaitStates = (UINT8)FastReadDummyClk;
65 DEBUG ((DEBUG_VERBOSE,
"%a: Create and link table.\n", __func__));
66 DEBUG ((DEBUG_VERBOSE,
" Instruction : 0x%x\n", FastReadInstruction));
67 DEBUG ((DEBUG_VERBOSE,
" Mode bits : 0x%x\n", FastReadModeClk));
68 DEBUG ((DEBUG_VERBOSE,
" Wait States (Dummy Clocks): 0x%x\n", FastReadDummyClk));
89 IN UINT32 SfdpEraseTypicalTime,
90 IN UINT32 SfdpEraseTimeMultiplier,
91 OUT UINT32 *EraseTypicalTime,
92 OUT UINT64 *EraseTimeout
97 UnitInMs = (SfdpEraseTypicalTime & ERASE_TYPICAL_TIME_UNITS_MASK) >> ERASE_TYPICAL_TIME_BIT_POSITION;
99 case ERASE_TYPICAL_TIME_UNIT_1_MS_BITMAP:
100 UnitInMs = ERASE_TYPICAL_TIME_UNIT_1_MS;
103 case ERASE_TYPICAL_TIME_UNIT_16_MS_BITMAP:
104 UnitInMs = ERASE_TYPICAL_TIME_UNIT_16_MS;
107 case ERASE_TYPICAL_TIME_UNIT_128_MS_BITMAP:
108 UnitInMs = ERASE_TYPICAL_TIME_UNIT_128_MS;
111 case ERASE_TYPICAL_TIME_UNIT_1000_MS_BITMAP:
112 UnitInMs = ERASE_TYPICAL_TIME_UNIT_1000_MS;
115 DEBUG ((DEBUG_ERROR,
"%a: Unsupported Erase Typical time.\n", __func__));
119 *EraseTypicalTime = UnitInMs * ((SfdpEraseTypicalTime & ERASE_TYPICAL_TIME_COUNT_MASK) + 1);
120 *EraseTimeout = 2 * (SfdpEraseTimeMultiplier + 1) * *EraseTypicalTime;
134 DEBUG ((DEBUG_VERBOSE,
" Erase Type %d\n", SupportedEraseType->EraseType));
135 DEBUG ((DEBUG_VERBOSE,
" Erase Type instruction: 0x%x\n", SupportedEraseType->EraseInstruction));
136 DEBUG ((DEBUG_VERBOSE,
" Erase size: 0x%x bytes\n", SupportedEraseType->EraseSizeInByte));
137 DEBUG ((DEBUG_VERBOSE,
" Erase time: %d Milliseconds\n", SupportedEraseType->EraseTypicalTime));
138 DEBUG ((DEBUG_VERBOSE,
" Erase timeout: %d Milliseconds:\n", SupportedEraseType->EraseTimeout));
156 InsertTailList (&Instance->SupportedEraseTypes, &SupportedEraseType->NextEraseType);
158 DEBUG ((DEBUG_VERBOSE,
"%a: Erase Type 0x%x is supported:\n", __func__, SupportedEraseType->EraseType));
178 if (Instance->SfdpBasicFlash->Erase1Size != 0) {
180 if (SupportedEraseType !=
NULL) {
181 SupportedEraseType->
EraseType = SFDP_ERASE_TYPE_1;
182 SupportedEraseType->
EraseInstruction = (UINT8)Instance->SfdpBasicFlash->Erase1Instr;
183 SupportedEraseType->
EraseSizeInByte = (UINT32)1 << Instance->SfdpBasicFlash->Erase1Size;
185 Instance->SfdpBasicFlash->Erase1Time,
186 Instance->SfdpBasicFlash->EraseMultiplier,
192 DEBUG ((DEBUG_ERROR,
"%a: Memory allocated failed for SFDP_SUPPORTED_ERASE_TYPE_RECORD (Type 1).\n", __func__));
198 if (Instance->SfdpBasicFlash->Erase2Size != 0) {
200 if (SupportedEraseType !=
NULL) {
201 SupportedEraseType->
EraseType = SFDP_ERASE_TYPE_2;
202 SupportedEraseType->
EraseInstruction = (UINT8)Instance->SfdpBasicFlash->Erase2Instr;
203 SupportedEraseType->
EraseSizeInByte = (UINT32)1 << Instance->SfdpBasicFlash->Erase2Size;
205 Instance->SfdpBasicFlash->Erase2Time,
206 Instance->SfdpBasicFlash->EraseMultiplier,
212 DEBUG ((DEBUG_ERROR,
"%a: Memory allocated failed for SFDP_SUPPORTED_ERASE_TYPE_RECORD (Type 2).\n", __func__));
218 if (Instance->SfdpBasicFlash->Erase3Size != 0) {
220 if (SupportedEraseType !=
NULL) {
221 SupportedEraseType->
EraseType = SFDP_ERASE_TYPE_3;
222 SupportedEraseType->
EraseInstruction = (UINT8)Instance->SfdpBasicFlash->Erase3Instr;
223 SupportedEraseType->
EraseSizeInByte = (UINT32)1 << Instance->SfdpBasicFlash->Erase3Size;
225 Instance->SfdpBasicFlash->Erase3Time,
226 Instance->SfdpBasicFlash->EraseMultiplier,
232 DEBUG ((DEBUG_ERROR,
"%a: Memory allocated failed for SFDP_SUPPORTED_ERASE_TYPE_RECORD (Type 3).\n", __func__));
238 if (Instance->SfdpBasicFlash->Erase4Size != 0) {
240 if (SupportedEraseType !=
NULL) {
241 SupportedEraseType->
EraseType = SFDP_ERASE_TYPE_4;
242 SupportedEraseType->
EraseInstruction = (UINT8)Instance->SfdpBasicFlash->Erase4Instr;
243 SupportedEraseType->
EraseSizeInByte = (UINT32)1 << Instance->SfdpBasicFlash->Erase4Size;
245 Instance->SfdpBasicFlash->Erase4Time,
246 Instance->SfdpBasicFlash->EraseMultiplier,
252 DEBUG ((DEBUG_ERROR,
"%a: Memory allocated failed for SFDP_SUPPORTED_ERASE_TYPE_RECORD (Type 4).\n", __func__));
273 IN UINT8 TargetTypeNum,
274 IN UINT8 *TargetTypes
279 for (Index = 0; Index < TargetTypeNum; Index++) {
280 if (EraseType == *(TargetTypes + Index)) {
316 IN SFDP_SEARCH_ERASE_TYPE SearchType,
317 IN UINT32 SearchValue,
318 IN UINT8 SupportedTypeTargetNum,
319 IN UINT8 *SupportedTypeTarget OPTIONAL,
324 UINT32 ValueToCompare;
325 BOOLEAN ExitSearching;
327 if (
IsListEmpty (&Instance->SupportedEraseTypes)) {
328 return EFI_NOT_FOUND;
331 *EraseTypeRecord =
NULL;
336 switch (SearchType) {
337 case SearchEraseTypeByType:
338 case SearchEraseTypeByCommand:
339 case SearchEraseTypeBySize:
341 case SearchEraseTypeBySmallestSize:
342 ValueToCompare = (UINT32)-1;
344 case SearchEraseTypeByBiggestSize:
348 return EFI_INVALID_PARAMETER;
351 ExitSearching =
FALSE;
355 switch (SearchType) {
356 case SearchEraseTypeByType:
357 if (EraseType->
EraseType == SearchValue) {
358 *EraseTypeRecord = EraseType;
359 ExitSearching =
TRUE;
364 case SearchEraseTypeBySize:
366 *EraseTypeRecord = EraseType;
367 ExitSearching =
TRUE;
372 case SearchEraseTypeByCommand:
374 *EraseTypeRecord = EraseType;
375 ExitSearching =
TRUE;
380 case SearchEraseTypeBySmallestSize:
383 *EraseTypeRecord = EraseType;
388 case SearchEraseTypeByBiggestSize:
391 *EraseTypeRecord = EraseType;
397 return EFI_INVALID_PARAMETER;
408 if (*EraseTypeRecord ==
NULL) {
409 return EFI_NOT_FOUND;
442 IN UINT32 FlashAddress,
443 IN UINT32 RemainingSize,
444 IN OUT UINT32 *BlockSizeToErase,
445 IN OUT UINT32 *BlockCountToErase,
446 OUT UINT8 *BlockEraseCommand,
447 OUT UINT32 *TypicalTime,
448 OUT UINT64 *MaximumTimeout
455 DEBUG ((DEBUG_VERBOSE,
"%a: Entry\n", __func__));
457 for (EraseSize = SIZE_2GB; EraseSize != 0; EraseSize = EraseSize >> 1) {
459 if (!EFI_ERROR (Status)) {
465 *BlockCountToErase = 1;
475 if (EraseType ==
NULL) {
476 return EFI_DEVICE_ERROR;
479 DEBUG ((DEBUG_VERBOSE,
" Erase address at 0x%08x.\n", FlashAddress));
480 DEBUG ((DEBUG_VERBOSE,
" - Erase block size : 0x%08x.\n", *BlockSizeToErase));
481 DEBUG ((DEBUG_VERBOSE,
" - Erase block count : 0x%08x.\n", *BlockCountToErase));
482 DEBUG ((DEBUG_VERBOSE,
" - Erase block command: 0x%02x.\n", *BlockEraseCommand));
483 DEBUG ((DEBUG_VERBOSE,
" - Remaining size to erase: 0x%08x.\n", RemainingSize));
484 DEBUG ((DEBUG_VERBOSE,
" - Erase typical time: %d milliseconds.\n", *TypicalTime));
485 DEBUG ((DEBUG_VERBOSE,
" - Erase timeout: %d milliseconds.\n", *MaximumTimeout));
505 IN UINT32 FlashAddress,
512 DEBUG ((DEBUG_VERBOSE,
"%a: Entry\n", __func__));
514 SectorMapRecord = Instance->CurrentSectorMap;
515 if (SectorMapRecord ==
NULL) {
516 return EFI_DEVICE_ERROR;
524 *FlashRegion = RegionRecord;
535 return EFI_INVALID_PARAMETER;
565 SPI_FLASH_FAST_READ_DUMMY * 8
569 if (Instance->SfdpBasicFlash->FastRead114 != 0) {
572 Instance->SfdpBasicFlash->FastRead114Instr,
573 Instance->SfdpBasicFlash->FastRead114ModeClk,
574 Instance->SfdpBasicFlash->FastRead114Dummy
579 if (Instance->SfdpBasicFlash->FastRead122 != 0) {
582 Instance->SfdpBasicFlash->FastRead122Instr,
583 Instance->SfdpBasicFlash->FastRead122ModeClk,
584 Instance->SfdpBasicFlash->FastRead122Dummy
589 if (Instance->SfdpBasicFlash->FastRead222 != 0) {
592 Instance->SfdpBasicFlash->FastRead222Instr,
593 Instance->SfdpBasicFlash->FastRead222ModeClk,
594 Instance->SfdpBasicFlash->FastRead222Dummy
599 if (Instance->SfdpBasicFlash->FastRead144 != 0) {
602 Instance->SfdpBasicFlash->FastRead144Instr,
603 Instance->SfdpBasicFlash->FastRead144ModeClk,
604 Instance->SfdpBasicFlash->FastRead144Dummy
609 if (Instance->SfdpBasicFlash->FastRead444 != 0) {
612 Instance->SfdpBasicFlash->FastRead444Instr,
613 Instance->SfdpBasicFlash->FastRead444ModeClk,
614 Instance->SfdpBasicFlash->FastRead444Dummy
619 if (Instance->SfdpBasicFlash->FastRead118Instr != 0) {
622 Instance->SfdpBasicFlash->FastRead118Instr,
623 Instance->SfdpBasicFlash->FastRead118ModeClk,
624 Instance->SfdpBasicFlash->FastRead118Dummy
629 if (Instance->SfdpBasicFlash->FastRead188Instr != 0) {
632 Instance->SfdpBasicFlash->FastRead188Instr,
633 Instance->SfdpBasicFlash->FastRead188ModeClk,
634 Instance->SfdpBasicFlash->FastRead188Dummy
659 UINT32 MinimumEraseSize;
661 if (
IsListEmpty (&Instance->SupportedEraseTypes)) {
662 DEBUG ((DEBUG_ERROR,
"%a: No erase type suppoted on the flash device.\n", __func__));
664 return EFI_DEVICE_ERROR;
667 MinimumEraseSize = (UINT32)-1;
670 RegionRecord->SupportedEraseType[RegionRecord->SupportedEraseTypeNum] = (UINT8)SupportedEraseType->
EraseType;
671 RegionRecord->SupportedEraseTypeNum++;
672 RegionRecord->EraseTypeBySizeBitmap |= SupportedEraseType->
EraseSizeInByte;
684 RegionRecord->SectorSize = MinimumEraseSize;
685 RegionRecord->RegionTotalSize = Instance->FlashDeviceSize;
686 RegionRecord->RegionSectors = RegionRecord->RegionTotalSize / RegionRecord->SectorSize;
709 DEBUG ((DEBUG_VERBOSE,
"%a: Entry:\n", __func__));
711 if (SectorMapRecord ==
NULL) {
712 DEBUG ((DEBUG_ERROR,
"%a: No memory resource for SFDP_SECTOR_MAP_DETECTION_RECORD.\n", __func__));
714 return EFI_OUT_OF_RESOURCES;
723 DEBUG ((DEBUG_VERBOSE,
" Sector map configurations ID : 0x%x\n", SectorMapRecord->
ConfigurationId));
724 DEBUG ((DEBUG_VERBOSE,
" Sector map configurations regions: %d\n", SectorMapRecord->
RegionCount));
728 if (RegionRecord ==
NULL) {
729 DEBUG ((DEBUG_ERROR,
"%a: No memory resource for SFDP_SECTOR_REGION_RECORD.\n", __func__));
731 return EFI_OUT_OF_RESOURCES;
744 Instance->CurrentSectorMap = SectorMapRecord;
747 DEBUG ((DEBUG_VERBOSE,
" Region sector size : 0x%x\n", RegionRecord->
SectorSize));
777 if (!EFI_ERROR (Status)) {
802 UINT32 TransactionBufferLength;
807 UINT8 ConfigurationId;
811 Instance->CurrentSectorMap =
NULL;
812 if (!Instance->ConfigurationCommandsNeeded) {
831 AddressLength = SPI_ADDR_4BYTE_ONLY;
836 if (CommandEntry->
CommandAddress == SpdfConfigurationCommandAddressNone) {
850 Status = Instance->SpiIo->Transaction (
857 TransactionBufferLength,
858 Instance->SpiTransactionWriteBuffer,
863 if (EFI_ERROR (Status)) {
864 DEBUG ((DEBUG_ERROR,
"%a: Fails to read the configuration byte.\n", __func__));
866 return EFI_DEVICE_ERROR;
873 ConfigurationId |= 0x01;
881 ConfigurationId = ConfigurationId << 1;
892 Instance->CurrentSectorMap = SectorMap;
903 if (Instance->CurrentSectorMap ==
NULL) {
904 DEBUG ((DEBUG_ERROR,
"%a: Activated flash sector map is not found!\n", __func__));
906 return EFI_DEVICE_ERROR;
940 UINT8 EraseTypeCount;
941 UINT32 MinimumEraseSize;
942 UINT32 RegionAddress;
944 SfdpSectorMapTable = Instance->SfdpFlashSectorMap;
948 if (SfdpSectorMapTable->GenericHeader.
DescriptorType == SFDP_SECTOR_MAP_TABLE_ENTRY_TYPE_MAP) {
950 Instance->ConfigurationCommandsNeeded =
FALSE;
952 DEBUG ((DEBUG_VERBOSE,
"%a: Sector map configuration detection command is needed\n", __func__));
953 Instance->ConfigurationCommandsNeeded =
TRUE;
958 if (CommandEntry ==
NULL) {
959 DEBUG ((DEBUG_ERROR,
"%a: No memory resource for SFDP_SECTOR_MAP_DETECTION_RECORD.\n", __func__));
961 return EFI_OUT_OF_RESOURCES;
976 if (SfdpDetectionCommand->
DescriptorEnd == SFDP_SECTOR_MAP_TABLE_ENTRY_LAST) {
980 SfdpDetectionCommand++;
989 if (SfdpConfigurationMap->
DescriptorType != SFDP_SECTOR_MAP_TABLE_ENTRY_TYPE_MAP) {
990 DEBUG ((DEBUG_ERROR,
"%a: Incorrect format of Sector Map Parameter.\n", __func__));
992 return EFI_DEVICE_ERROR;
996 DEBUG ((DEBUG_VERBOSE,
"%a: Sector map configurations:\n", __func__));
998 if (SectorMapRecord ==
NULL) {
999 DEBUG ((DEBUG_ERROR,
"%a: No memory resource for SFDP_SECTOR_MAP_DETECTION_RECORD.\n", __func__));
1001 return EFI_OUT_OF_RESOURCES;
1009 DEBUG ((DEBUG_VERBOSE,
" Sector map configurations ID : 0x%x\n", SectorMapRecord->
ConfigurationId));
1010 DEBUG ((DEBUG_VERBOSE,
" Sector map configurations regions: %d\n", SectorMapRecord->
RegionCount));
1013 for (RegionCount = 0; RegionCount < SectorMapRecord->
RegionCount; RegionCount++) {
1015 if (RegionRecord ==
NULL) {
1016 DEBUG ((DEBUG_ERROR,
"%a: No memory resource for SFDP_SECTOR_MAP_DETECTION_RECORD.\n", __func__));
1018 return EFI_OUT_OF_RESOURCES;
1049 if (
IsListEmpty (&Instance->SupportedEraseTypes)) {
1050 DEBUG ((DEBUG_ERROR,
"%a: No erase type suppoted on the flash device.\n", __func__));
1052 return EFI_DEVICE_ERROR;
1055 MinimumEraseSize = (UINT32)-1;
1056 for (EraseTypeCount = 0; EraseTypeCount < RegionRecord->
SupportedEraseTypeNum++; EraseTypeCount++) {
1087 DEBUG ((DEBUG_VERBOSE,
" Region: %d\n", RegionCount));
1089 DEBUG ((DEBUG_VERBOSE,
" Region sector size: 0x%x\n", RegionRecord->
SectorSize));
1097 if (SfdpConfigurationMap->
DescriptorEnd == SFDP_SECTOR_MAP_TABLE_ENTRY_LAST) {
1123 Instance->WriteEnableLatchRequired =
TRUE;
1125 if (Instance->SfdpBasicFlash->VolatileStatusBlockProtect == 1) {
1126 if (Instance->SfdpBasicFlash->WriteEnableVolatileStatus == 0) {
1127 Instance->WriteEnableLatchCommand = SPI_FLASH_WREN_50H;
1131 DEBUG ((DEBUG_ERROR,
"%a: Use Write Enable Command 0x%x.\n", __func__, Instance->WriteEnableLatchCommand));
1152 IN OUT UINT8 *FastReadInstruction,
1153 IN OUT UINT8 *FastReadModeBits,
1154 IN OUT UINT8 *FastReadDummyClocks
1160 return EFI_NOT_FOUND;
1165 *FastReadDummyClocks = FastReadEntry->
WaitStates;
1166 *FastReadModeBits = FastReadEntry->
ModeClocks;
1190 if (Instance ==
NULL) {
1194 if ((Instance->SfdpBasicFlash->Density & SFDP_FLASH_MEMORY_DENSITY_4GBIT) == 0) {
1198 return (Instance->SfdpBasicFlash->Density + 1) / 8;
1206 if ((Instance->SfdpBasicFlash->Density & ~SFDP_FLASH_MEMORY_DENSITY_4GBIT) < 32) {
1210 return (UINT32)
RShiftU64 (
LShiftU64 (1, Instance->SfdpBasicFlash->Density & ~SFDP_FLASH_MEMORY_DENSITY_4GBIT), 3);
1233 UINT32 TransactionBufferLength;
1242 SPI_FLASH_RDSFDP_DUMMY,
1243 SPI_FLASH_RDSFDP_ADDR_BYTES,
1249 Status = Instance->SpiIo->Transaction (
1256 TransactionBufferLength,
1257 Instance->SpiTransactionWriteBuffer,
1259 (UINT8 *)&Instance->SfdpHeader
1262 if (!EFI_ERROR (Status)) {
1264 if ((Instance->SfdpHeader.Signature != SFDP_HEADER_SIGNATURE) ||
1265 (Instance->SfdpHeader.MajorRev != SFDP_SUPPORTED_MAJOR_REVISION))
1267 Status = EFI_DEVICE_ERROR;
1269 DEBUG ((DEBUG_VERBOSE,
"Total %d parameter headers\n", Instance->SfdpHeader.NumParameterHeaders + 1));
1301 DEBUG ((DEBUG_VERBOSE,
"%a: Entry\n", __func__));
1304 if (EFI_ERROR (Status)) {
1305 DEBUG ((DEBUG_ERROR,
"%a: Failed to read SFDP header\n", __func__));
1311 if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) {
1312 DEBUG ((DEBUG_ERROR,
"%a: Failed to read SFDP Basic Parameter Table\n", __func__));
1318 DEBUG ((DEBUG_VERBOSE,
"%a: Flash Size=0x%X\n", __func__, Instance->FlashDeviceSize));
1319 if (Instance->FlashDeviceSize == 0) {
1325 if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) {
1326 DEBUG ((DEBUG_ERROR,
"%a: Failed to read SFDP Sector Map Parameter Table\n", __func__));
1328 }
else if (Status == EFI_NOT_FOUND) {
1329 DEBUG ((DEBUG_VERBOSE,
"%a: The SPI NOR flash device doesn't have SFDP Sector Map Parameter Table implemented:\n", __func__));
1335 Instance->Uniform4KEraseSupported =
FALSE;
1336 if (Instance->SfdpBasicFlash->EraseSizes == SPI_UNIFORM_4K_ERASE_SUPPORTED) {
1337 DEBUG ((DEBUG_VERBOSE,
"%a: The SPI NOR flash device supports uniform 4K erase.\n", __func__));
1341 if (Status == EFI_NOT_FOUND) {
1342 DEBUG ((DEBUG_ERROR,
"However, no corresponding 4K size erase type found.\n"));
1346 Instance->Uniform4KEraseSupported =
TRUE;
1349 DEBUG ((DEBUG_VERBOSE,
"%a: The SPI NOR flash device doesn't support uniform 4K erase.\n", __func__));
1385 IN UINT8 ParameterIdMsb,
1386 IN UINT8 ParameterIdLsb
1392 UINT32 TransactionBufferLength;
1394 DEBUG ((DEBUG_VERBOSE,
"%a: Entry\n", __func__));
1395 DEBUG ((DEBUG_VERBOSE,
" Looking for Parameter Header %02x:%02x\n", ParameterIdMsb, ParameterIdLsb));
1402 for (Index = 0; Index < Instance->SfdpHeader.NumParameterHeaders + 1; Index++) {
1405 if (!EFI_ERROR (Status)) {
1409 SPI_FLASH_RDSFDP_DUMMY,
1410 SPI_FLASH_RDSFDP_ADDR_BYTES,
1416 Status = Instance->SpiIo->Transaction (
1423 TransactionBufferLength,
1424 Instance->SpiTransactionWriteBuffer,
1425 sizeof (LocalSfdpParameterHeader),
1426 (UINT8 *)&LocalSfdpParameterHeader
1429 if (!EFI_ERROR (Status)) {
1433 " #%d Parameter Header: %02x:%02x, revision: %d.%d\n",
1435 LocalSfdpParameterHeader.IdMsb,
1436 LocalSfdpParameterHeader.IdLsb,
1437 LocalSfdpParameterHeader.MajorRev,
1438 LocalSfdpParameterHeader.MinorRev >= SfdpParameterHeader->MinorRev
1440 if ((LocalSfdpParameterHeader.IdLsb == ParameterIdLsb) &&
1441 (LocalSfdpParameterHeader.IdMsb == ParameterIdMsb) &&
1442 (LocalSfdpParameterHeader.MajorRev == (UINT32)SFDP_SUPPORTED_MAJOR_REVISION) &&
1443 (LocalSfdpParameterHeader.MinorRev >= SfdpParameterHeader->MinorRev))
1446 (VOID **)SfdpParameterHeader,
1447 (VOID **)&LocalSfdpParameterHeader,
1459 if (Status != EFI_DEVICE_ERROR) {
1460 if ((SfdpParameterHeader->IdLsb != ParameterIdLsb) ||
1461 (SfdpParameterHeader->IdMsb != ParameterIdMsb))
1463 DEBUG ((DEBUG_ERROR,
" Parameter Header: %02x:%02x is not found.\n", ParameterIdMsb, ParameterIdLsb));
1464 Status = EFI_NOT_FOUND;
1492 IN UINT32 TablePointer,
1493 IN VOID *DestBuffer,
1494 IN UINT32 LengthInBytes
1499 UINT8 *CurrentBuffer;
1501 UINT32 CurrentAddress;
1502 UINT32 MaximumTransferBytes;
1503 UINT32 TransactionBufferLength;
1506 MaximumTransferBytes = Instance->SpiIo->MaximumTransferBytes;
1507 CurrentBuffer = (UINT8 *)DestBuffer;
1508 for (ByteCounter = 0; ByteCounter < LengthInBytes; ByteCounter += Length) {
1509 CurrentAddress = TablePointer + ByteCounter;
1510 Length = LengthInBytes - ByteCounter;
1513 if (Length > MaximumTransferBytes) {
1514 Length = MaximumTransferBytes;
1521 if (!EFI_ERROR (Status)) {
1525 SPI_FLASH_RDSFDP_DUMMY,
1526 SPI_FLASH_RDSFDP_ADDR_BYTES,
1532 Status = Instance->SpiIo->Transaction (
1539 TransactionBufferLength,
1540 Instance->SpiTransactionWriteBuffer,
1544 if (EFI_ERROR (Status)) {
1545 DEBUG ((DEBUG_ERROR,
"%a: Fails to read SFDP parameter.\n", __func__));
1549 CurrentBuffer += Length;
1582 SFDP_SECTOR_MAP_PARAMETER_ID_MSB,
1585 if (!EFI_ERROR (Status)) {
1587 Instance->SfdpSectorMapByteCount = SfdpParamHeader.Length *
sizeof (UINT32);
1588 Instance->SfdpFlashSectorMap =
AllocateZeroPool (Instance->SfdpSectorMapByteCount);
1589 if (Instance->SfdpFlashSectorMap !=
NULL) {
1593 SfdpParamHeader.TablePointer,
1594 (VOID *)Instance->SfdpFlashSectorMap,
1595 Instance->SfdpSectorMapByteCount
1597 if (!EFI_ERROR (Status)) {
1599 if (EFI_ERROR (Status)) {
1600 DEBUG ((DEBUG_ERROR,
"%a: Fails to build sector map command and descriptor.\n", __func__));
1603 if (EFI_ERROR (Status)) {
1604 DEBUG ((DEBUG_ERROR,
"%a: Fails to get current sector map configuration.\n", __func__));
1609 FreePool (Instance->SfdpFlashSectorMap);
1610 Instance->SfdpFlashSectorMap =
NULL;
1611 DEBUG ((DEBUG_ERROR,
"%a: Fails to read SFDP Sector Map Parameter.\n", __func__));
1615 if (EFI_ERROR (Status)) {
1616 DEBUG ((DEBUG_ERROR,
"%a: Fails to allocate memory for reading SFDP Sector Map Parameter.\n", __func__));
1649 &SfdpBasicFlashParamHeader,
1650 SFDP_BASIC_PARAMETER_ID_MSB,
1653 if (!EFI_ERROR (Status)) {
1655 Instance->SfdpBasicFlashByteCount = SfdpBasicFlashParamHeader.Length *
sizeof (UINT32);
1656 Instance->SfdpBasicFlash =
AllocateZeroPool (Instance->SfdpBasicFlashByteCount);
1657 if (Instance->SfdpBasicFlash !=
NULL) {
1661 SfdpBasicFlashParamHeader.TablePointer,
1662 (VOID *)Instance->SfdpBasicFlash,
1663 Instance->SfdpBasicFlashByteCount
1665 if (!EFI_ERROR (Status)) {
1675 Instance->CurrentAddressBytes = 3;
1677 FreePool (Instance->SfdpBasicFlash);
1678 Instance->SfdpBasicFlash =
NULL;
1679 DEBUG ((DEBUG_ERROR,
"%a: Fails to read SFDP Basic Parameter.\n", __func__));
1683 if (EFI_ERROR (Status)) {
1684 DEBUG ((DEBUG_ERROR,
"%a: Fails to allocate memory for reading SFDP Basic Parameter.\n", __func__));
1717 if (Instance ==
NULL) {
1718 DEBUG ((DEBUG_ERROR,
"%a: Instance is NULL.\n", __func__));
1719 return EFI_INVALID_PARAMETER;
1722 if ((Instance->SpiIo ==
NULL) ||
1723 (Instance->SpiIo->SpiPeripheral ==
NULL) ||
1724 (Instance->SpiIo->SpiPeripheral->SpiBus ==
NULL)
1727 DEBUG ((DEBUG_ERROR,
"%a: One of SpiIo, SpiPeripheral and SpiBus is NULL.\n", __func__));
1728 return EFI_INVALID_PARAMETER;
1731 Instance->Signature = SPI_NOR_FLASH_SIGNATURE;
1735 Instance->SpiTransactionWriteBuffer =
1736 AllocatePool (Instance->SpiIo->MaximumTransferBytes + 10);
1738 Protocol = &Instance->Protocol;
1739 Protocol->SpiPeripheral = Instance->SpiIo->SpiPeripheral;
1741 Protocol->ReadData = ReadData;
1745 Protocol->WriteData = WriteData;
1746 Protocol->Erase =
Erase;
1747 Status = Protocol->GetFlashid (Protocol, (UINT8 *)&Protocol->Deviceid);
1751 "%a: Flash ID: Manufacturer=0x%02X, Device=0x%02X%02X\n",
1753 Protocol->Deviceid[0],
1754 Protocol->Deviceid[1],
1755 Protocol->Deviceid[2]
1760 if (EFI_ERROR (Status)) {
1761 DEBUG ((DEBUG_ERROR,
"%a: Failed to Read SFDP\n", __func__));
1767 DEBUG ((DEBUG_VERBOSE,
"%a: Flash Size=0x%X\n", __func__, Protocol->FlashSize));
1768 if (Protocol->FlashSize == 0) {
1774 if (EFI_ERROR (Status)) {
1775 DEBUG ((DEBUG_ERROR,
"%a: Fails to get the smallest erase block size.\n", __func__));
BOOLEAN EFIAPI IsListEmpty(IN CONST LIST_ENTRY *ListHead)
LIST_ENTRY *EFIAPI GetNextNode(IN CONST LIST_ENTRY *List, IN CONST LIST_ENTRY *Node)
BOOLEAN EFIAPI IsNodeAtEnd(IN CONST LIST_ENTRY *List, IN CONST LIST_ENTRY *Node)
LIST_ENTRY *EFIAPI GetFirstNode(IN CONST LIST_ENTRY *List)
UINT64 EFIAPI RShiftU64(IN UINT64 Operand, IN UINTN Count)
LIST_ENTRY *EFIAPI InitializeListHead(IN OUT LIST_ENTRY *ListHead)
UINT64 EFIAPI LShiftU64(IN UINT64 Operand, IN UINTN Count)
LIST_ENTRY *EFIAPI InsertTailList(IN OUT LIST_ENTRY *ListHead, IN OUT LIST_ENTRY *Entry)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
#define ASSERT_EFI_ERROR(StatusParameter)
#define DEBUG(Expression)
#define FixedPcdGet32(TokenName)
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
@ SPI_TRANSACTION_WRITE_THEN_READ
EFI_STATUS EFIAPI ReadStatus(IN CONST EFI_SPI_NOR_FLASH_PROTOCOL *This, IN UINT32 LengthInBytes, OUT UINT8 *FlashStatus)
EFI_STATUS WaitNotWip(IN SPI_NOR_FLASH_INSTANCE *SpiNorFlashInstance, IN UINT32 Timeout, IN UINT32 RetryCount)
EFI_STATUS EFIAPI WriteStatus(IN CONST EFI_SPI_NOR_FLASH_PROTOCOL *This, IN UINT32 LengthInBytes, IN UINT8 *FlashStatus)
EFI_STATUS EFIAPI LfReadData(IN CONST EFI_SPI_NOR_FLASH_PROTOCOL *This, IN UINT32 FlashAddress, IN UINT32 LengthInBytes, OUT UINT8 *Buffer)
EFI_STATUS EFIAPI GetFlashId(IN CONST EFI_SPI_NOR_FLASH_PROTOCOL *This, OUT UINT8 *Buffer)
EFI_STATUS EFIAPI Erase(IN CONST EFI_SPI_NOR_FLASH_PROTOCOL *This, IN UINT32 FlashAddress, IN UINT32 BlockCount)
UINT32 FillWriteBuffer(IN SPI_NOR_FLASH_INSTANCE *Instance, IN UINT8 Opcode, IN UINT32 DummyBytes, IN UINT8 AddressBytesSupported, IN BOOLEAN UseAddress, IN UINT32 Address, IN UINT32 WriteBytes, IN UINT8 *WriteBuffer)
UINT32 SfdpGetFlashSize(IN SPI_NOR_FLASH_INSTANCE *Instance)
EFI_STATUS CreateSingleFlashSectorMap(IN SPI_NOR_FLASH_INSTANCE *Instance)
EFI_STATUS GetEraseTypeRecord(IN SPI_NOR_FLASH_INSTANCE *Instance, IN SFDP_SEARCH_ERASE_TYPE SearchType, IN UINT32 SearchValue, IN UINT8 SupportedTypeTargetNum, IN UINT8 *SupportedTypeTarget OPTIONAL, OUT SFDP_SUPPORTED_ERASE_TYPE_RECORD **EraseTypeRecord)
EFI_STATUS InitialSpiNorFlashSfdpInstance(IN SPI_NOR_FLASH_INSTANCE *Instance)
VOID GetWriteEnableCommand(IN SPI_NOR_FLASH_INSTANCE *Instance)
VOID CreateSpiFastReadTableEntry(IN SPI_NOR_FLASH_INSTANCE *Instance, IN UINT32 FastReadInstruction, IN UINT32 FastReadModeClk, IN UINT32 FastReadDummyClk)
VOID CalculateEraseTiming(IN UINT32 SfdpEraseTypicalTime, IN UINT32 SfdpEraseTimeMultiplier, OUT UINT32 *EraseTypicalTime, OUT UINT64 *EraseTimeout)
BOOLEAN IsTargetEraseType(IN UINT16 EraseType, IN UINT8 TargetTypeNum, IN UINT8 *TargetTypes)
EFI_STATUS GetCurrentSectorMapConfiguration(IN SPI_NOR_FLASH_INSTANCE *Instance)
VOID DebugPrintEraseType(IN SFDP_SUPPORTED_ERASE_TYPE_RECORD *SupportedEraseType)
EFI_STATUS ReadSfdpSectorMapParameterTable(IN SPI_NOR_FLASH_INSTANCE *Instance)
VOID CreateEraseTypeEntry(IN SPI_NOR_FLASH_INSTANCE *Instance, IN SFDP_SUPPORTED_ERASE_TYPE_RECORD *SupportedEraseType)
VOID BuildUpEraseTypeTable(IN SPI_NOR_FLASH_INSTANCE *Instance)
EFI_STATUS SetupRegionEraseInfo(IN SPI_NOR_FLASH_INSTANCE *Instance, IN SFDP_SECTOR_REGION_RECORD *RegionRecord)
EFI_STATUS EFIAPI ReadSfdpParameterHeader(IN SPI_NOR_FLASH_INSTANCE *Instance, IN SFDP_PARAMETER_HEADER *SfdpParameterHeader, IN UINT8 ParameterIdMsb, IN UINT8 ParameterIdLsb)
EFI_STATUS ReadSfdpBasicParameterTable(IN SPI_NOR_FLASH_INSTANCE *Instance)
EFI_STATUS ReadSfdp(IN SPI_NOR_FLASH_INSTANCE *Instance)
EFI_STATUS BuildSectorMapCommandAndMap(IN SPI_NOR_FLASH_INSTANCE *Instance)
EFI_STATUS GetFastReadParameter(IN SPI_NOR_FLASH_INSTANCE *Instance, IN OUT UINT8 *FastReadInstruction, IN OUT UINT8 *FastReadModeBits, IN OUT UINT8 *FastReadDummyClocks)
EFI_STATUS EFIAPI ReadSfdpHeader(IN SPI_NOR_FLASH_INSTANCE *Instance)
EFI_STATUS SetSectorEraseBlockSize(IN SPI_NOR_FLASH_INSTANCE *Instance)
VOID BuildUpFastReadTable(IN SPI_NOR_FLASH_INSTANCE *Instance)
EFI_STATUS GetEraseBlockAttribute(IN SPI_NOR_FLASH_INSTANCE *Instance, IN SFDP_SECTOR_REGION_RECORD *FlashRegion, IN UINT32 FlashAddress, IN UINT32 RemainingSize, IN OUT UINT32 *BlockSizeToErase, IN OUT UINT32 *BlockCountToErase, OUT UINT8 *BlockEraseCommand, OUT UINT32 *TypicalTime, OUT UINT64 *MaximumTimeout)
EFI_STATUS GetRegionByFlashAddress(IN SPI_NOR_FLASH_INSTANCE *Instance, IN UINT32 FlashAddress, OUT SFDP_SECTOR_REGION_RECORD **FlashRegion)
EFI_STATUS EFIAPI SpiReadSfdpPtp(IN SPI_NOR_FLASH_INSTANCE *Instance, IN UINT32 TablePointer, IN VOID *DestBuffer, IN UINT32 LengthInBytes)
#define SFDP_SECTOR_MAP_PARAMETER_ID_LSB
#define SPI_ADDR_3BYTE_ONLY
#define SFDP_BASIC_PARAMETER_ID_LSB
JEDEC Basic Flash Parameter Header.
SPDF_CONFIGURATION_COMMAND_ADDR_LENGTH
UINT32 EraseType2
Earse type 2 is supported.
UINT32 EraseType3
Earse type 3 is supported.
UINT32 EraseType1
Earse type 1 is supported.
UINT32 RegionSize
Region size in 256 Byte unit.
UINT32 EraseType4
Earse type 4 is supported.
UINT32 DetectionLatency
Configuration detection command read latency.
UINT32 DetectionCommandAddressLen
Configuration detection command address length.
UINT32 DetectionInstruction
Sector map configuration detection command.
UINT32 DescriptorEnd
Descriptor Sequence End Indicator.
UINT32 CommandAddress
Sector map configuration detection command address.
UINT32 DescriptorType
Descriptor Type.
UINT32 DescriptorEnd
Descriptor Sequence End Indicator.
UINT32 ConfigurationID
ID of this configuration.
UINT32 DescriptorType
Descriptor Type.
UINT32 RegionCount
The region count of this configuration.
UINT8 ConfigurationBitMask
LIST_ENTRY NextCommand
Link list to next detection command.
UINT8 CommandInstruction
Detection command instruction.
UINT8 LatencyInClock
Command latency in clocks.
UINT32 CommandAddress
Address to issue the command.
SPDF_CONFIGURATION_COMMAND_ADDR_LENGTH CommandAddressLength
Adddress length of detection command.
UINT8 RegionCount
The regions of this sector map configuration.
LIST_ENTRY RegionList
The linked list of the regions.
UINT8 ConfigurationId
The ID of this configuration.
LIST_ENTRY NextDescriptor
Link list to next flash map descriptor.
UINT8 SupportedEraseType[SFDP_ERASE_TYPES_NUMBER]
Erase types supported.
LIST_ENTRY NextRegion
Link list to the next region.
UINT32 RegionSectors
Sectors in this region.
UINT32 RegionAddress
Region starting address.
UINT32 EraseTypeBySizeBitmap
UINT8 SupportedEraseTypeNum
Number of erase type supported.
UINT32 SectorSize
Sector size in byte (Minimum blcok erase size)
UINT32 RegionTotalSize
Region total size in bytes.
UINT64 EraseTimeout
Maximum typical erase timeout.
UINT8 EraseInstruction
Erase instruction.
UINT16 EraseType
Erase type this flash device supports.
LIST_ENTRY NextEraseType
Link list to next erase type.
UINT8 ModeClocks
Fast read clock.
UINT8 FastReadInstruction
Fast read instruction.
UINT8 WaitStates
Fast read wait dummy clocks.
LIST_ENTRY NextFastReadCap
Link list to next Fast read capability.
SFDP_SECTOR_CONFIGURATION_MAP ConfigurationMap
Flash map descriptor.
SFDP_SECTOR_CONFIGURATION_COMMAND ConfigurationCommand
Fash configuration detection command.