Skip to content
Standard libraryZig 0.17.1Official documentation
Sourcestd/os/uefi/tables.zig

Source line 1

std.os.uefi.tables.AllocateLocation

container

Source line 262

Fields

any
max_address: [*]align(4096) uefi.Page
address: [*]align(4096) uefi.Page

std.os.uefi.tables.AllocateType

container

Source line 268

Fields

any
max_address
address

std.os.uefi.tables.assert

alias

Source line 8

Alias of std.debug.assert

std.os.uefi.tables.BootServices

alias

Source line 10

Alias of std.os.uefi.tables.boot_services.BootServices

std.os.uefi.tables.CapsuleHeader

container

Source line 276

Fields

capsule_guid: Guid
header_size: u32
flags: u32
capsule_image_size: u32

std.os.uefi.tables.cc

alias

Source line 6

Alias of std.os.uefi.cc

std.os.uefi.tables.ConfigurationTable

alias

Source line 12

Alias of std.os.uefi.tables.configuration_table.ConfigurationTable

std.os.uefi.tables.Event

alias

Source line 4

Alias of std.os.uefi.Event

std.os.uefi.tables.EventNotify

type

Source line 16

std.os.uefi.tables.global_variable

constant

Source line 298

std.os.uefi.tables.Guid

alias

Source line 5

Alias of std.os.uefi.Guid

std.os.uefi.tables.Handle

alias

Source line 3

Alias of std.os.uefi.Handle

std.os.uefi.tables.InterfaceType

container

Source line 258

Fields

native

std.os.uefi.tables.LocateSearch

container

Source line 178

Fields

all_handles
by_register_notify: uefi.EventRegistration
by_protocol: *const Guid

std.os.uefi.tables.LocateSearchType

container

Source line 172

Fields

all_handles
by_register_notify
by_protocol

std.os.uefi.tables.math

alias

Source line 7

Alias of std.math

std.os.uefi.tables.MemoryDescriptor

container

Source line 126

Fields

type: MemoryType
physical_start: u64
virtual_start: u64
number_of_pages: u64
attribute: MemoryDescriptorAttribute

std.os.uefi.tables.MemoryDescriptorAttribute

container

Source line 105

Fields

uc: bool
wc: bool
wt: bool
wb: bool
uce: bool
_pad1: u7 = 0
wp: bool
rp: bool
xp: bool
nv: bool
more_reliable: bool
ro: bool
sp: bool
cpu_crypto: bool
_pad2: u43 = 0
memory_runtime: bool

std.os.uefi.tables.MemoryDescriptorIterator

container

Source line 161

Fields

ctx: MemoryMapSlice
index: usize = 0

std.os.uefi.tables.MemoryDescriptorIterator.next

function

Source line 165

pub fn next(self: *MemoryDescriptorIterator) ?*MemoryDescriptor

Parameters

std.os.uefi.tables.MemoryMapInfo

container

Source line 134

Fields

key: MemoryMapKey
descriptor_size: usize
descriptor_version: u32
len: usize

The number of descriptors in the map.

std.os.uefi.tables.MemoryMapKey

container

Source line 124

Fields

_

std.os.uefi.tables.MemoryMapSlice

container

Source line 142

Fields

info: MemoryMapInfo
ptr: [*]align(@alignOf(MemoryDescriptor)) u8

std.os.uefi.tables.MemoryMapSlice.get

function

Source line 150

pub fn get(self: MemoryMapSlice, index: usize) ?*MemoryDescriptor

Parameters

self: MemoryMapSlice
index: usize

std.os.uefi.tables.MemoryMapSlice.getUnchecked

function

Source line 155

pub fn getUnchecked(self: MemoryMapSlice, index: usize) *MemoryDescriptor

Parameters

self: MemoryMapSlice
index: usize

std.os.uefi.tables.MemoryMapSlice.iterator

function

Source line 146

pub fn iterator(self: MemoryMapSlice) MemoryDescriptorIterator

Parameters

std.os.uefi.tables.MemoryType

container

Source line 24

Fields

reserved_memory_type

can only be allocated using .allocate_any_pages mode unless you are explicitly targeting an interface that states otherwise

loader_code
loader_data
boot_services_code
boot_services_data
runtime_services_code

can only be allocated using .allocate_any_pages mode unless you are explicitly targeting an interface that states otherwise

runtime_services_data

can only be allocated using .allocate_any_pages mode unless you are explicitly targeting an interface that states otherwise

