]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
5e2400e8 BM |
2 | /* |
3 | * Copyright (C) 2015, Bin Meng <[email protected]> | |
5e2400e8 BM |
4 | */ |
5 | ||
8856d613 | 6 | #define LOG_CATEGORY LOGC_ACPI |
c193d9bd | 7 | |
5e2400e8 | 8 | #include <common.h> |
d2cb7a22 | 9 | #include <bloblist.h> |
b336a2b8 | 10 | #include <log.h> |
336d4615 | 11 | #include <malloc.h> |
4b6dddc2 | 12 | #include <smbios.h> |
776cc201 | 13 | #include <acpi/acpi_table.h> |
401d1c4f | 14 | #include <asm/global_data.h> |
6388e357 | 15 | #include <asm/sfi.h> |
07545d86 | 16 | #include <asm/mpspec.h> |
5e2400e8 | 17 | #include <asm/tables.h> |
3cf23719 | 18 | #include <asm/coreboot_tables.h> |
1a2e02f9 | 19 | #include <linux/log2.h> |
5e2400e8 | 20 | |
d2cb7a22 SG |
21 | DECLARE_GLOBAL_DATA_PTR; |
22 | ||
ef4d0a52 BM |
23 | /** |
24 | * Function prototype to write a specific configuration table | |
25 | * | |
26 | * @addr: start address to write the table | |
27 | * @return: end address of the table | |
28 | */ | |
42fd8c19 | 29 | typedef ulong (*table_write)(ulong addr); |
ef4d0a52 | 30 | |
b336a2b8 SG |
31 | /** |
32 | * struct table_info - Information about each table to write | |
33 | * | |
34 | * @name: Name of table (for debugging) | |
35 | * @write: Function to call to write this table | |
d2cb7a22 SG |
36 | * @tag: Bloblist tag if using CONFIG_BLOBLIST_TABLES |
37 | * @size: Maximum table size | |
38 | * @align: Table alignment in bytes | |
b336a2b8 SG |
39 | */ |
40 | struct table_info { | |
41 | const char *name; | |
42 | table_write write; | |
d2cb7a22 SG |
43 | enum bloblist_tag_t tag; |
44 | int size; | |
45 | int align; | |
b336a2b8 SG |
46 | }; |
47 | ||
48 | static struct table_info table_list[] = { | |
ef4d0a52 | 49 | #ifdef CONFIG_GENERATE_PIRQ_TABLE |
b336a2b8 | 50 | { "pirq", write_pirq_routing_table }, |
ef4d0a52 BM |
51 | #endif |
52 | #ifdef CONFIG_GENERATE_SFI_TABLE | |
b336a2b8 | 53 | { "sfi", write_sfi_table, }, |
ef4d0a52 BM |
54 | #endif |
55 | #ifdef CONFIG_GENERATE_MP_TABLE | |
b336a2b8 | 56 | { "mp", write_mp_table, }, |
ef4d0a52 | 57 | #endif |
6a324897 SG |
58 | /* |
59 | * tables which can go in the bloblist must be last in this list, so | |
60 | * that the calculation of gd->table_end works properly | |
61 | */ | |
ef4d0a52 | 62 | #ifdef CONFIG_GENERATE_ACPI_TABLE |
d2cb7a22 | 63 | { "acpi", write_acpi_tables, BLOBLISTT_ACPI_TABLES, 0x10000, 0x1000}, |
ef4d0a52 | 64 | #endif |
1c5aab80 | 65 | #if defined(CONFIG_GENERATE_SMBIOS_TABLE) && !defined(CONFIG_QFW_SMBIOS) |
d2cb7a22 | 66 | { "smbios", write_smbios_table, BLOBLISTT_SMBIOS_TABLES, 0x1000, 0x100}, |
ef4d0a52 BM |
67 | #endif |
68 | }; | |
69 | ||
7f5df8d4 BM |
70 | void table_fill_string(char *dest, const char *src, size_t n, char pad) |
71 | { | |
72 | int start, len; | |
73 | int i; | |
74 | ||
75 | strncpy(dest, src, n); | |
76 | ||
77 | /* Fill the remaining bytes with pad */ | |
78 | len = strlen(src); | |
79 | start = len < n ? len : n; | |
80 | for (i = start; i < n; i++) | |
81 | dest[i] = pad; | |
82 | } | |
83 | ||
38e498c3 | 84 | int write_tables(void) |
5e2400e8 | 85 | { |
ff94c219 | 86 | u32 high_table, table_size; |
b336a2b8 | 87 | struct memory_area cfg_tables[ARRAY_SIZE(table_list) + 1]; |
6a324897 | 88 | bool use_high = false; |
8856d613 | 89 | u32 rom_addr; |
ef4d0a52 | 90 | int i; |
5e2400e8 | 91 | |
6a324897 SG |
92 | gd->arch.table_start = ROM_TABLE_ADDR; |
93 | rom_addr = gd->arch.table_start; | |
d2cb7a22 | 94 | |
8856d613 | 95 | debug("Writing tables to %x:\n", rom_addr); |
b336a2b8 SG |
96 | for (i = 0; i < ARRAY_SIZE(table_list); i++) { |
97 | const struct table_info *table = &table_list[i]; | |
d2cb7a22 | 98 | int size = table->size ? : CONFIG_ROM_TABLE_SIZE; |
8856d613 | 99 | u32 rom_table_end; |
b336a2b8 | 100 | |
50834884 SG |
101 | if (!strcmp("smbios", table->name)) |
102 | gd->arch.smbios_start = rom_addr; | |
103 | ||
d2cb7a22 | 104 | if (IS_ENABLED(CONFIG_BLOBLIST_TABLES) && table->tag) { |
6a324897 SG |
105 | if (!gd->arch.table_end) |
106 | gd->arch.table_end = rom_addr; | |
8856d613 | 107 | rom_addr = (ulong)bloblist_add(table->tag, size, |
1a2e02f9 | 108 | ilog2(table->align)); |
8856d613 | 109 | if (!rom_addr) |
d2cb7a22 | 110 | return log_msg_ret("bloblist", -ENOBUFS); |
6a324897 SG |
111 | |
112 | /* the bloblist is always in high memory */ | |
113 | use_high = true; | |
114 | if (!gd->arch.table_start_high) | |
115 | gd->arch.table_start_high = rom_addr; | |
d2cb7a22 | 116 | } |
8856d613 | 117 | rom_table_end = table->write(rom_addr); |
c193d9bd HS |
118 | if (!rom_table_end) { |
119 | log_err("Can't create configuration table %d\n", i); | |
120 | return -EINTR; | |
121 | } | |
ff94c219 | 122 | |
f36e4c7d | 123 | if (IS_ENABLED(CONFIG_SEABIOS)) { |
8856d613 | 124 | table_size = rom_table_end - rom_addr; |
f36e4c7d SG |
125 | high_table = (u32)(ulong)high_table_malloc(table_size); |
126 | if (high_table) { | |
c193d9bd HS |
127 | if (!table->write(high_table)) { |
128 | log_err("Can't create configuration table %d\n", | |
129 | i); | |
130 | return -EINTR; | |
131 | } | |
f36e4c7d SG |
132 | |
133 | cfg_tables[i].start = high_table; | |
134 | cfg_tables[i].size = table_size; | |
135 | } else { | |
136 | printf("%d: no memory for configuration tables\n", | |
137 | i); | |
138 | return -ENOSPC; | |
139 | } | |
ff94c219 BM |
140 | } |
141 | ||
b336a2b8 | 142 | debug("- wrote '%s' to %x, end %x\n", table->name, |
8856d613 SG |
143 | rom_addr, rom_table_end); |
144 | if (rom_table_end - rom_addr > size) { | |
d2cb7a22 | 145 | log_err("Out of space for configuration tables: need %x, have %x\n", |
8856d613 | 146 | rom_table_end - rom_addr, size); |
d2cb7a22 SG |
147 | return log_msg_ret("bloblist", -ENOSPC); |
148 | } | |
8856d613 | 149 | rom_addr = rom_table_end; |
ef4d0a52 | 150 | } |
3cf23719 | 151 | |
6a324897 SG |
152 | if (use_high) |
153 | gd->arch.table_end_high = rom_addr; | |
154 | else | |
155 | gd->arch.table_end = rom_addr; | |
156 | ||
f36e4c7d SG |
157 | if (IS_ENABLED(CONFIG_SEABIOS)) { |
158 | /* make sure the last item is zero */ | |
159 | cfg_tables[i].size = 0; | |
160 | write_coreboot_table(CB_TABLE_ADDR, cfg_tables); | |
161 | } | |
162 | ||
d2cb7a22 SG |
163 | if (IS_ENABLED(CONFIG_BLOBLIST_TABLES)) { |
164 | void *ptr = (void *)CONFIG_ROM_TABLE_ADDR; | |
165 | ||
166 | /* Write an RSDP pointing to the tables */ | |
167 | if (IS_ENABLED(CONFIG_GENERATE_ACPI_TABLE)) { | |
168 | struct acpi_ctx *ctx = gd_acpi_ctx(); | |
169 | ||
170 | acpi_write_rsdp(ptr, ctx->rsdt, ctx->xsdt); | |
171 | ptr += ALIGN(sizeof(struct acpi_rsdp), 16); | |
172 | } | |
173 | if (IS_ENABLED(CONFIG_GENERATE_SMBIOS_TABLE)) { | |
174 | void *smbios; | |
175 | ||
176 | smbios = bloblist_find(BLOBLISTT_SMBIOS_TABLES, 0); | |
177 | if (!smbios) | |
178 | return log_msg_ret("smbios", -ENOENT); | |
179 | memcpy(ptr, smbios, sizeof(struct smbios_entry)); | |
180 | } | |
181 | } | |
182 | ||
b336a2b8 | 183 | debug("- done writing tables\n"); |
38e498c3 SG |
184 | |
185 | return 0; | |
5e2400e8 | 186 | } |