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 "accommon.h"
47#include "acnamesp.h"
48#include "acparser.h"
49#include "amlcode.h"
50
51#define _COMPONENT ACPI_NAMESPACE
52ACPI_MODULE_NAME("nsxfname")
53
54
55static char *acpi_ns_copy_device_id(struct acpica_device_id *dest,
56 struct acpica_device_id *source,
57 char *string_area);
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77acpi_status
78acpi_get_handle(acpi_handle parent,
79 acpi_string pathname, acpi_handle * ret_handle)
80{
81 acpi_status status;
82 struct acpi_namespace_node *node = NULL;
83 struct acpi_namespace_node *prefix_node = NULL;
84
85 ACPI_FUNCTION_ENTRY();
86
87
88
89 if (!ret_handle || !pathname) {
90 return (AE_BAD_PARAMETER);
91 }
92
93
94
95 if (parent) {
96 prefix_node = acpi_ns_map_handle_to_node(parent);
97 if (!prefix_node) {
98 return (AE_BAD_PARAMETER);
99 }
100 }
101
102
103
104
105
106
107
108
109 if (acpi_ns_valid_root_prefix(pathname[0])) {
110
111
112
113
114
115 if (!ACPI_STRCMP(pathname, ACPI_NS_ROOT_PATH)) {
116 *ret_handle =
117 acpi_ns_convert_entry_to_handle(acpi_gbl_root_node);
118 return (AE_OK);
119 }
120 } else if (!prefix_node) {
121
122
123
124 return (AE_BAD_PARAMETER);
125 }
126
127
128
129 status =
130 acpi_ns_get_node(prefix_node, pathname, ACPI_NS_NO_UPSEARCH, &node);
131 if (ACPI_SUCCESS(status)) {
132 *ret_handle = acpi_ns_convert_entry_to_handle(node);
133 }
134
135 return (status);
136}
137
138ACPI_EXPORT_SYMBOL(acpi_get_handle)
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155acpi_status
156acpi_get_name(acpi_handle handle, u32 name_type, struct acpi_buffer * buffer)
157{
158 acpi_status status;
159 struct acpi_namespace_node *node;
160
161
162
163 if (name_type > ACPI_NAME_TYPE_MAX) {
164 return (AE_BAD_PARAMETER);
165 }
166
167 status = acpi_ut_validate_buffer(buffer);
168 if (ACPI_FAILURE(status)) {
169 return (status);
170 }
171
172 if (name_type == ACPI_FULL_PATHNAME) {
173
174
175
176 status = acpi_ns_handle_to_pathname(handle, buffer);
177 return (status);
178 }
179
180
181
182
183
184 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
185 if (ACPI_FAILURE(status)) {
186 return (status);
187 }
188
189 node = acpi_ns_map_handle_to_node(handle);
190 if (!node) {
191 status = AE_BAD_PARAMETER;
192 goto unlock_and_exit;
193 }
194
195
196
197 status = acpi_ut_initialize_buffer(buffer, ACPI_PATH_SEGMENT_LENGTH);
198 if (ACPI_FAILURE(status)) {
199 goto unlock_and_exit;
200 }
201
202
203
204 ACPI_STRNCPY(buffer->pointer, acpi_ut_get_node_name(node),
205 ACPI_NAME_SIZE);
206 ((char *)buffer->pointer)[ACPI_NAME_SIZE] = 0;
207 status = AE_OK;
208
209 unlock_and_exit:
210
211 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
212 return (status);
213}
214
215ACPI_EXPORT_SYMBOL(acpi_get_name)
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230static char *acpi_ns_copy_device_id(struct acpica_device_id *dest,
231 struct acpica_device_id *source,
232 char *string_area)
233{
234
235
236 dest->string = string_area;
237 dest->length = source->length;
238
239
240
241 ACPI_MEMCPY(string_area, source->string, source->length);
242 return (string_area + source->length);
243}
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265acpi_status
266acpi_get_object_info(acpi_handle handle,
267 struct acpi_device_info **return_buffer)
268{
269 struct acpi_namespace_node *node;
270 struct acpi_device_info *info;
271 struct acpica_device_id_list *cid_list = NULL;
272 struct acpica_device_id *hid = NULL;
273 struct acpica_device_id *uid = NULL;
274 char *next_id_string;
275 acpi_object_type type;
276 acpi_name name;
277 u8 param_count = 0;
278 u8 valid = 0;
279 u32 info_size;
280 u32 i;
281 acpi_status status;
282
283
284
285 if (!handle || !return_buffer) {
286 return (AE_BAD_PARAMETER);
287 }
288
289 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
290 if (ACPI_FAILURE(status)) {
291 goto cleanup;
292 }
293
294 node = acpi_ns_map_handle_to_node(handle);
295 if (!node) {
296 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
297 return (AE_BAD_PARAMETER);
298 }
299
300
301
302 info_size = sizeof(struct acpi_device_info);
303 type = node->type;
304 name = node->name.integer;
305
306 if (node->type == ACPI_TYPE_METHOD) {
307 param_count = node->object->method.param_count;
308 }
309
310 status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
311 if (ACPI_FAILURE(status)) {
312 return (status);
313 }
314
315 if ((type == ACPI_TYPE_DEVICE) || (type == ACPI_TYPE_PROCESSOR)) {
316
317
318
319
320
321
322
323
324
325
326
327 status = acpi_ut_execute_HID(node, &hid);
328 if (ACPI_SUCCESS(status)) {
329 info_size += hid->length;
330 valid |= ACPI_VALID_HID;
331 }
332
333
334
335 status = acpi_ut_execute_UID(node, &uid);
336 if (ACPI_SUCCESS(status)) {
337 info_size += uid->length;
338 valid |= ACPI_VALID_UID;
339 }
340
341
342
343 status = acpi_ut_execute_CID(node, &cid_list);
344 if (ACPI_SUCCESS(status)) {
345
346
347
348 info_size +=
349 (cid_list->list_size -
350 sizeof(struct acpica_device_id_list));
351 valid |= ACPI_VALID_CID;
352 }
353 }
354
355
356
357
358
359 info = ACPI_ALLOCATE_ZEROED(info_size);
360 if (!info) {
361 status = AE_NO_MEMORY;
362 goto cleanup;
363 }
364
365
366
367 if ((type == ACPI_TYPE_DEVICE) || (type == ACPI_TYPE_PROCESSOR)) {
368
369
370
371
372
373
374
375
376
377
378
379 status = acpi_ut_execute_STA(node, &info->current_status);
380 if (ACPI_SUCCESS(status)) {
381 valid |= ACPI_VALID_STA;
382 }
383
384
385
386 status = acpi_ut_evaluate_numeric_object(METHOD_NAME__ADR, node,
387 &info->address);
388 if (ACPI_SUCCESS(status)) {
389 valid |= ACPI_VALID_ADR;
390 }
391
392
393
394 status = acpi_ut_execute_power_methods(node,
395 acpi_gbl_lowest_dstate_names,
396 ACPI_NUM_sx_w_METHODS,
397 info->lowest_dstates);
398 if (ACPI_SUCCESS(status)) {
399 valid |= ACPI_VALID_SXWS;
400 }
401
402
403
404 status = acpi_ut_execute_power_methods(node,
405 acpi_gbl_highest_dstate_names,
406 ACPI_NUM_sx_d_METHODS,
407 info->highest_dstates);
408 if (ACPI_SUCCESS(status)) {
409 valid |= ACPI_VALID_SXDS;
410 }
411 }
412
413
414
415
416
417 next_id_string = ACPI_CAST_PTR(char, info->compatible_id_list.ids);
418 if (cid_list) {
419
420
421
422 next_id_string +=
423 ((acpi_size) cid_list->count *
424 sizeof(struct acpica_device_id));
425 }
426
427
428
429
430
431
432
433 if (hid) {
434 next_id_string = acpi_ns_copy_device_id(&info->hardware_id,
435 hid, next_id_string);
436
437 if (acpi_ut_is_pci_root_bridge(hid->string)) {
438 info->flags |= ACPI_PCI_ROOT_BRIDGE;
439 }
440 }
441
442 if (uid) {
443 next_id_string = acpi_ns_copy_device_id(&info->unique_id,
444 uid, next_id_string);
445 }
446
447 if (cid_list) {
448 info->compatible_id_list.count = cid_list->count;
449 info->compatible_id_list.list_size = cid_list->list_size;
450
451
452
453 for (i = 0; i < cid_list->count; i++) {
454 next_id_string =
455 acpi_ns_copy_device_id(&info->compatible_id_list.
456 ids[i], &cid_list->ids[i],
457 next_id_string);
458
459 if (acpi_ut_is_pci_root_bridge(cid_list->ids[i].string)) {
460 info->flags |= ACPI_PCI_ROOT_BRIDGE;
461 }
462 }
463 }
464
465
466
467 info->info_size = info_size;
468 info->type = type;
469 info->name = name;
470 info->param_count = param_count;
471 info->valid = valid;
472
473 *return_buffer = info;
474 status = AE_OK;
475
476 cleanup:
477 if (hid) {
478 ACPI_FREE(hid);
479 }
480 if (uid) {
481 ACPI_FREE(uid);
482 }
483 if (cid_list) {
484 ACPI_FREE(cid_list);
485 }
486 return (status);
487}
488
489ACPI_EXPORT_SYMBOL(acpi_get_object_info)
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505acpi_status acpi_install_method(u8 *buffer)
506{
507 struct acpi_table_header *table =
508 ACPI_CAST_PTR(struct acpi_table_header, buffer);
509 u8 *aml_buffer;
510 u8 *aml_start;
511 char *path;
512 struct acpi_namespace_node *node;
513 union acpi_operand_object *method_obj;
514 struct acpi_parse_state parser_state;
515 u32 aml_length;
516 u16 opcode;
517 u8 method_flags;
518 acpi_status status;
519
520
521
522 if (!buffer) {
523 return AE_BAD_PARAMETER;
524 }
525
526
527
528 if (!ACPI_COMPARE_NAME(table->signature, ACPI_SIG_DSDT) &&
529 !ACPI_COMPARE_NAME(table->signature, ACPI_SIG_SSDT)) {
530 return AE_BAD_HEADER;
531 }
532
533
534
535 parser_state.aml = buffer + sizeof(struct acpi_table_header);
536 opcode = acpi_ps_peek_opcode(&parser_state);
537 if (opcode != AML_METHOD_OP) {
538 return AE_BAD_PARAMETER;
539 }
540
541
542
543 parser_state.aml += acpi_ps_get_opcode_size(opcode);
544 parser_state.pkg_end = acpi_ps_get_next_package_end(&parser_state);
545 path = acpi_ps_get_next_namestring(&parser_state);
546 method_flags = *parser_state.aml++;
547 aml_start = parser_state.aml;
548 aml_length = ACPI_PTR_DIFF(parser_state.pkg_end, aml_start);
549
550
551
552
553
554 aml_buffer = ACPI_ALLOCATE(aml_length);
555 if (!aml_buffer) {
556 return AE_NO_MEMORY;
557 }
558
559 method_obj = acpi_ut_create_internal_object(ACPI_TYPE_METHOD);
560 if (!method_obj) {
561 ACPI_FREE(aml_buffer);
562 return AE_NO_MEMORY;
563 }
564
565
566
567 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
568 if (ACPI_FAILURE(status)) {
569 goto error_exit;
570 }
571
572
573
574 status =
575 acpi_ns_lookup(NULL, path, ACPI_TYPE_METHOD, ACPI_IMODE_LOAD_PASS1,
576 ACPI_NS_DONT_OPEN_SCOPE | ACPI_NS_ERROR_IF_FOUND,
577 NULL, &node);
578
579 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
580
581 if (ACPI_FAILURE(status)) {
582 if (status != AE_ALREADY_EXISTS) {
583 goto error_exit;
584 }
585
586
587
588 if (node->type != ACPI_TYPE_METHOD) {
589 status = AE_TYPE;
590 goto error_exit;
591 }
592 }
593
594
595
596 ACPI_MEMCPY(aml_buffer, aml_start, aml_length);
597
598
599
600 method_obj->method.aml_start = aml_buffer;
601 method_obj->method.aml_length = aml_length;
602
603 method_obj->method.param_count = (u8)
604 (method_flags & AML_METHOD_ARG_COUNT);
605
606 method_obj->method.method_flags = (u8)
607 (method_flags & ~AML_METHOD_ARG_COUNT);
608
609 if (method_flags & AML_METHOD_SERIALIZED) {
610 method_obj->method.sync_level = (u8)
611 ((method_flags & AML_METHOD_SYNC_LEVEL) >> 4);
612 }
613
614
615
616
617
618 status = acpi_ns_attach_object(node, method_obj, ACPI_TYPE_METHOD);
619
620
621
622
623
624 node->flags |= ANOBJ_ALLOCATED_BUFFER;
625
626
627
628 acpi_ut_remove_reference(method_obj);
629 return status;
630
631error_exit:
632
633 ACPI_FREE(aml_buffer);
634 ACPI_FREE(method_obj);
635 return status;
636}
637ACPI_EXPORT_SYMBOL(acpi_install_method)
638