29fcc13da4b8b41c7aefb4d7695fb331d4a212c9
[coreboot.git] / src / arch / i386 / boot / tables.c
1
2 /* 2006.1 yhlu add mptable cross 0x467 processing */
3
4 #include <console/console.h>
5 #include <cpu/cpu.h>
6 #include <boot/tables.h>
7 #include <boot/linuxbios_tables.h>
8 #include <arch/pirq_routing.h>
9 #include <arch/smp/mpspec.h>
10 #include <arch/acpi.h>
11 #include <string.h>
12 #include "linuxbios_table.h"
13
14 // Global Descriptor Table, defined in c_start.S
15 extern uint8_t gdt;
16 extern uint8_t gdt_end;
17
18 /* i386 lgdt argument */
19 struct gdtarg {
20         unsigned short limit;
21         unsigned int base;
22 } __attribute__((packed));
23
24 // Copy GDT to new location and reload it
25 // 2003-07 by SONE Takeshi
26 // Ported from Etherboot to LinuxBIOS 2005-08 by Steve Magnani
27 void move_gdt(unsigned long newgdt)
28 {
29         uint16_t num_gdt_bytes = &gdt_end - &gdt;
30         struct gdtarg gdtarg;
31
32         printk_debug("Moving GDT to %#lx...", newgdt);
33         memcpy((void*)newgdt, &gdt, num_gdt_bytes);
34         gdtarg.base = newgdt;
35         gdtarg.limit = num_gdt_bytes - 1;
36         __asm__ __volatile__ ("lgdt %0\n\t" : : "m" (gdtarg));
37         printk_debug("ok\n");
38 }
39
40 struct lb_memory *write_tables(void)
41 {
42         unsigned long low_table_start, low_table_end, new_low_table_end;
43         unsigned long rom_table_start, rom_table_end;
44
45         rom_table_start = 0xf0000; 
46         rom_table_end =   0xf0000;
47         /* Start low addr at 16 bytes instead of 0 because of a buglet
48          * in the generic linux unzip code, as it tests for the a20 line.
49          */
50         low_table_start = 0;
51         low_table_end = 16;
52
53         post_code(0x9a);
54
55         /* This table must be betweeen 0xf0000 & 0x100000 */
56         rom_table_end = write_pirq_routing_table(rom_table_end);
57         rom_table_end = (rom_table_end + 1023) & ~1023;
58
59         /* Write ACPI tables */
60         /* write them in the rom area because DSDT can be large (8K on epia-m) which
61          * pushes linuxbios table out of first 4K if set up in low table area 
62          */
63         rom_table_end = write_acpi_tables(rom_table_end);
64         rom_table_end = (rom_table_end+1023) & ~1023;
65
66         /* copy the smp block to address 0 */
67         post_code(0x96);
68
69         /* The smp table must be in 0-1K, 639K-640K, or 960K-1M */
70         new_low_table_end = write_smp_table(low_table_end); // low_table_end is 0x10 at this point
71
72 #if HAVE_MP_TABLE==1
73         /* Don't write anything in the traditional x86 BIOS data segment,
74          * for example the linux kernel smp need to use 0x467 to pass reset vector
75          */
76         if(new_low_table_end>0x467){
77                 unsigned mptable_size;
78                 unsigned mpc_start;
79                 low_table_end += SMP_FLOATING_TABLE_LEN; /* keep the mpf in 1k low, so kernel can find it */
80                 mptable_size = new_low_table_end - low_table_end;
81                 /* We can not put mptable low, we need to copy them to somewhere else*/
82                 if((rom_table_end+mptable_size)<0x100000) {
83                         /* We can copy mptable on rom_table  */
84                         mpc_start = rom_table_end;
85                         rom_table_end += mptable_size;
86                         rom_table_end = (rom_table_end+1023) & ~1023;
87                 } else {
88                         /* We can need to put mptable before rom_table */
89                         mpc_start = rom_table_start - mptable_size;
90                         mpc_start &= ~1023;
91                         rom_table_start = mpc_start;
92                 }
93                 printk_debug("move mptable from 0x%0x to 0x%0x, size 0x%0x\n", low_table_end, mpc_start, mptable_size);
94                 memcpy((unsigned char *)mpc_start, (unsigned char *)low_table_end, mptable_size);
95                 smp_write_floating_table_physaddr(low_table_end - SMP_FLOATING_TABLE_LEN, mpc_start);
96                 memset((unsigned char *)low_table_end, '\0', mptable_size);
97         }
98 #endif
99
100         if (low_table_end < 0x500) {
101                 low_table_end = 0x500;
102         }
103
104         // Relocate the GDT to reserved memory, so it won't get clobbered
105         move_gdt(low_table_end);
106         low_table_end += &gdt_end - &gdt;
107
108         /* The linuxbios table must be in 0-4K or 960K-1M */
109         write_linuxbios_table(low_table_start, low_table_end,
110                               rom_table_start, rom_table_end);
111
112         return get_lb_mem();
113 }