]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Core/Dxe/Event/Tpl.c
Update the copyright notice format
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / Event / Tpl.c
1 /** @file
2 Task priority (TPL) functions.
3
4 Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
5 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 EFI_STATUS Status;
30 BOOLEAN InSmm;
31
32 if (gCpu == NULL) {
33 return;
34 }
35 if (!Enable) {
36 gCpu->DisableInterrupt (gCpu);
37 return;
38 }
39 if (gSmmBase2 == NULL) {
40 gCpu->EnableInterrupt (gCpu);
41 return;
42 }
43 Status = gSmmBase2->InSmm (gSmmBase2, &InSmm);
44 if (!EFI_ERROR (Status) && !InSmm) {
45 gCpu->EnableInterrupt(gCpu);
46 }
47 }
48
49
50 /**
51 Raise the task priority level to the new level.
52 High level is implemented by disabling processor interrupts.
53
54 @param NewTpl New task priority level
55
56 @return The previous task priority level
57
58 **/
59 EFI_TPL
60 EFIAPI
61 CoreRaiseTpl (
62 IN EFI_TPL NewTpl
63 )
64 {
65 EFI_TPL OldTpl;
66
67 OldTpl = gEfiCurrentTpl;
68 ASSERT (OldTpl <= NewTpl);
69 ASSERT (VALID_TPL (NewTpl));
70
71 //
72 // If raising to high level, disable interrupts
73 //
74 if (NewTpl >= TPL_HIGH_LEVEL && OldTpl < TPL_HIGH_LEVEL) {
75 CoreSetInterruptState (FALSE);
76 }
77
78 //
79 // Set the new value
80 //
81 gEfiCurrentTpl = NewTpl;
82
83 return OldTpl;
84 }
85
86
87
88
89 /**
90 Lowers the task priority to the previous value. If the new
91 priority unmasks events at a higher priority, they are dispatched.
92
93 @param NewTpl New, lower, task priority
94
95 **/
96 VOID
97 EFIAPI
98 CoreRestoreTpl (
99 IN EFI_TPL NewTpl
100 )
101 {
102 EFI_TPL OldTpl;
103
104 OldTpl = gEfiCurrentTpl;
105 ASSERT (NewTpl <= OldTpl);
106 ASSERT (VALID_TPL (NewTpl));
107
108 //
109 // If lowering below HIGH_LEVEL, make sure
110 // interrupts are enabled
111 //
112
113 if (OldTpl >= TPL_HIGH_LEVEL && NewTpl < TPL_HIGH_LEVEL) {
114 gEfiCurrentTpl = TPL_HIGH_LEVEL;
115 }
116
117 //
118 // Dispatch any pending events
119 //
120 while (((-2 << NewTpl) & gEventPending) != 0) {
121 gEfiCurrentTpl = HighBitSet64 (gEventPending);
122 if (gEfiCurrentTpl < TPL_HIGH_LEVEL) {
123 CoreSetInterruptState (TRUE);
124 }
125 CoreDispatchEventNotifies (gEfiCurrentTpl);
126 }
127
128 //
129 // Set the new value
130 //
131
132 gEfiCurrentTpl = NewTpl;
133
134 //
135 // If lowering below HIGH_LEVEL, make sure
136 // interrupts are enabled
137 //
138 if (gEfiCurrentTpl < TPL_HIGH_LEVEL) {
139 CoreSetInterruptState (TRUE);
140 }
141
142 }