1const std = @import("std");
2const uefi = std.os.uefi;
3const Guid = uefi.Guid;
4const Status = uefi.Status;
5const hii = uefi.hii;
6const cc = uefi.cc;
7
8/// Database manager for HII-related data structures.
9pub const HiiDatabase = extern struct {
10 _new_package_list: Status, // TODO
11 _remove_package_list: *const fn (*HiiDatabase, hii.Handle) callconv(cc) Status,
12 _update_package_list: *const fn (*HiiDatabase, hii.Handle, *const hii.PackageList) callconv(cc) Status,
13 _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 _register_package_notify: Status, // TODO
16 _unregister_package_notify: Status, // TODO
17 _find_keyboard_layouts: Status, // TODO
18 _get_keyboard_layout: Status, // TODO
19 _set_keyboard_layout: Status, // TODO
20 _get_package_list_handle: Status, // TODO
21
22 pub const RemovePackageListError = uefi.UnexpectedError || error{NotFound};
23 pub const UpdatePackageListError = uefi.UnexpectedError || error{
24 OutOfResources,
25 InvalidParameter,
26 NotFound,
27 };
28 pub const ListPackageListsError = uefi.UnexpectedError || error{
29 BufferTooSmall,
30 InvalidParameter,
31 NotFound,
32 };
33 pub const ExportPackageListError = uefi.UnexpectedError || error{
34 BufferTooSmall,
35 InvalidParameter,
36 NotFound,
37 };
38
39 /// Removes a package list from the HII database.
40 pub fn removePackageList(self: *HiiDatabase, handle: hii.Handle) RemovePackageListError!void {
41 switch (self._remove_package_list(self, handle)) {
42 .success => {},
43 .not_found => return error.NotFound,
44 else => |status| return uefi.unexpectedStatus(status),
45 }
46 }
47
48 /// Update a package list in the HII database.
49 pub fn updatePackageList(
50 self: *HiiDatabase,
51 handle: hii.Handle,
52 buffer: *const hii.PackageList,
53 ) UpdatePackageListError!void {
54 switch (self._update_package_list(self, handle, buffer)) {
55 .success => {},
56 .out_of_resources => return error.OutOfResources,
57 .invalid_parameter => return error.InvalidParameter,
58 .not_found => return error.NotFound,
59 else => |status| return uefi.unexpectedStatus(status),
60 }
61 }
62
63 /// Determines the handles that are currently active in the database.
64 pub fn listPackageLists(
65 self: *const HiiDatabase,
66 package_type: u8,
67 package_guid: ?*const Guid,
68 handles: []hii.Handle,
69 ) ListPackageListsError![]hii.Handle {
70 var len: usize = handles.len;
71 switch (self._list_package_lists(
72 self,
73 package_type,
74 package_guid,
75 &len,
76 handles.ptr,
77 )) {
78 .success => return handles[0..len],
79 .buffer_too_small => return error.BufferTooSmall,
80 .invalid_parameter => return error.InvalidParameter,
81 .not_found => return error.NotFound,
82 else => |status| return uefi.unexpectedStatus(status),
83 }
84 }
85
86 /// Exports the contents of one or all package lists in the HII database into a buffer.
87 pub fn exportPackageLists(
88 self: *const HiiDatabase,
89 handle: ?hii.Handle,
90 buffer: []hii.PackageList,
91 ) ExportPackageListError![]hii.PackageList {
92 var len = buffer.len;
93 switch (self._export_package_lists(self, handle, &len, buffer.ptr)) {
94 .success => return buffer[0..len],
95 .buffer_too_small => return error.BufferTooSmall,
96 .invalid_parameter => return error.InvalidParameter,
97 .not_found => return error.NotFound,
98 else => |status| return uefi.unexpectedStatus(status),
99 }
100 }
101
102 pub const guid align(8) = Guid{
103 .time_low = 0xef9fc172,
104 .time_mid = 0xa1b2,
105 .time_high_and_version = 0x4693,
106 .clock_seq_high_and_reserved = 0xb3,
107 .clock_seq_low = 0x27,
108 .node = [_]u8{ 0x6d, 0x32, 0xfc, 0x41, 0x60, 0x42 },
109 };
110};