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