xref: /titanic_50/usr/src/uts/intel/io/acpica/executer/exregion.c (revision 385cc6b4ad1792caef3f84eb61eed3f27085801f)
1db2bae30SDana Myers /******************************************************************************
2db2bae30SDana Myers  *
3db2bae30SDana Myers  * Module Name: exregion - ACPI default OpRegion (address space) handlers
4db2bae30SDana Myers  *
5db2bae30SDana Myers  *****************************************************************************/
6db2bae30SDana Myers 
726f3cdf0SGordon Ross /*
8*385cc6b4SJerry Jelinek  * Copyright (C) 2000 - 2016, Intel Corp.
9db2bae30SDana Myers  * All rights reserved.
10db2bae30SDana Myers  *
1126f3cdf0SGordon Ross  * Redistribution and use in source and binary forms, with or without
1226f3cdf0SGordon Ross  * modification, are permitted provided that the following conditions
1326f3cdf0SGordon Ross  * are met:
1426f3cdf0SGordon Ross  * 1. Redistributions of source code must retain the above copyright
1526f3cdf0SGordon Ross  *    notice, this list of conditions, and the following disclaimer,
1626f3cdf0SGordon Ross  *    without modification.
1726f3cdf0SGordon Ross  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
1826f3cdf0SGordon Ross  *    substantially similar to the "NO WARRANTY" disclaimer below
1926f3cdf0SGordon Ross  *    ("Disclaimer") and any redistribution must be conditioned upon
2026f3cdf0SGordon Ross  *    including a substantially similar Disclaimer requirement for further
2126f3cdf0SGordon Ross  *    binary redistribution.
2226f3cdf0SGordon Ross  * 3. Neither the names of the above-listed copyright holders nor the names
2326f3cdf0SGordon Ross  *    of any contributors may be used to endorse or promote products derived
2426f3cdf0SGordon Ross  *    from this software without specific prior written permission.
25db2bae30SDana Myers  *
2626f3cdf0SGordon Ross  * Alternatively, this software may be distributed under the terms of the
2726f3cdf0SGordon Ross  * GNU General Public License ("GPL") version 2 as published by the Free
2826f3cdf0SGordon Ross  * Software Foundation.
29db2bae30SDana Myers  *
3026f3cdf0SGordon Ross  * NO WARRANTY
3126f3cdf0SGordon Ross  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
3226f3cdf0SGordon Ross  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3326f3cdf0SGordon Ross  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
3426f3cdf0SGordon Ross  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3526f3cdf0SGordon Ross  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3626f3cdf0SGordon Ross  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3726f3cdf0SGordon Ross  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3826f3cdf0SGordon Ross  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
3926f3cdf0SGordon Ross  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
4026f3cdf0SGordon Ross  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
4126f3cdf0SGordon Ross  * POSSIBILITY OF SUCH DAMAGES.
4226f3cdf0SGordon Ross  */
43db2bae30SDana Myers 
44db2bae30SDana Myers #include "acpi.h"
45aa2aa9a6SDana Myers #include "accommon.h"
46db2bae30SDana Myers #include "acinterp.h"
47db2bae30SDana Myers 
48db2bae30SDana Myers 
49db2bae30SDana Myers #define _COMPONENT          ACPI_EXECUTER
50db2bae30SDana Myers         ACPI_MODULE_NAME    ("exregion")
51db2bae30SDana Myers 
52db2bae30SDana Myers 
53db2bae30SDana Myers /*******************************************************************************
54db2bae30SDana Myers  *
55db2bae30SDana Myers  * FUNCTION:    AcpiExSystemMemorySpaceHandler
56db2bae30SDana Myers  *
57db2bae30SDana Myers  * PARAMETERS:  Function            - Read or Write operation
58db2bae30SDana Myers  *              Address             - Where in the space to read or write
59db2bae30SDana Myers  *              BitWidth            - Field width in bits (8, 16, or 32)
60db2bae30SDana Myers  *              Value               - Pointer to in or out value
61db2bae30SDana Myers  *              HandlerContext      - Pointer to Handler's context
62db2bae30SDana Myers  *              RegionContext       - Pointer to context specific to the
63db2bae30SDana Myers  *                                    accessed region
64db2bae30SDana Myers  *
65db2bae30SDana Myers  * RETURN:      Status
66db2bae30SDana Myers  *
67db2bae30SDana Myers  * DESCRIPTION: Handler for the System Memory address space (Op Region)
68db2bae30SDana Myers  *
69db2bae30SDana Myers  ******************************************************************************/
70db2bae30SDana Myers 
71db2bae30SDana Myers ACPI_STATUS
AcpiExSystemMemorySpaceHandler(UINT32 Function,ACPI_PHYSICAL_ADDRESS Address,UINT32 BitWidth,UINT64 * Value,void * HandlerContext,void * RegionContext)72db2bae30SDana Myers AcpiExSystemMemorySpaceHandler (
73db2bae30SDana Myers     UINT32                  Function,
74db2bae30SDana Myers     ACPI_PHYSICAL_ADDRESS   Address,
75db2bae30SDana Myers     UINT32                  BitWidth,
7626f3cdf0SGordon Ross     UINT64                  *Value,
77db2bae30SDana Myers     void                    *HandlerContext,
78db2bae30SDana Myers     void                    *RegionContext)
79db2bae30SDana Myers {
80db2bae30SDana Myers     ACPI_STATUS             Status = AE_OK;
81db2bae30SDana Myers     void                    *LogicalAddrPtr = NULL;
82db2bae30SDana Myers     ACPI_MEM_SPACE_CONTEXT  *MemInfo = RegionContext;
83db2bae30SDana Myers     UINT32                  Length;
8457190917SDana Myers     ACPI_SIZE               MapLength;
8557190917SDana Myers     ACPI_SIZE               PageBoundaryMapLength;
86db2bae30SDana Myers #ifdef ACPI_MISALIGNMENT_NOT_SUPPORTED
87db2bae30SDana Myers     UINT32                  Remainder;
88db2bae30SDana Myers #endif
89db2bae30SDana Myers 
90db2bae30SDana Myers 
91db2bae30SDana Myers     ACPI_FUNCTION_TRACE (ExSystemMemorySpaceHandler);
92db2bae30SDana Myers 
93db2bae30SDana Myers 
94db2bae30SDana Myers     /* Validate and translate the bit width */
95db2bae30SDana Myers 
96db2bae30SDana Myers     switch (BitWidth)
97db2bae30SDana Myers     {
98db2bae30SDana Myers     case 8:
99*385cc6b4SJerry Jelinek 
100db2bae30SDana Myers         Length = 1;
101db2bae30SDana Myers         break;
102db2bae30SDana Myers 
103db2bae30SDana Myers     case 16:
104*385cc6b4SJerry Jelinek 
105db2bae30SDana Myers         Length = 2;
106db2bae30SDana Myers         break;
107db2bae30SDana Myers 
108db2bae30SDana Myers     case 32:
109*385cc6b4SJerry Jelinek 
110db2bae30SDana Myers         Length = 4;
111db2bae30SDana Myers         break;
112db2bae30SDana Myers 
113db2bae30SDana Myers     case 64:
114*385cc6b4SJerry Jelinek 
115db2bae30SDana Myers         Length = 8;
116db2bae30SDana Myers         break;
117db2bae30SDana Myers 
118db2bae30SDana Myers     default:
119*385cc6b4SJerry Jelinek 
12026f3cdf0SGordon Ross         ACPI_ERROR ((AE_INFO, "Invalid SystemMemory width %u",
121db2bae30SDana Myers             BitWidth));
122db2bae30SDana Myers         return_ACPI_STATUS (AE_AML_OPERAND_VALUE);
123db2bae30SDana Myers     }
124db2bae30SDana Myers 
125db2bae30SDana Myers #ifdef ACPI_MISALIGNMENT_NOT_SUPPORTED
126db2bae30SDana Myers     /*
127db2bae30SDana Myers      * Hardware does not support non-aligned data transfers, we must verify
128db2bae30SDana Myers      * the request.
129db2bae30SDana Myers      */
13026f3cdf0SGordon Ross     (void) AcpiUtShortDivide ((UINT64) Address, Length, NULL, &Remainder);
131db2bae30SDana Myers     if (Remainder != 0)
132db2bae30SDana Myers     {
133db2bae30SDana Myers         return_ACPI_STATUS (AE_AML_ALIGNMENT);
134db2bae30SDana Myers     }
135db2bae30SDana Myers #endif
136db2bae30SDana Myers 
137db2bae30SDana Myers     /*
138db2bae30SDana Myers      * Does the request fit into the cached memory mapping?
139db2bae30SDana Myers      * Is 1) Address below the current mapping? OR
140db2bae30SDana Myers      *    2) Address beyond the current mapping?
141db2bae30SDana Myers      */
142db2bae30SDana Myers     if ((Address < MemInfo->MappedPhysicalAddress) ||
14326f3cdf0SGordon Ross         (((UINT64) Address + Length) >
14426f3cdf0SGordon Ross             ((UINT64)
145db2bae30SDana Myers             MemInfo->MappedPhysicalAddress + MemInfo->MappedLength)))
146db2bae30SDana Myers     {
147db2bae30SDana Myers         /*
148db2bae30SDana Myers          * The request cannot be resolved by the current memory mapping;
149db2bae30SDana Myers          * Delete the existing mapping and create a new one.
150db2bae30SDana Myers          */
151db2bae30SDana Myers         if (MemInfo->MappedLength)
152db2bae30SDana Myers         {
153db2bae30SDana Myers             /* Valid mapping, delete it */
154db2bae30SDana Myers 
155db2bae30SDana Myers             AcpiOsUnmapMemory (MemInfo->MappedLogicalAddress,
156db2bae30SDana Myers                 MemInfo->MappedLength);
157db2bae30SDana Myers         }
158db2bae30SDana Myers 
159db2bae30SDana Myers         /*
16057190917SDana Myers          * October 2009: Attempt to map from the requested address to the
16157190917SDana Myers          * end of the region. However, we will never map more than one
16257190917SDana Myers          * page, nor will we cross a page boundary.
163db2bae30SDana Myers          */
16457190917SDana Myers         MapLength = (ACPI_SIZE)
165db2bae30SDana Myers             ((MemInfo->Address + MemInfo->Length) - Address);
166db2bae30SDana Myers 
16757190917SDana Myers         /*
16857190917SDana Myers          * If mapping the entire remaining portion of the region will cross
16957190917SDana Myers          * a page boundary, just map up to the page boundary, do not cross.
17057190917SDana Myers          * On some systems, crossing a page boundary while mapping regions
17157190917SDana Myers          * can cause warnings if the pages have different attributes
17257190917SDana Myers          * due to resource management.
17357190917SDana Myers          *
17457190917SDana Myers          * This has the added benefit of constraining a single mapping to
17557190917SDana Myers          * one page, which is similar to the original code that used a 4k
17657190917SDana Myers          * maximum window.
17757190917SDana Myers          */
178*385cc6b4SJerry Jelinek         PageBoundaryMapLength = (ACPI_SIZE)
179*385cc6b4SJerry Jelinek             (ACPI_ROUND_UP (Address, ACPI_DEFAULT_PAGE_SIZE) - Address);
18057190917SDana Myers         if (PageBoundaryMapLength == 0)
181db2bae30SDana Myers         {
18257190917SDana Myers             PageBoundaryMapLength = ACPI_DEFAULT_PAGE_SIZE;
18357190917SDana Myers         }
18457190917SDana Myers 
18557190917SDana Myers         if (MapLength > PageBoundaryMapLength)
18657190917SDana Myers         {
18757190917SDana Myers             MapLength = PageBoundaryMapLength;
188db2bae30SDana Myers         }
189db2bae30SDana Myers 
190db2bae30SDana Myers         /* Create a new mapping starting at the address given */
191db2bae30SDana Myers 
192*385cc6b4SJerry Jelinek         MemInfo->MappedLogicalAddress = AcpiOsMapMemory (Address, MapLength);
193db2bae30SDana Myers         if (!MemInfo->MappedLogicalAddress)
194db2bae30SDana Myers         {
195db2bae30SDana Myers             ACPI_ERROR ((AE_INFO,
19626f3cdf0SGordon Ross                 "Could not map memory at 0x%8.8X%8.8X, size %u",
197*385cc6b4SJerry Jelinek                 ACPI_FORMAT_UINT64 (Address), (UINT32) MapLength));
198db2bae30SDana Myers             MemInfo->MappedLength = 0;
199db2bae30SDana Myers             return_ACPI_STATUS (AE_NO_MEMORY);
200db2bae30SDana Myers         }
201db2bae30SDana Myers 
202db2bae30SDana Myers         /* Save the physical address and mapping size */
203db2bae30SDana Myers 
204db2bae30SDana Myers         MemInfo->MappedPhysicalAddress = Address;
20557190917SDana Myers         MemInfo->MappedLength = MapLength;
206db2bae30SDana Myers     }
207db2bae30SDana Myers 
208db2bae30SDana Myers     /*
209db2bae30SDana Myers      * Generate a logical pointer corresponding to the address we want to
210db2bae30SDana Myers      * access
211db2bae30SDana Myers      */
212db2bae30SDana Myers     LogicalAddrPtr = MemInfo->MappedLogicalAddress +
21326f3cdf0SGordon Ross         ((UINT64) Address - (UINT64) MemInfo->MappedPhysicalAddress);
214db2bae30SDana Myers 
215db2bae30SDana Myers     ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
21626f3cdf0SGordon Ross         "System-Memory (width %u) R/W %u Address=%8.8X%8.8X\n",
217*385cc6b4SJerry Jelinek         BitWidth, Function, ACPI_FORMAT_UINT64 (Address)));
218db2bae30SDana Myers 
219db2bae30SDana Myers     /*
220db2bae30SDana Myers      * Perform the memory read or write
221db2bae30SDana Myers      *
222db2bae30SDana Myers      * Note: For machines that do not support non-aligned transfers, the target
223db2bae30SDana Myers      * address was checked for alignment above. We do not attempt to break the
224db2bae30SDana Myers      * transfer up into smaller (byte-size) chunks because the AML specifically
225db2bae30SDana Myers      * asked for a transfer width that the hardware may require.
226db2bae30SDana Myers      */
227db2bae30SDana Myers     switch (Function)
228db2bae30SDana Myers     {
229db2bae30SDana Myers     case ACPI_READ:
230db2bae30SDana Myers 
231db2bae30SDana Myers         *Value = 0;
232db2bae30SDana Myers         switch (BitWidth)
233db2bae30SDana Myers         {
234db2bae30SDana Myers         case 8:
235*385cc6b4SJerry Jelinek 
23626f3cdf0SGordon Ross             *Value = (UINT64) ACPI_GET8 (LogicalAddrPtr);
237db2bae30SDana Myers             break;
238db2bae30SDana Myers 
239db2bae30SDana Myers         case 16:
240*385cc6b4SJerry Jelinek 
24126f3cdf0SGordon Ross             *Value = (UINT64) ACPI_GET16 (LogicalAddrPtr);
242db2bae30SDana Myers             break;
243db2bae30SDana Myers 
244db2bae30SDana Myers         case 32:
245*385cc6b4SJerry Jelinek 
24626f3cdf0SGordon Ross             *Value = (UINT64) ACPI_GET32 (LogicalAddrPtr);
247db2bae30SDana Myers             break;
248db2bae30SDana Myers 
249db2bae30SDana Myers         case 64:
250*385cc6b4SJerry Jelinek 
25126f3cdf0SGordon Ross             *Value = (UINT64) ACPI_GET64 (LogicalAddrPtr);
252db2bae30SDana Myers             break;
253db2bae30SDana Myers 
254db2bae30SDana Myers         default:
255*385cc6b4SJerry Jelinek 
256db2bae30SDana Myers             /* BitWidth was already validated */
257*385cc6b4SJerry Jelinek 
258db2bae30SDana Myers             break;
259db2bae30SDana Myers         }
260db2bae30SDana Myers         break;
261db2bae30SDana Myers 
262db2bae30SDana Myers     case ACPI_WRITE:
263db2bae30SDana Myers 
264db2bae30SDana Myers         switch (BitWidth)
265db2bae30SDana Myers         {
266db2bae30SDana Myers         case 8:
267*385cc6b4SJerry Jelinek 
268*385cc6b4SJerry Jelinek             ACPI_SET8 (LogicalAddrPtr, *Value);
269db2bae30SDana Myers             break;
270db2bae30SDana Myers 
271db2bae30SDana Myers         case 16:
272*385cc6b4SJerry Jelinek 
273*385cc6b4SJerry Jelinek             ACPI_SET16 (LogicalAddrPtr, *Value);
274db2bae30SDana Myers             break;
275db2bae30SDana Myers 
276db2bae30SDana Myers         case 32:
277*385cc6b4SJerry Jelinek 
278*385cc6b4SJerry Jelinek             ACPI_SET32 (LogicalAddrPtr, *Value);
279db2bae30SDana Myers             break;
280db2bae30SDana Myers 
281db2bae30SDana Myers         case 64:
282*385cc6b4SJerry Jelinek 
283*385cc6b4SJerry Jelinek             ACPI_SET64 (LogicalAddrPtr, *Value);
284db2bae30SDana Myers             break;
285db2bae30SDana Myers 
286db2bae30SDana Myers         default:
287*385cc6b4SJerry Jelinek 
288db2bae30SDana Myers             /* BitWidth was already validated */
289*385cc6b4SJerry Jelinek 
290db2bae30SDana Myers             break;
291db2bae30SDana Myers         }
292db2bae30SDana Myers         break;
293db2bae30SDana Myers 
294db2bae30SDana Myers     default:
295*385cc6b4SJerry Jelinek 
296db2bae30SDana Myers         Status = AE_BAD_PARAMETER;
297db2bae30SDana Myers         break;
298db2bae30SDana Myers     }
299db2bae30SDana Myers 
300db2bae30SDana Myers     return_ACPI_STATUS (Status);
301db2bae30SDana Myers }
302db2bae30SDana Myers 
303db2bae30SDana Myers 
304db2bae30SDana Myers /*******************************************************************************
305db2bae30SDana Myers  *
306db2bae30SDana Myers  * FUNCTION:    AcpiExSystemIoSpaceHandler
307db2bae30SDana Myers  *
308db2bae30SDana Myers  * PARAMETERS:  Function            - Read or Write operation
309db2bae30SDana Myers  *              Address             - Where in the space to read or write
310db2bae30SDana Myers  *              BitWidth            - Field width in bits (8, 16, or 32)
311db2bae30SDana Myers  *              Value               - Pointer to in or out value
312db2bae30SDana Myers  *              HandlerContext      - Pointer to Handler's context
313db2bae30SDana Myers  *              RegionContext       - Pointer to context specific to the
314db2bae30SDana Myers  *                                    accessed region
315db2bae30SDana Myers  *
316db2bae30SDana Myers  * RETURN:      Status
317db2bae30SDana Myers  *
318db2bae30SDana Myers  * DESCRIPTION: Handler for the System IO address space (Op Region)
319db2bae30SDana Myers  *
320db2bae30SDana Myers  ******************************************************************************/
321db2bae30SDana Myers 
322db2bae30SDana Myers ACPI_STATUS
AcpiExSystemIoSpaceHandler(UINT32 Function,ACPI_PHYSICAL_ADDRESS Address,UINT32 BitWidth,UINT64 * Value,void * HandlerContext,void * RegionContext)323db2bae30SDana Myers AcpiExSystemIoSpaceHandler (
324db2bae30SDana Myers     UINT32                  Function,
325db2bae30SDana Myers     ACPI_PHYSICAL_ADDRESS   Address,
326db2bae30SDana Myers     UINT32                  BitWidth,
32726f3cdf0SGordon Ross     UINT64                  *Value,
328db2bae30SDana Myers     void                    *HandlerContext,
329db2bae30SDana Myers     void                    *RegionContext)
330db2bae30SDana Myers {
331db2bae30SDana Myers     ACPI_STATUS             Status = AE_OK;
332db2bae30SDana Myers     UINT32                  Value32;
333db2bae30SDana Myers 
334db2bae30SDana Myers 
335db2bae30SDana Myers     ACPI_FUNCTION_TRACE (ExSystemIoSpaceHandler);
336db2bae30SDana Myers 
337db2bae30SDana Myers 
338db2bae30SDana Myers     ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
33926f3cdf0SGordon Ross         "System-IO (width %u) R/W %u Address=%8.8X%8.8X\n",
340*385cc6b4SJerry Jelinek         BitWidth, Function, ACPI_FORMAT_UINT64 (Address)));
341db2bae30SDana Myers 
342db2bae30SDana Myers     /* Decode the function parameter */
343db2bae30SDana Myers 
344db2bae30SDana Myers     switch (Function)
345db2bae30SDana Myers     {
346db2bae30SDana Myers     case ACPI_READ:
347db2bae30SDana Myers 
348aa2aa9a6SDana Myers         Status = AcpiHwReadPort ((ACPI_IO_ADDRESS) Address,
349db2bae30SDana Myers                     &Value32, BitWidth);
350db2bae30SDana Myers         *Value = Value32;
351db2bae30SDana Myers         break;
352db2bae30SDana Myers 
353db2bae30SDana Myers     case ACPI_WRITE:
354db2bae30SDana Myers 
355aa2aa9a6SDana Myers         Status = AcpiHwWritePort ((ACPI_IO_ADDRESS) Address,
356db2bae30SDana Myers                     (UINT32) *Value, BitWidth);
357db2bae30SDana Myers         break;
358db2bae30SDana Myers 
359db2bae30SDana Myers     default:
360*385cc6b4SJerry Jelinek 
361db2bae30SDana Myers         Status = AE_BAD_PARAMETER;
362db2bae30SDana Myers         break;
363db2bae30SDana Myers     }
364db2bae30SDana Myers 
365db2bae30SDana Myers     return_ACPI_STATUS (Status);
366db2bae30SDana Myers }
367db2bae30SDana Myers 
368db2bae30SDana Myers 
369db2bae30SDana Myers /*******************************************************************************
370db2bae30SDana Myers  *
371db2bae30SDana Myers  * FUNCTION:    AcpiExPciConfigSpaceHandler
372db2bae30SDana Myers  *
373db2bae30SDana Myers  * PARAMETERS:  Function            - Read or Write operation
374db2bae30SDana Myers  *              Address             - Where in the space to read or write
375db2bae30SDana Myers  *              BitWidth            - Field width in bits (8, 16, or 32)
376db2bae30SDana Myers  *              Value               - Pointer to in or out value
377db2bae30SDana Myers  *              HandlerContext      - Pointer to Handler's context
378db2bae30SDana Myers  *              RegionContext       - Pointer to context specific to the
379db2bae30SDana Myers  *                                    accessed region
380db2bae30SDana Myers  *
381db2bae30SDana Myers  * RETURN:      Status
382db2bae30SDana Myers  *
383db2bae30SDana Myers  * DESCRIPTION: Handler for the PCI Config address space (Op Region)
384db2bae30SDana Myers  *
385db2bae30SDana Myers  ******************************************************************************/
386db2bae30SDana Myers 
387db2bae30SDana Myers ACPI_STATUS
AcpiExPciConfigSpaceHandler(UINT32 Function,ACPI_PHYSICAL_ADDRESS Address,UINT32 BitWidth,UINT64 * Value,void * HandlerContext,void * RegionContext)388db2bae30SDana Myers AcpiExPciConfigSpaceHandler (
389db2bae30SDana Myers     UINT32                  Function,
390db2bae30SDana Myers     ACPI_PHYSICAL_ADDRESS   Address,
391db2bae30SDana Myers     UINT32                  BitWidth,
39226f3cdf0SGordon Ross     UINT64                  *Value,
393db2bae30SDana Myers     void                    *HandlerContext,
394db2bae30SDana Myers     void                    *RegionContext)
395db2bae30SDana Myers {
396db2bae30SDana Myers     ACPI_STATUS             Status = AE_OK;
397db2bae30SDana Myers     ACPI_PCI_ID             *PciId;
398db2bae30SDana Myers     UINT16                  PciRegister;
399db2bae30SDana Myers 
400db2bae30SDana Myers 
401db2bae30SDana Myers     ACPI_FUNCTION_TRACE (ExPciConfigSpaceHandler);
402db2bae30SDana Myers 
403db2bae30SDana Myers 
404db2bae30SDana Myers     /*
405db2bae30SDana Myers      *  The arguments to AcpiOs(Read|Write)PciConfiguration are:
406db2bae30SDana Myers      *
407db2bae30SDana Myers      *  PciSegment  is the PCI bus segment range 0-31
408db2bae30SDana Myers      *  PciBus      is the PCI bus number range 0-255
409db2bae30SDana Myers      *  PciDevice   is the PCI device number range 0-31
410db2bae30SDana Myers      *  PciFunction is the PCI device function number
411db2bae30SDana Myers      *  PciRegister is the Config space register range 0-255 bytes
412db2bae30SDana Myers      *
413db2bae30SDana Myers      *  Value - input value for write, output address for read
414db2bae30SDana Myers      *
415db2bae30SDana Myers      */
416db2bae30SDana Myers     PciId       = (ACPI_PCI_ID *) RegionContext;
417db2bae30SDana Myers     PciRegister = (UINT16) (UINT32) Address;
418db2bae30SDana Myers 
419db2bae30SDana Myers     ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
420*385cc6b4SJerry Jelinek         "Pci-Config %u (%u) Seg(%04x) Bus(%04x) "
421*385cc6b4SJerry Jelinek         "Dev(%04x) Func(%04x) Reg(%04x)\n",
422db2bae30SDana Myers         Function, BitWidth, PciId->Segment, PciId->Bus, PciId->Device,
423db2bae30SDana Myers         PciId->Function, PciRegister));
424db2bae30SDana Myers 
425db2bae30SDana Myers     switch (Function)
426db2bae30SDana Myers     {
427db2bae30SDana Myers     case ACPI_READ:
428db2bae30SDana Myers 
429db2bae30SDana Myers         *Value = 0;
430*385cc6b4SJerry Jelinek         Status = AcpiOsReadPciConfiguration (
431*385cc6b4SJerry Jelinek             PciId, PciRegister, Value, BitWidth);
432db2bae30SDana Myers         break;
433db2bae30SDana Myers 
434db2bae30SDana Myers     case ACPI_WRITE:
435db2bae30SDana Myers 
436*385cc6b4SJerry Jelinek         Status = AcpiOsWritePciConfiguration (
437*385cc6b4SJerry Jelinek             PciId, PciRegister, *Value, BitWidth);
438db2bae30SDana Myers         break;
439db2bae30SDana Myers 
440db2bae30SDana Myers     default:
441db2bae30SDana Myers 
442db2bae30SDana Myers         Status = AE_BAD_PARAMETER;
443db2bae30SDana Myers         break;
444db2bae30SDana Myers     }
445db2bae30SDana Myers 
446db2bae30SDana Myers     return_ACPI_STATUS (Status);
447db2bae30SDana Myers }
448db2bae30SDana Myers 
449db2bae30SDana Myers 
450db2bae30SDana Myers /*******************************************************************************
451db2bae30SDana Myers  *
452db2bae30SDana Myers  * FUNCTION:    AcpiExCmosSpaceHandler
453db2bae30SDana Myers  *
454db2bae30SDana Myers  * PARAMETERS:  Function            - Read or Write operation
455db2bae30SDana Myers  *              Address             - Where in the space to read or write
456db2bae30SDana Myers  *              BitWidth            - Field width in bits (8, 16, or 32)
457db2bae30SDana Myers  *              Value               - Pointer to in or out value
458db2bae30SDana Myers  *              HandlerContext      - Pointer to Handler's context
459db2bae30SDana Myers  *              RegionContext       - Pointer to context specific to the
460db2bae30SDana Myers  *                                    accessed region
461db2bae30SDana Myers  *
462db2bae30SDana Myers  * RETURN:      Status
463db2bae30SDana Myers  *
464db2bae30SDana Myers  * DESCRIPTION: Handler for the CMOS address space (Op Region)
465db2bae30SDana Myers  *
466db2bae30SDana Myers  ******************************************************************************/
467db2bae30SDana Myers 
468db2bae30SDana Myers ACPI_STATUS
AcpiExCmosSpaceHandler(UINT32 Function,ACPI_PHYSICAL_ADDRESS Address,UINT32 BitWidth,UINT64 * Value,void * HandlerContext,void * RegionContext)469db2bae30SDana Myers AcpiExCmosSpaceHandler (
470db2bae30SDana Myers     UINT32                  Function,
471db2bae30SDana Myers     ACPI_PHYSICAL_ADDRESS   Address,
472db2bae30SDana Myers     UINT32                  BitWidth,
47326f3cdf0SGordon Ross     UINT64                  *Value,
474db2bae30SDana Myers     void                    *HandlerContext,
475db2bae30SDana Myers     void                    *RegionContext)
476db2bae30SDana Myers {
477db2bae30SDana Myers     ACPI_STATUS             Status = AE_OK;
478db2bae30SDana Myers 
479db2bae30SDana Myers 
480db2bae30SDana Myers     ACPI_FUNCTION_TRACE (ExCmosSpaceHandler);
481db2bae30SDana Myers 
482db2bae30SDana Myers 
483db2bae30SDana Myers     return_ACPI_STATUS (Status);
484db2bae30SDana Myers }
485db2bae30SDana Myers 
486db2bae30SDana Myers 
487db2bae30SDana Myers /*******************************************************************************
488db2bae30SDana Myers  *
489db2bae30SDana Myers  * FUNCTION:    AcpiExPciBarSpaceHandler
490db2bae30SDana Myers  *
491db2bae30SDana Myers  * PARAMETERS:  Function            - Read or Write operation
492db2bae30SDana Myers  *              Address             - Where in the space to read or write
493db2bae30SDana Myers  *              BitWidth            - Field width in bits (8, 16, or 32)
494db2bae30SDana Myers  *              Value               - Pointer to in or out value
495db2bae30SDana Myers  *              HandlerContext      - Pointer to Handler's context
496db2bae30SDana Myers  *              RegionContext       - Pointer to context specific to the
497db2bae30SDana Myers  *                                    accessed region
498db2bae30SDana Myers  *
499db2bae30SDana Myers  * RETURN:      Status
500db2bae30SDana Myers  *
501db2bae30SDana Myers  * DESCRIPTION: Handler for the PCI BarTarget address space (Op Region)
502db2bae30SDana Myers  *
503db2bae30SDana Myers  ******************************************************************************/
504db2bae30SDana Myers 
505db2bae30SDana Myers ACPI_STATUS
AcpiExPciBarSpaceHandler(UINT32 Function,ACPI_PHYSICAL_ADDRESS Address,UINT32 BitWidth,UINT64 * Value,void * HandlerContext,void * RegionContext)506db2bae30SDana Myers AcpiExPciBarSpaceHandler (
507db2bae30SDana Myers     UINT32                  Function,
508db2bae30SDana Myers     ACPI_PHYSICAL_ADDRESS   Address,
509db2bae30SDana Myers     UINT32                  BitWidth,
51026f3cdf0SGordon Ross     UINT64                  *Value,
511db2bae30SDana Myers     void                    *HandlerContext,
512db2bae30SDana Myers     void                    *RegionContext)
513db2bae30SDana Myers {
514db2bae30SDana Myers     ACPI_STATUS             Status = AE_OK;
515db2bae30SDana Myers 
516db2bae30SDana Myers 
517db2bae30SDana Myers     ACPI_FUNCTION_TRACE (ExPciBarSpaceHandler);
518db2bae30SDana Myers 
519db2bae30SDana Myers 
520db2bae30SDana Myers     return_ACPI_STATUS (Status);
521db2bae30SDana Myers }
522db2bae30SDana Myers 
523db2bae30SDana Myers 
524db2bae30SDana Myers /*******************************************************************************
525db2bae30SDana Myers  *
526db2bae30SDana Myers  * FUNCTION:    AcpiExDataTableSpaceHandler
527db2bae30SDana Myers  *
528db2bae30SDana Myers  * PARAMETERS:  Function            - Read or Write operation
529db2bae30SDana Myers  *              Address             - Where in the space to read or write
530db2bae30SDana Myers  *              BitWidth            - Field width in bits (8, 16, or 32)
531db2bae30SDana Myers  *              Value               - Pointer to in or out value
532db2bae30SDana Myers  *              HandlerContext      - Pointer to Handler's context
533db2bae30SDana Myers  *              RegionContext       - Pointer to context specific to the
534db2bae30SDana Myers  *                                    accessed region
535db2bae30SDana Myers  *
536db2bae30SDana Myers  * RETURN:      Status
537db2bae30SDana Myers  *
538db2bae30SDana Myers  * DESCRIPTION: Handler for the Data Table address space (Op Region)
539db2bae30SDana Myers  *
540db2bae30SDana Myers  ******************************************************************************/
541db2bae30SDana Myers 
542db2bae30SDana Myers ACPI_STATUS
AcpiExDataTableSpaceHandler(UINT32 Function,ACPI_PHYSICAL_ADDRESS Address,UINT32 BitWidth,UINT64 * Value,void * HandlerContext,void * RegionContext)543db2bae30SDana Myers AcpiExDataTableSpaceHandler (
544db2bae30SDana Myers     UINT32                  Function,
545db2bae30SDana Myers     ACPI_PHYSICAL_ADDRESS   Address,
546db2bae30SDana Myers     UINT32                  BitWidth,
54726f3cdf0SGordon Ross     UINT64                  *Value,
548db2bae30SDana Myers     void                    *HandlerContext,
549db2bae30SDana Myers     void                    *RegionContext)
550db2bae30SDana Myers {
551db2bae30SDana Myers     ACPI_FUNCTION_TRACE (ExDataTableSpaceHandler);
552db2bae30SDana Myers 
553db2bae30SDana Myers 
55426f3cdf0SGordon Ross     /*
55526f3cdf0SGordon Ross      * Perform the memory read or write. The BitWidth was already
55626f3cdf0SGordon Ross      * validated.
55726f3cdf0SGordon Ross      */
558db2bae30SDana Myers     switch (Function)
559db2bae30SDana Myers     {
560db2bae30SDana Myers     case ACPI_READ:
561db2bae30SDana Myers 
562*385cc6b4SJerry Jelinek         memcpy (ACPI_CAST_PTR (char, Value), ACPI_PHYSADDR_TO_PTR (Address),
563db2bae30SDana Myers             ACPI_DIV_8 (BitWidth));
564db2bae30SDana Myers         break;
565db2bae30SDana Myers 
566db2bae30SDana Myers     case ACPI_WRITE:
56726f3cdf0SGordon Ross 
568*385cc6b4SJerry Jelinek         memcpy (ACPI_PHYSADDR_TO_PTR (Address), ACPI_CAST_PTR (char, Value),
56926f3cdf0SGordon Ross             ACPI_DIV_8 (BitWidth));
57026f3cdf0SGordon Ross         break;
57126f3cdf0SGordon Ross 
572db2bae30SDana Myers     default:
573db2bae30SDana Myers 
57426f3cdf0SGordon Ross         return_ACPI_STATUS (AE_BAD_PARAMETER);
575db2bae30SDana Myers     }
576db2bae30SDana Myers 
577db2bae30SDana Myers     return_ACPI_STATUS (AE_OK);
578db2bae30SDana Myers }
579