1 // SPDX-License-Identifier: BSD-3-Clause
3 * This file is part of the libpayload project.
5 * Copyright (C) 2008 Advanced Micro Devices, Inc.
6 * Copyright (C) 2009 coresystems GmbH
11 #include <asm/arch/sysinfo.h>
14 * This needs to be in the .data section so that it's copied over during
15 * relocation. By default it's put in the .bss section which is simply filled
16 * with zeroes when transitioning from "ROM", which is really RAM, to other
19 struct sysinfo_t lib_sysinfo __attribute__((section(".data")));
22 * Some of this is x86 specific, and the rest of it is generic. Right now,
23 * since we only support x86, we'll avoid trying to make lots of infrastructure
24 * we don't need. If in the future, we want to use coreboot on some other
25 * architecture, then take out the generic parsing code and move it elsewhere.
28 /* === Parsing code === */
29 /* This is the generic parsing code. */
31 static void cb_parse_memory(unsigned char *ptr, struct sysinfo_t *info)
33 struct cb_memory *mem = (struct cb_memory *)ptr;
34 int count = MEM_RANGE_COUNT(mem);
37 if (count > SYSINFO_MAX_MEM_RANGES)
38 count = SYSINFO_MAX_MEM_RANGES;
40 info->n_memranges = 0;
42 for (i = 0; i < count; i++) {
43 struct cb_memory_range *range =
44 (struct cb_memory_range *)MEM_RANGE_PTR(mem, i);
46 info->memrange[info->n_memranges].base =
47 UNPACK_CB64(range->start);
49 info->memrange[info->n_memranges].size =
50 UNPACK_CB64(range->size);
52 info->memrange[info->n_memranges].type = range->type;
58 static void cb_parse_serial(unsigned char *ptr, struct sysinfo_t *info)
60 struct cb_serial *ser = (struct cb_serial *)ptr;
64 static void cb_parse_vbnv(unsigned char *ptr, struct sysinfo_t *info)
66 struct cb_vbnv *vbnv = (struct cb_vbnv *)ptr;
68 info->vbnv_start = vbnv->vbnv_start;
69 info->vbnv_size = vbnv->vbnv_size;
72 static void cb_parse_gpios(unsigned char *ptr, struct sysinfo_t *info)
75 struct cb_gpios *gpios = (struct cb_gpios *)ptr;
77 info->num_gpios = (gpios->count < SYSINFO_MAX_GPIOS) ?
78 (gpios->count) : SYSINFO_MAX_GPIOS;
80 for (i = 0; i < info->num_gpios; i++)
81 info->gpios[i] = gpios->gpios[i];
84 static void cb_parse_vdat(unsigned char *ptr, struct sysinfo_t *info)
86 struct cb_vdat *vdat = (struct cb_vdat *) ptr;
88 info->vdat_addr = vdat->vdat_addr;
89 info->vdat_size = vdat->vdat_size;
92 static void cb_parse_tstamp(unsigned char *ptr, struct sysinfo_t *info)
94 info->tstamp_table = ((struct cb_cbmem_tab *)ptr)->cbmem_tab;
97 static void cb_parse_cbmem_cons(unsigned char *ptr, struct sysinfo_t *info)
99 info->cbmem_cons = ((struct cb_cbmem_tab *)ptr)->cbmem_tab;
102 static void cb_parse_framebuffer(unsigned char *ptr, struct sysinfo_t *info)
104 info->framebuffer = (struct cb_framebuffer *)ptr;
107 static void cb_parse_string(unsigned char *ptr, char **info)
109 *info = (char *)((struct cb_string *)ptr)->string;
112 __weak void cb_parse_unhandled(u32 tag, unsigned char *ptr)
116 static int cb_parse_header(void *addr, int len, struct sysinfo_t *info)
118 struct cb_header *header;
119 unsigned char *ptr = (unsigned char *)addr;
122 for (i = 0; i < len; i += 16, ptr += 16) {
123 header = (struct cb_header *)ptr;
124 if (!strncmp((const char *)header->signature, "LBIO", 4))
128 /* We walked the entire space and didn't find anything. */
132 if (!header->table_bytes)
135 /* Make sure the checksums match. */
136 if (!ip_checksum_ok(header, sizeof(*header)))
139 if (compute_ip_checksum(ptr + sizeof(*header), header->table_bytes) !=
140 header->table_checksum)
143 /* Now, walk the tables. */
144 ptr += header->header_bytes;
146 /* Inintialize some fields to sentinel values. */
147 info->vbnv_start = info->vbnv_size = (uint32_t)(-1);
149 for (i = 0; i < header->table_entries; i++) {
150 struct cb_record *rec = (struct cb_record *)ptr;
152 /* We only care about a few tags here (maybe more later). */
155 return cb_parse_header(
156 (void *)(unsigned long)
157 ((struct cb_forward *)rec)->forward,
161 cb_parse_memory(ptr, info);
164 cb_parse_serial(ptr, info);
167 cb_parse_string(ptr, &info->version);
169 case CB_TAG_EXTRA_VERSION:
170 cb_parse_string(ptr, &info->extra_version);
173 cb_parse_string(ptr, &info->build);
175 case CB_TAG_COMPILE_TIME:
176 cb_parse_string(ptr, &info->compile_time);
178 case CB_TAG_COMPILE_BY:
179 cb_parse_string(ptr, &info->compile_by);
181 case CB_TAG_COMPILE_HOST:
182 cb_parse_string(ptr, &info->compile_host);
184 case CB_TAG_COMPILE_DOMAIN:
185 cb_parse_string(ptr, &info->compile_domain);
187 case CB_TAG_COMPILER:
188 cb_parse_string(ptr, &info->compiler);
191 cb_parse_string(ptr, &info->linker);
193 case CB_TAG_ASSEMBLER:
194 cb_parse_string(ptr, &info->assembler);
197 * FIXME we should warn on serial if coreboot set up a
198 * framebuffer buf the payload does not know about it.
200 case CB_TAG_FRAMEBUFFER:
201 cb_parse_framebuffer(ptr, info);
204 cb_parse_gpios(ptr, info);
207 cb_parse_vdat(ptr, info);
209 case CB_TAG_TIMESTAMPS:
210 cb_parse_tstamp(ptr, info);
212 case CB_TAG_CBMEM_CONSOLE:
213 cb_parse_cbmem_cons(ptr, info);
216 cb_parse_vbnv(ptr, info);
219 cb_parse_unhandled(rec->tag, ptr);
229 /* == Architecture specific == */
230 /* This is the x86 specific stuff. */
232 int get_coreboot_info(struct sysinfo_t *info)
234 int ret = cb_parse_header((void *)0x00000000, 0x1000, info);
237 ret = cb_parse_header((void *)0x000f0000, 0x1000, info);
239 return (ret == 1) ? 0 : -1;