reserved-memory: Fix layering violation

Move memory.h out of the way in a more "private" space
(include/linker/devicetree_reserved.h) to prevent polluting the
devicetree space.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
This commit is contained in:
Carlo Caione 2021-09-28 09:15:37 +02:00 committed by Christopher Friedt
commit 8f53f319cd
6 changed files with 122 additions and 154 deletions

View file

@ -1,139 +0,0 @@
/**
* @file
* @brief reserved-memory Devicetree macro public API header file.
*/
/*
* Copyright (c) 2021 Carlo Caione <ccaione@baylibre.com>
*
* 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_ */

View file

@ -46,14 +46,122 @@
/**
* @brief Generate region definitions for all the reserved memory regions
*/
#define DT_RESERVED_MEM_REGIONS() _RESERVED_REGION_APPLY(_RESERVED_REGION_DECLARE)
#define LINKER_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)
#define LINKER_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)
#define LINKER_DT_RESERVED_MEM_SYMBOLS() _RESERVED_REGION_APPLY(_RESERVED_SYMBOL_DECLARE)
/**
* @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:
*
* LINKER_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 LINKER_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:
*
* LINKER_DT_RESERVED_MEM_GET_SIZE(DT_NODELABEL(n)) // 0x1000
*
* @param node_id node identifier
* @return the size of the reserved-memory region
*/
#define LINKER_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:
*
* LINKER_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 LINKER_DT_RESERVED_MEM_GET_PTR_BY_PHANDLE(node_id, ph) \
LINKER_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:
*
* LINKER_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 LINKER_DT_RESERVED_MEM_GET_SIZE_BY_PHANDLE(node_id, ph) \
LINKER_DT_RESERVED_MEM_GET_SIZE(DT_PHANDLE(node_id, ph))

View file

@ -259,7 +259,7 @@ extern char _vector_start[];
extern char _vector_end[];
#if DT_NODE_HAS_STATUS(_NODE_RESERVED, okay)
DT_RESERVED_MEM_SYMBOLS()
LINKER_DT_RESERVED_MEM_SYMBOLS()
#endif
#ifdef CONFIG_SW_VECTOR_RELAY

View file

@ -13,12 +13,12 @@
MEMORY
{
DT_RESERVED_MEM_REGIONS()
LINKER_DT_RESERVED_MEM_REGIONS()
}
SECTIONS
{
DT_RESERVED_MEM_SECTIONS()
LINKER_DT_RESERVED_MEM_SECTIONS()
}
#include <arch/arm64/scripts/linker.ld>

View file

@ -5,7 +5,6 @@
*/
#include <zephyr.h>
#include <devicetree/memory.h>
#include <linker/linker-defs.h>
/* Variables placed in reserved sections */
@ -18,17 +17,17 @@ void main(void)
uint32_t res_size_outer, res_size_inner;
res_ptr_outer =
DT_RESERVED_MEM_GET_PTR_BY_PHANDLE(DT_NODELABEL(sample_driver_outer),
memory_region);
LINKER_DT_RESERVED_MEM_GET_PTR_BY_PHANDLE(DT_NODELABEL(sample_driver_outer),
memory_region);
res_size_outer =
DT_RESERVED_MEM_GET_SIZE_BY_PHANDLE(DT_NODELABEL(sample_driver_outer),
memory_region);
LINKER_DT_RESERVED_MEM_GET_SIZE_BY_PHANDLE(DT_NODELABEL(sample_driver_outer),
memory_region);
printk("Reserved memory address for the outer driver: %p\n", res_ptr_outer);
printk("Reserved memory size for the outer driver: %d\n", res_size_outer);
res_ptr_inner = DT_RESERVED_MEM_GET_PTR(DT_NODELABEL(res1));
res_size_inner = DT_RESERVED_MEM_GET_SIZE(DT_NODELABEL(res1));
res_ptr_inner = LINKER_DT_RESERVED_MEM_GET_PTR(DT_NODELABEL(res1));
res_size_inner = LINKER_DT_RESERVED_MEM_GET_SIZE(DT_NODELABEL(res1));
printk("Reserved memory address for the inner driver: %p\n", res_ptr_inner);
printk("Reserved memory size for the inner driver: %d\n", res_size_inner);

View file

@ -12,12 +12,12 @@
MEMORY
{
DT_RESERVED_MEM_REGIONS()
LINKER_DT_RESERVED_MEM_REGIONS()
}
SECTIONS
{
DT_RESERVED_MEM_SECTIONS()
LINKER_DT_RESERVED_MEM_SECTIONS()
}
#include <arch/arm64/scripts/linker.ld>