162306a36Sopenharmony_ci/*
262306a36Sopenharmony_ci * This file is subject to the terms and conditions of the GNU General Public
362306a36Sopenharmony_ci * License.  See the file "COPYING" in the main directory of this archive
462306a36Sopenharmony_ci * for more details.
562306a36Sopenharmony_ci *
662306a36Sopenharmony_ci * Copyright (C) 1994 Waldorf GMBH
762306a36Sopenharmony_ci * Copyright (C) 1995, 1996, 1997, 1998, 1999, 2001, 2002, 2003 Ralf Baechle
862306a36Sopenharmony_ci * Copyright (C) 1996 Paul M. Antoine
962306a36Sopenharmony_ci * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
1062306a36Sopenharmony_ci * Copyright (C) 2004  Maciej W. Rozycki
1162306a36Sopenharmony_ci */
1262306a36Sopenharmony_ci#ifndef __ASM_CPU_INFO_H
1362306a36Sopenharmony_ci#define __ASM_CPU_INFO_H
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ci#include <linux/cache.h>
1662306a36Sopenharmony_ci#include <linux/types.h>
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ci#include <asm/mipsregs.h>
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_ci/*
2162306a36Sopenharmony_ci * Descriptor for a cache
2262306a36Sopenharmony_ci */
2362306a36Sopenharmony_cistruct cache_desc {
2462306a36Sopenharmony_ci	unsigned int waysize;	/* Bytes per way */
2562306a36Sopenharmony_ci	unsigned short sets;	/* Number of lines per set */
2662306a36Sopenharmony_ci	unsigned char ways;	/* Number of ways */
2762306a36Sopenharmony_ci	unsigned char linesz;	/* Size of line in bytes */
2862306a36Sopenharmony_ci	unsigned char waybit;	/* Bits to select in a cache set */
2962306a36Sopenharmony_ci	unsigned char flags;	/* Flags describing cache properties */
3062306a36Sopenharmony_ci};
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_cistruct guest_info {
3362306a36Sopenharmony_ci	unsigned long		ases;
3462306a36Sopenharmony_ci	unsigned long		ases_dyn;
3562306a36Sopenharmony_ci	unsigned long long	options;
3662306a36Sopenharmony_ci	unsigned long long	options_dyn;
3762306a36Sopenharmony_ci	int			tlbsize;
3862306a36Sopenharmony_ci	u8			conf;
3962306a36Sopenharmony_ci	u8			kscratch_mask;
4062306a36Sopenharmony_ci};
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ci/*
4362306a36Sopenharmony_ci * Flag definitions
4462306a36Sopenharmony_ci */
4562306a36Sopenharmony_ci#define MIPS_CACHE_NOT_PRESENT	0x00000001
4662306a36Sopenharmony_ci#define MIPS_CACHE_VTAG		0x00000002	/* Virtually tagged cache */
4762306a36Sopenharmony_ci#define MIPS_CACHE_ALIASES	0x00000004	/* Cache could have aliases */
4862306a36Sopenharmony_ci#define MIPS_CACHE_IC_F_DC	0x00000008	/* Ic can refill from D-cache */
4962306a36Sopenharmony_ci#define MIPS_IC_SNOOPS_REMOTE	0x00000010	/* Ic snoops remote stores */
5062306a36Sopenharmony_ci#define MIPS_CACHE_PINDEX	0x00000020	/* Physically indexed cache */
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_cistruct cpuinfo_mips {
5362306a36Sopenharmony_ci	u64			asid_cache;
5462306a36Sopenharmony_ci#ifdef CONFIG_MIPS_ASID_BITS_VARIABLE
5562306a36Sopenharmony_ci	unsigned long		asid_mask;
5662306a36Sopenharmony_ci#endif
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_ci	/*
5962306a36Sopenharmony_ci	 * Capability and feature descriptor structure for MIPS CPU
6062306a36Sopenharmony_ci	 */
6162306a36Sopenharmony_ci	unsigned long		ases;
6262306a36Sopenharmony_ci	unsigned long long	options;
6362306a36Sopenharmony_ci	unsigned int		udelay_val;
6462306a36Sopenharmony_ci	unsigned int		processor_id;
6562306a36Sopenharmony_ci	unsigned int		fpu_id;
6662306a36Sopenharmony_ci	unsigned int		fpu_csr31;
6762306a36Sopenharmony_ci	unsigned int		fpu_msk31;
6862306a36Sopenharmony_ci	unsigned int		msa_id;
6962306a36Sopenharmony_ci	unsigned int		cputype;
7062306a36Sopenharmony_ci	int			isa_level;
7162306a36Sopenharmony_ci	int			tlbsize;
7262306a36Sopenharmony_ci	int			tlbsizevtlb;
7362306a36Sopenharmony_ci	int			tlbsizeftlbsets;
7462306a36Sopenharmony_ci	int			tlbsizeftlbways;
7562306a36Sopenharmony_ci	struct cache_desc	icache; /* Primary I-cache */
7662306a36Sopenharmony_ci	struct cache_desc	dcache; /* Primary D or combined I/D cache */
7762306a36Sopenharmony_ci	struct cache_desc	vcache; /* Victim cache, between pcache and scache */
7862306a36Sopenharmony_ci	struct cache_desc	scache; /* Secondary cache */
7962306a36Sopenharmony_ci	struct cache_desc	tcache; /* Tertiary/split secondary cache */
8062306a36Sopenharmony_ci	int			srsets; /* Shadow register sets */
8162306a36Sopenharmony_ci	int			package;/* physical package number */
8262306a36Sopenharmony_ci	unsigned int		globalnumber;
8362306a36Sopenharmony_ci#ifdef CONFIG_64BIT
8462306a36Sopenharmony_ci	int			vmbits; /* Virtual memory size in bits */
8562306a36Sopenharmony_ci#endif
8662306a36Sopenharmony_ci	void			*data;	/* Additional data */
8762306a36Sopenharmony_ci	unsigned int		watch_reg_count;   /* Number that exist */
8862306a36Sopenharmony_ci	unsigned int		watch_reg_use_cnt; /* Usable by ptrace */
8962306a36Sopenharmony_ci#define NUM_WATCH_REGS 4
9062306a36Sopenharmony_ci	u16			watch_reg_masks[NUM_WATCH_REGS];
9162306a36Sopenharmony_ci	unsigned int		kscratch_mask; /* Usable KScratch mask. */
9262306a36Sopenharmony_ci	/*
9362306a36Sopenharmony_ci	 * Cache Coherency attribute for write-combine memory writes.
9462306a36Sopenharmony_ci	 * (shifted by _CACHE_SHIFT)
9562306a36Sopenharmony_ci	 */
9662306a36Sopenharmony_ci	unsigned int		writecombine;
9762306a36Sopenharmony_ci	/*
9862306a36Sopenharmony_ci	 * Simple counter to prevent enabling HTW in nested
9962306a36Sopenharmony_ci	 * htw_start/htw_stop calls
10062306a36Sopenharmony_ci	 */
10162306a36Sopenharmony_ci	unsigned int		htw_seq;
10262306a36Sopenharmony_ci
10362306a36Sopenharmony_ci	/* VZ & Guest features */
10462306a36Sopenharmony_ci	struct guest_info	guest;
10562306a36Sopenharmony_ci	unsigned int		gtoffset_mask;
10662306a36Sopenharmony_ci	unsigned int		guestid_mask;
10762306a36Sopenharmony_ci	unsigned int		guestid_cache;
10862306a36Sopenharmony_ci
10962306a36Sopenharmony_ci#ifdef CONFIG_CPU_LOONGSON3_CPUCFG_EMULATION
11062306a36Sopenharmony_ci	/* CPUCFG data for this CPU, synthesized at probe time.
11162306a36Sopenharmony_ci	 *
11262306a36Sopenharmony_ci	 * CPUCFG select 0 is PRId, 4 and above are unimplemented for now.
11362306a36Sopenharmony_ci	 * So the only stored values are for CPUCFG selects 1-3 inclusive.
11462306a36Sopenharmony_ci	 */
11562306a36Sopenharmony_ci	u32 loongson3_cpucfg_data[3];
11662306a36Sopenharmony_ci#endif
11762306a36Sopenharmony_ci} __attribute__((aligned(SMP_CACHE_BYTES)));
11862306a36Sopenharmony_ci
11962306a36Sopenharmony_ciextern struct cpuinfo_mips cpu_data[];
12062306a36Sopenharmony_ci#define current_cpu_data cpu_data[smp_processor_id()]
12162306a36Sopenharmony_ci#define raw_current_cpu_data cpu_data[raw_smp_processor_id()]
12262306a36Sopenharmony_ci#define boot_cpu_data cpu_data[0]
12362306a36Sopenharmony_ci
12462306a36Sopenharmony_ciextern void cpu_probe(void);
12562306a36Sopenharmony_ciextern void cpu_report(void);
12662306a36Sopenharmony_ci
12762306a36Sopenharmony_ciextern const char *__cpu_name[];
12862306a36Sopenharmony_ci#define cpu_name_string()	__cpu_name[raw_smp_processor_id()]
12962306a36Sopenharmony_ci
13062306a36Sopenharmony_cistruct seq_file;
13162306a36Sopenharmony_cistruct notifier_block;
13262306a36Sopenharmony_ci
13362306a36Sopenharmony_ciextern int register_proc_cpuinfo_notifier(struct notifier_block *nb);
13462306a36Sopenharmony_ciextern int proc_cpuinfo_notifier_call_chain(unsigned long val, void *v);
13562306a36Sopenharmony_ci
13662306a36Sopenharmony_ci#define proc_cpuinfo_notifier(fn, pri)					\
13762306a36Sopenharmony_ci({									\
13862306a36Sopenharmony_ci	static struct notifier_block fn##_nb = {			\
13962306a36Sopenharmony_ci		.notifier_call = fn,					\
14062306a36Sopenharmony_ci		.priority = pri						\
14162306a36Sopenharmony_ci	};								\
14262306a36Sopenharmony_ci									\
14362306a36Sopenharmony_ci	register_proc_cpuinfo_notifier(&fn##_nb);			\
14462306a36Sopenharmony_ci})
14562306a36Sopenharmony_ci
14662306a36Sopenharmony_cistruct proc_cpuinfo_notifier_args {
14762306a36Sopenharmony_ci	struct seq_file *m;
14862306a36Sopenharmony_ci	unsigned long n;
14962306a36Sopenharmony_ci};
15062306a36Sopenharmony_ci
15162306a36Sopenharmony_cistatic inline unsigned int cpu_cluster(struct cpuinfo_mips *cpuinfo)
15262306a36Sopenharmony_ci{
15362306a36Sopenharmony_ci	/* Optimisation for systems where multiple clusters aren't used */
15462306a36Sopenharmony_ci	if (!IS_ENABLED(CONFIG_CPU_MIPSR5) && !IS_ENABLED(CONFIG_CPU_MIPSR6))
15562306a36Sopenharmony_ci		return 0;
15662306a36Sopenharmony_ci
15762306a36Sopenharmony_ci	return (cpuinfo->globalnumber & MIPS_GLOBALNUMBER_CLUSTER) >>
15862306a36Sopenharmony_ci		MIPS_GLOBALNUMBER_CLUSTER_SHF;
15962306a36Sopenharmony_ci}
16062306a36Sopenharmony_ci
16162306a36Sopenharmony_cistatic inline unsigned int cpu_core(struct cpuinfo_mips *cpuinfo)
16262306a36Sopenharmony_ci{
16362306a36Sopenharmony_ci	return (cpuinfo->globalnumber & MIPS_GLOBALNUMBER_CORE) >>
16462306a36Sopenharmony_ci		MIPS_GLOBALNUMBER_CORE_SHF;
16562306a36Sopenharmony_ci}
16662306a36Sopenharmony_ci
16762306a36Sopenharmony_cistatic inline unsigned int cpu_vpe_id(struct cpuinfo_mips *cpuinfo)
16862306a36Sopenharmony_ci{
16962306a36Sopenharmony_ci	/* Optimisation for systems where VP(E)s aren't used */
17062306a36Sopenharmony_ci	if (!IS_ENABLED(CONFIG_MIPS_MT_SMP) && !IS_ENABLED(CONFIG_CPU_MIPSR6))
17162306a36Sopenharmony_ci		return 0;
17262306a36Sopenharmony_ci
17362306a36Sopenharmony_ci	return (cpuinfo->globalnumber & MIPS_GLOBALNUMBER_VP) >>
17462306a36Sopenharmony_ci		MIPS_GLOBALNUMBER_VP_SHF;
17562306a36Sopenharmony_ci}
17662306a36Sopenharmony_ci
17762306a36Sopenharmony_ciextern void cpu_set_cluster(struct cpuinfo_mips *cpuinfo, unsigned int cluster);
17862306a36Sopenharmony_ciextern void cpu_set_core(struct cpuinfo_mips *cpuinfo, unsigned int core);
17962306a36Sopenharmony_ciextern void cpu_set_vpe_id(struct cpuinfo_mips *cpuinfo, unsigned int vpe);
18062306a36Sopenharmony_ci
18162306a36Sopenharmony_cistatic inline bool cpus_are_siblings(int cpua, int cpub)
18262306a36Sopenharmony_ci{
18362306a36Sopenharmony_ci	struct cpuinfo_mips *infoa = &cpu_data[cpua];
18462306a36Sopenharmony_ci	struct cpuinfo_mips *infob = &cpu_data[cpub];
18562306a36Sopenharmony_ci	unsigned int gnuma, gnumb;
18662306a36Sopenharmony_ci
18762306a36Sopenharmony_ci	if (infoa->package != infob->package)
18862306a36Sopenharmony_ci		return false;
18962306a36Sopenharmony_ci
19062306a36Sopenharmony_ci	gnuma = infoa->globalnumber & ~MIPS_GLOBALNUMBER_VP;
19162306a36Sopenharmony_ci	gnumb = infob->globalnumber & ~MIPS_GLOBALNUMBER_VP;
19262306a36Sopenharmony_ci	if (gnuma != gnumb)
19362306a36Sopenharmony_ci		return false;
19462306a36Sopenharmony_ci
19562306a36Sopenharmony_ci	return true;
19662306a36Sopenharmony_ci}
19762306a36Sopenharmony_ci
19862306a36Sopenharmony_cistatic inline unsigned long cpu_asid_inc(void)
19962306a36Sopenharmony_ci{
20062306a36Sopenharmony_ci	return 1 << CONFIG_MIPS_ASID_SHIFT;
20162306a36Sopenharmony_ci}
20262306a36Sopenharmony_ci
20362306a36Sopenharmony_cistatic inline unsigned long cpu_asid_mask(struct cpuinfo_mips *cpuinfo)
20462306a36Sopenharmony_ci{
20562306a36Sopenharmony_ci#ifdef CONFIG_MIPS_ASID_BITS_VARIABLE
20662306a36Sopenharmony_ci	return cpuinfo->asid_mask;
20762306a36Sopenharmony_ci#endif
20862306a36Sopenharmony_ci	return ((1 << CONFIG_MIPS_ASID_BITS) - 1) << CONFIG_MIPS_ASID_SHIFT;
20962306a36Sopenharmony_ci}
21062306a36Sopenharmony_ci
21162306a36Sopenharmony_cistatic inline void set_cpu_asid_mask(struct cpuinfo_mips *cpuinfo,
21262306a36Sopenharmony_ci				     unsigned long asid_mask)
21362306a36Sopenharmony_ci{
21462306a36Sopenharmony_ci#ifdef CONFIG_MIPS_ASID_BITS_VARIABLE
21562306a36Sopenharmony_ci	cpuinfo->asid_mask = asid_mask;
21662306a36Sopenharmony_ci#endif
21762306a36Sopenharmony_ci}
21862306a36Sopenharmony_ci
21962306a36Sopenharmony_ci#endif /* __ASM_CPU_INFO_H */
220