summaryrefslogtreecommitdiff
path: root/DynamicTablesPkg/Include/AcpiTableGenerator.h
blob: ef5018c312c1abbc205a06b037ffd6063cf02f0a (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
/** @file

  Copyright (c) 2017 - 2020, Arm Limited. All rights reserved.<BR>

  SPDX-License-Identifier: BSD-2-Clause-Patent

  @par Glossary:
    - Cm or CM   - Configuration Manager
    - Obj or OBJ - Object
    - Std or STD - Standard
**/

#ifndef ACPI_TABLE_GENERATOR_H_
#define ACPI_TABLE_GENERATOR_H_

#include <IndustryStandard/Acpi.h>

// Module specific include files.
#include <TableGenerator.h>

#pragma pack(1)

/**
The Dynamic Tables Framework provisions two classes of ACPI table
generators.
 - Standard generators: The ACPI table generators implemented by the
                        Dynamic Tables Framework.
 - OEM generators:      The ACPI table generators customized by the OEM.

The Dynamic Tables Framework implements the following ACPI table generators:
  - RAW   : This is the simplest ACPI table generator. It simply installs
            the ACPI table provided in the AcpiTableData member of the
            CM_STD_OBJ_ACPI_TABLE_INFO. The ACPI table data is provided by
            the Configuration Manager and is generated using an implementation
            defined mechanism.
  - DSDT  : The DSDT generator is a clone of the RAW generator. The difference
            is in the way the ACPI Table Data is generated from an AML file.
  - SSDT  : The SSDT generator is a clone of the RAW generator. The difference
            is in the way the ACPI Table Data is generated from an AML file.
  - FADT  : The FADT generator collates the required platform information from
            the Configuration Manager and builds the FADT table.
  - MADT  : The MADT generator collates the GIC information  from the
            Configuration Manager and builds the MADT table.
  - GTDT  : The GTDT generator collates the Timer information from the
            Configuration Manager and builds the GTDT table.
  - DBG2  : The DBG2 generator collates the debug serial port information from
            the Configuration Manager and builds the DBG2 table.
  - SPCR  : The SPCR generator collates the serial port information from the
            Configuration Manager and builds the SPCR table.
  - MCFG  : The MCFG generator collates the PCI configuration space information
            from the Configuration Manager and builds the MCFG table.
  - IORT  : The IORT generator collates the IO Topology information from the
            Configuration Manager and builds the IORT table.
  - PPTT  : The PPTT generator collates the processor topology information from
            the Configuration Manager and builds the PPTT table.
  - SRAT  : The SRAT generator collates the system resource affinity information
            from the Configuration Manager and builds the SRAT table.
  - SSDT Serial-Port:
            The SSDT Serial generator collates the Serial port information
            from the Configuration Manager and patches the SSDT Serial Port
            template to build the SSDT Serial port table.
*/

/** The ACPI_TABLE_GENERATOR_ID type describes ACPI table generator ID.
*/
typedef TABLE_GENERATOR_ID ACPI_TABLE_GENERATOR_ID;

/** The ESTD_ACPI_TABLE_ID enum describes the ACPI table IDs reserved for
  the standard generators.
*/
typedef enum StdAcpiTableId {
  EStdAcpiTableIdReserved = 0x0000,             ///< Reserved
  EStdAcpiTableIdRaw,                           ///< RAW Generator
  EStdAcpiTableIdDsdt = EStdAcpiTableIdRaw,     ///< DSDT Generator
  EStdAcpiTableIdSsdt = EStdAcpiTableIdRaw,     ///< SSDT Generator
  EStdAcpiTableIdFadt,                          ///< FADT Generator
  EStdAcpiTableIdMadt,                          ///< MADT Generator
  EStdAcpiTableIdGtdt,                          ///< GTDT Generator
  EStdAcpiTableIdDbg2,                          ///< DBG2 Generator
  EStdAcpiTableIdSpcr,                          ///< SPCR Generator
  EStdAcpiTableIdMcfg,                          ///< MCFG Generator
  EStdAcpiTableIdIort,                          ///< IORT Generator
  EStdAcpiTableIdPptt,                          ///< PPTT Generator
  EStdAcpiTableIdSrat,                          ///< SRAT Generator
  EStdAcpiTableIdSsdtSerialPort,                ///< SSDT Serial-Port Generator
  EStdAcpiTableIdMax
} ESTD_ACPI_TABLE_ID;

/** This macro checks if the Table Generator ID is for an ACPI Table Generator.

  @param [in] TableGeneratorId  The table generator ID.

  @return TRUE if the table generator ID is for an ACPI Table
        Generator.
**/
#define IS_GENERATOR_TYPE_ACPI(TableGeneratorId) \
          (GET_TABLE_TYPE (TableGeneratorId) == ETableGeneratorTypeAcpi)

/** This macro checks if the Table Generator ID is for a standard ACPI
    Table Generator.

  @param [in] TableGeneratorId  The table generator ID.

  @return TRUE if the table generator ID is for a standard ACPI
          Table Generator.
**/
#define IS_VALID_STD_ACPI_GENERATOR_ID(TableGeneratorId)           \
          (                                                        \
          IS_GENERATOR_NAMESPACE_STD (TableGeneratorId) &&         \
          IS_GENERATOR_TYPE_ACPI (TableGeneratorId)     &&         \
          ((GET_TABLE_ID (GeneratorId) >= EStdAcpiTableIdRaw) &&   \
           (GET_TABLE_ID (GeneratorId) < EStdAcpiTableIdMax))      \
          )

/** This macro creates a standard ACPI Table Generator ID.

  @param [in] TableId  The table generator ID.

  @return a standard ACPI table generator ID.
**/
#define CREATE_STD_ACPI_TABLE_GEN_ID(TableId) \
          CREATE_TABLE_GEN_ID (               \
            ETableGeneratorTypeAcpi,          \
            ETableGeneratorNameSpaceStd,      \
            TableId                           \
            )

/** This macro creates an OEM ACPI Table Generator ID.

  @param [in] TableId  The table generator ID.

  @return an OEM ACPI table generator ID.
**/
#define CREATE_OEM_ACPI_TABLE_GEN_ID(TableId) \
          CREATE_TABLE_GEN_ID (               \
            ETableGeneratorTypeAcpi,          \
            ETableGeneratorNameSpaceOem,      \
            TableId                           \
            )

/** The Creator ID for the ACPI tables generated using
  the standard ACPI table generators.
*/
#define TABLE_GENERATOR_CREATOR_ID_ARM  SIGNATURE_32('A', 'R', 'M', 'H')

/** A macro to initialise the common header part of EFI ACPI tables as
    defined by the EFI_ACPI_DESCRIPTION_HEADER structure.

  @param [in] Signature The ACPI table signature.
  @param [in] Type      The ACPI table structure.
  @param [in] Revision  The ACPI table revision.
**/
#define ACPI_HEADER(Signature, Type, Revision) {              \
          Signature,             /* UINT32  Signature */      \
          sizeof (Type),         /* UINT32  Length */         \
          Revision,              /* UINT8   Revision */       \
          0,                     /* UINT8   Checksum */       \
          { 0, 0, 0, 0, 0, 0 },  /* UINT8   OemId[6] */       \
          0,                     /* UINT64  OemTableId */     \
          0,                     /* UINT32  OemRevision */    \
          0,                     /* UINT32  CreatorId */      \
          0                      /* UINT32  CreatorRevision */\
          }

/** A macro to dump the common header part of EFI ACPI tables as
    defined by the EFI_ACPI_DESCRIPTION_HEADER structure.

  @param [in] AcpiHeader The pointer to the ACPI table header.
**/
#define DUMP_ACPI_TABLE_HEADER(AcpiHeader)                        \
          DEBUG ((                                                \
            DEBUG_INFO,                                           \
            "ACPI TABLE %c%c%c%c : Rev 0x%x : Length : 0x%x\n",   \
            (AcpiHeader->Signature & 0xFF),                       \
            ((AcpiHeader->Signature >> 8) & 0xFF),                \
            ((AcpiHeader->Signature >> 16) & 0xFF),               \
            ((AcpiHeader->Signature >> 24) & 0xFF),               \
            AcpiHeader->Revision,                                 \
            AcpiHeader->Length                                    \
            ));

/** Forward declarations.
*/
typedef struct ConfigurationManagerProtocol EDKII_CONFIGURATION_MANAGER_PROTOCOL;
typedef struct CmAStdObjAcpiTableInfo       CM_STD_OBJ_ACPI_TABLE_INFO;
typedef struct AcpiTableGenerator           ACPI_TABLE_GENERATOR;

/** This function pointer describes the interface to ACPI table build
    functions provided by the ACPI table generator and called by the
    Table Manager to build an ACPI table.

  @param [in]  This            Pointer to the ACPI table generator.
  @param [in]  AcpiTableInfo   Pointer to the ACPI table information.
  @param [in]  CfgMgrProtocol  Pointer to the Configuration Manager
                               Protocol interface.
  @param [out] Table           Pointer to the generated ACPI table.

  @return  EFI_SUCCESS If the table is generated successfully or other
                        failure codes as returned by the generator.
**/
typedef EFI_STATUS (*ACPI_TABLE_GENERATOR_BUILD_TABLE) (
  IN  CONST ACPI_TABLE_GENERATOR                   *       This,
  IN  CONST CM_STD_OBJ_ACPI_TABLE_INFO             * CONST AcpiTableInfo,
  IN  CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL   * CONST CfgMgrProtocol,
  OUT       EFI_ACPI_DESCRIPTION_HEADER           **       Table
  );

