ReactOS 0.4.16-dev-2359-g4b75ec5
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 (WARNING)
 
VOID StallExecutionProcessor (ULONG Microseconds)
 
VOID UefiHwIdle (VOID)
 
BOOLEAN IsAcpiPresent (VOID)
 
static PRSDP_DESCRIPTOR FindAcpiBios (VOID)
 
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
 
UCHAR PcBiosDiskCount
 
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 ( WARNING  )

◆ DetectAcpiBios()

VOID DetectAcpiBios ( PCONFIGURATION_COMPONENT_DATA  SystemKey,
ULONG BusNumber 
)

Definition at line 95 of file uefihw.c.

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}
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:27
static PRSDP_DESCRIPTOR FindAcpiBios(VOID)
Definition: uefihw.c:75
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 169 of file uefihw.c.

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}
#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 234 of file uefihw.c.

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}
static VOID DetectDisplayController(_In_ PCONFIGURATION_COMPONENT_DATA BusKey)
Definition: uefihw.c:169

Referenced by UefiHwDetect().

◆ FindAcpiBios()

static PRSDP_DESCRIPTOR FindAcpiBios ( VOID  )
static

Definition at line 75 of file uefihw.c.

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}
#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().

◆ IsAcpiPresent()

BOOLEAN IsAcpiPresent ( VOID  )

Definition at line 68 of file uefihw.c.

69{
70 return AcpiPresent;
71}

Referenced by WinLdrInitializePhase1().

◆ StallExecutionProcessor()

VOID StallExecutionProcessor ( ULONG  Microseconds)

Definition at line 33 of file uefihw.c.

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

Referenced by UefiHwIdle().

◆ UefiHwDetect()

PCONFIGURATION_COMPONENT_DATA UefiHwDetect ( _In_opt_ PCSTR  Options)

Definition at line 277 of file uefihw.c.

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}
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:95
static VOID DetectInternal(PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber)
Definition: uefihw.c:234
_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 39 of file uefihw.c.

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}
#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:33
static EFI_EVENT IdleTimerEvent
Definition: uefihw.c:28
_In_ WDFCOLLECTION _In_ ULONG Index

Referenced by MachInit().

Variable Documentation

◆ AcpiPresent

BOOLEAN AcpiPresent = FALSE

Definition at line 27 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 28 of file uefihw.c.

Referenced by UefiHwIdle().

◆ PcBiosDiskCount

◆ VramAddress

ULONG_PTR VramAddress
extern

◆ VramSize

ULONG VramSize
extern