aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLv Zheng <lv.zheng@intel.com>2014-07-07 22:06:45 -0400
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2014-07-08 08:22:25 -0400
commit83b80bace4bdfc61abd16ca6ad0a51734a0f57f0 (patch)
treed358faaa07e08a90d88d84238ecd5594fcc125b3
parente8c038a3c6227892e6c0982804b6f9d03fa4b3c5 (diff)
ACPICA: OSL: Clean up acpi_os_printf()/acpi_os_vprintf() stubs
This patch is mainly for acpidump where there are redundant acpi_os_printf()/acpi_os_vprintf() stubs implemented. This patch cleans up such specific implementation by linking acpidump to osunixxf.c/oswinxf.c. To make acpi_os_printf() exported by osunixxf.c/oswinxf.c to behave as the old acpidump specific ones, applications need to: 1. Initialize acpi_gbl_db_output_flags to ACPI_DB_CONSOLE_OUTPUT. This is automatically done by ACPI_INIT_GLOBAL(), applications need to link utglobal.o to utilize this mechanism. 2. Initialize acpi_gbl_output_file to stdout. For GCC, assigning stdout to acpi_gbl_output_file using ACPI_INIT_GLOBAL() is not possible as stdout is not a constant in GCC environment. As an alternative solution, stdout assignment is put into acpi_os_initialize(). Thus acpi_os_initialize() need to be invoked very early by the applications to initialize the default output of acpi_os_printf(). This patch also releases osunixxf.c to the Linux kernel. Lv Zheng. Signed-off-by: Lv Zheng <lv.zheng@intel.com> Signed-off-by: Bob Moore <robert.moore@intel.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
-rw-r--r--drivers/acpi/acpica/acglobal.h3
-rw-r--r--drivers/acpi/acpica/acutils.h1
-rw-r--r--drivers/acpi/acpica/utinit.c1
-rw-r--r--tools/power/acpi/Makefile1
-rw-r--r--tools/power/acpi/os_specific/service_layers/osunixxf.c1304
-rw-r--r--tools/power/acpi/tools/acpidump/apdump.c22
-rw-r--r--tools/power/acpi/tools/acpidump/apmain.c1
7 files changed, 1308 insertions, 25 deletions
diff --git a/drivers/acpi/acpica/acglobal.h b/drivers/acpi/acpica/acglobal.h
index 115eedcade1e..78cc366ca878 100644
--- a/drivers/acpi/acpica/acglobal.h
+++ b/drivers/acpi/acpica/acglobal.h
@@ -297,7 +297,7 @@ ACPI_GLOBAL(u32, acpi_gbl_trace_dbg_layer);
297 * 297 *
298 ****************************************************************************/ 298 ****************************************************************************/
299 299
300ACPI_GLOBAL(u8, acpi_gbl_db_output_flags); 300ACPI_INIT_GLOBAL(u8, acpi_gbl_db_output_flags, ACPI_DB_CONSOLE_OUTPUT);
301 301
302#ifdef ACPI_DISASSEMBLER 302#ifdef ACPI_DISASSEMBLER
303 303
@@ -362,6 +362,7 @@ ACPI_GLOBAL(u32, acpi_gbl_num_objects);
362#ifdef ACPI_APPLICATION 362#ifdef ACPI_APPLICATION
363 363
364ACPI_INIT_GLOBAL(ACPI_FILE, acpi_gbl_debug_file, NULL); 364ACPI_INIT_GLOBAL(ACPI_FILE, acpi_gbl_debug_file, NULL);
365ACPI_INIT_GLOBAL(ACPI_FILE, acpi_gbl_output_file, NULL);
365 366
366#endif /* ACPI_APPLICATION */ 367#endif /* ACPI_APPLICATION */
367 368
diff --git a/drivers/acpi/acpica/acutils.h b/drivers/acpi/acpica/acutils.h
index 8a4414869566..e0adbc1f52ed 100644
--- a/drivers/acpi/acpica/acutils.h
+++ b/drivers/acpi/acpica/acutils.h
@@ -95,7 +95,6 @@ extern const char *acpi_gbl_pt_decode[];
95#ifdef ACPI_ASL_COMPILER 95#ifdef ACPI_ASL_COMPILER
96 96
97#include <stdio.h> 97#include <stdio.h>
98extern FILE *acpi_gbl_output_file;
99 98
100#define ACPI_MSG_REDIRECT_BEGIN \ 99#define ACPI_MSG_REDIRECT_BEGIN \
101 FILE *output_file = acpi_gbl_output_file; \ 100 FILE *output_file = acpi_gbl_output_file; \
diff --git a/drivers/acpi/acpica/utinit.c b/drivers/acpi/acpica/utinit.c
index a7936623998f..77120ec9ea86 100644
--- a/drivers/acpi/acpica/utinit.c
+++ b/drivers/acpi/acpica/utinit.c
@@ -207,7 +207,6 @@ acpi_status acpi_ut_init_globals(void)
207 acpi_gbl_trace_dbg_level = 0; 207 acpi_gbl_trace_dbg_level = 0;
208 acpi_gbl_trace_dbg_layer = 0; 208 acpi_gbl_trace_dbg_layer = 0;
209 acpi_gbl_debugger_configuration = DEBUGGER_THREADING; 209 acpi_gbl_debugger_configuration = DEBUGGER_THREADING;
210 acpi_gbl_db_output_flags = ACPI_DB_CONSOLE_OUTPUT;
211 acpi_gbl_osi_mutex = NULL; 210 acpi_gbl_osi_mutex = NULL;
212 acpi_gbl_reg_methods_executed = FALSE; 211 acpi_gbl_reg_methods_executed = FALSE;
213 212
diff --git a/tools/power/acpi/Makefile b/tools/power/acpi/Makefile
index 61446dbf70a6..f88a251863c5 100644
--- a/tools/power/acpi/Makefile
+++ b/tools/power/acpi/Makefile
@@ -108,6 +108,7 @@ DUMP_OBJS = \
108 apmain.o\ 108 apmain.o\
109 osunixdir.o\ 109 osunixdir.o\
110 osunixmap.o\ 110 osunixmap.o\
111 osunixxf.o\
111 tbprint.o\ 112 tbprint.o\
112 tbxfroot.o\ 113 tbxfroot.o\
113 utbuffer.o\ 114 utbuffer.o\
diff --git a/tools/power/acpi/os_specific/service_layers/osunixxf.c b/tools/power/acpi/os_specific/service_layers/osunixxf.c
new file mode 100644
index 000000000000..0e6a8a6be441
--- /dev/null
+++ b/tools/power/acpi/os_specific/service_layers/osunixxf.c
@@ -0,0 +1,1304 @@
1/******************************************************************************
2 *
3 * Module Name: osunixxf - UNIX OSL interfaces
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2014, Intel Corp.
9 * All rights reserved.
10 *
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.
25 *
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.
29 *
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.
42 */
43
44/*
45 * These interfaces are required in order to compile the ASL compiler and the
46 * various ACPICA tools under Linux or other Unix-like system.
47 */
48#include <acpi/acpi.h>
49#include "accommon.h"
50#include "amlcode.h"
51#include "acparser.h"
52#include "acdebug.h"
53
54#include <stdio.h>
55#include <stdlib.h>
56#include <stdarg.h>
57#include <unistd.h>
58#include <sys/time.h>
59#include <semaphore.h>
60#include <pthread.h>
61#include <errno.h>
62
63#define _COMPONENT ACPI_OS_SERVICES
64ACPI_MODULE_NAME("osunixxf")
65
66u8 acpi_gbl_debug_timeout = FALSE;
67
68/* Upcalls to acpi_exec */
69
70void
71ae_table_override(struct acpi_table_header *existing_table,
72 struct acpi_table_header **new_table);
73
74typedef void *(*PTHREAD_CALLBACK) (void *);
75
76/* Buffer used by acpi_os_vprintf */
77
78#define ACPI_VPRINTF_BUFFER_SIZE 512
79#define _ASCII_NEWLINE '\n'
80
81/* Terminal support for acpi_exec only */
82
83#ifdef ACPI_EXEC_APP
84#include <termios.h>
85
86struct termios original_term_attributes;
87int term_attributes_were_set = 0;
88
89acpi_status acpi_ut_read_line(char *buffer, u32 buffer_length, u32 *bytes_read);
90
91static void os_enter_line_edit_mode(void);
92
93static void os_exit_line_edit_mode(void);
94
95/******************************************************************************
96 *
97 * FUNCTION: os_enter_line_edit_mode, os_exit_line_edit_mode
98 *
99 * PARAMETERS: None
100 *
101 * RETURN: None
102 *
103 * DESCRIPTION: Enter/Exit the raw character input mode for the terminal.
104 *
105 * Interactive line-editing support for the AML debugger. Used with the
106 * common/acgetline module.
107 *
108 * readline() is not used because of non-portability. It is not available
109 * on all systems, and if it is, often the package must be manually installed.
110 *
111 * Therefore, we use the POSIX tcgetattr/tcsetattr and do the minimal line
112 * editing that we need in acpi_os_get_line.
113 *
114 * If the POSIX tcgetattr/tcsetattr interfaces are unavailable, these
115 * calls will also work:
116 * For os_enter_line_edit_mode: system ("stty cbreak -echo")
117 * For os_exit_line_edit_mode: system ("stty cooked echo")
118 *
119 *****************************************************************************/
120
121static void os_enter_line_edit_mode(void)
122{
123 struct termios local_term_attributes;
124
125 /* Get and keep the original attributes */
126
127 if (tcgetattr(STDIN_FILENO, &original_term_attributes)) {
128 fprintf(stderr, "Could not get terminal attributes!\n");
129 return;
130 }
131
132 /* Set the new attributes to enable raw character input */
133
134 memcpy(&local_term_attributes, &original_term_attributes,
135 sizeof(struct termios));
136
137 local_term_attributes.c_lflag &= ~(ICANON | ECHO);
138 local_term_attributes.c_cc[VMIN] = 1;
139 local_term_attributes.c_cc[VTIME] = 0;
140
141 if (tcsetattr(STDIN_FILENO, TCSANOW, &local_term_attributes)) {
142 fprintf(stderr, "Could not set terminal attributes!\n");
143 return;
144 }
145
146 term_attributes_were_set = 1;
147}
148
149static void os_exit_line_edit_mode(void)
150{
151
152 if (!term_attributes_were_set) {
153 return;
154 }
155
156 /* Set terminal attributes back to the original values */
157
158 if (tcsetattr(STDIN_FILENO, TCSANOW, &original_term_attributes)) {
159 fprintf(stderr, "Could not restore terminal attributes!\n");
160 }
161}
162
163#else
164
165/* These functions are not needed for other ACPICA utilities */
166
167#define os_enter_line_edit_mode()
168#define os_exit_line_edit_mode()
169#endif
170
171/******************************************************************************
172 *
173 * FUNCTION: acpi_os_initialize, acpi_os_terminate
174 *
175 * PARAMETERS: None
176 *
177 * RETURN: Status
178 *
179 * DESCRIPTION: Initialize and terminate this module.
180 *
181 *****************************************************************************/
182
183acpi_status acpi_os_initialize(void)
184{
185
186 acpi_gbl_output_file = stdout;
187
188 os_enter_line_edit_mode();
189 return (AE_OK);
190}
191
192acpi_status acpi_os_terminate(void)
193{
194
195 os_exit_line_edit_mode();
196 return (AE_OK);
197}
198
199#ifndef ACPI_USE_NATIVE_RSDP_POINTER
200/******************************************************************************
201 *
202 * FUNCTION: acpi_os_get_root_pointer
203 *
204 * PARAMETERS: None
205 *
206 * RETURN: RSDP physical address
207 *
208 * DESCRIPTION: Gets the ACPI root pointer (RSDP)
209 *
210 *****************************************************************************/
211
212acpi_physical_address acpi_os_get_root_pointer(void)
213{
214
215 return (0);
216}
217#endif
218
219/******************************************************************************
220 *
221 * FUNCTION: acpi_os_predefined_override
222 *
223 * PARAMETERS: init_val - Initial value of the predefined object
224 * new_val - The new value for the object
225 *
226 * RETURN: Status, pointer to value. Null pointer returned if not
227 * overriding.
228 *
229 * DESCRIPTION: Allow the OS to override predefined names
230 *
231 *****************************************************************************/
232
233acpi_status
234acpi_os_predefined_override(const struct acpi_predefined_names * init_val,
235 acpi_string * new_val)
236{
237
238 if (!init_val || !new_val) {
239 return (AE_BAD_PARAMETER);
240 }
241
242 *new_val = NULL;
243 return (AE_OK);
244}
245
246/******************************************************************************
247 *
248 * FUNCTION: acpi_os_table_override
249 *
250 * PARAMETERS: existing_table - Header of current table (probably
251 * firmware)
252 * new_table - Where an entire new table is returned.
253 *
254 * RETURN: Status, pointer to new table. Null pointer returned if no
255 * table is available to override
256 *
257 * DESCRIPTION: Return a different version of a table if one is available
258 *
259 *****************************************************************************/
260
261acpi_status
262acpi_os_table_override(struct acpi_table_header * existing_table,
263 struct acpi_table_header ** new_table)
264{
265
266 if (!existing_table || !new_table) {
267 return (AE_BAD_PARAMETER);
268 }
269
270 *new_table = NULL;
271
272#ifdef ACPI_EXEC_APP
273
274 ae_table_override(existing_table, new_table);
275 return (AE_OK);
276#else
277
278 return (AE_NO_ACPI_TABLES);
279#endif
280}
281
282/******************************************************************************
283 *
284 * FUNCTION: acpi_os_physical_table_override
285 *
286 * PARAMETERS: existing_table - Header of current table (probably firmware)
287 * new_address - Where new table address is returned
288 * (Physical address)
289 * new_table_length - Where new table length is returned
290 *
291 * RETURN: Status, address/length of new table. Null pointer returned
292 * if no table is available to override.
293 *
294 * DESCRIPTION: Returns AE_SUPPORT, function not used in user space.
295 *
296 *****************************************************************************/
297
298acpi_status
299acpi_os_physical_table_override(struct acpi_table_header * existing_table,
300 acpi_physical_address * new_address,
301 u32 *new_table_length)
302{
303
304 return (AE_SUPPORT);
305}
306
307/******************************************************************************
308 *
309 * FUNCTION: acpi_os_redirect_output
310 *
311 * PARAMETERS: destination - An open file handle/pointer
312 *
313 * RETURN: None
314 *
315 * DESCRIPTION: Causes redirect of acpi_os_printf and acpi_os_vprintf
316 *
317 *****************************************************************************/
318
319void acpi_os_redirect_output(void *destination)
320{
321
322 acpi_gbl_output_file = destination;
323}
324
325/******************************************************************************
326 *
327 * FUNCTION: acpi_os_printf
328 *
329 * PARAMETERS: fmt, ... - Standard printf format
330 *
331 * RETURN: None
332 *
333 * DESCRIPTION: Formatted output. Note: very similar to acpi_os_vprintf
334 * (performance), changes should be tracked in both functions.
335 *
336 *****************************************************************************/
337
338void ACPI_INTERNAL_VAR_XFACE acpi_os_printf(const char *fmt, ...)
339{
340 va_list args;
341 u8 flags;
342
343 flags = acpi_gbl_db_output_flags;
344 if (flags & ACPI_DB_REDIRECTABLE_OUTPUT) {
345
346 /* Output is directable to either a file (if open) or the console */
347
348 if (acpi_gbl_debug_file) {
349
350 /* Output file is open, send the output there */
351
352 va_start(args, fmt);
353 vfprintf(acpi_gbl_debug_file, fmt, args);
354 va_end(args);
355 } else {
356 /* No redirection, send output to console (once only!) */
357
358 flags |= ACPI_DB_CONSOLE_OUTPUT;
359 }
360 }
361
362 if (flags & ACPI_DB_CONSOLE_OUTPUT) {
363 va_start(args, fmt);
364 vfprintf(acpi_gbl_output_file, fmt, args);
365 va_end(args);
366 }
367}
368
369/******************************************************************************
370 *
371 * FUNCTION: acpi_os_vprintf
372 *
373 * PARAMETERS: fmt - Standard printf format
374 * args - Argument list
375 *
376 * RETURN: None
377 *
378 * DESCRIPTION: Formatted output with argument list pointer. Note: very
379 * similar to acpi_os_printf, changes should be tracked in both
380 * functions.
381 *
382 *****************************************************************************/
383
384void acpi_os_vprintf(const char *fmt, va_list args)
385{
386 u8 flags;
387 char buffer[ACPI_VPRINTF_BUFFER_SIZE];
388
389 /*
390 * We build the output string in a local buffer because we may be
391 * outputting the buffer twice. Using vfprintf is problematic because
392 * some implementations modify the args pointer/structure during
393 * execution. Thus, we use the local buffer for portability.
394 *
395 * Note: Since this module is intended for use by the various ACPICA
396 * utilities/applications, we can safely declare the buffer on the stack.
397 * Also, This function is used for relatively small error messages only.
398 */
399 vsnprintf(buffer, ACPI_VPRINTF_BUFFER_SIZE, fmt, args);
400
401 flags = acpi_gbl_db_output_flags;
402 if (flags & ACPI_DB_REDIRECTABLE_OUTPUT) {
403
404 /* Output is directable to either a file (if open) or the console */
405
406 if (acpi_gbl_debug_file) {
407
408 /* Output file is open, send the output there */
409
410 fputs(buffer, acpi_gbl_debug_file);
411 } else {
412 /* No redirection, send output to console (once only!) */
413
414 flags |= ACPI_DB_CONSOLE_OUTPUT;
415 }
416 }
417
418 if (flags & ACPI_DB_CONSOLE_OUTPUT) {
419 fputs(buffer, acpi_gbl_output_file);
420 }
421}
422
423#ifndef ACPI_EXEC_APP
424/******************************************************************************
425 *
426 * FUNCTION: acpi_os_get_line
427 *
428 * PARAMETERS: buffer - Where to return the command line
429 * buffer_length - Maximum length of Buffer
430 * bytes_read - Where the actual byte count is returned
431 *
432 * RETURN: Status and actual bytes read
433 *
434 * DESCRIPTION: Get the next input line from the terminal. NOTE: For the
435 * acpi_exec utility, we use the acgetline module instead to
436 * provide line-editing and history support.
437 *
438 *****************************************************************************/
439
440acpi_status acpi_os_get_line(char *buffer, u32 buffer_length, u32 *bytes_read)
441{
442 int input_char;
443 u32 end_of_line;
444
445 /* Standard acpi_os_get_line for all utilities except acpi_exec */
446
447 for (end_of_line = 0;; end_of_line++) {
448 if (end_of_line >= buffer_length) {
449 return (AE_BUFFER_OVERFLOW);
450 }
451
452 if ((input_char = getchar()) == EOF) {
453 return (AE_ERROR);
454 }
455
456 if (!input_char || input_char == _ASCII_NEWLINE) {
457 break;
458 }
459
460 buffer[end_of_line] = (char)input_char;
461 }
462
463 /* Null terminate the buffer */
464
465 buffer[end_of_line] = 0;
466
467 /* Return the number of bytes in the string */
468
469 if (bytes_read) {
470 *bytes_read = end_of_line;
471 }
472
473 return (AE_OK);
474}
475#endif
476
477#ifndef ACPI_USE_NATIVE_MEMORY_MAPPING
478/******************************************************************************
479 *
480 * FUNCTION: acpi_os_map_memory
481 *
482 * PARAMETERS: where - Physical address of memory to be mapped
483 * length - How much memory to map
484 *
485 * RETURN: Pointer to mapped memory. Null on error.
486 *
487 * DESCRIPTION: Map physical memory into caller's address space
488 *
489 *****************************************************************************/
490
491void *acpi_os_map_memory(acpi_physical_address where, acpi_size length)
492{
493
494 return (ACPI_TO_POINTER((acpi_size) where));
495}
496
497/******************************************************************************
498 *
499 * FUNCTION: acpi_os_unmap_memory
500 *
501 * PARAMETERS: where - Logical address of memory to be unmapped
502 * length - How much memory to unmap
503 *
504 * RETURN: None.
505 *
506 * DESCRIPTION: Delete a previously created mapping. Where and Length must
507 * correspond to a previous mapping exactly.
508 *
509 *****************************************************************************/
510
511void acpi_os_unmap_memory(void *where, acpi_size length)
512{
513
514 return;
515}
516#endif
517
518/******************************************************************************
519 *
520 * FUNCTION: acpi_os_allocate
521 *
522 * PARAMETERS: size - Amount to allocate, in bytes
523 *
524 * RETURN: Pointer to the new allocation. Null on error.
525 *
526 * DESCRIPTION: Allocate memory. Algorithm is dependent on the OS.
527 *
528 *****************************************************************************/
529
530void *acpi_os_allocate(acpi_size size)
531{
532 void *mem;
533
534 mem = (void *)malloc((size_t) size);
535 return (mem);
536}
537
538#ifdef USE_NATIVE_ALLOCATE_ZEROED
539/******************************************************************************
540 *
541 * FUNCTION: acpi_os_allocate_zeroed
542 *
543 * PARAMETERS: size - Amount to allocate, in bytes
544 *
545 * RETURN: Pointer to the new allocation. Null on error.
546 *
547 * DESCRIPTION: Allocate and zero memory. Algorithm is dependent on the OS.
548 *
549 *****************************************************************************/
550
551void *acpi_os_allocate_zeroed(acpi_size size)
552{
553 void *mem;
554
555 mem = (void *)calloc(1, (size_t) size);
556 return (mem);
557}
558#endif
559
560/******************************************************************************
561 *
562 * FUNCTION: acpi_os_free
563 *
564 * PARAMETERS: mem - Pointer to previously allocated memory
565 *
566 * RETURN: None.
567 *
568 * DESCRIPTION: Free memory allocated via acpi_os_allocate
569 *
570 *****************************************************************************/
571
572void acpi_os_free(void *mem)
573{
574
575 free(mem);
576}
577
578#ifdef ACPI_SINGLE_THREADED
579/******************************************************************************
580 *
581 * FUNCTION: Semaphore stub functions
582 *
583 * DESCRIPTION: Stub functions used for single-thread applications that do
584 * not require semaphore synchronization. Full implementations
585 * of these functions appear after the stubs.
586 *
587 *****************************************************************************/
588
589acpi_status
590acpi_os_create_semaphore(u32 max_units,
591 u32 initial_units, acpi_handle * out_handle)
592{
593 *out_handle = (acpi_handle) 1;
594 return (AE_OK);
595}
596
597acpi_status acpi_os_delete_semaphore(acpi_handle handle)
598{
599 return (AE_OK);
600}
601
602acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout)
603{
604 return (AE_OK);
605}
606
607acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units)
608{
609 return (AE_OK);
610}
611
612#else
613/******************************************************************************
614 *
615 * FUNCTION: acpi_os_create_semaphore
616 *
617 * PARAMETERS: initial_units - Units to be assigned to the new semaphore
618 * out_handle - Where a handle will be returned
619 *
620 * RETURN: Status
621 *
622 * DESCRIPTION: Create an OS semaphore
623 *
624 *****************************************************************************/
625
626acpi_status
627acpi_os_create_semaphore(u32 max_units,
628 u32 initial_units, acpi_handle * out_handle)
629{
630 sem_t *sem;
631
632 if (!out_handle) {
633 return (AE_BAD_PARAMETER);
634 }
635#ifdef __APPLE__
636 {
637 char *semaphore_name = tmpnam(NULL);
638
639 sem =
640 sem_open(semaphore_name, O_EXCL | O_CREAT, 0755,
641 initial_units);
642 if (!sem) {
643 return (AE_NO_MEMORY);
644 }
645 sem_unlink(semaphore_name); /* This just deletes the name */
646 }
647
648#else
649 sem = acpi_os_allocate(sizeof(sem_t));
650 if (!sem) {
651 return (AE_NO_MEMORY);
652 }
653
654 if (sem_init(sem, 0, initial_units) == -1) {
655 acpi_os_free(sem);
656 return (AE_BAD_PARAMETER);
657 }
658#endif
659
660 *out_handle = (acpi_handle) sem;
661 return (AE_OK);
662}
663
664/******************************************************************************
665 *
666 * FUNCTION: acpi_os_delete_semaphore
667 *
668 * PARAMETERS: handle - Handle returned by acpi_os_create_semaphore
669 *
670 * RETURN: Status
671 *
672 * DESCRIPTION: Delete an OS semaphore
673 *
674 *****************************************************************************/
675
676acpi_status acpi_os_delete_semaphore(acpi_handle handle)
677{
678 sem_t *sem = (sem_t *) handle;
679
680 if (!sem) {
681 return (AE_BAD_PARAMETER);
682 }
683
684 if (sem_destroy(sem) == -1) {
685 return (AE_BAD_PARAMETER);
686 }
687
688 return (AE_OK);
689}
690
691/******************************************************************************
692 *
693 * FUNCTION: acpi_os_wait_semaphore
694 *
695 * PARAMETERS: handle - Handle returned by acpi_os_create_semaphore
696 * units - How many units to wait for
697 * msec_timeout - How long to wait (milliseconds)
698 *
699 * RETURN: Status
700 *
701 * DESCRIPTION: Wait for units
702 *
703 *****************************************************************************/
704
705acpi_status
706acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 msec_timeout)
707{
708 acpi_status status = AE_OK;
709 sem_t *sem = (sem_t *) handle;
710#ifndef ACPI_USE_ALTERNATE_TIMEOUT
711 struct timespec time;
712 int ret_val;
713#endif
714
715 if (!sem) {
716 return (AE_BAD_PARAMETER);
717 }
718
719 switch (msec_timeout) {
720 /*
721 * No Wait:
722 * --------
723 * A zero timeout value indicates that we shouldn't wait - just
724 * acquire the semaphore if available otherwise return AE_TIME
725 * (a.k.a. 'would block').
726 */
727 case 0:
728
729 if (sem_trywait(sem) == -1) {
730 status = (AE_TIME);
731 }
732 break;
733
734 /* Wait Indefinitely */
735
736 case ACPI_WAIT_FOREVER:
737
738 if (sem_wait(sem)) {
739 status = (AE_TIME);
740 }
741 break;
742
743 /* Wait with msec_timeout */
744
745 default:
746
747#ifdef ACPI_USE_ALTERNATE_TIMEOUT
748 /*
749 * Alternate timeout mechanism for environments where
750 * sem_timedwait is not available or does not work properly.
751 */
752 while (msec_timeout) {
753 if (sem_trywait(sem) == 0) {
754
755 /* Got the semaphore */
756 return (AE_OK);
757 }
758
759 if (msec_timeout >= 10) {
760 msec_timeout -= 10;
761 usleep(10 * ACPI_USEC_PER_MSEC); /* ten milliseconds */
762 } else {
763 msec_timeout--;
764 usleep(ACPI_USEC_PER_MSEC); /* one millisecond */
765 }
766 }
767 status = (AE_TIME);
768#else
769 /*
770 * The interface to sem_timedwait is an absolute time, so we need to
771 * get the current time, then add in the millisecond Timeout value.
772 */
773 if (clock_gettime(CLOCK_REALTIME, &time) == -1) {
774 perror("clock_gettime");
775 return (AE_TIME);
776 }
777
778 time.tv_sec += (msec_timeout / ACPI_MSEC_PER_SEC);
779 time.tv_nsec +=
780 ((msec_timeout % ACPI_MSEC_PER_SEC) * ACPI_NSEC_PER_MSEC);
781
782 /* Handle nanosecond overflow (field must be less than one second) */
783
784 if (time.tv_nsec >= ACPI_NSEC_PER_SEC) {
785 time.tv_sec += (time.tv_nsec / ACPI_NSEC_PER_SEC);
786 time.tv_nsec = (time.tv_nsec % ACPI_NSEC_PER_SEC);
787 }
788
789 while (((ret_val = sem_timedwait(sem, &time)) == -1)
790 && (errno == EINTR)) {
791 continue;
792 }
793
794 if (ret_val != 0) {
795 if (errno != ETIMEDOUT) {
796 perror("sem_timedwait");
797 }
798 status = (AE_TIME);
799 }
800#endif
801 break;
802 }
803
804 return (status);
805}
806
807/******************************************************************************
808 *
809 * FUNCTION: acpi_os_signal_semaphore
810 *
811 * PARAMETERS: handle - Handle returned by acpi_os_create_semaphore
812 * units - Number of units to send
813 *
814 * RETURN: Status
815 *
816 * DESCRIPTION: Send units
817 *
818 *****************************************************************************/
819
820acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units)
821{
822 sem_t *sem = (sem_t *) handle;
823
824 if (!sem) {
825 return (AE_BAD_PARAMETER);
826 }
827
828 if (sem_post(sem) == -1) {
829 return (AE_LIMIT);
830 }
831
832 return (AE_OK);
833}
834
835#endif /* ACPI_SINGLE_THREADED */
836
837/******************************************************************************
838 *
839 * FUNCTION: Spinlock interfaces
840 *
841 * DESCRIPTION: Map these interfaces to semaphore interfaces
842 *
843 *****************************************************************************/
844
845acpi_status acpi_os_create_lock(acpi_spinlock * out_handle)
846{
847
848 return (acpi_os_create_semaphore(1, 1, out_handle));
849}
850
851void acpi_os_delete_lock(acpi_spinlock handle)
852{
853 acpi_os_delete_semaphore(handle);
854}
855
856acpi_cpu_flags acpi_os_acquire_lock(acpi_handle handle)
857{
858 acpi_os_wait_semaphore(handle, 1, 0xFFFF);
859 return (0);
860}
861
862void acpi_os_release_lock(acpi_spinlock handle, acpi_cpu_flags flags)
863{
864 acpi_os_signal_semaphore(handle, 1);
865}
866
867/******************************************************************************
868 *
869 * FUNCTION: acpi_os_install_interrupt_handler
870 *
871 * PARAMETERS: interrupt_number - Level handler should respond to.
872 * isr - Address of the ACPI interrupt handler
873 * except_ptr - Where status is returned
874 *
875 * RETURN: Handle to the newly installed handler.
876 *
877 * DESCRIPTION: Install an interrupt handler. Used to install the ACPI
878 * OS-independent handler.
879 *
880 *****************************************************************************/
881
882u32
883acpi_os_install_interrupt_handler(u32 interrupt_number,
884 acpi_osd_handler service_routine,
885 void *context)
886{
887
888 return (AE_OK);
889}
890
891/******************************************************************************
892 *
893 * FUNCTION: acpi_os_remove_interrupt_handler
894 *
895 * PARAMETERS: handle - Returned when handler was installed
896 *
897 * RETURN: Status
898 *
899 * DESCRIPTION: Uninstalls an interrupt handler.
900 *
901 *****************************************************************************/
902
903acpi_status
904acpi_os_remove_interrupt_handler(u32 interrupt_number,
905 acpi_osd_handler service_routine)
906{
907
908 return (AE_OK);
909}
910
911/******************************************************************************
912 *
913 * FUNCTION: acpi_os_stall
914 *
915 * PARAMETERS: microseconds - Time to sleep
916 *
917 * RETURN: Blocks until sleep is completed.
918 *
919 * DESCRIPTION: Sleep at microsecond granularity
920 *
921 *****************************************************************************/
922
923void acpi_os_stall(u32 microseconds)
924{
925
926 if (microseconds) {
927 usleep(microseconds);
928 }
929}
930
931/******************************************************************************
932 *
933 * FUNCTION: acpi_os_sleep
934 *
935 * PARAMETERS: milliseconds - Time to sleep
936 *
937 * RETURN: Blocks until sleep is completed.
938 *
939 * DESCRIPTION: Sleep at millisecond granularity
940 *
941 *****************************************************************************/
942
943void acpi_os_sleep(u64 milliseconds)
944{
945
946 /* Sleep for whole seconds */
947
948 sleep(milliseconds / ACPI_MSEC_PER_SEC);
949
950 /*
951 * Sleep for remaining microseconds.
952 * Arg to usleep() is in usecs and must be less than 1,000,000 (1 second).
953 */
954 usleep((milliseconds % ACPI_MSEC_PER_SEC) * ACPI_USEC_PER_MSEC);
955}
956
957/******************************************************************************
958 *
959 * FUNCTION: acpi_os_get_timer
960 *
961 * PARAMETERS: None
962 *
963 * RETURN: Current time in 100 nanosecond units
964 *
965 * DESCRIPTION: Get the current system time
966 *
967 *****************************************************************************/
968
969u64 acpi_os_get_timer(void)
970{
971 struct timeval time;
972
973 /* This timer has sufficient resolution for user-space application code */
974
975 gettimeofday(&time, NULL);
976
977 /* (Seconds * 10^7 = 100ns(10^-7)) + (Microseconds(10^-6) * 10^1 = 100ns) */
978
979 return (((u64)time.tv_sec * ACPI_100NSEC_PER_SEC) +
980 ((u64)time.tv_usec * ACPI_100NSEC_PER_USEC));
981}
982
983/******************************************************************************
984 *
985 * FUNCTION: acpi_os_read_pci_configuration
986 *
987 * PARAMETERS: pci_id - Seg/Bus/Dev
988 * pci_register - Device Register
989 * value - Buffer where value is placed
990 * width - Number of bits
991 *
992 * RETURN: Status
993 *
994 * DESCRIPTION: Read data from PCI configuration space
995 *
996 *****************************************************************************/
997
998acpi_status
999acpi_os_read_pci_configuration(struct acpi_pci_id *pci_id,
1000 u32 pci_register, u64 *value, u32 width)
1001{
1002
1003 *value = 0;
1004 return (AE_OK);
1005}
1006
1007/******************************************************************************
1008 *
1009 * FUNCTION: acpi_os_write_pci_configuration
1010 *
1011 * PARAMETERS: pci_id - Seg/Bus/Dev
1012 * pci_register - Device Register
1013 * value - Value to be written
1014 * width - Number of bits
1015 *
1016 * RETURN: Status.
1017 *
1018 * DESCRIPTION: Write data to PCI configuration space
1019 *
1020 *****************************************************************************/
1021
1022acpi_status
1023acpi_os_write_pci_configuration(struct acpi_pci_id * pci_id,
1024 u32 pci_register, u64 value, u32 width)
1025{
1026
1027 return (AE_OK);
1028}
1029
1030/******************************************************************************
1031 *
1032 * FUNCTION: acpi_os_read_port
1033 *
1034 * PARAMETERS: address - Address of I/O port/register to read
1035 * value - Where value is placed
1036 * width - Number of bits
1037 *
1038 * RETURN: Value read from port
1039 *
1040 * DESCRIPTION: Read data from an I/O port or register
1041 *
1042 *****************************************************************************/
1043
1044acpi_status acpi_os_read_port(acpi_io_address address, u32 *value, u32 width)
1045{
1046
1047 switch (width) {
1048 case 8:
1049
1050 *value = 0xFF;
1051 break;
1052
1053 case 16:
1054
1055 *value = 0xFFFF;
1056 break;
1057
1058 case 32:
1059
1060 *value = 0xFFFFFFFF;
1061 break;
1062
1063 default:
1064
1065 return (AE_BAD_PARAMETER);
1066 }
1067
1068 return (AE_OK);
1069}
1070
1071/******************************************************************************
1072 *
1073 * FUNCTION: acpi_os_write_port
1074 *
1075 * PARAMETERS: address - Address of I/O port/register to write
1076 * value - Value to write
1077 * width - Number of bits
1078 *
1079 * RETURN: None
1080 *
1081 * DESCRIPTION: Write data to an I/O port or register
1082 *
1083 *****************************************************************************/
1084
1085acpi_status acpi_os_write_port(acpi_io_address address, u32 value, u32 width)
1086{
1087
1088 return (AE_OK);
1089}
1090
1091/******************************************************************************
1092 *
1093 * FUNCTION: acpi_os_read_memory
1094 *
1095 * PARAMETERS: address - Physical Memory Address to read
1096 * value - Where value is placed
1097 * width - Number of bits (8,16,32, or 64)
1098 *
1099 * RETURN: Value read from physical memory address. Always returned
1100 * as a 64-bit integer, regardless of the read width.
1101 *
1102 * DESCRIPTION: Read data from a physical memory address
1103 *
1104 *****************************************************************************/
1105
1106acpi_status
1107acpi_os_read_memory(acpi_physical_address address, u64 *value, u32 width)
1108{
1109
1110 switch (width) {
1111 case 8:
1112 case 16:
1113 case 32:
1114 case 64:
1115
1116 *value = 0;
1117 break;
1118
1119 default:
1120
1121 return (AE_BAD_PARAMETER);
1122 }
1123 return (AE_OK);
1124}
1125
1126/******************************************************************************
1127 *
1128 * FUNCTION: acpi_os_write_memory
1129 *
1130 * PARAMETERS: address - Physical Memory Address to write
1131 * value - Value to write
1132 * width - Number of bits (8,16,32, or 64)
1133 *
1134 * RETURN: None
1135 *
1136 * DESCRIPTION: Write data to a physical memory address
1137 *
1138 *****************************************************************************/
1139
1140acpi_status
1141acpi_os_write_memory(acpi_physical_address address, u64 value, u32 width)
1142{
1143
1144 return (AE_OK);
1145}
1146
1147/******************************************************************************
1148 *
1149 * FUNCTION: acpi_os_readable
1150 *
1151 * PARAMETERS: pointer - Area to be verified
1152 * length - Size of area
1153 *
1154 * RETURN: TRUE if readable for entire length
1155 *
1156 * DESCRIPTION: Verify that a pointer is valid for reading
1157 *
1158 *****************************************************************************/
1159
1160u8 acpi_os_readable(void *pointer, acpi_size length)
1161{
1162
1163 return (TRUE);
1164}
1165
1166/******************************************************************************
1167 *
1168 * FUNCTION: acpi_os_writable
1169 *
1170 * PARAMETERS: pointer - Area to be verified
1171 * length - Size of area
1172 *
1173 * RETURN: TRUE if writable for entire length
1174 *
1175 * DESCRIPTION: Verify that a pointer is valid for writing
1176 *
1177 *****************************************************************************/
1178
1179u8 acpi_os_writable(void *pointer, acpi_size length)
1180{
1181
1182 return (TRUE);
1183}
1184
1185/******************************************************************************
1186 *
1187 * FUNCTION: acpi_os_signal
1188 *
1189 * PARAMETERS: function - ACPI A signal function code
1190 * info - Pointer to function-dependent structure
1191 *
1192 * RETURN: Status
1193 *
1194 * DESCRIPTION: Miscellaneous functions. Example implementation only.
1195 *
1196 *****************************************************************************/
1197
1198acpi_status acpi_os_signal(u32 function, void *info)
1199{
1200
1201 switch (function) {
1202 case ACPI_SIGNAL_FATAL:
1203
1204 break;
1205
1206 case ACPI_SIGNAL_BREAKPOINT:
1207
1208 break;
1209
1210 default:
1211
1212 break;
1213 }
1214
1215 return (AE_OK);
1216}
1217
1218/* Optional multi-thread support */
1219
1220#ifndef ACPI_SINGLE_THREADED
1221/******************************************************************************
1222 *
1223 * FUNCTION: acpi_os_get_thread_id
1224 *
1225 * PARAMETERS: None
1226 *
1227 * RETURN: Id of the running thread
1228 *
1229 * DESCRIPTION: Get the ID of the current (running) thread
1230 *
1231 *****************************************************************************/
1232
1233acpi_thread_id acpi_os_get_thread_id(void)
1234{
1235 pthread_t thread;
1236
1237 thread = pthread_self();
1238 return (ACPI_CAST_PTHREAD_T(thread));
1239}
1240
1241/******************************************************************************
1242 *
1243 * FUNCTION: acpi_os_execute
1244 *
1245 * PARAMETERS: type - Type of execution
1246 * function - Address of the function to execute
1247 * context - Passed as a parameter to the function
1248 *
1249 * RETURN: Status.
1250 *
1251 * DESCRIPTION: Execute a new thread
1252 *
1253 *****************************************************************************/
1254
1255acpi_status
1256acpi_os_execute(acpi_execute_type type,
1257 acpi_osd_exec_callback function, void *context)
1258{
1259 pthread_t thread;
1260 int ret;
1261
1262 ret =
1263 pthread_create(&thread, NULL, (PTHREAD_CALLBACK) function, context);
1264 if (ret) {
1265 acpi_os_printf("Create thread failed");
1266 }
1267 return (0);
1268}
1269
1270#else /* ACPI_SINGLE_THREADED */
1271acpi_thread_id acpi_os_get_thread_id(void)
1272{
1273 return (1);
1274}
1275
1276acpi_status
1277acpi_os_execute(acpi_execute_type type,
1278 acpi_osd_exec_callback function, void *context)
1279{
1280
1281 function(context);
1282
1283 return (AE_OK);
1284}
1285
1286#endif /* ACPI_SINGLE_THREADED */
1287
1288/******************************************************************************
1289 *
1290 * FUNCTION: acpi_os_wait_events_complete
1291 *
1292 * PARAMETERS: None
1293 *
1294 * RETURN: None
1295 *
1296 * DESCRIPTION: Wait for all asynchronous events to complete. This
1297 * implementation does nothing.
1298 *
1299 *****************************************************************************/
1300
1301void acpi_os_wait_events_complete(void)
1302{
1303 return;
1304}
diff --git a/tools/power/acpi/tools/acpidump/apdump.c b/tools/power/acpi/tools/acpidump/apdump.c
index 3cac12378366..e8729aa3a60e 100644
--- a/tools/power/acpi/tools/acpidump/apdump.c
+++ b/tools/power/acpi/tools/acpidump/apdump.c
@@ -427,25 +427,3 @@ exit:
427 free(table); 427 free(table);
428 return (table_status); 428 return (table_status);
429} 429}
430
431/******************************************************************************
432 *
433 * FUNCTION: acpi_os* print functions
434 *
435 * DESCRIPTION: Used for linkage with ACPICA modules
436 *
437 ******************************************************************************/
438
439void ACPI_INTERNAL_VAR_XFACE acpi_os_printf(const char *fmt, ...)
440{
441 va_list args;
442
443 va_start(args, fmt);
444 vfprintf(stdout, fmt, args);
445 va_end(args);
446}
447
448void acpi_os_vprintf(const char *fmt, va_list args)
449{
450 vfprintf(stdout, fmt, args);
451}
diff --git a/tools/power/acpi/tools/acpidump/apmain.c b/tools/power/acpi/tools/acpidump/apmain.c
index 51e8d638db18..c03e4731f099 100644
--- a/tools/power/acpi/tools/acpidump/apmain.c
+++ b/tools/power/acpi/tools/acpidump/apmain.c
@@ -288,6 +288,7 @@ int ACPI_SYSTEM_XFACE main(int argc, char *argv[])
288 u32 i; 288 u32 i;
289 289
290 ACPI_DEBUG_INITIALIZE(); /* For debug version only */ 290 ACPI_DEBUG_INITIALIZE(); /* For debug version only */
291 acpi_os_initialize();
291 292
292 /* Process command line options */ 293 /* Process command line options */
293 294