OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
GopInfoDump.c
Go to the documentation of this file.
1
9
10#include <Base.h>
11#include <Uefi/UefiBaseType.h>
12
15
16#include <Library/BaseLib.h>
17#include <Library/DebugLib.h>
18#include <Library/MemoryAllocationLib.h>
19#include <Library/MtrrLib.h>
20#include <Library/OcMemoryLib.h>
21#include <Library/OcStringLib.h>
22#include <Library/PrintLib.h>
23#include <Library/UefiBootServicesTableLib.h>
24
25EFI_STATUS
27 IN EFI_FILE_PROTOCOL *Root
28 )
29{
30 EFI_STATUS Status;
31 EFI_GRAPHICS_OUTPUT_PROTOCOL *Gop;
32 MTRR_MEMORY_CACHE_TYPE MtrrCacheType;
34 EFI_VIRTUAL_ADDRESS VirtualAddress;
35 EFI_PHYSICAL_ADDRESS PhysicalAddress;
36 EFI_PHYSICAL_ADDRESS EndAddress;
37 UINTN FrameBufferSize;
38 UINTN BytesPerPixel;
39 UINT64 Bits;
40 UINT8 Level;
41 BOOLEAN HasMtrr;
42 BOOLEAN HasPat;
43 UINT64 PatMsr;
44 PAT_INDEX PatIndex;
45 BOOLEAN HasDefaultPat;
46
47 CHAR8 *FileBuffer;
48 UINTN FileBufferSize;
49 CHAR16 TmpFileName[32];
50
51 ASSERT (Root != NULL);
52
53 Status = gBS->HandleProtocol (
54 gST->ConsoleOutHandle,
56 (VOID **)&Gop
57 );
58
59 if (EFI_ERROR (Status)) {
60 DEBUG ((DEBUG_INFO, "OCC: No console GOP found for dumping - %r\n", Status));
61 return Status;
62 }
63
64 FileBufferSize = SIZE_1KB;
65 FileBuffer = AllocateZeroPool (FileBufferSize);
66 if (FileBuffer == NULL) {
67 return EFI_OUT_OF_RESOURCES;
68 }
69
70 Status = EFI_SUCCESS;
71
72 if ((Gop->Mode == NULL) || (Gop->Mode->Info == NULL)) {
74 &FileBuffer,
75 &FileBufferSize,
76 "INVALID GOP %p %p!\n",
77 Gop->Mode,
78 (Gop->Mode != NULL) ? Gop->Mode->Info : NULL
79 );
80 Status = EFI_UNSUPPORTED;
81 }
82
83 if (!EFI_ERROR (Status)) {
85 &FileBuffer,
86 &FileBufferSize,
87 "GOP INFO %u(%u)x%u fmt %u\n",
88 Gop->Mode->Info->HorizontalResolution,
89 Gop->Mode->Info->PixelsPerScanLine,
90 Gop->Mode->Info->VerticalResolution,
91 Gop->Mode->Info->PixelFormat
92 );
93
94 if (Gop->Mode->Info->PixelFormat == PixelBitMask) {
96 &FileBuffer,
97 &FileBufferSize,
98 "GOP pix mask 0x%X:0x%X:0x%X:0x%X\n",
99 Gop->Mode->Info->PixelInformation.RedMask,
100 Gop->Mode->Info->PixelInformation.GreenMask,
101 Gop->Mode->Info->PixelInformation.BlueMask,
102 Gop->Mode->Info->PixelInformation.ReservedMask
103 );
104 }
105
107 &FileBuffer,
108 &FileBufferSize,
109 "GOP FB 0x%LX[0x%X]\n",
110 Gop->Mode->FrameBufferBase,
111 Gop->Mode->FrameBufferSize
112 );
113
114 Status = OcGopModeBytesPerPixel (Gop->Mode, &BytesPerPixel);
116 &FileBuffer,
117 &FileBufferSize,
118 "GOP BPP %u - %r\n",
119 BytesPerPixel,
120 Status
121 );
122
123 if (!EFI_ERROR (Status)) {
124 Status = OcGopModeSafeFrameBufferSize (Gop->Mode, &FrameBufferSize);
126 &FileBuffer,
127 &FileBufferSize,
128 "GOP FBS 0x%X%a - %r\n",
129 FrameBufferSize,
130 (Gop->Mode->FrameBufferSize != FrameBufferSize) ? " (FBS mismatch! Using this.)" : "",
131 Status
132 );
133 }
134 }
135
136 if (!EFI_ERROR (Status)) {
137 HasMtrr = IsMtrrSupported ();
138 HasPat = OcIsPatSupported ();
139
141 &FileBuffer,
142 &FileBufferSize,
143 "MTRR %asupported PAT %asupported\n",
144 HasMtrr ? "" : "not ",
145 HasPat ? "" : "not "
146 );
147
148 if (HasMtrr) {
149 if (HasPat) {
150 PatMsr = AsmReadMsr64 (MSR_IA32_CR_PAT);
151 HasDefaultPat = (PatMsr == PAT_DEFAULTS);
152
154 &FileBuffer,
155 &FileBufferSize,
156 "PAT 0x%016LX (%a)\n",
157 PatMsr,
158 HasDefaultPat ? "default" : "not default!"
159 );
160 }
161
162 PageTable = OcGetCurrentPageTable (NULL);
163
164 VirtualAddress = Gop->Mode->FrameBufferBase;
165 EndAddress = VirtualAddress + FrameBufferSize;
166
167 Status = EFI_SUCCESS;
168
169 do {
170 MtrrCacheType = MtrrGetMemoryAttribute (VirtualAddress);
171
172 if (HasPat) {
174 PageTable,
175 VirtualAddress,
176 &PhysicalAddress,
177 &Level,
178 &Bits,
179 &PatIndex,
180 FALSE
181 );
182
183 if (EFI_ERROR (Status)) {
184 break;
185 }
186
188 &FileBuffer,
189 &FileBufferSize,
190 "0x%LX~0x%LX MTRR %u=%a PTE%u bits 0x%016LX PAT@%u->%u=%a\n",
191 VirtualAddress,
192 PhysicalAddress,
193 MtrrCacheType,
194 OcGetMtrrTypeString (MtrrCacheType),
195 Level,
196 Bits,
197 PatIndex.Index,
198 GET_PAT_N (PatMsr, PatIndex.Index),
199 OcGetPatTypeString (GET_PAT_N (PatMsr, PatIndex.Index))
200 );
201
202 if (VirtualAddress != PhysicalAddress) {
203 Status = EFI_UNSUPPORTED;
204 break;
205 }
206 } else {
207 Level = 2;
208
210 &FileBuffer,
211 &FileBufferSize,
212 "0x%LX MTRR %u=%a\n",
213 VirtualAddress,
214 MtrrCacheType,
215 OcGetMtrrTypeString (MtrrCacheType)
216 );
217 }
218
219 switch (Level) {
220 case 1:
221 VirtualAddress += SIZE_1GB;
222 break;
223
224 case 2:
225 VirtualAddress += SIZE_2MB;
226 break;
227
228 case 4:
229 VirtualAddress += SIZE_4KB;
230 break;
231
232 default:
233 Status = EFI_UNSUPPORTED;
234 break;
235 }
236 } while (!EFI_ERROR (Status) && VirtualAddress < EndAddress);
237 }
238
239 if (EFI_ERROR (Status)) {
241 &FileBuffer,
242 &FileBufferSize,
243 "Failure reading page table! - %r\n",
244 Status
245 );
246 }
247 }
248
249 //
250 // Save dumped GOP info to file.
251 //
252 if (FileBuffer != NULL) {
253 UnicodeSPrint (TmpFileName, sizeof (TmpFileName), L"GOPInfo.txt");
254 Status = OcSetFileData (Root, TmpFileName, FileBuffer, (UINT32)AsciiStrLen (FileBuffer));
255 DEBUG ((DEBUG_INFO, "OCC: Dumped GOP cache info - %r\n", Status));
256
257 FreePool (FileBuffer);
258 }
259
260 return EFI_SUCCESS;
261}
UINT32 EndAddress
Definition AppleSmBios.h:46
EFI_STATUS OcGopInfoDump(IN EFI_FILE_PROTOCOL *Root)
Definition GopInfoDump.c:26
EFI_SYSTEM_TABLE * gST
EFI_BOOT_SERVICES * gBS
EFI_STATUS OcGopModeBytesPerPixel(IN EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE *Mode, OUT UINTN *BytesPerPixel)
Definition GopUtils.c:29
EFI_STATUS OcGopModeSafeFrameBufferSize(IN EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE *Mode, OUT UINTN *FrameBufferSize)
Definition GopUtils.c:85
EFI_STATUS OcSetFileData(IN EFI_FILE_PROTOCOL *WritableFs OPTIONAL, IN CONST CHAR16 *FileName, IN CONST VOID *Buffer, IN UINT32 Size)
PAGE_MAP_AND_DIRECTORY_POINTER * OcGetCurrentPageTable(OUT UINTN *Flags OPTIONAL)
BOOLEAN OcIsPatSupported(VOID)
CHAR8 * OcGetPatTypeString(UINT8 PatType)
EFI_STATUS OcGetSetPageTableInfoForAddress(IN PAGE_MAP_AND_DIRECTORY_POINTER *PageTable OPTIONAL, IN EFI_VIRTUAL_ADDRESS VirtualAddr, OUT EFI_PHYSICAL_ADDRESS *PhysicalAddr OPTIONAL, OUT UINT8 *Level OPTIONAL, OUT UINT64 *Bits OPTIONAL, IN OUT PAT_INDEX *PatIndex OPTIONAL, IN BOOLEAN SetPat)
CHAR8 * OcGetMtrrTypeString(UINT8 MtrrType)
VOID EFIAPI OcAsciiPrintBuffer(IN OUT CHAR8 **AsciiBuffer, IN OUT UINTN *AsciiBufferSize, IN CONST CHAR8 *FormatString,...)
Definition OcAsciiLib.c:510
#define GET_PAT_N(PatMsr, PatIndex)
#define MSR_IA32_CR_PAT
#define PAT_DEFAULTS
EFI_GUID gEfiGraphicsOutputProtocolGuid
UINT64 EFIAPI AsmReadMsr64(IN UINT32 Index)
Definition UserMisc.c:223
#define ASSERT(x)
Definition coder.h:55