Re: [U-Boot] [PATCH v10 08/16] regmap: Add raw read/write functions

2018-10-15 Thread Mario Six
Hi Simon,
On Sat, Oct 13, 2018 at 3:52 PM Simon Glass  wrote:
>
> Hi Mario,
>
> On 4 October 2018 at 01:00, Mario Six  wrote:
> > The regmap functions currently assume that all register map accesses
> > have a data width of 32 bits, but there are maps that have different
> > widths.
> >
> > To rectify this, implement the regmap_raw_read and regmap_raw_write
> > functions from the Linux kernel API that specify the width of a desired
> > read or write operation on a regmap.
> >
> > Implement the regmap_read and regmap_write functions using these raw
> > functions in a backwards-compatible manner.
> >
> > Reviewed-by: Anatolij Gustschin 
> > Signed-off-by: Mario Six 
> >
> > ---
> >
> > v9 -> v10:
> > * Switched to the read{b,w,l,q} and write{b,w,l,q} functions for
> >   register map access
> >
> > v8 -> v9:
> > * Removed forgotten "fpgamap" in documentation
> >
> > v7 -> v8:
> > No changes
> >
> > v6 -> v7:
> > * Fixed wrong variable type in 64-bit read (u32 -> u64)
> > * Added 64-bit case in write function
> >
> > v5 -> v6:
> > * Corrected format specifier
> > * Added support for 64-bit reads/writes
> >
> > v4 -> v5:
> > No changes
> >
> > v3 -> v4:
> > * Switched 'ranges[0] + offset' to 'ranges[0].start + offset'
> > * Explained the difference between the raw and non-raw read/write
> >   functions better in the docs
> >
> > v2 -> v3:
> > * Implement the "raw" functions from Linux instead of adding a size
> >   parameter to the regmap_{read,write} functions
> > * Fixed style violation
> > * Improved error handling
> >
> > v1 -> v2:
> > New in v2
> >
> > ---
> >  drivers/core/regmap.c | 64 
> > +--
> >  include/regmap.h  | 58 ++
> >  2 files changed, 115 insertions(+), 7 deletions(-)
>
> When applying this series I get various errors. Can you please take a look?
>
> https://travis-ci.org/sglass68/u-boot/builds/440419659
>
It seems that some architectures that implement readq/writeq do not implement
{in,out}_{be,le}64. I'll add some "#if defined" checks to resolve this, but I
think I'll have a closer look at that later, since I think every platform that
implements readq/writeq should also implement the in/out 64-bit macros.

> Regards,
> Simon
>
Best regards,
Mario
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH] armv8: lx2160ardb : Add support for LX2160ARDB platform

2018-10-15 Thread Priyanka Jain
LX2160ARDB is an evaluation board that supports LX2160A
family SoCs. This patch add base support for this board.

Signed-off-by: Wasim Khan 
Signed-off-by: Yogesh Gaur 
Signed-off-by: Meenakshi Aggarwal 
Signed-off-by: Vabhav Sharma 
Signed-off-by: Sriram Dash 
Signed-off-by: Rajesh Bhagat 
Signed-off-by: Pankit Garg 
Signed-off-by: Priyanka Jain 
---
Depends on 
https://patchwork.ozlabs.org/project/uboot/list/?series=70506
TF-A Boot support for NXP Chassis 2 platforms
https://patchwork.ozlabs.org/patch/982274/
Add LX2160A SoC Support

 arch/arm/Kconfig |  14 ++
 arch/arm/cpu/armv8/Kconfig   |   2 +-
 arch/arm/dts/Makefile|   3 +-
 arch/arm/dts/fsl-lx2160a-rdb.dts |  20 +++
 board/freescale/common/qixis.c   |   4 +
 board/freescale/lx2160a/Kconfig  |  16 ++
 board/freescale/lx2160a/MAINTAINERS  |   8 +
 board/freescale/lx2160a/Makefile |   9 +
 board/freescale/lx2160a/README   |  79 +
 board/freescale/lx2160a/ddr.c|  20 +++
 board/freescale/lx2160a/eth_lx2160ardb.c | 210 +++
 board/freescale/lx2160a/lx2160a.c| 279 +++
 configs/lx2160ardb_tfa_defconfig |  74 
 include/configs/lx2160a_common.h | 214 
 include/configs/lx2160ardb.h | 102 +++
 15 files changed, 1052 insertions(+), 2 deletions(-)
 create mode 100644 arch/arm/dts/fsl-lx2160a-rdb.dts
 create mode 100644 board/freescale/lx2160a/Kconfig
 create mode 100644 board/freescale/lx2160a/MAINTAINERS
 create mode 100644 board/freescale/lx2160a/Makefile
 create mode 100644 board/freescale/lx2160a/README
 create mode 100644 board/freescale/lx2160a/ddr.c
 create mode 100644 board/freescale/lx2160a/eth_lx2160ardb.c
 create mode 100644 board/freescale/lx2160a/lx2160a.c
 create mode 100644 configs/lx2160ardb_tfa_defconfig
 create mode 100644 include/configs/lx2160a_common.h
 create mode 100644 include/configs/lx2160ardb.h

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 9f5eaf8..8ef72f5 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -1018,6 +1018,19 @@ config TARGET_LS2081ARDB
  development platform that supports the QorIQ LS2081A/LS2041A
  Layerscape Architecture processor.
 
