summaryrefslogtreecommitdiffstats
path: root/IntelFrameworkPkg/Include/Framework/SmmCis.h
blob: 743a309c6da1314cb935ba98a3a6392a2b2de039 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
/** @file
  Include file matches things in the Smm CIS spec.

  Copyright (c) 2007, Intel Corporation
  All rights reserved. This program and the accompanying materials
  are licensed and made available under the terms and conditions of the BSD License
  which accompanies this distribution.  The full text of the license may be found at
  http://opensource.org/licenses/bsd-license.php

  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.

  Module Name:  FrameworkSmmCis.h

  @par Revision Reference:
  Version 1.1.

**/

#ifndef _FRAMEWORK_SMM_CIS_H_
#define _FRAMEWORK_SMM_CIS_H_

#include <Framework/DxeCis.h>

#define EFI_SMM_CPU_IO_GUID \
  { \
    0x5f439a0b, 0x45d8, 0x4682, {0xa4, 0xf4, 0xf0, 0x57, 0x6b, 0x51, 0x34, 0x41 } \
  }

typedef struct _EFI_SMM_SYSTEM_TABLE      EFI_SMM_SYSTEM_TABLE;
typedef struct _EFI_SMM_CPU_IO_INTERFACE  EFI_SMM_CPU_IO_INTERFACE;


//
// SMM Base specification constant and types
//
#define SMM_SMST_SIGNATURE            SIGNATURE_32 ('S', 'M', 'S', 'T')
#define EFI_SMM_SYSTEM_TABLE_REVISION (0 << 16) | (0x09)

//
// *******************************************************
// EFI_SMM_IO_WIDTH
// *******************************************************
//
typedef enum {
  SMM_IO_UINT8  = 0,
  SMM_IO_UINT16 = 1,
  SMM_IO_UINT32 = 2,
  SMM_IO_UINT64 = 3
} EFI_SMM_IO_WIDTH;

/**
  Provides the basic memory and I/O interfaces that are used to
  abstract accesses to devices.

  @param  This             The EFI_SMM_CPU_IO_INTERFACE instance.
  @param  Width            Signifies the width of the I/O operations.
  @param  Address          The base address of the I/O operations.
  @param  Count            The number of I/O operations to perform.
  @param  Buffer           For read operations, the destination buffer to store the results.
                           For write operations, the source buffer from which to write data.

  @retval EFI_SUCCESS           The data was read from or written to the device.
  @retval EFI_UNSUPPORTED       The Address is not valid for this system.
  @retval EFI_INVALID_PARAMETER Width or Count, or both, were invalid.
  @retval EFI_OUT_OF_RESOURCES  The request could not be completed due to a lack of resources.

**/
typedef
EFI_STATUS
(EFIAPI *EFI_SMM_CPU_IO)(
  IN EFI_SMM_CPU_IO_INTERFACE         *This,
  IN EFI_SMM_IO_WIDTH                 Width,
  IN UINT64                           Address,
  IN UINTN                            Count,
  IN OUT VOID                         *Buffer
  );

typedef struct {
  EFI_SMM_CPU_IO  Read;
  EFI_SMM_CPU_IO  Write;
} EFI_SMM_IO_ACCESS;

struct _EFI_SMM_CPU_IO_INTERFACE {
  EFI_SMM_IO_ACCESS Mem;
  EFI_SMM_IO_ACCESS Io;
};

/**
  Allocates pool memory from SMRAM for IA-32 or runtime memory for
  the Itanium processor family.

  @param  PoolType         The type of pool to allocate.The only supported type is EfiRuntimeServicesData
  @param  Size             The number of bytes to allocate from the pool.
  @param  Buffer           A pointer to a pointer to the allocated buffer if the call
                           succeeds; undefined otherwise.

  @retval EFI_SUCCESS           The requested number of bytes was allocated.
  @retval EFI_OUT_OF_RESOURCES  The pool requested could not be allocated.
  @retval EFI_UNSUPPORTED       In runtime.

**/
typedef
EFI_STATUS
(EFIAPI *EFI_SMMCORE_ALLOCATE_POOL)(
  IN EFI_MEMORY_TYPE                PoolType,
  IN UINTN                          Size,
  OUT VOID                          **Buffer
  );

