mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: Marco Felsch <m.felsch@pengutronix.de>, barebox@lists.infradead.org
Subject: Re: [PATCH 1/3] fixup! common: add initial barebox deep-probe support
Date: Wed, 28 Apr 2021 12:42:08 +0200
Message-ID: <05cf257f-fb53-1465-33d9-d5d69dca6e9d@pengutronix.de> (raw)
In-Reply-To: <20210428102821.2287-1-m.felsch@pengutronix.de>

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@pengutronix.de>

-- 
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@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


  parent reply	other threads:[~2021-04-28 10:43 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-16  9:49 [PATCH v4 00/17] barebox deep probe support Sascha Hauer
2021-04-16  9:49 ` [PATCH 01/17] imx53: remove unused imx53_add_nand Sascha Hauer
2021-04-16  9:49 ` [PATCH 02/17] of: platform: remove check of already added devices Sascha Hauer
2021-04-16  9:49 ` [PATCH 03/17] of: platform: Keep track of populated platform devices Sascha Hauer
2021-04-16  9:49 ` [PATCH 04/17] of: base: move memory init from DT to initcall Sascha Hauer
2021-04-16  9:49 ` [PATCH 05/17] of: base: move clock init from of_probe() to barebox_register_of() Sascha Hauer
2021-04-16  9:49 ` [PATCH 06/17] of: Set of_chosen and of_model earlier Sascha Hauer
2021-04-16  9:49 ` [PATCH 07/17] of: implement of_get_stdoutpath() Sascha Hauer
2021-04-16  9:49 ` [PATCH 08/17] initcall: add of_populate_initcall Sascha Hauer
2021-04-16  9:49 ` [PATCH 09/17] common: add initial barebox deep-probe support Sascha Hauer
2021-04-19  7:16   ` Ahmad Fatoum
2021-04-26  8:15     ` Marco Felsch
2021-04-16  9:49 ` [PATCH 10/17] pinctrl: Find controller node first Sascha Hauer
2021-04-16  9:49 ` [PATCH 11/17] common: Explicitly probe consoles earlier with deep probe Sascha Hauer
2021-04-16  9:49 ` [PATCH 12/17] pinctrl: Add deep probe support Sascha Hauer
2021-04-16  9:49 ` [PATCH 13/17] ARM: i.MX: esdctl: add deep-probe support Sascha Hauer
2021-04-16  9:49 ` [PATCH 14/17] ARM: stm32mp: ddrctrl: " Sascha Hauer
2021-04-16  9:49 ` [PATCH 15/17] ARM: boards: mx6-sabrelite: " Sascha Hauer
2021-04-16  9:49 ` [PATCH 16/17] ARM: i.MX Phytec physom: convert to board driver Sascha Hauer
2021-04-16  9:49 ` [PATCH 17/17] ARM: i.MX Phytec physom: Add deep-probe support Sascha Hauer
2021-04-19  7:12   ` Ahmad Fatoum
2021-04-26  9:20     ` Marco Felsch
2021-04-26  9:26       ` Marco Felsch
2021-04-26  9:36       ` Ahmad Fatoum
2021-04-26 10:03         ` Marco Felsch
2021-04-19  7:35 ` [PATCH v4 00/17] barebox deep probe support Ahmad Fatoum
2021-04-28 10:28 ` [PATCH 1/3] fixup! common: add initial barebox deep-probe support Marco Felsch
2021-04-28 10:28   ` [PATCH 2/3] fixup! ARM: boards: mx6-sabrelite: add " Marco Felsch
2021-04-28 10:28   ` [PATCH 3/3] fixup! ARM: i.MX Phytec physom: Add " Marco Felsch
2021-04-28 10:42   ` Ahmad Fatoum [this message]
2021-04-28 10:48     ` [PATCH 1/3] fixup! common: add initial barebox " Marco Felsch
2021-04-28 11:21   ` Marco Felsch
2021-05-03 11:54   ` Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=05cf257f-fb53-1465-33d9-d5d69dca6e9d@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=m.felsch@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

mail archive of the barebox mailing list

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://lore.barebox.org/barebox/0 barebox/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 barebox barebox/ https://lore.barebox.org/barebox \
		barebox@lists.infradead.org barebox@lists.infradead.org
	public-inbox-index barebox

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git