]>
Commit | Line | Data |
---|---|---|
23c98c94 | 1 | /** @file\r |
504214c4 LG |
2 | Support functions for managing protocol.\r |
3 | \r | |
d1102dba | 4 | Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r |
9d510e61 | 5 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
28a00297 | 6 | \r |
504214c4 | 7 | **/\r |
28a00297 | 8 | \r |
9 | #ifndef _HAND_H_\r | |
10 | #define _HAND_H_\r | |
11 | \r | |
1436aea4 | 12 | #define EFI_HANDLE_SIGNATURE SIGNATURE_32('h','n','d','l')\r |
ec90508b | 13 | \r |
14 | ///\r | |
15 | /// IHANDLE - contains a list of protocol handles\r | |
16 | ///\r | |
28a00297 | 17 | typedef struct {\r |
1436aea4 | 18 | UINTN Signature;\r |
ec90508b | 19 | /// All handles list of IHANDLE\r |
1436aea4 | 20 | LIST_ENTRY AllHandles;\r |
ec90508b | 21 | /// List of PROTOCOL_INTERFACE's for this handle\r |
1436aea4 MK |
22 | LIST_ENTRY Protocols;\r |
23 | UINTN LocateRequest;\r | |
ec90508b | 24 | /// The Handle Database Key value when this handle was last created or modified\r |
1436aea4 | 25 | UINT64 Key;\r |
28a00297 | 26 | } IHANDLE;\r |
27 | \r | |
28 | #define ASSERT_IS_HANDLE(a) ASSERT((a)->Signature == EFI_HANDLE_SIGNATURE)\r | |
29 | \r | |
1436aea4 | 30 | #define PROTOCOL_ENTRY_SIGNATURE SIGNATURE_32('p','r','t','e')\r |
ec90508b | 31 | \r |
32 | ///\r | |
33 | /// PROTOCOL_ENTRY - each different protocol has 1 entry in the protocol\r | |
34 | /// database. Each handler that supports this protocol is listed, along\r | |
35 | /// with a list of registered notifies.\r | |
36 | ///\r | |
28a00297 | 37 | typedef struct {\r |
1436aea4 | 38 | UINTN Signature;\r |
ec90508b | 39 | /// Link Entry inserted to mProtocolDatabase\r |
1436aea4 | 40 | LIST_ENTRY AllEntries;\r |
ec90508b | 41 | /// ID of the protocol\r |
1436aea4 | 42 | EFI_GUID ProtocolID;\r |
ec90508b | 43 | /// All protocol interfaces\r |
1436aea4 | 44 | LIST_ENTRY Protocols;\r |
ec90508b | 45 | /// Registerd notification handlers\r |
1436aea4 | 46 | LIST_ENTRY Notify;\r |
28a00297 | 47 | } PROTOCOL_ENTRY;\r |
48 | \r | |
f3f2e05d | 49 | #define PROTOCOL_INTERFACE_SIGNATURE SIGNATURE_32('p','i','f','c')\r |
ec90508b | 50 | \r |
51 | ///\r | |
52 | /// PROTOCOL_INTERFACE - each protocol installed on a handle is tracked\r | |
53 | /// with a protocol interface structure\r | |
54 | ///\r | |
28a00297 | 55 | typedef struct {\r |
1436aea4 | 56 | UINTN Signature;\r |
ec90508b | 57 | /// Link on IHANDLE.Protocols\r |
1436aea4 | 58 | LIST_ENTRY Link;\r |
ec90508b | 59 | /// Back pointer\r |
1436aea4 | 60 | IHANDLE *Handle;\r |
ec90508b | 61 | /// Link on PROTOCOL_ENTRY.Protocols\r |
1436aea4 | 62 | LIST_ENTRY ByProtocol;\r |
ec90508b | 63 | /// The protocol ID\r |
1436aea4 | 64 | PROTOCOL_ENTRY *Protocol;\r |
ec90508b | 65 | /// The interface value\r |
1436aea4 | 66 | VOID *Interface;\r |
ec90508b | 67 | /// OPEN_PROTOCOL_DATA list\r |
1436aea4 MK |
68 | LIST_ENTRY OpenList;\r |
69 | UINTN OpenListCount;\r | |
28a00297 | 70 | } PROTOCOL_INTERFACE;\r |
71 | \r | |
f3f2e05d | 72 | #define OPEN_PROTOCOL_DATA_SIGNATURE SIGNATURE_32('p','o','d','l')\r |
28a00297 | 73 | \r |
74 | typedef struct {\r | |
1436aea4 MK |
75 | UINTN Signature;\r |
76 | /// Link on PROTOCOL_INTERFACE.OpenList\r | |
77 | LIST_ENTRY Link;\r | |
78 | \r | |
79 | EFI_HANDLE AgentHandle;\r | |
80 | EFI_HANDLE ControllerHandle;\r | |
81 | UINT32 Attributes;\r | |
82 | UINT32 OpenCount;\r | |
28a00297 | 83 | } OPEN_PROTOCOL_DATA;\r |
84 | \r | |
1436aea4 | 85 | #define PROTOCOL_NOTIFY_SIGNATURE SIGNATURE_32('p','r','t','n')\r |
ec90508b | 86 | \r |
87 | ///\r | |
88 | /// PROTOCOL_NOTIFY - used for each register notification for a protocol\r | |
89 | ///\r | |
28a00297 | 90 | typedef struct {\r |
1436aea4 MK |
91 | UINTN Signature;\r |
92 | PROTOCOL_ENTRY *Protocol;\r | |
ec90508b | 93 | /// All notifications for this protocol\r |
1436aea4 | 94 | LIST_ENTRY Link;\r |
ec90508b | 95 | /// Event to notify\r |
1436aea4 | 96 | EFI_EVENT Event;\r |
ec90508b | 97 | /// Last position notified\r |
1436aea4 | 98 | LIST_ENTRY *Position;\r |
28a00297 | 99 | } PROTOCOL_NOTIFY;\r |
100 | \r | |
162ed594 | 101 | /**\r |
28a00297 | 102 | Finds the protocol entry for the requested protocol.\r |
28a00297 | 103 | The gProtocolDatabaseLock must be owned\r |
104 | \r | |
022c6d45 | 105 | @param Protocol The ID of the protocol\r |
106 | @param Create Create a new entry if not found\r | |
162ed594 | 107 | \r |
108 | @return Protocol entry\r | |
28a00297 | 109 | \r |
162ed594 | 110 | **/\r |
111 | PROTOCOL_ENTRY *\r | |
112 | CoreFindProtocolEntry (\r | |
1436aea4 MK |
113 | IN EFI_GUID *Protocol,\r |
114 | IN BOOLEAN Create\r | |
23c98c94 | 115 | );\r |
28a00297 | 116 | \r |
162ed594 | 117 | /**\r |
118 | Signal event for every protocol in protocol entry.\r | |
28a00297 | 119 | \r |
162ed594 | 120 | @param ProtEntry Protocol entry\r |
28a00297 | 121 | \r |
162ed594 | 122 | **/\r |
28a00297 | 123 | VOID\r |
124 | CoreNotifyProtocolEntry (\r | |
1436aea4 | 125 | IN PROTOCOL_ENTRY *ProtEntry\r |
23c98c94 | 126 | );\r |
28a00297 | 127 | \r |
162ed594 | 128 | /**\r |
129 | Finds the protocol instance for the requested handle and protocol.\r | |
130 | Note: This function doesn't do parameters checking, it's caller's responsibility\r | |
131 | to pass in valid parameters.\r | |
28a00297 | 132 | \r |
022c6d45 | 133 | @param Handle The handle to search the protocol on\r |
134 | @param Protocol GUID of the protocol\r | |
135 | @param Interface The interface for the protocol being searched\r | |
28a00297 | 136 | \r |
162ed594 | 137 | @return Protocol instance (NULL: Not found)\r |
28a00297 | 138 | \r |
162ed594 | 139 | **/\r |
28a00297 | 140 | PROTOCOL_INTERFACE *\r |
141 | CoreFindProtocolInterface (\r | |
1436aea4 MK |
142 | IN IHANDLE *Handle,\r |
143 | IN EFI_GUID *Protocol,\r | |
144 | IN VOID *Interface\r | |
23c98c94 | 145 | );\r |
28a00297 | 146 | \r |
162ed594 | 147 | /**\r |
148 | Removes Protocol from the protocol list (but not the handle list).\r | |
28a00297 | 149 | \r |
022c6d45 | 150 | @param Handle The handle to remove protocol on.\r |
151 | @param Protocol GUID of the protocol to be moved\r | |
152 | @param Interface The interface of the protocol\r | |
28a00297 | 153 | \r |
162ed594 | 154 | @return Protocol Entry\r |
28a00297 | 155 | \r |
162ed594 | 156 | **/\r |
28a00297 | 157 | PROTOCOL_INTERFACE *\r |
158 | CoreRemoveInterfaceFromProtocol (\r | |
1436aea4 MK |
159 | IN IHANDLE *Handle,\r |
160 | IN EFI_GUID *Protocol,\r | |
161 | IN VOID *Interface\r | |
23c98c94 | 162 | );\r |
28a00297 | 163 | \r |
e94a9ff7 | 164 | /**\r |
165 | Connects a controller to a driver.\r | |
166 | \r | |
022c6d45 | 167 | @param ControllerHandle Handle of the controller to be\r |
168 | connected.\r | |
169 | @param ContextDriverImageHandles DriverImageHandle A pointer to an\r | |
170 | ordered list of driver image\r | |
171 | handles.\r | |
172 | @param RemainingDevicePath RemainingDevicePath A pointer to\r | |
173 | the device path that specifies a\r | |
174 | child of the controller\r | |
175 | specified by ControllerHandle.\r | |
176 | \r | |
177 | @retval EFI_SUCCESS One or more drivers were\r | |
178 | connected to ControllerHandle.\r | |
179 | @retval EFI_OUT_OF_RESOURCES No enough system resources to\r | |
180 | complete the request.\r | |
181 | @retval EFI_NOT_FOUND No drivers were connected to\r | |
e94a9ff7 | 182 | ControllerHandle.\r |
183 | \r | |
184 | **/\r | |
022c6d45 | 185 | EFI_STATUS\r |
e94a9ff7 | 186 | CoreConnectSingleController (\r |
187 | IN EFI_HANDLE ControllerHandle,\r | |
188 | IN EFI_HANDLE *ContextDriverImageHandles OPTIONAL,\r | |
022c6d45 | 189 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r |
e94a9ff7 | 190 | );\r |
28a00297 | 191 | \r |
162ed594 | 192 | /**\r |
193 | Attempts to disconnect all drivers that are using the protocol interface being queried.\r | |
194 | If failed, reconnect all drivers disconnected.\r | |
195 | Note: This function doesn't do parameters checking, it's caller's responsibility\r | |
196 | to pass in valid parameters.\r | |
28a00297 | 197 | \r |
022c6d45 | 198 | @param UserHandle The handle on which the protocol is installed\r |
199 | @param Prot The protocol to disconnect drivers from\r | |
28a00297 | 200 | \r |
022c6d45 | 201 | @retval EFI_SUCCESS Drivers using the protocol interface are all\r |
202 | disconnected\r | |
162ed594 | 203 | @retval EFI_ACCESS_DENIED Failed to disconnect one or all of the drivers\r |
28a00297 | 204 | \r |
162ed594 | 205 | **/\r |
28a00297 | 206 | EFI_STATUS\r |
207 | CoreDisconnectControllersUsingProtocolInterface (\r | |
1436aea4 MK |
208 | IN EFI_HANDLE UserHandle,\r |
209 | IN PROTOCOL_INTERFACE *Prot\r | |
23c98c94 | 210 | );\r |
28a00297 | 211 | \r |
162ed594 | 212 | /**\r |
213 | Acquire lock on gProtocolDatabaseLock.\r | |
28a00297 | 214 | \r |
162ed594 | 215 | **/\r |
28a00297 | 216 | VOID\r |
217 | CoreAcquireProtocolLock (\r | |
218 | VOID\r | |
23c98c94 | 219 | );\r |
28a00297 | 220 | \r |
162ed594 | 221 | /**\r |
222 | Release lock on gProtocolDatabaseLock.\r | |
28a00297 | 223 | \r |
162ed594 | 224 | **/\r |
28a00297 | 225 | VOID\r |
226 | CoreReleaseProtocolLock (\r | |
227 | VOID\r | |
23c98c94 | 228 | );\r |
28a00297 | 229 | \r |
162ed594 | 230 | /**\r |
231 | Check whether a handle is a valid EFI_HANDLE\r | |
a7fcab7a | 232 | The gProtocolDatabaseLock must be owned\r |
28a00297 | 233 | \r |
022c6d45 | 234 | @param UserHandle The handle to check\r |
28a00297 | 235 | \r |
022c6d45 | 236 | @retval EFI_INVALID_PARAMETER The handle is NULL or not a valid EFI_HANDLE.\r |
162ed594 | 237 | @retval EFI_SUCCESS The handle is valid EFI_HANDLE.\r |
28a00297 | 238 | \r |
162ed594 | 239 | **/\r |
28a00297 | 240 | EFI_STATUS\r |
241 | CoreValidateHandle (\r | |
1436aea4 | 242 | IN EFI_HANDLE UserHandle\r |
23c98c94 | 243 | );\r |
28a00297 | 244 | \r |
245 | //\r | |
246 | // Externs\r | |
247 | //\r | |
1436aea4 MK |
248 | extern EFI_LOCK gProtocolDatabaseLock;\r |
249 | extern LIST_ENTRY gHandleList;\r | |
250 | extern UINT64 gHandleDatabaseKey;\r | |
28a00297 | 251 | \r |
252 | #endif\r |