/**
  Returns pool memory to the system.

  @param  Buffer           Pointer to the buffer to free.

  @retval EFI_SUCCESS           The memory was returned to the system.
  @retval EFI_INVALID_PARAMETER Buffer was invalid.
  @retval EFI_UNSUPPORTED       In runtime.

**/
typedef
EFI_STATUS
(EFIAPI *EFI_SMMCORE_FREE_POOL)(
  IN VOID                   *Buffer
  );

/**
  Allocates memory pages from the system.

  @param  Type             The type of allocation to perform.
  @param  MemoryType       The only supported type is EfiRuntimeServicesData
  @param  NumberofPages    The number of contiguous 4 KB pages to allocate
  @param  Memory           Pointer to a physical address. On input, the way in which
                           the address is used depends on the value of Type. On output, the address
                           is set to the base of the page range that was allocated.

  @retval EFI_SUCCESS           The requested pages were allocated.
  @retval EFI_OUT_OF_RESOURCES  The pages requested could not be allocated.
  @retval EFI_NOT_FOUND         The requested pages could not be found.
  @retval EFI_INVALID_PARAMETER Type is not AllocateAnyPages or AllocateMaxAddress
                                or AllocateAddress. Or MemoryType is in the range EfiMaxMemoryType..0x7FFFFFFF.

**/
typedef
EFI_STATUS
(EFIAPI *EFI_SMMCORE_ALLOCATE_PAGES)(
  IN EFI_ALLOCATE_TYPE      Type,
  IN EFI_MEMORY_TYPE        MemoryType,
  IN UINTN                  NumberOfPages,
  OUT EFI_PHYSICAL_ADDRESS  *Memory
  );

/**
  Frees memory pages for the system.

  @param  Memory           The base physical address of the pages to be freed
  @param  NumberOfPages    The number of contiguous 4 KB pages to free.

  @retval EFI_SUCCESS           The requested memory pages were freed.
  @retval EFI_INVALID_PARAMETER Memory is not a page-aligned address or NumberOfPages is invalid.
  @retval EFI_NOT_FOUND         The requested memory pages were not allocated with SmmAllocatePages().

**/
typedef
EFI_STATUS
(EFIAPI *EFI_SMMCORE_FREE_PAGES)(
  IN EFI_PHYSICAL_ADDRESS   Memory,
  IN UINTN                  NumberOfPages
  );

typedef
EFI_STATUS
(EFIAPI *EFI_SMM_STARTUP_THIS_AP)(
  IN  EFI_AP_PROCEDURE                    Procedure,
  IN  UINTN                               CpuNumber,
  IN  OUT VOID                            *ProcArguments OPTIONAL
  );

typedef struct {
  UINT8                 Reserved1[248];
  UINT32                SMBASE;
  UINT32                SMMRevId;
  UINT16                IORestart;
  UINT16                AutoHALTRestart;
  UINT8                 Reserved2[164];
  UINT32                ES;
  UINT32                CS;
  UINT32                SS;
  UINT32                DS;
  UINT32                FS;
  UINT32                GS;
  UINT32                LDTBase;
  UINT32                TR;
  UINT32                DR7;
  UINT32                DR6;
  UINT32                EAX;
  UINT32                ECX;
  UINT32                EDX;
  UINT32                EBX;
  UINT32                ESP;
  UINT32                EBP;
  UINT32                ESI;
  UINT32                EDI;
  UINT32                EIP;
  UINT32                EFLAGS;
  UINT32                CR3;
  UINT32                CR0;
} EFI_SMI_CPU_SAVE_STATE;

