|
| 1 | +const std = @import("std"); |
| 2 | +const Allocator = std.mem.Allocator; |
| 3 | +const os = @import("../os.zig"); |
| 4 | + |
| 5 | +pub const ParamsGlobal = extern struct { |
| 6 | + features: u64, |
| 7 | + gpu_generation: u32, |
| 8 | + gpu_variant: u32, |
| 9 | + gpu_revision: u32, |
| 10 | + chip_id: u32, |
| 11 | + num_dies: u32, |
| 12 | + num_clusters_total: u32, |
| 13 | + num_cores_per_cluster: u32, |
| 14 | + max_frequency_khz: u32, |
| 15 | + core_masks: [64]u64, |
| 16 | + vm_start: u64, |
| 17 | + vm_end: u64, |
| 18 | + vm_kernel_min_size: u64, |
| 19 | + max_commands_per_submission: u32, |
| 20 | + max_attachments: u32, |
| 21 | + command_timestamp_frequency_hz: u64, |
| 22 | +}; |
| 23 | + |
| 24 | +pub const GetParams = extern struct { |
| 25 | + group: u32, |
| 26 | + pad: u32 = 0, |
| 27 | + pointer: u64, |
| 28 | + size: u64, |
| 29 | + |
| 30 | + pub const req = os.IOCTL.IOWR(0x40, GetParams); |
| 31 | + |
| 32 | + pub fn get(self: *GetParams, fd: std.posix.fd_t) !void { |
| 33 | + return switch (std.posix.errno(os.ioctl(fd, req, @intFromPtr(self)))) { |
| 34 | + .SUCCESS => {}, |
| 35 | + .ACCES => error.AccessDenied, |
| 36 | + .PERM => error.PermissionDenied, |
| 37 | + .BADF => error.NotOpenForWriting, |
| 38 | + .NOENT => error.NotFound, |
| 39 | + .FAULT => unreachable, |
| 40 | + .INVAL => unreachable, |
| 41 | + .NOTTY => error.NotATerminal, |
| 42 | + .OPNOTSUPP => error.NotSupported, |
| 43 | + else => |e| std.posix.unexpectedErrno(e), |
| 44 | + }; |
| 45 | + } |
| 46 | +}; |
| 47 | + |
| 48 | +pub const GetTime = extern struct { |
| 49 | + flags: u64 = 0, |
| 50 | + gpu_timestamp: u64 = 0, |
| 51 | + |
| 52 | + pub const req = os.IOCTL.IOWR(0x41, GetTime); |
| 53 | + |
| 54 | + pub fn get(self: *GetTime, fd: std.posix.fd_t) !void { |
| 55 | + return switch (std.posix.errno(os.ioctl(fd, req, @intFromPtr(self)))) { |
| 56 | + .SUCCESS => {}, |
| 57 | + .ACCES => error.AccessDenied, |
| 58 | + .PERM => error.PermissionDenied, |
| 59 | + .BADF => error.NotOpenForWriting, |
| 60 | + .NOENT => error.NotFound, |
| 61 | + .FAULT => unreachable, |
| 62 | + .INVAL => unreachable, |
| 63 | + .NOTTY => error.NotATerminal, |
| 64 | + .OPNOTSUPP => error.NotSupported, |
| 65 | + else => |e| std.posix.unexpectedErrno(e), |
| 66 | + }; |
| 67 | + } |
| 68 | +}; |
0 commit comments