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