PatchworkOS  966e257
A non-POSIX operating system.
Loading...
Searching...
No Matches
field_unit.c
Go to the documentation of this file.
2
10
11#include <kernel/cpu/io.h>
12#include <kernel/log/log.h>
13#include <kernel/mem/vmm.h>
14
15#include <errno.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 void* physAddr = (void*)((uintptr_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 (void)state;
50 (void)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 (void)state;
92 (void)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 (void)state;
134 (void)opregion;
135
136 switch (accessSize)
137 {
138 case 8:
139 *out = io_in8(address);
140 break;
141 case 16:
142 *out = io_in16(address);
143 break;
144 case 32:
145 *out = io_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 (void)state;
159 (void)opregion;
160
161 switch (accessSize)
162 {
163 case 8:
164 io_out8(address, (uint8_t)value);
165 break;
166 case 16:
167 io_out16(address, (uint16_t)value);
168 break;
169 case 32:
170 io_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 (void)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 (void)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
324#define AML_REGION_MAX (sizeof(regionHandlers) / sizeof(regionHandlers[0]))
325
327 aml_bit_size_t accessSize, uint64_t* out)
328{
329 if (out == NULL)
330 {
331 errno = EINVAL;
332 return ERR;
333 }
334
335 if (opregion->space >= AML_REGION_MAX || regionHandlers[opregion->space].read == NULL)
336 {
337 LOG_ERR("unimplemented opregion read with opregion space '%s'\n", aml_region_space_to_string(opregion->space));
338 errno = ENOSYS;
339 return ERR;
340 }
341 return regionHandlers[opregion->space].read(state, opregion, address, accessSize, out);
342}
343
345 aml_bit_size_t accessSize, uint64_t value)
346{
347 if (opregion->space >= AML_REGION_MAX || regionHandlers[opregion->space].write == NULL)
348 {
349 LOG_ERR("unimplemented opregion write with opregion space '%s'\n", aml_region_space_to_string(opregion->space));
350 errno = ENOSYS;
351 return ERR;
352 }
353 return regionHandlers[opregion->space].write(state, opregion, address, accessSize, value);
354}
355
357{
358 // Bit manipulation magic to find the byte offset and align it to the access size.
359 return (bitOffset & ~(accessSize - 1)) / 8;
360}
361
362typedef enum aml_access_direction
363{
367
369 uint64_t byteOffset, uint64_t* out)
370{
371 switch (fieldUnit->fieldType)
372 {
375 {
376 aml_opregion_t* opregion = fieldUnit->opregion;
377 uintptr_t address = opregion->offset + byteOffset;
378 return aml_opregion_read(state, opregion, address, accessSize, out);
379 }
381 {
383 if (temp == NULL)
384 {
385 return ERR;
386 }
387 UNREF_DEFER(temp);
388
389 if (aml_integer_set(temp, byteOffset) == ERR)
390 {
391 return ERR;
392 }
393
394 if (aml_field_unit_store(state, fieldUnit->index, temp) == ERR)
395 {
396 return ERR;
397 }
398
399 aml_object_clear(temp);
400
401 if (aml_field_unit_load(state, fieldUnit->data, temp) == ERR)
402 {
403 return ERR;
404 }
405
406 assert(temp->type == AML_INTEGER);
407
408 *out = temp->integer.value;
409 return 0;
410 }
411 default:
412 LOG_ERR("invalid field object type %d\n", fieldUnit->type);
413 errno = EINVAL;
414 return ERR;
415 }
416}
417
419 uint64_t byteOffset, uint64_t value)
420{
421 switch (fieldUnit->fieldType)
422 {
425 {
426 aml_opregion_t* opregion = fieldUnit->opregion;
427 uintptr_t address = opregion->offset + byteOffset;
428 return aml_opregion_write(state, opregion, address, accessSize, value);
429 }
431 {
433 if (temp == NULL)
434 {
435 return ERR;
436 }
437 UNREF_DEFER(temp);
438
439 if (aml_integer_set(temp, byteOffset) == ERR)
440 {
441 return ERR;
442 }
443
444 if (aml_field_unit_store(state, fieldUnit->index, temp) == ERR)
445 {
446 return ERR;
447 }
448
449 aml_object_clear(temp);
450
451 if (aml_integer_set(temp, value) == ERR)
452 {
453 return ERR;
454 }
455
456 if (aml_field_unit_store(state, fieldUnit->data, temp) == ERR)
457 {
458 return ERR;
459 }
460 return 0;
461 }
462 default:
463 LOG_ERR("invalid field object type %d\n", fieldUnit->type);
464 errno = EINVAL;
465 return ERR;
466 }
467}
468
470 aml_access_direction_t direction)
471{
472 // The integer revision handling is enterily done by the aml_get_access_size function, so we dont need to
473 // do anything special here.
474
475 uint64_t result = 0;
477 if (fieldUnit->fieldFlags.lockRule == AML_LOCK_RULE_LOCK)
478 {
481 {
482 return ERR;
483 }
484 }
485
486 /// @todo "An Operation Region object implicitly supports Mutex synchronization. Updates to the object, or a Field
487 /// data object for the region, will automatically synchronize on the Operation Region object;" - Section 19.6.100
488
489 if (fieldUnit->fieldType == AML_FIELD_UNIT_BANK_FIELD)
490 {
491 if (aml_field_unit_store(state, fieldUnit->bank, fieldUnit->bankValue) == ERR)
492 {
493 result = ERR;
494 goto cleanup;
495 }
496 }
497
498 aml_region_space_t regionSpace;
499 if (fieldUnit->fieldType == AML_FIELD_UNIT_INDEX_FIELD)
500 {
501 regionSpace = fieldUnit->data->opregion->space;
502 }
503 else
504 {
505 regionSpace = fieldUnit->opregion->space;
506 }
507
508 aml_bit_size_t accessSize;
509 if (aml_get_access_size(fieldUnit->bitSize, fieldUnit->fieldFlags.accessType, regionSpace, &accessSize) == ERR)
510 {
511 result = ERR;
512 goto cleanup;
513 }
514
515 uint64_t byteOffset = aml_get_aligned_byte_offset(fieldUnit->bitOffset, accessSize);
516
517 uint64_t currentPos = 0;
518 while (currentPos < fieldUnit->bitSize)
519 {
520 aml_bit_size_t inAccessOffset = (fieldUnit->bitOffset + currentPos) & (accessSize - 1);
521 aml_bit_size_t bitsToAccess = MIN(fieldUnit->bitSize - currentPos, accessSize - inAccessOffset);
522 uint64_t mask = (bitsToAccess >= 64) ? UINT64_MAX : ((UINT64_C(1) << bitsToAccess) - 1);
523
524 switch (direction)
525 {
526 case AML_ACCESS_READ:
527 {
528 uint64_t value = 0;
529 if (aml_generic_field_read_at(state, fieldUnit, accessSize, byteOffset, &value) == ERR)
530 {
531 result = ERR;
532 goto cleanup;
533 }
534
535 value = (value >> inAccessOffset) & mask;
536
537 // We treat value as a buffer of 8 bytes.
538 if (aml_object_set_bits_at(data, currentPos, bitsToAccess, (uint8_t*)&value) == ERR)
539 {
540 result = ERR;
541 goto cleanup;
542 }
543 }
544 break;
545 case AML_ACCESS_WRITE:
546 {
547 uint64_t value;
548 switch (fieldUnit->fieldFlags.updateRule)
549 {
551 {
552 if (aml_generic_field_read_at(state, fieldUnit, accessSize, byteOffset, &value) == ERR)
553 {
554 result = ERR;
555 goto cleanup;
556 }
557 }
558 break;
560 value = UINT64_C(-1);
561 break;
563 value = 0;
564 break;
565 default:
566 LOG_ERR("invalid field update rule %d\n", fieldUnit->fieldFlags.updateRule);
567 errno = EINVAL;
568 result = ERR;
569 goto cleanup;
570 }
571
572 value &= ~(mask << inAccessOffset);
573
574 uint64_t newValue;
575 // We treat newValue as a buffer of 8 bytes.
576 if (aml_object_get_bits_at(data, currentPos, bitsToAccess, (uint8_t*)&newValue) == ERR)
577 {
578 result = ERR;
579 goto cleanup;
580 }
581 value |= (newValue & mask) << inAccessOffset;
582
583 if (aml_generic_field_write_at(state, fieldUnit, accessSize, byteOffset, value) == ERR)
584 {
585 result = ERR;
586 goto cleanup;
587 }
588 }
589 break;
590 default:
591 LOG_ERR("invalid field access direction %d\n", direction);
592 errno = EINVAL;
593 result = ERR;
594 goto cleanup;
595 }
596
597 currentPos += bitsToAccess;
598 byteOffset += accessSize / 8;
599 }
600
601cleanup:
602 if (globalMutex != NULL)
603 {
605 {
606 result = ERR;
607 }
608 }
609 return result;
610}
611
613{
614 if (fieldUnit == NULL || out == NULL)
615 {
616 errno = EINVAL;
617 return ERR;
618 }
619
620 uint64_t byteSize = (fieldUnit->bitSize + 7) / 8;
621 if (byteSize > aml_integer_byte_size())
622 {
623 if (aml_buffer_set_empty(out, byteSize) == ERR)
624 {
625 return ERR;
626 }
627 }
628 else
629 {
630 if (aml_integer_set(out, 0) == ERR)
631 {
632 return ERR;
633 }
634 }
635
636 return aml_field_unit_access(state, fieldUnit, out, AML_ACCESS_READ);
637}
638
640{
641 if (fieldUnit == NULL || in == NULL)
642 {
643 errno = EINVAL;
644 return ERR;
645 }
646
647 aml_type_t type = in->type;
648 if (type != AML_INTEGER && type != AML_BUFFER)
649 {
650 LOG_ERR("cannot write to field unit with data of type '%s'\n", aml_type_to_string(type));
651 errno = EINVAL;
652 return ERR;
653 }
654
655 return aml_field_unit_access(state, fieldUnit, in, AML_ACCESS_WRITE);
656}
#define assert(expression)
Definition assert.h:29
#define CLOCKS_NEVER
Definition clock_t.h:16
static fd_t data
Definition dwm.c:21
aml_access_direction_t
Definition field_unit.c:363
@ AML_ACCESS_READ
Definition field_unit.c:364
@ AML_ACCESS_WRITE
Definition field_unit.c:365
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:344
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:326
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:418
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:368
static uint64_t aml_get_aligned_byte_offset(aml_bit_size_t bitOffset, aml_bit_size_t accessSize)
Definition field_unit.c:356
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:469
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
#define AML_REGION_MAX
Definition field_unit.c:324
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
static void io_out8(port_t port, uint8_t val)
Write an 8-bit value to an I/O port.
Definition io.h:71
static void io_out32(port_t port, uint32_t val)
Read a 32-bit value from an I/O port.
Definition io.h:132
static uint16_t io_in16(port_t port)
Read a 16-bit value from an I/O port.
Definition io.h:106
static void io_out16(port_t port, uint16_t val)
Write a 16-bit value to an I/O port.
Definition io.h:95
static uint8_t io_in8(port_t port)
Read an 8-bit value from an I/O port.
Definition io.h:82
static uint32_t io_in32(port_t port)
Write a 32-bit value to an I/O port.
Definition io.h:119
#define LOG_ERR(format,...)
Definition log.h:108
#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:226
#define UNREF_DEFER(ptr)
RAII-style cleanup for scoped references.
Definition ref.h:54
#define UNREF(ptr)
Decrement reference count.
Definition ref.h:80
#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
The size of a memory page in bytes.
Definition proc.h:106
#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.
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:612
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:639
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: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
#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:62
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:351
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:533
void aml_object_clear(aml_object_t *object)
Clear the data of a object, setting its type to AML_UNINITIALIZED.
Definition object.c:96
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:412
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_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 uintptr_t address
Mapped virtual address of the HPET registers.
Definition hpet.c:95
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:152
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:162
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:104
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:136
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:177
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:120
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
#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: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