Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
devicetree_reserved.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2021, Carlo Caione <ccaione@baylibre.com>
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Generate memory regions and sections from reserved-memory nodes.
7 */
8
9#include <devicetree.h>
10
11/* Reserved memory node */
12#define _NODE_RESERVED DT_INST(0, reserved_memory)
13
14/* Unquoted region label */
15#define _DT_LABEL_TOKEN(res) DT_STRING_TOKEN(res, label)
16
17/* _start and _end section symbols */
18#define _DT_RESERVED_PREFIX(res) UTIL_CAT(__, _DT_LABEL_TOKEN(res))
19#define _DT_RESERVED_START(res) UTIL_CAT(_DT_RESERVED_PREFIX(res), _start)
20#define _DT_RESERVED_END(res) UTIL_CAT(_DT_RESERVED_PREFIX(res), _end)
21
22/* Declare a reserved memory region */
23#define _RESERVED_REGION_DECLARE(res) DT_STRING_TOKEN(res, label) (rw) : \
24 ORIGIN = DT_REG_ADDR(res), \
25 LENGTH = DT_REG_SIZE(res)
26
27/* Declare a reserved memory section */
28#define _RESERVED_SECTION_DECLARE(res) SECTION_DATA_PROLOGUE(_DT_LABEL_TOKEN(res), ,) \
29 { \
30 _DT_RESERVED_START(res) = .; \
31 KEEP(*(._DT_LABEL_TOKEN(res))) \
32 KEEP(*(._DT_LABEL_TOKEN(res).*)) \
33 _DT_RESERVED_END(res) = \
34 _DT_RESERVED_START(res) + DT_REG_SIZE(res); \
35 } GROUP_LINK_IN(_DT_LABEL_TOKEN(res))
36
37/* Declare reserved memory linker symbols */
38#define _RESERVED_SYMBOL_DECLARE(res) extern char _DT_RESERVED_START(res)[]; \
39 extern char _DT_RESERVED_END(res)[];
40
41/* Apply a macro to a reserved memory region */
42#define _RESERVED_REGION_APPLY(f) \
43 COND_CODE_1(IS_ENABLED(UTIL_CAT(_NODE_RESERVED, _EXISTS)), \
44 (DT_FOREACH_CHILD(_NODE_RESERVED, f)), ())
45
49#define DT_RESERVED_MEM_REGIONS() _RESERVED_REGION_APPLY(_RESERVED_REGION_DECLARE)
50
54#define DT_RESERVED_MEM_SECTIONS() _RESERVED_REGION_APPLY(_RESERVED_SECTION_DECLARE)
55
59#define DT_RESERVED_MEM_SYMBOLS() _RESERVED_REGION_APPLY(_RESERVED_SYMBOL_DECLARE)
Devicetree main header.