ReactOS  0.4.15-dev-425-gc40b086
exfield.c
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * Module Name: exfield - AML execution - FieldUnit read/write
4  *
5  *****************************************************************************/
6 
7 /*
8  * Copyright (C) 2000 - 2020, 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 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.
42  */
43 
44 #include "acpi.h"
45 #include "accommon.h"
46 #include "acdispat.h"
47 #include "acinterp.h"
48 #include "amlcode.h"
49 
50 
51 #define _COMPONENT ACPI_EXECUTER
52  ACPI_MODULE_NAME ("exfield")
53 
54 
55 /*
56  * This table maps the various Attrib protocols to the byte transfer
57  * length. Used for the generic serial bus.
58  */
59 #define ACPI_INVALID_PROTOCOL_ID 0x80
60 #define ACPI_MAX_PROTOCOL_ID 0x0F
61 
62 static const UINT8 AcpiProtocolLengths[] =
63 {
64  ACPI_INVALID_PROTOCOL_ID, /* 0 - reserved */
65  ACPI_INVALID_PROTOCOL_ID, /* 1 - reserved */
66  0x00, /* 2 - ATTRIB_QUICK */
67  ACPI_INVALID_PROTOCOL_ID, /* 3 - reserved */
68  0x01, /* 4 - ATTRIB_SEND_RECEIVE */
69  ACPI_INVALID_PROTOCOL_ID, /* 5 - reserved */
70  0x01, /* 6 - ATTRIB_BYTE */
71  ACPI_INVALID_PROTOCOL_ID, /* 7 - reserved */
72  0x02, /* 8 - ATTRIB_WORD */
73  ACPI_INVALID_PROTOCOL_ID, /* 9 - reserved */
74  0xFF, /* A - ATTRIB_BLOCK */
75  0xFF, /* B - ATTRIB_BYTES */
76  0x02, /* C - ATTRIB_PROCESS_CALL */
77  0xFF, /* D - ATTRIB_BLOCK_PROCESS_CALL */
78  0xFF, /* E - ATTRIB_RAW_BYTES */
79  0xFF /* F - ATTRIB_RAW_PROCESS_BYTES */
80 };
81 
82 #define PCC_MASTER_SUBSPACE 3
83 
84 /*
85  * The following macros determine a given offset is a COMD field.
86  * According to the specification, generic subspaces (types 0-2) contains a
87  * 2-byte COMD field at offset 4 and master subspaces (type 3) contains a 4-byte
88  * COMD field starting at offset 12.
89  */
90 #define GENERIC_SUBSPACE_COMMAND(a) (4 == a || a == 5)
91 #define MASTER_SUBSPACE_COMMAND(a) (12 <= a && a <= 15)
92 
93 
94 /*******************************************************************************
95  *
96  * FUNCTION: AcpiExGetProtocolBufferLength
97  *
98  * PARAMETERS: ProtocolId - The type of the protocol indicated by region
99  * field access attributes
100  * ReturnLength - Where the protocol byte transfer length is
101  * returned
102  *
103  * RETURN: Status and decoded byte transfer length
104  *
105  * DESCRIPTION: This routine returns the length of the GenericSerialBus
106  * protocol bytes
107  *
108  ******************************************************************************/
109 
114 {
115 
118  {
120  "Invalid Field/AccessAs protocol ID: 0x%4.4X", ProtocolId));
121 
122  return (AE_AML_PROTOCOL);
123  }
124 
126  return (AE_OK);
127 }
128 
129 
130 /*******************************************************************************
131  *
132  * FUNCTION: AcpiExReadDataFromField
133  *
134  * PARAMETERS: WalkState - Current execution state
135  * ObjDesc - The named field
136  * RetBufferDesc - Where the return data object is stored
137  *
138  * RETURN: Status
139  *
140  * DESCRIPTION: Read from a named field. Returns either an Integer or a
141  * Buffer, depending on the size of the field and whether if a
142  * field is created by the CreateField() operator.
143  *
144  ******************************************************************************/
145 
148  ACPI_WALK_STATE *WalkState,
149  ACPI_OPERAND_OBJECT *ObjDesc,
150  ACPI_OPERAND_OBJECT **RetBufferDesc)
151 {
153  ACPI_OPERAND_OBJECT *BufferDesc;
154  void *Buffer;
156 
157 
158  ACPI_FUNCTION_TRACE_PTR (ExReadDataFromField, ObjDesc);
159 
160 
161  /* Parameter validation */
162 
163  if (!ObjDesc)
164  {
166  }
167  if (!RetBufferDesc)
168  {
170  }
171 
172  if (ObjDesc->Common.Type == ACPI_TYPE_BUFFER_FIELD)
173  {
174  /*
175  * If the BufferField arguments have not been previously evaluated,
176  * evaluate them now and save the results.
177  */
178  if (!(ObjDesc->Common.Flags & AOPOBJ_DATA_VALID))
179  {
181  if (ACPI_FAILURE (Status))
182  {
184  }
185  }
186  }
187  else if ((ObjDesc->Common.Type == ACPI_TYPE_LOCAL_REGION_FIELD) &&
191  {
192  /* SMBus, GSBus, IPMI serial */
193 
194  Status = AcpiExReadSerialBus (ObjDesc, RetBufferDesc);
196  }
197 
198  /*
199  * Allocate a buffer for the contents of the field.
200  *
201  * If the field is larger than the current integer width, create
202  * a BUFFER to hold it. Otherwise, use an INTEGER. This allows
203  * the use of arithmetic operators on the returned value if the
204  * field size is equal or smaller than an Integer.
205  *
206  * However, all buffer fields created by CreateField operator needs to
207  * remain as a buffer to match other AML interpreter implementations.
208  *
209  * Note: Field.length is in bits.
210  */
212  ObjDesc->Field.BitLength);
213 
214  if (BufferLength > AcpiGbl_IntegerByteWidth ||
215  (ObjDesc->Common.Type == ACPI_TYPE_BUFFER_FIELD &&
216  ObjDesc->BufferField.IsCreateField))
217  {
218  /* Field is too large for an Integer, create a Buffer instead */
219 
220  BufferDesc = AcpiUtCreateBufferObject (BufferLength);
221  if (!BufferDesc)
222  {
224  }
225  Buffer = BufferDesc->Buffer.Pointer;
226  }
227  else
228  {
229  /* Field will fit within an Integer (normal case) */
230 
231  BufferDesc = AcpiUtCreateIntegerObject ((UINT64) 0);
232  if (!BufferDesc)
233  {
235  }
236 
237  BufferLength = AcpiGbl_IntegerByteWidth;
238  Buffer = &BufferDesc->Integer.Value;
239  }
240 
241  if ((ObjDesc->Common.Type == ACPI_TYPE_LOCAL_REGION_FIELD) &&
243  {
244  /* General Purpose I/O */
245 
246  Status = AcpiExReadGpio (ObjDesc, Buffer);
247  goto Exit;
248  }
249  else if ((ObjDesc->Common.Type == ACPI_TYPE_LOCAL_REGION_FIELD) &&
251  {
252  /*
253  * Reading from a PCC field unit does not require the handler because
254  * it only requires reading from the InternalPccBuffer.
255  */
257  "PCC FieldRead bits %u\n", ObjDesc->Field.BitLength));
258 
260  ObjDesc->Field.BaseByteOffset, (ACPI_SIZE) ACPI_ROUND_BITS_UP_TO_BYTES (
261  ObjDesc->Field.BitLength));
262 
263  *RetBufferDesc = BufferDesc;
264  return AE_OK;
265  }
266 
268  "FieldRead [TO]: Obj %p, Type %X, Buf %p, ByteLen %X\n",
269  ObjDesc, ObjDesc->Common.Type, Buffer, BufferLength));
271  "FieldRead [FROM]: BitLen %X, BitOff %X, ByteOff %X\n",
272  ObjDesc->CommonField.BitLength,
273  ObjDesc->CommonField.StartFieldBitOffset,
274  ObjDesc->CommonField.BaseByteOffset));
275 
276  /* Lock entire transaction if requested */
277 
278  AcpiExAcquireGlobalLock (ObjDesc->CommonField.FieldFlags);
279 
280  /* Read from the field */
281 
283  AcpiExReleaseGlobalLock (ObjDesc->CommonField.FieldFlags);
284 
285 
286 Exit:
287  if (ACPI_FAILURE (Status))
288  {
289  AcpiUtRemoveReference (BufferDesc);
290  }
291  else
292  {
293  *RetBufferDesc = BufferDesc;
294  }
295 
297 }
298 
299 
300 /*******************************************************************************
301  *
302  * FUNCTION: AcpiExWriteDataToField
303  *
304  * PARAMETERS: SourceDesc - Contains data to write
305  * ObjDesc - The named field
306  * ResultDesc - Where the return value is returned, if any
307  *
308  * RETURN: Status
309  *
310  * DESCRIPTION: Write to a named field
311  *
312  ******************************************************************************/
313 
316  ACPI_OPERAND_OBJECT *SourceDesc,
317  ACPI_OPERAND_OBJECT *ObjDesc,
318  ACPI_OPERAND_OBJECT **ResultDesc)
319 {
323  void *Buffer;
324 
325 
326  ACPI_FUNCTION_TRACE_PTR (ExWriteDataToField, ObjDesc);
327 
328 
329  /* Parameter validation */
330 
331  if (!SourceDesc || !ObjDesc)
332  {
334  }
335 
336  if (ObjDesc->Common.Type == ACPI_TYPE_BUFFER_FIELD)
337  {
338  /*
339  * If the BufferField arguments have not been previously evaluated,
340  * evaluate them now and save the results.
341  */
342  if (!(ObjDesc->Common.Flags & AOPOBJ_DATA_VALID))
343  {
345  if (ACPI_FAILURE (Status))
346  {
348  }
349  }
350  }
351  else if ((ObjDesc->Common.Type == ACPI_TYPE_LOCAL_REGION_FIELD) &&
353  {
354  /* General Purpose I/O */
355 
356  Status = AcpiExWriteGpio (SourceDesc, ObjDesc, ResultDesc);
358  }
359  else if ((ObjDesc->Common.Type == ACPI_TYPE_LOCAL_REGION_FIELD) &&
363  {
364  /* SMBus, GSBus, IPMI serial */
365 
366  Status = AcpiExWriteSerialBus (SourceDesc, ObjDesc, ResultDesc);
368  }
369  else if ((ObjDesc->Common.Type == ACPI_TYPE_LOCAL_REGION_FIELD) &&
371  {
372  /*
373  * According to the spec a write to the COMD field will invoke the
374  * region handler. Otherwise, write to the PccInternal buffer. This
375  * implementation will use the offsets specified rather than the name
376  * of the field. This is considered safer because some firmware tools
377  * are known to obfiscate named objects.
378  */
380  ObjDesc->Field.BitLength);
382  ObjDesc->Field.BaseByteOffset,
383  SourceDesc->Buffer.Pointer, DataLength);
384 
385  if ((ObjDesc->Field.RegionObj->Region.Address == PCC_MASTER_SUBSPACE &&
386  MASTER_SUBSPACE_COMMAND (ObjDesc->Field.BaseByteOffset)) ||
387  GENERIC_SUBSPACE_COMMAND (ObjDesc->Field.BaseByteOffset))
388  {
389  /* Perform the write */
390 
392  "PCC COMD field has been written. Invoking PCC handler now.\n"));
393 
395  ObjDesc, 0, (UINT64 *) ObjDesc->Field.RegionObj->Field.InternalPccBuffer,
396  ACPI_WRITE);
398  }
399  return (AE_OK);
400  }
401 
402 
403  /* Get a pointer to the data to be written */
404 
405  switch (SourceDesc->Common.Type)
406  {
407  case ACPI_TYPE_INTEGER:
408 
409  Buffer = &SourceDesc->Integer.Value;
410  BufferLength = sizeof (SourceDesc->Integer.Value);
411  break;
412 
413  case ACPI_TYPE_BUFFER:
414 
415  Buffer = SourceDesc->Buffer.Pointer;
416  BufferLength = SourceDesc->Buffer.Length;
417  break;
418 
419  case ACPI_TYPE_STRING:
420 
421  Buffer = SourceDesc->String.Pointer;
422  BufferLength = SourceDesc->String.Length;
423  break;
424 
425  default:
427  }
428 
430  "FieldWrite [FROM]: Obj %p (%s:%X), Buf %p, ByteLen %X\n",
431  SourceDesc, AcpiUtGetTypeName (SourceDesc->Common.Type),
432  SourceDesc->Common.Type, Buffer, BufferLength));
433 
435  "FieldWrite [TO]: Obj %p (%s:%X), BitLen %X, BitOff %X, ByteOff %X\n",
436  ObjDesc, AcpiUtGetTypeName (ObjDesc->Common.Type),
437  ObjDesc->Common.Type,
438  ObjDesc->CommonField.BitLength,
439  ObjDesc->CommonField.StartFieldBitOffset,
440  ObjDesc->CommonField.BaseByteOffset));
441 
442  /* Lock entire transaction if requested */
443 
444  AcpiExAcquireGlobalLock (ObjDesc->CommonField.FieldFlags);
445 
446  /* Write to the field */
447 
449  AcpiExReleaseGlobalLock (ObjDesc->CommonField.FieldFlags);
451 }
IN CINT OUT PVOID IN ULONG OUT PULONG ReturnLength
Definition: dumpinfo.c:39
#define ACPI_DB_BFIELD
Definition: acoutput.h:168
ACPI_STATUS AcpiDsGetBufferFieldArguments(ACPI_OPERAND_OBJECT *ObjDesc)
Definition: dsargs.c:196
void AcpiExReleaseGlobalLock(UINT32 FieldFlags)
Definition: exutils.c:270
#define GENERIC_SUBSPACE_COMMAND(a)
Definition: exfield.c:90
#define AE_NO_MEMORY
Definition: acexcep.h:112
#define AE_BAD_PARAMETER
Definition: acexcep.h:151
#define ACPI_TYPE_BUFFER
Definition: actypes.h:682
#define ACPI_TYPE_INTEGER
Definition: actypes.h:680
ACPI_OBJECT_FIELD_COMMON CommonField
Definition: acobject.h:531
ACPI_OPERAND_OBJECT * AcpiUtCreateBufferObject(ACPI_SIZE BufferSize)
Definition: utobject.c:258
#define ACPI_ADR_SPACE_GPIO
Definition: actypes.h:860
#define AE_AML_NO_OPERAND
Definition: acexcep.h:181
#define ACPI_MAX_PROTOCOL_ID
Definition: exfield.c:60
ACPI_OBJECT_COMMON_HEADER ACPI_COMMON_FIELD_INFO BOOLEAN IsCreateField
Definition: acobject.h:384
#define PCC_MASTER_SUBSPACE
Definition: exfield.c:82
UINT32 ACPI_STATUS
Definition: actypes.h:460
ACPI_STATUS AcpiExWriteGpio(ACPI_OPERAND_OBJECT *SourceDesc, ACPI_OPERAND_OBJECT *ObjDesc, ACPI_OPERAND_OBJECT **ReturnBuffer)
Definition: exserial.c:121
ACPI_OBJECT_COMMON_HEADER UINT8 SpaceId
Definition: acobject.h:202
ACPI_STATUS AcpiExReadSerialBus(ACPI_OPERAND_OBJECT *ObjDesc, ACPI_OPERAND_OBJECT **ReturnBuffer)
Definition: exserial.c:182
#define AE_AML_OPERAND_TYPE
Definition: acexcep.h:182
#define ACPI_FAILURE(a)
Definition: acexcep.h:95
unsigned int UINT32
_In_ ULONG BufferLength
Definition: usbdlib.h:225
#define ACPI_INVALID_PROTOCOL_ID
Definition: exfield.c:59
ACPI_STATUS AcpiExWriteDataToField(ACPI_OPERAND_OBJECT *SourceDesc, ACPI_OPERAND_OBJECT *ObjDesc, ACPI_OPERAND_OBJECT **ResultDesc)
Definition: exfield.c:315
#define ACPI_MODULE_NAME(Name)
Definition: acoutput.h:216
#define ACPI_ADR_SPACE_PLATFORM_COMM
Definition: actypes.h:862
#define AE_INFO
Definition: acoutput.h:230
void AcpiExAcquireGlobalLock(UINT32 FieldFlags)
Definition: exutils.c:225
Definition: bufpool.h:45
ACPI_OBJECT_REGION Region
Definition: acobject.h:525
#define ACPI_FUNCTION_TRACE_PTR(a, b)
Definition: acoutput.h:481
ACPI_STATUS AcpiExExtractFromField(ACPI_OPERAND_OBJECT *ObjDesc, void *Buffer, UINT32 BufferLength)
Definition: exfldio.c:723
#define MASTER_SUBSPACE_COMMAND(a)
Definition: exfield.c:91
ACPI_STATUS AcpiExWriteSerialBus(ACPI_OPERAND_OBJECT *SourceDesc, ACPI_OPERAND_OBJECT *ObjDesc, ACPI_OPERAND_OBJECT **ReturnBuffer)
Definition: exserial.c:291
ACPI_OBJECT_BUFFER Buffer
Definition: acobject.h:520
static void Exit(void)
Definition: sock.c:1331
ACPI_OPERAND_OBJECT * AcpiUtCreateIntegerObject(UINT64 Value)
Definition: utobject.c:223
#define ACPI_DEBUG_PRINT(pl)
Definition: acoutput.h:475
#define ACPI_ADR_SPACE_IPMI
Definition: actypes.h:859
_In_ UINT ProtocolId
Definition: ndis.h:2924
#define ACPI_TYPE_LOCAL_REGION_FIELD
Definition: actypes.h:708
#define ACPI_ADR_SPACE_GSBUS
Definition: actypes.h:861
ACPI_OBJECT_INTEGER Integer
Definition: acobject.h:518
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
ACPI_OBJECT_STRING String
Definition: acobject.h:519
Status
Definition: gdiplustypes.h:24
union acpi_operand_object * RegionObj
Definition: acobject.h:345
static const UINT8 AcpiProtocolLengths[]
Definition: exfield.c:62
#define return_ACPI_STATUS(s)
Definition: acoutput.h:496
#define ACPI_TYPE_BUFFER_FIELD
Definition: actypes.h:693
ACPI_OBJECT_COMMON Common
Definition: acobject.h:517
void AcpiUtRemoveReference(ACPI_OPERAND_OBJECT *Object)
Definition: utdelete.c:785
const char * AcpiUtGetTypeName(ACPI_OBJECT_TYPE Type)
Definition: utdecode.c:250
#define ACPI_ERROR(plist)
Definition: acoutput.h:240
ACPI_STATUS AcpiExGetProtocolBufferLength(UINT32 ProtocolId, UINT32 *ReturnLength)
Definition: exfield.c:111
ACPI_STATUS AcpiExReadGpio(ACPI_OPERAND_OBJECT *ObjDesc, void *Buffer)
Definition: exserial.c:70
#define AOPOBJ_DATA_VALID
Definition: acobject.h:96
ACPI_OBJECT_REGION_FIELD Field
Definition: acobject.h:532
ACPI_PHYSICAL_ADDRESS Address
Definition: acobject.h:206
#define ACPI_ADR_SPACE_SMBUS
Definition: actypes.h:856
#define ACPI_TYPE_STRING
Definition: actypes.h:681
#define ACPI_ROUND_BITS_UP_TO_BYTES(a)
Definition: acmacros.h:256
ACPI_STATUS AcpiExReadDataFromField(ACPI_WALK_STATE *WalkState, ACPI_OPERAND_OBJECT *ObjDesc, ACPI_OPERAND_OBJECT **RetBufferDesc)
Definition: exfield.c:147
ACPI_STATUS AcpiExInsertIntoField(ACPI_OPERAND_OBJECT *ObjDesc, void *Buffer, UINT32 BufferLength)
Definition: exfldio.c:883
ACPI_OBJECT_BUFFER_FIELD BufferField
Definition: acobject.h:533
unsigned long long UINT64
_Must_inspect_result_ _Out_writes_to_ DataLength PHIDP_DATA _Inout_ PULONG DataLength
Definition: hidpi.h:333
ACPI_STATUS AcpiExAccessRegion(ACPI_OPERAND_OBJECT *ObjDesc, UINT32 FieldDatumByteOffset, UINT64 *Value, UINT32 Function)
Definition: exfldio.c:249
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
unsigned char UINT8
#define AE_AML_PROTOCOL
Definition: acexcep.h:215
#define AE_OK
Definition: acexcep.h:97
#define ACPI_WRITE
Definition: actypes.h:744