xref: /titanic_41/usr/src/uts/intel/io/acpica/executer/exregion.c (revision 49d3bc91e27cd871b950d56c01398fa2f2e12ab4)
1 
2 /******************************************************************************
3  *
4  * Module Name: exregion - ACPI default OpRegion (address space) handlers
5  *
6  *****************************************************************************/
7 
8 /******************************************************************************
9  *
10  * 1. Copyright Notice
11  *
12  * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
13  * All rights reserved.
14  *
15  * 2. License
16  *
17  * 2.1. This is your license from Intel Corp. under its intellectual property
18  * rights.  You may have additional license terms from the party that provided
19  * you this software, covering your right to use that party's intellectual
20  * property rights.
21  *
22  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23  * copy of the source code appearing in this file ("Covered Code") an
24  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25  * base code distributed originally by Intel ("Original Intel Code") to copy,
26  * make derivatives, distribute, use and display any portion of the Covered
27  * Code in any form, with the right to sublicense such rights; and
28  *
29  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30  * license (with the right to sublicense), under only those claims of Intel
31  * patents that are infringed by the Original Intel Code, to make, use, sell,
32  * offer to sell, and import the Covered Code and derivative works thereof
33  * solely to the minimum extent necessary to exercise the above copyright
34  * license, and in no event shall the patent license extend to any additions
35  * to or modifications of the Original Intel Code.  No other license or right
36  * is granted directly or by implication, estoppel or otherwise;
37  *
38  * The above copyright and patent license is granted only if the following
39  * conditions are met:
40  *
41  * 3. Conditions
42  *
43  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44  * Redistribution of source code of any substantial portion of the Covered
45  * Code or modification with rights to further distribute source must include
46  * the above Copyright Notice, the above License, this list of Conditions,
47  * and the following Disclaimer and Export Compliance provision.  In addition,
48  * Licensee must cause all Covered Code to which Licensee contributes to
49  * contain a file documenting the changes Licensee made to create that Covered
50  * Code and the date of any change.  Licensee must include in that file the
51  * documentation of any changes made by any predecessor Licensee.  Licensee
52  * must include a prominent statement that the modification is derived,
53  * directly or indirectly, from Original Intel Code.
54  *
55  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56  * Redistribution of source code of any substantial portion of the Covered
57  * Code or modification without rights to further distribute source must
58  * include the following Disclaimer and Export Compliance provision in the
59  * documentation and/or other materials provided with distribution.  In
60  * addition, Licensee may not authorize further sublicense of source of any
61  * portion of the Covered Code, and must include terms to the effect that the
62  * license from Licensee to its licensee is limited to the intellectual
63  * property embodied in the software Licensee provides to its licensee, and
64  * not to intellectual property embodied in modifications its licensee may
65  * make.
66  *
67  * 3.3. Redistribution of Executable. Redistribution in executable form of any
68  * substantial portion of the Covered Code or modification must reproduce the
69  * above Copyright Notice, and the following Disclaimer and Export Compliance
70  * provision in the documentation and/or other materials provided with the
71  * distribution.
72  *
73  * 3.4. Intel retains all right, title, and interest in and to the Original
74  * Intel Code.
75  *
76  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77  * Intel shall be used in advertising or otherwise to promote the sale, use or
78  * other dealings in products derived from or relating to the Covered Code
79  * without prior written authorization from Intel.
80  *
81  * 4. Disclaimer and Export Compliance
82  *
83  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
86  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
87  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
88  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89  * PARTICULAR PURPOSE.
90  *
91  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
97  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98  * LIMITED REMEDY.
99  *
100  * 4.3. Licensee shall not export, either directly or indirectly, any of this
101  * software or system incorporating such software without first obtaining any
102  * required license or other approval from the U. S. Department of Commerce or
103  * any other agency or department of the United States Government.  In the
104  * event Licensee exports any such software from the United States or
105  * re-exports any such software from a foreign destination, Licensee shall
106  * ensure that the distribution and export/re-export of the software is in
107  * compliance with all laws, regulations, orders, or other restrictions of the
108  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109  * any of its subsidiaries will export/re-export any technical data, process,
110  * software, or service, directly or indirectly, to any country for which the
111  * United States government or any agency thereof requires an export license,
112  * other governmental approval, or letter of assurance, without first obtaining
113  * such license, approval or letter.
114  *
115  *****************************************************************************/
116 
117 
118 #define __EXREGION_C__
119 
120 #include "acpi.h"
121 #include "accommon.h"
122 #include "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               MapLength;
161     ACPI_SIZE               PageBoundaryMapLength;
162 #ifdef ACPI_MISALIGNMENT_NOT_SUPPORTED
163     UINT32                  Remainder;
164 #endif
165 
166 
167     ACPI_FUNCTION_TRACE (ExSystemMemorySpaceHandler);
168 
169 
170     /* Validate and translate the bit width */
171 
172     switch (BitWidth)
173     {
174     case 8:
175         Length = 1;
176         break;
177 
178     case 16:
179         Length = 2;
180         break;
181 
182     case 32:
183         Length = 4;
184         break;
185 
186     case 64:
187         Length = 8;
188         break;
189 
190     default:
191         ACPI_ERROR ((AE_INFO, "Invalid SystemMemory width %d",
192             BitWidth));
193         return_ACPI_STATUS (AE_AML_OPERAND_VALUE);
194     }
195 
196 #ifdef ACPI_MISALIGNMENT_NOT_SUPPORTED
197     /*
198      * Hardware does not support non-aligned data transfers, we must verify
199      * the request.
200      */
201     (void) AcpiUtShortDivide ((ACPI_INTEGER) Address, Length, NULL, &Remainder);
202     if (Remainder != 0)
203     {
204         return_ACPI_STATUS (AE_AML_ALIGNMENT);
205     }
206 #endif
207 
208     /*
209      * Does the request fit into the cached memory mapping?
210      * Is 1) Address below the current mapping? OR
211      *    2) Address beyond the current mapping?
212      */
213     if ((Address < MemInfo->MappedPhysicalAddress) ||
214         (((ACPI_INTEGER) Address + Length) >
215             ((ACPI_INTEGER)
216             MemInfo->MappedPhysicalAddress + MemInfo->MappedLength)))
217     {
218         /*
219          * The request cannot be resolved by the current memory mapping;
220          * Delete the existing mapping and create a new one.
221          */
222         if (MemInfo->MappedLength)
223         {
224             /* Valid mapping, delete it */
225 
226             AcpiOsUnmapMemory (MemInfo->MappedLogicalAddress,
227                 MemInfo->MappedLength);
228         }
229 
230         /*
231          * October 2009: Attempt to map from the requested address to the
232          * end of the region. However, we will never map more than one
233          * page, nor will we cross a page boundary.
234          */
235         MapLength = (ACPI_SIZE)
236             ((MemInfo->Address + MemInfo->Length) - Address);
237 
238         /*
239          * If mapping the entire remaining portion of the region will cross
240          * a page boundary, just map up to the page boundary, do not cross.
241          * On some systems, crossing a page boundary while mapping regions
242          * can cause warnings if the pages have different attributes
243          * due to resource management.
244          *
245          * This has the added benefit of constraining a single mapping to
246          * one page, which is similar to the original code that used a 4k
247          * maximum window.
248          */
249         PageBoundaryMapLength =
250             ACPI_ROUND_UP (Address, ACPI_DEFAULT_PAGE_SIZE) - Address;
251         if (PageBoundaryMapLength == 0)
252         {
253             PageBoundaryMapLength = ACPI_DEFAULT_PAGE_SIZE;
254         }
255 
256         if (MapLength > PageBoundaryMapLength)
257         {
258             MapLength = PageBoundaryMapLength;
259         }
260 
261         /* Create a new mapping starting at the address given */
262 
263         MemInfo->MappedLogicalAddress = AcpiOsMapMemory (
264             (ACPI_PHYSICAL_ADDRESS) Address, MapLength);
265         if (!MemInfo->MappedLogicalAddress)
266         {
267             ACPI_ERROR ((AE_INFO,
268                 "Could not map memory at %8.8X%8.8X, size %X",
269                 ACPI_FORMAT_NATIVE_UINT (Address), (UINT32) MapLength));
270             MemInfo->MappedLength = 0;
271             return_ACPI_STATUS (AE_NO_MEMORY);
272         }
273 
274         /* Save the physical address and mapping size */
275 
276         MemInfo->MappedPhysicalAddress = Address;
277         MemInfo->MappedLength = MapLength;
278     }
279 
280     /*
281      * Generate a logical pointer corresponding to the address we want to
282      * access
283      */
284     LogicalAddrPtr = MemInfo->MappedLogicalAddress +
285         ((ACPI_INTEGER) Address - (ACPI_INTEGER) MemInfo->MappedPhysicalAddress);
286 
287     ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
288         "System-Memory (width %d) R/W %d Address=%8.8X%8.8X\n",
289         BitWidth, Function, ACPI_FORMAT_NATIVE_UINT (Address)));
290 
291     /*
292      * Perform the memory read or write
293      *
294      * Note: For machines that do not support non-aligned transfers, the target
295      * address was checked for alignment above.  We do not attempt to break the
296      * transfer up into smaller (byte-size) chunks because the AML specifically
297      * asked for a transfer width that the hardware may require.
298      */
299     switch (Function)
300     {
301     case ACPI_READ:
302 
303         *Value = 0;
304         switch (BitWidth)
305         {
306         case 8:
307             *Value = (ACPI_INTEGER) ACPI_GET8 (LogicalAddrPtr);
308             break;
309 
310         case 16:
311             *Value = (ACPI_INTEGER) ACPI_GET16 (LogicalAddrPtr);
312             break;
313 
314         case 32:
315             *Value = (ACPI_INTEGER) ACPI_GET32 (LogicalAddrPtr);
316             break;
317 
318         case 64:
319             *Value = (ACPI_INTEGER) ACPI_GET64 (LogicalAddrPtr);
320             break;
321 
322         default:
323             /* BitWidth was already validated */
324             break;
325         }
326         break;
327 
328     case ACPI_WRITE:
329 
330         switch (BitWidth)
331         {
332         case 8:
333             ACPI_SET8 (LogicalAddrPtr) = (UINT8) *Value;
334             break;
335 
336         case 16:
337             ACPI_SET16 (LogicalAddrPtr) = (UINT16) *Value;
338             break;
339 
340         case 32:
341             ACPI_SET32 ( LogicalAddrPtr) = (UINT32) *Value;
342             break;
343 
344         case 64:
345             ACPI_SET64 (LogicalAddrPtr) = (UINT64) *Value;
346             break;
347 
348         default:
349             /* BitWidth was already validated */
350             break;
351         }
352         break;
353 
354     default:
355         Status = AE_BAD_PARAMETER;
356         break;
357     }
358 
359     return_ACPI_STATUS (Status);
360 }
361 
362 
363 /*******************************************************************************
364  *
365  * FUNCTION:    AcpiExSystemIoSpaceHandler
366  *
367  * PARAMETERS:  Function            - Read or Write operation
368  *              Address             - Where in the space to read or write
369  *              BitWidth            - Field width in bits (8, 16, or 32)
370  *              Value               - Pointer to in or out value
371  *              HandlerContext      - Pointer to Handler's context
372  *              RegionContext       - Pointer to context specific to the
373  *                                    accessed region
374  *
375  * RETURN:      Status
376  *
377  * DESCRIPTION: Handler for the System IO address space (Op Region)
378  *
379  ******************************************************************************/
380 
381 ACPI_STATUS
382 AcpiExSystemIoSpaceHandler (
383     UINT32                  Function,
384     ACPI_PHYSICAL_ADDRESS   Address,
385     UINT32                  BitWidth,
386     ACPI_INTEGER            *Value,
387     void                    *HandlerContext,
388     void                    *RegionContext)
389 {
390     ACPI_STATUS             Status = AE_OK;
391     UINT32                  Value32;
392 
393 
394     ACPI_FUNCTION_TRACE (ExSystemIoSpaceHandler);
395 
396 
397     ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
398         "System-IO (width %d) R/W %d Address=%8.8X%8.8X\n",
399         BitWidth, Function, ACPI_FORMAT_NATIVE_UINT (Address)));
400 
401     /* Decode the function parameter */
402 
403     switch (Function)
404     {
405     case ACPI_READ:
406 
407         Status = AcpiHwReadPort ((ACPI_IO_ADDRESS) Address,
408                     &Value32, BitWidth);
409         *Value = Value32;
410         break;
411 
412     case ACPI_WRITE:
413 
414         Status = AcpiHwWritePort ((ACPI_IO_ADDRESS) Address,
415                     (UINT32) *Value, BitWidth);
416         break;
417 
418     default:
419         Status = AE_BAD_PARAMETER;
420         break;
421     }
422 
423     return_ACPI_STATUS (Status);
424 }
425 
426 
427 /*******************************************************************************
428  *
429  * FUNCTION:    AcpiExPciConfigSpaceHandler
430  *
431  * PARAMETERS:  Function            - Read or Write operation
432  *              Address             - Where in the space to read or write
433  *              BitWidth            - Field width in bits (8, 16, or 32)
434  *              Value               - Pointer to in or out value
435  *              HandlerContext      - Pointer to Handler's context
436  *              RegionContext       - Pointer to context specific to the
437  *                                    accessed region
438  *
439  * RETURN:      Status
440  *
441  * DESCRIPTION: Handler for the PCI Config address space (Op Region)
442  *
443  ******************************************************************************/
444 
445 ACPI_STATUS
446 AcpiExPciConfigSpaceHandler (
447     UINT32                  Function,
448     ACPI_PHYSICAL_ADDRESS   Address,
449     UINT32                  BitWidth,
450     ACPI_INTEGER            *Value,
451     void                    *HandlerContext,
452     void                    *RegionContext)
453 {
454     ACPI_STATUS             Status = AE_OK;
455     ACPI_PCI_ID             *PciId;
456     UINT16                  PciRegister;
457 
458 
459     ACPI_FUNCTION_TRACE (ExPciConfigSpaceHandler);
460 
461 
462     /*
463      *  The arguments to AcpiOs(Read|Write)PciConfiguration are:
464      *
465      *  PciSegment  is the PCI bus segment range 0-31
466      *  PciBus      is the PCI bus number range 0-255
467      *  PciDevice   is the PCI device number range 0-31
468      *  PciFunction is the PCI device function number
469      *  PciRegister is the Config space register range 0-255 bytes
470      *
471      *  Value - input value for write, output address for read
472      *
473      */
474     PciId       = (ACPI_PCI_ID *) RegionContext;
475     PciRegister = (UINT16) (UINT32) Address;
476 
477     ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
478         "Pci-Config %d (%d) Seg(%04x) Bus(%04x) Dev(%04x) Func(%04x) Reg(%04x)\n",
479         Function, BitWidth, PciId->Segment, PciId->Bus, PciId->Device,
480         PciId->Function, PciRegister));
481 
482     switch (Function)
483     {
484     case ACPI_READ:
485 
486         *Value = 0;
487         Status = AcpiOsReadPciConfiguration (PciId, PciRegister,
488                     Value, BitWidth);
489         break;
490 
491     case ACPI_WRITE:
492 
493         Status = AcpiOsWritePciConfiguration (PciId, PciRegister,
494                     *Value, BitWidth);
495         break;
496 
497     default:
498 
499         Status = AE_BAD_PARAMETER;
500         break;
501     }
502 
503     return_ACPI_STATUS (Status);
504 }
505 
506 
507 /*******************************************************************************
508  *
509  * FUNCTION:    AcpiExCmosSpaceHandler
510  *
511  * PARAMETERS:  Function            - Read or Write operation
512  *              Address             - Where in the space to read or write
513  *              BitWidth            - Field width in bits (8, 16, or 32)
514  *              Value               - Pointer to in or out value
515  *              HandlerContext      - Pointer to Handler's context
516  *              RegionContext       - Pointer to context specific to the
517  *                                    accessed region
518  *
519  * RETURN:      Status
520  *
521  * DESCRIPTION: Handler for the CMOS address space (Op Region)
522  *
523  ******************************************************************************/
524 
525 ACPI_STATUS
526 AcpiExCmosSpaceHandler (
527     UINT32                  Function,
528     ACPI_PHYSICAL_ADDRESS   Address,
529     UINT32                  BitWidth,
530     ACPI_INTEGER            *Value,
531     void                    *HandlerContext,
532     void                    *RegionContext)
533 {
534     ACPI_STATUS             Status = AE_OK;
535 
536 
537     ACPI_FUNCTION_TRACE (ExCmosSpaceHandler);
538 
539 
540     return_ACPI_STATUS (Status);
541 }
542 
543 
544 /*******************************************************************************
545  *
546  * FUNCTION:    AcpiExPciBarSpaceHandler
547  *
548  * PARAMETERS:  Function            - Read or Write operation
549  *              Address             - Where in the space to read or write
550  *              BitWidth            - Field width in bits (8, 16, or 32)
551  *              Value               - Pointer to in or out value
552  *              HandlerContext      - Pointer to Handler's context
553  *              RegionContext       - Pointer to context specific to the
554  *                                    accessed region
555  *
556  * RETURN:      Status
557  *
558  * DESCRIPTION: Handler for the PCI BarTarget address space (Op Region)
559  *
560  ******************************************************************************/
561 
562 ACPI_STATUS
563 AcpiExPciBarSpaceHandler (
564     UINT32                  Function,
565     ACPI_PHYSICAL_ADDRESS   Address,
566     UINT32                  BitWidth,
567     ACPI_INTEGER            *Value,
568     void                    *HandlerContext,
569     void                    *RegionContext)
570 {
571     ACPI_STATUS             Status = AE_OK;
572 
573 
574     ACPI_FUNCTION_TRACE (ExPciBarSpaceHandler);
575 
576 
577     return_ACPI_STATUS (Status);
578 }
579 
580 
581 /*******************************************************************************
582  *
583  * FUNCTION:    AcpiExDataTableSpaceHandler
584  *
585  * PARAMETERS:  Function            - Read or Write operation
586  *              Address             - Where in the space to read or write
587  *              BitWidth            - Field width in bits (8, 16, or 32)
588  *              Value               - Pointer to in or out value
589  *              HandlerContext      - Pointer to Handler's context
590  *              RegionContext       - Pointer to context specific to the
591  *                                    accessed region
592  *
593  * RETURN:      Status
594  *
595  * DESCRIPTION: Handler for the Data Table address space (Op Region)
596  *
597  ******************************************************************************/
598 
599 ACPI_STATUS
600 AcpiExDataTableSpaceHandler (
601     UINT32                  Function,
602     ACPI_PHYSICAL_ADDRESS   Address,
603     UINT32                  BitWidth,
604     ACPI_INTEGER            *Value,
605     void                    *HandlerContext,
606     void                    *RegionContext)
607 {
608     ACPI_FUNCTION_TRACE (ExDataTableSpaceHandler);
609 
610 
611     /* Perform the memory read or write */
612 
613     switch (Function)
614     {
615     case ACPI_READ:
616 
617         ACPI_MEMCPY (ACPI_CAST_PTR (char, Value), ACPI_PHYSADDR_TO_PTR (Address),
618             ACPI_DIV_8 (BitWidth));
619         break;
620 
621     case ACPI_WRITE:
622     default:
623 
624         return_ACPI_STATUS (AE_SUPPORT);
625     }
626 
627     return_ACPI_STATUS (AE_OK);
628 }
629 
630 
631