Skip to content

systemc-components: add the SMMU V3 model#56

Draft
mahmdkamel wants to merge 1 commit intomainfrom
add_smmuv3
Draft

systemc-components: add the SMMU V3 model#56
mahmdkamel wants to merge 1 commit intomainfrom
add_smmuv3

Conversation

@mahmdkamel
Copy link
Copy Markdown
Contributor

@mahmdkamel mahmdkamel commented May 7, 2026

  • Add smmuv3 model under systemc-components.
  • Add a test bench at tests/components/smmuv3.

@mahmdkamel mahmdkamel force-pushed the add_smmuv3 branch 4 times, most recently from ce7966d to 6622c44 Compare May 7, 2026 08:50
Comment thread systemc-components/smmuv3/src/.gitignore Outdated
@androm3da androm3da requested a review from p-b-o May 7, 2026 16:26
add_subdirectory(generic_lua_model)
add_subdirectory(container_builder)
add_subdirectory(smmu500)
add_subdirectory(smmuv3)
Copy link
Copy Markdown

@p-b-o p-b-o May 7, 2026

Choose a reason for hiding this comment

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

A general remark about naming. Arm-MMU 600 or 700 are the two Arm SMMUv3, targeting v3.1 and v3.2 respectively. It seems the current implement is more v3.1, since it does not have support for Secure stage 2 translations.
So probably naming it smmu600 makes sense.

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.

read_dram(dest_pa, &readback, 4);
ASSERT_EQ(readback, 0xCAFEBABEu);
}

Copy link
Copy Markdown

@p-b-o p-b-o May 7, 2026

Choose a reason for hiding this comment

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

Maybe not required now, but would be useful to add S2 translations unit tests also, and S1 + S2 too, to mimic what a VM would do. In general, would be nice to have full coverage on SMMU code if we want to make this a "production ready" model.

Also, it would be nice to have expected_fail tests, with bad permissions or wrong translation table setup. It naturally comes with coverage approach mentioned in previous paragraph.

It can definitely grow over time, and it's not a blocker for this PR.


ASSERT_EQ(mmio_read32(REG_CMDQ_CONS) & 0x1F, 1u);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Same remark about testing other commands.


} // namespace gs

#endif // SMMUV3_H
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Overall looks quite complete! It's pretty inspired from QEMU model (maybe that's what was suggested in the prompt?).

I would trust more coverage and unit tests than a manual review for most of the complex parts (stages, ptw, registers configuration, etc)

Copy link
Copy Markdown
Contributor Author

@mahmdkamel mahmdkamel May 8, 2026

Choose a reason for hiding this comment

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

Thank you very much Pierrick, more test cases were added, and I added support for TBU DMI and DMI INV and test benches for them, please check again.

@mahmdkamel mahmdkamel force-pushed the add_smmuv3 branch 2 times, most recently from 9b6857a to 7ae2574 Compare May 8, 2026 01:40
Copy link
Copy Markdown
Member

@androm3da androm3da left a comment

Choose a reason for hiding this comment

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

Mostly nits here and there, I don't have any significant objections. LGTM


if (level == 3) break; // Must be page descriptor

switch (type) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please add a default handler (maybe unreachable?)

case NORMAL_WB:
oss << "Normal-WB";
break;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Add a default: unreachable

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.

Done!

class smmuv3_memory_attrs_extension : public tlm::tlm_extension<smmuv3_memory_attrs_extension>
{
public:
enum MemoryType {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

enum class would restrict the type and scope more strongly, consider whether it could be used here.

Copy link
Copy Markdown
Contributor Author

@mahmdkamel mahmdkamel May 8, 2026

Choose a reason for hiding this comment

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

should be adjusted now!

Copy link
Copy Markdown

@p-b-o p-b-o left a comment

Choose a reason for hiding this comment

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

It looks pretty good, and I think it's more than enough for a first version. If you don't have time, feel free to skip the coverage part.

ASSERT_EQ(par_lo & ~0xFFFu, static_cast<uint32_t>(page_pa) & ~0xFFFu);
}

TEST_BENCH(smmuv3_bench, TwoLevelStreamTable_S1_4KPage)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

While this test is useful, maybe the intent was to add a two stages translation test, exercising S1 + S2. I didn't find this configuration in all the new tests added.

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.

It should be added now, with other tests to increase coverage, and still adding more, also there is no any meaningful logging used, I am on the process of adding SCP_* log messages in the important locations.

ASSERT_EQ(dmi_inv_observer.ranges.size(), 0u);
}

int sc_main(int argc, char** argv)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

That's definitely a lot of new tests! Hard to say what might be missing from the full patchset, but running the test with a gcov build and see coverage might hint on which situations are not covered yet.

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.

still working on increasing it more, now it shows 89.31 % line coverage and 92.11 % for functions but still the branch is low: 73.76 %

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Great. Leaving a few branch combinations behind is not too much a problem (out of s1 + s2 which is important).

@p-b-o
Copy link
Copy Markdown

p-b-o commented May 8, 2026

I'm not sure what is going on with the CI, but it seems like smmuv3 tests are segfaulting with gcc (undefined behavior resulting in a wrong optimization?). Definitely worth taking a look before merging it.

@mahmdkamel mahmdkamel force-pushed the add_smmuv3 branch 2 times, most recently from c9c391c to d89f84e Compare May 8, 2026 16:12
- Add smmuv3 model under systemc-components.
- Add a test bench at tests/components/smmuv3.

Signed-off-by: Mahmoud Kamel <mkamel@qti.qualcomm.com>
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.

4 participants