Add missing #include.
[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 #include <lar.h>
40 #include <pci.h>
41
42 #define MIN(a,b) ((a) < (b) ? (a) : (b))
43 #define MAX(a,b) ((a) > (b) ? (a) : (b))
44 #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
45
46 #define LITTLE_ENDIAN   1234
47 #define BIG_ENDIAN      4321
48 #ifdef CONFIG_TARGET_I386
49 #define BYTE_ORDER      LITTLE_ENDIAN
50 #else
51 #define BYTE_ORDER      BIG_ENDIAN
52 #endif
53
54 #define EXIT_SUCCESS 0
55 #define EXIT_FAILURE 1
56
57 #define RAND_MAX 0x7fffffff
58
59 /* Payload information parameters - these are used to pass information
60  * to the entity loading the payload
61  * Usage:  PAYLOAD_INFO(key, value)
62  * Example:  PAYLOAD_INFO(name, "CoreInfo!")
63  */
64
65 #define _pstruct(key) __pinfo_ ##key
66 #define PAYLOAD_INFO(key, value)                                        \
67 static const char _pstruct(key)[]                                        \
68   __attribute__((__used__))                                              \
69   __attribute__((section(".note.pinfo"),unused)) = #key "=" value
70
71 /* Some NVRAM byte definitions */
72 #define NVRAM_RTC_SECONDS        0
73 #define NVRAM_RTC_MINUTES        2
74 #define NVRAM_RTC_HOURS          4
75 #define NVRAM_RTC_DAY            7
76 #define NVRAM_RTC_MONTH          8
77 #define NVRAM_RTC_YEAR           9
78 #define NVRAM_RTC_FREQ_SELECT    10
79 #define  NVRAM_RTC_UIP           0x80
80
81 struct tm {
82         int tm_sec;
83         int tm_min;
84         int tm_hour;
85         int tm_mday;
86         int tm_mon;
87         int tm_year;
88         int tm_wday;
89         int tm_yday;
90         int tm_isdst;
91 };
92
93 /* drivers/nvram.c */
94 u8 nvram_read(u8 addr);
95 void nvram_write(u8 val, u8 addr);
96 int nvram_updating(void);
97 void rtc_read_clock(struct tm *tm);
98
99 /* drivers/keyboard.c */
100 void keyboard_init(void);
101 int keyboard_havechar(void);
102 unsigned char keyboard_get_scancode(void);
103 int keyboard_getchar(void);
104
105 /* drivers/serial.c */
106 void serial_init(void);
107 void serial_putchar(unsigned char c);
108 int serial_havechar(void);
109 int serial_getchar(void);
110
111 void serial_clear(void);
112 void serial_start_bold(void);
113 void serial_end_bold(void);
114 void serial_set_cursor(int y, int x);
115
116 /* drivers/speaker.c */
117 void speaker_enable(u16 freq);
118 void speaker_disable(void);
119 void speaker_tone(u16 freq, unsigned int duration);
120
121 /* video/video.c */
122 int video_console_init(void);
123 void video_console_putchar(unsigned int ch);
124 void video_console_putc(u8 row, u8 col, unsigned int ch);
125 void video_console_clear(void);
126 void video_console_cursor_enable(int state);
127
128 /* libc/console.c */
129 void console_init(void);
130 int putchar(int c);
131 int puts(const char *s);
132 int havekey(void);
133 int getchar(void);
134 int getchar_timeout(int *ms);
135
136 extern int last_putchar;
137
138 #define havechar havekey
139
140 /* libc/ctype.c */
141 int isalnum(int c);
142 int isalpha(int c);
143 int isascii(int c);
144 int isblank(int c);
145 int iscntrl(int c);
146 int isdigit(int c);
147 int isgraph(int c);
148 int islower(int c);
149 int isprint(int c);
150 int ispunct(int c);
151 int isspace(int c);
152 int isupper(int c);
153 int isxdigit(int c);
154 int tolower(int c);
155 int toupper(int c);
156
157 /* libc/ipchecksum.c */
158 unsigned short ipchksum(const unsigned short *ptr, unsigned long nbytes);
159
160 /* libc/malloc.c */
161 void free(void *ptr);
162 void *malloc(size_t size);
163 void *calloc(size_t nmemb, size_t size);
164 void *realloc(void *ptr, size_t size);
165
166 /* libc/exec.c */
167 int exec(long addr, int argc, char **argv);
168
169 /* libc/lib.c */
170 int bcd2dec(int b);
171 int dec2bcd(int d);
172 int abs(int j);
173 long int labs(long int j);
174 long long int llabs(long long int j);
175 u8 bin2hex(u8 b);
176 u8 hex2bin(u8 h);
177
178 /* libc/memory.c */
179 void *memset(void *s, int c, size_t n);
180 void *memcpy(void *dst, const void *src, size_t n);
181 void *memmove(void *dst, const void *src, size_t n);
182 int memcmp(const char *s1, const char *s2, size_t len);
183
184 /* libc/printf.c */
185 int snprintf(char *str, size_t size, const char *fmt, ...);
186 int sprintf(char *str, const char *fmt, ...);
187 int vsnprintf(char *str, size_t size, const char *fmt, va_list ap);
188 int vsprintf(char *str, const char *fmt, va_list ap);
189 int printf(const char *fmt, ...);
190 int vprintf(const char *fmt, va_list ap);
191
192 /* libc/rand.c */
193 int rand_r(unsigned int *seed);
194 int rand(void);
195 void srand(unsigned int seed);
196
197 /* libc/sha1.c */
198 #define SHA1_BLOCK_LENGTH       64
199 #define SHA1_DIGEST_LENGTH      20
200 typedef struct {
201         u32 state[5];
202         u64 count;
203         u8 buffer[SHA1_BLOCK_LENGTH];
204 } SHA1_CTX;
205 void SHA1Init(SHA1_CTX *context);
206 void SHA1Transform(u32 state[5], const u8 buffer[SHA1_BLOCK_LENGTH]);
207 void SHA1Update(SHA1_CTX *context, const u8 *data, size_t len);
208 void SHA1Final(u8 digest[SHA1_DIGEST_LENGTH], SHA1_CTX *context);
209 u8 *sha1(const u8 *data, size_t len, u8 *buf);
210
211 /* libc/string.c */
212 size_t strnlen(const char *str, size_t maxlen);
213 size_t strlen(const char *str);
214 int strcmp(const char *s1, const char *s2);
215 int strncmp(const char *s1, const char *s2, int maxlen);
216 char *strncpy(char *d, const char *s, int n);
217 char *strcpy(char *d, const char *s);
218 char *strncat(char *d, const char *s, int n);
219 char *strchr(const char *s, int c);
220 char *strdup(const char *s);
221 char *strstr(const char *h, const char *n);
222
223 /* libc/time.c */
224
225 struct timeval {
226         time_t tv_sec;
227         suseconds_t tv_usec;
228 };
229
230 int gettimeofday(struct timeval *tv, void *tz);
231
232 /* libc/lar.c */
233
234 struct LAR {
235         void * start;
236         int cindex;
237         int count;
238         int alloc;
239         int eof;
240         void **headers;
241 };
242
243 struct larent {
244         u8 name[LAR_MAX_PATHLEN];
245 };
246
247 struct larstat {
248         u32 len;
249         u32 reallen;
250         u32 checksum;
251         u32 compchecksum;
252         u32 offset;
253         u32 compression;
254         u64 entry;
255         u64 loadaddress;
256 };
257
258 struct LFILE {
259         struct LAR *lar;
260         struct lar_header *header;
261         u32 size;
262         void *start;
263         u32 offset;
264 };
265
266 struct LAR *openlar(void *addr);
267 int closelar(struct LAR *lar);
268 struct larent *readlar(struct LAR *lar);
269 void rewindlar(struct LAR *lar);
270 int larstat(struct LAR *lar, const char *path, struct larstat *buf);
271 void *larfptr(struct LAR *lar, const char *filename);
272 int lfverify(struct LAR *lar, const char *filename);
273 struct LFILE * lfopen(struct LAR *lar, const char *filename);
274 int lfread(void *ptr, size_t size, size_t nmemb, struct LFILE *stream);
275
276 #define SEEK_SET 0
277 #define SEEK_CUR 1
278 #define SEEK_END 2
279
280 int lfseek(struct LFILE *stream, long offset, int whence);
281 int lfclose(struct LFILE *file);
282
283 /* i386/coreboot.c */
284 int get_coreboot_info(struct sysinfo_t *info);
285
286 /* i386/sysinfo.c */
287 void lib_get_sysinfo(void);
288
289 /* i386/timer.c */
290 /* Timer functions - defined by each architecture. */
291 unsigned int get_cpu_speed(void);
292 void ndelay(unsigned int n);
293 void udelay(unsigned int n);
294 void mdelay(unsigned int n);
295 void delay(unsigned int n);
296
297 /* i386/util.S */
298 #define abort() halt()
299 void halt(void) __attribute__ ((noreturn));
300
301 #endif