ReactOS  0.4.12-dev-685-gf36cbf7
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 - 2019, 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 
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 
83 /*******************************************************************************
84  *
85  * FUNCTION: AcpiExGetProtocolBufferLength
86  *
87  * PARAMETERS: ProtocolId - The type of the protocol indicated by region
88  * field access attributes
89  * ReturnLength - Where the protocol byte transfer length is
90  * returned
91  *
92  * RETURN: Status and decoded byte transfer length
93  *
94  * DESCRIPTION: This routine returns the length of the GenericSerialBus
95  * protocol bytes
96  *
97  ******************************************************************************/
98 
103 {
104 
107  {
109  "Invalid Field/AccessAs protocol ID: 0x%4.4X", ProtocolId));
110 
111  return (AE_AML_PROTOCOL);
112  }
113 
115  return (AE_OK);
116 }
117 
118 
119 /*******************************************************************************
120  *
121  * FUNCTION: AcpiExReadDataFromField
122  *
123  * PARAMETERS: WalkState - Current execution state
124  * ObjDesc - The named field
125  * RetBufferDesc - Where the return data object is stored
126  *
127  * RETURN: Status
128  *
129  * DESCRIPTION: Read from a named field. Returns either an Integer or a
130  * Buffer, depending on the size of the field.
131  *
132  ******************************************************************************/
133 
136  ACPI_WALK_STATE *WalkState,
137  ACPI_OPERAND_OBJECT *ObjDesc,
138  ACPI_OPERAND_OBJECT **RetBufferDesc)
139 {
141  ACPI_OPERAND_OBJECT *BufferDesc;
142  void *Buffer;
144 
145 
146  ACPI_FUNCTION_TRACE_PTR (ExReadDataFromField, ObjDesc);
147 
148 
149  /* Parameter validation */
150 
151  if (!ObjDesc)
152  {
154  }
155  if (!RetBufferDesc)
156  {
158  }
159 
160  if (ObjDesc->Common.Type == ACPI_TYPE_BUFFER_FIELD)
161  {
162  /*
163  * If the BufferField arguments have not been previously evaluated,
164  * evaluate them now and save the results.
165  */
166  if (!(ObjDesc->Common.Flags & AOPOBJ_DATA_VALID))
167  {
169  if (ACPI_FAILURE (Status))
170  {
172  }
173  }
174  }
175  else if ((ObjDesc->Common.Type == ACPI_TYPE_LOCAL_REGION_FIELD) &&
179  {
180  /* SMBus, GSBus, IPMI serial */
181 
182  Status = AcpiExReadSerialBus (ObjDesc, RetBufferDesc);
184  }
185 
186  /*
187  * Allocate a buffer for the contents of the field.
188  *
189  * If the field is larger than the current integer width, create
190  * a BUFFER to hold it. Otherwise, use an INTEGER. This allows
191  * the use of arithmetic operators on the returned value if the
192  * field size is equal or smaller than an Integer.
193  *
194  * Note: Field.length is in bits.
195  */
197  ObjDesc->Field.BitLength);
198 
199  if (BufferLength > AcpiGbl_IntegerByteWidth)
200  {
201  /* Field is too large for an Integer, create a Buffer instead */
202 
203  BufferDesc = AcpiUtCreateBufferObject (BufferLength);
204  if (!BufferDesc)
205  {
207  }
208  Buffer = BufferDesc->Buffer.Pointer;
209  }
210  else
211  {
212  /* Field will fit within an Integer (normal case) */
213 
214  BufferDesc = AcpiUtCreateIntegerObject ((UINT64) 0);
215  if (!BufferDesc)
216  {
218  }
219 
220  BufferLength = AcpiGbl_IntegerByteWidth;
221  Buffer = &BufferDesc->Integer.Value;
222  }
223 
224  if ((ObjDesc->Common.Type == ACPI_TYPE_LOCAL_REGION_FIELD) &&
226  {
227  /* General Purpose I/O */
228 
229  Status = AcpiExReadGpio (ObjDesc, Buffer);
230  goto Exit;
231  }
232 
234  "FieldRead [TO]: Obj %p, Type %X, Buf %p, ByteLen %X\n",
235  ObjDesc, ObjDesc->Common.Type, Buffer, BufferLength));
237  "FieldRead [FROM]: BitLen %X, BitOff %X, ByteOff %X\n",
238  ObjDesc->CommonField.BitLength,
239  ObjDesc->CommonField.StartFieldBitOffset,
240  ObjDesc->CommonField.BaseByteOffset));
241 
242  /* Lock entire transaction if requested */
243 
244  AcpiExAcquireGlobalLock (ObjDesc->CommonField.FieldFlags);
245 
246  /* Read from the field */
247 
249  AcpiExReleaseGlobalLock (ObjDesc->CommonField.FieldFlags);
250 
251 
252 Exit:
253  if (ACPI_FAILURE (Status))
254  {
255  AcpiUtRemoveReference (BufferDesc);
256  }
257  else
258  {
259  *RetBufferDesc = BufferDesc;
260  }
261 
263 }
264 
265 
266 /*******************************************************************************
267  *
268  * FUNCTION: AcpiExWriteDataToField
269  *
270  * PARAMETERS: SourceDesc - Contains data to write
271  * ObjDesc - The named field
272  * ResultDesc - Where the return value is returned, if any
273  *
274  * RETURN: Status
275  *
276  * DESCRIPTION: Write to a named field
277  *
278  ******************************************************************************/
279 
282  ACPI_OPERAND_OBJECT *SourceDesc,
283  ACPI_OPERAND_OBJECT *ObjDesc,
284  ACPI_OPERAND_OBJECT **ResultDesc)
285 {
288  void *Buffer;
289 
290 
291  ACPI_FUNCTION_TRACE_PTR (ExWriteDataToField, ObjDesc);
292 
293 
294  /* Parameter validation */
295 
296  if (!SourceDesc || !ObjDesc)
297  {
299  }
300 
301  if (ObjDesc->Common.Type == ACPI_TYPE_BUFFER_FIELD)
302  {
303  /*
304  * If the BufferField arguments have not been previously evaluated,
305  * evaluate them now and save the results.
306  */
307  if (!(ObjDesc->Common.Flags & AOPOBJ_DATA_VALID))
308  {
310  if (ACPI_FAILURE (Status))
311  {
313  }
314  }
315  }
316  else if ((ObjDesc->Common.Type == ACPI_TYPE_LOCAL_REGION_FIELD) &&
318  {
319  /* General Purpose I/O */
320 
321  Status = AcpiExWriteGpio (SourceDesc, ObjDesc, ResultDesc);
323  }
324  else if ((ObjDesc->Common.Type == ACPI_TYPE_LOCAL_REGION_FIELD) &&
328  {
329  /* SMBus, GSBus, IPMI serial */
330 
331  Status = AcpiExWriteSerialBus (SourceDesc, ObjDesc, ResultDesc);
333  }
334 
335  /* Get a pointer to the data to be written */
336 
337  switch (SourceDesc->Common.Type)
338  {
339  case ACPI_TYPE_INTEGER:
340 
341  Buffer = &SourceDesc->Integer.Value;
342  BufferLength = sizeof (SourceDesc->Integer.Value);
343  break;
344 
345  case ACPI_TYPE_BUFFER:
346 
347  Buffer = SourceDesc->Buffer.Pointer;
348  BufferLength = SourceDesc->Buffer.Length;
349  break;
350 
351  case ACPI_TYPE_STRING:
352 
353  Buffer = SourceDesc->String.Pointer;
354  BufferLength = SourceDesc->String.Length;
355  break;
356 
357  default:
359  }
360 
362  "FieldWrite [FROM]: Obj %p (%s:%X), Buf %p, ByteLen %X\n",
363  SourceDesc, AcpiUtGetTypeName (SourceDesc->Common.Type),
364  SourceDesc->Common.Type, Buffer, BufferLength));
365 
367  "FieldWrite [TO]: Obj %p (%s:%X), BitLen %X, BitOff %X, ByteOff %X\n",
368  ObjDesc, AcpiUtGetTypeName (ObjDesc->Common.Type),
369  ObjDesc->Common.Type,
370  ObjDesc->CommonField.BitLength,
371  ObjDesc->CommonField.StartFieldBitOffset,
372  ObjDesc->CommonField.BaseByteOffset));
373 
374  /* Lock entire transaction if requested */
375 
376  AcpiExAcquireGlobalLock (ObjDesc->CommonField.FieldFlags);
377 
378  /* Write to the field */
379 
381  AcpiExReleaseGlobalLock (ObjDesc->CommonField.FieldFlags);
383 }
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 AE_NO_MEMORY
Definition: acexcep.h:112
#define AE_BAD_PARAMETER
Definition: acexcep.h:151
#define ACPI_TYPE_BUFFER
Definition: actypes.h:680
#define ACPI_TYPE_INTEGER
Definition: actypes.h:678
ACPI_OBJECT_FIELD_COMMON CommonField
Definition: acobject.h:529
ACPI_OPERAND_OBJECT * AcpiUtCreateBufferObject(ACPI_SIZE BufferSize)
Definition: utobject.c:258
#define ACPI_ADR_SPACE_GPIO
Definition: actypes.h:858
#define AE_AML_NO_OPERAND
Definition: acexcep.h:181
#define ACPI_MAX_PROTOCOL_ID
Definition: exfield.c:60
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:281
#define ACPI_MODULE_NAME(Name)
Definition: acoutput.h:216
#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:523
#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
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:518
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:857
_In_ UINT ProtocolId
Definition: ndis.h:2906
#define ACPI_TYPE_LOCAL_REGION_FIELD
Definition: actypes.h:706
#define ACPI_ADR_SPACE_GSBUS
Definition: actypes.h:859
ACPI_OBJECT_INTEGER Integer
Definition: acobject.h:516
ACPI_OBJECT_STRING String
Definition: acobject.h:517
Status
Definition: gdiplustypes.h:24
union acpi_operand_object * RegionObj
Definition: acobject.h:345
const UINT8 AcpiProtocolLengths[]
Definition: exfield.c:62
#define return_ACPI_STATUS(s)
Definition: acoutput.h:496
#define ACPI_TYPE_BUFFER_FIELD
Definition: actypes.h:691
ACPI_OBJECT_COMMON Common
Definition: acobject.h:515
void AcpiUtRemoveReference(ACPI_OPERAND_OBJECT *Object)
Definition: utdelete.c:779
const char * AcpiUtGetTypeName(ACPI_OBJECT_TYPE Type)
Definition: utdecode.c:249
#define ACPI_ERROR(plist)
Definition: acoutput.h:240
ACPI_STATUS AcpiExGetProtocolBufferLength(UINT32 ProtocolId, UINT32 *ReturnLength)
Definition: exfield.c:100
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:530
#define ACPI_ADR_SPACE_SMBUS
Definition: actypes.h:854
#define ACPI_TYPE_STRING
Definition: actypes.h:679
#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:135
ACPI_STATUS AcpiExInsertIntoField(ACPI_OPERAND_OBJECT *ObjDesc, void *Buffer, UINT32 BufferLength)
Definition: exfldio.c:883
unsigned long long UINT64
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