mach-imx: bootaux: print stack pointer and reset vector
[platform/kernel/u-boot.git] / arch / arm / mach-imx / imx_bootaux.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (C) 2016 Freescale Semiconductor, Inc.
4  */
5
6 #include <common.h>
7 #include <asm/io.h>
8 #include <asm/mach-imx/sys_proto.h>
9 #include <command.h>
10 #include <imx_sip.h>
11 #include <linux/compiler.h>
12
13 int arch_auxiliary_core_up(u32 core_id, ulong boot_private_data)
14 {
15         ulong stack, pc;
16
17         if (!boot_private_data)
18                 return -EINVAL;
19
20         stack = *(u32 *)boot_private_data;
21         pc = *(u32 *)(boot_private_data + 4);
22
23         printf("## Starting auxiliary core stack = 0x%08lX, pc = 0x%08lX...\n",
24                stack, pc);
25
26         /* Set the stack and pc to M4 bootROM */
27         writel(stack, M4_BOOTROM_BASE_ADDR);
28         writel(pc, M4_BOOTROM_BASE_ADDR + 4);
29
30         /* Enable M4 */
31 #ifdef CONFIG_IMX8M
32         call_imx_sip(IMX_SIP_SRC, IMX_SIP_SRC_M4_START, 0, 0, 0);
33 #else
34         clrsetbits_le32(SRC_BASE_ADDR + SRC_M4_REG_OFFSET,
35                         SRC_M4C_NON_SCLR_RST_MASK, SRC_M4_ENABLE_MASK);
36 #endif
37
38         return 0;
39 }
40
41 int arch_auxiliary_core_check_up(u32 core_id)
42 {
43 #ifdef CONFIG_IMX8M
44         return call_imx_sip(IMX_SIP_SRC, IMX_SIP_SRC_M4_STARTED, 0, 0, 0);
45 #else
46         unsigned int val;
47
48         val = readl(SRC_BASE_ADDR + SRC_M4_REG_OFFSET);
49
50         if (val & SRC_M4C_NON_SCLR_RST_MASK)
51                 return 0;  /* assert in reset */
52
53         return 1;
54 #endif
55 }
56
57 /*
58  * To i.MX6SX and i.MX7D, the image supported by bootaux needs
59  * the reset vector at the head for the image, with SP and PC
60  * as the first two words.
61  *
62  * Per the cortex-M reference manual, the reset vector of M4 needs
63  * to exist at 0x0 (TCMUL). The PC and SP are the first two addresses
64  * of that vector.  So to boot M4, the A core must build the M4's reset
65  * vector with getting the PC and SP from image and filling them to
66  * TCMUL. When M4 is kicked, it will load the PC and SP by itself.
67  * The TCMUL is mapped to (M4_BOOTROM_BASE_ADDR) at A core side for
68  * accessing the M4 TCMUL.
69  */
70 static int do_bootaux(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
71 {
72         ulong addr;
73         int ret, up;
74
75         if (argc < 2)
76                 return CMD_RET_USAGE;
77
78         up = arch_auxiliary_core_check_up(0);
79         if (up) {
80                 printf("## Auxiliary core is already up\n");
81                 return CMD_RET_SUCCESS;
82         }
83
84         addr = simple_strtoul(argv[1], NULL, 16);
85
86         if (!addr)
87                 return CMD_RET_FAILURE;
88
89         ret = arch_auxiliary_core_up(0, addr);
90         if (ret)
91                 return CMD_RET_FAILURE;
92
93         return CMD_RET_SUCCESS;
94 }
95
96 U_BOOT_CMD(
97         bootaux, CONFIG_SYS_MAXARGS, 1, do_bootaux,
98         "Start auxiliary core",
99         ""
100 );