boot_services/tpl.rs
1//! This module defined every struct related to Tpl in boot services.
2
3use r_efi::efi;
4
5use crate::BootServices;
6
7/// This is a structure restore the [`Tpl`] at the end of its scope or when dropped.
8///
9/// See [`BootServices::raise_tpl_guarded`] for more details.
10#[must_use = "if unused the Tpl will immediately restored"]
11pub struct TplGuard<'a, T: BootServices + ?Sized> {
12 pub(crate) boot_services: &'a T,
13 pub(crate) retore_tpl: Tpl,
14}
15
16impl<'a, T: BootServices + ?Sized> Drop for TplGuard<'a, T> {
17 fn drop(&mut self) {
18 self.boot_services.restore_tpl(self.retore_tpl);
19 }
20}
21
22/// Task Priority Level
23#[derive(Debug, PartialEq, Eq, Clone, Copy, PartialOrd, Ord)]
24#[repr(transparent)]
25pub struct Tpl(pub usize);
26
27impl Tpl {
28 /// This is the lowest priority level.
29 /// It is the level of execution which occurs when no event notifications are pending and which interacts with the user.
30 /// User I/O (and blocking on User I/O) can be performed at this level.
31 /// The boot manager executes at this level and passes control to other UEFI applications at this level.
32 pub const APPLICATION: Tpl = Tpl(efi::TPL_APPLICATION);
33
34 /// Interrupts code executing below TPL_CALLBACK level.
35 /// Long term operations (such as file system operations and disk I/O) can occur at this level.
36 pub const CALLBACK: Tpl = Tpl(efi::TPL_CALLBACK);
37
38 /// Interrupts code executing below TPL_NOTIFY level.
39 /// Blocking is not allowed at this level.
40 /// Code executes to completion and returns.
41 /// If code requires more processing, it needs to signal an event to wait to obtain control again at whatever level it requires.
42 /// This level is typically used to process low level IO to or from a device.
43 pub const NOTIFY: Tpl = Tpl(efi::TPL_NOTIFY);
44}
45
46impl Into<usize> for Tpl {
47 fn into(self) -> usize {
48 self.0
49 }
50}
51
52impl Into<Tpl> for usize {
53 fn into(self) -> Tpl {
54 Tpl(self)
55 }
56}