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.
25 #include "PciHotPlugSupport.h"
27 EFI_PCI_HOT_PLUG_INIT_PROTOCOL
*gPciHotPlugInit
;
28 EFI_HPC_LOCATION
*gPciRootHpcPool
;
29 UINTN gPciRootHpcCount
;
30 ROOT_HPC_DATA
*gPciRootHpcData
;
49 // TODO: Event - add argument and description to function comment
50 // TODO: Context - add argument and description to function comment
52 ROOT_HPC_DATA
*HpcData
;
54 HpcData
= (ROOT_HPC_DATA
*) Context
;
55 HpcData
->Initialized
= TRUE
;
60 EfiCompareDevicePath (
61 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath1
,
62 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath2
75 // TODO: DevicePath1 - add argument and description to function comment
76 // TODO: DevicePath2 - add argument and description to function comment
81 Size1
= GetDevicePathSize (DevicePath1
);
82 Size2
= GetDevicePathSize (DevicePath2
);
88 if (CompareMem (DevicePath1
, DevicePath2
, Size1
)) {
96 InitializeHotPlugSupport (
110 // TODO: EFI_UNSUPPORTED - add return value to function comment
111 // TODO: EFI_OUT_OF_RESOURCES - add return value to function comment
112 // TODO: EFI_SUCCESS - add return value to function comment
115 EFI_HPC_LOCATION
*HpcList
;
119 // Locate the PciHotPlugInit Protocol
120 // If it doesn't exist, that means there is no
121 // hot plug controller supported on the platform
122 // the PCI Bus driver is running on. HotPlug Support
123 // is an optional feature, so absence of the protocol
124 // won't incur the penalty
126 gPciHotPlugInit
= NULL
;
127 gPciRootHpcPool
= NULL
;
128 gPciRootHpcCount
= 0;
129 gPciRootHpcData
= NULL
;
131 Status
= gBS
->LocateProtocol (
132 &gEfiPciHotPlugInitProtocolGuid
,
134 (VOID
**) &gPciHotPlugInit
137 if (EFI_ERROR (Status
)) {
138 return EFI_UNSUPPORTED
;
141 Status
= gPciHotPlugInit
->GetRootHpcList (
147 if (!EFI_ERROR (Status
)) {
149 gPciRootHpcPool
= HpcList
;
150 gPciRootHpcCount
= HpcCount
;
151 gPciRootHpcData
= AllocateZeroPool (sizeof (ROOT_HPC_DATA
) * gPciRootHpcCount
);
152 if (gPciRootHpcData
== NULL
) {
153 return EFI_OUT_OF_RESOURCES
;
161 IsRootPciHotPlugBus (
162 IN EFI_DEVICE_PATH_PROTOCOL
*HpbDevicePath
,
171 HpcDevicePath - A pointer to the EFI_DEVICE_PATH_PROTOCOL.
172 HpIndex - A pointer to the Index.
179 // TODO: HpbDevicePath - add argument and description to function comment
183 for (Index
= 0; Index
< gPciRootHpcCount
; Index
++) {
185 if (EfiCompareDevicePath (gPciRootHpcPool
[Index
].HpbDevicePath
, HpbDevicePath
)) {
187 if (HpIndex
!= NULL
) {
199 IsRootPciHotPlugController (
200 IN EFI_DEVICE_PATH_PROTOCOL
*HpcDevicePath
,
209 HpcDevicePath - A pointer to the EFI_DEVICE_PATH_PROTOCOL.
210 HpIndex - A pointer to the Index.
220 for (Index
= 0; Index
< gPciRootHpcCount
; Index
++) {
222 if (EfiCompareDevicePath (gPciRootHpcPool
[Index
].HpcDevicePath
, HpcDevicePath
)) {
224 if (HpIndex
!= NULL
) {
251 // TODO: HpIndex - add argument and description to function comment
252 // TODO: Event - add argument and description to function comment
256 Status
= gBS
->CreateEvent (
257 EFI_EVENT_NOTIFY_SIGNAL
,
260 gPciRootHpcData
+ HpIndex
,
261 &((gPciRootHpcData
+ HpIndex
)->Event
)
264 if (!EFI_ERROR (Status
)) {
265 *Event
= (gPciRootHpcData
+ HpIndex
)->Event
;
272 AllRootHPCInitialized (
273 IN UINTN TimeoutInMilliSeconds
286 // TODO: TimeoutInMilliSeconds - add argument and description to function comment
287 // TODO: EFI_SUCCESS - add return value to function comment
288 // TODO: EFI_TIMEOUT - add return value to function comment
293 Delay
= (UINT32
) (((TimeoutInMilliSeconds
* STALL_1_MILLI_SECOND
) / 30) + 1);
296 for (Index
= 0; Index
< gPciRootHpcCount
; Index
++) {
298 if (!gPciRootHpcData
[Index
].Initialized
) {
303 if (Index
== gPciRootHpcCount
) {
321 PCI_IO_DEVICE
*PciIoDevice
334 // TODO: PciIoDevice - add argument and description to function comment
335 // TODO: EFI_NOT_FOUND - add return value to function comment
336 // TODO: EFI_SUCCESS - add return value to function comment
337 // TODO: EFI_NOT_FOUND - add return value to function comment
344 return EFI_NOT_FOUND
;
348 Status
= LocateCapabilityRegBlock (
350 EFI_PCI_CAPABILITY_ID_HOTPLUG
,
356 // If the PPB has the hot plug controller build-in,
359 if (!EFI_ERROR (Status
)) {
363 return EFI_NOT_FOUND
;
367 GetResourcePaddingForHpb (
368 IN PCI_IO_DEVICE
*PciIoDevice
381 // TODO: PciIoDevice - add argument and description to function comment
382 // TODO: EFI_SUCCESS - add return value to function comment
383 // TODO: EFI_NOT_FOUND - add return value to function comment
388 EFI_HPC_PADDING_ATTRIBUTES Attributes
;
389 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*Descriptors
;
391 Status
= IsPciHotPlugBus (PciIoDevice
);
393 if (!EFI_ERROR (Status
)) {
394 PciAddress
= EFI_PCI_ADDRESS (PciIoDevice
->BusNumber
, PciIoDevice
->DeviceNumber
, PciIoDevice
->FunctionNumber
, 0);
395 Status
= gPciHotPlugInit
->GetResourcePadding (
397 PciIoDevice
->DevicePath
,
400 (VOID
**) &Descriptors
,
404 if (EFI_ERROR (Status
)) {
408 if ((State
& EFI_HPC_STATE_ENABLED
) && (State
& EFI_HPC_STATE_INITIALIZED
)) {
409 PciIoDevice
->ResourcePaddingDescriptors
= Descriptors
;
410 PciIoDevice
->PaddingAttributes
= Attributes
;
416 return EFI_NOT_FOUND
;
421 PCI_IO_DEVICE
*PciIoDevice
434 // TODO: PciIoDevice - add argument and description to function comment
435 // TODO: EFI_SUCCESS - add return value to function comment
436 // TODO: EFI_SUCCESS - add return value to function comment
437 // TODO: EFI_NOT_FOUND - add return value to function comment
442 Status
= IsSHPC (PciIoDevice
);
445 // If the PPB has the hot plug controller build-in,
448 if (!EFI_ERROR (Status
)) {
453 // Otherwise, see if it is a Root HPC
455 Result
= IsRootPciHotPlugBus (PciIoDevice
->DevicePath
, NULL
);
461 return EFI_NOT_FOUND
;