zhaoxin.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. }
  57. static void init_zhaoxin(struct cpuinfo_x86 *c)
  58. {
  59. early_init_zhaoxin(c);
  60. init_intel_cacheinfo(c);
  61. if (c->cpuid_level > 9) {
  62. unsigned int eax = cpuid_eax(10);
  63. /*
  64. * Check for version and the number of counters
  65. * Version(eax[7:0]) can't be 0;
  66. * Counters(eax[15:8]) should be greater than 1;
  67. */
  68. if ((eax & 0xff) && (((eax >> 8) & 0xff) > 1))
  69. set_cpu_cap(c, X86_FEATURE_ARCH_PERFMON);
  70. }
  71. if (c->x86 >= 0x6)
  72. init_zhaoxin_cap(c);
  73. #ifdef CONFIG_X86_64
  74. set_cpu_cap(c, X86_FEATURE_LFENCE_RDTSC);
  75. #endif
  76. init_ia32_feat_ctl(c);
  77. }
  78. #ifdef CONFIG_X86_32
  79. static unsigned int
  80. zhaoxin_size_cache(struct cpuinfo_x86 *c, unsigned int size)
  81. {
  82. return size;
  83. }
  84. #endif
  85. static const struct cpu_dev zhaoxin_cpu_dev = {
  86. .c_vendor = "zhaoxin",
  87. .c_ident = { " Shanghai " },
  88. .c_early_init = early_init_zhaoxin,
  89. .c_init = init_zhaoxin,
  90. #ifdef CONFIG_X86_32
  91. .legacy_cache_size = zhaoxin_size_cache,
  92. #endif
  93. .c_x86_vendor = X86_VENDOR_ZHAOXIN,
  94. };
  95. cpu_dev_register(zhaoxin_cpu_dev);