PatchworkOS
Loading...
Searching...
No Matches
patch_up.c
Go to the documentation of this file.
2
6#include <kernel/log/log.h>
7#include <kernel/log/panic.h>
8
9#include <errno.h>
10#include <stdlib.h>
11#include <sys/list.h>
12
14
16{
18 return 0;
19}
20
22{
23 if (unresolved == NULL)
24 {
25 errno = EINVAL;
26 return ERR;
27 }
28
30 if (entry == NULL)
31 {
32 return ERR;
33 }
34
35 list_entry_init(&entry->entry);
36 entry->unresolved = unresolved;
38 return 0;
39}
40
42{
43 if (unresolved == NULL)
44 {
45 return;
46 }
47
49 LIST_FOR_EACH(entry, &unresolvedObjects, entry)
50 {
51 if (entry->unresolved == unresolved)
52 {
54 free(entry);
55 return;
56 }
57 }
58}
59
61{
62 aml_state_t state;
63 if (aml_state_init(&state, NULL) == ERR)
64 {
65 LOG_PANIC("Failed to init AML state\n");
66 return ERR;
67 }
68
71 LIST_FOR_EACH_SAFE(entry, temp, &unresolvedObjects, entry)
72 {
73 aml_object_t* match =
75 if (match == NULL)
76 {
77 LOG_DEBUG("Still could not resolve '%s'\n", aml_name_string_to_string(&entry->unresolved->nameString));
78 errno = EOK;
79 continue;
80 }
81
82 aml_unresolved_obj_t* unresolved = entry->unresolved;
83 aml_object_t* obj = CONTAINER_OF(unresolved, aml_object_t, unresolved);
84 if (unresolved->callback(&state, match, obj) == ERR)
85 {
86 aml_state_deinit(&state);
87 LOG_ERR("Failed to patch up unresolved object\n");
88 return ERR;
89 }
90
91 // When a unresolved object changes type it will call aml_patch_up_remove_unresolved itself.
92 if (obj->type == AML_UNRESOLVED)
93 {
94 aml_state_deinit(&state);
95 LOG_ERR("Unresolved object did not change type\n");
96 errno = EILSEQ;
97 return ERR;
98 }
99 }
100
101 aml_state_deinit(&state);
102 return 0;
103}
104
aml_object_t * aml_namespace_find_by_name_string(aml_namespace_overlay_t *overlay, aml_object_t *start, const aml_name_string_t *nameString)
Find an object in the namespace heirarchy by a name string.
Definition namespace.c:174
@ AML_UNRESOLVED
Not in the spec, used internally to represent unresolved references.
Definition object.h:86
uint64_t aml_patch_up_init(void)
Initialize the patch-up system.
Definition patch_up.c:15
uint64_t aml_patch_up_unresolved_count(void)
Get the number of unresolved references in the global list.
Definition patch_up.c:105
void aml_patch_up_remove_unresolved(aml_unresolved_obj_t *unresolved)
Removes an unresolved reference from the global list.
Definition patch_up.c:41
uint64_t aml_patch_up_resolve_all(void)
Attempts to resolve all unresolved references.
Definition patch_up.c:60
uint64_t aml_patch_up_add_unresolved(aml_unresolved_obj_t *unresolved)
Adds a unresolved reference to the global list.
Definition patch_up.c:21
uint64_t aml_state_init(aml_state_t *state, aml_object_t **args)
Initialize an AML state.
Definition state.c:8
void aml_state_deinit(aml_state_t *state)
Deinitialize an AML state.
Definition state.c:79
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
#define LOG_ERR(format,...)
Definition log.h:89
#define LOG_DEBUG(format,...)
Definition log.h:81
#define LOG_PANIC(format,...)
Definition log.h:90
#define EINVAL
Invalid argument.
Definition errno.h:142
#define errno
Error number variable.
Definition errno.h:27
#define EILSEQ
Illegal byte sequence.
Definition errno.h:447
#define EOK
No error.
Definition errno.h:32
#define LIST_FOR_EACH(elem, list, member)
Iterates over a list.
Definition list.h:65
static uint64_t list_length(list_t *list)
Gets the length of the list.
Definition list.h:248
#define LIST_FOR_EACH_SAFE(elem, temp, list, member)
Safely iterates over a list, allowing for element removal during iteration.
Definition list.h:81
static void list_remove(list_t *list, list_entry_t *entry)
Removes a list entry from its current list.
Definition list.h:317
static void list_push(list_t *list, list_entry_t *entry)
Pushes an entry to the end of the list.
Definition list.h:345
static void list_entry_init(list_entry_t *entry)
Initializes a list entry.
Definition list.h:184
static void list_init(list_t *list)
Initializes a list.
Definition list.h:198
#define NULL
Pointer error value.
Definition NULL.h:23
#define ERR
Integer error value.
Definition ERR.h:17
#define CONTAINER_OF(ptr, type, member)
Container of macro.
static list_t unresolvedObjects
Definition patch_up.c:13
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
_PUBLIC void * malloc(size_t size)
Definition malloc.c:5
_PUBLIC void free(void *ptr)
Definition free.c:11
ACPI object.
Definition object.h:425
Entry in the global list of unresolved references.
Definition patch_up.h:32
aml_unresolved_obj_t * unresolved
The unresolved object.
Definition patch_up.h:34
list_entry_t entry
List entry for the global list of unresolved references.
Definition patch_up.h:33
AML State.
Definition state.h:25
aml_namespace_overlay_t overlay
Holds any named objects created during parsing.
Definition state.h:30
Data for an unresolved object.
Definition object.h:390
aml_name_string_t nameString
The NameString representing the path to the target object.
Definition object.h:392
aml_object_t * from
The object to start the search from when resolving the reference.
Definition object.h:393
aml_patch_up_resolve_callback_t callback
The callback to call when a matching object is found.
Definition object.h:394
A doubly linked list.
Definition list.h:51