Jordan Crouse | f6145c3 | 2008-03-19 23:56:58 +0000 | [diff] [blame] | 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 | |
Uwe Hermann | 3153863 | 2008-08-31 22:10:35 +0000 | [diff] [blame] | 30 | /** |
| 31 | * @mainpage |
| 32 | * |
Jordan Crouse | 3a48bdc | 2008-08-28 16:53:24 +0000 | [diff] [blame] | 33 | * @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 Crouse | 3a48bdc | 2008-08-28 16:53:24 +0000 | [diff] [blame] | 41 | */ |
| 42 | |
Uwe Hermann | fad8c2b | 2008-04-11 18:01:50 +0000 | [diff] [blame] | 43 | #ifndef _LIBPAYLOAD_H |
| 44 | #define _LIBPAYLOAD_H |
Jordan Crouse | f6145c3 | 2008-03-19 23:56:58 +0000 | [diff] [blame] | 45 | |
Stefan Reinauer | e5d30b7 | 2010-03-25 22:15:19 +0000 | [diff] [blame] | 46 | #include <libpayload-config.h> |
Patrick Georgi | 980a69b | 2010-06-24 11:16:10 +0000 | [diff] [blame] | 47 | #include <ctype.h> |
Jordan Crouse | f6145c3 | 2008-03-19 23:56:58 +0000 | [diff] [blame] | 48 | #include <stddef.h> |
Patrick Georgi | 980a69b | 2010-06-24 11:16:10 +0000 | [diff] [blame] | 49 | #include <stdio.h> |
| 50 | #include <stdarg.h> |
| 51 | #include <stdlib.h> |
| 52 | #include <string.h> |
Jordan Crouse | f6145c3 | 2008-03-19 23:56:58 +0000 | [diff] [blame] | 53 | #include <arch/types.h> |
| 54 | #include <arch/io.h> |
Stefan Reinauer | 99c0856 | 2008-08-19 17:49:53 +0000 | [diff] [blame] | 55 | #include <arch/virtual.h> |
Uwe Hermann | dc69e05 | 2008-03-20 01:53:30 +0000 | [diff] [blame] | 56 | #include <sysinfo.h> |
Uwe Hermann | 83233d0 | 2008-08-04 21:00:49 +0000 | [diff] [blame] | 57 | #include <pci.h> |
Stefan Reinauer | e5d30b7 | 2010-03-25 22:15:19 +0000 | [diff] [blame] | 58 | #ifdef CONFIG_LAR |
| 59 | #include <lar.h> |
| 60 | #endif |
Jordan Crouse | f6145c3 | 2008-03-19 23:56:58 +0000 | [diff] [blame] | 61 | |
| 62 | #define MIN(a,b) ((a) < (b) ? (a) : (b)) |
| 63 | #define MAX(a,b) ((a) > (b) ? (a) : (b)) |
| 64 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) |
| 65 | |
Uwe Hermann | 3995593 | 2008-04-03 23:01:23 +0000 | [diff] [blame] | 66 | #define LITTLE_ENDIAN 1234 |
| 67 | #define BIG_ENDIAN 4321 |
Uwe Hermann | 3995593 | 2008-04-03 23:01:23 +0000 | [diff] [blame] | 68 | |
Uwe Hermann | be504d1 | 2008-04-11 20:16:24 +0000 | [diff] [blame] | 69 | #define EXIT_SUCCESS 0 |
| 70 | #define EXIT_FAILURE 1 |
| 71 | |
Uwe Hermann | 4eb5089 | 2008-04-07 23:33:50 +0000 | [diff] [blame] | 72 | #define RAND_MAX 0x7fffffff |
| 73 | |
Jordan Crouse | 20c9cf1 | 2008-10-20 16:51:43 +0000 | [diff] [blame] | 74 | #define MAX_ARGC_COUNT 10 |
| 75 | |
Uwe Hermann | 3153863 | 2008-08-31 22:10:35 +0000 | [diff] [blame] | 76 | /* |
| 77 | * Payload information parameters - these are used to pass information |
| 78 | * to the entity loading the payload. |
| 79 | * Usage: PAYLOAD_INFO(key, value) |
| 80 | * Example: PAYLOAD_INFO(name, "CoreInfo!") |
Jordan Crouse | fc697ad | 2008-05-27 20:06:54 +0000 | [diff] [blame] | 81 | */ |
Jordan Crouse | fc697ad | 2008-05-27 20:06:54 +0000 | [diff] [blame] | 82 | #define _pstruct(key) __pinfo_ ##key |
| 83 | #define PAYLOAD_INFO(key, value) \ |
| 84 | static const char _pstruct(key)[] \ |
| 85 | __attribute__((__used__)) \ |
| 86 | __attribute__((section(".note.pinfo"),unused)) = #key "=" value |
| 87 | |
Jordan Crouse | 3a48bdc | 2008-08-28 16:53:24 +0000 | [diff] [blame] | 88 | /** |
| 89 | * @defgroup nvram NVRAM and RTC functions |
| 90 | * @{ |
| 91 | */ |
Jordan Crouse | e2ad806 | 2008-08-28 23:10:55 +0000 | [diff] [blame] | 92 | |
| 93 | #define NVRAM_RTC_SECONDS 0 /**< RTC Seconds offset in CMOS */ |
| 94 | #define NVRAM_RTC_MINUTES 2 /**< RTC Minutes offset in CMOS */ |
| 95 | #define NVRAM_RTC_HOURS 4 /**< RTC Hours offset in CMOS */ |
| 96 | #define NVRAM_RTC_DAY 7 /**< RTC Days offset in CMOS */ |
| 97 | #define NVRAM_RTC_MONTH 8 /**< RTC Month offset in CMOS */ |
| 98 | #define NVRAM_RTC_YEAR 9 /**< RTC Year offset in CMOS */ |
| 99 | #define NVRAM_RTC_FREQ_SELECT 10 /**< RTC Update Status Register */ |
| 100 | #define NVRAM_RTC_UIP 0x80 |
| 101 | |
Uwe Hermann | 3153863 | 2008-08-31 22:10:35 +0000 | [diff] [blame] | 102 | /** Broken down time structure */ |
Jordan Crouse | e227143 | 2008-04-25 23:11:02 +0000 | [diff] [blame] | 103 | struct tm { |
Jordan Crouse | e2ad806 | 2008-08-28 23:10:55 +0000 | [diff] [blame] | 104 | int tm_sec; /**< Number of seconds after the minute */ |
| 105 | int tm_min; /**< Number of minutes after the hour */ |
| 106 | int tm_hour; /**< Number of hours past midnight */ |
| 107 | int tm_mday; /**< The day of the month */ |
| 108 | int tm_mon; /**< The month of the year */ |
| 109 | int tm_year; /**< The number of years since 1900 */ |
| 110 | int tm_wday; /**< The day of the week */ |
| 111 | int tm_yday; /**< The number of days since January 1 */ |
| 112 | int tm_isdst; /**< A flag indicating daylight savings time */ |
Jordan Crouse | e227143 | 2008-04-25 23:11:02 +0000 | [diff] [blame] | 113 | }; |
Uwe Hermann | 8cc38d2 | 2008-03-27 23:26:40 +0000 | [diff] [blame] | 114 | |
Uwe Hermann | c16d24e | 2008-03-31 15:17:39 +0000 | [diff] [blame] | 115 | u8 nvram_read(u8 addr); |
| 116 | void nvram_write(u8 val, u8 addr); |
Jordan Crouse | e227143 | 2008-04-25 23:11:02 +0000 | [diff] [blame] | 117 | int nvram_updating(void); |
| 118 | void rtc_read_clock(struct tm *tm); |
Jordan Crouse | 3a48bdc | 2008-08-28 16:53:24 +0000 | [diff] [blame] | 119 | /** @} */ |
Uwe Hermann | 8cc38d2 | 2008-03-27 23:26:40 +0000 | [diff] [blame] | 120 | |
Jordan Crouse | 3a48bdc | 2008-08-28 16:53:24 +0000 | [diff] [blame] | 121 | /** |
Stefan Reinauer | 4151439 | 2008-09-26 18:42:40 +0000 | [diff] [blame] | 122 | * @defgroup usb USB functions |
| 123 | * @{ |
| 124 | */ |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 125 | int usb_initialize(void); |
Patrick Georgi | bbc5231 | 2011-11-04 12:06:06 +0100 | [diff] [blame] | 126 | int usb_exit (void); |
Patrick Georgi | 4727c07 | 2008-10-16 19:20:51 +0000 | [diff] [blame] | 127 | int usbhid_havechar(void); |
| 128 | int usbhid_getchar(void); |
Stefan Reinauer | 4151439 | 2008-09-26 18:42:40 +0000 | [diff] [blame] | 129 | /** @} */ |
| 130 | |
| 131 | /** |
Jordan Crouse | 3a48bdc | 2008-08-28 16:53:24 +0000 | [diff] [blame] | 132 | * @defgroup input Device functions |
| 133 | * @{ @} |
| 134 | */ |
| 135 | |
Stefan Reinauer | 1beabe1 | 2010-03-25 18:52:24 +0000 | [diff] [blame] | 136 | extern void (*reset_handler)(void); |
| 137 | int add_reset_handler(void (*new_handler)(void)); |
| 138 | |
Jordan Crouse | 3a48bdc | 2008-08-28 16:53:24 +0000 | [diff] [blame] | 139 | /** |
| 140 | * @defgroup keyboard Keyboard functions |
| 141 | * @ingroup input |
| 142 | * @{ |
| 143 | */ |
Jordan Crouse | 63f181f | 2008-04-25 23:09:39 +0000 | [diff] [blame] | 144 | void keyboard_init(void); |
Uwe Hermann | dc69e05 | 2008-03-20 01:53:30 +0000 | [diff] [blame] | 145 | int keyboard_havechar(void); |
| 146 | unsigned char keyboard_get_scancode(void); |
| 147 | int keyboard_getchar(void); |
Stefan Reinauer | d84ef1e | 2008-09-26 18:37:26 +0000 | [diff] [blame] | 148 | int keyboard_set_layout(char *country); |
Jordan Crouse | 3a48bdc | 2008-08-28 16:53:24 +0000 | [diff] [blame] | 149 | /** @} */ |
Jordan Crouse | f6145c3 | 2008-03-19 23:56:58 +0000 | [diff] [blame] | 150 | |
Jordan Crouse | 3a48bdc | 2008-08-28 16:53:24 +0000 | [diff] [blame] | 151 | /** |
| 152 | * @defgroup serial Serial functions |
| 153 | * @ingroup input |
| 154 | * @{ |
| 155 | */ |
Uwe Hermann | dc69e05 | 2008-03-20 01:53:30 +0000 | [diff] [blame] | 156 | void serial_init(void); |
Patrick Georgi | 657a6dc | 2008-10-21 15:08:18 +0000 | [diff] [blame] | 157 | void serial_putchar(unsigned int c); |
Uwe Hermann | dc69e05 | 2008-03-20 01:53:30 +0000 | [diff] [blame] | 158 | int serial_havechar(void); |
| 159 | int serial_getchar(void); |
Jordan Crouse | 3b47065 | 2008-06-20 00:01:42 +0000 | [diff] [blame] | 160 | void serial_clear(void); |
| 161 | void serial_start_bold(void); |
| 162 | void serial_end_bold(void); |
Stefan Reinauer | e75c3d8 | 2008-09-26 18:36:26 +0000 | [diff] [blame] | 163 | void serial_start_reverse(void); |
| 164 | void serial_end_reverse(void); |
Ulf Jordan | b4d4bac | 2008-08-11 20:34:28 +0000 | [diff] [blame] | 165 | void serial_start_altcharset(void); |
| 166 | void serial_end_altcharset(void); |
Ulf Jordan | d57a680 | 2008-09-03 19:59:44 +0000 | [diff] [blame] | 167 | void serial_set_color(short fg, short bg); |
Stefan Reinauer | e75c3d8 | 2008-09-26 18:36:26 +0000 | [diff] [blame] | 168 | void serial_cursor_enable(int state); |
Jordan Crouse | 3b47065 | 2008-06-20 00:01:42 +0000 | [diff] [blame] | 169 | void serial_set_cursor(int y, int x); |
Jordan Crouse | 3a48bdc | 2008-08-28 16:53:24 +0000 | [diff] [blame] | 170 | /** @} */ |
Jordan Crouse | 3b47065 | 2008-06-20 00:01:42 +0000 | [diff] [blame] | 171 | |
Jordan Crouse | 3a48bdc | 2008-08-28 16:53:24 +0000 | [diff] [blame] | 172 | /** |
| 173 | * @defgroup speaker Speaker functions |
| 174 | * @ingroup input |
| 175 | * @{ |
| 176 | */ |
Uwe Hermann | fad8c2b | 2008-04-11 18:01:50 +0000 | [diff] [blame] | 177 | void speaker_enable(u16 freq); |
| 178 | void speaker_disable(void); |
| 179 | void speaker_tone(u16 freq, unsigned int duration); |
Jordan Crouse | 3a48bdc | 2008-08-28 16:53:24 +0000 | [diff] [blame] | 180 | /** @} */ |
Uwe Hermann | fad8c2b | 2008-04-11 18:01:50 +0000 | [diff] [blame] | 181 | |
Jordan Crouse | 3a48bdc | 2008-08-28 16:53:24 +0000 | [diff] [blame] | 182 | /** |
| 183 | * @defgroup video Video functions |
| 184 | * @ingroup input |
| 185 | * @{ |
| 186 | */ |
Jordan Crouse | 30939bd | 2008-04-10 22:49:02 +0000 | [diff] [blame] | 187 | int video_console_init(void); |
| 188 | void video_console_putchar(unsigned int ch); |
| 189 | void video_console_putc(u8 row, u8 col, unsigned int ch); |
| 190 | void video_console_clear(void); |
| 191 | void video_console_cursor_enable(int state); |
Stefan Reinauer | 59fb9a2b | 2008-08-19 17:44:49 +0000 | [diff] [blame] | 192 | void video_console_get_cursor(unsigned int *x, unsigned int *y, unsigned int *en); |
| 193 | void video_console_set_cursor(unsigned int cursorx, unsigned int cursory); |
Jordan Crouse | 3a48bdc | 2008-08-28 16:53:24 +0000 | [diff] [blame] | 194 | /** @} */ |
Stefan Reinauer | 59fb9a2b | 2008-08-19 17:44:49 +0000 | [diff] [blame] | 195 | |
| 196 | /* drivers/option.c */ |
Patrick Georgi | 317ca0d | 2012-01-16 10:14:24 +0100 | [diff] [blame] | 197 | struct nvram_accessor { |
| 198 | u8 (*read)(u8 reg); |
| 199 | void (*write)(u8 val, u8 reg); |
| 200 | }; |
| 201 | |
Patrick Georgi | 5febb00 | 2012-02-02 15:51:29 +0100 | [diff] [blame] | 202 | extern u8 *mem_accessor_base; |
| 203 | extern struct nvram_accessor *use_nvram, *use_mem; |
Patrick Georgi | 317ca0d | 2012-01-16 10:14:24 +0100 | [diff] [blame] | 204 | |
| 205 | struct cb_cmos_option_table *get_system_option_table(void); |
Patrick Georgi | 56f468d | 2012-01-16 15:03:11 +0100 | [diff] [blame] | 206 | int options_checksum_valid(const struct nvram_accessor *nvram); |
Patrick Georgi | 317ca0d | 2012-01-16 10:14:24 +0100 | [diff] [blame] | 207 | void fix_options_checksum_with(const struct nvram_accessor *nvram); |
Stefan Reinauer | 59a1b7f | 2010-08-17 10:14:50 +0000 | [diff] [blame] | 208 | void fix_options_checksum(void); |
Patrick Georgi | 0a59511 | 2012-01-16 15:39:57 +0100 | [diff] [blame] | 209 | struct cb_cmos_entries *first_cmos_entry(struct cb_cmos_option_table *option_table); |
| 210 | struct cb_cmos_entries *next_cmos_entry(struct cb_cmos_entries *cur); |
Mathias Krause | d6a6eef | 2012-02-17 12:02:47 +0100 | [diff] [blame^] | 211 | int get_option_with(const struct nvram_accessor *nvram, struct cb_cmos_option_table *option_table, void *dest, const char *name); |
| 212 | int get_option_from(struct cb_cmos_option_table *option_table, void *dest, const char *name); |
| 213 | int get_option(void *dest, const char *name); |
| 214 | int set_option_with(const struct nvram_accessor *nvram, struct cb_cmos_option_table *option_table, const void *value, const char *name); |
| 215 | int set_option(const void *value, const char *name); |
| 216 | int get_option_as_string(const struct nvram_accessor *nvram, struct cb_cmos_option_table *option_table, char **dest, const char *name); |
| 217 | int set_option_from_string(const struct nvram_accessor *nvram, struct cb_cmos_option_table *option_table, const char *value, const char *name); |
Uwe Hermann | dc69e05 | 2008-03-20 01:53:30 +0000 | [diff] [blame] | 218 | |
Jordan Crouse | 3a48bdc | 2008-08-28 16:53:24 +0000 | [diff] [blame] | 219 | /** |
| 220 | * @defgroup console Console functions |
| 221 | * @{ |
| 222 | */ |
Uwe Hermann | dc69e05 | 2008-03-20 01:53:30 +0000 | [diff] [blame] | 223 | void console_init(void); |
Patrick Georgi | 657a6dc | 2008-10-21 15:08:18 +0000 | [diff] [blame] | 224 | int putchar(unsigned int c); |
Uwe Hermann | dc69e05 | 2008-03-20 01:53:30 +0000 | [diff] [blame] | 225 | int puts(const char *s); |
| 226 | int havekey(void); |
| 227 | int getchar(void); |
Jordan Crouse | 672d0ae | 2008-04-08 23:21:33 +0000 | [diff] [blame] | 228 | int getchar_timeout(int *ms); |
Uwe Hermann | dc69e05 | 2008-03-20 01:53:30 +0000 | [diff] [blame] | 229 | |
Jordan Crouse | f6145c3 | 2008-03-19 23:56:58 +0000 | [diff] [blame] | 230 | extern int last_putchar; |
| 231 | |
Patrick Georgi | 657a6dc | 2008-10-21 15:08:18 +0000 | [diff] [blame] | 232 | struct console_input_driver; |
| 233 | struct console_input_driver { |
| 234 | struct console_input_driver *next; |
| 235 | int (*havekey) (void); |
| 236 | int (*getchar) (void); |
| 237 | }; |
| 238 | |
| 239 | struct console_output_driver; |
| 240 | struct console_output_driver { |
| 241 | struct console_output_driver *next; |
| 242 | void (*putchar) (unsigned int); |
| 243 | }; |
| 244 | |
| 245 | void console_add_output_driver(struct console_output_driver *out); |
| 246 | void console_add_input_driver(struct console_input_driver *in); |
| 247 | |
Jordan Crouse | f6145c3 | 2008-03-19 23:56:58 +0000 | [diff] [blame] | 248 | #define havechar havekey |
Jordan Crouse | 3a48bdc | 2008-08-28 16:53:24 +0000 | [diff] [blame] | 249 | /** @} */ |
Jordan Crouse | f6145c3 | 2008-03-19 23:56:58 +0000 | [diff] [blame] | 250 | |
Jordan Crouse | 3a48bdc | 2008-08-28 16:53:24 +0000 | [diff] [blame] | 251 | /** |
Uwe Hermann | 3153863 | 2008-08-31 22:10:35 +0000 | [diff] [blame] | 252 | * @defgroup ipchecksum IP checksum functions |
Jordan Crouse | 3a48bdc | 2008-08-28 16:53:24 +0000 | [diff] [blame] | 253 | * @{ |
| 254 | */ |
Stefan Reinauer | 11e45cd | 2008-08-16 15:16:36 +0000 | [diff] [blame] | 255 | unsigned short ipchksum(const void *ptr, unsigned long nbytes); |
Jordan Crouse | 3a48bdc | 2008-08-28 16:53:24 +0000 | [diff] [blame] | 256 | /** @} */ |
Uwe Hermann | dc69e05 | 2008-03-20 01:53:30 +0000 | [diff] [blame] | 257 | |
Jordan Crouse | f6145c3 | 2008-03-19 23:56:58 +0000 | [diff] [blame] | 258 | |
Jordan Crouse | 3a48bdc | 2008-08-28 16:53:24 +0000 | [diff] [blame] | 259 | /** |
Uwe Hermann | 3153863 | 2008-08-31 22:10:35 +0000 | [diff] [blame] | 260 | * @defgroup exec Execution functions |
Jordan Crouse | 3a48bdc | 2008-08-28 16:53:24 +0000 | [diff] [blame] | 261 | * @{ |
| 262 | */ |
Jordan Crouse | 9dac1b4 | 2008-05-20 20:10:49 +0000 | [diff] [blame] | 263 | int exec(long addr, int argc, char **argv); |
Jordan Crouse | 3a48bdc | 2008-08-28 16:53:24 +0000 | [diff] [blame] | 264 | /** @} */ |
Jordan Crouse | 9dac1b4 | 2008-05-20 20:10:49 +0000 | [diff] [blame] | 265 | |
Jordan Crouse | 3a48bdc | 2008-08-28 16:53:24 +0000 | [diff] [blame] | 266 | /** |
Uwe Hermann | 3153863 | 2008-08-31 22:10:35 +0000 | [diff] [blame] | 267 | * @defgroup misc Misc functions |
Jordan Crouse | 3a48bdc | 2008-08-28 16:53:24 +0000 | [diff] [blame] | 268 | * @{ |
| 269 | */ |
Uwe Hermann | 8cc38d2 | 2008-03-27 23:26:40 +0000 | [diff] [blame] | 270 | int bcd2dec(int b); |
| 271 | int dec2bcd(int d); |
Uwe Hermann | b103345 | 2008-04-11 18:38:04 +0000 | [diff] [blame] | 272 | int abs(int j); |
| 273 | long int labs(long int j); |
| 274 | long long int llabs(long long int j); |
| 275 | u8 bin2hex(u8 b); |
| 276 | u8 hex2bin(u8 h); |
Uwe Hermann | 3153863 | 2008-08-31 22:10:35 +0000 | [diff] [blame] | 277 | void fatal(const char *msg) __attribute__ ((noreturn)); |
Jordan Crouse | 3a48bdc | 2008-08-28 16:53:24 +0000 | [diff] [blame] | 278 | /** @} */ |
Uwe Hermann | 8cc38d2 | 2008-03-27 23:26:40 +0000 | [diff] [blame] | 279 | |
Uwe Hermann | c5a78ac | 2008-04-08 23:38:15 +0000 | [diff] [blame] | 280 | |
Jordan Crouse | 3a48bdc | 2008-08-28 16:53:24 +0000 | [diff] [blame] | 281 | /** |
Uwe Hermann | 3153863 | 2008-08-31 22:10:35 +0000 | [diff] [blame] | 282 | * @defgroup hash Hashing functions |
Jordan Crouse | 3a48bdc | 2008-08-28 16:53:24 +0000 | [diff] [blame] | 283 | * @{ |
| 284 | */ |
Uwe Hermann | 3995593 | 2008-04-03 23:01:23 +0000 | [diff] [blame] | 285 | #define SHA1_BLOCK_LENGTH 64 |
| 286 | #define SHA1_DIGEST_LENGTH 20 |
| 287 | typedef struct { |
| 288 | u32 state[5]; |
| 289 | u64 count; |
| 290 | u8 buffer[SHA1_BLOCK_LENGTH]; |
| 291 | } SHA1_CTX; |
| 292 | void SHA1Init(SHA1_CTX *context); |
| 293 | void SHA1Transform(u32 state[5], const u8 buffer[SHA1_BLOCK_LENGTH]); |
| 294 | void SHA1Update(SHA1_CTX *context, const u8 *data, size_t len); |
Patrick Georgi | 7f96583 | 2011-04-21 18:57:16 +0200 | [diff] [blame] | 295 | void SHA1Pad(SHA1_CTX *context); |
Uwe Hermann | 3995593 | 2008-04-03 23:01:23 +0000 | [diff] [blame] | 296 | void SHA1Final(u8 digest[SHA1_DIGEST_LENGTH], SHA1_CTX *context); |
| 297 | u8 *sha1(const u8 *data, size_t len, u8 *buf); |
Jordan Crouse | 3a48bdc | 2008-08-28 16:53:24 +0000 | [diff] [blame] | 298 | /** @} */ |
Uwe Hermann | 3995593 | 2008-04-03 23:01:23 +0000 | [diff] [blame] | 299 | |
Jordan Crouse | 3a48bdc | 2008-08-28 16:53:24 +0000 | [diff] [blame] | 300 | /** |
Uwe Hermann | 3153863 | 2008-08-31 22:10:35 +0000 | [diff] [blame] | 301 | * @defgroup time Time functions |
Jordan Crouse | 3a48bdc | 2008-08-28 16:53:24 +0000 | [diff] [blame] | 302 | * @{ |
| 303 | */ |
Jordan Crouse | e2ad806 | 2008-08-28 23:10:55 +0000 | [diff] [blame] | 304 | |
Uwe Hermann | 3153863 | 2008-08-31 22:10:35 +0000 | [diff] [blame] | 305 | /** System time structure */ |
Jordan Crouse | e227143 | 2008-04-25 23:11:02 +0000 | [diff] [blame] | 306 | struct timeval { |
Jordan Crouse | e2ad806 | 2008-08-28 23:10:55 +0000 | [diff] [blame] | 307 | time_t tv_sec; /**< Seconds */ |
| 308 | suseconds_t tv_usec; /**< Microseconds */ |
Jordan Crouse | e227143 | 2008-04-25 23:11:02 +0000 | [diff] [blame] | 309 | }; |
| 310 | |
| 311 | int gettimeofday(struct timeval *tv, void *tz); |
Jordan Crouse | 3a48bdc | 2008-08-28 16:53:24 +0000 | [diff] [blame] | 312 | /** @} */ |
Jordan Crouse | e227143 | 2008-04-25 23:11:02 +0000 | [diff] [blame] | 313 | |
Stefan Reinauer | e5d30b7 | 2010-03-25 22:15:19 +0000 | [diff] [blame] | 314 | #ifdef CONFIG_LAR |
Jordan Crouse | 3a48bdc | 2008-08-28 16:53:24 +0000 | [diff] [blame] | 315 | /** |
Uwe Hermann | 3153863 | 2008-08-31 22:10:35 +0000 | [diff] [blame] | 316 | * @defgroup lar LAR functions |
Jordan Crouse | 3a48bdc | 2008-08-28 16:53:24 +0000 | [diff] [blame] | 317 | * @{ |
| 318 | */ |
Jordan Crouse | e2ad806 | 2008-08-28 23:10:55 +0000 | [diff] [blame] | 319 | |
Uwe Hermann | 3153863 | 2008-08-31 22:10:35 +0000 | [diff] [blame] | 320 | /** LAR file header */ |
Jordan Crouse | 681ec27 | 2008-05-07 20:34:02 +0000 | [diff] [blame] | 321 | struct LAR { |
Uwe Hermann | 3153863 | 2008-08-31 22:10:35 +0000 | [diff] [blame] | 322 | void *start; /**< Location of the LAR in memory */ |
Jordan Crouse | e2ad806 | 2008-08-28 23:10:55 +0000 | [diff] [blame] | 323 | int cindex; /**< Next file to return in readlar() */ |
| 324 | int count; /**< Number of entries in the header cache */ |
| 325 | int alloc; /**< Number of slots in the header cache */ |
| 326 | int eof; /**< Last entry in the header cache */ |
| 327 | void **headers; /**< Pointer to the header cache */ |
Jordan Crouse | 681ec27 | 2008-05-07 20:34:02 +0000 | [diff] [blame] | 328 | }; |
| 329 | |
Uwe Hermann | 3153863 | 2008-08-31 22:10:35 +0000 | [diff] [blame] | 330 | /** A structure representing the next LAR entry */ |
Jordan Crouse | 681ec27 | 2008-05-07 20:34:02 +0000 | [diff] [blame] | 331 | struct larent { |
Jordan Crouse | e2ad806 | 2008-08-28 23:10:55 +0000 | [diff] [blame] | 332 | u8 name[LAR_MAX_PATHLEN]; /**< The name of the next LAR entry */ |
Jordan Crouse | 681ec27 | 2008-05-07 20:34:02 +0000 | [diff] [blame] | 333 | }; |
| 334 | |
Uwe Hermann | 3153863 | 2008-08-31 22:10:35 +0000 | [diff] [blame] | 335 | /** A structure containing information about a LAR file */ |
Jordan Crouse | 681ec27 | 2008-05-07 20:34:02 +0000 | [diff] [blame] | 336 | struct larstat { |
Jordan Crouse | e2ad806 | 2008-08-28 23:10:55 +0000 | [diff] [blame] | 337 | u32 len; /**< Length of the file in the LAR */ |
| 338 | u32 reallen; /**< Length of the uncompressed file */ |
| 339 | u32 checksum; /**< Checksum of the uncompressed file */ |
| 340 | u32 compchecksum; /**< Checksum of the compressed file in the LAR */ |
| 341 | u32 offset; /**< Offset of the file in the LAR */ |
| 342 | u32 compression; /**< Compression type of the file */ |
| 343 | u64 entry; /**< Entry point of the file for executables */ |
| 344 | u64 loadaddress; /**< Address in memory to put the uncompressed file */ |
Jordan Crouse | 681ec27 | 2008-05-07 20:34:02 +0000 | [diff] [blame] | 345 | }; |
| 346 | |
Uwe Hermann | 3153863 | 2008-08-31 22:10:35 +0000 | [diff] [blame] | 347 | /** A structure representing a LAR file */ |
Jordan Crouse | 681ec27 | 2008-05-07 20:34:02 +0000 | [diff] [blame] | 348 | struct LFILE { |
Jordan Crouse | e2ad806 | 2008-08-28 23:10:55 +0000 | [diff] [blame] | 349 | struct LAR *lar; /**< Pointer to the LAR struct */ |
| 350 | struct lar_header *header; /**< Pointer to the header struct */ |
| 351 | u32 size; /**< Size of the file */ |
| 352 | void *start; /**< Start of the file in memory */ |
| 353 | u32 offset; /**< Offset of the file in the LAR */ |
Jordan Crouse | 681ec27 | 2008-05-07 20:34:02 +0000 | [diff] [blame] | 354 | }; |
| 355 | |
| 356 | struct LAR *openlar(void *addr); |
| 357 | int closelar(struct LAR *lar); |
| 358 | struct larent *readlar(struct LAR *lar); |
| 359 | void rewindlar(struct LAR *lar); |
| 360 | int larstat(struct LAR *lar, const char *path, struct larstat *buf); |
Jordan Crouse | 5069808 | 2008-05-20 20:09:42 +0000 | [diff] [blame] | 361 | void *larfptr(struct LAR *lar, const char *filename); |
Jordan Crouse | 9e734c2 | 2008-05-27 19:57:53 +0000 | [diff] [blame] | 362 | int lfverify(struct LAR *lar, const char *filename); |
Uwe Hermann | 3153863 | 2008-08-31 22:10:35 +0000 | [diff] [blame] | 363 | struct LFILE *lfopen(struct LAR *lar, const char *filename); |
Jordan Crouse | 681ec27 | 2008-05-07 20:34:02 +0000 | [diff] [blame] | 364 | int lfread(void *ptr, size_t size, size_t nmemb, struct LFILE *stream); |
| 365 | |
Jordan Crouse | 681ec27 | 2008-05-07 20:34:02 +0000 | [diff] [blame] | 366 | int lfseek(struct LFILE *stream, long offset, int whence); |
| 367 | int lfclose(struct LFILE *file); |
Jordan Crouse | 3a48bdc | 2008-08-28 16:53:24 +0000 | [diff] [blame] | 368 | /** @} */ |
Stefan Reinauer | e5d30b7 | 2010-03-25 22:15:19 +0000 | [diff] [blame] | 369 | #endif |
Jordan Crouse | 681ec27 | 2008-05-07 20:34:02 +0000 | [diff] [blame] | 370 | |
Jordan Crouse | 3a48bdc | 2008-08-28 16:53:24 +0000 | [diff] [blame] | 371 | /** |
Jordan Crouse | 6c6e433 | 2008-11-11 19:51:14 +0000 | [diff] [blame] | 372 | * @defgroup info System information functions |
| 373 | * This module contains functions that return information about the system |
| 374 | * @{ |
| 375 | */ |
| 376 | |
| 377 | int sysinfo_have_multiboot(unsigned long *addr); |
| 378 | /** @} */ |
| 379 | |
| 380 | /** |
Uwe Hermann | 3153863 | 2008-08-31 22:10:35 +0000 | [diff] [blame] | 381 | * @defgroup arch Architecture specific functions |
| 382 | * This module contains global architecture specific functions. |
Jordan Crouse | b746178 | 2008-08-28 23:12:22 +0000 | [diff] [blame] | 383 | * All architectures are expected to define these functions. |
Jordan Crouse | 3a48bdc | 2008-08-28 16:53:24 +0000 | [diff] [blame] | 384 | * @{ |
| 385 | */ |
Uwe Hermann | dc69e05 | 2008-03-20 01:53:30 +0000 | [diff] [blame] | 386 | int get_coreboot_info(struct sysinfo_t *info); |
Jordan Crouse | 20c9cf1 | 2008-10-20 16:51:43 +0000 | [diff] [blame] | 387 | int get_multiboot_info(struct sysinfo_t *info); |
Jordan Crouse | f6145c3 | 2008-03-19 23:56:58 +0000 | [diff] [blame] | 388 | |
Philip Prindeville | 44bf6fc | 2011-12-23 18:33:05 -0700 | [diff] [blame] | 389 | int lib_get_sysinfo(void); |
Uwe Hermann | dc69e05 | 2008-03-20 01:53:30 +0000 | [diff] [blame] | 390 | |
Uwe Hermann | 661e380 | 2008-03-21 18:37:23 +0000 | [diff] [blame] | 391 | /* Timer functions - defined by each architecture. */ |
Uwe Hermann | dc69e05 | 2008-03-20 01:53:30 +0000 | [diff] [blame] | 392 | unsigned int get_cpu_speed(void); |
| 393 | void ndelay(unsigned int n); |
Jordan Crouse | 234e87f | 2008-04-10 22:50:44 +0000 | [diff] [blame] | 394 | void udelay(unsigned int n); |
Uwe Hermann | dc69e05 | 2008-03-20 01:53:30 +0000 | [diff] [blame] | 395 | void mdelay(unsigned int n); |
| 396 | void delay(unsigned int n); |
| 397 | |
Jordan Crouse | 3a48bdc | 2008-08-28 16:53:24 +0000 | [diff] [blame] | 398 | /** |
Uwe Hermann | 3153863 | 2008-08-31 22:10:35 +0000 | [diff] [blame] | 399 | * @defgroup readline Readline functions |
| 400 | * This interface provides a simple implementation of the standard readline() |
| 401 | * and getline() functions. They read a line of input from the console. |
Jordan Crouse | 3a48bdc | 2008-08-28 16:53:24 +0000 | [diff] [blame] | 402 | * @{ |
| 403 | */ |
Uwe Hermann | 3153863 | 2008-08-31 22:10:35 +0000 | [diff] [blame] | 404 | char *readline(const char *prompt); |
Jakob Bornecrantz | b0d3e71 | 2008-08-23 12:17:46 +0000 | [diff] [blame] | 405 | int getline(char *buffer, int len); |
Jordan Crouse | 3a48bdc | 2008-08-28 16:53:24 +0000 | [diff] [blame] | 406 | /** @} */ |
Jordan Crouse | f6145c3 | 2008-03-19 23:56:58 +0000 | [diff] [blame] | 407 | |
Jordan Crouse | f6145c3 | 2008-03-19 23:56:58 +0000 | [diff] [blame] | 408 | #endif |