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