authorgravatar for ybham6@gmail.comYusuf Bham <ybham6@gmail.com> 2022-04-16 16:38:27-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-04-19 19:51:19-04:00
log2fa7f6e502724487e13a0a0b482bf499352746b2
treefbc11bc0ce6bb23cb8a7fb8d24766c56a886dd8f
parent859ae152bc83ca759f466794b8186fa0d3de5060

std.os.uefi: Add `BlockIoProtocol`


2 files changed, 82 insertions(+), 1 deletions(-)

lib/std/os/uefi/protocols.zig+2-1
......@@ -4,9 +4,10 @@ pub usingnamespace @import("protocols/device_path_protocol.zig");
44pub usingnamespace @import("protocols/rng_protocol.zig");
55pub usingnamespace @import("protocols/shell_parameters_protocol.zig");
66
7// Files
7// Files / IO
88pub usingnamespace @import("protocols/simple_file_system_protocol.zig");
99pub usingnamespace @import("protocols/file_protocol.zig");
10pub usingnamespace @import("protocols/block_io_protocol.zig");
1011
1112// Text
1213pub usingnamespace @import("protocols/simple_text_input_protocol.zig");
lib/std/os/uefi/protocols/block_io_protocol.zig created+80
......@@ -0,0 +1,80 @@
1const std = @import("std");
2const uefi = std.os.uefi;
3const Status = uefi.Status;
4
5const EfiBlockMedia = extern struct {
6 /// The current media ID. If the media changes, this value is changed.
7 media_id: u32,
8
9 /// `true` if the media is removable; otherwise, `false`.
10 removable_media: bool,
11 /// `true` if there is a media currently present in the device
12 media_present: bool,
13 /// `true` if the `BlockIoProtocol` was produced to abstract
14 /// partition structures on the disk. `false` if the `BlockIoProtocol` was
15 /// produced to abstract the logical blocks on a hardware device.
16 logical_partition: bool,
17 /// `true` if the media is marked read-only otherwise, `false`. This field
18 /// shows the read-only status as of the most recent `WriteBlocks()`
19 read_only: bool,
20 /// `true` if the WriteBlocks() function caches write data.
21 write_caching: bool,
22
23 /// The intrinsic block size of the device. If the media changes, then this
24 // field is updated. Returns the number of bytes per logical block.
25 block_size: u32,
26 /// Supplies the alignment requirement for any buffer used in a data
27 /// transfer. IoAlign values of 0 and 1 mean that the buffer can be
28 /// placed anywhere in memory. Otherwise, IoAlign must be a power of
29 /// 2, and the requirement is that the start address of a buffer must be
30 /// evenly divisible by IoAlign with no remainder.
31 io_align: u32,
32 /// The last LBA on the device. If the media changes, then this field is updated.
33 last_block: u64,
34
35 // Revision 2
36 lowest_aligned_lba: u64,
37 logical_blocks_per_physical_block: u32,
38 optimal_transfer_length_granularity: u32,
39};
40
41const BlockIoProtocol = extern struct {
42 const Self = @This();
43
44 revision: u64,
45 media: *EfiBlockMedia,
46
47 _reset: fn (*BlockIoProtocol, extended_verification: bool) callconv(.C) Status,
48 _read_blocks: fn (*BlockIoProtocol, media_id: u32, lba: u64, buffer_size: usize, buf: [*]u8) callconv(.C) Status,
49 _write_blocks: fn (*BlockIoProtocol, media_id: u32, lba: u64, buffer_size: usize, buf: [*]u8) callconv(.C) Status,
50 _flush_blocks: fn (*BlockIoProtocol) callconv(.C) Status,
51
52 /// Resets the block device hardware.
53 pub fn reset(self: *Self, extended_verification: bool) Status {
54 return self._reset(self, extended_verification);
55 }
56
57 /// Reads the number of requested blocks from the device.
58 pub fn readBlocks(self: *Self, media_id: u32, lba: u64, buffer_size: usize, buf: [*]u8) Status {
59 return self._read_blocks(self, media_id, lba, buffer_size, buf);
60 }
61
62 /// Writes a specified number of blocks to the device.
63 pub fn writeBlocks(self: *Self, media_id: u32, lba: u64, buffer_size: usize, buf: [*]u8) Status {
64 return self._write_blocks(self, media_id, lba, buffer_size, buf);
65 }
66
67 /// Flushes all modified data to a physical block device.
68 pub fn flushBlocks(self: *Self) Status {
69 return self._flush_blocks(self);
70 }
71
72 pub const guid align(8) = uefi.Guid{
73 .time_low = 0x964e5b21,
74 .time_mid = 0x6459,
75 .time_high_and_version = 0x11d2,
76 .clock_seq_high_and_reserved = 0x8e,
77 .clock_seq_low = 0x39,
78 .node = [_]u8{ 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b },
79 };
80};