ReactOS 0.4.16-dev-2546-g56481e1
uefihw.c File Reference
#include <uefildr.h>
#include "../vidfb.h"
#include <debug.h>
Include dependency graph for uefihw.c:

Go to the source code of this file.

Functions

 DBG_DEFAULT_CHANNEL (HWDETECT)
 
VOID StallExecutionProcessor (ULONG Microseconds)
 
VOID UefiHwIdle (VOID)
 
BOOLEAN IsAcpiPresent (VOID)
 
static PRSDP_DESCRIPTOR FindAcpiBios (VOID)
 
PDESCRIPTION_HEADER UefiFindAcpiTable (_In_ ULONG Signature)
 
VOID DetectAcpiBios (PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber)
 
static VOID DetectDisplayController (_In_ PCONFIGURATION_COMPONENT_DATA BusKey)
 
static VOID DetectInternal (PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber)
 
PCONFIGURATION_COMPONENT_DATA UefiHwDetect (_In_opt_ PCSTR Options)
 

Variables

EFI_SYSTEM_TABLEGlobalSystemTable
 
EFI_HANDLE GlobalImageHandle
 
ULONG_PTR VramAddress
 
ULONG VramSize
 
PCM_FRAMEBUF_DEVICE_DATA FrameBufferData
 
BOOLEAN AcpiPresent = FALSE
 
static EFI_EVENT IdleTimerEvent = NULL
 

Function Documentation

◆ DBG_DEFAULT_CHANNEL()

DBG_DEFAULT_CHANNEL ( HWDETECT  )

◆ DetectAcpiBios()

VOID DetectAcpiBios ( PCONFIGURATION_COMPONENT_DATA  SystemKey,
ULONG BusNumber 
)

Definition at line 144 of file uefihw.c.

145{
147 PCM_PARTIAL_RESOURCE_LIST PartialResourceList;
148 PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
149 PRSDP_DESCRIPTOR Rsdp;
150 PACPI_BIOS_DATA AcpiBiosData;
152
153 Rsdp = FindAcpiBios();
154
155 if (Rsdp)
156 {
157 /* Set up the flag in the loader block */
159
160 /* Calculate the table size */
161 TableSize = sizeof(ACPI_BIOS_DATA);
162
163 /* Set 'Configuration Data' value */
164 Size = FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, PartialDescriptors[1]) + TableSize;
165 PartialResourceList = FrLdrHeapAlloc(Size, TAG_HW_RESOURCE_LIST);
166 if (PartialResourceList == NULL)
167 {
168 ERR("Failed to allocate resource descriptor\n");
169 return;
170 }
171
172 RtlZeroMemory(PartialResourceList, Size);
173 PartialResourceList->Version = 0;
174 PartialResourceList->Revision = 0;
175 PartialResourceList->Count = 1;
176
177 PartialDescriptor = &PartialResourceList->PartialDescriptors[0];
178 PartialDescriptor->Type = CmResourceTypeDeviceSpecific;
180 PartialDescriptor->u.DeviceSpecificData.DataSize = TableSize;
181
182 /* Fill the table */
183 AcpiBiosData = (PACPI_BIOS_DATA)(PartialDescriptor + 1);
184
185 if (Rsdp->revision > 0)
186 {
187 TRACE("ACPI >1.0, using XSDT address\n");
188 AcpiBiosData->RSDTAddress.QuadPart = Rsdp->xsdt_physical_address;
189 }
190 else
191 {
192 TRACE("ACPI 1.0, using RSDT address\n");
193 AcpiBiosData->RSDTAddress.LowPart = Rsdp->rsdt_physical_address;
194 }
195
196 AcpiBiosData->Count = 0;
197
198 TRACE("RSDT %p, data size %x\n", Rsdp->rsdt_physical_address, TableSize);
199
200 /* Create new bus key */
201 FldrCreateComponentKey(SystemKey,
204 0x0,
205 0x0,
206 0xFFFFFFFF,
207 "ACPI BIOS",
208 PartialResourceList,
209 Size,
210 &BiosKey);
211
212 /* Increment bus number */
213 (*BusNumber)++;
214 }
215}
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
PVOID FrLdrHeapAlloc(SIZE_T MemorySize, ULONG Tag)
Definition: heap.c:533
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
struct _ACPI_BIOS_DATA ACPI_BIOS_DATA
struct _ACPI_BIOS_DATA * PACPI_BIOS_DATA
#define CmResourceTypeDeviceSpecific
Definition: restypes.h:108
@ AdapterClass
Definition: arc.h:102
@ MultiFunctionAdapter
Definition: arc.h:125
#define TRACE(s)
Definition: solgame.cpp:4
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
union _CM_PARTIAL_RESOURCE_DESCRIPTOR::@384 u
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@384::@393 DeviceSpecificData
CM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptors[1]
Definition: restypes.h:100
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG
Definition: typedefs.h:59
#define TAG_HW_RESOURCE_LIST
Definition: uefidisk.c:15
BOOLEAN AcpiPresent
Definition: uefihw.c:26
static PRSDP_DESCRIPTOR FindAcpiBios(VOID)
Definition: uefihw.c:74
LONGLONG QuadPart
Definition: typedefs.h:114
ULONG LowPart
Definition: typedefs.h:106
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4539
@ CmResourceShareUndetermined
Definition: cmtypes.h:240
_Must_inspect_result_ typedef _Out_ PULONG TableSize
Definition: iotypes.h:4330

