Re: [PATCHv8 03/15] net/lwip: implement dns cmd

2023-09-12 Thread Ilias Apalodimas
On Fri, Sep 08, 2023 at 07:53:08PM +0600, Maxim Uvarov wrote:
> U-Boot recently got support for an alternative network stack using LWIP.
> Replace dns command with the LWIP variant while keeping the output and
> error messages identical.
>
> Signed-off-by: Maxim Uvarov 
> ---
>  include/net/lwip.h   | 19 +++
>  net/lwip/Makefile|  2 ++
>  net/lwip/apps/dns/lwip-dns.c | 63 
>  3 files changed, 84 insertions(+)
>  create mode 100644 include/net/lwip.h
>  create mode 100644 net/lwip/apps/dns/lwip-dns.c
>
> diff --git a/include/net/lwip.h b/include/net/lwip.h
> new file mode 100644
> index 00..ab3db1a214
> --- /dev/null
> +++ b/include/net/lwip.h
> @@ -0,0 +1,19 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +
> +int do_lwip_dns(struct cmd_tbl *cmdtp, int flag, int argc,
> + char *const argv[]);
> +
> +/**
> + * ulwip_dns() - creates the DNS request to resolve a domain host name
> + *
> + * This function creates the DNS request to resolve a domain host name. 
> Function
> + * can return immediately if previous request was cached or it might require
> + * entering the polling loop for a request to a remote server.
> + *
> + * @name:dns name to resolve
> + * @varname: (optional) U-Boot variable name to store the result
> + * Returns: ERR_OK(0) for fetching entry from the cache
> + *  -EINPROGRESS success, can go to the polling loop
> + *  Other value < 0, if error
> + */
> +int ulwip_dns(char *name, char *varname);
> diff --git a/net/lwip/Makefile b/net/lwip/Makefile
> index 3fd5d34564..5d8d5527c6 100644
> --- a/net/lwip/Makefile
> +++ b/net/lwip/Makefile
> @@ -62,3 +62,5 @@ obj-$(CONFIG_NET) += lwip-external/src/netif/ethernet.o
>
>  obj-$(CONFIG_NET) += port/if.o
>  obj-$(CONFIG_NET) += port/sys-arch.o
> +
> +obj-y += apps/dns/lwip-dns.o
> diff --git a/net/lwip/apps/dns/lwip-dns.c b/net/lwip/apps/dns/lwip-dns.c
> new file mode 100644
> index 00..b340302f2c
> --- /dev/null
> +++ b/net/lwip/apps/dns/lwip-dns.c
> @@ -0,0 +1,63 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
> +/*
> + * (C) Copyright 2023 Linaro Ltd. 
> + */
> +
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +#include 
> +
> +#include 
> +
> +static void dns_found_cb(const char *name, const ip_addr_t *ipaddr, void 
> *callback_arg)
> +{
> + char *varname = (char *)callback_arg;
> + char *ipstr = ip4addr_ntoa(ipaddr);
> +
> + if (varname)
> + env_set(varname, ipstr);
> + log_info("resolved %s to %s\n",  name, ipstr);
> + ulwip_exit(0);
> +}
> +
> +int ulwip_dns(char *name, char *varname)
> +{
> + int err;
> + ip_addr_t ipaddr; /* not used */
> + ip_addr_t dns1;
> + ip_addr_t dns2;
> + char *dnsenv = env_get("dnsip");
> + char *dns2env = env_get("dnsip2");
> +
> + if (!dnsenv && !dns2env) {
> + log_err("nameserver is not set with dnsip and dnsip2 vars\n");
> + return -ENOENT;
> + }
> +
> + if (!dnsenv)
> + log_warning("dnsip var is not set\n");
> + if (!dns2env)
> + log_warning("dnsip2 var is not set\n");
> +
> + dns_init();
> +
> + if (ipaddr_aton(dnsenv, ))
> + dns_setserver(0, );
> +
> + if (ipaddr_aton(dns2env, ))
> + dns_setserver(1, );

env_get will return NULL if any of these is not set.  Looking at
ipaddr_aton() of lwip that might lead to a NULL deref in ip_2_ip6()

> +
> + err = dns_gethostbyname(name, , dns_found_cb, varname);
> + if (err == ERR_OK)
> + dns_found_cb(name, , varname);
> +
> + /* convert lwIP ERR_INPROGRESS to U-Boot -EINPROGRESS */
> + if (err == ERR_INPROGRESS)
> + err = -EINPROGRESS;
> +
> + return err;
> +}
> --
> 2.30.2
>


Re: [PATCH] riscv: enable multi-range memory layout

2023-09-12 Thread Heinrich Schuchardt



Am 13. September 2023 04:23:14 MESZ schrieb "Wu, Fei" :
>On 9/5/2023 6:09 PM, Fei Wu wrote:
>> In order to enable PCIe passthrough on qemu riscv, the physical memory
>> range between 3GB and 4GB is reserved. Therefore if guest has 4GB ram,
>> two ranges are created as [2G, 3G) and [4G, 7G), currently u-boot sets
>> ram_top to 4G - 1 if the gd->ram_top is above 4G in
>> board_get_usable_ram_top(), but that address is not backed by ram. This
>> patch selects the lowest range instead.
>> 
>I think multi-range memory layout is a common requirement, PCIe
>passthrough happens to be the first one to require it. Could anyone
>please take a look at this patch and give your comments?
>
>Thanks,
>Fei.
>
>> Signed-off-by: Fei Wu 
>> ---
>>  arch/riscv/cpu/generic/dram.c| 2 +-
>>  configs/qemu-riscv64_smode_defconfig | 2 +-

We should consider all riscv64 defconfigs.

Best regards

Heinrich

>>  2 files changed, 2 insertions(+), 2 deletions(-)
>> 
>> diff --git a/arch/riscv/cpu/generic/dram.c b/arch/riscv/cpu/generic/dram.c
>> index 44e11bd56c..fb53a57b4e 100644
>> --- a/arch/riscv/cpu/generic/dram.c
>> +++ b/arch/riscv/cpu/generic/dram.c
>> @@ -13,7 +13,7 @@ DECLARE_GLOBAL_DATA_PTR;
>>  
>>  int dram_init(void)
>>  {
>> -return fdtdec_setup_mem_size_base();
>> +return fdtdec_setup_mem_size_base_lowest();
>>  }
>>  
>>  int dram_init_banksize(void)
>> diff --git a/configs/qemu-riscv64_smode_defconfig 
>> b/configs/qemu-riscv64_smode_defconfig
>> index 1d0f021ade..de08a49dab 100644
>> --- a/configs/qemu-riscv64_smode_defconfig
>> +++ b/configs/qemu-riscv64_smode_defconfig
>> @@ -1,6 +1,6 @@
>>  CONFIG_RISCV=y
>>  CONFIG_SYS_MALLOC_LEN=0x80
>> -CONFIG_NR_DRAM_BANKS=1
>> +CONFIG_NR_DRAM_BANKS=2
>>  CONFIG_HAS_CUSTOM_SYS_INIT_SP_ADDR=y
>>  CONFIG_CUSTOM_SYS_INIT_SP_ADDR=0x8020
>>  CONFIG_ENV_SIZE=0x2
>


[PATCH v3 3/3] config: j7200: remove not needed power config

2023-09-12 Thread Udit Kumar
For J7200, R5/SPL TI_SCI_POWER_DOMAIN should be
disabled as DM is a separate binary like other
SOC of J7* family.

Fixes: 02dff65efe70 ("configs: j7200_evm_r5: Add initial support")

Signed-off-by: Udit Kumar 
---
 configs/j7200_evm_r5_defconfig | 1 -
 1 file changed, 1 deletion(-)

diff --git a/configs/j7200_evm_r5_defconfig b/configs/j7200_evm_r5_defconfig
index 6d240b16cb..9e744ba434 100644
--- a/configs/j7200_evm_r5_defconfig
+++ b/configs/j7200_evm_r5_defconfig
@@ -126,7 +126,6 @@ CONFIG_SPL_PINCTRL=y
 # CONFIG_SPL_PINCTRL_GENERIC is not set
 CONFIG_PINCTRL_SINGLE=y
 CONFIG_POWER_DOMAIN=y
-CONFIG_TI_SCI_POWER_DOMAIN=y
 CONFIG_TI_POWER_DOMAIN=y
 CONFIG_DM_PMIC=y
 CONFIG_PMIC_TPS65941=y
-- 
2.34.1



[PATCH v3 2/3] clk: ti: Add support to enable configs conditionally

2023-09-12 Thread Udit Kumar
TI SOC has two clock domains CLK_TI_SCI and
CLK_K3. These are mutually exclusive.

Adding conditional check for CLK_TI_SCI
and CLK_K3 along with other associated configs options.

Suggested-by: Nishanth Menon 
Signed-off-by: Udit Kumar 
Reviewed-by: Nishanth Menon 
---
 drivers/clk/ti/Kconfig | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/clk/ti/Kconfig b/drivers/clk/ti/Kconfig
index fbcdefd889..a21359d6b2 100644
--- a/drivers/clk/ti/Kconfig
+++ b/drivers/clk/ti/Kconfig
@@ -36,7 +36,7 @@ config CLK_TI_MUX
 
 config CLK_TI_SCI
bool "TI System Control Interface (TI SCI) clock driver"
-   depends on CLK && TI_SCI_PROTOCOL && OF_CONTROL
+   depends on CLK && TI_SCI_PROTOCOL && OF_CONTROL && !CLK_K3
help
  This enables the clock driver support over TI System Control Interface
  available on some new TI's SoCs. If you wish to use clock resources
@@ -44,13 +44,13 @@ config CLK_TI_SCI
 
 config CLK_K3_PLL
bool "PLL clock support for K3 SoC family of devices"
-   depends on CLK && LIB_RATIONAL
+   depends on CLK && LIB_RATIONAL && !CLK_TI_SCI
help
  Enables PLL clock support for K3 SoC family of devices.
 
 config SPL_CLK_K3_PLL
bool "PLL clock support for K3 SoC family of devices"
-   depends on CLK && LIB_RATIONAL && SPL
+   depends on CLK && LIB_RATIONAL && SPL && !CLK_TI_SCI
help
  Enables PLL clock support for K3 SoC family of devices.
 
@@ -62,6 +62,6 @@ config CLK_K3
 
 config SPL_CLK_K3
bool "Clock support for K3 SoC family of devices"
-   depends on CLK && SPL
+   depends on CLK && SPL && !CLK_TI_SCI
help
  Enables the clock translation layer from DT to device clocks.
-- 
2.34.1



[PATCH v3 1/3] power: domain: ti: Enable single config for power domain

2023-09-12 Thread Udit Kumar
TI SOC has two power domain TI_SCI_POWER_DOMAIN and
TI_POWER_DOMAIN. These are mutually exclusive.
So adding rule to select one, in case defconfig enabled both.

Suggested-by: Nishanth Menon 
Signed-off-by: Udit Kumar 
Reviewed-by: Nishanth Menon 
---
 drivers/power/domain/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/power/domain/Kconfig b/drivers/power/domain/Kconfig
index 411c210756..30c358fb88 100644
--- a/drivers/power/domain/Kconfig
+++ b/drivers/power/domain/Kconfig
@@ -92,7 +92,7 @@ config TEGRA186_POWER_DOMAIN
 
 config TI_SCI_POWER_DOMAIN
bool "Enable the TI SCI-based power domain driver"
-   depends on POWER_DOMAIN && TI_SCI_PROTOCOL
+   depends on POWER_DOMAIN && TI_SCI_PROTOCOL && !TI_POWER_DOMAIN
help
  Generic power domain implementation for TI devices implementing the
  TI SCI protocol.
-- 
2.34.1



[PATCH v3 0/3] enable power and clock Kconfig conditionally

2023-09-12 Thread Udit Kumar
This series, updates enabling mutually exclusive power and clock configs
for TI SOCs.


Sorry to push clock and power changes in one series,
managed by two maintainers. But In my quick grep,
I am not able to active PR raise from both trees.
So copying maintainers of clock and power for review.

Change log
Changes in v3:
- Patch 1 and 2: Added reviewed by
- Patch 3: Corrected Fixes in commit message
link to v2:
https://lore.kernel.org/all/20230912130645.1202325-1-u-kum...@ti.com/

Changes in v2:
- Patch 1 and 2) Added conditional support to enable Kconfig
- Patch 3 No change
link to v1:
https://lore.kernel.org/all/2023091946.749270-1-u-kum...@ti.com/

Udit Kumar (3):
  power: domain: ti: Enable single config for power domain
  clk: ti: Add support to enable configs conditionally
  config: j7200: remove not needed power config

 configs/j7200_evm_r5_defconfig | 1 -
 drivers/clk/ti/Kconfig | 8 
 drivers/power/domain/Kconfig   | 2 +-
 3 files changed, 5 insertions(+), 6 deletions(-)

-- 
2.34.1



Re: [PATCH] riscv: enable multi-range memory layout

2023-09-12 Thread Wu, Fei
On 9/5/2023 6:09 PM, Fei Wu wrote:
> In order to enable PCIe passthrough on qemu riscv, the physical memory
> range between 3GB and 4GB is reserved. Therefore if guest has 4GB ram,
> two ranges are created as [2G, 3G) and [4G, 7G), currently u-boot sets
> ram_top to 4G - 1 if the gd->ram_top is above 4G in
> board_get_usable_ram_top(), but that address is not backed by ram. This
> patch selects the lowest range instead.
> 
I think multi-range memory layout is a common requirement, PCIe
passthrough happens to be the first one to require it. Could anyone
please take a look at this patch and give your comments?

Thanks,
Fei.

> Signed-off-by: Fei Wu 
> ---
>  arch/riscv/cpu/generic/dram.c| 2 +-
>  configs/qemu-riscv64_smode_defconfig | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/riscv/cpu/generic/dram.c b/arch/riscv/cpu/generic/dram.c
> index 44e11bd56c..fb53a57b4e 100644
> --- a/arch/riscv/cpu/generic/dram.c
> +++ b/arch/riscv/cpu/generic/dram.c
> @@ -13,7 +13,7 @@ DECLARE_GLOBAL_DATA_PTR;
>  
>  int dram_init(void)
>  {
> - return fdtdec_setup_mem_size_base();
> + return fdtdec_setup_mem_size_base_lowest();
>  }
>  
>  int dram_init_banksize(void)
> diff --git a/configs/qemu-riscv64_smode_defconfig 
> b/configs/qemu-riscv64_smode_defconfig
> index 1d0f021ade..de08a49dab 100644
> --- a/configs/qemu-riscv64_smode_defconfig
> +++ b/configs/qemu-riscv64_smode_defconfig
> @@ -1,6 +1,6 @@
>  CONFIG_RISCV=y
>  CONFIG_SYS_MALLOC_LEN=0x80
> -CONFIG_NR_DRAM_BANKS=1
> +CONFIG_NR_DRAM_BANKS=2
>  CONFIG_HAS_CUSTOM_SYS_INIT_SP_ADDR=y
>  CONFIG_CUSTOM_SYS_INIT_SP_ADDR=0x8020
>  CONFIG_ENV_SIZE=0x2



[PATCH v3 3/5] cmd: kaslrseed: Use common API to fixup FDT

2023-09-12 Thread seanedmond
From: Sean Edmond 

Use the newly introduced common API fdt_fixup_kaslr_seed() in the
kaslrseed command.

Signed-off-by: Sean Edmond 
---
 cmd/kaslrseed.c | 22 --
 1 file changed, 8 insertions(+), 14 deletions(-)

