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  * Chris Dearman (chris@mips.com)
7  * Copyright (C) 2007 Mips Technologies, Inc.
8  * Copyright (C) 2014 Imagination Technologies Ltd.
9  */
10 #ifndef __ASM_MACH_MIPS_KERNEL_ENTRY_INIT_H
11 #define __ASM_MACH_MIPS_KERNEL_ENTRY_INIT_H
12 
13 	/*
14 	 * Prepare segments for EVA boot:
15 	 *
16 	 * This is in case the processor boots in legacy configuration
17 	 * (SI_EVAReset is de-asserted and CONFIG5.K == 0)
18 	 *
19 	 * On entry, t1 is loaded with CP0_CONFIG
20 	 *
21 	 * ========================= Mappings =============================
22 	 * Virtual memory           Physical memory           Mapping
23 	 * 0x00000000 - 0x7fffffff  0x80000000 - 0xfffffffff   MUSUK (kuseg)
24 	 *                          Flat 2GB physical memory
25 	 *
26 	 * 0x80000000 - 0x9fffffff  0x00000000 - 0x1ffffffff   MUSUK (kseg0)
27 	 * 0xa0000000 - 0xbf000000  0x00000000 - 0x1ffffffff   MUSUK (kseg1)
28 	 * 0xc0000000 - 0xdfffffff             -                 MK  (kseg2)
29 	 * 0xe0000000 - 0xffffffff             -                 MK  (kseg3)
30 	 *
31 	 *
32 	 * Lowmem is expanded to 2GB
33 	 */
34 	.macro	eva_entry
35 	/*
36 	 * Get Config.K0 value and use it to program
37 	 * the segmentation registers
38 	 */
39 	andi	t1, 0x7 /* CCA */
40 	move	t2, t1
41 	ins	t2, t1, 16, 3
42 	/* SegCtl0 */
43 	li      t0, ((MIPS_SEGCFG_MK << MIPS_SEGCFG_AM_SHIFT) |		\
44 		(0 << MIPS_SEGCFG_PA_SHIFT) |				\
45 		(1 << MIPS_SEGCFG_EU_SHIFT)) |				\
46 		(((MIPS_SEGCFG_MK << MIPS_SEGCFG_AM_SHIFT) |		\
47 		(0 << MIPS_SEGCFG_PA_SHIFT) |				\
48 		(1 << MIPS_SEGCFG_EU_SHIFT)) << 16)
49 	or	t0, t2
50 	mtc0	t0, $5, 2
51 
52 	/* SegCtl1 */
53 	li      t0, ((MIPS_SEGCFG_MUSUK << MIPS_SEGCFG_AM_SHIFT) |	\
54 		(0 << MIPS_SEGCFG_PA_SHIFT) |				\
55 		(2 << MIPS_SEGCFG_C_SHIFT) |				\
56 		(1 << MIPS_SEGCFG_EU_SHIFT)) |				\
57 		(((MIPS_SEGCFG_MUSUK << MIPS_SEGCFG_AM_SHIFT) |		\
58 		(0 << MIPS_SEGCFG_PA_SHIFT) |				\
59 		(1 << MIPS_SEGCFG_EU_SHIFT)) << 16)
60 	ins	t0, t1, 16, 3
61 	mtc0	t0, $5, 3
62 
63 	/* SegCtl2 */
64 	li	t0, ((MIPS_SEGCFG_MUSUK << MIPS_SEGCFG_AM_SHIFT) |	\
65 		(6 << MIPS_SEGCFG_PA_SHIFT) |				\
66 		(1 << MIPS_SEGCFG_EU_SHIFT)) |				\
67 		(((MIPS_SEGCFG_MUSUK << MIPS_SEGCFG_AM_SHIFT) |		\
68 		(4 << MIPS_SEGCFG_PA_SHIFT) |				\
69 		(1 << MIPS_SEGCFG_EU_SHIFT)) << 16)
70 	or	t0, t2
71 	mtc0	t0, $5, 4
72 
73 	jal	mips_ihb
74 	mfc0    t0, $16, 5
75 	li      t2, 0x40000000      /* K bit */
76 	or      t0, t0, t2
77 	mtc0    t0, $16, 5
78 	sync
79 	jal	mips_ihb
80 	.endm
81 
82 	.macro	kernel_entry_setup
83 
84 #ifdef CONFIG_EVA
85 	sync
86 	ehb
87 
88 	mfc0    t1, CP0_CONFIG
89 	bgez    t1, 9f
90 	mfc0	t0, CP0_CONFIG, 1
91 	bgez	t0, 9f
92 	mfc0	t0, CP0_CONFIG, 2
93 	bgez	t0, 9f
94 	mfc0	t0, CP0_CONFIG, 3
95 	sll     t0, t0, 6   /* SC bit */
96 	bgez    t0, 9f
97 
98 	eva_entry
99 	b       0f
100 9:
101 	/* Assume we came from YAMON... */
102 	PTR_LA	v0, 0x9fc00534	/* YAMON print */
103 	lw	v0, (v0)
104 	move	a0, zero
105 	PTR_LA  a1, nonsc_processor
106 	jal	v0
107 
108 	PTR_LA	v0, 0x9fc00520	/* YAMON exit */
109 	lw	v0, (v0)
110 	li	a0, 1
111 	jal	v0
112 
113 1:	b	1b
114 	nop
115 	__INITDATA
116 nonsc_processor:
117 	.asciz  "EVA kernel requires a MIPS core with Segment Control implemented\n"
118 	__FINIT
119 #endif /* CONFIG_EVA */
120 0:
121 	.endm
122 
123 /*
124  * Do SMP slave processor setup necessary before we can safely execute C code.
125  */
126 	.macro	smp_slave_setup
127 #ifdef CONFIG_EVA
128 	sync
129 	ehb
130 	mfc0    t1, CP0_CONFIG
131 	eva_entry
132 #endif
133 	.endm
134 
135 #endif /* __ASM_MACH_MIPS_KERNEL_ENTRY_INIT_H */
136