162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Copyright (C) 2020-2022 Loongson Technology Corporation Limited 462306a36Sopenharmony_ci */ 562306a36Sopenharmony_ci#ifndef __ASM_CPU_INFO_H 662306a36Sopenharmony_ci#define __ASM_CPU_INFO_H 762306a36Sopenharmony_ci 862306a36Sopenharmony_ci#include <linux/cache.h> 962306a36Sopenharmony_ci#include <linux/types.h> 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ci#include <asm/loongarch.h> 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_ci/* cache_desc->flags */ 1462306a36Sopenharmony_cienum { 1562306a36Sopenharmony_ci CACHE_PRESENT = (1 << 0), 1662306a36Sopenharmony_ci CACHE_PRIVATE = (1 << 1), /* core private cache */ 1762306a36Sopenharmony_ci CACHE_INCLUSIVE = (1 << 2), /* include the inner level caches */ 1862306a36Sopenharmony_ci}; 1962306a36Sopenharmony_ci 2062306a36Sopenharmony_ci/* 2162306a36Sopenharmony_ci * Descriptor for a cache 2262306a36Sopenharmony_ci */ 2362306a36Sopenharmony_cistruct cache_desc { 2462306a36Sopenharmony_ci unsigned char type; 2562306a36Sopenharmony_ci unsigned char level; 2662306a36Sopenharmony_ci unsigned short sets; /* Number of lines per set */ 2762306a36Sopenharmony_ci unsigned char ways; /* Number of ways */ 2862306a36Sopenharmony_ci unsigned char linesz; /* Size of line in bytes */ 2962306a36Sopenharmony_ci unsigned char flags; /* Flags describing cache properties */ 3062306a36Sopenharmony_ci}; 3162306a36Sopenharmony_ci 3262306a36Sopenharmony_ci#define CACHE_LEVEL_MAX 3 3362306a36Sopenharmony_ci#define CACHE_LEAVES_MAX 6 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_cistruct cpuinfo_loongarch { 3662306a36Sopenharmony_ci u64 asid_cache; 3762306a36Sopenharmony_ci unsigned long asid_mask; 3862306a36Sopenharmony_ci 3962306a36Sopenharmony_ci /* 4062306a36Sopenharmony_ci * Capability and feature descriptor structure for LoongArch CPU 4162306a36Sopenharmony_ci */ 4262306a36Sopenharmony_ci unsigned long long options; 4362306a36Sopenharmony_ci unsigned int processor_id; 4462306a36Sopenharmony_ci unsigned int fpu_vers; 4562306a36Sopenharmony_ci unsigned int fpu_csr0; 4662306a36Sopenharmony_ci unsigned int fpu_mask; 4762306a36Sopenharmony_ci unsigned int cputype; 4862306a36Sopenharmony_ci int isa_level; 4962306a36Sopenharmony_ci int tlbsize; 5062306a36Sopenharmony_ci int tlbsizemtlb; 5162306a36Sopenharmony_ci int tlbsizestlbsets; 5262306a36Sopenharmony_ci int tlbsizestlbways; 5362306a36Sopenharmony_ci int cache_leaves_present; /* number of cache_leaves[] elements */ 5462306a36Sopenharmony_ci struct cache_desc cache_leaves[CACHE_LEAVES_MAX]; 5562306a36Sopenharmony_ci int core; /* physical core number in package */ 5662306a36Sopenharmony_ci int package;/* physical package number */ 5762306a36Sopenharmony_ci int global_id; /* physical global thread number */ 5862306a36Sopenharmony_ci int vabits; /* Virtual Address size in bits */ 5962306a36Sopenharmony_ci int pabits; /* Physical Address size in bits */ 6062306a36Sopenharmony_ci unsigned int ksave_mask; /* Usable KSave mask. */ 6162306a36Sopenharmony_ci unsigned int watch_dreg_count; /* Number data breakpoints */ 6262306a36Sopenharmony_ci unsigned int watch_ireg_count; /* Number instruction breakpoints */ 6362306a36Sopenharmony_ci unsigned int watch_reg_use_cnt; /* min(NUM_WATCH_REGS, watch_dreg_count + watch_ireg_count), Usable by ptrace */ 6462306a36Sopenharmony_ci} __aligned(SMP_CACHE_BYTES); 6562306a36Sopenharmony_ci 6662306a36Sopenharmony_ciextern struct cpuinfo_loongarch cpu_data[]; 6762306a36Sopenharmony_ci#define boot_cpu_data cpu_data[0] 6862306a36Sopenharmony_ci#define current_cpu_data cpu_data[smp_processor_id()] 6962306a36Sopenharmony_ci#define raw_current_cpu_data cpu_data[raw_smp_processor_id()] 7062306a36Sopenharmony_ci 7162306a36Sopenharmony_ciextern void cpu_probe(void); 7262306a36Sopenharmony_ci 7362306a36Sopenharmony_ciextern const char *__cpu_family[]; 7462306a36Sopenharmony_ciextern const char *__cpu_full_name[]; 7562306a36Sopenharmony_ci#define cpu_family_string() __cpu_family[raw_smp_processor_id()] 7662306a36Sopenharmony_ci#define cpu_full_name_string() __cpu_full_name[raw_smp_processor_id()] 7762306a36Sopenharmony_ci 7862306a36Sopenharmony_cistruct seq_file; 7962306a36Sopenharmony_cistruct notifier_block; 8062306a36Sopenharmony_ci 8162306a36Sopenharmony_ciextern int register_proc_cpuinfo_notifier(struct notifier_block *nb); 8262306a36Sopenharmony_ciextern int proc_cpuinfo_notifier_call_chain(unsigned long val, void *v); 8362306a36Sopenharmony_ci 8462306a36Sopenharmony_ci#define proc_cpuinfo_notifier(fn, pri) \ 8562306a36Sopenharmony_ci({ \ 8662306a36Sopenharmony_ci static struct notifier_block fn##_nb = { \ 8762306a36Sopenharmony_ci .notifier_call = fn, \ 8862306a36Sopenharmony_ci .priority = pri \ 8962306a36Sopenharmony_ci }; \ 9062306a36Sopenharmony_ci \ 9162306a36Sopenharmony_ci register_proc_cpuinfo_notifier(&fn##_nb); \ 9262306a36Sopenharmony_ci}) 9362306a36Sopenharmony_ci 9462306a36Sopenharmony_cistruct proc_cpuinfo_notifier_args { 9562306a36Sopenharmony_ci struct seq_file *m; 9662306a36Sopenharmony_ci unsigned long n; 9762306a36Sopenharmony_ci}; 9862306a36Sopenharmony_ci 9962306a36Sopenharmony_cistatic inline bool cpus_are_siblings(int cpua, int cpub) 10062306a36Sopenharmony_ci{ 10162306a36Sopenharmony_ci struct cpuinfo_loongarch *infoa = &cpu_data[cpua]; 10262306a36Sopenharmony_ci struct cpuinfo_loongarch *infob = &cpu_data[cpub]; 10362306a36Sopenharmony_ci 10462306a36Sopenharmony_ci if (infoa->package != infob->package) 10562306a36Sopenharmony_ci return false; 10662306a36Sopenharmony_ci 10762306a36Sopenharmony_ci if (infoa->core != infob->core) 10862306a36Sopenharmony_ci return false; 10962306a36Sopenharmony_ci 11062306a36Sopenharmony_ci return true; 11162306a36Sopenharmony_ci} 11262306a36Sopenharmony_ci 11362306a36Sopenharmony_cistatic inline unsigned long cpu_asid_mask(struct cpuinfo_loongarch *cpuinfo) 11462306a36Sopenharmony_ci{ 11562306a36Sopenharmony_ci return cpuinfo->asid_mask; 11662306a36Sopenharmony_ci} 11762306a36Sopenharmony_ci 11862306a36Sopenharmony_cistatic inline void set_cpu_asid_mask(struct cpuinfo_loongarch *cpuinfo, 11962306a36Sopenharmony_ci unsigned long asid_mask) 12062306a36Sopenharmony_ci{ 12162306a36Sopenharmony_ci cpuinfo->asid_mask = asid_mask; 12262306a36Sopenharmony_ci} 12362306a36Sopenharmony_ci 12462306a36Sopenharmony_ci#endif /* __ASM_CPU_INFO_H */ 125