15typedef struct aml_region_handler
25 size_t accessBytes = (accessSize + 7) / 8;
29 for (
uint64_t page = 0; page < (crossesBoundary ? 2 : 1); page++)
35 LOG_ERR(
"failed to map physical address %p for opregion access\n", physAddr);
50 void* virtAddr =
NULL;
67 *out = *(
volatile uint8_t*)virtAddr;
70 *out = *(
volatile uint16_t*)virtAddr;
73 *out = *(
volatile uint32_t*)virtAddr;
76 *out = *(
volatile uint64_t*)virtAddr;
79 LOG_ERR(
"invalid opregion read with access size %u\n", accessSize);
92 void* virtAddr =
NULL;
100 if (virtAddr ==
NULL)
118 *(
volatile uint64_t*)virtAddr = value;
121 LOG_ERR(
"invalid opregion write with access size %u\n", accessSize);
146 LOG_ERR(
"unable to read opregion with access size %u\n", accessSize);
171 LOG_ERR(
"unable to write opregion with access size %u\n", accessSize);
194 if (adrObject !=
NULL)
205 *slot = adrValue & 0x0000FFFF;
206 *function = (adrValue >> 16) & 0x0000FFFF;
211 if (bbnObject !=
NULL)
223 *bus = bbnValue & 0xFF;
228 if (segObject !=
NULL)
240 *segmentGroup = segValue & 0xFFFF;
272 LOG_ERR(
"unable to read PCI config opregion with access size %u\n", accessSize);
303 LOG_ERR(
"unable to write PCI config opregion with access size %u\n", accessSize);
316#define AML_REGION_MAX (sizeof(regionHandlers) / sizeof(regionHandlers[0]))
351 return (bitOffset & ~(accessSize - 1)) / 8;
354typedef enum aml_access_direction
404 LOG_ERR(
"invalid field object type %d\n", fieldUnit->type);
455 LOG_ERR(
"invalid field object type %d\n", fieldUnit->type);
510 while (currentPos < fieldUnit->bitSize)
527 value = (value >> inAccessOffset) & mask;
564 value &= ~(mask << inAccessOffset);
573 value |= (newValue & mask) << inAccessOffset;
583 LOG_ERR(
"invalid field access direction %d\n", direction);
589 currentPos += bitsToAccess;
590 byteOffset += accessSize / 8;
606 if (fieldUnit ==
NULL || out ==
NULL)
633 if (fieldUnit ==
NULL || in ==
NULL)
#define assert(expression)
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)
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)
static aml_region_handler_t regionHandlers[]
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)
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)
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)
static uint64_t aml_get_aligned_byte_offset(aml_bit_size_t bitOffset, aml_bit_size_t accessSize)
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)
static void * aml_ensure_mem_is_mapped(uint64_t address, aml_bit_size_t accessSize)
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)
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)
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)
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)
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)
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)
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.
uint64_t aml_bit_size_t
Represents a size in bits within an opregion.
aml_region_space_t
Region Space Encoding.
@ AML_UPDATE_RULE_PRESERVE
@ AML_UPDATE_RULE_WRITE_AS_ZEROS
@ AML_UPDATE_RULE_WRITE_AS_ONES
@ AML_REGION_SYSTEM_MEMORY
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.
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.
uint64_t aml_integer_t
AML Integer type.
uint8_t aml_integer_byte_size(void) PURE_FUNC
Get the byte size of an AML integer.
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...
uint64_t aml_mutex_release(aml_mutex_id_t *mutex)
Release a mutex.
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.
#define AML_NAME_TO_STRING(name)
Macro to convert an aml_name_t to a stack allocated string.
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.
#define AML_NAME(a, b, c, d)
Macro to create an aml_name_t from 4 characters.
aml_type_t
ACPI data types.
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.
aml_object_t * aml_object_new(void)
Allocate a new ACPI object.
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.
uint64_t aml_buffer_set_empty(aml_object_t *object, uint64_t length)
Set a object as an empty buffer with the given length.
void aml_object_clear(aml_object_t *object)
Clear the data of a object, setting its type to AML_UNINITIALIZED.
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.
@ AML_FIELD_UNIT_BANK_FIELD
@ AML_FIELD_UNIT_INDEX_FIELD
aml_mutex_obj_t * aml_gl_get(void)
Get the global AML mutex.
const char * aml_type_to_string(aml_type_t type)
Convert an aml data type to a string.
const char * aml_region_space_to_string(aml_region_space_t space)
Convert an aml RegionSpace to a string.
static uint8_t port_inb(uint16_t port)
static void port_outl(uint16_t port, uint32_t val)
static uint16_t port_inw(uint16_t port)
static void port_outb(uint16_t port, uint8_t val)
static void port_outw(uint16_t port, uint16_t val)
static uint32_t port_inl(uint16_t port)
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.
uint8_t pci_function_t
PCI Function Type.
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.
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.
uint8_t pci_slot_t
PCI Slot Type.
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.
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.
uint8_t pci_bus_t
PCI Bus Type.
uint16_t pci_segment_group_t
PCI Segment Group Type.
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.
#define LOG_ERR(format,...)
#define PML_LOWER_TO_HIGHER(addr)
Converts an address from the lower half to the higher half.
#define VMM_IDENTITY_MAPPED_MIN
The minimum address for the identity mapped physical memory.
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.
#define DEREF_DEFER(ptr)
RAII-style cleanup for scoped references.
#define EINVAL
Invalid argument.
#define ENOSYS
Function not implemented.
#define errno
Error number variable.
uint64_t read(fd_t fd, void *buffer, uint64_t count)
System call for reading from files.
uint64_t write(fd_t fd, const void *buffer, uint64_t count)
System call for writing to files.
#define PAGE_SIZE
Memory page size.
#define NULL
Pointer error value.
#define ERR
Integer error value.
#define CONTAINER_OF(ptr, type, member)
Container of macro.
static aml_mutex_obj_t * globalMutex
__UINTPTR_TYPE__ uintptr_t
aml_access_type_t accessType
aml_update_rule_t updateRule
Data for a field unit object.
aml_bit_size_t bitOffset
Used for Field, IndexField and BankField.
aml_field_unit_obj_type_t fieldType
The type of field unit.
aml_field_unit_obj_t * bank
Used for BankField.
aml_field_flags_t fieldFlags
Used for Field, IndexField and BankField.
aml_field_unit_obj_t * index
Used for IndexField.
aml_field_unit_obj_t * data
Used for IndexField.
aml_bit_size_t bitSize
Used for Field, IndexField and BankField.
aml_opregion_obj_t * opregion
Used for Field and BankField.
aml_object_t * bankValue
Used for BankField.
aml_sync_level_t syncLevel
aml_integer_obj_t integer
Data for an operation region object.
uint64_t(* write)(aml_state_t *state, aml_opregion_obj_t *opregion, uint64_t address, aml_bit_size_t accessSize, uint64_t value)
uint64_t(* read)(aml_state_t *state, aml_opregion_obj_t *opregion, uint64_t address, aml_bit_size_t accessSize, uint64_t *out)
aml_namespace_overlay_t overlay
Holds any named objects created during parsing.