ReactOS 0.4.17-dev-812-ged4f258
hwpci.c File Reference
#include <freeldr.h>
#include <debug.h>
Include dependency graph for hwpci.c:

Go to the source code of this file.

Functions

 DBG_DEFAULT_CHANNEL (HWDETECT)
 
static PPCI_IRQ_ROUTING_TABLE GetPciIrqRoutingTable (VOID)
 
BOOLEAN PcFindPciBios (_Out_ PPCI_REGISTRY_INFO BusData)
 
static VOID DetectPciIrqRoutingTable (_In_ PCONFIGURATION_COMPONENT_DATA BusKey)
 
VOID DetectPciBios (_In_ PCONFIGURATION_COMPONENT_DATA SystemKey, _Inout_ PULONG BusNumber, _In_ FIND_PCI_BIOS MachFindPciBios)
 

Function Documentation

◆ DBG_DEFAULT_CHANNEL()

DBG_DEFAULT_CHANNEL ( HWDETECT  )

◆ DetectPciBios()

VOID DetectPciBios ( _In_ PCONFIGURATION_COMPONENT_DATA  SystemKey,
_Inout_ PULONG  BusNumber,
_In_ FIND_PCI_BIOS  MachFindPciBios 
)

Definition at line 171 of file hwpci.c.

175{
176 PCI_REGISTRY_INFO BusData;
177 PCM_PARTIAL_RESOURCE_LIST PartialResourceList;
178 PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
181 ULONG Size;
182 ULONG i;
183
184 /* Report the PCI BIOS */
185 if (!MachFindPciBios(&BusData))
186 return;
187
188 /* Set 'Configuration Data' value */
189 Size = FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, PartialDescriptors);
190 PartialResourceList = FrLdrHeapAlloc(Size, TAG_HW_RESOURCE_LIST);
191 if (PartialResourceList == NULL)
192 {
193 ERR("Failed to allocate resource descriptor\n");
194 return;
195 }
196
197 /* Initialize resource descriptor */
198 RtlZeroMemory(PartialResourceList, Size);
199
200 /* Create new bus key */
201 FldrCreateComponentKey(SystemKey,
204 0,
205 0,
206 0xFFFFFFFF,
207 "PCI BIOS",
208 PartialResourceList,
209 Size,
210 &BiosKey);
211
212 /* Increment bus number */
213 (*BusNumber)++;
214
216
217 /* Report PCI buses */
218 for (i = 0; i < (ULONG)BusData.NoBuses; i++)
219 {
220 /* Check if this is the first bus */
221 if (i == 0)
222 {
223 /* Set 'Configuration Data' value */
224 Size = FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, PartialDescriptors[1]) +
225 sizeof(BusData);
226 PartialResourceList = FrLdrHeapAlloc(Size, TAG_HW_RESOURCE_LIST);
227 if (!PartialResourceList)
228 {
229 ERR("Failed to allocate resource descriptor! Ignoring remaining PCI buses. (i = %lu, NoBuses = %lu)\n",
230 i, (ULONG)BusData.NoBuses);
231 return;
232 }
233
234 /* Initialize resource descriptor */
235 RtlZeroMemory(PartialResourceList, Size);
236 PartialResourceList->Version = 1;
237 PartialResourceList->Revision = 1;
238 PartialResourceList->Count = 1;
239
240 PartialDescriptor = &PartialResourceList->PartialDescriptors[0];
241 PartialDescriptor->Type = CmResourceTypeDeviceSpecific;
243 PartialDescriptor->u.DeviceSpecificData.DataSize = sizeof(BusData);
244
245 RtlCopyMemory(&PartialResourceList->PartialDescriptors[1],
246 &BusData, sizeof(BusData));
247 }
248 else
249 {
250 /* Set 'Configuration Data' value */
251 Size = FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, PartialDescriptors);
252 PartialResourceList = FrLdrHeapAlloc(Size, TAG_HW_RESOURCE_LIST);
253 if (!PartialResourceList)
254 {
255 ERR("Failed to allocate resource descriptor! Ignoring remaining PCI buses. (i = %lu, NoBuses = %lu)\n",
256 i, (ULONG)BusData.NoBuses);
257 return;
258 }
259
260 /* Initialize resource descriptor */
261 RtlZeroMemory(PartialResourceList, Size);
262 }
263
264 /* Create the bus key */
265 FldrCreateComponentKey(SystemKey,
268 0,
269 0,
270 0xFFFFFFFF,
271 "PCI",
272 PartialResourceList,
273 Size,
274 &BusKey);
275
276 /* Increment bus number */
277 (*BusNumber)++;
278 }
279}
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
static VOID DetectPciIrqRoutingTable(_In_ PCONFIGURATION_COMPONENT_DATA BusKey)
Definition: hwpci.c:114
PVOID FrLdrHeapAlloc(SIZE_T MemorySize, ULONG Tag)
Definition: heap.c:533
#define NULL
Definition: types.h:112
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 CmResourceTypeDeviceSpecific
Definition: restypes.h:108
@ AdapterClass
Definition: arc.h:102
@ MultiFunctionAdapter
Definition: arc.h:125
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@399::@408 DeviceSpecificData
union _CM_PARTIAL_RESOURCE_DESCRIPTOR::@399 u
CM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptors[1]
Definition: restypes.h:100
UCHAR NoBuses
Definition: pci.h:109
#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
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4539
@ CmResourceShareUndetermined
Definition: cmtypes.h:240

