Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Copyright (C) 2020 Intel Corporation
0004  */
0005 
0006 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
0007 
0008 #include <linux/init.h>
0009 #include <linux/module.h>
0010 #include <linux/printk.h>
0011 
0012 /* a tiny module only meant to test
0013  *
0014  *   set/clear_bit
0015  *   get_count_order/long
0016  */
0017 
0018 /* use an enum because that's the most common BITMAP usage */
0019 enum bitops_fun {
0020     BITOPS_4 = 4,
0021     BITOPS_7 = 7,
0022     BITOPS_11 = 11,
0023     BITOPS_31 = 31,
0024     BITOPS_88 = 88,
0025     BITOPS_LAST = 255,
0026     BITOPS_LENGTH = 256
0027 };
0028 
0029 static DECLARE_BITMAP(g_bitmap, BITOPS_LENGTH);
0030 
0031 static unsigned int order_comb[][2] = {
0032     {0x00000003,  2},
0033     {0x00000004,  2},
0034     {0x00001fff, 13},
0035     {0x00002000, 13},
0036     {0x50000000, 31},
0037     {0x80000000, 31},
0038     {0x80003000, 32},
0039 };
0040 
0041 #ifdef CONFIG_64BIT
0042 static unsigned long order_comb_long[][2] = {
0043     {0x0000000300000000, 34},
0044     {0x0000000400000000, 34},
0045     {0x00001fff00000000, 45},
0046     {0x0000200000000000, 45},
0047     {0x5000000000000000, 63},
0048     {0x8000000000000000, 63},
0049     {0x8000300000000000, 64},
0050 };
0051 #endif
0052 
0053 static int __init test_bitops_startup(void)
0054 {
0055     int i, bit_set;
0056 
0057     pr_info("Starting bitops test\n");
0058     set_bit(BITOPS_4, g_bitmap);
0059     set_bit(BITOPS_7, g_bitmap);
0060     set_bit(BITOPS_11, g_bitmap);
0061     set_bit(BITOPS_31, g_bitmap);
0062     set_bit(BITOPS_88, g_bitmap);
0063 
0064     for (i = 0; i < ARRAY_SIZE(order_comb); i++) {
0065         if (order_comb[i][1] != get_count_order(order_comb[i][0]))
0066             pr_warn("get_count_order wrong for %x\n",
0067                        order_comb[i][0]);
0068     }
0069 
0070     for (i = 0; i < ARRAY_SIZE(order_comb); i++) {
0071         if (order_comb[i][1] != get_count_order_long(order_comb[i][0]))
0072             pr_warn("get_count_order_long wrong for %x\n",
0073                        order_comb[i][0]);
0074     }
0075 
0076 #ifdef CONFIG_64BIT
0077     for (i = 0; i < ARRAY_SIZE(order_comb_long); i++) {
0078         if (order_comb_long[i][1] !=
0079                    get_count_order_long(order_comb_long[i][0]))
0080             pr_warn("get_count_order_long wrong for %lx\n",
0081                        order_comb_long[i][0]);
0082     }
0083 #endif
0084 
0085     barrier();
0086 
0087     clear_bit(BITOPS_4, g_bitmap);
0088     clear_bit(BITOPS_7, g_bitmap);
0089     clear_bit(BITOPS_11, g_bitmap);
0090     clear_bit(BITOPS_31, g_bitmap);
0091     clear_bit(BITOPS_88, g_bitmap);
0092 
0093     bit_set = find_first_bit(g_bitmap, BITOPS_LAST);
0094     if (bit_set != BITOPS_LAST)
0095         pr_err("ERROR: FOUND SET BIT %d\n", bit_set);
0096 
0097     pr_info("Completed bitops test\n");
0098 
0099     return 0;
0100 }
0101 
0102 static void __exit test_bitops_unstartup(void)
0103 {
0104 }
0105 
0106 module_init(test_bitops_startup);
0107 module_exit(test_bitops_unstartup);
0108 
0109 MODULE_AUTHOR("Jesse Brandeburg <jesse.brandeburg@intel.com>, Wei Yang <richard.weiyang@gmail.com>");
0110 MODULE_LICENSE("GPL");
0111 MODULE_DESCRIPTION("Bit testing module");