blob: b81b1b18bb515cd85c670549e0bc4dccd732f8f5 [file] [log] [blame]
Myles Watson58170782009-10-28 16:13:28 +00001/*
2 * This file is part of the coreboot project.
3 *
Uwe Hermannc70e9fc2010-02-15 23:10:19 +00004 * Copyright (C) 2009 Myles Watson <mylesgw@gmail.com>
Myles Watson58170782009-10-28 16:13:28 +00005 *
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.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
Patrick Georgib890a122015-03-26 15:17:45 +010017 * Foundation, Inc.
Myles Watson58170782009-10-28 16:13:28 +000018 */
19
20/* This file is for "nuisance prototypes" that have no other home. */
21
Myles Watson34261952010-03-19 02:33:40 +000022#ifndef __LIB_H__
23#define __LIB_H__
Ronald G. Minnich9764d4c2012-06-12 16:29:32 -070024#include <stdint.h>
Alexandru Gagniuc3dd0e722013-12-26 22:53:52 -050025#include <types.h>
Myles Watson34261952010-03-19 02:33:40 +000026
Myles Watson58170782009-10-28 16:13:28 +000027/* Defined in src/lib/lzma.c */
28unsigned long ulzma(unsigned char *src, unsigned char *dst);
29
Myles Watson34261952010-03-19 02:33:40 +000030/* Defined in src/lib/ramtest.c */
31void ram_check(unsigned long start, unsigned long stop);
Sven Schnelle3ad8c542011-12-02 16:23:06 +010032int ram_check_nodie(unsigned long start, unsigned long stop);
Alexandru Gagniuc5239ba22013-06-08 11:32:36 -050033int ram_check_noprint_nodie(unsigned long start, unsigned long stop);
Myles Watsonb54deb72010-04-02 21:39:12 +000034void quick_ram_check(void);
Myles Watson34261952010-03-19 02:33:40 +000035
David Hendricks560c6432014-02-13 13:07:50 -080036/* Defined in primitive_memtest.c */
37int primitive_memtest(uintptr_t base, uintptr_t size);
38
Ronald G. Minnich9764d4c2012-06-12 16:29:32 -070039/* Defined in src/lib/stack.c */
Stefan Reinauer75dbc382012-10-15 15:19:43 -070040int checkstack(void *top_of_stack, int core);
Ronald G. Minnich9764d4c2012-06-12 16:29:32 -070041
Stefan Reinauer2f38b072013-07-18 16:24:08 -070042/* Defined in src/lib/hexdump.c */
Alexandru Gagniuc3dd0e722013-12-26 22:53:52 -050043void hexdump(const void *memory, size_t length);
Paul Menzel60ec2ff2014-05-03 16:21:34 +020044void hexdump32(char LEVEL, const void *d, size_t len);
Stefan Reinauer2f38b072013-07-18 16:24:08 -070045
Julius Werner7a8a4ab2015-05-22 16:26:40 -070046#if !defined(__ROMCC__)
47/* Count Leading Zeroes: clz(0) == 32, clz(0xf) == 28, clz(1 << 31) == 0 */
48static inline int clz(u32 x) { return x ? __builtin_clz(x) : sizeof(x) * 8; }
49/* Integer binary logarithm (rounding down): log2(0) == -1, log2(5) == 2 */
50static inline int log2(u32 x) { return sizeof(x) * 8 - clz(x) - 1; }
51/* Find First Set: __ffs(1) == 0, __ffs(0) == -1, __ffs(1<<31) == 31 */
52static inline int __ffs(u32 x) { return log2(x & (u32)(-(s32)x)); }
53#endif
54
55/* Integer binary logarithm (rounding up): log2_ceil(0) == -1, log2(5) == 3 */
56static inline int log2_ceil(u32 x) { return (x == 0) ? -1 : log2(x * 2 - 1); }
57
Myles Watson34261952010-03-19 02:33:40 +000058#endif /* __LIB_H__ */