]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Core/Dxe/Event/Tpl.c
move header files in MdeModulePkg\Core\Dxe except DxeMain.h into their corresponding...
[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 #include "Event.h"
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 /**
40 Raise the task priority level to the new level.
41 High level is implemented by disabling processor interrupts.
42
43 @param NewTpl New task priority level
44
45 @return The previous task priority level
46
47 **/
48 EFI_TPL
49 EFIAPI
50 CoreRaiseTpl (
51 IN EFI_TPL NewTpl
52 )
53 {
54 EFI_TPL OldTpl;
55
56 OldTpl = gEfiCurrentTpl;
57 ASSERT (OldTpl <= NewTpl);
58 ASSERT (VALID_TPL (NewTpl));
59
60 //
61 // If raising to high level, disable interrupts
62 //
63 if (NewTpl >= TPL_HIGH_LEVEL && OldTpl < TPL_HIGH_LEVEL) {
64 CoreSetInterruptState (FALSE);
65 }
66
67 //
68 // Set the new value
69 //
70 gEfiCurrentTpl = NewTpl;
71
72 return OldTpl;
73 }
74
75
76
77
78 /**
79 Lowers the task priority to the previous value. If the new
80 priority unmasks events at a higher priority, they are dispatched.
81
82 @param NewTpl New, lower, task priority
83
84 **/
85 VOID
86 EFIAPI
87 CoreRestoreTpl (
88 IN EFI_TPL NewTpl
89 )
90 {
91 EFI_TPL OldTpl;
92
93 OldTpl = gEfiCurrentTpl;
94 ASSERT (NewTpl <= OldTpl);
95 ASSERT (VALID_TPL (NewTpl));
96
97 //
98 // If lowering below HIGH_LEVEL, make sure
99 // interrupts are enabled
100 //
101
102 if (OldTpl >= TPL_HIGH_LEVEL && NewTpl < TPL_HIGH_LEVEL) {
103 gEfiCurrentTpl = TPL_HIGH_LEVEL;
104 }
105
106 //
107 // Dispatch any pending events
108 //
109 while (((-2 << NewTpl) & gEventPending) != 0) {
110 gEfiCurrentTpl = HighBitSet64 (gEventPending);
111 if (gEfiCurrentTpl < TPL_HIGH_LEVEL) {
112 CoreSetInterruptState (TRUE);
113 }
114 CoreDispatchEventNotifies (gEfiCurrentTpl);
115 }
116
117 //
118 // Set the new value
119 //
120
121 gEfiCurrentTpl = NewTpl;
122
123 //
124 // If lowering below HIGH_LEVEL, make sure
125 // interrupts are enabled
126 //
127 if (gEfiCurrentTpl < TPL_HIGH_LEVEL) {
128 CoreSetInterruptState (TRUE);
129 }
130
131 }