Referenced by UefiHwDetect().

◆ DetectDisplayController()

static VOID DetectDisplayController ( _In_ PCONFIGURATION_COMPONENT_DATA  BusKey)
static

Definition at line 218 of file uefihw.c.

220{
221 PCONFIGURATION_COMPONENT_DATA ControllerKey;
222 PCM_PARTIAL_RESOURCE_LIST PartialResourceList;
223 PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
224 PCM_FRAMEBUF_DEVICE_DATA FramebufData;
225 ULONG Size;
226
227 if (!VramAddress || (VramSize == 0) || !FrameBufferData)
228 return;
229
230 Size = FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, PartialDescriptors[2]) + sizeof(*FramebufData);
231 PartialResourceList = FrLdrHeapAlloc(Size, TAG_HW_RESOURCE_LIST);
232 if (PartialResourceList == NULL)
233 {
234 ERR("Failed to allocate resource descriptor\n");
235 return;
236 }
237
238 /* Initialize resource descriptor */
239 RtlZeroMemory(PartialResourceList, Size);
240 PartialResourceList->Version = 1;
241 PartialResourceList->Revision = 2;
242 PartialResourceList->Count = 2;
243
244 /* Set Memory */
245 PartialDescriptor = &PartialResourceList->PartialDescriptors[0];
246 PartialDescriptor->Type = CmResourceTypeMemory;
248 PartialDescriptor->Flags = CM_RESOURCE_MEMORY_READ_WRITE;
249 PartialDescriptor->u.Memory.Start.QuadPart = VramAddress;
250 PartialDescriptor->u.Memory.Length = VramSize;
251
252 /* Set framebuffer-specific data */
253 PartialDescriptor = &PartialResourceList->PartialDescriptors[1];
254 PartialDescriptor->Type = CmResourceTypeDeviceSpecific;
256 PartialDescriptor->Flags = 0;
257 PartialDescriptor->u.DeviceSpecificData.DataSize = sizeof(*FramebufData);
258
259 /* Get pointer to framebuffer-specific data */
260 FramebufData = (PCM_FRAMEBUF_DEVICE_DATA)(PartialDescriptor + 1);
261 RtlCopyMemory(FramebufData, FrameBufferData, sizeof(*FrameBufferData));
262 FramebufData->Version = 1;
263 FramebufData->Revision = 3;
264 FramebufData->VideoClock = 0; // FIXME: Use EDID
265
270 0,
271 0xFFFFFFFF,
272 "UEFI GOP Framebuffer",
273 PartialResourceList,
274 Size,
275 &ControllerKey);
276
277 // NOTE: Don't add a MonitorPeripheral for now.
278 // We should use EDID data for it.
279}
#define CM_RESOURCE_MEMORY_READ_WRITE
Definition: cmtypes.h:121
#define CmResourceTypeMemory
Definition: restypes.h:106
@ ControllerClass
Definition: arc.h:103
@ DisplayController
Definition: arc.h:132
@ ConsoleOut
Definition: arc.h:92
@ Output
Definition: arc.h:94
struct _CM_FRAMEBUF_DEVICE_DATA * PCM_FRAMEBUF_DEVICE_DATA
ReactOS Framebuffer-specific video device configuration data.
Definition: framebuf.h:35
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@384::@389 Memory
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
ULONG_PTR VramAddress
Definition: uefivid.c:21
PCM_FRAMEBUF_DEVICE_DATA FrameBufferData
Definition: xboxvideo.c:31
ULONG VramSize
Definition: uefivid.c:22
@ CmResourceShareDeviceExclusive
Definition: cmtypes.h:241

Referenced by DetectInternal().

◆ DetectInternal()

static VOID DetectInternal ( PCONFIGURATION_COMPONENT_DATA  SystemKey,
ULONG BusNumber 
)
static

