blob: 40bf087cc37db92a5d526b03fe86b1d0aff5cf4d [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.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
Paul Menzela46a7122013-02-23 18:37:27 +010019 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Stefan Reinauer3c7f46b2009-02-27 23:09:55 +000020 */
Stefan Reinauer4f1cb232006-07-19 15:32:49 +000021
Eric Biederman8ca8d762003-04-22 19:02:15 +000022#include <console/console.h>
Eric Biederman8ca8d762003-04-22 19:02:15 +000023#include <cpu/cpu.h>
24#include <boot/tables.h>
Stefan Reinauerca374d42008-01-18 16:16:45 +000025#include <boot/coreboot_tables.h>
Eric Biederman8ca8d762003-04-22 19:02:15 +000026#include <arch/pirq_routing.h>
27#include <arch/smp/mpspec.h>
Stefan Reinauer688b3852004-01-28 16:56:14 +000028#include <arch/acpi.h>
Stefan Reinauer0dff6e32007-10-23 22:17:45 +000029#include <string.h>
Robert Millan81af3d42008-11-11 20:20:54 +000030#include <cpu/x86/multiboot.h>
Stefan Reinauer3b314022009-10-26 17:04:28 +000031#include <cbmem.h>
Myles Watson58170782009-10-28 16:13:28 +000032#include <lib.h>
Sven Schnelle164bcfd2011-08-14 20:56:34 +020033#include <smbios.h>
Steven J. Magnanid94e1d62005-09-12 18:41:30 +000034
Stefan Reinauer3c7f46b2009-02-27 23:09:55 +000035
Stefan Reinauer3b314022009-10-26 17:04:28 +000036void cbmem_arch_init(void)
37{
38 /* defined in gdt.c */
39 move_gdt();
40}
41
Eric Biedermanb78c1972004-10-14 20:54:17 +000042struct lb_memory *write_tables(void)
Eric Biederman8ca8d762003-04-22 19:02:15 +000043{
Stefan Reinauerdf77f342009-04-06 14:00:53 +000044 unsigned long low_table_start, low_table_end;
Eric Biederman8ca8d762003-04-22 19:02:15 +000045 unsigned long rom_table_start, rom_table_end;
46
Stefan Reinauerf2152ec2009-05-26 14:07:44 +000047 /* Even if high tables are configured, some tables are copied both to
48 * the low and the high area, so payloads and OSes don't need to know
49 * about the high tables.
Stefan Reinauer3c7f46b2009-02-27 23:09:55 +000050 */
Stefan Reinauer3b314022009-10-26 17:04:28 +000051 unsigned long high_table_pointer;
Stefan Reinauer3c7f46b2009-02-27 23:09:55 +000052
Stefan Reinauer14e22772010-04-27 06:56:47 +000053 rom_table_start = 0xf0000;
Eric Biederman8ca8d762003-04-22 19:02:15 +000054 rom_table_end = 0xf0000;
Stefan Reinauerf2152ec2009-05-26 14:07:44 +000055
56 /* Start low addr at 0x500, so we don't run into conflicts with the BDA
Martin Roth7b5f8ef2013-07-08 16:22:10 -060057 * in case our data structures grow beyond 0x400. Only multiboot, GDT
Stefan Reinauer14e22772010-04-27 06:56:47 +000058 * and the coreboot table use low_tables.
Eric Biederman8ca8d762003-04-22 19:02:15 +000059 */
60 low_table_start = 0;
Stefan Reinauerf2152ec2009-05-26 14:07:44 +000061 low_table_end = 0x500;
62
Patrick Georgie1667822012-05-05 15:29:32 +020063#if CONFIG_GENERATE_PIRQ_TABLE
Stefan Reinauer3b314022009-10-26 17:04:28 +000064#define MAX_PIRQ_TABLE_SIZE (4 * 1024)
65 post_code(0x9a);
Stefan Reinauerf2152ec2009-05-26 14:07:44 +000066
67 /* This table must be between 0x0f0000 and 0x100000 */
68 rom_table_end = write_pirq_routing_table(rom_table_end);
69 rom_table_end = ALIGN(rom_table_end, 1024);
70
71 /* And add a high table version for those payloads that
72 * want to live in the F segment
73 */
Stefan Reinauer3b314022009-10-26 17:04:28 +000074 high_table_pointer = (unsigned long)cbmem_add(CBMEM_ID_PIRQ, MAX_PIRQ_TABLE_SIZE);
75 if (high_table_pointer) {
76 unsigned long new_high_table_pointer;
77 new_high_table_pointer = write_pirq_routing_table(high_table_pointer);
78 // FIXME make pirq table code intelligent enough to know how
79 // much space it's going to need.
80 if (new_high_table_pointer > (high_table_pointer + MAX_PIRQ_TABLE_SIZE)) {
81 printk(BIOS_ERR, "ERROR: Increase PIRQ size.\n");
82 }
83 printk(BIOS_DEBUG, "PIRQ table: %ld bytes.\n",
84 new_high_table_pointer - high_table_pointer);
Stefan Reinauerf2152ec2009-05-26 14:07:44 +000085 }
Eric Biederman8ca8d762003-04-22 19:02:15 +000086
Stefan Reinauer3b314022009-10-26 17:04:28 +000087#endif
88
Patrick Georgie1667822012-05-05 15:29:32 +020089#if CONFIG_GENERATE_MP_TABLE
Stefan Reinauer3b314022009-10-26 17:04:28 +000090#define MAX_MP_TABLE_SIZE (4 * 1024)
91 post_code(0x9b);
92
93 /* The smp table must be in 0-1K, 639K-640K, or 960K-1M */
94 rom_table_end = write_smp_table(rom_table_end);
95 rom_table_end = ALIGN(rom_table_end, 1024);
96
97 high_table_pointer = (unsigned long)cbmem_add(CBMEM_ID_MPTABLE, MAX_MP_TABLE_SIZE);
98 if (high_table_pointer) {
99 unsigned long new_high_table_pointer;
100 new_high_table_pointer = write_smp_table(high_table_pointer);
101 // FIXME make mp table code intelligent enough to know how
102 // much space it's going to need.
103 if (new_high_table_pointer > (high_table_pointer + MAX_MP_TABLE_SIZE)) {
104 printk(BIOS_ERR, "ERROR: Increase MP table size.\n");
105 }
106
107 printk(BIOS_DEBUG, "MP table: %ld bytes.\n",
108 new_high_table_pointer - high_table_pointer);
109 }
110#endif /* CONFIG_GENERATE_MP_TABLE */
111
Patrick Georgie1667822012-05-05 15:29:32 +0200112#if CONFIG_GENERATE_ACPI_TABLES
Sven Schnelle164bcfd2011-08-14 20:56:34 +0200113#define MAX_ACPI_SIZE (45 * 1024)
Stefan Reinauer3b314022009-10-26 17:04:28 +0000114 post_code(0x9c);
Li-Ta Lo8e79fc32004-04-15 17:33:21 +0000115
Stefan Reinauerf2152ec2009-05-26 14:07:44 +0000116 /* Write ACPI tables to F segment and high tables area */
Stefan Reinauer3b314022009-10-26 17:04:28 +0000117
118 /* Ok, this is a bit hacky still, because some day we want to have this
Stefan Reinauer14e22772010-04-27 06:56:47 +0000119 * completely dynamic. But right now we are setting fixed sizes.
Stefan Reinauer3b314022009-10-26 17:04:28 +0000120 * It's probably still better than the old high_table_base code because
121 * now at least we know when we have an overflow in the area.
122 *
123 * We want to use 1MB - 64K for Resume backup. We use 512B for TOC and
124 * 512 byte for GDT, 4K for PIRQ and 4K for MP table and 8KB for the
125 * coreboot table. This leaves us with 47KB for all of ACPI. Let's see
126 * how far we get.
127 */
128 high_table_pointer = (unsigned long)cbmem_add(CBMEM_ID_ACPI, MAX_ACPI_SIZE);
129 if (high_table_pointer) {
130 unsigned long acpi_start = high_table_pointer;
131 unsigned long new_high_table_pointer;
132
Patrick Georgibab4f922009-05-26 19:39:14 +0000133 rom_table_end = ALIGN(rom_table_end, 16);
Stefan Reinauer3b314022009-10-26 17:04:28 +0000134 new_high_table_pointer = write_acpi_tables(high_table_pointer);
135 if (new_high_table_pointer > ( high_table_pointer + MAX_ACPI_SIZE)) {
136 printk(BIOS_ERR, "ERROR: Increase ACPI size\n");
137 }
138 printk(BIOS_DEBUG, "ACPI tables: %ld bytes.\n",
139 new_high_table_pointer - high_table_pointer);
140
141 /* Now we need to create a low table copy of the RSDP. */
142
143 /* First we look for the high table RSDP */
144 while (acpi_start < new_high_table_pointer) {
Patrick Georgibab4f922009-05-26 19:39:14 +0000145 if (memcmp(((acpi_rsdp_t *)acpi_start)->signature, RSDP_SIG, 8) == 0) {
146 break;
147 }
148 acpi_start++;
149 }
Stefan Reinauer3b314022009-10-26 17:04:28 +0000150
151 /* Now, if we found the RSDP, we take the RSDT and XSDT pointer
152 * from it in order to write the low RSDP
153 */
154 if (acpi_start < new_high_table_pointer) {
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000155 acpi_rsdp_t *low_rsdp = (acpi_rsdp_t *)rom_table_end,
156 *high_rsdp = (acpi_rsdp_t *)acpi_start;
157
158 acpi_write_rsdp(low_rsdp,
159 (acpi_rsdt_t *)(high_rsdp->rsdt_address),
Stefan Reinauerde3206a2010-02-22 06:09:43 +0000160 (acpi_xsdt_t *)((unsigned long)high_rsdp->xsdt_address));
Patrick Georgibab4f922009-05-26 19:39:14 +0000161 } else {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000162 printk(BIOS_ERR, "ERROR: Didn't find RSDP in high table.\n");
Patrick Georgibab4f922009-05-26 19:39:14 +0000163 }
Patrick Georgibab4f922009-05-26 19:39:14 +0000164 rom_table_end = ALIGN(rom_table_end + sizeof(acpi_rsdp_t), 16);
Stefan Reinauerf2152ec2009-05-26 14:07:44 +0000165 } else {
166 rom_table_end = write_acpi_tables(rom_table_end);
167 rom_table_end = ALIGN(rom_table_end, 1024);
Myles Watsonfa12b672009-04-30 22:45:41 +0000168 }
Stefan Reinauer3b314022009-10-26 17:04:28 +0000169
Patrick Georgi8f047de2009-05-13 14:39:59 +0000170#endif
Sven Schnelle164bcfd2011-08-14 20:56:34 +0200171#define MAX_SMBIOS_SIZE 2048
172#if CONFIG_GENERATE_SMBIOS_TABLES
173 high_table_pointer = (unsigned long)cbmem_add(CBMEM_ID_SMBIOS, MAX_SMBIOS_SIZE);
174 if (high_table_pointer) {
175 unsigned long new_high_table_pointer;
Steven J. Magnanid94e1d62005-09-12 18:41:30 +0000176
Sven Schnelle164bcfd2011-08-14 20:56:34 +0200177 new_high_table_pointer = smbios_write_tables(high_table_pointer);
178 rom_table_end = ALIGN(rom_table_end, 16);
179 memcpy((void *)rom_table_end, (void *)high_table_pointer, sizeof(struct smbios_entry));
180 rom_table_end += sizeof(struct smbios_entry);
181
182 if (new_high_table_pointer > ( high_table_pointer + MAX_SMBIOS_SIZE)) {
183 printk(BIOS_ERR, "ERROR: Increase SMBIOS size\n");
184 }
185 printk(BIOS_DEBUG, "SMBIOS tables: %ld bytes.\n",
186 new_high_table_pointer - high_table_pointer);
187 } else {
188 unsigned long new_rom_table_end = smbios_write_tables(rom_table_end);
189 printk(BIOS_DEBUG, "SMBIOS size %ld bytes\n", new_rom_table_end - rom_table_end);
190 rom_table_end = ALIGN(new_rom_table_end, 16);
191 }
192#endif
Robert Millan81af3d42008-11-11 20:20:54 +0000193
Aaron Durbin5a767fd2013-03-23 00:12:19 -0500194 post_code(0x9e);
195
196#if CONFIG_HAVE_ACPI_RESUME
197/* Only add CBMEM_ID_RESUME when the ramstage isn't relocatable. */
198#if !CONFIG_RELOCATABLE_RAMSTAGE
199 /* Let's prepare the ACPI S3 Resume area now already, so we can rely on
200 * it begin there during reboot time. We don't need the pointer, nor
201 * the result right now. If it fails, ACPI resume will be disabled.
202 */
203 cbmem_add(CBMEM_ID_RESUME, HIGH_MEMORY_SAVE);
204#endif
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800205#if CONFIG_NORTHBRIDGE_AMD_AGESA_FAMILY14 || CONFIG_NORTHBRIDGE_AMD_AGESA_FAMILY15_TN || CONFIG_NORTHBRIDGE_AMD_AGESA_FAMILY16_KB
Aaron Durbin5a767fd2013-03-23 00:12:19 -0500206 cbmem_add(CBMEM_ID_RESUME_SCRATCH, CONFIG_HIGH_SCRATCH_MEMORY_SIZE);
207#endif
208#endif
209
Stefan Reinauer294edb22011-08-14 13:52:03 -0700210#define MAX_COREBOOT_TABLE_SIZE (32 * 1024)
Stefan Reinauer3b314022009-10-26 17:04:28 +0000211 post_code(0x9d);
Stefan Reinauerf2152ec2009-05-26 14:07:44 +0000212
Uwe Hermann312673c2009-10-27 21:49:33 +0000213 high_table_pointer = (unsigned long)cbmem_add(CBMEM_ID_CBTABLE, MAX_COREBOOT_TABLE_SIZE);
Stefan Reinauer3b314022009-10-26 17:04:28 +0000214
215 if (high_table_pointer) {
216 unsigned long new_high_table_pointer;
217
Kyösti Mälkki1ae305e2013-09-04 13:05:01 +0300218 /* FIXME: The high_table_base parameter is not reference when tables are high,
219 * or high_table_pointer >1 MB.
220 */
221#if CONFIG_DYNAMIC_CBMEM
222 u64 fixme_high_tables_base = 0;
223#else
Kyösti Mälkkie1ea8022013-09-04 14:11:08 +0300224 u64 fixme_high_tables_base = (u32)get_cbmem_toc();
Kyösti Mälkki1ae305e2013-09-04 13:05:01 +0300225#endif
226
Stefan Reinauerf2152ec2009-05-26 14:07:44 +0000227 /* Also put a forwarder entry into 0-4K */
Stefan Reinauer3b314022009-10-26 17:04:28 +0000228 new_high_table_pointer = write_coreboot_table(low_table_start, low_table_end,
Kyösti Mälkki1ae305e2013-09-04 13:05:01 +0300229 fixme_high_tables_base, high_table_pointer);
Stefan Reinauer3b314022009-10-26 17:04:28 +0000230
231 if (new_high_table_pointer > (high_table_pointer +
232 MAX_COREBOOT_TABLE_SIZE))
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000233 printk(BIOS_ERR, "%s: coreboot table didn't fit (%lx)\n",
Stefan Reinauer3b314022009-10-26 17:04:28 +0000234 __func__, new_high_table_pointer -
235 high_table_pointer);
236
237 printk(BIOS_DEBUG, "coreboot table: %ld bytes.\n",
238 new_high_table_pointer - high_table_pointer);
Stefan Reinauerefab4ba2009-03-17 14:38:48 +0000239 } else {
Stefan Reinauerf2152ec2009-05-26 14:07:44 +0000240 /* The coreboot table must be in 0-4K or 960K-1M */
Juhana Helovuo6b56e432010-09-13 14:47:22 +0000241 rom_table_end = write_coreboot_table(
242 low_table_start, low_table_end,
243 rom_table_start, rom_table_end);
Stefan Reinauerefab4ba2009-03-17 14:38:48 +0000244 }
Stefan Reinauer14e22772010-04-27 06:56:47 +0000245
Juhana Helovuo6b56e432010-09-13 14:47:22 +0000246#if CONFIG_MULTIBOOT
247 post_code(0x9d);
248
249 /* The Multiboot information structure */
250 write_multiboot_info(rom_table_end);
251#endif
252
Stefan Reinauer3e4e3032013-03-20 14:08:04 -0700253 /* Print CBMEM sections */
Stefan Reinauer3b314022009-10-26 17:04:28 +0000254 cbmem_list();
Stefan Reinauerf2152ec2009-05-26 14:07:44 +0000255
Eric Biederman8ca8d762003-04-22 19:02:15 +0000256 return get_lb_mem();
257}