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 / linux / aien-gpu / aien_gpu_check.c

32 lines · 1551 bytes Raw Blame History
1/* aien_gpu_check: window-0 user-space check of /dev/aien-gpu (L332 rung 2). Prints what the module read,
2 * maps the arena, writes a pattern through the mapping and reads it back. Exit 0 = all checks passed. */
3#include <fcntl.h>
4#include <stdint.h>
5#include <stdio.h>
6#include <sys/ioctl.h>
7#include <sys/mman.h>
8#include <unistd.h>
9
10#include "aien_gpu_uapi.h"
11
12int main(void)
13{
14 int fails = 0, fd = open("/dev/aien-gpu", O_RDWR);
15 if (fd < 0) { perror("open /dev/aien-gpu"); return 2; }
16 struct aien_gpu_info in = {0};
17 if (ioctl(fd, AIEN_GPU_INFO, &in) != 0) { perror("AIEN_GPU_INFO"); return 2; }
18 printf("boot0=%08x boot42=%08x bar0=%llu fw_bytes=%llu fw_ok=%u arena=%llu iova=%llx\n", in.boot0, in.boot42,
19 (unsigned long long)in.bar0_bytes, (unsigned long long)in.fw_bytes, in.fw_ok,
20 (unsigned long long)in.arena_bytes, (unsigned long long)in.arena_iova);
21 fails += in.boot0 == 0 || in.boot0 == 0xffffffffu; /* all-ones = BAR0 not answering */
22 fails += !in.fw_ok;
23 volatile uint32_t *a = mmap(0, in.arena_bytes, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
24 if (a == MAP_FAILED) { perror("mmap"); return 2; }
25 uint64_t n = in.arena_bytes / 4;
26 for (uint64_t i = 0; i < n; i++) a[i] = (uint32_t)(i * 2654435761u);
27 for (uint64_t i = 0; i < n; i++) if (a[i] != (uint32_t)(i * 2654435761u)) { fails++; break; }
28 printf("arena pattern %s, checks failed %d\n", fails ? "or identity FAIL" : "PASS", fails);
29 munmap((void *)a, in.arena_bytes);
30 close(fd);
31 return fails ? 1 : 0;
32}