2 This driver implements EFI_PCI_HOT_PLUG_INIT_PROTOCOL, providing the PCI bus
3 driver with resource padding information, for PCIe hotplug purposes.
5 Copyright (C) 2016, Red Hat, Inc.
7 This program and the accompanying materials are licensed and made available
8 under the terms and conditions of the BSD License which accompanies this
9 distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
13 WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include <IndustryStandard/Acpi10.h>
18 #include <Library/DebugLib.h>
19 #include <Library/DevicePathLib.h>
20 #include <Library/MemoryAllocationLib.h>
21 #include <Library/UefiBootServicesTableLib.h>
23 #include <Protocol/PciHotPlugInit.h>
24 #include <Protocol/PciRootBridgeIo.h>
27 // The protocol interface this driver produces.
29 // Refer to 12.6 "PCI Hot Plug PCI Initialization Protocol" in the Platform
30 // Init 1.4a Spec, Volume 5.
32 STATIC EFI_PCI_HOT_PLUG_INIT_PROTOCOL mPciHotPlugInit
;
36 // Resource padding template for the GetResourcePadding() protocol member
39 // Refer to Table 8 "ACPI 2.0 & 3.0 QWORD Address Space Descriptor Usage" in
40 // the Platform Init 1.4a Spec, Volume 5.
42 // This structure is interpreted by the ApplyResourcePadding() function in the
43 // edk2 PCI Bus UEFI_DRIVER.
47 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR MmioPadding
;
48 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR IoPadding
;
49 EFI_ACPI_END_TAG_DESCRIPTOR EndDesc
;
53 STATIC CONST RESOURCE_PADDING mPadding
= {
58 ACPI_ADDRESS_SPACE_DESCRIPTOR
, // Desc
60 sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
) -
62 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
,
66 ACPI_ADDRESS_SPACE_TYPE_MEM
, // ResType
71 64, // AddrSpaceGranularity:
72 // reserve 64-bit aperture
75 SIZE_2MB
- 1, // AddrRangeMax:
77 0, // AddrTranslationOffset:
87 ACPI_ADDRESS_SPACE_DESCRIPTOR
, // Desc
89 sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
) -
91 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
,
95 ACPI_ADDRESS_SPACE_TYPE_IO
,// ResType
100 0, // AddrSpaceGranularity:
104 512 - 1, // AddrRangeMax:
105 // align at 512 IO ports
106 0, // AddrTranslationOffset:
116 ACPI_END_TAG_DESCRIPTOR
, // Desc
117 0 // Checksum: to be ignored
123 Returns a list of root Hot Plug Controllers (HPCs) that require
124 initialization during the boot process.
126 This procedure returns a list of root HPCs. The PCI bus driver must
127 initialize these controllers during the boot process. The PCI bus driver may
128 or may not be able to detect these HPCs. If the platform includes a
129 PCI-to-CardBus bridge, it can be included in this list if it requires
130 initialization. The HpcList must be self consistent. An HPC cannot control
131 any of its parent buses. Only one HPC can control a PCI bus. Because this
132 list includes only root HPCs, no HPC in the list can be a child of another
133 HPC. This policy must be enforced by the EFI_PCI_HOT_PLUG_INIT_PROTOCOL.
134 The PCI bus driver may not check for such invalid conditions. The callee
135 allocates the buffer HpcList
137 @param[in] This Pointer to the EFI_PCI_HOT_PLUG_INIT_PROTOCOL
139 @param[out] HpcCount The number of root HPCs that were returned.
140 @param[out] HpcList The list of root HPCs. HpcCount defines the number of
141 elements in this list.
143 @retval EFI_SUCCESS HpcList was returned.
144 @retval EFI_OUT_OF_RESOURCES HpcList was not returned due to insufficient
146 @retval EFI_INVALID_PARAMETER HpcCount is NULL or HpcList is NULL.
152 IN EFI_PCI_HOT_PLUG_INIT_PROTOCOL
*This
,
154 OUT EFI_HPC_LOCATION
**HpcList
157 if (HpcCount
== NULL
|| HpcList
== NULL
) {
158 return EFI_INVALID_PARAMETER
;
162 // There are no top-level (i.e., un-enumerable) hot-plug controllers in QEMU
163 // that would require special initialization.
172 Initializes one root Hot Plug Controller (HPC). This process may causes
173 initialization of its subordinate buses.
175 This function initializes the specified HPC. At the end of initialization,
176 the hot-plug slots or sockets (controlled by this HPC) are powered and are
177 connected to the bus. All the necessary registers in the HPC are set up. For
178 a Standard (PCI) Hot Plug Controller (SHPC), the registers that must be set
179 up are defined in the PCI Standard Hot Plug Controller and Subsystem
182 @param[in] This Pointer to the EFI_PCI_HOT_PLUG_INIT_PROTOCOL
184 @param[in] HpcDevicePath The device path to the HPC that is being
186 @param[in] HpcPciAddress The address of the HPC function on the PCI bus.
187 @param[in] Event The event that should be signaled when the HPC
188 initialization is complete. Set to NULL if the
189 caller wants to wait until the entire
190 initialization process is complete.
191 @param[out] HpcState The state of the HPC hardware. The state is
192 EFI_HPC_STATE_INITIALIZED or
193 EFI_HPC_STATE_ENABLED.
195 @retval EFI_SUCCESS If Event is NULL, the specific HPC was
196 successfully initialized. If Event is not
197 NULL, Event will be signaled at a later time
198 when initialization is complete.
199 @retval EFI_UNSUPPORTED This instance of
200 EFI_PCI_HOT_PLUG_INIT_PROTOCOL does not
201 support the specified HPC.
202 @retval EFI_OUT_OF_RESOURCES Initialization failed due to insufficient
204 @retval EFI_INVALID_PARAMETER HpcState is NULL.
210 IN EFI_PCI_HOT_PLUG_INIT_PROTOCOL
*This
,
211 IN EFI_DEVICE_PATH_PROTOCOL
*HpcDevicePath
,
212 IN UINT64 HpcPciAddress
,
213 IN EFI_EVENT Event
, OPTIONAL
214 OUT EFI_HPC_STATE
*HpcState
218 // This function should never be called, due to the information returned by
223 if (HpcState
== NULL
) {
224 return EFI_INVALID_PARAMETER
;
226 return EFI_UNSUPPORTED
;
231 Returns the resource padding that is required by the PCI bus that is
232 controlled by the specified Hot Plug Controller (HPC).
234 This function returns the resource padding that is required by the PCI bus
235 that is controlled by the specified HPC. This member function is called for
236 all the root HPCs and nonroot HPCs that are detected by the PCI bus
237 enumerator. This function will be called before PCI resource allocation is
238 completed. This function must be called after all the root HPCs, with the
239 possible exception of a PCI-to-CardBus bridge, have completed
242 @param[in] This Pointer to the EFI_PCI_HOT_PLUG_INIT_PROTOCOL
244 @param[in] HpcDevicePath The device path to the HPC.
245 @param[in] HpcPciAddress The address of the HPC function on the PCI bus.
246 @param[in] HpcState The state of the HPC hardware.
247 @param[out] Padding The amount of resource padding that is required
248 by the PCI bus under the control of the specified
250 @param[out] Attributes Describes how padding is accounted for. The
251 padding is returned in the form of ACPI 2.0
252 resource descriptors.
254 @retval EFI_SUCCESS The resource padding was successfully
256 @retval EFI_UNSUPPORTED This instance of the
257 EFI_PCI_HOT_PLUG_INIT_PROTOCOL does not
258 support the specified HPC.
259 @retval EFI_NOT_READY This function was called before HPC
260 initialization is complete.
261 @retval EFI_INVALID_PARAMETER HpcState or Padding or Attributes is NULL.
262 @retval EFI_OUT_OF_RESOURCES ACPI 2.0 resource descriptors for Padding
263 cannot be allocated due to insufficient
270 IN EFI_PCI_HOT_PLUG_INIT_PROTOCOL
*This
,
271 IN EFI_DEVICE_PATH_PROTOCOL
*HpcDevicePath
,
272 IN UINT64 HpcPciAddress
,
273 OUT EFI_HPC_STATE
*HpcState
,
275 OUT EFI_HPC_PADDING_ATTRIBUTES
*Attributes
279 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_PCI_ADDRESS
*Address
;
280 CHAR16
*DevicePathString
;
282 Address
= (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_PCI_ADDRESS
*)&HpcPciAddress
;
283 DevicePathString
= ConvertDevicePathToText (HpcDevicePath
, FALSE
, FALSE
);
285 DEBUG ((EFI_D_VERBOSE
, "%a: Address=%02x:%02x.%x DevicePath=%s\n",
286 __FUNCTION__
, Address
->Bus
, Address
->Device
, Address
->Function
,
287 (DevicePathString
== NULL
) ? L
"<unavailable>" : DevicePathString
));
289 if (DevicePathString
!= NULL
) {
290 FreePool (DevicePathString
);
294 if (HpcState
== NULL
|| Padding
== NULL
|| Attributes
== NULL
) {
295 return EFI_INVALID_PARAMETER
;
298 *Padding
= AllocateCopyPool (sizeof mPadding
, &mPadding
);
299 if (*Padding
== NULL
) {
300 return EFI_OUT_OF_RESOURCES
;
304 // Resource padding is required.
306 *HpcState
= EFI_HPC_STATE_INITIALIZED
| EFI_HPC_STATE_ENABLED
;
309 // The padding should be applied at PCI bus level, and considered by upstream
310 // bridges, recursively.
312 *Attributes
= EfiPaddingPciBus
;
318 Entry point for this driver.
320 @param[in] ImageHandle Image handle of this driver.
321 @param[in] SystemTable Pointer to SystemTable.
323 @retval EFI_SUCESS Driver has loaded successfully.
324 @return Error codes from lower level functions.
330 IN EFI_HANDLE ImageHandle
,
331 IN EFI_SYSTEM_TABLE
*SystemTable
336 mPciHotPlugInit
.GetRootHpcList
= GetRootHpcList
;
337 mPciHotPlugInit
.InitializeRootHpc
= InitializeRootHpc
;
338 mPciHotPlugInit
.GetResourcePadding
= GetResourcePadding
;
339 Status
= gBS
->InstallMultipleProtocolInterfaces (&ImageHandle
,
340 &gEfiPciHotPlugInitProtocolGuid
, &mPciHotPlugInit
, NULL
);