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] |
David Horstmann | aeda12b | 2021-04-23 15:24:46 +0100 | [diff] [blame] | 30 | dsb st |
David Horstmann | 85c39c5 | 2020-11-09 11:42:31 +0000 | [diff] [blame] | 31 | 1: |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 32 | /* Choose Error record 0 on the PE */ |
| 33 | msr ERRSELR_EL1, x0 |
| 34 | isb |
| 35 | |
| 36 | /* Enable error reporting */ |
| 37 | orr x1, x1, #ERXCTLR_ED_BIT |
| 38 | msr ERXCTLR_EL1, x1 |
| 39 | |
| 40 | /* Program count down timer to 1 */ |
| 41 | mov x0, #1 |
| 42 | msr ERXPFGCDN_EL1, x0 |
| 43 | |
| 44 | /* Start count down to generate error */ |
| 45 | orr x2, x2, #ERXPFGCTL_CDEN_BIT |
| 46 | msr ERXPFGCTL_EL1, x2 |
| 47 | isb |
| 48 | |
David Horstmann | 85c39c5 | 2020-11-09 11:42:31 +0000 | [diff] [blame] | 49 | /* If no waiting is required, jump to end */ |
| 50 | cbz x3, 3f |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 51 | |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 52 | sevl |
| 53 | |
David Horstmann | 85c39c5 | 2020-11-09 11:42:31 +0000 | [diff] [blame] | 54 | 2: |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 55 | wfe |
David Horstmann | aeda12b | 2021-04-23 15:24:46 +0100 | [diff] [blame] | 56 | dsb st |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 57 | ldr x0, [x3, #0] |
David Horstmann | 85c39c5 | 2020-11-09 11:42:31 +0000 | [diff] [blame] | 58 | cbz x0, 2b |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 59 | |
David Horstmann | 85c39c5 | 2020-11-09 11:42:31 +0000 | [diff] [blame] | 60 | 3: |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 61 | ret |
| 62 | endfunc inject_serror_record |
| 63 | |
| 64 | /* |
| 65 | * Inject Unrecoverable error through fault record 0. Wait until serror_received |
| 66 | * is set by the SDEI handler in response to receving the event. |
| 67 | */ |
| 68 | func inject_serror |
| 69 | /* Inject fault into record 0 */ |
| 70 | mov x0, #0 |
| 71 | |
| 72 | /* Enable error reporting */ |
| 73 | mov x1, #ERXCTLR_UE_BIT |
| 74 | msr ERXCTLR_EL1, x1 |
| 75 | |
| 76 | /* Injected fault control */ |
| 77 | mov x2, #ERXPFGCTL_UEU_BIT |
| 78 | |
| 79 | /* Wait address */ |
| 80 | adrp x3, serror_received |
| 81 | add x3, x3, :lo12:serror_received |
| 82 | |
| 83 | b inject_serror_record |
| 84 | endfunc inject_serror |
| 85 | |
| 86 | /* |
| 87 | * Inject Uncontainable error through fault record 0. This function doesn't wait |
| 88 | * as the handling is terminal in EL3. |
| 89 | */ |
| 90 | func inject_uncontainable |
| 91 | /* Inject fault into record 0 */ |
| 92 | mov x0, #0 |
| 93 | |
| 94 | mov x1, xzr |
| 95 | |
| 96 | /* Injected fault control */ |
| 97 | mov x2, #ERXPFGCTL_UC_BIT |
| 98 | |
| 99 | /* Nothing to wait for */ |
| 100 | mov x3, xzr |
| 101 | |
| 102 | b inject_serror_record |
| 103 | endfunc inject_uncontainable |
| 104 | |
| 105 | /* |
| 106 | * SDEI event handler for SErrors. |
| 107 | */ |
| 108 | func serror_sdei_event_handler |
| 109 | stp x29, x30, [sp, #-16]! |
| 110 | bl serror_handler |
| 111 | ldp x29, x30, [sp], #16 |
| 112 | mov_imm x0, SDEI_EVENT_COMPLETE |
| 113 | mov x1, xzr |
| 114 | smc #0 |
| 115 | b . |
| 116 | endfunc serror_sdei_event_handler |
| 117 | #endif |