]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFrameworkModulePkg/Bus/Pci/PciBusDxe/PciHotPlugSupport.c
Coding style modification.
[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
c05d0125 15#include "pcibus.h"\r
ead42efc 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
bcd70414 29/**\r
ead42efc 30\r
31Routine Description:\r
32\r
33Arguments:\r
34\r
35Returns:\r
36\r
37 None\r
38\r
bcd70414 39**/\r
ead42efc 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
bcd70414 55/**\r
ead42efc 56\r
57Routine Description:\r
58\r
59Arguments:\r
60\r
61Returns:\r
62\r
63 None\r
64\r
bcd70414 65**/\r
ead42efc 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
bcd70414 90/**\r
ead42efc 91\r
92Routine Description:\r
93\r
94Arguments:\r
95\r
96Returns:\r
97\r
98 None\r
99\r
bcd70414 100**/\r
ead42efc 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
bcd70414 156/**\r
ead42efc 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
bcd70414 169**/\r
ead42efc 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
bcd70414 194/**\r
ead42efc 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
bcd70414 207**/\r
ead42efc 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
bcd70414 231/**\r
ead42efc 232\r
233Routine Description:\r
234\r
235Arguments:\r
236\r
237Returns:\r
238\r
239 None\r
240\r
bcd70414 241**/\r
ead42efc 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
bcd70414 266/**\r
ead42efc 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
bcd70414 277**/\r
ead42efc 278{\r
279 UINT32 Delay;\r
280 UINTN Index;\r
281\r
282 Delay = (UINT32) ((TimeoutInMicroSeconds / 30) + 1);\r
283 do {\r
284\r
285 for (Index = 0; Index < gPciRootHpcCount; Index++) {\r
286\r
287 if (!gPciRootHpcData[Index].Initialized) {\r
288 break;\r
289 }\r
290 }\r
291\r
292 if (Index == gPciRootHpcCount) {\r
293 return EFI_SUCCESS;\r
294 }\r
295\r
296 //\r
297 // Stall for 30 us\r
298 //\r
299 gBS->Stall (30);\r
300\r
301 Delay--;\r
302\r
303 } while (Delay);\r
304\r
305 return EFI_TIMEOUT;\r
306}\r
307\r
308EFI_STATUS\r
309IsSHPC (\r
310 PCI_IO_DEVICE *PciIoDevice\r
311 )\r
bcd70414 312/**\r
ead42efc 313\r
314Routine Description:\r
315\r
316Arguments:\r
317\r
318Returns:\r
319\r
320 None\r
321\r
bcd70414 322**/\r
ead42efc 323// TODO: PciIoDevice - add argument and description to function comment\r
324// TODO: EFI_NOT_FOUND - add return value to function comment\r
325// TODO: EFI_SUCCESS - add return value to function comment\r
326// TODO: EFI_NOT_FOUND - add return value to function comment\r
327{\r
328\r
329 EFI_STATUS Status;\r
330 UINT8 Offset;\r
331\r
332 if (!PciIoDevice) {\r
333 return EFI_NOT_FOUND;\r
334 }\r
335\r
336 Offset = 0;\r
337 Status = LocateCapabilityRegBlock (\r
338 PciIoDevice,\r
339 EFI_PCI_CAPABILITY_ID_HOTPLUG,\r
340 &Offset,\r
341 NULL\r
342 );\r
343\r
344 //\r
345 // If the PPB has the hot plug controller build-in,\r
346 // then return TRUE;\r
347 //\r
348 if (!EFI_ERROR (Status)) {\r
349 return EFI_SUCCESS;\r
350 }\r
351\r
352 return EFI_NOT_FOUND;\r
353}\r
354\r
355EFI_STATUS\r
356GetResourcePaddingForHpb (\r
357 IN PCI_IO_DEVICE *PciIoDevice\r
358 )\r
bcd70414 359/**\r
ead42efc 360\r
361Routine Description:\r
362\r
363Arguments:\r
364\r
365Returns:\r
366\r
367 None\r
368\r
bcd70414 369**/\r
ead42efc 370// TODO: PciIoDevice - add argument and description to function comment\r
371// TODO: EFI_SUCCESS - add return value to function comment\r
372// TODO: EFI_NOT_FOUND - add return value to function comment\r
373{\r
374 EFI_STATUS Status;\r
375 EFI_HPC_STATE State;\r
376 UINT64 PciAddress;\r
377 EFI_HPC_PADDING_ATTRIBUTES Attributes;\r
378 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Descriptors;\r
379\r
380 Status = IsPciHotPlugBus (PciIoDevice);\r
381\r
382 if (!EFI_ERROR (Status)) {\r
383 PciAddress = EFI_PCI_ADDRESS (PciIoDevice->BusNumber, PciIoDevice->DeviceNumber, PciIoDevice->FunctionNumber, 0);\r
384 Status = gPciHotPlugInit->GetResourcePadding (\r
385 gPciHotPlugInit,\r
386 PciIoDevice->DevicePath,\r
387 PciAddress,\r
388 &State,\r
389 (VOID **) &Descriptors,\r
390 &Attributes\r
391 );\r
392\r
393 if (EFI_ERROR (Status)) {\r
394 return Status;\r
395 }\r
396\r
397 if ((State & EFI_HPC_STATE_ENABLED) && (State & EFI_HPC_STATE_INITIALIZED)) {\r
398 PciIoDevice->ResourcePaddingDescriptors = Descriptors;\r
399 PciIoDevice->PaddingAttributes = Attributes;\r
400 }\r
401\r
402 return EFI_SUCCESS;\r
403 }\r
404\r
405 return EFI_NOT_FOUND;\r
406}\r
407\r
408EFI_STATUS\r
409IsPciHotPlugBus (\r
410 PCI_IO_DEVICE *PciIoDevice\r
411 )\r
bcd70414 412/**\r
ead42efc 413\r
414Routine Description:\r
415\r
416Arguments:\r
417\r
418Returns:\r
419\r
420 None\r
421\r
bcd70414 422**/\r
ead42efc 423// TODO: PciIoDevice - add argument and description to function comment\r
424// TODO: EFI_SUCCESS - add return value to function comment\r
425// TODO: EFI_SUCCESS - add return value to function comment\r
426// TODO: EFI_NOT_FOUND - add return value to function comment\r
427{\r
428 BOOLEAN Result;\r
429 EFI_STATUS Status;\r
430\r
431 Status = IsSHPC (PciIoDevice);\r
432\r
433 //\r
434 // If the PPB has the hot plug controller build-in,\r
435 // then return TRUE;\r
436 //\r
437 if (!EFI_ERROR (Status)) {\r
438 return EFI_SUCCESS;\r
439 }\r
440\r
441 //\r
442 // Otherwise, see if it is a Root HPC\r
443 //\r
444 Result = IsRootPciHotPlugBus (PciIoDevice->DevicePath, NULL);\r
445\r
446 if (Result) {\r
447 return EFI_SUCCESS;\r
448 }\r
449\r
450 return EFI_NOT_FOUND;\r
451}\r