conventional_memory
unusable_memory
acpi_reclaim_memory

can only be allocated using .allocate_any_pages mode unless you are explicitly targeting an interface that states otherwise

acpi_memory_nvs

can only be allocated using .allocate_any_pages mode unless you are explicitly targeting an interface that states otherwise

memory_mapped_io
memory_mapped_io_port_space
pal_code
persistent_memory
unaccepted_memory
max_memory_type
invalid_start
invalid_end = 0x6FFFFFFF
oem_start = 0x70000000

MemoryType values in the range 0x70000000..0x7FFFFFFF are reserved for OEM use.

oem_end = 0x7FFFFFFF
vendor_start = 0x80000000

MemoryType values in the range 0x80000000..0xFFFFFFFF are reserved for use by UEFI OS loaders that are provided by operating system vendors.

vendor_end = 0xFFFFFFFF
_

std.os.uefi.tables.MemoryType.format

function

Source line 93

pub fn format(self: MemoryType, w: *std.Io.Writer) std.Io.Writer.Error!void

Parameters

self: MemoryType
w: *std.Io.Writer

Errors

WriteFailed

See the Writer implementation for detailed diagnostics.

std.os.uefi.tables.MemoryType.fromOem

function

Source line 67

pub fn fromOem(value: Oem) MemoryType

Parameters

value: Oem

std.os.uefi.tables.MemoryType.fromVendor

function

Source line 80

pub fn fromVendor(value: Vendor) MemoryType

Parameters

value: Vendor

std.os.uefi.tables.MemoryType.Oem

type

Source line 25

std.os.uefi.tables.MemoryType.toOem

function

Source line 72

pub fn toOem(memtype: MemoryType) ?Oem

Parameters

memtype: MemoryType

std.os.uefi.tables.MemoryType.toVendor

function

Source line 85

pub fn toVendor(memtype: MemoryType) ?Vendor

Parameters

memtype: MemoryType

std.os.uefi.tables.MemoryType.Vendor

type

Source line 29

std.os.uefi.tables.OpenProtocolArgs

container

Source line 213

Fields

by_handle_protocol: struct { agent: ?Handle = null, controller: ?Handle = null }

Used in the implementation of handleProtocol.

get_protocol: struct { agent: ?Handle = null, controller: ?Handle = null }

Used by a driver to get a protocol interface from a handle. Care must be taken when using this open mode because the driver that opens a protocol interface in this manner will not be informed if the protocol interface is uninstalled or reinstalled. The caller is also not required to close the protocol interface with closeProtocol.

test_protocol: struct { agent: ?Handle = null, controller: ?Handle = null }

Used by a driver to test for the existence of a protocol interface on a handle. The caller only use the return status code. The caller is also not required to close the protocol interface with closeProtocol.

by_child_controller: struct { agent: Handle, controller: Handle }

Used by bus drivers to show that a protocol interface is being used by one of the child controllers of a bus. This information is used by BootServices.connectController to recursively connect all child controllers and by BootServices.disconnectController to get the list of child controllers that a bus driver created.

by_driver: struct { agent: Handle, controller: Handle }

Used by a driver to gain access to a protocol interface. When this mode is used, the driver’s Stop() function will be called by BootServices.disconnectController if the protocol interface is reinstalled or uninstalled. Once a protocol interface is opened by a driver with this attribute, no other drivers will be allowed to open the same protocol interface with the .by_driver attribute.

by_driver_exclusive: struct { agent: Handle, controller: Handle }

Used by a driver to gain exclusive access to a protocol interface. If any other drivers have the protocol interface opened with an attribute of .by_driver, then an attempt will be made to remove them with BootServices.disconnectController.

exclusive: struct { agent: Handle, controller: ?Handle = null }

Used by applications to gain exclusive access to a protocol interface. If any drivers have the protocol interface opened with an attribute of .by_driver, then an attempt will be made to remove them by calling the driver’s Stop() function.

std.os.uefi.tables.OpenProtocolAttributes

container

Source line 184

Fields

by_handle_protocol = @bitCast(Bits{ .by_handle_protocol = true })
get_protocol = @bitCast(Bits{ .get_protocol = true })
test_protocol = @bitCast(Bits{ .test_protocol = true })
by_child_controller = @bitCast(Bits{ .by_child_controller = true })
by_driver = @bitCast(Bits{ .by_driver = true })
by_driver_exclusive = @bitCast(Bits{ .by_driver = true, .exclusive = true })
exclusive = @bitCast(Bits{ .exclusive = true })
_

