blob: d84f7f1b0bbd12919ce269d80032a49824f49352 [file] [log] [blame]
Andrew Scull18834872018-10-12 11:48:09 +01001/*
Andrew Walbran692b3252019-03-07 15:51:31 +00002 * Copyright 2018 The Hafnium Authors.
Andrew Scull18834872018-10-12 11:48:09 +01003 *
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 Scullc960c032018-10-24 15:13:35 +010017#include <stdnoreturn.h>
18
Andrew Walbran1f32e722019-06-07 17:57:26 +010019#include "hf/arch/barriers.h"
Andrew Scullc960c032018-10-24 15:13:35 +010020#include "hf/arch/init.h"
21
Andrew Scull18c78fc2018-08-20 12:57:41 +010022#include "hf/api.h"
23#include "hf/cpu.h"
24#include "hf/dlog.h"
Andrew Sculla9c172d2019-04-03 14:10:00 +010025#include "hf/panic.h"
Jose Marinhoa1dfeda2019-02-27 16:46:03 +000026#include "hf/spci.h"
Andrew Scull18c78fc2018-08-20 12:57:41 +010027#include "hf/vm.h"
28
Andrew Scullf35a5c92018-08-07 18:09:46 +010029#include "vmapi/hf/call.h"
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010030
31#include "msr.h"
Andrew Scull18c78fc2018-08-20 12:57:41 +010032#include "psci.h"
Andrew Walbran33645652019-04-15 12:29:31 +010033#include "psci_handler.h"
Andrew Scull7fd4bb72018-12-08 23:40:12 +000034#include "smc.h"
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010035
Andrew Walbran3d84a262018-12-13 14:41:19 +000036#define HCR_EL2_VI (1u << 7)
37
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010038struct hvc_handler_return {
Andrew Scull37402872018-10-24 14:23:06 +010039 uintreg_t user_ret;
Wedson Almeida Filho87009642018-07-02 10:20:07 +010040 struct vcpu *new;
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010041};
42
Andrew Scullc960c032018-10-24 15:13:35 +010043/* Gets a reference to the currently executing vCPU. */
44static struct vcpu *current(void)
Andrew Walbran3d84a262018-12-13 14:41:19 +000045{
46 return (struct vcpu *)read_msr(tpidr_el2);
47}
48
Andrew Walbran1f8d4872018-12-20 11:21:32 +000049/**
50 * Saves the state of per-vCPU peripherals, such as the virtual timer, and
51 * informs the arch-independent sections that registers have been saved.
52 */
53void complete_saving_state(struct vcpu *vcpu)
54{
Andrew Walbran6480f8f2019-06-05 17:39:14 +010055 vcpu->regs.peripherals.cntv_cval_el0 = read_msr(cntv_cval_el0);
56 vcpu->regs.peripherals.cntv_ctl_el0 = read_msr(cntv_ctl_el0);
Andrew Walbran1f8d4872018-12-20 11:21:32 +000057
58 api_regs_state_saved(vcpu);
59
60 /*
61 * If switching away from the primary, copy the current EL0 virtual
62 * timer registers to the corresponding EL2 physical timer registers.
63 * This is used to emulate the virtual timer for the primary in case it
64 * should fire while the secondary is running.
65 */
66 if (vcpu->vm->id == HF_PRIMARY_VM_ID) {
67 /*
68 * Clear timer control register before copying compare value, to
69 * avoid a spurious timer interrupt. This could be a problem if
70 * the interrupt is configured as edge-triggered, as it would
71 * then be latched in.
72 */
73 write_msr(cnthp_ctl_el2, 0);
74 write_msr(cnthp_cval_el2, read_msr(cntv_cval_el0));
75 write_msr(cnthp_ctl_el2, read_msr(cntv_ctl_el0));
76 }
77}
78
79/**
80 * Restores the state of per-vCPU peripherals, such as the virtual timer.
81 */
82void begin_restoring_state(struct vcpu *vcpu)
83{
84 /*
85 * Clear timer control register before restoring compare value, to avoid
86 * a spurious timer interrupt. This could be a problem if the interrupt
87 * is configured as edge-triggered, as it would then be latched in.
88 */
89 write_msr(cntv_ctl_el0, 0);
Andrew Walbran6480f8f2019-06-05 17:39:14 +010090 write_msr(cntv_cval_el0, vcpu->regs.peripherals.cntv_cval_el0);
91 write_msr(cntv_ctl_el0, vcpu->regs.peripherals.cntv_ctl_el0);
Andrew Walbran1f8d4872018-12-20 11:21:32 +000092
93 /*
94 * If we are switching (back) to the primary, disable the EL2 physical
95 * timer which was being used to emulate the EL0 virtual timer, as the
96 * virtual timer is now running for the primary again.
97 */
98 if (vcpu->vm->id == HF_PRIMARY_VM_ID) {
99 write_msr(cnthp_ctl_el2, 0);
100 write_msr(cnthp_cval_el2, 0);
101 }
102}
103
Andrew Walbran1f32e722019-06-07 17:57:26 +0100104/**
105 * Ensures all explicit memory access and management instructions for
106 * non-shareable normal memory have completed before continuing.
107 */
108static void dsb_nsh(void)
109{
110 __asm__ volatile("dsb nsh");
111}
112
113/**
114 * Invalidate all stage 1 TLB entries on the current (physical) CPU for the
115 * current VMID.
116 */
117static void invalidate_vm_tlb(void)
118{
Andrew Walbrancff1f682019-07-04 14:52:45 +0100119 /*
120 * Ensure that the last VTTBR write has taken effect so we invalidate
121 * the right set of TLB entries.
122 */
Andrew Walbran1f32e722019-06-07 17:57:26 +0100123 isb();
Andrew Walbrancff1f682019-07-04 14:52:45 +0100124
Andrew Walbran1f32e722019-06-07 17:57:26 +0100125 __asm__ volatile("tlbi vmalle1");
Andrew Walbrancff1f682019-07-04 14:52:45 +0100126
127 /*
128 * Ensure that no instructions are fetched for the VM until after the
129 * TLB invalidation has taken effect.
130 */
Andrew Walbran1f32e722019-06-07 17:57:26 +0100131 isb();
Andrew Walbrancff1f682019-07-04 14:52:45 +0100132
133 /*
134 * Ensure that no data reads or writes for the VM happen until after the
135 * TLB invalidation has taken effect. Non-sharable is enough because the
136 * TLB is local to the CPU.
137 */
Andrew Walbran1f32e722019-06-07 17:57:26 +0100138 dsb_nsh();
139}
140
141/**
142 * Invalidates the TLB if a different vCPU is being run than the last vCPU of
143 * the same VM which was run on the current pCPU.
144 *
145 * This is necessary because VMs may (contrary to the architecture
146 * specification) use inconsistent ASIDs across vCPUs. c.f. KVM's similar
147 * workaround:
148 * https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=94d0e5980d6791b9
149 */
150void maybe_invalidate_tlb(struct vcpu *vcpu)
151{
152 size_t current_cpu_index = cpu_index(vcpu->cpu);
Andrew Walbranb037d5b2019-06-25 17:19:41 +0100153 spci_vcpu_index_t new_vcpu_index = vcpu_index(vcpu);
Andrew Walbran1f32e722019-06-07 17:57:26 +0100154
155 if (vcpu->vm->arch.last_vcpu_on_cpu[current_cpu_index] !=
156 new_vcpu_index) {
157 /*
158 * The vCPU has changed since the last time this VM was run on
159 * this pCPU, so we need to invalidate the TLB.
160 */
161 invalidate_vm_tlb();
162
163 /* Record the fact that this vCPU is now running on this CPU. */
164 vcpu->vm->arch.last_vcpu_on_cpu[current_cpu_index] =
165 new_vcpu_index;
166 }
167}
168
Andrew Scullc960c032018-10-24 15:13:35 +0100169noreturn void irq_current_exception(uintreg_t elr, uintreg_t spsr)
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100170{
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000171 (void)elr;
172 (void)spsr;
173
Andrew Sculla9c172d2019-04-03 14:10:00 +0100174 panic("IRQ from current");
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100175}
176
Andrew Scullc960c032018-10-24 15:13:35 +0100177noreturn void fiq_current_exception(uintreg_t elr, uintreg_t spsr)
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100178{
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000179 (void)elr;
180 (void)spsr;
181
Andrew Sculla9c172d2019-04-03 14:10:00 +0100182 panic("FIQ from current");
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000183}
184
Andrew Scullc960c032018-10-24 15:13:35 +0100185noreturn void serr_current_exception(uintreg_t elr, uintreg_t spsr)
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000186{
187 (void)elr;
188 (void)spsr;
189
Andrew Sculla9c172d2019-04-03 14:10:00 +0100190 panic("SERR from current");
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000191}
192
Andrew Scullc960c032018-10-24 15:13:35 +0100193noreturn void sync_current_exception(uintreg_t elr, uintreg_t spsr)
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000194{
195 uintreg_t esr = read_msr(esr_el2);
196
197 (void)spsr;
198
Wedson Almeida Filhofed69022018-07-11 15:39:12 +0100199 switch (esr >> 26) {
200 case 0x25: /* EC = 100101, Data abort. */
Andrew Scull4f170f52018-07-19 12:58:20 +0100201 dlog("Data abort: pc=0x%x, esr=0x%x, ec=0x%x", elr, esr,
202 esr >> 26);
Andrew Scull7364a8e2018-07-19 15:39:29 +0100203 if (!(esr & (1u << 10))) { /* Check FnV bit. */
Andrew Scull0a029e82018-11-23 16:48:08 +0000204 dlog(", far=0x%x", read_msr(far_el2));
Andrew Scull7364a8e2018-07-19 15:39:29 +0100205 } else {
Wedson Almeida Filhofed69022018-07-11 15:39:12 +0100206 dlog(", far=invalid");
Andrew Scull7364a8e2018-07-19 15:39:29 +0100207 }
Wedson Almeida Filhofed69022018-07-11 15:39:12 +0100208
209 dlog("\n");
Wedson Almeida Filho81568c42019-01-04 13:33:02 +0000210 break;
Wedson Almeida Filhofed69022018-07-11 15:39:12 +0100211
212 default:
Wedson Almeida Filho2f94ec12018-07-26 16:00:48 +0100213 dlog("Unknown current sync exception pc=0x%x, esr=0x%x, "
214 "ec=0x%x\n",
215 elr, esr, esr >> 26);
Andrew Scullc960c032018-10-24 15:13:35 +0100216 break;
Wedson Almeida Filhofed69022018-07-11 15:39:12 +0100217 }
Wedson Almeida Filho81568c42019-01-04 13:33:02 +0000218
Andrew Sculla9c172d2019-04-03 14:10:00 +0100219 panic("EL2 exception");
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100220}
221
Wedson Almeida Filho03e767a2018-07-30 15:32:03 +0100222/**
Andrew Walbran3d84a262018-12-13 14:41:19 +0000223 * Sets or clears the VI bit in the HCR_EL2 register saved in the given
224 * arch_regs.
225 */
226static void set_virtual_interrupt(struct arch_regs *r, bool enable)
227{
228 if (enable) {
229 r->lazy.hcr_el2 |= HCR_EL2_VI;
230 } else {
231 r->lazy.hcr_el2 &= ~HCR_EL2_VI;
232 }
233}
234
235/**
236 * Sets or clears the VI bit in the HCR_EL2 register.
237 */
238static void set_virtual_interrupt_current(bool enable)
239{
240 uintreg_t hcr_el2 = read_msr(hcr_el2);
Wedson Almeida Filho81568c42019-01-04 13:33:02 +0000241
Andrew Walbran3d84a262018-12-13 14:41:19 +0000242 if (enable) {
243 hcr_el2 |= HCR_EL2_VI;
244 } else {
245 hcr_el2 &= ~HCR_EL2_VI;
246 }
247 write_msr(hcr_el2, hcr_el2);
248}
249
Andrew Scull37402872018-10-24 14:23:06 +0100250struct hvc_handler_return hvc_handler(uintreg_t arg0, uintreg_t arg1,
251 uintreg_t arg2, uintreg_t arg3)
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100252{
253 struct hvc_handler_return ret;
254
Wedson Almeida Filho87009642018-07-02 10:20:07 +0100255 ret.new = NULL;
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100256
Andrew Walbran33645652019-04-15 12:29:31 +0100257 if (psci_handler(current(), arg0, arg1, arg2, arg3, &ret.user_ret,
258 &ret.new)) {
259 return ret;
Wedson Almeida Filho03e767a2018-07-30 15:32:03 +0100260 }
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100261
Jose Marinhoa1dfeda2019-02-27 16:46:03 +0000262 switch ((uint32_t)arg0) {
Jose Marinhofc0b2b62019-06-06 11:18:45 +0100263 case SPCI_VERSION_32:
264 ret.user_ret = api_spci_version();
265 break;
266
Andrew Scull55c4d8b2018-12-18 18:50:18 +0000267 case HF_VM_GET_ID:
268 ret.user_ret = api_vm_get_id(current());
269 break;
270
Wedson Almeida Filho87009642018-07-02 10:20:07 +0100271 case HF_VM_GET_COUNT:
Wedson Almeida Filho3fcbcff2018-07-10 23:53:39 +0100272 ret.user_ret = api_vm_get_count();
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100273 break;
Wedson Almeida Filho87009642018-07-02 10:20:07 +0100274
275 case HF_VCPU_GET_COUNT:
Wedson Almeida Filho00df6c72018-10-18 11:19:24 +0100276 ret.user_ret = api_vcpu_get_count(arg1, current());
Wedson Almeida Filho87009642018-07-02 10:20:07 +0100277 break;
278
279 case HF_VCPU_RUN:
Andrew Scull6d2db332018-10-10 15:28:17 +0100280 ret.user_ret = hf_vcpu_run_return_encode(
Wedson Almeida Filho00df6c72018-10-18 11:19:24 +0100281 api_vcpu_run(arg1, arg2, current(), &ret.new));
Wedson Almeida Filho87009642018-07-02 10:20:07 +0100282 break;
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100283
Jose Marinho135dff32019-02-28 10:25:57 +0000284 case SPCI_YIELD_32:
285 ret.user_ret = api_spci_yield(current(), &ret.new);
Andrew Scull55c4d8b2018-12-18 18:50:18 +0000286 break;
287
Wedson Almeida Filho2f94ec12018-07-26 16:00:48 +0100288 case HF_VM_CONFIGURE:
Wedson Almeida Filho00df6c72018-10-18 11:19:24 +0100289 ret.user_ret = api_vm_configure(ipa_init(arg1), ipa_init(arg2),
Wedson Almeida Filhoea62e2e2019-01-09 19:14:59 +0000290 current(), &ret.new);
Wedson Almeida Filho2f94ec12018-07-26 16:00:48 +0100291 break;
292
Jose Marinhoa1dfeda2019-02-27 16:46:03 +0000293 case SPCI_MSG_SEND_32:
294 ret.user_ret = api_spci_msg_send(arg1, current(), &ret.new);
Wedson Almeida Filho2f94ec12018-07-26 16:00:48 +0100295 break;
296
Jose Marinho3e2442f2019-03-12 13:30:37 +0000297 case SPCI_MSG_RECV_32:
298 ret.user_ret = api_spci_msg_recv(arg1, current(), &ret.new);
Wedson Almeida Filho2f94ec12018-07-26 16:00:48 +0100299 break;
300
Andrew Scullaa039b32018-10-04 15:02:26 +0100301 case HF_MAILBOX_CLEAR:
Wedson Almeida Filhoea62e2e2019-01-09 19:14:59 +0000302 ret.user_ret = api_mailbox_clear(current(), &ret.new);
303 break;
304
305 case HF_MAILBOX_WRITABLE_GET:
306 ret.user_ret = api_mailbox_writable_get(current());
307 break;
308
309 case HF_MAILBOX_WAITER_GET:
310 ret.user_ret = api_mailbox_waiter_get(arg1, current());
Wedson Almeida Filho2f94ec12018-07-26 16:00:48 +0100311 break;
312
Wedson Almeida Filhoc559d132019-01-09 19:33:40 +0000313 case HF_INTERRUPT_ENABLE:
314 ret.user_ret = api_interrupt_enable(arg1, arg2, current());
Andrew Walbran318f5732018-11-20 16:23:42 +0000315 break;
316
Wedson Almeida Filhoc559d132019-01-09 19:33:40 +0000317 case HF_INTERRUPT_GET:
318 ret.user_ret = api_interrupt_get(current());
Andrew Walbran318f5732018-11-20 16:23:42 +0000319 break;
320
Wedson Almeida Filhoc559d132019-01-09 19:33:40 +0000321 case HF_INTERRUPT_INJECT:
322 ret.user_ret = api_interrupt_inject(arg1, arg2, arg3, current(),
Andrew Walbran318f5732018-11-20 16:23:42 +0000323 &ret.new);
324 break;
325
Andrew Scull6386f252018-12-06 13:29:10 +0000326 case HF_SHARE_MEMORY:
327 ret.user_ret =
328 api_share_memory(arg1 >> 32, ipa_init(arg2), arg3,
329 arg1 & 0xffffffff, current());
330 break;
331
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100332 default:
333 ret.user_ret = -1;
334 }
335
Andrew Walbran3d84a262018-12-13 14:41:19 +0000336 /* Set or clear VI bit. */
337 if (ret.new == NULL) {
338 /*
339 * Not switching vCPUs, set the bit for the current vCPU
340 * directly in the register.
341 */
342 set_virtual_interrupt_current(
343 current()->interrupts.enabled_and_pending_count > 0);
344 } else {
345 /*
346 * About to switch vCPUs, set the bit for the vCPU to which we
347 * are switching in the saved copy of the register.
348 */
349 set_virtual_interrupt(
350 &ret.new->regs,
351 ret.new->interrupts.enabled_and_pending_count > 0);
352 }
353
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100354 return ret;
355}
356
Wedson Almeida Filho87009642018-07-02 10:20:07 +0100357struct vcpu *irq_lower(void)
358{
Andrew Scull9726c252019-01-23 13:44:19 +0000359 /*
360 * Switch back to primary VM, interrupts will be handled there.
361 *
362 * If the VM has aborted, this vCPU will be aborted when the scheduler
363 * tries to run it again. This means the interrupt will not be delayed
364 * by the aborted VM.
365 *
366 * TODO: Only switch when the interrupt isn't for the current VM.
367 */
Andrew Scull33fecd32019-01-08 14:48:27 +0000368 return api_preempt(current());
Wedson Almeida Filho87009642018-07-02 10:20:07 +0100369}
370
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000371struct vcpu *fiq_lower(void)
372{
373 return irq_lower();
374}
375
376struct vcpu *serr_lower(void)
377{
378 dlog("SERR from lower\n");
Andrew Scull9726c252019-01-23 13:44:19 +0000379 return api_abort(current());
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000380}
381
Wedson Almeida Filho99d2d4c2019-02-14 12:53:46 +0000382/**
383 * Initialises a fault info structure. It assumes that an FnV bit exists at
384 * bit offset 10 of the ESR, and that it is only valid when the bottom 6 bits of
385 * the ESR (the fault status code) are 010000; this is the case for both
386 * instruction and data aborts, but not necessarily for other exception reasons.
387 */
388static struct vcpu_fault_info fault_info_init(uintreg_t esr,
Andrew Sculld3cfaad2019-04-04 11:34:10 +0100389 const struct vcpu *vcpu, int mode)
Wedson Almeida Filho99d2d4c2019-02-14 12:53:46 +0000390{
391 uint32_t fsc = esr & 0x3f;
392 struct vcpu_fault_info r;
393
394 r.mode = mode;
Wedson Almeida Filho99d2d4c2019-02-14 12:53:46 +0000395 r.pc = va_init(vcpu->regs.pc);
396
397 /*
398 * Check the FnV bit, which is only valid if dfsc/ifsc is 010000. It
399 * indicates that we cannot rely on far_el2.
400 */
401 if (fsc == 0x10 && esr & (1u << 10)) {
402 r.vaddr = va_init(0);
403 r.ipaddr = ipa_init(read_msr(hpfar_el2) << 8);
404 } else {
405 r.vaddr = va_init(read_msr(far_el2));
406 r.ipaddr = ipa_init((read_msr(hpfar_el2) << 8) |
407 (read_msr(far_el2) & (PAGE_SIZE - 1)));
408 }
409
410 return r;
411}
412
Andrew Scull37402872018-10-24 14:23:06 +0100413struct vcpu *sync_lower_exception(uintreg_t esr)
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100414{
Wedson Almeida Filho00df6c72018-10-18 11:19:24 +0100415 struct vcpu *vcpu = current();
Wedson Almeida Filho99d2d4c2019-02-14 12:53:46 +0000416 struct vcpu_fault_info info;
Jose Marinho135dff32019-02-28 10:25:57 +0000417 struct vcpu *new_vcpu;
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100418
419 switch (esr >> 26) {
420 case 0x01: /* EC = 000001, WFI or WFE. */
Andrew Walbran48196eb2019-03-04 14:56:24 +0000421 /* Skip the instruction. */
422 vcpu->regs.pc += (esr & (1u << 25)) ? 4 : 2;
Wedson Almeida Filho87009642018-07-02 10:20:07 +0100423 /* Check TI bit of ISS, 0 = WFI, 1 = WFE. */
Andrew Scull7364a8e2018-07-19 15:39:29 +0100424 if (esr & 1) {
Andrew Walbran48196eb2019-03-04 14:56:24 +0000425 /* WFE */
426 /*
427 * TODO: consider giving the scheduler more context,
428 * somehow.
429 */
Jose Marinho135dff32019-02-28 10:25:57 +0000430 api_spci_yield(vcpu, &new_vcpu);
431 return new_vcpu;
Andrew Scull7364a8e2018-07-19 15:39:29 +0100432 }
Andrew Walbran48196eb2019-03-04 14:56:24 +0000433 /* WFI */
Andrew Scull9726c252019-01-23 13:44:19 +0000434 return api_wait_for_interrupt(vcpu);
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100435
436 case 0x24: /* EC = 100100, Data abort. */
Wedson Almeida Filho99d2d4c2019-02-14 12:53:46 +0000437 info = fault_info_init(
Andrew Sculld3cfaad2019-04-04 11:34:10 +0100438 esr, vcpu, (esr & (1u << 6)) ? MM_MODE_W : MM_MODE_R);
Wedson Almeida Filho99d2d4c2019-02-14 12:53:46 +0000439 if (vcpu_handle_page_fault(vcpu, &info)) {
440 return NULL;
441 }
Wedson Almeida Filho81568c42019-01-04 13:33:02 +0000442 break;
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100443
Wedson Almeida Filho2f94ec12018-07-26 16:00:48 +0100444 case 0x20: /* EC = 100000, Instruction abort. */
Andrew Sculld3cfaad2019-04-04 11:34:10 +0100445 info = fault_info_init(esr, vcpu, MM_MODE_X);
Wedson Almeida Filho99d2d4c2019-02-14 12:53:46 +0000446 if (vcpu_handle_page_fault(vcpu, &info)) {
447 return NULL;
448 }
Wedson Almeida Filho81568c42019-01-04 13:33:02 +0000449 break;
Wedson Almeida Filho2f94ec12018-07-26 16:00:48 +0100450
Andrew Scullc960c032018-10-24 15:13:35 +0100451 case 0x17: /* EC = 010111, SMC instruction. */ {
452 uintreg_t smc_pc = vcpu->regs.pc;
Andrew Walbran33645652019-04-15 12:29:31 +0100453 uintreg_t ret;
454 struct vcpu *next = NULL;
Andrew Scullc960c032018-10-24 15:13:35 +0100455
Andrew Walbran33645652019-04-15 12:29:31 +0100456 if (!psci_handler(vcpu, vcpu->regs.r[0], vcpu->regs.r[1],
457 vcpu->regs.r[2], vcpu->regs.r[3], &ret,
458 &next)) {
Wedson Almeida Filho03e767a2018-07-30 15:32:03 +0100459 dlog("Unsupported SMC call: 0x%x\n", vcpu->regs.r[0]);
Andrew Walbran33645652019-04-15 12:29:31 +0100460 ret = PSCI_ERROR_NOT_SUPPORTED;
Wedson Almeida Filho03e767a2018-07-30 15:32:03 +0100461 }
462
463 /* Skip the SMC instruction. */
Andrew Scullc960c032018-10-24 15:13:35 +0100464 vcpu->regs.pc = smc_pc + (esr & (1u << 25) ? 4 : 2);
Andrew Scull9726c252019-01-23 13:44:19 +0000465 vcpu->regs.r[0] = ret;
Andrew Walbran33645652019-04-15 12:29:31 +0100466 return next;
Andrew Scullc960c032018-10-24 15:13:35 +0100467 }
Wedson Almeida Filho03e767a2018-07-30 15:32:03 +0100468
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100469 default:
Wedson Almeida Filho2f94ec12018-07-26 16:00:48 +0100470 dlog("Unknown lower sync exception pc=0x%x, esr=0x%x, "
471 "ec=0x%x\n",
Andrew Scull4f170f52018-07-19 12:58:20 +0100472 vcpu->regs.pc, esr, esr >> 26);
Andrew Scull9726c252019-01-23 13:44:19 +0000473 break;
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100474 }
475
Andrew Scull9726c252019-01-23 13:44:19 +0000476 /* The exception wasn't handled so abort the VM. */
477 return api_abort(vcpu);
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100478}