sbi_hart.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 feature flags of a hart */
  13. enum sbi_hart_features {
  14. /** Hart has S-mode counter enable */
  15. SBI_HART_HAS_SCOUNTEREN = (1 << 0),
  16. /** Hart has M-mode counter enable */
  17. SBI_HART_HAS_MCOUNTEREN = (1 << 1),
  18. /** Hart has counter inhibit CSR */
  19. SBI_HART_HAS_MCOUNTINHIBIT = (1 << 2),
  20. /** Hart has sscofpmf extension */
  21. SBI_HART_HAS_SSCOFPMF = (1 << 3),
  22. /** HART has timer csr implementation in hardware */
  23. SBI_HART_HAS_TIME = (1 << 4),
  24. /** Last index of Hart features*/
  25. SBI_HART_HAS_LAST_FEATURE = SBI_HART_HAS_TIME,
  26. };
  27. struct sbi_scratch;
  28. int sbi_hart_reinit(struct sbi_scratch *scratch);
  29. int sbi_hart_init(struct sbi_scratch *scratch, bool cold_boot);
  30. extern void (*sbi_hart_expected_trap)(void);
  31. static inline ulong sbi_hart_expected_trap_addr(void)
  32. {
  33. return (ulong)sbi_hart_expected_trap;
  34. }
  35. unsigned int sbi_hart_mhpm_count(struct sbi_scratch *scratch);
  36. void sbi_hart_delegation_dump(struct sbi_scratch *scratch,
  37. const char *prefix, const char *suffix);
  38. unsigned int sbi_hart_pmp_count(struct sbi_scratch *scratch);
  39. unsigned long sbi_hart_pmp_granularity(struct sbi_scratch *scratch);
  40. unsigned int sbi_hart_pmp_addrbits(struct sbi_scratch *scratch);
  41. unsigned int sbi_hart_mhpm_bits(struct sbi_scratch *scratch);
  42. int sbi_hart_pmp_configure(struct sbi_scratch *scratch);
  43. bool sbi_hart_has_feature(struct sbi_scratch *scratch, unsigned long feature);
  44. void sbi_hart_get_features_str(struct sbi_scratch *scratch,
  45. char *features_str, int nfstr);
  46. void __attribute__((noreturn)) sbi_hart_hang(void);
  47. void __attribute__((noreturn))
  48. sbi_hart_switch_mode(unsigned long arg0, unsigned long arg1,
  49. unsigned long next_addr, unsigned long next_mode,
  50. bool next_virt);
  51. #endif