-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Add reserved-memory support #35460
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
Merged
Merged
Add reserved-memory support #35460
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| description: | | ||
| Reserved memory - Each child of the reserved-memory node specifies one or | ||
| more regions of reserved memory. Regions in the /reserved-memory node may be | ||
| referenced by other device nodes by adding a memory-region property to the | ||
| device node. | ||
|
|
||
| compatible: "reserved-memory" | ||
|
|
||
carlocaione marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| include: | ||
| - name: base.yaml | ||
| property-allowlist: ['#address-cells', '#size-cells'] | ||
|
|
||
| child-binding: | ||
| description: Regions | ||
| properties: | ||
| label: | ||
| type: string | ||
| required: false | ||
| description: Human readable string describing the device (used as device_get_binding() argument) | ||
| reg: | ||
| type: array | ||
| description: register space | ||
| required: true | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| /** | ||
| * @file | ||
| * @brief reserved-memory Devicetree macro public API header file. | ||
| */ | ||
|
|
||
| /* | ||
| * Copyright (c) 2021 Carlo Caione <[email protected]> | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| #ifndef ZEPHYR_INCLUDE_DEVICETREE_MEMORY_H_ | ||
| #define ZEPHYR_INCLUDE_DEVICETREE_MEMORY_H_ | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| /** | ||
| * @defgroup devicetree-reserved Devicetree reserved-memory API | ||
| * @ingroup devicetree | ||
| * @{ | ||
| */ | ||
|
|
||
| /** | ||
| * @brief Get the pointer to the reserved-memory region | ||
| * | ||
| * Example devicetree fragment: | ||
| * | ||
| * reserved: reserved-memory { | ||
| * compatible = "reserved-memory"; | ||
| * ... | ||
| * n: node { | ||
| * reg = <0x42000000 0x1000>; | ||
| * }; | ||
| * }; | ||
| * | ||
| * Example usage: | ||
| * | ||
| * DT_RESERVED_MEM_GET_PTR(DT_NODELABEL(n)) // (uint8_t *) 0x42000000 | ||
| * | ||
| * @param node_id node identifier | ||
| * @return pointer to the beginning of the reserved-memory region | ||
| */ | ||
| #define DT_RESERVED_MEM_GET_PTR(node_id) _DT_RESERVED_START(node_id) | ||
|
|
||
| /** | ||
| * @brief Get the size of the reserved-memory region | ||
| * | ||
| * Example devicetree fragment: | ||
| * | ||
| * reserved: reserved-memory { | ||
| * compatible = "reserved-memory"; | ||
| * ... | ||
| * n: node { | ||
| * reg = <0x42000000 0x1000>; | ||
| * }; | ||
| * }; | ||
| * | ||
| * Example usage: | ||
| * | ||
| * DT_RESERVED_MEM_GET_SIZE(DT_NODELABEL(n)) // 0x1000 | ||
| * | ||
| * @param node_id node identifier | ||
| * @return the size of the reserved-memory region | ||
| */ | ||
| #define DT_RESERVED_MEM_GET_SIZE(node_id) DT_REG_SIZE(node_id) | ||
|
|
||
| /** | ||
| * @brief Get the pointer to the reserved-memory region from a memory-reserved | ||
| * phandle | ||
| * | ||
| * Example devicetree fragment: | ||
| * | ||
| * reserved: reserved-memory { | ||
| * compatible = "reserved-memory"; | ||
| * ... | ||
| * res0: res { | ||
| * reg = <0x42000000 0x1000>; | ||
| * label = "res0"; | ||
| * }; | ||
| * }; | ||
| * | ||
| * n: node { | ||
| * memory-region = <&res0>; | ||
| * }; | ||
| * | ||
| * Example usage: | ||
| * | ||
| * DT_RESERVED_MEM_GET_PTR_BY_PHANDLE(DT_NODELABEL(n), memory_region) // (uint8_t *) 0x42000000 | ||
| * | ||
| * @param node_id node identifier | ||
| * @param ph phandle to reserved-memory region | ||
| * | ||
| * @return pointer to the beginning of the reserved-memory region | ||
| */ | ||
| #define DT_RESERVED_MEM_GET_PTR_BY_PHANDLE(node_id, ph) \ | ||
| DT_RESERVED_MEM_GET_PTR(DT_PHANDLE(node_id, ph)) | ||
|
|
||
| /** | ||
| * @brief Get the size of the reserved-memory region from a memory-reserved | ||
| * phandle | ||
| * | ||
| * Example devicetree fragment: | ||
| * | ||
| * reserved: reserved-memory { | ||
| * compatible = "reserved-memory"; | ||
| * ... | ||
| * res0: res { | ||
| * reg = <0x42000000 0x1000>; | ||
| * label = "res0"; | ||
| * }; | ||
| * }; | ||
| * | ||
| * n: node { | ||
| * memory-region = <&res0>; | ||
| * }; | ||
| * | ||
| * Example usage: | ||
| * | ||
| * DT_RESERVED_MEM_GET_SIZE_BY_PHANDLE(DT_NODELABEL(n), memory_region) // (uint8_t *) 0x42000000 | ||
| * | ||
| * @param node_id node identifier | ||
| * @param ph phandle to reserved-memory region | ||
| * | ||
| * @return size of the reserved-memory region | ||
| */ | ||
| #define DT_RESERVED_MEM_GET_SIZE_BY_PHANDLE(node_id, ph) \ | ||
| DT_RESERVED_MEM_GET_SIZE(DT_PHANDLE(node_id, ph)) | ||
|
|
||
| /** | ||
| * @} | ||
| */ | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
|
|
||
| #endif /* ZEPHYR_INCLUDE_DEVICETREE_MEMORY_H_ */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| /* | ||
| * Copyright (c) 2021, Carlo Caione <[email protected]> | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * Generate memory regions and sections from reserved-memory nodes. | ||
| */ | ||
|
|
||
| #include <devicetree.h> | ||
|
|
||
| /* Reserved memory node */ | ||
| #define _NODE_RESERVED DT_INST(0, reserved_memory) | ||
|
|
||
| /* Unquoted region label */ | ||
| #define _DT_LABEL_TOKEN(res) DT_STRING_TOKEN(res, label) | ||
|
|
||
| /* _start and _end section symbols */ | ||
| #define _DT_RESERVED_PREFIX(res) UTIL_CAT(__, _DT_LABEL_TOKEN(res)) | ||
| #define _DT_RESERVED_START(res) UTIL_CAT(_DT_RESERVED_PREFIX(res), _start) | ||
carlocaione marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| #define _DT_RESERVED_END(res) UTIL_CAT(_DT_RESERVED_PREFIX(res), _end) | ||
|
|
||
| /* Declare a reserved memory region */ | ||
| #define _RESERVED_REGION_DECLARE(res) DT_STRING_TOKEN(res, label) (rw) : \ | ||
| ORIGIN = DT_REG_ADDR(res), \ | ||
| LENGTH = DT_REG_SIZE(res) | ||
|
|
||
| /* Declare a reserved memory section */ | ||
| #define _RESERVED_SECTION_DECLARE(res) SECTION_DATA_PROLOGUE(_DT_LABEL_TOKEN(res), ,) \ | ||
| { \ | ||
| _DT_RESERVED_START(res) = .; \ | ||
| KEEP(*(._DT_LABEL_TOKEN(res))) \ | ||
| KEEP(*(._DT_LABEL_TOKEN(res).*)) \ | ||
| _DT_RESERVED_END(res) = \ | ||
| _DT_RESERVED_START(res) + DT_REG_SIZE(res); \ | ||
| } GROUP_LINK_IN(_DT_LABEL_TOKEN(res)) | ||
|
|
||
| /* Declare reserved memory linker symbols */ | ||
| #define _RESERVED_SYMBOL_DECLARE(res) extern char _DT_RESERVED_START(res)[]; \ | ||
| extern char _DT_RESERVED_END(res)[]; | ||
|
|
||
| /* Apply a macro to a reserved memory region */ | ||
| #define _RESERVED_REGION_APPLY(f) \ | ||
| COND_CODE_1(IS_ENABLED(UTIL_CAT(_NODE_RESERVED, _EXISTS)), \ | ||
carlocaione marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| (DT_FOREACH_CHILD(_NODE_RESERVED, f)), ()) | ||
|
|
||
| /** | ||
| * @brief Generate region definitions for all the reserved memory regions | ||
| */ | ||
| #define DT_RESERVED_MEM_REGIONS() _RESERVED_REGION_APPLY(_RESERVED_REGION_DECLARE) | ||
|
|
||
| /** | ||
| * @brief Generate section definitions for all the reserved memory regions | ||
| */ | ||
| #define DT_RESERVED_MEM_SECTIONS() _RESERVED_REGION_APPLY(_RESERVED_SECTION_DECLARE) | ||
|
|
||
| /** | ||
| * @brief Generate linker script symbols for all the reserved memory regions | ||
| */ | ||
| #define DT_RESERVED_MEM_SYMBOLS() _RESERVED_REGION_APPLY(_RESERVED_SYMBOL_DECLARE) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.