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