[PATCH] mci: bcm2835: Set mci host for sdhci

2024-05-21 Thread Jonas Richardsen
The pointer `sdhci.mci` is currently not being set for the bcm2835. This
leads to a null pointer dereference for example in `sdhci_wait_idle()`
if the `sdhci_read` function fails or times out.

Set the pointer within the `bcm2835_mci_probe` function. This is
analogous to the behaviour seen in `arasan_sdhci_probe`,
`fsl_esdhc_probe`, `rk_sdhci_probe` and other, similar functions.

Signed-off-by: Jonas Richardsen 
---
 drivers/mci/mci-bcm2835.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/mci/mci-bcm2835.c b/drivers/mci/mci-bcm2835.c
index 3546cc3a32..7fcf4f905b 100644
--- a/drivers/mci/mci-bcm2835.c
+++ b/drivers/mci/mci-bcm2835.c
@@ -382,6 +382,7 @@ static int bcm2835_mci_probe(struct device *hw_dev)
host->hw_dev = hw_dev;
host->max_clock = clk_get_rate(clk);
 
+   host->sdhci.mci = &host->mci;
host->sdhci.read32 = bcm2835_sdhci_read32;
host->sdhci.write32 = bcm2835_sdhci_write32;
 
-- 
2.42.0




[PATCH v2] driver: add Linux struct platform_device/driver compatibility wrapper

2024-05-21 Thread Ahmad Fatoum
In Linux struct platform_device is a superset on top of struct device with
additions related to specifics of the platform bus.

In barebox, there is no such distinction, so porting of Linux drivers
usually involves a lot of renaming and substitutions.

The naive approach of

  #define platform_device device
  #define platform_driver driver

won't work though as struct device dev needs to be a member of
platform_device as kernel code has a lot of instances of &pdev->dev.

Therefore, let's tackle this differently:

 1) We add struct device as only member of struct platform_device and
define all members in both and have them overlap by use of a union.

 2) Have functions that receive a platform_device/driver in Linux, but
a device/driver in barebox accept either by using GCC's transparent
union extension.

More changes are needed, e.g. in  to use __param_either where
appropriate, but this can be added alongside future kernel driver ports.

The use of __param_either instead of defining the union with a tag and
using that is intentional to keep prototypes self-documenting. This
violates the C standard's strict aliasing rule, but this doesn't matter
for us anyway as we compile barebox with -fno-strict-aliasing.

Signed-off-by: Ahmad Fatoum 
---
v1 -> v2:
  - fix remove callback to accept platform_device instead of
platform_driver
---
 include/device.h   | 124 +
 include/driver.h   |  40 ++-
 include/linux/compiler_types.h |  11 +++
 3 files changed, 98 insertions(+), 77 deletions(-)

diff --git a/include/device.h b/include/device.h
index 8c3561e5a2f6..abe9707fb8f5 100644
--- a/include/device.h
+++ b/include/device.h
@@ -7,6 +7,8 @@
 #define DEVICE_H
 
 #include 
+#include 
+#include 
 
 enum dev_dma_coherence {
DEV_DMA_COHERENCE_DEFAULT = 0,
@@ -23,83 +25,85 @@ struct platform_device_id;
 struct of_device_id;
 
 /** @brief Describes a particular device present in the system */
-struct device {
-   /*! This member (and 'type' described below) is used to match
-* with a driver. This is a descriptive name and could be
-* MPC5XXX_ether or imx_serial. Unless absolutely necessary,
-* should not be modified directly and dev_set_name() should
-* be used instead.
-*/
-   char *name;
+struct platform_device {
+   struct_group_tagged(device, dev,
+   /*! This member (and 'type' described below) is used to match
+* with a driver. This is a descriptive name and could be
+* MPC5XXX_ether or imx_serial. Unless absolutely necessary,
+* should not be modified directly and dev_set_name() should
+* be used instead.
+*/
+   char *name;
 
-   /*! This member is used to store device's unique name as
-*  obtained by calling dev_id(). Internal field, do not
-*  access it directly.
- */
-   char *unique_name;
-   /*! The id is used to uniquely identify a device in the system. The id
-* will show up under /dev/ as the device's name. Usually this is
-* something like eth0 or nor0. */
-   int id;
+   /*! This member is used to store device's unique name as
+*  obtained by calling dev_id(). Internal field, do not
+*  access it directly.
+ */
+   char *unique_name;
+   /*! The id is used to uniquely identify a device in the system. 
The id
+* will show up under /dev/ as the device's name. Usually this 
is
+* something like eth0 or nor0. */
+   int id;
 
-   enum dev_dma_coherence dma_coherent;
+   enum dev_dma_coherence dma_coherent;
 
-   struct resource *resource;
-   int num_resources;
+   struct resource *resource;
+   int num_resources;
 
-   void *platform_data; /*! board specific information about this device */
+   void *platform_data; /*! board specific information about this 
device */
 
-   /*! Devices of a particular class normaly need to store more
-* information than struct device holds.
-*/
-   void *priv;
-   void *type_data; /*! In case this device is a specific device, this 
pointer
- * points to the type specific device, i.e. 
eth_device
- */
-   struct driver *driver; /*! The driver for this device */
+   /*! Devices of a particular class normaly need to store more
+* information than struct device holds.
+*/
+   void *priv;
+   void *type_data; /*! In case this device is a specific 
device, this pointer
+ * points to the type specific device, 
i.e. eth_device
+ */
+   struct driver *driver; /*! 

Re: [PATCH 0/4] make more use of handoff data

2024-05-21 Thread Sascha Hauer


On Tue, 21 May 2024 12:49:09 +0200, Sascha Hauer wrote:
> struct boarddata is a mechanism to pass a ARM machine number from PBL to
> barebox proper. The EFI payload also uses it to pass some custom
> pointers to barebox proper. handoff data was created for exactly this
> purpose, so retire boarddata and use handoff data instead.
> 
> @afa, the efi patch is compile tested only. Could you give it a try?
> 
> [...]

Applied, thanks!

[1/4] handoff-data: put handoff data into data section
  https://git.pengutronix.de/cgit/barebox/commit/?id=bd7ecdd33ea7 (link may 
not be stable)
[2/4] efi-payload: use handoff data to pass data to barebox proper
  https://git.pengutronix.de/cgit/barebox/commit/?id=26b93791e9d3 (link may 
not be stable)
[3/4] ARM: beagle: setup C environment early
  https://git.pengutronix.de/cgit/barebox/commit/?id=439d2f864760 (link may 
not be stable)
[4/4] ARM: replace boarddata with handoff data
  https://git.pengutronix.de/cgit/barebox/commit/?id=602aaa68a66d (link may 
not be stable)

Best regards,
-- 
Sascha Hauer 




[PATCH] fixup! kbuild: add support for merged defconfigs

2024-05-21 Thread Ahmad Fatoum
scripts: list-defconfigs.sh: remove interleaves new lines from output

Github actions apparently chokes on new lines in the middle of the JSON,
so let's avoid them.

Signed-off-by: Ahmad Fatoum 
---
 scripts/list-defconfigs.sh | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/scripts/list-defconfigs.sh b/scripts/list-defconfigs.sh
index d7516425f8e3..5eaaab51cc61 100755
--- a/scripts/list-defconfigs.sh
+++ b/scripts/list-defconfigs.sh
@@ -4,12 +4,13 @@
 # Output json formatted defconfig list for Github Action consumption
 ARCH=${@:-$(for a in arch/*/; do basename $a; done)}
 
-echo '{ "include" : [ '
+# Github chokes on interleaved new lines, thus use printf
+printf '{ "include" : [ '
 for arch in $ARCH; do
make ARCH=$arch CROSS_COMPILE= help | \
awk '/_defconfig/ { print $1  }' | \
xargs -i printf '{ "arch": "%s", "config": "%s" }\n' \
"$arch" "{}" | \
paste -sd ',' -
-done | paste -sd ',' -
+done | paste -sd ',' - | tr -d '\n'
 echo '] }'
-- 
2.39.2




Re: [PATCH v2 1/3] pinctrl: split off consumer API into linux/pinctrl/consumer.h

2024-05-21 Thread Sascha Hauer


On Tue, 21 May 2024 14:13:55 +0200, Ahmad Fatoum wrote:
> Follow-up patches will align the barebox pinctrl consumer API with
> Linux'. So it makes sense to have the header called the same as well.
> Users of the old pinctrl.h header are unaffected as it will include
> the new .
> 
> 

Applied, thanks!

[1/3] pinctrl: split off consumer API into linux/pinctrl/consumer.h
  https://git.pengutronix.de/cgit/barebox/commit/?id=6da06fc95ba1 (link may 
not be stable)
[2/3] pinctrl: rename barebox pinctrl_select_state to pinctrl_get_select
  https://git.pengutronix.de/cgit/barebox/commit/?id=ee4be3efa1e7 (link may 
not be stable)
[3/3] pinctrl: implement pinctrl_lookup_state/select_state
  https://git.pengutronix.de/cgit/barebox/commit/?id=da674fab4c62 (link may 
