Support Intel SCH (Poulsbo) and add iwave/iWRainbowG6 board
[coreboot.git] / src / cpu / x86 / smm / smmrelocate.S
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2008-2010 coresystems GmbH
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; version 2 of
9  * 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,
19  * MA 02110-1301 USA
20  */
21
22 // Make sure no stage 2 code is included:
23 #define __PRE_RAM__
24
25 // FIXME: Is this piece of code southbridge specific, or
26 // can it be cleaned up so this include is not required?
27 // It's needed right now because we get our DEFAULT_PMBASE from
28 // here.
29 #if defined(CONFIG_SOUTHBRIDGE_INTEL_I82801GX)
30 #include "../../../southbridge/intel/i82801gx/i82801gx.h"
31 #elif defined(CONFIG_SOUTHBRIDGE_INTEL_I82801DX)
32 #include "../../../southbridge/intel/i82801dx/i82801dx.h"
33 #elif defined(CONFIG_SOUTHBRIDGE_INTEL_SCH)
34 #include "../../../southbridge/intel/sch/sch.h"
35 #else
36 #error "Southbridge needs SMM handler support."
37 #endif
38
39 #define LAPIC_ID 0xfee00020
40
41 .global smm_relocation_start
42 .global smm_relocation_end
43
44 /* initially SMM is some sort of real mode. */
45 .code16
46
47 /**
48  * This trampoline code relocates SMBASE to 0xa0000 - ( lapicid * 0x400 )
49  *
50  * Why 0x400? It is a safe value to cover the save state area per CPU. On
51  * current AMD CPUs this area is _documented_ to be 0x200 bytes. On Intel
52  * Core 2 CPUs the _documented_ parts of the save state area is 48 bytes
53  * bigger, effectively sizing our data structures 0x300 bytes.
54  *
55  * LAPICID      SMBASE          SMM Entry       SAVE STATE
56  *    0         0xa0000         0xa8000         0xafd00
57  *    1         0x9fc00         0xa7c00         0xaf900
58  *    2         0x9f800         0xa7800         0xaf500
59  *    3         0x9f400         0xa7400         0xaf100
60  *    4         0x9f000         0xa7000         0xaed00
61  *    5         0x9ec00         0xa6c00         0xae900
62  *    6         0x9e800         0xa6800         0xae500
63  *    7         0x9e400         0xa6400         0xae100
64  *    8         0x9e000         0xa6000         0xadd00
65  *    9         0x9dc00         0xa5c00         0xad900
66  *   10         0x9d800         0xa5800         0xad500
67  *   11         0x9d400         0xa5400         0xad100
68  *   12         0x9d000         0xa5000         0xacd00
69  *   13         0x9cc00         0xa4c00         0xac900
70  *   14         0x9c800         0xa4800         0xac500
71  *   15         0x9c400         0xa4400         0xac100
72  *    .            .               .               .
73  *    .            .               .               .
74  *    .            .               .               .
75  *   31         0x98400         0xa0400         0xa8100
76  *
77  * With 32 cores, the SMM handler would need to fit between
78  * 0xa0000-0xa0400 and the stub plus stack would need to go
79  * at 0xa8000-0xa8100 (example for core 0). That is not enough.
80  *
81  * This means we're basically limited to 16 cpu cores before
82  * we need to use the TSEG/HSEG for the actual SMM handler plus stack.
83  * When we exceed 32 cores, we also need to put SMBASE to TSEG/HSEG.
84  *
85  * If we figure out the documented values above are safe to use,
86  * we could pack the structure above even more, so we could use the
87  * scheme to pack save state areas for 63 AMD CPUs or 58 Intel CPUs
88  * in the ASEG.
89  *
90  * Note: Some versions of Pentium M need their SMBASE aligned to 32k.
91  * On those the above only works for up to 2 cores. But for now we only
92  * care fore Core (2) Duo/Solo
93  *
94  */
95
96 smm_relocation_start:
97         /* Check revision to see if AMD64 style SMM_BASE
98          *   Intel Core Solo/Duo:  0x30007
99          *   Intel Core2 Solo/Duo: 0x30100
100          *   AMD64:                0x3XX64
101          * This check does not make much sense, unless someone ports
102          * SMI handling to AMD64 CPUs.
103          */
104
105         mov $0x38000 + 0x7efc, %ebx
106         addr32 mov (%ebx), %al
107         cmp $0x64, %al
108         je 1f
109
110         mov $0x38000 + 0x7ef8, %ebx
111         jmp smm_relocate
112 1:
113         mov $0x38000 + 0x7f00, %ebx
114
115 smm_relocate:
116         /* Get this CPU's LAPIC ID */
117         movl $LAPIC_ID, %esi
118         addr32 movl (%esi), %ecx
119         shr  $24, %ecx
120
121         /* calculate offset by multiplying the
122          * apic ID by 1024 (0x400)
123          */
124         movl %ecx, %edx
125         shl $10, %edx
126
127         movl $0xa0000, %eax
128         subl %edx, %eax /* subtract offset, see above */
129
130         addr32 movl %eax, (%ebx)
131
132
133         /* The next section of code is potentially southbridge specific */
134
135         /* Clear SMI status */
136         movw $(DEFAULT_PMBASE + 0x34), %dx
137         inw %dx, %ax
138         outw %ax, %dx
139
140         /* Clear PM1 status */
141         movw $(DEFAULT_PMBASE + 0x00), %dx
142         inw %dx, %ax
143         outw %ax, %dx
144
145         /* Set EOS bit so other SMIs can occur */
146         movw $(DEFAULT_PMBASE + 0x30), %dx
147         inl %dx, %eax
148         orl $(1 << 1), %eax
149         outl %eax, %dx
150
151         /* End of southbridge specific section. */
152
153 #if defined(CONFIG_DEBUG_SMM_RELOCATION) && CONFIG_DEBUG_SMM_RELOCATION
154         /* print [SMM-x] so we can determine if CPUx went to SMM */
155         movw $CONFIG_TTYS0_BASE, %dx
156         mov $'[', %al
157         outb %al, %dx
158         mov $'S', %al
159         outb %al, %dx
160         mov $'M', %al
161         outb %al, %dx
162         outb %al, %dx
163         movb $'-', %al
164         outb %al, %dx
165         /* calculate ascii of cpu number. More than 9 cores? -> FIXME */
166         movb %cl, %al
167         addb $'0', %al
168         outb %al, %dx
169         mov $']', %al
170         outb %al, %dx
171         mov $'\r', %al
172         outb %al, %dx
173         mov $'\n', %al
174         outb %al, %dx
175 #endif
176
177         /* That's it. return */
178         rsm
179 smm_relocation_end:
180