ReactOS 0.4.17-dev-1190-g4c812f4
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_TABLE * GlobalSystemTable
 
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 151 of file uefihw.c.

152{
154 PCM_PARTIAL_RESOURCE_LIST PartialResourceList;
155 PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
156 PRSDP_DESCRIPTOR Rsdp;
157 PACPI_BIOS_DATA AcpiBiosData;
159
160 Rsdp = FindAcpiBios();
161
162 if (Rsdp)
163 {
164 /* Set up the flag in the loader block */
166
167 /* Calculate the table size */
168 TableSize = sizeof(ACPI_BIOS_DATA);
169
170 /* Set 'Configuration Data' value */
171 Size = FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, PartialDescriptors[1]) + TableSize;
172 PartialResourceList = FrLdrHeapAlloc(Size, TAG_HW_RESOURCE_LIST);
173 if (PartialResourceList == NULL)
174 {
175 ERR("Failed to allocate resource descriptor\n");
176 return;
177 }
178
179 RtlZeroMemory(PartialResourceList, Size);
180 PartialResourceList->Version = 0;
181 PartialResourceList->Revision = 0;
182 PartialResourceList->Count = 1;
183
184 PartialDescriptor = &PartialResourceList->PartialDescriptors[0];
185 PartialDescriptor->Type = CmResourceTypeDeviceSpecific;
187 PartialDescriptor->u.DeviceSpecificData.DataSize = TableSize;
188
189 /* Fill the table */
190 AcpiBiosData = (PACPI_BIOS_DATA)(PartialDescriptor + 1);
191
192 if (Rsdp->revision > 0)
193 {
194 TRACE("ACPI >1.0, using XSDT address\n");
195 AcpiBiosData->RSDTAddress.QuadPart = Rsdp->xsdt_physical_address;
196 }
197 else
198 {
199 TRACE("ACPI 1.0, using RSDT address\n");
200 AcpiBiosData->RSDTAddress.LowPart = Rsdp->rsdt_physical_address;
201 }
202
203 AcpiBiosData->Count = 0;
204
205 TRACE("RSDT %p, data size %x\n", Rsdp->rsdt_physical_address, TableSize);
206
207 /* Create new bus key */
208 FldrCreateComponentKey(SystemKey,
211 0x0,
212 0x0,
213 0xFFFFFFFF,
214 "ACPI BIOS",
215 PartialResourceList,
216 Size,
217 &BiosKey);
218
219 /* Increment bus number */
220 (*BusNumber)++;
221 }
222}
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:224
#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
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@494::@503 DeviceSpecificData
union _CM_PARTIAL_RESOURCE_DESCRIPTOR::@494 u
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:81
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:4343

Referenced by UefiHwDetect().

◆ DetectDisplayController()

static VOID DetectDisplayController ( _In_ PCONFIGURATION_COMPONENT_DATA  BusKey)
static

Definition at line 225 of file uefihw.c.

227{
228 PCONFIGURATION_COMPONENT_DATA ControllerKey;
229 PCM_PARTIAL_RESOURCE_LIST PartialResourceList;
230 PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
231 PCM_FRAMEBUF_DEVICE_DATA FramebufData;
232 ULONG Size;
233
234 if (!VramAddress || (VramSize == 0) || !FrameBufferData)
235 return;
236
237 Size = FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, PartialDescriptors[2]) + sizeof(*FramebufData);
238 PartialResourceList = FrLdrHeapAlloc(Size, TAG_HW_RESOURCE_LIST);
239 if (PartialResourceList == NULL)
240 {
241 ERR("Failed to allocate resource descriptor\n");
242 return;
243 }
244
245 /* Initialize resource descriptor */
246 RtlZeroMemory(PartialResourceList, Size);
247 PartialResourceList->Version = 1;
248 PartialResourceList->Revision = 2;
249 PartialResourceList->Count = 2;
250
251 /* Set Memory */
252 PartialDescriptor = &PartialResourceList->PartialDescriptors[0];
253 PartialDescriptor->Type = CmResourceTypeMemory;
255 PartialDescriptor->Flags = CM_RESOURCE_MEMORY_READ_WRITE;
256 PartialDescriptor->u.Memory.Start.QuadPart = VramAddress;
257 PartialDescriptor->u.Memory.Length = VramSize;
258
259 /* Set framebuffer-specific data */
260 PartialDescriptor = &PartialResourceList->PartialDescriptors[1];
261 PartialDescriptor->Type = CmResourceTypeDeviceSpecific;
263 PartialDescriptor->Flags = 0;
264 PartialDescriptor->u.DeviceSpecificData.DataSize = sizeof(*FramebufData);
265
266 /* Get pointer to framebuffer-specific data */
267 FramebufData = (PCM_FRAMEBUF_DEVICE_DATA)(PartialDescriptor + 1);
268 RtlCopyMemory(FramebufData, FrameBufferData, sizeof(*FrameBufferData));
269 FramebufData->Version = 1;
270 FramebufData->Revision = 3;
271 FramebufData->VideoClock = 0; // FIXME: Use EDID
272
277 0,
278 0xFFFFFFFF,
279 "UEFI GOP Framebuffer",
280 PartialResourceList,
281 Size,
282 &ControllerKey);
283
284 // NOTE: Don't add a MonitorPeripheral for now.
285 // We should use EDID data for it.
286}
#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::@494::@499 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 290 of file uefihw.c.

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

Referenced by UefiHwDetect().

◆ FindAcpiBios()

static PRSDP_DESCRIPTOR FindAcpiBios ( VOID  )
static