typedef struct {
  UINT64   reserved;
  UINT64   r1;
  UINT64   r2;
  UINT64   r3;
  UINT64   r4;
  UINT64   r5;
  UINT64   r6;
  UINT64   r7;
  UINT64   r8;
  UINT64   r9;
  UINT64   r10;
  UINT64   r11;
  UINT64   r12;
  UINT64   r13;
  UINT64   r14;
  UINT64   r15;
  UINT64   r16;
  UINT64   r17;
  UINT64   r18;
  UINT64   r19;
  UINT64   r20;
  UINT64   r21;
  UINT64   r22;
  UINT64   r23;
  UINT64   r24;
  UINT64   r25;
  UINT64   r26;
  UINT64   r27;
  UINT64   r28;
  UINT64   r29;
  UINT64   r30;
  UINT64   r31;

  UINT64   pr;

  UINT64   b0;
  UINT64   b1;
  UINT64   b2;
  UINT64   b3;
  UINT64   b4;
  UINT64   b5;
  UINT64   b6;
  UINT64   b7;

  // application registers
  UINT64   ar_rsc;
  UINT64   ar_bsp;
  UINT64   ar_bspstore;
  UINT64   ar_rnat;

  UINT64   ar_fcr;

  UINT64   ar_eflag;
  UINT64   ar_csd;
  UINT64   ar_ssd;
  UINT64   ar_cflg;
  UINT64   ar_fsr;
  UINT64   ar_fir;
  UINT64   ar_fdr;

  UINT64   ar_ccv;

  UINT64   ar_unat;

  UINT64   ar_fpsr;

  UINT64   ar_pfs;
  UINT64   ar_lc;
  UINT64   ar_ec;

  // control registers
  UINT64   cr_dcr;
  UINT64   cr_itm;
  UINT64   cr_iva;
  UINT64   cr_pta;
  UINT64   cr_ipsr;
  UINT64   cr_isr;
  UINT64   cr_iip;
  UINT64   cr_ifa;
  UINT64   cr_itir;
  UINT64   cr_iipa;
  UINT64   cr_ifs;
  UINT64   cr_iim;
  UINT64   cr_iha;

  // debug registers
  UINT64   dbr0;
  UINT64   dbr1;
  UINT64   dbr2;
  UINT64   dbr3;
  UINT64   dbr4;
  UINT64   dbr5;
  UINT64   dbr6;
  UINT64   dbr7;

  UINT64   ibr0;
  UINT64   ibr1;
  UINT64   ibr2;
  UINT64   ibr3;
  UINT64   ibr4;
  UINT64   ibr5;
  UINT64   ibr6;
  UINT64   ibr7;

  // virtual registers
  UINT64   int_nat;         // nat bits for R1-R31

} EFI_PMI_SYSTEM_CONTEXT;

typedef union {
  EFI_SMI_CPU_SAVE_STATE     Ia32SaveState;
  EFI_PMI_SYSTEM_CONTEXT     ItaniumSaveState;
} EFI_SMM_CPU_SAVE_STATE;

typedef struct {
  UINT16                Fcw;
  UINT16                Fsw;
  UINT16                Ftw;
  UINT16                Opcode;
  UINT32                Eip;
  UINT16                Cs;
  UINT16                Rsvd1;
  UINT32                DataOffset;
  UINT16                Ds;
  UINT8                 Rsvd2[10];
  UINT8                 St0Mm0[10], Rsvd3[6];
  UINT8                 St0Mm1[10], Rsvd4[6];
  UINT8                 St0Mm2[10], Rsvd5[6];
  UINT8                 St0Mm3[10], Rsvd6[6];
  UINT8                 St0Mm4[10], Rsvd7[6];
  UINT8                 St0Mm5[10], Rsvd8[6];
  UINT8                 St0Mm6[10], Rsvd9[6];
  UINT8                 St0Mm7[10], Rsvd10[6];
  UINT8                 Rsvd11[22*16];
} EFI_SMI_OPTIONAL_FPSAVE_STATE;

typedef struct {
  UINT64   f2[2];
  UINT64   f3[2];
  UINT64   f4[2];
  UINT64   f5[2];
  UINT64   f6[2];
  UINT64   f7[2];
  UINT64   f8[2];
  UINT64   f9[2];
  UINT64   f10[2];
  UINT64   f11[2];
  UINT64   f12[2];
  UINT64   f13[2];
  UINT64   f14[2];
  UINT64   f15[2];
  UINT64   f16[2];
  UINT64   f17[2];
  UINT64   f18[2];
  UINT64   f19[2];
  UINT64   f20[2];
  UINT64   f21[2];
  UINT64   f22[2];
  UINT64   f23[2];
  UINT64   f24[2];
  UINT64   f25[2];
  UINT64   f26[2];
  UINT64   f27[2];
  UINT64   f28[2];
  UINT64   f29[2];
  UINT64   f30[2];
  UINT64   f31[2];
} EFI_PMI_OPTIONAL_FLOATING_POINT_CONTEXT;

