Myles Watson | 5817078 | 2009-10-28 16:13:28 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Uwe Hermann | c70e9fc | 2010-02-15 23:10:19 +0000 | [diff] [blame] | 4 | * Copyright (C) 2009 Myles Watson <mylesgw@gmail.com> |
Myles Watson | 5817078 | 2009-10-28 16:13:28 +0000 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
Myles Watson | 5817078 | 2009-10-28 16:13:28 +0000 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | /* This file is for "nuisance prototypes" that have no other home. */ |
| 17 | |
Myles Watson | 3426195 | 2010-03-19 02:33:40 +0000 | [diff] [blame] | 18 | #ifndef __LIB_H__ |
| 19 | #define __LIB_H__ |
Ronald G. Minnich | 9764d4c | 2012-06-12 16:29:32 -0700 | [diff] [blame] | 20 | #include <stdint.h> |
Alexandru Gagniuc | 3dd0e72 | 2013-12-26 22:53:52 -0500 | [diff] [blame] | 21 | #include <types.h> |
Myles Watson | 3426195 | 2010-03-19 02:33:40 +0000 | [diff] [blame] | 22 | |
Julius Werner | a25b5d2 | 2016-02-08 11:46:22 -0800 | [diff] [blame^] | 23 | /* Defined in src/lib/lzma.c. Returns decompressed size or 0 on error. */ |
| 24 | size_t ulzma(const void *src, void *dst); |
| 25 | size_t ulzman(const void *src, size_t srcn, void *dst, size_t dstn); |
Myles Watson | 5817078 | 2009-10-28 16:13:28 +0000 | [diff] [blame] | 26 | |
Myles Watson | 3426195 | 2010-03-19 02:33:40 +0000 | [diff] [blame] | 27 | /* Defined in src/lib/ramtest.c */ |
| 28 | void ram_check(unsigned long start, unsigned long stop); |
Sven Schnelle | 3ad8c54 | 2011-12-02 16:23:06 +0100 | [diff] [blame] | 29 | int ram_check_nodie(unsigned long start, unsigned long stop); |
Alexandru Gagniuc | 5239ba2 | 2013-06-08 11:32:36 -0500 | [diff] [blame] | 30 | int ram_check_noprint_nodie(unsigned long start, unsigned long stop); |
Myles Watson | b54deb7 | 2010-04-02 21:39:12 +0000 | [diff] [blame] | 31 | void quick_ram_check(void); |
Myles Watson | 3426195 | 2010-03-19 02:33:40 +0000 | [diff] [blame] | 32 | |
David Hendricks | 560c643 | 2014-02-13 13:07:50 -0800 | [diff] [blame] | 33 | /* Defined in primitive_memtest.c */ |
| 34 | int primitive_memtest(uintptr_t base, uintptr_t size); |
| 35 | |
Ronald G. Minnich | 9764d4c | 2012-06-12 16:29:32 -0700 | [diff] [blame] | 36 | /* Defined in src/lib/stack.c */ |
Stefan Reinauer | 75dbc38 | 2012-10-15 15:19:43 -0700 | [diff] [blame] | 37 | int checkstack(void *top_of_stack, int core); |
Ronald G. Minnich | 9764d4c | 2012-06-12 16:29:32 -0700 | [diff] [blame] | 38 | |
Lee Leahy | 1b0ab81 | 2015-05-14 14:50:42 -0700 | [diff] [blame] | 39 | /* |
| 40 | * Defined in src/lib/hexdump.c |
| 41 | * Use the Linux command "xxd" for matching output. xxd is found in package |
| 42 | * https://packages.debian.org/jessie/amd64/vim-common/filelist |
| 43 | */ |
Alexandru Gagniuc | 3dd0e72 | 2013-12-26 22:53:52 -0500 | [diff] [blame] | 44 | void hexdump(const void *memory, size_t length); |
Paul Menzel | 60ec2ff | 2014-05-03 16:21:34 +0200 | [diff] [blame] | 45 | void hexdump32(char LEVEL, const void *d, size_t len); |
Stefan Reinauer | 2f38b07 | 2013-07-18 16:24:08 -0700 | [diff] [blame] | 46 | |
Julius Werner | 7a8a4ab | 2015-05-22 16:26:40 -0700 | [diff] [blame] | 47 | #if !defined(__ROMCC__) |
| 48 | /* Count Leading Zeroes: clz(0) == 32, clz(0xf) == 28, clz(1 << 31) == 0 */ |
| 49 | static inline int clz(u32 x) { return x ? __builtin_clz(x) : sizeof(x) * 8; } |
| 50 | /* Integer binary logarithm (rounding down): log2(0) == -1, log2(5) == 2 */ |
| 51 | static inline int log2(u32 x) { return sizeof(x) * 8 - clz(x) - 1; } |
| 52 | /* Find First Set: __ffs(1) == 0, __ffs(0) == -1, __ffs(1<<31) == 31 */ |
| 53 | static inline int __ffs(u32 x) { return log2(x & (u32)(-(s32)x)); } |
| 54 | #endif |
| 55 | |
| 56 | /* Integer binary logarithm (rounding up): log2_ceil(0) == -1, log2(5) == 3 */ |
| 57 | static inline int log2_ceil(u32 x) { return (x == 0) ? -1 : log2(x * 2 - 1); } |
| 58 | |
Myles Watson | 3426195 | 2010-03-19 02:33:40 +0000 | [diff] [blame] | 59 | #endif /* __LIB_H__ */ |