Deleted Added
sdiff udiff text old ( 67754 ) new ( 69450 )
full compact
1
2/******************************************************************************
3 *
4 * Module Name: amregion - ACPI default OpRegion (address space) handlers
5 * $Revision: 40 $
6 *
7 *****************************************************************************/
8
9/******************************************************************************
10 *
11 * 1. Copyright Notice
12 *
13 * Some or all of this work - Copyright (c) 1999, Intel Corp. All rights
14 * reserved.
15 *
16 * 2. License
17 *
18 * 2.1. This is your license from Intel Corp. under its intellectual property
19 * rights. You may have additional license terms from the party that provided
20 * you this software, covering your right to use that party's intellectual
21 * property rights.
22 *
23 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
24 * copy of the source code appearing in this file ("Covered Code") an
25 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
26 * base code distributed originally by Intel ("Original Intel Code") to copy,
27 * make derivatives, distribute, use and display any portion of the Covered
28 * Code in any form, with the right to sublicense such rights; and
29 *
30 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
31 * license (with the right to sublicense), under only those claims of Intel
32 * patents that are infringed by the Original Intel Code, to make, use, sell,
33 * offer to sell, and import the Covered Code and derivative works thereof
34 * solely to the minimum extent necessary to exercise the above copyright
35 * license, and in no event shall the patent license extend to any additions
36 * to or modifications of the Original Intel Code. No other license or right
37 * is granted directly or by implication, estoppel or otherwise;
38 *
39 * The above copyright and patent license is granted only if the following
40 * conditions are met:
41 *
42 * 3. Conditions
43 *
44 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
45 * Redistribution of source code of any substantial portion of the Covered
46 * Code or modification with rights to further distribute source must include
47 * the above Copyright Notice, the above License, this list of Conditions,
48 * and the following Disclaimer and Export Compliance provision. In addition,
49 * Licensee must cause all Covered Code to which Licensee contributes to
50 * contain a file documenting the changes Licensee made to create that Covered
51 * Code and the date of any change. Licensee must include in that file the
52 * documentation of any changes made by any predecessor Licensee. Licensee
53 * must include a prominent statement that the modification is derived,
54 * directly or indirectly, from Original Intel Code.
55 *
56 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
57 * Redistribution of source code of any substantial portion of the Covered
58 * Code or modification without rights to further distribute source must
59 * include the following Disclaimer and Export Compliance provision in the
60 * documentation and/or other materials provided with distribution. In
61 * addition, Licensee may not authorize further sublicense of source of any
62 * portion of the Covered Code, and must include terms to the effect that the
63 * license from Licensee to its licensee is limited to the intellectual
64 * property embodied in the software Licensee provides to its licensee, and
65 * not to intellectual property embodied in modifications its licensee may
66 * make.
67 *
68 * 3.3. Redistribution of Executable. Redistribution in executable form of any
69 * substantial portion of the Covered Code or modification must reproduce the
70 * above Copyright Notice, and the following Disclaimer and Export Compliance
71 * provision in the documentation and/or other materials provided with the
72 * distribution.
73 *
74 * 3.4. Intel retains all right, title, and interest in and to the Original
75 * Intel Code.
76 *
77 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
78 * Intel shall be used in advertising or otherwise to promote the sale, use or
79 * other dealings in products derived from or relating to the Covered Code
80 * without prior written authorization from Intel.
81 *
82 * 4. Disclaimer and Export Compliance
83 *
84 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
85 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
86 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
87 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
88 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
89 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90 * PARTICULAR PURPOSE.
91 *
92 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
93 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
94 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
95 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
96 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
97 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
98 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99 * LIMITED REMEDY.
100 *
101 * 4.3. Licensee shall not export, either directly or indirectly, any of this
102 * software or system incorporating such software without first obtaining any
103 * required license or other approval from the U. S. Department of Commerce or
104 * any other agency or department of the United States Government. In the
105 * event Licensee exports any such software from the United States or
106 * re-exports any such software from a foreign destination, Licensee shall
107 * ensure that the distribution and export/re-export of the software is in
108 * compliance with all laws, regulations, orders, or other restrictions of the
109 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
110 * any of its subsidiaries will export/re-export any technical data, process,
111 * software, or service, directly or indirectly, to any country for which the
112 * United States government or any agency thereof requires an export license,
113 * other governmental approval, or letter of assurance, without first obtaining
114 * such license, approval or letter.
115 *
116 *****************************************************************************/
117
118
119#define __AMREGION_C__
120
121#include "acpi.h"
122#include "acinterp.h"
123#include "amlcode.h"
124#include "acnamesp.h"
125#include "achware.h"
126#include "acevents.h"
127
128
129#define _COMPONENT INTERPRETER
130 MODULE_NAME ("amregion")
131
132
133/*******************************************************************************
134 *
135 * FUNCTION: AcpiAmlSystemMemorySpaceHandler
136 *
137 * PARAMETERS: Function - Read or Write operation
138 * Address - Where in the space to read or write
139 * BitWidth - Field width in bits (8, 16, or 32)
140 * Value - Pointer to in or out value
141 * HandlerContext - Pointer to Handler's context
142 * RegionContext - Pointer to context specific to the
143 * accessed region
144 *
145 * RETURN: Status
146 *
147 * DESCRIPTION: Handler for the System Memory address space (Op Region)
148 *
149 ******************************************************************************/
150
151ACPI_STATUS
152AcpiAmlSystemMemorySpaceHandler (
153 UINT32 Function,
154 ACPI_PHYSICAL_ADDRESS Address,
155 UINT32 BitWidth,
156 UINT32 *Value,
157 void *HandlerContext,
158 void *RegionContext)
159{
160 ACPI_STATUS Status = AE_OK;
161 void *LogicalAddrPtr = NULL;
162 MEM_HANDLER_CONTEXT *MemInfo = RegionContext;
163 UINT32 Length;
164
165
166 FUNCTION_TRACE ("AmlSystemMemorySpaceHandler");
167
168
169 /* Validate and translate the bit width */
170
171 switch (BitWidth)
172 {
173 case 8:
174 Length = 1;
175 break;
176
177 case 16:
178 Length = 2;
179 break;
180
181 case 32:
182 Length = 4;
183 break;
184
185 default:
186 DEBUG_PRINT (ACPI_ERROR,
187 ("AmlSystemMemorySpaceHandler: Invalid SystemMemory width %d\n",
188 BitWidth));
189 return_ACPI_STATUS (AE_AML_OPERAND_VALUE);
190 break;
191 }
192
193
194 /*
195 * Does the request fit into the cached memory mapping?
196 * Is 1) Address below the current mapping? OR
197 * 2) Address beyond the current mapping?
198 */
199
200 if ((Address < MemInfo->MappedPhysicalAddress) ||
201 ((Address + Length) >
202 (MemInfo->MappedPhysicalAddress + MemInfo->MappedLength)))
203 {
204 /*
205 * The request cannot be resolved by the current memory mapping;
206 * Delete the existing mapping and create a new one.
207 */
208
209 if (MemInfo->MappedLength)
210 {
211 /* Valid mapping, delete it */
212
213 AcpiOsUnmapMemory (MemInfo->MappedLogicalAddress,
214 MemInfo->MappedLength);
215 }
216
217 MemInfo->MappedLength = 0; /* In case of failure below */
218
219 /* Create a new mapping starting at the address given */
220
221 Status = AcpiOsMapMemory (Address, SYSMEM_REGION_WINDOW_SIZE,
222 (void **) &MemInfo->MappedLogicalAddress);
223 if (ACPI_FAILURE (Status))
224 {
225 return_ACPI_STATUS (Status);
226 }
227
228 /* TBD: should these pointers go to 64-bit in all cases ? */
229
230 MemInfo->MappedPhysicalAddress = Address;
231 MemInfo->MappedLength = SYSMEM_REGION_WINDOW_SIZE;
232 }
233
234
235 /*
236 * Generate a logical pointer corresponding to the address we want to
237 * access
238 */
239
240 /* TBD: should these pointers go to 64-bit in all cases ? */
241
242 LogicalAddrPtr = MemInfo->MappedLogicalAddress +
243 (Address - MemInfo->MappedPhysicalAddress);
244
245 /* Perform the memory read or write */
246
247 switch (Function)
248 {
249
250 case ADDRESS_SPACE_READ:
251
252 DEBUG_PRINT ((TRACE_OPREGION | VERBOSE_INFO),
253 ("Read (%d width) Address:0x%X\n", BitWidth, Address));
254
255 switch (BitWidth)
256 {
257 case 8:
258 *Value = (UINT32)* (UINT8 *) LogicalAddrPtr;
259 break;
260
261 case 16:
262 MOVE_UNALIGNED16_TO_32 (Value, LogicalAddrPtr);
263 break;
264
265 case 32:
266 MOVE_UNALIGNED32_TO_32 (Value, LogicalAddrPtr);
267 break;
268 }
269
270 break;
271
272
273 case ADDRESS_SPACE_WRITE:
274
275 DEBUG_PRINT ((TRACE_OPREGION | VERBOSE_INFO),
276 ("Write (%d width) Address:0x%p Value 0x%X\n",
277 BitWidth, Address, *Value));
278
279 switch (BitWidth)
280 {
281 case 8:
282 *(UINT8 *) LogicalAddrPtr = (UINT8) *Value;
283 break;
284
285 case 16:
286 MOVE_UNALIGNED16_TO_16 (LogicalAddrPtr, Value);
287 break;
288
289 case 32:
290 MOVE_UNALIGNED32_TO_32 (LogicalAddrPtr, Value);
291 break;
292 }
293
294 break;
295
296
297 default:
298 Status = AE_BAD_PARAMETER;
299 break;
300 }
301
302 return_ACPI_STATUS (Status);
303}
304
305
306/*******************************************************************************
307 *
308 * FUNCTION: AcpiAmlSystemIoSpaceHandler
309 *
310 * PARAMETERS: Function - Read or Write operation
311 * Address - Where in the space to read or write
312 * BitWidth - Field width in bits (8, 16, or 32)
313 * Value - Pointer to in or out value
314 * HandlerContext - Pointer to Handler's context
315 * RegionContext - Pointer to context specific to the
316 * accessed region
317 *
318 * RETURN: Status
319 *
320 * DESCRIPTION: Handler for the System IO address space (Op Region)
321 *
322 ******************************************************************************/
323
324ACPI_STATUS
325AcpiAmlSystemIoSpaceHandler (
326 UINT32 Function,
327 ACPI_PHYSICAL_ADDRESS Address,
328 UINT32 BitWidth,
329 UINT32 *Value,
330 void *HandlerContext,
331 void *RegionContext)
332{
333 ACPI_STATUS Status = AE_OK;
334
335
336 FUNCTION_TRACE ("AmlSystemIoSpaceHandler");
337
338
339 /* Decode the function parameter */
340
341 switch (Function)
342 {
343
344 case ADDRESS_SPACE_READ:
345
346 DEBUG_PRINT ((TRACE_OPREGION | VERBOSE_INFO),
347 ("Read(%d width) Address:0x%08x\n", BitWidth, Address));
348
349 switch (BitWidth)
350 {
351 /* I/O Port width */
352
353 case 8:
354 *Value = (UINT32) AcpiOsIn8 ((ACPI_IO_ADDRESS) Address);
355 break;
356
357 case 16:
358 *Value = (UINT32) AcpiOsIn16 ((ACPI_IO_ADDRESS) Address);
359 break;
360
361 case 32:
362 *Value = AcpiOsIn32 ((ACPI_IO_ADDRESS) Address);
363 break;
364
365 default:
366 DEBUG_PRINT (ACPI_ERROR,
367 ("AmlSystemIoSpaceHandler: Invalid SystemIO width %d\n",
368 BitWidth));
369 Status = AE_AML_OPERAND_VALUE;
370 }
371
372 break;
373
374
375 case ADDRESS_SPACE_WRITE:
376
377 DEBUG_PRINT ((TRACE_OPREGION | VERBOSE_INFO),
378 ("Write(%d width) Address:0x%08x Value 0x%08x\n",
379 BitWidth, Address, *Value));
380
381 switch (BitWidth)
382 {
383 /* I/O Port width */
384 case 8:
385 AcpiOsOut8 ((ACPI_IO_ADDRESS) Address, (UINT8) *Value);
386 break;
387
388 case 16:
389 AcpiOsOut16 ((ACPI_IO_ADDRESS) Address, (UINT16) *Value);
390 break;
391
392 case 32:
393 AcpiOsOut32 ((ACPI_IO_ADDRESS) Address, *Value);
394 break;
395
396 default:
397 DEBUG_PRINT (ACPI_ERROR, (
398 "AmlSystemIoSpaceHandler: Invalid SystemIO width %d\n",
399 BitWidth));
400 Status = AE_AML_OPERAND_VALUE;
401 }
402
403 break;
404
405
406 default:
407 Status = AE_BAD_PARAMETER;
408 break;
409 }
410
411 return_ACPI_STATUS (Status);
412}
413
414/*******************************************************************************
415 *
416 * FUNCTION: AcpiAmlPciConfigSpaceHandler
417 *
418 * PARAMETERS: Function - Read or Write operation
419 * Address - Where in the space to read or write
420 * BitWidth - Field width in bits (8, 16, or 32)
421 * Value - Pointer to in or out value
422 * HandlerContext - Pointer to Handler's context
423 * RegionContext - Pointer to context specific to the
424 * accessed region
425 *
426 * RETURN: Status
427 *
428 * DESCRIPTION: Handler for the PCI Config address space (Op Region)
429 *
430 ******************************************************************************/
431
432ACPI_STATUS
433AcpiAmlPciConfigSpaceHandler (
434 UINT32 Function,
435 ACPI_PHYSICAL_ADDRESS Address,
436 UINT32 BitWidth,
437 UINT32 *Value,
438 void *HandlerContext,
439 void *RegionContext)
440{
441 ACPI_STATUS Status = AE_OK;
442 UINT32 PciBus;
443 UINT32 DevFunc;
444 UINT8 PciReg;
445 PCI_HANDLER_CONTEXT *PCIContext;
446
447
448 FUNCTION_TRACE ("AmlPciConfigSpaceHandler");
449
450 /*
451 * The arguments to AcpiOs(Read|Write)PciCfg(Byte|Word|Dword) are:
452 *
453 * SegBus - 0xSSSSBBBB - SSSS is the PCI bus segment
454 * BBBB is the PCI bus number
455 *
456 * DevFunc - 0xDDDDFFFF - DDDD is the PCI device number
457 * FFFF is the PCI device function number
458 *
459 * RegNum - Config space register must be < 40h
460 *
461 * Value - input value for write, output for read
462 *
463 */
464
465 PCIContext = (PCI_HANDLER_CONTEXT *) RegionContext;
466
467 PciBus = LOWORD(PCIContext->Seg) << 16;
468 PciBus |= LOWORD(PCIContext->Bus);
469
470 DevFunc = PCIContext->DevFunc;
471
472 PciReg = (UINT8) Address;
473
474 switch (Function)
475 {
476
477 case ADDRESS_SPACE_READ:
478
479 DEBUG_PRINT ((TRACE_OPREGION | VERBOSE_INFO),
480 ("R%d S(%04x) B(%04x) DF(%08x) R(%04x)\n", BitWidth,
481 PCIContext->Seg,PCIContext->Bus,PCIContext->DevFunc, PciReg));
482
483 *Value = 0;
484
485 switch (BitWidth)
486 {
487 /* PCI Register width */
488
489 case 8:
490 Status = AcpiOsReadPciCfgByte (PciBus, DevFunc, PciReg,
491 (UINT8 *) Value);
492 break;
493
494 case 16:
495 Status = AcpiOsReadPciCfgWord (PciBus, DevFunc, PciReg,
496 (UINT16 *) Value);
497 break;
498
499 case 32:
500 Status = AcpiOsReadPciCfgDword (PciBus, DevFunc, PciReg,
501 Value);
502 break;
503
504 default:
505 DEBUG_PRINT (ACPI_ERROR,
506 ("AmlPciConfigSpaceHandler: Invalid PCIConfig width %d\n",
507 BitWidth));
508 Status = AE_AML_OPERAND_VALUE;
509
510 } /* Switch bitWidth */
511
512 break;
513
514
515 case ADDRESS_SPACE_WRITE:
516
517 DEBUG_PRINT ((TRACE_OPREGION | VERBOSE_INFO),
518 ("W%d S(%04x) B(%04x) DF(%08x) R(%04x) D(%08x)\n", BitWidth,
519 PCIContext->Seg,PCIContext->Bus,PCIContext->DevFunc,
520 PciReg,*Value));
521
522 switch (BitWidth)
523 {
524 /* PCI Register width */
525
526 case 8:
527 Status = AcpiOsWritePciCfgByte (PciBus, DevFunc, PciReg,
528 *(UINT8 *) Value);
529 break;
530
531 case 16:
532 Status = AcpiOsWritePciCfgWord (PciBus, DevFunc, PciReg,
533 *(UINT16 *) Value);
534 break;
535
536 case 32:
537 Status = AcpiOsWritePciCfgDword (PciBus, DevFunc, PciReg,
538 *Value);
539 break;
540
541 default:
542 DEBUG_PRINT (ACPI_ERROR, (
543 "AmlPciConfigSpaceHandler: Invalid PCIConfig width %d\n",
544 BitWidth));
545 Status = AE_AML_OPERAND_VALUE;
546
547 } /* Switch bitWidth */
548
549 break;
550
551
552 default:
553
554 Status = AE_BAD_PARAMETER;
555 break;
556
557 }
558
559 return_ACPI_STATUS (Status);
560}
561