blob: ab1f067ee38be84aa0d06445a63763d88435bdd4 [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.
Myles Watson58170782009-10-28 16:13:28 +000014 */
15
16/* This file is for "nuisance prototypes" that have no other home. */
17
Myles Watson34261952010-03-19 02:33:40 +000018#ifndef __LIB_H__
19#define __LIB_H__
Ronald G. Minnich9764d4c2012-06-12 16:29:32 -070020#include <stdint.h>
Alexandru Gagniuc3dd0e722013-12-26 22:53:52 -050021#include <types.h>
Myles Watson34261952010-03-19 02:33:40 +000022
Myles Watson58170782009-10-28 16:13:28 +000023/* Defined in src/lib/lzma.c */
24unsigned long ulzma(unsigned char *src, unsigned char *dst);
25
Myles Watson34261952010-03-19 02:33:40 +000026/* Defined in src/lib/ramtest.c */
27void ram_check(unsigned long start, unsigned long stop);
Sven Schnelle3ad8c542011-12-02 16:23:06 +010028int ram_check_nodie(unsigned long start, unsigned long stop);
Alexandru Gagniuc5239ba22013-06-08 11:32:36 -050029int ram_check_noprint_nodie(unsigned long start, unsigned long stop);
Myles Watsonb54deb72010-04-02 21:39:12 +000030void quick_ram_check(void);
Myles Watson34261952010-03-19 02:33:40 +000031
David Hendricks560c6432014-02-13 13:07:50 -080032/* Defined in primitive_memtest.c */
33int primitive_memtest(uintptr_t base, uintptr_t size);
34
Ronald G. Minnich9764d4c2012-06-12 16:29:32 -070035/* Defined in src/lib/stack.c */
Stefan Reinauer75dbc382012-10-15 15:19:43 -070036int checkstack(void *top_of_stack, int core);
Ronald G. Minnich9764d4c2012-06-12 16:29:32 -070037
Lee Leahy1b0ab812015-05-14 14:50:42 -070038/*
39 * Defined in src/lib/hexdump.c
40 * Use the Linux command "xxd" for matching output. xxd is found in package
41 * https://packages.debian.org/jessie/amd64/vim-common/filelist
42 */
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__ */