blob: d0cd66fe4dc71fe447f29769c455522e805e0bcb [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
Lee Leahy1b0ab812015-05-14 14:50:42 -070042/*
43 * Defined in src/lib/hexdump.c
44 * Use the Linux command "xxd" for matching output. xxd is found in package
45 * https://packages.debian.org/jessie/amd64/vim-common/filelist
46 */
Alexandru Gagniuc3dd0e722013-12-26 22:53:52 -050047void hexdump(const void *memory, size_t length);
Paul Menzel60ec2ff2014-05-03 16:21:34 +020048void hexdump32(char LEVEL, const void *d, size_t len);
Stefan Reinauer2f38b072013-07-18 16:24:08 -070049
Julius Werner7a8a4ab2015-05-22 16:26:40 -070050#if !defined(__ROMCC__)
51/* Count Leading Zeroes: clz(0) == 32, clz(0xf) == 28, clz(1 << 31) == 0 */
52static inline int clz(u32 x) { return x ? __builtin_clz(x) : sizeof(x) * 8; }
53/* Integer binary logarithm (rounding down): log2(0) == -1, log2(5) == 2 */
54static inline int log2(u32 x) { return sizeof(x) * 8 - clz(x) - 1; }
55/* Find First Set: __ffs(1) == 0, __ffs(0) == -1, __ffs(1<<31) == 31 */
56static inline int __ffs(u32 x) { return log2(x & (u32)(-(s32)x)); }
57#endif
58
59/* Integer binary logarithm (rounding up): log2_ceil(0) == -1, log2(5) == 3 */
60static inline int log2_ceil(u32 x) { return (x == 0) ? -1 : log2(x * 2 - 1); }
61
Myles Watson34261952010-03-19 02:33:40 +000062#endif /* __LIB_H__ */