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

[topgen] Improve support for multiple address spaces #23122

Closed
wants to merge 1 commit into from

Conversation

Razer6
Copy link
Member

@Razer6 Razer6 commented May 14, 2024

This PR uses a different approach than #22961 to support multiple address spaces better and generate their C and Rust collateral.

In this PR, topgen iterates over all address spaces available and individually calls TopGenC or TopGenRust on it. Consequently, all address spaces are treated separately, and all outputs are generated in separate files. Therefore, the address space becomes part of the file name as a suffix after the top name. One address space is a default address space (annotated in the HJSON, e.g., the hart) that doesn't face this change in file name. That means the currently existing file names stay the same (without suffixes) and describe the hart address space.

The C and Rust headers generate the definition for alerts and interrupts. Right now, these definitions will only be generated for the default address space. This will be improved in the future since multiple address spaces with multiple CPUs might have their own PLIC. Consequently, the interrupt definitions for different address spaces or interrupt domains will be generated in the corresponding file.

@Razer6 Razer6 requested review from msfschaffner and a team as code owners May 14, 2024 19:37
@Razer6 Razer6 requested review from jwnrt and jadephilipoom and removed request for a team May 14, 2024 19:37
@Razer6 Razer6 force-pushed the dev-multiple-addr-spaces branch 2 times, most recently from 6c23793 to eaf64b5 Compare May 14, 2024 19:42
Copy link
Member Author

@Razer6 Razer6 left a comment

Choose a reason for hiding this comment

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

@a-will As discussed, this is now a different approach for generating the C and Rust collaterals for multiple address spaces.

hw/top_darjeeling/sw/autogen/top_darjeeling_soc_mbx.h Outdated Show resolved Hide resolved
@Razer6 Razer6 requested review from a-will and removed request for msfschaffner, jwnrt and jadephilipoom May 14, 2024 19:45
@a-will a-will force-pushed the dev-multiple-addr-spaces branch 2 times, most recently from 81c0174 to 32ad6ff Compare May 15, 2024 05:01
Copy link
Contributor

@a-will a-will left a comment

Choose a reason for hiding this comment

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

Generally looks good to me. I fixed up some stylistic issues to get it to pass lint, but you might want to have a more strict Python reviewer than me.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hm, no real content. I suppose there isn't any reason to generate these C files at this time, but also... no harm leaving it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, these address spaces only have definitions in the header. Not sure if we can determine if there is nothing to generate. Probably the length of all internal structures is 0?

Comment on lines 68 to 74
def _get_irq_peripherals(self):
if self.addr_space != self.default_addr_space:
return []
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not totally sure whether this restriction would generally hold, but it doesn't hurt to start with it.

Copy link
Member Author

Choose a reason for hiding this comment

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

No, in the future, I would like to determine if there is a PLIC in the address space and then yield the devices that are connected to that one - keyword interrupt_domain.

@a-will
Copy link
Contributor

a-will commented May 15, 2024

Looks like englishbreakfast may need similar attention :)

@Razer6 Razer6 force-pushed the dev-multiple-addr-spaces branch 2 times, most recently from 4393271 to 7621c1f Compare May 16, 2024 08:26
@Razer6
Copy link
Member Author

Razer6 commented May 16, 2024

CI is happy now :) @andreaskurth Who be eligible to review that PR form a python perspective?

@Razer6 Razer6 requested a review from andreaskurth May 16, 2024 11:58
@Razer6 Razer6 added Component:Tooling Issues related to tooling, e.g. tools/scripts for doc, code generation (docgen, reggen), CSR Component:Darjeeling labels May 16, 2024
@Razer6 Razer6 force-pushed the dev-multiple-addr-spaces branch from 7621c1f to 821e459 Compare May 16, 2024 21:51
util/topgen/c.py Outdated
@@ -125,6 +132,28 @@ def __init__(self, top_info, name_to_block: Dict[str, IpBlock]):
self._init_clkmgr_clocks()
self._init_mmio_region()

def all_device_regions(self) -> Dict[str, MemoryRegion]:
Copy link
Member Author

Choose a reason for hiding this comment

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

@a-will This function was newly added to capture the memory regions of all devices, not just in the current address space. This was needed since the single alert handler needs to capture all devices, not just the ones from the current address space.

@Razer6 Razer6 changed the base branch from integrated_dev to master October 21, 2024 17:37
@Razer6 Razer6 requested review from rswarbrick, mundaym, a team, vogelpi and cfrantz as code owners October 21, 2024 17:37
@Razer6 Razer6 changed the base branch from master to integrated_dev October 21, 2024 17:48
Copy link
Contributor

@rswarbrick rswarbrick left a comment

Choose a reason for hiding this comment

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

Some nitty comments, but this looks really good to me.

util/topgen.py Outdated
rsformat_dir.mkdir(parents=True, exist_ok=True)
# The Rust file needs some complex information, so we initialize this
# object to store it.
rs_helper = TopGenRust(completecfg, name_to_block, version_stamp, addr_space['name'])
Copy link
Contributor

Choose a reason for hiding this comment

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

I know that the rest of this file has the same problem, but maybe it makes sense to do some sanity checking of addr_space['name'] here? (Make sure it's a string, maybe? And how does default_addr_space relate to the allowed values here? (Or maybe that sort of check belongs somewhere earlier, rather than being Rust-specific?)

Copy link
Member Author

@Razer6 Razer6 Oct 21, 2024

Choose a reason for hiding this comment

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

I agree, it might be checked that addr_space['name'] is a string. There is no custom validation for these kind of dicts, right? default_addr_space is a boolean, to indicate that address space is a the default address space. Maybe that should be checked somewhere else as part of the general validation phase.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think there is (not code I wrote...). And good point about default_addr_space: I totally misread your code!

util/topgen.py Show resolved Hide resolved
util/topgen.py Outdated Show resolved Hide resolved
@Razer6 Razer6 force-pushed the dev-multiple-addr-spaces branch from a54d8d0 to 32e1390 Compare October 30, 2024 13:34
@Razer6 Razer6 requested a review from milesdai as a code owner October 30, 2024 13:34
@Razer6 Razer6 changed the base branch from integrated_dev to master October 30, 2024 13:35
@Razer6 Razer6 force-pushed the dev-multiple-addr-spaces branch 3 times, most recently from e6bc97d to 667e183 Compare December 12, 2024 07:58
@Razer6 Razer6 requested a review from a-will December 12, 2024 07:59
@Razer6 Razer6 force-pushed the dev-multiple-addr-spaces branch 2 times, most recently from b76909f to 8cdfb81 Compare December 12, 2024 10:53
Individually generate C and Rust collateral for all address spaces

Signed-off-by: Robert Schilling <rschilling@rivosinc.com>
@Razer6
Copy link
Member Author

Razer6 commented Jan 20, 2025

Closing since #25894 is merged

@Razer6 Razer6 closed this Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component:Darjeeling Component:Tooling Issues related to tooling, e.g. tools/scripts for doc, code generation (docgen, reggen), CSR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants