interplane.Get Omega
Read in your language

CUDApp

CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit.

Brought by drakestapleton

branch main Branches Tags History

CUDApp / third_party / aien-gpu-abi1 / aien_gpu_uapi.h

168 lines · 7731 bytes Raw Blame History
1/* SPDX-License-Identifier: MIT OR GPL-2.0-only */
2/*
3 * aien_gpu_uapi.h -- the /dev/aien-gpu interface (ABI 1). Shared by the module and user space.
4 * A new, small compute ABI of our own, not NVIDIA's NV_ESC/UVM ioctls (docs/DESIGN.md section 3).
5 * Every argument block has a fixed size and is copied into the kernel once; its checks are Omega
6 * (om/abi.om) before the kernel acts on it. Little endian; reserved bytes must be zero.
7 */
8#ifndef AIEN_GPU_UAPI_H
9#define AIEN_GPU_UAPI_H
10
11#include <linux/ioctl.h>
12#include <linux/types.h>
13
14#define AGPU_ABI_VERSION 1
15
16/* Device state, AGPU_INFO.state */
17enum agpu_state {
18 AGPU_STATE_BOUND = 1, /* identity checked, BAR0 mapped, memory allocated; GSP not touched */
19 AGPU_STATE_BOOTING = 2, /* a start-up is running or stopped half way (never retried per load) */
20 AGPU_STATE_GSP_UP = 3, /* GSP-RM reported INIT_DONE */
21 AGPU_STATE_RM_READY = 4, /* stage C bring-up done: clients may allocate memory and channels */
22 AGPU_STATE_FAILED = 5, /* a stage stopped; see the boot or rm verdict; reload the module after a reset */
23};
24
25struct agpu_info {
26 __u32 abi; /* AGPU_ABI_VERSION */
27 __u32 state; /* enum agpu_state */
28 __u32 boot0, boot42; /* NV_PMC_BOOT_0, NV_PMC_BOOT_42 as read at probe */
29 __u64 bar0_bytes;
30 __u64 arena_bytes, arena_iova; /* the boot arena: mmap offset 0, length arena_bytes */
31 __u64 heap_bytes, heap_iova; /* the GSP system-memory heap: device only, never mapped */
32 __u64 fw_bytes; /* gsp_ga10x.bin size as loaded at probe (0 if missing) */
33 __u32 fw_ok; /* size and sha256 equal the pins in kmod/aien_gpu.h */
34 __u32 dma_bits;
35 __u32 boot_attempts; /* 0 or 1: one GSP start-up per load */
36 __u32 reserved[9];
37};
38
39/* AGPU_BOOT: stage B. in = the 128-byte block om/abi.om checks (request 1); out = the verdict. */
40enum agpu_boot_verdict {
41 AGPU_BOOT_INIT_DONE = 1, /* GSP-RM sent GSP_INIT_DONE */
42 AGPU_BOOT_REFUSED = 2, /* the block failed om/abi.om (out.code); the chip was not touched */
43 AGPU_BOOT_MMIO_STOPPED = 3, /* the 11 register steps stopped: out.stage says where */
44 AGPU_BOOT_QUEUE_ERROR = 4, /* a status-queue message failed om/mqget.om (out.code) */
45 AGPU_BOOT_SEQ_REFUSED = 5, /* a sequencer request failed om/seq.om (out.code) */
46 AGPU_BOOT_SEQ_STOPPED = 6, /* a sequencer list stopped: poll (out.code 1) or core operation (2) */
47 AGPU_BOOT_TIMEOUT = 7, /* no INIT_DONE within waitms */
48 AGPU_BOOT_STATE = 8, /* not in AGPU_STATE_BOUND (already attempted) */
49};
50
51struct agpu_boot_out {
52 __u32 verdict; /* enum agpu_boot_verdict */
53 __u32 code; /* refusal code of the Omega unit named by the verdict */
54 __u32 stage; /* om/boot.om stage: 0 ok, 1 arg, 2 busy, 3 emem, 4 sec2, 5 mask, 6 lockdown, 7 fmc, 8 riscv */
55 __u32 polls[4];
56 __u32 dwords, ememc_after;
57 __u32 sec2_mb0, sec2_mb1, hwcfg2, gsp_mb0, gsp_mb1, cpuctl;
58 __u32 msgs; /* status-queue messages read */
59 __u32 last_fn; /* function of the last message */
60 __u32 seq_runs; /* sequencer requests performed */
61 __u32 seq_ops; /* operations of the last one performed */
62 __u32 rx_seq; /* next expected status-queue sequence number */
63 __u64 mmio_us, wait_us; /* time in the register steps, time waiting for INIT_DONE */
64 __u32 reserved[4];
65};
66
67struct agpu_boot {
68 __u8 in[128]; /* layout: om/abi.om header and tools/aien-gpu-boot.c */
69 struct agpu_boot_out out;
70};
71
72/* AGPU_ARENA_READ: copy a range of the boot arena out (root; evidence such as GSP's log buffers after
73 * the start-up, when the arena is no longer mappable). om/abi.om request 2 checks off/len. */
74struct agpu_arena_read {
75 __u64 off, len; /* len 1..16 MiB, inside the arena */
76 __u64 buf; /* user pointer */
77};
78
79/*
80 * Stage C. All GSP RPC payloads are NVIDIA's 580.173.02 structures (MIT headers), built and checked by
81 * om/rm.om; any value that depends on what GSP-RM reports is read at run time, and a mismatch is a
82 * named refusal (AGPU_RM_E_*), never a guess. Route: an RM-managed GPU address space whose page tables
83 * this module writes (docs/STAGE-C.md); no UVM.
84 */
85enum agpu_rm_verdict {
86 AGPU_RM_OK = 1,
87 AGPU_RM_E_STATE = 2, /* wrong device state for this call */
88 AGPU_RM_E_ARG = 3, /* argument block refused by om/abi.om (code) */
89 AGPU_RM_E_QUEUE = 4, /* message queue refusal (code: om/seal, om/mqput, om/mqget) */
90 AGPU_RM_E_TIMEOUT = 5, /* no reply within the RPC deadline */
91 AGPU_RM_E_RESULT = 6, /* GSP-RM answered rpc_result != 0 (code = rpc_result, fn = function) */
92 AGPU_RM_E_STATUS = 7, /* the RPC's own status field != NV_OK (code = status) */
93 AGPU_RM_E_VERSION = 8, /* SET_GUEST_SYSTEM_INFO answered another version than 580.173.02's */
94 AGPU_RM_E_STATIC = 9, /* GspStaticConfigInfo failed a check (code says which) */
95 AGPU_RM_E_REPLY = 10, /* a reply failed om/rm.om (code) */
96 AGPU_RM_E_NOMEM = 11, /* host memory or DMA mapping */
97 AGPU_RM_E_UNSUPPORTED = 12, /* GSP asked for something this driver does not do (code says what) */
98};
99
100struct agpu_rm_status {
101 __u32 verdict; /* enum agpu_rm_verdict */
102 __u32 code;
103 __u32 fn; /* RPC function that failed, or 0 */
104 __u32 step; /* the numbered step of docs/STAGE-C.md that failed, or 0 */
105};
106
107/* AGPU_RM_INIT: once per load, after INIT_DONE (spec section 1). */
108struct agpu_rm_init {
109 struct agpu_rm_status st;
110 __u32 vgx_major, vgx_minor; /* what GSP-RM answered */
111 __u32 h_client, h_device, h_subdevice; /* GSP-RM's internal handles (static info 1728..1736) */
112 __u32 gr_runlist; /* runlist id of GR0 (FIFO device info table) */
113 __u32 reserved[8];
114 __u8 static_info[1792]; /* GspStaticConfigInfo as received, for the evidence */
115};
116
117/* AGPU_MEM_ALLOC: system memory the GPU sees at gpu_va == the CPU address the caller maps it at.
118 * The caller reserves [va, va + size) first (mmap PROT_NONE, MAP_FIXED_NOREPLACE), then maps the
119 * returned mmap_off over it with MAP_FIXED|MAP_SHARED. */
120#define AGPU_MEM_GPU_UNCACHED 1u /* GPU does not cache it in L2 (memory the CPU polls) */
121struct agpu_mem_alloc {
122 __u64 size; /* multiple of 4096, 4 KiB .. 64 GiB */
123 __u64 va; /* 4096-aligned, below 2^48, outside [4 GiB, 4.5 GiB) (GSP's range) */
124 __u32 flags; /* AGPU_MEM_* */
125 __u32 handle; /* out */
126 __u64 mmap_off; /* out */
127 struct agpu_rm_status st; /* out */
128};
129
130struct agpu_mem_free {
131 __u32 handle;
132 __u32 reserved;
133 struct agpu_rm_status st;
134};
135
136/* AGPU_CHAN_CREATE: one compute channel (TSG, context share, GPFIFO channel, BLACKWELL_COMPUTE_B,
137 * scheduled). Ring and USERD live in caller memory from AGPU_MEM_ALLOC (GPU-uncached). */
138struct agpu_chan_create {
139 __u32 ring_handle; /* memory holding the GPFIFO ring */
140 __u32 entries; /* ring entries, power of two, 8..65536 */
141 __u64 ring_off; /* byte offset of the ring in that memory, 8-aligned */
142 __u32 userd_handle; /* memory holding USERD (512 bytes) */
143 __u32 err_handle; /* memory receiving channel errors (error notifier) */
144 __u64 userd_off; /* 512-aligned */
145 __u32 chid; /* out */
146 __u32 token; /* out: work-submit token, (runlist << 16) | chid */
147 __u64 doorbell_off; /* out: mmap offset of the 64 KiB usermode page; doorbell word at +0x90 */
148 __u32 channel; /* out: handle for AGPU_CHAN_DESTROY */
149 __u32 reserved;
150 struct agpu_rm_status st;
151};
152
153struct agpu_chan_destroy {
154 __u32 channel;
155 __u32 reserved;
156 struct agpu_rm_status st;
157};
158
159#define AGPU_INFO _IOR('A', 0x10, struct agpu_info)
160#define AGPU_BOOT _IOWR('A', 0x11, struct agpu_boot)
161#define AGPU_ARENA_READ _IOW('A', 0x12, struct agpu_arena_read)
162#define AGPU_RM_INIT _IOWR('A', 0x20, struct agpu_rm_init)
163#define AGPU_MEM_ALLOC _IOWR('A', 0x21, struct agpu_mem_alloc)
164#define AGPU_MEM_FREE _IOWR('A', 0x22, struct agpu_mem_free)
165#define AGPU_CHAN_CREATE _IOWR('A', 0x23, struct agpu_chan_create)
166#define AGPU_CHAN_DESTROY _IOWR('A', 0x24, struct agpu_chan_destroy)
167
168#endif