18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * This file is subject to the terms and conditions of the GNU General Public 38c2ecf20Sopenharmony_ci * License. See the file "COPYING" in the main directory of this archive 48c2ecf20Sopenharmony_ci * for more details. 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * Copyright (C) 1994 Waldorf GMBH 78c2ecf20Sopenharmony_ci * Copyright (C) 1995, 1996, 1997, 1998, 1999, 2001, 2002, 2003 Ralf Baechle 88c2ecf20Sopenharmony_ci * Copyright (C) 1996 Paul M. Antoine 98c2ecf20Sopenharmony_ci * Copyright (C) 1999, 2000 Silicon Graphics, Inc. 108c2ecf20Sopenharmony_ci * Copyright (C) 2004 Maciej W. Rozycki 118c2ecf20Sopenharmony_ci */ 128c2ecf20Sopenharmony_ci#ifndef __ASM_CPU_INFO_H 138c2ecf20Sopenharmony_ci#define __ASM_CPU_INFO_H 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#include <linux/cache.h> 168c2ecf20Sopenharmony_ci#include <linux/types.h> 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci#include <asm/mipsregs.h> 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci/* 218c2ecf20Sopenharmony_ci * Descriptor for a cache 228c2ecf20Sopenharmony_ci */ 238c2ecf20Sopenharmony_cistruct cache_desc { 248c2ecf20Sopenharmony_ci unsigned int waysize; /* Bytes per way */ 258c2ecf20Sopenharmony_ci unsigned short sets; /* Number of lines per set */ 268c2ecf20Sopenharmony_ci unsigned char ways; /* Number of ways */ 278c2ecf20Sopenharmony_ci unsigned char linesz; /* Size of line in bytes */ 288c2ecf20Sopenharmony_ci unsigned char waybit; /* Bits to select in a cache set */ 298c2ecf20Sopenharmony_ci unsigned char flags; /* Flags describing cache properties */ 308c2ecf20Sopenharmony_ci}; 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_cistruct guest_info { 338c2ecf20Sopenharmony_ci unsigned long ases; 348c2ecf20Sopenharmony_ci unsigned long ases_dyn; 358c2ecf20Sopenharmony_ci unsigned long long options; 368c2ecf20Sopenharmony_ci unsigned long long options_dyn; 378c2ecf20Sopenharmony_ci int tlbsize; 388c2ecf20Sopenharmony_ci u8 conf; 398c2ecf20Sopenharmony_ci u8 kscratch_mask; 408c2ecf20Sopenharmony_ci}; 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci/* 438c2ecf20Sopenharmony_ci * Flag definitions 448c2ecf20Sopenharmony_ci */ 458c2ecf20Sopenharmony_ci#define MIPS_CACHE_NOT_PRESENT 0x00000001 468c2ecf20Sopenharmony_ci#define MIPS_CACHE_VTAG 0x00000002 /* Virtually tagged cache */ 478c2ecf20Sopenharmony_ci#define MIPS_CACHE_ALIASES 0x00000004 /* Cache could have aliases */ 488c2ecf20Sopenharmony_ci#define MIPS_CACHE_IC_F_DC 0x00000008 /* Ic can refill from D-cache */ 498c2ecf20Sopenharmony_ci#define MIPS_IC_SNOOPS_REMOTE 0x00000010 /* Ic snoops remote stores */ 508c2ecf20Sopenharmony_ci#define MIPS_CACHE_PINDEX 0x00000020 /* Physically indexed cache */ 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_cistruct cpuinfo_mips { 538c2ecf20Sopenharmony_ci u64 asid_cache; 548c2ecf20Sopenharmony_ci#ifdef CONFIG_MIPS_ASID_BITS_VARIABLE 558c2ecf20Sopenharmony_ci unsigned long asid_mask; 568c2ecf20Sopenharmony_ci#endif 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ci /* 598c2ecf20Sopenharmony_ci * Capability and feature descriptor structure for MIPS CPU 608c2ecf20Sopenharmony_ci */ 618c2ecf20Sopenharmony_ci unsigned long ases; 628c2ecf20Sopenharmony_ci unsigned long long options; 638c2ecf20Sopenharmony_ci unsigned int udelay_val; 648c2ecf20Sopenharmony_ci unsigned int processor_id; 658c2ecf20Sopenharmony_ci unsigned int fpu_id; 668c2ecf20Sopenharmony_ci unsigned int fpu_csr31; 678c2ecf20Sopenharmony_ci unsigned int fpu_msk31; 688c2ecf20Sopenharmony_ci unsigned int msa_id; 698c2ecf20Sopenharmony_ci unsigned int cputype; 708c2ecf20Sopenharmony_ci int isa_level; 718c2ecf20Sopenharmony_ci int tlbsize; 728c2ecf20Sopenharmony_ci int tlbsizevtlb; 738c2ecf20Sopenharmony_ci int tlbsizeftlbsets; 748c2ecf20Sopenharmony_ci int tlbsizeftlbways; 758c2ecf20Sopenharmony_ci struct cache_desc icache; /* Primary I-cache */ 768c2ecf20Sopenharmony_ci struct cache_desc dcache; /* Primary D or combined I/D cache */ 778c2ecf20Sopenharmony_ci struct cache_desc vcache; /* Victim cache, between pcache and scache */ 788c2ecf20Sopenharmony_ci struct cache_desc scache; /* Secondary cache */ 798c2ecf20Sopenharmony_ci struct cache_desc tcache; /* Tertiary/split secondary cache */ 808c2ecf20Sopenharmony_ci int srsets; /* Shadow register sets */ 818c2ecf20Sopenharmony_ci int package;/* physical package number */ 828c2ecf20Sopenharmony_ci unsigned int globalnumber; 838c2ecf20Sopenharmony_ci#ifdef CONFIG_64BIT 848c2ecf20Sopenharmony_ci int vmbits; /* Virtual memory size in bits */ 858c2ecf20Sopenharmony_ci#endif 868c2ecf20Sopenharmony_ci void *data; /* Additional data */ 878c2ecf20Sopenharmony_ci unsigned int watch_reg_count; /* Number that exist */ 888c2ecf20Sopenharmony_ci unsigned int watch_reg_use_cnt; /* Usable by ptrace */ 898c2ecf20Sopenharmony_ci#define NUM_WATCH_REGS 4 908c2ecf20Sopenharmony_ci u16 watch_reg_masks[NUM_WATCH_REGS]; 918c2ecf20Sopenharmony_ci unsigned int kscratch_mask; /* Usable KScratch mask. */ 928c2ecf20Sopenharmony_ci /* 938c2ecf20Sopenharmony_ci * Cache Coherency attribute for write-combine memory writes. 948c2ecf20Sopenharmony_ci * (shifted by _CACHE_SHIFT) 958c2ecf20Sopenharmony_ci */ 968c2ecf20Sopenharmony_ci unsigned int writecombine; 978c2ecf20Sopenharmony_ci /* 988c2ecf20Sopenharmony_ci * Simple counter to prevent enabling HTW in nested 998c2ecf20Sopenharmony_ci * htw_start/htw_stop calls 1008c2ecf20Sopenharmony_ci */ 1018c2ecf20Sopenharmony_ci unsigned int htw_seq; 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_ci /* VZ & Guest features */ 1048c2ecf20Sopenharmony_ci struct guest_info guest; 1058c2ecf20Sopenharmony_ci unsigned int gtoffset_mask; 1068c2ecf20Sopenharmony_ci unsigned int guestid_mask; 1078c2ecf20Sopenharmony_ci unsigned int guestid_cache; 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_ci#ifdef CONFIG_CPU_LOONGSON3_CPUCFG_EMULATION 1108c2ecf20Sopenharmony_ci /* CPUCFG data for this CPU, synthesized at probe time. 1118c2ecf20Sopenharmony_ci * 1128c2ecf20Sopenharmony_ci * CPUCFG select 0 is PRId, 4 and above are unimplemented for now. 1138c2ecf20Sopenharmony_ci * So the only stored values are for CPUCFG selects 1-3 inclusive. 1148c2ecf20Sopenharmony_ci */ 1158c2ecf20Sopenharmony_ci u32 loongson3_cpucfg_data[3]; 1168c2ecf20Sopenharmony_ci#endif 1178c2ecf20Sopenharmony_ci} __attribute__((aligned(SMP_CACHE_BYTES))); 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_ciextern struct cpuinfo_mips cpu_data[]; 1208c2ecf20Sopenharmony_ci#define current_cpu_data cpu_data[smp_processor_id()] 1218c2ecf20Sopenharmony_ci#define raw_current_cpu_data cpu_data[raw_smp_processor_id()] 1228c2ecf20Sopenharmony_ci#define boot_cpu_data cpu_data[0] 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_ciextern void cpu_probe(void); 1258c2ecf20Sopenharmony_ciextern void cpu_report(void); 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ciextern const char *__cpu_name[]; 1288c2ecf20Sopenharmony_ci#define cpu_name_string() __cpu_name[raw_smp_processor_id()] 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_cistruct seq_file; 1318c2ecf20Sopenharmony_cistruct notifier_block; 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ciextern int register_proc_cpuinfo_notifier(struct notifier_block *nb); 1348c2ecf20Sopenharmony_ciextern int proc_cpuinfo_notifier_call_chain(unsigned long val, void *v); 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ci#define proc_cpuinfo_notifier(fn, pri) \ 1378c2ecf20Sopenharmony_ci({ \ 1388c2ecf20Sopenharmony_ci static struct notifier_block fn##_nb = { \ 1398c2ecf20Sopenharmony_ci .notifier_call = fn, \ 1408c2ecf20Sopenharmony_ci .priority = pri \ 1418c2ecf20Sopenharmony_ci }; \ 1428c2ecf20Sopenharmony_ci \ 1438c2ecf20Sopenharmony_ci register_proc_cpuinfo_notifier(&fn##_nb); \ 1448c2ecf20Sopenharmony_ci}) 1458c2ecf20Sopenharmony_ci 1468c2ecf20Sopenharmony_cistruct proc_cpuinfo_notifier_args { 1478c2ecf20Sopenharmony_ci struct seq_file *m; 1488c2ecf20Sopenharmony_ci unsigned long n; 1498c2ecf20Sopenharmony_ci}; 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_cistatic inline unsigned int cpu_cluster(struct cpuinfo_mips *cpuinfo) 1528c2ecf20Sopenharmony_ci{ 1538c2ecf20Sopenharmony_ci /* Optimisation for systems where multiple clusters aren't used */ 1548c2ecf20Sopenharmony_ci if (!IS_ENABLED(CONFIG_CPU_MIPSR5) && !IS_ENABLED(CONFIG_CPU_MIPSR6)) 1558c2ecf20Sopenharmony_ci return 0; 1568c2ecf20Sopenharmony_ci 1578c2ecf20Sopenharmony_ci return (cpuinfo->globalnumber & MIPS_GLOBALNUMBER_CLUSTER) >> 1588c2ecf20Sopenharmony_ci MIPS_GLOBALNUMBER_CLUSTER_SHF; 1598c2ecf20Sopenharmony_ci} 1608c2ecf20Sopenharmony_ci 1618c2ecf20Sopenharmony_cistatic inline unsigned int cpu_core(struct cpuinfo_mips *cpuinfo) 1628c2ecf20Sopenharmony_ci{ 1638c2ecf20Sopenharmony_ci return (cpuinfo->globalnumber & MIPS_GLOBALNUMBER_CORE) >> 1648c2ecf20Sopenharmony_ci MIPS_GLOBALNUMBER_CORE_SHF; 1658c2ecf20Sopenharmony_ci} 1668c2ecf20Sopenharmony_ci 1678c2ecf20Sopenharmony_cistatic inline unsigned int cpu_vpe_id(struct cpuinfo_mips *cpuinfo) 1688c2ecf20Sopenharmony_ci{ 1698c2ecf20Sopenharmony_ci /* Optimisation for systems where VP(E)s aren't used */ 1708c2ecf20Sopenharmony_ci if (!IS_ENABLED(CONFIG_MIPS_MT_SMP) && !IS_ENABLED(CONFIG_CPU_MIPSR6)) 1718c2ecf20Sopenharmony_ci return 0; 1728c2ecf20Sopenharmony_ci 1738c2ecf20Sopenharmony_ci return (cpuinfo->globalnumber & MIPS_GLOBALNUMBER_VP) >> 1748c2ecf20Sopenharmony_ci MIPS_GLOBALNUMBER_VP_SHF; 1758c2ecf20Sopenharmony_ci} 1768c2ecf20Sopenharmony_ci 1778c2ecf20Sopenharmony_ciextern void cpu_set_cluster(struct cpuinfo_mips *cpuinfo, unsigned int cluster); 1788c2ecf20Sopenharmony_ciextern void cpu_set_core(struct cpuinfo_mips *cpuinfo, unsigned int core); 1798c2ecf20Sopenharmony_ciextern void cpu_set_vpe_id(struct cpuinfo_mips *cpuinfo, unsigned int vpe); 1808c2ecf20Sopenharmony_ci 1818c2ecf20Sopenharmony_cistatic inline bool cpus_are_siblings(int cpua, int cpub) 1828c2ecf20Sopenharmony_ci{ 1838c2ecf20Sopenharmony_ci struct cpuinfo_mips *infoa = &cpu_data[cpua]; 1848c2ecf20Sopenharmony_ci struct cpuinfo_mips *infob = &cpu_data[cpub]; 1858c2ecf20Sopenharmony_ci unsigned int gnuma, gnumb; 1868c2ecf20Sopenharmony_ci 1878c2ecf20Sopenharmony_ci if (infoa->package != infob->package) 1888c2ecf20Sopenharmony_ci return false; 1898c2ecf20Sopenharmony_ci 1908c2ecf20Sopenharmony_ci gnuma = infoa->globalnumber & ~MIPS_GLOBALNUMBER_VP; 1918c2ecf20Sopenharmony_ci gnumb = infob->globalnumber & ~MIPS_GLOBALNUMBER_VP; 1928c2ecf20Sopenharmony_ci if (gnuma != gnumb) 1938c2ecf20Sopenharmony_ci return false; 1948c2ecf20Sopenharmony_ci 1958c2ecf20Sopenharmony_ci return true; 1968c2ecf20Sopenharmony_ci} 1978c2ecf20Sopenharmony_ci 1988c2ecf20Sopenharmony_cistatic inline unsigned long cpu_asid_inc(void) 1998c2ecf20Sopenharmony_ci{ 2008c2ecf20Sopenharmony_ci return 1 << CONFIG_MIPS_ASID_SHIFT; 2018c2ecf20Sopenharmony_ci} 2028c2ecf20Sopenharmony_ci 2038c2ecf20Sopenharmony_cistatic inline unsigned long cpu_asid_mask(struct cpuinfo_mips *cpuinfo) 2048c2ecf20Sopenharmony_ci{ 2058c2ecf20Sopenharmony_ci#ifdef CONFIG_MIPS_ASID_BITS_VARIABLE 2068c2ecf20Sopenharmony_ci return cpuinfo->asid_mask; 2078c2ecf20Sopenharmony_ci#endif 2088c2ecf20Sopenharmony_ci return ((1 << CONFIG_MIPS_ASID_BITS) - 1) << CONFIG_MIPS_ASID_SHIFT; 2098c2ecf20Sopenharmony_ci} 2108c2ecf20Sopenharmony_ci 2118c2ecf20Sopenharmony_cistatic inline void set_cpu_asid_mask(struct cpuinfo_mips *cpuinfo, 2128c2ecf20Sopenharmony_ci unsigned long asid_mask) 2138c2ecf20Sopenharmony_ci{ 2148c2ecf20Sopenharmony_ci#ifdef CONFIG_MIPS_ASID_BITS_VARIABLE 2158c2ecf20Sopenharmony_ci cpuinfo->asid_mask = asid_mask; 2168c2ecf20Sopenharmony_ci#endif 2178c2ecf20Sopenharmony_ci} 2188c2ecf20Sopenharmony_ci 2198c2ecf20Sopenharmony_ci#endif /* __ASM_CPU_INFO_H */ 220