1 /** @file
2   This file declares EFI PCI Hot Plug Init Protocol.
3 
4   This protocol provides the necessary functionality to initialize the Hot Plug
5   Controllers (HPCs) and the buses that they control. This protocol also provides
6   information regarding resource padding.
7 
8   @par Note:
9     This protocol is required only on platforms that support one or more PCI Hot
10     Plug* slots or CardBus sockets.
11 
12   The EFI_PCI_HOT_PLUG_INIT_PROTOCOL provides a mechanism for the PCI bus enumerator
13   to properly initialize the HPCs and CardBus sockets that require initialization.
14   The HPC initialization takes place before the PCI enumeration process is complete.
15   There cannot be more than one instance of this protocol in a system. This protocol
16   is installed on its own separate handle.
17 
18   Because the system may include multiple HPCs, one instance of this protocol
19   should represent all of them. The protocol functions use the device path of
20   the HPC to identify the HPC. When the PCI bus enumerator finds a root HPC, it
21   will call EFI_PCI_HOT_PLUG_INIT_PROTOCOL.InitializeRootHpc(). If InitializeRootHpc()
22   is unable to initialize a root HPC, the PCI enumerator will ignore that root HPC
23   and continue the enumeration process. If the HPC is not initialized, the devices
24   that it controls may not be initialized, and no resource padding will be provided.
25 
26   From the standpoint of the PCI bus enumerator, HPCs are divided into the following
27   two classes:
28 
29     - Root HPC:
30         These HPCs must be initialized by calling InitializeRootHpc() during the
31         enumeration process. These HPCs will also require resource padding. The
32         platform code must have a priori knowledge of these devices and must know
33         how to initialize them. There may not be any way to access their PCI
34         configuration space before the PCI enumerator programs all the upstream
35         bridges and thus enables the path to these devices. The PCI bus enumerator
36         is responsible for determining the PCI bus address of the HPC before it
37         calls InitializeRootHpc().
38     - Nonroot HPC:
39         These HPCs will not need explicit initialization during enumeration process.
40         These HPCs will require resource padding. The platform code does not have
41         to have a priori knowledge of these devices.
42 
43   Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
44   SPDX-License-Identifier: BSD-2-Clause-Patent
45 
46   @par Revision Reference:
47   This Protocol is defined in UEFI Platform Initialization Specification 1.2
48   Volume 5: Standards
49 
50 **/
51 
52 #ifndef _EFI_PCI_HOT_PLUG_INIT_H_
53 #define _EFI_PCI_HOT_PLUG_INIT_H_
54 
55 ///
56 /// Global ID for the EFI_PCI_HOT_PLUG_INIT_PROTOCOL
57 ///
58 #define EFI_PCI_HOT_PLUG_INIT_PROTOCOL_GUID \
59   { \
60     0xaa0e8bc1, 0xdabc, 0x46b0, {0xa8, 0x44, 0x37, 0xb8, 0x16, 0x9b, 0x2b, 0xea } \
61   }
62 
63 ///
64 /// Forward declaration for EFI_PCI_HOT_PLUG_INIT_PROTOCOL
65 ///
66 typedef struct _EFI_PCI_HOT_PLUG_INIT_PROTOCOL EFI_PCI_HOT_PLUG_INIT_PROTOCOL;
67 
68 ///
69 /// Describes the current state of an HPC
70 ///
71 typedef UINT16 EFI_HPC_STATE;
72 
73 ///
74 /// The HPC initialization function was called and the HPC completed
75 /// initialization, but it was not enabled for some reason. The HPC may be
76 /// disabled in hardware, or it may be disabled due to user preferences,
77 /// hardware failure, or other reasons. No resource padding is required.
78 ///
79 #define  EFI_HPC_STATE_INITIALIZED    0x01
80 
81 ///
82 /// The HPC initialization function was called, the HPC completed
83 /// initialization, and it was enabled. Resource padding is required.
84 ///
85 #define  EFI_HPC_STATE_ENABLED        0x02
86 
87 ///
88 /// Location definition for PCI Hot Plug Controller
89 ///
90 typedef struct{
91   ///
92   ///
93   /// The device path to the root HPC. An HPC cannot control its parent buses.
94   /// The PCI bus driver requires this information so that it can pass the
95   /// correct HpcPciAddress to the InitializeRootHpc() and GetResourcePadding()
96   /// functions.
97   ///
98   EFI_DEVICE_PATH_PROTOCOL  *HpcDevicePath;
99   ///
100   /// The device path to the Hot Plug Bus (HPB) that is controlled by the root
101   /// HPC. The PCI bus driver uses this information to check if a particular PCI
102   /// bus has hot-plug slots.  The device path of a PCI bus is the same as the
103   /// device path of its parent. For Standard(PCI) Hot Plug Controllers (SHPCs)
104   /// and PCI Express*, HpbDevicePath is the same as HpcDevicePath.
105   ///
106   EFI_DEVICE_PATH_PROTOCOL  *HpbDevicePath;
107 } EFI_HPC_LOCATION;
108 
109 ///
110 /// Describes how resource padding should be applied
111 ///
112 typedef enum {
113   ///
114   /// Apply the padding at a PCI bus level. In other words, the resources
115   /// that are allocated to the bus containing hot-plug slots are padded by
116   /// the specified amount. If the hot-plug bus is behind a PCI-to-PCI
117   /// bridge, the PCI-to-PCI bridge apertures will indicate the padding
118   ///
119   EfiPaddingPciBus,
120   ///
121   /// Apply the padding at a PCI root bridge level. If a PCI root bridge
122   /// includes more than one hot-plug bus, the resource padding requests
123   /// for these buses are added together and the resources that are
124   /// allocated to the root bridge are padded by the specified amount. This
125   /// strategy may reduce the total amount of padding, but requires
126   /// reprogramming of PCI-to-PCI bridges in a hot-add event. If the hotplug
127   /// bus is behind a PCI-to-PCI bridge, the PCI-to-PCI bridge
128   /// apertures do not indicate the padding for that bus.
129   ///
130   EfiPaddingPciRootBridge
131 } EFI_HPC_PADDING_ATTRIBUTES;
132 
133 /**
134   Returns a list of root Hot Plug Controllers (HPCs) that require initialization
135   during the boot process.
136 
137   This procedure returns a list of root HPCs. The PCI bus driver must initialize
138   these controllers during the boot process. The PCI bus driver may or may not be
139   able to detect these HPCs. If the platform includes a PCI-to-CardBus bridge, it
140   can be included in this list if it requires initialization.  The HpcList must be
141   self consistent. An HPC cannot control any of its parent buses. Only one HPC can
142   control a PCI bus. Because this list includes only root HPCs, no HPC in the list
143   can be a child of another HPC. This policy must be enforced by the
144   EFI_PCI_HOT_PLUG_INIT_PROTOCOL.   The PCI bus driver may not check for such
145   invalid conditions.  The callee allocates the buffer HpcList
146 
147   @param[in]  This       Pointer to the EFI_PCI_HOT_PLUG_INIT_PROTOCOL instance.
148   @param[out] HpcCount   The number of root HPCs that were returned.
149   @param[out] HpcList    The list of root HPCs. HpcCount defines the number of
150                          elements in this list.
151 
152   @retval EFI_SUCCESS             HpcList was returned.
153   @retval EFI_OUT_OF_RESOURCES    HpcList was not returned due to insufficient
154                                   resources.
155   @retval EFI_INVALID_PARAMETER   HpcCount is NULL or HpcList is NULL.
156 
157 **/
158 typedef
159 EFI_STATUS
160 (EFIAPI *EFI_GET_ROOT_HPC_LIST)(
161   IN  EFI_PCI_HOT_PLUG_INIT_PROTOCOL  *This,
162   OUT UINTN                           *HpcCount,
163   OUT EFI_HPC_LOCATION                **HpcList
164   );
165 
166 /**
167   Initializes one root Hot Plug Controller (HPC). This process may causes
168   initialization of its subordinate buses.
169 
170   This function initializes the specified HPC. At the end of initialization,
171   the hot-plug slots or sockets (controlled by this HPC) are powered and are
172   connected to the bus. All the necessary registers in the HPC are set up. For
173   a Standard (PCI) Hot Plug Controller (SHPC), the registers that must be set
174   up are defined in the PCI Standard Hot Plug Controller and Subsystem
175   Specification.
176 
177   @param[in]  This            Pointer to the EFI_PCI_HOT_PLUG_INIT_PROTOCOL instance.
178   @param[in]  HpcDevicePath   The device path to the HPC that is being initialized.
179   @param[in]  HpcPciAddress   The address of the HPC function on the PCI bus.
180   @param[in]  Event           The event that should be signaled when the HPC
181                               initialization is complete.  Set to NULL if the
182                               caller wants to wait until the entire initialization
183                               process is complete.
184   @param[out] HpcState        The state of the HPC hardware. The state is
185                               EFI_HPC_STATE_INITIALIZED or EFI_HPC_STATE_ENABLED.
186 
187   @retval EFI_SUCCESS             If Event is NULL, the specific HPC was successfully
188                                   initialized. If Event is not NULL, Event will be
189                                   signaled at a later time when initialization is complete.
190   @retval EFI_UNSUPPORTED         This instance of EFI_PCI_HOT_PLUG_INIT_PROTOCOL
191                                   does not support the specified HPC.
192   @retval EFI_OUT_OF_RESOURCES    Initialization failed due to insufficient
193                                   resources.
194   @retval EFI_INVALID_PARAMETER   HpcState is NULL.
195 
196 **/
197 typedef
198 EFI_STATUS
199 (EFIAPI *EFI_INITIALIZE_ROOT_HPC)(
200   IN  EFI_PCI_HOT_PLUG_INIT_PROTOCOL  *This,
201   IN  EFI_DEVICE_PATH_PROTOCOL        *HpcDevicePath,
202   IN  UINT64                          HpcPciAddress,
203   IN  EFI_EVENT                       Event,           OPTIONAL
204   OUT EFI_HPC_STATE                   *HpcState
205   );
206 
207 /**
208   Returns the resource padding that is required by the PCI bus that is controlled
209   by the specified Hot Plug Controller (HPC).
210 
211   This function returns the resource padding that is required by the PCI bus that
212   is controlled by the specified HPC. This member function is called for all the
213   root HPCs and nonroot HPCs that are detected by the PCI bus enumerator. This
214   function will be called before PCI resource allocation is completed. This function
215   must be called after all the root HPCs, with the possible exception of a
216   PCI-to-CardBus bridge, have completed initialization.
217 
218   @param[in]  This            Pointer to the EFI_PCI_HOT_PLUG_INIT_PROTOCOL instance.
219   @param[in]  HpcDevicePath   The device path to the HPC.
220   @param[in]  HpcPciAddress   The address of the HPC function on the PCI bus.
221   @param[in]  HpcState        The state of the HPC hardware.
222   @param[out] Padding         The amount of resource padding that is required by the
223                               PCI bus under the control of the specified HPC.
224   @param[out] Attributes      Describes how padding is accounted for. The padding
225                               is returned in the form of ACPI 2.0 resource descriptors.
226 
227   @retval EFI_SUCCESS             The resource padding was successfully returned.
228   @retval EFI_UNSUPPORTED         This instance of the EFI_PCI_HOT_PLUG_INIT_PROTOCOL
229                                   does not support the specified HPC.
230   @retval EFI_NOT_READY           This function was called before HPC initialization
231                                   is complete.
232   @retval EFI_INVALID_PARAMETER   HpcState or Padding or Attributes is NULL.
233   @retval EFI_OUT_OF_RESOURCES    ACPI 2.0 resource descriptors for Padding
234                                   cannot be allocated due to insufficient resources.
235 
236 **/
237 typedef
238 EFI_STATUS
239 (EFIAPI *EFI_GET_HOT_PLUG_PADDING)(
240   IN  EFI_PCI_HOT_PLUG_INIT_PROTOCOL  *This,
241   IN  EFI_DEVICE_PATH_PROTOCOL        *HpcDevicePath,
242   IN  UINT64                          HpcPciAddress,
243   OUT EFI_HPC_STATE                   *HpcState,
244   OUT VOID                            **Padding,
245   OUT EFI_HPC_PADDING_ATTRIBUTES      *Attributes
246   );
247 
248 ///
249 /// This protocol provides the necessary functionality to initialize the
250 /// Hot Plug Controllers (HPCs) and the buses that they control. This protocol
251 /// also provides information regarding resource padding.
252 ///
253 struct _EFI_PCI_HOT_PLUG_INIT_PROTOCOL {
254   ///
255   /// Returns a list of root HPCs and the buses that they control.
256   ///
257   EFI_GET_ROOT_HPC_LIST     GetRootHpcList;
258 
259   ///
260   /// Initializes the specified root HPC.
261   ///
262   EFI_INITIALIZE_ROOT_HPC   InitializeRootHpc;
263 
264   ///
265   /// Returns the resource padding that is required by the HPC.
266   ///
267   EFI_GET_HOT_PLUG_PADDING  GetResourcePadding;
268 };
269 
270 extern EFI_GUID gEfiPciHotPlugInitProtocolGuid;
271 
272 #endif
273