Skip to content

Commit f2ac457

Browse files
committed
LoongArch: Add CPU definition headers
Add common headers (CPU definition and address space layout) for basic LoongArch support. Reviewed-by: WANG Xuerui <[email protected]> Reviewed-by: Jiaxun Yang <[email protected]> Signed-off-by: Huacai Chen <[email protected]>
1 parent fa96b57 commit f2ac457

File tree

8 files changed

+2191
-0
lines changed

8 files changed

+2191
-0
lines changed
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/*
3+
* Copyright (C) 2020-2022 Loongson Technology Corporation Limited
4+
*
5+
* Derived from MIPS:
6+
* Copyright (C) 1996, 99 Ralf Baechle
7+
* Copyright (C) 2000, 2002 Maciej W. Rozycki
8+
* Copyright (C) 1990, 1999 by Silicon Graphics, Inc.
9+
*/
10+
#ifndef _ASM_ADDRSPACE_H
11+
#define _ASM_ADDRSPACE_H
12+
13+
#include <linux/const.h>
14+
15+
#include <asm/loongarch.h>
16+
17+
/*
18+
* This gives the physical RAM offset.
19+
*/
20+
#ifndef __ASSEMBLY__
21+
#ifndef PHYS_OFFSET
22+
#define PHYS_OFFSET _AC(0, UL)
23+
#endif
24+
extern unsigned long vm_map_base;
25+
#endif /* __ASSEMBLY__ */
26+
27+
#ifndef IO_BASE
28+
#define IO_BASE CSR_DMW0_BASE
29+
#endif
30+
31+
#ifndef CACHE_BASE
32+
#define CACHE_BASE CSR_DMW1_BASE
33+
#endif
34+
35+
#ifndef UNCACHE_BASE
36+
#define UNCACHE_BASE CSR_DMW0_BASE
37+
#endif
38+
39+
#define DMW_PABITS 48
40+
#define TO_PHYS_MASK ((1ULL << DMW_PABITS) - 1)
41+
42+
/*
43+
* Memory above this physical address will be considered highmem.
44+
*/
45+
#ifndef HIGHMEM_START
46+
#define HIGHMEM_START (_AC(1, UL) << _AC(DMW_PABITS, UL))
47+
#endif
48+
49+
#define TO_PHYS(x) ( ((x) & TO_PHYS_MASK))
50+
#define TO_CACHE(x) (CACHE_BASE | ((x) & TO_PHYS_MASK))
51+
#define TO_UNCACHE(x) (UNCACHE_BASE | ((x) & TO_PHYS_MASK))
52+
53+
/*
54+
* This handles the memory map.
55+
*/
56+
#ifndef PAGE_OFFSET
57+
#define PAGE_OFFSET (CACHE_BASE + PHYS_OFFSET)
58+
#endif
59+
60+
#ifndef FIXADDR_TOP
61+
#define FIXADDR_TOP ((unsigned long)(long)(int)0xfffe0000)
62+
#endif
63+
64+
#ifdef __ASSEMBLY__
65+
#define _ATYPE_
66+
#define _ATYPE32_
67+
#define _ATYPE64_
68+
#define _CONST64_(x) x
69+
#else
70+
#define _ATYPE_ __PTRDIFF_TYPE__
71+
#define _ATYPE32_ int
72+
#define _ATYPE64_ __s64
73+
#ifdef CONFIG_64BIT
74+
#define _CONST64_(x) x ## L
75+
#else
76+
#define _CONST64_(x) x ## LL
77+
#endif
78+
#endif
79+
80+
/*
81+
* 32/64-bit LoongArch address spaces
82+
*/
83+
#ifdef __ASSEMBLY__
84+
#define _ACAST32_
85+
#define _ACAST64_
86+
#else
87+
#define _ACAST32_ (_ATYPE_)(_ATYPE32_) /* widen if necessary */
88+
#define _ACAST64_ (_ATYPE64_) /* do _not_ narrow */
89+
#endif
90+
91+
#ifdef CONFIG_32BIT
92+
93+
#define UVRANGE 0x00000000
94+
#define KPRANGE0 0x80000000
95+
#define KPRANGE1 0xa0000000
96+
#define KVRANGE 0xc0000000
97+
98+
#else
99+
100+
#define XUVRANGE _CONST64_(0x0000000000000000)
101+
#define XSPRANGE _CONST64_(0x4000000000000000)
102+
#define XKPRANGE _CONST64_(0x8000000000000000)
103+
#define XKVRANGE _CONST64_(0xc000000000000000)
104+
105+
#endif
106+
107+
/*
108+
* Returns the physical address of a KPRANGEx / XKPRANGE address
109+
*/
110+
#define PHYSADDR(a) ((_ACAST64_(a)) & TO_PHYS_MASK)
111+
112+
#endif /* _ASM_ADDRSPACE_H */
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/*
3+
* Copyright (C) 2020-2022 Loongson Technology Corporation Limited
4+
*
5+
* Derived from MIPS:
6+
* Copyright (C) 2003, 2004 Ralf Baechle
7+
* Copyright (C) 2004 Maciej W. Rozycki
8+
*/
9+
#ifndef __ASM_CPU_FEATURES_H
10+
#define __ASM_CPU_FEATURES_H
11+
12+
#include <asm/cpu.h>
13+
#include <asm/cpu-info.h>
14+
15+
#define cpu_opt(opt) (cpu_data[0].options & (opt))
16+
#define cpu_has(feat) (cpu_data[0].options & BIT_ULL(feat))
17+
18+
#define cpu_has_loongarch (cpu_has_loongarch32 | cpu_has_loongarch64)
19+
#define cpu_has_loongarch32 (cpu_data[0].isa_level & LOONGARCH_CPU_ISA_32BIT)
20+
#define cpu_has_loongarch64 (cpu_data[0].isa_level & LOONGARCH_CPU_ISA_64BIT)
21+
22+
#define cpu_icache_line_size() cpu_data[0].icache.linesz
23+
#define cpu_dcache_line_size() cpu_data[0].dcache.linesz
24+
#define cpu_vcache_line_size() cpu_data[0].vcache.linesz
25+
#define cpu_scache_line_size() cpu_data[0].scache.linesz
26+
27+
#ifdef CONFIG_32BIT
28+
# define cpu_has_64bits (cpu_data[0].isa_level & LOONGARCH_CPU_ISA_64BIT)
29+
# define cpu_vabits 31
30+
# define cpu_pabits 31
31+
#endif
32+
33+
#ifdef CONFIG_64BIT
34+
# define cpu_has_64bits 1
35+
# define cpu_vabits cpu_data[0].vabits
36+
# define cpu_pabits cpu_data[0].pabits
37+
# define __NEED_ADDRBITS_PROBE
38+
#endif
39+
40+
/*
41+
* SMP assumption: Options of CPU 0 are a superset of all processors.
42+
* This is true for all known LoongArch systems.
43+
*/
44+
#define cpu_has_cpucfg cpu_opt(LOONGARCH_CPU_CPUCFG)
45+
#define cpu_has_lam cpu_opt(LOONGARCH_CPU_LAM)
46+
#define cpu_has_ual cpu_opt(LOONGARCH_CPU_UAL)
47+
#define cpu_has_fpu cpu_opt(LOONGARCH_CPU_FPU)
48+
#define cpu_has_lsx cpu_opt(LOONGARCH_CPU_LSX)
49+
#define cpu_has_lasx cpu_opt(LOONGARCH_CPU_LASX)
50+
#define cpu_has_complex cpu_opt(LOONGARCH_CPU_COMPLEX)
51+
#define cpu_has_crypto cpu_opt(LOONGARCH_CPU_CRYPTO)
52+
#define cpu_has_lvz cpu_opt(LOONGARCH_CPU_LVZ)
53+
#define cpu_has_lbt_x86 cpu_opt(LOONGARCH_CPU_LBT_X86)
54+
#define cpu_has_lbt_arm cpu_opt(LOONGARCH_CPU_LBT_ARM)
55+
#define cpu_has_lbt_mips cpu_opt(LOONGARCH_CPU_LBT_MIPS)
56+
#define cpu_has_lbt (cpu_has_lbt_x86|cpu_has_lbt_arm|cpu_has_lbt_mips)
57+
#define cpu_has_csr cpu_opt(LOONGARCH_CPU_CSR)
58+
#define cpu_has_tlb cpu_opt(LOONGARCH_CPU_TLB)
59+
#define cpu_has_watch cpu_opt(LOONGARCH_CPU_WATCH)
60+
#define cpu_has_vint cpu_opt(LOONGARCH_CPU_VINT)
61+
#define cpu_has_csripi cpu_opt(LOONGARCH_CPU_CSRIPI)
62+
#define cpu_has_extioi cpu_opt(LOONGARCH_CPU_EXTIOI)
63+
#define cpu_has_prefetch cpu_opt(LOONGARCH_CPU_PREFETCH)
64+
#define cpu_has_pmp cpu_opt(LOONGARCH_CPU_PMP)
65+
#define cpu_has_perf cpu_opt(LOONGARCH_CPU_PMP)
66+
#define cpu_has_scalefreq cpu_opt(LOONGARCH_CPU_SCALEFREQ)
67+
#define cpu_has_flatmode cpu_opt(LOONGARCH_CPU_FLATMODE)
68+
#define cpu_has_eiodecode cpu_opt(LOONGARCH_CPU_EIODECODE)
69+
#define cpu_has_guestid cpu_opt(LOONGARCH_CPU_GUESTID)
70+
#define cpu_has_hypervisor cpu_opt(LOONGARCH_CPU_HYPERVISOR)
71+
72+
73+
#endif /* __ASM_CPU_FEATURES_H */

