blob: 66c1b1ff924797b0c77f5ce390373f7b4cc36817 [file] [log] [blame]
Stefan Reinauerdebb11f2008-10-29 04:46:52 +00001/*
2 * This file is part of the coreboot project.
3 *
Stefan Reinauerbc0f7a62010-08-01 15:41:14 +00004 * Copyright (C) 2008-2010 coresystems GmbH
Stefan Reinauerdebb11f2008-10-29 04:46:52 +00005 *
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.
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000015 */
16
Stefan Reinauer4da810b2009-07-21 21:41:42 +000017// Make sure no stage 2 code is included:
Myles Watson1d6d45e2009-11-06 17:02:51 +000018#define __PRE_RAM__
Stefan Reinauer4da810b2009-07-21 21:41:42 +000019
Stefan Reinauer14e22772010-04-27 06:56:47 +000020// FIXME: Is this piece of code southbridge specific, or
Stefan Reinauer4da810b2009-07-21 21:41:42 +000021// can it be cleaned up so this include is not required?
Stefan Reinauerbc0f7a62010-08-01 15:41:14 +000022// It's needed right now because we get our DEFAULT_PMBASE from
Stefan Reinauer5f5436f2010-04-25 20:42:02 +000023// here.
Stefan Reinauer582748f2011-04-19 01:18:54 +000024#if CONFIG_SOUTHBRIDGE_INTEL_I82801GX
Stefan Reinauer4da810b2009-07-21 21:41:42 +000025#include "../../../southbridge/intel/i82801gx/i82801gx.h"
Stefan Reinauer582748f2011-04-19 01:18:54 +000026#elif CONFIG_SOUTHBRIDGE_INTEL_I82801DX
Stefan Reinauerbc0f7a62010-08-01 15:41:14 +000027#include "../../../southbridge/intel/i82801dx/i82801dx.h"
Stefan Reinauer582748f2011-04-19 01:18:54 +000028#elif CONFIG_SOUTHBRIDGE_INTEL_SCH
Patrick Georgibe61a172010-12-18 07:48:43 +000029#include "../../../southbridge/intel/sch/sch.h"
Patrick Georgie72a8a32012-11-06 11:05:09 +010030#elif CONFIG_SOUTHBRIDGE_INTEL_I82801IX
31#include "../../../southbridge/intel/i82801ix/i82801ix.h"
Stefan Reinauerbc0f7a62010-08-01 15:41:14 +000032#else
33#error "Southbridge needs SMM handler support."
34#endif
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000035
Stefan Reinauer3aa067f2012-04-02 13:24:04 -070036#if CONFIG_SMM_TSEG
Vladimir Serbinenko7f464202015-05-28 21:03:51 +020037#error "Don't use this file with TSEG."
Stefan Reinauer3aa067f2012-04-02 13:24:04 -070038
39#endif /* CONFIG_SMM_TSEG */
40
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000041#define LAPIC_ID 0xfee00020
42
43.global smm_relocation_start
44.global smm_relocation_end
45
46/* initially SMM is some sort of real mode. */
47.code16
48
49/**
Stefan Reinauer8c5b58e2012-04-04 10:38:05 -070050 * When starting up, x86 CPUs have their SMBASE set to 0x30000. However,
51 * this is not a good place for the SMM handler to live, so it needs to
52 * be relocated.
53 * Traditionally SMM handlers used to live in the A segment (0xa0000).
54 * With growing SMM handlers, more CPU cores, etc. CPU vendors started
55 * allowing to relocate the handler to the end of physical memory, which
56 * they refer to as TSEG.
57 * This trampoline code relocates SMBASE to base address - ( lapicid * 0x400 )
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000058 *
59 * Why 0x400? It is a safe value to cover the save state area per CPU. On
60 * current AMD CPUs this area is _documented_ to be 0x200 bytes. On Intel
61 * Core 2 CPUs the _documented_ parts of the save state area is 48 bytes
62 * bigger, effectively sizing our data structures 0x300 bytes.
63 *
Stefan Reinauer8c5b58e2012-04-04 10:38:05 -070064 * Example (with SMM handler living at 0xa0000):
65 *
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000066 * LAPICID SMBASE SMM Entry SAVE STATE
67 * 0 0xa0000 0xa8000 0xafd00
68 * 1 0x9fc00 0xa7c00 0xaf900
69 * 2 0x9f800 0xa7800 0xaf500
70 * 3 0x9f400 0xa7400 0xaf100
71 * 4 0x9f000 0xa7000 0xaed00
72 * 5 0x9ec00 0xa6c00 0xae900
73 * 6 0x9e800 0xa6800 0xae500
74 * 7 0x9e400 0xa6400 0xae100
75 * 8 0x9e000 0xa6000 0xadd00
76 * 9 0x9dc00 0xa5c00 0xad900
77 * 10 0x9d800 0xa5800 0xad500
78 * 11 0x9d400 0xa5400 0xad100
79 * 12 0x9d000 0xa5000 0xacd00
80 * 13 0x9cc00 0xa4c00 0xac900
81 * 14 0x9c800 0xa4800 0xac500
82 * 15 0x9c400 0xa4400 0xac100
83 * . . . .
84 * . . . .
85 * . . . .
86 * 31 0x98400 0xa0400 0xa8100
87 *
88 * With 32 cores, the SMM handler would need to fit between
89 * 0xa0000-0xa0400 and the stub plus stack would need to go
90 * at 0xa8000-0xa8100 (example for core 0). That is not enough.
91 *
Stefan Reinauer14e22772010-04-27 06:56:47 +000092 * This means we're basically limited to 16 cpu cores before
Stefan Reinauer8c5b58e2012-04-04 10:38:05 -070093 * we need to move the SMM handler to TSEG.
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000094 *
95 * Note: Some versions of Pentium M need their SMBASE aligned to 32k.
96 * On those the above only works for up to 2 cores. But for now we only
97 * care fore Core (2) Duo/Solo
98 *
99 */
100
101smm_relocation_start:
102 /* Check revision to see if AMD64 style SMM_BASE
103 * Intel Core Solo/Duo: 0x30007
104 * Intel Core2 Solo/Duo: 0x30100
Stefan Reinauer3aa067f2012-04-02 13:24:04 -0700105 * Intel SandyBridge: 0x30101
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000106 * AMD64: 0x3XX64
107 * This check does not make much sense, unless someone ports
108 * SMI handling to AMD64 CPUs.
109 */
110
111 mov $0x38000 + 0x7efc, %ebx
112 addr32 mov (%ebx), %al
113 cmp $0x64, %al
114 je 1f
Stefan Reinauer14e22772010-04-27 06:56:47 +0000115
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000116 mov $0x38000 + 0x7ef8, %ebx
117 jmp smm_relocate
1181:
119 mov $0x38000 + 0x7f00, %ebx
120
121smm_relocate:
122 /* Get this CPU's LAPIC ID */
123 movl $LAPIC_ID, %esi
124 addr32 movl (%esi), %ecx
125 shr $24, %ecx
Stefan Reinauer14e22772010-04-27 06:56:47 +0000126
127 /* calculate offset by multiplying the
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000128 * apic ID by 1024 (0x400)
129 */
130 movl %ecx, %edx
131 shl $10, %edx
132
133 movl $0xa0000, %eax
134 subl %edx, %eax /* subtract offset, see above */
135
136 addr32 movl %eax, (%ebx)
137
Stefan Reinauerbc0f7a62010-08-01 15:41:14 +0000138 /* The next section of code is potentially southbridge specific */
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000139
140 /* Clear SMI status */
141 movw $(DEFAULT_PMBASE + 0x34), %dx
142 inw %dx, %ax
143 outw %ax, %dx
144
145 /* Clear PM1 status */
146 movw $(DEFAULT_PMBASE + 0x00), %dx
147 inw %dx, %ax
148 outw %ax, %dx
149
150 /* Set EOS bit so other SMIs can occur */
151 movw $(DEFAULT_PMBASE + 0x30), %dx
152 inl %dx, %eax
153 orl $(1 << 1), %eax
154 outl %eax, %dx
155
Stefan Reinauerbc0f7a62010-08-01 15:41:14 +0000156 /* End of southbridge specific section. */
157
Stefan Reinauer582748f2011-04-19 01:18:54 +0000158#if CONFIG_DEBUG_SMM_RELOCATION
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000159 /* print [SMM-x] so we can determine if CPUx went to SMM */
Stefan Reinauer08670622009-06-30 15:17:49 +0000160 movw $CONFIG_TTYS0_BASE, %dx
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000161 mov $'[', %al
162 outb %al, %dx
163 mov $'S', %al
164 outb %al, %dx
165 mov $'M', %al
166 outb %al, %dx
167 outb %al, %dx
168 movb $'-', %al
169 outb %al, %dx
170 /* calculate ascii of cpu number. More than 9 cores? -> FIXME */
171 movb %cl, %al
Stefan Reinauer14e22772010-04-27 06:56:47 +0000172 addb $'0', %al
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000173 outb %al, %dx
174 mov $']', %al
175 outb %al, %dx
176 mov $'\r', %al
177 outb %al, %dx
178 mov $'\n', %al
179 outb %al, %dx
180#endif
181
182 /* That's it. return */
183 rsm
184smm_relocation_end: