1 /*
2  * This file is subject to the terms and conditions of the GNU General Public
3  * License.  See the file "COPYING" in the main directory of this archive
4  * for more details.
5  *
6  * Copyright (C) 2005 Embedded Alley Solutions, Inc
7  * Copyright (C) 2005 Ralf Baechle (ralf@linux-mips.org)
8  * Copyright (C) 2009 Jiajie Chen (chenjiajie@cse.buaa.edu.cn)
9  * Copyright (C) 2012 Huacai Chen (chenhc@lemote.com)
10  */
11 #ifndef __ASM_MACH_LOONGSON64_KERNEL_ENTRY_H
12 #define __ASM_MACH_LOONGSON64_KERNEL_ENTRY_H
13 
14 #include <asm/cpu.h>
15 
16 /*
17  * Override macros used in arch/mips/kernel/head.S.
18  */
19 	.macro	kernel_entry_setup
20 	.set	push
21 	.set	mips64
22 	/* Set LPA on LOONGSON3 config3 */
23 	mfc0	t0, CP0_CONFIG3
24 	or	t0, (0x1 << 7)
25 	mtc0	t0, CP0_CONFIG3
26 	/* Set ELPA on LOONGSON3 pagegrain */
27 	mfc0	t0, CP0_PAGEGRAIN
28 	or	t0, (0x1 << 29)
29 	mtc0	t0, CP0_PAGEGRAIN
30 	/* Enable STFill Buffer */
31 	mfc0	t0, CP0_PRID
32 	/* Loongson-3A R4+ */
33 	andi	t1, t0, PRID_IMP_MASK
34 	li	t2, PRID_IMP_LOONGSON_64G
35 	beq     t1, t2, 1f
36 	nop
37 	/* Loongson-3A R2/R3 */
38 	andi	t0, (PRID_IMP_MASK | PRID_REV_MASK)
39 	slti	t0, (PRID_IMP_LOONGSON_64C | PRID_REV_LOONGSON3A_R2_0)
40 	bnez	t0, 2f
41 	nop
42 1:
43 	mfc0	t0, CP0_CONFIG6
44 	or	t0, 0x100
45 	mtc0	t0, CP0_CONFIG6
46 2:
47 	_ehb
48 	.set	pop
49 	.endm
50 
51 /*
52  * Do SMP slave processor setup.
53  */
54 	.macro	smp_slave_setup
55 	.set	push
56 	.set	mips64
57 	/* Set LPA on LOONGSON3 config3 */
58 	mfc0	t0, CP0_CONFIG3
59 	or	t0, (0x1 << 7)
60 	mtc0	t0, CP0_CONFIG3
61 	/* Set ELPA on LOONGSON3 pagegrain */
62 	mfc0	t0, CP0_PAGEGRAIN
63 	or	t0, (0x1 << 29)
64 	mtc0	t0, CP0_PAGEGRAIN
65 	/* Enable STFill Buffer */
66 	mfc0	t0, CP0_PRID
67 	/* Loongson-3A R4+ */
68 	andi	t1, t0, PRID_IMP_MASK
69 	li	t2, PRID_IMP_LOONGSON_64G
70 	beq     t1, t2, 1f
71 	nop
72 	/* Loongson-3A R2/R3 */
73 	andi	t0, (PRID_IMP_MASK | PRID_REV_MASK)
74 	slti	t0, (PRID_IMP_LOONGSON_64C | PRID_REV_LOONGSON3A_R2_0)
75 	bnez	t0, 2f
76 	nop
77 1:
78 	mfc0	t0, CP0_CONFIG6
79 	or	t0, 0x100
80 	mtc0	t0, CP0_CONFIG6
81 2:
82 	_ehb
83 	.set	pop
84 	.endm
85 
86 #endif /* __ASM_MACH_LOONGSON64_KERNEL_ENTRY_H */
87