std.os.uefi.tables.OpenProtocolAttributes.Bits

container

Source line 185

Fields

by_handle_protocol: bool = false
get_protocol: bool = false
test_protocol: bool = false
by_child_controller: bool = false
by_driver: bool = false
exclusive: bool = false
reserved: u26 = 0

std.os.uefi.tables.OpenProtocolAttributes.fromBits

function

Source line 204

pub fn fromBits(bits: Bits) OpenProtocolAttributes

Parameters

bits: Bits

std.os.uefi.tables.OpenProtocolAttributes.toBits

function

Source line 208

pub fn toBits(self: OpenProtocolAttributes) Bits

Parameters

std.os.uefi.tables.PhysicalAddress

type

Source line 274

std.os.uefi.tables.ProtocolInformationEntry

container

Source line 251

Fields

agent_handle: ?Handle
controller_handle: ?Handle
attributes: OpenProtocolAttributes
open_count: u32

std.os.uefi.tables.ResetType

container

Source line 291

Fields

cold
warm
shutdown
platform_specific

std.os.uefi.tables.RuntimeServices

alias

Source line 11

Alias of std.os.uefi.tables.runtime_services.RuntimeServices

std.os.uefi.tables.std

alias

Source line 1

Alias of std

std.os.uefi.tables.SystemTable

alias

Source line 13

Alias of std.os.uefi.tables.system_table.SystemTable

std.os.uefi.tables.TableHeader

alias

Source line 14

Alias of std.os.uefi.tables.table_header.TableHeader

std.os.uefi.tables.TimerDelay

container

Source line 18

Fields

cancel
periodic
relative

std.os.uefi.tables.uefi

alias

Source line 2

Alias of std.os.uefi

std.os.uefi.tables.UefiCapsuleBlockDescriptor

container

Source line 283

Fields

length: u64
address: extern union {
    data_block: PhysicalAddress,
    continuation_pointer: PhysicalAddress,
}
Source code

std/os/uefi/tables.zig

const std = @import("std");
const uefi = std.os.uefi;
const Handle = uefi.Handle;
const Event = uefi.Event;
const Guid = uefi.Guid;
const cc = uefi.cc;
const math = std.math;
const assert = std.debug.assert;

pub const BootServices = @import("tables/boot_services.zig").BootServices;
pub const RuntimeServices = @import("tables/runtime_services.zig").RuntimeServices;
pub const ConfigurationTable = @import("tables/configuration_table.zig").ConfigurationTable;
pub const SystemTable = @import("tables/system_table.zig").SystemTable;
pub const TableHeader = @import("tables/table_header.zig").TableHeader;

pub const EventNotify = *const fn (event: Event, ctx: *anyopaque) callconv(cc) void;

pub const TimerDelay = enum(u32) {
    cancel,
    periodic,
    relative,
};

