Andrew Scull | 1883487 | 2018-10-12 11:48:09 +0100 | [diff] [blame] | 1 | /* |
Andrew Walbran | 692b325 | 2019-03-07 15:51:31 +0000 | [diff] [blame] | 2 | * Copyright 2018 The Hafnium Authors. |
Andrew Scull | 1883487 | 2018-10-12 11:48:09 +0100 | [diff] [blame] | 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 | * https://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 | |
Andrew Scull | c960c03 | 2018-10-24 15:13:35 +0100 | [diff] [blame] | 17 | #include <stdnoreturn.h> |
| 18 | |
Andrew Walbran | 1f32e72 | 2019-06-07 17:57:26 +0100 | [diff] [blame^] | 19 | #include "hf/arch/barriers.h" |
Andrew Scull | c960c03 | 2018-10-24 15:13:35 +0100 | [diff] [blame] | 20 | #include "hf/arch/init.h" |
| 21 | |
Andrew Scull | 18c78fc | 2018-08-20 12:57:41 +0100 | [diff] [blame] | 22 | #include "hf/api.h" |
| 23 | #include "hf/cpu.h" |
| 24 | #include "hf/dlog.h" |
Andrew Scull | a9c172d | 2019-04-03 14:10:00 +0100 | [diff] [blame] | 25 | #include "hf/panic.h" |
Jose Marinho | a1dfeda | 2019-02-27 16:46:03 +0000 | [diff] [blame] | 26 | #include "hf/spci.h" |
Andrew Scull | 18c78fc | 2018-08-20 12:57:41 +0100 | [diff] [blame] | 27 | #include "hf/vm.h" |
| 28 | |
Andrew Scull | f35a5c9 | 2018-08-07 18:09:46 +0100 | [diff] [blame] | 29 | #include "vmapi/hf/call.h" |
Wedson Almeida Filho | 987c0ff | 2018-06-20 16:34:38 +0100 | [diff] [blame] | 30 | |
| 31 | #include "msr.h" |
Andrew Scull | 18c78fc | 2018-08-20 12:57:41 +0100 | [diff] [blame] | 32 | #include "psci.h" |
Andrew Scull | 7fd4bb7 | 2018-12-08 23:40:12 +0000 | [diff] [blame] | 33 | #include "smc.h" |
Wedson Almeida Filho | 987c0ff | 2018-06-20 16:34:38 +0100 | [diff] [blame] | 34 | |
Andrew Walbran | 3d84a26 | 2018-12-13 14:41:19 +0000 | [diff] [blame] | 35 | #define HCR_EL2_VI (1u << 7) |
| 36 | |
Wedson Almeida Filho | 987c0ff | 2018-06-20 16:34:38 +0100 | [diff] [blame] | 37 | struct hvc_handler_return { |
Andrew Scull | 3740287 | 2018-10-24 14:23:06 +0100 | [diff] [blame] | 38 | uintreg_t user_ret; |
Wedson Almeida Filho | 8700964 | 2018-07-02 10:20:07 +0100 | [diff] [blame] | 39 | struct vcpu *new; |
Wedson Almeida Filho | 987c0ff | 2018-06-20 16:34:38 +0100 | [diff] [blame] | 40 | }; |
| 41 | |
Wedson Almeida Filho | 03e767a | 2018-07-30 15:32:03 +0100 | [diff] [blame] | 42 | void cpu_entry(struct cpu *c); |
| 43 | |
Andrew Scull | c960c03 | 2018-10-24 15:13:35 +0100 | [diff] [blame] | 44 | static uint32_t el3_psci_version = 0; |
| 45 | |
| 46 | /* Performs arch specific boot time initialisation. */ |
| 47 | void arch_one_time_init(void) |
| 48 | { |
| 49 | el3_psci_version = smc(PSCI_VERSION, 0, 0, 0); |
| 50 | |
| 51 | /* Check there's nothing unexpected about PSCI. */ |
| 52 | switch (el3_psci_version) { |
| 53 | case PSCI_VERSION_0_2: |
| 54 | case PSCI_VERSION_1_0: |
| 55 | case PSCI_VERSION_1_1: |
| 56 | /* Supported EL3 PSCI version. */ |
| 57 | dlog("Found PSCI version: 0x%x\n", el3_psci_version); |
| 58 | break; |
| 59 | |
| 60 | default: |
| 61 | /* Unsupported EL3 PSCI version. Log a warning but continue. */ |
| 62 | dlog("Warning: unknown PSCI version: 0x%x\n", el3_psci_version); |
| 63 | el3_psci_version = 0; |
| 64 | break; |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | /* Gets a reference to the currently executing vCPU. */ |
| 69 | static struct vcpu *current(void) |
Andrew Walbran | 3d84a26 | 2018-12-13 14:41:19 +0000 | [diff] [blame] | 70 | { |
| 71 | return (struct vcpu *)read_msr(tpidr_el2); |
| 72 | } |
| 73 | |
Andrew Walbran | 1f8d487 | 2018-12-20 11:21:32 +0000 | [diff] [blame] | 74 | /** |
| 75 | * Saves the state of per-vCPU peripherals, such as the virtual timer, and |
| 76 | * informs the arch-independent sections that registers have been saved. |
| 77 | */ |
| 78 | void complete_saving_state(struct vcpu *vcpu) |
| 79 | { |
Andrew Walbran | 6480f8f | 2019-06-05 17:39:14 +0100 | [diff] [blame] | 80 | vcpu->regs.peripherals.cntv_cval_el0 = read_msr(cntv_cval_el0); |
| 81 | vcpu->regs.peripherals.cntv_ctl_el0 = read_msr(cntv_ctl_el0); |
Andrew Walbran | 1f8d487 | 2018-12-20 11:21:32 +0000 | [diff] [blame] | 82 | |
| 83 | api_regs_state_saved(vcpu); |
| 84 | |
| 85 | /* |
| 86 | * If switching away from the primary, copy the current EL0 virtual |
| 87 | * timer registers to the corresponding EL2 physical timer registers. |
| 88 | * This is used to emulate the virtual timer for the primary in case it |
| 89 | * should fire while the secondary is running. |
| 90 | */ |
| 91 | if (vcpu->vm->id == HF_PRIMARY_VM_ID) { |
| 92 | /* |
| 93 | * Clear timer control register before copying compare value, to |
| 94 | * avoid a spurious timer interrupt. This could be a problem if |
| 95 | * the interrupt is configured as edge-triggered, as it would |
| 96 | * then be latched in. |
| 97 | */ |
| 98 | write_msr(cnthp_ctl_el2, 0); |
| 99 | write_msr(cnthp_cval_el2, read_msr(cntv_cval_el0)); |
| 100 | write_msr(cnthp_ctl_el2, read_msr(cntv_ctl_el0)); |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Restores the state of per-vCPU peripherals, such as the virtual timer. |
| 106 | */ |
| 107 | void begin_restoring_state(struct vcpu *vcpu) |
| 108 | { |
| 109 | /* |
| 110 | * Clear timer control register before restoring compare value, to avoid |
| 111 | * a spurious timer interrupt. This could be a problem if the interrupt |
| 112 | * is configured as edge-triggered, as it would then be latched in. |
| 113 | */ |
| 114 | write_msr(cntv_ctl_el0, 0); |
Andrew Walbran | 6480f8f | 2019-06-05 17:39:14 +0100 | [diff] [blame] | 115 | write_msr(cntv_cval_el0, vcpu->regs.peripherals.cntv_cval_el0); |
| 116 | write_msr(cntv_ctl_el0, vcpu->regs.peripherals.cntv_ctl_el0); |
Andrew Walbran | 1f8d487 | 2018-12-20 11:21:32 +0000 | [diff] [blame] | 117 | |
| 118 | /* |
| 119 | * If we are switching (back) to the primary, disable the EL2 physical |
| 120 | * timer which was being used to emulate the EL0 virtual timer, as the |
| 121 | * virtual timer is now running for the primary again. |
| 122 | */ |
| 123 | if (vcpu->vm->id == HF_PRIMARY_VM_ID) { |
| 124 | write_msr(cnthp_ctl_el2, 0); |
| 125 | write_msr(cnthp_cval_el2, 0); |
| 126 | } |
| 127 | } |
| 128 | |
Andrew Walbran | 1f32e72 | 2019-06-07 17:57:26 +0100 | [diff] [blame^] | 129 | /** |
| 130 | * Ensures all explicit memory access and management instructions for |
| 131 | * non-shareable normal memory have completed before continuing. |
| 132 | */ |
| 133 | static void dsb_nsh(void) |
| 134 | { |
| 135 | __asm__ volatile("dsb nsh"); |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * Invalidate all stage 1 TLB entries on the current (physical) CPU for the |
| 140 | * current VMID. |
| 141 | */ |
| 142 | static void invalidate_vm_tlb(void) |
| 143 | { |
| 144 | isb(); |
| 145 | __asm__ volatile("tlbi vmalle1"); |
| 146 | isb(); |
| 147 | dsb_nsh(); |
| 148 | } |
| 149 | |
| 150 | /** |
| 151 | * Invalidates the TLB if a different vCPU is being run than the last vCPU of |
| 152 | * the same VM which was run on the current pCPU. |
| 153 | * |
| 154 | * This is necessary because VMs may (contrary to the architecture |
| 155 | * specification) use inconsistent ASIDs across vCPUs. c.f. KVM's similar |
| 156 | * workaround: |
| 157 | * https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=94d0e5980d6791b9 |
| 158 | */ |
| 159 | void maybe_invalidate_tlb(struct vcpu *vcpu) |
| 160 | { |
| 161 | size_t current_cpu_index = cpu_index(vcpu->cpu); |
| 162 | size_t new_vcpu_index = vcpu_index(vcpu); |
| 163 | |
| 164 | if (vcpu->vm->arch.last_vcpu_on_cpu[current_cpu_index] != |
| 165 | new_vcpu_index) { |
| 166 | /* |
| 167 | * The vCPU has changed since the last time this VM was run on |
| 168 | * this pCPU, so we need to invalidate the TLB. |
| 169 | */ |
| 170 | invalidate_vm_tlb(); |
| 171 | |
| 172 | /* Record the fact that this vCPU is now running on this CPU. */ |
| 173 | vcpu->vm->arch.last_vcpu_on_cpu[current_cpu_index] = |
| 174 | new_vcpu_index; |
| 175 | } |
| 176 | } |
| 177 | |
Andrew Scull | c960c03 | 2018-10-24 15:13:35 +0100 | [diff] [blame] | 178 | noreturn void irq_current_exception(uintreg_t elr, uintreg_t spsr) |
Wedson Almeida Filho | 987c0ff | 2018-06-20 16:34:38 +0100 | [diff] [blame] | 179 | { |
Wedson Almeida Filho | 9d5040f | 2018-10-29 08:41:27 +0000 | [diff] [blame] | 180 | (void)elr; |
| 181 | (void)spsr; |
| 182 | |
Andrew Scull | a9c172d | 2019-04-03 14:10:00 +0100 | [diff] [blame] | 183 | panic("IRQ from current"); |
Wedson Almeida Filho | 987c0ff | 2018-06-20 16:34:38 +0100 | [diff] [blame] | 184 | } |
| 185 | |
Andrew Scull | c960c03 | 2018-10-24 15:13:35 +0100 | [diff] [blame] | 186 | noreturn void fiq_current_exception(uintreg_t elr, uintreg_t spsr) |
Wedson Almeida Filho | 987c0ff | 2018-06-20 16:34:38 +0100 | [diff] [blame] | 187 | { |
Wedson Almeida Filho | 9d5040f | 2018-10-29 08:41:27 +0000 | [diff] [blame] | 188 | (void)elr; |
| 189 | (void)spsr; |
| 190 | |
Andrew Scull | a9c172d | 2019-04-03 14:10:00 +0100 | [diff] [blame] | 191 | panic("FIQ from current"); |
Wedson Almeida Filho | 9d5040f | 2018-10-29 08:41:27 +0000 | [diff] [blame] | 192 | } |
| 193 | |
Andrew Scull | c960c03 | 2018-10-24 15:13:35 +0100 | [diff] [blame] | 194 | noreturn void serr_current_exception(uintreg_t elr, uintreg_t spsr) |
Wedson Almeida Filho | 9d5040f | 2018-10-29 08:41:27 +0000 | [diff] [blame] | 195 | { |
| 196 | (void)elr; |
| 197 | (void)spsr; |
| 198 | |
Andrew Scull | a9c172d | 2019-04-03 14:10:00 +0100 | [diff] [blame] | 199 | panic("SERR from current"); |
Wedson Almeida Filho | 9d5040f | 2018-10-29 08:41:27 +0000 | [diff] [blame] | 200 | } |
| 201 | |
Andrew Scull | c960c03 | 2018-10-24 15:13:35 +0100 | [diff] [blame] | 202 | noreturn void sync_current_exception(uintreg_t elr, uintreg_t spsr) |
Wedson Almeida Filho | 9d5040f | 2018-10-29 08:41:27 +0000 | [diff] [blame] | 203 | { |
| 204 | uintreg_t esr = read_msr(esr_el2); |
| 205 | |
| 206 | (void)spsr; |
| 207 | |
Wedson Almeida Filho | fed6902 | 2018-07-11 15:39:12 +0100 | [diff] [blame] | 208 | switch (esr >> 26) { |
| 209 | case 0x25: /* EC = 100101, Data abort. */ |
Andrew Scull | 4f170f5 | 2018-07-19 12:58:20 +0100 | [diff] [blame] | 210 | dlog("Data abort: pc=0x%x, esr=0x%x, ec=0x%x", elr, esr, |
| 211 | esr >> 26); |
Andrew Scull | 7364a8e | 2018-07-19 15:39:29 +0100 | [diff] [blame] | 212 | if (!(esr & (1u << 10))) { /* Check FnV bit. */ |
Andrew Scull | 0a029e8 | 2018-11-23 16:48:08 +0000 | [diff] [blame] | 213 | dlog(", far=0x%x", read_msr(far_el2)); |
Andrew Scull | 7364a8e | 2018-07-19 15:39:29 +0100 | [diff] [blame] | 214 | } else { |
Wedson Almeida Filho | fed6902 | 2018-07-11 15:39:12 +0100 | [diff] [blame] | 215 | dlog(", far=invalid"); |
Andrew Scull | 7364a8e | 2018-07-19 15:39:29 +0100 | [diff] [blame] | 216 | } |
Wedson Almeida Filho | fed6902 | 2018-07-11 15:39:12 +0100 | [diff] [blame] | 217 | |
| 218 | dlog("\n"); |
Wedson Almeida Filho | 81568c4 | 2019-01-04 13:33:02 +0000 | [diff] [blame] | 219 | break; |
Wedson Almeida Filho | fed6902 | 2018-07-11 15:39:12 +0100 | [diff] [blame] | 220 | |
| 221 | default: |
Wedson Almeida Filho | 2f94ec1 | 2018-07-26 16:00:48 +0100 | [diff] [blame] | 222 | dlog("Unknown current sync exception pc=0x%x, esr=0x%x, " |
| 223 | "ec=0x%x\n", |
| 224 | elr, esr, esr >> 26); |
Andrew Scull | c960c03 | 2018-10-24 15:13:35 +0100 | [diff] [blame] | 225 | break; |
Wedson Almeida Filho | fed6902 | 2018-07-11 15:39:12 +0100 | [diff] [blame] | 226 | } |
Wedson Almeida Filho | 81568c4 | 2019-01-04 13:33:02 +0000 | [diff] [blame] | 227 | |
Andrew Scull | a9c172d | 2019-04-03 14:10:00 +0100 | [diff] [blame] | 228 | panic("EL2 exception"); |
Wedson Almeida Filho | 987c0ff | 2018-06-20 16:34:38 +0100 | [diff] [blame] | 229 | } |
| 230 | |
Wedson Almeida Filho | 03e767a | 2018-07-30 15:32:03 +0100 | [diff] [blame] | 231 | /** |
| 232 | * Handles PSCI requests received via HVC or SMC instructions from the primary |
| 233 | * VM only. |
| 234 | * |
Andrew Scull | c960c03 | 2018-10-24 15:13:35 +0100 | [diff] [blame] | 235 | * A minimal PSCI 1.1 interface is offered which can make use of previous |
| 236 | * version of PSCI in EL3 by acting as an adapter. |
| 237 | * |
Wedson Almeida Filho | 03e767a | 2018-07-30 15:32:03 +0100 | [diff] [blame] | 238 | * Returns true if the request was a PSCI one, false otherwise. |
| 239 | */ |
Andrew Scull | 3740287 | 2018-10-24 14:23:06 +0100 | [diff] [blame] | 240 | static bool psci_handler(uint32_t func, uintreg_t arg0, uintreg_t arg1, |
| 241 | uintreg_t arg2, int32_t *ret) |
Wedson Almeida Filho | 03e767a | 2018-07-30 15:32:03 +0100 | [diff] [blame] | 242 | { |
| 243 | struct cpu *c; |
Wedson Almeida Filho | 03e767a | 2018-07-30 15:32:03 +0100 | [diff] [blame] | 244 | |
Andrew Scull | c960c03 | 2018-10-24 15:13:35 +0100 | [diff] [blame] | 245 | /* |
| 246 | * If there's a problem with the EL3 PSCI, block standard secure service |
| 247 | * calls by marking them as unknown. Other calls will be allowed to pass |
| 248 | * through. |
| 249 | * |
| 250 | * This blocks more calls than just PSCI so it may need to be made more |
| 251 | * lenient in future. |
| 252 | */ |
| 253 | if (el3_psci_version == 0) { |
| 254 | *ret = SMCCC_RETURN_UNKNOWN; |
| 255 | return (func & SMCCC_SERVICE_CALL_MASK) == |
| 256 | SMCCC_STANDARD_SECURE_SERVICE_CALL; |
| 257 | } |
| 258 | |
| 259 | switch (func & ~SMCCC_CONVENTION_MASK) { |
Wedson Almeida Filho | 03e767a | 2018-07-30 15:32:03 +0100 | [diff] [blame] | 260 | case PSCI_VERSION: |
Andrew Scull | c960c03 | 2018-10-24 15:13:35 +0100 | [diff] [blame] | 261 | *ret = PSCI_VERSION_1_1; |
Wedson Almeida Filho | 03e767a | 2018-07-30 15:32:03 +0100 | [diff] [blame] | 262 | break; |
| 263 | |
Andrew Scull | c960c03 | 2018-10-24 15:13:35 +0100 | [diff] [blame] | 264 | case PSCI_FEATURES: |
| 265 | switch (arg0 & ~SMCCC_CONVENTION_MASK) { |
| 266 | case PSCI_CPU_SUSPEND: |
| 267 | if (el3_psci_version == PSCI_VERSION_0_2) { |
| 268 | /* |
| 269 | * PSCI 0.2 doesn't support PSCI_FEATURES so |
| 270 | * report PSCI 0.2 compatible features. |
| 271 | */ |
| 272 | *ret = 0; |
| 273 | } else { |
| 274 | /* PSCI 1.x only defines two feature bits. */ |
| 275 | *ret = smc(func, arg0, 0, 0) & 0x3; |
| 276 | } |
| 277 | break; |
| 278 | |
| 279 | case PSCI_VERSION: |
| 280 | case PSCI_FEATURES: |
| 281 | case PSCI_SYSTEM_OFF: |
| 282 | case PSCI_SYSTEM_RESET: |
| 283 | case PSCI_AFFINITY_INFO: |
| 284 | case PSCI_CPU_OFF: |
| 285 | case PSCI_CPU_ON: |
| 286 | /* These are supported without special features. */ |
| 287 | *ret = 0; |
| 288 | break; |
| 289 | |
| 290 | default: |
| 291 | /* Everything else is unsupported. */ |
| 292 | *ret = PSCI_RETURN_NOT_SUPPORTED; |
| 293 | break; |
| 294 | } |
Wedson Almeida Filho | 03e767a | 2018-07-30 15:32:03 +0100 | [diff] [blame] | 295 | break; |
| 296 | |
| 297 | case PSCI_SYSTEM_OFF: |
| 298 | smc(PSCI_SYSTEM_OFF, 0, 0, 0); |
Andrew Scull | a9c172d | 2019-04-03 14:10:00 +0100 | [diff] [blame] | 299 | panic("System off failed"); |
Wedson Almeida Filho | 03e767a | 2018-07-30 15:32:03 +0100 | [diff] [blame] | 300 | break; |
| 301 | |
| 302 | case PSCI_SYSTEM_RESET: |
| 303 | smc(PSCI_SYSTEM_RESET, 0, 0, 0); |
Andrew Scull | a9c172d | 2019-04-03 14:10:00 +0100 | [diff] [blame] | 304 | panic("System reset failed"); |
Wedson Almeida Filho | 03e767a | 2018-07-30 15:32:03 +0100 | [diff] [blame] | 305 | break; |
| 306 | |
| 307 | case PSCI_AFFINITY_INFO: |
| 308 | c = cpu_find(arg0); |
| 309 | if (!c) { |
| 310 | *ret = PSCI_RETURN_INVALID_PARAMETERS; |
| 311 | break; |
| 312 | } |
| 313 | |
| 314 | if (arg1 != 0) { |
| 315 | *ret = PSCI_RETURN_NOT_SUPPORTED; |
| 316 | break; |
| 317 | } |
| 318 | |
| 319 | sl_lock(&c->lock); |
| 320 | if (c->is_on) { |
| 321 | *ret = 0; /* ON */ |
| 322 | } else { |
| 323 | *ret = 1; /* OFF */ |
| 324 | } |
| 325 | sl_unlock(&c->lock); |
| 326 | break; |
| 327 | |
Andrew Scull | c960c03 | 2018-10-24 15:13:35 +0100 | [diff] [blame] | 328 | case PSCI_CPU_SUSPEND: { |
| 329 | /* |
| 330 | * Update vcpu state to wake from the provided entry point but |
| 331 | * if suspend returns, for example because it failed or was a |
| 332 | * standby power state, the SMC will return and the updated |
| 333 | * vcpu registers will be ignored. |
| 334 | */ |
| 335 | struct vcpu *vcpu = current(); |
| 336 | |
| 337 | arch_regs_set_pc_arg(&vcpu->regs, ipa_init(arg1), arg2); |
| 338 | *ret = smc(PSCI_CPU_SUSPEND | SMCCC_64_BIT, arg0, |
| 339 | (uintreg_t)&cpu_entry, (uintreg_t)vcpu->cpu); |
| 340 | break; |
| 341 | } |
| 342 | |
Wedson Almeida Filho | 03e767a | 2018-07-30 15:32:03 +0100 | [diff] [blame] | 343 | case PSCI_CPU_OFF: |
Wedson Almeida Filho | 00df6c7 | 2018-10-18 11:19:24 +0100 | [diff] [blame] | 344 | cpu_off(current()->cpu); |
Wedson Almeida Filho | 03e767a | 2018-07-30 15:32:03 +0100 | [diff] [blame] | 345 | smc(PSCI_CPU_OFF, 0, 0, 0); |
Andrew Scull | a9c172d | 2019-04-03 14:10:00 +0100 | [diff] [blame] | 346 | panic("CPU off failed"); |
Wedson Almeida Filho | 03e767a | 2018-07-30 15:32:03 +0100 | [diff] [blame] | 347 | break; |
| 348 | |
| 349 | case PSCI_CPU_ON: |
| 350 | c = cpu_find(arg0); |
| 351 | if (!c) { |
| 352 | *ret = PSCI_RETURN_INVALID_PARAMETERS; |
| 353 | break; |
| 354 | } |
| 355 | |
Andrew Scull | 1b8d044 | 2018-08-06 15:47:04 +0100 | [diff] [blame] | 356 | if (cpu_on(c, ipa_init(arg1), arg2)) { |
Wedson Almeida Filho | 03e767a | 2018-07-30 15:32:03 +0100 | [diff] [blame] | 357 | *ret = PSCI_RETURN_ALREADY_ON; |
| 358 | break; |
| 359 | } |
| 360 | |
| 361 | /* |
| 362 | * There's a race when turning a CPU on when it's in the |
| 363 | * process of turning off. We need to loop here while it is |
| 364 | * reported that the CPU is on (because it's about to turn |
| 365 | * itself off). |
| 366 | */ |
| 367 | do { |
Andrew Scull | c960c03 | 2018-10-24 15:13:35 +0100 | [diff] [blame] | 368 | *ret = smc(PSCI_CPU_ON | SMCCC_64_BIT, arg0, |
| 369 | (uintreg_t)&cpu_entry, (uintreg_t)c); |
| 370 | } while (*ret == PSCI_RETURN_ALREADY_ON); |
Wedson Almeida Filho | 03e767a | 2018-07-30 15:32:03 +0100 | [diff] [blame] | 371 | |
Andrew Scull | c960c03 | 2018-10-24 15:13:35 +0100 | [diff] [blame] | 372 | if (*ret != PSCI_RETURN_SUCCESS) { |
| 373 | cpu_off(c); |
Wedson Almeida Filho | 03e767a | 2018-07-30 15:32:03 +0100 | [diff] [blame] | 374 | } |
| 375 | break; |
| 376 | |
Andrew Scull | c960c03 | 2018-10-24 15:13:35 +0100 | [diff] [blame] | 377 | case PSCI_MIGRATE: |
| 378 | case PSCI_MIGRATE_INFO_TYPE: |
| 379 | case PSCI_MIGRATE_INFO_UP_CPU: |
| 380 | case PSCI_CPU_FREEZE: |
| 381 | case PSCI_CPU_DEFAULT_SUSPEND: |
| 382 | case PSCI_NODE_HW_STATE: |
| 383 | case PSCI_SYSTEM_SUSPEND: |
| 384 | case PSCI_SET_SYSPEND_MODE: |
| 385 | case PSCI_STAT_RESIDENCY: |
| 386 | case PSCI_STAT_COUNT: |
| 387 | case PSCI_SYSTEM_RESET2: |
| 388 | case PSCI_MEM_PROTECT: |
| 389 | case PSCI_MEM_PROTECT_CHECK_RANGE: |
| 390 | /* Block all other known PSCI calls. */ |
| 391 | *ret = PSCI_RETURN_NOT_SUPPORTED; |
| 392 | break; |
| 393 | |
Wedson Almeida Filho | 03e767a | 2018-07-30 15:32:03 +0100 | [diff] [blame] | 394 | default: |
| 395 | return false; |
| 396 | } |
| 397 | |
| 398 | return true; |
| 399 | } |
| 400 | |
Andrew Walbran | 3d84a26 | 2018-12-13 14:41:19 +0000 | [diff] [blame] | 401 | /** |
| 402 | * Sets or clears the VI bit in the HCR_EL2 register saved in the given |
| 403 | * arch_regs. |
| 404 | */ |
| 405 | static void set_virtual_interrupt(struct arch_regs *r, bool enable) |
| 406 | { |
| 407 | if (enable) { |
| 408 | r->lazy.hcr_el2 |= HCR_EL2_VI; |
| 409 | } else { |
| 410 | r->lazy.hcr_el2 &= ~HCR_EL2_VI; |
| 411 | } |
| 412 | } |
| 413 | |
| 414 | /** |
| 415 | * Sets or clears the VI bit in the HCR_EL2 register. |
| 416 | */ |
| 417 | static void set_virtual_interrupt_current(bool enable) |
| 418 | { |
| 419 | uintreg_t hcr_el2 = read_msr(hcr_el2); |
Wedson Almeida Filho | 81568c4 | 2019-01-04 13:33:02 +0000 | [diff] [blame] | 420 | |
Andrew Walbran | 3d84a26 | 2018-12-13 14:41:19 +0000 | [diff] [blame] | 421 | if (enable) { |
| 422 | hcr_el2 |= HCR_EL2_VI; |
| 423 | } else { |
| 424 | hcr_el2 &= ~HCR_EL2_VI; |
| 425 | } |
| 426 | write_msr(hcr_el2, hcr_el2); |
| 427 | } |
| 428 | |
Andrew Scull | 3740287 | 2018-10-24 14:23:06 +0100 | [diff] [blame] | 429 | struct hvc_handler_return hvc_handler(uintreg_t arg0, uintreg_t arg1, |
| 430 | uintreg_t arg2, uintreg_t arg3) |
Wedson Almeida Filho | 987c0ff | 2018-06-20 16:34:38 +0100 | [diff] [blame] | 431 | { |
| 432 | struct hvc_handler_return ret; |
| 433 | |
Wedson Almeida Filho | 8700964 | 2018-07-02 10:20:07 +0100 | [diff] [blame] | 434 | ret.new = NULL; |
Wedson Almeida Filho | 987c0ff | 2018-06-20 16:34:38 +0100 | [diff] [blame] | 435 | |
Wedson Almeida Filho | 00df6c7 | 2018-10-18 11:19:24 +0100 | [diff] [blame] | 436 | if (current()->vm->id == HF_PRIMARY_VM_ID) { |
Andrew Scull | c0e569a | 2018-10-02 18:05:21 +0100 | [diff] [blame] | 437 | int32_t psci_ret; |
Wedson Almeida Filho | 81568c4 | 2019-01-04 13:33:02 +0000 | [diff] [blame] | 438 | |
Andrew Scull | c0e569a | 2018-10-02 18:05:21 +0100 | [diff] [blame] | 439 | if (psci_handler(arg0, arg1, arg2, arg3, &psci_ret)) { |
| 440 | ret.user_ret = psci_ret; |
| 441 | return ret; |
| 442 | } |
Wedson Almeida Filho | 03e767a | 2018-07-30 15:32:03 +0100 | [diff] [blame] | 443 | } |
Wedson Almeida Filho | 987c0ff | 2018-06-20 16:34:38 +0100 | [diff] [blame] | 444 | |
Jose Marinho | a1dfeda | 2019-02-27 16:46:03 +0000 | [diff] [blame] | 445 | switch ((uint32_t)arg0) { |
Jose Marinho | fc0b2b6 | 2019-06-06 11:18:45 +0100 | [diff] [blame] | 446 | case SPCI_VERSION_32: |
| 447 | ret.user_ret = api_spci_version(); |
| 448 | break; |
| 449 | |
Andrew Scull | 55c4d8b | 2018-12-18 18:50:18 +0000 | [diff] [blame] | 450 | case HF_VM_GET_ID: |
| 451 | ret.user_ret = api_vm_get_id(current()); |
| 452 | break; |
| 453 | |
Wedson Almeida Filho | 8700964 | 2018-07-02 10:20:07 +0100 | [diff] [blame] | 454 | case HF_VM_GET_COUNT: |
Wedson Almeida Filho | 3fcbcff | 2018-07-10 23:53:39 +0100 | [diff] [blame] | 455 | ret.user_ret = api_vm_get_count(); |
Wedson Almeida Filho | 987c0ff | 2018-06-20 16:34:38 +0100 | [diff] [blame] | 456 | break; |
Wedson Almeida Filho | 8700964 | 2018-07-02 10:20:07 +0100 | [diff] [blame] | 457 | |
| 458 | case HF_VCPU_GET_COUNT: |
Wedson Almeida Filho | 00df6c7 | 2018-10-18 11:19:24 +0100 | [diff] [blame] | 459 | ret.user_ret = api_vcpu_get_count(arg1, current()); |
Wedson Almeida Filho | 8700964 | 2018-07-02 10:20:07 +0100 | [diff] [blame] | 460 | break; |
| 461 | |
| 462 | case HF_VCPU_RUN: |
Andrew Scull | 6d2db33 | 2018-10-10 15:28:17 +0100 | [diff] [blame] | 463 | ret.user_ret = hf_vcpu_run_return_encode( |
Wedson Almeida Filho | 00df6c7 | 2018-10-18 11:19:24 +0100 | [diff] [blame] | 464 | api_vcpu_run(arg1, arg2, current(), &ret.new)); |
Wedson Almeida Filho | 8700964 | 2018-07-02 10:20:07 +0100 | [diff] [blame] | 465 | break; |
Wedson Almeida Filho | 987c0ff | 2018-06-20 16:34:38 +0100 | [diff] [blame] | 466 | |
Jose Marinho | 135dff3 | 2019-02-28 10:25:57 +0000 | [diff] [blame] | 467 | case SPCI_YIELD_32: |
| 468 | ret.user_ret = api_spci_yield(current(), &ret.new); |
Andrew Scull | 55c4d8b | 2018-12-18 18:50:18 +0000 | [diff] [blame] | 469 | break; |
| 470 | |
Wedson Almeida Filho | 2f94ec1 | 2018-07-26 16:00:48 +0100 | [diff] [blame] | 471 | case HF_VM_CONFIGURE: |
Wedson Almeida Filho | 00df6c7 | 2018-10-18 11:19:24 +0100 | [diff] [blame] | 472 | ret.user_ret = api_vm_configure(ipa_init(arg1), ipa_init(arg2), |
Wedson Almeida Filho | ea62e2e | 2019-01-09 19:14:59 +0000 | [diff] [blame] | 473 | current(), &ret.new); |
Wedson Almeida Filho | 2f94ec1 | 2018-07-26 16:00:48 +0100 | [diff] [blame] | 474 | break; |
| 475 | |
Jose Marinho | a1dfeda | 2019-02-27 16:46:03 +0000 | [diff] [blame] | 476 | case SPCI_MSG_SEND_32: |
| 477 | ret.user_ret = api_spci_msg_send(arg1, current(), &ret.new); |
Wedson Almeida Filho | 2f94ec1 | 2018-07-26 16:00:48 +0100 | [diff] [blame] | 478 | break; |
| 479 | |
Jose Marinho | 3e2442f | 2019-03-12 13:30:37 +0000 | [diff] [blame] | 480 | case SPCI_MSG_RECV_32: |
| 481 | ret.user_ret = api_spci_msg_recv(arg1, current(), &ret.new); |
Wedson Almeida Filho | 2f94ec1 | 2018-07-26 16:00:48 +0100 | [diff] [blame] | 482 | break; |
| 483 | |
Andrew Scull | aa039b3 | 2018-10-04 15:02:26 +0100 | [diff] [blame] | 484 | case HF_MAILBOX_CLEAR: |
Wedson Almeida Filho | ea62e2e | 2019-01-09 19:14:59 +0000 | [diff] [blame] | 485 | ret.user_ret = api_mailbox_clear(current(), &ret.new); |
| 486 | break; |
| 487 | |
| 488 | case HF_MAILBOX_WRITABLE_GET: |
| 489 | ret.user_ret = api_mailbox_writable_get(current()); |
| 490 | break; |
| 491 | |
| 492 | case HF_MAILBOX_WAITER_GET: |
| 493 | ret.user_ret = api_mailbox_waiter_get(arg1, current()); |
Wedson Almeida Filho | 2f94ec1 | 2018-07-26 16:00:48 +0100 | [diff] [blame] | 494 | break; |
| 495 | |
Wedson Almeida Filho | c559d13 | 2019-01-09 19:33:40 +0000 | [diff] [blame] | 496 | case HF_INTERRUPT_ENABLE: |
| 497 | ret.user_ret = api_interrupt_enable(arg1, arg2, current()); |
Andrew Walbran | 318f573 | 2018-11-20 16:23:42 +0000 | [diff] [blame] | 498 | break; |
| 499 | |
Wedson Almeida Filho | c559d13 | 2019-01-09 19:33:40 +0000 | [diff] [blame] | 500 | case HF_INTERRUPT_GET: |
| 501 | ret.user_ret = api_interrupt_get(current()); |
Andrew Walbran | 318f573 | 2018-11-20 16:23:42 +0000 | [diff] [blame] | 502 | break; |
| 503 | |
Wedson Almeida Filho | c559d13 | 2019-01-09 19:33:40 +0000 | [diff] [blame] | 504 | case HF_INTERRUPT_INJECT: |
| 505 | ret.user_ret = api_interrupt_inject(arg1, arg2, arg3, current(), |
Andrew Walbran | 318f573 | 2018-11-20 16:23:42 +0000 | [diff] [blame] | 506 | &ret.new); |
| 507 | break; |
| 508 | |
Andrew Scull | 6386f25 | 2018-12-06 13:29:10 +0000 | [diff] [blame] | 509 | case HF_SHARE_MEMORY: |
| 510 | ret.user_ret = |
| 511 | api_share_memory(arg1 >> 32, ipa_init(arg2), arg3, |
| 512 | arg1 & 0xffffffff, current()); |
| 513 | break; |
| 514 | |
Wedson Almeida Filho | 987c0ff | 2018-06-20 16:34:38 +0100 | [diff] [blame] | 515 | default: |
| 516 | ret.user_ret = -1; |
| 517 | } |
| 518 | |
Andrew Walbran | 3d84a26 | 2018-12-13 14:41:19 +0000 | [diff] [blame] | 519 | /* Set or clear VI bit. */ |
| 520 | if (ret.new == NULL) { |
| 521 | /* |
| 522 | * Not switching vCPUs, set the bit for the current vCPU |
| 523 | * directly in the register. |
| 524 | */ |
| 525 | set_virtual_interrupt_current( |
| 526 | current()->interrupts.enabled_and_pending_count > 0); |
| 527 | } else { |
| 528 | /* |
| 529 | * About to switch vCPUs, set the bit for the vCPU to which we |
| 530 | * are switching in the saved copy of the register. |
| 531 | */ |
| 532 | set_virtual_interrupt( |
| 533 | &ret.new->regs, |
| 534 | ret.new->interrupts.enabled_and_pending_count > 0); |
| 535 | } |
| 536 | |
Wedson Almeida Filho | 987c0ff | 2018-06-20 16:34:38 +0100 | [diff] [blame] | 537 | return ret; |
| 538 | } |
| 539 | |
Wedson Almeida Filho | 8700964 | 2018-07-02 10:20:07 +0100 | [diff] [blame] | 540 | struct vcpu *irq_lower(void) |
| 541 | { |
Andrew Scull | 9726c25 | 2019-01-23 13:44:19 +0000 | [diff] [blame] | 542 | /* |
| 543 | * Switch back to primary VM, interrupts will be handled there. |
| 544 | * |
| 545 | * If the VM has aborted, this vCPU will be aborted when the scheduler |
| 546 | * tries to run it again. This means the interrupt will not be delayed |
| 547 | * by the aborted VM. |
| 548 | * |
| 549 | * TODO: Only switch when the interrupt isn't for the current VM. |
| 550 | */ |
Andrew Scull | 33fecd3 | 2019-01-08 14:48:27 +0000 | [diff] [blame] | 551 | return api_preempt(current()); |
Wedson Almeida Filho | 8700964 | 2018-07-02 10:20:07 +0100 | [diff] [blame] | 552 | } |
| 553 | |
Wedson Almeida Filho | 9d5040f | 2018-10-29 08:41:27 +0000 | [diff] [blame] | 554 | struct vcpu *fiq_lower(void) |
| 555 | { |
| 556 | return irq_lower(); |
| 557 | } |
| 558 | |
| 559 | struct vcpu *serr_lower(void) |
| 560 | { |
| 561 | dlog("SERR from lower\n"); |
Andrew Scull | 9726c25 | 2019-01-23 13:44:19 +0000 | [diff] [blame] | 562 | return api_abort(current()); |
Wedson Almeida Filho | 9d5040f | 2018-10-29 08:41:27 +0000 | [diff] [blame] | 563 | } |
| 564 | |
Wedson Almeida Filho | 99d2d4c | 2019-02-14 12:53:46 +0000 | [diff] [blame] | 565 | /** |
| 566 | * Initialises a fault info structure. It assumes that an FnV bit exists at |
| 567 | * bit offset 10 of the ESR, and that it is only valid when the bottom 6 bits of |
| 568 | * the ESR (the fault status code) are 010000; this is the case for both |
| 569 | * instruction and data aborts, but not necessarily for other exception reasons. |
| 570 | */ |
| 571 | static struct vcpu_fault_info fault_info_init(uintreg_t esr, |
Andrew Scull | d3cfaad | 2019-04-04 11:34:10 +0100 | [diff] [blame] | 572 | const struct vcpu *vcpu, int mode) |
Wedson Almeida Filho | 99d2d4c | 2019-02-14 12:53:46 +0000 | [diff] [blame] | 573 | { |
| 574 | uint32_t fsc = esr & 0x3f; |
| 575 | struct vcpu_fault_info r; |
| 576 | |
| 577 | r.mode = mode; |
Wedson Almeida Filho | 99d2d4c | 2019-02-14 12:53:46 +0000 | [diff] [blame] | 578 | r.pc = va_init(vcpu->regs.pc); |
| 579 | |
| 580 | /* |
| 581 | * Check the FnV bit, which is only valid if dfsc/ifsc is 010000. It |
| 582 | * indicates that we cannot rely on far_el2. |
| 583 | */ |
| 584 | if (fsc == 0x10 && esr & (1u << 10)) { |
| 585 | r.vaddr = va_init(0); |
| 586 | r.ipaddr = ipa_init(read_msr(hpfar_el2) << 8); |
| 587 | } else { |
| 588 | r.vaddr = va_init(read_msr(far_el2)); |
| 589 | r.ipaddr = ipa_init((read_msr(hpfar_el2) << 8) | |
| 590 | (read_msr(far_el2) & (PAGE_SIZE - 1))); |
| 591 | } |
| 592 | |
| 593 | return r; |
| 594 | } |
| 595 | |
Andrew Scull | 3740287 | 2018-10-24 14:23:06 +0100 | [diff] [blame] | 596 | struct vcpu *sync_lower_exception(uintreg_t esr) |
Wedson Almeida Filho | 987c0ff | 2018-06-20 16:34:38 +0100 | [diff] [blame] | 597 | { |
Wedson Almeida Filho | 00df6c7 | 2018-10-18 11:19:24 +0100 | [diff] [blame] | 598 | struct vcpu *vcpu = current(); |
Wedson Almeida Filho | 99d2d4c | 2019-02-14 12:53:46 +0000 | [diff] [blame] | 599 | struct vcpu_fault_info info; |
Jose Marinho | 135dff3 | 2019-02-28 10:25:57 +0000 | [diff] [blame] | 600 | struct vcpu *new_vcpu; |
Wedson Almeida Filho | 987c0ff | 2018-06-20 16:34:38 +0100 | [diff] [blame] | 601 | |
| 602 | switch (esr >> 26) { |
| 603 | case 0x01: /* EC = 000001, WFI or WFE. */ |
Andrew Walbran | 48196eb | 2019-03-04 14:56:24 +0000 | [diff] [blame] | 604 | /* Skip the instruction. */ |
| 605 | vcpu->regs.pc += (esr & (1u << 25)) ? 4 : 2; |
Wedson Almeida Filho | 8700964 | 2018-07-02 10:20:07 +0100 | [diff] [blame] | 606 | /* Check TI bit of ISS, 0 = WFI, 1 = WFE. */ |
Andrew Scull | 7364a8e | 2018-07-19 15:39:29 +0100 | [diff] [blame] | 607 | if (esr & 1) { |
Andrew Walbran | 48196eb | 2019-03-04 14:56:24 +0000 | [diff] [blame] | 608 | /* WFE */ |
| 609 | /* |
| 610 | * TODO: consider giving the scheduler more context, |
| 611 | * somehow. |
| 612 | */ |
Jose Marinho | 135dff3 | 2019-02-28 10:25:57 +0000 | [diff] [blame] | 613 | api_spci_yield(vcpu, &new_vcpu); |
| 614 | return new_vcpu; |
Andrew Scull | 7364a8e | 2018-07-19 15:39:29 +0100 | [diff] [blame] | 615 | } |
Andrew Walbran | 48196eb | 2019-03-04 14:56:24 +0000 | [diff] [blame] | 616 | /* WFI */ |
Andrew Scull | 9726c25 | 2019-01-23 13:44:19 +0000 | [diff] [blame] | 617 | return api_wait_for_interrupt(vcpu); |
Wedson Almeida Filho | 987c0ff | 2018-06-20 16:34:38 +0100 | [diff] [blame] | 618 | |
| 619 | case 0x24: /* EC = 100100, Data abort. */ |
Wedson Almeida Filho | 99d2d4c | 2019-02-14 12:53:46 +0000 | [diff] [blame] | 620 | info = fault_info_init( |
Andrew Scull | d3cfaad | 2019-04-04 11:34:10 +0100 | [diff] [blame] | 621 | esr, vcpu, (esr & (1u << 6)) ? MM_MODE_W : MM_MODE_R); |
Wedson Almeida Filho | 99d2d4c | 2019-02-14 12:53:46 +0000 | [diff] [blame] | 622 | if (vcpu_handle_page_fault(vcpu, &info)) { |
| 623 | return NULL; |
| 624 | } |
Wedson Almeida Filho | 81568c4 | 2019-01-04 13:33:02 +0000 | [diff] [blame] | 625 | break; |
Wedson Almeida Filho | 987c0ff | 2018-06-20 16:34:38 +0100 | [diff] [blame] | 626 | |
Wedson Almeida Filho | 2f94ec1 | 2018-07-26 16:00:48 +0100 | [diff] [blame] | 627 | case 0x20: /* EC = 100000, Instruction abort. */ |
Andrew Scull | d3cfaad | 2019-04-04 11:34:10 +0100 | [diff] [blame] | 628 | info = fault_info_init(esr, vcpu, MM_MODE_X); |
Wedson Almeida Filho | 99d2d4c | 2019-02-14 12:53:46 +0000 | [diff] [blame] | 629 | if (vcpu_handle_page_fault(vcpu, &info)) { |
| 630 | return NULL; |
| 631 | } |
Wedson Almeida Filho | 81568c4 | 2019-01-04 13:33:02 +0000 | [diff] [blame] | 632 | break; |
Wedson Almeida Filho | 2f94ec1 | 2018-07-26 16:00:48 +0100 | [diff] [blame] | 633 | |
Andrew Scull | c960c03 | 2018-10-24 15:13:35 +0100 | [diff] [blame] | 634 | case 0x17: /* EC = 010111, SMC instruction. */ { |
| 635 | uintreg_t smc_pc = vcpu->regs.pc; |
| 636 | int32_t ret; |
| 637 | |
Andrew Scull | 1950326 | 2018-09-20 14:48:39 +0100 | [diff] [blame] | 638 | if (vcpu->vm->id != HF_PRIMARY_VM_ID || |
Wedson Almeida Filho | 03e767a | 2018-07-30 15:32:03 +0100 | [diff] [blame] | 639 | !psci_handler(vcpu->regs.r[0], vcpu->regs.r[1], |
| 640 | vcpu->regs.r[2], vcpu->regs.r[3], &ret)) { |
| 641 | dlog("Unsupported SMC call: 0x%x\n", vcpu->regs.r[0]); |
Andrew Scull | c960c03 | 2018-10-24 15:13:35 +0100 | [diff] [blame] | 642 | ret = PSCI_RETURN_NOT_SUPPORTED; |
Wedson Almeida Filho | 03e767a | 2018-07-30 15:32:03 +0100 | [diff] [blame] | 643 | } |
| 644 | |
| 645 | /* Skip the SMC instruction. */ |
Andrew Scull | c960c03 | 2018-10-24 15:13:35 +0100 | [diff] [blame] | 646 | vcpu->regs.pc = smc_pc + (esr & (1u << 25) ? 4 : 2); |
Andrew Scull | 9726c25 | 2019-01-23 13:44:19 +0000 | [diff] [blame] | 647 | vcpu->regs.r[0] = ret; |
| 648 | return NULL; |
Andrew Scull | c960c03 | 2018-10-24 15:13:35 +0100 | [diff] [blame] | 649 | } |
Wedson Almeida Filho | 03e767a | 2018-07-30 15:32:03 +0100 | [diff] [blame] | 650 | |
Wedson Almeida Filho | 987c0ff | 2018-06-20 16:34:38 +0100 | [diff] [blame] | 651 | default: |
Wedson Almeida Filho | 2f94ec1 | 2018-07-26 16:00:48 +0100 | [diff] [blame] | 652 | dlog("Unknown lower sync exception pc=0x%x, esr=0x%x, " |
| 653 | "ec=0x%x\n", |
Andrew Scull | 4f170f5 | 2018-07-19 12:58:20 +0100 | [diff] [blame] | 654 | vcpu->regs.pc, esr, esr >> 26); |
Andrew Scull | 9726c25 | 2019-01-23 13:44:19 +0000 | [diff] [blame] | 655 | break; |
Wedson Almeida Filho | 987c0ff | 2018-06-20 16:34:38 +0100 | [diff] [blame] | 656 | } |
| 657 | |
Andrew Scull | 9726c25 | 2019-01-23 13:44:19 +0000 | [diff] [blame] | 658 | /* The exception wasn't handled so abort the VM. */ |
| 659 | return api_abort(vcpu); |
Wedson Almeida Filho | 987c0ff | 2018-06-20 16:34:38 +0100 | [diff] [blame] | 660 | } |