diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/Kconfig | 14 | ||||
| -rw-r--r-- | lib/Kconfig.debug | 13 | ||||
| -rw-r--r-- | lib/Makefile | 3 | ||||
| -rw-r--r-- | lib/checksum.c | 13 | ||||
| -rw-r--r-- | lib/cordic.c | 101 | ||||
| -rw-r--r-- | lib/crc8.c | 86 | ||||
| -rw-r--r-- | lib/plist.c | 7 |
7 files changed, 218 insertions, 19 deletions
diff --git a/lib/Kconfig b/lib/Kconfig index 830181cc7a83..32f3e5ae2be5 100644 --- a/lib/Kconfig +++ b/lib/Kconfig | |||
| @@ -79,6 +79,13 @@ config LIBCRC32C | |||
| 79 | require M here. See Castagnoli93. | 79 | require M here. See Castagnoli93. |
| 80 | Module will be libcrc32c. | 80 | Module will be libcrc32c. |
| 81 | 81 | ||
| 82 | config CRC8 | ||
| 83 | tristate "CRC8 function" | ||
| 84 | help | ||
| 85 | This option provides CRC8 function. Drivers may select this | ||
| 86 | when they need to do cyclic redundancy check according CRC8 | ||
| 87 | algorithm. Module will be called crc8. | ||
| 88 | |||
| 82 | config AUDIT_GENERIC | 89 | config AUDIT_GENERIC |
| 83 | bool | 90 | bool |
| 84 | depends on AUDIT && !AUDIT_ARCH | 91 | depends on AUDIT && !AUDIT_ARCH |
| @@ -262,4 +269,11 @@ config AVERAGE | |||
| 262 | 269 | ||
| 263 | If unsure, say N. | 270 | If unsure, say N. |
| 264 | 271 | ||
| 272 | config CORDIC | ||
| 273 | tristate "Cordic function" | ||
| 274 | help | ||
| 275 | The option provides arithmetic function using cordic algorithm | ||
| 276 | so its calculations are in fixed point. Modules can select this | ||
| 277 | when they require this function. Module will be called cordic. | ||
| 278 | |||
| 265 | endmenu | 279 | endmenu |
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index dd373c8ee943..c0cb9c4bc46d 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug | |||
| @@ -227,7 +227,7 @@ config BOOTPARAM_SOFTLOCKUP_PANIC_VALUE | |||
| 227 | config DETECT_HUNG_TASK | 227 | config DETECT_HUNG_TASK |
| 228 | bool "Detect Hung Tasks" | 228 | bool "Detect Hung Tasks" |
| 229 | depends on DEBUG_KERNEL | 229 | depends on DEBUG_KERNEL |
| 230 | default DETECT_SOFTLOCKUP | 230 | default LOCKUP_DETECTOR |
| 231 | help | 231 | help |
| 232 | Say Y here to enable the kernel to detect "hung tasks", | 232 | Say Y here to enable the kernel to detect "hung tasks", |
| 233 | which are bugs that cause the task to be stuck in | 233 | which are bugs that cause the task to be stuck in |
| @@ -648,12 +648,15 @@ config TRACE_IRQFLAGS | |||
| 648 | Enables hooks to interrupt enabling and disabling for | 648 | Enables hooks to interrupt enabling and disabling for |
| 649 | either tracing or lock debugging. | 649 | either tracing or lock debugging. |
| 650 | 650 | ||
| 651 | config DEBUG_SPINLOCK_SLEEP | 651 | config DEBUG_ATOMIC_SLEEP |
| 652 | bool "Spinlock debugging: sleep-inside-spinlock checking" | 652 | bool "Sleep inside atomic section checking" |
| 653 | select PREEMPT_COUNT | ||
| 653 | depends on DEBUG_KERNEL | 654 | depends on DEBUG_KERNEL |
| 654 | help | 655 | help |
| 655 | If you say Y here, various routines which may sleep will become very | 656 | If you say Y here, various routines which may sleep will become very |
| 656 | noisy if they are called with a spinlock held. | 657 | noisy if they are called inside atomic sections: when a spinlock is |
| 658 | held, inside an rcu read side critical section, inside preempt disabled | ||
| 659 | sections, inside an interrupt, etc... | ||
| 657 | 660 | ||
| 658 | config DEBUG_LOCKING_API_SELFTESTS | 661 | config DEBUG_LOCKING_API_SELFTESTS |
| 659 | bool "Locking API boot-time self-tests" | 662 | bool "Locking API boot-time self-tests" |
| @@ -866,7 +869,7 @@ config BOOT_PRINTK_DELAY | |||
| 866 | system, and then set "lpj=M" before setting "boot_delay=N". | 869 | system, and then set "lpj=M" before setting "boot_delay=N". |
| 867 | NOTE: Using this option may adversely affect SMP systems. | 870 | NOTE: Using this option may adversely affect SMP systems. |
| 868 | I.e., processors other than the first one may not boot up. | 871 | I.e., processors other than the first one may not boot up. |
| 869 | BOOT_PRINTK_DELAY also may cause DETECT_SOFTLOCKUP to detect | 872 | BOOT_PRINTK_DELAY also may cause LOCKUP_DETECTOR to detect |
| 870 | what it believes to be lockup conditions. | 873 | what it believes to be lockup conditions. |
| 871 | 874 | ||
| 872 | config RCU_TORTURE_TEST | 875 | config RCU_TORTURE_TEST |
diff --git a/lib/Makefile b/lib/Makefile index 6b597fdb1898..892f4e282ea1 100644 --- a/lib/Makefile +++ b/lib/Makefile | |||
| @@ -61,6 +61,7 @@ obj-$(CONFIG_CRC_ITU_T) += crc-itu-t.o | |||
| 61 | obj-$(CONFIG_CRC32) += crc32.o | 61 | obj-$(CONFIG_CRC32) += crc32.o |
| 62 | obj-$(CONFIG_CRC7) += crc7.o | 62 | obj-$(CONFIG_CRC7) += crc7.o |
| 63 | obj-$(CONFIG_LIBCRC32C) += libcrc32c.o | 63 | obj-$(CONFIG_LIBCRC32C) += libcrc32c.o |
| 64 | obj-$(CONFIG_CRC8) += crc8.o | ||
| 64 | obj-$(CONFIG_GENERIC_ALLOCATOR) += genalloc.o | 65 | obj-$(CONFIG_GENERIC_ALLOCATOR) += genalloc.o |
| 65 | 66 | ||
| 66 | obj-$(CONFIG_ZLIB_INFLATE) += zlib_inflate/ | 67 | obj-$(CONFIG_ZLIB_INFLATE) += zlib_inflate/ |
| @@ -112,6 +113,8 @@ obj-$(CONFIG_AVERAGE) += average.o | |||
| 112 | 113 | ||
| 113 | obj-$(CONFIG_CPU_RMAP) += cpu_rmap.o | 114 | obj-$(CONFIG_CPU_RMAP) += cpu_rmap.o |
| 114 | 115 | ||
| 116 | obj-$(CONFIG_CORDIC) += cordic.o | ||
| 117 | |||
| 115 | hostprogs-y := gen_crc32table | 118 | hostprogs-y := gen_crc32table |
| 116 | clean-files := crc32table.h | 119 | clean-files := crc32table.h |
| 117 | 120 | ||
diff --git a/lib/checksum.c b/lib/checksum.c index 097508732f34..8df2f91e6d98 100644 --- a/lib/checksum.c +++ b/lib/checksum.c | |||
| @@ -49,7 +49,7 @@ static inline unsigned short from32to16(unsigned int x) | |||
| 49 | 49 | ||
| 50 | static unsigned int do_csum(const unsigned char *buff, int len) | 50 | static unsigned int do_csum(const unsigned char *buff, int len) |
| 51 | { | 51 | { |
| 52 | int odd, count; | 52 | int odd; |
| 53 | unsigned int result = 0; | 53 | unsigned int result = 0; |
| 54 | 54 | ||
| 55 | if (len <= 0) | 55 | if (len <= 0) |
| @@ -64,25 +64,22 @@ static unsigned int do_csum(const unsigned char *buff, int len) | |||
| 64 | len--; | 64 | len--; |
| 65 | buff++; | 65 | buff++; |
| 66 | } | 66 | } |
| 67 | count = len >> 1; /* nr of 16-bit words.. */ | 67 | if (len >= 2) { |
| 68 | if (count) { | ||
| 69 | if (2 & (unsigned long) buff) { | 68 | if (2 & (unsigned long) buff) { |
| 70 | result += *(unsigned short *) buff; | 69 | result += *(unsigned short *) buff; |
| 71 | count--; | ||
| 72 | len -= 2; | 70 | len -= 2; |
| 73 | buff += 2; | 71 | buff += 2; |
| 74 | } | 72 | } |
| 75 | count >>= 1; /* nr of 32-bit words.. */ | 73 | if (len >= 4) { |
| 76 | if (count) { | 74 | const unsigned char *end = buff + ((unsigned)len & ~3); |
| 77 | unsigned int carry = 0; | 75 | unsigned int carry = 0; |
| 78 | do { | 76 | do { |
| 79 | unsigned int w = *(unsigned int *) buff; | 77 | unsigned int w = *(unsigned int *) buff; |
| 80 | count--; | ||
| 81 | buff += 4; | 78 | buff += 4; |
| 82 | result += carry; | 79 | result += carry; |
| 83 | result += w; | 80 | result += w; |
| 84 | carry = (w > result); | 81 | carry = (w > result); |
| 85 | } while (count); | 82 | } while (buff < end); |
| 86 | result += carry; | 83 | result += carry; |
| 87 | result = (result & 0xffff) + (result >> 16); | 84 | result = (result & 0xffff) + (result >> 16); |
| 88 | } | 85 | } |
diff --git a/lib/cordic.c b/lib/cordic.c new file mode 100644 index 000000000000..aa27a88d7e04 --- /dev/null +++ b/lib/cordic.c | |||
| @@ -0,0 +1,101 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2011 Broadcom Corporation | ||
| 3 | * | ||
| 4 | * Permission to use, copy, modify, and/or distribute this software for any | ||
| 5 | * purpose with or without fee is hereby granted, provided that the above | ||
| 6 | * copyright notice and this permission notice appear in all copies. | ||
| 7 | * | ||
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY | ||
| 11 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION | ||
| 13 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN | ||
| 14 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 15 | */ | ||
| 16 | #include <linux/module.h> | ||
| 17 | #include <linux/cordic.h> | ||
| 18 | |||
| 19 | #define CORDIC_ANGLE_GEN 39797 | ||
| 20 | #define CORDIC_PRECISION_SHIFT 16 | ||
| 21 | #define CORDIC_NUM_ITER (CORDIC_PRECISION_SHIFT + 2) | ||
| 22 | |||
| 23 | #define FIXED(X) ((s32)((X) << CORDIC_PRECISION_SHIFT)) | ||
| 24 | #define FLOAT(X) (((X) >= 0) \ | ||
| 25 | ? ((((X) >> (CORDIC_PRECISION_SHIFT - 1)) + 1) >> 1) \ | ||
| 26 | : -((((-(X)) >> (CORDIC_PRECISION_SHIFT - 1)) + 1) >> 1)) | ||
| 27 | |||
| 28 | static const s32 arctan_table[] = { | ||
| 29 | 2949120, | ||
| 30 | 1740967, | ||
| 31 | 919879, | ||
| 32 | 466945, | ||
| 33 | 234379, | ||
| 34 | 117304, | ||
| 35 | 58666, | ||
| 36 | 29335, | ||
| 37 | 14668, | ||
| 38 | 7334, | ||
| 39 | 3667, | ||
| 40 | 1833, | ||
| 41 | 917, | ||
| 42 | 458, | ||
| 43 | 229, | ||
| 44 | 115, | ||
| 45 | 57, | ||
| 46 | 29 | ||
| 47 | }; | ||
| 48 | |||
| 49 | /* | ||
| 50 | * cordic_calc_iq() - calculates the i/q coordinate for given angle | ||
| 51 | * | ||
| 52 | * theta: angle in degrees for which i/q coordinate is to be calculated | ||
| 53 | * coord: function output parameter holding the i/q coordinate | ||
| 54 | */ | ||
| 55 | struct cordic_iq cordic_calc_iq(s32 theta) | ||
| 56 | { | ||
| 57 | struct cordic_iq coord; | ||
| 58 | s32 angle, valtmp; | ||
| 59 | unsigned iter; | ||
| 60 | int signx = 1; | ||
| 61 | int signtheta; | ||
| 62 | |||
| 63 | coord.i = CORDIC_ANGLE_GEN; | ||
| 64 | coord.q = 0; | ||
| 65 | angle = 0; | ||
| 66 | |||
| 67 | theta = FIXED(theta); | ||
| 68 | signtheta = (theta < 0) ? -1 : 1; | ||
| 69 | theta = ((theta + FIXED(180) * signtheta) % FIXED(360)) - | ||
| 70 | FIXED(180) * signtheta; | ||
| 71 | |||
| 72 | if (FLOAT(theta) > 90) { | ||
| 73 | theta -= FIXED(180); | ||
| 74 | signx = -1; | ||
| 75 | } else if (FLOAT(theta) < -90) { | ||
| 76 | theta += FIXED(180); | ||
| 77 | signx = -1; | ||
| 78 | } | ||
| 79 | |||
| 80 | for (iter = 0; iter < CORDIC_NUM_ITER; iter++) { | ||
| 81 | if (theta > angle) { | ||
| 82 | valtmp = coord.i - (coord.q >> iter); | ||
| 83 | coord.q += (coord.i >> iter); | ||
| 84 | angle += arctan_table[iter]; | ||
| 85 | } else { | ||
| 86 | valtmp = coord.i + (coord.q >> iter); | ||
| 87 | coord.q -= (coord.i >> iter); | ||
| 88 | angle -= arctan_table[iter]; | ||
| 89 | } | ||
| 90 | coord.i = valtmp; | ||
| 91 | } | ||
| 92 | |||
| 93 | coord.i *= signx; | ||
| 94 | coord.q *= signx; | ||
| 95 | return coord; | ||
| 96 | } | ||
| 97 | EXPORT_SYMBOL(cordic_calc_iq); | ||
| 98 | |||
| 99 | MODULE_DESCRIPTION("Cordic functions"); | ||
| 100 | MODULE_AUTHOR("Broadcom Corporation"); | ||
| 101 | MODULE_LICENSE("Dual BSD/GPL"); | ||
diff --git a/lib/crc8.c b/lib/crc8.c new file mode 100644 index 000000000000..87b59cafdb83 --- /dev/null +++ b/lib/crc8.c | |||
| @@ -0,0 +1,86 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2011 Broadcom Corporation | ||
| 3 | * | ||
| 4 | * Permission to use, copy, modify, and/or distribute this software for any | ||
| 5 | * purpose with or without fee is hereby granted, provided that the above | ||
| 6 | * copyright notice and this permission notice appear in all copies. | ||
| 7 | * | ||
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY | ||
| 11 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION | ||
| 13 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN | ||
| 14 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 15 | */ | ||
| 16 | |||
| 17 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | ||
| 18 | |||
| 19 | #include <linux/module.h> | ||
| 20 | #include <linux/crc8.h> | ||
| 21 | #include <linux/printk.h> | ||
| 22 | |||
| 23 | /* | ||
| 24 | * crc8_populate_msb - fill crc table for given polynomial in reverse bit order. | ||
| 25 | * | ||
| 26 | * table: table to be filled. | ||
| 27 | * polynomial: polynomial for which table is to be filled. | ||
| 28 | */ | ||
| 29 | void crc8_populate_msb(u8 table[CRC8_TABLE_SIZE], u8 polynomial) | ||
| 30 | { | ||
| 31 | int i, j; | ||
| 32 | const u8 msbit = 0x80; | ||
| 33 | u8 t = msbit; | ||
| 34 | |||
| 35 | table[0] = 0; | ||
| 36 | |||
| 37 | for (i = 1; i < CRC8_TABLE_SIZE; i *= 2) { | ||
| 38 | t = (t << 1) ^ (t & msbit ? polynomial : 0); | ||
| 39 | for (j = 0; j < i; j++) | ||
| 40 | table[i+j] = table[j] ^ t; | ||
| 41 | } | ||
| 42 | } | ||
| 43 | EXPORT_SYMBOL(crc8_populate_msb); | ||
| 44 | |||
| 45 | /* | ||
| 46 | * crc8_populate_lsb - fill crc table for given polynomial in regular bit order. | ||
| 47 | * | ||
| 48 | * table: table to be filled. | ||
| 49 | * polynomial: polynomial for which table is to be filled. | ||
| 50 | */ | ||
| 51 | void crc8_populate_lsb(u8 table[CRC8_TABLE_SIZE], u8 polynomial) | ||
| 52 | { | ||
| 53 | int i, j; | ||
| 54 | u8 t = 1; | ||
| 55 | |||
| 56 | table[0] = 0; | ||
| 57 | |||
| 58 | for (i = (CRC8_TABLE_SIZE >> 1); i; i >>= 1) { | ||
| 59 | t = (t >> 1) ^ (t & 1 ? polynomial : 0); | ||
| 60 | for (j = 0; j < CRC8_TABLE_SIZE; j += 2*i) | ||
| 61 | table[i+j] = table[j] ^ t; | ||
| 62 | } | ||
| 63 | } | ||
| 64 | EXPORT_SYMBOL(crc8_populate_lsb); | ||
| 65 | |||
| 66 | /* | ||
| 67 | * crc8 - calculate a crc8 over the given input data. | ||
| 68 | * | ||
| 69 | * table: crc table used for calculation. | ||
| 70 | * pdata: pointer to data buffer. | ||
| 71 | * nbytes: number of bytes in data buffer. | ||
| 72 | * crc: previous returned crc8 value. | ||
| 73 | */ | ||
| 74 | u8 crc8(const u8 table[CRC8_TABLE_SIZE], u8 *pdata, size_t nbytes, u8 crc) | ||
| 75 | { | ||
| 76 | /* loop over the buffer data */ | ||
| 77 | while (nbytes-- > 0) | ||
| 78 | crc = table[(crc ^ *pdata++) & 0xff]; | ||
| 79 | |||
| 80 | return crc; | ||
| 81 | } | ||
| 82 | EXPORT_SYMBOL(crc8); | ||
| 83 | |||
| 84 | MODULE_DESCRIPTION("CRC8 (by Williams, Ross N.) function"); | ||
| 85 | MODULE_AUTHOR("Broadcom Corporation"); | ||
| 86 | MODULE_LICENSE("Dual BSD/GPL"); | ||
diff --git a/lib/plist.c b/lib/plist.c index 0ae7e6431726..a0a4da489c22 100644 --- a/lib/plist.c +++ b/lib/plist.c | |||
| @@ -56,11 +56,6 @@ static void plist_check_list(struct list_head *top) | |||
| 56 | 56 | ||
| 57 | static void plist_check_head(struct plist_head *head) | 57 | static void plist_check_head(struct plist_head *head) |
| 58 | { | 58 | { |
| 59 | WARN_ON(head != &test_head && !head->rawlock && !head->spinlock); | ||
| 60 | if (head->rawlock) | ||
| 61 | WARN_ON_SMP(!raw_spin_is_locked(head->rawlock)); | ||
| 62 | if (head->spinlock) | ||
| 63 | WARN_ON_SMP(!spin_is_locked(head->spinlock)); | ||
| 64 | if (!plist_head_empty(head)) | 59 | if (!plist_head_empty(head)) |
| 65 | plist_check_list(&plist_first(head)->prio_list); | 60 | plist_check_list(&plist_first(head)->prio_list); |
| 66 | plist_check_list(&head->node_list); | 61 | plist_check_list(&head->node_list); |
| @@ -180,7 +175,7 @@ static int __init plist_test(void) | |||
| 180 | unsigned int r = local_clock(); | 175 | unsigned int r = local_clock(); |
| 181 | 176 | ||
| 182 | printk(KERN_INFO "start plist test\n"); | 177 | printk(KERN_INFO "start plist test\n"); |
| 183 | plist_head_init(&test_head, NULL); | 178 | plist_head_init(&test_head); |
| 184 | for (i = 0; i < ARRAY_SIZE(test_node); i++) | 179 | for (i = 0; i < ARRAY_SIZE(test_node); i++) |
| 185 | plist_node_init(test_node + i, 0); | 180 | plist_node_init(test_node + i, 0); |
| 186 | 181 | ||
