hwvalid.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. /******************************************************************************
  2. *
  3. * Module Name: hwvalid - I/O request validation
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2009, Intel Corp.
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions, and the following disclaimer,
  15. * without modification.
  16. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  17. * substantially similar to the "NO WARRANTY" disclaimer below
  18. * ("Disclaimer") and any redistribution must be conditioned upon
  19. * including a substantially similar Disclaimer requirement for further
  20. * binary redistribution.
  21. * 3. Neither the names of the above-listed copyright holders nor the names
  22. * of any contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * Alternatively, this software may be distributed under the terms of the
  26. * GNU General Public License ("GPL") version 2 as published by the Free
  27. * Software Foundation.
  28. *
  29. * NO WARRANTY
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  33. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  34. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  35. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  36. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  37. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  38. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  39. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  40. * POSSIBILITY OF SUCH DAMAGES.
  41. */
  42. #include <acpi/acpi.h>
  43. #include "accommon.h"
  44. #define _COMPONENT ACPI_HARDWARE
  45. ACPI_MODULE_NAME("hwvalid")
  46. /* Local prototypes */
  47. static acpi_status
  48. acpi_hw_validate_io_request(acpi_io_address address, u32 bit_width);
  49. /*
  50. * Protected I/O ports. Some ports are always illegal, and some are
  51. * conditionally illegal. This table must remain ordered by port address.
  52. *
  53. * The table is used to implement the Microsoft port access rules that
  54. * first appeared in Windows XP. Some ports are always illegal, and some
  55. * ports are only illegal if the BIOS calls _OSI with a win_xP string or
  56. * later (meaning that the BIOS itelf is post-XP.)
  57. *
  58. * This provides ACPICA with the desired port protections and
  59. * Microsoft compatibility.
  60. *
  61. * Description of port entries:
  62. * DMA: DMA controller
  63. * PIC0: Programmable Interrupt Controller (8259_a)
  64. * PIT1: System Timer 1
  65. * PIT2: System Timer 2 failsafe
  66. * RTC: Real-time clock
  67. * CMOS: Extended CMOS
  68. * DMA1: DMA 1 page registers
  69. * DMA1L: DMA 1 Ch 0 low page
  70. * DMA2: DMA 2 page registers
  71. * DMA2L: DMA 2 low page refresh
  72. * ARBC: Arbitration control
  73. * SETUP: Reserved system board setup
  74. * POS: POS channel select
  75. * PIC1: Cascaded PIC
  76. * IDMA: ISA DMA
  77. * ELCR: PIC edge/level registers
  78. * PCI: PCI configuration space
  79. */
  80. static const struct acpi_port_info acpi_protected_ports[] = {
  81. {"DMA", 0x0000, 0x000F, ACPI_OSI_WIN_XP},
  82. {"PIC0", 0x0020, 0x0021, ACPI_ALWAYS_ILLEGAL},
  83. {"PIT1", 0x0040, 0x0043, ACPI_OSI_WIN_XP},
  84. {"PIT2", 0x0048, 0x004B, ACPI_OSI_WIN_XP},
  85. {"RTC", 0x0070, 0x0071, ACPI_OSI_WIN_XP},
  86. {"CMOS", 0x0074, 0x0076, ACPI_OSI_WIN_XP},
  87. {"DMA1L", 0x0087, 0x0087, ACPI_OSI_WIN_XP},
  88. {"DMA2", 0x0089, 0x008B, ACPI_OSI_WIN_XP},
  89. {"DMA2L", 0x008F, 0x008F, ACPI_OSI_WIN_XP},
  90. {"ARBC", 0x0090, 0x0091, ACPI_OSI_WIN_XP},
  91. {"SETUP", 0x0093, 0x0094, ACPI_OSI_WIN_XP},
  92. {"POS", 0x0096, 0x0097, ACPI_OSI_WIN_XP},
  93. {"PIC1", 0x00A0, 0x00A1, ACPI_ALWAYS_ILLEGAL},
  94. {"IDMA", 0x00C0, 0x00DF, ACPI_OSI_WIN_XP},
  95. {"ELCR", 0x04D0, 0x04D1, ACPI_ALWAYS_ILLEGAL},
  96. {"PCI", 0x0CF8, 0x0CFF, ACPI_OSI_WIN_XP}
  97. };
  98. #define ACPI_PORT_INFO_ENTRIES ACPI_ARRAY_LENGTH (acpi_protected_ports)
  99. /******************************************************************************
  100. *
  101. * FUNCTION: acpi_hw_validate_io_request
  102. *
  103. * PARAMETERS: Address Address of I/O port/register
  104. * bit_width Number of bits (8,16,32)
  105. *
  106. * RETURN: Status
  107. *
  108. * DESCRIPTION: Validates an I/O request (address/length). Certain ports are
  109. * always illegal and some ports are only illegal depending on
  110. * the requests the BIOS AML code makes to the predefined
  111. * _OSI method.
  112. *
  113. ******************************************************************************/
  114. static acpi_status
  115. acpi_hw_validate_io_request(acpi_io_address address, u32 bit_width)
  116. {
  117. u32 i;
  118. u32 byte_width;
  119. acpi_io_address last_address;
  120. const struct acpi_port_info *port_info;
  121. ACPI_FUNCTION_TRACE(hw_validate_io_request);
  122. /* Supported widths are 8/16/32 */
  123. if ((bit_width != 8) && (bit_width != 16) && (bit_width != 32)) {
  124. return AE_BAD_PARAMETER;
  125. }
  126. port_info = acpi_protected_ports;
  127. byte_width = ACPI_DIV_8(bit_width);
  128. last_address = address + byte_width - 1;
  129. ACPI_DEBUG_PRINT((ACPI_DB_IO, "Address %p LastAddress %p Length %X",
  130. ACPI_CAST_PTR(void, address), ACPI_CAST_PTR(void,
  131. last_address),
  132. byte_width));
  133. /* Maximum 16-bit address in I/O space */
  134. if (last_address > ACPI_UINT16_MAX) {
  135. ACPI_ERROR((AE_INFO,
  136. "Illegal I/O port address/length above 64K: 0x%p/%X",
  137. ACPI_CAST_PTR(void, address), byte_width));
  138. return_ACPI_STATUS(AE_AML_ILLEGAL_ADDRESS);
  139. }
  140. /* Exit if requested address is not within the protected port table */
  141. if (address > acpi_protected_ports[ACPI_PORT_INFO_ENTRIES - 1].end) {
  142. return_ACPI_STATUS(AE_OK);
  143. }
  144. /* Check request against the list of protected I/O ports */
  145. for (i = 0; i < ACPI_PORT_INFO_ENTRIES; i++, port_info++) {
  146. /*
  147. * Check if the requested address range will write to a reserved
  148. * port. Four cases to consider:
  149. *
  150. * 1) Address range is contained completely in the port address range
  151. * 2) Address range overlaps port range at the port range start
  152. * 3) Address range overlaps port range at the port range end
  153. * 4) Address range completely encompasses the port range
  154. */
  155. if ((address <= port_info->end)
  156. && (last_address >= port_info->start)) {
  157. /* Port illegality may depend on the _OSI calls made by the BIOS */
  158. if (acpi_gbl_osi_data >= port_info->osi_dependency) {
  159. ACPI_ERROR((AE_INFO,
  160. "Denied AML access to port 0x%p/%X (%s 0x%.4X-0x%.4X)",
  161. ACPI_CAST_PTR(void, address),
  162. byte_width, port_info->name,
  163. port_info->start, port_info->end));
  164. return_ACPI_STATUS(AE_AML_ILLEGAL_ADDRESS);
  165. }
  166. }
  167. /* Finished if address range ends before the end of this port */
  168. if (last_address <= port_info->end) {
  169. break;
  170. }
  171. }
  172. return_ACPI_STATUS(AE_OK);
  173. }
  174. /******************************************************************************
  175. *
  176. * FUNCTION: acpi_hw_read_port
  177. *
  178. * PARAMETERS: Address Address of I/O port/register to read
  179. * Value Where value is placed
  180. * Width Number of bits
  181. *
  182. * RETURN: Value read from port
  183. *
  184. * DESCRIPTION: Read data from an I/O port or register. This is a front-end
  185. * to acpi_os_read_port that performs validation on both the port
  186. * address and the length.
  187. *
  188. *****************************************************************************/
  189. acpi_status acpi_hw_read_port(acpi_io_address address, u32 *value, u32 width)
  190. {
  191. acpi_status status;
  192. status = acpi_hw_validate_io_request(address, width);
  193. if (ACPI_FAILURE(status)) {
  194. return status;
  195. }
  196. status = acpi_os_read_port(address, value, width);
  197. return status;
  198. }
  199. /******************************************************************************
  200. *
  201. * FUNCTION: acpi_hw_write_port
  202. *
  203. * PARAMETERS: Address Address of I/O port/register to write
  204. * Value Value to write
  205. * Width Number of bits
  206. *
  207. * RETURN: None
  208. *
  209. * DESCRIPTION: Write data to an I/O port or register. This is a front-end
  210. * to acpi_os_write_port that performs validation on both the port
  211. * address and the length.
  212. *
  213. *****************************************************************************/
  214. acpi_status acpi_hw_write_port(acpi_io_address address, u32 value, u32 width)
  215. {
  216. acpi_status status;
  217. status = acpi_hw_validate_io_request(address, width);
  218. if (ACPI_FAILURE(status)) {
  219. return status;
  220. }
  221. status = acpi_os_write_port(address, value, width);
  222. return status;
  223. }