Definition at line 283 of file uefihw.c.

284{
285 PCM_PARTIAL_RESOURCE_LIST PartialResourceList;
287 ULONG Size;
288
289 /* Set 'Configuration Data' value */
290 Size = FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, PartialDescriptors);
291 PartialResourceList = FrLdrHeapAlloc(Size, TAG_HW_RESOURCE_LIST);
292 if (PartialResourceList == NULL)
293 {
294 ERR("Failed to allocate resource descriptor\n");
295 return;
296 }
297
298 /* Initialize resource descriptor */
299 RtlZeroMemory(PartialResourceList, Size);
300 PartialResourceList->Version = 1;
301 PartialResourceList->Revision = 1;
302 PartialResourceList->Count = 0;
303
304 /* Create new bus key */
305 FldrCreateComponentKey(SystemKey,
308 0,
309 0,
310 0xFFFFFFFF,
311 "UEFI Internal",
312 PartialResourceList,
313 Size,
314 &BusKey);
315
316 /* Increment bus number */
317 (*BusNumber)++;
318
319 /* Detect devices that do not belong to "standard" buses */
321
322 /* FIXME: Detect more devices */
323}
static VOID DetectDisplayController(_In_ PCONFIGURATION_COMPONENT_DATA BusKey)
Definition: uefihw.c:218

Referenced by UefiHwDetect().

◆ FindAcpiBios()

static PRSDP_DESCRIPTOR FindAcpiBios ( VOID  )
static

Definition at line 74 of file uefihw.c.

75{
76 UINTN i;
77 RSDP_DESCRIPTOR* rsdp = NULL;
79
81 {
83 &acpi2_guid, sizeof(acpi2_guid)))
84 {
86 break;
87 }
88 }
89
90 return rsdp;
91}
#define EFI_ACPI_20_TABLE_GUID
Definition: Acpi.h:40
UINT32 UINTN
_ACRTIMP int __cdecl memcmp(const void *, const void *, size_t)
Definition: string.c:2802
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
EFI_CONFIGURATION_TABLE * ConfigurationTable
Definition: UefiSpec.h:1968
UINTN NumberOfTableEntries
Definition: UefiSpec.h:1963
EFI_SYSTEM_TABLE * GlobalSystemTable
Definition: uefildr.c:16

Referenced by DetectAcpiBios(), and UefiFindAcpiTable().

◆ IsAcpiPresent()

BOOLEAN IsAcpiPresent ( VOID  )

Definition at line 67 of file uefihw.c.

68{
69 return AcpiPresent;
70}

Referenced by WinLdrInitializePhase1().

◆ StallExecutionProcessor()

VOID StallExecutionProcessor ( ULONG  Microseconds)

Definition at line 32 of file uefihw.c.

33{
34 GlobalSystemTable->BootServices->Stall(Microseconds);
35}
EFI_STALL Stall
Definition: UefiSpec.h:1852
EFI_BOOT_SERVICES * BootServices
Definition: UefiSpec.h:1959

Referenced by UefiHwIdle().

◆ UefiFindAcpiTable()

PDESCRIPTION_HEADER UefiFindAcpiTable ( _In_ ULONG  Signature)

Definition at line 94 of file uefihw.c.

96{
99
100 Rsdp = FindAcpiBios();
101 if (Rsdp == NULL)
102 return NULL;
103
104 if ((Rsdp->revision > 0) && (Rsdp->xsdt_physical_address != 0))
105 {
107
108 if ((Xsdt != NULL) && (Xsdt->Header.Length >= sizeof(Xsdt->Header)))
109 {
110 Count = (Xsdt->Header.Length - sizeof(Xsdt->Header)) / sizeof(Xsdt->Tables[0]);
111 for (Index = 0; Index < Count; ++Index)
112 {
115
116 if ((Header != NULL) && (Header->Signature == Signature))
117 return Header;
118 }
119 }
120 }
121
122 if (Rsdp->rsdt_physical_address != 0)
123 {
125
126 if ((Rsdt != NULL) && (Rsdt->Header.Length >= sizeof(Rsdt->Header)))
127 {
128 Count = (Rsdt->Header.Length - sizeof(Rsdt->Header)) / sizeof(Rsdt->Tables[0]);
129 for (Index = 0; Index < Count; ++Index)
130 {
133
134 if ((Header != NULL) && (Header->Signature == Signature))
135 return Header;
136 }
137 }
138 }
139
140 return NULL;
141}
Definition: Header.h:9
static const WCHAR Signature[]
Definition: parser.c:141
int Count
Definition: noreturn.cpp:7
RSDT * PRSDT
Definition: acpi.h:206
DESCRIPTION_HEADER * PDESCRIPTION_HEADER
Definition: acpi.h:109
XSDT * PXSDT
Definition: acpi.h:214
Definition: acpi.h:201
ULONG Tables[ANYSIZE_ARRAY]
Definition: acpi.h:204
DESCRIPTION_HEADER Header
Definition: acpi.h:203
Definition: acpi.h:209
PHYSICAL_ADDRESS Tables[ANYSIZE_ARRAY]
Definition: acpi.h:212
DESCRIPTION_HEADER Header
Definition: acpi.h:211
uint32_t ULONG_PTR
Definition: typedefs.h:65
_In_ WDFCOLLECTION _In_ ULONG Index

