--- Hi, this is the reworked version with Ahmad's review feedback. Regards, Marco common/deep-probe.c | 38 +++++++++++++++++++++++++++++-- include/asm-generic/barebox.lds.h | 10 +------- include/deep-probe.h | 31 +++++++++++++------------ 3 files changed, 53 insertions(+), 26 deletions(-) diff --git a/common/deep-probe.c b/common/deep-probe.c index 9fc67f170c..ef927be02f 100644 --- a/common/deep-probe.c +++ b/common/deep-probe.c @@ -2,8 +2,16 @@ #include <common.h> #include <deep-probe.h> +#include <linux/list.h> #include <of.h> +struct deep_probe_entry { + struct list_head entry; + const char *compatible; +}; + +static LIST_HEAD(boards_list); + enum deep_probe_state { DEEP_PROBE_UNKONWN = -1, DEEP_PROBE_NOT_SUPPORTED, @@ -12,6 +20,33 @@ enum deep_probe_state { static enum deep_probe_state boardstate = DEEP_PROBE_UNKONWN; +int deep_probe_enable_board(const struct driver_d *board_driver, const char *compatible) +{ + struct deep_probe_entry *new; + + if (!board_driver && !compatible) + return -EINVAL; + + if (board_driver) { + const struct of_device_id *of_device_ids = board_driver->of_compatible; + + for (; of_device_ids->compatible; of_device_ids++) { + new = xzalloc(sizeof(*new)); + new->compatible = of_device_ids->compatible; + list_add(&new->entry, &boards_list); + } + } + + if (compatible) { + new = xzalloc(sizeof(*new)); + new->compatible = compatible; + list_add(&new->entry, &boards_list); + } + + return 0; +} +EXPORT_SYMBOL_GPL(deep_probe_enable_board); + bool deep_probe_is_supported(void) { struct deep_probe_entry *board; @@ -20,8 +55,7 @@ bool deep_probe_is_supported(void) return boardstate; /* determine boardstate */ - for (board = &__barebox_deep_probe_start; - board != &__barebox_deep_probe_end; board++) { + list_for_each_entry(board, &boards_list, entry) { if (of_machine_is_compatible(board->compatible)) { boardstate = DEEP_PROBE_SUPPORTED; return true; diff --git a/include/asm-generic/barebox.lds.h b/include/asm-generic/barebox.lds.h index c5f9d97547..a7d32160d1 100644 --- a/include/asm-generic/barebox.lds.h +++ b/include/asm-generic/barebox.lds.h @@ -114,13 +114,6 @@ KEEP(*(.rsa_keys.rodata.*)); \ __rsa_keys_end = .; \ -#define BAREBOX_DEEP_PROBE \ - STRUCT_ALIGN(); \ - __barebox_deep_probe_start = .; \ - KEEP(*(SORT_BY_NAME(.barebox_deep_probe*))) \ - __barebox_deep_probe_end = .; - - #ifdef CONFIG_CONSTRUCTORS #define KERNEL_CTORS() . = ALIGN(8); \ __ctors_start = .; \ @@ -143,8 +136,7 @@ BAREBOX_CLK_TABLE \ BAREBOX_DTB \ BAREBOX_RSA_KEYS \ - BAREBOX_PCI_FIXUP \ - BAREBOX_DEEP_PROBE + BAREBOX_PCI_FIXUP #if defined(CONFIG_ARCH_BAREBOX_MAX_BARE_INIT_SIZE) && \ CONFIG_ARCH_BAREBOX_MAX_BARE_INIT_SIZE < CONFIG_BAREBOX_MAX_BARE_INIT_SIZE diff --git a/include/deep-probe.h b/include/deep-probe.h index a646c10340..327e02071e 100644 --- a/include/deep-probe.h +++ b/include/deep-probe.h @@ -2,25 +2,26 @@ #ifndef __DEEP_PROBE_H #define __DEEP_PROBE_H -#include <linux/stringify.h> -#include <linux/types.h> - -struct deep_probe_entry { - const char *compatible; -}; +struct driver_d; bool deep_probe_is_supported(void); +int deep_probe_enable_board(const struct driver_d *board_driver, const char *compatible); -extern struct deep_probe_entry __barebox_deep_probe_start; -extern struct deep_probe_entry __barebox_deep_probe_end; +#define deep_probe_enable_board_driver(drv) \ + static int __init drv##deep_probe_init(void) \ + { \ + return deep_probe_enable_board(&drv, NULL); \ + } \ + pure_initcall(drv##deep_probe_init) -#define __BAREBOX_DEEP_PROBE_ENABLE(_entry,_compatible) \ - static const struct deep_probe_entry _entry \ - __attribute__ ((used,section (".barebox_deep_probe_" __stringify(_entry)))) = { \ - .compatible = _compatible, \ - } +#define _deep_probe_enable_compatible(id, compatible) \ + static int __init id(void) \ + { \ + return deep_probe_enable_board(NULL, compatible);\ + } \ + pure_initcall(id) -#define BAREBOX_DEEP_PROBE_ENABLE(_compatible) \ - __BAREBOX_DEEP_PROBE_ENABLE(__UNIQUE_ID(deepprobe),_compatible) +#define deep_probe_enable_board_compatible(compatible) \ + _deep_probe_enable_compatible(__PASTE(__UNIQUE_ID(deep_probe), _init), compatible) #endif /* __DEEP_PROBE_H */ -- 2.29.2 _______________________________________________ barebox mailing list barebox@xxxxxxxxxxxxxxxxxxx http://lists.infradead.org/mailman/listinfo/barebox