4 * Copyright (C) 2004 Eric Kohl
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.
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.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 typedef struct _ROUTING_SLOT
40 } __attribute__((packed
)) ROUTING_SLOT
, *PROUTING_SLOT
;
42 typedef struct _PCI_IRQ_ROUTING_TABLE
50 ULONG CompatibleRouter
;
55 } __attribute__((packed
)) PCI_IRQ_ROUTING_TABLE
, *PPCI_IRQ_ROUTING_TABLE
;
57 typedef struct _PCI_REGISTRY_INFO
62 UCHAR HardwareMechanism
;
63 } PCI_REGISTRY_INFO
, *PPCI_REGISTRY_INFO
;
65 static PPCI_IRQ_ROUTING_TABLE
66 GetPciIrqRoutingTable(VOID
)
68 PPCI_IRQ_ROUTING_TABLE Table
;
73 Table
= (PPCI_IRQ_ROUTING_TABLE
)0xF0000;
74 while ((ULONG
)Table
< 0x100000)
76 if (Table
->Signature
== 0x52495024)
78 DbgPrint((DPRINT_HWDETECT
,
79 "Found signature\n"));
83 for (i
= 0; i
< Table
->Size
; i
++)
88 if ((Sum
& 0xFF) != 0)
90 DbgPrint((DPRINT_HWDETECT
,
91 "Invalid routing table\n"));
95 DbgPrint((DPRINT_HWDETECT
,
101 Table
= (PPCI_IRQ_ROUTING_TABLE
)((ULONG
)Table
+ 0x10);
109 FindPciBios(PPCI_REGISTRY_INFO BusData
)
114 RegsIn
.b
.ah
= 0xB1; /* Subfunction B1h */
115 RegsIn
.b
.al
= 0x01; /* PCI BIOS present */
117 Int386(0x1A, &RegsIn
, &RegsOut
);
119 if (INT386_SUCCESS(RegsOut
) && RegsOut
.d
.edx
== 0x20494350 && RegsOut
.b
.ah
== 0)
121 DbgPrint((DPRINT_HWDETECT
, "Found PCI bios\n"));
123 DbgPrint((DPRINT_HWDETECT
, "AL: %x\n", RegsOut
.b
.al
));
124 DbgPrint((DPRINT_HWDETECT
, "BH: %x\n", RegsOut
.b
.bh
));
125 DbgPrint((DPRINT_HWDETECT
, "BL: %x\n", RegsOut
.b
.bl
));
126 DbgPrint((DPRINT_HWDETECT
, "CL: %x\n", RegsOut
.b
.cl
));
128 BusData
->NoBuses
= RegsOut
.b
.cl
+ 1;
129 BusData
->MajorRevision
= RegsOut
.b
.bh
;
130 BusData
->MinorRevision
= RegsOut
.b
.bl
;
131 BusData
->HardwareMechanism
= RegsOut
.b
.cl
;
137 DbgPrint((DPRINT_HWDETECT
, "No PCI bios found\n"));
144 DetectPciIrqRoutingTable(PCONFIGURATION_COMPONENT_DATA BusKey
)
146 PCM_PARTIAL_RESOURCE_LIST PartialResourceList
;
147 PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor
;
148 PPCI_IRQ_ROUTING_TABLE Table
;
149 PCONFIGURATION_COMPONENT_DATA TableKey
;
152 Table
= GetPciIrqRoutingTable();
155 DbgPrint((DPRINT_HWDETECT
, "Table size: %u\n", Table
->Size
));
157 FldrCreateComponentKey(BusKey
,
158 L
"RealModeIrqRoutingTable",
161 RealModeIrqRoutingTable
,
164 /* Set 'Component Information' */
165 FldrSetComponentInformation(TableKey
,
170 /* Set 'Identifier' value */
171 FldrSetIdentifier(TableKey
, L
"PCI Real-mode IRQ Routing Table");
173 /* Set 'Configuration Data' value */
174 Size
= FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST
, PartialDescriptors
) +
175 2 * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR
) + Table
->Size
;
176 PartialResourceList
= MmAllocateMemory(Size
);
177 if (PartialResourceList
== NULL
)
179 DbgPrint((DPRINT_HWDETECT
,
180 "Failed to allocate resource descriptor\n"));
184 /* Initialize resource descriptor */
185 memset(PartialResourceList
, 0, Size
);
186 PartialResourceList
->Version
= 1;
187 PartialResourceList
->Revision
= 1;
188 PartialResourceList
->Count
= 2;
190 PartialDescriptor
= &PartialResourceList
->PartialDescriptors
[0];
191 PartialDescriptor
->Type
= CmResourceTypeBusNumber
;
192 PartialDescriptor
->ShareDisposition
= CmResourceShareDeviceExclusive
;
193 PartialDescriptor
->u
.BusNumber
.Start
= 0;
194 PartialDescriptor
->u
.BusNumber
.Length
= 1;
196 PartialDescriptor
= &PartialResourceList
->PartialDescriptors
[1];
197 PartialDescriptor
->Type
= CmResourceTypeDeviceSpecific
;
198 PartialDescriptor
->ShareDisposition
= CmResourceShareUndetermined
;
199 PartialDescriptor
->u
.DeviceSpecificData
.DataSize
= Table
->Size
;
201 memcpy(&PartialResourceList
->PartialDescriptors
[2],
204 /* Set 'Configuration Data' value */
205 FldrSetConfigurationData(TableKey
, PartialResourceList
, Size
);
206 MmFreeMemory(PartialResourceList
);
212 DetectPciBios(PCONFIGURATION_COMPONENT_DATA SystemKey
, ULONG
*BusNumber
)
214 PCM_PARTIAL_RESOURCE_LIST PartialResourceList
;
215 PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor
;
216 PCI_REGISTRY_INFO BusData
;
217 PCONFIGURATION_COMPONENT_DATA BiosKey
;
219 PCONFIGURATION_COMPONENT_DATA BusKey
;
221 WCHAR szPci
[] = L
"PCI";
223 /* Report the PCI BIOS */
224 if (FindPciBios(&BusData
))
226 /* Create new bus key */
227 FldrCreateComponentKey(SystemKey
,
228 L
"MultifunctionAdapter",
231 MultiFunctionAdapter
,
234 /* Set 'Component Information' */
235 FldrSetComponentInformation(BiosKey
,
240 /* Increment bus number */
243 /* Set 'Identifier' value */
244 FldrSetIdentifier(BiosKey
, L
"PCI BIOS");
246 /* Set 'Configuration Data' value */
247 Size
= FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST
,
249 PartialResourceList
= MmAllocateMemory(Size
);
250 if (PartialResourceList
== NULL
)
252 DbgPrint((DPRINT_HWDETECT
,
253 "Failed to allocate resource descriptor\n"));
257 /* Initialize resource descriptor */
258 memset(PartialResourceList
, 0, Size
);
260 /* Set 'Configuration Data' value */
261 FldrSetConfigurationData(BiosKey
, PartialResourceList
, Size
);
262 MmFreeMemory(PartialResourceList
);
264 DetectPciIrqRoutingTable(BiosKey
);
266 /* Report PCI buses */
267 for (i
= 0; i
< (ULONG
)BusData
.NoBuses
; i
++)
269 /* Create the bus key */
270 FldrCreateComponentKey(SystemKey
,
271 L
"MultifunctionAdapter",
274 MultiFunctionAdapter
,
277 /* Set 'Component Information' */
278 FldrSetComponentInformation(BusKey
,
283 /* Check if this is the first bus */
286 /* Set 'Configuration Data' value */
287 Size
= FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST
,
288 PartialDescriptors
) +
289 sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR
) +
290 sizeof(PCI_REGISTRY_INFO
);
291 PartialResourceList
= MmAllocateMemory(Size
);
292 if (!PartialResourceList
)
294 DbgPrint((DPRINT_HWDETECT
,
295 "Failed to allocate resource descriptor\n"));
299 /* Initialize resource descriptor */
300 memset(PartialResourceList
, 0, Size
);
301 PartialResourceList
->Version
= 1;
302 PartialResourceList
->Revision
= 1;
303 PartialResourceList
->Count
= 1;
304 PartialDescriptor
= &PartialResourceList
->PartialDescriptors
[0];
305 PartialDescriptor
->Type
= CmResourceTypeDeviceSpecific
;
306 PartialDescriptor
->ShareDisposition
= CmResourceShareUndetermined
;
307 PartialDescriptor
->u
.DeviceSpecificData
.DataSize
= sizeof(PCI_REGISTRY_INFO
);
308 memcpy(&PartialResourceList
->PartialDescriptors
[1],
310 sizeof(PCI_REGISTRY_INFO
));
312 /* Set 'Configuration Data' value */
313 FldrSetConfigurationData(BusKey
, PartialResourceList
, Size
);
314 MmFreeMemory(PartialResourceList
);
318 /* Set 'Configuration Data' value */
319 Size
= FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST
,
321 PartialResourceList
= MmAllocateMemory(Size
);
322 if (!PartialResourceList
)
324 DbgPrint((DPRINT_HWDETECT
,
325 "Failed to allocate resource descriptor\n"));
329 /* Initialize resource descriptor */
330 memset(PartialResourceList
, 0, Size
);
332 /* Set 'Configuration Data' value */
333 FldrSetConfigurationData(BusKey
, PartialResourceList
, Size
);
334 MmFreeMemory(PartialResourceList
);
337 /* Increment bus number */
340 /* Set 'Identifier' value */
341 FldrSetIdentifier(BusKey
, szPci
);