Skip to content

Rewrite acpi crate and entire AML interpreter #246

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 113 commits into from
Aug 18, 2025

Conversation

IsaacWoods
Copy link
Member

@IsaacWoods IsaacWoods commented Mar 25, 2025

This (entirely too large) PR represents work I've been doing over the last few months to address a large number of bugs in both the acpi and aml crates, and generally improve the quality of the library. While this work is nowhere near complete, it represents the library getting back to a point where I think it is reasonable for projects to use it (in that it is more correct than the current interpreter in all circumstances), and is already too unwieldy to rebase against other PRs that are waiting for review/merging.

For contributors awaiting PRs being merged, I apologise for this derailing your contributions, and I am happy to assist in rebasing your changes/creating new patches with you credited as authors. I will review current PRs when I have time.

Summary of changes

Firstly, the acpi crate has undergone major reworking to simplify logic surrounding table mapping and RSDT enumeration. This should fix #245.

Previous work on allowing fallible allocations has been removed, as it added significant complexity for little real-world gain at this time - if the ecosystem around fallible allocation in Rust improves in the future, I'm not against re-adding these capabilities. The split between the portion of the library that can be used without an allocator vs requiring one has been made clearer, with allocating methods being moved under the higher-level platform module.

This PR also deprecates the aml crate, bringing the interpreter into the acpi crate under a feature-flag. This simplifies the most common use-cases of the library, and was effectively required for ergonomic handling of some AML operations that require us to handle static ACPI tables. Future work with the ACPI event system will likely require closer coupling between the previously-separate parts of the library, as well.

I am imagining that these changes will be published as acpi v6.0.0, with the aml crate being marked as deprecated and receiving no future updates.

Remaining tasks

  • Consider final situation with AcpiHandler vs acpi::aml::Handler - do we want to merge them, make AcpiHandler a supertrait (perhaps being renamed RegionMapper or similar as this is the only functionality it needs to provide)?
  • Change GenericAddress to have arbitrary field widths - apparently required by the PCC (see acpi: add support for PCC table #233)
  • DefVarPackage
  • DefToBuffer
  • DefToInteger
  • DefToString
  • DefToDecimalString
  • DefToHexString
  • Correctly handle references in more places
  • Be more lenient with name collisions (see what other interpreters do)
  • Add pre-defined objects to namespace
  • Handle global lock correctly
  • Fix test runner
  • Fix object mutable access situation
  • Fix Clippy complaints
  • New Readme to reflect new features of the library

Tasks for future PRs

I have decided to push various functionality to future PRs to get this merged as it is a strict improvement on current main.

  • DefMatch
  • DefLoad
  • DefLoadTable
  • DefDataRegion
  • Connect fields
  • Extended access fields
  • Custom field address space handlers
  • Handle bank and index field accesses
  • Proper support for DefStore vs DefCopyObject
  • GPE handling and mechanism to enter ACPI mode
  • Proper event handling and related opcodes (DefNotify etc)

Feedback

I would welcome feedback on the new APIs, crate layout, or changes I should consider before publishing a new major version of acpi. I particularly welcome feedback + bug-reports from people who have integrated acpi into a kernel or other project.

cc @rw-vanc - I would be interested in any concerns re Redox moving to the new version of the crate, and any further work you'd be interested in.
cc @usadson - this should fix #245. Thank you for your report.

I don't really understand why this had a lifetime instead of constructing
the slice for the lifetime of `self`, but this cleans stuff up a fair bit
both in the library and for users.
Still need to do a bunch of bit fiddling stuff to facilitate actually reading
and storing to them.
IsaacWoods added 14 commits July 7, 2025 13:41
This is required for various special address space types (e.g. the PCC)
This was unneeded complexity in the end and came unstuck when we realised
the library needs to do I/O port accesses for register accesses. Users can
just not implement parts of the API they're unable/will not use and deal with
the consequences.

Also catches changes to cache a mapping to the FACS in the AML interpreter.
This requires the AML interpreter to have access to the fixed hardware
registers, and so changes the convenience initialization method to take
a `AcpiPlatform` instead of just the tables. I think this is fine in the
long run - users can still manually construct an interpreter if needed.
@IsaacWoods IsaacWoods merged commit 806093c into rust-osdev:main Aug 18, 2025
5 checks passed
@IsaacWoods
Copy link
Member Author

IsaacWoods commented Aug 18, 2025

🚀
Merged and published as acpi v6.0.0-pre.0 as this is already a strict improvement on the previous library. I'm not sure how much time I'll have in the coming months due to work commitments so thought this was better than leaving this PR in limbo for any longer.

Further work will be needed to support remaining opcodes, support correct behaviour of various existing bits of the library, and other bits. These can hopefully be done as non-breaking changes in the first instance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Invalid safety assumption in SdtHeaderIterator
4 participants