Skip to content

Commit

Permalink
dts: Move to 'zephyr,memory-attr'
Browse files Browse the repository at this point in the history
Move to 'zephyr,memory-attr' and use the newly introduced helpers.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
  • Loading branch information
carlocaione committed Jul 6, 2023
1 parent 8ba1fd7 commit 7ffb953
Show file tree
Hide file tree
Showing 35 changed files with 50 additions and 179 deletions.
2 changes: 1 addition & 1 deletion boards/arm/arduino_giga_r1/arduino_giga_r1_m7.dts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
device_type = "memory";
reg = <0xc0000000 DT_SIZE_M(8)>;
zephyr,memory-region = "SDRAM1";
zephyr,memory-region-mpu = "RAM";
zephyr,memory-attr = "RAM";
};

aliases {
Expand Down
2 changes: 1 addition & 1 deletion boards/arm/stm32f746g_disco/stm32f746g_disco.dts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
device_type = "memory";
reg = <0xc0000000 DT_SIZE_M(16)>;
zephyr,memory-region = "SDRAM1";
zephyr,memory-region-mpu = "RAM";
zephyr,memory-attr = "RAM";
};

aliases {
Expand Down
2 changes: 1 addition & 1 deletion boards/arm/stm32f7508_dk/stm32f7508_dk.dts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
device_type = "memory";
reg = <0xc0000000 DT_SIZE_M(16)>;
zephyr,memory-region = "SDRAM1";
zephyr,memory-region-mpu = "RAM";
zephyr,memory-attr = "RAM";
};

aliases {
Expand Down
2 changes: 1 addition & 1 deletion boards/arm/stm32f769i_disco/stm32f769i_disco.dts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
device_type = "memory";
reg = <0xc0000000 DT_SIZE_M(16)>;
zephyr,memory-region = "SDRAM1";
zephyr,memory-region-mpu = "RAM";
zephyr,memory-attr = "RAM";
};

leds {
Expand Down
2 changes: 1 addition & 1 deletion boards/arm/stm32h747i_disco/stm32h747i_disco_m7.dts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
device_type = "memory";
reg = <0xd0000000 DT_SIZE_M(32)>;
zephyr,memory-region = "SDRAM2";
zephyr,memory-region-mpu = "RAM";
zephyr,memory-attr = "RAM";
};

leds {
Expand Down
2 changes: 1 addition & 1 deletion boards/arm/stm32h7b3i_dk/stm32h7b3i_dk.dts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
device_type = "memory";
reg = <0xd0000000 DT_SIZE_M(16)>;
zephyr,memory-region = "SDRAM2";
zephyr,memory-region-mpu = "RAM";
zephyr,memory-attr = "RAM";
};

transceiver0: can-phy0 {
Expand Down
2 changes: 1 addition & 1 deletion boards/arm64/fvp_baser_aemv8r/fvp_baser_aemv8r.dts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
compatible = "zephyr,memory-region", "mmio-dram";
reg = <0x80000000 DT_SIZE_M(2048)>;
zephyr,memory-region = "DEVICE_REGION";
zephyr,memory-region-mpu = "IO";
zephyr,memory-attr = "IO";
};
};
};
Expand Down
8 changes: 4 additions & 4 deletions doc/hardware/arch/arm_cortex_m.rst
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ are programmed during system boot.
Arm memory map policies, allowing for privileged-only RWX permissions on SRAM).
* All the memory regions defined in the devicetree with the compatible
:dtcompatible:`zephyr,memory-region` and at least the property
``zephyr,memory-region-mpu`` defining the MPU permissions for the memory region.
``zephyr,memory-attr`` defining the MPU permissions for the memory region.
See the next section for more details.

The above MPU regions are defined in :file:`soc/arm/common/cortex_m/arm_mpu_regions.c`.
Expand All @@ -455,11 +455,11 @@ Fixed MPU regions defined in devicetree

The user can define memory regions to be allocated and created in the linker
script using nodes with the :dtcompatible:`zephyr,memory-region` devicetree
compatible. When the property ``zephyr,memory-region-mpu`` is present in such
compatible. When the property ``zephyr,memory-attr`` is present in such
a node, a new MPU region will be allocated and programmed during system
boot.

The property ``zephyr,memory-region-mpu`` is a string carrying the attributes
The property ``zephyr,memory-attr`` is a string carrying the attributes
for the MPU region. It is converted to a C token for use defining the attributes
of the MPU region.

