Sync with trunk head
[reactos.git] / drivers / bus / acpi / acpica / tables / tbconvrt.c
1 /******************************************************************************
2 *
3 * Module Name: tbconvrt - ACPI Table conversion utilities
4 * $Revision: 1.1 $
5 *
6 *****************************************************************************/
7
8 /*
9 * Copyright (C) 2000, 2001 R. Byron Moore
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */
25
26
27 #include <acpi.h>
28
29 #define _COMPONENT ACPI_TABLES
30 MODULE_NAME ("tbconvrt")
31
32
33 /*
34 * Build a GAS structure from earlier ACPI table entries (V1.0 and 0.71 extensions)
35 *
36 * 1) Address space
37 * 2) Length in bytes -- convert to length in bits
38 * 3) Bit offset is zero
39 * 4) Reserved field is zero
40 * 5) Expand address to 64 bits
41 */
42 #define ASL_BUILD_GAS_FROM_ENTRY(a,b,c,d) {a.address_space_id = (u8) d;\
43 a.register_bit_width = (u8) MUL_8 (b);\
44 a.register_bit_offset = 0;\
45 a.reserved = 0;\
46 ACPI_STORE_ADDRESS (a.address,c);}
47
48
49 /* ACPI V1.0 entries -- address space is always I/O */
50
51 #define ASL_BUILD_GAS_FROM_V1_ENTRY(a,b,c) ASL_BUILD_GAS_FROM_ENTRY(a,b,c,ADDRESS_SPACE_SYSTEM_IO)
52
53
54 /*******************************************************************************
55 *
56 * FUNCTION: Acpi_tb_convert_to_xsdt
57 *
58 * PARAMETERS:
59 *
60 * RETURN:
61 *
62 * DESCRIPTION:
63 *
64 ******************************************************************************/
65
66 ACPI_STATUS
67 acpi_tb_convert_to_xsdt (
68 ACPI_TABLE_DESC *table_info,
69 u32 *number_of_tables) {
70 u32 table_size;
71 u32 pointer_size;
72 u32 i;
73 XSDT_DESCRIPTOR *new_table;
74
75
76 #ifndef _IA64
77
78 if (acpi_gbl_RSDP->revision < 2) {
79 pointer_size = sizeof (u32);
80 }
81
82 else
83 #endif
84 {
85 pointer_size = sizeof (UINT64);
86 }
87
88 /*
89 * Determine the number of tables pointed to by the RSDT/XSDT.
90 * This is defined by the ACPI Specification to be the number of
91 * pointers contained within the RSDT/XSDT. The size of the pointers
92 * is architecture-dependent.
93 */
94
95 table_size = table_info->pointer->length;
96 *number_of_tables = (table_size -
97 sizeof (ACPI_TABLE_HEADER)) / pointer_size;
98
99 /* Compute size of the converted XSDT */
100
101 table_size = (*number_of_tables * sizeof (UINT64)) + sizeof (ACPI_TABLE_HEADER);
102
103
104 /* Allocate an XSDT */
105
106 new_table = acpi_cm_callocate (table_size);
107 if (!new_table) {
108 return (AE_NO_MEMORY);
109 }
110
111 /* Copy the header and set the length */
112
113 MEMCPY (new_table, table_info->pointer, sizeof (ACPI_TABLE_HEADER));
114 new_table->header.length = table_size;
115
116 /* Copy the table pointers */
117
118 for (i = 0; i < *number_of_tables; i++) {
119 if (acpi_gbl_RSDP->revision < 2) {
120 #ifdef _IA64
121 new_table->table_offset_entry[i] =
122 ((RSDT_DESCRIPTOR_REV071 *) table_info->pointer)->table_offset_entry[i];
123 #else
124 ACPI_STORE_ADDRESS (new_table->table_offset_entry[i],
125 ((RSDT_DESCRIPTOR_REV1 *) table_info->pointer)->table_offset_entry[i]);
126 #endif
127 }
128 else {
129 new_table->table_offset_entry[i] =
130 ((XSDT_DESCRIPTOR *) table_info->pointer)->table_offset_entry[i];
131 }
132 }
133
134
135 /* Delete the original table (either mapped or in a buffer) */
136
137 acpi_tb_delete_single_table (table_info);
138
139
140 /* Point the table descriptor to the new table */
141
142 table_info->pointer = (ACPI_TABLE_HEADER *) new_table;
143 table_info->base_pointer = (ACPI_TABLE_HEADER *) new_table;
144 table_info->length = table_size;
145 table_info->allocation = ACPI_MEM_ALLOCATED;
146
147 return (AE_OK);
148 }
149
150
151 /*******************************************************************************
152 *
153 * FUNCTION: Acpi_tb_convert_table_fadt
154 *
155 * PARAMETERS:
156 *
157 * RETURN:
158 *
159 * DESCRIPTION:
160 * Converts BIOS supplied 1.0 and 0.71 ACPI FADT to an intermediate
161 * ACPI 2.0 FADT. If the BIOS supplied a 2.0 FADT then it is simply
162 * copied to the intermediate FADT. The ACPI CA software uses this
163 * intermediate FADT. Thus a significant amount of special #ifdef
164 * type codeing is saved. This intermediate FADT will need to be
165 * freed at some point.
166 *
167 ******************************************************************************/
168
169 ACPI_STATUS
170 acpi_tb_convert_table_fadt (void)
171 {
172
173 #ifdef _IA64
174 FADT_DESCRIPTOR_REV071 *FADT71;
175 u8 pm1_address_space;
176 u8 pm2_address_space;
177 u8 pm_timer_address_space;
178 u8 gpe0address_space;
179 u8 gpe1_address_space;
180 #else
181 FADT_DESCRIPTOR_REV1 *FADT1;
182 #endif
183
184 FADT_DESCRIPTOR_REV2 *FADT2;
185 ACPI_TABLE_DESC *table_desc;
186
187
188 /* Acpi_gbl_FADT is valid */
189 /* Allocate and zero the 2.0 buffer */
190
191 FADT2 = acpi_cm_callocate (sizeof (FADT_DESCRIPTOR_REV2));
192 if (FADT2 == NULL) {
193 return (AE_NO_MEMORY);
194 }
195
196
197 /* The ACPI FADT revision number is FADT2_REVISION_ID=3 */
198 /* So, if the current table revision is less than 3 it is type 1.0 or 0.71 */
199
200 if (acpi_gbl_FADT->header.revision >= FADT2_REVISION_ID) {
201 /* We have an ACPI 2.0 FADT but we must copy it to our local buffer */
202
203 *FADT2 = *((FADT_DESCRIPTOR_REV2*) acpi_gbl_FADT);
204
205 }
206
207 else {
208
209 #ifdef _IA64
210 /*
211 * For the 64-bit case only, a revision ID less than V2.0 means the
212 * tables are the 0.71 extensions
213 */
214
215 /* The BIOS stored FADT should agree with Revision 0.71 */
216
217 FADT71 = (FADT_DESCRIPTOR_REV071 *) acpi_gbl_FADT;
218
219 /* Copy the table header*/
220
221 FADT2->header = FADT71->header;
222
223 /* Copy the common fields */
224
225 FADT2->sci_int = FADT71->sci_int;
226 FADT2->acpi_enable = FADT71->acpi_enable;
227 FADT2->acpi_disable = FADT71->acpi_disable;
228 FADT2->S4_bios_req = FADT71->S4_bios_req;
229 FADT2->plvl2_lat = FADT71->plvl2_lat;
230 FADT2->plvl3_lat = FADT71->plvl3_lat;
231 FADT2->day_alrm = FADT71->day_alrm;
232 FADT2->mon_alrm = FADT71->mon_alrm;
233 FADT2->century = FADT71->century;
234 FADT2->gpe1_base = FADT71->gpe1_base;
235
236 /*
237 * We still use the block length registers even though
238 * the GAS structure should obsolete them. This is because
239 * these registers are byte lengths versus the GAS which
240 * contains a bit width
241 */
242 FADT2->pm1_evt_len = FADT71->pm1_evt_len;
243 FADT2->pm1_cnt_len = FADT71->pm1_cnt_len;
244 FADT2->pm2_cnt_len = FADT71->pm2_cnt_len;
245 FADT2->pm_tm_len = FADT71->pm_tm_len;
246 FADT2->gpe0blk_len = FADT71->gpe0blk_len;
247 FADT2->gpe1_blk_len = FADT71->gpe1_blk_len;
248 FADT2->gpe1_base = FADT71->gpe1_base;
249
250 /* Copy the existing 0.71 flags to 2.0. The other bits are zero.*/
251
252 FADT2->wb_invd = FADT71->flush_cash;
253 FADT2->proc_c1 = FADT71->proc_c1;
254 FADT2->plvl2_up = FADT71->plvl2_up;
255 FADT2->pwr_button = FADT71->pwr_button;
256 FADT2->sleep_button = FADT71->sleep_button;
257 FADT2->fixed_rTC = FADT71->fixed_rTC;
258 FADT2->rtcs4 = FADT71->rtcs4;
259 FADT2->tmr_val_ext = FADT71->tmr_val_ext;
260 FADT2->dock_cap = FADT71->dock_cap;
261
262
263 /* We should not use these next two addresses */
264 /* Since our buffer is pre-zeroed nothing to do for */
265 /* the next three data items in the structure */
266 /* FADT2->Firmware_ctrl = 0; */
267 /* FADT2->Dsdt = 0; */
268
269 /* System Interrupt Model isn't used in ACPI 2.0*/
270 /* FADT2->Reserved1 = 0; */
271
272 /* This field is set by the OEM to convey the preferred */
273 /* power management profile to OSPM. It doesn't have any*/
274 /* 0.71 equivalence. Since we don't know what kind of */
275 /* 64-bit system this is, we will pick unspecified. */
276
277 FADT2->prefer_PM_profile = PM_UNSPECIFIED;
278
279
280 /* Port address of SMI command port */
281 /* We shouldn't use this port because IA64 doesn't */
282 /* have or use SMI. It has PMI. */
283
284 FADT2->smi_cmd = (u32)(FADT71->smi_cmd & 0xFFFFFFFF);
285
286
287 /* processor performance state control*/
288 /* The value OSPM writes to the SMI_CMD register to assume */
289 /* processor performance state control responsibility. */
290 /* There isn't any equivalence in 0.71 */
291 /* Again this should be meaningless for IA64 */
292 /* FADT2->Pstate_cnt = 0; */
293
294 /* The 32-bit Power management and GPE registers are */
295 /* not valid in IA-64 and we are not going to use them */
296 /* so leaving them pre-zeroed. */
297
298 /* Support for the _CST object and C States change notification.*/
299 /* This data item hasn't any 0.71 equivalence so leaving it zero.*/
300 /* FADT2->Cst_cnt = 0; */
301
302 /* number of flush strides that need to be read */
303 /* No 0.71 equivalence. Leave pre-zeroed. */
304 /* FADT2->Flush_size = 0; */
305
306 /* Processor's memory cache line width, in bytes */
307 /* No 0.71 equivalence. Leave pre-zeroed. */
308 /* FADT2->Flush_stride = 0; */
309
310 /* Processor's duty cycle index in processor's P_CNT reg*/
311 /* No 0.71 equivalence. Leave pre-zeroed. */
312 /* FADT2->Duty_offset = 0; */
313
314 /* Processor's duty cycle value bit width in P_CNT register.*/
315 /* No 0.71 equivalence. Leave pre-zeroed. */
316 /* FADT2->Duty_width = 0; */
317
318
319 /* Since there isn't any equivalence in 0.71 */
320 /* and since Big_sur had to support legacy */
321
322 FADT2->iapc_boot_arch = BAF_LEGACY_DEVICES;
323
324 /* Copy to ACPI 2.0 64-BIT Extended Addresses */
325
326 FADT2->Xfirmware_ctrl = FADT71->firmware_ctrl;
327 FADT2->Xdsdt = FADT71->dsdt;
328
329
330 /* Extract the address space IDs */
331
332 pm1_address_space = (u8)((FADT71->address_space & PM1_BLK_ADDRESS_SPACE) >> 1);
333 pm2_address_space = (u8)((FADT71->address_space & PM2_CNT_BLK_ADDRESS_SPACE) >> 2);
334 pm_timer_address_space = (u8)((FADT71->address_space & PM_TMR_BLK_ADDRESS_SPACE) >> 3);
335 gpe0address_space = (u8)((FADT71->address_space & GPE0_BLK_ADDRESS_SPACE) >> 4);
336 gpe1_address_space = (u8)((FADT71->address_space & GPE1_BLK_ADDRESS_SPACE) >> 5);
337
338 /*
339 * Convert the 0.71 (non-GAS style) Block addresses to V2.0 GAS structures,
340 * in this order:
341 *
342 * PM 1_a Events
343 * PM 1_b Events
344 * PM 1_a Control
345 * PM 1_b Control
346 * PM 2 Control
347 * PM Timer Control
348 * GPE Block 0
349 * GPE Block 1
350 */
351
352 ASL_BUILD_GAS_FROM_ENTRY (FADT2->Xpm1a_evt_blk, FADT71->pm1_evt_len, FADT71->pm1a_evt_blk, pm1_address_space);
353 ASL_BUILD_GAS_FROM_ENTRY (FADT2->Xpm1b_evt_blk, FADT71->pm1_evt_len, FADT71->pm1b_evt_blk, pm1_address_space);
354 ASL_BUILD_GAS_FROM_ENTRY (FADT2->Xpm1a_cnt_blk, FADT71->pm1_cnt_len, FADT71->pm1a_cnt_blk, pm1_address_space);
355 ASL_BUILD_GAS_FROM_ENTRY (FADT2->Xpm1b_cnt_blk, FADT71->pm1_cnt_len, FADT71->pm1b_cnt_blk, pm1_address_space);
356 ASL_BUILD_GAS_FROM_ENTRY (FADT2->Xpm2_cnt_blk, FADT71->pm2_cnt_len, FADT71->pm2_cnt_blk, pm2_address_space);
357 ASL_BUILD_GAS_FROM_ENTRY (FADT2->Xpm_tmr_blk, FADT71->pm_tm_len, FADT71->pm_tmr_blk, pm_timer_address_space);
358 ASL_BUILD_GAS_FROM_ENTRY (FADT2->Xgpe0blk, FADT71->gpe0blk_len, FADT71->gpe0blk, gpe0address_space);
359 ASL_BUILD_GAS_FROM_ENTRY (FADT2->Xgpe1_blk, FADT71->gpe1_blk_len, FADT71->gpe1_blk, gpe1_address_space);
360
361 #else
362
363 /* ACPI 1.0 FACS */
364
365
366 /* The BIOS stored FADT should agree with Revision 1.0 */
367
368 FADT1 = (FADT_DESCRIPTOR_REV1*) acpi_gbl_FADT;
369
370 /*
371 * Copy the table header and the common part of the tables
372 * The 2.0 table is an extension of the 1.0 table, so the
373 * entire 1.0 table can be copied first, then expand some
374 * fields to 64 bits.
375 */
376
377 MEMCPY (FADT2, FADT1, sizeof (FADT_DESCRIPTOR_REV1));
378
379
380 /* Convert table pointers to 64-bit fields */
381
382 ACPI_STORE_ADDRESS (FADT2->Xfirmware_ctrl, FADT1->firmware_ctrl);
383 ACPI_STORE_ADDRESS (FADT2->Xdsdt, FADT1->dsdt);
384
385 /* System Interrupt Model isn't used in ACPI 2.0*/
386 /* FADT2->Reserved1 = 0; */
387
388 /* This field is set by the OEM to convey the preferred */
389 /* power management profile to OSPM. It doesn't have any*/
390 /* 1.0 equivalence. Since we don't know what kind of */
391 /* 32-bit system this is, we will pick unspecified. */
392
393 FADT2->prefer_PM_profile = PM_UNSPECIFIED;
394
395
396 /* Processor Performance State Control. This is the value */
397 /* OSPM writes to the SMI_CMD register to assume processor */
398 /* performance state control responsibility. There isn't */
399 /* any equivalence in 1.0. So leave it zeroed. */
400
401 FADT2->pstate_cnt = 0;
402
403
404 /* Support for the _CST object and C States change notification.*/
405 /* This data item hasn't any 1.0 equivalence so leaving it zero.*/
406
407 FADT2->cst_cnt = 0;
408
409
410 /* Since there isn't any equivalence in 1.0 and since it */
411 /* is highly likely that a 1.0 system has legacy support. */
412
413 FADT2->iapc_boot_arch = BAF_LEGACY_DEVICES;
414
415
416 /*
417 * Convert the V1.0 Block addresses to V2.0 GAS structures
418 * in this order:
419 *
420 * PM 1_a Events
421 * PM 1_b Events
422 * PM 1_a Control
423 * PM 1_b Control
424 * PM 2 Control
425 * PM Timer Control
426 * GPE Block 0
427 * GPE Block 1
428 */
429
430 ASL_BUILD_GAS_FROM_V1_ENTRY (FADT2->Xpm1a_evt_blk, FADT1->pm1_evt_len, FADT1->pm1a_evt_blk);
431 ASL_BUILD_GAS_FROM_V1_ENTRY (FADT2->Xpm1b_evt_blk, FADT1->pm1_evt_len, FADT1->pm1b_evt_blk);
432 ASL_BUILD_GAS_FROM_V1_ENTRY (FADT2->Xpm1a_cnt_blk, FADT1->pm1_cnt_len, FADT1->pm1a_cnt_blk);
433 ASL_BUILD_GAS_FROM_V1_ENTRY (FADT2->Xpm1b_cnt_blk, FADT1->pm1_cnt_len, FADT1->pm1b_cnt_blk);
434 ASL_BUILD_GAS_FROM_V1_ENTRY (FADT2->Xpm2_cnt_blk, FADT1->pm2_cnt_len, FADT1->pm2_cnt_blk);
435 ASL_BUILD_GAS_FROM_V1_ENTRY (FADT2->Xpm_tmr_blk, FADT1->pm_tm_len, FADT1->pm_tmr_blk);
436 ASL_BUILD_GAS_FROM_V1_ENTRY (FADT2->Xgpe0blk, FADT1->gpe0blk_len, FADT1->gpe0blk);
437 ASL_BUILD_GAS_FROM_V1_ENTRY (FADT2->Xgpe1_blk, FADT1->gpe1_blk_len, FADT1->gpe1_blk);
438 #endif
439 }
440
441
442 /*
443 * Global FADT pointer will point to the common V2.0 FADT
444 */
445 acpi_gbl_FADT = FADT2;
446 acpi_gbl_FADT->header.length = sizeof (FADT_DESCRIPTOR);
447
448
449 /* Free the original table */
450
451 table_desc = &acpi_gbl_acpi_tables[ACPI_TABLE_FADT];
452 acpi_tb_delete_single_table (table_desc);
453
454
455 /* Install the new table */
456
457 table_desc->pointer = (ACPI_TABLE_HEADER *) acpi_gbl_FADT;
458 table_desc->base_pointer = acpi_gbl_FADT;
459 table_desc->allocation = ACPI_MEM_ALLOCATED;
460 table_desc->length = sizeof (FADT_DESCRIPTOR_REV2);
461
462
463 /* Dump the entire FADT */
464
465
466 return (AE_OK);
467 }
468
469
470 /*******************************************************************************
471 *
472 * FUNCTION: Acpi_tb_convert_table_facs
473 *
474 * PARAMETERS:
475 *
476 * RETURN:
477 *
478 * DESCRIPTION:
479 *
480 ******************************************************************************/
481
482 ACPI_STATUS
483 acpi_tb_build_common_facs (
484 ACPI_TABLE_DESC *table_info)
485 {
486 ACPI_COMMON_FACS *common_facs;
487
488 #ifdef _IA64
489 FACS_DESCRIPTOR_REV071 *FACS71;
490 #else
491 FACS_DESCRIPTOR_REV1 *FACS1;
492 #endif
493
494 FACS_DESCRIPTOR_REV2 *FACS2;
495
496
497 /* Allocate a common FACS */
498
499 common_facs = acpi_cm_callocate (sizeof (ACPI_COMMON_FACS));
500 if (!common_facs) {
501 return (AE_NO_MEMORY);
502 }
503
504
505 /* Copy fields to the new FACS */
506
507 if (acpi_gbl_RSDP->revision < 2) {
508 #ifdef _IA64
509 /* 0.71 FACS */
510
511 FACS71 = (FACS_DESCRIPTOR_REV071 *) acpi_gbl_FACS;
512
513 common_facs->global_lock = (u32 *) &(FACS71->global_lock);
514 common_facs->firmware_waking_vector = &FACS71->firmware_waking_vector;
515 common_facs->vector_width = 64;
516 #else
517 /* ACPI 1.0 FACS */
518
519 FACS1 = (FACS_DESCRIPTOR_REV1 *) acpi_gbl_FACS;
520
521 common_facs->global_lock = &(FACS1->global_lock);
522 common_facs->firmware_waking_vector = (UINT64 *) &FACS1->firmware_waking_vector;
523 common_facs->vector_width = 32;
524
525 #endif
526 }
527
528 else {
529 /* ACPI 2.0 FACS */
530
531 FACS2 = (FACS_DESCRIPTOR_REV2 *) acpi_gbl_FACS;
532
533 common_facs->global_lock = &(FACS2->global_lock);
534 common_facs->firmware_waking_vector = &FACS2->Xfirmware_waking_vector;
535 common_facs->vector_width = 64;
536 }
537
538
539 /* Set the global FACS pointer to point to the common FACS */
540
541
542 acpi_gbl_FACS = common_facs;
543
544 return (AE_OK);
545 }
546
547