Skip to content

Commit cd39ee9

Browse files
committed
[nrf fromtree] soc: nordic: common: dmm: fix region alignment getter
Getting the required alignment size for memory region node and device node needs to be handled by a separate macro. Otherwise alignment of single byte is reported for any region. Add a test that checks for this particular issue. Signed-off-by: Nikodem Kastelik <[email protected]> (cherry picked from commit c0d508a)
1 parent 732fc36 commit cd39ee9

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

soc/nordic/common/dmm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
{.dt_addr = DT_REG_ADDR(node_id), \
2424
.dt_size = DT_REG_SIZE(node_id), \
2525
.dt_attr = DT_PROP(node_id, zephyr_memory_attr), \
26-
.dt_align = DMM_ALIGN_SIZE(node_id), \
26+
.dt_align = DMM_REG_ALIGN_SIZE(node_id), \
2727
.dt_allc = &_BUILD_LINKER_END_VAR(node_id)},
2828

2929
/* Generate declarations of linker variables used to determine size of preallocated variables

soc/nordic/common/dmm.h

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,24 @@ extern "C" {
2323

2424
/** @cond INTERNAL_HIDDEN */
2525

26-
/* Determine if memory region for the peripheral is cacheable. */
27-
#define DMM_IS_REG_CACHEABLE(node_id) \
28-
COND_CODE_1(CONFIG_DCACHE, \
29-
(COND_CODE_1(DT_NODE_HAS_PROP(DT_PHANDLE(node_id, memory_regions), zephyr_memory_attr), \
30-
(DT_PROP(DT_PHANDLE(node_id, memory_regions), zephyr_memory_attr) & DT_MEM_CACHEABLE), \
26+
/* Determine if memory region is cacheable. */
27+
#define DMM_IS_REG_CACHEABLE(node_id) \
28+
COND_CODE_1(CONFIG_DCACHE, \
29+
(COND_CODE_1(DT_NODE_HAS_PROP(node_id, zephyr_memory_attr), \
30+
((DT_PROP(node_id, zephyr_memory_attr) & DT_MEM_CACHEABLE)), \
3131
(0))), (0))
3232

33-
/* Determine required alignment of the static buffers in memory regions. Cache line alignment is
34-
* required if region is cacheable and data cache is enabled.
33+
/* Determine required alignment of the data buffers in specified memory region.
34+
* Cache line alignment is required if region is cacheable and data cache is enabled.
3535
*/
36-
#define DMM_ALIGN_SIZE(node_id) \
36+
#define DMM_REG_ALIGN_SIZE(node_id) \
3737
(DMM_IS_REG_CACHEABLE(node_id) ? CONFIG_DCACHE_LINE_SIZE : sizeof(uint8_t))
3838

39+
/* Determine required alignment of the data buffers in memory region
40+
* associated with specified device node.
41+
*/
42+
#define DMM_ALIGN_SIZE(node_id) DMM_REG_ALIGN_SIZE(DT_PHANDLE(node_id, memory_regions))
43+
3944
/**
4045
* @brief Get reference to memory region associated with the specified device node
4146
*
@@ -46,6 +51,7 @@ extern "C" {
4651
#define DMM_DEV_TO_REG(node_id) \
4752
COND_CODE_1(DT_NODE_HAS_PROP(node_id, memory_regions), \
4853
((void *)DT_REG_ADDR(DT_PHANDLE(node_id, memory_regions))), (NULL))
54+
4955
/**
5056
* @brief Preallocate buffer in memory region associated with the specified device node
5157
*
@@ -55,7 +61,7 @@ extern "C" {
5561
COND_CODE_1(DT_NODE_HAS_PROP(node_id, memory_regions), \
5662
(__attribute__((__section__(LINKER_DT_NODE_REGION_NAME( \
5763
DT_PHANDLE(node_id, memory_regions))))) \
58-
__aligned(DMM_ALIGN_SIZE(node_id))), \
64+
__aligned(DMM_ALIGN_SIZE(node_id))), \
5965
())
6066

6167
#ifdef CONFIG_HAS_NORDIC_DMM

tests/boards/nrf/dmm/src/main.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323
COND_CODE_1(DT_NODE_HAS_PROP(node_id, memory_regions), \
2424
(DT_REG_SIZE(DT_PHANDLE(node_id, memory_regions))), (0))
2525

26+
#if CONFIG_DCACHE
27+
BUILD_ASSERT(DMM_ALIGN_SIZE(DUT_CACHE) == CONFIG_DCACHE_LINE_SIZE);
28+
BUILD_ASSERT(DMM_ALIGN_SIZE(DUT_NOCACHE) == 1);
29+
#endif
30+
2631
struct dmm_test_region {
2732
void *mem_reg;
2833
uintptr_t start;

0 commit comments

Comments
 (0)