]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Core/Dxe/Library/Library.c
Clean up DxeCore to use report status code macros in ReportStatusCode to retire CoreR...
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / Library / Library.c
CommitLineData
162ed594 1/** @file\r
797a9d67 2 DXE Core library services.\r
23c98c94 3\r
4Copyright (c) 2006 - 2008, Intel Corporation. <BR>\r
28a00297 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
12\r
797a9d67 13**/\r
28a00297 14\r
9c4ac31c 15#include "DxeMain.h"\r
28a00297 16\r
28a00297 17//\r
18// Lock Stuff\r
19//\r
162ed594 20/**\r
28a00297 21 Initialize a basic mutual exclusion lock. Each lock\r
22 provides mutual exclusion access at it's task priority\r
23 level. Since there is no-premption (at any TPL) or\r
24 multiprocessor support, acquiring the lock only consists\r
25 of raising to the locks TPL.\r
26\r
022c6d45 27 @param Lock The EFI_LOCK structure to initialize\r
28a00297 28\r
022c6d45 29 @retval EFI_SUCCESS Lock Owned.\r
162ed594 30 @retval EFI_ACCESS_DENIED Reentrant Lock Acquisition, Lock not Owned.\r
28a00297 31\r
162ed594 32**/\r
33EFI_STATUS\r
34CoreAcquireLockOrFail (\r
35 IN EFI_LOCK *Lock\r
36 )\r
28a00297 37{\r
38 ASSERT (Lock != NULL);\r
39 ASSERT (Lock->Lock != EfiLockUninitialized);\r
40\r
41 if (Lock->Lock == EfiLockAcquired) {\r
42 //\r
43 // Lock is already owned, so bail out\r
44 //\r
45 return EFI_ACCESS_DENIED;\r
46 }\r
47\r
48 Lock->OwnerTpl = CoreRaiseTpl (Lock->Tpl);\r
49\r
50 Lock->Lock = EfiLockAcquired;\r
51 return EFI_SUCCESS;\r
52}\r
53\r
54\r
28a00297 55\r
162ed594 56/**\r
28a00297 57 Raising to the task priority level of the mutual exclusion\r
58 lock, and then acquires ownership of the lock.\r
59\r
022c6d45 60 @param Lock The lock to acquire\r
28a00297 61\r
162ed594 62 @return Lock owned\r
28a00297 63\r
162ed594 64**/\r
65VOID\r
66CoreAcquireLock (\r
67 IN EFI_LOCK *Lock\r
68 )\r
28a00297 69{\r
70 ASSERT (Lock != NULL);\r
71 ASSERT (Lock->Lock == EfiLockReleased);\r
72\r
73 Lock->OwnerTpl = CoreRaiseTpl (Lock->Tpl);\r
74 Lock->Lock = EfiLockAcquired;\r
75}\r
76\r
77\r
28a00297 78\r
162ed594 79/**\r
80 Releases ownership of the mutual exclusion lock, and\r
81 restores the previous task priority level.\r
28a00297 82\r
022c6d45 83 @param Lock The lock to release\r
28a00297 84\r
162ed594 85 @return Lock unowned\r
28a00297 86\r
162ed594 87**/\r
88VOID\r
89CoreReleaseLock (\r
90 IN EFI_LOCK *Lock\r
91 )\r
28a00297 92{\r
93 EFI_TPL Tpl;\r
94\r
95 ASSERT (Lock != NULL);\r
96 ASSERT (Lock->Lock == EfiLockAcquired);\r
97\r
98 Tpl = Lock->OwnerTpl;\r
99\r
100 Lock->Lock = EfiLockReleased;\r
101\r
102 CoreRestoreTpl (Tpl);\r
103}\r
104\r
105\r
162ed594 106/**\r
107 Create a protocol notification event and return it.\r
108\r
022c6d45 109 @param ProtocolGuid Protocol to register notification event on.\r
110 @param NotifyTpl Maximum TPL to signal the NotifyFunction.\r
111 @param NotifyFunction EFI notification routine.\r
112 @param NotifyContext Context passed into Event when it is created.\r
113 @param Registration Registration key returned from\r
114 RegisterProtocolNotify().\r
115 @param SignalFlag Boolean value to decide whether kick the event after\r
116 register or not.\r
162ed594 117\r
118 @return The EFI_EVENT that has been registered to be signaled when a ProtocolGuid\r
119 is added to the system.\r
120\r
121**/\r
28a00297 122EFI_EVENT\r
123CoreCreateProtocolNotifyEvent (\r
124 IN EFI_GUID *ProtocolGuid,\r
125 IN EFI_TPL NotifyTpl,\r
126 IN EFI_EVENT_NOTIFY NotifyFunction,\r
127 IN VOID *NotifyContext,\r
128 OUT VOID **Registration,\r
129 IN BOOLEAN SignalFlag\r
130 )\r
28a00297 131{\r
132 EFI_STATUS Status;\r
133 EFI_EVENT Event;\r
134\r
135 //\r
136 // Create the event\r
137 //\r
28a00297 138 Status = CoreCreateEvent (\r
139 EVT_NOTIFY_SIGNAL,\r
140 NotifyTpl,\r
141 NotifyFunction,\r
142 NotifyContext,\r
e94a9ff7 143 &Event\r
28a00297 144 );\r
145 ASSERT_EFI_ERROR (Status);\r
146\r
147 //\r
148 // Register for protocol notifactions on this event\r
149 //\r
28a00297 150 Status = CoreRegisterProtocolNotify (\r
e94a9ff7 151 ProtocolGuid,\r
152 Event,\r
153 Registration\r
154 );\r
28a00297 155 ASSERT_EFI_ERROR (Status);\r
156\r
157 if (SignalFlag) {\r
158 //\r
159 // Kick the event so we will perform an initial pass of\r
160 // current installed drivers\r
161 //\r
162 CoreSignalEvent (Event);\r
163 }\r
164\r
165 return Event;\r
166}\r
167\r
162ed594 168\r