1aa2aa9a6SDana Myers /******************************************************************************
2aa2aa9a6SDana Myers *
3aa2aa9a6SDana Myers * Module Name: hwvalid - I/O request validation
4aa2aa9a6SDana Myers *
5aa2aa9a6SDana Myers *****************************************************************************/
6aa2aa9a6SDana Myers
7*35786f68SRobert Mustacchi /******************************************************************************
8*35786f68SRobert Mustacchi *
9*35786f68SRobert Mustacchi * 1. Copyright Notice
10*35786f68SRobert Mustacchi *
11*35786f68SRobert Mustacchi * Some or all of this work - Copyright (c) 1999 - 2018, Intel Corp.
12aa2aa9a6SDana Myers * All rights reserved.
13aa2aa9a6SDana Myers *
14*35786f68SRobert Mustacchi * 2. License
15*35786f68SRobert Mustacchi *
16*35786f68SRobert Mustacchi * 2.1. This is your license from Intel Corp. under its intellectual property
17*35786f68SRobert Mustacchi * rights. You may have additional license terms from the party that provided
18*35786f68SRobert Mustacchi * you this software, covering your right to use that party's intellectual
19*35786f68SRobert Mustacchi * property rights.
20*35786f68SRobert Mustacchi *
21*35786f68SRobert Mustacchi * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22*35786f68SRobert Mustacchi * copy of the source code appearing in this file ("Covered Code") an
23*35786f68SRobert Mustacchi * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24*35786f68SRobert Mustacchi * base code distributed originally by Intel ("Original Intel Code") to copy,
25*35786f68SRobert Mustacchi * make derivatives, distribute, use and display any portion of the Covered
26*35786f68SRobert Mustacchi * Code in any form, with the right to sublicense such rights; and
27*35786f68SRobert Mustacchi *
28*35786f68SRobert Mustacchi * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29*35786f68SRobert Mustacchi * license (with the right to sublicense), under only those claims of Intel
30*35786f68SRobert Mustacchi * patents that are infringed by the Original Intel Code, to make, use, sell,
31*35786f68SRobert Mustacchi * offer to sell, and import the Covered Code and derivative works thereof
32*35786f68SRobert Mustacchi * solely to the minimum extent necessary to exercise the above copyright
33*35786f68SRobert Mustacchi * license, and in no event shall the patent license extend to any additions
34*35786f68SRobert Mustacchi * to or modifications of the Original Intel Code. No other license or right
35*35786f68SRobert Mustacchi * is granted directly or by implication, estoppel or otherwise;
36*35786f68SRobert Mustacchi *
37*35786f68SRobert Mustacchi * The above copyright and patent license is granted only if the following
38*35786f68SRobert Mustacchi * conditions are met:
39*35786f68SRobert Mustacchi *
40*35786f68SRobert Mustacchi * 3. Conditions
41*35786f68SRobert Mustacchi *
42*35786f68SRobert Mustacchi * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43*35786f68SRobert Mustacchi * Redistribution of source code of any substantial portion of the Covered
44*35786f68SRobert Mustacchi * Code or modification with rights to further distribute source must include
45*35786f68SRobert Mustacchi * the above Copyright Notice, the above License, this list of Conditions,
46*35786f68SRobert Mustacchi * and the following Disclaimer and Export Compliance provision. In addition,
47*35786f68SRobert Mustacchi * Licensee must cause all Covered Code to which Licensee contributes to
48*35786f68SRobert Mustacchi * contain a file documenting the changes Licensee made to create that Covered
49*35786f68SRobert Mustacchi * Code and the date of any change. Licensee must include in that file the
50*35786f68SRobert Mustacchi * documentation of any changes made by any predecessor Licensee. Licensee
51*35786f68SRobert Mustacchi * must include a prominent statement that the modification is derived,
52*35786f68SRobert Mustacchi * directly or indirectly, from Original Intel Code.
53*35786f68SRobert Mustacchi *
54*35786f68SRobert Mustacchi * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55*35786f68SRobert Mustacchi * Redistribution of source code of any substantial portion of the Covered
56*35786f68SRobert Mustacchi * Code or modification without rights to further distribute source must
57*35786f68SRobert Mustacchi * include the following Disclaimer and Export Compliance provision in the
58*35786f68SRobert Mustacchi * documentation and/or other materials provided with distribution. In
59*35786f68SRobert Mustacchi * addition, Licensee may not authorize further sublicense of source of any
60*35786f68SRobert Mustacchi * portion of the Covered Code, and must include terms to the effect that the
61*35786f68SRobert Mustacchi * license from Licensee to its licensee is limited to the intellectual
62*35786f68SRobert Mustacchi * property embodied in the software Licensee provides to its licensee, and
63*35786f68SRobert Mustacchi * not to intellectual property embodied in modifications its licensee may
64*35786f68SRobert Mustacchi * make.
65*35786f68SRobert Mustacchi *
66*35786f68SRobert Mustacchi * 3.3. Redistribution of Executable. Redistribution in executable form of any
67*35786f68SRobert Mustacchi * substantial portion of the Covered Code or modification must reproduce the
68*35786f68SRobert Mustacchi * above Copyright Notice, and the following Disclaimer and Export Compliance
69*35786f68SRobert Mustacchi * provision in the documentation and/or other materials provided with the
70*35786f68SRobert Mustacchi * distribution.
71*35786f68SRobert Mustacchi *
72*35786f68SRobert Mustacchi * 3.4. Intel retains all right, title, and interest in and to the Original
73*35786f68SRobert Mustacchi * Intel Code.
74*35786f68SRobert Mustacchi *
75*35786f68SRobert Mustacchi * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76*35786f68SRobert Mustacchi * Intel shall be used in advertising or otherwise to promote the sale, use or
77*35786f68SRobert Mustacchi * other dealings in products derived from or relating to the Covered Code
78*35786f68SRobert Mustacchi * without prior written authorization from Intel.
79*35786f68SRobert Mustacchi *
80*35786f68SRobert Mustacchi * 4. Disclaimer and Export Compliance
81*35786f68SRobert Mustacchi *
82*35786f68SRobert Mustacchi * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83*35786f68SRobert Mustacchi * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84*35786f68SRobert Mustacchi * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85*35786f68SRobert Mustacchi * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86*35786f68SRobert Mustacchi * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87*35786f68SRobert Mustacchi * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88*35786f68SRobert Mustacchi * PARTICULAR PURPOSE.
89*35786f68SRobert Mustacchi *
90*35786f68SRobert Mustacchi * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91*35786f68SRobert Mustacchi * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92*35786f68SRobert Mustacchi * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93*35786f68SRobert Mustacchi * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94*35786f68SRobert Mustacchi * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95*35786f68SRobert Mustacchi * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96*35786f68SRobert Mustacchi * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97*35786f68SRobert Mustacchi * LIMITED REMEDY.
98*35786f68SRobert Mustacchi *
99*35786f68SRobert Mustacchi * 4.3. Licensee shall not export, either directly or indirectly, any of this
100*35786f68SRobert Mustacchi * software or system incorporating such software without first obtaining any
101*35786f68SRobert Mustacchi * required license or other approval from the U. S. Department of Commerce or
102*35786f68SRobert Mustacchi * any other agency or department of the United States Government. In the
103*35786f68SRobert Mustacchi * event Licensee exports any such software from the United States or
104*35786f68SRobert Mustacchi * re-exports any such software from a foreign destination, Licensee shall
105*35786f68SRobert Mustacchi * ensure that the distribution and export/re-export of the software is in
106*35786f68SRobert Mustacchi * compliance with all laws, regulations, orders, or other restrictions of the
107*35786f68SRobert Mustacchi * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108*35786f68SRobert Mustacchi * any of its subsidiaries will export/re-export any technical data, process,
109*35786f68SRobert Mustacchi * software, or service, directly or indirectly, to any country for which the
110*35786f68SRobert Mustacchi * United States government or any agency thereof requires an export license,
111*35786f68SRobert Mustacchi * other governmental approval, or letter of assurance, without first obtaining
112*35786f68SRobert Mustacchi * such license, approval or letter.
113*35786f68SRobert Mustacchi *
114*35786f68SRobert Mustacchi *****************************************************************************
115*35786f68SRobert Mustacchi *
116*35786f68SRobert Mustacchi * Alternatively, you may choose to be licensed under the terms of the
117*35786f68SRobert Mustacchi * following license:
118*35786f68SRobert Mustacchi *
11926f3cdf0SGordon Ross * Redistribution and use in source and binary forms, with or without
12026f3cdf0SGordon Ross * modification, are permitted provided that the following conditions
12126f3cdf0SGordon Ross * are met:
12226f3cdf0SGordon Ross * 1. Redistributions of source code must retain the above copyright
12326f3cdf0SGordon Ross * notice, this list of conditions, and the following disclaimer,
12426f3cdf0SGordon Ross * without modification.
12526f3cdf0SGordon Ross * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12626f3cdf0SGordon Ross * substantially similar to the "NO WARRANTY" disclaimer below
12726f3cdf0SGordon Ross * ("Disclaimer") and any redistribution must be conditioned upon
12826f3cdf0SGordon Ross * including a substantially similar Disclaimer requirement for further
12926f3cdf0SGordon Ross * binary redistribution.
13026f3cdf0SGordon Ross * 3. Neither the names of the above-listed copyright holders nor the names
13126f3cdf0SGordon Ross * of any contributors may be used to endorse or promote products derived
13226f3cdf0SGordon Ross * from this software without specific prior written permission.
13326f3cdf0SGordon Ross *
13426f3cdf0SGordon Ross * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
13526f3cdf0SGordon Ross * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136*35786f68SRobert Mustacchi * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
13726f3cdf0SGordon Ross * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138*35786f68SRobert Mustacchi * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139*35786f68SRobert Mustacchi * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140*35786f68SRobert Mustacchi * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141*35786f68SRobert Mustacchi * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142*35786f68SRobert Mustacchi * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143*35786f68SRobert Mustacchi * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144*35786f68SRobert Mustacchi * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145*35786f68SRobert Mustacchi *
146*35786f68SRobert Mustacchi * Alternatively, you may choose to be licensed under the terms of the
147*35786f68SRobert Mustacchi * GNU General Public License ("GPL") version 2 as published by the Free
148*35786f68SRobert Mustacchi * Software Foundation.
149*35786f68SRobert Mustacchi *
150*35786f68SRobert Mustacchi *****************************************************************************/
151aa2aa9a6SDana Myers
152aa2aa9a6SDana Myers #include "acpi.h"
153aa2aa9a6SDana Myers #include "accommon.h"
154aa2aa9a6SDana Myers
155aa2aa9a6SDana Myers #define _COMPONENT ACPI_HARDWARE
156aa2aa9a6SDana Myers ACPI_MODULE_NAME ("hwvalid")
157aa2aa9a6SDana Myers
158aa2aa9a6SDana Myers /* Local prototypes */
159aa2aa9a6SDana Myers
160aa2aa9a6SDana Myers static ACPI_STATUS
161aa2aa9a6SDana Myers AcpiHwValidateIoRequest (
162aa2aa9a6SDana Myers ACPI_IO_ADDRESS Address,
163aa2aa9a6SDana Myers UINT32 BitWidth);
164aa2aa9a6SDana Myers
165aa2aa9a6SDana Myers
166aa2aa9a6SDana Myers /*
167aa2aa9a6SDana Myers * Protected I/O ports. Some ports are always illegal, and some are
168aa2aa9a6SDana Myers * conditionally illegal. This table must remain ordered by port address.
169aa2aa9a6SDana Myers *
170aa2aa9a6SDana Myers * The table is used to implement the Microsoft port access rules that
171aa2aa9a6SDana Myers * first appeared in Windows XP. Some ports are always illegal, and some
172aa2aa9a6SDana Myers * ports are only illegal if the BIOS calls _OSI with a WinXP string or
173aa2aa9a6SDana Myers * later (meaning that the BIOS itelf is post-XP.)
174aa2aa9a6SDana Myers *
175aa2aa9a6SDana Myers * This provides ACPICA with the desired port protections and
176aa2aa9a6SDana Myers * Microsoft compatibility.
177aa2aa9a6SDana Myers *
178aa2aa9a6SDana Myers * Description of port entries:
179aa2aa9a6SDana Myers * DMA: DMA controller
180aa2aa9a6SDana Myers * PIC0: Programmable Interrupt Controller (8259A)
181aa2aa9a6SDana Myers * PIT1: System Timer 1
182aa2aa9a6SDana Myers * PIT2: System Timer 2 failsafe
183aa2aa9a6SDana Myers * RTC: Real-time clock
184aa2aa9a6SDana Myers * CMOS: Extended CMOS
185aa2aa9a6SDana Myers * DMA1: DMA 1 page registers
186aa2aa9a6SDana Myers * DMA1L: DMA 1 Ch 0 low page
187aa2aa9a6SDana Myers * DMA2: DMA 2 page registers
188aa2aa9a6SDana Myers * DMA2L: DMA 2 low page refresh
189aa2aa9a6SDana Myers * ARBC: Arbitration control
190aa2aa9a6SDana Myers * SETUP: Reserved system board setup
191aa2aa9a6SDana Myers * POS: POS channel select
192aa2aa9a6SDana Myers * PIC1: Cascaded PIC
193aa2aa9a6SDana Myers * IDMA: ISA DMA
194aa2aa9a6SDana Myers * ELCR: PIC edge/level registers
195aa2aa9a6SDana Myers * PCI: PCI configuration space
196aa2aa9a6SDana Myers */
197aa2aa9a6SDana Myers static const ACPI_PORT_INFO AcpiProtectedPorts[] =
198aa2aa9a6SDana Myers {
199aa2aa9a6SDana Myers {"DMA", 0x0000, 0x000F, ACPI_OSI_WIN_XP},
200aa2aa9a6SDana Myers {"PIC0", 0x0020, 0x0021, ACPI_ALWAYS_ILLEGAL},
201aa2aa9a6SDana Myers {"PIT1", 0x0040, 0x0043, ACPI_OSI_WIN_XP},
202aa2aa9a6SDana Myers {"PIT2", 0x0048, 0x004B, ACPI_OSI_WIN_XP},
203aa2aa9a6SDana Myers {"RTC", 0x0070, 0x0071, ACPI_OSI_WIN_XP},
204aa2aa9a6SDana Myers {"CMOS", 0x0074, 0x0076, ACPI_OSI_WIN_XP},
205aa2aa9a6SDana Myers {"DMA1", 0x0081, 0x0083, ACPI_OSI_WIN_XP},
206aa2aa9a6SDana Myers {"DMA1L", 0x0087, 0x0087, ACPI_OSI_WIN_XP},
207aa2aa9a6SDana Myers {"DMA2", 0x0089, 0x008B, ACPI_OSI_WIN_XP},
208aa2aa9a6SDana Myers {"DMA2L", 0x008F, 0x008F, ACPI_OSI_WIN_XP},
209aa2aa9a6SDana Myers {"ARBC", 0x0090, 0x0091, ACPI_OSI_WIN_XP},
210aa2aa9a6SDana Myers {"SETUP", 0x0093, 0x0094, ACPI_OSI_WIN_XP},
211aa2aa9a6SDana Myers {"POS", 0x0096, 0x0097, ACPI_OSI_WIN_XP},
212aa2aa9a6SDana Myers {"PIC1", 0x00A0, 0x00A1, ACPI_ALWAYS_ILLEGAL},
213aa2aa9a6SDana Myers {"IDMA", 0x00C0, 0x00DF, ACPI_OSI_WIN_XP},
214aa2aa9a6SDana Myers {"ELCR", 0x04D0, 0x04D1, ACPI_ALWAYS_ILLEGAL},
215aa2aa9a6SDana Myers {"PCI", 0x0CF8, 0x0CFF, ACPI_OSI_WIN_XP}
216aa2aa9a6SDana Myers };
217aa2aa9a6SDana Myers
218*35786f68SRobert Mustacchi #define ACPI_PORT_INFO_ENTRIES ACPI_ARRAY_LENGTH (AcpiProtectedPorts)
219aa2aa9a6SDana Myers
220aa2aa9a6SDana Myers
221aa2aa9a6SDana Myers /******************************************************************************
222aa2aa9a6SDana Myers *
223aa2aa9a6SDana Myers * FUNCTION: AcpiHwValidateIoRequest
224aa2aa9a6SDana Myers *
225aa2aa9a6SDana Myers * PARAMETERS: Address Address of I/O port/register
226aa2aa9a6SDana Myers * BitWidth Number of bits (8,16,32)
227aa2aa9a6SDana Myers *
228aa2aa9a6SDana Myers * RETURN: Status
229aa2aa9a6SDana Myers *
230aa2aa9a6SDana Myers * DESCRIPTION: Validates an I/O request (address/length). Certain ports are
231aa2aa9a6SDana Myers * always illegal and some ports are only illegal depending on
232aa2aa9a6SDana Myers * the requests the BIOS AML code makes to the predefined
233aa2aa9a6SDana Myers * _OSI method.
234aa2aa9a6SDana Myers *
235aa2aa9a6SDana Myers ******************************************************************************/
236aa2aa9a6SDana Myers
237aa2aa9a6SDana Myers static ACPI_STATUS
AcpiHwValidateIoRequest(ACPI_IO_ADDRESS Address,UINT32 BitWidth)238aa2aa9a6SDana Myers AcpiHwValidateIoRequest (
239aa2aa9a6SDana Myers ACPI_IO_ADDRESS Address,
240aa2aa9a6SDana Myers UINT32 BitWidth)
241aa2aa9a6SDana Myers {
242aa2aa9a6SDana Myers UINT32 i;
243aa2aa9a6SDana Myers UINT32 ByteWidth;
244aa2aa9a6SDana Myers ACPI_IO_ADDRESS LastAddress;
245aa2aa9a6SDana Myers const ACPI_PORT_INFO *PortInfo;
246aa2aa9a6SDana Myers
247aa2aa9a6SDana Myers
248aa2aa9a6SDana Myers ACPI_FUNCTION_TRACE (HwValidateIoRequest);
249aa2aa9a6SDana Myers
250aa2aa9a6SDana Myers
251aa2aa9a6SDana Myers /* Supported widths are 8/16/32 */
252aa2aa9a6SDana Myers
253aa2aa9a6SDana Myers if ((BitWidth != 8) &&
254aa2aa9a6SDana Myers (BitWidth != 16) &&
255aa2aa9a6SDana Myers (BitWidth != 32))
256aa2aa9a6SDana Myers {
2577b1019a6SJerry Jelinek ACPI_ERROR ((AE_INFO,
2587b1019a6SJerry Jelinek "Bad BitWidth parameter: %8.8X", BitWidth));
259*35786f68SRobert Mustacchi return_ACPI_STATUS (AE_BAD_PARAMETER);
260aa2aa9a6SDana Myers }
261aa2aa9a6SDana Myers
262aa2aa9a6SDana Myers PortInfo = AcpiProtectedPorts;
263aa2aa9a6SDana Myers ByteWidth = ACPI_DIV_8 (BitWidth);
264aa2aa9a6SDana Myers LastAddress = Address + ByteWidth - 1;
265aa2aa9a6SDana Myers
266*35786f68SRobert Mustacchi ACPI_DEBUG_PRINT ((ACPI_DB_IO,
267*35786f68SRobert Mustacchi "Address %8.8X%8.8X LastAddress %8.8X%8.8X Length %X",
2687b1019a6SJerry Jelinek ACPI_FORMAT_UINT64 (Address), ACPI_FORMAT_UINT64 (LastAddress),
269aa2aa9a6SDana Myers ByteWidth));
270aa2aa9a6SDana Myers
271aa2aa9a6SDana Myers /* Maximum 16-bit address in I/O space */
272aa2aa9a6SDana Myers
273aa2aa9a6SDana Myers if (LastAddress > ACPI_UINT16_MAX)
274aa2aa9a6SDana Myers {
275aa2aa9a6SDana Myers ACPI_ERROR ((AE_INFO,
2767b1019a6SJerry Jelinek "Illegal I/O port address/length above 64K: %8.8X%8.8X/0x%X",
2777b1019a6SJerry Jelinek ACPI_FORMAT_UINT64 (Address), ByteWidth));
278aa2aa9a6SDana Myers return_ACPI_STATUS (AE_LIMIT);
279aa2aa9a6SDana Myers }
280aa2aa9a6SDana Myers
281aa2aa9a6SDana Myers /* Exit if requested address is not within the protected port table */
282aa2aa9a6SDana Myers
283aa2aa9a6SDana Myers if (Address > AcpiProtectedPorts[ACPI_PORT_INFO_ENTRIES - 1].End)
284aa2aa9a6SDana Myers {
285aa2aa9a6SDana Myers return_ACPI_STATUS (AE_OK);
286aa2aa9a6SDana Myers }
287aa2aa9a6SDana Myers
288aa2aa9a6SDana Myers /* Check request against the list of protected I/O ports */
289aa2aa9a6SDana Myers
290aa2aa9a6SDana Myers for (i = 0; i < ACPI_PORT_INFO_ENTRIES; i++, PortInfo++)
291aa2aa9a6SDana Myers {
292aa2aa9a6SDana Myers /*
293aa2aa9a6SDana Myers * Check if the requested address range will write to a reserved
294*35786f68SRobert Mustacchi * port. There are four cases to consider:
295aa2aa9a6SDana Myers *
296aa2aa9a6SDana Myers * 1) Address range is contained completely in the port address range
297aa2aa9a6SDana Myers * 2) Address range overlaps port range at the port range start
298aa2aa9a6SDana Myers * 3) Address range overlaps port range at the port range end
299aa2aa9a6SDana Myers * 4) Address range completely encompasses the port range
300aa2aa9a6SDana Myers */
301aa2aa9a6SDana Myers if ((Address <= PortInfo->End) && (LastAddress >= PortInfo->Start))
302aa2aa9a6SDana Myers {
303aa2aa9a6SDana Myers /* Port illegality may depend on the _OSI calls made by the BIOS */
304aa2aa9a6SDana Myers
305aa2aa9a6SDana Myers if (AcpiGbl_OsiData >= PortInfo->OsiDependency)
306aa2aa9a6SDana Myers {
307*35786f68SRobert Mustacchi ACPI_DEBUG_PRINT ((ACPI_DB_VALUES,
308*35786f68SRobert Mustacchi "Denied AML access to port 0x%8.8X%8.8X/%X (%s 0x%.4X-0x%.4X)\n",
3097b1019a6SJerry Jelinek ACPI_FORMAT_UINT64 (Address), ByteWidth, PortInfo->Name,
310aa2aa9a6SDana Myers PortInfo->Start, PortInfo->End));
311aa2aa9a6SDana Myers
312aa2aa9a6SDana Myers return_ACPI_STATUS (AE_AML_ILLEGAL_ADDRESS);
313aa2aa9a6SDana Myers }
314aa2aa9a6SDana Myers }
315aa2aa9a6SDana Myers
316aa2aa9a6SDana Myers /* Finished if address range ends before the end of this port */
317aa2aa9a6SDana Myers
318aa2aa9a6SDana Myers if (LastAddress <= PortInfo->End)
319aa2aa9a6SDana Myers {
320aa2aa9a6SDana Myers break;
321aa2aa9a6SDana Myers }
322aa2aa9a6SDana Myers }
323aa2aa9a6SDana Myers
324aa2aa9a6SDana Myers return_ACPI_STATUS (AE_OK);
325aa2aa9a6SDana Myers }
326aa2aa9a6SDana Myers
327aa2aa9a6SDana Myers
328aa2aa9a6SDana Myers /******************************************************************************
329aa2aa9a6SDana Myers *
330aa2aa9a6SDana Myers * FUNCTION: AcpiHwReadPort
331aa2aa9a6SDana Myers *
332aa2aa9a6SDana Myers * PARAMETERS: Address Address of I/O port/register to read
333*35786f68SRobert Mustacchi * Value Where value (data) is returned
334aa2aa9a6SDana Myers * Width Number of bits
335aa2aa9a6SDana Myers *
336aa2aa9a6SDana Myers * RETURN: Status and value read from port
337aa2aa9a6SDana Myers *
338aa2aa9a6SDana Myers * DESCRIPTION: Read data from an I/O port or register. This is a front-end
339aa2aa9a6SDana Myers * to AcpiOsReadPort that performs validation on both the port
340aa2aa9a6SDana Myers * address and the length.
341aa2aa9a6SDana Myers *
342aa2aa9a6SDana Myers *****************************************************************************/
343aa2aa9a6SDana Myers
344aa2aa9a6SDana Myers ACPI_STATUS
AcpiHwReadPort(ACPI_IO_ADDRESS Address,UINT32 * Value,UINT32 Width)345aa2aa9a6SDana Myers AcpiHwReadPort (
346aa2aa9a6SDana Myers ACPI_IO_ADDRESS Address,
347aa2aa9a6SDana Myers UINT32 *Value,
348aa2aa9a6SDana Myers UINT32 Width)
349aa2aa9a6SDana Myers {
350aa2aa9a6SDana Myers ACPI_STATUS Status;
351aa2aa9a6SDana Myers UINT32 OneByte;
352aa2aa9a6SDana Myers UINT32 i;
353aa2aa9a6SDana Myers
354aa2aa9a6SDana Myers
35526f3cdf0SGordon Ross /* Truncate address to 16 bits if requested */
35626f3cdf0SGordon Ross
35726f3cdf0SGordon Ross if (AcpiGbl_TruncateIoAddresses)
35826f3cdf0SGordon Ross {
35926f3cdf0SGordon Ross Address &= ACPI_UINT16_MAX;
36026f3cdf0SGordon Ross }
36126f3cdf0SGordon Ross
362aa2aa9a6SDana Myers /* Validate the entire request and perform the I/O */
363aa2aa9a6SDana Myers
364aa2aa9a6SDana Myers Status = AcpiHwValidateIoRequest (Address, Width);
365aa2aa9a6SDana Myers if (ACPI_SUCCESS (Status))
366aa2aa9a6SDana Myers {
367aa2aa9a6SDana Myers Status = AcpiOsReadPort (Address, Value, Width);
368aa2aa9a6SDana Myers return (Status);
369aa2aa9a6SDana Myers }
370aa2aa9a6SDana Myers
371aa2aa9a6SDana Myers if (Status != AE_AML_ILLEGAL_ADDRESS)
372aa2aa9a6SDana Myers {
373aa2aa9a6SDana Myers return (Status);
374aa2aa9a6SDana Myers }
375aa2aa9a6SDana Myers
376aa2aa9a6SDana Myers /*
377aa2aa9a6SDana Myers * There has been a protection violation within the request. Fall
378aa2aa9a6SDana Myers * back to byte granularity port I/O and ignore the failing bytes.
379*35786f68SRobert Mustacchi * This provides compatibility with other ACPI implementations.
380aa2aa9a6SDana Myers */
381aa2aa9a6SDana Myers for (i = 0, *Value = 0; i < Width; i += 8)
382aa2aa9a6SDana Myers {
383aa2aa9a6SDana Myers /* Validate and read one byte */
384aa2aa9a6SDana Myers
385aa2aa9a6SDana Myers if (AcpiHwValidateIoRequest (Address, 8) == AE_OK)
386aa2aa9a6SDana Myers {
387aa2aa9a6SDana Myers Status = AcpiOsReadPort (Address, &OneByte, 8);
388aa2aa9a6SDana Myers if (ACPI_FAILURE (Status))
389aa2aa9a6SDana Myers {
390aa2aa9a6SDana Myers return (Status);
391aa2aa9a6SDana Myers }
392aa2aa9a6SDana Myers
393aa2aa9a6SDana Myers *Value |= (OneByte << i);
394aa2aa9a6SDana Myers }
395aa2aa9a6SDana Myers
396aa2aa9a6SDana Myers Address++;
397aa2aa9a6SDana Myers }
398aa2aa9a6SDana Myers
399aa2aa9a6SDana Myers return (AE_OK);
400aa2aa9a6SDana Myers }
401aa2aa9a6SDana Myers
402aa2aa9a6SDana Myers
403aa2aa9a6SDana Myers /******************************************************************************
404aa2aa9a6SDana Myers *
405aa2aa9a6SDana Myers * FUNCTION: AcpiHwWritePort
406aa2aa9a6SDana Myers *
407aa2aa9a6SDana Myers * PARAMETERS: Address Address of I/O port/register to write
408aa2aa9a6SDana Myers * Value Value to write
409aa2aa9a6SDana Myers * Width Number of bits
410aa2aa9a6SDana Myers *
411aa2aa9a6SDana Myers * RETURN: Status
412aa2aa9a6SDana Myers *
413aa2aa9a6SDana Myers * DESCRIPTION: Write data to an I/O port or register. This is a front-end
414aa2aa9a6SDana Myers * to AcpiOsWritePort that performs validation on both the port
415aa2aa9a6SDana Myers * address and the length.
416aa2aa9a6SDana Myers *
417aa2aa9a6SDana Myers *****************************************************************************/
418aa2aa9a6SDana Myers
419aa2aa9a6SDana Myers ACPI_STATUS
AcpiHwWritePort(ACPI_IO_ADDRESS Address,UINT32 Value,UINT32 Width)420aa2aa9a6SDana Myers AcpiHwWritePort (
421aa2aa9a6SDana Myers ACPI_IO_ADDRESS Address,
422aa2aa9a6SDana Myers UINT32 Value,
423aa2aa9a6SDana Myers UINT32 Width)
424aa2aa9a6SDana Myers {
425aa2aa9a6SDana Myers ACPI_STATUS Status;
426aa2aa9a6SDana Myers UINT32 i;
427aa2aa9a6SDana Myers
428aa2aa9a6SDana Myers
42926f3cdf0SGordon Ross /* Truncate address to 16 bits if requested */
43026f3cdf0SGordon Ross
43126f3cdf0SGordon Ross if (AcpiGbl_TruncateIoAddresses)
43226f3cdf0SGordon Ross {
43326f3cdf0SGordon Ross Address &= ACPI_UINT16_MAX;
43426f3cdf0SGordon Ross }
43526f3cdf0SGordon Ross
436aa2aa9a6SDana Myers /* Validate the entire request and perform the I/O */
437aa2aa9a6SDana Myers
438aa2aa9a6SDana Myers Status = AcpiHwValidateIoRequest (Address, Width);
439aa2aa9a6SDana Myers if (ACPI_SUCCESS (Status))
440aa2aa9a6SDana Myers {
441aa2aa9a6SDana Myers Status = AcpiOsWritePort (Address, Value, Width);
442aa2aa9a6SDana Myers return (Status);
443aa2aa9a6SDana Myers }
444aa2aa9a6SDana Myers
445aa2aa9a6SDana Myers if (Status != AE_AML_ILLEGAL_ADDRESS)
446aa2aa9a6SDana Myers {
447aa2aa9a6SDana Myers return (Status);
448aa2aa9a6SDana Myers }
449aa2aa9a6SDana Myers
450aa2aa9a6SDana Myers /*
451aa2aa9a6SDana Myers * There has been a protection violation within the request. Fall
452aa2aa9a6SDana Myers * back to byte granularity port I/O and ignore the failing bytes.
453*35786f68SRobert Mustacchi * This provides compatibility with other ACPI implementations.
454aa2aa9a6SDana Myers */
455aa2aa9a6SDana Myers for (i = 0; i < Width; i += 8)
456aa2aa9a6SDana Myers {
457aa2aa9a6SDana Myers /* Validate and write one byte */
458aa2aa9a6SDana Myers
459aa2aa9a6SDana Myers if (AcpiHwValidateIoRequest (Address, 8) == AE_OK)
460aa2aa9a6SDana Myers {
461aa2aa9a6SDana Myers Status = AcpiOsWritePort (Address, (Value >> i) & 0xFF, 8);
462aa2aa9a6SDana Myers if (ACPI_FAILURE (Status))
463aa2aa9a6SDana Myers {
464aa2aa9a6SDana Myers return (Status);
465aa2aa9a6SDana Myers }
466aa2aa9a6SDana Myers }
467aa2aa9a6SDana Myers
468aa2aa9a6SDana Myers Address++;
469aa2aa9a6SDana Myers }
470aa2aa9a6SDana Myers
471aa2aa9a6SDana Myers return (AE_OK);
472aa2aa9a6SDana Myers }
473