cputype.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * Copyright (C) 2012 ARM Ltd.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef __ASM_CPUTYPE_H
  17. #define __ASM_CPUTYPE_H
  18. #define INVALID_HWID ULONG_MAX
  19. #define MPIDR_UP_BITMASK (0x1 << 30)
  20. #define MPIDR_MT_BITMASK (0x1 << 24)
  21. #define MPIDR_HWID_BITMASK 0xff00ffffff
  22. #define MPIDR_LEVEL_BITS_SHIFT 3
  23. #define MPIDR_LEVEL_BITS (1 << MPIDR_LEVEL_BITS_SHIFT)
  24. #define MPIDR_LEVEL_MASK ((1 << MPIDR_LEVEL_BITS) - 1)
  25. #define MPIDR_LEVEL_SHIFT(level) \
  26. (((1 << level) >> 1) << MPIDR_LEVEL_BITS_SHIFT)
  27. #define MPIDR_AFFINITY_LEVEL(mpidr, level) \
  28. ((mpidr >> MPIDR_LEVEL_SHIFT(level)) & MPIDR_LEVEL_MASK)
  29. #define read_cpuid(reg) ({ \
  30. u64 __val; \
  31. asm("mrs %0, " #reg : "=r" (__val)); \
  32. __val; \
  33. })
  34. #define MIDR_REVISION_MASK 0xf
  35. #define MIDR_REVISION(midr) ((midr) & MIDR_REVISION_MASK)
  36. #define MIDR_PARTNUM_SHIFT 4
  37. #define MIDR_PARTNUM_MASK (0xfff << MIDR_PARTNUM_SHIFT)
  38. #define MIDR_PARTNUM(midr) \
  39. (((midr) & MIDR_PARTNUM_MASK) >> MIDR_PARTNUM_SHIFT)
  40. #define MIDR_ARCHITECTURE_SHIFT 16
  41. #define MIDR_ARCHITECTURE_MASK (0xf << MIDR_ARCHITECTURE_SHIFT)
  42. #define MIDR_ARCHITECTURE(midr) \
  43. (((midr) & MIDR_ARCHITECTURE_MASK) >> MIDR_ARCHITECTURE_SHIFT)
  44. #define MIDR_VARIANT_SHIFT 20
  45. #define MIDR_VARIANT_MASK (0xf << MIDR_VARIANT_SHIFT)
  46. #define MIDR_VARIANT(midr) \
  47. (((midr) & MIDR_VARIANT_MASK) >> MIDR_VARIANT_SHIFT)
  48. #define MIDR_IMPLEMENTOR_SHIFT 24
  49. #define MIDR_IMPLEMENTOR_MASK (0xff << MIDR_IMPLEMENTOR_SHIFT)
  50. #define MIDR_IMPLEMENTOR(midr) \
  51. (((midr) & MIDR_IMPLEMENTOR_MASK) >> MIDR_IMPLEMENTOR_SHIFT)
  52. #define MIDR_CPU_VAR_REV(var, rev) \
  53. (((var) << MIDR_VARIANT_SHIFT) | (rev))
  54. #define MIDR_CPU_PART_MASK \
  55. (MIDR_IMPLEMENTOR_MASK | \
  56. MIDR_ARCHITECTURE_MASK | \
  57. MIDR_PARTNUM_MASK)
  58. #define MIDR_CPU_PART(imp, partnum) \
  59. (((imp) << MIDR_IMPLEMENTOR_SHIFT) | \
  60. (0xf << MIDR_ARCHITECTURE_SHIFT) | \
  61. ((partnum) << MIDR_PARTNUM_SHIFT))
  62. #define ARM_CPU_IMP_ARM 0x41
  63. #define ARM_CPU_IMP_APM 0x50
  64. #define ARM_CPU_IMP_CAVIUM 0x43
  65. #define ARM_CPU_PART_AEM_V8 0xD0F
  66. #define ARM_CPU_PART_FOUNDATION 0xD00
  67. #define ARM_CPU_PART_CORTEX_A57 0xD07
  68. #define ARM_CPU_PART_CORTEX_A53 0xD03
  69. #define ARM_CPU_PART_CORTEX_A55 0xD05
  70. #define APM_CPU_PART_POTENZA 0x000
  71. #define CAVIUM_CPU_PART_THUNDERX 0x0A1
  72. #define MIDR_CORTEX_A55 MIDR_CPU_PART(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A55)
  73. #ifndef __ASSEMBLY__
  74. /*
  75. * The CPU ID never changes at run time, so we might as well tell the
  76. * compiler that it's constant. Use this function to read the CPU ID
  77. * rather than directly reading processor_id or read_cpuid() directly.
  78. */
  79. static inline u32 __attribute_const__ read_cpuid_id(void)
  80. {
  81. return read_cpuid(MIDR_EL1);
  82. }
  83. static inline u64 __attribute_const__ read_cpuid_mpidr(void)
  84. {
  85. return read_cpuid(MPIDR_EL1);
  86. }
  87. static inline unsigned int __attribute_const__ read_cpuid_implementor(void)
  88. {
  89. return MIDR_IMPLEMENTOR(read_cpuid_id());
  90. }
  91. static inline unsigned int __attribute_const__ read_cpuid_part_number(void)
  92. {
  93. return MIDR_PARTNUM(read_cpuid_id());
  94. }
  95. static inline u32 __attribute_const__ read_cpuid_cachetype(void)
  96. {
  97. return read_cpuid(CTR_EL0);
  98. }
  99. #endif /* __ASSEMBLY__ */
  100. #endif