28 buffer.parentId = parentId;
37 if (current ==
NULL || current->parent ==
NULL)
56 while (current->parent !=
NULL)
78 root->name =
AML_NAME(
'\\',
'_',
'_',
'_');
84 if (
object ==
NULL || parentDir ==
NULL)
98 if (object->dir ==
NULL)
130 LOG_ERR(
"Failed to create ACPI namespace sysfs directory");
141 LOG_ERR(
"Failed to expose ACPI namespace in sysfs");
168 while (overlay !=
NULL)
176 overlay = overlay->
parent;
218 for (
uint64_t i = 0; i < nameCount; i++)
240 if (nameString ==
NULL)
290 if (path ==
NULL || path[0] ==
'\0')
297 const char* p = path;
303 else if (p[0] ==
'^')
339 const char* segmentStart = p;
340 while (*p !=
'.' && *p !=
'\0')
345 uint64_t segmentLength = p - segmentStart;
353 for (
uint64_t i = 0; i < segmentLength; i++)
366 if (
next ==
NULL && segmentCount == 1 && *p ==
'\0')
368 while (current->parent !=
NULL)
423 while (currentOverlay !=
NULL)
430 currentOverlay = currentOverlay->
parent;
441 object->overlay = overlay;
494 map_remove(&object->overlay->map, &object->mapEntry);
495 list_remove(&object->overlay->objects, &object->listEntry);
496 list_remove(&object->parent->children, &object->siblingsEntry);
498 object->overlay =
NULL;
499 object->parent =
NULL;
500 object->flags &= ~AML_OBJECT_NAMED;
530 object->overlay = overlay->
parent;
579 if (overlay ==
NULL ||
object ==
NULL)
588 while (currentOverlay !=
NULL)
592 return currentOverlay;
595 currentOverlay = currentOverlay->
parent;
#define assert(expression)
#define PACKED
GCC packed attribute.
#define LOG_ERR(format,...)
static map_key_t map_key_buffer(const void *buffer, uint64_t length)
Create a map key from a buffer.
void map_init(map_t *map)
Initialize a map.
void map_deinit(map_t *map)
Deinitialize a map.
uint64_t map_insert(map_t *map, const map_key_t *key, map_entry_t *value)
Insert a key-value pair into the map.
void map_remove(map_t *map, map_entry_t *entry)
Remove a entry from the map.
bool map_is_empty(const map_t *map)
Check if the map is empty.
map_entry_t * map_get(map_t *map, const map_key_t *key)
Get a value from the map by key.
#define DEREF_DEFER(ptr)
RAII-style cleanup for scoped references.
#define REF(ptr)
Increment reference count.
#define DEREF(ptr)
Decrement reference count.
#define ENOENT
No such file or directory.
#define EEXIST
File exists.
#define EINVAL
Invalid argument.
#define errno
Error number variable.
#define LIST_FOR_EACH(elem, list, member)
Iterates over a list.
static list_entry_t * list_pop_first(list_t *list)
Pops the first entry from the list.
static void list_push_back(list_t *list, list_entry_t *entry)
Pushes an entry to the end of the list.
#define LIST_FOR_EACH_SAFE(elem, temp, list, member)
Safely iterates over a list, allowing for element removal during iteration.
static void list_remove(list_t *list, list_entry_t *entry)
Removes a list entry from its current list.
static bool list_is_empty(list_t *list)
Checks if a list is empty.
static void list_init(list_t *list)
Initializes a list.
#define NULL
Pointer error value.
#define ERR
Integer error value.
#define CONTAINER_OF(ptr, type, member)
Container of macro.
#define CONTAINER_OF_SAFE(ptr, type, member)
Safe container of macro.
#define AML_NAME_TO_STRING(name)
Macro to convert an aml_name_t to a stack allocated string.
uint64_t aml_namespace_add_child(aml_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.
aml_object_t * aml_namespace_find_by_path(aml_overlay_t *overlay, aml_object_t *start, const char *path)
Find an object in the namespace heirarchy by a path string.
uint64_t aml_namespace_commit(aml_overlay_t *overlay)
Commit all names in a namespace overlay to the global namespace heirarchy.
#define AML_NAME_UNDEFINED
Macro for an undefined name.
uint64_t aml_namespace_expose(void)
Expose the entire namespace heirarchy to sysfs.
aml_overlay_t * aml_overlay_find_containing(aml_overlay_t *overlay, aml_object_t *object)
Search a overlay and its parents for the first overlay that contains the given object.
void aml_namespace_init(aml_object_t *root)
Initialize the namespace heirarchy.
#define AML_NAME(a, b, c, d)
Macro to create an aml_name_t from 4 characters.
aml_object_t * aml_namespace_find_by_name_string(aml_overlay_t *overlay, aml_object_t *start, const aml_name_string_t *nameString)
Find an object in the namespace heirarchy by a name string.
void aml_namespace_remove(aml_object_t *object)
Remove an object from the namespace heirarchy it was added to.
void aml_overlay_deinit(aml_overlay_t *overlay)
Deinitialize a namespace overlay.
aml_object_t * aml_namespace_find_child(aml_overlay_t *overlay, aml_object_t *parent, aml_name_t name)
Find a child object directly under a parent object in the namespace heirarchy.
void aml_overlay_init(aml_overlay_t *overlay)
Initialize a namespace overlay.
uint32_t aml_name_t
Name type.
aml_object_t * aml_namespace_get_root(void)
Get the root object of the namespace heirarchy.
void aml_overlay_set_parent(aml_overlay_t *overlay, aml_overlay_t *parent)
Set the parent of a namespace overlay.
aml_object_t * aml_namespace_find(aml_overlay_t *overlay, aml_object_t *start, uint64_t nameCount,...)
Find an object in the namespace heirarchy by name segments.
uint64_t aml_namespace_add_by_name_string(aml_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.
aml_object_t * aml_alias_traverse(aml_alias_t *alias)
Traverse an alias object to get the target object.
#define AML_OBJECT_ID_NONE
Value for an invalid object id.
uint64_t aml_object_id_t
Object id type.
@ AML_ALIAS
Not in the spec, used internally to represent Aliases.
@ AML_OBJECT_ROOT
Is the root object.
@ AML_OBJECT_NAMED
Appears in the namespace tree. Will be set in aml_object_add().
const char * aml_type_to_string(aml_type_t type)
Convert an aml data type to a string.
dentry_t * acpi_get_sysfs_root(void)
Retrieve the sysfs root directory for ACPI.
EFI_PHYSICAL_ADDRESS buffer
static dentry_t * namespaceDir
static uint64_t aml_namespace_expose_object(aml_object_t *object, dentry_t *parentDir)
static aml_object_t * aml_namespace_traverse_parents(aml_object_t *current, uint64_t depth)
static aml_object_t * aml_namespace_search_single_name(aml_overlay_t *overlay, aml_object_t *current, aml_name_t name)
static map_key_t aml_object_map_key(aml_object_id_t parentId, aml_name_t name)
static aml_overlay_t globalOverlay
static aml_object_t * namespaceRoot
#define va_start(ap, parmN)
__builtin_va_list va_list
aml_name_seg_t * segments
Array of segments in the name path.
uint64_t segmentCount
Number of segments in the name path.
aml_prefix_path_t prefixPath
list_t objects
List of all objects in this namespace. Used for fast iteration.
struct aml_overlay * parent
The parent overlay, or NULL if none.
map_t map
Used to find the children of namespaces using their id and the name of the child.
bool present
If the first character is a root character ('\'), if yes, the name string is absolute.
Directory entry structure.
dentry_t * sysfs_dir_new(dentry_t *parent, const char *name, const inode_ops_t *inodeOps, void *private)
Create a new directory inside a mounted SysFS instance.