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