PatchworkOS  dbbdc99
A non-POSIX operating system.
Loading...
Searching...
No Matches
field_unit.c
Go to the documentation of this file.
1#include <kernel/cpu/port.h>
2#include <kernel/log/log.h>
4#include <kernel/mem/vmm.h>
13
14#include <errno.h>
15#include <stdint.h>
16
17typedef struct aml_region_handler
18{
20 uint64_t* out);
22 uint64_t value);
24
26{
27 size_t accessBytes = (accessSize + 7) / 8;
28
29 bool crossesBoundary = ((uintptr_t)address & (PAGE_SIZE - 1)) + accessBytes > PAGE_SIZE;
30
31 for (uint64_t page = 0; page < (crossesBoundary ? 2 : 1); page++)
32 {
33 phys_addr_t physAddr = (phys_addr_t)address + page * PAGE_SIZE;
34 void* virtAddt = (void*)PML_LOWER_TO_HIGHER(physAddr);
35 if (vmm_map(NULL, virtAddt, physAddr, PAGE_SIZE, PML_GLOBAL | PML_WRITE | PML_PRESENT, NULL, NULL) == NULL)
36 {
37 LOG_ERR("failed to map physical address %p for opregion access\n", physAddr);
38 errno = EIO;
39 return NULL;
40 }
41 }
42
43 return (void*)PML_LOWER_TO_HIGHER(address);
44}
45
47 aml_bit_size_t accessSize, uint64_t* out)
48{
49 UNUSED(state);
50 UNUSED(opregion);
51
52 void* virtAddr = NULL;
54 {
55 virtAddr = (void*)address;
56 }
57 else
58 {
59 virtAddr = aml_ensure_mem_is_mapped(address, accessSize);
60 if (virtAddr == NULL)
61 {
62 return ERR;
63 }
64 }
65
66 switch (accessSize)
67 {
68 case 8:
69 *out = *(volatile uint8_t*)virtAddr;
70 break;
71 case 16:
72 *out = *(volatile uint16_t*)virtAddr;
73 break;
74 case 32:
75 *out = *(volatile uint32_t*)virtAddr;
76 break;
77 case 64:
78 *out = *(volatile uint64_t*)virtAddr;
79 break;
80 default:
81 LOG_ERR("invalid opregion read with access size %u\n", accessSize);
82 errno = ENOSYS;
83 return ERR;
84 }
85 return 0;
86}
87
89 aml_bit_size_t accessSize, uint64_t value)
90{
91 UNUSED(state);
92 UNUSED(opregion);
93
94 void* virtAddr = NULL;
96 {
97 virtAddr = (void*)address;
98 }
99 else
100 {
101 virtAddr = aml_ensure_mem_is_mapped(address, accessSize);
102 if (virtAddr == NULL)
103 {
104 return ERR;
105 }
106 }
107
108 switch (accessSize)
109 {
110 case 8:
111 *(volatile uint8_t*)virtAddr = (uint8_t)value;
112 break;
113 case 16:
114 *(volatile uint16_t*)virtAddr = (uint16_t)value;
115 break;
116 case 32:
117 *(volatile uint32_t*)virtAddr = (uint32_t)value;
118 break;
119 case 64:
120 *(volatile uint64_t*)virtAddr = value;
121 break;
122 default:
123 LOG_ERR("invalid opregion write with access size %u\n", accessSize);
124 errno = ENOSYS;
125 return ERR;
126 }
127 return 0;
128}
129
131 aml_bit_size_t accessSize, uint64_t* out)
132{
133 UNUSED(state);
134 UNUSED(opregion);
135
136 switch (accessSize)
137 {
138 case 8:
139 *out = in8(address);
140 break;
141 case 16:
142 *out = in16(address);
143 break;
144 case 32:
145 *out = in32(address);
146 break;
147 default:
148 LOG_ERR("unable to read opregion with access size %u\n", accessSize);
149 errno = ENOSYS;
150 return ERR;
151 }
152 return 0;
153}
154
156 aml_bit_size_t accessSize, uint64_t value)
157{
158 UNUSED(state);
159 UNUSED(opregion);
160
161 switch (accessSize)
162 {
163 case 8:
164 out8(address, (uint8_t)value);
165 break;
166 case 16:
167 out16(address, (uint16_t)value);
168 break;
169 case 32:
170 out32(address, (uint32_t)value);
171 break;
172 default:
173 LOG_ERR("unable to write opregion with access size %u\n", accessSize);
174 errno = ENOSYS;
175 return ERR;
176 }
177 return 0;
178}
179
181 pci_bus_t* bus, pci_slot_t* slot, pci_function_t* function)
182{
183 UNUSED(state);
184 // Note that the aml_object_find function will recursively search parent scopes.
185
186 // We assume zero for all parameters if the corresponding object is not found.
187 *segmentGroup = 0;
188 *bus = 0;
189 *slot = 0;
190 *function = 0;
191
192 aml_object_t* location = CONTAINER_OF(opregion, aml_object_t, opregion);
193
194 // See section 6.1.1 of the ACPI specification.
195 aml_object_t* adrObject = aml_namespace_find(&state->overlay, location, AML_NAME('_', 'A', 'D', 'R'));
196 if (adrObject != NULL)
197 {
198 UNREF_DEFER(adrObject);
199
200 aml_object_t* adrResult = aml_evaluate(state, adrObject, AML_INTEGER);
201 if (adrResult == NULL)
202 {
203 LOG_ERR("failed to evaluate _ADR for opregion '%s'\n", AML_NAME_TO_STRING(location->name));
204 return ERR;
205 }
206 aml_uint_t adrValue = adrResult->integer.value;
207 UNREF(adrResult);
208
209 *slot = adrValue & 0x0000FFFF; // Low word is slot
210 *function = (adrValue >> 16) & 0x0000FFFF; // High word is function
211 }
212
213 // Section 6.5.5 of the ACPI specification.
214 aml_object_t* bbnObject = aml_namespace_find(&state->overlay, location, AML_NAME('_', 'B', 'B', 'N'));
215 if (bbnObject != NULL)
216 {
217 UNREF_DEFER(bbnObject);
218
219 aml_object_t* bbnResult = aml_evaluate(state, bbnObject, AML_INTEGER);
220 if (bbnResult == NULL)
221 {
222 LOG_ERR("failed to evaluate _BBN for opregion '%s'\n", AML_NAME_TO_STRING(location->name));
223 return ERR;
224 }
225 aml_uint_t bbnValue = bbnResult->integer.value;
226 UNREF(bbnResult);
227
228 // Lower 8 bits is the bus number.
229 *bus = bbnValue & 0xFF;
230 }
231
232 // Section 6.5.6 of the ACPI specification.
233 aml_object_t* segObject = aml_namespace_find(&state->overlay, location, AML_NAME('_', 'S', 'E', 'G'));
234 if (segObject != NULL)
235 {
236 UNREF_DEFER(segObject);
237
238 aml_object_t* segResult = aml_evaluate(state, segObject, AML_INTEGER);
239 if (segResult == NULL)
240 {
241 LOG_ERR("failed to evaluate _SEG for opregion '%s'\n", AML_NAME_TO_STRING(location->name));
242 return ERR;
243 }
244 aml_uint_t segValue = segResult->integer.value;
245 UNREF(segResult);
246
247 // Lower 16 bits is the segment group number.
248 *segmentGroup = segValue & 0xFFFF;
249 }
250
251 return 0;
252}
253
255 aml_bit_size_t accessSize, uint64_t* out)
256{
257 UNUSED(state);
258
259 pci_segment_group_t segmentGroup;
260 pci_bus_t bus;
261 pci_slot_t slot;
262 pci_function_t function;
263 if (aml_pci_get_params(state, opregion, &segmentGroup, &bus, &slot, &function) == ERR)
264 {
265 return ERR;
266 }
267
268 switch (accessSize)
269 {
270 case 8:
271 *out = pci_config_read8(segmentGroup, bus, slot, function, (uint16_t)address);
272 break;
273 case 16:
274 *out = pci_config_read16(segmentGroup, bus, slot, function, (uint16_t)address);
275 break;
276 case 32:
277 *out = pci_config_read32(segmentGroup, bus, slot, function, (uint16_t)address);
278 break;
279 default:
280 LOG_ERR("unable to read PCI config opregion with access size %u\n", accessSize);
281 errno = ENOSYS;
282 return ERR;
283 }
284 return 0;
285}
286
288 aml_bit_size_t accessSize, uint64_t value)
289{
290 pci_segment_group_t segmentGroup;
291 pci_bus_t bus;
292 pci_slot_t slot;
293 pci_function_t function;
294 if (aml_pci_get_params(state, opregion, &segmentGroup, &bus, &slot, &function) == ERR)
295 {
296 return ERR;
297 }
298
299 switch (accessSize)
300 {
301 case 8:
302 pci_config_write8(segmentGroup, bus, slot, function, (uint16_t)address, (uint8_t)value);
303 break;
304 case 16:
305 pci_config_write16(segmentGroup, bus, slot, function, (uint16_t)address, (uint16_t)value);
306 break;
307 case 32:
308 pci_config_write32(segmentGroup, bus, slot, function, (uint16_t)address, (uint32_t)value);
309 break;
310 default:
311 LOG_ERR("unable to write PCI config opregion with access size %u\n", accessSize);
312 errno = ENOSYS;
313 return ERR;
314 }
315 return 0;
316}
317
323
325 aml_bit_size_t accessSize, uint64_t* out)
326{
327 if (out == NULL)
328 {
329 errno = EINVAL;
330 return ERR;
331 }
332
333 if (opregion->space >= ARRAY_SIZE(regionHandlers) || regionHandlers[opregion->space].read == NULL)
334 {
335 LOG_ERR("unimplemented opregion read with opregion space '%s'\n", aml_region_space_to_string(opregion->space));
336 errno = ENOSYS;
337 return ERR;
338 }
339 return regionHandlers[opregion->space].read(state, opregion, address, accessSize, out);
340}
341
343 aml_bit_size_t accessSize, uint64_t value)
344{
345 if (opregion->space >= ARRAY_SIZE(regionHandlers) || regionHandlers[opregion->space].write == NULL)
346 {
347 LOG_ERR("unimplemented opregion write with opregion space '%s'\n", aml_region_space_to_string(opregion->space));
348 errno = ENOSYS;
349 return ERR;
350 }
351 return regionHandlers[opregion->space].write(state, opregion, address, accessSize, value);
352}
353
355{
356 // Bit manipulation magic to find the byte offset and align it to the access size.
357 return (bitOffset & ~(accessSize - 1)) / 8;
358}
359
360typedef enum aml_access_direction
361{
365
367 uint64_t byteOffset, uint64_t* out)
368{
369 switch (fieldUnit->fieldType)
370 {
373 {
374 aml_opregion_t* opregion = fieldUnit->opregion;
375 uintptr_t address = opregion->offset + byteOffset;
376 return aml_opregion_read(state, opregion, address, accessSize, out);
377 }
379 {
381 if (temp == NULL)
382 {
383 return ERR;
384 }
385 UNREF_DEFER(temp);
386
387 if (aml_integer_set(temp, byteOffset) == ERR)
388 {
389 return ERR;
390 }
391
392 if (aml_field_unit_store(state, fieldUnit->index, temp) == ERR)
393 {
394 return ERR;
395 }
396
397 aml_object_clear(temp);
398
399 if (aml_field_unit_load(state, fieldUnit->data, temp) == ERR)
400 {
401 return ERR;
402 }
403
404 assert(temp->type == AML_INTEGER);
405
406 *out = temp->integer.value;
407 return 0;
408 }
409 default:
410 LOG_ERR("invalid field object type %d\n", fieldUnit->type);
411 errno = EINVAL;
412 return ERR;
413 }
414}
415
417 uint64_t byteOffset, uint64_t value)
418{
419 switch (fieldUnit->fieldType)
420 {
423 {
424 aml_opregion_t* opregion = fieldUnit->opregion;
425 uintptr_t address = opregion->offset + byteOffset;
426 return aml_opregion_write(state, opregion, address, accessSize, value);
427 }
429 {
431 if (temp == NULL)
432 {
433 return ERR;
434 }
435 UNREF_DEFER(temp);
436
437 if (aml_integer_set(temp, byteOffset) == ERR)
438 {
439 return ERR;
440 }
441
442 if (aml_field_unit_store(state, fieldUnit->index, temp) == ERR)
443 {
444 return ERR;
445 }
446
447 aml_object_clear(temp);
448
449 if (aml_integer_set(temp, value) == ERR)
450 {
451 return ERR;
452 }
453
454 if (aml_field_unit_store(state, fieldUnit->data, temp) == ERR)
455 {
456 return ERR;
457 }
458 return 0;
459 }
460 default:
461 LOG_ERR("invalid field object type %d\n", fieldUnit->type);
462 errno = EINVAL;
463 return ERR;
464 }
465}
466
468 aml_access_direction_t direction)
469{
470 // The integer revision handling is enterily done by the aml_get_access_size function, so we dont need to
471 // do anything special here.
472
473 uint64_t result = 0;
475 if (fieldUnit->fieldFlags.lockRule == AML_LOCK_RULE_LOCK)
476 {
479 {
480 return ERR;
481 }
482 }
483
484 /// @todo "An Operation Region object implicitly supports Mutex synchronization. Updates to the object, or a Field
485 /// data object for the region, will automatically synchronize on the Operation Region object;" - Section 19.6.100
486
487 if (fieldUnit->fieldType == AML_FIELD_UNIT_BANK_FIELD)
488 {
489 if (aml_field_unit_store(state, fieldUnit->bank, fieldUnit->bankValue) == ERR)
490 {
491 result = ERR;
492 goto cleanup;
493 }
494 }
495
496 aml_region_space_t regionSpace;
497 if (fieldUnit->fieldType == AML_FIELD_UNIT_INDEX_FIELD)
498 {
499 regionSpace = fieldUnit->data->opregion->space;
500 }
501 else
502 {
503 regionSpace = fieldUnit->opregion->space;
504 }
505
506 aml_bit_size_t accessSize;
507 if (aml_get_access_size(fieldUnit->bitSize, fieldUnit->fieldFlags.accessType, regionSpace, &accessSize) == ERR)
508 {
509 result = ERR;
510 goto cleanup;
511 }
512
513 uint64_t byteOffset = aml_get_aligned_byte_offset(fieldUnit->bitOffset, accessSize);
514
515 uint64_t currentPos = 0;
516 while (currentPos < fieldUnit->bitSize)
517 {
518 aml_bit_size_t inAccessOffset = (fieldUnit->bitOffset + currentPos) & (accessSize - 1);
519 aml_bit_size_t bitsToAccess = MIN(fieldUnit->bitSize - currentPos, accessSize - inAccessOffset);
520 uint64_t mask = (bitsToAccess >= 64) ? UINT64_MAX : ((1ULL << bitsToAccess) - 1);
521
522 switch (direction)
523 {
524 case AML_ACCESS_READ:
525 {
526 uint64_t value = 0;
527 if (aml_generic_field_read_at(state, fieldUnit, accessSize, byteOffset, &value) == ERR)
528 {
529 result = ERR;
530 goto cleanup;
531 }
532
533 value = (value >> inAccessOffset) & mask;
534
535 // We treat value as a buffer of 8 bytes.
536 if (aml_object_set_bits_at(data, currentPos, bitsToAccess, (uint8_t*)&value) == ERR)
537 {
538 result = ERR;
539 goto cleanup;
540 }
541 }
542 break;
543 case AML_ACCESS_WRITE:
544 {
545 uint64_t value;
546 switch (fieldUnit->fieldFlags.updateRule)
547 {
549 {
550 if (aml_generic_field_read_at(state, fieldUnit, accessSize, byteOffset, &value) == ERR)
551 {
552 result = ERR;
553 goto cleanup;
554 }
555 }
556 break;
558 value = UINT64_MAX;
559 break;
561 value = 0;
562 break;
563 default:
564 LOG_ERR("invalid field update rule %d\n", fieldUnit->fieldFlags.updateRule);
565 errno = EINVAL;
566 result = ERR;
567 goto cleanup;
568 }
569
570 value &= ~(mask << inAccessOffset);
571
572 uint64_t newValue;
573 // We treat newValue as a buffer of 8 bytes.
574 if (aml_object_get_bits_at(data, currentPos, bitsToAccess, (uint8_t*)&newValue) == ERR)
575 {
576 result = ERR;
577 goto cleanup;
578 }
579 value |= (newValue & mask) << inAccessOffset;
580
581 if (aml_generic_field_write_at(state, fieldUnit, accessSize, byteOffset, value) == ERR)
582 {
583 result = ERR;
584 goto cleanup;
585 }
586 }
587 break;
588 default:
589 LOG_ERR("invalid field access direction %d\n", direction);
590 errno = EINVAL;
591 result = ERR;
592 goto cleanup;
593 }
594
595 currentPos += bitsToAccess;
596 byteOffset += accessSize / 8;
597 }
598
599cleanup:
600 if (globalMutex != NULL)
601 {
603 {
604 result = ERR;
605 }
606 }
607 return result;
608}
609
611{
612 if (fieldUnit == NULL || out == NULL)
613 {
614 errno = EINVAL;
615 return ERR;
616 }
617
618 uint64_t byteSize = (fieldUnit->bitSize + 7) / 8;
619 if (byteSize > aml_integer_byte_size())
620 {
621 if (aml_buffer_set_empty(out, byteSize) == ERR)
622 {
623 return ERR;
624 }
625 }
626 else
627 {
628 if (aml_integer_set(out, 0) == ERR)
629 {
630 return ERR;
631 }
632 }
633
634 return aml_field_unit_access(state, fieldUnit, out, AML_ACCESS_READ);
635}
636
638{
639 if (fieldUnit == NULL || in == NULL)
640 {
641 errno = EINVAL;
642 return ERR;
643 }
644
645 aml_type_t type = in->type;
646 if (type != AML_INTEGER && type != AML_BUFFER)
647 {
648 LOG_ERR("cannot write to field unit with data of type '%s'\n", aml_type_to_string(type));
649 errno = EINVAL;
650 return ERR;
651 }
652
653 return aml_field_unit_access(state, fieldUnit, in, AML_ACCESS_WRITE);
654}
#define assert(expression)
Definition assert.h:29
#define CLOCKS_NEVER
Definition clock_t.h:18
static fd_t data
Definition dwm.c:21
aml_access_direction_t
Definition field_unit.c:361
@ AML_ACCESS_READ
Definition field_unit.c:362
@ AML_ACCESS_WRITE
Definition field_unit.c:363
static uint64_t aml_opregion_write(aml_state_t *state, aml_opregion_t *opregion, uint64_t address, aml_bit_size_t accessSize, uint64_t value)
Definition field_unit.c:342
static uint64_t aml_system_io_write(aml_state_t *state, aml_opregion_t *opregion, uint64_t address, aml_bit_size_t accessSize, uint64_t value)
Definition field_unit.c:155
static aml_region_handler_t regionHandlers[]
Definition field_unit.c:318
static uint64_t aml_opregion_read(aml_state_t *state, aml_opregion_t *opregion, uint64_t address, aml_bit_size_t accessSize, uint64_t *out)
Definition field_unit.c:324
static uint64_t aml_system_mem_read(aml_state_t *state, aml_opregion_t *opregion, uintptr_t address, aml_bit_size_t accessSize, uint64_t *out)
Definition field_unit.c:46
static uint64_t aml_generic_field_write_at(aml_state_t *state, aml_field_unit_t *fieldUnit, aml_bit_size_t accessSize, uint64_t byteOffset, uint64_t value)
Definition field_unit.c:416
static uint64_t aml_generic_field_read_at(aml_state_t *state, aml_field_unit_t *fieldUnit, aml_bit_size_t accessSize, uint64_t byteOffset, uint64_t *out)
Definition field_unit.c:366
static uint64_t aml_get_aligned_byte_offset(aml_bit_size_t bitOffset, aml_bit_size_t accessSize)
Definition field_unit.c:354
static uint64_t aml_field_unit_access(aml_state_t *state, aml_field_unit_t *fieldUnit, aml_object_t *data, aml_access_direction_t direction)
Definition field_unit.c:467
static uint64_t aml_pci_config_write(aml_state_t *state, aml_opregion_t *opregion, uint64_t address, aml_bit_size_t accessSize, uint64_t value)
Definition field_unit.c:287
static uint64_t aml_system_io_read(aml_state_t *state, aml_opregion_t *opregion, uint64_t address, aml_bit_size_t accessSize, uint64_t *out)
Definition field_unit.c:130
static uint64_t aml_system_mem_write(aml_state_t *state, aml_opregion_t *opregion, uint64_t address, aml_bit_size_t accessSize, uint64_t value)
Definition field_unit.c:88
static uint64_t aml_pci_get_params(aml_state_t *state, aml_opregion_t *opregion, pci_segment_group_t *segmentGroup, pci_bus_t *bus, pci_slot_t *slot, pci_function_t *function)
Definition field_unit.c:180
static void * aml_ensure_mem_is_mapped(uint64_t address, aml_bit_size_t accessSize)
Definition field_unit.c:25
static uint64_t aml_pci_config_read(aml_state_t *state, aml_opregion_t *opregion, uint64_t address, aml_bit_size_t accessSize, uint64_t *out)
Definition field_unit.c:254
uint64_t aml_get_access_size(aml_bit_size_t bitSize, aml_access_type_t accessType, aml_region_space_t regionSpace, aml_bit_size_t *out)
Get the access size in bits for a field.
Definition access_type.c:21
uint64_t aml_bit_size_t
Represents a size in bits within an opregion.
aml_region_space_t
Region Space Encoding.
Definition named.h:30
@ AML_LOCK_RULE_LOCK
Definition named.h:67
@ AML_UPDATE_RULE_PRESERVE
Definition named.h:76
@ AML_UPDATE_RULE_WRITE_AS_ZEROS
Definition named.h:78
@ AML_UPDATE_RULE_WRITE_AS_ONES
Definition named.h:77
@ AML_REGION_PCI_CONFIG
Definition named.h:33
@ AML_REGION_SYSTEM_IO
Definition named.h:32
@ AML_REGION_SYSTEM_MEMORY
Definition named.h:31
aml_object_t * aml_evaluate(aml_state_t *state, aml_object_t *object, aml_type_t targetTypes)
Evaluate an AML object.
Definition evaluate.c:8
uint64_t aml_field_unit_load(aml_state_t *state, aml_field_unit_t *fieldUnit, aml_object_t *out)
Read the value stored in a FieldUnit. FieldUnits include Fields, IndexFields and BankFields.
Definition field_unit.c:610
uint64_t aml_field_unit_store(aml_state_t *state, aml_field_unit_t *fieldUnit, aml_object_t *in)
Write a value to a FieldUnit. FieldUnits include Fields, IndexFields and BankFields.
Definition field_unit.c:637
uint64_t aml_uint_t
AML Integer type.
Definition integer.h:20
uint8_t aml_integer_byte_size(void) PURE
Get the byte size of an AML integer.
Definition integer.c:22
uint64_t aml_mutex_release(aml_mutex_id_t *mutex)
Release a mutex.
Definition mutex.c:115
uint64_t aml_mutex_acquire(aml_mutex_id_t *mutex, aml_sync_level_t syncLevel, clock_t timeout)
Acquire a mutex, blocking until it is available or the timeout is reached.
Definition mutex.c:95
#define AML_NAME_TO_STRING(name)
Macro to convert an aml_name_t to a stack allocated string.
Definition namespace.h:129
#define AML_NAME(a, b, c, d)
Macro to create an aml_name_t from 4 characters.
Definition namespace.h:112
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.
Definition namespace.c:192
aml_type_t
ACPI data types.
Definition object.h:59
aml_object_t * aml_object_new(void)
Allocate a new ACPI object.
Definition object.c:51
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:331
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:513
void aml_object_clear(aml_object_t *object)
Clear the data of a object, setting its type to AML_UNINITIALIZED.
Definition object.c:76
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:392
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:752
@ AML_INTEGER
Definition object.h:67
@ AML_BUFFER
Definition object.h:61
@ AML_FIELD_UNIT_BANK_FIELD
Definition object.h:168
@ AML_FIELD_UNIT_FIELD
Definition object.h:166
@ AML_FIELD_UNIT_INDEX_FIELD
Definition object.h:167
aml_mutex_t * aml_gl_get(void)
Get the global AML mutex.
Definition predefined.c:112
const char * aml_type_to_string(aml_type_t type)
Convert an aml data type to a string.
Definition to_string.c:5
const char * aml_region_space_to_string(aml_region_space_t space)
Convert an aml RegionSpace to a string.
Definition to_string.c:60
static uint16_t in16(port_t port)
Read a 16-bit value from an I/O port.
Definition port.h:107
static void out16(port_t port, uint16_t val)
Write a 16-bit value to an I/O port.
Definition port.h:96
static uint32_t in32(port_t port)
Write a 32-bit value to an I/O port.
Definition port.h:120
static void out8(port_t port, uint8_t val)
Write an 8-bit value to an I/O port.
Definition port.h:72
static uint8_t in8(port_t port)
Read an 8-bit value from an I/O port.
Definition port.h:83
static void out32(port_t port, uint32_t val)
Read a 32-bit value from an I/O port.
Definition port.h:133
static uintptr_t address
Mapped virtual address of the HPET registers.
Definition hpet.c:96
void pci_config_write8(pci_segment_group_t segmentGroup, pci_bus_t bus, pci_slot_t slot, pci_function_t function, uint16_t offset, uint8_t value)
Write a byte to PCI configuration space.
Definition config.c:151
uint8_t pci_function_t
PCI Function Type.
Definition config.h:39
void pci_config_write16(pci_segment_group_t segmentGroup, pci_bus_t bus, pci_slot_t slot, pci_function_t function, uint16_t offset, uint16_t value)
Write a word to PCI configuration space.
Definition config.c:161
uint8_t pci_config_read8(pci_segment_group_t segmentGroup, pci_bus_t bus, pci_slot_t slot, pci_function_t function, uint16_t offset)
Read a byte from PCI configuration space.
Definition config.c:103
uint8_t pci_slot_t
PCI Slot Type.
Definition config.h:34
uint32_t pci_config_read32(pci_segment_group_t segmentGroup, pci_bus_t bus, pci_slot_t slot, pci_function_t function, uint16_t offset)
Read a dword from PCI configuration space.
Definition config.c:135
void pci_config_write32(pci_segment_group_t segmentGroup, pci_bus_t bus, pci_slot_t slot, pci_function_t function, uint16_t offset, uint32_t value)
Write a dword to PCI configuration space.
Definition config.c:176
uint8_t pci_bus_t
PCI Bus Type.
Definition config.h:29
uint16_t pci_segment_group_t
PCI Segment Group Type.
Definition config.h:24
uint16_t pci_config_read16(pci_segment_group_t segmentGroup, pci_bus_t bus, pci_slot_t slot, pci_function_t function, uint16_t offset)
Read a word from PCI configuration space.
Definition config.c:119
#define LOG_ERR(format,...)
Definition log.h:93
uintptr_t phys_addr_t
Physical address type.
#define PML_LOWER_TO_HIGHER(addr)
Converts an address from the lower half to the higher half.
@ PML_PRESENT
@ PML_WRITE
@ PML_GLOBAL
void * vmm_map(space_t *space, void *virtAddr, phys_addr_t physAddr, size_t length, pml_flags_t flags, space_callback_func_t func, void *data)
Maps physical memory to virtual memory in a given address space.
Definition vmm.c:226
#define VMM_IDENTITY_MAPPED_MIN
The minimum address for the identity mapped physical memory.
Definition vmm.h:72
#define UNREF_DEFER(ptr)
RAII-style cleanup for scoped references.
Definition ref.h:122
#define UNREF(ptr)
Decrement reference count.
Definition ref.h:109
#define EINVAL
Invalid argument.
Definition errno.h:142
#define ENOSYS
Function not implemented.
Definition errno.h:222
#define EIO
I/O error.
Definition errno.h:57
#define errno
Error number variable.
Definition errno.h:27
#define ARRAY_SIZE(x)
Get the number of elements in a static array.
Definition defs.h:111
#define UNUSED(x)
Mark a variable as unused.
Definition defs.h:96
size_t write(fd_t fd, const void *buffer, size_t count)
System call for writing to files.
Definition write.c:8
size_t read(fd_t fd, void *buffer, size_t count)
System call for reading from files.
Definition read.c:8
#define MIN(x, y)
Definition math.h:18
#define NULL
Pointer error value.
Definition NULL.h:25
#define ERR
Integer error value.
Definition ERR.h:17
#define PAGE_SIZE
The size of a memory page in bytes.
Definition PAGE_SIZE.h:8
#define CONTAINER_OF(ptr, type, member)
Container of macro.
static size_t location
Definition pmm.c:41
static aml_mutex_t * globalMutex
Definition predefined.c:12
__UINT32_TYPE__ uint32_t
Definition stdint.h:15
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
#define UINT64_MAX
Definition stdint.h:74
__UINT8_TYPE__ uint8_t
Definition stdint.h:11
__UINTPTR_TYPE__ uintptr_t
Definition stdint.h:43
__UINT16_TYPE__ uint16_t
Definition stdint.h:13
aml_lock_rule_t lockRule
Definition named.h:88
aml_access_type_t accessType
Definition named.h:87
aml_update_rule_t updateRule
Definition named.h:89
Data for a field unit object.
Definition object.h:268
aml_opregion_t * opregion
Used for Field and BankField.
Definition object.h:275
aml_object_t * bankValue
Used for BankField.
Definition object.h:273
aml_bit_size_t bitSize
Used for Field, IndexField and BankField.
Definition object.h:278
aml_field_unit_t * bank
Used for BankField.
Definition object.h:274
aml_field_unit_type_t fieldType
The type of field unit.
Definition object.h:270
aml_field_flags_t fieldFlags
Used for Field, IndexField and BankField.
Definition object.h:276
aml_bit_size_t bitOffset
Used for Field, IndexField and BankField.
Definition object.h:277
aml_field_unit_t * index
Used for IndexField.
Definition object.h:271
aml_field_unit_t * data
Used for IndexField.
Definition object.h:272
aml_uint_t value
Definition object.h:288
Data for a mutex object.
Definition object.h:324
aml_mutex_id_t mutex
Definition object.h:327
aml_sync_level_t syncLevel
Definition object.h:326
ACPI object.
Definition object.h:447
aml_integer_t integer
Definition object.h:458
Data for an operation region object.
Definition object.h:345
aml_region_space_t space
Definition object.h:347
uintptr_t offset
Definition object.h:348
uint64_t(* write)(aml_state_t *state, aml_opregion_t *opregion, uint64_t address, aml_bit_size_t accessSize, uint64_t value)
Definition field_unit.c:21
uint64_t(* read)(aml_state_t *state, aml_opregion_t *opregion, uint64_t address, aml_bit_size_t accessSize, uint64_t *out)
Definition field_unit.c:19
AML State.
Definition state.h:25
aml_overlay_t overlay
Holds any named objects created during parsing.
Definition state.h:30