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