summaryrefslogtreecommitdiffstats
path: root/arch/arm/cpu/mmuinfo.c
blob: 44d6980a756915ba40f5ad52adcf49c5813aaa6d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// SPDX-License-Identifier: GPL-2.0-only
// SPDX-FileCopyrightText: 2012 Jan Luebbe <j.luebbe@pengutronix.de>, Pengutronix
/*
 * mmuinfo.c - Show MMU/cache information
 */

#include <common.h>
#include <command.h>
#include <getopt.h>
#include <asm/mmuinfo.h>
#include <asm/system_info.h>
#include <zero_page.h>
#include <mmu.h>

int mmuinfo(void *addr)
{
	if (IS_ENABLED(CONFIG_CPU_V8))
		return mmuinfo_v8(addr);
	if (IS_ENABLED(CONFIG_CPU_V7) && cpu_architecture() == CPU_ARCH_ARMv7)
		return mmuinfo_v7(addr);

	return -ENOSYS;
}

static __maybe_unused int do_mmuinfo(int argc, char *argv[])
{
	unsigned long addr;
	int access_zero_page = -1;
	int opt;

	while ((opt = getopt(argc, argv, "zZ")) > 0) {
		switch (opt) {
		case 'z':
			access_zero_page = true;
			break;
		case 'Z':
			access_zero_page = false;
			break;
		default:
			return COMMAND_ERROR_USAGE;
		}
	}

	if (access_zero_page >= 0) {
		if (argc - optind != 0)
			return COMMAND_ERROR_USAGE;

		if (!zero_page_remappable()) {
			pr_warn("No architecture support for zero page remap\n");
			return -ENOSYS;
		}

		if (access_zero_page)
			zero_page_access();
		else
			zero_page_faulting();

		return 0;
	}

	if (argc - optind != 1)
		return COMMAND_ERROR_USAGE;

	addr = strtoul_suffix(argv[1], NULL, 0);

	return mmuinfo((void *)addr);
}

BAREBOX_CMD_HELP_START(mmuinfo)
BAREBOX_CMD_HELP_TEXT("Show MMU/cache information using the cp15/model-specific registers.")
BAREBOX_CMD_HELP_TEXT("")
BAREBOX_CMD_HELP_TEXT("Options:")
BAREBOX_CMD_HELP_OPT ("-z",  "enable access to zero page")
BAREBOX_CMD_HELP_OPT ("-Z",  "disable access to zero page")
BAREBOX_CMD_HELP_END

#ifdef CONFIG_COMMAND_SUPPORT
BAREBOX_CMD_START(mmuinfo)
	.cmd            = do_mmuinfo,
	BAREBOX_CMD_DESC("show MMU/cache information of an address")
	BAREBOX_CMD_OPTS("[-zZ | ADDRESS]")
	BAREBOX_CMD_GROUP(CMD_GRP_INFO)
	BAREBOX_CMD_HELP(cmd_mmuinfo_help)
BAREBOX_CMD_END
#endif