]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Core/Dxe/Event/Tpl.c
Clean up DxeCore to remove duplicate memory allocation & device path utility services...
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / Event / Tpl.c
1 /** @file
2 Task priority (TPL) functions.
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 /**
19 Set Interrupt State.
20
21 @param Enable The state of enable or disable interrupt
22
23 **/
24 VOID
25 CoreSetInterruptState (
26 IN BOOLEAN Enable
27 )
28 {
29 if (gCpu != NULL) {
30 if (Enable) {
31 gCpu->EnableInterrupt(gCpu);
32 } else {
33 gCpu->DisableInterrupt(gCpu);
34 }
35 }
36 }
37
38 //
39 // Return the highest set bit
40 //
41
42 /**
43 Return the highest set bit.
44
45 @param Number The value to check
46
47 @return Bit position of the highest set bit
48
49 **/
50 UINTN
51 CoreHighestSetBit (
52 IN UINTN Number
53 )
54 {
55 UINTN Msb;
56
57 Msb = 31;
58 while ((Msb > 0) && ((Number & (UINTN)(1 << Msb)) == 0)) {
59 Msb--;
60 }
61
62 return Msb;
63 }
64
65
66
67
68 /**
69 Raise the task priority level to the new level.
70 High level is implemented by disabling processor interrupts.
71
72 @param NewTpl New task priority level
73
74 @return The previous task priority level
75
76 **/
77 EFI_TPL
78 EFIAPI
79 CoreRaiseTpl (
80 IN EFI_TPL NewTpl
81 )
82 {
83 EFI_TPL OldTpl;
84
85 OldTpl = gEfiCurrentTpl;
86 ASSERT (OldTpl <= NewTpl);
87 ASSERT (VALID_TPL (NewTpl));
88
89 //
90 // If raising to high level, disable interrupts
91 //
92 if (NewTpl >= TPL_HIGH_LEVEL && OldTpl < TPL_HIGH_LEVEL) {
93 CoreSetInterruptState (FALSE);
94 }
95
96 //
97 // Set the new value
98 //
99 gEfiCurrentTpl = NewTpl;
100
101 return OldTpl;
102 }
103
104
105
106
107 /**
108 Lowers the task priority to the previous value. If the new
109 priority unmasks events at a higher priority, they are dispatched.
110
111 @param NewTpl New, lower, task priority
112
113 **/
114 VOID
115 EFIAPI
116 CoreRestoreTpl (
117 IN EFI_TPL NewTpl
118 )
119 {
120 EFI_TPL OldTpl;
121
122 OldTpl = gEfiCurrentTpl;
123 ASSERT (NewTpl <= OldTpl);
124 ASSERT (VALID_TPL (NewTpl));
125
126 //
127 // If lowering below HIGH_LEVEL, make sure
128 // interrupts are enabled
129 //
130
131 if (OldTpl >= TPL_HIGH_LEVEL && NewTpl < TPL_HIGH_LEVEL) {
132 gEfiCurrentTpl = TPL_HIGH_LEVEL;
133 }
134
135 //
136 // Dispatch any pending events
137 //
138
139 while ((-2 << NewTpl) & gEventPending) {
140 gEfiCurrentTpl = CoreHighestSetBit (gEventPending);
141 if (gEfiCurrentTpl < TPL_HIGH_LEVEL) {
142 CoreSetInterruptState (TRUE);
143 }
144 CoreDispatchEventNotifies (gEfiCurrentTpl);
145 }
146
147 //
148 // Set the new value
149 //
150
151 gEfiCurrentTpl = NewTpl;
152
153 //
154 // If lowering below HIGH_LEVEL, make sure
155 // interrupts are enabled
156 //
157 if (gEfiCurrentTpl < TPL_HIGH_LEVEL) {
158 CoreSetInterruptState (TRUE);
159 }
160
161 }