Re: [PATCH 1/3] fixup! common: add initial barebox deep-probe support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello Marco,

On 28.04.21 12:28, Marco Felsch wrote:
> ---
> Hi,
> 
> this is just a proposal to change the current linker array approach to
> an initcall approach. Why? Because now we can simply register a
> board-driver without having to list each compatible. 
> 
> I used the pure_initcall without adding a new one, since the
> documentation says that pure_initcalls are used to init variables. In
> our case we init boards_list.
> 
> Regards,
>   Marco
> 
>  common/deep-probe.c               | 38 +++++++++++++++++++++++++++++--
>  include/asm-generic/barebox.lds.h | 10 +-------
>  include/deep-probe.h              | 34 +++++++++++++++------------
>  3 files changed, 56 insertions(+), 26 deletions(-)
> 
> diff --git a/common/deep-probe.c b/common/deep-probe.c
> index 9fc67f170c..6b04b4f5da 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;
> +};
> +
> +LIST_HEAD(boards_list);

Looks like it can be made static?

> +
>  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..e00bd9bafe 100644
> --- a/include/deep-probe.h
> +++ b/include/deep-probe.h
> @@ -2,25 +2,29 @@
>  #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);
> +
> +#define _deep_probe_enable_driver(id,drv)			\
> +	static int __init id(void)				\

Can't you use drv ## deep_probe_init here and drop id?

> +	{							\
> +		return deep_probe_enable_board(&drv,NULL);	\

Missing whitespace

> +	}							\
> +	pure_initcall(id)
>  
> -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)			\
> +	_deep_probe_enable_driver(__UNIQUE_ID(deepprobe),drv)
>  
> -#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(__UNIQUE_ID(deepprobe),compatible)
>  
>  #endif /* __DEEP_PROBE_H */

Apart from that, I like it:

Reviewed-by: Ahmad Fatoum <a.fatoum@xxxxxxxxxxxxxx>

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux