2 PCI Hot Plug support functions implementation for PCI Bus module..
4 Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 EFI_PCI_HOT_PLUG_INIT_PROTOCOL
*gPciHotPlugInit
= NULL
;
18 EFI_HPC_LOCATION
*gPciRootHpcPool
= NULL
;
19 UINTN gPciRootHpcCount
= 0;
20 ROOT_HPC_DATA
*gPciRootHpcData
= NULL
;
24 Event notification function to set Hot Plug controller status.
26 @param Event The event that invoke this function.
27 @param Context The calling context, pointer to ROOT_HPC_DATA.
37 ROOT_HPC_DATA
*HpcData
;
39 HpcData
= (ROOT_HPC_DATA
*) Context
;
40 HpcData
->Initialized
= TRUE
;
44 Compare two device pathes to check if they are exactly same.
46 @param DevicePath1 A pointer to the first device path data structure.
47 @param DevicePath2 A pointer to the second device path data structure.
49 @retval TRUE They are same.
50 @retval FALSE They are not same.
54 EfiCompareDevicePath (
55 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath1
,
56 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath2
62 Size1
= GetDevicePathSize (DevicePath1
);
63 Size2
= GetDevicePathSize (DevicePath2
);
69 if (CompareMem (DevicePath1
, DevicePath2
, Size1
) != 0) {
77 Check hot plug support and initialize root hot plug private data.
79 If Hot Plug is supported by the platform, call PCI Hot Plug Init protocol
80 to get PCI Hot Plug controller's information and constructor the root hot plug
81 private data structure.
83 @retval EFI_SUCCESS They are same.
84 @retval EFI_UNSUPPORTED No PCI Hot Plug controler on the platform.
85 @retval EFI_OUT_OF_RESOURCES No memory to constructor root hot plug private
90 InitializeHotPlugSupport (
95 EFI_HPC_LOCATION
*HpcList
;
99 // Locate the PciHotPlugInit Protocol
100 // If it doesn't exist, that means there is no
101 // hot plug controller supported on the platform
102 // the PCI Bus driver is running on. HotPlug Support
103 // is an optional feature, so absence of the protocol
104 // won't incur the penalty.
106 Status
= gBS
->LocateProtocol (
107 &gEfiPciHotPlugInitProtocolGuid
,
109 (VOID
**) &gPciHotPlugInit
112 if (EFI_ERROR (Status
)) {
113 return EFI_UNSUPPORTED
;
116 Status
= gPciHotPlugInit
->GetRootHpcList (
122 if (!EFI_ERROR (Status
)) {
124 gPciRootHpcPool
= HpcList
;
125 gPciRootHpcCount
= HpcCount
;
126 gPciRootHpcData
= AllocateZeroPool (sizeof (ROOT_HPC_DATA
) * gPciRootHpcCount
);
127 if (gPciRootHpcData
== NULL
) {
128 return EFI_OUT_OF_RESOURCES
;
136 Test whether device path is for root pci hot plug bus.
138 @param HpbDevicePath A pointer to device path data structure to be tested.
139 @param HpIndex If HpIndex is not NULL, return the index of root hot
140 plug in global array when TRUE is retuned.
142 @retval TRUE The device path is for root pci hot plug bus.
143 @retval FALSE The device path is not for root pci hot plug bus.
147 IsRootPciHotPlugBus (
148 IN EFI_DEVICE_PATH_PROTOCOL
*HpbDevicePath
,
149 OUT UINTN
*HpIndex OPTIONAL
154 for (Index
= 0; Index
< gPciRootHpcCount
; Index
++) {
156 if (EfiCompareDevicePath (gPciRootHpcPool
[Index
].HpbDevicePath
, HpbDevicePath
)) {
158 if (HpIndex
!= NULL
) {
170 Test whether device path is for root pci hot plug controller.
172 @param HpcDevicePath A pointer to device path data structure to be tested.
173 @param HpIndex If HpIndex is not NULL, return the index of root hot
174 plug in global array when TRUE is retuned.
176 @retval TRUE The device path is for root pci hot plug controller.
177 @retval FALSE The device path is not for root pci hot plug controller.
181 IsRootPciHotPlugController (
182 IN EFI_DEVICE_PATH_PROTOCOL
*HpcDevicePath
,
188 for (Index
= 0; Index
< gPciRootHpcCount
; Index
++) {
190 if (EfiCompareDevicePath (gPciRootHpcPool
[Index
].HpcDevicePath
, HpcDevicePath
)) {
192 if (HpIndex
!= NULL
) {
204 Creating event object for PCI Hot Plug controller.
206 @param HpIndex Index of hot plug device in global array.
207 @param Event The retuned event that invoke this function.
209 @return Status of create event invoken.
220 Status
= gBS
->CreateEvent (
224 gPciRootHpcData
+ HpIndex
,
225 &((gPciRootHpcData
+ HpIndex
)->Event
)
228 if (!EFI_ERROR (Status
)) {
229 *Event
= (gPciRootHpcData
+ HpIndex
)->Event
;
236 Wait for all root PCI Hot Plug controller finished initializing.
238 @param TimeoutInMicroSeconds Microseconds to wait for all root HPCs' initialization.
240 @retval EFI_SUCCESS All HPCs initialization finished.
241 @retval EFI_TIMEOUT Not ALL HPCs initialization finished in Microseconds.
245 AllRootHPCInitialized (
246 IN UINTN TimeoutInMicroSeconds
252 Delay
= (UINT32
) ((TimeoutInMicroSeconds
/ 30) + 1);
255 for (Index
= 0; Index
< gPciRootHpcCount
; Index
++) {
257 if (gPciRootHpcData
[Index
].Found
&& !gPciRootHpcData
[Index
].Initialized
) {
262 if (Index
== gPciRootHpcCount
) {
267 // Stall for 30 microseconds..
279 Check whether PCI-PCI bridge has PCI Hot Plug capability register block.
281 @param PciIoDevice A Pointer to the PCI-PCI bridge.
283 @retval TRUE PCI device is HPC.
284 @retval FALSE PCI device is not HPC.
289 IN PCI_IO_DEVICE
*PciIoDevice
296 if (PciIoDevice
== NULL
) {
301 Status
= LocateCapabilityRegBlock (
303 EFI_PCI_CAPABILITY_ID_HOTPLUG
,
309 // If the PCI-PCI bridge has the hot plug controller build-in,
312 if (!EFI_ERROR (Status
)) {
320 Get resource padding if the specified PCI bridge is a hot plug bus.
322 @param PciIoDevice PCI bridge instance.
326 GetResourcePaddingForHpb (
327 IN PCI_IO_DEVICE
*PciIoDevice
333 EFI_HPC_PADDING_ATTRIBUTES Attributes
;
334 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*Descriptors
;
336 if (IsPciHotPlugBus (PciIoDevice
)) {
338 // If PCI-PCI bridge device is PCI Hot Plug bus.
340 PciAddress
= EFI_PCI_ADDRESS (PciIoDevice
->BusNumber
, PciIoDevice
->DeviceNumber
, PciIoDevice
->FunctionNumber
, 0);
341 Status
= gPciHotPlugInit
->GetResourcePadding (
343 PciIoDevice
->DevicePath
,
346 (VOID
**) &Descriptors
,
350 if (EFI_ERROR (Status
)) {
354 if ((State
& EFI_HPC_STATE_ENABLED
) != 0 && (State
& EFI_HPC_STATE_INITIALIZED
) != 0) {
355 PciIoDevice
->ResourcePaddingDescriptors
= Descriptors
;
356 PciIoDevice
->PaddingAttributes
= Attributes
;
364 Test whether PCI device is hot plug bus.
366 @param PciIoDevice PCI device instance.
368 @retval TRUE PCI device is a hot plug bus.
369 @retval FALSE PCI device is not a hot plug bus.
374 PCI_IO_DEVICE
*PciIoDevice
377 if (IsSHPC (PciIoDevice
)) {
379 // If the PPB has the hot plug controller build-in,
386 // Otherwise, see if it is a Root HPC
388 if(IsRootPciHotPlugBus (PciIoDevice
->DevicePath
, NULL
)) {