blob: 8cfd6555a017d8964edecdfe6d35f7f4a2751a91 [file] [log] [blame]
Stefan Reinauer3c7f46b2009-02-27 23:09:55 +00001/*
2 * This file is part of the coreboot project.
3 *
Stefan Reinauerf2152ec2009-05-26 14:07:44 +00004 * Copyright (C) 2003 Eric Biederman
5 * Copyright (C) 2005 Steve Magnani
Stefan Reinauer3c7f46b2009-02-27 23:09:55 +00006 * Copyright (C) 2008-2009 coresystems GmbH
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
Stefan Reinauer3c7f46b2009-02-27 23:09:55 +000016 */
Stefan Reinauer4f1cb232006-07-19 15:32:49 +000017
Eric Biederman8ca8d762003-04-22 19:02:15 +000018#include <console/console.h>
Eric Biederman8ca8d762003-04-22 19:02:15 +000019#include <cpu/cpu.h>
20#include <boot/tables.h>
Stefan Reinauerca374d42008-01-18 16:16:45 +000021#include <boot/coreboot_tables.h>
Eric Biederman8ca8d762003-04-22 19:02:15 +000022#include <arch/pirq_routing.h>
23#include <arch/smp/mpspec.h>
Stefan Reinauer688b3852004-01-28 16:56:14 +000024#include <arch/acpi.h>
Stefan Reinauer0dff6e32007-10-23 22:17:45 +000025#include <string.h>
Stefan Reinauer3b314022009-10-26 17:04:28 +000026#include <cbmem.h>
Sven Schnelle164bcfd2011-08-14 20:56:34 +020027#include <smbios.h>
Steven J. Magnanid94e1d62005-09-12 18:41:30 +000028
Aaron Durbina0546da2016-04-19 15:17:08 -050029#define MAX_COREBOOT_TABLE_SIZE CONFIG_COREBOOT_TABLE_SIZE
30
Aaron Durbin3f7ad7b2014-02-18 19:36:05 -060031void write_tables(void)
Eric Biederman8ca8d762003-04-22 19:02:15 +000032{
Stefan Reinauerdf77f342009-04-06 14:00:53 +000033 unsigned long low_table_start, low_table_end;
Eric Biederman8ca8d762003-04-22 19:02:15 +000034 unsigned long rom_table_start, rom_table_end;
35
Stefan Reinauerf2152ec2009-05-26 14:07:44 +000036 /* Even if high tables are configured, some tables are copied both to
37 * the low and the high area, so payloads and OSes don't need to know
38 * about the high tables.
Stefan Reinauer3c7f46b2009-02-27 23:09:55 +000039 */
Stefan Reinauer3b314022009-10-26 17:04:28 +000040 unsigned long high_table_pointer;
Stefan Reinauer3c7f46b2009-02-27 23:09:55 +000041
Stefan Reinauer14e22772010-04-27 06:56:47 +000042 rom_table_start = 0xf0000;
Eric Biederman8ca8d762003-04-22 19:02:15 +000043 rom_table_end = 0xf0000;
Stefan Reinauerf2152ec2009-05-26 14:07:44 +000044
45 /* Start low addr at 0x500, so we don't run into conflicts with the BDA
Vladimir Serbinenko2657e842014-01-06 20:40:27 +010046 * in case our data structures grow beyond 0x400. Only GDT
Stefan Reinauer14e22772010-04-27 06:56:47 +000047 * and the coreboot table use low_tables.
Eric Biederman8ca8d762003-04-22 19:02:15 +000048 */
49 low_table_start = 0;
Stefan Reinauerf2152ec2009-05-26 14:07:44 +000050 low_table_end = 0x500;
51
Patrick Georgie1667822012-05-05 15:29:32 +020052#if CONFIG_GENERATE_PIRQ_TABLE
Stefan Reinauer3b314022009-10-26 17:04:28 +000053#define MAX_PIRQ_TABLE_SIZE (4 * 1024)
54 post_code(0x9a);
Stefan Reinauerf2152ec2009-05-26 14:07:44 +000055
56 /* This table must be between 0x0f0000 and 0x100000 */
57 rom_table_end = write_pirq_routing_table(rom_table_end);
58 rom_table_end = ALIGN(rom_table_end, 1024);
59
60 /* And add a high table version for those payloads that
61 * want to live in the F segment
62 */
Stefan Reinauer3b314022009-10-26 17:04:28 +000063 high_table_pointer = (unsigned long)cbmem_add(CBMEM_ID_PIRQ, MAX_PIRQ_TABLE_SIZE);
64 if (high_table_pointer) {
65 unsigned long new_high_table_pointer;
66 new_high_table_pointer = write_pirq_routing_table(high_table_pointer);
67 // FIXME make pirq table code intelligent enough to know how
68 // much space it's going to need.
69 if (new_high_table_pointer > (high_table_pointer + MAX_PIRQ_TABLE_SIZE)) {
70 printk(BIOS_ERR, "ERROR: Increase PIRQ size.\n");
71 }
72 printk(BIOS_DEBUG, "PIRQ table: %ld bytes.\n",
73 new_high_table_pointer - high_table_pointer);
Stefan Reinauerf2152ec2009-05-26 14:07:44 +000074 }
Eric Biederman8ca8d762003-04-22 19:02:15 +000075
Stefan Reinauer3b314022009-10-26 17:04:28 +000076#endif
77
Patrick Georgie1667822012-05-05 15:29:32 +020078#if CONFIG_GENERATE_MP_TABLE
Stefan Reinauer3b314022009-10-26 17:04:28 +000079#define MAX_MP_TABLE_SIZE (4 * 1024)
80 post_code(0x9b);
81
82 /* The smp table must be in 0-1K, 639K-640K, or 960K-1M */
83 rom_table_end = write_smp_table(rom_table_end);
84 rom_table_end = ALIGN(rom_table_end, 1024);
85
86 high_table_pointer = (unsigned long)cbmem_add(CBMEM_ID_MPTABLE, MAX_MP_TABLE_SIZE);
87 if (high_table_pointer) {
88 unsigned long new_high_table_pointer;
89 new_high_table_pointer = write_smp_table(high_table_pointer);
90 // FIXME make mp table code intelligent enough to know how
91 // much space it's going to need.
92 if (new_high_table_pointer > (high_table_pointer + MAX_MP_TABLE_SIZE)) {
93 printk(BIOS_ERR, "ERROR: Increase MP table size.\n");
94 }
95
96 printk(BIOS_DEBUG, "MP table: %ld bytes.\n",
97 new_high_table_pointer - high_table_pointer);
98 }
99#endif /* CONFIG_GENERATE_MP_TABLE */
100
Vladimir Serbinenko822bc652014-01-03 15:55:40 +0100101#if CONFIG_HAVE_ACPI_TABLES
Stefan Reinauer802c9102014-08-28 23:03:15 +0200102#define MAX_ACPI_SIZE (144 * 1024)
Kyösti Mälkkiae98e832014-11-28 11:24:19 +0200103
Stefan Reinauer3b314022009-10-26 17:04:28 +0000104 post_code(0x9c);
Li-Ta Lo8e79fc32004-04-15 17:33:21 +0000105
Stefan Reinauerf2152ec2009-05-26 14:07:44 +0000106 /* Write ACPI tables to F segment and high tables area */
Stefan Reinauer3b314022009-10-26 17:04:28 +0000107
108 /* Ok, this is a bit hacky still, because some day we want to have this
Stefan Reinauer14e22772010-04-27 06:56:47 +0000109 * completely dynamic. But right now we are setting fixed sizes.
Stefan Reinauer3b314022009-10-26 17:04:28 +0000110 * It's probably still better than the old high_table_base code because
111 * now at least we know when we have an overflow in the area.
112 *
113 * We want to use 1MB - 64K for Resume backup. We use 512B for TOC and
114 * 512 byte for GDT, 4K for PIRQ and 4K for MP table and 8KB for the
115 * coreboot table. This leaves us with 47KB for all of ACPI. Let's see
116 * how far we get.
117 */
118 high_table_pointer = (unsigned long)cbmem_add(CBMEM_ID_ACPI, MAX_ACPI_SIZE);
119 if (high_table_pointer) {
120 unsigned long acpi_start = high_table_pointer;
121 unsigned long new_high_table_pointer;
122
Patrick Georgibab4f922009-05-26 19:39:14 +0000123 rom_table_end = ALIGN(rom_table_end, 16);
Stefan Reinauer3b314022009-10-26 17:04:28 +0000124 new_high_table_pointer = write_acpi_tables(high_table_pointer);
125 if (new_high_table_pointer > ( high_table_pointer + MAX_ACPI_SIZE)) {
126 printk(BIOS_ERR, "ERROR: Increase ACPI size\n");
127 }
Martin Rothe3690102016-01-06 15:21:02 -0700128 printk(BIOS_DEBUG, "ACPI tables: %ld bytes.\n",
Stefan Reinauer3b314022009-10-26 17:04:28 +0000129 new_high_table_pointer - high_table_pointer);
130
131 /* Now we need to create a low table copy of the RSDP. */
132
133 /* First we look for the high table RSDP */
134 while (acpi_start < new_high_table_pointer) {
Patrick Georgibab4f922009-05-26 19:39:14 +0000135 if (memcmp(((acpi_rsdp_t *)acpi_start)->signature, RSDP_SIG, 8) == 0) {
136 break;
137 }
138 acpi_start++;
139 }
Stefan Reinauer3b314022009-10-26 17:04:28 +0000140
141 /* Now, if we found the RSDP, we take the RSDT and XSDT pointer
142 * from it in order to write the low RSDP
143 */
144 if (acpi_start < new_high_table_pointer) {
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000145 acpi_rsdp_t *low_rsdp = (acpi_rsdp_t *)rom_table_end,
146 *high_rsdp = (acpi_rsdp_t *)acpi_start;
147
Vladimir Serbinenko351fefc2014-10-26 20:42:08 +0100148 /* Technically rsdp length varies but coreboot always
149 writes longest size available. */
150 memcpy(low_rsdp, high_rsdp, sizeof(acpi_rsdp_t));
Patrick Georgibab4f922009-05-26 19:39:14 +0000151 } else {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000152 printk(BIOS_ERR, "ERROR: Didn't find RSDP in high table.\n");
Patrick Georgibab4f922009-05-26 19:39:14 +0000153 }
Patrick Georgibab4f922009-05-26 19:39:14 +0000154 rom_table_end = ALIGN(rom_table_end + sizeof(acpi_rsdp_t), 16);
Stefan Reinauerf2152ec2009-05-26 14:07:44 +0000155 } else {
156 rom_table_end = write_acpi_tables(rom_table_end);
157 rom_table_end = ALIGN(rom_table_end, 1024);
Myles Watsonfa12b672009-04-30 22:45:41 +0000158 }
Stefan Reinauer3b314022009-10-26 17:04:28 +0000159
Patrick Georgi8f047de2009-05-13 14:39:59 +0000160#endif
Sven Schnelle164bcfd2011-08-14 20:56:34 +0200161#define MAX_SMBIOS_SIZE 2048
162#if CONFIG_GENERATE_SMBIOS_TABLES
163 high_table_pointer = (unsigned long)cbmem_add(CBMEM_ID_SMBIOS, MAX_SMBIOS_SIZE);
164 if (high_table_pointer) {
165 unsigned long new_high_table_pointer;
Steven J. Magnanid94e1d62005-09-12 18:41:30 +0000166
Sven Schnelle164bcfd2011-08-14 20:56:34 +0200167 new_high_table_pointer = smbios_write_tables(high_table_pointer);
168 rom_table_end = ALIGN(rom_table_end, 16);
169 memcpy((void *)rom_table_end, (void *)high_table_pointer, sizeof(struct smbios_entry));
170 rom_table_end += sizeof(struct smbios_entry);
171
172 if (new_high_table_pointer > ( high_table_pointer + MAX_SMBIOS_SIZE)) {
173 printk(BIOS_ERR, "ERROR: Increase SMBIOS size\n");
174 }
Martin Rothe3690102016-01-06 15:21:02 -0700175 printk(BIOS_DEBUG, "SMBIOS tables: %ld bytes.\n",
Sven Schnelle164bcfd2011-08-14 20:56:34 +0200176 new_high_table_pointer - high_table_pointer);
177 } else {
178 unsigned long new_rom_table_end = smbios_write_tables(rom_table_end);
179 printk(BIOS_DEBUG, "SMBIOS size %ld bytes\n", new_rom_table_end - rom_table_end);
180 rom_table_end = ALIGN(new_rom_table_end, 16);
181 }
182#endif
Robert Millan81af3d42008-11-11 20:20:54 +0000183
Aaron Durbin5a767fd2013-03-23 00:12:19 -0500184 post_code(0x9e);
185
Stefan Reinauer3b314022009-10-26 17:04:28 +0000186 post_code(0x9d);
Stefan Reinauerf2152ec2009-05-26 14:07:44 +0000187
Uwe Hermann312673c2009-10-27 21:49:33 +0000188 high_table_pointer = (unsigned long)cbmem_add(CBMEM_ID_CBTABLE, MAX_COREBOOT_TABLE_SIZE);
Stefan Reinauer3b314022009-10-26 17:04:28 +0000189
190 if (high_table_pointer) {
191 unsigned long new_high_table_pointer;
192
Kyösti Mälkki1ae305e2013-09-04 13:05:01 +0300193 /* FIXME: The high_table_base parameter is not reference when tables are high,
194 * or high_table_pointer >1 MB.
195 */
Kyösti Mälkki1ae305e2013-09-04 13:05:01 +0300196 u64 fixme_high_tables_base = 0;
Kyösti Mälkki1ae305e2013-09-04 13:05:01 +0300197
Stefan Reinauerf2152ec2009-05-26 14:07:44 +0000198 /* Also put a forwarder entry into 0-4K */
Stefan Reinauer3b314022009-10-26 17:04:28 +0000199 new_high_table_pointer = write_coreboot_table(low_table_start, low_table_end,
Kyösti Mälkki1ae305e2013-09-04 13:05:01 +0300200 fixme_high_tables_base, high_table_pointer);
Stefan Reinauer3b314022009-10-26 17:04:28 +0000201
202 if (new_high_table_pointer > (high_table_pointer +
203 MAX_COREBOOT_TABLE_SIZE))
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000204 printk(BIOS_ERR, "%s: coreboot table didn't fit (%lx)\n",
Stefan Reinauer3b314022009-10-26 17:04:28 +0000205 __func__, new_high_table_pointer -
206 high_table_pointer);
207
Martin Rothe3690102016-01-06 15:21:02 -0700208 printk(BIOS_DEBUG, "coreboot table: %ld bytes.\n",
Stefan Reinauer3b314022009-10-26 17:04:28 +0000209 new_high_table_pointer - high_table_pointer);
Stefan Reinauerefab4ba2009-03-17 14:38:48 +0000210 } else {
Stefan Reinauerf2152ec2009-05-26 14:07:44 +0000211 /* The coreboot table must be in 0-4K or 960K-1M */
Paul Menzelddea9422014-02-03 08:36:51 +0100212 write_coreboot_table(low_table_start, low_table_end,
Juhana Helovuo6b56e432010-09-13 14:47:22 +0000213 rom_table_start, rom_table_end);
Stefan Reinauerefab4ba2009-03-17 14:38:48 +0000214 }
Stefan Reinauer14e22772010-04-27 06:56:47 +0000215
Stefan Reinauer3e4e3032013-03-20 14:08:04 -0700216 /* Print CBMEM sections */
Stefan Reinauer3b314022009-10-26 17:04:28 +0000217 cbmem_list();
Eric Biederman8ca8d762003-04-22 19:02:15 +0000218}