]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/Include/Library/NestedInterruptTplLib.h
OvmfPkg: Add library to handle TPL from within nested interrupt handlers
[mirror_edk2.git] / OvmfPkg / Include / Library / NestedInterruptTplLib.h
CommitLineData
a24fbd60
MB
1/** @file\r
2 Handle raising and lowering TPL from within nested interrupt handlers.\r
3\r
4 Allows interrupt handlers to safely raise and lower the TPL to\r
5 dispatch event notifications, correctly allowing for nested\r
6 interrupts to occur without risking stack exhaustion.\r
7\r
8 Copyright (C) 2022, Fen Systems Ltd.\r
9\r
10 SPDX-License-Identifier: BSD-2-Clause-Patent\r
11**/\r
12\r
13#ifndef __NESTED_INTERRUPT_TPL_LIB__\r
14#define __NESTED_INTERRUPT_TPL_LIB__\r
15\r
16#include <Uefi/UefiBaseType.h>\r
17#include <Uefi/UefiSpec.h>\r
18#include <Protocol/DebugSupport.h>\r
19\r
20///\r
21/// State shared between all invocations of a nested interrupt handler.\r
22///\r
23typedef struct {\r
24 ///\r
25 /// Highest TPL that is currently the target of a call to\r
26 /// RestoreTPL() by an instance of this interrupt handler.\r
27 ///\r
28 EFI_TPL InProgressRestoreTPL;\r
29 ///\r
30 /// Flag used to defer a call to RestoreTPL() from an inner instance\r
31 /// of the interrupt handler to an outer instance of the same\r
32 /// interrupt handler.\r
33 ///\r
34 BOOLEAN DeferredRestoreTPL;\r
35} NESTED_INTERRUPT_STATE;\r
36\r
37/**\r
38 Raise the task priority level to TPL_HIGH_LEVEL.\r
39\r
40 @param None.\r
41\r
42 @return The task priority level at which the interrupt occurred.\r
43**/\r
44EFI_TPL\r
45EFIAPI\r
46NestedInterruptRaiseTPL (\r
47 VOID\r
48 );\r
49\r
50/**\r
51 Lower the task priority back to the value at which the interrupt\r
52 occurred.\r
53\r
54 This is unfortunately messy. UEFI requires us to support nested\r
55 interrupts, but provides no way for an interrupt handler to call\r
56 RestoreTPL() without implicitly re-enabling interrupts. In a\r
57 virtual machine, it is possible for a large burst of interrupts to\r
58 arrive. We must prevent such a burst from leading to stack\r
59 exhaustion, while continuing to allow nested interrupts to occur.\r
60\r
61 Since nested interrupts are permitted, an interrupt handler may be\r
62 invoked as an inner interrupt handler while an outer instance of the\r
63 same interrupt handler is still inside its call to RestoreTPL().\r
64\r
65 To avoid stack exhaustion, this call may therefore (when provably\r
66 safe to do so) defer the actual TPL lowering to be performed by an\r
67 outer instance of the same interrupt handler.\r
68\r
69 @param InterruptedTPL The task priority level at which the interrupt\r
70 occurred, as previously returned from\r
71 NestedInterruptRaiseTPL().\r
72\r
73 @param SystemContext A pointer to the system context when the\r
74 interrupt occurred.\r
75\r
76 @param IsrState A pointer to the state shared between all\r
77 invocations of the nested interrupt handler.\r
78**/\r
79VOID\r
80EFIAPI\r
81NestedInterruptRestoreTPL (\r
82 IN EFI_TPL InterruptedTPL,\r
83 IN OUT EFI_SYSTEM_CONTEXT SystemContext,\r
84 IN OUT NESTED_INTERRUPT_STATE *IsrState\r
85 );\r
86\r
87#endif // __NESTED_INTERRUPT_TPL_LIB__\r