+config TARGET_LX2160ARDB
+   bool "Support lx2160ardb"
+   select ARCH_LX2160A
+   select ARCH_MISC_INIT
+   select ARM64
+   select ARMV8_MULTIENTRY
+   select BOARD_LATE_INIT
+   help
+ Support for NXP LX2160ARDB platform.
+ The lx2160ardb (LX2160A Reference design board (RDB)
+ is a high-performance development platform that supports the
+ QorIQ LX2160A/LX2120A/LX2080A Layerscape Architecture processor.
+
 config TARGET_HIKEY
bool "Support HiKey 96boards Consumer Edition Platform"
select ARM64
@@ -1478,6 +1491,7 @@ source "board/freescale/ls1046ardb/Kconfig"
 source "board/freescale/ls1012aqds/Kconfig"
 source "board/freescale/ls1012ardb/Kconfig"
 source "board/freescale/ls1012afrdm/Kconfig"
+source "board/freescale/lx2160a/Kconfig"
 source "board/freescale/mx35pdk/Kconfig"
 source "board/freescale/s32v234evb/Kconfig"
 source "board/grinn/chiliboard/Kconfig"
diff --git a/arch/arm/cpu/armv8/Kconfig b/arch/arm/cpu/armv8/Kconfig
index c8bebab..aac3aeb 100644
--- a/arch/arm/cpu/armv8/Kconfig
+++ b/arch/arm/cpu/armv8/Kconfig
@@ -105,7 +105,7 @@ config PSCI_RESET
   !TARGET_LS1012AFRWY && \
   !TARGET_LS1043ARDB && !TARGET_LS1043AQDS && \
   !TARGET_LS1046ARDB && !TARGET_LS1046AQDS && \
-  !TARGET_LS2081ARDB && \
+  !TARGET_LS2081ARDB && !TARGET_LX2160ARDB && \
   !ARCH_UNIPHIER && !TARGET_S32V234EVB
help
  Most armv8 systems have PSCI support enabled in EL3, either through
diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index ebfa227..0c3c396 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -226,7 +226,8 @@ dtb-$(CONFIG_FSL_LSCH3) += fsl-ls2080a-qds.dtb \
fsl-ls2081a-rdb.dtb \
fsl-ls2088a-rdb-qspi.dtb \
fsl-ls1088a-rdb.dtb \
-   fsl-ls1088a-qds.dtb
+   fsl-ls1088a-qds.dtb \
+   fsl-lx2160a-rdb.dtb
 dtb-$(CONFIG_FSL_LSCH2) += fsl-ls1043a-qds-duart.dtb \
fsl-ls1043a-qds-lpuart.dtb \
fsl-ls1043a-rdb.dtb \
diff --git a/arch/arm/dts/fsl-lx2160a-rdb.dts b/arch/arm/dts/fsl-lx2160a-rdb.dts
new file mode 100644
index 000..08201b5
--- /dev/null
+++ b/arch/arm/dts/fsl-lx2160a-rdb.dts
@@ -0,0 +1,20 @@
+// SPDX-License-Identifier: GPL-2.0+ OR X11
+/*
+ * NXP LX2160ARDB device tree source
+ *
+ * Author: Priyanka Jain 
+ * Sriram Dash 
+ *
+ * Copyright 2018 NXP
+ *
+ */
+
+/dts-v1/;
+
+#include "fsl-lx2160a.dtsi"
+
+/ {
+   model = "NXP Layerscape LX2160ARDB Board";
+   compatible = "fsl,lx2160ardb", "fsl,lx2160a";
+
+};
diff --

[U-Boot] [PATCH v11 02/16] regmap: Fix documentation

2018-10-15 Thread Mario Six
The documentation in regmap.h is not in kernel-doc format. Correct this.

Reviewed-by: Anatolij Gustschin 
Reviewed-by: Simon Glass 
Signed-off-by: Mario Six 

---
v10 -> v11:
No changes

v9 -> v10:
No changes

v8 -> v9:
No changes

v7 -> v8:
No changes

v6 -> v7:
No changes

v5 -> v6:
No changes

v4 -> v5:
No changes

v3 -> v4:
No changes

v2 -> v3:
New in v3
---
 include/regmap.h | 48 +++-
 1 file changed, 39 insertions(+), 9 deletions(-)

diff --git a/include/regmap.h b/include/regmap.h
index 6a574eaa41..32f75e06f5 100644
--- a/include/regmap.h
+++ b/include/regmap.h
@@ -21,8 +21,8 @@ struct regmap_range {
 /**
  * struct regmap - a way of accessing hardware/bus registers
  *
- * @range_count: Number of ranges available within the map
- * @ranges:Array of ranges
+ * @range_count:   Number of ranges available within the map
+ * @ranges:Array of ranges
  */
 struct regmap {
int range_count;
@@ -33,7 +33,28 @@ struct regmap {
  * Interface to provide access to registers either through a direct memory
  * bus or through a peripheral bus like I2C, SPI.
  */
+
+/**
+ * regmap_write() - Write a 32-bit value to a regmap
+ *
+ * @map:   Regmap to write to
+ * @offset:Offset in the regmap to write to
+ * @val:   Data to write to the regmap at the specified offset
+ *
+ * Return: 0 if OK, -ve on error
+ */
 int regmap_write(struct regmap *map, uint offset, uint val);
+
+/**
+ * regmap_read() - Read a 32-bit value from a regmap
+ *
+ * @map:   Regmap to read from
+ * @offset:Offset in the regmap to read from
+ * @valp:  Pointer to the buffer to receive the data read from the regmap
+ * at the specified offset
+ *
+ * Return: 0 if OK, -ve on error
+ */
 int regmap_read(struct regmap *map, uint offset, uint *valp);

 #define regmap_write32(map, ptr, member, val) \
@@ -49,31 +70,36 @@ int regmap_read(struct regmap *map, uint offset, uint 
*valp);
  * @offset:Offset of the memory
  * @mask:  Mask to apply to the read value
  * @val:   Value to apply to the value to write
+ * Return: 0 if OK, -ve on error
  */
 int regmap_update_bits(struct regmap *map, uint offset, uint mask, uint val);

 /**
  * regmap_init_mem() - Set up a new register map that uses memory access
  *
- * Use regmap_uninit() to free it.
- *
  * @node:  Device node that uses this map
  * @mapp:  Returns allocated map
+ * Return: 0 if OK, -ve on error
+ *
+ * Use regmap_uninit() to free it.
  */
 int regmap_init_mem(ofnode node, struct regmap **mapp);

 /**
- * regmap_init_mem_platdata() - Set up a new memory register map for 
of-platdata
+ * regmap_init_mem_platdata() - Set up a new memory register map for
+ * of-platdata
+ *
+ * @dev:   Device that uses this map
+ * @reg:   List of address, size pairs
+ * @count: Number of pairs (e.g. 1 if the regmap has a single entry)
+ * @mapp:  Returns allocated map
+ * Return: 0 if OK, -ve on error
  *
  * This creates a new regmap with a list of regions passed in, rather than
  * using the device tree. It only supports 32-bit machines.
  *
  * Use regmap_uninit() to free it.
  *
- * @dev:   Device that uses this map
- * @reg:   List of address, size pairs
- * @count: Number of pairs (e.g. 1 if the regmap has a single entry)
- * @mapp:  Returns allocated map
  */
 int regmap_init_mem_platdata(struct udevice *dev, fdt_val_t *reg, int count,
 struct regmap **mapp);
@@ -83,11 +109,15 @@ int regmap_init_mem_platdata(struct udevice *dev, 
fdt_val_t *reg, int count,
  *
  * @map:   Regmap to query
  * @range_num: Range to look up
+ * Return: Pointer to the range in question if OK, NULL on error
  */
 void *regmap_get_range(struct regmap *map, unsigned int range_num);

 /**
  * regmap_uninit() - free a previously inited regmap
+ *
+ * @map:   Regmap to free
+ * Return: 0 if OK, -ve on error
  */
 int regmap_uninit(struct regmap *map);

--
2.18.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v11 15/16] misc: Add gdsys_soc driver

2018-10-15 Thread Mario Six
This patch adds a driver for the bus associated with a IHS FPGA.

Reviewed-by: Simon Glass 
Signed-off-by: Mario Six 

---
v10 -> v11:
No changes

v9 -> v10:
No changes

v8 -> v9:
No changes

v7 -> v8:
No changes

v6 -> v7:
No changes

v5 -> v6:
No changes

v4 -> v5:
No changes

v3 -> v4:
No changes

v2 -> v3:
* Fixed style violations
* Added bindings file
* Added more debug output in case of errors
* Switched all printfs to debug
* Documented the private data structure
* Formatted documentation as proper kernel-doc
* Expanded Kconfig description

v1 -> v2:
* Switched to correct uclass for IHS FPGA driver (now in MISC uclass)
---
 .../devicetree/bindings/misc/gdsys,soc.txt| 16 
 drivers/misc/Kconfig  |  8 ++
 drivers/misc/Makefile |  1 +
 drivers/misc/gdsys_soc.c  | 74 +++
 drivers/misc/gdsys_soc.h  | 23 ++
 5 files changed, 122 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/misc/gdsys,soc.txt
 create mode 100644 drivers/misc/gdsys_soc.c
 create mode 100644 drivers/misc/gdsys_soc.h

diff --git a/Documentation/devicetree/bindings/misc/gdsys,soc.txt 
b/Documentation/devicetree/bindings/misc/gdsys,soc.txt
new file mode 100644
index 00..278e935b16
--- /dev/null
+++ b/Documentation/devicetree/bindings/misc/gdsys,soc.txt
@@ -0,0 +1,16 @@
+gdsys soc bus driver
+
+This driver provides a simple interface for the busses associated with gdsys
+IHS FPGAs. The bus itself contains devices whose register maps are contained
+within the FPGA's register space.
+
+Required properties:
+- fpga: A phandle to the controlling IHS FPGA
+
+Example:
+
+FPGA0BUS: fpga0bus {
+   compatible = "gdsys,soc";
+   ranges = <0x0 0xe060 0x4000>;
+   fpga = <&FPGA0>;
+};
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index c5697011f2..d589f32a55 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -312,4 +312,12 @@ config FS_LOADER
  The consumer driver would then use this loader to program whatever,
  ie. the FPGA device.

+config GDSYS_SOC
+   bool "Enable gdsys SOC driver"
+   depends on MISC
+   help
+ Support for gdsys IHS SOC, a simple bus associated with each gdsys
+ IHS (Integrated Hardware Systems) FPGA, which holds all devices whose
+ register maps are contained within the FPGA's register map.
+
 endmenu
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index aa5410ea15..ed5d7bb0c0 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -34,6 +34,7 @@ obj-$(CONFIG_FSL_SEC_MON) += fsl_sec_mon.o
 obj-$(CONFIG_FS_LOADER) += fs_loader.o
 obj-$(CONFIG_GDSYS_IOEP) += gdsys_ioep.o
 obj-$(CONFIG_GDSYS_RXAUI_CTRL) += gdsys_rxaui_ctrl.o
+obj-$(CONFIG_GDSYS_SOC) += gdsys_soc.o
 obj-$(CONFIG_$(SPL_)I2C_EEPROM) += i2c_eeprom.o
 obj-$(CONFIG_LED_STATUS) += status_led.o
 obj-$(CONFIG_LED_STATUS_GPIO) += gpio_led.o
diff --git a/drivers/misc/gdsys_soc.c b/drivers/misc/gdsys_soc.c
new file mode 100644
index 00..94a21e08af
--- /dev/null
+++ b/drivers/misc/gdsys_soc.c
@@ -0,0 +1,74 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2017
+ * Mario Six,  Guntermann & Drunck GmbH, mario@gdsys.cc
+ */
+
+#include 
+#include 
+#include 
+
+#include "gdsys_soc.h"
+
+/**
+ * struct gdsys_soc_priv - Private data for gdsys soc bus
+ * @fpga: The gdsys IHS FPGA this bus is associated with
+ */
+struct gdsys_soc_priv {
+   struct udevice *fpga;
+};
+
+static const struct udevice_id gdsys_soc_ids[] = {
+   { .compatible = "gdsys,soc" },
+   { /* sentinel */ }
+};
+
+int gdsys_soc_get_fpga(struct udevice *child, struct udevice **fpga)
+{
+   struct gdsys_soc_priv *bus_priv;
+
+   if (!child->parent) {
+   debug("%s: Invalid parent\n", child->name);
+   return -EINVAL;
+   }
+
+   if (!device_is_compatible(child->parent, "gdsys,soc")) {
+   debug("%s: Not child of a gdsys soc\n", child->name);
+   return -EINVAL;
+   }
+
+   bus_priv = dev_get_priv(child->parent);
+
+   *fpga = bus_priv->fpga;
+
+   return 0;
+}
+
+static int gdsys_soc_probe(struct udevice *dev)
+{
+   struct gdsys_soc_priv *priv = dev_get_priv(dev);
+   struct udevice *fpga;
+   int res = uclass_get_device_by_phandle(UCLASS_MISC, dev, "fpga",
+  &fpga);
+   if (res == -ENOENT) {
+   debug("%s: Could not find 'fpga' phandle\n", dev->name);
+   return -EINVAL;
+   }
+
+   if (res == -ENODEV) {
+   debug("%s: Could not get FPGA device\n", dev->name);
+   return -EINVAL;
+   }
+
+   priv->fpga = fpga;
+
+   return 0;
+}
+
+U_BOOT_DRIVER(gdsys_soc_bus) = {
+   .name   = "gdsys_soc_bus",
+   .id = UCLASS_SIMPLE_BUS,
+   .of_match   = gdsys_soc_ids,
+   .probe  = gds

[U-Boot] [PATCH v11 03/16] regmap: Add documentation

2018-10-15 Thread Mario Six
Document the regmap_alloc() function.

Reviewed-by: Anatolij Gustschin 
Reviewed-by: Simon Glass 
Signed-off-by: Mario Six 

---
v10 -> v11:
No changes

v9 -> v10:
No changes

v8 -> v9:
No changes

v7 -> v8:
No changes

v6 -> v7:
No changes

v5 -> v6:
No changes

v4 -> v5:
No changes

v3 -> v4:
No changes

v2 -> v3:
New in v3
---
 drivers/core/regmap.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/core/regmap.c b/drivers/core/regmap.c
index 8e5c3bcf61..77f6f520a0 100644
--- a/drivers/core/regmap.c
+++ b/drivers/core/regmap.c
@@ -17,6 +17,12 @@

 DECLARE_GLOBAL_DATA_PTR;

+/**
+ * regmap_alloc() - Allocate a regmap with a given number of ranges.
+ *
+ * @count: Number of ranges to be allocated for the regmap.
+ * Return: A pointer to the newly allocated regmap, or NULL on error.
+ */
 static struct regmap *regmap_alloc(int count)
 {
struct regmap *map;
--
2.18.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v11 04/16] regmap: Improve error handling

2018-10-15 Thread Mario Six
ofnode_read_simple_addr_cells may fail and return a negative error code.
Check for this when initializing regmaps.

Also check if both_len is zero, since this is perfectly possible, and
would lead to a division-by-zero further down the line.

Reviewed-by: Anatolij Gustschin 
Reviewed-by: Simon Glass 
Signed-off-by: Mario Six 

---
v10 -> v11:
No changes

v9 -> v10:
No changes

v8 -> v9:
No changes

v7 -> v8:
No changes

v6 -> v7:
No changes

v5 -> v6:
No changes

v4 -> v5:
No changes

v3 -> v4:
No changes

v2 -> v3:
New in v3
---
 drivers/core/regmap.c | 17 +
 1 file changed, 17 insertions(+)

diff --git a/drivers/core/regmap.c b/drivers/core/regmap.c
index 77f6f520a0..4ebab23349 100644
--- a/drivers/core/regmap.c
+++ b/drivers/core/regmap.c
@@ -67,8 +67,25 @@ int regmap_init_mem(ofnode node, struct regmap **mapp)
struct resource r;

addr_len = ofnode_read_simple_addr_cells(ofnode_get_parent(node));
+   if (addr_len < 0) {
+   debug("%s: Error while reading the addr length (ret = %d)\n",
+ ofnode_get_name(node), addr_len);
+   return addr_len;
+   }
+
size_len = ofnode_read_simple_size_cells(ofnode_get_parent(node));
+   if (size_len < 0) {
+   debug("%s: Error while reading the size length: (ret = %d)\n",
+ ofnode_get_name(node), size_len);
+   return size_len;
+   }
+
both_len = addr_len + size_len;
+   if (!both_len) {
+   debug("%s: Both addr and size length are zero\n",
+ ofnode_get_name(node));
+   return -EINVAL;
+   }

len = ofnode_read_size(node, "reg");
if (len < 0)
--
2.18.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v11 01/16] test: regmap: Increase size of syscon0 memory

2018-10-15 Thread Mario Six
The upcoming changes to the regmap interface will contain a proper check
for plausibility when reading/writing from/to a register map. To still
have the current tests pass, increase the size of the memory region for
the syscon0 device, since one of the tests reads and writes beyond this
range.

Reviewed-by: Anatolij Gustschin 
Reviewed-by: Simon Glass 
Signed-off-by: Mario Six 

---
v10 -> v11:
No changes

v9 -> v10:
No changes

v8 -> v9:
No changes

v7 -> v8:
No changes

v6 -> v7:
No changes

v5 -> v6:
* Fix the test that checks the changed size

v4 -> v5:
No changes

v3 -> v4:
No changes

v2 -> v3:
New in v3
---
 arch/sandbox/dts/test.dts | 2 +-
 test/dm/regmap.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index 420b72f4db..cc3b2e7c2a 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -521,7 +521,7 @@

syscon@0 {
compatible = "sandbox,syscon0";
-   reg = <0x10 4>;
+   reg = <0x10 16>;
};

syscon@1 {
diff --git a/test/dm/regmap.c b/test/dm/regmap.c
index d4b86b3b03..b28d6a6cd1 100644
--- a/test/dm/regmap.c
+++ b/test/dm/regmap.c
@@ -25,7 +25,7 @@ static int dm_test_regmap_base(struct unit_test_state *uts)
ut_assertok_ptr(map);
ut_asserteq(1, map->range_count);
ut_asserteq(0x10, map->ranges[0].start);
-   ut_asserteq(4, map->ranges[0].size);
+   ut_asserteq(16, map->ranges[0].size);
ut_asserteq(0x10, map_to_sysmem(regmap_get_range(map, 0)));

ut_assertok(uclass_get_device(UCLASS_SYSCON, 1, &dev));
--
2.18.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v11 13/16] regmap: Add overview documentation

2018-10-15 Thread Mario Six
Add some overview documentation that explains the purpose and some of
the features and limitations of the regmap interface.

Reviewed-by: Bin Meng 
Signed-off-by: Mario Six 

---
v10 -> v11:
No changes

v9 -> v10:
No changes

v8 -> v9:
* Amended for inclusion of endianness setting via DT

v7 -> v8:
New in v8
---
 include/regmap.h | 27 +++
 1 file changed, 27 insertions(+)

diff --git a/include/regmap.h b/include/regmap.h
index 98860c2732..b2b733fda6 100644
--- a/include/regmap.h
+++ b/include/regmap.h
@@ -7,6 +7,33 @@
 #ifndef __REGMAP_H
 #define __REGMAP_H

+/**
+ * DOC: Overview
+ *
+ * Regmaps are an abstraction mechanism that allows device drivers to access
+ * register maps irrespective of the underlying bus architecture. This entails
+ * that for devices that support multiple busses (e.g. I2C and SPI for a GPIO
+ * expander chip) only one driver has to be written. This driver will
+ * instantiate a regmap with a backend depending on the bus the device is
+ * attached to, and use the regmap API to access the register map through that
+ * bus transparently.
+ *
+ * Read and write functions are supplied, which can read/write data of
+ * arbitrary length from/to the regmap.
+ *
+ * The endianness of regmap accesses is selectable for each map through device
+ * tree settings via the boolean "little-endian", "big-endian", and
+ * "native-endian" properties.
+ *
+ * Furthermore, the register map described by a regmap can be split into
+ * multiple disjoint areas called ranges. In this way, register maps with
+ * "holes", i.e. areas of addressable memory that are not part of the register
+ * map, can be accessed in a concise manner.
+ *
+ * Currently, only a bare "mem" backend for regmaps is supported, which
+ * accesses the register map as regular IO-mapped memory.
+ */
+
 /**
  * enum regmap_size_t - Access sizes for regmap reads and writes
  *
--
2.18.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v11 08/16] regmap: Add raw read/write functions

2018-10-15 Thread Mario Six
The regmap functions currently assume that all register map accesses
have a data width of 32 bits, but there are maps that have different
widths.

To rectify this, implement the regmap_raw_read and regmap_raw_write
functions from the Linux kernel API that specify the width of a desired
read or write operation on a regmap.

Implement the regmap_read and regmap_write functions using these raw
functions in a backwards-compatible manner.

Reviewed-by: Anatolij Gustschin 
Signed-off-by: Mario Six 

---
v10 -> v11:
No changes

v9 -> v10:
* Switched to the read{b,w,l,q} and write{b,w,l,q} functions for
  register map access

v8 -> v9:
* Removed forgotten "fpgamap" in documentation

v7 -> v8:
No changes

v6 -> v7:
* Fixed wrong variable type in 64-bit read (u32 -> u64)
* Added 64-bit case in write function

v5 -> v6:
* Corrected format specifier
* Added support for 64-bit reads/writes

v4 -> v5:
No changes

v3 -> v4:
* Switched 'ranges[0] + offset' to 'ranges[0].start + offset'
* Explained the difference between the raw and non-raw read/write
  functions better in the docs

v2 -> v3:
* Implement the "raw" functions from Linux instead of adding a size
  parameter to the regmap_{read,write} functions
* Fixed style violation
* Improved error handling

v1 -> v2:
New in v2
---
 drivers/core/regmap.c | 64 ++-
 include/regmap.h  | 58 +++
 2 files changed, 115 insertions(+), 7 deletions(-)

diff --git a/drivers/core/regmap.c b/drivers/core/regmap.c
index 154426269d..916d9272ea 100644
--- a/drivers/core/regmap.c
+++ b/drivers/core/regmap.c
@@ -188,22 +188,72 @@ int regmap_uninit(struct regmap *map)
return 0;
 }

+int regmap_raw_read(struct regmap *map, uint offset, void *valp, size_t 
val_len)
+{
+   void *ptr;
+
+   ptr = map_physmem(map->ranges[0].start + offset, val_len, MAP_NOCACHE);
+
+   switch (val_len) {
+   case REGMAP_SIZE_8:
+   *((u8 *)valp) = readb((u8 *)ptr);
+   break;
+   case REGMAP_SIZE_16:
+   *((u16 *)valp) = readw((u16 *)ptr);
+   break;
+   case REGMAP_SIZE_32:
+   *((u32 *)valp) = readl((u32 *)ptr);
+   break;
+#if defined(readq)
+   case REGMAP_SIZE_64:
+   *((u64 *)valp) = readq((u64 *)ptr);
+   break;
+#endif
+   default:
+   debug("%s: regmap size %zu unknown\n", __func__, val_len);
+   return -EINVAL;
+   }
+   return 0;
+}
+
 int regmap_read(struct regmap *map, uint offset, uint *valp)
 {
-   u32 *ptr = map_physmem(map->ranges[0].start + offset, 4, MAP_NOCACHE);
+   return regmap_raw_read(map, offset, valp, REGMAP_SIZE_32);
+}

-   *valp = le32_to_cpu(readl(ptr));
+int regmap_raw_write(struct regmap *map, uint offset, const void *val,
+size_t val_len)
+{
+   void *ptr;
+
+   ptr = map_physmem(map->ranges[0].start + offset, val_len, MAP_NOCACHE);
+
+   switch (val_len) {
+   case REGMAP_SIZE_8:
+   writeb(*((u8 *)val), (u8 *)ptr);
+   break;
+   case REGMAP_SIZE_16:
+   writew(*((u16 *)val), (u16 *)ptr);
+   break;
+   case REGMAP_SIZE_32:
+   writel(*((u32 *)val), (u32 *)ptr);
+   break;
+#if defined(writeq)
+   case REGMAP_SIZE_64:
+   writeq(*((u64 *)val), (u64 *)ptr);
+   break;
+#endif
+   default:
+   debug("%s: regmap size %zu unknown\n", __func__, val_len);
+   return -EINVAL;
+   }

return 0;
 }

 int regmap_write(struct regmap *map, uint offset, uint val)
 {
-   u32 *ptr = map_physmem(map->ranges[0].start + offset, 4, MAP_NOCACHE);
-
-   writel(cpu_to_le32(val), ptr);
-
-   return 0;
+   return regmap_raw_write(map, offset, &val, REGMAP_SIZE_32);
 }

 int regmap_update_bits(struct regmap *map, uint offset, uint mask, uint val)
diff --git a/include/regmap.h b/include/regmap.h
index 32f75e06f5..f23664e8ba 100644
--- a/include/regmap.h
+++ b/include/regmap.h
@@ -7,6 +7,21 @@
 #ifndef __REGMAP_H
 #define __REGMAP_H

+/**
+ * enum regmap_size_t - Access sizes for regmap reads and writes
+ *
+ * @REGMAP_SIZE_8: 8-bit read/write access size
+ * @REGMAP_SIZE_16: 16-bit read/write access size
+ * @REGMAP_SIZE_32: 32-bit read/write access size
+ * @REGMAP_SIZE_64: 64-bit read/write access size
+ */
+enum regmap_size_t {
+   REGMAP_SIZE_8 = 1,
+   REGMAP_SIZE_16 = 2,
+   REGMAP_SIZE_32 = 4,
+   REGMAP_SIZE_64 = 8,
+};
+
 /**
  * struct regmap_range - a register map range
  *
@@ -41,6 +56,10 @@ struct regmap {
  * @offset:Offset in the regmap to write to
  * @val:   Data to write to the regmap at the specified offset
  *
+ * Note that this function will only write values of 32 bit width to the
+ * regmap; if the size of data to be read is different, the regmap_raw_write
+ * function can be used.
+ *
  * Return: 0 if OK, -v

[U-Boot] [PATCH v11 10/16] regmap: Define regmap_{get,set}

2018-10-15 Thread Mario Six
It would be convenient if one could use the regmap API in conjunction
with register maps defined as structs (i.e. structs that directly mirror
the memory layout of the registers in question). A similar approach was
planned with the regmap_write32/regmap_read32 macros, but was never
used.

Hence, implement regmap_set/regmap_range_set and
regmap_get/regmap_range_get macros, which, given a register map, a
struct describing the layout of the register map, and a member name
automatically produce regmap_read/regmap_write calls that access the
specified member in the register map.

Reviewed-by: Anatolij Gustschin 
Reviewed-by: Simon Glass 
Signed-off-by: Mario Six 

---
v10 -> v11:
No changes

v9 -> v10:
No changes

v8 -> v9:
No changes

v7 -> v8:
No changes

v6 -> v7:
No changes

v5 -> v6:
No changes

v4 -> v5:
No changes

v3 -> v4:
No changes

v2 -> v3:
* Fixed style violations
* Added documentation

v1 -> v2:
New in v2
---
 include/regmap.h | 54 
 1 file changed, 50 insertions(+), 4 deletions(-)

diff --git a/include/regmap.h b/include/regmap.h
index eba300da29..3b7eea5f49 100644
--- a/include/regmap.h
+++ b/include/regmap.h
@@ -146,11 +146,57 @@ int regmap_raw_write_range(struct regmap *map, uint 
range_num, uint offset,
 int regmap_raw_read_range(struct regmap *map, uint range_num, uint offset,
  void *valp, size_t val_len);

-#define regmap_write32(map, ptr, member, val) \
-   regmap_write(map, (uint32_t *)(ptr)->member - (uint32_t *)(ptr), val)
+/**
+ * regmap_range_set() - Set a value in a regmap range described by a struct
+ * @map:Regmap in which a value should be set
+ * @range:  Range of the regmap in which a value should be set
+ * @type:   Structure type that describes the memory layout of the regmap range
+ * @member: Member of the describing structure that should be set in the regmap
+ *  range
+ * @val:Value which should be written to the regmap range
+ */
+#define regmap_range_set(map, range, type, member, val) \
+   do { \
+   typeof(((type *)0)->member) __tmp = val; \
+   regmap_raw_write_range(map, range, offsetof(type, member), \
+  &__tmp, sizeof(((type *)0)->member)); \
+   } while (0)
+
+/**
+ * regmap_set() - Set a value in a regmap described by a struct
+ * @map:Regmap in which a value should be set
+ * @type:   Structure type that describes the memory layout of the regmap
+ * @member: Member of the describing structure that should be set in the regmap
+ * @val:Value which should be written to the regmap
+ */
+#define regmap_set(map, type, member, val) \
+   regmap_range_set(map, 0, type, member, val)

-#define regmap_read32(map, ptr, member, valp) \
-   regmap_read(map, (uint32_t *)(ptr)->member - (uint32_t *)(ptr), valp)
+/**
+ * regmap_range_get() - Get a value from a regmap range described by a struct
+ * @map:Regmap from which a value should be read
+ * @range:  Range of the regmap from which a value should be read
+ * @type:   Structure type that describes the memory layout of the regmap
+ *  range
+ * @member: Member of the describing structure that should be read in the
+ *  regmap range
+ * @valp:   Variable that receives the value read from the regmap range
+ */
+#define regmap_range_get(map, range, type, member, valp) \
+   regmap_raw_read_range(map, range, offsetof(type, member), \
+ (void *)valp, sizeof(((type *)0)->member))
+
+/**
+ * regmap_get() - Get a value from a regmap described by a struct
+ * @map:Regmap from which a value should be read
+ * @type:   Structure type that describes the memory layout of the regmap
+ *  range
+ * @member: Member of the describing structure that should be read in the
+ *  regmap
+ * @valp:   Variable that receives the value read from the regmap
+ */
+#define regmap_get(map, type, member, valp) \
+   regmap_range_get(map, 0, type, member, valp)

 /**
  * regmap_update_bits() - Perform a read/modify/write using a mask
--
2.18.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v11 09/16] regmap: Support reading from specific range

2018-10-15 Thread Mario Six
It is useful to be able to treat the different ranges of a regmap
separately to be able to use distinct offset for them, but this is
currently not implemented in the regmap API.

To preserve backwards compatibility, add regmap_read_range and
regmap_write_range functions that take an additional parameter
'range_num' that identifies the range to operate on.

Reviewed-by: Anatolij Gustschin 
Reviewed-by: Simon Glass 
Signed-off-by: Mario Six 

---
v10 -> v11:
No changes

v9 -> v10:
No changes

v8 -> v9:
No changes

v7 -> v8:
No changes

v6 -> v7:
No changes

v5 -> v6:
No changes

v4 -> v5:
No changes

v3 -> v4:
No changes

v2 -> v3:
* Renamed the functions to regmap_{write,read}_range
* Added function comments
* Fixed style violations
* Improved error handling

v1 -> v2:
New in v2
---
 drivers/core/regmap.c | 49 ++-
 include/regmap.h  | 31 +++
 2 files changed, 75 insertions(+), 5 deletions(-)

diff --git a/drivers/core/regmap.c b/drivers/core/regmap.c
index 916d9272ea..9b2e02af2e 100644
--- a/drivers/core/regmap.c
+++ b/drivers/core/regmap.c
@@ -188,11 +188,25 @@ int regmap_uninit(struct regmap *map)
return 0;
 }

-int regmap_raw_read(struct regmap *map, uint offset, void *valp, size_t 
val_len)
+int regmap_raw_read_range(struct regmap *map, uint range_num, uint offset,
+ void *valp, size_t val_len)
 {
+   struct regmap_range *range;
void *ptr;

-   ptr = map_physmem(map->ranges[0].start + offset, val_len, MAP_NOCACHE);
+   if (range_num >= map->range_count) {
+   debug("%s: range index %d larger than range count\n",
+ __func__, range_num);
+   return -ERANGE;
+   }
+   range = &map->ranges[range_num];
+
+   ptr = map_physmem(range->start + offset, val_len, MAP_NOCACHE);
+
+   if (offset + val_len > range->size) {
+   debug("%s: offset/size combination invalid\n", __func__);
+   return -ERANGE;
+   }

switch (val_len) {
case REGMAP_SIZE_8:
@@ -213,20 +227,39 @@ int regmap_raw_read(struct regmap *map, uint offset, void 
*valp, size_t val_len)
debug("%s: regmap size %zu unknown\n", __func__, val_len);
return -EINVAL;
}
+
return 0;
 }

+int regmap_raw_read(struct regmap *map, uint offset, void *valp, size_t 
val_len)
+{
+   return regmap_raw_read_range(map, 0, offset, valp, val_len);
+}
+
 int regmap_read(struct regmap *map, uint offset, uint *valp)
 {
return regmap_raw_read(map, offset, valp, REGMAP_SIZE_32);
 }

-int regmap_raw_write(struct regmap *map, uint offset, const void *val,
-size_t val_len)
+int regmap_raw_write_range(struct regmap *map, uint range_num, uint offset,
+  const void *val, size_t val_len)
 {
+   struct regmap_range *range;
void *ptr;

-   ptr = map_physmem(map->ranges[0].start + offset, val_len, MAP_NOCACHE);
+   if (range_num >= map->range_count) {
+   debug("%s: range index %d larger than range count\n",
+ __func__, range_num);
+   return -ERANGE;
+   }
+   range = &map->ranges[range_num];
+
+   ptr = map_physmem(range->start + offset, val_len, MAP_NOCACHE);
+
+   if (offset + val_len > range->size) {
+   debug("%s: offset/size combination invalid\n", __func__);
+   return -ERANGE;
+   }

switch (val_len) {
case REGMAP_SIZE_8:
@@ -251,6 +284,12 @@ int regmap_raw_write(struct regmap *map, uint offset, 
const void *val,
return 0;
 }

+int regmap_raw_write(struct regmap *map, uint offset, const void *val,
+size_t val_len)
+{
+   return regmap_raw_write_range(map, 0, offset, val, val_len);
+}
+
 int regmap_write(struct regmap *map, uint offset, uint val)
 {
return regmap_raw_write(map, offset, &val, REGMAP_SIZE_32);
diff --git a/include/regmap.h b/include/regmap.h
index f23664e8ba..eba300da29 100644
--- a/include/regmap.h
+++ b/include/regmap.h
@@ -115,6 +115,37 @@ int regmap_raw_write(struct regmap *map, uint offset, 
const void *val,
 int regmap_raw_read(struct regmap *map, uint offset, void *valp,
size_t val_len);

+/**
+ * regmap_raw_write_range() - Write a value of specified length to a range of a
+ *   regmap
+ *
+ * @map:   Regmap to write to
+ * @range_num: Number of the range in the regmap to write to
+ * @offset:Offset in the regmap to write to
+ * @val:   Value to write to the regmap at the specified offset
+ * @val_len:   Length of the data to be written to the regmap
+ *
+ * Return: 0 if OK, -ve on error
+ */
+int regmap_raw_write_range(struct regmap *map, uint range_num, uint offset,
+  const void *val, size_t val_len);
+
+/**
+ * regmap_raw_read_range() - Read a value of specified length from a range of a
+ * 

[U-Boot] [PATCH v11 12/16] regmap: Add endianness support

2018-10-15 Thread Mario Six
Add support for switching the endianness of regmap accesses via the
"little-endian", "big-endian", and "native-endian" boolean properties in
the device tree.

The default endianness is native endianness.

Signed-off-by: Mario Six 
Reviewed-by: Simon Glass 
Reviewed-by: Daniel Schwierzeck 

---
v10 -> v11:
* Added more #ifdef tests for 64-bit case to resolve compilation issues

v9 -> v10:
* Switched to readb/writeb for 8-bit reads/writes

v8 -> v9:
New in v9
---
 drivers/core/regmap.c | 134 ++
 include/regmap.h  |  14 +
 2 files changed, 138 insertions(+), 10 deletions(-)

diff --git a/drivers/core/regmap.c b/drivers/core/regmap.c
index 9b2e02af2e..5ef0f71c8b 100644
--- a/drivers/core/regmap.c
+++ b/drivers/core/regmap.c
@@ -164,6 +164,15 @@ int regmap_init_mem(ofnode node, struct regmap **mapp)
return ret;
}

+   if (ofnode_read_bool(node, "little-endian"))
+   map->endianness = REGMAP_LITTLE_ENDIAN;
+   else if (ofnode_read_bool(node, "big-endian"))
+   map->endianness = REGMAP_BIG_ENDIAN;
+   else if (ofnode_read_bool(node, "native-endian"))
+   map->endianness = REGMAP_NATIVE_ENDIAN;
+   else /* Default: native endianness */
+   map->endianness = REGMAP_NATIVE_ENDIAN;
+
*mapp = map;

return 0;
@@ -188,6 +197,55 @@ int regmap_uninit(struct regmap *map)
return 0;
 }

+static inline u8 __read_8(u8 *addr, enum regmap_endianness_t endianness)
+{
+   return readb(addr);
+}
+
+static inline u16 __read_16(u16 *addr, enum regmap_endianness_t endianness)
+{
+   switch (endianness) {
+   case REGMAP_LITTLE_ENDIAN:
+   return in_le16(addr);
+   case REGMAP_BIG_ENDIAN:
+   return in_be16(addr);
+   case REGMAP_NATIVE_ENDIAN:
+   return readw(addr);
+   }
+
+   return readw(addr);
+}
+
+static inline u32 __read_32(u32 *addr, enum regmap_endianness_t endianness)
+{
+   switch (endianness) {
+   case REGMAP_LITTLE_ENDIAN:
+   return in_le32(addr);
+   case REGMAP_BIG_ENDIAN:
+   return in_be32(addr);
+   case REGMAP_NATIVE_ENDIAN:
+   return readl(addr);
+   }
+
+   return readl(addr);
+}
+
+#if defined(in_le64) && defined(in_be64) && defined(readq)
+static inline u64 __read_64(u64 *addr, enum regmap_endianness_t endianness)
+{
+   switch (endianness) {
+   case REGMAP_LITTLE_ENDIAN:
+   return in_le64(addr);
+   case REGMAP_BIG_ENDIAN:
+   return in_be64(addr);
+   case REGMAP_NATIVE_ENDIAN:
+   return readq(addr);
+   }
+
+   return readq(addr);
+}
+#endif
+
 int regmap_raw_read_range(struct regmap *map, uint range_num, uint offset,
  void *valp, size_t val_len)
 {
@@ -210,17 +268,17 @@ int regmap_raw_read_range(struct regmap *map, uint 
range_num, uint offset,

switch (val_len) {
case REGMAP_SIZE_8:
-   *((u8 *)valp) = readb((u8 *)ptr);
+   *((u8 *)valp) = __read_8(ptr, map->endianness);
break;
case REGMAP_SIZE_16:
-   *((u16 *)valp) = readw((u16 *)ptr);
+   *((u16 *)valp) = __read_16(ptr, map->endianness);
break;
case REGMAP_SIZE_32:
-   *((u32 *)valp) = readl((u32 *)ptr);
+   *((u32 *)valp) = __read_32(ptr, map->endianness);
break;
-#if defined(readq)
+#if defined(in_le64) && defined(in_be64) && defined(readq)
case REGMAP_SIZE_64:
-   *((u64 *)valp) = readq((u64 *)ptr);
+   *((u64 *)valp) = __read_64(ptr, map->endianness);
break;
 #endif
default:
@@ -241,6 +299,62 @@ int regmap_read(struct regmap *map, uint offset, uint 
*valp)
return regmap_raw_read(map, offset, valp, REGMAP_SIZE_32);
 }

+static inline void __write_8(u8 *addr, const u8 *val,
+enum regmap_endianness_t endianness)
+{
+   writeb(*val, addr);
+}
+
+static inline void __write_16(u16 *addr, const u16 *val,
+ enum regmap_endianness_t endianness)
+{
+   switch (endianness) {
+   case REGMAP_NATIVE_ENDIAN:
+   writew(*val, addr);
+   break;
+   case REGMAP_LITTLE_ENDIAN:
+   out_le16(addr, *val);
+   break;
+   case REGMAP_BIG_ENDIAN:
+   out_be16(addr, *val);
+   break;
+   }
+}
+
+static inline void __write_32(u32 *addr, const u32 *val,
+ enum regmap_endianness_t endianness)
+{
+   switch (endianness) {
+   case REGMAP_NATIVE_ENDIAN:
+   writel(*val, addr);
+   break;
+   case REGMAP_LITTLE_ENDIAN:
+   out_le32(addr, *val);
+   break;
+   case REGMAP_BIG_ENDIAN:
+   out_be32(addr, *val);
+   break;
+   }

[U-Boot] [PATCH v11 06/16] regmap: Add error output

2018-10-15 Thread Mario Six
Add some debug output in cases where the initialization of a regmap
fails.

Reviewed-by: Anatolij Gustschin 
Reviewed-by: Simon Glass 
Signed-off-by: Mario Six 

---
v10 -> v11:
No changes

v9 -> v10:
No changes

v8 -> v9:
No changes

v7 -> v8:
No changes

v6 -> v7:
No changes

v5 -> v6:
No changes

v4 -> v5:
No changes

v3 -> v4:
No changes

v2 -> v3:
New in v3
---
 drivers/core/regmap.c | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/core/regmap.c b/drivers/core/regmap.c
index 25c1ae5d7d..154426269d 100644
--- a/drivers/core/regmap.c
+++ b/drivers/core/regmap.c
@@ -139,12 +139,18 @@ int regmap_init_mem(ofnode node, struct regmap **mapp)
}

len = ofnode_read_size(node, "reg");
-   if (len < 0)
+   if (len < 0) {
+   debug("%s: Error while reading reg size (ret = %d)\n",
+ ofnode_get_name(node), len);
return len;
+   }
len /= sizeof(fdt32_t);
count = len / both_len;
-   if (!count)
+   if (!count) {
+   debug("%s: Not enough data in reg property\n",
+ ofnode_get_name(node));
return -EINVAL;
+   }

map = regmap_alloc(count);
if (!map)
--
2.18.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v11 05/16] regmap: Introduce init_range

2018-10-15 Thread Mario Six
Both fdtdec_get_addr_size_fixed and of_address_to_resource can fail with
an error, which is not currently checked during regmap initialization.

Since the indentation depth is already quite deep, extract a new
'init_range' method to do the initialization.

Reviewed-by: Anatolij Gustschin 
Reviewed-by: Simon Glass 
Signed-off-by: Mario Six 

---
v10 -> v11:
No changes

v9 -> v10:
No changes

v8 -> v9:
No changes

v7 -> v8:
No changes

v6 -> v7:
No changes

v5 -> v6:
No changes

v4 -> v5:
No changes

v3 -> v4:
* Introduced else clause in of_live_active() if statement to make the
  distinction between live and non-live cases clearer

v2 -> v3:
New in v3
---
 drivers/core/regmap.c | 68 +++
 1 file changed, 56 insertions(+), 12 deletions(-)

diff --git a/drivers/core/regmap.c b/drivers/core/regmap.c
index 4ebab23349..25c1ae5d7d 100644
--- a/drivers/core/regmap.c
+++ b/drivers/core/regmap.c
@@ -56,6 +56,58 @@ int regmap_init_mem_platdata(struct udevice *dev, fdt_val_t 
*reg, int count,
return 0;
 }
 #else
+/**
+ * init_range() - Initialize a single range of a regmap
+ * @node: Device node that will use the map in question
+ * @range:Pointer to a regmap_range structure that will be initialized
+ * @addr_len: The length of the addr parts of the reg property
+ * @size_len: The length of the size parts of the reg property
+ * @index:The index of the range to initialize
+ *
+ * This function will read the necessary 'reg' information from the device tree
+ * (the 'addr' part, and the 'length' part), and initialize the range in
+ * quesion.
+ *
+ * Return: 0 if OK, -ve on error
+ */
+static int init_range(ofnode node, struct regmap_range *range, int addr_len,
+ int size_len, int index)
+{
+   fdt_size_t sz;
+   struct resource r;
+
+   if (of_live_active()) {
+   int ret;
+
+   ret = of_address_to_resource(ofnode_to_np(node),
+index, &r);
+   if (ret) {
+   debug("%s: Could not read resource of range %d (ret = 
%d)\n",
+ ofnode_get_name(node), index, ret);
+   return ret;
+   }
+
+   range->start = r.start;
+   range->size = r.end - r.start + 1;
+   } else {
+   int offset = ofnode_to_offset(node);
+
+   range->start = fdtdec_get_addr_size_fixed(gd->fdt_blob, offset,
+ "reg", index,
+ addr_len, size_len,
+ &sz, true);
+   if (range->start == FDT_ADDR_T_NONE) {
+   debug("%s: Could not read start of range %d\n",
+ ofnode_get_name(node), index);
+   return -EINVAL;
+   }
+
+   range->size = sz;
+   }
+
+   return 0;
+}
+
 int regmap_init_mem(ofnode node, struct regmap **mapp)
 {
struct regmap_range *range;
@@ -64,7 +116,6 @@ int regmap_init_mem(ofnode node, struct regmap **mapp)
int addr_len, size_len, both_len;
int len;
int index;
-   struct resource r;

addr_len = ofnode_read_simple_addr_cells(ofnode_get_parent(node));
if (addr_len < 0) {
@@ -101,17 +152,10 @@ int regmap_init_mem(ofnode node, struct regmap **mapp)

for (range = map->ranges, index = 0; count > 0;
 count--, range++, index++) {
-   fdt_size_t sz;
-   if (of_live_active()) {
-   of_address_to_resource(ofnode_to_np(node), index, &r);
-   range->start = r.start;
-   range->size = r.end - r.start + 1;
-   } else {
-   range->start = fdtdec_get_addr_size_fixed(gd->fdt_blob,
-   ofnode_to_offset(node), "reg", index,
-   addr_len, size_len, &sz, true);
-   range->size = sz;
-   }
+   int ret = init_range(node, range, addr_len, size_len, index);
+
+   if (ret)
+   return ret;
}

*mapp = map;
--
2.18.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v11 07/16] mips: Implement {in, out}_{le, be}_{16, 32, 64} and {in, out}_8

2018-10-15 Thread Mario Six
MIPS is the only architecture currently supported by U-Boot that does
not implement any of the in/out register access functions.

To have a interface that is useable across architectures, add the
functions to the MIPS architecture (implemented using the __raw_write
and __raw_read functions).

Reviewed-by: Simon Glass 
Reviewed-by: Stefan Roese 
Reviewed-by: Daniel Schwierzeck 
Signed-off-by: Mario Six 

---
v10 -> v11:
No changes

v9 -> v10:
No changes

v8 -> v9:
No changes

v7 -> v8:
No changes

v6 -> v7:
No changes

v5 -> v6:
New in v6
---
 arch/mips/include/asm/io.h | 22 ++
 1 file changed, 22 insertions(+)

diff --git a/arch/mips/include/asm/io.h b/arch/mips/include/asm/io.h
index 957442effd..7c40e415c7 100644
--- a/arch/mips/include/asm/io.h
+++ b/arch/mips/include/asm/io.h
@@ -547,6 +547,28 @@ __BUILD_CLRSETBITS(bwlq, sfx, end, type)
 #define __to_cpu(v)(v)
 #define cpu_to__(v)(v)

+#define out_arch(type, endian, a, v)   __raw_write##type(cpu_to_##endian(v),a)
+#define in_arch(type, endian, a)   endian##_to_cpu(__raw_read##type(a))
+
+#define out_le64(a, v) out_arch(q, le64, a, v)
+#define out_le32(a, v) out_arch(l, le32, a, v)
+#define out_le16(a, v) out_arch(w, le16, a, v)
+
+#define in_le64(a) in_arch(q, le64, a)
+#define in_le32(a) in_arch(l, le32, a)
+#define in_le16(a) in_arch(w, le16, a)
+
+#define out_be64(a, v) out_arch(q, be64, a, v)
+#define out_be32(a, v) out_arch(l, be32, a, v)
+#define out_be16(a, v) out_arch(w, be16, a, v)
+
+#define in_be64(a) in_arch(q, be64, a)
+#define in_be32(a) in_arch(l, be32, a)
+#define in_be16(a) in_arch(w, be16, a)
+
+#define out_8(a, v)__raw_writeb(v, a)
+#define in_8(a)__raw_readb(a)
+
 BUILD_CLRSETBITS(b, 8, _, u8)
 BUILD_CLRSETBITS(w, le16, le16, u16)
 BUILD_CLRSETBITS(w, be16, be16, u16)
--
2.18.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v11 11/16] test: regmap: Add test for regmap_{set, get}

2018-10-15 Thread Mario Six
Add test for regmap_{set,get} functions.

Reviewed-by: Anatolij Gustschin 
Reviewed-by: Simon Glass 
Signed-off-by: Mario Six 

---
v10 -> v11:
No changes

v9 -> v10:
No changes

v8 -> v9:
No changes

v7 -> v8:
No changes

v6 -> v7:
No changes

v5 -> v6:
No changes

v4 -> v5:
No changes

v3 -> v4:
No changes

v2 -> v3:
New in v3
---
 test/dm/regmap.c | 28 
 1 file changed, 28 insertions(+)

diff --git a/test/dm/regmap.c b/test/dm/regmap.c
index b28d6a6cd1..a8d7e6829e 100644
--- a/test/dm/regmap.c
+++ b/test/dm/regmap.c
@@ -116,3 +116,31 @@ static int dm_test_regmap_rw(struct unit_test_state *uts)
 }

 DM_TEST(dm_test_regmap_rw, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+/* Get/Set test */
+static int dm_test_regmap_getset(struct unit_test_state *uts)
+{
+   struct udevice *dev;
+   struct regmap *map;
+   uint reg;
+   struct layout {
+   u32 val0;
+   u32 val1;
+   u32 val2;
+   u32 val3;
+   };
+
+   ut_assertok(uclass_get_device(UCLASS_SYSCON, 0, &dev));
+   map = syscon_get_regmap(dev);
+   ut_assertok_ptr(map);
+
+   regmap_set(map, struct layout, val0, 0xcacafafa);
+   regmap_set(map, struct layout, val3, 0x55aa2211);
+
+   ut_assertok(regmap_get(map, struct layout, val0, ®));
+   ut_assertok(regmap_get(map, struct layout, val3, ®));
+
+   return 0;
+}
+
+DM_TEST(dm_test_regmap_getset, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
--
2.18.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v11 14/16] misc: Sort Makefile entries

2018-10-15 Thread Mario Six
Makefile entries should be sorted.

Reviewed-by: Anatolij Gustschin 
Reviewed-by: Simon Glass 
Signed-off-by: Mario Six 
Signed-off-by: Anatolij Gustschin 

---
v10 -> v11:
No changes

v9 -> v10:
No changes

v8 -> v9:
No changes

v7 -> v8:
No changes

v6 -> v7:
No changes

v5 -> v6:
No changes

v4 -> v5:
Drop re-ordered entries that are not in mainline
(e.g. CONFIG_GDSYS_IOEP, CONFIG_MPC83XX_SERDES, misc_sandbox.o)

v3 -> v4:
No changes

v2 -> v3:
New in v3
---
 drivers/misc/Makefile | 58 +--
 1 file changed, 29 insertions(+), 29 deletions(-)

diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index cf6587268e..aa5410ea15 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -4,11 +4,6 @@
 # Wolfgang Denk, DENX Software Engineering, w...@denx.de.

 obj-$(CONFIG_MISC) += misc-uclass.o
-obj-$(CONFIG_ALI152X) += ali512x.o
-obj-$(CONFIG_ALTERA_SYSID) += altera_sysid.o
-obj-$(CONFIG_ATSHA204A) += atsha204a-i2c.o
-obj-$(CONFIG_DS4510)  += ds4510.o
-obj-$(CONFIG_CBMEM_CONSOLE) += cbmem_console.o
 ifndef CONFIG_SPL_BUILD
 obj-$(CONFIG_CROS_EC) += cros_ec.o
 obj-$(CONFIG_CROS_EC_LPC) += cros_ec_lpc.o
@@ -16,45 +11,50 @@ obj-$(CONFIG_CROS_EC_I2C) += cros_ec_i2c.o
 obj-$(CONFIG_CROS_EC_SANDBOX) += cros_ec_sandbox.o
 obj-$(CONFIG_CROS_EC_SPI) += cros_ec_spi.o
 endif
-obj-$(CONFIG_FSL_IIM) += fsl_iim.o
-obj-$(CONFIG_LED_STATUS_GPIO) += gpio_led.o
-obj-$(CONFIG_$(SPL_)I2C_EEPROM) += i2c_eeprom.o
-obj-$(CONFIG_FSL_MC9SDZ60) += mc9sdz60.o
-obj-$(CONFIG_MXC_OCOTP) += mxc_ocotp.o
-obj-$(CONFIG_MXS_OCOTP) += mxs_ocotp.o
-obj-$(CONFIG_NUVOTON_NCT6102D) += nuvoton_nct6102d.o
-obj-$(CONFIG_NS87308) += ns87308.o
-obj-$(CONFIG_$(SPL_)PWRSEQ) += pwrseq-uclass.o
 ifdef CONFIG_DM_I2C
 ifndef CONFIG_SPL_BUILD
 obj-$(CONFIG_SANDBOX) += i2c_eeprom_emul.o
 endif
 endif
-obj-$(CONFIG_SMSC_LPC47M) += smsc_lpc47m.o
-obj-$(CONFIG_SMSC_SIO1007) += smsc_sio1007.o
-obj-$(CONFIG_LED_STATUS) += status_led.o
-obj-$(CONFIG_SANDBOX) += swap_case.o
 ifdef CONFIG_SPL_OF_PLATDATA
 ifdef CONFIG_SPL_BUILD
 obj-$(CONFIG_SANDBOX) += spltest_sandbox.o
 endif
 endif
-obj-$(CONFIG_SANDBOX) += syscon_sandbox.o misc_sandbox.o
-obj-$(CONFIG_TEGRA_CAR) += tegra_car.o
-obj-$(CONFIG_TEGRA186_BPMP) += tegra186_bpmp.o
-obj-$(CONFIG_TWL4030_LED) += twl4030_led.o
+obj-$(CONFIG_ALI152X) += ali512x.o
+obj-$(CONFIG_ALTERA_SYSID) += altera_sysid.o
+obj-$(CONFIG_ATSHA204A) += atsha204a-i2c.o
+obj-$(CONFIG_CBMEM_CONSOLE) += cbmem_console.o
+obj-$(CONFIG_DS4510)  += ds4510.o
+obj-$(CONFIG_FSL_DEVICE_DISABLE) += fsl_devdis.o
 obj-$(CONFIG_FSL_IFC) += fsl_ifc.o
+obj-$(CONFIG_FSL_IIM) += fsl_iim.o
+obj-$(CONFIG_FSL_MC9SDZ60) += mc9sdz60.o
 obj-$(CONFIG_FSL_SEC_MON) += fsl_sec_mon.o
+obj-$(CONFIG_FS_LOADER) += fs_loader.o
+obj-$(CONFIG_GDSYS_IOEP) += gdsys_ioep.o
+obj-$(CONFIG_GDSYS_RXAUI_CTRL) += gdsys_rxaui_ctrl.o
+obj-$(CONFIG_$(SPL_)I2C_EEPROM) += i2c_eeprom.o
+obj-$(CONFIG_LED_STATUS) += status_led.o
+obj-$(CONFIG_LED_STATUS_GPIO) += gpio_led.o
+obj-$(CONFIG_MPC83XX_SERDES) += mpc83xx_serdes.o
+obj-$(CONFIG_MXC_OCOTP) += mxc_ocotp.o
+obj-$(CONFIG_MXS_OCOTP) += mxs_ocotp.o
+obj-$(CONFIG_NS87308) += ns87308.o
+obj-$(CONFIG_NUVOTON_NCT6102D) += nuvoton_nct6102d.o
 obj-$(CONFIG_PCA9551_LED) += pca9551_led.o
-obj-$(CONFIG_FSL_DEVICE_DISABLE) += fsl_devdis.o
-obj-$(CONFIG_WINBOND_W83627) += winbond_w83627.o
+obj-$(CONFIG_$(SPL_)PWRSEQ) += pwrseq-uclass.o
 obj-$(CONFIG_QFW) += qfw.o
 obj-$(CONFIG_ROCKCHIP_EFUSE) += rockchip-efuse.o
-obj-$(CONFIG_STM32_RCC) += stm32_rcc.o
+obj-$(CONFIG_SANDBOX) += swap_case.o
+obj-$(CONFIG_SANDBOX) += syscon_sandbox.o misc_sandbox.o
+obj-$(CONFIG_SMSC_LPC47M) += smsc_lpc47m.o
+obj-$(CONFIG_SMSC_SIO1007) += smsc_sio1007.o
 obj-$(CONFIG_STM32MP_FUSE) += stm32mp_fuse.o
+obj-$(CONFIG_STM32_RCC) += stm32_rcc.o
 obj-$(CONFIG_SYS_DPAA_QBMAN) += fsl_portals.o
-obj-$(CONFIG_GDSYS_IOEP) += gdsys_ioep.o
-obj-$(CONFIG_GDSYS_RXAUI_CTRL) += gdsys_rxaui_ctrl.o
+obj-$(CONFIG_TEGRA186_BPMP) += tegra186_bpmp.o
+obj-$(CONFIG_TEGRA_CAR) += tegra_car.o
+obj-$(CONFIG_TWL4030_LED) += twl4030_led.o
 obj-$(CONFIG_VEXPRESS_CONFIG) += vexpress_config.o
-obj-$(CONFIG_MPC83XX_SERDES) += mpc83xx_serdes.o
-obj-$(CONFIG_FS_LOADER) += fs_loader.o
+obj-$(CONFIG_WINBOND_W83627) += winbond_w83627.o
--
2.18.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v11 16/16] misc: Add IHS FPGA driver

2018-10-15 Thread Mario Six
Add a driver for gdsys IHS (Integrated Hardware Systems) FPGAs, which
supports initialization of the FPGA, as well as information gathering.

Reviewed-by: Simon Glass 
Signed-off-by: Mario Six 

---
v10 -> v11:
No changes

v9 -> v10:
No changes

v8 -> v9:
No changes

v7 -> v8:
No changes

v6 -> v7:
No changes

v5 -> v6:
No changes

v4 -> v5:
No changes

v3 -> v4:
* Switched from 'res' as the name for return variables to 'ret'

v2 -> v3:
* Fixed style violations
* Added full documentation
* Extracted some magic numbers to constants
* Removed unnecessary includes
* Extracted wait_for_fpga_done
* Improved error handling and reporting
* Added device-tree-binding files
* Improved Kconfig entry

v1 -> v2:
New in v2
---
 .../bindings/misc/gdsys,iocon_fpga.txt|  19 +
 .../bindings/misc/gdsys,iocpu_fpga.txt|  19 +
 drivers/misc/Kconfig  |   9 +
 drivers/misc/Makefile |   1 +
 drivers/misc/ihs_fpga.c   | 867 ++
 drivers/misc/ihs_fpga.h   |  49 +
 6 files changed, 964 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/misc/gdsys,iocon_fpga.txt
 create mode 100644 Documentation/devicetree/bindings/misc/gdsys,iocpu_fpga.txt
 create mode 100644 drivers/misc/ihs_fpga.c
 create mode 100644 drivers/misc/ihs_fpga.h

diff --git a/Documentation/devicetree/bindings/misc/gdsys,iocon_fpga.txt 
b/Documentation/devicetree/bindings/misc/gdsys,iocon_fpga.txt
new file mode 100644
index 00..acd466fdc6
--- /dev/null
+++ b/Documentation/devicetree/bindings/misc/gdsys,iocon_fpga.txt
@@ -0,0 +1,19 @@
+gdsys IHS FPGA for CON devices
+
+The gdsys IHS FPGA is the main FPGA on gdsys CON devices. This driver provides
+support for enabling and starting the FPGA, as well as verifying working bus
+communication.
+
+Required properties:
+- compatible: must be "gdsys,iocon_fpga"
+- reset-gpios: List of GPIOs controlling the FPGA's reset
+- done-gpios: List of GPIOs notifying whether the FPGA's reconfiguration is
+  done
+
+Example:
+
+FPGA0 {
+   compatible = "gdsys,iocon_fpga";
+   reset-gpios = <&PPCPCA 26 0>;
+   done-gpios = <&GPIO_VB0 19 0>;
+};
diff --git a/Documentation/devicetree/bindings/misc/gdsys,iocpu_fpga.txt 
b/Documentation/devicetree/bindings/misc/gdsys,iocpu_fpga.txt
new file mode 100644
index 00..819db22bf7
--- /dev/null
+++ b/Documentation/devicetree/bindings/misc/gdsys,iocpu_fpga.txt
@@ -0,0 +1,19 @@
+gdsys IHS FPGA for CPU devices
+
+The gdsys IHS FPGA is the main FPGA on gdsys CPU devices. This driver provides
+support for enabling and starting the FPGA, as well as verifying working bus
+communication.
+
+Required properties:
+- compatible: must be "gdsys,iocpu_fpga"
+- reset-gpios: List of GPIOs controlling the FPGA's reset
+- done-gpios: List of GPIOs notifying whether the FPGA's reconfiguration is
+  done
+
+Example:
+
+FPGA0 {
+   compatible = "gdsys,iocpu_fpga";
+   reset-gpios = <&PPCPCA 26 0>;
+   done-gpios = <&GPIO_VB0 19 0>;
+};
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index d589f32a55..48febc47d2 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -320,4 +320,13 @@ config GDSYS_SOC
  IHS (Integrated Hardware Systems) FPGA, which holds all devices whose
  register maps are contained within the FPGA's register map.

+config IHS_FPGA
+   bool "Enable IHS FPGA driver"
+   depends on MISC
+   help
+ Support IHS (Integrated Hardware Systems) FPGA, the main FPGAs on
+ gdsys devices, which supply the majority of the functionality offered
+ by the devices. This driver supports both CON and CPU variants of the
+ devices, depending on the device tree entry.
+
 endmenu
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index ed5d7bb0c0..ef4bacb718 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -36,6 +36,7 @@ obj-$(CONFIG_GDSYS_IOEP) += gdsys_ioep.o
 obj-$(CONFIG_GDSYS_RXAUI_CTRL) += gdsys_rxaui_ctrl.o
 obj-$(CONFIG_GDSYS_SOC) += gdsys_soc.o
 obj-$(CONFIG_$(SPL_)I2C_EEPROM) += i2c_eeprom.o
+obj-$(CONFIG_IHS_FPGA) += ihs_fpga.o
 obj-$(CONFIG_LED_STATUS) += status_led.o
 obj-$(CONFIG_LED_STATUS_GPIO) += gpio_led.o
 obj-$(CONFIG_MPC83XX_SERDES) += mpc83xx_serdes.o
diff --git a/drivers/misc/ihs_fpga.c b/drivers/misc/ihs_fpga.c
new file mode 100644
index 00..f9e4b27a27
--- /dev/null
+++ b/drivers/misc/ihs_fpga.c
@@ -0,0 +1,867 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2017
+ * Mario Six,  Guntermann & Drunck GmbH, mario@gdsys.cc
+ *
+ * based on the ioep-fpga driver, which is
+ *
+ * (C) Copyright 2014
+ * Dirk Eibach,  Guntermann & Drunck GmbH, eib...@gdsys.de
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#include "ihs_fpga.h"
+
+/**
+ * struct ihs_fpga_priv - Private data structure for IHS FPGA driver
+ * @map:Register map for the FPGA's own register space
+ * @reset_gpio: 

Re: [U-Boot] [PATCH v2 1/1] efi_loader: PSCI reset and shutdown

2018-10-15 Thread Sumit Garg
On Sat, 13 Oct 2018 at 12:42, Heinrich Schuchardt  wrote:
>
> When an operating system started via bootefi tries to reset or power off
> this is done by calling the EFI runtime ResetSystem(). On most ARMv8 system
> the actual reset relies on PSCI. Depending on whether the PSCI firmware
> resides the hypervisor or in the supervisor either an HVC or an SVC command
> has to be issued. The current implementation always uses SVC. This results

Here you need to use SMC instead of SVC and EL3 firmware instead of supervisor.

> in crashes on systems where the PSCI firmware is implemented in the
> hypervisor, e.g. qemu-arm64_defconfig.
>
> The logic to decide which call is needed based on the device tree is already
> implemented in the PSCI firmware driver. So let's use it for the EFI
> runtime.
>
> As the same problem is also evident for the ARMv8 poweroff command
> implementation fix it in the same way.
>
> Signed-off-by: Heinrich Schuchardt 
> ---
> Travis reported no errors in
> https://travis-ci.org/xypron2/u-boot/builds/440843498
> except for two boards with an image size problem.
>
> v2:
> Use PSCI firmware driver to detect call method.
> Thanks to Sumit for pointing me at dtb parsing as part of
> "psci_probe()
> ---
>  arch/arm/cpu/armv7/smccc-call.S |  2 +
>  arch/arm/cpu/armv8/Kconfig  |  1 +
>  arch/arm/cpu/armv8/fwcall.c | 52 ++-
>  arch/arm/cpu/armv8/smccc-call.S |  2 +
>  drivers/firmware/psci.c | 91 +++--
>  include/linux/psci.h|  6 +--
>  6 files changed, 87 insertions(+), 67 deletions(-)
>
> diff --git a/arch/arm/cpu/armv7/smccc-call.S b/arch/arm/cpu/armv7/smccc-call.S
> index 0d8b59eb6b..eae69e36c3 100644
> --- a/arch/arm/cpu/armv7/smccc-call.S
> +++ b/arch/arm/cpu/armv7/smccc-call.S
> @@ -7,6 +7,8 @@
>  #include 
>  #include 
>
> +   .section.text.efi_runtime
> +
>  #define UNWIND(x...)
> /*
>  * Wrap c macros in asm macros to delay expansion until after the
> diff --git a/arch/arm/cpu/armv8/Kconfig b/arch/arm/cpu/armv8/Kconfig
> index c8bebabdf6..d643981b73 100644
> --- a/arch/arm/cpu/armv8/Kconfig
> +++ b/arch/arm/cpu/armv8/Kconfig
> @@ -96,6 +96,7 @@ endmenu
>  config PSCI_RESET
> bool "Use PSCI for reset and shutdown"
> default y
> +   select ARM_SMCCC if OF_CONTROL
> depends on !ARCH_EXYNOS7 && !ARCH_BCM283X && \
>!TARGET_LS2080A_SIMU && !TARGET_LS2080AQDS && \
>!TARGET_LS2080ARDB && !TARGET_LS2080A_EMU && \
> diff --git a/arch/arm/cpu/armv8/fwcall.c b/arch/arm/cpu/armv8/fwcall.c
> index 0ba3dad8cc..9957c2974b 100644
> --- a/arch/arm/cpu/armv8/fwcall.c
> +++ b/arch/arm/cpu/armv8/fwcall.c
> @@ -7,7 +7,6 @@
>
>  #include 
>  #include 
> -#include 
>  #include 
>  #include 
>  #include 
> @@ -19,7 +18,7 @@
>   * x0~x7: input arguments
>   * x0~x3: output arguments
>   */
> -static void __efi_runtime hvc_call(struct pt_regs *args)
> +static void hvc_call(struct pt_regs *args)
>  {
> asm volatile(
> "ldr x0, %0\n"
> @@ -53,7 +52,7 @@ static void __efi_runtime hvc_call(struct pt_regs *args)
>   * x0~x3: output arguments
>   */
>
> -void __efi_runtime smc_call(struct pt_regs *args)
> +void smc_call(struct pt_regs *args)
>  {
> asm volatile(
> "ldr x0, %0\n"
> @@ -83,9 +82,9 @@ void __efi_runtime smc_call(struct pt_regs *args)
>   * use PSCI on U-Boot running below a hypervisor, please detect
>   * this and set the flag accordingly.
>   */
> -static const __efi_runtime_data bool use_smc_for_psci = true;
> +static const bool use_smc_for_psci = true;
>
> -void __noreturn __efi_runtime psci_system_reset(void)
> +void __noreturn psci_system_reset(void)
>  {
> struct pt_regs regs;
>
> @@ -100,7 +99,7 @@ void __noreturn __efi_runtime psci_system_reset(void)
> ;
>  }
>
> -void __noreturn __efi_runtime psci_system_off(void)
> +void __noreturn psci_system_off(void)
>  {
> struct pt_regs regs;
>
> @@ -114,44 +113,3 @@ void __noreturn __efi_runtime psci_system_off(void)
> while (1)
> ;
>  }
> -
> -#ifdef CONFIG_CMD_POWEROFF
> -int do_poweroff(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
> -{
> -   puts("poweroff ...\n");
> -
> -   udelay(5); /* wait 50 ms */
> -
> -   disable_interrupts();
> -
> -   psci_system_off();
> -
> -   /*NOTREACHED*/
> -   return 0;
> -}
> -#endif
> -
> -#ifdef CONFIG_PSCI_RESET
> -void reset_misc(void)
> -{
> -   psci_system_reset();
> -}

I don't see if you have implemented this api using the psci driver. I
think this is used in case CONFIG_SYSRESET is not defined.

-Sumit

> -
> -#ifdef CONFIG_EFI_LOADER
> -void __efi_runtime EFIAPI efi_reset_system(
> -   enum efi_reset_type reset_type,
> -   efi_status_t reset_status,
> -   unsigned long data_size, void *reset_data)
> -{
> -   if (

Re: [U-Boot] [PATCH v2 1/2] cpu: Add DM_FLAG_PRE_RELOC flag to various cpu drivers

2018-10-15 Thread Stefan Roese

On 14.10.2018 10:07, Bin Meng wrote:

It turns out commit c0434407b595 broke some boards which have DM CPU
driver with CONFIG_DISPLAY_CPUINFO option on. These boards just fail
to boot when print_cpuinfo() is called during boot.

Fixes: c0434407b595 ("board_f: Use static print_cpuinfo if CONFIG_CPU is 
active")
Reported-by: Stefan Roese 
Signed-off-by: Bin Meng 


Reviewed-by: Stefan Roese 
Tested-by: Stefan Roese 

Thanks,
Stefan
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v2 2/2] cpu: sandbox: Add "u-boot, dm-pre-reloc" for all cpu nodes

2018-10-15 Thread Stefan Roese

On 14.10.2018 10:07, Bin Meng wrote:

To support CONFIG_DISPLAY_CPUINFO, add "u-boot,dm-pre-reloc" for
all cpu nodes in Sandbox test.dts.

Signed-off-by: Bin Meng 


Reviewed-by: Stefan Roese 

Thanks,
Stefan
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v3 3/9] dm: uclass: Add uclass_foreach_dev_probe

2018-10-15 Thread Patrice CHOTARD
Hi Bin

On 10/12/2018 12:13 PM, Bin Meng wrote:
> Hi Patrice,
> 
> On Fri, Oct 12, 2018 at 3:51 PM Patrice CHOTARD  
> wrote:
>>
>> Hi Bin
>>
>> On 10/11/2018 11:06 AM, Bin Meng wrote:
>>> Hi Patrice,
>>>
>>> On Tue, Oct 9, 2018 at 9:41 PM Patrice Chotard  
>>> wrote:

 Add uclass_foreach_dev_probe() which iterates through
 devices of a given uclass. Devices are probed if necessary
 and are ready to use.

 Signed-off-by: Patrice Chotard 
 Reviewed-by: Simon Glass 
 ---

 Changes in v3: None
 Changes in v2: None

  include/dm/uclass.h | 16 
  1 file changed, 16 insertions(+)

 diff --git a/include/dm/uclass.h b/include/dm/uclass.h
 index 6e7c1cd3e8bc..10ccfdce951e 100644
 --- a/include/dm/uclass.h
 +++ b/include/dm/uclass.h
 @@ -376,4 +376,20 @@ int uclass_resolve_seq(struct udevice *dev);
  #define uclass_foreach_dev_safe(pos, next, uc) \
 list_for_each_entry_safe(pos, next, &uc->dev_head, uclass_node)

 +/**
 + * uclass_foreach_dev_probe() - Helper function to iteration through 
 devices
 + * of given uclass
 + *
 + * This creates a for() loop which works through the available devices in
 + * a uclass in order from start to end. Devices are probed if necessary,
 + * and ready for use.
 + *
 + * @id: Uclass ID
 + * @dev: struct udevice * to hold the current device. Set to NULL when 
 there
 + * are no more devices.
 + */
 +#define uclass_foreach_dev_probe(id, dev)  \
 +   for (uclass_first_device(id, &dev); dev; \
 +uclass_next_device(&dev))
>>>
>>> Shouldn't we check the return value of uclass_first_device() and
>>> uclass_next_device()?
>>
>> It's not necessary to check the return value of uclass_first_device(id,
>> &dev) because in any error case, dev is NULL, which is the loop output
>> condition. This is only for the first iteration.
>>
> 
> Please see the comment of uclass_first_device().
> 
>  * @devp: Returns pointer to the first device in that uclass if no error
>  * occurred, or NULL if there is no first device, or an error occurred with
>  * that device.
>  * @return 0 if OK (found or not found), other -ve on error
> 
> So it can return error with a valid dev.

I checked the uclass_first_device() implementation and the comment seems
not aligned with what is coded. When uclass_first_device() returns a
valid dev, return value is always 0. (see uclass_get_device_tail()
return value).

In any case uclass_first_device() returns a valid dev with an error.

Simon, Bin do you confirm ?

> 
>> For the other iteration, dev comes from uclass_next_device(&dev),
>> similarly to uclass_first_device(), in any error case dev is NULL.
>>
> 
> Similar please see the comment of uclass_next_device().

I have the same remark regarding uclass_next_device().

Thanks

Patrice

> 
> Regards,
> Bin
> 
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 00/31] virtio: Introduce VirtIO driver support

2018-10-15 Thread Bin Meng
This series brings in VirtIO driver support in U-Boot. The work is based
on Tuomas's virtio support on QEMU ARM targets.

VirtIO is a virtualization standard for network and disk device drivers
where just the guest's device driver "knows" it is running in a virtual
environment, and cooperates with the hypervisor. This enables guests to
get high performance network and disk operations, and gives most of the
performance benefits of paravirtualization. In the U-Boot case, the
guest is U-Boot itself, while the virtual environment are normally QEMU
targets like ARM, RISC-V and x86.

Both VirtIO MMIO and PCI transport options are supported. Only VirtIO
network and block device drivers are supported for now.

The following QEMU targets are supported.

  - qemu_arm_defconfig
  - qemu_arm64_defconfig
  - qemu-riscv32_defconfig
  - qemu-riscv64_defconfig
  - qemu-x86_defconfig
  - qemu-x86_64_defconfig

A new child_post_probe() uclass driver method is introduced to better
support virtio device driver. This also changes BLK uclass driver to
supply a post_probe() method which calls part_init(), so that we can
avoid duplicating such call in every BLK driver.

Not every checkpatch warning reported was fixed, but I tried to fix as
many as possible which makes sense. travis-ci build all pass.

This series is available at u-boot-x86/virtio-working for testing.

Changes in v3:
- Exclude VIRTIO_BLK in sandbox_noblk_defconfig build

Changes in v2:
- new patch to add test case for uclass driver's child_post_probe()
- new patch to add dm_remove_devices_flags() call to do_bootm_linux()
  for riscv bootm
- Added virtio spec link and a short statement of what virtio is
  in the header and source files
- Changed to use 'transport' over 'bus' in drivers/virtio/Kconfig
- Added UCLASS_VIRTIO ID in alphabetical order
- Moved the header file inclusion from virtio.h to C file
- Fixed code styling issue (blank line before return) in
  virtio_xxx() APIs
- Changed virtio_init() to return int if there is an error
- Added virtio_uclass_pre_probe() to check virtio transport driver
  ops here so that we don't need check these ops each time when
  the virtio_xxx APIs are called
- Implemented child_post_remove() method to reset the virtio device
- Changed virtio_driver_features_init() parameter 'feature' and
  'feature_legacy' to const, and adjust member of
  'struct virtio_dev_priv' accordingly
- Initialize uc_priv->vqs in virtio_uclass_post_probe()
- Changed virtio net driver feature table to const
- Correct desc->vendor for PCI transport
- imply VIRTIO_PCI for qemu-arm too
- use an internal function _dm_pci_find_next_capability() for
  dm_pci_find_capability() and dm_pci_find_next_capability()
- adjust swap_case driver to handle request from
  _dm_pci_find_next_capability()
- fix compiler warnings in 64-bit build
- adjust virtio_pci_find_capability() to avoid walking through capability
  list to find next one by ourselves
- new patch to add a Sandbox transport driver
- new patch to add test cases for virtio uclass
- Added driver remove and flags description in the documentation

Bin Meng (26):
  dm: core: Allow uclass to set up a device's child after it is probed
  test: dm: core: Add test case for uclass driver's child_post_probe()
  riscv: bootm: Add dm_remove_devices_flags() call to do_bootm_linux()
  dm: Add a new uclass driver for VirtIO transport devices
  virtio: Add virtio over mmio transport driver
  test: dm: blk: Correct blk_base test case
  sandbox: blk: Switch to use platdata_auto_alloc_size for the driver
data
  efi_driver: blk: Switch to use platdata_auto_alloc_size for the driver
data
  blk: Call part_init() in the post_probe() method
  blk: Drop blk_prepare_device()
  blk: Make blk_next_free_devnum() public
  riscv: qemu: Enumerate virtio bus during early boot
  riscv: qemu: Include some useful commands
  kconfig: Introduce HAVE_ARCH_IOMAP
  x86: Implement arch-specific io accessor routines
  virtio: Add virtio over pci transport driver
  arm: qemu: Add a Kconfig in the board directory
  arm: qemu: Enumerate virtio bus during early boot
  x86: qemu: Imply virtio PCI transport and device drivers
  dm: pci: Add APIs to find next capability and extended capability
  test: dm: pci: Add cases for finding next PCI capability APIs
  virtio: pci: Support non-legacy PCI transport device
  virtio: net: Support non-legacy device
  virtio: Add a Sandbox transport driver
  test: dm: virtio: Add test cases for virtio uclass
  doc: Document virtio support

Tuomas Tynkkynen (5):
  virtio: Add codes for virtual queue/ring management
  virtio: Add net driver support
  blk: Introduce IF_TYPE_VIRTIO
  virtio: Add block driver support
  virtio: cmd: Add virtio command for virtio devices

 arch/Kconfig|   6 +
 arch/arm/Kconfig|   1 +
 arch/riscv/lib/bootm.c  |  11 +-
 arch/sandbox/dts/test.dts   |   8 +
 arch/x86/include/asm/io.h   |  66 +++
 board/e

[U-Boot] [PATCH v3 01/31] dm: core: Allow uclass to set up a device's child after it is probed

2018-10-15 Thread Bin Meng
Some buses need to set up their child devices after they are probed.
Support a common child_post_probe() method for the uclass.

With this change, the two APIs uclass_pre_probe_device() and
uclass_post_probe_device() become symmetric.

Signed-off-by: Bin Meng 
---

Changes in v3: None
Changes in v2: None

 drivers/core/uclass.c | 13 -
 include/dm/uclass.h   |  4 +++-
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c
index 3113d6a..3c7b9cf 100644
--- a/drivers/core/uclass.c
+++ b/drivers/core/uclass.c
@@ -687,8 +687,19 @@ int uclass_pre_probe_device(struct udevice *dev)
 
 int uclass_post_probe_device(struct udevice *dev)
 {
-   struct uclass_driver *uc_drv = dev->uclass->uc_drv;
+   struct uclass_driver *uc_drv;
+   int ret;
+
+   if (dev->parent) {
+   uc_drv = dev->parent->uclass->uc_drv;
+   if (uc_drv->child_post_probe) {
+   ret = uc_drv->child_post_probe(dev);
+   if (ret)
+   return ret;
+   }
+   }
 
+   uc_drv = dev->uclass->uc_drv;
if (uc_drv->post_probe)
return uc_drv->post_probe(dev);
 
diff --git a/include/dm/uclass.h b/include/dm/uclass.h
index eebf2d5..4ef0d0f 100644
--- a/include/dm/uclass.h
+++ b/include/dm/uclass.h
@@ -61,7 +61,8 @@ struct udevice;
  * @post_probe: Called after a new device is probed
  * @pre_remove: Called before a device is removed
  * @child_post_bind: Called after a child is bound to a device in this uclass
- * @child_pre_probe: Called before a child is probed in this uclass
+ * @child_pre_probe: Called before a child in this uclass is probed
+ * @child_post_probe: Called after a child in this uclass is probed
  * @init: Called to set up the uclass
  * @destroy: Called to destroy the uclass
  * @priv_auto_alloc_size: If non-zero this is the size of the private data
@@ -94,6 +95,7 @@ struct uclass_driver {
int (*pre_remove)(struct udevice *dev);
int (*child_post_bind)(struct udevice *dev);
int (*child_pre_probe)(struct udevice *dev);
+   int (*child_post_probe)(struct udevice *dev);
int (*init)(struct uclass *class);
int (*destroy)(struct uclass *class);
int priv_auto_alloc_size;
-- 
2.7.4

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 02/31] test: dm: core: Add test case for uclass driver's child_post_probe()

2018-10-15 Thread Bin Meng
Add test case to cover uclass driver's child_post_probe() method.

Signed-off-by: Bin Meng 

---

Changes in v3: None
Changes in v2:
- new patch to add test case for uclass driver's child_post_probe()

 include/dm/test.h  |  1 +
 test/dm/bus.c  | 45 +
 test/dm/test-fdt.c |  7 +--
 3 files changed, 51 insertions(+), 2 deletions(-)

diff --git a/include/dm/test.h b/include/dm/test.h
index 83418eb..07385cd 100644
--- a/include/dm/test.h
+++ b/include/dm/test.h
@@ -69,6 +69,7 @@ struct dm_test_priv {
int op_count[DM_TEST_OP_COUNT];
int uclass_flag;
int uclass_total;
+   int uclass_postp;
 };
 
 /**
diff --git a/test/dm/bus.c b/test/dm/bus.c
index d0cd5a0..93f3acd 100644
--- a/test/dm/bus.c
+++ b/test/dm/bus.c
@@ -63,6 +63,15 @@ static int testbus_child_pre_probe_uclass(struct udevice 
*dev)
return 0;
 }
 
+static int testbus_child_post_probe_uclass(struct udevice *dev)
+{
+   struct dm_test_priv *priv = dev_get_priv(dev);
+
+   priv->uclass_postp++;
+
+   return 0;
+}
+
 static int testbus_child_post_remove(struct udevice *dev)
 {
struct dm_test_parent_data *parent_data = dev_get_parent_priv(dev);
@@ -102,6 +111,7 @@ UCLASS_DRIVER(testbus) = {
.id = UCLASS_TEST_BUS,
.flags  = DM_UC_FLAG_SEQ_ALIAS,
.child_pre_probe = testbus_child_pre_probe_uclass,
+   .child_post_probe = testbus_child_post_probe_uclass,
 };
 
 /* Test that we can probe for children */
@@ -547,3 +557,38 @@ static int dm_test_bus_child_pre_probe_uclass(struct 
unit_test_state *uts)
 }
 DM_TEST(dm_test_bus_child_pre_probe_uclass,
DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+/*
+ * Test that the bus' uclass' child_post_probe() is called after the
+ * device's probe() method
+ */
+static int dm_test_bus_child_post_probe_uclass(struct unit_test_state *uts)
+{
+   struct udevice *bus, *dev;
+   int child_count;
+
+   /*
+* See testfdt_drv_probe() which effectively initializes that
+* the uclass postp flag is set to a value
+*/
+   ut_assertok(uclass_get_device(UCLASS_TEST_BUS, 0, &bus));
+   for (device_find_first_child(bus, &dev), child_count = 0;
+dev;
+device_find_next_child(&dev)) {
+   struct dm_test_priv *priv = dev_get_priv(dev);
+
+   /* Check that things happened in the right order */
+   ut_asserteq_ptr(NULL, priv);
+   ut_assertok(device_probe(dev));
+
+   priv = dev_get_priv(dev);
+   ut_assert(priv != NULL);
+   ut_asserteq(0, priv->uclass_postp);
+   child_count++;
+   }
+   ut_asserteq(3, child_count);
+
+   return 0;
+}
+DM_TEST(dm_test_bus_child_post_probe_uclass,
+   DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
diff --git a/test/dm/test-fdt.c b/test/dm/test-fdt.c
index 3da384f..e43acb2 100644
--- a/test/dm/test-fdt.c
+++ b/test/dm/test-fdt.c
@@ -55,10 +55,13 @@ static int testfdt_drv_probe(struct udevice *dev)
 
/*
 * If this device is on a bus, the uclass_flag will be set before
-* calling this function. This is used by
-* dm_test_bus_child_pre_probe_uclass().
+* calling this function. In the meantime the uclass_postp is
+* initlized to a value -1. These are used respectively by
+* dm_test_bus_child_pre_probe_uclass() and
+* dm_test_bus_child_post_probe_uclass().
 */
priv->uclass_total += priv->uclass_flag;
+   priv->uclass_postp = -1;
 
return 0;
 }
-- 
2.7.4

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 03/31] riscv: bootm: Add dm_remove_devices_flags() call to do_bootm_linux()

2018-10-15 Thread Bin Meng
This adds a call to dm_remove_devices_flags() to do_bootm_linux()
so that drivers that have one of the removal flags set (e.g.
DM_FLAG_ACTIVE_DMA_REMOVE) in their driver struct, may do some
last-stage cleanup before the OS is started.

arm and x86 already did such, and we should do the same for riscv.

Signed-off-by: Bin Meng 

---

Changes in v3: None
Changes in v2:
- new patch to add dm_remove_devices_flags() call to do_bootm_linux()
  for riscv bootm

 arch/riscv/lib/bootm.c | 11 ++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/arch/riscv/lib/bootm.c b/arch/riscv/lib/bootm.c
index a7a9fb9..2b5ccce 100644
--- a/arch/riscv/lib/bootm.c
+++ b/arch/riscv/lib/bootm.c
@@ -9,9 +9,11 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
+#include 
+#include 
+#include 
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -57,6 +59,13 @@ int do_bootm_linux(int flag, int argc, char *argv[], 
bootm_headers_t *images)
/* we assume that the kernel is in place */
printf("\nStarting kernel ...\n\n");
 
+   /*
+* Call remove function of all devices with a removal flag set.
+* This may be useful for last-stage operations, like cancelling
+* of DMA operation or releasing device internal buffers.
+*/
+   dm_remove_devices_flags(DM_REMOVE_ACTIVE_ALL);
+
cleanup_before_linux();
 
if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len)
-- 
2.7.4

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 08/31] test: dm: blk: Correct blk_base test case

2018-10-15 Thread Bin Meng
The blk_base test case creates a USB mass storage block device with
the Sandbox host block device as its parent. This does not make any
sense and causes potential issue, for example if the test case tries
to read/write anything on the USB mass storage block device it will
definitely fail as its parent is not on USB bus at all.

Correct the test case by creating another Sandbox host block device
instead of the USB mass storage one and adjust the case accordingly.

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

Changes in v3: None
Changes in v2: None

 test/dm/blk.c | 27 +++
 1 file changed, 11 insertions(+), 16 deletions(-)

diff --git a/test/dm/blk.c b/test/dm/blk.c
index 4de477b..9c71adc 100644
--- a/test/dm/blk.c
+++ b/test/dm/blk.c
@@ -15,34 +15,29 @@ DECLARE_GLOBAL_DATA_PTR;
 /* Test that block devices can be created */
 static int dm_test_blk_base(struct unit_test_state *uts)
 {
-   struct udevice *blk, *usb_blk, *dev;
+   struct udevice *blk1, *blk3, *dev;
 
/* Make sure there are no block devices */
-   ut_asserteq(-ENODEV, uclass_get_device_by_seq(UCLASS_BLK, 0, &blk));
+   ut_asserteq(-ENODEV, uclass_get_device_by_seq(UCLASS_BLK, 0, &dev));
 
/* Create two, one the parent of the other */
ut_assertok(blk_create_device(gd->dm_root, "sandbox_host_blk", "test",
- IF_TYPE_HOST, 1, 512, 2, &blk));
-   ut_assertok(blk_create_device(blk, "usb_storage_blk", "test",
- IF_TYPE_USB, 3, 512, 2, &usb_blk));
+ IF_TYPE_HOST, 1, 512, 2, &blk1));
+   ut_assertok(blk_create_device(blk1, "sandbox_host_blk", "test",
+ IF_TYPE_HOST, 3, 512, 2, &blk3));
 
/* Check we can find them */
ut_asserteq(-ENODEV, blk_get_device(IF_TYPE_HOST, 0, &dev));
ut_assertok(blk_get_device(IF_TYPE_HOST, 1, &dev));
-   ut_asserteq_ptr(blk, dev);
-
-   ut_asserteq(-ENODEV, blk_get_device(IF_TYPE_USB, 0, &dev));
-   ut_assertok(blk_get_device(IF_TYPE_USB, 3, &dev));
-   ut_asserteq_ptr(usb_blk, dev);
+   ut_asserteq_ptr(blk1, dev);
+   ut_assertok(blk_get_device(IF_TYPE_HOST, 3, &dev));
+   ut_asserteq_ptr(blk3, dev);
 
/* Check we can iterate */
ut_assertok(blk_first_device(IF_TYPE_HOST, &dev));
-   ut_asserteq_ptr(blk, dev);
-   ut_asserteq(-ENODEV, blk_next_device(&dev));
-
-   ut_assertok(blk_first_device(IF_TYPE_USB, &dev));
-   ut_asserteq_ptr(usb_blk, dev);
-   ut_asserteq(-ENODEV, blk_next_device(&dev));
+   ut_asserteq_ptr(blk1, dev);
+   ut_assertok(blk_next_device(&dev));
+   ut_asserteq_ptr(blk3, dev);
 
return 0;
 }
-- 
2.7.4

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 07/31] virtio: Add net driver support

2018-10-15 Thread Bin Meng
From: Tuomas Tynkkynen 

This adds virtio net device driver support.

Signed-off-by: Tuomas Tynkkynen 
Signed-off-by: Bin Meng 
Reviewed-by: Simon Glass 


---

Changes in v3: None
Changes in v2:
- Changed virtio net driver feature table to const

 drivers/virtio/Kconfig  |   7 ++
 drivers/virtio/Makefile |   1 +
 drivers/virtio/virtio_net.c | 218 +++
 drivers/virtio/virtio_net.h | 268 
 4 files changed, 494 insertions(+)
 create mode 100644 drivers/virtio/virtio_net.c
 create mode 100644 drivers/virtio/virtio_net.h

diff --git a/drivers/virtio/Kconfig b/drivers/virtio/Kconfig
index 4f9a11b..e20dd69 100644
--- a/drivers/virtio/Kconfig
+++ b/drivers/virtio/Kconfig
@@ -29,4 +29,11 @@ config VIRTIO_MMIO
  This driver provides support for memory mapped virtio
  platform device driver.
 
+config VIRTIO_NET
+   bool "virtio net driver"
+   depends on VIRTIO
+   help
+ This is the virtual net driver for virtio. It can be used with
+ QEMU based targets.
+
 endmenu
diff --git a/drivers/virtio/Makefile b/drivers/virtio/Makefile
index 2e48785..b7764f1 100644
--- a/drivers/virtio/Makefile
+++ b/drivers/virtio/Makefile
@@ -5,3 +5,4 @@
 
 obj-y += virtio-uclass.o virtio_ring.o
 obj-$(CONFIG_VIRTIO_MMIO) += virtio_mmio.o
+obj-$(CONFIG_VIRTIO_NET) += virtio_net.o
diff --git a/drivers/virtio/virtio_net.c b/drivers/virtio/virtio_net.c
new file mode 100644
index 000..5bb6a9f
--- /dev/null
+++ b/drivers/virtio/virtio_net.c
@@ -0,0 +1,218 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2018, Tuomas Tynkkynen 
+ * Copyright (C) 2018, Bin Meng 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "virtio_net.h"
+
+/* Amount of buffers to keep in the RX virtqueue */
+#define VIRTIO_NET_NUM_RX_BUFS 32
+
+/*
+ * This value comes from the VirtIO spec: 1500 for maximum packet size,
+ * 14 for the Ethernet header, 12 for virtio_net_hdr. In total 1526 bytes.
+ */
+#define VIRTIO_NET_RX_BUF_SIZE 1526
+
+struct virtio_net_priv {
+   union {
+   struct virtqueue *vqs[2];
+   struct {
+   struct virtqueue *rx_vq;
+   struct virtqueue *tx_vq;
+   };
+   };
+
+   char rx_buff[VIRTIO_NET_NUM_RX_BUFS][VIRTIO_NET_RX_BUF_SIZE];
+   bool rx_running;
+};
+
+/*
+ * For simplicity, the driver only negotiates the VIRTIO_NET_F_MAC feature.
+ * For the VIRTIO_NET_F_STATUS feature, we don't negotiate it, hence per spec
+ * we should assume the link is always active.
+ */
+static const u32 feature[] = {
+   VIRTIO_NET_F_MAC
+};
+
+static const u32 feature_legacy[] = {
+   VIRTIO_NET_F_MAC
+};
+
+static int virtio_net_start(struct udevice *dev)
+{
+   struct virtio_net_priv *priv = dev_get_priv(dev);
+   struct virtio_sg sg;
+   struct virtio_sg *sgs[] = { &sg };
+   int i;
+
+   if (!priv->rx_running) {
+   /* receive buffer length is always 1526 */
+   sg.length = VIRTIO_NET_RX_BUF_SIZE;
+
+   /* setup the receive buffer address */
+   for (i = 0; i < VIRTIO_NET_NUM_RX_BUFS; i++) {
+   sg.addr = priv->rx_buff[i];
+   virtqueue_add(priv->rx_vq, sgs, 0, 1);
+   }
+
+   virtqueue_kick(priv->rx_vq);
+
+   /* setup the receive queue only once */
+   priv->rx_running = true;
+   }
+
+   return 0;
+}
+
+static int virtio_net_send(struct udevice *dev, void *packet, int length)
+{
+   struct virtio_net_priv *priv = dev_get_priv(dev);
+   struct virtio_net_hdr hdr;
+   struct virtio_sg hdr_sg = { &hdr, sizeof(hdr) };
+   struct virtio_sg data_sg = { packet, length };
+   struct virtio_sg *sgs[] = { &hdr_sg, &data_sg };
+   int ret;
+
+   memset(&hdr, 0, sizeof(struct virtio_net_hdr));
+
+   ret = virtqueue_add(priv->tx_vq, sgs, 2, 0);
+   if (ret)
+   return ret;
+
+   virtqueue_kick(priv->tx_vq);
+
+   while (1) {
+   if (virtqueue_get_buf(priv->tx_vq, NULL))
+   break;
+   }
+
+   return 0;
+}
+
+static int virtio_net_recv(struct udevice *dev, int flags, uchar **packetp)
+{
+   struct virtio_net_priv *priv = dev_get_priv(dev);
+   unsigned int len;
+   void *buf;
+
+   buf = virtqueue_get_buf(priv->rx_vq, &len);
+   if (!buf)
+   return -EAGAIN;
+
+   *packetp = buf + sizeof(struct virtio_net_hdr);
+   return len - sizeof(struct virtio_net_hdr);
+}
+
+static int virtio_net_free_pkt(struct udevice *dev, uchar *packet, int length)
+{
+   struct virtio_net_priv *priv = dev_get_priv(dev);
+   void *buf = packet - sizeof(struct virtio_net_hdr);
+   struct virtio_sg sg = { buf, VIRTIO_NET_RX_BUF_SIZE };
+   struct virtio_sg *sgs[] = { &sg };
+
+   /* Put the buffer back to the rx r

[U-Boot] [PATCH v3 06/31] virtio: Add virtio over mmio transport driver

2018-10-15 Thread Bin Meng
VirtIO can use various different buses and virtio devices are
commonly implemented as PCI devices. But virtual environments
without PCI support (a common situation in embedded devices
models) might use simple memory mapped device (“virtio-mmio”)
instead of the PCI device.

This adds a transport driver that implements UCLASS_VIRTIO for
virtio over mmio.

Signed-off-by: Tuomas Tynkkynen 
Signed-off-by: Bin Meng 
Reviewed-by: Simon Glass 
---

Changes in v3: None
Changes in v2: None

 drivers/virtio/Kconfig   |   7 +
 drivers/virtio/Makefile  |   1 +
 drivers/virtio/virtio_mmio.c | 413 +++
 drivers/virtio/virtio_mmio.h | 129 ++
 4 files changed, 550 insertions(+)
 create mode 100644 drivers/virtio/virtio_mmio.c
 create mode 100644 drivers/virtio/virtio_mmio.h

diff --git a/drivers/virtio/Kconfig b/drivers/virtio/Kconfig
index 82fc536..4f9a11b 100644
--- a/drivers/virtio/Kconfig
+++ b/drivers/virtio/Kconfig
@@ -22,4 +22,11 @@ config VIRTIO
  This option is selected by any driver which implements the virtio
  transport, such as CONFIG_VIRTIO_MMIO or CONFIG_VIRTIO_PCI.
 
+config VIRTIO_MMIO
+   bool "Platform bus driver for memory mapped virtio devices"
+   select VIRTIO
+   help
+ This driver provides support for memory mapped virtio
+ platform device driver.
+
 endmenu
diff --git a/drivers/virtio/Makefile b/drivers/virtio/Makefile
index 17d264a..2e48785 100644
--- a/drivers/virtio/Makefile
+++ b/drivers/virtio/Makefile
@@ -4,3 +4,4 @@
 # Copyright (C) 2018, Bin Meng 
 
 obj-y += virtio-uclass.o virtio_ring.o
+obj-$(CONFIG_VIRTIO_MMIO) += virtio_mmio.o
diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
new file mode 100644
index 000..7b73870
--- /dev/null
+++ b/drivers/virtio/virtio_mmio.c
@@ -0,0 +1,413 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2018, Tuomas Tynkkynen 
+ * Copyright (C) 2018, Bin Meng 
+ *
+ * VirtIO memory-maped I/O transport driver
+ * Ported from Linux drivers/virtio/virtio_mmio.c
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "virtio_mmio.h"
+
+static int virtio_mmio_get_config(struct udevice *udev, unsigned int offset,
+ void *buf, unsigned int len)
+{
+   struct virtio_mmio_priv *priv = dev_get_priv(udev);
+   void __iomem *base = priv->base + VIRTIO_MMIO_CONFIG;
+   u8 b;
+   __le16 w;
+   __le32 l;
+
+   if (priv->version == 1) {
+   u8 *ptr = buf;
+   int i;
+
+   for (i = 0; i < len; i++)
+   ptr[i] = readb(base + offset + i);
+
+   return 0;
+   }
+
+   switch (len) {
+   case 1:
+   b = readb(base + offset);
+   memcpy(buf, &b, sizeof(b));
+   break;
+   case 2:
+   w = cpu_to_le16(readw(base + offset));
+   memcpy(buf, &w, sizeof(w));
+   break;
+   case 4:
+   l = cpu_to_le32(readl(base + offset));
+   memcpy(buf, &l, sizeof(l));
+   break;
+   case 8:
+   l = cpu_to_le32(readl(base + offset));
+   memcpy(buf, &l, sizeof(l));
+   l = cpu_to_le32(readl(base + offset + sizeof(l)));
+   memcpy(buf + sizeof(l), &l, sizeof(l));
+   break;
+   default:
+   WARN_ON(true);
+   }
+
+   return 0;
+}
+
+static int virtio_mmio_set_config(struct udevice *udev, unsigned int offset,
+ const void *buf, unsigned int len)
+{
+   struct virtio_mmio_priv *priv = dev_get_priv(udev);
+   void __iomem *base = priv->base + VIRTIO_MMIO_CONFIG;
+   u8 b;
+   __le16 w;
+   __le32 l;
+
+   if (priv->version == 1) {
+   const u8 *ptr = buf;
+   int i;
+
+   for (i = 0; i < len; i++)
+   writeb(ptr[i], base + offset + i);
+
+   return 0;
+   }
+
+   switch (len) {
+   case 1:
+   memcpy(&b, buf, sizeof(b));
+   writeb(b, base + offset);
+   break;
+   case 2:
+   memcpy(&w, buf, sizeof(w));
+   writew(le16_to_cpu(w), base + offset);
+   break;
+   case 4:
+   memcpy(&l, buf, sizeof(l));
+   writel(le32_to_cpu(l), base + offset);
+   break;
+   case 8:
+   memcpy(&l, buf, sizeof(l));
+   writel(le32_to_cpu(l), base + offset);
+   memcpy(&l, buf + sizeof(l), sizeof(l));
+   writel(le32_to_cpu(l), base + offset + sizeof(l));
+   break;
+   default:
+   WARN_ON(true);
+   }
+
+   return 0;
+}
+
+static int virtio_mmio_generation(struct udevice *udev, u32 *counter)
+{
+   struct virtio_mmio_priv *priv = dev_get_priv(udev);
+
+   if (priv->version

[U-Boot] [PATCH v3 09/31] sandbox: blk: Switch to use platdata_auto_alloc_size for the driver data

2018-10-15 Thread Bin Meng
Currently the sandbox block driver uses priv_auto_alloc_size for
the driver data, however that's only available after the device
probe phase. In order to make it accessible in an earlier phase,
switch to use platdata_auto_alloc_size instead.

This patch is the prerequisite for the follow up patch of DM BLK
driver changes to work with Sandbox.

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

Changes in v3: None
Changes in v2: None

 drivers/block/sandbox.c | 15 ---
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/drivers/block/sandbox.c b/drivers/block/sandbox.c
index 0392437..576d049 100644
--- a/drivers/block/sandbox.c
+++ b/drivers/block/sandbox.c
@@ -33,7 +33,7 @@ static unsigned long host_block_read(struct udevice *dev,
 unsigned long start, lbaint_t blkcnt,
 void *buffer)
 {
-   struct host_block_dev *host_dev = dev_get_priv(dev);
+   struct host_block_dev *host_dev = dev_get_platdata(dev);
struct blk_desc *block_dev = dev_get_uclass_platdata(dev);
 
 #else
@@ -64,7 +64,7 @@ static unsigned long host_block_write(struct udevice *dev,
  unsigned long start, lbaint_t blkcnt,
  const void *buffer)
 {
-   struct host_block_dev *host_dev = dev_get_priv(dev);
+   struct host_block_dev *host_dev = dev_get_platdata(dev);
struct blk_desc *block_dev = dev_get_uclass_platdata(dev);
 #else
 static unsigned long host_block_write(struct blk_desc *block_dev,
@@ -131,16 +131,17 @@ int host_dev_bind(int devnum, char *filename)
os_lseek(fd, 0, OS_SEEK_END) / 512, &dev);
if (ret)
goto err_file;
+
+   host_dev = dev_get_platdata(dev);
+   host_dev->fd = fd;
+   host_dev->filename = fname;
+
ret = device_probe(dev);
if (ret) {
device_unbind(dev);
goto err_file;
}
 
-   host_dev = dev_get_priv(dev);
-   host_dev->fd = fd;
-   host_dev->filename = fname;
-
return blk_prepare_device(dev);
 err_file:
os_close(fd);
@@ -226,7 +227,7 @@ U_BOOT_DRIVER(sandbox_host_blk) = {
.name   = "sandbox_host_blk",
.id = UCLASS_BLK,
.ops= &sandbox_host_blk_ops,
-   .priv_auto_alloc_size   = sizeof(struct host_block_dev),
+   .platdata_auto_alloc_size = sizeof(struct host_block_dev),
 };
 #else
 U_BOOT_LEGACY_BLK(sandbox_host) = {
-- 
2.7.4

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 05/31] virtio: Add codes for virtual queue/ring management

2018-10-15 Thread Bin Meng
From: Tuomas Tynkkynen 

This adds support for managing virtual queue/ring, the channel
for high performance I/O between host and guest.

Signed-off-by: Tuomas Tynkkynen 
Signed-off-by: Bin Meng 
Reviewed-by: Simon Glass 
---

Changes in v3: None
Changes in v2: None

 drivers/virtio/Makefile  |   2 +-
 drivers/virtio/virtio_ring.c | 358 +++
 include/virtio_ring.h| 320 ++
 3 files changed, 679 insertions(+), 1 deletion(-)
 create mode 100644 drivers/virtio/virtio_ring.c
 create mode 100644 include/virtio_ring.h

diff --git a/drivers/virtio/Makefile b/drivers/virtio/Makefile
index 23e7be7..17d264a 100644
--- a/drivers/virtio/Makefile
+++ b/drivers/virtio/Makefile
@@ -3,4 +3,4 @@
 # Copyright (C) 2018, Tuomas Tynkkynen 
 # Copyright (C) 2018, Bin Meng 
 
-obj-y += virtio-uclass.o
+obj-y += virtio-uclass.o virtio_ring.o
diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
new file mode 100644
index 000..0eeb350
--- /dev/null
+++ b/drivers/virtio/virtio_ring.c
@@ -0,0 +1,358 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2018, Tuomas Tynkkynen 
+ * Copyright (C) 2018, Bin Meng 
+ *
+ * virtio ring implementation
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+int virtqueue_add(struct virtqueue *vq, struct virtio_sg *sgs[],
+ unsigned int out_sgs, unsigned int in_sgs)
+{
+   struct vring_desc *desc;
+   unsigned int total_sg = out_sgs + in_sgs;
+   unsigned int i, n, avail, descs_used, uninitialized_var(prev);
+   int head;
+
+   WARN_ON(total_sg == 0);
+
+   head = vq->free_head;
+
+   desc = vq->vring.desc;
+   i = head;
+   descs_used = total_sg;
+
+   if (vq->num_free < descs_used) {
+   debug("Can't add buf len %i - avail = %i\n",
+ descs_used, vq->num_free);
+   /*
+* FIXME: for historical reasons, we force a notify here if
+* there are outgoing parts to the buffer.  Presumably the
+* host should service the ring ASAP.
+*/
+   if (out_sgs)
+   virtio_notify(vq->vdev, vq);
+   return -ENOSPC;
+   }
+
+   for (n = 0; n < out_sgs; n++) {
+   struct virtio_sg *sg = sgs[n];
+
+   desc[i].flags = cpu_to_virtio16(vq->vdev, VRING_DESC_F_NEXT);
+   desc[i].addr = cpu_to_virtio64(vq->vdev, (u64)(size_t)sg->addr);
+   desc[i].len = cpu_to_virtio32(vq->vdev, sg->length);
+
+   prev = i;
+   i = virtio16_to_cpu(vq->vdev, desc[i].next);
+   }
+   for (; n < (out_sgs + in_sgs); n++) {
+   struct virtio_sg *sg = sgs[n];
+
+   desc[i].flags = cpu_to_virtio16(vq->vdev, VRING_DESC_F_NEXT |
+   VRING_DESC_F_WRITE);
+   desc[i].addr = cpu_to_virtio64(vq->vdev,
+  (u64)(uintptr_t)sg->addr);
+   desc[i].len = cpu_to_virtio32(vq->vdev, sg->length);
+
+   prev = i;
+   i = virtio16_to_cpu(vq->vdev, desc[i].next);
+   }
+   /* Last one doesn't continue */
+   desc[prev].flags &= cpu_to_virtio16(vq->vdev, ~VRING_DESC_F_NEXT);
+
+   /* We're using some buffers from the free list. */
+   vq->num_free -= descs_used;
+
+   /* Update free pointer */
+   vq->free_head = i;
+
+   /*
+* Put entry in available array (but don't update avail->idx
+* until they do sync).
+*/
+   avail = vq->avail_idx_shadow & (vq->vring.num - 1);
+   vq->vring.avail->ring[avail] = cpu_to_virtio16(vq->vdev, head);
+
+   /*
+* Descriptors and available array need to be set before we expose the
+* new available array entries.
+*/
+   virtio_wmb();
+   vq->avail_idx_shadow++;
+   vq->vring.avail->idx = cpu_to_virtio16(vq->vdev, vq->avail_idx_shadow);
+   vq->num_added++;
+
+   /*
+* This is very unlikely, but theoretically possible.
+* Kick just in case.
+*/
+   if (unlikely(vq->num_added == (1 << 16) - 1))
+   virtqueue_kick(vq);
+
+   return 0;
+}
+
+static bool virtqueue_kick_prepare(struct virtqueue *vq)
+{
+   u16 new, old;
+   bool needs_kick;
+
+   /*
+* We need to expose available array entries before checking
+* avail event.
+*/
+   virtio_mb();
+
+   old = vq->avail_idx_shadow - vq->num_added;
+   new = vq->avail_idx_shadow;
+   vq->num_added = 0;
+
+   if (vq->event) {
+   needs_kick = vring_need_event(virtio16_to_cpu(vq->vdev,
+   vring_avail_event(&vq->vring)), new, old);
+   } else {
+   needs_kick = !(vq->vring.used->flags & cpu_to_virtio16(vq->vdev,
+   VRING

[U-Boot] [PATCH v3 04/31] dm: Add a new uclass driver for VirtIO transport devices

2018-10-15 Thread Bin Meng
This adds a new virtio uclass driver for “virtio” [1] family of
devices that are are found in virtual environments like QEMU,
yet by design they look like physical devices to the guest.

The uclass driver provides child_pre_probe() and child_post_probe()
methods to do some common operations for virtio device drivers like
device and driver supported feature negotiation, etc.

[1] http://docs.oasis-open.org/virtio/virtio/v1.0/virtio-v1.0.pdf

Signed-off-by: Tuomas Tynkkynen 
Signed-off-by: Bin Meng 

---

Changes in v3: None
Changes in v2:
- Added virtio spec link and a short statement of what virtio is
  in the header and source files
- Changed to use 'transport' over 'bus' in drivers/virtio/Kconfig
- Added UCLASS_VIRTIO ID in alphabetical order
- Moved the header file inclusion from virtio.h to C file
- Fixed code styling issue (blank line before return) in
  virtio_xxx() APIs
- Changed virtio_init() to return int if there is an error
- Added virtio_uclass_pre_probe() to check virtio transport driver
  ops here so that we don't need check these ops each time when
  the virtio_xxx APIs are called
- Implemented child_post_remove() method to reset the virtio device
- Changed virtio_driver_features_init() parameter 'feature' and
  'feature_legacy' to const, and adjust member of
  'struct virtio_dev_priv' accordingly
- Initialize uc_priv->vqs in virtio_uclass_post_probe()

 drivers/Kconfig|   2 +
 drivers/Makefile   |   1 +
 drivers/virtio/Kconfig |  25 ++
 drivers/virtio/Makefile|   6 +
 drivers/virtio/virtio-uclass.c | 369 +
 include/dm/uclass-id.h |   1 +
 include/virtio.h   | 707 +
 include/virtio_types.h |  24 ++
 8 files changed, 1135 insertions(+)
 create mode 100644 drivers/virtio/Kconfig
 create mode 100644 drivers/virtio/Makefile
 create mode 100644 drivers/virtio/virtio-uclass.c
 create mode 100644 include/virtio.h
 create mode 100644 include/virtio_types.h

diff --git a/drivers/Kconfig b/drivers/Kconfig
index 927a2b8..4ac823d 100644
--- a/drivers/Kconfig
+++ b/drivers/Kconfig
@@ -112,6 +112,8 @@ source "drivers/usb/Kconfig"
 
 source "drivers/video/Kconfig"
 
+source "drivers/virtio/Kconfig"
+
 source "drivers/w1/Kconfig"
 
 source "drivers/w1-eeprom/Kconfig"
diff --git a/drivers/Makefile b/drivers/Makefile
index fb38b67..4453c62 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -14,6 +14,7 @@ obj-$(CONFIG_$(SPL_TPL_)SERIAL_SUPPORT) += serial/
 obj-$(CONFIG_$(SPL_TPL_)SPI_FLASH_SUPPORT) += mtd/spi/
 obj-$(CONFIG_$(SPL_TPL_)SPI_SUPPORT) += spi/
 obj-$(CONFIG_$(SPL_TPL_)TIMER) += timer/
+obj-$(CONFIG_$(SPL_TPL_)VIRTIO) += virtio/
 obj-$(CONFIG_$(SPL_)DM_MAILBOX) += mailbox/
 obj-$(CONFIG_$(SPL_)REMOTEPROC) += remoteproc/
 
diff --git a/drivers/virtio/Kconfig b/drivers/virtio/Kconfig
new file mode 100644
index 000..82fc536
--- /dev/null
+++ b/drivers/virtio/Kconfig
@@ -0,0 +1,25 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Copyright (C) 2018, Tuomas Tynkkynen 
+# Copyright (C) 2018, Bin Meng 
+#
+# VirtIO is a virtualization standard for network and disk device drivers
+# where just the guest's device driver "knows" it is running in a virtual
+# environment, and cooperates with the hypervisor. This enables guests to
+# get high performance network and disk operations, and gives most of the
+# performance benefits of paravirtualization. In the U-Boot case, the guest
+# is U-Boot itself, while the virtual environment are normally QEMU targets
+# like ARM, RISC-V and x86.
+#
+# See http://docs.oasis-open.org/virtio/virtio/v1.0/virtio-v1.0.pdf for
+# the VirtIO specification v1.0.
+
+menu "VirtIO Drivers"
+
+config VIRTIO
+   bool
+   help
+ This option is selected by any driver which implements the virtio
+ transport, such as CONFIG_VIRTIO_MMIO or CONFIG_VIRTIO_PCI.
+
+endmenu
diff --git a/drivers/virtio/Makefile b/drivers/virtio/Makefile
new file mode 100644
index 000..23e7be7
--- /dev/null
+++ b/drivers/virtio/Makefile
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Copyright (C) 2018, Tuomas Tynkkynen 
+# Copyright (C) 2018, Bin Meng 
+
+obj-y += virtio-uclass.o
diff --git a/drivers/virtio/virtio-uclass.c b/drivers/virtio/virtio-uclass.c
new file mode 100644
index 000..34397d7
--- /dev/null
+++ b/drivers/virtio/virtio-uclass.c
@@ -0,0 +1,369 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2018, Tuomas Tynkkynen 
+ * Copyright (C) 2018, Bin Meng 
+ *
+ * VirtIO is a virtualization standard for network and disk device drivers
+ * where just the guest's device driver "knows" it is running in a virtual
+ * environment, and cooperates with the hypervisor. This enables guests to
+ * get high performance network and disk operations, and gives most of the
+ * performance benefits of paravirtualization. In the U-Boot case, the guest
+ * is U-Boot itself, while the virtual environment are normally QEMU targets
+ * 

[U-Boot] [PATCH v3 13/31] blk: Make blk_next_free_devnum() public

2018-10-15 Thread Bin Meng
blk_next_free_devnum() can be helpful in some cases. Make it
a public API.

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

Changes in v3: None
Changes in v2: None

 drivers/block/blk-uclass.c |  2 +-
 include/blk.h  | 11 +++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c
index 3f00ff8..76ee3db 100644
--- a/drivers/block/blk-uclass.c
+++ b/drivers/block/blk-uclass.c
@@ -517,7 +517,7 @@ int blk_find_max_devnum(enum if_type if_type)
return max_devnum;
 }
 
-static int blk_next_free_devnum(enum if_type if_type)
+int blk_next_free_devnum(enum if_type if_type)
 {
int ret;
 
diff --git a/include/blk.h b/include/blk.h
index c243179..5e94f0e 100644
--- a/include/blk.h
+++ b/include/blk.h
@@ -379,6 +379,17 @@ int blk_unbind_all(int if_type);
 int blk_find_max_devnum(enum if_type if_type);
 
 /**
+ * blk_next_free_devnum() - get the next device number for an interface type
+ *
+ * Finds the next number that is safe to use for a newly allocated device for
+ * an interface type @if_type.
+ *
+ * @if_type:   Interface type to scan
+ * @return next device number safe to use, or -ve on error
+ */
+int blk_next_free_devnum(enum if_type if_type);
+
+/**
  * blk_select_hwpart() - select a hardware partition
  *
  * Select a hardware partition if the device supports it (typically MMC does)
-- 
2.7.4

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 11/31] blk: Call part_init() in the post_probe() method

2018-10-15 Thread Bin Meng
part_init() is currently called in every DM BLK driver, either
in its bind() or probe() method. However we can use the BLK
uclass driver's post_probe() method to do it automatically.

Update all DM BLK drivers to adopt this change.

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

Changes in v3: None
Changes in v2: None

 cmd/sata.c|  9 -
 common/usb_storage.c  |  4 +---
 drivers/block/blk-uclass.c| 12 
 drivers/block/ide.c   |  2 --
 drivers/block/sandbox.c   |  2 +-
 drivers/mmc/mmc.c |  3 ---
 drivers/nvme/nvme.c   |  1 -
 drivers/scsi/scsi.c   |  1 -
 lib/efi_driver/efi_block_device.c |  2 --
 9 files changed, 14 insertions(+), 22 deletions(-)

diff --git a/cmd/sata.c b/cmd/sata.c
index 4f0c6e0..6d62ba8 100644
--- a/cmd/sata.c
+++ b/cmd/sata.c
@@ -51,7 +51,6 @@ int sata_probe(int devnum)
 {
 #ifdef CONFIG_AHCI
struct udevice *dev;
-   struct udevice *blk;
int rc;
 
rc = uclass_get_device(UCLASS_AHCI, devnum, &dev);
@@ -67,14 +66,6 @@ int sata_probe(int devnum)
return CMD_RET_FAILURE;
}
 
-   rc = blk_get_from_parent(dev, &blk);
-   if (!rc) {
-   struct blk_desc *desc = dev_get_uclass_platdata(blk);
-
-   if (desc->lba > 0 && desc->blksz > 0)
-   part_init(desc);
-   }
-
return 0;
 #else
return sata_initialize() < 0 ? CMD_RET_FAILURE : CMD_RET_SUCCESS;
diff --git a/common/usb_storage.c b/common/usb_storage.c
index d92ebb6..560d605 100644
--- a/common/usb_storage.c
+++ b/common/usb_storage.c
@@ -226,9 +226,7 @@ static int usb_stor_probe_device(struct usb_device *udev)
blkdev->lun = lun;
 
ret = usb_stor_get_info(udev, data, blkdev);
-   if (ret == 1)
-   ret = blk_prepare_device(dev);
-   if (!ret) {
+   if (ret == 1) {
usb_max_devs++;
debug("%s: Found device %p\n", __func__, udev);
} else {
diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c
index facf527..95e7b54 100644
--- a/drivers/block/blk-uclass.c
+++ b/drivers/block/blk-uclass.c
@@ -644,8 +644,20 @@ int blk_unbind_all(int if_type)
return 0;
 }
 
+static int blk_post_probe(struct udevice *dev)
+{
+#if !defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_LIBDISK_SUPPORT)
+   struct blk_desc *desc = dev_get_uclass_platdata(dev);
+
+   part_init(desc);
+#endif
+
+   return 0;
+}
+
 UCLASS_DRIVER(blk) = {
.id = UCLASS_BLK,
.name   = "blk",
+   .post_probe = blk_post_probe,
.per_device_platdata_auto_alloc_size = sizeof(struct blk_desc),
 };
diff --git a/drivers/block/ide.c b/drivers/block/ide.c
index 38adb6a..4b8a4ea 100644
--- a/drivers/block/ide.c
+++ b/drivers/block/ide.c
@@ -1169,8 +1169,6 @@ static int ide_blk_probe(struct udevice *udev)
BLK_REV_SIZE);
desc->revision[BLK_REV_SIZE] = '\0';
 
-   part_init(desc);
-
return 0;
 }
 
diff --git a/drivers/block/sandbox.c b/drivers/block/sandbox.c
index 576d049..d3b1aaa 100644
--- a/drivers/block/sandbox.c
+++ b/drivers/block/sandbox.c
@@ -142,7 +142,7 @@ int host_dev_bind(int devnum, char *filename)
goto err_file;
}
 
-   return blk_prepare_device(dev);
+   return 0;
 err_file:
os_close(fd);
 err:
diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
index 585951c..d6b9cdc 100644
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -2444,9 +2444,6 @@ static int mmc_startup(struct mmc *mmc)
bdesc->product[0] = 0;
bdesc->revision[0] = 0;
 #endif
-#if !defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_LIBDISK_SUPPORT)
-   part_init(bdesc);
-#endif
 
return 0;
 }
diff --git a/drivers/nvme/nvme.c b/drivers/nvme/nvme.c
index eb6fded..1ee0a0a 100644
--- a/drivers/nvme/nvme.c
+++ b/drivers/nvme/nvme.c
@@ -664,7 +664,6 @@ static int nvme_blk_probe(struct udevice *udev)
sprintf(desc->vendor, "0x%.4x", pplat->vendor);
memcpy(desc->product, ndev->serial, sizeof(ndev->serial));
memcpy(desc->revision, ndev->firmware_rev, sizeof(ndev->firmware_rev));
-   part_init(desc);
 
return 0;
 }
diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
index bc6ac8c..df47e2f 100644
--- a/drivers/scsi/scsi.c
+++ b/drivers/scsi/scsi.c
@@ -592,7 +592,6 @@ static int do_scsi_scan_one(struct udevice *dev, int id, 
int lun, bool verbose)
memcpy(&bdesc->vendor, &bd.vendor, sizeof(bd.vendor));
memcpy(&bdesc->product, &bd.product, sizeof(bd.product));
memcpy(&bdesc->revision, &bd.revision,  sizeof(bd.revision));
-   part_init(bdesc);
 
if (verbose) {
printf("  Device %d: ", 0);
diff --git a/lib/efi_driver/efi_block_device.c 
b/lib/efi_driver/efi_block_device.c
index 7b71b4d..

[U-Boot] [PATCH v3 14/31] blk: Introduce IF_TYPE_VIRTIO

2018-10-15 Thread Bin Meng
From: Tuomas Tynkkynen 

This adds a new block interface type for VirtIO block devices.

Signed-off-by: Tuomas Tynkkynen 
Signed-off-by: Bin Meng 
Reviewed-by: Simon Glass 
---

Changes in v3: None
Changes in v2: None

 disk/part.c| 6 ++
 drivers/block/blk-uclass.c | 2 ++
 include/blk.h  | 1 +
 3 files changed, 9 insertions(+)

diff --git a/disk/part.c b/disk/part.c
index 9e457a6..f30f9e9 100644
--- a/disk/part.c
+++ b/disk/part.c
@@ -150,6 +150,9 @@ void dev_print (struct blk_desc *dev_desc)
dev_desc->revision,
dev_desc->product);
break;
+   case IF_TYPE_VIRTIO:
+   printf("%s VirtIO Block Device\n", dev_desc->vendor);
+   break;
case IF_TYPE_DOC:
puts("device type DOC\n");
return;
@@ -281,6 +284,9 @@ static void print_part_header(const char *type, struct 
blk_desc *dev_desc)
case IF_TYPE_NVME:
puts ("NVMe");
break;
+   case IF_TYPE_VIRTIO:
+   puts("VirtIO");
+   break;
default:
puts ("UNKNOWN");
break;
diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c
index 76ee3db..65a766e 100644
--- a/drivers/block/blk-uclass.c
+++ b/drivers/block/blk-uclass.c
@@ -23,6 +23,7 @@ static const char *if_typename_str[IF_TYPE_COUNT] = {
[IF_TYPE_HOST]  = "host",
[IF_TYPE_NVME]  = "nvme",
[IF_TYPE_EFI]   = "efi",
+   [IF_TYPE_VIRTIO]= "virtio",
 };
 
 static enum uclass_id if_type_uclass_id[IF_TYPE_COUNT] = {
@@ -37,6 +38,7 @@ static enum uclass_id if_type_uclass_id[IF_TYPE_COUNT] = {
[IF_TYPE_HOST]  = UCLASS_ROOT,
[IF_TYPE_NVME]  = UCLASS_NVME,
[IF_TYPE_EFI]   = UCLASS_EFI,
+   [IF_TYPE_VIRTIO]= UCLASS_VIRTIO,
 };
 
 static enum if_type if_typename_to_iftype(const char *if_typename)
diff --git a/include/blk.h b/include/blk.h
index 5e94f0e..d0c033a 100644
--- a/include/blk.h
+++ b/include/blk.h
@@ -33,6 +33,7 @@ enum if_type {
IF_TYPE_HOST,
IF_TYPE_NVME,
IF_TYPE_EFI,
+   IF_TYPE_VIRTIO,
 
IF_TYPE_COUNT,  /* Number of interface types */
 };
-- 
2.7.4

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 16/31] virtio: cmd: Add virtio command for virtio devices

2018-10-15 Thread Bin Meng
From: Tuomas Tynkkynen 

Add 'virtio' command in U-Boot command line.

Signed-off-by: Tuomas Tynkkynen 
Signed-off-by: Bin Meng 
Reviewed-by: Simon Glass 
---

Changes in v3: None
Changes in v2: None

 cmd/Kconfig  |  7 +++
 cmd/Makefile |  1 +
 cmd/virtio.c | 38 ++
 3 files changed, 46 insertions(+)
 create mode 100644 cmd/virtio.c

diff --git a/cmd/Kconfig b/cmd/Kconfig
index 7ed3c9c..2fbdb17 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -1065,6 +1065,13 @@ config CMD_USB_MASS_STORAGE
help
  USB mass storage support
 
+config CMD_VIRTIO
+   bool "virtio"
+   depends on VIRTIO
+   default y if VIRTIO
+   help
+ VirtIO block device support
+
 config CMD_AXI
bool "axi"
depends on AXI
diff --git a/cmd/Makefile b/cmd/Makefile
index d9cdaf6..2e27514 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -136,6 +136,7 @@ obj-$(CONFIG_CMD_UBI) += ubi.o
 obj-$(CONFIG_CMD_UBIFS) += ubifs.o
 obj-$(CONFIG_CMD_UNIVERSE) += universe.o
 obj-$(CONFIG_CMD_UNZIP) += unzip.o
+obj-$(CONFIG_CMD_VIRTIO) += virtio.o
 obj-$(CONFIG_CMD_LZMADEC) += lzmadec.o
 
 obj-$(CONFIG_CMD_USB) += usb.o disk.o
diff --git a/cmd/virtio.c b/cmd/virtio.c
new file mode 100644
index 000..b7082bc
--- /dev/null
+++ b/cmd/virtio.c
@@ -0,0 +1,38 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2018, Tuomas Tynkkynen 
+ * Copyright (C) 2018, Bin Meng 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static int virtio_curr_dev;
+
+static int do_virtio(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+   if (argc == 2 && !strcmp(argv[1], "scan")) {
+   /* make sure all virtio devices are enumerated */
+   virtio_init();
+
+   return CMD_RET_SUCCESS;
+   }
+
+   return blk_common_cmd(argc, argv, IF_TYPE_VIRTIO, &virtio_curr_dev);
+}
+
+U_BOOT_CMD(
+   virtio, 8, 1, do_virtio,
+   "virtio block devices sub-system",
+   "scan - initialize virtio bus\n"
+   "virtio info - show all available virtio block devices\n"
+   "virtio device [dev] - show or set current virtio block device\n"
+   "virtio part [dev] - print partition table of one or all virtio block 
devices\n"
+   "virtio read addr blk# cnt - read `cnt' blocks starting at block\n"
+   " `blk#' to memory address `addr'\n"
+   "virtio write addr blk# cnt - write `cnt' blocks starting at block\n"
+   " `blk#' from memory address `addr'"
+);
-- 
2.7.4

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 15/31] virtio: Add block driver support

2018-10-15 Thread Bin Meng
From: Tuomas Tynkkynen 

This adds virtio block device driver support.

Signed-off-by: Tuomas Tynkkynen 
Signed-off-by: Bin Meng 
Reviewed-by: Simon Glass 

---

Changes in v3: None
Changes in v2:
- Correct desc->vendor for PCI transport

 drivers/virtio/Kconfig  |   7 +++
 drivers/virtio/Makefile |   1 +
 drivers/virtio/virtio_blk.c | 137 
 drivers/virtio/virtio_blk.h | 129 +
 4 files changed, 274 insertions(+)
 create mode 100644 drivers/virtio/virtio_blk.c
 create mode 100644 drivers/virtio/virtio_blk.h

diff --git a/drivers/virtio/Kconfig b/drivers/virtio/Kconfig
index e20dd69..b72477a 100644
--- a/drivers/virtio/Kconfig
+++ b/drivers/virtio/Kconfig
@@ -36,4 +36,11 @@ config VIRTIO_NET
  This is the virtual net driver for virtio. It can be used with
  QEMU based targets.
 
+config VIRTIO_BLK
+   bool "virtio block driver"
+   depends on VIRTIO
+   help
+ This is the virtual block driver for virtio. It can be used with
+ QEMU based targets.
+
 endmenu
diff --git a/drivers/virtio/Makefile b/drivers/virtio/Makefile
index b7764f1..5fe7428 100644
--- a/drivers/virtio/Makefile
+++ b/drivers/virtio/Makefile
@@ -6,3 +6,4 @@
 obj-y += virtio-uclass.o virtio_ring.o
 obj-$(CONFIG_VIRTIO_MMIO) += virtio_mmio.o
 obj-$(CONFIG_VIRTIO_NET) += virtio_net.o
+obj-$(CONFIG_VIRTIO_BLK) += virtio_blk.o
diff --git a/drivers/virtio/virtio_blk.c b/drivers/virtio/virtio_blk.c
new file mode 100644
index 000..e793e34
--- /dev/null
+++ b/drivers/virtio/virtio_blk.c
@@ -0,0 +1,137 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2018, Tuomas Tynkkynen 
+ * Copyright (C) 2018, Bin Meng 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "virtio_blk.h"
+
+struct virtio_blk_priv {
+   struct virtqueue *vq;
+};
+
+static ulong virtio_blk_do_req(struct udevice *dev, u64 sector,
+  lbaint_t blkcnt, void *buffer, u32 type)
+{
+   struct virtio_blk_priv *priv = dev_get_priv(dev);
+   unsigned int num_out = 0, num_in = 0;
+   struct virtio_sg *sgs[3];
+   u8 status;
+   int ret;
+
+   struct virtio_blk_outhdr out_hdr = {
+   .type = cpu_to_virtio32(dev, type),
+   .sector = cpu_to_virtio64(dev, sector),
+   };
+   struct virtio_sg hdr_sg = { &out_hdr, sizeof(out_hdr) };
+   struct virtio_sg data_sg = { buffer, blkcnt * 512 };
+   struct virtio_sg status_sg = { &status, sizeof(status) };
+
+   sgs[num_out++] = &hdr_sg;
+
+   if (type & VIRTIO_BLK_T_OUT)
+   sgs[num_out++] = &data_sg;
+   else
+   sgs[num_out + num_in++] = &data_sg;
+
+   sgs[num_out + num_in++] = &status_sg;
+
+   ret = virtqueue_add(priv->vq, sgs, num_out, num_in);
+   if (ret)
+   return ret;
+
+   virtqueue_kick(priv->vq);
+
+   while (!virtqueue_get_buf(priv->vq, NULL))
+   ;
+
+   return status == VIRTIO_BLK_S_OK ? blkcnt : -EIO;
+}
+
+static ulong virtio_blk_read(struct udevice *dev, lbaint_t start,
+lbaint_t blkcnt, void *buffer)
+{
+   return virtio_blk_do_req(dev, start, blkcnt, buffer,
+VIRTIO_BLK_T_IN);
+}
+
+static ulong virtio_blk_write(struct udevice *dev, lbaint_t start,
+ lbaint_t blkcnt, const void *buffer)
+{
+   return virtio_blk_do_req(dev, start, blkcnt, (void *)buffer,
+VIRTIO_BLK_T_OUT);
+}
+
+static int virtio_blk_bind(struct udevice *dev)
+{
+   struct virtio_dev_priv *uc_priv = dev_get_uclass_priv(dev->parent);
+   struct blk_desc *desc = dev_get_uclass_platdata(dev);
+   int devnum;
+
+   desc->if_type = IF_TYPE_VIRTIO;
+   /*
+* Initialize the devnum to -ENODEV. This is to make sure that
+* blk_next_free_devnum() works as expected, since the default
+* value 0 is a valid devnum.
+*/
+   desc->devnum = -ENODEV;
+   devnum = blk_next_free_devnum(IF_TYPE_VIRTIO);
+   if (devnum < 0)
+   return devnum;
+   desc->devnum = devnum;
+   desc->part_type = PART_TYPE_UNKNOWN;
+   /*
+* virtio mmio transport supplies string identification for us,
+* while pci trnasport uses a 2-byte subvendor value.
+*/
+   if (uc_priv->vendor >> 16)
+   sprintf(desc->vendor, "%s", (char *)&uc_priv->vendor);
+   else
+   sprintf(desc->vendor, "%04x", uc_priv->vendor);
+   desc->bdev = dev;
+
+   /* Indicate what driver features we support */
+   virtio_driver_features_init(uc_priv, NULL, 0, NULL, 0);
+
+   return 0;
+}
+
+static int virtio_blk_probe(struct udevice *dev)
+{
+   struct virtio_blk_priv *priv = dev_get_priv(dev);
+   struct blk_desc *desc = dev_get_uclass_platdata(dev);
+   u64 cap;
+   int ret;
+
+   

[U-Boot] [PATCH v3 12/31] blk: Drop blk_prepare_device()

2018-10-15 Thread Bin Meng
With the post_probe() changes, this API is no longer needed.

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

Changes in v3: None
Changes in v2: None

 drivers/block/blk-uclass.c |  9 -
 include/blk.h  | 10 --
 2 files changed, 19 deletions(-)

diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c
index 95e7b54..3f00ff8 100644
--- a/drivers/block/blk-uclass.c
+++ b/drivers/block/blk-uclass.c
@@ -471,15 +471,6 @@ unsigned long blk_derase(struct blk_desc *block_dev, 
lbaint_t start,
return ops->erase(dev, start, blkcnt);
 }
 
-int blk_prepare_device(struct udevice *dev)
-{
-   struct blk_desc *desc = dev_get_uclass_platdata(dev);
-
-   part_init(desc);
-
-   return 0;
-}
-
 int blk_get_from_parent(struct udevice *parent, struct udevice **devp)
 {
struct udevice *dev;
diff --git a/include/blk.h b/include/blk.h
index 6af2196..c243179 100644
--- a/include/blk.h
+++ b/include/blk.h
@@ -357,16 +357,6 @@ int blk_create_devicef(struct udevice *parent, const char 
*drv_name,
   lbaint_t lba, struct udevice **devp);
 
 /**
- * blk_prepare_device() - Prepare a block device for use
- *
- * This reads partition information from the device if supported.
- *
- * @dev:   Device to prepare
- * @return 0 if ok, -ve on error
- */
-int blk_prepare_device(struct udevice *dev);
-
-/**
  * blk_unbind_all() - Unbind all device of the given interface type
  *
  * The devices are removed and then unbound.
-- 
2.7.4

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 10/31] efi_driver: blk: Switch to use platdata_auto_alloc_size for the driver data

2018-10-15 Thread Bin Meng
Currently the efi block driver uses priv_auto_alloc_size for the
driver data, however that's only available after the device probe
phase. In order to make it accessible in an earlier phase, switch
to use platdata_auto_alloc_size instead.

This patch is the prerequisite for the follow up patch of DM BLK
driver changes to work with EFI loader.

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

Changes in v3: None
Changes in v2: None

 lib/efi_driver/efi_block_device.c | 24 
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/lib/efi_driver/efi_block_device.c 
b/lib/efi_driver/efi_block_device.c
index 5b9c139..7b71b4d 100644
--- a/lib/efi_driver/efi_block_device.c
+++ b/lib/efi_driver/efi_block_device.c
@@ -38,7 +38,7 @@
  * handle  handle of the controller on which this driver is installed
  * io  block io protocol proxied by this driver
  */
-struct efi_blk_priv {
+struct efi_blk_platdata {
efi_handle_thandle;
struct efi_block_io *io;
 };
@@ -55,8 +55,8 @@ struct efi_blk_priv {
 static ulong efi_bl_read(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt,
 void *buffer)
 {
-   struct efi_blk_priv *priv = dev->priv;
-   struct efi_block_io *io = priv->io;
+   struct efi_blk_platdata *platdata = dev_get_platdata(dev);
+   struct efi_block_io *io = platdata->io;
efi_status_t ret;
 
EFI_PRINT("%s: read '%s', from block " LBAFU ", " LBAFU " blocks\n",
@@ -84,8 +84,8 @@ static ulong efi_bl_read(struct udevice *dev, lbaint_t blknr, 
lbaint_t blkcnt,
 static ulong efi_bl_write(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt,
  const void *buffer)
 {
-   struct efi_blk_priv *priv = dev->priv;
-   struct efi_block_io *io = priv->io;
+   struct efi_blk_platdata *platdata = dev_get_platdata(dev);
+   struct efi_block_io *io = platdata->io;
efi_status_t ret;
 
EFI_PRINT("%s: write '%s', from block " LBAFU ", " LBAFU " blocks\n",
@@ -135,7 +135,7 @@ static int efi_bl_bind(efi_handle_t handle, void *interface)
struct efi_object *obj = efi_search_obj(handle);
struct efi_block_io *io = interface;
int disks;
-   struct efi_blk_priv *priv;
+   struct efi_blk_platdata *platdata;
 
EFI_PRINT("%s: handle %p, interface %p\n", __func__, handle, io);
 
@@ -163,16 +163,16 @@ static int efi_bl_bind(efi_handle_t handle, void 
*interface)
return -ENOENT;
/* Set the DM_FLAG_NAME_ALLOCED flag to avoid a memory leak */
device_set_name_alloced(bdev);
-   /* Allocate priv */
+
+   platdata = dev_get_platdata(bdev);
+   platdata->handle = handle;
+   platdata->io = interface;
+
ret = device_probe(bdev);
if (ret)
return ret;
EFI_PRINT("%s: block device '%s' created\n", __func__, bdev->name);
 
-   priv = bdev->priv;
-   priv->handle = handle;
-   priv->io = interface;
-
ret = blk_prepare_device(bdev);
 
/* Create handles for the partions of the block device */
@@ -193,7 +193,7 @@ U_BOOT_DRIVER(efi_blk) = {
.name   = "efi_blk",
.id = UCLASS_BLK,
.ops= &efi_blk_ops,
-   .priv_auto_alloc_size   = sizeof(struct efi_blk_priv),
+   .platdata_auto_alloc_size = sizeof(struct efi_blk_platdata),
 };
 
 /* EFI driver operators */
-- 
2.7.4

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 29/31] virtio: Add a Sandbox transport driver

2018-10-15 Thread Bin Meng
This driver provides support for Sandbox implementation of virtio
transport driver which is used for testing purpose only.

Two drivers are provided. The 2nd one is a driver that lacks the
'notify' op.

Signed-off-by: Bin Meng 

---

Changes in v3: None
Changes in v2:
- new patch to add a Sandbox transport driver

 drivers/virtio/Kconfig  |   8 ++
 drivers/virtio/Makefile |   1 +
 drivers/virtio/virtio_sandbox.c | 233 
 3 files changed, 242 insertions(+)
 create mode 100644 drivers/virtio/virtio_sandbox.c

diff --git a/drivers/virtio/Kconfig b/drivers/virtio/Kconfig
index 753912f..a9d5fd0 100644
--- a/drivers/virtio/Kconfig
+++ b/drivers/virtio/Kconfig
@@ -37,6 +37,14 @@ config VIRTIO_PCI
  This driver provides support for virtio based paravirtual device
  drivers over PCI.
 
+config VIRTIO_SANDBOX
+   bool "Sandbox driver for virtio devices"
+   depends on SANDBOX
+   select VIRTIO
+   help
+ This driver provides support for Sandbox implementation of virtio
+ transport driver which is used for testing purpose only.
+
 config VIRTIO_NET
bool "virtio net driver"
depends on VIRTIO
diff --git a/drivers/virtio/Makefile b/drivers/virtio/Makefile
index 072fb56..4579044 100644
--- a/drivers/virtio/Makefile
+++ b/drivers/virtio/Makefile
@@ -6,5 +6,6 @@
 obj-y += virtio-uclass.o virtio_ring.o
 obj-$(CONFIG_VIRTIO_MMIO) += virtio_mmio.o
 obj-$(CONFIG_VIRTIO_PCI) += virtio_pci_legacy.o virtio_pci_modern.o
+obj-$(CONFIG_VIRTIO_SANDBOX) += virtio_sandbox.o
 obj-$(CONFIG_VIRTIO_NET) += virtio_net.o
 obj-$(CONFIG_VIRTIO_BLK) += virtio_blk.o
diff --git a/drivers/virtio/virtio_sandbox.c b/drivers/virtio/virtio_sandbox.c
new file mode 100644
index 000..2addb1e
--- /dev/null
+++ b/drivers/virtio/virtio_sandbox.c
@@ -0,0 +1,233 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2018, Bin Meng 
+ *
+ * VirtIO Sandbox transport driver, for testing purpose only
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct virtio_sandbox_priv {
+   u8 id;
+   u8 status;
+   u64 device_features;
+   u64 driver_features;
+   ulong queue_desc;
+   ulong queue_available;
+   ulong queue_used;
+};
+
+static int virtio_sandbox_get_config(struct udevice *udev, unsigned int offset,
+void *buf, unsigned int len)
+{
+   return 0;
+}
+
+static int virtio_sandbox_set_config(struct udevice *udev, unsigned int offset,
+const void *buf, unsigned int len)
+{
+   return 0;
+}
+
+static int virtio_sandbox_get_status(struct udevice *udev, u8 *status)
+{
+   struct virtio_sandbox_priv *priv = dev_get_priv(udev);
+
+   *status = priv->status;
+
+   return 0;
+}
+
+static int virtio_sandbox_set_status(struct udevice *udev, u8 status)
+{
+   struct virtio_sandbox_priv *priv = dev_get_priv(udev);
+
+   /* We should never be setting status to 0 */
+   WARN_ON(status == 0);
+
+   priv->status = status;
+
+   return 0;
+}
+
+static int virtio_sandbox_reset(struct udevice *udev)
+{
+   struct virtio_sandbox_priv *priv = dev_get_priv(udev);
+
+   /* 0 status means a reset */
+   priv->status = 0;
+
+   return 0;
+}
+
+static int virtio_sandbox_get_features(struct udevice *udev, u64 *features)
+{
+   struct virtio_sandbox_priv *priv = dev_get_priv(udev);
+
+   *features = priv->device_features;
+
+   return 0;
+}
+
+static int virtio_sandbox_set_features(struct udevice *udev)
+{
+   struct virtio_sandbox_priv *priv = dev_get_priv(udev);
+   struct virtio_dev_priv *uc_priv = dev_get_uclass_priv(udev);
+
+   priv->driver_features = uc_priv->features;
+
+   return 0;
+}
+
+static struct virtqueue *virtio_sandbox_setup_vq(struct udevice *udev,
+unsigned int index)
+{
+   struct virtio_sandbox_priv *priv = dev_get_priv(udev);
+   struct virtqueue *vq;
+   ulong addr;
+   int err;
+
+   /* Create the vring */
+   vq = vring_create_virtqueue(index, 4, 4096, udev);
+   if (!vq) {
+   err = -ENOMEM;
+   goto error_new_virtqueue;
+   }
+
+   addr = virtqueue_get_desc_addr(vq);
+   priv->queue_desc = addr;
+
+   addr = virtqueue_get_avail_addr(vq);
+   priv->queue_available = addr;
+
+   addr = virtqueue_get_used_addr(vq);
+   priv->queue_used = addr;
+
+   return vq;
+
+error_new_virtqueue:
+   return ERR_PTR(err);
+}
+
+static void virtio_sandbox_del_vq(struct virtqueue *vq)
+{
+   vring_del_virtqueue(vq);
+}
+
+static int virtio_sandbox_del_vqs(struct udevice *udev)
+{
+   struct virtio_dev_priv *uc_priv = dev_get_uclass_priv(udev);
+   struct virtqueue *vq, *n;
+
+   list_for_each_entry_safe(vq, n, &uc_priv->vqs, list)
+   virtio_sandbox_del_vq(vq);
+
+   

[U-Boot] [PATCH v3 28/31] virtio: net: Support non-legacy device

2018-10-15 Thread Bin Meng
For v1.0 compliant device, it always assumes the member 'num_buffers'
exists in the struct virtio_net_hdr while the legacy driver only
presented 'num_buffers' when VIRTIO_NET_F_MRG_RXBUF was negotiated.
Without that feature the structure was 2 bytes shorter.

Update the driver to support the non-legacy device.

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

Changes in v3: None
Changes in v2: None

 drivers/virtio/virtio_net.c | 31 ++-
 1 file changed, 26 insertions(+), 5 deletions(-)

diff --git a/drivers/virtio/virtio_net.c b/drivers/virtio/virtio_net.c
index 5bb6a9f..0dbbd78 100644
--- a/drivers/virtio/virtio_net.c
+++ b/drivers/virtio/virtio_net.c
@@ -32,6 +32,7 @@ struct virtio_net_priv {
 
char rx_buff[VIRTIO_NET_NUM_RX_BUFS][VIRTIO_NET_RX_BUF_SIZE];
bool rx_running;
+   int net_hdr_len;
 };
 
 /*
@@ -77,12 +78,19 @@ static int virtio_net_send(struct udevice *dev, void 
*packet, int length)
 {
struct virtio_net_priv *priv = dev_get_priv(dev);
struct virtio_net_hdr hdr;
-   struct virtio_sg hdr_sg = { &hdr, sizeof(hdr) };
+   struct virtio_net_hdr_v1 hdr_v1;
+   struct virtio_sg hdr_sg;
struct virtio_sg data_sg = { packet, length };
struct virtio_sg *sgs[] = { &hdr_sg, &data_sg };
int ret;
 
-   memset(&hdr, 0, sizeof(struct virtio_net_hdr));
+   if (priv->net_hdr_len == sizeof(struct virtio_net_hdr))
+   hdr_sg.addr = &hdr;
+   else
+   hdr_sg.addr = &hdr_v1;
+   hdr_sg.length = priv->net_hdr_len;
+
+   memset(hdr_sg.addr, 0, priv->net_hdr_len);
 
ret = virtqueue_add(priv->tx_vq, sgs, 2, 0);
if (ret)
@@ -108,14 +116,14 @@ static int virtio_net_recv(struct udevice *dev, int 
flags, uchar **packetp)
if (!buf)
return -EAGAIN;
 
-   *packetp = buf + sizeof(struct virtio_net_hdr);
-   return len - sizeof(struct virtio_net_hdr);
+   *packetp = buf + priv->net_hdr_len;
+   return len - priv->net_hdr_len;
 }
 
 static int virtio_net_free_pkt(struct udevice *dev, uchar *packet, int length)
 {
struct virtio_net_priv *priv = dev_get_priv(dev);
-   void *buf = packet - sizeof(struct virtio_net_hdr);
+   void *buf = packet - priv->net_hdr_len;
struct virtio_sg sg = { buf, VIRTIO_NET_RX_BUF_SIZE };
struct virtio_sg *sgs[] = { &sg };
 
@@ -186,12 +194,25 @@ static int virtio_net_bind(struct udevice *dev)
 static int virtio_net_probe(struct udevice *dev)
 {
struct virtio_net_priv *priv = dev_get_priv(dev);
+   struct virtio_dev_priv *uc_priv = dev_get_uclass_priv(dev->parent);
int ret;
 
ret = virtio_find_vqs(dev, 2, priv->vqs);
if (ret < 0)
return ret;
 
+   /*
+* For v1.0 compliant device, it always assumes the member
+* 'num_buffers' exists in the struct virtio_net_hdr while
+* the legacy driver only presented 'num_buffers' when
+* VIRTIO_NET_F_MRG_RXBUF was negotiated. Without that feature
+* the structure was 2 bytes shorter.
+*/
+   if (uc_priv->legacy)
+   priv->net_hdr_len = sizeof(struct virtio_net_hdr);
+   else
+   priv->net_hdr_len = sizeof(struct virtio_net_hdr_v1);
+
return 0;
 }
 
-- 
2.7.4

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 26/31] test: dm: pci: Add cases for finding next PCI capability APIs

2018-10-15 Thread Bin Meng
Add test cases to cover the two newly added PCI APIs:
dm_pci_find_next_capability() & dm_pci_find_next_ext_capability().

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

---

Changes in v3: None
Changes in v2:
- adjust swap_case driver to handle request from
  _dm_pci_find_next_capability()

 drivers/misc/swap_case.c |  9 +
 test/dm/pci.c| 20 
 2 files changed, 29 insertions(+)

diff --git a/drivers/misc/swap_case.c b/drivers/misc/swap_case.c
index bffb809..fa608ce 100644
--- a/drivers/misc/swap_case.c
+++ b/drivers/misc/swap_case.c
@@ -124,12 +124,21 @@ static int sandbox_swap_case_read_config(struct udevice 
*emul, uint offset,
case PCI_CAP_ID_PM_OFFSET:
*valuep = (PCI_CAP_ID_EXP_OFFSET << 8) | PCI_CAP_ID_PM;
break;
+   case PCI_CAP_ID_PM_OFFSET + PCI_CAP_LIST_NEXT:
+   *valuep = PCI_CAP_ID_EXP_OFFSET;
+   break;
case PCI_CAP_ID_EXP_OFFSET:
*valuep = (PCI_CAP_ID_MSIX_OFFSET << 8) | PCI_CAP_ID_EXP;
break;
+   case PCI_CAP_ID_EXP_OFFSET + PCI_CAP_LIST_NEXT:
+   *valuep = PCI_CAP_ID_MSIX_OFFSET;
+   break;
case PCI_CAP_ID_MSIX_OFFSET:
*valuep = PCI_CAP_ID_MSIX;
break;
+   case PCI_CAP_ID_MSIX_OFFSET + PCI_CAP_LIST_NEXT:
+   *valuep = 0;
+   break;
case PCI_EXT_CAP_ID_ERR_OFFSET:
*valuep = (PCI_EXT_CAP_ID_VC_OFFSET << 20) | PCI_EXT_CAP_ID_ERR;
break;
diff --git a/test/dm/pci.c b/test/dm/pci.c
index 8699700..f645b8b 100644
--- a/test/dm/pci.c
+++ b/test/dm/pci.c
@@ -206,6 +206,16 @@ static int dm_test_pci_cap(struct unit_test_state *uts)
cap = dm_pci_find_capability(swap, PCI_CAP_ID_PCIX);
ut_asserteq(0, cap);
 
+   /* look up PCI_CAP_ID_MSIX starting from PCI_CAP_ID_PM_OFFSET */
+   cap = dm_pci_find_next_capability(swap, PCI_CAP_ID_PM_OFFSET,
+ PCI_CAP_ID_MSIX);
+   ut_asserteq(PCI_CAP_ID_MSIX_OFFSET, cap);
+
+   /* look up PCI_CAP_ID_VNDR starting from PCI_CAP_ID_EXP_OFFSET */
+   cap = dm_pci_find_next_capability(swap, PCI_CAP_ID_EXP_OFFSET,
+ PCI_CAP_ID_VNDR);
+   ut_asserteq(0, cap);
+
ut_assertok(uclass_get_device_by_seq(UCLASS_PCI, 1, &bus));
ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(1, 0x08, 0), &swap));
 
@@ -217,6 +227,16 @@ static int dm_test_pci_cap(struct unit_test_state *uts)
cap = dm_pci_find_ext_capability(swap, PCI_EXT_CAP_ID_SRIOV);
ut_asserteq(0, cap);
 
+   /* look up PCI_EXT_CAP_ID_DSN starting from PCI_EXT_CAP_ID_ERR_OFFSET */
+   cap = dm_pci_find_next_ext_capability(swap, PCI_EXT_CAP_ID_ERR_OFFSET,
+ PCI_EXT_CAP_ID_DSN);
+   ut_asserteq(PCI_EXT_CAP_ID_DSN_OFFSET, cap);
+
+   /* look up PCI_EXT_CAP_ID_RCRB starting from PCI_EXT_CAP_ID_VC_OFFSET */
+   cap = dm_pci_find_next_ext_capability(swap, PCI_EXT_CAP_ID_VC_OFFSET,
+ PCI_EXT_CAP_ID_RCRB);
+   ut_asserteq(0, cap);
+
return 0;
 }
 DM_TEST(dm_test_pci_cap, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
-- 
2.7.4

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 23/31] arm: qemu: Enumerate virtio bus during early boot

2018-10-15 Thread Bin Meng
Currently devices on the virtio bus is not automatically enumerated,
which means peripherals on the virtio bus are not discovered by their
drivers. This uses board_init() to do the virtio enumeration.

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

---

Changes in v3: None
Changes in v2:
- imply VIRTIO_PCI for qemu-arm too

 board/emulation/qemu-arm/Kconfig|  4 
 board/emulation/qemu-arm/qemu-arm.c | 10 ++
 2 files changed, 14 insertions(+)

diff --git a/board/emulation/qemu-arm/Kconfig b/board/emulation/qemu-arm/Kconfig
index d1c08c2..02ae4d9 100644
--- a/board/emulation/qemu-arm/Kconfig
+++ b/board/emulation/qemu-arm/Kconfig
@@ -5,5 +5,9 @@ config SYS_TEXT_BASE
 
 config BOARD_SPECIFIC_OPTIONS # dummy
def_bool y
+   imply VIRTIO_MMIO
+   imply VIRTIO_PCI
+   imply VIRTIO_NET
+   imply VIRTIO_BLK
 
 endif
diff --git a/board/emulation/qemu-arm/qemu-arm.c 
b/board/emulation/qemu-arm/qemu-arm.c
index 812c906..e1f4709 100644
--- a/board/emulation/qemu-arm/qemu-arm.c
+++ b/board/emulation/qemu-arm/qemu-arm.c
@@ -2,8 +2,12 @@
 /*
  * Copyright (c) 2017 Tuomas Tynkkynen
  */
+
 #include 
+#include 
 #include 
+#include 
+#include 
 
 #ifdef CONFIG_ARM64
 #include 
@@ -58,6 +62,12 @@ struct mm_region *mem_map = qemu_arm64_mem_map;
 
 int board_init(void)
 {
+   /*
+* Make sure virtio bus is enumerated so that peripherals
+* on the virtio bus can be discovered by their drivers
+*/
+   virtio_init();
+
return 0;
 }
 
-- 
2.7.4

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 24/31] x86: qemu: Imply virtio PCI transport and device drivers

2018-10-15 Thread Bin Meng
Add virtio drivers for QEMU x86 targets.

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

Changes in v3: None
Changes in v2: None

 board/emulation/qemu-x86/Kconfig | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/board/emulation/qemu-x86/Kconfig b/board/emulation/qemu-x86/Kconfig
index 41a27dd..6d19299 100644
--- a/board/emulation/qemu-x86/Kconfig
+++ b/board/emulation/qemu-x86/Kconfig
@@ -21,5 +21,8 @@ config BOARD_SPECIFIC_OPTIONS # dummy
select X86_RESET_VECTOR
select QEMU
select BOARD_ROMSIZE_KB_1024
+   imply VIRTIO_PCI
+   imply VIRTIO_NET
+   imply VIRTIO_BLK
 
 endif
-- 
2.7.4

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 18/31] riscv: qemu: Include some useful commands

2018-10-15 Thread Bin Meng
With the virtio net and blk drivers, we can do more stuff with some
useful commands. Imply those in the board Kconfig.

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

Changes in v3: None
Changes in v2: None

 board/emulation/qemu-riscv/Kconfig | 8 
 1 file changed, 8 insertions(+)

diff --git a/board/emulation/qemu-riscv/Kconfig 
b/board/emulation/qemu-riscv/Kconfig
index 5ae56da..37a80db 100644
--- a/board/emulation/qemu-riscv/Kconfig
+++ b/board/emulation/qemu-riscv/Kconfig
@@ -21,5 +21,13 @@ config BOARD_SPECIFIC_OPTIONS # dummy
imply VIRTIO_MMIO
imply VIRTIO_NET
imply VIRTIO_BLK
+   imply CMD_PING
+   imply CMD_FS_GENERIC
+   imply DOS_PARTITION
+   imply EFI_PARTITION
+   imply ISO_PARTITION
+   imply CMD_EXT2
+   imply CMD_EXT4
+   imply CMD_FAT
 
 endif
-- 
2.7.4

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 25/31] dm: pci: Add APIs to find next capability and extended capability

2018-10-15 Thread Bin Meng
This introduces two new APIs dm_pci_find_next_capability() and
dm_pci_find_next_ext_capability() to get PCI capability address
and PCI express extended capability address for a given PCI device
starting from a given offset.

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

---

Changes in v3: None
Changes in v2:
- use an internal function _dm_pci_find_next_capability() for
  dm_pci_find_capability() and dm_pci_find_next_capability()

 drivers/pci/pci-uclass.c | 51 ++--
 include/pci.h| 48 +
 2 files changed, 84 insertions(+), 15 deletions(-)

diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c
index eb118f3..0455c72 100644
--- a/drivers/pci/pci-uclass.c
+++ b/drivers/pci/pci-uclass.c
@@ -1318,26 +1318,14 @@ void *dm_pci_map_bar(struct udevice *dev, int bar, int 
flags)
return dm_pci_bus_to_virt(dev, pci_bus_addr, flags, 0, MAP_NOCACHE);
 }
 
-int dm_pci_find_capability(struct udevice *dev, int cap)
+static int _dm_pci_find_next_capability(struct udevice *dev, u8 pos, int cap)
 {
-   u16 status;
-   u8 header_type;
int ttl = PCI_FIND_CAP_TTL;
u8 id;
u16 ent;
-   u8 pos;
-
-   dm_pci_read_config16(dev, PCI_STATUS, &status);
-   if (!(status & PCI_STATUS_CAP_LIST))
-   return 0;
-
-   dm_pci_read_config8(dev, PCI_HEADER_TYPE, &header_type);
-   if ((header_type & 0x7f) == PCI_HEADER_TYPE_CARDBUS)
-   pos = PCI_CB_CAPABILITY_LIST;
-   else
-   pos = PCI_CAPABILITY_LIST;
 
dm_pci_read_config8(dev, pos, &pos);
+
while (ttl--) {
if (pos < PCI_STD_HEADER_SIZEOF)
break;
@@ -1355,7 +1343,32 @@ int dm_pci_find_capability(struct udevice *dev, int cap)
return 0;
 }
 
-int dm_pci_find_ext_capability(struct udevice *dev, int cap)
+int dm_pci_find_next_capability(struct udevice *dev, u8 start, int cap)
+{
+   return _dm_pci_find_next_capability(dev, start + PCI_CAP_LIST_NEXT,
+   cap);
+}
+
+int dm_pci_find_capability(struct udevice *dev, int cap)
+{
+   u16 status;
+   u8 header_type;
+   u8 pos;
+
+   dm_pci_read_config16(dev, PCI_STATUS, &status);
+   if (!(status & PCI_STATUS_CAP_LIST))
+   return 0;
+
+   dm_pci_read_config8(dev, PCI_HEADER_TYPE, &header_type);
+   if ((header_type & 0x7f) == PCI_HEADER_TYPE_CARDBUS)
+   pos = PCI_CB_CAPABILITY_LIST;
+   else
+   pos = PCI_CAPABILITY_LIST;
+
+   return _dm_pci_find_next_capability(dev, pos, cap);
+}
+
+int dm_pci_find_next_ext_capability(struct udevice *dev, int start, int cap)
 {
u32 header;
int ttl;
@@ -1364,6 +1377,9 @@ int dm_pci_find_ext_capability(struct udevice *dev, int 
cap)
/* minimum 8 bytes per capability */
ttl = (PCI_CFG_SPACE_EXP_SIZE - PCI_CFG_SPACE_SIZE) / 8;
 
+   if (start)
+   pos = start;
+
dm_pci_read_config32(dev, pos, &header);
/*
 * If we have no capabilities, this is indicated by cap ID,
@@ -1386,6 +1402,11 @@ int dm_pci_find_ext_capability(struct udevice *dev, int 
cap)
return 0;
 }
 
+int dm_pci_find_ext_capability(struct udevice *dev, int cap)
+{
+   return dm_pci_find_next_ext_capability(dev, 0, cap);
+}
+
 UCLASS_DRIVER(pci) = {
.id = UCLASS_PCI,
.name   = "pci",
diff --git a/include/pci.h b/include/pci.h
index 938a839..785d7d2 100644
--- a/include/pci.h
+++ b/include/pci.h
@@ -1313,6 +1313,29 @@ pci_addr_t dm_pci_phys_to_bus(struct udevice *dev, 
phys_addr_t addr,
 void *dm_pci_map_bar(struct udevice *dev, int bar, int flags);
 
 /**
+ * dm_pci_find_next_capability() - find a capability starting from an offset
+ *
+ * Tell if a device supports a given PCI capability. Returns the
+ * address of the requested capability structure within the device's
+ * PCI configuration space or 0 in case the device does not support it.
+ *
+ * Possible values for @cap:
+ *
+ *  %PCI_CAP_ID_MSIMessage Signalled Interrupts
+ *  %PCI_CAP_ID_PCIX   PCI-X
+ *  %PCI_CAP_ID_EXPPCI Express
+ *  %PCI_CAP_ID_MSIX   MSI-X
+ *
+ * See PCI_CAP_ID_xxx for the complete capability ID codes.
+ *
+ * @dev:   PCI device to query
+ * @start: offset to start from
+ * @cap:   capability code
+ * @return:capability address or 0 if not supported
+ */
+int dm_pci_find_next_capability(struct udevice *dev, u8 start, int cap);
+
+/**
  * dm_pci_find_capability() - find a capability
  *
  * Tell if a device supports a given PCI capability. Returns the
@@ -1335,6 +1358,31 @@ void *dm_pci_map_bar(struct udevice *dev, int bar, int 
flags);
 int dm_pci_find_capability(struct udevice *dev, int cap);
 
 /**
+ * dm_pci_find_next_ext_capability() - find an extended capability
+ *starting from an offset
+ *
+ * Tell if a devi

[U-Boot] [PATCH v3 19/31] kconfig: Introduce HAVE_ARCH_IOMAP

2018-10-15 Thread Bin Meng
Introduce a new Kconfig option for architecture codes to control
whether it provides io{read,write}{8,16,32} I/O accessor functions.

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

Changes in v3: None
Changes in v2: None

 include/linux/io.h | 4 
 lib/Kconfig| 6 ++
 2 files changed, 10 insertions(+)

diff --git a/include/linux/io.h b/include/linux/io.h
index d1b3efe..9badab4 100644
--- a/include/linux/io.h
+++ b/include/linux/io.h
@@ -7,6 +7,7 @@
 #include 
 #include 
 
+#ifndef CONFIG_HAVE_ARCH_IOMAP
 static inline u8 ioread8(const volatile void __iomem *addr)
 {
return readb(addr);
@@ -21,6 +22,7 @@ static inline u32 ioread32(const volatile void __iomem *addr)
 {
return readl(addr);
 }
+#endif /* !CONFIG_HAVE_ARCH_IOMAP */
 
 #ifdef CONFIG_64BIT
 static inline u64 ioread64(const volatile void __iomem *addr)
@@ -29,6 +31,7 @@ static inline u64 ioread64(const volatile void __iomem *addr)
 }
 #endif /* CONFIG_64BIT */
 
+#ifndef CONFIG_HAVE_ARCH_IOMAP
 static inline void iowrite8(u8 value, volatile void __iomem *addr)
 {
writeb(value, addr);
@@ -43,6 +46,7 @@ static inline void iowrite32(u32 value, volatile void __iomem 
*addr)
 {
writel(value, addr);
 }
+#endif /* !CONFIG_HAVE_ARCH_IOMAP */
 
 #ifdef CONFIG_64BIT
 static inline void iowrite64(u64 value, volatile void __iomem *addr)
diff --git a/lib/Kconfig b/lib/Kconfig
index ccab426..847e797 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -21,6 +21,12 @@ config DYNAMIC_CRC_TABLE
  Enable this option to calculate entries for CRC tables at runtime.
  This can be helpful when reducing the size of the build image
 
+config HAVE_ARCH_IOMAP
+   bool
+   help
+ Enable this option if architecture provides io{read,write}{8,16,32}
+ I/O accessor functions.
+
 config HAVE_PRIVATE_LIBGCC
bool
 
-- 
2.7.4

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 30/31] test: dm: virtio: Add test cases for virtio uclass

2018-10-15 Thread Bin Meng
Now that we have a sandbox virtio transport driver, add some test
cases to test virtio uclass driver.

Signed-off-by: Bin Meng 

---

Changes in v3:
- Exclude VIRTIO_BLK in sandbox_noblk_defconfig build

Changes in v2:
- new patch to add test cases for virtio uclass

 arch/Kconfig|   5 ++
 arch/sandbox/dts/test.dts   |   8 +++
 configs/sandbox_noblk_defconfig |   1 +
 test/dm/Makefile|   1 +
 test/dm/virtio.c| 122 
 5 files changed, 137 insertions(+)
 create mode 100644 test/dm/virtio.c

diff --git a/arch/Kconfig b/arch/Kconfig
index e822a0b..9fdd2f7 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -110,6 +110,11 @@ config SANDBOX
imply LIBAVB
imply CMD_AVB
imply UDP_FUNCTION_FASTBOOT
+   imply VIRTIO_MMIO
+   imply VIRTIO_PCI
+   imply VIRTIO_SANDBOX
+   imply VIRTIO_BLK
+   imply VIRTIO_NET
 
 config SH
bool "SuperH architecture"
diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index c52f5a9..47e0646 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -715,6 +715,14 @@
sandbox_tee {
compatible = "sandbox,tee";
};
+
+   sandbox_virtio1 {
+   compatible = "sandbox,virtio1";
+   };
+
+   sandbox_virtio2 {
+   compatible = "sandbox,virtio2";
+   };
 };
 
 #include "sandbox_pmic.dtsi"
diff --git a/configs/sandbox_noblk_defconfig b/configs/sandbox_noblk_defconfig
index 93b2240..e71e2d3 100644
--- a/configs/sandbox_noblk_defconfig
+++ b/configs/sandbox_noblk_defconfig
@@ -171,6 +171,7 @@ CONFIG_CONSOLE_TRUETYPE_CANTORAONE=y
 CONFIG_VIDEO_SANDBOX_SDL=y
 CONFIG_OSD=y
 CONFIG_SANDBOX_OSD=y
+# CONFIG_VIRTIO_BLK is not set
 CONFIG_FS_CBFS=y
 CONFIG_FS_CRAMFS=y
 CONFIG_CMD_DHRYSTONE=y
diff --git a/test/dm/Makefile b/test/dm/Makefile
index b490cf2..213e0fd 100644
--- a/test/dm/Makefile
+++ b/test/dm/Makefile
@@ -53,4 +53,5 @@ obj-$(CONFIG_MISC) += misc.o
 obj-$(CONFIG_DM_SERIAL) += serial.o
 obj-$(CONFIG_CPU) += cpu.o
 obj-$(CONFIG_TEE) += tee.o
+obj-$(CONFIG_VIRTIO_SANDBOX) += virtio.o
 endif
diff --git a/test/dm/virtio.c b/test/dm/virtio.c
new file mode 100644
index 000..4b317d2
--- /dev/null
+++ b/test/dm/virtio.c
@@ -0,0 +1,122 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2018, Bin Meng 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* Basic test of the virtio uclass */
+static int dm_test_virtio_base(struct unit_test_state *uts)
+{
+   struct udevice *bus, *dev;
+   u8 status;
+
+   /* check probe success */
+   ut_assertok(uclass_first_device(UCLASS_VIRTIO, &bus));
+
+   /* check the child virtio-blk device is bound */
+   ut_assertok(device_find_first_child(bus, &dev));
+   ut_assertok(strcmp(dev->name, "virtio-blk#0"));
+
+   /* check driver status */
+   ut_assertok(virtio_get_status(dev, &status));
+   ut_asserteq(VIRTIO_CONFIG_S_ACKNOWLEDGE, status);
+
+   return 0;
+}
+DM_TEST(dm_test_virtio_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+/* Test all of the virtio uclass ops */
+static int dm_test_virtio_all_ops(struct unit_test_state *uts)
+{
+   struct udevice *bus, *dev;
+   struct virtio_dev_priv *uc_priv;
+   uint offset = 0, len = 0, nvqs = 1;
+   void *buffer = NULL;
+   u8 status;
+   u32 counter;
+   u64 features;
+   struct virtqueue *vqs[2];
+
+   /* check probe success */
+   ut_assertok(uclass_first_device(UCLASS_VIRTIO, &bus));
+
+   /* check the child virtio-blk device is bound */
+   ut_assertok(device_find_first_child(bus, &dev));
+
+   /*
+* fake the virtio device probe by filling in uc_priv->vdev
+* which is used by virtio_find_vqs/virtio_del_vqs.
+*/
+   uc_priv = dev_get_uclass_priv(bus);
+   uc_priv->vdev = dev;
+
+   /* test virtio_xxx APIs */
+   ut_assertok(virtio_get_config(dev, offset, buffer, len));
+   ut_assertok(virtio_set_config(dev, offset, buffer, len));
+   ut_asserteq(-ENOSYS, virtio_generation(dev, &counter));
+   ut_assertok(virtio_set_status(dev, VIRTIO_CONFIG_S_DRIVER_OK));
+   ut_assertok(virtio_get_status(dev, &status));
+   ut_asserteq(VIRTIO_CONFIG_S_DRIVER_OK, status);
+   ut_assertok(virtio_reset(dev));
+   ut_assertok(virtio_get_status(dev, &status));
+   ut_asserteq(0, status);
+   ut_assertok(virtio_get_features(dev, &features));
+   ut_asserteq(VIRTIO_F_VERSION_1, features);
+   ut_assertok(virtio_set_features(dev));
+   ut_assertok(virtio_find_vqs(dev, nvqs, vqs));
+   ut_assertok(virtio_del_vqs(dev));
+   ut_assertok(virtio_notify(dev, vqs[0]));
+
+   return 0;
+}
+DM_TEST(dm_test_virtio_all_ops, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+/* Test of the virtio driver that does not have required driver ops */
+

[U-Boot] [PATCH v3 22/31] arm: qemu: Add a Kconfig in the board directory

2018-10-15 Thread Bin Meng
This adds a Kconfig file in the board directory, so that some
board-specific options can be specified there.

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

Changes in v3: None
Changes in v2: None

 arch/arm/Kconfig | 1 +
 board/emulation/qemu-arm/Kconfig | 9 +
 configs/qemu_arm64_defconfig | 1 -
 configs/qemu_arm_defconfig   | 1 -
 4 files changed, 10 insertions(+), 2 deletions(-)
 create mode 100644 board/emulation/qemu-arm/Kconfig

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index ccf2a84..a3e6784 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -1474,6 +1474,7 @@ source "board/broadcom/bcmns2/Kconfig"
 source "board/cavium/thunderx/Kconfig"
 source "board/cirrus/edb93xx/Kconfig"
 source "board/eets/pdu001/Kconfig"
+source "board/emulation/qemu-arm/Kconfig"
 source "board/freescale/ls2080a/Kconfig"
 source "board/freescale/ls2080aqds/Kconfig"
 source "board/freescale/ls2080ardb/Kconfig"
diff --git a/board/emulation/qemu-arm/Kconfig b/board/emulation/qemu-arm/Kconfig
new file mode 100644
index 000..d1c08c2
--- /dev/null
+++ b/board/emulation/qemu-arm/Kconfig
@@ -0,0 +1,9 @@
+if TARGET_QEMU_ARM_32BIT || TARGET_QEMU_ARM_64BIT
+
+config SYS_TEXT_BASE
+   default 0x
+
+config BOARD_SPECIFIC_OPTIONS # dummy
+   def_bool y
+
+endif
diff --git a/configs/qemu_arm64_defconfig b/configs/qemu_arm64_defconfig
index 7fd726f..bdb1c12 100644
--- a/configs/qemu_arm64_defconfig
+++ b/configs/qemu_arm64_defconfig
@@ -1,7 +1,6 @@
 CONFIG_ARM=y
 CONFIG_ARM_SMCCC=y
 CONFIG_ARCH_QEMU=y
-CONFIG_SYS_TEXT_BASE=0x
 CONFIG_TARGET_QEMU_ARM_64BIT=y
 CONFIG_AHCI=y
 CONFIG_DISTRO_DEFAULTS=y
diff --git a/configs/qemu_arm_defconfig b/configs/qemu_arm_defconfig
index fbceaf3..10959b2 100644
--- a/configs/qemu_arm_defconfig
+++ b/configs/qemu_arm_defconfig
@@ -1,7 +1,6 @@
 CONFIG_ARM=y
 CONFIG_ARM_SMCCC=y
 CONFIG_ARCH_QEMU=y
-CONFIG_SYS_TEXT_BASE=0x
 CONFIG_TARGET_QEMU_ARM_32BIT=y
 CONFIG_AHCI=y
 CONFIG_DISTRO_DEFAULTS=y
-- 
2.7.4

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 20/31] x86: Implement arch-specific io accessor routines

2018-10-15 Thread Bin Meng
At present the generic io{read,write}{8,16,32} routines only support
MMIO access. With architecture like x86 that has a separate IO space,
these routines cannot be used to access I/O ports.

Implement x86-specific version to support both PIO and MMIO access,
so that drivers for multiple architectures can use these accessors
without the need to know whether it's MMIO or PIO.

These are ported from Linux kernel lib/iomap.c, with slight changes.

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

Changes in v3: None
Changes in v2: None

 arch/Kconfig  |  1 +
 arch/x86/include/asm/io.h | 66 +++
 2 files changed, 67 insertions(+)

diff --git a/arch/Kconfig b/arch/Kconfig
index 1f2f407..e822a0b 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -120,6 +120,7 @@ config X86
select CREATE_ARCH_SYMLINK
select DM
select DM_PCI
+   select HAVE_ARCH_IOMAP
select HAVE_PRIVATE_LIBGCC
select OF_CONTROL
select PCI
diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
index c05c6bf..81def0a 100644
--- a/arch/x86/include/asm/io.h
+++ b/arch/x86/include/asm/io.h
@@ -241,6 +241,72 @@ static inline void sync(void)
 #define __iormb()  dmb()
 #define __iowmb()  dmb()
 
+/*
+ * Read/write from/to an (offsettable) iomem cookie. It might be a PIO
+ * access or a MMIO access, these functions don't care. The info is
+ * encoded in the hardware mapping set up by the mapping functions
+ * (or the cookie itself, depending on implementation and hw).
+ *
+ * The generic routines don't assume any hardware mappings, and just
+ * encode the PIO/MMIO as part of the cookie. They coldly assume that
+ * the MMIO IO mappings are not in the low address range.
+ *
+ * Architectures for which this is not true can't use this generic
+ * implementation and should do their own copy.
+ */
+
+/*
+ * We assume that all the low physical PIO addresses (0-0x) always
+ * PIO. That means we can do some sanity checks on the low bits, and
+ * don't need to just take things for granted.
+ */
+#define PIO_RESERVED   0x1UL
+
+/*
+ * Ugly macros are a way of life.
+ */
+#define IO_COND(addr, is_pio, is_mmio) do {\
+   unsigned long port = (unsigned long __force)addr;   \
+   if (port >= PIO_RESERVED) { \
+   is_mmio;\
+   } else {\
+   is_pio; \
+   }   \
+} while (0)
+
+static inline u8 ioread8(const volatile void __iomem *addr)
+{
+   IO_COND(addr, return inb(port), return readb(addr));
+   return 0xff;
+}
+
+static inline u16 ioread16(const volatile void __iomem *addr)
+{
+   IO_COND(addr, return inw(port), return readw(addr));
+   return 0x;
+}
+
+static inline u32 ioread32(const volatile void __iomem *addr)
+{
+   IO_COND(addr, return inl(port), return readl(addr));
+   return 0x;
+}
+
+static inline void iowrite8(u8 value, volatile void __iomem *addr)
+{
+   IO_COND(addr, outb(value, port), writeb(value, addr));
+}
+
+static inline void iowrite16(u16 value, volatile void __iomem *addr)
+{
+   IO_COND(addr, outw(value, port), writew(value, addr));
+}
+
+static inline void iowrite32(u32 value, volatile void __iomem *addr)
+{
+   IO_COND(addr, outl(value, port), writel(value, addr));
+}
+
 #include 
 
 #endif /* _ASM_IO_H */
-- 
2.7.4

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 31/31] doc: Document virtio support

2018-10-15 Thread Bin Meng
Add REAME.virtio to describe the information about U-Boot support for
VirtIO devices, including supported boards, build instructions, driver
details etc.

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

---

Changes in v3: None
Changes in v2:
- Added driver remove and flags description in the documentation

 doc/README.virtio | 253 ++
 1 file changed, 253 insertions(+)
 create mode 100644 doc/README.virtio

diff --git a/doc/README.virtio b/doc/README.virtio
new file mode 100644
index 000..d3652f2
--- /dev/null
+++ b/doc/README.virtio
@@ -0,0 +1,253 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Copyright (C) 2018, Bin Meng 
+
+VirtIO Support
+==
+
+This document describes the information about U-Boot support for VirtIO [1]
+devices, including supported boards, build instructions, driver details etc.
+
+What's VirtIO?
+--
+VirtIO is a virtualization standard for network and disk device drivers where
+just the guest's device driver "knows" it is running in a virtual environment,
+and cooperates with the hypervisor. This enables guests to get high performance
+network and disk operations, and gives most of the performance benefits of
+paravirtualization. In the U-Boot case, the guest is U-Boot itself, while the
+virtual environment are normally QEMU [2] targets like ARM, RISC-V and x86.
+
+Status
+--
+VirtIO can use various different buses, aka transports as described in the
+spec. While VirtIO devices are commonly implemented as PCI devices on x86,
+embedded devices models like ARM/RISC-V, which does not normally come with
+PCI support might use simple memory mapped device (MMIO) instead of the PCI
+device. The memory mapped virtio device behaviour is based on the PCI device
+specification. Therefore most operations including device initialization,
+queues configuration and buffer transfers are nearly identical. Both MMIO
+and PCI transport options are supported in U-Boot.
+
+The VirtIO spec defines a lots of VirtIO device types, however at present only
+network and block device, the most two commonly used devices, are supported.
+
+The following QEMU targets are supported.
+
+  - qemu_arm_defconfig
+  - qemu_arm64_defconfig
+  - qemu-riscv32_defconfig
+  - qemu-riscv64_defconfig
+  - qemu-x86_defconfig
+  - qemu-x86_64_defconfig
+
+Note ARM and RISC-V targets are configured with VirtIO MMIO transport driver,
+and on x86 it's the PCI transport driver.
+
+Build Instructions
+--
+Building U-Boot for pre-configured QEMU targets is no different from others.
+For example, we can do the following with the CROSS_COMPILE environment
+variable being properly set to a working toolchain for ARM:
+
+  $ make qemu_arm_defconfig
+  $ make
+
+You can even create a QEMU ARM target with VirtIO devices showing up on both
+MMIO and PCI buses. In this case, you can enable the PCI transport driver
+from 'make menuconfig':
+
+Device Drivers  --->
+   ...
+   VirtIO Drivers  --->
+   ...
+   [*] PCI driver for virtio devices
+
+Other drivers are at the same location and can be tuned to suit the needs.
+
+Requirements
+
+It is required that QEMU v2.5.0+ should be used to test U-Boot VirtIO support
+on QEMU ARM and x86, and v2.12.0+ on QEMU RISC-V.
+
+Testing
+---
+The following QEMU command line is used to get U-Boot up and running with
+VirtIO net and block devices on ARM.
+
+  $ qemu-system-arm -nographic -machine virt -bios u-boot.bin \
+-netdev tap,ifname=tap0,id=net0 \
+-device virtio-net-device,netdev=net0 \
+-drive if=none,file=test.img,format=raw,id=hd0 \
+-device virtio-blk-device,drive=hd0
+
+On x86, command is slightly different to create PCI VirtIO devices.
+
+  $ qemu-system-i386 -nographic -bios u-boot.rom \
+-netdev tap,ifname=tap0,id=net0 \
+-device virtio-net-pci,netdev=net0 \
+-drive if=none,file=test.img,format=raw,id=hd0 \
+-device virtio-blk-pci,drive=hd0
+
+Additional net and block devices can be created by appending more '-device'
+parameters. It is also possible to specify both MMIO and PCI VirtIO devices.
+For example, the following commnad creates 3 VirtIO devices, with 1 on MMIO
+and 2 on PCI bus.
+
+  $ qemu-system-arm -nographic -machine virt -bios u-boot.bin \
+-netdev tap,ifname=tap0,id=net0 \
+-device virtio-net-pci,netdev=net0 \
+-drive if=none,file=test0.img,format=raw,id=hd0 \
+-device virtio-blk-device,drive=hd0 \
+-drive if=none,file=test1.img,format=raw,id=hd1 \
+-device virtio-blk-pci,drive=hd1
+
+By default QEMU creates VirtIO legacy devices by default. To create non-legacy
+(aka modern) devices, pass additional device property/value pairs like below:
+
+  $ qemu-system-i386 -nographic -bios u-boot.rom \
+-netdev tap,ifname=tap0,id=net0 \
+-device 
virtio-net-pci,netdev=net0,disable-legacy=true,disable-modern=false \
+-drive if=none,file=test.img,format=raw,id=hd0 \
+-devic

[U-Boot] [PATCH v3 17/31] riscv: qemu: Enumerate virtio bus during early boot

2018-10-15 Thread Bin Meng
Currently devices on the virtio bus is not automatically enumerated,
which means peripherals on the virtio bus are not discovered by their
drivers. This uses board_init() to do the virtio enumeration.

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

Changes in v3: None
Changes in v2: None

 board/emulation/qemu-riscv/Kconfig  | 3 +++
 board/emulation/qemu-riscv/qemu-riscv.c | 9 +
 2 files changed, 12 insertions(+)

diff --git a/board/emulation/qemu-riscv/Kconfig 
b/board/emulation/qemu-riscv/Kconfig
index af23363..5ae56da 100644
--- a/board/emulation/qemu-riscv/Kconfig
+++ b/board/emulation/qemu-riscv/Kconfig
@@ -18,5 +18,8 @@ config SYS_TEXT_BASE
 config BOARD_SPECIFIC_OPTIONS # dummy
def_bool y
imply SYS_NS16550
+   imply VIRTIO_MMIO
+   imply VIRTIO_NET
+   imply VIRTIO_BLK
 
 endif
diff --git a/board/emulation/qemu-riscv/qemu-riscv.c 
b/board/emulation/qemu-riscv/qemu-riscv.c
index 041e716..2730a28 100644
--- a/board/emulation/qemu-riscv/qemu-riscv.c
+++ b/board/emulation/qemu-riscv/qemu-riscv.c
@@ -4,12 +4,21 @@
  */
 
 #include 
+#include 
 #include 
+#include 
+#include 
 
 #define MROM_FDT_ADDR  0x1020
 
 int board_init(void)
 {
+   /*
+* Make sure virtio bus is enumerated so that peripherals
+* on the virtio bus can be discovered by their drivers
+*/
+   virtio_init();
+
return 0;
 }
 
-- 
2.7.4

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v3 21/31] virtio: Add virtio over pci transport driver

