hwcap.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copied from arch/arm64/include/asm/hwcap.h
  4. *
  5. * Copyright (C) 2012 ARM Ltd.
  6. * Copyright (C) 2017 SiFive
  7. */
  8. #ifndef _ASM_RISCV_HWCAP_H
  9. #define _ASM_RISCV_HWCAP_H
  10. #include <asm/errno.h>
  11. #include <linux/bits.h>
  12. #include <uapi/asm/hwcap.h>
  13. #ifndef __ASSEMBLY__
  14. #include <linux/jump_label.h>
  15. /*
  16. * This yields a mask that user programs can use to figure out what
  17. * instruction set this cpu supports.
  18. */
  19. #define ELF_HWCAP (elf_hwcap)
  20. enum {
  21. CAP_HWCAP = 1,
  22. };
  23. extern unsigned long elf_hwcap;
  24. #define RISCV_ISA_EXT_a ('a' - 'a')
  25. #define RISCV_ISA_EXT_c ('c' - 'a')
  26. #define RISCV_ISA_EXT_d ('d' - 'a')
  27. #define RISCV_ISA_EXT_f ('f' - 'a')
  28. #define RISCV_ISA_EXT_h ('h' - 'a')
  29. #define RISCV_ISA_EXT_i ('i' - 'a')
  30. #define RISCV_ISA_EXT_m ('m' - 'a')
  31. #define RISCV_ISA_EXT_s ('s' - 'a')
  32. #define RISCV_ISA_EXT_u ('u' - 'a')
  33. /*
  34. * Increse this to higher value as kernel support more ISA extensions.
  35. */
  36. #define RISCV_ISA_EXT_MAX 64
  37. #define RISCV_ISA_EXT_NAME_LEN_MAX 32
  38. /* The base ID for multi-letter ISA extensions */
  39. #define RISCV_ISA_EXT_BASE 26
  40. /*
  41. * This enum represent the logical ID for each multi-letter RISC-V ISA extension.
  42. * The logical ID should start from RISCV_ISA_EXT_BASE and must not exceed
  43. * RISCV_ISA_EXT_MAX. 0-25 range is reserved for single letter
  44. * extensions while all the multi-letter extensions should define the next
  45. * available logical extension id.
  46. */
  47. enum riscv_isa_ext_id {
  48. RISCV_ISA_EXT_SSCOFPMF = RISCV_ISA_EXT_BASE,
  49. RISCV_ISA_EXT_SVPBMT,
  50. RISCV_ISA_EXT_ZICBOM,
  51. RISCV_ISA_EXT_ZIHINTPAUSE,
  52. RISCV_ISA_EXT_SSTC,
  53. RISCV_ISA_EXT_SVINVAL,
  54. RISCV_ISA_EXT_ID_MAX = RISCV_ISA_EXT_MAX,
  55. };
  56. /*
  57. * This enum represents the logical ID for each RISC-V ISA extension static
  58. * keys. We can use static key to optimize code path if some ISA extensions
  59. * are available.
  60. */
  61. enum riscv_isa_ext_key {
  62. RISCV_ISA_EXT_KEY_FPU, /* For 'F' and 'D' */
  63. RISCV_ISA_EXT_KEY_ZIHINTPAUSE,
  64. RISCV_ISA_EXT_KEY_SVINVAL,
  65. RISCV_ISA_EXT_KEY_MAX,
  66. };
  67. struct riscv_isa_ext_data {
  68. /* Name of the extension displayed to userspace via /proc/cpuinfo */
  69. char uprop[RISCV_ISA_EXT_NAME_LEN_MAX];
  70. /* The logical ISA extension ID */
  71. unsigned int isa_ext_id;
  72. };
  73. extern struct static_key_false riscv_isa_ext_keys[RISCV_ISA_EXT_KEY_MAX];
  74. static __always_inline int riscv_isa_ext2key(int num)
  75. {
  76. switch (num) {
  77. case RISCV_ISA_EXT_f:
  78. return RISCV_ISA_EXT_KEY_FPU;
  79. case RISCV_ISA_EXT_d:
  80. return RISCV_ISA_EXT_KEY_FPU;
  81. case RISCV_ISA_EXT_ZIHINTPAUSE:
  82. return RISCV_ISA_EXT_KEY_ZIHINTPAUSE;
  83. case RISCV_ISA_EXT_SVINVAL:
  84. return RISCV_ISA_EXT_KEY_SVINVAL;
  85. default:
  86. return -EINVAL;
  87. }
  88. }
  89. unsigned long riscv_isa_extension_base(const unsigned long *isa_bitmap);
  90. #define riscv_isa_extension_mask(ext) BIT_MASK(RISCV_ISA_EXT_##ext)
  91. bool __riscv_isa_extension_available(const unsigned long *isa_bitmap, int bit);
  92. #define riscv_isa_extension_available(isa_bitmap, ext) \
  93. __riscv_isa_extension_available(isa_bitmap, RISCV_ISA_EXT_##ext)
  94. #endif
  95. #endif /* _ASM_RISCV_HWCAP_H */