pub const MemoryType = enum(u32) {
    pub const Oem = math.IntFittingRange(
        0,
        @backingInt(MemoryType.oem_end) - @backingInt(MemoryType.oem_start),
    );
    pub const Vendor = math.IntFittingRange(
        0,
        @backingInt(MemoryType.vendor_end) - @backingInt(MemoryType.vendor_start),
    );

    /// can only be allocated using .allocate_any_pages mode unless you are explicitly targeting an interface that states otherwise
    reserved_memory_type,
    loader_code,
    loader_data,
    boot_services_code,
    boot_services_data,
    /// can only be allocated using .allocate_any_pages mode unless you are explicitly targeting an interface that states otherwise
    runtime_services_code,
    /// can only be allocated using .allocate_any_pages mode unless you are explicitly targeting an interface that states otherwise
    runtime_services_data,
    conventional_memory,
    unusable_memory,
    /// can only be allocated using .allocate_any_pages mode unless you are explicitly targeting an interface that states otherwise
    acpi_reclaim_memory,
    /// can only be allocated using .allocate_any_pages mode unless you are explicitly targeting an interface that states otherwise
    acpi_memory_nvs,
    memory_mapped_io,
    memory_mapped_io_port_space,
    pal_code,
    persistent_memory,
    unaccepted_memory,
    max_memory_type,
    invalid_start,
    invalid_end = 0x6FFFFFFF,
    /// MemoryType values in the range 0x70000000..0x7FFFFFFF are reserved for OEM use.
    oem_start = 0x70000000,
    oem_end = 0x7FFFFFFF,
    /// MemoryType values in the range 0x80000000..0xFFFFFFFF are reserved for use by UEFI
    /// OS loaders that are provided by operating system vendors.
    vendor_start = 0x80000000,
    vendor_end = 0xFFFFFFFF,
    _,

    pub fn fromOem(value: Oem) MemoryType {
        const oem_start = @backingInt(MemoryType.oem_start);
        return @fromBackingInt(@intCast(oem_start + value));
    }

    pub fn toOem(memtype: MemoryType) ?Oem {
        const as_int = @backingInt(memtype);
        const oem_start = @backingInt(MemoryType.oem_start);
        if (as_int < oem_start) return null;
        if (as_int > @backingInt(MemoryType.oem_end)) return null;
        return @truncate(as_int - oem_start);
    }

    pub fn fromVendor(value: Vendor) MemoryType {
        const vendor_start = @backingInt(MemoryType.vendor_start);
        return @fromBackingInt(@intCast(vendor_start + value));
    }

    pub fn toVendor(memtype: MemoryType) ?Vendor {
        const as_int = @backingInt(memtype);
        const vendor_start = @backingInt(MemoryType.vendor_start);
        if (as_int < @backingInt(MemoryType.vendor_end)) return null;
        if (as_int > @backingInt(MemoryType.vendor_end)) return null;
        return @truncate(as_int - vendor_start);
    }

    pub fn format(self: MemoryType, w: *std.Io.Writer) std.Io.Writer.Error!void {
        if (self.toOem()) |oemval|
            try w.print("OEM({X})", .{oemval})
        else if (self.toVendor()) |vendorval|
            try w.print("Vendor({X})", .{vendorval})
        else if (std.enums.tagName(MemoryType, self)) |name|
            try w.print("{s}", .{name})
        else
            try w.print("INVALID({X})", .{@backingInt(self)});
    }
};

pub const MemoryDescriptorAttribute = packed struct(u64) {
    uc: bool,
    wc: bool,
    wt: bool,
    wb: bool,
    uce: bool,
    _pad1: u7 = 0,
    wp: bool,
    rp: bool,
    xp: bool,
    nv: bool,
    more_reliable: bool,
    ro: bool,
    sp: bool,
    cpu_crypto: bool,
    _pad2: u43 = 0,
    memory_runtime: bool,
};

pub const MemoryMapKey = enum(usize) { _ };

pub const MemoryDescriptor = extern struct {
    type: MemoryType,
    physical_start: u64,
    virtual_start: u64,
    number_of_pages: u64,
    attribute: MemoryDescriptorAttribute,
};

pub const MemoryMapInfo = struct {
    key: MemoryMapKey,
    descriptor_size: usize,
    descriptor_version: u32,
    /// The number of descriptors in the map.
    len: usize,
};

pub const MemoryMapSlice = struct {
    info: MemoryMapInfo,
    ptr: [*]align(@alignOf(MemoryDescriptor)) u8,

    pub fn iterator(self: MemoryMapSlice) MemoryDescriptorIterator {
        return .{ .ctx = self };
    }

    pub fn get(self: MemoryMapSlice, index: usize) ?*MemoryDescriptor {
        if (index >= self.info.len) return null;
        return self.getUnchecked(index);
    }

    pub fn getUnchecked(self: MemoryMapSlice, index: usize) *MemoryDescriptor {
        const offset: usize = index * self.info.descriptor_size;
        return @ptrCast(@alignCast(self.ptr[offset..]));
    }
};

pub const MemoryDescriptorIterator = struct {
    ctx: MemoryMapSlice,
    index: usize = 0,

    pub fn next(self: *MemoryDescriptorIterator) ?*MemoryDescriptor {
        const md = self.ctx.get(self.index) orelse return null;
        self.index += 1;
        return md;
    }
};

pub const LocateSearchType = enum(u32) {
    all_handles,
    by_register_notify,
    by_protocol,
};

pub const LocateSearch = union(LocateSearchType) {
    all_handles,
    by_register_notify: uefi.EventRegistration,
    by_protocol: *const Guid,
};

