972
edits
[unchecked revision] | [unchecked revision] |
m (Bot: Replace deprecated source tag with syntaxhighlight) |
|||
(8 intermediate revisions by 2 users not shown) | |||
Line 35:
Below is an example of basic uACPI initialization sequence that enters ACPI mode, parses tables, brings the event system online, and finally loads & initializes the namespace.
<
#include <uacpi/uacpi.h>
#include <uacpi/event.h>
Line 53:
/*
* Set
*/
.
▲ * okay for now since we're just getting started. We can change this
▲ * to INFO later on, which is the recommended level for release
▲ * builds. There's also the loudest UACPI_LOG_DEBUG log level, which
▲ * is recommended to pin down lockups or hangs.
};
Line 123 ⟶ 118:
return 0;
}
</syntaxhighlight>
== Code examples ==
Line 135 ⟶ 130:
so that it's called by kernel code during initialization.
<
// ps2k.c
#include <uacpi/utilities.h>
Line 167 ⟶ 162:
uacpi_find_devices(PS2K_PNP_ID, match_ps2k, NULL);
}
</syntaxhighlight>
<
// acpi_init.c
void find_acpi_devices(void) {
Line 178 ⟶ 173:
// ...and more
}
</syntaxhighlight>
As you can see it's a very simple approach, but it has lots of drawbacks:
Line 189 ⟶ 184:
In this approach, we treat the ACPI namespace as a bus in our kernel, and let devices provide a way to identify them.
<
// acpi_bus.h
#include <uacpi/uacpi.h>
#include <uacpi/namespace.h>
#include <uacpi/utilities.h>▼
#include <uacpi/resources.h>▼
struct acpi_driver {
Line 203 ⟶ 200:
void acpi_register_driver(struct acpi_driver *driver);
</syntaxhighlight>
▲<source lang="c">
// ps2k.c
#include <acpi_bus.h>
▲#include <uacpi/resources.h>
#define PS2K_PNP_ID "PNP0303"
Line 229 ⟶ 223:
* well!
*/
uacpi_status
if (uacpi_unlikely_error(
log_error("unable to retrieve PS2K resources: %s", uacpi_status_to_string(
return -ENODEV;
}
Line 256 ⟶ 250:
{
acpi_register_driver(&ps2k_driver);
return 0;
}
</syntaxhighlight>
<
// acpi_bus.c
#include <acpi_bus.h>
▲#include <uacpi/utilities.h>
static struct acpi_driver *acpi_drivers_head
void acpi_register_driver(struct acpi_driver *driver)
Line 280 ⟶ 273:
uacpi_status ret = uacpi_get_namespace_node_info(node, &info);
if (uacpi_unlikely_error(ret)) {
const char *path = uacpi_namespace_node_generate_absolute_path(node);
log_error("unable to retrieve node %
uacpi_free_absolute_path(path);
return UACPI_NS_ITERATION_DECISION_CONTINUE;
}
Line 293 ⟶ 288:
struct acpi_driver *drv = NULL;
if (info->
// Match the HID against every existing acpi_driver pnp id list
}
if (drv == NULL && (info->
// Match the CID list against every existing acpi_driver pnp id list
}
Line 316 ⟶ 311:
);
}
</syntaxhighlight>
As you can see above, this approach is more scalable, faster, and involves way less code duplication.
Line 322 ⟶ 317:
=== Shutting Down the System ===
<
#include <uacpi/sleep.h>
Line 362 ⟶ 357:
return 0;
}
</syntaxhighlight>
=== Hooking Up the Power Button ===
Line 368 ⟶ 363:
The example below hooks up the power button press using a fixed event callback.
<
#include <uacpi/event.h>
Line 401 ⟶ 396:
return 0;
}
</syntaxhighlight>
Note that some of the more modern hardware routes the power button in a more complicated way, via an embedded controller.
|