1 /******************************************************************************
2 *
3 * Module Name: antables - ACPI table setup/install for AcpiNames utility
4 *
5 *****************************************************************************/
6
7 /*
8 * Copyright (C) 2000 - 2016, Intel Corp.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
44 #include "acpinames.h"
45
46 #define _COMPONENT ACPI_TOOLS
47 ACPI_MODULE_NAME ("antables")
48
49 /* Local prototypes */
50
51 static void
52 AnInitializeTableHeader (
53 ACPI_TABLE_HEADER *Header,
54 char *Signature,
55 UINT32 Length);
56
57
58 /* Non-AML tables that are constructed locally and installed */
59
60 static ACPI_TABLE_RSDP LocalRSDP;
61 static ACPI_TABLE_FACS LocalFACS;
62
63 /*
64 * We need a local FADT so that the hardware subcomponent will function,
65 * even though the underlying OSD HW access functions don't do anything.
66 */
67 static ACPI_TABLE_FADT LocalFADT;
68
69 /*
70 * Use XSDT so that both 32- and 64-bit versions of this utility will
71 * function automatically.
72 */
73 static ACPI_TABLE_XSDT *LocalXSDT;
74
75 #define BASE_XSDT_TABLES 1
76 #define BASE_XSDT_SIZE (sizeof (ACPI_TABLE_XSDT) + \
77 ((BASE_XSDT_TABLES -1) * sizeof (UINT64)))
78
79
80 /******************************************************************************
81 *
82 * FUNCTION: AnInitializeTableHeader
83 *
84 * PARAMETERS: Header - A valid standard ACPI table header
85 * Signature - Signature to insert
86 * Length - Length of the table
87 *
88 * RETURN: None. Header is modified.
89 *
90 * DESCRIPTION: Initialize the table header for a local ACPI table.
91 *
92 *****************************************************************************/
93
94 static void
AnInitializeTableHeader(ACPI_TABLE_HEADER * Header,char * Signature,UINT32 Length)95 AnInitializeTableHeader (
96 ACPI_TABLE_HEADER *Header,
97 char *Signature,
98 UINT32 Length)
99 {
100
101 ACPI_MOVE_NAME (Header->Signature, Signature);
102 Header->Length = Length;
103
104 Header->OemRevision = 0x1001;
105 strncpy (Header->OemId, "Intel", ACPI_OEM_ID_SIZE);
106 strncpy (Header->OemTableId, "AcpiName", ACPI_OEM_TABLE_ID_SIZE);
107 strncpy (Header->AslCompilerId, "INTL", ACPI_NAME_SIZE);
108 Header->AslCompilerRevision = ACPI_CA_VERSION;
109
110 /* Set the checksum, must set to zero first */
111
112 Header->Checksum = 0;
113 Header->Checksum = (UINT8) -AcpiTbChecksum (
114 (void *) Header, Header->Length);
115 }
116
117
118 /******************************************************************************
119 *
120 * FUNCTION: AnBuildLocalTables
121 *
122 * PARAMETERS: TableCount - Number of tables on the command line
123 * TableList - List of actual tables from files
124 *
125 * RETURN: Status
126 *
127 * DESCRIPTION: Build a complete ACPI table chain, with a local RSDP, XSDT,
128 * FADT, FACS, and the input DSDT/SSDT.
129 *
130 *****************************************************************************/
131
132 ACPI_STATUS
AnBuildLocalTables(ACPI_NEW_TABLE_DESC * TableList)133 AnBuildLocalTables (
134 ACPI_NEW_TABLE_DESC *TableList)
135 {
136 UINT32 TableCount = 0;
137 ACPI_PHYSICAL_ADDRESS DsdtAddress = 0;
138 UINT32 XsdtSize;
139 ACPI_NEW_TABLE_DESC *NextTable;
140 UINT32 NextIndex;
141 ACPI_TABLE_FADT *ExternalFadt = NULL;
142
143
144 /*
145 * Update the table count. For the DSDT, it is not put into the XSDT.
146 * For the FADT, this table is already accounted for since we usually
147 * install a local FADT.
148 */
149 NextTable = TableList;
150 while (NextTable)
151 {
152 if (!ACPI_COMPARE_NAME (NextTable->Table->Signature, ACPI_SIG_DSDT) &&
153 !ACPI_COMPARE_NAME (NextTable->Table->Signature, ACPI_SIG_FADT))
154 {
155 TableCount++;
156 }
157
158 NextTable = NextTable->Next;
159 }
160
161 XsdtSize = BASE_XSDT_SIZE + (TableCount * sizeof (UINT64));
162
163 /* Build an XSDT */
164
165 LocalXSDT = AcpiOsAllocate (XsdtSize);
166 if (!LocalXSDT)
167 {
168 return (AE_NO_MEMORY);
169 }
170
171 memset (LocalXSDT, 0, XsdtSize);
172 LocalXSDT->TableOffsetEntry[0] = ACPI_PTR_TO_PHYSADDR (&LocalFADT);
173
174 /*
175 * Install the user tables. The DSDT must be installed in the FADT.
176 * All other tables are installed directly into the XSDT.
177 *
178 * Note: The tables are loaded in reverse order from the incoming
179 * input, which makes it match the command line order.
180 */
181 NextIndex = BASE_XSDT_TABLES;
182 NextTable = TableList;
183 while (NextTable)
184 {
185 /*
186 * Incoming DSDT or FADT are special cases. All other tables are
187 * just immediately installed into the XSDT.
188 */
189 if (ACPI_COMPARE_NAME (NextTable->Table->Signature, ACPI_SIG_DSDT))
190 {
191 if (DsdtAddress)
192 {
193 printf ("Already found a DSDT, only one allowed\n");
194 return (AE_ALREADY_EXISTS);
195 }
196
197 /* The incoming user table is a DSDT */
198
199 DsdtAddress = ACPI_PTR_TO_PHYSADDR (NextTable->Table);
200 }
201 else if (ACPI_COMPARE_NAME (NextTable->Table->Signature, ACPI_SIG_FADT))
202 {
203 ExternalFadt =
204 ACPI_CAST_PTR (ACPI_TABLE_FADT, NextTable->Table);
205 LocalXSDT->TableOffsetEntry[0] =
206 ACPI_PTR_TO_PHYSADDR (NextTable->Table);
207 }
208 else
209 {
210 /* Install the table in the XSDT */
211
212 LocalXSDT->TableOffsetEntry[TableCount - NextIndex + 1] =
213 ACPI_PTR_TO_PHYSADDR (NextTable->Table);
214 NextIndex++;
215 }
216
217 NextTable = NextTable->Next;
218 }
219
220 /* Build an RSDP. Contains a valid XSDT only, no RSDT */
221
222 memset (&LocalRSDP, 0, sizeof (ACPI_TABLE_RSDP));
223 ACPI_MAKE_RSDP_SIG (LocalRSDP.Signature);
224 memcpy (LocalRSDP.OemId, "Intel", 6);
225
226 LocalRSDP.Revision = 2;
227 LocalRSDP.XsdtPhysicalAddress = ACPI_PTR_TO_PHYSADDR (LocalXSDT);
228 LocalRSDP.Length = sizeof (ACPI_TABLE_XSDT);
229
230 /* Set checksums for both XSDT and RSDP */
231
232 AnInitializeTableHeader ((void *) LocalXSDT, ACPI_SIG_XSDT, XsdtSize);
233
234 LocalRSDP.Checksum = 0;
235 LocalRSDP.Checksum = (UINT8) -AcpiTbChecksum (
236 (void *) &LocalRSDP, ACPI_RSDP_CHECKSUM_LENGTH);
237
238 if (!DsdtAddress)
239 {
240 return (AE_SUPPORT);
241 }
242
243 /*
244 * Build an FADT. There are two options for the FADT:
245 * 1) Incoming external FADT specified on the command line
246 * 2) A fully featured local FADT
247 */
248 memset (&LocalFADT, 0, sizeof (ACPI_TABLE_FADT));
249
250 if (ExternalFadt)
251 {
252 /*
253 * Use the external FADT, but we must update the DSDT/FACS
254 * addresses as well as the checksum
255 */
256 ExternalFadt->Dsdt = (UINT32) DsdtAddress;
257 ExternalFadt->Facs = ACPI_PTR_TO_PHYSADDR (&LocalFACS);
258
259 /*
260 * If there room in the FADT for the XDsdt and XFacs 64-bit
261 * pointers, use them.
262 */
263 if (ExternalFadt->Header.Length > ACPI_PTR_DIFF (
264 &ExternalFadt->XDsdt, ExternalFadt))
265 {
266 ExternalFadt->Dsdt = 0;
267 ExternalFadt->Facs = 0;
268 ExternalFadt->XDsdt = DsdtAddress;
269 ExternalFadt->XFacs = ACPI_PTR_TO_PHYSADDR (&LocalFACS);
270 }
271
272 /* Complete the external FADT with the checksum */
273
274 ExternalFadt->Header.Checksum = 0;
275 ExternalFadt->Header.Checksum = (UINT8) -AcpiTbChecksum (
276 (void *) ExternalFadt, ExternalFadt->Header.Length);
277 }
278 else
279 {
280 /*
281 * Build a local FADT so we can test the hardware/event init
282 */
283 LocalFADT.Header.Revision = 5;
284
285 /* Setup FADT header and DSDT/FACS addresses */
286
287 LocalFADT.Dsdt = 0;
288 LocalFADT.Facs = 0;
289
290 LocalFADT.XDsdt = DsdtAddress;
291 LocalFADT.XFacs = ACPI_PTR_TO_PHYSADDR (&LocalFACS);
292
293 /* Miscellaneous FADT fields */
294
295 LocalFADT.Gpe0BlockLength = 16;
296 LocalFADT.Gpe0Block = 0x00001234;
297
298 LocalFADT.Gpe1BlockLength = 6;
299 LocalFADT.Gpe1Block = 0x00005678;
300 LocalFADT.Gpe1Base = 96;
301
302 LocalFADT.Pm1EventLength = 4;
303 LocalFADT.Pm1aEventBlock = 0x00001aaa;
304 LocalFADT.Pm1bEventBlock = 0x00001bbb;
305
306 LocalFADT.Pm1ControlLength = 2;
307 LocalFADT.Pm1aControlBlock = 0xB0;
308
309 LocalFADT.PmTimerLength = 4;
310 LocalFADT.PmTimerBlock = 0xA0;
311
312 LocalFADT.Pm2ControlBlock = 0xC0;
313 LocalFADT.Pm2ControlLength = 1;
314
315 /* Setup one example X-64 field */
316
317 LocalFADT.XPm1bEventBlock.SpaceId = ACPI_ADR_SPACE_SYSTEM_IO;
318 LocalFADT.XPm1bEventBlock.Address = LocalFADT.Pm1bEventBlock;
319 LocalFADT.XPm1bEventBlock.BitWidth = (UINT8)
320 ACPI_MUL_8 (LocalFADT.Pm1EventLength);
321 }
322
323 AnInitializeTableHeader ((void *) &LocalFADT,
324 ACPI_SIG_FADT, sizeof (ACPI_TABLE_FADT));
325
326 /* Build a FACS */
327
328 memset (&LocalFACS, 0, sizeof (ACPI_TABLE_FACS));
329 ACPI_MOVE_NAME (LocalFACS.Signature, ACPI_SIG_FACS);
330
331 LocalFACS.Length = sizeof (ACPI_TABLE_FACS);
332 LocalFACS.GlobalLock = 0x11AA0011;
333 return (AE_OK);
334 }
335
336
337 /******************************************************************************
338 *
339 * FUNCTION: AcpiOsGetRootPointer
340 *
341 * PARAMETERS: None
342 *
343 * RETURN: Address of the RSDP
344 *
345 * DESCRIPTION: Return a local RSDP, used to dynamically load tables via the
346 * standard ACPI mechanism.
347 *
348 *****************************************************************************/
349
350 ACPI_PHYSICAL_ADDRESS
AcpiOsGetRootPointer(void)351 AcpiOsGetRootPointer (
352 void)
353 {
354
355 return (ACPI_PTR_TO_PHYSADDR (&LocalRSDP));
356 }
357