2 * Copyright (C) 2016, Bin Meng <bmeng.cn@gmail.com>
4 * SPDX-License-Identifier: GPL-2.0+
9 #include <asm/coreboot_tables.h>
12 DECLARE_GLOBAL_DATA_PTR;
14 int high_table_reserve(void)
16 /* adjust stack pointer to reserve space for configuration tables */
17 gd->arch.high_table_limit = gd->start_addr_sp;
18 gd->start_addr_sp -= CONFIG_HIGH_TABLE_SIZE;
19 gd->arch.high_table_ptr = gd->start_addr_sp;
21 /* clear the memory */
22 memset((void *)gd->arch.high_table_ptr, 0, CONFIG_HIGH_TABLE_SIZE);
24 gd->start_addr_sp &= ~0xf;
29 void *high_table_malloc(size_t bytes)
34 new_ptr = gd->arch.high_table_ptr + bytes;
35 if (new_ptr >= gd->arch.high_table_limit)
37 ptr = (void *)gd->arch.high_table_ptr;
38 gd->arch.high_table_ptr = new_ptr;
44 * cb_table_init() - initialize a coreboot table header
46 * This fills in the coreboot table header signature and the header bytes.
47 * Other fields are set to zero.
49 * @cbh: coreboot table header address
51 static void cb_table_init(struct cb_header *cbh)
53 memset(cbh, 0, sizeof(struct cb_header));
54 memcpy(cbh->signature, "LBIO", 4);
55 cbh->header_bytes = sizeof(struct cb_header);
59 * cb_table_add_entry() - add a coreboot table entry
61 * This increases the coreboot table entry size with added table entry length
62 * and increases entry count by 1.
64 * @cbh: coreboot table header address
65 * @cbr: to be added table entry address
66 * @return: pointer to next table entry address
68 static u32 cb_table_add_entry(struct cb_header *cbh, struct cb_record *cbr)
70 cbh->table_bytes += cbr->size;
73 return (u32)cbr + cbr->size;
77 * cb_table_finalize() - finalize the coreboot table
79 * This calculates the checksum for all coreboot table entries as well as
80 * the checksum for the coreboot header itself.
82 * @cbh: coreboot table header address
84 static void cb_table_finalize(struct cb_header *cbh)
86 struct cb_record *cbr = (struct cb_record *)(cbh + 1);
88 cbh->table_checksum = compute_ip_checksum(cbr, cbh->table_bytes);
89 cbh->header_checksum = compute_ip_checksum(cbh, cbh->header_bytes);
92 void write_coreboot_table(u32 addr, struct memory_area *cfg_tables)
94 struct cb_header *cbh = (struct cb_header *)addr;
95 struct cb_record *cbr;
96 struct cb_memory *mem;
97 struct cb_memory_range *map;
98 struct e820entry e820[32];
99 struct cb_framebuffer *fb;
100 struct vesa_mode_info *vesa;
104 cbr = (struct cb_record *)(cbh + 1);
107 * Two type of coreboot table entries are generated by us.
108 * They are 'struct cb_memory' and 'struct cb_framebuffer'.
111 /* populate memory map table */
112 mem = (struct cb_memory *)cbr;
113 mem->tag = CB_TAG_MEMORY;
116 /* first install e820 defined memory maps */
117 num = install_e820_map(ARRAY_SIZE(e820), e820);
118 for (i = 0; i < num; i++) {
119 map->start.lo = e820[i].addr & 0xffffffff;
120 map->start.hi = e820[i].addr >> 32;
121 map->size.lo = e820[i].size & 0xffffffff;
122 map->size.hi = e820[i].size >> 32;
123 map->type = e820[i].type;
127 /* then install all configuration tables */
128 while (cfg_tables->size) {
129 map->start.lo = cfg_tables->start & 0xffffffff;
130 map->start.hi = cfg_tables->start >> 32;
131 map->size.lo = cfg_tables->size & 0xffffffff;
132 map->size.hi = cfg_tables->size >> 32;
133 map->type = CB_MEM_TABLE;
138 mem->size = num * sizeof(struct cb_memory_range) +
139 sizeof(struct cb_record);
140 cbr = (struct cb_record *)cb_table_add_entry(cbh, cbr);
142 /* populate framebuffer table if we have sane vesa info */
143 vesa = &mode_info.vesa;
144 if (vesa->x_resolution && vesa->y_resolution) {
145 fb = (struct cb_framebuffer *)cbr;
146 fb->tag = CB_TAG_FRAMEBUFFER;
147 fb->size = sizeof(struct cb_framebuffer);
149 fb->x_resolution = vesa->x_resolution;
150 fb->y_resolution = vesa->y_resolution;
151 fb->bits_per_pixel = vesa->bits_per_pixel;
152 fb->bytes_per_line = vesa->bytes_per_scanline;
153 fb->physical_address = vesa->phys_base_ptr;
154 fb->red_mask_size = vesa->red_mask_size;
155 fb->red_mask_pos = vesa->red_mask_pos;
156 fb->green_mask_size = vesa->green_mask_size;
157 fb->green_mask_pos = vesa->green_mask_pos;
158 fb->blue_mask_size = vesa->blue_mask_size;
159 fb->blue_mask_pos = vesa->blue_mask_pos;
160 fb->reserved_mask_size = vesa->reserved_mask_size;
161 fb->reserved_mask_pos = vesa->reserved_mask_pos;
163 cbr = (struct cb_record *)cb_table_add_entry(cbh, cbr);
166 cb_table_finalize(cbh);