cpu-r3k-probe.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Processor capabilities determination functions.
  4. *
  5. * Copyright (C) xxxx the Anonymous
  6. * Copyright (C) 1994 - 2006 Ralf Baechle
  7. * Copyright (C) 2003, 2004 Maciej W. Rozycki
  8. * Copyright (C) 2001, 2004, 2011, 2012 MIPS Technologies, Inc.
  9. */
  10. #include <linux/init.h>
  11. #include <linux/kernel.h>
  12. #include <linux/ptrace.h>
  13. #include <linux/smp.h>
  14. #include <linux/stddef.h>
  15. #include <linux/export.h>
  16. #include <asm/bugs.h>
  17. #include <asm/cpu.h>
  18. #include <asm/cpu-features.h>
  19. #include <asm/cpu-type.h>
  20. #include <asm/fpu.h>
  21. #include <asm/mipsregs.h>
  22. #include <asm/elf.h>
  23. #include <asm/traps.h>
  24. #include "fpu-probe.h"
  25. /* Hardware capabilities */
  26. unsigned int elf_hwcap __read_mostly;
  27. EXPORT_SYMBOL_GPL(elf_hwcap);
  28. void __init check_bugs32(void)
  29. {
  30. }
  31. /*
  32. * Probe whether cpu has config register by trying to play with
  33. * alternate cache bit and see whether it matters.
  34. * It's used by cpu_probe to distinguish between R3000A and R3081.
  35. */
  36. static inline int cpu_has_confreg(void)
  37. {
  38. #ifdef CONFIG_CPU_R3000
  39. unsigned long size1, size2;
  40. unsigned long cfg = read_c0_conf();
  41. size1 = r3k_cache_size(ST0_ISC);
  42. write_c0_conf(cfg ^ R30XX_CONF_AC);
  43. size2 = r3k_cache_size(ST0_ISC);
  44. write_c0_conf(cfg);
  45. return size1 != size2;
  46. #else
  47. return 0;
  48. #endif
  49. }
  50. static inline void set_elf_platform(int cpu, const char *plat)
  51. {
  52. if (cpu == 0)
  53. __elf_platform = plat;
  54. }
  55. const char *__cpu_name[NR_CPUS];
  56. const char *__elf_platform;
  57. const char *__elf_base_platform;
  58. void cpu_probe(void)
  59. {
  60. struct cpuinfo_mips *c = &current_cpu_data;
  61. unsigned int cpu = smp_processor_id();
  62. /*
  63. * Set a default elf platform, cpu probe may later
  64. * overwrite it with a more precise value
  65. */
  66. set_elf_platform(cpu, "mips");
  67. c->processor_id = PRID_IMP_UNKNOWN;
  68. c->fpu_id = FPIR_IMP_NONE;
  69. c->cputype = CPU_UNKNOWN;
  70. c->writecombine = _CACHE_UNCACHED;
  71. c->fpu_csr31 = FPU_CSR_RN;
  72. c->fpu_msk31 = FPU_CSR_RSVD | FPU_CSR_ABS2008 | FPU_CSR_NAN2008 |
  73. FPU_CSR_CONDX | FPU_CSR_FS;
  74. c->srsets = 1;
  75. c->processor_id = read_c0_prid();
  76. switch (c->processor_id & (PRID_COMP_MASK | PRID_IMP_MASK)) {
  77. case PRID_COMP_LEGACY | PRID_IMP_R2000:
  78. c->cputype = CPU_R2000;
  79. __cpu_name[cpu] = "R2000";
  80. c->options = MIPS_CPU_TLB | MIPS_CPU_3K_CACHE |
  81. MIPS_CPU_NOFPUEX;
  82. if (__cpu_has_fpu())
  83. c->options |= MIPS_CPU_FPU;
  84. c->tlbsize = 64;
  85. break;
  86. case PRID_COMP_LEGACY | PRID_IMP_R3000:
  87. if ((c->processor_id & PRID_REV_MASK) == PRID_REV_R3000A) {
  88. if (cpu_has_confreg()) {
  89. c->cputype = CPU_R3081E;
  90. __cpu_name[cpu] = "R3081";
  91. } else {
  92. c->cputype = CPU_R3000A;
  93. __cpu_name[cpu] = "R3000A";
  94. }
  95. } else {
  96. c->cputype = CPU_R3000;
  97. __cpu_name[cpu] = "R3000";
  98. }
  99. c->options = MIPS_CPU_TLB | MIPS_CPU_3K_CACHE |
  100. MIPS_CPU_NOFPUEX;
  101. if (__cpu_has_fpu())
  102. c->options |= MIPS_CPU_FPU;
  103. c->tlbsize = 64;
  104. break;
  105. }
  106. BUG_ON(!__cpu_name[cpu]);
  107. BUG_ON(c->cputype == CPU_UNKNOWN);
  108. /*
  109. * Platform code can force the cpu type to optimize code
  110. * generation. In that case be sure the cpu type is correctly
  111. * manually setup otherwise it could trigger some nasty bugs.
  112. */
  113. BUG_ON(current_cpu_type() != c->cputype);
  114. if (mips_fpu_disabled)
  115. c->options &= ~MIPS_CPU_FPU;
  116. if (c->options & MIPS_CPU_FPU)
  117. cpu_set_fpu_opts(c);
  118. else
  119. cpu_set_nofpu_opts(c);
  120. reserve_exception_space(0, 0x400);
  121. }
  122. void cpu_report(void)
  123. {
  124. struct cpuinfo_mips *c = &current_cpu_data;
  125. pr_info("CPU%d revision is: %08x (%s)\n",
  126. smp_processor_id(), c->processor_id, cpu_name_string());
  127. if (c->options & MIPS_CPU_FPU)
  128. pr_info("FPU revision is: %08x\n", c->fpu_id);
  129. }