Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 1 | /* |
Deepika Bhavnani | c249d5e | 2020-02-06 16:29:45 -0600 | [diff] [blame] | 2 | * Copyright (c) 2018-2020, Arm Limited. All rights reserved. |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <arch.h> |
| 8 | #include <asm_macros.S> |
| 9 | #include <sdei.h> |
| 10 | |
| 11 | |
Deepika Bhavnani | c249d5e | 2020-02-06 16:29:45 -0600 | [diff] [blame] | 12 | #ifdef __aarch64__ |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 13 | .globl inject_serror |
| 14 | .globl inject_uncontainable |
| 15 | .globl serror_sdei_event_handler |
| 16 | |
| 17 | /* |
| 18 | * Program fault injection register, and wait for ever for the fault to trigger. |
David Horstmann | 85c39c5 | 2020-11-09 11:42:31 +0000 | [diff] [blame] | 19 | * Note that the model must be launched with fault inject support. |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 20 | * |
| 21 | * x0: Fault record number to program |
| 22 | * x1: Injected fault properties |
| 23 | * x2: Type of error to be generated |
| 24 | * x3: Memory location to wait for, or 0 if no waiting is required |
| 25 | */ |
| 26 | func inject_serror_record |
David Horstmann | 85c39c5 | 2020-11-09 11:42:31 +0000 | [diff] [blame] | 27 | /* Clear SError received flag if necessary */ |
| 28 | cbz x3, 1f |
| 29 | str xzr, [x3, #0] |
| 30 | 1: |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 31 | /* Choose Error record 0 on the PE */ |
| 32 | msr ERRSELR_EL1, x0 |
| 33 | isb |
| 34 | |
| 35 | /* Enable error reporting */ |
| 36 | orr x1, x1, #ERXCTLR_ED_BIT |
| 37 | msr ERXCTLR_EL1, x1 |
| 38 | |
| 39 | /* Program count down timer to 1 */ |
| 40 | mov x0, #1 |
| 41 | msr ERXPFGCDN_EL1, x0 |
| 42 | |
| 43 | /* Start count down to generate error */ |
| 44 | orr x2, x2, #ERXPFGCTL_CDEN_BIT |
| 45 | msr ERXPFGCTL_EL1, x2 |
| 46 | isb |
| 47 | |
David Horstmann | 85c39c5 | 2020-11-09 11:42:31 +0000 | [diff] [blame] | 48 | /* If no waiting is required, jump to end */ |
| 49 | cbz x3, 3f |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 50 | |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 51 | sevl |
| 52 | |
David Horstmann | 85c39c5 | 2020-11-09 11:42:31 +0000 | [diff] [blame] | 53 | 2: |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 54 | wfe |
| 55 | ldr x0, [x3, #0] |
David Horstmann | 85c39c5 | 2020-11-09 11:42:31 +0000 | [diff] [blame] | 56 | cbz x0, 2b |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 57 | |
David Horstmann | 85c39c5 | 2020-11-09 11:42:31 +0000 | [diff] [blame] | 58 | 3: |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 59 | ret |
| 60 | endfunc inject_serror_record |
| 61 | |
| 62 | /* |
| 63 | * Inject Unrecoverable error through fault record 0. Wait until serror_received |
| 64 | * is set by the SDEI handler in response to receving the event. |
| 65 | */ |
| 66 | func inject_serror |
| 67 | /* Inject fault into record 0 */ |
| 68 | mov x0, #0 |
| 69 | |
| 70 | /* Enable error reporting */ |
| 71 | mov x1, #ERXCTLR_UE_BIT |
| 72 | msr ERXCTLR_EL1, x1 |
| 73 | |
| 74 | /* Injected fault control */ |
| 75 | mov x2, #ERXPFGCTL_UEU_BIT |
| 76 | |
| 77 | /* Wait address */ |
| 78 | adrp x3, serror_received |
| 79 | add x3, x3, :lo12:serror_received |
| 80 | |
| 81 | b inject_serror_record |
| 82 | endfunc inject_serror |
| 83 | |
| 84 | /* |
| 85 | * Inject Uncontainable error through fault record 0. This function doesn't wait |
| 86 | * as the handling is terminal in EL3. |
| 87 | */ |
| 88 | func inject_uncontainable |
| 89 | /* Inject fault into record 0 */ |
| 90 | mov x0, #0 |
| 91 | |
| 92 | mov x1, xzr |
| 93 | |
| 94 | /* Injected fault control */ |
| 95 | mov x2, #ERXPFGCTL_UC_BIT |
| 96 | |
| 97 | /* Nothing to wait for */ |
| 98 | mov x3, xzr |
| 99 | |
| 100 | b inject_serror_record |
| 101 | endfunc inject_uncontainable |
| 102 | |
| 103 | /* |
| 104 | * SDEI event handler for SErrors. |
| 105 | */ |
| 106 | func serror_sdei_event_handler |
| 107 | stp x29, x30, [sp, #-16]! |
| 108 | bl serror_handler |
| 109 | ldp x29, x30, [sp], #16 |
| 110 | mov_imm x0, SDEI_EVENT_COMPLETE |
| 111 | mov x1, xzr |
| 112 | smc #0 |
| 113 | b . |
| 114 | endfunc serror_sdei_event_handler |
| 115 | #endif |