diff options
author | David S. Miller <davem@davemloft.net> | 2015-03-03 21:16:48 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2015-03-03 21:16:48 -0500 |
commit | 71a83a6db6138b9d41d8a0b6b91cb59f6dc4742c (patch) | |
tree | f74b6e4e48257ec6ce40b95645ecb8533b9cc1f8 /arch/x86/platform/intel-quark/imr_selftest.c | |
parent | b97526f3ff95f92b107f0fb52cbb8627e395429b (diff) | |
parent | a6c5170d1edea97c538c81e377e56c7b5c5b7e63 (diff) |
Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net
Conflicts:
drivers/net/ethernet/rocker/rocker.c
The rocker commit was two overlapping changes, one to rename
the ->vport member to ->pport, and another making the bitmask
expression use '1ULL' instead of plain '1'.
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'arch/x86/platform/intel-quark/imr_selftest.c')
-rw-r--r-- | arch/x86/platform/intel-quark/imr_selftest.c | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/arch/x86/platform/intel-quark/imr_selftest.c b/arch/x86/platform/intel-quark/imr_selftest.c new file mode 100644 index 000000000000..c9a0838890e2 --- /dev/null +++ b/arch/x86/platform/intel-quark/imr_selftest.c | |||
@@ -0,0 +1,129 @@ | |||
1 | /** | ||
2 | * imr_selftest.c | ||
3 | * | ||
4 | * Copyright(c) 2013 Intel Corporation. | ||
5 | * Copyright(c) 2015 Bryan O'Donoghue <pure.logic@nexus-software.ie> | ||
6 | * | ||
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. | ||
10 | * | ||
11 | */ | ||
12 | |||
13 | #include <asm-generic/sections.h> | ||
14 | #include <asm/imr.h> | ||
15 | #include <linux/init.h> | ||
16 | #include <linux/mm.h> | ||
17 | #include <linux/module.h> | ||
18 | #include <linux/types.h> | ||
19 | |||
20 | #define SELFTEST KBUILD_MODNAME ": " | ||
21 | /** | ||
22 | * imr_self_test_result - Print result string for self test. | ||
23 | * | ||
24 | * @res: result code - true if test passed false otherwise. | ||
25 | * @fmt: format string. | ||
26 | * ... variadic argument list. | ||
27 | */ | ||
28 | static void __init imr_self_test_result(int res, const char *fmt, ...) | ||
29 | { | ||
30 | va_list vlist; | ||
31 | |||
32 | /* Print pass/fail. */ | ||
33 | if (res) | ||
34 | pr_info(SELFTEST "pass "); | ||
35 | else | ||
36 | pr_info(SELFTEST "fail "); | ||
37 | |||
38 | /* Print variable string. */ | ||
39 | va_start(vlist, fmt); | ||
40 | vprintk(fmt, vlist); | ||
41 | va_end(vlist); | ||
42 | |||
43 | /* Optional warning. */ | ||
44 | WARN(res == 0, "test failed"); | ||
45 | } | ||
46 | #undef SELFTEST | ||
47 | |||
48 | /** | ||
49 | * imr_self_test | ||
50 | * | ||
51 | * Verify IMR self_test with some simple tests to verify overlap, | ||
52 | * zero sized allocations and 1 KiB sized areas. | ||
53 | * | ||
54 | */ | ||
55 | static void __init imr_self_test(void) | ||
56 | { | ||
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; | ||
61 | |||
62 | /* Test zero zero. */ | ||
63 | ret = imr_add_range(0, 0, 0, 0, false); | ||
64 | imr_self_test_result(ret < 0, "zero sized IMR\n"); | ||
65 | |||
66 | /* Test exact overlap. */ | ||
67 | ret = imr_add_range(base, size, IMR_CPU, IMR_CPU, false); | ||
68 | imr_self_test_result(ret < 0, fmt_over, __va(base), __va(base + size)); | ||
69 | |||
70 | /* Test overlap with base inside of existing. */ | ||
71 | base += size - IMR_ALIGN; | ||
72 | ret = imr_add_range(base, size, IMR_CPU, IMR_CPU, false); | ||
73 | imr_self_test_result(ret < 0, fmt_over, __va(base), __va(base + size)); | ||
74 | |||
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, false); | ||
78 | imr_self_test_result(ret < 0, fmt_over, __va(base), __va(base + size)); | ||
79 | |||
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, false); | ||
83 | imr_self_test_result(ret < 0, "1KiB IMR @ 0x00000000 - access-all\n"); | ||
84 | |||
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, false); | ||
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"); | ||
91 | } | ||
92 | |||
93 | /* Test 2 KiB works. */ | ||
94 | size = IMR_ALIGN * 2; | ||
95 | ret = imr_add_range(0, size, IMR_READ_ACCESS_ALL, | ||
96 | IMR_WRITE_ACCESS_ALL, false); | ||
97 | imr_self_test_result(ret >= 0, "2KiB IMR @ 0x00000000\n"); | ||
98 | if (ret >= 0) { | ||
99 | ret = imr_remove_range(0, size); | ||
100 | imr_self_test_result(ret == 0, "teardown 2KiB\n"); | ||
101 | } | ||
102 | } | ||
103 | |||
104 | /** | ||
105 | * imr_self_test_init - entry point for IMR driver. | ||
106 | * | ||
107 | * return: -ENODEV for no IMR support 0 if good to go. | ||
108 | */ | ||
109 | static int __init imr_self_test_init(void) | ||
110 | { | ||
111 | imr_self_test(); | ||
112 | return 0; | ||
113 | } | ||
114 | |||
115 | /** | ||
116 | * imr_self_test_exit - exit point for IMR code. | ||
117 | * | ||
118 | * return: | ||
119 | */ | ||
120 | static void __exit imr_self_test_exit(void) | ||
121 | { | ||
122 | } | ||
123 | |||
124 | module_init(imr_self_test_init); | ||
125 | module_exit(imr_self_test_exit); | ||
126 | |||
127 | MODULE_AUTHOR("Bryan O'Donoghue <pure.logic@nexus-software.ie>"); | ||
128 | MODULE_DESCRIPTION("Intel Isolated Memory Region self-test driver"); | ||
129 | MODULE_LICENSE("Dual BSD/GPL"); | ||