Skip to content
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

acpi: Add SdtHeaderIterator to get all headers. #202

Merged
merged 2 commits into from Mar 13, 2024

Conversation

fslongjin
Copy link
Contributor

This PR add SdtHeaderIterator to get all sdt headers.

@fslongjin
Copy link
Contributor Author

ping for code review~

Copy link
Member

@IsaacWoods IsaacWoods left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies for the delay in reviewing this!

Overall this looks reasonable, and I have no particular issues with exposing this functionality. Mainly out of interest - do you have a particular usecase for iterating through the headers particularly?

Also worth considering is that we currently have the internal TablesPhysPtrsIter iterator that gives us a more general view of each table as a pointer to the header - I wonder if we could clean that up (i.e. make it a concrete type) and use it to expose this sort of functionality (this would effectively be a map over it to extract each header)? Not too fussed either way though.

acpi/src/lib.rs Outdated
};
let r = header_mapping.validate(header_mapping.signature);
if r.is_err() {
log::warn!("Found invalid SSDT at physical address {:p}: {:?}", table_phys_ptr, r);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SSDTs are a specific type of table - this should probably be SDT to refer to any sort of ACPI table

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok~ I'll fix it.

@fslongjin
Copy link
Contributor Author

Overall this looks reasonable, and I have no particular issues with exposing this functionality. Mainly out of interest - do you have a particular usecase for iterating through the headers particularly?

Sure! I've used it in my hobby OS to generate attributes in sysfs: https://opengrok.ringotek.cn/xref/DragonOS/kernel/src/driver/acpi/sysfs.rs?r=7eda31b2f07c6ef41dc0d2bd13051f0fce5e5976#108

@IsaacWoods
Copy link
Member

Thanks, and thanks for providing your usecase! My understanding is that the sysfs files on Linux allow you to read the whole table, not just the header - are you intending to provide the same functionality in your OS? If so, I wonder if building out the generic functionality (i.e. iterating over whole tables, probably then with an adapter for just iterating headers) would be better for your usecase (and in general)?

If so, you can either do that in this PR, or if you're not sure what I'm going for, I'm happy to give it a go (and would add you as a co-author to those commits :)). Lmk.

@fslongjin
Copy link
Contributor Author

My understanding is that the sysfs files on Linux allow you to read the whole table, not just the header. - are you intending to provide the same functionality in your OS?

Yes, but during the development process, I read the acpi-rs code and didn't think about how to implement functionality more reasonably within this crate. The reasons are:

  1. Due to my limited understanding of ACPI, I am worried that saving the complete mapping of all ACPI Tables all the time might not be optimal for some systems.
  2. I think it's a bad idea if we save copies of all tables.

What do you think we should do?

@fslongjin
Copy link
Contributor Author

ping

@IsaacWoods
Copy link
Member

Hey, thanks for working on this and apologies for the slow reviews.

I'm going to merge this as is but not release a new version just yet, just so it can potentially be reworked in a larger refactor of the table iterators at a later date. You can still use it from a fork / git dependency on this repo, and it'll be released with the next version when that happens :)

Due to my limited understanding of ACPI, I am worried that saving the complete mapping of all ACPI Tables all the time might not be optimal for some systems.

For most kernels, this is not a big problem (if you have a direct memory map of physical memory it's literally a no-op) imo. Even cloning all the tables is not a huge deal, as they don't tend to be massive (especially if you leave out of the AML ones (DSDT and SSDTs)).

@IsaacWoods IsaacWoods merged commit dc11078 into rust-osdev:main Mar 13, 2024
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.

None yet

2 participants