Skip to content

Commit

Permalink
Merge pull request ziglang#22820 from linusg/uefi-tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
linusg authored Feb 9, 2025
2 parents 604ed52 + 0660f5b commit 0af492a
Show file tree
Hide file tree
Showing 23 changed files with 324 additions and 280 deletions.
2 changes: 1 addition & 1 deletion lib/std/Target.zig
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ pub const Os = struct {
.uefi => .{
.semver = .{
.min = .{ .major = 2, .minor = 0, .patch = 0 },
.max = .{ .major = 2, .minor = 9, .patch = 0 },
.max = .{ .major = 2, .minor = 11, .patch = 0 },
},
},

Expand Down
2 changes: 1 addition & 1 deletion lib/std/debug.zig
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ pub fn defaultPanic(
// ExitData buffer must be allocated using boot_services.allocatePool (spec: page 220)
const exit_data: []u16 = uefi.raw_pool_allocator.alloc(u16, exit_msg.len + 1) catch @trap();
@memcpy(exit_data, exit_msg[0..exit_data.len]); // Includes null terminator.
_ = bs.exit(uefi.handle, .Aborted, exit_data.len, exit_data.ptr);
_ = bs.exit(uefi.handle, .aborted, exit_data.len, exit_data.ptr);
}
@trap();
},
Expand Down
6 changes: 3 additions & 3 deletions lib/std/os/uefi.zig
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ pub const hii = @import("uefi/hii.zig");
pub const Status = @import("uefi/status.zig").Status;
pub const tables = @import("uefi/tables.zig");

/// The memory type to allocate when using the pool
/// Defaults to .LoaderData, the default data allocation type
/// The memory type to allocate when using the pool.
/// Defaults to `.loader_data`, the default data allocation type
/// used by UEFI applications to allocate pool memory.
pub var efi_pool_memory_type: tables.MemoryType = .LoaderData;
pub var efi_pool_memory_type: tables.MemoryType = .loader_data;
pub const pool_allocator = @import("uefi/pool_allocator.zig").pool_allocator;
pub const raw_pool_allocator = @import("uefi/pool_allocator.zig").raw_pool_allocator;

Expand Down
172 changes: 86 additions & 86 deletions lib/std/os/uefi/device_path.zig
Original file line number Diff line number Diff line change
Expand Up @@ -230,56 +230,56 @@ pub const DevicePath = union(Type) {
};

