PatchworkOS  966e257
A non-POSIX operating system.
Loading...
Searching...
No Matches
predefined.c
Go to the documentation of this file.
2
3#include <kernel/log/log.h>
4#include <modules/acpi/acpi.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 _OSI strings properly. For now, we just return true for everything.
33
34 if (aml_integer_set(result, UINT64_MAX) == ERR)
35 {
36 UNREF(result);
37 return NULL;
38 }
39
40 return result;
41}
42
44{
45 (void)method; // Unused
46 (void)args; // Unused
47
48 if (argCount != 0)
49 {
50 errno = EINVAL;
51 return NULL;
52 }
53
54 aml_object_t* result = aml_object_new();
55 if (result == NULL)
56 {
57 return NULL;
58 }
59
61 {
62 UNREF(result);
63 return NULL;
64 }
65
66 return result;
67}
68
70{
71 (void)method; // Unused
72 (void)args; // Unused
73
74 if (argCount != 0)
75 {
76 errno = EINVAL;
77 return NULL;
78 }
79
80 aml_object_t* result = aml_object_new();
81 if (result == NULL)
82 {
83 return NULL;
84 }
85
86 if (aml_string_set(result, OS_NAME) == ERR)
87 {
88 UNREF(result);
89 return NULL;
90 }
91
92 return result;
93}
94
96{
97 aml_object_t* object = aml_object_new();
98 if (object == NULL)
99 {
100 return ERR;
101 }
102 UNREF_DEFER(object);
103
104 if (aml_predefined_scope_set(object) == ERR || aml_namespace_add_child(NULL, NULL, name, object) == ERR)
105 {
106 return ERR;
107 }
108
109 return 0;
110}
111
113{
114 return globalMutex;
115}
116
118{
119 // Normal predefined root objects, see section 5.3.1 of the ACPI specification.
120 if (aml_create_predefined_scope(AML_NAME('_', 'G', 'P', 'E')) == ERR ||
121 aml_create_predefined_scope(AML_NAME('_', 'P', 'R', '_')) == ERR ||
122 aml_create_predefined_scope(AML_NAME('_', 'S', 'B', '_')) == ERR ||
123 aml_create_predefined_scope(AML_NAME('_', 'S', 'I', '_')) == ERR ||
124 aml_create_predefined_scope(AML_NAME('_', 'T', 'Z', '_')) == ERR)
125 {
126 return ERR;
127 }
128
129 // OS specific predefined objects, see section 5.7 of the ACPI specification.
131 if (osi == NULL)
132 {
133 return ERR;
134 }
135 UNREF_DEFER(osi);
136 aml_method_flags_t osiFlags = {
137 .argCount = 1,
138 .isSerialized = true,
139 .syncLevel = 15,
140 };
141 if (aml_method_set(osi, osiFlags, NULL, NULL, aml_osi_implementation) == ERR ||
142 aml_namespace_add_child(NULL, NULL, AML_NAME('_', 'O', 'S', 'I'), osi) == ERR)
143 {
144 return ERR;
145 }
146
148 if (rev == NULL)
149 {
150 return ERR;
151 }
152 UNREF_DEFER(rev);
153 aml_method_flags_t revFlags = {
154 .argCount = 0,
155 .isSerialized = true,
156 .syncLevel = 15,
157 };
158 if (aml_method_set(rev, revFlags, NULL, NULL, aml_rev_implementation) == ERR ||
159 aml_namespace_add_child(NULL, NULL, AML_NAME('_', 'R', 'E', 'V'), rev) == ERR)
160 {
161 return ERR;
162 }
163
165 if (os == NULL)
166 {
167 return ERR;
168 }
169 UNREF_DEFER(os);
170 aml_method_flags_t osFlags = {
171 .argCount = 0,
172 .isSerialized = true,
173 .syncLevel = 15,
174 };
175 if (aml_method_set(os, osFlags, NULL, NULL, aml_os_implementation) == ERR ||
176 aml_namespace_add_child(NULL, NULL, AML_NAME('_', 'O', 'S', '_'), os) == ERR)
177 {
178 return ERR;
179 }
180
181 /// @todo Implement _GL properly.
183 if (gl == NULL)
184 {
185 return ERR;
186 }
187 UNREF_DEFER(gl);
188 if (aml_mutex_set(gl, 0) == ERR || aml_namespace_add_child(NULL, NULL, AML_NAME('_', 'G', 'L', '_'), gl) == ERR)
189 {
190 return ERR;
191 }
192
193 globalMutex = REF(&gl->mutex);
194 return 0;
195}
#define LOG_DEBUG(format,...)
Definition log.h:100
#define UNREF_DEFER(ptr)
RAII-style cleanup for scoped references.
Definition ref.h:54
#define REF(ptr)
Increment reference count.
Definition ref.h:65
#define UNREF(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
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.
Definition namespace.c:395
#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:796
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:876
aml_object_t * aml_object_new(void)
Allocate a new ACPI object.
Definition object.c:62
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:1068
uint64_t aml_predefined_scope_set(aml_object_t *object)
Set a object as a predefined scope with the given name.
Definition object.c:1219
uint64_t aml_integer_set(aml_object_t *object, aml_uint_t value)
Set a object as an integer with the given value and bit width.
Definition object.c:772
@ AML_STRING
Definition object.h:85
aml_object_t * aml_rev_implementation(aml_method_t *method, aml_object_t **args, uint64_t argCount)
Implementation of the _REV predefined method.
Definition predefined.c:43
uint64_t aml_predefined_init(void)
Initialize predefined AML names and objects.
Definition predefined.c:117
aml_mutex_t * aml_gl_get(void)
Get the global AML mutex.
Definition predefined.c:112
aml_object_t * aml_osi_implementation(aml_method_t *method, aml_object_t **args, uint64_t argCount)
Implementation of the _OSI predefined method.
Definition predefined.c:14
aml_object_t * aml_os_implementation(aml_method_t *method, aml_object_t **args, uint64_t argCount)
Implementation of the _OS predefined method.
Definition predefined.c:69
#define RSDP_CURRENT_REVISION
The expected value of the revision field in the RSDP structure.
Definition acpi.h:66
static aml_mutex_t * globalMutex
Definition predefined.c:12
static uint64_t aml_create_predefined_scope(aml_name_t name)
Definition predefined.c:95
__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:306
Data for a mutex object.
Definition object.h:324
ACPI object.
Definition object.h:447
aml_mutex_t mutex
Definition object.h:461