zhaoxin.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <linux/sched.h>
  3. #include <linux/sched/clock.h>
  4. #include <asm/cpu.h>
  5. #include <asm/cpufeature.h>
  6. #include "cpu.h"
  7. #define MSR_ZHAOXIN_FCR57 0x00001257
  8. #define ACE_PRESENT (1 << 6)
  9. #define ACE_ENABLED (1 << 7)
  10. #define ACE_FCR (1 << 7) /* MSR_ZHAOXIN_FCR */
  11. #define RNG_PRESENT (1 << 2)
  12. #define RNG_ENABLED (1 << 3)
  13. #define RNG_ENABLE (1 << 8) /* MSR_ZHAOXIN_RNG */
  14. static void init_zhaoxin_cap(struct cpuinfo_x86 *c)
  15. {
  16. u32 lo, hi;
  17. /* Test for Extended Feature Flags presence */
  18. if (cpuid_eax(0xC0000000) >= 0xC0000001) {
  19. u32 tmp = cpuid_edx(0xC0000001);
  20. /* Enable ACE unit, if present and disabled */
  21. if ((tmp & (ACE_PRESENT | ACE_ENABLED)) == ACE_PRESENT) {
  22. rdmsr(MSR_ZHAOXIN_FCR57, lo, hi);
  23. /* Enable ACE unit */
  24. lo |= ACE_FCR;
  25. wrmsr(MSR_ZHAOXIN_FCR57, lo, hi);
  26. pr_info("CPU: Enabled ACE h/w crypto\n");
  27. }
  28. /* Enable RNG unit, if present and disabled */
  29. if ((tmp & (RNG_PRESENT | RNG_ENABLED)) == RNG_PRESENT) {
  30. rdmsr(MSR_ZHAOXIN_FCR57, lo, hi);
  31. /* Enable RNG unit */
  32. lo |= RNG_ENABLE;
  33. wrmsr(MSR_ZHAOXIN_FCR57, lo, hi);
  34. pr_info("CPU: Enabled h/w RNG\n");
  35. }
  36. /*
  37. * Store Extended Feature Flags as word 5 of the CPU
  38. * capability bit array
  39. */
  40. c->x86_capability[CPUID_C000_0001_EDX] = cpuid_edx(0xC0000001);
  41. }
  42. if (c->x86 >= 0x6)
  43. set_cpu_cap(c, X86_FEATURE_REP_GOOD);
  44. }
  45. static void early_init_zhaoxin(struct cpuinfo_x86 *c)
  46. {
  47. if (c->x86 >= 0x6)
  48. set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
  49. #ifdef CONFIG_X86_64
  50. set_cpu_cap(c, X86_FEATURE_SYSENTER32);
  51. #endif
  52. if (c->x86_power & (1 << 8)) {
  53. set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
  54. set_cpu_cap(c, X86_FEATURE_NONSTOP_TSC);
  55. }
  56. if (c->cpuid_level >= 0x00000001) {
  57. u32 eax, ebx, ecx, edx;
  58. cpuid(0x00000001, &eax, &ebx, &ecx, &edx);
  59. /*
  60. * If HTT (EDX[28]) is set EBX[16:23] contain the number of
  61. * apicids which are reserved per package. Store the resulting
  62. * shift value for the package management code.
  63. */
  64. if (edx & (1U << 28))
  65. c->x86_coreid_bits = get_count_order((ebx >> 16) & 0xff);
  66. }
  67. }
  68. static void init_zhaoxin(struct cpuinfo_x86 *c)
  69. {
  70. early_init_zhaoxin(c);
  71. init_intel_cacheinfo(c);
  72. detect_num_cpu_cores(c);
  73. #ifdef CONFIG_X86_32
  74. detect_ht(c);
  75. #endif
  76. if (c->cpuid_level > 9) {
  77. unsigned int eax = cpuid_eax(10);
  78. /*
  79. * Check for version and the number of counters
  80. * Version(eax[7:0]) can't be 0;
  81. * Counters(eax[15:8]) should be greater than 1;
  82. */
  83. if ((eax & 0xff) && (((eax >> 8) & 0xff) > 1))
  84. set_cpu_cap(c, X86_FEATURE_ARCH_PERFMON);
  85. }
  86. if (c->x86 >= 0x6)
  87. init_zhaoxin_cap(c);
  88. #ifdef CONFIG_X86_64
  89. set_cpu_cap(c, X86_FEATURE_LFENCE_RDTSC);
  90. #endif
  91. init_ia32_feat_ctl(c);
  92. }
  93. #ifdef CONFIG_X86_32
  94. static unsigned int
  95. zhaoxin_size_cache(struct cpuinfo_x86 *c, unsigned int size)
  96. {
  97. return size;
  98. }
  99. #endif
  100. static const struct cpu_dev zhaoxin_cpu_dev = {
  101. .c_vendor = "zhaoxin",
  102. .c_ident = { " Shanghai " },
  103. .c_early_init = early_init_zhaoxin,
  104. .c_init = init_zhaoxin,
  105. #ifdef CONFIG_X86_32
  106. .legacy_cache_size = zhaoxin_size_cache,
  107. #endif
  108. .c_x86_vendor = X86_VENDOR_ZHAOXIN,
  109. };
  110. cpu_dev_register(zhaoxin_cpu_dev);