alternative.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2021 Sifive.
  4. */
  5. #ifndef __ASM_ALTERNATIVE_H
  6. #define __ASM_ALTERNATIVE_H
  7. #define ERRATA_STRING_LENGTH_MAX 32
  8. #include <asm/alternative-macros.h>
  9. #ifndef __ASSEMBLY__
  10. #ifdef CONFIG_RISCV_ALTERNATIVE
  11. #include <linux/init.h>
  12. #include <linux/types.h>
  13. #include <linux/stddef.h>
  14. #include <asm/hwcap.h>
  15. #define RISCV_ALTERNATIVES_BOOT 0 /* alternatives applied during regular boot */
  16. #define RISCV_ALTERNATIVES_MODULE 1 /* alternatives applied during module-init */
  17. #define RISCV_ALTERNATIVES_EARLY_BOOT 2 /* alternatives applied before mmu start */
  18. void __init apply_boot_alternatives(void);
  19. void __init apply_early_boot_alternatives(void);
  20. void apply_module_alternatives(void *start, size_t length);
  21. struct alt_entry {
  22. void *old_ptr; /* address of original instruciton or data */
  23. void *alt_ptr; /* address of replacement instruction or data */
  24. unsigned long vendor_id; /* cpu vendor id */
  25. unsigned long alt_len; /* The replacement size */
  26. unsigned int errata_id; /* The errata id */
  27. } __packed;
  28. struct errata_checkfunc_id {
  29. unsigned long vendor_id;
  30. bool (*func)(struct alt_entry *alt);
  31. };
  32. void sifive_errata_patch_func(struct alt_entry *begin, struct alt_entry *end,
  33. unsigned long archid, unsigned long impid,
  34. unsigned int stage);
  35. void thead_errata_patch_func(struct alt_entry *begin, struct alt_entry *end,
  36. unsigned long archid, unsigned long impid,
  37. unsigned int stage);
  38. void riscv_cpufeature_patch_func(struct alt_entry *begin, struct alt_entry *end,
  39. unsigned int stage);
  40. #else /* CONFIG_RISCV_ALTERNATIVE */
  41. static inline void apply_boot_alternatives(void) { }
  42. static inline void apply_early_boot_alternatives(void) { }
  43. static inline void apply_module_alternatives(void *start, size_t length) { }
  44. #endif /* CONFIG_RISCV_ALTERNATIVE */
  45. #endif
  46. #endif