not be stable)

Best regards,
-- 
Sascha Hauer 




Re: [PATCH 2/4] efi-payload: use handoff data to pass data to barebox proper

2024-05-21 Thread Ahmad Fatoum
On 21.05.24 12:49, Sascha Hauer wrote:
> EFI payload uses custom fields in struct boarddata to pass data from PBL
> to barebox proper. handoff data was created for exactly this purpose.
> Now that we have it, switch EFI payload over to use it.
> 
> Signed-off-by: Sascha Hauer 

Tested-by: Ahmad Fatoum 

Tested with barebox as EFI payload compiled for arm64 with both
Tianocore and barebox as EFI loader.

> ---
>  efi/payload/boarddata.c| 12 +++-
>  efi/payload/entry-multi.c  | 16 +++-
>  include/boarddata.h|  4 
>  include/efi/efi-payload.h  |  5 +
>  include/pbl/handoff-data.h |  1 +
>  5 files changed, 20 insertions(+), 18 deletions(-)
> 
> diff --git a/efi/payload/boarddata.c b/efi/payload/boarddata.c
> index 3260e31c7b..d4e4b5ac1d 100644
> --- a/efi/payload/boarddata.c
> +++ b/efi/payload/boarddata.c
> @@ -8,25 +8,27 @@
>  
>  #include 
>  #include 
> -#include 
>  #include 
>  #include 
>  #include 
>  #include 
>  #include 
> +#include 
>  
>  static int handle_efi_boarddata(void)
>  {
> - const struct barebox_boarddata *bd = barebox_get_boarddata();
> + size_t size;
> + struct barebox_efi_data *efidata;
>   efi_status_t efiret;
>  
> - if (!barebox_boarddata_is_machine(bd, BAREBOX_MACH_TYPE_EFI))
> + efidata = handoff_data_get_entry(HANDOFF_DATA_EFI, &size);
> + if (!efidata)
>   return 0;
>  
>   barebox_add_memory_bank("ram0", mem_malloc_start(), mem_malloc_size());
>  
> - efi_parent_image = bd->image;
> - efi_sys_table = bd->sys_table;
> + efi_parent_image = efidata->image;
> + efi_sys_table = efidata->sys_table;
>   BS = efi_sys_table->boottime;
>   RT = efi_sys_table->runtime;
>  
> diff --git a/efi/payload/entry-multi.c b/efi/payload/entry-multi.c
> index f929ab01ec..26cf2ebfa7 100644
> --- a/efi/payload/entry-multi.c
> +++ b/efi/payload/entry-multi.c
> @@ -3,18 +3,13 @@
>  #include 
>  #include 
>  #include 
> -#include 
>  #include 
>  #include 
>  #include 
>  #include 
>  #include 
>  #include 
> -
> -static struct barebox_boarddata boarddata = {
> - .magic = BAREBOX_BOARDDATA_MAGIC,
> - .machine = BAREBOX_MACH_TYPE_EFI,
> -};
> +#include 
>  
>  asmlinkage void __efistub_efi_pe_entry(void *image, struct efi_system_table 
> *sys_table);
>  
> @@ -30,16 +25,19 @@ void __efistub_efi_pe_entry(void *image, struct 
> efi_system_table *sys_table)
>  {
>   size_t memsize;
>   efi_physical_addr_t mem;
> + static struct barebox_efi_data efidata;
>  
>  #ifdef DEBUG
>   sys_table->con_out->output_string(sys_table->con_out, L"\nbarebox\n");
>  #endif
>   pbl_set_putc(efi_putc, sys_table);
>  
> - boarddata.image = image;
> - boarddata.sys_table = sys_table;
> + efidata.image = image;
> + efidata.sys_table = sys_table;
> +
> + handoff_data_add(HANDOFF_DATA_EFI, &efidata, sizeof(efidata));
>  
>   mem = efi_earlymem_alloc(sys_table, &memsize);
>  
> - barebox_pbl_entry(mem, memsize, &boarddata);
> + barebox_pbl_entry(mem, memsize, NULL);
>  }
> diff --git a/include/boarddata.h b/include/boarddata.h
> index 8c048fd957..6092d5f304 100644
> --- a/include/boarddata.h
> +++ b/include/boarddata.h
> @@ -15,10 +15,6 @@ struct barebox_boarddata {
> * that do not potientially clashes with registered 
> machines,
> * i.e. use a number > 0x1.
> */
> -#ifdef CONFIG_EFI_STUB
> - void *image;
> - void *sys_table;
> -#endif
>  };
>  
>  /*
> diff --git a/include/efi/efi-payload.h b/include/efi/efi-payload.h
> index 774c069229..73b1b9bd8e 100644
> --- a/include/efi/efi-payload.h
> +++ b/include/efi/efi-payload.h
> @@ -8,6 +8,11 @@
>  struct efi_system_table;
>  struct efi_loaded_image;
>  
> +struct barebox_efi_data {
> + void *image;
> + void *sys_table;
> +};
> +
>  extern struct efi_system_table *efi_sys_table;
>  extern efi_handle_t efi_parent_image;
>  extern struct efi_device_path *efi_device_path;
> diff --git a/include/pbl/handoff-data.h b/include/pbl/handoff-data.h
> index 18ea9e508b..044b4bb884 100644
> --- a/include/pbl/handoff-data.h
> +++ b/include/pbl/handoff-data.h
> @@ -12,6 +12,7 @@ struct handoff_data {
>  #define HANDOFF_DATA_INTERNAL_DT_Z   HANDOFF_DATA_BAREBOX(1)
>  #define HANDOFF_DATA_EXTERNAL_DT HANDOFF_DATA_BAREBOX(2)
>  #define HANDOFF_DATA_BOARDDATA   HANDOFF_DATA_BAREBOX(3)
> +#define HANDOFF_DATA_EFI HANDOFF_DATA_BAREBOX(4)
>  
>  #define HANDOFF_DATA_BOARD(n)(0x951726fb + (n))
>  

-- 
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- |




[PATCH v2 2/3] pinctrl: rename barebox pinctrl_select_state to pinctrl_get_select

2024-05-21 Thread Ahmad Fatoum
Linux pinctrl_select_state() operates on struct pinctrl_state. The
helper that selects a state by name is instead called
pinctrl_get_select.

There's only a single user in-tree for that function, so let's rename
it and adjust the prototype.

Signed-off-by: Ahmad Fatoum 
---
v1 -> v2:
  - add missing  header include in consumer.h
---
 drivers/i2c/busses/i2c-imx.c | 24 ++--
 drivers/pinctrl/pinctrl.c| 13 +
 include/linux/pinctrl/consumer.h | 11 ---
 3 files changed, 31 insertions(+), 17 deletions(-)

diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index f6a67ec067df..981db015ea34 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -509,21 +509,25 @@ static int i2c_fsl_xfer(struct i2c_adapter *adapter,
return (result < 0) ? result : num;
 }
 
+static void i2c_fsl_pinctrl_select_state(struct i2c_adapter *adapter,
+const char *name)
+{
+   struct pinctrl *pinctrl;
+
+   pinctrl = pinctrl_get_select(adapter->dev.parent, name);
+   if (pinctrl)
+   pinctrl_put(pinctrl);
+   else
+   dev_err(adapter->dev.parent, "pinctrl failed: %pe\n", pinctrl);
+}
+
 static void i2c_fsl_prepare_recovery(struct i2c_adapter *adapter)
 {
-   int ret;
-
-   ret = pinctrl_select_state(adapter->dev.parent, "gpio");
-   if (ret)
-   dev_err(adapter->dev.parent, "pinctrl failed: %s\n", 
strerror(-ret));
+   i2c_fsl_pinctrl_select_state(adapter, "gpio");
 }
 static void i2c_fsl_unprepare_recovery(struct i2c_adapter *adapter)
 {
-   int ret;
-
-   ret = pinctrl_select_state(adapter->dev.parent, "default");
-   if (ret)
-   dev_err(adapter->dev.parent, "pinctrl failed: %s\n", 
strerror(-ret));
+   i2c_fsl_pinctrl_select_state(adapter, "default");
 }
 
 static void i2c_fsl_init_recovery(struct fsl_i2c_struct *i2c_fsl,
diff --git a/drivers/pinctrl/pinctrl.c b/drivers/pinctrl/pinctrl.c
index 95e7b0ea96e1..2d331211f71c 100644
--- a/drivers/pinctrl/pinctrl.c
+++ b/drivers/pinctrl/pinctrl.c
@@ -161,20 +161,25 @@ int of_pinctrl_select_state_default(struct device_node 
*np)
return of_pinctrl_select_state(np, "default");
 }
 
-int pinctrl_select_state(struct device *dev, const char *name)
+struct pinctrl *pinctrl_get_select(struct device *dev, const char *name)
 {
struct device_node *np;
+   int ret;
 
np = dev->of_node;
if (!np)
-   return 0;
+   return ERR_PTR(-ENODEV);
 
-   return of_pinctrl_select_state(np, name);
+   ret = of_pinctrl_select_state(np, name);
+   if (ret)
+   return ERR_PTR(ret);
+
+   return (struct pinctrl *)np;
 }
 
 int pinctrl_select_state_default(struct device *dev)
 {
-   return pinctrl_select_state(dev, "default");
+   return PTR_ERR_OR_ZERO(pinctrl_get_select(dev, "default"));
 }
 
 int pinctrl_register(struct pinctrl_device *pdev)
diff --git a/include/linux/pinctrl/consumer.h b/include/linux/pinctrl/consumer.h
index 3028f960deb4..7fd30cd49bd3 100644
--- a/include/linux/pinctrl/consumer.h
+++ b/include/linux/pinctrl/consumer.h
@@ -3,12 +3,15 @@
 #define LINUX_PINCTRL_CONSUMER_H
 
 #include 
+#include 
 
 struct device;
 struct device_node;
 
+struct pinctrl;
+
 #ifdef CONFIG_PINCTRL
-int pinctrl_select_state(struct device *dev, const char *state);
+struct pinctrl *pinctrl_get_select(struct device *dev, const char *state);
 int pinctrl_select_state_default(struct device *dev);
 int of_pinctrl_select_state(struct device_node *np, const char *state);
 int of_pinctrl_select_state_default(struct device_node *np);
@@ -17,9 +20,9 @@ int pinctrl_gpio_direction_output(unsigned int pin);
 int pinctrl_gpio_get_direction(unsigned pin);
 int pinctrl_single_probe(struct device *dev);
 #else
-static inline int pinctrl_select_state(struct device *dev, const char *state)
+static inline struct pinctrl *pinctrl_get_select(struct device *dev, const 
char *state)
 {
-   return -ENODEV;
+   return ERR_PTR(-ENODEV);
 }
 
 static inline int pinctrl_select_state_default(struct device *dev)
@@ -58,4 +61,6 @@ static inline int pinctrl_single_probe(struct device *dev)
 }
 #endif
 
+static inline void pinctrl_put(struct pinctrl *pinctrl) {}
+
 #endif /* LINUX_PINCTRL_CONSUMER_H */
-- 
2.39.2




[PATCH v2 1/3] pinctrl: split off consumer API into linux/pinctrl/consumer.h

2024-05-21 Thread Ahmad Fatoum
Follow-up patches will align the barebox pinctrl consumer API with
Linux'. So it makes sense to have the header called the same as well.
Users of the old pinctrl.h header are unaffected as it will include
the new .

Signed-off-by: Ahmad Fatoum 
---
v1 -> v2:
  - no change
---
 include/linux/pinctrl/consumer.h | 61 
 include/pinctrl.h| 55 +++-
 2 files changed, 65 insertions(+), 51 deletions(-)
 create mode 100644 include/linux/pinctrl/consumer.h

diff --git a/include/linux/pinctrl/consumer.h b/include/linux/pinctrl/consumer.h
new file mode 100644
index ..3028f960deb4
--- /dev/null
+++ b/include/linux/pinctrl/consumer.h
@@ -0,0 +1,61 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef LINUX_PINCTRL_CONSUMER_H
+#define LINUX_PINCTRL_CONSUMER_H
+
+#include 
+
+struct device;
+struct device_node;
+
+#ifdef CONFIG_PINCTRL
+int pinctrl_select_state(struct device *dev, const char *state);
+int pinctrl_select_state_default(struct device *dev);
+int of_pinctrl_select_state(struct device_node *np, const char *state);
+int of_pinctrl_select_state_default(struct device_node *np);
+int pinctrl_gpio_direction_input(unsigned pin);
+int pinctrl_gpio_direction_output(unsigned int pin);
+int pinctrl_gpio_get_direction(unsigned pin);
+int pinctrl_single_probe(struct device *dev);
+#else
+static inline int pinctrl_select_state(struct device *dev, const char *state)
+{
+   return -ENODEV;
+}
+
+static inline int pinctrl_select_state_default(struct device *dev)
+{
+   return -ENODEV;
+}
+
+static inline int of_pinctrl_select_state(struct device_node *np, const char 
*state)
+{
+   return -ENODEV;
+}
+
+static inline int of_pinctrl_select_state_default(struct device_node *np)
+{
+   return -ENODEV;
+}
+
+static inline int pinctrl_gpio_direction_input(unsigned pin)
+{
+   return -ENOTSUPP;
+}
+
+static inline int pinctrl_gpio_direction_output(unsigned int pin)
+{
+   return -ENOTSUPP;
+}
+
+static inline int pinctrl_gpio_get_direction(unsigned pin)
+{
+   return -ENOTSUPP;
+}
+
+static inline int pinctrl_single_probe(struct device *dev)
+{
+   return -ENOSYS;
+}
+#endif
+
+#endif /* LINUX_PINCTRL_CONSUMER_H */
diff --git a/include/pinctrl.h b/include/pinctrl.h
index f0f7c2cc8b3e..4ba7b489345b 100644
--- a/include/pinctrl.h
+++ b/include/pinctrl.h
@@ -2,7 +2,11 @@
 #ifndef PINCTRL_H
 #define PINCTRL_H
 
+#include 
+#include 
+
 struct pinctrl_device;
+struct device_node;
 
 struct pinctrl_ops {
int (*set_state)(struct pinctrl_device *, struct device_node *);
@@ -21,55 +25,4 @@ struct pinctrl_device {
 int pinctrl_register(struct pinctrl_device *pdev);
 void pinctrl_unregister(struct pinctrl_device *pdev);
 
-#ifdef CONFIG_PINCTRL
-int pinctrl_select_state(struct device *dev, const char *state);
-int pinctrl_select_state_default(struct device *dev);
-int of_pinctrl_select_state(struct device_node *np, const char *state);
-int of_pinctrl_select_state_default(struct device_node *np);
-int pinctrl_gpio_direction_input(unsigned pin);
-int pinctrl_gpio_direction_output(unsigned int pin);
-int pinctrl_gpio_get_direction(unsigned pin);
-int pinctrl_single_probe(struct device *dev);
-#else
-static inline int pinctrl_select_state(struct device *dev, const char *state)
-{
-   return -ENODEV;
-}
-
-static inline int pinctrl_select_state_default(struct device *dev)
-{
-   return -ENODEV;
-}
-
-static inline int of_pinctrl_select_state(struct device_node *np, const char 
*state)
-{
-   return -ENODEV;
-}
-
-static inline int of_pinctrl_select_state_default(struct device_node *np)
-{
-   return -ENODEV;
-}
-
-static inline int pinctrl_gpio_direction_input(unsigned pin)
-{
-   return -ENOTSUPP;
-}
-
-static inline int pinctrl_gpio_direction_output(unsigned int pin)
-{
-   return -ENOTSUPP;
-}
-
-static inline int pinctrl_gpio_get_direction(unsigned pin)
-{
-   return -ENOTSUPP;
-}
-
-static inline int pinctrl_single_probe(struct device *dev)
-{
-   return -ENOSYS;
-}
-#endif
-
 #endif /* PINCTRL_H */
-- 
2.39.2




[PATCH v2 3/3] pinctrl: implement pinctrl_lookup_state/select_state

2024-05-21 Thread Ahmad Fatoum
From: Ahmad Fatoum 

Besides pinctrl_get_select, the Linux API provides separate functions to
lookup a state and verify its existence and activating a state.

To make porting code easier that calls the former during probe and the
latter at runtime, define these functions and implement
of_pinctrl_select_state on top of them.

No functional change intended.

Signed-off-by: Ahmad Fatoum 
---
v1 -> v2:
  - remove out of place semicolon in !CONFIG_PINCTRL stubs
---
 drivers/pinctrl/pinctrl.c| 98 ++--
 include/linux/pinctrl/consumer.h | 23 
 2 files changed, 90 insertions(+), 31 deletions(-)

diff --git a/drivers/pinctrl/pinctrl.c b/drivers/pinctrl/pinctrl.c
index 2d331211f71c..dd0ed156ec9e 100644
--- a/drivers/pinctrl/pinctrl.c
+++ b/drivers/pinctrl/pinctrl.c
@@ -10,6 +10,14 @@
 #include 
 #include 
 
+struct pinctrl {
+   struct device_node consumer_np;
+};
+
+struct pinctrl_state {
+   struct property prop;
+};
+
 static LIST_HEAD(pinctrl_list);
 
 static struct pinctrl_device *pin_to_pinctrl(unsigned int pin)
@@ -90,30 +98,28 @@ static int pinctrl_config_one(struct device_node *for_node, 
struct device_node *
return -ENODEV;
 }
 
-int of_pinctrl_select_state(struct device_node *np, const char *name)
+static inline struct pinctrl_state *
+of_property_pinctrl_get_state(struct property *prop)
 {
+   return container_of(prop, struct pinctrl_state, prop);
+}
+
+struct pinctrl_state *pinctrl_lookup_state(struct pinctrl *pinctrl,
+  const char *name)
+{
+   struct device_node *np = &pinctrl->consumer_np;
int state, ret;
char propname[sizeof("pinctrl-4294967295")];
-   const __be32 *list;
-   int size, config;
-   phandle phandle;
-   struct device_node *np_config;
+   struct property *prop;
const char *statename;
 
-   if (!of_find_property(np, "pinctrl-0", NULL))
-   return 0;
-
/* For each defined state ID */
for (state = 0; ; state++) {
/* Retrieve the pinctrl-* property */
sprintf(propname, "pinctrl-%d", state);
-   list = of_get_property(np, propname, &size);
-   if (!list) {
-   ret = -ENODEV;
-   break;
-   }
-
-   size /= sizeof(*list);
+   prop = of_find_property(np, propname, NULL);
+   if (!prop)
+   return ERR_PTR(-ENODEV);
 
/* Determine whether pinctrl-names property names the state */
ret = of_property_read_string_index(np, "pinctrl-names",
@@ -131,31 +137,61 @@ int of_pinctrl_select_state(struct device_node *np, const 
char *name)
if (strcmp(name, statename))
continue;
 
-   /* For every referenced pin configuration node in it */
-   for (config = 0; config < size; config++) {
-   phandle = be32_to_cpup(list++);
+   return of_property_pinctrl_get_state(prop);
+   }
 
-   /* Look up the pin configuration node */
-   np_config = of_find_node_by_phandle(phandle);
-   if (!np_config) {
-   pr_err("prop %pOF %s index %i invalid 
phandle\n",
-   np, propname, config);
-   ret = -EINVAL;
-   goto err;
-   }
+   return ERR_PTR(ret);
+}
 
-   /* Parse the node */
-   ret = pinctrl_config_one(np, np_config);
-   if (ret < 0)
-   goto err;
+int pinctrl_select_state(struct pinctrl *pinctrl, struct pinctrl_state *state)
+{
+   int ret = -ENODEV;
+   const __be32 *list;
+   int size, config;
+   phandle phandle;
+   struct device_node *np = &pinctrl->consumer_np, *np_config;
+   struct property *prop = &state->prop;
+
+   list = of_property_get_value(prop);
+   size = prop->length / sizeof(*list);
+
+   /* For every referenced pin configuration node in it */
+   for (config = 0; config < size; config++) {
+   phandle = be32_to_cpup(list++);
+
+   /* Look up the pin configuration node */
+   np_config = of_find_node_by_phandle(phandle);
+   if (!np_config) {
+   pr_err("prop %pOF %s index %i invalid phandle\n",
+   np, prop->name, config);
+   ret = -EINVAL;
+   goto err;
}
 
-   return 0;
+   /* Parse the node */
+   ret = pinctrl_config_one(np, np_config);
+   if (ret < 0)
+   goto err;
}
 err:
return ret;
 }
 
+int of_pinctrl_select_state(struct device_node *np, const char *n

Re: [PATCH] include: linux/types.h: define intptr_t

2024-05-21 Thread Sascha Hauer


On Tue, 21 May 2024 10:29:44 +0200, Ahmad Fatoum wrote:
> We already define the unsigned uintptr_t, but lack its signed
> counterpart although we do define INTPTR_MAX. Add the definition
> for completeness.
> 
> 

Applied, thanks!

[1/1] include: linux/types.h: define intptr_t
  https://git.pengutronix.de/cgit/barebox/commit/?id=7176954ca289 (link may 
not be stable)

Best regards,
-- 
Sascha Hauer 




Re: [PATCH 1/2] usbgadget: fix error code in common code base

2024-05-21 Thread Sascha Hauer


On Tue, 21 May 2024 10:06:16 +0200, Marco Felsch wrote:
> Don't use command error codes in the common code base. Instead the
> commands should convert common error codes into command error codes.
> 
> 

Applied, thanks!

[1/2] usbgadget: fix error code in common code base
  https://git.pengutronix.de/cgit/barebox/commit/?id=41276fd07089 (link may 
not be stable)
[2/2] usbgadget: split usbgadget_register into prepare and register
  https://git.pengutronix.de/cgit/barebox/commit/?id=ef3c7fac172c (link may 
not be stable)

Best regards,
-- 
Sascha Hauer 




Re: [PATCH master 1/2] list: fix CONFIG_DEBUG_LIST link failure in PBL

2024-05-21 Thread Sascha Hauer


On Wed, 15 May 2024 08:07:57 +0200, Ahmad Fatoum wrote:
> With the addition of PBL handoff data, we now use  in PBL.
> This works fine with CONFIG_DEBUG_LIST disabled, because all functions are
> inlined, but when building with the option enabled, references to the
> out-of-line sanity checking functions breaks the build.
> 
> Fix this by omitting these references when building for PBL.
> 
> [...]

Applied, thanks!

[1/2] list: fix CONFIG_DEBUG_LIST link failure in PBL
  https://git.pengutronix.de/cgit/barebox/commit/?id=84d8445e0dfb (link may 
not be stable)
[2/2] pblimage: ls1028a: fix handling of short reads on
  https://git.pengutronix.de/cgit/barebox/commit/?id=27d7f5dcb305 (link may 
not be stable)

Best regards,
-- 
Sascha Hauer 




Re: [PATCH 1/3] pinctrl: split off consumer API into linux/pinctrl/consumer.h

2024-05-21 Thread Sascha Hauer


On Fri, 17 May 2024 07:56:10 +0200, Ahmad Fatoum wrote:
> Follow-up patches will align the barebox pinctrl consumer API with
> Linux'. So it makes sense to have the header called the same as well.
> Users of the old pinctrl.h header are unaffected as it will include
> the new .
> 
> 

Applied, thanks!

[1/3] pinctrl: split off consumer API into linux/pinctrl/consumer.h
  https://git.pengutronix.de/cgit/barebox/commit/?id=2cbfef3c0964 (link may 
not be stable)
[2/3] pinctrl: rename barebox pinctrl_select_state to pinctrl_get_select
  https://git.pengutronix.de/cgit/barebox/commit/?id=1a34f8cc686a (link may 
