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