ArmPlatformPkg: Apply uncrustify changes

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3737

Apply uncrustify changes to .c/.h files in the ArmPlatformPkg package

Cc: Andrew Fish <afish@apple.com>
Cc: Leif Lindholm <leif@nuviainc.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Reviewed-by: Andrew Fish <afish@apple.com>
This commit is contained in:
Michael Kubacki
2021-12-05 14:53:52 -08:00
committed by mergify[bot]
parent 429309e0c6
commit 40b0b23ed3
47 changed files with 2846 additions and 2662 deletions

View File

@ -34,7 +34,7 @@ VideoCopyNoHorizontalOverlap (
IN UINTN DestinationY, IN UINTN DestinationY,
IN UINTN Width, IN UINTN Width,
IN UINTN Height IN UINTN Height
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
UINTN SourceLine; UINTN SourceLine;
@ -47,7 +47,7 @@ VideoCopyNoHorizontalOverlap (
Status = EFI_SUCCESS; Status = EFI_SUCCESS;
if( DestinationY <= SourceY ) { if ( DestinationY <= SourceY ) {
// scrolling up (or horizontally but without overlap) // scrolling up (or horizontally but without overlap)
SourceLine = SourceY; SourceLine = SourceY;
DestinationLine = DestinationY; DestinationLine = DestinationY;
@ -60,23 +60,23 @@ VideoCopyNoHorizontalOverlap (
} }
switch (BitsPerPixel) { switch (BitsPerPixel) {
case LcdBitsPerPixel_24: case LcdBitsPerPixel_24:
WidthInBytes = Width * 4; WidthInBytes = Width * 4;
for( LineCount = 0; LineCount < Height; LineCount++ ) { for ( LineCount = 0; LineCount < Height; LineCount++ ) {
// Update the start addresses of source & destination using 32bit pointer arithmetic // Update the start addresses of source & destination using 32bit pointer arithmetic
SourceAddr = (VOID *)((UINT32 *)FrameBufferBase + SourceLine * HorizontalResolution + SourceX ); SourceAddr = (VOID *)((UINT32 *)FrameBufferBase + SourceLine * HorizontalResolution + SourceX);
DestinationAddr = (VOID *)((UINT32 *)FrameBufferBase + DestinationLine * HorizontalResolution + DestinationX); DestinationAddr = (VOID *)((UINT32 *)FrameBufferBase + DestinationLine * HorizontalResolution + DestinationX);
// Copy the entire line Y from video ram to the temp buffer // Copy the entire line Y from video ram to the temp buffer
CopyMem( DestinationAddr, SourceAddr, WidthInBytes); CopyMem (DestinationAddr, SourceAddr, WidthInBytes);
// Update the line numbers // Update the line numbers
SourceLine += Step; SourceLine += Step;
DestinationLine += Step; DestinationLine += Step;
} }
break; break;
case LcdBitsPerPixel_16_555: case LcdBitsPerPixel_16_555:
@ -85,18 +85,19 @@ VideoCopyNoHorizontalOverlap (
WidthInBytes = Width * 2; WidthInBytes = Width * 2;
for( LineCount = 0; LineCount < Height; LineCount++ ) { for ( LineCount = 0; LineCount < Height; LineCount++ ) {
// Update the start addresses of source & destination using 16bit pointer arithmetic // Update the start addresses of source & destination using 16bit pointer arithmetic
SourceAddr = (VOID *)((UINT16 *)FrameBufferBase + SourceLine * HorizontalResolution + SourceX ); SourceAddr = (VOID *)((UINT16 *)FrameBufferBase + SourceLine * HorizontalResolution + SourceX);
DestinationAddr = (VOID *)((UINT16 *)FrameBufferBase + DestinationLine * HorizontalResolution + DestinationX); DestinationAddr = (VOID *)((UINT16 *)FrameBufferBase + DestinationLine * HorizontalResolution + DestinationX);
// Copy the entire line Y from video ram to the temp buffer // Copy the entire line Y from video ram to the temp buffer
CopyMem( DestinationAddr, SourceAddr, WidthInBytes); CopyMem (DestinationAddr, SourceAddr, WidthInBytes);
// Update the line numbers // Update the line numbers
SourceLine += Step; SourceLine += Step;
DestinationLine += Step; DestinationLine += Step;
} }
break; break;
case LcdBitsPerPixel_8: case LcdBitsPerPixel_8:
@ -105,14 +106,13 @@ VideoCopyNoHorizontalOverlap (
case LcdBitsPerPixel_1: case LcdBitsPerPixel_1:
default: default:
// Can't handle this case // Can't handle this case
DEBUG((DEBUG_ERROR, "ArmVeGraphics_Blt: EfiBltVideoToVideo: INVALID Number of Bits Per Pixel: %d\n", BitsPerPixel)); DEBUG ((DEBUG_ERROR, "ArmVeGraphics_Blt: EfiBltVideoToVideo: INVALID Number of Bits Per Pixel: %d\n", BitsPerPixel));
Status = EFI_INVALID_PARAMETER; Status = EFI_INVALID_PARAMETER;
goto EXIT; goto EXIT;
// break; // break;
} }
EXIT: EXIT:
return Status; return Status;
} }
@ -128,7 +128,7 @@ VideoCopyHorizontalOverlap (
IN UINTN DestinationY, IN UINTN DestinationY,
IN UINTN Width, IN UINTN Width,
IN UINTN Height IN UINTN Height
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
@ -148,11 +148,10 @@ VideoCopyHorizontalOverlap (
Status = EFI_SUCCESS; Status = EFI_SUCCESS;
switch (BitsPerPixel) { switch (BitsPerPixel) {
case LcdBitsPerPixel_24: case LcdBitsPerPixel_24:
// Allocate a temporary buffer // Allocate a temporary buffer
PixelBuffer32bit = (UINT32 *) AllocatePool((Height * Width) * sizeof(UINT32)); PixelBuffer32bit = (UINT32 *)AllocatePool ((Height * Width) * sizeof (UINT32));
if (PixelBuffer32bit == NULL) { if (PixelBuffer32bit == NULL) {
Status = EFI_OUT_OF_RESOURCES; Status = EFI_OUT_OF_RESOURCES;
@ -170,7 +169,7 @@ VideoCopyHorizontalOverlap (
SourcePixel32bit = (UINT32 *)FrameBufferBase + SourcePixelY * HorizontalResolution + SourceX; SourcePixel32bit = (UINT32 *)FrameBufferBase + SourcePixelY * HorizontalResolution + SourceX;
// Copy the entire line Y from video ram to the temp buffer // Copy the entire line Y from video ram to the temp buffer
CopyMem( (VOID *)DestinationPixel32bit, (CONST VOID *)SourcePixel32bit, SizeIn32Bits); CopyMem ((VOID *)DestinationPixel32bit, (CONST VOID *)SourcePixel32bit, SizeIn32Bits);
} }
// Copy from the temp buffer to the video ram (destination region) // Copy from the temp buffer to the video ram (destination region)
@ -182,20 +181,19 @@ VideoCopyHorizontalOverlap (
DestinationPixel32bit = (UINT32 *)FrameBufferBase + DestinationPixelY * HorizontalResolution + DestinationX; DestinationPixel32bit = (UINT32 *)FrameBufferBase + DestinationPixelY * HorizontalResolution + DestinationX;
// Copy the entire line Y from the temp buffer to video ram // Copy the entire line Y from the temp buffer to video ram
CopyMem( (VOID *)DestinationPixel32bit, (CONST VOID *)SourcePixel32bit, SizeIn32Bits); CopyMem ((VOID *)DestinationPixel32bit, (CONST VOID *)SourcePixel32bit, SizeIn32Bits);
} }
// Free up the allocated memory // Free up the allocated memory
FreePool((VOID *) PixelBuffer32bit); FreePool ((VOID *)PixelBuffer32bit);
break; break;
case LcdBitsPerPixel_16_555: case LcdBitsPerPixel_16_555:
case LcdBitsPerPixel_16_565: case LcdBitsPerPixel_16_565:
case LcdBitsPerPixel_12_444: case LcdBitsPerPixel_12_444:
// Allocate a temporary buffer // Allocate a temporary buffer
PixelBuffer16bit = (UINT16 *) AllocatePool((Height * Width) * sizeof(UINT16)); PixelBuffer16bit = (UINT16 *)AllocatePool ((Height * Width) * sizeof (UINT16));
if (PixelBuffer16bit == NULL) { if (PixelBuffer16bit == NULL) {
Status = EFI_OUT_OF_RESOURCES; Status = EFI_OUT_OF_RESOURCES;
@ -214,7 +212,7 @@ VideoCopyHorizontalOverlap (
SourcePixel16bit = (UINT16 *)FrameBufferBase + SourcePixelY * HorizontalResolution + SourceX; SourcePixel16bit = (UINT16 *)FrameBufferBase + SourcePixelY * HorizontalResolution + SourceX;
// Copy the entire line Y from Video to the temp buffer // Copy the entire line Y from Video to the temp buffer
CopyMem( (VOID *)DestinationPixel16bit, (CONST VOID *)SourcePixel16bit, SizeIn16Bits); CopyMem ((VOID *)DestinationPixel16bit, (CONST VOID *)SourcePixel16bit, SizeIn16Bits);
} }
// Copy from the temp buffer into the destination area of the Video Memory // Copy from the temp buffer into the destination area of the Video Memory
@ -227,26 +225,24 @@ VideoCopyHorizontalOverlap (
DestinationPixel16bit = (UINT16 *)FrameBufferBase + (DestinationPixelY * HorizontalResolution + DestinationX); DestinationPixel16bit = (UINT16 *)FrameBufferBase + (DestinationPixelY * HorizontalResolution + DestinationX);
// Copy the entire line Y from the temp buffer to Video // Copy the entire line Y from the temp buffer to Video
CopyMem( (VOID *)DestinationPixel16bit, (CONST VOID *)SourcePixel16bit, SizeIn16Bits); CopyMem ((VOID *)DestinationPixel16bit, (CONST VOID *)SourcePixel16bit, SizeIn16Bits);
} }
// Free the allocated memory // Free the allocated memory
FreePool((VOID *) PixelBuffer16bit); FreePool ((VOID *)PixelBuffer16bit);
break; break;
case LcdBitsPerPixel_8: case LcdBitsPerPixel_8:
case LcdBitsPerPixel_4: case LcdBitsPerPixel_4:
case LcdBitsPerPixel_2: case LcdBitsPerPixel_2:
case LcdBitsPerPixel_1: case LcdBitsPerPixel_1:
default: default:
// Can't handle this case // Can't handle this case
DEBUG((DEBUG_ERROR, "ArmVeGraphics_Blt: EfiBltVideoToVideo: INVALID Number of Bits Per Pixel: %d\n", BitsPerPixel)); DEBUG ((DEBUG_ERROR, "ArmVeGraphics_Blt: EfiBltVideoToVideo: INVALID Number of Bits Per Pixel: %d\n", BitsPerPixel));
Status = EFI_INVALID_PARAMETER; Status = EFI_INVALID_PARAMETER;
goto EXIT; goto EXIT;
// break; // break;
} }
EXIT: EXIT:
@ -267,7 +263,7 @@ BltVideoFill (
IN UINTN Delta OPTIONAL // Number of BYTES in a row of the BltBuffer IN UINTN Delta OPTIONAL // Number of BYTES in a row of the BltBuffer
) )
{ {
EFI_PIXEL_BITMASK* PixelInformation; EFI_PIXEL_BITMASK *PixelInformation;
EFI_STATUS Status; EFI_STATUS Status;
UINT32 HorizontalResolution; UINT32 HorizontalResolution;
LCD_BPP BitsPerPixel; LCD_BPP BitsPerPixel;
@ -284,7 +280,7 @@ BltVideoFill (
FrameBufferBase = (UINTN *)((UINTN)(This->Mode->FrameBufferBase)); FrameBufferBase = (UINTN *)((UINTN)(This->Mode->FrameBufferBase));
HorizontalResolution = This->Mode->Info->HorizontalResolution; HorizontalResolution = This->Mode->Info->HorizontalResolution;
LcdPlatformGetBpp (This->Mode->Mode,&BitsPerPixel); LcdPlatformGetBpp (This->Mode->Mode, &BitsPerPixel);
switch (BitsPerPixel) { switch (BitsPerPixel) {
case LcdBitsPerPixel_24: case LcdBitsPerPixel_24:
@ -301,15 +297,16 @@ BltVideoFill (
// Fill the entire line // Fill the entire line
SetMem32 (DestinationAddr, WidthInBytes, *((UINT32 *)EfiSourcePixel)); SetMem32 (DestinationAddr, WidthInBytes, *((UINT32 *)EfiSourcePixel));
} }
break; break;
case LcdBitsPerPixel_16_555: case LcdBitsPerPixel_16_555:
// Convert the EFI pixel at the start of the BltBuffer(0,0) into a video display pixel // Convert the EFI pixel at the start of the BltBuffer(0,0) into a video display pixel
Pixel16bit = (UINT16) ( Pixel16bit = (UINT16)(
( (EfiSourcePixel->Red << 7) & PixelInformation->RedMask ) ((EfiSourcePixel->Red << 7) & PixelInformation->RedMask)
| ( (EfiSourcePixel->Green << 2) & PixelInformation->GreenMask ) | ((EfiSourcePixel->Green << 2) & PixelInformation->GreenMask)
| ( (EfiSourcePixel->Blue >> 3) & PixelInformation->BlueMask ) | ((EfiSourcePixel->Blue >> 3) & PixelInformation->BlueMask)
// | ( 0 & PixelInformation->ReservedMask ) // | ( 0 & PixelInformation->ReservedMask )
); );
// Copy the SourcePixel into every pixel inside the target rectangle // Copy the SourcePixel into every pixel inside the target rectangle
@ -328,14 +325,15 @@ BltVideoFill (
*DestinationPixel16bit = Pixel16bit; *DestinationPixel16bit = Pixel16bit;
} }
} }
break; break;
case LcdBitsPerPixel_16_565: case LcdBitsPerPixel_16_565:
// Convert the EFI pixel at the start of the BltBuffer(0,0) into a video display pixel // Convert the EFI pixel at the start of the BltBuffer(0,0) into a video display pixel
Pixel16bit = (UINT16) ( Pixel16bit = (UINT16)(
( (EfiSourcePixel->Red << 8) & PixelInformation->RedMask ) ((EfiSourcePixel->Red << 8) & PixelInformation->RedMask)
| ( (EfiSourcePixel->Green << 3) & PixelInformation->GreenMask ) | ((EfiSourcePixel->Green << 3) & PixelInformation->GreenMask)
| ( (EfiSourcePixel->Blue >> 3) & PixelInformation->BlueMask ) | ((EfiSourcePixel->Blue >> 3) & PixelInformation->BlueMask)
); );
// Copy the SourcePixel into every pixel inside the target rectangle // Copy the SourcePixel into every pixel inside the target rectangle
@ -354,14 +352,15 @@ BltVideoFill (
*DestinationPixel16bit = Pixel16bit; *DestinationPixel16bit = Pixel16bit;
} }
} }
break; break;
case LcdBitsPerPixel_12_444: case LcdBitsPerPixel_12_444:
// Convert the EFI pixel at the start of the BltBuffer(0,0) into a video display pixel // Convert the EFI pixel at the start of the BltBuffer(0,0) into a video display pixel
Pixel16bit = (UINT16) ( Pixel16bit = (UINT16)(
( (EfiSourcePixel->Red >> 4) & PixelInformation->RedMask ) ((EfiSourcePixel->Red >> 4) & PixelInformation->RedMask)
| ( (EfiSourcePixel->Green ) & PixelInformation->GreenMask ) | ((EfiSourcePixel->Green) & PixelInformation->GreenMask)
| ( (EfiSourcePixel->Blue << 4) & PixelInformation->BlueMask ) | ((EfiSourcePixel->Blue << 4) & PixelInformation->BlueMask)
); );
// Copy the SourcePixel into every pixel inside the target rectangle // Copy the SourcePixel into every pixel inside the target rectangle
@ -380,6 +379,7 @@ BltVideoFill (
*DestinationPixel16bit = Pixel16bit; *DestinationPixel16bit = Pixel16bit;
} }
} }
break; break;
case LcdBitsPerPixel_8: case LcdBitsPerPixel_8:
@ -388,7 +388,7 @@ BltVideoFill (
case LcdBitsPerPixel_1: case LcdBitsPerPixel_1:
default: default:
// Can't handle this case // Can't handle this case
DEBUG((DEBUG_ERROR, "LcdGraphicsBlt: EfiBltVideoFill: INVALID Number of Bits Per Pixel: %d\n", BitsPerPixel)); DEBUG ((DEBUG_ERROR, "LcdGraphicsBlt: EfiBltVideoFill: INVALID Number of Bits Per Pixel: %d\n", BitsPerPixel));
Status = EFI_INVALID_PARAMETER; Status = EFI_INVALID_PARAMETER;
break; break;
} }
@ -432,15 +432,15 @@ BltVideoToBltBuffer (
HorizontalResolution = This->Mode->Info->HorizontalResolution; HorizontalResolution = This->Mode->Info->HorizontalResolution;
FrameBufferBase = (UINTN *)((UINTN)(This->Mode->FrameBufferBase)); FrameBufferBase = (UINTN *)((UINTN)(This->Mode->FrameBufferBase));
if(( Delta != 0 ) && ( Delta != Width * sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL))) { if ((Delta != 0) && (Delta != Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL))) {
// Delta is not zero and it is different from the width. // Delta is not zero and it is different from the width.
// Divide it by the size of a pixel to find out the buffer's horizontal resolution. // Divide it by the size of a pixel to find out the buffer's horizontal resolution.
BltBufferHorizontalResolution = (UINT32) (Delta / sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL)); BltBufferHorizontalResolution = (UINT32)(Delta / sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
} else { } else {
BltBufferHorizontalResolution = Width; BltBufferHorizontalResolution = Width;
} }
LcdPlatformGetBpp (This->Mode->Mode,&BitsPerPixel); LcdPlatformGetBpp (This->Mode->Mode, &BitsPerPixel);
switch (BitsPerPixel) { switch (BitsPerPixel) {
case LcdBitsPerPixel_24: case LcdBitsPerPixel_24:
@ -452,12 +452,13 @@ BltVideoToBltBuffer (
SourceLine++, DestinationLine++) SourceLine++, DestinationLine++)
{ {
// Calculate the source and target addresses using 32bit pointer arithmetic: // Calculate the source and target addresses using 32bit pointer arithmetic:
SourceAddr = (VOID *)((UINT32 *)FrameBufferBase + SourceLine * HorizontalResolution + SourceX ); SourceAddr = (VOID *)((UINT32 *)FrameBufferBase + SourceLine * HorizontalResolution + SourceX);
DestinationAddr = (VOID *)((UINT32 *)BltBuffer + DestinationLine * BltBufferHorizontalResolution + DestinationX); DestinationAddr = (VOID *)((UINT32 *)BltBuffer + DestinationLine * BltBufferHorizontalResolution + DestinationX);
// Copy the entire line // Copy the entire line
CopyMem( DestinationAddr, SourceAddr, WidthInBytes); CopyMem (DestinationAddr, SourceAddr, WidthInBytes);
} }
break; break;
case LcdBitsPerPixel_16_555: case LcdBitsPerPixel_16_555:
@ -479,12 +480,13 @@ BltVideoToBltBuffer (
Pixel16bit = *SourcePixel16bit; Pixel16bit = *SourcePixel16bit;
// Copy the pixel into the new target // Copy the pixel into the new target
EfiDestinationPixel->Red = (UINT8) ( (Pixel16bit & PixelInformation->RedMask ) >> 7 ); EfiDestinationPixel->Red = (UINT8)((Pixel16bit & PixelInformation->RedMask) >> 7);
EfiDestinationPixel->Green = (UINT8) ( (Pixel16bit & PixelInformation->GreenMask ) >> 2); EfiDestinationPixel->Green = (UINT8)((Pixel16bit & PixelInformation->GreenMask) >> 2);
EfiDestinationPixel->Blue = (UINT8) ( (Pixel16bit & PixelInformation->BlueMask ) << 3 ); EfiDestinationPixel->Blue = (UINT8)((Pixel16bit & PixelInformation->BlueMask) << 3);
// EfiDestinationPixel->Reserved = (UINT8) 0; // EfiDestinationPixel->Reserved = (UINT8) 0;
} }
} }
break; break;
case LcdBitsPerPixel_16_565: case LcdBitsPerPixel_16_565:
@ -507,12 +509,13 @@ BltVideoToBltBuffer (
// Copy the pixel into the new target // Copy the pixel into the new target
// There is no info for the Reserved byte, so we set it to zero // There is no info for the Reserved byte, so we set it to zero
EfiDestinationPixel->Red = (UINT8) ( (Pixel16bit & PixelInformation->RedMask ) >> 8 ); EfiDestinationPixel->Red = (UINT8)((Pixel16bit & PixelInformation->RedMask) >> 8);
EfiDestinationPixel->Green = (UINT8) ( (Pixel16bit & PixelInformation->GreenMask ) >> 3); EfiDestinationPixel->Green = (UINT8)((Pixel16bit & PixelInformation->GreenMask) >> 3);
EfiDestinationPixel->Blue = (UINT8) ( (Pixel16bit & PixelInformation->BlueMask ) << 3 ); EfiDestinationPixel->Blue = (UINT8)((Pixel16bit & PixelInformation->BlueMask) << 3);
// EfiDestinationPixel->Reserved = (UINT8) 0; // EfiDestinationPixel->Reserved = (UINT8) 0;
} }
} }
break; break;
case LcdBitsPerPixel_12_444: case LcdBitsPerPixel_12_444:
@ -534,12 +537,13 @@ BltVideoToBltBuffer (
Pixel16bit = *SourcePixel16bit; Pixel16bit = *SourcePixel16bit;
// Copy the pixel into the new target // Copy the pixel into the new target
EfiDestinationPixel->Red = (UINT8) ( (Pixel16bit & PixelInformation->RedMask ) >> 4 ); EfiDestinationPixel->Red = (UINT8)((Pixel16bit & PixelInformation->RedMask) >> 4);
EfiDestinationPixel->Green = (UINT8) ( (Pixel16bit & PixelInformation->GreenMask ) ); EfiDestinationPixel->Green = (UINT8)((Pixel16bit & PixelInformation->GreenMask));
EfiDestinationPixel->Blue = (UINT8) ( (Pixel16bit & PixelInformation->BlueMask ) << 4 ); EfiDestinationPixel->Blue = (UINT8)((Pixel16bit & PixelInformation->BlueMask) << 4);
// EfiDestinationPixel->Reserved = (UINT8) 0; // EfiDestinationPixel->Reserved = (UINT8) 0;
} }
} }
break; break;
case LcdBitsPerPixel_8: case LcdBitsPerPixel_8:
@ -548,10 +552,11 @@ BltVideoToBltBuffer (
case LcdBitsPerPixel_1: case LcdBitsPerPixel_1:
default: default:
// Can't handle this case // Can't handle this case
DEBUG((DEBUG_ERROR, "LcdGraphicsBlt: EfiBltVideoToBltBuffer: INVALID Number of Bits Per Pixel: %d\n", BitsPerPixel)); DEBUG ((DEBUG_ERROR, "LcdGraphicsBlt: EfiBltVideoToBltBuffer: INVALID Number of Bits Per Pixel: %d\n", BitsPerPixel));
Status = EFI_INVALID_PARAMETER; Status = EFI_INVALID_PARAMETER;
break; break;
} }
return Status; return Status;
} }
@ -590,15 +595,15 @@ BltBufferToVideo (
HorizontalResolution = This->Mode->Info->HorizontalResolution; HorizontalResolution = This->Mode->Info->HorizontalResolution;
FrameBufferBase = (UINTN *)((UINTN)(This->Mode->FrameBufferBase)); FrameBufferBase = (UINTN *)((UINTN)(This->Mode->FrameBufferBase));
if(( Delta != 0 ) && ( Delta != Width * sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL))) { if ((Delta != 0) && (Delta != Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL))) {
// Delta is not zero and it is different from the width. // Delta is not zero and it is different from the width.
// Divide it by the size of a pixel to find out the buffer's horizontal resolution. // Divide it by the size of a pixel to find out the buffer's horizontal resolution.
BltBufferHorizontalResolution = (UINT32) (Delta / sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL)); BltBufferHorizontalResolution = (UINT32)(Delta / sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
} else { } else {
BltBufferHorizontalResolution = Width; BltBufferHorizontalResolution = Width;
} }
LcdPlatformGetBpp (This->Mode->Mode,&BitsPerPixel); LcdPlatformGetBpp (This->Mode->Mode, &BitsPerPixel);
switch (BitsPerPixel) { switch (BitsPerPixel) {
case LcdBitsPerPixel_24: case LcdBitsPerPixel_24:
@ -610,20 +615,21 @@ BltBufferToVideo (
SourceLine++, DestinationLine++) SourceLine++, DestinationLine++)
{ {
// Calculate the source and target addresses using 32bit pointer arithmetic: // Calculate the source and target addresses using 32bit pointer arithmetic:
SourceAddr = (VOID *)((UINT32 *)BltBuffer + SourceLine * BltBufferHorizontalResolution + SourceX ); SourceAddr = (VOID *)((UINT32 *)BltBuffer + SourceLine * BltBufferHorizontalResolution + SourceX);
DestinationAddr = (VOID *)((UINT32 *)FrameBufferBase + DestinationLine * HorizontalResolution + DestinationX); DestinationAddr = (VOID *)((UINT32 *)FrameBufferBase + DestinationLine * HorizontalResolution + DestinationX);
// Copy the entire row Y // Copy the entire row Y
CopyMem( DestinationAddr, SourceAddr, WidthInBytes); CopyMem (DestinationAddr, SourceAddr, WidthInBytes);
} }
break; break;
case LcdBitsPerPixel_16_555: case LcdBitsPerPixel_16_555:
// Access each pixel inside the BltBuffer Memory // Access each pixel inside the BltBuffer Memory
for (SourceLine = SourceY, DestinationLine = DestinationY; for (SourceLine = SourceY, DestinationLine = DestinationY;
SourceLine < SourceY + Height; SourceLine < SourceY + Height;
SourceLine++, DestinationLine++) { SourceLine++, DestinationLine++)
{
for (SourcePixelX = SourceX, DestinationPixelX = DestinationX; for (SourcePixelX = SourceX, DestinationPixelX = DestinationX;
SourcePixelX < SourceX + Width; SourcePixelX < SourceX + Width;
SourcePixelX++, DestinationPixelX++) SourcePixelX++, DestinationPixelX++)
@ -635,22 +641,23 @@ BltBufferToVideo (
// Copy the pixel into the new target // Copy the pixel into the new target
// Only the most significant bits will be copied across: // Only the most significant bits will be copied across:
// To convert from 8 bits to 5 bits per pixel we throw away the 3 least significant bits // To convert from 8 bits to 5 bits per pixel we throw away the 3 least significant bits
*DestinationPixel16bit = (UINT16) ( *DestinationPixel16bit = (UINT16)(
( (EfiSourcePixel->Red << 7) & PixelInformation->RedMask ) ((EfiSourcePixel->Red << 7) & PixelInformation->RedMask)
| ( (EfiSourcePixel->Green << 2) & PixelInformation->GreenMask ) | ((EfiSourcePixel->Green << 2) & PixelInformation->GreenMask)
| ( (EfiSourcePixel->Blue >> 3) & PixelInformation->BlueMask ) | ((EfiSourcePixel->Blue >> 3) & PixelInformation->BlueMask)
// | ( 0 & PixelInformation->ReservedMask ) // | ( 0 & PixelInformation->ReservedMask )
); );
} }
} }
break; break;
case LcdBitsPerPixel_16_565: case LcdBitsPerPixel_16_565:
// Access each pixel inside the BltBuffer Memory // Access each pixel inside the BltBuffer Memory
for (SourceLine = SourceY, DestinationLine = DestinationY; for (SourceLine = SourceY, DestinationLine = DestinationY;
SourceLine < SourceY + Height; SourceLine < SourceY + Height;
SourceLine++, DestinationLine++) { SourceLine++, DestinationLine++)
{
for (SourcePixelX = SourceX, DestinationPixelX = DestinationX; for (SourcePixelX = SourceX, DestinationPixelX = DestinationX;
SourcePixelX < SourceX + Width; SourcePixelX < SourceX + Width;
SourcePixelX++, DestinationPixelX++) SourcePixelX++, DestinationPixelX++)
@ -663,21 +670,22 @@ BltBufferToVideo (
// Only the most significant bits will be copied across: // Only the most significant bits will be copied across:
// To convert from 8 bits to 5 or 6 bits per pixel we throw away the 3 or 2 least significant bits // To convert from 8 bits to 5 or 6 bits per pixel we throw away the 3 or 2 least significant bits
// There is no room for the Reserved byte so we ignore that completely // There is no room for the Reserved byte so we ignore that completely
*DestinationPixel16bit = (UINT16) ( *DestinationPixel16bit = (UINT16)(
( (EfiSourcePixel->Red << 8) & PixelInformation->RedMask ) ((EfiSourcePixel->Red << 8) & PixelInformation->RedMask)
| ( (EfiSourcePixel->Green << 3) & PixelInformation->GreenMask ) | ((EfiSourcePixel->Green << 3) & PixelInformation->GreenMask)
| ( (EfiSourcePixel->Blue >> 3) & PixelInformation->BlueMask ) | ((EfiSourcePixel->Blue >> 3) & PixelInformation->BlueMask)
); );
} }
} }
break; break;
case LcdBitsPerPixel_12_444: case LcdBitsPerPixel_12_444:
// Access each pixel inside the BltBuffer Memory // Access each pixel inside the BltBuffer Memory
for (SourceLine = SourceY, DestinationLine = DestinationY; for (SourceLine = SourceY, DestinationLine = DestinationY;
SourceLine < SourceY + Height; SourceLine < SourceY + Height;
SourceLine++, DestinationLine++) { SourceLine++, DestinationLine++)
{
for (SourcePixelX = SourceX, DestinationPixelX = DestinationX; for (SourcePixelX = SourceX, DestinationPixelX = DestinationX;
SourcePixelX < SourceX + Width; SourcePixelX < SourceX + Width;
SourcePixelX++, DestinationPixelX++) SourcePixelX++, DestinationPixelX++)
@ -689,14 +697,15 @@ BltBufferToVideo (
// Copy the pixel into the new target // Copy the pixel into the new target
// Only the most significant bits will be copied across: // Only the most significant bits will be copied across:
// To convert from 8 bits to 5 bits per pixel we throw away the 3 least significant bits // To convert from 8 bits to 5 bits per pixel we throw away the 3 least significant bits
*DestinationPixel16bit = (UINT16) ( *DestinationPixel16bit = (UINT16)(
( (EfiSourcePixel->Red << 4) & PixelInformation->RedMask ) ((EfiSourcePixel->Red << 4) & PixelInformation->RedMask)
| ( (EfiSourcePixel->Green ) & PixelInformation->GreenMask ) | ((EfiSourcePixel->Green) & PixelInformation->GreenMask)
| ( (EfiSourcePixel->Blue >> 4) & PixelInformation->BlueMask ) | ((EfiSourcePixel->Blue >> 4) & PixelInformation->BlueMask)
// | ( 0 & PixelInformation->ReservedMask ) // | ( 0 & PixelInformation->ReservedMask )
); );
} }
} }
break; break;
case LcdBitsPerPixel_8: case LcdBitsPerPixel_8:
@ -705,10 +714,11 @@ BltBufferToVideo (
case LcdBitsPerPixel_1: case LcdBitsPerPixel_1:
default: default:
// Can't handle this case // Can't handle this case
DEBUG((DEBUG_ERROR, "LcdGraphicsBlt: EfiBltBufferToVideo: INVALID Number of Bits Per Pixel: %d\n", BitsPerPixel)); DEBUG ((DEBUG_ERROR, "LcdGraphicsBlt: EfiBltBufferToVideo: INVALID Number of Bits Per Pixel: %d\n", BitsPerPixel));
Status = EFI_INVALID_PARAMETER; Status = EFI_INVALID_PARAMETER;
break; break;
} }
return Status; return Status;
} }
@ -740,27 +750,27 @@ BltVideoToVideo (
// Source is the Video Memory, // Source is the Video Memory,
// Destination is the Video Memory // Destination is the Video Memory
LcdPlatformGetBpp (This->Mode->Mode,&BitsPerPixel); LcdPlatformGetBpp (This->Mode->Mode, &BitsPerPixel);
FrameBufferBase = (UINTN *)((UINTN)(This->Mode->FrameBufferBase)); FrameBufferBase = (UINTN *)((UINTN)(This->Mode->FrameBufferBase));
// The UEFI spec currently states: // The UEFI spec currently states:
// "There is no limitation on the overlapping of the source and destination rectangles" // "There is no limitation on the overlapping of the source and destination rectangles"
// Therefore, we must be careful to avoid overwriting the source data // Therefore, we must be careful to avoid overwriting the source data
if( SourceY == DestinationY ) { if ( SourceY == DestinationY ) {
// Copying within the same height, e.g. horizontal shift // Copying within the same height, e.g. horizontal shift
if( SourceX == DestinationX ) { if ( SourceX == DestinationX ) {
// Nothing to do // Nothing to do
Status = EFI_SUCCESS; Status = EFI_SUCCESS;
} else if( ((SourceX>DestinationX)?(SourceX - DestinationX):(DestinationX - SourceX)) < Width ) { } else if (((SourceX > DestinationX) ? (SourceX - DestinationX) : (DestinationX - SourceX)) < Width ) {
// There is overlap // There is overlap
Status = VideoCopyHorizontalOverlap (BitsPerPixel, FrameBufferBase, HorizontalResolution, SourceX, SourceY, DestinationX, DestinationY, Width, Height ); Status = VideoCopyHorizontalOverlap (BitsPerPixel, FrameBufferBase, HorizontalResolution, SourceX, SourceY, DestinationX, DestinationY, Width, Height);
} else { } else {
// No overlap // No overlap
Status = VideoCopyNoHorizontalOverlap (BitsPerPixel, FrameBufferBase, HorizontalResolution, SourceX, SourceY, DestinationX, DestinationY, Width, Height ); Status = VideoCopyNoHorizontalOverlap (BitsPerPixel, FrameBufferBase, HorizontalResolution, SourceX, SourceY, DestinationX, DestinationY, Width, Height);
} }
} else { } else {
// Copying from different heights // Copying from different heights
Status = VideoCopyNoHorizontalOverlap (BitsPerPixel, FrameBufferBase, HorizontalResolution, SourceX, SourceY, DestinationX, DestinationY, Width, Height ); Status = VideoCopyNoHorizontalOverlap (BitsPerPixel, FrameBufferBase, HorizontalResolution, SourceX, SourceY, DestinationX, DestinationY, Width, Height);
} }
return Status; return Status;
@ -790,14 +800,14 @@ LcdGraphicsBlt (
EFI_STATUS Status; EFI_STATUS Status;
UINT32 HorizontalResolution; UINT32 HorizontalResolution;
UINT32 VerticalResolution; UINT32 VerticalResolution;
LCD_INSTANCE* Instance; LCD_INSTANCE *Instance;
Instance = LCD_INSTANCE_FROM_GOP_THIS(This); Instance = LCD_INSTANCE_FROM_GOP_THIS (This);
// Setup the hardware if not already done // Setup the hardware if not already done
if (!mDisplayInitialized) { if (!mDisplayInitialized) {
Status = InitializeDisplay (Instance); Status = InitializeDisplay (Instance);
if (EFI_ERROR(Status)) { if (EFI_ERROR (Status)) {
goto EXIT; goto EXIT;
} }
} }
@ -805,18 +815,27 @@ LcdGraphicsBlt (
HorizontalResolution = This->Mode->Info->HorizontalResolution; HorizontalResolution = This->Mode->Info->HorizontalResolution;
VerticalResolution = This->Mode->Info->VerticalResolution; VerticalResolution = This->Mode->Info->VerticalResolution;
DEBUG((DEBUG_INFO, "LcdGraphicsBlt (BltOperation:%d,DestX:%d,DestY:%d,Width:%d,Height:%d) res(%d,%d)\n", DEBUG ((
BltOperation,DestinationX,DestinationY,Width,Height,HorizontalResolution,VerticalResolution)); DEBUG_INFO,
"LcdGraphicsBlt (BltOperation:%d,DestX:%d,DestY:%d,Width:%d,Height:%d) res(%d,%d)\n",
BltOperation,
DestinationX,
DestinationY,
Width,
Height,
HorizontalResolution,
VerticalResolution
));
// Check we have reasonable parameters // Check we have reasonable parameters
if (Width == 0 || Height == 0) { if ((Width == 0) || (Height == 0)) {
DEBUG((DEBUG_ERROR, "LcdGraphicsBlt: ERROR - Invalid dimension: Zero size area.\n" )); DEBUG ((DEBUG_ERROR, "LcdGraphicsBlt: ERROR - Invalid dimension: Zero size area.\n"));
Status = EFI_INVALID_PARAMETER; Status = EFI_INVALID_PARAMETER;
goto EXIT; goto EXIT;
} }
if ((BltOperation == EfiBltVideoFill) || (BltOperation == EfiBltBufferToVideo) || (BltOperation == EfiBltVideoToBltBuffer)) { if ((BltOperation == EfiBltVideoFill) || (BltOperation == EfiBltBufferToVideo) || (BltOperation == EfiBltVideoToBltBuffer)) {
ASSERT( BltBuffer != NULL); ASSERT (BltBuffer != NULL);
} }
/*if ((DestinationX >= HorizontalResolution) || (DestinationY >= VerticalResolution)) { /*if ((DestinationX >= HorizontalResolution) || (DestinationY >= VerticalResolution)) {
@ -828,9 +847,9 @@ LcdGraphicsBlt (
// If we are reading data out of the video buffer, check that the source area is within the display limits // If we are reading data out of the video buffer, check that the source area is within the display limits
if ((BltOperation == EfiBltVideoToBltBuffer) || (BltOperation == EfiBltVideoToVideo)) { if ((BltOperation == EfiBltVideoToBltBuffer) || (BltOperation == EfiBltVideoToVideo)) {
if ((SourceY + Height > VerticalResolution) || (SourceX + Width > HorizontalResolution)) { if ((SourceY + Height > VerticalResolution) || (SourceX + Width > HorizontalResolution)) {
DEBUG((DEBUG_INFO, "LcdGraphicsBlt: ERROR - Invalid source resolution.\n" )); DEBUG ((DEBUG_INFO, "LcdGraphicsBlt: ERROR - Invalid source resolution.\n"));
DEBUG((DEBUG_INFO, " - SourceY=%d + Height=%d > VerticalResolution=%d.\n", SourceY, Height, VerticalResolution )); DEBUG ((DEBUG_INFO, " - SourceY=%d + Height=%d > VerticalResolution=%d.\n", SourceY, Height, VerticalResolution));
DEBUG((DEBUG_INFO, " - SourceX=%d + Width=%d > HorizontalResolution=%d.\n", SourceX, Width, HorizontalResolution )); DEBUG ((DEBUG_INFO, " - SourceX=%d + Width=%d > HorizontalResolution=%d.\n", SourceX, Width, HorizontalResolution));
Status = EFI_INVALID_PARAMETER; Status = EFI_INVALID_PARAMETER;
goto EXIT; goto EXIT;
} }
@ -839,9 +858,9 @@ LcdGraphicsBlt (
// If we are writing data into the video buffer, that the destination area is within the display limits // If we are writing data into the video buffer, that the destination area is within the display limits
if ((BltOperation == EfiBltVideoFill) || (BltOperation == EfiBltBufferToVideo) || (BltOperation == EfiBltVideoToVideo)) { if ((BltOperation == EfiBltVideoFill) || (BltOperation == EfiBltBufferToVideo) || (BltOperation == EfiBltVideoToVideo)) {
if ((DestinationY + Height > VerticalResolution) || (DestinationX + Width > HorizontalResolution)) { if ((DestinationY + Height > VerticalResolution) || (DestinationX + Width > HorizontalResolution)) {
DEBUG((DEBUG_INFO, "LcdGraphicsBlt: ERROR - Invalid destination resolution.\n" )); DEBUG ((DEBUG_INFO, "LcdGraphicsBlt: ERROR - Invalid destination resolution.\n"));
DEBUG((DEBUG_INFO, " - DestinationY=%d + Height=%d > VerticalResolution=%d.\n", DestinationY, Height, VerticalResolution )); DEBUG ((DEBUG_INFO, " - DestinationY=%d + Height=%d > VerticalResolution=%d.\n", DestinationY, Height, VerticalResolution));
DEBUG((DEBUG_INFO, " - DestinationX=%d + Width=%d > HorizontalResolution=%d.\n", DestinationX, Width, HorizontalResolution )); DEBUG ((DEBUG_INFO, " - DestinationX=%d + Width=%d > HorizontalResolution=%d.\n", DestinationX, Width, HorizontalResolution));
Status = EFI_INVALID_PARAMETER; Status = EFI_INVALID_PARAMETER;
goto EXIT; goto EXIT;
} }
@ -870,7 +889,7 @@ LcdGraphicsBlt (
case EfiGraphicsOutputBltOperationMax: case EfiGraphicsOutputBltOperationMax:
default: default:
DEBUG((DEBUG_ERROR, "LcdGraphicsBlt: Invalid Operation\n")); DEBUG ((DEBUG_ERROR, "LcdGraphicsBlt: Invalid Operation\n"));
Status = EFI_INVALID_PARAMETER; Status = EFI_INVALID_PARAMETER;
break; break;
} }

View File

@ -75,10 +75,10 @@ LCD_INSTANCE mLcdTemplate = {
EFI_STATUS EFI_STATUS
LcdInstanceContructor ( LcdInstanceContructor (
OUT LCD_INSTANCE** NewInstance OUT LCD_INSTANCE **NewInstance
) )
{ {
LCD_INSTANCE* Instance; LCD_INSTANCE *Instance;
Instance = AllocateCopyPool (sizeof (LCD_INSTANCE), &mLcdTemplate); Instance = AllocateCopyPool (sizeof (LCD_INSTANCE), &mLcdTemplate);
if (Instance == NULL) { if (Instance == NULL) {
@ -99,7 +99,7 @@ LcdInstanceContructor (
EFI_STATUS EFI_STATUS
InitializeDisplay ( InitializeDisplay (
IN LCD_INSTANCE* Instance IN LCD_INSTANCE *Instance
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
@ -149,7 +149,7 @@ LcdGraphicsOutputDxeInitialize (
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
LCD_INSTANCE* Instance; LCD_INSTANCE *Instance;
Status = LcdIdentify (); Status = LcdIdentify ();
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
@ -263,7 +263,8 @@ LcdGraphicsQueryMode (
if ((This == NULL) || if ((This == NULL) ||
(Info == NULL) || (Info == NULL) ||
(SizeOfInfo == NULL) || (SizeOfInfo == NULL) ||
(ModeNumber >= This->Mode->MaxMode)) { (ModeNumber >= This->Mode->MaxMode))
{
DEBUG ((DEBUG_ERROR, "LcdGraphicsQueryMode: ERROR - For mode number %d : Invalid Parameter.\n", ModeNumber)); DEBUG ((DEBUG_ERROR, "LcdGraphicsQueryMode: ERROR - For mode number %d : Invalid Parameter.\n", ModeNumber));
Status = EFI_INVALID_PARAMETER; Status = EFI_INVALID_PARAMETER;
goto EXIT; goto EXIT;
@ -298,7 +299,7 @@ LcdGraphicsSetMode (
{ {
EFI_STATUS Status; EFI_STATUS Status;
EFI_GRAPHICS_OUTPUT_BLT_PIXEL FillColour; EFI_GRAPHICS_OUTPUT_BLT_PIXEL FillColour;
LCD_INSTANCE* Instance; LCD_INSTANCE *Instance;
LCD_BPP Bpp; LCD_BPP Bpp;
Instance = LCD_INSTANCE_FROM_GOP_THIS (This); Instance = LCD_INSTANCE_FROM_GOP_THIS (This);
@ -333,6 +334,7 @@ LcdGraphicsSetMode (
DEBUG ((DEBUG_ERROR, "LcdGraphicsSetMode: ERROR - Couldn't get bytes per pixel, status: %r\n", Status)); DEBUG ((DEBUG_ERROR, "LcdGraphicsSetMode: ERROR - Couldn't get bytes per pixel, status: %r\n", Status));
goto EXIT; goto EXIT;
} }
This->Mode->FrameBufferSize = Instance->ModeInfo.VerticalResolution This->Mode->FrameBufferSize = Instance->ModeInfo.VerticalResolution
* Instance->ModeInfo.PixelsPerScanLine * Instance->ModeInfo.PixelsPerScanLine
* GetBytesPerPixel (Bpp); * GetBytesPerPixel (Bpp);

View File

@ -48,7 +48,7 @@ VOID
LcdGraphicsExitBootServicesEvent ( LcdGraphicsExitBootServicesEvent (
IN EFI_EVENT Event, IN EFI_EVENT Event,
IN VOID *Context IN VOID *Context
); );
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
@ -57,14 +57,14 @@ LcdGraphicsQueryMode (
IN UINT32 ModeNumber, IN UINT32 ModeNumber,
OUT UINTN *SizeOfInfo, OUT UINTN *SizeOfInfo,
OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION **Info OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION **Info
); );
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
LcdGraphicsSetMode ( LcdGraphicsSetMode (
IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This, IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
IN UINT32 ModeNumber IN UINT32 ModeNumber
); );
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
@ -79,7 +79,7 @@ LcdGraphicsBlt (
IN UINTN Width, IN UINTN Width,
IN UINTN Height, IN UINTN Height,
IN UINTN Delta OPTIONAL IN UINTN Delta OPTIONAL
); );
UINTN UINTN
GetBytesPerPixel ( GetBytesPerPixel (
@ -91,11 +91,11 @@ EFIAPI
GraphicsOutputDxeInitialize ( GraphicsOutputDxeInitialize (
IN EFI_HANDLE ImageHandle, IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable IN EFI_SYSTEM_TABLE *SystemTable
); );
EFI_STATUS EFI_STATUS
InitializeDisplay ( InitializeDisplay (
IN LCD_INSTANCE* Instance IN LCD_INSTANCE *Instance
); );
#endif /* LCD_GRAPHICS_OUTPUT_DXE_H_ */ #endif /* LCD_GRAPHICS_OUTPUT_DXE_H_ */

View File

@ -41,13 +41,13 @@ NorFlashBlockIsLocked (
SEND_NOR_COMMAND (BlockAddress, 2, P30_CMD_READ_DEVICE_ID); SEND_NOR_COMMAND (BlockAddress, 2, P30_CMD_READ_DEVICE_ID);
// Read block lock status // Read block lock status
LockStatus = MmioRead32 (CREATE_NOR_ADDRESS(BlockAddress, 2)); LockStatus = MmioRead32 (CREATE_NOR_ADDRESS (BlockAddress, 2));
// Decode block lock status // Decode block lock status
LockStatus = FOLD_32BIT_INTO_16BIT(LockStatus); LockStatus = FOLD_32BIT_INTO_16BIT (LockStatus);
if ((LockStatus & 0x2) != 0) { if ((LockStatus & 0x2) != 0) {
DEBUG((DEBUG_ERROR, "NorFlashBlockIsLocked: WARNING: Block LOCKED DOWN\n")); DEBUG ((DEBUG_ERROR, "NorFlashBlockIsLocked: WARNING: Block LOCKED DOWN\n"));
} }
return ((LockStatus & 0x1) != 0); return ((LockStatus & 0x1) != 0);
@ -77,10 +77,10 @@ NorFlashUnlockSingleBlock (
SEND_NOR_COMMAND (BlockAddress, 2, P30_CMD_READ_DEVICE_ID); SEND_NOR_COMMAND (BlockAddress, 2, P30_CMD_READ_DEVICE_ID);
// Read block lock status // Read block lock status
LockStatus = MmioRead32 (CREATE_NOR_ADDRESS(BlockAddress, 2)); LockStatus = MmioRead32 (CREATE_NOR_ADDRESS (BlockAddress, 2));
// Decode block lock status // Decode block lock status
LockStatus = FOLD_32BIT_INTO_16BIT(LockStatus); LockStatus = FOLD_32BIT_INTO_16BIT (LockStatus);
} while ((LockStatus & 0x1) == 1); } while ((LockStatus & 0x1) == 1);
} else { } else {
// Request a lock setup // Request a lock setup
@ -98,7 +98,7 @@ NorFlashUnlockSingleBlock (
// Put device back into Read Array mode // Put device back into Read Array mode
SEND_NOR_COMMAND (BlockAddress, 0, P30_CMD_READ_ARRAY); SEND_NOR_COMMAND (BlockAddress, 0, P30_CMD_READ_ARRAY);
DEBUG((DEBUG_BLKIO, "UnlockSingleBlock: BlockAddress=0x%08x\n", BlockAddress)); DEBUG ((DEBUG_BLKIO, "UnlockSingleBlock: BlockAddress=0x%08x\n", BlockAddress));
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -120,7 +120,6 @@ NorFlashUnlockSingleBlockIfNecessary (
return Status; return Status;
} }
/** /**
* The following function presumes that the block has already been unlocked. * The following function presumes that the block has already been unlocked.
**/ **/
@ -136,8 +135,8 @@ NorFlashEraseSingleBlock (
Status = EFI_SUCCESS; Status = EFI_SUCCESS;
// Request a block erase and then confirm it // Request a block erase and then confirm it
SEND_NOR_COMMAND(BlockAddress, 0, P30_CMD_BLOCK_ERASE_SETUP); SEND_NOR_COMMAND (BlockAddress, 0, P30_CMD_BLOCK_ERASE_SETUP);
SEND_NOR_COMMAND(BlockAddress, 0, P30_CMD_BLOCK_ERASE_CONFIRM); SEND_NOR_COMMAND (BlockAddress, 0, P30_CMD_BLOCK_ERASE_CONFIRM);
// Wait until the status register gives us the all clear // Wait until the status register gives us the all clear
do { do {
@ -145,27 +144,27 @@ NorFlashEraseSingleBlock (
} while ((StatusRegister & P30_SR_BIT_WRITE) != P30_SR_BIT_WRITE); } while ((StatusRegister & P30_SR_BIT_WRITE) != P30_SR_BIT_WRITE);
if (StatusRegister & P30_SR_BIT_VPP) { if (StatusRegister & P30_SR_BIT_VPP) {
DEBUG((DEBUG_ERROR,"EraseSingleBlock(BlockAddress=0x%08x: VPP Range Error\n", BlockAddress)); DEBUG ((DEBUG_ERROR, "EraseSingleBlock(BlockAddress=0x%08x: VPP Range Error\n", BlockAddress));
Status = EFI_DEVICE_ERROR; Status = EFI_DEVICE_ERROR;
} }
if ((StatusRegister & (P30_SR_BIT_ERASE | P30_SR_BIT_PROGRAM)) == (P30_SR_BIT_ERASE | P30_SR_BIT_PROGRAM)) { if ((StatusRegister & (P30_SR_BIT_ERASE | P30_SR_BIT_PROGRAM)) == (P30_SR_BIT_ERASE | P30_SR_BIT_PROGRAM)) {
DEBUG((DEBUG_ERROR,"EraseSingleBlock(BlockAddress=0x%08x: Command Sequence Error\n", BlockAddress)); DEBUG ((DEBUG_ERROR, "EraseSingleBlock(BlockAddress=0x%08x: Command Sequence Error\n", BlockAddress));
Status = EFI_DEVICE_ERROR; Status = EFI_DEVICE_ERROR;
} }
if (StatusRegister & P30_SR_BIT_ERASE) { if (StatusRegister & P30_SR_BIT_ERASE) {
DEBUG((DEBUG_ERROR,"EraseSingleBlock(BlockAddress=0x%08x: Block Erase Error StatusRegister:0x%X\n", BlockAddress, StatusRegister)); DEBUG ((DEBUG_ERROR, "EraseSingleBlock(BlockAddress=0x%08x: Block Erase Error StatusRegister:0x%X\n", BlockAddress, StatusRegister));
Status = EFI_DEVICE_ERROR; Status = EFI_DEVICE_ERROR;
} }
if (StatusRegister & P30_SR_BIT_BLOCK_LOCKED) { if (StatusRegister & P30_SR_BIT_BLOCK_LOCKED) {
// The debug level message has been reduced because a device lock might happen. In this case we just retry it ... // The debug level message has been reduced because a device lock might happen. In this case we just retry it ...
DEBUG((DEBUG_INFO,"EraseSingleBlock(BlockAddress=0x%08x: Block Locked Error\n", BlockAddress)); DEBUG ((DEBUG_INFO, "EraseSingleBlock(BlockAddress=0x%08x: Block Locked Error\n", BlockAddress));
Status = EFI_WRITE_PROTECTED; Status = EFI_WRITE_PROTECTED;
} }
if (EFI_ERROR(Status)) { if (EFI_ERROR (Status)) {
// Clear the Status Register // Clear the Status Register
SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_CLEAR_STATUS_REGISTER); SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_CLEAR_STATUS_REGISTER);
} }
@ -189,7 +188,7 @@ NorFlashWriteSingleWord (
Status = EFI_SUCCESS; Status = EFI_SUCCESS;
// Request a write single word command // Request a write single word command
SEND_NOR_COMMAND(WordAddress, 0, P30_CMD_WORD_PROGRAM_SETUP); SEND_NOR_COMMAND (WordAddress, 0, P30_CMD_WORD_PROGRAM_SETUP);
// Store the word into NOR Flash; // Store the word into NOR Flash;
MmioWrite32 (WordAddress, WriteData); MmioWrite32 (WordAddress, WriteData);
@ -201,27 +200,26 @@ NorFlashWriteSingleWord (
// The chip is busy while the WRITE bit is not asserted // The chip is busy while the WRITE bit is not asserted
} while ((StatusRegister & P30_SR_BIT_WRITE) != P30_SR_BIT_WRITE); } while ((StatusRegister & P30_SR_BIT_WRITE) != P30_SR_BIT_WRITE);
// Perform a full status check: // Perform a full status check:
// Mask the relevant bits of Status Register. // Mask the relevant bits of Status Register.
// Everything should be zero, if not, we have a problem // Everything should be zero, if not, we have a problem
if (StatusRegister & P30_SR_BIT_VPP) { if (StatusRegister & P30_SR_BIT_VPP) {
DEBUG((DEBUG_ERROR,"NorFlashWriteSingleWord(WordAddress:0x%X): VPP Range Error\n",WordAddress)); DEBUG ((DEBUG_ERROR, "NorFlashWriteSingleWord(WordAddress:0x%X): VPP Range Error\n", WordAddress));
Status = EFI_DEVICE_ERROR; Status = EFI_DEVICE_ERROR;
} }
if (StatusRegister & P30_SR_BIT_PROGRAM) { if (StatusRegister & P30_SR_BIT_PROGRAM) {
DEBUG((DEBUG_ERROR,"NorFlashWriteSingleWord(WordAddress:0x%X): Program Error\n",WordAddress)); DEBUG ((DEBUG_ERROR, "NorFlashWriteSingleWord(WordAddress:0x%X): Program Error\n", WordAddress));
Status = EFI_DEVICE_ERROR; Status = EFI_DEVICE_ERROR;
} }
if (StatusRegister & P30_SR_BIT_BLOCK_LOCKED) { if (StatusRegister & P30_SR_BIT_BLOCK_LOCKED) {
DEBUG((DEBUG_ERROR,"NorFlashWriteSingleWord(WordAddress:0x%X): Device Protect Error\n",WordAddress)); DEBUG ((DEBUG_ERROR, "NorFlashWriteSingleWord(WordAddress:0x%X): Device Protect Error\n", WordAddress));
Status = EFI_DEVICE_ERROR; Status = EFI_DEVICE_ERROR;
} }
if (!EFI_ERROR(Status)) { if (!EFI_ERROR (Status)) {
// Clear the Status Register // Clear the Status Register
SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_CLEAR_STATUS_REGISTER); SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_CLEAR_STATUS_REGISTER);
} }
@ -294,7 +292,7 @@ NorFlashWriteBuffer (
// Check the availability of the buffer // Check the availability of the buffer
do { do {
// Issue the Buffered Program Setup command // Issue the Buffered Program Setup command
SEND_NOR_COMMAND(TargetAddress, 0, P30_CMD_BUFFERED_PROGRAM_SETUP); SEND_NOR_COMMAND (TargetAddress, 0, P30_CMD_BUFFERED_PROGRAM_SETUP);
// Read back the status register bit#7 from the same address // Read back the status register bit#7 from the same address
if (((*Data) & P30_SR_BIT_WRITE) == P30_SR_BIT_WRITE) { if (((*Data) & P30_SR_BIT_WRITE) == P30_SR_BIT_WRITE) {
@ -303,7 +301,6 @@ NorFlashWriteBuffer (
// Update the loop counter // Update the loop counter
WaitForBuffer--; WaitForBuffer--;
} while ((WaitForBuffer > 0) && (BufferAvailable == FALSE)); } while ((WaitForBuffer > 0) && (BufferAvailable == FALSE));
// The buffer was not available for writing // The buffer was not available for writing
@ -317,10 +314,10 @@ NorFlashWriteBuffer (
// Write the word count, which is (buffer_size_in_words - 1), // Write the word count, which is (buffer_size_in_words - 1),
// because word count 0 means one word. // because word count 0 means one word.
SEND_NOR_COMMAND(TargetAddress, 0, (BufferSizeInWords - 1)); SEND_NOR_COMMAND (TargetAddress, 0, (BufferSizeInWords - 1));
// Write the data to the NOR Flash, advancing each address by 4 bytes // Write the data to the NOR Flash, advancing each address by 4 bytes
for(Count=0; Count < BufferSizeInWords; Count++, Data++, Buffer++) { for (Count = 0; Count < BufferSizeInWords; Count++, Data++, Buffer++) {
MmioWrite32 ((UINTN)Data, *Buffer); MmioWrite32 ((UINTN)Data, *Buffer);
} }
@ -333,7 +330,6 @@ NorFlashWriteBuffer (
// The chip is busy while the WRITE bit is not asserted // The chip is busy while the WRITE bit is not asserted
} while ((StatusRegister & P30_SR_BIT_WRITE) != P30_SR_BIT_WRITE); } while ((StatusRegister & P30_SR_BIT_WRITE) != P30_SR_BIT_WRITE);
// Perform a full status check: // Perform a full status check:
// Mask the relevant bits of Status Register. // Mask the relevant bits of Status Register.
// Everything should be zero, if not, we have a problem // Everything should be zero, if not, we have a problem
@ -341,21 +337,21 @@ NorFlashWriteBuffer (
Status = EFI_SUCCESS; Status = EFI_SUCCESS;
if (StatusRegister & P30_SR_BIT_VPP) { if (StatusRegister & P30_SR_BIT_VPP) {
DEBUG((DEBUG_ERROR,"NorFlashWriteBuffer(TargetAddress:0x%X): VPP Range Error\n", TargetAddress)); DEBUG ((DEBUG_ERROR, "NorFlashWriteBuffer(TargetAddress:0x%X): VPP Range Error\n", TargetAddress));
Status = EFI_DEVICE_ERROR; Status = EFI_DEVICE_ERROR;
} }
if (StatusRegister & P30_SR_BIT_PROGRAM) { if (StatusRegister & P30_SR_BIT_PROGRAM) {
DEBUG((DEBUG_ERROR,"NorFlashWriteBuffer(TargetAddress:0x%X): Program Error\n", TargetAddress)); DEBUG ((DEBUG_ERROR, "NorFlashWriteBuffer(TargetAddress:0x%X): Program Error\n", TargetAddress));
Status = EFI_DEVICE_ERROR; Status = EFI_DEVICE_ERROR;
} }
if (StatusRegister & P30_SR_BIT_BLOCK_LOCKED) { if (StatusRegister & P30_SR_BIT_BLOCK_LOCKED) {
DEBUG((DEBUG_ERROR,"NorFlashWriteBuffer(TargetAddress:0x%X): Device Protect Error\n",TargetAddress)); DEBUG ((DEBUG_ERROR, "NorFlashWriteBuffer(TargetAddress:0x%X): Device Protect Error\n", TargetAddress));
Status = EFI_DEVICE_ERROR; Status = EFI_DEVICE_ERROR;
} }
if (!EFI_ERROR(Status)) { if (!EFI_ERROR (Status)) {
// Clear the Status Register // Clear the Status Register
SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_CLEAR_STATUS_REGISTER); SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_CLEAR_STATUS_REGISTER);
} }
@ -389,29 +385,29 @@ NorFlashWriteBlocks (
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
if(Instance->Media.ReadOnly == TRUE) { if (Instance->Media.ReadOnly == TRUE) {
return EFI_WRITE_PROTECTED; return EFI_WRITE_PROTECTED;
} }
// We must have some bytes to read // We must have some bytes to read
DEBUG((DEBUG_BLKIO, "NorFlashWriteBlocks: BufferSizeInBytes=0x%x\n", BufferSizeInBytes)); DEBUG ((DEBUG_BLKIO, "NorFlashWriteBlocks: BufferSizeInBytes=0x%x\n", BufferSizeInBytes));
if(BufferSizeInBytes == 0) { if (BufferSizeInBytes == 0) {
return EFI_BAD_BUFFER_SIZE; return EFI_BAD_BUFFER_SIZE;
} }
// The size of the buffer must be a multiple of the block size // The size of the buffer must be a multiple of the block size
DEBUG((DEBUG_BLKIO, "NorFlashWriteBlocks: BlockSize in bytes =0x%x\n", Instance->Media.BlockSize)); DEBUG ((DEBUG_BLKIO, "NorFlashWriteBlocks: BlockSize in bytes =0x%x\n", Instance->Media.BlockSize));
if ((BufferSizeInBytes % Instance->Media.BlockSize) != 0) { if ((BufferSizeInBytes % Instance->Media.BlockSize) != 0) {
return EFI_BAD_BUFFER_SIZE; return EFI_BAD_BUFFER_SIZE;
} }
// All blocks must be within the device // All blocks must be within the device
NumBlocks = ((UINT32)BufferSizeInBytes) / Instance->Media.BlockSize ; NumBlocks = ((UINT32)BufferSizeInBytes) / Instance->Media.BlockSize;
DEBUG((DEBUG_BLKIO, "NorFlashWriteBlocks: NumBlocks=%d, LastBlock=%ld, Lba=%ld.\n", NumBlocks, Instance->Media.LastBlock, Lba)); DEBUG ((DEBUG_BLKIO, "NorFlashWriteBlocks: NumBlocks=%d, LastBlock=%ld, Lba=%ld.\n", NumBlocks, Instance->Media.LastBlock, Lba));
if ((Lba + NumBlocks) > (Instance->Media.LastBlock + 1)) { if ((Lba + NumBlocks) > (Instance->Media.LastBlock + 1)) {
DEBUG((DEBUG_ERROR, "NorFlashWriteBlocks: ERROR - Write will exceed last block.\n")); DEBUG ((DEBUG_ERROR, "NorFlashWriteBlocks: ERROR - Write will exceed last block.\n"));
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -422,18 +418,17 @@ NorFlashWriteBlocks (
pWriteBuffer = (UINT32 *)Buffer; pWriteBuffer = (UINT32 *)Buffer;
CurrentBlock = Lba; CurrentBlock = Lba;
for (BlockCount=0; BlockCount < NumBlocks; BlockCount++, CurrentBlock++, pWriteBuffer = pWriteBuffer + BlockSizeInWords) { for (BlockCount = 0; BlockCount < NumBlocks; BlockCount++, CurrentBlock++, pWriteBuffer = pWriteBuffer + BlockSizeInWords) {
DEBUG ((DEBUG_BLKIO, "NorFlashWriteBlocks: Writing block #%d\n", (UINTN)CurrentBlock));
DEBUG((DEBUG_BLKIO, "NorFlashWriteBlocks: Writing block #%d\n", (UINTN)CurrentBlock));
Status = NorFlashWriteFullBlock (Instance, CurrentBlock, pWriteBuffer, BlockSizeInWords); Status = NorFlashWriteFullBlock (Instance, CurrentBlock, pWriteBuffer, BlockSizeInWords);
if (EFI_ERROR(Status)) { if (EFI_ERROR (Status)) {
break; break;
} }
} }
DEBUG((DEBUG_BLKIO, "NorFlashWriteBlocks: Exit Status = \"%r\".\n", Status)); DEBUG ((DEBUG_BLKIO, "NorFlashWriteBlocks: Exit Status = \"%r\".\n", Status));
return Status; return Status;
} }
@ -466,7 +461,7 @@ AlignedCopyMem (
UINT64 *Destination64; UINT64 *Destination64;
CONST UINT64 *Source64; CONST UINT64 *Source64;
if (BOTH_ALIGNED(DestinationBuffer, SourceBuffer, 8) && Length >= 8) { if (BOTH_ALIGNED (DestinationBuffer, SourceBuffer, 8) && (Length >= 8)) {
Destination64 = DestinationBuffer; Destination64 = DestinationBuffer;
Source64 = SourceBuffer; Source64 = SourceBuffer;
while (Length >= 8) { while (Length >= 8) {
@ -476,7 +471,7 @@ AlignedCopyMem (
Destination8 = (UINT8 *)Destination64; Destination8 = (UINT8 *)Destination64;
Source8 = (CONST UINT8 *)Source64; Source8 = (CONST UINT8 *)Source64;
} else if (BOTH_ALIGNED(DestinationBuffer, SourceBuffer, 4) && Length >= 4) { } else if (BOTH_ALIGNED (DestinationBuffer, SourceBuffer, 4) && (Length >= 4)) {
Destination32 = DestinationBuffer; Destination32 = DestinationBuffer;
Source32 = SourceBuffer; Source32 = SourceBuffer;
while (Length >= 4) { while (Length >= 4) {
@ -490,9 +485,11 @@ AlignedCopyMem (
Destination8 = DestinationBuffer; Destination8 = DestinationBuffer;
Source8 = SourceBuffer; Source8 = SourceBuffer;
} }
while (Length-- != 0) { while (Length-- != 0) {
*Destination8++ = *Source8++; *Destination8++ = *Source8++;
} }
return DestinationBuffer; return DestinationBuffer;
} }
@ -507,8 +504,14 @@ NorFlashReadBlocks (
UINT32 NumBlocks; UINT32 NumBlocks;
UINTN StartAddress; UINTN StartAddress;
DEBUG((DEBUG_BLKIO, "NorFlashReadBlocks: BufferSize=0x%xB BlockSize=0x%xB LastBlock=%ld, Lba=%ld.\n", DEBUG ((
BufferSizeInBytes, Instance->Media.BlockSize, Instance->Media.LastBlock, Lba)); DEBUG_BLKIO,
"NorFlashReadBlocks: BufferSize=0x%xB BlockSize=0x%xB LastBlock=%ld, Lba=%ld.\n",
BufferSizeInBytes,
Instance->Media.BlockSize,
Instance->Media.LastBlock,
Lba
));
// The buffer must be valid // The buffer must be valid
if (Buffer == NULL) { if (Buffer == NULL) {
@ -526,15 +529,16 @@ NorFlashReadBlocks (
} }
// All blocks must be within the device // All blocks must be within the device
NumBlocks = ((UINT32)BufferSizeInBytes) / Instance->Media.BlockSize ; NumBlocks = ((UINT32)BufferSizeInBytes) / Instance->Media.BlockSize;
if ((Lba + NumBlocks) > (Instance->Media.LastBlock + 1)) { if ((Lba + NumBlocks) > (Instance->Media.LastBlock + 1)) {
DEBUG((DEBUG_ERROR, "NorFlashReadBlocks: ERROR - Read will exceed last block\n")); DEBUG ((DEBUG_ERROR, "NorFlashReadBlocks: ERROR - Read will exceed last block\n"));
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
// Get the address to start reading from // Get the address to start reading from
StartAddress = GET_NOR_BLOCK_ADDRESS (Instance->RegionBaseAddress, StartAddress = GET_NOR_BLOCK_ADDRESS (
Instance->RegionBaseAddress,
Lba, Lba,
Instance->Media.BlockSize Instance->Media.BlockSize
); );
@ -575,7 +579,8 @@ NorFlashRead (
} }
// Get the address to start reading from // Get the address to start reading from
StartAddress = GET_NOR_BLOCK_ADDRESS (Instance->RegionBaseAddress, StartAddress = GET_NOR_BLOCK_ADDRESS (
Instance->RegionBaseAddress,
Lba, Lba,
Instance->Media.BlockSize Instance->Media.BlockSize
); );
@ -631,16 +636,17 @@ NorFlashWriteSingleBlock (
// The write must not span block boundaries. // The write must not span block boundaries.
// We need to check each variable individually because adding two large values together overflows. // We need to check each variable individually because adding two large values together overflows.
if ( ( Offset >= BlockSize ) || if ((Offset >= BlockSize) ||
( *NumBytes > BlockSize ) || (*NumBytes > BlockSize) ||
( (Offset + *NumBytes) > BlockSize ) ) { ((Offset + *NumBytes) > BlockSize))
DEBUG ((DEBUG_ERROR, "NorFlashWriteSingleBlock: ERROR - EFI_BAD_BUFFER_SIZE: (Offset=0x%x + NumBytes=0x%x) > BlockSize=0x%x\n", Offset, *NumBytes, BlockSize )); {
DEBUG ((DEBUG_ERROR, "NorFlashWriteSingleBlock: ERROR - EFI_BAD_BUFFER_SIZE: (Offset=0x%x + NumBytes=0x%x) > BlockSize=0x%x\n", Offset, *NumBytes, BlockSize));
return EFI_BAD_BUFFER_SIZE; return EFI_BAD_BUFFER_SIZE;
} }
// We must have some bytes to write // We must have some bytes to write
if (*NumBytes == 0) { if (*NumBytes == 0) {
DEBUG ((DEBUG_ERROR, "NorFlashWriteSingleBlock: ERROR - EFI_BAD_BUFFER_SIZE: (Offset=0x%x + NumBytes=0x%x) > BlockSize=0x%x\n", Offset, *NumBytes, BlockSize )); DEBUG ((DEBUG_ERROR, "NorFlashWriteSingleBlock: ERROR - EFI_BAD_BUFFER_SIZE: (Offset=0x%x + NumBytes=0x%x) > BlockSize=0x%x\n", Offset, *NumBytes, BlockSize));
return EFI_BAD_BUFFER_SIZE; return EFI_BAD_BUFFER_SIZE;
} }
@ -659,16 +665,19 @@ NorFlashWriteSingleBlock (
while (BytesToWrite > 0) { while (BytesToWrite > 0) {
// Read full word from NOR, splice as required. A word is the smallest // Read full word from NOR, splice as required. A word is the smallest
// unit we can write. // unit we can write.
TempStatus = NorFlashRead (Instance, Lba, CurOffset & ~(0x3), sizeof(Tmp), &Tmp); TempStatus = NorFlashRead (Instance, Lba, CurOffset & ~(0x3), sizeof (Tmp), &Tmp);
if (EFI_ERROR (TempStatus)) { if (EFI_ERROR (TempStatus)) {
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
// Physical address of word in NOR to write. // Physical address of word in NOR to write.
WordAddr = (CurOffset & ~(0x3)) + GET_NOR_BLOCK_ADDRESS (Instance->RegionBaseAddress, WordAddr = (CurOffset & ~(0x3)) + GET_NOR_BLOCK_ADDRESS (
Lba, BlockSize); Instance->RegionBaseAddress,
Lba,
BlockSize
);
// The word of data that is to be written. // The word of data that is to be written.
TmpBuf = *((UINT32*)(Buffer + (*NumBytes - BytesToWrite))); TmpBuf = *((UINT32 *)(Buffer + (*NumBytes - BytesToWrite)));
// First do word aligned chunks. // First do word aligned chunks.
if ((CurOffset & 0x3) == 0) { if ((CurOffset & 0x3) == 0) {
@ -681,10 +690,11 @@ NorFlashWriteSingleBlock (
break; break;
} }
} }
// Write this word to NOR // Write this word to NOR
WordToWrite = TmpBuf; WordToWrite = TmpBuf;
CurOffset += sizeof(TmpBuf); CurOffset += sizeof (TmpBuf);
BytesToWrite -= sizeof(TmpBuf); BytesToWrite -= sizeof (TmpBuf);
} else { } else {
// BytesToWrite < 4. Do small writes and left-overs // BytesToWrite < 4. Do small writes and left-overs
Mask = ~((~0) << (BytesToWrite * 8)); Mask = ~((~0) << (BytesToWrite * 8));
@ -698,6 +708,7 @@ NorFlashWriteSingleBlock (
break; break;
} }
} }
// Merge old and new data. Write merged word to NOR // Merge old and new data. Write merged word to NOR
WordToWrite = (Tmp & ~Mask) | TmpBuf; WordToWrite = (Tmp & ~Mask) | TmpBuf;
CurOffset += BytesToWrite; CurOffset += BytesToWrite;
@ -717,6 +728,7 @@ NorFlashWriteSingleBlock (
break; break;
} }
} }
// Merge old and new data. Write merged word to NOR // Merge old and new data. Write merged word to NOR
WordToWrite = (Tmp & ~Mask) | TmpBuf; WordToWrite = (Tmp & ~Mask) | TmpBuf;
BytesToWrite -= (4 - (CurOffset & 0x3)); BytesToWrite -= (4 - (CurOffset & 0x3));
@ -734,6 +746,7 @@ NorFlashWriteSingleBlock (
break; break;
} }
} }
// Merge old and new data. Write merged word to NOR // Merge old and new data. Write merged word to NOR
WordToWrite = (Tmp & ~Mask) | TmpBuf; WordToWrite = (Tmp & ~Mask) | TmpBuf;
CurOffset += BytesToWrite; CurOffset += BytesToWrite;
@ -751,13 +764,16 @@ NorFlashWriteSingleBlock (
if (EFI_ERROR (TempStatus)) { if (EFI_ERROR (TempStatus)) {
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
PrevBlockAddress = BlockAddress; PrevBlockAddress = BlockAddress;
} }
TempStatus = NorFlashWriteSingleWord (Instance, WordAddr, WordToWrite); TempStatus = NorFlashWriteSingleWord (Instance, WordAddr, WordToWrite);
if (EFI_ERROR (TempStatus)) { if (EFI_ERROR (TempStatus)) {
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
} }
// Exit if we got here and could write all the data. Otherwise do the // Exit if we got here and could write all the data. Otherwise do the
// Erase-Write cycle. // Erase-Write cycle.
if (!DoErase) { if (!DoErase) {
@ -779,7 +795,7 @@ NorFlashWriteSingleBlock (
} }
// Put the data at the appropriate location inside the buffer area // Put the data at the appropriate location inside the buffer area
CopyMem ((VOID*)((UINTN)Instance->ShadowBuffer + Offset), Buffer, *NumBytes); CopyMem ((VOID *)((UINTN)Instance->ShadowBuffer + Offset), Buffer, *NumBytes);
// Write the modified buffer back to the NorFlash // Write the modified buffer back to the NorFlash
TempStatus = NorFlashWriteBlocks (Instance, Lba, BlockSize, Instance->ShadowBuffer); TempStatus = NorFlashWriteBlocks (Instance, Lba, BlockSize, Instance->ShadowBuffer);
@ -831,14 +847,14 @@ NorFlashDiskIoReadDisk (
UINT32 BlockOffset; UINT32 BlockOffset;
EFI_LBA Lba; EFI_LBA Lba;
Instance = INSTANCE_FROM_DISKIO_THIS(This); Instance = INSTANCE_FROM_DISKIO_THIS (This);
if (MediaId != Instance->Media.MediaId) { if (MediaId != Instance->Media.MediaId) {
return EFI_MEDIA_CHANGED; return EFI_MEDIA_CHANGED;
} }
BlockSize = Instance->Media.BlockSize; BlockSize = Instance->Media.BlockSize;
Lba = (EFI_LBA) DivU64x32Remainder (DiskOffset, BlockSize, &BlockOffset); Lba = (EFI_LBA)DivU64x32Remainder (DiskOffset, BlockSize, &BlockOffset);
return NorFlashRead (Instance, Lba, BlockOffset, BufferSize, Buffer); return NorFlashRead (Instance, Lba, BlockOffset, BufferSize, Buffer);
} }
@ -879,14 +895,14 @@ NorFlashDiskIoWriteDisk (
UINTN WriteSize; UINTN WriteSize;
EFI_STATUS Status; EFI_STATUS Status;
Instance = INSTANCE_FROM_DISKIO_THIS(This); Instance = INSTANCE_FROM_DISKIO_THIS (This);
if (MediaId != Instance->Media.MediaId) { if (MediaId != Instance->Media.MediaId) {
return EFI_MEDIA_CHANGED; return EFI_MEDIA_CHANGED;
} }
BlockSize = Instance->Media.BlockSize; BlockSize = Instance->Media.BlockSize;
Lba = (EFI_LBA) DivU64x32Remainder (DiskOffset, BlockSize, &BlockOffset); Lba = (EFI_LBA)DivU64x32Remainder (DiskOffset, BlockSize, &BlockOffset);
RemainingBytes = BufferSize; RemainingBytes = BufferSize;
@ -904,12 +920,14 @@ NorFlashDiskIoWriteDisk (
// Write a partial block // Write a partial block
Status = NorFlashWriteSingleBlock (Instance, Lba, BlockOffset, &WriteSize, Buffer); Status = NorFlashWriteSingleBlock (Instance, Lba, BlockOffset, &WriteSize, Buffer);
} }
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
// Now continue writing either all the remaining bytes or single blocks. // Now continue writing either all the remaining bytes or single blocks.
RemainingBytes -= WriteSize; RemainingBytes -= WriteSize;
Buffer = (UINT8 *) Buffer + WriteSize; Buffer = (UINT8 *)Buffer + WriteSize;
Lba++; Lba++;
BlockOffset = 0; BlockOffset = 0;
WriteSize = MIN (RemainingBytes, BlockSize); WriteSize = MIN (RemainingBytes, BlockSize);
@ -946,26 +964,26 @@ NorFlashVirtualNotifyEvent (
UINTN Index; UINTN Index;
for (Index = 0; Index < mNorFlashDeviceCount; Index++) { for (Index = 0; Index < mNorFlashDeviceCount; Index++) {
EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->DeviceBaseAddress); EfiConvertPointer (0x0, (VOID **)&mNorFlashInstances[Index]->DeviceBaseAddress);
EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->RegionBaseAddress); EfiConvertPointer (0x0, (VOID **)&mNorFlashInstances[Index]->RegionBaseAddress);
// Convert BlockIo protocol // Convert BlockIo protocol
EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->BlockIoProtocol.FlushBlocks); EfiConvertPointer (0x0, (VOID **)&mNorFlashInstances[Index]->BlockIoProtocol.FlushBlocks);
EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->BlockIoProtocol.ReadBlocks); EfiConvertPointer (0x0, (VOID **)&mNorFlashInstances[Index]->BlockIoProtocol.ReadBlocks);
EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->BlockIoProtocol.Reset); EfiConvertPointer (0x0, (VOID **)&mNorFlashInstances[Index]->BlockIoProtocol.Reset);
EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->BlockIoProtocol.WriteBlocks); EfiConvertPointer (0x0, (VOID **)&mNorFlashInstances[Index]->BlockIoProtocol.WriteBlocks);
// Convert Fvb // Convert Fvb
EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->FvbProtocol.EraseBlocks); EfiConvertPointer (0x0, (VOID **)&mNorFlashInstances[Index]->FvbProtocol.EraseBlocks);
EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->FvbProtocol.GetAttributes); EfiConvertPointer (0x0, (VOID **)&mNorFlashInstances[Index]->FvbProtocol.GetAttributes);
EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->FvbProtocol.GetBlockSize); EfiConvertPointer (0x0, (VOID **)&mNorFlashInstances[Index]->FvbProtocol.GetBlockSize);
EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->FvbProtocol.GetPhysicalAddress); EfiConvertPointer (0x0, (VOID **)&mNorFlashInstances[Index]->FvbProtocol.GetPhysicalAddress);
EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->FvbProtocol.Read); EfiConvertPointer (0x0, (VOID **)&mNorFlashInstances[Index]->FvbProtocol.Read);
EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->FvbProtocol.SetAttributes); EfiConvertPointer (0x0, (VOID **)&mNorFlashInstances[Index]->FvbProtocol.SetAttributes);
EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->FvbProtocol.Write); EfiConvertPointer (0x0, (VOID **)&mNorFlashInstances[Index]->FvbProtocol.Write);
if (mNorFlashInstances[Index]->ShadowBuffer != NULL) { if (mNorFlashInstances[Index]->ShadowBuffer != NULL) {
EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->ShadowBuffer); EfiConvertPointer (0x0, (VOID **)&mNorFlashInstances[Index]->ShadowBuffer);
} }
} }

