64 if (staResult ==
NULL)
99 if (hid ==
NULL || hid[0] ==
'\0')
105 if (newArray ==
NULL)
109 ids->
array = newArray;
151 if (hidResult ==
NULL)
162 if (
strcmp(deviceId.
hid,
"ACPI0010") == 0)
173 if (cidResult ==
NULL)
198 LOG_ERR(
"failed to find \\_SB_ in namespace\n");
211 LOG_INFO(
"\\_SB_ is not present, skipping initialization\n");
221 if (iniResult ==
NULL)
223 LOG_ERR(
"failed to evaluate \\_SB_._INI\n");
244 if (written < 0 || written >=
MAX_PATH)
263 if (iniResult ==
NULL)
265 LOG_ERR(
"failed to evaluate %s._INI\n", childPath);
293 const char* a = aPtr->
hid;
299 const char* b = bPtr->
hid;
306 while (*a && *b && ((*a <
'0' || *a >
'9') && (*a <
'A' || *a >
'F')) &&
307 ((*b <
'0' || *b >
'9') && (*b <
'A' || *b >
'F')))
311 return (
unsigned char)*a - (
unsigned char)*b;
351 LOG_DEBUG(
"skipping configuration for fake ACPI device '%s'\n", name);
358 LOG_ERR(
"failed to find ACPI device '%s' in namespace for configuration\n", name);
365 LOG_ERR(
"ACPI object '%s' is not a device, cannot configure\n", name);
372 LOG_DEBUG(
"ACPI device '%s' is already configured, skipping\n", name);
383 if (resources ==
NULL)
390 LOG_ERR(
"failed to get current resources for ACPI device '%s' due to '%s'\n", name,
strerror(
errno));
412 if (!((desc->
mask >> phys) & 1))
420 LOG_ERR(
"failed to allocate virtual IRQ for ACPI device '%s' due to '%s'\n", name,
strerror(
errno));
427 LOG_ERR(
"failed to allocate memory for IRQs for ACPI device '%s' due to '%s'\n", name,
447 LOG_ERR(
"failed to allocate memory for IO ports for ACPI device '%s' due to '%s'\n", name,
456 LOG_ERR(
"failed to reserve IO ports for ACPI device '%s' due to '%s'\n", name,
strerror(
errno));
492 LOG_ERR(
"failed to initialize ACPI devices\n");
497 LOG_DEBUG(
"initializing ACPI devices under \\_SB_\n");
500 LOG_ERR(
"failed to initialize ACPI devices\n");
511 LOG_ERR(
"failed to initialize ACPI devices\n");
520 LOG_ERR(
"failed to initialize ACPI devices\n");
530 for (
size_t i = 0; i < ids.
length; i++)
542 for (
size_t i = 0; i < ids.
length; i++)
545 if (loadedModules ==
ERR)
551 if (loadedModules != 0 || ids.
array[i].
cid[0] ==
'\0')
557 if (loadedModules ==
ERR)
580 LOG_ERR(
"failed to find ACPI device '%s' in namespace for configuration retrieval\n", name);
588 LOG_ERR(
"ACPI object '%s' is not a device, cannot retrieve configuration\n", name);
595 LOG_ERR(
"ACPI device '%s' is not configured\n", name);
615 *out = cfg->
ios[i].
base + index;
#define MAX_NAME
Maximum length of names.
#define MAX_PATH
Maximum length of filepaths.
static uint64_t acpi_id_object_to_string(aml_object_t *idObject, char *out, size_t outSize)
static uint64_t acpi_ids_push_if_absent(acpi_ids_t *ids, const char *hid, const char *path)
static uint64_t acpi_ids_push(acpi_ids_t *ids, const char *hid, const char *cid, const char *path)
static void acpi_device_cfg_free(acpi_device_cfg_t *cfg)
static int acpi_id_compare(const void *left, const void *right)
static uint64_t acpi_ids_push_device(acpi_ids_t *ids, aml_object_t *device, const char *path)
static uint64_t acpi_device_init_children(acpi_ids_t *ids, aml_object_t *device, const char *path)
static uint64_t acpi_device_configure(const char *name)
static uint64_t acpi_sta_get_flags(aml_object_t *device, acpi_sta_flags_t *out)
static aml_object_t * acpi_sb_init(void)
uint64_t io_reserve(port_t *out, port_t minBase, port_t maxBase, uint64_t alignment, uint64_t length, const char *owner)
Find and reserve a range of I/O ports if available.
void io_release(port_t base, uint64_t length)
Release a previously reserved range of I/O ports.
uint16_t port_t
I/O port type.
void irq_virt_free(irq_virt_t virt)
Free a previously allocated virtual IRQ.
uint32_t irq_phys_t
Physical IRQ numbers.
uint64_t irq_virt_alloc(irq_virt_t *out, irq_phys_t phys, irq_flags_t flags, cpu_t *cpu)
Allocate a virtual IRQ mapped to the given physical IRQ.
uint8_t irq_virt_t
Virtual IRQ numbers.
@ IRQ_TRIGGER_EDGE
If set, the IRQ is edge triggered. Otherwise, level triggered.
@ IRQ_POLARITY_HIGH
If set, the IRQ is active high.
@ IRQ_SHARED
If set, the IRQ is shared.
@ IRQ_TRIGGER_LEVEL
If set, the IRQ is level triggered.
@ IRQ_POLARITY_LOW
If set, the IRQ is active low. Otherwise, active high.
@ IRQ_EXCLUSIVE
If set, the IRQ is exclusive (not shared).
#define LOG_ERR(format,...)
#define LOG_INFO(format,...)
#define LOG_DEBUG(format,...)
uint64_t module_device_attach(const char *type, const char *name, module_load_flags_t flags)
Notify the module system of a device being attached.
@ MODULE_LOAD_ONE
If set, will load only the first module matching the device type.
#define MUTEX_SCOPE(mutex)
Acquires a mutex for the reminder of the current scope.
#define UNREF_DEFER(ptr)
RAII-style cleanup for scoped references.
#define REF(ptr)
Increment reference count.
#define UNREF(ptr)
Decrement reference count.
#define ENOENT
No such file or directory.
#define ENOSPC
No space left on device.
#define EINVAL
Invalid argument.
#define errno
Error number variable.
#define ENODEV
No such device.
#define ENOTTY
Not a typewriter.
#define EILSEQ
Illegal byte sequence.
#define LIST_FOR_EACH(elem, list, member)
Iterates over a list.
#define NULL
Pointer error value.
#define ERR
Integer error value.
aml_object_t * aml_evaluate(aml_state_t *state, aml_object_t *object, aml_type_t targetTypes)
Evaluate an AML object.
uint64_t aml_uint_t
AML Integer type.
#define AML_NAME_TO_STRING(name)
Macro to convert an aml_name_t to a stack allocated string.
aml_object_t * aml_namespace_find_by_path(aml_overlay_t *overlay, aml_object_t *start, const char *path)
Find an object in the namespace heirarchy by a path string.
#define AML_NAME(a, b, c, d)
Macro to create an aml_name_t from 4 characters.
aml_object_t * aml_namespace_find_child(aml_overlay_t *overlay, aml_object_t *parent, aml_name_t name)
Find a child object directly under a parent object in the namespace heirarchy.
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.
uint64_t aml_eisa_id_to_string(uint32_t eisaId, char *buffer, size_t bufferSize)
Convert a numeric EISA ID to a string EISA ID.
const char * aml_type_to_string(aml_type_t type)
Convert an aml data type to a string.
mutex_t * aml_big_mutex_get(void)
Get the mutex for the entire AML subsystem.
acpi_device_cfg_t * acpi_device_cfg_lookup(const char *name)
Retrieves the ACPI device configuration for a device by its name.
uint64_t acpi_devices_init(void)
Enumerate, configure and load modules for ACPI devices.
uint64_t acpi_device_cfg_get_port(acpi_device_cfg_t *cfg, uint64_t index, port_t *out)
Retrieves an the nth IO port assigned to an ACPI device.
acpi_sta_flags_t
Flags for the _STA method.
#define ACPI_STA_FLAGS_DEFAULT
Default _STA flags if the _STA method does not exist.
@ ACPI_STA_BATTERY_PRESENT
Set if a battery is present.
@ ACPI_STA_SHOW_IN_UI
Set if the device should be shown in the UI.
@ ACPI_STA_PRESENT
Set if the device is present.
@ ACPI_STA_FUNCTIONAL
Set if the device is functioning properly (cleared if device failed its diagnostics)
@ ACPI_STA_ENABLED
Set if the device is enabled and decoding its resources.
#define ACPI_IRQ_DESCRIPTOR_INFO(descriptor)
Retrieves the IRQ descriptor info flags from an IRQ resource descriptor.
#define ACPI_RESOURCES_FOR_EACH(resource, resources)
Helper macro to iterate over all resource descriptors in an ACPI resources structure.
#define ACPI_RESOURCE_ITEM_NAME(resource)
Helper macro to get the generic item name of a resource descriptor.
acpi_irq_descriptor_info_t
ACPI IRQ descriptor info flags.
acpi_resources_t * acpi_resources_current(aml_object_t *device)
Get the current ACPI resource settings for a device.
acpi_item_name_t
Generic ACPI resource item names.
@ ACPI_IRQ_EDGE_TRIGGERED
Interrupt is triggered in response to a change in signal state from low to high.
@ ACPI_IRQ_EXCLUSIVE
This interrupt is not shared with other devices.
@ ACPI_IRQ_ACTIVE_LOW
This interrupt is sampled with the signal is low, or false.
sdt_header_t * acpi_tables_lookup(const char *signature, uint64_t minSize, uint64_t n)
Lookup the n'th table matching the signature.
static const path_flag_t flags[]
_PUBLIC int sscanf(const char *_RESTRICT s, const char *_RESTRICT format,...)
_PUBLIC int snprintf(char *_RESTRICT s, size_t n, const char *_RESTRICT format,...)
_PUBLIC void * realloc(void *ptr, size_t size)
_PUBLIC void qsort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *))
_PUBLIC void * calloc(size_t nmemb, size_t size)
_PUBLIC void free(void *ptr)
_PUBLIC char * strerror(int errnum)
_PUBLIC void * memmove(void *_RESTRICT s1, const void *_RESTRICT s2, size_t n)
_PUBLIC int strcmp(const char *s1, const char *s2)
errno_t strncpy_s(char *_RESTRICT s1, rsize_t s1max, const char *_RESTRICT s2, rsize_t n)
ACPI device configuration structure.
Represents an IO port range assigned to an ACPI device.
Represents a IRQ assigned to an ACPI device.
ACPI IO port resource descriptor.
uint8_t alignment
Alignment of the IO port(s) to utilize within the min and max range.
uint16_t minBase
Minimum base IO port address that may be used for the device.
uint16_t maxBase
Maximum base IO port address that may be used for the device.
uint8_t length
The amount of contiguous IO ports required by the device.
ACPI IRQ resource descriptor.
uint16_t mask
Mask of IRQs used by the device, bit 0 = IRQ 0, bit 1 = IRQ 1, etc..
Generic ACPI resource descriptor.
ACPI resources structure.