1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2021 Sifive.
6 #include <linux/kernel.h>
7 #include <linux/string.h>
10 #include <asm/alternative.h>
11 #include <asm/vendorid_list.h>
12 #include <asm/errata_list.h>
14 struct errata_info_t {
15 char name[ERRATA_STRING_LENGTH_MAX];
16 bool (*check_func)(unsigned long arch_id, unsigned long impid);
19 static bool errata_cip_453_check_func(unsigned long arch_id, unsigned long impid)
23 * Architecture ID: 0x8000000000000007
24 * Implement ID: 0x20181004 <= impid <= 0x20191105
26 if (arch_id != 0x8000000000000007 ||
27 (impid < 0x20181004 || impid > 0x20191105))
32 static bool errata_cip_1200_check_func(unsigned long arch_id, unsigned long impid)
36 * Architecture ID: 0x8000000000000007 or 0x1
37 * Implement ID: mimpid[23:0] <= 0x200630 and mimpid != 0x01200626
39 if (arch_id != 0x8000000000000007 && arch_id != 0x1)
41 if ((impid & 0xffffff) > 0x200630 || impid == 0x1200626)
46 static struct errata_info_t errata_list[ERRATA_SIFIVE_NUMBER] = {
49 .check_func = errata_cip_453_check_func
53 .check_func = errata_cip_1200_check_func
57 static u32 __init sifive_errata_probe(unsigned long archid, unsigned long impid)
60 u32 cpu_req_errata = 0;
62 for (idx = 0; idx < ERRATA_SIFIVE_NUMBER; idx++)
63 if (errata_list[idx].check_func(archid, impid))
64 cpu_req_errata |= (1U << idx);
66 return cpu_req_errata;
69 static void __init warn_miss_errata(u32 miss_errata)
73 pr_warn("----------------------------------------------------------------\n");
74 pr_warn("WARNING: Missing the following errata may cause potential issues\n");
75 for (i = 0; i < ERRATA_SIFIVE_NUMBER; i++)
76 if (miss_errata & 0x1 << i)
77 pr_warn("\tSiFive Errata[%d]:%s\n", i, errata_list[i].name);
78 pr_warn("Please enable the corresponding Kconfig to apply them\n");
79 pr_warn("----------------------------------------------------------------\n");
82 void __init sifive_errata_patch_func(struct alt_entry *begin, struct alt_entry *end,
83 unsigned long archid, unsigned long impid)
85 struct alt_entry *alt;
86 u32 cpu_req_errata = sifive_errata_probe(archid, impid);
87 u32 cpu_apply_errata = 0;
90 for (alt = begin; alt < end; alt++) {
91 if (alt->vendor_id != SIFIVE_VENDOR_ID)
93 if (alt->errata_id >= ERRATA_SIFIVE_NUMBER) {
94 WARN(1, "This errata id:%d is not in kernel errata list", alt->errata_id);
98 tmp = (1U << alt->errata_id);
99 if (cpu_req_errata & tmp) {
100 patch_text_nosync(alt->old_ptr, alt->alt_ptr, alt->alt_len);
101 cpu_apply_errata |= tmp;
104 if (cpu_apply_errata != cpu_req_errata)
105 warn_miss_errata(cpu_req_errata - cpu_apply_errata);