Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/native/kernel/gpu/gpu_chan.h # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / native / kernel / gpu / gpu_chan.h` 131 lines ยท 6102 bytes Raw Blame History 1 /* gpu_chan.h -- one GB10 compute channel's memory and doorbell (cut D, host 2 * side), freestanding. 3 * 4 * DOCUMENTED (open-gpu-kernel-modules 580.173.02): 5 * - GPFIFO entry: 8 bytes, NVC96F_GP_ENTRY0_GET 31:2, GP_ENTRY1_GET_HI 7:0, 6 * LEVEL 9:9, LENGTH 30:10 (class/clc96f.h). So the pushbuffer address 7 * field is 40 bits and the length 21 bits. 8 * - USERD: Nvc96fControl, GPPut at byte 0x8c, 512 bytes (clc96f.h). It has 9 * no GPGet, so consumption is tracked by the caller (as physics does). 10 * - Runlist entry USERD pointer on GB10B: NV_RAMRL_ENTRY_CHAN_USERD_PTR_LO 11 * 31:8 of word 0, USERD_PTR_HI_HW 19:0 of word 1 12 * (swref/published/blackwell/gb10b/dev_ram.h, checked by 13 * kchannelIsUserdAddrSizeValid_GB10B). 14 * - Work-submit token: kfifoGenerateWorkSubmitTokenHal_GB100 (the HAL GB10B 15 * gets): DOORBELL_RUNLIST_ID 22:16 = runlist id, DOORBELL_VECTOR 11:0 = 16 * channel id (blackwell/gb100/dev_vm.h). RUNLIST_ID 0x7F is INVALID. 17 * - Doorbell register: NV_VIRTUAL_FUNCTION_DOORBELL at 0x30090 in the VF 18 * space (gb100/dev_vm.h); usermode class NVC361_NOTIFY_CHANNEL_PENDING is 19 * the same 0x90 inside the 0x30000 usermode page. 20 * - Instance block size 4096 (NV_RAMIN_ALLOC_SIZE, ampere/ga100/dev_ram.h). 21 * - Instance block page directory: for GB10B the driver uses 22 * kgmmuInstBlkPageDirBaseGet_GV100 -> _GP100 (kern_gmmu_gp100.c): word 128 = 23 * TARGET 1:0 | VOL 2 | FAULT_REPLAY_TEX 4 | FAULT_REPLAY_GCC 5 | 24 * USE_NEW_PT_FORMAT 10 (TRUE only for format VERSION_2, so FALSE on GB10B) | 25 * BIG_PAGE_SIZE 11 (1 = 64 KiB) | LO 31:12 = pa >> 12; 26 * word 129 = HI = pa >> 32 (pascal/gp100 and volta/gv100 dev_ram.h). Driver 27 * behaviour, DOCUMENTED; that the GB10 silicon reads it there is UNVERIFIED. 28 * 29 * UNKNOWN for GB10B (no public header): the subcontext PDB table 30 * (NV_RAMIN_SC_* exists on GV100; which entries GB10B needs is not 31 * checked here), the rest of the instance block, the other runlist-entry words, the USERD target/aperture bits, 32 * and how the channel is made runnable. On GB10 RM asks GSP to do that 33 * (channel allocation RPC); here it is the `bind` op, filled by the 34 * simulator in tests and by the GSP lane (L192) on hardware. 35 * 36 * Encoders carried bit-identical from physics (aien-spark/physics 37 * nvrm/nvrm.h:135 nvrm_mthd, nvrm/nvrm.c:809 nvrm_gp_entry): they live in a 38 * Linux-only header there and Omega has not moved them to a shared header 39 * yet (dependency map cut A). Keep them byte-for-byte equal. */ 40 #ifndef CK_GPU_CHAN_H 41 #define CK_GPU_CHAN_H 42 43 #include 44 #include "gmmu.h" 45 #include "gpu_mem.h" 46 47 /* nvrm_mthd: incrementing method header (bits 31:29 = 1, INC_METHOD). */ 48 static inline uint32_t ck_gpu_mthd(uint32_t subc, uint32_t mthd, uint32_t count) 49 { 50 return (2u << 28) | (count << 16) | (subc << 13) | (mthd >> 2); 51 } 52 53 /* nvrm_gp_entry: GET/GET_HI = va, LEVEL bit (41) set as physics does, 54 * LENGTH = nwords. Callers must check va < 2^40 and nwords <= 0x1fffff 55 * (ck_gpu_chan_submit does). */ 56 static inline uint64_t ck_gpu_gp_entry(uint64_t va, uint32_t nwords) 57 { 58 return (va & ~3ull) | ((uint64_t)(nwords & 0x1fffff) << 42) | (1ull << 41); 59 } 60 61 #define CK_GPU_GP_VA_LIMIT (1ull << 40) 62 #define CK_GPU_GP_LEN_MAX 0x1fffffu 63 #define CK_GPU_USERD_BYTES 512u 64 #define CK_GPU_USERD_GPPUT 0x8cu 65 #define CK_GPU_INST_BYTES 4096u 66 #define CK_GPU_RAMIN_PDB_WORD 128u 67 #define CK_GPU_RAMIN_TARGET_SYS_COH 2u 68 #define CK_GPU_RAMIN_NEW_PT_FORMAT (1u << 10) 69 #define CK_GPU_RAMIN_BIG_PAGE_64K (1u << 11) 70 #define CK_GPU_REG_DOORBELL (CK_GPU_VF_BASE + 0x30090u) 71 #define CK_GPU_CHID_MAX 0xFFFu 72 #define CK_GPU_RUNLIST_INVALID 0x7Fu 73 74 uint32_t ck_gpu_submit_token(uint32_t runlist_id, uint32_t chid); 75 /* Encode the USERD pointer words of a runlist channel entry. Refuses a 76 * pointer that is not 256-byte aligned or does not fit 52 bits. Other bits 77 * of the entry are UNKNOWN on GB10B and left zero. */ 78 int ck_gpu_rl_userd(uint32_t out[2], uint64_t userd_pa); 79 80 /* What the device side needs to make the channel runnable (what a GSP 81 * channel-allocation request would carry). */ 82 struct ck_gpu_chan_desc { 83 uint32_t chid, runlist_id, token, entries; 84 uint64_t pdb; /* PD4 physical address of the channel's address space */ 85 uint64_t gpfifo_va; /* GPU VA of the ring */ 86 uint64_t userd_pa, inst_pa; 87 uint32_t rl_entry[2]; 88 }; 89 90 struct ck_gpu_chan_ops { 91 int (*bind)(void *ctx, const struct ck_gpu_chan_desc *d); 92 int (*disable)(void *ctx, uint32_t chid); 93 int (*is_idle)(void *ctx, uint32_t chid); 94 }; 95 96 enum ck_gpu_chan_status { 97 CK_GCHAN_OK = 0, 98 CK_GCHAN_EINVAL, 99 CK_GCHAN_ENOMEM, 100 CK_GCHAN_ESTATE, /* not open, or faulted */ 101 CK_GCHAN_EFULL, /* ring full: retire first */ 102 CK_GCHAN_EBIND, /* device refused the channel */ 103 CK_GCHAN_ETIMEDOUT, /* teardown: never idle; memory quarantined */ 104 }; 105 106 struct ck_gpu_chan { 107 struct ck_gmem *mem; 108 const struct ck_gpu_regs *regs; 109 struct ck_gpu_chan_ops ops; 110 void *ops_ctx; 111 struct ck_gpu_chan_desc d; 112 struct ck_gmem_buf *gpfifo, *userd, *inst; 113 uint32_t put, retired; 114 uint32_t open; 115 }; 116 117 /* entries: power of two, 2..65536. */ 118 int ck_gpu_chan_create(struct ck_gpu_chan *c, struct ck_gmem *mem, const struct ck_gpu_regs *regs, 119 const struct ck_gpu_chan_ops *ops, void *ops_ctx, uint32_t chid, uint32_t runlist_id, 120 uint32_t entries); 121 /* Queue nwords of pb starting at byte off, publish GPPut, ring the doorbell. 122 * pb must be a live buffer of the same allocator. */ 123 int ck_gpu_chan_submit(struct ck_gpu_chan *c, const struct ck_gmem_buf *pb, uint32_t off, uint32_t nwords); 124 /* The caller saw entries up to `upto` complete (e.g. a semaphore it polled). */ 125 void ck_gpu_chan_retire(struct ck_gpu_chan *c, uint32_t upto); 126 /* Disable, wait for idle at most idle_budget polls. Idle: free the ring, 127 * USERD and instance block. Not idle: quarantine them and every buffer in 128 * extra[] (pushbuffers, semaphores the GPU may still write). */ 129 int ck_gpu_chan_teardown(struct ck_gpu_chan *c, uint32_t idle_budget, struct ck_gmem_buf **extra, uint32_t nextra); 130 131 #endif