Print this page
acpica-unix2-20130823
PANKOVs restructure
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/intel/io/acpica/executer/exfield.c
+++ new/usr/src/common/acpica/components/executer/exfield.c
1 1 /******************************************************************************
2 2 *
3 3 * Module Name: exfield - ACPI AML (p-code) execution - field manipulation
4 4 *
5 5 *****************************************************************************/
6 6
7 7 /*
8 - * Copyright (C) 2000 - 2011, Intel Corp.
8 + * Copyright (C) 2000 - 2013, Intel Corp.
9 9 * All rights reserved.
10 10 *
11 11 * Redistribution and use in source and binary forms, with or without
12 12 * modification, are permitted provided that the following conditions
13 13 * are met:
14 14 * 1. Redistributions of source code must retain the above copyright
15 15 * notice, this list of conditions, and the following disclaimer,
16 16 * without modification.
17 17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 18 * substantially similar to the "NO WARRANTY" disclaimer below
19 19 * ("Disclaimer") and any redistribution must be conditioned upon
20 20 * including a substantially similar Disclaimer requirement for further
21 21 * binary redistribution.
22 22 * 3. Neither the names of the above-listed copyright holders nor the names
23 23 * of any contributors may be used to endorse or promote products derived
24 24 * from this software without specific prior written permission.
25 25 *
26 26 * Alternatively, this software may be distributed under the terms of the
27 27 * GNU General Public License ("GPL") version 2 as published by the Free
28 28 * Software Foundation.
29 29 *
30 30 * NO WARRANTY
31 31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 41 * POSSIBILITY OF SUCH DAMAGES.
42 42 */
43 43
44 44
45 45 #define __EXFIELD_C__
46 46
47 47 #include "acpi.h"
48 48 #include "accommon.h"
49 49 #include "acdispat.h"
50 50 #include "acinterp.h"
51 51
52 52
53 53 #define _COMPONENT ACPI_EXECUTER
54 54 ACPI_MODULE_NAME ("exfield")
55 55
56 56
↓ open down ↓ |
38 lines elided |
↑ open up ↑ |
57 57 /*******************************************************************************
58 58 *
59 59 * FUNCTION: AcpiExReadDataFromField
60 60 *
61 61 * PARAMETERS: WalkState - Current execution state
62 62 * ObjDesc - The named field
63 63 * RetBufferDesc - Where the return data object is stored
64 64 *
65 65 * RETURN: Status
66 66 *
67 - * DESCRIPTION: Read from a named field. Returns either an Integer or a
67 + * DESCRIPTION: Read from a named field. Returns either an Integer or a
68 68 * Buffer, depending on the size of the field.
69 69 *
70 70 ******************************************************************************/
71 71
72 72 ACPI_STATUS
73 73 AcpiExReadDataFromField (
74 74 ACPI_WALK_STATE *WalkState,
75 75 ACPI_OPERAND_OBJECT *ObjDesc,
76 76 ACPI_OPERAND_OBJECT **RetBufferDesc)
77 77 {
78 78 ACPI_STATUS Status;
79 79 ACPI_OPERAND_OBJECT *BufferDesc;
80 80 ACPI_SIZE Length;
81 81 void *Buffer;
82 82 UINT32 Function;
83 83
84 84
85 85 ACPI_FUNCTION_TRACE_PTR (ExReadDataFromField, ObjDesc);
86 86
87 87
88 88 /* Parameter validation */
89 89
90 90 if (!ObjDesc)
91 91 {
92 92 return_ACPI_STATUS (AE_AML_NO_OPERAND);
93 93 }
94 94 if (!RetBufferDesc)
95 95 {
96 96 return_ACPI_STATUS (AE_BAD_PARAMETER);
97 97 }
98 98
99 99 if (ObjDesc->Common.Type == ACPI_TYPE_BUFFER_FIELD)
100 100 {
101 101 /*
102 102 * If the BufferField arguments have not been previously evaluated,
103 103 * evaluate them now and save the results.
104 104 */
105 105 if (!(ObjDesc->Common.Flags & AOPOBJ_DATA_VALID))
↓ open down ↓ |
28 lines elided |
↑ open up ↑ |
106 106 {
107 107 Status = AcpiDsGetBufferFieldArguments (ObjDesc);
108 108 if (ACPI_FAILURE (Status))
109 109 {
110 110 return_ACPI_STATUS (Status);
111 111 }
112 112 }
113 113 }
114 114 else if ((ObjDesc->Common.Type == ACPI_TYPE_LOCAL_REGION_FIELD) &&
115 115 (ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_SMBUS ||
116 + ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_GSBUS ||
116 117 ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_IPMI))
117 118 {
118 119 /*
119 - * This is an SMBus or IPMI read. We must create a buffer to hold
120 + * This is an SMBus, GSBus or IPMI read. We must create a buffer to hold
120 121 * the data and then directly access the region handler.
121 122 *
122 - * Note: Smbus protocol value is passed in upper 16-bits of Function
123 + * Note: SMBus and GSBus protocol value is passed in upper 16-bits of Function
123 124 */
124 125 if (ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_SMBUS)
125 126 {
126 127 Length = ACPI_SMBUS_BUFFER_SIZE;
127 128 Function = ACPI_READ | (ObjDesc->Field.Attribute << 16);
128 129 }
130 + else if (ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_GSBUS)
131 + {
132 + Length = ACPI_GSBUS_BUFFER_SIZE;
133 + Function = ACPI_READ | (ObjDesc->Field.Attribute << 16);
134 + }
129 135 else /* IPMI */
130 136 {
131 137 Length = ACPI_IPMI_BUFFER_SIZE;
132 138 Function = ACPI_READ;
133 139 }
134 140
135 141 BufferDesc = AcpiUtCreateBufferObject (Length);
136 142 if (!BufferDesc)
137 143 {
138 144 return_ACPI_STATUS (AE_NO_MEMORY);
139 145 }
140 146
141 147 /* Lock entire transaction if requested */
142 148
143 149 AcpiExAcquireGlobalLock (ObjDesc->CommonField.FieldFlags);
144 150
145 151 /* Call the region handler for the read */
146 152
147 153 Status = AcpiExAccessRegion (ObjDesc, 0,
↓ open down ↓ |
9 lines elided |
↑ open up ↑ |
148 154 ACPI_CAST_PTR (UINT64, BufferDesc->Buffer.Pointer),
149 155 Function);
150 156 AcpiExReleaseGlobalLock (ObjDesc->CommonField.FieldFlags);
151 157 goto Exit;
152 158 }
153 159
154 160 /*
155 161 * Allocate a buffer for the contents of the field.
156 162 *
157 163 * If the field is larger than the current integer width, create
158 - * a BUFFER to hold it. Otherwise, use an INTEGER. This allows
164 + * a BUFFER to hold it. Otherwise, use an INTEGER. This allows
159 165 * the use of arithmetic operators on the returned value if the
160 166 * field size is equal or smaller than an Integer.
161 167 *
162 168 * Note: Field.length is in bits.
163 169 */
164 170 Length = (ACPI_SIZE) ACPI_ROUND_BITS_UP_TO_BYTES (ObjDesc->Field.BitLength);
165 171 if (Length > AcpiGbl_IntegerByteWidth)
166 172 {
167 173 /* Field is too large for an Integer, create a Buffer instead */
168 174
169 175 BufferDesc = AcpiUtCreateBufferObject (Length);
170 176 if (!BufferDesc)
171 177 {
172 178 return_ACPI_STATUS (AE_NO_MEMORY);
173 179 }
174 180 Buffer = BufferDesc->Buffer.Pointer;
175 181 }
176 182 else
177 183 {
178 184 /* Field will fit within an Integer (normal case) */
179 185
180 186 BufferDesc = AcpiUtCreateIntegerObject ((UINT64) 0);
181 187 if (!BufferDesc)
182 188 {
183 189 return_ACPI_STATUS (AE_NO_MEMORY);
184 190 }
185 191
186 192 Length = AcpiGbl_IntegerByteWidth;
187 193 Buffer = &BufferDesc->Integer.Value;
188 194 }
189 195
190 196 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
191 197 "FieldRead [TO]: Obj %p, Type %X, Buf %p, ByteLen %X\n",
192 198 ObjDesc, ObjDesc->Common.Type, Buffer, (UINT32) Length));
193 199 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
194 200 "FieldRead [FROM]: BitLen %X, BitOff %X, ByteOff %X\n",
195 201 ObjDesc->CommonField.BitLength,
196 202 ObjDesc->CommonField.StartFieldBitOffset,
197 203 ObjDesc->CommonField.BaseByteOffset));
198 204
199 205 /* Lock entire transaction if requested */
200 206
201 207 AcpiExAcquireGlobalLock (ObjDesc->CommonField.FieldFlags);
202 208
203 209 /* Read from the field */
204 210
205 211 Status = AcpiExExtractFromField (ObjDesc, Buffer, (UINT32) Length);
206 212 AcpiExReleaseGlobalLock (ObjDesc->CommonField.FieldFlags);
207 213
208 214
209 215 Exit:
210 216 if (ACPI_FAILURE (Status))
211 217 {
212 218 AcpiUtRemoveReference (BufferDesc);
213 219 }
214 220 else
215 221 {
216 222 *RetBufferDesc = BufferDesc;
217 223 }
218 224
219 225 return_ACPI_STATUS (Status);
220 226 }
221 227
222 228
223 229 /*******************************************************************************
224 230 *
225 231 * FUNCTION: AcpiExWriteDataToField
226 232 *
227 233 * PARAMETERS: SourceDesc - Contains data to write
228 234 * ObjDesc - The named field
229 235 * ResultDesc - Where the return value is returned, if any
230 236 *
231 237 * RETURN: Status
232 238 *
233 239 * DESCRIPTION: Write to a named field
234 240 *
235 241 ******************************************************************************/
236 242
237 243 ACPI_STATUS
238 244 AcpiExWriteDataToField (
239 245 ACPI_OPERAND_OBJECT *SourceDesc,
240 246 ACPI_OPERAND_OBJECT *ObjDesc,
241 247 ACPI_OPERAND_OBJECT **ResultDesc)
242 248 {
243 249 ACPI_STATUS Status;
244 250 UINT32 Length;
245 251 void *Buffer;
246 252 ACPI_OPERAND_OBJECT *BufferDesc;
247 253 UINT32 Function;
248 254
249 255
250 256 ACPI_FUNCTION_TRACE_PTR (ExWriteDataToField, ObjDesc);
251 257
252 258
253 259 /* Parameter validation */
254 260
255 261 if (!SourceDesc || !ObjDesc)
256 262 {
257 263 return_ACPI_STATUS (AE_AML_NO_OPERAND);
258 264 }
259 265
260 266 if (ObjDesc->Common.Type == ACPI_TYPE_BUFFER_FIELD)
261 267 {
262 268 /*
263 269 * If the BufferField arguments have not been previously evaluated,
264 270 * evaluate them now and save the results.
265 271 */
266 272 if (!(ObjDesc->Common.Flags & AOPOBJ_DATA_VALID))
↓ open down ↓ |
98 lines elided |
↑ open up ↑ |
267 273 {
268 274 Status = AcpiDsGetBufferFieldArguments (ObjDesc);
269 275 if (ACPI_FAILURE (Status))
270 276 {
271 277 return_ACPI_STATUS (Status);
272 278 }
273 279 }
274 280 }
275 281 else if ((ObjDesc->Common.Type == ACPI_TYPE_LOCAL_REGION_FIELD) &&
276 282 (ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_SMBUS ||
283 + ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_GSBUS ||
277 284 ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_IPMI))
278 285 {
279 286 /*
280 - * This is an SMBus or IPMI write. We will bypass the entire field
287 + * This is an SMBus, GSBus or IPMI write. We will bypass the entire field
281 288 * mechanism and handoff the buffer directly to the handler. For
282 289 * these address spaces, the buffer is bi-directional; on a write,
283 290 * return data is returned in the same buffer.
284 291 *
285 292 * Source must be a buffer of sufficient size:
286 - * ACPI_SMBUS_BUFFER_SIZE or ACPI_IPMI_BUFFER_SIZE.
293 + * ACPI_SMBUS_BUFFER_SIZE, ACPI_GSBUS_BUFFER_SIZE, or ACPI_IPMI_BUFFER_SIZE.
287 294 *
288 - * Note: SMBus protocol type is passed in upper 16-bits of Function
295 + * Note: SMBus and GSBus protocol type is passed in upper 16-bits of Function
289 296 */
290 297 if (SourceDesc->Common.Type != ACPI_TYPE_BUFFER)
291 298 {
292 299 ACPI_ERROR ((AE_INFO,
293 - "SMBus or IPMI write requires Buffer, found type %s",
300 + "SMBus/IPMI/GenericSerialBus write requires Buffer, found type %s",
294 301 AcpiUtGetObjectTypeName (SourceDesc)));
295 302
296 303 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
297 304 }
298 305
299 306 if (ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_SMBUS)
300 307 {
301 308 Length = ACPI_SMBUS_BUFFER_SIZE;
302 309 Function = ACPI_WRITE | (ObjDesc->Field.Attribute << 16);
303 310 }
311 + else if (ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_GSBUS)
312 + {
313 + Length = ACPI_GSBUS_BUFFER_SIZE;
314 + Function = ACPI_WRITE | (ObjDesc->Field.Attribute << 16);
315 + }
304 316 else /* IPMI */
305 317 {
306 318 Length = ACPI_IPMI_BUFFER_SIZE;
307 319 Function = ACPI_WRITE;
308 320 }
309 321
310 322 if (SourceDesc->Buffer.Length < Length)
311 323 {
312 324 ACPI_ERROR ((AE_INFO,
313 - "SMBus or IPMI write requires Buffer of length %u, found length %u",
325 + "SMBus/IPMI/GenericSerialBus write requires Buffer of length %u, found length %u",
314 326 Length, SourceDesc->Buffer.Length));
315 327
316 328 return_ACPI_STATUS (AE_AML_BUFFER_LIMIT);
317 329 }
318 330
319 331 /* Create the bi-directional buffer */
320 332
321 333 BufferDesc = AcpiUtCreateBufferObject (Length);
322 334 if (!BufferDesc)
323 335 {
324 336 return_ACPI_STATUS (AE_NO_MEMORY);
325 337 }
326 338
327 339 Buffer = BufferDesc->Buffer.Pointer;
328 340 ACPI_MEMCPY (Buffer, SourceDesc->Buffer.Pointer, Length);
329 341
330 342 /* Lock entire transaction if requested */
331 343
332 344 AcpiExAcquireGlobalLock (ObjDesc->CommonField.FieldFlags);
333 345
334 346 /*
335 347 * Perform the write (returns status and perhaps data in the
336 348 * same buffer)
337 349 */
338 350 Status = AcpiExAccessRegion (ObjDesc, 0,
339 351 (UINT64 *) Buffer, Function);
340 352 AcpiExReleaseGlobalLock (ObjDesc->CommonField.FieldFlags);
↓ open down ↓ |
17 lines elided |
↑ open up ↑ |
341 353
342 354 *ResultDesc = BufferDesc;
343 355 return_ACPI_STATUS (Status);
344 356 }
345 357
346 358 /* Get a pointer to the data to be written */
347 359
348 360 switch (SourceDesc->Common.Type)
349 361 {
350 362 case ACPI_TYPE_INTEGER:
363 +
351 364 Buffer = &SourceDesc->Integer.Value;
352 365 Length = sizeof (SourceDesc->Integer.Value);
353 366 break;
354 367
355 368 case ACPI_TYPE_BUFFER:
369 +
356 370 Buffer = SourceDesc->Buffer.Pointer;
357 371 Length = SourceDesc->Buffer.Length;
358 372 break;
359 373
360 374 case ACPI_TYPE_STRING:
375 +
361 376 Buffer = SourceDesc->String.Pointer;
362 377 Length = SourceDesc->String.Length;
363 378 break;
364 379
365 380 default:
381 +
366 382 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
367 383 }
368 384
369 385 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
370 386 "FieldWrite [FROM]: Obj %p (%s:%X), Buf %p, ByteLen %X\n",
371 387 SourceDesc, AcpiUtGetTypeName (SourceDesc->Common.Type),
372 388 SourceDesc->Common.Type, Buffer, Length));
373 389
374 390 ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
375 391 "FieldWrite [TO]: Obj %p (%s:%X), BitLen %X, BitOff %X, ByteOff %X\n",
376 392 ObjDesc, AcpiUtGetTypeName (ObjDesc->Common.Type),
377 393 ObjDesc->Common.Type,
378 394 ObjDesc->CommonField.BitLength,
379 395 ObjDesc->CommonField.StartFieldBitOffset,
380 396 ObjDesc->CommonField.BaseByteOffset));
381 397
382 398 /* Lock entire transaction if requested */
↓ open down ↓ |
7 lines elided |
↑ open up ↑ |
383 399
384 400 AcpiExAcquireGlobalLock (ObjDesc->CommonField.FieldFlags);
385 401
386 402 /* Write to the field */
387 403
388 404 Status = AcpiExInsertIntoField (ObjDesc, Buffer, Length);
389 405 AcpiExReleaseGlobalLock (ObjDesc->CommonField.FieldFlags);
390 406
391 407 return_ACPI_STATUS (Status);
392 408 }
393 -
394 -
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX