Add a map_addr method for transforming a register address#80
Open
jnkr-ifx wants to merge 1 commit intoInfineon:mainfrom
Open
Add a map_addr method for transforming a register address#80jnkr-ifx wants to merge 1 commit intoInfineon:mainfrom
jnkr-ifx wants to merge 1 commit intoInfineon:mainfrom
Conversation
On TrustZone devices, bit 28 of the address space is used to indicate
whether a memory access is secure or non-secure, meaning drivers often
need to bitwise-OR a security bit against the register address.
In order to support this with svd2pac, this commit adds a `map_addr`
function to registers and clusters allowing a driver to override the
register's address.
The function is implemented as a trait method for two reasons:
- To avoid naming collisions in case a cluster has a register named
`map_addr`.
- So that drivers can build safe abstractions on top of `map_addr`, like:
```rust
/// Helper trait for applying a security attribute to a register address.
pub trait WithSecurity {
/// Applies a security attribute to the address referenced by `self`.
fn with_security(self, security: impl Security) -> Self;
}
impl<T: pac::MapAddr> WithSecurity for &T {
fn with_security(self, security: impl Security) -> Self {
unsafe { self.map_addr(|addr| security.map_addr(addr)) }
}
}
```
The function signature intentionally mirrors [std's `map_addr`][map_addr]
function on pointer types.
[map_addr]: https://doc.rust-lang.org/std/primitive.pointer.html#method.map_addr-1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On many processors implementing TrustZone, bit 28 of the address space is used to indicate whether a memory access is secure or non-secure, meaning drivers often need to bitwise-OR a security bit against the register address.
In order to support this with svd2pac, this commit adds a
map_addrfunction to registers and clusters allowing a driver to override the register's address:The function is implemented as a trait method for two reasons:
map_addr.map_addr, like:The function signature intentionally mirrors std's
map_addrfunction on pointer types.