88/* INCLUDES ******************************************************************/
99
1010#include <uefildr.h>
11+ #include <drivers/bootvid/framebuf.h>
1112
1213#include <debug.h>
1314DBG_DEFAULT_CHANNEL (WARNING );
@@ -68,8 +69,7 @@ DetectAcpiBios(PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber)
6869 AcpiPresent = TRUE;
6970
7071 /* Calculate the table size */
71- TableSize = FreeldrDescCount * sizeof (BIOS_MEMORY_MAP ) +
72- sizeof (ACPI_BIOS_DATA ) - sizeof (BIOS_MEMORY_MAP );
72+ TableSize = sizeof (ACPI_BIOS_DATA );
7373
7474 /* Set 'Configuration Data' value */
7575 PartialResourceList = FrLdrHeapAlloc (sizeof (CM_PARTIAL_RESOURCE_LIST ) +
@@ -104,9 +104,7 @@ DetectAcpiBios(PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber)
104104 AcpiBiosData -> RSDTAddress .LowPart = Rsdp -> rsdt_physical_address ;
105105 }
106106
107- AcpiBiosData -> Count = FreeldrDescCount ;
108- memcpy (AcpiBiosData -> MemoryMap , EfiMemoryMap ,
109- FreeldrDescCount * sizeof (BIOS_MEMORY_MAP ));
107+ AcpiBiosData -> Count = 0 ;
110108
111109 TRACE ("RSDT %p, data size %x\n" , Rsdp -> rsdt_physical_address , TableSize );
112110
@@ -127,6 +125,196 @@ DetectAcpiBios(PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber)
127125 }
128126}
129127
128+ extern REACTOS_INTERNAL_BGCONTEXT framebufferData ;
129+ /****/ extern EFI_PIXEL_BITMASK UefiGopPixelBitmask ;/****/
130+
131+ static VOID
132+ DetectDisplayController (PCONFIGURATION_COMPONENT_DATA BusKey )
133+ {
134+ PCONFIGURATION_COMPONENT_DATA ControllerKey ;
135+ PCM_PARTIAL_RESOURCE_LIST PartialResourceList ;
136+ PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor ;
137+ PCM_FRAMEBUF_DEVICE_DATA FramebufferData ;
138+ ULONG Size ;
139+
140+ if (framebufferData .BufferSize == 0 )
141+ return ;
142+
143+ ERR ("\nStructure sizes:\n"
144+ " sizeof(CM_PARTIAL_RESOURCE_LIST) = %lu\n"
145+ " sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) = %lu\n"
146+ " sizeof(CM_FRAMEBUF_DEVICE_DATA) = %lu\n\n" ,
147+ sizeof (CM_PARTIAL_RESOURCE_LIST ),
148+ sizeof (CM_PARTIAL_RESOURCE_DESCRIPTOR ),
149+ sizeof (CM_FRAMEBUF_DEVICE_DATA ));
150+
151+ Size = sizeof (CM_PARTIAL_RESOURCE_LIST ) +
152+ sizeof (CM_PARTIAL_RESOURCE_DESCRIPTOR ) +
153+ sizeof (CM_FRAMEBUF_DEVICE_DATA );
154+ PartialResourceList = FrLdrHeapAlloc (Size , TAG_HW_RESOURCE_LIST );
155+ if (PartialResourceList == NULL )
156+ {
157+ ERR ("Failed to allocate resource descriptor\n" );
158+ return ;
159+ }
160+
161+ /* Initialize resource descriptor */
162+ RtlZeroMemory (PartialResourceList , Size );
163+ PartialResourceList -> Version = 1 ;
164+ PartialResourceList -> Revision = 2 ;
165+ PartialResourceList -> Count = 2 ;
166+
167+ /* Set Memory */
168+ PartialDescriptor = & PartialResourceList -> PartialDescriptors [0 ];
169+ PartialDescriptor -> Type = CmResourceTypeMemory ;
170+ PartialDescriptor -> ShareDisposition = CmResourceShareDeviceExclusive ;
171+ PartialDescriptor -> Flags = CM_RESOURCE_MEMORY_READ_WRITE ;
172+ PartialDescriptor -> u .Memory .Start .QuadPart = framebufferData .BaseAddress ;
173+ PartialDescriptor -> u .Memory .Length = framebufferData .BufferSize ;
174+
175+ /* Set framebuffer-specific data */
176+ PartialDescriptor = & PartialResourceList -> PartialDescriptors [1 ];
177+ PartialDescriptor -> Type = CmResourceTypeDeviceSpecific ;
178+ PartialDescriptor -> ShareDisposition = CmResourceShareUndetermined ;
179+ PartialDescriptor -> Flags = 0 ;
180+ PartialDescriptor -> u .DeviceSpecificData .DataSize =
181+ sizeof (CM_FRAMEBUF_DEVICE_DATA );
182+
183+ /* Get pointer to framebuffer-specific data */
184+ FramebufferData = (PVOID )(PartialDescriptor + 1 );
185+ RtlZeroMemory (FramebufferData , sizeof (* FramebufferData ));
186+ FramebufferData -> Version = 2 ;
187+ FramebufferData -> Revision = 0 ;
188+
189+ FramebufferData -> VideoClock = 0 ; // FIXME: Use EDID
190+
191+ /* Horizontal and Vertical resolution in pixels */
192+ FramebufferData -> ScreenWidth = framebufferData .ScreenWidth ;
193+ FramebufferData -> ScreenHeight = framebufferData .ScreenHeight ;
194+
195+ /* Number of pixel elements per video memory line */
196+ FramebufferData -> PixelsPerScanLine = framebufferData .PixelsPerScanLine ;
197+
198+ //
199+ // TODO: Investigate display rotation!
200+ //
201+ // See OpenCorePkg OcConsoleLib/ConsoleGop.c
202+ // if ((mGop.Rotation == 90) || (mGop.Rotation == 270))
203+ if (FramebufferData -> ScreenWidth < FramebufferData -> ScreenHeight )
204+ {
205+ #define SWAP (x , y ) { (x) ^= (y); (y) ^= (x); (x) ^= (y); }
206+ SWAP (FramebufferData -> ScreenWidth , FramebufferData -> ScreenHeight );
207+ FramebufferData -> PixelsPerScanLine = FramebufferData -> ScreenWidth ;
208+ #undef SWAP
209+ }
210+
211+ /* Physical format of the pixel */
212+ // ASSERT(sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL) == 4);
213+ switch (framebufferData .PixelFormat )
214+ {
215+ case PixelRedGreenBlueReserved8BitPerColor :
216+ {
217+ FramebufferData -> BitsPerPixel = (8 * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL ));
218+ * (EFI_PIXEL_BITMASK * )& FramebufferData -> PixelInformation = EfiPixelMasks [framebufferData .PixelFormat ];
219+ break ;
220+ }
221+
222+ case PixelBlueGreenRedReserved8BitPerColor :
223+ {
224+ FramebufferData -> BitsPerPixel = (8 * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL ));
225+ FramebufferData -> PixelInformation .RedMask = 0x00FF0000 ;
226+ FramebufferData -> PixelInformation .GreenMask = 0x0000FF00 ;
227+ FramebufferData -> PixelInformation .BlueMask = 0x000000FF ;
228+ FramebufferData -> PixelInformation .ReservedMask = 0xFF000000 ;
229+ break ;
230+ }
231+
232+ case PixelBitMask :
233+ {
234+ FramebufferData -> BitsPerPixel =
235+ PixelBitmasksToBpp (UefiGopPixelBitmask .RedMask ,
236+ UefiGopPixelBitmask .GreenMask ,
237+ UefiGopPixelBitmask .BlueMask ,
238+ UefiGopPixelBitmask .ReservedMask );
239+ * (EFI_PIXEL_BITMASK * )& FramebufferData -> PixelInformation = UefiGopPixelBitmask ;
240+ //FramebufferData->PixelInformation.RedMask = UefiGopPixelBitmask.RedMask;
241+ //FramebufferData->PixelInformation.GreenMask = UefiGopPixelBitmask.GreenMask;
242+ //FramebufferData->PixelInformation.BlueMask = UefiGopPixelBitmask.BlueMask;
243+ //FramebufferData->PixelInformation.ReservedMask = UefiGopPixelBitmask.ReservedMask;
244+ break ;
245+ }
246+
247+ case PixelBltOnly :
248+ default :
249+ {
250+ ERR ("Unsupported UFEI GOP format %lu\n" , framebufferData .PixelFormat );
251+ FramebufferData -> BitsPerPixel = 0 ;
252+ RtlZeroMemory (& FramebufferData -> PixelInformation ,
253+ sizeof (FramebufferData -> PixelInformation ));
254+ break ;
255+ }
256+ }
257+
258+ FldrCreateComponentKey (BusKey ,
259+ ControllerClass ,
260+ DisplayController ,
261+ Output | ConsoleOut ,
262+ 0 ,
263+ 0xFFFFFFFF ,
264+ "UEFI GOP Framebuffer" ,
265+ PartialResourceList ,
266+ Size ,
267+ & ControllerKey );
268+
269+ // NOTE: Don't add a MonitorPeripheral for now...
270+ // We should use EDID data for it.
271+ }
272+
273+ static
274+ VOID
275+ DetectInternal (PCONFIGURATION_COMPONENT_DATA SystemKey , ULONG * BusNumber )
276+ {
277+ PCM_PARTIAL_RESOURCE_LIST PartialResourceList ;
278+ PCONFIGURATION_COMPONENT_DATA BusKey ;
279+ ULONG Size ;
280+
281+ /* Set 'Configuration Data' value */
282+ Size = sizeof (CM_PARTIAL_RESOURCE_LIST ) -
283+ sizeof (CM_PARTIAL_RESOURCE_DESCRIPTOR );
284+ PartialResourceList = FrLdrHeapAlloc (Size , TAG_HW_RESOURCE_LIST );
285+ if (PartialResourceList == NULL )
286+ {
287+ ERR ("Failed to allocate resource descriptor\n" );
288+ return ;
289+ }
290+
291+ /* Initialize resource descriptor */
292+ RtlZeroMemory (PartialResourceList , Size );
293+ PartialResourceList -> Version = 1 ;
294+ PartialResourceList -> Revision = 2 ;
295+ PartialResourceList -> Count = 0 ;
296+
297+ /* Create new bus key */
298+ FldrCreateComponentKey (SystemKey ,
299+ AdapterClass ,
300+ MultiFunctionAdapter ,
301+ 0 ,
302+ 0 ,
303+ 0xFFFFFFFF ,
304+ "UEFI Internal" ,
305+ PartialResourceList ,
306+ Size ,
307+ & BusKey );
308+
309+ /* Increment bus number */
310+ (* BusNumber )++ ;
311+
312+ /* Detect devices that do not belong to "standard" buses */
313+ DetectDisplayController (BusKey );
314+
315+ /* FIXME: Detect more devices */
316+ }
317+
130318PCONFIGURATION_COMPONENT_DATA
131319UefiHwDetect (
132320 _In_opt_ PCSTR Options )
@@ -138,7 +326,7 @@ UefiHwDetect(
138326
139327 /* Create the 'System' key */
140328#if defined(_M_IX86 ) || defined(_M_AMD64 )
141- FldrCreateSystemKey (& SystemKey , "AT/AT COMPATIBLE " );
329+ FldrCreateSystemKey (& SystemKey , "UEFI-based Device " );
142330#elif defined(_M_IA64 )
143331 FldrCreateSystemKey (& SystemKey , "Intel Itanium processor family" );
144332#elif defined(_M_ARM ) || defined(_M_ARM64 )
@@ -149,6 +337,8 @@ UefiHwDetect(
149337
150338 /* Detect ACPI */
151339 DetectAcpiBios (SystemKey , & BusNumber );
340+ DetectInternal (SystemKey , & BusNumber );
341+
152342
153343 TRACE ("DetectHardware() Done\n" );
154344 return SystemKey ;
0 commit comments