blob: b89cf3d0b88f0493daacc95bec57a5a737016cb7 [file] [log] [blame]
Angel Ponsf23ae0b2020-04-02 23:48:12 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Stefan Reinauerdebb11f2008-10-29 04:46:52 +00002
Stefan Reinauer14e22772010-04-27 06:56:47 +00003// FIXME: Is this piece of code southbridge specific, or
Stefan Reinauer4da810b2009-07-21 21:41:42 +00004// can it be cleaned up so this include is not required?
Stefan Reinauerbc0f7a62010-08-01 15:41:14 +00005// It's needed right now because we get our DEFAULT_PMBASE from
Stefan Reinauer5f5436f2010-04-25 20:42:02 +00006// here.
Arthur Heymanseb76a452022-11-01 23:26:07 +01007#if CONFIG(SOUTHBRIDGE_INTEL_I82801IX)
Elyes HAOUAS660389e2018-10-14 20:34:09 +02008#include <southbridge/intel/i82801ix/i82801ix.h>
Stefan Reinauerbc0f7a62010-08-01 15:41:14 +00009#else
10#error "Southbridge needs SMM handler support."
11#endif
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000012
Edward O'Callaghan1104c272017-01-08 19:57:45 +110013// ADDR32() macro
Patrick Georgie8741fe2017-09-04 17:37:31 +020014#include <arch/registers.h>
Edward O'Callaghan1104c272017-01-08 19:57:45 +110015
Kyösti Mälkki4d372c72019-07-08 13:48:57 +030016#if !CONFIG(SMM_ASEG)
17#error "Only use this file with ASEG."
18#endif /* CONFIG_SMM_ASEG */
Stefan Reinauer3aa067f2012-04-02 13:24:04 -070019
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000020#define LAPIC_ID 0xfee00020
21
22.global smm_relocation_start
23.global smm_relocation_end
24
25/* initially SMM is some sort of real mode. */
26.code16
27
28/**
Stefan Reinauer8c5b58e2012-04-04 10:38:05 -070029 * When starting up, x86 CPUs have their SMBASE set to 0x30000. However,
30 * this is not a good place for the SMM handler to live, so it needs to
31 * be relocated.
32 * Traditionally SMM handlers used to live in the A segment (0xa0000).
33 * With growing SMM handlers, more CPU cores, etc. CPU vendors started
34 * allowing to relocate the handler to the end of physical memory, which
35 * they refer to as TSEG.
36 * This trampoline code relocates SMBASE to base address - ( lapicid * 0x400 )
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000037 *
38 * Why 0x400? It is a safe value to cover the save state area per CPU. On
39 * current AMD CPUs this area is _documented_ to be 0x200 bytes. On Intel
40 * Core 2 CPUs the _documented_ parts of the save state area is 48 bytes
41 * bigger, effectively sizing our data structures 0x300 bytes.
42 *
Stefan Reinauer8c5b58e2012-04-04 10:38:05 -070043 * Example (with SMM handler living at 0xa0000):
44 *
Elyes HAOUAS9d759572018-05-28 15:41:12 +020045 * LAPICID SMBASE SMM Entry SAVE STATE
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000046 * 0 0xa0000 0xa8000 0xafd00
47 * 1 0x9fc00 0xa7c00 0xaf900
48 * 2 0x9f800 0xa7800 0xaf500
49 * 3 0x9f400 0xa7400 0xaf100
50 * 4 0x9f000 0xa7000 0xaed00
51 * 5 0x9ec00 0xa6c00 0xae900
52 * 6 0x9e800 0xa6800 0xae500
53 * 7 0x9e400 0xa6400 0xae100
54 * 8 0x9e000 0xa6000 0xadd00
55 * 9 0x9dc00 0xa5c00 0xad900
56 * 10 0x9d800 0xa5800 0xad500
57 * 11 0x9d400 0xa5400 0xad100
58 * 12 0x9d000 0xa5000 0xacd00
59 * 13 0x9cc00 0xa4c00 0xac900
60 * 14 0x9c800 0xa4800 0xac500
61 * 15 0x9c400 0xa4400 0xac100
62 * . . . .
63 * . . . .
64 * . . . .
65 * 31 0x98400 0xa0400 0xa8100
66 *
67 * With 32 cores, the SMM handler would need to fit between
68 * 0xa0000-0xa0400 and the stub plus stack would need to go
69 * at 0xa8000-0xa8100 (example for core 0). That is not enough.
70 *
Elyes HAOUASd82be922016-07-28 18:58:27 +020071 * This means we're basically limited to 16 CPU cores before
Stefan Reinauer8c5b58e2012-04-04 10:38:05 -070072 * we need to move the SMM handler to TSEG.
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000073 *
74 * Note: Some versions of Pentium M need their SMBASE aligned to 32k.
75 * On those the above only works for up to 2 cores. But for now we only
76 * care fore Core (2) Duo/Solo
77 *
78 */
79
80smm_relocation_start:
81 /* Check revision to see if AMD64 style SMM_BASE
82 * Intel Core Solo/Duo: 0x30007
83 * Intel Core2 Solo/Duo: 0x30100
Stefan Reinauer3aa067f2012-04-02 13:24:04 -070084 * Intel SandyBridge: 0x30101
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000085 * AMD64: 0x3XX64
86 * This check does not make much sense, unless someone ports
87 * SMI handling to AMD64 CPUs.
88 */
89
90 mov $0x38000 + 0x7efc, %ebx
Edward O'Callaghan1104c272017-01-08 19:57:45 +110091 ADDR32(mov) (%ebx), %al
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000092 cmp $0x64, %al
93 je 1f
Stefan Reinauer14e22772010-04-27 06:56:47 +000094
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000095 mov $0x38000 + 0x7ef8, %ebx
96 jmp smm_relocate
971:
98 mov $0x38000 + 0x7f00, %ebx
99
100smm_relocate:
101 /* Get this CPU's LAPIC ID */
102 movl $LAPIC_ID, %esi
Edward O'Callaghan1104c272017-01-08 19:57:45 +1100103 ADDR32(movl) (%esi), %ecx
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000104 shr $24, %ecx
Stefan Reinauer14e22772010-04-27 06:56:47 +0000105
106 /* calculate offset by multiplying the
Elyes HAOUASd6e96862016-08-21 10:12:15 +0200107 * APIC ID by 1024 (0x400)
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000108 */
109 movl %ecx, %edx
110 shl $10, %edx
111
112 movl $0xa0000, %eax
113 subl %edx, %eax /* subtract offset, see above */
114
Edward O'Callaghan1104c272017-01-08 19:57:45 +1100115 ADDR32(movl) %eax, (%ebx)
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000116
Stefan Reinauerbc0f7a62010-08-01 15:41:14 +0000117 /* The next section of code is potentially southbridge specific */
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000118
119 /* Clear SMI status */
120 movw $(DEFAULT_PMBASE + 0x34), %dx
121 inw %dx, %ax
122 outw %ax, %dx
123
124 /* Clear PM1 status */
125 movw $(DEFAULT_PMBASE + 0x00), %dx
126 inw %dx, %ax
127 outw %ax, %dx
128
129 /* Set EOS bit so other SMIs can occur */
130 movw $(DEFAULT_PMBASE + 0x30), %dx
131 inl %dx, %eax
132 orl $(1 << 1), %eax
133 outl %eax, %dx
134
Stefan Reinauerbc0f7a62010-08-01 15:41:14 +0000135 /* End of southbridge specific section. */
136
Julius Wernercd49cce2019-03-05 16:53:33 -0800137#if CONFIG(DEBUG_SMM_RELOCATION)
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000138 /* print [SMM-x] so we can determine if CPUx went to SMM */
Stefan Reinauer08670622009-06-30 15:17:49 +0000139 movw $CONFIG_TTYS0_BASE, %dx
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000140 mov $'[', %al
141 outb %al, %dx
142 mov $'S', %al
143 outb %al, %dx
144 mov $'M', %al
145 outb %al, %dx
146 outb %al, %dx
147 movb $'-', %al
148 outb %al, %dx
Elyes HAOUASd82be922016-07-28 18:58:27 +0200149 /* calculate ascii of CPU number. More than 9 cores? -> FIXME */
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000150 movb %cl, %al
Stefan Reinauer14e22772010-04-27 06:56:47 +0000151 addb $'0', %al
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000152 outb %al, %dx
153 mov $']', %al
154 outb %al, %dx
155 mov $'\r', %al
156 outb %al, %dx
157 mov $'\n', %al
158 outb %al, %dx
159#endif
160
161 /* That's it. return */
162 rsm
163smm_relocation_end: