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 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.
26 DBG_DEFAULT_CHANNEL(HWDETECT
);
29 PPCI_IRQ_ROUTING_TABLE
30 GetPciIrqRoutingTable(VOID
)
32 PPCI_IRQ_ROUTING_TABLE Table
;
37 Table
= (PPCI_IRQ_ROUTING_TABLE
)0xF0000;
38 while ((ULONG_PTR
)Table
< 0x100000)
40 if (Table
->Signature
== 'RIP$')
42 TRACE("Found signature\n");
46 for (i
= 0; i
< Table
->TableSize
; i
++)
51 if ((Sum
& 0xFF) != 0)
53 ERR("Invalid routing table\n");
57 TRACE("Valid checksum\n");
62 Table
= (PPCI_IRQ_ROUTING_TABLE
)((ULONG_PTR
)Table
+ 0x10);
70 FindPciBios(PPCI_REGISTRY_INFO BusData
)
75 RegsIn
.b
.ah
= 0xB1; /* Subfunction B1h */
76 RegsIn
.b
.al
= 0x01; /* PCI BIOS present */
78 Int386(0x1A, &RegsIn
, &RegsOut
);
80 if (INT386_SUCCESS(RegsOut
) &&
81 (RegsOut
.d
.edx
== 0x20494350) &&
84 TRACE("Found PCI bios\n");
86 TRACE("AL: %x\n", RegsOut
.b
.al
);
87 TRACE("BH: %x\n", RegsOut
.b
.bh
);
88 TRACE("BL: %x\n", RegsOut
.b
.bl
);
89 TRACE("CL: %x\n", RegsOut
.b
.cl
);
91 BusData
->NoBuses
= RegsOut
.b
.cl
+ 1;
92 BusData
->MajorRevision
= RegsOut
.b
.bh
;
93 BusData
->MinorRevision
= RegsOut
.b
.bl
;
94 BusData
->HardwareMechanism
= RegsOut
.b
.al
;
99 TRACE("No PCI bios found\n");
107 DetectPciIrqRoutingTable(PCONFIGURATION_COMPONENT_DATA BusKey
)
109 PCM_PARTIAL_RESOURCE_LIST PartialResourceList
;
110 PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor
;
111 PPCI_IRQ_ROUTING_TABLE Table
;
112 PCONFIGURATION_COMPONENT_DATA TableKey
;
115 Table
= GetPciIrqRoutingTable();
118 TRACE("Table size: %u\n", Table
->TableSize
);
120 /* Set 'Configuration Data' value */
121 Size
= FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST
, PartialDescriptors
) +
122 2 * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR
) + Table
->TableSize
;
123 PartialResourceList
= MmHeapAlloc(Size
);
124 if (PartialResourceList
== NULL
)
126 ERR("Failed to allocate resource descriptor\n");
130 /* Initialize resource descriptor */
131 memset(PartialResourceList
, 0, Size
);
132 PartialResourceList
->Version
= 1;
133 PartialResourceList
->Revision
= 1;
134 PartialResourceList
->Count
= 2;
136 PartialDescriptor
= &PartialResourceList
->PartialDescriptors
[0];
137 PartialDescriptor
->Type
= CmResourceTypeBusNumber
;
138 PartialDescriptor
->ShareDisposition
= CmResourceShareDeviceExclusive
;
139 PartialDescriptor
->u
.BusNumber
.Start
= 0;
140 PartialDescriptor
->u
.BusNumber
.Length
= 1;
142 PartialDescriptor
= &PartialResourceList
->PartialDescriptors
[1];
143 PartialDescriptor
->Type
= CmResourceTypeDeviceSpecific
;
144 PartialDescriptor
->ShareDisposition
= CmResourceShareUndetermined
;
145 PartialDescriptor
->u
.DeviceSpecificData
.DataSize
= Table
->TableSize
;
147 memcpy(&PartialResourceList
->PartialDescriptors
[2],
151 FldrCreateComponentKey(BusKey
,
153 RealModeIrqRoutingTable
,
157 "PCI Real-mode IRQ Routing Table",
166 DetectPciBios(PCONFIGURATION_COMPONENT_DATA SystemKey
, ULONG
*BusNumber
)
168 PCM_PARTIAL_RESOURCE_LIST PartialResourceList
;
169 PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor
;
170 PCI_REGISTRY_INFO BusData
;
171 PCONFIGURATION_COMPONENT_DATA BiosKey
;
173 PCONFIGURATION_COMPONENT_DATA BusKey
;
176 /* Report the PCI BIOS */
177 if (FindPciBios(&BusData
))
179 /* Set 'Configuration Data' value */
180 Size
= FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST
, PartialDescriptors
);
181 PartialResourceList
= MmHeapAlloc(Size
);
182 if (PartialResourceList
== NULL
)
184 ERR("Failed to allocate resource descriptor\n");
188 /* Initialize resource descriptor */
189 memset(PartialResourceList
, 0, Size
);
191 /* Create new bus key */
192 FldrCreateComponentKey(SystemKey
,
194 MultiFunctionAdapter
,
203 /* Increment bus number */
206 DetectPciIrqRoutingTable(BiosKey
);
208 /* Report PCI buses */
209 for (i
= 0; i
< (ULONG
)BusData
.NoBuses
; i
++)
211 /* Check if this is the first bus */
214 /* Set 'Configuration Data' value */
215 Size
= FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST
,
216 PartialDescriptors
) +
217 sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR
) +
218 sizeof(PCI_REGISTRY_INFO
);
219 PartialResourceList
= MmHeapAlloc(Size
);
220 if (!PartialResourceList
)
222 ERR("Failed to allocate resource descriptor\n");
226 /* Initialize resource descriptor */
227 memset(PartialResourceList
, 0, Size
);
228 PartialResourceList
->Version
= 1;
229 PartialResourceList
->Revision
= 1;
230 PartialResourceList
->Count
= 1;
231 PartialDescriptor
= &PartialResourceList
->PartialDescriptors
[0];
232 PartialDescriptor
->Type
= CmResourceTypeDeviceSpecific
;
233 PartialDescriptor
->ShareDisposition
= CmResourceShareUndetermined
;
234 PartialDescriptor
->u
.DeviceSpecificData
.DataSize
= sizeof(PCI_REGISTRY_INFO
);
235 memcpy(&PartialResourceList
->PartialDescriptors
[1],
237 sizeof(PCI_REGISTRY_INFO
));
241 /* Set 'Configuration Data' value */
242 Size
= FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST
,
244 PartialResourceList
= MmHeapAlloc(Size
);
245 if (!PartialResourceList
)
247 ERR("Failed to allocate resource descriptor\n");
251 /* Initialize resource descriptor */
252 memset(PartialResourceList
, 0, Size
);
255 /* Create the bus key */
256 FldrCreateComponentKey(SystemKey
,
258 MultiFunctionAdapter
,
267 /* Increment bus number */