Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Kumar Gala | ec2b74f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 2 | /* |
Poonam Aggrwal | 0e87098 | 2009-07-31 12:08:14 +0530 | [diff] [blame] | 3 | * Copyright 2008-2009 Freescale Semiconductor, Inc. |
Kumar Gala | ec2b74f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 4 | */ |
| 5 | |
Kumar Gala | ec2b74f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 6 | #include <command.h> |
Simon Glass | 62f9b65 | 2019-11-14 12:57:09 -0700 | [diff] [blame] | 7 | #include <cpu_func.h> |
Tom Rini | 301bac6 | 2024-04-27 08:10:59 -0600 | [diff] [blame] | 8 | #include <vsprintf.h> |
Kumar Gala | ec2b74f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 9 | |
Michal Simek | 711e5e2 | 2015-06-22 10:46:40 +0200 | [diff] [blame] | 10 | static int cpu_status_all(void) |
| 11 | { |
| 12 | unsigned long cpuid; |
| 13 | |
| 14 | for (cpuid = 0; ; cpuid++) { |
| 15 | if (!is_core_valid(cpuid)) { |
| 16 | if (cpuid == 0) { |
| 17 | printf("Core num: %lu is not valid\n", cpuid); |
| 18 | return 1; |
| 19 | } |
| 20 | break; |
| 21 | } |
| 22 | cpu_status(cpuid); |
| 23 | } |
| 24 | |
| 25 | return 0; |
| 26 | } |
| 27 | |
Kim Phillips | 088f1b1 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 28 | static int |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 29 | cpu_cmd(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
Kumar Gala | ec2b74f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 30 | { |
Kumar Gala | 79679d8 | 2008-03-26 08:34:25 -0500 | [diff] [blame] | 31 | unsigned long cpuid; |
Kumar Gala | ec2b74f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 32 | |
Michal Simek | 711e5e2 | 2015-06-22 10:46:40 +0200 | [diff] [blame] | 33 | if (argc == 2 && strncmp(argv[1], "status", 6) == 0) |
| 34 | return cpu_status_all(); |
| 35 | |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 36 | if (argc < 3) |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 37 | return CMD_RET_USAGE; |
Kumar Gala | ec2b74f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 38 | |
Simon Glass | 0b1284e | 2021-07-24 09:03:30 -0600 | [diff] [blame] | 39 | cpuid = dectoul(argv[1], NULL); |
Timur Tabi | fbb9ecf | 2011-08-05 16:15:24 -0500 | [diff] [blame] | 40 | if (!is_core_valid(cpuid)) { |
| 41 | printf ("Core num: %lu is not valid\n", cpuid); |
Kumar Gala | ec2b74f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 42 | return 1; |
| 43 | } |
| 44 | |
| 45 | |
| 46 | if (argc == 3) { |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 47 | if (strncmp(argv[2], "reset", 5) == 0) |
Kumar Gala | ec2b74f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 48 | cpu_reset(cpuid); |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 49 | else if (strncmp(argv[2], "status", 6) == 0) |
Kumar Gala | ec2b74f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 50 | cpu_status(cpuid); |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 51 | else if (strncmp(argv[2], "disable", 7) == 0) |
Kumar Gala | 4194b36 | 2010-01-12 11:42:43 -0600 | [diff] [blame] | 52 | return cpu_disable(cpuid); |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 53 | else |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 54 | return CMD_RET_USAGE; |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 55 | |
Kumar Gala | ec2b74f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 56 | return 0; |
| 57 | } |
| 58 | |
| 59 | /* 4 or greater, make sure its release */ |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 60 | if (strncmp(argv[2], "release", 7) != 0) |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 61 | return CMD_RET_USAGE; |
Kumar Gala | ec2b74f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 62 | |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 63 | if (cpu_release(cpuid, argc - 3, argv + 3)) |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 64 | return CMD_RET_USAGE; |
Kumar Gala | ec2b74f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 65 | |
| 66 | return 0; |
| 67 | } |
| 68 | |
Tom Rini | 3616218 | 2023-10-07 15:13:08 -0400 | [diff] [blame] | 69 | U_BOOT_LONGHELP(cpu, |
Kim Phillips | 088f1b1 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 70 | "<num> reset - Reset cpu <num>\n" |
Michal Simek | 711e5e2 | 2015-06-22 10:46:40 +0200 | [diff] [blame] | 71 | "cpu status - Status of all cpus\n" |
Kim Phillips | 088f1b1 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 72 | "cpu <num> status - Status of cpu <num>\n" |
| 73 | "cpu <num> disable - Disable cpu <num>\n" |
| 74 | "cpu <num> release <addr> [args] - Release cpu <num> at <addr> with [args]" |
Kumar Gala | ec2b74f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 75 | #ifdef CONFIG_PPC |
Kim Phillips | 088f1b1 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 76 | "\n" |
Kumar Gala | 79679d8 | 2008-03-26 08:34:25 -0500 | [diff] [blame] | 77 | " [args] : <pir> <r3> <r6>\n" \ |
Kumar Gala | ec2b74f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 78 | " pir - processor id (if writeable)\n" \ |
| 79 | " r3 - value for gpr 3\n" \ |
Kumar Gala | ec2b74f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 80 | " r6 - value for gpr 6\n" \ |
Kumar Gala | ec2b74f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 81 | "\n" \ |
| 82 | " Use '-' for any arg if you want the default value.\n" \ |
Kumar Gala | 79679d8 | 2008-03-26 08:34:25 -0500 | [diff] [blame] | 83 | " Default for r3 is <num> and r6 is 0\n" \ |
Kumar Gala | ec2b74f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 84 | "\n" \ |
Kumar Gala | 79679d8 | 2008-03-26 08:34:25 -0500 | [diff] [blame] | 85 | " When cpu <num> is released r4 and r5 = 0.\n" \ |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 86 | " r7 will contain the size of the initial mapped area" |
Kumar Gala | ec2b74f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 87 | #endif |
Tom Rini | 3616218 | 2023-10-07 15:13:08 -0400 | [diff] [blame] | 88 | ); |
Kumar Gala | ec2b74f | 2008-01-17 16:48:33 -0600 | [diff] [blame] | 89 | |
| 90 | U_BOOT_CMD( |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 91 | cpu, CONFIG_SYS_MAXARGS, 1, cpu_cmd, |
Kim Phillips | 088f1b1 | 2012-10-29 13:34:31 +0000 | [diff] [blame] | 92 | "Multiprocessor CPU boot manipulation and release", cpu_help_text |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 93 | ); |