arch/loongarch/include/asm/cpu-info.h

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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+
8+
#include <linux/cache.h>
9+
#include <linux/types.h>
10+
11+
#include <asm/loongarch.h>
12+
13+
/*
14+
* Descriptor for a cache
15+
*/
16+
struct cache_desc {
17+
unsigned int waysize; /* Bytes per way */
18+
unsigned short sets; /* Number of lines per set */
19+
unsigned char ways; /* Number of ways */
20+
unsigned char linesz; /* Size of line in bytes */
21+
unsigned char waybit; /* Bits to select in a cache set */
22+
unsigned char flags; /* Flags describing cache properties */
23+
};
24+
25+
struct cpuinfo_loongarch {
26+
u64 asid_cache;
27+
unsigned long asid_mask;
28+
29+
/*
30+
* Capability and feature descriptor structure for LoongArch CPU
31+
*/
32+
unsigned long long options;
33+
unsigned int processor_id;
34+
unsigned int fpu_vers;
35+
unsigned int fpu_csr0;
36+
unsigned int fpu_mask;
37+
unsigned int cputype;
38+
int isa_level;
39+
int tlbsize;
40+
int tlbsizemtlb;
41+
int tlbsizestlbsets;
42+
int tlbsizestlbways;
43+
struct cache_desc icache; /* Primary I-cache */
44+
struct cache_desc dcache; /* Primary D or combined I/D cache */
45+
struct cache_desc vcache; /* Victim cache, between pcache and scache */
46+
struct cache_desc scache; /* Secondary cache */
47+
struct cache_desc tcache; /* Tertiary/split secondary cache */
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+
58+
extern struct cpuinfo_loongarch cpu_data[];
59+
#define boot_cpu_data cpu_data[0]
60+
#define current_cpu_data cpu_data[smp_processor_id()]
61+
#define raw_current_cpu_data cpu_data[raw_smp_processor_id()]
62+
63+
extern void cpu_probe(void);
64+
65+
extern const char *__cpu_family[];
66+
extern const char *__cpu_full_name[];
67+
#define cpu_family_string() __cpu_family[raw_smp_processor_id()]
68+
#define cpu_full_name_string() __cpu_full_name[raw_smp_processor_id()]
69+
70+
struct seq_file;
71+
struct notifier_block;
72+
73+
extern int register_proc_cpuinfo_notifier(struct notifier_block *nb);
74+
extern int proc_cpuinfo_notifier_call_chain(unsigned long val, void *v);
75+
76+
#define proc_cpuinfo_notifier(fn, pri) \
77+
({ \
78+
static struct notifier_block fn##_nb = { \
79+
.notifier_call = fn, \
80+
.priority = pri \
81+
}; \
82+
\
83+
register_proc_cpuinfo_notifier(&fn##_nb); \
84+
})
85+
86+
struct proc_cpuinfo_notifier_args {
87+
struct seq_file *m;
88+
unsigned long n;
89+
};
90+
91+
static inline bool cpus_are_siblings(int cpua, int cpub)
92+
{
93+
struct cpuinfo_loongarch *infoa = &cpu_data[cpua];
94+
struct cpuinfo_loongarch *infob = &cpu_data[cpub];
95+
96+
if (infoa->package != infob->package)
97+
return false;
98+
99+
if (infoa->core != infob->core)
100+
return false;
101+
102+
return true;
103+
}
104+
105+
static inline unsigned long cpu_asid_mask(struct cpuinfo_loongarch *cpuinfo)
106+
{
107+
return cpuinfo->asid_mask;
108+
}
109+
110+
static inline void set_cpu_asid_mask(struct cpuinfo_loongarch *cpuinfo,
111+
unsigned long asid_mask)
112+
{
113+
cpuinfo->asid_mask = asid_mask;
114+
}
115+
116+
#endif /* __ASM_CPU_INFO_H */

0 commit comments

Comments
 (0)