summaryrefslogtreecommitdiff
path: root/IntelFrameworkPkg/Include/Protocol/SmmBase.h
blob: cf4feb03451a20c65dd06a01f2bd77f9fd9757ca (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
/** @file
  This file declares SMM Base abstraction protocol.
  This protocol is used to install SMM handlers for support of subsequent SMI/PMI activations. This
  protocol is available on both IA-32 and Itanium based systems.
 
  The EFI_SMM_BASE_PROTOCOL is a set of services that is exported by a processor device. It is
  a required protocol for the platform processor. This protocol can be used in both boot services and
  runtime mode. However, only the following member functions need to exist into runtime:
  - InSmm()
  - Communicate()
  This protocol is responsible for registering the handler services. The order in which the handlers are
  executed is prescribed only with respect to the MakeLast flag in the RegisterCallback()
  service. The driver exports these registration and unregistration services in boot services mode, but
  the registered handlers will execute through the preboot and runtime. The only way to change the
  behavior of a registered driver after ExitBootServices() has been invoked is to use some
  private communication mechanism with the driver to order it to quiesce. This model permits typical
  use cases, such as invoking the handler to enter ACPI mode, where the OS loader would make this
  call before boot services are terminated. On the other hand, handlers for services such as chipset
  workarounds for the century rollover in CMOS should provide commensurate services throughout
  preboot and OS runtime.
 
  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.

  @par Revision Reference:
  This Protocol is defined in Framework of EFI SMM Core Interface Spec
  Version 0.9.

**/

#ifndef _SMM_BASE_H_
#define _SMM_BASE_H_

#include <FrameworkSmm.h>

#define EFI_SMM_BASE_PROTOCOL_GUID \
  { \
    0x1390954D, 0xda95, 0x4227, {0x93, 0x28, 0x72, 0x82, 0xc2, 0x17, 0xda, 0xa8 } \
  }

typedef struct _EFI_SMM_BASE_PROTOCOL             EFI_SMM_BASE_PROTOCOL;

//
// SMM Handler Definition
//
#define EFI_HANDLER_SUCCESS         0x0000
#define EFI_HANDLER_CRITICAL_EXIT   0x0001
#define EFI_HANDLER_SOURCE_QUIESCED 0x0002
#define EFI_HANDLER_SOURCE_PENDING  0x0003

/**
  Entry Point to Callback service

  @param  SmmImageHandle        A handle allocated by the SMM infrastructure code
                                to uniquely designate a specific DXE SMM driver.
  @param  CommunicationBuffer   A pointer to a collection of data in memory
                                that will be conveyed from a non-SMM environment into an SMM environment.
                                The buffer must be contiguous, physically mapped, and be a physical address.
  @param  SourceSize            The size of the CommunicationBuffer.

  @return Status code

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

//
// SMM Base Protocol Definition
//
/**
  Register a given driver into SMRAM.This is the equivalent of performing
  the LoadImage/StartImage into System Management Mode.

  @param  This                  Protocol instance pointer.
  @param  FilePath              Location of the image to be installed as the handler.
  @param  SourceBuffer          Optional source buffer in case of the image file
                                being in memory.
  @param  SourceSize            Size of the source image file, if in memory.
  @param  ImageHandle           Pointer to the handle that reflects the driver
                                loaded into SMM.
  @param  LegacyIA32Binary      The binary image to load is legacy 16 bit code.

  @retval EFI_SUCCESS           The operation was successful.
  @retval EFI_OUT_OF_RESOURCES  There were no additional SMRAM resources to load the handler
  @retval EFI_UNSUPPORTED       This platform does not support 16-bit handlers.
  @retval EFI_UNSUPPORTED       In runtime.
  @retval EFI_INVALID_PARAMETER The handlers was not the correct image type

**/
typedef
EFI_STATUS
(EFIAPI *EFI_SMM_REGISTER_HANDLER)(
  IN EFI_SMM_BASE_PROTOCOL                           *This,
  IN  EFI_DEVICE_PATH_PROTOCOL                       *FilePath,
  IN  VOID                                           *SourceBuffer OPTIONAL,
  IN  UINTN                                          SourceSize,
  OUT EFI_HANDLE                                     *ImageHandle,
  IN  BOOLEAN                                        LegacyIA32Binary OPTIONAL
  )
;

/**
  Remove a given driver SMRAM.  This is the equivalent of performing
  the UnloadImage System Management Mode.

  @param  This                  Protocol instance pointer.
  @param  ImageHandle           Pointer to the handle that reflects the driver
                                loaded into SMM.

  @retval EFI_SUCCESS           The operation was successful
  @retval EFI_INVALID_PARAMETER The handler did not exist
  @retval EFI_UNSUPPORTED       In runtime.

**/
typedef
EFI_STATUS
(EFIAPI *EFI_SMM_UNREGISTER_HANDLER)(
  IN EFI_SMM_BASE_PROTOCOL          *This,
  IN EFI_HANDLE                     ImageHandle
  )
;

/**
  The SMM Inter-module Communicate Service Communicate() function
  provides a services to send/received messages from a registered
  EFI service.  The BASE protocol driver is responsible for doing
  any of the copies such that the data lives in boot-service accessible RAM.

  @param  This                  Protocol instance pointer.
  @param  ImageHandle           Pointer to the handle that reflects the driver
                                loaded into SMM.
  @param  CommunicationBuffer   Pointer to the buffer to convey into SMRAM.
  @param  SourceSize            Size of the contents of buffer..

  @retval EFI_SUCCESS           The message was successfully posted
  @retval EFI_INVALID_PARAMETER The buffer was NULL

**/
typedef
EFI_STATUS
(EFIAPI *EFI_SMM_COMMUNICATE)(
  IN EFI_SMM_BASE_PROTOCOL          *This,
  IN EFI_HANDLE                     ImageHandle,
  IN OUT VOID                       *CommunicationBuffer,
  IN OUT UINTN                      *SourceSize
  )
;

/**
  Register a callback to execute within SMM.
  This allows receipt of messages created with the Boot Service COMMUNICATE.

  @param  This                  Protocol instance pointer.
  @param  CallbackAddress       Address of the callback service
  @param  MakeFirst             If present, will stipulate that the handler is posted
                                to be the first module executed in the dispatch table.
  @param  MakeLast              If present, will stipulate that the handler is posted
                                to be last executed in the dispatch table.
  @param  FloatingPointSave     This is an optional parameter which informs the
                                EFI_SMM_ACCESS_PROTOCOL Driver core if it needs to save
                                the floating point register state. If any of the handlers
                                require this, then the state will be saved for all of the handlers.

  @retval EFI_SUCCESS           The operation was successful
  @retval EFI_OUT_OF_RESOURCES  Not enough space in the dispatch queue
  @retval EFI_UNSUPPORTED       In runtime.
  @retval EFI_UNSUPPORTED       Not in SMM.

**/
typedef
EFI_STATUS
(EFIAPI *EFI_SMM_CALLBACK_SERVICE)(
  IN EFI_SMM_BASE_PROTOCOL                            *This,
  IN EFI_HANDLE                                       SmmImageHandle,
  IN EFI_SMM_CALLBACK_ENTRY_POINT                     CallbackAddress,
  IN BOOLEAN                                          MakeLast OPTIONAL,
  IN BOOLEAN                                          FloatingPointSave OPTIONAL
  )
;

/**
  The SmmAllocatePool() function allocates a memory region of Size bytes from memory of
  type PoolType and returns the address of the allocated memory in the location referenced
  by Buffer.  This function allocates pages from EFI SMRAM Memory as needed to grow the
  requested pool type.  All allocations are eight-byte aligned.

  @param  This                  Protocol instance pointer.
  @param  PoolType              The type of pool to allocate.
                                The only supported type is EfiRuntimeServicesData;
                                the interface will internally map this runtime request to SMRAM.
  @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_INVALID_PARAMETER PoolType was invalid.
  @retval EFI_UNSUPPORTED       In runtime.

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

/**
  The SmmFreePool() function returns the memory specified by Buffer to the system.
  On return, the memory's type is EFI SMRAM Memory.  The Buffer that is freed must
  have been allocated by SmmAllocatePool().

  @param  This                  Protocol instance pointer.
  @param  Buffer                Pointer to the buffer allocation.

  @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_SMM_FREE_POOL)(
  IN EFI_SMM_BASE_PROTOCOL          *This,
  IN VOID                           *Buffer
  )
;

/**
  This routine tells caller if execution context is SMM or not.

  @param  This                  Protocol instance pointer.
  @param  InSmm                 Whether the caller is inside SMM for IA-32 or servicing a PMI for the Itanium processor family.

  @retval EFI_SUCCESS           The operation was successful

**/
typedef
EFI_STATUS
(EFIAPI *EFI_SMM_INSIDE_OUT)(
  IN EFI_SMM_BASE_PROTOCOL          *This,
  OUT BOOLEAN                       *InSmm
  )
;

/**
  The GetSmstLocation() function returns the locatin of the System Management
  Service Table.  The use of the API is such that a driver can discover the
  location of the SMST in its entry point and then cache it in some driver
  global variable so that the SMST can be invoked in subsequent callbacks.

  @param  This                  Protocol instance pointer.
  @param  Smst                  Pointer to the SMST.

  @retval EFI_SUCCESS           The operation was successful
  @retval EFI_INVALID_PARAMETER Smst was invalid.
  @retval EFI_UNSUPPORTED       Not in SMM.

**/
typedef
EFI_STATUS
(EFIAPI *EFI_SMM_GET_SMST_LOCATION)(
  IN EFI_SMM_BASE_PROTOCOL          *This,
  IN OUT EFI_SMM_SYSTEM_TABLE       **Smst
  )
;

/**
  @par Protocol Description:
  This protocol is used to install SMM handlers for support of subsequent SMI/PMI
  activations. This protocol is available on both IA-32 and Itanium-based systems.

  @param Register
  Registers a handler to run in System Management RAM (SMRAM).

  @param UnRegister
  Removes a handler from execution in SMRAM.

  @param Communicate
  Sends/receives a message for a registered handler.

  @param RegisterCallback
  Registers a callback from the constructor.

  @param InSmm
  Detects whether the caller is inside or outside of SMM. SName

  @param SmmAllocatePool
  Allocates SMRAM.

  @param SmmFreePool
  Deallocates SMRAM.

  @param GetSmstLocation
  Retrieves the location of the System Management System Table (SMST).

**/
struct _EFI_SMM_BASE_PROTOCOL {
  EFI_SMM_REGISTER_HANDLER    Register;
  EFI_SMM_UNREGISTER_HANDLER  UnRegister;
  EFI_SMM_COMMUNICATE         Communicate;
  EFI_SMM_CALLBACK_SERVICE    RegisterCallback;
  EFI_SMM_INSIDE_OUT          InSmm;
  EFI_SMM_ALLOCATE_POOL       SmmAllocatePool;
  EFI_SMM_FREE_POOL           SmmFreePool;
  EFI_SMM_GET_SMST_LOCATION   GetSmstLocation;
};

extern EFI_GUID gEfiSmmBaseProtocolGuid;

#endif