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