]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFrameworkModulePkg/Bus/Pci/PciBusDxe/PciHotPlugSupport.c
Correct all header files for doxygen format and correct the license issue for VgaClas...
[mirror_edk2.git] / IntelFrameworkModulePkg / Bus / Pci / PciBusDxe / PciHotPlugSupport.c
CommitLineData
3db51098 1/**@file\r
ead42efc 2\r
3db51098 3Copyright (c) 2006, Intel Corporation \r
4All rights reserved. This program and the accompanying materials \r
5are licensed and made available under the terms and conditions of the BSD License \r
6which accompanies this distribution. The full text of the license may be found at \r
7http://opensource.org/licenses/bsd-license.php \r
8 \r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
ead42efc 11\r
3db51098 12**/\r
ead42efc 13\r
ead42efc 14\r
15#include "Pcibus.h"\r
16#include "PciHotPlugSupport.h"\r
17\r
18EFI_PCI_HOT_PLUG_INIT_PROTOCOL *gPciHotPlugInit;\r
19EFI_HPC_LOCATION *gPciRootHpcPool;\r
20UINTN gPciRootHpcCount;\r
21ROOT_HPC_DATA *gPciRootHpcData;\r
22\r
23VOID\r
24EFIAPI\r
25PciHPCInitialized (\r
26 IN EFI_EVENT Event,\r
27 IN VOID *Context\r
28 )\r
29/*++\r
30\r
31Routine Description:\r
32\r
33Arguments:\r
34\r
35Returns:\r
36\r
37 None\r
38\r
39--*/\r
40// TODO: Event - add argument and description to function comment\r
41// TODO: Context - add argument and description to function comment\r
42{\r
43 ROOT_HPC_DATA *HpcData;\r
44\r
45 HpcData = (ROOT_HPC_DATA *) Context;\r
46 HpcData->Initialized = TRUE;\r
47\r
48}\r
49\r
50BOOLEAN\r
51EfiCompareDevicePath (\r
52 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath1,\r
53 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath2\r
54 )\r
55/*++\r
56\r
57Routine Description:\r
58\r
59Arguments:\r
60\r
61Returns:\r
62\r
63 None\r
64\r
65--*/\r
66// TODO: DevicePath1 - add argument and description to function comment\r
67// TODO: DevicePath2 - add argument and description to function comment\r
68{\r
69 UINTN Size1;\r
70 UINTN Size2;\r
71\r
72 Size1 = GetDevicePathSize (DevicePath1);\r
73 Size2 = GetDevicePathSize (DevicePath2);\r
74\r
75 if (Size1 != Size2) {\r
76 return FALSE;\r
77 }\r
78\r
79 if (CompareMem (DevicePath1, DevicePath2, Size1)) {\r
80 return FALSE;\r
81 }\r
82\r
83 return TRUE;\r
84}\r
85\r
86EFI_STATUS\r
87InitializeHotPlugSupport (\r
88 VOID\r
89 )\r
90/*++\r
91\r
92Routine Description:\r
93\r
94Arguments:\r
95\r
96Returns:\r
97\r
98 None\r
99\r
100--*/\r
101// TODO: EFI_UNSUPPORTED - add return value to function comment\r
102// TODO: EFI_OUT_OF_RESOURCES - add return value to function comment\r
103// TODO: EFI_SUCCESS - add return value to function comment\r
104{\r
105 EFI_STATUS Status;\r
106 EFI_HPC_LOCATION *HpcList;\r
107 UINTN HpcCount;\r
108\r
109 //\r
110 // Locate the PciHotPlugInit Protocol\r
111 // If it doesn't exist, that means there is no\r
112 // hot plug controller supported on the platform\r
113 // the PCI Bus driver is running on. HotPlug Support\r
114 // is an optional feature, so absence of the protocol\r
115 // won't incur the penalty\r
116 //\r
117 gPciHotPlugInit = NULL;\r
118 gPciRootHpcPool = NULL;\r
119 gPciRootHpcCount = 0;\r
120 gPciRootHpcData = NULL;\r
121\r
122 Status = gBS->LocateProtocol (\r
123 &gEfiPciHotPlugInitProtocolGuid,\r
124 NULL,\r
125 (VOID **) &gPciHotPlugInit\r
126 );\r
127\r
128 if (EFI_ERROR (Status)) {\r
129 return EFI_UNSUPPORTED;\r
130 }\r
131\r
132 Status = gPciHotPlugInit->GetRootHpcList (\r
133 gPciHotPlugInit,\r
134 &HpcCount,\r
135 &HpcList\r
136 );\r
137\r
138 if (!EFI_ERROR (Status)) {\r
139\r
140 gPciRootHpcPool = HpcList;\r
141 gPciRootHpcCount = HpcCount;\r
142 gPciRootHpcData = AllocateZeroPool (sizeof (ROOT_HPC_DATA) * gPciRootHpcCount);\r
143 if (gPciRootHpcData == NULL) {\r
144 return EFI_OUT_OF_RESOURCES;\r
145 }\r
146 }\r
147\r
148 return EFI_SUCCESS;\r
149}\r
150\r
151BOOLEAN\r
152IsRootPciHotPlugBus (\r
153 IN EFI_DEVICE_PATH_PROTOCOL *HpbDevicePath,\r
154 OUT UINTN *HpIndex\r
155 )\r
156/*++\r
157\r
158Routine Description:\r
159\r
160Arguments:\r
161\r
162 HpcDevicePath - A pointer to the EFI_DEVICE_PATH_PROTOCOL.\r
163 HpIndex - A pointer to the Index.\r
164\r
165Returns:\r
166\r
167 None\r
168\r
169--*/\r
170// TODO: HpbDevicePath - add argument and description to function comment\r
171{\r
172 UINTN Index;\r
173\r
174 for (Index = 0; Index < gPciRootHpcCount; Index++) {\r
175\r
176 if (EfiCompareDevicePath (gPciRootHpcPool[Index].HpbDevicePath, HpbDevicePath)) {\r
177\r
178 if (HpIndex != NULL) {\r
179 *HpIndex = Index;\r
180 }\r
181\r
182 return TRUE;\r
183 }\r
184 }\r
185\r
186 return FALSE;\r
187}\r
188\r
189BOOLEAN\r
190IsRootPciHotPlugController (\r
191 IN EFI_DEVICE_PATH_PROTOCOL *HpcDevicePath,\r
192 OUT UINTN *HpIndex\r
193 )\r
194/*++\r
195\r
196Routine Description:\r
197\r
198Arguments:\r
199\r
200 HpcDevicePath - A pointer to the EFI_DEVICE_PATH_PROTOCOL.\r
201 HpIndex - A pointer to the Index.\r
202\r
203Returns:\r
204\r
205 None\r
206\r
207--*/\r
208{\r
209 UINTN Index;\r
210\r
211 for (Index = 0; Index < gPciRootHpcCount; Index++) {\r
212\r
213 if (EfiCompareDevicePath (gPciRootHpcPool[Index].HpcDevicePath, HpcDevicePath)) {\r
214\r
215 if (HpIndex != NULL) {\r
216 *HpIndex = Index;\r
217 }\r
218\r
219 return TRUE;\r
220 }\r
221 }\r
222\r
223 return FALSE;\r
224}\r
225\r
226EFI_STATUS\r
227CreateEventForHpc (\r
228 IN UINTN HpIndex,\r
229 OUT EFI_EVENT *Event\r
230 )\r
231/*++\r
232\r
233Routine Description:\r
234\r
235Arguments:\r
236\r
237Returns:\r
238\r
239 None\r
240\r
241--*/\r
242// TODO: HpIndex - add argument and description to function comment\r
243// TODO: Event - add argument and description to function comment\r
244{\r
245 EFI_STATUS Status;\r
246\r
247 Status = gBS->CreateEvent (\r
248 EVT_NOTIFY_SIGNAL,\r
249 TPL_CALLBACK,\r
250 PciHPCInitialized,\r
251 gPciRootHpcData + HpIndex,\r
252 &((gPciRootHpcData + HpIndex)->Event)\r
253 );\r
254\r
255 if (!EFI_ERROR (Status)) {\r
256 *Event = (gPciRootHpcData + HpIndex)->Event;\r
257 }\r
258\r
259 return Status;\r
260}\r
261\r
262EFI_STATUS\r
263AllRootHPCInitialized (\r
264 IN UINTN TimeoutInMicroSeconds\r
265 )\r
266/*++\r
267\r
268Routine Description:\r
269\r
270Arguments:\r
271 TimeoutInMicroSeconds - microseconds to wait for all root hpc's initialization\r
272\r
273Returns:\r
274 EFI_SUCCESS - All root hpc's initialization is finished before the timeout\r
275 EFI_TIMEOUT - Time out\r
276\r
277--*/\r
278// TODO: TimeoutInMilliSeconds - add argument and description to function comment\r
279// TODO: EFI_SUCCESS - add return value to function comment\r
280// TODO: EFI_TIMEOUT - add return value to function comment\r
281{\r
282 UINT32 Delay;\r
283 UINTN Index;\r
284\r
285 Delay = (UINT32) ((TimeoutInMicroSeconds / 30) + 1);\r
286 do {\r
287\r
288 for (Index = 0; Index < gPciRootHpcCount; Index++) {\r
289\r
290 if (!gPciRootHpcData[Index].Initialized) {\r
291 break;\r
292 }\r
293 }\r
294\r
295 if (Index == gPciRootHpcCount) {\r
296 return EFI_SUCCESS;\r
297 }\r
298\r
299 //\r
300 // Stall for 30 us\r
301 //\r
302 gBS->Stall (30);\r
303\r
304 Delay--;\r
305\r
306 } while (Delay);\r
307\r
308 return EFI_TIMEOUT;\r
309}\r
310\r
311EFI_STATUS\r
312IsSHPC (\r
313 PCI_IO_DEVICE *PciIoDevice\r
314 )\r
315/*++\r
316\r
317Routine Description:\r
318\r
319Arguments:\r
320\r
321Returns:\r
322\r
323 None\r
324\r
325--*/\r
326// TODO: PciIoDevice - add argument and description to function comment\r
327// TODO: EFI_NOT_FOUND - add return value to function comment\r
328// TODO: EFI_SUCCESS - add return value to function comment\r
329// TODO: EFI_NOT_FOUND - add return value to function comment\r
330{\r
331\r
332 EFI_STATUS Status;\r
333 UINT8 Offset;\r
334\r
335 if (!PciIoDevice) {\r
336 return EFI_NOT_FOUND;\r
337 }\r
338\r
339 Offset = 0;\r
340 Status = LocateCapabilityRegBlock (\r
341 PciIoDevice,\r
342 EFI_PCI_CAPABILITY_ID_HOTPLUG,\r
343 &Offset,\r
344 NULL\r
345 );\r
346\r
347 //\r
348 // If the PPB has the hot plug controller build-in,\r
349 // then return TRUE;\r
350 //\r
351 if (!EFI_ERROR (Status)) {\r
352 return EFI_SUCCESS;\r
353 }\r
354\r
355 return EFI_NOT_FOUND;\r
356}\r
357\r
358EFI_STATUS\r
359GetResourcePaddingForHpb (\r
360 IN PCI_IO_DEVICE *PciIoDevice\r
361 )\r
362/*++\r
363\r
364Routine Description:\r
365\r
366Arguments:\r
367\r
368Returns:\r
369\r
370 None\r
371\r
372--*/\r
373// TODO: PciIoDevice - add argument and description to function comment\r
374// TODO: EFI_SUCCESS - add return value to function comment\r
375// TODO: EFI_NOT_FOUND - add return value to function comment\r
376{\r
377 EFI_STATUS Status;\r
378 EFI_HPC_STATE State;\r
379 UINT64 PciAddress;\r
380 EFI_HPC_PADDING_ATTRIBUTES Attributes;\r
381 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Descriptors;\r
382\r
383 Status = IsPciHotPlugBus (PciIoDevice);\r
384\r
385 if (!EFI_ERROR (Status)) {\r
386 PciAddress = EFI_PCI_ADDRESS (PciIoDevice->BusNumber, PciIoDevice->DeviceNumber, PciIoDevice->FunctionNumber, 0);\r
387 Status = gPciHotPlugInit->GetResourcePadding (\r
388 gPciHotPlugInit,\r
389 PciIoDevice->DevicePath,\r
390 PciAddress,\r
391 &State,\r
392 (VOID **) &Descriptors,\r
393 &Attributes\r
394 );\r
395\r
396 if (EFI_ERROR (Status)) {\r
397 return Status;\r
398 }\r
399\r
400 if ((State & EFI_HPC_STATE_ENABLED) && (State & EFI_HPC_STATE_INITIALIZED)) {\r
401 PciIoDevice->ResourcePaddingDescriptors = Descriptors;\r
402 PciIoDevice->PaddingAttributes = Attributes;\r
403 }\r
404\r
405 return EFI_SUCCESS;\r
406 }\r
407\r
408 return EFI_NOT_FOUND;\r
409}\r
410\r
411EFI_STATUS\r
412IsPciHotPlugBus (\r
413 PCI_IO_DEVICE *PciIoDevice\r
414 )\r
415/*++\r
416\r
417Routine Description:\r
418\r
419Arguments:\r
420\r
421Returns:\r
422\r
423 None\r
424\r
425--*/\r
426// TODO: PciIoDevice - add argument and description to function comment\r
427// TODO: EFI_SUCCESS - add return value to function comment\r
428// TODO: EFI_SUCCESS - add return value to function comment\r
429// TODO: EFI_NOT_FOUND - add return value to function comment\r
430{\r
431 BOOLEAN Result;\r
432 EFI_STATUS Status;\r
433\r
434 Status = IsSHPC (PciIoDevice);\r
435\r
436 //\r
437 // If the PPB has the hot plug controller build-in,\r
438 // then return TRUE;\r
439 //\r
440 if (!EFI_ERROR (Status)) {\r
441 return EFI_SUCCESS;\r
442 }\r
443\r
444 //\r
445 // Otherwise, see if it is a Root HPC\r
446 //\r
447 Result = IsRootPciHotPlugBus (PciIoDevice->DevicePath, NULL);\r
448\r
449 if (Result) {\r
450 return EFI_SUCCESS;\r
451 }\r
452\r
453 return EFI_NOT_FOUND;\r
454}\r