PatchworkOS
Loading...
Searching...
No Matches
object.h
Go to the documentation of this file.
1#pragma once
2
8#include <kernel/fs/sysfs.h>
9#include <kernel/utils/ref.h>
10
11#include <stdint.h>
12
13typedef struct aml_state aml_state_t;
14typedef struct aml_object aml_object_t;
15typedef struct aml_opregion_obj aml_opregion_obj_t;
16typedef struct aml_string_obj aml_string_obj_t;
17typedef struct aml_method_obj aml_method_obj_t;
18
30#define AML_SMALL_BUFFER_SIZE 32
31
35#define AML_SMALL_STRING_SIZE AML_SMALL_BUFFER_SIZE
36
40#define AML_SMALL_PACKAGE_SIZE 4
41
45#define AML_OBJECT_CACHE_SIZE 64
46
117
139
147
151#define AML_OBJECT_ID_NONE 0
152
168
173typedef aml_object_t* (*aml_method_implementation_t)(aml_method_obj_t* method, aml_object_t** args, uint64_t argCount);
174
192#define AML_OBJECT_COMMON_HEADER \
193 ref_t ref; \
194 aml_object_id_t id; \
195 aml_name_t name; \
196 map_entry_t mapEntry; \
197 list_entry_t listEntry; \
198 aml_namespace_overlay_t* overlay; \
199 list_t children; \
200 list_entry_t siblingsEntry; \
201 aml_object_t* parent; \
202 aml_object_flags_t flags; \
203 aml_type_t type; \
204 dentry_t* dir
205
217
229
236typedef struct aml_event_obj
237{
240
258
263typedef struct aml_integer_obj
264{
268
273typedef struct aml_integer_constant_obj
274{
278
296
307
312typedef struct aml_object_referencev
313{
317
329
343
350
362
367typedef struct aml_string_obj
368{
370 char* content;
372 char smallString[AML_SMALL_STRING_SIZE + 1];
374
379typedef struct aml_alias_obj
380{
384
396
404typedef struct aml_arg_obj
405{
409
414typedef struct aml_local_obj
415{
419
452
459
470
476void aml_object_clear(aml_object_t* object);
477
488
505
522
532
542uint64_t aml_buffer_set(aml_object_t* object, const uint8_t* buffer, uint64_t bytesToCopy, uint64_t length);
543
552
563 aml_bit_size_t bitSize);
564
572
580
588
600 aml_bit_size_t bitOffset, aml_bit_size_t bitSize);
601
614 aml_field_flags_t flags, aml_bit_size_t bitOffset, aml_bit_size_t bitSize);
615
629 uint64_t bankValue, aml_field_flags_t flags, aml_bit_size_t bitOffset, aml_bit_size_t bitSize);
630
639
652 aml_method_implementation_t implementation);
653
661
670
679
690
699
709 aml_resource_order_t resourceOrder);
710
721 aml_pblk_len_t pblkLen);
722
733
741uint64_t aml_string_set(aml_object_t* object, const char* str);
742
753
761
772
782
796
806
815
823
static fd_t data
Definition dwm.c:21
uint64_t aml_bit_size_t
Represents a size in bits within an opregion.
uint8_t aml_proc_id_t
ProcID structure, deprecated in version 6.4 of the ACPI specification.
Definition named.h:151
uint32_t aml_pblk_addr_t
PblkAddr structure, deprecated in version 6.4 of the ACPI specification.
Definition named.h:156
uint8_t aml_system_level_t
SystemLevel structure.
Definition named.h:166
uint8_t aml_pblk_len_t
PblkLen structure, deprecated in version 6.4 of the ACPI specification.
Definition named.h:161
uint8_t aml_sync_level_t
Definition named.h:135
aml_region_space_t
Region Space Encoding.
Definition named.h:30
uint16_t aml_resource_order_t
ResourceOrder structure.
Definition named.h:171
uint64_t aml_integer_t
AML Integer type.
Definition integer.h:20
uint64_t aml_mutex_id_t
Mutex id.
Definition mutex.h:28
uint64_t aml_object_reference_set(aml_object_t *object, aml_object_t *target)
Set a object as an ObjectReference to the given target object.
Definition object.c:831
void aml_object_exception_check(aml_object_t *object, aml_state_t *state)
Check if a object has the AML_OBJECT_EXCEPTION_ON_USE flag set and raise an exception if it is.
Definition object.c:461
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_string_resize(aml_string_obj_t *string, uint64_t newLength)
Resize a string object to the new length.
Definition object.c:1005
aml_type_t
ACPI data types.
Definition object.h:57
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_local_set(aml_object_t *object)
Set a object as a empty local variable.
Definition object.c:1204
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_package_set(aml_object_t *object, uint64_t length)
Set a object as a package with the given number of elements.
Definition object.c:869
uint64_t aml_integer_set(aml_object_t *object, aml_integer_t value)
Set a object as an integer with the given value and bit width.
Definition object.c:708
aml_method_obj_t * aml_method_find(const uint8_t *addr)
Find the method which contains the provided address in its AML bytecode range.
Definition object.c:794
#define AML_SMALL_STRING_SIZE
Size of string buffers used for small objects optimization, not including the null terminator.
Definition object.h:35
uint64_t aml_object_count_children(aml_object_t *parent)
Recursively count how many children an object has.
Definition object.c:264
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_string_set(aml_object_t *object, const char *str)
Set a object as a string with the given value.
Definition object.c:988
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_object_set_bits_at(aml_object_t *object, aml_bit_size_t bitOffset, aml_bit_size_t bitSize, uint8_t *in)
Store bits into a object at the specified bit offset and size.
Definition object.c:338
uint64_t aml_alias_set(aml_object_t *object, aml_object_t *target)
Set a object as an alias to the given target object.
Definition object.c:1096
uint64_t aml_arg_set(aml_object_t *object, aml_object_t *value)
Set a object as an argument with the given target object.
Definition object.c:1179
aml_object_t * aml_alias_obj_traverse(aml_alias_obj_t *alias)
Traverse an alias object to get the target object.
Definition object.c:1114
uint64_t aml_predefined_scope_set(aml_object_t *object)
Set a object as a predefined scope with the given name.
Definition object.c:1162
uint64_t aml_buffer_set_empty(aml_object_t *object, uint64_t length)
Set a object as an empty buffer with the given length.
Definition object.c:487
aml_object_t *(* aml_method_implementation_t)(aml_method_obj_t *method, aml_object_t **args, uint64_t argCount)
Method Implementation function type.
Definition object.h:173
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
aml_field_unit_obj_type_t
Field Unit types.
Definition object.h:162
uint64_t aml_string_set_empty(aml_object_t *object, uint64_t length)
Set a object as an empty string with the given length.
Definition object.c:955
uint64_t aml_debug_object_set(aml_object_t *object)
Set a object as a debug object.
Definition object.c:564
aml_object_flags_t
Flags for ACPI objects.
Definition object.h:123
void aml_object_clear(aml_object_t *object)
Clear the data of a object, setting its type to AML_UNINITIALIZED.
Definition object.c:87
uint64_t aml_object_get_bits_at(aml_object_t *object, aml_bit_size_t bitOffset, aml_bit_size_t bitSize, uint8_t *out)
Retrieve bits from a object at the specified bit offset and size.
Definition object.c:399
uint64_t aml_object_id_t
Object id type.
Definition object.h:146
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
#define AML_SMALL_BUFFER_SIZE
Size of buffers used for small objects optimization.
Definition object.h:30
uint64_t aml_object_get_total_count(void)
Get the total amount of allocated ACPI objects.
Definition object.c:24
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_unresolved_set(aml_object_t *object, const aml_name_string_t *nameString, aml_object_t *from, aml_patch_up_resolve_callback_t callback)
Set a object as an unresolved reference with the given namestring and starting point.
Definition object.c:1135
uint64_t aml_buffer_set(aml_object_t *object, const uint8_t *buffer, uint64_t bytesToCopy, uint64_t length)
Set a object as a buffer with the given content.
Definition object.c:520
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
#define AML_SMALL_PACKAGE_SIZE
Size of package element arrays used for small objects optimization.
Definition object.h:40
@ AML_UNRESOLVED
Not in the spec, used internally to represent unresolved references.
Definition object.h:86
@ AML_METHOD
Definition object.h:75
@ AML_BUFFER_FIELD
Definition object.h:60
@ AML_PROCESSOR
Definition object.h:81
@ AML_PACKAGE
Definition object.h:79
@ AML_OBJECT_REFERENCE
Definition object.h:77
@ AML_OPERATION_REGION
Definition object.h:78
@ AML_TYPE_AMOUNT
Not a type, just the amount of types.
Definition object.h:115
@ AML_DEBUG_OBJECT
Definition object.h:61
@ AML_STRING
Definition object.h:83
@ AML_ALIAS
Not in the spec, used internally to represent Aliases.
Definition object.h:85
@ AML_ARG
Not in the spec, used internally to represent method arguments.
Definition object.h:88
@ AML_THERMAL_ZONE
Definition object.h:84
@ AML_FIELD_UNIT
Definition object.h:64
@ AML_DATA_OBJECTS
Definition object.h:99
@ AML_POWER_RESOURCE
Definition object.h:80
@ AML_COMPUTATIONAL_DATA_OBJECTS
Definition object.h:93
@ AML_DATA_REF_OBJECTS
Definition object.h:103
@ AML_EVENT
Definition object.h:63
@ AML_DEVICE
Definition object.h:62
@ AML_NAMESPACES
Definition object.h:107
@ AML_MUTEX
Definition object.h:76
@ AML_LOCAL
Not in the spec, used internally to represent method local variables.
Definition object.h:89
@ AML_ALL_TYPES
Definition object.h:112
@ AML_INTEGER
Definition object.h:65
@ AML_PREDEFINED_SCOPE
Not in the spec, used internally to represent _SB, _GPE, etc.
Definition object.h:87
@ AML_UNINITIALIZED
Definition object.h:58
@ AML_RAW_DATA_BUFFER
Definition object.h:82
@ AML_BUFFER
Definition object.h:59
@ AML_FIELD_UNIT_BANK_FIELD
Definition object.h:166
@ AML_FIELD_UNIT_NONE
Definition object.h:163
@ AML_FIELD_UNIT_FIELD
Definition object.h:164
@ AML_FIELD_UNIT_INDEX_FIELD
Definition object.h:165
@ AML_OBJECT_EXPOSED_IN_SYSFS
Definition object.h:137
@ AML_OBJECT_ROOT
Is the root object.
Definition object.h:125
@ AML_OBJECT_EXCEPTION_ON_USE
Definition object.h:133
@ AML_OBJECT_NAMED
Appears in the namespace tree. Will be set in aml_object_add().
Definition object.h:126
@ AML_OBJECT_NONE
No flags.
Definition object.h:124
uint64_t(* aml_patch_up_resolve_callback_t)(aml_state_t *state, aml_object_t *match, aml_object_t *unresolved)
Callback type for resolving a forward reference.
Definition patch_up.h:25
EFI_PHYSICAL_ADDRESS buffer
Definition mem.c:15
static void start()
Definition main.c:542
__UINT32_TYPE__ uint32_t
Definition stdint.h:15
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
__UINT8_TYPE__ uint8_t
Definition stdint.h:11
__UINTPTR_TYPE__ uintptr_t
Definition stdint.h:43
Data for an alias object.
Definition object.h:380
aml_object_t * target
Definition object.h:382
Data for an argument object.
Definition object.h:405
AML_OBJECT_COMMON_HEADER
Definition object.h:406
aml_object_t * value
The object that was passed as the argument.
Definition object.h:407
Data for a buffer field object.
Definition object.h:223
aml_object_t * target
Definition object.h:225
aml_bit_size_t bitSize
Definition object.h:227
aml_bit_size_t bitOffset
Definition object.h:226
Data for a buffer object.
Definition object.h:211
uint64_t length
Definition object.h:214
uint8_t * content
Definition object.h:213
Data placeholder for an event object.
Definition object.h:237
FieldFlags structure.
Definition named.h:86
Data for a field unit object.
Definition object.h:246
aml_bit_size_t bitOffset
Used for Field, IndexField and BankField.
Definition object.h:255
aml_field_unit_obj_type_t fieldType
The type of field unit.
Definition object.h:248
aml_field_unit_obj_t * bank
Used for BankField.
Definition object.h:252
aml_field_flags_t fieldFlags
Used for Field, IndexField and BankField.
Definition object.h:254
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_bit_size_t bitSize
Used for Field, IndexField and BankField.
Definition object.h:256
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
Data for an integer constant object.
Definition object.h:274
aml_integer_t value
Definition object.h:276
Data for an integer object.
Definition object.h:264
aml_integer_t value
Definition object.h:266
Data for a local variable object.
Definition object.h:415
aml_object_t * value
The value of the local variable.
Definition object.h:417
MethodFlags structure.
Definition named.h:142
Data for a method object.
Definition object.h:284
aml_method_implementation_t implementation
Definition object.h:290
aml_method_flags_t methodFlags
Definition object.h:291
const uint8_t * end
Definition object.h:293
aml_mutex_id_t mutex
Definition object.h:294
const uint8_t * start
Definition object.h:292
Data for a mutex object.
Definition object.h:302
aml_mutex_id_t mutex
Definition object.h:305
aml_sync_level_t syncLevel
Definition object.h:304
A NameString structure.
Definition name.h:87
Data for an object reference object.
Definition object.h:313
aml_object_t * target
Definition object.h:315
ACPI object.
Definition object.h:425
aml_buffer_obj_t buffer
Definition object.h:431
aml_buffer_field_obj_t bufferField
Definition object.h:432
aml_power_resource_obj_t powerResource
Definition object.h:442
aml_opregion_obj_t opregion
Definition object.h:440
aml_local_obj_t local
Definition object.h:449
AML_OBJECT_COMMON_HEADER
Definition object.h:429
aml_mutex_obj_t mutex
Definition object.h:438
aml_event_obj_t event
Definition object.h:433
aml_object_reference_obj_t objectReference
Definition object.h:439
aml_integer_obj_t integer
Definition object.h:435
aml_processor_obj_t processor
Definition object.h:443
aml_field_unit_obj_t fieldUnit
Definition object.h:434
aml_package_obj_t package
Definition object.h:441
aml_alias_obj_t alias
Definition object.h:446
aml_integer_constant_obj_t integerConstant
Definition object.h:436
aml_unresolved_obj_t unresolved
Definition object.h:447
aml_string_obj_t string
Definition object.h:444
aml_method_obj_t method
Definition object.h:437
aml_arg_obj_t arg
Definition object.h:448
Data for an operation region object.
Definition object.h:323
aml_region_space_t space
Definition object.h:325
uint32_t length
Definition object.h:327
uintptr_t offset
Definition object.h:326
Data for a package object.
Definition object.h:337
uint64_t length
Definition object.h:340
aml_object_t ** elements
Definition object.h:339
aml_resource_order_t resourceOrder
Definition object.h:348
aml_system_level_t systemLevel
Definition object.h:347
Data for a processor object.
Definition object.h:356
aml_proc_id_t procId
Definition object.h:358
aml_pblk_len_t pblkLen
Definition object.h:360
aml_pblk_addr_t pblkAddr
Definition object.h:359
AML State.
Definition state.h:25
Data for a string object.
Definition object.h:368
char * content
Definition object.h:370
uint64_t length
Definition object.h:371
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