2018-10-15 Thread Bin Meng
This adds a transport driver that implements UCLASS_VIRTIO for
virtio over pci, which is commonly used on x86.

It only supports the legacy interface of the pci transport, which
is the default device that QEMU emulates.

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

Changes in v3: None
Changes in v2: None

 drivers/virtio/Kconfig  |   8 +
 drivers/virtio/Makefile |   1 +
 drivers/virtio/virtio_pci.c | 421 
 drivers/virtio/virtio_pci.h | 173 ++
 4 files changed, 603 insertions(+)
 create mode 100644 drivers/virtio/virtio_pci.c
 create mode 100644 drivers/virtio/virtio_pci.h

diff --git a/drivers/virtio/Kconfig b/drivers/virtio/Kconfig
index b72477a..753912f 100644
--- a/drivers/virtio/Kconfig
+++ b/drivers/virtio/Kconfig
@@ -29,6 +29,14 @@ config VIRTIO_MMIO
  This driver provides support for memory mapped virtio
  platform device driver.
 
+config VIRTIO_PCI
+   bool "PCI driver for virtio devices"
+   depends on DM_PCI
+   select VIRTIO
+   help
+ This driver provides support for virtio based paravirtual device
+ drivers over PCI.
+
 config VIRTIO_NET
bool "virtio net driver"
depends on VIRTIO
diff --git a/drivers/virtio/Makefile b/drivers/virtio/Makefile
index 5fe7428..5ee6183 100644
--- a/drivers/virtio/Makefile
+++ b/drivers/virtio/Makefile
@@ -5,5 +5,6 @@
 
 obj-y += virtio-uclass.o virtio_ring.o
 obj-$(CONFIG_VIRTIO_MMIO) += virtio_mmio.o
