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
282 Delay
= (UINT32
) ((TimeoutInMicroSeconds
/ 30) + 1);
285 for (Index
= 0; Index
< gPciRootHpcCount
; Index
++) {
287 if (!gPciRootHpcData
[Index
].Initialized
) {
292 if (Index
== gPciRootHpcCount
) {
310 PCI_IO_DEVICE
*PciIoDevice
323 // TODO: PciIoDevice - add argument and description to function comment
324 // TODO: EFI_NOT_FOUND - add return value to function comment
325 // TODO: EFI_SUCCESS - add return value to function comment
326 // TODO: EFI_NOT_FOUND - add return value to function comment
333 return EFI_NOT_FOUND
;
337 Status
= LocateCapabilityRegBlock (
339 EFI_PCI_CAPABILITY_ID_HOTPLUG
,
345 // If the PPB has the hot plug controller build-in,
348 if (!EFI_ERROR (Status
)) {
352 return EFI_NOT_FOUND
;
356 GetResourcePaddingForHpb (
357 IN PCI_IO_DEVICE
*PciIoDevice
370 // TODO: PciIoDevice - add argument and description to function comment
371 // TODO: EFI_SUCCESS - add return value to function comment
372 // TODO: EFI_NOT_FOUND - add return value to function comment
377 EFI_HPC_PADDING_ATTRIBUTES Attributes
;
378 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*Descriptors
;
380 Status
= IsPciHotPlugBus (PciIoDevice
);
382 if (!EFI_ERROR (Status
)) {
383 PciAddress
= EFI_PCI_ADDRESS (PciIoDevice
->BusNumber
, PciIoDevice
->DeviceNumber
, PciIoDevice
->FunctionNumber
, 0);
384 Status
= gPciHotPlugInit
->GetResourcePadding (
386 PciIoDevice
->DevicePath
,
389 (VOID
**) &Descriptors
,
393 if (EFI_ERROR (Status
)) {
397 if ((State
& EFI_HPC_STATE_ENABLED
) && (State
& EFI_HPC_STATE_INITIALIZED
)) {
398 PciIoDevice
->ResourcePaddingDescriptors
= Descriptors
;
399 PciIoDevice
->PaddingAttributes
= Attributes
;
405 return EFI_NOT_FOUND
;
410 PCI_IO_DEVICE
*PciIoDevice
423 // TODO: PciIoDevice - add argument and description to function comment
424 // TODO: EFI_SUCCESS - add return value to function comment
425 // TODO: EFI_SUCCESS - add return value to function comment
426 // TODO: EFI_NOT_FOUND - add return value to function comment
431 Status
= IsSHPC (PciIoDevice
);
434 // If the PPB has the hot plug controller build-in,
437 if (!EFI_ERROR (Status
)) {
442 // Otherwise, see if it is a Root HPC
444 Result
= IsRootPciHotPlugBus (PciIoDevice
->DevicePath
, NULL
);
450 return EFI_NOT_FOUND
;