167754Smsmith/******************************************************************************
267754Smsmith *
377424Smsmith * Module Name: exregion - ACPI default OpRegion (address space) handlers
467754Smsmith *
567754Smsmith *****************************************************************************/
667754Smsmith
7316303Sjkim/******************************************************************************
8316303Sjkim *
9316303Sjkim * 1. Copyright Notice
10316303Sjkim *
11316303Sjkim * Some or all of this work - Copyright (c) 1999 - 2017, Intel Corp.
1270243Smsmith * All rights reserved.
1367754Smsmith *
14316303Sjkim * 2. License
15316303Sjkim *
16316303Sjkim * 2.1. This is your license from Intel Corp. under its intellectual property
17316303Sjkim * rights. You may have additional license terms from the party that provided
18316303Sjkim * you this software, covering your right to use that party's intellectual
19316303Sjkim * property rights.
20316303Sjkim *
21316303Sjkim * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22316303Sjkim * copy of the source code appearing in this file ("Covered Code") an
23316303Sjkim * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24316303Sjkim * base code distributed originally by Intel ("Original Intel Code") to copy,
25316303Sjkim * make derivatives, distribute, use and display any portion of the Covered
26316303Sjkim * Code in any form, with the right to sublicense such rights; and
27316303Sjkim *
28316303Sjkim * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29316303Sjkim * license (with the right to sublicense), under only those claims of Intel
30316303Sjkim * patents that are infringed by the Original Intel Code, to make, use, sell,
31316303Sjkim * offer to sell, and import the Covered Code and derivative works thereof
32316303Sjkim * solely to the minimum extent necessary to exercise the above copyright
33316303Sjkim * license, and in no event shall the patent license extend to any additions
34316303Sjkim * to or modifications of the Original Intel Code. No other license or right
35316303Sjkim * is granted directly or by implication, estoppel or otherwise;
36316303Sjkim *
37316303Sjkim * The above copyright and patent license is granted only if the following
38316303Sjkim * conditions are met:
39316303Sjkim *
40316303Sjkim * 3. Conditions
41316303Sjkim *
42316303Sjkim * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43316303Sjkim * Redistribution of source code of any substantial portion of the Covered
44316303Sjkim * Code or modification with rights to further distribute source must include
45316303Sjkim * the above Copyright Notice, the above License, this list of Conditions,
46316303Sjkim * and the following Disclaimer and Export Compliance provision. In addition,
47316303Sjkim * Licensee must cause all Covered Code to which Licensee contributes to
48316303Sjkim * contain a file documenting the changes Licensee made to create that Covered
49316303Sjkim * Code and the date of any change. Licensee must include in that file the
50316303Sjkim * documentation of any changes made by any predecessor Licensee. Licensee
51316303Sjkim * must include a prominent statement that the modification is derived,
52316303Sjkim * directly or indirectly, from Original Intel Code.
53316303Sjkim *
54316303Sjkim * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55316303Sjkim * Redistribution of source code of any substantial portion of the Covered
56316303Sjkim * Code or modification without rights to further distribute source must
57316303Sjkim * include the following Disclaimer and Export Compliance provision in the
58316303Sjkim * documentation and/or other materials provided with distribution. In
59316303Sjkim * addition, Licensee may not authorize further sublicense of source of any
60316303Sjkim * portion of the Covered Code, and must include terms to the effect that the
61316303Sjkim * license from Licensee to its licensee is limited to the intellectual
62316303Sjkim * property embodied in the software Licensee provides to its licensee, and
63316303Sjkim * not to intellectual property embodied in modifications its licensee may
64316303Sjkim * make.
65316303Sjkim *
66316303Sjkim * 3.3. Redistribution of Executable. Redistribution in executable form of any
67316303Sjkim * substantial portion of the Covered Code or modification must reproduce the
68316303Sjkim * above Copyright Notice, and the following Disclaimer and Export Compliance
69316303Sjkim * provision in the documentation and/or other materials provided with the
70316303Sjkim * distribution.
71316303Sjkim *
72316303Sjkim * 3.4. Intel retains all right, title, and interest in and to the Original
73316303Sjkim * Intel Code.
74316303Sjkim *
75316303Sjkim * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76316303Sjkim * Intel shall be used in advertising or otherwise to promote the sale, use or
77316303Sjkim * other dealings in products derived from or relating to the Covered Code
78316303Sjkim * without prior written authorization from Intel.
79316303Sjkim *
80316303Sjkim * 4. Disclaimer and Export Compliance
81316303Sjkim *
82316303Sjkim * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83316303Sjkim * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84316303Sjkim * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85316303Sjkim * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86316303Sjkim * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87316303Sjkim * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88316303Sjkim * PARTICULAR PURPOSE.
89316303Sjkim *
90316303Sjkim * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91316303Sjkim * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92316303Sjkim * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93316303Sjkim * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94316303Sjkim * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95316303Sjkim * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96316303Sjkim * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97316303Sjkim * LIMITED REMEDY.
98316303Sjkim *
99316303Sjkim * 4.3. Licensee shall not export, either directly or indirectly, any of this
100316303Sjkim * software or system incorporating such software without first obtaining any
101316303Sjkim * required license or other approval from the U. S. Department of Commerce or
102316303Sjkim * any other agency or department of the United States Government. In the
103316303Sjkim * event Licensee exports any such software from the United States or
104316303Sjkim * re-exports any such software from a foreign destination, Licensee shall
105316303Sjkim * ensure that the distribution and export/re-export of the software is in
106316303Sjkim * compliance with all laws, regulations, orders, or other restrictions of the
107316303Sjkim * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108316303Sjkim * any of its subsidiaries will export/re-export any technical data, process,
109316303Sjkim * software, or service, directly or indirectly, to any country for which the
110316303Sjkim * United States government or any agency thereof requires an export license,
111316303Sjkim * other governmental approval, or letter of assurance, without first obtaining
112316303Sjkim * such license, approval or letter.
113316303Sjkim *
114316303Sjkim *****************************************************************************
115316303Sjkim *
116316303Sjkim * Alternatively, you may choose to be licensed under the terms of the
117316303Sjkim * following license:
118316303Sjkim *
119217365Sjkim * Redistribution and use in source and binary forms, with or without
120217365Sjkim * modification, are permitted provided that the following conditions
121217365Sjkim * are met:
122217365Sjkim * 1. Redistributions of source code must retain the above copyright
123217365Sjkim *    notice, this list of conditions, and the following disclaimer,
124217365Sjkim *    without modification.
125217365Sjkim * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126217365Sjkim *    substantially similar to the "NO WARRANTY" disclaimer below
127217365Sjkim *    ("Disclaimer") and any redistribution must be conditioned upon
128217365Sjkim *    including a substantially similar Disclaimer requirement for further
129217365Sjkim *    binary redistribution.
130217365Sjkim * 3. Neither the names of the above-listed copyright holders nor the names
131217365Sjkim *    of any contributors may be used to endorse or promote products derived
132217365Sjkim *    from this software without specific prior written permission.
13367754Smsmith *
134316303Sjkim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135316303Sjkim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136316303Sjkim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137316303Sjkim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138316303Sjkim * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139316303Sjkim * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140316303Sjkim * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141316303Sjkim * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142316303Sjkim * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143316303Sjkim * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144316303Sjkim * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145316303Sjkim *
146316303Sjkim * Alternatively, you may choose to be licensed under the terms of the
147217365Sjkim * GNU General Public License ("GPL") version 2 as published by the Free
148217365Sjkim * Software Foundation.
14967754Smsmith *
150316303Sjkim *****************************************************************************/
15167754Smsmith
152193341Sjkim#include <contrib/dev/acpica/include/acpi.h>
153193341Sjkim#include <contrib/dev/acpica/include/accommon.h>
154193341Sjkim#include <contrib/dev/acpica/include/acinterp.h>
15567754Smsmith
15667754Smsmith
15777424Smsmith#define _COMPONENT          ACPI_EXECUTER
15891116Smsmith        ACPI_MODULE_NAME    ("exregion")
15967754Smsmith
16067754Smsmith
16167754Smsmith/*******************************************************************************
16267754Smsmith *
16377424Smsmith * FUNCTION:    AcpiExSystemMemorySpaceHandler
16467754Smsmith *
16567754Smsmith * PARAMETERS:  Function            - Read or Write operation
16667754Smsmith *              Address             - Where in the space to read or write
16767754Smsmith *              BitWidth            - Field width in bits (8, 16, or 32)
16867754Smsmith *              Value               - Pointer to in or out value
16967754Smsmith *              HandlerContext      - Pointer to Handler's context
17067754Smsmith *              RegionContext       - Pointer to context specific to the
17184491Smsmith *                                    accessed region
17267754Smsmith *
17367754Smsmith * RETURN:      Status
17467754Smsmith *
17567754Smsmith * DESCRIPTION: Handler for the System Memory address space (Op Region)
17667754Smsmith *
17767754Smsmith ******************************************************************************/
17867754Smsmith
17967754SmsmithACPI_STATUS
18077424SmsmithAcpiExSystemMemorySpaceHandler (
18167754Smsmith    UINT32                  Function,
18269450Smsmith    ACPI_PHYSICAL_ADDRESS   Address,
18367754Smsmith    UINT32                  BitWidth,
184202771Sjkim    UINT64                  *Value,
18567754Smsmith    void                    *HandlerContext,
18667754Smsmith    void                    *RegionContext)
18767754Smsmith{
18867754Smsmith    ACPI_STATUS             Status = AE_OK;
18967754Smsmith    void                    *LogicalAddrPtr = NULL;
19077424Smsmith    ACPI_MEM_SPACE_CONTEXT  *MemInfo = RegionContext;
19167754Smsmith    UINT32                  Length;
192199337Sjkim    ACPI_SIZE               MapLength;
193199337Sjkim    ACPI_SIZE               PageBoundaryMapLength;
194151937Sjkim#ifdef ACPI_MISALIGNMENT_NOT_SUPPORTED
19599679Siwasaki    UINT32                  Remainder;
19699679Siwasaki#endif
19767754Smsmith
19867754Smsmith
199167802Sjkim    ACPI_FUNCTION_TRACE (ExSystemMemorySpaceHandler);
20067754Smsmith
201167802Sjkim
20267754Smsmith    /* Validate and translate the bit width */
20367754Smsmith
20467754Smsmith    switch (BitWidth)
20567754Smsmith    {
20667754Smsmith    case 8:
207250838Sjkim
20867754Smsmith        Length = 1;
20967754Smsmith        break;
21067754Smsmith
21167754Smsmith    case 16:
212250838Sjkim
21367754Smsmith        Length = 2;
21467754Smsmith        break;
21567754Smsmith
21667754Smsmith    case 32:
217250838Sjkim
21867754Smsmith        Length = 4;
21967754Smsmith        break;
22067754Smsmith
22187031Smsmith    case 64:
222250838Sjkim
22387031Smsmith        Length = 8;
22487031Smsmith        break;
22587031Smsmith
22667754Smsmith    default:
227250838Sjkim
228204773Sjkim        ACPI_ERROR ((AE_INFO, "Invalid SystemMemory width %u",
22967754Smsmith            BitWidth));
23067754Smsmith        return_ACPI_STATUS (AE_AML_OPERAND_VALUE);
23167754Smsmith    }
23267754Smsmith
233151937Sjkim#ifdef ACPI_MISALIGNMENT_NOT_SUPPORTED
23467754Smsmith    /*
23599679Siwasaki     * Hardware does not support non-aligned data transfers, we must verify
23699679Siwasaki     * the request.
23799679Siwasaki     */
238202771Sjkim    (void) AcpiUtShortDivide ((UINT64) Address, Length, NULL, &Remainder);
23999679Siwasaki    if (Remainder != 0)
24099679Siwasaki    {
24199679Siwasaki        return_ACPI_STATUS (AE_AML_ALIGNMENT);
24299679Siwasaki    }
24399679Siwasaki#endif
24499679Siwasaki
24599679Siwasaki    /*
24667754Smsmith     * Does the request fit into the cached memory mapping?
24767754Smsmith     * Is 1) Address below the current mapping? OR
24867754Smsmith     *    2) Address beyond the current mapping?
24967754Smsmith     */
25069450Smsmith    if ((Address < MemInfo->MappedPhysicalAddress) ||
251202771Sjkim        (((UINT64) Address + Length) >
252202771Sjkim            ((UINT64)
253151937Sjkim            MemInfo->MappedPhysicalAddress + MemInfo->MappedLength)))
25467754Smsmith    {
25567754Smsmith        /*
25667754Smsmith         * The request cannot be resolved by the current memory mapping;
25767754Smsmith         * Delete the existing mapping and create a new one.
25867754Smsmith         */
25967754Smsmith        if (MemInfo->MappedLength)
26067754Smsmith        {
26167754Smsmith            /* Valid mapping, delete it */
26267754Smsmith
26367754Smsmith            AcpiOsUnmapMemory (MemInfo->MappedLogicalAddress,
264167802Sjkim                MemInfo->MappedLength);
26567754Smsmith        }
26667754Smsmith
267102550Siwasaki        /*
268199337Sjkim         * October 2009: Attempt to map from the requested address to the
269199337Sjkim         * end of the region. However, we will never map more than one
270199337Sjkim         * page, nor will we cross a page boundary.
27192388Smsmith         */
272199337Sjkim        MapLength = (ACPI_SIZE)
273151937Sjkim            ((MemInfo->Address + MemInfo->Length) - Address);
274151937Sjkim
275199337Sjkim        /*
276199337Sjkim         * If mapping the entire remaining portion of the region will cross
277199337Sjkim         * a page boundary, just map up to the page boundary, do not cross.
278199337Sjkim         * On some systems, crossing a page boundary while mapping regions
279199337Sjkim         * can cause warnings if the pages have different attributes
280199337Sjkim         * due to resource management.
281199337Sjkim         *
282199337Sjkim         * This has the added benefit of constraining a single mapping to
283199337Sjkim         * one page, which is similar to the original code that used a 4k
284199337Sjkim         * maximum window.
285199337Sjkim         */
286281396Sjkim        PageBoundaryMapLength = (ACPI_SIZE)
287281396Sjkim            (ACPI_ROUND_UP (Address, ACPI_DEFAULT_PAGE_SIZE) - Address);
288199337Sjkim        if (PageBoundaryMapLength == 0)
28992388Smsmith        {
290199337Sjkim            PageBoundaryMapLength = ACPI_DEFAULT_PAGE_SIZE;
29192388Smsmith        }
292102550Siwasaki
293199337Sjkim        if (MapLength > PageBoundaryMapLength)
294199337Sjkim        {
295199337Sjkim            MapLength = PageBoundaryMapLength;
296199337Sjkim        }
297199337Sjkim
29867754Smsmith        /* Create a new mapping starting at the address given */
29967754Smsmith
300281396Sjkim        MemInfo->MappedLogicalAddress = AcpiOsMapMemory (Address, MapLength);
301167802Sjkim        if (!MemInfo->MappedLogicalAddress)
30267754Smsmith        {
303167802Sjkim            ACPI_ERROR ((AE_INFO,
304204773Sjkim                "Could not map memory at 0x%8.8X%8.8X, size %u",
305281396Sjkim                ACPI_FORMAT_UINT64 (Address), (UINT32) MapLength));
30692388Smsmith            MemInfo->MappedLength = 0;
307167802Sjkim            return_ACPI_STATUS (AE_NO_MEMORY);
30867754Smsmith        }
30967754Smsmith
31084491Smsmith        /* Save the physical address and mapping size */
31167754Smsmith
31269450Smsmith        MemInfo->MappedPhysicalAddress = Address;
313199337Sjkim        MemInfo->MappedLength = MapLength;
31467754Smsmith    }
31567754Smsmith
31667754Smsmith    /*
31767754Smsmith     * Generate a logical pointer corresponding to the address we want to
31867754Smsmith     * access
31967754Smsmith     */
32067754Smsmith    LogicalAddrPtr = MemInfo->MappedLogicalAddress +
321202771Sjkim        ((UINT64) Address - (UINT64) MemInfo->MappedPhysicalAddress);
32267754Smsmith
32382367Smsmith    ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
324209746Sjkim        "System-Memory (width %u) R/W %u Address=%8.8X%8.8X\n",
325281396Sjkim        BitWidth, Function, ACPI_FORMAT_UINT64 (Address)));
32667754Smsmith
327167802Sjkim    /*
328167802Sjkim     * Perform the memory read or write
329167802Sjkim     *
330167802Sjkim     * Note: For machines that do not support non-aligned transfers, the target
331241973Sjkim     * address was checked for alignment above. We do not attempt to break the
332167802Sjkim     * transfer up into smaller (byte-size) chunks because the AML specifically
333167802Sjkim     * asked for a transfer width that the hardware may require.
334167802Sjkim     */
33567754Smsmith    switch (Function)
33667754Smsmith    {
33787031Smsmith    case ACPI_READ:
33867754Smsmith
33991116Smsmith        *Value = 0;
34067754Smsmith        switch (BitWidth)
34167754Smsmith        {
34267754Smsmith        case 8:
343250838Sjkim
344202771Sjkim            *Value = (UINT64) ACPI_GET8 (LogicalAddrPtr);
34567754Smsmith            break;
34667754Smsmith
34767754Smsmith        case 16:
348250838Sjkim
349202771Sjkim            *Value = (UINT64) ACPI_GET16 (LogicalAddrPtr);
35067754Smsmith            break;
35167754Smsmith
35267754Smsmith        case 32:
353250838Sjkim
354202771Sjkim            *Value = (UINT64) ACPI_GET32 (LogicalAddrPtr);
35567754Smsmith            break;
35687031Smsmith
35787031Smsmith        case 64:
358250838Sjkim
359202771Sjkim            *Value = (UINT64) ACPI_GET64 (LogicalAddrPtr);
36087031Smsmith            break;
361167802Sjkim
36299679Siwasaki        default:
363250838Sjkim
36499679Siwasaki            /* BitWidth was already validated */
365250838Sjkim
36699679Siwasaki            break;
36767754Smsmith        }
36867754Smsmith        break;
36967754Smsmith
37087031Smsmith    case ACPI_WRITE:
37167754Smsmith
37267754Smsmith        switch (BitWidth)
37367754Smsmith        {
37467754Smsmith        case 8:
375250838Sjkim
376243347Sjkim            ACPI_SET8 (LogicalAddrPtr, *Value);
37767754Smsmith            break;
37867754Smsmith
37967754Smsmith        case 16:
380250838Sjkim
381243347Sjkim            ACPI_SET16 (LogicalAddrPtr, *Value);
38267754Smsmith            break;
38367754Smsmith
38467754Smsmith        case 32:
385250838Sjkim
386243347Sjkim            ACPI_SET32 (LogicalAddrPtr, *Value);
38767754Smsmith            break;
38887031Smsmith
38987031Smsmith        case 64:
390250838Sjkim
391243347Sjkim            ACPI_SET64 (LogicalAddrPtr, *Value);
39287031Smsmith            break;
393102550Siwasaki
39499679Siwasaki        default:
395250838Sjkim
39699679Siwasaki            /* BitWidth was already validated */
397250838Sjkim
39899679Siwasaki            break;
39967754Smsmith        }
40067754Smsmith        break;
40167754Smsmith
40267754Smsmith    default:
403250838Sjkim
40467754Smsmith        Status = AE_BAD_PARAMETER;
40567754Smsmith        break;
40667754Smsmith    }
40767754Smsmith
40867754Smsmith    return_ACPI_STATUS (Status);
40967754Smsmith}
41067754Smsmith
41167754Smsmith
41267754Smsmith/*******************************************************************************
41367754Smsmith *
41477424Smsmith * FUNCTION:    AcpiExSystemIoSpaceHandler
41567754Smsmith *
41667754Smsmith * PARAMETERS:  Function            - Read or Write operation
41767754Smsmith *              Address             - Where in the space to read or write
41867754Smsmith *              BitWidth            - Field width in bits (8, 16, or 32)
41967754Smsmith *              Value               - Pointer to in or out value
42067754Smsmith *              HandlerContext      - Pointer to Handler's context
42167754Smsmith *              RegionContext       - Pointer to context specific to the
42284491Smsmith *                                    accessed region
42367754Smsmith *
42467754Smsmith * RETURN:      Status
42567754Smsmith *
42667754Smsmith * DESCRIPTION: Handler for the System IO address space (Op Region)
42767754Smsmith *
42867754Smsmith ******************************************************************************/
42967754Smsmith
43067754SmsmithACPI_STATUS
43177424SmsmithAcpiExSystemIoSpaceHandler (
43267754Smsmith    UINT32                  Function,
43369450Smsmith    ACPI_PHYSICAL_ADDRESS   Address,
43467754Smsmith    UINT32                  BitWidth,
435202771Sjkim    UINT64                  *Value,
43667754Smsmith    void                    *HandlerContext,
43767754Smsmith    void                    *RegionContext)
43867754Smsmith{
43967754Smsmith    ACPI_STATUS             Status = AE_OK;
440117521Snjl    UINT32                  Value32;
44167754Smsmith
44267754Smsmith
443167802Sjkim    ACPI_FUNCTION_TRACE (ExSystemIoSpaceHandler);
44467754Smsmith
44567754Smsmith
44682367Smsmith    ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
447209746Sjkim        "System-IO (width %u) R/W %u Address=%8.8X%8.8X\n",
448281396Sjkim        BitWidth, Function, ACPI_FORMAT_UINT64 (Address)));
44980062Smsmith
45067754Smsmith    /* Decode the function parameter */
45167754Smsmith
45267754Smsmith    switch (Function)
45367754Smsmith    {
45487031Smsmith    case ACPI_READ:
45567754Smsmith
456193267Sjkim        Status = AcpiHwReadPort ((ACPI_IO_ADDRESS) Address,
457151937Sjkim                    &Value32, BitWidth);
458117521Snjl        *Value = Value32;
45967754Smsmith        break;
46067754Smsmith
46187031Smsmith    case ACPI_WRITE:
46267754Smsmith
463193267Sjkim        Status = AcpiHwWritePort ((ACPI_IO_ADDRESS) Address,
464151937Sjkim                    (UINT32) *Value, BitWidth);
46567754Smsmith        break;
46667754Smsmith
46767754Smsmith    default:
468250838Sjkim
46967754Smsmith        Status = AE_BAD_PARAMETER;
47067754Smsmith        break;
47167754Smsmith    }
47267754Smsmith
47367754Smsmith    return_ACPI_STATUS (Status);
47467754Smsmith}
47567754Smsmith
47680062Smsmith
47767754Smsmith/*******************************************************************************
47867754Smsmith *
47977424Smsmith * FUNCTION:    AcpiExPciConfigSpaceHandler
48067754Smsmith *
48167754Smsmith * PARAMETERS:  Function            - Read or Write operation
48267754Smsmith *              Address             - Where in the space to read or write
48367754Smsmith *              BitWidth            - Field width in bits (8, 16, or 32)
48467754Smsmith *              Value               - Pointer to in or out value
48567754Smsmith *              HandlerContext      - Pointer to Handler's context
48667754Smsmith *              RegionContext       - Pointer to context specific to the
48784491Smsmith *                                    accessed region
48867754Smsmith *
48967754Smsmith * RETURN:      Status
49067754Smsmith *
49167754Smsmith * DESCRIPTION: Handler for the PCI Config address space (Op Region)
49267754Smsmith *
49367754Smsmith ******************************************************************************/
49467754Smsmith
49567754SmsmithACPI_STATUS
49677424SmsmithAcpiExPciConfigSpaceHandler (
49767754Smsmith    UINT32                  Function,
49869450Smsmith    ACPI_PHYSICAL_ADDRESS   Address,
49967754Smsmith    UINT32                  BitWidth,
500202771Sjkim    UINT64                  *Value,
50167754Smsmith    void                    *HandlerContext,
50267754Smsmith    void                    *RegionContext)
50367754Smsmith{
50467754Smsmith    ACPI_STATUS             Status = AE_OK;
50580062Smsmith    ACPI_PCI_ID             *PciId;
50680062Smsmith    UINT16                  PciRegister;
50767754Smsmith
50867754Smsmith
509167802Sjkim    ACPI_FUNCTION_TRACE (ExPciConfigSpaceHandler);
51067754Smsmith
51180062Smsmith
51267754Smsmith    /*
51387031Smsmith     *  The arguments to AcpiOs(Read|Write)PciConfiguration are:
51467754Smsmith     *
51580062Smsmith     *  PciSegment  is the PCI bus segment range 0-31
51680062Smsmith     *  PciBus      is the PCI bus number range 0-255
51780062Smsmith     *  PciDevice   is the PCI device number range 0-31
51880062Smsmith     *  PciFunction is the PCI device function number
51980062Smsmith     *  PciRegister is the Config space register range 0-255 bytes
52067754Smsmith     *
52180062Smsmith     *  Value - input value for write, output address for read
52267754Smsmith     *
52367754Smsmith     */
52480062Smsmith    PciId       = (ACPI_PCI_ID *) RegionContext;
52599679Siwasaki    PciRegister = (UINT16) (UINT32) Address;
52667754Smsmith
52782367Smsmith    ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
528298714Sjkim        "Pci-Config %u (%u) Seg(%04x) Bus(%04x) "
529298714Sjkim        "Dev(%04x) Func(%04x) Reg(%04x)\n",
53083174Smsmith        Function, BitWidth, PciId->Segment, PciId->Bus, PciId->Device,
53180062Smsmith        PciId->Function, PciRegister));
53267754Smsmith
53367754Smsmith    switch (Function)
53467754Smsmith    {
53587031Smsmith    case ACPI_READ:
53667754Smsmith
53780062Smsmith        *Value = 0;
538298714Sjkim        Status = AcpiOsReadPciConfiguration (
539298714Sjkim            PciId, PciRegister, Value, BitWidth);
54067754Smsmith        break;
54167754Smsmith
54287031Smsmith    case ACPI_WRITE:
54367754Smsmith
544298714Sjkim        Status = AcpiOsWritePciConfiguration (
545298714Sjkim            PciId, PciRegister, *Value, BitWidth);
54667754Smsmith        break;
54767754Smsmith
54867754Smsmith    default:
54967754Smsmith
55067754Smsmith        Status = AE_BAD_PARAMETER;
55167754Smsmith        break;
55267754Smsmith    }
55367754Smsmith
55467754Smsmith    return_ACPI_STATUS (Status);
55567754Smsmith}
55667754Smsmith
55784491Smsmith
55884491Smsmith/*******************************************************************************
55984491Smsmith *
56084491Smsmith * FUNCTION:    AcpiExCmosSpaceHandler
56184491Smsmith *
56284491Smsmith * PARAMETERS:  Function            - Read or Write operation
56384491Smsmith *              Address             - Where in the space to read or write
56484491Smsmith *              BitWidth            - Field width in bits (8, 16, or 32)
56584491Smsmith *              Value               - Pointer to in or out value
56684491Smsmith *              HandlerContext      - Pointer to Handler's context
56784491Smsmith *              RegionContext       - Pointer to context specific to the
56884491Smsmith *                                    accessed region
56984491Smsmith *
57084491Smsmith * RETURN:      Status
57184491Smsmith *
57284491Smsmith * DESCRIPTION: Handler for the CMOS address space (Op Region)
57384491Smsmith *
57484491Smsmith ******************************************************************************/
57584491Smsmith
57684491SmsmithACPI_STATUS
57784491SmsmithAcpiExCmosSpaceHandler (
57884491Smsmith    UINT32                  Function,
57984491Smsmith    ACPI_PHYSICAL_ADDRESS   Address,
58084491Smsmith    UINT32                  BitWidth,
581202771Sjkim    UINT64                  *Value,
58284491Smsmith    void                    *HandlerContext,
58384491Smsmith    void                    *RegionContext)
58484491Smsmith{
58584491Smsmith    ACPI_STATUS             Status = AE_OK;
58684491Smsmith
58784491Smsmith
588167802Sjkim    ACPI_FUNCTION_TRACE (ExCmosSpaceHandler);
58984491Smsmith
59084491Smsmith
59184491Smsmith    return_ACPI_STATUS (Status);
59284491Smsmith}
59384491Smsmith
59484491Smsmith
59584491Smsmith/*******************************************************************************
59684491Smsmith *
59784491Smsmith * FUNCTION:    AcpiExPciBarSpaceHandler
59884491Smsmith *
59984491Smsmith * PARAMETERS:  Function            - Read or Write operation
60084491Smsmith *              Address             - Where in the space to read or write
60184491Smsmith *              BitWidth            - Field width in bits (8, 16, or 32)
60284491Smsmith *              Value               - Pointer to in or out value
60384491Smsmith *              HandlerContext      - Pointer to Handler's context
60484491Smsmith *              RegionContext       - Pointer to context specific to the
60584491Smsmith *                                    accessed region
60684491Smsmith *
60784491Smsmith * RETURN:      Status
60884491Smsmith *
60984491Smsmith * DESCRIPTION: Handler for the PCI BarTarget address space (Op Region)
61084491Smsmith *
61184491Smsmith ******************************************************************************/
61284491Smsmith
61384491SmsmithACPI_STATUS
61484491SmsmithAcpiExPciBarSpaceHandler (
61584491Smsmith    UINT32                  Function,
61684491Smsmith    ACPI_PHYSICAL_ADDRESS   Address,
61784491Smsmith    UINT32                  BitWidth,
618202771Sjkim    UINT64                  *Value,
61984491Smsmith    void                    *HandlerContext,
62084491Smsmith    void                    *RegionContext)
62184491Smsmith{
62284491Smsmith    ACPI_STATUS             Status = AE_OK;
62384491Smsmith
62484491Smsmith
625167802Sjkim    ACPI_FUNCTION_TRACE (ExPciBarSpaceHandler);
62684491Smsmith
62784491Smsmith
62884491Smsmith    return_ACPI_STATUS (Status);
62984491Smsmith}
63084491Smsmith
63191116Smsmith
63291116Smsmith/*******************************************************************************
63391116Smsmith *
63491116Smsmith * FUNCTION:    AcpiExDataTableSpaceHandler
63591116Smsmith *
63691116Smsmith * PARAMETERS:  Function            - Read or Write operation
63791116Smsmith *              Address             - Where in the space to read or write
63891116Smsmith *              BitWidth            - Field width in bits (8, 16, or 32)
63991116Smsmith *              Value               - Pointer to in or out value
64091116Smsmith *              HandlerContext      - Pointer to Handler's context
64191116Smsmith *              RegionContext       - Pointer to context specific to the
64291116Smsmith *                                    accessed region
64391116Smsmith *
64491116Smsmith * RETURN:      Status
64591116Smsmith *
64691116Smsmith * DESCRIPTION: Handler for the Data Table address space (Op Region)
64791116Smsmith *
64891116Smsmith ******************************************************************************/
64991116Smsmith
65091116SmsmithACPI_STATUS
65191116SmsmithAcpiExDataTableSpaceHandler (
65291116Smsmith    UINT32                  Function,
65391116Smsmith    ACPI_PHYSICAL_ADDRESS   Address,
65491116Smsmith    UINT32                  BitWidth,
655202771Sjkim    UINT64                  *Value,
65691116Smsmith    void                    *HandlerContext,
65791116Smsmith    void                    *RegionContext)
65891116Smsmith{
659167802Sjkim    ACPI_FUNCTION_TRACE (ExDataTableSpaceHandler);
66091116Smsmith
66191116Smsmith
662206117Sjkim    /*
663206117Sjkim     * Perform the memory read or write. The BitWidth was already
664206117Sjkim     * validated.
665206117Sjkim     */
66691116Smsmith    switch (Function)
66791116Smsmith    {
66891116Smsmith    case ACPI_READ:
66991116Smsmith
670284583Sjkim        memcpy (ACPI_CAST_PTR (char, Value), ACPI_PHYSADDR_TO_PTR (Address),
671167802Sjkim            ACPI_DIV_8 (BitWidth));
67291116Smsmith        break;
67391116Smsmith
67491116Smsmith    case ACPI_WRITE:
675206117Sjkim
676284583Sjkim        memcpy (ACPI_PHYSADDR_TO_PTR (Address), ACPI_CAST_PTR (char, Value),
677206117Sjkim            ACPI_DIV_8 (BitWidth));
678206117Sjkim        break;
679206117Sjkim
68099679Siwasaki    default:
68191116Smsmith
682206117Sjkim        return_ACPI_STATUS (AE_BAD_PARAMETER);
68391116Smsmith    }
68491116Smsmith
685167802Sjkim    return_ACPI_STATUS (AE_OK);
68691116Smsmith}
687