ReactOS 0.4.16-dev-2491-g3dc6630
uefihw.c
Go to the documentation of this file.
1/*
2 * PROJECT: FreeLoader UEFI Support
3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4 * PURPOSE: Hardware detection routines
5 * COPYRIGHT: Copyright 2022 Justin Miller <justinmiller100@gmail.com>
6 */
7
8/* INCLUDES ******************************************************************/
9
10#include <uefildr.h>
11#include "../vidfb.h"
12
13#include <debug.h>
15
16/* GLOBALS *******************************************************************/
17
21
22/* From uefivid.c */
24extern ULONG VramSize;
26
29
30/* FUNCTIONS *****************************************************************/
31
32VOID
34{
35 GlobalSystemTable->BootServices->Stall(Microseconds);
36}
37
38VOID
40{
44
45 /* Keep one timer event around and arm it each idle tick */
46 if (IdleTimerEvent == NULL)
47 {
48 Status = BootServices->CreateEvent(EVT_TIMER,
50 NULL,
51 NULL,
53 if (EFI_ERROR(Status))
54 {
55 StallExecutionProcessor(10000); /* 10 ms fallback */
56 return;
57 }
58 }
59
60 /* Set a 10ms (100,000 * 100ns) relative timer */
61 Status = BootServices->SetTimer(IdleTimerEvent, TimerRelative, 100000);
62 if (!EFI_ERROR(Status))
63 Status = BootServices->WaitForEvent(1, &IdleTimerEvent, &Index);
64 if (EFI_ERROR(Status))
65 StallExecutionProcessor(10000); /* 10 ms fallback */
66}
67
69{
70 return AcpiPresent;
71}
72
73static
76{
77 UINTN i;
78 RSDP_DESCRIPTOR* rsdp = NULL;
80
82 {
84 &acpi2_guid, sizeof(acpi2_guid)))
85 {
87 break;
88 }
89 }
90
91 return rsdp;
92}
93
94VOID
96{
98 PCM_PARTIAL_RESOURCE_LIST PartialResourceList;
99 PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
100 PRSDP_DESCRIPTOR Rsdp;
101 PACPI_BIOS_DATA AcpiBiosData;
103
104 Rsdp = FindAcpiBios();
105
106 if (Rsdp)
107 {
108 /* Set up the flag in the loader block */
110
111 /* Calculate the table size */
112 TableSize = sizeof(ACPI_BIOS_DATA);
113
114 /* Set 'Configuration Data' value */
115 Size = FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, PartialDescriptors[1]) + TableSize;
116 PartialResourceList = FrLdrHeapAlloc(Size, TAG_HW_RESOURCE_LIST);
117 if (PartialResourceList == NULL)
118 {
119 ERR("Failed to allocate resource descriptor\n");
120 return;
121 }
122
123 RtlZeroMemory(PartialResourceList, Size);
124 PartialResourceList->Version = 0;
125 PartialResourceList->Revision = 0;
126 PartialResourceList->Count = 1;
127
128 PartialDescriptor = &PartialResourceList->PartialDescriptors[0];
129 PartialDescriptor->Type = CmResourceTypeDeviceSpecific;
131 PartialDescriptor->u.DeviceSpecificData.DataSize = TableSize;
132
133 /* Fill the table */
134 AcpiBiosData = (PACPI_BIOS_DATA)(PartialDescriptor + 1);
135
136 if (Rsdp->revision > 0)
137 {
138 TRACE("ACPI >1.0, using XSDT address\n");
139 AcpiBiosData->RSDTAddress.QuadPart = Rsdp->xsdt_physical_address;
140 }
141 else
142 {
143 TRACE("ACPI 1.0, using RSDT address\n");
144 AcpiBiosData->RSDTAddress.LowPart = Rsdp->rsdt_physical_address;
145 }
146
147 AcpiBiosData->Count = 0;
148
149 TRACE("RSDT %p, data size %x\n", Rsdp->rsdt_physical_address, TableSize);
150
151 /* Create new bus key */
152 FldrCreateComponentKey(SystemKey,
155 0x0,
156 0x0,
157 0xFFFFFFFF,
158 "ACPI BIOS",
159 PartialResourceList,
160 Size,
161 &BiosKey);
162
163 /* Increment bus number */
164 (*BusNumber)++;
165 }
166}
167
168static VOID
171{
172 PCONFIGURATION_COMPONENT_DATA ControllerKey;
173 PCM_PARTIAL_RESOURCE_LIST PartialResourceList;
174 PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
175 PCM_FRAMEBUF_DEVICE_DATA FramebufData;
176 ULONG Size;
177
178 if (!VramAddress || (VramSize == 0) || !FrameBufferData)
179 return;
180
181 Size = FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, PartialDescriptors[2]) + sizeof(*FramebufData);
182 PartialResourceList = FrLdrHeapAlloc(Size, TAG_HW_RESOURCE_LIST);
183 if (PartialResourceList == NULL)
184 {
185 ERR("Failed to allocate resource descriptor\n");
186 return;
187 }
188
189 /* Initialize resource descriptor */
190 RtlZeroMemory(PartialResourceList, Size);
191 PartialResourceList->Version = 1;
192 PartialResourceList->Revision = 2;
193 PartialResourceList->Count = 2;
194
195 /* Set Memory */
196 PartialDescriptor = &PartialResourceList->PartialDescriptors[0];
197 PartialDescriptor->Type = CmResourceTypeMemory;
199 PartialDescriptor->Flags = CM_RESOURCE_MEMORY_READ_WRITE;
200 PartialDescriptor->u.Memory.Start.QuadPart = VramAddress;
201 PartialDescriptor->u.Memory.Length = VramSize;
202
203 /* Set framebuffer-specific data */
204 PartialDescriptor = &PartialResourceList->PartialDescriptors[1];
205 PartialDescriptor->Type = CmResourceTypeDeviceSpecific;
207 PartialDescriptor->Flags = 0;
208 PartialDescriptor->u.DeviceSpecificData.DataSize = sizeof(*FramebufData);
209
210 /* Get pointer to framebuffer-specific data */
211 FramebufData = (PCM_FRAMEBUF_DEVICE_DATA)(PartialDescriptor + 1);
212 RtlCopyMemory(FramebufData, FrameBufferData, sizeof(*FrameBufferData));
213 FramebufData->Version = 1;
214 FramebufData->Revision = 3;
215 FramebufData->VideoClock = 0; // FIXME: Use EDID
216
221 0,
222 0xFFFFFFFF,
223 "UEFI GOP Framebuffer",
224 PartialResourceList,
225 Size,
226 &ControllerKey);
227
228 // NOTE: Don't add a MonitorPeripheral for now.
229 // We should use EDID data for it.
230}
231
232static
233VOID
235{
236 PCM_PARTIAL_RESOURCE_LIST PartialResourceList;
238 ULONG Size;
239
240 /* Set 'Configuration Data' value */
241 Size = FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, PartialDescriptors);
242 PartialResourceList = FrLdrHeapAlloc(Size, TAG_HW_RESOURCE_LIST);
243 if (PartialResourceList == NULL)
244 {
245 ERR("Failed to allocate resource descriptor\n");
246 return;
247 }
248
249 /* Initialize resource descriptor */
250 RtlZeroMemory(PartialResourceList, Size);
251 PartialResourceList->Version = 1;
252 PartialResourceList->Revision = 1;
253 PartialResourceList->Count = 0;
254
255 /* Create new bus key */
256 FldrCreateComponentKey(SystemKey,
259 0,
260 0,
261 0xFFFFFFFF,
262 "UEFI Internal",
263 PartialResourceList,
264 Size,
265 &BusKey);
266
267 /* Increment bus number */
268 (*BusNumber)++;
269
270 /* Detect devices that do not belong to "standard" buses */
272
273 /* FIXME: Detect more devices */
274}
275
279{
281 ULONG BusNumber = 0;
282
283 TRACE("DetectHardware()\n");
284
285 /* Create the 'System' key */
286#if defined(_M_IX86) || defined(_M_AMD64)
287 FldrCreateSystemKey(&SystemKey, "AT/AT COMPATIBLE");
288#elif defined(_M_IA64)
289 FldrCreateSystemKey(&SystemKey, "Intel Itanium processor family");
290#elif defined(_M_ARM) || defined(_M_ARM64)
291 FldrCreateSystemKey(&SystemKey, "ARM processor family");
292#else
293 #error Please define a system key for your architecture
294#endif
295
296 /* Detect buses */
297 DetectInternal(SystemKey, &BusNumber);
298 // TODO: DetectPciBios
299 DetectAcpiBios(SystemKey, &BusNumber);
300
301 TRACE("DetectHardware() Done\n");
302 return SystemKey;
303}
#define EFI_ACPI_20_TABLE_GUID
Definition: Acpi.h:40
#define WARNING
Definition: BusLogic958.h:56
UINT32 UINTN
#define EFI_ERROR(A)
Definition: UefiBaseType.h:165
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:31
#define TPL_APPLICATION
Definition: UefiSpec.h:561
@ TimerRelative
Definition: UefiSpec.h:464
#define EVT_TIMER
Definition: UefiSpec.h:362
unsigned char BOOLEAN
Definition: actypes.h:127
VOID FldrCreateSystemKey(_Out_ PCONFIGURATION_COMPONENT_DATA *SystemNode, _In_ PCSTR IdentifierString)
Definition: archwsup.c:135
VOID FldrCreateComponentKey(_In_ PCONFIGURATION_COMPONENT_DATA SystemNode, _In_ CONFIGURATION_CLASS Class, _In_ CONFIGURATION_TYPE Type, _In_ IDENTIFIER_FLAG Flags, _In_ ULONG Key, _In_ ULONG Affinity, _In_ PCSTR IdentifierString, _In_ PCM_PARTIAL_RESOURCE_LIST ResourceList, _In_ ULONG Size, _Out_ PCONFIGURATION_COMPONENT_DATA *ComponentKey)
Definition: archwsup.c:198
#define ERR(fmt,...)
Definition: precomp.h:57
#define DBG_DEFAULT_CHANNEL(ch)
Definition: debug.h:106
PVOID FrLdrHeapAlloc(SIZE_T MemorySize, ULONG Tag)
Definition: heap.c:533
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
_ACRTIMP int __cdecl memcmp(const void *, const void *, size_t)
Definition: string.c:2802
Status
Definition: gdiplustypes.h:25
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define CM_RESOURCE_MEMORY_READ_WRITE
Definition: cmtypes.h:121
#define _In_
Definition: no_sal2.h:158
#define _In_opt_
Definition: no_sal2.h:212
struct _ACPI_BIOS_DATA ACPI_BIOS_DATA
struct _ACPI_BIOS_DATA * PACPI_BIOS_DATA
#define CmResourceTypeMemory
Definition: restypes.h:106
#define CmResourceTypeDeviceSpecific
Definition: restypes.h:108
@ ControllerClass
Definition: arc.h:103
@ AdapterClass
Definition: arc.h:102
@ MultiFunctionAdapter
Definition: arc.h:125
@ DisplayController
Definition: arc.h:132
@ ConsoleOut
Definition: arc.h:92
@ Output
Definition: arc.h:94
struct _CM_FRAMEBUF_DEVICE_DATA * PCM_FRAMEBUF_DEVICE_DATA
#define TRACE(s)
Definition: solgame.cpp:4
EFI_SET_TIMER SetTimer
Definition: UefiSpec.h:1820
EFI_CREATE_EVENT CreateEvent
Definition: UefiSpec.h:1819
EFI_WAIT_FOR_EVENT WaitForEvent
Definition: UefiSpec.h:1821
EFI_STALL Stall
Definition: UefiSpec.h:1852
EFI_BOOT_SERVICES * BootServices
Definition: UefiSpec.h:1959
EFI_CONFIGURATION_TABLE * ConfigurationTable
Definition: UefiSpec.h:1968
UINTN NumberOfTableEntries
Definition: UefiSpec.h:1963
ULONG rsdt_physical_address
Definition: winldr.h:26
UCHAR revision
Definition: winldr.h:25
ULONGLONG xsdt_physical_address
Definition: winldr.h:28
PHYSICAL_ADDRESS RSDTAddress
Definition: pcbios.h:77
ULONGLONG Count
Definition: pcbios.h:78
ReactOS Framebuffer-specific video device configuration data.
Definition: framebuf.h:35
union _CM_PARTIAL_RESOURCE_DESCRIPTOR::@384 u
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@384::@393 DeviceSpecificData
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@384::@389 Memory
CM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptors[1]
Definition: restypes.h:100
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
const char * PCSTR
Definition: typedefs.h:52
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint32_t ULONG
Definition: typedefs.h:59
#define TAG_HW_RESOURCE_LIST
Definition: uefidisk.c:15
VOID DetectAcpiBios(PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber)
Definition: uefihw.c:95
static VOID DetectDisplayController(_In_ PCONFIGURATION_COMPONENT_DATA BusKey)
Definition: uefihw.c:169
static VOID DetectInternal(PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber)
Definition: uefihw.c:234
ULONG_PTR VramAddress
Definition: uefivid.c:21
VOID UefiHwIdle(VOID)
Definition: uefihw.c:39
BOOLEAN IsAcpiPresent(VOID)
Definition: uefihw.c:68
BOOLEAN AcpiPresent
Definition: uefihw.c:27
PCONFIGURATION_COMPONENT_DATA UefiHwDetect(_In_opt_ PCSTR Options)
Definition: uefihw.c:277
EFI_SYSTEM_TABLE * GlobalSystemTable
Definition: uefildr.c:16
VOID StallExecutionProcessor(ULONG Microseconds)
Definition: uefihw.c:33
PCM_FRAMEBUF_DEVICE_DATA FrameBufferData
Definition: xboxvideo.c:31
static PRSDP_DESCRIPTOR FindAcpiBios(VOID)
Definition: uefihw.c:75
ULONG VramSize
Definition: uefivid.c:22
static EFI_EVENT IdleTimerEvent
Definition: uefihw.c:28
EFI_HANDLE GlobalImageHandle
Definition: uefildr.c:15
UCHAR PcBiosDiskCount
Definition: hwdisk.c:47
LONGLONG QuadPart
Definition: typedefs.h:114
ULONG LowPart
Definition: typedefs.h:106
_In_ WDFCOLLECTION _In_ ULONG Index
_In_ PWDFDEVICE_INIT _In_ PWDF_REMOVE_LOCK_OPTIONS Options
Definition: wdfdevice.h:3540
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4539
@ CmResourceShareDeviceExclusive
Definition: cmtypes.h:241
@ CmResourceShareUndetermined
Definition: cmtypes.h:240
_In_opt_ PUNICODE_STRING _In_ PDRIVER_OBJECT _In_ PDEVICE_OBJECT _In_ INTERFACE_TYPE _In_ ULONG BusNumber
Definition: halfuncs.h:160
_Must_inspect_result_ typedef _Out_ PULONG TableSize
Definition: iotypes.h:4330
unsigned char UCHAR
Definition: xmlstorage.h:181