Indentation fix, cleanup.
[AROS.git] / arch / all-pc / acpica / source / components / hardware / hwvalid.c
blob832ca4acd9264ff95d1c58271a110191b638ffca
1 /******************************************************************************
3 * Module Name: hwvalid - I/O request validation
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2013, Intel Corp.
9 * All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
44 #define __HWVALID_C__
46 #include "acpi.h"
47 #include "accommon.h"
49 #define _COMPONENT ACPI_HARDWARE
50 ACPI_MODULE_NAME ("hwvalid")
52 /* Local prototypes */
54 static ACPI_STATUS
55 AcpiHwValidateIoRequest (
56 ACPI_IO_ADDRESS Address,
57 UINT32 BitWidth);
61 * Protected I/O ports. Some ports are always illegal, and some are
62 * conditionally illegal. This table must remain ordered by port address.
64 * The table is used to implement the Microsoft port access rules that
65 * first appeared in Windows XP. Some ports are always illegal, and some
66 * ports are only illegal if the BIOS calls _OSI with a WinXP string or
67 * later (meaning that the BIOS itelf is post-XP.)
69 * This provides ACPICA with the desired port protections and
70 * Microsoft compatibility.
72 * Description of port entries:
73 * DMA: DMA controller
74 * PIC0: Programmable Interrupt Controller (8259A)
75 * PIT1: System Timer 1
76 * PIT2: System Timer 2 failsafe
77 * RTC: Real-time clock
78 * CMOS: Extended CMOS
79 * DMA1: DMA 1 page registers
80 * DMA1L: DMA 1 Ch 0 low page
81 * DMA2: DMA 2 page registers
82 * DMA2L: DMA 2 low page refresh
83 * ARBC: Arbitration control
84 * SETUP: Reserved system board setup
85 * POS: POS channel select
86 * PIC1: Cascaded PIC
87 * IDMA: ISA DMA
88 * ELCR: PIC edge/level registers
89 * PCI: PCI configuration space
91 static const ACPI_PORT_INFO AcpiProtectedPorts[] =
93 {"DMA", 0x0000, 0x000F, ACPI_OSI_WIN_XP},
94 {"PIC0", 0x0020, 0x0021, ACPI_ALWAYS_ILLEGAL},
95 {"PIT1", 0x0040, 0x0043, ACPI_OSI_WIN_XP},
96 {"PIT2", 0x0048, 0x004B, ACPI_OSI_WIN_XP},
97 {"RTC", 0x0070, 0x0071, ACPI_OSI_WIN_XP},
98 {"CMOS", 0x0074, 0x0076, ACPI_OSI_WIN_XP},
99 {"DMA1", 0x0081, 0x0083, ACPI_OSI_WIN_XP},
100 {"DMA1L", 0x0087, 0x0087, ACPI_OSI_WIN_XP},
101 {"DMA2", 0x0089, 0x008B, ACPI_OSI_WIN_XP},
102 {"DMA2L", 0x008F, 0x008F, ACPI_OSI_WIN_XP},
103 {"ARBC", 0x0090, 0x0091, ACPI_OSI_WIN_XP},
104 {"SETUP", 0x0093, 0x0094, ACPI_OSI_WIN_XP},
105 {"POS", 0x0096, 0x0097, ACPI_OSI_WIN_XP},
106 {"PIC1", 0x00A0, 0x00A1, ACPI_ALWAYS_ILLEGAL},
107 {"IDMA", 0x00C0, 0x00DF, ACPI_OSI_WIN_XP},
108 {"ELCR", 0x04D0, 0x04D1, ACPI_ALWAYS_ILLEGAL},
109 {"PCI", 0x0CF8, 0x0CFF, ACPI_OSI_WIN_XP}
112 #define ACPI_PORT_INFO_ENTRIES ACPI_ARRAY_LENGTH (AcpiProtectedPorts)
115 /******************************************************************************
117 * FUNCTION: AcpiHwValidateIoRequest
119 * PARAMETERS: Address Address of I/O port/register
120 * BitWidth Number of bits (8,16,32)
122 * RETURN: Status
124 * DESCRIPTION: Validates an I/O request (address/length). Certain ports are
125 * always illegal and some ports are only illegal depending on
126 * the requests the BIOS AML code makes to the predefined
127 * _OSI method.
129 ******************************************************************************/
131 static ACPI_STATUS
132 AcpiHwValidateIoRequest (
133 ACPI_IO_ADDRESS Address,
134 UINT32 BitWidth)
136 UINT32 i;
137 UINT32 ByteWidth;
138 ACPI_IO_ADDRESS LastAddress;
139 const ACPI_PORT_INFO *PortInfo;
142 ACPI_FUNCTION_TRACE (HwValidateIoRequest);
145 /* Supported widths are 8/16/32 */
147 if ((BitWidth != 8) &&
148 (BitWidth != 16) &&
149 (BitWidth != 32))
151 ACPI_ERROR ((AE_INFO,
152 "Bad BitWidth parameter: %8.8X", BitWidth));
153 return (AE_BAD_PARAMETER);
156 PortInfo = AcpiProtectedPorts;
157 ByteWidth = ACPI_DIV_8 (BitWidth);
158 LastAddress = Address + ByteWidth - 1;
160 ACPI_DEBUG_PRINT ((ACPI_DB_IO, "Address %p LastAddress %p Length %X",
161 ACPI_CAST_PTR (void, Address), ACPI_CAST_PTR (void, LastAddress),
162 ByteWidth));
164 /* Maximum 16-bit address in I/O space */
166 if (LastAddress > ACPI_UINT16_MAX)
168 ACPI_ERROR ((AE_INFO,
169 "Illegal I/O port address/length above 64K: %p/0x%X",
170 ACPI_CAST_PTR (void, Address), ByteWidth));
171 return_ACPI_STATUS (AE_LIMIT);
174 /* Exit if requested address is not within the protected port table */
176 if (Address > AcpiProtectedPorts[ACPI_PORT_INFO_ENTRIES - 1].End)
178 return_ACPI_STATUS (AE_OK);
181 /* Check request against the list of protected I/O ports */
183 for (i = 0; i < ACPI_PORT_INFO_ENTRIES; i++, PortInfo++)
186 * Check if the requested address range will write to a reserved
187 * port. Four cases to consider:
189 * 1) Address range is contained completely in the port address range
190 * 2) Address range overlaps port range at the port range start
191 * 3) Address range overlaps port range at the port range end
192 * 4) Address range completely encompasses the port range
194 if ((Address <= PortInfo->End) && (LastAddress >= PortInfo->Start))
196 /* Port illegality may depend on the _OSI calls made by the BIOS */
198 if (AcpiGbl_OsiData >= PortInfo->OsiDependency)
200 ACPI_DEBUG_PRINT ((ACPI_DB_IO,
201 "Denied AML access to port 0x%p/%X (%s 0x%.4X-0x%.4X)",
202 ACPI_CAST_PTR (void, Address), ByteWidth, PortInfo->Name,
203 PortInfo->Start, PortInfo->End));
205 return_ACPI_STATUS (AE_AML_ILLEGAL_ADDRESS);
209 /* Finished if address range ends before the end of this port */
211 if (LastAddress <= PortInfo->End)
213 break;
217 return_ACPI_STATUS (AE_OK);
221 /******************************************************************************
223 * FUNCTION: AcpiHwReadPort
225 * PARAMETERS: Address Address of I/O port/register to read
226 * Value Where value is placed
227 * Width Number of bits
229 * RETURN: Status and value read from port
231 * DESCRIPTION: Read data from an I/O port or register. This is a front-end
232 * to AcpiOsReadPort that performs validation on both the port
233 * address and the length.
235 *****************************************************************************/
237 ACPI_STATUS
238 AcpiHwReadPort (
239 ACPI_IO_ADDRESS Address,
240 UINT32 *Value,
241 UINT32 Width)
243 ACPI_STATUS Status;
244 UINT32 OneByte;
245 UINT32 i;
248 /* Truncate address to 16 bits if requested */
250 if (AcpiGbl_TruncateIoAddresses)
252 Address &= ACPI_UINT16_MAX;
255 /* Validate the entire request and perform the I/O */
257 Status = AcpiHwValidateIoRequest (Address, Width);
258 if (ACPI_SUCCESS (Status))
260 Status = AcpiOsReadPort (Address, Value, Width);
261 return (Status);
264 if (Status != AE_AML_ILLEGAL_ADDRESS)
266 return (Status);
270 * There has been a protection violation within the request. Fall
271 * back to byte granularity port I/O and ignore the failing bytes.
272 * This provides Windows compatibility.
274 for (i = 0, *Value = 0; i < Width; i += 8)
276 /* Validate and read one byte */
278 if (AcpiHwValidateIoRequest (Address, 8) == AE_OK)
280 Status = AcpiOsReadPort (Address, &OneByte, 8);
281 if (ACPI_FAILURE (Status))
283 return (Status);
286 *Value |= (OneByte << i);
289 Address++;
292 return (AE_OK);
296 /******************************************************************************
298 * FUNCTION: AcpiHwWritePort
300 * PARAMETERS: Address Address of I/O port/register to write
301 * Value Value to write
302 * Width Number of bits
304 * RETURN: Status
306 * DESCRIPTION: Write data to an I/O port or register. This is a front-end
307 * to AcpiOsWritePort that performs validation on both the port
308 * address and the length.
310 *****************************************************************************/
312 ACPI_STATUS
313 AcpiHwWritePort (
314 ACPI_IO_ADDRESS Address,
315 UINT32 Value,
316 UINT32 Width)
318 ACPI_STATUS Status;
319 UINT32 i;
322 /* Truncate address to 16 bits if requested */
324 if (AcpiGbl_TruncateIoAddresses)
326 Address &= ACPI_UINT16_MAX;
329 /* Validate the entire request and perform the I/O */
331 Status = AcpiHwValidateIoRequest (Address, Width);
332 if (ACPI_SUCCESS (Status))
334 Status = AcpiOsWritePort (Address, Value, Width);
335 return (Status);
338 if (Status != AE_AML_ILLEGAL_ADDRESS)
340 return (Status);
344 * There has been a protection violation within the request. Fall
345 * back to byte granularity port I/O and ignore the failing bytes.
346 * This provides Windows compatibility.
348 for (i = 0; i < Width; i += 8)
350 /* Validate and write one byte */
352 if (AcpiHwValidateIoRequest (Address, 8) == AE_OK)
354 Status = AcpiOsWritePort (Address, (Value >> i) & 0xFF, 8);
355 if (ACPI_FAILURE (Status))
357 return (Status);
361 Address++;
364 return (AE_OK);