--- /dev/null
+/** @file\r
+ UEFI Component Name(2) protocol implementation for the generic GOP driver.\r
+\r
+Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution. The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+\r
+**/\r
+\r
+#include <PiDxe.h>\r
+#include <Library/UefiLib.h>\r
+\r
+extern EFI_COMPONENT_NAME_PROTOCOL mGraphicsOutputComponentName;\r
+extern EFI_COMPONENT_NAME2_PROTOCOL mGraphicsOutputComponentName2;\r
+\r
+//\r
+// Driver name table for GraphicsOutput module.\r
+// It is shared by the implementation of ComponentName & ComponentName2 Protocol.\r
+//\r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mGraphicsOutputDriverNameTable[] = {\r
+ {\r
+ "eng;en",\r
+ L"Generic Graphics Output Driver"\r
+ },\r
+ {\r
+ NULL,\r
+ NULL\r
+ }\r
+};\r
+\r
+/**\r
+ Retrieves a Unicode string that is the user readable name of the driver.\r
+\r
+ This function retrieves the user readable name of a driver in the form of a\r
+ Unicode string. If the driver specified by This has a user readable name in\r
+ the language specified by Language, then a pointer to the driver name is\r
+ returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r
+ by This does not support the language specified by Language,\r
+ then EFI_UNSUPPORTED is returned.\r
+\r
+ @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
+ EFI_COMPONENT_NAME_PROTOCOL instance.\r
+\r
+ @param Language[in] A pointer to a Null-terminated ASCII string\r
+ array indicating the language. This is the\r
+ language of the driver name that the caller is\r
+ requesting, and it must match one of the\r
+ languages specified in SupportedLanguages. The\r
+ number of languages supported by a driver is up\r
+ to the driver writer. Language is specified\r
+ in RFC 4646 or ISO 639-2 language code format.\r
+\r
+ @param DriverName[out] A pointer to the Unicode string to return.\r
+ This Unicode string is the name of the\r
+ driver specified by This in the language\r
+ specified by Language.\r
+\r
+ @retval EFI_SUCCESS The Unicode string for the Driver specified by\r
+ This and the language specified by Language was\r
+ returned in DriverName.\r
+\r
+ @retval EFI_INVALID_PARAMETER Language is NULL.\r
+\r
+ @retval EFI_INVALID_PARAMETER DriverName is NULL.\r
+\r
+ @retval EFI_UNSUPPORTED The driver specified by This does not support\r
+ the language specified by Language.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+GraphicsOutputComponentNameGetDriverName (\r
+ IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
+ IN CHAR8 *Language,\r
+ OUT CHAR16 **DriverName\r
+ )\r
+{\r
+ return LookupUnicodeString2 (\r
+ Language,\r
+ This->SupportedLanguages,\r
+ mGraphicsOutputDriverNameTable,\r
+ DriverName,\r
+ (BOOLEAN) (This == &mGraphicsOutputComponentName)\r
+ );\r
+}\r
+\r
+/**\r
+ Retrieves a Unicode string that is the user readable name of the controller\r
+ that is being managed by a driver.\r
+\r
+ This function retrieves the user readable name of the controller specified by\r
+ ControllerHandle and ChildHandle in the form of a Unicode string. If the\r
+ driver specified by This has a user readable name in the language specified by\r
+ Language, then a pointer to the controller name is returned in ControllerName,\r
+ and EFI_SUCCESS is returned. If the driver specified by This is not currently\r
+ managing the controller specified by ControllerHandle and ChildHandle,\r
+ then EFI_UNSUPPORTED is returned. If the driver specified by This does not\r
+ support the language specified by Language, then EFI_UNSUPPORTED is returned.\r
+\r
+ @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
+ EFI_COMPONENT_NAME_PROTOCOL instance.\r
+\r
+ @param ControllerHandle[in] The handle of a controller that the driver\r
+ specified by This is managing. This handle\r
+ specifies the controller whose name is to be\r
+ returned.\r
+\r
+ @param ChildHandle[in] The handle of the child controller to retrieve\r
+ the name of. This is an optional parameter that\r
+ may be NULL. It will be NULL for device\r
+ drivers. It will also be NULL for a bus drivers\r
+ that wish to retrieve the name of the bus\r
+ controller. It will not be NULL for a bus\r
+ driver that wishes to retrieve the name of a\r
+ child controller.\r
+\r
+ @param Language[in] A pointer to a Null-terminated ASCII string\r
+ array indicating the language. This is the\r
+ language of the driver name that the caller is\r
+ requesting, and it must match one of the\r
+ languages specified in SupportedLanguages. The\r
+ number of languages supported by a driver is up\r
+ to the driver writer. Language is specified in\r
+ RFC 4646 or ISO 639-2 language code format.\r
+\r
+ @param ControllerName[out] A pointer to the Unicode string to return.\r
+ This Unicode string is the name of the\r
+ controller specified by ControllerHandle and\r
+ ChildHandle in the language specified by\r
+ Language from the point of view of the driver\r
+ specified by This.\r
+\r
+ @retval EFI_SUCCESS The Unicode string for the user readable name in\r
+ the language specified by Language for the\r
+ driver specified by This was returned in\r
+ DriverName.\r
+\r
+ @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r
+\r
+ @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r
+ EFI_HANDLE.\r
+\r
+ @retval EFI_INVALID_PARAMETER Language is NULL.\r
+\r
+ @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
+\r
+ @retval EFI_UNSUPPORTED The driver specified by This is not currently\r
+ managing the controller specified by\r
+ ControllerHandle and ChildHandle.\r
+\r
+ @retval EFI_UNSUPPORTED The driver specified by This does not support\r
+ the language specified by Language.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+GraphicsOutputComponentNameGetControllerName (\r
+ IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
+ IN EFI_HANDLE ControllerHandle,\r
+ IN EFI_HANDLE ChildHandle OPTIONAL,\r
+ IN CHAR8 *Language,\r
+ OUT CHAR16 **ControllerName\r
+ )\r
+{\r
+ return EFI_UNSUPPORTED;\r
+}\r
+\r
+//\r
+// EFI Component Name Protocol\r
+//\r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL mGraphicsOutputComponentName = {\r
+ GraphicsOutputComponentNameGetDriverName,\r
+ GraphicsOutputComponentNameGetControllerName,\r
+ "eng"\r
+};\r
+\r
+//\r
+// EFI Component Name 2 Protocol\r
+//\r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL mGraphicsOutputComponentName2 = {\r
+ (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) GraphicsOutputComponentNameGetDriverName,\r
+ (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) GraphicsOutputComponentNameGetControllerName,\r
+ "en"\r
+};\r
--- /dev/null
+/** @file\r
+ Implementation for a generic GOP driver.\r
+\r
+Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution. The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+\r
+**/\r
+\r
+#include "GraphicsOutput.h"\r
+CONST ACPI_ADR_DEVICE_PATH mGraphicsOutputAdrNode = {\r
+ {\r
+ ACPI_DEVICE_PATH,\r
+ ACPI_ADR_DP,\r
+ { sizeof (ACPI_ADR_DEVICE_PATH), 0 },\r
+ },\r
+ ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_VGA, 0, 0)\r
+};\r
+\r
+EFI_PEI_GRAPHICS_DEVICE_INFO_HOB mDefaultGraphicsDeviceInfo = {\r
+ MAX_UINT16, MAX_UINT16, MAX_UINT16, MAX_UINT16, MAX_UINT8, MAX_UINT8\r
+};\r
+\r
+//\r
+// The driver should only start on one graphics controller.\r
+// So a global flag is used to remember that the driver is already started.\r
+//\r
+BOOLEAN mDriverStarted = FALSE;\r
+\r
+/**\r
+ Returns information for an available graphics mode that the graphics device\r
+ and the set of active video output devices supports.\r
+\r
+ @param This The EFI_GRAPHICS_OUTPUT_PROTOCOL instance.\r
+ @param ModeNumber The mode number to return information on.\r
+ @param SizeOfInfo A pointer to the size, in bytes, of the Info buffer.\r
+ @param Info A pointer to callee allocated buffer that returns information about ModeNumber.\r
+\r
+ @retval EFI_SUCCESS Valid mode information was returned.\r
+ @retval EFI_DEVICE_ERROR A hardware error occurred trying to retrieve the video mode.\r
+ @retval EFI_INVALID_PARAMETER ModeNumber is not valid.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+GraphicsOutputQueryMode (\r
+ IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This,\r
+ IN UINT32 ModeNumber,\r
+ OUT UINTN *SizeOfInfo,\r
+ OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION **Info\r
+ )\r
+{\r
+ if (This == NULL || Info == NULL || SizeOfInfo == NULL || ModeNumber >= This->Mode->MaxMode) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ *SizeOfInfo = This->Mode->SizeOfInfo;\r
+ *Info = AllocateCopyPool (*SizeOfInfo, This->Mode->Info);\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+ Set the video device into the specified mode and clears the visible portions of\r
+ the output display to black.\r
+\r
+ @param This The EFI_GRAPHICS_OUTPUT_PROTOCOL instance.\r
+ @param ModeNumber Abstraction that defines the current video mode.\r
+\r
+ @retval EFI_SUCCESS The graphics mode specified by ModeNumber was selected.\r
+ @retval EFI_DEVICE_ERROR The device had an error and could not complete the request.\r
+ @retval EFI_UNSUPPORTED ModeNumber is not supported by this device.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+GraphicsOutputSetMode (\r
+ IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This,\r
+ IN UINT32 ModeNumber\r
+)\r
+{\r
+ RETURN_STATUS Status;\r
+ EFI_GRAPHICS_OUTPUT_BLT_PIXEL Black;\r
+ GRAPHICS_OUTPUT_PRIVATE_DATA *Private;\r
+\r
+ if (ModeNumber >= This->Mode->MaxMode) {\r
+ return EFI_UNSUPPORTED;\r
+ }\r
+\r
+ Private = GRAPHICS_OUTPUT_PRIVATE_FROM_THIS (This);\r
+\r
+ Black.Blue = 0;\r
+ Black.Green = 0;\r
+ Black.Red = 0;\r
+ Black.Reserved = 0;\r
+\r
+ Status = FrameBufferBlt (\r
+ Private->FrameBufferBltLibConfigure,\r
+ &Black,\r
+ EfiBltVideoFill,\r
+ 0, 0,\r
+ 0, 0,\r
+ This->Mode->Info->HorizontalResolution,\r
+ This->Mode->Info->VerticalResolution,\r
+ 0\r
+ );\r
+ return RETURN_ERROR (Status) ? EFI_DEVICE_ERROR : EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+ Blt a rectangle of pixels on the graphics screen. Blt stands for BLock Transfer.\r
+\r
+ @param This Protocol instance pointer.\r
+ @param BltBuffer The data to transfer to the graphics screen.\r
+ Size is at least Width*Height*sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL).\r
+ @param BltOperation The operation to perform when copying BltBuffer on to the graphics screen.\r
+ @param SourceX The X coordinate of source for the BltOperation.\r
+ @param SourceY The Y coordinate of source for the BltOperation.\r
+ @param DestinationX The X coordinate of destination for the BltOperation.\r
+ @param DestinationY The Y coordinate of destination for the BltOperation.\r
+ @param Width The width of a rectangle in the blt rectangle in pixels.\r
+ @param Height The height of a rectangle in the blt rectangle in pixels.\r
+ @param Delta Not used for EfiBltVideoFill or the EfiBltVideoToVideo operation.\r
+ If a Delta of zero is used, the entire BltBuffer is being operated on.\r
+ If a subrectangle of the BltBuffer is being used then Delta\r
+ represents the number of bytes in a row of the BltBuffer.\r
+\r
+ @retval EFI_SUCCESS BltBuffer was drawn to the graphics screen.\r
+ @retval EFI_INVALID_PARAMETER BltOperation is not valid.\r
+ @retval EFI_DEVICE_ERROR The device had an error and could not complete the request.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+GraphicsOutputBlt (\r
+ IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This,\r
+ IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer, OPTIONAL\r
+ IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation,\r
+ IN UINTN SourceX,\r
+ IN UINTN SourceY,\r
+ IN UINTN DestinationX,\r
+ IN UINTN DestinationY,\r
+ IN UINTN Width,\r
+ IN UINTN Height,\r
+ IN UINTN Delta OPTIONAL\r
+ )\r
+{\r
+ RETURN_STATUS Status;\r
+ EFI_TPL Tpl;\r
+ GRAPHICS_OUTPUT_PRIVATE_DATA *Private;\r
+\r
+ Private = GRAPHICS_OUTPUT_PRIVATE_FROM_THIS (This);\r
+ //\r
+ // We have to raise to TPL_NOTIFY, so we make an atomic write to the frame buffer.\r
+ // We would not want a timer based event (Cursor, ...) to come in while we are\r
+ // doing this operation.\r
+ //\r
+ Tpl = gBS->RaiseTPL (TPL_NOTIFY);\r
+ Status = FrameBufferBlt (\r
+ Private->FrameBufferBltLibConfigure,\r
+ BltBuffer,\r
+ BltOperation,\r
+ SourceX, SourceY,\r
+ DestinationX, DestinationY, Width, Height,\r
+ Delta\r
+ );\r
+ gBS->RestoreTPL (Tpl);\r
+\r
+ return RETURN_ERROR (Status) ? EFI_INVALID_PARAMETER : EFI_SUCCESS;\r
+}\r
+\r
+CONST GRAPHICS_OUTPUT_PRIVATE_DATA mGraphicsOutputInstanceTemplate = {\r
+ GRAPHICS_OUTPUT_PRIVATE_DATA_SIGNATURE, // Signature\r
+ NULL, // GraphicsOutputHandle\r
+ {\r
+ GraphicsOutputQueryMode,\r
+ GraphicsOutputSetMode,\r
+ GraphicsOutputBlt,\r
+ NULL // Mode\r
+ },\r
+ {\r
+ 1, // MaxMode\r
+ 0, // Mode\r
+ NULL, // Info\r
+ sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION), // SizeOfInfo\r
+ 0, // FrameBufferBase\r
+ 0 // FrameBufferSize\r
+ },\r
+ NULL, // DevicePath\r
+ NULL, // PciIo\r
+ 0, // PciAttributes\r
+ NULL, // FrameBufferBltLibConfigure\r
+ 0 // FrameBufferBltLibConfigureSize\r
+};\r
+\r
+/**\r
+ Test whether the Controller can be managed by the driver.\r
+\r
+ @param This Driver Binding protocol instance pointer.\r
+ @param Controller The PCI controller.\r
+ @param RemainingDevicePath Optional parameter use to pick a specific child\r
+ device to start.\r
+\r
+ @retval EFI_SUCCESS The driver can manage the video device.\r
+ @retval other The driver cannot manage the video device.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+GraphicsOutputDriverBindingSupported (\r
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
+ IN EFI_HANDLE Controller,\r
+ IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ EFI_PCI_IO_PROTOCOL *PciIo;\r
+ EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
+\r
+ //\r
+ // Since there is only one GraphicsInfo HOB, the driver only manages one video device.\r
+ //\r
+ if (mDriverStarted) {\r
+ return EFI_ALREADY_STARTED;\r
+ }\r
+\r
+ //\r
+ // Test the PCI I/O Protocol\r
+ //\r
+ Status = gBS->OpenProtocol (\r
+ Controller,\r
+ &gEfiPciIoProtocolGuid,\r
+ (VOID **) &PciIo,\r
+ This->DriverBindingHandle,\r
+ Controller,\r
+ EFI_OPEN_PROTOCOL_BY_DRIVER\r
+ );\r
+ if (Status == EFI_ALREADY_STARTED) {\r
+ Status = EFI_SUCCESS;\r
+ }\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+ gBS->CloseProtocol (\r
+ Controller,\r
+ &gEfiPciIoProtocolGuid,\r
+ This->DriverBindingHandle,\r
+ Controller\r
+ );\r
+\r
+ //\r
+ // Test the DevicePath protocol\r
+ //\r
+ Status = gBS->OpenProtocol (\r
+ Controller,\r
+ &gEfiDevicePathProtocolGuid,\r
+ (VOID **) &DevicePath,\r
+ This->DriverBindingHandle,\r
+ Controller,\r
+ EFI_OPEN_PROTOCOL_BY_DRIVER\r
+ );\r
+ if (Status == EFI_ALREADY_STARTED) {\r
+ Status = EFI_SUCCESS;\r
+ }\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+ gBS->CloseProtocol (\r
+ Controller,\r
+ &gEfiDevicePathProtocolGuid,\r
+ This->DriverBindingHandle,\r
+ Controller\r
+ );\r
+\r
+ if ((RemainingDevicePath == NULL) ||\r
+ IsDevicePathEnd (RemainingDevicePath) ||\r
+ CompareMem (RemainingDevicePath, &mGraphicsOutputAdrNode, sizeof (mGraphicsOutputAdrNode)) == 0) {\r
+ return EFI_SUCCESS;\r
+ } else {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+}\r
+\r
+/**\r
+ Start the video controller.\r
+\r
+ @param This Driver Binding protocol instance pointer.\r
+ @param ControllerHandle The PCI controller.\r
+ @param RemainingDevicePath Optional parameter use to pick a specific child\r
+ device to start.\r
+\r
+ @retval EFI_SUCCESS The driver starts to manage the video device.\r
+ @retval other The driver cannot manage the video device.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+GraphicsOutputDriverBindingStart (\r
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
+ IN EFI_HANDLE Controller,\r
+ IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ RETURN_STATUS ReturnStatus;\r
+ GRAPHICS_OUTPUT_PRIVATE_DATA *Private;\r
+ EFI_PCI_IO_PROTOCOL *PciIo;\r
+ EFI_DEVICE_PATH *PciDevicePath;\r
+ PCI_TYPE00 Pci;\r
+ UINT8 Index;\r
+ EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Resources;\r
+ VOID *HobStart;\r
+ EFI_PEI_GRAPHICS_INFO_HOB *GraphicsInfo;\r
+ EFI_PEI_GRAPHICS_DEVICE_INFO_HOB *DeviceInfo;\r
+ EFI_PHYSICAL_ADDRESS FrameBufferBase;\r
+\r
+ FrameBufferBase = 0;\r
+\r
+ HobStart = GetFirstGuidHob (&gEfiGraphicsInfoHobGuid);\r
+ ASSERT ((HobStart != NULL) && (GET_GUID_HOB_DATA_SIZE (HobStart) == sizeof (EFI_PEI_GRAPHICS_INFO_HOB)));\r
+ GraphicsInfo = (EFI_PEI_GRAPHICS_INFO_HOB *) (GET_GUID_HOB_DATA (HobStart));\r
+\r
+ HobStart = GetFirstGuidHob (&gEfiGraphicsDeviceInfoHobGuid);\r
+ if ((HobStart == NULL) || (GET_GUID_HOB_DATA_SIZE (HobStart) < sizeof (*DeviceInfo))) {\r
+ //\r
+ // Use default device infomation when the device info HOB doesn't exist\r
+ //\r
+ DeviceInfo = &mDefaultGraphicsDeviceInfo;\r
+ DEBUG ((EFI_D_INFO, "[%a]: GraphicsDeviceInfo HOB doesn't exist!\n", gEfiCallerBaseName));\r
+ } else {\r
+ DeviceInfo = (EFI_PEI_GRAPHICS_DEVICE_INFO_HOB *) (GET_GUID_HOB_DATA (HobStart));\r
+ DEBUG ((EFI_D_INFO, "[%a]: GraphicsDeviceInfo HOB:\n"\r
+ " VendorId = %04x, DeviceId = %04x,\n"\r
+ " RevisionId = %02x, BarIndex = %x,\n"\r
+ " SubsystemVendorId = %04x, SubsystemId = %04x\n",\r
+ gEfiCallerBaseName,\r
+ DeviceInfo->VendorId, DeviceInfo->DeviceId,\r
+ DeviceInfo->RevisionId, DeviceInfo->BarIndex,\r
+ DeviceInfo->SubsystemVendorId, DeviceInfo->SubsystemId));\r
+ }\r
+\r
+ //\r
+ // Open the PCI I/O Protocol\r
+ //\r
+ Status = gBS->OpenProtocol (\r
+ Controller,\r
+ &gEfiPciIoProtocolGuid,\r
+ (VOID **) &PciIo,\r
+ This->DriverBindingHandle,\r
+ Controller,\r
+ EFI_OPEN_PROTOCOL_BY_DRIVER\r
+ );\r
+ if (Status == EFI_ALREADY_STARTED) {\r
+ Status = EFI_SUCCESS;\r
+ }\r
+ ASSERT_EFI_ERROR (Status);\r
+\r
+ Status = gBS->OpenProtocol (\r
+ Controller,\r
+ &gEfiDevicePathProtocolGuid,\r
+ (VOID **) &PciDevicePath,\r
+ This->DriverBindingHandle,\r
+ Controller,\r
+ EFI_OPEN_PROTOCOL_BY_DRIVER\r
+ );\r
+ if (Status == EFI_ALREADY_STARTED) {\r
+ Status = EFI_SUCCESS;\r
+ }\r
+ ASSERT_EFI_ERROR (Status);\r
+\r
+ //\r
+ // Read the PCI Class Code from the PCI Device\r
+ //\r
+ Status = PciIo->Pci.Read (PciIo, EfiPciIoWidthUint8, 0, sizeof (Pci), &Pci);\r
+ if (!EFI_ERROR (Status)) {\r
+ if (!IS_PCI_DISPLAY (&Pci) || (\r
+ ((DeviceInfo->VendorId != MAX_UINT16) && (DeviceInfo->VendorId != Pci.Hdr.VendorId)) ||\r
+ ((DeviceInfo->DeviceId != MAX_UINT16) && (DeviceInfo->DeviceId != Pci.Hdr.DeviceId)) ||\r
+ ((DeviceInfo->RevisionId != MAX_UINT8) && (DeviceInfo->RevisionId != Pci.Hdr.RevisionID)) ||\r
+ ((DeviceInfo->SubsystemVendorId != MAX_UINT16) && (DeviceInfo->SubsystemVendorId != Pci.Device.SubsystemVendorID)) ||\r
+ ((DeviceInfo->SubsystemId != MAX_UINT16) && (DeviceInfo->SubsystemId != Pci.Device.SubsystemID))\r
+ )\r
+ ) {\r
+ //\r
+ // It's not a video device, or device infomation doesn't match.\r
+ //\r
+ Status = EFI_UNSUPPORTED;\r
+ } else {\r
+ //\r
+ // If it's a video device and device information matches, use the BarIndex\r
+ // from device information, or any BAR if BarIndex is not specified\r
+ // whose size >= the frame buffer size from GraphicsInfo HOB.\r
+ // Store the new frame buffer base.\r
+ //\r
+ for (Index = 0; Index < MAX_PCI_BAR; Index++) {\r
+ if ((DeviceInfo->BarIndex != MAX_UINT8) && (DeviceInfo->BarIndex != Index)) {\r
+ continue;\r
+ }\r
+ Status = PciIo->GetBarAttributes (PciIo, Index, NULL, (VOID**) &Resources);\r
+ if (!EFI_ERROR (Status)) {\r
+ DEBUG ((EFI_D_INFO, "[%a]: BAR[%d]: Base = %lx, Length = %lx\n",\r
+ gEfiCallerBaseName, Index, Resources->AddrRangeMin, Resources->AddrLen));\r
+ if ((Resources->Desc == ACPI_ADDRESS_SPACE_DESCRIPTOR) &&\r
+ (Resources->Len == (UINT16) (sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR) - 3)) &&\r
+ (Resources->ResType == ACPI_ADDRESS_SPACE_TYPE_MEM) &&\r
+ (Resources->AddrLen >= GraphicsInfo->FrameBufferSize)\r
+ ) {\r
+ FrameBufferBase = Resources->AddrRangeMin;\r
+ DEBUG ((EFI_D_INFO, "[%a]: ... matched!\n", gEfiCallerBaseName));\r
+ break;\r
+ }\r
+ }\r
+ }\r
+ if (Index == MAX_PCI_BAR) {\r
+ Status = EFI_UNSUPPORTED;\r
+ }\r
+ }\r
+ }\r
+\r
+ if (EFI_ERROR (Status)) {\r
+ goto CloseProtocols;\r
+ }\r
+\r
+ if ((RemainingDevicePath != NULL) && IsDevicePathEnd (RemainingDevicePath)) {\r
+ return EFI_SUCCESS;\r
+ }\r
+\r
+ Private = AllocateCopyPool (sizeof (mGraphicsOutputInstanceTemplate), &mGraphicsOutputInstanceTemplate);\r
+ if (Private == NULL) {\r
+ Status = EFI_OUT_OF_RESOURCES;\r
+ goto CloseProtocols;\r
+ }\r
+\r
+ Private->GraphicsOutputMode.FrameBufferBase = FrameBufferBase;\r
+ Private->GraphicsOutputMode.FrameBufferSize = GraphicsInfo->FrameBufferSize;\r
+ Private->GraphicsOutputMode.Info = &GraphicsInfo->GraphicsMode;\r
+\r
+ //\r
+ // Fix up Mode pointer in GraphicsOutput\r
+ //\r
+ Private->GraphicsOutput.Mode = &Private->GraphicsOutputMode;\r
+\r
+ //\r
+ // Set attributes\r
+ //\r
+ Status = PciIo->Attributes (\r
+ PciIo,\r
+ EfiPciIoAttributeOperationGet,\r
+ 0,\r
+ &Private->PciAttributes\r
+ );\r
+ if (!EFI_ERROR (Status)) {\r
+ Status = PciIo->Attributes (\r
+ PciIo,\r
+ EfiPciIoAttributeOperationEnable,\r
+ EFI_PCI_DEVICE_ENABLE,\r
+ NULL\r
+ );\r
+ }\r
+\r
+ if (EFI_ERROR (Status)) {\r
+ goto FreeMemory;\r
+ }\r
+\r
+ //\r
+ // Create the FrameBufferBltLib configuration.\r
+ //\r
+ ReturnStatus = FrameBufferBltConfigure (\r
+ (VOID *) (UINTN) Private->GraphicsOutput.Mode->FrameBufferBase,\r
+ Private->GraphicsOutput.Mode->Info,\r
+ Private->FrameBufferBltLibConfigure,\r
+ &Private->FrameBufferBltLibConfigureSize\r
+ );\r
+ if (ReturnStatus == RETURN_BUFFER_TOO_SMALL) {\r
+ Private->FrameBufferBltLibConfigure = AllocatePool (Private->FrameBufferBltLibConfigureSize);\r
+ if (Private->FrameBufferBltLibConfigure != NULL) {\r
+ ReturnStatus = FrameBufferBltConfigure (\r
+ (VOID *) (UINTN) Private->GraphicsOutput.Mode->FrameBufferBase,\r
+ Private->GraphicsOutput.Mode->Info,\r
+ Private->FrameBufferBltLibConfigure,\r
+ &Private->FrameBufferBltLibConfigureSize\r
+ );\r
+ }\r
+ }\r
+ if (RETURN_ERROR (ReturnStatus)) {\r
+ Status = EFI_OUT_OF_RESOURCES;\r
+ goto RestorePciAttributes;\r
+ }\r
+\r
+ Private->DevicePath = AppendDevicePathNode (PciDevicePath, (EFI_DEVICE_PATH_PROTOCOL *) &mGraphicsOutputAdrNode);\r
+ if (Private->DevicePath == NULL) {\r
+ Status = EFI_OUT_OF_RESOURCES;\r
+ goto RestorePciAttributes;\r
+ }\r
+\r
+ Status = gBS->InstallMultipleProtocolInterfaces (\r
+ &Private->GraphicsOutputHandle,\r
+ &gEfiGraphicsOutputProtocolGuid, &Private->GraphicsOutput,\r
+ &gEfiDevicePathProtocolGuid, Private->DevicePath,\r
+ NULL\r
+ );\r
+\r
+ if (!EFI_ERROR (Status)) {\r
+ Status = gBS->OpenProtocol (\r
+ Controller,\r
+ &gEfiPciIoProtocolGuid,\r
+ (VOID **) &Private->PciIo,\r
+ This->DriverBindingHandle,\r
+ Private->GraphicsOutputHandle,\r
+ EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
+ );\r
+ if (!EFI_ERROR (Status)) {\r
+ mDriverStarted = TRUE;\r
+ } else {\r
+ gBS->UninstallMultipleProtocolInterfaces (\r
+ Private->GraphicsOutputHandle,\r
+ &gEfiGraphicsOutputProtocolGuid, &Private->GraphicsOutput,\r
+ &gEfiDevicePathProtocolGuid, Private->DevicePath,\r
+ NULL\r
+ );\r
+ }\r
+ }\r
+\r
+RestorePciAttributes:\r
+ if (EFI_ERROR (Status)) {\r
+ //\r
+ // Restore original PCI attributes\r
+ //\r
+ PciIo->Attributes (\r
+ PciIo,\r
+ EfiPciIoAttributeOperationSet,\r
+ Private->PciAttributes,\r
+ NULL\r
+ );\r
+ }\r
+\r
+FreeMemory:\r
+ if (EFI_ERROR (Status)) {\r
+ if (Private != NULL) {\r
+ if (Private->DevicePath != NULL) {\r
+ FreePool (Private->DevicePath);\r
+ }\r
+ if (Private->FrameBufferBltLibConfigure != NULL) {\r
+ FreePool (Private->FrameBufferBltLibConfigure);\r
+ }\r
+ FreePool (Private);\r
+ }\r
+ }\r
+\r
+CloseProtocols:\r
+ if (EFI_ERROR (Status)) {\r
+ //\r
+ // Close the PCI I/O Protocol\r
+ //\r
+ gBS->CloseProtocol (\r
+ Controller,\r
+ &gEfiDevicePathProtocolGuid,\r
+ This->DriverBindingHandle,\r
+ Controller\r
+ );\r
+\r
+ //\r
+ // Close the PCI I/O Protocol\r
+ //\r
+ gBS->CloseProtocol (\r
+ Controller,\r
+ &gEfiPciIoProtocolGuid,\r
+ This->DriverBindingHandle,\r
+ Controller\r
+ );\r
+ }\r
+ return Status;\r
+}\r
+\r
+/**\r
+ Stop the video controller.\r
+\r
+ @param This Driver Binding protocol instance pointer.\r
+ @param Controller The PCI controller.\r
+ @param NumberOfChildren The number of child device handles in ChildHandleBuffer.\r
+ @param ChildHandleBuffer An array of child handles to be freed. May be NULL\r
+ if NumberOfChildren is 0.\r
+\r
+ @retval EFI_SUCCESS The device was stopped.\r
+ @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+GraphicsOutputDriverBindingStop (\r
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
+ IN EFI_HANDLE Controller,\r
+ IN UINTN NumberOfChildren,\r
+ IN EFI_HANDLE *ChildHandleBuffer\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ EFI_GRAPHICS_OUTPUT_PROTOCOL *Gop;\r
+ GRAPHICS_OUTPUT_PRIVATE_DATA *Private;\r
+\r
+ if (NumberOfChildren == 0) {\r
+\r
+ //\r
+ // Close the PCI I/O Protocol\r
+ //\r
+ Status = gBS->CloseProtocol (\r
+ Controller,\r
+ &gEfiPciIoProtocolGuid,\r
+ This->DriverBindingHandle,\r
+ Controller\r
+ );\r
+ ASSERT_EFI_ERROR (Status);\r
+\r
+ Status = gBS->CloseProtocol (\r
+ Controller,\r
+ &gEfiDevicePathProtocolGuid,\r
+ This->DriverBindingHandle,\r
+ Controller\r
+ );\r
+ ASSERT_EFI_ERROR (Status);\r
+ return EFI_SUCCESS;\r
+ }\r
+\r
+ ASSERT (NumberOfChildren == 1);\r
+ Status = gBS->OpenProtocol (\r
+ ChildHandleBuffer[0],\r
+ &gEfiGraphicsOutputProtocolGuid,\r
+ (VOID **) &Gop,\r
+ This->DriverBindingHandle,\r
+ ChildHandleBuffer[0],\r
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+\r
+ Private = GRAPHICS_OUTPUT_PRIVATE_FROM_THIS (Gop);\r
+\r
+ Status = gBS->CloseProtocol (\r
+ Controller,\r
+ &gEfiPciIoProtocolGuid,\r
+ This->DriverBindingHandle,\r
+ Private->GraphicsOutputHandle\r
+ );\r
+ ASSERT_EFI_ERROR (Status);\r
+ //\r
+ // Remove the GOP protocol interface from the system\r
+ //\r
+ Status = gBS->UninstallMultipleProtocolInterfaces (\r
+ Private->GraphicsOutputHandle,\r
+ &gEfiGraphicsOutputProtocolGuid, &Private->GraphicsOutput,\r
+ &gEfiDevicePathProtocolGuid, Private->DevicePath,\r
+ NULL\r
+ );\r
+ if (!EFI_ERROR (Status)) {\r
+ //\r
+ // Restore original PCI attributes\r
+ //\r
+ Status = Private->PciIo->Attributes (\r
+ Private->PciIo,\r
+ EfiPciIoAttributeOperationSet,\r
+ Private->PciAttributes,\r
+ NULL\r
+ );\r
+ ASSERT_EFI_ERROR (Status);\r
+\r
+ FreePool (Private->DevicePath);\r
+ FreePool (Private->FrameBufferBltLibConfigure);\r
+ mDriverStarted = FALSE;\r
+ } else {\r
+ Status = gBS->OpenProtocol (\r
+ Controller,\r
+ &gEfiPciIoProtocolGuid,\r
+ (VOID **) &Private->PciIo,\r
+ This->DriverBindingHandle,\r
+ Private->GraphicsOutputHandle,\r
+ EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
+ );\r
+ ASSERT_EFI_ERROR (Status);\r
+ }\r
+ return Status;\r
+}\r
+\r
+EFI_DRIVER_BINDING_PROTOCOL mGraphicsOutputDriverBinding = {\r
+ GraphicsOutputDriverBindingSupported,\r
+ GraphicsOutputDriverBindingStart,\r
+ GraphicsOutputDriverBindingStop,\r
+ 0x10,\r
+ NULL,\r
+ NULL\r
+};\r
+\r
+/**\r
+ The Entry Point for GraphicsOutput driver.\r
+\r
+ It installs DriverBinding, ComponentName and ComponentName2 protocol if there is\r
+ GraphicsInfo HOB passed from Graphics PEIM.\r
+\r
+ @param[in] ImageHandle The firmware allocated handle for the EFI image.\r
+ @param[in] SystemTable A pointer to the EFI System Table.\r
+\r
+ @retval EFI_SUCCESS The entry point is executed successfully.\r
+ @retval other Some error occurs when executing this entry point.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeGraphicsOutput (\r
+ IN EFI_HANDLE ImageHandle,\r
+ IN EFI_SYSTEM_TABLE *SystemTable\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ VOID *HobStart;\r
+\r
+ HobStart = GetFirstGuidHob (&gEfiGraphicsInfoHobGuid);\r
+\r
+ if ((HobStart == NULL) || (GET_GUID_HOB_DATA_SIZE (HobStart) < sizeof (EFI_PEI_GRAPHICS_INFO_HOB))) {\r
+ return EFI_NOT_FOUND;\r
+ }\r
+\r
+ Status = EfiLibInstallDriverBindingComponentName2 (\r
+ ImageHandle,\r
+ SystemTable,\r
+ &mGraphicsOutputDriverBinding,\r
+ ImageHandle,\r
+ &mGraphicsOutputComponentName,\r
+ &mGraphicsOutputComponentName2\r
+ );\r
+ ASSERT_EFI_ERROR (Status);\r
+\r
+ return Status;\r
+}\r