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 / tests / test_smmu_svc.c

75 lines · 3094 bytes Raw Blame History
1/* SPDX-License-Identifier: Apache-2.0
2 * Copyright 2026 Drake Stapleton (AIEN / aien-dev)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/* test_smmu_svc.c -- host test of ck_dma_unconfine's refusals (#480).
18 * The service's instance table is static, so the source is included here and
19 * the table is laid out directly; no SMMU register is touched, because both
20 * refusals return before any command is issued. A stream held by one SMMU
21 * (the abort path) needs real registers and is covered by the stage tests
22 * through their mock. Host only, not hardware. */
23#include "ck_test.h"
24#include "../core/smmu_svc.c"
25
26/* Platform hooks the service links against. The refusals under test reach none
27 * of them; each one counts, so a refusal that touches the platform fails. */
28static int platform_calls;
29void ck_printf(const char *fmt, ...) { (void)fmt; }
30void *ck_dma_alloc(size_t bytes, size_t align, uint64_t *phys) { (void)bytes; (void)align; (void)phys; platform_calls++; return 0; }
31volatile void *ck_mmio_map(uint64_t phys, size_t len) { (void)phys; (void)len; platform_calls++; return 0; }
32void ck_mb(void) { platform_calls++; }
33const void *ck_acpi_find(const char sig[4]) { (void)sig; platform_calls++; return 0; }
34
35static void hold(unsigned k, int slot, uint32_t sid)
36{
37 g.inst[k].state = 1;
38 g.inst[k].used[slot] = 1;
39 g.inst[k].sid[slot] = sid;
40}
41
42static void test_not_confined(void)
43{
44 memset(&g, 0, sizeof g);
45 CHECK(ck_dma_unconfine(0x40) == CK_SMMU_EARG); /* no SMMU up at all */
46 hold(0, 0, 0x41);
47 CHECK(ck_dma_unconfine(0x40) == CK_SMMU_EARG); /* up, but another stream */
48 CHECK(g.inst[0].used[0] == 1 && g.inst[0].sid[0] == 0x41);
49 g.inst[1].state = CK_SMMU_FAILED; /* a failed instance holds nothing */
50 g.inst[1].used[0] = 1;
51 g.inst[1].sid[0] = 0x40;
52 CHECK(ck_dma_unconfine(0x40) == CK_SMMU_EARG);
53}
54
55static void test_ambiguous(void)
56{
57 memset(&g, 0, sizeof g);
58 hold(0, 2, 0x40);
59 hold(1, 0, 0x40);
60 int rc = ck_dma_unconfine(0x40);
61 CHECK(rc == CK_SMMU_AMBIGUOUS);
62 CHECK(rc != CK_SMMU_EARG && rc != 0);
63 /* fail closed: both holders keep the stream confined */
64 CHECK(g.inst[0].used[2] == 1 && g.inst[0].sid[2] == 0x40);
65 CHECK(g.inst[1].used[0] == 1 && g.inst[1].sid[0] == 0x40);
66 CHECK(ck_dma_unconfine(0x40) == CK_SMMU_AMBIGUOUS); /* stays refused on retry */
67}
68
69int main(void)
70{
71 test_not_confined();
72 test_ambiguous();
73 CHECK(platform_calls == 0); /* refusals issue no command and map nothing */
74 return ck_t_verdict("test_smmu_svc");
75}