+/**\r
+ Initialize all the text modes which the graphics console supports.\r
+\r
+ It returns information for available text modes that the graphics can support.\r
+\r
+ @param[in] HorizontalResolution The size of video screen in pixels in the X dimension.\r
+ @param[in] VerticalResolution The size of video screen in pixels in the Y dimension.\r
+ @param[in] GopModeNumber The graphics mode number which graphics console is based on.\r
+ @param[out] TextModeCount The total number of text modes that graphics console supports.\r
+ @param[out] TextModeData The buffer to the text modes column and row information.\r
+ Caller is responsible to free it when it's non-NULL.\r
+\r
+ @retval EFI_SUCCESS The supporting mode information is returned.\r
+ @retval EFI_INVALID_PARAMETER The parameters are invalid.\r
+\r
+**/\r
+EFI_STATUS\r
+InitializeGraphicsConsoleTextMode (\r
+ IN UINT32 HorizontalResolution,\r
+ IN UINT32 VerticalResolution,\r
+ IN UINT32 GopModeNumber,\r
+ OUT UINTN *TextModeCount,\r
+ OUT GRAPHICS_CONSOLE_MODE_DATA **TextModeData\r
+ )\r
+{\r
+ UINTN Index;\r
+ UINTN Count;\r
+ GRAPHICS_CONSOLE_MODE_DATA *ModeBuffer;\r
+ GRAPHICS_CONSOLE_MODE_DATA *NewModeBuffer;\r
+ UINTN ValidCount;\r
+ UINTN ValidIndex;\r
+ UINTN MaxColumns;\r
+ UINTN MaxRows;\r
+\r
+ if ((TextModeCount == NULL) || (TextModeData == NULL)) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ Count = sizeof (mGraphicsConsoleModeData) / sizeof (GRAPHICS_CONSOLE_MODE_DATA);\r
+\r
+ //\r
+ // Compute the maximum number of text Rows and Columns that this current graphics mode can support.\r
+ // To make graphics console work well, MaxColumns and MaxRows should not be zero.\r
+ //\r
+ MaxColumns = HorizontalResolution / EFI_GLYPH_WIDTH;\r
+ MaxRows = VerticalResolution / EFI_GLYPH_HEIGHT;\r
+\r
+ //\r
+ // According to UEFI spec, all output devices support at least 80x25 text mode.\r
+ //\r
+ ASSERT ((MaxColumns >= 80) && (MaxRows >= 25));\r
+\r
+ //\r
+ // Add full screen mode to the last entry.\r
+ //\r
+ mGraphicsConsoleModeData[Count - 1].Columns = MaxColumns;\r
+ mGraphicsConsoleModeData[Count - 1].Rows = MaxRows;\r
+\r
+ //\r
+ // Get defined mode buffer pointer.\r
+ //\r
+ ModeBuffer = mGraphicsConsoleModeData;\r
+\r
+ //\r
+ // Here we make sure that the final mode exposed does not include the duplicated modes,\r
+ // and does not include the invalid modes which exceed the max column and row.\r
+ // Reserve 2 modes for 80x25, 80x50 of graphics console.\r
+ //\r
+ NewModeBuffer = AllocateZeroPool (sizeof (GRAPHICS_CONSOLE_MODE_DATA) * (Count + 2));\r
+ ASSERT (NewModeBuffer != NULL);\r
+\r
+ //\r
+ // Mode 0 and mode 1 is for 80x25, 80x50 according to UEFI spec.\r
+ //\r
+ ValidCount = 0;\r
+\r
+ NewModeBuffer[ValidCount].Columns = 80;\r
+ NewModeBuffer[ValidCount].Rows = 25;\r
+ NewModeBuffer[ValidCount].GopWidth = HorizontalResolution;\r
+ NewModeBuffer[ValidCount].GopHeight = VerticalResolution;\r
+ NewModeBuffer[ValidCount].GopModeNumber = GopModeNumber;\r
+ NewModeBuffer[ValidCount].DeltaX = (HorizontalResolution - (NewModeBuffer[ValidCount].Columns * EFI_GLYPH_WIDTH)) >> 1;\r
+ NewModeBuffer[ValidCount].DeltaY = (VerticalResolution - (NewModeBuffer[ValidCount].Rows * EFI_GLYPH_HEIGHT)) >> 1;\r
+ ValidCount++;\r
+\r
+ if ((MaxColumns >= 80) && (MaxRows >= 50)) {\r
+ NewModeBuffer[ValidCount].Columns = 80;\r
+ NewModeBuffer[ValidCount].Rows = 50;\r
+ NewModeBuffer[ValidCount].DeltaX = (HorizontalResolution - (80 * EFI_GLYPH_WIDTH)) >> 1;\r
+ NewModeBuffer[ValidCount].DeltaY = (VerticalResolution - (50 * EFI_GLYPH_HEIGHT)) >> 1;\r
+ }\r
+\r
+ NewModeBuffer[ValidCount].GopWidth = HorizontalResolution;\r
+ NewModeBuffer[ValidCount].GopHeight = VerticalResolution;\r
+ NewModeBuffer[ValidCount].GopModeNumber = GopModeNumber;\r
+ ValidCount++;\r
+\r
+ //\r
+ // Start from mode 2 to put the valid mode other than 80x25 and 80x50 in the output mode buffer.\r
+ //\r
+ for (Index = 0; Index < Count; Index++) {\r
+ if ((ModeBuffer[Index].Columns == 0) || (ModeBuffer[Index].Rows == 0) ||\r
+ (ModeBuffer[Index].Columns > MaxColumns) || (ModeBuffer[Index].Rows > MaxRows))\r
+ {\r
+ //\r
+ // Skip the pre-defined mode which is invalid or exceeds the max column and row.\r
+ //\r
+ continue;\r
+ }\r
+\r
+ for (ValidIndex = 0; ValidIndex < ValidCount; ValidIndex++) {\r
+ if ((ModeBuffer[Index].Columns == NewModeBuffer[ValidIndex].Columns) &&\r
+ (ModeBuffer[Index].Rows == NewModeBuffer[ValidIndex].Rows))\r
+ {\r
+ //\r
+ // Skip the duplicated mode.\r
+ //\r
+ break;\r
+ }\r
+ }\r
+\r
+ if (ValidIndex == ValidCount) {\r
+ NewModeBuffer[ValidCount].Columns = ModeBuffer[Index].Columns;\r
+ NewModeBuffer[ValidCount].Rows = ModeBuffer[Index].Rows;\r
+ NewModeBuffer[ValidCount].GopWidth = HorizontalResolution;\r
+ NewModeBuffer[ValidCount].GopHeight = VerticalResolution;\r
+ NewModeBuffer[ValidCount].GopModeNumber = GopModeNumber;\r
+ NewModeBuffer[ValidCount].DeltaX = (HorizontalResolution - (NewModeBuffer[ValidCount].Columns * EFI_GLYPH_WIDTH)) >> 1;\r
+ NewModeBuffer[ValidCount].DeltaY = (VerticalResolution - (NewModeBuffer[ValidCount].Rows * EFI_GLYPH_HEIGHT)) >> 1;\r
+ ValidCount++;\r
+ }\r
+ }\r
+\r
+ DEBUG_CODE_BEGIN ();\r
+ for (Index = 0; Index < ValidCount; Index++) {\r
+ DEBUG ((\r
+ DEBUG_INFO,\r
+ "Graphics - Mode %d, Column = %d, Row = %d\n",\r
+ Index,\r
+ NewModeBuffer[Index].Columns,\r
+ NewModeBuffer[Index].Rows\r
+ ));\r
+ }\r
+\r
+ DEBUG_CODE_END ();\r
+\r
+ //\r
+ // Return valid mode count and mode information buffer.\r
+ //\r
+ *TextModeCount = ValidCount;\r
+ *TextModeData = NewModeBuffer;\r
+ return EFI_SUCCESS;\r
+}\r