2 * This file is part of the libpayload project.
4 * Copyright (C) 2008 Advanced Micro Devices, Inc.
5 * Copyright (C) 2009 coresystems GmbH
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <asm/arch-coreboot/ipchecksum.h>
33 #include <asm/arch-coreboot/sysinfo.h>
34 #include <asm/arch-coreboot/tables.h>
37 * This needs to be in the .data section so that it's copied over during
38 * relocation. By default it's put in the .bss section which is simply filled
39 * with zeroes when transitioning from "ROM", which is really RAM, to other
42 struct sysinfo_t lib_sysinfo __attribute__((section(".data")));
45 * Some of this is x86 specific, and the rest of it is generic. Right now,
46 * since we only support x86, we'll avoid trying to make lots of infrastructure
47 * we don't need. If in the future, we want to use coreboot on some other
48 * architecture, then take out the generic parsing code and move it elsewhere.
51 /* === Parsing code === */
52 /* This is the generic parsing code. */
54 static void cb_parse_memory(unsigned char *ptr, struct sysinfo_t *info)
56 struct cb_memory *mem = (struct cb_memory *)ptr;
57 int count = MEM_RANGE_COUNT(mem);
60 if (count > SYSINFO_MAX_MEM_RANGES)
61 count = SYSINFO_MAX_MEM_RANGES;
63 info->n_memranges = 0;
65 for (i = 0; i < count; i++) {
66 struct cb_memory_range *range =
67 (struct cb_memory_range *)MEM_RANGE_PTR(mem, i);
69 info->memrange[info->n_memranges].base =
70 UNPACK_CB64(range->start);
72 info->memrange[info->n_memranges].size =
73 UNPACK_CB64(range->size);
75 info->memrange[info->n_memranges].type = range->type;
81 static void cb_parse_serial(unsigned char *ptr, struct sysinfo_t *info)
83 struct cb_serial *ser = (struct cb_serial *)ptr;
87 static void cb_parse_vbnv(unsigned char *ptr, struct sysinfo_t *info)
89 struct cb_vbnv *vbnv = (struct cb_vbnv *)ptr;
91 info->vbnv_start = vbnv->vbnv_start;
92 info->vbnv_size = vbnv->vbnv_size;
95 static void cb_parse_gpios(unsigned char *ptr, struct sysinfo_t *info)
98 struct cb_gpios *gpios = (struct cb_gpios *)ptr;
100 info->num_gpios = (gpios->count < SYSINFO_MAX_GPIOS) ?
101 (gpios->count) : SYSINFO_MAX_GPIOS;
103 for (i = 0; i < info->num_gpios; i++)
104 info->gpios[i] = gpios->gpios[i];
107 static void cb_parse_vdat(unsigned char *ptr, struct sysinfo_t *info)
109 struct cb_vdat *vdat = (struct cb_vdat *) ptr;
111 info->vdat_addr = vdat->vdat_addr;
112 info->vdat_size = vdat->vdat_size;
115 static void cb_parse_tstamp(unsigned char *ptr, struct sysinfo_t *info)
117 info->tstamp_table = ((struct cb_cbmem_tab *)ptr)->cbmem_tab;
120 static void cb_parse_cbmem_cons(unsigned char *ptr, struct sysinfo_t *info)
122 info->cbmem_cons = ((struct cb_cbmem_tab *)ptr)->cbmem_tab;
125 static void cb_parse_framebuffer(unsigned char *ptr, struct sysinfo_t *info)
127 info->framebuffer = (struct cb_framebuffer *)ptr;
130 static void cb_parse_string(unsigned char *ptr, char **info)
132 *info = (char *)((struct cb_string *)ptr)->string;
135 static int cb_parse_header(void *addr, int len, struct sysinfo_t *info)
137 struct cb_header *header;
138 unsigned char *ptr = (unsigned char *)addr;
141 for (i = 0; i < len; i += 16, ptr += 16) {
142 header = (struct cb_header *)ptr;
143 if (!strncmp((const char *)header->signature, "LBIO", 4))
147 /* We walked the entire space and didn't find anything. */
151 if (!header->table_bytes)
154 /* Make sure the checksums match. */
155 if (ipchksum((u16 *) header, sizeof(*header)) != 0)
158 if (ipchksum((u16 *) (ptr + sizeof(*header)),
159 header->table_bytes) != header->table_checksum)
162 /* Now, walk the tables. */
163 ptr += header->header_bytes;
165 /* Inintialize some fields to sentinel values. */
166 info->vbnv_start = info->vbnv_size = (uint32_t)(-1);
168 for (i = 0; i < header->table_entries; i++) {
169 struct cb_record *rec = (struct cb_record *)ptr;
171 /* We only care about a few tags here (maybe more later). */
174 return cb_parse_header(
175 (void *)(unsigned long)
176 ((struct cb_forward *)rec)->forward,
180 cb_parse_memory(ptr, info);
183 cb_parse_serial(ptr, info);
186 cb_parse_string(ptr, &info->version);
188 case CB_TAG_EXTRA_VERSION:
189 cb_parse_string(ptr, &info->extra_version);
192 cb_parse_string(ptr, &info->build);
194 case CB_TAG_COMPILE_TIME:
195 cb_parse_string(ptr, &info->compile_time);
197 case CB_TAG_COMPILE_BY:
198 cb_parse_string(ptr, &info->compile_by);
200 case CB_TAG_COMPILE_HOST:
201 cb_parse_string(ptr, &info->compile_host);
203 case CB_TAG_COMPILE_DOMAIN:
204 cb_parse_string(ptr, &info->compile_domain);
206 case CB_TAG_COMPILER:
207 cb_parse_string(ptr, &info->compiler);
210 cb_parse_string(ptr, &info->linker);
212 case CB_TAG_ASSEMBLER:
213 cb_parse_string(ptr, &info->assembler);
216 * FIXME we should warn on serial if coreboot set up a
217 * framebuffer buf the payload does not know about it.
219 case CB_TAG_FRAMEBUFFER:
220 cb_parse_framebuffer(ptr, info);
223 cb_parse_gpios(ptr, info);
226 cb_parse_vdat(ptr, info);
228 case CB_TAG_TIMESTAMPS:
229 cb_parse_tstamp(ptr, info);
231 case CB_TAG_CBMEM_CONSOLE:
232 cb_parse_cbmem_cons(ptr, info);
235 cb_parse_vbnv(ptr, info);
245 /* == Architecture specific == */
246 /* This is the x86 specific stuff. */
248 int get_coreboot_info(struct sysinfo_t *info)
250 int ret = cb_parse_header((void *)0x00000000, 0x1000, info);
253 ret = cb_parse_header((void *)0x000f0000, 0x1000, info);
255 return (ret == 1) ? 0 : -1;