| 1 | #pragma once |
| 2 | |
| 3 | #include <uacpi/types.h> |
| 4 | #include <uacpi/internal/shareable.h> |
| 5 | #include <uacpi/status.h> |
| 6 | #include <uacpi/namespace.h> |
| 7 | |
| 8 | #ifndef UACPI_BAREBONES_MODE |
| 9 | |
| 10 | #define UACPI_NAMESPACE_NODE_FLAG_ALIAS (1 << 0) |
| 11 | |
| 12 | /* |
| 13 | * This node has been uninstalled and has no object associated with it. |
| 14 | * |
| 15 | * This is used to handle edge cases where an object needs to reference |
| 16 | * a namespace node, where the node might end up going out of scope before |
| 17 | * the object lifetime ends. |
| 18 | */ |
| 19 | #define UACPI_NAMESPACE_NODE_FLAG_DANGLING (1u << 1) |
| 20 | |
| 21 | /* |
| 22 | * This node is method-local and must not be exposed via public API as its |
| 23 | * lifetime is limited. |
| 24 | */ |
| 25 | #define UACPI_NAMESPACE_NODE_FLAG_TEMPORARY (1u << 2) |
| 26 | |
| 27 | #define UACPI_NAMESPACE_NODE_PREDEFINED (1u << 31) |
| 28 | |
| 29 | typedef struct uacpi_namespace_node { |
| 30 | struct uacpi_shareable shareable; |
| 31 | uacpi_object_name name; |
| 32 | uacpi_u32 flags; |
| 33 | uacpi_object *object; |
| 34 | struct uacpi_namespace_node *parent; |
| 35 | struct uacpi_namespace_node *child; |
| 36 | struct uacpi_namespace_node *next; |
| 37 | } uacpi_namespace_node; |
| 38 | |
| 39 | uacpi_status uacpi_initialize_namespace(void); |
| 40 | void uacpi_deinitialize_namespace(void); |
| 41 | |
| 42 | uacpi_namespace_node *uacpi_namespace_node_alloc(uacpi_object_name name); |
| 43 | void uacpi_namespace_node_unref(uacpi_namespace_node *node); |
| 44 | |
| 45 | |
| 46 | uacpi_status uacpi_namespace_node_type_unlocked( |
| 47 | const uacpi_namespace_node *node, uacpi_object_type *out_type |
| 48 | ); |
| 49 | uacpi_status uacpi_namespace_node_is_one_of_unlocked( |
| 50 | const uacpi_namespace_node *node, uacpi_object_type_bits type_mask, |
| 51 | uacpi_bool *out |
| 52 | ); |
| 53 | |
| 54 | uacpi_object *uacpi_namespace_node_get_object(const uacpi_namespace_node *node); |
| 55 | |
| 56 | uacpi_object *uacpi_namespace_node_get_object_typed( |
| 57 | const uacpi_namespace_node *node, uacpi_object_type_bits type_mask |
| 58 | ); |
| 59 | |
| 60 | uacpi_status uacpi_namespace_node_acquire_object( |
| 61 | const uacpi_namespace_node *node, uacpi_object **out_obj |
| 62 | ); |
| 63 | uacpi_status uacpi_namespace_node_acquire_object_typed( |
| 64 | const uacpi_namespace_node *node, uacpi_object_type_bits, |
| 65 | uacpi_object **out_obj |
| 66 | ); |
| 67 | |
| 68 | uacpi_status uacpi_namespace_node_reacquire_object( |
| 69 | uacpi_object *obj |
| 70 | ); |
| 71 | uacpi_status uacpi_namespace_node_release_object( |
| 72 | uacpi_object *obj |
| 73 | ); |
| 74 | |
| 75 | uacpi_status uacpi_namespace_node_install( |
| 76 | uacpi_namespace_node *parent, uacpi_namespace_node *node |
| 77 | ); |
| 78 | uacpi_status uacpi_namespace_node_uninstall(uacpi_namespace_node *node); |
| 79 | |
| 80 | uacpi_namespace_node *uacpi_namespace_node_find_sub_node( |
| 81 | uacpi_namespace_node *parent, |
| 82 | uacpi_object_name name |
| 83 | ); |
| 84 | |
| 85 | enum uacpi_may_search_above_parent { |
| 86 | UACPI_MAY_SEARCH_ABOVE_PARENT_NO, |
| 87 | UACPI_MAY_SEARCH_ABOVE_PARENT_YES, |
| 88 | }; |
| 89 | |
| 90 | enum uacpi_permanent_only { |
| 91 | UACPI_PERMANENT_ONLY_NO, |
| 92 | UACPI_PERMANENT_ONLY_YES, |
| 93 | }; |
| 94 | |
| 95 | enum uacpi_should_lock { |
| 96 | UACPI_SHOULD_LOCK_NO, |
| 97 | UACPI_SHOULD_LOCK_YES, |
| 98 | }; |
| 99 | |
| 100 | uacpi_status uacpi_namespace_node_resolve( |
| 101 | uacpi_namespace_node *scope, const uacpi_char *path, enum uacpi_should_lock, |
| 102 | enum uacpi_may_search_above_parent, enum uacpi_permanent_only, |
| 103 | uacpi_namespace_node **out_node |
| 104 | ); |
| 105 | |
| 106 | uacpi_status uacpi_namespace_do_for_each_child( |
| 107 | uacpi_namespace_node *parent, uacpi_iteration_callback descending_callback, |
| 108 | uacpi_iteration_callback ascending_callback, |
| 109 | uacpi_object_type_bits, uacpi_u32 max_depth, enum uacpi_should_lock, |
| 110 | enum uacpi_permanent_only, void *user |
| 111 | ); |
| 112 | |
| 113 | uacpi_bool uacpi_namespace_node_is_dangling(uacpi_namespace_node *node); |
| 114 | uacpi_bool uacpi_namespace_node_is_temporary(uacpi_namespace_node *node); |
| 115 | uacpi_bool uacpi_namespace_node_is_predefined(uacpi_namespace_node *node); |
| 116 | |
| 117 | uacpi_status uacpi_namespace_read_lock(void); |
| 118 | uacpi_status uacpi_namespace_read_unlock(void); |
| 119 | |
| 120 | uacpi_status uacpi_namespace_write_lock(void); |
| 121 | uacpi_status uacpi_namespace_write_unlock(void); |
| 122 | |
| 123 | #endif // !UACPI_BAREBONES_MODE |
| 124 | |