-
Notifications
You must be signed in to change notification settings - Fork 790
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
[topgen] Generically filter for MMIO region visible devices #23274
[topgen] Generically filter for MMIO region visible devices #23274
Conversation
72f443e
to
47c8d82
Compare
6cd511e
to
8779a22
Compare
@@ -577,6 +578,7 @@ | |||
regs: {hart: "0x21200000"}, | |||
dbg: {soc_dbg: "0x00000000"}, | |||
}, | |||
cpu_not_visible: ["mem", "regs", "dbg"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit sad to have the names appearing twice. Could we switch it so that we end up with something like this?
// Note that this module also contains a bus host.
base_addrs: {
mem: {hart: "0x00040000", cpu_visible: false},
regs: {hart: "0x21200000", cpu_visible: false},
dbg: {soc_dbg: "0x00000000", cpu_visible: false},
},
and we could make it so a region has a default visibility attribute (true, presumably)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed the implementation according to that. It was required to add some special cases when iterating over that struct. Should we add a top-level validation, to ensure that there is no address space named cpu_visible
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make more sense to formalize memory region groups? The "MMIO region" is not a property of an individual IP instance. Instead, it's a contiguous grouping of nodes in the address space.
Validating memory region groups (...or "subspaces"? Not sure what would be a good name yet...) would mean ensuring that all nodes between the two ends are included in the named group, and we'd have to be explicit about each node that is intended to be in the group. topgen would need to error out if any node is missing, since that would be an inconsistent subspace.
I kind of feel like topgen is a dubious place to do this... but if we really want the internal check for minimizing ePMP entries, I guess it makes sense. If there's no DRC, then it might make more sense to kick this out to downstream software completely. Well... maybe it's also convenient to define regions with just the two ends and abandon the check /shrug
@@ -553,6 +553,7 @@ | |||
regs: {hart: "0x30500000"}, | |||
ram: {hart: "0x30600000"}, | |||
}, | |||
cpu_visible: ['ram'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name of this key and how it's used don't really match. We also shouldn't need a designation of whether a node is "visible" to a CPU, since that is indicated by the address space (or could be determined by the xbar config).
The "regs" are very much visible to the CPU, for example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is totally right. This resulted from the fact, that everything except memories was included by default. I removed that base, and explicitly excluded memories from the MMIO range (except for the retention RAM).
a6be9b7
to
21d88f3
Compare
Not sure, if that is in the scope of this PR. I guess we can support multiple MMIO regions in a different PR if needed.
I'm not sure if downstream software actually uses those defines? If not, we maybe can remove that completely? |
This is exactly the scope of what you are modifying, though. The "MMIO region" is merely a macro defined in a software header. The code changed here has no relationship with the CPU's visibility of node. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we've got some misunderstandings of what the original code does here. It defines a contiguous region of the address map and calls it the "MMIO region" so software can program a single entry for it in the ePMP.
CPU visibility doesn't factor into it. Instead, there are hard-coded exceptions in topgen's output helpers that try to define the bounds of the region. If you want to remove those hard-coded exceptions, we would need to either explicitly define non-MMIO nodes for each addr_space, or we could generalize and define multiple such regions, with "MMIO" just being one of them.
util/topgen/lib.py
Outdated
if module['base_addrs'][if_name].get("cpu_visible", True): | ||
regions.append(region) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please no hard-coded address space name exceptions. This violates the data structure's layout.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly, I thought about that too. What about an address space validation as proposed in #23274 (comment) ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, meant to request changes on that last review. Doh!
What about defining it like this:
|
For the option where we generically define subspaces of an addr_space and explicitly include each node, it could look like this:
Actually, we could even choose to move all the base_addr definitions into this three-level tree, and that would make us have compatible definitions with IP-XACT (where a "subspace" is the same as an IP-XACT "memoryMap"). SystemRDL seems to allow nesting addrmap definitions, so it's a little more free. But anyway, that would look like this:
|
Looks good to me. The first one seems easy to me. Whats quite attractive to the second one is to have a base address table basically on one screen. It makes it much more readable for the base addresses, which already annoyed me a few times. However, the changes are of course much more intrusive though. |
Would it make sense to start with the first one? We could choose to move to the second one later. The first solution annoyingly adds some burden to update yet another place in the file when you assign new base addresses. That might motivate us to eventually get to the second solution instead of forever punting it, though, haha. |
That sounds good. The second one is an improvement on top of it, but touches a lot of places.
Totally agree. And it really shows you the memory map in one place. Quite hard to scroll down if there are many more devices ;-) |
21d88f3
to
9e46902
Compare
e1d4ee7
to
d967dc6
Compare
Add a new subspace entry to the address spaces to group multple address to the same address space. For this subspace, the range is computed and added as a definition to the C and Rust collateral. Signed-off-by: Robert Schilling <[email protected]>
d967dc6
to
93b29bb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, this looks great!
spi_device are included. | ||
''' | ||
nodes: [ | ||
"uart0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry you had to type all of that 😆
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha, no worries 😆
CHANGE AUTHORIZED: hw/top_darjeeling/data/top_darjeeling.hjson |
CHANGE AUTHORIZED: hw/top_darjeeling/data/top_darjeeling.hjson |
Remove hardcoded devices and interfaces for MMIO region filtering by adding two new optional module attributes cpu_visible and cpu_not_visible.
By unifying the implementation of the C and Rust generator, an inconsistency between the two implementations was uncovered. Ideally,
TopGenC
andTopGenRust
will be refactored with a common base class to remove as much of the code duplication. I'm not sure though if that is the right PR to fix that.This fixes #14345