2 * This file is part of the libpayload project.
4 * Copyright (C) 2008 Advanced Micro Devices, Inc.
5 * Copyright (C) 2009 coresystems GmbH
7 * SPDX-License-Identifier: BSD-3-Clause
11 #include <asm/arch-coreboot/ipchecksum.h>
12 #include <asm/arch-coreboot/sysinfo.h>
13 #include <asm/arch-coreboot/tables.h>
16 * This needs to be in the .data section so that it's copied over during
17 * relocation. By default it's put in the .bss section which is simply filled
18 * with zeroes when transitioning from "ROM", which is really RAM, to other
21 struct sysinfo_t lib_sysinfo __attribute__((section(".data")));
24 * Some of this is x86 specific, and the rest of it is generic. Right now,
25 * since we only support x86, we'll avoid trying to make lots of infrastructure
26 * we don't need. If in the future, we want to use coreboot on some other
27 * architecture, then take out the generic parsing code and move it elsewhere.
30 /* === Parsing code === */
31 /* This is the generic parsing code. */
33 static void cb_parse_memory(unsigned char *ptr, struct sysinfo_t *info)
35 struct cb_memory *mem = (struct cb_memory *)ptr;
36 int count = MEM_RANGE_COUNT(mem);
39 if (count > SYSINFO_MAX_MEM_RANGES)
40 count = SYSINFO_MAX_MEM_RANGES;
42 info->n_memranges = 0;
44 for (i = 0; i < count; i++) {
45 struct cb_memory_range *range =
46 (struct cb_memory_range *)MEM_RANGE_PTR(mem, i);
48 info->memrange[info->n_memranges].base =
49 UNPACK_CB64(range->start);
51 info->memrange[info->n_memranges].size =
52 UNPACK_CB64(range->size);
54 info->memrange[info->n_memranges].type = range->type;
60 static void cb_parse_serial(unsigned char *ptr, struct sysinfo_t *info)
62 struct cb_serial *ser = (struct cb_serial *)ptr;
66 static void cb_parse_vbnv(unsigned char *ptr, struct sysinfo_t *info)
68 struct cb_vbnv *vbnv = (struct cb_vbnv *)ptr;
70 info->vbnv_start = vbnv->vbnv_start;
71 info->vbnv_size = vbnv->vbnv_size;
74 static void cb_parse_gpios(unsigned char *ptr, struct sysinfo_t *info)
77 struct cb_gpios *gpios = (struct cb_gpios *)ptr;
79 info->num_gpios = (gpios->count < SYSINFO_MAX_GPIOS) ?
80 (gpios->count) : SYSINFO_MAX_GPIOS;
82 for (i = 0; i < info->num_gpios; i++)
83 info->gpios[i] = gpios->gpios[i];
86 static void cb_parse_vdat(unsigned char *ptr, struct sysinfo_t *info)
88 struct cb_vdat *vdat = (struct cb_vdat *) ptr;
90 info->vdat_addr = vdat->vdat_addr;
91 info->vdat_size = vdat->vdat_size;
94 static void cb_parse_tstamp(unsigned char *ptr, struct sysinfo_t *info)
96 info->tstamp_table = ((struct cb_cbmem_tab *)ptr)->cbmem_tab;
99 static void cb_parse_cbmem_cons(unsigned char *ptr, struct sysinfo_t *info)
101 info->cbmem_cons = ((struct cb_cbmem_tab *)ptr)->cbmem_tab;
104 static void cb_parse_framebuffer(unsigned char *ptr, struct sysinfo_t *info)
106 info->framebuffer = (struct cb_framebuffer *)ptr;
109 static void cb_parse_string(unsigned char *ptr, char **info)
111 *info = (char *)((struct cb_string *)ptr)->string;
114 static int cb_parse_header(void *addr, int len, struct sysinfo_t *info)
116 struct cb_header *header;
117 unsigned char *ptr = (unsigned char *)addr;
120 for (i = 0; i < len; i += 16, ptr += 16) {
121 header = (struct cb_header *)ptr;
122 if (!strncmp((const char *)header->signature, "LBIO", 4))
126 /* We walked the entire space and didn't find anything. */
130 if (!header->table_bytes)
133 /* Make sure the checksums match. */
134 if (ipchksum((u16 *) header, sizeof(*header)) != 0)
137 if (ipchksum((u16 *) (ptr + sizeof(*header)),
138 header->table_bytes) != header->table_checksum)
141 /* Now, walk the tables. */
142 ptr += header->header_bytes;
144 /* Inintialize some fields to sentinel values. */
145 info->vbnv_start = info->vbnv_size = (uint32_t)(-1);
147 for (i = 0; i < header->table_entries; i++) {
148 struct cb_record *rec = (struct cb_record *)ptr;
150 /* We only care about a few tags here (maybe more later). */
153 return cb_parse_header(
154 (void *)(unsigned long)
155 ((struct cb_forward *)rec)->forward,
159 cb_parse_memory(ptr, info);
162 cb_parse_serial(ptr, info);
165 cb_parse_string(ptr, &info->version);
167 case CB_TAG_EXTRA_VERSION:
168 cb_parse_string(ptr, &info->extra_version);
171 cb_parse_string(ptr, &info->build);
173 case CB_TAG_COMPILE_TIME:
174 cb_parse_string(ptr, &info->compile_time);
176 case CB_TAG_COMPILE_BY:
177 cb_parse_string(ptr, &info->compile_by);
179 case CB_TAG_COMPILE_HOST:
180 cb_parse_string(ptr, &info->compile_host);
182 case CB_TAG_COMPILE_DOMAIN:
183 cb_parse_string(ptr, &info->compile_domain);
185 case CB_TAG_COMPILER:
186 cb_parse_string(ptr, &info->compiler);
189 cb_parse_string(ptr, &info->linker);
191 case CB_TAG_ASSEMBLER:
192 cb_parse_string(ptr, &info->assembler);
195 * FIXME we should warn on serial if coreboot set up a
196 * framebuffer buf the payload does not know about it.
198 case CB_TAG_FRAMEBUFFER:
199 cb_parse_framebuffer(ptr, info);
202 cb_parse_gpios(ptr, info);
205 cb_parse_vdat(ptr, info);
207 case CB_TAG_TIMESTAMPS:
208 cb_parse_tstamp(ptr, info);
210 case CB_TAG_CBMEM_CONSOLE:
211 cb_parse_cbmem_cons(ptr, info);
214 cb_parse_vbnv(ptr, info);
224 /* == Architecture specific == */
225 /* This is the x86 specific stuff. */
227 int get_coreboot_info(struct sysinfo_t *info)
229 int ret = cb_parse_header((void *)0x00000000, 0x1000, info);
232 ret = cb_parse_header((void *)0x000f0000, 0x1000, info);
234 return (ret == 1) ? 0 : -1;