1
2
3
4
5
6
7
8
9
10#include <acpi/acpi.h>
11#include "accommon.h"
12#include "acinterp.h"
13
14#define _COMPONENT ACPI_EXECUTER
15ACPI_MODULE_NAME("exregion")
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34acpi_status
35acpi_ex_system_memory_space_handler(u32 function,
36 acpi_physical_address address,
37 u32 bit_width,
38 u64 *value,
39 void *handler_context, void *region_context)
40{
41 acpi_status status = AE_OK;
42 void *logical_addr_ptr = NULL;
43 struct acpi_mem_space_context *mem_info = region_context;
44 struct acpi_mem_mapping *mm = mem_info->cur_mm;
45 u32 length;
46 acpi_size map_length;
47 acpi_size page_boundary_map_length;
48#ifdef ACPI_MISALIGNMENT_NOT_SUPPORTED
49 u32 remainder;
50#endif
51
52 ACPI_FUNCTION_TRACE(ex_system_memory_space_handler);
53
54
55
56 switch (bit_width) {
57 case 8:
58
59 length = 1;
60 break;
61
62 case 16:
63
64 length = 2;
65 break;
66
67 case 32:
68
69 length = 4;
70 break;
71
72 case 64:
73
74 length = 8;
75 break;
76
77 default:
78
79 ACPI_ERROR((AE_INFO, "Invalid SystemMemory width %u",
80 bit_width));
81 return_ACPI_STATUS(AE_AML_OPERAND_VALUE);
82 }
83
84#ifdef ACPI_MISALIGNMENT_NOT_SUPPORTED
85
86
87
88
89 (void)acpi_ut_short_divide((u64) address, length, NULL, &remainder);
90 if (remainder != 0) {
91 return_ACPI_STATUS(AE_AML_ALIGNMENT);
92 }
93#endif
94
95
96
97
98
99
100 if (!mm || (address < mm->physical_address) ||
101 ((u64) address + length > (u64) mm->physical_address + mm->length)) {
102
103
104
105
106
107
108
109 for (mm = mem_info->first_mm; mm; mm = mm->next_mm) {
110 if (mm == mem_info->cur_mm)
111 continue;
112
113 if (address < mm->physical_address)
114 continue;
115
116 if ((u64) address + length >
117 (u64) mm->physical_address + mm->length)
118 continue;
119
120 mem_info->cur_mm = mm;
121 goto access;
122 }
123
124
125 mm = ACPI_ALLOCATE_ZEROED(sizeof(*mm));
126 if (!mm) {
127 ACPI_ERROR((AE_INFO,
128 "Unable to save memory mapping at 0x%8.8X%8.8X, size %u",
129 ACPI_FORMAT_UINT64(address), length));
130 return_ACPI_STATUS(AE_NO_MEMORY);
131 }
132
133
134
135
136
137
138 map_length = (acpi_size)
139 ((mem_info->address + mem_info->length) - address);
140
141
142
143
144
145
146
147
148
149
150
151
152 page_boundary_map_length = (acpi_size)
153 (ACPI_ROUND_UP(address, ACPI_DEFAULT_PAGE_SIZE) - address);
154 if (page_boundary_map_length == 0) {
155 page_boundary_map_length = ACPI_DEFAULT_PAGE_SIZE;
156 }
157
158 if (map_length > page_boundary_map_length) {
159 map_length = page_boundary_map_length;
160 }
161
162
163
164 logical_addr_ptr = acpi_os_map_memory(address, map_length);
165 if (!logical_addr_ptr) {
166 ACPI_ERROR((AE_INFO,
167 "Could not map memory at 0x%8.8X%8.8X, size %u",
168 ACPI_FORMAT_UINT64(address),
169 (u32)map_length));
170 ACPI_FREE(mm);
171 return_ACPI_STATUS(AE_NO_MEMORY);
172 }
173
174
175
176 mm->logical_address = logical_addr_ptr;
177 mm->physical_address = address;
178 mm->length = map_length;
179
180
181
182
183
184 mm->next_mm = mem_info->first_mm;
185 mem_info->first_mm = mm;
186
187 mem_info->cur_mm = mm;
188 }
189
190access:
191
192
193
194
195 logical_addr_ptr = mm->logical_address +
196 ((u64) address - (u64) mm->physical_address);
197
198 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
199 "System-Memory (width %u) R/W %u Address=%8.8X%8.8X\n",
200 bit_width, function, ACPI_FORMAT_UINT64(address)));
201
202
203
204
205
206
207
208
209
210 switch (function) {
211 case ACPI_READ:
212
213 *value = 0;
214 switch (bit_width) {
215 case 8:
216
217 *value = (u64)ACPI_GET8(logical_addr_ptr);
218 break;
219
220 case 16:
221
222 *value = (u64)ACPI_GET16(logical_addr_ptr);
223 break;
224
225 case 32:
226
227 *value = (u64)ACPI_GET32(logical_addr_ptr);
228 break;
229
230 case 64:
231
232 *value = (u64)ACPI_GET64(logical_addr_ptr);
233 break;
234
235 default:
236
237
238
239 break;
240 }
241 break;
242
243 case ACPI_WRITE:
244
245 switch (bit_width) {
246 case 8:
247
248 ACPI_SET8(logical_addr_ptr, *value);
249 break;
250
251 case 16:
252
253 ACPI_SET16(logical_addr_ptr, *value);
254 break;
255
256 case 32:
257
258 ACPI_SET32(logical_addr_ptr, *value);
259 break;
260
261 case 64:
262
263 ACPI_SET64(logical_addr_ptr, *value);
264 break;
265
266 default:
267
268
269
270 break;
271 }
272 break;
273
274 default:
275
276 status = AE_BAD_PARAMETER;
277 break;
278 }
279
280 return_ACPI_STATUS(status);
281}
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301acpi_status
302acpi_ex_system_io_space_handler(u32 function,
303 acpi_physical_address address,
304 u32 bit_width,
305 u64 *value,
306 void *handler_context, void *region_context)
307{
308 acpi_status status = AE_OK;
309 u32 value32;
310
311 ACPI_FUNCTION_TRACE(ex_system_io_space_handler);
312
313 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
314 "System-IO (width %u) R/W %u Address=%8.8X%8.8X\n",
315 bit_width, function, ACPI_FORMAT_UINT64(address)));
316
317
318
319 switch (function) {
320 case ACPI_READ:
321
322 status = acpi_hw_read_port((acpi_io_address)address,
323 &value32, bit_width);
324 *value = value32;
325 break;
326
327 case ACPI_WRITE:
328
329 status = acpi_hw_write_port((acpi_io_address)address,
330 (u32)*value, bit_width);
331 break;
332
333 default:
334
335 status = AE_BAD_PARAMETER;
336 break;
337 }
338
339 return_ACPI_STATUS(status);
340}
341
342#ifdef ACPI_PCI_CONFIGURED
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361acpi_status
362acpi_ex_pci_config_space_handler(u32 function,
363 acpi_physical_address address,
364 u32 bit_width,
365 u64 *value,
366 void *handler_context, void *region_context)
367{
368 acpi_status status = AE_OK;
369 struct acpi_pci_id *pci_id;
370 u16 pci_register;
371
372 ACPI_FUNCTION_TRACE(ex_pci_config_space_handler);
373
374
375
376
377
378
379
380
381
382
383
384
385
386 pci_id = (struct acpi_pci_id *)region_context;
387 pci_register = (u16) (u32) address;
388
389 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
390 "Pci-Config %u (%u) Seg(%04x) Bus(%04x) "
391 "Dev(%04x) Func(%04x) Reg(%04x)\n",
392 function, bit_width, pci_id->segment, pci_id->bus,
393 pci_id->device, pci_id->function, pci_register));
394
395 switch (function) {
396 case ACPI_READ:
397
398 *value = 0;
399 status =
400 acpi_os_read_pci_configuration(pci_id, pci_register, value,
401 bit_width);
402 break;
403
404 case ACPI_WRITE:
405
406 status =
407 acpi_os_write_pci_configuration(pci_id, pci_register,
408 *value, bit_width);
409 break;
410
411 default:
412
413 status = AE_BAD_PARAMETER;
414 break;
415 }
416
417 return_ACPI_STATUS(status);
418}
419#endif
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439acpi_status
440acpi_ex_cmos_space_handler(u32 function,
441 acpi_physical_address address,
442 u32 bit_width,
443 u64 *value,
444 void *handler_context, void *region_context)
445{
446 acpi_status status = AE_OK;
447
448 ACPI_FUNCTION_TRACE(ex_cmos_space_handler);
449
450 return_ACPI_STATUS(status);
451}
452
453#ifdef ACPI_PCI_CONFIGURED
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472acpi_status
473acpi_ex_pci_bar_space_handler(u32 function,
474 acpi_physical_address address,
475 u32 bit_width,
476 u64 *value,
477 void *handler_context, void *region_context)
478{
479 acpi_status status = AE_OK;
480
481 ACPI_FUNCTION_TRACE(ex_pci_bar_space_handler);
482
483 return_ACPI_STATUS(status);
484}
485#endif
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505acpi_status
506acpi_ex_data_table_space_handler(u32 function,
507 acpi_physical_address address,
508 u32 bit_width,
509 u64 *value,
510 void *handler_context, void *region_context)
511{
512 ACPI_FUNCTION_TRACE(ex_data_table_space_handler);
513
514
515
516
517
518 switch (function) {
519 case ACPI_READ:
520
521 memcpy(ACPI_CAST_PTR(char, value),
522 ACPI_PHYSADDR_TO_PTR(address), ACPI_DIV_8(bit_width));
523 break;
524
525 case ACPI_WRITE:
526
527 memcpy(ACPI_PHYSADDR_TO_PTR(address),
528 ACPI_CAST_PTR(char, value), ACPI_DIV_8(bit_width));
529 break;
530
531 default:
532
533 return_ACPI_STATUS(AE_BAD_PARAMETER);
534 }
535
536 return_ACPI_STATUS(AE_OK);
537}
538