Referenced by Pc98HwDetect(), PcHwDetect(), and XboxHwDetect().

◆ DetectPciIrqRoutingTable()

static VOID DetectPciIrqRoutingTable ( _In_ PCONFIGURATION_COMPONENT_DATA  BusKey)
static

Definition at line 114 of file hwpci.c.

116{
117 PCM_PARTIAL_RESOURCE_LIST PartialResourceList;
118 PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
121 ULONG Size;
122
124 if (!Table)
125 return;
126
127 TRACE("Table size: %u\n", Table->TableSize);
128
129 /* Set 'Configuration Data' value */
130 Size = FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, PartialDescriptors[2]) + Table->TableSize;
131 PartialResourceList = FrLdrHeapAlloc(Size, TAG_HW_RESOURCE_LIST);
132 if (PartialResourceList == NULL)
133 {
134 ERR("Failed to allocate resource descriptor\n");
135 return;
136 }
137
138 /* Initialize resource descriptor */
139 RtlZeroMemory(PartialResourceList, Size);
140 PartialResourceList->Version = 1;
141 PartialResourceList->Revision = 1;
142 PartialResourceList->Count = 2;
143
144 PartialDescriptor = &PartialResourceList->PartialDescriptors[0];
145 PartialDescriptor->Type = CmResourceTypeBusNumber;
147 PartialDescriptor->u.BusNumber.Start = 0;
148 PartialDescriptor->u.BusNumber.Length = 1;
149
150 PartialDescriptor = &PartialResourceList->PartialDescriptors[1];
151 PartialDescriptor->Type = CmResourceTypeDeviceSpecific;
153 PartialDescriptor->u.DeviceSpecificData.DataSize = Table->TableSize;
154
155 RtlCopyMemory(&PartialResourceList->PartialDescriptors[2],
156 Table, Table->TableSize);
157
161 0,
162 0,
163 0xFFFFFFFF,
164 "PCI Real-mode IRQ Routing Table",
165 PartialResourceList,
166 Size,
167 &TableKey);
168}
static PPCI_IRQ_ROUTING_TABLE GetPciIrqRoutingTable(VOID)
Definition: hwpci.c:28
ASMGENDATA Table[]
Definition: genincdata.c:61
#define CmResourceTypeBusNumber
Definition: restypes.h:109
@ PeripheralClass
Definition: arc.h:104
@ RealModeIrqRoutingTable
Definition: arc.h:152
#define TRACE(s)
Definition: solgame.cpp:4
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@399::@407 BusNumber
@ CmResourceShareDeviceExclusive
Definition: cmtypes.h:241

