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
12 #include <asm/arch/sysinfo.h>
15 * This needs to be in the .data section so that it's copied over during
16 * relocation. By default it's put in the .bss section which is simply filled
17 * with zeroes when transitioning from "ROM", which is really RAM, to other
20 struct sysinfo_t lib_sysinfo __attribute__((section(".data")));
23 * Some of this is x86 specific, and the rest of it is generic. Right now,
24 * since we only support x86, we'll avoid trying to make lots of infrastructure
25 * we don't need. If in the future, we want to use coreboot on some other
26 * architecture, then take out the generic parsing code and move it elsewhere.
29 /* === Parsing code === */
30 /* This is the generic parsing code. */
32 static void cb_parse_memory(unsigned char *ptr, struct sysinfo_t *info)
34 struct cb_memory *mem = (struct cb_memory *)ptr;
35 int count = MEM_RANGE_COUNT(mem);
38 if (count > SYSINFO_MAX_MEM_RANGES)
39 count = SYSINFO_MAX_MEM_RANGES;
41 info->n_memranges = 0;
43 for (i = 0; i < count; i++) {
44 struct cb_memory_range *range =
45 (struct cb_memory_range *)MEM_RANGE_PTR(mem, i);
47 info->memrange[info->n_memranges].base =
48 UNPACK_CB64(range->start);
50 info->memrange[info->n_memranges].size =
51 UNPACK_CB64(range->size);
53 info->memrange[info->n_memranges].type = range->type;
59 static void cb_parse_serial(unsigned char *ptr, struct sysinfo_t *info)
61 struct cb_serial *ser = (struct cb_serial *)ptr;
65 static void cb_parse_vbnv(unsigned char *ptr, struct sysinfo_t *info)
67 struct cb_vbnv *vbnv = (struct cb_vbnv *)ptr;
69 info->vbnv_start = vbnv->vbnv_start;
70 info->vbnv_size = vbnv->vbnv_size;
73 static void cb_parse_gpios(unsigned char *ptr, struct sysinfo_t *info)
76 struct cb_gpios *gpios = (struct cb_gpios *)ptr;
78 info->num_gpios = (gpios->count < SYSINFO_MAX_GPIOS) ?
79 (gpios->count) : SYSINFO_MAX_GPIOS;
81 for (i = 0; i < info->num_gpios; i++)
82 info->gpios[i] = gpios->gpios[i];
85 static void cb_parse_vdat(unsigned char *ptr, struct sysinfo_t *info)
87 struct cb_vdat *vdat = (struct cb_vdat *) ptr;
89 info->vdat_addr = vdat->vdat_addr;
90 info->vdat_size = vdat->vdat_size;
93 static void cb_parse_tstamp(unsigned char *ptr, struct sysinfo_t *info)
95 info->tstamp_table = ((struct cb_cbmem_tab *)ptr)->cbmem_tab;
98 static void cb_parse_cbmem_cons(unsigned char *ptr, struct sysinfo_t *info)
100 info->cbmem_cons = ((struct cb_cbmem_tab *)ptr)->cbmem_tab;
103 static void cb_parse_framebuffer(unsigned char *ptr, struct sysinfo_t *info)
105 info->framebuffer = (struct cb_framebuffer *)ptr;
108 static void cb_parse_string(unsigned char *ptr, char **info)
110 *info = (char *)((struct cb_string *)ptr)->string;
113 static int cb_parse_header(void *addr, int len, struct sysinfo_t *info)
115 struct cb_header *header;
116 unsigned char *ptr = (unsigned char *)addr;
119 for (i = 0; i < len; i += 16, ptr += 16) {
120 header = (struct cb_header *)ptr;
121 if (!strncmp((const char *)header->signature, "LBIO", 4))
125 /* We walked the entire space and didn't find anything. */
129 if (!header->table_bytes)
132 /* Make sure the checksums match. */
133 if (!ip_checksum_ok(header, sizeof(*header)))
136 if (compute_ip_checksum(ptr + sizeof(*header), header->table_bytes) !=
137 header->table_checksum)
140 /* Now, walk the tables. */
141 ptr += header->header_bytes;
143 /* Inintialize some fields to sentinel values. */
144 info->vbnv_start = info->vbnv_size = (uint32_t)(-1);
146 for (i = 0; i < header->table_entries; i++) {
147 struct cb_record *rec = (struct cb_record *)ptr;
149 /* We only care about a few tags here (maybe more later). */
152 return cb_parse_header(
153 (void *)(unsigned long)
154 ((struct cb_forward *)rec)->forward,
158 cb_parse_memory(ptr, info);
161 cb_parse_serial(ptr, info);
164 cb_parse_string(ptr, &info->version);
166 case CB_TAG_EXTRA_VERSION:
167 cb_parse_string(ptr, &info->extra_version);
170 cb_parse_string(ptr, &info->build);
172 case CB_TAG_COMPILE_TIME:
173 cb_parse_string(ptr, &info->compile_time);
175 case CB_TAG_COMPILE_BY:
176 cb_parse_string(ptr, &info->compile_by);
178 case CB_TAG_COMPILE_HOST:
179 cb_parse_string(ptr, &info->compile_host);
181 case CB_TAG_COMPILE_DOMAIN:
182 cb_parse_string(ptr, &info->compile_domain);
184 case CB_TAG_COMPILER:
185 cb_parse_string(ptr, &info->compiler);
188 cb_parse_string(ptr, &info->linker);
190 case CB_TAG_ASSEMBLER:
191 cb_parse_string(ptr, &info->assembler);
194 * FIXME we should warn on serial if coreboot set up a
195 * framebuffer buf the payload does not know about it.
197 case CB_TAG_FRAMEBUFFER:
198 cb_parse_framebuffer(ptr, info);
201 cb_parse_gpios(ptr, info);
204 cb_parse_vdat(ptr, info);
206 case CB_TAG_TIMESTAMPS:
207 cb_parse_tstamp(ptr, info);
209 case CB_TAG_CBMEM_CONSOLE:
210 cb_parse_cbmem_cons(ptr, info);
213 cb_parse_vbnv(ptr, info);
223 /* == Architecture specific == */
224 /* This is the x86 specific stuff. */
226 int get_coreboot_info(struct sysinfo_t *info)
228 int ret = cb_parse_header((void *)0x00000000, 0x1000, info);
231 ret = cb_parse_header((void *)0x000f0000, 0x1000, info);
233 return (ret == 1) ? 0 : -1;