typedef union {
  EFI_SMI_OPTIONAL_FPSAVE_STATE             Ia32FpSave;
  EFI_PMI_OPTIONAL_FLOATING_POINT_CONTEXT   ItaniumFpSave;
} EFI_SMM_FLOATING_POINT_SAVE_STATE;

/**
  This function is the main entry point for an SMM handler dispatch
  or communicate-based callback.

  @param  SmmImageHandle   A unique value returned by the SMM infrastructure
                           in response to registration for a communicate-based callback or dispatch.
  @param  CommunicationBuffer
                           An optional buffer that will be populated
                           by the SMM infrastructure in response to a non-SMM agent (preboot or runtime)
                           invoking the EFI_SMM_BASE_PROTOCOL.Communicate() service.
  @param  SourceSize       If CommunicationBuffer is non-NULL, this field
                           indicates the size of the data payload in this buffer.

  @return Status Code

**/
typedef
EFI_STATUS
(EFIAPI *EFI_SMM_HANDLER_ENTRY_POINT)(
  IN EFI_HANDLE             SmmImageHandle,
  IN OUT VOID               *CommunicationBuffer OPTIONAL,
  IN OUT UINTN              *SourceSize OPTIONAL
  );

/**
  The SmmInstallConfigurationTable() function is used to maintain the list
  of configuration tables that are stored in the System Management System
  Table.  The list is stored as an array of (GUID, Pointer) pairs.  The list
  must be allocated from pool memory with PoolType set to EfiRuntimeServicesData.

  @param  SystemTable      A pointer to the SMM System Table.
  @param  Guid             A pointer to the GUID for the entry to add, update, or remove.
  @param  Table            A pointer to the buffer of the table to add.
  @param  TableSize        The size of the table to install.

  @retval EFI_SUCCESS           The (Guid, Table) pair was added, updated, or removed.
  @retval EFI_INVALID_PARAMETER Guid is not valid.
  @retval EFI_NOT_FOUND         An attempt was made to delete a non-existent entry.
  @retval EFI_OUT_OF_RESOURCES  There is not enough memory available to complete the operation.

**/
typedef
EFI_STATUS
(EFIAPI *EFI_SMM_INSTALL_CONFIGURATION_TABLE)(
  IN EFI_SMM_SYSTEM_TABLE         *SystemTable,
  IN EFI_GUID                     *Guid,
  IN VOID                         *Table,
  IN UINTN                        TableSize
  );

//
// System Management System Table (SMST)
//
struct _EFI_SMM_SYSTEM_TABLE {
  EFI_TABLE_HEADER                    Hdr;

  CHAR16                              *SmmFirmwareVendor;
  UINT32                              SmmFirmwareRevision;

  EFI_SMM_INSTALL_CONFIGURATION_TABLE SmmInstallConfigurationTable;

  //
  // I/O Services
  //
  EFI_GUID                            EfiSmmCpuIoGuid;
  EFI_SMM_CPU_IO_INTERFACE            SmmIo;

  //
  // Runtime memory service
  //
  EFI_SMMCORE_ALLOCATE_POOL           SmmAllocatePool;
  EFI_SMMCORE_FREE_POOL               SmmFreePool;
  EFI_SMMCORE_ALLOCATE_PAGES          SmmAllocatePages;
  EFI_SMMCORE_FREE_PAGES              SmmFreePages;

  //
  // MP service
  //
  EFI_SMM_STARTUP_THIS_AP             SmmStartupThisAp;

  //
  // CPU information records
  //
  UINTN                               CurrentlyExecutingCpu;
  UINTN                               NumberOfCpus;
  EFI_SMM_CPU_SAVE_STATE              *CpuSaveState;
  EFI_SMM_FLOATING_POINT_SAVE_STATE   *CpuOptionalFloatingPointState;

  //
  // Extensibility table
  //
  UINTN                               NumberOfTableEntries;
  EFI_CONFIGURATION_TABLE             *SmmConfigurationTable;
};

#endif