]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Core/Dxe/Library/Library.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / Library / Library.c
1 /** @file
2 DXE Core library services.
3
4 Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include "DxeMain.h"
10
11 //
12 // Lock Stuff
13 //
14
15 /**
16 Initialize a basic mutual exclusion lock. Each lock
17 provides mutual exclusion access at it's task priority
18 level. Since there is no-premption (at any TPL) or
19 multiprocessor support, acquiring the lock only consists
20 of raising to the locks TPL.
21
22 @param Lock The EFI_LOCK structure to initialize
23
24 @retval EFI_SUCCESS Lock Owned.
25 @retval EFI_ACCESS_DENIED Reentrant Lock Acquisition, Lock not Owned.
26
27 **/
28 EFI_STATUS
29 CoreAcquireLockOrFail (
30 IN EFI_LOCK *Lock
31 )
32 {
33 ASSERT (Lock != NULL);
34 ASSERT (Lock->Lock != EfiLockUninitialized);
35
36 if (Lock->Lock == EfiLockAcquired) {
37 //
38 // Lock is already owned, so bail out
39 //
40 return EFI_ACCESS_DENIED;
41 }
42
43 Lock->OwnerTpl = CoreRaiseTpl (Lock->Tpl);
44
45 Lock->Lock = EfiLockAcquired;
46 return EFI_SUCCESS;
47 }
48
49 /**
50 Raising to the task priority level of the mutual exclusion
51 lock, and then acquires ownership of the lock.
52
53 @param Lock The lock to acquire
54
55 @return Lock owned
56
57 **/
58 VOID
59 CoreAcquireLock (
60 IN EFI_LOCK *Lock
61 )
62 {
63 ASSERT (Lock != NULL);
64 ASSERT (Lock->Lock == EfiLockReleased);
65
66 Lock->OwnerTpl = CoreRaiseTpl (Lock->Tpl);
67 Lock->Lock = EfiLockAcquired;
68 }
69
70 /**
71 Releases ownership of the mutual exclusion lock, and
72 restores the previous task priority level.
73
74 @param Lock The lock to release
75
76 @return Lock unowned
77
78 **/
79 VOID
80 CoreReleaseLock (
81 IN EFI_LOCK *Lock
82 )
83 {
84 EFI_TPL Tpl;
85
86 ASSERT (Lock != NULL);
87 ASSERT (Lock->Lock == EfiLockAcquired);
88
89 Tpl = Lock->OwnerTpl;
90
91 Lock->Lock = EfiLockReleased;
92
93 CoreRestoreTpl (Tpl);
94 }