From 80ad34da780aad04f194ece5e79f5776cf776dd7 Mon Sep 17 00:00:00 2001 From: Giacomo Travaglini Date: Thu, 28 May 2020 11:01:31 +0100 Subject: [PATCH] dev-arm: Define a ParentMem object for DTB autogen A memory willing to autogenerate child nodes can do that directly in the generateDeviceTree method. However sometimes portions of memory (child nodes) are tagged for specific applications. Hardcoding the child node in the parent memory class is not flexible, so we delegate this to the application model, which is registering the generator helper via the ParentMem interface JIRA: https://gem5.atlassian.net/browse/GEM5-768 Change-Id: I5fa5bac0decf5399dbaa3804569998dc5e6d7bc0 Signed-off-by: Giacomo Travaglini Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/34376 Tested-by: kokoro Reviewed-by: Richard Cooper --- src/dev/arm/RealView.py | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/dev/arm/RealView.py b/src/dev/arm/RealView.py index 5397de5aa..d35f7ceda 100644 --- a/src/dev/arm/RealView.py +++ b/src/dev/arm/RealView.py @@ -543,7 +543,40 @@ class HDLcd(AmbaDmaDevice): yield node -class MmioSRAM(SimpleMemory): +class ParentMem(SimpleMemory): + """ + This is a base abstract class for child node generation + A memory willing to autogenerate child nodes can do that + directly in the generateDeviceTree method. + However sometimes portions of memory (child nodes) are tagged + for specific applications. Hardcoding the child node in the + parent memory class is not flexible, so we delegate this + to the application model, which is registering the generator + helper via the ParentMem interface. + """ + def __init__(self, *args, **kwargs): + super(ParentMem, self).__init__(*args, **kwargs) + self._generators = [] + + def addSubnodeGenerator(self, gen): + """ + This is the method a client application would use to + register a child generator in the memory object. + """ + self._generators.append(gen) + + def generateSubnodes(self, node, state): + """ + This is the method the memory would use to instantiate + the child nodes via the previously registered generators. + """ + for subnode_gen in self._generators: + node.append(subnode_gen(state)) + +class MmioSRAM(ParentMem): + def __init__(self, *args, **kwargs): + super(MmioSRAM, self).__init__(**kwargs) + def generateDeviceTree(self, state): node = FdtNode("sram@%x" % long(self.range.start)) node.appendCompatible(["mmio-sram"]) @@ -559,6 +592,8 @@ class MmioSRAM(SimpleMemory): state.addrCells(self.range.start) + state.sizeCells(self.range.size()) )) + self.generateSubnodes(node, state) + yield node class FVPBasePwrCtrl(BasicPioDevice): -- 2.30.2