Since some people disapprove of white space cleanups mixed in regular commits
[coreboot.git] / src / include / cpu / x86 / smm.h
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2008-2009 coresystems GmbH
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
18  */
19
20 /* AMD64 SMM State-Save Area
21  * starts @ 0x7e00
22  */
23 typedef struct {
24         u16     es_selector;
25         u16     es_attributes;
26         u32     es_limit;
27         u64     es_base;
28
29         u16     cs_selector;
30         u16     cs_attributcs;
31         u32     cs_limit;
32         u64     cs_base;
33
34         u16     ss_selector;
35         u16     ss_attributss;
36         u32     ss_limit;
37         u64     ss_base;
38
39         u16     ds_selector;
40         u16     ds_attributds;
41         u32     ds_limit;
42         u64     ds_base;
43
44         u16     fs_selector;
45         u16     fs_attributfs;
46         u32     fs_limit;
47         u64     fs_base;
48
49         u16     gs_selector;
50         u16     gs_attributgs;
51         u32     gs_limit;
52         u64     gs_base;
53
54         u8      reserved0[4];
55         u16     gdtr_limit;
56         u8      reserved1[2];
57         u64     gdtr_base;
58
59         u16     ldtr_selector;
60         u16     ldtr_attributes;
61         u32     ldtr_limit;
62         u64     ldtr_base;
63
64         u8      reserved2[4];
65         u16     idtr_limit;
66         u8      reserved3[2];
67         u64     idtr_base;
68
69         u16     tr_selector;
70         u16     tr_attributes;
71         u32     tr_limit;
72         u64     tr_base;
73
74         u8      reserved4[40];
75
76         u8      io_restart;
77         u8      autohalt_restart;
78
79         u8      reserved5[6];
80
81         u64     efer;
82
83         u8      reserved6[36];
84
85         u32     smm_revision;
86         u32     smbase;
87
88         u8      reserved7[68];
89
90         u64     cr4;
91         u64     cr3;
92         u64     cr0;
93         u64     dr7;
94         u64     dr6;
95
96         u64     rflags;
97         u64     rip;
98         u64     r15;
99         u64     r14;
100         u64     r13;
101         u64     r12;
102         u64     r11;
103         u64     r10;
104         u64     r9;
105         u64     r8;
106
107         u64     rdi;
108         u64     rsi;
109         u64     rpb;
110         u64     rsp;
111         u64     rbx;
112         u64     rdx;
113         u64     rcx;
114         u64     rax;
115 } __attribute__((packed)) amd64_smm_state_save_area_t;
116
117
118 /* Intel Core 2 (EM64T) SMM State-Save Area
119  * starts @ 0x7d00
120  */
121 typedef struct {
122         u8      reserved0[208];
123
124         u32     gdtr_upper_base;
125         u32     ldtr_upper_base;
126         u32     idtr_upper_base;
127
128         u8      reserved1[4];
129
130         u64     io_rdi;
131         u64     io_rip;
132         u64     io_rcx;
133         u64     io_rsi;
134         u64     cr4;
135
136         u8      reserved2[68];
137
138         u64     gdtr_base;
139         u64     idtr_base;
140         u64     ldtr_base;
141
142         u8      reserved3[84];
143
144         u32     smm_revision;
145         u32     smbase;
146
147         u16     io_restart;
148         u16     autohalt_restart;
149
150         u8      reserved4[24];
151
152         u64     r15;
153         u64     r14;
154         u64     r13;
155         u64     r12;
156         u64     r11;
157         u64     r10;
158         u64     r9;
159         u64     r8;
160
161         u64     rax;
162         u64     rcx;
163         u64     rdx;
164         u64     rbx;
165
166         u64     rsp;
167         u64     rbp;
168         u64     rsi;
169         u64     rdi;
170
171
172         u64     io_mem_addr;
173         u32     io_misc_info;
174
175         u32     es_sel;
176         u32     cs_sel;
177         u32     ss_sel;
178         u32     ds_sel;
179         u32     fs_sel;
180         u32     gs_sel;
181
182         u32     ldtr_sel;
183         u32     tr_sel;
184
185         u64     dr7;
186         u64     dr6;
187         u64     rip;
188         u64     efer;
189         u64     rflags;
190
191         u64     cr3;
192         u64     cr0;
193 } __attribute__((packed)) em64t_smm_state_save_area_t;
194
195
196 /* Legacy x86 SMM State-Save Area
197  * starts @ 0x7e00
198  */
199
200 typedef struct {
201         u8      reserved0[248];
202         u32     smbase;
203         u32     smm_revision;
204         u16     io_restart;
205         u16     autohalt_restart;
206         u8      reserved1[132];
207         u32     gdtbase;
208         u8      reserved2[8];
209         u32     idtbase;
210         u8      reserved3[16];
211         u32     es;
212         u32     cs;
213         u32     ss;
214         u32     ds;
215         u32     fs;
216         u32     gs;
217         u32     ldtbase;
218         u32     tr;
219         u32     dr7;
220         u32     dr6;
221         u32     eax;
222         u32     ecx;
223         u32     edx;
224         u32     ebx;
225         u32     esp;
226         u32     ebp;
227         u32     esi;
228         u32     edi;
229         u32     eip;
230         u32     eflags;
231         u32     cr3;
232         u32     cr0;
233 } __attribute__((packed)) legacy_smm_state_save_area_t;
234
235 typedef enum {
236         AMD64,
237         EM64T,
238         LEGACY
239 } save_state_type_t;
240
241
242 typedef struct {
243         save_state_type_t type;
244         union {
245         amd64_smm_state_save_area_t *amd64_state_save;
246         em64t_smm_state_save_area_t *em64t_state_save;
247         legacy_smm_state_save_area_t *legacy_state_save;
248         };
249 } smm_state_save_area_t;
250
251
252 /* SMI handler function prototypes */
253 void smi_handler(u32 smm_revision);
254
255 void io_trap_handler(int smif);
256 int southbridge_io_trap_handler(int smif);
257 int mainboard_io_trap_handler(int smif);
258
259 void southbridge_smi_set_eos(void);
260
261 void __attribute__((weak)) cpu_smi_handler(unsigned int node, smm_state_save_area_t *state_save);
262 void __attribute__((weak)) northbridge_smi_handler(unsigned int node, smm_state_save_area_t *state_save);
263 void __attribute__((weak)) southbridge_smi_handler(unsigned int node, smm_state_save_area_t *state_save);
264