+obj-$(CONFIG_VIRTIO_PCI) += virtio_pci.o
 obj-$(CONFIG_VIRTIO_NET) += virtio_net.o
 obj-$(CONFIG_VIRTIO_BLK) += virtio_blk.o
diff --git a/drivers/virtio/virtio_pci.c b/drivers/virtio/virtio_pci.c
new file mode 100644
index 000..a3f1083
--- /dev/null
+++ b/drivers/virtio/virtio_pci.c
@@ -0,0 +1,421 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2018, Bin Meng 
+ *
+ * VirtIO PCI bus transport driver
+ * Ported from Linux drivers/virtio/virtio_pci*.c
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "virtio_pci.h"
+
+#define VIRTIO_PCI_DRV_NAME"virtio-pci"
+
+/* PCI device ID in the range 0x1000 to 0x103f */
+#define VIRTIO_PCI_VENDOR_ID   0x1af4
+#define VIRTIO_PCI_DEVICE_ID00 0x1000
+#define VIRTIO_PCI_DEVICE_ID01 0x1001
+#define VIRTIO_PCI_DEVICE_ID02 0x1002
+#define VIRTIO_PCI_DEVICE_ID03 0x1003
+#define VIRTIO_PCI_DEVICE_ID04 0x1004
+#define VIRTIO_PCI_DEVICE_ID05 0x1005
+#define VIRTIO_PCI_DEVICE_ID06 0x1006
+#define VIRTIO_PCI_DEVICE_ID07 0x1007
+#define VIRTIO_PCI_DEVICE_ID08 0x1008
+#define VIRTIO_PCI_DEVICE_ID09 0x1009
+#define VIRTIO_PCI_DEVICE_ID0A 0x100a
+#define VIRTIO_PCI_DEVICE_ID0B 0x100b
+#define VIRTIO_PCI_DEVICE_ID0C 0x100c
+#define VIRTIO_PCI_DEVICE_ID0D 0x100d
+#define VIRTIO_PCI_DEVICE_ID0E 0x100e
+#define VIRTIO_PCI_DEVICE_ID0F 0x100f
+#define VIRTIO_PCI_DEVICE_ID10 0x1010
+#define VIRTIO_PCI_DEVICE_ID11 0x1011
+#define VIRTIO_PCI_DEVICE_ID12 0x1012
+#define VIRTIO_PCI_DEVICE_ID13 0x1013
+#define VIRTIO_PCI_DEVICE_ID14 0x1014
+#define VIRTIO_PCI_DEVICE_ID15 0x1015
+#define VIRTIO_PCI_DEVICE_ID16 0x1016
+#define VIRTIO_PCI_DEVICE_ID17 0x1017
+#define VIRTIO_PCI_DEVICE_ID18 0x1018
+#define VIRTIO_PCI_DEVICE_ID19 0x1019
+#define VIRTIO_PCI_DEVICE_ID1A 0x101a
+#define VIRTIO_PCI_DEVICE_ID1B 0x101b
+#define VIRTIO_PCI_DEVICE_ID1C 0x101c
+#define VIRTIO_PCI_DEVICE_ID1D 0x101d
+#define VIRTIO_PCI_DEVICE_ID1E 0x101e
+#define VIRTIO_PCI_DEVICE_ID1F 0x101f
+#define VIRTIO_PCI_DEVICE_ID20 0x1020
+#define VIRTIO_PCI_DEVICE_ID21 0x1021
+#define VIRTIO_PCI_DEVICE_ID22 0x1022
+#define VIRTIO_PCI_DEVICE_ID23 0x1023
+#define VIRTIO_PCI_DEVICE_ID24 0x1024
+#define VIRTIO_PCI_DEVICE_ID25 0x1025
+#define VIRTIO_PCI_DEVICE_ID26 0x1026
+#define VIRTIO_PCI_DEVICE_ID27 0x1027
+#define VIRTIO_PCI_DEVICE_ID28 0x1028
+#define VIRTIO_PCI_DEVICE_ID29 0x1029
+#define VIRTIO_PCI_DEVICE_ID2A 0x102a
+#define VIRTIO_PCI_DEVICE_ID2B 0x102b
+#define VIRTIO_PCI_DEVICE_ID2C 0x102c
+#define VIRTIO_PCI_DEVICE_ID2D 0x102d
+#define VIRTIO_PCI_DEVICE_ID2E 0x102e
+#define VIRTIO_PCI_DEVICE_ID2F 0x102f
+#define VIRTIO_PCI_DEVICE_ID30 0x1030
+#define VIRTIO_PCI_DEVICE_ID31 0x1031
+#define VIRTIO_PCI_DEVICE_ID32 0x1032
+#define VIRTIO_PCI_DEVICE_ID33 0x1033
+#define VIRTIO_PCI_DEVICE_ID34 0x1034
+#define VIRTIO_PCI_DEVICE_ID35 0x1035
+#define VIRTIO_PCI_DEVICE_ID36 0x1036
+#define VIRTIO_PCI_DEVICE_ID37 0x1037
+#define VIRTIO_PCI_DEVICE_ID38 0x1038
+#define VIRTIO_PCI_DEVICE_ID39 0x1039
+#define VIRTIO_PCI_DEVICE_ID3A 0x103a
+#define VIRTIO_PCI_DEVICE_ID3B 0x103b
+#define VIRTIO_PCI_DEVICE_ID3C 0x103c
+#define VIRTIO_PCI_DEVICE_ID3D 0x103d
+#define VIRTIO_PCI_DEVICE_ID3E 0x103e
+#define VIRTIO_PCI_DEVICE_ID3F 0x103f
+
+/**
+ * virtio pci transport driver private data
+ *
+ * @ioaddr:pci transport device register base
+ * @version:   pci transport device version
+ */
+struct virtio_pci_priv {
+   void __iomem *ioaddr;
+};
+
+static int virtio_pci_get_config(struct u

[U-Boot] [PATCH v3 27/31] virtio: pci: Support non-legacy PCI transport device

2018-10-15 Thread Bin Meng
By default QEMU creates legacy PCI transport devices, but we can
ask QEMU to create non-legacy one if we pass additional device
property/value pairs in the command line:

  -device virtio-blk-pci,disable-legacy=true,disable-modern=false

This adds a new driver driver to support non-legacy (modern) device
mode. Previous driver/file name is changed accordingly.

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

---

Changes in v3: None
Changes in v2:
- fix compiler warnings in 64-bit build
- adjust virtio_pci_find_capability() to avoid walking through capability
  list to find next one by ourselves

 drivers/virtio/Makefile|   2 +-
 .../virtio/{virtio_pci.c => virtio_pci_legacy.c}   |   6 +-
 drivers/virtio/virtio_pci_modern.c | 609 +
 3 files changed, 613 insertions(+), 4 deletions(-)
 rename drivers/virtio/{virtio_pci.c => virtio_pci_legacy.c} (98%)
 create mode 100644 drivers/virtio/virtio_pci_modern.c

diff --git a/drivers/virtio/Makefile b/drivers/virtio/Makefile
index 5ee6183..072fb56 100644
--- a/drivers/virtio/Makefile
+++ b/drivers/virtio/Makefile
@@ -5,6 +5,6 @@
 
 obj-y += virtio-uclass.o virtio_ring.o
 obj-$(CONFIG_VIRTIO_MMIO) += virtio_mmio.o
-obj-$(CONFIG_VIRTIO_PCI) += virtio_pci.o
+obj-$(CONFIG_VIRTIO_PCI) += virtio_pci_legacy.o virtio_pci_modern.o
 obj-$(CONFIG_VIRTIO_NET) += virtio_net.o
 obj-$(CONFIG_VIRTIO_BLK) += virtio_blk.o
diff --git a/drivers/virtio/virtio_pci.c b/drivers/virtio/virtio_pci_legacy.c
similarity index 98%
rename from drivers/virtio/virtio_pci.c
rename to drivers/virtio/virtio_pci_legacy.c
index a3f1083..08764ee 100644
--- a/drivers/virtio/virtio_pci.c
+++ b/drivers/virtio/virtio_pci_legacy.c
@@ -16,7 +16,7 @@
 #include 
 #include "virtio_pci.h"
 
-#define VIRTIO_PCI_DRV_NAME"virtio-pci"
+#define VIRTIO_PCI_DRV_NAME"virtio-pci.l"
 
 /* PCI device ID in the range 0x1000 to 0x103f */
 #define VIRTIO_PCI_VENDOR_ID   0x1af4
@@ -341,7 +341,7 @@ static const struct dm_virtio_ops virtio_pci_ops = {
.notify = virtio_pci_notify,
 };
 
-U_BOOT_DRIVER(virtio_pci) = {
+U_BOOT_DRIVER(virtio_pci_legacy) = {
.name   = VIRTIO_PCI_DRV_NAME,
.id = UCLASS_VIRTIO,
.ops= &virtio_pci_ops,
@@ -418,4 +418,4 @@ static struct pci_device_id virtio_pci_supported[] = {
{},
 };
 
-U_BOOT_PCI_DEVICE(virtio_pci, virtio_pci_supported);
+U_BOOT_PCI_DEVICE(virtio_pci_legacy, virtio_pci_supported);
diff --git a/drivers/virtio/virtio_pci_modern.c 
b/drivers/virtio/virtio_pci_modern.c
new file mode 100644
index 000..da76aea
--- /dev/null
+++ b/drivers/virtio/virtio_pci_modern.c
@@ -0,0 +1,609 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2018, Bin Meng 
+ *
+ * VirtIO PCI bus transport driver
+ * Ported from Linux drivers/virtio/virtio_pci*.c
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "virtio_pci.h"
+
+#define VIRTIO_PCI_DRV_NAME"virtio-pci.m"
+
+/* PCI device ID in the range 0x1040 to 0x107f */
+#define VIRTIO_PCI_VENDOR_ID   0x1af4
+#define VIRTIO_PCI_DEVICE_ID00 0x1040
+#define VIRTIO_PCI_DEVICE_ID01 0x1041
+#define VIRTIO_PCI_DEVICE_ID02 0x1042
+#define VIRTIO_PCI_DEVICE_ID03 0x1043
+#define VIRTIO_PCI_DEVICE_ID04 0x1044
+#define VIRTIO_PCI_DEVICE_ID05 0x1045
+#define VIRTIO_PCI_DEVICE_ID06 0x1046
+#define VIRTIO_PCI_DEVICE_ID07 0x1047
+#define VIRTIO_PCI_DEVICE_ID08 0x1048
+#define VIRTIO_PCI_DEVICE_ID09 0x1049
+#define VIRTIO_PCI_DEVICE_ID0A 0x104a
+#define VIRTIO_PCI_DEVICE_ID0B 0x104b
+#define VIRTIO_PCI_DEVICE_ID0C 0x104c
+#define VIRTIO_PCI_DEVICE_ID0D 0x104d
+#define VIRTIO_PCI_DEVICE_ID0E 0x104e
+#define VIRTIO_PCI_DEVICE_ID0F 0x104f
+#define VIRTIO_PCI_DEVICE_ID10 0x1050
+#define VIRTIO_PCI_DEVICE_ID11 0x1051
+#define VIRTIO_PCI_DEVICE_ID12 0x1052
+#define VIRTIO_PCI_DEVICE_ID13 0x1053
+#define VIRTIO_PCI_DEVICE_ID14 0x1054
+#define VIRTIO_PCI_DEVICE_ID15 0x1055
+#define VIRTIO_PCI_DEVICE_ID16 0x1056
+#define VIRTIO_PCI_DEVICE_ID17 0x1057
+#define VIRTIO_PCI_DEVICE_ID18 0x1058
+#define VIRTIO_PCI_DEVICE_ID19 0x1059
+#define VIRTIO_PCI_DEVICE_ID1A 0x105a
+#define VIRTIO_PCI_DEVICE_ID1B 0x105b
+#define VIRTIO_PCI_DEVICE_ID1C 0x105c
+#define VIRTIO_PCI_DEVICE_ID1D 0x105d
+#define VIRTIO_PCI_DEVICE_ID1E 0x105e
+#define VIRTIO_PCI_DEVICE_ID1F 0x105f
+#define VIRTIO_PCI_DEVICE_ID20 0x1060
+#define VIRTIO_PCI_DEVICE_ID21 0x1061
+#define VIRTIO_PCI_DEVICE_ID22 0x1062
+#define VIRTIO_PCI_DEVICE_ID23 0x1063
+#define VIRTIO_PCI_DEVICE_ID24 0x1064
+#define VIRTIO_PCI_DEVICE_ID25 0x1065
+#define VIRTIO_PCI_DEVICE_ID26 0x1066
+#define VIRTIO_PCI_DEVICE_ID27 0x1067
+#define VIRTIO_PCI_DEVICE_ID28 0x1068
+#define VIRTIO_PCI_DEVICE_ID29 0x1069
+#define VIRTIO_PCI_DEVICE_ID2A 0x106a
+#define VIRTIO_PCI_DEVICE_ID2B 0x106b
+#define VIRTIO_PCI_DEVICE_ID2C 0x106c
+#define VIRTIO_PCI_DEVICE_ID2D 0x106d
+#define VIRTIO_PCI_DEVICE_ID2E 0x106e
+#define VIRTIO_PCI_DEVICE_ID2F 0x106f
+#define VIRTIO_PCI_DEVIC

[U-Boot] [PATCH 2/2] net: mvpp2: increase PHY reset pulse

2018-10-15 Thread Baruch Siach
The default Linux PHY reset delay is 10ms. This is also the requirement
for Marvell 88E151x PHYs, which are likely to be used with this Ethernet
MAC.

Cc: Stefan Chulski 
Signed-off-by: Baruch Siach 
---
 drivers/net/mvpp2.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/mvpp2.c b/drivers/net/mvpp2.c
index b3b1fe1a0c41..f28b939b17dc 100644
--- a/drivers/net/mvpp2.c
+++ b/drivers/net/mvpp2.c
@@ -4806,7 +4806,7 @@ static void mvpp2_gpio_init(struct mvpp2_port *port)
 {
if (dm_gpio_is_valid(&port->phy_reset_gpio)) {
dm_gpio_set_value(&port->phy_reset_gpio, 1);
-   udelay(1000);
+   udelay(1);
dm_gpio_set_value(&port->phy_reset_gpio, 0);
}
 
-- 
2.19.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 1/2] net: mvpp2: fix polarity of PHY reset signal

2018-10-15 Thread Baruch Siach
The dm_gpio_set_value() call sets the logical level of the GPIO signal.
That is, it takes the GPIO_ACTIVE_{LOW,HIGH} property into account. The
driver needs to assert the reset, and then deassert it. Not the other
way around.

Cc: Stefan Chulski 
Signed-off-by: Baruch Siach 
---
 drivers/net/mvpp2.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/mvpp2.c b/drivers/net/mvpp2.c
index 62c0c2be0626..b3b1fe1a0c41 100644
--- a/drivers/net/mvpp2.c
+++ b/drivers/net/mvpp2.c
@@ -4805,9 +4805,9 @@ static int phy_info_parse(struct udevice *dev, struct 
mvpp2_port *port)
 static void mvpp2_gpio_init(struct mvpp2_port *port)
 {
if (dm_gpio_is_valid(&port->phy_reset_gpio)) {
-   dm_gpio_set_value(&port->phy_reset_gpio, 0);
-   udelay(1000);
dm_gpio_set_value(&port->phy_reset_gpio, 1);
+   udelay(1000);
+   dm_gpio_set_value(&port->phy_reset_gpio, 0);
}
 
if (dm_gpio_is_valid(&port->phy_tx_disable_gpio))
-- 
2.19.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] Please pull ARC changes

2018-10-15 Thread Alexey Brodkin
Hi Tom,

The following changes since commit 3d5ced9e22d32112a20f9dc0f5fb1f22ef088079:

  Merge tag 'dm-9oct18' of git://git.denx.de/u-boot-dm (2018-10-10 13:35:17 
-0400)

are available in the Git repository at:

  git://git.denx.de/u-boot-arc.git tags/arc-more-updates-for-2018.11-rc2

for you to fetch changes up to a2110918559b34219721cf31bbe8bd94a843e1ac:

  iot_dk: Link for eFlash (2018-10-12 15:14:41 +0300)


More fixes and improvements for ARC here:

Fixes:
 * Take care of global uninitialized variables
   They used to be put right after .bss section and were never
   zeroed as they should be. Now merged with normal .bss

Improvements:
 * Print more verbose CPU info for boards built on real silicon
 * Add support for SD-card detection on all ARC boards
 * Quite a few fixes for IoT DK
   - Support reset by command
   - Print of CPU freq on boot
   - Link for eFlash etc


Alexey Brodkin (9):
  iot_dk: Add localversion string
  iot_dk: Disable networking support
  ARC: make generic print_cpuinfo() weak
  iot_dk/hsdk: Implement its own print_cpuinfo()
  iot_dk: Implement board reset
  iot_dk: Add support of 136 MHz clock
  iot_dk: Save CPU clock value to gd->cpu_clk
  axs10x/emdk/hsdk/iot_dk: Implement board_mmc_getcd()
  iot_dk: Link for eFlash

 arch/arc/lib/cpu.c |  2 +-
 board/synopsys/axs10x/axs10x.c |  7 +++
 board/synopsys/emdk/emdk.c |  7 +++
 board/synopsys/hsdk/hsdk.c | 15 +++
 board/synopsys/iot_devkit/iot_devkit.c | 43 
++-
 configs/iot_devkit_defconfig   |  5 +++--
 6 files changed, 71 insertions(+), 8 deletions(-)

Regards,
Alexey
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [uboot-snps-arc] Please pull ARC changes

2018-10-15 Thread Alexey Brodkin
Hi Tom,

Not sure why that duplicate email appeared...
Either my mailer became crazy or I'm fatfingering :(

Sorry for that!

Though I'll re-send a pull-request as I did miss one important patch.

-Alexey

On Mon, 2018-10-15 at 10:22 +, Alexey Brodkin wrote:
> Hi Tom,
> 
> The following changes since commit 3d5ced9e22d32112a20f9dc0f5fb1f22ef088079:
> 
>   Merge tag 'dm-9oct18' of git://git.denx.de/u-boot-dm (2018-10-10 13:35:17 
> -0400)
> 
> are available in the Git repository at:
> 
>   git://git.denx.de/u-boot-arc.git tags/arc-more-updates-for-2018.11-rc2
> 
> for you to fetch changes up to a2110918559b34219721cf31bbe8bd94a843e1ac:
> 
>   iot_dk: Link for eFlash (2018-10-12 15:14:41 +0300)
> 
> 
> More fixes and improvements for ARC here:
> 
> Fixes:
>  * Take care of global uninitialized variables
>They used to be put right after .bss section and were never
>zeroed as they should be. Now merged with normal .bss
> 
> Improvements:
>  * Print more verbose CPU info for boards built on real silicon
>  * Add support for SD-card detection on all ARC boards
>  * Quite a few fixes for IoT DK
>- Support reset by command
>- Print of CPU freq on boot
>- Link for eFlash etc
> 
> 
> Alexey Brodkin (9):
>   iot_dk: Add localversion string
>   iot_dk: Disable networking support
>   ARC: make generic print_cpuinfo() weak
>   iot_dk/hsdk: Implement its own print_cpuinfo()
>   iot_dk: Implement board reset
>   iot_dk: Add support of 136 MHz clock
>   iot_dk: Save CPU clock value to gd->cpu_clk
>   axs10x/emdk/hsdk/iot_dk: Implement board_mmc_getcd()
>   iot_dk: Link for eFlash
> 
>  arch/arc/lib/cpu.c |  2 +-
>  board/synopsys/axs10x/axs10x.c |  7 +++
>  board/synopsys/emdk/emdk.c |  7 +++
>  board/synopsys/hsdk/hsdk.c | 15 +++
>  board/synopsys/iot_devkit/iot_devkit.c | 43 
> ++-
>  configs/iot_devkit_defconfig   |  5 +++--
>  6 files changed, 71 insertions(+), 8 deletions(-)
> 
> Regards,
> Alexey
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] Please pull ARC changes (fixed re-send)

2018-10-15 Thread Alexey Brodkin
Hi Tom,

This pull-request overrides the one sent last Friday:
https://lists.denx.de/pipermail/u-boot/2018-October/344211.html
as well as its duplicate sent for some reason today:
https://lists.denx.de/pipermail/u-boot/2018-October/344435.html

The following changes since commit 3d5ced9e22d32112a20f9dc0f5fb1f22ef088079:

  Merge tag 'dm-9oct18' of git://git.denx.de/u-boot-dm (2018-10-10 13:35:17 
-0400)

are available in the Git repository at:

  git://git.denx.de/u-boot-arc.git tags/arc-more-updates-for-2018.11-rc2-2

for you to fetch changes up to 6e63314f432d32d2ce12a51dafa78129e81fe9cf:

  ARC: Don't use COMMON section for global not-initialized variables 
(2018-10-15 13:35:17 +0300)


More fixes and improvements for ARC here:

Fixes (this time included for real):
 * Take care of global uninitialized variables
   They used to be put right after .bss section and were never
   zeroed as they should be. Now merged with normal .bss

Improvements:
 * Print more verbose CPU info for boards built on real silicon
 * Add support for SD-card detection on all ARC boards
 * Quite a few fixes for IoT DK
   - Support reset by command
   - Print of CPU freq on boot
   - Link for eFlash etc


Alexey Brodkin (10):
  iot_dk: Add localversion string
  iot_dk: Disable networking support
  ARC: make generic print_cpuinfo() weak
  iot_dk/hsdk: Implement its own print_cpuinfo()
  iot_dk: Implement board reset
  iot_dk: Add support of 136 MHz clock
  iot_dk: Save CPU clock value to gd->cpu_clk
  axs10x/emdk/hsdk/iot_dk: Implement board_mmc_getcd()
  iot_dk: Link for eFlash
  ARC: Don't use COMMON section for global not-initialized variables

 arch/arc/config.mk |  2 +-
 arch/arc/lib/cpu.c |  2 +-
 board/synopsys/axs10x/axs10x.c |  7 +++
 board/synopsys/emdk/emdk.c |  7 +++
 board/synopsys/hsdk/hsdk.c | 15 +++
 board/synopsys/iot_devkit/iot_devkit.c | 43 
++-
 configs/iot_devkit_defconfig   |  5 +++--
 7 files changed, 72 insertions(+), 9 deletions(-)

-Alexey
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH 0/7] Restructure the i.MX U-Boot documentation

2018-10-15 Thread Fabio Estevam
Hi Breno,

On Tue, Oct 9, 2018 at 10:54 PM Breno Matheus Lima  wrote:
>
> This patch set is restructuring and cleaning up the current i.MX documentation
> included in the U-Boot doc directory.
>
> The current i.MX documentation is in the root directory so we cannot easily
> check which one is i.MX related:
> http://git.denx.de/?p=u-boot/u-boot-imx.git;a=tree;f=doc;
>
> This series is restructuring the documentation only relevant for i.MX devices
> in a new imx directory:
>
> doc
> └── imx
> ├── common
> │   ├── imx25.txt
> │   ├── imx27.txt
> │   ├── imx5.txt
> │   ├── imx6.txt
> │   └── mxs.txt
> ├── hab
> │   └── habv4
> │├── encrypted_boot.txt
> │└── secure_boot.txt
> ├── misc
> │   └── sdp.txt
> └── mkimage
>  ├── imximage.txt
>  └── mxsimage.txt
>
> Subsequent patches will include more content in HAB documentation.
>
> Breno Lima (7):
>   doc: imx: reorganize i.MX documentation
>   doc: imx: Move SPD related info to the appropriate doc
>   doc: imx: mkimage: reorganize i.MX mkimage documentation
>   doc: imx: Reorganize i.MX SoC common documentation
>   doc: imx: hab: Reorganize High Assurance Boot documentation
>   doc: imx: misc: Reorganize miscellaneous documentation
>   doc: imx: Improve i.MX documentation naming

I think this cleanup makes things better organized, thanks:

Reviewed-by: Fabio Estevam 
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 1/1] board: ge: bx50v3: Change maintainer

2018-10-15 Thread Fabien Lahoudere
While using ./scripts/get_maintainer.pl I detect that the Maintainer name
and address for bx50v3 boards are not valid.
The new maintainer for GE bx50v3 products must be Ian Ray.

Signed-off-by: Fabien Lahoudere 
---
 board/ge/bx50v3/MAINTAINERS | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/board/ge/bx50v3/MAINTAINERS b/board/ge/bx50v3/MAINTAINERS
index a44edd4..91d5c86 100644
--- a/board/ge/bx50v3/MAINTAINERS
+++ b/board/ge/bx50v3/MAINTAINERS
@@ -1,5 +1,5 @@
 GE_BX50V3 BOARD
-M: Martin Donnelly 
+M: Ian Ray 
 S: Maintained
 F: board/ge/bx50v3/
 F: include/configs/ge_bx50v3.h
-- 
1.8.3.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 0/2] board: ge: bx50v3: Fix screen flickering

2018-10-15 Thread Fabien Lahoudere
This patchset solves screen flickering observed at bootup on b650v3.

Steps to reproduce:
1) Connect B650 to power.
2) Switch On the Monitor.
3) Observe the display.

Ian Ray (2):
  board: ge: bx50v3: correct LDB clock
  board: ge: bx50v3: b{4,6}50v3 modeline

 board/ge/bx50v3/bx50v3.c | 32 +++-
 1 file changed, 19 insertions(+), 13 deletions(-)

-- 
1.8.3.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH] ARM: Samsung: Add Exynos5422-based Odroid HC2 support

2018-10-15 Thread Marek Szyprowski
Hi All,


On 2018-10-14 18:49, Meul, Dirk wrote:
> Odroid HC2 board is based on Odroid XU4 board, like the Odroid HC1.
>
> The linux kernel does not provide a hc2 DTB so the hc1 DTB is also used
> for the Odroid HC2.
>
> Signed-off-by: Dirk Meul 

I don't have access to HC2, but the code looks reasonable and does
similar things
I did while adding support for Odroid HC1.

Acked-by: Marek Szyprowski 

> ---
>  board/samsung/common/exynos5-dt-types.c | 16 +---
>  board/samsung/common/exynos5-dt.c   |  4 ++--
>  configs/odroid-xu3_defconfig    |  2 +-
>  include/samsung/exynos5-dt-types.h  |  2 ++
>  4 files changed, 18 insertions(+), 6 deletions(-)
>
> diff --git a/board/samsung/common/exynos5-dt-types.c
> b/board/samsung/common/exynos5-dt-types.c
> index 4473968db6..7a86e91877 100644
> --- a/board/samsung/common/exynos5-dt-types.c
> +++ b/board/samsung/common/exynos5-dt-types.c
> @@ -24,14 +24,15 @@ static const struct udevice_id board_ids[] = {
>  };
>  
>  /**
> - * Odroix XU3/XU4/HC1 board revisions (from
> HC1_MAIN_REV0.1_20170630.pdf):
> + * Odroix XU3/XU4/HC1/HC2 board revisions (from
> HC1+_HC2_MAIN_REV0.1_20171017.pdf):
>   * Rev   ADCmax  Board
>   * 0.1 0 XU3 0.1
>   * 0.2   372 XU3 0.2 | XU3L - no DISPLAYPORT (probe I2C0:0x40 /
> INA231)
>   * 0.3  1280 XU4 0.1
>   * 0.4   739 XU4 0.2
>   * 0.5  1016 XU4+Air0.1 (Passive cooling)
> - * 0.6  1308 XU4S 0.1 (HC1)
> + * 0.6  1309 XU4-HC1 0.1
> + * 0.7  1470 XU4-HC1+ 0.1 (HC2)
>   * Use +1% for ADC value tolerance in the array below, the code loops
> until
>   * the measured ADC value is lower than then ADCmax from the array.
>   */
> @@ -39,7 +40,8 @@ struct odroid_rev_info odroid_info[] = {
>      { EXYNOS5_BOARD_ODROID_XU3_REV01, 1, 10, "xu3" },
>      { EXYNOS5_BOARD_ODROID_XU3_REV02, 2, 375, "xu3" },
>      { EXYNOS5_BOARD_ODROID_XU4_REV01, 1, 1293, "xu4" },
> -    { EXYNOS5_BOARD_ODROID_HC1_REV01, 1, 1321, "hc1" },
> +    { EXYNOS5_BOARD_ODROID_HC1_REV01, 1, 1322, "hc1" },
> +    { EXYNOS5_BOARD_ODROID_HC2_REV01, 1, 1484, "hc1" },
>      { EXYNOS5_BOARD_ODROID_UNKNOWN, 0, 4095, "unknown" },
>  };
>  
> @@ -144,6 +146,14 @@ bool board_is_odroidhc1(void)
>      return false;
>  }
>  
> +bool board_is_odroidhc2(void)
> +{
> +    if (gd->board_type == EXYNOS5_BOARD_ODROID_HC2_REV01)
> +        return true;
> +
> +    return false;
> +}
> +
>  bool board_is_generic(void)
>  {
>      if (gd->board_type == EXYNOS5_BOARD_GENERIC)
> diff --git a/board/samsung/common/exynos5-dt.c
> b/board/samsung/common/exynos5-dt.c
> index 8c3a9ea564..c183965b92 100644
> --- a/board/samsung/common/exynos5-dt.c
> +++ b/board/samsung/common/exynos5-dt.c
> @@ -179,7 +179,7 @@ char *get_dfu_alt_system(char *interface, char
> *devstr)
>  {
>      char *info = "Not supported!";
>  
> -    if (board_is_odroidxu4() || board_is_odroidhc1())
> +    if (board_is_odroidxu4() || board_is_odroidhc1() ||
> board_is_odroidhc2())
>          return info;
>  
>      return env_get("dfu_alt_system");
> @@ -192,7 +192,7 @@ char *get_dfu_alt_boot(char *interface, char *devstr)
>      char *alt_boot;
>      int dev_num;
>  
> -    if (board_is_odroidxu4() || board_is_odroidhc1())
> +    if (board_is_odroidxu4() || board_is_odroidhc1() ||
> board_is_odroidhc2())
>          return info;
>  
>      dev_num = simple_strtoul(devstr, NULL, 10);
> diff --git a/configs/odroid-xu3_defconfig b/configs/odroid-xu3_defconfig
> index 258b9781cc..d5c7cc7129 100644
> --- a/configs/odroid-xu3_defconfig
> +++ b/configs/odroid-xu3_defconfig
> @@ -2,7 +2,7 @@ CONFIG_ARM=y
>  CONFIG_ARCH_EXYNOS=y
>  CONFIG_SYS_TEXT_BASE=0x43E0
>  CONFIG_ARCH_EXYNOS5=y
> -CONFIG_IDENT_STRING=" for ODROID-XU3/XU4/HC1"
> +CONFIG_IDENT_STRING=" for ODROID-XU3/XU4/HC1/HC2"
>  CONFIG_DISTRO_DEFAULTS=y
>  CONFIG_NR_DRAM_BANKS=8
>  # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
> diff --git a/include/samsung/exynos5-dt-types.h
> b/include/samsung/exynos5-dt-types.h
> index 8e11af30d1..8fe08fe211 100644
> --- a/include/samsung/exynos5-dt-types.h
> +++ b/include/samsung/exynos5-dt-types.h
> @@ -9,6 +9,7 @@ enum {
>      EXYNOS5_BOARD_ODROID_XU3_REV02,
>      EXYNOS5_BOARD_ODROID_XU4_REV01,
>      EXYNOS5_BOARD_ODROID_HC1_REV01,
> +    EXYNOS5_BOARD_ODROID_HC2_REV01,
>      EXYNOS5_BOARD_ODROID_UNKNOWN,
>  
>      EXYNOS5_BOARD_COUNT,
> @@ -25,5 +26,6 @@ bool board_is_generic(void);
>  bool board_is_odroidxu3(void);
>  bool board_is_odroidxu4(void);
>  bool board_is_odroidhc1(void);
> +bool board_is_odroidhc2(void);
>  
>  #endif
> -- 
> 2.17.1
>
>

Best regards
-- 
Marek Szyprowski, PhD
Samsung R&D Institute Poland

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 1/2] board: ge: bx50v3: correct LDB clock

2018-10-15 Thread Fabien Lahoudere
From: Ian Ray 

Use Video PLL to provide 65MHz for all displays.

Signed-off-by: Ian Ray 
Signed-off-by: Fabien Lahoudere 
---
 board/ge/bx50v3/bx50v3.c | 30 +-
 1 file changed, 17 insertions(+), 13 deletions(-)

diff --git a/board/ge/bx50v3/bx50v3.c b/board/ge/bx50v3/bx50v3.c
index b2d065c..f07141b 100644
--- a/board/ge/bx50v3/bx50v3.c
+++ b/board/ge/bx50v3/bx50v3.c
@@ -426,14 +426,22 @@ static void enable_videopll(void)
 
setbits_le32(&ccm->analog_pll_video, BM_ANADIG_PLL_VIDEO_POWERDOWN);
 
-   /* set video pll to 910MHz (24MHz * (37+11/12))
-   * video pll post div to 910/4 = 227.5MHz
-   */
+   /* PLL_VIDEO  455MHz (24MHz * (37+11/12) / 2)
+*   |
+* PLL5
+*   |
+* CS2CDR[LDB_DI0_CLK_SEL]
+*   |
+*   +> LDB_DI0_SERIAL_CLK_ROOT
+*   |
+*   +--> CSCMR2[LDB_DI0_IPU_DIV] --> LDB_DI0_IPU  455 / 7 = 65 MHz
+*/
+
clrsetbits_le32(&ccm->analog_pll_video,
BM_ANADIG_PLL_VIDEO_DIV_SELECT |
BM_ANADIG_PLL_VIDEO_POST_DIV_SELECT,
BF_ANADIG_PLL_VIDEO_DIV_SELECT(37) |
-   BF_ANADIG_PLL_VIDEO_POST_DIV_SELECT(0));
+   BF_ANADIG_PLL_VIDEO_POST_DIV_SELECT(1));
 
writel(BF_ANADIG_PLL_VIDEO_NUM_A(11), &ccm->analog_pll_video_num);
writel(BF_ANADIG_PLL_VIDEO_DENOM_B(12), &ccm->analog_pll_video_denom);
@@ -459,8 +467,8 @@ static void setup_display_b850v3(void)
 
enable_videopll();
 
-   /* IPU1 D0 clock is 227.5 / 3.5 = 65MHz */
-   clrbits_le32(&mxc_ccm->cscmr2, MXC_CCM_CSCMR2_LDB_DI0_IPU_DIV);
+   /* IPU1 DI0 clock is 455MHz / 7 = 65MHz */
+   setbits_le32(&mxc_ccm->cscmr2, MXC_CCM_CSCMR2_LDB_DI0_IPU_DIV);
 
imx_setup_hdmi();
 
@@ -507,7 +515,7 @@ static void setup_display_bx50v3(void)
 */
mdelay(200);
 
-   /* IPU1 DI0 clock is 480/7 = 68.5 MHz */
+   /* IPU1 DI0 clock is 455MHz / 7 = 65MHz */
setbits_le32(&mxc_ccm->cscmr2, MXC_CCM_CSCMR2_LDB_DI0_IPU_DIV);
 
/* Set LDB_DI0 as clock source for IPU_DI0 */
@@ -683,12 +691,8 @@ int board_early_init_f(void)
setup_iomux_uart();
 
 #if defined(CONFIG_VIDEO_IPUV3)
-   if (is_b850v3())
-   /* Set LDB clock to Video PLL */
-   select_ldb_di_clock_source(MXC_PLL5_CLK);
-   else
-   /* Set LDB clock to USB PLL */
-   select_ldb_di_clock_source(MXC_PLL3_SW_CLK);
+   /* Set LDB clock to Video PLL */
+   select_ldb_di_clock_source(MXC_PLL5_CLK);
 #endif
return 0;
 }
-- 
1.8.3.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 1/1] board: ge: bx50v3: fix initialization of i2c bus0

2018-10-15 Thread Fabien Lahoudere
From: Dan Cimpoca 

I2C bus 0 was not initialized correctly. There is an offset between i2c
index and the structure number of pad info. So i2c bus 0 can be in an
inconsistent state.

This problem become visible on B{4,6}50v3 with the CPUC HW watchdog enabled.
Sometimes when the CPUC HW watchdog interrupted the boot process, U-Boot was
not able to read VPD from I2C/EEPROM and the system failed to boot up again,
because a device connected to that bus was stuck in data transfer state (from
previous boot attempt) and there was no method to recover (struct
mxc_i2c_bus::idle_bus_fn was not set) courtesy of incorrect initialization.

Signed-off-by: Dan Cimpoca 
Signed-off-by: Fabien Lahoudere 
---
 board/ge/bx50v3/bx50v3.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/board/ge/bx50v3/bx50v3.c b/board/ge/bx50v3/bx50v3.c
index 2eb1b65..2458525 100644
--- a/board/ge/bx50v3/bx50v3.c
+++ b/board/ge/bx50v3/bx50v3.c
@@ -714,9 +714,9 @@ static void set_confidx(const struct vpd_cache* vpd)
 
 int board_init(void)
 {
-   setup_i2c(1, CONFIG_SYS_I2C_SPEED, 0x7f, &i2c_pad_info1);
-   setup_i2c(2, CONFIG_SYS_I2C_SPEED, 0x7f, &i2c_pad_info2);
-   setup_i2c(3, CONFIG_SYS_I2C_SPEED, 0x7f, &i2c_pad_info3);
+   setup_i2c(0, CONFIG_SYS_I2C_SPEED, 0x7f, &i2c_pad_info1);
+   setup_i2c(1, CONFIG_SYS_I2C_SPEED, 0x7f, &i2c_pad_info2);
+   setup_i2c(2, CONFIG_SYS_I2C_SPEED, 0x7f, &i2c_pad_info3);
 
read_vpd(CONFIG_SYS_I2C_EEPROM_BUS);
 
-- 
1.8.3.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH 2/2] board: ge: bx50v3: b{4,6}50v3 modeline

2018-10-15 Thread Fabien Lahoudere
From: Ian Ray 

The b{4,6}50v3 kernel framebuffer console requires a modeline otherwise
the LVDS panel shows garbage.

Signed-off-by: Ian Ray 
Signed-off-by: Fabien Lahoudere 
---
 board/ge/bx50v3/bx50v3.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/board/ge/bx50v3/bx50v3.c b/board/ge/bx50v3/bx50v3.c
index f07141b..2eb1b65 100644
--- a/board/ge/bx50v3/bx50v3.c
+++ b/board/ge/bx50v3/bx50v3.c
@@ -809,6 +809,8 @@ int board_late_init(void)
 
if (is_b850v3())
env_set("videoargs", "video=DP-1:1024x768@60 
video=HDMI-A-1:1024x768@60");
+   else
+   env_set("videoargs", "video=LVDS-1:1024x768@65");
 
/* board specific pmic init */
pmic_init();
-- 
1.8.3.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [U-Boot, BUG] snow: mmc: SD card access broken: unable to select a mode

2018-10-15 Thread Guillaume Gardet

Hi,

Le 16/05/2018 à 09:22, Guillaume Gardet a écrit :

Hi Jaehoon,


Le 26/04/2018 à 15:15, Guillaume Gardet a écrit :



Le 26/04/2018 à 12:31, Jaehoon Chung a écrit :

Hi,

On 04/09/2018 09:02 PM, Guillaume Gardet wrote:

Hi Jaehoon,

There are problems with SD card access on Samsung Chromebook (snow) with latest 
master (and also 2018.05-rc1 and 2018.03).

eMMC is ok, but SD card access leads to 'unable to select a mode' problem. If I 
disable HS mode, I can access the SD card without problem:



Once we try to select HS mode, all access to SD card result in failure, even 
when trying to setup a lower frequency mode, including SD legacy at 25 MHz.

Any idea what is going? Maybe you have fixes pending?

Sorry for late. Hmm. I will check your issue. Just disable MMC_MODE_HS, then 
it's working fine?
or HS_52MHz?


I tried to disable HS_52MHz only and it did not fix the problem. Then I tried 
to disable both HS and HS_52MHz and it fixed the problem.


Any progress on this problem?



Ping again.
The problem is still there in u-boot v2018.11-rc1.


Guillaume




Guillaume




Guillaume



Best Regards,
Jaehoon Chung



Guillaume

diff --git a/drivers/mmc/dw_mmc.c b/drivers/mmc/dw_mmc.c
index 23f642980bf..28f4fa0f213 100644
--- a/drivers/mmc/dw_mmc.c
+++ b/drivers/mmc/dw_mmc.c
@@ -508,7 +508,8 @@ void dwmci_setup_cfg(struct mmc_config *cfg, struct 
dwmci_host *host,
       cfg->host_caps |= MMC_MODE_4BIT;
       cfg->host_caps &= ~MMC_MODE_8BIT;
   }
-    cfg->host_caps |= MMC_MODE_HS | MMC_MODE_HS_52MHz;
+    /* Temp workaround for Chromebook snow to avoid the 'unable to select a 
mode' error */
+//     cfg->host_caps |= MMC_MODE_HS | MMC_MODE_HS_52MHz;

   cfg->b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT;
   }








___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH] drivers: serial: probe all serial devices

2018-10-15 Thread Vabhav Sharma
Serial subsystem search and probe only one first serial
device and unable to use remaining available UART devices

This patch changes the logic to probe all available serial devices
using platform data or device tree in DM model in order to use all
UART devices

Signed-off-by: Vabhav Sharma 
---
 drivers/serial/Kconfig | 12 
 drivers/serial/serial-uclass.c | 42 ++
 2 files changed, 54 insertions(+)

diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
index 597db4b..d6451b1 100644
--- a/drivers/serial/Kconfig
+++ b/drivers/serial/Kconfig
@@ -133,6 +133,18 @@ config SERIAL_SEARCH_ALL
 
  If unsure, say N.
 
+config SERIAL_PROBE_ALL
+   bool "Probe all available serial devices"
+   depends on DM_SERIAL
+   help
+The serial subsystem only probe for single serial device, but does
+not probe for remaining available devices.
+With this option set,we make probing for all available devices
+mandatory.
+
+If probing is not required for all remaining available
+devices other than default current console device, say N.
+
 config SPL_DM_SERIAL
bool "Enable Driver Model for serial drivers in SPL"
depends on DM_SERIAL && SPL_DM
diff --git a/drivers/serial/serial-uclass.c b/drivers/serial/serial-uclass.c
index e50f0aa..405e60e 100644
--- a/drivers/serial/serial-uclass.c
+++ b/drivers/serial/serial-uclass.c
@@ -82,6 +82,13 @@ static void serial_find_console_or_panic(void)
uclass_first_device(UCLASS_SERIAL, &dev);
if (dev) {
gd->cur_serial_dev = dev;
+#ifdef CONFIG_SERIAL_PROBE_ALL
+   /* Scanning uclass to probe all devices */
+   for (;
+dev;
+uclass_next_device(&dev))
+   ;
+#endif
return;
}
} else if (CONFIG_IS_ENABLED(OF_CONTROL) && blob) {
@@ -92,11 +99,25 @@ static void serial_find_console_or_panic(void)
if (np && !uclass_get_device_by_ofnode(UCLASS_SERIAL,
np_to_ofnode(np), &dev)) {
gd->cur_serial_dev = dev;
+#ifdef CONFIG_SERIAL_PROBE_ALL
+   /* Scanning uclass to probe all devices */
+   for (;
+dev;
+uclass_next_device(&dev))
+   ;
+#endif
return;
}
} else {
if (!serial_check_stdout(blob, &dev)) {
gd->cur_serial_dev = dev;
+#ifdef CONFIG_SERIAL_PROBE_ALL
+   /* Scanning uclass to probe all devices */
+   for (;
+dev;
+uclass_next_device(&dev))
+   ;
+#endif
return;
}
}
@@ -121,6 +142,13 @@ static void serial_find_console_or_panic(void)
!uclass_get_device(UCLASS_SERIAL, INDEX, &dev)) {
if (dev->flags & DM_FLAG_ACTIVATED) {
gd->cur_serial_dev = dev;
+#ifdef CONFIG_SERIAL_PROBE_ALL
+   /* Scanning uclass to probe all devices */
+   for (;
+dev;
+uclass_next_device(&dev))
+   ;
+#endif
return;
}
}
@@ -132,6 +160,13 @@ static void serial_find_console_or_panic(void)
if (!ret) {
/* Device did succeed probing */
gd->cur_serial_dev = dev;
+#ifdef CONFIG_SERIAL_PROBE_ALL
+   /* Scanning uclass to probe all devices */
+   for (;
+dev;
+uclass_next_device(&dev))
+   ;
+#endif
return;
}
}
@@ -140,6 +175,13 @@ static void serial_find_console_or_panic(void)
!uclass_get_device(UCLASS_SERIAL, INDEX, &dev) ||
(!uclass_first_device(UCLASS_SERIAL, &dev) && dev)) {
gd->cur_serial_dev = dev;
+#ifdef CONFIG_SERIAL_PROBE_ALL
+   /* Scanning uclass to probe all devices */
+   for (;
+dev;
+uclass_next_device(&dev))
+   ;
+#endif
   

Re: [U-Boot] [PATCH] drivers: serial: probe all serial devices

2018-10-15 Thread Bin Meng
On Mon, Oct 15, 2018 at 8:15 PM Vabhav Sharma  wrote:
>
> Serial subsystem search and probe only one first serial
> device and unable to use remaining available UART devices
>
> This patch changes the logic to probe all available serial devices
> using platform data or device tree in DM model in order to use all
> UART devices
>
> Signed-off-by: Vabhav Sharma 
> ---
>  drivers/serial/Kconfig | 12 
>  drivers/serial/serial-uclass.c | 42 
> ++
>  2 files changed, 54 insertions(+)
>

Looks more and more devices have requirement to be probed during boot.
Guess we should handle such in a unified way?

Regards,
Bin
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] Pull request: u-boot-spi/master

2018-10-15 Thread Tom Rini
On Fri, Oct 12, 2018 at 11:45:13AM +0530, Jagan Teki wrote:

> Hi Tom,
> 
> Please pull this PR.
> 
> thanks,
> Jagan.
> 
> The following changes since commit 0a60a81ba3860946551cb79aa6486aa076e357f3:
> 
>   Kconfig: sandbox: enable cmd_avb and dependencies (2018-10-07 13:34:19 
> -0400)
> 
> are available in the Git repository at:
> 
>   git://git.denx.de/u-boot-spi.git master
> 
> for you to fetch changes up to 5c391486b411025785e064f160d248bef31b3d28:
> 
>   sf: Add MICRON manufacturer id (2018-10-12 11:37:49 +0530)
> 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] Pull request: u-boot-sunxi/master

2018-10-15 Thread Tom Rini
On Fri, Oct 12, 2018 at 11:46:36AM +0530, Jagan Teki wrote:

> Hi Tom,
> 
> Please pull this PR.
> 
> thanks,
> Jagan.
> 
> The following changes since commit 0a60a81ba3860946551cb79aa6486aa076e357f3:
> 
>   Kconfig: sandbox: enable cmd_avb and dependencies (2018-10-07 13:34:19 
> -0400)
> 
> are available in the Git repository at:
> 
>   git://git.denx.de/u-boot-sunxi.git sunxi
> 
> for you to fetch changes up to 90de3969be48924114f2d725923e12f32bf7796e:
> 
>   sunxi: fix DRAM gate/reset sequence of H6 (2018-10-10 12:04:07 +0530)
> 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] Please pull ARC changes (fixed re-send)

