1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44#include <acpi/acpi.h>
45#include "accommon.h"
46#include "acinterp.h"
47#include "amlresrc.h"
48
49#define _COMPONENT ACPI_EXECUTER
50ACPI_MODULE_NAME("exconcat")
51
52
53static acpi_status
54acpi_ex_convert_to_object_type_string(union acpi_operand_object *obj_desc,
55 union acpi_operand_object **result_desc);
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80acpi_status
81acpi_ex_do_concatenate(union acpi_operand_object *operand0,
82 union acpi_operand_object *operand1,
83 union acpi_operand_object **actual_return_desc,
84 struct acpi_walk_state *walk_state)
85{
86 union acpi_operand_object *local_operand0 = operand0;
87 union acpi_operand_object *local_operand1 = operand1;
88 union acpi_operand_object *temp_operand1 = NULL;
89 union acpi_operand_object *return_desc;
90 char *buffer;
91 acpi_object_type operand0_type;
92 acpi_object_type operand1_type;
93 acpi_status status;
94
95 ACPI_FUNCTION_TRACE(ex_do_concatenate);
96
97
98
99 switch (operand0->common.type) {
100 case ACPI_TYPE_INTEGER:
101 case ACPI_TYPE_STRING:
102 case ACPI_TYPE_BUFFER:
103
104 operand0_type = operand0->common.type;
105 break;
106
107 default:
108
109
110
111 status =
112 acpi_ex_convert_to_object_type_string(operand0,
113 &local_operand0);
114 if (ACPI_FAILURE(status)) {
115 goto cleanup;
116 }
117
118 operand0_type = ACPI_TYPE_STRING;
119 break;
120 }
121
122
123
124 switch (operand1->common.type) {
125 case ACPI_TYPE_INTEGER:
126 case ACPI_TYPE_STRING:
127 case ACPI_TYPE_BUFFER:
128
129 operand1_type = operand1->common.type;
130 break;
131
132 default:
133
134
135
136 status =
137 acpi_ex_convert_to_object_type_string(operand1,
138 &local_operand1);
139 if (ACPI_FAILURE(status)) {
140 goto cleanup;
141 }
142
143 operand1_type = ACPI_TYPE_STRING;
144 break;
145 }
146
147
148
149
150
151
152
153
154 switch (operand0_type) {
155 case ACPI_TYPE_INTEGER:
156
157 status =
158 acpi_ex_convert_to_integer(local_operand1, &temp_operand1,
159 ACPI_STRTOUL_BASE16);
160 break;
161
162 case ACPI_TYPE_BUFFER:
163
164 status =
165 acpi_ex_convert_to_buffer(local_operand1, &temp_operand1);
166 break;
167
168 case ACPI_TYPE_STRING:
169
170 switch (operand1_type) {
171 case ACPI_TYPE_INTEGER:
172 case ACPI_TYPE_STRING:
173 case ACPI_TYPE_BUFFER:
174
175
176
177 status =
178 acpi_ex_convert_to_string(local_operand1,
179 &temp_operand1,
180 ACPI_IMPLICIT_CONVERT_HEX);
181 break;
182
183 default:
184
185 status = AE_OK;
186 break;
187 }
188 break;
189
190 default:
191
192 ACPI_ERROR((AE_INFO, "Invalid object type: 0x%X",
193 operand0->common.type));
194 status = AE_AML_INTERNAL;
195 }
196
197 if (ACPI_FAILURE(status)) {
198 goto cleanup;
199 }
200
201
202
203 if ((local_operand1 != operand1) && (local_operand1 != temp_operand1)) {
204 acpi_ut_remove_reference(local_operand1);
205 }
206
207 local_operand1 = temp_operand1;
208
209
210
211
212
213
214
215
216
217
218
219
220 switch (operand0_type) {
221 case ACPI_TYPE_INTEGER:
222
223
224
225
226 return_desc = acpi_ut_create_buffer_object((acpi_size)
227 ACPI_MUL_2
228 (acpi_gbl_integer_byte_width));
229 if (!return_desc) {
230 status = AE_NO_MEMORY;
231 goto cleanup;
232 }
233
234 buffer = (char *)return_desc->buffer.pointer;
235
236
237
238 memcpy(buffer, &operand0->integer.value,
239 acpi_gbl_integer_byte_width);
240
241
242
243 memcpy(buffer + acpi_gbl_integer_byte_width,
244 &local_operand1->integer.value,
245 acpi_gbl_integer_byte_width);
246 break;
247
248 case ACPI_TYPE_STRING:
249
250
251
252 return_desc = acpi_ut_create_string_object(((acpi_size)
253 local_operand0->
254 string.length +
255 local_operand1->
256 string.length));
257 if (!return_desc) {
258 status = AE_NO_MEMORY;
259 goto cleanup;
260 }
261
262 buffer = return_desc->string.pointer;
263
264
265
266 strcpy(buffer, local_operand0->string.pointer);
267 strcat(buffer, local_operand1->string.pointer);
268 break;
269
270 case ACPI_TYPE_BUFFER:
271
272
273
274 return_desc = acpi_ut_create_buffer_object(((acpi_size)
275 operand0->buffer.
276 length +
277 local_operand1->
278 buffer.length));
279 if (!return_desc) {
280 status = AE_NO_MEMORY;
281 goto cleanup;
282 }
283
284 buffer = (char *)return_desc->buffer.pointer;
285
286
287
288 memcpy(buffer, operand0->buffer.pointer,
289 operand0->buffer.length);
290 memcpy(buffer + operand0->buffer.length,
291 local_operand1->buffer.pointer,
292 local_operand1->buffer.length);
293 break;
294
295 default:
296
297
298
299 ACPI_ERROR((AE_INFO, "Invalid object type: 0x%X",
300 operand0->common.type));
301 status = AE_AML_INTERNAL;
302 goto cleanup;
303 }
304
305 *actual_return_desc = return_desc;
306
307cleanup:
308 if (local_operand0 != operand0) {
309 acpi_ut_remove_reference(local_operand0);
310 }
311
312 if (local_operand1 != operand1) {
313 acpi_ut_remove_reference(local_operand1);
314 }
315
316 return_ACPI_STATUS(status);
317}
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334static acpi_status
335acpi_ex_convert_to_object_type_string(union acpi_operand_object *obj_desc,
336 union acpi_operand_object **result_desc)
337{
338 union acpi_operand_object *return_desc;
339 const char *type_string;
340
341 type_string = acpi_ut_get_type_name(obj_desc->common.type);
342
343 return_desc = acpi_ut_create_string_object(((acpi_size)strlen(type_string) + 9));
344 if (!return_desc) {
345 return (AE_NO_MEMORY);
346 }
347
348 strcpy(return_desc->string.pointer, "[");
349 strcat(return_desc->string.pointer, type_string);
350 strcat(return_desc->string.pointer, " Object]");
351
352 *result_desc = return_desc;
353 return (AE_OK);
354}
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371acpi_status
372acpi_ex_concat_template(union acpi_operand_object *operand0,
373 union acpi_operand_object *operand1,
374 union acpi_operand_object **actual_return_desc,
375 struct acpi_walk_state *walk_state)
376{
377 acpi_status status;
378 union acpi_operand_object *return_desc;
379 u8 *new_buf;
380 u8 *end_tag;
381 acpi_size length0;
382 acpi_size length1;
383 acpi_size new_length;
384
385 ACPI_FUNCTION_TRACE(ex_concat_template);
386
387
388
389
390
391
392
393
394
395 status = acpi_ut_get_resource_end_tag(operand0, &end_tag);
396 if (ACPI_FAILURE(status)) {
397 return_ACPI_STATUS(status);
398 }
399
400 length0 = ACPI_PTR_DIFF(end_tag, operand0->buffer.pointer);
401
402
403
404 status = acpi_ut_get_resource_end_tag(operand1, &end_tag);
405 if (ACPI_FAILURE(status)) {
406 return_ACPI_STATUS(status);
407 }
408
409 length1 = ACPI_PTR_DIFF(end_tag, operand1->buffer.pointer);
410
411
412
413 new_length = length0 + length1 + sizeof(struct aml_resource_end_tag);
414
415
416
417 return_desc = acpi_ut_create_buffer_object(new_length);
418 if (!return_desc) {
419 return_ACPI_STATUS(AE_NO_MEMORY);
420 }
421
422
423
424
425
426 new_buf = return_desc->buffer.pointer;
427 memcpy(new_buf, operand0->buffer.pointer, length0);
428 memcpy(new_buf + length0, operand1->buffer.pointer, length1);
429
430
431
432 new_buf[new_length - 1] = 0;
433 new_buf[new_length - 2] = ACPI_RESOURCE_NAME_END_TAG | 1;
434
435
436
437 *actual_return_desc = return_desc;
438 return_ACPI_STATUS(AE_OK);
439}
440