not be stable)
[3/3] pinctrl: implement pinctrl_lookup_state/select_state
  https://git.pengutronix.de/cgit/barebox/commit/?id=e13c73ff4b17 (link may 
not be stable)

Best regards,
-- 
Sascha Hauer 




Re: [PATCH] driver: move some inline getters for struct device into device.h

2024-05-21 Thread Sascha Hauer


On Fri, 17 May 2024 07:57:51 +0200, Ahmad Fatoum wrote:
> The purpose of device.h is to contain only the device related
> definitions and have as few header dependencies as possible.
> 
> dev_of_node() and dev_is_dma_coherent() are accessors for struct device
> and have no other dependencies, so move them into this header as well.
> 
> 
> [...]

Applied, thanks!

[1/1] driver: move some inline getters for struct device into device.h
  https://git.pengutronix.de/cgit/barebox/commit/?id=16a636613978 (link may 
not be stable)

Best regards,
-- 
Sascha Hauer 




Re: [PATCH] mci: imx-esdhc: retire esdhc_platform_data

2024-05-21 Thread Sascha Hauer


On Fri, 17 May 2024 07:59:51 +0200, Ahmad Fatoum wrote:
> We have no board in-tree that doesn't probe the imx-esdhc from DT.
> The platform data is thus unused as the PBL usage happens without it,
> therefore remove that struct definition and the dead code handling it.
> 
> 

