1/** @file
2  ACPI Table Protocol Driver
3
4  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
5  This program and the accompanying materials
6  are licensed and made available under the terms and conditions of the BSD License
7  which accompanies this distribution.  The full text of the license may be found at
8  http://opensource.org/licenses/bsd-license.php
9
10  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13**/
14
15#ifndef _ACPI_TABLE_H_
16#define _ACPI_TABLE_H_
17
18
19#include <PiDxe.h>
20
21#include <Protocol/AcpiTable.h>
22#include <Guid/Acpi.h>
23#include <Protocol/AcpiSystemDescriptionTable.h>
24
25#include <Library/BaseLib.h>
26#include <Library/DebugLib.h>
27#include <Library/UefiLib.h>
28#include <Library/BaseMemoryLib.h>
29#include <Library/UefiDriverEntryPoint.h>
30#include <Library/MemoryAllocationLib.h>
31#include <Library/UefiBootServicesTableLib.h>
32#include <Library/PcdLib.h>
33
34//
35// Statements that include other files
36//
37#include <IndustryStandard/Acpi.h>
38
39#include "AcpiSdt.h"
40
41//
42// Great than or equal to 2.0.
43//
44#define ACPI_TABLE_VERSION_GTE_2_0 (EFI_ACPI_TABLE_VERSION_2_0  | \
45                                    EFI_ACPI_TABLE_VERSION_3_0  | \
46                                    EFI_ACPI_TABLE_VERSION_4_0  | \
47                                    EFI_ACPI_TABLE_VERSION_5_0)
48
49//
50// Private Driver Data
51//
52//
53// ACPI Table Linked List Signature.
54//
55#define EFI_ACPI_TABLE_LIST_SIGNATURE SIGNATURE_32 ('E', 'A', 'T', 'L')
56
57//
58// ACPI Table Linked List Entry definition.
59//
60//  Signature must be set to EFI_ACPI_TABLE_LIST_SIGNATURE
61//  Link is the linked list data.
62//  Version is the versions of the ACPI tables that this table belongs in.
63//  Table is a pointer to the table.
64//  PageAddress is the address of the pages allocated for the table.
65//  NumberOfPages is the number of pages allocated at PageAddress.
66//  Handle is used to identify a particular table.
67//
68typedef struct {
69  UINT32                  Signature;
70  LIST_ENTRY              Link;
71  EFI_ACPI_TABLE_VERSION  Version;
72  EFI_ACPI_COMMON_HEADER  *Table;
73  EFI_PHYSICAL_ADDRESS    PageAddress;
74  UINTN                   NumberOfPages;
75  UINTN                   Handle;
76} EFI_ACPI_TABLE_LIST;
77
78//
79// Containment record for ACPI Table linked list.
80//
81#define EFI_ACPI_TABLE_LIST_FROM_LINK(_link)  CR (_link, EFI_ACPI_TABLE_LIST, Link, EFI_ACPI_TABLE_LIST_SIGNATURE)
82
83//
84// The maximum number of tables this driver supports
85//
86#define EFI_ACPI_MAX_NUM_TABLES 20
87
88//
89// Protocol private structure definition
90//
91//
92// ACPI support protocol instance signature definition.
93//
94#define EFI_ACPI_TABLE_SIGNATURE  SIGNATURE_32 ('S', 'T', 'A', 'E')
95
96//
97// ACPI support protocol instance data structure
98//
99typedef struct {
100  UINTN                                         Signature;
101  EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER  *Rsdp1;                 // Pointer to RSD_PTR structure
102  EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER  *Rsdp3;                 // Pointer to RSD_PTR structure
103  EFI_ACPI_DESCRIPTION_HEADER                   *Rsdt1;                 // Pointer to RSDT table header
104  EFI_ACPI_DESCRIPTION_HEADER                   *Rsdt3;                 // Pointer to RSDT table header
105  EFI_ACPI_DESCRIPTION_HEADER                   *Xsdt;                  // Pointer to XSDT table header
106  EFI_ACPI_1_0_FIXED_ACPI_DESCRIPTION_TABLE     *Fadt1;                 // Pointer to FADT table header
107  EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE     *Fadt3;                 // Pointer to FADT table header
108  EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE  *Facs1;                 // Pointer to FACS table header
109  EFI_ACPI_3_0_FIRMWARE_ACPI_CONTROL_STRUCTURE  *Facs3;                 // Pointer to FACS table header
110  EFI_ACPI_DESCRIPTION_HEADER                   *Dsdt1;                 // Pointer to DSDT table header
111  EFI_ACPI_DESCRIPTION_HEADER                   *Dsdt3;                 // Pointer to DSDT table header
112  LIST_ENTRY                                    TableList;
113  UINTN                                         NumberOfTableEntries1;  // Number of ACPI 1.0 tables
114  UINTN                                         NumberOfTableEntries3;  // Number of ACPI 3.0 tables
115  UINTN                                         CurrentHandle;
116  EFI_ACPI_TABLE_PROTOCOL                       AcpiTableProtocol;
117  EFI_ACPI_SDT_PROTOCOL                         AcpiSdtProtocol;
118  LIST_ENTRY                                    NotifyList;
119} EFI_ACPI_TABLE_INSTANCE;
120
121//
122// ACPI table protocol instance containing record macro
123//
124#define EFI_ACPI_TABLE_INSTANCE_FROM_THIS(a) \
125  CR (a, \
126      EFI_ACPI_TABLE_INSTANCE, \
127      AcpiTableProtocol, \
128      EFI_ACPI_TABLE_SIGNATURE \
129      )
130
131//
132// Protocol Constructor functions
133//
134
135/**
136  Constructor for the ACPI support protocol.  Initializes instance
137  data.
138
139  @param  AcpiTableInstance       Instance to construct
140
141  @return EFI_SUCCESS             Instance initialized.
142  @return EFI_OUT_OF_RESOURCES    Unable to allocate required resources.
143
144**/
145EFI_STATUS
146AcpiTableAcpiTableConstructor (
147  EFI_ACPI_TABLE_INSTANCE                 *AcpiTableInstance
148  );
149
150
151/**
152  Entry point of the ACPI table driver.
153  Creates and initializes an instance of the ACPI Table
154  Protocol and installs it on a new handle.
155
156  @param  ImageHandle   A handle for the image that is initializing this driver
157  @param  SystemTable   A pointer to the EFI system table
158
159  @return EFI_SUCCESS           Driver initialized successfully
160  @return EFI_LOAD_ERROR        Failed to Initialize or has been loaded
161  @return EFI_OUT_OF_RESOURCES  Could not allocate needed resources
162
163**/
164EFI_STATUS
165EFIAPI
166InitializeAcpiTableDxe (
167  IN EFI_HANDLE           ImageHandle,
168  IN EFI_SYSTEM_TABLE     *SystemTable
169  );
170
171/**
172
173  This function finds the table specified by the handle and returns a pointer to it.
174  If the handle is not found, EFI_NOT_FOUND is returned and the contents of Table are
175  undefined.
176
177  @param[in]  Handle      Table to find.
178  @param[in]  TableList   Table list to search
179  @param[out] Table       Pointer to table found.
180
181  @retval EFI_SUCCESS              The function completed successfully.
182  @retval EFI_NOT_FOUND            No table found matching the handle specified.
183
184**/
185EFI_STATUS
186FindTableByHandle (
187  IN UINTN                                Handle,
188  IN LIST_ENTRY                           *TableList,
189  OUT EFI_ACPI_TABLE_LIST                 **Table
190  );
191
192/**
193
194  This function calculates and updates an UINT8 checksum.
195
196  @param[in]  Buffer          Pointer to buffer to checksum
197  @param[in]  Size            Number of bytes to checksum
198  @param[in]  ChecksumOffset  Offset to place the checksum result in
199
200  @retval EFI_SUCCESS             The function completed successfully.
201
202**/
203EFI_STATUS
204AcpiPlatformChecksum (
205  IN VOID       *Buffer,
206  IN UINTN      Size,
207  IN UINTN      ChecksumOffset
208  );
209
210/**
211  This function invokes ACPI notification.
212
213  @param[in]  AcpiTableInstance          Instance to AcpiTable
214  @param[in]  Version                    Version(s) to set.
215  @param[in]  Handle                     Handle of the table.
216**/
217VOID
218SdtNotifyAcpiList (
219  IN EFI_ACPI_TABLE_INSTANCE   *AcpiTableInstance,
220  IN EFI_ACPI_TABLE_VERSION    Version,
221  IN UINTN                     Handle
222  );
223
224/**
225  This function initializes AcpiSdt protocol in ACPI table instance.
226
227  @param[in]  AcpiTableInstance       Instance to construct
228**/
229VOID
230SdtAcpiTableAcpiSdtConstructor (
231  IN EFI_ACPI_TABLE_INSTANCE   *AcpiTableInstance
232  );
233
234//
235// export PrivateData symbol, because we need that in AcpiSdtProtol implementation
236//
237extern EFI_HANDLE                mHandle;
238extern EFI_ACPI_TABLE_INSTANCE   *mPrivateData;
239
240#endif
241