ReactOS 0.4.16-dev-2293-g4d8327b
hwpci.c
Go to the documentation of this file.
1/*
2 * FreeLoader
3 *
4 * Copyright (C) 2004 Eric Kohl
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21#include <freeldr.h>
22
23#include <debug.h>
25
27
28static
31{
33 PUCHAR Ptr;
34 ULONG Sum;
35 ULONG i;
36
38 while ((ULONG_PTR)Table < 0x100000)
39 {
40 if (Table->Signature == 'RIP$')
41 {
42 TRACE("Found signature\n");
43
44 if (Table->TableSize < FIELD_OFFSET(PCI_IRQ_ROUTING_TABLE, Slot) ||
45 Table->TableSize % 16 != 0)
46 {
47 ERR("Invalid routing table size (%u) at 0x%p. Continue searching...\n", Table->TableSize, Table);
49 continue;
50 }
51
52 Ptr = (PUCHAR)Table;
53 Sum = 0;
54 for (i = 0; i < Table->TableSize; i++)
55 {
56 Sum += Ptr[i];
57 }
58
59 if ((Sum & 0xFF) != 0)
60 {
61 ERR("Invalid routing table checksum (%#lx) at 0x%p. Continue searching...\n", Sum & 0xFF, Table);
62 }
63 else
64 {
65 TRACE("Valid checksum (%#lx): found routing table at 0x%p\n", Sum & 0xFF, Table);
66 return Table;
67 }
68 }
69
71 }
72
73 ERR("No valid routing table found!\n");
74
75 return NULL;
76}
77
78
81{
82 REGS RegsIn;
83 REGS RegsOut;
84
85 RegsIn.b.ah = 0xB1; /* Subfunction B1h */
86 RegsIn.b.al = 0x01; /* PCI BIOS present */
87
88 Int386(0x1A, &RegsIn, &RegsOut);
89
90 if (INT386_SUCCESS(RegsOut) &&
91 (RegsOut.d.edx == ' ICP') &&
92 (RegsOut.b.ah == 0))
93 {
94 TRACE("Found PCI bios\n");
95
96 TRACE("AL: %x\n", RegsOut.b.al);
97 TRACE("BH: %x\n", RegsOut.b.bh);
98 TRACE("BL: %x\n", RegsOut.b.bl);
99 TRACE("CL: %x\n", RegsOut.b.cl);
100
101 BusData->NoBuses = RegsOut.b.cl + 1;
102 BusData->MajorRevision = RegsOut.b.bh;
103 BusData->MinorRevision = RegsOut.b.bl;
104 BusData->HardwareMechanism = RegsOut.b.al;
105
106 return TRUE;
107 }
108
109 TRACE("No PCI bios found\n");
110
111 return FALSE;
112}
113
114
115static
116VOID
118{
119 PCM_PARTIAL_RESOURCE_LIST PartialResourceList;
120 PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
123 ULONG Size;
124
126 if (Table != NULL)
127 {
128 TRACE("Table size: %u\n", Table->TableSize);
129
130 /* Set 'Configuration Data' value */
131 Size = FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, PartialDescriptors[2]) + Table->TableSize;
132 PartialResourceList = FrLdrHeapAlloc(Size, TAG_HW_RESOURCE_LIST);
133 if (PartialResourceList == NULL)
134 {
135 ERR("Failed to allocate resource descriptor\n");
136 return;
137 }
138
139 /* Initialize resource descriptor */
140 RtlZeroMemory(PartialResourceList, Size);
141 PartialResourceList->Version = 1;
142 PartialResourceList->Revision = 1;
143 PartialResourceList->Count = 2;
144
145 PartialDescriptor = &PartialResourceList->PartialDescriptors[0];
146 PartialDescriptor->Type = CmResourceTypeBusNumber;
148 PartialDescriptor->u.BusNumber.Start = 0;
149 PartialDescriptor->u.BusNumber.Length = 1;
150
151 PartialDescriptor = &PartialResourceList->PartialDescriptors[1];
152 PartialDescriptor->Type = CmResourceTypeDeviceSpecific;
154 PartialDescriptor->u.DeviceSpecificData.DataSize = Table->TableSize;
155
156 RtlCopyMemory(&PartialResourceList->PartialDescriptors[2],
157 Table, Table->TableSize);
158
162 0,
163 0,
164 0xFFFFFFFF,
165 "PCI Real-mode IRQ Routing Table",
166 PartialResourceList,
167 Size,
168 &TableKey);
169 }
170}
171
172
173VOID
175{
176 PCM_PARTIAL_RESOURCE_LIST PartialResourceList;
177 PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
178 PCI_REGISTRY_INFO BusData;
181 ULONG Size;
182 ULONG i;
183
184 /* Report the PCI BIOS */
185 if (FindPciBios(&BusData))
186 {
187 /* Set 'Configuration Data' value */
188 Size = FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, PartialDescriptors);
189 PartialResourceList = FrLdrHeapAlloc(Size, TAG_HW_RESOURCE_LIST);
190 if (PartialResourceList == NULL)
191 {
192 ERR("Failed to allocate resource descriptor\n");
193 return;
194 }
195
196 /* Initialize resource descriptor */
197 RtlZeroMemory(PartialResourceList, Size);
198
199 /* Create new bus key */
200 FldrCreateComponentKey(SystemKey,
203 0,
204 0,
205 0xFFFFFFFF,
206 "PCI BIOS",
207 PartialResourceList,
208 Size,
209 &BiosKey);
210
211 /* Increment bus number */
212 (*BusNumber)++;
213
215
216 /* Report PCI buses */
217 for (i = 0; i < (ULONG)BusData.NoBuses; i++)
218 {
219 /* Check if this is the first bus */
220 if (i == 0)
221 {
222 /* Set 'Configuration Data' value */
223 Size = FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, PartialDescriptors[1]) +
224 sizeof(BusData);
225 PartialResourceList = FrLdrHeapAlloc(Size, TAG_HW_RESOURCE_LIST);
226 if (!PartialResourceList)
227 {
228 ERR("Failed to allocate resource descriptor! Ignoring remaining PCI buses. (i = %lu, NoBuses = %lu)\n",
229 i, (ULONG)BusData.NoBuses);
230 return;
231 }
232
233 /* Initialize resource descriptor */
234 RtlZeroMemory(PartialResourceList, Size);
235 PartialResourceList->Version = 1;
236 PartialResourceList->Revision = 1;
237 PartialResourceList->Count = 1;
238
239 PartialDescriptor = &PartialResourceList->PartialDescriptors[0];
240 PartialDescriptor->Type = CmResourceTypeDeviceSpecific;
242 PartialDescriptor->u.DeviceSpecificData.DataSize = sizeof(BusData);
243
244 RtlCopyMemory(&PartialResourceList->PartialDescriptors[1],
245 &BusData, sizeof(BusData));
246 }
247 else
248 {
249 /* Set 'Configuration Data' value */
250 Size = FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, PartialDescriptors);
251 PartialResourceList = FrLdrHeapAlloc(Size, TAG_HW_RESOURCE_LIST);
252 if (!PartialResourceList)
253 {
254 ERR("Failed to allocate resource descriptor! Ignoring remaining PCI buses. (i = %lu, NoBuses = %lu)\n",
255 i, (ULONG)BusData.NoBuses);
256 return;
257 }
258
259 /* Initialize resource descriptor */
260 RtlZeroMemory(PartialResourceList, Size);
261 }
262
263 /* Create the bus key */
264 FldrCreateComponentKey(SystemKey,
267 0,
268 0,
269 0xFFFFFFFF,
270 "PCI",
271 PartialResourceList,
272 Size,
273 &BusKey);
274
275 /* Increment bus number */
276 (*BusNumber)++;
277 }
278 }
279}
280
281/* EOF */
unsigned char BOOLEAN
Definition: actypes.h:127
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
static PPCI_IRQ_ROUTING_TABLE GetPciIrqRoutingTable(VOID)
Definition: hwpci.c:30
static VOID DetectPciIrqRoutingTable(PCONFIGURATION_COMPONENT_DATA BusKey)
Definition: hwpci.c:117
VOID DetectPciBios(PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber)
Definition: hwpci.c:174
BOOLEAN PcFindPciBios(PPCI_REGISTRY_INFO BusData)
Definition: hwpci.c:80
FIND_PCI_BIOS FindPciBios
Definition: hwpci.c:26
BOOLEAN(* FIND_PCI_BIOS)(PPCI_REGISTRY_INFO BusData)
Definition: hardware.h:74
#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
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
ASMGENDATA Table[]
Definition: genincdata.c:61
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 INT386_SUCCESS(regs)
Definition: pcbios.h:181
int __cdecl Int386(int ivec, REGS *in, REGS *out)
#define CmResourceTypeDeviceSpecific
Definition: restypes.h:108
#define CmResourceTypeBusNumber
Definition: restypes.h:109
@ AdapterClass
Definition: arc.h:102
@ PeripheralClass
Definition: arc.h:104
@ MultiFunctionAdapter
Definition: arc.h:125
@ RealModeIrqRoutingTable
Definition: arc.h:152
struct _PCI_IRQ_ROUTING_TABLE * PPCI_IRQ_ROUTING_TABLE
#define TRACE(s)
Definition: solgame.cpp:4
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
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@382::@391 DeviceSpecificData
union _CM_PARTIAL_RESOURCE_DESCRIPTOR::@382 u
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@382::@390 BusNumber
CM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptors[1]
Definition: restypes.h:100
UCHAR MajorRevision
Definition: pci.h:107
UCHAR NoBuses
Definition: pci.h:109
UCHAR HardwareMechanism
Definition: pci.h:110
UCHAR MinorRevision
Definition: pci.h:108
#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_PTR
Definition: typedefs.h:65
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
#define TAG_HW_RESOURCE_LIST
Definition: uefidisk.c:15
Definition: pcbios.h:161
DWORDREGS d
Definition: pcbios.h:163
BYTEREGS b
Definition: pcbios.h:165
_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