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
45#include <acpi/acpi.h>
46#include <acpi/acinterp.h>
47#include <acpi/amlcode.h>
48#include <acpi/acnamesp.h>
49#include <acpi/acevents.h>
50#include <acpi/actables.h>
51
52
53#define _COMPONENT ACPI_EXECUTER
54 ACPI_MODULE_NAME ("exconfig")
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72acpi_status
73acpi_ex_add_table (
74 struct acpi_table_header *table,
75 struct acpi_namespace_node *parent_node,
76 union acpi_operand_object **ddb_handle)
77{
78 acpi_status status;
79 struct acpi_table_desc table_info;
80 union acpi_operand_object *obj_desc;
81
82
83 ACPI_FUNCTION_TRACE ("ex_add_table");
84
85
86
87
88 obj_desc = acpi_ut_create_internal_object (ACPI_TYPE_LOCAL_REFERENCE);
89 if (!obj_desc) {
90 return_ACPI_STATUS (AE_NO_MEMORY);
91 }
92
93
94
95 ACPI_MEMSET (&table_info, 0, sizeof (struct acpi_table_desc));
96
97 table_info.type = 5;
98 table_info.pointer = table;
99 table_info.length = (acpi_size) table->length;
100 table_info.allocation = ACPI_MEM_ALLOCATED;
101
102 status = acpi_tb_install_table (&table_info);
103 if (ACPI_FAILURE (status)) {
104 goto cleanup;
105 }
106
107
108
109 status = acpi_ns_load_table (table_info.installed_desc, parent_node);
110 if (ACPI_FAILURE (status)) {
111
112
113 (void) acpi_tb_uninstall_table (table_info.installed_desc);
114 goto cleanup;
115 }
116
117
118
119 obj_desc->reference.opcode = AML_LOAD_OP;
120 obj_desc->reference.object = table_info.installed_desc;
121 *ddb_handle = obj_desc;
122 return_ACPI_STATUS (AE_OK);
123
124
125cleanup:
126 acpi_ut_remove_reference (obj_desc);
127 return_ACPI_STATUS (status);
128}
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144acpi_status
145acpi_ex_load_table_op (
146 struct acpi_walk_state *walk_state,
147 union acpi_operand_object **return_desc)
148{
149 acpi_status status;
150 union acpi_operand_object **operand = &walk_state->operands[0];
151 struct acpi_table_header *table;
152 struct acpi_namespace_node *parent_node;
153 struct acpi_namespace_node *start_node;
154 struct acpi_namespace_node *parameter_node = NULL;
155 union acpi_operand_object *ddb_handle;
156
157
158 ACPI_FUNCTION_TRACE ("ex_load_table_op");
159
160
161#if 0
162
163
164
165
166 status = acpi_tb_match_signature (operand[0]->string.pointer, NULL);
167 if (status == AE_OK) {
168
169
170 return_ACPI_STATUS (AE_ALREADY_EXISTS);
171 }
172#endif
173
174
175
176 status = acpi_tb_find_table (operand[0]->string.pointer,
177 operand[1]->string.pointer,
178 operand[2]->string.pointer, &table);
179 if (ACPI_FAILURE (status)) {
180 if (status != AE_NOT_FOUND) {
181 return_ACPI_STATUS (status);
182 }
183
184
185
186 ddb_handle = acpi_ut_create_internal_object (ACPI_TYPE_INTEGER);
187 if (!ddb_handle) {
188 return_ACPI_STATUS (AE_NO_MEMORY);
189 }
190
191 ddb_handle->integer.value = 0;
192 *return_desc = ddb_handle;
193
194 return_ACPI_STATUS (AE_OK);
195 }
196
197
198
199 start_node = walk_state->scope_info->scope.node;
200 parent_node = acpi_gbl_root_node;
201
202
203
204 if (operand[3]->string.length > 0) {
205
206
207
208
209 status = acpi_ns_get_node_by_path (operand[3]->string.pointer, start_node,
210 ACPI_NS_SEARCH_PARENT, &parent_node);
211 if (ACPI_FAILURE (status)) {
212 return_ACPI_STATUS (status);
213 }
214 }
215
216
217
218 if (operand[4]->string.length > 0) {
219 if ((operand[4]->string.pointer[0] != '\\') &&
220 (operand[4]->string.pointer[0] != '^')) {
221
222
223
224
225 start_node = parent_node;
226 }
227
228
229
230
231 status = acpi_ns_get_node_by_path (operand[4]->string.pointer, start_node,
232 ACPI_NS_SEARCH_PARENT, ¶meter_node);
233 if (ACPI_FAILURE (status)) {
234 return_ACPI_STATUS (status);
235 }
236 }
237
238
239
240 status = acpi_ex_add_table (table, parent_node, &ddb_handle);
241 if (ACPI_FAILURE (status)) {
242 return_ACPI_STATUS (status);
243 }
244
245
246
247 if (parameter_node) {
248
249
250 status = acpi_ex_store (operand[5], ACPI_CAST_PTR (union acpi_operand_object, parameter_node),
251 walk_state);
252 if (ACPI_FAILURE (status)) {
253 (void) acpi_ex_unload_table (ddb_handle);
254 return_ACPI_STATUS (status);
255 }
256 }
257
258 *return_desc = ddb_handle;
259 return_ACPI_STATUS (status);
260}
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278acpi_status
279acpi_ex_load_op (
280 union acpi_operand_object *obj_desc,
281 union acpi_operand_object *target,
282 struct acpi_walk_state *walk_state)
283{
284 acpi_status status;
285 union acpi_operand_object *ddb_handle;
286 union acpi_operand_object *buffer_desc = NULL;
287 struct acpi_table_header *table_ptr = NULL;
288 u8 *table_data_ptr;
289 struct acpi_table_header table_header;
290 u32 i;
291
292 ACPI_FUNCTION_TRACE ("ex_load_op");
293
294
295
296
297 switch (ACPI_GET_OBJECT_TYPE (obj_desc)) {
298 case ACPI_TYPE_REGION:
299
300 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Load from Region %p %s\n",
301 obj_desc, acpi_ut_get_object_type_name (obj_desc)));
302
303
304
305 table_header.length = 0;
306 for (i = 0; i < sizeof (struct acpi_table_header); i++) {
307 status = acpi_ev_address_space_dispatch (obj_desc, ACPI_READ,
308 (acpi_physical_address) i, 8,
309 ((u8 *) &table_header) + i);
310 if (ACPI_FAILURE (status)) {
311 return_ACPI_STATUS (status);
312 }
313 }
314
315
316
317 table_ptr = ACPI_MEM_ALLOCATE (table_header.length);
318 if (!table_ptr) {
319 return_ACPI_STATUS (AE_NO_MEMORY);
320 }
321
322
323
324 ACPI_MEMCPY (table_ptr, &table_header, sizeof (struct acpi_table_header));
325 table_data_ptr = ACPI_PTR_ADD (u8, table_ptr, sizeof (struct acpi_table_header));
326
327
328
329 for (i = 0; i < table_header.length; i++) {
330 status = acpi_ev_address_space_dispatch (obj_desc, ACPI_READ,
331 (acpi_physical_address) i, 8,
332 ((u8 *) table_data_ptr + i));
333 if (ACPI_FAILURE (status)) {
334 goto cleanup;
335 }
336 }
337 break;
338
339
340 case ACPI_TYPE_LOCAL_REGION_FIELD:
341 case ACPI_TYPE_LOCAL_BANK_FIELD:
342 case ACPI_TYPE_LOCAL_INDEX_FIELD:
343
344 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Load from Field %p %s\n",
345 obj_desc, acpi_ut_get_object_type_name (obj_desc)));
346
347
348
349
350
351
352 status = acpi_ex_read_data_from_field (walk_state, obj_desc, &buffer_desc);
353 if (ACPI_FAILURE (status)) {
354 goto cleanup;
355 }
356
357 table_ptr = ACPI_CAST_PTR (struct acpi_table_header, buffer_desc->buffer.pointer);
358 break;
359
360
361 default:
362 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
363 }
364
365
366
367 if ((!ACPI_STRNCMP (table_ptr->signature,
368 acpi_gbl_table_data[ACPI_TABLE_PSDT].signature,
369 acpi_gbl_table_data[ACPI_TABLE_PSDT].sig_length)) &&
370 (!ACPI_STRNCMP (table_ptr->signature,
371 acpi_gbl_table_data[ACPI_TABLE_SSDT].signature,
372 acpi_gbl_table_data[ACPI_TABLE_SSDT].sig_length))) {
373 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
374 "Table has invalid signature [%4.4s], must be SSDT or PSDT\n",
375 table_ptr->signature));
376 status = AE_BAD_SIGNATURE;
377 goto cleanup;
378 }
379
380
381
382 status = acpi_ex_add_table (table_ptr, acpi_gbl_root_node, &ddb_handle);
383 if (ACPI_FAILURE (status)) {
384 goto cleanup;
385 }
386
387
388
389 status = acpi_ex_store (ddb_handle, target, walk_state);
390 if (ACPI_FAILURE (status)) {
391 (void) acpi_ex_unload_table (ddb_handle);
392 }
393
394 return_ACPI_STATUS (status);
395
396
397cleanup:
398
399 if (buffer_desc) {
400 acpi_ut_remove_reference (buffer_desc);
401 }
402 else {
403 ACPI_MEM_FREE (table_ptr);
404 }
405 return_ACPI_STATUS (status);
406}
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421acpi_status
422acpi_ex_unload_table (
423 union acpi_operand_object *ddb_handle)
424{
425 acpi_status status = AE_OK;
426 union acpi_operand_object *table_desc = ddb_handle;
427 struct acpi_table_desc *table_info;
428
429
430 ACPI_FUNCTION_TRACE ("ex_unload_table");
431
432
433
434
435
436
437
438
439 if ((!ddb_handle) ||
440 (ACPI_GET_DESCRIPTOR_TYPE (ddb_handle) != ACPI_DESC_TYPE_OPERAND) ||
441 (ACPI_GET_OBJECT_TYPE (ddb_handle) != ACPI_TYPE_LOCAL_REFERENCE)) {
442 return_ACPI_STATUS (AE_BAD_PARAMETER);
443 }
444
445
446
447 table_info = (struct acpi_table_desc *) table_desc->reference.object;
448
449
450
451
452
453 acpi_ns_delete_namespace_by_owner (table_info->table_id);
454
455
456
457 (void) acpi_tb_uninstall_table (table_info->installed_desc);
458
459
460
461 acpi_ut_remove_reference (table_desc);
462 return_ACPI_STATUS (status);
463}
464
465