cpu-info.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
  4. */
  5. #ifndef __ASM_CPU_INFO_H
  6. #define __ASM_CPU_INFO_H
  7. #include <linux/cache.h>
  8. #include <linux/types.h>
  9. #include <asm/loongarch.h>
  10. /* cache_desc->flags */
  11. enum {
  12. CACHE_PRESENT = (1 << 0),
  13. CACHE_PRIVATE = (1 << 1), /* core private cache */
  14. CACHE_INCLUSIVE = (1 << 2), /* include the inner level caches */
  15. };
  16. /*
  17. * Descriptor for a cache
  18. */
  19. struct cache_desc {
  20. unsigned char type;
  21. unsigned char level;
  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 flags; /* Flags describing cache properties */
  26. };
  27. #define CACHE_LEVEL_MAX 3
  28. #define CACHE_LEAVES_MAX 6
  29. struct cpuinfo_loongarch {
  30. u64 asid_cache;
  31. unsigned long asid_mask;
  32. /*
  33. * Capability and feature descriptor structure for LoongArch CPU
  34. */
  35. unsigned long long options;
  36. unsigned int processor_id;
  37. unsigned int fpu_vers;
  38. unsigned int fpu_csr0;
  39. unsigned int fpu_mask;
  40. unsigned int cputype;
  41. int isa_level;
  42. int tlbsize;
  43. int tlbsizemtlb;
  44. int tlbsizestlbsets;
  45. int tlbsizestlbways;
  46. int cache_leaves_present; /* number of cache_leaves[] elements */
  47. struct cache_desc cache_leaves[CACHE_LEAVES_MAX];
  48. int core; /* physical core number in package */
  49. int package;/* physical package number */
  50. int vabits; /* Virtual Address size in bits */
  51. int pabits; /* Physical Address size in bits */
  52. unsigned int ksave_mask; /* Usable KSave mask. */
  53. unsigned int watch_dreg_count; /* Number data breakpoints */
  54. unsigned int watch_ireg_count; /* Number instruction breakpoints */
  55. unsigned int watch_reg_use_cnt; /* min(NUM_WATCH_REGS, watch_dreg_count + watch_ireg_count), Usable by ptrace */
  56. } __aligned(SMP_CACHE_BYTES);
  57. extern struct cpuinfo_loongarch cpu_data[];
  58. #define boot_cpu_data cpu_data[0]
  59. #define current_cpu_data cpu_data[smp_processor_id()]
  60. #define raw_current_cpu_data cpu_data[raw_smp_processor_id()]
  61. extern void cpu_probe(void);
  62. extern const char *__cpu_family[];
  63. extern const char *__cpu_full_name[];
  64. #define cpu_family_string() __cpu_family[raw_smp_processor_id()]
  65. #define cpu_full_name_string() __cpu_full_name[raw_smp_processor_id()]
  66. struct seq_file;
  67. struct notifier_block;
  68. extern int register_proc_cpuinfo_notifier(struct notifier_block *nb);
  69. extern int proc_cpuinfo_notifier_call_chain(unsigned long val, void *v);
  70. #define proc_cpuinfo_notifier(fn, pri) \
  71. ({ \
  72. static struct notifier_block fn##_nb = { \
  73. .notifier_call = fn, \
  74. .priority = pri \
  75. }; \
  76. \
  77. register_proc_cpuinfo_notifier(&fn##_nb); \
  78. })
  79. struct proc_cpuinfo_notifier_args {
  80. struct seq_file *m;
  81. unsigned long n;
  82. };
  83. static inline bool cpus_are_siblings(int cpua, int cpub)
  84. {
  85. struct cpuinfo_loongarch *infoa = &cpu_data[cpua];
  86. struct cpuinfo_loongarch *infob = &cpu_data[cpub];
  87. if (infoa->package != infob->package)
  88. return false;
  89. if (infoa->core != infob->core)
  90. return false;
  91. return true;
  92. }
  93. static inline unsigned long cpu_asid_mask(struct cpuinfo_loongarch *cpuinfo)
  94. {
  95. return cpuinfo->asid_mask;
  96. }
  97. static inline void set_cpu_asid_mask(struct cpuinfo_loongarch *cpuinfo,
  98. unsigned long asid_mask)
  99. {
  100. cpuinfo->asid_mask = asid_mask;
  101. }
  102. #endif /* __ASM_CPU_INFO_H */