Print this page
update to acpica-unix2-20140114
acpica-unix2-20130823
PANKOVs restructure
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/intel/io/acpica/executer/exutils.c
+++ new/usr/src/common/acpica/components/executer/exutils.c
1 -
2 1 /******************************************************************************
3 2 *
4 3 * Module Name: exutils - interpreter/scanner utilities
5 4 *
6 5 *****************************************************************************/
7 6
8 7 /*
9 - * Copyright (C) 2000 - 2011, Intel Corp.
8 + * Copyright (C) 2000 - 2014, Intel Corp.
10 9 * All rights reserved.
11 10 *
12 11 * Redistribution and use in source and binary forms, with or without
13 12 * modification, are permitted provided that the following conditions
14 13 * are met:
15 14 * 1. Redistributions of source code must retain the above copyright
16 15 * notice, this list of conditions, and the following disclaimer,
17 16 * without modification.
18 17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 18 * substantially similar to the "NO WARRANTY" disclaimer below
20 19 * ("Disclaimer") and any redistribution must be conditioned upon
21 20 * including a substantially similar Disclaimer requirement for further
22 21 * binary redistribution.
23 22 * 3. Neither the names of the above-listed copyright holders nor the names
24 23 * of any contributors may be used to endorse or promote products derived
25 24 * from this software without specific prior written permission.
26 25 *
27 26 * Alternatively, this software may be distributed under the terms of the
28 27 * GNU General Public License ("GPL") version 2 as published by the Free
29 28 * Software Foundation.
30 29 *
31 30 * NO WARRANTY
32 31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
↓ open down ↓ |
20 lines elided |
↑ open up ↑ |
40 39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 41 * POSSIBILITY OF SUCH DAMAGES.
43 42 */
44 43
45 44 #define __EXUTILS_C__
46 45
47 46 /*
48 47 * DEFINE_AML_GLOBALS is tested in amlcode.h
49 48 * to determine whether certain global names should be "defined" or only
50 - * "declared" in the current compilation. This enhances maintainability
49 + * "declared" in the current compilation. This enhances maintainability
51 50 * by enabling a single header file to embody all knowledge of the names
52 51 * in question.
53 52 *
54 53 * Exactly one module of any executable should #define DEFINE_GLOBALS
55 - * before #including the header files which use this convention. The
54 + * before #including the header files which use this convention. The
56 55 * names in question will be defined and initialized in that module,
57 56 * and declared as extern in all other modules which #include those
58 57 * header files.
59 58 */
60 59
61 60 #define DEFINE_AML_GLOBALS
62 61
63 62 #include "acpi.h"
64 63 #include "accommon.h"
65 64 #include "acinterp.h"
66 65 #include "amlcode.h"
67 66
68 67 #define _COMPONENT ACPI_EXECUTER
69 68 ACPI_MODULE_NAME ("exutils")
70 69
71 70 /* Local prototypes */
72 71
73 72 static UINT32
74 73 AcpiExDigitsNeeded (
75 74 UINT64 Value,
76 75 UINT32 Base);
77 76
78 77
79 78 #ifndef ACPI_NO_METHOD_EXECUTION
80 79 /*******************************************************************************
81 80 *
82 81 * FUNCTION: AcpiExEnterInterpreter
83 82 *
84 83 * PARAMETERS: None
85 84 *
86 85 * RETURN: None
87 86 *
88 87 * DESCRIPTION: Enter the interpreter execution region. Failure to enter
89 88 * the interpreter region is a fatal system error. Used in
90 89 * conjunction with ExitInterpreter.
91 90 *
92 91 ******************************************************************************/
93 92
94 93 void
95 94 AcpiExEnterInterpreter (
96 95 void)
97 96 {
98 97 ACPI_STATUS Status;
99 98
100 99
101 100 ACPI_FUNCTION_TRACE (ExEnterInterpreter);
102 101
103 102
104 103 Status = AcpiUtAcquireMutex (ACPI_MTX_INTERPRETER);
105 104 if (ACPI_FAILURE (Status))
106 105 {
107 106 ACPI_ERROR ((AE_INFO, "Could not acquire AML Interpreter mutex"));
108 107 }
109 108
110 109 return_VOID;
111 110 }
112 111
113 112
↓ open down ↓ |
48 lines elided |
↑ open up ↑ |
114 113 /*******************************************************************************
115 114 *
116 115 * FUNCTION: AcpiExReacquireInterpreter
117 116 *
118 117 * PARAMETERS: None
119 118 *
120 119 * RETURN: None
121 120 *
122 121 * DESCRIPTION: Reacquire the interpreter execution region from within the
123 122 * interpreter code. Failure to enter the interpreter region is a
124 - * fatal system error. Used in conjuction with
123 + * fatal system error. Used in conjunction with
125 124 * RelinquishInterpreter
126 125 *
127 126 ******************************************************************************/
128 127
129 128 void
130 129 AcpiExReacquireInterpreter (
131 130 void)
132 131 {
133 132 ACPI_FUNCTION_TRACE (ExReacquireInterpreter);
134 133
135 134
136 135 /*
137 136 * If the global serialized flag is set, do not release the interpreter,
138 137 * since it was not actually released by AcpiExRelinquishInterpreter.
139 138 * This forces the interpreter to be single threaded.
140 139 */
141 140 if (!AcpiGbl_AllMethodsSerialized)
142 141 {
143 142 AcpiExEnterInterpreter ();
144 143 }
145 144
146 145 return_VOID;
147 146 }
148 147
149 148
150 149 /*******************************************************************************
151 150 *
152 151 * FUNCTION: AcpiExExitInterpreter
153 152 *
154 153 * PARAMETERS: None
155 154 *
156 155 * RETURN: None
157 156 *
158 157 * DESCRIPTION: Exit the interpreter execution region. This is the top level
159 158 * routine used to exit the interpreter when all processing has
160 159 * been completed.
161 160 *
162 161 ******************************************************************************/
163 162
164 163 void
165 164 AcpiExExitInterpreter (
166 165 void)
167 166 {
168 167 ACPI_STATUS Status;
169 168
170 169
171 170 ACPI_FUNCTION_TRACE (ExExitInterpreter);
172 171
173 172
174 173 Status = AcpiUtReleaseMutex (ACPI_MTX_INTERPRETER);
175 174 if (ACPI_FAILURE (Status))
176 175 {
177 176 ACPI_ERROR ((AE_INFO, "Could not release AML Interpreter mutex"));
178 177 }
179 178
180 179 return_VOID;
181 180 }
182 181
183 182
184 183 /*******************************************************************************
185 184 *
186 185 * FUNCTION: AcpiExRelinquishInterpreter
187 186 *
188 187 * PARAMETERS: None
189 188 *
190 189 * RETURN: None
191 190 *
192 191 * DESCRIPTION: Exit the interpreter execution region, from within the
193 192 * interpreter - before attempting an operation that will possibly
194 193 * block the running thread.
195 194 *
196 195 * Cases where the interpreter is unlocked internally
197 196 * 1) Method to be blocked on a Sleep() AML opcode
198 197 * 2) Method to be blocked on an Acquire() AML opcode
199 198 * 3) Method to be blocked on a Wait() AML opcode
200 199 * 4) Method to be blocked to acquire the global lock
201 200 * 5) Method to be blocked waiting to execute a serialized control method
202 201 * that is currently executing
203 202 * 6) About to invoke a user-installed opregion handler
204 203 *
205 204 ******************************************************************************/
206 205
207 206 void
208 207 AcpiExRelinquishInterpreter (
209 208 void)
210 209 {
211 210 ACPI_FUNCTION_TRACE (ExRelinquishInterpreter);
212 211
213 212
214 213 /*
215 214 * If the global serialized flag is set, do not release the interpreter.
216 215 * This forces the interpreter to be single threaded.
217 216 */
218 217 if (!AcpiGbl_AllMethodsSerialized)
219 218 {
220 219 AcpiExExitInterpreter ();
221 220 }
222 221
↓ open down ↓ |
88 lines elided |
↑ open up ↑ |
223 222 return_VOID;
224 223 }
225 224
226 225
227 226 /*******************************************************************************
228 227 *
229 228 * FUNCTION: AcpiExTruncateFor32bitTable
230 229 *
231 230 * PARAMETERS: ObjDesc - Object to be truncated
232 231 *
233 - * RETURN: none
232 + * RETURN: TRUE if a truncation was performed, FALSE otherwise.
234 233 *
235 234 * DESCRIPTION: Truncate an ACPI Integer to 32 bits if the execution mode is
236 235 * 32-bit, as determined by the revision of the DSDT.
237 236 *
238 237 ******************************************************************************/
239 238
240 -void
239 +BOOLEAN
241 240 AcpiExTruncateFor32bitTable (
242 241 ACPI_OPERAND_OBJECT *ObjDesc)
243 242 {
244 243
245 244 ACPI_FUNCTION_ENTRY ();
246 245
247 246
248 247 /*
249 248 * Object must be a valid number and we must be executing
250 - * a control method. NS node could be there for AML_INT_NAMEPATH_OP.
249 + * a control method. Object could be NS node for AML_INT_NAMEPATH_OP.
251 250 */
252 251 if ((!ObjDesc) ||
253 252 (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc) != ACPI_DESC_TYPE_OPERAND) ||
254 253 (ObjDesc->Common.Type != ACPI_TYPE_INTEGER))
255 254 {
256 - return;
255 + return (FALSE);
257 256 }
258 257
259 - if (AcpiGbl_IntegerByteWidth == 4)
258 + if ((AcpiGbl_IntegerByteWidth == 4) &&
259 + (ObjDesc->Integer.Value > (UINT64) ACPI_UINT32_MAX))
260 260 {
261 261 /*
262 - * We are running a method that exists in a 32-bit ACPI table.
262 + * We are executing in a 32-bit ACPI table.
263 263 * Truncate the value to 32 bits by zeroing out the upper 32-bit field
264 264 */
265 265 ObjDesc->Integer.Value &= (UINT64) ACPI_UINT32_MAX;
266 + return (TRUE);
266 267 }
268 +
269 + return (FALSE);
267 270 }
268 271
269 272
270 273 /*******************************************************************************
271 274 *
272 275 * FUNCTION: AcpiExAcquireGlobalLock
273 276 *
274 277 * PARAMETERS: FieldFlags - Flags with Lock rule:
275 278 * AlwaysLock or NeverLock
276 279 *
277 280 * RETURN: None
278 281 *
279 282 * DESCRIPTION: Obtain the ACPI hardware Global Lock, only if the field
280 283 * flags specifiy that it is to be obtained before field access.
281 284 *
282 285 ******************************************************************************/
283 286
284 287 void
285 288 AcpiExAcquireGlobalLock (
286 289 UINT32 FieldFlags)
287 290 {
288 291 ACPI_STATUS Status;
289 292
290 293
291 294 ACPI_FUNCTION_TRACE (ExAcquireGlobalLock);
292 295
293 296
294 297 /* Only use the lock if the AlwaysLock bit is set */
295 298
296 299 if (!(FieldFlags & AML_FIELD_LOCK_RULE_MASK))
297 300 {
298 301 return_VOID;
299 302 }
300 303
301 304 /* Attempt to get the global lock, wait forever */
302 305
303 306 Status = AcpiExAcquireMutexObject (ACPI_WAIT_FOREVER,
304 307 AcpiGbl_GlobalLockMutex, AcpiOsGetThreadId ());
305 308
306 309 if (ACPI_FAILURE (Status))
307 310 {
308 311 ACPI_EXCEPTION ((AE_INFO, Status,
309 312 "Could not acquire Global Lock"));
310 313 }
311 314
312 315 return_VOID;
313 316 }
314 317
315 318
316 319 /*******************************************************************************
317 320 *
318 321 * FUNCTION: AcpiExReleaseGlobalLock
319 322 *
320 323 * PARAMETERS: FieldFlags - Flags with Lock rule:
321 324 * AlwaysLock or NeverLock
322 325 *
323 326 * RETURN: None
324 327 *
325 328 * DESCRIPTION: Release the ACPI hardware Global Lock
326 329 *
327 330 ******************************************************************************/
328 331
329 332 void
330 333 AcpiExReleaseGlobalLock (
331 334 UINT32 FieldFlags)
332 335 {
333 336 ACPI_STATUS Status;
334 337
335 338
336 339 ACPI_FUNCTION_TRACE (ExReleaseGlobalLock);
337 340
338 341
339 342 /* Only use the lock if the AlwaysLock bit is set */
340 343
341 344 if (!(FieldFlags & AML_FIELD_LOCK_RULE_MASK))
342 345 {
343 346 return_VOID;
344 347 }
345 348
346 349 /* Release the global lock */
347 350
348 351 Status = AcpiExReleaseMutexObject (AcpiGbl_GlobalLockMutex);
349 352 if (ACPI_FAILURE (Status))
350 353 {
351 354 /* Report the error, but there isn't much else we can do */
352 355
353 356 ACPI_EXCEPTION ((AE_INFO, Status,
354 357 "Could not release Global Lock"));
355 358 }
356 359
357 360 return_VOID;
358 361 }
359 362
360 363
361 364 /*******************************************************************************
362 365 *
363 366 * FUNCTION: AcpiExDigitsNeeded
364 367 *
365 368 * PARAMETERS: Value - Value to be represented
366 369 * Base - Base of representation
367 370 *
368 371 * RETURN: The number of digits.
369 372 *
370 373 * DESCRIPTION: Calculate the number of digits needed to represent the Value
371 374 * in the given Base (Radix)
372 375 *
373 376 ******************************************************************************/
374 377
375 378 static UINT32
376 379 AcpiExDigitsNeeded (
377 380 UINT64 Value,
378 381 UINT32 Base)
379 382 {
380 383 UINT32 NumDigits;
381 384 UINT64 CurrentValue;
382 385
383 386
384 387 ACPI_FUNCTION_TRACE (ExDigitsNeeded);
385 388
386 389
387 390 /* UINT64 is unsigned, so we don't worry about a '-' prefix */
388 391
389 392 if (Value == 0)
390 393 {
391 394 return_UINT32 (1);
392 395 }
393 396
394 397 CurrentValue = Value;
395 398 NumDigits = 0;
396 399
397 400 /* Count the digits in the requested base */
398 401
399 402 while (CurrentValue)
400 403 {
401 404 (void) AcpiUtShortDivide (CurrentValue, Base, &CurrentValue, NULL);
402 405 NumDigits++;
403 406 }
404 407
405 408 return_UINT32 (NumDigits);
406 409 }
407 410
408 411
409 412 /*******************************************************************************
410 413 *
411 414 * FUNCTION: AcpiExEisaIdToString
412 415 *
413 416 * PARAMETERS: CompressedId - EISAID to be converted
414 417 * OutString - Where to put the converted string (8 bytes)
415 418 *
416 419 * RETURN: None
417 420 *
418 421 * DESCRIPTION: Convert a numeric EISAID to string representation. Return
419 422 * buffer must be large enough to hold the string. The string
420 423 * returned is always exactly of length ACPI_EISAID_STRING_SIZE
421 424 * (includes null terminator). The EISAID is always 32 bits.
422 425 *
423 426 ******************************************************************************/
424 427
425 428 void
426 429 AcpiExEisaIdToString (
427 430 char *OutString,
428 431 UINT64 CompressedId)
429 432 {
430 433 UINT32 SwappedId;
431 434
432 435
433 436 ACPI_FUNCTION_ENTRY ();
434 437
435 438
436 439 /* The EISAID should be a 32-bit integer */
437 440
438 441 if (CompressedId > ACPI_UINT32_MAX)
439 442 {
440 443 ACPI_WARNING ((AE_INFO,
441 444 "Expected EISAID is larger than 32 bits: 0x%8.8X%8.8X, truncating",
442 445 ACPI_FORMAT_UINT64 (CompressedId)));
443 446 }
444 447
445 448 /* Swap ID to big-endian to get contiguous bits */
446 449
447 450 SwappedId = AcpiUtDwordByteSwap ((UINT32) CompressedId);
448 451
449 452 /* First 3 bytes are uppercase letters. Next 4 bytes are hexadecimal */
450 453
451 454 OutString[0] = (char) (0x40 + (((unsigned long) SwappedId >> 26) & 0x1F));
452 455 OutString[1] = (char) (0x40 + ((SwappedId >> 21) & 0x1F));
453 456 OutString[2] = (char) (0x40 + ((SwappedId >> 16) & 0x1F));
454 457 OutString[3] = AcpiUtHexToAsciiChar ((UINT64) SwappedId, 12);
455 458 OutString[4] = AcpiUtHexToAsciiChar ((UINT64) SwappedId, 8);
456 459 OutString[5] = AcpiUtHexToAsciiChar ((UINT64) SwappedId, 4);
457 460 OutString[6] = AcpiUtHexToAsciiChar ((UINT64) SwappedId, 0);
458 461 OutString[7] = 0;
459 462 }
460 463
461 464
462 465 /*******************************************************************************
463 466 *
464 467 * FUNCTION: AcpiExIntegerToString
465 468 *
466 469 * PARAMETERS: OutString - Where to put the converted string. At least
467 470 * 21 bytes are needed to hold the largest
468 471 * possible 64-bit integer.
469 472 * Value - Value to be converted
470 473 *
471 474 * RETURN: None, string
472 475 *
473 476 * DESCRIPTION: Convert a 64-bit integer to decimal string representation.
474 477 * Assumes string buffer is large enough to hold the string. The
475 478 * largest string is (ACPI_MAX64_DECIMAL_DIGITS + 1).
476 479 *
477 480 ******************************************************************************/
478 481
479 482 void
480 483 AcpiExIntegerToString (
481 484 char *OutString,
482 485 UINT64 Value)
483 486 {
484 487 UINT32 Count;
485 488 UINT32 DigitsNeeded;
486 489 UINT32 Remainder;
487 490
488 491
489 492 ACPI_FUNCTION_ENTRY ();
490 493
491 494
↓ open down ↓ |
215 lines elided |
↑ open up ↑ |
492 495 DigitsNeeded = AcpiExDigitsNeeded (Value, 10);
493 496 OutString[DigitsNeeded] = 0;
494 497
495 498 for (Count = DigitsNeeded; Count > 0; Count--)
496 499 {
497 500 (void) AcpiUtShortDivide (Value, 10, &Value, &Remainder);
498 501 OutString[Count-1] = (char) ('0' + Remainder);\
499 502 }
500 503 }
501 504
505 +
506 +/*******************************************************************************
507 + *
508 + * FUNCTION: AcpiIsValidSpaceId
509 + *
510 + * PARAMETERS: SpaceId - ID to be validated
511 + *
512 + * RETURN: TRUE if valid/supported ID.
513 + *
514 + * DESCRIPTION: Validate an operation region SpaceID.
515 + *
516 + ******************************************************************************/
517 +
518 +BOOLEAN
519 +AcpiIsValidSpaceId (
520 + UINT8 SpaceId)
521 +{
522 +
523 + if ((SpaceId >= ACPI_NUM_PREDEFINED_REGIONS) &&
524 + (SpaceId < ACPI_USER_REGION_BEGIN) &&
525 + (SpaceId != ACPI_ADR_SPACE_DATA_TABLE) &&
526 + (SpaceId != ACPI_ADR_SPACE_FIXED_HARDWARE))
527 + {
528 + return (FALSE);
529 + }
530 +
531 + return (TRUE);
532 +}
533 +
534 +
502 535 #endif
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX