Skip to content

Introduce a NodeId type - #50

Merged
repnop merged 1 commit into
repnop:mainfrom
bjorn3:node_id
Sep 29, 2026
Merged

repnop merged 1 commit into
repnop:mainfrom
bjorn3:node_id

Conversation

@bjorn3

@bjorn3 bjorn3 commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

This can be used to check if two Node's are actually the same node. And it can be used as BTreeMap or HashMap key to map from a Node to OS data associated with this device like the active driver.

Comment thread src/nodes.rs
let node_addr = (self.this as *const RawNode<<P as Parser<'a>>::Granularity>).addr();
let strings_addr = self.strings.0.as_ptr().addr();
NodeId(strings_addr - node_addr)
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Alternatively the Node could gain an index field which is filled with the amount of nodes before the current node. This would make the Node type a bit larger though.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I like the addition of a NodeId but using the pointer values feels a bit odd—though given that addresses are committed to being stable by this point, I suppose it doesn't really matter much what the addresses are. any scenarios that you could see this causing an issue? my mind is vaguely concerned about interactions with some future APIs but having a difficult time coming up with anything concrete given the data is supposed to be read-only at this stage.

@bjorn3 bjorn3 Aug 18, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, if you ever add a mutation API, the current implementation would be problematic. In that case either the docs of .id() could be updated to indicate that edits invalidate all ids (presumably a kernel would only use it for overlays, which are applied before drivers start), or you could store NodeIds directly in the tree (assuming you expand the dtb to a heap allocated tree for easier edits)

@bjorn3

bjorn3 commented Jun 14, 2026 •

Copy link
Copy Markdown
Contributor Author

I figured out an alternative for my purposes. I could still see it useful for others though.
Edit: Although the case of a missing interrupt-parent does complicate things. Maybe instead of immediately resolving phandles, fn interrupt_parent() should return an Option<PHandle>?
Edit2: That would get rather complicated with #58.

This can be used to check if two Node's are actually the same node. And
it can be used as BTreeMap or HashMap key to map from a Node to OS data
associated with this device like the active driver.
@repnop
repnop merged commit d37dc7e into repnop:main Sep 29, 2026
2 of 3 checks passed
@repnop

repnop commented Sep 29, 2026

Copy link
Copy Markdown
Owner

LGTM, if we need to mess with it in the future shouldn't be a big deal

@bjorn3
bjorn3 deleted the node_id branch September 30, 2026 06:04
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.

2 participants