-
Notifications
You must be signed in to change notification settings - Fork 8.4k
boards: st: h7: add memory-regions property to mac node #100910
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: main
Are you sure you want to change the base?
boards: st: h7: add memory-regions property to mac node #100910
Conversation
f1b20a2 to
60a4695
Compare
|
Failed twister-builds have nothing to do with the changes this PR introduces, as far as I can say. |
juickar
left a 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.
@bklaric1 try to rebase on main. A fix has been pushed for the CI failed test
60a4695 to
81c21ce
Compare
|
@juickar they seem to be queued now for almost a day. Was there another fix in the meantime? |
|
@juickar the first run before the rebase seemed to pass, at least the part that runs the build with code changes. So I guess I'll wait for the CI fix and/or review to update this branch to rerun the checks. |
erwango
left a 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.
Thanks for the change, but in order to avoid impacting existing users, I'd prefer you keep the changes out of the boards.
So please assign the memory regions (memory-regions = <&sram2/3>;) in .dtsi files and keep existing pattern of using sram3 when available otherwise sram2.
This was, out of tree users won't see any difference.
soc/st/stm32/stm32h7x/mpu_regions.c
Outdated
| #ifdef sram_eth_node | ||
| BUILD_ASSERT(!DT_SAME_NODE(sram_eth_node, DT_CHOSEN(zephyr_sram)), | ||
| "Remove property memory-regions from 'mac' node " | ||
| "to locate ethernet buffers in system RAM."); | ||
| #endif |
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.
Since this is not an option today, I'd suggest to remove
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.
This was suggested by @etienne-lms. But I can remove it if wanted.
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 should prevent one to set memory-regions property to the zephyr,sram phandle.
I'd suggest:
#include <zephyr/devicetree.h>
#include <zephyr/arch/arm/mpu/arm_mpu_mem_cfg.h>
+#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(mac))
+#define sram_eth_node DT_PHANDLE(DT_NODELABEL(mac), memory_regions)
+
+BUILD_ASSERT(DT_NODE_HAS_PROP(DT_NODELABEL(mac), memory_regions) &&
+ DT_NODE_HAS_STATUS_OKAY(sram_eth_node),
+ "Ethernet MAC node must provide an enabled memory region for ethernet buffers");
+BUILD_ASSERT(!DT_SAME_NODE(sram_eth_node, DT_CHOSEN(zephyr_sram)),
+ "Ethernet buffer memory-region cannot be located in Zephyr system RAM.");
+#endif /* mac node enabled */
+
static const struct arm_mpu_region mpu_regions[] = {
(...)
#ifdef sram_eth_node
MPU_REGION_ENTRY("SRAM_ETH_BUF",
DT_REG_ADDR(sram_eth_node),
REGION_RAM_NOCACHE_ATTR(REGION_16K)),
MPU_REGION_ENTRY("SRAM_ETH_DESC",
DT_REG_ADDR(sram_eth_node),
REGION_PPB_ATTR(REGION_256B)),
#endif
};
(...)I guess DT_NODE_HAS_PROP(DT_NODELABEL(mac), memory_regions) assertion can be removed if the property is tagged required.
@erwango If I understand this correctly, this is what you're suggesting:
Eveything else stays the same (pending BUILD_ASSERT change). |
Yes
Yes
I assume you're talking about SoC instead of "boards".
Not required. Keep what is proposed in the PR, except the build assert proposing a fallback on System RAM. |
soc/st/stm32/stm32h7x/mpu_regions.c
Outdated
| #ifdef sram_eth_node | ||
| BUILD_ASSERT(!DT_SAME_NODE(sram_eth_node, DT_CHOSEN(zephyr_sram)), | ||
| "Remove property memory-regions from 'mac' node " | ||
| "to locate ethernet buffers in system RAM."); | ||
| #endif |
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 should prevent one to set memory-regions property to the zephyr,sram phandle.
I'd suggest:
#include <zephyr/devicetree.h>
#include <zephyr/arch/arm/mpu/arm_mpu_mem_cfg.h>
+#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(mac))
+#define sram_eth_node DT_PHANDLE(DT_NODELABEL(mac), memory_regions)
+
+BUILD_ASSERT(DT_NODE_HAS_PROP(DT_NODELABEL(mac), memory_regions) &&
+ DT_NODE_HAS_STATUS_OKAY(sram_eth_node),
+ "Ethernet MAC node must provide an enabled memory region for ethernet buffers");
+BUILD_ASSERT(!DT_SAME_NODE(sram_eth_node, DT_CHOSEN(zephyr_sram)),
+ "Ethernet buffer memory-region cannot be located in Zephyr system RAM.");
+#endif /* mac node enabled */
+
static const struct arm_mpu_region mpu_regions[] = {
(...)
#ifdef sram_eth_node
MPU_REGION_ENTRY("SRAM_ETH_BUF",
DT_REG_ADDR(sram_eth_node),
REGION_RAM_NOCACHE_ATTR(REGION_16K)),
MPU_REGION_ENTRY("SRAM_ETH_DESC",
DT_REG_ADDR(sram_eth_node),
REGION_PPB_ATTR(REGION_256B)),
#endif
};
(...)I guess DT_NODE_HAS_PROP(DT_NODELABEL(mac), memory_regions) assertion can be removed if the property is tagged required.
81c21ce to
4161046
Compare
|
@erwango @etienne-lms I amended the commit to add the requested changes, update the property to be required, and update the commit message. |
4161046 to
f6e1669
Compare
Use the memory-regions property in stm32h7.dtsi to explicitly locate ethernet buffer and descriptor to an sram region. Set sram2 as default and override with sram3 when available, in soc level .dtsi files. Add #memory-region-cells to sram2 and sram3 nodes in specific .dtsi files in dts/arm/st/h7, since it is needed by the memory-regions property. Also add the memory-regions property to stm32h563.dtsi since ethernet defined there uses the same .yaml file and thus requires the same addition as in stm32h7.dtsi. Also add #memory-region-cells to sram2 and sram3 nodes in stm32h562.dtsi. Use the same check and definition of the sram_eth_node in mpu_regions.c and sections.ld as in soc/st/stm32/h7rsx. Signed-off-by: Benjamin Klaric <benjamin.klaric01@gmail.com>
f6e1669 to
f57c012
Compare
|
Note: I also needed to add the Also note that I didn't override the |
|
| compatible = "zephyr,memory-region", "mmio-sram"; | ||
| reg = <0x20040000 DT_SIZE_K(64)>; | ||
| zephyr,memory-region = "SRAM2"; | ||
| #memory-region-cells = <0>; |
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.
This should be declared in zephyr,memory-region.yml or somewhere else; IIRC edtlib has special casing for #xxx-cells properties so this works, but it should still be listed and documented as part of a binding.
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.
As far as I can tell, this is needed because memory-regions is defined as phandle-array here:
zephyr/dts/bindings/reserved-memory/memory-region.yaml
Lines 7 to 10 in e6fd157
| properties: | |
| memory-regions: | |
| type: phandle-array | |
| description: List of memory region phandles |
I don't know if it's possible to define it in memory-region.yaml directly (as <0>), and if it's wanted there, since <0> might not always be the use case.
I hope I didn't miss the point of your comment.
| }; | ||
|
|
||
| &mac { | ||
| memory-regions = <&sram3>; |
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.
Nit: maybe memory-region-names should be used?
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.
memory-region-names is not phandle but rather string-array:
zephyr/dts/bindings/reserved-memory/memory-region.yaml
Lines 12 to 14 in e6fd157
| memory-region-names: | |
| type: string-array | |
| description: A list of names, one for each corresponding phandle in memory-region |
Since we need to pass a referance to sram node, I am unsure if it will work with memory-region-names, tho I might be wrong.
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.
Names used in memory-region-names are rather identifiers for the phandle indices used in a memory-regions property. It's useful when there can be several phandles, not a single one, see for examples clocks = ... and clock-names.
Since here we only expect one, I don't think it's really useful.
| #endif | ||
|
|
||
| #if DT_NODE_HAS_STATUS_OKAY(sram_eth_node) | ||
| #if defined(sram_eth_node) && DT_NODE_HAS_STATUS_OKAY(sram_eth_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.
defined(sram_eth_node) will always evaluate to 1: it is defined literally one line above
Either the check is not necessary:
| #if defined(sram_eth_node) && DT_NODE_HAS_STATUS_OKAY(sram_eth_node) | |
| #if DT_NODE_HAS_STATUS_OKAY(sram_eth_node) |
Or this is a mistake and you were looking for another macro (DT_NODE_EXISTS? DT_NODE_HAS_PROP on &mac?)
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.
This was a copy&paste mistake I made from mpu_regions.c. The idea will be explained in the comment regarding mpu_regions.c. Will remove it here.
| #endif | ||
|
|
||
| #if DT_NODE_HAS_STATUS_OKAY(sram_eth_node) | ||
| #if defined(sram_eth_node) && DT_NODE_HAS_STATUS_OKAY(sram_eth_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.
ditto wrt defined(sram_eth_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.
The idea here was, disregarding the mistake made in sections.ld, to check if sram_eth_node has status = "okay", meaning we check if the sram node passed with memory-regions has status = "okay", to avoid the case of passing sram node which is disabled. This is the case with the current implementation of this check here:
zephyr/soc/st/stm32/stm32h7rsx/mpu_regions.c
Lines 33 to 35 in e6fd157
| #if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(mac)) | |
| #define sram_eth_node DT_NODELABEL(sram2) | |
| #if DT_NODE_HAS_STATUS_OKAY(sram_eth_node) |
sram2 is passed but it is disabled by default in DT.
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.
Ah, right, I see now that (unlike in the linker script) here sram_eth_node is only defined if the ETH MAC node is enabled. So indeed here it does make sense.
| REGION_RAM_NOCACHE_ATTR(REGION_16K)), | ||
| MPU_REGION_ENTRY("SRAM_ETH_DESC", | ||
| DT_REG_ADDR(sram_eth_node), | ||
| REGION_PPB_ATTR(REGION_256B)), |
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.
Nit, outside PR scope: (ab)using REGION_PPB as a REGION_STRONGLY_ORDERED is really ugly.
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.
As you said, it's outside the scope of PR and also beyond my current knowledge on the topic, but taking a guess here, could it be defined as REGION_RAM_NOCACHE_ATTR() instead? As far as I can tell, the goal is to make the region non-cacheable.
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 assume there is a reason for which PPB was used rather than RAM_NOCACHE as done above, but I don't know which. So let's leave it as is for now...
|
The failed twister-build (5) is related to missing |



Changes
memory-regionsproperty to h7 series boards (to the ones supporting ethernet) in order to explicitly locate ethernet buffer and descriptor to an sram region inside the DT. Sincesram3was the first option andsram2the fallback (inmpu_regions.candsections.ld), I tried to usesram3when possible and usedsram2otherwise.#memory-region-cellstosram3andsram2nodes indts/arm/st/h7since it is needed by the memory-regions property.sram_eth_nodeinmpu_regions.candsections.ldas in boards: st: stm32h7s78_dk: add Ethernet support #99296.memory-regionsproperty todts/bindings/ethernet/st,stm32h7-ethernet.yamlso twister-builds can run (will be added by the PR listed under Dependencies and can be removed later).Dependencies
memory-regionsproperty todts/bindings/ethernet/st,stm32h7-ethernet.yaml)Notes
@etienne-lms suggested this change in #99296.