b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 1 | /* |
| 2 | * (C) Copyright 2012 |
| 3 | * Marvell Semiconductor <www.marvell.com> |
| 4 | * Written-by: Xiaofan Tian <tianxf@marvell.com> |
| 5 | * |
| 6 | * SPDX-License-Identifier: GPL-2.0+ |
| 7 | */ |
| 8 | |
| 9 | #include <common.h> |
| 10 | #include <asm/arch/cpu.h> |
| 11 | |
| 12 | bool pxa_amp_uart_enabled(void) |
| 13 | { |
| 14 | return smp_hw_cpuid() == *(unsigned int *)CONFIG_AMP_SYNC_ADDR; |
| 15 | } |
| 16 | |
| 17 | static void pxa_amp_set_master(unsigned int cpuid) |
| 18 | { |
| 19 | *(unsigned int *)CONFIG_AMP_SYNC_ADDR = cpuid; |
| 20 | } |
| 21 | |
| 22 | bool pxa_is_warm_reset(void) |
| 23 | { |
| 24 | return *(unsigned int *)CONFIG_WARM_RESET; |
| 25 | } |
| 26 | |
| 27 | void pxa_amp_init(void) |
| 28 | { |
| 29 | if (!pxa_is_warm_reset()) { |
| 30 | BUG_ON(smp_hw_cpuid()); |
| 31 | pxa_amp_set_master(0); |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | unsigned int pxa_amp_reloc_end(void) |
| 36 | { |
| 37 | unsigned int reloc_end[CONFIG_NR_CPUS - 1] = CONFIG_SYS_AMP_RELOC_END; |
| 38 | |
| 39 | if (smp_hw_cpuid()) |
| 40 | return reloc_end[smp_hw_cpuid() - 1]; |
| 41 | else |
| 42 | return CONFIG_SYS_RELOC_END; |
| 43 | } |
| 44 | |
| 45 | int do_amp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 46 | { |
| 47 | unsigned int cpu; |
| 48 | |
| 49 | if (argc != 2) |
| 50 | return cmd_usage(cmdtp); |
| 51 | |
| 52 | /* Disable I&D cache */ |
| 53 | icache_disable(); |
| 54 | dcache_disable(); |
| 55 | |
| 56 | cpu = simple_strtoul(argv[1], NULL, 10); |
| 57 | pxa_cpu_reset(cpu, CONFIG_SYS_TEXT_BASE); |
| 58 | |
| 59 | /* Enable I&D cache */ |
| 60 | dcache_enable(); |
| 61 | icache_enable(); |
| 62 | return 0; |
| 63 | } |
| 64 | |
| 65 | U_BOOT_CMD( |
| 66 | amp, 2, 1, do_amp, |
| 67 | "Release other cpu from reset mode", |
| 68 | "Usage:\namp [cpu id]" |
| 69 | ); |
| 70 | |
| 71 | int do_uartsw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 72 | { |
| 73 | unsigned int cpu; |
| 74 | |
| 75 | if (argc != 2) |
| 76 | return cmd_usage(cmdtp); |
| 77 | cpu = simple_strtoul(argv[1], NULL, 10); |
| 78 | if (cpu >= CONFIG_NR_CPUS) { |
| 79 | printf("Invalid CPU number\n"); |
| 80 | return -1; |
| 81 | } |
| 82 | |
| 83 | pxa_amp_set_master(cpu); |
| 84 | |
| 85 | return 0; |
| 86 | } |
| 87 | U_BOOT_CMD( |
| 88 | uartsw, 2, 1, do_uartsw, |
| 89 | "Switch UART to another cpu", |
| 90 | "Usage:\nuartsw [cpu id]" |
| 91 | ); |
| 92 | |
| 93 | int do_cpuid(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 94 | { |
| 95 | unsigned int cpu; |
| 96 | |
| 97 | cpu = smp_hw_cpuid(); |
| 98 | printf("This is cpu %d\n", cpu); |
| 99 | |
| 100 | return 0; |
| 101 | } |
| 102 | |
| 103 | U_BOOT_CMD( |
| 104 | cpuid, 1, 1, do_cpuid, |
| 105 | "Show current CPU ID", |
| 106 | "Usage:\ncpuid" |
| 107 | ); |