Skip to content

Commit

Permalink
iterable_sections: move to specific header
Browse files Browse the repository at this point in the history
Until now iterable sections APIs have been part of the toolchain
(common) headers. They are not strictly related to a toolchain, they
just rely on linker providing support for sections. Most files relied on
indirect includes to access the API, now, it is included as needed.

Signed-off-by: Gerard Marull-Paretas <[email protected]>
  • Loading branch information
gmarull authored and carlescufi committed May 22, 2023
1 parent 4975c94 commit dacb3db
Show file tree
Hide file tree
Showing 133 changed files with 599 additions and 430 deletions.
1 change: 1 addition & 0 deletions arch/x86/core/intel64/irq.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <zephyr/drivers/interrupt_controller/loapic.h>
#include <zephyr/irq.h>
#include <zephyr/logging/log.h>
#include <zephyr/sys/iterable_sections.h>
#include <x86_mmu.h>

LOG_MODULE_DECLARE(os, CONFIG_KERNEL_LOG_LEVEL);
Expand Down
2 changes: 2 additions & 0 deletions boards/arm/ip_k66f/linker.ld
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/linker/iterable_sections.h>

/**
* @file
* @brief Linker command/script file
Expand Down
1 change: 1 addition & 0 deletions drivers/console/uart_mux.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ LOG_MODULE_REGISTER(uart_mux, CONFIG_UART_MUX_LOG_LEVEL);
#include <zephyr/sys/ring_buffer.h>
#include <zephyr/sys/util.h>
#include <zephyr/sys/atomic.h>
#include <zephyr/sys/iterable_sections.h>

#include "gsm_mux.h"

Expand Down
1 change: 1 addition & 0 deletions drivers/pcie/host/pcie.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ LOG_MODULE_REGISTER(pcie, LOG_LEVEL_ERR);
#include <zephyr/sys/check.h>
#include <stdbool.h>
#include <zephyr/drivers/pcie/pcie.h>
#include <zephyr/sys/iterable_sections.h>

#if CONFIG_PCIE_MSI
#include <zephyr/drivers/pcie/msi.h>
Expand Down
1 change: 1 addition & 0 deletions drivers/sensor/sensor_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <ctype.h>
#include <zephyr/device.h>
#include <zephyr/drivers/sensor.h>
#include <zephyr/sys/iterable_sections.h>

#define SENSOR_GET_HELP \
"Get sensor data. Channel names are optional. All channels are read " \
Expand Down
1 change: 1 addition & 0 deletions drivers/usb/uvb/uvb.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <zephyr/kernel.h>
#include <zephyr/device.h>
#include <zephyr/sys/dlist.h>
#include <zephyr/sys/iterable_sections.h>

#include "uvb.h"

Expand Down
2 changes: 1 addition & 1 deletion drivers/usb/uvb/uvb.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
#ifndef ZEPHYR_INCLUDE_UVB
#define ZEPHYR_INCLUDE_UVB

#include <zephyr/linker/linker-defs.h>
#include <zephyr/sys/atomic.h>
#include <zephyr/sys/dlist.h>
#include <zephyr/sys/iterable_sections.h>

#ifdef __cplusplus
extern "C" {
Expand Down
7 changes: 5 additions & 2 deletions include/zephyr/arch/x86/intel64/arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

#include <zephyr/arch/x86/intel64/thread.h>
#include <zephyr/arch/x86/thread_stack.h>
#if defined(CONFIG_PCIE) && !defined(_ASMLANGUAGE)
#include <zephyr/sys/iterable_sections.h>
#endif

#if CONFIG_ISR_STACK_SIZE != (CONFIG_ISR_SUBSTACK_SIZE * CONFIG_ISR_DEPTH)
#error "Check ISR stack configuration (CONFIG_ISR_*)"
Expand Down Expand Up @@ -113,15 +116,15 @@ struct x86_ssf {
CODE_UNREACHABLE; /* LCOV_EXCL_LINE */ \
} while (false)

#endif /* _ASMLANGUAGE */

#ifdef CONFIG_PCIE
#define X86_RESERVE_IRQ(irq_p, name) \
static TYPE_SECTION_ITERABLE(uint8_t, name, irq_alloc, name) = irq_p
#else
#define X86_RESERVE_IRQ(irq_p, name)
#endif