Referenced by DetectPciBios().

◆ GetPciIrqRoutingTable()

static PPCI_IRQ_ROUTING_TABLE GetPciIrqRoutingTable ( VOID  )
static

Definition at line 28 of file hwpci.c.

29{
31 PUCHAR Ptr;
32 ULONG Sum;
33 ULONG i;
34
36 while ((ULONG_PTR)Table < 0x100000)
37 {
38 if (Table->Signature == 'RIP$')
39 {
40 TRACE("Found signature\n");
41
42 if (Table->TableSize < FIELD_OFFSET(PCI_IRQ_ROUTING_TABLE, Slot) ||
43 Table->TableSize % 16 != 0)
44 {
45 ERR("Invalid routing table size (%u) at 0x%p. Continue searching...\n", Table->TableSize, Table);
47 continue;
48 }
49
50 Ptr = (PUCHAR)Table;
51 Sum = 0;
52 for (i = 0; i < Table->TableSize; i++)
53 {
54 Sum += Ptr[i];
55 }
56
57 if ((Sum & 0xFF) != 0)
58 {
59 ERR("Invalid routing table checksum (%#lx) at 0x%p. Continue searching...\n", Sum & 0xFF, Table);
60 }
61 else
62 {
63 TRACE("Valid checksum (%#lx): found routing table at 0x%p\n", Sum & 0xFF, Table);
64 return Table;
65 }
66 }
67
69 }
70
71 ERR("No valid routing table found!\n");
72
73 return NULL;
74}
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
struct _PCI_IRQ_ROUTING_TABLE * PPCI_IRQ_ROUTING_TABLE
uint32_t ULONG_PTR
Definition: typedefs.h:65
unsigned char * PUCHAR
Definition: typedefs.h:53

Referenced by DetectPciIrqRoutingTable().

◆ PcFindPciBios()

BOOLEAN PcFindPciBios ( _Out_ PPCI_REGISTRY_INFO  BusData)

Definition at line 77 of file hwpci.c.

79{
80 REGS RegsIn;
81 REGS RegsOut;
82
83 RegsIn.b.ah = 0xB1; /* Subfunction B1h */
84 RegsIn.b.al = 0x01; /* PCI BIOS present */
85
86 Int386(0x1A, &RegsIn, &RegsOut);
87
88 if (INT386_SUCCESS(RegsOut) &&
89 (RegsOut.d.edx == ' ICP') &&
90 (RegsOut.b.ah == 0))
91 {
92 TRACE("Found PCI bios\n");
93
94 TRACE("AL: %x\n", RegsOut.b.al);
95 TRACE("BH: %x\n", RegsOut.b.bh);
96 TRACE("BL: %x\n", RegsOut.b.bl);
97 TRACE("CL: %x\n", RegsOut.b.cl);
98
99 BusData->NoBuses = RegsOut.b.cl + 1;
100 BusData->MajorRevision = RegsOut.b.bh;
101 BusData->MinorRevision = RegsOut.b.bl;
102 BusData->HardwareMechanism = RegsOut.b.al;
103
104 return TRUE;
105 }
106
107 TRACE("No PCI bios found\n");
108
109 return FALSE;
110}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define INT386_SUCCESS(regs)
Definition: pcbios.h:181
int __cdecl Int386(int ivec, REGS *in, REGS *out)
unsigned char bl
Definition: pcbios.h:136
unsigned char cl
Definition: pcbios.h:139
unsigned char al
Definition: pcbios.h:133
unsigned char ah
Definition: pcbios.h:134
unsigned char bh
Definition: pcbios.h:137
unsigned long edx
Definition: pcbios.h:96
Definition: pcbios.h:161
DWORDREGS d
Definition: pcbios.h:163
BYTEREGS b
Definition: pcbios.h:165

Referenced by Pc98HwDetect(), and PcHwDetect().