@@ -16,6 +16,7 @@ DBG_DEFAULT_CHANNEL(UI);
1616extern EFI_SYSTEM_TABLE * GlobalSystemTable ;
1717extern EFI_HANDLE GlobalImageHandle ;
1818EFI_GUID EfiGraphicsOutputProtocol = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID ;
19+ EFI_GUID AppleScreenInfoProtocol = APPLE_SCREEN_INFO_PROTOCOL_GUID ;
1920
2021ULONG_PTR VramAddress ;
2122ULONG VramSize ;
@@ -52,8 +53,9 @@ static EFI_PIXEL_BITMASK EfiPixelMasks[] =
5253
5354#endif /* UEFI */
5455
56+ static
5557EFI_STATUS
56- UefiInitializeVideo (VOID )
58+ UefiInitializeGop (VOID )
5759{
5860 EFI_STATUS Status ;
5961 EFI_GRAPHICS_OUTPUT_PROTOCOL * gop = NULL ;
@@ -128,6 +130,84 @@ UefiInitializeVideo(VOID)
128130 return Status ;
129131}
130132
133+ static
134+ EFI_STATUS
135+ UefiInitializeAppleScreen (VOID )
136+ {
137+ EFI_STATUS Status ;
138+ APPLE_SCREEN_INFO_PROTOCOL * AppleScreen = NULL ;
139+ EFI_PIXEL_BITMASK * pPixelBitmask ;
140+
141+ UINT64 BaseAddress , FrameBufferSize ;
142+ UINT32 BytesPerRow , Width , Height , Depth ;
143+
144+ Status = GlobalSystemTable -> BootServices -> LocateProtocol (& AppleScreenInfoProtocol , 0 , (VOID * * )& AppleScreen );
145+ if (Status != EFI_SUCCESS )
146+ {
147+ ERR ("Failed to find Apple Screen Info with status %d\n" , Status );
148+ return Status ;
149+ }
150+
151+ Status = AppleScreen -> GetInfo (AppleScreen ,
152+ & BaseAddress ,
153+ & FrameBufferSize ,
154+ & BytesPerRow ,
155+ & Width ,
156+ & Height ,
157+ & Depth );
158+
159+ if (Status != EFI_SUCCESS )
160+ {
161+ ERR ("Failed to get screen info from Apple Scren Info: %d\n" , Status );
162+ return Status ;
163+ }
164+
165+ VramAddress = (ULONG_PTR ) BaseAddress ;
166+ VramSize = (ULONG ) FrameBufferSize ;
167+
168+ // All devices requiring Apple Screen Info use PixelBlueGreenRedReserved8BitPerColor.
169+ pPixelBitmask = & EfiPixelMasks [PixelBlueGreenRedReserved8BitPerColor ];
170+
171+ if (!VidFbInitializeVideo (& FrameBufferData ,
172+ VramAddress ,
173+ VramSize ,
174+ Width ,
175+ Height ,
176+ (BytesPerRow / 4 ),
177+ Depth ,
178+ (PPIXEL_BITMASK )pPixelBitmask ))
179+ {
180+ ERR ("Couldn't initialize video framebuffer\n" );
181+ Status = EFI_UNSUPPORTED ;
182+ }
183+
184+ return Status ;
185+ }
186+
187+ EFI_STATUS
188+ UefiInitializeVideo (VOID )
189+ {
190+ EFI_STATUS Status ;
191+
192+ // First, try GOP
193+ Status = UefiInitializeGop ();
194+ if (Status != EFI_SUCCESS )
195+ {
196+ // Try Apple Screen if that fails
197+ TRACE ("Cannot find video via GOP, falling back to Apple Screen Info\n" );
198+ Status = UefiInitializeAppleScreen ();
199+ if (Status != EFI_SUCCESS )
200+ {
201+ // Bail out, there's no graphics
202+ ERR ("Cannot find framebuffer!\n" );
203+ return Status ;
204+ }
205+ }
206+
207+ return EFI_SUCCESS ;
208+ }
209+
210+
131211VOID
132212UefiVideoClearScreen (UCHAR Attr )
133213{
0 commit comments