Stefan Reinauer | 3c7f46b | 2009-02-27 23:09:55 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) .... others |
| 5 | * Copyright (C) 2008-2009 coresystems GmbH |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 | */ |
Stefan Reinauer | 4f1cb23 | 2006-07-19 15:32:49 +0000 | [diff] [blame] | 20 | |
| 21 | /* 2006.1 yhlu add mptable cross 0x467 processing */ |
| 22 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 23 | #include <console/console.h> |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 24 | #include <cpu/cpu.h> |
| 25 | #include <boot/tables.h> |
Stefan Reinauer | ca374d4 | 2008-01-18 16:16:45 +0000 | [diff] [blame] | 26 | #include <boot/coreboot_tables.h> |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 27 | #include <arch/pirq_routing.h> |
| 28 | #include <arch/smp/mpspec.h> |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 29 | #include <arch/acpi.h> |
Stefan Reinauer | 0dff6e3 | 2007-10-23 22:17:45 +0000 | [diff] [blame] | 30 | #include <string.h> |
Robert Millan | 81af3d4 | 2008-11-11 20:20:54 +0000 | [diff] [blame] | 31 | #include <cpu/x86/multiboot.h> |
Stefan Reinauer | ca374d4 | 2008-01-18 16:16:45 +0000 | [diff] [blame] | 32 | #include "coreboot_table.h" |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 33 | |
Steven J. Magnani | d94e1d6 | 2005-09-12 18:41:30 +0000 | [diff] [blame] | 34 | // Global Descriptor Table, defined in c_start.S |
| 35 | extern uint8_t gdt; |
| 36 | extern uint8_t gdt_end; |
| 37 | |
| 38 | /* i386 lgdt argument */ |
| 39 | struct gdtarg { |
Stefan Reinauer | 4f1cb23 | 2006-07-19 15:32:49 +0000 | [diff] [blame] | 40 | unsigned short limit; |
| 41 | unsigned int base; |
Steven J. Magnani | d94e1d6 | 2005-09-12 18:41:30 +0000 | [diff] [blame] | 42 | } __attribute__((packed)); |
| 43 | |
| 44 | // Copy GDT to new location and reload it |
| 45 | // 2003-07 by SONE Takeshi |
Stefan Reinauer | f8ee180 | 2008-01-18 15:08:58 +0000 | [diff] [blame] | 46 | // Ported from Etherboot to coreboot 2005-08 by Steve Magnani |
Steven J. Magnani | d94e1d6 | 2005-09-12 18:41:30 +0000 | [diff] [blame] | 47 | void move_gdt(unsigned long newgdt) |
| 48 | { |
| 49 | uint16_t num_gdt_bytes = &gdt_end - &gdt; |
Stefan Reinauer | 4f1cb23 | 2006-07-19 15:32:49 +0000 | [diff] [blame] | 50 | struct gdtarg gdtarg; |
Steven J. Magnani | d94e1d6 | 2005-09-12 18:41:30 +0000 | [diff] [blame] | 51 | |
Stefan Reinauer | 4f1cb23 | 2006-07-19 15:32:49 +0000 | [diff] [blame] | 52 | printk_debug("Moving GDT to %#lx...", newgdt); |
| 53 | memcpy((void*)newgdt, &gdt, num_gdt_bytes); |
| 54 | gdtarg.base = newgdt; |
| 55 | gdtarg.limit = num_gdt_bytes - 1; |
| 56 | __asm__ __volatile__ ("lgdt %0\n\t" : : "m" (gdtarg)); |
| 57 | printk_debug("ok\n"); |
Steven J. Magnani | d94e1d6 | 2005-09-12 18:41:30 +0000 | [diff] [blame] | 58 | } |
| 59 | |
Stefan Reinauer | 3c7f46b | 2009-02-27 23:09:55 +0000 | [diff] [blame] | 60 | #if HAVE_HIGH_TABLES == 1 |
| 61 | uint64_t high_tables_base = 0; |
| 62 | uint64_t high_tables_size; |
| 63 | #endif |
| 64 | |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 65 | struct lb_memory *write_tables(void) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 66 | { |
Stefan Reinauer | 4f1cb23 | 2006-07-19 15:32:49 +0000 | [diff] [blame] | 67 | unsigned long low_table_start, low_table_end, new_low_table_end; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 68 | unsigned long rom_table_start, rom_table_end; |
| 69 | |
Stefan Reinauer | 3c7f46b | 2009-02-27 23:09:55 +0000 | [diff] [blame] | 70 | #if HAVE_HIGH_TABLES == 1 |
| 71 | /* Even if high tables are configured, all tables are copied both to the |
| 72 | * low and the high area, so payloads and OSes don't need to know about |
| 73 | * the high tables. |
| 74 | */ |
| 75 | unsigned long high_table_start, high_table_end=0; |
| 76 | |
| 77 | if (high_tables_base) { |
Stefan Reinauer | efab4ba | 2009-03-17 14:38:48 +0000 | [diff] [blame^] | 78 | printk_debug("High Tables Base is %llx.\n", high_tables_base); |
Stefan Reinauer | 3c7f46b | 2009-02-27 23:09:55 +0000 | [diff] [blame] | 79 | high_table_start = high_tables_base; |
| 80 | high_table_end = high_tables_base; |
| 81 | } else { |
| 82 | printk_debug("High Tables Base is not set.\n"); |
| 83 | } |
| 84 | #endif |
| 85 | |
Yinghai Lu | 47cb7c7 | 2007-04-06 20:27:40 +0000 | [diff] [blame] | 86 | rom_table_start = 0xf0000; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 87 | rom_table_end = 0xf0000; |
| 88 | /* Start low addr at 16 bytes instead of 0 because of a buglet |
| 89 | * in the generic linux unzip code, as it tests for the a20 line. |
| 90 | */ |
| 91 | low_table_start = 0; |
| 92 | low_table_end = 16; |
| 93 | |
| 94 | post_code(0x9a); |
Li-Ta Lo | 8e79fc3 | 2004-04-15 17:33:21 +0000 | [diff] [blame] | 95 | |
Stefan Reinauer | 3c7f46b | 2009-02-27 23:09:55 +0000 | [diff] [blame] | 96 | #if HAVE_LOW_TABLES == 1 |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 97 | /* This table must be betweeen 0xf0000 & 0x100000 */ |
Jason Schildt | 043b409 | 2005-08-10 15:16:44 +0000 | [diff] [blame] | 98 | rom_table_end = write_pirq_routing_table(rom_table_end); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 99 | rom_table_end = (rom_table_end + 1023) & ~1023; |
Stefan Reinauer | 3c7f46b | 2009-02-27 23:09:55 +0000 | [diff] [blame] | 100 | #endif |
| 101 | #if HAVE_HIGH_TABLES == 1 |
| 102 | if (high_tables_base) { |
| 103 | high_table_end = write_pirq_routing_table(high_table_end); |
| 104 | high_table_end = (high_table_end + 1023) & ~1023; |
| 105 | } |
| 106 | #endif |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 107 | |
Stefan Reinauer | a7648c2 | 2004-01-29 17:31:34 +0000 | [diff] [blame] | 108 | /* Write ACPI tables */ |
Ronald G. Minnich | 02fa3b2 | 2004-10-06 17:33:54 +0000 | [diff] [blame] | 109 | /* write them in the rom area because DSDT can be large (8K on epia-m) which |
Stefan Reinauer | f8ee180 | 2008-01-18 15:08:58 +0000 | [diff] [blame] | 110 | * pushes coreboot table out of first 4K if set up in low table area |
Yinghai Lu | 47cb7c7 | 2007-04-06 20:27:40 +0000 | [diff] [blame] | 111 | */ |
Stefan Reinauer | 3c7f46b | 2009-02-27 23:09:55 +0000 | [diff] [blame] | 112 | #if HAVE_LOW_TABLES == 1 |
Ronald G. Minnich | 02fa3b2 | 2004-10-06 17:33:54 +0000 | [diff] [blame] | 113 | rom_table_end = write_acpi_tables(rom_table_end); |
| 114 | rom_table_end = (rom_table_end+1023) & ~1023; |
Stefan Reinauer | 3c7f46b | 2009-02-27 23:09:55 +0000 | [diff] [blame] | 115 | #endif |
| 116 | #if HAVE_HIGH_TABLES == 1 |
| 117 | if (high_tables_base) { |
| 118 | high_table_end = write_acpi_tables(high_table_end); |
| 119 | high_table_end = (high_table_end+1023) & ~1023; |
| 120 | } |
| 121 | #endif |
Stefan Reinauer | 4f1cb23 | 2006-07-19 15:32:49 +0000 | [diff] [blame] | 122 | /* copy the smp block to address 0 */ |
| 123 | post_code(0x96); |
| 124 | |
Myles Watson | 47e42e5 | 2009-03-12 17:42:20 +0000 | [diff] [blame] | 125 | #if HAVE_MP_TABLE == 1 |
| 126 | |
Stefan Reinauer | 4f1cb23 | 2006-07-19 15:32:49 +0000 | [diff] [blame] | 127 | /* The smp table must be in 0-1K, 639K-640K, or 960K-1M */ |
Stefan Reinauer | 3c7f46b | 2009-02-27 23:09:55 +0000 | [diff] [blame] | 128 | #if HAVE_LOW_TABLES == 1 |
Yinghai Lu | 47cb7c7 | 2007-04-06 20:27:40 +0000 | [diff] [blame] | 129 | new_low_table_end = write_smp_table(low_table_end); // low_table_end is 0x10 at this point |
Stefan Reinauer | 3c7f46b | 2009-02-27 23:09:55 +0000 | [diff] [blame] | 130 | #endif |
| 131 | #if HAVE_HIGH_TABLES == 1 |
| 132 | if (high_tables_base) { |
| 133 | high_table_end = write_smp_table(high_table_end); |
| 134 | high_table_end = (high_table_end+1023) & ~1023; |
| 135 | } |
| 136 | #endif |
Stefan Reinauer | 4f1cb23 | 2006-07-19 15:32:49 +0000 | [diff] [blame] | 137 | |
| 138 | /* Don't write anything in the traditional x86 BIOS data segment, |
| 139 | * for example the linux kernel smp need to use 0x467 to pass reset vector |
Roman Kononov | 96e3022 | 2008-07-23 23:22:59 +0000 | [diff] [blame] | 140 | * or use 0x40e/0x413 for EBDA finding... |
Stefan Reinauer | 4f1cb23 | 2006-07-19 15:32:49 +0000 | [diff] [blame] | 141 | */ |
Roman Kononov | 96e3022 | 2008-07-23 23:22:59 +0000 | [diff] [blame] | 142 | if(new_low_table_end>0x400){ |
Yinghai Lu | 47cb7c7 | 2007-04-06 20:27:40 +0000 | [diff] [blame] | 143 | unsigned mptable_size; |
| 144 | unsigned mpc_start; |
| 145 | low_table_end += SMP_FLOATING_TABLE_LEN; /* keep the mpf in 1k low, so kernel can find it */ |
| 146 | mptable_size = new_low_table_end - low_table_end; |
| 147 | /* We can not put mptable low, we need to copy them to somewhere else*/ |
| 148 | if((rom_table_end+mptable_size)<0x100000) { |
| 149 | /* We can copy mptable on rom_table */ |
| 150 | mpc_start = rom_table_end; |
| 151 | rom_table_end += mptable_size; |
| 152 | rom_table_end = (rom_table_end+1023) & ~1023; |
| 153 | } else { |
| 154 | /* We can need to put mptable before rom_table */ |
| 155 | mpc_start = rom_table_start - mptable_size; |
| 156 | mpc_start &= ~1023; |
| 157 | rom_table_start = mpc_start; |
| 158 | } |
Myles Watson | c4ddbff | 2009-02-09 17:52:54 +0000 | [diff] [blame] | 159 | printk_debug("move mptable from 0x%0lx to 0x%0x, size 0x%0x\n", low_table_end, mpc_start, mptable_size); |
Yinghai Lu | 47cb7c7 | 2007-04-06 20:27:40 +0000 | [diff] [blame] | 160 | memcpy((unsigned char *)mpc_start, (unsigned char *)low_table_end, mptable_size); |
| 161 | smp_write_floating_table_physaddr(low_table_end - SMP_FLOATING_TABLE_LEN, mpc_start); |
| 162 | memset((unsigned char *)low_table_end, '\0', mptable_size); |
| 163 | } |
Myles Watson | 47e42e5 | 2009-03-12 17:42:20 +0000 | [diff] [blame] | 164 | #endif /* HAVE_MP_TABLE */ |
Stefan Reinauer | 4f1cb23 | 2006-07-19 15:32:49 +0000 | [diff] [blame] | 165 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 166 | if (low_table_end < 0x500) { |
| 167 | low_table_end = 0x500; |
| 168 | } |
Stefan Reinauer | 688b385 | 2004-01-28 16:56:14 +0000 | [diff] [blame] | 169 | |
Steven J. Magnani | d94e1d6 | 2005-09-12 18:41:30 +0000 | [diff] [blame] | 170 | // Relocate the GDT to reserved memory, so it won't get clobbered |
Stefan Reinauer | 3c7f46b | 2009-02-27 23:09:55 +0000 | [diff] [blame] | 171 | #if HAVE_HIGH_TABLES == 1 |
| 172 | if (high_tables_base) { |
| 173 | move_gdt(high_table_end); |
| 174 | high_table_end += &gdt_end - &gdt; |
| 175 | high_table_end = (high_table_end+1023) & ~1023; |
| 176 | } else { |
| 177 | #endif |
| 178 | move_gdt(low_table_end); |
| 179 | low_table_end += &gdt_end - &gdt; |
| 180 | #if HAVE_HIGH_TABLES == 1 |
| 181 | } |
| 182 | #endif |
Steven J. Magnani | d94e1d6 | 2005-09-12 18:41:30 +0000 | [diff] [blame] | 183 | |
Robert Millan | 81af3d4 | 2008-11-11 20:20:54 +0000 | [diff] [blame] | 184 | #if CONFIG_MULTIBOOT |
| 185 | /* The Multiboot information structure */ |
Stefan Reinauer | 8dcd50b | 2009-03-06 17:24:29 +0000 | [diff] [blame] | 186 | mbi = (struct multiboot_info *)rom_table_end; |
Robert Millan | 81af3d4 | 2008-11-11 20:20:54 +0000 | [diff] [blame] | 187 | rom_table_end = write_multiboot_info( |
| 188 | low_table_start, low_table_end, |
| 189 | rom_table_start, rom_table_end); |
| 190 | #endif |
| 191 | |
Stefan Reinauer | efab4ba | 2009-03-17 14:38:48 +0000 | [diff] [blame^] | 192 | #if HAVE_HIGH_TABLES == 1 |
| 193 | if (high_tables_base) { |
| 194 | write_coreboot_table(low_table_start, low_table_end, |
| 195 | high_table_start, high_table_end); |
| 196 | } else { |
| 197 | printk_err("ERROR: No high_tables_base.\n"); |
| 198 | write_coreboot_table(low_table_start, low_table_end, |
| 199 | rom_table_start, rom_table_end); |
| 200 | } |
| 201 | #else |
Stefan Reinauer | f8ee180 | 2008-01-18 15:08:58 +0000 | [diff] [blame] | 202 | /* The coreboot table must be in 0-4K or 960K-1M */ |
| 203 | write_coreboot_table(low_table_start, low_table_end, |
Stefan Reinauer | 4f1cb23 | 2006-07-19 15:32:49 +0000 | [diff] [blame] | 204 | rom_table_start, rom_table_end); |
Stefan Reinauer | 3c7f46b | 2009-02-27 23:09:55 +0000 | [diff] [blame] | 205 | #endif |
| 206 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 207 | return get_lb_mem(); |
| 208 | } |