Repository navigation
smmuv2: Add ability to specify sid and cb numbers in a cdl file #34
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /* | ||
| * Copyright 2026, DornerWorks | ||
| * | ||
| * SPDX-License-Identifier: BSD-2-Clause | ||
| */ | ||
|
|
||
| arch aarch64 | ||
|
|
||
| objects { | ||
| sid_a = streamid (sid: 4) | ||
| sid_b = streamid (sid: 9) | ||
| sid_c = streamid (sid: 12) | ||
| smmu_cnode = cnode (4 bits) | ||
| } | ||
|
|
||
| caps { | ||
| smmu_cnode { | ||
| 0x1: sid_a | ||
| 0x2: sid_b | ||
| 0x3: sid_c | ||
| } | ||
| } | ||
|
|
||
| irq maps { | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| arch aarch64 | ||
|
|
||
| objects { | ||
|
|
||
| sid_a = streamid (sid: 4) | ||
| sid_b = streamid (sid: 9) | ||
| sid_c = streamid (sid: 12) | ||
| smmu_cnode = cnode (4 bits) | ||
|
|
||
|
|
||
| } caps { | ||
|
|
||
| smmu_cnode { | ||
| 1: sid_a | ||
| 2: sid_b | ||
| 3: sid_c | ||
| } | ||
|
|
||
| } cdt { | ||
|
|
||
| } irq maps { | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,8 +52,6 @@ | |
|
|
||
| #define STACK_ALIGNMENT_BYTES 16 | ||
|
|
||
| #define MAX_STREAM_IDS 60 | ||
|
|
||
| static seL4_CPtr capdl_to_sel4_orig[CONFIG_CAPDL_LOADER_MAX_OBJECTS]; | ||
| static seL4_CPtr capdl_to_sel4_copy[CONFIG_CAPDL_LOADER_MAX_OBJECTS]; | ||
| static seL4_CPtr capdl_to_sel4_irq[CONFIG_CAPDL_LOADER_MAX_OBJECTS]; | ||
|
|
@@ -82,7 +80,6 @@ extern char _end[]; | |
| * This is expected to be initialised by 'init_copy_addr' on system init */ | ||
| uintptr_t copy_addr; | ||
|
|
||
| uint32_t sid_number = 0; | ||
| /* In the case where we just want a 4K page and we cannot allocate | ||
| * a page table ourselves, we use this pre allocated region that | ||
| * is guaranteed to have a pagetable */ | ||
|
|
@@ -642,23 +639,19 @@ unsigned int create_object(CDL_Model *spec, CDL_Object *obj, CDL_ObjID id, seL4_ | |
| #endif | ||
|
|
||
| /* There can be multiple sids per context bank, currently only 1 sid per cb is implemented for the vms. | ||
| * When this gets extended we need to decide to add sid number -> cb number map into the haskell / python tool | ||
| * or generate the capdl spec so that the order remains correct here e.g a list a stream ids followed by the cb they | ||
| * are mapped to, the cb condition here (1***) will the reset the stream id number back to 0 for the next context bank. | ||
| * The sid and cb numbers are taken from the capdl spec, so the order of the objects in the spec does not matter. | ||
| * Stream IDs are fixed by the hardware and must always be specified while a cb without a bank number gets bank 0. | ||
| */ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comment on lines 641-644 needs to be slightly updated for this change. In particular, I think that the second half of the comment involving the order of stream ids and context banks in the specification is no longer relevant. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comments have been updated in the latest push. |
||
| #ifdef CONFIG_ARM_SMMU | ||
| if (CDL_Obj_Type(obj) == CDL_SID) { | ||
| err = seL4_ARM_SIDControl_GetSID(seL4_CapSMMUSIDControl, sid_number, seL4_CapInitThreadCNode, free_slot, | ||
| err = seL4_ARM_SIDControl_GetSID(seL4_CapSMMUSIDControl, CDL_SID_Sid(obj), seL4_CapInitThreadCNode, free_slot, | ||
| CONFIG_WORD_SIZE); | ||
| ZF_LOGF_IF(err != seL4_NoError, "Failed to allocate SID cap"); | ||
| sid_number++; | ||
| ZF_LOGF_IF(sid_number > MAX_STREAM_IDS, "Stream ID numbers exhausted"); | ||
|
Comment on lines
-654
to
-655
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like a breaking change in behaviour to me. If sid numbers where previously allocated automatically and now always need to be specified, existing specs will break. I don't think that is a good option. If we want to keep the loader simple, which I would prefer, the front-ends now need to provide this sid allocation when no sids are listed in the spec.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with the suggestion to have the allocation provided by the front-end when required. It should be relatively straightforward to do in either the Python or Haskell parts of the toolchain, although it might be a bit more complicated if we want to support a mix of manually specified sids and cbs with others that are automatically allocated. Does anyone have a use-case that would be helped by a mix like that? If not, I think it would be simplest to not provide support for such specifications.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It doesn't make sense not specifying a SID. It would be like creating an interrupt handler and not wanting to specify the interrupt ID. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Kent is right, that it doesn't really make sense to not specify an SID.
Is that needed at all? That is entirely platform dependent and checked by the microkernel, so it will just crash at runtime during this call if it is too high.
I am not that familiar with this repository, so I am assuming the front-ends mean the tools that generate a CapdDL spec? The breaking case only seems to be if you have an old spec file that you are using with a new loader? Is this something we should address in this change?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it probably includes things like the CAmkES generation of capDL specs, if they support SMMU, so that our other repositories which (maybe?) use the SMMU don't break. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Based off of @Furao's and @kent-mcleod's comments, the latest push chooses to require SIDs and missing SIDs are caught at build time. An example |
||
| return seL4_NoError; | ||
| } else if (CDL_Obj_Type(obj) == CDL_CB) { | ||
| err = seL4_ARM_CBControl_GetCB(seL4_CapSMMUCBControl, CDL_CB_Bank(obj), seL4_CapInitThreadCNode, free_slot, | ||
| CONFIG_WORD_SIZE); | ||
| ZF_LOGF_IF(err != seL4_NoError, "Failed to allocate CB cap"); | ||
| sid_number = 0; //(1***) | ||
| return seL4_NoError; | ||
| } | ||
| #endif | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| # | ||
| # Copyright 2026, DornerWorks | ||
| # | ||
| # SPDX-License-Identifier: BSD-2-Clause | ||
| # | ||
|
|
||
| # Add the root directory of this repository to your PYTHONPATH environment | ||
| # variable to enable the following import. | ||
| import capdl | ||
|
|
||
| # Create an allocator for kernel objects. | ||
| obj_allocator = capdl.ObjectAllocator() | ||
|
|
||
| # Let's create a CNode for the SMMU driver. | ||
| smmu_cnode = obj_allocator.alloc(capdl.ObjectType.seL4_CapTableObject, | ||
| name='smmu_cnode', size_bits=4) | ||
|
|
||
| # Let's create some SMMU stream IDs. These are fixed by the hardware, so | ||
| # each one must be given its stream ID when it is allocated. | ||
| sids = [obj_allocator.alloc(capdl.ObjectType.seL4_ARMSID, name, streamid=sid) | ||
| for name, sid in [('sid_a', 4), ('sid_b', 9), ('sid_c', 12)]] | ||
|
|
||
| # Let's give the CNode a cap to each stream ID. | ||
| cap_allocator = capdl.CSpaceAllocator(smmu_cnode) | ||
| for sid in sids: | ||
| cap_allocator.alloc(sid) | ||
|
|
||
| # Now create a spec and print it out to show what we did. | ||
| spec = capdl.Spec(arch='aarch64') | ||
| spec.add_object(smmu_cnode) | ||
| for sid in sids: | ||
| spec.add_object(sid) | ||
| print(str(spec)) |
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 not relevant to this PR but I'm slightly confused about how this previously worked. It looks like the initialiser already required that context banks had a number specified, but nothing was being passed through by the CapDL-tool here.
Uh oh!
There was an error while loading. Please reload this page.
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 guess if it defaults to zero (which it should, I think) then it would work for at least one context bank... any more would fail because it's already in use.