Applied, thanks!

[1/1] mci: imx-esdhc: retire esdhc_platform_data
  https://git.pengutronix.de/cgit/barebox/commit/?id=4cce368d53c1 (link may 
not be stable)

Best regards,
-- 
Sascha Hauer 




Re: [PATCH] mci: collect host operation in struct mci_ops

2024-05-21 Thread Sascha Hauer


On Fri, 17 May 2024 08:09:44 +0200, Ahmad Fatoum wrote:
> The number of ops implementable by MCI drivers increase due to HS200
> support and will increase more for HS400. Collecting them into a common
> struct makes it easier to specialize them for drivers that support
> multiple variants and makes code more similar to Linux.
> 
> No functional change.
> 
> [...]

Applied, thanks!

[1/1] mci: collect host operation in struct mci_ops
  https://git.pengutronix.de/cgit/barebox/commit/?id=dfef2a2d2792 (link may 
not be stable)

Best regards,
-- 
Sascha Hauer 




Re: [PATCH] common: hide DEFAULT_COMPRESSION menu

2024-05-21 Thread Sascha Hauer


On Fri, 17 May 2024 08:21:51 +0200, Ahmad Fatoum wrote:
> CONFIG_DEFAULT_COMPRESSION_* refers to the compression done for
> in-barebox binaries and is not useful when barebox proper as a whole is
> compressed as in that case, we would have compression applied twice.
> 
> For this reason, DEFAULT_COMPRESSION_NONE is the only possible choice in
> a PBL-enabled build. Having the choice with only one option is confusing
> though, so let's hide the prompt.
> 
> [...]

