sbi_hart.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * SPDX-License-Identifier: BSD-2-Clause
  3. *
  4. * Copyright (c) 2019 Western Digital Corporation or its affiliates.
  5. *
  6. * Authors:
  7. * Anup Patel <anup.patel@wdc.com>
  8. */
  9. #ifndef __SBI_HART_H__
  10. #define __SBI_HART_H__
  11. #include <sbi/sbi_types.h>
  12. /** Possible privileged specification versions of a hart */
  13. enum sbi_hart_priv_versions {
  14. /** Unknown privileged specification */
  15. SBI_HART_PRIV_VER_UNKNOWN = 0,
  16. /** Privileged specification v1.10 */
  17. SBI_HART_PRIV_VER_1_10 = 1,
  18. /** Privileged specification v1.11 */
  19. SBI_HART_PRIV_VER_1_11 = 2,
  20. /** Privileged specification v1.12 */
  21. SBI_HART_PRIV_VER_1_12 = 3,
  22. };
  23. /** Possible ISA extensions of a hart */
  24. enum sbi_hart_extensions {
  25. /** Hart has Sscofpmt extension */
  26. SBI_HART_EXT_SSCOFPMF = 0,
  27. /** HART has HW time CSR (extension name not available) */
  28. SBI_HART_EXT_TIME,
  29. /** HART has AIA M-mode CSRs */
  30. SBI_HART_EXT_SMAIA,
  31. /** HART has Smstateen CSR **/
  32. SBI_HART_EXT_SMSTATEEN,
  33. /** HART has Sstc extension */
  34. SBI_HART_EXT_SSTC,
  35. /** Maximum index of Hart extension */
  36. SBI_HART_EXT_MAX,
  37. };
  38. struct sbi_hart_features {
  39. bool detected;
  40. int priv_version;
  41. unsigned long extensions;
  42. unsigned int pmp_count;
  43. unsigned int pmp_addr_bits;
  44. unsigned long pmp_gran;
  45. unsigned int mhpm_count;
  46. unsigned int mhpm_bits;
  47. };
  48. struct sbi_scratch;
  49. int sbi_hart_reinit(struct sbi_scratch *scratch);
  50. int sbi_hart_init(struct sbi_scratch *scratch, bool cold_boot);
  51. extern void (*sbi_hart_expected_trap)(void);
  52. static inline ulong sbi_hart_expected_trap_addr(void)
  53. {
  54. return (ulong)sbi_hart_expected_trap;
  55. }
  56. unsigned int sbi_hart_mhpm_count(struct sbi_scratch *scratch);
  57. void sbi_hart_delegation_dump(struct sbi_scratch *scratch,
  58. const char *prefix, const char *suffix);
  59. unsigned int sbi_hart_pmp_count(struct sbi_scratch *scratch);
  60. unsigned long sbi_hart_pmp_granularity(struct sbi_scratch *scratch);
  61. unsigned int sbi_hart_pmp_addrbits(struct sbi_scratch *scratch);
  62. unsigned int sbi_hart_mhpm_bits(struct sbi_scratch *scratch);
  63. int sbi_hart_pmp_configure(struct sbi_scratch *scratch);
  64. int sbi_hart_priv_version(struct sbi_scratch *scratch);
  65. void sbi_hart_get_priv_version_str(struct sbi_scratch *scratch,
  66. char *version_str, int nvstr);
  67. void sbi_hart_update_extension(struct sbi_scratch *scratch,
  68. enum sbi_hart_extensions ext,
  69. bool enable);
  70. bool sbi_hart_has_extension(struct sbi_scratch *scratch,
  71. enum sbi_hart_extensions ext);
  72. void sbi_hart_get_extensions_str(struct sbi_scratch *scratch,
  73. char *extension_str, int nestr);
  74. void __attribute__((noreturn)) sbi_hart_hang(void);
  75. void __attribute__((noreturn))
  76. sbi_hart_switch_mode(unsigned long arg0, unsigned long arg1,
  77. unsigned long next_addr, unsigned long next_mode,
  78. bool next_virt);
  79. #endif