Referenced by UefiInitializeBgrtLogo().

◆ UefiHwDetect()

PCONFIGURATION_COMPONENT_DATA UefiHwDetect ( _In_opt_ PCSTR  Options)

Definition at line 326 of file uefihw.c.

328{
330 ULONG BusNumber = 0;
331
332 TRACE("DetectHardware()\n");
333
334 /* Create the 'System' key */
335#if defined(_M_IX86) || defined(_M_AMD64)
336 FldrCreateSystemKey(&SystemKey, "AT/AT COMPATIBLE");
337#elif defined(_M_IA64)
338 FldrCreateSystemKey(&SystemKey, "Intel Itanium processor family");
339#elif defined(_M_ARM) || defined(_M_ARM64)
340 FldrCreateSystemKey(&SystemKey, "ARM processor family");
341#else
342 #error Please define a system key for your architecture
343#endif
344
345 /* Detect buses */
346 DetectInternal(SystemKey, &BusNumber);
347 // TODO: DetectPciBios
348 DetectAcpiBios(SystemKey, &BusNumber);
349
350 TRACE("DetectHardware() Done\n");
351 return SystemKey;
352}
VOID FldrCreateSystemKey(_Out_ PCONFIGURATION_COMPONENT_DATA *SystemNode, _In_ PCSTR IdentifierString)
Definition: archwsup.c:135
VOID DetectAcpiBios(PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber)
Definition: uefihw.c:144
static VOID DetectInternal(PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber)
Definition: uefihw.c:283
_In_opt_ PUNICODE_STRING _In_ PDRIVER_OBJECT _In_ PDEVICE_OBJECT _In_ INTERFACE_TYPE _In_ ULONG BusNumber
Definition: halfuncs.h:160

Referenced by MachInit().

◆ UefiHwIdle()

VOID UefiHwIdle ( VOID  )

Definition at line 38 of file uefihw.c.

39{
43
44 /* Keep one timer event around and arm it each idle tick */
45 if (IdleTimerEvent == NULL)
46 {
47 Status = BootServices->CreateEvent(EVT_TIMER,
49 NULL,
50 NULL,
52 if (EFI_ERROR(Status))
53 {
54 StallExecutionProcessor(10000); /* 10 ms fallback */
55 return;
56 }
57 }
58
59 /* Set a 10ms (100,000 * 100ns) relative timer */
60 Status = BootServices->SetTimer(IdleTimerEvent, TimerRelative, 100000);
61 if (!EFI_ERROR(Status))
62 Status = BootServices->WaitForEvent(1, &IdleTimerEvent, &Index);
63 if (EFI_ERROR(Status))
64 StallExecutionProcessor(10000); /* 10 ms fallback */
65}
#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
Status
Definition: gdiplustypes.h:25
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
VOID StallExecutionProcessor(ULONG Microseconds)
Definition: uefihw.c:32
static EFI_EVENT IdleTimerEvent
Definition: uefihw.c:27

Referenced by MachInit().

Variable Documentation

◆ AcpiPresent

BOOLEAN AcpiPresent = FALSE

Definition at line 26 of file uefihw.c.

Referenced by DetectAcpiBios(), and IsAcpiPresent().

◆ FrameBufferData

◆ GlobalImageHandle

EFI_HANDLE GlobalImageHandle
extern

Definition at line 15 of file uefildr.c.

◆ GlobalSystemTable

EFI_SYSTEM_TABLE* GlobalSystemTable
extern

Definition at line 16 of file uefildr.c.

Referenced by FindAcpiBios(), StallExecutionProcessor(), and UefiHwIdle().

◆ IdleTimerEvent

EFI_EVENT IdleTimerEvent = NULL
static

Definition at line 27 of file uefihw.c.

Referenced by UefiHwIdle().

◆ VramAddress

◆ VramSize

ULONG VramSize
extern