1
2
3
4
5
6
7
8
9
10#include <acpi/acpi.h>
11#include "accommon.h"
12
13#define _COMPONENT ACPI_HARDWARE
14ACPI_MODULE_NAME("hwvalid")
15
16
17static acpi_status
18acpi_hw_validate_io_request(acpi_io_address address, u32 bit_width);
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51static const struct acpi_port_info acpi_protected_ports[] = {
52 {"DMA", 0x0000, 0x000F, ACPI_OSI_WIN_XP},
53 {"PIC0", 0x0020, 0x0021, ACPI_ALWAYS_ILLEGAL},
54 {"PIT1", 0x0040, 0x0043, ACPI_OSI_WIN_XP},
55 {"PIT2", 0x0048, 0x004B, ACPI_OSI_WIN_XP},
56 {"RTC", 0x0070, 0x0071, ACPI_OSI_WIN_XP},
57 {"CMOS", 0x0074, 0x0076, ACPI_OSI_WIN_XP},
58 {"DMA1", 0x0081, 0x0083, ACPI_OSI_WIN_XP},
59 {"DMA1L", 0x0087, 0x0087, ACPI_OSI_WIN_XP},
60 {"DMA2", 0x0089, 0x008B, ACPI_OSI_WIN_XP},
61 {"DMA2L", 0x008F, 0x008F, ACPI_OSI_WIN_XP},
62 {"ARBC", 0x0090, 0x0091, ACPI_OSI_WIN_XP},
63 {"SETUP", 0x0093, 0x0094, ACPI_OSI_WIN_XP},
64 {"POS", 0x0096, 0x0097, ACPI_OSI_WIN_XP},
65 {"PIC1", 0x00A0, 0x00A1, ACPI_ALWAYS_ILLEGAL},
66 {"IDMA", 0x00C0, 0x00DF, ACPI_OSI_WIN_XP},
67 {"ELCR", 0x04D0, 0x04D1, ACPI_ALWAYS_ILLEGAL},
68 {"PCI", 0x0CF8, 0x0CFF, ACPI_OSI_WIN_XP}
69};
70
71#define ACPI_PORT_INFO_ENTRIES ACPI_ARRAY_LENGTH (acpi_protected_ports)
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89static acpi_status
90acpi_hw_validate_io_request(acpi_io_address address, u32 bit_width)
91{
92 u32 i;
93 u32 byte_width;
94 acpi_io_address last_address;
95 const struct acpi_port_info *port_info;
96
97 ACPI_FUNCTION_TRACE(hw_validate_io_request);
98
99
100
101 if ((bit_width != 8) && (bit_width != 16) && (bit_width != 32)) {
102 ACPI_ERROR((AE_INFO,
103 "Bad BitWidth parameter: %8.8X", bit_width));
104 return_ACPI_STATUS(AE_BAD_PARAMETER);
105 }
106
107 port_info = acpi_protected_ports;
108 byte_width = ACPI_DIV_8(bit_width);
109 last_address = address + byte_width - 1;
110
111 ACPI_DEBUG_PRINT((ACPI_DB_IO,
112 "Address %8.8X%8.8X LastAddress %8.8X%8.8X Length %X",
113 ACPI_FORMAT_UINT64(address),
114 ACPI_FORMAT_UINT64(last_address), byte_width));
115
116
117
118 if (last_address > ACPI_UINT16_MAX) {
119 ACPI_ERROR((AE_INFO,
120 "Illegal I/O port address/length above 64K: %8.8X%8.8X/0x%X",
121 ACPI_FORMAT_UINT64(address), byte_width));
122 return_ACPI_STATUS(AE_LIMIT);
123 }
124
125
126
127 if (address > acpi_protected_ports[ACPI_PORT_INFO_ENTRIES - 1].end) {
128 return_ACPI_STATUS(AE_OK);
129 }
130
131
132
133 for (i = 0; i < ACPI_PORT_INFO_ENTRIES; i++, port_info++) {
134
135
136
137
138
139
140
141
142
143 if ((address <= port_info->end)
144 && (last_address >= port_info->start)) {
145
146
147
148 if (acpi_gbl_osi_data >= port_info->osi_dependency) {
149 ACPI_DEBUG_PRINT((ACPI_DB_VALUES,
150 "Denied AML access to port 0x%8.8X%8.8X/%X (%s 0x%.4X-0x%.4X)\n",
151 ACPI_FORMAT_UINT64(address),
152 byte_width, port_info->name,
153 port_info->start,
154 port_info->end));
155
156 return_ACPI_STATUS(AE_AML_ILLEGAL_ADDRESS);
157 }
158 }
159
160
161
162 if (last_address <= port_info->end) {
163 break;
164 }
165 }
166
167 return_ACPI_STATUS(AE_OK);
168}
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186acpi_status acpi_hw_read_port(acpi_io_address address, u32 *value, u32 width)
187{
188 acpi_status status;
189 u32 one_byte;
190 u32 i;
191
192
193
194 if (acpi_gbl_truncate_io_addresses) {
195 address &= ACPI_UINT16_MAX;
196 }
197
198
199
200 status = acpi_hw_validate_io_request(address, width);
201 if (ACPI_SUCCESS(status)) {
202 status = acpi_os_read_port(address, value, width);
203 return (status);
204 }
205
206 if (status != AE_AML_ILLEGAL_ADDRESS) {
207 return (status);
208 }
209
210
211
212
213
214
215 for (i = 0, *value = 0; i < width; i += 8) {
216
217
218
219 if (acpi_hw_validate_io_request(address, 8) == AE_OK) {
220 status = acpi_os_read_port(address, &one_byte, 8);
221 if (ACPI_FAILURE(status)) {
222 return (status);
223 }
224
225 *value |= (one_byte << i);
226 }
227
228 address++;
229 }
230
231 return (AE_OK);
232}
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250acpi_status acpi_hw_write_port(acpi_io_address address, u32 value, u32 width)
251{
252 acpi_status status;
253 u32 i;
254
255
256
257 if (acpi_gbl_truncate_io_addresses) {
258 address &= ACPI_UINT16_MAX;
259 }
260
261
262
263 status = acpi_hw_validate_io_request(address, width);
264 if (ACPI_SUCCESS(status)) {
265 status = acpi_os_write_port(address, value, width);
266 return (status);
267 }
268
269 if (status != AE_AML_ILLEGAL_ADDRESS) {
270 return (status);
271 }
272
273
274
275
276
277
278 for (i = 0; i < width; i += 8) {
279
280
281
282 if (acpi_hw_validate_io_request(address, 8) == AE_OK) {
283 status =
284 acpi_os_write_port(address, (value >> i) & 0xFF, 8);
285 if (ACPI_FAILURE(status)) {
286 return (status);
287 }
288 }
289
290 address++;
291 }
292
293 return (AE_OK);
294}
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310acpi_status acpi_hw_validate_io_block(u64 address, u32 bit_width, u32 count)
311{
312 acpi_status status;
313
314 while (count--) {
315 status = acpi_hw_validate_io_request((acpi_io_address)address,
316 bit_width);
317 if (ACPI_FAILURE(status))
318 return_ACPI_STATUS(status);
319
320 address += ACPI_DIV_8(bit_width);
321 }
322
323 return_ACPI_STATUS(AE_OK);
324}
325