17typedef struct aml_region_handler
27 size_t accessBytes = (accessSize + 7) / 8;
31 for (
uint64_t page = 0; page < (crossesBoundary ? 2 : 1); page++)
37 LOG_ERR(
"failed to map physical address %p for opregion access\n", physAddr);
52 void* virtAddr =
NULL;
69 *out = *(
volatile uint8_t*)virtAddr;
72 *out = *(
volatile uint16_t*)virtAddr;
75 *out = *(
volatile uint32_t*)virtAddr;
78 *out = *(
volatile uint64_t*)virtAddr;
81 LOG_ERR(
"invalid opregion read with access size %u\n", accessSize);
94 void* virtAddr =
NULL;
102 if (virtAddr ==
NULL)
120 *(
volatile uint64_t*)virtAddr = value;
123 LOG_ERR(
"invalid opregion write with access size %u\n", accessSize);
148 LOG_ERR(
"unable to read opregion with access size %u\n", accessSize);
173 LOG_ERR(
"unable to write opregion with access size %u\n", accessSize);
196 if (adrObject !=
NULL)
201 if (adrResult ==
NULL)
209 *slot = adrValue & 0x0000FFFF;
210 *function = (adrValue >> 16) & 0x0000FFFF;
215 if (bbnObject !=
NULL)
220 if (bbnResult ==
NULL)
229 *bus = bbnValue & 0xFF;
234 if (segObject !=
NULL)
239 if (segResult ==
NULL)
248 *segmentGroup = segValue & 0xFFFF;
280 LOG_ERR(
"unable to read PCI config opregion with access size %u\n", accessSize);
311 LOG_ERR(
"unable to write PCI config opregion with access size %u\n", accessSize);
324#define AML_REGION_MAX (sizeof(regionHandlers) / sizeof(regionHandlers[0]))
359 return (bitOffset & ~(accessSize - 1)) / 8;
362typedef enum aml_access_direction
412 LOG_ERR(
"invalid field object type %d\n", fieldUnit->type);
463 LOG_ERR(
"invalid field object type %d\n", fieldUnit->type);
518 while (currentPos < fieldUnit->bitSize)
535 value = (value >> inAccessOffset) & mask;
572 value &= ~(mask << inAccessOffset);
581 value |= (newValue & mask) << inAccessOffset;
591 LOG_ERR(
"invalid field access direction %d\n", direction);
597 currentPos += bitsToAccess;
598 byteOffset += accessSize / 8;
614 if (fieldUnit ==
NULL || out ==
NULL)
641 if (fieldUnit ==
NULL || in ==
NULL)
#define assert(expression)
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)
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)
static aml_region_handler_t regionHandlers[]
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)
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)
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)
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)
static uint64_t aml_get_aligned_byte_offset(aml_bit_size_t bitOffset, aml_bit_size_t accessSize)
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)
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)
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)
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)
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)
static void * aml_ensure_mem_is_mapped(uint64_t address, aml_bit_size_t accessSize)
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)
static void io_out8(port_t port, uint8_t val)
Write an 8-bit value to an I/O port.
static void io_out32(port_t port, uint32_t val)
Read a 32-bit value from an I/O port.
static uint16_t io_in16(port_t port)
Read a 16-bit value from an I/O port.
static void io_out16(port_t port, uint16_t val)
Write a 16-bit value to an I/O port.
static uint8_t io_in8(port_t port)
Read an 8-bit value from an I/O port.
static uint32_t io_in32(port_t port)
Write a 32-bit value to an I/O port.
#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 UNREF_DEFER(ptr)
RAII-style cleanup for scoped references.
#define UNREF(ptr)
Decrement reference count.
#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
The size of a memory page in bytes.
#define NULL
Pointer error value.
#define ERR
Integer error value.
#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.
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
aml_object_t * aml_evaluate(aml_state_t *state, aml_object_t *object, aml_type_t targetTypes)
Evaluate an AML object.
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.
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.
uint64_t aml_uint_t
AML Integer type.
uint8_t aml_integer_byte_size(void) PURE
Get the byte size of an AML integer.
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.
#define AML_NAME(a, b, c, d)
Macro to create an aml_name_t from 4 characters.
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.
aml_type_t
ACPI data types.
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.
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.
@ AML_FIELD_UNIT_BANK_FIELD
@ AML_FIELD_UNIT_INDEX_FIELD
aml_mutex_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 uintptr_t address
Mapped virtual address of the HPET registers.
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.
static aml_mutex_t * globalMutex
__UINTPTR_TYPE__ uintptr_t
aml_access_type_t accessType
aml_update_rule_t updateRule
Data for a field unit object.
aml_opregion_t * opregion
Used for Field and BankField.
aml_object_t * bankValue
Used for BankField.
aml_bit_size_t bitSize
Used for Field, IndexField and BankField.
aml_field_unit_t * bank
Used for BankField.
aml_field_unit_type_t fieldType
The type of field unit.
aml_field_flags_t fieldFlags
Used for Field, IndexField and BankField.
aml_bit_size_t bitOffset
Used for Field, IndexField and BankField.
aml_field_unit_t * index
Used for IndexField.
aml_field_unit_t * data
Used for IndexField.
aml_sync_level_t syncLevel
Data for an operation region object.
uint64_t(* write)(aml_state_t *state, aml_opregion_t *opregion, uint64_t address, aml_bit_size_t accessSize, uint64_t value)
uint64_t(* read)(aml_state_t *state, aml_opregion_t *opregion, uint64_t address, aml_bit_size_t accessSize, uint64_t *out)
aml_overlay_t overlay
Holds any named objects created during parsing.