16bb96fa6SBoyan Karatotev /* 23f4c1e1eSBoyan Karatotev * Copyright (c) 2017-2023, Arm Limited and Contributors. All rights reserved. 36bb96fa6SBoyan Karatotev * 46bb96fa6SBoyan Karatotev * SPDX-License-Identifier: BSD-3-Clause 56bb96fa6SBoyan Karatotev */ 66bb96fa6SBoyan Karatotev 76bb96fa6SBoyan Karatotev #ifndef ERRATA_REPORT_H 86bb96fa6SBoyan Karatotev #define ERRATA_REPORT_H 96bb96fa6SBoyan Karatotev 103f4c1e1eSBoyan Karatotev #include <lib/cpus/cpu_ops.h> 113f4c1e1eSBoyan Karatotev 123f4c1e1eSBoyan Karatotev 133f4c1e1eSBoyan Karatotev #define ERRATUM_WA_FUNC_SIZE CPU_WORD_SIZE 143f4c1e1eSBoyan Karatotev #define ERRATUM_CHECK_FUNC_SIZE CPU_WORD_SIZE 153f4c1e1eSBoyan Karatotev #define ERRATUM_ID_SIZE 4 163f4c1e1eSBoyan Karatotev #define ERRATUM_CVE_SIZE 2 173f4c1e1eSBoyan Karatotev #define ERRATUM_CHOSEN_SIZE 1 183f4c1e1eSBoyan Karatotev #define ERRATUM_MITIGATED_SIZE 1 193f4c1e1eSBoyan Karatotev 203f4c1e1eSBoyan Karatotev #define ERRATUM_WA_FUNC 0 213f4c1e1eSBoyan Karatotev #define ERRATUM_CHECK_FUNC ERRATUM_WA_FUNC + ERRATUM_WA_FUNC_SIZE 223f4c1e1eSBoyan Karatotev #define ERRATUM_ID ERRATUM_CHECK_FUNC + ERRATUM_CHECK_FUNC_SIZE 233f4c1e1eSBoyan Karatotev #define ERRATUM_CVE ERRATUM_ID + ERRATUM_ID_SIZE 243f4c1e1eSBoyan Karatotev #define ERRATUM_CHOSEN ERRATUM_CVE + ERRATUM_CVE_SIZE 253f4c1e1eSBoyan Karatotev #define ERRATUM_MITIGATED ERRATUM_CHOSEN + ERRATUM_CHOSEN_SIZE 263f4c1e1eSBoyan Karatotev #define ERRATUM_ENTRY_SIZE ERRATUM_MITIGATED + ERRATUM_MITIGATED_SIZE 273f4c1e1eSBoyan Karatotev 28*4a97ff51SArvind Ram Prakash /* Errata status */ 29*4a97ff51SArvind Ram Prakash #define ERRATA_NOT_APPLIES 0 30*4a97ff51SArvind Ram Prakash #define ERRATA_APPLIES 1 31*4a97ff51SArvind Ram Prakash #define ERRATA_MISSING 2 32*4a97ff51SArvind Ram Prakash 336bb96fa6SBoyan Karatotev #ifndef __ASSEMBLER__ 344f748cc4SBoyan Karatotev #include <lib/cassert.h> 356bb96fa6SBoyan Karatotev 366bb96fa6SBoyan Karatotev void print_errata_status(void); 376bb96fa6SBoyan Karatotev void errata_print_msg(unsigned int status, const char *cpu, const char *id); 386bb96fa6SBoyan Karatotev 39*4a97ff51SArvind Ram Prakash #if ERRATA_A520_2938996 || ERRATA_X4_2726228 40*4a97ff51SArvind Ram Prakash unsigned int check_if_affected_core(void); 41*4a97ff51SArvind Ram Prakash #endif 42*4a97ff51SArvind Ram Prakash 434f748cc4SBoyan Karatotev /* 444f748cc4SBoyan Karatotev * NOTE that this structure will be different on AArch32 and AArch64. The 454f748cc4SBoyan Karatotev * uintptr_t will reflect the change and the alignment will be correct in both. 464f748cc4SBoyan Karatotev */ 474f748cc4SBoyan Karatotev struct erratum_entry { 484f748cc4SBoyan Karatotev uintptr_t (*wa_func)(uint64_t cpu_rev); 494f748cc4SBoyan Karatotev uintptr_t (*check_func)(uint64_t cpu_rev); 504f748cc4SBoyan Karatotev /* Will fit CVEs with up to 10 character in the ID field */ 514f748cc4SBoyan Karatotev uint32_t id; 524f748cc4SBoyan Karatotev /* Denote CVEs with their year or errata with 0 */ 534f748cc4SBoyan Karatotev uint16_t cve; 544f748cc4SBoyan Karatotev uint8_t chosen; 554f748cc4SBoyan Karatotev /* TODO(errata ABI): placeholder for the mitigated field */ 564f748cc4SBoyan Karatotev uint8_t _mitigated; 574f748cc4SBoyan Karatotev } __packed; 584f748cc4SBoyan Karatotev 594f748cc4SBoyan Karatotev CASSERT(sizeof(struct erratum_entry) == ERRATUM_ENTRY_SIZE, 604f748cc4SBoyan Karatotev assert_erratum_entry_asm_c_different_sizes); 613f4c1e1eSBoyan Karatotev #else 623f4c1e1eSBoyan Karatotev 633f4c1e1eSBoyan Karatotev /* 643f4c1e1eSBoyan Karatotev * errata framework macro helpers 653f4c1e1eSBoyan Karatotev * 663f4c1e1eSBoyan Karatotev * NOTE an erratum and CVE id could clash. However, both numbers are very large 673f4c1e1eSBoyan Karatotev * and the probablity is minuscule. Working around this makes code very 683f4c1e1eSBoyan Karatotev * complicated and extremely difficult to read so it is not considered. In the 693f4c1e1eSBoyan Karatotev * unlikely event that this does happen, prepending the CVE id with a 0 should 703f4c1e1eSBoyan Karatotev * resolve the conflict 713f4c1e1eSBoyan Karatotev */ 723f4c1e1eSBoyan Karatotev #define ERRATUM(id) 0, id 733f4c1e1eSBoyan Karatotev #define CVE(year, id) year, id 743f4c1e1eSBoyan Karatotev #define NO_ISB 1 753f4c1e1eSBoyan Karatotev #define NO_ASSERT 0 7694a75ad4SBoyan Karatotev #define NO_APPLY_AT_RESET 0 7794a75ad4SBoyan Karatotev #define APPLY_AT_RESET 1 784d22b0e5SHarrison Mutai #define GET_CPU_REV 1 794d22b0e5SHarrison Mutai #define NO_GET_CPU_REV 0 804d22b0e5SHarrison Mutai 8194a75ad4SBoyan Karatotev /* useful for errata that end up always being worked around */ 8294a75ad4SBoyan Karatotev #define ERRATUM_ALWAYS_CHOSEN 1 833f4c1e1eSBoyan Karatotev 846bb96fa6SBoyan Karatotev #endif /* __ASSEMBLER__ */ 856bb96fa6SBoyan Karatotev 866bb96fa6SBoyan Karatotev /* Macro to get CPU revision code for checking errata version compatibility. */ 876bb96fa6SBoyan Karatotev #define CPU_REV(r, p) ((r << 4) | p) 886bb96fa6SBoyan Karatotev 896bb96fa6SBoyan Karatotev #endif /* ERRATA_REPORT_H */ 90