ReactOS 0.4.16-dev-240-gdb5fa3b
hwxface.c
Go to the documentation of this file.
1/******************************************************************************
2 *
3 * Module Name: hwxface - Public ACPICA hardware interfaces
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2022, 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 MERCHANTABILITY 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#define EXPORT_ACPI_INTERFACES
45
46#include "acpi.h"
47#include "accommon.h"
48#include "acnamesp.h"
49
50#define _COMPONENT ACPI_HARDWARE
51 ACPI_MODULE_NAME ("hwxface")
52
53
54/******************************************************************************
55 *
56 * FUNCTION: AcpiReset
57 *
58 * PARAMETERS: None
59 *
60 * RETURN: Status
61 *
62 * DESCRIPTION: Set reset register in memory or IO space. Note: Does not
63 * support reset register in PCI config space, this must be
64 * handled separately.
65 *
66 ******************************************************************************/
67
70 void)
71{
72 ACPI_GENERIC_ADDRESS *ResetReg;
74
75
77
78
79 ResetReg = &AcpiGbl_FADT.ResetRegister;
80
81 /* Check if the reset register is supported */
82
83 if (!(AcpiGbl_FADT.Flags & ACPI_FADT_RESET_REGISTER) ||
84 !ResetReg->Address)
85 {
87 }
88
89 if (ResetReg->SpaceId == ACPI_ADR_SPACE_SYSTEM_IO)
90 {
91 /*
92 * For I/O space, write directly to the OSL. This bypasses the port
93 * validation mechanism, which may block a valid write to the reset
94 * register.
95 *
96 * NOTE:
97 * The ACPI spec requires the reset register width to be 8, so we
98 * hardcode it here and ignore the FADT value. This maintains
99 * compatibility with other ACPI implementations that have allowed
100 * BIOS code with bad register width values to go unnoticed.
101 */
102 Status = AcpiOsWritePort ((ACPI_IO_ADDRESS) ResetReg->Address,
103 AcpiGbl_FADT.ResetValue, ACPI_RESET_REGISTER_WIDTH);
104 }
105 else
106 {
107 /* Write the reset value to the reset register */
108
109 Status = AcpiHwWrite (AcpiGbl_FADT.ResetValue, ResetReg);
110 }
111
113}
114
116
117
118/******************************************************************************
119 *
120 * FUNCTION: AcpiRead
121 *
122 * PARAMETERS: Value - Where the value is returned
123 * Reg - GAS register structure
124 *
125 * RETURN: Status
126 *
127 * DESCRIPTION: Read from either memory or IO space.
128 *
129 * LIMITATIONS: <These limitations also apply to AcpiWrite>
130 * BitWidth must be exactly 8, 16, 32, or 64.
131 * SpaceID must be SystemMemory or SystemIO.
132 * BitOffset and AccessWidth are currently ignored, as there has
133 * not been a need to implement these.
134 *
135 ******************************************************************************/
136
141{
143
144
146
147
149 return (Status);
150}
151
153
154
155/******************************************************************************
156 *
157 * FUNCTION: AcpiWrite
158 *
159 * PARAMETERS: Value - Value to be written
160 * Reg - GAS register structure
161 *
162 * RETURN: Status
163 *
164 * DESCRIPTION: Write to either memory or IO space.
165 *
166 ******************************************************************************/
167
172{
174
175
177
178
179 Status = AcpiHwWrite (Value, Reg);
180 return (Status);
181}
182
184
185
186#if (!ACPI_REDUCED_HARDWARE)
187/*******************************************************************************
188 *
189 * FUNCTION: AcpiReadBitRegister
190 *
191 * PARAMETERS: RegisterId - ID of ACPI Bit Register to access
192 * ReturnValue - Value that was read from the register,
193 * normalized to bit position zero.
194 *
195 * RETURN: Status and the value read from the specified Register. Value
196 * returned is normalized to bit0 (is shifted all the way right)
197 *
198 * DESCRIPTION: ACPI BitRegister read function. Does not acquire the HW lock.
199 *
200 * SUPPORTS: Bit fields in PM1 Status, PM1 Enable, PM1 Control, and
201 * PM2 Control.
202 *
203 * Note: The hardware lock is not required when reading the ACPI bit registers
204 * since almost all of them are single bit and it does not matter that
205 * the parent hardware register can be split across two physical
206 * registers. The only multi-bit field is SLP_TYP in the PM1 control
207 * register, but this field does not cross an 8-bit boundary (nor does
208 * it make much sense to actually read this field.)
209 *
210 ******************************************************************************/
211
214 UINT32 RegisterId,
216{
217 ACPI_BIT_REGISTER_INFO *BitRegInfo;
218 UINT32 RegisterValue;
221
222
224
225
226 /* Get the info structure corresponding to the requested ACPI Register */
227
228 BitRegInfo = AcpiHwGetBitRegisterInfo (RegisterId);
229 if (!BitRegInfo)
230 {
232 }
233
234 /* Read the entire parent register */
235
237 &RegisterValue);
238 if (ACPI_FAILURE (Status))
239 {
241 }
242
243 /* Normalize the value that was read, mask off other bits */
244
245 Value = ((RegisterValue & BitRegInfo->AccessBitMask)
246 >> BitRegInfo->BitPosition);
247
249 "BitReg %X, ParentReg %X, Actual %8.8X, ReturnValue %8.8X\n",
250 RegisterId, BitRegInfo->ParentRegister, RegisterValue, Value));
251
254}
255
257
258
259/*******************************************************************************
260 *
261 * FUNCTION: AcpiWriteBitRegister
262 *
263 * PARAMETERS: RegisterId - ID of ACPI Bit Register to access
264 * Value - Value to write to the register, in bit
265 * position zero. The bit is automatically
266 * shifted to the correct position.
267 *
268 * RETURN: Status
269 *
270 * DESCRIPTION: ACPI Bit Register write function. Acquires the hardware lock
271 * since most operations require a read/modify/write sequence.
272 *
273 * SUPPORTS: Bit fields in PM1 Status, PM1 Enable, PM1 Control, and
274 * PM2 Control.
275 *
276 * Note that at this level, the fact that there may be actually two
277 * hardware registers (A and B - and B may not exist) is abstracted.
278 *
279 ******************************************************************************/
280
283 UINT32 RegisterId,
285{
286 ACPI_BIT_REGISTER_INFO *BitRegInfo;
287 ACPI_CPU_FLAGS LockFlags;
288 UINT32 RegisterValue;
290
291
293
294
295 /* Get the info structure corresponding to the requested ACPI Register */
296
297 BitRegInfo = AcpiHwGetBitRegisterInfo (RegisterId);
298 if (!BitRegInfo)
299 {
301 }
302
303 LockFlags = AcpiOsAcquireLock (AcpiGbl_HardwareLock);
304
305 /*
306 * At this point, we know that the parent register is one of the
307 * following: PM1 Status, PM1 Enable, PM1 Control, or PM2 Control
308 */
309 if (BitRegInfo->ParentRegister != ACPI_REGISTER_PM1_STATUS)
310 {
311 /*
312 * 1) Case for PM1 Enable, PM1 Control, and PM2 Control
313 *
314 * Perform a register read to preserve the bits that we are not
315 * interested in
316 */
318 &RegisterValue);
319 if (ACPI_FAILURE (Status))
320 {
321 goto UnlockAndExit;
322 }
323
324 /*
325 * Insert the input bit into the value that was just read
326 * and write the register
327 */
328 ACPI_REGISTER_INSERT_VALUE (RegisterValue, BitRegInfo->BitPosition,
329 BitRegInfo->AccessBitMask, Value);
330
332 RegisterValue);
333 }
334 else
335 {
336 /*
337 * 2) Case for PM1 Status
338 *
339 * The Status register is different from the rest. Clear an event
340 * by writing 1, writing 0 has no effect. So, the only relevant
341 * information is the single bit we're interested in, all others
342 * should be written as 0 so they will be left unchanged.
343 */
344 RegisterValue = ACPI_REGISTER_PREPARE_BITS (Value,
345 BitRegInfo->BitPosition, BitRegInfo->AccessBitMask);
346
347 /* No need to write the register if value is all zeros */
348
349 if (RegisterValue)
350 {
352 RegisterValue);
353 }
354 }
355
357 "BitReg %X, ParentReg %X, Value %8.8X, Actual %8.8X\n",
358 RegisterId, BitRegInfo->ParentRegister, Value, RegisterValue));
359
360
361UnlockAndExit:
362
363 AcpiOsReleaseLock (AcpiGbl_HardwareLock, LockFlags);
365}
366
368
369#endif /* !ACPI_REDUCED_HARDWARE */
370
371
372/*******************************************************************************
373 *
374 * FUNCTION: AcpiGetSleepTypeData
375 *
376 * PARAMETERS: SleepState - Numeric sleep state
377 * *SleepTypeA - Where SLP_TYPa is returned
378 * *SleepTypeB - Where SLP_TYPb is returned
379 *
380 * RETURN: Status
381 *
382 * DESCRIPTION: Obtain the SLP_TYPa and SLP_TYPb values for the requested
383 * sleep state via the appropriate \_Sx object.
384 *
385 * The sleep state package returned from the corresponding \_Sx_ object
386 * must contain at least one integer.
387 *
388 * March 2005:
389 * Added support for a package that contains two integers. This
390 * goes against the ACPI specification which defines this object as a
391 * package with one encoded DWORD integer. However, existing practice
392 * by many BIOS vendors is to return a package with 2 or more integer
393 * elements, at least one per sleep type (A/B).
394 *
395 * January 2013:
396 * Therefore, we must be prepared to accept a package with either a
397 * single integer or multiple integers.
398 *
399 * The single integer DWORD format is as follows:
400 * BYTE 0 - Value for the PM1A SLP_TYP register
401 * BYTE 1 - Value for the PM1B SLP_TYP register
402 * BYTE 2-3 - Reserved
403 *
404 * The dual integer format is as follows:
405 * Integer 0 - Value for the PM1A SLP_TYP register
406 * Integer 1 - Value for the PM1A SLP_TYP register
407 *
408 ******************************************************************************/
409
412 UINT8 SleepState,
413 UINT8 *SleepTypeA,
414 UINT8 *SleepTypeB)
415{
418 ACPI_OPERAND_OBJECT **Elements;
419
420
422
423
424 /* Validate parameters */
425
426 if ((SleepState > ACPI_S_STATES_MAX) ||
427 !SleepTypeA || !SleepTypeB)
428 {
430 }
431
432 /* Allocate the evaluation information block */
433
435 if (!Info)
436 {
438 }
439
440 /*
441 * Evaluate the \_Sx namespace object containing the register values
442 * for this state
443 */
444 Info->RelativePathname = AcpiGbl_SleepStateNames[SleepState];
445
447 if (ACPI_FAILURE (Status))
448 {
449 if (Status == AE_NOT_FOUND)
450 {
451 /* The _Sx states are optional, ignore NOT_FOUND */
452
453 goto FinalCleanup;
454 }
455
456 goto WarningCleanup;
457 }
458
459 /* Must have a return object */
460
461 if (!Info->ReturnObject)
462 {
463 ACPI_ERROR ((AE_INFO, "No Sleep State object returned from [%s]",
464 Info->RelativePathname));
466 goto WarningCleanup;
467 }
468
469 /* Return object must be of type Package */
470
471 if (Info->ReturnObject->Common.Type != ACPI_TYPE_PACKAGE)
472 {
473 ACPI_ERROR ((AE_INFO, "Sleep State return object is not a Package"));
475 goto ReturnValueCleanup;
476 }
477
478 /*
479 * Any warnings about the package length or the object types have
480 * already been issued by the predefined name module -- there is no
481 * need to repeat them here.
482 */
483 Elements = Info->ReturnObject->Package.Elements;
484 switch (Info->ReturnObject->Package.Count)
485 {
486 case 0:
487
489 break;
490
491 case 1:
492
493 if (Elements[0]->Common.Type != ACPI_TYPE_INTEGER)
494 {
496 break;
497 }
498
499 /* A valid _Sx_ package with one integer */
500
501 *SleepTypeA = (UINT8) Elements[0]->Integer.Value;
502 *SleepTypeB = (UINT8) (Elements[0]->Integer.Value >> 8);
503 break;
504
505 case 2:
506 default:
507
508 if ((Elements[0]->Common.Type != ACPI_TYPE_INTEGER) ||
509 (Elements[1]->Common.Type != ACPI_TYPE_INTEGER))
510 {
512 break;
513 }
514
515 /* A valid _Sx_ package with two integers */
516
517 *SleepTypeA = (UINT8) Elements[0]->Integer.Value;
518 *SleepTypeB = (UINT8) Elements[1]->Integer.Value;
519 break;
520 }
521
522ReturnValueCleanup:
523 AcpiUtRemoveReference (Info->ReturnObject);
524
525WarningCleanup:
526 if (ACPI_FAILURE (Status))
527 {
529 "While evaluating Sleep State [%s]",
530 Info->RelativePathname));
531 }
532
533FinalCleanup:
534 ACPI_FREE (Info);
536}
537
unsigned long long UINT64
unsigned char UINT8
unsigned int UINT32
UINT32 void void ** ReturnValue
Definition: acevents.h:216
#define ACPI_FAILURE(a)
Definition: acexcep.h:95
#define AE_BAD_PARAMETER
Definition: acexcep.h:151
#define AE_NOT_FOUND
Definition: acexcep.h:113
#define AE_AML_PACKAGE_LIMIT
Definition: acexcep.h:190
#define AE_NO_MEMORY
Definition: acexcep.h:112
#define AE_NOT_EXIST
Definition: acexcep.h:114
#define AE_AML_NO_RETURN_VALUE
Definition: acexcep.h:197
#define AE_AML_OPERAND_TYPE
Definition: acexcep.h:182
#define AE_OK
Definition: acexcep.h:97
const char * AcpiGbl_SleepStateNames[ACPI_S_STATE_COUNT]
Definition: utglobal.c:62
#define ACPI_REGISTER_PM1_STATUS
Definition: aclocal.h:1184
#define ACPI_REGISTER_INSERT_VALUE(Reg, Pos, Mask, Val)
Definition: acmacros.h:360
#define ACPI_REGISTER_PREPARE_BITS(Val, Pos, Mask)
Definition: acmacros.h:357
ACPI_STATUS AcpiNsEvaluate(ACPI_EVALUATE_INFO *Info)
Definition: nseval.c:82
#define ACPI_DEBUG_PRINT(pl)
Definition: acoutput.h:475
#define ACPI_EXCEPTION(plist)
Definition: acoutput.h:239
#define ACPI_MODULE_NAME(Name)
Definition: acoutput.h:216
#define ACPI_FUNCTION_TRACE_U32(a, b)
Definition: acoutput.h:482
#define return_ACPI_STATUS(s)
Definition: acoutput.h:496
#define ACPI_FUNCTION_TRACE(a)
Definition: acoutput.h:480
#define ACPI_ERROR(plist)
Definition: acoutput.h:240
#define AE_INFO
Definition: acoutput.h:230
#define ACPI_FUNCTION_NAME(a)
Definition: acoutput.h:479
#define ACPI_DB_IO
Definition: acoutput.h:177
ACPI_STATUS AcpiOsWritePort(ACPI_IO_ADDRESS Address, UINT32 Value, UINT32 Width)
Definition: osl.c:731
void AcpiOsReleaseLock(ACPI_SPINLOCK Handle, ACPI_CPU_FLAGS Flags)
Definition: osl.c:516
ACPI_CPU_FLAGS AcpiOsAcquireLock(ACPI_SPINLOCK Handle)
Definition: osl.c:498
#define ACPI_FADT_RESET_REGISTER
Definition: actbl.h:346
#define ACPI_S_STATES_MAX
Definition: actypes.h:630
#define ACPI_RESET_REGISTER_WIDTH
Definition: actypes.h:411
#define ACPI_ADR_SPACE_SYSTEM_IO
Definition: actypes.h:862
#define ACPI_CPU_FLAGS
Definition: actypes.h:252
#define ACPI_FREE(a)
Definition: actypes.h:386
#define ACPI_TYPE_INTEGER
Definition: actypes.h:688
UINT32 ACPI_STATUS
Definition: actypes.h:460
#define ACPI_EXPORT_SYMBOL(Symbol)
Definition: actypes.h:343
#define ACPI_ALLOCATE_ZEROED(a)
Definition: actypes.h:385
#define ACPI_TYPE_PACKAGE
Definition: actypes.h:691
void AcpiUtRemoveReference(ACPI_OPERAND_OBJECT *Object)
Definition: utdelete.c:790
Status
Definition: gdiplustypes.h:25
ACPI_STATUS AcpiHwWrite(UINT64 Value, ACPI_GENERIC_ADDRESS *Reg)
Definition: hwregs.c:357
ACPI_STATUS AcpiHwRead(UINT64 *Value, ACPI_GENERIC_ADDRESS *Reg)
Definition: hwregs.c:259
ACPI_STATUS AcpiHwRegisterRead(UINT32 RegisterId, UINT32 *ReturnValue)
Definition: hwregs.c:574
ACPI_STATUS AcpiHwRegisterWrite(UINT32 RegisterId, UINT32 Value)
Definition: hwregs.c:684
ACPI_BIT_REGISTER_INFO * AcpiHwGetBitRegisterInfo(UINT32 RegisterId)
Definition: hwregs.c:502
ACPI_STATUS AcpiReset(void)
Definition: hwxface.c:69
ACPI_STATUS AcpiWriteBitRegister(UINT32 RegisterId, UINT32 Value)
Definition: hwxface.c:282
ACPI_STATUS AcpiGetSleepTypeData(UINT8 SleepState, UINT8 *SleepTypeA, UINT8 *SleepTypeB)
Definition: hwxface.c:411
ACPI_STATUS AcpiReadBitRegister(UINT32 RegisterId, UINT32 *ReturnValue)
Definition: hwxface.c:213
ACPI_STATUS AcpiRead(UINT64 *ReturnValue, ACPI_GENERIC_ADDRESS *Reg)
Definition: hwxface.c:138
ACPI_STATUS AcpiWrite(UINT64 Value, ACPI_GENERIC_ADDRESS *Reg)
Definition: hwxface.c:169
union acpi_operand_object ** Elements
Definition: acobject.h:161
ACPI_OBJECT_INTEGER Integer
Definition: acobject.h:520
ACPI_OBJECT_COMMON Common
Definition: acobject.h:519
ACPI_OBJECT_PACKAGE Package
Definition: acobject.h:523
_Must_inspect_result_ _In_ WDFCHILDLIST _In_ PWDF_CHILD_LIST_ITERATOR _Out_ WDFDEVICE _Inout_opt_ PWDF_CHILD_RETRIEVE_INFO Info
Definition: wdfchildlist.h:690
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413