Re: [PATCH] fixdep: fix CONFIG_IS_ENABLED etc. handling

2020-07-17 Thread Masahiro Yamada
On Thu, Jul 9, 2020 at 6:53 AM Stephen Warren  wrote:
>
> From: Stephen Warren 
>
> When fixdep detects CONFIG_IS_ENABLED and other similar macros, it must
> parse the macro parameter to determine which actual CONFIG_ option is
> being referenced. This involves moving a pointer forward through the
> entire CONFIG_ option "word". Currently, the code uses variable q to walk
> through the word, but doesn't actually initialize it to point at the
> parameter before doing so. Consequently, the walking process immediately
> fails since it sees the macro invocatoins's ( rather than the expected
> alpha-numeric characters in the macro parameter. Fix this by adding the
> missing initialization.
>
> Fixes: 67f2ee86ccbe ("kbuild: fixdep: Resync this with v4.17")
> Fixes: 7012865e961c ("gpio: fix test.py for gpio label lookup")
> Signed-off-by: Stephen Warren 
> ---
>  scripts/basic/fixdep.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
> index 24be244d5e6a..958668df5546 100644
> --- a/scripts/basic/fixdep.c
> +++ b/scripts/basic/fixdep.c
> @@ -266,6 +266,7 @@ static void parse_config_file(const char *p)
> (q - p == 9 && !memcmp(p, "IS_MODULE(", 10)) ||
> (q - p == 3 && !memcmp(p, "VAL(", 4))) {
> p = q + 1;
> +   q  = p;
> while (isalnum(*q) || *q == '_')
> q++;
> r = q;
> --
> 2.25.1
>


Sorry, I missed this patch.
Yes, this fixes the bug. Thanks.


Just a nit about the coding style:
There are two spaces after 'q'.




-- 
Best Regards
Masahiro Yamada


Re: [PATCH v3 4/6] rock-pi-4: Enable HDMI output

2020-07-17 Thread Kever Yang



On 2020/7/7 下午9:50, Jagan Teki wrote:

Enable config options to get HDMI output on RockPI-4 boards.

Signed-off-by: Jagan Teki 

Reviewed-by: Kever Yang

Thanks,
- Kever

---
Changes for v3:
- fix configs

  configs/rock-pi-4-rk3399_defconfig | 5 +
  1 file changed, 5 insertions(+)

diff --git a/configs/rock-pi-4-rk3399_defconfig 
b/configs/rock-pi-4-rk3399_defconfig
index a4b322074c..98f71a50a5 100644
--- a/configs/rock-pi-4-rk3399_defconfig
+++ b/configs/rock-pi-4-rk3399_defconfig
@@ -58,6 +58,7 @@ CONFIG_USB_EHCI_HCD=y
  CONFIG_USB_EHCI_GENERIC=y
  CONFIG_USB_DWC3=y
  CONFIG_USB_DWC3_GENERIC=y
+CONFIG_USB_KEYBOARD=y
  CONFIG_USB_GADGET=y
  CONFIG_USB_HOST_ETHER=y
  CONFIG_USB_ETHER_ASIX=y
@@ -65,5 +66,9 @@ CONFIG_USB_ETHER_ASIX88179=y
  CONFIG_USB_ETHER_MCS7830=y
  CONFIG_USB_ETHER_RTL8152=y
  CONFIG_USB_ETHER_SMSC95XX=y
+CONFIG_DM_VIDEO=y
+CONFIG_DISPLAY=y
+CONFIG_VIDEO_ROCKCHIP=y
+CONFIG_DISPLAY_ROCKCHIP_HDMI=y
  CONFIG_SPL_TINY_MEMSET=y
  CONFIG_ERRNO_STR=y





Re: [PATCH v3 6/6] roc-rk3399-pc: Update ENV offset, size

2020-07-17 Thread Kever Yang



On 2020/7/7 下午9:50, Jagan Teki wrote:

Adjust the ENV offset, size to fit into all images
on 16MB flash.

Signed-off-by: Jagan Teki 

Reviewed-by: Kever Yang

Thanks,
- Kever

---
Changes for v3:
- fix configs

  configs/roc-pc-mezzanine-rk3399_defconfig | 4 ++--
  configs/roc-pc-rk3399_defconfig   | 4 ++--
  2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/configs/roc-pc-mezzanine-rk3399_defconfig 
b/configs/roc-pc-mezzanine-rk3399_defconfig
index b2c370cc59..f15dddc684 100644
--- a/configs/roc-pc-mezzanine-rk3399_defconfig
+++ b/configs/roc-pc-mezzanine-rk3399_defconfig
@@ -1,8 +1,8 @@
  CONFIG_ARM=y
  CONFIG_ARCH_ROCKCHIP=y
  CONFIG_SYS_TEXT_BASE=0x0020
-CONFIG_ENV_SIZE=0x6000
-CONFIG_ENV_OFFSET=0x46
+CONFIG_ENV_SIZE=0x8000
+CONFIG_ENV_OFFSET=0x3F8000
  CONFIG_ENV_SECT_SIZE=0x1000
  CONFIG_SPL_DM_SPI=y
  CONFIG_ROCKCHIP_RK3399=y
diff --git a/configs/roc-pc-rk3399_defconfig b/configs/roc-pc-rk3399_defconfig
index 588d03952a..9ffde7f960 100644
--- a/configs/roc-pc-rk3399_defconfig
+++ b/configs/roc-pc-rk3399_defconfig
@@ -1,8 +1,8 @@
  CONFIG_ARM=y
  CONFIG_ARCH_ROCKCHIP=y
  CONFIG_SYS_TEXT_BASE=0x0020
-CONFIG_ENV_SIZE=0x6000
-CONFIG_ENV_OFFSET=0x46
+CONFIG_ENV_SIZE=0x8000
+CONFIG_ENV_OFFSET=0x3F8000
  CONFIG_ENV_SECT_SIZE=0x1000
  CONFIG_SPL_DM_SPI=y
  CONFIG_ROCKCHIP_RK3399=y





[PATCH v2 2/3] test: vboot: add tests for multiple required keys

2020-07-17 Thread Thirupathaiah Annapureddy
This patch adds vboot tests to verify the support for multiple
required keys using new required-mode DTB policy.

This patch also fixes existing test where dev
key is assumed to be marked as not required, although
it is marked as required.

Note that this patch re-added sign_fit_norequire().
sign_fit_norequire() was removed as part of the commit:
b008677daf2a9dc0335260c7c4e24390487fe0ca
(test: vboot: Fix pylint errors)
This patch leverages sign_fit_norequire() to fix the
existing bug.

Signed-off-by: Thirupathaiah Annapureddy 
---

Changes in v2:
- Added tests to cover any or all required keys policy.

 test/py/tests/test_vboot.py | 46 +++--
 1 file changed, 44 insertions(+), 2 deletions(-)

diff --git a/test/py/tests/test_vboot.py b/test/py/tests/test_vboot.py
index 6b998cfd70..e45800d94c 100644
--- a/test/py/tests/test_vboot.py
+++ b/test/py/tests/test_vboot.py
@@ -126,6 +126,23 @@ def test_vboot(u_boot_console, sha_algo, padding, 
sign_options, required):
 cons.log.action('%s: Sign images' % sha_algo)
 util.run_and_log(cons, args)
 
+def sign_fit_norequire(sha_algo, options):
+"""Sign the FIT
+
+Signs the FIT and writes the signature into it. It also writes the
+public key into the dtb. It does not mark key as 'required' in dtb.
+
+Args:
+sha_algo: Either 'sha1' or 'sha256', to select the algorithm to
+use.
+options: Options to provide to mkimage.
+"""
+args = [mkimage, '-F', '-k', tmpdir, '-K', dtb, fit]
+if options:
+args += options.split(' ')
+cons.log.action('%s: Sign images' % sha_algo)
+util.run_and_log(cons, args)
+
 def replace_fit_totalsize(size):
 """Replace FIT header's totalsize with something greater.
 
@@ -279,15 +296,40 @@ def test_vboot(u_boot_console, sha_algo, padding, 
sign_options, required):
 # Build the FIT with dev key (keys NOT required). This adds the
 # signature into sandbox-u-boot.dtb, NOT marked 'required'.
 make_fit('sign-configs-%s%s.its' % (sha_algo, padding))
-sign_fit(sha_algo, sign_options)
+sign_fit_norequire(sha_algo, sign_options)
 
 # So now sandbox-u-boot.dtb two signatures, for the prod and dev keys.
 # Only the prod key is set as 'required'. But FIT we just built has
-# a dev signature only (sign_fit() overwrites the FIT).
+# a dev signature only (sign_fit_norequire() overwrites the FIT).
 # Try to boot the FIT with dev key. This FIT should not be accepted by
 # U-Boot because the prod key is required.
 run_bootm(sha_algo, 'required key', '', False)
 
+# Build the FIT with dev key (keys required) and sign it. This puts the
+# signature into sandbox-u-boot.dtb, marked 'required'.
+make_fit('sign-configs-%s%s.its' % (sha_algo, padding))
+sign_fit(sha_algo, sign_options)
+
+# Set the required-mode policy to "any".
+# So now sandbox-u-boot.dtb two signatures, for the prod and dev keys.
+# Both the dev and prod key are set as 'required'. But FIT we just 
built has
+# a dev signature only (sign_fit() overwrites the FIT).
+# Try to boot the FIT with dev key. This FIT should be accepted by
+# U-Boot because the dev key is required and policy is "any" required 
key.
+util.run_and_log(cons, 'fdtput -t s %s /signature required-mode any' %
+ (dtb))
+run_bootm(sha_algo, 'multi required key', 'dev+', True)
+
+# Set the required-mode policy to "all".
+# So now sandbox-u-boot.dtb two signatures, for the prod and dev keys.
+# Both the dev and prod key are set as 'required'. But FIT we just 
built has
+# a dev signature only (sign_fit() overwrites the FIT).
+# Try to boot the FIT with dev key. This FIT should not be accepted by
+# U-Boot because the prod key is required and policy is "all" required 
key
+util.run_and_log(cons, 'fdtput -t s %s /signature required-mode all' %
+ (dtb))
+run_bootm(sha_algo, 'multi required key', '', False)
+
 cons = u_boot_console
 tmpdir = cons.config.result_dir + '/'
 datadir = cons.config.source_dir + '/test/py/tests/vboot/'
-- 
2.25.2



[PATCH v2 3/3] doc: verified-boot: add required-mode information

2020-07-17 Thread Thirupathaiah Annapureddy
Signed-off-by: Thirupathaiah Annapureddy 
---

Changes in v2:
- New

 doc/uImage.FIT/signature.txt | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/doc/uImage.FIT/signature.txt b/doc/uImage.FIT/signature.txt
index d4afd755e9..a3455889ed 100644
--- a/doc/uImage.FIT/signature.txt
+++ b/doc/uImage.FIT/signature.txt
@@ -386,6 +386,20 @@ that might be used by the target needs to be signed with 
'required' keys.
 
 This happens automatically as part of a bootm command when FITs are used.
 
+For Signed Configurations, the default verification behavior can be changed by
+the following optional property in /signature node in U-Boot's control FDT.
+
+- required-mode: Valid values are "any" to allow verified boot to succeed if
+the selected configuration is signed by any of the 'required' keys, and "all"
+to allow verified boot to succeed if the selected configuration is signed by
+all of the 'required' keys.
+
+This property can be added to a binary device tree using fdtput as shown in
+below examples::
+
+   fdtput -t s control.dtb /signature required-mode any
+   fdtput -t s control.dtb /signature required-mode all
+
 
 Enabling FIT Verification
 -
-- 
2.25.2



[PATCH v2 0/3] Add support for multiple required keys

2020-07-17 Thread Thirupathaiah Annapureddy
This patch series adds the support for multiple required keys
in U-Boot DTB with test support.

Changes in v2 (thanks for the feedback Simon and Rasmus):
- Introduce a policy variable in U-boot DTB to control whether any or all
required keys must have signed configuration.
- Added tests to cover any or all required keys policy. 
- Updated signature.txt to include required-mode policy information.

Thirupathaiah Annapureddy (3):
  vboot: add DTB policy for supporting multiple required conf keys
  test: vboot: add tests for multiple required keys
  doc: verified-boot: add required-mode information

 common/image-fit-sig.c   | 30 ---
 doc/uImage.FIT/signature.txt | 14 +++
 test/py/tests/test_vboot.py  | 46 ++--
 3 files changed, 85 insertions(+), 5 deletions(-)

-- 
2.25.2



[PATCH v2 1/3] vboot: add DTB policy for supporting multiple required conf keys

2020-07-17 Thread Thirupathaiah Annapureddy
Currently FIT image must be signed by all required conf keys. This means
Verified Boot fails if there is a signature verification failure
using any required key in U-boot DTB.

This patch introduces a new policy in DTB that can be set to any required
conf key. This means if verified boot passes with one of the required
keys, u-boot will continue the OS hand off.

There were prior attempts to address this:
https://lists.denx.de/pipermail/u-boot/2019-April/366047.html
The above patch was failing "make tests".
https://lists.denx.de/pipermail/u-boot/2020-January/396629.html

Signed-off-by: Thirupathaiah Annapureddy 
---

Changes in v2:
- Modify fit_config_verify_required_sigs() to process required-mode
policy variable in U-boot DTB.

 common/image-fit-sig.c | 30 +++---
 1 file changed, 27 insertions(+), 3 deletions(-)

diff --git a/common/image-fit-sig.c b/common/image-fit-sig.c
index cc1967109e..d9b1c93a9b 100644
--- a/common/image-fit-sig.c
+++ b/common/image-fit-sig.c
@@ -416,6 +416,10 @@ int fit_config_verify_required_sigs(const void *fit, int 
conf_noffset,
 {
int noffset;
int sig_node;
+   int verified = 0;
+   int reqd_sigs = 0;
+   bool reqd_policy_all = true;
+   const char *reqd_mode;
 
/* Work out what we need to verify */
sig_node = fdt_subnode_offset(sig_blob, 0, FIT_SIG_NODENAME);
@@ -425,6 +429,14 @@ int fit_config_verify_required_sigs(const void *fit, int 
conf_noffset,
return 0;
}
 
+   /* Get required-mode policy property from DTB */
+   reqd_mode = fdt_getprop(sig_blob, sig_node, "required-mode", NULL);
+   if (reqd_mode && !strcmp(reqd_mode, "any"))
+   reqd_policy_all = false;
+
+   debug("%s: required-mode policy set to '%s'\n", __func__,
+ reqd_policy_all ? "all" : "any");
+
fdt_for_each_subnode(noffset, sig_blob, sig_node) {
const char *required;
int ret;
@@ -433,15 +445,27 @@ int fit_config_verify_required_sigs(const void *fit, int 
conf_noffset,
   NULL);
if (!required || strcmp(required, "conf"))
continue;
+
+   reqd_sigs++;
+
ret = fit_config_verify_sig(fit, conf_noffset, sig_blob,
noffset);
if (ret) {
-   printf("Failed to verify required signature '%s'\n",
-  fit_get_name(sig_blob, noffset, NULL));
-   return ret;
+   if (reqd_policy_all) {
+   printf("Failed to verify required signature 
'%s'\n",
+  fit_get_name(sig_blob, noffset, NULL));
+   return ret;
+   }
+   } else {
+   verified++;
+   if (!reqd_policy_all)
+   break;
}
}
 
+   if (reqd_sigs && !verified)
+   return -EPERM;
+
return 0;
 }
 
-- 
2.25.2



Re: [PATCH v2 1/2] rockchip: Add SoC detection helper

2020-07-17 Thread Kever Yang



On 2020/7/8 下午6:29, Jagan Teki wrote:

On Wed, Jul 8, 2020 at 3:43 PM Kever Yang  wrote:

Hi Jagan,


  This is all for rk3288, please just put it into rk3288.c instead of
make a new cpu.h.

Yes, I have used cpu.h since rk3308 also has revision, if not to
consider than I will move to rk3288 specific.


Please do it, thanks.


Kever



Jagan.







Re: [PATCH] rockchip: sdram: fix dram_init_banksize

2020-07-17 Thread Kever Yang

Hi Alex,

Tanks for your fix.

On 2020/7/15 上午7:03, Alex Bee wrote:

Currently 2.5 GB is calculated as DRAM size for a 1 GB RK322x board
if CONFIG_SPL_OPTEE is set. This is troublesome when booting a
linux kernel since this size will be injected in FDT of the kernel.

gd->bd->bi_dram[0].start (which is basically CONFIG_SYS_SDRAM_BASE)
must not be taken into consideration for calculation of second bank
size, since this offset is already included in calculation of "top".

After applying this patch 992 MB (1024 MB - 32 MB reserved for
optee-os) is correctly calculated and has also been verified on
2 GB boards.

Signed-off-by: Alex Bee 

Reviewed-by: Kever Yang

Thanks,
- Kever

---
  arch/arm/mach-rockchip/sdram.c | 6 ++
  1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/arch/arm/mach-rockchip/sdram.c b/arch/arm/mach-rockchip/sdram.c
index 24fe6cc8f0..4c637b7767 100644
--- a/arch/arm/mach-rockchip/sdram.c
+++ b/arch/arm/mach-rockchip/sdram.c
@@ -56,16 +56,14 @@ int dram_init_banksize(void)
- CONFIG_SYS_SDRAM_BASE;
gd->bd->bi_dram[1].start = tos_parameter->tee_mem.phy_addr +
tos_parameter->tee_mem.size;
-   gd->bd->bi_dram[1].size = gd->bd->bi_dram[0].start
-   + top - gd->bd->bi_dram[1].start;
+   gd->bd->bi_dram[1].size = top - gd->bd->bi_dram[1].start;
} else {
gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
gd->bd->bi_dram[0].size = 0x840;
/* Reserve 32M for OPTEE with TA */
gd->bd->bi_dram[1].start = CONFIG_SYS_SDRAM_BASE
+ gd->bd->bi_dram[0].size + 0x200;
-   gd->bd->bi_dram[1].size = gd->bd->bi_dram[0].start
-   + top - gd->bd->bi_dram[1].start;
+   gd->bd->bi_dram[1].size = top - gd->bd->bi_dram[1].start;
}
  #else
gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;





Re: [PATCH 2/2] configs: rock64-rk3328_defconfig: Add SPI Flash support

2020-07-17 Thread Kever Yang



On 2020/7/9 上午6:50, Johannes Krottmayer wrote:

Add U-Boot SPI Flash support for the PINE64 Rock64 board

Signed-off-by: Johannes Krottmayer 
Cc: Matwey V. Kornilov 

Reviewed-by: Kever Yang

Thanks,
- Kever

---
  configs/rock64-rk3328_defconfig | 2 ++
  1 file changed, 2 insertions(+)

diff --git a/configs/rock64-rk3328_defconfig b/configs/rock64-rk3328_defconfig
index f123826358..0a51e51a0c 100644
--- a/configs/rock64-rk3328_defconfig
+++ b/configs/rock64-rk3328_defconfig
@@ -97,3 +97,5 @@ CONFIG_SPL_TINY_MEMSET=y
  CONFIG_TPL_TINY_MEMSET=y
  CONFIG_ERRNO_STR=y
  CONFIG_SMBIOS_MANUFACTURER="pine64"
+CONFIG_ROCKCHIP_SPI=y
+CONFIG_SPI_FLASH_GIGADEVICE=y





Re: [PATCH 1/2] ARM: dts: rk3328-rock64: Add SPI Flash support

2020-07-17 Thread Kever Yang



On 2020/7/9 上午6:50, Johannes Krottmayer wrote:

Add U-Boot SPI Flash support for the PINE64 Rock64 board

Signed-off-by: Johannes Krottmayer 
Cc: Matwey V. Kornilov 

Reviewed-by: Kever Yang

Thanks,
- Kever

---
  arch/arm/dts/rk3328-rock64-u-boot.dtsi | 6 ++
  1 file changed, 6 insertions(+)

diff --git a/arch/arm/dts/rk3328-rock64-u-boot.dtsi 
b/arch/arm/dts/rk3328-rock64-u-boot.dtsi
index f076075076..7340ef95f1 100644
--- a/arch/arm/dts/rk3328-rock64-u-boot.dtsi
+++ b/arch/arm/dts/rk3328-rock64-u-boot.dtsi
@@ -46,3 +46,9 @@
  _sd {
u-boot,dm-spl;
  };
+
+ {
+   spi_flash: spiflash@0 {
+   u-boot,dm-pre-reloc;
+   };
+};





Re: [PATCH 2/3] drivers: spi: rk_spi: Add support for RK3328

2020-07-17 Thread Kever Yang



On 2020/7/9 上午5:57, Johannes Krottmayer wrote:

Add support for the RK3328 SPI controller

Signed-off-by: Johannes Krottmayer 
Cc: Kever Yang 
Cc: Jagan Teki 

Reviewed-by: Kever Yang

Thanks,
- Kever

---
I don't know if "rk3399_spi_params" is also required for the
RK3328 SPI controller.

Probing, Reading, Writing and Erasing of a flash device works
with the SF command. Tested it with the PINE64 Rock64 board.

  drivers/spi/rk_spi.c | 2 ++
  1 file changed, 2 insertions(+)

diff --git a/drivers/spi/rk_spi.c b/drivers/spi/rk_spi.c
index 833cb04922..0495e04945 100644
--- a/drivers/spi/rk_spi.c
+++ b/drivers/spi/rk_spi.c
@@ -545,7 +545,9 @@ const  struct rockchip_spi_params rk3399_spi_params = {
  };
  
  static const struct udevice_id rockchip_spi_ids[] = {

+   { .compatible = "rockchip,rk3066-spi" },
{ .compatible = "rockchip,rk3288-spi" },
+   { .compatible = "rockchip,rk3328-spi" },
{ .compatible = "rockchip,rk3368-spi",
  .data = (ulong)_spi_params },
{ .compatible = "rockchip,rk3399-spi",





Re: [PATCH 3/3] ARM: dts: rk3328: Add SPI support

2020-07-17 Thread Kever Yang



On 2020/7/9 上午5:57, Johannes Krottmayer wrote:

Add U-Boot SPI support for the RK3328

Signed-off-by: Johannes Krottmayer 
Cc: Kever Yang 
Cc: Jagan Teki 

Reviewed-by: Kever Yang

Thanks,
- Kever

---
  arch/arm/dts/rk3328-u-boot.dtsi | 5 +
  1 file changed, 5 insertions(+)

diff --git a/arch/arm/dts/rk3328-u-boot.dtsi b/arch/arm/dts/rk3328-u-boot.dtsi
index c69e13e11e..c980daae99 100644
--- a/arch/arm/dts/rk3328-u-boot.dtsi
+++ b/arch/arm/dts/rk3328-u-boot.dtsi
@@ -7,6 +7,7 @@
aliases {
mmc0 = 
mmc1 = 
+   spi0 = 
};
  
  	chosen {

@@ -66,3 +67,7 @@
  _otg {
hnp-srp-disable;
  };
+
+ {
+   u-boot,dm-pre-reloc;
+};





Re: [PATCH 1/3] drivers: clk: rockchip: clk_rk3328: Add SPI support

2020-07-17 Thread Kever Yang



On 2020/7/9 上午5:57, Johannes Krottmayer wrote:

Add SPI support for the RK3328 clock driver

Signed-off-by: Johannes Krottmayer 
Cc: Kever Yang 
Cc: Jagan Teki 

Reviewed-by: Kever Yang

Thanks,
- Kever

---
  drivers/clk/rockchip/clk_rk3328.c | 31 +++
  1 file changed, 31 insertions(+)

diff --git a/drivers/clk/rockchip/clk_rk3328.c 
b/drivers/clk/rockchip/clk_rk3328.c
index 02d3b08efa..bf4f1069ea 100644
--- a/drivers/clk/rockchip/clk_rk3328.c
+++ b/drivers/clk/rockchip/clk_rk3328.c
@@ -555,6 +555,31 @@ static ulong rk3328_saradc_set_clk(struct rk3328_cru *cru, 
uint hz)
return rk3328_saradc_get_clk(cru);
  }
  
+static ulong rk3328_spi_get_clk(struct rk3328_cru *cru)

+{
+   u32 div, val;
+
+   val = readl(>clksel_con[24]);
+   div = (val & CLK_SPI_DIV_CON_MASK) >> CLK_SPI_DIV_CON_SHIFT;
+
+   return DIV_TO_RATE(OSC_HZ, div);
+}
+
+static ulong rk3328_spi_set_clk(struct rk3328_cru *cru, uint hz)
+{
+   u32 src_clk_div;
+
+   src_clk_div = GPLL_HZ / hz;
+   assert(src_clk_div < 128);
+
+   rk_clrsetreg(>clksel_con[24],
+CLK_PWM_PLL_SEL_MASK | CLK_PWM_DIV_CON_MASK,
+CLK_PWM_PLL_SEL_GPLL << CLK_PWM_PLL_SEL_SHIFT |
+(src_clk_div - 1) << CLK_PWM_DIV_CON_SHIFT);
+
+   return rk3328_spi_get_clk(cru);
+}
+
  static ulong rk3328_clk_get_rate(struct clk *clk)
  {
struct rk3328_clk_priv *priv = dev_get_priv(clk->dev);
@@ -581,6 +606,9 @@ static ulong rk3328_clk_get_rate(struct clk *clk)
case SCLK_SARADC:
rate = rk3328_saradc_get_clk(priv->cru);
break;
+   case SCLK_SPI:
+   rate = rk3328_spi_get_clk(priv->cru);
+   break;
default:
return -ENOENT;
}
@@ -617,6 +645,9 @@ static ulong rk3328_clk_set_rate(struct clk *clk, ulong 
rate)
case SCLK_SARADC:
ret = rk3328_saradc_set_clk(priv->cru, rate);
break;
+   case SCLK_SPI:
+   ret = rk3328_spi_set_clk(priv->cru, rate);
+   break;
case DCLK_LCDC:
case SCLK_PDM:
case SCLK_RTC32K:





[PATCH 6/6] stdio: Tidy up the coding style

2020-07-17 Thread Simon Glass
Bring the coding style in this file up to the current level.

Signed-off-by: Simon Glass 
---

 common/stdio.c  | 37 -
 include/stdio_dev.h |  9 +
 2 files changed, 25 insertions(+), 21 deletions(-)

diff --git a/common/stdio.c b/common/stdio.c
index d67ea60d6c..84c36a735c 100644
--- a/common/stdio.c
+++ b/common/stdio.c
@@ -191,16 +191,15 @@ struct stdio_dev *stdio_get_by_name(const char *name)
return NULL;
 }
 
-struct stdio_dev* stdio_clone(struct stdio_dev *dev)
+struct stdio_dev *stdio_clone(struct stdio_dev *dev)
 {
struct stdio_dev *_dev;
 
-   if(!dev)
+   if (!dev)
return NULL;
 
_dev = calloc(1, sizeof(struct stdio_dev));
-
-   if(!_dev)
+   if (!_dev)
return NULL;
 
memcpy(_dev, dev, sizeof(struct stdio_dev));
@@ -213,7 +212,7 @@ int stdio_register_dev(struct stdio_dev *dev, struct 
stdio_dev **devp)
struct stdio_dev *_dev;
 
_dev = stdio_clone(dev);
-   if(!_dev)
+   if (!_dev)
return -ENODEV;
list_add_tail(&_dev->list, );
if (devp)
@@ -227,41 +226,38 @@ int stdio_register(struct stdio_dev *dev)
return stdio_register_dev(dev, NULL);
 }
 
-/* deregister the device "devname".
- * returns 0 if success, -1 if device is assigned and 1 if devname not found
- */
 int stdio_deregister_dev(struct stdio_dev *dev, int force)
 {
-   int l;
struct list_head *pos;
char temp_names[3][16];
+   int i;
 
/* get stdio devices (ListRemoveItem changes the dev list) */
-   for (l=0 ; l< MAX_FILES; l++) {
-   if (stdio_devices[l] == dev) {
+   for (i = 0 ; i < MAX_FILES; i++) {
+   if (stdio_devices[i] == dev) {
if (force) {
-   strcpy(temp_names[l], "nulldev");
+   strcpy(temp_names[i], "nulldev");
continue;
}
/* Device is assigned -> report error */
-   return -1;
+   return -EBUSY;
}
-   memcpy (_names[l][0],
-   stdio_devices[l]->name,
-   sizeof(temp_names[l]));
+   memcpy(_names[i][0], stdio_devices[i]->name,
+  sizeof(temp_names[i]));
}
 
list_del(>list);
free(dev);
 
-   /* reassign Device list */
+   /* reassign device list */
list_for_each(pos, ) {
dev = list_entry(pos, struct stdio_dev, list);
-   for (l=0 ; l< MAX_FILES; l++) {
-   if(strcmp(dev->name, temp_names[l]) == 0)
-   stdio_devices[l] = dev;
+   for (i = 0 ; i < MAX_FILES; i++) {
+   if (strcmp(dev->name, temp_names[i]) == 0)
+   stdio_devices[i] = dev;
}
}
+
return 0;
 }
 
@@ -270,7 +266,6 @@ int stdio_deregister(const char *devname, int force)
struct stdio_dev *dev;
 
dev = stdio_get_by_name(devname);
-
if (!dev) /* device not found */
return -ENODEV;
 
diff --git a/include/stdio_dev.h b/include/stdio_dev.h
index b61c0c6cef..48871a6a22 100644
--- a/include/stdio_dev.h
+++ b/include/stdio_dev.h
@@ -84,6 +84,15 @@ int stdio_init(void);
 
 void stdio_print_current_devices(void);
 int stdio_deregister(const char *devname, int force);
+
+/**
+ * stdio_deregister_dev() - deregister the device "devname".
+ *
+ * @dev: Stdio device to deregister
+ * @force: true to force deregistration even if in use
+ *
+ * returns 0 on success, -EBUSY if device is assigned
+ */
 int stdio_deregister_dev(struct stdio_dev *dev, int force);
 struct list_head *stdio_get_list(void);
 struct stdio_dev *stdio_get_by_name(const char *name);
-- 
2.28.0.rc0.105.gf9edc3c819-goog



[PATCH 2/6] stdio: Tidy up use of CONFIG_SYS_DEVICE_NULLDEV

2020-07-17 Thread Simon Glass
Now that this is in Kconfig we can move the logic at the top of the file
to Kconfig, and use if() instead of #if. Update the file with these
changes.

Signed-off-by: Simon Glass 
---

 common/Kconfig |  1 +
 common/stdio.c | 30 ++
 2 files changed, 11 insertions(+), 20 deletions(-)

diff --git a/common/Kconfig b/common/Kconfig
index 4d5b3a9cfb..c9abd400ee 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -645,6 +645,7 @@ config SPL_SYS_STDIO_DEREGISTER
 
 config SYS_DEVICE_NULLDEV
bool "Enable a null device for stdio"
+   default y if SPLASH_SCREEN || SYS_STDIO_DEREGISTER
help
  Enable creation of a "nulldev" stdio device. This allows silent
  operation of the console by setting stdout to "nulldev". Enable
diff --git a/common/stdio.c b/common/stdio.c
index 2119204b98..33a795e7bb 100644
--- a/common/stdio.c
+++ b/common/stdio.c
@@ -31,15 +31,6 @@ static struct stdio_dev devs;
 struct stdio_dev *stdio_devices[] = { NULL, NULL, NULL };
 char *stdio_names[MAX_FILES] = { "stdin", "stdout", "stderr" };
 
-#if defined(CONFIG_SPLASH_SCREEN) && !defined(CONFIG_SYS_DEVICE_NULLDEV)
-#defineCONFIG_SYS_DEVICE_NULLDEV   1
-#endif
-
-#if CONFIG_IS_ENABLED(SYS_STDIO_DEREGISTER)
-#defineCONFIG_SYS_DEVICE_NULLDEV   1
-#endif
-
-#ifdef CONFIG_SYS_DEVICE_NULLDEV
 static void nulldev_putc(struct stdio_dev *dev, const char c)
 {
/* nulldev is empty! */
@@ -55,7 +46,6 @@ static int nulldev_input(struct stdio_dev *dev)
/* nulldev is empty! */
return 0;
 }
-#endif
 
 static void stdio_serial_putc(struct stdio_dev *dev, const char c)
 {
@@ -96,18 +86,18 @@ static void drv_system_init (void)
dev.tstc = stdio_serial_tstc;
stdio_register ();
 
-#ifdef CONFIG_SYS_DEVICE_NULLDEV
-   memset (, 0, sizeof (dev));
+   if (CONFIG_IS_ENABLED(SYS_DEVICE_NULLDEV)) {
+   memset(, '\0', sizeof(dev));
 
-   strcpy (dev.name, "nulldev");
-   dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_INPUT;
-   dev.putc = nulldev_putc;
-   dev.puts = nulldev_puts;
-   dev.getc = nulldev_input;
-   dev.tstc = nulldev_input;
+   strcpy(dev.name, "nulldev");
+   dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_INPUT;
+   dev.putc = nulldev_putc;
+   dev.puts = nulldev_puts;
+   dev.getc = nulldev_input;
+   dev.tstc = nulldev_input;
 
-   stdio_register ();
-#endif
+   stdio_register();
+   }
 }
 
 /**
-- 
2.28.0.rc0.105.gf9edc3c819-goog



[PATCH 4/6] stdio: Update to use compiler for Kconfig checks

2020-07-17 Thread Simon Glass
Drop use of the preprocessor where possible.

Signed-off-by: Simon Glass 
---

 common/stdio.c | 172 -
 1 file changed, 83 insertions(+), 89 deletions(-)

diff --git a/common/stdio.c b/common/stdio.c
index 33a795e7bb..1921dc6719 100644
--- a/common/stdio.c
+++ b/common/stdio.c
@@ -18,10 +18,7 @@
 #include 
 #include 
 #include 
-
-#if defined(CONFIG_SYS_I2C)
 #include 
-#endif
 
 #include 
 
@@ -109,7 +106,6 @@ struct list_head* stdio_get_list(void)
return &(devs.list);
 }
 
-#ifdef CONFIG_DM_VIDEO
 /**
  * stdio_probe_device() - Find a device which provides the given stdio device
  *
@@ -160,7 +156,6 @@ static int stdio_probe_device(const char *name, enum 
uclass_id id,
 
return 0;
 }
-#endif
 
 struct stdio_dev *stdio_get_by_name(const char *name)
 {
@@ -175,22 +170,23 @@ struct stdio_dev *stdio_get_by_name(const char *name)
if (strcmp(sdev->name, name) == 0)
return sdev;
}
-#ifdef CONFIG_DM_VIDEO
-   /*
-* We did not find a suitable stdio device. If there is a video
-* driver with a name starting with 'vidconsole', we can try probing
-* that in the hope that it will produce the required stdio device.
-*
-* This function is sometimes called with the entire value of
-* 'stdout', which may include a list of devices separate by commas.
-* Obviously this is not going to work, so we ignore that case. The
-* call path in that case is console_init_r() -> search_device() ->
-* stdio_get_by_name().
-*/
-   if (!strncmp(name, "vidconsole", 10) && !strchr(name, ',') &&
-   !stdio_probe_device(name, UCLASS_VIDEO, ))
-   return sdev;
-#endif
+   if (IS_ENABLED(CONFIG_DM_VIDEO)) {
+   /*
+* We did not find a suitable stdio device. If there is a video
+* driver with a name starting with 'vidconsole', we can try
+* probing that in the hope that it will produce the required
+* stdio device.
+*
+* This function is sometimes called with the entire value of
+* 'stdout', which may include a list of devices separate by
+* commas. Obviously this is not going to work, so we ignore
+* that case. The call path in that case is
+* console_init_r() -> search_device() -> stdio_get_by_name()
+*/
+   if (!strncmp(name, "vidconsole", 10) && !strchr(name, ',') &&
+   !stdio_probe_device(name, UCLASS_VIDEO, ))
+   return sdev;
+   }
 
return NULL;
 }
@@ -234,7 +230,6 @@ int stdio_register(struct stdio_dev *dev)
 /* deregister the device "devname".
  * returns 0 if success, -1 if device is assigned and 1 if devname not found
  */
-#if CONFIG_IS_ENABLED(SYS_STDIO_DEREGISTER)
 int stdio_deregister_dev(struct stdio_dev *dev, int force)
 {
int l;
@@ -281,7 +276,6 @@ int stdio_deregister(const char *devname, int force)
 
return stdio_deregister_dev(dev, force);
 }
-#endif /* CONFIG_IS_ENABLED(SYS_STDIO_DEREGISTER) */
 
 int stdio_init_tables(void)
 {
@@ -305,87 +299,87 @@ int stdio_init_tables(void)
 
 int stdio_add_devices(void)
 {
-#ifdef CONFIG_DM_KEYBOARD
struct udevice *dev;
struct uclass *uc;
int ret;
 
-   /*
-* For now we probe all the devices here. At some point this should be
-* done only when the devices are required - e.g. we have a list of
-* input devices to start up in the stdin environment variable. That
-* work probably makes more sense when stdio itself is converted to
-* driver model.
-*
-* TODO(s...@chromium.org): Convert changing uclass_first_device() etc.
-* to return the device even on error. Then we could use that here.
-*/
-   ret = uclass_get(UCLASS_KEYBOARD, );
-   if (ret)
-   return ret;
-
-   /* Don't report errors to the caller - assume that they are non-fatal */
-   uclass_foreach_dev(dev, uc) {
-   ret = device_probe(dev);
+   if (IS_ENABLED(CONFIG_DM_KEYBOARD)) {
+   /*
+* For now we probe all the devices here. At some point this
+* should be done only when the devices are required - e.g. we
+* have a list of input devices to start up in the stdin
+* environment variable. That work probably makes more sense
+* when stdio itself is converted to driver model.
+*
+* TODO(s...@chromium.org): Convert changing
+* uclass_first_device() etc. to return the device even on
+* error. Then we could use that here.
+*/
+   ret = uclass_get(UCLASS_KEYBOARD, );
if (ret)
-   printf("Failed to 

[PATCH 5/6] stdio: Drop brackets around .list

2020-07-17 Thread Simon Glass
These brackets are not needed. Drop them.

Signed-off-by: Simon Glass 
---

 common/stdio.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/common/stdio.c b/common/stdio.c
index 1921dc6719..d67ea60d6c 100644
--- a/common/stdio.c
+++ b/common/stdio.c
@@ -103,7 +103,7 @@ static void drv_system_init (void)
  */
 struct list_head* stdio_get_list(void)
 {
-   return &(devs.list);
+   return 
 }
 
 /**
@@ -165,7 +165,7 @@ struct stdio_dev *stdio_get_by_name(const char *name)
if (!name)
return NULL;
 
-   list_for_each(pos, &(devs.list)) {
+   list_for_each(pos, ) {
sdev = list_entry(pos, struct stdio_dev, list);
if (strcmp(sdev->name, name) == 0)
return sdev;
@@ -215,7 +215,7 @@ int stdio_register_dev(struct stdio_dev *dev, struct 
stdio_dev **devp)
_dev = stdio_clone(dev);
if(!_dev)
return -ENODEV;
-   list_add_tail(&(_dev->list), &(devs.list));
+   list_add_tail(&_dev->list, );
if (devp)
*devp = _dev;
 
@@ -251,11 +251,11 @@ int stdio_deregister_dev(struct stdio_dev *dev, int force)
sizeof(temp_names[l]));
}
 
-   list_del(&(dev->list));
+   list_del(>list);
free(dev);
 
/* reassign Device list */
-   list_for_each(pos, &(devs.list)) {
+   list_for_each(pos, ) {
dev = list_entry(pos, struct stdio_dev, list);
for (l=0 ; l< MAX_FILES; l++) {
if(strcmp(dev->name, temp_names[l]) == 0)
@@ -292,7 +292,7 @@ int stdio_init_tables(void)
 #endif /* CONFIG_NEEDS_MANUAL_RELOC */
 
/* Initialize the list */
-   INIT_LIST_HEAD(&(devs.list));
+   INIT_LIST_HEAD();
 
return 0;
 }
-- 
2.28.0.rc0.105.gf9edc3c819-goog



[PATCH 1/6] Convert CONFIG_SYS_DEVICE_NULLDEV to Kconfig

2020-07-17 Thread Simon Glass
This converts the following to Kconfig:
   CONFIG_SYS_DEVICE_NULLDEV

Signed-off-by: Simon Glass 
---

 common/Kconfig   | 16 
 configs/M5249EVB_defconfig   |  3 ++-
 configs/colibri_pxa270_defconfig |  2 +-
 doc/README.silent|  2 +-
 include/configs/M5249EVB.h   |  2 --
 include/configs/colibri_pxa270.h |  2 --
 scripts/config_whitelist.txt |  1 -
 7 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/common/Kconfig b/common/Kconfig
index 67b3818fde..4d5b3a9cfb 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -634,6 +634,22 @@ config SYS_STDIO_DEREGISTER
  removed (for example a USB keyboard) then this option can be
  enabled to ensure this is handled correctly.
 
+config SPL_SYS_STDIO_DEREGISTER
+   bool "Allow deregistering stdio devices in SPL"
+   help
+ Generally there is no need to deregister stdio devices since they
+ are never deactivated. But if a stdio device is used which can be
+ removed (for example a USB keyboard) then this option can be
+ enabled to ensure this is handled correctly. This is very rarely
+ needed in SPL.
+
+config SYS_DEVICE_NULLDEV
+   bool "Enable a null device for stdio"
+   help
+ Enable creation of a "nulldev" stdio device. This allows silent
+ operation of the console by setting stdout to "nulldev". Enable
+ this to use a serial console under board control.
+
 endmenu
 
 menu "Logging"
diff --git a/configs/M5249EVB_defconfig b/configs/M5249EVB_defconfig
index 12db389b69..8f8a4a6bad 100644
--- a/configs/M5249EVB_defconfig
+++ b/configs/M5249EVB_defconfig
@@ -3,7 +3,9 @@ CONFIG_SYS_TEXT_BASE=0xFFE0
 CONFIG_ENV_SIZE=0x2000
 CONFIG_ENV_SECT_SIZE=0x2000
 CONFIG_TARGET_M5249EVB=y
+CONFIG_DEFAULT_DEVICE_TREE="M5249EVB"
 CONFIG_SYS_CONSOLE_INFO_QUIET=y
+CONFIG_SYS_DEVICE_NULLDEV=y
 # CONFIG_DISPLAY_BOARDINFO is not set
 # CONFIG_CMDLINE_EDITING is not set
 # CONFIG_AUTOBOOT is not set
@@ -12,7 +14,6 @@ CONFIG_LOOPW=y
 CONFIG_CMD_MX_CYCLIC=y
 # CONFIG_CMD_SETEXPR is not set
 CONFIG_CMD_CACHE=y
-CONFIG_DEFAULT_DEVICE_TREE="M5249EVB"
 CONFIG_ENV_ADDR=0xFFE04000
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
 # CONFIG_NET is not set
diff --git a/configs/colibri_pxa270_defconfig b/configs/colibri_pxa270_defconfig
index 669b9dfe58..aff7b62639 100644
--- a/configs/colibri_pxa270_defconfig
+++ b/configs/colibri_pxa270_defconfig
@@ -10,6 +10,7 @@ CONFIG_NR_DRAM_BANKS=1
 CONFIG_ENV_VARS_UBOOT_CONFIG=y
 CONFIG_USE_BOOTARGS=y
 CONFIG_BOOTARGS="console=tty0 console=ttyS0,115200"
+CONFIG_SYS_DEVICE_NULLDEV=y
 # CONFIG_DISPLAY_BOARDINFO is not set
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 # CONFIG_CMDLINE_EDITING is not set
@@ -43,6 +44,5 @@ CONFIG_SYS_FLASH_CFI=y
 CONFIG_DM_SERIAL=y
 CONFIG_PXA_SERIAL=y
 CONFIG_USB=y
-CONFIG_USB_STORAGE=y
 # CONFIG_REGEX is not set
 CONFIG_OF_LIBFDT=y
diff --git a/doc/README.silent b/doc/README.silent
index 6d90a0ec40..00288e03b0 100644
--- a/doc/README.silent
+++ b/doc/README.silent
@@ -19,7 +19,7 @@ The following actions are taken if "silent" is set at boot 
time:
  - When the console devices have been initialized, "stdout" and
"stderr" are set to "nulldev", so subsequent messages are
suppressed automatically. Make sure to enable "nulldev" by
-   #defining CONFIG_SYS_DEVICE_NULLDEV in your board config file.
+   enabling CONFIG_SYS_DEVICE_NULLDEV in your board defconfig file.
 
  - When booting a linux kernel, the "bootargs" are fixed up so that
the argument "console=" will be in the command line, no matter how
diff --git a/include/configs/M5249EVB.h b/include/configs/M5249EVB.h
index de7132940c..1a1a110765 100644
--- a/include/configs/M5249EVB.h
+++ b/include/configs/M5249EVB.h
@@ -31,8 +31,6 @@
  */
 #undef CONFIG_BOOTP_BOOTFILESIZE
 
-#define CONFIG_SYS_DEVICE_NULLDEV  1   /* include nulldev device   
*/
-
 #define CONFIG_SYS_LOAD_ADDR   0x20/* default load address 
*/
 
 /*
diff --git a/include/configs/colibri_pxa270.h b/include/configs/colibri_pxa270.h
index 29827f1ee8..3bbef55ec3 100644
--- a/include/configs/colibri_pxa270.h
+++ b/include/configs/colibri_pxa270.h
@@ -70,8 +70,6 @@
 #defineCONFIG_BOOTP_BOOTFILESIZE
 #endif
 
-#defineCONFIG_SYS_DEVICE_NULLDEV   1
-
 /*
  * Clock Configuration
  */
diff --git a/scripts/config_whitelist.txt b/scripts/config_whitelist.txt
index 1c7946fb65..2da34a5d23 100644
--- a/scripts/config_whitelist.txt
+++ b/scripts/config_whitelist.txt
@@ -2178,7 +2178,6 @@ CONFIG_SYS_DEBUG_SERVER_FW_IN_NOR
 CONFIG_SYS_DEFAULT_LPDDR2_TIMINGS
 CONFIG_SYS_DEFAULT_VIDEO_MODE
 CONFIG_SYS_DEF_EEPROM_ADDR
-CONFIG_SYS_DEVICE_NULLDEV
 CONFIG_SYS_DFU_DATA_BUF_SIZE
 CONFIG_SYS_DFU_MAX_FILE_SIZE
 CONFIG_SYS_DIAG_ADDR
-- 
2.28.0.rc0.105.gf9edc3c819-goog



[PATCH 3/6] stdio: Drop #ifdefs in the header file

2020-07-17 Thread Simon Glass
These prevent the use of IS_ENABLED() and are unnecessary. Drop them and
fix a few code-style nits nearby.

Signed-off-by: Simon Glass 
---

 include/stdio_dev.h | 40 
 1 file changed, 12 insertions(+), 28 deletions(-)

diff --git a/include/stdio_dev.h b/include/stdio_dev.h
index cd0cd601bf..b61c0c6cef 100644
--- a/include/stdio_dev.h
+++ b/include/stdio_dev.h
@@ -57,7 +57,7 @@ extern char *stdio_names[MAX_FILES];
 /*
  * PROTOTYPES
  */
-intstdio_register (struct stdio_dev * dev);
+int stdio_register(struct stdio_dev *dev);
 int stdio_register_dev(struct stdio_dev *dev, struct stdio_dev **devp);
 
 /**
@@ -82,35 +82,19 @@ int stdio_add_devices(void);
  */
 int stdio_init(void);
 
-void   stdio_print_current_devices(void);
-#if CONFIG_IS_ENABLED(SYS_STDIO_DEREGISTER)
+void stdio_print_current_devices(void);
 int stdio_deregister(const char *devname, int force);
 int stdio_deregister_dev(struct stdio_dev *dev, int force);
-#endif
-struct list_head* stdio_get_list(void);
-struct stdio_dev* stdio_get_by_name(const char* name);
-struct stdio_dev* stdio_clone(struct stdio_dev *dev);
-
-#ifdef CONFIG_LCD
-intdrv_lcd_init (void);
-#endif
-#if defined(CONFIG_VIDEO) || defined(CONFIG_CFB_CONSOLE)
-intdrv_video_init (void);
-#endif
-#ifdef CONFIG_KEYBOARD
-intdrv_keyboard_init (void);
-#endif
-#ifdef CONFIG_USB_TTY
-intdrv_usbtty_init (void);
-#endif
-#ifdef CONFIG_NETCONSOLE
-intdrv_nc_init (void);
-#endif
-#ifdef CONFIG_JTAG_CONSOLE
-int drv_jtag_console_init (void);
-#endif
-#ifdef CONFIG_CBMEM_CONSOLE
+struct list_head *stdio_get_list(void);
+struct stdio_dev *stdio_get_by_name(const char *name);
+struct stdio_dev *stdio_clone(struct stdio_dev *dev);
+
+int drv_lcd_init(void);
+int drv_video_init(void);
+int drv_keyboard_init(void);
+int drv_usbtty_init(void);
+int drv_nc_init(void);
+int drv_jtag_console_init(void);
 int cbmemc_init(void);
-#endif
 
 #endif
-- 
2.28.0.rc0.105.gf9edc3c819-goog



[PATCH 0/6] stdio: Clean up stdio.c

2020-07-17 Thread Simon Glass
This file is quite old and has some crufty code. This series converts a
few things to Kconfig and updates the file.


Simon Glass (6):
  Convert CONFIG_SYS_DEVICE_NULLDEV to Kconfig
  stdio: Tidy up use of CONFIG_SYS_DEVICE_NULLDEV
  stdio: Drop #ifdefs in the header file
  stdio: Update to use compiler for Kconfig checks
  stdio: Drop brackets around 
  stdio: Tidy up the coding style

 common/Kconfig   |  17 +++
 common/stdio.c   | 251 ++-
 configs/M5249EVB_defconfig   |   3 +-
 configs/colibri_pxa270_defconfig |   2 +-
 doc/README.silent|   2 +-
 include/configs/M5249EVB.h   |   2 -
 include/configs/colibri_pxa270.h |   2 -
 include/stdio_dev.h  |  49 +++---
 scripts/config_whitelist.txt |   1 -
 9 files changed, 157 insertions(+), 172 deletions(-)

-- 
2.28.0.rc0.105.gf9edc3c819-goog



Re: [PATCH] rockchip: rk3328: Add SPI support

2020-07-17 Thread Kever Yang

Hi Johannes,

    Do you have plan to update for this patch?


Thanks,

- Kever

On 2020/7/8 下午6:08, Kever Yang wrote:

Hi Johannes,

The changes look good to me, but you need to split the patch into 3 
patches:


- rk3328 clock driver;

- rkspi driver;

- rk3328-u-boot.dtsi

BTW: the patch no need reply-to previous mail, you can make a new thread.

Thanks,

- Kever

On 2020/7/4 上午2:08, Johannes Krottmayer wrote:

Add U-Boot SPI support for the RK3328

Signed-off-by: Johannes Krottmayer 
Cc: Kever Yang 
Cc: Jagan Teki 
---

It's a initial SPI support. Not sure if "rk3399_spi_params" is also
needed. Probing of the SPI flash devices works. Tested with the
PINE64 Rock64 board.

Okay?

  arch/arm/dts/rk3328-u-boot.dtsi   |  5 +
  drivers/clk/rockchip/clk_rk3328.c | 31 +++
  drivers/spi/rk_spi.c  |  2 ++
  3 files changed, 38 insertions(+)

diff --git a/arch/arm/dts/rk3328-u-boot.dtsi 
b/arch/arm/dts/rk3328-u-boot.dtsi

index c69e13e11e..c980daae99 100644
--- a/arch/arm/dts/rk3328-u-boot.dtsi
+++ b/arch/arm/dts/rk3328-u-boot.dtsi
@@ -7,6 +7,7 @@
  aliases {
  mmc0 = 
  mmc1 = 
+ spi0 = 
  };
    chosen {
@@ -66,3 +67,7 @@
  _otg {
  hnp-srp-disable;
  };
+
+ {
+    u-boot,dm-pre-reloc;
+};
diff --git a/drivers/clk/rockchip/clk_rk3328.c 
b/drivers/clk/rockchip/clk_rk3328.c

index 02d3b08efa..bd95ab832b 100644
--- a/drivers/clk/rockchip/clk_rk3328.c
+++ b/drivers/clk/rockchip/clk_rk3328.c
@@ -555,6 +555,31 @@ static ulong rk3328_saradc_set_clk(struct 
rk3328_cru *cru, uint hz)

  return rk3328_saradc_get_clk(cru);
  }
  +static ulong rk3328_spi_get_clk(struct rk3328_cru *cru)
+{
+    u32 div, val;
+
+    val = readl(>clksel_con[24]);
+    div = (val & CLK_SPI_DIV_CON_MASK) >> CLK_SPI_DIV_CON_SHIFT;
+
+    return DIV_TO_RATE(OSC_HZ, div);
+}
+
+static ulong rk3328_spi_set_clk(struct rk3328_cru *cru, uint hz)
+{
+    u32 src_clk_div;
+
+    src_clk_div = GPLL_HZ / hz;
+    assert(src_clk_div < 128);
+
+    rk_clrsetreg(>clksel_con[24],
+ CLK_PWM_PLL_SEL_MASK | CLK_PWM_DIV_CON_MASK,
+ CLK_PWM_PLL_SEL_GPLL << CLK_PWM_PLL_SEL_SHIFT |
+ (src_clk_div - 1) << CLK_PWM_DIV_CON_SHIFT);
+
+    return rk3328_spi_get_clk(cru);
+}
+
  static ulong rk3328_clk_get_rate(struct clk *clk)
  {
  struct rk3328_clk_priv *priv = dev_get_priv(clk->dev);
@@ -581,6 +606,9 @@ static ulong rk3328_clk_get_rate(struct clk *clk)
  case SCLK_SARADC:
  rate = rk3328_saradc_get_clk(priv->cru);
  break;
+    case SCLK_SPI:
+    rate = rk3328_spi_get_clk(priv->cru);
+    break;
  default:
  return -ENOENT;
  }
@@ -617,6 +645,9 @@ static ulong rk3328_clk_set_rate(struct clk *clk, 
ulong rate)

  case SCLK_SARADC:
  ret = rk3328_saradc_set_clk(priv->cru, rate);
  break;
+    case SCLK_SPI:
+    ret = rk3328_spi_set_clk(priv->cru, rate);
+    break;
  case DCLK_LCDC:
  case SCLK_PDM:
  case SCLK_RTC32K:
diff --git a/drivers/spi/rk_spi.c b/drivers/spi/rk_spi.c
index 833cb04922..0495e04945 100644
--- a/drivers/spi/rk_spi.c
+++ b/drivers/spi/rk_spi.c
@@ -545,7 +545,9 @@ const  struct rockchip_spi_params 
rk3399_spi_params = {

  };
    static const struct udevice_id rockchip_spi_ids[] = {
+    { .compatible = "rockchip,rk3066-spi" },
  { .compatible = "rockchip,rk3288-spi" },
+    { .compatible = "rockchip,rk3328-spi" },
  { .compatible = "rockchip,rk3368-spi",
    .data = (ulong)_spi_params },
  { .compatible = "rockchip,rk3399-spi",








Re: [PATCH 0/9] mmc: fsl_esdhc: support eMMC HS200/HS400 modes

2020-07-17 Thread Jaehoon Chung
On 7/17/20 5:48 PM, Y.b. Lu wrote:
> Hi Jaehoon,
> 
> Below is the full log of the performance and function tests for eMMC HS400 
> mode. Since I used date to record time, there must be some error more or less.
> I tested the r/w performance with 4G data size at 175MHz bus speed. The 
> results were,
> Read: 273MB/s = 4096MB / 15s
> Write: 74MB/s = 4096MB / 55s
> 
> According to the eMMC data sheet the HS400 max performance for sequential r/w 
> are,
> Read: 270MB/s
> Write: 90MB/s
> 
> The performance seems to be matched and good.
> BTW, the test was applied two more patches to fix stability issue. Let me 
> send out v2 patch-set with them.
> Thanks.

Thanks for sharing result. I will check your patch-v2.

Best Regards,
Jaehoon Chung

> 
>  log ==
> NOTICE:  BL2: v1.5(release):LSDK-20.04
> NOTICE:  BL2: Built : 05:20:45, Apr  9 2020
> NOTICE:  UDIMM 18ADF2G72AZ-3G2E1
> NOTICE:  DDR4 UDIMM with 2-rank 64-bit bus (x8)
> 
> NOTICE:  32 GB DDR4, 64-bit, CL=22, ECC on, 256B, CS0+CS1
> NOTICE:  BL2: Booting BL31
> NOTICE:  BL31: v1.5(release):LSDK-20.04
> NOTICE:  BL31: Built : 11:00:17, Jul 15 2020
> NOTICE:  Welcome to LX2160 BL31 Phase
> 
> 
> U-Boot 2020.07-00703-g1b677f8 (Jul 17 2020 - 16:30:43 +0800)
> 
> SoC:  LX2160ACE Rev2.0 (0x87360020)
> Clock Configuration:
>CPU0(A72):2000 MHz  CPU1(A72):2000 MHz  CPU2(A72):2000 MHz
>CPU3(A72):2000 MHz  CPU4(A72):2000 MHz  CPU5(A72):2000 MHz
>CPU6(A72):2000 MHz  CPU7(A72):2000 MHz  CPU8(A72):2000 MHz
>CPU9(A72):2000 MHz  CPU10(A72):2000 MHz  CPU11(A72):2000 MHz
>CPU12(A72):2000 MHz  CPU13(A72):2000 MHz  CPU14(A72):2000 MHz
>CPU15(A72):2000 MHz
>Bus:  700  MHz  DDR:  2900 MT/s
> Reset Configuration Word (RCW):
>: 5038 24500050  
>0010:  0c01  
>0020: 02e001a0 2580  0096
>0030:    
>0040:    
>0050:    
>0060:   00027000 
>0070: 08b30010 00150020
> Model: NXP Layerscape LX2160ARDB Board
> Board: LX2160ACE Rev2.0-RDB, Board version: B, boot from FlexSPI DEV#1
> FPGA: v7.0
> SERDES1 Reference: Clock1 = 161.13MHz Clock2 = 161.13MHz
> SERDES2 Reference: Clock1 = 100MHz Clock2 = 100MHz
> SERDES3 Reference: Clock1 = 100MHz Clock2 = 100MHz
> VID: Core voltage after adjustment is at 852 mV
> DRAM:  31.9 GiB
> DDR31.9 GiB (DDR4, 64-bit, CL=22, ECC on)
>DDR Controller Interleaving Mode: 256B
>DDR Chip-Select Interleaving Mode: CS0+CS1
> Using SERDES1 Protocol: 19 (0x13)
> Using SERDES2 Protocol: 5 (0x5)
> Using SERDES3 Protocol: 2 (0x2)
> PCIe0: pcie@340 disabled
> PCIe1: pcie@350 disabled
> PCIe2: pcie@360 Root Complex: x1 gen1
> PCI: Failed autoconfig bar 18
> PCIe3: pcie@370 disabled
> PCIe4: pcie@380 Root Complex: no link
> PCIe5: pcie@390 disabled
> MMC:   FSL_SDHC: 0, FSL_SDHC: 1
> Loading Environment from SPI Flash... SF: Detected mt35xu512aba with page 
> size 256 Bytes, erase size 128 KiB, total 64 MiB
> *** Warning - bad CRC, using default environment
> 
> EEPROM: NXID v1
> In:serial_pl01x
> Out:   serial_pl01x
> Err:   serial_pl01x
> Net:   e1000: 68:05:ca:31:2c:73
> 
> Warning: e1000#0 MAC addresses don't match:
> Address in ROM is   68:05:ca:31:2c:73
> Address in environment is   00:04:9f:05:84:57
> eth0: DPMAC3@usxgmii, eth1: DPMAC4@usxgmii, eth2: DPMAC17@rgmii-id, eth3: 
> DPMAC18@rgmii-id, eth4: e1000#0
> SF: Detected mt35xu512aba with page size 256 Bytes, erase size 128 KiB, total 
> 64 MiB
> device 0 offset 0x64, size 0x8
> SF: 524288 bytes @ 0x64 Read: OK
> device 0 offset 0xa0, size 0x30
> SF: 3145728 bytes @ 0xa0 Read: OK
> device 0 offset 0xe0, size 0x10
> SF: 1048576 bytes @ 0xe0 Read: OK
> crc32+
> fsl-mc: Booting Management Complex ... SUCCESS
> fsl-mc: Management Complex booted (version: 10.20.4, boot status: 0x1)
> Hit any key to stop autoboot:  0
> => mmc dev 1
> switch to partitions #0, OK
> mmc1(part 0) is current device
> => mmcinfo
> Device: FSL_SDHC
> Manufacturer ID: 13
> OEM: 14e
> Name: R1J59
> Bus Speed: 17500
> Mode: HS400 (200MHz)
> Rd Block Len: 512
> MMC version 5.0
> High Capacity: Yes
> Capacity: 116.5 GiB
> Bus Width: 8-bit DDR
> Erase Group Size: 512 KiB
> HC WP Group Size: 32 MiB
> User Capacity: 116.5 GiB WRREL
> Boot Capacity: 8 MiB ENH
> RPMB Capacity: 4 MiB ENH
> Boot area 0 is not write protected
> Boot area 1 is not write protected
> => date;mmc read 8100 0 20;mmc read 8100 0 20;mmc read 
> 8100 0 20;mmc read 8100 0 20;date
> Date: 2020-07-17 (Friday)Time:  7:46:18
> 
> MMC read: dev # 1, block # 0, count 2097152 ... 2097152 blocks read: OK
> 
> MMC read: dev # 1, block # 0, count 2097152 ... 2097152 blocks read: OK

Re: [GIT PULL] Pull request: u-boot-imx u-boot-imx-20200716

2020-07-17 Thread Tom Rini
On Fri, Jul 17, 2020 at 06:05:57PM -0300, Fabio Estevam wrote:

> Hi Tom,
> 
> On Fri, Jul 17, 2020 at 11:55 AM Tom Rini  wrote:
> 
> > Please note there's a bunch of whitespace errors in
> > drivers/ddr/imx/imx8m/ddrphy_utils.c, a single one in
> > arch/arm/mach-imx/imx8m/soc.c and
> > drivers/pinctrl/nxp/pinctrl-imx*.c has some warnings about using
> > __section(..) vs __attribute__((section(..))) but these are all things
> > that can be addressed with this merged.  So, applied to u-boot/master,
> 
> Could you please share these drivers/pinctrl/nxp/pinctrl-imx*.c warnings?

Sure:
$ ./scripts/checkpatch.pl -q -f drivers/pinctrl/nxp/pinctrl-imx*.c
WARNING: __section(.data) is preferred over __attribute__((section(".data")))
#13: FILE: drivers/pinctrl/nxp/pinctrl-imx5.c:13:
+static struct imx_pinctrl_soc_info imx5_pinctrl_soc_info 
__attribute__((section(".data")));

total: 0 errors, 1 warnings, 0 checks, 44 lines checked
WARNING: __section(.data) is preferred over __attribute__((section(".data")))
#12: FILE: drivers/pinctrl/nxp/pinctrl-imx7.c:12:
+static struct imx_pinctrl_soc_info imx7_pinctrl_soc_info 
__attribute__((section(".data")));

total: 0 errors, 1 warnings, 0 checks, 41 lines checked
WARNING: __section(.data) is preferred over __attribute__((section(".data")))
#11: FILE: drivers/pinctrl/nxp/pinctrl-imx8m.c:11:
+static struct imx_pinctrl_soc_info imx8mq_pinctrl_soc_info 
__attribute__((section(".data")));

total: 0 errors, 1 warnings, 0 checks, 38 lines checked
WARNING: Use the livetree API (dev_read_...)
#59: FILE: drivers/pinctrl/nxp/pinctrl-imx.c:59:
+   if (fdtdec_get_int_array(gd->fdt_blob, node, "fsl,pins",

WARNING: quoted string split across lines
#102: FILE: drivers/pinctrl/nxp/pinctrl-imx.c:102:
+   dev_dbg(dev, "mux_reg 0x%x, conf_reg 0x%x, "
+   "input_reg 0x%x, mux_mode 0x%x, "

WARNING: quoted string split across lines
#103: FILE: drivers/pinctrl/nxp/pinctrl-imx.c:103:
+   "input_reg 0x%x, mux_mode 0x%x, "
+   "input_val 0x%x, config_val 0x%x\n",

WARNING: quoted string split across lines
#172: FILE: drivers/pinctrl/nxp/pinctrl-imx.c:172:
+   dev_dbg(dev, "select_input: offset 0x%x val "
+   "0x%x\n", input_reg, input_val);

WARNING: quoted string split across lines
#187: FILE: drivers/pinctrl/nxp/pinctrl-imx.c:187:
+   dev_dbg(dev, "write config: offset 0x%x val "
+   "0x%x\n", conf_reg, config_val);

WARNING: Use the livetree API (dev_read_...)
#206: FILE: drivers/pinctrl/nxp/pinctrl-imx.c:206:
+   struct fdtdec_phandle_args arg;

WARNING: Use the livetree API (dev_read_...)
#230: FILE: drivers/pinctrl/nxp/pinctrl-imx.c:230:
+   info->mux_mask = fdtdec_get_int(gd->fdt_blob, node, "fsl,mux_mask", 0);

WARNING: Use the livetree API (dev_read_...)
#235: FILE: drivers/pinctrl/nxp/pinctrl-imx.c:235:
+   if (fdtdec_get_bool(gd->fdt_blob, node, "fsl,input-sel")) {

WARNING: Use the livetree API (dev_read_...)
#236: FILE: drivers/pinctrl/nxp/pinctrl-imx.c:236:
+   ret = fdtdec_parse_phandle_with_args(gd->fdt_blob,

WARNING: Use the livetree API (dev_read_...)
#244: FILE: drivers/pinctrl/nxp/pinctrl-imx.c:244:
+   addr = fdtdec_get_addr_size(gd->fdt_blob, arg.node, "reg",

total: 0 errors, 10 warnings, 0 checks, 273 lines checked

> What are the defconfig targets that triggered it?

Not a build-time issue, my scripts do a ./scripts/checkpatch.pl --git
origin/master.. -q and I search on ERROR.  Since the above WARNINGS were
on the same page as the ERRORs I noted them.

-- 
Tom


signature.asc
Description: PGP signature


Re: [GIT PULL] Pull request: u-boot-imx u-boot-imx-20200716

2020-07-17 Thread Fabio Estevam
Hi Tom,

On Fri, Jul 17, 2020 at 11:55 AM Tom Rini  wrote:

> Please note there's a bunch of whitespace errors in
> drivers/ddr/imx/imx8m/ddrphy_utils.c, a single one in
> arch/arm/mach-imx/imx8m/soc.c and
> drivers/pinctrl/nxp/pinctrl-imx*.c has some warnings about using
> __section(..) vs __attribute__((section(..))) but these are all things
> that can be addressed with this merged.  So, applied to u-boot/master,

Could you please share these drivers/pinctrl/nxp/pinctrl-imx*.c warnings?

What are the defconfig targets that triggered it?


Re: [PATCH] doc: fit: Write hex address as hex instead of int

2020-07-17 Thread Tom Rini
On Wed, Jul 15, 2020 at 03:10:17PM +0200, Michal Simek wrote:

> When update_uboot.its is used directly there is syntax error for no reason.
> 
> Error report:
> mkimage -f update_uboot.its boot
> Error: update_uboot.its:18.12-13 syntax error
> FATAL ERROR: Unable to parse input tree
> mkimage: Can't read boot.tmp: Invalid argument
> 
> Fixes: 4bae90904b69 ("Automatic software update from TFTP server")
> Signed-off-by: Michal Simek 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v1] include: pci_ids: Add Cavium devices

2020-07-17 Thread Tom Rini
On Fri, Jul 17, 2020 at 08:06:22AM +0200, Stefan Roese wrote:

> From: Suneel Garapati 
> 
> Add VendorID and DeviceID for supported devices on OcteonTX/TX2
> platforms.
> 
> Signed-off-by: Suneel Garapati 
> Reviewed-by: Stefan Roese 
> Cc: Simon Glass 
> Cc: Daniel Schwierzeck 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH] mtd: mtdpart: use uint64_t instead of int for cur_off

2020-07-17 Thread Tom Rini
On Mon, Jul 13, 2020 at 02:40:02PM +0200, Martin Kaistra wrote:

> The types of "offset" and "size" of "struct mtd_partition" are uint64_t,
> while mtd_parse_partitions() uses int to work with these values. When
> the offset reaches 2GB, it is interpreted as a negative value, which
> leads to error messages like
> 
> mtd: partition "" is out of reach -- disabled
> 
> eg. when using the "ubi part" command.
> 
> Fix this by using uint64_t for cur_off and cur_sz.
> 
> Signed-off-by: Martin Kaistra 
> Reviewed-by: Kurt Kanzenbach 
> Reviewed-by: Heiko Schocher 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH] board/km: update MAINTAINERS email

2020-07-17 Thread Tom Rini
On Thu, Jul 09, 2020 at 05:31:23PM +0200, Holger Brunck wrote:

> Signed-off-by: Holger Brunck 
> CC: Valentin Longchamp 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v2] mkimage: Fix error message if write less data then expected

2020-07-17 Thread Tom Rini
On Wed, Jul 08, 2020 at 11:52:50AM +0200, Mylène Josserand wrote:

> Add a new error message in case the size of data written
> are shorter than the one expected.
> 
> Currently, it will lead to the following error message:
> 
> "mkimage: Write error on uImage: Success"
> 
> This is not explicit when the error is because the device
> doesn't have enough space. Let's use a more understandable message:
> 
> "mkimage: Write only 4202432/4682240 bytes, probably no space left on the 
> device"
> 
> Signed-off-by: Mylène Josserand 
> Reviewed-by: Walter Lozano 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 1/1] doc: correct description of crash dumps

2020-07-17 Thread Tom Rini
On Thu, Jul 09, 2020 at 08:12:06AM +0200, Heinrich Schuchardt wrote:

> Correct the description of the ESR register.
> 
> Fix a typo.
> 
> Signed-off-by: Heinrich Schuchardt 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH] fixdep: fix CONFIG_IS_ENABLED etc. handling

2020-07-17 Thread Tom Rini
On Wed, Jul 08, 2020 at 03:45:56PM -0600, Stephen Warren wrote:

> From: Stephen Warren 
> 
> When fixdep detects CONFIG_IS_ENABLED and other similar macros, it must
> parse the macro parameter to determine which actual CONFIG_ option is
> being referenced. This involves moving a pointer forward through the
> entire CONFIG_ option "word". Currently, the code uses variable q to walk
> through the word, but doesn't actually initialize it to point at the
> parameter before doing so. Consequently, the walking process immediately
> fails since it sees the macro invocatoins's ( rather than the expected
> alpha-numeric characters in the macro parameter. Fix this by adding the
> missing initialization.
> 
> Fixes: 67f2ee86ccbe ("kbuild: fixdep: Resync this with v4.17")
> Fixes: 7012865e961c ("gpio: fix test.py for gpio label lookup")
> Signed-off-by: Stephen Warren 
> Reviewed-by: Simon Glass 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH] remove include/config_defaults.h

2020-07-17 Thread Tom Rini
On Tue, Jul 07, 2020 at 10:40:26AM +0200, Rasmus Villemoes wrote:

> Since commit 4b0bcfa7c4ec (Kconfig: Migrate CONFIG_BOOTM_* options),
> the config_defaults.h file has been void of any actual content - and
> these days, "sane defaults for everyone" is achieved by appropriate
> default values in Kconfig. Remove it, and thus make every translation
> unit process one less header file.
> 
> Signed-off-by: Rasmus Villemoes 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH] doc: multi-dtb-fit: Remove double underscores

2020-07-17 Thread Tom Rini
On Sun, Jul 05, 2020 at 07:04:50PM -0300, Fabio Estevam wrote:

> Remove the incorrect usage of double underscores for the
> CONFIG_OF_LIST and CONFIG_SPL_OF_LIST symbols.
> 
> Signed-off-by: Fabio Estevam 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v2 1/1] fs: error handling in do_load()

2020-07-17 Thread Tom Rini
On Mon, Jun 29, 2020 at 08:08:49PM +0200, Heinrich Schuchardt wrote:

> If a file cannot be loaded, show an error message.
> Set the EFI boot device only after successfully loading a file.
> 
> Signed-off-by: Heinrich Schuchardt 
> Reviewed-by: Simon Glass 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 1/3] treewide: convert bd_t to struct bd_info by coccinelle

2020-07-17 Thread Tom Rini
On Fri, Jun 26, 2020 at 03:13:33PM +0900, Masahiro Yamada wrote:

> The Linux coding style guide (Documentation/process/coding-style.rst)
> clearly says:
> 
>   It's a **mistake** to use typedef for structures and pointers.
> 
> Besides, using typedef for structures is annoying when you try to make
> headers self-contained.
> 
> Let's say you have the following function declaration in a header:
> 
>   void foo(bd_t *bd);
> 
> This is not self-contained since bd_t is not defined.
> 
> To tell the compiler what 'bd_t' is, you need to include 
> 
>   #include 
>   void foo(bd_t *bd);
> 
> Then, the include direcective pulls in more bloat needlessly.
> 
> If you use 'struct bd_info' instead, it is enough to put a forward
> declaration as follows:
> 
>   struct bd_info;
>   void foo(struct bd_info *bd);
> 
> Right, typedef'ing bd_t is a mistake.
> 
> I used coccinelle to generate this commit.
> 
> The semantic patch that makes this change is as follows:
> 
>   
>   @@
>   typedef bd_t;
>   @@
>   -bd_t
>   +struct bd_info
>   
> 
> Signed-off-by: Masahiro Yamada 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 3/3] asm/u-boot.h: remove bd_t definitions

2020-07-17 Thread Tom Rini
On Fri, Jun 26, 2020 at 03:13:35PM +0900, Masahiro Yamada wrote:

> All the users of bd_t were converted to struct bd_info.
> 
> Remove the definitions.
> 
> Signed-off-by: Masahiro Yamada 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 2/3] treewide: convert bd_t to struct bd_info manually

2020-07-17 Thread Tom Rini
On Fri, Jun 26, 2020 at 03:13:34PM +0900, Masahiro Yamada wrote:

> Some code was not converted by coccinelle, somehow.
> 
> I manually fixed up the remaining, and comments, README docs.
> 
> Signed-off-by: Masahiro Yamada 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH] arm64: Remove CONFIG_SYS_FULL_VA macro

2020-07-17 Thread Tom Rini
On Thu, Jun 25, 2020 at 09:26:57AM +0200, Michal Simek wrote:

> All configurations have been removed in 2016 by commit 7985cdf74b28
> ("arm64: Remove non-full-va map code").
> 
> Signed-off-by: Michal Simek 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH] lib: zlib: Remove offset pointer optimization in inftrees.c

2020-07-17 Thread Tom Rini
On Wed, Jun 24, 2020 at 04:31:08PM +0800, Ley Foon Tan wrote:

> From: Chin Liang See 
> 
> This fixes the CVE-2016-9840. Commit imported from [1].
> 
> inftrees.c was subtracting an offset from a pointer to an array,
> in order to provide a pointer that allowed indexing starting at
> the offset. This is not compliant with the C standard, for which
> the behavior of a pointer decremented before its allocated memory
> is undefined. Per the recommendation of a security audit of the
> zlib code by Trail of Bits and TrustInSoft, in support of the
> Mozilla Foundation, this tiny optimization was removed, in order
> to avoid the possibility of undefined behavior.
> 
> [1]: 
> https://github.com/madler/zlib/commit/6a043145ca6e9c55184013841a67b2fef87e44c0
> 
> Signed-off-by: Mark Adler 
> Signed-off-by: Chin Liang See 
> Signed-off-by: Ley Foon Tan 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH] Convert CONFIG_ARMV7_PSCI_1_0 and CONFIG_ARMV7_PSCI_0_2 to Kconfig

2020-07-17 Thread Tom Rini
On Wed, Jun 17, 2020 at 06:19:18PM +0200, Patrick Delaunay wrote:

> This converts the following to Kconfig:
> CONFIG_ARMV7_PSCI_1_0
> CONFIG_ARMV7_PSCI_0_2
> 
> Signed-off-by: Patrick Delaunay 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH] Makefile: Silence relocate-rela call

2020-07-17 Thread Tom Rini
On Thu, Jun 25, 2020 at 08:39:45AM +0200, Jan Kiszka wrote:

> From: Jan Kiszka 
> 
> Signed-off-by: Jan Kiszka 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v2 1/1] spl: fix ext4fs_mount return code handling

2020-07-17 Thread Tom Rini
On Tue, Jun 16, 2020 at 10:03:52PM +0200, Heiko Thiery wrote:

> From: Thomas Schaefer 
> 
> - Despite other ext4 filesystem functions, ext4fs_mount returns
>   0 in case of error.
> - This leads to u-boot crash in case that an SD card
>   with valid partition table but without ext4 filesystem created
>   in a partition is found on SD card.
> - Fix this by returning a proper error code of '-1' from spl_load_image_ext
>   function in case of ext4fs_mount error.
> 
> Signed-off-by: Thomas Schaefer 
> [hthiery: slightly reword the commit message]
> Signed-off-by: Heiko Thiery 
> Reviewed-by: Tom Rini 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 4/4] cmd: booti: convert the debug print about image move to printf

2020-07-17 Thread Tom Rini
On Fri, Jun 12, 2020 at 03:41:21PM +0300, Tero Kristo wrote:

> Moving of the OS image may have some nasty side effects like corrupting
> DTB. Convert the current debug print to printf so that the relocation of
> the OS is always obvious to the user.
> 
> Signed-off-by: Tero Kristo 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 2/4] image: fdt: bail out with error if no boot time FDT image found

2020-07-17 Thread Tom Rini
On Fri, Jun 12, 2020 at 03:41:19PM +0300, Tero Kristo wrote:

> Currently the boot continues if the FDT image is clearly corrupted,
> which just causes the loaded OS to hang. Abort boot properly if the FDT
> is corrupted.
> 
> Signed-off-by: Tero Kristo 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 3/4] common: bootm: add checks to verify if ramdisk / fdtimage overlaps OS image

2020-07-17 Thread Tom Rini
On Fri, Jun 12, 2020 at 03:41:20PM +0300, Tero Kristo wrote:

> These cases are typically fatal and are difficult to debug for random
> users. Add checks for detecting overlapping images and abort if overlap
> is detected.
> 
> Signed-off-by: Tero Kristo 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v2] lz4: fix decompressor on big-endian powerpc

2020-07-17 Thread Tom Rini
On Sun, Jun 07, 2020 at 02:29:18PM +0200, Rasmus Villemoes wrote:

> Booting an lz4-compressed kernel image fails on our powerpc board with
> -EPROTONOSUPPORT. Adding a bit of debug prints, we get
> 
>   magic: 0x184d2204
>   flags: 0x64
>   reserved0: 1
>   has_content_checksum: 1
>   has_content_size: 0
>   has_block_checksum: 0
>   independent_blocks: 1
>   version: 0
>   block_descriptor: 70
>   reserved1: 7
>   max_block_size: 0
>   reserved2: 0
> 
> So the magic is ok, but the version check fails, also some reserved
> bits are apparently set. But that's because the code interprets the
> "flags" and "block_descriptor" bytes wrongly:
> 
> Using bit-fields to access individual bits of an "on the wire" format
> is not portable, not even when restricted to the C flavour implemented
> by gcc. Quoting the gcc manual:
> 
>* 'The order of allocation of bit-fields within a unit (C90 6.5.2.1,
>  C99 and C11 6.7.2.1).'
> 
>  Determined by ABI.
> 
> and indeed, the PPC Processor ABI supplement says
> 
>* Bit-fields are allocated from right to left (least to most
>  significant) on Little-Endian implementations and from left to
>  right (most to least significant) on Big-Endian implementations.
> 
> The upstream code (github.com/lz4/lz4) uses explicit shifts and masks
> for encoding/decoding:
> 
> /* FLG Byte */
> *dstPtr++ = (BYTE)(((1 & _2BITS) << 6)/* Version('01') */
> + ((cctxPtr->prefs.frameInfo.blockMode & _1BIT ) << 5)
> + ((cctxPtr->prefs.frameInfo.blockChecksumFlag & _1BIT ) << 4)
> + ((unsigned)(cctxPtr->prefs.frameInfo.contentSize > 0) << 3)
> + ((cctxPtr->prefs.frameInfo.contentChecksumFlag & _1BIT ) << 2)
> +  (cctxPtr->prefs.frameInfo.dictID > 0) );
> 
> /* Flags */
> {   U32 const FLG = srcPtr[4];
> U32 const version = (FLG>>6) & _2BITS;
> blockChecksumFlag = (FLG>>4) & _1BIT;
> blockMode = (FLG>>5) & _1BIT;
> contentSizeFlag = (FLG>>3) & _1BIT;
> contentChecksumFlag = (FLG>>2) & _1BIT;
> dictIDFlag = FLG & _1BIT;
> /* validate */
> if (((FLG>>1)&_1BIT) != 0) return err0r(LZ4F_ERROR_reservedFlag_set); 
> /* Reserved bit */
> if (version != 1) return err0r(LZ4F_ERROR_headerVersion_wrong);   
>  /* Version Number, only supported value */
> }
> 
> Do the same here, and while at it, be more careful to use unaligned
> accessors to what is most likely unaligned. Also update the comment to
> make it clear that it only refers to the lz4.c file, not the following
> code of lz4_wrapper.c.
> 
> This has been tested partly, of course, by seeing that my
> lz4-compressed kernel now boots, partly by running the (de)compression
> test-suite in the (x86_64) sandbox - i.e., it should still work just
> fine on little-endian hosts.
> 
> Reviewed-by: Julius Werner 
> Signed-off-by: Rasmus Villemoes 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH] Convert CONFIG_MXC_UART to Kconfig

2020-07-17 Thread Tom Rini
On Tue, Jun 09, 2020 at 10:46:46AM -0400, Tom Rini wrote:

> This converts the following to Kconfig:
>CONFIG_MXC_UART
> 
> Signed-off-by: Tom Rini 
> Acked-by: Peng Fan 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 1/1] doc: Coccinelle: move to HTML doc

2020-07-17 Thread Tom Rini
On Fri, Jun 05, 2020 at 05:13:44AM +0200, Heinrich Schuchardt wrote:

> Move doc/README.coccinelle to doc/develop/coccinelle.rst using the current
> linux-next version of the text.
> 
> Signed-off-by: Heinrich Schuchardt 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 1/2] imx8m: ddrphy_utils: Improve coding style

2020-07-17 Thread Tom Rini
On Fri, Jul 17, 2020 at 04:36:53PM -0300, Fabio Estevam wrote:

> Currently checkpatch is not happy about this file:
> 
> total: 14 errors, 2 warnings, 7 checks, 359 lines checked
> 
> Improve the coding style so that it can now report:
> 
> total: 0 errors, 0 warnings, 6 checks, 360 lines checked
> 
> Reported-by: Tom Rini 
> Signed-off-by: Fabio Estevam 

Reviewed-by: Tom Rini 

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 2/2] imx8m: soc: Remove unneeded space

2020-07-17 Thread Tom Rini
On Fri, Jul 17, 2020 at 04:36:54PM -0300, Fabio Estevam wrote:

> Checkpatch reports the following issue:
> 
> ERROR: space prohibited before that ',' (ctx:WxW)
> #936: FILE: arch/arm/mach-imx/imx8m/soc.c:936:
> +   0, 0 , 0, 0, 0, 0, );
> 
> Remove the unneeded space.
>  ^
> Reported-by: Tom Rini 
> Signed-off-by: Fabio Estevam 

Reviewed-by: Tom Rini 

-- 
Tom


signature.asc
Description: PGP signature


Re: [GIT PULL] Pull request: u-boot-imx u-boot-imx-20200716

2020-07-17 Thread Fabio Estevam
Hi Tom,

On Fri, Jul 17, 2020 at 11:55 AM Tom Rini  wrote:

> Please note there's a bunch of whitespace errors in
> drivers/ddr/imx/imx8m/ddrphy_utils.c, a single one in
> arch/arm/mach-imx/imx8m/soc.c and
> drivers/pinctrl/nxp/pinctrl-imx*.c has some warnings about using
> __section(..) vs __attribute__((section(..))) but these are all things
> that can be addressed with this merged.  So, applied to u-boot/master,
> thanks!

I have fixed the first two issues you reported.

Thanks


[PATCH 2/2] imx8m: soc: Remove unneeded space

2020-07-17 Thread Fabio Estevam
Checkpatch reports the following issue:

ERROR: space prohibited before that ',' (ctx:WxW)
#936: FILE: arch/arm/mach-imx/imx8m/soc.c:936:
+ 0, 0 , 0, 0, 0, 0, );

Remove the unneeded space.
   ^
Reported-by: Tom Rini 
Signed-off-by: Fabio Estevam 
---
 arch/arm/mach-imx/imx8m/soc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/mach-imx/imx8m/soc.c b/arch/arm/mach-imx/imx8m/soc.c
index b3c08271e6..75e1877e20 100644
--- a/arch/arm/mach-imx/imx8m/soc.c
+++ b/arch/arm/mach-imx/imx8m/soc.c
@@ -933,7 +933,7 @@ static void acquire_buildinfo(void)
 
/* Get ARM Trusted Firmware commit id */
arm_smccc_smc(IMX_SIP_BUILDINFO, IMX_SIP_BUILDINFO_GET_COMMITHASH,
- 0, 0 , 0, 0, 0, 0, );
+ 0, 0, 0, 0, 0, 0, );
atf_commit = res.a0;
if (atf_commit == 0x) {
debug("ATF does not support build info\n");
-- 
2.17.1



[PATCH 1/2] imx8m: ddrphy_utils: Improve coding style

2020-07-17 Thread Fabio Estevam
Currently checkpatch is not happy about this file:

total: 14 errors, 2 warnings, 7 checks, 359 lines checked

Improve the coding style so that it can now report:

total: 0 errors, 0 warnings, 6 checks, 360 lines checked

Reported-by: Tom Rini 
Signed-off-by: Fabio Estevam 
---
 drivers/ddr/imx/imx8m/ddrphy_utils.c | 29 ++--
 1 file changed, 15 insertions(+), 14 deletions(-)

diff --git a/drivers/ddr/imx/imx8m/ddrphy_utils.c 
b/drivers/ddr/imx/imx8m/ddrphy_utils.c
index 20ae47bfb5..0f8baefb1f 100644
--- a/drivers/ddr/imx/imx8m/ddrphy_utils.c
+++ b/drivers/ddr/imx/imx8m/ddrphy_utils.c
@@ -1,7 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0+
 /*
-* Copyright 2018 NXP
-*/
+ * Copyright 2018 NXP
+ */
 
 #include 
 #include 
@@ -201,7 +201,7 @@ unsigned int lpddr4_mr_read(unsigned int mr_rank, unsigned 
int mr_addr)
 }
 
 unsigned int look_for_max(unsigned int data[],
-unsigned int addr_start, unsigned int addr_end)
+ unsigned int addr_start, unsigned int addr_end)
 {
unsigned int i, imax = 0;
 
@@ -233,9 +233,9 @@ void get_trained_CDD(u32 fsp)
if (i == 0) {
cdd_cha[0] = (tmp >> 8) & 0xff;
} else if (i == 6) {
-   cdd_cha[11]=tmp & 0xff;
+   cdd_cha[11] = tmp & 0xff;
} else {
-   cdd_chb[ i * 2 - 1] = tmp & 0xff;
+   cdd_chb[i * 2 - 1] = tmp & 0xff;
cdd_chb[i * 2] = (tmp >> 8) & 0xff;
}
}
@@ -254,7 +254,8 @@ void get_trained_CDD(u32 fsp)
g_cdd_ww_max[fsp] =  cdd_cha_ww_max > cdd_chb_ww_max ? 
cdd_cha_ww_max : cdd_chb_ww_max;
} else {
unsigned int ddr4_cdd[64];
-   for( i = 0; i < 29; i++) {
+
+   for (i = 0; i < 29; i++) {
tmp = reg32_read(IP2APB_DDRPHY_IPS_BASE_ADDR(0) + 
(0x54012 + i) * 4);
ddr4_cdd[i * 2] = tmp & 0xff;
ddr4_cdd[i * 2 + 1] = (tmp >> 8) & 0xff;
@@ -269,18 +270,18 @@ void get_trained_CDD(u32 fsp)
 
 void update_umctl2_rank_space_setting(unsigned int pstat_num)
 {
-   unsigned int i,ddr_type;
+   unsigned int i, ddr_type;
unsigned int addr_slot, rdata, tmp, tmp_t;
-   unsigned int ddrc_w2r,ddrc_r2w,ddrc_wr_gap,ddrc_rd_gap;
+   unsigned int ddrc_w2r, ddrc_r2w, ddrc_wr_gap, ddrc_rd_gap;
 
ddr_type = reg32_read(DDRC_MSTR(0)) & 0x3f;
for (i = 0; i < pstat_num; i++) {
addr_slot = i ? (i + 1) * 0x1000 : 0;
if (ddr_type == 0x20) {
/* update r2w:[13:8], w2r:[5:0] */
-   rdata=reg32_read(DDRC_DRAMTMG2(0) + addr_slot);
+   rdata = reg32_read(DDRC_DRAMTMG2(0) + addr_slot);
ddrc_w2r = rdata & 0x3f;
-   if(is_imx8mp())
+   if (is_imx8mp())
tmp = ddrc_w2r + (g_cdd_wr_max[i] >> 1);
else
tmp = ddrc_w2r + (g_cdd_wr_max[i] >> 1) + 1;
@@ -297,7 +298,7 @@ void update_umctl2_rank_space_setting(unsigned int 
pstat_num)
reg32_write((DDRC_DRAMTMG2(0) + addr_slot), tmp_t);
} else {
/* update w2r:[5:0] */
-   rdata=reg32_read(DDRC_DRAMTMG9(0) + addr_slot);
+   rdata = reg32_read(DDRC_DRAMTMG9(0) + addr_slot);
ddrc_w2r = rdata & 0x3f;
if (is_imx8mp())
tmp = ddrc_w2r + (g_cdd_wr_max[i] >> 1);
@@ -310,7 +311,7 @@ void update_umctl2_rank_space_setting(unsigned int 
pstat_num)
/* update r2w:[13:8] */
rdata = reg32_read(DDRC_DRAMTMG2(0) + addr_slot);
ddrc_r2w = (rdata >> 8) & 0x3f;
-   if(is_imx8mp())
+   if (is_imx8mp())
tmp = ddrc_r2w + (g_cdd_rw_max[i] >> 1);
else
tmp = ddrc_r2w + (g_cdd_rw_max[i] >> 1) + 1;
@@ -324,7 +325,7 @@ void update_umctl2_rank_space_setting(unsigned int 
pstat_num)
/* update rankctl: wr_gap:11:8; rd:gap:7:4; 
quasi-dymic, doc wrong(static) */
rdata = reg32_read(DDRC_RANKCTL(0) + addr_slot);
ddrc_wr_gap = (rdata >> 8) & 0xf;
-   if(is_imx8mp())
+   if (is_imx8mp())
tmp = ddrc_wr_gap + (g_cdd_ww_max[i] >> 1);
else
tmp = ddrc_wr_gap + (g_cdd_ww_max[i] >> 1) + 1;
@@ -342,7 +343,7 @@ void update_umctl2_rank_space_setting(unsigned int 
pstat_num)
}
  

Re: [PATCH 1/1] clk: ICS8N3QV01 remove superfluous code

2020-07-17 Thread Heinrich Schuchardt
On 2/16/20 9:50 AM, Lukasz Majewski wrote:
> On Sat, 15 Feb 2020 21:27:38 +0100
> Heinrich Schuchardt  wrote:
>
>> Do not calculate a unused value of n which is overwritten in both
>> branches of the subsequent if statement.
>>
>> Identified by cppcheck.
>>
>> Signed-off-by: Heinrich Schuchardt 
>> ---
>>  drivers/clk/ics8n3qv01.c | 1 -
>>  1 file changed, 1 deletion(-)
>>

> Reviewed-by: Lukasz Majewski 
>

Hello Lukasz,

this patch reviewed by you in February is still not merged. Will you
create a pull request for CLOCK, please?

You can download the patch from

https://patchwork.ozlabs.org/project/uboot/patch/20200215202738.15469-1-xypron.g...@gmx.de/

Best regards

Heinrich


[PATCH] efi_loader: use logging for block device messages

2020-07-17 Thread Heinrich Schuchardt
Use logging instead of printf() for messages occurring when scanning block
devices during the initialization of the UEFI sub-system.

Signed-off-by: Heinrich Schuchardt 
---
 lib/efi_loader/efi_disk.c | 23 +--
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c
index 670bf2b8ef..7bd1ccec45 100644
--- a/lib/efi_loader/efi_disk.c
+++ b/lib/efi_loader/efi_disk.c
@@ -5,11 +5,14 @@
  *  Copyright (c) 2016 Alexander Graf
  */

+#define LOG_CATEGORY LOGC_EFI
+
 #include 
 #include 
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 

@@ -490,7 +493,7 @@ int efi_disk_create_partitions(efi_handle_t parent, struct 
blk_desc *desc,
ret = efi_disk_add_dev(parent, dp, if_typename, desc, diskid,
   info.start, part, NULL);
if (ret != EFI_SUCCESS) {
-   printf("Adding partition %s failed\n", pdevname);
+   log_err("Adding partition %s failed\n", pdevname);
continue;
}
disks++;
@@ -528,16 +531,16 @@ efi_status_t efi_disk_register(void)
const char *if_typename = blk_get_if_type_name(desc->if_type);

/* Add block device for the full device */
-   printf("Scanning disk %s...\n", dev->name);
+   log_info("Scanning disk %s...\n", dev->name);
ret = efi_disk_add_dev(NULL, NULL, if_typename,
desc, desc->devnum, 0, 0, );
if (ret == EFI_NOT_READY) {
-   printf("Disk %s not ready\n", dev->name);
+   log_notice("Disk %s not ready\n", dev->name);
continue;
}
if (ret) {
-   printf("ERROR: failure to add disk device %s, r = 
%lu\n",
-  dev->name, ret & ~EFI_ERROR_MASK);
+   log_err("ERROR: failure to add disk device %s, r = 
%lu\n",
+   dev->name, ret & ~EFI_ERROR_MASK);
return ret;
}
disks++;
@@ -560,7 +563,7 @@ efi_status_t efi_disk_register(void)
continue;

if_typename = cur_drvr->if_typename;
-   printf("Scanning disks on %s...\n", if_typename);
+   log_info("Scanning disks on %s...\n", if_typename);
for (i = 0; i < 4; i++) {
struct blk_desc *desc;
char devname[32] = { 0 }; /* dp->str is u16[32] long */
@@ -578,12 +581,12 @@ efi_status_t efi_disk_register(void)
ret = efi_disk_add_dev(NULL, NULL, if_typename, desc,
   i, 0, 0, );
if (ret == EFI_NOT_READY) {
-   printf("Disk %s not ready\n", devname);
+   log_notice("Disk %s not ready\n", devname);
continue;
}
if (ret) {
-   printf("ERROR: failure to add disk device %s, r 
= %lu\n",
-  devname, ret & ~EFI_ERROR_MASK);
+   log_err("ERROR: failure to add disk device %s, 
r = %lu\n",
+   devname, ret & ~EFI_ERROR_MASK);
return ret;
}
disks++;
@@ -595,7 +598,7 @@ efi_status_t efi_disk_register(void)
}
}
 #endif
-   printf("Found %d disks\n", disks);
+   log_info("Found %d disks\n", disks);

return EFI_SUCCESS;
 }
--
2.27.0



[PATCH 1/1] efi_loader: use logging for bootefi command

2020-07-17 Thread Heinrich Schuchardt
Log messages of the bootefi command instead of simply printing them to the
console.

Do not show "## Application terminated" message when the UEFI binary
completed successfully.

Signed-off-by: Heinrich Schuchardt 
---
 cmd/bootefi.c | 42 --
 1 file changed, 24 insertions(+), 18 deletions(-)

diff --git a/cmd/bootefi.c b/cmd/bootefi.c
index 57552f99fc..8154efde52 100644
--- a/cmd/bootefi.c
+++ b/cmd/bootefi.c
@@ -5,6 +5,8 @@
  *  Copyright (c) 2016 Alexander Graf
  */

+#define LOG_CATEGORY LOGC_EFI
+
 #include 
 #include 
 #include 
@@ -14,6 +16,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -62,7 +65,7 @@ static efi_status_t set_load_options(efi_handle_t handle, 
const char *env_var,
size = utf8_utf16_strlen(env) + 1;
loaded_image_info->load_options = calloc(size, sizeof(u16));
if (!loaded_image_info->load_options) {
-   printf("ERROR: Out of memory\n");
+   log_err("ERROR: Out of memory\n");
EFI_CALL(systab.boottime->close_protocol(handle,
 _guid_loaded_image,
 efi_root, NULL));
@@ -137,7 +140,7 @@ static efi_status_t copy_fdt(void **fdtp)
 EFI_ACPI_RECLAIM_MEMORY, fdt_pages,
 _fdt_addr);
if (ret != EFI_SUCCESS) {
-   printf("ERROR: Failed to reserve space for FDT\n");
+   log_err("ERROR: Failed to reserve space for FDT\n");
goto done;
}
}
@@ -156,8 +159,8 @@ static void efi_reserve_memory(u64 addr, u64 size)
addr = (uintptr_t)map_sysmem(addr, 0);
if (efi_add_memory_map(addr, size,
   EFI_RESERVED_MEMORY_TYPE) != EFI_SUCCESS)
-   printf("Reserved memory mapping failed addr %llx size %llx\n",
-  addr, size);
+   log_err("Reserved memory mapping failed addr %llx size %llx\n",
+   addr, size);
 }

 /**
@@ -252,7 +255,7 @@ efi_status_t efi_install_fdt(void *fdt)
 */
 #if CONFIG_IS_ENABLED(GENERATE_ACPI_TABLE)
if (fdt) {
-   printf("ERROR: can't have ACPI table and device tree.\n");
+   log_err("ERROR: can't have ACPI table and device tree.\n");
return EFI_LOAD_ERROR;
}
 #else
@@ -272,13 +275,13 @@ efi_status_t efi_install_fdt(void *fdt)
if (!fdt_opt) {
fdt_opt = env_get("fdtcontroladdr");
if (!fdt_opt) {
-   printf("ERROR: need device tree\n");
+   log_err("ERROR: need device tree\n");
return EFI_NOT_FOUND;
}
}
fdt_addr = simple_strtoul(fdt_opt, NULL, 16);
if (!fdt_addr) {
-   printf("ERROR: invalid $fdt_addr or $fdtcontroladdr\n");
+   log_err("ERROR: invalid $fdt_addr or 
$fdtcontroladdr\n");
return EFI_LOAD_ERROR;
}
fdt = map_sysmem(fdt_addr, 0);
@@ -286,19 +289,19 @@ efi_status_t efi_install_fdt(void *fdt)

/* Install device tree */
if (fdt_check_header(fdt)) {
-   printf("ERROR: invalid device tree\n");
+   log_err("ERROR: invalid device tree\n");
return EFI_LOAD_ERROR;
}

/* Prepare device tree for payload */
ret = copy_fdt();
if (ret) {
-   printf("ERROR: out of memory\n");
+   log_err("ERROR: out of memory\n");
return EFI_OUT_OF_RESOURCES;
}

if (image_setup_libfdt(, fdt, 0, NULL)) {
-   printf("ERROR: failed to process device tree\n");
+   log_err("ERROR: failed to process device tree\n");
return EFI_LOAD_ERROR;
}

@@ -308,7 +311,7 @@ efi_status_t efi_install_fdt(void *fdt)
/* Install device tree as UEFI table */
ret = efi_install_configuration_table(_guid_fdt, fdt);
if (ret != EFI_SUCCESS) {
-   printf("ERROR: failed to install device tree\n");
+   log_err("ERROR: failed to install device tree\n");
return ret;
}
 #endif /* GENERATE_ACPI_TABLE */
@@ -339,10 +342,13 @@ static efi_status_t do_bootefi_exec(efi_handle_t handle)

/* Call our payload! */
ret = EFI_CALL(efi_start_image(handle, _data_size, _data));
-   printf("## Application terminated, r = %lu\n", ret & ~EFI_ERROR_MASK);
-   if (ret && exit_data) {
-   printf("## %ls\n", exit_data);
-   efi_free_pool(exit_data);
+   if (ret != EFI_SUCCESS) {
+   log_err("## Application failed, r = %lu\n",
+   

Re: [PATCH v2 1/4] usb: xhci: Add missing endian conversions (cpu_to_leXX / leXX_to_cpu)

2020-07-17 Thread Stefan Roese

Hi Bin,

On 17.07.20 16:14, Bin Meng wrote:

Hi Stefan,

On Fri, Jul 17, 2020 at 10:04 PM Stefan Roese  wrote:


While trying to use the U-Boot xHCI driver on the MIPS Octeon platform,
which is big endian, I noticed that the driver is missing a few endian
conversion calls. This patch adds these missing endian conversion
calls.

Signed-off-by: Stefan Roese 
Reviewed-by: Bin Meng 
Cc: Bin Meng 
Cc: Marek Vasut 
---
v2:
- Add missing (uintptr_t) cast to remove compile time warning

  drivers/usb/host/xhci-mem.c | 9 +
  1 file changed, 5 insertions(+), 4 deletions(-)


Tested-by: Bin Meng 

Only this patch is sent as v2?


Yes. I didn't want to pollute the list with unneeded patches. If you
prefer a complete patchset in the new version, then I can of course
do as as well.

Thanks,
Stefan


[PATCH 1/1] dfu: fix typo parameteres

2020-07-17 Thread Heinrich Schuchardt
%s/parameteres/parameters/g

Even if a line exceeds 80 characters we should not split output strings
to make debugging easier.

Signed-off-by: Heinrich Schuchardt 
---
 common/update.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/common/update.c b/common/update.c
index 5ffac3acfe..8abc7bc02e 100644
--- a/common/update.c
+++ b/common/update.c
@@ -170,8 +170,7 @@ got_update_file:
printf("\n");
if (update_fit_getparams(fit, noffset, _addr,
_fladdr, _size)) {
-   printf("Error: can't get update parameteres, "
-   "aborting\n");
+   printf("Error: can't get update parameters, 
aborting\n");
ret = 1;
goto next_node;
}
--
2.27.0



[PATCH 3/4] clk: add clock driver for SCMI agents

2020-07-17 Thread Etienne Carriere
This change introduces a clock driver for SCMI agent devices. When
SCMI agent and SCMI clock drivers are enabled, SCMI agent binds a
clock device for each SCMI clock protocol devices enabled in the FDT.

SCMI clock driver is embedded upon CONFIG_CLK_SCMI=y. If enabled,
CONFIG_SCMI_AGENT is also enabled.

SCMI Clock protocol is defined in the SCMI specification [1].

Links: [1] 
https://developer.arm.com/architectures/system-architectures/software-standards/scmi
Signed-off-by: Etienne Carriere 
---

 drivers/clk/Kconfig |   8 +++
 drivers/clk/Makefile|   1 +
 drivers/clk/clk_scmi.c  | 152 
 drivers/firmware/scmi.c |   3 +
 4 files changed, 164 insertions(+)
 create mode 100644 drivers/clk/clk_scmi.c

diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig
index 82cb1874e19..234d6035202 100644
--- a/drivers/clk/Kconfig
+++ b/drivers/clk/Kconfig
@@ -152,6 +152,14 @@ config CLK_CDCE9XX
   Enable the clock synthesizer driver for CDCE913/925/937/949
   series of chips.
 
+config CLK_SCMI
+   bool "Enable SCMI clock driver"
+   select SCMI_FIRMWARE
+   help
+ Enable this option if you want to support clock devices exposed
+ by a SCMI agent based on SCMI clock protocol communication
+ with a SCMI server.
+
 source "drivers/clk/analogbits/Kconfig"
 source "drivers/clk/at91/Kconfig"
 source "drivers/clk/exynos/Kconfig"
diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
index d9119545810..76bba77d1f0 100644
--- a/drivers/clk/Makefile
+++ b/drivers/clk/Makefile
@@ -31,6 +31,7 @@ obj-$(CONFIG_CLK_K210) += kendryte/
 obj-$(CONFIG_CLK_MPC83XX) += mpc83xx_clk.o
 obj-$(CONFIG_CLK_OWL) += owl/
 obj-$(CONFIG_CLK_RENESAS) += renesas/
+obj-$(CONFIG_CLK_SCMI) += clk_scmi.o
 obj-$(CONFIG_CLK_SIFIVE) += sifive/
 obj-$(CONFIG_ARCH_SUNXI) += sunxi/
 obj-$(CONFIG_CLK_STM32F) += clk_stm32f.o
diff --git a/drivers/clk/clk_scmi.c b/drivers/clk/clk_scmi.c
new file mode 100644
index 000..efe64a6a38f
--- /dev/null
+++ b/drivers/clk/clk_scmi.c
@@ -0,0 +1,152 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2019-2020 Linaro Limited
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+
+enum scmi_clock_message_id {
+   SCMI_CLOCK_RATE_SET = 0x5,
+   SCMI_CLOCK_RATE_GET = 0x6,
+   SCMI_CLOCK_CONFIG_SET = 0x7,
+};
+
+#define SCMI_CLK_RATE_ASYNC_NOTIFY BIT(0)
+#define SCMI_CLK_RATE_ASYNC_NORESP (BIT(0) | BIT(1))
+#define SCMI_CLK_RATE_ROUND_DOWN   0
+#define SCMI_CLK_RATE_ROUND_UP BIT(2)
+#define SCMI_CLK_RATE_ROUND_CLOSESTBIT(3)
+
+struct scmi_clk_state_in {
+   u32 clock_id;
+   u32 attributes;
+};
+
+struct scmi_clk_state_out {
+   s32 status;
+};
+
+static int scmi_clk_gate(struct clk *clk, int enable)
+{
+   struct scmi_clk_state_in in = {
+   .clock_id = clk->id,
+   .attributes = enable,
+   };
+   struct scmi_clk_state_out out;
+   struct scmi_msg scmi_msg = {
+   .protocol_id = SCMI_PROTOCOL_ID_CLOCK,
+   .message_id = SCMI_CLOCK_CONFIG_SET,
+   .in_msg = (u8 *),
+   .in_msg_sz = sizeof(in),
+   .out_msg = (u8 *),
+   .out_msg_sz = sizeof(out),
+   };
+   int rc;
+
+   rc = scmi_send_and_process_msg(clk->dev->parent, _msg);
+   if (rc)
+   return rc;
+
+   return scmi_to_linux_errno(out.status);
+}
+
+static int scmi_clk_enable(struct clk *clk)
+{
+   return scmi_clk_gate(clk, 1);
+}
+
+static int scmi_clk_disable(struct clk *clk)
+{
+   return scmi_clk_gate(clk, 0);
+}
+
+struct scmi_clk_rate_get_in {
+   u32 clock_id;
+};
+
+struct scmi_clk_rate_get_out {
+   s32 status;
+   u32 rate_lsb;
+   u32 rate_msb;
+};
+
+static ulong scmi_clk_get_rate(struct clk *clk)
+{
+   struct scmi_clk_rate_get_in in = {
+   .clock_id = clk->id,
+   };
+   struct scmi_clk_rate_get_out out;
+   struct scmi_msg scmi_msg = {
+   .protocol_id = SCMI_PROTOCOL_ID_CLOCK,
+   .message_id = SCMI_CLOCK_RATE_GET,
+   .in_msg = (u8 *),
+   .in_msg_sz = sizeof(in),
+   .out_msg = (u8 *),
+   .out_msg_sz = sizeof(out),
+   };
+   int rc;
+
+   rc = scmi_send_and_process_msg(clk->dev->parent, _msg);
+   if (rc)
+   return 0;
+
+   rc = scmi_to_linux_errno(out.status);
+   if (rc)
+   return 0;
+
+   return (ulong)(((u64)out.rate_msb << 32) | out.rate_lsb);
+}
+
+struct scmi_clk_rate_set_in {
+   u32 clock_id;
+   u32 flags;
+   u32 rate_lsb;
+   u32 rate_msb;
+};
+
+struct scmi_clk_rate_set_out {
+   s32 status;
+};
+
+static ulong scmi_clk_set_rate(struct clk *clk, ulong rate)
+{
+   struct scmi_clk_rate_set_in in = {
+   .clock_id = clk->id,
+   .flags = SCMI_CLK_RATE_ASYNC_NORESP |
+

[PATCH 1/4] firmware: add new driver for SCMI firmwares

2020-07-17 Thread Etienne Carriere
This change introduces SCMI agent driver in U-Boot in the firmware
U-class.

SCMI agent driver is designed for platforms that embed a SCMI server in
a firmware hosted for example by a companion co-processor or the secure
world of the executing processor.

SCMI protocols allow an SCMI agent to discover and access external
resources as clock, reset controllers and many more. SCMI agent and
server communicate following the SCMI specification [1]. SCMI agent
complies with the DT bindings defined in the Linux kernel source tree
regarding SCMI agent description since v5.8-rc1.

These bindings describe 2 supported message transport layer: using
mailbox uclass devices or using Arm SMC invocation instruction. Both
use a piece or shared memory for message data exchange.

In the current state, the SCMI agent driver does not bind to any SCMI
protocol to a U-Boot device driver. Former changes will implement
dedicated driver (i.e. an SCMI clock driver or an SCMI reset controller
driver) and add bind supported SCMI protocols in scmi_agent_bind().

Links: [1] 
https://developer.arm.com/architectures/system-architectures/software-standards/scmi
Signed-off-by: Etienne Carriere 
---

 drivers/firmware/Kconfig  |  15 ++
 drivers/firmware/Makefile |   1 +
 drivers/firmware/scmi.c   | 439 ++
 include/scmi.h|  82 +++
 4 files changed, 537 insertions(+)
 create mode 100644 drivers/firmware/scmi.c
 create mode 100644 include/scmi.h

diff --git a/drivers/firmware/Kconfig b/drivers/firmware/Kconfig
index b70a2063551..f7c7ee7a5aa 100644
--- a/drivers/firmware/Kconfig
+++ b/drivers/firmware/Kconfig
@@ -1,6 +1,21 @@
 config FIRMWARE
bool "Enable Firmware driver support"
 
+config SCMI_FIRMWARE
+   bool "Enable SCMI support"
+   select FIRMWARE
+   select OF_TRANSLATE
+   depends on DM_MAILBOX || ARM_SMCCC
+   help
+ An SCMI agent communicates with a related SCMI server firmware
+ located in another sub-system, as a companion micro controller
+ or a companion host in the CPU system.
+
+ Communications between agent (client) and the SCMI server are
+ based on message exchange. Messages can be exchange over tranport
+ channels as a mailbox device or an Arm SMCCC service with some
+ piece of identified shared memory.
+
 config SPL_FIRMWARE
bool "Enable Firmware driver support in SPL"
depends on FIRMWARE
diff --git a/drivers/firmware/Makefile b/drivers/firmware/Makefile
index a0c250a473e..3965838179f 100644
--- a/drivers/firmware/Makefile
+++ b/drivers/firmware/Makefile
@@ -2,4 +2,5 @@ obj-$(CONFIG_FIRMWARE)  += firmware-uclass.o
 obj-$(CONFIG_$(SPL_)ARM_PSCI_FW)   += psci.o
 obj-$(CONFIG_TI_SCI_PROTOCOL)  += ti_sci.o
 obj-$(CONFIG_SANDBOX)  += firmware-sandbox.o
+obj-$(CONFIG_SCMI_FIRMWARE)+= scmi.o
 obj-$(CONFIG_ZYNQMP_FIRMWARE)  += firmware-zynqmp.o
diff --git a/drivers/firmware/scmi.c b/drivers/firmware/scmi.c
new file mode 100644
index 000..fa8a91c3f3d
--- /dev/null
+++ b/drivers/firmware/scmi.c
@@ -0,0 +1,439 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2015-2019, Arm Limited and Contributors. All rights reserved.
+ * Copyright (C) 2019-2020 Linaro Limited.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define TIMEOUT_US_10MS1
+
+struct error_code {
+   int scmi;
+   int errno;
+};
+
+static const struct error_code scmi_linux_errmap[] = {
+   { .scmi = SCMI_NOT_SUPPORTED, .errno = -EOPNOTSUPP, },
+   { .scmi = SCMI_INVALID_PARAMETERS, .errno = -EINVAL, },
+   { .scmi = SCMI_DENIED, .errno = -EACCES, },
+   { .scmi = SCMI_NOT_FOUND, .errno = -ENOENT, },
+   { .scmi = SCMI_OUT_OF_RANGE, .errno = -ERANGE, },
+   { .scmi = SCMI_BUSY, .errno = -EBUSY, },
+   { .scmi = SCMI_COMMS_ERROR, .errno = -ECOMM, },
+   { .scmi = SCMI_GENERIC_ERROR, .errno = -EIO, },
+   { .scmi = SCMI_HARDWARE_ERROR, .errno = -EREMOTEIO, },
+   { .scmi = SCMI_PROTOCOL_ERROR, .errno = -EPROTO, },
+};
+
+int scmi_to_linux_errno(s32 scmi_code)
+{
+   int n;
+
+   if (scmi_code == 0)
+   return 0;
+
+   for (n = 0; n < ARRAY_SIZE(scmi_linux_errmap); n++)
+   if (scmi_code == scmi_linux_errmap[n].scmi)
+   return scmi_linux_errmap[1].errno;
+
+   return -EPROTO;
+}
+
+struct method_ops {
+   int (*process_msg)(struct udevice *dev, struct scmi_msg *msg);
+   int (*remove_agent)(struct udevice *dev);
+};
+
+struct scmi_agent {
+   struct method_ops *method_ops;
+   void *method_priv;
+};
+
+/*
+ * Shared Memory based Transport (SMT) message buffer management
+ *
+ * SMT uses 28 byte header prior message payload to handle the state of
+ * the communication channel 

[PATCH 4/4] reset: add reset controller driver for SCMI agents

2020-07-17 Thread Etienne Carriere
This change introduces a reset controller driver for SCMI agent devices.
When SCMI agent and SCMI reset domain drivers are enabled, SCMI agent
binds a reset controller device for each SCMI reset domain protocol
devices enabled in the FDT.

SCMI reset driver is embedded upon CONFIG_RESET_SCMI=y. If enabled,
CONFIG_SCMI_AGENT is also enabled.

SCMI Reset Domain protocol is defined in the SCMI specification [1].

Links: [1] 
https://developer.arm.com/architectures/system-architectures/software-standards/scmi
Signed-off-by: Etienne Carriere 
---

 drivers/firmware/scmi.c|  3 ++
 drivers/reset/Kconfig  |  8 
 drivers/reset/Makefile |  1 +
 drivers/reset/reset-scmi.c | 86 ++
 4 files changed, 98 insertions(+)
 create mode 100644 drivers/reset/reset-scmi.c

diff --git a/drivers/firmware/scmi.c b/drivers/firmware/scmi.c
index 9f06718df51..9be53a9cf11 100644
--- a/drivers/firmware/scmi.c
+++ b/drivers/firmware/scmi.c
@@ -402,6 +402,9 @@ static int scmi_bind(struct udevice *dev)
case SCMI_PROTOCOL_ID_CLOCK:
drv = DM_GET_DRIVER(scmi_clock);
break;
+   case SCMI_PROTOCOL_ID_RESET_DOMAIN:
+   drv = DM_GET_DRIVER(scmi_reset_domain);
+   break;
default:
dev_info(dev, "Ignore unsupported SCMI protocol %u\n",
 protocol_id);
diff --git a/drivers/reset/Kconfig b/drivers/reset/Kconfig
index 6d535612234..31bd4cd5b45 100644
--- a/drivers/reset/Kconfig
+++ b/drivers/reset/Kconfig
@@ -164,4 +164,12 @@ config RESET_RASPBERRYPI
  relevant. This driver provides a reset controller capable of
  interfacing with RPi4's co-processor and model these firmware
  initialization routines as reset lines.
+
+config RESET_SCMI
+   bool "Enable SCMI reset domain driver"
+   select SCMI_FIRMWARE
+   help
+ Enable this option if you want to support reset controller
+ devices exposed by a SCMI agent based on SCMI reset domain
+ protocol communication with a SCMI server.
 endmenu
diff --git a/drivers/reset/Makefile b/drivers/reset/Makefile
index 8e0124b8dee..f3c0fbfd8f3 100644
--- a/drivers/reset/Makefile
+++ b/drivers/reset/Makefile
@@ -25,3 +25,4 @@ obj-$(CONFIG_RESET_HISILICON) += reset-hisilicon.o
 obj-$(CONFIG_RESET_IMX7) += reset-imx7.o
 obj-$(CONFIG_RESET_SYSCON) += reset-syscon.o
 obj-$(CONFIG_RESET_RASPBERRYPI) += reset-raspberrypi.o
+obj-$(CONFIG_RESET_SCMI) += reset-scmi.o
diff --git a/drivers/reset/reset-scmi.c b/drivers/reset/reset-scmi.c
new file mode 100644
index 000..e664d91d865
--- /dev/null
+++ b/drivers/reset/reset-scmi.c
@@ -0,0 +1,86 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2019-2020 Linaro Limited
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+enum scmi_reset_domain_message_id {
+   SCMI_RESET_DOMAIN_RESET = 0x4,
+};
+
+#define SCMI_RD_RESET_FLAG_ASSERT  BIT(1)
+#define SCMI_RD_RESET_FLAG_DEASSERT0
+
+struct scmi_rd_reset_in {
+   u32 domain_id;
+   u32 flags;
+   u32 reset_state;
+};
+
+struct scmi_rd_reset_out {
+   s32 status;
+};
+
+static int scmi_reset_set_state(struct reset_ctl *rst, int assert_not_deassert)
+{
+   struct scmi_rd_reset_in in = {
+   .domain_id = rst->id,
+   .flags = assert_not_deassert ? SCMI_RD_RESET_FLAG_ASSERT :
+SCMI_RD_RESET_FLAG_DEASSERT,
+   .reset_state = 0,
+   };
+   struct scmi_rd_reset_out out;
+   struct scmi_msg scmi_msg = {
+   .protocol_id = SCMI_PROTOCOL_ID_RESET_DOMAIN,
+   .message_id = SCMI_RESET_DOMAIN_RESET,
+   .in_msg = (u8 *),
+   .in_msg_sz = sizeof(in),
+   .out_msg = (u8 *),
+   .out_msg_sz = sizeof(out),
+   };
+   int rc;
+
+   rc = scmi_send_and_process_msg(rst->dev->parent, _msg);
+   if (rc)
+   return rc;
+
+   return scmi_to_linux_errno(out.status);
+}
+
+static int scmi_reset_assert(struct reset_ctl *rst)
+{
+   return scmi_reset_set_state(rst, SCMI_RD_RESET_FLAG_ASSERT);
+}
+
+static int scmi_reset_deassert(struct reset_ctl *rst)
+{
+   return scmi_reset_set_state(rst, SCMI_RD_RESET_FLAG_DEASSERT);
+}
+
+static int scmi_reset_request(struct reset_ctl *reset_ctl)
+{
+   return 0;
+}
+
+static int scmi_reset_rfree(struct reset_ctl *reset_ctl)
+{
+   return 0;
+}
+
+static const struct reset_ops scmi_reset_domain_ops = {
+   .request= scmi_reset_request,
+   .rfree  = scmi_reset_rfree,
+   .rst_assert = scmi_reset_assert,
+   .rst_deassert   = scmi_reset_deassert,
+};
+
+U_BOOT_DRIVER(scmi_reset_domain) = {
+   .name = "scmi_reset_domain",
+   .id = UCLASS_RESET,
+   .ops = _reset_domain_ops,
+};
-- 
2.17.1



[PATCH 2/4] dt-bindings: arm: SCMI bindings documentation

2020-07-17 Thread Etienne Carriere
Dump SCMI DT bindings documentation from Linux kernel source
tree v5.8-rc1.

Signed-off-by: Etienne Carriere 
---

 doc/device-tree-bindings/arm/arm,scmi.txt | 197 ++
 1 file changed, 197 insertions(+)
 create mode 100644 doc/device-tree-bindings/arm/arm,scmi.txt

diff --git a/doc/device-tree-bindings/arm/arm,scmi.txt 
b/doc/device-tree-bindings/arm/arm,scmi.txt
new file mode 100644
index 000..1f293ea24cd
--- /dev/null
+++ b/doc/device-tree-bindings/arm/arm,scmi.txt
@@ -0,0 +1,197 @@
+System Control and Management Interface (SCMI) Message Protocol
+--
+
+The SCMI is intended to allow agents such as OSPM to manage various functions
+that are provided by the hardware platform it is running on, including power
+and performance functions.
+
+This binding is intended to define the interface the firmware implementing
+the SCMI as described in ARM document number ARM DEN 0056A ("ARM System Control
+and Management Interface Platform Design Document")[0] provide for OSPM in
+the device tree.
+
+Required properties:
+
+The scmi node with the following properties shall be under the /firmware/ node.
+
+- compatible : shall be "arm,scmi" or "arm,scmi-smc" for smc/hvc transports
+- mboxes: List of phandle and mailbox channel specifiers. It should contain
+ exactly one or two mailboxes, one for transmitting messages("tx")
+ and another optional for receiving the notifications("rx") if
+ supported.
+- shmem : List of phandle pointing to the shared memory(SHM) area as per
+ generic mailbox client binding.
+- #address-cells : should be '1' if the device has sub-nodes, maps to
+ protocol identifier for a given sub-node.
+- #size-cells : should be '0' as 'reg' property doesn't have any size
+ associated with it.
+- arm,smc-id : SMC id required when using smc or hvc transports
+
+Optional properties:
+
+- mbox-names: shall be "tx" or "rx" depending on mboxes entries.
+
+See Documentation/devicetree/bindings/mailbox/mailbox.txt for more details
+about the generic mailbox controller and client driver bindings.
+
+The mailbox is the only permitted method of calling the SCMI firmware.
+Mailbox doorbell is used as a mechanism to alert the presence of a
+messages and/or notification.
+
+Each protocol supported shall have a sub-node with corresponding compatible
+as described in the following sections. If the platform supports dedicated
+communication channel for a particular protocol, the 3 properties namely:
+mboxes, mbox-names and shmem shall be present in the sub-node corresponding
+to that protocol.
+
+Clock/Performance bindings for the clocks/OPPs based on SCMI Message Protocol
+
+
+This binding uses the common clock binding[1].
+
+Required properties:
+- #clock-cells : Should be 1. Contains the Clock ID value used by SCMI 
commands.
+
+Power domain bindings for the power domains based on SCMI Message Protocol
+
+
+This binding for the SCMI power domain providers uses the generic power
+domain binding[2].
+
+Required properties:
+ - #power-domain-cells : Should be 1. Contains the device or the power
+domain ID value used by SCMI commands.
+
+Sensor bindings for the sensors based on SCMI Message Protocol
+--
+SCMI provides an API to access the various sensors on the SoC.
+
+Required properties:
+- #thermal-sensor-cells: should be set to 1. This property follows the
+thermal device tree bindings[3].
+
+Valid cell values are raw identifiers (Sensor ID)
+as used by the firmware. Refer to  platform details
+for your implementation for the IDs to use.
+
+Reset signal bindings for the reset domains based on SCMI Message Protocol
+
+
+This binding for the SCMI reset domain providers uses the generic reset
+signal binding[5].
+
+Required properties:
+ - #reset-cells : Should be 1. Contains the reset domain ID value used
+ by SCMI commands.
+
+SRAM and Shared Memory for SCMI
+---
+
+A small area of SRAM is reserved for SCMI communication between application
+processors and SCP.
+
+The properties should follow the generic mmio-sram description found in [4]
+
+Each sub-node represents the reserved area for SCMI.
+
+Required sub-node properties:
+- reg : The base offset and size of the reserved area with the SRAM
+- compatible : should be "arm,scmi-shmem" for Non-secure SRAM based
+  shared memory
+
+[0] http://infocenter.arm.com/help/topic/com.arm.doc.den0056a/index.html
+[1] Documentation/devicetree/bindings/clock/clock-bindings.txt
+[2] Documentation/devicetree/bindings/power/power-domain.yaml
+[3] 

Re: [PATCH] dm: core: Don't show an ACPI warning if there is no ordering

2020-07-17 Thread Bin Meng
On Fri, Jul 17, 2020 at 10:49 PM Simon Glass  wrote:
>
> Some boards don't care about the ordering of ACPI code fragments. Change
> the warning to a debug message.
>
> Signed-off-by: Simon Glass 
> ---
>
>  drivers/core/acpi.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>

Reviewed-by: Bin Meng 


[PATCH v6 20/25] x86: mtrr: Add support for writing to MTRRs on any CPU

2020-07-17 Thread Simon Glass
To enable support for the 'mtrr' command, add a way to perform MTRR
operations on selected CPUs.

This works by setting up a little 'operation' structure and sending it
around the CPUs for action.

Signed-off-by: Simon Glass 
Reviewed-by: Bin Meng 
Reviewed-by: Wolfgang Wallner 
---

(no changes since v2)

Changes in v2:
- Keep things building by temporarily renaming the function in cmd/

 arch/x86/cpu/mtrr.c | 81 +
 arch/x86/include/asm/mtrr.h | 21 ++
 cmd/x86/mtrr.c  |  6 +--
 3 files changed, 105 insertions(+), 3 deletions(-)

diff --git a/arch/x86/cpu/mtrr.c b/arch/x86/cpu/mtrr.c
index 5c567551e5..2468d88a80 100644
--- a/arch/x86/cpu/mtrr.c
+++ b/arch/x86/cpu/mtrr.c
@@ -221,3 +221,84 @@ int mtrr_set_next_var(uint type, uint64_t start, uint64_t 
size)
 
return 0;
 }
+
+/** enum mtrr_opcode - supported operations for mtrr_do_oper() */
+enum mtrr_opcode {
+   MTRR_OP_SET,
+   MTRR_OP_SET_VALID,
+};
+
+/**
+ * struct mtrr_oper - An MTRR operation to perform on a CPU
+ *
+ * @opcode: Indicates operation to perform
+ * @reg: MTRR reg number to select (0-7, -1 = all)
+ * @valid: Valid value to write for MTRR_OP_SET_VALID
+ * @base: Base value to write for MTRR_OP_SET
+ * @mask: Mask value to write for MTRR_OP_SET
+ */
+struct mtrr_oper {
+   enum mtrr_opcode opcode;
+   int reg;
+   bool valid;
+   u64 base;
+   u64 mask;
+};
+
+static void mtrr_do_oper(void *arg)
+{
+   struct mtrr_oper *oper = arg;
+   u64 mask;
+
+   switch (oper->opcode) {
+   case MTRR_OP_SET_VALID:
+   mask = native_read_msr(MTRR_PHYS_MASK_MSR(oper->reg));
+   if (oper->valid)
+   mask |= MTRR_PHYS_MASK_VALID;
+   else
+   mask &= ~MTRR_PHYS_MASK_VALID;
+   wrmsrl(MTRR_PHYS_MASK_MSR(oper->reg), mask);
+   break;
+   case MTRR_OP_SET:
+   wrmsrl(MTRR_PHYS_BASE_MSR(oper->reg), oper->base);
+   wrmsrl(MTRR_PHYS_MASK_MSR(oper->reg), oper->mask);
+   break;
+   }
+}
+
+static int mtrr_start_op(int cpu_select, struct mtrr_oper *oper)
+{
+   struct mtrr_state state;
+   int ret;
+
+   mtrr_open(, true);
+   ret = mp_run_on_cpus(cpu_select, mtrr_do_oper, oper);
+   mtrr_close(, true);
+   if (ret)
+   return log_msg_ret("run", ret);
+
+   return 0;
+}
+
+int mtrr_set_valid(int cpu_select, int reg, bool valid)
+{
+   struct mtrr_oper oper;
+
+   oper.opcode = MTRR_OP_SET_VALID;
+   oper.reg = reg;
+   oper.valid = valid;
+
+   return mtrr_start_op(cpu_select, );
+}
+
+int mtrr_set(int cpu_select, int reg, u64 base, u64 mask)
+{
+   struct mtrr_oper oper;
+
+   oper.opcode = MTRR_OP_SET;
+   oper.reg = reg;
+   oper.base = base;
+   oper.mask = mask;
+
+   return mtrr_start_op(cpu_select, );
+}
diff --git a/arch/x86/include/asm/mtrr.h b/arch/x86/include/asm/mtrr.h
index e1f1a44643..48db1dd82f 100644
--- a/arch/x86/include/asm/mtrr.h
+++ b/arch/x86/include/asm/mtrr.h
@@ -159,6 +159,27 @@ int mtrr_set_next_var(uint type, uint64_t base, uint64_t 
size);
  */
 void mtrr_read_all(struct mtrr_info *info);
 
+/**
+ * mtrr_set_valid() - Set the valid flag for a selected MTRR and CPU(s)
+ *
+ * @cpu_select: Selected CPUs (either a CPU number or MP_SELECT_...)
+ * @reg: MTRR register to write (0-7)
+ * @valid: Valid flag to write
+ * @return 0 on success, -ve on error
+ */
+int mtrr_set_valid(int cpu_select, int reg, bool valid);
+
+/**
+ * mtrr_set() - Set the valid flag for a selected MTRR and CPU(s)
+ *
+ * @cpu_select: Selected CPUs (either a CPU number or MP_SELECT_...)
+ * @reg: MTRR register to write (0-7)
+ * @base: Base address and MTRR_BASE_TYPE_MASK
+ * @mask: Mask and MTRR_PHYS_MASK_VALID
+ * @return 0 on success, -ve on error
+ */
+int mtrr_set(int cpu_select, int reg, u64 base, u64 mask);
+
 #endif
 
 #if ((CONFIG_XIP_ROM_SIZE & (CONFIG_XIP_ROM_SIZE - 1)) != 0)
diff --git a/cmd/x86/mtrr.c b/cmd/x86/mtrr.c
index f357f58767..46ef6a2830 100644
--- a/cmd/x86/mtrr.c
+++ b/cmd/x86/mtrr.c
@@ -96,7 +96,7 @@ static int do_mtrr_set(uint reg, int argc, char *const argv[])
return 0;
 }
 
-static int mtrr_set_valid(int reg, bool valid)
+static int mtrr_set_valid_(int reg, bool valid)
 {
struct mtrr_state state;
uint64_t mask;
@@ -134,9 +134,9 @@ static int do_mtrr(struct cmd_tbl *cmdtp, int flag, int 
argc,
return CMD_RET_USAGE;
}
if (*cmd == 'e')
-   return mtrr_set_valid(reg, true);
+   return mtrr_set_valid_(reg, true);
else if (*cmd == 'd')
-   return mtrr_set_valid(reg, false);
+   return mtrr_set_valid_(reg, false);
else if (*cmd == 's')
return do_mtrr_set(reg, argc - 1, argv + 1);
else
-- 
2.28.0.rc0.105.gf9edc3c819-goog



[PATCH v6 16/25] x86: mtrr: Use MP calls to list the MTRRs

2020-07-17 Thread Simon Glass
Update the mtrr command to use mp_run_on_cpus() to obtain its information.
Since the selected CPU is the boot CPU this does not change the result,
but it sets the stage for supporting other CPUs.

Signed-off-by: Simon Glass 
Reviewed-by: Wolfgang Wallner 
Reviewed-by: Bin Meng 
---

(no changes since v2)

Changes in v2:
- Rename mtrr_save_all() to mtrr_read_all()

 arch/x86/cpu/mtrr.c | 11 +++
 arch/x86/include/asm/mtrr.h | 30 ++
 cmd/x86/mtrr.c  | 25 +
 3 files changed, 62 insertions(+), 4 deletions(-)

diff --git a/arch/x86/cpu/mtrr.c b/arch/x86/cpu/mtrr.c
index 7ec077..c9b4e7d06e 100644
--- a/arch/x86/cpu/mtrr.c
+++ b/arch/x86/cpu/mtrr.c
@@ -21,6 +21,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -63,6 +64,16 @@ static void set_var_mtrr(uint reg, uint type, uint64_t 
start, uint64_t size)
wrmsrl(MTRR_PHYS_MASK_MSR(reg), mask | MTRR_PHYS_MASK_VALID);
 }
 
+void mtrr_read_all(struct mtrr_info *info)
+{
+   int i;
+
+   for (i = 0; i < MTRR_COUNT; i++) {
+   info->mtrr[i].base = native_read_msr(MTRR_PHYS_BASE_MSR(i));
+   info->mtrr[i].mask = native_read_msr(MTRR_PHYS_MASK_MSR(i));
+   }
+}
+
 int mtrr_commit(bool do_caches)
 {
struct mtrr_request *req = gd->arch.mtrr_req;
diff --git a/arch/x86/include/asm/mtrr.h b/arch/x86/include/asm/mtrr.h
index 212a699c1b..e1f1a44643 100644
--- a/arch/x86/include/asm/mtrr.h
+++ b/arch/x86/include/asm/mtrr.h
@@ -70,6 +70,26 @@ struct mtrr_state {
bool enable_cache;
 };
 
+/**
+ * struct mtrr - Information about a single MTRR
+ *
+ * @base: Base address and MTRR_BASE_TYPE_MASK
+ * @mask: Mask and MTRR_PHYS_MASK_VALID
+ */
+struct mtrr {
+   u64 base;
+   u64 mask;
+};
+
+/**
+ * struct mtrr_info - Information about all MTRRs
+ *
+ * @mtrr: Information about each mtrr
+ */
+struct mtrr_info {
+   struct mtrr mtrr[MTRR_COUNT];
+};
+
 /**
  * mtrr_open() - Prepare to adjust MTRRs
  *
@@ -129,6 +149,16 @@ int mtrr_commit(bool do_caches);
  */
 int mtrr_set_next_var(uint type, uint64_t base, uint64_t size);
 
+/**
+ * mtrr_read_all() - Save all the MTRRs
+ *
+ * This reads all MTRRs from the boot CPU into a struct so they can be loaded
+ * onto other CPUs
+ *
+ * @info: Place to put the MTRR info
+ */
+void mtrr_read_all(struct mtrr_info *info);
+
 #endif
 
 #if ((CONFIG_XIP_ROM_SIZE & (CONFIG_XIP_ROM_SIZE - 1)) != 0)
diff --git a/cmd/x86/mtrr.c b/cmd/x86/mtrr.c
index 5d25c5802a..f357f58767 100644
--- a/cmd/x86/mtrr.c
+++ b/cmd/x86/mtrr.c
@@ -5,7 +5,9 @@
 
 #include 
 #include 
+#include 
 #include 
+#include 
 #include 
 
 static const char *const mtrr_type_name[MTRR_TYPE_COUNT] = {
@@ -18,19 +20,32 @@ static const char *const mtrr_type_name[MTRR_TYPE_COUNT] = {
"Back",
 };
 
-static int do_mtrr_list(void)
+static void read_mtrrs(void *arg)
 {
+   struct mtrr_info *info = arg;
+
+   mtrr_read_all(info);
+}
+
+static int do_mtrr_list(int cpu_select)
+{
+   struct mtrr_info info;
+   int ret;
int i;
 
printf("Reg Valid Write-type   %-16s %-16s %-16s\n", "Base   ||",
   "Mask   ||", "Size   ||");
+   memset(, '\0', sizeof(info));
+   ret = mp_run_on_cpus(cpu_select, read_mtrrs, );
+   if (ret)
+   return log_msg_ret("run", ret);
for (i = 0; i < MTRR_COUNT; i++) {
const char *type = "Invalid";
uint64_t base, mask, size;
bool valid;
 
-   base = native_read_msr(MTRR_PHYS_BASE_MSR(i));
-   mask = native_read_msr(MTRR_PHYS_MASK_MSR(i));
+   base = info.mtrr[i].base;
+   mask = info.mtrr[i].mask;
size = ~mask & ((1ULL << CONFIG_CPU_ADDR_BITS) - 1);
size |= (1 << 12) - 1;
size += 1;
@@ -102,11 +117,13 @@ static int do_mtrr(struct cmd_tbl *cmdtp, int flag, int 
argc,
   char *const argv[])
 {
const char *cmd;
+   int cpu_select;
uint reg;
 
+   cpu_select = MP_SELECT_BSP;
cmd = argv[1];
if (argc < 2 || *cmd == 'l')
-   return do_mtrr_list();
+   return do_mtrr_list(cpu_select);
argc -= 2;
argv += 2;
if (argc <= 0)
-- 
2.28.0.rc0.105.gf9edc3c819-goog



[PATCH v6 18/25] x86: coral: Update the memory map

2020-07-17 Thread Simon Glass
This currently excludes the temporary memory used to start up the APs.
Add it.

Signed-off-by: Simon Glass 
Reviewed-by: Bin Meng 
Reviewed-by: Wolfgang Wallner 
---

(no changes since v2)

Changes in v2:
- Add new patch to add AP_DEFAULT_BASE to coral's memory map

 doc/board/google/chromebook_coral.rst | 1 +
 1 file changed, 1 insertion(+)

diff --git a/doc/board/google/chromebook_coral.rst 
b/doc/board/google/chromebook_coral.rst
index 40bd9397d4..c39f1e310c 100644
--- a/doc/board/google/chromebook_coral.rst
+++ b/doc/board/google/chromebook_coral.rst
@@ -188,6 +188,7 @@ Partial memory map
 fef0  1000 CONFIG_BOOTSTAGE_STASH_ADDR
 fef0   Base of CAR region
 
+   3   AP_DEFAULT_BASE (used to start up additional CPUs)
f   CONFIG_ROM_TABLE_ADDR
   12   BSS (defined in u-boot-spl.lds)
   20   FSP-S (which is run after U-Boot is relocated)
-- 
2.28.0.rc0.105.gf9edc3c819-goog



Re: [GIT PULL] Pull request: u-boot-imx u-boot-imx-20200716

2020-07-17 Thread Tom Rini
On Thu, Jul 16, 2020 at 10:01:19PM +0200, Stefano Babic wrote:

> Hi Tom,
> 
> please pull from u-boot-imx, thanks !
> 
> The following changes since commit 497c7598c4e713eb9ad88fd7963e57b21b8b35e1:
> 
>   Merge branch 'master' of
> https://gitlab.denx.de/u-boot/custodians/u-boot-spi (2020-07-11 17:40:00
> -0400)
> 
> are available in the Git repository at:
> 
>   https://gitlab.denx.de/u-boot/custodians/u-boot-imx.git
> tags/u-boot-imx-20200716
> 
> for you to fetch changes up to ab8b4e818cbc3846672c13b12f1d75daccfac519:
> 
>   mx6memcal: fix build (2020-07-16 15:11:18 +0200)
> 

Please note there's a bunch of whitespace errors in
drivers/ddr/imx/imx8m/ddrphy_utils.c, a single one in
arch/arm/mach-imx/imx8m/soc.c and
drivers/pinctrl/nxp/pinctrl-imx*.c has some warnings about using
__section(..) vs __attribute__((section(..))) but these are all things
that can be addressed with this merged.  So, applied to u-boot/master,
thanks!

-- 
Tom


signature.asc
Description: PGP signature


[PATCH] dm: core: Don't show an ACPI warning if there is no ordering

2020-07-17 Thread Simon Glass
Some boards don't care about the ordering of ACPI code fragments. Change
the warning to a debug message.

Signed-off-by: Simon Glass 
---

 drivers/core/acpi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/core/acpi.c b/drivers/core/acpi.c
index cdbc2c5cf5..7fe93992b5 100644
--- a/drivers/core/acpi.c
+++ b/drivers/core/acpi.c
@@ -195,7 +195,7 @@ static int sort_acpi_item_type(struct acpi_ctx *ctx, void 
*start,
"u-boot,acpi-dsdt-order" :
"u-boot,acpi-ssdt-order", );
if (!order) {
-   log_warning("Failed to find ordering, leaving as is\n");
+   log_debug("Failed to find ordering, leaving as is\n");
return 0;
}
 
-- 
2.28.0.rc0.105.gf9edc3c819-goog



[PATCH v6 24/25] x86: mp: Add more comments to the module

2020-07-17 Thread Simon Glass
Add a description of how this module works and also some missing function
comments.

Reviewed-by: Wolfgang Wallner 
Signed-off-by: Simon Glass 
Reviewed-by: Bin Meng 
---

(no changes since v3)

Changes in v3:
- Remove stray asterisk from comments
- Drop mention of cpu_map which was handled in a previous patch

Changes in v2:
- Add a new patch with more comments

 arch/x86/cpu/mp_init.c| 91 ++-
 arch/x86/include/asm/mp.h | 14 +-
 2 files changed, 102 insertions(+), 3 deletions(-)

diff --git a/arch/x86/cpu/mp_init.c b/arch/x86/cpu/mp_init.c
index c373c3099a..d2f1ee38cf 100644
--- a/arch/x86/cpu/mp_init.c
+++ b/arch/x86/cpu/mp_init.c
@@ -32,13 +32,99 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
+/*
+ * Setting up multiprocessing
+ *
+ * See 
https://www.intel.com/content/www/us/en/intelligent-systems/intel-boot-loader-development-kit/minimal-intel-architecture-boot-loader-paper.html
+ *
+ * Note that this file refers to the boot CPU (the one U-Boot is running on) as
+ * the BSP (BootStrap Processor) and the others as APs (Application 
Processors).
+ *
+ * This module works by loading some setup code into RAM at AP_DEFAULT_BASE and
+ * telling each AP to execute it. The code that each AP runs is in
+ * sipi_vector.S (see ap_start16) which includes a struct sipi_params at the
+ * end of it. Those parameters are set up by the C code.
+
+ * Setting up is handled by load_sipi_vector(). It inits the common block of
+ * parameters (sipi_params) which tell the APs what to do. This block includes
+ * microcode and the MTTRs (Memory-Type-Range Registers) from the main CPU.
+ * There is also an ap_count which each AP increments as it starts up, so the
+ * BSP can tell how many checked in.
+ *
+ * The APs are started with a SIPI (Startup Inter-Processor Interrupt) which
+ * tells an AP to start executing at a particular address, in this case
+ * AP_DEFAULT_BASE which contains the code copied from ap_start16. This 
protocol
+ * is handled by start_aps().
+ *
+ * After being started, each AP runs the code in ap_start16, switches to 32-bit
+ * mode, runs the code at ap_start, then jumps to c_handler which is ap_init().
+ * This runs a very simple 'flight plan' described in mp_steps(). This sets up
+ * the CPU and waits for further instructions by looking at its entry in
+ * ap_callbacks[]. Note that the flight plan is only actually run for each CPU
+ * in bsp_do_flight_plan(): once the BSP completes each flight record, it sets
+ * mp_flight_record->barrier to 1 to allow the APs to executed the record one
+ * by one.
+ *
+ * CPUS are numbered sequentially from 0 using the device tree:
+ *
+ * cpus {
+ * u-boot,dm-pre-reloc;
+ * #address-cells = <1>;
+ * #size-cells = <0>;
+ *
+ * cpu@0 {
+ * u-boot,dm-pre-reloc;
+ * device_type = "cpu";
+ * compatible = "intel,apl-cpu";
+ * reg = <0>;
+ * intel,apic-id = <0>;
+ * };
+ *
+ * cpu@1 {
+ * device_type = "cpu";
+ * compatible = "intel,apl-cpu";
+ * reg = <1>;
+ * intel,apic-id = <2>;
+ * };
+ *
+ * Here the 'reg' property is the CPU number and then is placed in dev->req_seq
+ * so that we can index into ap_callbacks[] using that. The APIC ID is 
different
+ * and may not be sequential (it typically is if hyperthreading is supported).
+ *
+ * Once APs are inited they wait in ap_wait_for_instruction() for instructions.
+ * Instructions come in the form of a function to run. This logic is in
+ * mp_run_on_cpus() which supports running on any one AP, all APs, just the BSP
+ * or all CPUs. The BSP logic is handled directly in mp_run_on_cpus(), by
+ * calling the function. For the APs, callback information is stored in a
+ * single, common struct mp_callback and a pointer to this is written to each
+ * AP's slot in ap_callbacks[] by run_ap_work(). All APs get the message even
+ * if it is only for one of them. When an AP notices a message it checks 
whether
+ * it should call the function (see check in ap_wait_for_instruction()) and 
then
+ * does so if needed. After that it sets its slot to NULL to indicate it is
+ * done.
+ *
+ * While U-Boot is running it can use mp_run_on_cpus() to run code on the APs.
+ * An example of this is the 'mtrr' command which allows reading and changing
+ * the MTRRs on all CPUs.
+ *
+ * Before U-Boot exits it calls mp_park_aps() which tells all CPUs to halt by
+ * executing a 'hlt' instruction. That allows them to be used by Linux when it
+ * starts up.
+ */
+
 /* This also needs to match the sipi.S assembly code for saved MSR encoding */
-struct saved_msr {
+struct __packed saved_msr {
uint32_t index;
uint32_t lo;
uint32_t hi;
-} __packed;
+};
 
+/**
+ * struct mp_flight_plan - Holds the flight plan
+ *
+ * @num_records: Number of 

[PATCH v6 25/25] x86: mtrr: Enhance 'mtrr' command to list MTRRs on any CPU

2020-07-17 Thread Simon Glass
Update this command so it can list the MTRRs on a selected CPU. If
'-c all' is used, then all CPUs are listed.

Signed-off-by: Simon Glass 
Reviewed-by: Wolfgang Wallner 
---

Changes in v6:
- Rebase to x86/master

 cmd/x86/mtrr.c | 22 +-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/cmd/x86/mtrr.c b/cmd/x86/mtrr.c
index d8a7e56d5a..e118bba5a2 100644
--- a/cmd/x86/mtrr.c
+++ b/cmd/x86/mtrr.c
@@ -131,7 +131,27 @@ static int do_mtrr(struct cmd_tbl *cmdtp, int flag, int 
argc,
}
}
if (cmd == 'l') {
-   return do_mtrr_list(cpu_select);
+   bool first;
+   int i;
+
+   i = mp_first_cpu(cpu_select);
+   if (i < 0) {
+   printf("Invalid CPU (err=%d)\n", i);
+   return CMD_RET_FAILURE;
+   }
+   first = true;
+   for (; i >= 0; i = mp_next_cpu(cpu_select, i)) {
+   if (!first)
+   printf("\n");
+   printf("CPU %d:\n", i);
+   ret = do_mtrr_list(i);
+   if (ret) {
+   printf("Failed to read CPU %d (err=%d)\n", i,
+  ret);
+   return CMD_RET_FAILURE;
+   }
+   first = false;
+   }
} else {
switch (cmd) {
case 'e':
-- 
2.28.0.rc0.105.gf9edc3c819-goog



[PATCH v6 14/25] x86: mp: Park CPUs before running the OS

2020-07-17 Thread Simon Glass
With the new MP features the CPUs are no-longer parked when the OS is run.
Fix this by calling a special function to park them, just before the OS is
started.

Signed-off-by: Simon Glass 
Reviewed-by: Wolfgang Wallner 
---

(no changes since v5)

Changes in v5:
- Drop timing in mp_park_aps()

Changes in v3:
- Update the comment for mp_park_aps()

 arch/x86/cpu/cpu.c|  5 +
 arch/x86/cpu/mp_init.c| 16 
 arch/x86/include/asm/mp.h | 17 +
 3 files changed, 38 insertions(+)

diff --git a/arch/x86/cpu/cpu.c b/arch/x86/cpu/cpu.c
index c343586e04..69c14189d1 100644
--- a/arch/x86/cpu/cpu.c
+++ b/arch/x86/cpu/cpu.c
@@ -67,6 +67,11 @@ static const char *const x86_vendor_name[] = {
 
 int __weak x86_cleanup_before_linux(void)
 {
+   int ret;
+
+   ret = mp_park_aps();
+   if (ret)
+   return log_msg_ret("park", ret);
bootstage_stash((void *)CONFIG_BOOTSTAGE_STASH_ADDR,
CONFIG_BOOTSTAGE_STASH_SIZE);
 
diff --git a/arch/x86/cpu/mp_init.c b/arch/x86/cpu/mp_init.c
index dd6d6bfab7..427ec8fc23 100644
--- a/arch/x86/cpu/mp_init.c
+++ b/arch/x86/cpu/mp_init.c
@@ -668,6 +668,22 @@ int mp_run_on_cpus(int cpu_select, mp_run_func func, void 
*arg)
return 0;
 }
 
+static void park_this_cpu(void *unused)
+{
+   stop_this_cpu();
+}
+
+int mp_park_aps(void)
+{
+   int ret;
+
+   ret = mp_run_on_cpus(MP_SELECT_APS, park_this_cpu, NULL);
+   if (ret)
+   return log_ret(ret);
+
+   return 0;
+}
+
 int mp_init(void)
 {
int num_aps, num_cpus;
diff --git a/arch/x86/include/asm/mp.h b/arch/x86/include/asm/mp.h
index eb49e690f2..f9d6c8e6bf 100644
--- a/arch/x86/include/asm/mp.h
+++ b/arch/x86/include/asm/mp.h
@@ -109,6 +109,15 @@ typedef void (*mp_run_func)(void *arg);
  * @return 0 on success, -ve on error
  */
 int mp_run_on_cpus(int cpu_select, mp_run_func func, void *arg);
+
+/**
+ * mp_park_aps() - Park the APs ready for the OS
+ *
+ * This halts all CPUs except the main one, ready for the OS to use them
+ *
+ * @return 0 if OK, -ve on error
+ */
+int mp_park_aps(void);
 #else
 static inline int mp_run_on_cpus(int cpu_select, mp_run_func func, void *arg)
 {
@@ -117,6 +126,14 @@ static inline int mp_run_on_cpus(int cpu_select, 
mp_run_func func, void *arg)
 
return 0;
 }
+
+static inline int mp_park_aps(void)
+{
+   /* No APs to park */
+
+   return 0;
+}
+
 #endif
 
 #endif /* _X86_MP_H_ */
-- 
2.28.0.rc0.105.gf9edc3c819-goog



[PATCH v6 23/25] x86: mtrr: Update 'mtrr' to allow setting MTRRs on any CPU

2020-07-17 Thread Simon Glass
Add a -c option to mtrr to allow any CPU to be updated with this command.

Signed-off-by: Simon Glass 
Reviewed-by: Wolfgang Wallner 
Reviewed-by: Bin Meng 
---

(no changes since v3)

Changes in v3:
- Mention that the CPU number is in hex

 cmd/x86/mtrr.c | 18 --
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/cmd/x86/mtrr.c b/cmd/x86/mtrr.c
index b51b1cd7e2..d8a7e56d5a 100644
--- a/cmd/x86/mtrr.c
+++ b/cmd/x86/mtrr.c
@@ -104,6 +104,17 @@ static int do_mtrr(struct cmd_tbl *cmdtp, int flag, int 
argc,
int ret;
 
cpu_select = MP_SELECT_BSP;
+   if (argc >= 3 && !strcmp("-c", argv[1])) {
+   const char *cpustr;
+
+   cpustr = argv[2];
+   if (*cpustr == 'a')
+   cpu_select = MP_SELECT_ALL;
+   else
+   cpu_select = simple_strtol(cpustr, NULL, 16);
+   argc -= 2;
+   argv += 2;
+   }
argc--;
argv++;
cmd = argv[0] ? *argv[0] : 0;
@@ -145,11 +156,14 @@ static int do_mtrr(struct cmd_tbl *cmdtp, int flag, int 
argc,
 }
 
 U_BOOT_CMD(
-   mtrr,   6,  1,  do_mtrr,
+   mtrr,   8,  1,  do_mtrr,
"Use x86 memory type range registers (32-bit only)",
"[list]- list current registers\n"
"set   - set a register\n"
"\t is Uncacheable, Combine, Through, Protect, Back\n"
"disable   - disable a register\n"
-   "enable- enable a register"
+   "enable- enable a register\n"
+   "\n"
+   "Precede command with '-c |all' to access a particular hex CPU, 
e.g.\n"
+   "   mtrr -c all list; mtrr -c 2e list"
 );
-- 
2.28.0.rc0.105.gf9edc3c819-goog



Re: Please pull u-boot-x86

2020-07-17 Thread Tom Rini
On Fri, Jul 17, 2020 at 06:15:17PM +0800, Bin Meng wrote:

> Hi Tom,
> 
> This PR includes the following changes for v2020.10 release:
> 
> - New timer API to allow delays with a 32-bit microsecond timer
> - Add dynamic ACPI structs (DSDT/SSDT) generations to the DM core
> - x86: Enable ACPI table generation by default
> - x86: Enable the copy framebuffer on Coral
> - x86: A few fixes to FSP2 with ApolloLake
> - x86: Drop setup_pcat_compatibility()
> - x86: Primary-to-Sideband Bus minor fixes
> 
> Azure results: PASS
> https://dev.azure.com/bmeng/GitHub/_build/results?buildId=263=results
> 
> The following changes since commit fee68b98fe3890631a9bdf8f8db328179011ee3f:
> 
>   Merge tag 'efi-2020-10-rc1-4' of
> https://gitlab.denx.de/u-boot/custodians/u-boot-efi (2020-07-16
> 16:35:15 -0400)
> 
> are available in the git repository at:
> 
>   https://gitlab.denx.de/u-boot/custodians/u-boot-x86
> 
> for you to fetch changes up to d40d2c570600396b54dece16429727ef50cfeef0:
> 
>   acpi: Enable ACPI table generation by default on x86 (2020-07-17
> 14:32:24 +0800)
> 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


[PATCH v6 19/25] x86: mtrr: Update MTRRs on all CPUs

2020-07-17 Thread Simon Glass
When the boot CPU MTRRs are updated, perform the same update on all other
CPUs so they are kept in sync.

This avoids kernel warnings about mismatched MTRRs.

Signed-off-by: Simon Glass 
Reviewed-by: Wolfgang Wallner 
---

(no changes since v2)

Changes in v2:
- Rename function to mtrr_write_all()

 arch/x86/cpu/mtrr.c | 57 +
 1 file changed, 57 insertions(+)

diff --git a/arch/x86/cpu/mtrr.c b/arch/x86/cpu/mtrr.c
index c9b4e7d06e..5c567551e5 100644
--- a/arch/x86/cpu/mtrr.c
+++ b/arch/x86/cpu/mtrr.c
@@ -74,10 +74,61 @@ void mtrr_read_all(struct mtrr_info *info)
}
 }
 
+void mtrr_write_all(struct mtrr_info *info)
+{
+   struct mtrr_state state;
+   int i;
+
+   for (i = 0; i < MTRR_COUNT; i++) {
+   mtrr_open(, true);
+   wrmsrl(MTRR_PHYS_BASE_MSR(i), info->mtrr[i].base);
+   wrmsrl(MTRR_PHYS_MASK_MSR(i), info->mtrr[i].mask);
+   mtrr_close(, true);
+   }
+}
+
+static void write_mtrrs(void *arg)
+{
+   struct mtrr_info *info = arg;
+
+   mtrr_write_all(info);
+}
+
+static void read_mtrrs(void *arg)
+{
+   struct mtrr_info *info = arg;
+
+   mtrr_read_all(info);
+}
+
+/**
+ * mtrr_copy_to_aps() - Copy the MTRRs from the boot CPU to other CPUs
+ *
+ * @return 0 on success, -ve on failure
+ */
+static int mtrr_copy_to_aps(void)
+{
+   struct mtrr_info info;
+   int ret;
+
+   ret = mp_run_on_cpus(MP_SELECT_BSP, read_mtrrs, );
+   if (ret == -ENXIO)
+   return 0;
+   else if (ret)
+   return log_msg_ret("bsp", ret);
+
+   ret = mp_run_on_cpus(MP_SELECT_APS, write_mtrrs, );
+   if (ret)
+   return log_msg_ret("bsp", ret);
+
+   return 0;
+}
+
 int mtrr_commit(bool do_caches)
 {
struct mtrr_request *req = gd->arch.mtrr_req;
struct mtrr_state state;
+   int ret;
int i;
 
debug("%s: enabled=%d, count=%d\n", __func__, gd->arch.has_mtrr,
@@ -99,6 +150,12 @@ int mtrr_commit(bool do_caches)
mtrr_close(, do_caches);
debug("mtrr done\n");
 
+   if (gd->flags & GD_FLG_RELOC) {
+   ret = mtrr_copy_to_aps();
+   if (ret)
+   return log_msg_ret("copy", ret);
+   }
+
return 0;
 }
 
-- 
2.28.0.rc0.105.gf9edc3c819-goog



[PATCH v6 22/25] x86: mtrr: Restructure so command execution is in one place

2020-07-17 Thread Simon Glass
At present do_mtrr() does the 'list' subcommand at the top and the rest
below. Update it to do them all in the same place so we can (in a later
patch) add parsing of the CPU number for all subcommands.

Signed-off-by: Simon Glass 
Reviewed-by: Wolfgang Wallner 
Reviewed-by: Bin Meng 
---

(no changes since v1)

 cmd/x86/mtrr.c | 55 +-
 1 file changed, 36 insertions(+), 19 deletions(-)

diff --git a/cmd/x86/mtrr.c b/cmd/x86/mtrr.c
index b047a9897c..b51b1cd7e2 100644
--- a/cmd/x86/mtrr.c
+++ b/cmd/x86/mtrr.c
@@ -98,31 +98,48 @@ static int do_mtrr_set(int cpu_select, uint reg, int argc, 
char *const argv[])
 static int do_mtrr(struct cmd_tbl *cmdtp, int flag, int argc,
   char *const argv[])
 {
-   const char *cmd;
+   int cmd;
int cpu_select;
uint reg;
+   int ret;
 
cpu_select = MP_SELECT_BSP;
-   cmd = argv[1];
-   if (argc < 2 || *cmd == 'l')
+   argc--;
+   argv++;
+   cmd = argv[0] ? *argv[0] : 0;
+   if (argc < 1 || !cmd) {
+   cmd = 'l';
+   reg = 0;
+   } else {
+   if (argc < 2)
+   return CMD_RET_USAGE;
+   reg = simple_strtoul(argv[1], NULL, 16);
+   if (reg >= MTRR_COUNT) {
+   printf("Invalid register number\n");
+   return CMD_RET_USAGE;
+   }
+   }
+   if (cmd == 'l') {
return do_mtrr_list(cpu_select);
-   argc -= 2;
-   argv += 2;
-   if (argc <= 0)
-   return CMD_RET_USAGE;
-   reg = simple_strtoul(argv[0], NULL, 16);
-   if (reg >= MTRR_COUNT) {
-   printf("Invalid register number\n");
-   return CMD_RET_USAGE;
+   } else {
+   switch (cmd) {
+   case 'e':
+   ret = mtrr_set_valid(cpu_select, reg, true);
+   break;
+   case 'd':
+   ret = mtrr_set_valid(cpu_select, reg, false);
+   break;
+   case 's':
+   ret = do_mtrr_set(cpu_select, reg, argc - 2, argv + 2);
+   break;
+   default:
+   return CMD_RET_USAGE;
+   }
+   if (ret) {
+   printf("Operation failed (err=%d)\n", ret);
+   return CMD_RET_FAILURE;
+   }
}
-   if (*cmd == 'e')
-   return mtrr_set_valid(cpu_select, reg, true);
-   else if (*cmd == 'd')
-   return mtrr_set_valid(cpu_select, reg, false);
-   else if (*cmd == 's')
-   return do_mtrr_set(cpu_select, reg, argc - 1, argv + 1);
-   else
-   return CMD_RET_USAGE;
 
return 0;
 }
-- 
2.28.0.rc0.105.gf9edc3c819-goog



[PATCH v6 21/25] x86: mtrr: Update the command to use the new mtrr calls

2020-07-17 Thread Simon Glass
Use the multi-CPU calls to set the MTRR values. This still supports only
the boot CPU for now.

Signed-off-by: Simon Glass 
Reviewed-by: Wolfgang Wallner 
Reviewed-by: Bin Meng 
---

(no changes since v2)

Changes in v2:
- Drop the renamed mtrr_set_valid_() instead of mtrr_set_valid()

 cmd/x86/mtrr.c | 34 --
 1 file changed, 8 insertions(+), 26 deletions(-)

diff --git a/cmd/x86/mtrr.c b/cmd/x86/mtrr.c
index 46ef6a2830..b047a9897c 100644
--- a/cmd/x86/mtrr.c
+++ b/cmd/x86/mtrr.c
@@ -59,14 +59,14 @@ static int do_mtrr_list(int cpu_select)
return 0;
 }
 
-static int do_mtrr_set(uint reg, int argc, char *const argv[])
+static int do_mtrr_set(int cpu_select, uint reg, int argc, char *const argv[])
 {
const char *typename = argv[0];
-   struct mtrr_state state;
uint32_t start, size;
uint64_t base, mask;
int i, type = -1;
bool valid;
+   int ret;
 
if (argc < 3)
return CMD_RET_USAGE;
@@ -88,27 +88,9 @@ static int do_mtrr_set(uint reg, int argc, char *const 
argv[])
if (valid)
mask |= MTRR_PHYS_MASK_VALID;
 
-   mtrr_open(, true);
-   wrmsrl(MTRR_PHYS_BASE_MSR(reg), base);
-   wrmsrl(MTRR_PHYS_MASK_MSR(reg), mask);
-   mtrr_close(, true);
-
-   return 0;
-}
-
-static int mtrr_set_valid_(int reg, bool valid)
-{
-   struct mtrr_state state;
-   uint64_t mask;
-
-   mtrr_open(, true);
-   mask = native_read_msr(MTRR_PHYS_MASK_MSR(reg));
-   if (valid)
-   mask |= MTRR_PHYS_MASK_VALID;
-   else
-   mask &= ~MTRR_PHYS_MASK_VALID;
-   wrmsrl(MTRR_PHYS_MASK_MSR(reg), mask);
-   mtrr_close(, true);
+   ret = mtrr_set(cpu_select, reg, base, mask);
+   if (ret)
+   return CMD_RET_FAILURE;
 
return 0;
 }
@@ -134,11 +116,11 @@ static int do_mtrr(struct cmd_tbl *cmdtp, int flag, int 
argc,
return CMD_RET_USAGE;
}
if (*cmd == 'e')
-   return mtrr_set_valid_(reg, true);
+   return mtrr_set_valid(cpu_select, reg, true);
else if (*cmd == 'd')
-   return mtrr_set_valid_(reg, false);
+   return mtrr_set_valid(cpu_select, reg, false);
else if (*cmd == 's')
-   return do_mtrr_set(reg, argc - 1, argv + 1);
+   return do_mtrr_set(cpu_select, reg, argc - 1, argv + 1);
else
return CMD_RET_USAGE;
 
-- 
2.28.0.rc0.105.gf9edc3c819-goog



[PATCH v6 15/25] x86: mp: Add iterators for CPUs

2020-07-17 Thread Simon Glass
It is convenient to iterate through the CPUs performing work on each one
and processing the result. Add a few iterator functions which handle this.
These can be used by any client code. It can call mp_run_on_cpus() on
each CPU that is returned, handling them one at a time.

Signed-off-by: Simon Glass 
Reviewed-by: Wolfgang Wallner 
---

(no changes since v4)

Changes in v4:
- Update mp_next_cpu() to stop if CONFIG_SMP_AP_WORK is not enabled

Changes in v3:
- Add more comments on how the iterators work

 arch/x86/cpu/mp_init.c| 63 +++
 arch/x86/include/asm/mp.h | 42 ++
 2 files changed, 105 insertions(+)

diff --git a/arch/x86/cpu/mp_init.c b/arch/x86/cpu/mp_init.c
index 427ec8fc23..c373c3099a 100644
--- a/arch/x86/cpu/mp_init.c
+++ b/arch/x86/cpu/mp_init.c
@@ -684,6 +684,69 @@ int mp_park_aps(void)
return 0;
 }
 
+int mp_first_cpu(int cpu_select)
+{
+   struct udevice *dev;
+   int num_cpus;
+   int ret;
+
+   /*
+* This assumes that CPUs are numbered from 0. This function tries to
+* avoid assuming the CPU 0 is the boot CPU
+*/
+   if (cpu_select == MP_SELECT_ALL)
+   return 0;   /* start with the first one */
+
+   ret = get_bsp(, _cpus);
+   if (ret < 0)
+   return log_msg_ret("bsp", ret);
+
+   /* Return boot CPU if requested */
+   if (cpu_select == MP_SELECT_BSP)
+   return ret;
+
+   /* Return something other than the boot CPU, if APs requested */
+   if (cpu_select == MP_SELECT_APS && num_cpus > 1)
+   return ret == 0 ? 1 : 0;
+
+   /* Try to check for an invalid value */
+   if (cpu_select < 0 || cpu_select >= num_cpus)
+   return -EINVAL;
+
+   return cpu_select;  /* return the only selected one */
+}
+
+int mp_next_cpu(int cpu_select, int prev_cpu)
+{
+   struct udevice *dev;
+   int num_cpus;
+   int ret;
+   int bsp;
+
+   /* If we selected the BSP or a particular single CPU, we are done */
+   if (!IS_ENABLED(CONFIG_SMP_AP_WORK) || cpu_select == MP_SELECT_BSP ||
+   cpu_select >= 0)
+   return -EFBIG;
+
+   /* Must be doing MP_SELECT_ALL or MP_SELECT_APS; return the next CPU */
+   ret = get_bsp(, _cpus);
+   if (ret < 0)
+   return log_msg_ret("bsp", ret);
+   bsp = ret;
+
+   /* Move to the next CPU */
+   assert(prev_cpu >= 0);
+   ret = prev_cpu + 1;
+
+   /* Skip the BSP if needed */
+   if (cpu_select == MP_SELECT_APS && ret == bsp)
+   ret++;
+   if (ret >= num_cpus)
+   return -EFBIG;
+
+   return ret;
+}
+
 int mp_init(void)
 {
int num_aps, num_cpus;
diff --git a/arch/x86/include/asm/mp.h b/arch/x86/include/asm/mp.h
index f9d6c8e6bf..9379826b6b 100644
--- a/arch/x86/include/asm/mp.h
+++ b/arch/x86/include/asm/mp.h
@@ -118,6 +118,33 @@ int mp_run_on_cpus(int cpu_select, mp_run_func func, void 
*arg);
  * @return 0 if OK, -ve on error
  */
 int mp_park_aps(void);
+
+/**
+ * mp_first_cpu() - Get the first CPU to process, from a selection
+ *
+ * This is used to iterate through selected CPUs. Call this function first, 
then
+ * call mp_next_cpu() repeatedly (with the same @cpu_select) until it returns
+ * -EFBIG.
+ *
+ * @cpu_select: Selected CPUs (either a CPU number or MP_SELECT_...)
+ * @return next CPU number to run on (e.g. 0)
+ */
+int mp_first_cpu(int cpu_select);
+
+/**
+ * mp_next_cpu() - Get the next CPU to process, from a selection
+ *
+ * This is used to iterate through selected CPUs. After first calling
+ * mp_first_cpu() once, call this function repeatedly until it returns -EFBIG.
+ *
+ * The value of @cpu_select must be the same for all calls and must match the
+ * value passed to mp_first_cpu(), otherwise the behaviour is undefined.
+ *
+ * @cpu_select: Selected CPUs (either a CPU number or MP_SELECT_...)
+ * @prev_cpu: Previous value returned by mp_first_cpu()/mp_next_cpu()
+ * @return next CPU number to run on (e.g. 0)
+ */
+int mp_next_cpu(int cpu_select, int prev_cpu);
 #else
 static inline int mp_run_on_cpus(int cpu_select, mp_run_func func, void *arg)
 {
@@ -134,6 +161,21 @@ static inline int mp_park_aps(void)
return 0;
 }
 
+static inline int mp_first_cpu(int cpu_select)
+{
+   /* We cannot run on any APs, nor a selected CPU */
+   return cpu_select == MP_SELECT_APS ? -EFBIG : MP_SELECT_BSP;
+}
+
+static inline int mp_next_cpu(int cpu_select, int prev_cpu)
+{
+   /*
+* When MP is not enabled, there is only one CPU and we did it in
+* mp_first_cpu()
+*/
+   return -EFBIG;
+}
+
 #endif
 
 #endif /* _X86_MP_H_ */
-- 
2.28.0.rc0.105.gf9edc3c819-goog



[PATCH v6 17/25] x86: Don't enable SMP in SPL

2020-07-17 Thread Simon Glass
SMP should be set up in U-Boot where possible, not SPL. Disable it in SPL.
For 64-bit U-Boot we should find a way to allow SMP operations in U-Boot,
but this is somewhat more complicated. For now that is disabled too.

Signed-off-by: Simon Glass 
Reviewed-by: Bin Meng 
Reviewed-by: Wolfgang Wallner 
---

(no changes since v2)

Changes in v2:
- Add a new patch to avoid enabling SMP in SPL

 arch/x86/cpu/Makefile | 2 +-
 arch/x86/include/asm/mp.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/cpu/Makefile b/arch/x86/cpu/Makefile
index ee0499f5d7..16e67e3da2 100644
--- a/arch/x86/cpu/Makefile
+++ b/arch/x86/cpu/Makefile
@@ -60,7 +60,7 @@ ifndef CONFIG_SYS_COREBOOT
 obj-$(CONFIG_$(SPL_TPL_)X86_32BIT_INIT) += irq.o
 endif
 ifndef CONFIG_$(SPL_)X86_64
-obj-$(CONFIG_SMP) += mp_init.o
+obj-$(CONFIG_$(SPL_)SMP) += mp_init.o
 endif
 obj-y += mtrr.o
 obj-$(CONFIG_PCI) += pci.o
diff --git a/arch/x86/include/asm/mp.h b/arch/x86/include/asm/mp.h
index 9379826b6b..ff49004222 100644
--- a/arch/x86/include/asm/mp.h
+++ b/arch/x86/include/asm/mp.h
@@ -93,7 +93,7 @@ int x86_mp_init(void);
  */
 typedef void (*mp_run_func)(void *arg);
 
-#if defined(CONFIG_SMP) && !CONFIG_IS_ENABLED(X86_64)
+#if CONFIG_IS_ENABLED(SMP) && !CONFIG_IS_ENABLED(X86_64)
 /**
  * mp_run_on_cpus() - Run a function on one or all CPUs
  *
-- 
2.28.0.rc0.105.gf9edc3c819-goog



[PATCH v6 11/25] global_data: Add a generic global_data flag for SMP state

2020-07-17 Thread Simon Glass
Allow keeping track of whether all CPUs have been enabled yet. This allows
us to know whether other CPUs need to be considered when updating
CPU-specific settings such as MTRRs on x86.

Signed-off-by: Simon Glass 
Reviewed-by: Wolfgang Wallner 
---

(no changes since v3)

Changes in v3:
- Rename flag to GD_FLG_SMP_READY

 include/asm-generic/global_data.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/asm-generic/global_data.h 
b/include/asm-generic/global_data.h
index 8c78792cc9..d4a4e2215d 100644
--- a/include/asm-generic/global_data.h
+++ b/include/asm-generic/global_data.h
@@ -167,5 +167,6 @@ typedef struct global_data {
 #define GD_FLG_LOG_READY   0x08000 /* Log system is ready for use */
 #define GD_FLG_WDT_READY   0x1 /* Watchdog is ready for use   */
 #define GD_FLG_SKIP_LL_INIT0x2 /* Don't perform low-level init*/
+#define GD_FLG_SMP_READY   0x4 /* SMP init is complete*/
 
 #endif /* __ASM_GENERIC_GBL_DATA_H */
-- 
2.28.0.rc0.105.gf9edc3c819-goog



[PATCH v6 13/25] x86: mp: Allow running functions on multiple CPUs

2020-07-17 Thread Simon Glass
Add a way to run a function on a selection of CPUs. This supports either
a single CPU, all CPUs, just the main CPU or just the 'APs', in Intel
terminology.

It works by writing into a mailbox and then waiting for the CPUs to notice
it, take action and indicate they are done.

When SMP is not yet enabled, this just calls the function on the main CPU.

Signed-off-by: Simon Glass 
Reviewed-by: Wolfgang Wallner 
---

(no changes since v4)

Changes in v4:
- Only enable this feature of CONFIG_SMP_AP_WORK is enabled
- Allow running on the BSP if SMP is not enabled

Changes in v3:
- Add a comment to run_ap_work()
- Rename flag to GD_FLG_SMP_READY
- Update the comment for run_ap_work() to explain logical_cpu_number
- Clarify meaning of @cpu_select in mp_run_on_cpus() comment

 arch/x86/cpu/mp_init.c| 107 +++---
 arch/x86/include/asm/mp.h |  33 
 2 files changed, 134 insertions(+), 6 deletions(-)

diff --git a/arch/x86/cpu/mp_init.c b/arch/x86/cpu/mp_init.c
index 69a23829b9..dd6d6bfab7 100644
--- a/arch/x86/cpu/mp_init.c
+++ b/arch/x86/cpu/mp_init.c
@@ -54,12 +54,7 @@ struct mp_flight_plan {
  * callback
  */
 struct mp_callback {
-   /**
-* func() - Function to call on the AP
-*
-* @arg: Argument to pass
-*/
-   void (*func)(void *arg);
+   mp_run_func func;
void *arg;
int logical_cpu_number;
 };
@@ -514,6 +509,70 @@ static void store_callback(struct mp_callback **slot, 
struct mp_callback *val)
dmb();
 }
 
+/**
+ * run_ap_work() - Run a callback on selected APs
+ *
+ * This writes @callback to all APs and waits for them all to acknowledge it,
+ * Note that whether each AP actually calls the callback depends on the value
+ * of logical_cpu_number (see struct mp_callback). The logical CPU number is
+ * the CPU device's req->seq value.
+ *
+ * @callback: Callback information to pass to all APs
+ * @bsp: CPU device for the BSP
+ * @num_cpus: The number of CPUs in the system (= number of APs + 1)
+ * @expire_ms: Timeout to wait for all APs to finish, in milliseconds, or 0 for
+ * no timeout
+ * @return 0 if OK, -ETIMEDOUT if one or more APs failed to respond in time
+ */
+static int run_ap_work(struct mp_callback *callback, struct udevice *bsp,
+  int num_cpus, uint expire_ms)
+{
+   int cur_cpu = bsp->req_seq;
+   int num_aps = num_cpus - 1; /* number of non-BSPs to get this message */
+   int cpus_accepted;
+   ulong start;
+   int i;
+
+   if (!IS_ENABLED(CONFIG_SMP_AP_WORK)) {
+   printf("APs already parked. CONFIG_SMP_AP_WORK not enabled\n");
+   return -ENOTSUPP;
+   }
+
+   /* Signal to all the APs to run the func. */
+   for (i = 0; i < num_cpus; i++) {
+   if (cur_cpu != i)
+   store_callback(_callbacks[i], callback);
+   }
+   mfence();
+
+   /* Wait for all the APs to signal back that call has been accepted. */
+   start = get_timer(0);
+
+   do {
+   mdelay(1);
+   cpus_accepted = 0;
+
+   for (i = 0; i < num_cpus; i++) {
+   if (cur_cpu == i)
+   continue;
+   if (!read_callback(_callbacks[i]))
+   cpus_accepted++;
+   }
+
+   if (expire_ms && get_timer(start) >= expire_ms) {
+   log(UCLASS_CPU, LOGL_CRIT,
+   "AP call expired; %d/%d CPUs accepted\n",
+   cpus_accepted, num_aps);
+   return -ETIMEDOUT;
+   }
+   } while (cpus_accepted != num_aps);
+
+   /* Make sure we can see any data written by the APs */
+   mfence();
+
+   return 0;
+}
+
 /**
  * ap_wait_for_instruction() - Wait for and process requests from the main CPU
  *
@@ -573,6 +632,42 @@ static struct mp_flight_record mp_steps[] = {
MP_FR_BLOCK_APS(ap_wait_for_instruction, NULL, NULL, NULL),
 };
 
+int mp_run_on_cpus(int cpu_select, mp_run_func func, void *arg)
+{
+   struct mp_callback lcb = {
+   .func = func,
+   .arg = arg,
+   .logical_cpu_number = cpu_select,
+   };
+   struct udevice *dev;
+   int num_cpus;
+   int ret;
+
+   ret = get_bsp(, _cpus);
+   if (ret < 0)
+   return log_msg_ret("bsp", ret);
+   if (cpu_select == MP_SELECT_ALL || cpu_select == MP_SELECT_BSP ||
+   cpu_select == ret) {
+   /* Run on BSP first */
+   func(arg);
+   }
+
+   if (!IS_ENABLED(CONFIG_SMP_AP_WORK) ||
+   !(gd->flags & GD_FLG_SMP_READY)) {
+   /* Allow use of this function on the BSP only */
+   if (cpu_select == MP_SELECT_BSP || !cpu_select)
+   return 0;
+   return -ENOTSUPP;
+   }
+
+   /* Allow up to 1 second for all APs to finish */

[PATCH v6 12/25] x86: Set the SMP flag when MP init is complete

2020-07-17 Thread Simon Glass
Set this flag so we can track when it is safe to use CPUs other than the
main one.

Signed-off-by: Simon Glass 
Reviewed-by: Wolfgang Wallner 
Reviewed-by: Bin Meng 
---

(no changes since v3)

Changes in v3:
- Rename flag to GD_FLG_SMP_READY

 arch/x86/cpu/mp_init.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/x86/cpu/mp_init.c b/arch/x86/cpu/mp_init.c
index 787de92fa3..69a23829b9 100644
--- a/arch/x86/cpu/mp_init.c
+++ b/arch/x86/cpu/mp_init.c
@@ -643,6 +643,7 @@ int mp_init(void)
debug("CPU init failed: err=%d\n", ret);
return ret;
}
+   gd->flags |= GD_FLG_SMP_READY;
 
return 0;
 }
-- 
2.28.0.rc0.105.gf9edc3c819-goog



[PATCH v6 10/25] x86: mp: Support APs waiting for instructions

2020-07-17 Thread Simon Glass
At present the APs (non-boot CPUs) are inited once and then parked ready
for the OS to use them. However in some cases we want to send new requests
through, such as to change MTRRs and keep them consistent across CPUs.

Change the last state of the flight plan to go into a wait loop, accepting
instructions from the main CPU.

Drop cpu_map since it is not used.

Signed-off-by: Simon Glass 
Reviewed-by: Wolfgang Wallner 
---

(no changes since v4)

Changes in v4:
- Add a Kconfig to control this feature, enabled only on APL

Changes in v3:
- s/slow/slot/
- Use C code instead of assembler to read/write callback pointers
- Update commit message to mention dropping of cpu_map

Changes in v2:
- Add more comments

 arch/x86/Kconfig|   7 ++
 arch/x86/cpu/apollolake/Kconfig |   1 +
 arch/x86/cpu/mp_init.c  | 123 +---
 arch/x86/include/asm/mp.h   |  11 +++
 4 files changed, 134 insertions(+), 8 deletions(-)

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 27295ef384..ff4f06ed79 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -603,6 +603,13 @@ config SMP
  only one CPU will be enabled regardless of the number of CPUs
  available.
 
+config SMP_AP_WORK
+   bool
+   depends on SMP
+   help
+Allow APs to do other work after initialisation instead of going
+to sleep.
+
 config MAX_CPUS
int "Maximum number of CPUs permitted"
depends on SMP
diff --git a/arch/x86/cpu/apollolake/Kconfig b/arch/x86/cpu/apollolake/Kconfig
index 942f11f566..99d4e105c2 100644
--- a/arch/x86/cpu/apollolake/Kconfig
+++ b/arch/x86/cpu/apollolake/Kconfig
@@ -15,6 +15,7 @@ config INTEL_APOLLOLAKE
select TPL_PCH_SUPPORT
select PCH_SUPPORT
select P2SB
+   select SMP_AP_WORK
imply ENABLE_MRC_CACHE
imply AHCI_PCI
imply SCSI
diff --git a/arch/x86/cpu/mp_init.c b/arch/x86/cpu/mp_init.c
index 9fdde7832a..787de92fa3 100644
--- a/arch/x86/cpu/mp_init.c
+++ b/arch/x86/cpu/mp_init.c
@@ -15,6 +15,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -43,13 +44,38 @@ struct mp_flight_plan {
struct mp_flight_record *records;
 };
 
+/**
+ * struct mp_callback - Callback information for APs
+ *
+ * @func: Function to run
+ * @arg: Argument to pass to the function
+ * @logical_cpu_number: Either a CPU number (i.e. dev->req_seq) or a special
+ * value like MP_SELECT_BSP. It tells the AP whether it should process this
+ * callback
+ */
+struct mp_callback {
+   /**
+* func() - Function to call on the AP
+*
+* @arg: Argument to pass
+*/
+   void (*func)(void *arg);
+   void *arg;
+   int logical_cpu_number;
+};
+
 static struct mp_flight_plan mp_info;
 
-struct cpu_map {
-   struct udevice *dev;
-   int apic_id;
-   int err_code;
-};
+/*
+ * ap_callbacks - Callback mailbox array
+ *
+ * Array of callback, one entry for each available CPU, indexed by the CPU
+ * number, which is dev->req_seq. The entry for the main CPU is never used.
+ * When this is NULL, there is no pending work for the CPU to run. When
+ * non-NULL it points to the mp_callback structure. This is shared between all
+ * CPUs, so should only be written by the main CPU.
+ */
+static struct mp_callback **ap_callbacks;
 
 static inline void barrier_wait(atomic_t *b)
 {
@@ -147,11 +173,12 @@ static void ap_init(unsigned int cpu_index)
debug("AP: slot %d apic_id %x, dev %s\n", cpu_index, apic_id,
  dev ? dev->name : "(apic_id not found)");
 
-   /* Walk the flight plan */
+   /*
+* Walk the flight plan, which only returns if CONFIG_SMP_AP_WORK is not
+* enabled
+*/
ap_do_flight_plan(dev);
 
-   /* Park the AP */
-   debug("parking\n");
 done:
stop_this_cpu();
 }
@@ -456,6 +483,81 @@ static int get_bsp(struct udevice **devp, int *cpu_countp)
return dev->req_seq >= 0 ? dev->req_seq : 0;
 }
 
+/**
+ * read_callback() - Read the pointer in a callback slot
+ *
+ * This is called by APs to read their callback slot to see if there is a
+ * pointer to new instructions
+ *
+ * @slot: Pointer to the AP's callback slot
+ * @return value of that pointer
+ */
+static struct mp_callback *read_callback(struct mp_callback **slot)
+{
+   dmb();
+
+   return *slot;
+}
+
+/**
+ * store_callback() - Store a pointer to the callback slot
+ *
+ * This is called by APs to write NULL into the callback slot when they have
+ * finished the work requested by the BSP.
+ *
+ * @slot: Pointer to the AP's callback slot
+ * @val: Value to write (e.g. NULL)
+ */
+static void store_callback(struct mp_callback **slot, struct mp_callback *val)
+{
+   *slot = val;
+   dmb();
+}
+
+/**
+ * ap_wait_for_instruction() - Wait for and process requests from the main CPU
+ *
+ * This is called by APs (here, everything other than the main boot CPU) to
+ * await 

[PATCH v6 07/25] x86: mp_init: Set up the CPU numbers at the start

2020-07-17 Thread Simon Glass
At present each CPU is given a number when it starts itself up. While this
saves a tiny amount of time by doing the device-tree read in parallel, it
is confusing that the numbering happens on the fly.

Move this code into mp_init() and do it at the start.

Signed-off-by: Simon Glass 
Reviewed-by: Wolfgang Wallner 
Reviewed-by: Bin Meng 
---

(no changes since v1)

 arch/x86/cpu/mp_init.c | 21 +
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/arch/x86/cpu/mp_init.c b/arch/x86/cpu/mp_init.c
index df43f71572..6f6de49df0 100644
--- a/arch/x86/cpu/mp_init.c
+++ b/arch/x86/cpu/mp_init.c
@@ -444,12 +444,6 @@ static int mp_init_cpu(struct udevice *cpu, void *unused)
 {
struct cpu_platdata *plat = dev_get_parent_platdata(cpu);
 
-   /*
-* Multiple APs are brought up simultaneously and they may get the same
-* seq num in the uclass_resolve_seq() during device_probe(). To avoid
-* this, set req_seq to the reg number in the device tree in advance.
-*/
-   cpu->req_seq = dev_read_u32_default(cpu, "reg", -1);
plat->ucode_version = microcode_read_rev();
plat->device_id = gd->arch.x86_device;
 
@@ -465,13 +459,8 @@ int mp_init(void)
int num_aps, num_cpus;
atomic_t *ap_count;
struct udevice *cpu;
-   int ret;
-
-   /* This will cause the CPUs devices to be bound */
struct uclass *uc;
-   ret = uclass_get(UCLASS_CPU, );
-   if (ret)
-   return ret;
+   int ret;
 
if (IS_ENABLED(CONFIG_QFW)) {
ret = qemu_cpu_fixup();
@@ -479,6 +468,14 @@ int mp_init(void)
return ret;
}
 
+   /*
+* Multiple APs are brought up simultaneously and they may get the same
+* seq num in the uclass_resolve_seq() during device_probe(). To avoid
+* this, set req_seq to the reg number in the device tree in advance.
+*/
+   uclass_id_foreach_dev(UCLASS_CPU, cpu, uc)
+   cpu->req_seq = dev_read_u32_default(cpu, "reg", -1);
+
ret = init_bsp();
if (ret) {
debug("Cannot init boot CPU: err=%d\n", ret);
-- 
2.28.0.rc0.105.gf9edc3c819-goog



[PATCH v6 06/25] x86: mtrr: Fix 'ensable' typo

2020-07-17 Thread Simon Glass
Fix a typo in the command help.

Signed-off-by: Simon Glass 
Reviewed-by: Wolfgang Wallner 
Reviewed-by: Bin Meng 
---

(no changes since v1)

 cmd/x86/mtrr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cmd/x86/mtrr.c b/cmd/x86/mtrr.c
index 084d7315f4..5d25c5802a 100644
--- a/cmd/x86/mtrr.c
+++ b/cmd/x86/mtrr.c
@@ -135,5 +135,5 @@ U_BOOT_CMD(
"set   - set a register\n"
"\t is Uncacheable, Combine, Through, Protect, Back\n"
"disable   - disable a register\n"
-   "ensable   - enable a register"
+   "enable- enable a register"
 );
-- 
2.28.0.rc0.105.gf9edc3c819-goog



[PATCH v6 09/25] x86: cpu: Remove unnecessary #ifdefs

2020-07-17 Thread Simon Glass
Drop some #ifdefs that are not needed or can be converted to compile-time
checks.

Signed-off-by: Simon Glass 
Reviewed-by: Wolfgang Wallner 
Reviewed-by: Bin Meng 
---

(no changes since v1)

 arch/x86/cpu/cpu.c  | 53 -
 arch/x86/cpu/i386/cpu.c |  2 --
 2 files changed, 26 insertions(+), 29 deletions(-)

diff --git a/arch/x86/cpu/cpu.c b/arch/x86/cpu/cpu.c
index 98ed66e67d..c343586e04 100644
--- a/arch/x86/cpu/cpu.c
+++ b/arch/x86/cpu/cpu.c
@@ -67,10 +67,8 @@ static const char *const x86_vendor_name[] = {
 
 int __weak x86_cleanup_before_linux(void)
 {
-#ifdef CONFIG_BOOTSTAGE_STASH
bootstage_stash((void *)CONFIG_BOOTSTAGE_STASH_ADDR,
CONFIG_BOOTSTAGE_STASH_SIZE);
-#endif
 
return 0;
 }
@@ -201,18 +199,19 @@ int last_stage_init(void)
 
write_tables();
 
-#ifdef CONFIG_GENERATE_ACPI_TABLE
-   fadt = acpi_find_fadt();
+   if (IS_ENABLED(CONFIG_GENERATE_ACPI_TABLE)) {
+   fadt = acpi_find_fadt();
 
-   /* Don't touch ACPI hardware on HW reduced platforms */
-   if (fadt && !(fadt->flags & ACPI_FADT_HW_REDUCED_ACPI)) {
-   /*
-* Other than waiting for OSPM to request us to switch to ACPI
-* mode, do it by ourselves, since SMI will not be triggered.
-*/
-   enter_acpi_mode(fadt->pm1a_cnt_blk);
+   /* Don't touch ACPI hardware on HW reduced platforms */
+   if (fadt && !(fadt->flags & ACPI_FADT_HW_REDUCED_ACPI)) {
+   /*
+* Other than waiting for OSPM to request us to switch
+* to ACPI * mode, do it by ourselves, since SMI will
+* not be triggered.
+*/
+   enter_acpi_mode(fadt->pm1a_cnt_blk);
+   }
}
-#endif
 
return 0;
 }
@@ -220,19 +219,20 @@ int last_stage_init(void)
 
 static int x86_init_cpus(void)
 {
-#ifdef CONFIG_SMP
-   debug("Init additional CPUs\n");
-   x86_mp_init();
-#else
-   struct udevice *dev;
+   if (IS_ENABLED(CONFIG_SMP)) {
+   debug("Init additional CPUs\n");
+   x86_mp_init();
+   } else {
+   struct udevice *dev;
 
-   /*
-* This causes the cpu-x86 driver to be probed.
-* We don't check return value here as we want to allow boards
-* which have not been converted to use cpu uclass driver to boot.
-*/
-   uclass_first_device(UCLASS_CPU, );
-#endif
+   /*
+* This causes the cpu-x86 driver to be probed.
+* We don't check return value here as we want to allow boards
+* which have not been converted to use cpu uclass driver to
+* boot.
+*/
+   uclass_first_device(UCLASS_CPU, );
+   }
 
return 0;
 }
@@ -276,9 +276,8 @@ int reserve_arch(void)
if (IS_ENABLED(CONFIG_ENABLE_MRC_CACHE))
mrccache_reserve();
 
-#ifdef CONFIG_SEABIOS
-   high_table_reserve();
-#endif
+   if (IS_ENABLED(CONFIG_SEABIOS))
+   high_table_reserve();
 
if (IS_ENABLED(CONFIG_HAVE_ACPI_RESUME)) {
acpi_s3_reserve();
diff --git a/arch/x86/cpu/i386/cpu.c b/arch/x86/cpu/i386/cpu.c
index 55a0907bc8..8f342dd06e 100644
--- a/arch/x86/cpu/i386/cpu.c
+++ b/arch/x86/cpu/i386/cpu.c
@@ -631,7 +631,6 @@ int cpu_jump_to_64bit_uboot(ulong target)
return -EFAULT;
 }
 
-#ifdef CONFIG_SMP
 int x86_mp_init(void)
 {
int ret;
@@ -644,4 +643,3 @@ int x86_mp_init(void)
 
return 0;
 }
-#endif
-- 
2.28.0.rc0.105.gf9edc3c819-goog



[PATCH v6 08/25] x86: mp_init: Adjust bsp_init() to return more information

2020-07-17 Thread Simon Glass
This function is misnamed since it does not actually init the BSP. Also
it is convenient to adjust it to return a little more information.

Rename and update the function, to allow it to return the BSP CPU device
and number, as well as the total number of CPUs.

Signed-off-by: Simon Glass 
Reviewed-by: Wolfgang Wallner 
Reviewed-by: Bin Meng 
---

(no changes since v4)

Changes in v4:
- Update get_bsp() to return zero when SMP is not inited

Changes in v2:
- Drop change to include/dm/uclass.h
- Mention error return in get_bsp()

 arch/x86/cpu/mp_init.c | 36 +++-
 1 file changed, 23 insertions(+), 13 deletions(-)

diff --git a/arch/x86/cpu/mp_init.c b/arch/x86/cpu/mp_init.c
index 6f6de49df0..9fdde7832a 100644
--- a/arch/x86/cpu/mp_init.c
+++ b/arch/x86/cpu/mp_init.c
@@ -421,9 +421,18 @@ static int bsp_do_flight_plan(struct udevice *cpu, struct 
mp_flight_plan *plan,
return ret;
 }
 
-static int init_bsp(struct udevice **devp)
+/**
+ * get_bsp() - Get information about the bootstrap processor
+ *
+ * @devp: If non-NULL, returns CPU device corresponding to the BSP
+ * @cpu_countp: If non-NULL, returns the total number of CPUs
+ * @return CPU number of the BSP, or -ve on error. If multiprocessing is not
+ * enabled, returns 0
+ */
+static int get_bsp(struct udevice **devp, int *cpu_countp)
 {
char processor_name[CPU_MAX_NAME_LEN];
+   struct udevice *dev;
int apic_id;
int ret;
 
@@ -431,13 +440,20 @@ static int init_bsp(struct udevice **devp)
debug("CPU: %s\n", processor_name);
 
apic_id = lapicid();
-   ret = find_cpu_by_apic_id(apic_id, devp);
-   if (ret) {
+   ret = find_cpu_by_apic_id(apic_id, );
+   if (ret < 0) {
printf("Cannot find boot CPU, APIC ID %d\n", apic_id);
return ret;
}
+   ret = cpu_get_count(dev);
+   if (ret < 0)
+   return log_msg_ret("count", ret);
+   if (devp)
+   *devp = dev;
+   if (cpu_countp)
+   *cpu_countp = ret;
 
-   return 0;
+   return dev->req_seq >= 0 ? dev->req_seq : 0;
 }
 
 static int mp_init_cpu(struct udevice *cpu, void *unused)
@@ -476,24 +492,18 @@ int mp_init(void)
uclass_id_foreach_dev(UCLASS_CPU, cpu, uc)
cpu->req_seq = dev_read_u32_default(cpu, "reg", -1);
 
-   ret = init_bsp();
-   if (ret) {
+   ret = get_bsp(, _cpus);
+   if (ret < 0) {
debug("Cannot init boot CPU: err=%d\n", ret);
return ret;
}
 
-   num_cpus = cpu_get_count(cpu);
-   if (num_cpus < 0) {
-   debug("Cannot get number of CPUs: err=%d\n", num_cpus);
-   return num_cpus;
-   }
-
if (num_cpus < 2)
debug("Warning: Only 1 CPU is detected\n");
 
ret = check_cpu_devices(num_cpus);
if (ret)
-   debug("Warning: Device tree does not describe all CPUs. Extra 
ones will not be started correctly\n");
+   log_warning("Warning: Device tree does not describe all CPUs. 
Extra ones will not be started correctly\n");
 
/* Copy needed parameters so that APs have a reference to the plan */
mp_info.num_records = ARRAY_SIZE(mp_steps);
-- 
2.28.0.rc0.105.gf9edc3c819-goog



[PATCH v6 04/25] x86: mp_init: Switch parameter names in start_aps()

2020-07-17 Thread Simon Glass
These parameters are named differently from elsewhere in this file. Switch
them to avoid confusion.

Also add comments to this function.

Signed-off-by: Simon Glass 
Reviewed-by: Bin Meng 
Reviewed-by: Wolfgang Wallner 
---

(no changes since v2)

Changes in v2:
- Add comments to explain what start_aps() does

 arch/x86/cpu/mp_init.c | 25 +++--
 1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/arch/x86/cpu/mp_init.c b/arch/x86/cpu/mp_init.c
index e77d7f2cd6..8b00d57c88 100644
--- a/arch/x86/cpu/mp_init.c
+++ b/arch/x86/cpu/mp_init.c
@@ -308,13 +308,26 @@ static int apic_wait_timeout(int total_delay, const char 
*msg)
return 0;
 }
 
-static int start_aps(int ap_count, atomic_t *num_aps)
+/**
+ * start_aps() - Start up the APs and count how many we find
+ *
+ * This is called on the boot processor to start up all the other processors
+ * (here called APs).
+ *
+ * @num_aps: Number of APs we expect to find
+ * @ap_count: Initially zero. Incremented by this function for each AP found
+ * @return 0 if all APs were set up correctly or there are none to set up,
+ * -ENOSPC if the SIPI vector is too high in memory,
+ * -ETIMEDOUT if the ICR is busy or the second SIPI fails to complete
+ * -EIO if not all APs check in correctly
+ */
+static int start_aps(int num_aps, atomic_t *ap_count)
 {
int sipi_vector;
/* Max location is 4KiB below 1MiB */
const int max_vector_loc = ((1 << 20) - (1 << 12)) >> 12;
 
-   if (ap_count == 0)
+   if (num_aps == 0)
return 0;
 
/* The vector is sent as a 4k aligned address in one byte */
@@ -326,7 +339,7 @@ static int start_aps(int ap_count, atomic_t *num_aps)
return -ENOSPC;
}
 
-   debug("Attempting to start %d APs\n", ap_count);
+   debug("Attempting to start %d APs\n", num_aps);
 
if (apic_wait_timeout(1000, "ICR not to be busy"))
return -ETIMEDOUT;
@@ -349,7 +362,7 @@ static int start_aps(int ap_count, atomic_t *num_aps)
return -ETIMEDOUT;
 
/* Wait for CPUs to check in up to 200 us */
-   wait_for_aps(num_aps, ap_count, 200, 15);
+   wait_for_aps(ap_count, num_aps, 200, 15);
 
/* Send 2nd SIPI */
if (apic_wait_timeout(1000, "ICR not to be busy"))
@@ -362,9 +375,9 @@ static int start_aps(int ap_count, atomic_t *num_aps)
return -ETIMEDOUT;
 
/* Wait for CPUs to check in */
-   if (wait_for_aps(num_aps, ap_count, 1, 50)) {
+   if (wait_for_aps(ap_count, num_aps, 1, 50)) {
debug("Not all APs checked in: %d/%d\n",
- atomic_read(num_aps), ap_count);
+ atomic_read(ap_count), num_aps);
return -EIO;
}
 
-- 
2.28.0.rc0.105.gf9edc3c819-goog



[PATCH v6 02/25] x86: Move MP code into mp_init

2020-07-17 Thread Simon Glass
At present the 'flight plan' for CPUs is passed into mp_init. But it is
always the same. Move it into the mp_init file so everything is in one
place. Also drop the SMI function since it does nothing. If we implement
SMIs, more refactoring will be needed anyway.

Signed-off-by: Simon Glass 
Reviewed-by: Wolfgang Wallner 
Reviewed-by: Bin Meng 
---

(no changes since v1)

 arch/x86/cpu/i386/cpu.c   | 24 +---
 arch/x86/cpu/mp_init.c| 22 ++
 arch/x86/include/asm/mp.h | 17 +
 3 files changed, 16 insertions(+), 47 deletions(-)

diff --git a/arch/x86/cpu/i386/cpu.c b/arch/x86/cpu/i386/cpu.c
index a6a6afec8c..55a0907bc8 100644
--- a/arch/x86/cpu/i386/cpu.c
+++ b/arch/x86/cpu/i386/cpu.c
@@ -21,6 +21,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -631,29 +632,14 @@ int cpu_jump_to_64bit_uboot(ulong target)
 }
 
 #ifdef CONFIG_SMP
-static int enable_smis(struct udevice *cpu, void *unused)
-{
-   return 0;
-}
-
-static struct mp_flight_record mp_steps[] = {
-   MP_FR_BLOCK_APS(mp_init_cpu, NULL, mp_init_cpu, NULL),
-   /* Wait for APs to finish initialization before proceeding */
-   MP_FR_BLOCK_APS(NULL, NULL, enable_smis, NULL),
-};
-
 int x86_mp_init(void)
 {
-   struct mp_params mp_params;
-
-   mp_params.parallel_microcode_load = 0,
-   mp_params.flight_plan = _steps[0];
-   mp_params.num_records = ARRAY_SIZE(mp_steps);
-   mp_params.microcode_pointer = 0;
+   int ret;
 
-   if (mp_init(_params)) {
+   ret = mp_init();
+   if (ret) {
printf("Warning: MP init failure\n");
-   return -EIO;
+   return log_ret(ret);
}
 
return 0;
diff --git a/arch/x86/cpu/mp_init.c b/arch/x86/cpu/mp_init.c
index c25d17c647..831fd7035d 100644
--- a/arch/x86/cpu/mp_init.c
+++ b/arch/x86/cpu/mp_init.c
@@ -41,6 +41,9 @@ struct saved_msr {
uint32_t hi;
 } __packed;
 
+static struct mp_flight_record mp_steps[] = {
+   MP_FR_BLOCK_APS(mp_init_cpu, NULL, mp_init_cpu, NULL),
+};
 
 struct mp_flight_plan {
int num_records;
@@ -372,7 +375,7 @@ static int start_aps(int ap_count, atomic_t *num_aps)
return 0;
 }
 
-static int bsp_do_flight_plan(struct udevice *cpu, struct mp_params *mp_params)
+static int bsp_do_flight_plan(struct udevice *cpu, struct mp_flight_plan *plan)
 {
int i;
int ret = 0;
@@ -380,8 +383,8 @@ static int bsp_do_flight_plan(struct udevice *cpu, struct 
mp_params *mp_params)
const int step_us = 100;
int num_aps = num_cpus - 1;
 
-   for (i = 0; i < mp_params->num_records; i++) {
-   struct mp_flight_record *rec = _params->flight_plan[i];
+   for (i = 0; i < plan->num_records; i++) {
+   struct mp_flight_record *rec = >records[i];
 
/* Wait for APs if the record is not released */
if (atomic_read(>barrier) == 0) {
@@ -420,7 +423,7 @@ static int init_bsp(struct udevice **devp)
return 0;
 }
 
-int mp_init(struct mp_params *p)
+int mp_init(void)
 {
int num_aps;
atomic_t *ap_count;
@@ -445,11 +448,6 @@ int mp_init(struct mp_params *p)
return ret;
}
 
-   if (p == NULL || p->flight_plan == NULL || p->num_records < 1) {
-   printf("Invalid MP parameters\n");
-   return -EINVAL;
-   }
-
num_cpus = cpu_get_count(cpu);
if (num_cpus < 0) {
debug("Cannot get number of CPUs: err=%d\n", num_cpus);
@@ -464,8 +462,8 @@ int mp_init(struct mp_params *p)
debug("Warning: Device tree does not describe all CPUs. Extra 
ones will not be started correctly\n");
 
/* Copy needed parameters so that APs have a reference to the plan */
-   mp_info.num_records = p->num_records;
-   mp_info.records = p->flight_plan;
+   mp_info.num_records = ARRAY_SIZE(mp_steps);
+   mp_info.records = mp_steps;
 
/* Load the SIPI vector */
ret = load_sipi_vector(_count, num_cpus);
@@ -489,7 +487,7 @@ int mp_init(struct mp_params *p)
}
 
/* Walk the flight plan for the BSP */
-   ret = bsp_do_flight_plan(cpu, p);
+   ret = bsp_do_flight_plan(cpu, _info);
if (ret) {
debug("CPU init failed: err=%d\n", ret);
return ret;
diff --git a/arch/x86/include/asm/mp.h b/arch/x86/include/asm/mp.h
index 9dddf88b5a..db02904ecb 100644
--- a/arch/x86/include/asm/mp.h
+++ b/arch/x86/include/asm/mp.h
@@ -51,21 +51,6 @@ struct mp_flight_record {
 #define MP_FR_NOBLOCK_APS(ap_func, ap_arg, bsp_func, bsp_arg) \
MP_FLIGHT_RECORD(1, ap_func, ap_arg, bsp_func, bsp_arg)
 
-/*
- * The mp_params structure provides the arguments to the mp subsystem
- * for bringing up APs.
- *
- * At present this is overkill for U-Boot, but it may make it easier to add
- * SMM support.
- */
-struct mp_params {
-   int parallel_microcode_load;
-   const 

[PATCH v6 03/25] x86: mp_init: Avoid declarations in header files

2020-07-17 Thread Simon Glass
The functions used by the flight plan are declared in the header file but
are not used in any other file.

Move the flight plan steps down to just above where it is used so that we
can make these function static.

Signed-off-by: Simon Glass 
Reviewed-by: Wolfgang Wallner 
Reviewed-by: Bin Meng 
---

(no changes since v1)

 arch/x86/cpu/mp_init.c| 40 +++
 arch/x86/include/asm/mp.h |  3 ---
 2 files changed, 20 insertions(+), 23 deletions(-)

diff --git a/arch/x86/cpu/mp_init.c b/arch/x86/cpu/mp_init.c
index 831fd7035d..e77d7f2cd6 100644
--- a/arch/x86/cpu/mp_init.c
+++ b/arch/x86/cpu/mp_init.c
@@ -41,10 +41,6 @@ struct saved_msr {
uint32_t hi;
 } __packed;
 
-static struct mp_flight_record mp_steps[] = {
-   MP_FR_BLOCK_APS(mp_init_cpu, NULL, mp_init_cpu, NULL),
-};
-
 struct mp_flight_plan {
int num_records;
struct mp_flight_record *records;
@@ -423,6 +419,26 @@ static int init_bsp(struct udevice **devp)
return 0;
 }
 
+static int mp_init_cpu(struct udevice *cpu, void *unused)
+{
+   struct cpu_platdata *plat = dev_get_parent_platdata(cpu);
+
+   /*
+* Multiple APs are brought up simultaneously and they may get the same
+* seq num in the uclass_resolve_seq() during device_probe(). To avoid
+* this, set req_seq to the reg number in the device tree in advance.
+*/
+   cpu->req_seq = dev_read_u32_default(cpu, "reg", -1);
+   plat->ucode_version = microcode_read_rev();
+   plat->device_id = gd->arch.x86_device;
+
+   return device_probe(cpu);
+}
+
+static struct mp_flight_record mp_steps[] = {
+   MP_FR_BLOCK_APS(mp_init_cpu, NULL, mp_init_cpu, NULL),
+};
+
 int mp_init(void)
 {
int num_aps;
@@ -495,19 +511,3 @@ int mp_init(void)
 
return 0;
 }
-
-int mp_init_cpu(struct udevice *cpu, void *unused)
-{
-   struct cpu_platdata *plat = dev_get_parent_platdata(cpu);
-
-   /*
-* Multiple APs are brought up simultaneously and they may get the same
-* seq num in the uclass_resolve_seq() during device_probe(). To avoid
-* this, set req_seq to the reg number in the device tree in advance.
-*/
-   cpu->req_seq = dev_read_u32_default(cpu, "reg", -1);
-   plat->ucode_version = microcode_read_rev();
-   plat->device_id = gd->arch.x86_device;
-
-   return device_probe(cpu);
-}
diff --git a/arch/x86/include/asm/mp.h b/arch/x86/include/asm/mp.h
index db02904ecb..94af819ad9 100644
--- a/arch/x86/include/asm/mp.h
+++ b/arch/x86/include/asm/mp.h
@@ -72,9 +72,6 @@ struct mp_flight_record {
  */
 int mp_init(void);
 
-/* Probes the CPU device */
-int mp_init_cpu(struct udevice *cpu, void *unused);
-
 /* Set up additional CPUs */
 int x86_mp_init(void);
 
-- 
2.28.0.rc0.105.gf9edc3c819-goog



[PATCH v6 01/25] x86: mp_init: Switch to livetree

2020-07-17 Thread Simon Glass
Update this code to use livetree calls instead of flat-tree.

Signed-off-by: Simon Glass 
Reviewed-by: Wolfgang Wallner 
Reviewed-by: Bin Meng 
---

(no changes since v1)

 arch/x86/cpu/mp_init.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/x86/cpu/mp_init.c b/arch/x86/cpu/mp_init.c
index 7fde4ff7e1..c25d17c647 100644
--- a/arch/x86/cpu/mp_init.c
+++ b/arch/x86/cpu/mp_init.c
@@ -507,8 +507,7 @@ int mp_init_cpu(struct udevice *cpu, void *unused)
 * seq num in the uclass_resolve_seq() during device_probe(). To avoid
 * this, set req_seq to the reg number in the device tree in advance.
 */
-   cpu->req_seq = fdtdec_get_int(gd->fdt_blob, dev_of_offset(cpu), "reg",
- -1);
+   cpu->req_seq = dev_read_u32_default(cpu, "reg", -1);
plat->ucode_version = microcode_read_rev();
plat->device_id = gd->arch.x86_device;
 
-- 
2.28.0.rc0.105.gf9edc3c819-goog



[PATCH v6 05/25] x86: mp_init: Drop the num_cpus static variable

2020-07-17 Thread Simon Glass
This does not need to be global across all functions in this file. Pass a
parameter instead.

Signed-off-by: Simon Glass 
Reviewed-by: Wolfgang Wallner 
Reviewed-by: Bin Meng 
---

(no changes since v3)

Changes in v3:
- Update bsp_do_flight_plan() to say 'on the BSP'

 arch/x86/cpu/mp_init.c | 22 +++---
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/arch/x86/cpu/mp_init.c b/arch/x86/cpu/mp_init.c
index 8b00d57c88..df43f71572 100644
--- a/arch/x86/cpu/mp_init.c
+++ b/arch/x86/cpu/mp_init.c
@@ -31,9 +31,6 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-/* Total CPUs include BSP */
-static int num_cpus;
-
 /* This also needs to match the sipi.S assembly code for saved MSR encoding */
 struct saved_msr {
uint32_t index;
@@ -384,13 +381,23 @@ static int start_aps(int num_aps, atomic_t *ap_count)
return 0;
 }
 
-static int bsp_do_flight_plan(struct udevice *cpu, struct mp_flight_plan *plan)
+/**
+ * bsp_do_flight_plan() - Do the flight plan on the BSP
+ *
+ * This runs the flight plan on the main CPU used to boot U-Boot
+ *
+ * @cpu: Device for the main CPU
+ * @plan: Flight plan to run
+ * @num_aps: Number of APs (CPUs other than the BSP)
+ * @returns 0 on success, -ETIMEDOUT if an AP failed to come up
+ */
+static int bsp_do_flight_plan(struct udevice *cpu, struct mp_flight_plan *plan,
+ int num_aps)
 {
int i;
int ret = 0;
const int timeout_us = 10;
const int step_us = 100;
-   int num_aps = num_cpus - 1;
 
for (i = 0; i < plan->num_records; i++) {
struct mp_flight_record *rec = >records[i];
@@ -410,6 +417,7 @@ static int bsp_do_flight_plan(struct udevice *cpu, struct 
mp_flight_plan *plan)
 
release_barrier(>barrier);
}
+
return ret;
 }
 
@@ -454,7 +462,7 @@ static struct mp_flight_record mp_steps[] = {
 
 int mp_init(void)
 {
-   int num_aps;
+   int num_aps, num_cpus;
atomic_t *ap_count;
struct udevice *cpu;
int ret;
@@ -516,7 +524,7 @@ int mp_init(void)
}
 
/* Walk the flight plan for the BSP */
-   ret = bsp_do_flight_plan(cpu, _info);
+   ret = bsp_do_flight_plan(cpu, _info, num_aps);
if (ret) {
debug("CPU init failed: err=%d\n", ret);
return ret;
-- 
2.28.0.rc0.105.gf9edc3c819-goog



[PATCH v6 00/25] x86: Enhance MTRR functionality to support multiple CPUs

2020-07-17 Thread Simon Glass
At present MTRRs are mirrored to the secondary CPUs only once, as those
CPUs are started up. But U-Boot may add more MTRRs later, e.g. if it
decides that a video console must be set up.

This series enhances the x86 multi-processor support to allow MTRRs to
be updated at any time. It also updates the 'mtrr' command to support
setting the MTRRs on CPUs other than the boot CPU.

Changes in v6:
- Rebase to x86/master

Changes in v5:
- Drop timing in mp_park_aps()

Changes in v4:
- Update get_bsp() to return zero when SMP is not inited
- Add a Kconfig to control this feature, enabled only on APL
- Only enable this feature of CONFIG_SMP_AP_WORK is enabled
- Allow running on the BSP if SMP is not enabled
- Update mp_next_cpu() to stop if CONFIG_SMP_AP_WORK is not enabled

Changes in v3:
- Update bsp_do_flight_plan() to say 'on the BSP'
- s/slow/slot/
- Use C code instead of assembler to read/write callback pointers
- Update commit message to mention dropping of cpu_map
- Rename flag to GD_FLG_SMP_READY
- Rename flag to GD_FLG_SMP_READY
- Add a comment to run_ap_work()
- Rename flag to GD_FLG_SMP_READY
- Update the comment for run_ap_work() to explain logical_cpu_number
- Clarify meaning of @cpu_select in mp_run_on_cpus() comment
- Update the comment for mp_park_aps()
- Add more comments on how the iterators work
- Mention that the CPU number is in hex
- Remove stray asterisk from comments
- Drop mention of cpu_map which was handled in a previous patch

Changes in v2:
- Add comments to explain what start_aps() does
- Drop change to include/dm/uclass.h
- Mention error return in get_bsp()
- Add more comments
- Rename mtrr_save_all() to mtrr_read_all()
- Add a new patch to avoid enabling SMP in SPL
- Add new patch to add AP_DEFAULT_BASE to coral's memory map
- Rename function to mtrr_write_all()
- Keep things building by temporarily renaming the function in cmd/
- Drop the renamed mtrr_set_valid_() instead of mtrr_set_valid()
- Add a new patch with more comments

Simon Glass (25):
  x86: mp_init: Switch to livetree
  x86: Move MP code into mp_init
  x86: mp_init: Avoid declarations in header files
  x86: mp_init: Switch parameter names in start_aps()
  x86: mp_init: Drop the num_cpus static variable
  x86: mtrr: Fix 'ensable' typo
  x86: mp_init: Set up the CPU numbers at the start
  x86: mp_init: Adjust bsp_init() to return more information
  x86: cpu: Remove unnecessary #ifdefs
  x86: mp: Support APs waiting for instructions
  global_data: Add a generic global_data flag for SMP state
  x86: Set the SMP flag when MP init is complete
  x86: mp: Allow running functions on multiple CPUs
  x86: mp: Park CPUs before running the OS
  x86: mp: Add iterators for CPUs
  x86: mtrr: Use MP calls to list the MTRRs
  x86: Don't enable SMP in SPL
  x86: coral: Update the memory map
  x86: mtrr: Update MTRRs on all CPUs
  x86: mtrr: Add support for writing to MTRRs on any CPU
  x86: mtrr: Update the command to use the new mtrr calls
  x86: mtrr: Restructure so command execution is in one place
  x86: mtrr: Update 'mtrr' to allow setting MTRRs on any CPU
  x86: mp: Add more comments to the module
  x86: mtrr: Enhance 'mtrr' command to list MTRRs on any CPU

 arch/x86/Kconfig  |   7 +
 arch/x86/cpu/Makefile |   2 +-
 arch/x86/cpu/apollolake/Kconfig   |   1 +
 arch/x86/cpu/cpu.c|  58 +--
 arch/x86/cpu/i386/cpu.c   |  26 +-
 arch/x86/cpu/mp_init.c| 528 ++
 arch/x86/cpu/mtrr.c   | 149 
 arch/x86/include/asm/mp.h | 137 ++-
 arch/x86/include/asm/mtrr.h   |  51 +++
 cmd/x86/mtrr.c| 148 +---
 doc/board/google/chromebook_coral.rst |   1 +
 include/asm-generic/global_data.h |   1 +
 12 files changed, 924 insertions(+), 185 deletions(-)

-- 
2.28.0.rc0.105.gf9edc3c819-goog



Re: [PATCH v2 1/4] usb: xhci: Add missing endian conversions (cpu_to_leXX / leXX_to_cpu)

2020-07-17 Thread Bin Meng
Hi Stefan,

On Fri, Jul 17, 2020 at 10:04 PM Stefan Roese  wrote:
>
> While trying to use the U-Boot xHCI driver on the MIPS Octeon platform,
> which is big endian, I noticed that the driver is missing a few endian
> conversion calls. This patch adds these missing endian conversion
> calls.
>
> Signed-off-by: Stefan Roese 
> Reviewed-by: Bin Meng 
> Cc: Bin Meng 
> Cc: Marek Vasut 
> ---
> v2:
> - Add missing (uintptr_t) cast to remove compile time warning
>
>  drivers/usb/host/xhci-mem.c | 9 +
>  1 file changed, 5 insertions(+), 4 deletions(-)

Tested-by: Bin Meng 

Only this patch is sent as v2?

Regards,
Bin


[PATCH v2 1/4] usb: xhci: Add missing endian conversions (cpu_to_leXX / leXX_to_cpu)

2020-07-17 Thread Stefan Roese
While trying to use the U-Boot xHCI driver on the MIPS Octeon platform,
which is big endian, I noticed that the driver is missing a few endian
conversion calls. This patch adds these missing endian conversion
calls.

Signed-off-by: Stefan Roese 
Reviewed-by: Bin Meng 
Cc: Bin Meng 
Cc: Marek Vasut 
---
v2:
- Add missing (uintptr_t) cast to remove compile time warning

 drivers/usb/host/xhci-mem.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index 2d968aafb0..7d55944765 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -110,7 +110,7 @@ static void xhci_scratchpad_free(struct xhci_ctrl *ctrl)
 
ctrl->dcbaa->dev_context_ptrs[0] = 0;
 
-   free((void *)(uintptr_t)ctrl->scratchpad->sp_array[0]);
+   free((void *)(uintptr_t)le64_to_cpu(ctrl->scratchpad->sp_array[0]));
free(ctrl->scratchpad->sp_array);
free(ctrl->scratchpad);
ctrl->scratchpad = NULL;
@@ -225,7 +225,8 @@ static void xhci_link_segments(struct xhci_segment *prev,
prev->next = next;
if (link_trbs) {
val_64 = (uintptr_t)next->trbs;
-   prev->trbs[TRBS_PER_SEGMENT-1].link.segment_ptr = val_64;
+   prev->trbs[TRBS_PER_SEGMENT-1].link.segment_ptr =
+   cpu_to_le64(val_64);
 
/*
 * Set the last TRB in the segment to
@@ -486,7 +487,7 @@ int xhci_alloc_virt_device(struct xhci_ctrl *ctrl, unsigned 
int slot_id)
byte_64 = (uintptr_t)(virt_dev->out_ctx->bytes);
 
/* Point to output device context in dcbaa. */
-   ctrl->dcbaa->dev_context_ptrs[slot_id] = byte_64;
+   ctrl->dcbaa->dev_context_ptrs[slot_id] = cpu_to_le64(byte_64);
 
xhci_flush_cache((uintptr_t)>dcbaa->dev_context_ptrs[slot_id],
 sizeof(__le64));
@@ -768,7 +769,7 @@ void xhci_setup_addressable_virt_dev(struct xhci_ctrl *ctrl,
 
debug("route string %x\n", route);
 #endif
-   slot_ctx->dev_info |= route;
+   slot_ctx->dev_info |= cpu_to_le32(route);
 
switch (speed) {
case USB_SPEED_SUPER:
-- 
2.27.0



Re: [PATCH v1 1/4] usb: xhci: Add missing endian conversions (cpu_to_leXX / leXX_to_cpu)

2020-07-17 Thread Bin Meng
Hi Stefan,

On Fri, Jul 17, 2020 at 7:34 PM Stefan Roese  wrote:
>
> Hi Bin,
>
> On 17.07.20 13:18, Bin Meng wrote:
> > Hi Stefan,
> >
> > On Thu, Jul 2, 2020 at 4:47 PM Stefan Roese  wrote:
> >>
> >> While trying to use the U-Boot xHCI driver on the MIPS Octeon platform,
> >> which is big endian, I noticed that the driver is missing a few endian
> >> conversion calls. This patch adds these missing endian conversion
> >> calls.
> >>
> >> Signed-off-by: Stefan Roese 
> >> Cc: Bin Meng 
> >> Cc: Marek Vasut 
> >> ---
> >>
> >>   drivers/usb/host/xhci-mem.c | 9 +
> >>   1 file changed, 5 insertions(+), 4 deletions(-)
> >>
> >> diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
> >> index 2d968aafb0..bd959b4093 100644
> >> --- a/drivers/usb/host/xhci-mem.c
> >> +++ b/drivers/usb/host/xhci-mem.c
> >> @@ -110,7 +110,7 @@ static void xhci_scratchpad_free(struct xhci_ctrl 
> >> *ctrl)
> >>
> >>  ctrl->dcbaa->dev_context_ptrs[0] = 0;
> >>
> >> -   free((void *)(uintptr_t)ctrl->scratchpad->sp_array[0]);
> >> +   free((void *)le64_to_cpu(ctrl->scratchpad->sp_array[0]));
> >
> > There is a build warning for this:
> >
> > drivers/usb/host/xhci-mem.c: In function 'xhci_scratchpad_free':
> > drivers/usb/host/xhci-mem.c:113:7: warning: cast to pointer from
> > integer of different size [-Wint-to-pointer-cast]
> >free((void *)le64_to_cpu(ctrl->scratchpad->sp_array[0]));
> > ^
>
> So we need the (uintptr_t) here as well?
>
>free((void *)(uintptr_t)le64_to_cpu(ctrl->scratchpad->sp_array[0]));

I think so.

>
> Should I send v2 for this patch?

Yes, please.

>
> >>  free(ctrl->scratchpad->sp_array);
> >>  free(ctrl->scratchpad);
> >>  ctrl->scratchpad = NULL;
> >> @@ -225,7 +225,8 @@ static void xhci_link_segments(struct xhci_segment 
> >> *prev,
> >>  prev->next = next;
> >>  if (link_trbs) {
> >>  val_64 = (uintptr_t)next->trbs;
> >> -   prev->trbs[TRBS_PER_SEGMENT-1].link.segment_ptr = val_64;
> >> +   prev->trbs[TRBS_PER_SEGMENT-1].link.segment_ptr =
> >> +   cpu_to_le64(val_64);
> >>
> >>  /*
> >>   * Set the last TRB in the segment to
> >> @@ -486,7 +487,7 @@ int xhci_alloc_virt_device(struct xhci_ctrl *ctrl, 
> >> unsigned int slot_id)
> >>  byte_64 = (uintptr_t)(virt_dev->out_ctx->bytes);
> >>
> >>  /* Point to output device context in dcbaa. */
> >> -   ctrl->dcbaa->dev_context_ptrs[slot_id] = byte_64;
> >> +   ctrl->dcbaa->dev_context_ptrs[slot_id] = cpu_to_le64(byte_64);
> >>
> >>  
> >> xhci_flush_cache((uintptr_t)>dcbaa->dev_context_ptrs[slot_id],
> >>   sizeof(__le64));
> >> @@ -768,7 +769,7 @@ void xhci_setup_addressable_virt_dev(struct xhci_ctrl 
> >> *ctrl,
> >>
> >>  debug("route string %x\n", route);
> >>   #endif
> >> -   slot_ctx->dev_info |= route;
> >> +   slot_ctx->dev_info |= cpu_to_le32(route);
> >>
> >>  switch (speed) {
> >>  case USB_SPEED_SUPER:
> >> --
> >
> > Test results on Minnowmax which has one USB 2.0 port and one 3.0 port:
> >
> > USB 2.0 flash drive inserted to USB 2.0 port: recognized, read/write OK
> > USB 2.0 flash drive inserted to USB 3.0 port: recognized, read/write OK
> >
> > USB 3.0 flash drive inserted to USB 2.0 port: recognized, read/write OK
> > USB 3.0 flash drive inserted to USB 3.0 port: recognized, read/write OK
> >
> > USB 2.0 flash drive connected to a USB 3.0 HUB inserted to USB 2.0
> > port: recognized, read/write OK
> > USB 2.0 flash drive connected to a USB 3.0 HUB inserted to USB 3.0
> > port: recognized, read/write OK
> >
> > USB 3.0 flash drive connected to a USB 3.0 HUB inserted to USB 2.0
> > port: recognized, read/write OK
> > USB 3.0 flash drive connected to a USB 3.0 HUB inserted to USB 3.0
> > port: recognized, read/write OK
> >
> > Tested-by: Bin Meng 
>
> Very good. :)

Regards,
Bin


Re: [PATCH 1/4] lmb/bdinfo: dump lmb info via bdinfo

2020-07-17 Thread Tero Kristo

On 17/07/2020 16:29, Tom Rini wrote:

On Fri, Jun 12, 2020 at 03:41:18PM +0300, Tero Kristo wrote:


Dump lmb status from the bdinfo command. This is useful for seeing the
reserved memory regions from the u-boot cmdline.

Signed-off-by: Tero Kristo 
---
  cmd/bdinfo.c  |  8 +++-
  include/lmb.h |  1 +
  lib/lmb.c | 42 +++---
  3 files changed, 31 insertions(+), 20 deletions(-)

diff --git a/cmd/bdinfo.c b/cmd/bdinfo.c
index dba552b03f..05e1b27de0 100644
--- a/cmd/bdinfo.c
+++ b/cmd/bdinfo.c
@@ -10,6 +10,7 @@
  #include 
  #include 
  #include 
+#include 
  #include 
  #include 
  #include 
@@ -365,8 +366,13 @@ static int do_bdinfo(struct cmd_tbl *cmdtp, int flag, int 
argc,
  #if CONFIG_IS_ENABLED(MULTI_DTB_FIT)
print_num("multi_dtb_fit", (ulong)gd->multi_dtb_fit);
  #endif
-   if (gd->fdt_blob)
+   if (gd->fdt_blob) {
+   struct lmb lmb;
print_num("fdt_blob", (ulong)gd->fdt_blob);
+   lmb_init_and_reserve(, gd->bd, (void *)gd->fdt_blob);
+   lmb_dump_all_force();
+   }
+
print_cpu_word_size();
  
  	return 0;


Can you please rebase this on top of master?  Simon's series to cleanup
bdinfo stuff has been applied, thanks.  The rest of your changes are
fine and under test now.


Yeah, I can repost this single patch. Thanks for the heads-up.

-Tero

--
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. 
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki


[PATCH 1/2] bcmgenet: fix DMA buffer management

2020-07-17 Thread Jason Wessel
This commit fixes a serious issue occurring when several network
commands are run on a raspberry pi 4 board: for instance a "dhcp"
command and then one or several "tftp" commands. In this case,
packet recv callbacks were called several times on the same packets,
and send function was failing most of the time.

note: if the boot procedure is made of a single network
command, the issue is not visible.

The issue is related to management of the packet ring buffers
(producer / consumer) and DMA.
Each time a packet is received, the ethernet device stores it
in the buffer and increments an index called RDMA_PROD_INDEX.
Each time the driver outputs a received packet, it increments
another index called RDMA_CONS_INDEX.

Between each pair of network commands, as part of the driver
'start' function, previous code tried to reset both RDMA_CONS_INDEX
and RDMA_PROD_INDEX to 0. But RDMA_PROD_INDEX cannot be written from
driver side, thus its value was actually not updated, and only
RDMA_CONS_INDEX was reset to 0. This was resulting in a major
synchronization issue between the driver and the device. Most
visible behavior was that the driver seemed to receive again the
packets from the previous commands (e.g. DHCP response packets
"received" again when performing the first TFTP command).

This fix consists in setting RDMA_CONS_INDEX to the same
value as RDMA_PROD_INDEX, when resetting the driver.

The same kind of fix was needed on the TX side, and a few variables
had to be reset accordingly (c_index, tx_index, rx_index).

The rx_index and tx_index have only 256 entries so the bottom 8 bits
must be masked off.

Originated-by: Etienne Dublé 
Signed-off-by: Jason Wessel 
---
 drivers/net/bcmgenet.c | 17 +
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/net/bcmgenet.c b/drivers/net/bcmgenet.c
index 11b6148ab6..1b7e7ba2bf 100644
--- a/drivers/net/bcmgenet.c
+++ b/drivers/net/bcmgenet.c
@@ -378,8 +378,6 @@ static void rx_descs_init(struct bcmgenet_eth_priv *priv)
u32 len_stat, i;
void *desc_base = priv->rx_desc_base;
 
-   priv->c_index = 0;
-
len_stat = (RX_BUF_LENGTH << DMA_BUFLENGTH_SHIFT) | DMA_OWN;
 
for (i = 0; i < RX_DESCS; i++) {
@@ -403,8 +401,11 @@ static void rx_ring_init(struct bcmgenet_eth_priv *priv)
writel(RX_DESCS * DMA_DESC_SIZE / 4 - 1,
   priv->mac_reg + RDMA_RING_REG_BASE + DMA_END_ADDR);
 
-   writel(0x0, priv->mac_reg + RDMA_PROD_INDEX);
-   writel(0x0, priv->mac_reg + RDMA_CONS_INDEX);
+   /* cannot init RDMA_PROD_INDEX to 0, so align RDMA_CONS_INDEX on it 
instead */
+   priv->c_index = readl(priv->mac_reg + RDMA_PROD_INDEX);
+   writel(priv->c_index, priv->mac_reg + RDMA_CONS_INDEX);
+   priv->rx_index = priv->c_index;
+   priv->rx_index &= 0xFF;
writel((RX_DESCS << DMA_RING_SIZE_SHIFT) | RX_BUF_LENGTH,
   priv->mac_reg + RDMA_RING_REG_BASE + DMA_RING_BUF_SIZE);
writel(DMA_FC_THRESH_VALUE, priv->mac_reg + RDMA_XON_XOFF_THRESH);
@@ -421,8 +422,10 @@ static void tx_ring_init(struct bcmgenet_eth_priv *priv)
writel(0x0, priv->mac_reg + TDMA_WRITE_PTR);
writel(TX_DESCS * DMA_DESC_SIZE / 4 - 1,
   priv->mac_reg + TDMA_RING_REG_BASE + DMA_END_ADDR);
-   writel(0x0, priv->mac_reg + TDMA_PROD_INDEX);
-   writel(0x0, priv->mac_reg + TDMA_CONS_INDEX);
+   /* cannot init TDMA_CONS_INDEX to 0, so align TDMA_PROD_INDEX on it 
instead */
+   priv->tx_index = readl(priv->mac_reg + TDMA_CONS_INDEX);
+   writel(priv->tx_index, priv->mac_reg + TDMA_PROD_INDEX);
+   priv->tx_index &= 0xFF;
writel(0x1, priv->mac_reg + TDMA_RING_REG_BASE + DMA_MBUF_DONE_THRESH);
writel(0x0, priv->mac_reg + TDMA_FLOW_PERIOD);
writel((TX_DESCS << DMA_RING_SIZE_SHIFT) | RX_BUF_LENGTH,
@@ -469,8 +472,6 @@ static int bcmgenet_gmac_eth_start(struct udevice *dev)
 
priv->tx_desc_base = priv->mac_reg + GENET_TX_OFF;
priv->rx_desc_base = priv->mac_reg + GENET_RX_OFF;
-   priv->tx_index = 0x0;
-   priv->rx_index = 0x0;
 
bcmgenet_umac_reset(priv);
 
-- 
2.17.1



[PATCH 2/2] bcmgenet: Add support for rgmii-rxid

2020-07-17 Thread Jason Wessel
The commit 57805f2270c4 ("net: bcmgenet: Don't set ID_MODE_DIS when
not using RGMII") needed to be extended for the case of using the
rgmii-rxid.  The latest version of the Rasbperry Pi4 dtb files for the
5.4 now specify the rgmii-rxid.

Signed-off-by: Jason Wessel 
---
 drivers/net/bcmgenet.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/net/bcmgenet.c b/drivers/net/bcmgenet.c
index 1b7e7ba2bf..ace1331362 100644
--- a/drivers/net/bcmgenet.c
+++ b/drivers/net/bcmgenet.c
@@ -457,7 +457,8 @@ static int bcmgenet_adjust_link(struct bcmgenet_eth_priv 
*priv)
clrsetbits_32(priv->mac_reg + EXT_RGMII_OOB_CTRL, OOB_DISABLE,
RGMII_LINK | RGMII_MODE_EN);
 
-   if (phy_dev->interface == PHY_INTERFACE_MODE_RGMII)
+   if (phy_dev->interface == PHY_INTERFACE_MODE_RGMII ||
+   phy_dev->interface == PHY_INTERFACE_MODE_RGMII_RXID)
setbits_32(priv->mac_reg + EXT_RGMII_OOB_CTRL, ID_MODE_DIS);
 
writel(speed << CMD_SPEED_SHIFT, (priv->mac_reg + UMAC_CMD));
-- 
2.17.1



Re: [PATCH] lib: zlib: Use post-increment only in inffast.c

2020-07-17 Thread Tom Rini
On Wed, Jun 24, 2020 at 04:34:03PM +0800, Ley Foon Tan wrote:

> From: Chin Liang See 
> 
> This fixes CVE-2016-9841. Changes integrated from [1], with changes
> make for Uboot code base.
> 
> An old inffast.c optimization turns out to not be optimal anymore
> with modern compilers, and furthermore was not compliant with the
> C standard, for which decrementing a pointer before its allocated
> memory is undefined. Per the recommendation of a security audit of
> the zlib code by Trail of Bits and TrustInSoft, in support of the
> Mozilla Foundation, this "optimization" was removed, in order to
> avoid the possibility of undefined behavior.
> 
> [1]: 
> https://github.com/madler/zlib/commit/9aaec95e82117c1cb0f9624264c3618fc380cecb
> 
> Signed-off-by: Mark Adler 
> Signed-off-by: Chin Liang See 
> Signed-off-by: Ley Foon Tan 

This breaks the following tests on sandbox:
FAILED test/py/tests/test_efi_fit.py::test_efi_fit_launch - u_boot_spawn.Timeout
FAILED test/py/tests/test_fit.py::test_fit - OSError: [Errno 5] Input/output 
error

-- 
Tom


signature.asc
Description: PGP signature


  1   2   >