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