diff --git a/cmd/kaslrseed.c b/cmd/kaslrseed.c
index 8a1d8120cd..c65607619b 100644
--- a/cmd/kaslrseed.c
+++ b/cmd/kaslrseed.c
@@ -19,7 +19,7 @@ static int do_kaslr_seed(struct cmd_tbl *cmdtp, int flag, int 
argc, char *const
size_t n = 0x8;
struct udevice *dev;
u64 *buf;
-   int nodeoffset;
+   ofnode root;
int ret = CMD_RET_SUCCESS;
 
if (uclass_get_device(UCLASS_RNG, 0, ) || !dev) {
@@ -45,21 +45,15 @@ static int do_kaslr_seed(struct cmd_tbl *cmdtp, int flag, 
int argc, char *const
return CMD_RET_FAILURE;
}
 
-   ret = fdt_check_header(working_fdt);
-   if (ret < 0) {
-   printf("fdt_chosen: %s\n", fdt_strerror(ret));
-   return CMD_RET_FAILURE;
-   }
-
-   nodeoffset = fdt_find_or_add_subnode(working_fdt, 0, "chosen");
-   if (nodeoffset < 0) {
-   printf("Reading chosen node failed\n");
-   return CMD_RET_FAILURE;
+   ret = root_ofnode_from_fdt(working_fdt, );
+   if (ret) {
+   printf("ERROR: Unable to get root ofnode\n");
+   goto CMD_RET_FAILURE;
}
 
-   ret = fdt_setprop(working_fdt, nodeoffset, "kaslr-seed", buf, 
sizeof(buf));
-   if (ret < 0) {
-   printf("Unable to set kaslr-seed on chosen node: %s\n", 
fdt_strerror(ret));
+   ret = fdt_fixup_kaslr_seed(root, buf, sizeof(buf));
+   if (ret) {
+   printf("ERROR: failed to add kaslr-seed to fdt\n");
return CMD_RET_FAILURE;
}
 
-- 
2.40.0



[PATCH v3 1/5] fdt: common API to populate kaslr seed

2023-09-12 Thread seanedmond
From: Dhananjay Phadke 

fdt_fixup_kaslr_seed() will update given ofnode with random seed value.
Source for random seed can be TPM or RNG driver in u-boot or sec
firmware (ARM).

Signed-off-by: Dhananjay Phadke 
Signed-off-by: Sean Edmond 
---
 arch/arm/cpu/armv8/sec_firmware.c | 39 +++
 common/fdt_support.c  | 19 +++
 drivers/core/ofnode.c | 17 ++
 include/dm/ofnode.h   | 12 ++
 include/fdt_support.h |  9 +++
 5 files changed, 71 insertions(+), 25 deletions(-)

diff --git a/arch/arm/cpu/armv8/sec_firmware.c 
b/arch/arm/cpu/armv8/sec_firmware.c
index c0e8726346..5f04cd8aec 100644
--- a/arch/arm/cpu/armv8/sec_firmware.c
+++ b/arch/arm/cpu/armv8/sec_firmware.c
@@ -411,46 +411,35 @@ int sec_firmware_init(const void *sec_firmware_img,
 /*
  * fdt_fix_kaslr - Add kalsr-seed node in Device tree
  * @fdt:   Device tree
- * @eret:  0 in case of error, 1 for success
+ * @eret:  0 for success
  */
 int fdt_fixup_kaslr(void *fdt)
 {
-   int nodeoffset;
-   int err, ret = 0;
-   u8 rand[8];
+   int ret = 0;
 
 #if defined(CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT)
+   u8 rand[8];
+   ofnode root;
+
/* Check if random seed generation is  supported */
if (sec_firmware_support_hwrng() == false) {
printf("WARNING: SEC firmware not running, no kaslr-seed\n");
-   return 0;
+   return -EOPNOTSUPP;
}
 
-   err = sec_firmware_get_random(rand, 8);
-   if (err < 0) {
+   ret = sec_firmware_get_random(rand, 8);
+   if (ret < 0) {
printf("WARNING: No random number to set kaslr-seed\n");
-   return 0;
+   return ret;
}
 
-   err = fdt_check_header(fdt);
-   if (err < 0) {
-   printf("fdt_chosen: %s\n", fdt_strerror(err));
-   return 0;
+   ret = root_ofnode_from_fdt(fdt, );
+   if (ret < 0) {
+   printf("WARNING: Unable to get root ofnode\n");
+   return ret;
}
 
-   /* find or create "/chosen" node. */
-   nodeoffset = fdt_find_or_add_subnode(fdt, 0, "chosen");
-   if (nodeoffset < 0)
-   return 0;
-
-   err = fdt_setprop(fdt, nodeoffset, "kaslr-seed", rand,
- sizeof(rand));
-   if (err < 0) {
-   printf("WARNING: can't set kaslr-seed %s.\n",
-  fdt_strerror(err));
-   return 0;
-   }
-   ret = 1;
+   ret = fdt_fixup_kaslr_seed(root, rand, sizeof(rand));
 #endif
 
return ret;
diff --git a/common/fdt_support.c b/common/fdt_support.c
index 5e49078f8c..52be4375b4 100644
--- a/common/fdt_support.c
+++ b/common/fdt_support.c
@@ -631,6 +631,25 @@ void fdt_fixup_ethernet(void *fdt)
}
 }
 
+int fdt_fixup_kaslr_seed(ofnode node, const u8 *seed, int len)
+{
+   ofnode chosen;
+   int ret;
+
+   /* find or create "/chosen" node. */
+   ret = ofnode_add_subnode(node, "chosen", );
+   if (ret && ret != -EEXIST)
+   return -ENOENT;
+
+   ret = ofnode_write_prop(chosen, "kaslr-seed", seed, len, true);
+   if (ret) {
+   printf("WARNING: can't set kaslr-seed\n");
+   return ret;
+   }
+
+   return 0;
+}
+
 int fdt_record_loadable(void *blob, u32 index, const char *name,
uintptr_t load_addr, u32 size, uintptr_t entry_point,
const char *type, const char *os, const char *arch)
diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c
index 8df16e56af..4be21133b8 100644
--- a/drivers/core/ofnode.c
+++ b/drivers/core/ofnode.c
@@ -870,6 +870,23 @@ ofnode oftree_path(oftree tree, const char *path)
}
 }
 
+int root_ofnode_from_fdt(void *fdt, ofnode *root_node)
+{
+   oftree tree;
+   /* If OFNODE_MULTI_TREE is not set, and if fdt is not the control FDT,
+*  oftree_from_fdt() will return NULL
+*/
+   tree = oftree_from_fdt(fdt);
+
+   if (!oftree_valid(tree)) {
+   printf("Cannot create oftree\n");
+   return -EINVAL;
+   }
+   *root_node = oftree_root(tree);
+
+   return 0;
+}
+
 const void *ofnode_read_chosen_prop(const char *propname, int *sizep)
 {
ofnode chosen_node;
diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h
index 0f38b3e736..e79bb62be8 100644
--- a/include/dm/ofnode.h
+++ b/include/dm/ofnode.h
@@ -901,6 +901,18 @@ ofnode oftree_path(oftree tree, const char *path);
  */
 ofnode oftree_root(oftree tree);
 
+/**
+ * root_ofnode_from_fdt() - Gets the root ofnode given an FDT blob.
+ *  Note, this will fail if OFNODE_MULTI_TREE
+ *  is not set.
+ *
+ * @fdt: Device tree to use
+ * @root_node : Root ofnode
+ *
+ * Return: 0 if OK, -ve on error
+ */
+int root_ofnode_from_fdt(void *fdt, ofnode 

[PATCH v3 5/5] fdt: Fix compile error for !OFNODE_MULTI_TREE

2023-09-12 Thread seanedmond
From: Sean Edmond 

Required to fix the following compile error when building sandbox:
/tmp/cci9ibby.ltrans21.ltrans.o: In function `do_cedit_load':
:(.text+0x601d): undefined reference to `oftree_dispose'

Signed-off-by: Sean Edmond 
---
 drivers/core/ofnode.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c
index 4be21133b8..f7b3f41077 100644
--- a/drivers/core/ofnode.c
+++ b/drivers/core/ofnode.c
@@ -92,12 +92,6 @@ static oftree oftree_ensure(void *fdt)
return tree;
 }
 
-void oftree_dispose(oftree tree)
-{
-   if (of_live_active())
-   of_live_free(tree.np);
-}
-
 void *ofnode_lookup_fdt(ofnode node)
 {
if (gd->flags & GD_FLG_RELOC) {
@@ -195,6 +189,12 @@ static inline int oftree_find(const void *fdt)
 
 #endif /* OFNODE_MULTI_TREE */
 
+void oftree_dispose(oftree tree)
+{
+   if (of_live_active())
+   of_live_free(tree.np);
+}
+
 /**
  * ofnode_from_tree_offset() - get an ofnode from a tree offset (flat tree)
  *
-- 
2.40.0



[PATCH v3 4/5] dm: core: Modify default for OFNODE_MULTI_TREE

2023-09-12 Thread seanedmond
From: Sean Edmond 

There is a preference to use the "ofnode" API for FDT fixups
moving forward.  The FDT fixup will usually be for the kernel FDT.  To
fixup the kernel FDT with the ofnode API, it's required to set the
OFNODE_MULTI_TREE option.

To ensure existing users of kaslr fdt fixup are not impacted, Let's modify
the default value for OFNODE_MULTI_TREE to ensure it's always set if
!OF_LIVE.  This will cause a 1007 byte increase in the code size.

Signed-off-by: Sean Edmond 
---
 drivers/core/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/core/Kconfig b/drivers/core/Kconfig
index f0d848f45d..38e44ef6fc 100644
--- a/drivers/core/Kconfig
+++ b/drivers/core/Kconfig
@@ -424,7 +424,7 @@ config DM_DEV_READ_INLINE
 
 config OFNODE_MULTI_TREE
bool "Allow the ofnode interface to access any tree"
-   default y if EVENT && !DM_DEV_READ_INLINE && !DM_INLINE_OFNODE
+   default y if !OF_LIVE
help
  Normally U-Boot makes use of its control FDT, the one used to bind
  devices and provide options. In some cases, U-Boot must also process
-- 
2.40.0



[PATCH v3 0/5] Populate kaslr seed with RNG

2023-09-12 Thread seanedmond
From: Sean Edmond 

This patch series creates a common API (fdt_fixup_kaslr_seed()) for 
populating the kaslr seed in the DTB.  Existing users (kaslrseed,
and ARMv8 sec firmware) have been updated to use this common API.

New functionality has been introduced to populate the kaslr using
the RNG.  This can be enabled with CONFIG_RNG_TPM_SEED.  

changes in v3:
- Populate with RNG device instead of TPM device (this is a more generic 
solution)
- Use event spy to do the FDT fixup
- fix compile error for sandbox for !OFNODE_MULTI_TREE

changes in v2:
- fdt_fixup_kaslr_seed() uses the ofnode API
- Add root_ofnode_from_fdt() to get the root node from an FDT and
  perform error checking on the oftree
- add comments to exported functions
- Add error checking in image_setup_libfdt() for return from
  fdt_tpm_kaslr_seed()
- uclass_get_device() -> uclass_first_device_err()
- Change default config for OFNODE_MULTI_TREE (y if !OF_LIVE)


Dhananjay Phadke (2):
  fdt: common API to populate kaslr seed
  fdt: kaslr seed from RNG device

Sean Edmond (3):
  cmd: kaslrseed: Use common API to fixup FDT
  dm: core: Modify default for OFNODE_MULTI_TREE
  fdt: Fix compile error for !OFNODE_MULTI_TREE

 arch/arm/cpu/armv8/sec_firmware.c | 39 --
 cmd/kaslrseed.c   | 22 +
 common/fdt_support.c  | 55 +++
 drivers/core/Kconfig  |  2 +-
 drivers/core/ofnode.c | 29 
 include/dm/ofnode.h   | 12 +++
 include/fdt_support.h |  9 +
 lib/Kconfig   |  7 
 8 files changed, 129 insertions(+), 46 deletions(-)

-- 
2.40.0



[PATCH v3 2/5] fdt: kaslr seed from RNG device

2023-09-12 Thread seanedmond
From: Dhananjay Phadke 

Add support for KASLR seed from the RNG device. Invokes dm_rng_read()
API to read 8-bytes of random bytes.  Performs the FDT fixup using event
spy.  To enable use CONFIG_KASLR_RNG_SEED

Signed-off-by: Dhananjay Phadke 
Signed-off-by: Drew Kluemke 
Signed-off-by: Sean Edmond 
---
 common/fdt_support.c | 36 
 lib/Kconfig  |  7 +++
 2 files changed, 43 insertions(+)

diff --git a/common/fdt_support.c b/common/fdt_support.c
index 52be4375b4..09ce582865 100644
--- a/common/fdt_support.c
+++ b/common/fdt_support.c
@@ -12,7 +12,10 @@
 #include 
 #include 
 #include 
+#include 
 #include 
+#include 
+#include 
 #include 
 #include 
 #include 
@@ -650,6 +653,39 @@ int fdt_fixup_kaslr_seed(ofnode node, const u8 *seed, int 
len)
return 0;
 }
 
+int fdt_rng_kaslr_seed(void *ctx, struct event *event)
+{
+   u8 rand[8] = {0};
+   struct udevice *dev;
+   int ret;
+   oftree tree = event->data.ft_fixup.tree;
+   ofnode root_node = oftree_root(tree);
+
+   ret = uclass_first_device_err(UCLASS_RNG, );
+   if (ret) {
+   printf("ERROR: Failed to find RNG device\n");
+   return ret;
+   }
+
+   ret = dm_rng_read(dev, rand, sizeof(rand));
+   if (ret) {
+   printf("ERROR: RNG read failed, ret=%d\n", ret);
+   return ret;
+   }
+
+   ret = fdt_fixup_kaslr_seed(root_node, rand, sizeof(rand));
+   if (ret) {
+   printf("ERROR: failed to add kaslr-seed to fdt\n");
+   return ret;
+   }
+
+   return 0;
+}
+
+#if defined(CONFIG_KASLR_RNG_SEED)
+EVENT_SPY(EVT_FT_FIXUP, fdt_rng_kaslr_seed);
+#endif
+
 int fdt_record_loadable(void *blob, u32 index, const char *name,
uintptr_t load_addr, u32 size, uintptr_t entry_point,
const char *type, const char *os, const char *arch)
diff --git a/lib/Kconfig b/lib/Kconfig
index 3926652db6..545a14343e 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -465,6 +465,13 @@ config VPL_TPM
  for the low-level TPM interface, but only one TPM is supported at
  a time by the TPM library.
 
+config KASLR_RNG_SEED
+   bool "Use RNG driver for KASLR random seed"
+   depends on DM_RNG
+   help
+ This enables support for using the RNG driver as entropy source for
+ KASLR seed populated in kernel's device tree.
+
 endmenu
 
 menu "Android Verified Boot"
-- 
2.40.0



Re: [PATCH v2] bootstd: Make efi_mgr bootmeth work for non-sandbox setups

2023-09-12 Thread Mark Kettenis
> From: Simon Glass 
> Date: Sun, 10 Sep 2023 13:13:16 -0600
> 
> Hi Mark,
> 
> On Sun, 10 Sept 2023 at 08:57, Mark Kettenis  wrote:
> >
> > > From: Simon Glass 
> > > Date: Thu, 7 Sep 2023 09:57:34 -0600
> > >
> > > Hi Mark,
> > >
> > > On Thu, 7 Sept 2023 at 07:08, Mark Kettenis  
> > > wrote:
> > > >
> > > > > From: Simon Glass 
> > > > > Date: Thu, 7 Sep 2023 06:23:10 -0600
> > > > >
> > > > > Hi Mark,
> > > > >
> > > > > On Sun, 3 Sept 2023 at 14:40, Mark Kettenis  
> > > > > wrote:
> > > > > >
> > > > > > Enable the bootflow based on this bootmeth if the BootOrder EFI
> > > > > > variable is set.
> > > > > >
> > > > > > Signed-off-by: Mark Kettenis 
> > > > > > ---
> > > > > >
> > > > > > ChangeLog:
> > > > > >
> > > > > > v2: - Initialize EFI subsystem to populate EFI variables
> > > > > >
> > > > > >
> > > > > >  boot/bootmeth_efi_mgr.c | 17 -
> > > > > >  1 file changed, 16 insertions(+), 1 deletion(-)
> > > > > >
> > > > > > diff --git a/boot/bootmeth_efi_mgr.c b/boot/bootmeth_efi_mgr.c
> > > > > > index e9d973429f..e6c42d41fb 100644
> > > > > > --- a/boot/bootmeth_efi_mgr.c
> > > > > > +++ b/boot/bootmeth_efi_mgr.c
> > > > > > @@ -14,6 +14,8 @@
> > > > > >  #include 
> > > > > >  #include 
> > > > > >  #include 
> > > > > > +#include 
> > > > > > +#include 
> > > > > >
> > > > > >  /**
> > > > > >   * struct efi_mgr_priv - private info for the efi-mgr driver
> > > > > > @@ -46,13 +48,26 @@ static int efi_mgr_check(struct udevice *dev, 
> > > > > > struct bootflow_iter *iter)
> > > > > >  static int efi_mgr_read_bootflow(struct udevice *dev, struct 
> > > > > > bootflow *bflow)
> > > > > >  {
> > > > > > struct efi_mgr_priv *priv = dev_get_priv(dev);
> > > > > > +   efi_status_t ret;
> > > > > > +   efi_uintn_t size;
> > > > > > +   u16 *bootorder;
> > > > > >
> > > > > > if (priv->fake_dev) {
> > > > > > bflow->state = BOOTFLOWST_READY;
> > > > > > return 0;
> > > > > > }
> > > > > >
> > > > > > -   /* To be implemented */
> > > > > > +   ret = efi_init_obj_list();
> > > > >
> > > > > Doesn't this start up the whole EFI system? Is there a cheaper way to
> > > > > see if the variable subsystem exists, or can work?
> > > >
> > > > A fair bit of it at least.  With the possible exception of launching
> > > > EFI capsules (which shouldn't happen for a "normal" boot), I don't
> > > > think this is very expensive though.
> > > >
> > > > There currently isn't a way to only initialize the variable subsystem;
> > > > we can't just call efi_init_variables() here since we have to also
> > > > call efi_disks_register() and a later efi_init_obj_list() call would
> > > > call efi_init_variables() again, which would leak memory.
> > > >
> > > > Alternatively we could just unconditionally declare the efi_mgr
> > > > bootmeth as "ready" (like you already do for sandbox).  That would
> > > > postpone initialization of the EFI subsystem until we actually execute
> > > > this bootmeth.
> > > >
> > > > But we need to do something before we switch more targets to standard
> > > > boot since otherwise booting through the EFI boot manager is just
> > > > plain broken.
> > >
> > > Yes...
> > >
> > > I don't have any great ideas on this. If we could get the EFI code
> > > better integrated into U-Boot then perhaps we would not need this
> > > 'monolithm' init?
> >
> > You'll have to take that up with the maintainers of the EFI loader
> > subsystem.  I just want to repair the breakage that was introduced
> > with bootstd.
> 
> Yes, understood. Do you know how long it takes to do this step?

It is instant.  But then this is on a fast machine with the EFI
variables stored on the internal NVMe disk, which is plenty fast as
well.  And I haven't enabled any of the capsule or TPM stuff hich may
take more time.

> The control for this feature is CMD_BOOTEFI_BOOTMGR...I think it would
> be better to have BOOTEFI_BOOTMGR as well as CMD_BOOTEFI_BOOTMGR,
> since it is strange to have a CMD Kconfig in lib/efi_loader
> 
> I am OK with this patch as I don't see any alternative. We need to do
> something and we can always improve it if it causes problems.
> 
> Heinrich?
> 
> Regards,
> Simon
> 


Re: [PATCH v3 16/16] doc: board: ti: k3: Add J784S4 EVM and AM69 SK documentation

2023-09-12 Thread Heinrich Schuchardt



Am 12. September 2023 14:50:35 MESZ schrieb Marcel Ziswiler 
:
>On Fri, 2023-09-08 at 16:35 +0530, Apurva Nandan wrote:
>> TI K3 J784S4 and AM69 SK are new additions to the K3 SoC family.
>> Add documentation about the J784S4 EVM and AM69 SK.
>> 
>> Signed-off-by: Dasnavis Sabiya 
>> Signed-off-by: Apurva Nandan 
>> ---
>>  board/ti/j784s4/MAINTAINERS |   1 +
>>  doc/board/ti/j784s4_evm.rst | 339 
>>  doc/board/ti/k3.rst |   1 +
>>  3 files changed, 341 insertions(+)
>>  create mode 100644 doc/board/ti/j784s4_evm.rst
>> 
>> diff --git a/board/ti/j784s4/MAINTAINERS b/board/ti/j784s4/MAINTAINERS
>> index 7d3549dd31..be2f9a04b7 100644
>> --- a/board/ti/j784s4/MAINTAINERS
>> +++ b/board/ti/j784s4/MAINTAINERS
>> @@ -18,3 +18,4 @@ F:arch/arm/dts/k3-j784s4-ddr-evm-lp4-4266.dtsi
>>  F: arch/arm/dts/k3-am69-sk.dts
>>  F: arch/arm/dts/k3-am69-sk-u-boot.dtsi
>>  F: arch/arm/dts/k3-am69-r5-sk.dts
>> +F: doc/board/ti/j784s4_evm.rst
>> diff --git a/doc/board/ti/j784s4_evm.rst b/doc/board/ti/j784s4_evm.rst
>> new file mode 100644
>> index 00..1e2b7f3820
>> --- /dev/null
>> +++ b/doc/board/ti/j784s4_evm.rst
>> @@ -0,0 +1,339 @@
>> +.. SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
>
>Should be:
>
>GPL-2.0-or-later OR BSD-3-Clause
>
>> +.. sectionauthor:: Apurva Nandan 
>> +
>> +J784S4 and AM69 Platforms
>> +=
>> +
>> +Introduction:
>> +-
>> +The J784S4 SoC belongs to the K3 Multicore SoC architecture
>> +platform, providing advanced system integration in automotive,
>> +ADAS and industrial applications requiring AI at the network edge.
>> +This SoC extends the K3 Jacinto 7 family of SoCs with focus on
>> +raising performance and integration while providing interfaces,
>> +memory architecture and compute performance for multi-sensor, high
>> +concurrency applications.
>> +
>> +The device is partitioned into three functional domains, each containing
>> +specific processing cores and peripherals:
>> +
>> +1. Wake-up (WKUP) domain:
>> +    * ARM Cortex-M4F processor, runs TI Foundational Security (TIFS)
>> +
>> +2. Microcontroller (MCU) domain:
>> +    * Dual core ARM Cortex-R5F processor, runs device management
>> +  and SoC early boot
>> +
>> +3. MAIN domain:
>> +    * Dual core 64-bit ARM Cortex-A72, runs HLOS
>> +
>> +More info can be found in TRM: http://www.ti.com/lit/zip/spruj52
>> +
>> +Platform information:
>> +
>> +* https://www.ti.com/tool/J784S4XEVM
>> +* https://www.ti.com/tool/SK-AM69
>> +
>> +Boot Flow:
>> +--
>> +Below is the pictorial representation of boot flow:
>> +
>> +.. image:: img/boot_diagram_k3_current.svg
>> +
>> +- On this platform, "TI Foundational Security (TIFS)" functions as the
>> +  security enclave master. While "Device Manager (DM)", also known as the
>> +  "TISCI server" in TI terminology, offers all the essential services.
>> +
>> +- As illustrated in the diagram above, R5 SPL manages power and clock
>> +  services independently before handing over control to DM. The A72 or
>> +  the C7x (Aux core) software components request TIFS/DM to handle
>> +  security or device management services.
>> +
>> +Sources:
>> +

Thanks for providing this documentation.

Just nits below.

Colons ':' are not needed for headings

>> +
>> +.. include::  k3.rst
>> +    :start-after: .. k3_rst_include_start_boot_sources
>> +    :end-before: .. k3_rst_include_end_boot_sources
>> +
>> +Build procedure:
>> +
>> +0. Setup the environment variables:
>> +
>> +.. include::  k3.rst
>> +    :start-after: .. k3_rst_include_start_common_env_vars_desc
>> +    :end-before: .. k3_rst_include_end_common_env_vars_desc
>> +
>> +.. include::  k3.rst
>> +    :start-after: .. k3_rst_include_start_board_env_vars_desc
>> +    :end-before: .. k3_rst_include_end_board_env_vars_desc
>> +
>> +Set the variables corresponding to this platform:
>> +
>> +.. include::  k3.rst
>> +    :start-after: .. k3_rst_include_start_common_env_vars_defn
>> +    :end-before: .. k3_rst_include_end_common_env_vars_defn
>> +.. code-block:: bash
>> +
>> + $ export UBOOT_CFG_CORTEXR=j784s4_evm_r5_defconfig
>> + $ export UBOOT_CFG_CORTEXA=j784s4_evm_a72_defconfig
>> + $ export TFA_BOARD=generic
>> + $ export TFA_EXTRA_ARGS="K3_USART=0x8"
>> + $ export OPTEE_PLATFORM=k3-j784s4
>> + $ export OPTEE_EXTRA_ARGS="CFG_CONSOLE_UART=0x8"
>> +
>> +.. j784s4_evm_rst_include_start_build_steps
>> +
>> +1. Trusted Firmware-A:
>> +
>> +.. include::  k3.rst
>> +    :start-after: .. k3_rst_include_start_build_steps_tfa
>> +    :end-before: .. k3_rst_include_end_build_steps_tfa
>> +
>> +
>> +2. OP-TEE:
>> +
>> +.. include::  k3.rst
>> +    :start-after: .. k3_rst_include_start_build_steps_optee
>> +    :end-before: .. k3_rst_include_end_build_steps_optee
>> +
>> +3. U-Boot:
>> +
>> +.. _j784s4_evm_rst_u_boot_r5:
>> +
>> +* 3.1 R5:
>> +
>> +.. include::  k3.rst
>> +    :start-after: .. k3_rst_include_start_build_steps_spl_r5
>> +   

bootstd: CACHE Misaligned operation errors (Marvell Armada 385)

2023-09-12 Thread Tony Dinh
I've been testing the boostd for a few Marvell boards and seeing this
error on the Thecus N2350 (Marvell Armada 385, dual-core CPU). The
"bootflow scan scsi" command triggered the "CACHE: Misaligned
operation at range" error. However, this error did not affect the
result of the scan, i.e. the bootflow for scsi partition was created
correctly, and u-boot is running normally.

Enabling CONFIG_SYS_DCACHE_OFF got rid of the errors altogether.
Perhaps this is a case where the DCACHE is not required and should be
turned off?

Please see the log after the break below.

All the best,
Tony



U-Boot 2023.10-rc4-tld-1-00036-gbb16283b81-dirty (Sep 11 2023 - 11:56:18 -0700)
Thecus N2350

SoC:   MV88F6820-A0 at 1066 MHz
DRAM:  1 GiB (533 MHz, 32-bit, ECC not enabled)
Core:  65 devices, 23 uclasses, devicetree: separate
NAND:  512 MiB
MMC:
Loading Environment from SPIFlash... SF: Detected mx25l3205d with page
size 256 Bytes, erase size 4 KiB, total 4 MiB
*** Warning - bad CRC, using default environment

Model: Thecus N2350
Net:
Warning: ethernet@7 (eth0) using random MAC address - be:13:ae:99:49:ab
eth0: ethernet@7
Hit any key to stop autoboot:  0

N2350 > env def -a
## Resetting to default environment

N2350 > bootdev l
Seq  Probed  Status  UclassName
---  --  --    --
  0   [   ]  OK  ethernet  ethernet@7.bootdev
---  --  --    --
(1 bootdev)

N2350 > bootdev hunt scsi
Hunting with: scsi
pcie0.0: Link down
pcie1.0: Link down
scanning bus for devices...
SATA link 0 timeout.
Target spinup took 0 ms.
AHCI 0001. 32 slots 2 ports 6 Gbps 0x3 impl SATA mode
flags: 64bit ncq led only pmp fbss pio slum part sxs
  Device 0: (1:0) Vendor: ATA Prod.: ST750LX003-1AC15 Rev: SM12
Type: Hard Disk
Capacity: 715404.8 MB = 698.6 GB (1465149168 x 512)

N2350 > bootflow scan usb
Bus usb@58000: USB EHCI 1.00
Bus usb3@f: MVEBU XHCI INIT controller @ 0xf10f4000
Register 2000120 NbrPorts 2
Starting the controller
USB XHCI 1.00
Bus usb3@f8000: MVEBU XHCI INIT controller @ 0xf10fc000
Register 2000120 NbrPorts 2
Starting the controller
USB XHCI 1.00
scanning bus usb@58000 for devices... 1 USB Device(s) found
scanning bus usb3@f for devices... 1 USB Device(s) found
scanning bus usb3@f8000 for devices... 2 USB Device(s) found
** File not found /boot/boot.bmp **

N2350 > bootflow scan scsi
CACHE: Misaligned operation at range [3fb7fe48, 3fb80248]
CACHE: Misaligned operation at range [3fb7fe48, 3fb80248]
CACHE: Misaligned operation at range [3fb7fe48, 3fb80248]
ERROR: v7_outer_cache_inval_range - start address is not aligned - 0x3fb7fe48
ERROR: v7_outer_cache_inval_range - stop address is not aligned - 0x3fb80248
** File not found /boot/boot.bmp **
** File not found /boot/boot.bmp **

N2350 > bootflow scan scsi
CACHE: Misaligned operation at range [3fb88a88, 3fb88e88]
CACHE: Misaligned operation at range [3fb88a88, 3fb88e88]
CACHE: Misaligned operation at range [3fb88a88, 3fb88e88]
ERROR: v7_outer_cache_inval_range - start address is not aligned - 0x3fb88a88
ERROR: v7_outer_cache_inval_range - stop address is not aligned - 0x3fb88e88
** File not found /boot/boot.bmp **
** File not found /boot/boot.bmp **

N2350 > bootflow l
Showing all bootflows
Seq  Method   State   UclassPart  Name  Filename
---  ---  --      

  0  script   ready   scsi 1  ahci_scsi.id1lun0.bootdev
/boot/boot.scr
  1  script   ready   usb_mass_1  usb_mass_storage.lun0.boo
/boot/boot.scr
---  ---  --      

(2 bootflows, 2 valid)

N2350 > boot
Scanning for bootflows in all bootdevs
Seq  Method   State   UclassPart  Name  Filename
---  ---  --      

Scanning global bootmeth 'efi_mgr':
Hunting with: mmc
Scanning bootdev 'ahci_scsi.id1lun0.bootdev':
CACHE: Misaligned operation at range [3fb91d08, 3fb92108]
CACHE: Misaligned operation at range [3fb91d08, 3fb92108]
CACHE: Misaligned operation at range [3fb91d08, 3fb92108]
ERROR: v7_outer_cache_inval_range - start address is not aligned - 0x3fb91d08
ERROR: v7_outer_cache_inval_range - stop address is not aligned - 0x3fb92108
** File not found /boot/boot.bmp **
  0  script   ready   scsi 1  ahci_scsi.id1lun0.bootdev
/boot/boot.scr
** Booting bootflow 'ahci_scsi.id1lun0.bootdev.part_1' with script
Booting with distro boot script
loading uImage from scsi 0:1 ...
511 bytes read in 120 ms (40.7 MiB/s)
loading uInitrd from scsi 0:1 ...
7355687 bytes read in 197 ms (35.6 MiB/s)
loading DTB file from scsi 0:1 ...
20906 bytes read in 16 ms (1.2 MiB/s)
## Booting kernel from Legacy Image at 0100 ...
   Image Name:   Linux-6.4.11-mvebu-tld-1
   Created:  2023-08-20  17:34:55 UTC
   Image Type:   ARM Linux Kernel Image (uncompressed)
 

Re: [PATCHv8 00/15] net/lwip: add lwip library for the network stack

2023-09-12 Thread Simon Glass
Hi Maxim,

On Tue, 12 Sept 2023 at 05:42, Maxim Uvarov  wrote:
>
> On Fri, 8 Sept 2023 at 19:59, Tom Rini  wrote:
>
> > On Fri, Sep 08, 2023 at 07:53:05PM +0600, Maxim Uvarov wrote:
> >
> > > Before apply these patches it  is needed to create lwIP merge into
> > U-Boot:
> > > git subtree add --prefix net/lwip/lwip-external
> > https://git.savannah.nongnu.org/git/lwip.git master --squash
> > > or
> > > create git submodule, depends how it's more easy to maintain external
> > > library.
> >
> > So, I think we're going to go with subtree.  Please work out how to
> > integrate the above in to the build process automatically (and such that
> > we can maintain it via upgrades moving forward).
> >
> > --
> > Tom
> >
>
> I did not find a good way to friend git format-patch, git am and subtree.
> And now with using subtree I can provide my thoughts, in general I do not
> see any big advantages
> with maintaining subtree code.
>
> Problem is that:
>
> 1. subtree does some root reset. So rebase looks like:
> label onto
>
>
>
> # Branch acbc0469a49de7055141cc730aa9c728e61b6de2-2
>
> reset [new root]
>
> pick acbc0469a4 Squashed 'net/lwip/lwip-external/' content from commit
> 84fde1ebbf
> label acbc0469a49de7055141cc730aa9c728e61b6de2-2
>
>
>
> reset onto
>
> merge -C ec4a128c8d acbc0469a49de7055141cc730aa9c728e61b6de2-2 # Merge
> commit 'acbc0469a49de7055141cc730aa9c728e61b6de2' as
> 'net/lwip/lwip-external'
> pick 739681a6f5 net/lwip: add doc/develop/net_lwip.rst
>
> pick f0ecab85e0 net/lwip: integrate lwIP library
>
> 2. if  --rebase-merges option was not provided to rebase, then rebase will
> omit subtree directory and try to apply rebase patches to root directory.
> I.e. in current case squashed commit for lwip, will be applied to uboot
> root directory instead of ./net/lwip/lwip-external.
>
> 3. due to broken rebases without --rebase-merges more likely things like
> git bisect also will not work.
>
> 4.  change in subtree code ./net/lwip/lwip-external/../something.c will
> create a git commit which looks like a standard U-Boot commit. I.e. path
> starts with ./net/lwip/lwip-external/

I don't really understand most of the above, but I take it that
subtree has some problems...I did find an article about subtree [1]

>
> 5. lwip maintains code with a mailing list.  So we don't need to push
> subtree git somewhere to create a pull request.
>
> 6. I rechecked the latest edk2 and they use submodules now. (openssl,
> libfdt, berkeley-softfloat-3 and others).
>
> 7. dynamic download also looks horrible for me. I.e. create subtree in
> Makefile on compilation process. I think maintaining that will give you a
> bunch of problems. I think we should not touch git structure after cloning.
>
> So what I can here suggest:
> 1.  lwip source code is 9.4M.  If we compare all code it will be 564M in
> total. So just having 1 commit witn copy of lwip library will work here.

So we add a 9.4MB patch for the code we need? I suppose that is OK,
although it is much larger than net/ today (0.5MB).

What is the churn on lwip? E.g. would it be easy to add a commit every
few months to bring in upstream changes?

>
> or
>
> 2. use git submodules. Size of the project will be lower.  Submodule will
> not allow you to use local changes. I.e. change needs to be merged into the
> upstream project and then you can update git HEAD for the submodule.

I really don't want to work with a submodule project. I've just had
too many problems.

>
> or
>
> 3. inside u-boot.git create branch lib-lwip and clone lwip repo there. Then
> use git submoule to connect this branch as a folder to the main U-Boot code.

It really needs to be properly part of U-Boot.

>
> BR,
> Maxim.

Regards,
Simon

[1] https://www.atlassian.com/git/tutorials/git-subtree


Re: [PATCH 1/3] trace: Use 64bit variable for start and len

2023-09-12 Thread Simon Glass
Hi Michal,

On Mon, 11 Sept 2023 at 06:32, Michal Simek  wrote:
>
> tputq() requires variables to have 64bit width that's why make them 64bit
> to clean alignment requirement.
>
> Signed-off-by: Michal Simek 
> ---
>
>  tools/proftool.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)

Reviewed-by: Simon Glass 

I would have thought that 'unsigned long' is enough on a 64-bit
machines? Are you running on 32-bit?

>
> diff --git a/tools/proftool.c b/tools/proftool.c
> index 101bcb63334e..869a2a32c510 100644
> --- a/tools/proftool.c
> +++ b/tools/proftool.c
> @@ -1493,7 +1493,8 @@ static int write_pages(struct twriter *tw, enum 
> out_format_t out_format,
>  static int write_flyrecord(struct twriter *tw, enum out_format_t out_format,
>int *missing_countp, int *skip_countp)
>  {
> -   int start, ret, len;
> +   unsigned long long start, len;
> +   int ret;
> FILE *fout = tw->fout;
> char str[200];
>
> --
> 2.36.1
>

Regards,
Simon


Re: [PATCH 3/3] trace: Fix alignment logic in flyrecord header

2023-09-12 Thread Simon Glass
Hi Michal,

On Mon, 11 Sept 2023 at 06:32, Michal Simek  wrote:
>
> Current alignment which is using 16 bytes is not correct in connection to
> trace_clocks description and it's length.
> That's why use start_addr variable and record proper size based on used
> entries.
>
> Fixes: be16fc81b2ed ("trace: Update proftool to use new binary format").
> Signed-off-by: Michal Simek 
> ---
>
>  tools/proftool.c | 31 +--
>  1 file changed, 29 insertions(+), 2 deletions(-)
>

Reviewed-by: Simon Glass 

See my comment below

> diff --git a/tools/proftool.c b/tools/proftool.c
> index 7c95a94482fc..f79128169e68 100644
> --- a/tools/proftool.c
> +++ b/tools/proftool.c
> @@ -1493,19 +1493,43 @@ static int write_pages(struct twriter *tw, enum 
> out_format_t out_format,
>  static int write_flyrecord(struct twriter *tw, enum out_format_t out_format,
>int *missing_countp, int *skip_countp)
>  {
> -   unsigned long long start, len;
> +   unsigned long long start, start_addr, len;
> int ret;
> FILE *fout = tw->fout;
> char str[200];
>
> +   /* Record start pointer */
> +   start_addr = tw->ptr;

I'd prefer start_ofs since it is not an address, is it?

> +   debug("Start of flyrecord header at: 0x%llx\n", start_addr);
> +
> tw->ptr += fprintf(fout, "flyrecord%c", 0);
>
> +   /* flyrecord\0 - allocated 10 bytes */
> +   start_addr += 10;
> +
> +   /*
> +* 8 bytes that are a 64-bit word containing the offset into the file
> +* that holds the data for the CPU.
> +*
> +* 8 bytes that are a 64-bit word containing the size of the CPU
> +* data at that offset.
> +*/
> +   start_addr += 16;
> +
> snprintf(str, sizeof(str),
>  "[local] global counter uptime perf mono mono_raw boot 
> x86-tsc\n");
> len = strlen(str);
>
> +   /* trace clock length - 8 bytes */
> +   start_addr += 8;
> +   /* trace clock data */
> +   start_addr += len;
> +
> +   debug("Calculated flyrecord header end at: 0x%llx, trace clock len: 
> 0x%llx\n",
> + start_addr, len);
> +
> /* trace data */
> -   start = ALIGN(tw->ptr + 16, TRACE_PAGE_SIZE);
> +   start = ALIGN(start_addr, TRACE_PAGE_SIZE);

Would it be possible to store the old tw->ptr value at the top of this
function (e.g. in tw_base) and calculate start using (tw->ptr -
tw_base)? It seems that there are two parallel trackers here.

> tw->ptr += tputq(fout, start);
>
> /* use a placeholder for the size */
> @@ -1517,6 +1541,9 @@ static int write_flyrecord(struct twriter *tw, enum 
> out_format_t out_format,
> tw->ptr += tputq(fout, len);
> tw->ptr += tputs(fout, str);
>
> +   debug("End of flyrecord header at: 0x%x, offset: 0x%llx\n",
> + tw->ptr, start);
> +
> debug("trace text base %lx, map file %lx\n", text_base, text_offset);
>
> ret = write_pages(tw, out_format, missing_countp, skip_countp);
> --
> 2.36.1
>

Regards,
Simon


Re: [PATCH 2/3] trace: Move trace_clocks description above record offset calculation

2023-09-12 Thread Simon Glass
On Mon, 11 Sept 2023 at 06:32, Michal Simek  wrote:
>
> Flyrecord tracing data are page aligned that's why it is necessary to
> calculate alignment properly. Because trace_clocks description is the part
> of record length it is necessary to have information about length earlier.
>
> Signed-off-by: Michal Simek 
> ---
>
>  tools/proftool.c | 7 ---
>  1 file changed, 4 insertions(+), 3 deletions(-)
>

Reviewed-by: Simon Glass 


Re: [PATCH] usb: dwc3: core: add external vBus supply support for ulpi phy

2023-09-12 Thread Marek Vasut

On 9/12/23 06:01, Venkatesh Yadav Abbarapu wrote:

[ Piyush: Ported from Linux kernel commit
  b84ba26c922a ("usb: dwc3: core: add external vBus
supply support for ulpi phy") ]

Some ULPI USB PHY does not support internal VBUS supply, to drive the CPEN
pin, which requires the configuration of the ULPI DRVVBUSEXTERNAL bit of
OTG_CTRL register.

Added 'snps,ulpi-ext-vbus-drv' a DT property to configure the USB2 PHY to
drive VBUS with an external supply, by setting the USB2 PHY ULPIEXTVBUSDRV
bit[:17] of the GUSB2PHYCFG register to drive VBUS with an external supply.

Signed-off-by: Venkatesh Yadav Abbarapu 


Please sync the DWC3 driver with Linux first.


Re: [PATCH v2 3/3] config: j7200: remove not needed power config

2023-09-12 Thread Nishanth Menon
On 18:36-20230912, Udit Kumar wrote:
> For J7200, R5/SPL TI_SCI_POWER_DOMAIN should be
> disabled as DM is a separate binary like other
> SOC of J7* family.
> 
> Fixes: 02dff65efe7 (configs: j7200_evm_r5: Add initial support)

Fixes: 02dff65efe70 ("configs: j7200_evm_r5: Add initial support")

> 
> Signed-off-by: Udit Kumar 
> ---
>  configs/j7200_evm_r5_defconfig | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/configs/j7200_evm_r5_defconfig b/configs/j7200_evm_r5_defconfig
> index 6d240b16cb..9e744ba434 100644
> --- a/configs/j7200_evm_r5_defconfig
> +++ b/configs/j7200_evm_r5_defconfig
> @@ -126,7 +126,6 @@ CONFIG_SPL_PINCTRL=y
>  # CONFIG_SPL_PINCTRL_GENERIC is not set
>  CONFIG_PINCTRL_SINGLE=y
>  CONFIG_POWER_DOMAIN=y
> -CONFIG_TI_SCI_POWER_DOMAIN=y
>  CONFIG_TI_POWER_DOMAIN=y
>  CONFIG_DM_PMIC=y
>  CONFIG_PMIC_TPS65941=y
> -- 
> 2.34.1
> 

-- 
Regards,
Nishanth Menon
Key (0xDDB5849D1736249D) / Fingerprint: F8A2 8693 54EB 8232 17A3  1A34 DDB5 
849D 1736 249D


Re: [PATCH v2 2/3] clk: ti: Add support to enable configs conditionally

2023-09-12 Thread Nishanth Menon
On 18:36-20230912, Udit Kumar wrote:
> TI SOC has two clock domains CLK_TI_SCI and
> CLK_K3. These are mutually exclusive.
> 
> Adding conditional check for CLK_TI_SCI
> and CLK_K3 along with other associated configs options.
> 
> Suggested-by: Nishanth Menon 
> Signed-off-by: Udit Kumar 
> ---
>  drivers/clk/ti/Kconfig | 8 
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/clk/ti/Kconfig b/drivers/clk/ti/Kconfig
> index fbcdefd889..a21359d6b2 100644
> --- a/drivers/clk/ti/Kconfig
> +++ b/drivers/clk/ti/Kconfig
> @@ -36,7 +36,7 @@ config CLK_TI_MUX
>  
>  config CLK_TI_SCI
>   bool "TI System Control Interface (TI SCI) clock driver"
> - depends on CLK && TI_SCI_PROTOCOL && OF_CONTROL
> + depends on CLK && TI_SCI_PROTOCOL && OF_CONTROL && !CLK_K3
>   help
> This enables the clock driver support over TI System Control Interface
> available on some new TI's SoCs. If you wish to use clock resources
> @@ -44,13 +44,13 @@ config CLK_TI_SCI
>  
>  config CLK_K3_PLL
>   bool "PLL clock support for K3 SoC family of devices"
> - depends on CLK && LIB_RATIONAL
> + depends on CLK && LIB_RATIONAL && !CLK_TI_SCI
>   help
> Enables PLL clock support for K3 SoC family of devices.
>  
>  config SPL_CLK_K3_PLL
>   bool "PLL clock support for K3 SoC family of devices"
> - depends on CLK && LIB_RATIONAL && SPL
> + depends on CLK && LIB_RATIONAL && SPL && !CLK_TI_SCI
>   help
> Enables PLL clock support for K3 SoC family of devices.
>  
> @@ -62,6 +62,6 @@ config CLK_K3
>  
>  config SPL_CLK_K3
>   bool "Clock support for K3 SoC family of devices"
> - depends on CLK && SPL
> + depends on CLK && SPL && !CLK_TI_SCI
>   help
> Enables the clock translation layer from DT to device clocks.
> -- 
> 2.34.1
> 

Reviewed-by: Nishanth Menon 
-- 
Regards,
Nishanth Menon
Key (0xDDB5849D1736249D) / Fingerprint: F8A2 8693 54EB 8232 17A3  1A34 DDB5 
849D 1736 249D


Re: [PATCH v2 1/3] power: domain: ti: Enable single config for power domain

2023-09-12 Thread Nishanth Menon
On 18:36-20230912, Udit Kumar wrote:
> TI SOC has two power domain TI_SCI_POWER_DOMAIN and
> TI_POWER_DOMAIN. These are mutually exclusive.
> So adding rule to select one, in case defconfig enabled both.
> 
> Suggested-by: Nishanth Menon 
> Signed-off-by: Udit Kumar 
> ---
>  drivers/power/domain/Kconfig | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/power/domain/Kconfig b/drivers/power/domain/Kconfig
> index 411c210756..30c358fb88 100644
> --- a/drivers/power/domain/Kconfig
> +++ b/drivers/power/domain/Kconfig
> @@ -92,7 +92,7 @@ config TEGRA186_POWER_DOMAIN
>  
>  config TI_SCI_POWER_DOMAIN
>   bool "Enable the TI SCI-based power domain driver"
> - depends on POWER_DOMAIN && TI_SCI_PROTOCOL
> + depends on POWER_DOMAIN && TI_SCI_PROTOCOL && !TI_POWER_DOMAIN
>   help
> Generic power domain implementation for TI devices implementing the
> TI SCI protocol.
> -- 
> 2.34.1
> 

Reviewed-by: Nishanth Menon 

-- 
Regards,
Nishanth Menon
Key (0xDDB5849D1736249D) / Fingerprint: F8A2 8693 54EB 8232 17A3  1A34 DDB5 
849D 1736 249D


Re: [PATCH v2 1/4] part: rename disk_partition_type_uuid()

2023-09-12 Thread Tom Rini
On Sat, Sep 02, 2023 at 09:35:21AM +0200, Heinrich Schuchardt wrote:

> Rename disk_partition_type_uuid to disk_partition_type_guid.
> 
> Provide function descriptions for the getter and setter.
> 
> Fixes: bcd645428c34 ("part: Add accessors for struct disk_partition 
> type_uuid")
> Signed-off-by: Heinrich Schuchardt 
> Reviewed-by: Simon Glass 

For the series, applied to u-boot/next, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v5 3/8] tests: gpt: Remove test order dependency

2023-09-12 Thread Tom Rini
On Thu, Aug 31, 2023 at 10:51:36AM -0600, Joshua Watt wrote:

> Re-create a clean disk image for each test to prevent modifications from
> one test affecting another
> 
> Signed-off-by: Joshua Watt 

For the series, applied to u-boot/next, thanks!

-- 
Tom


signature.asc
Description: PGP signature


[PATCH] imx7: Disable CAAM Job Ring 0

2023-09-12 Thread Fabio Estevam
From: Fabio Estevam 

Trying to boot a fitImage after a successful hab_auth_img operation
causes the following error:

 ## Loading kernel from FIT Image at 8800 ...
   Using 'conf-imx7d-smegw01.dtb' configuration
   Trying 'kernel-1' kernel subimage
 Description:  Linux kernel
 Type: Kernel Image
 Compression:  uncompressed
 Data Start:   0x8800010c
 Data Size:9901752 Bytes = 9.4 MiB
 Architecture: ARM
 OS:   Linux
 Load Address: 0x8080
 Entry Point:  0x8080
 Hash algo:sha256
 Hash value:   
28f8779bbf010780f16dd3d84ecb9b604c44c5c2cf7acd098c264a2d3f68e969
   Verifying Hash Integrity ... sha256Error in SEC deq
   CAAM was not setup properly or it is faulty error!

The reason for this error is that the BootROM uses the CAAM Job Ring 0,
so disable its node in U-Boot to avoid the resource conflict.

imx8m dtsi files also have the Job Ring 0 disable since the following
kernel commit:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/arch?h=v6.5=dc9c1ceb555ff661e6fc1081434600771f29657c

For a temporary solution, disable the Job Ring 0 in imx7s-u-boot.dtsi.

Reported-by: Eduard Strehlau 
Signed-off-by: Fabio Estevam 
---
 arch/arm/dts/imx7d-colibri-eval-v3-u-boot.dtsi | 2 ++
 arch/arm/dts/imx7d-pico-pi-u-boot.dtsi | 2 ++
 arch/arm/dts/imx7d-sdb-qspi-u-boot.dtsi| 2 ++
 arch/arm/dts/imx7d-sdb-u-boot.dtsi | 2 ++
 arch/arm/dts/imx7d-smegw01-u-boot.dtsi | 3 +++
 arch/arm/dts/imx7s-u-boot.dtsi | 7 +++
 6 files changed, 18 insertions(+)
 create mode 100644 arch/arm/dts/imx7d-smegw01-u-boot.dtsi
 create mode 100644 arch/arm/dts/imx7s-u-boot.dtsi

diff --git a/arch/arm/dts/imx7d-colibri-eval-v3-u-boot.dtsi 
b/arch/arm/dts/imx7d-colibri-eval-v3-u-boot.dtsi
index 52aa8758701f..57ca28edb70d 100644
--- a/arch/arm/dts/imx7d-colibri-eval-v3-u-boot.dtsi
+++ b/arch/arm/dts/imx7d-colibri-eval-v3-u-boot.dtsi
@@ -3,6 +3,8 @@
  * Copyright 2020-2022 Toradex
  */
 
+#include "imx7s-u-boot.dtsi"
+
 &{/aliases} {
/* SDHCI instance order: eMMC, SD/MMC */
mmc0 = 
diff --git a/arch/arm/dts/imx7d-pico-pi-u-boot.dtsi 
b/arch/arm/dts/imx7d-pico-pi-u-boot.dtsi
index 67b41ae1129c..843b4583e53a 100644
--- a/arch/arm/dts/imx7d-pico-pi-u-boot.dtsi
+++ b/arch/arm/dts/imx7d-pico-pi-u-boot.dtsi
@@ -1,3 +1,5 @@
+#include "imx7s-u-boot.dtsi"
+
 /{
 aliases {
 mmc0 = 
diff --git a/arch/arm/dts/imx7d-sdb-qspi-u-boot.dtsi 
b/arch/arm/dts/imx7d-sdb-qspi-u-boot.dtsi
index 62cdcbaeb67d..896c8bcaa5ad 100644
--- a/arch/arm/dts/imx7d-sdb-qspi-u-boot.dtsi
+++ b/arch/arm/dts/imx7d-sdb-qspi-u-boot.dtsi
@@ -3,6 +3,8 @@
  * Copyright 2018 NXP
  */
 
+#include "imx7s-u-boot.dtsi"
+
  {
flash0: mx25l51245g@0 {
compatible = "jedec,spi-nor";
diff --git a/arch/arm/dts/imx7d-sdb-u-boot.dtsi 
b/arch/arm/dts/imx7d-sdb-u-boot.dtsi
index ac1d6e2e6480..e4a27b8dd5aa 100644
--- a/arch/arm/dts/imx7d-sdb-u-boot.dtsi
+++ b/arch/arm/dts/imx7d-sdb-u-boot.dtsi
@@ -1,3 +1,5 @@
+#include "imx7s-u-boot.dtsi"
+
  {
status = "disable";
 };
diff --git a/arch/arm/dts/imx7d-smegw01-u-boot.dtsi 
b/arch/arm/dts/imx7d-smegw01-u-boot.dtsi
new file mode 100644
index ..90f7500ee34c
--- /dev/null
+++ b/arch/arm/dts/imx7d-smegw01-u-boot.dtsi
@@ -0,0 +1,3 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+
+#include "imx7s-u-boot.dtsi"
diff --git a/arch/arm/dts/imx7s-u-boot.dtsi b/arch/arm/dts/imx7s-u-boot.dtsi
new file mode 100644
index ..c4c1da3c64f1
--- /dev/null
+++ b/arch/arm/dts/imx7s-u-boot.dtsi
@@ -0,0 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0+ OR MIT
+
+ {
+   sec_jr0: jr@1000 {
+   status = "disabled";
+   };
+};
-- 
2.34.1



Re: [PATCH] arm: apple: Add initial Apple M2 Ultra support

2023-09-12 Thread Simon Glass
Hi Mark,

On Mon, 11 Sept 2023 at 14:25, Mark Kettenis  wrote:
>
> > From: Simon Glass 
> > Date: Sun, 10 Sep 2023 16:36:48 -0600
> >
> > Hi,
> >
> > On Wed, 6 Sept 2023 at 15:50, Janne Grunau  wrote:
> > >
> > > Apple's M2 Ultra SoC are somewhat similar to the M1 Ultra but needs
> > > a tweaked memory map as the M2 Pro/Max SoCs.  USB, NVMe, UART, WDT
> > > and PCIe are working with the existing drivers.
> > >
> > > Signed-off-by: Janne Grunau 
> > > ---
> > >  arch/arm/mach-apple/board.c | 183 
> > > 
> > >  1 file changed, 183 insertions(+)
> > >
> > > diff --git a/arch/arm/mach-apple/board.c b/arch/arm/mach-apple/board.c
> > > index d50194811843..47393babbc62 100644
> > > --- a/arch/arm/mach-apple/board.c
> > > +++ b/arch/arm/mach-apple/board.c
> > > @@ -444,6 +444,187 @@ static struct mm_region t6020_mem_map[] = {
> > > }
> > >  };
> > >
> > > +/* Apple M2 Ultra */
> > > +
> > > +static struct mm_region t6022_mem_map[] = {
> > > +   {
> > > +   /* I/O */
> > > +   .virt = 0x28000,
> > > +   .phys = 0x28000,
> > > +   .size = SZ_1G,
> > > +   .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
> > > +PTE_BLOCK_NON_SHARE |
> > > +PTE_BLOCK_PXN | PTE_BLOCK_UXN
> > > +   }, {
> >
> > Is there no devicetree binding for this information?
>
> Not directly.  The device tree does contain the addresses of the
> devices of course.  But what we want here is a memory map that uses a
> few big ranges that cover all the devices in the device tree rather
> than lots of small ranges that cover the individual devices.

OK I see.

>
> But yes, it sucks that every time Apple produces a new SoC we need to
> add another memory map.

Regards,
Simon


Re: [PATCH] addrmap: Fix off by one in addrmap_set_entry()

2023-09-12 Thread Simon Glass
On Thu, 27 Jul 2023 at 19:51, Simon Glass  wrote:
>
> Hi Dan,
>
> On Thu, 27 Jul 2023 at 04:56, Dan Carpenter  wrote:
> >
> > On Wed, Jul 26, 2023 at 06:49:44PM -0600, Simon Glass wrote:
> > > Hi Dan,
> > >
> > > On Tue, 25 Jul 2023 at 09:40, Dan Carpenter  
> > > wrote:
> > > >
> > > > The > comparison needs to be changed to >= to prevent an out of bounds
> > > > write on th next line.
> > > >
> > > > Signed-off-by: Dan Carpenter 
> > > > ---
> > > >  lib/addr_map.c | 2 +-
> > > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > >
> > > > diff --git a/lib/addr_map.c b/lib/addr_map.c
> > > > index 9b3e0a544e47..86e932e4b561 100644
> > > > --- a/lib/addr_map.c
> > > > +++ b/lib/addr_map.c
> > > > @@ -59,7 +59,7 @@ void *addrmap_phys_to_virt(phys_addr_t paddr)
> > > >  void addrmap_set_entry(unsigned long vaddr, phys_addr_t paddr,
> > > > phys_size_t size, int idx)
> > > >  {
> > > > -   if (idx > CONFIG_SYS_NUM_ADDR_MAP)
> > > > +   if (idx >= CONFIG_SYS_NUM_ADDR_MAP)
> > > > return;
> > >
> > > It looks like this function should return an error.
> > >
> >
> > If we hit this error path there probably isn't a reasonable way to
> > recover.  Maybe we could add a WARN()?
>
> When we get an error we should report it. For leaf functions like
> this, WARN adds to code size for a case that should not happen. The
> caller will need to check the error and fail. The function should
> always have had an error-return code, by the look of it. If we adopt
> the approach of warning instead of returning error codes,
>
> +Bin Meng
> +Kumar Gala

Since this is a fix, separate from the poor API:

Reviewed-by: Simon Glass 


Re: [PATCH v3 5/9] board_f: Fix corruption of relocaddr

2023-09-12 Thread Devarsh Thakkar
Hi Simon,

On 11/09/23 04:44, Simon Glass wrote:
> Hi Devarsh,
> 
> On Thu, 17 Aug 2023 at 09:10, Tom Rini  wrote:
>>
>> On Wed, Aug 16, 2023 at 09:16:05PM +0530, Devarsh Thakkar wrote:
>>> Hi Simon,
>>>
>>> On 15/08/23 20:14, Simon Glass wrote:
 Hi Devarsh,

 On Tue, 15 Aug 2023 at 03:23, Devarsh Thakkar  wrote:
>
> Hi Simon, Tom,
>
> On 15/08/23 04:13, Simon Glass wrote:
>> Hi Devarsh, Nikhil, Tom,
>>
>> On Wed, 9 Aug 2023 at 09:29, Bin Meng  wrote:
>>>
>>> On Thu, Aug 3, 2023 at 7:03 PM Bin Meng  wrote:

 On Thu, Aug 3, 2023 at 6:37 PM Bin Meng  wrote:
>
> On Tue, Aug 1, 2023 at 12:00 AM Simon Glass  wrote:
>>
>> When the video framebuffer comes from the bloblist, we should not 
>> change
>> relocaddr to this address, since it interfers with the normal memory
>
> typo: interferes
>
>> allocation.
>>
>> This fixes a boot loop in qemu-x86_64
>>
>> Signed-off-by: Simon Glass 
>> Fixes: 5bc610a7d9d ("common: board_f: Pass frame buffer info from 
>> SPL to u-boot")
>> Suggested-by: Nikhil M Jain 
>> ---
>>
>> Changes in v3:
>> - Reword the Kconfig help as suggested
>>
>> Changes in v2:
>> - Add a Kconfig as the suggested conditional did not work
>>
>>   common/board_f.c  | 3 ++-
>>   drivers/video/Kconfig | 9 +
>>   2 files changed, 11 insertions(+), 1 deletion(-)
>>
>> diff --git a/common/board_f.c b/common/board_f.c
>> index 7d2c380e91e..5173d0a0c2d 100644
>> --- a/common/board_f.c
>> +++ b/common/board_f.c
>> @@ -419,7 +419,8 @@ static int reserve_video(void)
>>  if (!ho)
>>  return log_msg_ret("blf", -ENOENT);
>>  video_reserve_from_bloblist(ho);
>> -   gd->relocaddr = ho->fb;
>> +   if (IS_ENABLED(CONFIG_VIDEO_RESERVE_SPL))
>> +   gd->relocaddr = ho->fb;
>>  } else if (CONFIG_IS_ENABLED(VIDEO)) {
>>  ulong addr;
>>  int ret;
>> diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
>> index b41dc60cec5..f2e56204d52 100644
>> --- a/drivers/video/Kconfig
>> +++ b/drivers/video/Kconfig
>> @@ -1106,6 +1106,15 @@ config SPL_VIDEO_REMOVE
>>if this  option is enabled video driver will be removed 
>> at the end of
>>SPL stage, beforeloading the next stage.
>>
>> +config VIDEO_RESERVE_SPL
>> +   bool
>> +   help
>> + This adjusts reserve_video() to redirect memory 
>> reservation when it
>> + sees a video handoff blob (BLOBLISTT_U_BOOT_VIDEO). This 
>> avoids the
>> + memory used for framebuffer from being allocated by U-Boot 
>> proper,
>> + thus preventing any further memory reservations done by 
>> U-Boot proper
>> + from overwriting the framebuffer.
>> +
>>   if SPL_SPLASH_SCREEN
>>
>>   config SPL_SPLASH_SCREEN_ALIGN
>
> Reviewed-by: Bin Meng 

 applied to u-boot-x86, thanks!
>>>
>>> Dropped this one from the x86 queue per the discussion.
>>
>> I just wanted to come back to this discussion.
>>
>> Do we have an agreed way forward? Who is waiting for who?
>>
>
> I was waiting on feedback on
> https://lore.kernel.org/all/3b1e8005-f161-8058-13e7-3de2316aa...@ti.com/
> but per my opinion, I would prefer to go with "Approach 2" with a
> Kconfig as it looks simpler to me. It would look something like below :
>
> if (gd->relocaddr > (unsigned long)ho->fb) {
>   ulong fb_reloc_gap = gd->relocaddr - gd->ho->fb;
>
>   /* Relocate after framebuffer area if nearing too close to it */
>   if (fb_reloc_gap < CONFIG_BLOBLIST_FB_RELOC_MIN_GAP)
>  gd->relocaddr = ho->fb;
> }
>
> Regarding CONFIG_BLOBLIST_FB_RELOC_MIN_GAP
> -> This describes minimum gap to keep between framebuffer address and
> relocation address to avoid overlap when framebuffer address used by
> blob is below the current relocation address
>
> -> It would be selected as default when CONFIG_BLOBLIST is selected with
>   default value set to 100Mb
>
> -> SoC specific Vendors can override this in their defconfigs to a
> custom value if they feel 100Mb is not enough
>
> Also probably we can have some debug/error prints in the code to show
> overlap happened (or is going happen) so that users can fine tune this
> Kconfig if they got it wrong at 

[PATCH v2 3/3] config: j7200: remove not needed power config

2023-09-12 Thread Udit Kumar
For J7200, R5/SPL TI_SCI_POWER_DOMAIN should be
disabled as DM is a separate binary like other
SOC of J7* family.

Fixes: 02dff65efe7 (configs: j7200_evm_r5: Add initial support)

Signed-off-by: Udit Kumar 
---
 configs/j7200_evm_r5_defconfig | 1 -
 1 file changed, 1 deletion(-)

diff --git a/configs/j7200_evm_r5_defconfig b/configs/j7200_evm_r5_defconfig
index 6d240b16cb..9e744ba434 100644
--- a/configs/j7200_evm_r5_defconfig
+++ b/configs/j7200_evm_r5_defconfig
@@ -126,7 +126,6 @@ CONFIG_SPL_PINCTRL=y
 # CONFIG_SPL_PINCTRL_GENERIC is not set
 CONFIG_PINCTRL_SINGLE=y
 CONFIG_POWER_DOMAIN=y
-CONFIG_TI_SCI_POWER_DOMAIN=y
 CONFIG_TI_POWER_DOMAIN=y
 CONFIG_DM_PMIC=y
 CONFIG_PMIC_TPS65941=y
-- 
2.34.1



[PATCH v2 2/3] clk: ti: Add support to enable configs conditionally

2023-09-12 Thread Udit Kumar
TI SOC has two clock domains CLK_TI_SCI and
CLK_K3. These are mutually exclusive.

Adding conditional check for CLK_TI_SCI
and CLK_K3 along with other associated configs options.

Suggested-by: Nishanth Menon 
Signed-off-by: Udit Kumar 
---
 drivers/clk/ti/Kconfig | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/clk/ti/Kconfig b/drivers/clk/ti/Kconfig
index fbcdefd889..a21359d6b2 100644
--- a/drivers/clk/ti/Kconfig
+++ b/drivers/clk/ti/Kconfig
@@ -36,7 +36,7 @@ config CLK_TI_MUX
 
 config CLK_TI_SCI
bool "TI System Control Interface (TI SCI) clock driver"
-   depends on CLK && TI_SCI_PROTOCOL && OF_CONTROL
+   depends on CLK && TI_SCI_PROTOCOL && OF_CONTROL && !CLK_K3
help
  This enables the clock driver support over TI System Control Interface
  available on some new TI's SoCs. If you wish to use clock resources
@@ -44,13 +44,13 @@ config CLK_TI_SCI
 
 config CLK_K3_PLL
bool "PLL clock support for K3 SoC family of devices"
-   depends on CLK && LIB_RATIONAL
+   depends on CLK && LIB_RATIONAL && !CLK_TI_SCI
help
  Enables PLL clock support for K3 SoC family of devices.
 
 config SPL_CLK_K3_PLL
bool "PLL clock support for K3 SoC family of devices"
-   depends on CLK && LIB_RATIONAL && SPL
+   depends on CLK && LIB_RATIONAL && SPL && !CLK_TI_SCI
help
  Enables PLL clock support for K3 SoC family of devices.
 
@@ -62,6 +62,6 @@ config CLK_K3
 
 config SPL_CLK_K3
bool "Clock support for K3 SoC family of devices"
-   depends on CLK && SPL
+   depends on CLK && SPL && !CLK_TI_SCI
help
  Enables the clock translation layer from DT to device clocks.
-- 
2.34.1



[PATCH v2 0/3] enable power and clock Kconfig conditionally

2023-09-12 Thread Udit Kumar
This series, updates enabling mutually exclusive power and clock configs
for TI SOCs.


Sorry to push clock and power changes in one series,
managed by two maintainers. But In my quick grep,
I am not able to active PR raise from both trees.
So copying maintainers of clock and power for review.

Change log
Changes in v2:
- Patch 1 and 2) Added conditional support to enable Kconfig
- Patch 3 No change
link to v1:
https://lore.kernel.org/all/2023091946.749270-1-u-kum...@ti.com/


Udit Kumar (3):
  power: domain: ti: Enable single config for power domain
  clk: ti: Add support to enable configs conditionally
  config: j7200: remove not needed power config

 configs/j7200_evm_r5_defconfig | 1 -
 drivers/clk/ti/Kconfig | 8 
 drivers/power/domain/Kconfig   | 2 +-
 3 files changed, 5 insertions(+), 6 deletions(-)

-- 
2.34.1



[PATCH v2 1/3] power: domain: ti: Enable single config for power domain

2023-09-12 Thread Udit Kumar
TI SOC has two power domain TI_SCI_POWER_DOMAIN and
TI_POWER_DOMAIN. These are mutually exclusive.
So adding rule to select one, in case defconfig enabled both.

Suggested-by: Nishanth Menon 
Signed-off-by: Udit Kumar 
---
 drivers/power/domain/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/power/domain/Kconfig b/drivers/power/domain/Kconfig
index 411c210756..30c358fb88 100644
--- a/drivers/power/domain/Kconfig
+++ b/drivers/power/domain/Kconfig
@@ -92,7 +92,7 @@ config TEGRA186_POWER_DOMAIN
 
 config TI_SCI_POWER_DOMAIN
bool "Enable the TI SCI-based power domain driver"
-   depends on POWER_DOMAIN && TI_SCI_PROTOCOL
+   depends on POWER_DOMAIN && TI_SCI_PROTOCOL && !TI_POWER_DOMAIN
help
  Generic power domain implementation for TI devices implementing the
  TI SCI protocol.
-- 
2.34.1



Re: [PATCH v3 16/16] doc: board: ti: k3: Add J784S4 EVM and AM69 SK documentation

2023-09-12 Thread Marcel Ziswiler
On Fri, 2023-09-08 at 16:35 +0530, Apurva Nandan wrote:
> TI K3 J784S4 and AM69 SK are new additions to the K3 SoC family.
> Add documentation about the J784S4 EVM and AM69 SK.
> 
> Signed-off-by: Dasnavis Sabiya 
> Signed-off-by: Apurva Nandan 
> ---
>  board/ti/j784s4/MAINTAINERS |   1 +
>  doc/board/ti/j784s4_evm.rst | 339 
>  doc/board/ti/k3.rst |   1 +
>  3 files changed, 341 insertions(+)
>  create mode 100644 doc/board/ti/j784s4_evm.rst
> 
> diff --git a/board/ti/j784s4/MAINTAINERS b/board/ti/j784s4/MAINTAINERS
> index 7d3549dd31..be2f9a04b7 100644
> --- a/board/ti/j784s4/MAINTAINERS
> +++ b/board/ti/j784s4/MAINTAINERS
> @@ -18,3 +18,4 @@ F:arch/arm/dts/k3-j784s4-ddr-evm-lp4-4266.dtsi
>  F: arch/arm/dts/k3-am69-sk.dts
>  F: arch/arm/dts/k3-am69-sk-u-boot.dtsi
>  F: arch/arm/dts/k3-am69-r5-sk.dts
> +F: doc/board/ti/j784s4_evm.rst
> diff --git a/doc/board/ti/j784s4_evm.rst b/doc/board/ti/j784s4_evm.rst
> new file mode 100644
> index 00..1e2b7f3820
> --- /dev/null
> +++ b/doc/board/ti/j784s4_evm.rst
> @@ -0,0 +1,339 @@
> +.. SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause

Should be:

GPL-2.0-or-later OR BSD-3-Clause

> +.. sectionauthor:: Apurva Nandan 
> +
> +J784S4 and AM69 Platforms
> +=
> +
> +Introduction:
> +-
> +The J784S4 SoC belongs to the K3 Multicore SoC architecture
> +platform, providing advanced system integration in automotive,
> +ADAS and industrial applications requiring AI at the network edge.
> +This SoC extends the K3 Jacinto 7 family of SoCs with focus on
> +raising performance and integration while providing interfaces,
> +memory architecture and compute performance for multi-sensor, high
> +concurrency applications.
> +
> +The device is partitioned into three functional domains, each containing
> +specific processing cores and peripherals:
> +
> +1. Wake-up (WKUP) domain:
> +    * ARM Cortex-M4F processor, runs TI Foundational Security (TIFS)
> +
> +2. Microcontroller (MCU) domain:
> +    * Dual core ARM Cortex-R5F processor, runs device management
> +  and SoC early boot
> +
> +3. MAIN domain:
> +    * Dual core 64-bit ARM Cortex-A72, runs HLOS
> +
> +More info can be found in TRM: http://www.ti.com/lit/zip/spruj52
> +
> +Platform information:
> +
> +* https://www.ti.com/tool/J784S4XEVM
> +* https://www.ti.com/tool/SK-AM69
> +
> +Boot Flow:
> +--
> +Below is the pictorial representation of boot flow:
> +
> +.. image:: img/boot_diagram_k3_current.svg
> +
> +- On this platform, "TI Foundational Security (TIFS)" functions as the
> +  security enclave master. While "Device Manager (DM)", also known as the
> +  "TISCI server" in TI terminology, offers all the essential services.
> +
> +- As illustrated in the diagram above, R5 SPL manages power and clock
> +  services independently before handing over control to DM. The A72 or
> +  the C7x (Aux core) software components request TIFS/DM to handle
> +  security or device management services.
> +
> +Sources:
> +
> +
> +.. include::  k3.rst
> +    :start-after: .. k3_rst_include_start_boot_sources
> +    :end-before: .. k3_rst_include_end_boot_sources
> +
> +Build procedure:
> +
> +0. Setup the environment variables:
> +
> +.. include::  k3.rst
> +    :start-after: .. k3_rst_include_start_common_env_vars_desc
> +    :end-before: .. k3_rst_include_end_common_env_vars_desc
> +
> +.. include::  k3.rst
> +    :start-after: .. k3_rst_include_start_board_env_vars_desc
> +    :end-before: .. k3_rst_include_end_board_env_vars_desc
> +
> +Set the variables corresponding to this platform:
> +
> +.. include::  k3.rst
> +    :start-after: .. k3_rst_include_start_common_env_vars_defn
> +    :end-before: .. k3_rst_include_end_common_env_vars_defn
> +.. code-block:: bash
> +
> + $ export UBOOT_CFG_CORTEXR=j784s4_evm_r5_defconfig
> + $ export UBOOT_CFG_CORTEXA=j784s4_evm_a72_defconfig
> + $ export TFA_BOARD=generic
> + $ export TFA_EXTRA_ARGS="K3_USART=0x8"
> + $ export OPTEE_PLATFORM=k3-j784s4
> + $ export OPTEE_EXTRA_ARGS="CFG_CONSOLE_UART=0x8"
> +
> +.. j784s4_evm_rst_include_start_build_steps
> +
> +1. Trusted Firmware-A:
> +
> +.. include::  k3.rst
> +    :start-after: .. k3_rst_include_start_build_steps_tfa
> +    :end-before: .. k3_rst_include_end_build_steps_tfa
> +
> +
> +2. OP-TEE:
> +
> +.. include::  k3.rst
> +    :start-after: .. k3_rst_include_start_build_steps_optee
> +    :end-before: .. k3_rst_include_end_build_steps_optee
> +
> +3. U-Boot:
> +
> +.. _j784s4_evm_rst_u_boot_r5:
> +
> +* 3.1 R5:
> +
> +.. include::  k3.rst
> +    :start-after: .. k3_rst_include_start_build_steps_spl_r5
> +    :end-before: .. k3_rst_include_end_build_steps_spl_r5
> +
> +.. _j784s4_evm_rst_u_boot_a72:
> +
> +* 3.2 A72:
> +
> +.. include::  k3.rst
> +    :start-after: .. k3_rst_include_start_build_steps_uboot
> +    :end-before: .. k3_rst_include_end_build_steps_uboot
> +.. j784s4_evm_rst_include_end_build_steps

Re: [PATCH v3 13/16] arm: dts: Introduce am69-sk u-boot dts files

2023-09-12 Thread Nishanth Menon
On 12:20-20230912, Marcel Ziswiler wrote:
[...]

> > diff --git a/arch/arm/dts/k3-am69-r5-sk.dts b/arch/arm/dts/k3-am69-r5-sk.dts
> > new file mode 100644
> > index 00..8c789c4f28valuation module (EVM) is a pl
> > --- /dev/null
> > +++ b/arch/arm/dts/k3-am69-r5-sk.dts
> > @@ -0,0 +1,105 @@
> > +// SPDX-License-Identifier: GPL-2.0
> 
> Should be:
> 
> GPL-2.0-only
Indeed https://spdx.org/licenses/GPL-2.0-only.html

Should be fixed in kernel across the board for K3 devices. Thanks for catching.


> BTW: Why is TI not releasing their device trees with a more permissive 
> license like GPL-2.0-or-later OR MIT
> like most others do?

We can check again, but some sort of corporate policy thing, I suspect.
-- 
Regards,
Nishanth Menon
Key (0xDDB5849D1736249D) / Fingerprint: F8A2 8693 54EB 8232 17A3  1A34 DDB5 
849D 1736 249D


Re: [PATCH v3 10/16] arm: dts: Introduce am69-sk dts from linux kernel

2023-09-12 Thread Nishanth Menon
On 12:10-20230912, Marcel Ziswiler wrote:
> On Fri, 2023-09-08 at 16:35 +0530, Apurva Nandan wrote:
> > From: Dasnavis Sabiya 
> > 
> > Introduce the basic am69-sk evm dts from the next-20230905 tag of the
> > linux kernel.
> > 
> > Signed-off-by: Dasnavis Sabiya 
> > Signed-off-by: Apurva Nandan 
> > ---
> >  arch/arm/dts/Makefile   |   3 +-
> >  arch/arm/dts/k3-am69-sk.dts | 364 
> >  2 files changed, 366 insertions(+), 1 deletion(-)
> >  create mode 100644 arch/arm/dts/k3-am69-sk.dts
> > 
> > diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
> > index 363f7a1171..1bcdbea9e5 100644
> > --- a/arch/arm/dts/Makefile
> > +++ b/arch/arm/dts/Makefile
> > @@ -1330,7 +1330,8 @@ dtb-$(CONFIG_SOC_K3_J721S2) += 
> > k3-am68-sk-base-board.dtb\
> >    k3-am68-sk-r5-base-board.dtb\
> >    k3-j721s2-common-proc-board.dtb\
> >    k3-j721s2-r5-common-proc-board.dtb
> > -dtb-$(CONFIG_SOC_K3_J784S4) += k3-j784s4-evm.dtb\
> > +dtb-$(CONFIG_SOC_K3_J784S4) += k3-am69-sk.dtb\
> > +  k3-j784s4-evm.dtb\
> >    k3-j784s4-r5-evm.dtb
> >  dtb-$(CONFIG_SOC_K3_AM642) += k3-am642-evm.dtb \
> >   k3-am642-r5-evm.dtb \
> > diff --git a/arch/arm/dts/k3-am69-sk.dts b/arch/arm/dts/k3-am69-sk.dts
> > new file mode 100644
> > index 00..0699370911
> > --- /dev/null
> > +++ b/arch/arm/dts/k3-am69-sk.dts
> > @@ -0,0 +1,364 @@
> > +// SPDX-License-Identifier: GPL-2.0
> 
> Should be:
> 
> GPL-2.0-only

Nope - comes from the kernel and is in sync with what the rest of dts
imports look like.

> 
> > +/*
> > + * Copyright (C) 2022-2023 Texas Instruments Incorporated - 
> > https://www.ti.com/
> > + *
> > + * Design Files: https://www.ti.com/lit/zip/SPRR466
> > + * TRM: https://www.ti.com/lit/zip/spruj52
> > + */
> > +
> > +/dts-v1/;
> > +
> > +#include 
> > +#include 
> > +#include "k3-j784s4.dtsi"
> > +
> > +/ {
> > +   compatible = "ti,am69-sk", "ti,j784s4";
> > +   model = "Texas Instruments AM69 SK";
> 
> I never understood TI's naming. Somewhere they call it Evaluation Module 
> (EVM), somewhere Starter Kit (SK) and
> even at other places Evaluation Board (EVB).
> 

Hehe - neither do we understand marketing speak - changes over time
etc.. overall pattern: SK is cost optimized (aka "low cost"
and limited expansion) vs evm - relatively large expansion and expensive ;)

-- 
Regards,
Nishanth Menon
Key (0xDDB5849D1736249D) / Fingerprint: F8A2 8693 54EB 8232 17A3  1A34 DDB5 
849D 1736 249D


Re: [PATCH v3 03/16] soc: ti: k3-socinfo: Add entry for J784S4 SoC

2023-09-12 Thread Nishanth Menon
On 11:21-20230912, Marcel Ziswiler wrote:
> On Fri, 2023-09-08 at 16:35 +0530, Apurva Nandan wrote:
> > Add support for J784S4 SoC Identification.
> > 
> > Signed-off-by: Hari Nagalla 
> > Signed-off-by: Apurva Nandan 
> > ---
> >  arch/arm/mach-k3/include/mach/hardware.h | 1 +
> >  drivers/soc/soc_ti_k3.c  | 3 +++
> >  2 files changed, 4 insertions(+)
> > 
> > diff --git a/arch/arm/mach-k3/include/mach/hardware.h 
> > b/arch/arm/mach-k3/include/mach/hardware.h
> > index 03b18f6bad..bada87d0b2 100644
> > --- a/arch/arm/mach-k3/include/mach/hardware.h
> > +++ b/arch/arm/mach-k3/include/mach/hardware.h
> > @@ -50,6 +50,7 @@
> >  #define JTAG_ID_PARTNO_J721S2  0xbb75
> >  #define JTAG_ID_PARTNO_AM62X   0xbb7e
> >  #define JTAG_ID_PARTNO_AM62AX   0xbb8d
> > +#define JTAG_ID_PARTNO_J784S4  0xbb80
> 
> Not sure whether it would be smarter to sort this based on the JTAG ID or the 
> name of the define like you did.

The order followed at the moment is introduction order, which is not
proper.

Alpha sort on name is better.. but the file already does'nt follow the
same.. I suggest doing an alpha sort of the macro based on names as a cleanup 
patch
prior to introducing.

> 
> >  #define K3_SOC_ID(id, ID) \
> >  static inline bool soc_is_##id(void) \
> > diff --git a/drivers/soc/soc_ti_k3.c b/drivers/soc/soc_ti_k3.c
> > index b720131ae5..6f7fcf9e11 100644
> > --- a/drivers/soc/soc_ti_k3.c
> > +++ b/drivers/soc/soc_ti_k3.c
> > @@ -45,6 +45,9 @@ static const char *get_family_string(u32 idreg)
> > case JTAG_ID_PARTNO_AM62AX:
> > family = "AM62AX";
> > break;
> > +   case JTAG_ID_PARTNO_J784S4:
> > +   family = "J784S4";
> > +   break;
> > default:
> > family = "Unknown Silicon";
> > };

-- 
Regards,
Nishanth Menon
Key (0xDDB5849D1736249D) / Fingerprint: F8A2 8693 54EB 8232 17A3  1A34 DDB5 
849D 1736 249D


Re: [PATCH] drivers: misc: k3_avs: Add Linux compatibles to maintain sync

2023-09-12 Thread Nishanth Menon
On 13:06-20230907, Reid Tonking wrote:
> The ti,j7200-vtm and ti,j721e-vtm compatibles are used for voltage
> and thermal monitoring (VTM) by (drivers/thermal/k3_j72xx_bandgap.c)
> in Linux, but the same hardware is used for adaptive voltage scaling
> (AVS) in u-boot, This brings both drivers in line with the same
> compatibles.
> 
> Since the j7200 uses the config as the j721e, the data is inherited
> from j721e vs creating a duplicate
> 
> Signed-off-by: Neha Francis 
> Signed-off-by: Reid Tonking 
> ---
Reviewed-by: Nishanth Menon 

-- 
Regards,
Nishanth Menon
Key (0xDDB5849D1736249D) / Fingerprint: F8A2 8693 54EB 8232 17A3  1A34 DDB5 
849D 1736 249D


Re: [PATCH v3 13/16] arm: dts: Introduce am69-sk u-boot dts files

2023-09-12 Thread Marcel Ziswiler
On Fri, 2023-09-08 at 16:35 +0530, Apurva Nandan wrote:
> From: Dasnavis Sabiya 
> 
> Introduce the base dts files needed for u-boot or to augment the linux
> dtbs for use in the u-boot-spl and u-boot binaries.
> 
> Signed-off-by: Dasnavis Sabiya 
> Signed-off-by: Apurva Nandan 
> ---
>  arch/arm/dts/Makefile   |   3 +-
>  arch/arm/dts/k3-am69-r5-sk.dts  | 105 
>  arch/arm/dts/k3-am69-sk-u-boot.dtsi |  25 +++
>  3 files changed, 132 insertions(+), 1 deletion(-)
>  create mode 100644 arch/arm/dts/k3-am69-r5-sk.dts
>  create mode 100644 arch/arm/dts/k3-am69-sk-u-boot.dtsi
> 
> diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
> index 1bcdbea9e5..bb7ae79745 100644
> --- a/arch/arm/dts/Makefile
> +++ b/arch/arm/dts/Makefile
> @@ -1330,7 +1330,8 @@ dtb-$(CONFIG_SOC_K3_J721S2) += 
> k3-am68-sk-base-board.dtb\
>    k3-am68-sk-r5-base-board.dtb\
>    k3-j721s2-common-proc-board.dtb\
>    k3-j721s2-r5-common-proc-board.dtb
> -dtb-$(CONFIG_SOC_K3_J784S4) += k3-am69-sk.dtb\
> +dtb-$(CONFIG_SOC_K3_J784S4) += k3-am69-r5-sk.dtb\
> +  k3-am69-sk.dtb\
>    k3-j784s4-evm.dtb\
>    k3-j784s4-r5-evm.dtb
>  dtb-$(CONFIG_SOC_K3_AM642) += k3-am642-evm.dtb \
> diff --git a/arch/arm/dts/k3-am69-r5-sk.dts b/arch/arm/dts/k3-am69-r5-sk.dts
> new file mode 100644
> index 00..8c789c4f28valuation module (EVM) is a pl
> --- /dev/null
> +++ b/arch/arm/dts/k3-am69-r5-sk.dts
> @@ -0,0 +1,105 @@
> +// SPDX-License-Identifier: GPL-2.0

Should be:

GPL-2.0-only

BTW: Why is TI not releasing their device trees with a more permissive license 
like GPL-2.0-or-later OR MIT
like most others do?

> +/*
> + * Copyright (C) 2022-2023 Texas Instruments Incorporated - 
> https://www.ti.com/
> + */
> +
> +/dts-v1/;
> +
> +#include "k3-am69-sk.dts"
> +#include "k3-j784s4-ddr-evm-lp4-4266.dtsi"
> +#include "k3-j784s4-ddr.dtsi"
> +#include "k3-am69-sk-u-boot.dtsi"
> +
> +/ {
> +   chosen {
> +   tick-timer = _timer0;
> +   };
> +
> +   aliases {
> +   remoteproc0 = 
> +   remoteproc1 = _0;
> +   };
> +
> +   a72_0: a72@0 {
> +   compatible = "ti,am654-rproc";
> +   reg = <0x0 0x00a9 0x0 0x10>;
> +   power-domains = <_pds 61 TI_SCI_PD_EXCLUSIVE>,
> +   <_pds 202 TI_SCI_PD_EXCLUSIVE>;
> +   resets = <_reset 202 0>;
> +   clocks = <_clks 61 0>;
> +   assigned-clocks = <_clks 61 0>, <_clks 202 0>;
> +   assigned-clock-parents = <_clks 61 2>;
> +   assigned-clock-rates = <2>, <20>;
> +   ti,sci = <>;
> +   ti,sci-proc-id = <32>;
> +   ti,sci-host-id = <10>;
> +   bootph-pre-ram;
> +   };
> +
> +   dm_tifs: dm-tifs {
> +   compatible = "ti,j721e-dm-sci";
> +   ti,host-id = <3>;
> +   ti,secure-host;
> +   mbox-names = "rx", "tx";
> +   mboxes= <_proxy_mcu 21>, <_proxy_mcu 23>;
> +   bootph-pre-ram;
> +   };
> +};
> +
> +_timer0 {
> +   status = "okay";
> +   clock-frequency = <25000>;
> +   bootph-pre-ram;
> +};
> +
> +_proxy_sa3 {
> +   status = "okay";
> +   bootph-pre-ram;
> +};
> +
> +_proxy_mcu {
> +   status = "okay";
> +   bootph-pre-ram;
> +};
> +
> +_mcu_wakeup {
> +   sysctrler: sysctrler {
> +   compatible = "ti,am654-system-controller";
> +   mboxes= <_proxy_mcu 4>,
> +   <_proxy_mcu 5>,
> +   <_proxy_sa3 5>;
> +   mbox-names = "tx", "rx", "boot_notify";
> +   bootph-pre-ram;
> +   };
> +};
> +
> + {
> +   mboxes= <_proxy_mcu 8>, <_proxy_mcu 6>, 
> <_proxy_mcu 5>;
> +   mbox-names = "tx", "rx", "notify";
> +   ti,host-id = <4>;
> +   ti,secure-host;
> +   bootph-pre-ram;
> +};
> +
> +_uart0 {
> +   bootph-pre-ram;
> +   status = "okay";
> +};
> +
> + {
> +   reg = <0x0 0x4704 0x0 0x100>,
> + <0x0 0x5000 0x0 0x800>;
> +};
> +
> + {
> +   reg = <0x0 0x4705 0x0 0x100>,
> + <0x0 0x5800 0x0 0x800>;
> +};
> +
> +_ringacc {
> +   ti,sci = <_tifs>;
> +};
> +
> +_udmap {
> +   ti,sci = <_tifs>;
> +};
> diff --git a/arch/arm/dts/k3-am69-sk-u-boot.dtsi 
> b/arch/arm/dts/k3-am69-sk-u-boot.dtsi
> new file mode 100644
> index 00..c8944499e8
> --- /dev/null
> +++ b/arch/arm/dts/k3-am69-sk-u-boot.dtsi
> @@ -0,0 +1,25 @@
> +// SPDX-License-Identifier: GPL-2.0

Ditto.

> +/*
> + * Copyright (C) 2022 Texas Instruments Incorporated - https://www.ti.com/
> + */
> +
> +#include "k3-j784s4-binman.dtsi"
> +
> +_udmap {
> +   reg =   <0x0 0x285c 0x0 0x100>,
> +   <0x0 

Re: [PATCH 2/2] arm: dts: k3-am625: Sync with kernel v6.6-rc1

2023-09-12 Thread Mattijs Korpershoek
On lun., sept. 11, 2023 at 09:02, Nishanth Menon  wrote:

> Sync device tree with v6.6-rc1
>
> Signed-off-by: Nishanth Menon 

Reviewed-by: Mattijs Korpershoek 

> ---
>  arch/arm/dts/k3-am62-main.dtsi   |  52 -
>  arch/arm/dts/k3-am62-mcu.dtsi|  24 +
>  arch/arm/dts/k3-am62-verdin-dev.dtsi |  50 +
>  arch/arm/dts/k3-am62-verdin.dtsi |  45 +++-
>  arch/arm/dts/k3-am62.dtsi|   8 ++
>  arch/arm/dts/k3-am625-beagleplay.dts | 154 ++-
>  arch/arm/dts/k3-am625-sk.dts |   2 +-
>  7 files changed, 325 insertions(+), 10 deletions(-)
>
> diff --git a/arch/arm/dts/k3-am62-main.dtsi b/arch/arm/dts/k3-am62-main.dtsi
> index 2488e3a537fe..284b90c94da8 100644
> --- a/arch/arm/dts/k3-am62-main.dtsi
> +++ b/arch/arm/dts/k3-am62-main.dtsi
> @@ -55,11 +55,29 @@
>   #phy-cells = <1>;
>   };
>  
> - epwm_tbclk: clock@4130 {
> - compatible = "ti,am62-epwm-tbclk", "syscon";
> + epwm_tbclk: clock-controller@4130 {
> + compatible = "ti,am62-epwm-tbclk";
>   reg = <0x4130 0x4>;
>   #clock-cells = <1>;
>   };
> +
> + audio_refclk0: clock-controller@82e0 {
> + compatible = "ti,am62-audio-refclk";
> + reg = <0x82e0 0x4>;
> + clocks = <_clks 157 0>;
> + assigned-clocks = <_clks 157 0>;
> + assigned-clock-parents = <_clks 157 8>;
> + #clock-cells = <0>;
> + };
> +
> + audio_refclk1: clock-controller@82e4 {
> + compatible = "ti,am62-audio-refclk";
> + reg = <0x82e4 0x4>;
> + clocks = <_clks 157 10>;
> + assigned-clocks = <_clks 157 10>;
> + assigned-clock-parents = <_clks 157 18>;
> + #clock-cells = <0>;
> + };
>   };
>  
>   dmss: bus@4800 {
> @@ -174,7 +192,6 @@
>   crypto: crypto@4090 {
>   compatible = "ti,am62-sa3ul";
>   reg = <0x00 0x4090 0x00 0x1200>;
> - power-domains = <_pds 70 TI_SCI_PD_SHARED>;
>   #address-cells = <2>;
>   #size-cells = <2>;
>   ranges = <0x00 0x4090 0x00 0x4090 0x00 0x3>;
> @@ -590,7 +607,7 @@
>  
>   usb0: usb@3100 {
>   compatible = "snps,dwc3";
> - reg =<0x00 0x3100 0x00 0x5>;
> + reg = <0x00 0x3100 0x00 0x5>;
>   interrupts = , /* 
> irq.0 */
>; /* 
> irq.0 */
>   interrupt-names = "host", "peripheral";
> @@ -613,7 +630,7 @@
>  
>   usb1: usb@3110 {
>   compatible = "snps,dwc3";
> - reg =<0x00 0x3110 0x00 0x5>;
> + reg = <0x00 0x3110 0x00 0x5>;
>   interrupts = , /* 
> irq.0 */
>; /* 
> irq.0 */
>   interrupt-names = "host", "peripheral";
> @@ -718,6 +735,31 @@
>   };
>   };
>  
> + dss: dss@3020 {
> + compatible = "ti,am625-dss";
> + reg = <0x00 0x3020 0x00 0x1000>, /* common */
> +   <0x00 0x30202000 0x00 0x1000>, /* vidl1 */
> +   <0x00 0x30206000 0x00 0x1000>, /* vid */
> +   <0x00 0x30207000 0x00 0x1000>, /* ovr1 */
> +   <0x00 0x30208000 0x00 0x1000>, /* ovr2 */
> +   <0x00 0x3020a000 0x00 0x1000>, /* vp1: Used for OLDI */
> +   <0x00 0x3020b000 0x00 0x1000>; /* vp2: Used as DPI Out */
> + reg-names = "common", "vidl1", "vid",
> + "ovr1", "ovr2", "vp1", "vp2";
> + power-domains = <_pds 186 TI_SCI_PD_EXCLUSIVE>;
> + clocks = <_clks 186 6>,
> +  <_vp1_clk>,
> +  <_clks 186 2>;
> + clock-names = "fck", "vp1", "vp2";
> + interrupts = ;
> + status = "disabled";
> +
> + dss_ports: ports {
> + #address-cells = <1>;
> + #size-cells = <0>;
> + };
> + };
> +
>   hwspinlock: spinlock@2a00 {
>   compatible = "ti,am64-hwspinlock";
>   reg = <0x00 0x2a00 0x00 0x1000>;
> diff --git a/arch/arm/dts/k3-am62-mcu.dtsi b/arch/arm/dts/k3-am62-mcu.dtsi
> index 19fc38157d94..80a3e1db26a9 100644
> --- a/arch/arm/dts/k3-am62-mcu.dtsi
> +++ b/arch/arm/dts/k3-am62-mcu.dtsi
> @@ -147,4 +147,28 @@
>   /* Tightly coupled to M4F */
>   status = "reserved";
>   };
> +
> + mcu_mcan0: can@4e08000 {
> + compatible = "bosch,m_can";
> + reg = <0x00 

Re: [PATCH v3 10/16] arm: dts: Introduce am69-sk dts from linux kernel

2023-09-12 Thread Marcel Ziswiler
On Fri, 2023-09-08 at 16:35 +0530, Apurva Nandan wrote:
> From: Dasnavis Sabiya 
> 
> Introduce the basic am69-sk evm dts from the next-20230905 tag of the
> linux kernel.
> 
> Signed-off-by: Dasnavis Sabiya 
> Signed-off-by: Apurva Nandan 
> ---
>  arch/arm/dts/Makefile   |   3 +-
>  arch/arm/dts/k3-am69-sk.dts | 364 
>  2 files changed, 366 insertions(+), 1 deletion(-)
>  create mode 100644 arch/arm/dts/k3-am69-sk.dts
> 
> diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
> index 363f7a1171..1bcdbea9e5 100644
> --- a/arch/arm/dts/Makefile
> +++ b/arch/arm/dts/Makefile
> @@ -1330,7 +1330,8 @@ dtb-$(CONFIG_SOC_K3_J721S2) += 
> k3-am68-sk-base-board.dtb\
>    k3-am68-sk-r5-base-board.dtb\
>    k3-j721s2-common-proc-board.dtb\
>    k3-j721s2-r5-common-proc-board.dtb
> -dtb-$(CONFIG_SOC_K3_J784S4) += k3-j784s4-evm.dtb\
> +dtb-$(CONFIG_SOC_K3_J784S4) += k3-am69-sk.dtb\
> +  k3-j784s4-evm.dtb\
>    k3-j784s4-r5-evm.dtb
>  dtb-$(CONFIG_SOC_K3_AM642) += k3-am642-evm.dtb \
>   k3-am642-r5-evm.dtb \
> diff --git a/arch/arm/dts/k3-am69-sk.dts b/arch/arm/dts/k3-am69-sk.dts
> new file mode 100644
> index 00..0699370911
> --- /dev/null
> +++ b/arch/arm/dts/k3-am69-sk.dts
> @@ -0,0 +1,364 @@
> +// SPDX-License-Identifier: GPL-2.0

Should be:

GPL-2.0-only

> +/*
> + * Copyright (C) 2022-2023 Texas Instruments Incorporated - 
> https://www.ti.com/
> + *
> + * Design Files: https://www.ti.com/lit/zip/SPRR466
> + * TRM: https://www.ti.com/lit/zip/spruj52
> + */
> +
> +/dts-v1/;
> +
> +#include 
> +#include 
> +#include "k3-j784s4.dtsi"
> +
> +/ {
> +   compatible = "ti,am69-sk", "ti,j784s4";
> +   model = "Texas Instruments AM69 SK";

I never understood TI's naming. Somewhere they call it Evaluation Module (EVM), 
somewhere Starter Kit (SK) and
even at other places Evaluation Board (EVB).

> +
> +   chosen {
> +   stdout-path = "serial2:115200n8";
> +   };
> +
> +   aliases {
> +   serial0 = _uart0;
> +   serial1 = _uart0;
> +   serial2 = _uart8;
> +   mmc0 = _sdhci0;
> +   mmc1 = _sdhci1;
> +   i2c0 = _i2c0;
> +   i2c3 = _i2c0;
> +   ethernet0 = _cpsw_port1;
> +   };
> +
> +   memory@8000 {
> +   device_type = "memory";
> +   /* 32G RAM */
> +   reg = <0x00 0x8000 0x00 0x8000>,
> + <0x08 0x8000 0x07 0x8000>;
> +   };
> +
> +   reserved_memory: reserved-memory {
> +   #address-cells = <2>;
> +   #size-cells = <2>;
> +   ranges;
> +
> +   secure_ddr: optee@9e80 {
> +   reg = <0x00 0x9e80 0x00 0x0180>;
> +   no-map;
> +   };
> +   };
> +
> +   vusb_main: regulator-vusb-main5v0 {
> +   /* USB MAIN INPUT 5V DC */
> +   compatible = "regulator-fixed";
> +   regulator-name = "vusb-main5v0";
> +   regulator-min-microvolt = <500>;
> +   regulator-max-microvolt = <500>;
> +   regulator-always-on;
> +   regulator-boot-on;
> +   };
> +
> +   vsys_5v0: regulator-vsys5v0 {
> +   /* Output of LM61460 */
> +   compatible = "regulator-fixed";
> +   regulator-name = "vsys_5v0";
> +   regulator-min-microvolt = <500>;
> +   regulator-max-microvolt = <500>;
> +   vin-supply = <_main>;
> +   regulator-always-on;
> +   regulator-boot-on;
> +   };
> +
> +   vsys_3v3: regulator-vsys3v3 {
> +   /* Output of LM5143 */
> +   compatible = "regulator-fixed";
> +   regulator-name = "vsys_3v3";
> +   regulator-min-microvolt = <330>;
> +   regulator-max-microvolt = <330>;
> +   vin-supply = <_main>;
> +   regulator-always-on;
> +   regulator-boot-on;
> +   };
> +
> +   vdd_mmc1: regulator-sd {
> +   /* Output of TPS22918 */
> +   compatible = "regulator-fixed";
> +   regulator-name = "vdd_mmc1";
> +   regulator-min-microvolt = <330>;
> +   regulator-max-microvolt = <330>;
> +   regulator-boot-on;
> +   enable-active-high;
> +   vin-supply = <_3v3>;
> +   gpio = < 2 GPIO_ACTIVE_HIGH>;
> +   };
> +
> +   vdd_sd_dv: regulator-tlv71033 {
> +   /* Output of TLV71033 */
> +   compatible = "regulator-gpio";
> +   regulator-name = "tlv71033";
> +   pinctrl-names = "default";
> +   pinctrl-0 = 

Re: [PATCH 1/2] arm: dts: k3-pinctrl: Sync with kernel v6.6-rc1

2023-09-12 Thread Mattijs Korpershoek
On lun., sept. 11, 2023 at 09:02, Nishanth Menon  wrote:

> Sync pinctrl header with v6.6-rc1
>
> Signed-off-by: Nishanth Menon 

Reviewed-by: Mattijs Korpershoek 

> ---
>  arch/arm/dts/k3-pinctrl.h | 12 
>  1 file changed, 12 insertions(+)
>
> diff --git a/arch/arm/dts/k3-pinctrl.h b/arch/arm/dts/k3-pinctrl.h
> index c97548a3f42d..2a4e0e084d69 100644
> --- a/arch/arm/dts/k3-pinctrl.h
> +++ b/arch/arm/dts/k3-pinctrl.h
> @@ -11,6 +11,7 @@
>  #define PULLUDEN_SHIFT   (16)
>  #define PULLTYPESEL_SHIFT(17)
>  #define RXACTIVE_SHIFT   (18)
> +#define DEBOUNCE_SHIFT   (11)
>  
>  #define PULL_DISABLE (1 << PULLUDEN_SHIFT)
>  #define PULL_ENABLE  (0 << PULLUDEN_SHIFT)
> @@ -29,9 +30,20 @@
>  #define PIN_INPUT_PULLUP (INPUT_EN | PULL_UP)
>  #define PIN_INPUT_PULLDOWN   (INPUT_EN | PULL_DOWN)
>  
> +#define PIN_DEBOUNCE_DISABLE (0 << DEBOUNCE_SHIFT)
> +#define PIN_DEBOUNCE_CONF1   (1 << DEBOUNCE_SHIFT)
> +#define PIN_DEBOUNCE_CONF2   (2 << DEBOUNCE_SHIFT)
> +#define PIN_DEBOUNCE_CONF3   (3 << DEBOUNCE_SHIFT)
> +#define PIN_DEBOUNCE_CONF4   (4 << DEBOUNCE_SHIFT)
> +#define PIN_DEBOUNCE_CONF5   (5 << DEBOUNCE_SHIFT)
> +#define PIN_DEBOUNCE_CONF6   (6 << DEBOUNCE_SHIFT)
> +
>  #define AM62AX_IOPAD(pa, val, muxmode)   (((pa) & 0x1fff)) 
> ((val) | (muxmode))
>  #define AM62AX_MCU_IOPAD(pa, val, muxmode)   (((pa) & 0x1fff)) ((val) | 
> (muxmode))
>  
> +#define AM62PX_IOPAD(pa, val, muxmode)   (((pa) & 0x1fff)) 
> ((val) | (muxmode))
> +#define AM62PX_MCU_IOPAD(pa, val, muxmode)   (((pa) & 0x1fff)) ((val) | 
> (muxmode))
> +
>  #define AM62X_IOPAD(pa, val, muxmode)(((pa) & 0x1fff)) 
> ((val) | (muxmode))
>  #define AM62X_MCU_IOPAD(pa, val, muxmode)(((pa) & 0x1fff)) ((val) | 
> (muxmode))
>  
> -- 
> 2.40.0


Re: [PATCHv8 00/15] net/lwip: add lwip library for the network stack

2023-09-12 Thread Maxim Uvarov
On Fri, 8 Sept 2023 at 19:59, Tom Rini  wrote:

> On Fri, Sep 08, 2023 at 07:53:05PM +0600, Maxim Uvarov wrote:
>
> > Before apply these patches it  is needed to create lwIP merge into
> U-Boot:
> > git subtree add --prefix net/lwip/lwip-external
> https://git.savannah.nongnu.org/git/lwip.git master --squash
> > or
> > create git submodule, depends how it's more easy to maintain external
> > library.
>
> So, I think we're going to go with subtree.  Please work out how to
> integrate the above in to the build process automatically (and such that
> we can maintain it via upgrades moving forward).
>
> --
> Tom
>

I did not find a good way to friend git format-patch, git am and subtree.
And now with using subtree I can provide my thoughts, in general I do not
see any big advantages
with maintaining subtree code.

Problem is that:

1. subtree does some root reset. So rebase looks like:
label onto



# Branch acbc0469a49de7055141cc730aa9c728e61b6de2-2

reset [new root]

pick acbc0469a4 Squashed 'net/lwip/lwip-external/' content from commit
84fde1ebbf
label acbc0469a49de7055141cc730aa9c728e61b6de2-2



reset onto

merge -C ec4a128c8d acbc0469a49de7055141cc730aa9c728e61b6de2-2 # Merge
commit 'acbc0469a49de7055141cc730aa9c728e61b6de2' as
'net/lwip/lwip-external'
pick 739681a6f5 net/lwip: add doc/develop/net_lwip.rst

pick f0ecab85e0 net/lwip: integrate lwIP library

2. if  --rebase-merges option was not provided to rebase, then rebase will
omit subtree directory and try to apply rebase patches to root directory.
I.e. in current case squashed commit for lwip, will be applied to uboot
root directory instead of ./net/lwip/lwip-external.

3. due to broken rebases without --rebase-merges more likely things like
git bisect also will not work.

4.  change in subtree code ./net/lwip/lwip-external/../something.c will
create a git commit which looks like a standard U-Boot commit. I.e. path
starts with ./net/lwip/lwip-external/

5. lwip maintains code with a mailing list.  So we don't need to push
subtree git somewhere to create a pull request.

6. I rechecked the latest edk2 and they use submodules now. (openssl,
libfdt, berkeley-softfloat-3 and others).

7. dynamic download also looks horrible for me. I.e. create subtree in
Makefile on compilation process. I think maintaining that will give you a
bunch of problems. I think we should not touch git structure after cloning.

So what I can here suggest:
1.  lwip source code is 9.4M.  If we compare all code it will be 564M in
total. So just having 1 commit witn copy of lwip library will work here.

or

2. use git submodules. Size of the project will be lower.  Submodule will
not allow you to use local changes. I.e. change needs to be merged into the
upstream project and then you can update git HEAD for the submodule.

or

3. inside u-boot.git create branch lib-lwip and clone lwip repo there. Then
use git submoule to connect this branch as a folder to the main U-Boot code.

BR,
Maxim.


Re: [PATCH v3 05/16] drivers: dma: Add support for J784S4 SoC

2023-09-12 Thread Marcel Ziswiler
On Fri, 2023-09-08 at 16:35 +0530, Apurva Nandan wrote:
> Add support for DMA in J784S4 SoC.
> 
> Signed-off-by: Jayesh Choudhary 
> Signed-off-by: Hari Nagalla 
> Signed-off-by: Apurva Nandan 
> ---
>  drivers/dma/ti/Makefile   |   1 +
>  drivers/dma/ti/k3-psil-j784s4.c   | 166 ++
>  drivers/dma/ti/k3-psil-priv.h |   1 +
>  drivers/dma/ti/k3-psil.c  |   2 +
>  drivers/firmware/ti_sci_static_data.h |  34 ++
>  drivers/ram/Kconfig   |   2 +-
>  6 files changed, 205 insertions(+), 1 deletion(-)
>  create mode 100644 drivers/dma/ti/k3-psil-j784s4.c
> 
> diff --git a/drivers/dma/ti/Makefile b/drivers/dma/ti/Makefile
> index 6807eb8e8b..bd4ce68d9c 100644
> --- a/drivers/dma/ti/Makefile
> +++ b/drivers/dma/ti/Makefile
> @@ -8,3 +8,4 @@ k3-psil-data-$(CONFIG_SOC_K3_J721E) += k3-psil-j721e.o
>  k3-psil-data-$(CONFIG_SOC_K3_J721S2) += k3-psil-j721s2.o
>  k3-psil-data-$(CONFIG_SOC_K3_AM642) += k3-psil-am64.o
>  k3-psil-data-$(CONFIG_SOC_K3_AM625) += k3-psil-am62.o
> +k3-psil-data-$(CONFIG_SOC_K3_J784S4) += k3-psil-j784s4.o
> diff --git a/drivers/dma/ti/k3-psil-j784s4.c b/drivers/dma/ti/k3-psil-j784s4.c
> new file mode 100644
> index 00..d62d5e9c33
> --- /dev/null
> +++ b/drivers/dma/ti/k3-psil-j784s4.c
> @@ -0,0 +1,166 @@
> +// SPDX-License-Identifier: GPL-2.0

Should be:

GPL-2.0-only

> +/*
> + *  Copyright (C) 2022 Texas Instruments Incorporated - https://www.ti.com
> + */
> +#include 
> +
> +#include "k3-psil-priv.h"
> +
> +#define PSIL_PDMA_XY_TR(x) \
> +   {   \
> +   .thread_id = x, \
> +   .ep_config = {  \
> +   .ep_type = PSIL_EP_PDMA_XY, \
> +   },  \
> +   }
> +
> +#define PSIL_PDMA_XY_PKT(x)\
> +   {   \
> +   .thread_id = x, \
> +   .ep_config = {  \
> +   .ep_type = PSIL_EP_PDMA_XY, \
> +   .pkt_mode = 1,  \
> +   },  \
> +   }
> +
> +#define PSIL_PDMA_MCASP(x) \
> +   {   \
> +   .thread_id = x, \
> +   .ep_config = {  \
> +   .ep_type = PSIL_EP_PDMA_XY, \
> +   .pdma_acc32 = 1,\
> +   .pdma_burst = 1,\
> +   },  \
> +   }
> +
> +#define PSIL_ETHERNET(x)   \
> +   {   \
> +   .thread_id = x, \
> +   .ep_config = {  \
> +   .ep_type = PSIL_EP_NATIVE,  \
> +   .pkt_mode = 1,  \
> +   .needs_epib = 1,\
> +   .psd_size = 16, \
> +   },  \
> +   }
> +
> +#define PSIL_SA2UL(x, tx)  \
> +   {   \
> +   .thread_id = x, \
> +   .ep_config = {  \
> +   .ep_type = PSIL_EP_NATIVE,  \
> +   .pkt_mode = 1,  \
> +   .needs_epib = 1,\
> +   .psd_size = 64, \
> +   .notdpkt = tx,  \
> +   },  \
> +   }
> +
> +/* PSI-L source thread IDs, used for RX (DMA_DEV_TO_MEM) */
> +static struct psil_ep j784s4_src_ep_map[] = {
> +   /* PDMA_MCASP - McASP0-4 */
> +   PSIL_PDMA_MCASP(0x4400),
> +   PSIL_PDMA_MCASP(0x4401),
> +   PSIL_PDMA_MCASP(0x4402),
> +   PSIL_PDMA_MCASP(0x4403),
> +   PSIL_PDMA_MCASP(0x4404),
> +   /* PDMA_SPI_G0 - SPI0-3 */
> +   PSIL_PDMA_XY_PKT(0x4600),
> +   PSIL_PDMA_XY_PKT(0x4601),
> +   PSIL_PDMA_XY_PKT(0x4602),
> +   PSIL_PDMA_XY_PKT(0x4603),
> +   PSIL_PDMA_XY_PKT(0x4604),
> +   PSIL_PDMA_XY_PKT(0x4605),
> +   PSIL_PDMA_XY_PKT(0x4606),
> +   PSIL_PDMA_XY_PKT(0x4607),
> +   PSIL_PDMA_XY_PKT(0x4608),
> +   PSIL_PDMA_XY_PKT(0x4609),
> +   PSIL_PDMA_XY_PKT(0x460a),
> +   PSIL_PDMA_XY_PKT(0x460b),
> +   PSIL_PDMA_XY_PKT(0x460c),
> +   PSIL_PDMA_XY_PKT(0x460d),
> +   PSIL_PDMA_XY_PKT(0x460e),
> +   PSIL_PDMA_XY_PKT(0x460f),
> +   /* PDMA_SPI_G1 - SPI4-7 */
> +   

Re: [PATCH v3 04/16] arm: mach-k3: j784s4: Add clk and power support

2023-09-12 Thread Marcel Ziswiler
On Fri, 2023-09-08 at 16:35 +0530, Apurva Nandan wrote:
> Add clk and device data which can be used by respective drivers
> to configure clocks and PSC.
> 
> Signed-off-by: Hari Nagalla 
> Signed-off-by: Apurva Nandan 
> ---
>  arch/arm/mach-k3/j784s4/Makefile   |   5 +
>  arch/arm/mach-k3/j784s4/clk-data.c | 428 +
>  arch/arm/mach-k3/j784s4/dev-data.c |  98 ++
>  drivers/clk/ti/clk-k3.c    |   6 +
>  drivers/power/domain/ti-power-domain.c |   6 +
>  include/k3-clk.h   |   1 +
>  include/k3-dev.h   |   1 +
>  7 files changed, 545 insertions(+)
>  create mode 100644 arch/arm/mach-k3/j784s4/Makefile
>  create mode 100644 arch/arm/mach-k3/j784s4/clk-data.c
>  create mode 100644 arch/arm/mach-k3/j784s4/dev-data.c
> 
> diff --git a/arch/arm/mach-k3/j784s4/Makefile 
> b/arch/arm/mach-k3/j784s4/Makefile
> new file mode 100644
> index 00..b6cd23457d
> --- /dev/null
> +++ b/arch/arm/mach-k3/j784s4/Makefile
> @@ -0,0 +1,5 @@
> +# SPDX-License-Identifier: GPL-2.0+

Should be:

GPL-2.0-or-later

> +#
> +# Copyright (C) 2022 Texas Instruments Incorporated - https://www.ti.com/
> +obj-y += clk-data.o
> +obj-y += dev-data.o
> diff --git a/arch/arm/mach-k3/j784s4/clk-data.c 
> b/arch/arm/mach-k3/j784s4/clk-data.c
> new file mode 100644
> index 00..1c9f0698ea
> --- /dev/null
> +++ b/arch/arm/mach-k3/j784s4/clk-data.c
> @@ -0,0 +1,428 @@
> +// SPDX-License-Identifier: GPL-2.0+

Ditto.

> +/*
> + * J784S4 specific clock platform data
> + *
> + * This file is auto generated. Please do not hand edit and report any issues
> + * to Bryan Brattlof .
> + *
> + * Copyright (C) 2020-2022 Texas Instruments Incorporated - 
> https://www.ti.com/
> + */
> +
> +#include 
> +#include "k3-clk.h"
> +
> +static const char * const gluelogic_hfosc0_clkout_parents[] = {
> +   "osc_19_2_mhz",
> +   "osc_20_mhz",
> +   "osc_24_mhz",
> +   "osc_25_mhz",
> +   "osc_26_mhz",
> +   "osc_27_mhz",
> +};
> +
> +static const char * const mcu_ospi0_iclk_sel_out0_parents[] = {
> +   "board_0_mcu_ospi0_dqs_out",
> +   "fss_mcu_0_ospi_0_ospi_oclk_clk",
> +};
> +
> +static const char * const mcu_ospi1_iclk_sel_out0_parents[] = {
> +   "board_0_mcu_ospi1_dqs_out",
> +   "fss_mcu_0_ospi_1_ospi_oclk_clk",
> +};
> +
> +static const char * const wkup_fref_clksel_out0_parents[] = {
> +   "gluelogic_hfosc0_clkout",
> +   "j7am_wakeup_16ff_wkup_0_wkup_rcosc_12p5m_clk",
> +};
> +
> +static const char * const k3_pll_ctrl_wrap_wkup_0_sysclkout_clk_parents[] = {
> +   "wkup_fref_clksel_out0",
> +   "hsdiv1_16fft_mcu_0_hsdivout0_clk",
> +};
> +
> +static const char * const mcu_ospi_ref_clk_sel_out0_parents[] = {
> +   "hsdiv4_16fft_mcu_1_hsdivout4_clk",
> +   "hsdiv4_16fft_mcu_2_hsdivout4_clk",
> +};
> +
> +static const char * const mcu_ospi_ref_clk_sel_out1_parents[] = {
> +   "hsdiv4_16fft_mcu_1_hsdivout4_clk",
> +   "hsdiv4_16fft_mcu_2_hsdivout4_clk",
> +};
> +
> +static const char * const wkup_gpio0_clksel_out0_parents[] = {
> +   "k3_pll_ctrl_wrap_wkup_0_chip_div1_clk_clk",
> +   "k3_pll_ctrl_wrap_wkup_0_chip_div1_clk_clk",
> +   "j7am_wakeup_16ff_wkup_0_wkup_rcosc_32k_clk",
> +   "j7am_wakeup_16ff_wkup_0_wkup_rcosc_12p5m_clk",
> +};
> +
> +static const char * const mcu_usart_clksel_out0_parents[] = {
> +   "hsdiv4_16fft_mcu_1_hsdivout3_clk",
> +   "postdiv3_16fft_main_1_hsdivout5_clk",
> +};
> +
> +static const char * const wkup_i2c_mcupll_bypass_out0_parents[] = {
> +   "hsdiv4_16fft_mcu_1_hsdivout3_clk",
> +   "gluelogic_hfosc0_clkout",
> +};
> +
> +static const char * const main_pll_hfosc_sel_out0_parents[] = {
> +   "gluelogic_hfosc0_clkout",
> +   "board_0_hfosc1_clk_out",
> +};
> +
> +static const char * const main_pll_hfosc_sel_out1_parents[] = {
> +   "gluelogic_hfosc0_clkout",
> +   "board_0_hfosc1_clk_out",
> +};
> +
> +static const char * const main_pll_hfosc_sel_out12_parents[] = {
> +   "gluelogic_hfosc0_clkout",
> +   "board_0_hfosc1_clk_out",
> +};
> +
> +static const char * const main_pll_hfosc_sel_out19_parents[] = {
> +   "gluelogic_hfosc0_clkout",
> +   "board_0_hfosc1_clk_out",
> +};
> +
> +static const char * const main_pll_hfosc_sel_out2_parents[] = {
> +   "gluelogic_hfosc0_clkout",
> +   "board_0_hfosc1_clk_out",
> +};
> +
> +static const char * const main_pll_hfosc_sel_out26_0_parents[] = {
> +   "gluelogic_hfosc0_clkout",
> +   "board_0_hfosc1_clk_out",
> +};
> +
> +static const char * const main_pll_hfosc_sel_out27_0_parents[] = {
> +   "gluelogic_hfosc0_clkout",
> +   "board_0_hfosc1_clk_out",
> +};
> +
> +static const char * const main_pll_hfosc_sel_out28_parents[] = {
> +   "gluelogic_hfosc0_clkout",
> +   "board_0_hfosc1_clk_out",
> +};
> +
> +static const char * const main_pll_hfosc_sel_out3_parents[] = {
> +   "gluelogic_hfosc0_clkout",
> +   

Enabling POST in imx8mp processor board. -reg

2023-09-12 Thread S, Lavakumar (GE HealthCare)
Hi all,


Warm greetings all.
I working on enabling RAM test as POST operation in u-boot 2022, for the imx8mp 
processor board.
Can you suggest me how to make things work.
Any leads are appreciated.


Regards,
Lavakumar S
GE CommonOs & Platforms



[PATCH] usb: dwc3: core: add external vBus supply support for ulpi phy

2023-09-12 Thread Venkatesh Yadav Abbarapu
[ Piyush: Ported from Linux kernel commit
  b84ba26c922a ("usb: dwc3: core: add external vBus
supply support for ulpi phy") ]

Some ULPI USB PHY does not support internal VBUS supply, to drive the CPEN
pin, which requires the configuration of the ULPI DRVVBUSEXTERNAL bit of
OTG_CTRL register.

Added 'snps,ulpi-ext-vbus-drv' a DT property to configure the USB2 PHY to
drive VBUS with an external supply, by setting the USB2 PHY ULPIEXTVBUSDRV
bit[:17] of the GUSB2PHYCFG register to drive VBUS with an external supply.

Signed-off-by: Venkatesh Yadav Abbarapu 
---
 drivers/usb/dwc3/core.c | 13 +
 drivers/usb/dwc3/core.h |  4 
 include/dwc3-uboot.h|  1 +
 3 files changed, 18 insertions(+)

diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index 49f6a1900b..d59bbefec4 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -529,6 +529,16 @@ static void dwc3_phy_setup(struct dwc3 *dwc)
if (dwc->dis_u2_freeclk_exists_quirk)
reg &= ~DWC3_GUSB2PHYCFG_U2_FREECLK_EXISTS;
 
+   /*
+* Some ULPI USB PHY does not support internal VBUS supply, to drive
+* the CPEN pin requires the configuration of the ULPI DRVVBUSEXTERNAL
+* bit of OTG_CTRL register. Controller configures the USB2 PHY
+* ULPIEXTVBUSDRV bit[17] of the GUSB2PHYCFG register to drive vBus
+* with an external supply.
+*/
+   if (dwc->ulpi_ext_vbus_drv)
+   reg |= DWC3_GUSB2PHYCFG_ULPIEXTVBUSDRV;
+
dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg);
 
mdelay(100);
@@ -888,6 +898,7 @@ int dwc3_uboot_init(struct dwc3_device *dwc3_dev)
dwc->dis_tx_ipgap_linecheck_quirk = 
dwc3_dev->dis_tx_ipgap_linecheck_quirk;
dwc->dis_enblslpm_quirk = dwc3_dev->dis_enblslpm_quirk;
dwc->dis_u2_freeclk_exists_quirk = 
dwc3_dev->dis_u2_freeclk_exists_quirk;
+   dwc->ulpi_ext_vbus_drv = dwc3_dev->ulpi_ext_vbus_drv;
 
dwc->tx_de_emphasis_quirk = dwc3_dev->tx_de_emphasis_quirk;
if (dwc3_dev->tx_de_emphasis)
@@ -1107,6 +1118,8 @@ void dwc3_of_parse(struct dwc3 *dwc)
"snps,dis-u2-freeclk-exists-quirk");
dwc->tx_de_emphasis_quirk = dev_read_bool(dev,
"snps,tx_de_emphasis_quirk");
+   dwc->ulpi_ext_vbus_drv = dev_read_bool(dev,
+   "snps,ulpi-ext-vbus-drv");
tmp = dev_read_u8_array_ptr(dev, "snps,tx_de_emphasis", 1);
if (tmp)
tx_de_emphasis = *tmp;
diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index 532746dd88..54450842e0 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -184,6 +184,7 @@
 /* Global USB2 PHY Configuration Register */
 #define DWC3_GUSB2PHYCFG_PHYSOFTRST(1 << 31)
 #define DWC3_GUSB2PHYCFG_U2_FREECLK_EXISTS (1 << 30)
+#define DWC3_GUSB2PHYCFG_ULPIEXTVBUSDRVBIT(17)
 #define DWC3_GUSB2PHYCFG_SUSPHY(1 << 6)
 #define DWC3_GUSB2PHYCFG_ENBLSLPM  (1 << 8)
 #define DWC3_GUSB2PHYCFG_PHYIF(n)  ((n) << 3)
@@ -742,6 +743,8 @@ struct dwc3_scratchpad_array {
  * 1   - -3.5dB de-emphasis
  * 2   - No de-emphasis
  * 3   - Reserved
+ * @ulpi_ext_vbus_drv: Set to confiure the upli chip to drives CPEN pin
+ * VBUS with an external supply.
  * @index: index of _this_ controller
  * @list: to maintain the list of dwc3 controllers
  */
@@ -876,6 +879,7 @@ struct dwc3 {
 
unsignedtx_de_emphasis_quirk:1;
unsignedtx_de_emphasis:2;
+   unsignedulpi_ext_vbus_drv:1;
int index;
struct list_headlist;
 };
diff --git a/include/dwc3-uboot.h b/include/dwc3-uboot.h
index e08530ec4e..722a9352ce 100644
--- a/include/dwc3-uboot.h
+++ b/include/dwc3-uboot.h
@@ -39,6 +39,7 @@ struct dwc3_device {
unsigned dis_u2_freeclk_exists_quirk;
unsigned tx_de_emphasis_quirk;
unsigned tx_de_emphasis;
+   unsigned ulpi_ext_vbus_drv;
int index;
 };
 
-- 
2.17.1



[PATCH] usb: xhci: Workaround to fix the USB halted endpoint issues

2023-09-12 Thread Venkatesh Yadav Abbarapu
The xhci host controller driver trying to queue the URB's and it is
getting halted at the endpoint, thereby hitting the BUG_ON's.
Mostly these kind of random issues are seen on faulty boards.
Removing these BUG_ON's from the U-Boot xhci code, as in Linux kernel
xhci code BUG_ON/BUG's are removed entirely.
Please also note, that BUG_ON() is not recommended any more in the Linux
kernel.
Similar issue has been observed on TI AM437x board and they created a patch
in Linux kernel as below
https://patches.linaro.org/project/linux-usb/patch/1390250711-25840-1-git-send-email-ba...@ti.com/

Signed-off-by: Venkatesh Yadav Abbarapu 
---
 drivers/usb/host/xhci-mem.c  | 17 -
 drivers/usb/host/xhci-ring.c | 31 +++
 drivers/usb/host/xhci.c  |  6 --
 include/usb/xhci.h   |  2 +-
 4 files changed, 8 insertions(+), 48 deletions(-)

diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index 72b7530626..0efb4bd7ba 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -36,8 +36,6 @@
  */
 void xhci_flush_cache(uintptr_t addr, u32 len)
 {
-   BUG_ON((void *)addr == NULL || len == 0);
-
flush_dcache_range(addr & ~(CACHELINE_SIZE - 1),
ALIGN(addr + len, CACHELINE_SIZE));
 }
@@ -51,8 +49,6 @@ void xhci_flush_cache(uintptr_t addr, u32 len)
  */
 void xhci_inval_cache(uintptr_t addr, u32 len)
 {
-   BUG_ON((void *)addr == NULL || len == 0);
-
invalidate_dcache_range(addr & ~(CACHELINE_SIZE - 1),
ALIGN(addr + len, CACHELINE_SIZE));
 }
@@ -84,8 +80,6 @@ static void xhci_ring_free(struct xhci_ctrl *ctrl, struct 
xhci_ring *ring)
struct xhci_segment *seg;
struct xhci_segment *first_seg;
 
-   BUG_ON(!ring);
-
first_seg = ring->first_seg;
seg = first_seg->next;
while (seg != first_seg) {
@@ -210,7 +204,6 @@ static void *xhci_malloc(unsigned int size)
size_t cacheline_size = max(XHCI_ALIGNMENT, CACHELINE_SIZE);
 
ptr = memalign(cacheline_size, ALIGN(size, cacheline_size));
-   BUG_ON(!ptr);
memset(ptr, '\0', size);
 
xhci_flush_cache((uintptr_t)ptr, size);
@@ -291,7 +284,6 @@ static struct xhci_segment *xhci_segment_alloc(struct 
xhci_ctrl *ctrl)
struct xhci_segment *seg;
 
seg = malloc(sizeof(struct xhci_segment));
-   BUG_ON(!seg);
 
seg->trbs = xhci_malloc(SEGMENT_SIZE);
seg->dma = xhci_dma_map(ctrl, seg->trbs, SEGMENT_SIZE);
@@ -323,13 +315,11 @@ struct xhci_ring *xhci_ring_alloc(struct xhci_ctrl *ctrl, 
unsigned int num_segs,
struct xhci_segment *prev;
 
ring = malloc(sizeof(struct xhci_ring));
-   BUG_ON(!ring);
 
if (num_segs == 0)
return ring;
 
ring->first_seg = xhci_segment_alloc(ctrl);
-   BUG_ON(!ring->first_seg);
 
num_segs--;
 
@@ -338,7 +328,6 @@ struct xhci_ring *xhci_ring_alloc(struct xhci_ctrl *ctrl, 
unsigned int num_segs,
struct xhci_segment *next;
 
next = xhci_segment_alloc(ctrl);
-   BUG_ON(!next);
 
xhci_link_segments(ctrl, prev, next, link_trbs);
 
@@ -399,7 +388,6 @@ static int xhci_scratchpad_alloc(struct xhci_ctrl *ctrl)
break;
page_size = page_size >> 1;
}
-   BUG_ON(i == 16);
 
ctrl->page_size = 1 << (i + 12);
buf = memalign(ctrl->page_size, num_sp * ctrl->page_size);
@@ -444,9 +432,7 @@ static struct xhci_container_ctx
struct xhci_container_ctx *ctx;
 
ctx = malloc(sizeof(struct xhci_container_ctx));
-   BUG_ON(!ctx);
 
-   BUG_ON((type != XHCI_CTX_TYPE_DEVICE) && (type != XHCI_CTX_TYPE_INPUT));
ctx->type = type;
ctx->size = (MAX_EP_CTX_NUM + 1) *
CTX_SIZE(xhci_readl(>hccr->cr_hccparams));
@@ -638,7 +624,6 @@ int xhci_mem_init(struct xhci_ctrl *ctrl, struct xhci_hccr 
*hccr,
 struct xhci_input_control_ctx
*xhci_get_input_control_ctx(struct xhci_container_ctx *ctx)
 {
-   BUG_ON(ctx->type != XHCI_CTX_TYPE_INPUT);
return (struct xhci_input_control_ctx *)ctx->bytes;
 }
 
@@ -760,8 +745,6 @@ void xhci_setup_addressable_virt_dev(struct xhci_ctrl *ctrl,
 
virt_dev = ctrl->devs[slot_id];
 
-   BUG_ON(!virt_dev);
-
/* Extract the EP0 and Slot Ctrl */
ep0_ctx = xhci_get_ep_ctx(ctrl, virt_dev->in_ctx, 0);
slot_ctx = xhci_get_slot_ctx(ctrl, virt_dev->in_ctx);
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index c8260cbdf9..1bde0b9793 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -244,6 +244,7 @@ static int prepare_ring(struct xhci_ctrl *ctrl, struct 
xhci_ring *ep_ring,
return -EINVAL;
case EP_STATE_HALTED:
puts("WARN halted endpoint, queueing URB anyway.\n");
+   return -EPIPE;
case 

[PATCH] clk: versal: Fix the function versal_clock_ref

2023-09-12 Thread Venkatesh Yadav Abbarapu
For reference clocks, PM_CLK_GET_PARENT call is not allowed.
PM_CLK_GET_PARENT only allowed for MUX clocks. Rename the
versal_clock_ref() with versal_clock_get_ref_rate() for better
readability. Fix the versal_clock_get_ref_rate function by
passing the parent_id, and check whether the parent_id
belongs to ref_clk or pl_alt_ref_clk.
Also adding the function versal_clock_get_fixed_factor_rate()
if the clk_id belongs to the fixed factor clock.

Signed-off-by: Venkatesh Yadav Abbarapu 
---
 drivers/clk/clk_versal.c | 98 ++--
 1 file changed, 65 insertions(+), 33 deletions(-)

diff --git a/drivers/clk/clk_versal.c b/drivers/clk/clk_versal.c
index b3b123..2e004beca2 100644
--- a/drivers/clk/clk_versal.c
+++ b/drivers/clk/clk_versal.c
@@ -68,6 +68,13 @@
 #define CLOCK_NODE_TYPE_DIV4
 #define CLOCK_NODE_TYPE_GATE   6
 
+#define PM_CLK_REF_CLK (0x830c06aU)
+#define PM_CLK_PL_ALT_REF_CLK  (0x830c06bU)
+#define PM_CLK_MUXED_IRO   (0x830c06cU)
+#define PM_CLK_EMIO(0x830c071U)
+
+#define TOPOLOGY_TYPE_FIXEDFACTOR  0x3
+
 enum clk_type {
CLK_TYPE_OUTPUT,
CLK_TYPE_EXTERNAL,
@@ -365,48 +372,37 @@ static u32 versal_clock_set_div(u32 clk_id, u32 div)
return div;
 }
 
-static u64 versal_clock_ref(u32 clk_id)
+static u64 versal_clock_get_ref_rate(u32 clk_id)
 {
-   u32 ret_payload[PAYLOAD_ARG_CNT];
-   int ref;
-
-   xilinx_pm_request(PM_CLOCK_GETPARENT, clk_id, 0, 0, 0, ret_payload);
-   ref = ret_payload[0];
-   if (!(ref & 1))
+   if (clk_id == PM_CLK_REF_CLK || clk_id == PM_CLK_MUXED_IRO || clk_id == 
PM_CLK_EMIO)
return ref_clk;
-   if (ref & 2)
+   else if (clk_id == PM_CLK_PL_ALT_REF_CLK)
return pl_alt_ref_clk;
-   return 0;
+   else
+   return 0;
 }
 
-static u64 versal_clock_get_pll_rate(u32 clk_id)
+static int versal_clock_get_fixed_factor_rate(u32 clock_id, u32 parent_id)
 {
+   struct versal_pm_query_data qdata = {0};
u32 ret_payload[PAYLOAD_ARG_CNT];
-   u32 fbdiv;
-   u32 res;
-   u32 frac;
-   u64 freq;
-   u32 parent_rate, parent_id;
-   u32 id = clk_id & 0xFFF;
+   u32 mult, div;
+   u32 parent_rate;
+   int ret;
 
-   xilinx_pm_request(PM_CLOCK_GETSTATE, clk_id, 0, 0, 0, ret_payload);
-   res = ret_payload[1];
-   if (!res) {
-   printf("0%x PLL not enabled\n", clk_id);
-   return 0;
-   }
+   qdata.qid = PM_QID_CLOCK_GET_FIXEDFACTOR_PARAMS;
+   qdata.arg1 = clock_id;
 
-   parent_id = clock[clock[id].parent[0].id].clk_id;
-   parent_rate = versal_clock_ref(parent_id);
+   ret = versal_pm_query(qdata, ret_payload);
+   if (ret)
+   return ret;
 
-   xilinx_pm_request(PM_CLOCK_GETDIVIDER, clk_id, 0, 0, 0, ret_payload);
-   fbdiv = ret_payload[1];
-   xilinx_pm_request(PM_CLOCK_PLL_GETPARAM, clk_id, 2, 0, 0, ret_payload);
-   frac = ret_payload[1];
+   mult = ret_payload[1];
+   div = ret_payload[2];
 
-   freq = (fbdiv * parent_rate) >> (1 << frac);
+   parent_rate = versal_clock_get_ref_rate(parent_id);
+   return parent_rate * mult / div;
 
-   return freq;
 }
 
 static u32 versal_clock_mux(u32 clk_id)
@@ -437,6 +433,37 @@ static u32 versal_clock_get_parentid(u32 clk_id)
return clock[clock[id].parent[parent_id].id].clk_id;
 }
 
+static u64 versal_clock_get_pll_rate(u32 clk_id)
+{
+   u32 ret_payload[PAYLOAD_ARG_CNT];
+   u32 fbdiv;
+   u32 res;
+   u32 frac;
+   u64 freq;
+   u32 parent_rate, parent_id, parent_ref_clk_id;
+   u32 id = clk_id & 0xFFF;
+
+   xilinx_pm_request(PM_CLOCK_GETSTATE, clk_id, 0, 0, 0, ret_payload);
+   res = ret_payload[1];
+   if (!res) {
+   printf("0%x PLL not enabled\n", clk_id);
+   return 0;
+   }
+
+   parent_id = clock[clock[id].parent[0].id].clk_id;
+   parent_ref_clk_id = versal_clock_get_parentid(parent_id);
+   parent_rate = versal_clock_get_ref_rate(parent_ref_clk_id);
+
+   xilinx_pm_request(PM_CLOCK_GETDIVIDER, clk_id, 0, 0, 0, ret_payload);
+   fbdiv = ret_payload[1];
+   xilinx_pm_request(PM_CLOCK_PLL_GETPARAM, clk_id, 2, 0, 0, ret_payload);
+   frac = ret_payload[1];
+
+   freq = (fbdiv * parent_rate) >> (1 << frac);
+
+   return freq;
+}
+
 static u32 versal_clock_gate(u32 clk_id)
 {
u32 id = clk_id & 0xFFF;
@@ -479,14 +506,19 @@ static u64 versal_clock_calc(u32 clk_id)
u32 parent_id;
u64 clk_rate;
u32 div;
+   struct clock_topology topology;
 
if (versal_clock_pll(clk_id, _rate))
return clk_rate;
 
parent_id = versal_clock_get_parentid(clk_id);
if (((parent_id >> NODE_SUBCLASS_SHIFT) &
-NODE_CLASS_MASK) == NODE_SUBCLASS_CLOCK_REF)
-   return versal_clock_ref(clk_id);
+NODE_CLASS_MASK) == 

Re: [PATCH v3 03/16] soc: ti: k3-socinfo: Add entry for J784S4 SoC

2023-09-12 Thread Marcel Ziswiler
On Fri, 2023-09-08 at 16:35 +0530, Apurva Nandan wrote:
> Add support for J784S4 SoC Identification.
> 
> Signed-off-by: Hari Nagalla 
> Signed-off-by: Apurva Nandan 
> ---
>  arch/arm/mach-k3/include/mach/hardware.h | 1 +
>  drivers/soc/soc_ti_k3.c  | 3 +++
>  2 files changed, 4 insertions(+)
> 
> diff --git a/arch/arm/mach-k3/include/mach/hardware.h 
> b/arch/arm/mach-k3/include/mach/hardware.h
> index 03b18f6bad..bada87d0b2 100644
> --- a/arch/arm/mach-k3/include/mach/hardware.h
> +++ b/arch/arm/mach-k3/include/mach/hardware.h
> @@ -50,6 +50,7 @@
>  #define JTAG_ID_PARTNO_J721S2  0xbb75
>  #define JTAG_ID_PARTNO_AM62X   0xbb7e
>  #define JTAG_ID_PARTNO_AM62AX   0xbb8d
> +#define JTAG_ID_PARTNO_J784S4  0xbb80

Not sure whether it would be smarter to sort this based on the JTAG ID or the 
name of the define like you did.

>  #define K3_SOC_ID(id, ID) \
>  static inline bool soc_is_##id(void) \
> diff --git a/drivers/soc/soc_ti_k3.c b/drivers/soc/soc_ti_k3.c
> index b720131ae5..6f7fcf9e11 100644
> --- a/drivers/soc/soc_ti_k3.c
> +++ b/drivers/soc/soc_ti_k3.c
> @@ -45,6 +45,9 @@ static const char *get_family_string(u32 idreg)
> case JTAG_ID_PARTNO_AM62AX:
> family = "AM62AX";
> break;
> +   case JTAG_ID_PARTNO_J784S4:
> +   family = "J784S4";
> +   break;
> default:
> family = "Unknown Silicon";
> };


Re: [PATCH v3 02/16] arm: mach-k3: Add basic support for J784S4 SoC definition

2023-09-12 Thread Marcel Ziswiler
On Fri, 2023-09-08 at 16:35 +0530, Apurva Nandan wrote:
> Add j784s4 initialization files for initial SPL boot.
> 
> Signed-off-by: Hari Nagalla 
> [ add firewall configurations and change the R5 MCU scratchpad ]
> Signed-off-by: Manorit Chawdhry 
> Signed-off-by: Dasnavis Sabiya 
> Signed-off-by: Apurva Nandan 
> ---
>  arch/arm/mach-k3/Kconfig  |  16 +-
>  arch/arm/mach-k3/Makefile |   3 +
>  arch/arm/mach-k3/arm64-mmu.c  |  52 +++
>  arch/arm/mach-k3/include/mach/hardware.h  |   4 +
>  .../mach-k3/include/mach/j784s4_hardware.h    |  60 
>  arch/arm/mach-k3/include/mach/j784s4_spl.h    |  46 +++
>  arch/arm/mach-k3/include/mach/spl.h   |   6 +-
>  arch/arm/mach-k3/j784s4_fdt.c |  15 +
>  arch/arm/mach-k3/j784s4_init.c    | 332 ++
>  9 files changed, 526 insertions(+), 8 deletions(-)
>  create mode 100644 arch/arm/mach-k3/include/mach/j784s4_hardware.h
>  create mode 100644 arch/arm/mach-k3/include/mach/j784s4_spl.h
>  create mode 100644 arch/arm/mach-k3/j784s4_fdt.c
>  create mode 100644 arch/arm/mach-k3/j784s4_init.c
> 
> diff --git a/arch/arm/mach-k3/Kconfig b/arch/arm/mach-k3/Kconfig
> index 9168bf842d..0af2ec6ddb 100644
> --- a/arch/arm/mach-k3/Kconfig
> +++ b/arch/arm/mach-k3/Kconfig
> @@ -22,6 +22,9 @@ config SOC_K3_AM625
>  config SOC_K3_AM62A7
> bool "TI's K3 based AM62A7 SoC Family Support"
>  
> +config SOC_K3_J784S4
> +   bool "TI's K3 based J784S4 SoC Family Support"
> +
>  endchoice
>  
>  config SYS_SOC
> @@ -30,7 +33,7 @@ config SYS_SOC
>  config SYS_K3_NON_SECURE_MSRAM_SIZE
> hex
> default 0x8 if SOC_K3_AM654
> -   default 0x10 if SOC_K3_J721E || SOC_K3_J721S2
> +   default 0x10 if SOC_K3_J721E || SOC_K3_J721S2 || SOC_K3_J784S4
> default 0x1c if SOC_K3_AM642
> default 0x3c000 if SOC_K3_AM625 || SOC_K3_AM62A7
> help
> @@ -42,7 +45,7 @@ config SYS_K3_NON_SECURE_MSRAM_SIZE
>  config SYS_K3_MAX_DOWNLODABLE_IMAGE_SIZE
> hex
> default 0x58000 if SOC_K3_AM654
> -   default 0xc if SOC_K3_J721E || SOC_K3_J721S2
> +   default 0xc if SOC_K3_J721E || SOC_K3_J721S2 || SOC_K3_J784S4
> default 0x18 if SOC_K3_AM642
> default 0x38000 if SOC_K3_AM625 || SOC_K3_AM62A7
> help
> @@ -52,15 +55,14 @@ config SYS_K3_MAX_DOWNLODABLE_IMAGE_SIZE
>  config SYS_K3_MCU_SCRATCHPAD_BASE
> hex
> default 0x4028 if SOC_K3_AM654
> -   default 0x41cff9fc if SOC_K3_J721S2
> -   default 0x41cff9fc if SOC_K3_J721E
> +   default 0x41cff9fc if SOC_K3_J721E || SOC_K3_J721S2 || SOC_K3_J784S4
> help
>   Describes the base address of MCU Scratchpad RAM.
>  
>  config SYS_K3_MCU_SCRATCHPAD_SIZE
> hex
> default 0x200 if SOC_K3_AM654
> -   default 0x200 if SOC_K3_J721E || SOC_K3_J721S2
> +   default 0x200 if SOC_K3_J721E || SOC_K3_J721S2 || SOC_K3_J784S4
> help
>   Describes the size of MCU Scratchpad RAM.
>  
> @@ -68,7 +70,7 @@ config SYS_K3_BOOT_PARAM_TABLE_INDEX
> hex
> default 0x41c7fbfc if SOC_K3_AM654
> default 0x41cffbfc if SOC_K3_J721E
> -   default 0x41cfdbfc if SOC_K3_J721S2
> +   default 0x41cfdbfc if SOC_K3_J721S2 || SOC_K3_J784S4
> default 0x701bebfc if SOC_K3_AM642
> default 0x43c3f290 if SOC_K3_AM625
> default 0x43c3f290 if SOC_K3_AM62A7 && CPU_V7R
> @@ -172,7 +174,7 @@ config K3_ATF_LOAD_ADDR
>  
>  config K3_DM_FW
> bool "Separate DM firmware image"
> -   depends on SPL && CPU_V7R && (SOC_K3_J721E || SOC_K3_J721S2 || 
> SOC_K3_AM625 || SOC_K3_AM62A7) &&
> !CLK_TI_SCI && !TI_SCI_POWER_DOMAIN
> +   depends on SPL && CPU_V7R && (SOC_K3_J721E || SOC_K3_J721S2 || 
> SOC_K3_AM625 || SOC_K3_AM62A7 ||
> SOC_K3_J784S4) && !CLK_TI_SCI && !TI_SCI_POWER_DOMAIN
> default y
> help
>   Enabling this will indicate that the system has separate DM
> diff --git a/arch/arm/mach-k3/Makefile b/arch/arm/mach-k3/Makefile
> index fd77b8bbba..6fe36c265c 100644
> --- a/arch/arm/mach-k3/Makefile
> +++ b/arch/arm/mach-k3/Makefile
> @@ -7,6 +7,7 @@ obj-$(CONFIG_SOC_K3_J721E) += j721e/ j7200/
>  obj-$(CONFIG_SOC_K3_J721S2) += j721s2/
>  obj-$(CONFIG_SOC_K3_AM625) += am62x/
>  obj-$(CONFIG_SOC_K3_AM62A7) += am62ax/
> +obj-$(CONFIG_SOC_K3_J784S4) += j784s4/
>  obj-$(CONFIG_ARM64) += arm64-mmu.o
>  obj-$(CONFIG_CPU_V7R) += r5_mpu.o lowlevel_init.o
>  obj-$(CONFIG_ARM64) += cache.o
> @@ -16,6 +17,7 @@ obj-$(CONFIG_SOC_K3_AM654) += am654_fdt.o
>  obj-$(CONFIG_SOC_K3_J721E) += j721e_fdt.o
>  obj-$(CONFIG_SOC_K3_J721S2) += j721s2_fdt.o
>  obj-$(CONFIG_SOC_K3_AM625) += am625_fdt.o
> +obj-$(CONFIG_SOC_K3_J784S4) += j784s4_fdt.o
>  endif
>  ifeq ($(CONFIG_SPL_BUILD),y)
>  obj-$(CONFIG_SOC_K3_AM654) += am654_init.o
> @@ -24,6 +26,7 @@ obj-$(CONFIG_SOC_K3_J721S2) += j721s2_init.o
>  obj-$(CONFIG_SOC_K3_AM642) += am642_init.o
>  

Re: [PATCH v3 00/16]Introduce initial TI's J784S4 and AM69 support

2023-09-12 Thread Marcel Ziswiler
On Fri, 2023-09-08 at 16:35 +0530, Apurva Nandan wrote:
> Hello Everyone!
> 
> This series will introduce basic support (SD and UART) support for Texas
> Instruments J784S4 EVM.
> 
> The J784S4 SoC device tree patches are taken from kernel patch submissions
> and will be updated as they are accepted and merged to the kernel tree.
> All other patches are specific to SPL and u-boot and do not have
> dependency on other trees. Appreciate a review for acceptance to u-boot
> tree.
> 
> Here are some of the salient features of the J784S4 automotive grade 
> application processor:
> 
> The J784S4 SoC belongs to the K3 Multicore SoC architecture
> platform, providing advanced system integration in automotive,
> ADAS and industrial applications requiring AI at the network edge.
> This SoC extends the K3 Jacinto 7 family of SoCs with focus on
> raising performance and integration while providing interfaces,
> memory architecture and compute performance for multi-sensor, high
> concurrency applications.
> 
> Some highlights of this SoC are:
> * Up to 8 Cortex-A72s, four clusters of lockstep capable dual Cortex-R5F MCUs,
>   4 C7x floating point vector DSPs with Matrix Multiply Accelerator(MMA) for
>   deep learning and CNN.
> * 3D GPU: Automotive grade IMG BXS-4-64

BTW: Is it actually an IMG BXS-4-64 MC1 or MC4?

> * Vision Processing Accelerator (VPAC) with image signal processor and Depth
>   and Motion Processing Accelerator (DMPAC)
> * Three CSI2.0 4L RX plus two CSI2.0 4L TX, two DSI Tx, one eDP/DP and one
>   DPI interface.
> * Integrated gigabit ethernet switch, up to 8 ports (TDA4VH), two ports
>   support 10Gb USXGMII; Two 4 lane PCIe-GEN3 controllers, USB3.0 Dual-role
>   device subsystems, Up to 20 MCANs, among other peripherals.
> 
> See J784S4 Technical Reference Manual (SPRUJ52 - JUNE 2022)
> for further details: http://www.ti.com/lit/zip/spruj52
> 
> In addtion, the J784S4 EVM board is designed for TI J784S4 SoC. It 
> supports the following interfaces:
> * 32 GB DDR4 RAM
> * x2 Gigabit Ethernet interfaces capable of working in Switch and MAC mode
> * x1 Input Audio Jack, x1 Output Audio Jack
> * x1 USB2.0 Hub with two Type A host and x1 USB 3.1 Type-C Port
> * x2 4L PCIe connector
> * x1 UHS-1 capable micro-SD card slot
> * 512 Mbit OSPI flash, 1 Gbit Octal NAND flash, 512 Mbit QSPI flash,
>   UFS flash.
> * x6 UART through UART-USB bridge
> * XDS110 for onboard JTAG debug using USB
> * Temperature sensors, user push buttons and LEDs
> * 40-pin User Expansion Connector
> * x2 ENET Expansion Connector, x1 GESI expander, x2 Display connector
> * x1 15-pin CSI header
> * x6 MCAN instances
> 
> Schematics: https://www.ti.com/lit/zip/sprr458
> 
> bootlog: 
> https://paste.sr.ht/~hnagalla/f14840abc854519f912923662f1fdc8075d92107
> 
> Changes in v3:
> 1) Added AM69 SK support in the series
> 2) Switched from distroboot to bootstd support
> 3) Added remoteproc support for J784S4
> 4) Added documentation for both SoCs
> 5) Added binman support
> 6) Removed unnecessarry nodes from r5-evm.dts and evm-u-boot.dtsi
> 7) Added HS device support
> 8) Added env file for environement variables
> 9) Removed ti-serdes-mux bindings
> 10) Cleaned up all files and synced with latest
> 11) Addressed all previous review comments
> 
> Note: The base dts files have been sync from next-20230905 linux tag as per 
> review comment received
> on previous re-roll:
> https://lore.kernel.org/u-boot/20230321155227.GV8135@bill-the-cat/
> 
> Link to v2:
> https://lore.kernel.org/u-boot/20230321141028.24456-1-hnaga...@ti.com/
> 
> Changes in v2:
> - Refactored environement scripts to 'j784s4.env' and removed scripts not
>   needed for basic board bootup.
> - Imported the J7874S4 basic device tree files from v6.2 linux kernel.
> - Moved j784s4 clock definitions and clock data into one patch/commit.
> - coalesce board commits into one commit.
> 
> Apurva Nandan (9):
>   arm: dts: Introduce j784s4 dts from linux kernel
>   arm: mach-k3: Add basic support for J784S4 SoC definition
>   soc: ti: k3-socinfo: Add entry for J784S4 SoC
>   arm: mach-k3: j784s4: Add clk and power support
>   drivers: dma: Add support for J784S4 SoC
>   board: ti: j784s4: Add board support for J784S4 EVM
>   arm: dts: Introduce j784s4 u-boot dts files
>   configs: j784s4_evm: Add defconfig for j784s4 evm and am69 sk
>   doc: board: ti: k3: Add J784S4 EVM and AM69 SK documentation
> 
> Dasnavis Sabiya (5):
>   arm: dts: Introduce am69-sk dts from linux kernel
>   board: ti: j784s4: Add support for board detection by EEPROM read
>   board: ti: j784s4: Update env to use am69-sk dtb
>   arm: dts: Introduce am69-sk u-boot dts files
>   arm: dts: k3-j784s4-binman: Add support for AM69 SK
> 
> Hari Nagalla (2):
>   remoteproc: k3-r5: Extend support for R5F clusters on J784S4 SoCs
>   remoteproc: k3-dsp: Extend support for C71x DSPs on J784S4 SoCs
> 
>  arch/arm/dts/Makefile |    4 +
>  arch/arm/dts/k3-am69-r5-sk.dts    |  105 +
>  

[PATCH v1] CI: allow jobs to be run in merge requests

2023-09-12 Thread Andrejs Cainikovs
Out-of-tree users could run an out-of-tree CI with limited coverage,
however it is convenient to be able to run the upstream CI from time
to time. To enable that we would need to change job rules to be able
to run on any GitLab event. Excerpt from GitLab documentation:

> Jobs with no rules default to except: merge_requests

Signed-off-by: Andrejs Cainikovs 
---
 .gitlab-ci.yml | 46 +-
 1 file changed, 29 insertions(+), 17 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 1df13261c2d..a080bd32c64 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -21,6 +21,8 @@ stages:
 .buildman_and_testpy_template: _and_testpy_dfn
   stage: test.py
   retry: 2 # QEMU may be too slow, etc.
+  rules:
+- when: always
   before_script:
 # Clone uboot-test-hooks
 - git config --global --add safe.directory "${CI_PROJECT_DIR}"
@@ -93,8 +95,13 @@ stages:
   - "*.css"
 expire_in: 1 week
 
-build all 32bit ARM platforms:
+.world_build:
   stage: world build
+  rules:
+- when: always
+
+build all 32bit ARM platforms:
+  extends: .world_build
   script:
 - ret=0;
   git config --global --add safe.directory "${CI_PROJECT_DIR}";
@@ -106,7 +113,7 @@ build all 32bit ARM platforms:
   fi;
 
 build all 64bit ARM platforms:
-  stage: world build
+  extends: .world_build
   script:
 - virtualenv -p /usr/bin/python3 /tmp/venv
 - . /tmp/venv/bin/activate
@@ -120,7 +127,7 @@ build all 64bit ARM platforms:
   fi;
 
 build all PowerPC platforms:
-  stage: world build
+  extends: .world_build
   script:
 - ret=0;
   git config --global --add safe.directory "${CI_PROJECT_DIR}";
@@ -131,7 +138,7 @@ build all PowerPC platforms:
   fi;
 
 build all other platforms:
-  stage: world build
+  extends: .world_build
   script:
 - ret=0;
   git config --global --add safe.directory "${CI_PROJECT_DIR}";
@@ -141,8 +148,13 @@ build all other platforms:
 exit $ret;
   fi;
 
-check for new CONFIG symbols outside Kconfig:
+.testsuites:
   stage: testsuites
+  rules:
+- when: always
+
+check for new CONFIG symbols outside Kconfig:
+  extends: .testsuites
   script:
 - git config --global --add safe.directory "${CI_PROJECT_DIR}"
 # If grep succeeds and finds a match the test fails as we should
@@ -154,13 +166,13 @@ check for new CONFIG symbols outside Kconfig:
 # QA jobs for code analytics
 # static code analysis with cppcheck (we can add --enable=all later)
 cppcheck:
-  stage: testsuites
+  extends: .testsuites
   script:
 - cppcheck -j$(nproc) --force --quiet --inline-suppr .
 
 # search for TODO within source tree
 grep TODO/FIXME/HACK:
-  stage: testsuites
+  extends: .testsuites
   script:
 - grep -r TODO .
 - grep -r FIXME .
@@ -169,7 +181,7 @@ grep TODO/FIXME/HACK:
 
 # build documentation
 docs:
-  stage: testsuites
+  extends: .testsuites
   script:
 - virtualenv -p /usr/bin/python3 /tmp/venvhtml
 - . /tmp/venvhtml/bin/activate
@@ -179,30 +191,30 @@ docs:
 
 # some statistics about the code base
 sloccount:
-  stage: testsuites
+  extends: .testsuites
   script:
 - sloccount .
 
 # ensure all configs have MAINTAINERS entries
 Check for configs without MAINTAINERS entry:
-  stage: testsuites
+  extends: .testsuites
   script:
 - ./tools/buildman/buildman --maintainer-check || exit 0
 
 # Ensure host tools build
 Build tools-only:
-  stage: testsuites
+  extends: .testsuites
   script:
 - make tools-only_config tools-only -j$(nproc)
 
 # Ensure env tools build
 Build envtools:
-  stage: testsuites
+  extends: .testsuites
   script:
 - make tools-only_config envtools -j$(nproc)
 
 Run binman, buildman, dtoc, Kconfig and patman testsuites:
-  stage: testsuites
+  extends: .testsuites
   script:
 - git config --global user.name "GitLab CI Runner";
   git config --global user.email tr...@konsulko.com;
@@ -226,7 +238,7 @@ Run binman, buildman, dtoc, Kconfig and patman testsuites:
   make testconfig
 
 Run tests for Nokia RX-51 (aka N900):
-  stage: testsuites
+  extends: .testsuites
   script:
 - mkdir nokia_rx51_tmp;
   ln -s /opt/nokia/u-boot-gen-combined nokia_rx51_tmp/;
@@ -240,7 +252,7 @@ Run tests for Nokia RX-51 (aka N900):
 
 # Check for any pylint regressions
 Run pylint:
-  stage: testsuites
+  extends: .testsuites
   script:
 - git config --global --add safe.directory "${CI_PROJECT_DIR}"
 - pip install -r test/py/requirements.txt
@@ -260,7 +272,7 @@ Run pylint:
 
 # Check for pre-schema driver model tags
 Check for pre-schema tags:
-  stage: testsuites
+  extends: .testsuites
   script:
 - git config --global --add safe.directory "${CI_PROJECT_DIR}";
 # If grep succeeds and finds a match the test fails as we should
@@ -269,7 +281,7 @@ Check for pre-schema tags:
 
 # Check we can package the Python tools
 Check packing of Python tools:
-  stage: testsuites
+  extends: .testsuites
   script:
 - make pip
 
-- 
2.34.1



Re: [PATCH v2 7/7] arm: dts: k3-j721e: Sync with v6.5-rc1

2023-09-12 Thread Neha Malcom Francis

Hi Nishanth

On 11/09/23 16:53, Nishanth Menon wrote:

On 19:44-20230907, Neha Malcom Francis wrote:

Sync k3-j721e DTS with kernel.org v6.5-rc1.

Signed-off-by: Neha Malcom Francis 


[...]



This file has:
* tps659413 -> Should come in from upstream kernel please.


[...]

  

we have tps659412 defined here - should have come in from
upstream kernel.org
[...]



Regarding the PMIC nodes, these have not yet been upstreamed, effort is ongoing 
[1]. Will move these out from U-Boot once they have been merged.



[1] https://lore.kernel.org/all/20230810-tps6594-v6-0-2b2e2399e...@ti.com/

--
Thanking You
Neha Malcom Francis


[PATCH v2] spi: cadence_qspi: Select flash subnode at runtime

2023-09-12 Thread Udit Kumar
Currently spi driver gets flash parameter from first subnode.

Few boards have more than one flash with different parameters
and selection of flash is done by on board switch settings.
In such case, uboot needs to be recompiled with updated
device tree to align with board switch settings.

This patch allows to select flash node at runtime.

Boards those are supporting multiple flashes
needs to implement cadence_qspi_get_subnode function and return correct
flash node.

Cc: Apurva Nandan 
Signed-off-by: Udit Kumar 
Reviewed-by: Neha Malcom Francis 
---
One of such platform is J721S2 EVM
link https://www.ti.com/lit/pdf/spruj69
Fig 3.1, Page 18 has details of two flashes connected with one controller

Change log:
Changes in v2
- Corrected link in comment
- removed extra space
- Added Reviewed-by, after addressing v1 feedback
- link to v1
https://lore.kernel.org/all/20230907092143.4110817-1-u-kum...@ti.com/

 drivers/spi/cadence_qspi.c | 7 ++-
 drivers/spi/cadence_qspi.h | 1 +
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/spi/cadence_qspi.c b/drivers/spi/cadence_qspi.c
index cc3a54f295..eb7fbf83d0 100644
--- a/drivers/spi/cadence_qspi.c
+++ b/drivers/spi/cadence_qspi.c
@@ -40,6 +40,11 @@ __weak int cadence_qspi_versal_flash_reset(struct udevice 
*dev)
return 0;
 }
 
+__weak ofnode cadence_qspi_get_subnode(struct udevice *dev)
+{
+   return dev_read_first_subnode(dev);
+}
+
 static int cadence_spi_write_speed(struct udevice *bus, uint hz)
 {
struct cadence_spi_priv *priv = dev_get_priv(bus);
@@ -401,7 +406,7 @@ static int cadence_spi_of_to_plat(struct udevice *bus)
plat->is_dma = dev_read_bool(bus, "cdns,is-dma");
 
/* All other parameters are embedded in the child node */
-   subnode = dev_read_first_subnode(bus);
+   subnode = cadence_qspi_get_subnode(bus);
if (!ofnode_valid(subnode)) {
printf("Error: subnode with SPI flash config missing!\n");
return -ENODEV;
diff --git a/drivers/spi/cadence_qspi.h b/drivers/spi/cadence_qspi.h
index 1c59d1a9d9..12825f8911 100644
--- a/drivers/spi/cadence_qspi.h
+++ b/drivers/spi/cadence_qspi.h
@@ -304,6 +304,7 @@ int cadence_qspi_apb_dma_read(struct cadence_spi_priv *priv,
 int cadence_qspi_apb_wait_for_dma_cmplt(struct cadence_spi_priv *priv);
 int cadence_qspi_apb_exec_flash_cmd(void *reg_base, unsigned int reg);
 int cadence_qspi_versal_flash_reset(struct udevice *dev);
+ofnode cadence_qspi_get_subnode(struct udevice *dev);
 void cadence_qspi_apb_enable_linear_mode(bool enable);
 
 #endif /* __CADENCE_QSPI_H__ */
-- 
2.34.1



[PATCH 8/8] doc: rollback: anti-rollback verification

2023-09-12 Thread seanedmond
From: Sean Edmond 

Add documentation for anti-rollback verification, optional properties in
FIT image, and UCLASS_ROLLBACK device.

Signed-off-by: Sean Edmond 
---
 doc/develop/driver-model/index.rst |  1 +
 doc/develop/driver-model/rollback-info.rst | 42 +
 doc/usage/fit/signature.rst| 53 +++---
 doc/usage/fit/source_file_format.rst   | 21 -
 4 files changed, 108 insertions(+), 9 deletions(-)
 create mode 100644 doc/develop/driver-model/rollback-info.rst

diff --git a/doc/develop/driver-model/index.rst 
b/doc/develop/driver-model/index.rst
index 8e12bbd936..bb2d2e8a5d 100644
--- a/doc/develop/driver-model/index.rst
+++ b/doc/develop/driver-model/index.rst
@@ -25,6 +25,7 @@ subsystems
pci-info
pmic-framework
remoteproc-framework
+   rollback-info
serial-howto
soc-framework
spi-howto
diff --git a/doc/develop/driver-model/rollback-info.rst 
b/doc/develop/driver-model/rollback-info.rst
new file mode 100644
index 00..06ba4584a9
--- /dev/null
+++ b/doc/develop/driver-model/rollback-info.rst
@@ -0,0 +1,42 @@
+.. SPDX-License-Identifier: GPL-2.0+
+
+Rollback Driver Guide
+=
+
+Rollback protection is required when there is a need to retire
+previous versions of FIT images due to security flaws in them.
+See :doc:`../../usage/fit/signature` for details on rollback protection.
+
+The rollback driver is intended to provide tamper-evident storage using
+a UCLASS_ROLLBACK device.  It exposes the following APIs which are
+used in the FIT verification process (if FIT_ROLLBACK_CHECK is set):
+- rollback_idx_get()
+- rollback_idx_set()
+
+A TPM based rollback device has been provided as an example.  Users could
+create their own UCLASS_ROLLBACK device to access proprietary secure storage.
+
+TPM 2.0 based rollback devices
+
+
+A TPM-based rollback device has been provided as a reference.  It can be
+enabled with:
+- DM_ROLLBACK
+- ROLLBACK_TPM
+
+The tpm based rollback device should be added as a child node of the TPM in
+the u-boot device tree.  You should provide the property "rollback-nv-index"
+to set the TPM's NV index (if no "rollback-nv-index" is provided, an NV index
+of 0 is assumed).  For example:
+
+   tpm2 {
+   compatible = "sandbox,tpm2";
+
+   rollback@1 {
+   compatible = "tpm,rollback";
+   rollback-nv-index = <0x1001007>;
+   };
+   };
+
+Note, the ROLLBACK_TPM device does not set any policy.  Consumers of this
+driver should add a policy to make it more secure.
\ No newline at end of file
diff --git a/doc/usage/fit/signature.rst b/doc/usage/fit/signature.rst
index 0804bffd1e..30dd529c29 100644
--- a/doc/usage/fit/signature.rst
+++ b/doc/usage/fit/signature.rst
@@ -674,14 +674,53 @@ Sign the fitImage with the hardware key::
 
"model=PKCS%2315%20emulated;manufacturer=ZeitControl;serial=000x;token=OpenPGP%20card%20%28User%20PIN%20%28sig%29%29"
 \
 -K u-boot.dtb -N pkcs11 -r fitImage
 
+Roll-back Protection
+-
 
-Future Work

-
-- Roll-back protection using a TPM is done using the tpm command. This can
-  be scripted, but we might consider a default way of doing this, built into
-  bootm.
-
+Rollback protection is required when there is a need to retire
+previous versions of FIT images due to security flaws in them.
+
+This feature is realized by adding a rollback index as a property
+in the FIT image.  Every time a security flaw is discovered, the
+rollback index is incremented.  For example:
+
++-++
+| FIT version | Rollback index |
++=++
+| 1.0 | 0  |
++-++
+| 1.1 | 0  |
++-++
+| 2.0 | 0  |
++-++
+| Security issue found!|
++-++
+| 1.2 | 1  |
++-++
+| 2.1 | 1  |
++-++
+
+Each sub-image node inside /images node has an optional rollback rollback_index
+("rollback"). This version number is part of signed data and is incremented as
+security flaws are discovered and fixed. If no "rollback" property is present
+in the FIT image, a rollback index of 0 is assumed.
+
+U-Boot stores the last seen "rollback" for a given image type in platform
+specific tamper-evident storage (using a UCLASS_ROLLBACK device).
+See :doc:`../../develop/driver-model/rollback-info` for more information on
+rollback devices.
+
+As part of signature verification, U-Boot enforces rollback
+protection if enabled (with FIT_ROLLBACK_CHECK). The rollback index stored in 
secure
+storage is validated with "rollback" in the sub-image node. If the counter
+in the FIT image is lower than the counter in platform secure storage, image

[PATCH 5/8] dm: test: Add a test for rollback driver

2023-09-12 Thread seanedmond
From: Sean Edmond 

Adds a test for a sandbox and TPM backed rollback driver.

Allows for testing of anti-rollback version number get/set API using the
rollback driver.

Signed-off-by: Sean Edmond 
---
 arch/sandbox/dts/test.dts |  9 +
 configs/sandbox_defconfig |  3 ++
 test/dm/Makefile  |  1 +
 test/dm/rollback.c| 78 +++
 4 files changed, 91 insertions(+)
 create mode 100644 test/dm/rollback.c

diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index f351d5cb84..1226bad6a6 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -1263,6 +1263,10 @@
backlight = < 0 100>;
};
 
+   rollback@0 {
+   compatible = "sandbox,rollback";
+   };
+
scsi {
compatible = "sandbox,scsi";
sandbox,filepath = "scsi.img";
@@ -1376,6 +1380,11 @@
 
tpm2 {
compatible = "sandbox,tpm2";
+
+   rollback@1 {
+   compatible = "tpm,rollback";
+   rollback-nv-index = <0x1001007>;
+   };
};
 
tpm {
diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index 1cd1c2ed7c..f2bd10fbf0 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -346,3 +346,6 @@ CONFIG_UNIT_TEST=y
 CONFIG_UT_TIME=y
 CONFIG_UT_DM=y
 CONFIG_ARM_FFA_TRANSPORT=y
+CONFIG_DM_ROLLBACK=y
+CONFIG_ROLLBACK_SANDBOX=y
+CONFIG_ROLLBACK_TPM=y
diff --git a/test/dm/Makefile b/test/dm/Makefile
index 7ed00733c1..3875ec4f4b 100644
--- a/test/dm/Makefile
+++ b/test/dm/Makefile
@@ -104,6 +104,7 @@ obj-$(CONFIG_DM_RNG) += rng.o
 obj-$(CONFIG_DM_RTC) += rtc.o
 obj-$(CONFIG_SCMI_FIRMWARE) += scmi.o
 obj-$(CONFIG_SCSI) += scsi.o
+obj-$(CONFIG_DM_ROLLBACK) += security.o
 obj-$(CONFIG_DM_SERIAL) += serial.o
 obj-$(CONFIG_DM_SPI_FLASH) += sf.o
 obj-$(CONFIG_SIMPLE_BUS) += simple-bus.o
diff --git a/test/dm/rollback.c b/test/dm/rollback.c
new file mode 100644
index 00..a2984797f9
--- /dev/null
+++ b/test/dm/rollback.c
@@ -0,0 +1,78 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2023 Microsoft Corporation
+ * Written by Sean Edmond 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/*
+ * get_rollback() - Get a rollback driver of a given driver name
+ *
+ * @devp: Returns the rollback device
+ * @driver_name: Driver name to find
+ * Returns: 0 if OK, -ENODEV if not found
+ */
+static int get_rollback(struct udevice **devp, char *driver_name)
+{
+   struct udevice *dev;
+
+   uclass_foreach_dev_probe(UCLASS_ROLLBACK, dev) {
+   if (strcmp(dev->driver->name, driver_name) == 0) {
+   *devp = dev;
+   return 0;
+   }
+   }
+
+   return -ENODEV;
+}
+
+/* Basic test of rollback driver Anti rollback version number read/write */
+static int test_rollback_idx(struct unit_test_state *uts, char *driver_name)
+{
+   struct udevice *dev;
+   u64 rollback_idx;
+
+   /* get the rollback driver */
+   ut_assertok(get_rollback(, driver_name));
+
+   /* ensure initial value is 0 */
+   rollback_idx_get(dev, _idx);
+   ut_asserteq(0, rollback_idx);
+
+   /* write 1 and ensure it's read back */
+   rollback_idx_set(dev, 1);
+   rollback_idx_get(dev, _idx);
+   ut_asserteq(1, rollback_idx);
+
+   /* write all ones and ensure it's read back */
+   rollback_idx_set(dev, 0xULL);
+   rollback_idx_get(dev, _idx);
+   ut_asserteq(0xULL, rollback_idx);
+
+   return 0;
+}
+
+static int dm_test_rollback_sandbox(struct unit_test_state *uts)
+{
+   ut_assertok(test_rollback_idx(uts, "rollback_sandbox"));
+
+   return 0;
+}
+
+DM_TEST(dm_test_rollback_sandbox, UT_TESTF_SCAN_FDT);
+
+static int dm_test_rollback_tpm(struct unit_test_state *uts)
+{
+   ut_assertok(test_rollback_idx(uts, "rollback_tpm"));
+
+   return 0;
+}
+
+DM_TEST(dm_test_rollback_tpm, UT_TESTF_SCAN_FDT);
-- 
2.40.0



[PATCH 7/8] sandbox: tpm: Fix TPM2_CC_NV_DEFINE_SPACE command

2023-09-12 Thread seanedmond
From: Sean Edmond 

The TPM 2.0 command reference shows "auth" (type TPM2B_AUTH) before
"publicInfo" (type TPM2B_NV_PUBLIC).

The TPM v2 driver was updated to add this field.  The sandbox driver
needs to be updated to match the driver implementation.

Signed-off-by: Sean Edmond 
---
 drivers/tpm/tpm2_tis_sandbox.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/tpm/tpm2_tis_sandbox.c b/drivers/tpm/tpm2_tis_sandbox.c
index e4004cfcca..3e38d28637 100644
--- a/drivers/tpm/tpm2_tis_sandbox.c
+++ b/drivers/tpm/tpm2_tis_sandbox.c
@@ -758,8 +758,10 @@ static int sandbox_tpm2_xfer(struct udevice *dev, const u8 
*sendbuf,
break;
}
case TPM2_CC_NV_DEFINE_SPACE: {
-   int policy_size, index, seq;
+   int policy_size, auth_size, index, seq;
 
+   auth_size = get_unaligned_be16(sent);
+   sent += 2 + auth_size;
policy_size = get_unaligned_be16(sent + 12);
index = get_unaligned_be32(sent + 2);
sent += 14 + policy_size;
-- 
2.40.0



[PATCH 2/8] drivers: rollback: Add TPM2 implementation of rollback devices

2023-09-12 Thread seanedmond
From: Stephen Carlson 

This implementation of the rollback uclass driver allows existing TPM2
devices declared in the device tree to be referenced for storing the OS
anti-rollback counter, using the TPM2 non-volatile storage API.  The
rollback device must be a child of the TPM device.  For example:

tpm2 {
compatible = "sandbox,tpm2";

rollback@1 {
compatible = "tpm,rollback";
rollback-nv-index = <0x1001007>;
};
};

Signed-off-by: Stephen Carlson 
Signed-off-by: Sean Edmond 
---
 MAINTAINERS |   1 +
 drivers/rollback/Makefile   |   1 +
 drivers/rollback/rollback-tpm.c | 117 
 include/tpm-v2.h|  17 +
 lib/tpm-v2.c|  48 +
 5 files changed, 184 insertions(+)
 create mode 100644 drivers/rollback/rollback-tpm.c

diff --git a/MAINTAINERS b/MAINTAINERS
index de14724c27..e5ac889db4 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1446,6 +1446,7 @@ F:drivers/rollback/Kconfig
 F: drivers/rollback/Makefile
 F: drivers/rollback/rollback-sandbox.c
 F: drivers/rollback/rollback-uclass.c
+F: drivers/security/rollback-tpm.c
 
 SEMIHOSTING
 R: Sean Anderson 
diff --git a/drivers/rollback/Makefile b/drivers/rollback/Makefile
index 4e7fa46041..63c08863ca 100644
--- a/drivers/rollback/Makefile
+++ b/drivers/rollback/Makefile
@@ -4,3 +4,4 @@
 
 obj-$(CONFIG_DM_ROLLBACK) += rollback-uclass.o
 obj-$(CONFIG_ROLLBACK_SANDBOX) += rollback-sandbox.o
+obj-$(CONFIG_ROLLBACK_TPM) += rollback-tpm.o
\ No newline at end of file
diff --git a/drivers/rollback/rollback-tpm.c b/drivers/rollback/rollback-tpm.c
new file mode 100644
index 00..3bb6214042
--- /dev/null
+++ b/drivers/rollback/rollback-tpm.c
@@ -0,0 +1,117 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2021 Microsoft, Inc
+ * Written by Stephen Carlson 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct rollback_state {
+   u32 nv_index;
+   struct udevice *tpm_dev;
+};
+
+static int tpm_rollback_idx_get(struct udevice *dev, u64 *rollback_idx)
+{
+   struct rollback_state *priv = dev_get_priv(dev);
+   int ret;
+
+   if (!rollback_idx)
+   return -EINVAL;
+
+   ret = tpm2_nv_read_value(priv->tpm_dev, priv->nv_index, rollback_idx, 
sizeof(u64));
+   if (ret) {
+   log(UCLASS_ROLLBACK, LOGL_ERR,
+   "Unable to read rollback number from TPM (ret=%d)\n", ret);
+   return ret;
+   }
+
+   return ret;
+}
+
+static int tpm_rollback_idx_set(struct udevice *dev, u64 rollback_idx)
+{
+   int ret;
+   struct rollback_state *priv = dev_get_priv(dev);
+
+   ret = tpm2_nv_write_value(priv->tpm_dev, priv->nv_index, _idx, 
sizeof(u64));
+   if (ret) {
+   log(UCLASS_ROLLBACK, LOGL_ERR,
+   "Unable to write anti-rollback version to TPM (ret=%d)\n", 
ret);
+   return ret;
+   }
+
+   return 0;
+}
+
+static const struct rollback_ops tpm_rollback_ops = {
+   .rollback_idx_get   = tpm_rollback_idx_get,
+   .rollback_idx_set   = tpm_rollback_idx_set,
+};
+
+static int tpm_rollback_probe(struct udevice *dev)
+{
+   struct rollback_state *priv = dev_get_priv(dev);
+   int ret;
+
+   /* initialize the TPM rollback counter NV index
+* and initial to 0.  Note, this driver provides
+* a NULL policy.
+*/
+   ret = tpm_rollback_counter_init(priv->tpm_dev, priv->nv_index,
+   NULL, 0);
+   if (ret) {
+   log(UCLASS_ROLLBACK, LOGL_ERR,
+   "TPM rollback init failed (ret=%d)\n", ret);
+   return ret;
+   }
+
+   return 0;
+}
+
+static int tpm_rollback_remove(struct udevice *dev)
+{
+   struct rollback_state *priv = dev_get_priv(dev);
+
+   return tpm_close(priv->tpm_dev);
+}
+
+static int tpm_rollback_ofdata_to_platdata(struct udevice *dev)
+{
+   struct udevice *parent_dev;
+   struct rollback_state *priv = dev_get_priv(dev);
+
+   priv->nv_index = (u32)dev_read_u32_default(dev, "rollback-nv-index", 0);
+
+   parent_dev = dev_get_parent(dev);
+
+   if (parent_dev->driver->id == UCLASS_TPM) {
+   priv->tpm_dev = parent_dev;
+   } else {
+   log(UCLASS_ROLLBACK, LOGL_ERR,
+   "TPM rollback must be a child node of a TPM\n");
+   return -EINVAL;
+   }
+
+   return 0;
+}
+
+static const struct udevice_id tpm_rollback_ids[] = {
+   { .compatible = "tpm,rollback" },
+   { }
+};
+
+U_BOOT_DRIVER(rollback_tpm) = {
+   .name   = "rollback_tpm",
+   .id = UCLASS_ROLLBACK,
+   .priv_auto = sizeof(struct rollback_state),
+   .of_match = tpm_rollback_ids,
+   .of_to_plat = tpm_rollback_ofdata_to_platdata,
+   

[PATCH 1/8] drivers: rollback: Add rollback devices to driver model

2023-09-12 Thread seanedmond
From: Stephen Carlson 

Rollback devices currently implement operations to store an OS
anti-rollback monotonic counter. Existing devices such as the Trusted
Platform Module (TPM) already support this operation, but this uclass
provides abstraction for current and future devices that may support
different features.

- New Driver Model uclass UCLASS_ROLLBACK.
- New config CONFIG_DM_ROLLBACK to enable security device support.
- New driver rollback-sandbox matching "rollback,sandbox", enabled with
  new config CONFIG_ROLLBACK_SANDBOX.

Signed-off-by: Stephen Carlson 
Signed-off-by: Sean Edmond 
---
 MAINTAINERS |  9 
 drivers/Kconfig |  2 +
 drivers/Makefile|  1 +
 drivers/rollback/Kconfig| 25 +++
 drivers/rollback/Makefile   |  6 +++
 drivers/rollback/rollback-sandbox.c | 65 +
 drivers/rollback/rollback-uclass.c  | 30 +
 include/dm/uclass-id.h  |  1 +
 include/rollback.h  | 42 +++
 9 files changed, 181 insertions(+)
 create mode 100644 drivers/rollback/Kconfig
 create mode 100644 drivers/rollback/Makefile
 create mode 100644 drivers/rollback/rollback-sandbox.c
 create mode 100644 drivers/rollback/rollback-uclass.c
 create mode 100644 include/rollback.h

diff --git a/MAINTAINERS b/MAINTAINERS
index bf851cffd6..de14724c27 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1438,6 +1438,15 @@ F:   cmd/seama.c
 F: doc/usage/cmd/seama.rst
 F: test/cmd/seama.c
 
+ROLLBACK
+M: Stephen Carlson 
+M: Sean Edmond 
+S: Maintained
+F: drivers/rollback/Kconfig
+F: drivers/rollback/Makefile
+F: drivers/rollback/rollback-sandbox.c
+F: drivers/rollback/rollback-uclass.c
+
 SEMIHOSTING
 R: Sean Anderson 
 S: Orphaned
diff --git a/drivers/Kconfig b/drivers/Kconfig
index a25f6ae02f..faa7cbb72b 100644
--- a/drivers/Kconfig
+++ b/drivers/Kconfig
@@ -116,6 +116,8 @@ source "drivers/rtc/Kconfig"
 
 source "drivers/scsi/Kconfig"
 
+source "drivers/rollback/Kconfig"
+
 source "drivers/serial/Kconfig"
 
 source "drivers/smem/Kconfig"
diff --git a/drivers/Makefile b/drivers/Makefile
index efc2a4afb2..f6cfb48cb6 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -98,6 +98,7 @@ obj-$(CONFIG_PCH) += pch/
 obj-$(CONFIG_DM_REBOOT_MODE) += reboot-mode/
 obj-y += rtc/
 obj-y += scsi/
+obj-y += rollback/
 obj-y += sound/
 obj-y += spmi/
 obj-y += watchdog/
diff --git a/drivers/rollback/Kconfig b/drivers/rollback/Kconfig
new file mode 100644
index 00..31f5a3f56d
--- /dev/null
+++ b/drivers/rollback/Kconfig
@@ -0,0 +1,25 @@
+config DM_ROLLBACK
+   bool "Support rollback devices with driver model"
+   depends on DM
+   help
+ This option enables support for the rollback uclass which supports
+ devices intended to provide the anti-rollback feature during
+ boot. These devices might encapsulate existing features of TPM
+ or TEE devices, but can also be dedicated security processors
+ implemented in specific hardware.
+
+config ROLLBACK_SANDBOX
+   bool "Enable sandbox rollback driver"
+   depends on DM_ROLLBACK
+   help
+ This driver supports a simulated rollback device that uses volatile
+ memory to store secure data and begins uninitialized. This
+ implementation allows OS images with security requirements to be
+ loaded in the sandbox environment.
+
+config ROLLBACK_TPM
+   bool "Enable TPM rollback driver"
+   depends on TPM && TPM_V2 && DM_ROLLBACK
+   help
+ This driver supports a rollback device based on existing TPM
+ functionality.
diff --git a/drivers/rollback/Makefile b/drivers/rollback/Makefile
new file mode 100644
index 00..4e7fa46041
--- /dev/null
+++ b/drivers/rollback/Makefile
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# (C) Copyright 2021 Microsoft, Inc.
+
+obj-$(CONFIG_DM_ROLLBACK) += rollback-uclass.o
+obj-$(CONFIG_ROLLBACK_SANDBOX) += rollback-sandbox.o
diff --git a/drivers/rollback/rollback-sandbox.c 
b/drivers/rollback/rollback-sandbox.c
new file mode 100644
index 00..acbe6d2303
--- /dev/null
+++ b/drivers/rollback/rollback-sandbox.c
@@ -0,0 +1,65 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2021 Microsoft, Inc
+ * Written by Stephen Carlson 
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+static struct rollback_state {
+   u64 rollback_idx;
+};
+
+static int sb_rollback_idx_get(struct udevice *dev, u64 *rollback_idx)
+{
+   struct rollback_state *priv = dev_get_priv(dev);
+
+   if (!rollback_idx)
+   return -EINVAL;
+
+   *rollback_idx = priv->rollback_idx;
+   return 0;
+}
+
+static int sb_rollback_idx_set(struct udevice *dev, u64 rollback_idx)
+{
+   struct rollback_state *priv = dev_get_priv(dev);
+   u64 old_rollback_idx;
+
+   old_rollback_idx = priv->rollback_idx;
+  

[PATCH 6/8] tpm: Fix issues relating to NV Indexes

2023-09-12 Thread seanedmond
From: Sean Edmond 

The TPM 2.0 command reference states that "auth" (type TPM2B_AUTH)
should come before "publicInfo" (type TPM2B_NV_PUBLIC) in the
"TPM2_NV_DefineSpace" command.  Let's add an empty "auth" (size 0), so
that this can work with compliant TPMs.

Make sure that NV index used in tpm2_nv_define_space() can be used
directly in the NV read/write/lock APIs.

Signed-off-by: Sean Edmond 
---
 lib/tpm-v2.c | 20 ++--
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/lib/tpm-v2.c b/lib/tpm-v2.c
index c3c469eb35..d3ecf556d2 100644
--- a/lib/tpm-v2.c
+++ b/lib/tpm-v2.c
@@ -109,7 +109,7 @@ u32 tpm2_nv_define_space(struct udevice *dev, u32 
space_index,
const int platform_len = sizeof(u32);
const int session_hdr_len = 13;
const int message_len = 14;
-   uint offset = TPM2_HDR_LEN + platform_len + session_hdr_len +
+   uint offset = TPM2_HDR_LEN + platform_len + session_hdr_len + 2 +
message_len;
u8 command_v2[COMMAND_BUFFER_SIZE] = {
/* header 10 bytes */
@@ -127,6 +127,9 @@ u32 tpm2_nv_define_space(struct udevice *dev, u32 
space_index,
0,  /* session_attrs */
tpm_u16(0), /* auth_size */
 
+   /* auth value */
+   tpm_u16(0),
+
/* message 14 bytes + policy */
tpm_u16(message_len + nv_policy_size),  /* size */
tpm_u32(space_index),
@@ -206,7 +209,7 @@ u32 tpm2_nv_read_value(struct udevice *dev, u32 index, void 
*data, u32 count)
 
/* handles 8 bytes */
tpm_u32(TPM2_RH_PLATFORM),  /* Primary platform seed */
-   tpm_u32(HR_NV_INDEX + index),   /* Password authorisation */
+   tpm_u32(index), /* nvIndex */
 
/* AUTH_SESSION */
tpm_u32(9), /* Authorization size */
@@ -229,9 +232,14 @@ u32 tpm2_nv_read_value(struct udevice *dev, u32 index, 
void *data, u32 count)
ret = tpm_sendrecv_command(dev, command_v2, response, _len);
if (ret)
return log_msg_ret("read", ret);
+
+   const size_t tag_offset = 0;
+   const size_t size_offset = 2;
+   const size_t code_offset = 6;
+   const size_t data_offset = 16;
if (unpack_byte_string(response, response_len, "wdds",
-  0, , 2, , 6, ,
-  16, data, count))
+  tag_offset, , size_offset, , 
code_offset, ,
+  data_offset, data, count))
return TPM_LIB_ERROR;
 
return 0;
@@ -254,7 +262,7 @@ u32 tpm2_nv_write_value(struct udevice *dev, u32 index, 
const void *data,
 
/* handles 8 bytes */
tpm_u32(auth),  /* Primary platform seed */
-   tpm_u32(HR_NV_INDEX + index),   /* Password authorisation */
+   tpm_u32(index), /* nvIndex */
 
/* AUTH_SESSION */
tpm_u32(9), /* Authorization size */
@@ -643,7 +651,7 @@ u32 tpm2_write_lock(struct udevice *dev, u32 index)
 
/* handles 8 bytes */
tpm_u32(TPM2_RH_PLATFORM),  /* Primary platform seed */
-   tpm_u32(HR_NV_INDEX + index),   /* Password authorisation */
+   tpm_u32(index), /* nvIndex */
 
/* session header 9 bytes */
tpm_u32(9), /* Header size */
-- 
2.40.0



[PATCH 4/8] common: Add OS anti-rollback grace version

2023-09-12 Thread seanedmond
From: Stephen Carlson 

New config CONFIG_FIT_ROLLBACK_CHECK_GRACE to add a one unit grace version
to OS anti-rollback protection, allowing images with anti-rollback
counters exactly one less than the platform value to still be loaded. No
update to the platform anti-rollback counter will be performed in this
case.

Signed-off-by: Stephen Carlson 
Signed-off-by: Sean Edmond 
---
 boot/Kconfig | 10 ++
 boot/image-fit-sig.c |  7 ++-
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/boot/Kconfig b/boot/Kconfig
index 9180a1c8dc..95a717765c 100644
--- a/boot/Kconfig
+++ b/boot/Kconfig
@@ -112,6 +112,16 @@ config FIT_ROLLBACK_CHECK
  when a platform needs to retire previous versions of FIT images due to
  security flaws and prevent devices from being reverted to them.
 
+config FIT_ROLLBACK_CHECK_GRACE
+   bool "Enable FIT Anti rollback grace version"
+   depends on FIT_ARBP
+   default n
+   help
+ Enables a one unit grace version for FIT image anti-rollback 
protection,
+ where anti-rollback protection will still accept a FIT image with an
+ anti-rollback version one less than the current number, but will not
+ update the platform anti-rollback counter in that case.
+
 config FIT_VERBOSE
bool "Show verbose messages when FIT images fail"
depends on FIT
diff --git a/boot/image-fit-sig.c b/boot/image-fit-sig.c
index 91eaf4baa8..5689a316b6 100644
--- a/boot/image-fit-sig.c
+++ b/boot/image-fit-sig.c
@@ -70,6 +70,7 @@ static int fit_image_verify_rollback(const void *fit, int 
image_noffset)
 #if !defined(USE_HOSTCC)
u64 image_rollback;
u64 plat_rollback = 0ULL;
+   u64 target_rollback;
struct udevice *dev;
int ret;
 
@@ -90,7 +91,11 @@ static int fit_image_verify_rollback(const void *fit, int 
image_noffset)
if (ret)
return -EIO;
 
-   if (image_rollback < plat_rollback) {
+   target_rollback = plat_rollback;
+   /* Calculate target anti-rollback version, including grace version if 
enabled */
+   if (CONFIG_IS_ENABLED(FIT_ROLLBACK_CHECK_GRACE) && plat_rollback > 0ULL)
+   target_rollback = plat_rollback - 1ULL;
+   if (image_rollback < target_rollback) {
return -EPERM;
} else if (image_rollback > plat_rollback) {
ret = rollback_idx_set(dev, image_rollback);
-- 
2.40.0



[PATCH 3/8] common: Add OS anti-rollback validation using rollback devices

2023-09-12 Thread seanedmond
From: Stephen Carlson 

New config CONFIG_ROLLBACK_CHECK to enable enforcement of OS anti-rollback
counter during image loading.

Images with an anti-rollback counter value "rollback" declared in the FDT
will be compared against the current device anti-rollback counter value,
and older images will not pass signature validation. If the image is
newer, the device anti-rollback counter value will be updated.

Signed-off-by: Stephen Carlson 
Signed-off-by: Sean Edmond 
---
 boot/Kconfig |  9 +
 boot/image-fit-sig.c | 92 
 boot/image-fit.c | 31 +++
 include/image.h  |  6 ++-
 4 files changed, 137 insertions(+), 1 deletion(-)

diff --git a/boot/Kconfig b/boot/Kconfig
index e8fb03b801..9180a1c8dc 100644
--- a/boot/Kconfig
+++ b/boot/Kconfig
@@ -103,6 +103,15 @@ config FIT_CIPHER
  Enable the feature of data ciphering/unciphering in the tool mkimage
  and in the u-boot support of the FIT image.
 
+config FIT_ROLLBACK_CHECK
+   bool "Enable Anti rollback version check for FIT images"
+   depends on FIT_SIGNATURE
+   default n
+   help
+ Enables FIT image anti-rollback protection. This feature is required
+ when a platform needs to retire previous versions of FIT images due to
+ security flaws and prevent devices from being reverted to them.
+
 config FIT_VERBOSE
bool "Show verbose messages when FIT images fail"
depends on FIT
diff --git a/boot/image-fit-sig.c b/boot/image-fit-sig.c
index 12369896fe..91eaf4baa8 100644
--- a/boot/image-fit-sig.c
+++ b/boot/image-fit-sig.c
@@ -11,6 +11,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 DECLARE_GLOBAL_DATA_PTR;
 #endif /* !USE_HOSTCC*/
 #include 
@@ -63,6 +65,44 @@ struct image_region *fit_region_make_list(const void *fit,
return region;
 }
 
+static int fit_image_verify_rollback(const void *fit, int image_noffset)
+{
+#if !defined(USE_HOSTCC)
+   u64 image_rollback;
+   u64 plat_rollback = 0ULL;
+   struct udevice *dev;
+   int ret;
+
+   ret = fit_image_get_rollback(fit, image_noffset, _rollback);
+
+   /* If the FIT doesn't contain the rollback property, assume an
+* anti-rollback version number of 0.  This ensures failure
+* if the platform anti-rollback version number is non-zero
+*/
+   if (ret)
+   image_rollback = 0;
+
+   ret = uclass_first_device_err(UCLASS_ROLLBACK, );
+   if (ret)
+   return ret;
+
+   ret = rollback_idx_get(dev, _rollback);
+   if (ret)
+   return -EIO;
+
+   if (image_rollback < plat_rollback) {
+   return -EPERM;
+   } else if (image_rollback > plat_rollback) {
+   ret = rollback_idx_set(dev, image_rollback);
+   printf(" Updating OS anti-rollback to %llu from %llu\n",
+  image_rollback, plat_rollback);
+   return ret;
+   }
+#endif
+
+   return 0;
+}
+
 static int fit_image_setup_verify(struct image_sign_info *info,
  const void *fit, int noffset,
  const void *key_blob, int required_keynode,
@@ -175,6 +215,16 @@ static int fit_image_verify_sig(const void *fit, int 
image_noffset,
goto error;
}
 
+   if (!tools_build()) {
+   if (FIT_IMAGE_ENABLE_ROLLBACK_CHECK && verified) {
+   ret = fit_image_verify_rollback(fit, image_noffset);
+   if (ret) {
+   err_msg = "Anti-rollback verification failed";
+   goto error;
+   }
+   }
+   }
+
return verified ? 0 : -EPERM;
 
 error:
@@ -385,6 +435,38 @@ static int fit_config_check_sig(const void *fit, int 
noffset, int conf_noffset,
return 0;
 }
 
+static int fit_config_verify_rollback(const void *fit, int conf_noffset,
+ int sig_offset)
+{
+   static const char default_list[] = FIT_KERNEL_PROP "\0"
+   FIT_FDT_PROP;
+   int ret, len;
+   const char *prop, *iname, *end;
+   int image_noffset;
+
+   /* If there is "sign-images" property, use that */
+   prop = fdt_getprop(fit, sig_offset, "sign-images", );
+   if (!prop) {
+   prop = default_list;
+   len = sizeof(default_list);
+   }
+
+   /* Locate the images */
+   end = prop + len;
+   for (iname = prop; iname < end; iname += strlen(iname) + 1) {
+   image_noffset = fit_conf_get_prop_node(fit, conf_noffset,
+  iname, IH_PHASE_NONE);
+   if (image_noffset < 0)
+   return -ENOENT;
+
+   ret = fit_image_verify_rollback(fit, image_noffset);
+   if (ret)
+   return ret;
+   }
+
+   return 

[PATCH 0/5] Add anti-rollback validation feature

2023-09-12 Thread seanedmond
From: Sean Edmond 

Adds Add anti-rollback version protection. Images with an anti-rollback counter
value "rollback" declared in the kernel FDT will be compared against the 
current device 
anti-rollback counter value, and older images will not pass signature 
validation. If the image is newer, the device anti-rollback counter value will
be updated.

The "rollback" value is stored/retrieved using the newly added security driver.
A "TPM backed" and "sandbox backed" security driver have been provided as 
examples.

Adds new configs:
- CONFIG_DM_ROLLBACK : enable security device support
- CONFIG_ROLLBACK_SANDBOX : enables "rollback-sandbox" driver
- CONFIG_ROLLBACK_TPM : Enables "rollback-tpm" driver
- CONFIG_FIT_ROLLBACK_CHECK : enable enforcement of OS anti-rollback counter 
during image loading
- CONFIG_FIT_ROLLBACK_CHECK_GRACE : adds a one unit grace version to OS 
anti-rollback protection

changes in v2:
- arbvn -> rollback_idx
- rollback-tpm is a child of TPM device
- tpm_rollback_counter_init() tries to read NV index, defines and writes 0 if 
it fails
- tpm_rollback_counter_init() moved to tpm-v2.c
- Use tpm_auto_start()
- No error checking in rollback_idx_get()/rollback_idx_set() (intelligence is 
in fit_image_verify_rollback())
- assume "rollback" of 0 if FIT property not found
- "grace period" -> "grace version"
- drop "dm_" prefix in header
- Fix for tpm2_nv_define_space() (add "auth" parameter)
- Make NV index consistent across APIs (define/read/write/lock).  IS THIS 
CORRECT?!
- Add documentation

Sean Edmond (1):
  dm: test: Add a test for security driver

Stephen Carlson (4):
  drivers: security: Add security devices to driver model
  drivers: security: Add TPM2 implementation of security devices
  common: Add OS anti-rollback validation using security devices
  common: Add OS anti-rollback grace period

 MAINTAINERS |   9 ++
 arch/sandbox/dts/test.dts   |   8 ++
 boot/Kconfig|  19 +++
 boot/image-fit-sig.c|  94 +++
 boot/image-fit.c|  23 
 configs/sandbox_defconfig   |   3 +
 drivers/Kconfig |   2 +
 drivers/Makefile|   1 +
 drivers/security/Kconfig|  25 
 drivers/security/Makefile   |   7 ++
 drivers/security/sandbox_security.c |  65 +++
 drivers/security/security-tpm.c | 173 
 drivers/security/security-uclass.c  |  30 +
 include/dm-security.h   |  44 +++
 include/dm/uclass-id.h  |   1 +
 include/image.h |   4 +
 include/tpm-v2.h|   1 +
 test/dm/Makefile|   1 +
 test/dm/security.c  |  78 +
 19 files changed, 588 insertions(+)
 create mode 100644 drivers/security/Kconfig
 create mode 100644 drivers/security/Makefile
 create mode 100644 drivers/security/sandbox_security.c
 create mode 100644 drivers/security/security-tpm.c
 create mode 100644 drivers/security/security-uclass.c
 create mode 100644 include/dm-security.h
 create mode 100644 test/dm/security.c

-- 
2.40.0



Re: [RESEND PATCH] spi: cadence_qspi: Select flash subnode at runtime

2023-09-12 Thread Neha Malcom Francis

Hi Udit

On 07/09/23 14:51, Udit Kumar wrote:

Currently spi driver gets flash parameter from first subnode.

Few boards have more than one flash with different parameters
and selection of flash is done by on board switch settings.
In such case, uboot needs to be recompiled with updated
device tree to align with board switch settings.

This patch allows to select flash node at runtime.

Boards those are supporting multiple flashes
needs to implement cadence_qspi_get_subnode function and return correct
flash node.

Cc: Apurva Nandan 
Signed-off-by: Udit Kumar 
---
One of such platform is J721S2 EVM
link https://www.ti.com/lit/pdf/spruj67


I think this link is wrong, may be you mean
https://www.ti.com/lit/pdf/spruj69


Fig 3.1, Page 18 has details of two flashes connected with one controller.

  drivers/spi/cadence_qspi.c | 7 ++-
  drivers/spi/cadence_qspi.h | 1 +
  2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/spi/cadence_qspi.c b/drivers/spi/cadence_qspi.c
index cc3a54f295..7a02ceed10 100644
--- a/drivers/spi/cadence_qspi.c
+++ b/drivers/spi/cadence_qspi.c
@@ -40,6 +40,11 @@ __weak int cadence_qspi_versal_flash_reset(struct udevice 
*dev)
return 0;
  }
  
+__weak ofnode  cadence_qspi_get_subnode(struct udevice *dev)


Extra space after ofnode.


+{
+   return dev_read_first_subnode(dev);
+}
+
  static int cadence_spi_write_speed(struct udevice *bus, uint hz)
  {
struct cadence_spi_priv *priv = dev_get_priv(bus);
@@ -401,7 +406,7 @@ static int cadence_spi_of_to_plat(struct udevice *bus)
plat->is_dma = dev_read_bool(bus, "cdns,is-dma");
  
  	/* All other parameters are embedded in the child node */

-   subnode = dev_read_first_subnode(bus);
+   subnode = cadence_qspi_get_subnode(bus);
if (!ofnode_valid(subnode)) {
printf("Error: subnode with SPI flash config missing!\n");
return -ENODEV;
diff --git a/drivers/spi/cadence_qspi.h b/drivers/spi/cadence_qspi.h
index 1c59d1a9d9..12825f8911 100644
--- a/drivers/spi/cadence_qspi.h
+++ b/drivers/spi/cadence_qspi.h
@@ -304,6 +304,7 @@ int cadence_qspi_apb_dma_read(struct cadence_spi_priv *priv,
  int cadence_qspi_apb_wait_for_dma_cmplt(struct cadence_spi_priv *priv);
  int cadence_qspi_apb_exec_flash_cmd(void *reg_base, unsigned int reg);
  int cadence_qspi_versal_flash_reset(struct udevice *dev);
+ofnode cadence_qspi_get_subnode(struct udevice *dev);
  void cadence_qspi_apb_enable_linear_mode(bool enable);
  
  #endif /* __CADENCE_QSPI_H__ */


But otherwise
Reviewed-by: Neha Malcom Francis 

--
Thanking You
Neha Malcom Francis


Re: [RFC PATCH 0/2] RFC version for ATF and OP-TEE Firewalling

2023-09-12 Thread Manorit Chawdhry
Hi Kamlesh,

On 14:49-20230912, Kamlesh Gurudasani wrote:
> Manorit Chawdhry  writes:
> 
> > This is a start to firewall ATF and OP-TEE memory regions using the
> > firewalls present in K3 SoCs. Please give reviews as to what can be
> > better in the implementation.
> >
> > Signed-off-by: Manorit Chawdhry 
> Hi Manorit, thanks for the patches.
> 
> I hope this solution is easily scalable to sitara devices as well.
> Mainly considering the difference in type of firewalls.

I am trying to keep both types of devices in mind and will change the
implementation if required to incorporate both of them. I don't see any
problems as such in the current implementation w.r.t Sitara devices
also, will see if any occurs and will update you. Thanks.

Regards,
Manorit

> 
> Regards,
> Kamlesh


Re: [RFC PATCH 0/2] RFC version for ATF and OP-TEE Firewalling

2023-09-12 Thread Kamlesh Gurudasani
Manorit Chawdhry  writes:

> This is a start to firewall ATF and OP-TEE memory regions using the
> firewalls present in K3 SoCs. Please give reviews as to what can be
> better in the implementation.
>
> Signed-off-by: Manorit Chawdhry 
Hi Manorit, thanks for the patches.

I hope this solution is easily scalable to sitara devices as well.
Mainly considering the difference in type of firewalls.

Regards,
Kamlesh


Re: [PATCH RFC 2/2] configs: visionfive2: Enable MISC_INIT_R

2023-09-12 Thread Milan P . Stanić
On Mon, 2023-09-11 at 18:32, Jami Kettunen wrote:
> From: Jami Kettunen 
> 
> Used to select mainline kernel fdtfile based on board revision.
> 
> Signed-off-by: Jami Kettunen 

Tested-by: Milan P. Stanić 

> ---
>  configs/starfive_visionfive2_defconfig | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/configs/starfive_visionfive2_defconfig 
> b/configs/starfive_visionfive2_defconfig
> index e9b63e5b84..33f9ec8ad6 100644
> --- a/configs/starfive_visionfive2_defconfig
> +++ b/configs/starfive_visionfive2_defconfig
> @@ -125,3 +125,4 @@ CONFIG_USB=y
>  CONFIG_USB_XHCI_HCD=y
>  CONFIG_USB_XHCI_PCI=y
>  CONFIG_USB_KEYBOARD=y
> +CONFIG_MISC_INIT_R=y


Re: [PATCH RFC 1/2] board: visionfive2: Select fdtfile based on revision

2023-09-12 Thread Milan P . Stanić
On Mon, 2023-09-11 at 18:32, Jami Kettunen wrote:
> From: Jami Kettunen 
> 
> Linux mainline kernel device tree files[1] are named:
> - jh7110-starfive-visionfive-2-v1.2a
> - jh7110-starfive-visionfive-2-v1.3b
> 
> which should be selected accordingly by U-Boot to have a proper extlinux
> experience with fdtdir set by the distribution.
> 
> [1] https://github.com/torvalds/linux/tree/master/arch/riscv/boot/dts/starfive
> 
> Signed-off-by: Jami Kettunen 

Tested-by: Milan P. Stanić 

> ---
>  .../visionfive2/starfive_visionfive2.c| 25 +++
>  1 file changed, 25 insertions(+)
> 
> diff --git a/board/starfive/visionfive2/starfive_visionfive2.c 
> b/board/starfive/visionfive2/starfive_visionfive2.c
> index d609262b67..9244d4654b 100644
> --- a/board/starfive/visionfive2/starfive_visionfive2.c
> +++ b/board/starfive/visionfive2/starfive_visionfive2.c
> @@ -10,6 +10,8 @@
>  #include 
>  #include 
>  #include 
> +#include 
> +#include 
>  
>  #define JH7110_L2_PREFETCHER_BASE_ADDR   0x203
>  #define JH7110_L2_PREFETCHER_HART_OFFSET 0x2000
> @@ -41,6 +43,29 @@ int board_init(void)
>   return 0;
>  }
>  
> +int misc_init_r(void)
> +{
> + u8 rev;
> + const char *linux_dtb_file;
> +
> + rev = get_pcb_revision_from_eeprom();
> + switch (rev) {
> + case 'a':
> + case 'A':
> + linux_dtb_file = 
> "starfive/jh7110-starfive-visionfive-2-v1.2a.dtb";
> + break;
> +
> + case 'b':
> + case 'B':
> + default:
> + linux_dtb_file = 
> "starfive/jh7110-starfive-visionfive-2-v1.3b.dtb";
> + break;
> + };
> +
> + env_set("fdtfile", linux_dtb_file);
> + return 0;
> +}
> +
>  void *board_fdt_blob_setup(int *err)
>  {
>   *err = 0;


Re: [PATCHv8 01/15] net/lwip: add doc/develop/net_lwip.rst

2023-09-12 Thread Ilias Apalodimas
On Fri, Sep 08, 2023 at 07:53:06PM +0600, Maxim Uvarov wrote:
> Add initial documentation of lwIP network IP stack integration
> to the U-Boot (net_lwip.rst).
> 
> Signed-off-by: Maxim Uvarov 
> Reviewed-by: Simon Glass 
> ---
>  doc/develop/index.rst|  1 +
>  doc/develop/net_lwip.rst | 75 
>  2 files changed, 76 insertions(+)
>  create mode 100644 doc/develop/net_lwip.rst
> 
> diff --git a/doc/develop/index.rst b/doc/develop/index.rst
> index 5b230d0321..4764990f25 100644
> --- a/doc/develop/index.rst
> +++ b/doc/develop/index.rst
> @@ -48,6 +48,7 @@ Implementation
> spl
> falcon
> uefi/index
> +   net_lwip
> vbe
> version
>  
> diff --git a/doc/develop/net_lwip.rst b/doc/develop/net_lwip.rst
> new file mode 100644
> index 00..a77ab60d0f
> --- /dev/null
> +++ b/doc/develop/net_lwip.rst
> @@ -0,0 +1,75 @@
> +.. SPDX-License-Identifier: GPL-2.0+
> +
> +lwIP IP stack integration for U-Boot
> +
> +
> +Intro
> +-
> +
> +lwIP is a library implementing network protocols, which is commonly used
> +on embedded devices.
> +
> +https://savannah.nongnu.org/projects/lwip/
> +lwIP  license:
> +lwIP is licensed under a BSD-style license: 
> http://lwip.wikia.com/wiki/License.
> +
> +Main features include:
> +
> +* Protocols: IP, IPv6, ICMP, ND, MLD, UDP, TCP, IGMP, ARP, PPPoS, PPPoE
> +
> +* DHCP client, DNS client (incl. mDNS hostname resolver),
> +  AutoIP/APIPA (Zeroconf), SNMP agent (v1, v2c, v3, private MIB support
> +  & MIB compiler)
> +
> +* APIs: specialized APIs for enhanced performance, optional Berkeley-alike
> +  socket API
> +
> +* Extended features: IP forwarding over multiple network interfaces, TCP
> +  congestion control, RTT estimation and fast recovery/fast retransmit
> +
> +* Addon applications: HTTP(S) server, SNTP client, SMTP(S) client, ping,
> +  NetBIOS nameserver, mDNS responder, MQTT client, TFTP server
> +
> +U-Boot implementation details
> +-
> +
> +1. In general we can build lwIP as a library and link it against U-Boot or
> +   compile it in the U-Boot tree in the same way as other U-Boot files. There
> +   are few reasons why second variant was selected: lwIP is very customizable
> +   with defines for features, memory size, types of allocation, some internal
> +   types and platform specific code. It turned out easier to enable/disable
> +   debug which is also done with defines, and is needed periodically.
> +
> +2. lwIP has 2 APIs - raw mode and sequential (as lwIP names it, or socket API
> +   as we name it in Linux). For now only raw API is supported.
> +
> +In raw IP mode a callback function for RX path is registered and will be 
> called
> +when packet is passed to the IP stack and is ready for the application.
> +
> +One example is the unmodified working ping example from lwip sources which
> +registered the callback:
> +
> +.. code-block:: c
> +
> +ping_pcb = raw_new(IP_PROTO_ICMP);
> +raw_recv(ping_pcb, ping_recv, NULL); <- ping_recv is app callback.
> +raw_bind(ping_pcb, IP_ADDR_ANY)
> +
> +3.  Input and output
> +
> +RX packet path is injected to U-Boot eth_rx() polling loop and TX patch is in
> +eth_send() accordingly. That way we can leave the driver code unmodified and
> +consume packets once they are ready. So we do not touch any drivers code and
> +just eat packets when they are ready.
> +
> +U-Boot lwIP Applications
> +
> +
> +.. kernel-doc:: include/net/lwip.h
> +   :internal:
> +
> +lwIP API to control polling loop
> +
> +
> +.. kernel-doc:: include/net/ulwip.h
> +   :internal:
> -- 
> 2.30.2
> 
Reviewed-by: Ilias Apalodimas 



Re: [PATCH 1/2] arm: dts: k3-pinctrl: Sync with kernel v6.6-rc1

2023-09-12 Thread Dhruva Gole
On Sep 11, 2023 at 09:02:55 -0500, Nishanth Menon wrote:
> Sync pinctrl header with v6.6-rc1
> 
> Signed-off-by: Nishanth Menon 
> ---
>  arch/arm/dts/k3-pinctrl.h | 12 
>  1 file changed, 12 insertions(+)
> 
> diff --git a/arch/arm/dts/k3-pinctrl.h b/arch/arm/dts/k3-pinctrl.h
> index c97548a3f42d..2a4e0e084d69 100644
> --- a/arch/arm/dts/k3-pinctrl.h
> +++ b/arch/arm/dts/k3-pinctrl.h
> @@ -11,6 +11,7 @@
>  #define PULLUDEN_SHIFT   (16)
>  #define PULLTYPESEL_SHIFT(17)
>  #define RXACTIVE_SHIFT   (18)
> +#define DEBOUNCE_SHIFT   (11)
>  
>  #define PULL_DISABLE (1 << PULLUDEN_SHIFT)
>  #define PULL_ENABLE  (0 << PULLUDEN_SHIFT)
> @@ -29,9 +30,20 @@
>  #define PIN_INPUT_PULLUP (INPUT_EN | PULL_UP)
>  #define PIN_INPUT_PULLDOWN   (INPUT_EN | PULL_DOWN)
>  
> +#define PIN_DEBOUNCE_DISABLE (0 << DEBOUNCE_SHIFT)
> +#define PIN_DEBOUNCE_CONF1   (1 << DEBOUNCE_SHIFT)
> +#define PIN_DEBOUNCE_CONF2   (2 << DEBOUNCE_SHIFT)
> +#define PIN_DEBOUNCE_CONF3   (3 << DEBOUNCE_SHIFT)
> +#define PIN_DEBOUNCE_CONF4   (4 << DEBOUNCE_SHIFT)
> +#define PIN_DEBOUNCE_CONF5   (5 << DEBOUNCE_SHIFT)
> +#define PIN_DEBOUNCE_CONF6   (6 << DEBOUNCE_SHIFT)
> +
>  #define AM62AX_IOPAD(pa, val, muxmode)   (((pa) & 0x1fff)) 
> ((val) | (muxmode))
>  #define AM62AX_MCU_IOPAD(pa, val, muxmode)   (((pa) & 0x1fff)) ((val) | 
> (muxmode))
>  
> +#define AM62PX_IOPAD(pa, val, muxmode)   (((pa) & 0x1fff)) 
> ((val) | (muxmode))
> +#define AM62PX_MCU_IOPAD(pa, val, muxmode)   (((pa) & 0x1fff)) ((val) | 
> (muxmode))
> +
>  #define AM62X_IOPAD(pa, val, muxmode)(((pa) & 0x1fff)) 
> ((val) | (muxmode))
>  #define AM62X_MCU_IOPAD(pa, val, muxmode)(((pa) & 0x1fff)) ((val) | 
> (muxmode))
>  

Reviewed-by: Dhruva Gole 

-- 
Best regards,
Dhruva Gole 


Re: [PATCH 2/2] arm: dts: k3-am625: Sync with kernel v6.6-rc1

2023-09-12 Thread Dhruva Gole
On Sep 11, 2023 at 09:02:56 -0500, Nishanth Menon wrote:
> Sync device tree with v6.6-rc1
> 
> Signed-off-by: Nishanth Menon 
> ---
>  arch/arm/dts/k3-am62-main.dtsi   |  52 -
>  arch/arm/dts/k3-am62-mcu.dtsi|  24 +
>  arch/arm/dts/k3-am62-verdin-dev.dtsi |  50 +
>  arch/arm/dts/k3-am62-verdin.dtsi |  45 +++-
>  arch/arm/dts/k3-am62.dtsi|   8 ++
>  arch/arm/dts/k3-am625-beagleplay.dts | 154 ++-
>  arch/arm/dts/k3-am625-sk.dts |   2 +-
>  7 files changed, 325 insertions(+), 10 deletions(-)
> 

LGTM! Thanks for the sync up.

Reviewed-by: Dhruva Gole 

> 

-- 
Best regards,
Dhruva Gole 


[PATCH v4 13/13] test: dm: add scmi command test

2023-09-12 Thread AKASHI Takahiro
In this test, "scmi" command is tested against different sub-commands.
Please note that scmi command is for debug purpose and is not intended
in production system.

Signed-off-by: AKASHI Takahiro 
Reviewed-by: Simon Glass 
Reviewed-by: Etienne Carriere 
---
v4
* move 'base'-related changes to the prior commit
* add CONFIG_CMD_SCMI to sandbox_defconfig
v3
* change char to u8 in vendor/agent names
v2
* use helper functions, removing direct uses of ops
---
 configs/sandbox_defconfig |  1 +
 test/dm/scmi.c| 53 +++
 2 files changed, 54 insertions(+)

diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index 1cd1c2ed7cd5..3906476bb4fc 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -122,6 +122,7 @@ CONFIG_CMD_REGULATOR=y
 CONFIG_CMD_AES=y
 CONFIG_CMD_TPM=y
 CONFIG_CMD_TPM_TEST=y
+CONFIG_CMD_SCMI=y
 CONFIG_CMD_BTRFS=y
 CONFIG_CMD_CBFS=y
 CONFIG_CMD_CRAMFS=y
diff --git a/test/dm/scmi.c b/test/dm/scmi.c
index 48610299c1a1..423b6ef70b29 100644
--- a/test/dm/scmi.c
+++ b/test/dm/scmi.c
@@ -206,6 +206,59 @@ static int dm_test_scmi_base(struct unit_test_state *uts)
 
 DM_TEST(dm_test_scmi_base, UT_TESTF_SCAN_FDT);
 
+static int dm_test_scmi_cmd(struct unit_test_state *uts)
+{
+   struct udevice *agent_dev;
+
+   /* preparation */
+   ut_assertok(uclass_get_device_by_name(UCLASS_SCMI_AGENT, "scmi",
+ _dev));
+   ut_assertnonnull(agent_dev);
+
+   /* scmi info */
+   ut_assertok(run_command("scmi info", 0));
+
+   ut_assert_nextline("SCMI device: scmi");
+   ut_assert_nextline("  protocol version: 0x2");
+   ut_assert_nextline("  # of agents: 2");
+   ut_assert_nextline("  0: platform");
+   ut_assert_nextline("> 1: OSPM");
+   ut_assert_nextline("  # of protocols: 3");
+   ut_assert_nextline("  Clock management");
+   ut_assert_nextline("  Reset domain management");
+   ut_assert_nextline("  Voltage domain management");
+   ut_assert_nextline("  vendor: U-Boot");
+   ut_assert_nextline("  sub vendor: Sandbox");
+   ut_assert_nextline("  impl version: 0x1");
+
+   ut_assert_console_end();
+
+   /* scmi perm_dev */
+   ut_assertok(run_command("scmi perm_dev 1 0 1", 0));
+   ut_assert_console_end();
+
+   ut_assert(run_command("scmi perm_dev 1 0 0", 0));
+   ut_assert_nextline("Denying access to device:0 failed (-13)");
+   ut_assert_console_end();
+
+   /* scmi perm_proto */
+   ut_assertok(run_command("scmi perm_proto 1 0 14 1", 0));
+   ut_assert_console_end();
+
+   ut_assert(run_command("scmi perm_proto 1 0 14 0", 0));
+   ut_assert_nextline("Denying access to protocol:0x14 on device:0 failed 
(-13)");
+   ut_assert_console_end();
+
+   /* scmi reset */
+   ut_assert(run_command("scmi reset 1 1", 0));
+   ut_assert_nextline("Reset failed (-13)");
+   ut_assert_console_end();
+
+   return 0;
+}
+
+DM_TEST(dm_test_scmi_cmd, UT_TESTF_SCAN_FDT);
+
 static int dm_test_scmi_clocks(struct unit_test_state *uts)
 {
struct sandbox_scmi_agent *agent;
-- 
2.34.1



[PATCH v4 12/13] doc: cmd: add documentation for scmi

2023-09-12 Thread AKASHI Takahiro
This is a help text for scmi command.

Signed-off-by: AKASHI Takahiro 
Reviewed-by: Simon Glass 
Reviewed-by: Etienne Carriere 
---
v4
* s/tranport/transport/
v2
* add more descriptions about SCMI
---
 doc/usage/cmd/scmi.rst | 126 +
 1 file changed, 126 insertions(+)
 create mode 100644 doc/usage/cmd/scmi.rst

diff --git a/doc/usage/cmd/scmi.rst b/doc/usage/cmd/scmi.rst
new file mode 100644
index ..9ea7e0e41dad
--- /dev/null
+++ b/doc/usage/cmd/scmi.rst
@@ -0,0 +1,126 @@
+.. SPDX-License-Identifier: GPL-2.0+:
+
+scmi command
+
+
+Synopsis
+
+
+::
+
+scmi info
+scmi perm_dev   
+scmi perm_proto
+scmi reset  
+
+Description
+---
+
+Arm System Control and Management Interface (SCMI hereafter) is a set of
+standardised interfaces to manage system resources, like clocks, power
+domains, pin controls, reset and so on, in a system-wide manner.
+
+An entity which provides those services is called a SCMI firmware (or
+SCMI server if you like) may be placed/implemented by EL3 software or
+by a dedicated system control processor (SCP) or else.
+
+A user of SCMI interfaces, including U-Boot, is called a SCMI agent and
+may issues commands, which are defined in each protocol for specific system
+resources, to SCMI server via a communication channel, called a transport.
+Those interfaces are independent from the server's implementation thanks to
+a transport layer.
+
+For more details, see the `SCMI specification`_.
+
+While most of system resources managed under SCMI protocols are implemented
+and handled as standard U-Boot devices, for example clk_scmi, scmi command
+provides additional management functionality against SCMI server.
+
+scmi info
+~
+Show base information about SCMI server and supported protocols
+
+scmi perm_dev
+~
+Allow or deny access permission to the device
+
+scmi perm_proto
+~~~
+Allow or deny access to the protocol on the device
+
+scmi reset
+~~
+Reset the already-configured permissions against the device
+
+Parameters are used as follows:
+
+
+SCMI Agent ID, hex value
+
+
+SCMI Device ID, hex value
+
+Please note that what a device means is not defined
+in the specification.
+
+
+SCMI Protocol ID, hex value
+
+It must not be 0x10 (base protocol)
+
+
+Flags to control the action, hex value
+
+0 to deny, 1 to allow. The other values are reserved and allowed
+values may depend on the implemented version of SCMI server in
+the future. See SCMI specification for more details.
+
+Example
+---
+
+Obtain basic information about SCMI server:
+
+::
+
+=> scmi info
+SCMI device: scmi
+  protocol version: 0x2
+  # of agents: 3
+  0: platform
+> 1: OSPM
+  2: PSCI
+  # of protocols: 4
+  Power domain management
+  Performance domain management
+  Clock management
+  Sensor management
+  vendor: Linaro
+  sub vendor: PMWG
+  impl version: 0x20b
+
+Ask for access permission to device#0:
+
+::
+
+=> scmi perm_dev 1 0 1
+
+Reset configurations with all access permission settings retained:
+
+::
+
+=> scmi reset 1 0
+
+Configuration
+-
+
+The scmi command is only available if CONFIG_CMD_SCMI=y.
+Default n because this command is mainly for debug purpose.
+
+Return value
+
+
+The return value ($?) is set to 0 if the operation succeeded,
+1 if the operation failed or -1 if the operation failed due to
+a syntax error.
+
+.. _`SCMI specification`: 
https://developer.arm.com/documentation/den0056/e/?lang=en
-- 
2.34.1



[PATCH v4 11/13] cmd: add scmi command for SCMI firmware

2023-09-12 Thread AKASHI Takahiro
This command, "scmi", may provide a command line interface to various SCMI
protocols. It supports at least initially SCMI base protocol and is
intended mainly for debug purpose.

Signed-off-by: AKASHI Takahiro 
Reviewed-by: Simon Glass 
Reviewed-by: Etienne Carriere 
---
v3
* describe that arguments are in hex at a help message
* modify the code for dynamically allocated agent names
v2
* remove sub command category, 'scmi base', for simplicity
---
 cmd/Kconfig  |   9 ++
 cmd/Makefile |   1 +
 cmd/scmi.c   | 337 +++
 3 files changed, 347 insertions(+)
 create mode 100644 cmd/scmi.c

diff --git a/cmd/Kconfig b/cmd/Kconfig
index 43ca10f69ccf..f46152ace7d8 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -2533,6 +2533,15 @@ config CMD_CROS_EC
  a number of sub-commands for performing EC tasks such as
  updating its flash, accessing a small saved context area
  and talking to the I2C bus behind the EC (if there is one).
+
+config CMD_SCMI
+   bool "Enable scmi command"
+   depends on SCMI_FIRMWARE
+   default n
+   help
+ This command provides user interfaces to several SCMI (System
+ Control and Management Interface) protocols available on Arm
+ platforms to manage system resources.
 endmenu
 
 menu "Filesystem commands"
diff --git a/cmd/Makefile b/cmd/Makefile
index 9bebf321c397..ad3810b17e93 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -158,6 +158,7 @@ obj-$(CONFIG_CMD_SATA) += sata.o
 obj-$(CONFIG_CMD_NVME) += nvme.o
 obj-$(CONFIG_SANDBOX) += sb.o
 obj-$(CONFIG_CMD_SF) += sf.o
+obj-$(CONFIG_CMD_SCMI) += scmi.o
 obj-$(CONFIG_CMD_SCSI) += scsi.o disk.o
 obj-$(CONFIG_CMD_SHA1SUM) += sha1sum.o
 obj-$(CONFIG_CMD_SEAMA) += seama.o
diff --git a/cmd/scmi.c b/cmd/scmi.c
new file mode 100644
index ..5efec8ad87fd
--- /dev/null
+++ b/cmd/scmi.c
@@ -0,0 +1,337 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ *  SCMI (System Control and Management Interface) utility command
+ *
+ *  Copyright (c) 2023 Linaro Limited
+ * Author: AKASHI Takahiro
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include  /* uclass_get_device */
+#include 
+#include 
+
+static struct udevice *agent;
+static struct udevice *base_proto;
+
+struct {
+   enum scmi_std_protocol id;
+   const char *name;
+} protocol_name[] = {
+   {SCMI_PROTOCOL_ID_BASE, "Base"},
+   {SCMI_PROTOCOL_ID_POWER_DOMAIN, "Power domain management"},
+   {SCMI_PROTOCOL_ID_SYSTEM, "System power management"},
+   {SCMI_PROTOCOL_ID_PERF, "Performance domain management"},
+   {SCMI_PROTOCOL_ID_CLOCK, "Clock management"},
+   {SCMI_PROTOCOL_ID_SENSOR, "Sensor management"},
+   {SCMI_PROTOCOL_ID_RESET_DOMAIN, "Reset domain management"},
+   {SCMI_PROTOCOL_ID_VOLTAGE_DOMAIN, "Voltage domain management"},
+};
+
+/**
+ * get_proto_name() - get the name of SCMI protocol
+ *
+ * @id:SCMI Protocol ID
+ *
+ * Get the printable name of the protocol, @id
+ *
+ * Return: Name string on success, NULL on failure
+ */
+static const char *get_proto_name(enum scmi_std_protocol id)
+{
+   int i;
+
+   for (i = 0; i < ARRAY_SIZE(protocol_name); i++)
+   if (id == protocol_name[i].id)
+   return protocol_name[i].name;
+
+   return NULL;
+}
+
+/**
+ * do_scmi_info() - get the information of SCMI services
+ *
+ * @cmdtp: Command table
+ * @flag:  Command flag
+ * @argc:  Number of arguments
+ * @argv:  Argument array
+ *
+ * Get the information of SCMI services using various interfaces
+ * provided by the Base protocol.
+ *
+ * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure
+ */
+static int do_scmi_info(struct cmd_tbl *cmdtp, int flag, int argc,
+   char * const argv[])
+{
+   u32 agent_id, num_protocols;
+   u8 *agent_name, *protocols;
+   int i, ret;
+
+   if (argc != 1)
+   return CMD_RET_USAGE;
+
+   printf("SCMI device: %s\n", agent->name);
+   printf("  protocol version: 0x%x\n", scmi_version(agent));
+   printf("  # of agents: %d\n", scmi_num_agents(agent));
+   for (i = 0; i < scmi_num_agents(agent); i++) {
+   ret = scmi_base_discover_agent(base_proto, i, _id,
+  _name);
+   if (ret) {
+   if (ret != -EOPNOTSUPP)
+   printf("base_discover_agent() failed for id: %d 
(%d)\n",
+  i, ret);
+   break;
+   }
+   printf("%c%2d: %s\n", i == scmi_agent_id(agent) ? '>' : ' ',
+  i, agent_name);
+   free(agent_name);
+   }
+   printf("  # of protocols: %d\n", scmi_num_protocols(agent));
+   num_protocols = scmi_num_protocols(agent);
+   protocols = scmi_protocols(agent);
+  

[PATCH v4 10/13] test: dm: add SCMI base protocol test

2023-09-12 Thread AKASHI Takahiro
Added is a new unit test for SCMI base protocol, which will exercise all
the commands provided by the protocol, except SCMI_BASE_NOTIFY_ERRORS.
  $ ut dm scmi_base
It is assumed that test.dtb is used as sandbox's device tree.

Signed-off-by: AKASHI Takahiro 
Reviewed-by: Etienne Carriere 
---
v4
* fix a typo fix in v3
  s/scmi_protocol_message_attrs/scmi_base_protocol_message_attrs/
v3
* typo: s/scmi_base_protocol_attrs/scmi_base_protocol_message_attrs/
* modify the code for dynamically allocated vendor/agent names
v2
* use helper functions, removing direct uses of ops
---
 test/dm/scmi.c | 111 +
 1 file changed, 111 insertions(+)

diff --git a/test/dm/scmi.c b/test/dm/scmi.c
index 881be3171b7c..48610299c1a1 100644
--- a/test/dm/scmi.c
+++ b/test/dm/scmi.c
@@ -16,6 +16,9 @@
 #include 
 #include 
 #include 
+#include 
+#include 
+#include 
 #include 
 #include 
 #include 
@@ -95,6 +98,114 @@ static int dm_test_scmi_sandbox_agent(struct 
unit_test_state *uts)
 }
 DM_TEST(dm_test_scmi_sandbox_agent, UT_TESTF_SCAN_FDT);
 
+static int dm_test_scmi_base(struct unit_test_state *uts)
+{
+   struct udevice *agent_dev, *base;
+   struct scmi_agent_priv *priv;
+   u32 version, num_agents, num_protocols, impl_version;
+   u32 attributes, agent_id;
+   u8 *vendor, *agent_name, *protocols;
+   int ret;
+
+   /* preparation */
+   ut_assertok(uclass_get_device_by_name(UCLASS_SCMI_AGENT, "scmi",
+ _dev));
+   ut_assertnonnull(agent_dev);
+   ut_assertnonnull(priv = dev_get_uclass_plat(agent_dev));
+   ut_assertnonnull(base = scmi_get_protocol(agent_dev,
+ SCMI_PROTOCOL_ID_BASE));
+
+   /* version */
+   ret = scmi_base_protocol_version(base, );
+   ut_assertok(ret);
+   ut_asserteq(priv->version, version);
+
+   /* protocol attributes */
+   ret = scmi_base_protocol_attrs(base, _agents, _protocols);
+   ut_assertok(ret);
+   ut_asserteq(priv->num_agents, num_agents);
+   ut_asserteq(priv->num_protocols, num_protocols);
+
+   /* discover vendor */
+   ret = scmi_base_discover_vendor(base, );
+   ut_assertok(ret);
+   ut_asserteq_str(priv->vendor, vendor);
+   free(vendor);
+
+   /* message attributes */
+   ret = scmi_base_protocol_message_attrs(base,
+  SCMI_BASE_DISCOVER_SUB_VENDOR,
+  );
+   ut_assertok(ret);
+   ut_assertok(attributes);
+
+   /* discover sub vendor */
+   ret = scmi_base_discover_sub_vendor(base, );
+   ut_assertok(ret);
+   ut_asserteq_str(priv->sub_vendor, vendor);
+   free(vendor);
+
+   /* impl version */
+   ret = scmi_base_discover_impl_version(base, _version);
+   ut_assertok(ret);
+   ut_asserteq(priv->impl_version, impl_version);
+
+   /* discover agent (my self) */
+   ret = scmi_base_discover_agent(base, 0x, _id,
+  _name);
+   ut_assertok(ret);
+   ut_asserteq(priv->agent_id, agent_id);
+   ut_asserteq_str(priv->agent_name, agent_name);
+   free(agent_name);
+
+   /* discover protocols */
+   ret = scmi_base_discover_list_protocols(base, );
+   ut_asserteq(num_protocols, ret);
+   ut_asserteq_mem(priv->protocols, protocols, sizeof(u8) * num_protocols);
+   free(protocols);
+
+   /*
+* NOTE: Sandbox SCMI driver handles device-0 only. It supports setting
+* access and protocol permissions, but doesn't allow unsetting them nor
+* resetting the configurations.
+*/
+   /* set device permissions */
+   ret = scmi_base_set_device_permissions(base, agent_id, 0,
+  
SCMI_BASE_SET_DEVICE_PERMISSIONS_ACCESS);
+   ut_assertok(ret); /* SCMI_SUCCESS */
+   ret = scmi_base_set_device_permissions(base, agent_id, 1,
+  
SCMI_BASE_SET_DEVICE_PERMISSIONS_ACCESS);
+   ut_asserteq(-ENOENT, ret); /* SCMI_NOT_FOUND */
+   ret = scmi_base_set_device_permissions(base, agent_id, 0, 0);
+   ut_asserteq(-EACCES, ret); /* SCMI_DENIED */
+
+   /* set protocol permissions */
+   ret = scmi_base_set_protocol_permissions(base, agent_id, 0,
+SCMI_PROTOCOL_ID_CLOCK,
+
SCMI_BASE_SET_PROTOCOL_PERMISSIONS_ACCESS);
+   ut_assertok(ret); /* SCMI_SUCCESS */
+   ret = scmi_base_set_protocol_permissions(base, agent_id, 1,
+SCMI_PROTOCOL_ID_CLOCK,
+
SCMI_BASE_SET_PROTOCOL_PERMISSIONS_ACCESS);
+   ut_asserteq(-ENOENT, ret); /* SCMI_NOT_FOUND */
+   ret = scmi_base_set_protocol_permissions(base, agent_id, 0,
+  

[PATCH v4 09/13] sandbox: remove SCMI base node definition from test.dts

2023-09-12 Thread AKASHI Takahiro
SCMI base protocol is mandatory and doesn't need to be listed in a device
tree.

Signed-off-by: AKASHI Takahiro 
Reviewed-by: Simon Glass 
Reviewed-by: Etienne Carriere 
---
 arch/sandbox/dts/test.dts | 4 
 1 file changed, 4 deletions(-)

diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index f351d5cb84b0..dc0bfdfb6e4b 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -693,10 +693,6 @@
#address-cells = <1>;
#size-cells = <0>;
 
-   protocol@10 {
-   reg = <0x10>;
-   };
-
clk_scmi: protocol@14 {
reg = <0x14>;
#clock-cells = <1>;
-- 
2.34.1



[PATCH v4 08/13] firmware: scmi: add a check against availability of protocols

2023-09-12 Thread AKASHI Takahiro
Now that we have Base protocol support, we will be able to check if a given
protocol is really supported by the SCMI server (firmware).

Signed-off-by: AKASHI Takahiro 
Reviewed-by: Etienne Carriere 
---
v3
* new; import this patch from my followup patch set
---
 drivers/firmware/scmi/scmi_agent-uclass.c | 41 +--
 1 file changed, 38 insertions(+), 3 deletions(-)

diff --git a/drivers/firmware/scmi/scmi_agent-uclass.c 
b/drivers/firmware/scmi/scmi_agent-uclass.c
index cd72345b8e54..b83cb0f5d0bc 100644
--- a/drivers/firmware/scmi/scmi_agent-uclass.c
+++ b/drivers/firmware/scmi/scmi_agent-uclass.c
@@ -38,6 +38,38 @@ static const struct error_code scmi_linux_errmap[] = {
{ .scmi = SCMI_PROTOCOL_ERROR, .errno = -EPROTO, },
 };
 
+/**
+ * scmi_protocol_is_supported - check availability of protocol
+ * @dev:   SCMI agent device
+ * @proto_id:  Identifier of protocol
+ *
+ * check if the protocol, @proto_id, is provided by the SCMI agent,
+ * @dev.
+ *
+ * Return: 0 on success, error code otherwise
+ */
+static bool scmi_protocol_is_supported(struct udevice *dev,
+  enum scmi_std_protocol proto_id)
+{
+   struct scmi_agent_priv *priv;
+   int i;
+
+   if (proto_id == SCMI_PROTOCOL_ID_BASE)
+   return true;
+
+   priv = dev_get_uclass_plat(dev);
+   if (!priv) {
+   dev_err(dev, "No priv data found\n");
+   return false;
+   }
+
+   for (i = 0; i < priv->num_protocols; i++)
+   if (priv->protocols[i] == proto_id)
+   return true;
+
+   return false;
+}
+
 struct udevice *scmi_get_protocol(struct udevice *dev,
  enum scmi_std_protocol id)
 {
@@ -373,15 +405,18 @@ static int scmi_bind_protocols(struct udevice *dev)
name = ofnode_get_name(node);
switch (protocol_id) {
case SCMI_PROTOCOL_ID_CLOCK:
-   if (CONFIG_IS_ENABLED(CLK_SCMI))
+   if (CONFIG_IS_ENABLED(CLK_SCMI) &&
+   scmi_protocol_is_supported(dev, protocol_id))
drv = DM_DRIVER_GET(scmi_clock);
break;
case SCMI_PROTOCOL_ID_RESET_DOMAIN:
-   if (IS_ENABLED(CONFIG_RESET_SCMI))
+   if (IS_ENABLED(CONFIG_RESET_SCMI) &&
+   scmi_protocol_is_supported(dev, protocol_id))
drv = DM_DRIVER_GET(scmi_reset_domain);
break;
case SCMI_PROTOCOL_ID_VOLTAGE_DOMAIN:
-   if (IS_ENABLED(CONFIG_DM_REGULATOR_SCMI)) {
+   if (IS_ENABLED(CONFIG_DM_REGULATOR_SCMI) &&
+   scmi_protocol_is_supported(dev, protocol_id)) {
node = ofnode_find_subnode(node, "regulators");
if (!ofnode_valid(node)) {
dev_err(dev, "no regulators node\n");
-- 
2.34.1



[PATCH v4 07/13] firmware: scmi: install base protocol to SCMI agent

2023-09-12 Thread AKASHI Takahiro
SCMI base protocol is mandatory, and once SCMI node is found in a device
tree, the protocol handle (udevice) is unconditionally installed to
the agent. Then basic information will be retrieved from SCMI server via
the protocol and saved into the agent instance's local storage.

Signed-off-by: AKASHI Takahiro 
Reviewed-by: Simon Glass 
Reviewed-by: Etienne Carriere 
---
v4
* remove 'scmi_agent' global variable as it is never utilized
* add 'agent' variable in scmi_bind_protocols()
* return an appropriate error (EPROTO) when
  scmi_base_discover_list_protocols() fails
* fix misc typos
v3
* typo fix: add '@' for argument name in function description
* eliminate dev_get_uclass_plat()'s repeated in inline
* modify the code for dynamically allocated sub-vendor/agent names
v2
* use helper functions, removing direct uses of ops
---
 drivers/firmware/scmi/scmi_agent-uclass.c | 127 --
 include/scmi_agent-uclass.h   |  66 +++
 2 files changed, 183 insertions(+), 10 deletions(-)

diff --git a/drivers/firmware/scmi/scmi_agent-uclass.c 
b/drivers/firmware/scmi/scmi_agent-uclass.c
index 64878f04359e..cd72345b8e54 100644
--- a/drivers/firmware/scmi/scmi_agent-uclass.c
+++ b/drivers/firmware/scmi/scmi_agent-uclass.c
@@ -38,12 +38,6 @@ static const struct error_code scmi_linux_errmap[] = {
{ .scmi = SCMI_PROTOCOL_ERROR, .errno = -EPROTO, },
 };
 
-/*
- * NOTE: The only one instance should exist according to
- * the current specification and device tree bindings.
- */
-struct udevice *scmi_agent;
-
 struct udevice *scmi_get_protocol(struct udevice *dev,
  enum scmi_std_protocol id)
 {
@@ -57,6 +51,9 @@ struct udevice *scmi_get_protocol(struct udevice *dev,
}
 
switch (id) {
+   case SCMI_PROTOCOL_ID_BASE:
+   proto = priv->base_dev;
+   break;
case SCMI_PROTOCOL_ID_CLOCK:
proto = priv->clock_dev;
break;
@@ -101,6 +98,9 @@ static int scmi_add_protocol(struct udevice *dev,
}
 
switch (proto_id) {
+   case SCMI_PROTOCOL_ID_BASE:
+   priv->base_dev = proto;
+   break;
case SCMI_PROTOCOL_ID_CLOCK:
priv->clock_dev = proto;
break;
@@ -237,6 +237,83 @@ int devm_scmi_process_msg(struct udevice *dev, struct 
scmi_msg *msg)
return scmi_process_msg(protocol->parent, priv->channel, msg);
 }
 
+/**
+ * scmi_fill_base_info - get base information about SCMI server
+ * @agent: SCMI agent device
+ * @dev:   SCMI protocol device
+ *
+ * By using Base protocol commands, collect the base information
+ * about SCMI server.
+ *
+ * Return: 0 on success, error code otherwise
+ */
+static int scmi_fill_base_info(struct udevice *agent, struct udevice *dev)
+{
+   struct scmi_agent_priv *priv = dev_get_uclass_plat(agent);
+   int ret;
+
+   ret = scmi_base_protocol_version(dev, >version);
+   if (ret) {
+   dev_err(dev, "protocol_version() failed (%d)\n", ret);
+   return ret;
+   }
+   /* check for required version */
+   if (priv->version < SCMI_BASE_PROTOCOL_VERSION) {
+   dev_err(dev, "base protocol version (%d) lower than expected\n",
+   priv->version);
+   return -EPROTO;
+   }
+
+   ret = scmi_base_protocol_attrs(dev, >num_agents,
+  >num_protocols);
+   if (ret) {
+   dev_err(dev, "protocol_attrs() failed (%d)\n", ret);
+   return ret;
+   }
+   ret = scmi_base_discover_vendor(dev, >vendor);
+   if (ret) {
+   dev_err(dev, "base_discover_vendor() failed (%d)\n", ret);
+   return ret;
+   }
+   ret = scmi_base_discover_sub_vendor(dev, >sub_vendor);
+   if (ret) {
+   if (ret != -EOPNOTSUPP) {
+   dev_err(dev, "base_discover_sub_vendor() failed (%d)\n",
+   ret);
+   return ret;
+   }
+   priv->sub_vendor = "NA";
+   }
+   ret = scmi_base_discover_impl_version(dev, >impl_version);
+   if (ret) {
+   dev_err(dev, "base_discover_impl_version() failed (%d)\n",
+   ret);
+   return ret;
+   }
+
+   ret = scmi_base_discover_agent(dev, 0x,
+  >agent_id, >agent_name);
+   if (ret) {
+   if (ret != -EOPNOTSUPP) {
+   dev_err(dev,
+   "base_discover_agent() failed for myself 
(%d)\n",
+   ret);
+   return ret;
+   }
+   priv->agent_id = 0x;
+   priv->agent_name = "NA";
+   }
+
+   ret = scmi_base_discover_list_protocols(dev, >protocols);
+   if (ret != priv->num_protocols) {
+   dev_err(dev, 

[PATCH v4 06/13] test: dm: simplify SCMI unit test on sandbox

2023-09-12 Thread AKASHI Takahiro
Adding SCMI base protocol makes it inconvenient to hold the agent instance
(udevice) locally since the agent device will be re-created per each test.
Just remove it and simplify the test flows.
The test scenario is not changed at all.

Signed-off-by: AKASHI Takahiro 
Reviewed-by: Simon Glass 
Reviewed-by: Etienne Carriere 
---
v4
* move this patch forward in this series before installing base
  protocol to avoid collapsing existing SCMI test.
---
 arch/sandbox/include/asm/scmi_test.h   |  7 ++-
 drivers/firmware/scmi/sandbox-scmi_agent.c | 20 +--
 test/dm/scmi.c | 64 +++---
 3 files changed, 26 insertions(+), 65 deletions(-)

diff --git a/arch/sandbox/include/asm/scmi_test.h 
b/arch/sandbox/include/asm/scmi_test.h
index c72ec1e1cb25..2718336a9a50 100644
--- a/arch/sandbox/include/asm/scmi_test.h
+++ b/arch/sandbox/include/asm/scmi_test.h
@@ -89,10 +89,11 @@ struct sandbox_scmi_devices {
 
 #ifdef CONFIG_SCMI_FIRMWARE
 /**
- * sandbox_scmi_service_ctx - Get the simulated SCMI services context
+ * sandbox_scmi_agent_ctx - Get the simulated SCMI agent context
+ * @dev:   Reference to the test agent
  * @return:Reference to backend simulated resources state
  */
-struct sandbox_scmi_service *sandbox_scmi_service_ctx(void);
+struct sandbox_scmi_agent *sandbox_scmi_agent_ctx(struct udevice *dev);
 
 /**
  * sandbox_scmi_devices_ctx - Get references to devices accessed through SCMI
@@ -101,7 +102,7 @@ struct sandbox_scmi_service *sandbox_scmi_service_ctx(void);
  */
 struct sandbox_scmi_devices *sandbox_scmi_devices_ctx(struct udevice *dev);
 #else
-static inline struct sandbox_scmi_service *sandbox_scmi_service_ctx(void)
+static struct sandbox_scmi_agent *sandbox_scmi_agent_ctx(struct udevice *dev)
 {
return NULL;
 }
diff --git a/drivers/firmware/scmi/sandbox-scmi_agent.c 
b/drivers/firmware/scmi/sandbox-scmi_agent.c
index 42a5a1f37f8b..27d17809be43 100644
--- a/drivers/firmware/scmi/sandbox-scmi_agent.c
+++ b/drivers/firmware/scmi/sandbox-scmi_agent.c
@@ -66,11 +66,9 @@ static struct sandbox_scmi_voltd scmi_voltd[] = {
{ .id = 1, .voltage_uv = 180 },
 };
 
-static struct sandbox_scmi_service sandbox_scmi_service_state;
-
-struct sandbox_scmi_service *sandbox_scmi_service_ctx(void)
+struct sandbox_scmi_agent *sandbox_scmi_agent_ctx(struct udevice *dev)
 {
-   return _scmi_service_state;
+   return dev_get_priv(dev);
 }
 
 static void debug_print_agent_state(struct udevice *dev, char *str)
@@ -898,16 +896,8 @@ static int sandbox_scmi_test_process_msg(struct udevice 
*dev,
 
 static int sandbox_scmi_test_remove(struct udevice *dev)
 {
-   struct sandbox_scmi_agent *agent = dev_get_priv(dev);
-
-   if (agent != sandbox_scmi_service_ctx()->agent)
-   return -EINVAL;
-
debug_print_agent_state(dev, "removed");
 
-   /* We only need to dereference the agent in the context */
-   sandbox_scmi_service_ctx()->agent = NULL;
-
return 0;
 }
 
@@ -915,9 +905,6 @@ static int sandbox_scmi_test_probe(struct udevice *dev)
 {
struct sandbox_scmi_agent *agent = dev_get_priv(dev);
 
-   if (sandbox_scmi_service_ctx()->agent)
-   return -EINVAL;
-
*agent = (struct sandbox_scmi_agent){
.clk = scmi_clk,
.clk_count = ARRAY_SIZE(scmi_clk),
@@ -929,9 +916,6 @@ static int sandbox_scmi_test_probe(struct udevice *dev)
 
debug_print_agent_state(dev, "probed");
 
-   /* Save reference for tests purpose */
-   sandbox_scmi_service_ctx()->agent = agent;
-
return 0;
 };
 
diff --git a/test/dm/scmi.c b/test/dm/scmi.c
index d87e2731ce42..881be3171b7c 100644
--- a/test/dm/scmi.c
+++ b/test/dm/scmi.c
@@ -23,22 +23,11 @@
 #include 
 #include 
 
-static int ut_assert_scmi_state_preprobe(struct unit_test_state *uts)
-{
-   struct sandbox_scmi_service *scmi_ctx = sandbox_scmi_service_ctx();
-
-   ut_assertnonnull(scmi_ctx);
-   ut_assertnull(scmi_ctx->agent);
-
-   return 0;
-}
-
 static int ut_assert_scmi_state_postprobe(struct unit_test_state *uts,
+ struct sandbox_scmi_agent *agent,
  struct udevice *dev)
 {
struct sandbox_scmi_devices *scmi_devices;
-   struct sandbox_scmi_service *scmi_ctx;
-   struct sandbox_scmi_agent *agent;
 
/* Device references to check context against test sequence */
scmi_devices = sandbox_scmi_devices_ctx(dev);
@@ -48,10 +37,6 @@ static int ut_assert_scmi_state_postprobe(struct 
unit_test_state *uts,
ut_asserteq(2, scmi_devices->regul_count);
 
/* State of the simulated SCMI server exposed */
-   scmi_ctx = sandbox_scmi_service_ctx();
-   ut_assertnonnull(scmi_ctx);
-   agent = scmi_ctx->agent;
-   ut_assertnonnull(agent);
ut_asserteq(3, agent->clk_count);
ut_assertnonnull(agent->clk);
ut_asserteq(1, agent->reset_count);
@@ 

[PATCH v4 05/13] firmware: scmi: fake base protocol commands on sandbox

2023-09-12 Thread AKASHI Takahiro
This is a simple implementation of SCMI base protocol for sandbox.
The main use is in SCMI unit test.

Signed-off-by: AKASHI Takahiro 
Reviewed-by: Simon Glass 
Reviewed-by: Etienne Carriere 
---
v4
* move this patch forward in this series before installing base
  protocol to avoid collapsing existing SCMI test.
v3
* type fixes: s/udevice/dev/ in function descriptions
---
 drivers/firmware/scmi/sandbox-scmi_agent.c | 359 -
 1 file changed, 358 insertions(+), 1 deletion(-)

diff --git a/drivers/firmware/scmi/sandbox-scmi_agent.c 
b/drivers/firmware/scmi/sandbox-scmi_agent.c
index 031882998dfa..42a5a1f37f8b 100644
--- a/drivers/firmware/scmi/sandbox-scmi_agent.c
+++ b/drivers/firmware/scmi/sandbox-scmi_agent.c
@@ -14,11 +14,14 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 
 /*
  * The sandbox SCMI agent driver simulates to some extend a SCMI message
  * processing. It simulates few of the SCMI services for some of the
  * SCMI protocols embedded in U-Boot. Currently:
+ * - SCMI base protocol
  * - SCMI clock protocol emulates an agent exposing 2 clocks
  * - SCMI reset protocol emulates an agent exposing a reset controller
  * - SCMI voltage domain protocol emulates an agent exposing 2 regulators
@@ -33,6 +36,21 @@
  * various uclass devices, as clocks and reset controllers.
  */
 
+#define SANDBOX_SCMI_BASE_PROTOCOL_VERSION SCMI_BASE_PROTOCOL_VERSION
+#define SANDBOX_SCMI_VENDOR "U-Boot"
+#define SANDBOX_SCMI_SUB_VENDOR "Sandbox"
+#define SANDBOX_SCMI_IMPL_VERSION 0x1
+#define SANDBOX_SCMI_AGENT_NAME "OSPM"
+#define SANDBOX_SCMI_PLATFORM_NAME "platform"
+
+static u8 protocols[] = {
+   SCMI_PROTOCOL_ID_CLOCK,
+   SCMI_PROTOCOL_ID_RESET_DOMAIN,
+   SCMI_PROTOCOL_ID_VOLTAGE_DOMAIN,
+};
+
+#define NUM_PROTOCOLS ARRAY_SIZE(protocols)
+
 static struct sandbox_scmi_clk scmi_clk[] = {
{ .rate = 333 },
{ .rate = 200 },
@@ -114,6 +132,316 @@ static struct sandbox_scmi_voltd 
*get_scmi_voltd_state(uint domain_id)
  * Sandbox SCMI agent ops
  */
 
+/* Base Protocol */
+
+/**
+ * sandbox_scmi_base_protocol_version - implement SCMI_BASE_PROTOCOL_VERSION
+ * @dev:   SCMI device
+ * @msg:   SCMI message
+ *
+ * Implement SCMI_BASE_PROTOCOL_VERSION command.
+ */
+static int sandbox_scmi_base_protocol_version(struct udevice *dev,
+ struct scmi_msg *msg)
+{
+   struct scmi_protocol_version_out *out = NULL;
+
+   if (!msg->out_msg || msg->out_msg_sz < sizeof(*out))
+   return -EINVAL;
+
+   out = (struct scmi_protocol_version_out *)msg->out_msg;
+   out->version = SANDBOX_SCMI_BASE_PROTOCOL_VERSION;
+   out->status = SCMI_SUCCESS;
+
+   return 0;
+}
+
+/**
+ * sandbox_scmi_base_protocol_attrs - implement SCMI_BASE_PROTOCOL_ATTRIBUTES
+ * @dev:   SCMI device
+ * @msg:   SCMI message
+ *
+ * Implement SCMI_BASE_PROTOCOL_ATTRIBUTES command.
+ */
+static int sandbox_scmi_base_protocol_attrs(struct udevice *dev,
+   struct scmi_msg *msg)
+{
+   struct scmi_protocol_attrs_out *out = NULL;
+
+   if (!msg->out_msg || msg->out_msg_sz < sizeof(*out))
+   return -EINVAL;
+
+   out = (struct scmi_protocol_attrs_out *)msg->out_msg;
+   out->attributes = FIELD_PREP(0xff00, 2) | NUM_PROTOCOLS;
+   out->status = SCMI_SUCCESS;
+
+   return 0;
+}
+
+/**
+ * sandbox_scmi_base_message_attrs - implement
+ * SCMI_BASE_PROTOCOL_MESSAGE_ATTRIBUTES
+ * @dev:   SCMI device
+ * @msg:   SCMI message
+ *
+ * Implement SCMI_BASE_PROTOCOL_MESSAGE_ATTRIBUTES command.
+ */
+static int sandbox_scmi_base_message_attrs(struct udevice *dev,
+  struct scmi_msg *msg)
+{
+   u32 message_id;
+   struct scmi_protocol_msg_attrs_out *out = NULL;
+
+   if (!msg->in_msg || msg->in_msg_sz < sizeof(message_id) ||
+   !msg->out_msg || msg->out_msg_sz < sizeof(*out))
+   return -EINVAL;
+
+   message_id = *(u32 *)msg->in_msg;
+   out = (struct scmi_protocol_msg_attrs_out *)msg->out_msg;
+
+   if (message_id >= SCMI_PROTOCOL_VERSION &&
+   message_id <= SCMI_BASE_RESET_AGENT_CONFIGURATION &&
+   message_id != SCMI_BASE_NOTIFY_ERRORS) {
+   out->attributes = 0;
+   out->status = SCMI_SUCCESS;
+   } else {
+   out->status = SCMI_NOT_FOUND;
+   }
+
+   return 0;
+}
+
+/**
+ * sandbox_scmi_base_discover_vendor - implement SCMI_BASE_DISCOVER_VENDOR
+ * @dev:   SCMI device
+ * @msg:   SCMI message
+ *
+ * Implement SCMI_BASE_DISCOVER_VENDOR command
+ */
+static int sandbox_scmi_base_discover_vendor(struct udevice *dev,
+struct scmi_msg *msg)
+{
+   struct scmi_base_discover_vendor_out *out = NULL;
+
+   if (!msg->out_msg || msg->out_msg_sz < sizeof(*out))
+   return -EINVAL;
+
+   

[PATCH v4 04/13] firmware: scmi: framework for installing additional protocols

2023-09-12 Thread AKASHI Takahiro
This framework allows SCMI protocols to be installed and bound to the agent
so that the agent can manage and utilize them later.

Signed-off-by: AKASHI Takahiro 
Reviewed-by: Simon Glass 
Reviewed-by: Etienne Carriere 
---
V4
* remove 'agent' variable as it should be added in the following commit
v3
* move "per_device_plat_auto" from a earlier patch
* fix comments in "scmi_agent_priv"
* modify an order of include files in scmi_agent.h
v2
* check for availability of protocols
---
 drivers/firmware/scmi/scmi_agent-uclass.c | 100 +-
 include/scmi_agent-uclass.h   |  15 +++-
 include/scmi_agent.h  |  14 +++
 3 files changed, 125 insertions(+), 4 deletions(-)

diff --git a/drivers/firmware/scmi/scmi_agent-uclass.c 
b/drivers/firmware/scmi/scmi_agent-uclass.c
index 0b97569eb1a0..64878f04359e 100644
--- a/drivers/firmware/scmi/scmi_agent-uclass.c
+++ b/drivers/firmware/scmi/scmi_agent-uclass.c
@@ -38,6 +38,86 @@ static const struct error_code scmi_linux_errmap[] = {
{ .scmi = SCMI_PROTOCOL_ERROR, .errno = -EPROTO, },
 };
 
+/*
+ * NOTE: The only one instance should exist according to
+ * the current specification and device tree bindings.
+ */
+struct udevice *scmi_agent;
+
+struct udevice *scmi_get_protocol(struct udevice *dev,
+ enum scmi_std_protocol id)
+{
+   struct scmi_agent_priv *priv;
+   struct udevice *proto;
+
+   priv = dev_get_uclass_plat(dev);
+   if (!priv) {
+   dev_err(dev, "No priv data found\n");
+   return NULL;
+   }
+
+   switch (id) {
+   case SCMI_PROTOCOL_ID_CLOCK:
+   proto = priv->clock_dev;
+   break;
+   case SCMI_PROTOCOL_ID_RESET_DOMAIN:
+   proto = priv->resetdom_dev;
+   break;
+   case SCMI_PROTOCOL_ID_VOLTAGE_DOMAIN:
+   proto = priv->voltagedom_dev;
+   break;
+   default:
+   dev_err(dev, "Protocol not supported\n");
+   proto = NULL;
+   break;
+   }
+   if (proto && device_probe(proto))
+   dev_err(dev, "Probe failed\n");
+
+   return proto;
+}
+
+/**
+ * scmi_add_protocol - add protocol to agent
+ * @dev:   SCMI agent device
+ * @proto_id:  SCMI protocol ID
+ * @proto: SCMI protocol device
+ *
+ * Associate the protocol instance, @proto, to the agent, @dev,
+ * for later use.
+ *
+ * Return: 0 on success, error code otherwise
+ */
+static int scmi_add_protocol(struct udevice *dev,
+enum scmi_std_protocol proto_id,
+struct udevice *proto)
+{
+   struct scmi_agent_priv *priv;
+
+   priv = dev_get_uclass_plat(dev);
+   if (!priv) {
+   dev_err(dev, "No priv data found\n");
+   return -ENODEV;
+   }
+
+   switch (proto_id) {
+   case SCMI_PROTOCOL_ID_CLOCK:
+   priv->clock_dev = proto;
+   break;
+   case SCMI_PROTOCOL_ID_RESET_DOMAIN:
+   priv->resetdom_dev = proto;
+   break;
+   case SCMI_PROTOCOL_ID_VOLTAGE_DOMAIN:
+   priv->voltagedom_dev = proto;
+   break;
+   default:
+   dev_err(dev, "Protocol not supported\n");
+   return -EPROTO;
+   }
+
+   return 0;
+}
+
 int scmi_to_linux_errno(s32 scmi_code)
 {
int n;
@@ -167,9 +247,10 @@ static int scmi_bind_protocols(struct udevice *dev)
int ret = 0;
ofnode node;
const char *name;
+   struct driver *drv;
+   struct udevice *proto;
 
dev_for_each_subnode(node, dev) {
-   struct driver *drv = NULL;
u32 protocol_id;
 
if (!ofnode_is_enabled(node))
@@ -178,6 +259,7 @@ static int scmi_bind_protocols(struct udevice *dev)
if (ofnode_read_u32(node, "reg", _id))
continue;
 
+   drv = NULL;
name = ofnode_get_name(node);
switch (protocol_id) {
case SCMI_PROTOCOL_ID_CLOCK:
@@ -208,11 +290,22 @@ static int scmi_bind_protocols(struct udevice *dev)
continue;
}
 
-   ret = device_bind(dev, drv, name, NULL, node, NULL);
-   if (ret)
+   ret = device_bind(dev, drv, name, NULL, node, );
+   if (ret) {
+   dev_err(dev, "failed to bind %s protocol\n", drv->name);
break;
+   }
+   ret = scmi_add_protocol(dev, protocol_id, proto);
+   if (ret) {
+   dev_err(dev, "failed to add protocol: %s, ret: %d\n",
+   proto->name, ret);
+   break;
+   }
}
 
+   if (!ret)
+   scmi_agent = dev;
+
return ret;
 }
 
@@ -220,5 +313,6 @@ UCLASS_DRIVER(scmi_agent) = {
.id = 

[PATCH v4 03/13] firmware: scmi: move scmi_bind_protocols() backward

2023-09-12 Thread AKASHI Takahiro
Move the location of scmi_bind_protocols() backward for changes
in later patches.
There is no change in functionality.

Signed-off-by: AKASHI Takahiro 
Reviewed-by: Simon Glass 
Reviewed-by: Etienne Carriere 
---
v4
* remove scmi_bind_protocols() from the original place. See patch#1
* s/depeding/depending/
---
 drivers/firmware/scmi/scmi_agent-uclass.c | 118 +++---
 1 file changed, 59 insertions(+), 59 deletions(-)

diff --git a/drivers/firmware/scmi/scmi_agent-uclass.c 
b/drivers/firmware/scmi/scmi_agent-uclass.c
index 75744cb35d7c..0b97569eb1a0 100644
--- a/drivers/firmware/scmi/scmi_agent-uclass.c
+++ b/drivers/firmware/scmi/scmi_agent-uclass.c
@@ -52,65 +52,6 @@ int scmi_to_linux_errno(s32 scmi_code)
return -EPROTO;
 }
 
-/*
- * SCMI agent devices binds devices of various uclasses depeding on
- * the FDT description. scmi_bind_protocol() is a generic bind sequence
- * called by the uclass at bind stage, that is uclass post_bind.
- */
-static int scmi_bind_protocols(struct udevice *dev)
-{
-   int ret = 0;
-   ofnode node;
-   const char *name;
-
-   dev_for_each_subnode(node, dev) {
-   struct driver *drv = NULL;
-   u32 protocol_id;
-
-   if (!ofnode_is_enabled(node))
-   continue;
-
-   if (ofnode_read_u32(node, "reg", _id))
-   continue;
-
-   name = ofnode_get_name(node);
-   switch (protocol_id) {
-   case SCMI_PROTOCOL_ID_CLOCK:
-   if (CONFIG_IS_ENABLED(CLK_SCMI))
-   drv = DM_DRIVER_GET(scmi_clock);
-   break;
-   case SCMI_PROTOCOL_ID_RESET_DOMAIN:
-   if (IS_ENABLED(CONFIG_RESET_SCMI))
-   drv = DM_DRIVER_GET(scmi_reset_domain);
-   break;
-   case SCMI_PROTOCOL_ID_VOLTAGE_DOMAIN:
-   if (IS_ENABLED(CONFIG_DM_REGULATOR_SCMI)) {
-   node = ofnode_find_subnode(node, "regulators");
-   if (!ofnode_valid(node)) {
-   dev_err(dev, "no regulators node\n");
-   return -ENXIO;
-   }
-   drv = DM_DRIVER_GET(scmi_voltage_domain);
-   }
-   break;
-   default:
-   break;
-   }
-
-   if (!drv) {
-   dev_dbg(dev, "Ignore unsupported SCMI protocol %#x\n",
-   protocol_id);
-   continue;
-   }
-
-   ret = device_bind(dev, drv, name, NULL, node, NULL);
-   if (ret)
-   break;
-   }
-
-   return ret;
-}
-
 static struct udevice *find_scmi_protocol_device(struct udevice *dev)
 {
struct udevice *parent = NULL, *protocol;
@@ -216,6 +157,65 @@ int devm_scmi_process_msg(struct udevice *dev, struct 
scmi_msg *msg)
return scmi_process_msg(protocol->parent, priv->channel, msg);
 }
 
+/*
+ * SCMI agent devices binds devices of various uclasses depending on
+ * the FDT description. scmi_bind_protocol() is a generic bind sequence
+ * called by the uclass at bind stage, that is uclass post_bind.
+ */
+static int scmi_bind_protocols(struct udevice *dev)
+{
+   int ret = 0;
+   ofnode node;
+   const char *name;
+
+   dev_for_each_subnode(node, dev) {
+   struct driver *drv = NULL;
+   u32 protocol_id;
+
+   if (!ofnode_is_enabled(node))
+   continue;
+
+   if (ofnode_read_u32(node, "reg", _id))
+   continue;
+
+   name = ofnode_get_name(node);
+   switch (protocol_id) {
+   case SCMI_PROTOCOL_ID_CLOCK:
+   if (CONFIG_IS_ENABLED(CLK_SCMI))
+   drv = DM_DRIVER_GET(scmi_clock);
+   break;
+   case SCMI_PROTOCOL_ID_RESET_DOMAIN:
+   if (IS_ENABLED(CONFIG_RESET_SCMI))
+   drv = DM_DRIVER_GET(scmi_reset_domain);
+   break;
+   case SCMI_PROTOCOL_ID_VOLTAGE_DOMAIN:
+   if (IS_ENABLED(CONFIG_DM_REGULATOR_SCMI)) {
+   node = ofnode_find_subnode(node, "regulators");
+   if (!ofnode_valid(node)) {
+   dev_err(dev, "no regulators node\n");
+   return -ENXIO;
+   }
+   drv = DM_DRIVER_GET(scmi_voltage_domain);
+   }
+   break;
+   default:
+   break;
+   }
+
+   if (!drv) {
+  

[PATCH v4 02/13] firmware: scmi: implement SCMI base protocol

2023-09-12 Thread AKASHI Takahiro
SCMI base protocol is mandatory according to the SCMI specification.

With this patch, SCMI base protocol can be accessed via SCMI transport
layers. All the commands, except SCMI_BASE_NOTIFY_ERRORS, are supported.
This is because U-Boot doesn't support interrupts and the current transport
layers are not able to handle asynchronous messages properly.

Signed-off-by: AKASHI Takahiro 
Reviewed-by: Simon Glass 
---
v3
* strncpy (TODO)
* remove a duplicated function prototype
* use newly-allocated memory when return vendor name or agent name
* revise function descriptions in a header
v2
* add helper functions, removing direct uses of ops
* add function descriptions for each of functions in ops
---
 drivers/firmware/scmi/Makefile |   1 +
 drivers/firmware/scmi/base.c   | 656 +
 include/dm/uclass-id.h |   1 +
 include/scmi_protocols.h   | 351 ++
 4 files changed, 1009 insertions(+)
 create mode 100644 drivers/firmware/scmi/base.c

diff --git a/drivers/firmware/scmi/Makefile b/drivers/firmware/scmi/Makefile
index b2ff483c75a1..1a23d4981709 100644
--- a/drivers/firmware/scmi/Makefile
+++ b/drivers/firmware/scmi/Makefile
@@ -1,4 +1,5 @@
 obj-y  += scmi_agent-uclass.o
+obj-y  += base.o
 obj-y  += smt.o
 obj-$(CONFIG_SCMI_AGENT_SMCCC) += smccc_agent.o
 obj-$(CONFIG_SCMI_AGENT_MAILBOX)   += mailbox_agent.o
diff --git a/drivers/firmware/scmi/base.c b/drivers/firmware/scmi/base.c
new file mode 100644
index ..6b99f36d0697
--- /dev/null
+++ b/drivers/firmware/scmi/base.c
@@ -0,0 +1,656 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * SCMI Base protocol as U-Boot device
+ *
+ * Copyright (C) 2023 Linaro Limited
+ * author: AKASHI Takahiro 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/**
+ * scmi_generic_protocol_version - get protocol version
+ * @dev:   SCMI device
+ * @id:SCMI protocol ID
+ * @version:   Pointer to SCMI protocol version
+ *
+ * Obtain the protocol version number in @version.
+ *
+ * Return: 0 on success, error code otherwise
+ */
+int scmi_generic_protocol_version(struct udevice *dev,
+ enum scmi_std_protocol id, u32 *version)
+{
+   struct scmi_protocol_version_out out;
+   struct scmi_msg msg = {
+   .protocol_id = id,
+   .message_id = SCMI_PROTOCOL_VERSION,
+   .out_msg = (u8 *),
+   .out_msg_sz = sizeof(out),
+   };
+   int ret;
+
+   ret = devm_scmi_process_msg(dev, );
+   if (ret)
+   return ret;
+   if (out.status)
+   return scmi_to_linux_errno(out.status);
+
+   *version = out.version;
+
+   return 0;
+}
+
+/**
+ * scmi_base_protocol_version_int - get Base protocol version
+ * @dev:   SCMI device
+ * @version:   Pointer to SCMI protocol version
+ *
+ * Obtain the protocol version number in @version for Base protocol.
+ *
+ * Return: 0 on success, error code otherwise
+ */
+static int scmi_base_protocol_version_int(struct udevice *dev, u32 *version)
+{
+   return scmi_generic_protocol_version(dev, SCMI_PROTOCOL_ID_BASE,
+version);
+}
+
+/**
+ * scmi_protocol_attrs_int - get protocol attributes
+ * @dev:   SCMI device
+ * @num_agents:Number of SCMI agents
+ * @num_protocols: Number of SCMI protocols
+ *
+ * Obtain the protocol attributes, the number of agents and the number
+ * of protocols, in @num_agents and @num_protocols respectively, that
+ * the device provides.
+ *
+ * Return: 0 on success, error code otherwise
+ */
+static int scmi_protocol_attrs_int(struct udevice *dev, u32 *num_agents,
+  u32 *num_protocols)
+{
+   struct scmi_protocol_attrs_out out;
+   struct scmi_msg msg = {
+   .protocol_id = SCMI_PROTOCOL_ID_BASE,
+   .message_id = SCMI_PROTOCOL_ATTRIBUTES,
+   .out_msg = (u8 *),
+   .out_msg_sz = sizeof(out),
+   };
+   int ret;
+
+   ret = devm_scmi_process_msg(dev, );
+   if (ret)
+   return ret;
+   if (out.status)
+   return scmi_to_linux_errno(out.status);
+
+   *num_agents = SCMI_PROTOCOL_ATTRS_NUM_AGENTS(out.attributes);
+   *num_protocols = SCMI_PROTOCOL_ATTRS_NUM_PROTOCOLS(out.attributes);
+
+   return 0;
+}
+
+/**
+ * scmi_protocol_message_attrs_int - get message-specific attributes
+ * @dev:   SCMI device
+ * @message_id:SCMI message ID
+ * @attributes:Message-specific attributes
+ *
+ * Obtain the message-specific attributes in @attributes.
+ * This command succeeds if the message is implemented and available.
+ *
+ * Return: 0 on success, error code otherwise
+ */
+static int scmi_protocol_message_attrs_int(struct udevice *dev, u32 message_id,
+  

[PATCH v4 01/13] scmi: refactor the code to hide a channel from devices

2023-09-12 Thread AKASHI Takahiro
The commit 85dc58289238 ("firmware: scmi: prepare uclass to pass channel
reference") added an explicit parameter, channel, but it seems to make
the code complex.

Hiding this parameter will allow for adding a generic (protocol-agnostic)
helper function, i.e. for PROTOCOL_VERSION, in a later patch.

Signed-off-by: AKASHI Takahiro 
Reviewed-by: Simon Glass 
---
v4
* revive scmi_bind_protocols which was accidentally removed
* remove .per_child_auto from the driver declaration as it is not needed
v3
* fix an issue on ST board (reported by Etienne)
  by taking care of cases where probed devices are children of
  SCMI protocol device (i.e. clock devices under CCF)
  See find_scmi_protocol_device().
* move "per_device_plato_auto" to a succeeding right patch
v2
* new patch
---
 drivers/clk/clk_scmi.c|  27 ++
 drivers/firmware/scmi/scmi_agent-uclass.c | 105 --
 drivers/power/regulator/scmi_regulator.c  |  26 ++
 drivers/reset/reset-scmi.c|  19 +---
 include/scmi_agent.h  |  15 ++--
 5 files changed, 104 insertions(+), 88 deletions(-)

diff --git a/drivers/clk/clk_scmi.c b/drivers/clk/clk_scmi.c
index d172fed24c9d..34a49363a51a 100644
--- a/drivers/clk/clk_scmi.c
+++ b/drivers/clk/clk_scmi.c
@@ -13,17 +13,8 @@
 #include 
 #include 
 
-/**
- * struct scmi_clk_priv - Private data for SCMI clocks
- * @channel: Reference to the SCMI channel to use
- */
-struct scmi_clk_priv {
-   struct scmi_channel *channel;
-};
-
 static int scmi_clk_get_num_clock(struct udevice *dev, size_t *num_clocks)
 {
-   struct scmi_clk_priv *priv = dev_get_priv(dev);
struct scmi_clk_protocol_attr_out out;
struct scmi_msg msg = {
.protocol_id = SCMI_PROTOCOL_ID_CLOCK,
@@ -33,7 +24,7 @@ static int scmi_clk_get_num_clock(struct udevice *dev, size_t 
*num_clocks)
};
int ret;
 
-   ret = devm_scmi_process_msg(dev, priv->channel, );
+   ret = devm_scmi_process_msg(dev, );
if (ret)
return ret;
 
@@ -44,7 +35,6 @@ static int scmi_clk_get_num_clock(struct udevice *dev, size_t 
*num_clocks)
 
 static int scmi_clk_get_attibute(struct udevice *dev, int clkid, char **name)
 {
-   struct scmi_clk_priv *priv = dev_get_priv(dev);
struct scmi_clk_attribute_in in = {
.clock_id = clkid,
};
@@ -59,7 +49,7 @@ static int scmi_clk_get_attibute(struct udevice *dev, int 
clkid, char **name)
};
int ret;
 
-   ret = devm_scmi_process_msg(dev, priv->channel, );
+   ret = devm_scmi_process_msg(dev, );
if (ret)
return ret;
 
@@ -70,7 +60,6 @@ static int scmi_clk_get_attibute(struct udevice *dev, int 
clkid, char **name)
 
 static int scmi_clk_gate(struct clk *clk, int enable)
 {
-   struct scmi_clk_priv *priv = dev_get_priv(clk->dev);
struct scmi_clk_state_in in = {
.clock_id = clk->id,
.attributes = enable,
@@ -81,7 +70,7 @@ static int scmi_clk_gate(struct clk *clk, int enable)
  in, out);
int ret;
 
-   ret = devm_scmi_process_msg(clk->dev, priv->channel, );
+   ret = devm_scmi_process_msg(clk->dev, );
if (ret)
return ret;
 
@@ -100,7 +89,6 @@ static int scmi_clk_disable(struct clk *clk)
 
 static ulong scmi_clk_get_rate(struct clk *clk)
 {
-   struct scmi_clk_priv *priv = dev_get_priv(clk->dev);
struct scmi_clk_rate_get_in in = {
.clock_id = clk->id,
};
@@ -110,7 +98,7 @@ static ulong scmi_clk_get_rate(struct clk *clk)
  in, out);
int ret;
 
-   ret = devm_scmi_process_msg(clk->dev, priv->channel, );
+   ret = devm_scmi_process_msg(clk->dev, );
if (ret < 0)
return ret;
 
@@ -123,7 +111,6 @@ static ulong scmi_clk_get_rate(struct clk *clk)
 
 static ulong scmi_clk_set_rate(struct clk *clk, ulong rate)
 {
-   struct scmi_clk_priv *priv = dev_get_priv(clk->dev);
struct scmi_clk_rate_set_in in = {
.clock_id = clk->id,
.flags = SCMI_CLK_RATE_ROUND_CLOSEST,
@@ -136,7 +123,7 @@ static ulong scmi_clk_set_rate(struct clk *clk, ulong rate)
  in, out);
int ret;
 
-   ret = devm_scmi_process_msg(clk->dev, priv->channel, );
+   ret = devm_scmi_process_msg(clk->dev, );
if (ret < 0)
return ret;
 
@@ -149,12 +136,11 @@ static ulong scmi_clk_set_rate(struct clk *clk, ulong 
rate)
 
 static int scmi_clk_probe(struct udevice *dev)
 {
-   struct scmi_clk_priv *priv = dev_get_priv(dev);
struct clk *clk;
size_t num_clocks, i;
int ret;
 
-   ret = devm_scmi_of_get_channel(dev, >channel);
+   ret = devm_scmi_of_get_channel(dev);
if (ret)
return ret;
 
@@ -205,5 +191,4 @@ U_BOOT_DRIVER(scmi_clock) = {
.id = UCLASS_CLK,
 

[PATCH v4 00/13] firmware: scmi: add SCMI base protocol support

2023-09-12 Thread AKASHI Takahiro
This patch series allows users to access SCMI base protocol provided by
SCMI server (platform). It will also be utilized in separate patches
in the future to add sanity/validity checks for other protocols.
See SCMI specification document v3.2 beta[1] for more details about SCMI
base protocol.

What is currently not implemented is
- SCMI_BASE_NOTIFY_ERRORS command and notification callback mechanism

This feature won't be very useful in the current U-Boot environment.

[1] https://developer.arm.com/documentation/den0056/e/?lang=en


Test

The patch series was tested on the following platforms:
* sandbox
* qemu-arm64 with OPTEE as SCMI server


Prerequisite:
=
* This patch series is based on v2023.10-rc4.


Patches:

Patch#1-#4,#7-#8: Add SCMI base protocol driver
Patch#5-#6,#9-#10: Add SCMI base protocol device unit test
Patch#11-#13: Add scmi command


Change history:
===
v4 (Sep 12, 2023)
* shuffle the patch order (patch#5,6 prior to patch#7)
* several improvements/cleanup thanks to Etienne
  (Each commit message has more details.)

v3 (Sep 8, 2023)
* import patch#6 (protocol availability check) from my followup patch
* fix an issue on ST board (reported by Etienne) (patch#1)
* minor code improvements
* fix various typos pointed out by Etienne
* revise function descriptions/comments 
  (Each commit message has more details.)

v2 (Jul, 26, 2023)
* refactor devm_scmi_of_get_channel()/process_msg(), removing uses of ops
  (patch#1)
* use helper functions, removing uses of ops (patch#2,#9,#10)
* add more descriptions in scmi command doc (patch#11)
* remove 'scmi base' sub-command (patch#10,#12)

v1 (Jun, 28, 2023)
* initial release

AKASHI Takahiro (13):
  scmi: refactor the code to hide a channel from devices
  firmware: scmi: implement SCMI base protocol
  firmware: scmi: move scmi_bind_protocols() backward
  firmware: scmi: framework for installing additional protocols
  firmware: scmi: fake base protocol commands on sandbox
  test: dm: simplify SCMI unit test on sandbox
  firmware: scmi: install base protocol to SCMI agent
  firmware: scmi: add a check against availability of protocols
  sandbox: remove SCMI base node definition from test.dts
  test: dm: add SCMI base protocol test
  cmd: add scmi command for SCMI firmware
  doc: cmd: add documentation for scmi
  test: dm: add scmi command test

 arch/sandbox/dts/test.dts  |   4 -
 arch/sandbox/include/asm/scmi_test.h   |   7 +-
 cmd/Kconfig|   9 +
 cmd/Makefile   |   1 +
 cmd/scmi.c | 337 +++
 configs/sandbox_defconfig  |   1 +
 doc/usage/cmd/scmi.rst | 126 
 drivers/clk/clk_scmi.c |  27 +-
 drivers/firmware/scmi/Makefile |   1 +
 drivers/firmware/scmi/base.c   | 656 +
 drivers/firmware/scmi/sandbox-scmi_agent.c | 379 +++-
 drivers/firmware/scmi/scmi_agent-uclass.c  | 411 +++--
 drivers/power/regulator/scmi_regulator.c   |  26 +-
 drivers/reset/reset-scmi.c |  19 +-
 include/dm/uclass-id.h |   1 +
 include/scmi_agent-uclass.h|  81 ++-
 include/scmi_agent.h   |  29 +-
 include/scmi_protocols.h   | 351 +++
 test/dm/scmi.c | 228 +--
 19 files changed, 2500 insertions(+), 194 deletions(-)
 create mode 100644 cmd/scmi.c
 create mode 100644 doc/usage/cmd/scmi.rst
 create mode 100644 drivers/firmware/scmi/base.c

-- 
2.34.1



Re: [RFC PATCH 0/5] Allow for removal of DT nodes and properties

2023-09-12 Thread Ilias Apalodimas
Hi Tom,

[...]

> > > > > > > > > I don't think they should be in DT at all, they don't describe
> > > > > > > > > anything to do with hardware, or generally even the runtime 
> > > > > > > > > of a
> > > > > > > > > device, they don't even describe the boot/runtime state of the
> > > > > > > > > firmware, they describe build time, so I don't see what that 
> > > > > > > > > has to do
> > > > > > > > > with device tree? Can you explain that? To me those sorts of 
> > > > > > > > > things
> > > > > > > > > should live in a build time style config file.
> > > > > > >
> > > > > > > For the record, I tend to agree.
> > > > > > >
> > > > > >
> > > > > > +1
> > > > > >
> > > > > > > > I beg to differ. Devicetree is more than just hardware and 
> > > > > > > > always has
> > > > > > > > been. See, for example the /chosen and /options nodes.
> > > > > > >
> > > > > > > There are exceptions...
> > > > > > >
> > > > > >
> > > > > > We've been this over and over again and frankly it gets a bit 
> > > > > > annoying.
> > > > > > It's called *DEVICE* tree for a reason.  As Rob pointed out there 
> > > > > > are
> > > > > > exceptions, but those made a lot of sense.  Having arbitrary 
> > > > > > internal ABI
> > > > > > stuff of various projects in the schema just defeats the definition 
> > > > > > of a
> > > > > > spec.
> > > > >
> > > > > Our efforts should not just be about internal ABI, but working to
> > > > > provide a consistent configuration system for all firmware elements.
> > > >
> > > > And that's what the firmware handoff was all about.
> > > > I get what you are trying to do here.  I am just aware of any other
> > >
> > > "just not aware" did you mean?
> >
> > Yep, sorry!
> >
> > >
> > > > project apart from U-Boot which uses DT for it's own configuration.
> > > > So trying to standardize some bindings that are useful to all projects
> > > > that use DT is fine. Trying to *enforce* them to use it for config
> > > > isn't IMHO.
> > > >
> > > > >
> > > > > We cannot have it both ways, i.e. refusing to accept non-hardware
> > > > > bindings and then complaining that U-Boot does not pass schema
> > > > > validation. Devicetree should be a shared resource, not just for the
> > > > > use of Linux.
> > > >
> > > > It's not for the use of Linux, I've wasted enough time repeating that
> > > > and so has Rob.  Please go back to previous emails and read the
> > > > arguments.
> > >
> > > Right, it's not just for Linux, but Linux is where most of the
> > > exceptions to the "ONLY HARDWARE" rule got in, because they also make
> > > sense.
> >
> > Exactly.
> >
> > > And the overarching point Simon keeps trying to make I believe
> > > can be boiled down to that too.  There are things that one does not have
> > > a (reasonable) choice about how to do things with when interacting with
> > > the hunk of melted sand on your desk and that information needs to go
> > > somewhere.
> >
> > DT is a big hammer indeed, but that doesn't mean we always need to use
> > it.  I never disagreed with adding nodes that make sense and will be
> > useful for others. For example, the internal Driver model
> > configuration options used to enable a device early etc etc are
> > probably useful to more projects.  On the other hand, if U-Boot is
> > indeed the only project using DT for its internal configuration why
> > should we care?
> >
> > For example, let's imagine you build TF-A, and TF-A is configured and
> > bundled with a device tree that gets passed along to U-Boot (using
> > OF_BOARD).  Why on earth should TF-A be aware of internal DM
> > implementation details and build a device tree containing
> > u-boot,dm-pre-reloc, u-boot,dm-spl, dm-tpl, and every other
> > non-upstreamed nodes we have?
>
> I don't think this is a clear example, sorry.  "dm-pre-reloc" etc are
> the bootph things now that you say could be useful.  So they're an
> example of how (now that things are more receptive) we need to look at
> what U-Boot has that doesn't pass validation and see "does this make
> sense, today" or not.
>

The point here is a bit different though.  We need this in U-Boot *because*
we use the DT to configure things.  They are useful information, but unless
another bootloader uses the same config method, U-Boot is the only consumer.

If we could split those nodes in an internal u-boot .dtsi file that would
be much much cleaner.  But IIRC we'll have problems with patching DTs in
TPL/SPL with limited memory.

> I guess I'm confused as to why it's a theoretical problem for TF-A to
> pass along /binman/ but not a problem to pass along
> /soc/.../snvs/.../linux,snvs_pwrkey on i.MX8.  _Sometimes_ internals

It's the same problem and I don't think it's ok for TF-A to pass those as
either.

> just need to be there.  That also does not mean every single should be
> there.
>

> > Another example would be the public key that we shoehorn on the DT.
> > In commit ddf67daac39d ("efi_capsule: Move signature from DTB to
> > .rodata") I tried to get rid of