Applied, thanks!

[1/1] common: hide DEFAULT_COMPRESSION menu
  https://git.pengutronix.de/cgit/barebox/commit/?id=f661c703ff46 (link may 
not be stable)

Best regards,
-- 
Sascha Hauer 




Re: [PATCH master] ARM: layerscape: fix layerscape multiarch build with DEBUG_LL

2024-05-21 Thread Sascha Hauer


On Fri, 17 May 2024 08:22:14 +0200, Ahmad Fatoum wrote:
> Layerscape was added recently into the CONFIG_ARCH_MULTIARCH (really
> multiplatform), but the required changes to DBEUG_LL was omitted, which
> breaks DEBUG_LL use for other platforms that aren't layerscape.
> 
> Fix this, so DEBUG_LL may be used for either layerscape or other enabled
> platforms.
> 
> [...]

Applied, thanks!

[1/1] ARM: layerscape: fix layerscape multiarch build with DEBUG_LL
  https://git.pengutronix.de/cgit/barebox/commit/?id=a8fa6c2afcb1 (link may 
not be stable)

Best regards,
-- 
Sascha Hauer 




[PATCH 3/4] ARM: beagle: setup C environment early

2024-05-21 Thread Sascha Hauer
Setup C environment in early board code. This will be needed in the next
step. Factored out to a separate patch to ease bisecting.

Signed-off-by: Sascha Hauer 
---
 arch/arm/boards/beagle/lowlevel.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/arm/boards/beagle/lowlevel.c 
b/arch/arm/boards/beagle/lowlevel.c
index e4610722f6..828c8c76b3 100644
--- a/arch/arm/boards/beagle/lowlevel.c
+++ b/arch/arm/boards/beagle/lowlevel.c
@@ -175,6 +175,9 @@ ENTRY_FUNCTION(start_omap3_beagleboard_sdram, bootinfo, r1, 
r2)
 {
omap3_save_bootinfo((void *)bootinfo);
 
+   relocate_to_current_adr();
+   setup_c();
+
beagle_board_init_sdram();
 }
 
-- 
2.39.2




[PATCH 1/4] handoff-data: put handoff data into data section

2024-05-21 Thread Sascha Hauer
The intention was to put the handoff data into the data section and not
into the bss section so that it won't be cleared by another call to
setup_c(). This was not fully done, add a __section(.data) to the
missing places.

Signed-off-by: Sascha Hauer 
---
 include/pbl/handoff-data.h | 18 +-
 pbl/handoff-data.c |  2 +-
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/include/pbl/handoff-data.h b/include/pbl/handoff-data.h
index 7f883421df..18ea9e508b 100644
--- a/include/pbl/handoff-data.h
+++ b/include/pbl/handoff-data.h
@@ -24,15 +24,15 @@ struct handoff_data_entry {
unsigned int flags;
 };
 
