ReactOS 0.4.16-dev-2232-gc2aaa52
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)
 
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
 
EFI_MEMORY_DESCRIPTOREfiMemoryMap
 
UINT32 FreeldrDescCount
 
ULONG_PTR VramAddress
 
ULONG VramSize
 
PCM_FRAMEBUF_DEVICE_DATA FrameBufferData
 
BOOLEAN AcpiPresent = FALSE
 

Function Documentation

◆ DBG_DEFAULT_CHANNEL()

DBG_DEFAULT_CHANNEL ( WARNING  )

◆ DetectAcpiBios()

VOID DetectAcpiBios ( PCONFIGURATION_COMPONENT_DATA  SystemKey,
ULONG BusNumber 
)

Definition at line 60 of file uefihw.c.

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}
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 * 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
BIOS_MEMORY_MAP MemoryMap[1]
Definition: pcbios.h:79
ULONGLONG Count
Definition: pcbios.h:78
union _CM_PARTIAL_RESOURCE_DESCRIPTOR::@432 u
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@432::@441 DeviceSpecificData
CM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptors[1]
Definition: restypes.h:100
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG
Definition: typedefs.h:59
#define TAG_HW_RESOURCE_LIST
Definition: uefidisk.c:15
UINT32 FreeldrDescCount
Definition: uefimem.c:35
EFI_MEMORY_DESCRIPTOR * EfiMemoryMap
Definition: uefimem.c:34
BOOLEAN AcpiPresent
Definition: uefihw.c:29
static PRSDP_DESCRIPTOR FindAcpiBios(VOID)
Definition: uefihw.c:40
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 137 of file uefihw.c.

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}
#define CM_RESOURCE_MEMORY_READ_WRITE
Definition: cmtypes.h:120
#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::@432::@437 Memory
ULONG_PTR VramAddress
Definition: uefivid.c:20
PCM_FRAMEBUF_DEVICE_DATA FrameBufferData
Definition: xboxvideo.c:31
ULONG VramSize
Definition: uefivid.c:21
@ CmResourceShareDeviceExclusive
Definition: cmtypes.h:241

Referenced by DetectInternal().

◆ DetectInternal()

static VOID DetectInternal ( PCONFIGURATION_COMPONENT_DATA  SystemKey,
ULONG BusNumber 
)
static

Definition at line 202 of file uefihw.c.

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

Referenced by UefiHwDetect().

◆ FindAcpiBios()

static PRSDP_DESCRIPTOR FindAcpiBios ( VOID  )
static

Definition at line 40 of file uefihw.c.

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

34{
35 return AcpiPresent;
36}

Referenced by WinLdrInitializePhase1().

◆ UefiHwDetect()

PCONFIGURATION_COMPONENT_DATA UefiHwDetect ( _In_opt_ PCSTR  Options)

Definition at line 245 of file uefihw.c.

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}
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:60
static VOID DetectInternal(PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber)
Definition: uefihw.c:202
_In_opt_ PUNICODE_STRING _In_ PDRIVER_OBJECT _In_ PDEVICE_OBJECT _In_ INTERFACE_TYPE _In_ ULONG BusNumber
Definition: halfuncs.h:160

Referenced by MachInit().

Variable Documentation

◆ AcpiPresent

BOOLEAN AcpiPresent = FALSE

Definition at line 29 of file uefihw.c.

Referenced by DetectAcpiBios(), and IsAcpiPresent().

◆ EfiMemoryMap

EFI_MEMORY_DESCRIPTOR* EfiMemoryMap
extern

◆ FrameBufferData

PCM_FRAMEBUF_DEVICE_DATA FrameBufferData
extern

Definition at line 31 of file xboxvideo.c.

Referenced by DetectDisplayController(), UefiInitializeVideo(), and XboxVideoInit().

◆ FreeldrDescCount

UINT32 FreeldrDescCount
extern

Definition at line 35 of file uefimem.c.

Referenced by DetectAcpiBios(), UefiMemGetMemoryMap(), and UefiSetMemory().

◆ 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().

◆ PcBiosDiskCount

◆ VramAddress

ULONG_PTR VramAddress
extern

Definition at line 20 of file uefivid.c.

Referenced by DetectDisplayController(), UefiInitializeVideo(), and VidInitialize().

◆ VramSize

ULONG VramSize
extern

Definition at line 21 of file uefivid.c.

Referenced by DetectDisplayController(), UefiInitializeVideo(), and VidInitialize().