interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / native / kernel / gpu / amd_ring.h

58 lines · 2525 bytes Raw Blame History
1/* native/kernel/gpu/amd_ring.h -- Public PM4/SDMA ring submission interface.
2 *
3 * Owned by feat/imac-gpu-core; consumed by feat/imac-gpu-shader.
4 * Every call is AIENOS bare-metal (no OS services, no floats, no CUDA).
5 *
6 * The GFX ring (RING_GFX) accepts PM4 IT_DRAW and compute PM4 for the CP.
7 * The SDMA ring (RING_SDMA) accepts SDMA operation packets.
8 * The compute queue (RING_MEC) is an HQD-backed MQD pipe for DISPATCH_DIRECT.
9 *
10 * Sources consulted (MIT-licensed, not reproduced):
11 * Linux drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c -- gfx_v8_0_ring_emit_*
12 * Linux drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c -- sdma_v3_0_ring_emit_*
13 * Attribution in THIRD_PARTY_NOTICES. */
14#pragma once
15#include <stdint.h>
16
17/* Which ring to submit to. */
18typedef enum {
19 AMD_RING_GFX = 0, /* CP GFX ring 0 (CP_RB0) */
20 AMD_RING_SDMA = 1, /* SDMA0 GFX ring */
21 AMD_RING_MEC = 2, /* MEC HQD compute pipe 0 queue 0 */
22} amd_ring_id_t;
23
24/* Return codes used by all ring and fence functions. */
25#define AMD_RING_OK 0
26#define AMD_RING_EFULL -1 /* ring full, caller must retry later */
27#define AMD_RING_ETIMEOUT -2 /* fence or vblank wait timed out */
28#define AMD_RING_ENODEV -3 /* ring not initialised */
29
30/* Opaque ring state (defined in amd_gpu.h, included by gpu_x86.c). */
31struct amd_ring;
32
33/* Submit one PM4/SDMA dword packet to ring `id`.
34 * `dw` points to `count` dwords. count must be <= 256.
35 * Advances the write pointer; hardware picks it up asynchronously.
36 * Thread-safety: single-threaded bare-metal; no locking. */
37int ck_gpu_ring_submit(amd_ring_id_t id, const uint32_t *dw, unsigned count);
38
39/* Wait until the fence value written to *fence_va equals `seq`.
40 * `timeout_ms` is TSC-bounded; 0 means check once.
41 * Returns AMD_RING_OK, AMD_RING_ETIMEOUT. */
42int ck_gpu_fence_wait(const volatile uint32_t *fence_va, uint32_t seq, unsigned timeout_ms);
43
44/* Page flip: schedule the scan-out to switch to the back buffer at the next
45 * vblank. Waits for the flip to complete (at most 50 ms for a 60 Hz panel).
46 * Returns AMD_RING_OK or AMD_RING_ETIMEOUT. */
47int ck_gpu_flip(void);
48
49/* Return the CPU pointer to the current back buffer (where renderers draw).
50 * NULL if the GPU driver is not initialised. */
51volatile uint32_t *ck_gpu_backbuffer(void);
52
53/* Return the back buffer physical address in VRAM (MC space).
54 * 0 if not initialised. */
55uint64_t ck_gpu_backbuffer_pa(void);
56
57/* VRAM size in bytes as read from MC_VM_FB_LOCATION. 0 if not read yet. */
58uint64_t ck_gpu_vram_size(void);