PatchworkOS
Loading...
Searching...
No Matches
predefined.c
Go to the documentation of this file.
2
3#include <kernel/acpi/acpi.h>
6#include <kernel/log/log.h>
7
8#include <kernel/version.h>
9
10#include <errno.h>
11
13
15{
16 (void)method; // Unused
17
18 if (argCount != 1 || args[0]->type != AML_STRING)
19 {
20 errno = EINVAL;
21 return NULL;
22 }
23
24 LOG_DEBUG("_OSI called with argument: '%.*s'\n", (int)args[0]->string.length, args[0]->string.content);
25
26 aml_object_t* result = aml_object_new();
27 if (result == NULL)
28 {
29 return NULL;
30 }
31
32 // TODO: Implement this properly.
33 if (aml_integer_set(result, UINT64_MAX) == ERR)
34 {
35 DEREF(result);
36 return NULL;
37 }
38
39 return result;
40}
41
43{
44 (void)method; // Unused
45 (void)args; // Unused
46
47 if (argCount != 0)
48 {
49 errno = EINVAL;
50 return NULL;
51 }
52
53 aml_object_t* result = aml_object_new();
54 if (result == NULL)
55 {
56 return NULL;
57 }
58
60 {
61 DEREF(result);
62 return NULL;
63 }
64
65 return result;
66}
67
69{
70 (void)method; // Unused
71 (void)args; // Unused
72
73 if (argCount != 0)
74 {
75 errno = EINVAL;
76 return NULL;
77 }
78
79 aml_object_t* result = aml_object_new();
80 if (result == NULL)
81 {
82 return NULL;
83 }
84
85 if (aml_string_set(result, OS_NAME) == ERR)
86 {
87 DEREF(result);
88 return NULL;
89 }
90
91 return result;
92}
93
95{
96 aml_object_t* object = aml_object_new();
97 if (object == NULL)
98 {
99 return ERR;
100 }
101 DEREF_DEFER(object);
102
103 if (aml_predefined_scope_set(object) == ERR || aml_namespace_add_child(NULL, NULL, name, object) == ERR)
104 {
105 return ERR;
106 }
107
108 return 0;
109}
110
112{
113 return globalMutex;
114}
115
117{
118 // Normal predefined root objects, see section 5.3.1 of the ACPI specification.
119 if (aml_create_predefined_scope(AML_NAME('_', 'G', 'P', 'E')) == ERR ||
120 aml_create_predefined_scope(AML_NAME('_', 'P', 'R', '_')) == ERR ||
121 aml_create_predefined_scope(AML_NAME('_', 'S', 'B', '_')) == ERR ||
122 aml_create_predefined_scope(AML_NAME('_', 'S', 'I', '_')) == ERR ||
123 aml_create_predefined_scope(AML_NAME('_', 'T', 'Z', '_')) == ERR)
124 {
125 return ERR;
126 }
127
128 // OS specific predefined objects, see section 5.7 of the ACPI specification.
130 if (osi == NULL)
131 {
132 return ERR;
133 }
134 DEREF_DEFER(osi);
135 aml_method_flags_t osiFlags = {
136 .argCount = 1,
137 .isSerialized = true,
138 .syncLevel = 15,
139 };
140 if (aml_method_set(osi, osiFlags, NULL, NULL, aml_osi_implementation) == ERR ||
141 aml_namespace_add_child(NULL, NULL, AML_NAME('_', 'O', 'S', 'I'), osi) == ERR)
142 {
143 return ERR;
144 }
145
147 if (rev == NULL)
148 {
149 return ERR;
150 }
151 DEREF_DEFER(rev);
152 aml_method_flags_t revFlags = {
153 .argCount = 0,
154 .isSerialized = true,
155 .syncLevel = 15,
156 };
157 if (aml_method_set(rev, revFlags, NULL, NULL, aml_rev_implementation) == ERR ||
158 aml_namespace_add_child(NULL, NULL, AML_NAME('_', 'R', 'E', 'V'), rev) == ERR)
159 {
160 return ERR;
161 }
162
164 if (os == NULL)
165 {
166 return ERR;
167 }
168 DEREF_DEFER(os);
169 aml_method_flags_t osFlags = {
170 .argCount = 0,
171 .isSerialized = true,
172 .syncLevel = 15,
173 };
174 if (aml_method_set(os, osFlags, NULL, NULL, aml_os_implementation) == ERR ||
175 aml_namespace_add_child(NULL, NULL, AML_NAME('_', 'O', 'S', '_'), os) == ERR)
176 {
177 return ERR;
178 }
179
180 // TODO: Implement _GL properly.
182 if (gl == NULL)
183 {
184 return ERR;
185 }
186 DEREF_DEFER(gl);
187 if (aml_mutex_set(gl, 0) == ERR || aml_namespace_add_child(NULL, NULL, AML_NAME('_', 'G', 'L', '_'), gl) == ERR)
188 {
189 return ERR;
190 }
191
192 globalMutex = REF(&gl->mutex);
193 return 0;
194}
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
#define AML_NAME(a, b, c, d)
Macro to create an aml_name_t from 4 characters.
Definition namespace.h:112
uint32_t aml_name_t
Name type.
Definition namespace.h:101
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_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_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_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_predefined_scope_set(aml_object_t *object)
Set a object as a predefined scope with the given name.
Definition object.c:1162
@ AML_STRING
Definition object.h:83
aml_object_t * aml_os_implementation(aml_method_obj_t *method, aml_object_t **args, uint64_t argCount)
Implementation of the _OS predefined method.
Definition predefined.c:68
uint64_t aml_predefined_init(void)
Initialize predefined AML names and objects.
Definition predefined.c:116
aml_object_t * aml_rev_implementation(aml_method_obj_t *method, aml_object_t **args, uint64_t argCount)
Implementation of the _REV predefined method.
Definition predefined.c:42
aml_mutex_obj_t * aml_gl_get(void)
Get the global AML mutex.
Definition predefined.c:111
aml_object_t * aml_osi_implementation(aml_method_obj_t *method, aml_object_t **args, uint64_t argCount)
Implementation of the _OSI predefined method.
Definition predefined.c:14
#define RSDP_CURRENT_REVISION
The expected value of the revision field in the RSDP structure.
Definition acpi.h:66
#define LOG_DEBUG(format,...)
Definition log.h:81
#define DEREF_DEFER(ptr)
RAII-style cleanup for scoped references.
Definition ref.h:54
#define REF(ptr)
Increment reference count.
Definition ref.h:65
#define DEREF(ptr)
Decrement reference count.
Definition ref.h:80
#define EINVAL
Invalid argument.
Definition errno.h:142
#define errno
Error number variable.
Definition errno.h:27
#define NULL
Pointer error value.
Definition NULL.h:23
#define ERR
Integer error value.
Definition ERR.h:17
static uint64_t aml_create_predefined_scope(aml_name_t name)
Definition predefined.c:94
static aml_mutex_obj_t * globalMutex
Definition predefined.c:12
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
#define UINT64_MAX
Definition stdint.h:74
MethodFlags structure.
Definition named.h:142
uint8_t argCount
Amount of arguments (0-7)
Definition named.h:143
Data for a method object.
Definition object.h:284
Data for a mutex object.
Definition object.h:302
ACPI object.
Definition object.h:425
aml_mutex_obj_t mutex
Definition object.h:438