View File

@ -9,7 +9,6 @@
#ifndef __NOR_FLASH_H__ #ifndef __NOR_FLASH_H__
#define __NOR_FLASH_H__ #define __NOR_FLASH_H__
#include <Base.h> #include <Base.h>
#include <PiDxe.h> #include <PiDxe.h>
@ -41,10 +40,10 @@
// Each command must be sent simultaneously to both chips, // Each command must be sent simultaneously to both chips,
// i.e. at the lower 16 bits AND at the higher 16 bits // i.e. at the lower 16 bits AND at the higher 16 bits
#define CREATE_NOR_ADDRESS(BaseAddr,OffsetAddr) ((BaseAddr) + ((OffsetAddr) << 2)) #define CREATE_NOR_ADDRESS(BaseAddr, OffsetAddr) ((BaseAddr) + ((OffsetAddr) << 2))
#define CREATE_DUAL_CMD(Cmd) ( ( Cmd << 16) | ( Cmd & LOW_16_BITS) ) #define CREATE_DUAL_CMD(Cmd) ( ( Cmd << 16) | ( Cmd & LOW_16_BITS) )
#define SEND_NOR_COMMAND(BaseAddr,Offset,Cmd) MmioWrite32 (CREATE_NOR_ADDRESS(BaseAddr,Offset), CREATE_DUAL_CMD(Cmd)) #define SEND_NOR_COMMAND(BaseAddr, Offset, Cmd) MmioWrite32 (CREATE_NOR_ADDRESS(BaseAddr,Offset), CREATE_DUAL_CMD(Cmd))
#define GET_NOR_BLOCK_ADDRESS(BaseAddr,Lba,LbaSize)( BaseAddr + (UINTN)((Lba) * LbaSize) ) #define GET_NOR_BLOCK_ADDRESS(BaseAddr, Lba, LbaSize) ( BaseAddr + (UINTN)((Lba) * LbaSize) )
// Status Register Bits // Status Register Bits
#define P30_SR_BIT_WRITE (BIT7 << 16 | BIT7) #define P30_SR_BIT_WRITE (BIT7 << 16 | BIT7)
@ -138,7 +137,7 @@ struct _NOR_FLASH_INSTANCE {
EFI_DISK_IO_PROTOCOL DiskIoProtocol; EFI_DISK_IO_PROTOCOL DiskIoProtocol;
EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL FvbProtocol; EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL FvbProtocol;
VOID* ShadowBuffer; VOID *ShadowBuffer;
NOR_FLASH_DEVICE_PATH DevicePath; NOR_FLASH_DEVICE_PATH DevicePath;
}; };
@ -180,7 +179,7 @@ NorFlashBlockIoReadBlocks (
IN EFI_LBA Lba, IN EFI_LBA Lba,
IN UINTN BufferSizeInBytes, IN UINTN BufferSizeInBytes,
OUT VOID *Buffer OUT VOID *Buffer
); );
// //
// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.WriteBlocks // BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.WriteBlocks
@ -193,7 +192,7 @@ NorFlashBlockIoWriteBlocks (
IN EFI_LBA Lba, IN EFI_LBA Lba,
IN UINTN BufferSizeInBytes, IN UINTN BufferSizeInBytes,
IN VOID *Buffer IN VOID *Buffer
); );
// //
// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.FlushBlocks // BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.FlushBlocks
@ -202,7 +201,7 @@ EFI_STATUS
EFIAPI EFIAPI
NorFlashBlockIoFlushBlocks ( NorFlashBlockIoFlushBlocks (
IN EFI_BLOCK_IO_PROTOCOL *This IN EFI_BLOCK_IO_PROTOCOL *This
); );
// //
// DiskIO Protocol function EFI_DISK_IO_PROTOCOL.ReadDisk // DiskIO Protocol function EFI_DISK_IO_PROTOCOL.ReadDisk
@ -236,28 +235,28 @@ NorFlashDiskIoWriteDisk (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
FvbGetAttributes( FvbGetAttributes (
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This, IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
OUT EFI_FVB_ATTRIBUTES_2 *Attributes OUT EFI_FVB_ATTRIBUTES_2 *Attributes
); );
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
FvbSetAttributes( FvbSetAttributes (
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This, IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
IN OUT EFI_FVB_ATTRIBUTES_2 *Attributes IN OUT EFI_FVB_ATTRIBUTES_2 *Attributes
); );
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
FvbGetPhysicalAddress( FvbGetPhysicalAddress (
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This, IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
OUT EFI_PHYSICAL_ADDRESS *Address OUT EFI_PHYSICAL_ADDRESS *Address
); );
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
FvbGetBlockSize( FvbGetBlockSize (
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This, IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
IN EFI_LBA Lba, IN EFI_LBA Lba,
OUT UINTN *BlockSize, OUT UINTN *BlockSize,
@ -266,7 +265,7 @@ FvbGetBlockSize(
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
FvbRead( FvbRead (
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This, IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
IN EFI_LBA Lba, IN EFI_LBA Lba,
IN UINTN Offset, IN UINTN Offset,
@ -276,7 +275,7 @@ FvbRead(
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
FvbWrite( FvbWrite (
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This, IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
IN EFI_LBA Lba, IN EFI_LBA Lba,
IN UINTN Offset, IN UINTN Offset,
@ -286,7 +285,7 @@ FvbWrite(
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
FvbEraseBlocks( FvbEraseBlocks (
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This, IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
... ...
); );
@ -334,16 +333,15 @@ NorFlashCreateInstance (
IN UINT32 Index, IN UINT32 Index,
IN UINT32 BlockSize, IN UINT32 BlockSize,
IN BOOLEAN SupportFvb, IN BOOLEAN SupportFvb,
OUT NOR_FLASH_INSTANCE** NorFlashInstance OUT NOR_FLASH_INSTANCE **NorFlashInstance
); );
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
NorFlashFvbInitialize ( NorFlashFvbInitialize (
IN NOR_FLASH_INSTANCE* Instance IN NOR_FLASH_INSTANCE *Instance
); );
// //
// NorFlash.c // NorFlash.c
// //

View File

@ -23,7 +23,7 @@ NorFlashBlockIoReset (
{ {
NOR_FLASH_INSTANCE *Instance; NOR_FLASH_INSTANCE *Instance;
Instance = INSTANCE_FROM_BLKIO_THIS(This); Instance = INSTANCE_FROM_BLKIO_THIS (This);
DEBUG ((DEBUG_BLKIO, "NorFlashBlockIoReset(MediaId=0x%x)\n", This->Media->MediaId)); DEBUG ((DEBUG_BLKIO, "NorFlashBlockIoReset(MediaId=0x%x)\n", This->Media->MediaId));
@ -51,7 +51,7 @@ NorFlashBlockIoReadBlocks (
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
Instance = INSTANCE_FROM_BLKIO_THIS(This); Instance = INSTANCE_FROM_BLKIO_THIS (This);
Media = This->Media; Media = This->Media;
DEBUG ((DEBUG_BLKIO, "NorFlashBlockIoReadBlocks(MediaId=0x%x, Lba=%ld, BufferSize=0x%x bytes (%d kB), BufferPtr @ 0x%08x)\n", MediaId, Lba, BufferSizeInBytes, Buffer)); DEBUG ((DEBUG_BLKIO, "NorFlashBlockIoReadBlocks(MediaId=0x%x, Lba=%ld, BufferSize=0x%x bytes (%d kB), BufferPtr @ 0x%08x)\n", MediaId, Lba, BufferSizeInBytes, Buffer));
@ -87,18 +87,18 @@ NorFlashBlockIoWriteBlocks (
NOR_FLASH_INSTANCE *Instance; NOR_FLASH_INSTANCE *Instance;
EFI_STATUS Status; EFI_STATUS Status;
Instance = INSTANCE_FROM_BLKIO_THIS(This); Instance = INSTANCE_FROM_BLKIO_THIS (This);
DEBUG ((DEBUG_BLKIO, "NorFlashBlockIoWriteBlocks(MediaId=0x%x, Lba=%ld, BufferSize=0x%x bytes (%d kB), BufferPtr @ 0x%08x)\n", MediaId, Lba, BufferSizeInBytes, Buffer)); DEBUG ((DEBUG_BLKIO, "NorFlashBlockIoWriteBlocks(MediaId=0x%x, Lba=%ld, BufferSize=0x%x bytes (%d kB), BufferPtr @ 0x%08x)\n", MediaId, Lba, BufferSizeInBytes, Buffer));
if( !This->Media->MediaPresent ) { if ( !This->Media->MediaPresent ) {
Status = EFI_NO_MEDIA; Status = EFI_NO_MEDIA;
} else if( This->Media->MediaId != MediaId ) { } else if ( This->Media->MediaId != MediaId ) {
Status = EFI_MEDIA_CHANGED; Status = EFI_MEDIA_CHANGED;
} else if( This->Media->ReadOnly ) { } else if ( This->Media->ReadOnly ) {
Status = EFI_WRITE_PROTECTED; Status = EFI_WRITE_PROTECTED;
} else { } else {
Status = NorFlashWriteBlocks (Instance,Lba,BufferSizeInBytes,Buffer); Status = NorFlashWriteBlocks (Instance, Lba, BufferSizeInBytes, Buffer);
} }
return Status; return Status;

View File

@ -56,7 +56,7 @@ NOR_FLASH_INSTANCE mNorFlashInstanceTemplate = {
0, // LastBlock ... NEED TO BE FILLED 0, // LastBlock ... NEED TO BE FILLED
0, // LowestAlignedLba 0, // LowestAlignedLba
1, // LogicalBlocksPerPhysicalBlock 1, // LogicalBlocksPerPhysicalBlock
}, //Media; }, // Media;
{ {
EFI_DISK_IO_PROTOCOL_REVISION, // Revision EFI_DISK_IO_PROTOCOL_REVISION, // Revision
@ -72,7 +72,7 @@ NOR_FLASH_INSTANCE mNorFlashInstanceTemplate = {
FvbRead, // Read FvbRead, // Read
FvbWrite, // Write FvbWrite, // Write
FvbEraseBlocks, // EraseBlocks FvbEraseBlocks, // EraseBlocks
NULL, //ParentHandle NULL, // ParentHandle
}, // FvbProtoccol; }, // FvbProtoccol;
NULL, // ShadowBuffer NULL, // ShadowBuffer
{ {
@ -85,7 +85,8 @@ NOR_FLASH_INSTANCE mNorFlashInstanceTemplate = {
(UINT8)(OFFSET_OF (NOR_FLASH_DEVICE_PATH, End) >> 8) (UINT8)(OFFSET_OF (NOR_FLASH_DEVICE_PATH, End) >> 8)
} }
}, },
{ 0x0, 0x0, 0x0, { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } }, // GUID ... NEED TO BE FILLED { 0x0, 0x0, 0x0, { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }
}, // GUID ... NEED TO BE FILLED
}, },
0, // Index 0, // Index
{ {
@ -104,15 +105,15 @@ NorFlashCreateInstance (
IN UINT32 Index, IN UINT32 Index,
IN UINT32 BlockSize, IN UINT32 BlockSize,
IN BOOLEAN SupportFvb, IN BOOLEAN SupportFvb,
OUT NOR_FLASH_INSTANCE** NorFlashInstance OUT NOR_FLASH_INSTANCE **NorFlashInstance
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
NOR_FLASH_INSTANCE* Instance; NOR_FLASH_INSTANCE *Instance;
ASSERT(NorFlashInstance != NULL); ASSERT (NorFlashInstance != NULL);
Instance = AllocateRuntimeCopyPool (sizeof(NOR_FLASH_INSTANCE),&mNorFlashInstanceTemplate); Instance = AllocateRuntimeCopyPool (sizeof (NOR_FLASH_INSTANCE), &mNorFlashInstanceTemplate);
if (Instance == NULL) { if (Instance == NULL) {
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
@ -129,7 +130,7 @@ NorFlashCreateInstance (
CopyGuid (&Instance->DevicePath.Vendor.Guid, &gEfiCallerIdGuid); CopyGuid (&Instance->DevicePath.Vendor.Guid, &gEfiCallerIdGuid);
Instance->DevicePath.Index = (UINT8)Index; Instance->DevicePath.Index = (UINT8)Index;
Instance->ShadowBuffer = AllocateRuntimePool (BlockSize);; Instance->ShadowBuffer = AllocateRuntimePool (BlockSize);
if (Instance->ShadowBuffer == NULL) { if (Instance->ShadowBuffer == NULL) {
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
@ -139,24 +140,30 @@ NorFlashCreateInstance (
Status = gBS->InstallMultipleProtocolInterfaces ( Status = gBS->InstallMultipleProtocolInterfaces (
&Instance->Handle, &Instance->Handle,
&gEfiDevicePathProtocolGuid, &Instance->DevicePath, &gEfiDevicePathProtocolGuid,
&gEfiBlockIoProtocolGuid, &Instance->BlockIoProtocol, &Instance->DevicePath,
&gEfiFirmwareVolumeBlockProtocolGuid, &Instance->FvbProtocol, &gEfiBlockIoProtocolGuid,
&Instance->BlockIoProtocol,
&gEfiFirmwareVolumeBlockProtocolGuid,
&Instance->FvbProtocol,
NULL NULL
); );
if (EFI_ERROR(Status)) { if (EFI_ERROR (Status)) {
FreePool (Instance); FreePool (Instance);
return Status; return Status;
} }
} else { } else {
Status = gBS->InstallMultipleProtocolInterfaces ( Status = gBS->InstallMultipleProtocolInterfaces (
&Instance->Handle, &Instance->Handle,
&gEfiDevicePathProtocolGuid, &Instance->DevicePath, &gEfiDevicePathProtocolGuid,
&gEfiBlockIoProtocolGuid, &Instance->BlockIoProtocol, &Instance->DevicePath,
&gEfiDiskIoProtocolGuid, &Instance->DiskIoProtocol, &gEfiBlockIoProtocolGuid,
&Instance->BlockIoProtocol,
&gEfiDiskIoProtocolGuid,
&Instance->DiskIoProtocol,
NULL NULL
); );
if (EFI_ERROR(Status)) { if (EFI_ERROR (Status)) {
FreePool (Instance); FreePool (Instance);
return Status; return Status;
} }
@ -196,12 +203,13 @@ NorFlashUnlockAndEraseSingleBlock (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
break; break;
} }
Status = NorFlashEraseSingleBlock (Instance, BlockAddress); Status = NorFlashEraseSingleBlock (Instance, BlockAddress);
Index++; Index++;
} while ((Index < NOR_FLASH_ERASE_RETRY) && (Status == EFI_WRITE_PROTECTED)); } while ((Index < NOR_FLASH_ERASE_RETRY) && (Status == EFI_WRITE_PROTECTED));
if (Index == NOR_FLASH_ERASE_RETRY) { if (Index == NOR_FLASH_ERASE_RETRY) {
DEBUG((DEBUG_ERROR,"EraseSingleBlock(BlockAddress=0x%08x: Block Locked Error (try to erase %d times)\n", BlockAddress,Index)); DEBUG ((DEBUG_ERROR, "EraseSingleBlock(BlockAddress=0x%08x: Block Locked Error (try to erase %d times)\n", BlockAddress, Index));
} }
if (!EfiAtRuntime ()) { if (!EfiAtRuntime ()) {
@ -248,8 +256,8 @@ NorFlashWriteFullBlock (
} }
Status = NorFlashUnlockAndEraseSingleBlock (Instance, BlockAddress); Status = NorFlashUnlockAndEraseSingleBlock (Instance, BlockAddress);
if (EFI_ERROR(Status)) { if (EFI_ERROR (Status)) {
DEBUG((DEBUG_ERROR, "WriteSingleBlock: ERROR - Failed to Unlock and Erase the single block at 0x%X\n", BlockAddress)); DEBUG ((DEBUG_ERROR, "WriteSingleBlock: ERROR - Failed to Unlock and Erase the single block at 0x%X\n", BlockAddress));
goto EXIT; goto EXIT;
} }
@ -257,25 +265,30 @@ NorFlashWriteFullBlock (
// Check that the address starts at a 32-word boundary, i.e. last 7 bits must be zero // Check that the address starts at a 32-word boundary, i.e. last 7 bits must be zero
if ((WordAddress & BOUNDARY_OF_32_WORDS) == 0x00) { if ((WordAddress & BOUNDARY_OF_32_WORDS) == 0x00) {
// First, break the entire block into buffer-sized chunks. // First, break the entire block into buffer-sized chunks.
BuffersInBlock = (UINTN)(BlockSizeInWords * 4) / P30_MAX_BUFFER_SIZE_IN_BYTES; BuffersInBlock = (UINTN)(BlockSizeInWords * 4) / P30_MAX_BUFFER_SIZE_IN_BYTES;
// Then feed each buffer chunk to the NOR Flash // Then feed each buffer chunk to the NOR Flash
// If a buffer does not contain any data, don't write it. // If a buffer does not contain any data, don't write it.
for(BufferIndex=0; for (BufferIndex = 0;
BufferIndex < BuffersInBlock; BufferIndex < BuffersInBlock;
BufferIndex++, WordAddress += P30_MAX_BUFFER_SIZE_IN_BYTES, DataBuffer += P30_MAX_BUFFER_SIZE_IN_WORDS BufferIndex++, WordAddress += P30_MAX_BUFFER_SIZE_IN_BYTES, DataBuffer += P30_MAX_BUFFER_SIZE_IN_WORDS
) { )
{
// Check the buffer to see if it contains any data (not set all 1s). // Check the buffer to see if it contains any data (not set all 1s).
for (Cnt = 0; Cnt < P30_MAX_BUFFER_SIZE_IN_WORDS; Cnt++) { for (Cnt = 0; Cnt < P30_MAX_BUFFER_SIZE_IN_WORDS; Cnt++) {
if (~DataBuffer[Cnt] != 0 ) { if (~DataBuffer[Cnt] != 0 ) {
// Some data found, write the buffer. // Some data found, write the buffer.
Status = NorFlashWriteBuffer (Instance, WordAddress, P30_MAX_BUFFER_SIZE_IN_BYTES, Status = NorFlashWriteBuffer (
DataBuffer); Instance,
if (EFI_ERROR(Status)) { WordAddress,
P30_MAX_BUFFER_SIZE_IN_BYTES,
DataBuffer
);
if (EFI_ERROR (Status)) {
goto EXIT; goto EXIT;
} }
break; break;
} }
} }
@ -284,20 +297,19 @@ NorFlashWriteFullBlock (
// Finally, finish off any remaining words that are less than the maximum size of the buffer // Finally, finish off any remaining words that are less than the maximum size of the buffer
RemainingWords = BlockSizeInWords % P30_MAX_BUFFER_SIZE_IN_WORDS; RemainingWords = BlockSizeInWords % P30_MAX_BUFFER_SIZE_IN_WORDS;
if(RemainingWords != 0) { if (RemainingWords != 0) {
Status = NorFlashWriteBuffer (Instance, WordAddress, (RemainingWords * 4), DataBuffer); Status = NorFlashWriteBuffer (Instance, WordAddress, (RemainingWords * 4), DataBuffer);
if (EFI_ERROR(Status)) { if (EFI_ERROR (Status)) {
goto EXIT; goto EXIT;
} }
} }
} else { } else {
// For now, use the single word programming algorithm // For now, use the single word programming algorithm
// It is unlikely that the NOR Flash will exist in an address which falls within a 32 word boundary range, // It is unlikely that the NOR Flash will exist in an address which falls within a 32 word boundary range,
// i.e. which ends in the range 0x......01 - 0x......7F. // i.e. which ends in the range 0x......01 - 0x......7F.
for(WordIndex=0; WordIndex<BlockSizeInWords; WordIndex++, DataBuffer++, WordAddress = WordAddress + 4) { for (WordIndex = 0; WordIndex < BlockSizeInWords; WordIndex++, DataBuffer++, WordAddress = WordAddress + 4) {
Status = NorFlashWriteSingleWord (Instance, WordAddress, *DataBuffer); Status = NorFlashWriteSingleWord (Instance, WordAddress, *DataBuffer);
if (EFI_ERROR(Status)) { if (EFI_ERROR (Status)) {
goto EXIT; goto EXIT;
} }
} }
@ -309,9 +321,10 @@ EXIT:
gBS->RestoreTPL (OriginalTPL); gBS->RestoreTPL (OriginalTPL);
} }
if (EFI_ERROR(Status)) { if (EFI_ERROR (Status)) {
DEBUG((DEBUG_ERROR, "NOR FLASH Programming [WriteSingleBlock] failed at address 0x%08x. Exit Status = \"%r\".\n", WordAddress, Status)); DEBUG ((DEBUG_ERROR, "NOR FLASH Programming [WriteSingleBlock] failed at address 0x%08x. Exit Status = \"%r\".\n", WordAddress, Status));
} }
return Status; return Status;
} }
@ -324,22 +337,22 @@ NorFlashInitialise (
{ {
EFI_STATUS Status; EFI_STATUS Status;
UINT32 Index; UINT32 Index;
NOR_FLASH_DESCRIPTION* NorFlashDevices; NOR_FLASH_DESCRIPTION *NorFlashDevices;
BOOLEAN ContainVariableStorage; BOOLEAN ContainVariableStorage;
Status = NorFlashPlatformInitialization (); Status = NorFlashPlatformInitialization ();
if (EFI_ERROR(Status)) { if (EFI_ERROR (Status)) {
DEBUG((DEBUG_ERROR,"NorFlashInitialise: Fail to initialize Nor Flash devices\n")); DEBUG ((DEBUG_ERROR, "NorFlashInitialise: Fail to initialize Nor Flash devices\n"));
return Status; return Status;
} }
Status = NorFlashPlatformGetDevices (&NorFlashDevices, &mNorFlashDeviceCount); Status = NorFlashPlatformGetDevices (&NorFlashDevices, &mNorFlashDeviceCount);
if (EFI_ERROR(Status)) { if (EFI_ERROR (Status)) {
DEBUG((DEBUG_ERROR,"NorFlashInitialise: Fail to get Nor Flash devices\n")); DEBUG ((DEBUG_ERROR, "NorFlashInitialise: Fail to get Nor Flash devices\n"));
return Status; return Status;
} }
mNorFlashInstances = AllocateRuntimePool (sizeof(NOR_FLASH_INSTANCE*) * mNorFlashDeviceCount); mNorFlashInstances = AllocateRuntimePool (sizeof (NOR_FLASH_INSTANCE *) * mNorFlashDeviceCount);
for (Index = 0; Index < mNorFlashDeviceCount; Index++) { for (Index = 0; Index < mNorFlashDeviceCount; Index++) {
// Check if this NOR Flash device contain the variable storage region // Check if this NOR Flash device contain the variable storage region
@ -365,8 +378,8 @@ NorFlashInitialise (
ContainVariableStorage, ContainVariableStorage,
&mNorFlashInstances[Index] &mNorFlashInstances[Index]
); );
if (EFI_ERROR(Status)) { if (EFI_ERROR (Status)) {
DEBUG((DEBUG_ERROR,"NorFlashInitialise: Fail to create instance for NorFlash[%d]\n",Index)); DEBUG ((DEBUG_ERROR, "NorFlashInitialise: Fail to create instance for NorFlash[%d]\n", Index));
} }
} }
@ -389,7 +402,7 @@ NorFlashInitialise (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
NorFlashFvbInitialize ( NorFlashFvbInitialize (
IN NOR_FLASH_INSTANCE* Instance IN NOR_FLASH_INSTANCE *Instance
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
@ -397,8 +410,8 @@ NorFlashFvbInitialize (
EFI_BOOT_MODE BootMode; EFI_BOOT_MODE BootMode;
UINTN RuntimeMmioRegionSize; UINTN RuntimeMmioRegionSize;
DEBUG((DEBUG_BLKIO,"NorFlashFvbInitialize\n")); DEBUG ((DEBUG_BLKIO, "NorFlashFvbInitialize\n"));
ASSERT((Instance != NULL)); ASSERT ((Instance != NULL));
// //
// Declare the Non-Volatile storage as EFI_MEMORY_RUNTIME // Declare the Non-Volatile storage as EFI_MEMORY_RUNTIME
@ -412,14 +425,17 @@ NorFlashFvbInitialize (
Status = gDS->AddMemorySpace ( Status = gDS->AddMemorySpace (
EfiGcdMemoryTypeMemoryMappedIo, EfiGcdMemoryTypeMemoryMappedIo,
Instance->DeviceBaseAddress, RuntimeMmioRegionSize, Instance->DeviceBaseAddress,
RuntimeMmioRegionSize,
EFI_MEMORY_UC | EFI_MEMORY_RUNTIME EFI_MEMORY_UC | EFI_MEMORY_RUNTIME
); );
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
Status = gDS->SetMemorySpaceAttributes ( Status = gDS->SetMemorySpaceAttributes (
Instance->DeviceBaseAddress, RuntimeMmioRegionSize, Instance->DeviceBaseAddress,
EFI_MEMORY_UC | EFI_MEMORY_RUNTIME); RuntimeMmioRegionSize,
EFI_MEMORY_UC | EFI_MEMORY_RUNTIME
);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
mFlashNvStorageVariableBase = (PcdGet64 (PcdFlashNvStorageVariableBase64) != 0) ? mFlashNvStorageVariableBase = (PcdGet64 (PcdFlashNvStorageVariableBase64) != 0) ?
@ -437,23 +453,26 @@ NorFlashFvbInitialize (
} }
// Install the Default FVB header if required // Install the Default FVB header if required
if (EFI_ERROR(Status)) { if (EFI_ERROR (Status)) {
// There is no valid header, so time to install one. // There is no valid header, so time to install one.
DEBUG ((DEBUG_INFO, "%a: The FVB Header is not valid.\n", __FUNCTION__)); DEBUG ((DEBUG_INFO, "%a: The FVB Header is not valid.\n", __FUNCTION__));
DEBUG ((DEBUG_INFO, "%a: Installing a correct one for this volume.\n", DEBUG ((
__FUNCTION__)); DEBUG_INFO,
"%a: Installing a correct one for this volume.\n",
__FUNCTION__
));
// Erase all the NorFlash that is reserved for variable storage // Erase all the NorFlash that is reserved for variable storage
FvbNumLba = (PcdGet32(PcdFlashNvStorageVariableSize) + PcdGet32(PcdFlashNvStorageFtwWorkingSize) + PcdGet32(PcdFlashNvStorageFtwSpareSize)) / Instance->Media.BlockSize; FvbNumLba = (PcdGet32 (PcdFlashNvStorageVariableSize) + PcdGet32 (PcdFlashNvStorageFtwWorkingSize) + PcdGet32 (PcdFlashNvStorageFtwSpareSize)) / Instance->Media.BlockSize;
Status = FvbEraseBlocks (&Instance->FvbProtocol, (EFI_LBA)0, FvbNumLba, EFI_LBA_LIST_TERMINATOR); Status = FvbEraseBlocks (&Instance->FvbProtocol, (EFI_LBA)0, FvbNumLba, EFI_LBA_LIST_TERMINATOR);
if (EFI_ERROR(Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
// Install all appropriate headers // Install all appropriate headers
Status = InitializeFvAndVariableStoreHeaders (Instance); Status = InitializeFvAndVariableStoreHeaders (Instance);
if (EFI_ERROR(Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
} }

View File

@ -44,7 +44,7 @@ InitializeFvAndVariableStoreHeaders (
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
VOID* Headers; VOID *Headers;
UINTN HeadersLength; UINTN HeadersLength;
EFI_FIRMWARE_VOLUME_HEADER *FirmwareVolumeHeader; EFI_FIRMWARE_VOLUME_HEADER *FirmwareVolumeHeader;
VARIABLE_STORE_HEADER *VariableStoreHeader; VARIABLE_STORE_HEADER *VariableStoreHeader;
@ -55,8 +55,8 @@ InitializeFvAndVariableStoreHeaders (
UINT64 NvStorageFtwWorkingBase; UINT64 NvStorageFtwWorkingBase;
UINT64 NvStorageVariableBase; UINT64 NvStorageVariableBase;
HeadersLength = sizeof(EFI_FIRMWARE_VOLUME_HEADER) + sizeof(EFI_FV_BLOCK_MAP_ENTRY) + sizeof(VARIABLE_STORE_HEADER); HeadersLength = sizeof (EFI_FIRMWARE_VOLUME_HEADER) + sizeof (EFI_FV_BLOCK_MAP_ENTRY) + sizeof (VARIABLE_STORE_HEADER);
Headers = AllocateZeroPool(HeadersLength); Headers = AllocateZeroPool (HeadersLength);
NvStorageFtwWorkingSize = PcdGet32 (PcdFlashNvStorageFtwWorkingSize); NvStorageFtwWorkingSize = PcdGet32 (PcdFlashNvStorageFtwWorkingSize);
NvStorageFtwSpareSize = PcdGet32 (PcdFlashNvStorageFtwSpareSize); NvStorageFtwSpareSize = PcdGet32 (PcdFlashNvStorageFtwSpareSize);
@ -71,40 +71,59 @@ InitializeFvAndVariableStoreHeaders (
// FirmwareVolumeHeader->FvLength is declared to have the Variable area AND the FTW working area AND the FTW Spare contiguous. // FirmwareVolumeHeader->FvLength is declared to have the Variable area AND the FTW working area AND the FTW Spare contiguous.
if ((NvStorageVariableBase + NvStorageVariableSize) != NvStorageFtwWorkingBase) { if ((NvStorageVariableBase + NvStorageVariableSize) != NvStorageFtwWorkingBase) {
DEBUG ((DEBUG_ERROR, "%a: NvStorageFtwWorkingBase is not contiguous with NvStorageVariableBase region\n", DEBUG ((
__FUNCTION__)); DEBUG_ERROR,
"%a: NvStorageFtwWorkingBase is not contiguous with NvStorageVariableBase region\n",
__FUNCTION__
));
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
if ((NvStorageFtwWorkingBase + NvStorageFtwWorkingSize) != NvStorageFtwSpareBase) { if ((NvStorageFtwWorkingBase + NvStorageFtwWorkingSize) != NvStorageFtwSpareBase) {
DEBUG ((DEBUG_ERROR, "%a: NvStorageFtwSpareBase is not contiguous with NvStorageFtwWorkingBase region\n", DEBUG ((
__FUNCTION__)); DEBUG_ERROR,
"%a: NvStorageFtwSpareBase is not contiguous with NvStorageFtwWorkingBase region\n",
__FUNCTION__
));
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
// Check if the size of the area is at least one block size // Check if the size of the area is at least one block size
if ((NvStorageVariableSize <= 0) || (NvStorageVariableSize / Instance->Media.BlockSize <= 0)) { if ((NvStorageVariableSize <= 0) || (NvStorageVariableSize / Instance->Media.BlockSize <= 0)) {
DEBUG ((DEBUG_ERROR, "%a: NvStorageVariableSize is 0x%x, should be atleast one block size\n", __FUNCTION__, DEBUG ((
NvStorageVariableSize)); DEBUG_ERROR,
"%a: NvStorageVariableSize is 0x%x, should be atleast one block size\n",
__FUNCTION__,
NvStorageVariableSize
));
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
if ((NvStorageFtwWorkingSize <= 0) || (NvStorageFtwWorkingSize / Instance->Media.BlockSize <= 0)) { if ((NvStorageFtwWorkingSize <= 0) || (NvStorageFtwWorkingSize / Instance->Media.BlockSize <= 0)) {
DEBUG ((DEBUG_ERROR, "%a: NvStorageFtwWorkingSize is 0x%x, should be atleast one block size\n", __FUNCTION__, DEBUG ((
NvStorageFtwWorkingSize)); DEBUG_ERROR,
"%a: NvStorageFtwWorkingSize is 0x%x, should be atleast one block size\n",
__FUNCTION__,
NvStorageFtwWorkingSize
));
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
if ((NvStorageFtwSpareSize <= 0) || (NvStorageFtwSpareSize / Instance->Media.BlockSize <= 0)) { if ((NvStorageFtwSpareSize <= 0) || (NvStorageFtwSpareSize / Instance->Media.BlockSize <= 0)) {
DEBUG ((DEBUG_ERROR, "%a: NvStorageFtwSpareSize is 0x%x, should be atleast one block size\n", __FUNCTION__, DEBUG ((
NvStorageFtwSpareSize)); DEBUG_ERROR,
"%a: NvStorageFtwSpareSize is 0x%x, should be atleast one block size\n",
__FUNCTION__,
NvStorageFtwSpareSize
));
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
// Ensure the Variable area Base Addresses are aligned on a block size boundaries // Ensure the Variable area Base Addresses are aligned on a block size boundaries
if ((NvStorageVariableBase % Instance->Media.BlockSize != 0) || if ((NvStorageVariableBase % Instance->Media.BlockSize != 0) ||
(NvStorageFtwWorkingBase % Instance->Media.BlockSize != 0) || (NvStorageFtwWorkingBase % Instance->Media.BlockSize != 0) ||
(NvStorageFtwSpareBase % Instance->Media.BlockSize != 0)) { (NvStorageFtwSpareBase % Instance->Media.BlockSize != 0))
{
DEBUG ((DEBUG_ERROR, "%a: NvStorage Base addresses must be aligned to block size boundaries", __FUNCTION__)); DEBUG ((DEBUG_ERROR, "%a: NvStorage Base addresses must be aligned to block size boundaries", __FUNCTION__));
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -112,14 +131,14 @@ InitializeFvAndVariableStoreHeaders (
// //
// EFI_FIRMWARE_VOLUME_HEADER // EFI_FIRMWARE_VOLUME_HEADER
// //
FirmwareVolumeHeader = (EFI_FIRMWARE_VOLUME_HEADER*)Headers; FirmwareVolumeHeader = (EFI_FIRMWARE_VOLUME_HEADER *)Headers;
CopyGuid (&FirmwareVolumeHeader->FileSystemGuid, &gEfiSystemNvDataFvGuid); CopyGuid (&FirmwareVolumeHeader->FileSystemGuid, &gEfiSystemNvDataFvGuid);
FirmwareVolumeHeader->FvLength = FirmwareVolumeHeader->FvLength =
PcdGet32(PcdFlashNvStorageVariableSize) + PcdGet32 (PcdFlashNvStorageVariableSize) +
PcdGet32(PcdFlashNvStorageFtwWorkingSize) + PcdGet32 (PcdFlashNvStorageFtwWorkingSize) +
PcdGet32(PcdFlashNvStorageFtwSpareSize); PcdGet32 (PcdFlashNvStorageFtwSpareSize);
FirmwareVolumeHeader->Signature = EFI_FVH_SIGNATURE; FirmwareVolumeHeader->Signature = EFI_FVH_SIGNATURE;
FirmwareVolumeHeader->Attributes = (EFI_FVB_ATTRIBUTES_2) ( FirmwareVolumeHeader->Attributes = (EFI_FVB_ATTRIBUTES_2)(
EFI_FVB2_READ_ENABLED_CAP | // Reads may be enabled EFI_FVB2_READ_ENABLED_CAP | // Reads may be enabled
EFI_FVB2_READ_STATUS | // Reads are currently enabled EFI_FVB2_READ_STATUS | // Reads are currently enabled
EFI_FVB2_STICKY_WRITE | // A block erase is required to flip bits into EFI_FVB2_ERASE_POLARITY EFI_FVB2_STICKY_WRITE | // A block erase is required to flip bits into EFI_FVB2_ERASE_POLARITY
@ -128,20 +147,20 @@ InitializeFvAndVariableStoreHeaders (
EFI_FVB2_WRITE_STATUS | // Writes are currently enabled EFI_FVB2_WRITE_STATUS | // Writes are currently enabled
EFI_FVB2_WRITE_ENABLED_CAP // Writes may be enabled EFI_FVB2_WRITE_ENABLED_CAP // Writes may be enabled
); );
FirmwareVolumeHeader->HeaderLength = sizeof(EFI_FIRMWARE_VOLUME_HEADER) + sizeof(EFI_FV_BLOCK_MAP_ENTRY); FirmwareVolumeHeader->HeaderLength = sizeof (EFI_FIRMWARE_VOLUME_HEADER) + sizeof (EFI_FV_BLOCK_MAP_ENTRY);
FirmwareVolumeHeader->Revision = EFI_FVH_REVISION; FirmwareVolumeHeader->Revision = EFI_FVH_REVISION;
FirmwareVolumeHeader->BlockMap[0].NumBlocks = Instance->Media.LastBlock + 1; FirmwareVolumeHeader->BlockMap[0].NumBlocks = Instance->Media.LastBlock + 1;
FirmwareVolumeHeader->BlockMap[0].Length = Instance->Media.BlockSize; FirmwareVolumeHeader->BlockMap[0].Length = Instance->Media.BlockSize;
FirmwareVolumeHeader->BlockMap[1].NumBlocks = 0; FirmwareVolumeHeader->BlockMap[1].NumBlocks = 0;
FirmwareVolumeHeader->BlockMap[1].Length = 0; FirmwareVolumeHeader->BlockMap[1].Length = 0;
FirmwareVolumeHeader->Checksum = CalculateCheckSum16 ((UINT16*)FirmwareVolumeHeader,FirmwareVolumeHeader->HeaderLength); FirmwareVolumeHeader->Checksum = CalculateCheckSum16 ((UINT16 *)FirmwareVolumeHeader, FirmwareVolumeHeader->HeaderLength);
// //
// VARIABLE_STORE_HEADER // VARIABLE_STORE_HEADER
// //
VariableStoreHeader = (VARIABLE_STORE_HEADER*)((UINTN)Headers + FirmwareVolumeHeader->HeaderLength); VariableStoreHeader = (VARIABLE_STORE_HEADER *)((UINTN)Headers + FirmwareVolumeHeader->HeaderLength);
CopyGuid (&VariableStoreHeader->Signature, &gEfiAuthenticatedVariableGuid); CopyGuid (&VariableStoreHeader->Signature, &gEfiAuthenticatedVariableGuid);
VariableStoreHeader->Size = PcdGet32(PcdFlashNvStorageVariableSize) - FirmwareVolumeHeader->HeaderLength; VariableStoreHeader->Size = PcdGet32 (PcdFlashNvStorageVariableSize) - FirmwareVolumeHeader->HeaderLength;
VariableStoreHeader->Format = VARIABLE_STORE_FORMATTED; VariableStoreHeader->Format = VARIABLE_STORE_FORMATTED;
VariableStoreHeader->State = VARIABLE_STORE_HEALTHY; VariableStoreHeader->State = VARIABLE_STORE_HEALTHY;
@ -172,10 +191,10 @@ ValidateFvHeader (
UINTN VariableStoreLength; UINTN VariableStoreLength;
UINTN FvLength; UINTN FvLength;
FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER*)Instance->RegionBaseAddress; FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *)Instance->RegionBaseAddress;
FvLength = PcdGet32(PcdFlashNvStorageVariableSize) + PcdGet32(PcdFlashNvStorageFtwWorkingSize) + FvLength = PcdGet32 (PcdFlashNvStorageVariableSize) + PcdGet32 (PcdFlashNvStorageFtwWorkingSize) +
PcdGet32(PcdFlashNvStorageFtwSpareSize); PcdGet32 (PcdFlashNvStorageFtwSpareSize);
// //
// Verify the header revision, header signature, length // Verify the header revision, header signature, length
@ -187,40 +206,57 @@ ValidateFvHeader (
|| (FwVolHeader->FvLength != FvLength) || (FwVolHeader->FvLength != FvLength)
) )
{ {
DEBUG ((DEBUG_INFO, "%a: No Firmware Volume header present\n", DEBUG ((
__FUNCTION__)); DEBUG_INFO,
"%a: No Firmware Volume header present\n",
__FUNCTION__
));
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
// Check the Firmware Volume Guid // Check the Firmware Volume Guid
if( CompareGuid (&FwVolHeader->FileSystemGuid, &gEfiSystemNvDataFvGuid) == FALSE ) { if ( CompareGuid (&FwVolHeader->FileSystemGuid, &gEfiSystemNvDataFvGuid) == FALSE ) {
DEBUG ((DEBUG_INFO, "%a: Firmware Volume Guid non-compatible\n", DEBUG ((
__FUNCTION__)); DEBUG_INFO,
"%a: Firmware Volume Guid non-compatible\n",
__FUNCTION__
));
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
// Verify the header checksum // Verify the header checksum
Checksum = CalculateSum16((UINT16*)FwVolHeader, FwVolHeader->HeaderLength); Checksum = CalculateSum16 ((UINT16 *)FwVolHeader, FwVolHeader->HeaderLength);
if (Checksum != 0) { if (Checksum != 0) {
DEBUG ((DEBUG_INFO, "%a: FV checksum is invalid (Checksum:0x%X)\n", DEBUG ((
__FUNCTION__, Checksum)); DEBUG_INFO,
"%a: FV checksum is invalid (Checksum:0x%X)\n",
__FUNCTION__,
Checksum
));
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
VariableStoreHeader = (VARIABLE_STORE_HEADER*)((UINTN)FwVolHeader + FwVolHeader->HeaderLength); VariableStoreHeader = (VARIABLE_STORE_HEADER *)((UINTN)FwVolHeader + FwVolHeader->HeaderLength);
// Check the Variable Store Guid // Check the Variable Store Guid
if (!CompareGuid (&VariableStoreHeader->Signature, &gEfiVariableGuid) && if (!CompareGuid (&VariableStoreHeader->Signature, &gEfiVariableGuid) &&
!CompareGuid (&VariableStoreHeader->Signature, &gEfiAuthenticatedVariableGuid)) { !CompareGuid (&VariableStoreHeader->Signature, &gEfiAuthenticatedVariableGuid))
DEBUG ((DEBUG_INFO, "%a: Variable Store Guid non-compatible\n", {
__FUNCTION__)); DEBUG ((
DEBUG_INFO,
"%a: Variable Store Guid non-compatible\n",
__FUNCTION__
));
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
VariableStoreLength = PcdGet32 (PcdFlashNvStorageVariableSize) - FwVolHeader->HeaderLength; VariableStoreLength = PcdGet32 (PcdFlashNvStorageVariableSize) - FwVolHeader->HeaderLength;
if (VariableStoreHeader->Size != VariableStoreLength) { if (VariableStoreHeader->Size != VariableStoreLength) {
DEBUG ((DEBUG_INFO, "%a: Variable Store Length does not match\n", DEBUG ((
__FUNCTION__)); DEBUG_INFO,
"%a: Variable Store Length does not match\n",
__FUNCTION__
));
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
@ -242,7 +278,7 @@ ValidateFvHeader (
**/ **/
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
FvbGetAttributes( FvbGetAttributes (
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This, IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
OUT EFI_FVB_ATTRIBUTES_2 *Attributes OUT EFI_FVB_ATTRIBUTES_2 *Attributes
) )
@ -250,9 +286,9 @@ FvbGetAttributes(
EFI_FVB_ATTRIBUTES_2 FlashFvbAttributes; EFI_FVB_ATTRIBUTES_2 FlashFvbAttributes;
NOR_FLASH_INSTANCE *Instance; NOR_FLASH_INSTANCE *Instance;
Instance = INSTANCE_FROM_FVB_THIS(This); Instance = INSTANCE_FROM_FVB_THIS (This);
FlashFvbAttributes = (EFI_FVB_ATTRIBUTES_2) ( FlashFvbAttributes = (EFI_FVB_ATTRIBUTES_2)(
EFI_FVB2_READ_ENABLED_CAP | // Reads may be enabled EFI_FVB2_READ_ENABLED_CAP | // Reads may be enabled
EFI_FVB2_READ_STATUS | // Reads are currently enabled EFI_FVB2_READ_STATUS | // Reads are currently enabled
@ -264,7 +300,6 @@ FvbGetAttributes(
// Check if it is write protected // Check if it is write protected
if (Instance->Media.ReadOnly != TRUE) { if (Instance->Media.ReadOnly != TRUE) {
FlashFvbAttributes = FlashFvbAttributes | FlashFvbAttributes = FlashFvbAttributes |
EFI_FVB2_WRITE_STATUS | // Writes are currently enabled EFI_FVB2_WRITE_STATUS | // Writes are currently enabled
EFI_FVB2_WRITE_ENABLED_CAP; // Writes may be enabled EFI_FVB2_WRITE_ENABLED_CAP; // Writes may be enabled
@ -298,12 +333,12 @@ FvbGetAttributes(
**/ **/
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
FvbSetAttributes( FvbSetAttributes (
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This, IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
IN OUT EFI_FVB_ATTRIBUTES_2 *Attributes IN OUT EFI_FVB_ATTRIBUTES_2 *Attributes
) )
{ {
DEBUG ((DEBUG_BLKIO, "FvbSetAttributes(0x%X) is not supported\n",*Attributes)); DEBUG ((DEBUG_BLKIO, "FvbSetAttributes(0x%X) is not supported\n", *Attributes));
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
@ -333,11 +368,11 @@ FvbGetPhysicalAddress (
{ {
NOR_FLASH_INSTANCE *Instance; NOR_FLASH_INSTANCE *Instance;
Instance = INSTANCE_FROM_FVB_THIS(This); Instance = INSTANCE_FROM_FVB_THIS (This);
DEBUG ((DEBUG_BLKIO, "FvbGetPhysicalAddress(BaseAddress=0x%08x)\n", Instance->RegionBaseAddress)); DEBUG ((DEBUG_BLKIO, "FvbGetPhysicalAddress(BaseAddress=0x%08x)\n", Instance->RegionBaseAddress));
ASSERT(Address != NULL); ASSERT (Address != NULL);
*Address = mFlashNvStorageVariableBase; *Address = mFlashNvStorageVariableBase;
return EFI_SUCCESS; return EFI_SUCCESS;
@ -381,7 +416,7 @@ FvbGetBlockSize (
EFI_STATUS Status; EFI_STATUS Status;
NOR_FLASH_INSTANCE *Instance; NOR_FLASH_INSTANCE *Instance;
Instance = INSTANCE_FROM_FVB_THIS(This); Instance = INSTANCE_FROM_FVB_THIS (This);
DEBUG ((DEBUG_BLKIO, "FvbGetBlockSize(Lba=%ld, BlockSize=0x%x, LastBlock=%ld)\n", Lba, Instance->Media.BlockSize, Instance->Media.LastBlock)); DEBUG ((DEBUG_BLKIO, "FvbGetBlockSize(Lba=%ld, BlockSize=0x%x, LastBlock=%ld)\n", Lba, Instance->Media.BlockSize, Instance->Media.LastBlock));
@ -390,8 +425,8 @@ FvbGetBlockSize (
Status = EFI_INVALID_PARAMETER; Status = EFI_INVALID_PARAMETER;
} else { } else {
// This is easy because in this platform each NorFlash device has equal sized blocks. // This is easy because in this platform each NorFlash device has equal sized blocks.
*BlockSize = (UINTN) Instance->Media.BlockSize; *BlockSize = (UINTN)Instance->Media.BlockSize;
*NumberOfBlocks = (UINTN) (Instance->Media.LastBlock - Lba + 1); *NumberOfBlocks = (UINTN)(Instance->Media.LastBlock - Lba + 1);
DEBUG ((DEBUG_BLKIO, "FvbGetBlockSize: *BlockSize=0x%x, *NumberOfBlocks=0x%x.\n", *BlockSize, *NumberOfBlocks)); DEBUG ((DEBUG_BLKIO, "FvbGetBlockSize: *BlockSize=0x%x, *NumberOfBlocks=0x%x.\n", *BlockSize, *NumberOfBlocks));
@ -456,7 +491,7 @@ FvbRead (
UINTN BlockSize; UINTN BlockSize;
NOR_FLASH_INSTANCE *Instance; NOR_FLASH_INSTANCE *Instance;
Instance = INSTANCE_FROM_FVB_THIS(This); Instance = INSTANCE_FROM_FVB_THIS (This);
DEBUG ((DEBUG_BLKIO, "FvbRead(Parameters: Lba=%ld, Offset=0x%x, *NumBytes=0x%x, Buffer @ 0x%08x)\n", Instance->StartLba + Lba, Offset, *NumBytes, Buffer)); DEBUG ((DEBUG_BLKIO, "FvbRead(Parameters: Lba=%ld, Offset=0x%x, *NumBytes=0x%x, Buffer @ 0x%08x)\n", Instance->StartLba + Lba, Offset, *NumBytes, Buffer));
@ -465,14 +500,15 @@ FvbRead (
// Cache the block size to avoid de-referencing pointers all the time // Cache the block size to avoid de-referencing pointers all the time
BlockSize = Instance->Media.BlockSize; BlockSize = Instance->Media.BlockSize;
DEBUG ((DEBUG_BLKIO, "FvbRead: Check if (Offset=0x%x + NumBytes=0x%x) <= BlockSize=0x%x\n", Offset, *NumBytes, BlockSize )); DEBUG ((DEBUG_BLKIO, "FvbRead: Check if (Offset=0x%x + NumBytes=0x%x) <= BlockSize=0x%x\n", Offset, *NumBytes, BlockSize));
// The read must not span block boundaries. // The read must not span block boundaries.
// We need to check each variable individually because adding two large values together overflows. // We need to check each variable individually because adding two large values together overflows.
if ((Offset >= BlockSize) || if ((Offset >= BlockSize) ||
(*NumBytes > BlockSize) || (*NumBytes > BlockSize) ||
((Offset + *NumBytes) > BlockSize)) { ((Offset + *NumBytes) > BlockSize))
DEBUG ((DEBUG_ERROR, "FvbRead: ERROR - EFI_BAD_BUFFER_SIZE: (Offset=0x%x + NumBytes=0x%x) > BlockSize=0x%x\n", Offset, *NumBytes, BlockSize )); {
DEBUG ((DEBUG_ERROR, "FvbRead: ERROR - EFI_BAD_BUFFER_SIZE: (Offset=0x%x + NumBytes=0x%x) > BlockSize=0x%x\n", Offset, *NumBytes, BlockSize));
return EFI_BAD_BUFFER_SIZE; return EFI_BAD_BUFFER_SIZE;
} }
@ -495,6 +531,7 @@ FvbRead (
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
} }
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -626,7 +663,7 @@ FvbEraseBlocks (
UINTN NumOfLba; // Number of Lba blocks to erase UINTN NumOfLba; // Number of Lba blocks to erase
NOR_FLASH_INSTANCE *Instance; NOR_FLASH_INSTANCE *Instance;
Instance = INSTANCE_FROM_FVB_THIS(This); Instance = INSTANCE_FROM_FVB_THIS (This);
DEBUG ((DEBUG_BLKIO, "FvbEraseBlocks()\n")); DEBUG ((DEBUG_BLKIO, "FvbEraseBlocks()\n"));
@ -648,7 +685,7 @@ FvbEraseBlocks (
// Have we reached the end of the list? // Have we reached the end of the list?
if (StartingLba == EFI_LBA_LIST_TERMINATOR) { if (StartingLba == EFI_LBA_LIST_TERMINATOR) {
//Exit the while loop // Exit the while loop
break; break;
} }
@ -670,6 +707,7 @@ FvbEraseBlocks (
goto EXIT; goto EXIT;
} }
} while (TRUE); } while (TRUE);
VA_END (Args); VA_END (Args);
// //
@ -691,7 +729,6 @@ FvbEraseBlocks (
// Go through each one and erase it // Go through each one and erase it
while (NumOfLba > 0) { while (NumOfLba > 0) {
// Get the physical address of Lba to erase // Get the physical address of Lba to erase
BlockAddress = GET_NOR_BLOCK_ADDRESS ( BlockAddress = GET_NOR_BLOCK_ADDRESS (
Instance->RegionBaseAddress, Instance->RegionBaseAddress,
@ -702,7 +739,7 @@ FvbEraseBlocks (
// Erase it // Erase it
DEBUG ((DEBUG_BLKIO, "FvbEraseBlocks: Erasing Lba=%ld @ 0x%08x.\n", Instance->StartLba + StartingLba, BlockAddress)); DEBUG ((DEBUG_BLKIO, "FvbEraseBlocks: Erasing Lba=%ld @ 0x%08x.\n", Instance->StartLba + StartingLba, BlockAddress));
Status = NorFlashUnlockAndEraseSingleBlock (Instance, BlockAddress); Status = NorFlashUnlockAndEraseSingleBlock (Instance, BlockAddress);
if (EFI_ERROR(Status)) { if (EFI_ERROR (Status)) {
VA_END (Args); VA_END (Args);
Status = EFI_DEVICE_ERROR; Status = EFI_DEVICE_ERROR;
goto EXIT; goto EXIT;
@ -713,6 +750,7 @@ FvbEraseBlocks (
NumOfLba--; NumOfLba--;
} }
} while (TRUE); } while (TRUE);
VA_END (Args); VA_END (Args);
EXIT: EXIT:
@ -734,6 +772,6 @@ FvbVirtualNotifyEvent (
IN VOID *Context IN VOID *Context
) )
{ {
EfiConvertPointer (0x0, (VOID**)&mFlashNvStorageVariableBase); EfiConvertPointer (0x0, (VOID **)&mFlashNvStorageVariableBase);
return; return;
} }

View File

@ -50,7 +50,7 @@ NOR_FLASH_INSTANCE mNorFlashInstanceTemplate = {
0, // LastBlock ... NEED TO BE FILLED 0, // LastBlock ... NEED TO BE FILLED
0, // LowestAlignedLba 0, // LowestAlignedLba
1, // LogicalBlocksPerPhysicalBlock 1, // LogicalBlocksPerPhysicalBlock
}, //Media; }, // Media;
{ {
EFI_DISK_IO_PROTOCOL_REVISION, // Revision EFI_DISK_IO_PROTOCOL_REVISION, // Revision
@ -66,7 +66,7 @@ NOR_FLASH_INSTANCE mNorFlashInstanceTemplate = {
FvbRead, // Read FvbRead, // Read
FvbWrite, // Write FvbWrite, // Write
FvbEraseBlocks, // EraseBlocks FvbEraseBlocks, // EraseBlocks
NULL, //ParentHandle NULL, // ParentHandle
}, // FvbProtoccol; }, // FvbProtoccol;
NULL, // ShadowBuffer NULL, // ShadowBuffer
{ {
@ -79,7 +79,8 @@ NOR_FLASH_INSTANCE mNorFlashInstanceTemplate = {
(UINT8)(OFFSET_OF (NOR_FLASH_DEVICE_PATH, End) >> 8) (UINT8)(OFFSET_OF (NOR_FLASH_DEVICE_PATH, End) >> 8)
} }
}, },
{ 0x0, 0x0, 0x0, { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } }, // GUID ... NEED TO BE FILLED { 0x0, 0x0, 0x0, { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }
}, // GUID ... NEED TO BE FILLED
}, },
0, // Index 0, // Index
{ {
@ -98,15 +99,15 @@ NorFlashCreateInstance (
IN UINT32 Index, IN UINT32 Index,
IN UINT32 BlockSize, IN UINT32 BlockSize,
IN BOOLEAN SupportFvb, IN BOOLEAN SupportFvb,
OUT NOR_FLASH_INSTANCE** NorFlashInstance OUT NOR_FLASH_INSTANCE **NorFlashInstance
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
NOR_FLASH_INSTANCE* Instance; NOR_FLASH_INSTANCE *Instance;
ASSERT(NorFlashInstance != NULL); ASSERT (NorFlashInstance != NULL);
Instance = AllocateRuntimeCopyPool (sizeof(NOR_FLASH_INSTANCE),&mNorFlashInstanceTemplate); Instance = AllocateRuntimeCopyPool (sizeof (NOR_FLASH_INSTANCE), &mNorFlashInstanceTemplate);
if (Instance == NULL) { if (Instance == NULL) {
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
@ -123,7 +124,7 @@ NorFlashCreateInstance (
CopyGuid (&Instance->DevicePath.Vendor.Guid, &gEfiCallerIdGuid); CopyGuid (&Instance->DevicePath.Vendor.Guid, &gEfiCallerIdGuid);
Instance->DevicePath.Index = (UINT8)Index; Instance->DevicePath.Index = (UINT8)Index;
Instance->ShadowBuffer = AllocateRuntimePool (BlockSize);; Instance->ShadowBuffer = AllocateRuntimePool (BlockSize);
if (Instance->ShadowBuffer == NULL) { if (Instance->ShadowBuffer == NULL) {
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
@ -137,12 +138,12 @@ NorFlashCreateInstance (
EFI_NATIVE_INTERFACE, EFI_NATIVE_INTERFACE,
&Instance->FvbProtocol &Instance->FvbProtocol
); );
if (EFI_ERROR(Status)) { if (EFI_ERROR (Status)) {
FreePool (Instance); FreePool (Instance);
return Status; return Status;
} }
} else { } else {
DEBUG((DEBUG_ERROR,"standalone MM NOR Flash driver only support FVB.\n")); DEBUG ((DEBUG_ERROR, "standalone MM NOR Flash driver only support FVB.\n"));
FreePool (Instance); FreePool (Instance);
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
@ -171,12 +172,13 @@ NorFlashUnlockAndEraseSingleBlock (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
break; break;
} }
Status = NorFlashEraseSingleBlock (Instance, BlockAddress); Status = NorFlashEraseSingleBlock (Instance, BlockAddress);
Index++; Index++;
} while ((Index < NOR_FLASH_ERASE_RETRY) && (Status == EFI_WRITE_PROTECTED)); } while ((Index < NOR_FLASH_ERASE_RETRY) && (Status == EFI_WRITE_PROTECTED));
if (Index == NOR_FLASH_ERASE_RETRY) { if (Index == NOR_FLASH_ERASE_RETRY) {
DEBUG((DEBUG_ERROR,"EraseSingleBlock(BlockAddress=0x%08x: Block Locked Error (try to erase %d times)\n", BlockAddress,Index)); DEBUG ((DEBUG_ERROR, "EraseSingleBlock(BlockAddress=0x%08x: Block Locked Error (try to erase %d times)\n", BlockAddress, Index));
} }
return Status; return Status;
@ -208,8 +210,8 @@ NorFlashWriteFullBlock (
WordAddress = BlockAddress; WordAddress = BlockAddress;
Status = NorFlashUnlockAndEraseSingleBlock (Instance, BlockAddress); Status = NorFlashUnlockAndEraseSingleBlock (Instance, BlockAddress);
if (EFI_ERROR(Status)) { if (EFI_ERROR (Status)) {
DEBUG((DEBUG_ERROR, "WriteSingleBlock: ERROR - Failed to Unlock and Erase the single block at 0x%X\n", BlockAddress)); DEBUG ((DEBUG_ERROR, "WriteSingleBlock: ERROR - Failed to Unlock and Erase the single block at 0x%X\n", BlockAddress));
goto EXIT; goto EXIT;
} }
@ -217,25 +219,30 @@ NorFlashWriteFullBlock (
// Check that the address starts at a 32-word boundary, i.e. last 7 bits must be zero // Check that the address starts at a 32-word boundary, i.e. last 7 bits must be zero
if ((WordAddress & BOUNDARY_OF_32_WORDS) == 0x00) { if ((WordAddress & BOUNDARY_OF_32_WORDS) == 0x00) {
// First, break the entire block into buffer-sized chunks. // First, break the entire block into buffer-sized chunks.
BuffersInBlock = (UINTN)(BlockSizeInWords * 4) / P30_MAX_BUFFER_SIZE_IN_BYTES; BuffersInBlock = (UINTN)(BlockSizeInWords * 4) / P30_MAX_BUFFER_SIZE_IN_BYTES;
// Then feed each buffer chunk to the NOR Flash // Then feed each buffer chunk to the NOR Flash
// If a buffer does not contain any data, don't write it. // If a buffer does not contain any data, don't write it.
for(BufferIndex=0; for (BufferIndex = 0;
BufferIndex < BuffersInBlock; BufferIndex < BuffersInBlock;
BufferIndex++, WordAddress += P30_MAX_BUFFER_SIZE_IN_BYTES, DataBuffer += P30_MAX_BUFFER_SIZE_IN_WORDS BufferIndex++, WordAddress += P30_MAX_BUFFER_SIZE_IN_BYTES, DataBuffer += P30_MAX_BUFFER_SIZE_IN_WORDS
) { )
{
// Check the buffer to see if it contains any data (not set all 1s). // Check the buffer to see if it contains any data (not set all 1s).
for (Cnt = 0; Cnt < P30_MAX_BUFFER_SIZE_IN_WORDS; Cnt++) { for (Cnt = 0; Cnt < P30_MAX_BUFFER_SIZE_IN_WORDS; Cnt++) {
if (~DataBuffer[Cnt] != 0 ) { if (~DataBuffer[Cnt] != 0 ) {
// Some data found, write the buffer. // Some data found, write the buffer.
Status = NorFlashWriteBuffer (Instance, WordAddress, P30_MAX_BUFFER_SIZE_IN_BYTES, Status = NorFlashWriteBuffer (
DataBuffer); Instance,
if (EFI_ERROR(Status)) { WordAddress,
P30_MAX_BUFFER_SIZE_IN_BYTES,
DataBuffer
);
if (EFI_ERROR (Status)) {
goto EXIT; goto EXIT;
} }
break; break;
} }
} }
@ -244,29 +251,29 @@ NorFlashWriteFullBlock (
// Finally, finish off any remaining words that are less than the maximum size of the buffer // Finally, finish off any remaining words that are less than the maximum size of the buffer
RemainingWords = BlockSizeInWords % P30_MAX_BUFFER_SIZE_IN_WORDS; RemainingWords = BlockSizeInWords % P30_MAX_BUFFER_SIZE_IN_WORDS;
if(RemainingWords != 0) { if (RemainingWords != 0) {
Status = NorFlashWriteBuffer (Instance, WordAddress, (RemainingWords * 4), DataBuffer); Status = NorFlashWriteBuffer (Instance, WordAddress, (RemainingWords * 4), DataBuffer);
if (EFI_ERROR(Status)) { if (EFI_ERROR (Status)) {
goto EXIT; goto EXIT;
} }
} }
} else { } else {
// For now, use the single word programming algorithm // For now, use the single word programming algorithm
// It is unlikely that the NOR Flash will exist in an address which falls within a 32 word boundary range, // It is unlikely that the NOR Flash will exist in an address which falls within a 32 word boundary range,
// i.e. which ends in the range 0x......01 - 0x......7F. // i.e. which ends in the range 0x......01 - 0x......7F.
for(WordIndex=0; WordIndex<BlockSizeInWords; WordIndex++, DataBuffer++, WordAddress = WordAddress + 4) { for (WordIndex = 0; WordIndex < BlockSizeInWords; WordIndex++, DataBuffer++, WordAddress = WordAddress + 4) {
Status = NorFlashWriteSingleWord (Instance, WordAddress, *DataBuffer); Status = NorFlashWriteSingleWord (Instance, WordAddress, *DataBuffer);
if (EFI_ERROR(Status)) { if (EFI_ERROR (Status)) {
goto EXIT; goto EXIT;
} }
} }
} }
EXIT: EXIT:
if (EFI_ERROR(Status)) { if (EFI_ERROR (Status)) {
DEBUG((DEBUG_ERROR, "NOR FLASH Programming [WriteSingleBlock] failed at address 0x%08x. Exit Status = \"%r\".\n", WordAddress, Status)); DEBUG ((DEBUG_ERROR, "NOR FLASH Programming [WriteSingleBlock] failed at address 0x%08x. Exit Status = \"%r\".\n", WordAddress, Status));
} }
return Status; return Status;
} }
@ -279,22 +286,22 @@ NorFlashInitialise (
{ {
EFI_STATUS Status; EFI_STATUS Status;
UINT32 Index; UINT32 Index;
NOR_FLASH_DESCRIPTION* NorFlashDevices; NOR_FLASH_DESCRIPTION *NorFlashDevices;
BOOLEAN ContainVariableStorage; BOOLEAN ContainVariableStorage;
Status = NorFlashPlatformInitialization (); Status = NorFlashPlatformInitialization ();
if (EFI_ERROR(Status)) { if (EFI_ERROR (Status)) {
DEBUG((DEBUG_ERROR,"NorFlashInitialise: Fail to initialize Nor Flash devices\n")); DEBUG ((DEBUG_ERROR, "NorFlashInitialise: Fail to initialize Nor Flash devices\n"));
return Status; return Status;
} }
Status = NorFlashPlatformGetDevices (&NorFlashDevices, &mNorFlashDeviceCount); Status = NorFlashPlatformGetDevices (&NorFlashDevices, &mNorFlashDeviceCount);
if (EFI_ERROR(Status)) { if (EFI_ERROR (Status)) {
DEBUG((DEBUG_ERROR,"NorFlashInitialise: Fail to get Nor Flash devices\n")); DEBUG ((DEBUG_ERROR, "NorFlashInitialise: Fail to get Nor Flash devices\n"));
return Status; return Status;
} }
mNorFlashInstances = AllocatePool (sizeof(NOR_FLASH_INSTANCE*) * mNorFlashDeviceCount); mNorFlashInstances = AllocatePool (sizeof (NOR_FLASH_INSTANCE *) * mNorFlashDeviceCount);
for (Index = 0; Index < mNorFlashDeviceCount; Index++) { for (Index = 0; Index < mNorFlashDeviceCount; Index++) {
// Check if this NOR Flash device contain the variable storage region // Check if this NOR Flash device contain the variable storage region
@ -320,8 +327,8 @@ NorFlashInitialise (
ContainVariableStorage, ContainVariableStorage,
&mNorFlashInstances[Index] &mNorFlashInstances[Index]
); );
if (EFI_ERROR(Status)) { if (EFI_ERROR (Status)) {
DEBUG((DEBUG_ERROR,"NorFlashInitialise: Fail to create instance for NorFlash[%d]\n",Index)); DEBUG ((DEBUG_ERROR, "NorFlashInitialise: Fail to create instance for NorFlash[%d]\n", Index));
} }
} }
@ -331,14 +338,13 @@ NorFlashInitialise (
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
NorFlashFvbInitialize ( NorFlashFvbInitialize (
IN NOR_FLASH_INSTANCE* Instance IN NOR_FLASH_INSTANCE *Instance
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
UINT32 FvbNumLba; UINT32 FvbNumLba;
ASSERT((Instance != NULL)); ASSERT ((Instance != NULL));
mFlashNvStorageVariableBase = (FixedPcdGet64 (PcdFlashNvStorageVariableBase64) != 0) ? mFlashNvStorageVariableBase = (FixedPcdGet64 (PcdFlashNvStorageVariableBase64) != 0) ?
FixedPcdGet64 (PcdFlashNvStorageVariableBase64) : FixedPcdGet32 (PcdFlashNvStorageVariableBase); FixedPcdGet64 (PcdFlashNvStorageVariableBase64) : FixedPcdGet32 (PcdFlashNvStorageVariableBase);
@ -349,23 +355,26 @@ NorFlashFvbInitialize (
Status = ValidateFvHeader (Instance); Status = ValidateFvHeader (Instance);
// Install the Default FVB header if required // Install the Default FVB header if required
if (EFI_ERROR(Status)) { if (EFI_ERROR (Status)) {
// There is no valid header, so time to install one. // There is no valid header, so time to install one.
DEBUG ((DEBUG_INFO, "%a: The FVB Header is not valid.\n", __FUNCTION__)); DEBUG ((DEBUG_INFO, "%a: The FVB Header is not valid.\n", __FUNCTION__));
DEBUG ((DEBUG_INFO, "%a: Installing a correct one for this volume.\n", DEBUG ((
__FUNCTION__)); DEBUG_INFO,
"%a: Installing a correct one for this volume.\n",
__FUNCTION__
));
// Erase all the NorFlash that is reserved for variable storage // Erase all the NorFlash that is reserved for variable storage
FvbNumLba = (PcdGet32(PcdFlashNvStorageVariableSize) + PcdGet32(PcdFlashNvStorageFtwWorkingSize) + PcdGet32(PcdFlashNvStorageFtwSpareSize)) / Instance->Media.BlockSize; FvbNumLba = (PcdGet32 (PcdFlashNvStorageVariableSize) + PcdGet32 (PcdFlashNvStorageFtwWorkingSize) + PcdGet32 (PcdFlashNvStorageFtwSpareSize)) / Instance->Media.BlockSize;
Status = FvbEraseBlocks (&Instance->FvbProtocol, (EFI_LBA)0, FvbNumLba, EFI_LBA_LIST_TERMINATOR); Status = FvbEraseBlocks (&Instance->FvbProtocol, (EFI_LBA)0, FvbNumLba, EFI_LBA_LIST_TERMINATOR);
if (EFI_ERROR(Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
// Install all appropriate headers // Install all appropriate headers
Status = InitializeFvAndVariableStoreHeaders (Instance); Status = InitializeFvAndVariableStoreHeaders (Instance);
if (EFI_ERROR(Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
} }

View File

@ -7,7 +7,6 @@
**/ **/
#include <PiDxe.h> #include <PiDxe.h>
#include <Library/BaseLib.h> #include <Library/BaseLib.h>
@ -40,13 +39,15 @@ PL061Locate (
for (Index = 0; Index < mPL061PlatformGpio->GpioControllerCount; Index++) { for (Index = 0; Index < mPL061PlatformGpio->GpioControllerCount; Index++) {
if ( (Gpio >= mPL061PlatformGpio->GpioController[Index].GpioIndex) if ( (Gpio >= mPL061PlatformGpio->GpioController[Index].GpioIndex)
&& (Gpio < mPL061PlatformGpio->GpioController[Index].GpioIndex && (Gpio < mPL061PlatformGpio->GpioController[Index].GpioIndex
+ mPL061PlatformGpio->GpioController[Index].InternalGpioCount)) { + mPL061PlatformGpio->GpioController[Index].InternalGpioCount))
{
*ControllerIndex = Index; *ControllerIndex = Index;
*ControllerOffset = Gpio % mPL061PlatformGpio->GpioController[Index].InternalGpioCount; *ControllerOffset = Gpio % mPL061PlatformGpio->GpioController[Index].InternalGpioCount;
*RegisterBase = mPL061PlatformGpio->GpioController[Index].RegisterBase; *RegisterBase = mPL061PlatformGpio->GpioController[Index].RegisterBase;
return EFI_SUCCESS; return EFI_SUCCESS;
} }
} }
DEBUG ((DEBUG_ERROR, "%a, failed to locate gpio %d\n", __func__, Gpio)); DEBUG ((DEBUG_ERROR, "%a, failed to locate gpio %d\n", __func__, Gpio));
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
@ -105,7 +106,6 @@ PL061SetPins (
/** /**
Function implementations Function implementations
**/ **/
EFI_STATUS EFI_STATUS
PL061Identify ( PL061Identify (
VOID VOID
@ -115,7 +115,8 @@ PL061Identify (
UINTN RegisterBase; UINTN RegisterBase;
if ( (mPL061PlatformGpio->GpioCount == 0) if ( (mPL061PlatformGpio->GpioCount == 0)
|| (mPL061PlatformGpio->GpioControllerCount == 0)) { || (mPL061PlatformGpio->GpioControllerCount == 0))
{
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
@ -130,7 +131,8 @@ PL061Identify (
if ( (MmioRead8 (RegisterBase + PL061_GPIO_PCELL_ID0) != 0x0D) if ( (MmioRead8 (RegisterBase + PL061_GPIO_PCELL_ID0) != 0x0D)
|| (MmioRead8 (RegisterBase + PL061_GPIO_PCELL_ID1) != 0xF0) || (MmioRead8 (RegisterBase + PL061_GPIO_PCELL_ID1) != 0xF0)
|| (MmioRead8 (RegisterBase + PL061_GPIO_PCELL_ID2) != 0x05) || (MmioRead8 (RegisterBase + PL061_GPIO_PCELL_ID2) != 0x05)
|| (MmioRead8 (RegisterBase + PL061_GPIO_PCELL_ID3) != 0xB1)) { || (MmioRead8 (RegisterBase + PL061_GPIO_PCELL_ID3) != 0xB1))
{
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
@ -138,7 +140,8 @@ PL061Identify (
if ( (MmioRead8 (RegisterBase + PL061_GPIO_PERIPH_ID0) != 0x61) if ( (MmioRead8 (RegisterBase + PL061_GPIO_PERIPH_ID0) != 0x61)
|| (MmioRead8 (RegisterBase + PL061_GPIO_PERIPH_ID1) != 0x10) || (MmioRead8 (RegisterBase + PL061_GPIO_PERIPH_ID1) != 0x10)
|| ((MmioRead8 (RegisterBase + PL061_GPIO_PERIPH_ID2) & 0xF) != 0x04) || ((MmioRead8 (RegisterBase + PL061_GPIO_PERIPH_ID2) & 0xF) != 0x04)
|| (MmioRead8 (RegisterBase + PL061_GPIO_PERIPH_ID3) != 0x00)) { || (MmioRead8 (RegisterBase + PL061_GPIO_PERIPH_ID3) != 0x00))
{
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
} }
@ -181,7 +184,7 @@ Get (
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
if (PL061GetPins (RegisterBase, GPIO_PIN_MASK(Offset)) != 0) { if (PL061GetPins (RegisterBase, GPIO_PIN_MASK (Offset)) != 0) {
*Value = 1; *Value = 1;
} else { } else {
*Value = 0; *Value = 0;
@ -222,26 +225,27 @@ Set (
Status = PL061Locate (Gpio, &Index, &Offset, &RegisterBase); Status = PL061Locate (Gpio, &Index, &Offset, &RegisterBase);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
switch (Mode) switch (Mode) {
{
case GPIO_MODE_INPUT: case GPIO_MODE_INPUT:
// Set the corresponding direction bit to LOW for input // Set the corresponding direction bit to LOW for input
MmioAnd8 (RegisterBase + PL061_GPIO_DIR_REG, MmioAnd8 (
~GPIO_PIN_MASK(Offset) & 0xFF); RegisterBase + PL061_GPIO_DIR_REG,
~GPIO_PIN_MASK(Offset) & 0xFF
);
break; break;
case GPIO_MODE_OUTPUT_0: case GPIO_MODE_OUTPUT_0:
// Set the corresponding direction bit to HIGH for output // Set the corresponding direction bit to HIGH for output
MmioOr8 (RegisterBase + PL061_GPIO_DIR_REG, GPIO_PIN_MASK(Offset)); MmioOr8 (RegisterBase + PL061_GPIO_DIR_REG, GPIO_PIN_MASK (Offset));
// Set the corresponding data bit to LOW for 0 // Set the corresponding data bit to LOW for 0
PL061SetPins (RegisterBase, GPIO_PIN_MASK(Offset), 0); PL061SetPins (RegisterBase, GPIO_PIN_MASK (Offset), 0);
break; break;
case GPIO_MODE_OUTPUT_1: case GPIO_MODE_OUTPUT_1:
// Set the corresponding direction bit to HIGH for output // Set the corresponding direction bit to HIGH for output
MmioOr8 (RegisterBase + PL061_GPIO_DIR_REG, GPIO_PIN_MASK(Offset)); MmioOr8 (RegisterBase + PL061_GPIO_DIR_REG, GPIO_PIN_MASK (Offset));
// Set the corresponding data bit to HIGH for 1 // Set the corresponding data bit to HIGH for 1
PL061SetPins (RegisterBase, GPIO_PIN_MASK(Offset), 0xff); PL061SetPins (RegisterBase, GPIO_PIN_MASK (Offset), 0xff);
break; break;
default: default:
@ -290,9 +294,9 @@ GetMode (
} }
// Check if it is input or output // Check if it is input or output
if (MmioRead8 (RegisterBase + PL061_GPIO_DIR_REG) & GPIO_PIN_MASK(Offset)) { if (MmioRead8 (RegisterBase + PL061_GPIO_DIR_REG) & GPIO_PIN_MASK (Offset)) {
// Pin set to output // Pin set to output
if (PL061GetPins (RegisterBase, GPIO_PIN_MASK(Offset)) != 0) { if (PL061GetPins (RegisterBase, GPIO_PIN_MASK (Offset)) != 0) {
*Mode = GPIO_MODE_OUTPUT_1; *Mode = GPIO_MODE_OUTPUT_1;
} else { } else {
*Mode = GPIO_MODE_OUTPUT_0; *Mode = GPIO_MODE_OUTPUT_0;
@ -381,27 +385,28 @@ PL061InstallProtocol (
mPL061PlatformGpio->GpioCount = PL061_GPIO_PINS; mPL061PlatformGpio->GpioCount = PL061_GPIO_PINS;
mPL061PlatformGpio->GpioControllerCount = 1; mPL061PlatformGpio->GpioControllerCount = 1;
mPL061PlatformGpio->GpioController = (GPIO_CONTROLLER *)((UINTN) mPL061PlatformGpio + sizeof (PLATFORM_GPIO_CONTROLLER)); mPL061PlatformGpio->GpioController = (GPIO_CONTROLLER *)((UINTN)mPL061PlatformGpio + sizeof (PLATFORM_GPIO_CONTROLLER));
GpioController = mPL061PlatformGpio->GpioController; GpioController = mPL061PlatformGpio->GpioController;
GpioController->RegisterBase = (UINTN) PcdGet32 (PcdPL061GpioBase); GpioController->RegisterBase = (UINTN)PcdGet32 (PcdPL061GpioBase);
GpioController->GpioIndex = 0; GpioController->GpioIndex = 0;
GpioController->InternalGpioCount = PL061_GPIO_PINS; GpioController->InternalGpioCount = PL061_GPIO_PINS;
} }
Status = PL061Identify(); Status = PL061Identify ();
if (EFI_ERROR(Status)) { if (EFI_ERROR (Status)) {
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
// Install the Embedded GPIO Protocol onto a new handle // Install the Embedded GPIO Protocol onto a new handle
Handle = NULL; Handle = NULL;
Status = gBS->InstallMultipleProtocolInterfaces( Status = gBS->InstallMultipleProtocolInterfaces (
&Handle, &Handle,
&gEmbeddedGpioProtocolGuid, &gGpio, &gEmbeddedGpioProtocolGuid,
&gGpio,
NULL NULL
); );
if (EFI_ERROR(Status)) { if (EFI_ERROR (Status)) {
Status = EFI_OUT_OF_RESOURCES; Status = EFI_OUT_OF_RESOURCES;
} }

View File

@ -6,7 +6,6 @@
**/ **/
#ifndef __PL061_GPIO_H__ #ifndef __PL061_GPIO_H__
#define __PL061_GPIO_H__ #define __PL061_GPIO_H__

View File

@ -7,7 +7,6 @@
**/ **/
#include <PiDxe.h> #include <PiDxe.h>
#include <Library/BaseLib.h> #include <Library/BaseLib.h>
@ -175,11 +174,11 @@ SP805RegisterHandler (
IN EFI_WATCHDOG_TIMER_NOTIFY NotifyFunction IN EFI_WATCHDOG_TIMER_NOTIFY NotifyFunction
) )
{ {
if (mWatchdogNotify == NULL && NotifyFunction == NULL) { if ((mWatchdogNotify == NULL) && (NotifyFunction == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
if (mWatchdogNotify != NULL && NotifyFunction != NULL) { if ((mWatchdogNotify != NULL) && (NotifyFunction != NULL)) {
return EFI_ALREADY_STARTED; return EFI_ALREADY_STARTED;
} }
@ -363,8 +362,11 @@ SP805Initialize (
EFI_HANDLE Handle; EFI_HANDLE Handle;
// Find the interrupt controller protocol. ASSERT if not found. // Find the interrupt controller protocol. ASSERT if not found.
Status = gBS->LocateProtocol (&gHardwareInterruptProtocolGuid, NULL, Status = gBS->LocateProtocol (
(VOID **)&mInterrupt); &gHardwareInterruptProtocolGuid,
NULL,
(VOID **)&mInterrupt
);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
// Unlock access to the SP805 registers // Unlock access to the SP805 registers
@ -386,17 +388,26 @@ SP805Initialize (
SP805Lock (); SP805Lock ();
if (PcdGet32 (PcdSP805WatchdogInterrupt) > 0) { if (PcdGet32 (PcdSP805WatchdogInterrupt) > 0) {
Status = mInterrupt->RegisterInterruptSource (mInterrupt, Status = mInterrupt->RegisterInterruptSource (
mInterrupt,
PcdGet32 (PcdSP805WatchdogInterrupt), PcdGet32 (PcdSP805WatchdogInterrupt),
SP805InterruptHandler); SP805InterruptHandler
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: failed to register watchdog interrupt - %r\n", DEBUG ((
__FUNCTION__, Status)); DEBUG_ERROR,
"%a: failed to register watchdog interrupt - %r\n",
__FUNCTION__,
Status
));
return Status; return Status;
} }
} else { } else {
DEBUG ((DEBUG_WARN, "%a: no interrupt specified, running in RESET mode only\n", DEBUG ((
__FUNCTION__)); DEBUG_WARN,
"%a: no interrupt specified, running in RESET mode only\n",
__FUNCTION__
));
} }
// //
@ -406,8 +417,13 @@ SP805Initialize (
ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiWatchdogTimerArchProtocolGuid); ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiWatchdogTimerArchProtocolGuid);
// Register for an ExitBootServicesEvent // Register for an ExitBootServicesEvent
Status = gBS->CreateEvent (EVT_SIGNAL_EXIT_BOOT_SERVICES, TPL_NOTIFY, Status = gBS->CreateEvent (
ExitBootServicesEvent, NULL, &mEfiExitBootServicesEvent); EVT_SIGNAL_EXIT_BOOT_SERVICES,
TPL_NOTIFY,
ExitBootServicesEvent,
NULL,
&mEfiExitBootServicesEvent
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
Status = EFI_OUT_OF_RESOURCES; Status = EFI_OUT_OF_RESOURCES;
goto EXIT; goto EXIT;
@ -417,7 +433,8 @@ SP805Initialize (
Handle = NULL; Handle = NULL;
Status = gBS->InstallMultipleProtocolInterfaces ( Status = gBS->InstallMultipleProtocolInterfaces (
&Handle, &Handle,
&gEfiWatchdogTimerArchProtocolGuid, &mWatchdogTimer, &gEfiWatchdogTimerArchProtocolGuid,
&mWatchdogTimer,
NULL NULL
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {

View File

@ -6,7 +6,6 @@
**/ **/
#ifndef __SP805_WATCHDOG_H__ #ifndef __SP805_WATCHDOG_H__
#define __SP805_WATCHDOG_H__ #define __SP805_WATCHDOG_H__

View File

@ -117,7 +117,7 @@ ArmPlatformInitialize (
**/ **/
VOID VOID
ArmPlatformGetVirtualMemoryMap ( ArmPlatformGetVirtualMemoryMap (
OUT ARM_MEMORY_REGION_DESCRIPTOR** VirtualMemoryMap OUT ARM_MEMORY_REGION_DESCRIPTOR **VirtualMemoryMap
); );
/** /**

View File

@ -242,8 +242,8 @@ LcdPlatformInitializeDisplay (
**/ **/
EFI_STATUS EFI_STATUS
LcdPlatformGetVram ( LcdPlatformGetVram (
OUT EFI_PHYSICAL_ADDRESS* VramBaseAddress, OUT EFI_PHYSICAL_ADDRESS *VramBaseAddress,
OUT UINTN* VramSize OUT UINTN *VramSize
); );
/** Return total number of modes supported. /** Return total number of modes supported.
@ -321,7 +321,7 @@ LcdPlatformGetTimings (
EFI_STATUS EFI_STATUS
LcdPlatformGetBpp ( LcdPlatformGetBpp (
IN UINT32 ModeNumber, IN UINT32 ModeNumber,
OUT LCD_BPP* Bpp OUT LCD_BPP *Bpp
); );
#endif /* LCD_PLATFORM_LIB_H_ */ #endif /* LCD_PLATFORM_LIB_H_ */

View File

@ -25,7 +25,9 @@ STATIC UINT32 mDpDeviceId;
**/ **/
STATIC STATIC
VOID VOID
LayerGraphicsDisable (VOID) LayerGraphicsDisable (
VOID
)
{ {
MmioAnd32 (DP_BASE + DP_DE_LG_CONTROL, ~DP_DE_LG_ENABLE); MmioAnd32 (DP_BASE + DP_DE_LG_CONTROL, ~DP_DE_LG_ENABLE);
} }
@ -36,7 +38,9 @@ LayerGraphicsDisable (VOID)
**/ **/
STATIC STATIC
VOID VOID
LayerGraphicsEnable (VOID) LayerGraphicsEnable (
VOID
)
{ {
MmioOr32 (DP_BASE + DP_DE_LG_CONTROL, DP_DE_LG_ENABLE); MmioOr32 (DP_BASE + DP_DE_LG_CONTROL, DP_DE_LG_ENABLE);
} }
@ -134,8 +138,8 @@ LayerGraphicsConfig (
STATIC STATIC
VOID VOID
SetDisplayEngineTiming ( SetDisplayEngineTiming (
IN CONST SCAN_TIMINGS * CONST Horizontal, IN CONST SCAN_TIMINGS *CONST Horizontal,
IN CONST SCAN_TIMINGS * CONST Vertical IN CONST SCAN_TIMINGS *CONST Vertical
) )
{ {
UINTN RegHIntervals; UINTN RegHIntervals;
@ -227,9 +231,12 @@ ArmMaliDpGetCoreId (
on the platform. on the platform.
**/ **/
EFI_STATUS EFI_STATUS
LcdIdentify (VOID) LcdIdentify (
VOID
)
{ {
DEBUG ((DEBUG_WARN, DEBUG ((
DEBUG_WARN,
"Probing ARM Mali DP500/DP550/DP650 at base address 0x%p\n", "Probing ARM Mali DP500/DP550/DP650 at base address 0x%p\n",
DP_BASE DP_BASE
)); ));
@ -266,8 +273,11 @@ LcdInitialize (
} }
if (mDpDeviceId == MALIDP_NOT_PRESENT) { if (mDpDeviceId == MALIDP_NOT_PRESENT) {
DEBUG ((DEBUG_ERROR, "ARM Mali DP initialization failed," DEBUG ((
"no ARM Mali DP present\n")); DEBUG_ERROR,
"ARM Mali DP initialization failed,"
"no ARM Mali DP present\n"
));
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
@ -285,7 +295,9 @@ LcdInitialize (
**/ **/
STATIC STATIC
VOID VOID
SetConfigurationMode (VOID) SetConfigurationMode (
VOID
)
{ {
// Request configuration Mode. // Request configuration Mode.
if (mDpDeviceId == MALIDP_500) { if (mDpDeviceId == MALIDP_500) {
@ -303,7 +315,9 @@ SetConfigurationMode (VOID)
**/ **/
STATIC STATIC
VOID VOID
SetNormalMode (VOID) SetNormalMode (
VOID
)
{ {
// Disable configuration Mode. // Disable configuration Mode.
if (mDpDeviceId == MALIDP_500) { if (mDpDeviceId == MALIDP_500) {
@ -321,7 +335,9 @@ SetNormalMode (VOID)
**/ **/
STATIC STATIC
VOID VOID
SetConfigValid (VOID) SetConfigValid (
VOID
)
{ {
if (mDpDeviceId == MALIDP_500) { if (mDpDeviceId == MALIDP_500) {
MmioOr32 (DP_BASE + DP_DP500_CONFIG_VALID, DP_DC_CONFIG_VALID); MmioOr32 (DP_BASE + DP_DP500_CONFIG_VALID, DP_DC_CONFIG_VALID);
@ -396,7 +412,9 @@ LcdSetMode (
**/ **/
VOID VOID
LcdShutdown (VOID) LcdShutdown (
VOID
)
{ {
// Disable graphics layer. // Disable graphics layer.
LayerGraphicsDisable (); LayerGraphicsDisable ();

View File

@ -6,6 +6,7 @@
SPDX-License-Identifier: BSD-2-Clause-Patent SPDX-License-Identifier: BSD-2-Clause-Patent
**/ **/
#ifndef ARMMALIDP_H_ #ifndef ARMMALIDP_H_
#define ARMMALIDP_H_ #define ARMMALIDP_H_
@ -180,7 +181,7 @@
#define DP_DE_BG_R_PIXEL_SHIFT 16 #define DP_DE_BG_R_PIXEL_SHIFT 16
#define DP_DE_BG_G_PIXEL_SHIFT 8 #define DP_DE_BG_G_PIXEL_SHIFT 8
//Graphics layer LG_FORMAT Pixel Format // Graphics layer LG_FORMAT Pixel Format
#define DP_PIXEL_FORMAT_ARGB_8888 0x8 #define DP_PIXEL_FORMAT_ARGB_8888 0x8
#define DP_PIXEL_FORMAT_ABGR_8888 0x9 #define DP_PIXEL_FORMAT_ABGR_8888 0x9
#define DP_PIXEL_FORMAT_RGBA_8888 0xA #define DP_PIXEL_FORMAT_RGBA_8888 0xA

View File

@ -11,7 +11,6 @@
#include <Ppi/ArmMpCoreInfo.h> #include <Ppi/ArmMpCoreInfo.h>
ARM_CORE_INFO mArmPlatformNullMpCoreInfoTable[] = { ARM_CORE_INFO mArmPlatformNullMpCoreInfoTable[] = {
{ {
// Cluster 0, Core 0 // Cluster 0, Core 0
@ -95,7 +94,7 @@ ArmPlatformInitialize (
return RETURN_SUCCESS; return RETURN_SUCCESS;
} }
//TODO: Implement me // TODO: Implement me
return RETURN_SUCCESS; return RETURN_SUCCESS;
} }
@ -106,8 +105,8 @@ PrePeiCoreGetMpCoreInfo (
OUT ARM_CORE_INFO **ArmCoreTable OUT ARM_CORE_INFO **ArmCoreTable
) )
{ {
if (ArmIsMpCore()) { if (ArmIsMpCore ()) {
*CoreCount = sizeof(mArmPlatformNullMpCoreInfoTable) / sizeof(ARM_CORE_INFO); *CoreCount = sizeof (mArmPlatformNullMpCoreInfoTable) / sizeof (ARM_CORE_INFO);
*ArmCoreTable = mArmPlatformNullMpCoreInfoTable; *ArmCoreTable = mArmPlatformNullMpCoreInfoTable;
return EFI_SUCCESS; return EFI_SUCCESS;
} else { } else {
@ -131,12 +130,11 @@ ArmPlatformGetPlatformPpiList (
OUT EFI_PEI_PPI_DESCRIPTOR **PpiList OUT EFI_PEI_PPI_DESCRIPTOR **PpiList
) )
{ {
if (ArmIsMpCore()) { if (ArmIsMpCore ()) {
*PpiListSize = sizeof(gPlatformPpiTable); *PpiListSize = sizeof (gPlatformPpiTable);
*PpiList = gPlatformPpiTable; *PpiList = gPlatformPpiTable;
} else { } else {
*PpiListSize = 0; *PpiListSize = 0;
*PpiList = NULL; *PpiList = NULL;
} }
} }

View File

@ -21,8 +21,8 @@
**/ **/
VOID VOID
ArmPlatformGetVirtualMemoryMap ( ArmPlatformGetVirtualMemoryMap (
IN ARM_MEMORY_REGION_DESCRIPTOR** VirtualMemoryMap IN ARM_MEMORY_REGION_DESCRIPTOR **VirtualMemoryMap
) )
{ {
ASSERT(0); ASSERT (0);
} }

View File

@ -40,8 +40,8 @@ LcdPlatformInitializeDisplay (
**/ **/
EFI_STATUS EFI_STATUS
LcdPlatformGetVram ( LcdPlatformGetVram (
OUT EFI_PHYSICAL_ADDRESS* VramBaseAddress, OUT EFI_PHYSICAL_ADDRESS *VramBaseAddress,
OUT UINTN* VramSize OUT UINTN *VramSize
) )
{ {
ASSERT (FALSE); ASSERT (FALSE);
@ -137,7 +137,7 @@ LcdPlatformGetTimings (
EFI_STATUS EFI_STATUS
LcdPlatformGetBpp ( LcdPlatformGetBpp (
IN UINT32 ModeNumber, IN UINT32 ModeNumber,
OUT LCD_BPP* Bpp OUT LCD_BPP *Bpp
) )
{ {
ASSERT (FALSE); ASSERT (FALSE);

View File

@ -39,11 +39,11 @@ SerialPortInitialize (
ReceiveFifoDepth = 0; // Use default FIFO depth ReceiveFifoDepth = 0; // Use default FIFO depth
Parity = (EFI_PARITY_TYPE)FixedPcdGet8 (PcdUartDefaultParity); Parity = (EFI_PARITY_TYPE)FixedPcdGet8 (PcdUartDefaultParity);
DataBits = FixedPcdGet8 (PcdUartDefaultDataBits); DataBits = FixedPcdGet8 (PcdUartDefaultDataBits);
StopBits = (EFI_STOP_BITS_TYPE) FixedPcdGet8 (PcdUartDefaultStopBits); StopBits = (EFI_STOP_BITS_TYPE)FixedPcdGet8 (PcdUartDefaultStopBits);
return PL011UartInitializePort ( return PL011UartInitializePort (
(UINTN)PcdGet64 (PcdSerialRegisterBase), (UINTN)PcdGet64 (PcdSerialRegisterBase),
PL011UartClockGetFreq(), PL011UartClockGetFreq (),
&BaudRate, &BaudRate,
&ReceiveFifoDepth, &ReceiveFifoDepth,
&Parity, &Parity,
@ -87,7 +87,7 @@ EFIAPI
SerialPortRead ( SerialPortRead (
OUT UINT8 *Buffer, OUT UINT8 *Buffer,
IN UINTN NumberOfBytes IN UINTN NumberOfBytes
) )
{ {
return PL011UartRead ((UINTN)PcdGet64 (PcdSerialRegisterBase), Buffer, NumberOfBytes); return PL011UartRead ((UINTN)PcdGet64 (PcdSerialRegisterBase), Buffer, NumberOfBytes);
} }
@ -107,6 +107,7 @@ SerialPortPoll (
{ {
return PL011UartPoll ((UINTN)PcdGet64 (PcdSerialRegisterBase)); return PL011UartPoll ((UINTN)PcdGet64 (PcdSerialRegisterBase));
} }
/** /**
Set new attributes to PL011. Set new attributes to PL011.
@ -151,7 +152,7 @@ SerialPortSetAttributes (
{ {
return PL011UartInitializePort ( return PL011UartInitializePort (
(UINTN)PcdGet64 (PcdSerialRegisterBase), (UINTN)PcdGet64 (PcdSerialRegisterBase),
PL011UartClockGetFreq(), PL011UartClockGetFreq (),
BaudRate, BaudRate,
ReceiveFifoDepth, ReceiveFifoDepth,
Parity, Parity,

View File

@ -116,7 +116,7 @@ PL011UartInitializePort (
LineControl |= PL011_UARTLCR_H_PEN; LineControl |= PL011_UARTLCR_H_PEN;
break; break;
case MarkParity: case MarkParity:
LineControl |= ( PL011_UARTLCR_H_PEN \ LineControl |= (PL011_UARTLCR_H_PEN \
| PL011_UARTLCR_H_SPS \ | PL011_UARTLCR_H_SPS \
| PL011_UARTLCR_H_EPS); | PL011_UARTLCR_H_EPS);
break; break;
@ -188,6 +188,7 @@ PL011UartInitializePort (
return RETURN_INVALID_PARAMETER; return RETURN_INVALID_PARAMETER;
} }
} }
if (0 == UartClkInHz) { if (0 == UartClkInHz) {
return RETURN_INVALID_PARAMETER; return RETURN_INVALID_PARAMETER;
} }
@ -204,13 +205,15 @@ PL011UartInitializePort (
if (((MmioRead32 (UartBase + UARTCR) & PL011_UARTCR_UARTEN) != 0) && if (((MmioRead32 (UartBase + UARTCR) & PL011_UARTCR_UARTEN) != 0) &&
(MmioRead32 (UartBase + UARTLCR_H) == LineControl) && (MmioRead32 (UartBase + UARTLCR_H) == LineControl) &&
(MmioRead32 (UartBase + UARTIBRD) == Integer) && (MmioRead32 (UartBase + UARTIBRD) == Integer) &&
(MmioRead32 (UartBase + UARTFBRD) == Fractional)) { (MmioRead32 (UartBase + UARTFBRD) == Fractional))
{
// Nothing to do - already initialized with correct attributes // Nothing to do - already initialized with correct attributes
return RETURN_SUCCESS; return RETURN_SUCCESS;
} }
// Wait for the end of transmission // Wait for the end of transmission
while ((MmioRead32 (UartBase + UARTFR) & PL011_UARTFR_TXFE) == 0); while ((MmioRead32 (UartBase + UARTFR) & PL011_UARTFR_TXFE) == 0) {
}
// Disable UART: "The UARTLCR_H, UARTIBRD, and UARTFBRD registers must not be changed // Disable UART: "The UARTLCR_H, UARTIBRD, and UARTFBRD registers must not be changed
// when the UART is enabled" // when the UART is enabled"
@ -227,8 +230,10 @@ PL011UartInitializePort (
MmioWrite32 (UartBase + UARTECR, 0); MmioWrite32 (UartBase + UARTECR, 0);
// Enable Tx, Rx, and UART overall // Enable Tx, Rx, and UART overall
MmioWrite32 (UartBase + UARTCR, MmioWrite32 (
PL011_UARTCR_RXE | PL011_UARTCR_TXE | PL011_UARTCR_UARTEN); UartBase + UARTCR,
PL011_UARTCR_RXE | PL011_UARTCR_TXE | PL011_UARTCR_UARTEN
);
return RETURN_SUCCESS; return RETURN_SUCCESS;
} }
@ -347,7 +352,6 @@ PL011UartGetControl (
UINT32 FlagRegister; UINT32 FlagRegister;
UINT32 ControlRegister; UINT32 ControlRegister;
FlagRegister = MmioRead32 (UartBase + UARTFR); FlagRegister = MmioRead32 (UartBase + UARTFR);
ControlRegister = MmioRead32 (UartBase + UARTCR); ControlRegister = MmioRead32 (UartBase + UARTCR);
@ -386,7 +390,8 @@ PL011UartGetControl (
} }
if ((ControlRegister & (PL011_UARTCR_CTSEN | PL011_UARTCR_RTSEN)) if ((ControlRegister & (PL011_UARTCR_CTSEN | PL011_UARTCR_RTSEN))
== (PL011_UARTCR_CTSEN | PL011_UARTCR_RTSEN)) { == (PL011_UARTCR_CTSEN | PL011_UARTCR_RTSEN))
{
*Control |= EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE; *Control |= EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE;
} }
@ -415,11 +420,12 @@ PL011UartWrite (
IN UINTN NumberOfBytes IN UINTN NumberOfBytes
) )
{ {
UINT8* CONST Final = &Buffer[NumberOfBytes]; UINT8 *CONST Final = &Buffer[NumberOfBytes];
while (Buffer < Final) { while (Buffer < Final) {
// Wait until UART able to accept another char // Wait until UART able to accept another char
while ((MmioRead32 (UartBase + UARTFR) & UART_TX_FULL_FLAG_MASK)); while ((MmioRead32 (UartBase + UARTFR) & UART_TX_FULL_FLAG_MASK)) {
}
MmioWrite8 (UartBase + UARTDR, *Buffer++); MmioWrite8 (UartBase + UARTDR, *Buffer++);
} }
@ -448,7 +454,9 @@ PL011UartRead (
UINTN Count; UINTN Count;
for (Count = 0; Count < NumberOfBytes; Count++, Buffer++) { for (Count = 0; Count < NumberOfBytes; Count++, Buffer++) {
while ((MmioRead32 (UartBase + UARTFR) & UART_RX_EMPTY_FLAG_MASK) != 0); while ((MmioRead32 (UartBase + UARTFR) & UART_RX_EMPTY_FLAG_MASK) != 0) {
}
*Buffer = MmioRead8 (UartBase + UARTDR); *Buffer = MmioRead8 (UartBase + UARTDR);
} }

View File

@ -6,7 +6,6 @@
**/ **/
#ifndef __PL031_REAL_TIME_CLOCK_H__ #ifndef __PL031_REAL_TIME_CLOCK_H__
#define __PL031_REAL_TIME_CLOCK_H__ #define __PL031_REAL_TIME_CLOCK_H__

View File

@ -46,7 +46,8 @@ IdentifyPL031 (
if ( (MmioRead8 (mPL031RtcBase + PL031_RTC_PCELL_ID0) != 0x0D) if ( (MmioRead8 (mPL031RtcBase + PL031_RTC_PCELL_ID0) != 0x0D)
|| (MmioRead8 (mPL031RtcBase + PL031_RTC_PCELL_ID1) != 0xF0) || (MmioRead8 (mPL031RtcBase + PL031_RTC_PCELL_ID1) != 0xF0)
|| (MmioRead8 (mPL031RtcBase + PL031_RTC_PCELL_ID2) != 0x05) || (MmioRead8 (mPL031RtcBase + PL031_RTC_PCELL_ID2) != 0x05)
|| (MmioRead8 (mPL031RtcBase + PL031_RTC_PCELL_ID3) != 0xB1)) { || (MmioRead8 (mPL031RtcBase + PL031_RTC_PCELL_ID3) != 0xB1))
{
Status = EFI_NOT_FOUND; Status = EFI_NOT_FOUND;
goto EXIT; goto EXIT;
} }
@ -55,14 +56,15 @@ IdentifyPL031 (
if ( (MmioRead8 (mPL031RtcBase + PL031_RTC_PERIPH_ID0) != 0x31) if ( (MmioRead8 (mPL031RtcBase + PL031_RTC_PERIPH_ID0) != 0x31)
|| (MmioRead8 (mPL031RtcBase + PL031_RTC_PERIPH_ID1) != 0x10) || (MmioRead8 (mPL031RtcBase + PL031_RTC_PERIPH_ID1) != 0x10)
|| ((MmioRead8 (mPL031RtcBase + PL031_RTC_PERIPH_ID2) & 0xF) != 0x04) || ((MmioRead8 (mPL031RtcBase + PL031_RTC_PERIPH_ID2) & 0xF) != 0x04)
|| (MmioRead8 (mPL031RtcBase + PL031_RTC_PERIPH_ID3) != 0x00)) { || (MmioRead8 (mPL031RtcBase + PL031_RTC_PERIPH_ID3) != 0x00))
{
Status = EFI_NOT_FOUND; Status = EFI_NOT_FOUND;
goto EXIT; goto EXIT;
} }
Status = EFI_SUCCESS; Status = EFI_SUCCESS;
EXIT: EXIT:
return Status; return Status;
} }
@ -74,7 +76,7 @@ InitializePL031 (
EFI_STATUS Status; EFI_STATUS Status;
// Prepare the hardware // Prepare the hardware
Status = IdentifyPL031(); Status = IdentifyPL031 ();
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
goto EXIT; goto EXIT;
} }
@ -96,7 +98,7 @@ InitializePL031 (
mPL031Initialized = TRUE; mPL031Initialized = TRUE;
EXIT: EXIT:
return Status; return Status;
} }
@ -164,7 +166,6 @@ LibGetTime (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
Sets the current local time and date information. Sets the current local time and date information.
@ -217,7 +218,6 @@ LibSetTime (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
Returns the current wakeup alarm clock setting. Returns the current wakeup alarm clock setting.
@ -242,7 +242,6 @@ LibGetWakeupTime (
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
/** /**
Sets the system wakeup alarm clock time. Sets the system wakeup alarm clock time.
@ -288,7 +287,7 @@ LibRtcVirtualNotifyEvent (
// to virtual address. After the OS transitions to calling in virtual mode, all future // to virtual address. After the OS transitions to calling in virtual mode, all future
// runtime calls will be made in virtual mode. // runtime calls will be made in virtual mode.
// //
EfiConvertPointer (0x0, (VOID**)&mPL031RtcBase); EfiConvertPointer (0x0, (VOID **)&mPL031RtcBase);
return; return;
} }
@ -318,7 +317,8 @@ LibRtcInitialize (
// Declare the controller as EFI_MEMORY_RUNTIME // Declare the controller as EFI_MEMORY_RUNTIME
Status = gDS->AddMemorySpace ( Status = gDS->AddMemorySpace (
EfiGcdMemoryTypeMemoryMappedIo, EfiGcdMemoryTypeMemoryMappedIo,
mPL031RtcBase, SIZE_4KB, mPL031RtcBase,
SIZE_4KB,
EFI_MEMORY_UC | EFI_MEMORY_RUNTIME EFI_MEMORY_UC | EFI_MEMORY_RUNTIME
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
@ -334,7 +334,8 @@ LibRtcInitialize (
Handle = NULL; Handle = NULL;
Status = gBS->InstallMultipleProtocolInterfaces ( Status = gBS->InstallMultipleProtocolInterfaces (
&Handle, &Handle,
&gEfiRealTimeClockArchProtocolGuid, NULL, &gEfiRealTimeClockArchProtocolGuid,
NULL,
NULL NULL
); );
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);

View File

@ -26,20 +26,25 @@ LcdIdentify (
VOID VOID
) )
{ {
DEBUG ((DEBUG_WARN, "Probing ID registers at 0x%lx for a PL111\n", DEBUG ((
PL111_REG_CLCD_PERIPH_ID_0)); DEBUG_WARN,
"Probing ID registers at 0x%lx for a PL111\n",
PL111_REG_CLCD_PERIPH_ID_0
));
// Check if this is a PL111 // Check if this is a PL111
if (MmioRead8 (PL111_REG_CLCD_PERIPH_ID_0) == PL111_CLCD_PERIPH_ID_0 && if ((MmioRead8 (PL111_REG_CLCD_PERIPH_ID_0) == PL111_CLCD_PERIPH_ID_0) &&
MmioRead8 (PL111_REG_CLCD_PERIPH_ID_1) == PL111_CLCD_PERIPH_ID_1 && (MmioRead8 (PL111_REG_CLCD_PERIPH_ID_1) == PL111_CLCD_PERIPH_ID_1) &&
(MmioRead8 (PL111_REG_CLCD_PERIPH_ID_2) & 0xf) == PL111_CLCD_PERIPH_ID_2 && ((MmioRead8 (PL111_REG_CLCD_PERIPH_ID_2) & 0xf) == PL111_CLCD_PERIPH_ID_2) &&
MmioRead8 (PL111_REG_CLCD_PERIPH_ID_3) == PL111_CLCD_PERIPH_ID_3 && (MmioRead8 (PL111_REG_CLCD_PERIPH_ID_3) == PL111_CLCD_PERIPH_ID_3) &&
MmioRead8 (PL111_REG_CLCD_P_CELL_ID_0) == PL111_CLCD_P_CELL_ID_0 && (MmioRead8 (PL111_REG_CLCD_P_CELL_ID_0) == PL111_CLCD_P_CELL_ID_0) &&
MmioRead8 (PL111_REG_CLCD_P_CELL_ID_1) == PL111_CLCD_P_CELL_ID_1 && (MmioRead8 (PL111_REG_CLCD_P_CELL_ID_1) == PL111_CLCD_P_CELL_ID_1) &&
MmioRead8 (PL111_REG_CLCD_P_CELL_ID_2) == PL111_CLCD_P_CELL_ID_2 && (MmioRead8 (PL111_REG_CLCD_P_CELL_ID_2) == PL111_CLCD_P_CELL_ID_2) &&
MmioRead8 (PL111_REG_CLCD_P_CELL_ID_3) == PL111_CLCD_P_CELL_ID_3) { (MmioRead8 (PL111_REG_CLCD_P_CELL_ID_3) == PL111_CLCD_P_CELL_ID_3))
{
return EFI_SUCCESS; return EFI_SUCCESS;
} }
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
@ -148,6 +153,7 @@ LcdSetMode (
if (ModeInfo.PixelFormat == PixelBlueGreenRedReserved8BitPerColor) { if (ModeInfo.PixelFormat == PixelBlueGreenRedReserved8BitPerColor) {
LcdControl |= PL111_CTRL_BGR; LcdControl |= PL111_CTRL_BGR;
} }
MmioWrite32 (PL111_REG_LCD_CONTROL, LcdControl); MmioWrite32 (PL111_REG_LCD_CONTROL, LcdControl);
return EFI_SUCCESS; return EFI_SUCCESS;

View File

@ -61,10 +61,10 @@
/**********************************************************************/ /**********************************************************************/
// Register: PL111_REG_LCD_TIMING_0 // Register: PL111_REG_LCD_TIMING_0
#define HOR_AXIS_PANEL(hbp,hfp,hsw,hor_res) (UINT32)(((UINT32)(hbp) << 24) | ((UINT32)(hfp) << 16) | ((UINT32)(hsw) << 8) | (((UINT32)((hor_res)/16)-1) << 2)) #define HOR_AXIS_PANEL(hbp, hfp, hsw, hor_res) (UINT32)(((UINT32)(hbp) << 24) | ((UINT32)(hfp) << 16) | ((UINT32)(hsw) << 8) | (((UINT32)((hor_res)/16)-1) << 2))
// Register: PL111_REG_LCD_TIMING_1 // Register: PL111_REG_LCD_TIMING_1
#define VER_AXIS_PANEL(vbp,vfp,vsw,ver_res) (UINT32)(((UINT32)(vbp) << 24) | ((UINT32)(vfp) << 16) | ((UINT32)(vsw) << 10) | ((ver_res)-1)) #define VER_AXIS_PANEL(vbp, vfp, vsw, ver_res) (UINT32)(((UINT32)(vbp) << 24) | ((UINT32)(vfp) << 16) | ((UINT32)(vsw) << 10) | ((ver_res)-1))
// Register: PL111_REG_LCD_TIMING_2 // Register: PL111_REG_LCD_TIMING_2
#define PL111_BIT_SHIFT_PCD_HI 27 #define PL111_BIT_SHIFT_PCD_HI 27

View File

@ -25,11 +25,9 @@ PrePeiGetHobList (
VOID VOID
) )
{ {
return (VOID *)ArmReadTpidrurw(); return (VOID *)ArmReadTpidrurw ();
} }
/** /**
Updates the pointer to the HOB list. Updates the pointer to the HOB list.
@ -42,7 +40,7 @@ PrePeiSetHobList (
IN VOID *HobList IN VOID *HobList
) )
{ {
ArmWriteTpidrurw((UINTN)HobList); ArmWriteTpidrurw ((UINTN)HobList);
return EFI_SUCCESS; return EFI_SUCCESS;
} }

View File

@ -26,12 +26,11 @@ InitMmu (
IN ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable IN ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable
) )
{ {
VOID *TranslationTableBase; VOID *TranslationTableBase;
UINTN TranslationTableSize; UINTN TranslationTableSize;
RETURN_STATUS Status; RETURN_STATUS Status;
//Note: Because we called PeiServicesInstallPeiMemory() before to call InitMmu() the MMU Page Table resides in // Note: Because we called PeiServicesInstallPeiMemory() before to call InitMmu() the MMU Page Table resides in
// DRAM (even at the top of DRAM as it is the first permanent memory allocation) // DRAM (even at the top of DRAM as it is the first permanent memory allocation)
Status = ArmConfigureMmu (MemoryTable, &TranslationTableBase, &TranslationTableSize); Status = ArmConfigureMmu (MemoryTable, &TranslationTableBase, &TranslationTableSize);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
@ -102,6 +101,7 @@ MemoryPeim (
Found = TRUE; Found = TRUE;
break; break;
} }
NextHob.Raw = GET_NEXT_HOB (NextHob); NextHob.Raw = GET_NEXT_HOB (NextHob);
} }
@ -142,21 +142,25 @@ MemoryPeim (
if (PcdGet64 (PcdFdBaseAddress) == NextHob.ResourceDescriptor->PhysicalStart) { if (PcdGet64 (PcdFdBaseAddress) == NextHob.ResourceDescriptor->PhysicalStart) {
if (SystemMemoryTop != FdTop) { if (SystemMemoryTop != FdTop) {
// Create the System Memory HOB for the firmware // Create the System Memory HOB for the firmware
BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, BuildResourceDescriptorHob (
EFI_RESOURCE_SYSTEM_MEMORY,
ResourceAttributes, ResourceAttributes,
PcdGet64 (PcdFdBaseAddress), PcdGet64 (PcdFdBaseAddress),
PcdGet32 (PcdFdSize)); PcdGet32 (PcdFdSize)
);
// Top of the FD is system memory available for UEFI // Top of the FD is system memory available for UEFI
NextHob.ResourceDescriptor->PhysicalStart += PcdGet32(PcdFdSize); NextHob.ResourceDescriptor->PhysicalStart += PcdGet32 (PcdFdSize);
NextHob.ResourceDescriptor->ResourceLength -= PcdGet32(PcdFdSize); NextHob.ResourceDescriptor->ResourceLength -= PcdGet32 (PcdFdSize);
} }
} else { } else {
// Create the System Memory HOB for the firmware // Create the System Memory HOB for the firmware
BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, BuildResourceDescriptorHob (
EFI_RESOURCE_SYSTEM_MEMORY,
ResourceAttributes, ResourceAttributes,
PcdGet64 (PcdFdBaseAddress), PcdGet64 (PcdFdBaseAddress),
PcdGet32 (PcdFdSize)); PcdGet32 (PcdFdSize)
);
// Update the HOB // Update the HOB
NextHob.ResourceDescriptor->ResourceLength = PcdGet64 (PcdFdBaseAddress) - NextHob.ResourceDescriptor->PhysicalStart; NextHob.ResourceDescriptor->ResourceLength = PcdGet64 (PcdFdBaseAddress) - NextHob.ResourceDescriptor->PhysicalStart;
@ -164,25 +168,30 @@ MemoryPeim (
// If there is some memory available on the top of the FD then create a HOB // If there is some memory available on the top of the FD then create a HOB
if (FdTop < NextHob.ResourceDescriptor->PhysicalStart + ResourceLength) { if (FdTop < NextHob.ResourceDescriptor->PhysicalStart + ResourceLength) {
// Create the System Memory HOB for the remaining region (top of the FD) // Create the System Memory HOB for the remaining region (top of the FD)
BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, BuildResourceDescriptorHob (
EFI_RESOURCE_SYSTEM_MEMORY,
ResourceAttributes, ResourceAttributes,
FdTop, FdTop,
ResourceTop - FdTop); ResourceTop - FdTop
);
} }
} }
// Mark the memory covering the Firmware Device as boot services data // Mark the memory covering the Firmware Device as boot services data
BuildMemoryAllocationHob (PcdGet64 (PcdFdBaseAddress), BuildMemoryAllocationHob (
PcdGet64 (PcdFdBaseAddress),
PcdGet32 (PcdFdSize), PcdGet32 (PcdFdSize),
EfiBootServicesData); EfiBootServicesData
);
Found = TRUE; Found = TRUE;
break; break;
} }
NextHob.Raw = GET_NEXT_HOB (NextHob); NextHob.Raw = GET_NEXT_HOB (NextHob);
} }
ASSERT(Found); ASSERT (Found);
} }
// Build Memory Allocation Hob // Build Memory Allocation Hob

View File

@ -106,6 +106,7 @@ InitializeMemory (
if (SystemMemoryTop - 1 > MAX_ALLOC_ADDRESS) { if (SystemMemoryTop - 1 > MAX_ALLOC_ADDRESS) {
SystemMemoryTop = (UINT64)MAX_ALLOC_ADDRESS + 1; SystemMemoryTop = (UINT64)MAX_ALLOC_ADDRESS + 1;
} }
FdBase = (UINTN)PcdGet64 (PcdFdBaseAddress); FdBase = (UINTN)PcdGet64 (PcdFdBaseAddress);
FdTop = FdBase + (UINTN)PcdGet32 (PcdFdSize); FdTop = FdBase + (UINTN)PcdGet32 (PcdFdSize);

View File

@ -23,24 +23,24 @@ PeiCommonExceptionEntry (
switch (Entry) { switch (Entry) {
case EXCEPT_AARCH64_SYNCHRONOUS_EXCEPTIONS: case EXCEPT_AARCH64_SYNCHRONOUS_EXCEPTIONS:
CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Synchronous Exception at 0x%X\n\r", LR); CharCount = AsciiSPrint (Buffer, sizeof (Buffer), "Synchronous Exception at 0x%X\n\r", LR);
break; break;
case EXCEPT_AARCH64_IRQ: case EXCEPT_AARCH64_IRQ:
CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"IRQ Exception at 0x%X\n\r", LR); CharCount = AsciiSPrint (Buffer, sizeof (Buffer), "IRQ Exception at 0x%X\n\r", LR);
break; break;
case EXCEPT_AARCH64_FIQ: case EXCEPT_AARCH64_FIQ:
CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"FIQ Exception at 0x%X\n\r", LR); CharCount = AsciiSPrint (Buffer, sizeof (Buffer), "FIQ Exception at 0x%X\n\r", LR);
break; break;
case EXCEPT_AARCH64_SERROR: case EXCEPT_AARCH64_SERROR:
CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"SError/Abort Exception at 0x%X\n\r", LR); CharCount = AsciiSPrint (Buffer, sizeof (Buffer), "SError/Abort Exception at 0x%X\n\r", LR);
break; break;
default: default:
CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Unknown Exception at 0x%X\n\r", LR); CharCount = AsciiSPrint (Buffer, sizeof (Buffer), "Unknown Exception at 0x%X\n\r", LR);
break; break;
} }
SerialPortWrite ((UINT8 *) Buffer, CharCount); SerialPortWrite ((UINT8 *)Buffer, CharCount);
while(1); while (1) {
}
} }

View File

@ -23,34 +23,35 @@ PeiCommonExceptionEntry (
switch (Entry) { switch (Entry) {
case 0: case 0:
CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Reset Exception at 0x%X\n\r",LR); CharCount = AsciiSPrint (Buffer, sizeof (Buffer), "Reset Exception at 0x%X\n\r", LR);
break; break;
case 1: case 1:
CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Undefined Exception at 0x%X\n\r",LR); CharCount = AsciiSPrint (Buffer, sizeof (Buffer), "Undefined Exception at 0x%X\n\r", LR);
break; break;
case 2: case 2:
CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"SWI Exception at 0x%X\n\r",LR); CharCount = AsciiSPrint (Buffer, sizeof (Buffer), "SWI Exception at 0x%X\n\r", LR);
break; break;
case 3: case 3:
CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"PrefetchAbort Exception at 0x%X\n\r",LR); CharCount = AsciiSPrint (Buffer, sizeof (Buffer), "PrefetchAbort Exception at 0x%X\n\r", LR);
break; break;
case 4: case 4:
CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"DataAbort Exception at 0x%X\n\r",LR); CharCount = AsciiSPrint (Buffer, sizeof (Buffer), "DataAbort Exception at 0x%X\n\r", LR);
break; break;
case 5: case 5:
CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Reserved Exception at 0x%X\n\r",LR); CharCount = AsciiSPrint (Buffer, sizeof (Buffer), "Reserved Exception at 0x%X\n\r", LR);
break; break;
case 6: case 6:
CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"IRQ Exception at 0x%X\n\r",LR); CharCount = AsciiSPrint (Buffer, sizeof (Buffer), "IRQ Exception at 0x%X\n\r", LR);
break; break;
case 7: case 7:
CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"FIQ Exception at 0x%X\n\r",LR); CharCount = AsciiSPrint (Buffer, sizeof (Buffer), "FIQ Exception at 0x%X\n\r", LR);
break; break;
default: default:
CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"Unknown Exception at 0x%X\n\r",LR); CharCount = AsciiSPrint (Buffer, sizeof (Buffer), "Unknown Exception at 0x%X\n\r", LR);
break; break;
} }
SerialPortWrite ((UINT8 *) Buffer, CharCount);
while(1);
}
SerialPortWrite ((UINT8 *)Buffer, CharCount);
while (1) {
}
}

View File

@ -37,18 +37,21 @@ SecondaryMain (
ARM_CORE_INFO *ArmCoreInfoTable; ARM_CORE_INFO *ArmCoreInfoTable;
UINT32 ClusterId; UINT32 ClusterId;
UINT32 CoreId; UINT32 CoreId;
VOID (*SecondaryStart)(VOID);
VOID (*SecondaryStart)(
VOID
);
UINTN SecondaryEntryAddr; UINTN SecondaryEntryAddr;
UINTN AcknowledgeInterrupt; UINTN AcknowledgeInterrupt;
UINTN InterruptId; UINTN InterruptId;
ClusterId = GET_CLUSTER_ID(MpId); ClusterId = GET_CLUSTER_ID (MpId);
CoreId = GET_CORE_ID(MpId); CoreId = GET_CORE_ID (MpId);
// Get the gArmMpCoreInfoPpiGuid // Get the gArmMpCoreInfoPpiGuid
PpiListSize = 0; PpiListSize = 0;
ArmPlatformGetPlatformPpiList (&PpiListSize, &PpiList); ArmPlatformGetPlatformPpiList (&PpiListSize, &PpiList);
PpiListCount = PpiListSize / sizeof(EFI_PEI_PPI_DESCRIPTOR); PpiListCount = PpiListSize / sizeof (EFI_PEI_PPI_DESCRIPTOR);
for (Index = 0; Index < PpiListCount; Index++, PpiList++) { for (Index = 0; Index < PpiListCount; Index++, PpiList++) {
if (CompareGuid (PpiList->Guid, &gArmMpCoreInfoPpiGuid) == TRUE) { if (CompareGuid (PpiList->Guid, &gArmMpCoreInfoPpiGuid) == TRUE) {
break; break;
@ -92,11 +95,11 @@ SecondaryMain (
} while (SecondaryEntryAddr == 0); } while (SecondaryEntryAddr == 0);
// Jump to secondary core entry point. // Jump to secondary core entry point.
SecondaryStart = (VOID (*)())SecondaryEntryAddr; SecondaryStart = (VOID (*)()) SecondaryEntryAddr;
SecondaryStart(); SecondaryStart ();
// The secondaries shouldn't reach here // The secondaries shouldn't reach here
ASSERT(FALSE); ASSERT (FALSE);
} }
VOID VOID
@ -114,17 +117,17 @@ PrimaryMain (
CreatePpiList (&PpiListSize, &PpiList); CreatePpiList (&PpiListSize, &PpiList);
// Enable the GIC Distributor // Enable the GIC Distributor
ArmGicEnableDistributor (PcdGet64(PcdGicDistributorBase)); ArmGicEnableDistributor (PcdGet64 (PcdGicDistributorBase));
// If ArmVe has not been built as Standalone then we need to wake up the secondary cores // If ArmVe has not been built as Standalone then we need to wake up the secondary cores
if (FeaturePcdGet (PcdSendSgiToBringUpSecondaryCores)) { if (FeaturePcdGet (PcdSendSgiToBringUpSecondaryCores)) {
// Sending SGI to all the Secondary CPU interfaces // Sending SGI to all the Secondary CPU interfaces
ArmGicSendSgiTo (PcdGet64(PcdGicDistributorBase), ARM_GIC_ICDSGIR_FILTER_EVERYONEELSE, 0x0E, PcdGet32 (PcdGicSgiIntId)); ArmGicSendSgiTo (PcdGet64 (PcdGicDistributorBase), ARM_GIC_ICDSGIR_FILTER_EVERYONEELSE, 0x0E, PcdGet32 (PcdGicSgiIntId));
} }
// Adjust the Temporary Ram as the new Ppi List (Common + Platform Ppi Lists) is created at // Adjust the Temporary Ram as the new Ppi List (Common + Platform Ppi Lists) is created at
// the base of the primary core stack // the base of the primary core stack
PpiListSize = ALIGN_VALUE(PpiListSize, CPU_STACK_ALIGNMENT); PpiListSize = ALIGN_VALUE (PpiListSize, CPU_STACK_ALIGNMENT);
TemporaryRamBase = (UINTN)PcdGet64 (PcdCPUCoresStackBase) + PpiListSize; TemporaryRamBase = (UINTN)PcdGet64 (PcdCPUCoresStackBase) + PpiListSize;
TemporaryRamSize = (UINTN)PcdGet32 (PcdCPUCorePrimaryStackSize) - PpiListSize; TemporaryRamSize = (UINTN)PcdGet32 (PcdCPUCorePrimaryStackSize) - PpiListSize;
@ -133,7 +136,7 @@ PrimaryMain (
// Note: this must be in sync with the stuff in the asm file // Note: this must be in sync with the stuff in the asm file
// Note also: HOBs (pei temp ram) MUST be above stack // Note also: HOBs (pei temp ram) MUST be above stack
// //
SecCoreData.DataSize = sizeof(EFI_SEC_PEI_HAND_OFF); SecCoreData.DataSize = sizeof (EFI_SEC_PEI_HAND_OFF);
SecCoreData.BootFirmwareVolumeBase = (VOID *)(UINTN)PcdGet64 (PcdFvBaseAddress); SecCoreData.BootFirmwareVolumeBase = (VOID *)(UINTN)PcdGet64 (PcdFvBaseAddress);
SecCoreData.BootFirmwareVolumeSize = PcdGet32 (PcdFvSize); SecCoreData.BootFirmwareVolumeSize = PcdGet32 (PcdFvSize);
SecCoreData.TemporaryRamBase = (VOID *)TemporaryRamBase; // We run on the primary core (and so we use the first stack) SecCoreData.TemporaryRamBase = (VOID *)TemporaryRamBase; // We run on the primary core (and so we use the first stack)

View File

@ -14,7 +14,7 @@ SecondaryMain (
IN UINTN MpId IN UINTN MpId
) )
{ {
ASSERT(FALSE); ASSERT (FALSE);
} }
VOID VOID
@ -33,7 +33,7 @@ PrimaryMain (
// Adjust the Temporary Ram as the new Ppi List (Common + Platform Ppi Lists) is created at // Adjust the Temporary Ram as the new Ppi List (Common + Platform Ppi Lists) is created at
// the base of the primary core stack // the base of the primary core stack
PpiListSize = ALIGN_VALUE(PpiListSize, CPU_STACK_ALIGNMENT); PpiListSize = ALIGN_VALUE (PpiListSize, CPU_STACK_ALIGNMENT);
TemporaryRamBase = (UINTN)PcdGet64 (PcdCPUCoresStackBase) + PpiListSize; TemporaryRamBase = (UINTN)PcdGet64 (PcdCPUCoresStackBase) + PpiListSize;
TemporaryRamSize = (UINTN)PcdGet32 (PcdCPUCorePrimaryStackSize) - PpiListSize; TemporaryRamSize = (UINTN)PcdGet32 (PcdCPUCorePrimaryStackSize) - PpiListSize;
@ -42,7 +42,7 @@ PrimaryMain (
// Note: this must be in sync with the stuff in the asm file // Note: this must be in sync with the stuff in the asm file
// Note also: HOBs (pei temp ram) MUST be above stack // Note also: HOBs (pei temp ram) MUST be above stack
// //
SecCoreData.DataSize = sizeof(EFI_SEC_PEI_HAND_OFF); SecCoreData.DataSize = sizeof (EFI_SEC_PEI_HAND_OFF);
SecCoreData.BootFirmwareVolumeBase = (VOID *)(UINTN)PcdGet64 (PcdFvBaseAddress); SecCoreData.BootFirmwareVolumeBase = (VOID *)(UINTN)PcdGet64 (PcdFvBaseAddress);
SecCoreData.BootFirmwareVolumeSize = PcdGet32 (PcdFvSize); SecCoreData.BootFirmwareVolumeSize = PcdGet32 (PcdFvSize);
SecCoreData.TemporaryRamBase = (VOID *)TemporaryRamBase; // We run on the primary core (and so we use the first stack) SecCoreData.TemporaryRamBase = (VOID *)TemporaryRamBase; // We run on the primary core (and so we use the first stack)

View File

@ -20,7 +20,7 @@ CONST EFI_PEI_PPI_DESCRIPTOR gCommonPpiTable[] = {
{ {
EFI_PEI_PPI_DESCRIPTOR_PPI, EFI_PEI_PPI_DESCRIPTOR_PPI,
&gEfiTemporaryRamSupportPpiGuid, &gEfiTemporaryRamSupportPpiGuid,
(VOID *) &mTemporaryRamSupportPpi (VOID *)&mTemporaryRamSupportPpi
} }
}; };
@ -41,15 +41,15 @@ CreatePpiList (
// Copy the Common and Platform PPis in Temporary Memory // Copy the Common and Platform PPis in Temporary Memory
ListBase = PcdGet64 (PcdCPUCoresStackBase); ListBase = PcdGet64 (PcdCPUCoresStackBase);
CopyMem ((VOID*)ListBase, gCommonPpiTable, sizeof(gCommonPpiTable)); CopyMem ((VOID *)ListBase, gCommonPpiTable, sizeof (gCommonPpiTable));
CopyMem ((VOID*)(ListBase + sizeof(gCommonPpiTable)), PlatformPpiList, PlatformPpiListSize); CopyMem ((VOID *)(ListBase + sizeof (gCommonPpiTable)), PlatformPpiList, PlatformPpiListSize);
// Set the Terminate flag on the last PPI entry // Set the Terminate flag on the last PPI entry
LastPpi = (EFI_PEI_PPI_DESCRIPTOR*)ListBase + ((sizeof(gCommonPpiTable) + PlatformPpiListSize) / sizeof(EFI_PEI_PPI_DESCRIPTOR)) - 1; LastPpi = (EFI_PEI_PPI_DESCRIPTOR *)ListBase + ((sizeof (gCommonPpiTable) + PlatformPpiListSize) / sizeof (EFI_PEI_PPI_DESCRIPTOR)) - 1;
LastPpi->Flags |= EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST; LastPpi->Flags |= EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST;
*PpiList = (EFI_PEI_PPI_DESCRIPTOR*)ListBase; *PpiList = (EFI_PEI_PPI_DESCRIPTOR *)ListBase;
*PpiListSize = sizeof(gCommonPpiTable) + PlatformPpiListSize; *PpiListSize = sizeof (gCommonPpiTable) + PlatformPpiListSize;
} }
VOID VOID
@ -65,8 +65,10 @@ CEntryPoint (
// Enable Instruction Caches on all cores. // Enable Instruction Caches on all cores.
ArmEnableInstructionCache (); ArmEnableInstructionCache ();
InvalidateDataCacheRange ((VOID *)(UINTN)PcdGet64 (PcdCPUCoresStackBase), InvalidateDataCacheRange (
PcdGet32 (PcdCPUCorePrimaryStackSize)); (VOID *)(UINTN)PcdGet64 (PcdCPUCoresStackBase),
PcdGet32 (PcdCPUCorePrimaryStackSize)
);
// //
// Note: Doesn't have to Enable CPU interface in non-secure world, // Note: Doesn't have to Enable CPU interface in non-secure world,
@ -84,7 +86,7 @@ CEntryPoint (
ArmEnableVFP (); ArmEnableVFP ();
} }
//Note: The MMU will be enabled by MemoryPeim. Only the primary core will have the MMU on. // Note: The MMU will be enabled by MemoryPeim. Only the primary core will have the MMU on.
// If not primary Jump to Secondary Main // If not primary Jump to Secondary Main
if (ArmPlatformIsPrimaryCore (MpId)) { if (ArmPlatformIsPrimaryCore (MpId)) {
@ -122,11 +124,11 @@ PrePeiCoreTemporaryRamSupport (
HeapSize = ALIGN_VALUE (CopySize / 2, CPU_STACK_ALIGNMENT); HeapSize = ALIGN_VALUE (CopySize / 2, CPU_STACK_ALIGNMENT);
OldHeap = (VOID*)(UINTN)TemporaryMemoryBase; OldHeap = (VOID *)(UINTN)TemporaryMemoryBase;
NewHeap = (VOID*)((UINTN)PermanentMemoryBase + (CopySize - HeapSize)); NewHeap = (VOID *)((UINTN)PermanentMemoryBase + (CopySize - HeapSize));
OldStack = (VOID*)((UINTN)TemporaryMemoryBase + HeapSize); OldStack = (VOID *)((UINTN)TemporaryMemoryBase + HeapSize);
NewStack = (VOID*)(UINTN)PermanentMemoryBase; NewStack = (VOID *)(UINTN)PermanentMemoryBase;
// //
// Migrate the temporary memory stack to permanent memory stack. // Migrate the temporary memory stack to permanent memory stack.

View File

@ -6,6 +6,7 @@
SPDX-License-Identifier: BSD-2-Clause-Patent SPDX-License-Identifier: BSD-2-Clause-Patent
**/ **/
#ifndef __PREPEICORE_H_ #ifndef __PREPEICORE_H_
#define __PREPEICORE_H_ #define __PREPEICORE_H_
@ -40,7 +41,10 @@ SecSwitchStack (
); );
// Vector Table for Pei Phase // Vector Table for Pei Phase
VOID PeiVectorTable (VOID); VOID
PeiVectorTable (
VOID
);
VOID VOID
EFIAPI EFIAPI

View File

@ -20,4 +20,3 @@ ArchInitialize (
ArmEnableVFP (); ArmEnableVFP ();
} }
} }

View File

@ -20,18 +20,18 @@ PrimaryMain (
) )
{ {
// Enable the GIC Distributor // Enable the GIC Distributor
ArmGicEnableDistributor(PcdGet64(PcdGicDistributorBase)); ArmGicEnableDistributor (PcdGet64 (PcdGicDistributorBase));
// In some cases, the secondary cores are waiting for an SGI from the next stage boot loader to resume their initialization // In some cases, the secondary cores are waiting for an SGI from the next stage boot loader to resume their initialization
if (!FixedPcdGet32(PcdSendSgiToBringUpSecondaryCores)) { if (!FixedPcdGet32 (PcdSendSgiToBringUpSecondaryCores)) {
// Sending SGI to all the Secondary CPU interfaces // Sending SGI to all the Secondary CPU interfaces
ArmGicSendSgiTo (PcdGet64(PcdGicDistributorBase), ARM_GIC_ICDSGIR_FILTER_EVERYONEELSE, 0x0E, PcdGet32 (PcdGicSgiIntId)); ArmGicSendSgiTo (PcdGet64 (PcdGicDistributorBase), ARM_GIC_ICDSGIR_FILTER_EVERYONEELSE, 0x0E, PcdGet32 (PcdGicSgiIntId));
} }
PrePiMain (UefiMemoryBase, StacksBase, StartTimeStamp); PrePiMain (UefiMemoryBase, StacksBase, StartTimeStamp);
// We must never return // We must never return
ASSERT(FALSE); ASSERT (FALSE);
} }
VOID VOID
@ -46,16 +46,19 @@ SecondaryMain (
ARM_CORE_INFO *ArmCoreInfoTable; ARM_CORE_INFO *ArmCoreInfoTable;
UINT32 ClusterId; UINT32 ClusterId;
UINT32 CoreId; UINT32 CoreId;
VOID (*SecondaryStart)(VOID);
VOID (*SecondaryStart)(
VOID
);
UINTN SecondaryEntryAddr; UINTN SecondaryEntryAddr;
UINTN AcknowledgeInterrupt; UINTN AcknowledgeInterrupt;
UINTN InterruptId; UINTN InterruptId;
ClusterId = GET_CLUSTER_ID(MpId); ClusterId = GET_CLUSTER_ID (MpId);
CoreId = GET_CORE_ID(MpId); CoreId = GET_CORE_ID (MpId);
// On MP Core Platform we must implement the ARM MP Core Info PPI (gArmMpCoreInfoPpiGuid) // On MP Core Platform we must implement the ARM MP Core Info PPI (gArmMpCoreInfoPpiGuid)
Status = GetPlatformPpi (&gArmMpCoreInfoPpiGuid, (VOID**)&ArmMpCoreInfoPpi); Status = GetPlatformPpi (&gArmMpCoreInfoPpiGuid, (VOID **)&ArmMpCoreInfoPpi);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
ArmCoreCount = 0; ArmCoreCount = 0;
@ -91,9 +94,9 @@ SecondaryMain (
} while (SecondaryEntryAddr == 0); } while (SecondaryEntryAddr == 0);
// Jump to secondary core entry point. // Jump to secondary core entry point.
SecondaryStart = (VOID (*)())SecondaryEntryAddr; SecondaryStart = (VOID (*)()) SecondaryEntryAddr;
SecondaryStart(); SecondaryStart ();
// The secondaries shouldn't reach here // The secondaries shouldn't reach here
ASSERT(FALSE); ASSERT (FALSE);
} }

View File

@ -18,7 +18,7 @@ PrimaryMain (
PrePiMain (UefiMemoryBase, StacksBase, StartTimeStamp); PrePiMain (UefiMemoryBase, StacksBase, StartTimeStamp);
// We must never return // We must never return
ASSERT(FALSE); ASSERT (FALSE);
} }
VOID VOID
@ -27,6 +27,5 @@ SecondaryMain (
) )
{ {
// We must never get into this function on UniCore system // We must never get into this function on UniCore system
ASSERT(FALSE); ASSERT (FALSE);
} }

View File

@ -22,11 +22,11 @@
#include "PrePi.h" #include "PrePi.h"
#define IS_XIP() (((UINT64)FixedPcdGet64 (PcdFdBaseAddress) > mSystemMemoryEnd) || \ #define IS_XIP() (((UINT64)FixedPcdGet64 (PcdFdBaseAddress) > mSystemMemoryEnd) ||\
((FixedPcdGet64 (PcdFdBaseAddress) + FixedPcdGet32 (PcdFdSize)) <= FixedPcdGet64 (PcdSystemMemoryBase))) ((FixedPcdGet64 (PcdFdBaseAddress) + FixedPcdGet32 (PcdFdSize)) <= FixedPcdGet64 (PcdSystemMemoryBase)))
UINT64 mSystemMemoryEnd = FixedPcdGet64(PcdSystemMemoryBase) + UINT64 mSystemMemoryEnd = FixedPcdGet64 (PcdSystemMemoryBase) +
FixedPcdGet64(PcdSystemMemorySize) - 1; FixedPcdGet64 (PcdSystemMemorySize) - 1;
EFI_STATUS EFI_STATUS
GetPlatformPpi ( GetPlatformPpi (
@ -41,7 +41,7 @@ GetPlatformPpi (
PpiListSize = 0; PpiListSize = 0;
ArmPlatformGetPlatformPpiList (&PpiListSize, &PpiList); ArmPlatformGetPlatformPpiList (&PpiListSize, &PpiList);
PpiListCount = PpiListSize / sizeof(EFI_PEI_PPI_DESCRIPTOR); PpiListCount = PpiListSize / sizeof (EFI_PEI_PPI_DESCRIPTOR);
for (Index = 0; Index < PpiListCount; Index++, PpiList++) { for (Index = 0; Index < PpiListCount; Index++, PpiList++) {
if (CompareGuid (PpiList->Guid, PpiGuid) == TRUE) { if (CompareGuid (PpiList->Guid, PpiGuid) == TRUE) {
*Ppi = PpiList->Ppi; *Ppi = PpiList->Ppi;
@ -59,10 +59,10 @@ PrePiMain (
IN UINT64 StartTimeStamp IN UINT64 StartTimeStamp
) )
{ {
EFI_HOB_HANDOFF_INFO_TABLE* HobList; EFI_HOB_HANDOFF_INFO_TABLE *HobList;
ARM_MP_CORE_INFO_PPI* ArmMpCoreInfoPpi; ARM_MP_CORE_INFO_PPI *ArmMpCoreInfoPpi;
UINTN ArmCoreCount; UINTN ArmCoreCount;
ARM_CORE_INFO* ArmCoreInfoTable; ARM_CORE_INFO *ArmCoreInfoTable;
EFI_STATUS Status; EFI_STATUS Status;
CHAR8 Buffer[100]; CHAR8 Buffer[100];
UINTN CharCount; UINTN CharCount;
@ -70,18 +70,26 @@ PrePiMain (
FIRMWARE_SEC_PERFORMANCE Performance; FIRMWARE_SEC_PERFORMANCE Performance;
// If ensure the FD is either part of the System Memory or totally outside of the System Memory (XIP) // If ensure the FD is either part of the System Memory or totally outside of the System Memory (XIP)
ASSERT (IS_XIP() || ASSERT (
IS_XIP () ||
((FixedPcdGet64 (PcdFdBaseAddress) >= FixedPcdGet64 (PcdSystemMemoryBase)) && ((FixedPcdGet64 (PcdFdBaseAddress) >= FixedPcdGet64 (PcdSystemMemoryBase)) &&
((UINT64)(FixedPcdGet64 (PcdFdBaseAddress) + FixedPcdGet32 (PcdFdSize)) <= (UINT64)mSystemMemoryEnd))); ((UINT64)(FixedPcdGet64 (PcdFdBaseAddress) + FixedPcdGet32 (PcdFdSize)) <= (UINT64)mSystemMemoryEnd))
);
// Initialize the architecture specific bits // Initialize the architecture specific bits
ArchInitialize (); ArchInitialize ();
// Initialize the Serial Port // Initialize the Serial Port
SerialPortInitialize (); SerialPortInitialize ();
CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"UEFI firmware (version %s built at %a on %a)\n\r", CharCount = AsciiSPrint (
(CHAR16*)PcdGetPtr(PcdFirmwareVersionString), __TIME__, __DATE__); Buffer,
SerialPortWrite ((UINT8 *) Buffer, CharCount); sizeof (Buffer),
"UEFI firmware (version %s built at %a on %a)\n\r",
(CHAR16 *)PcdGetPtr (PcdFirmwareVersionString),
__TIME__,
__DATE__
);
SerialPortWrite ((UINT8 *)Buffer, CharCount);
// Initialize the Debug Agent for Source Level Debugging // Initialize the Debug Agent for Source Level Debugging
InitializeDebugAgent (DEBUG_AGENT_INIT_POSTMEM_SEC, NULL, NULL); InitializeDebugAgent (DEBUG_AGENT_INIT_POSTMEM_SEC, NULL, NULL);
@ -89,10 +97,10 @@ PrePiMain (
// Declare the PI/UEFI memory region // Declare the PI/UEFI memory region
HobList = HobConstructor ( HobList = HobConstructor (
(VOID*)UefiMemoryBase, (VOID *)UefiMemoryBase,
FixedPcdGet32 (PcdSystemMemoryUefiRegionSize), FixedPcdGet32 (PcdSystemMemoryUefiRegionSize),
(VOID*)UefiMemoryBase, (VOID *)UefiMemoryBase,
(VOID*)StacksBase // The top of the UEFI Memory is reserved for the stacks (VOID *)StacksBase // The top of the UEFI Memory is reserved for the stacks
); );
PrePeiSetHobList (HobList); PrePeiSetHobList (HobList);
@ -107,14 +115,15 @@ PrePiMain (
} else { } else {
StacksSize = PcdGet32 (PcdCPUCorePrimaryStackSize); StacksSize = PcdGet32 (PcdCPUCorePrimaryStackSize);
} }
BuildStackHob (StacksBase, StacksSize); BuildStackHob (StacksBase, StacksSize);
//TODO: Call CpuPei as a library // TODO: Call CpuPei as a library
BuildCpuHob (ArmGetPhysicalAddressBits (), PcdGet8 (PcdPrePiCpuIoSize)); BuildCpuHob (ArmGetPhysicalAddressBits (), PcdGet8 (PcdPrePiCpuIoSize));
if (ArmIsMpCore ()) { if (ArmIsMpCore ()) {
// Only MP Core platform need to produce gArmMpCoreInfoPpiGuid // Only MP Core platform need to produce gArmMpCoreInfoPpiGuid
Status = GetPlatformPpi (&gArmMpCoreInfoPpiGuid, (VOID**)&ArmMpCoreInfoPpi); Status = GetPlatformPpi (&gArmMpCoreInfoPpiGuid, (VOID **)&ArmMpCoreInfoPpi);
// On MP Core Platform we must implement the ARM MP Core Info PPI (gArmMpCoreInfoPpiGuid) // On MP Core Platform we must implement the ARM MP Core Info PPI (gArmMpCoreInfoPpiGuid)
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
@ -122,7 +131,7 @@ PrePiMain (
// Build the MP Core Info Table // Build the MP Core Info Table
ArmCoreCount = 0; ArmCoreCount = 0;
Status = ArmMpCoreInfoPpi->GetMpCoreInfo (&ArmCoreCount, &ArmCoreInfoTable); Status = ArmMpCoreInfoPpi->GetMpCoreInfo (&ArmCoreCount, &ArmCoreInfoTable);
if (!EFI_ERROR(Status) && (ArmCoreCount > 0)) { if (!EFI_ERROR (Status) && (ArmCoreCount > 0)) {
// Build MPCore Info HOB // Build MPCore Info HOB
BuildGuidDataHob (&gArmMpCoreInfoGuid, ArmCoreInfoTable, sizeof (ARM_CORE_INFO) * ArmCoreCount); BuildGuidDataHob (&gArmMpCoreInfoGuid, ArmCoreInfoTable, sizeof (ARM_CORE_INFO) * ArmCoreCount);
} }
@ -185,9 +194,9 @@ CEntryPoint (
ArmEnableInstructionCache (); ArmEnableInstructionCache ();
// Define the Global Variable region when we are not running in XIP // Define the Global Variable region when we are not running in XIP
if (!IS_XIP()) { if (!IS_XIP ()) {
if (ArmPlatformIsPrimaryCore (MpId)) { if (ArmPlatformIsPrimaryCore (MpId)) {
if (ArmIsMpCore()) { if (ArmIsMpCore ()) {
// Signal the Global Variable Region is defined (event: ARM_CPU_EVENT_DEFAULT) // Signal the Global Variable Region is defined (event: ARM_CPU_EVENT_DEFAULT)
ArmCallSEV (); ArmCallSEV ();
} }
@ -199,9 +208,10 @@ CEntryPoint (
// If not primary Jump to Secondary Main // If not primary Jump to Secondary Main
if (ArmPlatformIsPrimaryCore (MpId)) { if (ArmPlatformIsPrimaryCore (MpId)) {
InvalidateDataCacheRange (
InvalidateDataCacheRange ((VOID *)UefiMemoryBase, (VOID *)UefiMemoryBase,
FixedPcdGet32 (PcdSystemMemoryUefiRegionSize)); FixedPcdGet32 (PcdSystemMemoryUefiRegionSize)
);
// Goto primary Main. // Goto primary Main.
PrimaryMain (UefiMemoryBase, StacksBase, StartTimeStamp); PrimaryMain (UefiMemoryBase, StacksBase, StartTimeStamp);