1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (c) 2024 Arm Ltd 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 */ 27 28 #ifndef _MACHINE_CPU_FEAT_H_ 29 #define _MACHINE_CPU_FEAT_H_ 30 31 #include <sys/linker_set.h> 32 33 typedef enum { 34 ERRATA_UNKNOWN, /* Unknown erratum */ 35 ERRATA_NONE, /* No errata for this feature on this system. */ 36 ERRATA_AFFECTED, /* There is errata on this system. */ 37 ERRATA_FW_MITIGAION, /* There is errata, and a firmware */ 38 /* mitigation. The mitigation may need a */ 39 /* kernel component. */ 40 } cpu_feat_errata; 41 42 #define CPU_FEAT_STAGE_MASK 0x00000001 43 #define CPU_FEAT_EARLY_BOOT 0x00000000 44 #define CPU_FEAT_AFTER_DEV 0x00000001 45 46 #define CPU_FEAT_SCOPE_MASK 0x00000010 47 #define CPU_FEAT_PER_CPU 0x00000000 48 #define CPU_FEAT_SYSTEM 0x00000010 49 50 struct cpu_feat; 51 52 typedef bool (cpu_feat_check)(const struct cpu_feat *, u_int); 53 typedef bool (cpu_feat_has_errata)(const struct cpu_feat *, u_int, 54 u_int **, u_int *); 55 typedef void (cpu_feat_enable)(const struct cpu_feat *, cpu_feat_errata, 56 u_int *, u_int); 57 58 struct cpu_feat { 59 const char *feat_name; 60 cpu_feat_check *feat_check; 61 cpu_feat_has_errata *feat_has_errata; 62 cpu_feat_enable *feat_enable; 63 uint32_t feat_flags; 64 }; 65 SET_DECLARE(cpu_feat_set, struct cpu_feat); 66 67 /* 68 * Allow drivers to mark an erratum as worked around, e.g. the Errata 69 * Management ABI may know the workaround isn't needed on a given system. 70 */ 71 typedef cpu_feat_errata (*cpu_feat_errata_check_fn)(const struct cpu_feat *, 72 u_int); 73 void cpu_feat_register_errata_check(cpu_feat_errata_check_fn); 74 75 void enable_cpu_feat(uint32_t); 76 77 /* Check if an erratum is in the list of errata */ 78 static inline bool 79 cpu_feat_has_erratum(u_int *errata_list, u_int errata_count, u_int erratum) 80 { 81 for (u_int i = 0; i < errata_count; i++) 82 if (errata_list[0] == erratum) 83 return (true); 84 85 return (false); 86 } 87 88 #endif /* _MACHINE_CPU_FEAT_H_ */ 89