pub const OpenProtocolAttributes = enum(u32) {
    pub const Bits = packed struct(u32) {
        by_handle_protocol: bool = false,
        get_protocol: bool = false,
        test_protocol: bool = false,
        by_child_controller: bool = false,
        by_driver: bool = false,
        exclusive: bool = false,
        reserved: u26 = 0,
    };

    by_handle_protocol = @bitCast(Bits{ .by_handle_protocol = true }),
    get_protocol = @bitCast(Bits{ .get_protocol = true }),
    test_protocol = @bitCast(Bits{ .test_protocol = true }),
    by_child_controller = @bitCast(Bits{ .by_child_controller = true }),
    by_driver = @bitCast(Bits{ .by_driver = true }),
    by_driver_exclusive = @bitCast(Bits{ .by_driver = true, .exclusive = true }),
    exclusive = @bitCast(Bits{ .exclusive = true }),
    _,

    pub fn fromBits(bits: Bits) OpenProtocolAttributes {
        return @bitCast(bits);
    }

    pub fn toBits(self: OpenProtocolAttributes) Bits {
        return @bitCast(self);
    }
};

pub const OpenProtocolArgs = union(OpenProtocolAttributes) {
    /// Used in the implementation of `handleProtocol`.
    by_handle_protocol: struct { agent: ?Handle = null, controller: ?Handle = null },
    /// Used by a driver to get a protocol interface from a handle. Care must be
    /// taken when using this open mode because the driver that opens a protocol
    /// interface in this manner will not be informed if the protocol interface
    /// is uninstalled or reinstalled. The caller is also not required to close
    /// the protocol interface with `closeProtocol`.
    get_protocol: struct { agent: ?Handle = null, controller: ?Handle = null },
    /// Used by a driver to test for the existence of a protocol interface on a
    /// handle. The caller only use the return status code. The caller is also
    /// not required to close the protocol interface with `closeProtocol`.
    test_protocol: struct { agent: ?Handle = null, controller: ?Handle = null },
    /// Used by bus drivers to show that a protocol interface is being used by one
    /// of the child controllers of a bus. This information is used by
    /// `BootServices.connectController` to recursively connect all child controllers
    /// and by `BootServices.disconnectController` to get the list of child
    /// controllers that a bus driver created.
    by_child_controller: struct { agent: Handle, controller: Handle },
    /// Used by a driver to gain access to a protocol interface. When this mode
    /// is used, the driver’s Stop() function will be called by
    /// `BootServices.disconnectController` if the protocol interface is reinstalled
    /// or uninstalled. Once a protocol interface is opened by a driver with this
    /// attribute, no other drivers will be allowed to open the same protocol interface
    /// with the `.by_driver` attribute.
    by_driver: struct { agent: Handle, controller: Handle },
    /// Used by a driver to gain exclusive access to a protocol interface. If any
    /// other drivers have the protocol interface opened with an attribute of
    /// `.by_driver`, then an attempt will be made to remove them with
    /// `BootServices.disconnectController`.
    by_driver_exclusive: struct { agent: Handle, controller: Handle },
    /// Used by applications to gain exclusive access to a protocol interface. If
    /// any drivers have the protocol interface opened with an attribute of
    /// `.by_driver`, then an attempt will be made to remove them by calling the
    /// driver’s Stop() function.
    exclusive: struct { agent: Handle, controller: ?Handle = null },
};

pub const ProtocolInformationEntry = extern struct {
    agent_handle: ?Handle,
    controller_handle: ?Handle,
    attributes: OpenProtocolAttributes,
    open_count: u32,
};

pub const InterfaceType = enum(u32) {
    native,
};

pub const AllocateLocation = union(AllocateType) {
    any,
    max_address: [*]align(4096) uefi.Page,
    address: [*]align(4096) uefi.Page,
};

pub const AllocateType = enum(u32) {
    any,
    max_address,
    address,
};

pub const PhysicalAddress = u64;

pub const CapsuleHeader = extern struct {
    capsule_guid: Guid,
    header_size: u32,
    flags: u32,
    capsule_image_size: u32,
};

pub const UefiCapsuleBlockDescriptor = extern struct {
    length: u64,
    address: extern union {
        data_block: PhysicalAddress,
        continuation_pointer: PhysicalAddress,
    },
};

pub const ResetType = enum(u32) {
    cold,
    warm,
    shutdown,
    platform_specific,
};

pub const global_variable = Guid{
    .time_low = 0x8be4df61,
    .time_mid = 0x93ca,
    .time_high_and_version = 0x11d2,
    .clock_seq_high_and_reserved = 0xaa,
    .clock_seq_low = 0x0d,
    .node = [_]u8{ 0x00, 0xe0, 0x98, 0x03, 0x2b, 0x8c },
};

test {
    std.testing.refAllDecls(@This());
}