/** This function pointer describes the interface used by the
    Table Manager to give the generator an opportunity to free
    any resources allocated for building the ACPI table.

  @param [in]      This           Pointer to the ACPI table generator.
  @param [in]      AcpiTableInfo  Pointer to the ACPI Table Info.
  @param [in]      CfgMgrProtocol Pointer to the Configuration Manager
                                  Protocol Interface.
  @param [in, out] Table          Pointer to the ACPI Table.

  @return EFI_SUCCESS  If freed successfully or other failure codes
                        as returned by the generator.
**/
typedef EFI_STATUS (*ACPI_TABLE_GENERATOR_FREE_TABLE) (
  IN      CONST ACPI_TABLE_GENERATOR                   * CONST This,
  IN      CONST CM_STD_OBJ_ACPI_TABLE_INFO             * CONST AcpiTableInfo,
  IN      CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL   * CONST CfgMgrProtocol,
  IN OUT        EFI_ACPI_DESCRIPTION_HEADER           ** CONST Table
  );

/** This function pointer describes an extended interface to build
    ACPI Tables. The ACPI table generator can generate multiple
    ACPI Tables and return a pointer to the list of ACPI tables.
    The FreeTableResourcesEx() must be called to free any resources
    that may have been allocated using this interface.

  @param [in]  This            Pointer to the ACPI table generator.
  @param [in]  AcpiTableInfo   Pointer to the ACPI table information.
  @param [in]  CfgMgrProtocol  Pointer to the Configuration Manager
                               Protocol interface.
  @param [out] Table           Pointer to a list of generated ACPI table(s).
  @param [out] TableCount      Number of generated ACPI table(s).

  @return  EFI_SUCCESS If the table is generated successfully or other
                        failure codes as returned by the generator.
**/
typedef EFI_STATUS (*ACPI_TABLE_GENERATOR_BUILD_TABLEEX) (
  IN  CONST ACPI_TABLE_GENERATOR                   *       This,
  IN  CONST CM_STD_OBJ_ACPI_TABLE_INFO             * CONST AcpiTableInfo,
  IN  CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL   * CONST CfgMgrProtocol,
  OUT       EFI_ACPI_DESCRIPTION_HEADER          ***       Table,
  OUT       UINTN                                  * CONST TableCount
  );

