coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
lib.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 /* This file is for "nuisance prototypes" that have no other home. */
4 
5 #ifndef __LIB_H__
6 #define __LIB_H__
7 
8 #include <types.h>
9 
10 /* Defined in src/lib/lzma.c. Returns decompressed size or 0 on error. */
11 size_t ulzman(const void *src, size_t srcn, void *dst, size_t dstn);
12 
13 /* Defined in src/lib/ramtest.c */
14 /* Assumption is 32-bit addressable UC memory. */
15 void ram_check(uintptr_t start);
16 int ram_check_nodie(uintptr_t start);
19 
20 /* Defined in primitive_memtest.c */
22 
23 /* Defined in src/lib/stack.c */
24 int checkstack(void *top_of_stack, int core);
25 
26 /*
27  * Defined in src/lib/hexdump.c
28  * Use the Linux command "xxd" for matching output. xxd is found in package
29  * https://packages.debian.org/jessie/amd64/vim-common/filelist
30  */
31 void hexdump(const void *memory, size_t length);
32 
33 /*
34  * hexstrtobin - Turn a string of ASCII hex characters into binary
35  *
36  * @str: String of hex characters to parse
37  * @buf: Buffer to store the resulting bytes into
38  * @len: Maximum length of buffer to fill
39  *
40  * Defined in src/lib/hexstrtobin.c
41  * Ignores non-hex characters in the string.
42  * Ignores the last hex character if the number of hex characters in the string
43  * is odd.
44  * Returns the number of bytes that have been put in the buffer.
45  */
46 size_t hexstrtobin(const char *str, uint8_t *buf, size_t len);
47 
48 /* Population Count: number of bits that are one */
49 static inline int popcnt(u32 x) { return __builtin_popcount(x); }
50 /* Count Leading Zeroes: clz(0) == 32, clz(0xf) == 28, clz(1 << 31) == 0 */
51 static inline int clz(u32 x) { return x ? __builtin_clz(x) : sizeof(x) * 8; }
52 /* Integer binary logarithm (rounding down): log2(0) == -1, log2(5) == 2 */
53 static inline int log2(u32 x) { return sizeof(x) * 8 - clz(x) - 1; }
54 /* Find First Set: __ffs(1) == 0, __ffs(0) == -1, __ffs(1<<31) == 31 */
55 static inline int __ffs(u32 x) { return log2(x & (u32)(-(s32)x)); }
56 /* Find Last Set: __fls(1) == 0, __fls(5) == 2, __fls(1 << 31) == 31 */
57 static inline int __fls(u32 x) { return log2(x); }
58 
59 /* Integer binary logarithm (rounding up): log2_ceil(0) == -1, log2_ceil(5) == 3 */
60 static inline int log2_ceil(u32 x) { return (x == 0) ? -1 : log2(x - 1) + 1; }
61 
62 static inline int popcnt64(u64 x) { return __builtin_popcountll(x); }
63 static inline int clz64(u64 x) { return x ? __builtin_clzll(x) : sizeof(x) * 8; }
64 static inline int log2_64(u64 x) { return sizeof(x) * 8 - clz64(x) - 1; }
65 static inline int __ffs64(u64 x) { return log2_64(x & (u64)(-(s64)x)); }
66 static inline int __fls64(u64 x) { return log2_64(x); }
67 
68 #endif /* __LIB_H__ */
uint64_t length
Definition: fw_cfg_if.h:1
int x
Definition: edid.c:994
static int log2_ceil(u32 x)
Definition: lib.h:60
void ram_check(uintptr_t start)
Definition: ramtest.c:120
static int log2_64(u64 x)
Definition: lib.h:64
static int popcnt(u32 x)
Definition: lib.h:49
int ram_check_nodie(uintptr_t start)
Definition: ramtest.c:134
static int __ffs64(u64 x)
Definition: lib.h:65
void hexdump(const void *memory, size_t length)
Definition: hexdump.c:7
size_t ulzman(const void *src, size_t srcn, void *dst, size_t dstn)
Definition: lzma.c:19
static int clz(u32 x)
Definition: lib.h:51
int primitive_memtest(uintptr_t base, uintptr_t size)
static int __fls(u32 x)
Definition: lib.h:57
static int log2(u32 x)
Definition: lib.h:53
size_t hexstrtobin(const char *str, uint8_t *buf, size_t len)
Definition: hexstrtobin.c:6
static int popcnt64(u64 x)
Definition: lib.h:62
int ram_check_noprint_nodie(uintptr_t start)
Definition: ramtest.c:149
int checkstack(void *top_of_stack, int core)
Definition: stack.c:30
static int clz64(u64 x)
Definition: lib.h:63
void quick_ram_check_or_die(uintptr_t dst)
Definition: ramtest.c:177
static int __ffs(u32 x)
Definition: lib.h:55
static int __fls64(u64 x)
Definition: lib.h:66
static uint8_t * buf
Definition: uart.c:7
static const PCI_SUBCLASS memory[]
Definition: pci_class.c:66
uintptr_t base
Definition: uart.c:17
int64_t s64
Definition: stdint.h:53
uint64_t u64
Definition: stdint.h:54
uint32_t u32
Definition: stdint.h:51
unsigned long uintptr_t
Definition: stdint.h:21
unsigned char uint8_t
Definition: stdint.h:8
int32_t s32
Definition: stdint.h:50