aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / native / kernel / x86 / bench_proto.h
| 1 | /* bench_proto.h -- AIENOS GPU bench console wire protocol (port 47035). |
| 2 | * LAB BUILD ONLY (CK_X86_BENCH=1). Shared between the kernel (bench_x86.c) |
| 3 | * and the Spark tool (tools/ck_gpu_bench.c). All integers big-endian on the |
| 4 | * wire. HMAC-SHA256 with a 32-byte key bound into the signed image at build |
| 5 | * time; replay protection via a monotone 64-bit counter. */ |
| 6 | #ifndef AIENOS_CK_BENCH_PROTO_H |
| 7 | #define AIENOS_CK_BENCH_PROTO_H |
| 8 | #include <stdint.h> |
| 9 | #include <stddef.h> |
| 10 | |
| 11 | #define CK_X86_BENCH_PORT 47035u |
| 12 | #define BENCH_MAGIC_REQ "ABCH" |
| 13 | #define BENCH_MAGIC_RESP "ABCR" |
| 14 | #define BENCH_VERSION 1u |
| 15 | #define BENCH_HMAC_BYTES 32u |
| 16 | |
| 17 | /* Commands. */ |
| 18 | #define BENCH_CMD_PING 0x00u |
| 19 | #define BENCH_CMD_PCI_CFG 0x01u /* arg0=cfg_offset -> result=value */ |
| 20 | #define BENCH_CMD_BAR5_READ 0x02u /* arg0=reg_index -> result=value */ |
| 21 | #define BENCH_CMD_BAR5_WRITE 0x03u /* arg0=reg_index, arg1=value -> before */ |
| 22 | #define BENCH_CMD_BAR0_READ 0x04u /* arg0=word_off -> result=value */ |
| 23 | #define BENCH_CMD_BAR0_WRITE 0x05u /* arg0=word_off, arg1=value -> before */ |
| 24 | #define BENCH_CMD_BAR5_POLL 0x06u /* arg0=reg_index, arg1=mask, arg2=expected, arg3=ms */ |
| 25 | #define BENCH_CMD_BAR5_RMW 0x07u /* arg0=reg_index, arg1=clear_mask, arg2=set_bits */ |
| 26 | |
| 27 | /* Status codes in responses. */ |
| 28 | #define BENCH_OK 0x00u |
| 29 | #define BENCH_ERR_AUTH 0x01u /* HMAC mismatch or counter replay */ |
| 30 | #define BENCH_ERR_RANGE 0x02u /* register not on allowlist */ |
| 31 | #define BENCH_ERR_ALLONES 0x03u /* read returned 0xFFFFFFFF */ |
| 32 | #define BENCH_ERR_TIMEOUT 0x04u /* TSC-bounded poll timed out */ |
| 33 | #define BENCH_ERR_NODEV 0x05u /* GPU BAR not mapped / not ready */ |
| 34 | #define BENCH_ERR_BUSY 0x06u /* kernel not bench-ready */ |
| 35 | #define BENCH_ERR_CMD 0x07u /* unknown command */ |
| 36 | |
| 37 | /* Wire layout of a request (all integers big-endian): |
| 38 | * 0 magic[4] 4 version u8 5 cmd u8 6 pad[2] 8 counter u64 |
| 39 | * 16 arg0 u32 20 arg1 u32 24 arg2 u32 28 arg3 u32 |
| 40 | * 32 hmac[32] total = 64 bytes */ |
| 41 | #define BENCH_REQ_BYTES 64u |
| 42 | #define BENCH_HMAC_OFF 32u /* offset of HMAC field in request */ |
| 43 | |
| 44 | /* Wire layout of a response: |
| 45 | * 0 magic[4] 4 version u8 5 status u8 6 pad[2] 8 counter u64 |
| 46 | * 16 tsc u64 24 result u32 28 before u32 |
| 47 | * 32 hmac[32] total = 64 bytes */ |
| 48 | #define BENCH_RESP_BYTES 64u |
| 49 | |
| 50 | /* BAR5 write allowlist (DWORD-index ranges, inclusive). Register numbers: AMD's MIT headers in |
| 51 | * Linux, drivers/gpu/drm/amd/include/asic_reg/ (dce/dce_11_2_d.h, smu/smu_7_1_3_d.h). */ |
| 52 | #define BENCH_BAR5_WRITE_LO0 0x4800u /* DCE 11.2 UNIPHY link control, LVTMA panel power sequencer, backlight PWM */ |
| 53 | #define BENCH_BAR5_WRITE_HI0 0x4900u |
| 54 | #define BENCH_BAR5_WRITE_LO1 0x4A00u /* DCE 11.2 DIG 0/1 front ends (HDMI and DP encoder blocks) */ |
| 55 | #define BENCH_BAR5_WRITE_HI1 0x4C00u |
| 56 | /* DCP0 graphics surface: mmGRPH_PRIMARY_SURFACE_ADDRESS 0x1a04 .. mmGRPH_UPDATE 0x1a11, mmGRPH_FLIP_CONTROL 0x1a12. */ |
| 57 | #define BENCH_BAR5_WRITE_LO2 0x1A04u |
| 58 | #define BENCH_BAR5_WRITE_HI2 0x1A12u |
| 59 | /* SMC mailbox 0: mmSMC_MESSAGE_0 0x94, mmSMC_RESP_0 0x95 (the pair smu7_send_msg_to_smc uses). */ |
| 60 | #define BENCH_BAR5_WRITE_LO3 0x0094u |
| 61 | #define BENCH_BAR5_WRITE_HI3 0x0095u |
| 62 | /* SMC message argument: mmSMC_MSG_ARG_0 0xa4. */ |
| 63 | #define BENCH_BAR5_WRITE_LO4 0x00A4u |
| 64 | #define BENCH_BAR5_WRITE_HI4 0x00A4u |
| 65 | |
| 66 | /* BAR5 read range: any DWORD index in [0, 65535]. */ |
| 67 | #define BENCH_BAR5_READ_MAX 0xFFFFu |
| 68 | |
| 69 | /* BAR0 (VRAM) window: first 256 KiB (DWORD words 0..65535). */ |
| 70 | #define BENCH_BAR0_MAX_WORDS 0x10000u |
| 71 | |
| 72 | /* All-ones sentinel. */ |
| 73 | #define BENCH_ALLONES 0xFFFFFFFFu |
| 74 | |
| 75 | /* Decode/encode helpers (big-endian). */ |
| 76 | static inline uint32_t bench_r32(const uint8_t *b) { |
| 77 | return (uint32_t)b[0]<<24|(uint32_t)b[1]<<16|(uint32_t)b[2]<<8|b[3]; } |
| 78 | static inline uint64_t bench_r64(const uint8_t *b) { |
| 79 | return (uint64_t)bench_r32(b)<<32|(uint64_t)bench_r32(b+4); } |
| 80 | static inline void bench_w32(uint8_t *b, uint32_t v) { |
| 81 | b[0]=(uint8_t)(v>>24);b[1]=(uint8_t)(v>>16);b[2]=(uint8_t)(v>>8);b[3]=(uint8_t)v; } |
| 82 | static inline void bench_w64(uint8_t *b, uint64_t v) { |
| 83 | bench_w32(b,(uint32_t)(v>>32));bench_w32(b+4,(uint32_t)v); } |
| 84 | |
| 85 | /* Test key (16 zero bytes + 0x01..0x10) used in QEMU/lab builds when |
| 86 | * CK_X86_BENCH_KEY is not set at compile time. */ |
| 87 | #define BENCH_TEST_KEY_INIT \ |
| 88 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, \ |
| 89 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, \ |
| 90 | 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08, \ |
| 91 | 0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10 |
| 92 | |
| 93 | #endif /* AIENOS_CK_BENCH_PROTO_H */ |