2018-10-15 Thread Tom Rini
On Mon, Oct 15, 2018 at 10:39:46AM +, Alexey Brodkin wrote:

> Hi Tom,
> 
> This pull-request overrides the one sent last Friday:
> https://lists.denx.de/pipermail/u-boot/2018-October/344211.html
> as well as its duplicate sent for some reason today:
> https://lists.denx.de/pipermail/u-boot/2018-October/344435.html
> 
> The following changes since commit 3d5ced9e22d32112a20f9dc0f5fb1f22ef088079:
> 
>   Merge tag 'dm-9oct18' of git://git.denx.de/u-boot-dm (2018-10-10 13:35:17 
> -0400)
> 
> are available in the Git repository at:
> 
>   git://git.denx.de/u-boot-arc.git tags/arc-more-updates-for-2018.11-rc2-2
> 
> for you to fetch changes up to 6e63314f432d32d2ce12a51dafa78129e81fe9cf:
> 
>   ARC: Don't use COMMON section for global not-initialized variables 
> (2018-10-15 13:35:17 +0300)
> 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v2] socfpga: clean up sfp generation

2018-10-15 Thread Westergreen, Dalon
On Sun, 2018-10-14 at 19:58 +0200, Marek Vasut wrote:
> On 10/13/2018 12:13 AM, Dalon Westergreen wrote:
> From: Dalon Westergreen 
> Move the sfp file generation entirely to the root Makefile.  Thismeans that
> the u-boot-spl.sfp will only be generated when requiredand only for the
> socfpga variants that require it.
> sfp generation is now entirely controlled by CONFIG_BUILD_TARGETbeing set to
> either spl/u-boot-spl.sfp or more likelyu-boot-with-spl.sfp
> Signed-off-by: Dalon Westergreen 
> ---v2:  -> condense changes to 1 patch to avoid breaking git bisect---
> Makefile | 11 --- scripts/Makefile.spl | 12  2
> files changed, 8 insertions(+), 15 deletions(-)
> diff --git a/Makefile b/Makefileindex aadd1ec8c6..16ce14d071 100644---
> a/Makefile+++ b/Makefile@@ -1207,6 +1207,14 @@ u-boot.spr: spl/u-boot-spl.img
> u-boot.img FORCE  $(call if_changed,pad_cat)  ifneq
> ($(CONFIG_ARCH_SOCFPGA),)+ifdef CONFIG_TARGET_SOCFPGA_ARRIA10
> Shouldn't that be ifneq ($(CONFIG),) ?, just like the line above ?

That was just cut and paste from scripts/Makefile.spl, but i will change it.
--dalon
> +MKIMAGEFLAGS_$(SPL_BIN).sfp = -T
> socfpgaimage_v1+else+MKIMAGEFLAGS_$(SPL_BIN).sfp = -T
> socfpgaimage+endif+spl/u-boot-spl.sfp: spl/u-boot-spl.bin FORCE+  $(call
> if_changed,mkimage)
> Otherwise it looks good I think :)
> 


smime.p7s
Description: S/MIME cryptographic signature
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v2] socfpga: clean up sfp generation

2018-10-15 Thread Marek Vasut
On 10/15/2018 03:42 PM, Westergreen, Dalon wrote:
> On Sun, 2018-10-14 at 19:58 +0200, Marek Vasut wrote:
>> On 10/13/2018 12:13 AM, Dalon Westergreen wrote:
>> From: Dalon Westergreen > >
>>
>> Move the sfp file generation entirely to the root Makefile.  This
>> means that the u-boot-spl.sfp will only be generated when required
>> and only for the socfpga variants that require it.
>>
>> sfp generation is now entirely controlled by CONFIG_BUILD_TARGET
>> being set to either spl/u-boot-spl.sfp or more likely
>> u-boot-with-spl.sfp
>>
>> Signed-off-by: Dalon Westergreen > >
>>
>> ---
>> v2:
>>   -> condense changes to 1 patch to avoid breaking git bisect
>> ---
>>  Makefile | 11 ---
>>  scripts/Makefile.spl | 12 
>>  2 files changed, 8 insertions(+), 15 deletions(-)
>>
>> diff --git a/Makefile b/Makefile
>> index aadd1ec8c6..16ce14d071 100644
>> --- a/Makefile
>> +++ b/Makefile
>> @@ -1207,6 +1207,14 @@ u-boot.spr: spl/u-boot-spl.img u-boot.img FORCE
>>  $(call if_changed,pad_cat)
>>  
>>  ifneq ($(CONFIG_ARCH_SOCFPGA),)
>> +ifdef CONFIG_TARGET_SOCFPGA_ARRIA10
>>
>> Shouldn't that be ifneq ($(CONFIG),) ?, just like the line above ?
> 
> That was just cut and paste from scripts/Makefile.spl, but i will change it.

Thanks

-- 
Best regards,
Marek Vasut
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [Patch v3] socfpga: clean up sfp generation

2018-10-15 Thread Dalon Westergreen
From: Dalon Westergreen 

Move the sfp file generation entirely to the root Makefile.  This
means that the u-boot-spl.sfp will only be generated when required
and only for the socfpga variants that require it.

sfp generation is now entirely controlled by CONFIG_BUILD_TARGET
being set to either spl/u-boot-spl.sfp or more likely
u-boot-with-spl.sfp

Signed-off-by: Dalon Westergreen 

---
v3:
  -> Change ifdef to ifneq
  -> Fix error, should not use $(SPL_BIN) as it was not defined
 in Makefile
v2:
  -> condense changes to 1 patch to avoid breaking git bisect
---
 Makefile | 11 ---
 scripts/Makefile.spl | 12 
 2 files changed, 8 insertions(+), 15 deletions(-)

diff --git a/Makefile b/Makefile
index aadd1ec8c6..5f03e534a5 100644
--- a/Makefile
+++ b/Makefile
@@ -1207,6 +1207,14 @@ u-boot.spr: spl/u-boot-spl.img u-boot.img FORCE
$(call if_changed,pad_cat)
 
 ifneq ($(CONFIG_ARCH_SOCFPGA),)
+ifneq ($(CONFIG_TARGET_SOCFPGA_ARRIA10),)
+MKIMAGEFLAGS_u-boot-spl.sfp = -T socfpgaimage_v1
+else
+MKIMAGEFLAGS_u-boot-spl.sfp = -T socfpgaimage
+endif
+spl/u-boot-spl.sfp: spl/u-boot-spl.bin FORCE
+   $(call if_changed,mkimage)
+
 quiet_cmd_socboot = SOCBOOT $@
 cmd_socboot = cat  spl/u-boot-spl.sfp spl/u-boot-spl.sfp   \
spl/u-boot-spl.sfp spl/u-boot-spl.sfp   \
@@ -1542,9 +1550,6 @@ spl/sunxi-spl.bin: spl/u-boot-spl
 spl/sunxi-spl-with-ecc.bin: spl/sunxi-spl.bin
@:
 
-spl/u-boot-spl.sfp: spl/u-boot-spl
-   @:
-
 spl/boot.bin: spl/u-boot-spl
@:
 
diff --git a/scripts/Makefile.spl b/scripts/Makefile.spl
index 7416abec62..a58113cee2 100644
--- a/scripts/Makefile.spl
+++ b/scripts/Makefile.spl
@@ -198,10 +198,6 @@ ifdef CONFIG_SAMSUNG
 ALL-y  += $(obj)/$(BOARD)-spl.bin
 endif
 
-ifdef CONFIG_ARCH_SOCFPGA
-ALL-y  += $(obj)/$(SPL_BIN).sfp
-endif
-
 ifdef CONFIG_ARCH_SUNXI
 ALL-y  += $(obj)/sunxi-spl.bin
 
@@ -324,14 +320,6 @@ LDFLAGS_$(SPL_BIN) += -Ttext $(CONFIG_SPL_TEXT_BASE)
 endif
 endif
 
-ifdef CONFIG_TARGET_SOCFPGA_ARRIA10
-MKIMAGEFLAGS_$(SPL_BIN).sfp = -T socfpgaimage_v1
-else
-MKIMAGEFLAGS_$(SPL_BIN).sfp = -T socfpgaimage
-endif
-$(obj)/$(SPL_BIN).sfp: $(obj)/$(SPL_BIN).bin FORCE
-   $(call if_changed,mkimage)
-
 quiet_cmd_mksunxiboot = MKSUNXI $@
 cmd_mksunxiboot = $(objtree)/tools/mksunxiboot \
--default-dt $(CONFIG_DEFAULT_DEVICE_TREE) $< $@
-- 
2.17.2

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v11 0/6] efi_loader: Code refactoring and improvement

2018-10-15 Thread Simon Glass
This collects the patches previously sent to break up the very large
functions in efi_loader into smaller pieces. Now that the other sandbox
stuff is applied, perhaps it is time to apply these patches.

This also adds a few new patches to fix more recent breakages.
Unfortunately we still cannot enable the efi loader tests since one of
the tests fails. Thus we should expect additional failures to appear
until that is resolved.

Changes in v11:
- Add a new patch to drop setup_ok
- Add a new patch to put CPUs under a cpu-bus node
- Drop patches previously applied
- Fix the EFI code that has since been added and relies on broken behaviour

Changes in v9:
- Add comments to bootefi_test_prepare() about the memset()s

Changes in v7:
- Drop patch "efi: Init the 'rows' and 'cols' variables"
- Drop patches previous applied

Changes in v5:
- Drop call to efi_init_obj_list() which is now done in do_bootefi()
- Introduce load_options_path to specifyc U-Boot env var for load_options_path
- Rebase to master

Changes in v4:
- Rebase to master

Changes in v3:
- Add new patch to rename bootefi_test_finish() to bootefi_run_finish()
- Add new patch to split out test init/uninit into functions
- Add patch to create a function to set up for running EFI code
- Drop incorrect map_sysmem() in write_smbios_table()

Simon Glass (6):
  sandbox: Put CPUs under a cpu-bus node
  efi_loader: Drop setup_ok
  sandbox: smbios: Update to support sandbox
  efi: Split out test init/uninit into functions
  efi: Create a function to set up for running EFI code
  efi: Rename bootefi_test_finish() to bootefi_run_finish()

 arch/sandbox/dts/test.dts   |  18 ++--
 cmd/bootefi.c   | 146 +---
 include/efi_selftest.h  |   2 -
 lib/efi_loader/efi_smbios.c |  20 +++--
 lib/efi_selftest/efi_selftest.c |  14 +--
 lib/smbios.c|  32 +--
 6 files changed, 149 insertions(+), 83 deletions(-)

-- 
2.19.1.331.ge82ca0e54c-goog

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v11 3/6] sandbox: smbios: Update to support sandbox

2018-10-15 Thread Simon Glass
At present this code casts addresses to pointers so cannot be used with
sandbox. Update it to use mapmem instead.

Signed-off-by: Simon Glass 
---

Changes in v11:
- Fix the EFI code that has since been added and relies on broken behaviour

Changes in v9: None
Changes in v7: None
Changes in v5: None
Changes in v4: None
Changes in v3:
- Drop incorrect map_sysmem() in write_smbios_table()

 lib/efi_loader/efi_smbios.c | 20 +---
 lib/smbios.c| 32 
 2 files changed, 37 insertions(+), 15 deletions(-)

diff --git a/lib/efi_loader/efi_smbios.c b/lib/efi_loader/efi_smbios.c
index 38e42fa2432..a81488495e2 100644
--- a/lib/efi_loader/efi_smbios.c
+++ b/lib/efi_loader/efi_smbios.c
@@ -7,6 +7,7 @@
 
 #include 
 #include 
+#include 
 #include 
 
 static const efi_guid_t smbios_guid = SMBIOS_TABLE_GUID;
@@ -19,17 +20,19 @@ static const efi_guid_t smbios_guid = SMBIOS_TABLE_GUID;
 efi_status_t efi_smbios_register(void)
 {
/* Map within the low 32 bits, to allow for 32bit SMBIOS tables */
-   u64 dmi = U32_MAX;
+   u64 dmi_addr = U32_MAX;
efi_status_t ret;
+   void *dmi;
 
/* Reserve 4kiB page for SMBIOS */
ret = efi_allocate_pages(EFI_ALLOCATE_MAX_ADDRESS,
-EFI_RUNTIME_SERVICES_DATA, 1, &dmi);
+EFI_RUNTIME_SERVICES_DATA, 1, &dmi_addr);
 
if (ret != EFI_SUCCESS) {
/* Could not find space in lowmem, use highmem instead */
ret = efi_allocate_pages(EFI_ALLOCATE_ANY_PAGES,
-EFI_RUNTIME_SERVICES_DATA, 1, &dmi);
+EFI_RUNTIME_SERVICES_DATA, 1,
+&dmi_addr);
 
if (ret != EFI_SUCCESS)
return ret;
@@ -39,11 +42,14 @@ efi_status_t efi_smbios_register(void)
 * Generate SMBIOS tables - we know that efi_allocate_pages() returns
 * a 4k-aligned address, so it is safe to assume that
 * write_smbios_table() will write the table at that address.
+*
+* Note that on sandbox, efi_allocate_pages() unfortunately returns a
+* pointer even though it uses a uint64_t type. Convert it.
 */
-   assert(!(dmi & 0xf));
-   write_smbios_table(dmi);
+   assert(!(dmi_addr & 0xf));
+   dmi = (void *)(uintptr_t)dmi_addr;
+   write_smbios_table(map_to_sysmem(dmi));
 
/* And expose them to our EFI payload */
-   return efi_install_configuration_table(&smbios_guid,
-  (void *)(uintptr_t)dmi);
+   return efi_install_configuration_table(&smbios_guid, dmi);
 }
diff --git a/lib/smbios.c b/lib/smbios.c
index 326eb00230d..87109d431a2 100644
--- a/lib/smbios.c
+++ b/lib/smbios.c
@@ -6,6 +6,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -72,9 +73,10 @@ static int smbios_string_table_len(char *start)
 
 static int smbios_write_type0(ulong *current, int handle)
 {
-   struct smbios_type0 *t = (struct smbios_type0 *)*current;
+   struct smbios_type0 *t;
int len = sizeof(struct smbios_type0);
 
+   t = map_sysmem(*current, len);
memset(t, 0, sizeof(struct smbios_type0));
fill_smbios_header(t, SMBIOS_BIOS_INFORMATION, len, handle);
t->vendor = smbios_add_string(t->eos, "U-Boot");
@@ -101,16 +103,18 @@ static int smbios_write_type0(ulong *current, int handle)
 
len = t->length + smbios_string_table_len(t->eos);
*current += len;
+   unmap_sysmem(t);
 
return len;
 }
 
 static int smbios_write_type1(ulong *current, int handle)
 {
-   struct smbios_type1 *t = (struct smbios_type1 *)*current;
+   struct smbios_type1 *t;
int len = sizeof(struct smbios_type1);
char *serial_str = env_get("serial#");
 
+   t = map_sysmem(*current, len);
memset(t, 0, sizeof(struct smbios_type1));
fill_smbios_header(t, SMBIOS_SYSTEM_INFORMATION, len, handle);
t->manufacturer = smbios_add_string(t->eos, CONFIG_SMBIOS_MANUFACTURER);
@@ -122,15 +126,17 @@ static int smbios_write_type1(ulong *current, int handle)
 
len = t->length + smbios_string_table_len(t->eos);
*current += len;
+   unmap_sysmem(t);
 
return len;
 }
 
 static int smbios_write_type2(ulong *current, int handle)
 {
-   struct smbios_type2 *t = (struct smbios_type2 *)*current;
+   struct smbios_type2 *t;
int len = sizeof(struct smbios_type2);
 
+   t = map_sysmem(*current, len);
memset(t, 0, sizeof(struct smbios_type2));
fill_smbios_header(t, SMBIOS_BOARD_INFORMATION, len, handle);
t->manufacturer = smbios_add_string(t->eos, CONFIG_SMBIOS_MANUFACTURER);
@@ -140,15 +146,17 @@ static int smbios_write_type2(ulong *current, int handle)
 
len = t->length + smbios_string_table_len(t->eos);
*current += len;
+   unm

[U-Boot] [PATCH v11 6/6] efi: Rename bootefi_test_finish() to bootefi_run_finish()

2018-10-15 Thread Simon Glass
This function can be used from do_bootefi_exec() so that we use mostly the
same code for a normal EFI application and an EFI test.

Rename the function and use it in both places.

Signed-off-by: Simon Glass 
---

Changes in v11:
- Drop patches previously applied

Changes in v9: None
Changes in v7:
- Drop patch "efi: Init the 'rows' and 'cols' variables"
- Drop patches previous applied

Changes in v5:
- Rebase to master

Changes in v4:
- Rebase to master

Changes in v3:
- Add new patch to rename bootefi_test_finish() to bootefi_run_finish()

 cmd/bootefi.c | 33 -
 1 file changed, 16 insertions(+), 17 deletions(-)

diff --git a/cmd/bootefi.c b/cmd/bootefi.c
index 6a9a610a65c..d5a03ee7f6d 100644
--- a/cmd/bootefi.c
+++ b/cmd/bootefi.c
@@ -344,6 +344,20 @@ static efi_status_t bootefi_run_prepare(const char 
*load_options_path,
return 0;
 }
 
+/**
+ * bootefi_run_finish() - finish up after running an EFI test
+ *
+ * @image: Pointer to a struct which holds the loaded image info
+ * @obj: Pointer to a struct which holds the loaded image object
+ */
+static void bootefi_run_finish(struct efi_loaded_image *image,
+  struct efi_loaded_image_obj *obj)
+{
+   efi_restore_gd();
+   free(image->load_options);
+   efi_delete_handle(&obj->parent);
+}
+
 /**
  * do_bootefi_exec() - execute EFI binary
  *
@@ -461,8 +475,7 @@ static efi_status_t do_bootefi_exec(void *efi,
 
 exit:
/* image has returned, loaded-image obj goes *poof*: */
-   if (obj)
-   efi_delete_handle(&obj->parent);
+   bootefi_run_finish(image, obj);
if (mem_handle)
efi_delete_handle(mem_handle);
 
@@ -500,20 +513,6 @@ static efi_status_t bootefi_test_prepare(struct 
efi_loaded_image **imagep,
return bootefi_run_prepare(load_options_path, bootefi_device_path,
   bootefi_image_path, imagep, objp);
 }
-
-/**
- * bootefi_test_finish() - finish up after running an EFI test
- *
- * @image: Pointer to a struct which holds the loaded image info
- * @obj: Pointer to a struct which holds the loaded image object
- */
-static void bootefi_test_finish(struct efi_loaded_image *image,
-   struct efi_loaded_image_obj *obj)
-{
-   efi_restore_gd();
-   free(image->load_options);
-   efi_delete_handle(&obj->parent);
-}
 #endif /* CONFIG_CMD_BOOTEFI_SELFTEST */
 
 static int do_bootefi_bootmgr_exec(void)
@@ -604,7 +603,7 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, 
char * const argv[])
 
/* Execute the test */
r = efi_selftest(obj, &systab);
-   bootefi_test_finish(image, obj);
+   bootefi_run_finish(image, obj);
return r != EFI_SUCCESS;
} else
 #endif
-- 
2.19.1.331.ge82ca0e54c-goog

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v11 4/6] efi: Split out test init/uninit into functions

2018-10-15 Thread Simon Glass
The functions in bootefi are very long because they mix high-level code
and control with the low-level implementation. To help with this, create
functions which handle preparing for running the test and cleaning up
afterwards.

Also shorten the awfully long variable names here.

Signed-off-by: Simon Glass 
---

Changes in v11: None
Changes in v9:
- Add comments to bootefi_test_prepare() about the memset()s

Changes in v7: None
Changes in v5:
- Drop call to efi_init_obj_list() which is now done in do_bootefi()

Changes in v4: None
Changes in v3:
- Add new patch to split out test init/uninit into functions

 cmd/bootefi.c | 90 +--
 1 file changed, 65 insertions(+), 25 deletions(-)

diff --git a/cmd/bootefi.c b/cmd/bootefi.c
index 82d755ceb31..88b8b0172db 100644
--- a/cmd/bootefi.c
+++ b/cmd/bootefi.c
@@ -454,6 +454,64 @@ exit:
return ret;
 }
 
+#ifdef CONFIG_CMD_BOOTEFI_SELFTEST
+/**
+ * bootefi_test_prepare() - prepare to run an EFI test
+ *
+ * This sets things up so we can call EFI functions. This involves preparing
+ * the 'gd' pointer and setting up the load ed image data structures.
+ *
+ * @image: Pointer to a struct which will hold the loaded image info.
+ *This struct will be inited by this function before use.
+ * @obj: Pointer to a struct which will hold the loaded image object
+ *This struct will be inited by this function before use.
+ * @path: File path to the test being run (often just the test name with a
+ *backslash before it
+ * @test_func: Address of the test function that is being run
+ * @return 0 if OK, -ve on error
+ */
+static efi_status_t bootefi_test_prepare(struct efi_loaded_image **imagep,
+struct efi_loaded_image_obj **objp,
+const char *path, ulong test_func)
+{
+   efi_status_t r;
+
+   /* Construct a dummy device path */
+   bootefi_device_path = efi_dp_from_mem(EFI_RESERVED_MEMORY_TYPE,
+ (uintptr_t)test_func,
+ (uintptr_t)test_func);
+   bootefi_image_path = efi_dp_from_file(NULL, 0, path);
+   r = efi_setup_loaded_image(bootefi_device_path, bootefi_image_path,
+  objp, imagep);
+   if (r)
+   return r;
+   /*
+* gd lives in a fixed register which may get clobbered while we execute
+* the payload. So save it here and restore it on every callback entry
+*/
+   efi_save_gd();
+
+   /* Transfer environment variable efi_selftest as load options */
+   set_load_options(*imagep, "efi_selftest");
+
+   return 0;
+}
+
+/**
+ * bootefi_test_finish() - finish up after running an EFI test
+ *
+ * @image: Pointer to a struct which holds the loaded image info
+ * @obj: Pointer to a struct which holds the loaded image object
+ */
+static void bootefi_test_finish(struct efi_loaded_image *image,
+   struct efi_loaded_image_obj *obj)
+{
+   efi_restore_gd();
+   free(image->load_options);
+   efi_delete_handle(&obj->parent);
+}
+#endif /* CONFIG_CMD_BOOTEFI_SELFTEST */
+
 static int do_bootefi_bootmgr_exec(void)
 {
struct efi_device_path *device_path, *file_path;
@@ -532,34 +590,16 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int 
argc, char * const argv[])
 #endif
 #ifdef CONFIG_CMD_BOOTEFI_SELFTEST
if (!strcmp(argv[1], "selftest")) {
-   struct efi_loaded_image_obj *image_handle;
-   struct efi_loaded_image *loaded_image_info;
-
-   /* Construct a dummy device path. */
-   bootefi_device_path = efi_dp_from_mem(EFI_RESERVED_MEMORY_TYPE,
- (uintptr_t)&efi_selftest,
- (uintptr_t)&efi_selftest);
-   bootefi_image_path = efi_dp_from_file(NULL, 0, "\\selftest");
-
-   r = efi_setup_loaded_image(bootefi_device_path,
-  bootefi_image_path, &image_handle,
-  &loaded_image_info);
-   if (r != EFI_SUCCESS)
+   struct efi_loaded_image_obj *obj;
+   struct efi_loaded_image *image;
+
+   if (bootefi_test_prepare(&image, &obj, "\\selftest",
+(uintptr_t)&efi_selftest))
return CMD_RET_FAILURE;
 
-   /*
-* gd lives in a fixed register which may get clobbered while we
-* execute the payload. So save it here and restore it on every
-* callback entry
-*/
-   efi_save_gd();
-   /* Transfer environment variable efi_selftest as load options */
-   set_load_options(loaded_image_info, "efi_selftest");
/* Execute the test */

[U-Boot] [PATCH v11 1/6] sandbox: Put CPUs under a cpu-bus node

2018-10-15 Thread Simon Glass
The CPU uclass expects that all CPUs have a parent device which is a
cpu-bus. Fix up the sandbox test DT to follow this convention. This allow
the code in smbios_write_type4_dm() to work, since it calls
dev_get_parent_platdata() on each CPU.

Signed-off-by: Simon Glass 
---

Changes in v11:
- Add a new patch to put CPUs under a cpu-bus node

Changes in v9: None
Changes in v7: None
Changes in v5: None
Changes in v4: None
Changes in v3: None

 arch/sandbox/dts/test.dts | 18 ++
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index 420b72f4dbc..dc24fef3b21 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -344,16 +344,18 @@
mbox-names = "other", "test";
};
 
