authorgravatar for carmen@dotcarmen.devCarmen <carmen@dotcarmen.dev> 2025-04-01 03:47:51-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2025-04-01 10:47:51+00:00
logfa86e09fb39c8007c7b63e70ed7db1afc7022476
treede1aeccdded0b5fc25a791b50af469f9bd1e967c
parentb636d56d6a71b9ed521de7fccb519b7d0fa3db90
signaturebadge-check Signed by PGP key B5690EEEBB952194

std.os.uefi.protocol: ziggify function signatures (#23214)


27 files changed, 2075 insertions(+), 469 deletions(-)

lib/std/debug.zig+3-3
......@@ -629,9 +629,9 @@ pub fn defaultPanic(
629629 // isn't visible on actual hardware if directly booted into
630630 inline for ([_]?*uefi.protocol.SimpleTextOutput{ uefi.system_table.std_err, uefi.system_table.con_out }) |o| {
631631 if (o) |out| {
632 _ = out.setAttribute(uefi.protocol.SimpleTextOutput.red);
633 _ = out.outputString(exit_msg);
634 _ = out.setAttribute(uefi.protocol.SimpleTextOutput.white);
632 out.setAttribute(.{ .foreground = .red }) catch {};
633 _ = out.outputString(exit_msg) catch {};
634 out.setAttribute(.{ .foreground = .white }) catch {};
635635 }
636636 }
637637
lib/std/os/uefi.zig+13-53
......@@ -43,6 +43,11 @@ pub const Ipv6Address = extern struct {
4343 address: [16]u8,
4444};
4545
46pub const IpAddress = extern union {
47 v4: Ipv4Address,
48 v6: Ipv6Address,
49};
50
4651/// GUIDs are align(8) unless otherwise specified.
4752pub const Guid = extern struct {
4853 time_low: u32,
......@@ -190,60 +195,15 @@ test "GUID formatting" {
190195 try std.testing.expect(std.mem.eql(u8, str, "32cb3c89-8080-427c-ba13-5049873bc287"));
191196}
192197
193pub const FileInfo = extern struct {
194 size: u64,
195 file_size: u64,
196 physical_size: u64,
197 create_time: Time,
198 last_access_time: Time,
199 modification_time: Time,
200 attribute: u64,
201
202 pub fn getFileName(self: *const FileInfo) [*:0]const u16 {
203 return @ptrCast(@alignCast(@as([*]const u8, @ptrCast(self)) + @sizeOf(FileInfo)));
204 }
205
206 pub const efi_file_read_only: u64 = 0x0000000000000001;
207 pub const efi_file_hidden: u64 = 0x0000000000000002;
208 pub const efi_file_system: u64 = 0x0000000000000004;
209 pub const efi_file_reserved: u64 = 0x0000000000000008;
210 pub const efi_file_directory: u64 = 0x0000000000000010;
211 pub const efi_file_archive: u64 = 0x0000000000000020;
212 pub const efi_file_valid_attr: u64 = 0x0000000000000037;
213
214 pub const guid align(8) = Guid{
215 .time_low = 0x09576e92,
216 .time_mid = 0x6d3f,
217 .time_high_and_version = 0x11d2,
218 .clock_seq_high_and_reserved = 0x8e,
219 .clock_seq_low = 0x39,
220 .node = [_]u8{ 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b },
221 };
222};
223
224pub const FileSystemInfo = extern struct {
225 size: u64,
226 read_only: bool,
227 volume_size: u64,
228 free_space: u64,
229 block_size: u32,
230 _volume_label: u16,
231
232 pub fn getVolumeLabel(self: *const FileSystemInfo) [*:0]const u16 {
233 return @as([*:0]const u16, @ptrCast(&self._volume_label));
234 }
235
236 pub const guid align(8) = Guid{
237 .time_low = 0x09576e93,
238 .time_mid = 0x6d3f,
239 .time_high_and_version = 0x11d2,
240 .clock_seq_high_and_reserved = 0x8e,
241 .clock_seq_low = 0x39,
242 .node = [_]u8{ 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b },
243 };
244};
245
246198test {
247199 _ = tables;
248200 _ = protocol;
249201}
202
203pub const UnexpectedError = error{Unexpected};
204
205pub fn unexpectedStatus(status: Status) UnexpectedError {
206 // TODO: debug printing the encountered error? maybe handle warnings?
207 _ = status;
208 return error.Unexpected;
209}
lib/std/os/uefi/protocol.zig+21-2
......@@ -1,3 +1,8 @@
1const std = @import("std");
2const uefi = std.os.uefi;
3
4pub const ServiceBinding = @import("protocol/service_binding.zig").ServiceBinding;
5
16pub const LoadedImage = @import("protocol/loaded_image.zig").LoadedImage;
27pub const DevicePath = @import("protocol/device_path.zig").DevicePath;
38pub const Rng = @import("protocol/rng.zig").Rng;
......@@ -23,11 +28,25 @@ pub const edid = @import("protocol/edid.zig");
2328pub const SimpleNetwork = @import("protocol/simple_network.zig").SimpleNetwork;
2429pub const ManagedNetwork = @import("protocol/managed_network.zig").ManagedNetwork;
2530
26pub const Ip6ServiceBinding = @import("protocol/ip6_service_binding.zig").Ip6ServiceBinding;
31pub const Ip6ServiceBinding = ServiceBinding(.{
32 .time_low = 0xec835dd3,
33 .time_mid = 0xfe0f,
34 .time_high_and_version = 0x617b,
35 .clock_seq_high_and_reserved = 0xa6,
36 .clock_seq_low = 0x21,
37 .node = [_]u8{ 0xb3, 0x50, 0xc3, 0xe1, 0x33, 0x88 },
38});
2739pub const Ip6 = @import("protocol/ip6.zig").Ip6;
2840pub const Ip6Config = @import("protocol/ip6_config.zig").Ip6Config;
2941
30pub const Udp6ServiceBinding = @import("protocol/udp6_service_binding.zig").Udp6ServiceBinding;
42pub const Udp6ServiceBinding = ServiceBinding(.{
43 .time_low = 0x66ed4721,
44 .time_mid = 0x3c98,
45 .time_high_and_version = 0x4d3e,
46 .clock_seq_high_and_reserved = 0x81,
47 .clock_seq_low = 0xe3,
48 .node = [_]u8{ 0xd0, 0x3d, 0xd3, 0x9a, 0x72, 0x54 },
49});
3150pub const Udp6 = @import("protocol/udp6.zig").Udp6;
3251
3352pub const HiiDatabase = @import("protocol/hii_database.zig").HiiDatabase;
lib/std/os/uefi/protocol/absolute_pointer.zig+19-5
......@@ -4,22 +4,36 @@ const Event = uefi.Event;
44const Guid = uefi.Guid;
55const Status = uefi.Status;
66const cc = uefi.cc;
7const Error = Status.Error;
78
89/// Protocol for touchscreens.
910pub const AbsolutePointer = extern struct {
10 _reset: *const fn (*const AbsolutePointer, bool) callconv(cc) Status,
11 _reset: *const fn (*AbsolutePointer, bool) callconv(cc) Status,
1112 _get_state: *const fn (*const AbsolutePointer, *State) callconv(cc) Status,
1213 wait_for_input: Event,
1314 mode: *Mode,
1415
16 pub const ResetError = uefi.UnexpectedError || error{DeviceError};
17 pub const GetStateError = uefi.UnexpectedError || error{ NotReady, DeviceError };
18
1519 /// Resets the pointer device hardware.
16 pub fn reset(self: *const AbsolutePointer, verify: bool) Status {
17 return self._reset(self, verify);
20 pub fn reset(self: *AbsolutePointer, verify: bool) ResetError!void {
21 switch (self._reset(self, verify)) {
22 .success => {},
23 .device_error => return Error.DeviceError,
24 else => |status| return uefi.unexpectedStatus(status),
25 }
1826 }
1927
2028 /// Retrieves the current state of a pointer device.
21 pub fn getState(self: *const AbsolutePointer, state: *State) Status {
22 return self._get_state(self, state);
29 pub fn getState(self: *const AbsolutePointer) GetStateError!State {
30 var state: State = undefined;
31 switch (self._get_state(self, &state)) {
32 .success => return state,
33 .not_ready => return Error.NotReady,
34 .device_error => return Error.DeviceError,
35 else => |status| return uefi.unexpectedStatus(status),
36 }
2337 }
2438
2539 pub const guid align(8) = Guid{
lib/std/os/uefi/protocol/block_io.zig+55-9
......@@ -2,6 +2,7 @@ const std = @import("std");
22const uefi = std.os.uefi;
33const Status = uefi.Status;
44const cc = uefi.cc;
5const Error = Status.Error;
56
67pub const BlockIo = extern struct {
78 const Self = @This();
......@@ -11,27 +12,72 @@ pub const BlockIo = extern struct {
1112
1213 _reset: *const fn (*BlockIo, extended_verification: bool) callconv(cc) Status,
1314 _read_blocks: *const fn (*BlockIo, media_id: u32, lba: u64, buffer_size: usize, buf: [*]u8) callconv(cc) Status,
14 _write_blocks: *const fn (*BlockIo, media_id: u32, lba: u64, buffer_size: usize, buf: [*]u8) callconv(cc) Status,
15 _write_blocks: *const fn (*BlockIo, media_id: u32, lba: u64, buffer_size: usize, buf: [*]const u8) callconv(cc) Status,
1516 _flush_blocks: *const fn (*BlockIo) callconv(cc) Status,
1617
18 pub const ResetError = uefi.UnexpectedError || error{DeviceError};
19 pub const ReadBlocksError = uefi.UnexpectedError || error{
20 DeviceError,
21 NoMedia,
22 BadBufferSize,
23 InvalidParameter,
24 };
25 pub const WriteBlocksError = uefi.UnexpectedError || error{
26 WriteProtected,
27 NoMedia,
28 MediaChanged,
29 DeviceError,
30 BadBufferSize,
31 InvalidParameter,
32 };
33 pub const FlushBlocksError = uefi.UnexpectedError || error{
34 DeviceError,
35 NoMedia,
36 };
37
1738 /// Resets the block device hardware.
18 pub fn reset(self: *Self, extended_verification: bool) Status {
19 return self._reset(self, extended_verification);
39 pub fn reset(self: *Self, extended_verification: bool) ResetError!void {
40 switch (self._reset(self, extended_verification)) {
41 .success => {},
42 .device_error => return Error.DeviceError,
43 else => |status| return uefi.unexpectedStatus(status),
44 }
2045 }
2146
2247 /// Reads the number of requested blocks from the device.
23 pub fn readBlocks(self: *Self, media_id: u32, lba: u64, buffer_size: usize, buf: [*]u8) Status {
24 return self._read_blocks(self, media_id, lba, buffer_size, buf);
48 pub fn readBlocks(self: *Self, media_id: u32, lba: u64, buf: []u8) ReadBlocksError!void {
49 switch (self._read_blocks(self, media_id, lba, buf.len, buf.ptr)) {
50 .success => {},
51 .device_error => return Error.DeviceError,
52 .no_media => return Error.NoMedia,
53 .bad_buffer_size => return Error.BadBufferSize,
54 .invalid_parameter => return Error.InvalidParameter,
55 else => |status| return uefi.unexpectedStatus(status),
56 }
2557 }
2658
2759 /// Writes a specified number of blocks to the device.
28 pub fn writeBlocks(self: *Self, media_id: u32, lba: u64, buffer_size: usize, buf: [*]u8) Status {
29 return self._write_blocks(self, media_id, lba, buffer_size, buf);
60 pub fn writeBlocks(self: *Self, media_id: u32, lba: u64, buf: []const u8) WriteBlocksError!void {
61 switch (self._write_blocks(self, media_id, lba, buf.len, buf.ptr)) {
62 .success => {},
63 .write_protected => return Error.WriteProtected,
64 .no_media => return Error.NoMedia,
65 .media_changed => return Error.MediaChanged,
66 .device_error => return Error.DeviceError,
67 .bad_buffer_size => return Error.BadBufferSize,
68 .invalid_parameter => return Error.InvalidParameter,
69 else => |status| return uefi.unexpectedStatus(status),
70 }
3071 }
3172
3273 /// Flushes all modified data to a physical block device.
33 pub fn flushBlocks(self: *Self) Status {
34 return self._flush_blocks(self);
74 pub fn flushBlocks(self: *Self) FlushBlocksError!void {
75 switch (self._flush_blocks(self)) {
76 .success => {},
77 .device_error => return Error.DeviceError,
78 .no_media => return Error.NoMedia,
79 else => |status| return uefi.unexpectedStatus(status),
80 }
3581 }
3682
3783 pub const guid align(8) = uefi.Guid{
lib/std/os/uefi/protocol/device_path.zig+14-6
......@@ -13,6 +13,8 @@ pub const DevicePath = extern struct {
1313 subtype: u8,
1414 length: u16 align(1),
1515
16 pub const CreateFileDevicePathError = Allocator.Error;
17
1618 pub const guid align(8) = Guid{
1719 .time_low = 0x09576e91,
1820 .time_mid = 0x6d3f,
......@@ -23,15 +25,17 @@ pub const DevicePath = extern struct {
2325 };
2426
2527 /// Returns the next DevicePath node in the sequence, if any.
26 pub fn next(self: *DevicePath) ?*DevicePath {
27 if (self.type == .end and @as(uefi.DevicePath.End.Subtype, @enumFromInt(self.subtype)) == .end_entire)
28 pub fn next(self: *const DevicePath) ?*const DevicePath {
29 const bytes: [*]const u8 = @ptrCast(self);
30 const next_node: *const DevicePath = @ptrCast(bytes + self.length);
31 if (next_node.type == .end and @as(uefi.DevicePath.End.Subtype, @enumFromInt(self.subtype)) == .end_entire)
2832 return null;
2933
30 return @as(*DevicePath, @ptrCast(@as([*]u8, @ptrCast(self)) + self.length));
34 return next_node;
3135 }
3236
3337 /// Calculates the total length of the device path structure in bytes, including the end of device path node.
34 pub fn size(self: *DevicePath) usize {
38 pub fn size(self: *const DevicePath) usize {
3539 var node = self;
3640
3741 while (node.next()) |next_node| {
......@@ -42,7 +46,11 @@ pub const DevicePath = extern struct {
4246 }
4347
4448 /// Creates a file device path from the existing device path and a file path.
45 pub fn create_file_device_path(self: *DevicePath, allocator: Allocator, path: [:0]align(1) const u16) !*DevicePath {
49 pub fn createFileDevicePath(
50 self: *const DevicePath,
51 allocator: Allocator,
52 path: []const u16,
53 ) CreateFileDevicePathError!*const DevicePath {
4654 const path_size = self.size();
4755
4856 // 2 * (path.len + 1) for the path and its null terminator, which are u16s
......@@ -67,7 +75,7 @@ pub const DevicePath = extern struct {
6775
6876 ptr[path.len] = 0;
6977
70 var end = @as(*uefi.DevicePath.End.EndEntireDevicePath, @ptrCast(@as(*DevicePath, @ptrCast(new)).next().?));
78 var end = @as(*uefi.DevicePath.End.EndEntireDevicePath, @ptrCast(@constCast(@as(*DevicePath, @ptrCast(new)).next().?)));
7179 end.type = .end;
7280 end.subtype = .end_entire;
7381 end.length = @sizeOf(uefi.DevicePath.End.EndEntireDevicePath);
lib/std/os/uefi/protocol/edid.zig+25-9
......@@ -4,6 +4,7 @@ const Guid = uefi.Guid;
44const Handle = uefi.Handle;
55const Status = uefi.Status;
66const cc = uefi.cc;
7const Error = Status.Error;
78
89/// EDID information for an active video output device
910pub const Active = extern struct {
......@@ -37,17 +38,27 @@ pub const Discovered = extern struct {
3738
3839/// Override EDID information
3940pub const Override = extern struct {
40 _get_edid: *const fn (*const Override, Handle, *Attributes, *usize, *?[*]u8) callconv(cc) Status,
41 _get_edid: *const fn (*const Override, *const Handle, *Attributes, *usize, *?[*]u8) callconv(cc) Status,
42
43 pub const GetEdidError = uefi.UnexpectedError || error{
44 Unsupported,
45 };
4146
4247 /// Returns policy information and potentially a replacement EDID for the specified video output device.
43 pub fn getEdid(
44 self: *const Override,
45 handle: Handle,
46 attributes: *Attributes,
47 edid_size: *usize,
48 edid: *?[*]u8,
49 ) Status {
50 return self._get_edid(self, handle, attributes, edid_size, edid);
48 pub fn getEdid(self: *const Override, handle: Handle) GetEdidError!Edid {
49 var size: usize = undefined;
50 var ptr: ?[*]u8 = undefined;
51 var attributes: Attributes = undefined;
52 switch (self._get_edid(self, &handle, &attributes, &size, &ptr)) {
53 .success => {},
54 .unsupported => return Error.Unsupported,
55 else => |status| return uefi.unexpectedStatus(status),
56 }
57
58 return .{
59 .attributes = attributes,
60 .edid = if (ptr) |p| p[0..size] else null,
61 };
5162 }
5263
5364 pub const guid align(8) = Guid{
......@@ -59,6 +70,11 @@ pub const Override = extern struct {
5970 .node = [_]u8{ 0xf4, 0x58, 0xfe, 0x04, 0x0b, 0xd5 },
6071 };
6172
73 pub const Edid = struct {
74 attributes: Attributes,
75 edid: ?[]u8,
76 };
77
6278 pub const Attributes = packed struct(u32) {
6379 dont_override: bool,
6480 enable_hot_plug: bool,
lib/std/os/uefi/protocol/file.zig+301-84
......@@ -5,28 +5,89 @@ const Guid = uefi.Guid;
55const Time = uefi.Time;
66const Status = uefi.Status;
77const cc = uefi.cc;
8const Error = Status.Error;
89
910pub const File = extern struct {
1011 revision: u64,
11 _open: *const fn (*const File, **const File, [*:0]const u16, u64, u64) callconv(cc) Status,
12 _close: *const fn (*const File) callconv(cc) Status,
13 _delete: *const fn (*const File) callconv(cc) Status,
14 _read: *const fn (*const File, *usize, [*]u8) callconv(cc) Status,
15 _write: *const fn (*const File, *usize, [*]const u8) callconv(cc) Status,
12 _open: *const fn (*const File, **File, [*:0]const u16, u64, u64) callconv(cc) Status,
13 _close: *const fn (*File) callconv(cc) Status,
14 _delete: *const fn (*File) callconv(cc) Status,
15 _read: *const fn (*File, *usize, [*]u8) callconv(cc) Status,
16 _write: *const fn (*File, *usize, [*]const u8) callconv(cc) Status,
1617 _get_position: *const fn (*const File, *u64) callconv(cc) Status,
17 _set_position: *const fn (*const File, u64) callconv(cc) Status,
18 _set_position: *const fn (*File, u64) callconv(cc) Status,
1819 _get_info: *const fn (*const File, *align(8) const Guid, *const usize, [*]u8) callconv(cc) Status,
19 _set_info: *const fn (*const File, *align(8) const Guid, usize, [*]const u8) callconv(cc) Status,
20 _flush: *const fn (*const File) callconv(cc) Status,
20 _set_info: *const fn (*File, *align(8) const Guid, usize, [*]const u8) callconv(cc) Status,
21 _flush: *const fn (*File) callconv(cc) Status,
2122
22 pub const SeekError = error{SeekError};
23 pub const GetSeekPosError = error{GetSeekPosError};
24 pub const ReadError = error{ReadError};
25 pub const WriteError = error{WriteError};
23 pub const OpenError = uefi.UnexpectedError || error{
24 NotFound,
25 NoMedia,
26 MediaChanged,
27 DeviceError,
28 VolumeCorrupted,
29 WriteProtected,
30 AccessDenied,
31 OutOfResources,
32 VolumeFull,
33 InvalidParameter,
34 };
35 pub const CloseError = uefi.UnexpectedError;
36 pub const SeekError = uefi.UnexpectedError || error{
37 Unsupported,
38 DeviceError,
39 };
40 pub const ReadError = uefi.UnexpectedError || error{
41 NoMedia,
42 DeviceError,
43 VolumeCorrupted,
44 BufferTooSmall,
45 };
46 pub const WriteError = uefi.UnexpectedError || error{
47 Unsupported,
48 NoMedia,
49 DeviceError,
50 VolumeCorrupted,
51 WriteProtected,
52 AccessDenied,
53 VolumeFull,
54 };
55 pub const GetInfoError = uefi.UnexpectedError || error{
56 Unsupported,
57 NoMedia,
58 DeviceError,
59 VolumeCorrupted,
60 BufferTooSmall,
61 };
62 pub const SetInfoError = uefi.UnexpectedError || error{
63 Unsupported,
64 NoMedia,
65 DeviceError,
66 VolumeCorrupted,
67 WriteProtected,
68 AccessDenied,
69 VolumeFull,
70 BadBufferSize,
71 };
72 pub const FlushError = uefi.UnexpectedError || error{
73 DeviceError,
74 VolumeCorrupted,
75 WriteProtected,
76 AccessDenied,
77 VolumeFull,
78 };
2679
27 pub const SeekableStream = io.SeekableStream(*const File, SeekError, GetSeekPosError, seekTo, seekBy, getPos, getEndPos);
28 pub const Reader = io.Reader(*const File, ReadError, readFn);
29 pub const Writer = io.Writer(*const File, WriteError, writeFn);
80 pub const SeekableStream = io.SeekableStream(
81 *File,
82 SeekError,
83 SeekError,
84 setPosition,
85 seekBy,
86 getPosition,
87 getEndPos,
88 );
89 pub const Reader = io.Reader(*File, ReadError, read);
90 pub const Writer = io.Writer(*File, WriteError, write);
3091
3192 pub fn seekableStream(self: *File) SeekableStream {
3293 return .{ .context = self };
......@@ -40,75 +101,111 @@ pub const File = extern struct {
40101 return .{ .context = self };
41102 }
42103
43 pub fn open(self: *const File, new_handle: **const File, file_name: [*:0]const u16, open_mode: u64, attributes: u64) Status {
44 return self._open(self, new_handle, file_name, open_mode, attributes);
45 }
46
47 pub fn close(self: *const File) Status {
48 return self._close(self);
104 pub fn open(
105 self: *const File,
106 file_name: [*:0]const u16,
107 mode: OpenMode,
108 create_attributes: Attributes,
109 ) OpenError!*File {
110 var new: *File = undefined;
111 switch (self._open(
112 self,
113 &new,
114 file_name,
115 @intFromEnum(mode),
116 @bitCast(create_attributes),
117 )) {
118 .success => return new,
119 .not_found => return Error.NotFound,
120 .no_media => return Error.NoMedia,
121 .media_changed => return Error.MediaChanged,
122 .device_error => return Error.DeviceError,
123 .volume_corrupted => return Error.VolumeCorrupted,
124 .write_protected => return Error.WriteProtected,
125 .access_denied => return Error.AccessDenied,
126 .out_of_resources => return Error.OutOfResources,
127 .volume_full => return Error.VolumeFull,
128 .invalid_parameter => return Error.InvalidParameter,
129 else => |status| return uefi.unexpectedStatus(status),
130 }
49131 }
50132
51 pub fn delete(self: *const File) Status {
52 return self._delete(self);
133 pub fn close(self: *File) CloseError!void {
134 switch (self._close(self)) {
135 .success => {},
136 else => |status| return uefi.unexpectedStatus(status),
137 }
53138 }
54139
55 pub fn read(self: *const File, buffer_size: *usize, buffer: [*]u8) Status {
56 return self._read(self, buffer_size, buffer);
140 /// Delete the file.
141 ///
142 /// Returns true if the file was deleted, false if the file was not deleted, which is a warning
143 /// according to the UEFI specification.
144 pub fn delete(self: *File) uefi.UnexpectedError!bool {
145 switch (self._delete(self)) {
146 .success => return true,
147 .warn_delete_failure => return false,
148 else => |status| return uefi.unexpectedStatus(status),
149 }
57150 }
58151
59 fn readFn(self: *const File, buffer: []u8) ReadError!usize {
152 pub fn read(self: *File, buffer: []u8) ReadError!usize {
60153 var size: usize = buffer.len;
61 if (.success != self.read(&size, buffer.ptr)) return ReadError.ReadError;
62 return size;
63 }
64
65 pub fn write(self: *const File, buffer_size: *usize, buffer: [*]const u8) Status {
66 return self._write(self, buffer_size, buffer);
67 }
68
69 fn writeFn(self: *const File, bytes: []const u8) WriteError!usize {
70 var size: usize = bytes.len;
71 if (.success != self.write(&size, bytes.ptr)) return WriteError.WriteError;
72 return size;
154 switch (self._read(self, &size, buffer.ptr)) {
155 .success => return size,
156 .no_media => return Error.NoMedia,
157 .device_error => return Error.DeviceError,
158 .volume_corrupted => return Error.VolumeCorrupted,
159 .buffer_too_small => return Error.BufferTooSmall,
160 else => |status| return uefi.unexpectedStatus(status),
161 }
73162 }
74163
75 pub fn getPosition(self: *const File, position: *u64) Status {
76 return self._get_position(self, position);
164 pub fn write(self: *File, buffer: []const u8) WriteError!usize {
165 var size: usize = buffer.len;
166 switch (self._write(self, &size, buffer.ptr)) {
167 .success => return size,
168 .unsupported => return Error.Unsupported,
169 .no_media => return Error.NoMedia,
170 .device_error => return Error.DeviceError,
171 .volume_corrupted => return Error.VolumeCorrupted,
172 .write_protected => return Error.WriteProtected,
173 .access_denied => return Error.AccessDenied,
174 .volume_full => return Error.VolumeFull,
175 else => |status| return uefi.unexpectedStatus(status),
176 }
77177 }
78178
79 fn getPos(self: *const File) GetSeekPosError!u64 {
80 var pos: u64 = undefined;
81 if (.success != self.getPosition(&pos)) return GetSeekPosError.GetSeekPosError;
82 return pos;
179 pub fn getPosition(self: *const File) SeekError!u64 {
180 var position: u64 = undefined;
181 switch (self._get_position(self, &position)) {
182 .success => return position,
183 .unsupported => return Error.Unsupported,
184 .device_error => return Error.DeviceError,
185 else => |status| return uefi.unexpectedStatus(status),
186 }
83187 }
84188
85 fn getEndPos(self: *const File) GetSeekPosError!u64 {
86 // preserve the old file position
87 var pos: u64 = undefined;
88 var end_pos: u64 = undefined;
89 if (.success != self.getPosition(&pos)) return GetSeekPosError.GetSeekPosError;
90 // seek to end of file to get position = file size
91 if (.success != self.setPosition(efi_file_position_end_of_file)) return GetSeekPosError.GetSeekPosError;
92 // get the position
93 if (.success != self.getPosition(&end_pos)) return GetSeekPosError.GetSeekPosError;
94 // restore the old position
95 if (.success != self.setPosition(pos)) return GetSeekPosError.GetSeekPosError;
96 // return the file size = position
97 return end_pos;
98 }
189 fn getEndPos(self: *File) SeekError!u64 {
190 const start_pos = try self.getPosition();
191 // ignore error
192 defer self.setPosition(start_pos) catch {};
99193
100 pub fn setPosition(self: *const File, position: u64) Status {
101 return self._set_position(self, position);
194 try self.setPosition(end_of_file);
195 return self.getPosition();
102196 }
103197
104 fn seekTo(self: *const File, pos: u64) SeekError!void {
105 if (.success != self.setPosition(pos)) return SeekError.SeekError;
198 pub fn setPosition(self: *File, position: u64) SeekError!void {
199 switch (self._set_position(self, position)) {
200 .success => {},
201 .unsupported => return Error.Unsupported,
202 .device_error => return Error.DeviceError,
203 else => |status| return uefi.unexpectedStatus(status),
204 }
106205 }
107206
108 fn seekBy(self: *const File, offset: i64) SeekError!void {
109 // save the old position and calculate the delta
110 var pos: u64 = undefined;
111 if (.success != self.getPosition(&pos)) return SeekError.SeekError;
207 fn seekBy(self: *File, offset: i64) SeekError!void {
208 var pos = try self.getPosition();
112209 const seek_back = offset < 0;
113210 const amt = @abs(offset);
114211 if (seek_back) {
......@@ -116,32 +213,152 @@ pub const File = extern struct {
116213 } else {
117214 pos -= amt;
118215 }
119 if (.success != self.setPosition(pos)) return SeekError.SeekError;
216 try self.setPosition(pos);
120217 }
121218
122 pub fn getInfo(self: *const File, information_type: *align(8) const Guid, buffer_size: *usize, buffer: [*]u8) Status {
123 return self._get_info(self, information_type, buffer_size, buffer);
219 pub fn getInfo(
220 self: *const File,
221 comptime info: std.meta.Tag(Info),
222 ) GetInfoError!std.meta.TagPayload(Info, info) {
223 const InfoType = std.meta.TagPayload(Info, info);
224
225 var val: InfoType = undefined;
226 var len: usize = @sizeOf(InfoType);
227 switch (self._get_info(self, &InfoType.guid, &len, @ptrCast(&val))) {
228 .success => return val,
229 .unsupported => return Error.Unsupported,
230 .no_media => return Error.NoMedia,
231 .device_error => return Error.DeviceError,
232 .volume_corrupted => return Error.VolumeCorrupted,
233 .buffer_too_small => return Error.BufferTooSmall,
234 else => |status| return uefi.unexpectedStatus(status),
235 }
124236 }
125237
126 pub fn setInfo(self: *const File, information_type: *align(8) const Guid, buffer_size: usize, buffer: [*]const u8) Status {
127 return self._set_info(self, information_type, buffer_size, buffer);
238 pub fn setInfo(
239 self: *File,
240 comptime info: std.meta.Tag(Info),
241 data: *const std.meta.TagPayload(Info, info),
242 ) SetInfoError!void {
243 const InfoType = @TypeOf(data);
244 switch (self._set_info(self, &InfoType.guid, @sizeOf(InfoType), @ptrCast(data))) {
245 .success => {},
246 .unsupported => return Error.Unsupported,
247 .no_media => return Error.NoMedia,
248 .device_error => return Error.DeviceError,
249 .volume_corrupted => return Error.VolumeCorrupted,
250 .write_protected => return Error.WriteProtected,
251 .access_denied => return Error.AccessDenied,
252 .volume_full => return Error.VolumeFull,
253 .bad_buffer_size => return Error.BadBufferSize,
254 else => |status| return uefi.unexpectedStatus(status),
255 }
128256 }
129257
130 pub fn flush(self: *const File) Status {
131 return self._flush(self);
258 pub fn flush(self: *File) FlushError!void {
259 switch (self._flush(self)) {
260 .success => {},
261 .device_error => return Error.DeviceError,
262 .volume_corrupted => return Error.VolumeCorrupted,
263 .write_protected => return Error.WriteProtected,
264 .access_denied => return Error.AccessDenied,
265 .volume_full => return Error.VolumeFull,
266 else => |status| return uefi.unexpectedStatus(status),
267 }
132268 }
133269
134 pub const efi_file_mode_read: u64 = 0x0000000000000001;
135 pub const efi_file_mode_write: u64 = 0x0000000000000002;
136 pub const efi_file_mode_create: u64 = 0x8000000000000000;
270 pub const OpenMode = enum(u64) {
271 read = 0x0000000000000001,
272 // implies read
273 write = 0x0000000000000002,
274 // implies read+write
275 create = 0x8000000000000000,
276 };
277
278 pub const Attributes = packed struct(u64) {
279 // 0x0000000000000001
280 read_only: bool = false,
281 // 0x0000000000000002
282 hidden: bool = false,
283 // 0x0000000000000004
284 system: bool = false,
285 // 0x0000000000000008
286 reserved: bool = false,
287 // 0x0000000000000010
288 directory: bool = false,
289 // 0x0000000000000020
290 archive: bool = false,
291 _pad: u58 = 0,
292 };
293
294 pub const Info = union(enum) {
295 file: Info.File,
296 file_system: FileSystem,
297 volume_label: VolumeLabel,
298
299 pub const File = extern struct {
300 size: u64,
301 file_size: u64,
302 physical_size: u64,
303 create_time: Time,
304 last_access_time: Time,
305 modification_time: Time,
306 attribute: Attributes,
307 _file_name: u16,
308
309 pub fn getFileName(self: *const Info.File) [*:0]const u16 {
310 return @as([*:0]const u16, @ptrCast(&self._file_name));
311 }
312
313 pub const guid align(8) = Guid{
314 .time_low = 0x09576e92,
315 .time_mid = 0x6d3f,
316 .time_high_and_version = 0x11d2,
317 .clock_seq_high_and_reserved = 0x8e,
318 .clock_seq_low = 0x39,
319 .node = [_]u8{ 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b },
320 };
321 };
322
323 pub const FileSystem = extern struct {
324 size: u64,
325 read_only: bool,
326 volume_size: u64,
327 free_space: u64,
328 block_size: u32,
329 _volume_label: u16,
330
331 pub fn getVolumeLabel(self: *const FileSystem) [*:0]const u16 {
332 return @as([*:0]const u16, @ptrCast(&self._volume_label));
333 }
334
335 pub const guid align(8) = Guid{
336 .time_low = 0x09576e93,
337 .time_mid = 0x6d3f,
338 .time_high_and_version = 0x11d2,
339 .clock_seq_high_and_reserved = 0x8e,
340 .clock_seq_low = 0x39,
341 .node = [_]u8{ 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b },
342 };
343 };
344
345 pub const VolumeLabel = extern struct {
346 _volume_label: u16,
347
348 pub fn getVolumeLabel(self: *const VolumeLabel) [*:0]const u16 {
349 return @as([*:0]const u16, @ptrCast(&self._volume_label));
350 }
137351
138 pub const efi_file_read_only: u64 = 0x0000000000000001;
139 pub const efi_file_hidden: u64 = 0x0000000000000002;
140 pub const efi_file_system: u64 = 0x0000000000000004;
141 pub const efi_file_reserved: u64 = 0x0000000000000008;
142 pub const efi_file_directory: u64 = 0x0000000000000010;
143 pub const efi_file_archive: u64 = 0x0000000000000020;
144 pub const efi_file_valid_attr: u64 = 0x0000000000000037;
352 pub const guid align(8) = Guid{
353 .time_low = 0xdb47d7d3,
354 .time_mid = 0xfe81,
355 .time_high_and_version = 0x11d3,
356 .clock_seq_high_and_reserved = 0x9a,
357 .clock_seq_low = 0x35,
358 .node = [_]u8{ 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d },
359 };
360 };
361 };
145362
146 pub const efi_file_position_end_of_file: u64 = 0xffffffffffffffff;
363 const end_of_file: u64 = 0xffffffffffffffff;
147364};
lib/std/os/uefi/protocol/graphics_output.zig+61-8
......@@ -3,26 +3,79 @@ const uefi = std.os.uefi;
33const Guid = uefi.Guid;
44const Status = uefi.Status;
55const cc = uefi.cc;
6const Error = Status.Error;
67
78pub const GraphicsOutput = extern struct {
89 _query_mode: *const fn (*const GraphicsOutput, u32, *usize, **Mode.Info) callconv(cc) Status,
9 _set_mode: *const fn (*const GraphicsOutput, u32) callconv(cc) Status,
10 _blt: *const fn (*const GraphicsOutput, ?[*]BltPixel, BltOperation, usize, usize, usize, usize, usize, usize, usize) callconv(cc) Status,
10 _set_mode: *const fn (*GraphicsOutput, u32) callconv(cc) Status,
11 _blt: *const fn (*GraphicsOutput, ?[*]BltPixel, BltOperation, usize, usize, usize, usize, usize, usize, usize) callconv(cc) Status,
1112 mode: *Mode,
1213
14 pub const QueryModeError = uefi.UnexpectedError || error{
15 DeviceError,
16 InvalidParameter,
17 };
18 pub const SetModeError = uefi.UnexpectedError || error{
19 DeviceError,
20 Unsupported,
21 };
22 pub const BltError = uefi.UnexpectedError || error{
23 InvalidParameter,
24 DeviceError,
25 };
26
1327 /// Returns information for an available graphics mode that the graphics device and the set of active video output devices supports.
14 pub fn queryMode(self: *const GraphicsOutput, mode: u32, size_of_info: *usize, info: **Mode.Info) Status {
15 return self._query_mode(self, mode, size_of_info, info);
28 pub fn queryMode(self: *const GraphicsOutput, mode_id: u32) QueryModeError!*Mode.Info {
29 var size_of_info: usize = undefined;
30 var info: *Mode.Info = undefined;
31 switch (self._query_mode(self, mode_id, &size_of_info, &info)) {
32 .success => return info,
33 .device_error => return Error.DeviceError,
34 .invalid_parameter => return Error.InvalidParameter,
35 else => |status| return uefi.unexpectedStatus(status),
36 }
1637 }
1738
1839 /// Set the video device into the specified mode and clears the visible portions of the output display to black.
19 pub fn setMode(self: *const GraphicsOutput, mode: u32) Status {
20 return self._set_mode(self, mode);
40 pub fn setMode(self: *GraphicsOutput, mode_id: u32) SetModeError!void {
41 switch (self._set_mode(self, mode_id)) {
42 .success => {},
43 .device_error => return Error.DeviceError,
44 .unsupported => return Error.Unsupported,
45 else => |status| return uefi.unexpectedStatus(status),
46 }
2147 }
2248
2349 /// Blt a rectangle of pixels on the graphics screen. Blt stands for BLock Transfer.
24 pub fn blt(self: *const GraphicsOutput, blt_buffer: ?[*]BltPixel, blt_operation: BltOperation, source_x: usize, source_y: usize, destination_x: usize, destination_y: usize, width: usize, height: usize, delta: usize) Status {
25 return self._blt(self, blt_buffer, blt_operation, source_x, source_y, destination_x, destination_y, width, height, delta);
50 pub fn blt(
51 self: *GraphicsOutput,
52 blt_buffer: ?[*]BltPixel,
53 blt_operation: BltOperation,
54 source_x: usize,
55 source_y: usize,
56 destination_x: usize,
57 destination_y: usize,
58 width: usize,
59 height: usize,
60 delta: usize,
61 ) BltError!void {
62 switch (self._blt(
63 self,
64 blt_buffer,
65 blt_operation,
66 source_x,
67 source_y,
68 destination_x,
69 destination_y,
70 width,
71 height,
72 delta,
73 )) {
74 .success => {},
75 .device_error => return Error.DeviceError,
76 .invalid_parameter => return Error.InvalidParameter,
77 else => |status| return uefi.unexpectedStatus(status),
78 }
2679 }
2780
2881 pub const guid align(8) = Guid{
lib/std/os/uefi/protocol/hii_database.zig+72-11
......@@ -4,14 +4,15 @@ const Guid = uefi.Guid;
44const Status = uefi.Status;
55const hii = uefi.hii;
66const cc = uefi.cc;
7const Error = Status.Error;
78
89/// Database manager for HII-related data structures.
910pub const HiiDatabase = extern struct {
1011 _new_package_list: Status, // TODO
11 _remove_package_list: *const fn (*const HiiDatabase, hii.Handle) callconv(cc) Status,
12 _update_package_list: *const fn (*const HiiDatabase, hii.Handle, *const hii.PackageList) callconv(cc) Status,
12 _remove_package_list: *const fn (*HiiDatabase, hii.Handle) callconv(cc) Status,
13 _update_package_list: *const fn (*HiiDatabase, hii.Handle, *const hii.PackageList) callconv(cc) Status,
1314 _list_package_lists: *const fn (*const HiiDatabase, u8, ?*const Guid, *usize, [*]hii.Handle) callconv(cc) Status,
14 _export_package_lists: *const fn (*const HiiDatabase, ?hii.Handle, *usize, *hii.PackageList) callconv(cc) Status,
15 _export_package_lists: *const fn (*const HiiDatabase, ?hii.Handle, *usize, [*]hii.PackageList) callconv(cc) Status,
1516 _register_package_notify: Status, // TODO
1617 _unregister_package_notify: Status, // TODO
1718 _find_keyboard_layouts: Status, // TODO
......@@ -19,24 +20,84 @@ pub const HiiDatabase = extern struct {
1920 _set_keyboard_layout: Status, // TODO
2021 _get_package_list_handle: Status, // TODO
2122
23 pub const RemovePackageListError = uefi.UnexpectedError || error{NotFound};
24 pub const UpdatePackageListError = uefi.UnexpectedError || error{
25 OutOfResources,
26 InvalidParameter,
27 NotFound,
28 };
29 pub const ListPackageListsError = uefi.UnexpectedError || error{
30 BufferTooSmall,
31 InvalidParameter,
32 NotFound,
33 };
34 pub const ExportPackageListError = uefi.UnexpectedError || error{
35 BufferTooSmall,
36 InvalidParameter,
37 NotFound,
38 };
39
2240 /// Removes a package list from the HII database.
23 pub fn removePackageList(self: *const HiiDatabase, handle: hii.Handle) Status {
24 return self._remove_package_list(self, handle);
41 pub fn removePackageList(self: *HiiDatabase, handle: hii.Handle) !void {
42 switch (self._remove_package_list(self, handle)) {
43 .success => {},
44 .not_found => return Error.NotFound,
45 else => |status| return uefi.unexpectedStatus(status),
46 }
2547 }
2648
2749 /// Update a package list in the HII database.
28 pub fn updatePackageList(self: *const HiiDatabase, handle: hii.Handle, buffer: *const hii.PackageList) Status {
29 return self._update_package_list(self, handle, buffer);
50 pub fn updatePackageList(
51 self: *HiiDatabase,
52 handle: hii.Handle,
53 buffer: *const hii.PackageList,
54 ) UpdatePackageListError!void {
55 switch (self._update_package_list(self, handle, buffer)) {
56 .success => {},
57 .out_of_resources => return Error.OutOfResources,
58 .invalid_parameter => return Error.InvalidParameter,
59 .not_found => return Error.NotFound,
60 else => |status| return uefi.unexpectedStatus(status),
61 }
3062 }
3163
3264 /// Determines the handles that are currently active in the database.
33 pub fn listPackageLists(self: *const HiiDatabase, package_type: u8, package_guid: ?*const Guid, buffer_length: *usize, handles: [*]hii.Handle) Status {
34 return self._list_package_lists(self, package_type, package_guid, buffer_length, handles);
65 pub fn listPackageLists(
66 self: *const HiiDatabase,
67 package_type: u8,
68 package_guid: ?*const Guid,
69 handles: []hii.Handle,
70 ) ListPackageListsError![]hii.Handle {
71 var len: usize = handles.len;
72 switch (self._list_package_lists(
73 self,
74 package_type,
75 package_guid,
76 &len,
77 handles.ptr,
78 )) {
79 .success => return handles[0..len],
80 .buffer_too_small => return Error.BufferTooSmall,
81 .invalid_parameter => return Error.InvalidParameter,
82 .not_found => return Error.NotFound,
83 else => |status| return uefi.unexpectedStatus(status),
84 }
3585 }
3686
3787 /// Exports the contents of one or all package lists in the HII database into a buffer.
38 pub fn exportPackageLists(self: *const HiiDatabase, handle: ?hii.Handle, buffer_size: *usize, buffer: *hii.PackageList) Status {
39 return self._export_package_lists(self, handle, buffer_size, buffer);
88 pub fn exportPackageLists(
89 self: *const HiiDatabase,
90 handle: ?hii.Handle,
91 buffer: []hii.PackageList,
92 ) ExportPackageListError![]hii.PackageList {
93 var len = buffer.len;
94 switch (self._export_package_lists(self, handle, &len, buffer.ptr)) {
95 .success => return buffer[0..len],
96 .buffer_too_small => return Error.BufferTooSmall,
97 .invalid_parameter => return Error.InvalidParameter,
98 .not_found => return Error.NotFound,
99 else => |status| return uefi.unexpectedStatus(status),
100 }
40101 }
41102
42103 pub const guid align(8) = Guid{
lib/std/os/uefi/protocol/hii_popup.zig+20-2
......@@ -4,15 +4,33 @@ const Guid = uefi.Guid;
44const Status = uefi.Status;
55const hii = uefi.hii;
66const cc = uefi.cc;
7const Error = Status.Error;
78
89/// Display a popup window
910pub const HiiPopup = extern struct {
1011 revision: u64,
1112 _create_popup: *const fn (*const HiiPopup, PopupStyle, PopupType, hii.Handle, u16, ?*PopupSelection) callconv(cc) Status,
1213
14 pub const CreatePopupError = uefi.UnexpectedError || error{
15 InvalidParameter,
16 OutOfResources,
17 };
18
1319 /// Displays a popup window.
14 pub fn createPopup(self: *const HiiPopup, style: PopupStyle, popup_type: PopupType, handle: hii.Handle, msg: u16, user_selection: ?*PopupSelection) Status {
15 return self._create_popup(self, style, popup_type, handle, msg, user_selection);
20 pub fn createPopup(
21 self: *const HiiPopup,
22 style: PopupStyle,
23 popup_type: PopupType,
24 handle: hii.Handle,
25 msg: u16,
26 ) CreatePopupError!PopupSelection {
27 var res: PopupSelection = undefined;
28 switch (self._create_popup(self, style, popup_type, handle, msg, &res)) {
29 .success => return res,
30 .invalid_parameter => return Error.InvalidParameter,
31 .out_of_resources => return Error.OutOfResources,
32 else => |status| return uefi.unexpectedStatus(status),
33 }
1634 }
1735
1836 pub const guid align(8) = Guid{
lib/std/os/uefi/protocol/ip6.zig+265-26
......@@ -7,61 +7,290 @@ const MacAddress = uefi.MacAddress;
77const ManagedNetworkConfigData = uefi.protocol.ManagedNetwork.Config;
88const SimpleNetwork = uefi.protocol.SimpleNetwork;
99const cc = uefi.cc;
10const Error = Status.Error;
1011
1112pub const Ip6 = extern struct {
1213 _get_mode_data: *const fn (*const Ip6, ?*Mode, ?*ManagedNetworkConfigData, ?*SimpleNetwork) callconv(cc) Status,
13 _configure: *const fn (*const Ip6, ?*const Config) callconv(cc) Status,
14 _groups: *const fn (*const Ip6, bool, ?*const Address) callconv(cc) Status,
15 _routes: *const fn (*const Ip6, bool, ?*const Address, u8, ?*const Address) callconv(cc) Status,
16 _neighbors: *const fn (*const Ip6, bool, *const Address, ?*const MacAddress, u32, bool) callconv(cc) Status,
17 _transmit: *const fn (*const Ip6, *CompletionToken) callconv(cc) Status,
18 _receive: *const fn (*const Ip6, *CompletionToken) callconv(cc) Status,
19 _cancel: *const fn (*const Ip6, ?*CompletionToken) callconv(cc) Status,
20 _poll: *const fn (*const Ip6) callconv(cc) Status,
14 _configure: *const fn (*Ip6, ?*const Config) callconv(cc) Status,
15 _groups: *const fn (*Ip6, bool, ?*const Address) callconv(cc) Status,
16 _routes: *const fn (*Ip6, bool, ?*const Address, u8, ?*const Address) callconv(cc) Status,
17 _neighbors: *const fn (*Ip6, bool, *const Address, ?*const MacAddress, u32, bool) callconv(cc) Status,
18 _transmit: *const fn (*Ip6, *CompletionToken) callconv(cc) Status,
19 _receive: *const fn (*Ip6, *CompletionToken) callconv(cc) Status,
20 _cancel: *const fn (*Ip6, ?*CompletionToken) callconv(cc) Status,
21 _poll: *const fn (*Ip6) callconv(cc) Status,
22
23 pub const GetModeDataError = uefi.UnexpectedError || error{
24 InvalidParameter,
25 OutOfResources,
26 };
27 pub const ConfigureError = uefi.UnexpectedError || error{
28 InvalidParameter,
29 OutOfResources,
30 NoMapping,
31 AlreadyStarted,
32 DeviceError,
33 Unsupported,
34 };
35 pub const GroupsError = uefi.UnexpectedError || error{
36 InvalidParameter,
37 NotStarted,
38 OutOfResources,
39 Unsupported,
40 AlreadyStarted,
41 NotFound,
42 DeviceError,
43 };
44 pub const RoutesError = uefi.UnexpectedError || error{
45 NotStarted,
46 InvalidParameter,
47 OutOfResources,
48 NotFound,
49 AccessDenied,
50 };
51 pub const NeighborsError = uefi.UnexpectedError || error{
52 NotStarted,
53 InvalidParameter,
54 OutOfResources,
55 NotFound,
56 AccessDenied,
57 };
58 pub const TransmitError = uefi.UnexpectedError || error{
59 NotStarted,
60 NoMapping,
61 InvalidParameter,
62 AccessDenied,
63 NotReady,
64 NotFound,
65 OutOfResources,
66 BufferTooSmall,
67 BadBufferSize,
68 DeviceError,
69 NoMedia,
70 };
71 pub const ReceiveError = uefi.UnexpectedError || error{
72 NotStarted,
73 NoMapping,
74 InvalidParameter,
75 OutOfResources,
76 DeviceError,
77 AccessDenied,
78 NotReady,
79 NoMedia,
80 };
81 pub const CancelError = uefi.UnexpectedError || error{
82 InvalidParameter,
83 NotStarted,
84 NotFound,
85 DeviceError,
86 };
87 pub const PollError = uefi.UnexpectedError || error{
88 NotStarted,
89 InvalidParameter,
90 DeviceError,
91 Timeout,
92 };
93
94 pub const ModeData = struct {
95 ip6_mode: Mode,
96 mnp_config: ManagedNetworkConfigData,
97 snp_mode: SimpleNetwork,
98 };
2199
22100 /// Gets the current operational settings for this instance of the EFI IPv6 Protocol driver.
23 pub fn getModeData(self: *const Ip6, ip6_mode_data: ?*Mode, mnp_config_data: ?*ManagedNetworkConfigData, snp_mode_data: ?*SimpleNetwork) Status {
24 return self._get_mode_data(self, ip6_mode_data, mnp_config_data, snp_mode_data);
101 pub fn getModeData(self: *const Ip6) GetModeDataError!ModeData {
102 var data: ModeData = undefined;
103 switch (self._get_mode_data(self, &data.ip6_mode, &data.mnp_config, &data.snp_mode)) {
104 .success => return data,
105 .invalid_parameter => return Error.InvalidParameter,
106 .out_of_resources => return Error.OutOfResources,
107 else => |status| return uefi.unexpectedStatus(status),
108 }
25109 }
26110
27111 /// Assign IPv6 address and other configuration parameter to this EFI IPv6 Protocol driver instance.
28 pub fn configure(self: *const Ip6, ip6_config_data: ?*const Config) Status {
29 return self._configure(self, ip6_config_data);
112 ///
113 /// To reset the configuration, use `disable` instead.
114 pub fn configure(self: *Ip6, ip6_config_data: *const Config) ConfigureError!void {
115 switch (self._configure(self, ip6_config_data)) {
116 .success => {},
117 .invalid_parameter => return Error.InvalidParameter,
118 .out_of_resources => return Error.OutOfResources,
119 .no_mapping => return Error.NoMapping,
120 .already_started => return Error.AlreadyStarted,
121 .device_error => return Error.DeviceError,
122 .unsupported => return Error.Unsupported,
123 else => |status| return uefi.unexpectedStatus(status),
124 }
125 }
126
127 pub fn disable(self: *Ip6) ConfigureError!void {
128 switch (self._configure(self, null)) {
129 .success => {},
130 .invalid_parameter => return Error.InvalidParameter,
131 .out_of_resources => return Error.OutOfResources,
132 .no_mapping => return Error.NoMapping,
133 .already_started => return Error.AlreadyStarted,
134 .device_error => return Error.DeviceError,
135 .unsupported => return Error.Unsupported,
136 else => |status| return uefi.unexpectedStatus(status),
137 }
138 }
139
140 pub fn leaveAllGroups(self: *Ip6) GroupsError!void {
141 switch (self._groups(self, false, null)) {
142 .success => {},
143 .invalid_parameter => return Error.InvalidParameter,
144 .not_started => return Error.NotStarted,
145 .out_of_resources => return Error.OutOfResources,
146 .unsupported => return Error.Unsupported,
147 .already_started => return Error.AlreadyStarted,
148 .not_found => return Error.NotFound,
149 .device_error => return Error.DeviceError,
150 else => |status| return uefi.unexpectedStatus(status),
151 }
30152 }
31153
32154 /// Joins and leaves multicast groups.
33 pub fn groups(self: *const Ip6, join_flag: bool, group_address: ?*const Address) Status {
34 return self._groups(self, join_flag, group_address);
155 ///
156 /// To leave all groups, use `leaveAllGroups` instead.
157 pub fn groups(
158 self: *Ip6,
159 join_flag: JoinFlag,
160 group_address: *const Address,
161 ) GroupsError!void {
162 switch (self._groups(
163 self,
164 // set to TRUE to join the multicast group session and FALSE to leave
165 join_flag == .join,
166 group_address,
167 )) {
168 .success => {},
169 .invalid_parameter => return Error.InvalidParameter,
170 .not_started => return Error.NotStarted,
171 .out_of_resources => return Error.OutOfResources,
172 .unsupported => return Error.Unsupported,
173 .already_started => return Error.AlreadyStarted,
174 .not_found => return Error.NotFound,
175 .device_error => return Error.DeviceError,
176 else => |status| return uefi.unexpectedStatus(status),
177 }
35178 }
36179
37180 /// Adds and deletes routing table entries.
38 pub fn routes(self: *const Ip6, delete_route: bool, destination: ?*const Address, prefix_length: u8, gateway_address: ?*const Address) Status {
39 return self._routes(self, delete_route, destination, prefix_length, gateway_address);
181 pub fn routes(
182 self: *Ip6,
183 delete_route: DeleteFlag,
184 destination: ?*const Address,
185 prefix_length: u8,
186 gateway_address: ?*const Address,
187 ) RoutesError!void {
188 switch (self._routes(
189 self,
190 delete_route == .delete,
191 destination,
192 prefix_length,
193 gateway_address,
194 )) {
195 .success => {},
196 .not_started => return Error.NotStarted,
197 .invalid_parameter => return Error.InvalidParameter,
198 .out_of_resources => return Error.OutOfResources,
199 .not_found => return Error.NotFound,
200 .access_denied => return Error.AccessDenied,
201 else => |status| return uefi.unexpectedStatus(status),
202 }
40203 }
41204
42205 /// Add or delete Neighbor cache entries.
43 pub fn neighbors(self: *const Ip6, delete_flag: bool, target_ip6_address: *const Address, target_link_address: ?*const MacAddress, timeout: u32, override: bool) Status {
44 return self._neighbors(self, delete_flag, target_ip6_address, target_link_address, timeout, override);
206 pub fn neighbors(
207 self: *Ip6,
208 delete_flag: DeleteFlag,
209 target_ip6_address: *const Address,
210 target_link_address: ?*const MacAddress,
211 timeout: u32,
212 override: bool,
213 ) NeighborsError!void {
214 switch (self._neighbors(
215 self,
216 // set to TRUE to delete this route from the routing table.
217 // set to FALSE to add this route to the routing table.
218 delete_flag == .delete,
219 target_ip6_address,
220 target_link_address,
221 timeout,
222 override,
223 )) {
224 .success => {},
225 .not_started => return Error.NotStarted,
226 .invalid_parameter => return Error.InvalidParameter,
227 .out_of_resources => return Error.OutOfResources,
228 .not_found => return Error.NotFound,
229 .access_denied => return Error.AccessDenied,
230 else => |status| return uefi.unexpectedStatus(status),
231 }
45232 }
46233
47234 /// Places outgoing data packets into the transmit queue.
48 pub fn transmit(self: *const Ip6, token: *CompletionToken) Status {
49 return self._transmit(self, token);
235 pub fn transmit(self: *Ip6, token: *CompletionToken) TransmitError!void {
236 switch (self._transmit(self, token)) {
237 .success => {},
238 .not_started => return Error.NotStarted,
239 .no_mapping => return Error.NoMapping,
240 .invalid_parameter => return Error.InvalidParameter,
241 .access_denied => return Error.AccessDenied,
242 .not_ready => return Error.NotReady,
243 .not_found => return Error.NotFound,
244 .out_of_resources => return Error.OutOfResources,
245 .buffer_too_small => return Error.BufferTooSmall,
246 .bad_buffer_size => return Error.BadBufferSize,
247 .device_error => return Error.DeviceError,
248 .no_media => return Error.NoMedia,
249 else => |status| return uefi.unexpectedStatus(status),
250 }
50251 }
51252
52253 /// Places a receiving request into the receiving queue.
53 pub fn receive(self: *const Ip6, token: *CompletionToken) Status {
54 return self._receive(self, token);
254 pub fn receive(self: *Ip6, token: *CompletionToken) ReceiveError!void {
255 switch (self._receive(self, token)) {
256 .success => {},
257 .not_started => return Error.NotStarted,
258 .no_mapping => return Error.NoMapping,
259 .invalid_parameter => return Error.InvalidParameter,
260 .out_of_resources => return Error.OutOfResources,
261 .device_error => return Error.DeviceError,
262 .access_denied => return Error.AccessDenied,
263 .not_ready => return Error.NotReady,
264 .no_media => return Error.NoMedia,
265 else => |status| return uefi.unexpectedStatus(status),
266 }
55267 }
56268
57269 /// Abort an asynchronous transmits or receive request.
58 pub fn cancel(self: *const Ip6, token: ?*CompletionToken) Status {
59 return self._cancel(self, token);
270 pub fn cancel(self: *Ip6, token: ?*CompletionToken) CancelError!void {
271 switch (self._cancel(self, token)) {
272 .success => {},
273 .invalid_parameter => return Error.InvalidParameter,
274 .not_started => return Error.NotStarted,
275 .not_found => return Error.NotFound,
276 .device_error => return Error.DeviceError,
277 else => |status| return uefi.unexpectedStatus(status),
278 }
60279 }
61280
62281 /// Polls for incoming data packets and processes outgoing data packets.
63 pub fn poll(self: *const Ip6) Status {
64 return self._poll(self);
282 ///
283 /// Returns true if a packet was received or processed.
284 pub fn poll(self: *Ip6) PollError!bool {
285 switch (self._poll(self)) {
286 .success => return true,
287 .not_ready => return false,
288 .not_started => return Error.NotStarted,
289 .invalid_parameter => return Error.InvalidParameter,
290 .device_error => return Error.DeviceError,
291 .timeout => return Error.Timeout,
292 else => |status| return uefi.unexpectedStatus(status),
293 }
65294 }
66295
67296 pub const guid align(8) = Guid{
......@@ -73,6 +302,16 @@ pub const Ip6 = extern struct {
73302 .node = [_]u8{ 0xb6, 0x6c, 0x10, 0x19, 0x57, 0xe2 },
74303 };
75304
305 pub const DeleteFlag = enum {
306 delete,
307 add,
308 };
309
310 pub const JoinFlag = enum {
311 join,
312 leave,
313 };
314
76315 pub const Mode = extern struct {
77316 is_started: bool,
78317 max_packet_size: u32,
lib/std/os/uefi/protocol/ip6_config.zig+127-16
......@@ -4,6 +4,9 @@ const Guid = uefi.Guid;
44const Event = uefi.Event;
55const Status = uefi.Status;
66const cc = uefi.cc;
7const Error = Status.Error;
8const MacAddress = uefi.MacAddress;
9const Ip6 = uefi.protocol.Ip6;
710
811pub const Ip6Config = extern struct {
912 _set_data: *const fn (*const Ip6Config, DataType, usize, *const anyopaque) callconv(cc) Status,
......@@ -11,20 +14,98 @@ pub const Ip6Config = extern struct {
1114 _register_data_notify: *const fn (*const Ip6Config, DataType, Event) callconv(cc) Status,
1215 _unregister_data_notify: *const fn (*const Ip6Config, DataType, Event) callconv(cc) Status,
1316
14 pub fn setData(self: *const Ip6Config, data_type: DataType, data_size: usize, data: *const anyopaque) Status {
15 return self._set_data(self, data_type, data_size, data);
17 pub const SetDataError = uefi.UnexpectedError || error{
18 InvalidParameter,
19 WriteProtected,
20 AccessDenied,
21 NotReady,
22 BadBufferSize,
23 Unsupported,
24 OutOfResources,
25 DeviceError,
26 };
27 pub const GetDataError = uefi.UnexpectedError || error{
28 InvalidParameter,
29 BufferTooSmall,
30 NotReady,
31 NotFound,
32 };
33 pub const RegisterDataNotifyError = uefi.UnexpectedError || error{
34 InvalidParameter,
35 Unsupported,
36 OutOfResources,
37 AccessDenied,
38 };
39 pub const UnregisterDataNotifyError = uefi.UnexpectedError || error{
40 InvalidParameter,
41 NotFound,
42 };
43
44 pub fn setData(
45 self: *const Ip6Config,
46 comptime data_type: std.meta.Tag(DataType),
47 payload: *const std.meta.TagPayload(DataType, data_type),
48 ) SetDataError!void {
49 const data_size = @sizeOf(@TypeOf(payload));
50 switch (self._set_data(self, data_type, data_size, @ptrCast(payload))) {
51 .success => {},
52 .invalid_parameter => return Error.InvalidParameter,
53 .write_protected => return Error.WriteProtected,
54 .access_denied => return Error.AccessDenied,
55 .not_ready => return Error.NotReady,
56 .bad_buffer_size => return Error.BadBufferSize,
57 .unsupported => return Error.Unsupported,
58 .out_of_resources => return Error.OutOfResources,
59 .device_error => return Error.DeviceError,
60 else => |status| return uefi.unexpectedStatus(status),
61 }
1662 }
1763
18 pub fn getData(self: *const Ip6Config, data_type: DataType, data_size: *usize, data: ?*const anyopaque) Status {
19 return self._get_data(self, data_type, data_size, data);
64 pub fn getData(
65 self: *const Ip6Config,
66 comptime data_type: std.meta.Tag(DataType),
67 ) GetDataError!std.meta.TagPayload(DataType, data_type) {
68 const DataPayload = std.meta.TagPayload(DataType, data_type);
69
70 var payload: DataPayload = undefined;
71 var payload_size: usize = @sizeOf(DataPayload);
72
73 switch (self._get_data(self, data_type, &payload_size, @ptrCast(&payload))) {
74 .success => return payload,
75 .invalid_parameter => return Error.InvalidParameter,
76 .buffer_too_small => return Error.BufferTooSmall,
77 .not_ready => return Error.NotReady,
78 .not_found => return Error.NotFound,
79 else => |status| return uefi.unexpectedStatus(status),
80 }
2081 }
2182
22 pub fn registerDataNotify(self: *const Ip6Config, data_type: DataType, event: Event) Status {
23 return self._register_data_notify(self, data_type, event);
83 pub fn registerDataNotify(
84 self: *const Ip6Config,
85 data_type: DataType,
86 event: Event,
87 ) RegisterDataNotifyError!void {
88 switch (self._register_data_notify(self, data_type, event)) {
89 .success => {},
90 .invalid_parameter => return Error.InvalidParameter,
91 .unsupported => return Error.Unsupported,
92 .out_of_resources => return Error.OutOfResources,
93 .access_denied => return Error.AccessDenied,
94 else => |status| return uefi.unexpectedStatus(status),
95 }
2496 }
2597
26 pub fn unregisterDataNotify(self: *const Ip6Config, data_type: DataType, event: Event) Status {
27 return self._unregister_data_notify(self, data_type, event);
98 pub fn unregisterDataNotify(
99 self: *const Ip6Config,
100 data_type: DataType,
101 event: Event,
102 ) UnregisterDataNotifyError!void {
103 switch (self._unregister_data_notify(self, data_type, event)) {
104 .success => {},
105 .invalid_parameter => return Error.InvalidParameter,
106 .not_found => return Error.NotFound,
107 else => |status| return uefi.unexpectedStatus(status),
108 }
28109 }
29110
30111 pub const guid align(8) = Guid{
......@@ -36,13 +117,43 @@ pub const Ip6Config = extern struct {
36117 .node = [_]u8{ 0x48, 0xbc, 0xd9, 0x0a, 0xd3, 0x1a },
37118 };
38119
39 pub const DataType = enum(u32) {
40 interface_info,
41 alt_interface_id,
42 policy,
43 dup_addr_detect_transmits,
44 manual_address,
45 gateway,
46 dns_server,
120 pub const DataType = union(enum(u32)) {
121 interface_info: InterfaceInfo,
122 alt_interface_id: InterfaceId,
123 policy: Policy,
124 dup_addr_detect_transmits: DupAddrDetectTransmits,
125 manual_address: [*]ManualAddress,
126 gateway: [*]Ip6.Address,
127 dns_server: [*]Ip6.Address,
128 };
129
130 pub const InterfaceInfo = extern struct {
131 name: [32]u16,
132 if_type: u8,
133 hw_address_size: u32,
134 hw_address: MacAddress,
135 address_info_count: u32,
136 address_info: [*]Ip6.AddressInfo,
137 route_count: u32,
138 route_table: Ip6.RouteTable,
139 };
140
141 pub const InterfaceId = extern struct {
142 id: [8]u8,
143 };
144
145 pub const Policy = enum(u32) {
146 manual,
147 automatic,
148 };
149
150 pub const DupAddrDetectTransmits = extern struct {
151 dup_addr_detect_transmits: u32,
152 };
153
154 pub const ManualAddress = extern struct {
155 address: Ip6.Address,
156 is_anycast: bool,
157 prefix_length: u8,
47158 };
48159};
lib/std/os/uefi/protocol/ip6_service_binding.zig deleted-28
......@@ -1,28 +0,0 @@
1const std = @import("std");
2const uefi = std.os.uefi;
3const Handle = uefi.Handle;
4const Guid = uefi.Guid;
5const Status = uefi.Status;
6const cc = uefi.cc;
7
8pub const Ip6ServiceBinding = extern struct {
9 _create_child: *const fn (*const Ip6ServiceBinding, *?Handle) callconv(cc) Status,
10 _destroy_child: *const fn (*const Ip6ServiceBinding, Handle) callconv(cc) Status,
11
12 pub fn createChild(self: *const Ip6ServiceBinding, handle: *?Handle) Status {
13 return self._create_child(self, handle);
14 }
15
16 pub fn destroyChild(self: *const Ip6ServiceBinding, handle: Handle) Status {
17 return self._destroy_child(self, handle);
18 }
19
20 pub const guid align(8) = Guid{
21 .time_low = 0xec835dd3,
22 .time_mid = 0xfe0f,
23 .time_high_and_version = 0x617b,
24 .clock_seq_high_and_reserved = 0xa6,
25 .clock_seq_low = 0x21,
26 .node = [_]u8{ 0xb3, 0x50, 0xc3, 0xe1, 0x33, 0x88 },
27 };
28};
lib/std/os/uefi/protocol/loaded_image.zig+10-3
......@@ -7,6 +7,7 @@ const SystemTable = uefi.tables.SystemTable;
77const MemoryType = uefi.tables.MemoryType;
88const DevicePath = uefi.protocol.DevicePath;
99const cc = uefi.cc;
10const Error = Status.Error;
1011
1112pub const LoadedImage = extern struct {
1213 revision: u32,
......@@ -21,11 +22,17 @@ pub const LoadedImage = extern struct {
2122 image_size: u64,
2223 image_code_type: MemoryType,
2324 image_data_type: MemoryType,
24 _unload: *const fn (*const LoadedImage, Handle) callconv(cc) Status,
25 _unload: *const fn (*LoadedImage, Handle) callconv(cc) Status,
26
27 pub const UnloadError = uefi.UnexpectedError || error{InvalidParameter};
2528
2629 /// Unloads an image from memory.
27 pub fn unload(self: *const LoadedImage, handle: Handle) Status {
28 return self._unload(self, handle);
30 pub fn unload(self: *LoadedImage, handle: Handle) UnloadError!void {
31 switch (self._unload(self, handle)) {
32 .success => {},
33 .invalid_parameter => return Error.InvalidParameter,
34 else => |status| return uefi.unexpectedStatus(status),
35 }
2936 }
3037
3138 pub const guid align(8) = Guid{
lib/std/os/uefi/protocol/managed_network.zig+151-23
......@@ -8,58 +8,186 @@ const Time = uefi.Time;
88const SimpleNetwork = uefi.protocol.SimpleNetwork;
99const MacAddress = uefi.MacAddress;
1010const cc = uefi.cc;
11const Error = Status.Error;
1112
1213pub const ManagedNetwork = extern struct {
1314 _get_mode_data: *const fn (*const ManagedNetwork, ?*Config, ?*SimpleNetwork) callconv(cc) Status,
14 _configure: *const fn (*const ManagedNetwork, ?*const Config) callconv(cc) Status,
15 _mcast_ip_to_mac: *const fn (*const ManagedNetwork, bool, *const anyopaque, *MacAddress) callconv(cc) Status,
16 _groups: *const fn (*const ManagedNetwork, bool, ?*const MacAddress) callconv(cc) Status,
17 _transmit: *const fn (*const ManagedNetwork, *const CompletionToken) callconv(cc) Status,
18 _receive: *const fn (*const ManagedNetwork, *const CompletionToken) callconv(cc) Status,
19 _cancel: *const fn (*const ManagedNetwork, ?*const CompletionToken) callconv(cc) Status,
20 _poll: *const fn (*const ManagedNetwork) callconv(cc) Status,
15 _configure: *const fn (*ManagedNetwork, ?*const Config) callconv(cc) Status,
16 _mcast_ip_to_mac: *const fn (*ManagedNetwork, bool, *const anyopaque, *MacAddress) callconv(cc) Status,
17 _groups: *const fn (*ManagedNetwork, bool, ?*const MacAddress) callconv(cc) Status,
18 _transmit: *const fn (*ManagedNetwork, *CompletionToken) callconv(cc) Status,
19 _receive: *const fn (*ManagedNetwork, *CompletionToken) callconv(cc) Status,
20 _cancel: *const fn (*ManagedNetwork, ?*const CompletionToken) callconv(cc) Status,
21 _poll: *const fn (*ManagedNetwork) callconv(cc) Status,
22
23 pub const GetModeDataError = uefi.UnexpectedError || error{
24 InvalidParameter,
25 Unsupported,
26 NotStarted,
27 } || Error;
28 pub const ConfigureError = uefi.UnexpectedError || error{
29 InvalidParameter,
30 OutOfResources,
31 Unsupported,
32 DeviceError,
33 } || Error;
34 pub const McastIpToMacError = uefi.UnexpectedError || error{
35 InvalidParameter,
36 NotStarted,
37 Unsupported,
38 DeviceError,
39 } || Error;
40 pub const GroupsError = uefi.UnexpectedError || error{
41 InvalidParameter,
42 NotStarted,
43 AlreadyStarted,
44 NotFound,
45 DeviceError,
46 Unsupported,
47 } || Error;
48 pub const TransmitError = uefi.UnexpectedError || error{
49 NotStarted,
50 InvalidParameter,
51 AccessDenied,
52 OutOfResources,
53 DeviceError,
54 NotReady,
55 NoMedia,
56 };
57 pub const ReceiveError = uefi.UnexpectedError || error{
58 NotStarted,
59 InvalidParameter,
60 OutOfResources,
61 DeviceError,
62 AccessDenied,
63 NotReady,
64 NoMedia,
65 };
66 pub const CancelError = uefi.UnexpectedError || error{
67 NotStarted,
68 InvalidParameter,
69 NotFound,
70 };
71 pub const PollError = uefi.UnexpectedError || error{
72 NotStarted,
73 DeviceError,
74 NotReady,
75 Timeout,
76 };
77
78 pub const GetModeDataData = struct {
79 mnp_config: Config,
80 snp_mode: SimpleNetwork,
81 };
2182
2283 /// Returns the operational parameters for the current MNP child driver.
2384 /// May also support returning the underlying SNP driver mode data.
24 pub fn getModeData(self: *const ManagedNetwork, mnp_config_data: ?*Config, snp_mode_data: ?*SimpleNetwork) Status {
25 return self._get_mode_data(self, mnp_config_data, snp_mode_data);
85 pub fn getModeData(self: *const ManagedNetwork) GetModeDataError!GetModeDataData {
86 var data: GetModeDataData = undefined;
87 switch (self._get_mode_data(self, &data.mnp_config, &data.snp_mode)) {
88 .success => return data,
89 else => |status| {
90 try status.err();
91 return uefi.unexpectedStatus(status);
92 },
93 }
2694 }
2795
2896 /// Sets or clears the operational parameters for the MNP child driver.
29 pub fn configure(self: *const ManagedNetwork, mnp_config_data: ?*const Config) Status {
30 return self._configure(self, mnp_config_data);
97 pub fn configure(self: *ManagedNetwork, mnp_config_data: ?*const Config) ConfigureError!void {
98 switch (self._configure(self, mnp_config_data)) {
99 .success => {},
100 else => |status| {
101 try status.err();
102 return uefi.unexpectedStatus(status);
103 },
104 }
31105 }
32106
33107 /// Translates an IP multicast address to a hardware (MAC) multicast address.
34108 /// This function may be unsupported in some MNP implementations.
35 pub fn mcastIpToMac(self: *const ManagedNetwork, ipv6flag: bool, ipaddress: *const anyopaque, mac_address: *MacAddress) Status {
36 return self._mcast_ip_to_mac(self, ipv6flag, ipaddress, mac_address);
109 pub fn mcastIpToMac(
110 self: *ManagedNetwork,
111 ipv6flag: bool,
112 ipaddress: *const uefi.IpAddress,
113 ) McastIpToMacError!MacAddress {
114 var result: MacAddress = undefined;
115 switch (self._mcast_ip_to_mac(self, ipv6flag, ipaddress, &result)) {
116 .success => return result,
117 else => |status| {
118 try status.err();
119 return uefi.unexpectedStatus(status);
120 },
121 }
37122 }
38123
39124 /// Enables and disables receive filters for multicast address.
40125 /// This function may be unsupported in some MNP implementations.
41 pub fn groups(self: *const ManagedNetwork, join_flag: bool, mac_address: ?*const MacAddress) Status {
42 return self._groups(self, join_flag, mac_address);
126 pub fn groups(
127 self: *ManagedNetwork,
128 join_flag: bool,
129 mac_address: ?*const MacAddress,
130 ) GroupsError!void {
131 switch (self._groups(self, join_flag, mac_address)) {
132 .success => {},
133 else => |status| {
134 try status.err();
135 return uefi.unexpectedStatus(status);
136 },
137 }
43138 }
44139
45140 /// Places asynchronous outgoing data packets into the transmit queue.
46 pub fn transmit(self: *const ManagedNetwork, token: *const CompletionToken) Status {
47 return self._transmit(self, token);
141 pub fn transmit(self: *ManagedNetwork, token: *CompletionToken) TransmitError!void {
142 switch (self._transmit(self, token)) {
143 .success => {},
144 .not_started => return Error.NotStarted,
145 .invalid_parameter => return Error.InvalidParameter,
146 .access_denied => return Error.AccessDenied,
147 .out_of_resources => return Error.OutOfResources,
148 .device_error => return Error.DeviceError,
149 .not_ready => return Error.NotReady,
150 .no_media => return Error.NoMedia,
151 else => |status| return uefi.unexpectedStatus(status),
152 }
48153 }
49154
50155 /// Places an asynchronous receiving request into the receiving queue.
51 pub fn receive(self: *const ManagedNetwork, token: *const CompletionToken) Status {
52 return self._receive(self, token);
156 pub fn receive(self: *ManagedNetwork, token: *CompletionToken) TransmitError!void {
157 switch (self._receive(self, token)) {
158 .success => {},
159 .not_started => return Error.NotStarted,
160 .invalid_parameter => return Error.InvalidParameter,
161 .out_of_resources => return Error.OutOfResources,
162 .device_error => return Error.DeviceError,
163 .access_denied => return Error.AccessDenied,
164 .not_ready => return Error.NotReady,
165 .no_media => return Error.NoMedia,
166 else => |status| return uefi.unexpectedStatus(status),
167 }
53168 }
54169
55170 /// Aborts an asynchronous transmit or receive request.
56 pub fn cancel(self: *const ManagedNetwork, token: ?*const CompletionToken) Status {
57 return self._cancel(self, token);
171 pub fn cancel(self: *ManagedNetwork, token: ?*const CompletionToken) CancelError!void {
172 switch (self._cancel(self, token)) {
173 .success => {},
174 .not_started => return Error.NotStarted,
175 .invalid_parameter => return Error.InvalidParameter,
176 .not_found => return Error.NotFound,
177 else => |status| return uefi.unexpectedStatus(status),
178 }
58179 }
59180
60181 /// Polls for incoming data packets and processes outgoing data packets.
61 pub fn poll(self: *const ManagedNetwork) Status {
62 return self._poll(self);
182 pub fn poll(self: *ManagedNetwork) PollError!void {
183 switch (self._poll(self)) {
184 .success => {},
185 .not_started => return Error.NotStarted,
186 .device_error => return Error.DeviceError,
187 .not_ready => return Error.NotReady,
188 .timeout => return Error.Timeout,
189 else => |status| return uefi.unexpectedStatus(status),
190 }
63191 }
64192
65193 pub const guid align(8) = Guid{
lib/std/os/uefi/protocol/rng.zig+31-4
......@@ -3,20 +3,47 @@ const uefi = std.os.uefi;
33const Guid = uefi.Guid;
44const Status = uefi.Status;
55const cc = uefi.cc;
6const Error = Status.Error;
67
78/// Random Number Generator protocol
89pub const Rng = extern struct {
910 _get_info: *const fn (*const Rng, *usize, [*]align(8) Guid) callconv(cc) Status,
1011 _get_rng: *const fn (*const Rng, ?*align(8) const Guid, usize, [*]u8) callconv(cc) Status,
1112
13 pub const GetInfoError = uefi.UnexpectedError || error{
14 Unsupported,
15 DeviceError,
16 BufferTooSmall,
17 };
18 pub const GetRNGError = uefi.UnexpectedError || error{
19 Unsupported,
20 DeviceError,
21 NotReady,
22 InvalidParameter,
23 };
24
1225 /// Returns information about the random number generation implementation.
13 pub fn getInfo(self: *const Rng, list_size: *usize, list: [*]align(8) Guid) Status {
14 return self._get_info(self, list_size, list);
26 pub fn getInfo(self: *const Rng, list: []align(8) Guid) GetInfoError![]align(8) Guid {
27 var len: usize = list.len;
28 switch (self._get_info(self, &len, list.ptr)) {
29 .success => return list[0..len],
30 .unsupported => return Error.Unsupported,
31 .device_error => return Error.DeviceError,
32 .buffer_too_small => return Error.BufferTooSmall,
33 else => |status| return uefi.unexpectedStatus(status),
34 }
1535 }
1636
1737 /// Produces and returns an RNG value using either the default or specified RNG algorithm.
18 pub fn getRNG(self: *const Rng, algo: ?*align(8) const Guid, value_length: usize, value: [*]u8) Status {
19 return self._get_rng(self, algo, value_length, value);
38 pub fn getRNG(self: *const Rng, algo: ?*align(8) const Guid, value: []u8) GetRNGError!void {
39 switch (self._get_rng(self, algo, value.len, value.ptr)) {
40 .success => {},
41 .unsupported => return Error.Unsupported,
42 .device_error => return Error.DeviceError,
43 .not_ready => return Error.NotReady,
44 .invalid_parameter => return Error.InvalidParameter,
45 else => |status| return uefi.unexpectedStatus(status),
46 }
2047 }
2148
2249 pub const guid align(8) = Guid{
lib/std/os/uefi/protocol/serial_io.zig+84-17
......@@ -3,46 +3,113 @@ const uefi = std.os.uefi;
33const Guid = uefi.Guid;
44const Status = uefi.Status;
55const cc = uefi.cc;
6const Error = Status.Error;
67
78pub const SerialIo = extern struct {
89 revision: u64,
9 _reset: *const fn (*const SerialIo) callconv(cc) Status,
10 _set_attribute: *const fn (*const SerialIo, u64, u32, u32, ParityType, u8, StopBitsType) callconv(cc) Status,
11 _set_control: *const fn (*const SerialIo, u32) callconv(cc) Status,
10 _reset: *const fn (*SerialIo) callconv(cc) Status,
11 _set_attribute: *const fn (*SerialIo, u64, u32, u32, ParityType, u8, StopBitsType) callconv(cc) Status,
12 _set_control: *const fn (*SerialIo, u32) callconv(cc) Status,
1213 _get_control: *const fn (*const SerialIo, *u32) callconv(cc) Status,
13 _write: *const fn (*const SerialIo, *usize, *anyopaque) callconv(cc) Status,
14 _read: *const fn (*const SerialIo, *usize, *anyopaque) callconv(cc) Status,
14 _write: *const fn (*SerialIo, *usize, *const anyopaque) callconv(cc) Status,
15 _read: *const fn (*SerialIo, *usize, *anyopaque) callconv(cc) Status,
1516 mode: *Mode,
1617 device_type_guid: ?*Guid,
1718
19 pub const ResetError = uefi.UnexpectedError || error{DeviceError};
20 pub const SetAttributeError = uefi.UnexpectedError || error{
21 InvalidParameter,
22 DeviceError,
23 };
24 pub const SetControlError = uefi.UnexpectedError || error{
25 Unsupported,
26 DeviceError,
27 };
28 pub const GetControlError = uefi.UnexpectedError || error{DeviceError};
29 pub const WriteError = uefi.UnexpectedError || error{
30 DeviceError,
31 Timeout,
32 };
33 pub const ReadError = uefi.UnexpectedError || error{
34 DeviceError,
35 Timeout,
36 };
37
1838 /// Resets the serial device.
19 pub fn reset(self: *const SerialIo) Status {
20 return self._reset(self);
39 pub fn reset(self: *SerialIo) ResetError!void {
40 switch (self._reset(self)) {
41 .success => {},
42 .device_error => return Error.DeviceError,
43 else => |status| return uefi.unexpectedStatus(status),
44 }
2145 }
2246
2347 /// Sets the baud rate, receive FIFO depth, transmit/receive time out, parity, data bits, and stop bits on a serial device.
24 pub fn setAttribute(self: *const SerialIo, baud_rate: u64, receiver_fifo_depth: u32, timeout: u32, parity: ParityType, data_bits: u8, stop_bits: StopBitsType) Status {
25 return self._set_attribute(self, baud_rate, receiver_fifo_depth, timeout, parity, data_bits, stop_bits);
48 pub fn setAttribute(
49 self: *SerialIo,
50 baud_rate: u64,
51 receiver_fifo_depth: u32,
52 timeout: u32,
53 parity: ParityType,
54 data_bits: u8,
55 stop_bits: StopBitsType,
56 ) SetAttributeError!void {
57 switch (self._set_attribute(
58 self,
59 baud_rate,
60 receiver_fifo_depth,
61 timeout,
62 parity,
63 data_bits,
64 stop_bits,
65 )) {
66 .success => {},
67 .invalid_parameter => return Error.InvalidParameter,
68 .device_error => return Error.DeviceError,
69 else => |status| return uefi.unexpectedStatus(status),
70 }
2671 }
2772
2873 /// Sets the control bits on a serial device.
29 pub fn setControl(self: *const SerialIo, control: u32) Status {
30 return self._set_control(self, control);
74 pub fn setControl(self: *SerialIo, control: u32) SetControlError!void {
75 switch (self._set_control(self, control)) {
76 .success => {},
77 .unsupported => return Error.Unsupported,
78 .device_error => return Error.DeviceError,
79 else => |status| return uefi.unexpectedStatus(status),
80 }
3181 }
3282
3383 /// Retrieves the status of the control bits on a serial device.
34 pub fn getControl(self: *const SerialIo, control: *u32) Status {
35 return self._get_control(self, control);
84 pub fn getControl(self: *SerialIo) GetControlError!u32 {
85 var control: u32 = undefined;
86 switch (self._get_control(self, &control)) {
87 .success => return control,
88 .device_error => return Error.DeviceError,
89 else => |status| return uefi.unexpectedStatus(status),
90 }
3691 }
3792
3893 /// Writes data to a serial device.
39 pub fn write(self: *const SerialIo, buffer_size: *usize, buffer: *anyopaque) Status {
40 return self._write(self, buffer_size, buffer);
94 pub fn write(self: *SerialIo, buffer: []const u8) WriteError!usize {
95 var len: usize = buffer.len;
96 switch (self._write(self, &len, buffer.ptr)) {
97 .success => return len,
98 .device_error => return Error.DeviceError,
99 .timeout => return Error.Timeout,
100 else => |status| return uefi.unexpectedStatus(status),
101 }
41102 }
42103
43104 /// Reads data from a serial device.
44 pub fn read(self: *const SerialIo, buffer_size: *usize, buffer: *anyopaque) Status {
45 return self._read(self, buffer_size, buffer);
105 pub fn read(self: *SerialIo, buffer: []u8) ReadError!usize {
106 var len: usize = buffer.len;
107 switch (self._read(self, &len, buffer.ptr)) {
108 .success => return len,
109 .device_error => return Error.DeviceError,
110 .timeout => return Error.Timeout,
111 else => |status| return uefi.unexpectedStatus(status),
112 }
46113 }
47114
48115 pub const guid align(8) = Guid{
lib/std/os/uefi/protocol/service_binding.zig created+60
......@@ -0,0 +1,60 @@
1const std = @import("std");
2const uefi = std.uefi;
3const Guid = uefi.Guid;
4const Handle = uefi.Handle;
5const Status = uefi.Status;
6const Error = Status.Error;
7const cc = uefi.cc;
8
9pub fn ServiceBinding(service_guid: Guid) type {
10 return struct {
11 const Self = @This();
12
13 _create_child: *const fn (*Self, *?Handle) callconv(cc) Status,
14 _destroy_child: *const fn (*Self, Handle) callconv(cc) Status,
15
16 pub const CreateChildError = uefi.UnexpectedError || error{
17 InvalidParameter,
18 OutOfResources,
19 } || Error;
20 pub const DestroyChildError = uefi.UnexpectedError || error{
21 Unsupported,
22 InvalidParameter,
23 AccessDenied,
24 } || Error;
25
26 /// To add this protocol to an existing handle, use `addToHandle` instead.
27 pub fn createChild(self: *Self) CreateChildError!Handle {
28 var handle: ?Handle = null;
29 switch (self._create_child(self, &handle)) {
30 .success => return handle orelse error.Unexpected,
31 else => |status| {
32 try status.err();
33 return uefi.unexpectedStatus(status);
34 },
35 }
36 }
37
38 pub fn addToHandle(self: *Self, handle: Handle) CreateChildError!void {
39 switch (self._create_child(self, @ptrCast(@constCast(&handle)))) {
40 .success => {},
41 else => |status| {
42 try status.err();
43 return uefi.unexpectedStatus(status);
44 },
45 }
46 }
47
48 pub fn destroyChild(self: *Self, handle: Handle) DestroyChildError!void {
49 switch (self._destroy_child(self, handle)) {
50 .success => {},
51 else => |status| {
52 try status.err();
53 return uefi.unexpectedStatus(status);
54 },
55 }
56 }
57
58 pub const guid align(8) = service_guid;
59 };
60}
lib/std/os/uefi/protocol/simple_file_system.zig+26-4
......@@ -1,16 +1,38 @@
11const std = @import("std");
22const uefi = std.os.uefi;
33const Guid = uefi.Guid;
4const FileProtocol = uefi.protocol.File;
4const File = uefi.protocol.File;
55const Status = uefi.Status;
66const cc = uefi.cc;
7const Error = Status.Error;
78
89pub const SimpleFileSystem = extern struct {
910 revision: u64,
10 _open_volume: *const fn (*const SimpleFileSystem, **const FileProtocol) callconv(cc) Status,
11 _open_volume: *const fn (*const SimpleFileSystem, **File) callconv(cc) Status,
1112
12 pub fn openVolume(self: *const SimpleFileSystem, root: **const FileProtocol) Status {
13 return self._open_volume(self, root);
13 pub const OpenVolumeError = uefi.UnexpectedError || error{
14 Unsupported,
15 NoMedia,
16 DeviceError,
17 VolumeCorrupted,
18 AccessDenied,
19 OutOfResources,
20 MediaChanged,
21 };
22
23 pub fn openVolume(self: *const SimpleFileSystem) OpenVolumeError!*File {
24 var root: *File = undefined;
25 switch (self._open_volume(self, &root)) {
26 .success => return root,
27 .unsupported => return Error.Unsupported,
28 .no_media => return Error.NoMedia,
29 .device_error => return Error.DeviceError,
30 .volume_corrupted => return Error.VolumeCorrupted,
31 .access_denied => return Error.AccessDenied,
32 .out_of_resources => return Error.OutOfResources,
33 .media_changed => return Error.MediaChanged,
34 else => |status| return uefi.unexpectedStatus(status),
35 }
1436 }
1537
1638 pub const guid align(8) = Guid{
lib/std/os/uefi/protocol/simple_network.zig+312-38
......@@ -4,88 +4,349 @@ const Event = uefi.Event;
44const Guid = uefi.Guid;
55const Status = uefi.Status;
66const cc = uefi.cc;
7const Error = Status.Error;
78
89pub const SimpleNetwork = extern struct {
910 revision: u64,
10 _start: *const fn (*const SimpleNetwork) callconv(cc) Status,
11 _stop: *const fn (*const SimpleNetwork) callconv(cc) Status,
12 _initialize: *const fn (*const SimpleNetwork, usize, usize) callconv(cc) Status,
13 _reset: *const fn (*const SimpleNetwork, bool) callconv(cc) Status,
14 _shutdown: *const fn (*const SimpleNetwork) callconv(cc) Status,
15 _receive_filters: *const fn (*const SimpleNetwork, ReceiveFilter, ReceiveFilter, bool, usize, ?[*]const MacAddress) callconv(cc) Status,
16 _station_address: *const fn (*const SimpleNetwork, bool, ?*const MacAddress) callconv(cc) Status,
11 _start: *const fn (*SimpleNetwork) callconv(cc) Status,
12 _stop: *const fn (*SimpleNetwork) callconv(cc) Status,
13 _initialize: *const fn (*SimpleNetwork, usize, usize) callconv(cc) Status,
14 _reset: *const fn (*SimpleNetwork, bool) callconv(cc) Status,
15 _shutdown: *const fn (*SimpleNetwork) callconv(cc) Status,
16 _receive_filters: *const fn (*SimpleNetwork, ReceiveFilter, ReceiveFilter, bool, usize, ?[*]const MacAddress) callconv(cc) Status,
17 _station_address: *const fn (*SimpleNetwork, bool, ?*const MacAddress) callconv(cc) Status,
1718 _statistics: *const fn (*const SimpleNetwork, bool, ?*usize, ?*Statistics) callconv(cc) Status,
18 _mcast_ip_to_mac: *const fn (*const SimpleNetwork, bool, *const anyopaque, *MacAddress) callconv(cc) Status,
19 _nvdata: *const fn (*const SimpleNetwork, bool, usize, usize, [*]u8) callconv(cc) Status,
20 _get_status: *const fn (*const SimpleNetwork, *InterruptStatus, ?*?[*]u8) callconv(cc) Status,
21 _transmit: *const fn (*const SimpleNetwork, usize, usize, [*]const u8, ?*const MacAddress, ?*const MacAddress, ?*const u16) callconv(cc) Status,
22 _receive: *const fn (*const SimpleNetwork, ?*usize, *usize, [*]u8, ?*MacAddress, ?*MacAddress, ?*u16) callconv(cc) Status,
19 _mcast_ip_to_mac: *const fn (*SimpleNetwork, bool, *const anyopaque, *MacAddress) callconv(cc) Status,
20 _nvdata: *const fn (*SimpleNetwork, bool, usize, usize, [*]u8) callconv(cc) Status,
21 _get_status: *const fn (*SimpleNetwork, ?*InterruptStatus, ?*?[*]u8) callconv(cc) Status,
22 _transmit: *const fn (*SimpleNetwork, usize, usize, [*]const u8, ?*const MacAddress, ?*const MacAddress, ?*const u16) callconv(cc) Status,
23 _receive: *const fn (*SimpleNetwork, ?*usize, *usize, [*]u8, ?*MacAddress, ?*MacAddress, ?*u16) callconv(cc) Status,
2324 wait_for_packet: Event,
2425 mode: *Mode,
2526
27 pub const StartError = uefi.UnexpectedError || error{
28 AlreadyStarted,
29 InvalidParameter,
30 DeviceError,
31 Unsupported,
32 };
33 pub const StopError = uefi.UnexpectedError || error{
34 NotStarted,
35 InvalidParameter,
36 DeviceError,
37 Unsupported,
38 };
39 pub const InitializeError = uefi.UnexpectedError || error{
40 NotStarted,
41 OutOfResources,
42 InvalidParameter,
43 DeviceError,
44 Unsupported,
45 };
46 pub const ResetError = uefi.UnexpectedError || error{
47 NotStarted,
48 InvalidParameter,
49 DeviceError,
50 Unsupported,
51 };
52 pub const ShutdownError = uefi.UnexpectedError || error{
53 NotStarted,
54 InvalidParameter,
55 DeviceError,
56 };
57 pub const ReceiveFiltersError = uefi.UnexpectedError || error{
58 NotStarted,
59 InvalidParameter,
60 DeviceError,
61 Unsupported,
62 };
63 pub const StationAddressError = uefi.UnexpectedError || error{
64 NotStarted,
65 InvalidParameter,
66 DeviceError,
67 Unsupported,
68 };
69 pub const StatisticsError = uefi.UnexpectedError || error{
70 NotStarted,
71 BufferTooSmall,
72 InvalidParameter,
73 DeviceError,
74 Unsupported,
75 };
76 pub const McastIpToMacError = uefi.UnexpectedError || error{
77 NotStarted,
78 InvalidParameter,
79 DeviceError,
80 Unsupported,
81 };
82 pub const NvDataError = uefi.UnexpectedError || error{
83 NotStarted,
84 InvalidParameter,
85 DeviceError,
86 Unsupported,
87 };
88 pub const GetStatusError = uefi.UnexpectedError || error{
89 NotStarted,
90 InvalidParameter,
91 DeviceError,
92 };
93 pub const TransmitError = uefi.UnexpectedError || error{
94 NotStarted,
95 NotReady,
96 BufferTooSmall,
97 InvalidParameter,
98 DeviceError,
99 Unsupported,
100 };
101 pub const ReceiveError = uefi.UnexpectedError || error{
102 NotStarted,
103 NotReady,
104 BufferTooSmall,
105 InvalidParameter,
106 DeviceError,
107 };
108
26109 /// Changes the state of a network interface from "stopped" to "started".
27 pub fn start(self: *const SimpleNetwork) Status {
28 return self._start(self);
110 pub fn start(self: *SimpleNetwork) StartError!void {
111 switch (self._start(self)) {
112 .success => {},
113 .already_started => return Error.AlreadyStarted,
114 .invalid_parameter => return Error.InvalidParameter,
115 .device_error => return Error.DeviceError,
116 .unsupported => return Error.Unsupported,
117 else => |status| return uefi.unexpectedStatus(status),
118 }
29119 }
30120
31121 /// Changes the state of a network interface from "started" to "stopped".
32 pub fn stop(self: *const SimpleNetwork) Status {
33 return self._stop(self);
122 pub fn stop(self: *SimpleNetwork) StopError!void {
123 switch (self._stop(self)) {
124 .success => {},
125 .not_started => return Error.NotStarted,
126 .invalid_parameter => return Error.InvalidParameter,
127 .device_error => return Error.DeviceError,
128 .unsupported => return Error.Unsupported,
129 else => |status| return uefi.unexpectedStatus(status),
130 }
34131 }
35132
36133 /// Resets a network adapter and allocates the transmit and receive buffers required by the network interface.
37 pub fn initialize(self: *const SimpleNetwork, extra_rx_buffer_size: usize, extra_tx_buffer_size: usize) Status {
38 return self._initialize(self, extra_rx_buffer_size, extra_tx_buffer_size);
134 pub fn initialize(
135 self: *SimpleNetwork,
136 extra_rx_buffer_size: usize,
137 extra_tx_buffer_size: usize,
138 ) InitializeError!void {
139 switch (self._initialize(self, extra_rx_buffer_size, extra_tx_buffer_size)) {
140 .success => {},
141 .not_started => return Error.NotStarted,
142 .out_of_resources => return Error.OutOfResources,
143 .invalid_parameter => return Error.InvalidParameter,
144 .device_error => return Error.DeviceError,
145 .unsupported => return Error.Unsupported,
146 else => |status| return uefi.unexpectedStatus(status),
147 }
39148 }
40149
41150 /// Resets a network adapter and reinitializes it with the parameters that were provided in the previous call to initialize().
42 pub fn reset(self: *const SimpleNetwork, extended_verification: bool) Status {
43 return self._reset(self, extended_verification);
151 pub fn reset(self: *SimpleNetwork, extended_verification: bool) ResetError!void {
152 switch (self._reset(self, extended_verification)) {
153 .success => {},
154 .not_started => return Error.NotStarted,
155 .invalid_parameter => return Error.InvalidParameter,
156 .device_error => return Error.DeviceError,
157 .unsupported => return Error.Unsupported,
158 else => |status| return uefi.unexpectedStatus(status),
159 }
44160 }
45161
46162 /// Resets a network adapter and leaves it in a state that is safe for another driver to initialize.
47 pub fn shutdown(self: *const SimpleNetwork) Status {
48 return self._shutdown(self);
163 pub fn shutdown(self: *SimpleNetwork) ShutdownError!void {
164 switch (self._shutdown(self)) {
165 .success => {},
166 .not_started => return ShutdownError.NotStarted,
167 .invalid_parameter => return ShutdownError.InvalidParameter,
168 .device_error => return ShutdownError.DeviceError,
169 else => |status| return uefi.unexpectedStatus(status),
170 }
49171 }
50172
51173 /// Manages the multicast receive filters of a network interface.
52 pub fn receiveFilters(self: *const SimpleNetwork, enable: ReceiveFilter, disable: ReceiveFilter, reset_mcast_filter: bool, mcast_filter_cnt: usize, mcast_filter: ?[*]const MacAddress) Status {
53 return self._receive_filters(self, enable, disable, reset_mcast_filter, mcast_filter_cnt, mcast_filter);
174 pub fn receiveFilters(
175 self: *SimpleNetwork,
176 enable: ReceiveFilter,
177 disable: ReceiveFilter,
178 reset_mcast_filter: bool,
179 mcast_filter: ?[]const MacAddress,
180 ) ReceiveFiltersError!void {
181 const count: usize, const ptr: ?[*]const MacAddress =
182 if (mcast_filter) |f|
183 .{ f.len, f.ptr }
184 else
185 .{ 0, null };
186
187 switch (self._receive_filters(self, enable, disable, reset_mcast_filter, count, ptr)) {
188 .success => {},
189 .not_started => return Error.NotStarted,
190 .invalid_parameter => return Error.InvalidParameter,
191 .device_error => return Error.DeviceError,
192 .unsupported => return Error.Unsupported,
193 else => |status| return uefi.unexpectedStatus(status),
194 }
54195 }
55196
56197 /// Modifies or resets the current station address, if supported.
57 pub fn stationAddress(self: *const SimpleNetwork, reset_flag: bool, new: ?*const MacAddress) Status {
58 return self._station_address(self, reset_flag, new);
198 pub fn stationAddress(
199 self: *SimpleNetwork,
200 reset_flag: bool,
201 new: ?*const MacAddress,
202 ) StationAddressError!void {
203 switch (self._station_address(self, reset_flag, new)) {
204 .success => {},
205 .not_started => return Error.NotStarted,
206 .invalid_parameter => return Error.InvalidParameter,
207 .device_error => return Error.DeviceError,
208 .unsupported => return Error.Unsupported,
209 else => |status| return uefi.unexpectedStatus(status),
210 }
211 }
212
213 pub fn resetStatistics(self: *SimpleNetwork) StatisticsError!void {
214 switch (self._statistics(self, true, null, null)) {
215 .success => {},
216 .not_started => return Error.NotStarted,
217 .invalid_parameter => return Error.InvalidParameter,
218 .device_error => return Error.DeviceError,
219 .unsupported => return Error.Unsupported,
220 else => |status| return uefi.unexpectedStatus(status),
221 }
59222 }
60223
61224 /// Resets or collects the statistics on a network interface.
62 pub fn statistics(self: *const SimpleNetwork, reset_flag: bool, statistics_size: ?*usize, statistics_table: ?*Statistics) Status {
63 return self._statistics(self, reset_flag, statistics_size, statistics_table);
225 pub fn statistics(self: *SimpleNetwork, reset_flag: bool) StatisticsError!Statistics {
226 var stats: Statistics = undefined;
227 var stats_size: usize = @sizeOf(Statistics);
228 switch (self._statistics(self, reset_flag, &stats_size, &stats)) {
229 .success => {},
230 .not_started => return Error.NotStarted,
231 .invalid_parameter => return Error.InvalidParameter,
232 .device_error => return Error.DeviceError,
233 .unsupported => return Error.Unsupported,
234 else => |status| return uefi.unexpectedStatus(status),
235 }
236
237 if (stats_size != @sizeOf(Statistics))
238 return error.Unexpected
239 else
240 return stats;
64241 }
65242
66243 /// Converts a multicast IP address to a multicast HW MAC address.
67 pub fn mcastIpToMac(self: *const SimpleNetwork, ipv6: bool, ip: *const anyopaque, mac: *MacAddress) Status {
68 return self._mcast_ip_to_mac(self, ipv6, ip, mac);
244 pub fn mcastIpToMac(
245 self: *SimpleNetwork,
246 ipv6: bool,
247 ip: *const anyopaque,
248 ) McastIpToMacError!MacAddress {
249 var mac: MacAddress = undefined;
250 switch (self._mcast_ip_to_mac(self, ipv6, ip, &mac)) {
251 .success => return mac,
252 .not_started => return Error.NotStarted,
253 .invalid_parameter => return Error.InvalidParameter,
254 .device_error => return Error.DeviceError,
255 .unsupported => return Error.Unsupported,
256 else => |status| return uefi.unexpectedStatus(status),
257 }
69258 }
70259
71260 /// Performs read and write operations on the NVRAM device attached to a network interface.
72 pub fn nvdata(self: *const SimpleNetwork, read_write: bool, offset: usize, buffer_size: usize, buffer: [*]u8) Status {
73 return self._nvdata(self, read_write, offset, buffer_size, buffer);
261 pub fn nvData(
262 self: *SimpleNetwork,
263 read_write: NvDataOperation,
264 offset: usize,
265 buffer: []u8,
266 ) NvDataError!void {
267 switch (self._nvdata(
268 self,
269 // if ReadWrite is TRUE, a read operation is performed
270 read_write == .read,
271 offset,
272 buffer.len,
273 buffer.ptr,
274 )) {
275 .success => {},
276 .not_started => return Error.NotStarted,
277 .invalid_parameter => return Error.InvalidParameter,
278 .device_error => return Error.DeviceError,
279 .unsupported => return Error.Unsupported,
280 else => |status| return uefi.unexpectedStatus(status),
281 }
74282 }
75283
76284 /// Reads the current interrupt status and recycled transmit buffer status from a network interface.
77 pub fn getStatus(self: *const SimpleNetwork, interrupt_status: *InterruptStatus, tx_buf: ?*?[*]u8) Status {
78 return self._get_status(self, interrupt_status, tx_buf);
285 pub fn getStatus(
286 self: *SimpleNetwork,
287 interrupt_status: ?*InterruptStatus,
288 recycled_tx_buf: ?*?[*]u8,
289 ) GetStatusError!void {
290 switch (self._get_status(self, interrupt_status, recycled_tx_buf)) {
291 .success => {},
292 .not_started => return Error.NotStarted,
293 .invalid_parameter => return Error.InvalidParameter,
294 .device_error => return Error.DeviceError,
295 else => |status| return uefi.unexpectedStatus(status),
296 }
79297 }
80298
81299 /// Places a packet in the transmit queue of a network interface.
82 pub fn transmit(self: *const SimpleNetwork, header_size: usize, buffer_size: usize, buffer: [*]const u8, src_addr: ?*const MacAddress, dest_addr: ?*const MacAddress, protocol: ?*const u16) Status {
83 return self._transmit(self, header_size, buffer_size, buffer, src_addr, dest_addr, protocol);
300 pub fn transmit(
301 self: *SimpleNetwork,
302 header_size: usize,
303 buffer: []const u8,
304 src_addr: ?*const MacAddress,
305 dest_addr: ?*const MacAddress,
306 protocol: ?*const u16,
307 ) TransmitError!void {
308 switch (self._transmit(
309 self,
310 header_size,
311 buffer.len,
312 buffer.ptr,
313 src_addr,
314 dest_addr,
315 protocol,
316 )) {
317 .success => {},
318 .not_started => return Error.NotStarted,
319 .not_ready => return Error.NotReady,
320 .buffer_too_small => return Error.BufferTooSmall,
321 .invalid_parameter => return Error.InvalidParameter,
322 .device_error => return Error.DeviceError,
323 .unsupported => return Error.Unsupported,
324 else => |status| return uefi.unexpectedStatus(status),
325 }
84326 }
85327
86328 /// Receives a packet from a network interface.
87 pub fn receive(self: *const SimpleNetwork, header_size: ?*usize, buffer_size: *usize, buffer: [*]u8, src_addr: ?*MacAddress, dest_addr: ?*MacAddress, protocol: ?*u16) Status {
88 return self._receive(self, header_size, buffer_size, buffer, src_addr, dest_addr, protocol);
329 pub fn receive(self: *SimpleNetwork, buffer: []u8) ReceiveError!Packet {
330 var packet: Packet = undefined;
331 packet.buffer = buffer;
332
333 switch (self._receive(
334 self,
335 &packet.header_size,
336 &packet.buffer.len,
337 packet.buffer.ptr,
338 &packet.src_addr,
339 &packet.dst_addr,
340 &packet.protocol,
341 )) {
342 .success => return packet,
343 .not_started => return Error.NotStarted,
344 .not_ready => return Error.NotReady,
345 .buffer_too_small => return Error.BufferTooSmall,
346 .invalid_parameter => return Error.InvalidParameter,
347 .device_error => return Error.DeviceError,
348 else => |status| return uefi.unexpectedStatus(status),
349 }
89350 }
90351
91352 pub const guid align(8) = Guid{
......@@ -97,6 +358,11 @@ pub const SimpleNetwork = extern struct {
97358 .node = [_]u8{ 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d },
98359 };
99360
361 pub const NvDataOperation = enum {
362 read,
363 write,
364 };
365
100366 pub const MacAddress = [32]u8;
101367
102368 pub const Mode = extern struct {
......@@ -172,4 +438,12 @@ pub const SimpleNetwork = extern struct {
172438 software_interrupt: bool,
173439 _pad: u28 = 0,
174440 };
441
442 pub const Packet = struct {
443 header_size: usize,
444 buffer: []u8,
445 src_addr: MacAddress,
446 dst_addr: MacAddress,
447 protocol: u16,
448 };
175449};
lib/std/os/uefi/protocol/simple_pointer.zig+22-5
......@@ -4,22 +4,39 @@ const Event = uefi.Event;
44const Guid = uefi.Guid;
55const Status = uefi.Status;
66const cc = uefi.cc;
7const Error = Status.Error;
78
89/// Protocol for mice.
910pub const SimplePointer = struct {
10 _reset: *const fn (*const SimplePointer, bool) callconv(cc) Status,
11 _reset: *const fn (*SimplePointer, bool) callconv(cc) Status,
1112 _get_state: *const fn (*const SimplePointer, *State) callconv(cc) Status,
1213 wait_for_input: Event,
1314 mode: *Mode,
1415
16 pub const ResetError = uefi.UnexpectedError || error{DeviceError};
17 pub const GetStateError = uefi.UnexpectedError || error{
18 NotReady,
19 DeviceError,
20 };
21
1522 /// Resets the pointer device hardware.
16 pub fn reset(self: *const SimplePointer, verify: bool) Status {
17 return self._reset(self, verify);
23 pub fn reset(self: *SimplePointer, verify: bool) ResetError!void {
24 switch (self._reset(self, verify)) {
25 .success => {},
26 .device_error => return Error.DeviceError,
27 else => |status| return uefi.unexpectedStatus(status),
28 }
1829 }
1930
2031 /// Retrieves the current state of a pointer device.
21 pub fn getState(self: *const SimplePointer, state: *State) Status {
22 return self._get_state(self, state);
32 pub fn getState(self: *const SimplePointer) GetStateError!State {
33 var state: State = undefined;
34 switch (self._get_state(self, &state)) {
35 .success => return state,
36 .not_ready => return Error.NotReady,
37 .device_error => return Error.DeviceError,
38 else => |status| return uefi.unexpectedStatus(status),
39 }
2340 }
2441
2542 pub const guid align(8) = Guid{
lib/std/os/uefi/protocol/simple_text_input.zig+25-6
......@@ -4,21 +4,40 @@ const Event = uefi.Event;
44const Guid = uefi.Guid;
55const Status = uefi.Status;
66const cc = uefi.cc;
7const Error = Status.Error;
78
89/// Character input devices, e.g. Keyboard
910pub const SimpleTextInput = extern struct {
10 _reset: *const fn (*const SimpleTextInput, bool) callconv(cc) Status,
11 _read_key_stroke: *const fn (*const SimpleTextInput, *Key.Input) callconv(cc) Status,
11 _reset: *const fn (*SimpleTextInput, bool) callconv(cc) Status,
12 _read_key_stroke: *const fn (*SimpleTextInput, *Key.Input) callconv(cc) Status,
1213 wait_for_key: Event,
1314
15 pub const ResetError = uefi.UnexpectedError || error{DeviceError};
16 pub const ReadKeyStrokeError = uefi.UnexpectedError || error{
17 NotReady,
18 DeviceError,
19 Unsupported,
20 };
21
1422 /// Resets the input device hardware.
15 pub fn reset(self: *const SimpleTextInput, verify: bool) Status {
16 return self._reset(self, verify);
23 pub fn reset(self: *SimpleTextInput, verify: bool) ResetError!void {
24 switch (self._reset(self, verify)) {
25 .success => {},
26 .device_error => return Error.DeviceError,
27 else => |status| return uefi.unexpectedStatus(status),
28 }
1729 }
1830
1931 /// Reads the next keystroke from the input device.
20 pub fn readKeyStroke(self: *const SimpleTextInput, input_key: *Key.Input) Status {
21 return self._read_key_stroke(self, input_key);
32 pub fn readKeyStroke(self: *SimpleTextInput) ReadKeyStrokeError!Key.Input {
33 var key: Key.Input = undefined;
34 switch (self._read_key_stroke(self, &key)) {
35 .success => return key,
36 .not_ready => return Error.NotReady,
37 .device_error => return Error.DeviceError,
38 .unsupported => return Error.Unsupported,
39 else => |status| return uefi.unexpectedStatus(status),
40 }
2241 }
2342
2443 pub const guid align(8) = Guid{
lib/std/os/uefi/protocol/simple_text_input_ex.zig+61-15
......@@ -4,39 +4,85 @@ const Event = uefi.Event;
44const Guid = uefi.Guid;
55const Status = uefi.Status;
66const cc = uefi.cc;
7const Error = Status.Error;
78
89/// Character input devices, e.g. Keyboard
910pub const SimpleTextInputEx = extern struct {
10 _reset: *const fn (*const SimpleTextInputEx, bool) callconv(cc) Status,
11 _read_key_stroke_ex: *const fn (*const SimpleTextInputEx, *Key) callconv(cc) Status,
11 _reset: *const fn (*SimpleTextInputEx, bool) callconv(cc) Status,
12 _read_key_stroke_ex: *const fn (*SimpleTextInputEx, *Key) callconv(cc) Status,
1213 wait_for_key_ex: Event,
13 _set_state: *const fn (*const SimpleTextInputEx, *const u8) callconv(cc) Status,
14 _register_key_notify: *const fn (*const SimpleTextInputEx, *const Key, *const fn (*const Key) callconv(cc) usize, **anyopaque) callconv(cc) Status,
15 _unregister_key_notify: *const fn (*const SimpleTextInputEx, *const anyopaque) callconv(cc) Status,
14 _set_state: *const fn (*SimpleTextInputEx, *const u8) callconv(cc) Status,
15 _register_key_notify: *const fn (*SimpleTextInputEx, *const Key, *const fn (*const Key) callconv(cc) Status, **anyopaque) callconv(cc) Status,
16 _unregister_key_notify: *const fn (*SimpleTextInputEx, *const anyopaque) callconv(cc) Status,
17
18 pub const ResetError = uefi.UnexpectedError || error{DeviceError};
19 pub const ReadKeyStrokeError = uefi.UnexpectedError || error{
20 NotReady,
21 DeviceError,
22 Unsupported,
23 };
24 pub const SetStateError = uefi.UnexpectedError || error{
25 DeviceError,
26 Unsupported,
27 };
28 pub const RegisterKeyNotifyError = uefi.UnexpectedError || error{OutOfResources};
29 pub const UnregisterKeyNotifyError = uefi.UnexpectedError || error{InvalidParameter};
1630
1731 /// Resets the input device hardware.
18 pub fn reset(self: *const SimpleTextInputEx, verify: bool) Status {
19 return self._reset(self, verify);
32 pub fn reset(self: *SimpleTextInputEx, verify: bool) ResetError!void {
33 switch (self._reset(self, verify)) {
34 .success => {},
35 .device_error => return Error.DeviceError,
36 else => |status| return uefi.unexpectedStatus(status),
37 }
2038 }
2139
2240 /// Reads the next keystroke from the input device.
23 pub fn readKeyStrokeEx(self: *const SimpleTextInputEx, key_data: *Key) Status {
24 return self._read_key_stroke_ex(self, key_data);
41 pub fn readKeyStroke(self: *SimpleTextInputEx) ReadKeyStrokeError!Key {
42 var key: Key = undefined;
43 switch (self._read_key_stroke_ex(self, &key)) {
44 .success => return key,
45 .not_ready => return Error.NotReady,
46 .device_error => return Error.DeviceError,
47 .unsupported => return Error.Unsupported,
48 else => |status| return uefi.unexpectedStatus(status),
49 }
2550 }
2651
2752 /// Set certain state for the input device.
28 pub fn setState(self: *const SimpleTextInputEx, state: *const u8) Status {
29 return self._set_state(self, state);
53 pub fn setState(self: *SimpleTextInputEx, state: *const Key.State.Toggle) SetStateError!void {
54 switch (self._set_state(self, @ptrCast(state))) {
55 .success => {},
56 .device_error => return Error.DeviceError,
57 .unsupported => return Error.Unsupported,
58 else => |status| return uefi.unexpectedStatus(status),
59 }
3060 }
3161
3262 /// Register a notification function for a particular keystroke for the input device.
33 pub fn registerKeyNotify(self: *const SimpleTextInputEx, key_data: *const Key, notify: *const fn (*const Key) callconv(cc) usize, handle: **anyopaque) Status {
34 return self._register_key_notify(self, key_data, notify, handle);
63 pub fn registerKeyNotify(
64 self: *SimpleTextInputEx,
65 key_data: *const Key,
66 notify: *const fn (*const Key) callconv(cc) Status,
67 ) RegisterKeyNotifyError!uefi.Handle {
68 var handle: uefi.Handle = undefined;
69 switch (self._register_key_notify(self, key_data, notify, &handle)) {
70 .success => return handle,
71 .out_of_resources => return Error.OutOfResources,
72 else => |status| return uefi.unexpectedStatus(status),
73 }
3574 }
3675
3776 /// Remove the notification that was previously registered.
38 pub fn unregisterKeyNotify(self: *const SimpleTextInputEx, handle: *const anyopaque) Status {
39 return self._unregister_key_notify(self, handle);
77 pub fn unregisterKeyNotify(
78 self: *SimpleTextInputEx,
79 handle: uefi.Handle,
80 ) UnregisterKeyNotifyError!void {
81 switch (self._unregister_key_notify(self, handle)) {
82 .success => {},
83 .invalid_parameter => return Error.InvalidParameter,
84 else => |status| return uefi.unexpectedStatus(status),
85 }
4086 }
4187
4288 pub const guid align(8) = Guid{
lib/std/os/uefi/protocol/simple_text_output.zig+144-50
......@@ -3,63 +3,142 @@ const uefi = std.os.uefi;
33const Guid = uefi.Guid;
44const Status = uefi.Status;
55const cc = uefi.cc;
6const Error = Status.Error;
67
78/// Character output devices
89pub const SimpleTextOutput = extern struct {
9 _reset: *const fn (*const SimpleTextOutput, bool) callconv(cc) Status,
10 _output_string: *const fn (*const SimpleTextOutput, [*:0]const u16) callconv(cc) Status,
10 _reset: *const fn (*SimpleTextOutput, bool) callconv(cc) Status,
11 _output_string: *const fn (*SimpleTextOutput, [*:0]const u16) callconv(cc) Status,
1112 _test_string: *const fn (*const SimpleTextOutput, [*:0]const u16) callconv(cc) Status,
1213 _query_mode: *const fn (*const SimpleTextOutput, usize, *usize, *usize) callconv(cc) Status,
13 _set_mode: *const fn (*const SimpleTextOutput, usize) callconv(cc) Status,
14 _set_attribute: *const fn (*const SimpleTextOutput, usize) callconv(cc) Status,
15 _clear_screen: *const fn (*const SimpleTextOutput) callconv(cc) Status,
16 _set_cursor_position: *const fn (*const SimpleTextOutput, usize, usize) callconv(cc) Status,
17 _enable_cursor: *const fn (*const SimpleTextOutput, bool) callconv(cc) Status,
14 _set_mode: *const fn (*SimpleTextOutput, usize) callconv(cc) Status,
15 _set_attribute: *const fn (*SimpleTextOutput, usize) callconv(cc) Status,
16 _clear_screen: *const fn (*SimpleTextOutput) callconv(cc) Status,
17 _set_cursor_position: *const fn (*SimpleTextOutput, usize, usize) callconv(cc) Status,
18 _enable_cursor: *const fn (*SimpleTextOutput, bool) callconv(cc) Status,
1819 mode: *Mode,
1920
21 pub const ResetError = uefi.UnexpectedError || error{DeviceError};
22 pub const OutputStringError = uefi.UnexpectedError || error{
23 DeviceError,
24 Unsupported,
25 };
26 pub const QueryModeError = uefi.UnexpectedError || error{
27 DeviceError,
28 Unsupported,
29 };
30 pub const SetModeError = uefi.UnexpectedError || error{
31 DeviceError,
32 Unsupported,
33 };
34 pub const SetAttributeError = uefi.UnexpectedError || error{DeviceError};
35 pub const ClearScreenError = uefi.UnexpectedError || error{
36 DeviceError,
37 Unsupported,
38 };
39 pub const SetCursorPositionError = uefi.UnexpectedError || error{
40 DeviceError,
41 Unsupported,
42 };
43 pub const EnableCursorError = uefi.UnexpectedError || error{
44 DeviceError,
45 Unsupported,
46 };
47
2048 /// Resets the text output device hardware.
21 pub fn reset(self: *const SimpleTextOutput, verify: bool) Status {
22 return self._reset(self, verify);
49 pub fn reset(self: *SimpleTextOutput, verify: bool) ResetError!void {
50 switch (self._reset(self, verify)) {
51 .success => {},
52 .device_error => return Error.DeviceError,
53 else => |status| return uefi.unexpectedStatus(status),
54 }
2355 }
2456
2557 /// Writes a string to the output device.
26 pub fn outputString(self: *const SimpleTextOutput, msg: [*:0]const u16) Status {
27 return self._output_string(self, msg);
58 ///
59 /// Returns `true` if the string was successfully written, `false` if an unknown glyph was encountered.
60 pub fn outputString(self: *SimpleTextOutput, msg: [*:0]const u16) OutputStringError!bool {
61 switch (self._output_string(self, msg)) {
62 .success => return true,
63 .warn_unknown_glyph => return false,
64 .device_error => return Error.DeviceError,
65 .unsupported => return Error.Unsupported,
66 else => |status| return uefi.unexpectedStatus(status),
67 }
2868 }
2969
3070 /// Verifies that all characters in a string can be output to the target device.
31 pub fn testString(self: *const SimpleTextOutput, msg: [*:0]const u16) Status {
32 return self._test_string(self, msg);
71 pub fn testString(self: *const SimpleTextOutput, msg: [*:0]const u16) uefi.UnexpectedError!bool {
72 switch (self._test_string(self, msg)) {
73 .success => return true,
74 .unsupported => return false,
75 else => |status| return uefi.unexpectedStatus(status),
76 }
3377 }
3478
3579 /// Returns information for an available text mode that the output device(s) supports.
36 pub fn queryMode(self: *const SimpleTextOutput, mode_number: usize, columns: *usize, rows: *usize) Status {
37 return self._query_mode(self, mode_number, columns, rows);
80 pub fn queryMode(self: *const SimpleTextOutput, mode_number: usize) QueryModeError!Geometry {
81 var geo: Geometry = undefined;
82 switch (self._query_mode(self, mode_number, &geo.columns, &geo.rows)) {
83 .success => return geo,
84 .device_error => return Error.DeviceError,
85 .unsupported => return Error.Unsupported,
86 else => |status| return uefi.unexpectedStatus(status),
87 }
3888 }
3989
4090 /// Sets the output device(s) to a specified mode.
41 pub fn setMode(self: *const SimpleTextOutput, mode_number: usize) Status {
42 return self._set_mode(self, mode_number);
91 pub fn setMode(self: *SimpleTextOutput, mode_number: usize) SetModeError!void {
92 switch (self._set_mode(self, mode_number)) {
93 .success => {},
94 .device_error => return Error.DeviceError,
95 .unsupported => return Error.Unsupported,
96 else => |status| return uefi.unexpectedStatus(status),
97 }
4398 }
4499
45100 /// Sets the background and foreground colors for the outputString() and clearScreen() functions.
46 pub fn setAttribute(self: *const SimpleTextOutput, attribute: usize) Status {
47 return self._set_attribute(self, attribute);
101 pub fn setAttribute(self: *SimpleTextOutput, attribute: Attribute) SetAttributeError!void {
102 const attr_as_num: u8 = @bitCast(attribute);
103 switch (self._set_attribute(self, @intCast(attr_as_num))) {
104 .success => {},
105 .device_error => return Error.DeviceError,
106 else => |status| return uefi.unexpectedStatus(status),
107 }
48108 }
49109
50110 /// Clears the output device(s) display to the currently selected background color.
51 pub fn clearScreen(self: *const SimpleTextOutput) Status {
52 return self._clear_screen(self);
111 pub fn clearScreen(self: *SimpleTextOutput) ClearScreenError!void {
112 switch (self._clear_screen(self)) {
113 .success => {},
114 .device_error => return Error.DeviceError,
115 .unsupported => return Error.Unsupported,
116 else => |status| return uefi.unexpectedStatus(status),
117 }
53118 }
54119
55120 /// Sets the current coordinates of the cursor position.
56 pub fn setCursorPosition(self: *const SimpleTextOutput, column: usize, row: usize) Status {
57 return self._set_cursor_position(self, column, row);
121 pub fn setCursorPosition(
122 self: *SimpleTextOutput,
123 column: usize,
124 row: usize,
125 ) SetCursorPositionError!void {
126 switch (self._set_cursor_position(self, column, row)) {
127 .success => {},
128 .device_error => return Error.DeviceError,
129 .unsupported => return Error.Unsupported,
130 else => |status| return uefi.unexpectedStatus(status),
131 }
58132 }
59133
60134 /// Makes the cursor visible or invisible.
61 pub fn enableCursor(self: *const SimpleTextOutput, visible: bool) Status {
62 return self._enable_cursor(self, visible);
135 pub fn enableCursor(self: *SimpleTextOutput, visible: bool) EnableCursorError!void {
136 switch (self._enable_cursor(self, visible)) {
137 .success => {},
138 .device_error => return Error.DeviceError,
139 .unsupported => return Error.Unsupported,
140 else => |status| return uefi.unexpectedStatus(status),
141 }
63142 }
64143
65144 pub const guid align(8) = Guid{
......@@ -118,31 +197,41 @@ pub const SimpleTextOutput = extern struct {
118197 pub const geometricshape_left_triangle: u16 = 0x25c4;
119198 pub const arrow_up: u16 = 0x2591;
120199 pub const arrow_down: u16 = 0x2593;
121 pub const black: u8 = 0x00;
122 pub const blue: u8 = 0x01;
123 pub const green: u8 = 0x02;
124 pub const cyan: u8 = 0x03;
125 pub const red: u8 = 0x04;
126 pub const magenta: u8 = 0x05;
127 pub const brown: u8 = 0x06;
128 pub const lightgray: u8 = 0x07;
129 pub const bright: u8 = 0x08;
130 pub const darkgray: u8 = 0x08;
131 pub const lightblue: u8 = 0x09;
132 pub const lightgreen: u8 = 0x0a;
133 pub const lightcyan: u8 = 0x0b;
134 pub const lightred: u8 = 0x0c;
135 pub const lightmagenta: u8 = 0x0d;
136 pub const yellow: u8 = 0x0e;
137 pub const white: u8 = 0x0f;
138 pub const background_black: u8 = 0x00;
139 pub const background_blue: u8 = 0x10;
140 pub const background_green: u8 = 0x20;
141 pub const background_cyan: u8 = 0x30;
142 pub const background_red: u8 = 0x40;
143 pub const background_magenta: u8 = 0x50;
144 pub const background_brown: u8 = 0x60;
145 pub const background_lightgray: u8 = 0x70;
200
201 pub const Attribute = packed struct(u8) {
202 foreground: ForegroundColor = .white,
203 background: BackgroundColor = .black,
204
205 pub const ForegroundColor = enum(u4) {
206 black,
207 blue,
208 green,
209 cyan,
210 red,
211 magenta,
212 brown,
213 lightgray,
214 darkgray,
215 lightblue,
216 lightgreen,
217 lightcyan,
218 lightred,
219 lightmagenta,
220 yellow,
221 white,
222 };
223
224 pub const BackgroundColor = enum(u4) {
225 black,
226 blue,
227 green,
228 cyan,
229 red,
230 magenta,
231 brown,
232 lightgray,
233 };
234 };
146235
147236 pub const Mode = extern struct {
148237 max_mode: u32, // specified as signed
......@@ -152,4 +241,9 @@ pub const SimpleTextOutput = extern struct {
152241 cursor_row: i32,
153242 cursor_visible: bool,
154243 };
244
245 pub const Geometry = struct {
246 columns: usize,
247 rows: usize,
248 };
155249};
lib/std/os/uefi/protocol/udp6.zig+153-14
......@@ -8,6 +8,7 @@ const Ip6 = uefi.protocol.Ip6;
88const ManagedNetworkConfigData = uefi.protocol.ManagedNetwork.Config;
99const SimpleNetwork = uefi.protocol.SimpleNetwork;
1010const cc = uefi.cc;
11const Error = Status.Error;
1112
1213pub const Udp6 = extern struct {
1314 _get_mode_data: *const fn (*const Udp6, ?*Config, ?*Ip6.Mode, ?*ManagedNetworkConfigData, ?*SimpleNetwork) callconv(cc) Status,
......@@ -18,32 +19,158 @@ pub const Udp6 = extern struct {
1819 _cancel: *const fn (*const Udp6, ?*CompletionToken) callconv(cc) Status,
1920 _poll: *const fn (*const Udp6) callconv(cc) Status,
2021
21 pub fn getModeData(self: *const Udp6, udp6_config_data: ?*Config, ip6_mode_data: ?*Ip6.Mode, mnp_config_data: ?*ManagedNetworkConfigData, snp_mode_data: ?*SimpleNetwork) Status {
22 return self._get_mode_data(self, udp6_config_data, ip6_mode_data, mnp_config_data, snp_mode_data);
22 pub const GetModeDataError = uefi.UnexpectedError || error{
23 NotStarted,
24 InvalidParameter,
25 };
26 pub const ConfigureError = uefi.UnexpectedError || error{
27 NoMapping,
28 InvalidParameter,
29 AlreadyStarted,
30 AccessDenied,
31 OutOfResources,
32 DeviceError,
33 };
34 pub const GroupsError = uefi.UnexpectedError || error{
35 NotStarted,
36 OutOfResources,
37 InvalidParameter,
38 AlreadyStarted,
39 NotFound,
40 DeviceError,
41 };
42 pub const TransmitError = uefi.UnexpectedError || error{
43 NotStarted,
44 NoMapping,
45 InvalidParameter,
46 AccessDenied,
47 NotReady,
48 OutOfResources,
49 NotFound,
50 BadBufferSize,
51 NoMedia,
52 };
53 pub const ReceiveError = uefi.UnexpectedError || error{
54 NotStarted,
55 NoMapping,
56 InvalidParameter,
57 OutOfResources,
58 DeviceError,
59 AccessDenied,
60 NotReady,
61 NoMedia,
62 };
63 pub const CancelError = uefi.UnexpectedError || error{
64 InvalidParameter,
65 NotStarted,
66 NotFound,
67 };
68 pub const PollError = uefi.UnexpectedError || error{
69 InvalidParameter,
70 DeviceError,
71 Timeout,
72 };
73
74 pub fn getModeData(self: *const Udp6) GetModeDataError!ModeData {
75 var data: ModeData = undefined;
76 switch (self._get_mode_data(
77 self,
78 &data.udp6_config_data,
79 &data.ip6_mode_data,
80 &data.mnp_config_data,
81 &data.snp_mode_data,
82 )) {
83 .success => return data,
84 .not_started => return Error.NotStarted,
85 .invalid_parameter => return Error.InvalidParameter,
86 else => |status| return uefi.unexpectedStatus(status),
87 }
2388 }
2489
25 pub fn configure(self: *const Udp6, udp6_config_data: ?*const Config) Status {
26 return self._configure(self, udp6_config_data);
90 pub fn configure(self: *Udp6, udp6_config_data: ?*const Config) ConfigureError!void {
91 switch (self._configure(self, udp6_config_data)) {
92 .success => {},
93 .no_mapping => return Error.NoMapping,
94 .invalid_parameter => return Error.InvalidParameter,
95 .already_started => return Error.AlreadyStarted,
96 .access_denied => return Error.AccessDenied,
97 .out_of_resources => return Error.OutOfResources,
98 .device_error => return Error.DeviceError,
99 else => |status| return uefi.unexpectedStatus(status),
100 }
27101 }
28102
29 pub fn groups(self: *const Udp6, join_flag: bool, multicast_address: ?*const Ip6.Address) Status {
30 return self._groups(self, join_flag, multicast_address);
103 pub fn groups(
104 self: *Udp6,
105 join_flag: JoinFlag,
106 multicast_address: ?*const Ip6.Address,
107 ) GroupsError!void {
108 switch (self._groups(
109 self,
110 // set to TRUE to join a multicast group
111 join_flag == .join,
112 multicast_address,
113 )) {
114 .success => {},
115 .not_started => return Error.NotStarted,
116 .out_of_resources => return Error.OutOfResources,
117 .invalid_parameter => return Error.InvalidParameter,
118 .already_started => return Error.AlreadyStarted,
119 .not_found => return Error.NotFound,
120 .device_error => return Error.DeviceError,
121 else => |status| return uefi.unexpectedStatus(status),
122 }
31123 }
32124
33 pub fn transmit(self: *const Udp6, token: *CompletionToken) Status {
34 return self._transmit(self, token);
125 pub fn transmit(self: *Udp6, token: *CompletionToken) TransmitError!void {
126 switch (self._transmit(self, token)) {
127 .success => {},
128 .not_started => return Error.NotStarted,
129 .no_mapping => return Error.NoMapping,
130 .invalid_parameter => return Error.InvalidParameter,
131 .access_denied => return Error.AccessDenied,
132 .not_ready => return Error.NotReady,
133 .out_of_resources => return Error.OutOfResources,
134 .not_found => return Error.NotFound,
135 .bad_buffer_size => return Error.BadBufferSize,
136 .no_media => return Error.NoMedia,
137 else => |status| return uefi.unexpectedStatus(status),
138 }
35139 }
36140
37 pub fn receive(self: *const Udp6, token: *CompletionToken) Status {
38 return self._receive(self, token);
141 pub fn receive(self: *Udp6, token: *CompletionToken) ReceiveError!void {
142 switch (self._receive(self, token)) {
143 .success => {},
144 .not_started => return Error.NotStarted,
145 .no_mapping => return Error.NoMapping,
146 .invalid_parameter => return Error.InvalidParameter,
147 .out_of_resources => return Error.OutOfResources,
148 .device_error => return Error.DeviceError,
149 .access_denied => return Error.AccessDenied,
150 .not_ready => return Error.NotReady,
151 .no_media => return Error.NoMedia,
152 else => |status| return uefi.unexpectedStatus(status),
153 }
39154 }
40155
41 pub fn cancel(self: *const Udp6, token: ?*CompletionToken) Status {
42 return self._cancel(self, token);
156 pub fn cancel(self: *Udp6, token: ?*CompletionToken) CancelError!void {
157 switch (self._cancel(self, token)) {
158 .success => {},
159 .invalid_parameter => return Error.InvalidParameter,
160 .not_started => return Error.NotStarted,
161 .not_found => return Error.NotFound,
162 else => |status| return uefi.unexpectedStatus(status),
163 }
43164 }
44165
45 pub fn poll(self: *const Udp6) Status {
46 return self._poll(self);
166 pub fn poll(self: *Udp6) PollError!void {
167 switch (self._poll(self)) {
168 .success => {},
169 .invalid_parameter => return Error.InvalidParameter,
170 .device_error => return Error.DeviceError,
171 .timeout => return Error.Timeout,
172 else => |status| return uefi.unexpectedStatus(status),
173 }
47174 }
48175
49176 pub const guid align(8) = uefi.Guid{
......@@ -55,6 +182,18 @@ pub const Udp6 = extern struct {
55182 .node = [_]u8{ 0x90, 0xe0, 0x60, 0xb3, 0x49, 0x55 },
56183 };
57184
185 pub const JoinFlag = enum {
186 join,
187 leave,
188 };
189
190 pub const ModeData = struct {
191 udp6_config_data: Config,
192 ip6_mode_data: Ip6.Mode,
193 mnp_config_data: ManagedNetworkConfigData,
194 snp_mode_data: SimpleNetwork,
195 };
196
58197 pub const Config = extern struct {
59198 accept_promiscuous: bool,
60199 accept_any_port: bool,
lib/std/os/uefi/protocol/udp6_service_binding.zig deleted-28
......@@ -1,28 +0,0 @@
1const std = @import("std");
2const uefi = std.os.uefi;
3const Handle = uefi.Handle;
4const Guid = uefi.Guid;
5const Status = uefi.Status;
6const cc = uefi.cc;
7
8pub const Udp6ServiceBinding = extern struct {
9 _create_child: *const fn (*const Udp6ServiceBinding, *?Handle) callconv(cc) Status,
10 _destroy_child: *const fn (*const Udp6ServiceBinding, Handle) callconv(cc) Status,
11
12 pub fn createChild(self: *const Udp6ServiceBinding, handle: *?Handle) Status {
13 return self._create_child(self, handle);
14 }
15
16 pub fn destroyChild(self: *const Udp6ServiceBinding, handle: Handle) Status {
17 return self._destroy_child(self, handle);
18 }
19
20 pub const guid align(8) = Guid{
21 .time_low = 0x66ed4721,
22 .time_mid = 0x3c98,
23 .time_high_and_version = 0x4d3e,
24 .clock_seq_high_and_reserved = 0x81,
25 .clock_seq_low = 0xe3,
26 .node = [_]u8{ 0xd0, 0x3d, 0xd3, 0x9a, 0x72, 0x54 },
27 };
28};