ReactOS 0.4.16-dev-2284-g3529151
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
23
24/* From uefivid.c */
26extern ULONG VramSize;
28
30
31/* FUNCTIONS *****************************************************************/
32
34{
35 return AcpiPresent;
36}
37
38static
41{
42 UINTN i;
43 RSDP_DESCRIPTOR* rsdp = NULL;
45
47 {
49 &acpi2_guid, sizeof(acpi2_guid)))
50 {
52 break;
53 }
54 }
55
56 return rsdp;
57}
58
59VOID
61{
63 PCM_PARTIAL_RESOURCE_LIST PartialResourceList;
64 PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
66 PACPI_BIOS_DATA AcpiBiosData;
68
69 Rsdp = FindAcpiBios();
70
71 if (Rsdp)
72 {
73 /* Set up the flag in the loader block */
75
76 /* Calculate the table size */
78 sizeof(ACPI_BIOS_DATA) - sizeof(BIOS_MEMORY_MAP);
79
80 /* Set 'Configuration Data' value */
81 Size = FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, PartialDescriptors[1]) + TableSize;
82 PartialResourceList = FrLdrHeapAlloc(Size, TAG_HW_RESOURCE_LIST);
83 if (PartialResourceList == NULL)
84 {
85 ERR("Failed to allocate resource descriptor\n");
86 return;
87 }
88
89 RtlZeroMemory(PartialResourceList, Size);
90 PartialResourceList->Version = 0;
91 PartialResourceList->Revision = 0;
92 PartialResourceList->Count = 1;
93
94 PartialDescriptor = &PartialResourceList->PartialDescriptors[0];
95 PartialDescriptor->Type = CmResourceTypeDeviceSpecific;
97 PartialDescriptor->u.DeviceSpecificData.DataSize = TableSize;
98
99 /* Fill the table */
100 AcpiBiosData = (PACPI_BIOS_DATA)(PartialDescriptor + 1);
101
102 if (Rsdp->revision > 0)
103 {
104 TRACE("ACPI >1.0, using XSDT address\n");
105 AcpiBiosData->RSDTAddress.QuadPart = Rsdp->xsdt_physical_address;
106 }
107 else
108 {
109 TRACE("ACPI 1.0, using RSDT address\n");
110 AcpiBiosData->RSDTAddress.LowPart = Rsdp->rsdt_physical_address;
111 }
112
113 AcpiBiosData->Count = FreeldrDescCount;
114 RtlCopyMemory(AcpiBiosData->MemoryMap, EfiMemoryMap,
116
117 TRACE("RSDT %p, data size %x\n", Rsdp->rsdt_physical_address, TableSize);
118
119 /* Create new bus key */
120 FldrCreateComponentKey(SystemKey,
123 0x0,
124 0x0,
125 0xFFFFFFFF,
126 "ACPI BIOS",
127 PartialResourceList,
128 Size,
129 &BiosKey);
130
131 /* Increment bus number */
132 (*BusNumber)++;
133 }
134}
135
136static VOID
139{
140 PCONFIGURATION_COMPONENT_DATA ControllerKey;
141 PCM_PARTIAL_RESOURCE_LIST PartialResourceList;
142 PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
143 PCM_FRAMEBUF_DEVICE_DATA FramebufData;
144 ULONG Size;
145
146 if (!VramAddress || (VramSize == 0) || !FrameBufferData)
147 return;
148
149 Size = FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, PartialDescriptors[2]) + sizeof(*FramebufData);
150 PartialResourceList = FrLdrHeapAlloc(Size, TAG_HW_RESOURCE_LIST);
151 if (PartialResourceList == NULL)
152 {
153 ERR("Failed to allocate resource descriptor\n");
154 return;
155 }
156
157 /* Initialize resource descriptor */
158 RtlZeroMemory(PartialResourceList, Size);
159 PartialResourceList->Version = 1;
160 PartialResourceList->Revision = 2;
161 PartialResourceList->Count = 2;
162
163 /* Set Memory */
164 PartialDescriptor = &PartialResourceList->PartialDescriptors[0];
165 PartialDescriptor->Type = CmResourceTypeMemory;
167 PartialDescriptor->Flags = CM_RESOURCE_MEMORY_READ_WRITE;
168 PartialDescriptor->u.Memory.Start.QuadPart = VramAddress;
169 PartialDescriptor->u.Memory.Length = VramSize;
170
171 /* Set framebuffer-specific data */
172 PartialDescriptor = &PartialResourceList->PartialDescriptors[1];
173 PartialDescriptor->Type = CmResourceTypeDeviceSpecific;
175 PartialDescriptor->Flags = 0;
176 PartialDescriptor->u.DeviceSpecificData.DataSize = sizeof(*FramebufData);
177
178 /* Get pointer to framebuffer-specific data */
179 FramebufData = (PCM_FRAMEBUF_DEVICE_DATA)(PartialDescriptor + 1);
180 RtlCopyMemory(FramebufData, FrameBufferData, sizeof(*FrameBufferData));
181 FramebufData->Version = 1;
182 FramebufData->Revision = 3;
183 FramebufData->VideoClock = 0; // FIXME: Use EDID
184
189 0,
190 0xFFFFFFFF,
191 "UEFI GOP Framebuffer",
192 PartialResourceList,
193 Size,
194 &ControllerKey);
195
196 // NOTE: Don't add a MonitorPeripheral for now.
197 // We should use EDID data for it.
198}
199
200static
201VOID
203{
204 PCM_PARTIAL_RESOURCE_LIST PartialResourceList;
206 ULONG Size;
207
208 /* Set 'Configuration Data' value */
209 Size = FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, PartialDescriptors);
210 PartialResourceList = FrLdrHeapAlloc(Size, TAG_HW_RESOURCE_LIST);
211 if (PartialResourceList == NULL)
212 {
213 ERR("Failed to allocate resource descriptor\n");
214 return;
215 }
216
217 /* Initialize resource descriptor */
218 RtlZeroMemory(PartialResourceList, Size);
219 PartialResourceList->Version = 1;
220 PartialResourceList->Revision = 1;
221 PartialResourceList->Count = 0;
222
223 /* Create new bus key */
224 FldrCreateComponentKey(SystemKey,
227 0,
228 0,
229 0xFFFFFFFF,
230 "UEFI Internal",
231 PartialResourceList,
232 Size,
233 &BusKey);
234
235 /* Increment bus number */
236 (*BusNumber)++;
237
238 /* Detect devices that do not belong to "standard" buses */
240
241 /* FIXME: Detect more devices */
242}
243
247{
249 ULONG BusNumber = 0;
250
251 TRACE("DetectHardware()\n");
252
253 /* Create the 'System' key */
254#if defined(_M_IX86) || defined(_M_AMD64)
255 FldrCreateSystemKey(&SystemKey, "AT/AT COMPATIBLE");
256#elif defined(_M_IA64)
257 FldrCreateSystemKey(&SystemKey, "Intel Itanium processor family");
258#elif defined(_M_ARM) || defined(_M_ARM64)
259 FldrCreateSystemKey(&SystemKey, "ARM processor family");
260#else
261 #error Please define a system key for your architecture
262#endif
263
264 /* Detect buses */
265 DetectInternal(SystemKey, &BusNumber);
266 // TODO: DetectPciBios
267 DetectAcpiBios(SystemKey, &BusNumber);
268
269 TRACE("DetectHardware() Done\n");
270 return SystemKey;
271}
#define EFI_ACPI_20_TABLE_GUID
Definition: Acpi.h:40
#define WARNING
Definition: BusLogic958.h:56
UINT32 UINTN
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
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:120
#define _In_
Definition: no_sal2.h:158
#define _In_opt_
Definition: no_sal2.h:212
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_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
BIOS_MEMORY_MAP MemoryMap[1]
Definition: pcbios.h:79
ULONGLONG Count
Definition: pcbios.h:78
ReactOS Framebuffer-specific video device configuration data.
Definition: framebuf.h:35
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@382::@391 DeviceSpecificData
union _CM_PARTIAL_RESOURCE_DESCRIPTOR::@382 u
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@382::@387 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 UINT32
Definition: typedefs.h:59
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:60
static VOID DetectDisplayController(_In_ PCONFIGURATION_COMPONENT_DATA BusKey)
Definition: uefihw.c:137
UINT32 FreeldrDescCount
Definition: uefimem.c:34
EFI_MEMORY_DESCRIPTOR * EfiMemoryMap
Definition: uefimem.c:33
static VOID DetectInternal(PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber)
Definition: uefihw.c:202
ULONG_PTR VramAddress
Definition: uefivid.c:20
BOOLEAN IsAcpiPresent(VOID)
Definition: uefihw.c:33
BOOLEAN AcpiPresent
Definition: uefihw.c:29
PCONFIGURATION_COMPONENT_DATA UefiHwDetect(_In_opt_ PCSTR Options)
Definition: uefihw.c:245
EFI_SYSTEM_TABLE * GlobalSystemTable
Definition: uefildr.c:16
PCM_FRAMEBUF_DEVICE_DATA FrameBufferData
Definition: xboxvideo.c:31
static PRSDP_DESCRIPTOR FindAcpiBios(VOID)
Definition: uefihw.c:40
ULONG VramSize
Definition: uefivid.c:21
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_ 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