-   cpu-test1 {
-   compatible = "sandbox,cpu_sandbox";
-   };
+   cpus {
+   cpu-test1 {
+   compatible = "sandbox,cpu_sandbox";
+   };
 
-   cpu-test2 {
-   compatible = "sandbox,cpu_sandbox";
-   };
+   cpu-test2 {
+   compatible = "sandbox,cpu_sandbox";
+   };
 
-   cpu-test3 {
-   compatible = "sandbox,cpu_sandbox";
+   cpu-test3 {
+   compatible = "sandbox,cpu_sandbox";
+   };
};
 
misc-test {
-- 
2.19.1.331.ge82ca0e54c-goog

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v11 2/6] efi_loader: Drop setup_ok

2018-10-15 Thread Simon Glass
This value is stored in data which appears to be read-only with sandbox on
my Ubuntu 18.04 machine. In any case it is not good practice to store
run-time data in a build-time linker list.

The value does not seem to be that useful, since tests that fail to setup
are likely to fail to run also. Let's drop it for now.

Signed-off-by: Simon Glass 
---

Changes in v11:
- Add a new patch to drop setup_ok

Changes in v9: None
Changes in v7: None
Changes in v5: None
Changes in v4: None
Changes in v3: None

 include/efi_selftest.h  |  2 --
 lib/efi_selftest/efi_selftest.c | 14 +++---
 2 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/include/efi_selftest.h b/include/efi_selftest.h
index 56beac305ec..49d3d6d0b47 100644
--- a/include/efi_selftest.h
+++ b/include/efi_selftest.h
@@ -129,7 +129,6 @@ u16 efi_st_get_key(void);
  * @setup: set up the unit test
  * @teardown:  tear down the unit test
  * @execute:   execute the unit test
- * @setup_ok:  setup was successful (set at runtime)
  * @on_request:test is only executed on request
  */
 struct efi_unit_test {
@@ -139,7 +138,6 @@ struct efi_unit_test {
 const struct efi_system_table *systable);
int (*execute)(void);
int (*teardown)(void);
-   int setup_ok;
bool on_request;
 };
 
diff --git a/lib/efi_selftest/efi_selftest.c b/lib/efi_selftest/efi_selftest.c
index dd338db687e..dfd11be2302 100644
--- a/lib/efi_selftest/efi_selftest.c
+++ b/lib/efi_selftest/efi_selftest.c
@@ -74,20 +74,20 @@ void efi_st_exit_boot_services(void)
  */
 static int setup(struct efi_unit_test *test, unsigned int *failures)
 {
-   if (!test->setup) {
-   test->setup_ok = EFI_ST_SUCCESS;
+   int ret;
+
+   if (!test->setup)
return EFI_ST_SUCCESS;
-   }
efi_st_printc(EFI_LIGHTBLUE, "\nSetting up '%s'\n", test->name);
-   test->setup_ok = test->setup(handle, systable);
-   if (test->setup_ok != EFI_ST_SUCCESS) {
+   ret = test->setup(handle, systable);
+   if (ret) {
efi_st_error("Setting up '%s' failed\n", test->name);
++*failures;
} else {
efi_st_printc(EFI_LIGHTGREEN,
  "Setting up '%s' succeeded\n", test->name);
}
-   return test->setup_ok;
+   return ret;
 }
 
 /*
@@ -197,7 +197,7 @@ void efi_st_do_tests(const u16 *testname, unsigned int 
phase,
continue;
if (steps & EFI_ST_SETUP)
setup(test, failures);
-   if (steps & EFI_ST_EXECUTE && test->setup_ok == EFI_ST_SUCCESS)
+   if (steps & EFI_ST_EXECUTE)
execute(test, failures);
if (steps & EFI_ST_TEARDOWN)
teardown(test, failures);
-- 
2.19.1.331.ge82ca0e54c-goog

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH] ARM: Samsung: Add Exynos5422-based Odroid HC2 support

2018-10-15 Thread Lukasz Majewski
Hi Dirk,

> Odroid HC2 board is based on Odroid XU4 board, like the Odroid HC1.
> 
> The linux kernel does not provide a hc2 DTB so the hc1 DTB is also
> used for the Odroid HC2.
> 
> Signed-off-by: Dirk Meul 
> ---
>  board/samsung/common/exynos5-dt-types.c | 16 +---
>  board/samsung/common/exynos5-dt.c   |  4 ++--
>  configs/odroid-xu3_defconfig|  2 +-
>  include/samsung/exynos5-dt-types.h  |  2 ++
>  4 files changed, 18 insertions(+), 6 deletions(-)
> 
> diff --git a/board/samsung/common/exynos5-dt-types.c
> b/board/samsung/common/exynos5-dt-types.c index
> 4473968db6..7a86e91877 100644 ---
> a/board/samsung/common/exynos5-dt-types.c +++
> b/board/samsung/common/exynos5-dt-types.c @@ -24,14 +24,15 @@ static
> const struct udevice_id board_ids[] = { };
> 
>  /**
> - * Odroix XU3/XU4/HC1 board revisions (from
> HC1_MAIN_REV0.1_20170630.pdf):
> + * Odroix XU3/XU4/HC1/HC2 board revisions (from
> HC1+_HC2_MAIN_REV0.1_20171017.pdf):
>   * Rev   ADCmax  Board
>   * 0.1 0 XU3 0.1
>   * 0.2   372 XU3 0.2 | XU3L - no DISPLAYPORT (probe I2C0:0x40 /
> INA231)
>   * 0.3  1280 XU4 0.1
>   * 0.4   739 XU4 0.2
>   * 0.5  1016 XU4+Air0.1 (Passive cooling)
> - * 0.6  1308 XU4S 0.1 (HC1)
> + * 0.6  1309 XU4-HC1 0.1
> + * 0.7  1470 XU4-HC1+ 0.1 (HC2)
>   * Use +1% for ADC value tolerance in the array below, the code
> loops until
>   * the measured ADC value is lower than then ADCmax from the array.
>   */
> @@ -39,7 +40,8 @@ struct odroid_rev_info odroid_info[] = {
>  { EXYNOS5_BOARD_ODROID_XU3_REV01, 1, 10, "xu3" },
>  { EXYNOS5_BOARD_ODROID_XU3_REV02, 2, 375, "xu3" },
>  { EXYNOS5_BOARD_ODROID_XU4_REV01, 1, 1293, "xu4" },
> -{ EXYNOS5_BOARD_ODROID_HC1_REV01, 1, 1321, "hc1" },
> +{ EXYNOS5_BOARD_ODROID_HC1_REV01, 1, 1322, "hc1" },
> +{ EXYNOS5_BOARD_ODROID_HC2_REV01, 1, 1484, "hc1" },
>  { EXYNOS5_BOARD_ODROID_UNKNOWN, 0, 4095, "unknown" },
>  };
> 
> @@ -144,6 +146,14 @@ bool board_is_odroidhc1(void)
>  return false;
>  }
> 
> +bool board_is_odroidhc2(void)
> +{
> +if (gd->board_type == EXYNOS5_BOARD_ODROID_HC2_REV01)
> +return true;
> +
> +return false;
> +}
> +
>  bool board_is_generic(void)
>  {
>  if (gd->board_type == EXYNOS5_BOARD_GENERIC)
> diff --git a/board/samsung/common/exynos5-dt.c
> b/board/samsung/common/exynos5-dt.c index 8c3a9ea564..c183965b92
> 100644 --- a/board/samsung/common/exynos5-dt.c
> +++ b/board/samsung/common/exynos5-dt.c
> @@ -179,7 +179,7 @@ char *get_dfu_alt_system(char *interface, char
> *devstr) {
>  char *info = "Not supported!";
> 
> -if (board_is_odroidxu4() || board_is_odroidhc1())
> +if (board_is_odroidxu4() || board_is_odroidhc1() ||
> board_is_odroidhc2()) return info;
> 
>  return env_get("dfu_alt_system");
> @@ -192,7 +192,7 @@ char *get_dfu_alt_boot(char *interface, char
> *devstr) char *alt_boot;
>  int dev_num;
> 
> -if (board_is_odroidxu4() || board_is_odroidhc1())
> +if (board_is_odroidxu4() || board_is_odroidhc1() ||
> board_is_odroidhc2()) return info;
> 
>  dev_num = simple_strtoul(devstr, NULL, 10);
> diff --git a/configs/odroid-xu3_defconfig
> b/configs/odroid-xu3_defconfig index 258b9781cc..d5c7cc7129 100644
> --- a/configs/odroid-xu3_defconfig
> +++ b/configs/odroid-xu3_defconfig
> @@ -2,7 +2,7 @@ CONFIG_ARM=y
>  CONFIG_ARCH_EXYNOS=y
>  CONFIG_SYS_TEXT_BASE=0x43E0
>  CONFIG_ARCH_EXYNOS5=y
> -CONFIG_IDENT_STRING=" for ODROID-XU3/XU4/HC1"
> +CONFIG_IDENT_STRING=" for ODROID-XU3/XU4/HC1/HC2"
>  CONFIG_DISTRO_DEFAULTS=y
>  CONFIG_NR_DRAM_BANKS=8
>  # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
> diff --git a/include/samsung/exynos5-dt-types.h
> b/include/samsung/exynos5-dt-types.h index 8e11af30d1..8fe08fe211
> 100644 --- a/include/samsung/exynos5-dt-types.h
> +++ b/include/samsung/exynos5-dt-types.h
> @@ -9,6 +9,7 @@ enum {
>  EXYNOS5_BOARD_ODROID_XU3_REV02,
>  EXYNOS5_BOARD_ODROID_XU4_REV01,
>  EXYNOS5_BOARD_ODROID_HC1_REV01,
> +EXYNOS5_BOARD_ODROID_HC2_REV01,
>  EXYNOS5_BOARD_ODROID_UNKNOWN,
> 
>  EXYNOS5_BOARD_COUNT,
> @@ -25,5 +26,6 @@ bool board_is_generic(void);
>  bool board_is_odroidxu3(void);
>  bool board_is_odroidxu4(void);
>  bool board_is_odroidhc1(void);
> +bool board_is_odroidhc2(void);
> 
>  #endif
> --
> 2.17.1
> 
> 

Reviewed-by: Lukasz Majewski 


Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: w...@denx.de


pgpYr9HEs9x8O.pgp
Description: OpenPGP digital signature
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v11 5/6] efi: Create a function to set up for running EFI code

2018-10-15 Thread Simon Glass
There is still duplicated code in efi_loader for tests and normal
operation.

Add a new bootefi_run_prepare() function which holds common code used to
set up U-Boot to run EFI code. Make use of this from the existing
bootefi_test_prepare() function, as well as do_bootefi_exec().

Also shorten a few variable names.

Signed-off-by: Simon Glass 
---

Changes in v11: None
Changes in v9: None
Changes in v7: None
Changes in v5:
- Drop call to efi_init_obj_list() which is now done in do_bootefi()
- Introduce load_options_path to specifyc U-Boot env var for load_options_path

Changes in v4:
- Rebase to master

Changes in v3:
- Add patch to create a function to set up for running EFI code

 cmd/bootefi.c | 91 +++
 1 file changed, 48 insertions(+), 43 deletions(-)

diff --git a/cmd/bootefi.c b/cmd/bootefi.c
index 88b8b0172db..6a9a610a65c 100644
--- a/cmd/bootefi.c
+++ b/cmd/bootefi.c
@@ -320,6 +320,30 @@ static efi_status_t efi_install_fdt(ulong fdt_addr)
return ret;
 }
 
+static efi_status_t bootefi_run_prepare(const char *load_options_path,
+   struct efi_device_path *device_path,
+   struct efi_device_path *image_path,
+   struct efi_loaded_image **imagep,
+   struct efi_loaded_image_obj **objp)
+{
+   efi_status_t ret;
+
+   ret = efi_setup_loaded_image(device_path, image_path, objp, imagep);
+   if (ret != EFI_SUCCESS)
+   return ret;
+
+   /*
+* gd lives in a fixed register which may get clobbered while we execute
+* the payload. So save it here and restore it on every callback entry
+*/
+   efi_save_gd();
+
+   /* Transfer environment variable as load options */
+   set_load_options(*imagep, load_options_path);
+
+   return 0;
+}
+
 /**
  * do_bootefi_exec() - execute EFI binary
  *
@@ -338,8 +362,8 @@ static efi_status_t do_bootefi_exec(void *efi,
efi_handle_t mem_handle = NULL;
struct efi_device_path *memdp = NULL;
efi_status_t ret;
-   struct efi_loaded_image_obj *image_handle = NULL;
-   struct efi_loaded_image *loaded_image_info = NULL;
+   struct efi_loaded_image_obj *obj = NULL;
+   struct efi_loaded_image *image = NULL;
 
EFIAPI efi_status_t (*entry)(efi_handle_t image_handle,
 struct efi_system_table *st);
@@ -369,21 +393,13 @@ static efi_status_t do_bootefi_exec(void *efi,
assert(device_path && image_path);
}
 
-   ret = efi_setup_loaded_image(device_path, image_path, &image_handle,
-&loaded_image_info);
-   if (ret != EFI_SUCCESS)
-   goto exit;
-
-   /*
-* gd lives in a fixed register which may get clobbered while we execute
-* the payload. So save it here and restore it on every callback entry
-*/
-   efi_save_gd();
+   ret = bootefi_run_prepare("bootargs", device_path, image_path,
+ &image, &obj);
+   if (ret)
+   return ret;
 
-   /* Transfer environment variable bootargs as load options */
-   set_load_options(loaded_image_info, "bootargs");
/* Load the EFI payload */
-   entry = efi_load_pe(image_handle, efi, loaded_image_info);
+   entry = efi_load_pe(obj, efi, image);
if (!entry) {
ret = EFI_LOAD_ERROR;
goto exit;
@@ -391,10 +407,9 @@ static efi_status_t do_bootefi_exec(void *efi,
 
if (memdp) {
struct efi_device_path_memory *mdp = (void *)memdp;
-   mdp->memory_type = loaded_image_info->image_code_type;
-   mdp->start_address = (uintptr_t)loaded_image_info->image_base;
-   mdp->end_address = mdp->start_address +
-   loaded_image_info->image_size;
+   mdp->memory_type = image->image_code_type;
+   mdp->start_address = (uintptr_t)image->image_base;
+   mdp->end_address = mdp->start_address + image->image_size;
}
 
/* we don't support much: */
@@ -404,8 +419,8 @@ static efi_status_t do_bootefi_exec(void *efi,
/* Call our payload! */
debug("%s:%d Jumping to 0x%lx\n", __func__, __LINE__, (long)entry);
 
-   if (setjmp(&image_handle->exit_jmp)) {
-   ret = image_handle->exit_status;
+   if (setjmp(&obj->exit_jmp)) {
+   ret = obj->exit_status;
goto exit;
}
 
@@ -417,7 +432,7 @@ static efi_status_t do_bootefi_exec(void *efi,
 
/* Move into EL2 and keep running there */
armv8_switch_to_el2((ulong)entry,
-   (ulong)image_handle,
+   (ulong)obj,
(ulong)&systab, 0, (ulong)efi_run_in_el2,
  

[U-Boot] [GIT PULL] Xilinx changes for v2018.11-rc2

2018-10-15 Thread Michal Simek
Hi Tom,

please consider to pull these patches to your tree.
Buildmain for xilinx boards looks good and travis is not done yet but
link is here (I have seen several timeouts recently but it was there
even on clear mainline).
https://travis-ci.org/michalsimek/u-boot/builds/441591781

If you don't like this please at least cherry-pick this one
Revert "fdt: fdtdec_setup_memory_banksize() use livetree"
(sha1: 01ac0843aeedc3c95fe68e7ce6a8f35bf1a04b23)
which I need for getting SPL up and running again on zynq/zynqmp boards.

Thanks,
Michal

The following changes since commit 15f22ac2eea5ee9f17b14a143c94e7480bbafbff:

  ldpaa_eth.c: Fix warning when PHYLIB is not enabled (2018-10-12
07:41:24 -0400)

are available in the git repository at:

  git://www.denx.de/git/u-boot-microblaze.git tags/xilinx-for-v2018.11-rc2

for you to fetch changes up to 045c62be10d64a558f56febcaa2d01b1abbcfa00:

  cmd: kgdb: Enable kgdb only for PPC (2018-10-15 12:36:37 +0200)


Xilinx changes for v2018.11-rc2

FPGA:
- Fix SPL fpga loading from FIT

ARM64:
- Fix gic accesses in EL2/EL1

Xilinx:
- Add dlc20 board support
- Add Versal board support
- Sync defconfigs
- Enable MP via Kconfig
- Add missing efuse node
- Enable CDC for zcu100

cmd:
- Fix kgdb Kconfig dependency

serial-pl01x:
 - Add support for handling clk from DT


Michal Simek (13):
  spl: fpga: Implement fpga bistream loading with fpga_load
  arm: zynq: Enable FIT fpga loading in SPL for zc706
  arm: zynq: Add support for DLC20 board
  Revert "fdt: fdtdec_setup_memory_banksize() use livetree"
  arm: zynq: Add efuse node for Zynq-7000S devices
  xilinx: Sync defconfigs with current Kconfig
  arm64: zynqmp: Enable CDC ethernet gadget for zcu100/Ultra96
  arm64: gic: Do gicv3 secure initialization based on EL level
  arm64: versal: Add support for new Xilinx Versal ACAPs
  net: gem: Do not setup any clock for Xilinx SoC Versal
  arm64: versal: Add Xilinx Versal Virtual QEMU board
  arm64: zynqmp: Enable MP by default via Kconfig
  cmd: kgdb: Enable kgdb only for PPC

Siva Durga Prasad Paladugu (3):
  serial: pl01x: Get clock from clock node if no clock property found
  arm64: zynqmp: Move TCM initialization to a separate routine
  arm64: zynqmp: Add new command for TCM initialization

 Kconfig|   2 +-
 MAINTAINERS|   6 
 arch/arm/Kconfig   |  11 +++
 arch/arm/Makefile  |   1 +
 arch/arm/cpu/armv8/zynqmp/cpu.c|  12 +--
 arch/arm/dts/Makefile  |   1 +
 arch/arm/dts/zynq-7000.dtsi|   5 +++
 arch/arm/dts/zynq-dlc20-rev1.0.dts | 103
+
 arch/arm/include/asm/arch-zynqmp/sys_proto.h   |   3 ++
 arch/arm/lib/gic_64.S  |  16 +
 arch/arm/mach-versal/Kconfig   |  44
+
 arch/arm/mach-versal/Makefile  |   8 +
 arch/arm/mach-versal/clk.c |  30 +
 arch/arm/mach-versal/cpu.c |  83
++
 arch/arm/mach-versal/include/mach/gpio.h   |   6 
 arch/arm/mach-versal/include/mach/hardware.h   |  34
+++
 arch/arm/mach-versal/include/mach/sys_proto.h  |   6 
 board/xilinx/versal/MAINTAINERS|   7 
 board/xilinx/versal/Makefile   |   7 
 board/xilinx/versal/board.c|  81
+
 board/xilinx/zynq/zynq-dlc20-rev1.0/ps7_init_gpl.c | 280
++
 board/xilinx/zynqmp/cmds.c |  37
-
 cmd/Kconfig|   1 +
 common/spl/spl_fit.c   |  34
+--
 configs/avnet_ultra96_rev1_defconfig   |   8 +++--
 configs/microblaze-generic_defconfig   |   2 +-
 configs/xilinx_versal_virt_defconfig   |  68
++
 configs/xilinx_zynqmp_mini_emmc0_defconfig |   1 +
 configs/xilinx_zynqmp_mini_emmc1_defconfig |   1 +
 configs/xilinx_zynqmp_mini_nand_defconfig  |   1 +
 configs/xilinx_zynqmp_mini_qspi_defconfig  |   1 -
 configs/xilinx_zynqmp_zc1232_revA_defconfig|   1 -
 configs/xilinx_zynqmp_zc1254_revA_defconfig|   1 -
 configs/xilinx_zynqmp_zc1275_revA_defconfig|   1 -
 configs/xilinx_zynqmp_zc1275_revB_

Re: [U-Boot] [Patch v3] socfpga: clean up sfp generation

2018-10-15 Thread Simon Goldschmidt

On 15.10.2018 15:52, Dalon Westergreen wrote:

From: Dalon Westergreen 

Move the sfp file generation entirely to the root Makefile.  This
means that the u-boot-spl.sfp will only be generated when required
and only for the socfpga variants that require it.

sfp generation is now entirely controlled by CONFIG_BUILD_TARGET
being set to either spl/u-boot-spl.sfp or more likely
u-boot-with-spl.sfp

Signed-off-by: Dalon Westergreen 


Tested with socfpga_socrates_defconfig to not break the build:
Tested-by: Simon Goldschmidt 



---
v3:
   -> Change ifdef to ifneq
   -> Fix error, should not use $(SPL_BIN) as it was not defined
  in Makefile
v2:
   -> condense changes to 1 patch to avoid breaking git bisect
---
  Makefile | 11 ---
  scripts/Makefile.spl | 12 
  2 files changed, 8 insertions(+), 15 deletions(-)

diff --git a/Makefile b/Makefile
index aadd1ec8c6..5f03e534a5 100644
--- a/Makefile
+++ b/Makefile
@@ -1207,6 +1207,14 @@ u-boot.spr: spl/u-boot-spl.img u-boot.img FORCE
$(call if_changed,pad_cat)
  
  ifneq ($(CONFIG_ARCH_SOCFPGA),)

+ifneq ($(CONFIG_TARGET_SOCFPGA_ARRIA10),)
+MKIMAGEFLAGS_u-boot-spl.sfp = -T socfpgaimage_v1
+else
+MKIMAGEFLAGS_u-boot-spl.sfp = -T socfpgaimage
+endif
+spl/u-boot-spl.sfp: spl/u-boot-spl.bin FORCE
+   $(call if_changed,mkimage)
+
  quiet_cmd_socboot = SOCBOOT $@
  cmd_socboot = cat spl/u-boot-spl.sfp spl/u-boot-spl.sfp   \
spl/u-boot-spl.sfp spl/u-boot-spl.sfp   \
@@ -1542,9 +1550,6 @@ spl/sunxi-spl.bin: spl/u-boot-spl
  spl/sunxi-spl-with-ecc.bin: spl/sunxi-spl.bin
@:
  
-spl/u-boot-spl.sfp: spl/u-boot-spl

-   @:
-
  spl/boot.bin: spl/u-boot-spl
@:
  
diff --git a/scripts/Makefile.spl b/scripts/Makefile.spl

index 7416abec62..a58113cee2 100644
--- a/scripts/Makefile.spl
+++ b/scripts/Makefile.spl
@@ -198,10 +198,6 @@ ifdef CONFIG_SAMSUNG
  ALL-y += $(obj)/$(BOARD)-spl.bin
  endif
  
-ifdef CONFIG_ARCH_SOCFPGA

-ALL-y  += $(obj)/$(SPL_BIN).sfp
-endif
-
  ifdef CONFIG_ARCH_SUNXI
  ALL-y += $(obj)/sunxi-spl.bin
  
@@ -324,14 +320,6 @@ LDFLAGS_$(SPL_BIN) += -Ttext $(CONFIG_SPL_TEXT_BASE)

  endif
  endif
  
-ifdef CONFIG_TARGET_SOCFPGA_ARRIA10

-MKIMAGEFLAGS_$(SPL_BIN).sfp = -T socfpgaimage_v1
-else
-MKIMAGEFLAGS_$(SPL_BIN).sfp = -T socfpgaimage
-endif
-$(obj)/$(SPL_BIN).sfp: $(obj)/$(SPL_BIN).bin FORCE
-   $(call if_changed,mkimage)
-
  quiet_cmd_mksunxiboot = MKSUNXI $@
  cmd_mksunxiboot = $(objtree)/tools/mksunxiboot \
--default-dt $(CONFIG_DEFAULT_DEVICE_TREE) $< $@



___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v2 1/1] efi_loader: PSCI reset and shutdown

2018-10-15 Thread Heinrich Schuchardt
On 10/15/2018 09:34 AM, Sumit Garg wrote:
> On Sat, 13 Oct 2018 at 12:42, Heinrich Schuchardt  wrote:
>>
>> When an operating system started via bootefi tries to reset or power off
>> this is done by calling the EFI runtime ResetSystem(). On most ARMv8 system
>> the actual reset relies on PSCI. Depending on whether the PSCI firmware
>> resides the hypervisor or in the supervisor either an HVC or an SVC command
>> has to be issued. The current implementation always uses SVC. This results
> 
> Here you need to use SMC instead of SVC and EL3 firmware instead of 
> supervisor.
> 
>> in crashes on systems where the PSCI firmware is implemented in the
>> hypervisor, e.g. qemu-arm64_defconfig.
>>
>> The logic to decide which call is needed based on the device tree is already
>> implemented in the PSCI firmware driver. So let's use it for the EFI
>> runtime.
>>
>> As the same problem is also evident for the ARMv8 poweroff command
>> implementation fix it in the same way.
>>
>> Signed-off-by: Heinrich Schuchardt 
>> ---
>> Travis reported no errors in
>> https://travis-ci.org/xypron2/u-boot/builds/440843498
>> except for two boards with an image size problem.
>>
>> v2:
>> Use PSCI firmware driver to detect call method.
>> Thanks to Sumit for pointing me at dtb parsing as part of
>> "psci_probe()
>> ---
>>  arch/arm/cpu/armv7/smccc-call.S |  2 +
>>  arch/arm/cpu/armv8/Kconfig  |  1 +
>>  arch/arm/cpu/armv8/fwcall.c | 52 ++-
>>  arch/arm/cpu/armv8/smccc-call.S |  2 +
>>  drivers/firmware/psci.c | 91 +++--
>>  include/linux/psci.h|  6 +--
>>  6 files changed, 87 insertions(+), 67 deletions(-)
>>
>> diff --git a/arch/arm/cpu/armv7/smccc-call.S 
>> b/arch/arm/cpu/armv7/smccc-call.S
>> index 0d8b59eb6b..eae69e36c3 100644
>> --- a/arch/arm/cpu/armv7/smccc-call.S
>> +++ b/arch/arm/cpu/armv7/smccc-call.S
>> @@ -7,6 +7,8 @@
>>  #include 
>>  #include 
>>
>> +   .section.text.efi_runtime
>> +
>>  #define UNWIND(x...)
>> /*
>>  * Wrap c macros in asm macros to delay expansion until after the
>> diff --git a/arch/arm/cpu/armv8/Kconfig b/arch/arm/cpu/armv8/Kconfig
>> index c8bebabdf6..d643981b73 100644
>> --- a/arch/arm/cpu/armv8/Kconfig
>> +++ b/arch/arm/cpu/armv8/Kconfig
>> @@ -96,6 +96,7 @@ endmenu
>>  config PSCI_RESET
>> bool "Use PSCI for reset and shutdown"
>> default y
>> +   select ARM_SMCCC if OF_CONTROL
>> depends on !ARCH_EXYNOS7 && !ARCH_BCM283X && \
>>!TARGET_LS2080A_SIMU && !TARGET_LS2080AQDS && \
>>!TARGET_LS2080ARDB && !TARGET_LS2080A_EMU && \
>> diff --git a/arch/arm/cpu/armv8/fwcall.c b/arch/arm/cpu/armv8/fwcall.c
>> index 0ba3dad8cc..9957c2974b 100644
>> --- a/arch/arm/cpu/armv8/fwcall.c
>> +++ b/arch/arm/cpu/armv8/fwcall.c
>> @@ -7,7 +7,6 @@
>>
>>  #include 
>>  #include 
>> -#include 
>>  #include 
>>  #include 
>>  #include 
>> @@ -19,7 +18,7 @@
>>   * x0~x7: input arguments
>>   * x0~x3: output arguments
>>   */
>> -static void __efi_runtime hvc_call(struct pt_regs *args)
>> +static void hvc_call(struct pt_regs *args)
>>  {
>> asm volatile(
>> "ldr x0, %0\n"
>> @@ -53,7 +52,7 @@ static void __efi_runtime hvc_call(struct pt_regs *args)
>>   * x0~x3: output arguments
>>   */
>>
>> -void __efi_runtime smc_call(struct pt_regs *args)
>> +void smc_call(struct pt_regs *args)
>>  {
>> asm volatile(
>> "ldr x0, %0\n"
>> @@ -83,9 +82,9 @@ void __efi_runtime smc_call(struct pt_regs *args)
>>   * use PSCI on U-Boot running below a hypervisor, please detect
>>   * this and set the flag accordingly.
>>   */
>> -static const __efi_runtime_data bool use_smc_for_psci = true;
>> +static const bool use_smc_for_psci = true;
>>
>> -void __noreturn __efi_runtime psci_system_reset(void)
>> +void __noreturn psci_system_reset(void)
>>  {
>> struct pt_regs regs;
>>
>> @@ -100,7 +99,7 @@ void __noreturn __efi_runtime psci_system_reset(void)
>> ;
>>  }
>>
>> -void __noreturn __efi_runtime psci_system_off(void)
>> +void __noreturn psci_system_off(void)
>>  {
>> struct pt_regs regs;
>>
>> @@ -114,44 +113,3 @@ void __noreturn __efi_runtime psci_system_off(void)
>> while (1)
>> ;
>>  }
>> -
>> -#ifdef CONFIG_CMD_POWEROFF
>> -int do_poweroff(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
>> -{
>> -   puts("poweroff ...\n");
>> -
>> -   udelay(5); /* wait 50 ms */
>> -
>> -   disable_interrupts();
>> -
>> -   psci_system_off();
>> -
>> -   /*NOTREACHED*/
>> -   return 0;
>> -}
>> -#endif
>> -
>> -#ifdef CONFIG_PSCI_RESET
>> -void reset_misc(void)
>> -{
>> -   psci_system_reset();
>> -}
> 
> I don't see if you have implemented this api using the psci driver. I
> think this is used in case CONFIG_SYSRESET is not defined.
> 
> -Sumit

During EFI runtime the whole DM subsystem is not available. So what I do
h

[U-Boot] [PATCH v3 1/1] efi_loader: PSCI reset and shutdown

2018-10-15 Thread Heinrich Schuchardt
When an operating system started via bootefi tries to reset or power off
this is done by calling the EFI runtime ResetSystem(). On most ARMv8 system
the actual reset relies on PSCI. Depending on whether the PSCI firmware
resides the hypervisor (EL2) or in the secure monitor (EL3) either an HVC
or an SMC command has to be issued.

The current implementation always uses SMC. This results in crashes on
systems where the PSCI firmware is implemented in the hypervisor, e.g.
qemu-arm64_defconfig.

The logic to decide which call is needed based on the device tree is already
implemented in the PSCI firmware driver. During the EFI runtime the device
driver model is not available. But we can minimize code duplication by
merging the EFI runtime reset and poweroff code with the PSCI firmware
driver.

As the same HVC/SMC problem is also evident for the ARMv8 poweroff command
let's move it into the same code module.

Signed-off-by: Heinrich Schuchardt 
---
Travis reporteded no errors in
https://travis-ci.org/xypron2/u-boot/builds/440843498
except for two boards with an image size problem.

v3:
update commit message
v2:
Use PSCI firmware driver to detect call method.
Thanks to Sumit for pointing me at dtb parsing as part of
"psci_probe()
---
 arch/arm/cpu/armv7/smccc-call.S |  2 +
 arch/arm/cpu/armv8/Kconfig  |  1 +
 arch/arm/cpu/armv8/fwcall.c | 52 ++-
 arch/arm/cpu/armv8/smccc-call.S |  2 +
 drivers/firmware/psci.c | 91 +++--
 include/linux/psci.h|  6 +--
 6 files changed, 87 insertions(+), 67 deletions(-)

diff --git a/arch/arm/cpu/armv7/smccc-call.S b/arch/arm/cpu/armv7/smccc-call.S
index 0d8b59eb6b..eae69e36c3 100644
--- a/arch/arm/cpu/armv7/smccc-call.S
+++ b/arch/arm/cpu/armv7/smccc-call.S
@@ -7,6 +7,8 @@
 #include 
 #include 
 
+   .section.text.efi_runtime
+
 #define UNWIND(x...)
/*
 * Wrap c macros in asm macros to delay expansion until after the
diff --git a/arch/arm/cpu/armv8/Kconfig b/arch/arm/cpu/armv8/Kconfig
index c8bebabdf6..d643981b73 100644
--- a/arch/arm/cpu/armv8/Kconfig
+++ b/arch/arm/cpu/armv8/Kconfig
@@ -96,6 +96,7 @@ endmenu
 config PSCI_RESET
bool "Use PSCI for reset and shutdown"
default y
+   select ARM_SMCCC if OF_CONTROL
depends on !ARCH_EXYNOS7 && !ARCH_BCM283X && \
   !TARGET_LS2080A_SIMU && !TARGET_LS2080AQDS && \
   !TARGET_LS2080ARDB && !TARGET_LS2080A_EMU && \
diff --git a/arch/arm/cpu/armv8/fwcall.c b/arch/arm/cpu/armv8/fwcall.c
index 0ba3dad8cc..9957c2974b 100644
--- a/arch/arm/cpu/armv8/fwcall.c
+++ b/arch/arm/cpu/armv8/fwcall.c
@@ -7,7 +7,6 @@
 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -19,7 +18,7 @@
  * x0~x7: input arguments
  * x0~x3: output arguments
  */
-static void __efi_runtime hvc_call(struct pt_regs *args)
+static void hvc_call(struct pt_regs *args)
 {
asm volatile(
"ldr x0, %0\n"
@@ -53,7 +52,7 @@ static void __efi_runtime hvc_call(struct pt_regs *args)
  * x0~x3: output arguments
  */
 
-void __efi_runtime smc_call(struct pt_regs *args)
+void smc_call(struct pt_regs *args)
 {
asm volatile(
"ldr x0, %0\n"
@@ -83,9 +82,9 @@ void __efi_runtime smc_call(struct pt_regs *args)
  * use PSCI on U-Boot running below a hypervisor, please detect
  * this and set the flag accordingly.
  */
-static const __efi_runtime_data bool use_smc_for_psci = true;
+static const bool use_smc_for_psci = true;
 
-void __noreturn __efi_runtime psci_system_reset(void)
+void __noreturn psci_system_reset(void)
 {
struct pt_regs regs;
 
@@ -100,7 +99,7 @@ void __noreturn __efi_runtime psci_system_reset(void)
;
 }
 
-void __noreturn __efi_runtime psci_system_off(void)
+void __noreturn psci_system_off(void)
 {
struct pt_regs regs;
 
@@ -114,44 +113,3 @@ void __noreturn __efi_runtime psci_system_off(void)
while (1)
;
 }
-
-#ifdef CONFIG_CMD_POWEROFF
-int do_poweroff(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-   puts("poweroff ...\n");
-
-   udelay(5); /* wait 50 ms */
-
-   disable_interrupts();
-
-   psci_system_off();
-
-   /*NOTREACHED*/
-   return 0;
-}
-#endif
-
-#ifdef CONFIG_PSCI_RESET
-void reset_misc(void)
-{
-   psci_system_reset();
-}
-
-#ifdef CONFIG_EFI_LOADER
-void __efi_runtime EFIAPI efi_reset_system(
-   enum efi_reset_type reset_type,
-   efi_status_t reset_status,
-   unsigned long data_size, void *reset_data)
-{
-   if (reset_type == EFI_RESET_COLD ||
-   reset_type == EFI_RESET_WARM ||
-   reset_type == EFI_RESET_PLATFORM_SPECIFIC) {
-   psci_system_reset();
-   } else if (reset_type == EFI_RESET_SHUTDOWN) {
-   psci_system_off();
-   }
-
-   while (1) { }
-}
-#endif /* CONFIG_EFI_LOADER */
-#endif /* 

Re: [U-Boot] [PATCH v11 1/6] sandbox: Put CPUs under a cpu-bus node

2018-10-15 Thread Heinrich Schuchardt
On 10/15/2018 04:17 PM, Simon Glass wrote:
> The CPU uclass expects that all CPUs have a parent device which is a
> cpu-bus. Fix up the sandbox test DT to follow this convention. This allow
> the code in smbios_write_type4_dm() to work, since it calls
> dev_get_parent_platdata() on each CPU.
> 
> Signed-off-by: Simon Glass 
> ---
> 
> Changes in v11:
> - Add a new patch to put CPUs under a cpu-bus node
> 
> Changes in v9: None
> Changes in v7: None
> Changes in v5: None
> Changes in v4: None
> Changes in v3: None
> 
>  arch/sandbox/dts/test.dts | 18 ++
>  1 file changed, 10 insertions(+), 8 deletions(-)
> 
> diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
> index 420b72f4dbc..dc24fef3b21 100644
> --- a/arch/sandbox/dts/test.dts
> +++ b/arch/sandbox/dts/test.dts
> @@ -344,16 +344,18 @@
>   mbox-names = "other", "test";
>   };
>  
> - cpu-test1 {
> - compatible = "sandbox,cpu_sandbox";
> - };
> + cpus {

Our device trees should adhere to the
"Devicetree Specification, Release v0.2"
available on https://www.devicetree.org/specifications/

Please, add all required properties:

- #address-cells
- #size-cells

> + cpu-test1 {

The device tree specification has: "The node name for every CPU node
should be cpu". Please, call the CPUs cpu1 - cpu3.

Please, add all required properties:

- device-type
- reg
- clock-frequency
- timebase-frequency

Best regards

Heinrich

> + compatible = "sandbox,cpu_sandbox";
> + };
>  
> - cpu-test2 {
> - compatible = "sandbox,cpu_sandbox";
> - };
> + cpu-test2 {
> + compatible = "sandbox,cpu_sandbox";
> + };
>  
> - cpu-test3 {
> - compatible = "sandbox,cpu_sandbox";
> + cpu-test3 {
> + compatible = "sandbox,cpu_sandbox";
> + };
>   };
>  
>   misc-test {
> 

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v11 2/6] efi_loader: Drop setup_ok

2018-10-15 Thread Heinrich Schuchardt
On 10/15/2018 04:17 PM, Simon Glass wrote:
> This value is stored in data which appears to be read-only with sandbox on
> my Ubuntu 18.04 machine. In any case it is not good practice to store
> run-time data in a build-time linker list.
Yes this should be changed. Otherwise a reset of the board will not put
us back into the initial status.

> 
> The value does not seem to be that useful, since tests that fail to setup
> are likely to fail to run also. Let's drop it for now.

With your change we will run execute() even if setup() fails. This
contradicts the commit message. Please, find a solution that avoids
calling execute() after a failed setup().

Best regards

Heinrich


> 
> Signed-off-by: Simon Glass 
> ---
> 
> Changes in v11:
> - Add a new patch to drop setup_ok
> 
> Changes in v9: None
> Changes in v7: None
> Changes in v5: None
> Changes in v4: None
> Changes in v3: None
> 
>  include/efi_selftest.h  |  2 --
>  lib/efi_selftest/efi_selftest.c | 14 +++---
>  2 files changed, 7 insertions(+), 9 deletions(-)
> 
> diff --git a/include/efi_selftest.h b/include/efi_selftest.h
> index 56beac305ec..49d3d6d0b47 100644
> --- a/include/efi_selftest.h
> +++ b/include/efi_selftest.h
> @@ -129,7 +129,6 @@ u16 efi_st_get_key(void);
>   * @setup:   set up the unit test
>   * @teardown:tear down the unit test
>   * @execute: execute the unit test
> - * @setup_ok:setup was successful (set at runtime)
>   * @on_request:  test is only executed on request
>   */
>  struct efi_unit_test {
> @@ -139,7 +138,6 @@ struct efi_unit_test {
>const struct efi_system_table *systable);
>   int (*execute)(void);
>   int (*teardown)(void);
> - int setup_ok;
>   bool on_request;
>  };
>  
> diff --git a/lib/efi_selftest/efi_selftest.c b/lib/efi_selftest/efi_selftest.c
> index dd338db687e..dfd11be2302 100644
> --- a/lib/efi_selftest/efi_selftest.c
> +++ b/lib/efi_selftest/efi_selftest.c
> @@ -74,20 +74,20 @@ void efi_st_exit_boot_services(void)
>   */
>  static int setup(struct efi_unit_test *test, unsigned int *failures)
>  {
> - if (!test->setup) {
> - test->setup_ok = EFI_ST_SUCCESS;
> + int ret;
> +
> + if (!test->setup)
>   return EFI_ST_SUCCESS;
> - }
>   efi_st_printc(EFI_LIGHTBLUE, "\nSetting up '%s'\n", test->name);
> - test->setup_ok = test->setup(handle, systable);
> - if (test->setup_ok != EFI_ST_SUCCESS) {
> + ret = test->setup(handle, systable);
> + if (ret) {
>   efi_st_error("Setting up '%s' failed\n", test->name);
>   ++*failures;
>   } else {
>   efi_st_printc(EFI_LIGHTGREEN,
> "Setting up '%s' succeeded\n", test->name);
>   }
> - return test->setup_ok;
> + return ret;
>  }
>  
>  /*
> @@ -197,7 +197,7 @@ void efi_st_do_tests(const u16 *testname, unsigned int 
> phase,
>   continue;
>   if (steps & EFI_ST_SETUP)
>   setup(test, failures);
> - if (steps & EFI_ST_EXECUTE && test->setup_ok == EFI_ST_SUCCESS)
> + if (steps & EFI_ST_EXECUTE)
>   execute(test, failures);
>   if (steps & EFI_ST_TEARDOWN)
>   teardown(test, failures);
> 

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v11 4/6] efi: Split out test init/uninit into functions

2018-10-15 Thread Heinrich Schuchardt
On 10/15/2018 04:17 PM, Simon Glass wrote:
> The functions in bootefi are very long because they mix high-level code
> and control with the low-level implementation. To help with this, create
> functions which handle preparing for running the test and cleaning up
> afterwards.
> 
> Also shorten the awfully long variable names here.
> 
> Signed-off-by: Simon Glass 
> ---
> 
> Changes in v11: None
> Changes in v9:
> - Add comments to bootefi_test_prepare() about the memset()s
> 
> Changes in v7: None
> Changes in v5:
> - Drop call to efi_init_obj_list() which is now done in do_bootefi()
> 
> Changes in v4: None
> Changes in v3:
> - Add new patch to split out test init/uninit into functions
> 
>  cmd/bootefi.c | 90 +--
>  1 file changed, 65 insertions(+), 25 deletions(-)
> 
> diff --git a/cmd/bootefi.c b/cmd/bootefi.c
> index 82d755ceb31..88b8b0172db 100644
> --- a/cmd/bootefi.c
> +++ b/cmd/bootefi.c
> @@ -454,6 +454,64 @@ exit:
>   return ret;
>  }
>  
> +#ifdef CONFIG_CMD_BOOTEFI_SELFTEST
> +/**
> + * bootefi_test_prepare() - prepare to run an EFI test
> + *
> + * This sets things up so we can call EFI functions. This involves preparing
> + * the 'gd' pointer and setting up the load ed image data structures.
> + *
> + * @image: Pointer to a struct which will hold the loaded image info.
> + *This struct will be inited by this function before use.
> + * @obj: Pointer to a struct which will hold the loaded image object
> + *This struct will be inited by this function before use.
> + * @path: File path to the test being run (often just the test name with a
> + *backslash before it
> + * @test_func: Address of the test function that is being run
> + * @return 0 if OK, -ve on error
> + */
> +static efi_status_t bootefi_test_prepare(struct efi_loaded_image **imagep,
> +  struct efi_loaded_image_obj **objp,
> +  const char *path, ulong test_func)
> +{
> + efi_status_t r;
> +
> + /* Construct a dummy device path */
> + bootefi_device_path = efi_dp_from_mem(EFI_RESERVED_MEMORY_TYPE,
> +   (uintptr_t)test_func,
> +   (uintptr_t)test_func);
> + bootefi_image_path = efi_dp_from_file(NULL, 0, path);
> + r = efi_setup_loaded_image(bootefi_device_path, bootefi_image_path,
> +objp, imagep);
> + if (r)
> + return r;
> + /*
> +  * gd lives in a fixed register which may get clobbered while we execute
> +  * the payload. So save it here and restore it on every callback entry
> +  */
> + efi_save_gd();
> +
> + /* Transfer environment variable efi_selftest as load options */
> + set_load_options(*imagep, "efi_selftest");
> +
> + return 0;
> +}
> +
> +/**
> + * bootefi_test_finish() - finish up after running an EFI test
> + *
> + * @image: Pointer to a struct which holds the loaded image info
> + * @obj: Pointer to a struct which holds the loaded image object
> + */
> +static void bootefi_test_finish(struct efi_loaded_image *image,
> + struct efi_loaded_image_obj *obj)
> +{
> + efi_restore_gd();
> + free(image->load_options);
> + efi_delete_handle(&obj->parent);
> +}
> +#endif /* CONFIG_CMD_BOOTEFI_SELFTEST */
> +
>  static int do_bootefi_bootmgr_exec(void)
>  {
>   struct efi_device_path *device_path, *file_path;
> @@ -532,34 +590,16 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int 
> argc, char * const argv[])
>  #endif
>  #ifdef CONFIG_CMD_BOOTEFI_SELFTEST
>   if (!strcmp(argv[1], "selftest")) {

Why not move the whole body of the if clause to a single separate
function and do the same for 'hello'.

> - struct efi_loaded_image_obj *image_handle;
> - struct efi_loaded_image *loaded_image_info;
> -
> - /* Construct a dummy device path. */
> - bootefi_device_path = efi_dp_from_mem(EFI_RESERVED_MEMORY_TYPE,
> -   (uintptr_t)&efi_selftest,
> -   (uintptr_t)&efi_selftest);
> - bootefi_image_path = efi_dp_from_file(NULL, 0, "\\selftest");
> -
> - r = efi_setup_loaded_image(bootefi_device_path,
> -bootefi_image_path, &image_handle,
> -&loaded_image_info);
> - if (r != EFI_SUCCESS)
> + struct efi_loaded_image_obj *obj;

obj what? Use a speaking name: img_handle.

> + struct efi_loaded_image *image;

This name obscures the variable content. The variable holds the
EFI_LOADED_IMAGE_PROTOCOL. So you could call it img_prot.

Regards

Heinrich

> +
> + if (bootefi_test_prepare(&image, &obj, "\\selftest",
> +  (uintptr_t)&efi_selftest))
>   

[U-Boot] [PATCH] arm: socfpga: fpga: fix type of local variable

2018-10-15 Thread Simon Goldschmidt
The 'status' variable in 'socfpga_load()' for both gen5 and arria10
is of type 'unsigned long' while it is always used as 'int' only.
Change it to 'int'.

Signed-off-by: Simon Goldschmidt 
---

 drivers/fpga/socfpga_arria10.c | 2 +-
 drivers/fpga/socfpga_gen5.c| 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/fpga/socfpga_arria10.c b/drivers/fpga/socfpga_arria10.c
index d6b59498e5..114dd910ab 100644
--- a/drivers/fpga/socfpga_arria10.c
+++ b/drivers/fpga/socfpga_arria10.c
@@ -453,7 +453,7 @@ int fpgamgr_program_finish(void)
  */
 int socfpga_load(Altera_desc *desc, const void *rbf_data, size_t rbf_size)
 {
-   unsigned long status;
+   int status;
 
/* disable all signals from hps peripheral controller to fpga */
writel(0, &system_manager_base->fpgaintf_en_global);
diff --git a/drivers/fpga/socfpga_gen5.c b/drivers/fpga/socfpga_gen5.c
index 184de743fd..6d16e0b37f 100644
--- a/drivers/fpga/socfpga_gen5.c
+++ b/drivers/fpga/socfpga_gen5.c
@@ -204,7 +204,7 @@ static int fpgamgr_program_poll_usermode(void)
  */
 int socfpga_load(Altera_desc *desc, const void *rbf_data, size_t rbf_size)
 {
-   unsigned long status;
+   int status;
 
if ((uint32_t)rbf_data & 0x3) {
puts("FPGA: Unaligned data, realign to 32bit boundary.\n");
-- 
2.17.1

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v3 7/8] test: dm: core: Add a test case for driver marked with DM_FLAG_PRE_RELOC flag

2018-10-15 Thread sjg
Now that we fixed the pre-relocation driver binding for driver marked
with DM_FLAG_PRE_RELOC flag, add a test case to cover that scenario.

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

Changes in v3: None
Changes in v2: None

 arch/sandbox/dts/test.dts |  4 
 test/dm/bus.c |  2 +-
 test/dm/test-fdt.c| 29 ++---
 3 files changed, 31 insertions(+), 4 deletions(-)

Applied to u-boot-dm, thanks!
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v3 8/8] timer: Sort Kconfig driver entries

2018-10-15 Thread sjg
This is currently out of order. Sort it.

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

---

Changes in v3:
- rebase on u-boot/master so that patch [4/8] can be applied cleanly

Changes in v2: None

 drivers/timer/Kconfig | 110 +-
 1 file changed, 55 insertions(+), 55 deletions(-)

Applied to u-boot-dm, thanks!
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v3 6/8] dm: core: Mirror the chosen node parse logic in the livetree scanning

2018-10-15 Thread sjg
Commit f2006808f099: ("dm: core: parse chosen node") added a logic
to parse the chosen node during dm_scan_fdt_node(), but unfortunately
it missed adding the same logic in dm_scan_fdt_live(). This mirrors
the logic in the livetree version.

The weird thing is that commit f2006808f099 did update the test case
to test such logic, but even if I reset to that commit, the test case
still fails, and I have no idea how it could pass.

With this fix, the following 2 test cases now pass:

Test: dm_test_bus_children: bus.c
test/dm/bus.c:112, dm_test_bus_children(): num_devices ==
list_count_items(&uc->dev_head): Expected 7, got 6

Test: dm_test_fdt: test-fdt.c
test/dm/test-fdt.c:184, dm_test_fdt(): num_devices ==
list_count_items(&uc->dev_head): Expected 7, got 6

Fixes: f2006808f099 ("dm: core: parse chosen node")
Signed-off-by: Bin Meng 
Reviewed-by: Simon Glass 
---

Changes in v3: None
Changes in v2: None

 drivers/core/root.c | 10 ++
 1 file changed, 10 insertions(+)

Applied to u-boot-dm, thanks!
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v3 4/8] dm: core: Respect drivers with the DM_FLAG_PRE_RELOC flag in lists_bind_fdt()

2018-10-15 Thread sjg
Currently the comments of several APIs (eg: dm_init_and_scan()) say:

@pre_reloc_only: If true, bind only drivers with the DM_FLAG_PRE_RELOC
flag. If false bind all drivers.

The 'Pre-Relocation Support' chapter in doc/driver-model/README.txt
documents the same that both device tree properties and driver flag
are supported.

However the implementation only checks these special device tree
properties without checking the driver flag at all. This updates
lists_bind_fdt() to consider both scenarios.

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

---

Changes in v3: None
Changes in v2:
- rebase on u-boot/master, and fix one build error

 drivers/core/device.c  |  2 +-
 drivers/core/lists.c   |  9 -
 drivers/core/root.c| 12 
 drivers/serial/serial-uclass.c |  2 +-
 drivers/timer/timer-uclass.c   |  2 +-
 include/dm/lists.h |  5 -
 6 files changed, 19 insertions(+), 13 deletions(-)

Applied to u-boot-dm, thanks!
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v3 1/8] dm: cpu: Fix print_cpuinfo() output

2018-10-15 Thread sjg
It was observed that current output of print_cpuinfo() on QEMU
x86 targets does not have an ending '\n', neither have a leading
'CPU:' any more. However it used to have these before.

It turns out commit c0434407b595 introduced a unified DM version
of print_cpuinfo() that exposed such issue on QEMU x86.

Fixes: c0434407b595 ("board_f: Use static print_cpuinfo if CONFIG_CPU
is active")
Signed-off-by: Bin Meng 
Reviewed-by: Simon Glass 
---

Changes in v3: None
Changes in v2: None

 common/board_f.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Applied to u-boot-dm, thanks!
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v3 5/8] dm: Correct pre_reloc_only parameter description in several APIs' comments

2018-10-15 Thread sjg
The pre_reloc_only parameter description currently only mentions
drivers with the DM_FLAG_PRE_RELOC flag, but does not mention the
special device tree properties. Correct them.

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

Changes in v3: None
Changes in v2: None

 include/dm/device-internal.h |  4 ++--
 include/dm/lists.h   |  4 ++--
 include/dm/root.h| 17 +
 3 files changed, 13 insertions(+), 12 deletions(-)

Applied to u-boot-dm, thanks!
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v3 2/8] cpu: mpc83xx: Remove unnecessary characters in the description string

2018-10-15 Thread sjg
The description string should not contain unnecessary characters,
like the ending '\n' or the leading 'CPU:'.

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

Changes in v3: None
Changes in v2: None

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

Applied to u-boot-dm, thanks!
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v3 3/8] dm: util: Add a livetree equivalent API of dm_fdt_pre_reloc()

2018-10-15 Thread sjg
This adds a new API dm_ofnode_pre_reloc(), a livetree equivalent
API of dm_fdt_pre_reloc().

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

Changes in v3: None
Changes in v2: None

 drivers/core/util.c | 25 +
 include/dm/util.h   | 27 ++-
 2 files changed, 51 insertions(+), 1 deletion(-)

Applied to u-boot-dm, thanks!
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v11 16/16] misc: Add IHS FPGA driver

2018-10-15 Thread sjg
Add a driver for gdsys IHS (Integrated Hardware Systems) FPGAs, which
supports initialization of the FPGA, as well as information gathering.

Reviewed-by: Simon Glass 
Signed-off-by: Mario Six 

---
v10 -> v11:
No changes

v9 -> v10:
No changes

v8 -> v9:
No changes

v7 -> v8:
No changes

v6 -> v7:
No changes

v5 -> v6:
No changes

v4 -> v5:
No changes

v3 -> v4:
* Switched from 'res' as the name for return variables to 'ret'

v2 -> v3:
* Fixed style violations
* Added full documentation
* Extracted some magic numbers to constants
* Removed unnecessary includes
* Extracted wait_for_fpga_done
* Improved error handling and reporting
* Added device-tree-binding files
* Improved Kconfig entry

v1 -> v2:
New in v2
---
 .../bindings/misc/gdsys,iocon_fpga.txt|  19 +
 .../bindings/misc/gdsys,iocpu_fpga.txt|  19 +
 drivers/misc/Kconfig  |   9 +
 drivers/misc/Makefile |   1 +
 drivers/misc/ihs_fpga.c   | 867 ++
 drivers/misc/ihs_fpga.h   |  49 +
 6 files changed, 964 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/misc/gdsys,iocon_fpga.txt
 create mode 100644 Documentation/devicetree/bindings/misc/gdsys,iocpu_fpga.txt
 create mode 100644 drivers/misc/ihs_fpga.c
 create mode 100644 drivers/misc/ihs_fpga.h

Applied to u-boot-dm, thanks!
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


  1   2   >