Expand All @@ -471,7 +471,7 @@ For example, to define a new non-cacheable memory region in devicetree:
compatible = "zephyr,memory-region", "mmio-sram";
reg = <0x20300000 0x100000>;
zephyr,memory-region = "SRAM_NO_CACHE";
zephyr,memory-region-mpu = "RAM_NOCACHE";
zephyr,memory-attr = "RAM_NOCACHE";
};
This will automatically create a new MPU entry in
Expand Down
6 changes: 3 additions & 3 deletions drivers/adc/adc_stm32.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,20 +250,20 @@ static int adc_stm32_dma_start(const struct device *dev,
* The entire buffer must be in a single region.
* An example of how the SRAM region can be defined in the DTS:
* &sram4 {
* zephyr,memory-region-mpu = "RAM_NOCACHE";
* zephyr,memory-attr = "RAM_NOCACHE";
* };
*/
static bool address_in_non_cacheable_sram(const uint16_t *buffer, const uint16_t size)
{
/* Default if no valid SRAM region found or buffer+size not located in a single region */
bool cachable = false;
#define IS_NON_CACHEABLE_REGION_FN(node_id) \
COND_CODE_1(DT_NODE_HAS_PROP(node_id, zephyr_memory_region_mpu), ({ \
COND_CODE_1(DT_NODE_HAS_PROP(node_id, zephyr_memory_attr), ({ \
const uint32_t region_start = DT_REG_ADDR(node_id); \
const uint32_t region_end = region_start + DT_REG_SIZE(node_id); \
if (((uint32_t)buffer >= region_start) && \
(((uint32_t)buffer + size) < region_end)) { \
cachable = strcmp(DT_PROP(node_id, zephyr_memory_region_mpu), \
cachable = strcmp(DT_PROP(node_id, zephyr_memory_attr), \
"RAM_NOCACHE") == 0; \
} \
}), \
Expand Down
6 changes: 3 additions & 3 deletions drivers/dma/dma_stm32_bdma.c
Original file line number Diff line number Diff line change
Expand Up @@ -809,11 +809,11 @@ static int bdma_stm32_init(const struct device *dev)
* This check verifies that the non-cachable flag is set in the DTS.
* For example:
* &sram4 {
* zephyr,memory-region-mpu = "RAM_NOCACHE";
* zephyr,memory-attr = "RAM_NOCACHE";
* };
*/
#if DT_NODE_HAS_PROP(DT_NODELABEL(sram4), zephyr_memory_region_mpu)
if (strcmp(DT_PROP(DT_NODELABEL(sram4), zephyr_memory_region_mpu), "RAM_NOCACHE") != 0) {
#if DT_NODE_HAS_PROP(DT_NODELABEL(sram4), zephyr_memory_attr)
if (strcmp(DT_PROP(DT_NODELABEL(sram4), zephyr_memory_attr), "RAM_NOCACHE") != 0) {
LOG_ERR("SRAM4 is not set as non-cachable.");
return -EIO;
}
Expand Down
2 changes: 1 addition & 1 deletion dts/arm/nxp/nxp_lpc55S1x_common.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
compatible = "zephyr,memory-region", "mmio-sram";
reg = <0x20010000 DT_SIZE_K(16)>;
zephyr,memory-region = "USB_SRAM";
zephyr,memory-region-mpu = "RAM";
zephyr,memory-attr = "RAM";
};
};

Expand Down
2 changes: 1 addition & 1 deletion dts/arm/nxp/nxp_lpc55S2x_common.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
compatible = "zephyr,memory-region", "mmio-sram";
reg = <0x40100000 DT_SIZE_K(16)>;
zephyr,memory-region = "USB_SRAM";
zephyr,memory-region-mpu = "RAM";
zephyr,memory-attr = "RAM";
};
};

Expand Down
2 changes: 1 addition & 1 deletion dts/arm/nxp/nxp_lpc55S6x_common.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
compatible = "zephyr,memory-region", "mmio-sram";
reg = <0x100000 DT_SIZE_K(16)>;
zephyr,memory-region = "USB_SRAM";
zephyr,memory-region-mpu = "RAM";
zephyr,memory-attr = "RAM";
};

syscon: syscon@0 {
Expand Down
2 changes: 1 addition & 1 deletion dts/arm/nxp/nxp_rt5xx_common.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
compatible = "zephyr,memory-region", "mmio-sram";
reg = <0x40140000 DT_SIZE_K(16)>;
zephyr,memory-region = "SRAM1";
zephyr,memory-region-mpu = "RAM";
zephyr,memory-attr = "RAM";
};
};

Expand Down
2 changes: 1 addition & 1 deletion dts/arm/nxp/nxp_rt6xx_common.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
compatible = "zephyr,memory-region", "mmio-sram";
reg = <0x40140000 DT_SIZE_K(16)>;
zephyr,memory-region = "SRAM1";
zephyr,memory-region-mpu = "RAM";
zephyr,memory-attr = "RAM";
};
};

