UACPI: Difference between revisions

199 bytes added ,  29 days ago
m
Bot: Replace deprecated source tag with syntaxhighlight
[unchecked revision][unchecked revision]
m (Bot: Replace deprecated source tag with syntaxhighlight)
 
(3 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.
 
<sourcesyntaxhighlight lang="c">
#include <uacpi/uacpi.h>
#include <uacpi/event.h>
Line 51:
*/
.rsdp = rsdp_phys_addr,
 
 
/*
Line 119 ⟶ 118:
return 0;
}
</syntaxhighlight>
</source>
 
== Code examples ==
Line 131 ⟶ 130:
so that it's called by kernel code during initialization.
 
<sourcesyntaxhighlight lang="c">
// ps2k.c
#include <uacpi/utilities.h>
Line 163 ⟶ 162:
uacpi_find_devices(PS2K_PNP_ID, match_ps2k, NULL);
}
</syntaxhighlight>
</source>
 
<sourcesyntaxhighlight lang="c">
// acpi_init.c
void find_acpi_devices(void) {
Line 174 ⟶ 173:
// ...and more
}
</syntaxhighlight>
</source>
 
As you can see it's a very simple approach, but it has lots of drawbacks:
Line 185 ⟶ 184:
In this approach, we treat the ACPI namespace as a bus in our kernel, and let devices provide a way to identify them.
 
<sourcesyntaxhighlight lang="c">
// acpi_bus.h
#include <uacpi/uacpi.h>
Line 201 ⟶ 200:
 
void acpi_register_driver(struct acpi_driver *driver);
</syntaxhighlight>
</source>
 
<sourcesyntaxhighlight lang="c">
// ps2k.c
#include <acpi_bus.h>
Line 253 ⟶ 252:
return 0;
}
</syntaxhighlight>
</source>
 
<sourcesyntaxhighlight lang="c">
// acpi_bus.c
#include <acpi_bus.h>
Line 289 ⟶ 288:
struct acpi_driver *drv = NULL;
 
if (info->has_hidflags & UACPI_NS_NODE_INFO_HAS_HID) {
// Match the HID against every existing acpi_driver pnp id list
}
 
if (drv == NULL && (info->has_cidflags & UACPI_NS_NODE_INFO_HAS_CID)) {
// Match the CID list against every existing acpi_driver pnp id list
}
Line 312 ⟶ 311:
);
}
</syntaxhighlight>
</source>
 
As you can see above, this approach is more scalable, faster, and involves way less code duplication.
Line 318 ⟶ 317:
 
=== Shutting Down the System ===
<sourcesyntaxhighlight lang="c">
#include <uacpi/sleep.h>
 
Line 358 ⟶ 357:
return 0;
}
</syntaxhighlight>
</source>
 
=== Hooking Up the Power Button ===
Line 364 ⟶ 363:
The example below hooks up the power button press using a fixed event callback.
 
<sourcesyntaxhighlight lang="c">
#include <uacpi/event.h>
 
Line 397 ⟶ 396:
return 0;
}
</syntaxhighlight>
</source>
 
Note that some of the more modern hardware routes the power button in a more complicated way, via an embedded controller.