libpayload: Support functions for Geode
[coreboot.git] / payloads / libpayload / include / libpayload.h
1 /*
2  * This file is part of the libpayload project.
3  *
4  * Copyright (C) 2008 Advanced Micro Devices, Inc.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. The name of the author may not be used to endorse or promote products
15  *    derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  */
29
30 #ifndef LIBPAYLOAD_H
31 #define LIBPAYLOAD_H
32
33 #include <autoconf.h>
34 #include <stddef.h>
35 #include <arch/types.h>
36 #include <arch/io.h>
37 #include <sysinfo.h>
38 #include <stdarg.h>
39
40 #define MIN(a,b) ((a) < (b) ? (a) : (b))
41 #define MAX(a,b) ((a) > (b) ? (a) : (b))
42 #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
43
44 #define BIN2HEX(b) ("0123456789abcdef"[b & 15])
45 #define HEX2BIN(h) (('0' <= h && h <= '9') ? (h - '0') : \
46                     ('a' <= h && h <= 'f') ? (h - 'a' + 10) : 0)
47
48 #define LITTLE_ENDIAN   1234
49 #define BIG_ENDIAN      4321
50 #ifdef CONFIG_TARGET_I386
51 #define BYTE_ORDER      LITTLE_ENDIAN
52 #else
53 #define BYTE_ORDER      BIG_ENDIAN
54 #endif
55
56 #define RAND_MAX 0x7fffffff
57
58 /* Some NVRAM byte definitions */
59 #define NVRAM_RTC_SECONDS        0
60 #define NVRAM_RTC_MINUTES        2
61 #define NVRAM_RTC_HOURS          4
62 #define NVRAM_RTC_DAY            7
63 #define NVRAM_RTC_MONTH          8
64 #define NVRAM_RTC_YEAR           9
65
66 /* drivers/nvram.c */
67 u8 nvram_read(u8 addr);
68 void nvram_write(u8 val, u8 addr);
69
70 /* drivers/keyboard.c */
71 int keyboard_havechar(void);
72 unsigned char keyboard_get_scancode(void);
73 int keyboard_getchar(void);
74
75 /* drivers/serial.c */
76 void serial_init(void);
77 void serial_putchar(unsigned char c);
78 int serial_havechar(void);
79 int serial_getchar(void);
80
81 /* video/video.c */
82 int video_console_init(void);
83 void video_console_putchar(unsigned int ch);
84 void video_console_putc(u8 row, u8 col, unsigned int ch);
85 void video_console_clear(void);
86 void video_console_cursor_enable(int state);
87
88 /* libc/console.c */
89 void console_init(void);
90 int putchar(int c);
91 int puts(const char *s);
92 int havekey(void);
93 int getchar(void);
94 int getchar_timeout(int *ms);
95
96 extern int last_putchar;
97
98 #define havechar havekey
99
100 /* libc/ctype.c */
101 int isspace(int c);
102 int isdigit(int c);
103 int tolower(int c);
104
105 /* libc/ipchecksum.c */
106 unsigned short ipchksum(const unsigned short *ptr, unsigned long nbytes);
107
108 /* libc/malloc.c */
109 void free(void *ptr);
110 void *malloc(size_t size);
111 void *calloc(size_t nmemb, size_t size);
112 void *realloc(void *ptr, size_t size);
113
114 /* libc/lib.c */
115 int bcd2dec(int b);
116 int dec2bcd(int d);
117
118 /* libc/memory.c */
119 void *memset(void *s, int c, size_t n);
120 void *memcpy(void *dst, const void *src, size_t n);
121 void *memmove(void *dst, const void *src, size_t n);
122 int memcmp(const char *s1, const char *s2, size_t len);
123
124 /* libc/printf.c */
125 int snprintf(char *str, size_t size, const char *fmt, ...);
126 int sprintf(char *str, const char *fmt, ...);
127 int vsnprintf(char *str, size_t size, const char *fmt, va_list ap);
128 int vsprintf(char *str, const char *fmt, va_list ap);
129 int printf(const char *fmt, ...);
130 int vprintf(const char *fmt, va_list ap);
131
132 /* libc/rand.c */
133 int rand_r(unsigned int *seed);
134 int rand(void);
135 void srand(unsigned int seed);
136
137 /* libc/sha1.c */
138 #define SHA1_BLOCK_LENGTH       64
139 #define SHA1_DIGEST_LENGTH      20
140 typedef struct {
141         u32 state[5];
142         u64 count;
143         u8 buffer[SHA1_BLOCK_LENGTH];
144 } SHA1_CTX;
145 void SHA1Init(SHA1_CTX *context);
146 void SHA1Transform(u32 state[5], const u8 buffer[SHA1_BLOCK_LENGTH]);
147 void SHA1Update(SHA1_CTX *context, const u8 *data, size_t len);
148 void SHA1Final(u8 digest[SHA1_DIGEST_LENGTH], SHA1_CTX *context);
149 u8 *sha1(const u8 *data, size_t len, u8 *buf);
150
151 /* libc/string.c */
152 size_t strnlen(const char *str, size_t maxlen);
153 size_t strlen(const char *str);
154 int strcmp(const char *s1, const char *s2);
155 int strncmp(const char *s1, const char *s2, int maxlen);
156 char *strncpy(char *d, const char *s, int n);
157 char *strcpy(char *d, const char *s);
158 char *strncat(char *d, const char *s, int n);
159 char *strchr(const char *s, int c);
160 char *strdup(const char *s);
161 char *strstr(const char *h, const char *n);
162
163 /* i386/coreboot.c */
164 int get_coreboot_info(struct sysinfo_t *info);
165
166 /* i386/sysinfo.c */
167 void lib_get_sysinfo(void);
168
169 /* i386/timer.c */
170 /* Timer functions - defined by each architecture. */
171 unsigned int get_cpu_speed(void);
172 void ndelay(unsigned int n);
173 void udelay(unsigned int n);
174 void mdelay(unsigned int n);
175 void delay(unsigned int n);
176
177 /* i386/util.S */
178 #define abort() halt()
179 void halt(void) __attribute__ ((noreturn));
180
181 #endif