coreboot.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  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. /* Maximum number of memory range definitions. */
  30. #define SYSINFO_MAX_MEM_RANGES 32
  31. /* Allow a maximum of 8 GPIOs */
  32. #define SYSINFO_MAX_GPIOS 8
  33. struct cbuint64 {
  34. uint32_t lo;
  35. uint32_t hi;
  36. };
  37. struct cb_header {
  38. uint8_t signature[4];
  39. uint32_t header_bytes;
  40. uint32_t header_checksum;
  41. uint32_t table_bytes;
  42. uint32_t table_checksum;
  43. uint32_t table_entries;
  44. };
  45. struct cb_record {
  46. uint32_t tag;
  47. uint32_t size;
  48. };
  49. #define CB_TAG_UNUSED 0x0000
  50. #define CB_TAG_MEMORY 0x0001
  51. struct cb_memory_range {
  52. struct cbuint64 start;
  53. struct cbuint64 size;
  54. uint32_t type;
  55. };
  56. #define CB_MEM_RAM 1
  57. #define CB_MEM_RESERVED 2
  58. #define CB_MEM_ACPI 3
  59. #define CB_MEM_NVS 4
  60. #define CB_MEM_UNUSABLE 5
  61. #define CB_MEM_VENDOR_RSVD 6
  62. #define CB_MEM_TABLE 16
  63. struct cb_memory {
  64. uint32_t tag;
  65. uint32_t size;
  66. struct cb_memory_range map[0];
  67. };
  68. #define CB_TAG_HWRPB 0x0002
  69. struct cb_hwrpb {
  70. uint32_t tag;
  71. uint32_t size;
  72. uint64_t hwrpb;
  73. };
  74. #define CB_TAG_MAINBOARD 0x0003
  75. struct cb_mainboard {
  76. uint32_t tag;
  77. uint32_t size;
  78. uint8_t vendor_idx;
  79. uint8_t part_number_idx;
  80. uint8_t strings[0];
  81. };
  82. #define CB_TAG_VERSION 0x0004
  83. #define CB_TAG_EXTRA_VERSION 0x0005
  84. #define CB_TAG_BUILD 0x0006
  85. #define CB_TAG_COMPILE_TIME 0x0007
  86. #define CB_TAG_COMPILE_BY 0x0008
  87. #define CB_TAG_COMPILE_HOST 0x0009
  88. #define CB_TAG_COMPILE_DOMAIN 0x000a
  89. #define CB_TAG_COMPILER 0x000b
  90. #define CB_TAG_LINKER 0x000c
  91. #define CB_TAG_ASSEMBLER 0x000d
  92. struct cb_string {
  93. uint32_t tag;
  94. uint32_t size;
  95. uint8_t string[0];
  96. };
  97. #define CB_TAG_SERIAL 0x000f
  98. struct cb_serial {
  99. uint32_t tag;
  100. uint32_t size;
  101. #define CB_SERIAL_TYPE_IO_MAPPED 1
  102. #define CB_SERIAL_TYPE_MEMORY_MAPPED 2
  103. uint32_t type;
  104. uint32_t baseaddr;
  105. uint32_t baud;
  106. };
  107. #define CB_TAG_CONSOLE 0x00010
  108. struct cb_console {
  109. uint32_t tag;
  110. uint32_t size;
  111. uint16_t type;
  112. };
  113. #define CB_TAG_CONSOLE_SERIAL8250 0
  114. #define CB_TAG_CONSOLE_VGA 1 // OBSOLETE
  115. #define CB_TAG_CONSOLE_BTEXT 2 // OBSOLETE
  116. #define CB_TAG_CONSOLE_LOGBUF 3 // OBSOLETE
  117. #define CB_TAG_CONSOLE_SROM 4 // OBSOLETE
  118. #define CB_TAG_CONSOLE_EHCI 5
  119. #define CB_TAG_FORWARD 0x00011
  120. struct cb_forward {
  121. uint32_t tag;
  122. uint32_t size;
  123. uint64_t forward;
  124. };
  125. #define CB_TAG_FRAMEBUFFER 0x0012
  126. struct cb_framebuffer {
  127. uint32_t tag;
  128. uint32_t size;
  129. uint64_t physical_address;
  130. uint32_t x_resolution;
  131. uint32_t y_resolution;
  132. uint32_t bytes_per_line;
  133. uint8_t bits_per_pixel;
  134. uint8_t red_mask_pos;
  135. uint8_t red_mask_size;
  136. uint8_t green_mask_pos;
  137. uint8_t green_mask_size;
  138. uint8_t blue_mask_pos;
  139. uint8_t blue_mask_size;
  140. uint8_t reserved_mask_pos;
  141. uint8_t reserved_mask_size;
  142. };
  143. #define CB_TAG_GPIO 0x0013
  144. #define CB_GPIO_ACTIVE_LOW 0
  145. #define CB_GPIO_ACTIVE_HIGH 1
  146. #define CB_GPIO_MAX_NAME_LENGTH 16
  147. struct cb_gpio {
  148. uint32_t port;
  149. uint32_t polarity;
  150. uint32_t value;
  151. uint8_t name[CB_GPIO_MAX_NAME_LENGTH];
  152. };
  153. struct cb_gpios {
  154. uint32_t tag;
  155. uint32_t size;
  156. uint32_t count;
  157. struct cb_gpio gpios[0];
  158. };
  159. #define CB_TAG_VDAT 0x0015
  160. #define CB_TAG_VBNV 0x0019
  161. #define CB_TAG_VBOOT_HANDOFF 0x0020
  162. #define CB_TAG_DMA 0x0022
  163. struct cb_range {
  164. uint32_t tag;
  165. uint32_t size;
  166. uint64_t range_start;
  167. uint32_t range_size;
  168. };
  169. #define CB_TAG_TIMESTAMPS 0x0016
  170. #define CB_TAG_CBMEM_CONSOLE 0x0017
  171. #define CB_TAG_MRC_CACHE 0x0018
  172. #define CB_TAG_ACPI_GNVS 0x0024
  173. struct cb_cbmem_tab {
  174. uint32_t tag;
  175. uint32_t size;
  176. uint64_t cbmem_tab;
  177. };
  178. #define CB_TAG_X86_ROM_MTRR 0x0021
  179. struct cb_x86_rom_mtrr {
  180. uint32_t tag;
  181. uint32_t size;
  182. /* The variable range MTRR index covering the ROM. If one wants to
  183. * enable caching the ROM, the variable MTRR needs to be set to
  184. * write-protect. To disable the caching after enabling set the
  185. * type to uncacheable. */
  186. uint32_t index;
  187. };
  188. #define CB_TAG_CMOS_OPTION_TABLE 0x00c8
  189. struct cb_cmos_option_table {
  190. uint32_t tag;
  191. uint32_t size;
  192. uint32_t header_length;
  193. };
  194. #define CB_TAG_OPTION 0x00c9
  195. #define CB_CMOS_MAX_NAME_LENGTH 32
  196. struct cb_cmos_entries {
  197. uint32_t tag;
  198. uint32_t size;
  199. uint32_t bit;
  200. uint32_t length;
  201. uint32_t config;
  202. uint32_t config_id;
  203. uint8_t name[CB_CMOS_MAX_NAME_LENGTH];
  204. };
  205. #define CB_TAG_OPTION_ENUM 0x00ca
  206. #define CB_CMOS_MAX_TEXT_LENGTH 32
  207. struct cb_cmos_enums {
  208. uint32_t tag;
  209. uint32_t size;
  210. uint32_t config_id;
  211. uint32_t value;
  212. uint8_t text[CB_CMOS_MAX_TEXT_LENGTH];
  213. };
  214. #define CB_TAG_OPTION_DEFAULTS 0x00cb
  215. #define CB_CMOS_IMAGE_BUFFER_SIZE 128
  216. struct cb_cmos_defaults {
  217. uint32_t tag;
  218. uint32_t size;
  219. uint32_t name_length;
  220. uint8_t name[CB_CMOS_MAX_NAME_LENGTH];
  221. uint8_t default_set[CB_CMOS_IMAGE_BUFFER_SIZE];
  222. };
  223. #define CB_TAG_OPTION_CHECKSUM 0x00cc
  224. #define CB_CHECKSUM_NONE 0
  225. #define CB_CHECKSUM_PCBIOS 1
  226. struct cb_cmos_checksum {
  227. uint32_t tag;
  228. uint32_t size;
  229. uint32_t range_start;
  230. uint32_t range_end;
  231. uint32_t location;
  232. uint32_t type;
  233. };
  234. unsigned short ipchksum(const void *vptr, unsigned long nbytes);
  235. /* Helpful inlines */
  236. static inline uint64_t cb_unpack64(struct cbuint64 val)
  237. {
  238. return (((uint64_t) val.hi) << 32) | val.lo;
  239. }
  240. static inline uint16_t cb_checksum(const void *ptr, unsigned len)
  241. {
  242. return ipchksum((uint8_t *)ptr, len);
  243. }
  244. static inline const char *cb_mb_vendor_string(const struct cb_mainboard *cbm)
  245. {
  246. return (char *)(cbm->strings + cbm->vendor_idx);
  247. }
  248. static inline const char *cb_mb_part_string(const struct cb_mainboard *cbm)
  249. {
  250. return (char *)(cbm->strings + cbm->part_number_idx);
  251. }
  252. struct sysinfo_t {
  253. unsigned int cpu_khz;
  254. struct cb_serial *serial;
  255. unsigned short ser_ioport;
  256. unsigned long ser_base; // for mmapped serial
  257. int n_memranges;
  258. struct memrange {
  259. unsigned long long base;
  260. unsigned long long size;
  261. unsigned int type;
  262. } memrange[SYSINFO_MAX_MEM_RANGES];
  263. struct cb_cmos_option_table *option_table;
  264. uint32_t cmos_range_start;
  265. uint32_t cmos_range_end;
  266. uint32_t cmos_checksum_location;
  267. uint32_t vbnv_start;
  268. uint32_t vbnv_size;
  269. char *version;
  270. char *extra_version;
  271. char *build;
  272. char *compile_time;
  273. char *compile_by;
  274. char *compile_host;
  275. char *compile_domain;
  276. char *compiler;
  277. char *linker;
  278. char *assembler;
  279. char *cb_version;
  280. struct cb_framebuffer *framebuffer;
  281. int num_gpios;
  282. struct cb_gpio gpios[SYSINFO_MAX_GPIOS];
  283. unsigned long *mbtable; /** Pointer to the multiboot table */
  284. struct cb_header *header;
  285. struct cb_mainboard *mainboard;
  286. /* these are chromeos specific and may or may not be valid. */
  287. void *vboot_handoff;
  288. uint32_t vboot_handoff_size;
  289. void *vdat_addr;
  290. uint32_t vdat_size;
  291. void *tstamp_table;
  292. void *cbmem_cons;
  293. void *mrc_cache;
  294. void *acpi_gnvs;
  295. };
  296. extern struct sysinfo_t lib_sysinfo;
  297. /* Helpful macros */
  298. #define MEM_RANGE_COUNT(_rec) \
  299. (((_rec)->size - sizeof(*(_rec))) / sizeof((_rec)->map[0]))
  300. #define MEM_RANGE_PTR(_rec, _idx) \
  301. (void *)(((uint8_t *) (_rec)) + sizeof(*(_rec)) \
  302. + (sizeof((_rec)->map[0]) * (_idx)))
  303. int get_coreboot_info(struct sysinfo_t *info);
  304. int cb_parse_header(void *addr, int len, struct sysinfo_t *info);