Expand Down
2 changes: 1 addition & 1 deletion dts/arm/st/f7/stm32f7.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
compatible = "zephyr,memory-region", "mmio-sram";
reg = <0x90000000 DT_SIZE_M(256)>;
zephyr,memory-region = "QSPI";
zephyr,memory-region-mpu = "EXTMEM";
zephyr,memory-attr = "EXTMEM";
};

clocks {
Expand Down
2 changes: 1 addition & 1 deletion dts/arm/st/h7/stm32h7.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
compatible = "zephyr,memory-region", "mmio-sram";
reg = <0x90000000 DT_SIZE_M(256)>;
zephyr,memory-region = "QSPI";
zephyr,memory-region-mpu = "EXTMEM";
zephyr,memory-attr = "EXTMEM";
};

clocks {
Expand Down
16 changes: 1 addition & 15 deletions dts/bindings/base/zephyr,memory-region.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: Compatible for devices resulting in linker memory regions

compatible: "zephyr,memory-region"

include: base.yaml
include: [base.yaml, "zephyr,memory-attr.yaml"]

properties:
zephyr,memory-region:
Expand All @@ -16,17 +16,3 @@ properties:
memory region in the final executable. The region address and size
is taken from the <reg> property, while the name is the value of
this property.
zephyr,memory-region-mpu:
type: string
enum:
- "RAM"
- "RAM_NOCACHE"
- "FLASH"
- "PPB"
- "IO"
- "EXTMEM"
description: |
Signify that this node should result in a dedicated MPU region. The
region address and size are taken from the <reg> property, while the MPU
attribute is the value of this property.
114 changes: 0 additions & 114 deletions include/zephyr/linker/devicetree_regions.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@
#define _DT_SECTION_SIZE(node_id) UTIL_CAT(_DT_SECTION_PREFIX(node_id), _size)
#define _DT_SECTION_LOAD(node_id) UTIL_CAT(_DT_SECTION_PREFIX(node_id), _load_start)

#define _DT_ATTR(token) UTIL_CAT(UTIL_CAT(REGION_, token), _ATTR)

/**
* @brief Declare a memory region
*
Expand Down Expand Up @@ -162,35 +160,6 @@
_DT_SECTION_SIZE(node_id) = _DT_SECTION_END(node_id) - _DT_SECTION_START(node_id); \
_DT_SECTION_LOAD(node_id) = LOADADDR(LINKER_DT_NODE_REGION_NAME_TOKEN(node_id));

/**
* Call the user-provided MPU_FN() macro passing the expected arguments
*/
#define _EXPAND_MPU_FN(node_id, MPU_FN, ...) \
MPU_FN(LINKER_DT_NODE_REGION_NAME(node_id), \
DT_REG_ADDR(node_id), \
DT_REG_SIZE(node_id), \
_DT_ATTR(DT_STRING_TOKEN(node_id, zephyr_memory_region_mpu))),

/**
* Check that the node_id has both properties:
* - zephyr,memory-region-mpu
* - zephyr,memory-region
*
* and call the EXPAND_MPU_FN() macro
*/
#define _CHECK_ATTR_FN(node_id, EXPAND_MPU_FN, ...) \
COND_CODE_1(UTIL_AND(DT_NODE_HAS_PROP(node_id, zephyr_memory_region_mpu), \
DT_NODE_HAS_PROP(node_id, zephyr_memory_region)), \
(EXPAND_MPU_FN(node_id, __VA_ARGS__)), \
())

/**
* Call _CHECK_ATTR_FN() for each enabled node passing EXPAND_MPU_FN() as
* explicit argument and the user-provided MPU_FN() macro in __VA_ARGS__
*/
#define _CHECK_APPLY_FN(compat, EXPAND_MPU_FN, ...) \
DT_FOREACH_STATUS_OKAY_VARGS(compat, _CHECK_ATTR_FN, EXPAND_MPU_FN, __VA_ARGS__)

/** @endcond */

/**
Expand All @@ -211,87 +180,4 @@
#define LINKER_DT_SECTIONS() \
DT_FOREACH_STATUS_OKAY(_DT_COMPATIBLE, _SECTION_DECLARE)

/**
* @brief Generate MPU regions from the device tree nodes with compatible
* 'zephyr,memory-region' and 'zephyr,memory-region-mpu' attribute.
*
* Helper macro to apply an MPU_FN macro to all the memory regions declared
* using the 'zephyr,memory-region-mpu' property and the 'zephyr,memory-region'
* compatible.
*
* @p MPU_FN must take the form:
*
* @code{.c}
* #define MPU_FN(name, base, size, attr) ...
* @endcode
*
* The 'name', 'base' and 'size' parameters are taken from the DT node.
*
* The 'zephyr,memory-region-mpu' enum property is passed as an extended token
* to the MPU_FN macro using the 'attr' parameter, in the form
* REGION_{attr}_ATTR.
*
* The following enums are supported for the 'zephyr,memory-region-mpu'
* property:
*
* - RAM
* - RAM_NOCACHE
* - FLASH
* - PPB
* - IO
*
* This means that usually the arch code would provide some macros or defines
* with the same name of the extended property, that is:
*
* - REGION_RAM_ATTR
* - REGION_RAM_NOCACHE_ATTR
* - REGION_FLASH_ATTR
* - REGION_PPB_ATTR
* - REGION_IO_ATTR
*
* Example devicetree fragment:
*
* / {
* soc {
* sram1: memory@2000000 {
* zephyr,memory-region = "MY_NAME";
* zephyr,memory-region-mpu = "RAM_NOCACHE";
* };
* };
* };
*
* For detailed information about MPU region attribute define configuration refer
* to the specific architecture MPU header.
* For example: include/zephyr/arch/arm/aarch32/mpu/arm_mpu_v7m.h.
*
* The 'attr' parameter of the MPU_FN function will be the extended
* 'REGION_RAM_NOCACHE_ATTR' token and the arch code will be usually
* implementing a macro with the same name.
*
* Example:
*
* @code{.c}
*
* #define REGION_RAM_NOCACHE_ATTR 0xAAAA
* #define REGION_RAM_ATTR 0xBBBB
* #define REGION_FLASH_ATTR 0xCCCC
*
* #define MPU_FN(p_name, p_base, p_size, p_attr) \
* { \
* .name = p_name, \
* .base = p_base, \
* .size = p_size, \
* .attr = p_attr, \
* }
*
* static const struct arm_mpu_region mpu_regions[] = {
* ...
* LINKER_DT_REGION_MPU(MPU_FN)
* ...
* };
* @endcode
*
*/
#define LINKER_DT_REGION_MPU(mpu_fn) _CHECK_APPLY_FN(_DT_COMPATIBLE, _EXPAND_MPU_FN, mpu_fn)

#endif /* ZEPHYR_INCLUDE_LINKER_DEVICETREE_REGIONS_H_ */
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
compatible = "zephyr,memory-region", "mmio-sram";
reg = <0x202c0000 DT_SIZE_K(16)>;
zephyr,memory-region="OCRAM2_OVERLAY";
zephyr,memory-region-mpu = "IO";
zephyr,memory-attr = "IO";
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
compatible = "zephyr,memory-region", "mmio-sram";
reg = <0x202c0000 DT_SIZE_K(16)>;
zephyr,memory-region="OCRAM2_OVERLAY";
zephyr,memory-region-mpu = "IO";
zephyr,memory-attr = "IO";
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
compatible = "zephyr,memory-region", "mmio-sram";
reg = <0x202c0000 DT_SIZE_K(16)>;
zephyr,memory-region="OCRAM2_OVERLAY";
zephyr,memory-region-mpu = "IO";
zephyr,memory-attr = "IO";
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
compatible = "zephyr,memory-region", "mmio-sram";
reg = <0x202c0000 DT_SIZE_K(16)>;
zephyr,memory-region="OCRAM2_OVERLAY";
zephyr,memory-region-mpu = "IO";
zephyr,memory-attr = "IO";
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
compatible = "zephyr,memory-region", "mmio-sram";
reg = <0x202c0000 DT_SIZE_K(16)>;
zephyr,memory-region="OCRAM2_OVERLAY";
zephyr,memory-region-mpu = "IO";
zephyr,memory-attr = "IO";
};
};

Expand Down
Loading

0 comments on commit 7ffb953

Please sign in to comment.