1 /******************************************************************************
3 * Module Name: antables - ACPI table setup/install for AcpiNames utility
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2013, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
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.
44 #include "acpinames.h"
46 #define _COMPONENT ACPI_TOOLS
47 ACPI_MODULE_NAME ("antables")
49 /* Local prototypes */
52 AeLocalGetRootPointer (
55 /* Non-AML tables that are constructed locally and installed */
57 static ACPI_TABLE_RSDP LocalRSDP
;
58 static ACPI_TABLE_FACS LocalFACS
;
61 * We need a local FADT so that the hardware subcomponent will function,
62 * even though the underlying OSD HW access functions don't do anything.
64 static ACPI_TABLE_FADT LocalFADT
;
67 * Use XSDT so that both 32- and 64-bit versions of this utility will
68 * function automatically.
70 static ACPI_TABLE_XSDT
*LocalXSDT
;
72 #define BASE_XSDT_TABLES 1
73 #define BASE_XSDT_SIZE (sizeof (ACPI_TABLE_XSDT) + \
74 ((BASE_XSDT_TABLES -1) * sizeof (UINT64)))
76 ACPI_TABLE_DESC Tables
[ACPI_MAX_INIT_TABLES
];
79 /******************************************************************************
81 * FUNCTION: AeBuildLocalTables
83 * PARAMETERS: TableCount - Number of tables on the command line
84 * TableList - List of actual tables from files
88 * DESCRIPTION: Build a complete ACPI table chain, with a local RSDP, XSDT,
89 * FADT, FACS, and the input DSDT/SSDT.
91 *****************************************************************************/
96 AE_TABLE_DESC
*TableList
)
98 ACPI_PHYSICAL_ADDRESS DsdtAddress
= 0;
100 AE_TABLE_DESC
*NextTable
;
102 ACPI_TABLE_FADT
*ExternalFadt
= NULL
;
106 * Update the table count. For DSDT, it is not put into the XSDT. For
107 * FADT, this is already accounted for since we usually install a
110 NextTable
= TableList
;
113 if (ACPI_COMPARE_NAME (NextTable
->Table
->Signature
, ACPI_SIG_DSDT
) ||
114 ACPI_COMPARE_NAME (NextTable
->Table
->Signature
, ACPI_SIG_FADT
))
118 NextTable
= NextTable
->Next
;
121 XsdtSize
= BASE_XSDT_SIZE
+ (TableCount
* sizeof (UINT64
));
125 LocalXSDT
= AcpiOsAllocate (XsdtSize
);
128 return (AE_NO_MEMORY
);
131 ACPI_MEMSET (LocalXSDT
, 0, XsdtSize
);
132 ACPI_MOVE_NAME (LocalXSDT
->Header
.Signature
, ACPI_SIG_XSDT
);
133 LocalXSDT
->Header
.Length
= XsdtSize
;
134 LocalXSDT
->Header
.Revision
= 1;
136 LocalXSDT
->TableOffsetEntry
[0] = ACPI_PTR_TO_PHYSADDR (&LocalFADT
);
139 * Install the user tables. The DSDT must be installed in the FADT.
140 * All other tables are installed directly into the XSDT.
142 NextIndex
= BASE_XSDT_TABLES
;
143 NextTable
= TableList
;
147 * Incoming DSDT or FADT are special cases. All other tables are
148 * just immediately installed into the XSDT.
150 if (ACPI_COMPARE_NAME (NextTable
->Table
->Signature
, ACPI_SIG_DSDT
))
154 printf ("Already found a DSDT, only one allowed\n");
155 return (AE_ALREADY_EXISTS
);
158 /* The incoming user table is a DSDT */
160 DsdtAddress
= ACPI_PTR_TO_PHYSADDR (NextTable
->Table
);
162 else if (ACPI_COMPARE_NAME (NextTable
->Table
->Signature
, ACPI_SIG_FADT
))
164 ExternalFadt
= ACPI_CAST_PTR (ACPI_TABLE_FADT
, NextTable
->Table
);
165 LocalXSDT
->TableOffsetEntry
[2] = ACPI_PTR_TO_PHYSADDR (NextTable
->Table
);
169 /* Install the table in the XSDT */
171 LocalXSDT
->TableOffsetEntry
[NextIndex
] = ACPI_PTR_TO_PHYSADDR (NextTable
->Table
);
175 NextTable
= NextTable
->Next
;
180 ACPI_MEMSET (&LocalRSDP
, 0, sizeof (ACPI_TABLE_RSDP
));
181 ACPI_MAKE_RSDP_SIG (LocalRSDP
.Signature
);
182 ACPI_MEMCPY (LocalRSDP
.OemId
, "I_TEST", 6);
183 LocalRSDP
.Revision
= 2;
184 LocalRSDP
.XsdtPhysicalAddress
= ACPI_PTR_TO_PHYSADDR (LocalXSDT
);
185 LocalRSDP
.Length
= sizeof (ACPI_TABLE_XSDT
);
187 /* Set checksums for both XSDT and RSDP */
189 LocalXSDT
->Header
.Checksum
= (UINT8
) -AcpiTbChecksum (
190 (void *) LocalXSDT
, LocalXSDT
->Header
.Length
);
191 LocalRSDP
.Checksum
= (UINT8
) -AcpiTbChecksum (
192 (void *) &LocalRSDP
, ACPI_RSDP_CHECKSUM_LENGTH
);
202 * Use the external FADT, but we must update the DSDT/FACS addresses
203 * as well as the checksum
205 ExternalFadt
->Dsdt
= DsdtAddress
;
206 ExternalFadt
->Facs
= ACPI_PTR_TO_PHYSADDR (&LocalFACS
);
208 if (ExternalFadt
->Header
.Length
> ACPI_PTR_DIFF (&ExternalFadt
->XDsdt
, ExternalFadt
))
210 ExternalFadt
->XDsdt
= DsdtAddress
;
211 ExternalFadt
->XFacs
= ACPI_PTR_TO_PHYSADDR (&LocalFACS
);
213 /* Complete the FADT with the checksum */
215 ExternalFadt
->Header
.Checksum
= 0;
216 ExternalFadt
->Header
.Checksum
= (UINT8
) -AcpiTbChecksum (
217 (void *) ExternalFadt
, ExternalFadt
->Header
.Length
);
222 * Build a local FADT so we can test the hardware/event init
224 ACPI_MEMSET (&LocalFADT
, 0, sizeof (ACPI_TABLE_FADT
));
225 ACPI_MOVE_NAME (LocalFADT
.Header
.Signature
, ACPI_SIG_FADT
);
227 /* Setup FADT header and DSDT/FACS addresses */
232 LocalFADT
.XDsdt
= DsdtAddress
;
233 LocalFADT
.XFacs
= ACPI_PTR_TO_PHYSADDR (&LocalFACS
);
235 LocalFADT
.Header
.Revision
= 3;
236 LocalFADT
.Header
.Length
= sizeof (ACPI_TABLE_FADT
);
238 /* Miscellaneous FADT fields */
240 LocalFADT
.Gpe0BlockLength
= 16;
241 LocalFADT
.Gpe0Block
= 0x00001234;
243 LocalFADT
.Gpe1BlockLength
= 6;
244 LocalFADT
.Gpe1Block
= 0x00005678;
245 LocalFADT
.Gpe1Base
= 96;
247 LocalFADT
.Pm1EventLength
= 4;
248 LocalFADT
.Pm1aEventBlock
= 0x00001aaa;
249 LocalFADT
.Pm1bEventBlock
= 0x00001bbb;
251 LocalFADT
.Pm1ControlLength
= 2;
252 LocalFADT
.Pm1aControlBlock
= 0xB0;
254 LocalFADT
.PmTimerLength
= 4;
255 LocalFADT
.PmTimerBlock
= 0xA0;
257 LocalFADT
.Pm2ControlBlock
= 0xC0;
258 LocalFADT
.Pm2ControlLength
= 1;
260 /* Setup one example X-64 field */
262 LocalFADT
.XPm1bEventBlock
.SpaceId
= ACPI_ADR_SPACE_SYSTEM_IO
;
263 LocalFADT
.XPm1bEventBlock
.Address
= LocalFADT
.Pm1bEventBlock
;
264 LocalFADT
.XPm1bEventBlock
.BitWidth
= (UINT8
) ACPI_MUL_8 (LocalFADT
.Pm1EventLength
);
266 /* Complete the FADT with the checksum */
268 LocalFADT
.Header
.Checksum
= 0;
269 LocalFADT
.Header
.Checksum
= (UINT8
) -AcpiTbChecksum (
270 (void *) &LocalFADT
, LocalFADT
.Header
.Length
);
275 ACPI_MEMSET (&LocalFACS
, 0, sizeof (ACPI_TABLE_FACS
));
276 ACPI_MOVE_NAME (LocalFACS
.Signature
, ACPI_SIG_FACS
);
278 LocalFACS
.Length
= sizeof (ACPI_TABLE_FACS
);
279 LocalFACS
.GlobalLock
= 0x11AA0011;
285 /******************************************************************************
287 * FUNCTION: AeLocalGetRootPointer
291 * RETURN: Address of the RSDP
293 * DESCRIPTION: Return a local RSDP, used to dynamically load tables via the
294 * standard ACPI mechanism.
296 *****************************************************************************/
298 ACPI_PHYSICAL_ADDRESS
299 AeLocalGetRootPointer (
303 return ((ACPI_PHYSICAL_ADDRESS
) &LocalRSDP
);