Definition at line 81 of file uefihw.c.

82{
83 UINTN i;
84 RSDP_DESCRIPTOR* rsdp = NULL;
86
88 {
90 &acpi2_guid, sizeof(acpi2_guid)))
91 {
93 break;
94 }
95 }
96
97 return rsdp;
98}
#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:2807
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 74 of file uefihw.c.

75{
76 return AcpiPresent;
77}

Referenced by WinLdrInitializePhase1().

◆ StallExecutionProcessor()

VOID StallExecutionProcessor ( ULONG  Microseconds)

Definition at line 39 of file uefihw.c.

40{
41 GlobalSystemTable->BootServices->Stall(Microseconds);
42}
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 101 of file uefihw.c.

103{
105 PRSDP_DESCRIPTOR Rsdp;
106
107 Rsdp = FindAcpiBios();
108 if (Rsdp == NULL)
109 return NULL;
110
111 if ((Rsdp->revision > 0) && (Rsdp->xsdt_physical_address != 0))
112 {
114
115 if ((Xsdt != NULL) && (Xsdt->Header.Length >= sizeof(Xsdt->Header)))
116 {
117 Count = (Xsdt->Header.Length - sizeof(Xsdt->Header)) / sizeof(Xsdt->Tables[0]);
118 for (Index = 0; Index < Count; ++Index)
119 {
122
123 if ((Header != NULL) && (Header->Signature == Signature))
124 return Header;
125 }
126 }
127 }
128
129 if (Rsdp->rsdt_physical_address != 0)
130 {
132
133 if ((Rsdt != NULL) && (Rsdt->Header.Length >= sizeof(Rsdt->Header)))
134 {
135 Count = (Rsdt->Header.Length - sizeof(Rsdt->Header)) / sizeof(Rsdt->Tables[0]);
136 for (Index = 0; Index < Count; ++Index)
137 {
140
141 if ((Header != NULL) && (Header->Signature == Signature))
142 return Header;
143 }
144 }
145 }
146
147 return NULL;
148}
Definition: Header.h:9
static const WCHAR Signature[]
Definition: parser.c:141
int Count
Definition: noreturn.cpp:7
RSDT * PRSDT
Definition: acpi.h:207
DESCRIPTION_HEADER * PDESCRIPTION_HEADER
Definition: acpi.h:110
XSDT * PXSDT
Definition: acpi.h:215
Definition: acpi.h:202
ULONG Tables[ANYSIZE_ARRAY]
Definition: acpi.h:205
DESCRIPTION_HEADER Header
Definition: acpi.h:204
Definition: acpi.h:210
PHYSICAL_ADDRESS Tables[ANYSIZE_ARRAY]
Definition: acpi.h:213
DESCRIPTION_HEADER Header
Definition: acpi.h:212
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 494 of file uefihw.c.

496{
498 ULONG BusNumber = 0;
499
500 TRACE("DetectHardware()\n");
501
502 /* Create the 'System' key */
503#if defined(_M_IX86) || defined(_M_AMD64)
504 FldrCreateSystemKey(&SystemKey, "AT/AT COMPATIBLE");
505#elif defined(_M_IA64)
506 FldrCreateSystemKey(&SystemKey, "Intel Itanium processor family");
507#elif defined(_M_ARM) || defined(_M_ARM64)
508 FldrCreateSystemKey(&SystemKey, "ARM processor family");
509#else
510 #error Please define a system key for your architecture
511#endif
512
513 /* Detect buses */
514 DetectInternal(SystemKey, &BusNumber);
515#if defined(_M_IX86) || defined(_M_AMD64)
516 DetectPciBus(SystemKey, &BusNumber, UefiDetectPciBus);
517#endif
518 DetectAcpiBios(SystemKey, &BusNumber);
519
520 TRACE("DetectHardware() Done\n");
521 return SystemKey;
522}
VOID FldrCreateSystemKey(_Out_ PCONFIGURATION_COMPONENT_DATA *SystemNode, _In_ PCSTR IdentifierString)
Definition: archwsup.c:161
VOID DetectPciBus(_In_ PCONFIGURATION_COMPONENT_DATA SystemKey, _Inout_ PULONG BusNumber, _In_ DETECT_PCI_BUS MachDetectPciBus)
Detects and reports the PCI buses found on the platform. Only conventional PCI buses (or PCIe buses o...
Definition: hwpci.c:23
_In_ ULONG BusNumber
Definition: pciidex.h:65
VOID DetectAcpiBios(PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber)
Definition: uefihw.c:151
static VOID DetectInternal(PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber)
Definition: uefihw.c:290

Referenced by MachInit().

◆ UefiHwIdle()

VOID UefiHwIdle ( VOID  )

Definition at line 45 of file uefihw.c.

46{
50
51 /* Keep one timer event around and arm it each idle tick */
52 if (IdleTimerEvent == NULL)
53 {
54 Status = BootServices->CreateEvent(EVT_TIMER,
56 NULL,
57 NULL,
59 if (EFI_ERROR(Status))
60 {
61 StallExecutionProcessor(10000); /* 10 ms fallback */
62 return;
63 }
64 }
65
66 /* Set a 10ms (100,000 * 100ns) relative timer */
67 Status = BootServices->SetTimer(IdleTimerEvent, TimerRelative, 100000);
68 if (!EFI_ERROR(Status))
69 Status = BootServices->WaitForEvent(1, &IdleTimerEvent, &Index);
70 if (EFI_ERROR(Status))
71 StallExecutionProcessor(10000); /* 10 ms fallback */
72}
#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:24
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:39
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