blob: ee786f7d063d9e7ec47dcfd8d207e53092c77d61 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Peng Fan6f6058b2016-01-28 16:55:04 +08002/*
3 * Copyright (C) 2016 Freescale Semiconductor, Inc.
Peng Fan6f6058b2016-01-28 16:55:04 +08004 */
5
6#include <common.h>
Peng Fan8cf22312018-01-10 13:20:32 +08007#include <asm/io.h>
Peng Fanecd7ab52018-01-10 13:20:33 +08008#include <asm/mach-imx/sys_proto.h>
Peng Fan6f6058b2016-01-28 16:55:04 +08009#include <command.h>
Peng Fanecd7ab52018-01-10 13:20:33 +080010#include <imx_sip.h>
Tom Rini20b9f2e2018-01-03 08:52:39 -050011#include <linux/compiler.h>
Peng Fan6f6058b2016-01-28 16:55:04 +080012
Peng Fan8cf22312018-01-10 13:20:32 +080013int arch_auxiliary_core_up(u32 core_id, ulong boot_private_data)
Peng Fan6f6058b2016-01-28 16:55:04 +080014{
Peng Fan8cf22312018-01-10 13:20:32 +080015 ulong stack, pc;
16
17 if (!boot_private_data)
18 return -EINVAL;
19
Gary Bisson68e74102018-11-14 17:55:29 +010020 stack = *(u32 *)boot_private_data;
21 pc = *(u32 *)(boot_private_data + 4);
Peng Fan8cf22312018-01-10 13:20:32 +080022
Igor Opaniuk0ba1b4d2019-11-28 15:56:19 +020023 printf("## Starting auxiliary core stack = 0x%08lX, pc = 0x%08lX...\n",
24 stack, pc);
25
Peng Fan8cf22312018-01-10 13:20:32 +080026 /* 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 */
Peng Fancd357ad2018-11-20 10:19:25 +000031#ifdef CONFIG_IMX8M
Ye Li264977d2019-10-26 16:24:03 +020032 call_imx_sip(IMX_SIP_SRC, IMX_SIP_SRC_M4_START, 0, 0, 0);
Peng Fanecd7ab52018-01-10 13:20:33 +080033#else
Peng Fan8cf22312018-01-10 13:20:32 +080034 clrsetbits_le32(SRC_BASE_ADDR + SRC_M4_REG_OFFSET,
35 SRC_M4C_NON_SCLR_RST_MASK, SRC_M4_ENABLE_MASK);
Peng Fanecd7ab52018-01-10 13:20:33 +080036#endif
Peng Fan8cf22312018-01-10 13:20:32 +080037
38 return 0;
Peng Fan6f6058b2016-01-28 16:55:04 +080039}
40
Peng Fan8cf22312018-01-10 13:20:32 +080041int arch_auxiliary_core_check_up(u32 core_id)
Peng Fan6f6058b2016-01-28 16:55:04 +080042{
Peng Fancd357ad2018-11-20 10:19:25 +000043#ifdef CONFIG_IMX8M
Ye Li264977d2019-10-26 16:24:03 +020044 return call_imx_sip(IMX_SIP_SRC, IMX_SIP_SRC_M4_STARTED, 0, 0, 0);
Peng Fanecd7ab52018-01-10 13:20:33 +080045#else
Peng Fan8cf22312018-01-10 13:20:32 +080046 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;
Peng Fanecd7ab52018-01-10 13:20:33 +080054#endif
Peng Fan6f6058b2016-01-28 16:55:04 +080055}
56
Peng Fan6f6058b2016-01-28 16:55:04 +080057/*
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 */
Tom Rini20b9f2e2018-01-03 08:52:39 -050070static int do_bootaux(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Peng Fan6f6058b2016-01-28 16:55:04 +080071{
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
Igor Opaniuk0ba1b4d2019-11-28 15:56:19 +020086 if (!addr)
87 return CMD_RET_FAILURE;
Peng Fan6f6058b2016-01-28 16:55:04 +080088
89 ret = arch_auxiliary_core_up(0, addr);
90 if (ret)
91 return CMD_RET_FAILURE;
92
93 return CMD_RET_SUCCESS;
94}
95
96U_BOOT_CMD(
97 bootaux, CONFIG_SYS_MAXARGS, 1, do_bootaux,
98 "Start auxiliary core",
99 ""
100);