blob: 1ceb04de53b9604e49b6d2d222407f36f335ca5b [file] [log] [blame]
Andrew Scull18834872018-10-12 11:48:09 +01001/*
2 * Copyright 2018 Google LLC
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 Scull18c78fc2018-08-20 12:57:41 +010017#include "hf/api.h"
18#include "hf/cpu.h"
19#include "hf/dlog.h"
20#include "hf/vm.h"
21
Andrew Scullf35a5c92018-08-07 18:09:46 +010022#include "vmapi/hf/call.h"
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010023
24#include "msr.h"
Andrew Scull18c78fc2018-08-20 12:57:41 +010025#include "psci.h"
Andrew Scull7fd4bb72018-12-08 23:40:12 +000026#include "smc.h"
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010027
Andrew Walbran3d84a262018-12-13 14:41:19 +000028#define HCR_EL2_VI (1u << 7)
29
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010030struct hvc_handler_return {
Andrew Scull37402872018-10-24 14:23:06 +010031 uintreg_t user_ret;
Wedson Almeida Filho87009642018-07-02 10:20:07 +010032 struct vcpu *new;
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010033};
34
Wedson Almeida Filho03e767a2018-07-30 15:32:03 +010035void cpu_entry(struct cpu *c);
36
Andrew Walbran3d84a262018-12-13 14:41:19 +000037static inline struct vcpu *current(void)
38{
39 return (struct vcpu *)read_msr(tpidr_el2);
40}
41
Andrew Walbran1f8d4872018-12-20 11:21:32 +000042/**
43 * Saves the state of per-vCPU peripherals, such as the virtual timer, and
44 * informs the arch-independent sections that registers have been saved.
45 */
46void complete_saving_state(struct vcpu *vcpu)
47{
48 vcpu->regs.lazy.cntv_cval_el0 = read_msr(cntv_cval_el0);
49 vcpu->regs.lazy.cntv_ctl_el0 = read_msr(cntv_ctl_el0);
50
51 api_regs_state_saved(vcpu);
52
53 /*
54 * If switching away from the primary, copy the current EL0 virtual
55 * timer registers to the corresponding EL2 physical timer registers.
56 * This is used to emulate the virtual timer for the primary in case it
57 * should fire while the secondary is running.
58 */
59 if (vcpu->vm->id == HF_PRIMARY_VM_ID) {
60 /*
61 * Clear timer control register before copying compare value, to
62 * avoid a spurious timer interrupt. This could be a problem if
63 * the interrupt is configured as edge-triggered, as it would
64 * then be latched in.
65 */
66 write_msr(cnthp_ctl_el2, 0);
67 write_msr(cnthp_cval_el2, read_msr(cntv_cval_el0));
68 write_msr(cnthp_ctl_el2, read_msr(cntv_ctl_el0));
69 }
70}
71
72/**
73 * Restores the state of per-vCPU peripherals, such as the virtual timer.
74 */
75void begin_restoring_state(struct vcpu *vcpu)
76{
77 /*
78 * Clear timer control register before restoring compare value, to avoid
79 * a spurious timer interrupt. This could be a problem if the interrupt
80 * is configured as edge-triggered, as it would then be latched in.
81 */
82 write_msr(cntv_ctl_el0, 0);
83 write_msr(cntv_cval_el0, vcpu->regs.lazy.cntv_cval_el0);
84 write_msr(cntv_ctl_el0, vcpu->regs.lazy.cntv_ctl_el0);
85
86 /*
87 * If we are switching (back) to the primary, disable the EL2 physical
88 * timer which was being used to emulate the EL0 virtual timer, as the
89 * virtual timer is now running for the primary again.
90 */
91 if (vcpu->vm->id == HF_PRIMARY_VM_ID) {
92 write_msr(cnthp_ctl_el2, 0);
93 write_msr(cnthp_cval_el2, 0);
94 }
95}
96
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +000097void irq_current_exception(uintreg_t elr, uintreg_t spsr)
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010098{
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +000099 (void)elr;
100 (void)spsr;
101
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100102 dlog("IRQ from current\n");
Andrew Scull7364a8e2018-07-19 15:39:29 +0100103 for (;;) {
104 /* do nothing */
105 }
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100106}
107
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000108void fiq_current_exception(uintreg_t elr, uintreg_t spsr)
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100109{
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000110 (void)elr;
111 (void)spsr;
112
113 dlog("FIQ from current\n");
114 for (;;) {
115 /* do nothing */
116 }
117}
118
119void serr_current_exception(uintreg_t elr, uintreg_t spsr)
120{
121 (void)elr;
122 (void)spsr;
123
124 dlog("SERR from current\n");
125 for (;;) {
126 /* do nothing */
127 }
128}
129
130void sync_current_exception(uintreg_t elr, uintreg_t spsr)
131{
132 uintreg_t esr = read_msr(esr_el2);
133
134 (void)spsr;
135
Wedson Almeida Filhofed69022018-07-11 15:39:12 +0100136 switch (esr >> 26) {
137 case 0x25: /* EC = 100101, Data abort. */
Andrew Scull4f170f52018-07-19 12:58:20 +0100138 dlog("Data abort: pc=0x%x, esr=0x%x, ec=0x%x", elr, esr,
139 esr >> 26);
Andrew Scull7364a8e2018-07-19 15:39:29 +0100140 if (!(esr & (1u << 10))) { /* Check FnV bit. */
Andrew Scull0a029e82018-11-23 16:48:08 +0000141 dlog(", far=0x%x", read_msr(far_el2));
Andrew Scull7364a8e2018-07-19 15:39:29 +0100142 } else {
Wedson Almeida Filhofed69022018-07-11 15:39:12 +0100143 dlog(", far=invalid");
Andrew Scull7364a8e2018-07-19 15:39:29 +0100144 }
Wedson Almeida Filhofed69022018-07-11 15:39:12 +0100145
146 dlog("\n");
Wedson Almeida Filho81568c42019-01-04 13:33:02 +0000147 break;
Wedson Almeida Filhofed69022018-07-11 15:39:12 +0100148
149 default:
Wedson Almeida Filho2f94ec12018-07-26 16:00:48 +0100150 dlog("Unknown current sync exception pc=0x%x, esr=0x%x, "
151 "ec=0x%x\n",
152 elr, esr, esr >> 26);
Wedson Almeida Filhofed69022018-07-11 15:39:12 +0100153 }
Wedson Almeida Filho81568c42019-01-04 13:33:02 +0000154
Andrew Scull7364a8e2018-07-19 15:39:29 +0100155 for (;;) {
156 /* do nothing */
157 }
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100158}
159
Wedson Almeida Filho03e767a2018-07-30 15:32:03 +0100160/**
161 * Handles PSCI requests received via HVC or SMC instructions from the primary
162 * VM only.
163 *
164 * Returns true if the request was a PSCI one, false otherwise.
165 */
Andrew Scull37402872018-10-24 14:23:06 +0100166static bool psci_handler(uint32_t func, uintreg_t arg0, uintreg_t arg1,
167 uintreg_t arg2, int32_t *ret)
Wedson Almeida Filho03e767a2018-07-30 15:32:03 +0100168{
169 struct cpu *c;
170 int32_t sret;
171
172 switch (func & ~PSCI_CONVENTION_MASK) {
173 case PSCI_VERSION:
174 /* Version is 0.2. */
175 *ret = 2;
176 break;
177
178 case PSCI_MIGRATE_INFO_TYPE:
179 /* Trusted OS does not require migration. */
180 *ret = 2;
181 break;
182
183 case PSCI_SYSTEM_OFF:
184 smc(PSCI_SYSTEM_OFF, 0, 0, 0);
185 for (;;) {
186 }
187 break;
188
189 case PSCI_SYSTEM_RESET:
190 smc(PSCI_SYSTEM_RESET, 0, 0, 0);
191 for (;;) {
192 }
193 break;
194
195 case PSCI_AFFINITY_INFO:
196 c = cpu_find(arg0);
197 if (!c) {
198 *ret = PSCI_RETURN_INVALID_PARAMETERS;
199 break;
200 }
201
202 if (arg1 != 0) {
203 *ret = PSCI_RETURN_NOT_SUPPORTED;
204 break;
205 }
206
207 sl_lock(&c->lock);
208 if (c->is_on) {
209 *ret = 0; /* ON */
210 } else {
211 *ret = 1; /* OFF */
212 }
213 sl_unlock(&c->lock);
214 break;
215
216 case PSCI_CPU_OFF:
Wedson Almeida Filho00df6c72018-10-18 11:19:24 +0100217 cpu_off(current()->cpu);
Wedson Almeida Filho03e767a2018-07-30 15:32:03 +0100218 smc(PSCI_CPU_OFF, 0, 0, 0);
219 for (;;) {
220 }
221 break;
222
223 case PSCI_CPU_ON:
224 c = cpu_find(arg0);
225 if (!c) {
226 *ret = PSCI_RETURN_INVALID_PARAMETERS;
227 break;
228 }
229
Andrew Scull1b8d0442018-08-06 15:47:04 +0100230 if (cpu_on(c, ipa_init(arg1), arg2)) {
Wedson Almeida Filho03e767a2018-07-30 15:32:03 +0100231 *ret = PSCI_RETURN_ALREADY_ON;
232 break;
233 }
234
235 /*
236 * There's a race when turning a CPU on when it's in the
237 * process of turning off. We need to loop here while it is
238 * reported that the CPU is on (because it's about to turn
239 * itself off).
240 */
241 do {
Andrew Scull37402872018-10-24 14:23:06 +0100242 sret = smc(PSCI_CPU_ON, arg0, (uintreg_t)&cpu_entry,
243 (uintreg_t)c);
Wedson Almeida Filho03e767a2018-07-30 15:32:03 +0100244 } while (sret == PSCI_RETURN_ALREADY_ON);
245
246 if (sret == PSCI_RETURN_SUCCESS) {
247 *ret = PSCI_RETURN_SUCCESS;
248 } else {
249 dlog("Unexpected return from PSCI_CPU_ON: 0x%x\n",
250 sret);
251 *ret = PSCI_RETURN_INTERNAL_FAILURE;
252 }
253 break;
254
255 default:
256 return false;
257 }
258
259 return true;
260}
261
Andrew Walbran3d84a262018-12-13 14:41:19 +0000262/**
263 * Sets or clears the VI bit in the HCR_EL2 register saved in the given
264 * arch_regs.
265 */
266static void set_virtual_interrupt(struct arch_regs *r, bool enable)
267{
268 if (enable) {
269 r->lazy.hcr_el2 |= HCR_EL2_VI;
270 } else {
271 r->lazy.hcr_el2 &= ~HCR_EL2_VI;
272 }
273}
274
275/**
276 * Sets or clears the VI bit in the HCR_EL2 register.
277 */
278static void set_virtual_interrupt_current(bool enable)
279{
280 uintreg_t hcr_el2 = read_msr(hcr_el2);
Wedson Almeida Filho81568c42019-01-04 13:33:02 +0000281
Andrew Walbran3d84a262018-12-13 14:41:19 +0000282 if (enable) {
283 hcr_el2 |= HCR_EL2_VI;
284 } else {
285 hcr_el2 &= ~HCR_EL2_VI;
286 }
287 write_msr(hcr_el2, hcr_el2);
288}
289
Andrew Scull37402872018-10-24 14:23:06 +0100290struct hvc_handler_return hvc_handler(uintreg_t arg0, uintreg_t arg1,
291 uintreg_t arg2, uintreg_t arg3)
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100292{
293 struct hvc_handler_return ret;
294
Wedson Almeida Filho87009642018-07-02 10:20:07 +0100295 ret.new = NULL;
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100296
Wedson Almeida Filho00df6c72018-10-18 11:19:24 +0100297 if (current()->vm->id == HF_PRIMARY_VM_ID) {
Andrew Scullc0e569a2018-10-02 18:05:21 +0100298 int32_t psci_ret;
Wedson Almeida Filho81568c42019-01-04 13:33:02 +0000299
Andrew Scullc0e569a2018-10-02 18:05:21 +0100300 if (psci_handler(arg0, arg1, arg2, arg3, &psci_ret)) {
301 ret.user_ret = psci_ret;
302 return ret;
303 }
Wedson Almeida Filho03e767a2018-07-30 15:32:03 +0100304 }
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100305
Wedson Almeida Filho03e767a2018-07-30 15:32:03 +0100306 switch ((uint32_t)arg0 & ~PSCI_CONVENTION_MASK) {
Andrew Scull55c4d8b2018-12-18 18:50:18 +0000307 case HF_VM_GET_ID:
308 ret.user_ret = api_vm_get_id(current());
309 break;
310
Wedson Almeida Filho87009642018-07-02 10:20:07 +0100311 case HF_VM_GET_COUNT:
Wedson Almeida Filho3fcbcff2018-07-10 23:53:39 +0100312 ret.user_ret = api_vm_get_count();
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100313 break;
Wedson Almeida Filho87009642018-07-02 10:20:07 +0100314
315 case HF_VCPU_GET_COUNT:
Wedson Almeida Filho00df6c72018-10-18 11:19:24 +0100316 ret.user_ret = api_vcpu_get_count(arg1, current());
Wedson Almeida Filho87009642018-07-02 10:20:07 +0100317 break;
318
319 case HF_VCPU_RUN:
Andrew Scull6d2db332018-10-10 15:28:17 +0100320 ret.user_ret = hf_vcpu_run_return_encode(
Wedson Almeida Filho00df6c72018-10-18 11:19:24 +0100321 api_vcpu_run(arg1, arg2, current(), &ret.new));
Wedson Almeida Filho87009642018-07-02 10:20:07 +0100322 break;
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100323
Andrew Scull55c4d8b2018-12-18 18:50:18 +0000324 case HF_VCPU_YIELD:
325 ret.user_ret = 0;
326 ret.new = api_yield(current());
327 break;
328
Wedson Almeida Filho2f94ec12018-07-26 16:00:48 +0100329 case HF_VM_CONFIGURE:
Wedson Almeida Filho00df6c72018-10-18 11:19:24 +0100330 ret.user_ret = api_vm_configure(ipa_init(arg1), ipa_init(arg2),
Wedson Almeida Filhoea62e2e2019-01-09 19:14:59 +0000331 current(), &ret.new);
Wedson Almeida Filho2f94ec12018-07-26 16:00:48 +0100332 break;
333
Andrew Scullaa039b32018-10-04 15:02:26 +0100334 case HF_MAILBOX_SEND:
Wedson Almeida Filho00df6c72018-10-18 11:19:24 +0100335 ret.user_ret =
Wedson Almeida Filho17c997f2019-01-09 18:50:09 +0000336 api_mailbox_send(arg1, arg2, arg3, current(), &ret.new);
Wedson Almeida Filho2f94ec12018-07-26 16:00:48 +0100337 break;
338
Andrew Scullaa039b32018-10-04 15:02:26 +0100339 case HF_MAILBOX_RECEIVE:
Andrew Scull6d2db332018-10-10 15:28:17 +0100340 ret.user_ret = hf_mailbox_receive_return_encode(
Wedson Almeida Filho00df6c72018-10-18 11:19:24 +0100341 api_mailbox_receive(arg1, current(), &ret.new));
Wedson Almeida Filho2f94ec12018-07-26 16:00:48 +0100342 break;
343
Andrew Scullaa039b32018-10-04 15:02:26 +0100344 case HF_MAILBOX_CLEAR:
Wedson Almeida Filhoea62e2e2019-01-09 19:14:59 +0000345 ret.user_ret = api_mailbox_clear(current(), &ret.new);
346 break;
347
348 case HF_MAILBOX_WRITABLE_GET:
349 ret.user_ret = api_mailbox_writable_get(current());
350 break;
351
352 case HF_MAILBOX_WAITER_GET:
353 ret.user_ret = api_mailbox_waiter_get(arg1, current());
Wedson Almeida Filho2f94ec12018-07-26 16:00:48 +0100354 break;
355
Wedson Almeida Filhoc559d132019-01-09 19:33:40 +0000356 case HF_INTERRUPT_ENABLE:
357 ret.user_ret = api_interrupt_enable(arg1, arg2, current());
Andrew Walbran318f5732018-11-20 16:23:42 +0000358 break;
359
Wedson Almeida Filhoc559d132019-01-09 19:33:40 +0000360 case HF_INTERRUPT_GET:
361 ret.user_ret = api_interrupt_get(current());
Andrew Walbran318f5732018-11-20 16:23:42 +0000362 break;
363
Wedson Almeida Filhoc559d132019-01-09 19:33:40 +0000364 case HF_INTERRUPT_INJECT:
365 ret.user_ret = api_interrupt_inject(arg1, arg2, arg3, current(),
Andrew Walbran318f5732018-11-20 16:23:42 +0000366 &ret.new);
367 break;
368
Andrew Scull6386f252018-12-06 13:29:10 +0000369 case HF_SHARE_MEMORY:
370 ret.user_ret =
371 api_share_memory(arg1 >> 32, ipa_init(arg2), arg3,
372 arg1 & 0xffffffff, current());
373 break;
374
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100375 default:
376 ret.user_ret = -1;
377 }
378
Andrew Walbran3d84a262018-12-13 14:41:19 +0000379 /* Set or clear VI bit. */
380 if (ret.new == NULL) {
381 /*
382 * Not switching vCPUs, set the bit for the current vCPU
383 * directly in the register.
384 */
385 set_virtual_interrupt_current(
386 current()->interrupts.enabled_and_pending_count > 0);
387 } else {
388 /*
389 * About to switch vCPUs, set the bit for the vCPU to which we
390 * are switching in the saved copy of the register.
391 */
392 set_virtual_interrupt(
393 &ret.new->regs,
394 ret.new->interrupts.enabled_and_pending_count > 0);
395 }
396
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100397 return ret;
398}
399
Wedson Almeida Filho87009642018-07-02 10:20:07 +0100400struct vcpu *irq_lower(void)
401{
Andrew Scull9726c252019-01-23 13:44:19 +0000402 /*
403 * Switch back to primary VM, interrupts will be handled there.
404 *
405 * If the VM has aborted, this vCPU will be aborted when the scheduler
406 * tries to run it again. This means the interrupt will not be delayed
407 * by the aborted VM.
408 *
409 * TODO: Only switch when the interrupt isn't for the current VM.
410 */
Andrew Scull33fecd32019-01-08 14:48:27 +0000411 return api_preempt(current());
Wedson Almeida Filho87009642018-07-02 10:20:07 +0100412}
413
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000414struct vcpu *fiq_lower(void)
415{
416 return irq_lower();
417}
418
419struct vcpu *serr_lower(void)
420{
421 dlog("SERR from lower\n");
Andrew Scull9726c252019-01-23 13:44:19 +0000422 return api_abort(current());
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000423}
424
Wedson Almeida Filho99d2d4c2019-02-14 12:53:46 +0000425/**
426 * Initialises a fault info structure. It assumes that an FnV bit exists at
427 * bit offset 10 of the ESR, and that it is only valid when the bottom 6 bits of
428 * the ESR (the fault status code) are 010000; this is the case for both
429 * instruction and data aborts, but not necessarily for other exception reasons.
430 */
431static struct vcpu_fault_info fault_info_init(uintreg_t esr,
432 const struct vcpu *vcpu, int mode,
433 uint8_t size)
434{
435 uint32_t fsc = esr & 0x3f;
436 struct vcpu_fault_info r;
437
438 r.mode = mode;
439 r.size = size;
440 r.pc = va_init(vcpu->regs.pc);
441
442 /*
443 * Check the FnV bit, which is only valid if dfsc/ifsc is 010000. It
444 * indicates that we cannot rely on far_el2.
445 */
446 if (fsc == 0x10 && esr & (1u << 10)) {
447 r.vaddr = va_init(0);
448 r.ipaddr = ipa_init(read_msr(hpfar_el2) << 8);
449 } else {
450 r.vaddr = va_init(read_msr(far_el2));
451 r.ipaddr = ipa_init((read_msr(hpfar_el2) << 8) |
452 (read_msr(far_el2) & (PAGE_SIZE - 1)));
453 }
454
455 return r;
456}
457
Andrew Scull37402872018-10-24 14:23:06 +0100458struct vcpu *sync_lower_exception(uintreg_t esr)
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100459{
Wedson Almeida Filho00df6c72018-10-18 11:19:24 +0100460 struct vcpu *vcpu = current();
Andrew Scullc0e569a2018-10-02 18:05:21 +0100461 int32_t ret;
Wedson Almeida Filho99d2d4c2019-02-14 12:53:46 +0000462 struct vcpu_fault_info info;
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100463
464 switch (esr >> 26) {
465 case 0x01: /* EC = 000001, WFI or WFE. */
Wedson Almeida Filho87009642018-07-02 10:20:07 +0100466 /* Check TI bit of ISS, 0 = WFI, 1 = WFE. */
Andrew Scull7364a8e2018-07-19 15:39:29 +0100467 if (esr & 1) {
Wedson Almeida Filho87009642018-07-02 10:20:07 +0100468 return NULL;
Andrew Scull7364a8e2018-07-19 15:39:29 +0100469 }
Andrew Walbran6b98b852018-12-21 14:35:19 +0000470 /* Skip the WFI instruction. */
471 vcpu->regs.pc += (esr & (1u << 25)) ? 4 : 2;
Andrew Scull9726c252019-01-23 13:44:19 +0000472 return api_wait_for_interrupt(vcpu);
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100473
474 case 0x24: /* EC = 100100, Data abort. */
Wedson Almeida Filho99d2d4c2019-02-14 12:53:46 +0000475 /*
476 * Determine the size based on the SAS bits, which are only
477 * valid if the ISV bit is set. The WnR bit is used to decide
478 * if it's a read or write.
479 */
480 info = fault_info_init(
481 esr, vcpu, (esr & (1u << 6)) ? MM_MODE_W : MM_MODE_R,
482 (esr & (1u << 24)) ? (1u << ((esr >> 22) & 0x3)) : 0);
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100483
Wedson Almeida Filho99d2d4c2019-02-14 12:53:46 +0000484 /* Call the platform-independent handler. */
485 if (vcpu_handle_page_fault(vcpu, &info)) {
486 return NULL;
487 }
Wedson Almeida Filho81568c42019-01-04 13:33:02 +0000488 break;
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100489
Wedson Almeida Filho2f94ec12018-07-26 16:00:48 +0100490 case 0x20: /* EC = 100000, Instruction abort. */
Wedson Almeida Filho99d2d4c2019-02-14 12:53:46 +0000491 /* Determine the size based on the IL bit. */
492 info = fault_info_init(esr, vcpu, MM_MODE_X,
493 (esr & (1u << 25)) ? 4 : 2);
Wedson Almeida Filho2f94ec12018-07-26 16:00:48 +0100494
Wedson Almeida Filho99d2d4c2019-02-14 12:53:46 +0000495 /* Call the platform-independent handler. */
496 if (vcpu_handle_page_fault(vcpu, &info)) {
497 return NULL;
498 }
Wedson Almeida Filho81568c42019-01-04 13:33:02 +0000499 break;
Wedson Almeida Filho2f94ec12018-07-26 16:00:48 +0100500
Wedson Almeida Filho03e767a2018-07-30 15:32:03 +0100501 case 0x17: /* EC = 010111, SMC instruction. */
Andrew Scull19503262018-09-20 14:48:39 +0100502 if (vcpu->vm->id != HF_PRIMARY_VM_ID ||
Wedson Almeida Filho03e767a2018-07-30 15:32:03 +0100503 !psci_handler(vcpu->regs.r[0], vcpu->regs.r[1],
504 vcpu->regs.r[2], vcpu->regs.r[3], &ret)) {
505 dlog("Unsupported SMC call: 0x%x\n", vcpu->regs.r[0]);
506 ret = -1;
507 }
508
509 /* Skip the SMC instruction. */
510 vcpu->regs.pc += (esr & (1u << 25)) ? 4 : 2;
Andrew Scull9726c252019-01-23 13:44:19 +0000511 vcpu->regs.r[0] = ret;
512 return NULL;
Wedson Almeida Filho03e767a2018-07-30 15:32:03 +0100513
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100514 default:
Wedson Almeida Filho2f94ec12018-07-26 16:00:48 +0100515 dlog("Unknown lower sync exception pc=0x%x, esr=0x%x, "
516 "ec=0x%x\n",
Andrew Scull4f170f52018-07-19 12:58:20 +0100517 vcpu->regs.pc, esr, esr >> 26);
Andrew Scull9726c252019-01-23 13:44:19 +0000518 break;
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100519 }
520
Andrew Scull9726c252019-01-23 13:44:19 +0000521 /* The exception wasn't handled so abort the VM. */
522 return api_abort(vcpu);
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100523}