cpu-info.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 1994 Waldorf GMBH
  7. * Copyright (C) 1995, 1996, 1997, 1998, 1999, 2001, 2002, 2003 Ralf Baechle
  8. * Copyright (C) 1996 Paul M. Antoine
  9. * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
  10. * Copyright (C) 2004 Maciej W. Rozycki
  11. */
  12. #ifndef __ASM_CPU_INFO_H
  13. #define __ASM_CPU_INFO_H
  14. #include <linux/cache.h>
  15. #include <linux/types.h>
  16. #include <asm/mipsregs.h>
  17. /*
  18. * Descriptor for a cache
  19. */
  20. struct cache_desc {
  21. unsigned int waysize; /* Bytes per way */
  22. unsigned short sets; /* Number of lines per set */
  23. unsigned char ways; /* Number of ways */
  24. unsigned char linesz; /* Size of line in bytes */
  25. unsigned char waybit; /* Bits to select in a cache set */
  26. unsigned char flags; /* Flags describing cache properties */
  27. };
  28. struct guest_info {
  29. unsigned long ases;
  30. unsigned long ases_dyn;
  31. unsigned long long options;
  32. unsigned long long options_dyn;
  33. int tlbsize;
  34. u8 conf;
  35. u8 kscratch_mask;
  36. };
  37. /*
  38. * Flag definitions
  39. */
  40. #define MIPS_CACHE_NOT_PRESENT 0x00000001
  41. #define MIPS_CACHE_VTAG 0x00000002 /* Virtually tagged cache */
  42. #define MIPS_CACHE_ALIASES 0x00000004 /* Cache could have aliases */
  43. #define MIPS_CACHE_IC_F_DC 0x00000008 /* Ic can refill from D-cache */
  44. #define MIPS_IC_SNOOPS_REMOTE 0x00000010 /* Ic snoops remote stores */
  45. #define MIPS_CACHE_PINDEX 0x00000020 /* Physically indexed cache */
  46. struct cpuinfo_mips {
  47. u64 asid_cache;
  48. #ifdef CONFIG_MIPS_ASID_BITS_VARIABLE
  49. unsigned long asid_mask;
  50. #endif
  51. /*
  52. * Capability and feature descriptor structure for MIPS CPU
  53. */
  54. unsigned long ases;
  55. unsigned long long options;
  56. unsigned int udelay_val;
  57. unsigned int processor_id;
  58. unsigned int fpu_id;
  59. unsigned int fpu_csr31;
  60. unsigned int fpu_msk31;
  61. unsigned int msa_id;
  62. unsigned int cputype;
  63. int isa_level;
  64. int tlbsize;
  65. int tlbsizevtlb;
  66. int tlbsizeftlbsets;
  67. int tlbsizeftlbways;
  68. struct cache_desc icache; /* Primary I-cache */
  69. struct cache_desc dcache; /* Primary D or combined I/D cache */
  70. struct cache_desc vcache; /* Victim cache, between pcache and scache */
  71. struct cache_desc scache; /* Secondary cache */
  72. struct cache_desc tcache; /* Tertiary/split secondary cache */
  73. int srsets; /* Shadow register sets */
  74. int package;/* physical package number */
  75. unsigned int globalnumber;
  76. #ifdef CONFIG_64BIT
  77. int vmbits; /* Virtual memory size in bits */
  78. #endif
  79. void *data; /* Additional data */
  80. unsigned int watch_reg_count; /* Number that exist */
  81. unsigned int watch_reg_use_cnt; /* Usable by ptrace */
  82. #define NUM_WATCH_REGS 4
  83. u16 watch_reg_masks[NUM_WATCH_REGS];
  84. unsigned int kscratch_mask; /* Usable KScratch mask. */
  85. /*
  86. * Cache Coherency attribute for write-combine memory writes.
  87. * (shifted by _CACHE_SHIFT)
  88. */
  89. unsigned int writecombine;
  90. /*
  91. * Simple counter to prevent enabling HTW in nested
  92. * htw_start/htw_stop calls
  93. */
  94. unsigned int htw_seq;
  95. /* VZ & Guest features */
  96. struct guest_info guest;
  97. unsigned int gtoffset_mask;
  98. unsigned int guestid_mask;
  99. unsigned int guestid_cache;
  100. } __attribute__((aligned(SMP_CACHE_BYTES)));
  101. extern struct cpuinfo_mips cpu_data[];
  102. #define current_cpu_data cpu_data[smp_processor_id()]
  103. #define raw_current_cpu_data cpu_data[raw_smp_processor_id()]
  104. #define boot_cpu_data cpu_data[0]
  105. extern void cpu_probe(void);
  106. extern void cpu_report(void);
  107. extern const char *__cpu_name[];
  108. #define cpu_name_string() __cpu_name[raw_smp_processor_id()]
  109. struct seq_file;
  110. struct notifier_block;
  111. extern int register_proc_cpuinfo_notifier(struct notifier_block *nb);
  112. extern int proc_cpuinfo_notifier_call_chain(unsigned long val, void *v);
  113. #define proc_cpuinfo_notifier(fn, pri) \
  114. ({ \
  115. static struct notifier_block fn##_nb = { \
  116. .notifier_call = fn, \
  117. .priority = pri \
  118. }; \
  119. \
  120. register_proc_cpuinfo_notifier(&fn##_nb); \
  121. })
  122. struct proc_cpuinfo_notifier_args {
  123. struct seq_file *m;
  124. unsigned long n;
  125. };
  126. static inline unsigned int cpu_cluster(struct cpuinfo_mips *cpuinfo)
  127. {
  128. /* Optimisation for systems where multiple clusters aren't used */
  129. if (!IS_ENABLED(CONFIG_CPU_MIPSR6))
  130. return 0;
  131. return (cpuinfo->globalnumber & MIPS_GLOBALNUMBER_CLUSTER) >>
  132. MIPS_GLOBALNUMBER_CLUSTER_SHF;
  133. }
  134. static inline unsigned int cpu_core(struct cpuinfo_mips *cpuinfo)
  135. {
  136. return (cpuinfo->globalnumber & MIPS_GLOBALNUMBER_CORE) >>
  137. MIPS_GLOBALNUMBER_CORE_SHF;
  138. }
  139. static inline unsigned int cpu_vpe_id(struct cpuinfo_mips *cpuinfo)
  140. {
  141. /* Optimisation for systems where VP(E)s aren't used */
  142. if (!IS_ENABLED(CONFIG_MIPS_MT_SMP) && !IS_ENABLED(CONFIG_CPU_MIPSR6))
  143. return 0;
  144. return (cpuinfo->globalnumber & MIPS_GLOBALNUMBER_VP) >>
  145. MIPS_GLOBALNUMBER_VP_SHF;
  146. }
  147. extern void cpu_set_cluster(struct cpuinfo_mips *cpuinfo, unsigned int cluster);
  148. extern void cpu_set_core(struct cpuinfo_mips *cpuinfo, unsigned int core);
  149. extern void cpu_set_vpe_id(struct cpuinfo_mips *cpuinfo, unsigned int vpe);
  150. static inline bool cpus_are_siblings(int cpua, int cpub)
  151. {
  152. struct cpuinfo_mips *infoa = &cpu_data[cpua];
  153. struct cpuinfo_mips *infob = &cpu_data[cpub];
  154. unsigned int gnuma, gnumb;
  155. if (infoa->package != infob->package)
  156. return false;
  157. gnuma = infoa->globalnumber & ~MIPS_GLOBALNUMBER_VP;
  158. gnumb = infob->globalnumber & ~MIPS_GLOBALNUMBER_VP;
  159. if (gnuma != gnumb)
  160. return false;
  161. return true;
  162. }
  163. static inline unsigned long cpu_asid_inc(void)
  164. {
  165. return 1 << CONFIG_MIPS_ASID_SHIFT;
  166. }
  167. static inline unsigned long cpu_asid_mask(struct cpuinfo_mips *cpuinfo)
  168. {
  169. #ifdef CONFIG_MIPS_ASID_BITS_VARIABLE
  170. return cpuinfo->asid_mask;
  171. #endif
  172. return ((1 << CONFIG_MIPS_ASID_BITS) - 1) << CONFIG_MIPS_ASID_SHIFT;
  173. }
  174. static inline void set_cpu_asid_mask(struct cpuinfo_mips *cpuinfo,
  175. unsigned long asid_mask)
  176. {
  177. #ifdef CONFIG_MIPS_ASID_BITS_VARIABLE
  178. cpuinfo->asid_mask = asid_mask;
  179. #endif
  180. }
  181. #endif /* __ASM_CPU_INFO_H */