3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include "PciHotPlugSupport.h"
18 EFI_PCI_HOT_PLUG_INIT_PROTOCOL
*gPciHotPlugInit
;
19 EFI_HPC_LOCATION
*gPciRootHpcPool
;
20 UINTN gPciRootHpcCount
;
21 ROOT_HPC_DATA
*gPciRootHpcData
;
40 // TODO: Event - add argument and description to function comment
41 // TODO: Context - add argument and description to function comment
43 ROOT_HPC_DATA
*HpcData
;
45 HpcData
= (ROOT_HPC_DATA
*) Context
;
46 HpcData
->Initialized
= TRUE
;
51 EfiCompareDevicePath (
52 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath1
,
53 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath2
66 // TODO: DevicePath1 - add argument and description to function comment
67 // TODO: DevicePath2 - add argument and description to function comment
72 Size1
= GetDevicePathSize (DevicePath1
);
73 Size2
= GetDevicePathSize (DevicePath2
);
79 if (CompareMem (DevicePath1
, DevicePath2
, Size1
)) {
87 InitializeHotPlugSupport (
101 // TODO: EFI_UNSUPPORTED - add return value to function comment
102 // TODO: EFI_OUT_OF_RESOURCES - add return value to function comment
103 // TODO: EFI_SUCCESS - add return value to function comment
106 EFI_HPC_LOCATION
*HpcList
;
110 // Locate the PciHotPlugInit Protocol
111 // If it doesn't exist, that means there is no
112 // hot plug controller supported on the platform
113 // the PCI Bus driver is running on. HotPlug Support
114 // is an optional feature, so absence of the protocol
115 // won't incur the penalty
117 gPciHotPlugInit
= NULL
;
118 gPciRootHpcPool
= NULL
;
119 gPciRootHpcCount
= 0;
120 gPciRootHpcData
= NULL
;
122 Status
= gBS
->LocateProtocol (
123 &gEfiPciHotPlugInitProtocolGuid
,
125 (VOID
**) &gPciHotPlugInit
128 if (EFI_ERROR (Status
)) {
129 return EFI_UNSUPPORTED
;
132 Status
= gPciHotPlugInit
->GetRootHpcList (
138 if (!EFI_ERROR (Status
)) {
140 gPciRootHpcPool
= HpcList
;
141 gPciRootHpcCount
= HpcCount
;
142 gPciRootHpcData
= AllocateZeroPool (sizeof (ROOT_HPC_DATA
) * gPciRootHpcCount
);
143 if (gPciRootHpcData
== NULL
) {
144 return EFI_OUT_OF_RESOURCES
;
152 IsRootPciHotPlugBus (
153 IN EFI_DEVICE_PATH_PROTOCOL
*HpbDevicePath
,
162 HpcDevicePath - A pointer to the EFI_DEVICE_PATH_PROTOCOL.
163 HpIndex - A pointer to the Index.
170 // TODO: HpbDevicePath - add argument and description to function comment
174 for (Index
= 0; Index
< gPciRootHpcCount
; Index
++) {
176 if (EfiCompareDevicePath (gPciRootHpcPool
[Index
].HpbDevicePath
, HpbDevicePath
)) {
178 if (HpIndex
!= NULL
) {
190 IsRootPciHotPlugController (
191 IN EFI_DEVICE_PATH_PROTOCOL
*HpcDevicePath
,
200 HpcDevicePath - A pointer to the EFI_DEVICE_PATH_PROTOCOL.
201 HpIndex - A pointer to the Index.
211 for (Index
= 0; Index
< gPciRootHpcCount
; Index
++) {
213 if (EfiCompareDevicePath (gPciRootHpcPool
[Index
].HpcDevicePath
, HpcDevicePath
)) {
215 if (HpIndex
!= NULL
) {
242 // TODO: HpIndex - add argument and description to function comment
243 // TODO: Event - add argument and description to function comment
247 Status
= gBS
->CreateEvent (
251 gPciRootHpcData
+ HpIndex
,
252 &((gPciRootHpcData
+ HpIndex
)->Event
)
255 if (!EFI_ERROR (Status
)) {
256 *Event
= (gPciRootHpcData
+ HpIndex
)->Event
;
263 AllRootHPCInitialized (
264 IN UINTN TimeoutInMicroSeconds
271 TimeoutInMicroSeconds - microseconds to wait for all root hpc's initialization
274 EFI_SUCCESS - All root hpc's initialization is finished before the timeout
275 EFI_TIMEOUT - Time out
278 // TODO: TimeoutInMilliSeconds - add argument and description to function comment
279 // TODO: EFI_SUCCESS - add return value to function comment
280 // TODO: EFI_TIMEOUT - add return value to function comment
285 Delay
= (UINT32
) ((TimeoutInMicroSeconds
/ 30) + 1);
288 for (Index
= 0; Index
< gPciRootHpcCount
; Index
++) {
290 if (!gPciRootHpcData
[Index
].Initialized
) {
295 if (Index
== gPciRootHpcCount
) {
313 PCI_IO_DEVICE
*PciIoDevice
326 // TODO: PciIoDevice - add argument and description to function comment
327 // TODO: EFI_NOT_FOUND - add return value to function comment
328 // TODO: EFI_SUCCESS - add return value to function comment
329 // TODO: EFI_NOT_FOUND - add return value to function comment
336 return EFI_NOT_FOUND
;
340 Status
= LocateCapabilityRegBlock (
342 EFI_PCI_CAPABILITY_ID_HOTPLUG
,
348 // If the PPB has the hot plug controller build-in,
351 if (!EFI_ERROR (Status
)) {
355 return EFI_NOT_FOUND
;
359 GetResourcePaddingForHpb (
360 IN PCI_IO_DEVICE
*PciIoDevice
373 // TODO: PciIoDevice - add argument and description to function comment
374 // TODO: EFI_SUCCESS - add return value to function comment
375 // TODO: EFI_NOT_FOUND - add return value to function comment
380 EFI_HPC_PADDING_ATTRIBUTES Attributes
;
381 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*Descriptors
;
383 Status
= IsPciHotPlugBus (PciIoDevice
);
385 if (!EFI_ERROR (Status
)) {
386 PciAddress
= EFI_PCI_ADDRESS (PciIoDevice
->BusNumber
, PciIoDevice
->DeviceNumber
, PciIoDevice
->FunctionNumber
, 0);
387 Status
= gPciHotPlugInit
->GetResourcePadding (
389 PciIoDevice
->DevicePath
,
392 (VOID
**) &Descriptors
,
396 if (EFI_ERROR (Status
)) {
400 if ((State
& EFI_HPC_STATE_ENABLED
) && (State
& EFI_HPC_STATE_INITIALIZED
)) {
401 PciIoDevice
->ResourcePaddingDescriptors
= Descriptors
;
402 PciIoDevice
->PaddingAttributes
= Attributes
;
408 return EFI_NOT_FOUND
;
413 PCI_IO_DEVICE
*PciIoDevice
426 // TODO: PciIoDevice - add argument and description to function comment
427 // TODO: EFI_SUCCESS - add return value to function comment
428 // TODO: EFI_SUCCESS - add return value to function comment
429 // TODO: EFI_NOT_FOUND - add return value to function comment
434 Status
= IsSHPC (PciIoDevice
);
437 // If the PPB has the hot plug controller build-in,
440 if (!EFI_ERROR (Status
)) {
445 // Otherwise, see if it is a Root HPC
447 Result
= IsRootPciHotPlugBus (PciIoDevice
->DevicePath
, NULL
);
453 return EFI_NOT_FOUND
;