Linux 4.19.133
[linux/fpc-iii.git] / drivers / acpi / acpica / exoparg3.c
blob764fa6f924ff5f16d5026442c6246a03c41f5967
1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /******************************************************************************
4 * Module Name: exoparg3 - AML execution - opcodes with 3 arguments
6 * Copyright (C) 2000 - 2018, Intel Corp.
8 *****************************************************************************/
10 #include <acpi/acpi.h>
11 #include "accommon.h"
12 #include "acinterp.h"
13 #include "acparser.h"
14 #include "amlcode.h"
16 #define _COMPONENT ACPI_EXECUTER
17 ACPI_MODULE_NAME("exoparg3")
19 /*!
20 * Naming convention for AML interpreter execution routines.
22 * The routines that begin execution of AML opcodes are named with a common
23 * convention based upon the number of arguments, the number of target operands,
24 * and whether or not a value is returned:
26 * AcpiExOpcode_xA_yT_zR
28 * Where:
30 * xA - ARGUMENTS: The number of arguments (input operands) that are
31 * required for this opcode type (1 through 6 args).
32 * yT - TARGETS: The number of targets (output operands) that are required
33 * for this opcode type (0, 1, or 2 targets).
34 * zR - RETURN VALUE: Indicates whether this opcode type returns a value
35 * as the function return (0 or 1).
37 * The AcpiExOpcode* functions are called via the Dispatcher component with
38 * fully resolved operands.
39 !*/
40 /*******************************************************************************
42 * FUNCTION: acpi_ex_opcode_3A_0T_0R
44 * PARAMETERS: walk_state - Current walk state
46 * RETURN: Status
48 * DESCRIPTION: Execute Triadic operator (3 operands)
50 ******************************************************************************/
51 acpi_status acpi_ex_opcode_3A_0T_0R(struct acpi_walk_state *walk_state)
53 union acpi_operand_object **operand = &walk_state->operands[0];
54 struct acpi_signal_fatal_info *fatal;
55 acpi_status status = AE_OK;
57 ACPI_FUNCTION_TRACE_STR(ex_opcode_3A_0T_0R,
58 acpi_ps_get_opcode_name(walk_state->opcode));
60 switch (walk_state->opcode) {
61 case AML_FATAL_OP: /* Fatal (fatal_type fatal_code fatal_arg) */
63 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
64 "FatalOp: Type %X Code %X Arg %X "
65 "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n",
66 (u32)operand[0]->integer.value,
67 (u32)operand[1]->integer.value,
68 (u32)operand[2]->integer.value));
70 fatal = ACPI_ALLOCATE(sizeof(struct acpi_signal_fatal_info));
71 if (fatal) {
72 fatal->type = (u32) operand[0]->integer.value;
73 fatal->code = (u32) operand[1]->integer.value;
74 fatal->argument = (u32) operand[2]->integer.value;
77 /* Always signal the OS! */
79 status = acpi_os_signal(ACPI_SIGNAL_FATAL, fatal);
81 /* Might return while OS is shutting down, just continue */
83 ACPI_FREE(fatal);
84 goto cleanup;
86 case AML_EXTERNAL_OP:
88 * If the interpreter sees this opcode, just ignore it. The External
89 * op is intended for use by disassemblers in order to properly
90 * disassemble control method invocations. The opcode or group of
91 * opcodes should be surrounded by an "if (0)" clause to ensure that
92 * AML interpreters never see the opcode. Thus, something is
93 * wrong if an external opcode ever gets here.
95 ACPI_ERROR((AE_INFO, "Executed External Op"));
96 status = AE_OK;
97 goto cleanup;
99 default:
101 ACPI_ERROR((AE_INFO, "Unknown AML opcode 0x%X",
102 walk_state->opcode));
104 status = AE_AML_BAD_OPCODE;
105 goto cleanup;
108 cleanup:
110 return_ACPI_STATUS(status);
113 /*******************************************************************************
115 * FUNCTION: acpi_ex_opcode_3A_1T_1R
117 * PARAMETERS: walk_state - Current walk state
119 * RETURN: Status
121 * DESCRIPTION: Execute Triadic operator (3 operands)
123 ******************************************************************************/
125 acpi_status acpi_ex_opcode_3A_1T_1R(struct acpi_walk_state *walk_state)
127 union acpi_operand_object **operand = &walk_state->operands[0];
128 union acpi_operand_object *return_desc = NULL;
129 char *buffer = NULL;
130 acpi_status status = AE_OK;
131 u64 index;
132 acpi_size length;
134 ACPI_FUNCTION_TRACE_STR(ex_opcode_3A_1T_1R,
135 acpi_ps_get_opcode_name(walk_state->opcode));
137 switch (walk_state->opcode) {
138 case AML_MID_OP: /* Mid (Source[0], Index[1], Length[2], Result[3]) */
140 * Create the return object. The Source operand is guaranteed to be
141 * either a String or a Buffer, so just use its type.
143 return_desc = acpi_ut_create_internal_object((operand[0])->
144 common.type);
145 if (!return_desc) {
146 status = AE_NO_MEMORY;
147 goto cleanup;
150 /* Get the Integer values from the objects */
152 index = operand[1]->integer.value;
153 length = (acpi_size)operand[2]->integer.value;
156 * If the index is beyond the length of the String/Buffer, or if the
157 * requested length is zero, return a zero-length String/Buffer
159 if (index >= operand[0]->string.length) {
160 length = 0;
163 /* Truncate request if larger than the actual String/Buffer */
165 else if ((index + length) > operand[0]->string.length) {
166 length =
167 (acpi_size)operand[0]->string.length -
168 (acpi_size)index;
171 /* Strings always have a sub-pointer, not so for buffers */
173 switch ((operand[0])->common.type) {
174 case ACPI_TYPE_STRING:
176 /* Always allocate a new buffer for the String */
178 buffer = ACPI_ALLOCATE_ZEROED((acpi_size)length + 1);
179 if (!buffer) {
180 status = AE_NO_MEMORY;
181 goto cleanup;
183 break;
185 case ACPI_TYPE_BUFFER:
187 /* If the requested length is zero, don't allocate a buffer */
189 if (length > 0) {
191 /* Allocate a new buffer for the Buffer */
193 buffer = ACPI_ALLOCATE_ZEROED(length);
194 if (!buffer) {
195 status = AE_NO_MEMORY;
196 goto cleanup;
199 break;
201 default: /* Should not happen */
203 status = AE_AML_OPERAND_TYPE;
204 goto cleanup;
207 if (buffer) {
209 /* We have a buffer, copy the portion requested */
211 memcpy(buffer,
212 operand[0]->string.pointer + index, length);
215 /* Set the length of the new String/Buffer */
217 return_desc->string.pointer = buffer;
218 return_desc->string.length = (u32) length;
220 /* Mark buffer initialized */
222 return_desc->buffer.flags |= AOPOBJ_DATA_VALID;
223 break;
225 default:
227 ACPI_ERROR((AE_INFO, "Unknown AML opcode 0x%X",
228 walk_state->opcode));
230 status = AE_AML_BAD_OPCODE;
231 goto cleanup;
234 /* Store the result in the target */
236 status = acpi_ex_store(return_desc, operand[3], walk_state);
238 cleanup:
240 /* Delete return object on error */
242 if (ACPI_FAILURE(status) || walk_state->result_obj) {
243 acpi_ut_remove_reference(return_desc);
244 walk_state->result_obj = NULL;
245 } else {
246 /* Set the return object and exit */
248 walk_state->result_obj = return_desc;
251 return_ACPI_STATUS(status);