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
//! Management Mode (MM) Core Interface Definitions
//!
//! This module contains definitions related to the MM Core Interface as defined
//! in the UEFI Platform Initialization Specification.
//!
//! ## License
//!
//! Copyright (c) Microsoft Corporation.
//!
//! SPDX-License-Identifier: Apache-2.0
//!
use cratespec_version;
use c_void;
use ;
/// MMST signature: `'S', 'M', 'S', 'T'` (same as C `MM_MMST_SIGNATURE`).
pub const MM_MMST_SIGNATURE: u32 = u32from_le_bytes;
/// MMST major revision, the same as the PI Specification major revision.
pub const MM_MMST_REVISION_MAJOR: u32 = PI_SPECIFICATION_MAJOR_REVISION;
/// MMST minor revision, the same as the PI Specification minor revision.
pub const MM_MMST_REVISION_MINOR: u32 = PI_SPECIFICATION_MINOR_REVISION;
/// PI Specification version encoded as `(major << 16) | minor`.
pub const MM_SYSTEM_TABLE_REVISION: u32 = | MM_MMST_REVISION_MINOR;
//
// This EFI_MM_CPU_IO_PROTOCOL is embedded in MMST, so we need to define it here to be able to parse the MMST correctly.
//
/// A single MM I/O access function pointer.
///
/// Matches the C typedef `EFI_MM_CPU_IO`:
/// ```c
/// typedef EFI_STATUS (EFIAPI *EFI_MM_CPU_IO)(
/// IN CONST EFI_MM_CPU_IO_PROTOCOL *This,
/// IN EFI_MM_IO_WIDTH Width,
/// IN UINT64 Address,
/// IN UINTN Count,
/// IN OUT VOID *Buffer
/// );
/// ```
pub type MmCpuIoFn = unsafe extern "efiapi" fn ;
/// MM CPU I/O access pair (Read + Write).
///
/// Matches `EFI_MM_IO_ACCESS`.
/// ```c
/// typedef struct {
/// ///
/// /// This service provides the various modalities of memory and I/O read.
/// ///
/// EFI_MM_CPU_IO Read;
/// ///
/// /// This service provides the various modalities of memory and I/O write.
/// ///
/// EFI_MM_CPU_IO Write;
/// } EFI_MM_IO_ACCESS;
/// ```
/// The `EFI_MM_CPU_IO_PROTOCOL` embedded in the system table.
///
/// ```c
/// typedef struct _EFI_MM_CPU_IO_PROTOCOL {
/// EFI_MM_IO_ACCESS Mem;
/// EFI_MM_IO_ACCESS Io;
/// } EFI_MM_CPU_IO_PROTOCOL;
/// ```
/// Adds, updates, or removes a configuration table entry from the Management Mode System Table.
///
/// This function matches the C typedef `EFI_MM_INSTALL_CONFIGURATION_TABLE`:
/// ```c
/// typedef
/// EFI_STATUS
/// (EFIAPI *EFI_MM_INSTALL_CONFIGURATION_TABLE)(
/// IN CONST EFI_MM_SYSTEM_TABLE *SystemTable,
/// IN CONST EFI_GUID *Guid,
/// IN VOID *Table,
/// IN UINTN TableSize
/// );
/// ```
pub type MmInstallConfigurationTableFn = unsafe extern "efiapi" fn ;
/// Allocates pool memory from the specified memory type.
///
/// This function matches the C typedef `EFI_MM_ALLOCATE_POOL`, which is already defined in `r_efi::efi` as `BootAllocatePool`.
pub type MmAllocatePoolFn = BootAllocatePool;
/// Frees pool memory.
///
/// This function matches the C typedef `EFI_MM_FREE_POOL`, which is already defined in `r_efi::efi` as `BootFreePool`.
pub type MmFreePoolFn = BootFreePool;
/// Allocates memory pages from the system.
///
/// This function matches the C typedef `EFI_ALLOCATE_PAGES`, which is already defined in `r_efi::efi` as `BootAllocatePages`.
pub type MmAllocatePagesFn = BootAllocatePages;
/// Frees memory pages.
///
/// This function matches the C typedef `EFI_FREE_PAGES`, which is already defined in `r_efi::efi` as `BootFreePages`.
pub type MmFreePagesFn = BootFreePages;
/// `EFI_MM_STARTUP_THIS_AP`
pub type MmStartupThisApFn =
unsafe extern "efiapi" fn ;
/// Installs a protocol interface on a device handle.
///
/// This function matches the C typedef `EFI_INSTALL_PROTOCOL_INTERFACE`, which is already defined in `r_efi::efi` as `BootInstallProtocolInterface`.
pub type MmInstallProtocolInterfaceFn = BootInstallProtocolInterface;
/// Removes a protocol interface from a device handle.
///
/// This function matches the C typedef `EFI_UNINSTALL_PROTOCOL_INTERFACE`, which is already defined in `r_efi::efi` as `BootUninstallProtocolInterface`.
pub type MmUninstallProtocolInterfaceFn = BootUninstallProtocolInterface;
/// Queries a handle to determine if it supports a specified protocol.
///
/// This function matches the C typedef `EFI_HANDLE_PROTOCOL`, which is already defined in `r_efi::efi` as `BootHandleProtocol`.
pub type MmHandleProtocolFn = BootHandleProtocol;
/// Register a callback function be called when a particular protocol interface is installed.
///
/// This function matches the C typedef `EFI_MM_REGISTER_PROTOCOL_NOTIFY`:
/// ```c
/// typedef
/// EFI_STATUS
/// (EFIAPI *EFI_MM_REGISTER_PROTOCOL_NOTIFY)(
/// IN CONST EFI_GUID *Protocol,
/// IN EFI_MM_NOTIFY_FN Function,
/// OUT VOID **Registration
/// );
/// ```
pub type MmRegisterProtocolNotifyFn = unsafe extern "efiapi" fn ;
/// Returns an array of handles that support a specified protocol.
///
/// This function matches the C typedef `EFI_LOCATE_HANDLE`, which is already defined in `r_efi::efi` as `BootLocateHandle`.
pub type MmLocateHandleFn = BootLocateHandle;
/// Returns the first protocol instance that matches the given protocol.
///
/// This function matches the C typedef `EFI_LOCATE_PROTOCOL`, which is already defined in `r_efi::efi` as `BootLocateProtocol`.
pub type MmLocateProtocolFn = BootLocateProtocol;
/// Manage MMI of a particular type.
///
/// This function matches the C typedef `EFI_MM_INTERRUPT_MANAGE`:
/// ```c
/// typedef
/// EFI_STATUS
/// (EFIAPI *EFI_MM_INTERRUPT_MANAGE)(
/// IN CONST EFI_GUID *HandlerType,
/// IN CONST VOID *Context OPTIONAL,
/// IN OUT VOID *CommBuffer OPTIONAL,
/// IN OUT UINTN *CommBufferSize OPTIONAL
/// );
/// ```
pub type MmiManageFn = unsafe extern "efiapi" fn ;
/// Main entry point for an MM handler dispatch or communicate-based callback.
///
/// This function matches the C typedef `EFI_MM_HANDLER_ENTRY_POINT`:
/// ```c
/// typedef
/// EFI_STATUS
/// (EFIAPI *EFI_MM_HANDLER_ENTRY_POINT)(
/// IN EFI_HANDLE DispatchHandle,
/// IN CONST VOID *Context OPTIONAL,
/// IN OUT VOID *CommBuffer OPTIONAL,
/// IN OUT UINTN *CommBufferSize OPTIONAL
/// );
/// ```
pub type MmiHandlerEntryPoint = unsafe extern "efiapi" fn ;
/// Registers a handler entry point for a particular MMI handler type.
///
/// This function matches the C typedef `EFI_MM_INTERRUPT_REGISTER`:
/// ```c
/// typedef
/// EFI_STATUS
/// (EFIAPI *EFI_MM_INTERRUPT_REGISTER)(
/// IN EFI_MM_HANDLER_ENTRY_POINT Handler,
/// IN CONST EFI_GUID *HandlerType OPTIONAL,
/// OUT EFI_HANDLE *DispatchHandle
/// );
/// ```
pub type MmiHandlerRegisterFn = unsafe extern "efiapi" fn ;
/// Unregister a handler in MM.
///
/// This function matches the C typedef `EFI_MM_INTERRUPT_UNREGISTER`:
/// ```c
/// typedef
/// EFI_STATUS
/// (EFIAPI *EFI_MM_INTERRUPT_UNREGISTER)(
/// IN EFI_HANDLE DispatchHandle
/// );
/// ```
pub type MmiHandlerUnregisterFn = unsafe extern "efiapi" fn ;
/// EFI_MM_ENTRY_CONTEXT structure.
///
/// Processor information and functionality needed by MM Foundation.
/// Matches the C `EFI_MM_ENTRY_CONTEXT` from PI specification.
///
/// Layout (x86_64, all fields 8 bytes):
/// - `mm_startup_this_ap`: Function pointer for `EFI_MM_STARTUP_THIS_AP`
/// - `currently_executing_cpu`: Index of the processor executing the MM Foundation
/// - `number_of_cpus`: Total number of possible processors in the platform (1-based)
/// - `cpu_save_state_size`: Pointer to array of save state sizes per CPU
/// - `cpu_save_state`: Pointer to array of CPU save state pointers
/// The Management Mode System Table (MMST).
///
/// This is the `#[repr(C)]` Rust definition of the C `EFI_MM_SYSTEM_TABLE` structure
/// from `PiMmCis.h`. The table pointer is passed as the second argument to
/// every MM driver's entry point:
///
/// ```c
/// EFI_STATUS EFIAPI DriverEntry(EFI_HANDLE ImageHandle, EFI_MM_SYSTEM_TABLE *MmSt);
/// ```