#endif /* _ASMLANGUAGE */

/*
* All Intel64 interrupts are dynamically connected.
*/
Expand Down
1 change: 1 addition & 0 deletions include/zephyr/bluetooth/conn.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <zephyr/bluetooth/addr.h>
#include <zephyr/bluetooth/gap.h>
#include <zephyr/bluetooth/direction.h>
#include <zephyr/sys/iterable_sections.h>

#ifdef __cplusplus
extern "C" {
Expand Down
1 change: 1 addition & 0 deletions include/zephyr/bluetooth/gatt.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <zephyr/bluetooth/conn.h>
#include <zephyr/bluetooth/uuid.h>
#include <zephyr/bluetooth/att.h>
#include <zephyr/sys/iterable_sections.h>

#ifdef __cplusplus
extern "C" {
Expand Down
1 change: 1 addition & 0 deletions include/zephyr/bluetooth/mesh/heartbeat.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include <stdint.h>

#include <zephyr/sys/iterable_sections.h>
#include <zephyr/sys/slist.h>

/**
Expand Down
1 change: 1 addition & 0 deletions include/zephyr/bluetooth/mesh/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <stdint.h>

#include <zephyr/kernel.h>
#include <zephyr/sys/iterable_sections.h>

/**
* @brief Provisioning
Expand Down
1 change: 1 addition & 0 deletions include/zephyr/bluetooth/mesh/proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <stdint.h>

#include <zephyr/kernel.h>
#include <zephyr/sys/iterable_sections.h>

/**
* @brief Proxy
Expand Down
1 change: 1 addition & 0 deletions include/zephyr/bluetooth/services/ias.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

#include <zephyr/bluetooth/conn.h>
#include <zephyr/sys/iterable_sections.h>

#ifdef __cplusplus
extern "C" {
Expand Down
1 change: 1 addition & 0 deletions include/zephyr/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <zephyr/init.h>
#include <zephyr/linker/sections.h>
#include <zephyr/sys/device_mmio.h>
#include <zephyr/sys/iterable_sections.h>
#include <zephyr/sys/util.h>
#include <zephyr/toolchain.h>

Expand Down
1 change: 1 addition & 0 deletions include/zephyr/display/cfb.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include <zephyr/device.h>
#include <zephyr/drivers/display.h>
#include <zephyr/sys/iterable_sections.h>

#ifdef __cplusplus
extern "C" {
Expand Down
1 change: 1 addition & 0 deletions include/zephyr/drivers/emul.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ struct emul;
#include <zephyr/drivers/espi_emul.h>
#include <zephyr/drivers/i2c_emul.h>
#include <zephyr/drivers/spi_emul.h>
#include <zephyr/sys/iterable_sections.h>

/**
* The types of supported buses.
Expand Down
1 change: 1 addition & 0 deletions include/zephyr/drivers/pcie/pcie.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <zephyr/dt-bindings/pcie/pcie.h>
#include <zephyr/types.h>
#include <zephyr/kernel.h>
#include <zephyr/sys/iterable_sections.h>

#ifdef __cplusplus
extern "C" {
Expand Down
1 change: 1 addition & 0 deletions include/zephyr/drivers/sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include <zephyr/types.h>
#include <zephyr/device.h>
#include <zephyr/sys/iterable_sections.h>
#include <errno.h>

#ifdef __cplusplus
Expand Down
1 change: 1 addition & 0 deletions include/zephyr/input/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <zephyr/device.h>
#include <zephyr/dt-bindings/input/input-event-codes.h>
#include <zephyr/kernel.h>
#include <zephyr/sys/iterable_sections.h>

#ifdef __cplusplus
extern "C" {
Expand Down
1 change: 1 addition & 0 deletions include/zephyr/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <zephyr/toolchain.h>
#include <zephyr/tracing/tracing_macros.h>
#include <zephyr/sys/mem_stats.h>
#include <zephyr/sys/iterable_sections.h>

#ifdef __cplusplus
extern "C" {
Expand Down
2 changes: 2 additions & 0 deletions include/zephyr/linker/common-ram.ld
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* SPDX-License-Identifier: Apache-2.0 */

#include <zephyr/linker/iterable_sections.h>

#if defined(CONFIG_NETWORKING)
#ifndef NETWORK_RAM_SECTIONS
#define NETWORK_RAM_SECTIONS \
Expand Down
2 changes: 2 additions & 0 deletions include/zephyr/linker/common-rom/common-rom-bt.ld
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* SPDX-License-Identifier: Apache-2.0 */

#include <zephyr/linker/iterable_sections.h>

ITERABLE_SECTION_ROM(bt_l2cap_fixed_chan, 4)

#if defined(CONFIG_BT_BREDR)
Expand Down
2 changes: 2 additions & 0 deletions include/zephyr/linker/common-rom/common-rom-debug.ld
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* SPDX-License-Identifier: Apache-2.0 */

#include <zephyr/linker/iterable_sections.h>

ITERABLE_SECTION_ROM(tracing_backend, 4)

SECTION_DATA_PROLOGUE(zephyr_dbg_info,,)
Expand Down
2 changes: 2 additions & 0 deletions include/zephyr/linker/common-rom/common-rom-kernel-devices.ld
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* SPDX-License-Identifier: Apache-2.0 */

#include <zephyr/linker/iterable_sections.h>

SECTION_PROLOGUE(initlevel,,)
{
/*
Expand Down
2 changes: 2 additions & 0 deletions include/zephyr/linker/common-rom/common-rom-logging.ld
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* SPDX-License-Identifier: Apache-2.0 */

#include <zephyr/linker/iterable_sections.h>

ITERABLE_SECTION_ROM(log_strings, 4)

ITERABLE_SECTION_ROM(log_const, 4)
Expand Down
2 changes: 2 additions & 0 deletions include/zephyr/linker/common-rom/common-rom-misc.ld
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* SPDX-License-Identifier: Apache-2.0 */

#include <zephyr/linker/iterable_sections.h>

#if defined(CONFIG_EC_HOST_CMD)
ITERABLE_SECTION_ROM(ec_host_cmd_handler, 4)
#endif
Expand Down
2 changes: 2 additions & 0 deletions include/zephyr/linker/common-rom/common-rom-net.ld
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* SPDX-License-Identifier: Apache-2.0 */

#include <zephyr/linker/iterable_sections.h>

#if defined(CONFIG_NET_SOCKETS)
ITERABLE_SECTION_ROM(net_socket_register, 4)
#endif
Expand Down
145 changes: 145 additions & 0 deletions include/zephyr/linker/iterable_sections.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/*
* Copyright (C) 2020, Intel Corporation
* Copyright (C) 2023, Nordic Semiconductor ASA
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef INCLUDE_ZEPHYR_LINKER_ITERABLE_SECTIONS_H_
#define INCLUDE_ZEPHYR_LINKER_ITERABLE_SECTIONS_H_

/**
* @addtogroup iterable_section_apis
* @{
*/

#define Z_LINK_ITERABLE(struct_type) \
_CONCAT(_##struct_type, _list_start) = .; \
KEEP(*(SORT_BY_NAME(._##struct_type.static.*))); \
_CONCAT(_##struct_type, _list_end) = .

#define Z_LINK_ITERABLE_NUMERIC(struct_type) \
_CONCAT(_##struct_type, _list_start) = .; \
KEEP(*(SORT(._##struct_type.static.*_?_*))); \
KEEP(*(SORT(._##struct_type.static.*_??_*))); \
_CONCAT(_##struct_type, _list_end) = .

#define Z_LINK_ITERABLE_ALIGNED(struct_type, align) \
. = ALIGN(align); \
Z_LINK_ITERABLE(struct_type);

#define Z_LINK_ITERABLE_GC_ALLOWED(struct_type) \
_CONCAT(_##struct_type, _list_start) = .; \
*(SORT_BY_NAME(._##struct_type.static.*)); \
_CONCAT(_##struct_type, _list_end) = .

/**
* @brief Define a read-only iterable section output.
*
* @details
* Define an output section which will set up an iterable area
* of equally-sized data structures. For use with STRUCT_SECTION_ITERABLE().
* Input sections will be sorted by name, per ld's SORT_BY_NAME.
*
* This macro should be used for read-only data.
*
* Note that this keeps the symbols in the image even though
* they are not being directly referenced. Use this when symbols
* are indirectly referenced by iterating through the section.
*/
#define ITERABLE_SECTION_ROM(struct_type, subalign) \
SECTION_PROLOGUE(struct_type##_area,,SUBALIGN(subalign)) \
{ \
Z_LINK_ITERABLE(struct_type); \
} GROUP_ROM_LINK_IN(RAMABLE_REGION, ROMABLE_REGION)

/**
* @brief Define a read-only iterable section output, sorted numerically.
*
* This version of ITERABLE_SECTION_ROM() sorts the entries numerically, that
* is, `SECNAME_10` will come after `SECNAME_2`. `_` separator is required, and
* up to 2 numeric digits are handled (0-99).
*
* @see ITERABLE_SECTION_ROM()
*/
#define ITERABLE_SECTION_ROM_NUMERIC(struct_type, subalign) \
SECTION_PROLOGUE(struct_type##_area, EMPTY, SUBALIGN(subalign)) \
{ \
Z_LINK_ITERABLE_NUMERIC(struct_type); \
} GROUP_ROM_LINK_IN(RAMABLE_REGION, ROMABLE_REGION)

/**
* @brief Define a garbage collectable read-only iterable section output.
*
* @details
* Define an output section which will set up an iterable area
* of equally-sized data structures. For use with STRUCT_SECTION_ITERABLE().
* Input sections will be sorted by name, per ld's SORT_BY_NAME.
*
* This macro should be used for read-only data.
*
* Note that the symbols within the section can be garbage collected.
*/
#define ITERABLE_SECTION_ROM_GC_ALLOWED(struct_type, subalign) \
SECTION_PROLOGUE(struct_type##_area,,SUBALIGN(subalign)) \
{ \
Z_LINK_ITERABLE_GC_ALLOWED(struct_type); \
} GROUP_LINK_IN(ROMABLE_REGION)

/**
* @brief Define a read-write iterable section output.
*
* @details
* Define an output section which will set up an iterable area
* of equally-sized data structures. For use with STRUCT_SECTION_ITERABLE().
* Input sections will be sorted by name, per ld's SORT_BY_NAME.
*
* This macro should be used for read-write data that is modified at runtime.
*
* Note that this keeps the symbols in the image even though
* they are not being directly referenced. Use this when symbols
* are indirectly referenced by iterating through the section.
*/
#define ITERABLE_SECTION_RAM(struct_type, subalign) \
SECTION_DATA_PROLOGUE(struct_type##_area,,SUBALIGN(subalign)) \
{ \
Z_LINK_ITERABLE(struct_type); \
} GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION)

/**
* @brief Define a read-write iterable section output, sorted numerically.
*
* This version of ITERABLE_SECTION_RAM() sorts the entries numerically, that
* is, `SECNAME10` will come after `SECNAME2`. Up to 2 numeric digits are
* handled (0-99).
*
* @see ITERABLE_SECTION_RAM()
*/
#define ITERABLE_SECTION_RAM_NUMERIC(struct_type, subalign) \
SECTION_PROLOGUE(struct_type##_area, EMPTY, SUBALIGN(subalign)) \
{ \
Z_LINK_ITERABLE_NUMERIC(struct_type); \
} GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION)

/**
* @brief Define a garbage collectable read-write iterable section output.
*
* @details
* Define an output section which will set up an iterable area
* of equally-sized data structures. For use with STRUCT_SECTION_ITERABLE().
* Input sections will be sorted by name, per ld's SORT_BY_NAME.
*
* This macro should be used for read-write data that is modified at runtime.
*
* Note that the symbols within the section can be garbage collected.
*/
#define ITERABLE_SECTION_RAM_GC_ALLOWED(struct_type, subalign) \
SECTION_DATA_PROLOGUE(struct_type##_area,,SUBALIGN(subalign)) \
{ \
Z_LINK_ITERABLE_GC_ALLOWED(struct_type); \
} GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION)

/**
* @}
*/ /* end of struct_section_apis */

#endif /* INCLUDE_ZEPHYR_LINKER_ITERABLE_SECTIONS_H_ */
Loading

0 comments on commit dacb3db

Please sign in to comment.