zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

blob b96881fc (8496B) - Raw


      1 // SPDX-License-Identifier: MIT
      2 // Copyright (c) 2015-2021 Zig Contributors
      3 // This file is part of [zig](https://ziglang.org/), which is MIT licensed.
      4 // The MIT license requires this copyright notice to be included in all copies
      5 // and substantial portions of the software.
      6 const uefi = @import("std").os.uefi;
      7 const Event = uefi.Event;
      8 const Guid = uefi.Guid;
      9 const Handle = uefi.Handle;
     10 const Status = uefi.Status;
     11 const TableHeader = uefi.tables.TableHeader;
     12 const DevicePathProtocol = uefi.protocols.DevicePathProtocol;
     13 
     14 /// Boot services are services provided by the system's firmware until the operating system takes
     15 /// over control over the hardware by calling exitBootServices.
     16 ///
     17 /// Boot Services must not be used after exitBootServices has been called. The only exception is
     18 /// getMemoryMap, which may be used after the first unsuccessful call to exitBootServices.
     19 /// After successfully calling exitBootServices, system_table.console_in_handle, system_table.con_in,
     20 /// system_table.console_out_handle, system_table.con_out, system_table.standard_error_handle,
     21 /// system_table.std_err, and system_table.boot_services should be set to null. After setting these
     22 /// attributes to null, system_table.hdr.crc32 must be recomputed.
     23 ///
     24 /// As the boot_services table may grow with new UEFI versions, it is important to check hdr.header_size.
     25 pub const BootServices = extern struct {
     26     hdr: TableHeader,
     27 
     28     /// Raises a task's priority level and returns its previous level.
     29     raiseTpl: fn (usize) callconv(.C) usize,
     30 
     31     /// Restores a task's priority level to its previous value.
     32     restoreTpl: fn (usize) callconv(.C) void,
     33 
     34     /// Allocates memory pages from the system.
     35     allocatePages: fn (AllocateType, MemoryType, usize, *[*]align(4096) u8) callconv(.C) Status,
     36 
     37     /// Frees memory pages.
     38     freePages: fn ([*]align(4096) u8, usize) callconv(.C) Status,
     39 
     40     /// Returns the current memory map.
     41     getMemoryMap: fn (*usize, [*]MemoryDescriptor, *usize, *usize, *u32) callconv(.C) Status,
     42 
     43     /// Allocates pool memory.
     44     allocatePool: fn (MemoryType, usize, *[*]align(8) u8) callconv(.C) Status,
     45 
     46     /// Returns pool memory to the system.
     47     freePool: fn ([*]align(8) u8) callconv(.C) Status,
     48 
     49     /// Creates an event.
     50     createEvent: fn (u32, usize, ?fn (Event, ?*c_void) callconv(.C) void, ?*const c_void, *Event) callconv(.C) Status,
     51 
     52     /// Sets the type of timer and the trigger time for a timer event.
     53     setTimer: fn (Event, TimerDelay, u64) callconv(.C) Status,
     54 
     55     /// Stops execution until an event is signaled.
     56     waitForEvent: fn (usize, [*]const Event, *usize) callconv(.C) Status,
     57 
     58     /// Signals an event.
     59     signalEvent: fn (Event) callconv(.C) Status,
     60 
     61     /// Closes an event.
     62     closeEvent: fn (Event) callconv(.C) Status,
     63 
     64     /// Checks whether an event is in the signaled state.
     65     checkEvent: fn (Event) callconv(.C) Status,
     66 
     67     installProtocolInterface: Status, // TODO
     68     reinstallProtocolInterface: Status, // TODO
     69     uninstallProtocolInterface: Status, // TODO
     70 
     71     /// Queries a handle to determine if it supports a specified protocol.
     72     handleProtocol: fn (Handle, *align(8) const Guid, *?*c_void) callconv(.C) Status,
     73 
     74     reserved: *c_void,
     75 
     76     registerProtocolNotify: Status, // TODO
     77 
     78     /// Returns an array of handles that support a specified protocol.
     79     locateHandle: fn (LocateSearchType, ?*align(8) const Guid, ?*const c_void, *usize, [*]Handle) callconv(.C) Status,
     80 
     81     locateDevicePath: Status, // TODO
     82     installConfigurationTable: Status, // TODO
     83 
     84     /// Loads an EFI image into memory.
     85     loadImage: fn (bool, Handle, ?*const DevicePathProtocol, ?[*]const u8, usize, *?Handle) callconv(.C) Status,
     86 
     87     /// Transfers control to a loaded image's entry point.
     88     startImage: fn (Handle, ?*usize, ?*[*]u16) callconv(.C) Status,
     89 
     90     /// Terminates a loaded EFI image and returns control to boot services.
     91     exit: fn (Handle, Status, usize, ?*const c_void) callconv(.C) Status,
     92 
     93     /// Unloads an image.
     94     unloadImage: fn (Handle) callconv(.C) Status,
     95 
     96     /// Terminates all boot services.
     97     exitBootServices: fn (Handle, usize) callconv(.C) Status,
     98 
     99     /// Returns a monotonically increasing count for the platform.
    100     getNextMonotonicCount: fn (*u64) callconv(.C) Status,
    101 
    102     /// Induces a fine-grained stall.
    103     stall: fn (usize) callconv(.C) Status,
    104 
    105     /// Sets the system's watchdog timer.
    106     setWatchdogTimer: fn (usize, u64, usize, ?[*]const u16) callconv(.C) Status,
    107 
    108     connectController: Status, // TODO
    109     disconnectController: Status, // TODO
    110 
    111     /// Queries a handle to determine if it supports a specified protocol.
    112     openProtocol: fn (Handle, *align(8) const Guid, *?*c_void, ?Handle, ?Handle, OpenProtocolAttributes) callconv(.C) Status,
    113 
    114     /// Closes a protocol on a handle that was opened using openProtocol().
    115     closeProtocol: fn (Handle, *align(8) const Guid, Handle, ?Handle) callconv(.C) Status,
    116 
    117     /// Retrieves the list of agents that currently have a protocol interface opened.
    118     openProtocolInformation: fn (Handle, *align(8) const Guid, *[*]ProtocolInformationEntry, *usize) callconv(.C) Status,
    119 
    120     /// Retrieves the list of protocol interface GUIDs that are installed on a handle in a buffer allocated from pool.
    121     protocolsPerHandle: fn (Handle, *[*]*align(8) const Guid, *usize) callconv(.C) Status,
    122 
    123     /// Returns an array of handles that support the requested protocol in a buffer allocated from pool.
    124     locateHandleBuffer: fn (LocateSearchType, ?*align(8) const Guid, ?*const c_void, *usize, *[*]Handle) callconv(.C) Status,
    125 
    126     /// Returns the first protocol instance that matches the given protocol.
    127     locateProtocol: fn (*align(8) const Guid, ?*const c_void, *?*c_void) callconv(.C) Status,
    128 
    129     installMultipleProtocolInterfaces: Status, // TODO
    130     uninstallMultipleProtocolInterfaces: Status, // TODO
    131 
    132     /// Computes and returns a 32-bit CRC for a data buffer.
    133     calculateCrc32: fn ([*]const u8, usize, *u32) callconv(.C) Status,
    134 
    135     /// Copies the contents of one buffer to another buffer
    136     copyMem: fn ([*]u8, [*]const u8, usize) callconv(.C) void,
    137 
    138     /// Fills a buffer with a specified value
    139     setMem: fn ([*]u8, usize, u8) callconv(.C) void,
    140 
    141     createEventEx: Status, // TODO
    142 
    143     pub const signature: u64 = 0x56524553544f4f42;
    144 
    145     pub const event_timer: u32 = 0x80000000;
    146     pub const event_runtime: u32 = 0x40000000;
    147     pub const event_notify_wait: u32 = 0x00000100;
    148     pub const event_notify_signal: u32 = 0x00000200;
    149     pub const event_signal_exit_boot_services: u32 = 0x00000201;
    150     pub const event_signal_virtual_address_change: u32 = 0x00000202;
    151 
    152     pub const tpl_application: usize = 4;
    153     pub const tpl_callback: usize = 8;
    154     pub const tpl_notify: usize = 16;
    155     pub const tpl_high_level: usize = 31;
    156 };
    157 
    158 pub const TimerDelay = extern enum(u32) {
    159     TimerCancel,
    160     TimerPeriodic,
    161     TimerRelative,
    162 };
    163 
    164 pub const MemoryType = extern enum(u32) {
    165     ReservedMemoryType,
    166     LoaderCode,
    167     LoaderData,
    168     BootServicesCode,
    169     BootServicesData,
    170     RuntimeServicesCode,
    171     RuntimeServicesData,
    172     ConventionalMemory,
    173     UnusableMemory,
    174     ACPIReclaimMemory,
    175     ACPIMemoryNVS,
    176     MemoryMappedIO,
    177     MemoryMappedIOPortSpace,
    178     PalCode,
    179     PersistentMemory,
    180     MaxMemoryType,
    181 };
    182 
    183 pub const MemoryDescriptor = extern struct {
    184     type: MemoryType,
    185     physical_start: u64,
    186     virtual_start: u64,
    187     number_of_pages: usize,
    188     attribute: packed struct {
    189         uc: bool,
    190         wc: bool,
    191         wt: bool,
    192         wb: bool,
    193         uce: bool,
    194         _pad1: u7,
    195         wp: bool,
    196         rp: bool,
    197         xp: bool,
    198         nv: bool,
    199         more_reliable: bool,
    200         ro: bool,
    201         sp: bool,
    202         cpu_crypto: bool,
    203         _pad2: u43,
    204         memory_runtime: bool,
    205     },
    206 };
    207 
    208 pub const LocateSearchType = extern enum(u32) {
    209     AllHandles,
    210     ByRegisterNotify,
    211     ByProtocol,
    212 };
    213 
    214 pub const OpenProtocolAttributes = packed struct {
    215     by_handle_protocol: bool = false,
    216     get_protocol: bool = false,
    217     test_protocol: bool = false,
    218     by_child_controller: bool = false,
    219     by_driver: bool = false,
    220     exclusive: bool = false,
    221     _pad: u26 = undefined,
    222 };
    223 
    224 pub const ProtocolInformationEntry = extern struct {
    225     agent_handle: ?Handle,
    226     controller_handle: ?Handle,
    227     attributes: OpenProtocolAttributes,
    228     open_count: u32,
    229 };
    230 
    231 pub const AllocateType = extern enum(u32) {
    232     AllocateAnyPages,
    233     AllocateMaxAddress,
    234     AllocateAddress,
    235 };