2 * This file is part of the libpayload project.
4 * Copyright (C) 2008 Advanced Micro Devices, Inc.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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.
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
30 #include <libpayload.h>
31 #include <coreboot_tables.h>
34 * Some of this is x86 specific, and the rest of it is generic. Right now,
35 * since we only support x86, we'll avoid trying to make lots of infrastructure
36 * we don't need. If in the future, we want to use coreboot on some other
37 * architecture, then take out the generic parsing code and move it elsewhere.
40 /* === Parsing code === */
41 /* This is the generic parsing code. */
43 static void cb_parse_memory(unsigned char *ptr, struct sysinfo_t *info)
45 struct cb_memory *mem = (struct cb_memory *)ptr;
46 int count = MEM_RANGE_COUNT(mem);
49 if (count > SYSINFO_MAX_MEM_RANGES)
50 count = SYSINFO_MAX_MEM_RANGES;
52 info->n_memranges = 0;
54 for (i = 0; i < count; i++) {
55 struct cb_memory_range *range =
56 (struct cb_memory_range *)MEM_RANGE_PTR(mem, i);
58 if (range->type != CB_MEM_RAM)
61 info->memrange[info->n_memranges].base =
62 UNPACK_CB64(range->start);
64 info->memrange[info->n_memranges].size =
65 UNPACK_CB64(range->size);
71 static void cb_parse_serial(unsigned char *ptr, struct sysinfo_t *info)
73 struct cb_serial *ser = (struct cb_serial *)ptr;
74 info->ser_ioport = ser->ioport;
78 static void cb_parse_optiontable(unsigned char *ptr, struct sysinfo_t *info)
80 info->option_table = (struct cb_cmos_option_table *)ptr;
83 static void cb_parse_checksum(unsigned char *ptr, struct sysinfo_t *info)
85 struct cb_cmos_checksum *cmos_cksum = (struct cb_cmos_checksum *)ptr;
86 info->cmos_range_start = cmos_cksum->range_start;
87 info->cmos_range_end = cmos_cksum->range_end;
88 info->cmos_checksum_location = cmos_cksum->location;
92 static int cb_parse_header(void *addr, int len, struct sysinfo_t *info)
94 struct cb_header *header;
95 unsigned char *ptr = (unsigned char *)addr;
98 for (i = 0; i < len; i += 16, ptr += 16) {
99 header = (struct cb_header *)ptr;
100 if (!strncmp((const char *)header->signature, "LBIO", 4))
104 /* We walked the entire space and didn't find anything. */
108 if (!header->table_bytes)
111 /* Make sure the checksums match. */
112 if (ipchksum((u16 *) header, sizeof(*header)) != 0)
115 if (ipchksum((u16 *) (ptr + sizeof(*header)),
116 header->table_bytes) != header->table_checksum)
119 /* Now, walk the tables. */
120 ptr += header->header_bytes;
122 for (i = 0; i < header->table_entries; i++) {
123 struct cb_record *rec = (struct cb_record *)ptr;
125 /* We only care about a few tags here (maybe more later). */
128 cb_parse_memory(ptr, info);
131 cb_parse_serial(ptr, info);
134 case CB_TAG_CMOS_OPTION_TABLE:
135 cb_parse_optiontable(ptr, info);
137 case CB_TAG_OPTION_CHECKSUM:
138 cb_parse_checksum(ptr, info);
149 /* == Architecture specific == */
150 /* This is the x86 specific stuff. */
152 int get_coreboot_info(struct sysinfo_t *info)
154 int ret = cb_parse_header((void *)0x0, 0x1000, info);
157 ret = cb_parse_header((void *)0xf0000, 0x1000, info);
159 return (ret == 1) ? 0 : -1;