2 * Copyright (C) 2016, Bin Meng <bmeng.cn@gmail.com>
4 * SPDX-License-Identifier: GPL-2.0+
9 #include <asm/coreboot_tables.h>
13 * cb_table_init() - initialize a coreboot table header
15 * This fills in the coreboot table header signature and the header bytes.
16 * Other fields are set to zero.
18 * @cbh: coreboot table header address
20 static void cb_table_init(struct cb_header *cbh)
22 memset(cbh, 0, sizeof(struct cb_header));
23 memcpy(cbh->signature, "LBIO", 4);
24 cbh->header_bytes = sizeof(struct cb_header);
28 * cb_table_add_entry() - add a coreboot table entry
30 * This increases the coreboot table entry size with added table entry length
31 * and increases entry count by 1.
33 * @cbh: coreboot table header address
34 * @cbr: to be added table entry address
35 * @return: pointer to next table entry address
37 static u32 cb_table_add_entry(struct cb_header *cbh, struct cb_record *cbr)
39 cbh->table_bytes += cbr->size;
42 return (u32)cbr + cbr->size;
46 * cb_table_finalize() - finalize the coreboot table
48 * This calculates the checksum for all coreboot table entries as well as
49 * the checksum for the coreboot header itself.
51 * @cbh: coreboot table header address
53 static void cb_table_finalize(struct cb_header *cbh)
55 struct cb_record *cbr = (struct cb_record *)(cbh + 1);
57 cbh->table_checksum = compute_ip_checksum(cbr, cbh->table_bytes);
58 cbh->header_checksum = compute_ip_checksum(cbh, cbh->header_bytes);
61 void write_coreboot_table(u32 addr, struct memory_area *cfg_tables)
63 struct cb_header *cbh = (struct cb_header *)addr;
64 struct cb_record *cbr;
65 struct cb_memory *mem;
66 struct cb_memory_range *map;
67 struct e820entry e820[32];
68 struct cb_framebuffer *fb;
69 struct vesa_mode_info *vesa;
73 cbr = (struct cb_record *)(cbh + 1);
76 * Two type of coreboot table entries are generated by us.
77 * They are 'struct cb_memory' and 'struct cb_framebuffer'.
80 /* populate memory map table */
81 mem = (struct cb_memory *)cbr;
82 mem->tag = CB_TAG_MEMORY;
85 /* first install e820 defined memory maps */
86 num = install_e820_map(ARRAY_SIZE(e820), e820);
87 for (i = 0; i < num; i++) {
88 map->start.lo = e820[i].addr & 0xffffffff;
89 map->start.hi = e820[i].addr >> 32;
90 map->size.lo = e820[i].size & 0xffffffff;
91 map->size.hi = e820[i].size >> 32;
92 map->type = e820[i].type;
96 /* then install all configuration tables */
97 while (cfg_tables->size) {
98 map->start.lo = cfg_tables->start & 0xffffffff;
99 map->start.hi = cfg_tables->start >> 32;
100 map->size.lo = cfg_tables->size & 0xffffffff;
101 map->size.hi = cfg_tables->size >> 32;
102 map->type = CB_MEM_TABLE;
107 mem->size = num * sizeof(struct cb_memory_range) +
108 sizeof(struct cb_record);
109 cbr = (struct cb_record *)cb_table_add_entry(cbh, cbr);
111 /* populate framebuffer table if we have sane vesa info */
112 vesa = &mode_info.vesa;
113 if (vesa->x_resolution && vesa->y_resolution) {
114 fb = (struct cb_framebuffer *)cbr;
115 fb->tag = CB_TAG_FRAMEBUFFER;
116 fb->size = sizeof(struct cb_framebuffer);
118 fb->x_resolution = vesa->x_resolution;
119 fb->y_resolution = vesa->y_resolution;
120 fb->bits_per_pixel = vesa->bits_per_pixel;
121 fb->bytes_per_line = vesa->bytes_per_scanline;
122 fb->physical_address = vesa->phys_base_ptr;
123 fb->red_mask_size = vesa->red_mask_size;
124 fb->red_mask_pos = vesa->red_mask_pos;
125 fb->green_mask_size = vesa->green_mask_size;
126 fb->green_mask_pos = vesa->green_mask_pos;
127 fb->blue_mask_size = vesa->blue_mask_size;
128 fb->blue_mask_pos = vesa->blue_mask_pos;
129 fb->reserved_mask_size = vesa->reserved_mask_size;
130 fb->reserved_mask_pos = vesa->reserved_mask_pos;
132 cbr = (struct cb_record *)cb_table_add_entry(cbh, cbr);
135 cb_table_finalize(cbh);