Merge tag 'powerpc-4.6-4' of git://git.kernel.org/pub/scm/linux/kernel/git/powerpc...
[linux/fpc-iii.git] / arch / x86 / platform / intel-quark / imr_selftest.c
blobf5bad40936ac5bc7a4b47a868fb07121963fe2be
1 /**
2 * imr_selftest.c -- Intel Isolated Memory Region self-test driver
4 * Copyright(c) 2013 Intel Corporation.
5 * Copyright(c) 2015 Bryan O'Donoghue <pure.logic@nexus-software.ie>
7 * IMR self test. The purpose of this module is to run a set of tests on the
8 * IMR API to validate it's sanity. We check for overlapping, reserved
9 * addresses and setup/teardown sanity.
13 #include <asm-generic/sections.h>
14 #include <asm/cpu_device_id.h>
15 #include <asm/imr.h>
16 #include <linux/init.h>
17 #include <linux/mm.h>
18 #include <linux/types.h>
20 #define SELFTEST KBUILD_MODNAME ": "
21 /**
22 * imr_self_test_result - Print result string for self test.
24 * @res: result code - true if test passed false otherwise.
25 * @fmt: format string.
26 * ... variadic argument list.
28 static void __init imr_self_test_result(int res, const char *fmt, ...)
30 va_list vlist;
32 /* Print pass/fail. */
33 if (res)
34 pr_info(SELFTEST "pass ");
35 else
36 pr_info(SELFTEST "fail ");
38 /* Print variable string. */
39 va_start(vlist, fmt);
40 vprintk(fmt, vlist);
41 va_end(vlist);
43 /* Optional warning. */
44 WARN(res == 0, "test failed");
46 #undef SELFTEST
48 /**
49 * imr_self_test
51 * Verify IMR self_test with some simple tests to verify overlap,
52 * zero sized allocations and 1 KiB sized areas.
55 static void __init imr_self_test(void)
57 phys_addr_t base = virt_to_phys(&_text);
58 size_t size = virt_to_phys(&__end_rodata) - base;
59 const char *fmt_over = "overlapped IMR @ (0x%08lx - 0x%08lx)\n";
60 int ret;
62 /* Test zero zero. */
63 ret = imr_add_range(0, 0, 0, 0);
64 imr_self_test_result(ret < 0, "zero sized IMR\n");
66 /* Test exact overlap. */
67 ret = imr_add_range(base, size, IMR_CPU, IMR_CPU);
68 imr_self_test_result(ret < 0, fmt_over, __va(base), __va(base + size));
70 /* Test overlap with base inside of existing. */
71 base += size - IMR_ALIGN;
72 ret = imr_add_range(base, size, IMR_CPU, IMR_CPU);
73 imr_self_test_result(ret < 0, fmt_over, __va(base), __va(base + size));
75 /* Test overlap with end inside of existing. */
76 base -= size + IMR_ALIGN * 2;
77 ret = imr_add_range(base, size, IMR_CPU, IMR_CPU);
78 imr_self_test_result(ret < 0, fmt_over, __va(base), __va(base + size));
80 /* Test that a 1 KiB IMR @ zero with read/write all will bomb out. */
81 ret = imr_add_range(0, IMR_ALIGN, IMR_READ_ACCESS_ALL,
82 IMR_WRITE_ACCESS_ALL);
83 imr_self_test_result(ret < 0, "1KiB IMR @ 0x00000000 - access-all\n");
85 /* Test that a 1 KiB IMR @ zero with CPU only will work. */
86 ret = imr_add_range(0, IMR_ALIGN, IMR_CPU, IMR_CPU);
87 imr_self_test_result(ret >= 0, "1KiB IMR @ 0x00000000 - cpu-access\n");
88 if (ret >= 0) {
89 ret = imr_remove_range(0, IMR_ALIGN);
90 imr_self_test_result(ret == 0, "teardown - cpu-access\n");
93 /* Test 2 KiB works. */
94 size = IMR_ALIGN * 2;
95 ret = imr_add_range(0, size, IMR_READ_ACCESS_ALL, IMR_WRITE_ACCESS_ALL);
96 imr_self_test_result(ret >= 0, "2KiB IMR @ 0x00000000\n");
97 if (ret >= 0) {
98 ret = imr_remove_range(0, size);
99 imr_self_test_result(ret == 0, "teardown 2KiB\n");
103 static const struct x86_cpu_id imr_ids[] __initconst = {
104 { X86_VENDOR_INTEL, 5, 9 }, /* Intel Quark SoC X1000. */
109 * imr_self_test_init - entry point for IMR driver.
111 * return: -ENODEV for no IMR support 0 if good to go.
113 static int __init imr_self_test_init(void)
115 if (x86_match_cpu(imr_ids))
116 imr_self_test();
117 return 0;
121 * imr_self_test_exit - exit point for IMR code.
123 * return:
125 device_initcall(imr_self_test_init);