|
PatchworkOS
2ca1c69
A non-POSIX operating system.
|
Device and Power Management. More...
Device and Power Management.
Handles enumeration and configuration of ACPI devices, along with dynamic loading of device drivers.
Each device found under the \_SB namespace with a _HID method will have its HID collected and the module system will be notified that a device with that HID exists, if there is no module supporting that HID then the devices _CID method will be evaluated (if it exists) and the module system will be notified of the CID returned by that method.
Processor Container Devices (HID "ACPI0010") are ignored as their use is deprecated so even if the hardware provides them, we dont want to use them. Its also possible that certain devices such as the HPET are not reported even if they exist, in these cases we manually check for them and add their HIDs.
The difference between HIDs and CIDs is that HIDs are unique identifiers for the specific device type, while CIDs are more generic identifiers. Its the difference between a specific model of network card and just a generic network card.
Trying HIDs first and CIDs after means we try to load a module for the exact device, or if that fails a generic module that can handle the device, tho perhaps not optimally.
Each ACPI device specifies the resources it needs via its AML, for example via the _CRS method. This can include IRQs, IO ports, etc. During device initialization, this data is parsed and the necessary resources are allocated and configured for the device.
For the sake of ensuring consistency across different systems, all modules will be loaded based on their ACPI HIDs or CIDs in alphanumerical order, this also applies to device configuration. This means that a device with the ACPI HID "ACPI0001" will be loaded before a device with the ACPI HID "ACPI0002" and that one before the device with the ACPI HID "PNP0000". This only applies to the module loading and device configuration but not to device enumeration.
Data Structures | |
| struct | acpi_device_irq_t |
| Represents a IRQ assigned to an ACPI device. More... | |
| struct | acpi_device_io_t |
| Represents an IO port range assigned to an ACPI device. More... | |
| struct | acpi_device_cfg_t |
| ACPI device configuration structure. More... | |
Macros | |
| #define | ACPI_STA_FLAGS_DEFAULT (ACPI_STA_PRESENT | ACPI_STA_ENABLED | ACPI_STA_SHOW_IN_UI | ACPI_STA_FUNCTIONAL) |
| Default _STA flags if the _STA method does not exist. | |
Enumerations | |
| enum | acpi_sta_flags_t { ACPI_STA_PRESENT = 1 << 0 , ACPI_STA_ENABLED = 1 << 1 , ACPI_STA_SHOW_IN_UI = 1 << 2 , ACPI_STA_FUNCTIONAL , ACPI_STA_BATTERY_PRESENT = 1 << 4 } |
| Flags for the _STA method. More... | |
Functions | |
| uint64_t | acpi_devices_init (void) |
| Enumerate, configure and load modules for ACPI devices. | |
| 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_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. | |
| #define ACPI_STA_FLAGS_DEFAULT (ACPI_STA_PRESENT | ACPI_STA_ENABLED | ACPI_STA_SHOW_IN_UI | ACPI_STA_FUNCTIONAL) |
| enum acpi_sta_flags_t |
Flags for the _STA method.
| uint64_t acpi_devices_init | ( | void | ) |
Enumerate, configure and load modules for ACPI devices.
This function always evaluates the _SB._INI node if it exists, enumerates ACPI devices (found under _SB), evaluates their _STA object retrieving its present and functional status (if it exists) and then evaluates their _INI object according to these rules:
ERR. Definition at line 480 of file devices.c.
| acpi_device_cfg_t * acpi_device_cfg_lookup | ( | const char * | name | ) |
Retrieves the ACPI device configuration for a device by its name.
| name | The name of the device to retrieve the configuration for. |
NULL and errno is set to:EINVAL: Invalid parameters.ENOENT: The specified name does not exist in the ACPI namespace.ENOTTY: The specified name is not a device.ENODEV: The specified device has no configuration. Definition at line 567 of file devices.c.
| 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.
Useful as each IO entry contains a base and length, making it rather complex to just, for example, get the 5th port.
| cfg | The device configuration to retrieve the port from. |
| index | The index of the IO port to retrieve. |
| out | Output pointer to store the retrieved port. |
0. On failure, ERR and errno is set to:EINVAL: Invalid parameters.ENOSPC: The specified index is out of bounds. Definition at line 603 of file devices.c.