interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / aienux / kernel / arm64 / smp.om

154 lines · 4234 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note aienux/kernel/arm64/smp.om: Pure-Omega 20-core Grace SMP bring-up via PSCI CPU_ON (0xC4000003).
3note Supports up to SMP_MAX=64 cores (removes C reference's 16-core cap!).
4note Cleans page tables + per-core SmpBootBlock to PoC (DC CVAC + DSB SY) before PSCI CPU_ON.
5note Secondary cores drop EL2 -> EL1h with shared TTBR0_EL1, init per-core GICR, check in via STLR + DSB ISH + SEV.
6
7const SMP_MAX ulong 64
8const SMP_STACK_PAGES ulong 4
9const SMP_TIMEOUT_MS ulong 5000
10const SMP_IDLE ulong 0
11const SMP_ON_CALLED ulong 1
12const SMP_CHECKED_IN ulong 2
13
14note Per-core SmpBootBlock: 16 u64s (128 bytes, cacheline-aligned) per core:
15note [0]root [1]mair [2]tcr [3]sctlr [4]sp_top [5]entry(smpmain) [6]core_idx [7]stack_floor
16note [8]bss_base(X27) [9]target_mpidr [10]state(atomic) [11]seen_mpidr [12]seen_el [13]seen_sctlr [14]seen_ttbr0 [15]gic_ok
17global smp_blocks uchar 8192
18note smp_stats: 0=online_count, 1=expected_count, 2=failed_count
19global smp_stats ulong 4
20
21fn smp_blk_pa idx ulong fld ulong to ulong
22off = add mul idx 128 mul fld 8
23ret fwadr smp_blocks off 8
24end
25
26fn smp_blk_get idx ulong fld ulong to ulong
27ret fwld smp_blk_pa idx fld 8
28end
29
30fn smp_blk_put idx ulong fld ulong v ulong to void
31x = fwst smp_blk_pa idx fld 8 v
32end
33
34note smpmain: executed on each secondary core at EL1h with MMU on, shared TTBR0_EL1, own 16 KiB stack.
35fn smpmain idx ulong to void
36gok = ulong 0
37if gicv3_init_cpu idx
38gok = ulong 1
39end
40smp_blk_put idx 11 arm64_mpidr_aff
41smp_blk_put idx 12 arm64_current_el
42smp_blk_put idx 13 arm64_sysrd SYSREG_SCTLR_EL1
43smp_blk_put idx 14 and arm64_sysrd SYSREG_TTBR0_EL1 0x0000fffffffffffe
44smp_blk_put idx 15 gok
45arm64_stlr smp_blk_pa idx 10 SMP_CHECKED_IN
46arm64_dsb_ish
47arm64_sev
48note Park secondary core in WFE with DAIF masked until scheduler work is dispatched.
49i = ulong 0
50while lt i 9223372036854775807 bound 9223372036854775807
51arm64_wfe
52end
53end
54
55fn smp_start_one i ulong mpidr ulong conduit ulong to bool
56if ne get gic_state 3 0
57if not gic_prealloc_lpi_tables i
58ret false
59end
60end
61stk = frames_alloc SMP_STACK_PAGES MMU_PAGE FR_PA_40BIT_LIMIT
62if eq stk 0
63ret false
64end
65smp_blk_put i 0 get mmu_state 0
66smp_blk_put i 1 MMU_MAIR_EL1
67smp_blk_put i 2 get mmu_state 2
68smp_blk_put i 3 get mmu_state 3
69smp_blk_put i 4 add stk mul SMP_STACK_PAGES MMU_PAGE
70smp_blk_put i 5 arm64_meta 5
71smp_blk_put i 6 i
72smp_blk_put i 7 add stk 4096
73smp_blk_put i 8 arm64_meta 1
74smp_blk_put i 9 mpidr
75smp_blk_put i 10 SMP_ON_CALLED
76bpa = smp_blk_pa i 0
77arm64_dc_cvac_range bpa 128
78rc = arm64_psci_cpu_on conduit mpidr arm64_meta 6 bpa
79if ne rc 0
80smp_blk_put i 10 SMP_IDLE
81ret false
82end
83ret true
84end
85
86note Bring up all secondary cores listed in ACPI MADT (acpi_cpu_mpidr[0..ncpus)).
87note Returns number of online cores (including boot core).
88fn smp_bringup to ulong
89conduit = get acpi_info 7
90ncpus = get acpi_info 6
91if gt ncpus SMP_MAX
92ncpus = SMP_MAX
93end
94put smp_stats 0 1
95put smp_stats 1 ncpus
96put smp_stats 2 0
97if or le ncpus 1 eq conduit PSCI_CONDUIT_NONE
98ret 1
99end
100if or eq arm64_meta 6 0 eq arm64_meta 5 0
101put smp_stats 2 sub ncpus 1
102ret 1
103end
104boot_mpidr = arm64_mpidr_aff
105note Clean all live page-table frames and x27 metadata (vbar_el1 etc.) to PoC before starting secondaries.
106mmu_clean_tables_poc
107arm64_dc_cvac_range arm64_meta 1 512
108i = ulong 0
109while lt i ncpus bound 64
110mpidr = get acpi_cpu_mpidr i
111if ne mpidr boot_mpidr
112if not smp_start_one i mpidr conduit
113put smp_stats 2 add get smp_stats 2 1
114end
115end
116i = add i 1
117end
118note Wait up to SMP_TIMEOUT_MS (overflow-safe CNTVCT_EL0 deadline) for all started cores to check in.
119deadline = arm64_deadline_ticks SMP_TIMEOUT_MS
120i = ulong 0
121while lt i ncpus bound 64
122st = arm64_ldar smp_blk_pa i 10
123if eq st SMP_ON_CALLED
124spa = smp_blk_pa i 10
125done = false
126w = ulong 0
127while and not done lt w 100000000 bound 100000000
128if eq arm64_ldar spa SMP_CHECKED_IN
129done = true
130else
131if ge fwsys 2 deadline
132break
133end
134end
135w = add w 1
136end
137if and done eq smp_blk_get i 15 1
138put smp_stats 0 add get smp_stats 0 1
139else
140put smp_stats 2 add get smp_stats 2 1
141end
142else
143if eq st SMP_CHECKED_IN
144if eq smp_blk_get i 15 1
145put smp_stats 0 add get smp_stats 0 1
146else
147put smp_stats 2 add get smp_stats 2 1
148end
149end
150end
151i = add i 1
152end
153ret get smp_stats 0
154end