PatchworkOS
Loading...
Searching...
No Matches
named.c
Go to the documentation of this file.
2
12#include <kernel/acpi/tables.h>
13#include <kernel/log/log.h>
14
16{
17 if (aml_term_arg_read_integer(ctx, out) == ERR)
18 {
19 AML_DEBUG_ERROR(ctx, "Failed to read TermArg");
20 return ERR;
21 }
22
23 return 0;
24}
25
27{
28 uint8_t byte;
29 if (aml_byte_data_read(ctx, &byte) == ERR)
30 {
31 AML_DEBUG_ERROR(ctx, "Failed to read ByteData");
32 return ERR;
33 }
34
35 if (byte > AML_REGION_PCC && byte < AML_REGION_OEM_MIN)
36 {
37 AML_DEBUG_ERROR(ctx, "Invalid RegionSpace: '0x%x'", byte);
38 errno = EILSEQ;
39 return ERR;
40 }
41
42 *out = (aml_region_space_t)byte;
43 return 0;
44}
45
47{
48 if (aml_term_arg_read_integer(ctx, out) == ERR)
49 {
50 AML_DEBUG_ERROR(ctx, "Failed to read TermArg");
51 return ERR;
52 }
53
54 return 0;
55}
56
58{
59 if (aml_term_arg_read_integer(ctx, out) == ERR)
60 {
61 AML_DEBUG_ERROR(ctx, "Failed to read TermArg");
62 return ERR;
63 }
64
65 return 0;
66}
67
69{
71 {
72 AML_DEBUG_ERROR(ctx, "Failed to read OpRegionOp");
73 return ERR;
74 }
75
76 aml_name_string_t nameString;
77 if (aml_name_string_read(ctx, &nameString) == ERR)
78 {
79 AML_DEBUG_ERROR(ctx, "Failed to read NameString");
80 return ERR;
81 }
82
83 aml_region_space_t regionSpace;
84 if (aml_region_space_read(ctx, &regionSpace) == ERR)
85 {
86 AML_DEBUG_ERROR(ctx, "Failed to read RegionSpace");
87 return ERR;
88 }
89
90 uint64_t regionOffset;
91 if (aml_region_offset_read(ctx, &regionOffset) == ERR)
92 {
93 AML_DEBUG_ERROR(ctx, "Failed to read RegionOffset");
94 return ERR;
95 }
96
97 uint64_t regionLen;
98 if (aml_region_len_read(ctx, &regionLen) == ERR)
99 {
100 AML_DEBUG_ERROR(ctx, "Failed to read RegionLen");
101 return ERR;
102 }
103
104 aml_object_t* newObject = aml_object_new();
105 if (newObject == NULL)
106 {
107 AML_DEBUG_ERROR(ctx, "Failed to create object '%s'", aml_name_string_to_string(&nameString));
108 return ERR;
109 }
110 DEREF_DEFER(newObject);
111
112 if (aml_operation_region_set(newObject, regionSpace, regionOffset, regionLen) == ERR ||
113 aml_namespace_add_by_name_string(&ctx->state->overlay, ctx->scope, &nameString, newObject) == ERR)
114 {
115 AML_DEBUG_ERROR(ctx, "Failed to add object '%s'", aml_name_string_to_string(&nameString));
116 return ERR;
117 }
118
119 return 0;
120}
121
123{
124 uint8_t flags;
125 if (aml_byte_data_read(ctx, &flags) == ERR)
126 {
127 AML_DEBUG_ERROR(ctx, "Failed to read ByteData");
128 return ERR;
129 }
130
131 if (flags & (1 << 7))
132 {
133 AML_DEBUG_ERROR(ctx, "Reserved bit 7 is set in FieldFlags '0x%x'", flags);
134 errno = EILSEQ;
135 return ERR;
136 }
137
138 aml_access_type_t accessType = flags & 0xF;
139 if (accessType > AML_ACCESS_TYPE_BUFFER)
140 {
141 AML_DEBUG_ERROR(ctx, "Invalid AccessType in FieldFlags '0x%x'", accessType);
142 errno = EILSEQ;
143 return ERR;
144 }
145
146 *out = (aml_field_flags_t){
147 .accessType = accessType,
148 .lockRule = (flags >> 4) & 0x1,
149 .updateRule = (flags >> 5) & 0x3,
150 };
151
152 return 0;
153}
154
156{
157 aml_name_seg_t* name;
158 if (aml_name_seg_read(ctx, &name) == ERR)
159 {
160 AML_DEBUG_ERROR(ctx, "Failed to read NameSeg");
161 return ERR;
162 }
163
164 aml_pkg_length_t pkgLength;
165 if (aml_pkg_length_read(ctx, &pkgLength) == ERR)
166 {
167 AML_DEBUG_ERROR(ctx, "Failed to read PkgLength");
168 return ERR;
169 }
170
171 aml_object_t* newObject = aml_object_new();
172 if (newObject == NULL)
173 {
174 return ERR;
175 }
176 DEREF_DEFER(newObject);
177
178 switch (fieldCtx->type)
179 {
181 {
182 if (fieldCtx->field.opregion == NULL)
183 {
184 AML_DEBUG_ERROR(ctx, "opregion is null");
185 errno = EILSEQ;
186 return ERR;
187 }
188
189 if (aml_field_unit_field_set(newObject, fieldCtx->field.opregion, fieldCtx->flags, fieldCtx->currentOffset,
190 pkgLength) == ERR)
191 {
192 return ERR;
193 }
194 }
195 break;
197 {
198 if (fieldCtx->index.index == NULL)
199 {
200 AML_DEBUG_ERROR(ctx, "index is null");
201 errno = EILSEQ;
202 return ERR;
203 }
204
205 if (fieldCtx->index.index == NULL)
206 {
207 AML_DEBUG_ERROR(ctx, "dataObject is null");
208 errno = EILSEQ;
209 return ERR;
210 }
211
212 if (aml_field_unit_index_field_set(newObject, fieldCtx->index.index, fieldCtx->index.data, fieldCtx->flags,
213 fieldCtx->currentOffset, pkgLength) == ERR)
214 {
215 return ERR;
216 }
217 }
218 break;
220 {
221 if (fieldCtx->bank.opregion == NULL)
222 {
223 AML_DEBUG_ERROR(ctx, "opregion is null");
224 errno = EILSEQ;
225 return ERR;
226 }
227
228 if (fieldCtx->bank.bank == NULL)
229 {
230 AML_DEBUG_ERROR(ctx, "bank is null");
231 errno = EILSEQ;
232 return ERR;
233 }
234
235 if (aml_field_unit_bank_field_set(newObject, fieldCtx->bank.opregion, fieldCtx->bank.bank,
236 fieldCtx->bank.bankValue, fieldCtx->flags, fieldCtx->currentOffset, pkgLength) == ERR)
237 {
238 return ERR;
239 }
240 }
241 break;
242 default:
243 AML_DEBUG_ERROR(ctx, "Invalid FieldList type '%d'", fieldCtx->type);
244 errno = EILSEQ;
245 return ERR;
246 }
247
248 if (aml_namespace_add_child(&ctx->state->overlay, ctx->scope, *name, newObject) == ERR)
249 {
250 AML_DEBUG_ERROR(ctx, "Failed to add object '%s'", AML_NAME_TO_STRING(*name));
251 return ERR;
252 }
253
254 fieldCtx->currentOffset += pkgLength;
255 return 0;
256}
257
259{
260 if (aml_token_expect(ctx, 0x00) == ERR)
261 {
262 AML_DEBUG_ERROR(ctx, "Failed to read ReservedField");
263 return ERR;
264 }
265
266 aml_pkg_length_t pkgLength;
267 if (aml_pkg_length_read(ctx, &pkgLength) == ERR)
268 {
269 AML_DEBUG_ERROR(ctx, "Failed to read PkgLength");
270 return ERR;
271 }
272
273 fieldCtx->currentOffset += pkgLength;
274 return 0;
275}
276
278{
279 aml_token_t token;
280 aml_token_peek(ctx, &token);
281
282 if (AML_IS_LEAD_NAME_CHAR(&token))
283 {
284 if (aml_name_field_read(ctx, fieldCtx) == ERR)
285 {
286 AML_DEBUG_ERROR(ctx, "Failed to read NamedField");
287 return ERR;
288 }
289 }
290 else if (token.num == 0x00)
291 {
292 if (aml_reserved_field_read(ctx, fieldCtx) == ERR)
293 {
294 AML_DEBUG_ERROR(ctx, "Failed to read ReservedField");
295 return ERR;
296 }
297 }
298 else
299 {
300 AML_DEBUG_ERROR(ctx, "Invalid field element token '0x%x'", token.num);
301 errno = ENOSYS;
302 return ERR;
303 }
304
305 return 0;
306}
307
309{
310 while (end > ctx->current)
311 {
312 // End of buffer not reached => byte is not nothing => must be a FieldElement.
313 if (aml_field_element_read(ctx, fieldCtx) == ERR)
314 {
315 AML_DEBUG_ERROR(ctx, "Failed to read field element");
316 return ERR;
317 }
318 }
319
320 return 0;
321}
322
324{
325 if (aml_token_expect(ctx, AML_FIELD_OP) == ERR)
326 {
327 AML_DEBUG_ERROR(ctx, "Failed to read FieldOp");
328 return ERR;
329 }
330
331 const uint8_t* start = ctx->current;
332
333 aml_pkg_length_t pkgLength;
334 if (aml_pkg_length_read(ctx, &pkgLength) == ERR)
335 {
336 AML_DEBUG_ERROR(ctx, "Failed to read PkgLength");
337 return ERR;
338 }
339
341 if (opregion == NULL)
342 {
343 AML_DEBUG_ERROR(ctx, "Failed to read or resolve NameString");
344 return ERR;
345 }
346 DEREF_DEFER(opregion);
347
348 if (opregion->type != AML_OPERATION_REGION)
349 {
350 AML_DEBUG_ERROR(ctx, "OpRegion is not of type OperationRegion");
351 errno = EILSEQ;
352 return ERR;
353 }
354
355 aml_field_flags_t fieldFlags;
356 if (aml_field_flags_read(ctx, &fieldFlags) == ERR)
357 {
358 AML_DEBUG_ERROR(ctx, "Failed to read field flags");
359 return ERR;
360 }
361
362 const uint8_t* end = start + pkgLength;
363
364 aml_field_list_ctx_t fieldCtx = {
366 .flags = fieldFlags,
367 .currentOffset = 0,
368 .field.opregion = &opregion->opregion,
369 };
370
371 if (aml_field_list_read(ctx, &fieldCtx, end) == ERR)
372 {
373 AML_DEBUG_ERROR(ctx, "Failed to read field list");
374 return ERR;
375 }
376
377 return 0;
378}
379
381{
383 {
384 AML_DEBUG_ERROR(ctx, "Failed to read IndexFieldOp");
385 return ERR;
386 }
387
388 const uint8_t* start = ctx->current;
389
390 aml_pkg_length_t pkgLength;
391 if (aml_pkg_length_read(ctx, &pkgLength) == ERR)
392 {
393 AML_DEBUG_ERROR(ctx, "Failed to read PkgLength");
394 return ERR;
395 }
396
398 if (index == NULL)
399 {
400 AML_DEBUG_ERROR(ctx, "Failed to read or resolve index NameString");
401 return ERR;
402 }
403 DEREF_DEFER(index);
404
406 if (data == NULL)
407 {
408 AML_DEBUG_ERROR(ctx, "Failed to read or resolve data NameString");
409 return ERR;
410 }
412
413 aml_field_flags_t fieldFlags;
414 if (aml_field_flags_read(ctx, &fieldFlags) == ERR)
415 {
416 AML_DEBUG_ERROR(ctx, "Failed to read field flags");
417 return ERR;
418 }
419
420 if (index->type != AML_FIELD_UNIT)
421 {
422 AML_DEBUG_ERROR(ctx, "Index is not of type FieldUnit");
423 errno = EILSEQ;
424 return ERR;
425 }
426
427 if (data->type != AML_FIELD_UNIT)
428 {
429 AML_DEBUG_ERROR(ctx, "Data is not of type FieldUnit");
430 errno = EILSEQ;
431 return ERR;
432 }
433
434 const uint8_t* end = start + pkgLength;
435
437 .flags = fieldFlags,
438 .currentOffset = 0,
439 .index.index = &index->fieldUnit,
440 .index.data = &data->fieldUnit};
441
442 if (aml_field_list_read(ctx, &fieldCtx, end) == ERR)
443 {
444 AML_DEBUG_ERROR(ctx, "Failed to read field list");
445 return ERR;
446 }
447
448 return 0;
449}
450
452{
454 {
455 AML_DEBUG_ERROR(ctx, "Failed to read BankFieldOp");
456 return ERR;
457 }
458
459 const uint8_t* start = ctx->current;
460
461 aml_pkg_length_t pkgLength;
462 if (aml_pkg_length_read(ctx, &pkgLength) == ERR)
463 {
464 AML_DEBUG_ERROR(ctx, "Failed to read PkgLength");
465 return ERR;
466 }
467
468 const uint8_t* end = start + pkgLength;
469
471 if (opregion == NULL)
472 {
473 AML_DEBUG_ERROR(ctx, "Failed to read or resolve opregion NameString");
474 return ERR;
475 }
476 DEREF_DEFER(opregion);
477
479 if (bank == NULL)
480 {
481 AML_DEBUG_ERROR(ctx, "Failed to read or resolve bank NameString");
482 return ERR;
483 }
484 DEREF_DEFER(bank);
485
486 uint64_t bankValue;
487 if (aml_bank_value_read(ctx, &bankValue) == ERR)
488 {
489 AML_DEBUG_ERROR(ctx, "Failed to read BankValue");
490 return ERR;
491 }
492
493 aml_field_flags_t fieldFlags;
494 if (aml_field_flags_read(ctx, &fieldFlags) == ERR)
495 {
496 AML_DEBUG_ERROR(ctx, "Failed to read FieldFlags");
497 return ERR;
498 }
499
500 aml_field_list_ctx_t fieldCtx = {
502 .flags = fieldFlags,
503 .currentOffset = 0,
504 .bank.opregion = &opregion->opregion,
505 .bank.bank = &bank->fieldUnit,
506 .bank.bankValue = bankValue,
507 };
508
509 if (aml_field_list_read(ctx, &fieldCtx, end) == ERR)
510 {
511 AML_DEBUG_ERROR(ctx, "Failed to read FieldList");
512 return ERR;
513 }
514
515 return 0;
516}
517
519{
520 uint8_t flags;
521 if (aml_byte_data_read(ctx, &flags) == ERR)
522 {
523 AML_DEBUG_ERROR(ctx, "Failed to read ByteData");
524 return ERR;
525 }
526
527 uint8_t argCount = flags & 0x7;
528 bool isSerialized = (flags >> 3) & 0x1;
529 uint8_t syncLevel = (flags >> 4) & 0xF;
530
531 *out = (aml_method_flags_t){
532 .argCount = argCount,
533 .isSerialized = isSerialized,
534 .syncLevel = syncLevel,
535 };
536
537 return 0;
538}
539
541{
543 {
544 AML_DEBUG_ERROR(ctx, "Failed to read MethodOp");
545 return ERR;
546 }
547
548 const uint8_t* start = ctx->current;
549
550 aml_pkg_length_t pkgLength;
551 if (aml_pkg_length_read(ctx, &pkgLength) == ERR)
552 {
553 AML_DEBUG_ERROR(ctx, "Failed to read PkgLength");
554 return ERR;
555 }
556
557 aml_name_string_t nameString;
558 if (aml_name_string_read(ctx, &nameString) == ERR)
559 {
560 AML_DEBUG_ERROR(ctx, "Failed to read NameString");
561 return ERR;
562 }
563
564 aml_method_flags_t methodFlags;
565 if (aml_method_flags_read(ctx, &methodFlags) == ERR)
566 {
567 AML_DEBUG_ERROR(ctx, "Failed to read MethodFlags");
568 return ERR;
569 }
570
571 const uint8_t* end = start + pkgLength;
572
573 aml_object_t* newObject = aml_object_new();
574 if (newObject == NULL)
575 {
576 return ERR;
577 }
578 DEREF_DEFER(newObject);
579
580 if (aml_method_set(newObject, methodFlags, ctx->current, end, NULL) == ERR ||
581 aml_namespace_add_by_name_string(&ctx->state->overlay, ctx->scope, &nameString, newObject) == ERR)
582 {
583 AML_DEBUG_ERROR(ctx, "Failed to add object '%s'", aml_name_string_to_string(&nameString));
584 return ERR;
585 }
586
587 // We are only defining the method, not executing it, so we skip its body, and only parse it when it is called.
588 ctx->current = end;
589
590 return 0;
591}
592
594{
596 {
597 AML_DEBUG_ERROR(ctx, "Failed to read DeviceOp");
598 return ERR;
599 }
600
601 const uint8_t* start = ctx->current;
602
603 aml_pkg_length_t pkgLength;
604 if (aml_pkg_length_read(ctx, &pkgLength) == ERR)
605 {
606 AML_DEBUG_ERROR(ctx, "Failed to read PkgLength");
607 return ERR;
608 }
609
610 aml_name_string_t nameString;
611 if (aml_name_string_read(ctx, &nameString) == ERR)
612 {
613 AML_DEBUG_ERROR(ctx, "Failed to read NameString");
614 return ERR;
615 }
616
617 const uint8_t* end = start + pkgLength;
618
619 aml_object_t* device = aml_object_new();
620 if (device == NULL)
621 {
622 return ERR;
623 }
624 DEREF_DEFER(device);
625
626 if (aml_device_set(device) == ERR ||
627 aml_namespace_add_by_name_string(&ctx->state->overlay, ctx->scope, &nameString, device) == ERR)
628 {
629 AML_DEBUG_ERROR(ctx, "Failed to add object '%s'", aml_name_string_to_string(&nameString));
630 return ERR;
631 }
632
633 if (aml_term_list_read(ctx->state, device, ctx->current, end, ctx) == ERR)
634 {
635 AML_DEBUG_ERROR(ctx, "Failed to read Device body");
636 return ERR;
637 }
638
639 ctx->current = end;
640 return 0;
641}
642
644{
645 uint8_t flags;
646 if (aml_byte_data_read(ctx, &flags) == ERR)
647 {
648 AML_DEBUG_ERROR(ctx, "Failed to read ByteData");
649 return ERR;
650 }
651
652 if (flags & 0xF0)
653 {
654 AML_DEBUG_ERROR(ctx, "Reserved bits are set in SyncFlags '0x%x'", flags);
655 errno = EILSEQ;
656 return ERR;
657 }
658
659 *out = flags & 0x0F;
660 return 0;
661}
662
664{
665 if (aml_token_expect(ctx, AML_MUTEX_OP) == ERR)
666 {
667 AML_DEBUG_ERROR(ctx, "Failed to read MutexOp");
668 return ERR;
669 }
670
671 aml_name_string_t nameString;
672 if (aml_name_string_read(ctx, &nameString) == ERR)
673 {
674 AML_DEBUG_ERROR(ctx, "Failed to read NameString");
675 return ERR;
676 }
677
678 aml_sync_level_t syncFlags;
679 if (aml_sync_flags_read(ctx, &syncFlags) == ERR)
680 {
681 AML_DEBUG_ERROR(ctx, "Failed to read SyncFlags");
682 return ERR;
683 }
684
685 aml_object_t* newObject = aml_object_new();
686 if (newObject == NULL)
687 {
688 return ERR;
689 }
690 DEREF_DEFER(newObject);
691
692 if (aml_mutex_set(newObject, syncFlags) == ERR ||
693 aml_namespace_add_by_name_string(&ctx->state->overlay, ctx->scope, &nameString, newObject) == ERR)
694 {
695 AML_DEBUG_ERROR(ctx, "Failed to add object '%s'", aml_name_string_to_string(&nameString));
696 return ERR;
697 }
698
699 return 0;
700}
701
703{
704 if (aml_byte_data_read(ctx, out) == ERR)
705 {
706 AML_DEBUG_ERROR(ctx, "Failed to read ByteData");
707 return ERR;
708 }
709 return 0;
710}
711
713{
714 if (aml_dword_data_read(ctx, out) == ERR)
715 {
716 AML_DEBUG_ERROR(ctx, "Failed to read DWordData");
717 return ERR;
718 }
719 return 0;
720}
721
723{
724 if (aml_byte_data_read(ctx, out) == ERR)
725 {
726 AML_DEBUG_ERROR(ctx, "Failed to read ByteData");
727 return ERR;
728 }
729 return 0;
730}
731
733{
735 {
736 AML_DEBUG_ERROR(ctx, "Failed to read ProcessorOp");
737 return ERR;
738 }
739
740 const uint8_t* start = ctx->current;
741
742 aml_pkg_length_t pkgLength;
743 if (aml_pkg_length_read(ctx, &pkgLength) == ERR)
744 {
745 AML_DEBUG_ERROR(ctx, "Failed to read PkgLength");
746 return ERR;
747 }
748
749 aml_name_string_t nameString;
750 if (aml_name_string_read(ctx, &nameString) == ERR)
751 {
752 AML_DEBUG_ERROR(ctx, "Failed to read NameString");
753 return ERR;
754 }
755
756 aml_proc_id_t procId;
757 if (aml_proc_id_read(ctx, &procId) == ERR)
758 {
759 AML_DEBUG_ERROR(ctx, "Failed to read proc id");
760 return ERR;
761 }
762
763 aml_pblk_addr_t pblkAddr;
764 if (aml_pblk_addr_read(ctx, &pblkAddr) == ERR)
765 {
766 AML_DEBUG_ERROR(ctx, "Failed to read pblk addr");
767 return ERR;
768 }
769
770 aml_pblk_len_t pblkLen;
771 if (aml_pblk_len_read(ctx, &pblkLen) == ERR)
772 {
773 AML_DEBUG_ERROR(ctx, "Failed to read pblk len");
774 return ERR;
775 }
776
777 const uint8_t* end = start + pkgLength;
778
779 aml_object_t* processor = aml_object_new();
780 if (processor == NULL)
781 {
782 return ERR;
783 }
784 DEREF_DEFER(processor);
785
786 if (aml_processor_set(processor, procId, pblkAddr, pblkLen) == ERR ||
787 aml_namespace_add_by_name_string(&ctx->state->overlay, ctx->scope, &nameString, processor) == ERR)
788 {
789 AML_DEBUG_ERROR(ctx, "Failed to add object '%s'", aml_name_string_to_string(&nameString));
790 return ERR;
791 }
792
793 if (aml_term_list_read(ctx->state, processor, ctx->current, end, ctx) == ERR)
794 {
795 AML_DEBUG_ERROR(ctx, "Failed to read Processor body");
796 return ERR;
797 }
798
799 ctx->current = end;
800 return 0;
801}
802
804{
805 aml_object_t* sourceBuff = aml_term_arg_read(ctx, AML_BUFFER);
806 if (sourceBuff == NULL)
807 {
808 AML_DEBUG_ERROR(ctx, "Failed to read TermArg");
809 return NULL;
810 }
811
812 return sourceBuff; // Transfer ownership
813}
814
816{
817 if (aml_term_arg_read_integer(ctx, out) == ERR)
818 {
819 AML_DEBUG_ERROR(ctx, "Failed to read TermArg");
820 return ERR;
821 }
822
823 return 0;
824}
825
827{
828 if (aml_term_arg_read_integer(ctx, out) == ERR)
829 {
830 AML_DEBUG_ERROR(ctx, "Failed to read TermArg");
831 return ERR;
832 }
833
834 return 0;
835}
836
838{
840 {
841 AML_DEBUG_ERROR(ctx, "Failed to read CreateBitFieldOp");
842 return ERR;
843 }
844
845 aml_object_t* sourceBuff = aml_source_buff_read(ctx);
846 if (sourceBuff == NULL)
847 {
848 AML_DEBUG_ERROR(ctx, "Failed to read SourceBuff");
849 return ERR;
850 }
851 DEREF_DEFER(sourceBuff);
852
853 assert(sourceBuff->type == AML_BUFFER);
854
855 uint64_t bitIndex;
856 if (aml_bit_index_read(ctx, &bitIndex) == ERR)
857 {
858 AML_DEBUG_ERROR(ctx, "Failed to read BitIndex");
859 return ERR;
860 }
861
862 aml_name_string_t nameString;
863 if (aml_name_string_read(ctx, &nameString) == ERR)
864 {
865 AML_DEBUG_ERROR(ctx, "Failed to read NameString");
866 return ERR;
867 }
868
869 aml_object_t* newObject = aml_object_new();
870 if (newObject == NULL)
871 {
872 return ERR;
873 }
874 DEREF_DEFER(newObject);
875
876 if (aml_buffer_field_set(newObject, sourceBuff, bitIndex, 1) == ERR ||
877 aml_namespace_add_by_name_string(&ctx->state->overlay, ctx->scope, &nameString, newObject) == ERR)
878 {
879 AML_DEBUG_ERROR(ctx, "Failed to add object '%s'", aml_name_string_to_string(&nameString));
880 return ERR;
881 }
882
883 return 0;
884}
885
887 aml_token_num_t expectedOp)
888{
889 if (aml_token_expect(ctx, expectedOp) == ERR)
890 {
891 AML_DEBUG_ERROR(ctx, "Failed to read expected op");
892 return ERR;
893 }
894
895 aml_object_t* sourceBuff = aml_source_buff_read(ctx);
896 if (sourceBuff == NULL)
897 {
898 AML_DEBUG_ERROR(ctx, "Failed to read SourceBuff");
899 return ERR;
900 }
901 DEREF_DEFER(sourceBuff);
902
903 assert(sourceBuff->type == AML_BUFFER);
904
905 uint64_t byteIndex;
906 if (aml_byte_index_read(ctx, &byteIndex) == ERR)
907 {
908 AML_DEBUG_ERROR(ctx, "Failed to read ByteIndex");
909 return ERR;
910 }
911
912 aml_name_string_t nameString;
913 if (aml_name_string_read(ctx, &nameString) == ERR)
914 {
915 AML_DEBUG_ERROR(ctx, "Failed to read NameString");
916 return ERR;
917 }
918
919 aml_object_t* newObject = aml_object_new();
920 if (newObject == NULL)
921 {
922 return ERR;
923 }
924 DEREF_DEFER(newObject);
925
926 if (aml_buffer_field_set(newObject, sourceBuff, byteIndex * 8, fieldWidth) == ERR ||
927 aml_namespace_add_by_name_string(&ctx->state->overlay, ctx->scope, &nameString, newObject) == ERR)
928 {
929 AML_DEBUG_ERROR(ctx, "Failed to add object '%s'", aml_name_string_to_string(&nameString));
930 return ERR;
931 }
932
933 return 0;
934}
935
940
945
950
955
957{
958 if (aml_token_expect(ctx, AML_EVENT_OP) == ERR)
959 {
960 AML_DEBUG_ERROR(ctx, "Failed to read EventOp");
961 return ERR;
962 }
963
964 aml_name_string_t nameString;
965 if (aml_name_string_read(ctx, &nameString) == ERR)
966 {
967 AML_DEBUG_ERROR(ctx, "Failed to read NameString");
968 return ERR;
969 }
970
971 aml_object_t* newObject = aml_object_new();
972 if (newObject == NULL)
973 {
974 return ERR;
975 }
976 DEREF_DEFER(newObject);
977
978 if (aml_event_set(newObject) == ERR ||
979 aml_namespace_add_by_name_string(&ctx->state->overlay, ctx->scope, &nameString, newObject) == ERR)
980 {
981 AML_DEBUG_ERROR(ctx, "Failed to add object '%s'", aml_name_string_to_string(&nameString));
982 return ERR;
983 }
984
985 return 0;
986}
987
989{
991 {
992 AML_DEBUG_ERROR(ctx, "Failed to read ThermalZoneOp");
993 return ERR;
994 }
995
996 const uint8_t* start = ctx->current;
997
998 aml_pkg_length_t pkgLength;
999 if (aml_pkg_length_read(ctx, &pkgLength) == ERR)
1000 {
1001 AML_DEBUG_ERROR(ctx, "Failed to read PkgLength");
1002 return ERR;
1003 }
1004
1005 aml_name_string_t nameString;
1006 if (aml_name_string_read(ctx, &nameString) == ERR)
1007 {
1008 AML_DEBUG_ERROR(ctx, "Failed to read NameString");
1009 return ERR;
1010 }
1011
1012 const uint8_t* end = start + pkgLength;
1013
1014 aml_object_t* thermalZone = aml_object_new();
1015 if (thermalZone == NULL)
1016 {
1017 return ERR;
1018 }
1019 DEREF_DEFER(thermalZone);
1020
1021 if (aml_thermal_zone_set(thermalZone) == ERR ||
1022 aml_namespace_add_by_name_string(&ctx->state->overlay, ctx->scope, &nameString, thermalZone) == ERR)
1023 {
1024 AML_DEBUG_ERROR(ctx, "Failed to add object '%s'", aml_name_string_to_string(&nameString));
1025 return ERR;
1026 }
1027
1028 if (aml_term_list_read(ctx->state, thermalZone, ctx->current, end, ctx) == ERR)
1029 {
1030 AML_DEBUG_ERROR(ctx, "Failed to read ThermalZone body");
1031 return ERR;
1032 }
1033
1034 ctx->current = end;
1035 return 0;
1036}
1037
1039{
1040 if (aml_byte_data_read(ctx, (uint8_t*)out) == ERR)
1041 {
1042 AML_DEBUG_ERROR(ctx, "Failed to read ByteData");
1043 return ERR;
1044 }
1045 return 0;
1046}
1047
1049{
1050 if (aml_word_data_read(ctx, (uint16_t*)out) == ERR)
1051 {
1052 AML_DEBUG_ERROR(ctx, "Failed to read WordData");
1053 return ERR;
1054 }
1055 return 0;
1056}
1057
1059{
1061 {
1062 AML_DEBUG_ERROR(ctx, "Failed to read PowerResOp");
1063 return ERR;
1064 }
1065
1066 const uint8_t* start = ctx->current;
1067
1068 aml_pkg_length_t pkgLength;
1069 if (aml_pkg_length_read(ctx, &pkgLength) == ERR)
1070 {
1071 AML_DEBUG_ERROR(ctx, "Failed to read PkgLength");
1072 return ERR;
1073 }
1074
1075 aml_name_string_t nameString;
1076 if (aml_name_string_read(ctx, &nameString) == ERR)
1077 {
1078 AML_DEBUG_ERROR(ctx, "Failed to read NameString");
1079 return ERR;
1080 }
1081
1082 aml_system_level_t systemLevel;
1083 if (aml_system_level_read(ctx, &systemLevel) == ERR)
1084 {
1085 AML_DEBUG_ERROR(ctx, "Failed to read SystemLevel");
1086 return ERR;
1087 }
1088
1089 aml_resource_order_t resourceOrder;
1090 if (aml_resource_order_read(ctx, &resourceOrder) == ERR)
1091 {
1092 AML_DEBUG_ERROR(ctx, "Failed to read ResourceOrder");
1093 return ERR;
1094 }
1095
1096 const uint8_t* end = start + pkgLength;
1097
1098 aml_object_t* powerResource = aml_object_new();
1099 if (powerResource == NULL)
1100 {
1101 return ERR;
1102 }
1103 DEREF_DEFER(powerResource);
1104
1105 if (aml_power_resource_set(powerResource, systemLevel, resourceOrder) == ERR ||
1106 aml_namespace_add_by_name_string(&ctx->state->overlay, ctx->scope, &nameString, powerResource) == ERR)
1107 {
1108 AML_DEBUG_ERROR(ctx, "Failed to add object '%s'", aml_name_string_to_string(&nameString));
1109 return ERR;
1110 }
1111
1112 if (aml_term_list_read(ctx->state, powerResource, ctx->current, end, ctx) == ERR)
1113 {
1114 AML_DEBUG_ERROR(ctx, "Failed to read PowerResource body");
1115 return ERR;
1116 }
1117
1118 ctx->current = end;
1119 return 0;
1120}
1121
1123{
1124 if (aml_term_arg_read_integer(ctx, out) == ERR)
1125 {
1126 AML_DEBUG_ERROR(ctx, "Failed to read TermArg");
1127 return ERR;
1128 }
1129
1130 return 0;
1131}
1132
1134{
1136 {
1137 AML_DEBUG_ERROR(ctx, "Failed to read CreateFieldOp");
1138 return ERR;
1139 }
1140
1141 aml_object_t* sourceBuff = aml_source_buff_read(ctx);
1142 if (sourceBuff == NULL)
1143 {
1144 AML_DEBUG_ERROR(ctx, "Failed to read SourceBuff");
1145 return ERR;
1146 }
1147 DEREF_DEFER(sourceBuff);
1148
1149 assert(sourceBuff->type == AML_BUFFER);
1150
1151 uint64_t bitIndex;
1152 if (aml_bit_index_read(ctx, &bitIndex) == ERR)
1153 {
1154 AML_DEBUG_ERROR(ctx, "Failed to read BitIndex");
1155 return ERR;
1156 }
1157
1158 uint64_t numBits;
1159 if (aml_num_bits_read(ctx, &numBits) == ERR)
1160 {
1161 AML_DEBUG_ERROR(ctx, "Failed to read NumBits");
1162 return ERR;
1163 }
1164
1165 aml_name_string_t nameString;
1166 if (aml_name_string_read(ctx, &nameString) == ERR)
1167 {
1168 AML_DEBUG_ERROR(ctx, "Failed to read NameString");
1169 return ERR;
1170 }
1171
1172 aml_object_t* newObject = aml_object_new();
1173 if (newObject == NULL)
1174 {
1175 return ERR;
1176 }
1177 DEREF_DEFER(newObject);
1178
1179 if (aml_buffer_field_set(newObject, sourceBuff, bitIndex, numBits) == ERR ||
1180 aml_namespace_add_by_name_string(&ctx->state->overlay, ctx->scope, &nameString, newObject) == ERR)
1181 {
1182 AML_DEBUG_ERROR(ctx, "Failed to add object '%s'", aml_name_string_to_string(&nameString));
1183 return ERR;
1184 }
1185
1186 return 0;
1187}
1188
1190{
1192 {
1193 AML_DEBUG_ERROR(ctx, "Failed to read DataRegionOp");
1194 return ERR;
1195 }
1196
1197 aml_name_string_t regionName;
1198 if (aml_name_string_read(ctx, &regionName) == ERR)
1199 {
1200 AML_DEBUG_ERROR(ctx, "Failed to read RegionName");
1201 return ERR;
1202 }
1203
1205 if (signature == NULL)
1206 {
1207 AML_DEBUG_ERROR(ctx, "Failed to read Signature");
1208 return ERR;
1209 }
1210 DEREF_DEFER(signature);
1211
1213 if (oemId == NULL)
1214 {
1215 AML_DEBUG_ERROR(ctx, "Failed to read OemId");
1216 return ERR;
1217 }
1218 DEREF_DEFER(oemId);
1219
1220 aml_string_obj_t* oemTableId = aml_term_arg_read_string(ctx);
1221 if (oemTableId == NULL)
1222 {
1223 AML_DEBUG_ERROR(ctx, "Failed to read OemTableId");
1224 return ERR;
1225 }
1226 DEREF_DEFER(oemTableId);
1227
1228 if (signature->length != SDT_SIGNATURE_LENGTH)
1229 {
1230 AML_DEBUG_ERROR(ctx, "Invalid signature length %d", signature->length);
1231 errno = EILSEQ;
1232 return ERR;
1233 }
1234
1235 uint64_t index = 0;
1236 sdt_header_t* table = NULL;
1237 while (1)
1238 {
1239 table = acpi_tables_lookup(signature->content, index++);
1240 if (table == NULL)
1241 {
1242 AML_DEBUG_ERROR(ctx, "Failed to find ACPI table with signature '%s', oemId '%s' and oemTableId '%s'",
1243 signature->content, oemId->content, oemTableId->content);
1244 errno = ENOENT;
1245 return ERR;
1246 }
1247
1248 if (oemId->length != 0)
1249 {
1250 if (oemId->length != SDT_OEM_ID_LENGTH)
1251 {
1252 AML_DEBUG_ERROR(ctx, "Invalid oemId length %d", oemId->length);
1253 errno = EILSEQ;
1254 return ERR;
1255 }
1256
1257 if (strncmp((const char*)table->oemId, (const char*)oemId->content, SDT_OEM_ID_LENGTH) != 0)
1258 {
1259 continue;
1260 }
1261 }
1262
1263 if (oemTableId->length != 0)
1264 {
1265 if (oemTableId->length != SDT_OEM_TABLE_ID_LENGTH)
1266 {
1267 AML_DEBUG_ERROR(ctx, "Invalid oemTableId length %d", oemTableId->length);
1268 errno = EILSEQ;
1269 return ERR;
1270 }
1271
1272 if (strncmp((const char*)table->oemTableId, (const char*)oemTableId->content, SDT_OEM_TABLE_ID_LENGTH) != 0)
1273 {
1274 continue;
1275 }
1276 }
1277
1278 aml_object_t* newObject = aml_object_new();
1279 if (newObject == NULL)
1280 {
1281 return ERR;
1282 }
1283 DEREF_DEFER(newObject);
1284
1285 if (aml_operation_region_set(newObject, AML_REGION_SYSTEM_MEMORY, (uint64_t)table, table->length) == ERR ||
1286 aml_namespace_add_by_name_string(&ctx->state->overlay, ctx->scope, &regionName, newObject) == ERR)
1287 {
1288 AML_DEBUG_ERROR(ctx, "Failed to add object '%s'", aml_name_string_to_string(&regionName));
1289 return ERR;
1290 }
1291
1292 return 0;
1293 }
1294}
1295
1297{
1298 aml_token_t op;
1299 aml_token_peek(ctx, &op);
1300
1301 uint64_t result = 0;
1302 switch (op.num)
1303 {
1304 case AML_OPREGION_OP:
1305 result = aml_def_opregion_read(ctx);
1306 break;
1307 case AML_FIELD_OP:
1308 result = aml_def_field_read(ctx);
1309 break;
1310 case AML_METHOD_OP:
1311 result = aml_def_method_read(ctx);
1312 break;
1313 case AML_DEVICE_OP:
1314 result = aml_def_device_read(ctx);
1315 break;
1316 case AML_MUTEX_OP:
1317 result = aml_def_mutex_read(ctx);
1318 break;
1319 case AML_INDEX_FIELD_OP:
1320 result = aml_def_index_field_read(ctx);
1321 break;
1322 case AML_BANK_FIELD_OP:
1323 result = aml_def_bank_field_read(ctx);
1324 break;
1326 result = aml_def_processor_read(ctx);
1327 break;
1329 result = aml_def_create_bit_field_read(ctx);
1330 break;
1332 result = aml_def_create_byte_field_read(ctx);
1333 break;
1335 result = aml_def_create_word_field_read(ctx);
1336 break;
1338 result = aml_def_create_dword_field_read(ctx);
1339 break;
1341 result = aml_def_create_qword_field_read(ctx);
1342 break;
1343 case AML_EVENT_OP:
1344 result = aml_def_event_read(ctx);
1345 break;
1347 result = aml_def_thermal_zone_read(ctx);
1348 break;
1349 case AML_POWER_RES_OP:
1350 result = aml_def_power_res_read(ctx);
1351 break;
1353 result = aml_def_create_field_read(ctx);
1354 break;
1355 case AML_DATA_REGION_OP:
1356 result = aml_def_data_region_read(ctx);
1357 break;
1358 default:
1359 AML_DEBUG_ERROR(ctx, "Unknown NamedObj '%s' (0x%x)", op.props->name, op.num);
1360 errno = ENOSYS;
1361 return ERR;
1362 }
1363
1364 if (result == ERR)
1365 {
1366 AML_DEBUG_ERROR(ctx, "Failed to read NamedObj '%s' (0x%x)", op.props->name, op.num);
1367 return ERR;
1368 }
1369
1370 return 0;
1371}
1372
#define assert(expression)
Definition assert.h:29
static fd_t data
Definition dwm.c:21
#define AML_DEBUG_ERROR(ctx, format,...)
Macro to simplify calling aml_debug_error() with the current function name.
Definition debug.h:30
uint64_t aml_byte_data_read(aml_term_list_ctx_t *ctx, uint8_t *out)
Read a ByteData structure from the AML stream.
Definition data.c:16
uint64_t aml_dword_data_read(aml_term_list_ctx_t *ctx, uint32_t *out)
Read a DWordData structure from the AML stream.
Definition data.c:42
uint64_t aml_word_data_read(aml_term_list_ctx_t *ctx, uint16_t *out)
Read a WordData structure from the AML stream.
Definition data.c:30
uint64_t aml_def_create_field_read(aml_term_list_ctx_t *ctx)
Reads a DefCreateField structure from the AML byte stream.
Definition named.c:1133
uint64_t aml_def_opregion_read(aml_term_list_ctx_t *ctx)
Reads a DefOpRegion structure from the AML byte stream.
Definition named.c:68
uint8_t aml_proc_id_t
ProcID structure, deprecated in version 6.4 of the ACPI specification.
Definition named.h:151
uint64_t aml_def_device_read(aml_term_list_ctx_t *ctx)
Reads a DefDevice structure from the AML byte stream.
Definition named.c:593
uint64_t aml_field_flags_read(aml_term_list_ctx_t *ctx, aml_field_flags_t *out)
Reads a FieldFlags structure from the AML byte stream.
Definition named.c:122
uint64_t aml_name_string_read(aml_term_list_ctx_t *ctx, aml_name_string_t *out)
Reads the next data as a NameString structure from the AML bytecode stream.
Definition name.c:189
uint64_t aml_reserved_field_read(aml_term_list_ctx_t *ctx, aml_field_list_ctx_t *fieldCtx)
Reads a ReservedField structure from the AML byte stream.
Definition named.c:258
uint32_t aml_pblk_addr_t
PblkAddr structure, deprecated in version 6.4 of the ACPI specification.
Definition named.h:156
uint64_t aml_def_index_field_read(aml_term_list_ctx_t *ctx)
Reads a DefIndexField structure from the AML byte stream.
Definition named.c:380
aml_object_t * aml_name_string_read_and_resolve(aml_term_list_ctx_t *ctx)
Reads the next data as a NameString structure from the AML bytecode stream and resolves it to a objec...
Definition name.c:227
uint64_t aml_def_field_read(aml_term_list_ctx_t *ctx)
Reads a DefField structure from the AML byte stream.
Definition named.c:323
uint64_t aml_byte_index_read(aml_term_list_ctx_t *ctx, aml_integer_t *out)
Reads a ByteIndex structure from the AML byte stream.
Definition named.c:826
aml_access_type_t
Enum for all field access types, bits 0-3 of FieldFlags.
Definition named.h:51
uint64_t aml_def_create_byte_field_read(aml_term_list_ctx_t *ctx)
Reads a DefCreateByteField structure from the AML byte stream.
Definition named.c:936
uint64_t aml_def_bank_field_read(aml_term_list_ctx_t *ctx)
Reads a DefBankField structure from the AML byte stream.
Definition named.c:451
uint64_t aml_field_element_read(aml_term_list_ctx_t *ctx, aml_field_list_ctx_t *fieldCtx)
Reads a FieldElement structure from the AML byte stream.
Definition named.c:277
uint64_t aml_sync_flags_read(aml_term_list_ctx_t *ctx, aml_sync_level_t *out)
Reads a SyncFlags structure from the AML byte stream.
Definition named.c:643
uint64_t aml_def_thermal_zone_read(aml_term_list_ctx_t *ctx)
Reads a DefThermalZone structure from the AML byte stream.
Definition named.c:988
uint64_t aml_region_space_read(aml_term_list_ctx_t *ctx, aml_region_space_t *out)
Reads a RegionSpace structure from the AML byte stream.
Definition named.c:26
uint64_t aml_num_bits_read(aml_term_list_ctx_t *ctx, aml_integer_t *out)
Reads a NumBits structure from the AML byte stream.
Definition named.c:1122
uint64_t aml_def_create_dword_field_read(aml_term_list_ctx_t *ctx)
Reads a DefCreateDWordField structure from the AML byte stream.
Definition named.c:946
uint64_t aml_name_seg_read(aml_term_list_ctx_t *ctx, aml_name_seg_t **out)
Reads the next data as a NameSeg from the AML bytecode stream.
Definition name.c:27
uint64_t aml_def_data_region_read(aml_term_list_ctx_t *ctx)
Reads a DefDataRegion structure from the AML byte stream.
Definition named.c:1189
#define AML_IS_LEAD_NAME_CHAR(token)
Check if a token is a LeadNameChar structure.
Definition name.h:28
uint64_t aml_def_create_word_field_read(aml_term_list_ctx_t *ctx)
Reads a DefCreateWordField structure from the AML byte stream.
Definition named.c:941
uint64_t aml_def_create_qword_field_read(aml_term_list_ctx_t *ctx)
Reads a DefCreateQWordField structure from the AML byte stream.
Definition named.c:951
uint64_t aml_name_field_read(aml_term_list_ctx_t *ctx, aml_field_list_ctx_t *fieldCtx)
Reads a NamedField structure from the AML byte stream.
Definition named.c:155
uint64_t aml_system_level_read(aml_term_list_ctx_t *ctx, aml_system_level_t *out)
Reads a SystemLevel structure from the AML byte stream.
Definition named.c:1038
uint64_t aml_def_create_bit_field_read(aml_term_list_ctx_t *ctx)
Reads a DefCreateBitField structure from the AML byte stream.
Definition named.c:837
uint8_t aml_system_level_t
SystemLevel structure.
Definition named.h:166
uint64_t aml_def_method_read(aml_term_list_ctx_t *ctx)
Reads a DefMethod structure from the AML byte stream.
Definition named.c:540
uint64_t aml_def_event_read(aml_term_list_ctx_t *ctx)
Reads a DefEvent structure from the AML byte stream.
Definition named.c:956
uint64_t aml_named_obj_read(aml_term_list_ctx_t *ctx)
Reads a NamedObj structure from the AML byte stream.
Definition named.c:1296
uint8_t aml_pblk_len_t
PblkLen structure, deprecated in version 6.4 of the ACPI specification.
Definition named.h:161
uint64_t aml_def_mutex_read(aml_term_list_ctx_t *ctx)
Reads a DefMutex structure from the AML byte stream.
Definition named.c:663
uint8_t aml_sync_level_t
Definition named.h:135
uint64_t aml_proc_id_read(aml_term_list_ctx_t *ctx, aml_proc_id_t *out)
Reads a ProcID structure from the AML byte stream. Deprecated in ACPI 6.4 but still supported.
Definition named.c:702
uint64_t aml_bit_index_read(aml_term_list_ctx_t *ctx, aml_integer_t *out)
Reads a BitIndex structure from the AML byte stream.
Definition named.c:815
uint64_t aml_def_processor_read(aml_term_list_ctx_t *ctx)
Reads a DefProcessor structure from the AML byte stream. Deprecated in ACPI 6.4 but still supported.
Definition named.c:732
aml_object_t * aml_source_buff_read(aml_term_list_ctx_t *ctx)
Reads a SourceBuff structure from the AML byte stream.
Definition named.c:803
uint64_t aml_pblk_len_read(aml_term_list_ctx_t *ctx, aml_pblk_len_t *out)
Reads a PblkLen structure from the AML byte stream. Deprecated in ACPI 6.4 but still supported.
Definition named.c:722
uint64_t aml_bank_value_read(aml_term_list_ctx_t *ctx, aml_integer_t *out)
Reads a BankValue structure from the AML byte stream.
Definition named.c:15
aml_region_space_t
Region Space Encoding.
Definition named.h:30
uint64_t aml_resource_order_read(aml_term_list_ctx_t *ctx, aml_resource_order_t *out)
Reads a ResourceOrder structure from the AML byte stream.
Definition named.c:1048
uint64_t aml_method_flags_read(aml_term_list_ctx_t *ctx, aml_method_flags_t *out)
Reads a MethodFlags structure from the AML byte stream.
Definition named.c:518
uint16_t aml_resource_order_t
ResourceOrder structure.
Definition named.h:171
uint64_t aml_def_power_res_read(aml_term_list_ctx_t *ctx)
Reads a DefPowerRes structure from the AML byte stream.
Definition named.c:1058
uint64_t aml_region_offset_read(aml_term_list_ctx_t *ctx, aml_integer_t *out)
Reads a RegionOffset structure from the AML byte stream.
Definition named.c:46
uint64_t aml_region_len_read(aml_term_list_ctx_t *ctx, aml_integer_t *out)
Reads a RegionLen structure from the AML byte stream.
Definition named.c:57
uint64_t aml_field_list_read(aml_term_list_ctx_t *ctx, aml_field_list_ctx_t *fieldCtx, const uint8_t *end)
Reads a FieldList structure from the AML byte stream.
Definition named.c:308
uint64_t aml_pblk_addr_read(aml_term_list_ctx_t *ctx, aml_pblk_addr_t *out)
Reads a PblkAddr structure from the AML byte stream. Deprecated in ACPI 6.4 but still supported.
Definition named.c:712
@ AML_ACCESS_TYPE_BUFFER
Definition named.h:57
@ AML_FIELD_LIST_TYPE_FIELD
FieldList is part of a DefField.
Definition named.h:98
@ AML_FIELD_LIST_TYPE_BANK_FIELD
FieldList is part of a BankField.
Definition named.h:100
@ AML_FIELD_LIST_TYPE_INDEX_FIELD
FieldList is part of an IndexField.
Definition named.h:99
@ AML_REGION_PCC
Definition named.h:41
@ AML_REGION_OEM_MIN
Definition named.h:42
@ AML_REGION_SYSTEM_MEMORY
Definition named.h:31
uint32_t aml_pkg_length_t
PkgLength structure.
uint64_t aml_pkg_length_read(aml_term_list_ctx_t *ctx, aml_pkg_length_t *out)
Reads a PkgLength structure from the AML byte stream.
aml_object_t * aml_term_arg_read(aml_term_list_ctx_t *ctx, aml_type_t allowedTypes)
Reads an TermArg structure from the AML byte stream.
Definition term.c:20
uint64_t aml_term_arg_read_integer(aml_term_list_ctx_t *ctx, aml_integer_t *out)
Wrapper around aml_term_arg_read() that converts the result to an integer.
Definition term.c:89
uint64_t aml_term_list_read(aml_state_t *state, aml_object_t *scope, const uint8_t *start, const uint8_t *end, aml_term_list_ctx_t *parentCtx)
Reads a TermList structure from the AML byte stream.
Definition term.c:216
aml_string_obj_t * aml_term_arg_read_string(aml_term_list_ctx_t *ctx)
Wrapper around aml_term_arg_read() that converts the result to a string.
Definition term.c:105
uint64_t aml_integer_t
AML Integer type.
Definition integer.h:20
#define AML_NAME_TO_STRING(name)
Macro to convert an aml_name_t to a stack allocated string.
Definition namespace.h:129
uint64_t aml_namespace_add_child(aml_namespace_overlay_t *overlay, aml_object_t *parent, aml_name_t name, aml_object_t *object)
Add an child to a parent in the namespace heirarchy.
Definition namespace.c:332
uint64_t aml_namespace_add_by_name_string(aml_namespace_overlay_t *overlay, aml_object_t *start, const aml_name_string_t *nameString, aml_object_t *object)
Add an object to the namespace heirarchy using a name string.
Definition namespace.c:381
uint64_t aml_field_unit_field_set(aml_object_t *object, aml_opregion_obj_t *opregion, aml_field_flags_t flags, aml_bit_size_t bitOffset, aml_bit_size_t bitSize)
Set a object as a field unit of type Field.
Definition object.c:615
uint64_t aml_method_set(aml_object_t *object, aml_method_flags_t flags, const uint8_t *start, const uint8_t *end, aml_method_implementation_t implementation)
Set a object as a method with the given flags and address range.
Definition object.c:732
uint64_t aml_event_set(aml_object_t *object)
Set a object as an event.
Definition object.c:598
uint64_t aml_device_set(aml_object_t *object)
Set a object as a device or bus.
Definition object.c:581
uint64_t aml_mutex_set(aml_object_t *object, aml_sync_level_t syncLevel)
Set a object as a mutex with the given synchronization level.
Definition object.c:812
uint64_t aml_power_resource_set(aml_object_t *object, aml_system_level_t systemLevel, aml_resource_order_t resourceOrder)
Set a object as a power resource with the given system level and resource order.
Definition object.c:915
uint64_t aml_thermal_zone_set(aml_object_t *object)
Set a object as a thermal zone.
Definition object.c:1079
aml_object_t * aml_object_new(void)
Allocate a new ACPI object.
Definition object.c:54
uint64_t aml_field_unit_index_field_set(aml_object_t *object, aml_field_unit_obj_t *index, aml_field_unit_obj_t *data, aml_field_flags_t flags, aml_bit_size_t bitOffset, aml_bit_size_t bitSize)
Set a object as a field unit of type IndexField.
Definition object.c:642
uint64_t aml_buffer_field_set(aml_object_t *object, aml_object_t *target, aml_bit_size_t bitOffset, aml_bit_size_t bitSize)
Set a object as a buffer field with the given buffer, bit offset and bit size.
Definition object.c:537
uint64_t aml_processor_set(aml_object_t *object, aml_proc_id_t procId, aml_pblk_addr_t pblkAddr, aml_pblk_len_t pblkLen)
Set a object as a processor with the given ProcID, PblkAddr, and PblkLen.
Definition object.c:935
uint64_t aml_operation_region_set(aml_object_t *object, aml_region_space_t space, uintptr_t offset, uint32_t length)
Set a object as an operation region with the given space, offset, and length.
Definition object.c:849
uint64_t aml_field_unit_bank_field_set(aml_object_t *object, aml_opregion_obj_t *opregion, aml_field_unit_obj_t *bank, uint64_t bankValue, aml_field_flags_t flags, aml_bit_size_t bitOffset, aml_bit_size_t bitSize)
Set a object as a field unit of type BankField.
Definition object.c:669
@ AML_OPERATION_REGION
Definition object.h:78
@ AML_FIELD_UNIT
Definition object.h:64
@ AML_BUFFER
Definition object.h:59
const char * aml_name_string_to_string(const aml_name_string_t *nameString)
Convert an aml NameString to a string.
Definition to_string.c:254
aml_token_num_t
Token numbers.
Definition token.h:35
static uint64_t aml_token_expect(aml_term_list_ctx_t *ctx, aml_token_num_t expected)
Reads a token from the AML stream and verifies it matches the expected token.
Definition token.h:353
static void aml_token_peek(aml_term_list_ctx_t *ctx, aml_token_t *out)
Attempt to read a token from the AML stream, without advancing the instruction pointer.
Definition token.h:301
@ AML_DEVICE_OP
Definition token.h:189
@ AML_CREATE_BIT_FIELD_OP
Definition token.h:139
@ AML_EVENT_OP
Definition token.h:168
@ AML_DATA_REGION_OP
Definition token.h:195
@ AML_OPREGION_OP
Definition token.h:187
@ AML_CREATE_QWORD_FIELD_OP
Definition token.h:141
@ AML_FIELD_OP
Definition token.h:188
@ AML_DEPRECATED_PROCESSOR_OP
Definition token.h:190
@ AML_METHOD_OP
Definition token.h:51
@ AML_THERMAL_ZONE_OP
Definition token.h:192
@ AML_MUTEX_OP
Definition token.h:167
@ AML_POWER_RES_OP
Definition token.h:191
@ AML_INDEX_FIELD_OP
Definition token.h:193
@ AML_CREATE_BYTE_FIELD_OP
Definition token.h:138
@ AML_BANK_FIELD_OP
Definition token.h:194
@ AML_CREATE_WORD_FIELD_OP
Definition token.h:137
@ AML_CREATE_FIELD_OP
Definition token.h:170
@ AML_CREATE_DWORD_FIELD_OP
Definition token.h:136
sdt_header_t * acpi_tables_lookup(const char *signature, uint64_t n)
Lookup the n'th table matching the signature.
Definition tables.c:281
#define SDT_OEM_ID_LENGTH
The length of the OEM ID field in the SDT header structure.
Definition acpi.h:76
#define SDT_OEM_TABLE_ID_LENGTH
The length of the OEM Table ID field in the SDT header structure.
Definition acpi.h:81
#define SDT_SIGNATURE_LENGTH
The length of the signature field in the SDT header structure.
Definition acpi.h:71
#define DEREF_DEFER(ptr)
RAII-style cleanup for scoped references.
Definition ref.h:54
#define ENOENT
No such file or directory.
Definition errno.h:42
#define ENOSYS
Function not implemented.
Definition errno.h:222
#define errno
Error number variable.
Definition errno.h:27
#define EILSEQ
Illegal byte sequence.
Definition errno.h:447
#define NULL
Pointer error value.
Definition NULL.h:23
#define ERR
Integer error value.
Definition ERR.h:17
static uint64_t aml_def_create_field_read_helper(aml_term_list_ctx_t *ctx, uint8_t fieldWidth, aml_token_num_t expectedOp)
Definition named.c:886
static void start()
Definition main.c:542
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
__UINT8_TYPE__ uint8_t
Definition stdint.h:11
__UINT16_TYPE__ uint16_t
Definition stdint.h:13
_PUBLIC int strncmp(const char *s1, const char *s2, size_t n)
Definition strncmp.c:3
FieldFlags structure.
Definition named.h:86
aml_access_type_t accessType
Definition named.h:87
Context passed to lower functions by aml_field_list_read().
Definition named.h:108
aml_field_unit_obj_t * bank
Definition named.h:125
struct aml_field_list_ctx_t::@0::@2 field
aml_field_flags_t flags
The flags of the FieldList.
Definition named.h:110
aml_bit_size_t currentOffset
The current offset within the opregion.
Definition named.h:111
aml_opregion_obj_t * opregion
Definition named.h:115
aml_field_unit_obj_t * index
Definition named.h:119
aml_field_list_type_t type
The type of FieldList.
Definition named.h:109
aml_field_unit_obj_t * bank
Used for BankField.
Definition object.h:252
aml_field_unit_obj_t * index
Used for IndexField.
Definition object.h:249
aml_field_unit_obj_t * data
Used for IndexField.
Definition object.h:250
aml_opregion_obj_t * opregion
Used for Field and BankField.
Definition object.h:253
aml_object_t * bankValue
Used for BankField.
Definition object.h:251
MethodFlags structure.
Definition named.h:142
uint8_t argCount
Amount of arguments (0-7)
Definition named.h:143
A NameSeg strcture.
A NameString structure.
Definition name.h:87
ACPI object.
Definition object.h:425
aml_opregion_obj_t opregion
Definition object.h:440
aml_field_unit_obj_t fieldUnit
Definition object.h:434
aml_namespace_overlay_t overlay
Holds any named objects created during parsing.
Definition state.h:30
Data for a string object.
Definition object.h:368
char * content
Definition object.h:370
uint64_t length
Definition object.h:371
Context for reading a TermList.
Definition term.h:37
aml_object_t * scope
Definition term.h:39
aml_state_t * state
Definition term.h:38
const uint8_t * current
Definition term.h:42
const char * name
Definition token.h:243
Token.
Definition token.h:253
const aml_token_props_t * props
Definition token.h:256
aml_token_num_t num
Definition token.h:254
System Description Table Header.
Definition acpi.h:90
uint8_t oemTableId[SDT_OEM_TABLE_ID_LENGTH]
Definition acpi.h:96
uint32_t length
Definition acpi.h:92
uint8_t oemId[SDT_OEM_ID_LENGTH]
Definition acpi.h:95