File Index
Files and directories
Sign in
FILE

exoparg3.c

File preview with syntax highlighting.

linux-6.19.14/drivers/acpi/acpica/exoparg3.c C
  1// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
  2/******************************************************************************
  3 *
  4 * Module Name: exoparg3 - AML execution - opcodes with 3 arguments
  5 *
  6 * Copyright (C) 2000 - 2025, Intel Corp.
  7 *
  8 *****************************************************************************/
  9
 10#include <acpi/acpi.h>
 11#include "accommon.h"
 12#include "acinterp.h"
 13#include <acpi/acoutput.h>
 14#include "acparser.h"
 15#include "amlcode.h"
 16
 17#define _COMPONENT          ACPI_EXECUTER
 18ACPI_MODULE_NAME("exoparg3")
 19
 20/*!
 21 * Naming convention for AML interpreter execution routines.
 22 *
 23 * The routines that begin execution of AML opcodes are named with a common
 24 * convention based upon the number of arguments, the number of target operands,
 25 * and whether or not a value is returned:
 26 *
 27 *      AcpiExOpcode_xA_yT_zR
 28 *
 29 * Where:
 30 *
 31 * xA - ARGUMENTS:    The number of arguments (input operands) that are
 32 *                    required for this opcode type (1 through 6 args).
 33 * yT - TARGETS:      The number of targets (output operands) that are required
 34 *                    for this opcode type (0, 1, or 2 targets).
 35 * zR - RETURN VALUE: Indicates whether this opcode type returns a value
 36 *                    as the function return (0 or 1).
 37 *
 38 * The AcpiExOpcode* functions are called via the Dispatcher component with
 39 * fully resolved operands.
 40!*/
 41/*******************************************************************************
 42 *
 43 * FUNCTION:    acpi_ex_opcode_3A_0T_0R
 44 *
 45 * PARAMETERS:  walk_state          - Current walk state
 46 *
 47 * RETURN:      Status
 48 *
 49 * DESCRIPTION: Execute Triadic operator (3 operands)
 50 *
 51 ******************************************************************************/
 52acpi_status acpi_ex_opcode_3A_0T_0R(struct acpi_walk_state *walk_state)
 53{
 54	union acpi_operand_object **operand = &walk_state->operands[0];
 55	struct acpi_signal_fatal_info fatal;
 56
 57	ACPI_FUNCTION_TRACE_STR(ex_opcode_3A_0T_0R,
 58				acpi_ps_get_opcode_name(walk_state->opcode));
 59
 60	switch (walk_state->opcode) {
 61	case AML_FATAL_OP:	/* Fatal (fatal_type fatal_code fatal_arg) */
 62
 63		fatal.type = (u32)operand[0]->integer.value;
 64		fatal.code = (u32)operand[1]->integer.value;
 65		fatal.argument = (u32)operand[2]->integer.value;
 66
 67		ACPI_BIOS_ERROR((AE_INFO,
 68				 "Fatal ACPI BIOS error (Type 0x%X Code 0x%X Arg 0x%X)\n",
 69				 fatal.type, fatal.code, fatal.argument));
 70
 71		/* Always signal the OS! */
 72
 73		acpi_os_signal(ACPI_SIGNAL_FATAL, &fatal);
 74
 75		/*
 76		 * Might return while OS is shutting down, so abort the AML execution
 77		 * by returning an error.
 78		 */
 79		return_ACPI_STATUS(AE_ERROR);
 80
 81	case AML_EXTERNAL_OP:
 82		/*
 83		 * If the interpreter sees this opcode, just ignore it. The External
 84		 * op is intended for use by disassemblers in order to properly
 85		 * disassemble control method invocations. The opcode or group of
 86		 * opcodes should be surrounded by an "if (0)" clause to ensure that
 87		 * AML interpreters never see the opcode. Thus, something is
 88		 * wrong if an external opcode ever gets here.
 89		 */
 90		ACPI_ERROR((AE_INFO, "Executed External Op"));
 91
 92		return_ACPI_STATUS(AE_OK);
 93
 94	default:
 95
 96		ACPI_ERROR((AE_INFO, "Unknown AML opcode 0x%X",
 97			    walk_state->opcode));
 98
 99		return_ACPI_STATUS(AE_AML_BAD_OPCODE);
100	}
101}
102
103/*******************************************************************************
104 *
105 * FUNCTION:    acpi_ex_opcode_3A_1T_1R
106 *
107 * PARAMETERS:  walk_state          - Current walk state
108 *
109 * RETURN:      Status
110 *
111 * DESCRIPTION: Execute Triadic operator (3 operands)
112 *
113 ******************************************************************************/
114
115acpi_status acpi_ex_opcode_3A_1T_1R(struct acpi_walk_state *walk_state)
116{
117	union acpi_operand_object **operand = &walk_state->operands[0];
118	union acpi_operand_object *return_desc = NULL;
119	char *buffer = NULL;
120	acpi_status status = AE_OK;
121	u64 index;
122	acpi_size length;
123
124	ACPI_FUNCTION_TRACE_STR(ex_opcode_3A_1T_1R,
125				acpi_ps_get_opcode_name(walk_state->opcode));
126
127	switch (walk_state->opcode) {
128	case AML_MID_OP:	/* Mid (Source[0], Index[1], Length[2], Result[3]) */
129		/*
130		 * Create the return object. The Source operand is guaranteed to be
131		 * either a String or a Buffer, so just use its type.
132		 */
133		return_desc = acpi_ut_create_internal_object((operand[0])->
134							     common.type);
135		if (!return_desc) {
136			status = AE_NO_MEMORY;
137			goto cleanup;
138		}
139
140		/* Get the Integer values from the objects */
141
142		index = operand[1]->integer.value;
143		length = (acpi_size)operand[2]->integer.value;
144
145		/*
146		 * If the index is beyond the length of the String/Buffer, or if the
147		 * requested length is zero, return a zero-length String/Buffer
148		 */
149		if (index >= operand[0]->string.length) {
150			length = 0;
151		}
152
153		/* Truncate request if larger than the actual String/Buffer */
154
155		else if ((index + length) > operand[0]->string.length) {
156			length =
157			    (acpi_size)operand[0]->string.length -
158			    (acpi_size)index;
159		}
160
161		/* Strings always have a sub-pointer, not so for buffers */
162
163		switch ((operand[0])->common.type) {
164		case ACPI_TYPE_STRING:
165
166			/* Always allocate a new buffer for the String */
167
168			buffer = ACPI_ALLOCATE_ZEROED((acpi_size)length + 1);
169			if (!buffer) {
170				status = AE_NO_MEMORY;
171				goto cleanup;
172			}
173			break;
174
175		case ACPI_TYPE_BUFFER:
176
177			/* If the requested length is zero, don't allocate a buffer */
178
179			if (length > 0) {
180
181				/* Allocate a new buffer for the Buffer */
182
183				buffer = ACPI_ALLOCATE_ZEROED(length);
184				if (!buffer) {
185					status = AE_NO_MEMORY;
186					goto cleanup;
187				}
188			}
189			break;
190
191		default:	/* Should not happen */
192
193			status = AE_AML_OPERAND_TYPE;
194			goto cleanup;
195		}
196
197		if (buffer) {
198
199			/* We have a buffer, copy the portion requested */
200
201			memcpy(buffer,
202			       operand[0]->string.pointer + index, length);
203		}
204
205		/* Set the length of the new String/Buffer */
206
207		return_desc->string.pointer = buffer;
208		return_desc->string.length = (u32) length;
209
210		/* Mark buffer initialized */
211
212		return_desc->buffer.flags |= AOPOBJ_DATA_VALID;
213		break;
214
215	default:
216
217		ACPI_ERROR((AE_INFO, "Unknown AML opcode 0x%X",
218			    walk_state->opcode));
219
220		status = AE_AML_BAD_OPCODE;
221		goto cleanup;
222	}
223
224	/* Store the result in the target */
225
226	status = acpi_ex_store(return_desc, operand[3], walk_state);
227
228cleanup:
229
230	/* Delete return object on error */
231
232	if (ACPI_FAILURE(status) || walk_state->result_obj) {
233		acpi_ut_remove_reference(return_desc);
234		walk_state->result_obj = NULL;
235	} else {
236		/* Set the return object and exit */
237
238		walk_state->result_obj = return_desc;
239	}
240
241	return_ACPI_STATUS(status);
242}
~/ Read-only file preview.