Skip to content

Commit 0ee2e52

Browse files
feat: add map
1 parent 443df51 commit 0ee2e52

File tree

3 files changed

+91
-2
lines changed

3 files changed

+91
-2
lines changed

libdrm/types.zig

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

55
pub usingnamespace @import("types/base.zig");
6+
pub usingnamespace @import("types/map.zig");
67
pub usingnamespace @import("types/mode.zig");
78
pub usingnamespace @import("types/mode/crtc.zig");
89
pub usingnamespace @import("types/mode/conn.zig");

libdrm/types/base.zig

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,23 @@ pub const Unique = extern struct {
66
len: usize = 0,
77
value: [*]u8 = undefined,
88

9-
pub const req = os.IOCTL.IOWR(0x1, Unique);
9+
pub const reqGet = os.IOCTL.IOWR(0x1, Unique);
10+
pub const reqSet = os.IOCTL.IOWR(0x10, Unique);
1011

1112
pub fn get(self: *Unique, fd: std.os.fd_t) !void {
12-
return switch (std.os.errno(os.ioctl(fd, req, @intFromPtr(self)))) {
13+
return switch (std.os.errno(os.ioctl(fd, reqGet, @intFromPtr(self)))) {
14+
.SUCCESS => {},
15+
.BADF => error.NotOpenForWriting,
16+
.NOENT => error.NotFound,
17+
.FAULT => unreachable,
18+
.INVAL => unreachable,
19+
.NOTTY => error.NotATerminal,
20+
else => |e| std.os.unexpectedErrno(e),
21+
};
22+
}
23+
24+
pub fn set(self: *Unique, fd: std.os.fd_t) !void {
25+
return switch (std.os.errno(os.ioctl(fd, reqSet, @intFromPtr(self)))) {
1326
.SUCCESS => {},
1427
.BADF => error.NotOpenForWriting,
1528
.NOENT => error.NotFound,

libdrm/types/map.zig

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
const std = @import("std");
2+
const Allocator = std.mem.Allocator;
3+
const os = @import("../os.zig");
4+
5+
pub const Map = extern struct {
6+
offset: c_ulong = 0,
7+
size: c_ulong = 0,
8+
type: Type = undefined,
9+
flags: u8 = 0,
10+
handle: usize = 0,
11+
mtrr: c_int = 0,
12+
13+
pub const reqGet = os.IOCTL.IOWR(0x4, Map);
14+
pub const reqAdd = os.IOCTL.IOWR(0x15, Map);
15+
pub const reqRemove = os.IOCTL.IOWR(0x1B, Map);
16+
17+
pub fn get(self: *Map, fd: std.os.fd_t) !void {
18+
return switch (std.os.errno(os.ioctl(fd, reqGet, @intFromPtr(self)))) {
19+
.SUCCESS => {},
20+
.BADF => error.NotOpenForWriting,
21+
.NOENT => error.NotFound,
22+
.FAULT => unreachable,
23+
.INVAL => unreachable,
24+
.NOTTY => error.NotATerminal,
25+
.OPNOTSUPP => error.NotSupported,
26+
else => |e| std.os.unexpectedErrno(e),
27+
};
28+
}
29+
30+
pub fn add(self: *Map, fd: std.os.fd_t) !void {
31+
return switch (std.os.errno(os.ioctl(fd, reqAdd, @intFromPtr(self)))) {
32+
.SUCCESS => {},
33+
.BADF => error.NotOpenForWriting,
34+
.NOENT => error.NotFound,
35+
.FAULT => unreachable,
36+
.INVAL => unreachable,
37+
.NOTTY => error.NotATerminal,
38+
.OPNOTSUPP => error.NotSupported,
39+
else => |e| std.os.unexpectedErrno(e),
40+
};
41+
}
42+
43+
pub fn remove(self: *Map, fd: std.os.fd_t) !void {
44+
return switch (std.os.errno(os.ioctl(fd, reqRemove, @intFromPtr(self)))) {
45+
.SUCCESS => {},
46+
.BADF => error.NotOpenForWriting,
47+
.NOENT => error.NotFound,
48+
.FAULT => unreachable,
49+
.INVAL => unreachable,
50+
.NOTTY => error.NotATerminal,
51+
.OPNOTSUPP => error.NotSupported,
52+
else => |e| std.os.unexpectedErrno(e),
53+
};
54+
}
55+
56+
pub const Type = enum(u8) {
57+
framebuffer = 0,
58+
registers = 1,
59+
shm = 2,
60+
agp = 3,
61+
scatterGather = 4,
62+
consistent = 5,
63+
};
64+
65+
pub const Flags = enum(u8) {
66+
restricted = 1,
67+
readOnly = 2,
68+
locked = 3,
69+
kernel = 8,
70+
writeCombining = 0x10,
71+
containsLock = 0x20,
72+
removable = 0x40,
73+
driver = 0x80,
74+
};
75+
};

0 commit comments

Comments
 (0)