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