]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/contrib/dev/acpica/exregion.c
This commit was generated by cvs2svn to compensate for changes in r165071,
[FreeBSD/FreeBSD.git] / sys / contrib / dev / acpica / exregion.c
1
2 /******************************************************************************
3  *
4  * Module Name: exregion - ACPI default OpRegion (address space) handlers
5  *              $Revision: 1.91 $
6  *
7  *****************************************************************************/
8
9 /******************************************************************************
10  *
11  * 1. Copyright Notice
12  *
13  * Some or all of this work - Copyright (c) 1999 - 2005, Intel Corp.
14  * All rights 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 __EXREGION_C__
120
121 #include <contrib/dev/acpica/acpi.h>
122 #include <contrib/dev/acpica/acinterp.h>
123
124
125 #define _COMPONENT          ACPI_EXECUTER
126         ACPI_MODULE_NAME    ("exregion")
127
128
129 /*******************************************************************************
130  *
131  * FUNCTION:    AcpiExSystemMemorySpaceHandler
132  *
133  * PARAMETERS:  Function            - Read or Write operation
134  *              Address             - Where in the space to read or write
135  *              BitWidth            - Field width in bits (8, 16, or 32)
136  *              Value               - Pointer to in or out value
137  *              HandlerContext      - Pointer to Handler's context
138  *              RegionContext       - Pointer to context specific to the
139  *                                    accessed region
140  *
141  * RETURN:      Status
142  *
143  * DESCRIPTION: Handler for the System Memory address space (Op Region)
144  *
145  ******************************************************************************/
146
147 ACPI_STATUS
148 AcpiExSystemMemorySpaceHandler (
149     UINT32                  Function,
150     ACPI_PHYSICAL_ADDRESS   Address,
151     UINT32                  BitWidth,
152     ACPI_INTEGER            *Value,
153     void                    *HandlerContext,
154     void                    *RegionContext)
155 {
156     ACPI_STATUS             Status = AE_OK;
157     void                    *LogicalAddrPtr = NULL;
158     ACPI_MEM_SPACE_CONTEXT  *MemInfo = RegionContext;
159     UINT32                  Length;
160     ACPI_SIZE               WindowSize;
161 #ifdef ACPI_MISALIGNMENT_NOT_SUPPORTED
162     UINT32                  Remainder;
163 #endif
164
165     ACPI_FUNCTION_TRACE ("ExSystemMemorySpaceHandler");
166
167
168     /* Validate and translate the bit width */
169
170     switch (BitWidth)
171     {
172     case 8:
173         Length = 1;
174         break;
175
176     case 16:
177         Length = 2;
178         break;
179
180     case 32:
181         Length = 4;
182         break;
183
184     case 64:
185         Length = 8;
186         break;
187
188     default:
189         ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Invalid SystemMemory width %d\n",
190             BitWidth));
191         return_ACPI_STATUS (AE_AML_OPERAND_VALUE);
192     }
193
194 #ifdef ACPI_MISALIGNMENT_NOT_SUPPORTED
195     /*
196      * Hardware does not support non-aligned data transfers, we must verify
197      * the request.
198      */
199     (void) AcpiUtShortDivide ((ACPI_INTEGER) Address, Length, NULL, &Remainder);
200     if (Remainder != 0)
201     {
202         return_ACPI_STATUS (AE_AML_ALIGNMENT);
203     }
204 #endif
205
206     /*
207      * Does the request fit into the cached memory mapping?
208      * Is 1) Address below the current mapping? OR
209      *    2) Address beyond the current mapping?
210      */
211     if ((Address < MemInfo->MappedPhysicalAddress) ||
212         (((ACPI_INTEGER) Address + Length) >
213             ((ACPI_INTEGER)
214             MemInfo->MappedPhysicalAddress + MemInfo->MappedLength)))
215     {
216         /*
217          * The request cannot be resolved by the current memory mapping;
218          * Delete the existing mapping and create a new one.
219          */
220         if (MemInfo->MappedLength)
221         {
222             /* Valid mapping, delete it */
223
224             AcpiOsUnmapMemory (MemInfo->MappedLogicalAddress,
225                                 MemInfo->MappedLength);
226         }
227
228         /*
229          * Don't attempt to map memory beyond the end of the region, and
230          * constrain the maximum mapping size to something reasonable.
231          */
232         WindowSize = (ACPI_SIZE)
233             ((MemInfo->Address + MemInfo->Length) - Address);
234
235         if (WindowSize > ACPI_SYSMEM_REGION_WINDOW_SIZE)
236         {
237             WindowSize = ACPI_SYSMEM_REGION_WINDOW_SIZE;
238         }
239
240         /* Create a new mapping starting at the address given */
241
242         Status = AcpiOsMapMemory (Address, WindowSize,
243                                     (void **) &MemInfo->MappedLogicalAddress);
244         if (ACPI_FAILURE (Status))
245         {
246             ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
247                 "Could not map memory at %8.8X%8.8X, size %X\n",
248                 ACPI_FORMAT_UINT64 (Address), (UINT32) WindowSize));
249             MemInfo->MappedLength = 0;
250             return_ACPI_STATUS (Status);
251         }
252
253         /* Save the physical address and mapping size */
254
255         MemInfo->MappedPhysicalAddress = Address;
256         MemInfo->MappedLength = WindowSize;
257     }
258
259     /*
260      * Generate a logical pointer corresponding to the address we want to
261      * access
262      */
263     LogicalAddrPtr = MemInfo->MappedLogicalAddress +
264                      ((ACPI_INTEGER) Address -
265                       (ACPI_INTEGER) MemInfo->MappedPhysicalAddress);
266
267     ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
268             "SystemMemory %d (%d width) Address=%8.8X%8.8X\n",
269             Function, BitWidth,
270             ACPI_FORMAT_UINT64 (Address)));
271
272    /*
273     * Perform the memory read or write
274     *
275     * Note: For machines that do not support non-aligned transfers, the target
276     * address was checked for alignment above.  We do not attempt to break the
277     * transfer up into smaller (byte-size) chunks because the AML specifically
278     * asked for a transfer width that the hardware may require.
279     */
280     switch (Function)
281     {
282     case ACPI_READ:
283
284         *Value = 0;
285         switch (BitWidth)
286         {
287         case 8:
288             *Value = (ACPI_INTEGER) *((UINT8 *) LogicalAddrPtr);
289             break;
290
291         case 16:
292             *Value = (ACPI_INTEGER) *((UINT16 *) LogicalAddrPtr);
293             break;
294
295         case 32:
296             *Value = (ACPI_INTEGER) *((UINT32 *) LogicalAddrPtr);
297             break;
298
299 #if ACPI_MACHINE_WIDTH != 16
300         case 64:
301             *Value = (ACPI_INTEGER) *((UINT64 *) LogicalAddrPtr);
302             break;
303 #endif
304         default:
305             /* BitWidth was already validated */
306             break;
307         }
308         break;
309
310     case ACPI_WRITE:
311
312         switch (BitWidth)
313         {
314         case 8:
315             *(UINT8 *) LogicalAddrPtr = (UINT8) *Value;
316             break;
317
318         case 16:
319             *(UINT16 *) LogicalAddrPtr = (UINT16) *Value;
320             break;
321
322         case 32:
323             *(UINT32 *) LogicalAddrPtr = (UINT32) *Value;
324             break;
325
326 #if ACPI_MACHINE_WIDTH != 16
327         case 64:
328             *(UINT64 *) LogicalAddrPtr = (UINT64) *Value;
329             break;
330 #endif
331
332         default:
333             /* BitWidth was already validated */
334             break;
335         }
336         break;
337
338     default:
339         Status = AE_BAD_PARAMETER;
340         break;
341     }
342
343     return_ACPI_STATUS (Status);
344 }
345
346
347 /*******************************************************************************
348  *
349  * FUNCTION:    AcpiExSystemIoSpaceHandler
350  *
351  * PARAMETERS:  Function            - Read or Write operation
352  *              Address             - Where in the space to read or write
353  *              BitWidth            - Field width in bits (8, 16, or 32)
354  *              Value               - Pointer to in or out value
355  *              HandlerContext      - Pointer to Handler's context
356  *              RegionContext       - Pointer to context specific to the
357  *                                    accessed region
358  *
359  * RETURN:      Status
360  *
361  * DESCRIPTION: Handler for the System IO address space (Op Region)
362  *
363  ******************************************************************************/
364
365 ACPI_STATUS
366 AcpiExSystemIoSpaceHandler (
367     UINT32                  Function,
368     ACPI_PHYSICAL_ADDRESS   Address,
369     UINT32                  BitWidth,
370     ACPI_INTEGER            *Value,
371     void                    *HandlerContext,
372     void                    *RegionContext)
373 {
374     ACPI_STATUS             Status = AE_OK;
375     UINT32                  Value32;
376
377
378     ACPI_FUNCTION_TRACE ("ExSystemIoSpaceHandler");
379
380
381     ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
382             "SystemIO %d (%d width) Address=%8.8X%8.8X\n", Function, BitWidth,
383             ACPI_FORMAT_UINT64 (Address)));
384
385     /* Decode the function parameter */
386
387     switch (Function)
388     {
389     case ACPI_READ:
390
391         Status = AcpiOsReadPort ((ACPI_IO_ADDRESS) Address,
392                     &Value32, BitWidth);
393         *Value = Value32;
394         break;
395
396     case ACPI_WRITE:
397
398         Status = AcpiOsWritePort ((ACPI_IO_ADDRESS) Address,
399                     (UINT32) *Value, BitWidth);
400         break;
401
402     default:
403         Status = AE_BAD_PARAMETER;
404         break;
405     }
406
407     return_ACPI_STATUS (Status);
408 }
409
410
411 /*******************************************************************************
412  *
413  * FUNCTION:    AcpiExPciConfigSpaceHandler
414  *
415  * PARAMETERS:  Function            - Read or Write operation
416  *              Address             - Where in the space to read or write
417  *              BitWidth            - Field width in bits (8, 16, or 32)
418  *              Value               - Pointer to in or out value
419  *              HandlerContext      - Pointer to Handler's context
420  *              RegionContext       - Pointer to context specific to the
421  *                                    accessed region
422  *
423  * RETURN:      Status
424  *
425  * DESCRIPTION: Handler for the PCI Config address space (Op Region)
426  *
427  ******************************************************************************/
428
429 ACPI_STATUS
430 AcpiExPciConfigSpaceHandler (
431     UINT32                  Function,
432     ACPI_PHYSICAL_ADDRESS   Address,
433     UINT32                  BitWidth,
434     ACPI_INTEGER            *Value,
435     void                    *HandlerContext,
436     void                    *RegionContext)
437 {
438     ACPI_STATUS             Status = AE_OK;
439     ACPI_PCI_ID             *PciId;
440     UINT16                  PciRegister;
441
442
443     ACPI_FUNCTION_TRACE ("ExPciConfigSpaceHandler");
444
445
446     /*
447      *  The arguments to AcpiOs(Read|Write)PciConfiguration are:
448      *
449      *  PciSegment  is the PCI bus segment range 0-31
450      *  PciBus      is the PCI bus number range 0-255
451      *  PciDevice   is the PCI device number range 0-31
452      *  PciFunction is the PCI device function number
453      *  PciRegister is the Config space register range 0-255 bytes
454      *
455      *  Value - input value for write, output address for read
456      *
457      */
458     PciId       = (ACPI_PCI_ID *) RegionContext;
459     PciRegister = (UINT16) (UINT32) Address;
460
461     ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
462         "PciConfig %d (%d) Seg(%04x) Bus(%04x) Dev(%04x) Func(%04x) Reg(%04x)\n",
463         Function, BitWidth, PciId->Segment, PciId->Bus, PciId->Device,
464         PciId->Function, PciRegister));
465
466     switch (Function)
467     {
468     case ACPI_READ:
469
470         *Value = 0;
471         Status = AcpiOsReadPciConfiguration (PciId, PciRegister,
472                     Value, BitWidth);
473         break;
474
475     case ACPI_WRITE:
476
477         Status = AcpiOsWritePciConfiguration (PciId, PciRegister,
478                     *Value, BitWidth);
479         break;
480
481     default:
482
483         Status = AE_BAD_PARAMETER;
484         break;
485     }
486
487     return_ACPI_STATUS (Status);
488 }
489
490
491 /*******************************************************************************
492  *
493  * FUNCTION:    AcpiExCmosSpaceHandler
494  *
495  * PARAMETERS:  Function            - Read or Write operation
496  *              Address             - Where in the space to read or write
497  *              BitWidth            - Field width in bits (8, 16, or 32)
498  *              Value               - Pointer to in or out value
499  *              HandlerContext      - Pointer to Handler's context
500  *              RegionContext       - Pointer to context specific to the
501  *                                    accessed region
502  *
503  * RETURN:      Status
504  *
505  * DESCRIPTION: Handler for the CMOS address space (Op Region)
506  *
507  ******************************************************************************/
508
509 ACPI_STATUS
510 AcpiExCmosSpaceHandler (
511     UINT32                  Function,
512     ACPI_PHYSICAL_ADDRESS   Address,
513     UINT32                  BitWidth,
514     ACPI_INTEGER            *Value,
515     void                    *HandlerContext,
516     void                    *RegionContext)
517 {
518     ACPI_STATUS             Status = AE_OK;
519
520
521     ACPI_FUNCTION_TRACE ("ExCmosSpaceHandler");
522
523
524     return_ACPI_STATUS (Status);
525 }
526
527
528 /*******************************************************************************
529  *
530  * FUNCTION:    AcpiExPciBarSpaceHandler
531  *
532  * PARAMETERS:  Function            - Read or Write operation
533  *              Address             - Where in the space to read or write
534  *              BitWidth            - Field width in bits (8, 16, or 32)
535  *              Value               - Pointer to in or out value
536  *              HandlerContext      - Pointer to Handler's context
537  *              RegionContext       - Pointer to context specific to the
538  *                                    accessed region
539  *
540  * RETURN:      Status
541  *
542  * DESCRIPTION: Handler for the PCI BarTarget address space (Op Region)
543  *
544  ******************************************************************************/
545
546 ACPI_STATUS
547 AcpiExPciBarSpaceHandler (
548     UINT32                  Function,
549     ACPI_PHYSICAL_ADDRESS   Address,
550     UINT32                  BitWidth,
551     ACPI_INTEGER            *Value,
552     void                    *HandlerContext,
553     void                    *RegionContext)
554 {
555     ACPI_STATUS             Status = AE_OK;
556
557
558     ACPI_FUNCTION_TRACE ("ExPciBarSpaceHandler");
559
560
561     return_ACPI_STATUS (Status);
562 }
563
564
565 /*******************************************************************************
566  *
567  * FUNCTION:    AcpiExDataTableSpaceHandler
568  *
569  * PARAMETERS:  Function            - Read or Write operation
570  *              Address             - Where in the space to read or write
571  *              BitWidth            - Field width in bits (8, 16, or 32)
572  *              Value               - Pointer to in or out value
573  *              HandlerContext      - Pointer to Handler's context
574  *              RegionContext       - Pointer to context specific to the
575  *                                    accessed region
576  *
577  * RETURN:      Status
578  *
579  * DESCRIPTION: Handler for the Data Table address space (Op Region)
580  *
581  ******************************************************************************/
582
583 ACPI_STATUS
584 AcpiExDataTableSpaceHandler (
585     UINT32                  Function,
586     ACPI_PHYSICAL_ADDRESS   Address,
587     UINT32                  BitWidth,
588     ACPI_INTEGER            *Value,
589     void                    *HandlerContext,
590     void                    *RegionContext)
591 {
592     ACPI_STATUS             Status = AE_OK;
593     UINT32                  ByteWidth = ACPI_DIV_8 (BitWidth);
594     UINT32                  i;
595     char                    *LogicalAddrPtr;
596
597
598     ACPI_FUNCTION_TRACE ("ExDataTableSpaceHandler");
599
600
601     LogicalAddrPtr = ACPI_PHYSADDR_TO_PTR (Address);
602
603     /* Perform the memory read or write */
604
605     switch (Function)
606     {
607     case ACPI_READ:
608
609         for (i = 0; i < ByteWidth; i++)
610         {
611             ((char *) Value) [i] = LogicalAddrPtr[i];
612         }
613         break;
614
615     case ACPI_WRITE:
616     default:
617
618         return_ACPI_STATUS (AE_SUPPORT);
619     }
620
621     return_ACPI_STATUS (Status);
622 }
623
624