ueficirruslogic5430graphicsoutput.c
来自「EFI BIOS是Intel提出的下一代的BIOS标准。这里上传的Edk源代码是」· C语言 代码 · 共 1,045 行 · 第 1/3 页
C
1,045 行
Private = CIRRUS_LOGIC_5430_PRIVATE_DATA_FROM_GRAPHICS_OUTPUT_THIS (This);
if ((BltOperation < 0) || (BltOperation >= EfiGraphicsOutputBltOperationMax)) {
return EFI_INVALID_PARAMETER;
}
if (Width == 0 || Height == 0) {
return EFI_INVALID_PARAMETER;
}
//
// If Delta is zero, then the entire BltBuffer is being used, so Delta
// is the number of bytes in each row of BltBuffer. Since BltBuffer is Width pixels size,
// the number of bytes in each row can be computed.
//
if (Delta == 0) {
Delta = Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL);
}
//
// We need to fill the Virtual Screen buffer with the blt data.
// The virtual screen is upside down, as the first row is the bootom row of
// the image.
//
CurrentMode = This->Mode->Mode;
//
// Make sure the SourceX, SourceY, DestinationX, DestinationY, Width, and Height parameters
// are valid for the operation and the current screen geometry.
//
if (BltOperation == EfiBltVideoToBltBuffer) {
//
// Video to BltBuffer: Source is Video, destination is BltBuffer
//
if (SourceY + Height > Private->ModeData[CurrentMode].VerticalResolution) {
return EFI_INVALID_PARAMETER;
}
if (SourceX + Width > Private->ModeData[CurrentMode].HorizontalResolution) {
return EFI_INVALID_PARAMETER;
}
} else {
//
// BltBuffer to Video: Source is BltBuffer, destination is Video
//
if (DestinationY + Height > Private->ModeData[CurrentMode].VerticalResolution) {
return EFI_INVALID_PARAMETER;
}
if (DestinationX + Width > Private->ModeData[CurrentMode].HorizontalResolution) {
return EFI_INVALID_PARAMETER;
}
}
//
// We have to raise to TPL Notify, so we make an atomic write the frame buffer.
// We would not want a timer based event (Cursor, ...) to come in while we are
// doing this operation.
//
OriginalTPL = gBS->RaiseTPL (EFI_TPL_NOTIFY);
switch (BltOperation) {
case EfiBltVideoToBltBuffer:
//
// Video to BltBuffer: Source is Video, destination is BltBuffer
//
for (SrcY = SourceY, DstY = DestinationY; DstY < (Height + DestinationY); SrcY++, DstY++) {
Offset = (SrcY * Private->ModeData[CurrentMode].HorizontalResolution) + SourceX;
if (((Offset & 0x03) == 0) && ((Width & 0x03) == 0)) {
Private->PciIo->Mem.Read (
Private->PciIo,
EfiPciIoWidthUint32,
0,
Offset,
Width >> 2,
Private->LineBuffer
);
} else {
Private->PciIo->Mem.Read (
Private->PciIo,
EfiPciIoWidthUint8,
0,
Offset,
Width,
Private->LineBuffer
);
}
for (X = 0; X < Width; X++) {
Blt = (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) ((UINT8 *) BltBuffer + (DstY * Delta) + (DestinationX + X) * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
Blt->Red = (UINT8) (Private->LineBuffer[X] & 0xe0);
Blt->Green = (UINT8) ((Private->LineBuffer[X] & 0x1c) << 3);
Blt->Blue = (UINT8) ((Private->LineBuffer[X] & 0x03) << 6);
}
}
break;
case EfiBltVideoToVideo:
//
// Perform hardware acceleration for Video to Video operations
//
ScreenWidth = Private->ModeData[CurrentMode].HorizontalResolution;
SourceOffset = (SourceY * Private->ModeData[CurrentMode].HorizontalResolution) + (SourceX);
Offset = (DestinationY * Private->ModeData[CurrentMode].HorizontalResolution) + (DestinationX);
outw (Private, GRAPH_ADDRESS_REGISTER, 0x0000);
outw (Private, GRAPH_ADDRESS_REGISTER, 0x0010);
outw (Private, GRAPH_ADDRESS_REGISTER, 0x0012);
outw (Private, GRAPH_ADDRESS_REGISTER, 0x0014);
outw (Private, GRAPH_ADDRESS_REGISTER, 0x0001);
outw (Private, GRAPH_ADDRESS_REGISTER, 0x0011);
outw (Private, GRAPH_ADDRESS_REGISTER, 0x0013);
outw (Private, GRAPH_ADDRESS_REGISTER, 0x0015);
outw (Private, GRAPH_ADDRESS_REGISTER, (UINT16) (((Width << 8) & 0xff00) | 0x20));
outw (Private, GRAPH_ADDRESS_REGISTER, (UINT16) ((Width & 0xff00) | 0x21));
outw (Private, GRAPH_ADDRESS_REGISTER, (UINT16) (((Height << 8) & 0xff00) | 0x22));
outw (Private, GRAPH_ADDRESS_REGISTER, (UINT16) ((Height & 0xff00) | 0x23));
outw (Private, GRAPH_ADDRESS_REGISTER, (UINT16) (((ScreenWidth << 8) & 0xff00) | 0x24));
outw (Private, GRAPH_ADDRESS_REGISTER, (UINT16) ((ScreenWidth & 0xff00) | 0x25));
outw (Private, GRAPH_ADDRESS_REGISTER, (UINT16) (((ScreenWidth << 8) & 0xff00) | 0x26));
outw (Private, GRAPH_ADDRESS_REGISTER, (UINT16) ((ScreenWidth & 0xff00) | 0x27));
outw (Private, GRAPH_ADDRESS_REGISTER, (UINT16) ((((Offset) << 8) & 0xff00) | 0x28));
outw (Private, GRAPH_ADDRESS_REGISTER, (UINT16) ((((Offset) >> 0) & 0xff00) | 0x29));
outw (Private, GRAPH_ADDRESS_REGISTER, (UINT16) ((((Offset) >> 8) & 0xff00) | 0x2a));
outw (Private, GRAPH_ADDRESS_REGISTER, (UINT16) ((((SourceOffset) << 8) & 0xff00) | 0x2c));
outw (Private, GRAPH_ADDRESS_REGISTER, (UINT16) ((((SourceOffset) >> 0) & 0xff00) | 0x2d));
outw (Private, GRAPH_ADDRESS_REGISTER, (UINT16) ((((SourceOffset) >> 8) & 0xff00) | 0x2e));
outw (Private, GRAPH_ADDRESS_REGISTER, 0x002f);
outw (Private, GRAPH_ADDRESS_REGISTER, 0x0030);
outw (Private, GRAPH_ADDRESS_REGISTER, 0x0d32);
outw (Private, GRAPH_ADDRESS_REGISTER, 0x0033);
outw (Private, GRAPH_ADDRESS_REGISTER, 0x0034);
outw (Private, GRAPH_ADDRESS_REGISTER, 0x0035);
outw (Private, GRAPH_ADDRESS_REGISTER, 0x0231);
outb (Private, GRAPH_ADDRESS_REGISTER, 0x31);
while ((inb (Private, GRAPH_DATA_REGISTER) & 0x01) == 0x01)
;
break;
case EfiBltVideoFill:
Blt = BltBuffer;
Pixel = (UINT8) ((Blt->Red & 0xe0) | ((Blt->Green >> 3) & 0x1c) | ((Blt->Blue >> 6) & 0x03));
WidePixel = (Pixel << 8) | Pixel;
WidePixel = (WidePixel << 16) | WidePixel;
if (DestinationX == 0 && Width == Private->ModeData[CurrentMode].HorizontalResolution) {
Offset = DestinationY * Private->ModeData[CurrentMode].HorizontalResolution;
if (((Offset & 0x03) == 0) && (((Width * Height) & 0x03) == 0)) {
Private->PciIo->Mem.Write (
Private->PciIo,
EfiPciIoWidthFillUint32,
0,
Offset,
(Width * Height) >> 2,
&WidePixel
);
} else {
Private->PciIo->Mem.Write (
Private->PciIo,
EfiPciIoWidthFillUint8,
0,
Offset,
Width * Height,
&Pixel
);
}
} else {
for (SrcY = SourceY, DstY = DestinationY; SrcY < (Height + SourceY); SrcY++, DstY++) {
Offset = (DstY * Private->ModeData[CurrentMode].HorizontalResolution) + DestinationX;
if (((Offset & 0x03) == 0) && ((Width & 0x03) == 0)) {
Private->PciIo->Mem.Write (
Private->PciIo,
EfiPciIoWidthFillUint32,
0,
Offset,
Width >> 2,
&WidePixel
);
} else {
Private->PciIo->Mem.Write (
Private->PciIo,
EfiPciIoWidthFillUint8,
0,
Offset,
Width,
&Pixel
);
}
}
}
break;
case EfiBltBufferToVideo:
for (SrcY = SourceY, DstY = DestinationY; SrcY < (Height + SourceY); SrcY++, DstY++) {
for (X = 0; X < Width; X++) {
Blt = (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) ((UINT8 *) BltBuffer + (SrcY * Delta) + (SourceX + X) * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
Private->LineBuffer[X] = (UINT8) ((Blt->Red & 0xe0) | ((Blt->Green >> 3) & 0x1c) | ((Blt->Blue >> 6) & 0x03));
}
Offset = (DstY * Private->ModeData[CurrentMode].HorizontalResolution) + DestinationX;
if (((Offset & 0x03) == 0) && ((Width & 0x03) == 0)) {
Private->PciIo->Mem.Write (
Private->PciIo,
EfiPciIoWidthUint32,
0,
Offset,
Width >> 2,
Private->LineBuffer
);
} else {
Private->PciIo->Mem.Write (
Private->PciIo,
EfiPciIoWidthUint8,
0,
Offset,
Width,
Private->LineBuffer
);
}
}
break;
}
gBS->RestoreTPL (OriginalTPL);
return EFI_SUCCESS;
}
//
// Construction and Destruction functions
//
EFI_STATUS
CirrusLogic5430GraphicsOutputConstructor (
CIRRUS_LOGIC_5430_PRIVATE_DATA *Private
)
/*++
Routine Description:
Arguments:
Returns:
None
--*/
// TODO: Private - add argument and description to function comment
// TODO: EFI_SUCCESS - add return value to function comment
{
EFI_STATUS Status;
EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
UINTN Index;
//
// Fill in Private->GraphicsOutput protocol
//
GraphicsOutput = &Private->GraphicsOutput;
GraphicsOutput->QueryMode = CirrusLogic5430GraphicsOutputQueryMode;
GraphicsOutput->SetMode = CirrusLogic5430GraphicsOutputSetMode;
GraphicsOutput->Blt = CirrusLogic5430GraphicsOutputBlt;
//
// Initialize the private data
//
Status = gBS->AllocatePool (
EfiBootServicesData,
sizeof (EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE),
(VOID **) &Private->GraphicsOutput.Mode
);
if (EFI_ERROR (Status)) {
return Status;
}
Status = gBS->AllocatePool (
EfiBootServicesData,
sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION),
(VOID **) &Private->GraphicsOutput.Mode->Info
);
if (EFI_ERROR (Status)) {
return Status;
}
Private->GraphicsOutput.Mode->MaxMode = CIRRUS_LOGIC_5430_GRAPHICS_OUTPUT_MODE_COUNT;
Private->GraphicsOutput.Mode->Mode = GRAPHICS_OUTPUT_INVALIDE_MODE_NUMBER;
for (Index = 0; Index < Private->GraphicsOutput.Mode->MaxMode; Index++) {
Private->ModeData[Index].HorizontalResolution = CirrusLogic5430VideoModes[Index].Width;
Private->ModeData[Index].VerticalResolution = CirrusLogic5430VideoModes[Index].Height;
Private->ModeData[Index].ColorDepth = 32;
Private->ModeData[Index].RefreshRate = CirrusLogic5430VideoModes[Index].RefreshRate;
}
Private->HardwareNeedsStarting = TRUE;
Private->LineBuffer = NULL;
//
// Initialize the hardware
//
GraphicsOutput->SetMode (GraphicsOutput, 0);
DrawLogo (Private);
return EFI_SUCCESS;
}
EFI_STATUS
CirrusLogic5430GraphicsOutputDestructor (
CIRRUS_LOGIC_5430_PRIVATE_DATA *Private
)
/*++
Routine Description:
Arguments:
Returns:
None
--*/
// TODO: Private - add argument and description to function comment
// TODO: EFI_SUCCESS - add return value to function comment
{
if (Private->GraphicsOutput.Mode != NULL) {
if (Private->GraphicsOutput.Mode->Info != NULL) {
gBS->FreePool (Private->GraphicsOutput.Mode->Info);
}
gBS->FreePool (Private->GraphicsOutput.Mode);
}
return EFI_SUCCESS;
}
VOID
outb (
CIRRUS_LOGIC_5430_PRIVATE_DATA *Private,
UINTN Address,
UINT8 Data
)
/*++
Routine Description:
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?