sh_eth: fix EESIPR values for SH77{34|63}
[linux/fpc-iii.git] / drivers / acpi / acpica / dbhistry.c
blob46bd65d38df966cf3c953476c6d16f110056824a
1 /******************************************************************************
3 * Module Name: dbhistry - debugger HISTORY command
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2016, 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 #include <acpi/acpi.h>
45 #include "accommon.h"
46 #include "acdebug.h"
48 #define _COMPONENT ACPI_CA_DEBUGGER
49 ACPI_MODULE_NAME("dbhistry")
51 #define HI_NO_HISTORY 0
52 #define HI_RECORD_HISTORY 1
53 #define HISTORY_SIZE 40
54 typedef struct history_info {
55 char *command;
56 u32 cmd_num;
58 } HISTORY_INFO;
60 static HISTORY_INFO acpi_gbl_history_buffer[HISTORY_SIZE];
61 static u16 acpi_gbl_lo_history = 0;
62 static u16 acpi_gbl_num_history = 0;
63 static u16 acpi_gbl_next_history_index = 0;
64 u32 acpi_gbl_next_cmd_num = 1;
66 /*******************************************************************************
68 * FUNCTION: acpi_db_add_to_history
70 * PARAMETERS: command_line - Command to add
72 * RETURN: None
74 * DESCRIPTION: Add a command line to the history buffer.
76 ******************************************************************************/
78 void acpi_db_add_to_history(char *command_line)
80 u16 cmd_len;
81 u16 buffer_len;
83 /* Put command into the next available slot */
85 cmd_len = (u16)strlen(command_line);
86 if (!cmd_len) {
87 return;
90 if (acpi_gbl_history_buffer[acpi_gbl_next_history_index].command !=
91 NULL) {
92 buffer_len =
93 (u16)
94 strlen(acpi_gbl_history_buffer[acpi_gbl_next_history_index].
95 command);
97 if (cmd_len > buffer_len) {
98 acpi_os_free(acpi_gbl_history_buffer
99 [acpi_gbl_next_history_index].command);
100 acpi_gbl_history_buffer[acpi_gbl_next_history_index].
101 command = acpi_os_allocate(cmd_len + 1);
103 } else {
104 acpi_gbl_history_buffer[acpi_gbl_next_history_index].command =
105 acpi_os_allocate(cmd_len + 1);
108 strcpy(acpi_gbl_history_buffer[acpi_gbl_next_history_index].command,
109 command_line);
111 acpi_gbl_history_buffer[acpi_gbl_next_history_index].cmd_num =
112 acpi_gbl_next_cmd_num;
114 /* Adjust indexes */
116 if ((acpi_gbl_num_history == HISTORY_SIZE) &&
117 (acpi_gbl_next_history_index == acpi_gbl_lo_history)) {
118 acpi_gbl_lo_history++;
119 if (acpi_gbl_lo_history >= HISTORY_SIZE) {
120 acpi_gbl_lo_history = 0;
124 acpi_gbl_next_history_index++;
125 if (acpi_gbl_next_history_index >= HISTORY_SIZE) {
126 acpi_gbl_next_history_index = 0;
129 acpi_gbl_next_cmd_num++;
130 if (acpi_gbl_num_history < HISTORY_SIZE) {
131 acpi_gbl_num_history++;
135 /*******************************************************************************
137 * FUNCTION: acpi_db_display_history
139 * PARAMETERS: None
141 * RETURN: None
143 * DESCRIPTION: Display the contents of the history buffer
145 ******************************************************************************/
147 void acpi_db_display_history(void)
149 u32 i;
150 u16 history_index;
152 history_index = acpi_gbl_lo_history;
154 /* Dump entire history buffer */
156 for (i = 0; i < acpi_gbl_num_history; i++) {
157 if (acpi_gbl_history_buffer[history_index].command) {
158 acpi_os_printf("%3ld %s\n",
159 acpi_gbl_history_buffer[history_index].
160 cmd_num,
161 acpi_gbl_history_buffer[history_index].
162 command);
165 history_index++;
166 if (history_index >= HISTORY_SIZE) {
167 history_index = 0;
172 /*******************************************************************************
174 * FUNCTION: acpi_db_get_from_history
176 * PARAMETERS: command_num_arg - String containing the number of the
177 * command to be retrieved
179 * RETURN: Pointer to the retrieved command. Null on error.
181 * DESCRIPTION: Get a command from the history buffer
183 ******************************************************************************/
185 char *acpi_db_get_from_history(char *command_num_arg)
187 u32 cmd_num;
189 if (command_num_arg == NULL) {
190 cmd_num = acpi_gbl_next_cmd_num - 1;
193 else {
194 cmd_num = strtoul(command_num_arg, NULL, 0);
197 return (acpi_db_get_history_by_index(cmd_num));
200 /*******************************************************************************
202 * FUNCTION: acpi_db_get_history_by_index
204 * PARAMETERS: cmd_num - Index of the desired history entry.
205 * Values are 0...(acpi_gbl_next_cmd_num - 1)
207 * RETURN: Pointer to the retrieved command. Null on error.
209 * DESCRIPTION: Get a command from the history buffer
211 ******************************************************************************/
213 char *acpi_db_get_history_by_index(u32 cmd_num)
215 u32 i;
216 u16 history_index;
218 /* Search history buffer */
220 history_index = acpi_gbl_lo_history;
221 for (i = 0; i < acpi_gbl_num_history; i++) {
222 if (acpi_gbl_history_buffer[history_index].cmd_num == cmd_num) {
224 /* Found the command, return it */
226 return (acpi_gbl_history_buffer[history_index].command);
229 /* History buffer is circular */
231 history_index++;
232 if (history_index >= HISTORY_SIZE) {
233 history_index = 0;
237 acpi_os_printf("Invalid history number: %u\n", history_index);
238 return (NULL);