1const std = @import("../../std.zig");
2
3const bits = switch (@import("builtin").cpu.arch) {
4 .mips,
5 .mipsel,
6 .mips64,
7 .mips64el,
8 .powerpc,
9 .powerpcle,
10 .powerpc64,
11 .powerpc64le,
12 .sparc,
13 .sparc64,
14 .alpha,
15 => .{ .size = 13, .dir = 3, .none = 1, .read = 2, .write = 4 },
16 else => .{ .size = 14, .dir = 2, .none = 0, .read = 2, .write = 1 },
17};
18
19const Direction = @Int(.unsigned, bits.dir);
20
21pub const Request = packed struct {
22 nr: u8,
23 io_type: u8,
24 size: @Int(.unsigned, bits.size),
25 dir: Direction,
26};
27
28fn io_impl(dir: Direction, io_type: u8, nr: u8, comptime T: type) u32 {
29 const request = Request{
30 .dir = dir,
31 .size = @sizeOf(T),
32 .io_type = io_type,
33 .nr = nr,
34 };
35 return @as(u32, @bitCast(request));
36}
37
38pub fn IO(io_type: u8, nr: u8) u32 {
39 return io_impl(bits.none, io_type, nr, void);
40}
41
42pub fn IOR(io_type: u8, nr: u8, comptime T: type) u32 {
43 return io_impl(bits.read, io_type, nr, T);
44}
45
46pub fn IOW(io_type: u8, nr: u8, comptime T: type) u32 {
47 return io_impl(bits.write, io_type, nr, T);
48}
49
50pub fn IOWR(io_type: u8, nr: u8, comptime T: type) u32 {
51 return io_impl(bits.read | bits.write, io_type, nr, T);
52}
53
54comptime {
55 std.debug.assert(@bitSizeOf(Request) == 32);
56}