18#define DIAGNOSTIC_LOGBUFFER_MAXCHAR 1024
20CHAR16 *mLogBuffer =
NULL;
21UINTN mLogRemainChar = 0;
28 mLogRemainChar = MaxBufferChar;
40 if (len < mLogRemainChar) {
41 StrCpyS (mLogBuffer, mLogRemainChar, Str);
42 mLogRemainChar -= len;
57 UINT64 *Buffer64 = (UINT64 *)Buffer;
59 for (i = 0; i < (BufferSize >> 3); i++) {
73 UINT64 *BufferA64 = (UINT64 *)BufferA;
74 UINT64 *BufferB64 = (UINT64 *)BufferB;
76 for (i = 0; i < (BufferSize >> 3); i++) {
77 if (*BufferA64 != *BufferB64) {
78 DEBUG ((DEBUG_ERROR,
"CompareBuffer: Error at %i", i));
79 DEBUG ((DEBUG_ERROR,
"(0x%lX) != (0x%lX)\n", *BufferA64, *BufferB64));
104 DiagnosticLog (L
"ERROR: No Media Present\n");
108 if (MmcHostInstance->State != MmcTransferState) {
109 DiagnosticLog (L
"ERROR: Not ready for Transfer state\n");
110 return EFI_NOT_READY;
118 Status =
MmcReadBlocks (&(MmcHostInstance->BlockIo), MmcHostInstance->BlockIo.
Media->
MediaId, Lba, BufferSize, BackBuffer);
120 DiagnosticLog (L
"ERROR: Fail to Read Block (1)\n");
125 GenerateRandomBuffer (WriteBuffer, BufferSize);
128 DiagnosticLog (L
"ERROR: Fail to Write Block (1)\n");
133 Status =
MmcReadBlocks (&(MmcHostInstance->BlockIo), MmcHostInstance->BlockIo.
Media->
MediaId, Lba, BufferSize, ReadBuffer);
135 DiagnosticLog (L
"ERROR: Fail to Read Block (2)\n");
140 if (!CompareBuffer (ReadBuffer, WriteBuffer, BufferSize)) {
141 DiagnosticLog (L
"ERROR: Fail to Read/Write Block (1)\n");
142 return EFI_INVALID_PARAMETER;
148 DiagnosticLog (L
"ERROR: Fail to Write Block (2)\n");
153 Status =
MmcReadBlocks (&(MmcHostInstance->BlockIo), MmcHostInstance->BlockIo.
Media->
MediaId, Lba, BufferSize, ReadBuffer);
155 DiagnosticLog (L
"ERROR: Fail to Read Block (3)\n");
160 if (!CompareBuffer (ReadBuffer, BackBuffer, BufferSize)) {
161 DiagnosticLog (L
"ERROR: Fail to Read/Write Block (2)\n");
162 return EFI_INVALID_PARAMETER;
170MmcDriverDiagnosticsRunDiagnostics (
185 if ((Language ==
NULL) ||
186 (ErrorType ==
NULL) ||
188 (ControllerHandle ==
NULL) ||
189 (BufferSize ==
NULL))
191 return EFI_INVALID_PARAMETER;
196 return EFI_UNSUPPORTED;
201 *BufferSize = DIAGNOSTIC_LOGBUFFER_MAXCHAR;
202 *Buffer = DiagnosticInitLog (DIAGNOSTIC_LOGBUFFER_MAXCHAR);
204 DiagnosticLog (L
"MMC Driver Diagnostics\n");
207 MmcHostInstance =
NULL;
208 CurrentLink = mMmcHostPool.ForwardLink;
209 while (CurrentLink !=
NULL && CurrentLink != &mMmcHostPool && (Status ==
EFI_SUCCESS)) {
210 MmcHostInstance = MMC_HOST_INSTANCE_FROM_LINK (CurrentLink);
211 ASSERT (MmcHostInstance !=
NULL);
212 if (MmcHostInstance->MmcHandle == ControllerHandle) {
216 CurrentLink = CurrentLink->ForwardLink;
220 if ( (MmcHostInstance ==
NULL)
221 || (MmcHostInstance->MmcHandle != ControllerHandle))
223 return EFI_UNSUPPORTED;
227 DiagnosticLog (L
"MMC Driver Diagnostics - Test: First Block\n");
228 Status = MmcReadWriteDataTest (MmcHostInstance, 1, MmcHostInstance->BlockIo.
Media->
BlockSize);
231 DiagnosticLog (L
"MMC Driver Diagnostics - Test: Second Block\n");
232 Status = MmcReadWriteDataTest (MmcHostInstance, 2, MmcHostInstance->BlockIo.
Media->
BlockSize);
235 DiagnosticLog (L
"MMC Driver Diagnostics - Test: Any Block\n");
236 Status = MmcReadWriteDataTest (
243 DiagnosticLog (L
"MMC Driver Diagnostics - Test: Last Block\n");
247 DiagnosticLog (L
"MMC Driver Diagnostics - Test: First Block / 2 BlockSSize\n");
248 Status = MmcReadWriteDataTest (MmcHostInstance, 1, 2 * MmcHostInstance->BlockIo.
Media->
BlockSize);
RETURN_STATUS EFIAPI StrCpyS(OUT CHAR16 *Destination, IN UINTN DestMax, IN CONST CHAR16 *Source)
INTN EFIAPI AsciiStrnCmp(IN CONST CHAR8 *FirstString, IN CONST CHAR8 *SecondString, IN UINTN Length)
UINT64 EFIAPI RShiftU64(IN UINT64 Operand, IN UINTN Count)
UINT64 EFIAPI LShiftU64(IN UINT64 Operand, IN UINTN Count)
UINTN EFIAPI StrLen(IN CONST CHAR16 *String)
EFI_STATUS(EFIAPI * EFI_DRIVER_DIAGNOSTICS2_RUN_DIAGNOSTICS)(IN EFI_DRIVER_DIAGNOSTICS2_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN EFI_HANDLE ChildHandle OPTIONAL, IN EFI_DRIVER_DIAGNOSTIC_TYPE DiagnosticType, IN CHAR8 *Language, OUT EFI_GUID **ErrorType, OUT UINTN *BufferSize, OUT CHAR16 **Buffer)
EFI_DRIVER_DIAGNOSTIC_TYPE
#define GLOBAL_REMOVE_IF_UNREFERENCED
#define DEBUG(Expression)
EFI_STATUS EFIAPI MmcReadBlocks(IN EFI_BLOCK_IO_PROTOCOL *This, IN UINT32 MediaId, IN EFI_LBA Lba, IN UINTN BufferSize, OUT VOID *Buffer)
EFI_STATUS EFIAPI MmcWriteBlocks(IN EFI_BLOCK_IO_PROTOCOL *This, IN UINT32 MediaId, IN EFI_LBA Lba, IN UINTN BufferSize, IN VOID *Buffer)
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
EFI_BLOCK_IO_MEDIA * Media