// SPDX-License-Identifier: GPL-2.0+
/*
 * Copyright 2008-2009 Freescale Semiconductor, Inc.
 */

#include <command.h>
#include <cpu_func.h>
#include <vsprintf.h>

static int cpu_status_all(void)
{
	unsigned long cpuid;

	for (cpuid = 0; ; cpuid++) {
		if (!is_core_valid(cpuid)) {
			if (cpuid == 0) {
				printf("Core num: %lu is not valid\n", cpuid);
				return 1;
			}
			break;
		}
		cpu_status(cpuid);
	}

	return 0;
}

static int
cpu_cmd(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
{
	unsigned long cpuid;

	if (argc == 2 && strncmp(argv[1], "status", 6) == 0)
		  return cpu_status_all();

	if (argc < 3)
		return CMD_RET_USAGE;

	cpuid = dectoul(argv[1], NULL);
	if (!is_core_valid(cpuid)) {
		printf ("Core num: %lu is not valid\n",	cpuid);
		return 1;
	}

	if (argc == 3) {
		if (strncmp(argv[2], "reset", 5) == 0)
			cpu_reset(cpuid);
		else if (strncmp(argv[2], "status", 6) == 0)
			cpu_status(cpuid);
		else if (strncmp(argv[2], "disable", 7) == 0)
			return cpu_disable(cpuid);
		else
			return CMD_RET_USAGE;

		return 0;
	}

	/* 4 or greater, make sure its release */
	if (strncmp(argv[2], "release", 7) != 0)
		return CMD_RET_USAGE;

	if (cpu_release(cpuid, argc - 3, argv + 3))
		return CMD_RET_USAGE;

	return 0;
}

U_BOOT_LONGHELP(cpu,
	    "<num> reset                 - Reset cpu <num>\n"
	"cpu status                      - Status of all cpus\n"
	"cpu <num> status                - Status of cpu <num>\n"
	"cpu <num> disable               - Disable cpu <num>\n"
	"cpu <num> release <addr> [args] - Release cpu <num> at <addr> with [args]"
#ifdef CONFIG_PPC
	"\n"
	"                         [args] : <pir> <r3> <r6>\n" \
	"                                   pir - processor id (if writeable)\n" \
	"                                    r3 - value for gpr 3\n" \
	"                                    r6 - value for gpr 6\n" \
	"\n" \
	"     Use '-' for any arg if you want the default value.\n" \
	"     Default for r3 is <num> and r6 is 0\n" \
	"\n" \
	"     When cpu <num> is released r4 and r5 = 0.\n" \
	"     r7 will contain the size of the initial mapped area"
#endif
	);

U_BOOT_CMD(
	cpu, CONFIG_SYS_MAXARGS, 1, cpu_cmd,
	"Multiprocessor CPU boot manipulation and release", cpu_help_text
);
