1
0

coreboot.h 7.8 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. u32 lo;
  35. u32 hi;
  36. };
  37. struct cb_header {
  38. u8 signature[4];
  39. u32 header_bytes;
  40. u32 header_checksum;
  41. u32 table_bytes;
  42. u32 table_checksum;
  43. u32 table_entries;
  44. };
  45. struct cb_record {
  46. u32 tag;
  47. u32 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. u32 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. u32 tag;
  65. u32 size;
  66. struct cb_memory_range map[0];
  67. };
  68. #define CB_TAG_HWRPB 0x0002
  69. struct cb_hwrpb {
  70. u32 tag;
  71. u32 size;
  72. u64 hwrpb;
  73. };
  74. #define CB_TAG_MAINBOARD 0x0003
  75. struct cb_mainboard {
  76. u32 tag;
  77. u32 size;
  78. u8 vendor_idx;
  79. u8 part_number_idx;
  80. u8 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. u32 tag;
  94. u32 size;
  95. u8 string[0];
  96. };
  97. #define CB_TAG_SERIAL 0x000f
  98. struct cb_serial {
  99. u32 tag;
  100. u32 size;
  101. #define CB_SERIAL_TYPE_IO_MAPPED 1
  102. #define CB_SERIAL_TYPE_MEMORY_MAPPED 2
  103. u32 type;
  104. u32 baseaddr;
  105. u32 baud;
  106. };
  107. #define CB_TAG_CONSOLE 0x00010
  108. struct cb_console {
  109. u32 tag;
  110. u32 size;
  111. u16 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. u32 tag;
  122. u32 size;
  123. u64 forward;
  124. };
  125. #define CB_TAG_FRAMEBUFFER 0x0012
  126. struct cb_framebuffer {
  127. u32 tag;
  128. u32 size;
  129. u64 physical_address;
  130. u32 x_resolution;
  131. u32 y_resolution;
  132. u32 bytes_per_line;
  133. u8 bits_per_pixel;
  134. u8 red_mask_pos;
  135. u8 red_mask_size;
  136. u8 green_mask_pos;
  137. u8 green_mask_size;
  138. u8 blue_mask_pos;
  139. u8 blue_mask_size;
  140. u8 reserved_mask_pos;
  141. u8 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. u32 port;
  149. u32 polarity;
  150. u32 value;
  151. u8 name[CB_GPIO_MAX_NAME_LENGTH];
  152. };
  153. struct cb_gpios {
  154. u32 tag;
  155. u32 size;
  156. u32 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. u32 tag;
  165. u32 size;
  166. u64 range_start;
  167. u32 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. u32 tag;
  175. u32 size;
  176. u64 cbmem_tab;
  177. };
  178. #define CB_TAG_X86_ROM_MTRR 0x0021
  179. struct cb_x86_rom_mtrr {
  180. u32 tag;
  181. u32 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. u32 index;
  187. };
  188. #define CB_TAG_CMOS_OPTION_TABLE 0x00c8
  189. struct cb_cmos_option_table {
  190. u32 tag;
  191. u32 size;
  192. u32 header_length;
  193. };
  194. #define CB_TAG_OPTION 0x00c9
  195. #define CB_CMOS_MAX_NAME_LENGTH 32
  196. struct cb_cmos_entries {
  197. u32 tag;
  198. u32 size;
  199. u32 bit;
  200. u32 length;
  201. u32 config;
  202. u32 config_id;
  203. u8 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. u32 tag;
  209. u32 size;
  210. u32 config_id;
  211. u32 value;
  212. u8 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. u32 tag;
  218. u32 size;
  219. u32 name_length;
  220. u8 name[CB_CMOS_MAX_NAME_LENGTH];
  221. u8 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. u32 tag;
  228. u32 size;
  229. u32 range_start;
  230. u32 range_end;
  231. u32 location;
  232. u32 type;
  233. };
  234. unsigned short ipchksum(const void *vptr, unsigned long nbytes);
  235. /* Helpful inlines */
  236. static inline u64 cb_unpack64(struct cbuint64 val)
  237. {
  238. return (((u64) val.hi) << 32) | val.lo;
  239. }
  240. static inline u16 cb_checksum(const void *ptr, unsigned len)
  241. {
  242. return ipchksum((u8 *)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. u32 cmos_range_start;
  265. u32 cmos_range_end;
  266. u32 cmos_checksum_location;
  267. u32 vbnv_start;
  268. u32 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. u32 vboot_handoff_size;
  289. void *vdat_addr;
  290. u32 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 *)(((u8 *) (_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);