blob: efb41b3519747dadb77a4ccd4b420e81032288bd [file] [log] [blame]
Huacai Chenc4617312014-06-26 11:41:28 +08001/*
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 */
Huacai Chen30ad29b2015-04-21 10:00:35 +080011#ifndef __ASM_MACH_LOONGSON64_KERNEL_ENTRY_H
12#define __ASM_MACH_LOONGSON64_KERNEL_ENTRY_H
Huacai Chenc4617312014-06-26 11:41:28 +080013
Huacai Chenc824ad12018-09-05 17:33:01 +080014#include <asm/cpu.h>
15
Huacai Chenc4617312014-06-26 11:41:28 +080016/*
17 * Override macros used in arch/mips/kernel/head.S.
18 */
19 .macro kernel_entry_setup
Huacai Chenc4617312014-06-26 11:41:28 +080020 .set push
21 .set mips64
Huacai Chenc4617312014-06-26 11:41:28 +080022 /* Set ELPA on LOONGSON3 pagegrain */
Huacai Chen97ab1bb2018-04-28 11:21:26 +080023 mfc0 t0, CP0_PAGEGRAIN
Huacai Chenb2edcfc2016-03-03 09:45:09 +080024 or t0, (0x1 << 29)
Huacai Chen97ab1bb2018-04-28 11:21:26 +080025 mtc0 t0, CP0_PAGEGRAIN
Huacai Chen1e820da32016-03-03 09:45:13 +080026 /* Enable STFill Buffer */
Huacai Chenc824ad12018-09-05 17:33:01 +080027 mfc0 t0, CP0_PRID
Huacai Chen75074452019-09-21 21:50:27 +080028 /* Loongson-3A R4+ */
29 andi t1, t0, PRID_IMP_MASK
30 li t2, PRID_IMP_LOONGSON_64G
31 beq t1, t2, 1f
32 nop
33 /* Loongson-3A R2/R3 */
Huacai Chenc824ad12018-09-05 17:33:01 +080034 andi t0, (PRID_IMP_MASK | PRID_REV_MASK)
Nathan Chancellorf2c6c222021-12-08 09:56:17 -070035 slti t0, t0, (PRID_IMP_LOONGSON_64C | PRID_REV_LOONGSON3A_R2_0)
Huacai Chen75074452019-09-21 21:50:27 +080036 bnez t0, 2f
37 nop
381:
Huacai Chen97ab1bb2018-04-28 11:21:26 +080039 mfc0 t0, CP0_CONFIG6
Huacai Chen1e820da32016-03-03 09:45:13 +080040 or t0, 0x100
Huacai Chen97ab1bb2018-04-28 11:21:26 +080041 mtc0 t0, CP0_CONFIG6
Huacai Chen75074452019-09-21 21:50:27 +0800422:
Huacai Chenc4617312014-06-26 11:41:28 +080043 _ehb
44 .set pop
Huacai Chenc4617312014-06-26 11:41:28 +080045 .endm
46
47/*
48 * Do SMP slave processor setup.
49 */
50 .macro smp_slave_setup
Huacai Chenc4617312014-06-26 11:41:28 +080051 .set push
52 .set mips64
Huacai Chenc4617312014-06-26 11:41:28 +080053 /* Set ELPA on LOONGSON3 pagegrain */
Huacai Chen97ab1bb2018-04-28 11:21:26 +080054 mfc0 t0, CP0_PAGEGRAIN
Huacai Chenb2edcfc2016-03-03 09:45:09 +080055 or t0, (0x1 << 29)
Huacai Chen97ab1bb2018-04-28 11:21:26 +080056 mtc0 t0, CP0_PAGEGRAIN
Huacai Chen1e820da32016-03-03 09:45:13 +080057 /* Enable STFill Buffer */
Huacai Chenc824ad12018-09-05 17:33:01 +080058 mfc0 t0, CP0_PRID
Huacai Chen75074452019-09-21 21:50:27 +080059 /* Loongson-3A R4+ */
60 andi t1, t0, PRID_IMP_MASK
61 li t2, PRID_IMP_LOONGSON_64G
62 beq t1, t2, 1f
63 nop
64 /* Loongson-3A R2/R3 */
Huacai Chenc824ad12018-09-05 17:33:01 +080065 andi t0, (PRID_IMP_MASK | PRID_REV_MASK)
Nathan Chancellorf2c6c222021-12-08 09:56:17 -070066 slti t0, t0, (PRID_IMP_LOONGSON_64C | PRID_REV_LOONGSON3A_R2_0)
Huacai Chen75074452019-09-21 21:50:27 +080067 bnez t0, 2f
68 nop
691:
Huacai Chen97ab1bb2018-04-28 11:21:26 +080070 mfc0 t0, CP0_CONFIG6
Huacai Chen1e820da32016-03-03 09:45:13 +080071 or t0, 0x100
Huacai Chen97ab1bb2018-04-28 11:21:26 +080072 mtc0 t0, CP0_CONFIG6
Huacai Chen75074452019-09-21 21:50:27 +0800732:
Huacai Chenc4617312014-06-26 11:41:28 +080074 _ehb
75 .set pop
Huacai Chenc4617312014-06-26 11:41:28 +080076 .endm
77
Huacai Chen6ce48892021-04-13 16:57:23 +080078#define USE_KEXEC_SMP_WAIT_FINAL
79 .macro kexec_smp_wait_final
80 /* s0:prid s1:initfn */
81 /* a0:base t1:cpuid t2:node t9:count */
82 mfc0 t1, CP0_EBASE
83 andi t1, MIPS_EBASE_CPUNUM
84 dins a0, t1, 8, 2 /* insert core id*/
85 dext t2, t1, 2, 2
86 dins a0, t2, 44, 2 /* insert node id */
87 mfc0 s0, CP0_PRID
88 andi s0, s0, (PRID_IMP_MASK | PRID_REV_MASK)
89 beq s0, (PRID_IMP_LOONGSON_64C | PRID_REV_LOONGSON3B_R1), 1f
90 beq s0, (PRID_IMP_LOONGSON_64C | PRID_REV_LOONGSON3B_R2), 1f
91 b 2f /* Loongson-3A1000/3A2000/3A3000/3A4000 */
921: dins a0, t2, 14, 2 /* Loongson-3B1000/3B1500 need bit 15~14 */
932: li t9, 0x100 /* wait for init loop */
943: addiu t9, -1 /* limit mailbox access */
95 bnez t9, 3b
96 lw s1, 0x20(a0) /* check PC as an indicator */
97 beqz s1, 2b
98 ld s1, 0x20(a0) /* get PC via mailbox reg0 */
99 ld sp, 0x28(a0) /* get SP via mailbox reg1 */
100 ld gp, 0x30(a0) /* get GP via mailbox reg2 */
101 ld a1, 0x38(a0)
102 jr s1 /* jump to initial PC */
103 .endm
104
Huacai Chen30ad29b2015-04-21 10:00:35 +0800105#endif /* __ASM_MACH_LOONGSON64_KERNEL_ENTRY_H */