xref: /OK3568_Linux_fs/kernel/drivers/acpi/acpica/tbfadt.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2*4882a593Smuzhiyun /******************************************************************************
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * Module Name: tbfadt   - FADT table utilities
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  * Copyright (C) 2000 - 2020, Intel Corp.
7*4882a593Smuzhiyun  *
8*4882a593Smuzhiyun  *****************************************************************************/
9*4882a593Smuzhiyun 
10*4882a593Smuzhiyun #include <acpi/acpi.h>
11*4882a593Smuzhiyun #include "accommon.h"
12*4882a593Smuzhiyun #include "actables.h"
13*4882a593Smuzhiyun 
14*4882a593Smuzhiyun #define _COMPONENT          ACPI_TABLES
15*4882a593Smuzhiyun ACPI_MODULE_NAME("tbfadt")
16*4882a593Smuzhiyun 
17*4882a593Smuzhiyun /* Local prototypes */
18*4882a593Smuzhiyun static void
19*4882a593Smuzhiyun acpi_tb_init_generic_address(struct acpi_generic_address *generic_address,
20*4882a593Smuzhiyun 			     u8 space_id,
21*4882a593Smuzhiyun 			     u8 byte_width,
22*4882a593Smuzhiyun 			     u64 address, const char *register_name, u8 flags);
23*4882a593Smuzhiyun 
24*4882a593Smuzhiyun static void acpi_tb_convert_fadt(void);
25*4882a593Smuzhiyun 
26*4882a593Smuzhiyun static void acpi_tb_setup_fadt_registers(void);
27*4882a593Smuzhiyun 
28*4882a593Smuzhiyun static u64
29*4882a593Smuzhiyun acpi_tb_select_address(char *register_name, u32 address32, u64 address64);
30*4882a593Smuzhiyun 
31*4882a593Smuzhiyun /* Table for conversion of FADT to common internal format and FADT validation */
32*4882a593Smuzhiyun 
33*4882a593Smuzhiyun typedef struct acpi_fadt_info {
34*4882a593Smuzhiyun 	const char *name;
35*4882a593Smuzhiyun 	u16 address64;
36*4882a593Smuzhiyun 	u16 address32;
37*4882a593Smuzhiyun 	u16 length;
38*4882a593Smuzhiyun 	u8 default_length;
39*4882a593Smuzhiyun 	u8 flags;
40*4882a593Smuzhiyun 
41*4882a593Smuzhiyun } acpi_fadt_info;
42*4882a593Smuzhiyun 
43*4882a593Smuzhiyun #define ACPI_FADT_OPTIONAL          0
44*4882a593Smuzhiyun #define ACPI_FADT_REQUIRED          1
45*4882a593Smuzhiyun #define ACPI_FADT_SEPARATE_LENGTH   2
46*4882a593Smuzhiyun #define ACPI_FADT_GPE_REGISTER      4
47*4882a593Smuzhiyun 
48*4882a593Smuzhiyun static struct acpi_fadt_info fadt_info_table[] = {
49*4882a593Smuzhiyun 	{"Pm1aEventBlock",
50*4882a593Smuzhiyun 	 ACPI_FADT_OFFSET(xpm1a_event_block),
51*4882a593Smuzhiyun 	 ACPI_FADT_OFFSET(pm1a_event_block),
52*4882a593Smuzhiyun 	 ACPI_FADT_OFFSET(pm1_event_length),
53*4882a593Smuzhiyun 	 ACPI_PM1_REGISTER_WIDTH * 2,	/* Enable + Status register */
54*4882a593Smuzhiyun 	 ACPI_FADT_REQUIRED},
55*4882a593Smuzhiyun 
56*4882a593Smuzhiyun 	{"Pm1bEventBlock",
57*4882a593Smuzhiyun 	 ACPI_FADT_OFFSET(xpm1b_event_block),
58*4882a593Smuzhiyun 	 ACPI_FADT_OFFSET(pm1b_event_block),
59*4882a593Smuzhiyun 	 ACPI_FADT_OFFSET(pm1_event_length),
60*4882a593Smuzhiyun 	 ACPI_PM1_REGISTER_WIDTH * 2,	/* Enable + Status register */
61*4882a593Smuzhiyun 	 ACPI_FADT_OPTIONAL},
62*4882a593Smuzhiyun 
63*4882a593Smuzhiyun 	{"Pm1aControlBlock",
64*4882a593Smuzhiyun 	 ACPI_FADT_OFFSET(xpm1a_control_block),
65*4882a593Smuzhiyun 	 ACPI_FADT_OFFSET(pm1a_control_block),
66*4882a593Smuzhiyun 	 ACPI_FADT_OFFSET(pm1_control_length),
67*4882a593Smuzhiyun 	 ACPI_PM1_REGISTER_WIDTH,
68*4882a593Smuzhiyun 	 ACPI_FADT_REQUIRED},
69*4882a593Smuzhiyun 
70*4882a593Smuzhiyun 	{"Pm1bControlBlock",
71*4882a593Smuzhiyun 	 ACPI_FADT_OFFSET(xpm1b_control_block),
72*4882a593Smuzhiyun 	 ACPI_FADT_OFFSET(pm1b_control_block),
73*4882a593Smuzhiyun 	 ACPI_FADT_OFFSET(pm1_control_length),
74*4882a593Smuzhiyun 	 ACPI_PM1_REGISTER_WIDTH,
75*4882a593Smuzhiyun 	 ACPI_FADT_OPTIONAL},
76*4882a593Smuzhiyun 
77*4882a593Smuzhiyun 	{"Pm2ControlBlock",
78*4882a593Smuzhiyun 	 ACPI_FADT_OFFSET(xpm2_control_block),
79*4882a593Smuzhiyun 	 ACPI_FADT_OFFSET(pm2_control_block),
80*4882a593Smuzhiyun 	 ACPI_FADT_OFFSET(pm2_control_length),
81*4882a593Smuzhiyun 	 ACPI_PM2_REGISTER_WIDTH,
82*4882a593Smuzhiyun 	 ACPI_FADT_SEPARATE_LENGTH},
83*4882a593Smuzhiyun 
84*4882a593Smuzhiyun 	{"PmTimerBlock",
85*4882a593Smuzhiyun 	 ACPI_FADT_OFFSET(xpm_timer_block),
86*4882a593Smuzhiyun 	 ACPI_FADT_OFFSET(pm_timer_block),
87*4882a593Smuzhiyun 	 ACPI_FADT_OFFSET(pm_timer_length),
88*4882a593Smuzhiyun 	 ACPI_PM_TIMER_WIDTH,
89*4882a593Smuzhiyun 	 ACPI_FADT_SEPARATE_LENGTH},	/* ACPI 5.0A: Timer is optional */
90*4882a593Smuzhiyun 
91*4882a593Smuzhiyun 	{"Gpe0Block",
92*4882a593Smuzhiyun 	 ACPI_FADT_OFFSET(xgpe0_block),
93*4882a593Smuzhiyun 	 ACPI_FADT_OFFSET(gpe0_block),
94*4882a593Smuzhiyun 	 ACPI_FADT_OFFSET(gpe0_block_length),
95*4882a593Smuzhiyun 	 0,
96*4882a593Smuzhiyun 	 ACPI_FADT_SEPARATE_LENGTH | ACPI_FADT_GPE_REGISTER},
97*4882a593Smuzhiyun 
98*4882a593Smuzhiyun 	{"Gpe1Block",
99*4882a593Smuzhiyun 	 ACPI_FADT_OFFSET(xgpe1_block),
100*4882a593Smuzhiyun 	 ACPI_FADT_OFFSET(gpe1_block),
101*4882a593Smuzhiyun 	 ACPI_FADT_OFFSET(gpe1_block_length),
102*4882a593Smuzhiyun 	 0,
103*4882a593Smuzhiyun 	 ACPI_FADT_SEPARATE_LENGTH | ACPI_FADT_GPE_REGISTER}
104*4882a593Smuzhiyun };
105*4882a593Smuzhiyun 
106*4882a593Smuzhiyun #define ACPI_FADT_INFO_ENTRIES \
107*4882a593Smuzhiyun 			(sizeof (fadt_info_table) / sizeof (struct acpi_fadt_info))
108*4882a593Smuzhiyun 
109*4882a593Smuzhiyun /* Table used to split Event Blocks into separate status/enable registers */
110*4882a593Smuzhiyun 
111*4882a593Smuzhiyun typedef struct acpi_fadt_pm_info {
112*4882a593Smuzhiyun 	struct acpi_generic_address *target;
113*4882a593Smuzhiyun 	u16 source;
114*4882a593Smuzhiyun 	u8 register_num;
115*4882a593Smuzhiyun 
116*4882a593Smuzhiyun } acpi_fadt_pm_info;
117*4882a593Smuzhiyun 
118*4882a593Smuzhiyun static struct acpi_fadt_pm_info fadt_pm_info_table[] = {
119*4882a593Smuzhiyun 	{&acpi_gbl_xpm1a_status,
120*4882a593Smuzhiyun 	 ACPI_FADT_OFFSET(xpm1a_event_block),
121*4882a593Smuzhiyun 	 0},
122*4882a593Smuzhiyun 
123*4882a593Smuzhiyun 	{&acpi_gbl_xpm1a_enable,
124*4882a593Smuzhiyun 	 ACPI_FADT_OFFSET(xpm1a_event_block),
125*4882a593Smuzhiyun 	 1},
126*4882a593Smuzhiyun 
127*4882a593Smuzhiyun 	{&acpi_gbl_xpm1b_status,
128*4882a593Smuzhiyun 	 ACPI_FADT_OFFSET(xpm1b_event_block),
129*4882a593Smuzhiyun 	 0},
130*4882a593Smuzhiyun 
131*4882a593Smuzhiyun 	{&acpi_gbl_xpm1b_enable,
132*4882a593Smuzhiyun 	 ACPI_FADT_OFFSET(xpm1b_event_block),
133*4882a593Smuzhiyun 	 1}
134*4882a593Smuzhiyun };
135*4882a593Smuzhiyun 
136*4882a593Smuzhiyun #define ACPI_FADT_PM_INFO_ENTRIES \
137*4882a593Smuzhiyun 			(sizeof (fadt_pm_info_table) / sizeof (struct acpi_fadt_pm_info))
138*4882a593Smuzhiyun 
139*4882a593Smuzhiyun /*******************************************************************************
140*4882a593Smuzhiyun  *
141*4882a593Smuzhiyun  * FUNCTION:    acpi_tb_init_generic_address
142*4882a593Smuzhiyun  *
143*4882a593Smuzhiyun  * PARAMETERS:  generic_address     - GAS struct to be initialized
144*4882a593Smuzhiyun  *              space_id            - ACPI Space ID for this register
145*4882a593Smuzhiyun  *              byte_width          - Width of this register
146*4882a593Smuzhiyun  *              address             - Address of the register
147*4882a593Smuzhiyun  *              register_name       - ASCII name of the ACPI register
148*4882a593Smuzhiyun  *
149*4882a593Smuzhiyun  * RETURN:      None
150*4882a593Smuzhiyun  *
151*4882a593Smuzhiyun  * DESCRIPTION: Initialize a Generic Address Structure (GAS)
152*4882a593Smuzhiyun  *              See the ACPI specification for a full description and
153*4882a593Smuzhiyun  *              definition of this structure.
154*4882a593Smuzhiyun  *
155*4882a593Smuzhiyun  ******************************************************************************/
156*4882a593Smuzhiyun 
157*4882a593Smuzhiyun static void
acpi_tb_init_generic_address(struct acpi_generic_address * generic_address,u8 space_id,u8 byte_width,u64 address,const char * register_name,u8 flags)158*4882a593Smuzhiyun acpi_tb_init_generic_address(struct acpi_generic_address *generic_address,
159*4882a593Smuzhiyun 			     u8 space_id,
160*4882a593Smuzhiyun 			     u8 byte_width,
161*4882a593Smuzhiyun 			     u64 address, const char *register_name, u8 flags)
162*4882a593Smuzhiyun {
163*4882a593Smuzhiyun 	u8 bit_width;
164*4882a593Smuzhiyun 
165*4882a593Smuzhiyun 	/*
166*4882a593Smuzhiyun 	 * Bit width field in the GAS is only one byte long, 255 max.
167*4882a593Smuzhiyun 	 * Check for bit_width overflow in GAS.
168*4882a593Smuzhiyun 	 */
169*4882a593Smuzhiyun 	bit_width = (u8)(byte_width * 8);
170*4882a593Smuzhiyun 	if (byte_width > 31) {	/* (31*8)=248, (32*8)=256 */
171*4882a593Smuzhiyun 		/*
172*4882a593Smuzhiyun 		 * No error for GPE blocks, because we do not use the bit_width
173*4882a593Smuzhiyun 		 * for GPEs, the legacy length (byte_width) is used instead to
174*4882a593Smuzhiyun 		 * allow for a large number of GPEs.
175*4882a593Smuzhiyun 		 */
176*4882a593Smuzhiyun 		if (!(flags & ACPI_FADT_GPE_REGISTER)) {
177*4882a593Smuzhiyun 			ACPI_ERROR((AE_INFO,
178*4882a593Smuzhiyun 				    "%s - 32-bit FADT register is too long (%u bytes, %u bits) "
179*4882a593Smuzhiyun 				    "to convert to GAS struct - 255 bits max, truncating",
180*4882a593Smuzhiyun 				    register_name, byte_width,
181*4882a593Smuzhiyun 				    (byte_width * 8)));
182*4882a593Smuzhiyun 		}
183*4882a593Smuzhiyun 
184*4882a593Smuzhiyun 		bit_width = 255;
185*4882a593Smuzhiyun 	}
186*4882a593Smuzhiyun 
187*4882a593Smuzhiyun 	/*
188*4882a593Smuzhiyun 	 * The 64-bit Address field is non-aligned in the byte packed
189*4882a593Smuzhiyun 	 * GAS struct.
190*4882a593Smuzhiyun 	 */
191*4882a593Smuzhiyun 	ACPI_MOVE_64_TO_64(&generic_address->address, &address);
192*4882a593Smuzhiyun 
193*4882a593Smuzhiyun 	/* All other fields are byte-wide */
194*4882a593Smuzhiyun 
195*4882a593Smuzhiyun 	generic_address->space_id = space_id;
196*4882a593Smuzhiyun 	generic_address->bit_width = bit_width;
197*4882a593Smuzhiyun 	generic_address->bit_offset = 0;
198*4882a593Smuzhiyun 	generic_address->access_width = 0;	/* Access width ANY */
199*4882a593Smuzhiyun }
200*4882a593Smuzhiyun 
201*4882a593Smuzhiyun /*******************************************************************************
202*4882a593Smuzhiyun  *
203*4882a593Smuzhiyun  * FUNCTION:    acpi_tb_select_address
204*4882a593Smuzhiyun  *
205*4882a593Smuzhiyun  * PARAMETERS:  register_name       - ASCII name of the ACPI register
206*4882a593Smuzhiyun  *              address32           - 32-bit address of the register
207*4882a593Smuzhiyun  *              address64           - 64-bit address of the register
208*4882a593Smuzhiyun  *
209*4882a593Smuzhiyun  * RETURN:      The resolved 64-bit address
210*4882a593Smuzhiyun  *
211*4882a593Smuzhiyun  * DESCRIPTION: Select between 32-bit and 64-bit versions of addresses within
212*4882a593Smuzhiyun  *              the FADT. Used for the FACS and DSDT addresses.
213*4882a593Smuzhiyun  *
214*4882a593Smuzhiyun  * NOTES:
215*4882a593Smuzhiyun  *
216*4882a593Smuzhiyun  * Check for FACS and DSDT address mismatches. An address mismatch between
217*4882a593Smuzhiyun  * the 32-bit and 64-bit address fields (FIRMWARE_CTRL/X_FIRMWARE_CTRL and
218*4882a593Smuzhiyun  * DSDT/X_DSDT) could be a corrupted address field or it might indicate
219*4882a593Smuzhiyun  * the presence of two FACS or two DSDT tables.
220*4882a593Smuzhiyun  *
221*4882a593Smuzhiyun  * November 2013:
222*4882a593Smuzhiyun  * By default, as per the ACPICA specification, a valid 64-bit address is
223*4882a593Smuzhiyun  * used regardless of the value of the 32-bit address. However, this
224*4882a593Smuzhiyun  * behavior can be overridden via the acpi_gbl_use32_bit_fadt_addresses flag.
225*4882a593Smuzhiyun  *
226*4882a593Smuzhiyun  ******************************************************************************/
227*4882a593Smuzhiyun 
228*4882a593Smuzhiyun static u64
acpi_tb_select_address(char * register_name,u32 address32,u64 address64)229*4882a593Smuzhiyun acpi_tb_select_address(char *register_name, u32 address32, u64 address64)
230*4882a593Smuzhiyun {
231*4882a593Smuzhiyun 
232*4882a593Smuzhiyun 	if (!address64) {
233*4882a593Smuzhiyun 
234*4882a593Smuzhiyun 		/* 64-bit address is zero, use 32-bit address */
235*4882a593Smuzhiyun 
236*4882a593Smuzhiyun 		return ((u64)address32);
237*4882a593Smuzhiyun 	}
238*4882a593Smuzhiyun 
239*4882a593Smuzhiyun 	if (address32 && (address64 != (u64)address32)) {
240*4882a593Smuzhiyun 
241*4882a593Smuzhiyun 		/* Address mismatch between 32-bit and 64-bit versions */
242*4882a593Smuzhiyun 
243*4882a593Smuzhiyun 		ACPI_BIOS_WARNING((AE_INFO,
244*4882a593Smuzhiyun 				   "32/64X %s address mismatch in FADT: "
245*4882a593Smuzhiyun 				   "0x%8.8X/0x%8.8X%8.8X, using %u-bit address",
246*4882a593Smuzhiyun 				   register_name, address32,
247*4882a593Smuzhiyun 				   ACPI_FORMAT_UINT64(address64),
248*4882a593Smuzhiyun 				   acpi_gbl_use32_bit_fadt_addresses ? 32 :
249*4882a593Smuzhiyun 				   64));
250*4882a593Smuzhiyun 
251*4882a593Smuzhiyun 		/* 32-bit address override */
252*4882a593Smuzhiyun 
253*4882a593Smuzhiyun 		if (acpi_gbl_use32_bit_fadt_addresses) {
254*4882a593Smuzhiyun 			return ((u64)address32);
255*4882a593Smuzhiyun 		}
256*4882a593Smuzhiyun 	}
257*4882a593Smuzhiyun 
258*4882a593Smuzhiyun 	/* Default is to use the 64-bit address */
259*4882a593Smuzhiyun 
260*4882a593Smuzhiyun 	return (address64);
261*4882a593Smuzhiyun }
262*4882a593Smuzhiyun 
263*4882a593Smuzhiyun /*******************************************************************************
264*4882a593Smuzhiyun  *
265*4882a593Smuzhiyun  * FUNCTION:    acpi_tb_parse_fadt
266*4882a593Smuzhiyun  *
267*4882a593Smuzhiyun  * PARAMETERS:  None
268*4882a593Smuzhiyun  *
269*4882a593Smuzhiyun  * RETURN:      None
270*4882a593Smuzhiyun  *
271*4882a593Smuzhiyun  * DESCRIPTION: Initialize the FADT, DSDT and FACS tables
272*4882a593Smuzhiyun  *              (FADT contains the addresses of the DSDT and FACS)
273*4882a593Smuzhiyun  *
274*4882a593Smuzhiyun  ******************************************************************************/
275*4882a593Smuzhiyun 
acpi_tb_parse_fadt(void)276*4882a593Smuzhiyun void acpi_tb_parse_fadt(void)
277*4882a593Smuzhiyun {
278*4882a593Smuzhiyun 	u32 length;
279*4882a593Smuzhiyun 	struct acpi_table_header *table;
280*4882a593Smuzhiyun 	struct acpi_table_desc *fadt_desc;
281*4882a593Smuzhiyun 	acpi_status status;
282*4882a593Smuzhiyun 
283*4882a593Smuzhiyun 	/*
284*4882a593Smuzhiyun 	 * The FADT has multiple versions with different lengths,
285*4882a593Smuzhiyun 	 * and it contains pointers to both the DSDT and FACS tables.
286*4882a593Smuzhiyun 	 *
287*4882a593Smuzhiyun 	 * Get a local copy of the FADT and convert it to a common format
288*4882a593Smuzhiyun 	 * Map entire FADT, assumed to be smaller than one page.
289*4882a593Smuzhiyun 	 */
290*4882a593Smuzhiyun 	fadt_desc = &acpi_gbl_root_table_list.tables[acpi_gbl_fadt_index];
291*4882a593Smuzhiyun 	status = acpi_tb_get_table(fadt_desc, &table);
292*4882a593Smuzhiyun 	if (ACPI_FAILURE(status)) {
293*4882a593Smuzhiyun 		return;
294*4882a593Smuzhiyun 	}
295*4882a593Smuzhiyun 	length = fadt_desc->length;
296*4882a593Smuzhiyun 
297*4882a593Smuzhiyun 	/*
298*4882a593Smuzhiyun 	 * Validate the FADT checksum before we copy the table. Ignore
299*4882a593Smuzhiyun 	 * checksum error as we want to try to get the DSDT and FACS.
300*4882a593Smuzhiyun 	 */
301*4882a593Smuzhiyun 	(void)acpi_tb_verify_checksum(table, length);
302*4882a593Smuzhiyun 
303*4882a593Smuzhiyun 	/* Create a local copy of the FADT in common ACPI 2.0+ format */
304*4882a593Smuzhiyun 
305*4882a593Smuzhiyun 	acpi_tb_create_local_fadt(table, length);
306*4882a593Smuzhiyun 
307*4882a593Smuzhiyun 	/* All done with the real FADT, unmap it */
308*4882a593Smuzhiyun 
309*4882a593Smuzhiyun 	acpi_tb_put_table(fadt_desc);
310*4882a593Smuzhiyun 
311*4882a593Smuzhiyun 	/* Obtain the DSDT and FACS tables via their addresses within the FADT */
312*4882a593Smuzhiyun 
313*4882a593Smuzhiyun 	acpi_tb_install_standard_table((acpi_physical_address)acpi_gbl_FADT.
314*4882a593Smuzhiyun 				       Xdsdt,
315*4882a593Smuzhiyun 				       ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL,
316*4882a593Smuzhiyun 				       FALSE, TRUE, &acpi_gbl_dsdt_index);
317*4882a593Smuzhiyun 
318*4882a593Smuzhiyun 	/* If Hardware Reduced flag is set, there is no FACS */
319*4882a593Smuzhiyun 
320*4882a593Smuzhiyun 	if (!acpi_gbl_reduced_hardware) {
321*4882a593Smuzhiyun 		if (acpi_gbl_FADT.facs) {
322*4882a593Smuzhiyun 			acpi_tb_install_standard_table((acpi_physical_address)
323*4882a593Smuzhiyun 						       acpi_gbl_FADT.facs,
324*4882a593Smuzhiyun 						       ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL,
325*4882a593Smuzhiyun 						       FALSE, TRUE,
326*4882a593Smuzhiyun 						       &acpi_gbl_facs_index);
327*4882a593Smuzhiyun 		}
328*4882a593Smuzhiyun 		if (acpi_gbl_FADT.Xfacs) {
329*4882a593Smuzhiyun 			acpi_tb_install_standard_table((acpi_physical_address)
330*4882a593Smuzhiyun 						       acpi_gbl_FADT.Xfacs,
331*4882a593Smuzhiyun 						       ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL,
332*4882a593Smuzhiyun 						       FALSE, TRUE,
333*4882a593Smuzhiyun 						       &acpi_gbl_xfacs_index);
334*4882a593Smuzhiyun 		}
335*4882a593Smuzhiyun 	}
336*4882a593Smuzhiyun }
337*4882a593Smuzhiyun 
338*4882a593Smuzhiyun /*******************************************************************************
339*4882a593Smuzhiyun  *
340*4882a593Smuzhiyun  * FUNCTION:    acpi_tb_create_local_fadt
341*4882a593Smuzhiyun  *
342*4882a593Smuzhiyun  * PARAMETERS:  table               - Pointer to BIOS FADT
343*4882a593Smuzhiyun  *              length              - Length of the table
344*4882a593Smuzhiyun  *
345*4882a593Smuzhiyun  * RETURN:      None
346*4882a593Smuzhiyun  *
347*4882a593Smuzhiyun  * DESCRIPTION: Get a local copy of the FADT and convert it to a common format.
348*4882a593Smuzhiyun  *              Performs validation on some important FADT fields.
349*4882a593Smuzhiyun  *
350*4882a593Smuzhiyun  * NOTE:        We create a local copy of the FADT regardless of the version.
351*4882a593Smuzhiyun  *
352*4882a593Smuzhiyun  ******************************************************************************/
353*4882a593Smuzhiyun 
acpi_tb_create_local_fadt(struct acpi_table_header * table,u32 length)354*4882a593Smuzhiyun void acpi_tb_create_local_fadt(struct acpi_table_header *table, u32 length)
355*4882a593Smuzhiyun {
356*4882a593Smuzhiyun 	/*
357*4882a593Smuzhiyun 	 * Check if the FADT is larger than the largest table that we expect
358*4882a593Smuzhiyun 	 * (typically the current ACPI specification version). If so, truncate
359*4882a593Smuzhiyun 	 * the table, and issue a warning.
360*4882a593Smuzhiyun 	 */
361*4882a593Smuzhiyun 	if (length > sizeof(struct acpi_table_fadt)) {
362*4882a593Smuzhiyun 		ACPI_BIOS_WARNING((AE_INFO,
363*4882a593Smuzhiyun 				   "FADT (revision %u) is longer than %s length, "
364*4882a593Smuzhiyun 				   "truncating length %u to %u",
365*4882a593Smuzhiyun 				   table->revision, ACPI_FADT_CONFORMANCE,
366*4882a593Smuzhiyun 				   length,
367*4882a593Smuzhiyun 				   (u32)sizeof(struct acpi_table_fadt)));
368*4882a593Smuzhiyun 	}
369*4882a593Smuzhiyun 
370*4882a593Smuzhiyun 	/* Clear the entire local FADT */
371*4882a593Smuzhiyun 
372*4882a593Smuzhiyun 	memset(&acpi_gbl_FADT, 0, sizeof(struct acpi_table_fadt));
373*4882a593Smuzhiyun 
374*4882a593Smuzhiyun 	/* Copy the original FADT, up to sizeof (struct acpi_table_fadt) */
375*4882a593Smuzhiyun 
376*4882a593Smuzhiyun 	memcpy(&acpi_gbl_FADT, table,
377*4882a593Smuzhiyun 	       ACPI_MIN(length, sizeof(struct acpi_table_fadt)));
378*4882a593Smuzhiyun 
379*4882a593Smuzhiyun 	/* Take a copy of the Hardware Reduced flag */
380*4882a593Smuzhiyun 
381*4882a593Smuzhiyun 	acpi_gbl_reduced_hardware = FALSE;
382*4882a593Smuzhiyun 	if (acpi_gbl_FADT.flags & ACPI_FADT_HW_REDUCED) {
383*4882a593Smuzhiyun 		acpi_gbl_reduced_hardware = TRUE;
384*4882a593Smuzhiyun 	}
385*4882a593Smuzhiyun 
386*4882a593Smuzhiyun 	/* Convert the local copy of the FADT to the common internal format */
387*4882a593Smuzhiyun 
388*4882a593Smuzhiyun 	acpi_tb_convert_fadt();
389*4882a593Smuzhiyun 
390*4882a593Smuzhiyun 	/* Initialize the global ACPI register structures */
391*4882a593Smuzhiyun 
392*4882a593Smuzhiyun 	acpi_tb_setup_fadt_registers();
393*4882a593Smuzhiyun }
394*4882a593Smuzhiyun 
395*4882a593Smuzhiyun /*******************************************************************************
396*4882a593Smuzhiyun  *
397*4882a593Smuzhiyun  * FUNCTION:    acpi_tb_convert_fadt
398*4882a593Smuzhiyun  *
399*4882a593Smuzhiyun  * PARAMETERS:  none - acpi_gbl_FADT is used.
400*4882a593Smuzhiyun  *
401*4882a593Smuzhiyun  * RETURN:      None
402*4882a593Smuzhiyun  *
403*4882a593Smuzhiyun  * DESCRIPTION: Converts all versions of the FADT to a common internal format.
404*4882a593Smuzhiyun  *              Expand 32-bit addresses to 64-bit as necessary. Also validate
405*4882a593Smuzhiyun  *              important fields within the FADT.
406*4882a593Smuzhiyun  *
407*4882a593Smuzhiyun  * NOTE:        acpi_gbl_FADT must be of size (struct acpi_table_fadt), and must
408*4882a593Smuzhiyun  *              contain a copy of the actual BIOS-provided FADT.
409*4882a593Smuzhiyun  *
410*4882a593Smuzhiyun  * Notes on 64-bit register addresses:
411*4882a593Smuzhiyun  *
412*4882a593Smuzhiyun  * After this FADT conversion, later ACPICA code will only use the 64-bit "X"
413*4882a593Smuzhiyun  * fields of the FADT for all ACPI register addresses.
414*4882a593Smuzhiyun  *
415*4882a593Smuzhiyun  * The 64-bit X fields are optional extensions to the original 32-bit FADT
416*4882a593Smuzhiyun  * V1.0 fields. Even if they are present in the FADT, they are optional and
417*4882a593Smuzhiyun  * are unused if the BIOS sets them to zero. Therefore, we must copy/expand
418*4882a593Smuzhiyun  * 32-bit V1.0 fields to the 64-bit X fields if the 64-bit X field is originally
419*4882a593Smuzhiyun  * zero.
420*4882a593Smuzhiyun  *
421*4882a593Smuzhiyun  * For ACPI 1.0 FADTs (that contain no 64-bit addresses), all 32-bit address
422*4882a593Smuzhiyun  * fields are expanded to the corresponding 64-bit X fields in the internal
423*4882a593Smuzhiyun  * common FADT.
424*4882a593Smuzhiyun  *
425*4882a593Smuzhiyun  * For ACPI 2.0+ FADTs, all valid (non-zero) 32-bit address fields are expanded
426*4882a593Smuzhiyun  * to the corresponding 64-bit X fields, if the 64-bit field is originally
427*4882a593Smuzhiyun  * zero. Adhering to the ACPI specification, we completely ignore the 32-bit
428*4882a593Smuzhiyun  * field if the 64-bit field is valid, regardless of whether the host OS is
429*4882a593Smuzhiyun  * 32-bit or 64-bit.
430*4882a593Smuzhiyun  *
431*4882a593Smuzhiyun  * Possible additional checks:
432*4882a593Smuzhiyun  *  (acpi_gbl_FADT.pm1_event_length >= 4)
433*4882a593Smuzhiyun  *  (acpi_gbl_FADT.pm1_control_length >= 2)
434*4882a593Smuzhiyun  *  (acpi_gbl_FADT.pm_timer_length >= 4)
435*4882a593Smuzhiyun  *  Gpe block lengths must be multiple of 2
436*4882a593Smuzhiyun  *
437*4882a593Smuzhiyun  ******************************************************************************/
438*4882a593Smuzhiyun 
acpi_tb_convert_fadt(void)439*4882a593Smuzhiyun static void acpi_tb_convert_fadt(void)
440*4882a593Smuzhiyun {
441*4882a593Smuzhiyun 	const char *name;
442*4882a593Smuzhiyun 	struct acpi_generic_address *address64;
443*4882a593Smuzhiyun 	u32 address32;
444*4882a593Smuzhiyun 	u8 length;
445*4882a593Smuzhiyun 	u8 flags;
446*4882a593Smuzhiyun 	u32 i;
447*4882a593Smuzhiyun 
448*4882a593Smuzhiyun 	/*
449*4882a593Smuzhiyun 	 * For ACPI 1.0 FADTs (revision 1 or 2), ensure that reserved fields which
450*4882a593Smuzhiyun 	 * should be zero are indeed zero. This will workaround BIOSs that
451*4882a593Smuzhiyun 	 * inadvertently place values in these fields.
452*4882a593Smuzhiyun 	 *
453*4882a593Smuzhiyun 	 * The ACPI 1.0 reserved fields that will be zeroed are the bytes located
454*4882a593Smuzhiyun 	 * at offset 45, 55, 95, and the word located at offset 109, 110.
455*4882a593Smuzhiyun 	 *
456*4882a593Smuzhiyun 	 * Note: The FADT revision value is unreliable. Only the length can be
457*4882a593Smuzhiyun 	 * trusted.
458*4882a593Smuzhiyun 	 */
459*4882a593Smuzhiyun 	if (acpi_gbl_FADT.header.length <= ACPI_FADT_V2_SIZE) {
460*4882a593Smuzhiyun 		acpi_gbl_FADT.preferred_profile = 0;
461*4882a593Smuzhiyun 		acpi_gbl_FADT.pstate_control = 0;
462*4882a593Smuzhiyun 		acpi_gbl_FADT.cst_control = 0;
463*4882a593Smuzhiyun 		acpi_gbl_FADT.boot_flags = 0;
464*4882a593Smuzhiyun 	}
465*4882a593Smuzhiyun 
466*4882a593Smuzhiyun 	/*
467*4882a593Smuzhiyun 	 * Now we can update the local FADT length to the length of the
468*4882a593Smuzhiyun 	 * current FADT version as defined by the ACPI specification.
469*4882a593Smuzhiyun 	 * Thus, we will have a common FADT internally.
470*4882a593Smuzhiyun 	 */
471*4882a593Smuzhiyun 	acpi_gbl_FADT.header.length = sizeof(struct acpi_table_fadt);
472*4882a593Smuzhiyun 
473*4882a593Smuzhiyun 	/*
474*4882a593Smuzhiyun 	 * Expand the 32-bit DSDT addresses to 64-bit as necessary.
475*4882a593Smuzhiyun 	 * Later ACPICA code will always use the X 64-bit field.
476*4882a593Smuzhiyun 	 */
477*4882a593Smuzhiyun 	acpi_gbl_FADT.Xdsdt = acpi_tb_select_address("DSDT",
478*4882a593Smuzhiyun 						     acpi_gbl_FADT.dsdt,
479*4882a593Smuzhiyun 						     acpi_gbl_FADT.Xdsdt);
480*4882a593Smuzhiyun 
481*4882a593Smuzhiyun 	/* If Hardware Reduced flag is set, we are all done */
482*4882a593Smuzhiyun 
483*4882a593Smuzhiyun 	if (acpi_gbl_reduced_hardware) {
484*4882a593Smuzhiyun 		return;
485*4882a593Smuzhiyun 	}
486*4882a593Smuzhiyun 
487*4882a593Smuzhiyun 	/* Examine all of the 64-bit extended address fields (X fields) */
488*4882a593Smuzhiyun 
489*4882a593Smuzhiyun 	for (i = 0; i < ACPI_FADT_INFO_ENTRIES; i++) {
490*4882a593Smuzhiyun 		/*
491*4882a593Smuzhiyun 		 * Get the 32-bit and 64-bit addresses, as well as the register
492*4882a593Smuzhiyun 		 * length and register name.
493*4882a593Smuzhiyun 		 */
494*4882a593Smuzhiyun 		address32 = *ACPI_ADD_PTR(u32,
495*4882a593Smuzhiyun 					  &acpi_gbl_FADT,
496*4882a593Smuzhiyun 					  fadt_info_table[i].address32);
497*4882a593Smuzhiyun 
498*4882a593Smuzhiyun 		address64 = ACPI_ADD_PTR(struct acpi_generic_address,
499*4882a593Smuzhiyun 					 &acpi_gbl_FADT,
500*4882a593Smuzhiyun 					 fadt_info_table[i].address64);
501*4882a593Smuzhiyun 
502*4882a593Smuzhiyun 		length = *ACPI_ADD_PTR(u8,
503*4882a593Smuzhiyun 				       &acpi_gbl_FADT,
504*4882a593Smuzhiyun 				       fadt_info_table[i].length);
505*4882a593Smuzhiyun 
506*4882a593Smuzhiyun 		name = fadt_info_table[i].name;
507*4882a593Smuzhiyun 		flags = fadt_info_table[i].flags;
508*4882a593Smuzhiyun 
509*4882a593Smuzhiyun 		/*
510*4882a593Smuzhiyun 		 * Expand the ACPI 1.0 32-bit addresses to the ACPI 2.0 64-bit "X"
511*4882a593Smuzhiyun 		 * generic address structures as necessary. Later code will always use
512*4882a593Smuzhiyun 		 * the 64-bit address structures.
513*4882a593Smuzhiyun 		 *
514*4882a593Smuzhiyun 		 * November 2013:
515*4882a593Smuzhiyun 		 * Now always use the 64-bit address if it is valid (non-zero), in
516*4882a593Smuzhiyun 		 * accordance with the ACPI specification which states that a 64-bit
517*4882a593Smuzhiyun 		 * address supersedes the 32-bit version. This behavior can be
518*4882a593Smuzhiyun 		 * overridden by the acpi_gbl_use32_bit_fadt_addresses flag.
519*4882a593Smuzhiyun 		 *
520*4882a593Smuzhiyun 		 * During 64-bit address construction and verification,
521*4882a593Smuzhiyun 		 * these cases are handled:
522*4882a593Smuzhiyun 		 *
523*4882a593Smuzhiyun 		 * Address32 zero, Address64 [don't care]   - Use Address64
524*4882a593Smuzhiyun 		 *
525*4882a593Smuzhiyun 		 * No override: if acpi_gbl_use32_bit_fadt_addresses is FALSE, and:
526*4882a593Smuzhiyun 		 * Address32 non-zero, Address64 zero       - Copy/use Address32
527*4882a593Smuzhiyun 		 * Address32 non-zero == Address64 non-zero - Use Address64
528*4882a593Smuzhiyun 		 * Address32 non-zero != Address64 non-zero - Warning, use Address64
529*4882a593Smuzhiyun 		 *
530*4882a593Smuzhiyun 		 * Override: if acpi_gbl_use32_bit_fadt_addresses is TRUE, and:
531*4882a593Smuzhiyun 		 * Address32 non-zero, Address64 zero       - Copy/use Address32
532*4882a593Smuzhiyun 		 * Address32 non-zero == Address64 non-zero - Copy/use Address32
533*4882a593Smuzhiyun 		 * Address32 non-zero != Address64 non-zero - Warning, copy/use Address32
534*4882a593Smuzhiyun 		 *
535*4882a593Smuzhiyun 		 * Note: space_id is always I/O for 32-bit legacy address fields
536*4882a593Smuzhiyun 		 */
537*4882a593Smuzhiyun 		if (address32) {
538*4882a593Smuzhiyun 			if (address64->address) {
539*4882a593Smuzhiyun 				if (address64->address != (u64)address32) {
540*4882a593Smuzhiyun 
541*4882a593Smuzhiyun 					/* Address mismatch */
542*4882a593Smuzhiyun 
543*4882a593Smuzhiyun 					ACPI_BIOS_WARNING((AE_INFO,
544*4882a593Smuzhiyun 							   "32/64X address mismatch in FADT/%s: "
545*4882a593Smuzhiyun 							   "0x%8.8X/0x%8.8X%8.8X, using %u-bit address",
546*4882a593Smuzhiyun 							   name, address32,
547*4882a593Smuzhiyun 							   ACPI_FORMAT_UINT64
548*4882a593Smuzhiyun 							   (address64->address),
549*4882a593Smuzhiyun 							   acpi_gbl_use32_bit_fadt_addresses
550*4882a593Smuzhiyun 							   ? 32 : 64));
551*4882a593Smuzhiyun 				}
552*4882a593Smuzhiyun 
553*4882a593Smuzhiyun 				/*
554*4882a593Smuzhiyun 				 * For each extended field, check for length mismatch
555*4882a593Smuzhiyun 				 * between the legacy length field and the corresponding
556*4882a593Smuzhiyun 				 * 64-bit X length field.
557*4882a593Smuzhiyun 				 * Note: If the legacy length field is > 0xFF bits, ignore
558*4882a593Smuzhiyun 				 * this check. (GPE registers can be larger than the
559*4882a593Smuzhiyun 				 * 64-bit GAS structure can accommodate, 0xFF bits).
560*4882a593Smuzhiyun 				 */
561*4882a593Smuzhiyun 				if ((ACPI_MUL_8(length) <= ACPI_UINT8_MAX) &&
562*4882a593Smuzhiyun 				    (address64->bit_width !=
563*4882a593Smuzhiyun 				     ACPI_MUL_8(length))) {
564*4882a593Smuzhiyun 					ACPI_BIOS_WARNING((AE_INFO,
565*4882a593Smuzhiyun 							   "32/64X length mismatch in FADT/%s: %u/%u",
566*4882a593Smuzhiyun 							   name,
567*4882a593Smuzhiyun 							   ACPI_MUL_8(length),
568*4882a593Smuzhiyun 							   address64->
569*4882a593Smuzhiyun 							   bit_width));
570*4882a593Smuzhiyun 				}
571*4882a593Smuzhiyun 			}
572*4882a593Smuzhiyun 
573*4882a593Smuzhiyun 			/*
574*4882a593Smuzhiyun 			 * Hardware register access code always uses the 64-bit fields.
575*4882a593Smuzhiyun 			 * So if the 64-bit field is zero or is to be overridden,
576*4882a593Smuzhiyun 			 * initialize it with the 32-bit fields.
577*4882a593Smuzhiyun 			 * Note that when the 32-bit address favor is specified, the
578*4882a593Smuzhiyun 			 * 64-bit fields are always re-initialized so that
579*4882a593Smuzhiyun 			 * access_size/bit_width/bit_offset fields can be correctly
580*4882a593Smuzhiyun 			 * configured to the values to trigger a 32-bit compatible
581*4882a593Smuzhiyun 			 * access mode in the hardware register access code.
582*4882a593Smuzhiyun 			 */
583*4882a593Smuzhiyun 			if (!address64->address
584*4882a593Smuzhiyun 			    || acpi_gbl_use32_bit_fadt_addresses) {
585*4882a593Smuzhiyun 				acpi_tb_init_generic_address(address64,
586*4882a593Smuzhiyun 							     ACPI_ADR_SPACE_SYSTEM_IO,
587*4882a593Smuzhiyun 							     length,
588*4882a593Smuzhiyun 							     (u64)address32,
589*4882a593Smuzhiyun 							     name, flags);
590*4882a593Smuzhiyun 			}
591*4882a593Smuzhiyun 		}
592*4882a593Smuzhiyun 
593*4882a593Smuzhiyun 		if (fadt_info_table[i].flags & ACPI_FADT_REQUIRED) {
594*4882a593Smuzhiyun 			/*
595*4882a593Smuzhiyun 			 * Field is required (Pm1a_event, Pm1a_control).
596*4882a593Smuzhiyun 			 * Both the address and length must be non-zero.
597*4882a593Smuzhiyun 			 */
598*4882a593Smuzhiyun 			if (!address64->address || !length) {
599*4882a593Smuzhiyun 				ACPI_BIOS_ERROR((AE_INFO,
600*4882a593Smuzhiyun 						 "Required FADT field %s has zero address and/or length: "
601*4882a593Smuzhiyun 						 "0x%8.8X%8.8X/0x%X",
602*4882a593Smuzhiyun 						 name,
603*4882a593Smuzhiyun 						 ACPI_FORMAT_UINT64(address64->
604*4882a593Smuzhiyun 								    address),
605*4882a593Smuzhiyun 						 length));
606*4882a593Smuzhiyun 			}
607*4882a593Smuzhiyun 		} else if (fadt_info_table[i].flags & ACPI_FADT_SEPARATE_LENGTH) {
608*4882a593Smuzhiyun 			/*
609*4882a593Smuzhiyun 			 * Field is optional (Pm2_control, GPE0, GPE1) AND has its own
610*4882a593Smuzhiyun 			 * length field. If present, both the address and length must
611*4882a593Smuzhiyun 			 * be valid.
612*4882a593Smuzhiyun 			 */
613*4882a593Smuzhiyun 			if ((address64->address && !length) ||
614*4882a593Smuzhiyun 			    (!address64->address && length)) {
615*4882a593Smuzhiyun 				ACPI_BIOS_WARNING((AE_INFO,
616*4882a593Smuzhiyun 						   "Optional FADT field %s has valid %s but zero %s: "
617*4882a593Smuzhiyun 						   "0x%8.8X%8.8X/0x%X", name,
618*4882a593Smuzhiyun 						   (length ? "Length" :
619*4882a593Smuzhiyun 						    "Address"),
620*4882a593Smuzhiyun 						   (length ? "Address" :
621*4882a593Smuzhiyun 						    "Length"),
622*4882a593Smuzhiyun 						   ACPI_FORMAT_UINT64
623*4882a593Smuzhiyun 						   (address64->address),
624*4882a593Smuzhiyun 						   length));
625*4882a593Smuzhiyun 			}
626*4882a593Smuzhiyun 		}
627*4882a593Smuzhiyun 	}
628*4882a593Smuzhiyun }
629*4882a593Smuzhiyun 
630*4882a593Smuzhiyun /*******************************************************************************
631*4882a593Smuzhiyun  *
632*4882a593Smuzhiyun  * FUNCTION:    acpi_tb_setup_fadt_registers
633*4882a593Smuzhiyun  *
634*4882a593Smuzhiyun  * PARAMETERS:  None, uses acpi_gbl_FADT.
635*4882a593Smuzhiyun  *
636*4882a593Smuzhiyun  * RETURN:      None
637*4882a593Smuzhiyun  *
638*4882a593Smuzhiyun  * DESCRIPTION: Initialize global ACPI PM1 register definitions. Optionally,
639*4882a593Smuzhiyun  *              force FADT register definitions to their default lengths.
640*4882a593Smuzhiyun  *
641*4882a593Smuzhiyun  ******************************************************************************/
642*4882a593Smuzhiyun 
acpi_tb_setup_fadt_registers(void)643*4882a593Smuzhiyun static void acpi_tb_setup_fadt_registers(void)
644*4882a593Smuzhiyun {
645*4882a593Smuzhiyun 	struct acpi_generic_address *target64;
646*4882a593Smuzhiyun 	struct acpi_generic_address *source64;
647*4882a593Smuzhiyun 	u8 pm1_register_byte_width;
648*4882a593Smuzhiyun 	u32 i;
649*4882a593Smuzhiyun 
650*4882a593Smuzhiyun 	/*
651*4882a593Smuzhiyun 	 * Optionally check all register lengths against the default values and
652*4882a593Smuzhiyun 	 * update them if they are incorrect.
653*4882a593Smuzhiyun 	 */
654*4882a593Smuzhiyun 	if (acpi_gbl_use_default_register_widths) {
655*4882a593Smuzhiyun 		for (i = 0; i < ACPI_FADT_INFO_ENTRIES; i++) {
656*4882a593Smuzhiyun 			target64 =
657*4882a593Smuzhiyun 			    ACPI_ADD_PTR(struct acpi_generic_address,
658*4882a593Smuzhiyun 					 &acpi_gbl_FADT,
659*4882a593Smuzhiyun 					 fadt_info_table[i].address64);
660*4882a593Smuzhiyun 
661*4882a593Smuzhiyun 			/*
662*4882a593Smuzhiyun 			 * If a valid register (Address != 0) and the (default_length > 0)
663*4882a593Smuzhiyun 			 * (Not a GPE register), then check the width against the default.
664*4882a593Smuzhiyun 			 */
665*4882a593Smuzhiyun 			if ((target64->address) &&
666*4882a593Smuzhiyun 			    (fadt_info_table[i].default_length > 0) &&
667*4882a593Smuzhiyun 			    (fadt_info_table[i].default_length !=
668*4882a593Smuzhiyun 			     target64->bit_width)) {
669*4882a593Smuzhiyun 				ACPI_BIOS_WARNING((AE_INFO,
670*4882a593Smuzhiyun 						   "Invalid length for FADT/%s: %u, using default %u",
671*4882a593Smuzhiyun 						   fadt_info_table[i].name,
672*4882a593Smuzhiyun 						   target64->bit_width,
673*4882a593Smuzhiyun 						   fadt_info_table[i].
674*4882a593Smuzhiyun 						   default_length));
675*4882a593Smuzhiyun 
676*4882a593Smuzhiyun 				/* Incorrect size, set width to the default */
677*4882a593Smuzhiyun 
678*4882a593Smuzhiyun 				target64->bit_width =
679*4882a593Smuzhiyun 				    fadt_info_table[i].default_length;
680*4882a593Smuzhiyun 			}
681*4882a593Smuzhiyun 		}
682*4882a593Smuzhiyun 	}
683*4882a593Smuzhiyun 
684*4882a593Smuzhiyun 	/*
685*4882a593Smuzhiyun 	 * Get the length of the individual PM1 registers (enable and status).
686*4882a593Smuzhiyun 	 * Each register is defined to be (event block length / 2). Extra divide
687*4882a593Smuzhiyun 	 * by 8 converts bits to bytes.
688*4882a593Smuzhiyun 	 */
689*4882a593Smuzhiyun 	pm1_register_byte_width = (u8)
690*4882a593Smuzhiyun 	    ACPI_DIV_16(acpi_gbl_FADT.xpm1a_event_block.bit_width);
691*4882a593Smuzhiyun 
692*4882a593Smuzhiyun 	/*
693*4882a593Smuzhiyun 	 * Calculate separate GAS structs for the PM1x (A/B) Status and Enable
694*4882a593Smuzhiyun 	 * registers. These addresses do not appear (directly) in the FADT, so it
695*4882a593Smuzhiyun 	 * is useful to pre-calculate them from the PM1 Event Block definitions.
696*4882a593Smuzhiyun 	 *
697*4882a593Smuzhiyun 	 * The PM event blocks are split into two register blocks, first is the
698*4882a593Smuzhiyun 	 * PM Status Register block, followed immediately by the PM Enable
699*4882a593Smuzhiyun 	 * Register block. Each is of length (pm1_event_length/2)
700*4882a593Smuzhiyun 	 *
701*4882a593Smuzhiyun 	 * Note: The PM1A event block is required by the ACPI specification.
702*4882a593Smuzhiyun 	 * However, the PM1B event block is optional and is rarely, if ever,
703*4882a593Smuzhiyun 	 * used.
704*4882a593Smuzhiyun 	 */
705*4882a593Smuzhiyun 
706*4882a593Smuzhiyun 	for (i = 0; i < ACPI_FADT_PM_INFO_ENTRIES; i++) {
707*4882a593Smuzhiyun 		source64 =
708*4882a593Smuzhiyun 		    ACPI_ADD_PTR(struct acpi_generic_address, &acpi_gbl_FADT,
709*4882a593Smuzhiyun 				 fadt_pm_info_table[i].source);
710*4882a593Smuzhiyun 
711*4882a593Smuzhiyun 		if (source64->address) {
712*4882a593Smuzhiyun 			acpi_tb_init_generic_address(fadt_pm_info_table[i].
713*4882a593Smuzhiyun 						     target, source64->space_id,
714*4882a593Smuzhiyun 						     pm1_register_byte_width,
715*4882a593Smuzhiyun 						     source64->address +
716*4882a593Smuzhiyun 						     (fadt_pm_info_table[i].
717*4882a593Smuzhiyun 						      register_num *
718*4882a593Smuzhiyun 						      pm1_register_byte_width),
719*4882a593Smuzhiyun 						     "PmRegisters", 0);
720*4882a593Smuzhiyun 		}
721*4882a593Smuzhiyun 	}
722*4882a593Smuzhiyun }
723