Skip to content

Commit 49894df

Browse files
feat: adding gem
1 parent da2b48a commit 49894df

File tree

3 files changed

+141
-0
lines changed

3 files changed

+141
-0
lines changed

libdrm/types.zig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ const std = @import("std");
22
const Allocator = std.mem.Allocator;
33
const os = @import("os.zig");
44

5+
pub const amdgpu = @import("types/amdgpu.zig");
6+
57
pub usingnamespace @import("types/base.zig");
8+
pub usingnamespace @import("types/gem.zig");
69
pub usingnamespace @import("types/map.zig");
710
pub usingnamespace @import("types/mode.zig");
811
pub usingnamespace @import("types/mode/crtc.zig");

libdrm/types/amdgpu.zig

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
const std = @import("std");
2+
const Allocator = std.mem.Allocator;
3+
const os = @import("../os.zig");
4+
5+
pub const GemCreate = extern union {
6+
in: In,
7+
out: Out,
8+
9+
pub const req = os.IOCTL.IOWR(0x40, GemCreate);
10+
11+
pub fn get(self: *GemCreate, fd: std.os.fd_t) !void {
12+
return switch (std.os.errno(os.ioctl(fd, req, @intFromPtr(self)))) {
13+
.SUCCESS => {},
14+
.BADF => error.NotOpenForWriting,
15+
.NOENT => error.NotFound,
16+
.FAULT => unreachable,
17+
.INVAL => unreachable,
18+
.NOTTY => error.NotATerminal,
19+
.OPNOTSUPP => error.NotSupported,
20+
else => |e| std.os.unexpectedErrno(e),
21+
};
22+
}
23+
24+
pub const DomainFlags = packed struct(u64) {
25+
cpu: u1 = 0,
26+
gtt: u1 = 0,
27+
vram: u1 = 0,
28+
gds: u1 = 0,
29+
gwd: u1 = 0,
30+
oa: u1 = 0,
31+
padding: u58 = 0,
32+
};
33+
34+
pub const In = extern struct {
35+
boSize: u64 = 0,
36+
alignment: u64 = 0,
37+
domains: u64 = 0,
38+
domainFlags: DomainFlags = .{},
39+
};
40+
41+
pub const Out = extern struct {
42+
handle: u32 = 0,
43+
pad: u32 = 0,
44+
};
45+
};
46+
47+
pub const GemMmap = extern union {
48+
in: In,
49+
out: Out,
50+
51+
pub const req = os.IOCTL.IOWR(0x41, GemMmap);
52+
53+
pub fn get(self: *GemMmap, fd: std.os.fd_t) !void {
54+
return switch (std.os.errno(os.ioctl(fd, req, @intFromPtr(self)))) {
55+
.SUCCESS => {},
56+
.BADF => error.NotOpenForWriting,
57+
.NOENT => error.NotFound,
58+
.FAULT => unreachable,
59+
.INVAL => unreachable,
60+
.NOTTY => error.NotATerminal,
61+
.OPNOTSUPP => error.NotSupported,
62+
else => |e| std.os.unexpectedErrno(e),
63+
};
64+
}
65+
66+
pub const In = extern struct {
67+
handle: u32 = 0,
68+
pad: u32 = 0,
69+
};
70+
71+
pub const Out = extern struct {
72+
addr: u64 = 0,
73+
};
74+
};

libdrm/types/gem.zig

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
const std = @import("std");
2+
const Allocator = std.mem.Allocator;
3+
const os = @import("../os.zig");
4+
5+
pub const GemClose = extern struct {
6+
handle: u32 = 0,
7+
pad: u32 = 0,
8+
9+
pub const req = os.IOCTL.IOW(0x9, GemClose);
10+
11+
pub fn get(self: *GemClose, fd: std.os.fd_t) !void {
12+
return switch (std.os.errno(os.ioctl(fd, req, @intFromPtr(self)))) {
13+
.SUCCESS => {},
14+
.BADF => error.NotOpenForWriting,
15+
.NOENT => error.NotFound,
16+
.FAULT => unreachable,
17+
.INVAL => unreachable,
18+
.NOTTY => error.NotATerminal,
19+
.OPNOTSUPP => error.NotSupported,
20+
else => |e| std.os.unexpectedErrno(e),
21+
};
22+
}
23+
};
24+
25+
pub const GemFlink = extern struct {
26+
handle: u32 = 0,
27+
name: u32 = 0,
28+
29+
pub const req = os.IOCTL.IOWR(0xA, GemFlink);
30+
31+
pub fn get(self: *GemFlink, fd: std.os.fd_t) !void {
32+
return switch (std.os.errno(os.ioctl(fd, req, @intFromPtr(self)))) {
33+
.SUCCESS => {},
34+
.BADF => error.NotOpenForWriting,
35+
.NOENT => error.NotFound,
36+
.FAULT => unreachable,
37+
.INVAL => unreachable,
38+
.NOTTY => error.NotATerminal,
39+
.OPNOTSUPP => error.NotSupported,
40+
else => |e| std.os.unexpectedErrno(e),
41+
};
42+
}
43+
};
44+
45+
pub const GemOpen = extern struct {
46+
name: u32 = 0,
47+
handle: u32 = 0,
48+
size: u64 = 0,
49+
50+
pub const req = os.IOCTL.IOWR(0xB, GemOpen);
51+
52+
pub fn get(self: *GemOpen, fd: std.os.fd_t) !void {
53+
return switch (std.os.errno(os.ioctl(fd, req, @intFromPtr(self)))) {
54+
.SUCCESS => {},
55+
.BADF => error.NotOpenForWriting,
56+
.NOENT => error.NotFound,
57+
.FAULT => unreachable,
58+
.INVAL => unreachable,
59+
.NOTTY => error.NotATerminal,
60+
.OPNOTSUPP => error.NotSupported,
61+
else => |e| std.os.unexpectedErrno(e),
62+
};
63+
}
64+
};

0 commit comments

Comments
 (0)