-#define handoff_data_add_flags(_cookie, _data, _size, _flags)  \
-   do {\
-   static struct handoff_data_entry hde;   \
-   hde.cookie = _cookie;   \
-   hde.data = _data;   \
-   hde.size = _size;   \
-   hde.flags = _flags; \
-   \
-   handoff_data_add_entry(&hde);   \
+#define handoff_data_add_flags(_cookie, _data, _size, _flags)  \
+   do {\
+   static struct handoff_data_entry hde __section(.data);  \
+   hde.cookie = _cookie;   \
+   hde.data = _data;   \
+   hde.size = _size;   \
+   hde.flags = _flags; \
+   \
+   handoff_data_add_entry(&hde);   \
} while (0);
 
 #define handoff_data_add(_cookie, _data, _size)\
diff --git a/pbl/handoff-data.c b/pbl/handoff-data.c
index e6745797c0..85c3985995 100644
--- a/pbl/handoff-data.c
+++ b/pbl/handoff-data.c
@@ -9,7 +9,7 @@ static struct handoff_data *handoff_data = (void *)-1;
 
 static struct handoff_data *handoff_data_get(void)
 {
-   static struct handoff_data __handoff_data;
+   static struct handoff_data __handoff_data __section(.data);
 
/*
 * Sometimes the PBL copies itself to some other location and is
-- 
2.39.2




[PATCH 2/4] efi-payload: use handoff data to pass data to barebox proper

2024-05-21 Thread Sascha Hauer
EFI payload uses custom fields in struct boarddata to pass data from PBL
to barebox proper. handoff data was created for exactly this purpose.
Now that we have it, switch EFI payload over to use it.

Signed-off-by: Sascha Hauer 
---
 efi/payload/boarddata.c| 12 +++-
 efi/payload/entry-multi.c  | 16 +++-
 include/boarddata.h|  4 
 include/efi/efi-payload.h  |  5 +
 include/pbl/handoff-data.h |  1 +
 5 files changed, 20 insertions(+), 18 deletions(-)

diff --git a/efi/payload/boarddata.c b/efi/payload/boarddata.c
index 3260e31c7b..d4e4b5ac1d 100644
--- a/efi/payload/boarddata.c
+++ b/efi/payload/boarddata.c
@@ -8,25 +8,27 @@
 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
 #include 
 #include 
+#include 
 
 static int handle_efi_boarddata(void)
 {
-   const struct barebox_boarddata *bd = barebox_get_boarddata();
+   size_t size;
+   struct barebox_efi_data *efidata;
efi_status_t efiret;
 
-   if (!barebox_boarddata_is_machine(bd, BAREBOX_MACH_TYPE_EFI))
+   efidata = handoff_data_get_entry(HANDOFF_DATA_EFI, &size);
+   if (!efidata)
return 0;
 
barebox_add_memory_bank("ram0", mem_malloc_start(), mem_malloc_size());
 
-   efi_parent_image = bd->image;
-   efi_sys_table = bd->sys_table;
+   efi_parent_image = efidata->image;
+   efi_sys_table = efidata->sys_table;
BS = efi_sys_table->boottime;
RT = efi_sys_table->runtime;
 
diff --git a/efi/payload/entry-multi.c b/efi/payload/entry-multi.c
index f929ab01ec..26cf2ebfa7 100644
--- a/efi/payload/entry-multi.c
+++ b/efi/payload/entry-multi.c
@@ -3,18 +3,13 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
-
-static struct barebox_boarddata boarddata = {
-   .magic = BAREBOX_BOARDDATA_MAGIC,
-   .machine = BAREBOX_MACH_TYPE_EFI,
-};
+#include 
 
 asmlinkage void __efistub_efi_pe_entry(void *image, struct efi_system_table 
*sys_table);
 
@@ -30,16 +25,19 @@ void __efistub_efi_pe_entry(void *image, struct 
efi_system_table *sys_table)
 {
size_t memsize;
efi_physical_addr_t mem;
+   static struct barebox_efi_data efidata;
 
 #ifdef DEBUG
sys_table->con_out->output_string(sys_table->con_out, L"\nbarebox\n");
 #endif
pbl_set_putc(efi_putc, sys_table);
 
-   boarddata.image = image;
-   boarddata.sys_table = sys_table;
+   efidata.image = image;
+   efidata.sys_table = sys_table;
+
+   handoff_data_add(HANDOFF_DATA_EFI, &efidata, sizeof(efidata));
 
mem = efi_earlymem_alloc(sys_table, &memsize);
 
-   barebox_pbl_entry(mem, memsize, &boarddata);
+   barebox_pbl_entry(mem, memsize, NULL);
 }
diff --git a/include/boarddata.h b/include/boarddata.h
index 8c048fd957..6092d5f304 100644
--- a/include/boarddata.h
+++ b/include/boarddata.h
@@ -15,10 +15,6 @@ struct barebox_boarddata {
  * that do not potientially clashes with registered 
machines,
  * i.e. use a number > 0x1.
  */
-#ifdef CONFIG_EFI_STUB
-   void *image;
-   void *sys_table;
-#endif
 };
 
 /*
diff --git a/include/efi/efi-payload.h b/include/efi/efi-payload.h
index 774c069229..73b1b9bd8e 100644
--- a/include/efi/efi-payload.h
+++ b/include/efi/efi-payload.h
@@ -8,6 +8,11 @@
 struct efi_system_table;
 struct efi_loaded_image;
 
+struct barebox_efi_data {
+   void *image;
+   void *sys_table;
+};
+
 extern struct efi_system_table *efi_sys_table;
 extern efi_handle_t efi_parent_image;
 extern struct efi_device_path *efi_device_path;
diff --git a/include/pbl/handoff-data.h b/include/pbl/handoff-data.h
index 18ea9e508b..044b4bb884 100644
--- a/include/pbl/handoff-data.h
+++ b/include/pbl/handoff-data.h
@@ -12,6 +12,7 @@ struct handoff_data {
 #define HANDOFF_DATA_INTERNAL_DT_Z HANDOFF_DATA_BAREBOX(1)
 #define HANDOFF_DATA_EXTERNAL_DT   HANDOFF_DATA_BAREBOX(2)
 #define HANDOFF_DATA_BOARDDATA HANDOFF_DATA_BAREBOX(3)
+#define HANDOFF_DATA_EFI   HANDOFF_DATA_BAREBOX(4)
 
 #define HANDOFF_DATA_BOARD(n)  (0x951726fb + (n))
 
-- 
2.39.2




[PATCH 0/4] make more use of handoff data

2024-05-21 Thread Sascha Hauer
struct boarddata is a mechanism to pass a ARM machine number from PBL to
barebox proper. The EFI payload also uses it to pass some custom
pointers to barebox proper. handoff data was created for exactly this
purpose, so retire boarddata and use handoff data instead.

@afa, the efi patch is compile tested only. Could you give it a try?

Sascha

Sascha Hauer (4):
  handoff-data: put handoff data into data section
  efi-payload: use handoff data to pass data to barebox proper
  ARM: beagle: setup C environment early
  ARM: replace boarddata with handoff data

 arch/arm/boards/beagle/lowlevel.c |  9 ++--
 arch/arm/boards/chumby_falconwing/lowlevel.c  |  7 +--
 .../boards/crystalfontz-cfa10036/lowlevel.c   |  7 +--
 arch/arm/boards/freescale-mx23-evk/lowlevel.c |  7 +--
 arch/arm/boards/imx233-olinuxino/lowlevel.c   |  7 +--
 arch/arm/boards/karo-tx28/lowlevel.c  |  7 +--
 arch/arm/cpu/start.c  | 20 +++-
 arch/arm/cpu/uncompress.c |  3 --
 arch/arm/include/asm/barebox-arm.h| 24 -
 efi/payload/boarddata.c   | 12 +++--
 efi/payload/entry-multi.c | 16 +++---
 include/boarddata.h   | 49 ---
 include/efi/efi-payload.h |  5 ++
 include/pbl/handoff-data.h| 21 
 pbl/handoff-data.c|  6 +--
 15 files changed, 64 insertions(+), 136 deletions(-)
 delete mode 100644 include/boarddata.h

-- 
2.39.2




[PATCH 4/4] ARM: replace boarddata with handoff data

2024-05-21 Thread Sascha Hauer
struct boarddata can be used to pass a ARM machine number from PBL to
barebox proper. Now that we have handoff data for this purpose, retire
struct boarddata and use handoff data instead.

Signed-off-by: Sascha Hauer 
---
 arch/arm/boards/beagle/lowlevel.c |  6 +--
 arch/arm/boards/chumby_falconwing/lowlevel.c  |  7 +--
 .../boards/crystalfontz-cfa10036/lowlevel.c   |  7 +--
 arch/arm/boards/freescale-mx23-evk/lowlevel.c |  7 +--
 arch/arm/boards/imx233-olinuxino/lowlevel.c   |  7 +--
 arch/arm/boards/karo-tx28/lowlevel.c  |  7 +--
 arch/arm/cpu/start.c  | 20 +++--
 arch/arm/cpu/uncompress.c |  3 --
 arch/arm/include/asm/barebox-arm.h| 24 --
 include/boarddata.h   | 45 ---
 include/pbl/handoff-data.h|  2 +-
 pbl/handoff-data.c|  4 +-
 12 files changed, 31 insertions(+), 108 deletions(-)
 delete mode 100644 include/boarddata.h

diff --git a/arch/arm/boards/beagle/lowlevel.c 
b/arch/arm/boards/beagle/lowlevel.c
index 828c8c76b3..e7f76aca4e 100644
--- a/arch/arm/boards/beagle/lowlevel.c
+++ b/arch/arm/boards/beagle/lowlevel.c
@@ -164,11 +164,9 @@ static void sdrc_init(void)
 
 static noinline int beagle_board_init_sdram(void)
 {
-   struct barebox_arm_boarddata *bd = (void *)OMAP3_SRAM_SCRATCH_SPACE + 
0x10;
+   handoff_add_arm_machine(MACH_TYPE_OMAP3_BEAGLE);
 
-   boarddata_create(bd, MACH_TYPE_OMAP3_BEAGLE);
-
-   barebox_arm_entry(0x8000, SZ_128M, bd);
+   barebox_arm_entry(0x8000, SZ_128M, NULL);
 }
 
 ENTRY_FUNCTION(start_omap3_beagleboard_sdram, bootinfo, r1, r2)
diff --git a/arch/arm/boards/chumby_falconwing/lowlevel.c 
b/arch/arm/boards/chumby_falconwing/lowlevel.c
index fdda6ba5f2..e823767739 100644
--- a/arch/arm/boards/chumby_falconwing/lowlevel.c
+++ b/arch/arm/boards/chumby_falconwing/lowlevel.c
@@ -9,12 +9,9 @@
 
 static noinline void continue_imx_entry(size_t size)
 {
-   static struct barebox_arm_boarddata boarddata = {
-   .magic = BAREBOX_ARM_BOARDDATA_MAGIC,
-   .machine = MACH_TYPE_CHUMBY,
-   };
+   handoff_add_arm_machine(MACH_TYPE_CHUMBY);
 
-   barebox_arm_entry(IMX_MEMORY_BASE, size, &boarddata);
+   barebox_arm_entry(IMX_MEMORY_BASE, size, NULL);
 }
 
 ENTRY_FUNCTION(start_chumby_falconwing, r0, r1, r2)
diff --git a/arch/arm/boards/crystalfontz-cfa10036/lowlevel.c 
b/arch/arm/boards/crystalfontz-cfa10036/lowlevel.c
index 447ef0dc66..2468f304e7 100644
--- a/arch/arm/boards/crystalfontz-cfa10036/lowlevel.c
+++ b/arch/arm/boards/crystalfontz-cfa10036/lowlevel.c
@@ -9,12 +9,9 @@
 
 static noinline void continue_imx_entry(size_t size)
 {
-   static struct barebox_arm_boarddata boarddata = {
-   .magic = BAREBOX_ARM_BOARDDATA_MAGIC,
-   .machine = MACH_TYPE_CFA10036,
-   };
+   handoff_add_arm_machine(MACH_TYPE_CFA10036);
 
-   barebox_arm_entry(IMX_MEMORY_BASE, size, &boarddata);
+   barebox_arm_entry(IMX_MEMORY_BASE, size, NULL);
 }
 
 ENTRY_FUNCTION(start_cfa10036, r0, r1, r2)
diff --git a/arch/arm/boards/freescale-mx23-evk/lowlevel.c 
b/arch/arm/boards/freescale-mx23-evk/lowlevel.c
index 195ade3a7f..2f31b4fd0c 100644
--- a/arch/arm/boards/freescale-mx23-evk/lowlevel.c
+++ b/arch/arm/boards/freescale-mx23-evk/lowlevel.c
@@ -9,12 +9,9 @@
 
 static noinline void continue_imx_entry(size_t size)
 {
-   static struct barebox_arm_boarddata boarddata = {
-   .magic = BAREBOX_ARM_BOARDDATA_MAGIC,
-   .machine = MACH_TYPE_MX23EVK,
-   };
+   handoff_add_arm_machine(MACH_TYPE_MX23EVK);
 
-   barebox_arm_entry(IMX_MEMORY_BASE, size, &boarddata);
+   barebox_arm_entry(IMX_MEMORY_BASE, size, NULL);
 }
 
 ENTRY_FUNCTION(start_imx23_evk, r0, r1, r2)
diff --git a/arch/arm/boards/imx233-olinuxino/lowlevel.c 
b/arch/arm/boards/imx233-olinuxino/lowlevel.c
index 91c1ba3dba..e4b6b1207f 100644
--- a/arch/arm/boards/imx233-olinuxino/lowlevel.c
+++ b/arch/arm/boards/imx233-olinuxino/lowlevel.c
@@ -13,12 +13,9 @@
 
 static noinline void continue_imx_entry(size_t size)
 {
-   static struct barebox_arm_boarddata boarddata = {
-   .magic = BAREBOX_ARM_BOARDDATA_MAGIC,
-   .machine = MACH_TYPE_IMX233_OLINUXINO,
-   };
+   handoff_add_arm_machine(MACH_TYPE_IMX233_OLINUXINO);
 
-   barebox_arm_entry(IMX_MEMORY_BASE, size, &boarddata);
+   barebox_arm_entry(IMX_MEMORY_BASE, size, NULL);
 }
 
 ENTRY_FUNCTION(start_barebox_olinuxino_imx23, r0, r1, r2)
diff --git a/arch/arm/boards/karo-tx28/lowlevel.c 
b/arch/arm/boards/karo-tx28/lowlevel.c
index 3be5f521e1..e423d5ecab 100644
--- a/arch/arm/boards/karo-tx28/lowlevel.c
+++ b/arch/arm/boards/karo-tx28/lowlevel.c
@@ -17,12 +17,9 @@
 
 static noinline void continue_imx_entry(size_t size)
 {
-   static struct barebox_arm_boarddata boarddata = {
-   .magic = BAREBOX_ARM_BOARDDATA_MAGIC,

[PATCH] driver: add Linux struct platform_device/driver compatibility wrapper

2024-05-21 Thread Ahmad Fatoum
In Linux struct platform_device is a superset on top of struct device with
additions related to specifics of the platform bus.

In barebox, there is no such distinction, so porting of Linux drivers
usually involves a lot of renaming and substitutions.

The naive approach of

  #define platform_device device
  #define platform_driver driver

won't work though as struct device dev needs to be a member of
platform_device as kernel code has a lot of instances of &pdev->dev.

Therefore, let's tackle this differently:

 1) We add struct device as only member of struct platform_device and
define all members in both and have them overlap by use of a union.

 2) Have functions that receive a platform_device/driver in Linux, but
a device/driver in barebox accept either by using GCC's transparent
union extension.

More changes are needed, e.g. in  to use __param_either where
appropriate, but this can be added alongside future kernel driver ports.

The use of __param_either instead of defining the union with a tag and
using that is intentional to keep prototypes self-documenting. This
violates the C standard's strict aliasing rule, but this doesn't matter
for us anyway as we compile barebox with -fno-strict-aliasing.

Signed-off-by: Ahmad Fatoum 
---
 include/device.h   | 124 +
 include/driver.h   |  40 ++-
 include/linux/compiler_types.h |  11 +++
 3 files changed, 98 insertions(+), 77 deletions(-)

diff --git a/include/device.h b/include/device.h
index 8c3561e5a2f6..abe9707fb8f5 100644
--- a/include/device.h
+++ b/include/device.h
@@ -7,6 +7,8 @@
 #define DEVICE_H
 
 #include 
+#include 
+#include 
 
 enum dev_dma_coherence {
DEV_DMA_COHERENCE_DEFAULT = 0,
@@ -23,83 +25,85 @@ struct platform_device_id;
 struct of_device_id;
 
 /** @brief Describes a particular device present in the system */
-struct device {
-   /*! This member (and 'type' described below) is used to match
-* with a driver. This is a descriptive name and could be
-* MPC5XXX_ether or imx_serial. Unless absolutely necessary,
-* should not be modified directly and dev_set_name() should
-* be used instead.
-*/
-   char *name;
+struct platform_device {
+   struct_group_tagged(device, dev,
+   /*! This member (and 'type' described below) is used to match
+* with a driver. This is a descriptive name and could be
+* MPC5XXX_ether or imx_serial. Unless absolutely necessary,
+* should not be modified directly and dev_set_name() should
+* be used instead.
+*/
+   char *name;
 
-   /*! This member is used to store device's unique name as
-*  obtained by calling dev_id(). Internal field, do not
-*  access it directly.
- */
-   char *unique_name;
-   /*! The id is used to uniquely identify a device in the system. The id
-* will show up under /dev/ as the device's name. Usually this is
-* something like eth0 or nor0. */
-   int id;
+   /*! This member is used to store device's unique name as
+*  obtained by calling dev_id(). Internal field, do not
+*  access it directly.
+ */
+   char *unique_name;
+   /*! The id is used to uniquely identify a device in the system. 
The id
+* will show up under /dev/ as the device's name. Usually this 
is
+* something like eth0 or nor0. */
+   int id;
 
-   enum dev_dma_coherence dma_coherent;
+   enum dev_dma_coherence dma_coherent;
 
-   struct resource *resource;
-   int num_resources;
+   struct resource *resource;
+   int num_resources;
 
-   void *platform_data; /*! board specific information about this device */
+   void *platform_data; /*! board specific information about this 
device */
 
-   /*! Devices of a particular class normaly need to store more
-* information than struct device holds.
-*/
-   void *priv;
-   void *type_data; /*! In case this device is a specific device, this 
pointer
- * points to the type specific device, i.e. 
eth_device
- */
-   struct driver *driver; /*! The driver for this device */
+   /*! Devices of a particular class normaly need to store more
+* information than struct device holds.
+*/
+   void *priv;
+   void *type_data; /*! In case this device is a specific 
device, this pointer
+ * points to the type specific device, 
i.e. eth_device
+ */
+   struct driver *driver; /*! The driver for this device */
 
-   struct list_head list; /* The list of all devices *

[PATCH] include: linux/types.h: define intptr_t

2024-05-21 Thread Ahmad Fatoum
We already define the unsigned uintptr_t, but lack its signed
counterpart although we do define INTPTR_MAX. Add the definition
for completeness.

Signed-off-by: Ahmad Fatoum 
---
 include/linux/types.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/linux/types.h b/include/linux/types.h
index aee9dfa87e54..c5e38fee9595 100644
--- a/include/linux/types.h
+++ b/include/linux/types.h
@@ -26,6 +26,7 @@ typedef __kernel_key_tkey_t;
 typedef __kernel_suseconds_t   suseconds_t;
 typedef _Bool  bool;
 typedef unsigned long  uintptr_t;
+typedef long   intptr_t;
 
 #ifdef __KERNEL__
 typedef __kernel_uid32_t   uid_t;
-- 
2.39.2




[PATCH 2/2] usbgadget: split usbgadget_register into prepare and register

2024-05-21 Thread Marco Felsch
Currently usbgadget_register() prepares the struct::f_multi_opts
according a given configuration string and registers the the usbgadget
device.

This is not optimal for adding custom fastboot_opts. Split the single
function into usbgadget_prepare() and usbgadget_register() to avoid code
duplication. This way it's easy to reuse the preparation code and add
the custom fastboot_opts afterwards.

In addition usbgadget_prepare_register() is added to keep the simplicity
of the single prepare and register functionality.

Signed-off-by: Marco Felsch 
---
 commands/dfu.c   |  2 +-
 commands/usbgadget.c |  2 +-
 common/usbgadget.c   | 36 
 include/linux/usb/gadget-multi.h |  4 +++-
 4 files changed, 32 insertions(+), 12 deletions(-)

diff --git a/commands/dfu.c b/commands/dfu.c
index bbe75841b914..ab784c638200 100644
--- a/commands/dfu.c
+++ b/commands/dfu.c
@@ -29,7 +29,7 @@ static int do_dfu(int argc, char *argv[])
 
funcs.flags |= USBGADGET_DFU;
funcs.dfu_opts = argv[optind];
-   ret = usbgadget_register(&funcs);
+   ret = usbgadget_prepare_register(&funcs);
if (ret)
return COMMAND_ERROR_USAGE;
 
diff --git a/commands/usbgadget.c b/commands/usbgadget.c
index 736ccb5d9185..1cd8c915b1b1 100644
--- a/commands/usbgadget.c
+++ b/commands/usbgadget.c
@@ -51,7 +51,7 @@ static int do_usbgadget(int argc, char *argv[])
}
}
 
-   ret = usbgadget_register(&funcs);
+   ret = usbgadget_prepare_register(&funcs);
return ret ? COMMAND_ERROR_USAGE : 0;
 }
 
diff --git a/common/usbgadget.c b/common/usbgadget.c
index 9974be57d1cb..1333eaa413ea 100644
--- a/common/usbgadget.c
+++ b/common/usbgadget.c
@@ -31,11 +31,9 @@ static inline struct file_list *get_dfu_function(void)
return system_partitions_get_null();
 }
 
-int usbgadget_register(const struct usbgadget_funcs *funcs)
+struct f_multi_opts *usbgadget_prepare(const struct usbgadget_funcs *funcs)
 {
-   int ret;
int flags = funcs->flags;
-   struct device *dev;
struct f_multi_opts *opts;
 
opts = xzalloc(sizeof(*opts));
@@ -71,10 +69,18 @@ int usbgadget_register(const struct usbgadget_funcs *funcs)
 
if (usb_multi_count_functions(opts) == 0) {
pr_warn("No functions to register\n");
-   ret = -EINVAL;
-   goto err;
+   usb_multi_opts_release(opts);
+   return ERR_PTR(-EINVAL);
}
 
+   return opts;
+}
+
+int usbgadget_register(struct f_multi_opts *opts)
+{
+   int ret;
+   struct device *dev;
+
/*
 * Creating a gadget with both DFU and Fastboot may not work.
 * fastboot 1:8.1.0+r23-5 can deal with it, but dfu-util 0.9
@@ -90,11 +96,23 @@ int usbgadget_register(const struct usbgadget_funcs *funcs)
 
ret = usb_multi_register(opts);
if (ret)
-   goto err;
+   return ret;
 
return 0;
-err:
-   usb_multi_opts_release(opts);
+}
+
+int usbgadget_prepare_register(const struct usbgadget_funcs *funcs)
+{
+   struct f_multi_opts *opts;
+   int ret;
+
+   opts = usbgadget_prepare(funcs);
+   if (IS_ERR(opts))
+   return PTR_ERR(opts);
+
+   ret = usbgadget_register(opts);
+   if (ret)
+   usb_multi_opts_release(opts);
 
return ret;
 }
@@ -122,7 +140,7 @@ static int usbgadget_do_autostart(void)
 
funcs.flags |= USBGADGET_DFU | USBGADGET_FASTBOOT | 
USBGADGET_MASS_STORAGE;
 
-   err = usbgadget_register(&funcs);
+   err = usbgadget_prepare_register(&funcs);
if (!err)
started = true;
 
diff --git a/include/linux/usb/gadget-multi.h b/include/linux/usb/gadget-multi.h
index 1027a10082e0..14aa609a5895 100644
--- a/include/linux/usb/gadget-multi.h
+++ b/include/linux/usb/gadget-multi.h
@@ -35,7 +35,9 @@ struct usbgadget_funcs {
const char *ums_opts;
 };
 
-int usbgadget_register(const struct usbgadget_funcs *funcs);
+struct f_multi_opts *usbgadget_prepare(const struct usbgadget_funcs *funcs);
+int usbgadget_register(struct f_multi_opts *opts);
+int usbgadget_prepare_register(const struct usbgadget_funcs *funcs);
 
 void usbgadget_autostart(bool enable);
 
-- 
2.39.2




[PATCH 1/2] usbgadget: fix error code in common code base

2024-05-21 Thread Marco Felsch
Don't use command error codes in the common code base. Instead the
commands should convert common error codes into command error codes.

Signed-off-by: Marco Felsch 
---
 commands/dfu.c   | 2 +-
 commands/usbgadget.c | 5 +++--
 common/usbgadget.c   | 2 +-
 3 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/commands/dfu.c b/commands/dfu.c
index 2116747f6885..bbe75841b914 100644
--- a/commands/dfu.c
+++ b/commands/dfu.c
@@ -31,7 +31,7 @@ static int do_dfu(int argc, char *argv[])
funcs.dfu_opts = argv[optind];
ret = usbgadget_register(&funcs);
if (ret)
-   return ret;
+   return COMMAND_ERROR_USAGE;
 
command_slice_release();
while (!usb_dfu_detached()) {
diff --git a/commands/usbgadget.c b/commands/usbgadget.c
index e69660fde541..736ccb5d9185 100644
--- a/commands/usbgadget.c
+++ b/commands/usbgadget.c
@@ -20,6 +20,7 @@ static int do_usbgadget(int argc, char *argv[])
 {
struct usbgadget_funcs funcs = {};
int opt;
+   int ret;
 
while ((opt = getopt(argc, argv, "asdA::D::S::b")) > 0) {
switch (opt) {
@@ -50,8 +51,8 @@ static int do_usbgadget(int argc, char *argv[])
}
}
 
-
-   return usbgadget_register(&funcs);
+   ret = usbgadget_register(&funcs);
+   return ret ? COMMAND_ERROR_USAGE : 0;
 }
 
 BAREBOX_CMD_HELP_START(usbgadget)
diff --git a/common/usbgadget.c b/common/usbgadget.c
index 371355116364..9974be57d1cb 100644
--- a/common/usbgadget.c
+++ b/common/usbgadget.c
@@ -71,7 +71,7 @@ int usbgadget_register(const struct usbgadget_funcs *funcs)
 
if (usb_multi_count_functions(opts) == 0) {
pr_warn("No functions to register\n");
-   ret = COMMAND_ERROR_USAGE;
+   ret = -EINVAL;
goto err;
}
 
-- 
2.39.2




Re: [PATCH master 1/2] ARM: cpu: start: align uncompressed DTB size to 4 bytes

2024-05-21 Thread Sascha Hauer


On Fri, 17 May 2024 08:22:24 +0200, Ahmad Fatoum wrote:
> KASAN reports that decompression exceeds the bounds of the allocation
> and my DT size isn't 4-bytes aligned. Align the allocation size to fix
> this.
> 
> 

Applied, thanks!

[1/2] ARM: cpu: start: align uncompressed DTB size to 4 bytes
  https://git.pengutronix.de/cgit/barebox/commit/?id=ce38eef3c056 (link may 
not be stable)
[2/2] RISC-V: start: align uncompressed DTB size to 4 bytes
  https://git.pengutronix.de/cgit/barebox/commit/?id=249164bc555f (link may 
not be stable)

Best regards,
-- 
Sascha Hauer 




Re: [PATCH v2 0/6] add PBL handoff-data support

2024-05-21 Thread Sascha Hauer


On Fri, 17 May 2024 08:45:05 +0200, Ahmad Fatoum wrote:
> This series replaces the 3 patches from v1 that are in next.
> 
> The first 3 patches are new: They ensure that the handoff structs
> (linked list pointers, cookie, flags, ...) are also reserved in the
> SDRAM banks and not only the data.
> 
> The three patches after that differ to v1 mainly in that reservation
> of space for the handoff data is correctly taken care of. This was
> erroneous both in PBL and in barebox proper and led to problems for me
> trying to boot a Qemu Virt64 machine that has for some reason a FDT that
> describes its size in the header as 1MiB.
> 
> [...]

Applied, thanks!

[1/6] memory: add support for requesting barebox area as a whole
  https://git.pengutronix.de/cgit/barebox/commit/?id=59289e3d8cc3 (link may 
not be stable)
[2/6] treewide: use request_barebox_region for possible barebox memory regions
  https://git.pengutronix.de/cgit/barebox/commit/?id=64fa27a491b8 (link may 
not be stable)
[3/6] ARM: cpu: start: register barebox memory area
  https://git.pengutronix.de/cgit/barebox/commit/?id=3f7b6146669c (link may 
not be stable)
[4/6] ARM: move blob_is_arm_boarddata() to include
  https://git.pengutronix.de/cgit/barebox/commit/?id=fad13ab1cdc6 (link may 
not be stable)
[5/6] add handoff-data support
  https://git.pengutronix.de/cgit/barebox/commit/?id=e72ea06e3ad3 (link may 
not be stable)
[6/6] ARM: pass handoff data from PBL to proper
  https://git.pengutronix.de/cgit/barebox/commit/?id=b02063a8aa22 (link may 
not be stable)

Best regards,
-- 
Sascha Hauer 




Re: [PATCH master 1/2] ARM: document PBL barebox memory layout

2024-05-21 Thread Sascha Hauer


On Fri, 17 May 2024 08:10:56 +0200, Ahmad Fatoum wrote:
> Apparently, we have an overlap between ramoops/barebox proper
> and the early malloc area. Before fixing that, let's add a diagram
> explaining the current state of affairs.
> 
> 

Applied, thanks!

[1/2] ARM: document PBL barebox memory layout
  https://git.pengutronix.de/cgit/barebox/commit/?id=c9af0d2b5e57 (link may 
not be stable)
[2/2] ARM: fix overlap between ramoops area and early malloc area
  https://git.pengutronix.de/cgit/barebox/commit/?id=d1cc8a4045a0 (link may 
not be stable)

Best regards,
-- 
Sascha Hauer