/** This function pointer describes an extended interface used by the
    Table Manager to give the generator an opportunity to free
    any resources allocated for building the ACPI table. This interface
    must be used in conjunction with the BuildAcpiTableEx interface.

  @param [in]      This           Pointer to the ACPI table generator.
  @param [in]      AcpiTableInfo  Pointer to the ACPI Table Info.
  @param [in]      CfgMgrProtocol Pointer to the Configuration Manager
                                  Protocol Interface.
  @param [in, out] Table          Pointer to the list of ACPI Table(s).
  @param [in]      TableCount     Number of ACPI table(s).

  @return EFI_SUCCESS  If freed successfully or other failure codes
                        as returned by the generator.
**/
typedef EFI_STATUS (*ACPI_TABLE_GENERATOR_FREE_TABLEEX) (
  IN      CONST ACPI_TABLE_GENERATOR                   * CONST This,
  IN      CONST CM_STD_OBJ_ACPI_TABLE_INFO             * CONST AcpiTableInfo,
  IN      CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL   * CONST CfgMgrProtocol,
  IN OUT        EFI_ACPI_DESCRIPTION_HEADER          *** CONST Table,
  IN      CONST UINTN                                          TableCount
  );

/** The ACPI_TABLE_GENERATOR structure provides an interface that the
    Table Manager can use to invoke the functions to build ACPI tables.

    Note: Although the Generator is required to implement at least
          one pair of interfaces (BuildAcpiTable & FreeTableResources or
          BuildAcpiTableEx & FreeTableResourcesEx) for generating the ACPI
          table(s), if both pair of interfaces are implemented the extended
          version will take precedence.
**/
typedef struct AcpiTableGenerator {
  /// The ACPI table generator ID.
  ACPI_TABLE_GENERATOR_ID                GeneratorID;

  /// String describing the ACPI table generator.
  CONST CHAR16                         * Description;

  /// The ACPI table signature.
  UINT32                                 AcpiTableSignature;

  /// The ACPI table revision.
  UINT8                                  AcpiTableRevision;

  /// The minimum supported ACPI table revision.
  UINT8                                  MinAcpiTableRevision;

  /// The ACPI table creator ID.
  UINT32                                 CreatorId;

  /// The ACPI table creator revision.
  UINT32                                 CreatorRevision;

  /// ACPI table build function pointer.
  ACPI_TABLE_GENERATOR_BUILD_TABLE       BuildAcpiTable;

  /** The function to free any resources
      allocated for building the ACPI table.
  */
  ACPI_TABLE_GENERATOR_FREE_TABLE        FreeTableResources;

  /// ACPI table extended build function pointer.
  ACPI_TABLE_GENERATOR_BUILD_TABLEEX     BuildAcpiTableEx;

  /** The function to free any resources
      allocated for building the ACPI table
      using the extended interface.
  */
  ACPI_TABLE_GENERATOR_FREE_TABLEEX      FreeTableResourcesEx;
} ACPI_TABLE_GENERATOR;

/** Register ACPI table factory generator.

  The ACPI table factory maintains a list of the Standard and OEM ACPI
  table generators.

  @param [in]  Generator       Pointer to the ACPI table generator.

  @retval EFI_SUCCESS           The Generator was registered
                                successfully.
  @retval EFI_INVALID_PARAMETER The Generator ID is invalid or
                                the Generator pointer is NULL.
  @retval EFI_ALREADY_STARTED   The Generator for the Table ID is
                                already registered.
**/
EFI_STATUS
EFIAPI
RegisterAcpiTableGenerator (
  IN CONST ACPI_TABLE_GENERATOR                 * CONST Generator
  );

/** Deregister ACPI generator.

  This function is called by the ACPI table generator to deregister itself
  from the ACPI table factory.

  @param [in]  Generator       Pointer to the ACPI table generator.

  @retval EFI_SUCCESS           Success.
  @retval EFI_INVALID_PARAMETER The generator is invalid.
  @retval EFI_NOT_FOUND         The requested generator is not found
                                in the list of registered generators.
**/
EFI_STATUS
EFIAPI
DeregisterAcpiTableGenerator (
  IN CONST ACPI_TABLE_GENERATOR                 * CONST Generator
  );

#pragma pack()

#endif // ACPI_TABLE_GENERATOR_H_