1
2
3
4
5
6
7
8
9#include <common.h>
10#include <net.h>
11#include <asm/arch/sysinfo.h>
12
13DECLARE_GLOBAL_DATA_PTR;
14
15
16
17
18
19
20
21struct sysinfo_t lib_sysinfo __attribute__((section(".data")));
22
23
24
25
26
27
28
29
30
31
32
33static void cb_parse_memory(unsigned char *ptr, struct sysinfo_t *info)
34{
35 struct cb_memory *mem = (struct cb_memory *)ptr;
36 int count = MEM_RANGE_COUNT(mem);
37 int i;
38
39 if (count > SYSINFO_MAX_MEM_RANGES)
40 count = SYSINFO_MAX_MEM_RANGES;
41
42 info->n_memranges = 0;
43
44 for (i = 0; i < count; i++) {
45 struct cb_memory_range *range =
46 (struct cb_memory_range *)MEM_RANGE_PTR(mem, i);
47
48 info->memrange[info->n_memranges].base =
49 UNPACK_CB64(range->start);
50
51 info->memrange[info->n_memranges].size =
52 UNPACK_CB64(range->size);
53
54 info->memrange[info->n_memranges].type = range->type;
55
56 info->n_memranges++;
57 }
58}
59
60static void cb_parse_serial(unsigned char *ptr, struct sysinfo_t *info)
61{
62 struct cb_serial *ser = (struct cb_serial *)ptr;
63 info->serial = ser;
64}
65
66static void cb_parse_vbnv(unsigned char *ptr, struct sysinfo_t *info)
67{
68 struct cb_vbnv *vbnv = (struct cb_vbnv *)ptr;
69
70 info->vbnv_start = vbnv->vbnv_start;
71 info->vbnv_size = vbnv->vbnv_size;
72}
73
74static void cb_parse_cbmem_entry(unsigned char *ptr, struct sysinfo_t *info)
75{
76 struct cb_cbmem_entry *entry = (struct cb_cbmem_entry *)ptr;
77
78 if (entry->id != CBMEM_ID_SMBIOS)
79 return;
80
81 info->smbios_start = entry->address;
82 info->smbios_size = entry->entry_size;
83}
84
85static void cb_parse_gpios(unsigned char *ptr, struct sysinfo_t *info)
86{
87 int i;
88 struct cb_gpios *gpios = (struct cb_gpios *)ptr;
89
90 info->num_gpios = (gpios->count < SYSINFO_MAX_GPIOS) ?
91 (gpios->count) : SYSINFO_MAX_GPIOS;
92
93 for (i = 0; i < info->num_gpios; i++)
94 info->gpios[i] = gpios->gpios[i];
95}
96
97static void cb_parse_vdat(unsigned char *ptr, struct sysinfo_t *info)
98{
99 struct cb_vdat *vdat = (struct cb_vdat *) ptr;
100
101 info->vdat_addr = vdat->vdat_addr;
102 info->vdat_size = vdat->vdat_size;
103}
104
105static void cb_parse_tstamp(unsigned char *ptr, struct sysinfo_t *info)
106{
107 info->tstamp_table = ((struct cb_cbmem_tab *)ptr)->cbmem_tab;
108}
109
110static void cb_parse_cbmem_cons(unsigned char *ptr, struct sysinfo_t *info)
111{
112 info->cbmem_cons = ((struct cb_cbmem_tab *)ptr)->cbmem_tab;
113}
114
115static void cb_parse_framebuffer(unsigned char *ptr, struct sysinfo_t *info)
116{
117 info->framebuffer = (struct cb_framebuffer *)ptr;
118}
119
120static void cb_parse_string(unsigned char *ptr, char **info)
121{
122 *info = (char *)((struct cb_string *)ptr)->string;
123}
124
125__weak void cb_parse_unhandled(u32 tag, unsigned char *ptr)
126{
127}
128
129static int cb_parse_header(void *addr, int len, struct sysinfo_t *info)
130{
131 unsigned char *ptr = addr;
132 struct cb_header *header;
133 int i;
134
135 header = (struct cb_header *)ptr;
136 if (!header->table_bytes)
137 return 0;
138
139
140 if (!ip_checksum_ok(header, sizeof(*header)))
141 return -1;
142
143 if (compute_ip_checksum(ptr + sizeof(*header), header->table_bytes) !=
144 header->table_checksum)
145 return -1;
146
147
148 ptr += header->header_bytes;
149
150
151 info->vbnv_start = info->vbnv_size = (uint32_t)(-1);
152
153 for (i = 0; i < header->table_entries; i++) {
154 struct cb_record *rec = (struct cb_record *)ptr;
155
156
157 switch (rec->tag) {
158 case CB_TAG_FORWARD:
159 return cb_parse_header(
160 (void *)(unsigned long)
161 ((struct cb_forward *)rec)->forward,
162 len, info);
163 continue;
164 case CB_TAG_MEMORY:
165 cb_parse_memory(ptr, info);
166 break;
167 case CB_TAG_SERIAL:
168 cb_parse_serial(ptr, info);
169 break;
170 case CB_TAG_VERSION:
171 cb_parse_string(ptr, &info->version);
172 break;
173 case CB_TAG_EXTRA_VERSION:
174 cb_parse_string(ptr, &info->extra_version);
175 break;
176 case CB_TAG_BUILD:
177 cb_parse_string(ptr, &info->build);
178 break;
179 case CB_TAG_COMPILE_TIME:
180 cb_parse_string(ptr, &info->compile_time);
181 break;
182 case CB_TAG_COMPILE_BY:
183 cb_parse_string(ptr, &info->compile_by);
184 break;
185 case CB_TAG_COMPILE_HOST:
186 cb_parse_string(ptr, &info->compile_host);
187 break;
188 case CB_TAG_COMPILE_DOMAIN:
189 cb_parse_string(ptr, &info->compile_domain);
190 break;
191 case CB_TAG_COMPILER:
192 cb_parse_string(ptr, &info->compiler);
193 break;
194 case CB_TAG_LINKER:
195 cb_parse_string(ptr, &info->linker);
196 break;
197 case CB_TAG_ASSEMBLER:
198 cb_parse_string(ptr, &info->assembler);
199 break;
200
201
202
203
204 case CB_TAG_FRAMEBUFFER:
205 cb_parse_framebuffer(ptr, info);
206 break;
207 case CB_TAG_GPIO:
208 cb_parse_gpios(ptr, info);
209 break;
210 case CB_TAG_VDAT:
211 cb_parse_vdat(ptr, info);
212 break;
213 case CB_TAG_TIMESTAMPS:
214 cb_parse_tstamp(ptr, info);
215 break;
216 case CB_TAG_CBMEM_CONSOLE:
217 cb_parse_cbmem_cons(ptr, info);
218 break;
219 case CB_TAG_VBNV:
220 cb_parse_vbnv(ptr, info);
221 break;
222 case CB_TAG_CBMEM_ENTRY:
223 cb_parse_cbmem_entry(ptr, info);
224 break;
225 default:
226 cb_parse_unhandled(rec->tag, ptr);
227 break;
228 }
229
230 ptr += rec->size;
231 }
232
233 return 1;
234}
235
236
237
238
239int get_coreboot_info(struct sysinfo_t *info)
240{
241 long addr;
242 int ret;
243
244 addr = locate_coreboot_table();
245 if (addr < 0)
246 return addr;
247 ret = cb_parse_header((void *)addr, 0x1000, info);
248 if (!ret)
249 return -ENOENT;
250 gd->arch.coreboot_table = addr;
251 gd->flags |= GD_FLG_SKIP_LL_INIT;
252
253 return 0;
254}
255