|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
| 2 | +/* |
| 3 | + * Copyright (C) 2021 Sifive. |
| 4 | + */ |
| 5 | + |
| 6 | +#include <linux/kernel.h> |
| 7 | +#include <linux/string.h> |
| 8 | +#include <linux/bug.h> |
| 9 | +#include <asm/patch.h> |
| 10 | +#include <asm/alternative.h> |
| 11 | +#include <asm/vendorid_list.h> |
| 12 | +#include <asm/errata_list.h> |
| 13 | + |
| 14 | +struct errata_info_t { |
| 15 | + char name[ERRATA_STRING_LENGTH_MAX]; |
| 16 | + bool (*check_func)(unsigned long arch_id, unsigned long impid); |
| 17 | +}; |
| 18 | + |
| 19 | +static u32 __init sifive_errata_probe(unsigned long archid, unsigned long impid) |
| 20 | +{ |
| 21 | + int idx; |
| 22 | + u32 cpu_req_errata = 0; |
| 23 | + |
| 24 | + for (idx = 0; idx < ERRATA_SIFIVE_NUMBER; idx++) |
| 25 | + if (errata_list[idx].check_func(archid, impid)) |
| 26 | + cpu_req_errata |= (1U << idx); |
| 27 | + |
| 28 | + return cpu_req_errata; |
| 29 | +} |
| 30 | + |
| 31 | +static void __init warn_miss_errata(u32 miss_errata) |
| 32 | +{ |
| 33 | + int i; |
| 34 | + |
| 35 | + pr_warn("----------------------------------------------------------------\n"); |
| 36 | + pr_warn("WARNING: Missing the following errata may cause potential issues\n"); |
| 37 | + for (i = 0; i < ERRATA_SIFIVE_NUMBER; i++) |
| 38 | + if (miss_errata & 0x1 << i) |
| 39 | + pr_warn("\tSiFive Errata[%d]:%s\n", i, errata_list[i].name); |
| 40 | + pr_warn("Please enable the corresponding Kconfig to apply them\n"); |
| 41 | + pr_warn("----------------------------------------------------------------\n"); |
| 42 | +} |
| 43 | + |
| 44 | +void __init sifive_errata_patch_func(struct alt_entry *begin, struct alt_entry *end, |
| 45 | + unsigned long archid, unsigned long impid) |
| 46 | +{ |
| 47 | + struct alt_entry *alt; |
| 48 | + u32 cpu_req_errata = sifive_errata_probe(archid, impid); |
| 49 | + u32 cpu_apply_errata = 0; |
| 50 | + u32 tmp; |
| 51 | + |
| 52 | + for (alt = begin; alt < end; alt++) { |
| 53 | + if (alt->vendor_id != SIFIVE_VENDOR_ID) |
| 54 | + continue; |
| 55 | + if (alt->errata_id >= ERRATA_SIFIVE_NUMBER) { |
| 56 | + WARN(1, "This errata id:%d is not in kernel errata list", alt->errata_id); |
| 57 | + continue; |
| 58 | + } |
| 59 | + |
| 60 | + tmp = (1U << alt->errata_id); |
| 61 | + if (cpu_req_errata & tmp) { |
| 62 | + patch_text_nosync(alt->old_ptr, alt->alt_ptr, alt->alt_len); |
| 63 | + cpu_apply_errata |= tmp; |
| 64 | + } |
| 65 | + } |
| 66 | + if (cpu_apply_errata != cpu_req_errata) |
| 67 | + warn_miss_errata(cpu_req_errata - cpu_apply_errata); |
| 68 | +} |
0 commit comments