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