~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/x86/platform/intel-quark/imr_selftest.c

Version: ~ [ linux-5.15-rc5 ] ~ [ linux-5.14.11 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.72 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.152 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.210 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.250 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.286 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.288 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.18.140 ] ~ [ linux-3.16.85 ] ~ [ linux-3.14.79 ] ~ [ linux-3.12.74 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /**
  2  * imr_selftest.c -- Intel Isolated Memory Region self-test driver
  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/cpu_device_id.h>
 15 #include <asm/imr.h>
 16 #include <linux/init.h>
 17 #include <linux/mm.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 __printf(2, 3)
 29 void __init imr_self_test_result(int res, const char *fmt, ...)
 30 {
 31         va_list vlist;
 32 
 33         /* Print pass/fail. */
 34         if (res)
 35                 pr_info(SELFTEST "pass ");
 36         else
 37                 pr_info(SELFTEST "fail ");
 38 
 39         /* Print variable string. */
 40         va_start(vlist, fmt);
 41         vprintk(fmt, vlist);
 42         va_end(vlist);
 43 
 44         /* Optional warning. */
 45         WARN(res == 0, "test failed");
 46 }
 47 #undef SELFTEST
 48 
 49 /**
 50  * imr_self_test
 51  *
 52  * Verify IMR self_test with some simple tests to verify overlap,
 53  * zero sized allocations and 1 KiB sized areas.
 54  *
 55  */
 56 static void __init imr_self_test(void)
 57 {
 58         phys_addr_t base  = virt_to_phys(&_text);
 59         size_t size = virt_to_phys(&__end_rodata) - base;
 60         const char *fmt_over = "overlapped IMR @ (0x%08lx - 0x%08lx)\n";
 61         int ret;
 62 
 63         /* Test zero zero. */
 64         ret = imr_add_range(0, 0, 0, 0);
 65         imr_self_test_result(ret < 0, "zero sized IMR\n");
 66 
 67         /* Test exact overlap. */
 68         ret = imr_add_range(base, size, IMR_CPU, IMR_CPU);
 69         imr_self_test_result(ret < 0, fmt_over, __va(base), __va(base + size));
 70 
 71         /* Test overlap with base inside of existing. */
 72         base += size - IMR_ALIGN;
 73         ret = imr_add_range(base, size, IMR_CPU, IMR_CPU);
 74         imr_self_test_result(ret < 0, fmt_over, __va(base), __va(base + size));
 75 
 76         /* Test overlap with end inside of existing. */
 77         base -= size + IMR_ALIGN * 2;
 78         ret = imr_add_range(base, size, IMR_CPU, IMR_CPU);
 79         imr_self_test_result(ret < 0, fmt_over, __va(base), __va(base + size));
 80 
 81         /* Test that a 1 KiB IMR @ zero with read/write all will bomb out. */
 82         ret = imr_add_range(0, IMR_ALIGN, IMR_READ_ACCESS_ALL,
 83                             IMR_WRITE_ACCESS_ALL);
 84         imr_self_test_result(ret < 0, "1KiB IMR @ 0x00000000 - access-all\n");
 85 
 86         /* Test that a 1 KiB IMR @ zero with CPU only will work. */
 87         ret = imr_add_range(0, IMR_ALIGN, IMR_CPU, IMR_CPU);
 88         imr_self_test_result(ret >= 0, "1KiB IMR @ 0x00000000 - cpu-access\n");
 89         if (ret >= 0) {
 90                 ret = imr_remove_range(0, IMR_ALIGN);
 91                 imr_self_test_result(ret == 0, "teardown - cpu-access\n");
 92         }
 93 
 94         /* Test 2 KiB works. */
 95         size = IMR_ALIGN * 2;
 96         ret = imr_add_range(0, size, IMR_READ_ACCESS_ALL, IMR_WRITE_ACCESS_ALL);
 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 static const struct x86_cpu_id imr_ids[] __initconst = {
105         { X86_VENDOR_INTEL, 5, 9 },     /* Intel Quark SoC X1000. */
106         {}
107 };
108 
109 /**
110  * imr_self_test_init - entry point for IMR driver.
111  *
112  * return: -ENODEV for no IMR support 0 if good to go.
113  */
114 static int __init imr_self_test_init(void)
115 {
116         if (x86_match_cpu(imr_ids))
117                 imr_self_test();
118         return 0;
119 }
120 
121 /**
122  * imr_self_test_exit - exit point for IMR code.
123  *
124  * return:
125  */
126 device_initcall(imr_self_test_init);
127 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp