1const uefi = @import("std").os.uefi;
2const Guid = uefi.Guid;
3const TableHeader = uefi.tables.TableHeader;
4const Time = uefi.Time;
5const TimeCapabilities = uefi.TimeCapabilities;
6const Status = uefi.Status;
7const MemoryDescriptor = uefi.tables.MemoryDescriptor;
8
9/// Runtime services are provided by the firmware before and after exitBootServices has been called.
10///
11/// As the runtime_services table may grow with new UEFI versions, it is important to check hdr.header_size.
12///
13/// Some functions may not be supported. Check the RuntimeServicesSupported variable using getVariable.
14/// getVariable is one of the functions that may not be supported.
15///
16/// Some functions may not be called while other functions are running.
17pub const RuntimeServices = extern struct {
18    hdr: TableHeader,
19
20    /// Returns the current time and date information, and the time-keeping capabilities of the hardware platform.
21    getTime: fn (*uefi.Time, ?*TimeCapabilities) callconv(.C) Status,
22
23    setTime: Status, // TODO
24    getWakeupTime: Status, // TODO
25    setWakeupTime: Status, // TODO
26
27    /// Changes the runtime addressing mode of EFI firmware from physical to virtual.
28    setVirtualAddressMap: fn (usize, usize, u32, [*]MemoryDescriptor) callconv(.C) Status,
29
30    /// Determines the new virtual address that is to be used on subsequent memory accesses.
31    convertPointer: fn (usize, **anyopaque) callconv(.C) Status,
32
33    /// Returns the value of a variable.
34    getVariable: fn ([*:0]const u16, *align(8) const Guid, ?*u32, *usize, ?*anyopaque) callconv(.C) Status,
35
36    /// Enumerates the current variable names.
37    getNextVariableName: fn (*usize, [*:0]u16, *align(8) Guid) callconv(.C) Status,
38
39    /// Sets the value of a variable.
40    setVariable: fn ([*:0]const u16, *align(8) const Guid, u32, usize, *anyopaque) callconv(.C) Status,
41
42    getNextHighMonotonicCount: Status, // TODO
43
44    /// Resets the entire platform.
45    resetSystem: fn (ResetType, Status, usize, ?*const anyopaque) callconv(.C) noreturn,
46
47    updateCapsule: Status, // TODO
48    queryCapsuleCapabilities: Status, // TODO
49    queryVariableInfo: Status, // TODO
50
51    pub const signature: u64 = 0x56524553544e5552;
52};
53
54pub const ResetType = enum(u32) {
55    ResetCold,
56    ResetWarm,
57    ResetShutdown,
58    ResetPlatformSpecific,
59};
60
61pub const global_variable align(8) = Guid{
62    .time_low = 0x8be4df61,
63    .time_mid = 0x93ca,
64    .time_high_and_version = 0x11d2,
65    .clock_seq_high_and_reserved = 0xaa,
66    .clock_seq_low = 0x0d,
67    .node = [_]u8{ 0x00, 0xe0, 0x98, 0x03, 0x2b, 0x8c },
68};
69