blob: 69e0539126faf81231e13058476af6ca76fd493c [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
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
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>
Stefan Reinauerde3206a2010-02-22 06:09:43 +000026#include <arch/coreboot_tables.h>
Eric Biederman8ca8d762003-04-22 19:02:15 +000027#include <arch/pirq_routing.h>
28#include <arch/smp/mpspec.h>
Stefan Reinauer688b3852004-01-28 16:56:14 +000029#include <arch/acpi.h>
Stefan Reinauer0dff6e32007-10-23 22:17:45 +000030#include <string.h>
Robert Millan81af3d42008-11-11 20:20:54 +000031#include <cpu/x86/multiboot.h>
Stefan Reinauer3b314022009-10-26 17:04:28 +000032#include <cbmem.h>
Myles Watson58170782009-10-28 16:13:28 +000033#include <lib.h>
Steven J. Magnanid94e1d62005-09-12 18:41:30 +000034
Stefan Reinauer3c7f46b2009-02-27 23:09:55 +000035uint64_t high_tables_base = 0;
36uint64_t high_tables_size;
Stefan Reinauer3c7f46b2009-02-27 23:09:55 +000037
Stefan Reinauer3b314022009-10-26 17:04:28 +000038void cbmem_arch_init(void)
39{
40 /* defined in gdt.c */
41 move_gdt();
42}
43
Eric Biedermanb78c1972004-10-14 20:54:17 +000044struct lb_memory *write_tables(void)
Eric Biederman8ca8d762003-04-22 19:02:15 +000045{
Stefan Reinauerdf77f342009-04-06 14:00:53 +000046 unsigned long low_table_start, low_table_end;
Eric Biederman8ca8d762003-04-22 19:02:15 +000047 unsigned long rom_table_start, rom_table_end;
48
Stefan Reinauerf2152ec2009-05-26 14:07:44 +000049 /* Even if high tables are configured, some tables are copied both to
50 * the low and the high area, so payloads and OSes don't need to know
51 * about the high tables.
Stefan Reinauer3c7f46b2009-02-27 23:09:55 +000052 */
Stefan Reinauer3b314022009-10-26 17:04:28 +000053 unsigned long high_table_pointer;
Stefan Reinauer3c7f46b2009-02-27 23:09:55 +000054
Stefan Reinauer3b314022009-10-26 17:04:28 +000055 if (!high_tables_base) {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000056 printk(BIOS_ERR, "ERROR: High Tables Base is not set.\n");
Stefan Reinauer3b314022009-10-26 17:04:28 +000057 // Are there any boards without?
58 // Stepan thinks we should die() here!
Stefan Reinauer3c7f46b2009-02-27 23:09:55 +000059 }
Stefan Reinauer3c7f46b2009-02-27 23:09:55 +000060
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000061 printk(BIOS_DEBUG, "High Tables Base is %llx.\n", high_tables_base);
Stefan Reinauer3b314022009-10-26 17:04:28 +000062
Stefan Reinauer14e22772010-04-27 06:56:47 +000063 rom_table_start = 0xf0000;
Eric Biederman8ca8d762003-04-22 19:02:15 +000064 rom_table_end = 0xf0000;
Stefan Reinauerf2152ec2009-05-26 14:07:44 +000065
66 /* Start low addr at 0x500, so we don't run into conflicts with the BDA
67 * in case our data structures grow beyound 0x400. Only multiboot, GDT
Stefan Reinauer14e22772010-04-27 06:56:47 +000068 * and the coreboot table use low_tables.
Eric Biederman8ca8d762003-04-22 19:02:15 +000069 */
70 low_table_start = 0;
Stefan Reinauerf2152ec2009-05-26 14:07:44 +000071 low_table_end = 0x500;
72
Stefan Reinauer3b314022009-10-26 17:04:28 +000073#if CONFIG_GENERATE_PIRQ_TABLE == 1
74#define MAX_PIRQ_TABLE_SIZE (4 * 1024)
75 post_code(0x9a);
Stefan Reinauerf2152ec2009-05-26 14:07:44 +000076
77 /* This table must be between 0x0f0000 and 0x100000 */
78 rom_table_end = write_pirq_routing_table(rom_table_end);
79 rom_table_end = ALIGN(rom_table_end, 1024);
80
81 /* And add a high table version for those payloads that
82 * want to live in the F segment
83 */
Stefan Reinauer3b314022009-10-26 17:04:28 +000084 high_table_pointer = (unsigned long)cbmem_add(CBMEM_ID_PIRQ, MAX_PIRQ_TABLE_SIZE);
85 if (high_table_pointer) {
86 unsigned long new_high_table_pointer;
87 new_high_table_pointer = write_pirq_routing_table(high_table_pointer);
88 // FIXME make pirq table code intelligent enough to know how
89 // much space it's going to need.
90 if (new_high_table_pointer > (high_table_pointer + MAX_PIRQ_TABLE_SIZE)) {
91 printk(BIOS_ERR, "ERROR: Increase PIRQ size.\n");
92 }
93 printk(BIOS_DEBUG, "PIRQ table: %ld bytes.\n",
94 new_high_table_pointer - high_table_pointer);
Stefan Reinauerf2152ec2009-05-26 14:07:44 +000095 }
Eric Biederman8ca8d762003-04-22 19:02:15 +000096
Stefan Reinauer3b314022009-10-26 17:04:28 +000097#endif
98
99#if CONFIG_GENERATE_MP_TABLE == 1
100#define MAX_MP_TABLE_SIZE (4 * 1024)
101 post_code(0x9b);
102
103 /* The smp table must be in 0-1K, 639K-640K, or 960K-1M */
104 rom_table_end = write_smp_table(rom_table_end);
105 rom_table_end = ALIGN(rom_table_end, 1024);
106
107 high_table_pointer = (unsigned long)cbmem_add(CBMEM_ID_MPTABLE, MAX_MP_TABLE_SIZE);
108 if (high_table_pointer) {
109 unsigned long new_high_table_pointer;
110 new_high_table_pointer = write_smp_table(high_table_pointer);
111 // FIXME make mp table code intelligent enough to know how
112 // much space it's going to need.
113 if (new_high_table_pointer > (high_table_pointer + MAX_MP_TABLE_SIZE)) {
114 printk(BIOS_ERR, "ERROR: Increase MP table size.\n");
115 }
116
117 printk(BIOS_DEBUG, "MP table: %ld bytes.\n",
118 new_high_table_pointer - high_table_pointer);
119 }
120#endif /* CONFIG_GENERATE_MP_TABLE */
121
122#if CONFIG_GENERATE_ACPI_TABLES == 1
123#define MAX_ACPI_SIZE (47 * 1024)
124 post_code(0x9c);
Li-Ta Lo8e79fc32004-04-15 17:33:21 +0000125
Stefan Reinauerf2152ec2009-05-26 14:07:44 +0000126 /* Write ACPI tables to F segment and high tables area */
Stefan Reinauer3b314022009-10-26 17:04:28 +0000127
128 /* Ok, this is a bit hacky still, because some day we want to have this
Stefan Reinauer14e22772010-04-27 06:56:47 +0000129 * completely dynamic. But right now we are setting fixed sizes.
Stefan Reinauer3b314022009-10-26 17:04:28 +0000130 * It's probably still better than the old high_table_base code because
131 * now at least we know when we have an overflow in the area.
132 *
133 * We want to use 1MB - 64K for Resume backup. We use 512B for TOC and
134 * 512 byte for GDT, 4K for PIRQ and 4K for MP table and 8KB for the
135 * coreboot table. This leaves us with 47KB for all of ACPI. Let's see
136 * how far we get.
137 */
138 high_table_pointer = (unsigned long)cbmem_add(CBMEM_ID_ACPI, MAX_ACPI_SIZE);
139 if (high_table_pointer) {
140 unsigned long acpi_start = high_table_pointer;
141 unsigned long new_high_table_pointer;
142
Patrick Georgibab4f922009-05-26 19:39:14 +0000143 rom_table_end = ALIGN(rom_table_end, 16);
Stefan Reinauer3b314022009-10-26 17:04:28 +0000144 new_high_table_pointer = write_acpi_tables(high_table_pointer);
145 if (new_high_table_pointer > ( high_table_pointer + MAX_ACPI_SIZE)) {
146 printk(BIOS_ERR, "ERROR: Increase ACPI size\n");
147 }
148 printk(BIOS_DEBUG, "ACPI tables: %ld bytes.\n",
149 new_high_table_pointer - high_table_pointer);
150
151 /* Now we need to create a low table copy of the RSDP. */
152
153 /* First we look for the high table RSDP */
154 while (acpi_start < new_high_table_pointer) {
Patrick Georgibab4f922009-05-26 19:39:14 +0000155 if (memcmp(((acpi_rsdp_t *)acpi_start)->signature, RSDP_SIG, 8) == 0) {
156 break;
157 }
158 acpi_start++;
159 }
Stefan Reinauer3b314022009-10-26 17:04:28 +0000160
161 /* Now, if we found the RSDP, we take the RSDT and XSDT pointer
162 * from it in order to write the low RSDP
163 */
164 if (acpi_start < new_high_table_pointer) {
Stefan Reinauerb657a3c2009-07-21 21:38:33 +0000165 acpi_rsdp_t *low_rsdp = (acpi_rsdp_t *)rom_table_end,
166 *high_rsdp = (acpi_rsdp_t *)acpi_start;
167
168 acpi_write_rsdp(low_rsdp,
169 (acpi_rsdt_t *)(high_rsdp->rsdt_address),
Stefan Reinauerde3206a2010-02-22 06:09:43 +0000170 (acpi_xsdt_t *)((unsigned long)high_rsdp->xsdt_address));
Patrick Georgibab4f922009-05-26 19:39:14 +0000171 } else {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000172 printk(BIOS_ERR, "ERROR: Didn't find RSDP in high table.\n");
Patrick Georgibab4f922009-05-26 19:39:14 +0000173 }
Patrick Georgibab4f922009-05-26 19:39:14 +0000174 rom_table_end = ALIGN(rom_table_end + sizeof(acpi_rsdp_t), 16);
Stefan Reinauerf2152ec2009-05-26 14:07:44 +0000175 } else {
176 rom_table_end = write_acpi_tables(rom_table_end);
177 rom_table_end = ALIGN(rom_table_end, 1024);
Myles Watsonfa12b672009-04-30 22:45:41 +0000178 }
Stefan Reinauer3b314022009-10-26 17:04:28 +0000179
Patrick Georgi8f047de2009-05-13 14:39:59 +0000180#endif
Steven J. Magnanid94e1d62005-09-12 18:41:30 +0000181
Robert Millan81af3d42008-11-11 20:20:54 +0000182
Stefan Reinauer3b314022009-10-26 17:04:28 +0000183#define MAX_COREBOOT_TABLE_SIZE (8 * 1024)
184 post_code(0x9d);
Stefan Reinauerf2152ec2009-05-26 14:07:44 +0000185
Uwe Hermann312673c2009-10-27 21:49:33 +0000186 high_table_pointer = (unsigned long)cbmem_add(CBMEM_ID_CBTABLE, MAX_COREBOOT_TABLE_SIZE);
Stefan Reinauer3b314022009-10-26 17:04:28 +0000187
188 if (high_table_pointer) {
189 unsigned long new_high_table_pointer;
190
Stefan Reinauerf2152ec2009-05-26 14:07:44 +0000191 /* Also put a forwarder entry into 0-4K */
Stefan Reinauer3b314022009-10-26 17:04:28 +0000192 new_high_table_pointer = write_coreboot_table(low_table_start, low_table_end,
193 high_tables_base, high_table_pointer);
194
195 if (new_high_table_pointer > (high_table_pointer +
196 MAX_COREBOOT_TABLE_SIZE))
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000197 printk(BIOS_ERR, "%s: coreboot table didn't fit (%lx)\n",
Stefan Reinauer3b314022009-10-26 17:04:28 +0000198 __func__, new_high_table_pointer -
199 high_table_pointer);
200
201 printk(BIOS_DEBUG, "coreboot table: %ld bytes.\n",
202 new_high_table_pointer - high_table_pointer);
Stefan Reinauerefab4ba2009-03-17 14:38:48 +0000203 } else {
Stefan Reinauerf2152ec2009-05-26 14:07:44 +0000204 /* The coreboot table must be in 0-4K or 960K-1M */
Juhana Helovuo6b56e432010-09-13 14:47:22 +0000205 rom_table_end = write_coreboot_table(
206 low_table_start, low_table_end,
207 rom_table_start, rom_table_end);
Stefan Reinauerefab4ba2009-03-17 14:38:48 +0000208 }
Stefan Reinauer14e22772010-04-27 06:56:47 +0000209
Stefan Reinauer3b314022009-10-26 17:04:28 +0000210 post_code(0x9e);
211
212#if CONFIG_HAVE_ACPI_RESUME
213 /* Let's prepare the ACPI S3 Resume area now already, so we can rely on
214 * it begin there during reboot time. We don't need the pointer, nor
215 * the result right now. If it fails, ACPI resume will be disabled.
216 */
217 cbmem_add(CBMEM_ID_RESUME, 1024 * (1024-64));
218#endif
Stefan Reinauer14e22772010-04-27 06:56:47 +0000219
Juhana Helovuo6b56e432010-09-13 14:47:22 +0000220#if CONFIG_MULTIBOOT
221 post_code(0x9d);
222
223 /* The Multiboot information structure */
224 write_multiboot_info(rom_table_end);
225#endif
226
Stefan Reinauer3b314022009-10-26 17:04:28 +0000227 // Remove before sending upstream
228 cbmem_list();
Stefan Reinauerf2152ec2009-05-26 14:07:44 +0000229
Eric Biederman8ca8d762003-04-22 19:02:15 +0000230 return get_lb_mem();
231}