xref: /minix3/minix/drivers/power/acpi/executer/exregion.c (revision 29492bb71c7148a089a5afafa0c99409161218df)
1433d6423SLionel Sambuc /******************************************************************************
2433d6423SLionel Sambuc  *
3433d6423SLionel Sambuc  * Module Name: exregion - ACPI default OpRegion (address space) handlers
4433d6423SLionel Sambuc  *
5433d6423SLionel Sambuc  *****************************************************************************/
6433d6423SLionel Sambuc 
7*29492bb7SDavid van Moolenbroek /*
8*29492bb7SDavid van Moolenbroek  * Copyright (C) 2000 - 2014, Intel Corp.
9433d6423SLionel Sambuc  * All rights reserved.
10433d6423SLionel Sambuc  *
11*29492bb7SDavid van Moolenbroek  * Redistribution and use in source and binary forms, with or without
12*29492bb7SDavid van Moolenbroek  * modification, are permitted provided that the following conditions
13*29492bb7SDavid van Moolenbroek  * are met:
14*29492bb7SDavid van Moolenbroek  * 1. Redistributions of source code must retain the above copyright
15*29492bb7SDavid van Moolenbroek  *    notice, this list of conditions, and the following disclaimer,
16*29492bb7SDavid van Moolenbroek  *    without modification.
17*29492bb7SDavid van Moolenbroek  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18*29492bb7SDavid van Moolenbroek  *    substantially similar to the "NO WARRANTY" disclaimer below
19*29492bb7SDavid van Moolenbroek  *    ("Disclaimer") and any redistribution must be conditioned upon
20*29492bb7SDavid van Moolenbroek  *    including a substantially similar Disclaimer requirement for further
21*29492bb7SDavid van Moolenbroek  *    binary redistribution.
22*29492bb7SDavid van Moolenbroek  * 3. Neither the names of the above-listed copyright holders nor the names
23*29492bb7SDavid van Moolenbroek  *    of any contributors may be used to endorse or promote products derived
24*29492bb7SDavid van Moolenbroek  *    from this software without specific prior written permission.
25433d6423SLionel Sambuc  *
26*29492bb7SDavid van Moolenbroek  * Alternatively, this software may be distributed under the terms of the
27*29492bb7SDavid van Moolenbroek  * GNU General Public License ("GPL") version 2 as published by the Free
28*29492bb7SDavid van Moolenbroek  * Software Foundation.
29433d6423SLionel Sambuc  *
30*29492bb7SDavid van Moolenbroek  * NO WARRANTY
31*29492bb7SDavid van Moolenbroek  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32*29492bb7SDavid van Moolenbroek  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33*29492bb7SDavid van Moolenbroek  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34*29492bb7SDavid van Moolenbroek  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35*29492bb7SDavid van Moolenbroek  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36*29492bb7SDavid van Moolenbroek  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37*29492bb7SDavid van Moolenbroek  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38*29492bb7SDavid van Moolenbroek  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39*29492bb7SDavid van Moolenbroek  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40*29492bb7SDavid van Moolenbroek  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41*29492bb7SDavid van Moolenbroek  * POSSIBILITY OF SUCH DAMAGES.
42*29492bb7SDavid van Moolenbroek  */
43433d6423SLionel Sambuc 
44433d6423SLionel Sambuc #include "acpi.h"
45433d6423SLionel Sambuc #include "accommon.h"
46433d6423SLionel Sambuc #include "acinterp.h"
47433d6423SLionel Sambuc 
48433d6423SLionel Sambuc 
49433d6423SLionel Sambuc #define _COMPONENT          ACPI_EXECUTER
50433d6423SLionel Sambuc         ACPI_MODULE_NAME    ("exregion")
51433d6423SLionel Sambuc 
52433d6423SLionel Sambuc 
53433d6423SLionel Sambuc /*******************************************************************************
54433d6423SLionel Sambuc  *
55433d6423SLionel Sambuc  * FUNCTION:    AcpiExSystemMemorySpaceHandler
56433d6423SLionel Sambuc  *
57433d6423SLionel Sambuc  * PARAMETERS:  Function            - Read or Write operation
58433d6423SLionel Sambuc  *              Address             - Where in the space to read or write
59433d6423SLionel Sambuc  *              BitWidth            - Field width in bits (8, 16, or 32)
60433d6423SLionel Sambuc  *              Value               - Pointer to in or out value
61433d6423SLionel Sambuc  *              HandlerContext      - Pointer to Handler's context
62433d6423SLionel Sambuc  *              RegionContext       - Pointer to context specific to the
63433d6423SLionel Sambuc  *                                    accessed region
64433d6423SLionel Sambuc  *
65433d6423SLionel Sambuc  * RETURN:      Status
66433d6423SLionel Sambuc  *
67433d6423SLionel Sambuc  * DESCRIPTION: Handler for the System Memory address space (Op Region)
68433d6423SLionel Sambuc  *
69433d6423SLionel Sambuc  ******************************************************************************/
70433d6423SLionel Sambuc 
71433d6423SLionel Sambuc ACPI_STATUS
AcpiExSystemMemorySpaceHandler(UINT32 Function,ACPI_PHYSICAL_ADDRESS Address,UINT32 BitWidth,UINT64 * Value,void * HandlerContext,void * RegionContext)72433d6423SLionel Sambuc AcpiExSystemMemorySpaceHandler (
73433d6423SLionel Sambuc     UINT32                  Function,
74433d6423SLionel Sambuc     ACPI_PHYSICAL_ADDRESS   Address,
75433d6423SLionel Sambuc     UINT32                  BitWidth,
76433d6423SLionel Sambuc     UINT64                  *Value,
77433d6423SLionel Sambuc     void                    *HandlerContext,
78433d6423SLionel Sambuc     void                    *RegionContext)
79433d6423SLionel Sambuc {
80433d6423SLionel Sambuc     ACPI_STATUS             Status = AE_OK;
81433d6423SLionel Sambuc     void                    *LogicalAddrPtr = NULL;
82433d6423SLionel Sambuc     ACPI_MEM_SPACE_CONTEXT  *MemInfo = RegionContext;
83433d6423SLionel Sambuc     UINT32                  Length;
84433d6423SLionel Sambuc     ACPI_SIZE               MapLength;
85433d6423SLionel Sambuc     ACPI_SIZE               PageBoundaryMapLength;
86433d6423SLionel Sambuc #ifdef ACPI_MISALIGNMENT_NOT_SUPPORTED
87433d6423SLionel Sambuc     UINT32                  Remainder;
88433d6423SLionel Sambuc #endif
89433d6423SLionel Sambuc 
90433d6423SLionel Sambuc 
91433d6423SLionel Sambuc     ACPI_FUNCTION_TRACE (ExSystemMemorySpaceHandler);
92433d6423SLionel Sambuc 
93433d6423SLionel Sambuc 
94433d6423SLionel Sambuc     /* Validate and translate the bit width */
95433d6423SLionel Sambuc 
96433d6423SLionel Sambuc     switch (BitWidth)
97433d6423SLionel Sambuc     {
98433d6423SLionel Sambuc     case 8:
99*29492bb7SDavid van Moolenbroek 
100433d6423SLionel Sambuc         Length = 1;
101433d6423SLionel Sambuc         break;
102433d6423SLionel Sambuc 
103433d6423SLionel Sambuc     case 16:
104*29492bb7SDavid van Moolenbroek 
105433d6423SLionel Sambuc         Length = 2;
106433d6423SLionel Sambuc         break;
107433d6423SLionel Sambuc 
108433d6423SLionel Sambuc     case 32:
109*29492bb7SDavid van Moolenbroek 
110433d6423SLionel Sambuc         Length = 4;
111433d6423SLionel Sambuc         break;
112433d6423SLionel Sambuc 
113433d6423SLionel Sambuc     case 64:
114*29492bb7SDavid van Moolenbroek 
115433d6423SLionel Sambuc         Length = 8;
116433d6423SLionel Sambuc         break;
117433d6423SLionel Sambuc 
118433d6423SLionel Sambuc     default:
119*29492bb7SDavid van Moolenbroek 
120433d6423SLionel Sambuc         ACPI_ERROR ((AE_INFO, "Invalid SystemMemory width %u",
121433d6423SLionel Sambuc             BitWidth));
122433d6423SLionel Sambuc         return_ACPI_STATUS (AE_AML_OPERAND_VALUE);
123433d6423SLionel Sambuc     }
124433d6423SLionel Sambuc 
125433d6423SLionel Sambuc #ifdef ACPI_MISALIGNMENT_NOT_SUPPORTED
126433d6423SLionel Sambuc     /*
127433d6423SLionel Sambuc      * Hardware does not support non-aligned data transfers, we must verify
128433d6423SLionel Sambuc      * the request.
129433d6423SLionel Sambuc      */
130433d6423SLionel Sambuc     (void) AcpiUtShortDivide ((UINT64) Address, Length, NULL, &Remainder);
131433d6423SLionel Sambuc     if (Remainder != 0)
132433d6423SLionel Sambuc     {
133433d6423SLionel Sambuc         return_ACPI_STATUS (AE_AML_ALIGNMENT);
134433d6423SLionel Sambuc     }
135433d6423SLionel Sambuc #endif
136433d6423SLionel Sambuc 
137433d6423SLionel Sambuc     /*
138433d6423SLionel Sambuc      * Does the request fit into the cached memory mapping?
139433d6423SLionel Sambuc      * Is 1) Address below the current mapping? OR
140433d6423SLionel Sambuc      *    2) Address beyond the current mapping?
141433d6423SLionel Sambuc      */
142433d6423SLionel Sambuc     if ((Address < MemInfo->MappedPhysicalAddress) ||
143433d6423SLionel Sambuc         (((UINT64) Address + Length) >
144433d6423SLionel Sambuc             ((UINT64)
145433d6423SLionel Sambuc             MemInfo->MappedPhysicalAddress + MemInfo->MappedLength)))
146433d6423SLionel Sambuc     {
147433d6423SLionel Sambuc         /*
148433d6423SLionel Sambuc          * The request cannot be resolved by the current memory mapping;
149433d6423SLionel Sambuc          * Delete the existing mapping and create a new one.
150433d6423SLionel Sambuc          */
151433d6423SLionel Sambuc         if (MemInfo->MappedLength)
152433d6423SLionel Sambuc         {
153433d6423SLionel Sambuc             /* Valid mapping, delete it */
154433d6423SLionel Sambuc 
155433d6423SLionel Sambuc             AcpiOsUnmapMemory (MemInfo->MappedLogicalAddress,
156433d6423SLionel Sambuc                 MemInfo->MappedLength);
157433d6423SLionel Sambuc         }
158433d6423SLionel Sambuc 
159433d6423SLionel Sambuc         /*
160433d6423SLionel Sambuc          * October 2009: Attempt to map from the requested address to the
161433d6423SLionel Sambuc          * end of the region. However, we will never map more than one
162433d6423SLionel Sambuc          * page, nor will we cross a page boundary.
163433d6423SLionel Sambuc          */
164433d6423SLionel Sambuc         MapLength = (ACPI_SIZE)
165433d6423SLionel Sambuc             ((MemInfo->Address + MemInfo->Length) - Address);
166433d6423SLionel Sambuc 
167433d6423SLionel Sambuc         /*
168433d6423SLionel Sambuc          * If mapping the entire remaining portion of the region will cross
169433d6423SLionel Sambuc          * a page boundary, just map up to the page boundary, do not cross.
170433d6423SLionel Sambuc          * On some systems, crossing a page boundary while mapping regions
171433d6423SLionel Sambuc          * can cause warnings if the pages have different attributes
172433d6423SLionel Sambuc          * due to resource management.
173433d6423SLionel Sambuc          *
174433d6423SLionel Sambuc          * This has the added benefit of constraining a single mapping to
175433d6423SLionel Sambuc          * one page, which is similar to the original code that used a 4k
176433d6423SLionel Sambuc          * maximum window.
177433d6423SLionel Sambuc          */
178433d6423SLionel Sambuc         PageBoundaryMapLength =
179433d6423SLionel Sambuc             ACPI_ROUND_UP (Address, ACPI_DEFAULT_PAGE_SIZE) - Address;
180433d6423SLionel Sambuc         if (PageBoundaryMapLength == 0)
181433d6423SLionel Sambuc         {
182433d6423SLionel Sambuc             PageBoundaryMapLength = ACPI_DEFAULT_PAGE_SIZE;
183433d6423SLionel Sambuc         }
184433d6423SLionel Sambuc 
185433d6423SLionel Sambuc         if (MapLength > PageBoundaryMapLength)
186433d6423SLionel Sambuc         {
187433d6423SLionel Sambuc             MapLength = PageBoundaryMapLength;
188433d6423SLionel Sambuc         }
189433d6423SLionel Sambuc 
190433d6423SLionel Sambuc         /* Create a new mapping starting at the address given */
191433d6423SLionel Sambuc 
192433d6423SLionel Sambuc         MemInfo->MappedLogicalAddress = AcpiOsMapMemory (
193433d6423SLionel Sambuc             (ACPI_PHYSICAL_ADDRESS) Address, MapLength);
194433d6423SLionel Sambuc         if (!MemInfo->MappedLogicalAddress)
195433d6423SLionel Sambuc         {
196433d6423SLionel Sambuc             ACPI_ERROR ((AE_INFO,
197433d6423SLionel Sambuc                 "Could not map memory at 0x%8.8X%8.8X, size %u",
198433d6423SLionel Sambuc                 ACPI_FORMAT_NATIVE_UINT (Address), (UINT32) MapLength));
199433d6423SLionel Sambuc             MemInfo->MappedLength = 0;
200433d6423SLionel Sambuc             return_ACPI_STATUS (AE_NO_MEMORY);
201433d6423SLionel Sambuc         }
202433d6423SLionel Sambuc 
203433d6423SLionel Sambuc         /* Save the physical address and mapping size */
204433d6423SLionel Sambuc 
205433d6423SLionel Sambuc         MemInfo->MappedPhysicalAddress = Address;
206433d6423SLionel Sambuc         MemInfo->MappedLength = MapLength;
207433d6423SLionel Sambuc     }
208433d6423SLionel Sambuc 
209433d6423SLionel Sambuc     /*
210433d6423SLionel Sambuc      * Generate a logical pointer corresponding to the address we want to
211433d6423SLionel Sambuc      * access
212433d6423SLionel Sambuc      */
213433d6423SLionel Sambuc     LogicalAddrPtr = MemInfo->MappedLogicalAddress +
214433d6423SLionel Sambuc         ((UINT64) Address - (UINT64) MemInfo->MappedPhysicalAddress);
215433d6423SLionel Sambuc 
216433d6423SLionel Sambuc     ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
217433d6423SLionel Sambuc         "System-Memory (width %u) R/W %u Address=%8.8X%8.8X\n",
218433d6423SLionel Sambuc         BitWidth, Function, ACPI_FORMAT_NATIVE_UINT (Address)));
219433d6423SLionel Sambuc 
220433d6423SLionel Sambuc     /*
221433d6423SLionel Sambuc      * Perform the memory read or write
222433d6423SLionel Sambuc      *
223433d6423SLionel Sambuc      * Note: For machines that do not support non-aligned transfers, the target
224433d6423SLionel Sambuc      * address was checked for alignment above. We do not attempt to break the
225433d6423SLionel Sambuc      * transfer up into smaller (byte-size) chunks because the AML specifically
226433d6423SLionel Sambuc      * asked for a transfer width that the hardware may require.
227433d6423SLionel Sambuc      */
228433d6423SLionel Sambuc     switch (Function)
229433d6423SLionel Sambuc     {
230433d6423SLionel Sambuc     case ACPI_READ:
231433d6423SLionel Sambuc 
232433d6423SLionel Sambuc         *Value = 0;
233433d6423SLionel Sambuc         switch (BitWidth)
234433d6423SLionel Sambuc         {
235433d6423SLionel Sambuc         case 8:
236*29492bb7SDavid van Moolenbroek 
237433d6423SLionel Sambuc             *Value = (UINT64) ACPI_GET8 (LogicalAddrPtr);
238433d6423SLionel Sambuc             break;
239433d6423SLionel Sambuc 
240433d6423SLionel Sambuc         case 16:
241*29492bb7SDavid van Moolenbroek 
242433d6423SLionel Sambuc             *Value = (UINT64) ACPI_GET16 (LogicalAddrPtr);
243433d6423SLionel Sambuc             break;
244433d6423SLionel Sambuc 
245433d6423SLionel Sambuc         case 32:
246*29492bb7SDavid van Moolenbroek 
247433d6423SLionel Sambuc             *Value = (UINT64) ACPI_GET32 (LogicalAddrPtr);
248433d6423SLionel Sambuc             break;
249433d6423SLionel Sambuc 
250433d6423SLionel Sambuc         case 64:
251*29492bb7SDavid van Moolenbroek 
252433d6423SLionel Sambuc             *Value = (UINT64) ACPI_GET64 (LogicalAddrPtr);
253433d6423SLionel Sambuc             break;
254433d6423SLionel Sambuc 
255433d6423SLionel Sambuc         default:
256*29492bb7SDavid van Moolenbroek 
257433d6423SLionel Sambuc             /* BitWidth was already validated */
258*29492bb7SDavid van Moolenbroek 
259433d6423SLionel Sambuc             break;
260433d6423SLionel Sambuc         }
261433d6423SLionel Sambuc         break;
262433d6423SLionel Sambuc 
263433d6423SLionel Sambuc     case ACPI_WRITE:
264433d6423SLionel Sambuc 
265433d6423SLionel Sambuc         switch (BitWidth)
266433d6423SLionel Sambuc         {
267433d6423SLionel Sambuc         case 8:
268*29492bb7SDavid van Moolenbroek 
269*29492bb7SDavid van Moolenbroek             ACPI_SET8 (LogicalAddrPtr, *Value);
270433d6423SLionel Sambuc             break;
271433d6423SLionel Sambuc 
272433d6423SLionel Sambuc         case 16:
273*29492bb7SDavid van Moolenbroek 
274*29492bb7SDavid van Moolenbroek             ACPI_SET16 (LogicalAddrPtr, *Value);
275433d6423SLionel Sambuc             break;
276433d6423SLionel Sambuc 
277433d6423SLionel Sambuc         case 32:
278*29492bb7SDavid van Moolenbroek 
279*29492bb7SDavid van Moolenbroek             ACPI_SET32 (LogicalAddrPtr, *Value);
280433d6423SLionel Sambuc             break;
281433d6423SLionel Sambuc 
282433d6423SLionel Sambuc         case 64:
283*29492bb7SDavid van Moolenbroek 
284*29492bb7SDavid van Moolenbroek             ACPI_SET64 (LogicalAddrPtr, *Value);
285433d6423SLionel Sambuc             break;
286433d6423SLionel Sambuc 
287433d6423SLionel Sambuc         default:
288*29492bb7SDavid van Moolenbroek 
289433d6423SLionel Sambuc             /* BitWidth was already validated */
290*29492bb7SDavid van Moolenbroek 
291433d6423SLionel Sambuc             break;
292433d6423SLionel Sambuc         }
293433d6423SLionel Sambuc         break;
294433d6423SLionel Sambuc 
295433d6423SLionel Sambuc     default:
296*29492bb7SDavid van Moolenbroek 
297433d6423SLionel Sambuc         Status = AE_BAD_PARAMETER;
298433d6423SLionel Sambuc         break;
299433d6423SLionel Sambuc     }
300433d6423SLionel Sambuc 
301433d6423SLionel Sambuc     return_ACPI_STATUS (Status);
302433d6423SLionel Sambuc }
303433d6423SLionel Sambuc 
304433d6423SLionel Sambuc 
305433d6423SLionel Sambuc /*******************************************************************************
306433d6423SLionel Sambuc  *
307433d6423SLionel Sambuc  * FUNCTION:    AcpiExSystemIoSpaceHandler
308433d6423SLionel Sambuc  *
309433d6423SLionel Sambuc  * PARAMETERS:  Function            - Read or Write operation
310433d6423SLionel Sambuc  *              Address             - Where in the space to read or write
311433d6423SLionel Sambuc  *              BitWidth            - Field width in bits (8, 16, or 32)
312433d6423SLionel Sambuc  *              Value               - Pointer to in or out value
313433d6423SLionel Sambuc  *              HandlerContext      - Pointer to Handler's context
314433d6423SLionel Sambuc  *              RegionContext       - Pointer to context specific to the
315433d6423SLionel Sambuc  *                                    accessed region
316433d6423SLionel Sambuc  *
317433d6423SLionel Sambuc  * RETURN:      Status
318433d6423SLionel Sambuc  *
319433d6423SLionel Sambuc  * DESCRIPTION: Handler for the System IO address space (Op Region)
320433d6423SLionel Sambuc  *
321433d6423SLionel Sambuc  ******************************************************************************/
322433d6423SLionel Sambuc 
323433d6423SLionel Sambuc ACPI_STATUS
AcpiExSystemIoSpaceHandler(UINT32 Function,ACPI_PHYSICAL_ADDRESS Address,UINT32 BitWidth,UINT64 * Value,void * HandlerContext,void * RegionContext)324433d6423SLionel Sambuc AcpiExSystemIoSpaceHandler (
325433d6423SLionel Sambuc     UINT32                  Function,
326433d6423SLionel Sambuc     ACPI_PHYSICAL_ADDRESS   Address,
327433d6423SLionel Sambuc     UINT32                  BitWidth,
328433d6423SLionel Sambuc     UINT64                  *Value,
329433d6423SLionel Sambuc     void                    *HandlerContext,
330433d6423SLionel Sambuc     void                    *RegionContext)
331433d6423SLionel Sambuc {
332433d6423SLionel Sambuc     ACPI_STATUS             Status = AE_OK;
333433d6423SLionel Sambuc     UINT32                  Value32;
334433d6423SLionel Sambuc 
335433d6423SLionel Sambuc 
336433d6423SLionel Sambuc     ACPI_FUNCTION_TRACE (ExSystemIoSpaceHandler);
337433d6423SLionel Sambuc 
338433d6423SLionel Sambuc 
339433d6423SLionel Sambuc     ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
340433d6423SLionel Sambuc         "System-IO (width %u) R/W %u Address=%8.8X%8.8X\n",
341433d6423SLionel Sambuc         BitWidth, Function, ACPI_FORMAT_NATIVE_UINT (Address)));
342433d6423SLionel Sambuc 
343433d6423SLionel Sambuc     /* Decode the function parameter */
344433d6423SLionel Sambuc 
345433d6423SLionel Sambuc     switch (Function)
346433d6423SLionel Sambuc     {
347433d6423SLionel Sambuc     case ACPI_READ:
348433d6423SLionel Sambuc 
349433d6423SLionel Sambuc         Status = AcpiHwReadPort ((ACPI_IO_ADDRESS) Address,
350433d6423SLionel Sambuc                     &Value32, BitWidth);
351433d6423SLionel Sambuc         *Value = Value32;
352433d6423SLionel Sambuc         break;
353433d6423SLionel Sambuc 
354433d6423SLionel Sambuc     case ACPI_WRITE:
355433d6423SLionel Sambuc 
356433d6423SLionel Sambuc         Status = AcpiHwWritePort ((ACPI_IO_ADDRESS) Address,
357433d6423SLionel Sambuc                     (UINT32) *Value, BitWidth);
358433d6423SLionel Sambuc         break;
359433d6423SLionel Sambuc 
360433d6423SLionel Sambuc     default:
361*29492bb7SDavid van Moolenbroek 
362433d6423SLionel Sambuc         Status = AE_BAD_PARAMETER;
363433d6423SLionel Sambuc         break;
364433d6423SLionel Sambuc     }
365433d6423SLionel Sambuc 
366433d6423SLionel Sambuc     return_ACPI_STATUS (Status);
367433d6423SLionel Sambuc }
368433d6423SLionel Sambuc 
369433d6423SLionel Sambuc 
370433d6423SLionel Sambuc /*******************************************************************************
371433d6423SLionel Sambuc  *
372433d6423SLionel Sambuc  * FUNCTION:    AcpiExPciConfigSpaceHandler
373433d6423SLionel Sambuc  *
374433d6423SLionel Sambuc  * PARAMETERS:  Function            - Read or Write operation
375433d6423SLionel Sambuc  *              Address             - Where in the space to read or write
376433d6423SLionel Sambuc  *              BitWidth            - Field width in bits (8, 16, or 32)
377433d6423SLionel Sambuc  *              Value               - Pointer to in or out value
378433d6423SLionel Sambuc  *              HandlerContext      - Pointer to Handler's context
379433d6423SLionel Sambuc  *              RegionContext       - Pointer to context specific to the
380433d6423SLionel Sambuc  *                                    accessed region
381433d6423SLionel Sambuc  *
382433d6423SLionel Sambuc  * RETURN:      Status
383433d6423SLionel Sambuc  *
384433d6423SLionel Sambuc  * DESCRIPTION: Handler for the PCI Config address space (Op Region)
385433d6423SLionel Sambuc  *
386433d6423SLionel Sambuc  ******************************************************************************/
387433d6423SLionel Sambuc 
388433d6423SLionel Sambuc ACPI_STATUS
AcpiExPciConfigSpaceHandler(UINT32 Function,ACPI_PHYSICAL_ADDRESS Address,UINT32 BitWidth,UINT64 * Value,void * HandlerContext,void * RegionContext)389433d6423SLionel Sambuc AcpiExPciConfigSpaceHandler (
390433d6423SLionel Sambuc     UINT32                  Function,
391433d6423SLionel Sambuc     ACPI_PHYSICAL_ADDRESS   Address,
392433d6423SLionel Sambuc     UINT32                  BitWidth,
393433d6423SLionel Sambuc     UINT64                  *Value,
394433d6423SLionel Sambuc     void                    *HandlerContext,
395433d6423SLionel Sambuc     void                    *RegionContext)
396433d6423SLionel Sambuc {
397433d6423SLionel Sambuc     ACPI_STATUS             Status = AE_OK;
398433d6423SLionel Sambuc     ACPI_PCI_ID             *PciId;
399433d6423SLionel Sambuc     UINT16                  PciRegister;
400433d6423SLionel Sambuc 
401433d6423SLionel Sambuc 
402433d6423SLionel Sambuc     ACPI_FUNCTION_TRACE (ExPciConfigSpaceHandler);
403433d6423SLionel Sambuc 
404433d6423SLionel Sambuc 
405433d6423SLionel Sambuc     /*
406433d6423SLionel Sambuc      *  The arguments to AcpiOs(Read|Write)PciConfiguration are:
407433d6423SLionel Sambuc      *
408433d6423SLionel Sambuc      *  PciSegment  is the PCI bus segment range 0-31
409433d6423SLionel Sambuc      *  PciBus      is the PCI bus number range 0-255
410433d6423SLionel Sambuc      *  PciDevice   is the PCI device number range 0-31
411433d6423SLionel Sambuc      *  PciFunction is the PCI device function number
412433d6423SLionel Sambuc      *  PciRegister is the Config space register range 0-255 bytes
413433d6423SLionel Sambuc      *
414433d6423SLionel Sambuc      *  Value - input value for write, output address for read
415433d6423SLionel Sambuc      *
416433d6423SLionel Sambuc      */
417433d6423SLionel Sambuc     PciId       = (ACPI_PCI_ID *) RegionContext;
418433d6423SLionel Sambuc     PciRegister = (UINT16) (UINT32) Address;
419433d6423SLionel Sambuc 
420433d6423SLionel Sambuc     ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
421433d6423SLionel Sambuc         "Pci-Config %u (%u) Seg(%04x) Bus(%04x) Dev(%04x) Func(%04x) Reg(%04x)\n",
422433d6423SLionel Sambuc         Function, BitWidth, PciId->Segment, PciId->Bus, PciId->Device,
423433d6423SLionel Sambuc         PciId->Function, PciRegister));
424433d6423SLionel Sambuc 
425433d6423SLionel Sambuc     switch (Function)
426433d6423SLionel Sambuc     {
427433d6423SLionel Sambuc     case ACPI_READ:
428433d6423SLionel Sambuc 
429433d6423SLionel Sambuc         *Value = 0;
430433d6423SLionel Sambuc         Status = AcpiOsReadPciConfiguration (PciId, PciRegister,
431433d6423SLionel Sambuc                     Value, BitWidth);
432433d6423SLionel Sambuc         break;
433433d6423SLionel Sambuc 
434433d6423SLionel Sambuc     case ACPI_WRITE:
435433d6423SLionel Sambuc 
436433d6423SLionel Sambuc         Status = AcpiOsWritePciConfiguration (PciId, PciRegister,
437433d6423SLionel Sambuc                     *Value, BitWidth);
438433d6423SLionel Sambuc         break;
439433d6423SLionel Sambuc 
440433d6423SLionel Sambuc     default:
441433d6423SLionel Sambuc 
442433d6423SLionel Sambuc         Status = AE_BAD_PARAMETER;
443433d6423SLionel Sambuc         break;
444433d6423SLionel Sambuc     }
445433d6423SLionel Sambuc 
446433d6423SLionel Sambuc     return_ACPI_STATUS (Status);
447433d6423SLionel Sambuc }
448433d6423SLionel Sambuc 
449433d6423SLionel Sambuc 
450433d6423SLionel Sambuc /*******************************************************************************
451433d6423SLionel Sambuc  *
452433d6423SLionel Sambuc  * FUNCTION:    AcpiExCmosSpaceHandler
453433d6423SLionel Sambuc  *
454433d6423SLionel Sambuc  * PARAMETERS:  Function            - Read or Write operation
455433d6423SLionel Sambuc  *              Address             - Where in the space to read or write
456433d6423SLionel Sambuc  *              BitWidth            - Field width in bits (8, 16, or 32)
457433d6423SLionel Sambuc  *              Value               - Pointer to in or out value
458433d6423SLionel Sambuc  *              HandlerContext      - Pointer to Handler's context
459433d6423SLionel Sambuc  *              RegionContext       - Pointer to context specific to the
460433d6423SLionel Sambuc  *                                    accessed region
461433d6423SLionel Sambuc  *
462433d6423SLionel Sambuc  * RETURN:      Status
463433d6423SLionel Sambuc  *
464433d6423SLionel Sambuc  * DESCRIPTION: Handler for the CMOS address space (Op Region)
465433d6423SLionel Sambuc  *
466433d6423SLionel Sambuc  ******************************************************************************/
467433d6423SLionel Sambuc 
468433d6423SLionel Sambuc ACPI_STATUS
AcpiExCmosSpaceHandler(UINT32 Function,ACPI_PHYSICAL_ADDRESS Address,UINT32 BitWidth,UINT64 * Value,void * HandlerContext,void * RegionContext)469433d6423SLionel Sambuc AcpiExCmosSpaceHandler (
470433d6423SLionel Sambuc     UINT32                  Function,
471433d6423SLionel Sambuc     ACPI_PHYSICAL_ADDRESS   Address,
472433d6423SLionel Sambuc     UINT32                  BitWidth,
473433d6423SLionel Sambuc     UINT64                  *Value,
474433d6423SLionel Sambuc     void                    *HandlerContext,
475433d6423SLionel Sambuc     void                    *RegionContext)
476433d6423SLionel Sambuc {
477433d6423SLionel Sambuc     ACPI_STATUS             Status = AE_OK;
478433d6423SLionel Sambuc 
479433d6423SLionel Sambuc 
480433d6423SLionel Sambuc     ACPI_FUNCTION_TRACE (ExCmosSpaceHandler);
481433d6423SLionel Sambuc 
482433d6423SLionel Sambuc 
483433d6423SLionel Sambuc     return_ACPI_STATUS (Status);
484433d6423SLionel Sambuc }
485433d6423SLionel Sambuc 
486433d6423SLionel Sambuc 
487433d6423SLionel Sambuc /*******************************************************************************
488433d6423SLionel Sambuc  *
489433d6423SLionel Sambuc  * FUNCTION:    AcpiExPciBarSpaceHandler
490433d6423SLionel Sambuc  *
491433d6423SLionel Sambuc  * PARAMETERS:  Function            - Read or Write operation
492433d6423SLionel Sambuc  *              Address             - Where in the space to read or write
493433d6423SLionel Sambuc  *              BitWidth            - Field width in bits (8, 16, or 32)
494433d6423SLionel Sambuc  *              Value               - Pointer to in or out value
495433d6423SLionel Sambuc  *              HandlerContext      - Pointer to Handler's context
496433d6423SLionel Sambuc  *              RegionContext       - Pointer to context specific to the
497433d6423SLionel Sambuc  *                                    accessed region
498433d6423SLionel Sambuc  *
499433d6423SLionel Sambuc  * RETURN:      Status
500433d6423SLionel Sambuc  *
501433d6423SLionel Sambuc  * DESCRIPTION: Handler for the PCI BarTarget address space (Op Region)
502433d6423SLionel Sambuc  *
503433d6423SLionel Sambuc  ******************************************************************************/
504433d6423SLionel Sambuc 
505433d6423SLionel Sambuc ACPI_STATUS
AcpiExPciBarSpaceHandler(UINT32 Function,ACPI_PHYSICAL_ADDRESS Address,UINT32 BitWidth,UINT64 * Value,void * HandlerContext,void * RegionContext)506433d6423SLionel Sambuc AcpiExPciBarSpaceHandler (
507433d6423SLionel Sambuc     UINT32                  Function,
508433d6423SLionel Sambuc     ACPI_PHYSICAL_ADDRESS   Address,
509433d6423SLionel Sambuc     UINT32                  BitWidth,
510433d6423SLionel Sambuc     UINT64                  *Value,
511433d6423SLionel Sambuc     void                    *HandlerContext,
512433d6423SLionel Sambuc     void                    *RegionContext)
513433d6423SLionel Sambuc {
514433d6423SLionel Sambuc     ACPI_STATUS             Status = AE_OK;
515433d6423SLionel Sambuc 
516433d6423SLionel Sambuc 
517433d6423SLionel Sambuc     ACPI_FUNCTION_TRACE (ExPciBarSpaceHandler);
518433d6423SLionel Sambuc 
519433d6423SLionel Sambuc 
520433d6423SLionel Sambuc     return_ACPI_STATUS (Status);
521433d6423SLionel Sambuc }
522433d6423SLionel Sambuc 
523433d6423SLionel Sambuc 
524433d6423SLionel Sambuc /*******************************************************************************
525433d6423SLionel Sambuc  *
526433d6423SLionel Sambuc  * FUNCTION:    AcpiExDataTableSpaceHandler
527433d6423SLionel Sambuc  *
528433d6423SLionel Sambuc  * PARAMETERS:  Function            - Read or Write operation
529433d6423SLionel Sambuc  *              Address             - Where in the space to read or write
530433d6423SLionel Sambuc  *              BitWidth            - Field width in bits (8, 16, or 32)
531433d6423SLionel Sambuc  *              Value               - Pointer to in or out value
532433d6423SLionel Sambuc  *              HandlerContext      - Pointer to Handler's context
533433d6423SLionel Sambuc  *              RegionContext       - Pointer to context specific to the
534433d6423SLionel Sambuc  *                                    accessed region
535433d6423SLionel Sambuc  *
536433d6423SLionel Sambuc  * RETURN:      Status
537433d6423SLionel Sambuc  *
538433d6423SLionel Sambuc  * DESCRIPTION: Handler for the Data Table address space (Op Region)
539433d6423SLionel Sambuc  *
540433d6423SLionel Sambuc  ******************************************************************************/
541433d6423SLionel Sambuc 
542433d6423SLionel Sambuc ACPI_STATUS
AcpiExDataTableSpaceHandler(UINT32 Function,ACPI_PHYSICAL_ADDRESS Address,UINT32 BitWidth,UINT64 * Value,void * HandlerContext,void * RegionContext)543433d6423SLionel Sambuc AcpiExDataTableSpaceHandler (
544433d6423SLionel Sambuc     UINT32                  Function,
545433d6423SLionel Sambuc     ACPI_PHYSICAL_ADDRESS   Address,
546433d6423SLionel Sambuc     UINT32                  BitWidth,
547433d6423SLionel Sambuc     UINT64                  *Value,
548433d6423SLionel Sambuc     void                    *HandlerContext,
549433d6423SLionel Sambuc     void                    *RegionContext)
550433d6423SLionel Sambuc {
551433d6423SLionel Sambuc     ACPI_FUNCTION_TRACE (ExDataTableSpaceHandler);
552433d6423SLionel Sambuc 
553433d6423SLionel Sambuc 
554433d6423SLionel Sambuc     /*
555433d6423SLionel Sambuc      * Perform the memory read or write. The BitWidth was already
556433d6423SLionel Sambuc      * validated.
557433d6423SLionel Sambuc      */
558433d6423SLionel Sambuc     switch (Function)
559433d6423SLionel Sambuc     {
560433d6423SLionel Sambuc     case ACPI_READ:
561433d6423SLionel Sambuc 
562433d6423SLionel Sambuc         ACPI_MEMCPY (ACPI_CAST_PTR (char, Value), ACPI_PHYSADDR_TO_PTR (Address),
563433d6423SLionel Sambuc             ACPI_DIV_8 (BitWidth));
564433d6423SLionel Sambuc         break;
565433d6423SLionel Sambuc 
566433d6423SLionel Sambuc     case ACPI_WRITE:
567433d6423SLionel Sambuc 
568433d6423SLionel Sambuc         ACPI_MEMCPY (ACPI_PHYSADDR_TO_PTR (Address), ACPI_CAST_PTR (char, Value),
569433d6423SLionel Sambuc             ACPI_DIV_8 (BitWidth));
570433d6423SLionel Sambuc         break;
571433d6423SLionel Sambuc 
572433d6423SLionel Sambuc     default:
573433d6423SLionel Sambuc 
574433d6423SLionel Sambuc         return_ACPI_STATUS (AE_BAD_PARAMETER);
575433d6423SLionel Sambuc     }
576433d6423SLionel Sambuc 
577433d6423SLionel Sambuc     return_ACPI_STATUS (AE_OK);
578433d6423SLionel Sambuc }
579