blob: 7af19dee06358ce0bf881210b3cd10b2ecfa385f [file] [log] [blame]
Jordan Crousef6145c32008-03-19 23:56:58 +00001/*
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
Uwe Hermann31538632008-08-31 22:10:35 +000030/**
31 * @mainpage
32 *
Jordan Crouse3a48bdc2008-08-28 16:53:24 +000033 * @section intro Introduction
34 * libpayload is a small BSD-licensed static library (a lightweight
35 * implementation of common and useful functions) intended to be used
36 * as a basis for coreboot payloads.
37 *
38 * @section example Example
39 * Here is an example of a very simple payload:
40 * @include sample/hello.c
Jordan Crouse3a48bdc2008-08-28 16:53:24 +000041 */
42
Uwe Hermannfad8c2b2008-04-11 18:01:50 +000043#ifndef _LIBPAYLOAD_H
44#define _LIBPAYLOAD_H
Jordan Crousef6145c32008-03-19 23:56:58 +000045
Jordan Crousef6145c32008-03-19 23:56:58 +000046#include <stddef.h>
47#include <arch/types.h>
48#include <arch/io.h>
Stefan Reinauer99c08562008-08-19 17:49:53 +000049#include <arch/virtual.h>
Uwe Hermanndc69e052008-03-20 01:53:30 +000050#include <sysinfo.h>
Jordan Crousef6145c32008-03-19 23:56:58 +000051#include <stdarg.h>
Jordan Crouse681ec272008-05-07 20:34:02 +000052#include <lar.h>
Uwe Hermann83233d02008-08-04 21:00:49 +000053#include <pci.h>
Jordan Crousef6145c32008-03-19 23:56:58 +000054
55#define MIN(a,b) ((a) < (b) ? (a) : (b))
56#define MAX(a,b) ((a) > (b) ? (a) : (b))
57#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
58
Uwe Hermann39955932008-04-03 23:01:23 +000059#define LITTLE_ENDIAN 1234
60#define BIG_ENDIAN 4321
Uwe Hermann39955932008-04-03 23:01:23 +000061
Uwe Hermannbe504d12008-04-11 20:16:24 +000062#define EXIT_SUCCESS 0
63#define EXIT_FAILURE 1
64
Uwe Hermann4eb50892008-04-07 23:33:50 +000065#define RAND_MAX 0x7fffffff
66
Uwe Hermann31538632008-08-31 22:10:35 +000067/*
68 * Payload information parameters - these are used to pass information
69 * to the entity loading the payload.
70 * Usage: PAYLOAD_INFO(key, value)
71 * Example: PAYLOAD_INFO(name, "CoreInfo!")
Jordan Crousefc697ad2008-05-27 20:06:54 +000072 */
Jordan Crousefc697ad2008-05-27 20:06:54 +000073#define _pstruct(key) __pinfo_ ##key
74#define PAYLOAD_INFO(key, value) \
75static const char _pstruct(key)[] \
76 __attribute__((__used__)) \
77 __attribute__((section(".note.pinfo"),unused)) = #key "=" value
78
Jordan Crouse3a48bdc2008-08-28 16:53:24 +000079/**
80 * @defgroup nvram NVRAM and RTC functions
81 * @{
82 */
Jordan Crousee2ad8062008-08-28 23:10:55 +000083
84#define NVRAM_RTC_SECONDS 0 /**< RTC Seconds offset in CMOS */
85#define NVRAM_RTC_MINUTES 2 /**< RTC Minutes offset in CMOS */
86#define NVRAM_RTC_HOURS 4 /**< RTC Hours offset in CMOS */
87#define NVRAM_RTC_DAY 7 /**< RTC Days offset in CMOS */
88#define NVRAM_RTC_MONTH 8 /**< RTC Month offset in CMOS */
89#define NVRAM_RTC_YEAR 9 /**< RTC Year offset in CMOS */
90#define NVRAM_RTC_FREQ_SELECT 10 /**< RTC Update Status Register */
91#define NVRAM_RTC_UIP 0x80
92
Uwe Hermann31538632008-08-31 22:10:35 +000093/** Broken down time structure */
Jordan Crousee2271432008-04-25 23:11:02 +000094struct tm {
Jordan Crousee2ad8062008-08-28 23:10:55 +000095 int tm_sec; /**< Number of seconds after the minute */
96 int tm_min; /**< Number of minutes after the hour */
97 int tm_hour; /**< Number of hours past midnight */
98 int tm_mday; /**< The day of the month */
99 int tm_mon; /**< The month of the year */
100 int tm_year; /**< The number of years since 1900 */
101 int tm_wday; /**< The day of the week */
102 int tm_yday; /**< The number of days since January 1 */
103 int tm_isdst; /**< A flag indicating daylight savings time */
Jordan Crousee2271432008-04-25 23:11:02 +0000104};
Uwe Hermann8cc38d22008-03-27 23:26:40 +0000105
Uwe Hermannc16d24e2008-03-31 15:17:39 +0000106u8 nvram_read(u8 addr);
107void nvram_write(u8 val, u8 addr);
Jordan Crousee2271432008-04-25 23:11:02 +0000108int nvram_updating(void);
109void rtc_read_clock(struct tm *tm);
Jordan Crouse3a48bdc2008-08-28 16:53:24 +0000110/** @} */
Uwe Hermann8cc38d22008-03-27 23:26:40 +0000111
Jordan Crouse3a48bdc2008-08-28 16:53:24 +0000112/**
113 * @defgroup input Device functions
114 * @{ @}
115 */
116
117/**
118 * @defgroup keyboard Keyboard functions
119 * @ingroup input
120 * @{
121 */
Jordan Crouse63f181f2008-04-25 23:09:39 +0000122void keyboard_init(void);
Uwe Hermanndc69e052008-03-20 01:53:30 +0000123int keyboard_havechar(void);
124unsigned char keyboard_get_scancode(void);
125int keyboard_getchar(void);
Jordan Crouse3a48bdc2008-08-28 16:53:24 +0000126/** @} */
Jordan Crousef6145c32008-03-19 23:56:58 +0000127
Jordan Crouse3a48bdc2008-08-28 16:53:24 +0000128/**
129 * @defgroup serial Serial functions
130 * @ingroup input
131 * @{
132 */
Uwe Hermanndc69e052008-03-20 01:53:30 +0000133void serial_init(void);
134void serial_putchar(unsigned char c);
135int serial_havechar(void);
136int serial_getchar(void);
Jordan Crouse3b470652008-06-20 00:01:42 +0000137void serial_clear(void);
138void serial_start_bold(void);
139void serial_end_bold(void);
Ulf Jordanb4d4bac2008-08-11 20:34:28 +0000140void serial_start_altcharset(void);
141void serial_end_altcharset(void);
Ulf Jordand57a6802008-09-03 19:59:44 +0000142void serial_set_color(short fg, short bg);
Jordan Crouse3b470652008-06-20 00:01:42 +0000143void serial_set_cursor(int y, int x);
Jordan Crouse3a48bdc2008-08-28 16:53:24 +0000144/** @} */
Jordan Crouse3b470652008-06-20 00:01:42 +0000145
Jordan Crouse3a48bdc2008-08-28 16:53:24 +0000146/**
147 * @defgroup speaker Speaker functions
148 * @ingroup input
149 * @{
150 */
Uwe Hermannfad8c2b2008-04-11 18:01:50 +0000151void speaker_enable(u16 freq);
152void speaker_disable(void);
153void speaker_tone(u16 freq, unsigned int duration);
Jordan Crouse3a48bdc2008-08-28 16:53:24 +0000154/** @} */
Uwe Hermannfad8c2b2008-04-11 18:01:50 +0000155
Jordan Crouse3a48bdc2008-08-28 16:53:24 +0000156/**
157 * @defgroup video Video functions
158 * @ingroup input
159 * @{
160 */
Jordan Crouse30939bd2008-04-10 22:49:02 +0000161int video_console_init(void);
162void video_console_putchar(unsigned int ch);
163void video_console_putc(u8 row, u8 col, unsigned int ch);
164void video_console_clear(void);
165void video_console_cursor_enable(int state);
Stefan Reinauer59fb9a2b2008-08-19 17:44:49 +0000166void video_console_get_cursor(unsigned int *x, unsigned int *y, unsigned int *en);
167void video_console_set_cursor(unsigned int cursorx, unsigned int cursory);
Jordan Crouse3a48bdc2008-08-28 16:53:24 +0000168/** @} */
Stefan Reinauer59fb9a2b2008-08-19 17:44:49 +0000169
170/* drivers/option.c */
171int get_option(void *dest, char *name);
Uwe Hermanndc69e052008-03-20 01:53:30 +0000172
Jordan Crouse3a48bdc2008-08-28 16:53:24 +0000173/**
174 * @defgroup console Console functions
175 * @{
176 */
Uwe Hermanndc69e052008-03-20 01:53:30 +0000177void console_init(void);
Jordan Crousef6145c32008-03-19 23:56:58 +0000178int putchar(int c);
Uwe Hermanndc69e052008-03-20 01:53:30 +0000179int puts(const char *s);
180int havekey(void);
181int getchar(void);
Jordan Crouse672d0ae2008-04-08 23:21:33 +0000182int getchar_timeout(int *ms);
Uwe Hermanndc69e052008-03-20 01:53:30 +0000183
Jordan Crousef6145c32008-03-19 23:56:58 +0000184extern int last_putchar;
185
186#define havechar havekey
Jordan Crouse3a48bdc2008-08-28 16:53:24 +0000187/** @} */
Jordan Crousef6145c32008-03-19 23:56:58 +0000188
Jordan Crouse3a48bdc2008-08-28 16:53:24 +0000189/**
Uwe Hermann31538632008-08-31 22:10:35 +0000190 * @defgroup ctype Character type functions
Jordan Crouse3a48bdc2008-08-28 16:53:24 +0000191 * @{
192 */
Uwe Hermann72199bc2008-04-11 19:43:55 +0000193int isalnum(int c);
194int isalpha(int c);
195int isascii(int c);
196int isblank(int c);
197int iscntrl(int c);
Jordan Crousef6145c32008-03-19 23:56:58 +0000198int isdigit(int c);
Uwe Hermann72199bc2008-04-11 19:43:55 +0000199int isgraph(int c);
200int islower(int c);
201int isprint(int c);
202int ispunct(int c);
203int isspace(int c);
204int isupper(int c);
205int isxdigit(int c);
Jordan Crousef6145c32008-03-19 23:56:58 +0000206int tolower(int c);
Uwe Hermann72199bc2008-04-11 19:43:55 +0000207int toupper(int c);
Jordan Crouse3a48bdc2008-08-28 16:53:24 +0000208/** @} */
Jordan Crousef6145c32008-03-19 23:56:58 +0000209
Jordan Crouse3a48bdc2008-08-28 16:53:24 +0000210/**
Uwe Hermann31538632008-08-31 22:10:35 +0000211 * @defgroup ipchecksum IP checksum functions
Jordan Crouse3a48bdc2008-08-28 16:53:24 +0000212 * @{
213 */
Stefan Reinauer11e45cd2008-08-16 15:16:36 +0000214unsigned short ipchksum(const void *ptr, unsigned long nbytes);
Jordan Crouse3a48bdc2008-08-28 16:53:24 +0000215/** @} */
Uwe Hermanndc69e052008-03-20 01:53:30 +0000216
Jordan Crouse3a48bdc2008-08-28 16:53:24 +0000217/**
Uwe Hermann31538632008-08-31 22:10:35 +0000218 * @defgroup malloc Memory allocation functions
Jordan Crouse3a48bdc2008-08-28 16:53:24 +0000219 * @{
220 */
Jordan Crousef6145c32008-03-19 23:56:58 +0000221void free(void *ptr);
Uwe Hermanndc69e052008-03-20 01:53:30 +0000222void *malloc(size_t size);
Jordan Crousef6145c32008-03-19 23:56:58 +0000223void *calloc(size_t nmemb, size_t size);
224void *realloc(void *ptr, size_t size);
Patrick Georgi5ccfa1a2008-09-02 15:49:32 +0000225void *memalign(size_t align, size_t size);
Jordan Crouse3a48bdc2008-08-28 16:53:24 +0000226/** @} */
Jordan Crousef6145c32008-03-19 23:56:58 +0000227
Jordan Crouse3a48bdc2008-08-28 16:53:24 +0000228/**
Uwe Hermann31538632008-08-31 22:10:35 +0000229 * @defgroup exec Execution functions
Jordan Crouse3a48bdc2008-08-28 16:53:24 +0000230 * @{
231 */
Jordan Crouse9dac1b42008-05-20 20:10:49 +0000232int exec(long addr, int argc, char **argv);
Jordan Crouse3a48bdc2008-08-28 16:53:24 +0000233/** @} */
Jordan Crouse9dac1b42008-05-20 20:10:49 +0000234
Jordan Crouse3a48bdc2008-08-28 16:53:24 +0000235/**
Uwe Hermann31538632008-08-31 22:10:35 +0000236 * @defgroup misc Misc functions
Jordan Crouse3a48bdc2008-08-28 16:53:24 +0000237 * @{
238 */
Uwe Hermann8cc38d22008-03-27 23:26:40 +0000239int bcd2dec(int b);
240int dec2bcd(int d);
Uwe Hermannb1033452008-04-11 18:38:04 +0000241int abs(int j);
242long int labs(long int j);
243long long int llabs(long long int j);
244u8 bin2hex(u8 b);
245u8 hex2bin(u8 h);
Uwe Hermann31538632008-08-31 22:10:35 +0000246void fatal(const char *msg) __attribute__ ((noreturn));
Jordan Crouse3a48bdc2008-08-28 16:53:24 +0000247/** @} */
Uwe Hermann8cc38d22008-03-27 23:26:40 +0000248
Jordan Crouse3a48bdc2008-08-28 16:53:24 +0000249/**
Uwe Hermann31538632008-08-31 22:10:35 +0000250 * @defgroup memory Memory manipulation functions
Jordan Crouse3a48bdc2008-08-28 16:53:24 +0000251 * @{
252 */
Jordan Crousef6145c32008-03-19 23:56:58 +0000253void *memset(void *s, int c, size_t n);
Uwe Hermanndc69e052008-03-20 01:53:30 +0000254void *memcpy(void *dst, const void *src, size_t n);
Jordan Crousef6145c32008-03-19 23:56:58 +0000255void *memmove(void *dst, const void *src, size_t n);
Ulf Jordan68285692008-08-09 19:34:56 +0000256int memcmp(const void *s1, const void *s2, size_t len);
Jordan Crouse3a48bdc2008-08-28 16:53:24 +0000257/** @} */
Jordan Crousef6145c32008-03-19 23:56:58 +0000258
Jordan Crouse3a48bdc2008-08-28 16:53:24 +0000259/**
Uwe Hermann31538632008-08-31 22:10:35 +0000260 * @defgroup printf Print functions
Jordan Crouse3a48bdc2008-08-28 16:53:24 +0000261 * @{
262 */
Uwe Hermann0a896252008-04-02 12:35:45 +0000263int snprintf(char *str, size_t size, const char *fmt, ...);
Jordan Crousef6145c32008-03-19 23:56:58 +0000264int sprintf(char *str, const char *fmt, ...);
265int vsnprintf(char *str, size_t size, const char *fmt, va_list ap);
266int vsprintf(char *str, const char *fmt, va_list ap);
267int printf(const char *fmt, ...);
268int vprintf(const char *fmt, va_list ap);
Jordan Crouse3a48bdc2008-08-28 16:53:24 +0000269/** @} */
Jordan Crousef6145c32008-03-19 23:56:58 +0000270
Jordan Crouse3a48bdc2008-08-28 16:53:24 +0000271/**
Uwe Hermann31538632008-08-31 22:10:35 +0000272 * @defgroup rand Random number generator functions
Jordan Crouse3a48bdc2008-08-28 16:53:24 +0000273 * @{
274 */
Uwe Hermannc5a78ac2008-04-08 23:38:15 +0000275int rand_r(unsigned int *seed);
276int rand(void);
277void srand(unsigned int seed);
Jordan Crouse3a48bdc2008-08-28 16:53:24 +0000278/** @} */
Uwe Hermannc5a78ac2008-04-08 23:38:15 +0000279
Jordan Crouse3a48bdc2008-08-28 16:53:24 +0000280/**
Uwe Hermann31538632008-08-31 22:10:35 +0000281 * @defgroup hash Hashing functions
Jordan Crouse3a48bdc2008-08-28 16:53:24 +0000282 * @{
283 */
Uwe Hermann39955932008-04-03 23:01:23 +0000284#define SHA1_BLOCK_LENGTH 64
285#define SHA1_DIGEST_LENGTH 20
286typedef struct {
287 u32 state[5];
288 u64 count;
289 u8 buffer[SHA1_BLOCK_LENGTH];
290} SHA1_CTX;
291void SHA1Init(SHA1_CTX *context);
292void SHA1Transform(u32 state[5], const u8 buffer[SHA1_BLOCK_LENGTH]);
293void SHA1Update(SHA1_CTX *context, const u8 *data, size_t len);
294void SHA1Final(u8 digest[SHA1_DIGEST_LENGTH], SHA1_CTX *context);
295u8 *sha1(const u8 *data, size_t len, u8 *buf);
Jordan Crouse3a48bdc2008-08-28 16:53:24 +0000296/** @} */
Uwe Hermann39955932008-04-03 23:01:23 +0000297
Jordan Crouse3a48bdc2008-08-28 16:53:24 +0000298/**
Uwe Hermann31538632008-08-31 22:10:35 +0000299 * @defgroup string String functions
Jordan Crouse3a48bdc2008-08-28 16:53:24 +0000300 * @{
301 */
Uwe Hermanndc69e052008-03-20 01:53:30 +0000302size_t strnlen(const char *str, size_t maxlen);
303size_t strlen(const char *str);
Jordan Crousef6145c32008-03-19 23:56:58 +0000304int strcmp(const char *s1, const char *s2);
Stefan Reinauer3b9d1b82008-08-26 21:51:04 +0000305int strncmp(const char *s1, const char *s2, size_t maxlen);
306char *strncpy(char *d, const char *s, size_t n);
Uwe Hermanndc69e052008-03-20 01:53:30 +0000307char *strcpy(char *d, const char *s);
Stefan Reinauer3b9d1b82008-08-26 21:51:04 +0000308char *strncat(char *d, const char *s, size_t n);
Jordan Crousef6145c32008-03-19 23:56:58 +0000309char *strchr(const char *s, int c);
Uwe Hermanndc69e052008-03-20 01:53:30 +0000310char *strdup(const char *s);
311char *strstr(const char *h, const char *n);
Jordan Crouse3a48bdc2008-08-28 16:53:24 +0000312/** @} */
Jordan Crousef6145c32008-03-19 23:56:58 +0000313
Jordan Crouse3a48bdc2008-08-28 16:53:24 +0000314/**
Uwe Hermann31538632008-08-31 22:10:35 +0000315 * @defgroup time Time functions
Jordan Crouse3a48bdc2008-08-28 16:53:24 +0000316 * @{
317 */
Jordan Crousee2ad8062008-08-28 23:10:55 +0000318
Uwe Hermann31538632008-08-31 22:10:35 +0000319/** System time structure */
Jordan Crousee2271432008-04-25 23:11:02 +0000320struct timeval {
Jordan Crousee2ad8062008-08-28 23:10:55 +0000321 time_t tv_sec; /**< Seconds */
322 suseconds_t tv_usec; /**< Microseconds */
Jordan Crousee2271432008-04-25 23:11:02 +0000323};
324
325int gettimeofday(struct timeval *tv, void *tz);
Jordan Crouse3a48bdc2008-08-28 16:53:24 +0000326/** @} */
Jordan Crousee2271432008-04-25 23:11:02 +0000327
Jordan Crouse3a48bdc2008-08-28 16:53:24 +0000328/**
Uwe Hermann31538632008-08-31 22:10:35 +0000329 * @defgroup lar LAR functions
Jordan Crouse3a48bdc2008-08-28 16:53:24 +0000330 * @{
331 */
Jordan Crousee2ad8062008-08-28 23:10:55 +0000332
Uwe Hermann31538632008-08-31 22:10:35 +0000333/** LAR file header */
Jordan Crouse681ec272008-05-07 20:34:02 +0000334struct LAR {
Uwe Hermann31538632008-08-31 22:10:35 +0000335 void *start; /**< Location of the LAR in memory */
Jordan Crousee2ad8062008-08-28 23:10:55 +0000336 int cindex; /**< Next file to return in readlar() */
337 int count; /**< Number of entries in the header cache */
338 int alloc; /**< Number of slots in the header cache */
339 int eof; /**< Last entry in the header cache */
340 void **headers; /**< Pointer to the header cache */
Jordan Crouse681ec272008-05-07 20:34:02 +0000341};
342
Uwe Hermann31538632008-08-31 22:10:35 +0000343/** A structure representing the next LAR entry */
Jordan Crouse681ec272008-05-07 20:34:02 +0000344struct larent {
Jordan Crousee2ad8062008-08-28 23:10:55 +0000345 u8 name[LAR_MAX_PATHLEN]; /**< The name of the next LAR entry */
Jordan Crouse681ec272008-05-07 20:34:02 +0000346};
347
Uwe Hermann31538632008-08-31 22:10:35 +0000348/** A structure containing information about a LAR file */
Jordan Crouse681ec272008-05-07 20:34:02 +0000349struct larstat {
Jordan Crousee2ad8062008-08-28 23:10:55 +0000350 u32 len; /**< Length of the file in the LAR */
351 u32 reallen; /**< Length of the uncompressed file */
352 u32 checksum; /**< Checksum of the uncompressed file */
353 u32 compchecksum; /**< Checksum of the compressed file in the LAR */
354 u32 offset; /**< Offset of the file in the LAR */
355 u32 compression; /**< Compression type of the file */
356 u64 entry; /**< Entry point of the file for executables */
357 u64 loadaddress; /**< Address in memory to put the uncompressed file */
Jordan Crouse681ec272008-05-07 20:34:02 +0000358};
359
Uwe Hermann31538632008-08-31 22:10:35 +0000360/** A structure representing a LAR file */
Jordan Crouse681ec272008-05-07 20:34:02 +0000361struct LFILE {
Jordan Crousee2ad8062008-08-28 23:10:55 +0000362 struct LAR *lar; /**< Pointer to the LAR struct */
363 struct lar_header *header; /**< Pointer to the header struct */
364 u32 size; /**< Size of the file */
365 void *start; /**< Start of the file in memory */
366 u32 offset; /**< Offset of the file in the LAR */
Jordan Crouse681ec272008-05-07 20:34:02 +0000367};
368
369struct LAR *openlar(void *addr);
370int closelar(struct LAR *lar);
371struct larent *readlar(struct LAR *lar);
372void rewindlar(struct LAR *lar);
373int larstat(struct LAR *lar, const char *path, struct larstat *buf);
Jordan Crouse50698082008-05-20 20:09:42 +0000374void *larfptr(struct LAR *lar, const char *filename);
Jordan Crouse9e734c22008-05-27 19:57:53 +0000375int lfverify(struct LAR *lar, const char *filename);
Uwe Hermann31538632008-08-31 22:10:35 +0000376struct LFILE *lfopen(struct LAR *lar, const char *filename);
Jordan Crouse681ec272008-05-07 20:34:02 +0000377int lfread(void *ptr, size_t size, size_t nmemb, struct LFILE *stream);
378
Uwe Hermann31538632008-08-31 22:10:35 +0000379#define SEEK_SET 0 /**< The seek offset is absolute. */
380#define SEEK_CUR 1 /**< The seek offset is against the current position. */
381#define SEEK_END 2 /**< The seek offset is against the end of the file. */
Jordan Crouse681ec272008-05-07 20:34:02 +0000382
383int lfseek(struct LFILE *stream, long offset, int whence);
384int lfclose(struct LFILE *file);
Jordan Crouse3a48bdc2008-08-28 16:53:24 +0000385/** @} */
Jordan Crouse681ec272008-05-07 20:34:02 +0000386
Jordan Crouse3a48bdc2008-08-28 16:53:24 +0000387/**
Uwe Hermann31538632008-08-31 22:10:35 +0000388 * @defgroup arch Architecture specific functions
389 * This module contains global architecture specific functions.
Jordan Crouseb7461782008-08-28 23:12:22 +0000390 * All architectures are expected to define these functions.
Jordan Crouse3a48bdc2008-08-28 16:53:24 +0000391 * @{
392 */
Uwe Hermanndc69e052008-03-20 01:53:30 +0000393int get_coreboot_info(struct sysinfo_t *info);
Jordan Crousef6145c32008-03-19 23:56:58 +0000394
Uwe Hermanndc69e052008-03-20 01:53:30 +0000395void lib_get_sysinfo(void);
396
Uwe Hermann661e3802008-03-21 18:37:23 +0000397/* Timer functions - defined by each architecture. */
Uwe Hermanndc69e052008-03-20 01:53:30 +0000398unsigned int get_cpu_speed(void);
399void ndelay(unsigned int n);
Jordan Crouse234e87f2008-04-10 22:50:44 +0000400void udelay(unsigned int n);
Uwe Hermanndc69e052008-03-20 01:53:30 +0000401void mdelay(unsigned int n);
402void delay(unsigned int n);
403
Jordan Crouseb7461782008-08-28 23:12:22 +0000404#define abort() halt() /**< Alias for the halt() function */
405
406/**
Uwe Hermann31538632008-08-31 22:10:35 +0000407 * Stop execution and halt the processor (this function does not return).
Jordan Crouseb7461782008-08-28 23:12:22 +0000408 */
Jordan Crousef6145c32008-03-19 23:56:58 +0000409void halt(void) __attribute__ ((noreturn));
Jordan Crouse3a48bdc2008-08-28 16:53:24 +0000410/** @} */
Stefan Reinauer6e51cee2008-08-19 17:47:18 +0000411
Jordan Crouse3a48bdc2008-08-28 16:53:24 +0000412/**
Uwe Hermann31538632008-08-31 22:10:35 +0000413 * @defgroup readline Readline functions
414 * This interface provides a simple implementation of the standard readline()
415 * and getline() functions. They read a line of input from the console.
Jordan Crouse3a48bdc2008-08-28 16:53:24 +0000416 * @{
417 */
Uwe Hermann31538632008-08-31 22:10:35 +0000418char *readline(const char *prompt);
Jakob Bornecrantzb0d3e712008-08-23 12:17:46 +0000419int getline(char *buffer, int len);
Jordan Crouse3a48bdc2008-08-28 16:53:24 +0000420/** @} */
Jordan Crousef6145c32008-03-19 23:56:58 +0000421
Jordan Crousef6145c32008-03-19 23:56:58 +0000422#endif