pub const Messaging = union(Subtype) {
Atapi: *const AtapiDevicePath,
Scsi: *const ScsiDevicePath,
FibreChannel: *const FibreChannelDevicePath,
FibreChannelEx: *const FibreChannelExDevicePath,
atapi: *const AtapiDevicePath,
scsi: *const ScsiDevicePath,
fibre_channel: *const FibreChannelDevicePath,
fibre_channel_ex: *const FibreChannelExDevicePath,
@"1394": *const F1394DevicePath,
Usb: *const UsbDevicePath,
Sata: *const SataDevicePath,
UsbWwid: *const UsbWwidDevicePath,
Lun: *const DeviceLogicalUnitDevicePath,
UsbClass: *const UsbClassDevicePath,
I2o: *const I2oDevicePath,
MacAddress: *const MacAddressDevicePath,
Ipv4: *const Ipv4DevicePath,
Ipv6: *const Ipv6DevicePath,
Vlan: *const VlanDevicePath,
InfiniBand: *const InfiniBandDevicePath,
Uart: *const UartDevicePath,
Vendor: *const VendorDefinedDevicePath,
usb: *const UsbDevicePath,
sata: *const SataDevicePath,
usb_wwid: *const UsbWwidDevicePath,
lun: *const DeviceLogicalUnitDevicePath,
usb_class: *const UsbClassDevicePath,
i2o: *const I2oDevicePath,
mac_address: *const MacAddressDevicePath,
ipv4: *const Ipv4DevicePath,
ipv6: *const Ipv6DevicePath,
vlan: *const VlanDevicePath,
infini_band: *const InfiniBandDevicePath,
uart: *const UartDevicePath,
vendor: *const VendorDefinedDevicePath,

pub const Subtype = enum(u8) {
Atapi = 1,
Scsi = 2,
FibreChannel = 3,
FibreChannelEx = 21,
atapi = 1,
scsi = 2,
fibre_channel = 3,
fibre_channel_ex = 21,
@"1394" = 4,
Usb = 5,
Sata = 18,
UsbWwid = 16,
Lun = 17,
UsbClass = 15,
I2o = 6,
MacAddress = 11,
Ipv4 = 12,
Ipv6 = 13,
Vlan = 20,
InfiniBand = 9,
Uart = 14,
Vendor = 10,
usb = 5,
sata = 18,
usb_wwid = 16,
lun = 17,
usb_class = 15,
i2o = 6,
mac_address = 11,
ipv4 = 12,
ipv6 = 13,
vlan = 20,
infini_band = 9,
uart = 14,
vendor = 10,
_,
};

pub const AtapiDevicePath = extern struct {
const Role = enum(u8) {
Master = 0,
Slave = 1,
pub const Role = enum(u8) {
master = 0,
slave = 1,
};

const Rank = enum(u8) {
Primary = 0,
Secondary = 1,
pub const Rank = enum(u8) {
primary = 0,
secondary = 1,
};

type: DevicePath.Type,
Expand Down Expand Up @@ -528,8 +528,8 @@ pub const DevicePath = union(Type) {

pub const Ipv4DevicePath = extern struct {
pub const IpType = enum(u8) {
Dhcp = 0,
Static = 1,
dhcp = 0,
static = 1,
};

type: DevicePath.Type,
Expand Down Expand Up @@ -564,9 +564,9 @@ pub const DevicePath = union(Type) {

pub const Ipv6DevicePath = extern struct {
pub const Origin = enum(u8) {
Manual = 0,
AssignedStateless = 1,
AssignedStateful = 2,
manual = 0,
assigned_stateless = 1,
assigned_stateful = 2,
};

type: DevicePath.Type,
Expand Down Expand Up @@ -619,8 +619,8 @@ pub const DevicePath = union(Type) {
pub const InfiniBandDevicePath = extern struct {
pub const ResourceFlags = packed struct(u32) {
pub const ControllerType = enum(u1) {
Ioc = 0,
Service = 1,
ioc = 0,
service = 1,
};

ioc_or_service: ControllerType,
Expand Down Expand Up @@ -659,20 +659,20 @@ pub const DevicePath = union(Type) {

pub const UartDevicePath = extern struct {
pub const Parity = enum(u8) {
Default = 0,
None = 1,
Even = 2,
Odd = 3,
Mark = 4,
Space = 5,
default = 0,
none = 1,
even = 2,
odd = 3,
mark = 4,
space = 5,
_,
};

pub const StopBits = enum(u8) {
Default = 0,
One = 1,
OneAndAHalf = 2,
Two = 3,
default = 0,
one = 1,
one_and_a_half = 2,
two = 3,
_,
};

Expand Down Expand Up @@ -719,40 +719,40 @@ pub const DevicePath = union(Type) {
};

pub const Media = union(Subtype) {
HardDrive: *const HardDriveDevicePath,
Cdrom: *const CdromDevicePath,
Vendor: *const VendorDevicePath,
FilePath: *const FilePathDevicePath,
MediaProtocol: *const MediaProtocolDevicePath,
PiwgFirmwareFile: *const PiwgFirmwareFileDevicePath,
PiwgFirmwareVolume: *const PiwgFirmwareVolumeDevicePath,
RelativeOffsetRange: *const RelativeOffsetRangeDevicePath,
RamDisk: *const RamDiskDevicePath,
hard_drive: *const HardDriveDevicePath,
cdrom: *const CdromDevicePath,
vendor: *const VendorDevicePath,
file_path: *const FilePathDevicePath,
media_protocol: *const MediaProtocolDevicePath,
piwg_firmware_file: *const PiwgFirmwareFileDevicePath,
piwg_firmware_volume: *const PiwgFirmwareVolumeDevicePath,
relative_offset_range: *const RelativeOffsetRangeDevicePath,
ram_disk: *const RamDiskDevicePath,

pub const Subtype = enum(u8) {
HardDrive = 1,
Cdrom = 2,
Vendor = 3,
FilePath = 4,
MediaProtocol = 5,
PiwgFirmwareFile = 6,
PiwgFirmwareVolume = 7,
RelativeOffsetRange = 8,
RamDisk = 9,
hard_drive = 1,
cdrom = 2,
vendor = 3,
file_path = 4,
media_protocol = 5,
piwg_firmware_file = 6,
piwg_firmware_volume = 7,
relative_offset_range = 8,
ram_disk = 9,
_,
};

pub const HardDriveDevicePath = extern struct {
pub const Format = enum(u8) {
LegacyMbr = 0x01,
GuidPartitionTable = 0x02,
legacy_mbr = 0x01,
guid_partition_table = 0x02,
};

pub const SignatureType = enum(u8) {
NoSignature = 0x00,
no_signature = 0x00,
/// "32-bit signature from address 0x1b8 of the type 0x01 MBR"
MbrSignature = 0x01,
GuidSignature = 0x02,
mbr_signature = 0x01,
guid_signature = 0x02,
};

type: DevicePath.Type,
Expand Down Expand Up @@ -935,10 +935,10 @@ pub const DevicePath = union(Type) {
};

pub const BiosBootSpecification = union(Subtype) {
BBS101: *const BBS101DevicePath,
bbs101: *const BBS101DevicePath,

pub const Subtype = enum(u8) {
BBS101 = 1,
bbs101 = 1,
_,
};

Expand Down Expand Up @@ -967,12 +967,12 @@ pub const DevicePath = union(Type) {
};

pub const End = union(Subtype) {
EndEntire: *const EndEntireDevicePath,
EndThisInstance: *const EndThisInstanceDevicePath,
end_entire: *const EndEntireDevicePath,
end_this_instance: *const EndThisInstanceDevicePath,

pub const Subtype = enum(u8) {
EndEntire = 0xff,
EndThisInstance = 0x01,
end_entire = 0xff,
end_this_instance = 0x01,
_,
};

Expand Down
4 changes: 2 additions & 2 deletions lib/std/os/uefi/pool_allocator.zig
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const UefiPoolAllocator = struct {
const full_len = metadata_len + len;

var unaligned_ptr: [*]align(8) u8 = undefined;
if (uefi.system_table.boot_services.?.allocatePool(uefi.efi_pool_memory_type, full_len, &unaligned_ptr) != .Success) return null;
if (uefi.system_table.boot_services.?.allocatePool(uefi.efi_pool_memory_type, full_len, &unaligned_ptr) != .success) return null;

const unaligned_addr = @intFromPtr(unaligned_ptr);
const aligned_addr = mem.alignForward(usize, unaligned_addr + @sizeOf(usize), ptr_align);
Expand Down Expand Up @@ -118,7 +118,7 @@ fn uefi_alloc(
std.debug.assert(@intFromEnum(alignment) <= 3);

var ptr: [*]align(8) u8 = undefined;
if (uefi.system_table.boot_services.?.allocatePool(uefi.efi_pool_memory_type, len, &ptr) != .Success) return null;
if (uefi.system_table.boot_services.?.allocatePool(uefi.efi_pool_memory_type, len, &ptr) != .success) return null;

return ptr;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/std/os/uefi/protocol/block_io.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub const BlockIo = extern struct {
const Self = @This();

revision: u64,
media: *EfiBlockMedia,
media: *BlockMedia,

_reset: *const fn (*BlockIo, extended_verification: bool) callconv(cc) Status,
_read_blocks: *const fn (*BlockIo, media_id: u32, lba: u64, buffer_size: usize, buf: [*]u8) callconv(cc) Status,
Expand Down Expand Up @@ -43,7 +43,7 @@ pub const BlockIo = extern struct {
.node = [_]u8{ 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b },
};

pub const EfiBlockMedia = extern struct {
pub const BlockMedia = extern struct {
/// The current media ID. If the media changes, this value is changed.
media_id: u32,

Expand Down
14 changes: 7 additions & 7 deletions lib/std/os/uefi/protocol/device_path.zig
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub const DevicePath = extern struct {

/// Returns the next DevicePath node in the sequence, if any.
pub fn next(self: *DevicePath) ?*DevicePath {
if (self.type == .End and @as(uefi.DevicePath.End.Subtype, @enumFromInt(self.subtype)) == .EndEntire)
if (self.type == .end and @as(uefi.DevicePath.End.Subtype, @enumFromInt(self.subtype)) == .end_entire)
return null;

return @as(*DevicePath, @ptrCast(@as([*]u8, @ptrCast(self)) + self.length));
Expand Down Expand Up @@ -55,8 +55,8 @@ pub const DevicePath = extern struct {
// as the end node itself is 4 bytes (type: u8 + subtype: u8 + length: u16).
var new = @as(*uefi.DevicePath.Media.FilePathDevicePath, @ptrCast(buf.ptr + path_size - 4));

new.type = .Media;
new.subtype = .FilePath;
new.type = .media;
new.subtype = .file_path;
new.length = @sizeOf(uefi.DevicePath.Media.FilePathDevicePath) + 2 * (@as(u16, @intCast(path.len)) + 1);

// The same as new.getPath(), but not const as we're filling it in.
Expand All @@ -68,8 +68,8 @@ pub const DevicePath = extern struct {
ptr[path.len] = 0;

var end = @as(*uefi.DevicePath.End.EndEntireDevicePath, @ptrCast(@as(*DevicePath, @ptrCast(new)).next().?));
end.type = .End;
end.subtype = .EndEntire;
end.type = .end;
end.subtype = .end_entire;
end.length = @sizeOf(uefi.DevicePath.End.EndEntireDevicePath);

return @as(*DevicePath, @ptrCast(buf.ptr));
Expand All @@ -84,7 +84,7 @@ pub const DevicePath = extern struct {
if (self.type == enum_value) {
const subtype = self.initSubtype(ufield.type);
if (subtype) |sb| {
// e.g. return .{ .Hardware = .{ .Pci = @ptrCast(...) } }
// e.g. return .{ .hardware = .{ .pci = @ptrCast(...) } }
return @unionInit(uefi.DevicePath, ufield.name, sb);
}
}
Expand All @@ -102,7 +102,7 @@ pub const DevicePath = extern struct {
const tag_val: u8 = @intFromEnum(@field(TTag, subtype.name));

if (self.subtype == tag_val) {
// e.g. expr = .{ .Pci = @ptrCast(...) }
// e.g. expr = .{ .pci = @ptrCast(...) }
return @unionInit(TUnion, subtype.name, @as(subtype.type, @ptrCast(self)));
}
}
Expand Down
Loading

0 comments on commit 0af492a

Please sign in to comment.