]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Core/Dxe/Event/tpl.c
Add comments and DoxyGen format for these files.
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / Event / tpl.c
1 /** @file
2
3 Task priority (TPL) function
4
5 Copyright (c) 2006 - 2008, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 #include <DxeMain.h>
17
18 STATIC
19 VOID
20 CoreSetInterruptState (
21 IN BOOLEAN Enable
22 )
23 /*++
24
25 Routine Description:
26
27 Set Interrupt State
28
29 Arguments:
30
31 Enable - The state of enable or disable interrupt
32
33 Returns:
34
35 None
36
37 --*/
38
39 {
40 if (gCpu != NULL) {
41 if (Enable) {
42 gCpu->EnableInterrupt(gCpu);
43 } else {
44 gCpu->DisableInterrupt(gCpu);
45 }
46 }
47 }
48
49 //
50 // Return the highest set bit
51 //
52 UINTN
53 CoreHighestSetBit (
54 IN UINTN Number
55 )
56 /*++
57
58 Routine Description:
59
60 Return the highest set bit
61
62 Arguments:
63
64 Number - The value to check
65
66 Returns:
67
68 Bit position of the highest set bit
69
70 --*/
71 {
72 UINTN msb;
73
74 msb = 31;
75 while ((msb > 0) && ((Number & (UINTN)(1 << msb)) == 0)) {
76 msb--;
77 }
78
79 return msb;
80 }
81
82
83
84 EFI_TPL
85 EFIAPI
86 CoreRaiseTpl (
87 IN EFI_TPL NewTpl
88 )
89 /*++
90
91 Routine Description:
92
93 Raise the task priority level to the new level.
94 High level is implemented by disabling processor interrupts.
95
96 Arguments:
97
98 NewTpl - New task priority level
99
100 Returns:
101
102 The previous task priority level
103
104 --*/
105 {
106 EFI_TPL OldTpl;
107
108 OldTpl = gEfiCurrentTpl;
109 ASSERT (OldTpl <= NewTpl);
110 ASSERT (VALID_TPL (NewTpl));
111
112 //
113 // If raising to high level, disable interrupts
114 //
115 if (NewTpl >= TPL_HIGH_LEVEL && OldTpl < TPL_HIGH_LEVEL) {
116 CoreSetInterruptState (FALSE);
117 }
118
119 //
120 // Set the new value
121 //
122 gEfiCurrentTpl = NewTpl;
123
124 return OldTpl;
125 }
126
127
128
129 VOID
130 EFIAPI
131 CoreRestoreTpl (
132 IN EFI_TPL NewTpl
133 )
134 /*++
135
136 Routine Description:
137
138 Lowers the task priority to the previous value. If the new
139 priority unmasks events at a higher priority, they are dispatched.
140
141 Arguments:
142
143 NewTpl - New, lower, task priority
144
145 Returns:
146
147 None
148
149 --*/
150 {
151 EFI_TPL OldTpl;
152
153 OldTpl = gEfiCurrentTpl;
154 ASSERT (NewTpl <= OldTpl);
155 ASSERT (VALID_TPL (NewTpl));
156
157 //
158 // If lowering below HIGH_LEVEL, make sure
159 // interrupts are enabled
160 //
161
162 if (OldTpl >= TPL_HIGH_LEVEL && NewTpl < TPL_HIGH_LEVEL) {
163 gEfiCurrentTpl = TPL_HIGH_LEVEL;
164 }
165
166 //
167 // Dispatch any pending events
168 //
169
170 while ((-2 << NewTpl) & gEventPending) {
171 gEfiCurrentTpl = CoreHighestSetBit (gEventPending);
172 if (gEfiCurrentTpl < TPL_HIGH_LEVEL) {
173 CoreSetInterruptState (TRUE);
174 }
175 CoreDispatchEventNotifies (gEfiCurrentTpl);
176 }
177
178 //
179 // Set the new value
180 //
181
182 gEfiCurrentTpl = NewTpl;
183
184 //
185 // If lowering below HIGH_LEVEL, make sure
186 // interrupts are enabled
187 //
188 if (gEfiCurrentTpl < TPL_HIGH_LEVEL) {
189 CoreSetInterruptState (TRUE);
190 }
191
192 }