Re: [U-Boot] [PATCH 17/17] fs-test: fix false positive error at Test Case 12

2018-07-29 Thread Heinrich Schuchardt
On 07/20/2018 04:57 AM, AKASHI Takahiro wrote:
> The error message to be matched is wrong. Fix it.
> 
> Signed-off-by: AKASHI Takahiro 
> ---
>  test/fs/fs-test.sh | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/test/fs/fs-test.sh b/test/fs/fs-test.sh
> index 2e8d5ee4df..7b0c5ea56f 100755
> --- a/test/fs/fs-test.sh
> +++ b/test/fs/fs-test.sh
> @@ -522,7 +522,7 @@ function check_results() {
>   "TC11: 1MB write to $3.w - content verified"
>  
>   # Check lookup of 'dot' directory
> - grep -A4 "Test Case 12 " "$1" | grep -q 'Unable to write file'
> + grep -A4 "Test Case 12 " "$1" | grep -q 'Unable to write'
>   pass_fail "TC12: 1MB write to . - write denied"
>  
>   # Check directory traversal
> 

Tom suggested in
https://lists.denx.de/pipermail/u-boot/2018-July/336378.html that the
comment headers in test/fs/fs-test.sh should be updated to reflect the
total number of passes and fails.

Best regards

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


[U-Boot] [PATCH] net: pch_gbe: Make probe/remove static

2018-07-29 Thread Bin Meng
These two routines are internal to pch_gbe driver.

Signed-off-by: Bin Meng 
---

 drivers/net/pch_gbe.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/pch_gbe.c b/drivers/net/pch_gbe.c
index d31c45f..2286dd0 100644
--- a/drivers/net/pch_gbe.c
+++ b/drivers/net/pch_gbe.c
@@ -429,7 +429,7 @@ static int pch_gbe_phy_init(struct udevice *dev)
return 0;
 }
 
-int pch_gbe_probe(struct udevice *dev)
+static int pch_gbe_probe(struct udevice *dev)
 {
struct pch_gbe_priv *priv;
struct eth_pdata *plat = dev_get_platdata(dev);
@@ -464,7 +464,7 @@ int pch_gbe_probe(struct udevice *dev)
return pch_gbe_phy_init(dev);
 }
 
-int pch_gbe_remove(struct udevice *dev)
+static int pch_gbe_remove(struct udevice *dev)
 {
struct pch_gbe_priv *priv = dev_get_priv(dev);
 
-- 
2.7.4

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


Re: [U-Boot] [PULL] efi patch queue 2018-07-25

2018-07-29 Thread Heinrich Schuchardt
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA512

On 07/29/2018 03:33 AM, Tom Rini wrote:
> On Sat, Jul 28, 2018 at 11:32:56PM +0200, Heinrich Schuchardt
> wrote:
>> -BEGIN PGP SIGNED MESSAGE- Hash: SHA512
>> 
>> On 07/28/2018 08:33 PM, Tom Rini wrote:
>>> On Sat, Jul 28, 2018 at 07:10:39PM +0200, Heinrich Schuchardt 
>>> wrote:
 -BEGIN PGP SIGNED MESSAGE- Hash: SHA512
 
 On 07/28/2018 06:32 PM, Tom Rini wrote:
> On Sat, Jul 28, 2018 at 06:21:58PM +0200, Heinrich
> Schuchardt wrote:
>> -BEGIN PGP SIGNED MESSAGE- Hash: SHA512
>> 
>> On 07/28/2018 06:13 PM, Tom Rini wrote:
>>> On Sat, Jul 28, 2018 at 06:07:20PM +0200, Heinrich 
>>> Schuchardt wrote:
>>> 
 -BEGIN PGP SIGNED MESSAGE- Hash: SHA512
 
 On 07/28/2018 05:55 PM, Tom Rini wrote:
> On Wed, Jul 25, 2018 at 03:04:27PM +0200,
> Alexander Graf wrote:
> 
>> Hi Tom,
>> 
>> This is my current patch queue for efi.  Please 
>> pull.
>> 
>> Alex
>> 
>> 
>> The following changes since commit 
>> 323a73adc9a1bf2de43fe03bdd9c3038ce7c2784:
>> 
>> mtd: nand: add new enum for storing ECC algorithm
>>  (2018-07-23 14:33:21 -0400)
>> 
>> are available in the git repository at:
>> 
>> git://github.com/agraf/u-boot.git 
>> tags/signed-efi-next
>> 
>> for you to fetch changes up to 
>> 0b8a88ab6aa24de0ef2bf1e8109409f71e770a8e:
>> 
>> MAINTAINERS: assign lib/charset.c (2018-07-25 
>> 15:00:24 +0200)
>> 
> 
> NAK, this breaks one of the filesystem tests. 
> Specifically: commit 
> 0dc1bfb7302d220a48364263d5632d6d572b069b Author: 
> Heinrich Schuchardt  Date:
> Mon Jul 2 02:41:23 2018 +0200
> 
> fs: fat: cannot write to subdirectories
> 
> Breaks TC13: 1MB write to ./1MB.file.w2
> 
 
 Hello Tom,
 
 please, provide the link to the Travis log with the 
 failure.
>>> 
>>> It's actually not in travis.  Running
>>> test/fs/fs-test.sh is annoying to automate:
>>> FSTST=`./test/fs/fs-test.sh 2>&1 | tail -n 3 | head -n
>>> 1` echo $FSTST | grep -q "TOTAL PASS: 204 TOTAL FAIL:
>>> 12" && exit 0 || exit 1
>>> 
>>> but I should see if I can get that into .travis.yml.
>>> 
>> 
>> ./test/fs/fs-test.sh Missing mkfs binary. Exiting!
>> 
>> You wouldn't run tests as root? Is this test meant to be
>> run with fakeroot?
> 
> It requires sudo to work along with various utilities to
> make the various filesystems.
> 
 
 Tom please, have a look at the files created by the tests w/o
 my patch.
 
 This is what the find command returns:
 
 sandbox/test/fs/mnt sandbox/test/fs/mnt/SUBDIR 
 sandbox/test/fs/mnt/2.5GB.file sandbox/test/fs/mnt/1MB.file 
 sandbox/test/fs/mnt/1MB.file.w
 sandbox/test/fs/mnt/1MB.file.w2 
 sandbox/test/fs/mnt/./1MB.file.w2
 
 You observe that the last file has an illegal file name
 (yes, the filename itself is "./1MB.file.w2". It should never
 have been created.
 
 Without my patch this illegal file is not created.
 
 Why should this be a reason to dismiss my patch?
>>> 
>>> Ah, OK, thanks for looking.  Please submit a patch that
>>> updates the tests.
>>> 
>> 
>> With Takahiro's patch series
>> 
>> fs: fat: extend FAT write operations 
>> https://patchwork.ozlabs.org/project/uboot/list/?series=56580 
>> https://lists.denx.de/pipermail/u-boot/2018-July/335683.html
>> 
>> the FAT driver will finally correctly support paths with
>> subdirectories.
>> 
>> With that patch series the created files are:
>> 
>> sandbox/test/fs/mnt sandbox/test/fs/mnt/SUBDIR 
>> sandbox/test/fs/mnt/2.5GB.file sandbox/test/fs/mnt/1MB.file 
>> sandbox/test/fs/mnt/1MB.file.w sandbox/test/fs/mnt/1MB.file.w2
>> 
>> There is nothing wrong with the TC13 test. After writing it tries
>> to do the verification with (b) and without (c) a relative path.
>> If both subtests are passed the file system is working as
>> expected. And as you already will have observed TC13b and TC13c
>> are not passed without Takahiro's patch series.
> 
> Then I guess the answer is an update to fs-test.sh to note that
> the expected, for now, results should be 200/16 and to make sure
> that Takahiro's series also updates fs-test.sh results.  Thanks!
> 

@Tom:
I am not able to reproduce that 200/16 result, I get 189/27. The
difference are probably the 11 fails on ext4.

Creating files in ext4 image if not already present.
mount: /home/user/u-boot/sandbox/test/fs/mnt: cannot mount; probably
corrupted filesystem on /dev/loop0.
umount: sandbox/test/fs/mnt: not mounted.
rmdir: failed to remove 'sandbox/test/fs/mnt': Directory not empty
** Start sandb

[U-Boot] [PATCH] ARC: Enable unaligned access in hardware if compiler uses it

2018-07-29 Thread Alexey Brodkin
Even if ARC core might handle unaligned access to data this
hardware feature by default is disabled.

But GCC starting from 8.1.0 unconditionally uses it for ARC HS cores.
Which leads to quite strange and fatal run-time failures like the one
below if HW is not configured properly:
| hsdk# sf probe
| Misaligned data access exception @ 0xbff794d4
| ECR:0x000d
| RET:0xbff794d4
| BLINK:  0xbff79644
| STAT32: 0x0800
| GP: 0x1003e000   r25: 0xbfd58f08
| BTA: 0xbff794a4  SP: 0xbfd58cd4  FP: 0xbfd58ef0
| LPS: 0xbff90240 LPE: 0xbff90244 LPC: 0x
| r00: 0x r01: 0x0003 r02: 0x26bf
| r03: 0x r04: 0x0100 r05: 0x
| r06: 0x0001 r07: 0x r08: 0x1dcd6500
| r09: 0x r10: 0x0020 r11: 0x
| r12: 0x1b3d4440 r13: 0xbff9eca4 r14: 0xbfd59d68
| r15: 0xbfd60cd0 r16: 0x r17: 0x
| r18: 0xbff9ed14 r19: 0xbfd59c78 r20: 0xbfd58d40
| r21: 0xbfd58d44 r22: 0x r23: 0x
| r24: 0xbfd59ba8
| Resetting CPU ...

Now we're checking for __ARC_UNALIGNED__ define emitted by the
compiler if it's going to use unaligned access and then we
force-enable it in hardware too.

Signed-off-by: Alexey Brodkin 
---
 arch/arc/include/asm/arcregs.h | 3 +++
 arch/arc/lib/start.S   | 9 +
 2 files changed, 12 insertions(+)

diff --git a/arch/arc/include/asm/arcregs.h b/arch/arc/include/asm/arcregs.h
index 56ec11f789b5..9920d2e71952 100644
--- a/arch/arc/include/asm/arcregs.h
+++ b/arch/arc/include/asm/arcregs.h
@@ -19,6 +19,9 @@
 #define ARC_AUX_IDENTITY   0x04
 #define ARC_AUX_STATUS32   0x0a
 
+/* STATUS32 Bits Positions */
+#define STATUS_AD_BIT  19  /* Enable unaligned access */
+
 /* Instruction cache related auxiliary registers */
 #define ARC_AUX_IC_IVIC0x10
 #define ARC_AUX_IC_CTRL0x11
diff --git a/arch/arc/lib/start.S b/arch/arc/lib/start.S
index e573ce7718b9..84959b41bdf5 100644
--- a/arch/arc/lib/start.S
+++ b/arch/arc/lib/start.S
@@ -61,6 +61,15 @@ ENTRY(_start)
 1:
 #endif
 
+#ifdef __ARC_UNALIGNED__
+   /*
+* Enable handling of unaligned access in the CPU as by default
+* this HW feature is disabled while GCC starting from 8.1.0
+* unconditionally uses it for ARC HS cores.
+*/
+   flag1 << STATUS_AD_BIT
+#endif
+
/* Establish C runtime stack and frame */
mov %sp, CONFIG_SYS_INIT_SP_ADDR
mov %fp, %sp
-- 
2.17.1

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


[U-Boot] [PATCH v4 1/2] lib: crc32: mark function crc32() as __efi_runtime

2018-07-29 Thread Heinrich Schuchardt
The function crc32() is needed by the EFI subsystem at runtime. So it has
to be linked into the runtime section together with all dependencies.

Eliminate empty defines local and ZEXPORT.

Mark variables as static which are not exported.

Signed-off-by: Heinrich Schuchardt 
---
v4:
put all relevant functions into the runtime code section
put none into the runtime data section
v3
new patch
---
 lib/crc32.c | 26 ++
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/lib/crc32.c b/lib/crc32.c
index 7f545fde4a0..4dab6226427 100644
--- a/lib/crc32.c
+++ b/lib/crc32.c
@@ -12,6 +12,7 @@
 #include 
 #else
 #include 
+#include 
 #endif
 #include 
 #include 
@@ -21,16 +22,18 @@
 #endif
 #include "u-boot/zlib.h"
 
-#define local static
-#define ZEXPORT/* empty */
+#ifdef USE_HOSTCC
+#define __efi_runtime
+#define __efi_runtime_data
+#endif
 
 #define tole(x) cpu_to_le32(x)
 
 #ifdef CONFIG_DYNAMIC_CRC_TABLE
 
-local int crc_table_empty = 1;
-local uint32_t crc_table[256];
-local void make_crc_table OF((void));
+static int __efi_runtime_data crc_table_empty = 1;
+static uint32_t __efi_runtime_data crc_table[256];
+static void __efi_runtime make_crc_table OF((void));
 
 /*
   Generate a table for a byte-wise 32-bit CRC calculation on the polynomial:
@@ -56,7 +59,7 @@ local void make_crc_table OF((void));
   the information needed to generate CRC's on data a byte at a time for all
   combinations of CRC register values and incoming bytes.
 */
-local void make_crc_table()
+static void __efi_runtime make_crc_table(void)
 {
   uint32_t c;
   int n, k;
@@ -83,7 +86,7 @@ local void make_crc_table()
  * Table of CRC-32's of all single-byte values (made by make_crc_table)
  */
 
-local const uint32_t crc_table[256] = {
+static const uint32_t __efi_runtime_data crc_table[256] = {
 tole(0xL), tole(0x77073096L), tole(0xee0e612cL), tole(0x990951baL),
 tole(0x076dc419L), tole(0x706af48fL), tole(0xe963a535L), tole(0x9e6495a3L),
 tole(0x0edb8832L), tole(0x79dcb8a4L), tole(0xe0d5e91eL), tole(0x97d2d988L),
@@ -176,7 +179,7 @@ const uint32_t * ZEXPORT get_crc_table()
 /* No ones complement version. JFFS2 (and other things ?)
  * don't use ones compliment in their CRC calculations.
  */
-uint32_t ZEXPORT crc32_no_comp(uint32_t crc, const Bytef *buf, uInt len)
+uint32_t __efi_runtime crc32_no_comp(uint32_t crc, const Bytef *buf, uInt len)
 {
 const uint32_t *tab = crc_table;
 const uint32_t *b =(const uint32_t *)buf;
@@ -218,7 +221,7 @@ uint32_t ZEXPORT crc32_no_comp(uint32_t crc, const Bytef 
*buf, uInt len)
 }
 #undef DO_CRC
 
-uint32_t ZEXPORT crc32 (uint32_t crc, const Bytef *p, uInt len)
+uint32_t __efi_runtime crc32(uint32_t crc, const Bytef *p, uInt len)
 {
  return crc32_no_comp(crc ^ 0xL, p, len) ^ 0xL;
 }
@@ -227,9 +230,8 @@ uint32_t ZEXPORT crc32 (uint32_t crc, const Bytef *p, uInt 
len)
  * Calculate the crc32 checksum triggering the watchdog every 'chunk_sz' bytes
  * of input.
  */
-uint32_t ZEXPORT crc32_wd (uint32_t crc,
-  const unsigned char *buf,
-  uInt len, uInt chunk_sz)
+uint32_t crc32_wd(uint32_t crc, const unsigned char *buf, uInt len,
+ uInt chunk_sz)
 {
 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
const unsigned char *end, *curr;
-- 
2.18.0

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


[U-Boot] [PATCH v4 0/2] efi_loader: correctly initialize system table crc32

2018-07-29 Thread Heinrich Schuchardt
Update the crc32 of the runtime services table when detaching.

Travis results where ok except for two file size limits exceeded:
https://travis-ci.org/xypron2/u-boot/builds/409390055

v4:
Remove patches accepted for efi-next
Rebase on current master
Do not put functions into runtime data

Heinrich Schuchardt (2):
  lib: crc32: mark function crc32() as __efi_runtime
  efi_loader: update runtime services table crc32

 include/efi_loader.h  |  3 +++
 lib/crc32.c   | 26 ++
 lib/efi_loader/efi_boottime.c | 12 
 lib/efi_loader/efi_runtime.c  | 15 +++
 4 files changed, 32 insertions(+), 24 deletions(-)

-- 
2.18.0

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


[U-Boot] [PATCH v4 2/2] efi_loader: update runtime services table crc32

2018-07-29 Thread Heinrich Schuchardt
The crc32 of the runtime services table must be updated after detaching.

efi_update_table_header_crc32() must be __efi_runtime. So move it to
efi_runtime.c

Signed-off-by: Heinrich Schuchardt 
---
v3
new patch
v4:
rebase on current master
---
 include/efi_loader.h  |  3 +++
 lib/efi_loader/efi_boottime.c | 12 
 lib/efi_loader/efi_runtime.c  | 15 +++
 3 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/include/efi_loader.h b/include/efi_loader.h
index 57ca5502726..f162adfff7e 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -417,6 +417,9 @@ static inline int guidcmp(const efi_guid_t *g1, const 
efi_guid_t *g2)
 #define __efi_runtime_data __attribute__ ((section (".data.efi_runtime")))
 #define __efi_runtime __attribute__ ((section (".text.efi_runtime")))
 
+/* Update CRC32 in table header */
+void __efi_runtime efi_update_table_header_crc32(struct efi_table_hdr *table);
+
 /* Call this with mmio_ptr as the _pointer_ to a pointer to an MMIO region
  * to make it available at runtime */
 efi_status_t efi_add_runtime_mmio(void *mmio_ptr, u64 len);
diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c
index b9e54f551a4..618e8a8d8cf 100644
--- a/lib/efi_loader/efi_boottime.c
+++ b/lib/efi_loader/efi_boottime.c
@@ -153,18 +153,6 @@ const char *__efi_nesting_dec(void)
return indent_string(--nesting_level);
 }
 
-/**
- * efi_update_table_header_crc32() - Update CRC32 in table header
- *
- * @table: EFI table
- */
-static void efi_update_table_header_crc32(struct efi_table_hdr *table)
-{
-   table->crc32 = 0;
-   table->crc32 = crc32(0, (const unsigned char *)table,
-table->headersize);
-}
-
 /**
  * efi_queue_event() - queue an EFI event
  * @event: event to signal
diff --git a/lib/efi_loader/efi_runtime.c b/lib/efi_loader/efi_runtime.c
index 06958f23fa1..351db8d8ed5 100644
--- a/lib/efi_loader/efi_runtime.c
+++ b/lib/efi_loader/efi_runtime.c
@@ -84,6 +84,18 @@ struct elf_rela {
  * handle a good number of runtime callbacks
  */
 
+/**
+ * efi_update_table_header_crc32() - Update crc32 in table header
+ *
+ * @table: EFI table
+ */
+void __efi_runtime efi_update_table_header_crc32(struct efi_table_hdr *table)
+{
+   table->crc32 = 0;
+   table->crc32 = crc32(0, (const unsigned char *)table,
+table->headersize);
+}
+
 static void EFIAPI efi_reset_system_boottime(
enum efi_reset_type reset_type,
efi_status_t reset_status,
@@ -273,6 +285,9 @@ static void efi_runtime_detach(ulong offset)
debug("%s: Setting %p to %lx\n", __func__, p, newaddr);
*p = newaddr;
}
+
+   /* Update crc32 */
+   efi_update_table_header_crc32(&efi_runtime_services.hdr);
 }
 
 /* Relocate EFI runtime to uboot_reloc_base = offset */
-- 
2.18.0

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


Re: [U-Boot] [PATCH v4 1/2] lib: crc32: mark function crc32() as __efi_runtime

2018-07-29 Thread Bin Meng
Hi Heinrich,

On Sun, Jul 29, 2018 at 3:49 PM, Heinrich Schuchardt  wrote:
> The function crc32() is needed by the EFI subsystem at runtime. So it has
> to be linked into the runtime section together with all dependencies.
>
> Eliminate empty defines local and ZEXPORT.
>
> Mark variables as static which are not exported.
>
> Signed-off-by: Heinrich Schuchardt 
> ---
> v4:
> put all relevant functions into the runtime code section
> put none into the runtime data section
> v3
> new patch
> ---
>  lib/crc32.c | 26 ++
>  1 file changed, 14 insertions(+), 12 deletions(-)
>

Is it possible to use linux kernel's lib/crc32.c? This way we can
future sync U-Boot's crc32 implementation with kernel's. Thanks!

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


[U-Boot] [PATCH] ARC: AXS10x/HSDK: Use our own version of mkimage

2018-07-29 Thread Alexey Brodkin
Since U-Boot tools are being built anyways it's much nicer
to use them instead of relying on some of them bein installed
on build host (which might easily not be the case).

Signed-off-by: Alexey Brodkin 
---
 board/synopsys/axs10x/config.mk | 2 +-
 board/synopsys/hsdk/config.mk   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/board/synopsys/axs10x/config.mk b/board/synopsys/axs10x/config.mk
index db04b986d1b9..81ff498f8189 100644
--- a/board/synopsys/axs10x/config.mk
+++ b/board/synopsys/axs10x/config.mk
@@ -18,6 +18,6 @@ else
--image $(srctree)/u-boot.bin \
--elf $(srctree)/u-boot
 endif
-   $(Q)mkimage -T script -C none -n 'uboot update script' \
+   $(Q)tools/mkimage -T script -C none -n 'uboot update script' \
-d $(srctree)/u-boot-update.txt \
$(srctree)/u-boot-update.img &> /dev/null
diff --git a/board/synopsys/hsdk/config.mk b/board/synopsys/hsdk/config.mk
index 16fb59c438cd..9e280f921a1b 100644
--- a/board/synopsys/hsdk/config.mk
+++ b/board/synopsys/hsdk/config.mk
@@ -6,6 +6,6 @@ bsp-generate: u-boot u-boot.bin
$(Q)python3 $(srctree)/board/$(BOARDDIR)/headerize-hsdk.py \
--arc-id 0x52 --image $(srctree)/u-boot.bin \
--elf $(srctree)/u-boot
-   $(Q)mkimage -T script -C none -n 'uboot update script' \
+   $(Q)tools/mkimage -T script -C none -n 'uboot update script' \
-d $(srctree)/u-boot-update.txt \
$(srctree)/u-boot-update.scr &> /dev/null
-- 
2.17.1

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


[U-Boot] [PATCH 1/1] drivers: serial: document on_baudrate()

2018-07-29 Thread Heinrich Schuchardt
Add parameter description.

Signed-off-by: Heinrich Schuchardt 
---
 drivers/serial/serial.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/drivers/serial/serial.c b/drivers/serial/serial.c
index 63b232b536c..c84fd83f210 100644
--- a/drivers/serial/serial.c
+++ b/drivers/serial/serial.c
@@ -36,7 +36,15 @@ static void serial_null(void)
 /**
  * on_baudrate() - Update the actual baudrate when the env var changes
  *
+ * @name:  changed environment variable
+ * @value: new value of the environment variable
+ * @op:operation (create, overwrite, or delete)
+ * @flags: attributes of environment variable change,
+ * see flags H_* in include/search.h
+ *
  * This will check for a valid baudrate and only apply it if valid.
+ *
+ * Return: 0 on success, 1 on error
  */
 static int on_baudrate(const char *name, const char *value, enum env_op op,
int flags)
-- 
2.18.0

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


[U-Boot] [PATCH 1/1] README: U_BOOT_ENV_CALLBACK functions

2018-07-29 Thread Heinrich Schuchardt
Describe the interface of environment variable callback functions.

Signed-off-by: Heinrich Schuchardt 
---
 README | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/README b/README
index aee0f7371c4..179d6d74a4a 100644
--- a/README
+++ b/README
@@ -3943,6 +3943,17 @@ If CONFIG_REGEX is defined, the variable_name above is 
evaluated as a
 regular expression. This allows multiple variables to be connected to
 the same callback without explicitly listing them all out.
 
+The signature of the callback functions is:
+
+int callback(const char *name, const char *value, enum env_op op, int 
flags)
+
+* name - changed environment variable
+* value - new value of the environment variable
+* op - operation (create, overwrite, or delete)
+* flags - attributes of the environment variable change, see flags H_* in
+  include/search.h
+
+The return value is 0 if the variable change is accepted and 1 otherwise.
 
 Command Line Parsing:
 =
-- 
2.18.0

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


Re: [U-Boot] [PATCH] env: common: load read-only variables after reset

2018-07-29 Thread Yaniv Levinsky
Hello Wolfgang,

On 07/28/2018 03:56 PM, Wolfgang Denk wrote:
> Dear Yaniv,
> 
> In message <20180727153444.5602-1-yaniv.levin...@compulab.co.il> you wrote:
>> U-Boot fails to load read-only variables from storage after a reset. It
>> happens because the environment hash table prevents creating read-only
>> variables unless the H_FORCE flag is passed.
> 
> This is NOT a good idea.  "env import" should respect read-only
> settings in exactly the same way as "env set" does.  Please keep in
> minf that the user my set a variable to read-only exactly just to
> prevent if from bein (accidentially) overwritten when importing an
> (not exactly know) set of environment settings.  Your patch would
> kill any such protection.
> 
> IMO the correct approach would be to add a "-f" flag to "env import"
> and the, and ONLY then, also set the H_FORCE flag.
> 
> Naked-by: Wolfgang Denk 
> 
> Best regards,
> 
> Wolfgang Denk
> 
Thank you for reviewing the patch.

The command "env import" should of course respect access restriction flags.

Confusingly, the function env_import() in env/common.c has nothing to do with
the implementation of the "env import" command. This is done entirely by
do_env_import() in cmd/nvedit.c.

To the best of my knowledge, the function env_import() is used only by storage
devices to load the environment on boot. In this scenario, I think we do need to
ignore access restriction flags. Otherwise, read-only variables won't load from
storage with the rest of the environment.

Please correct me if I'm wrong.

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


[U-Boot] [PATCH 1/1] doc: add structure to Sphinx generated docs

2018-07-29 Thread Heinrich Schuchardt
Create separate html pages for linker lists, the serial subsystem,
and the EFI subsystem.

Add a table of content.

Signed-off-by: Heinrich Schuchardt 
---
 Documentation/efi.rst  |  16 +
 Documentation/index.rst| 122 +++--
 Documentation/linker_lists.rst | 100 +++
 Documentation/serial.rst   |   7 ++
 MAINTAINERS|   1 +
 5 files changed, 132 insertions(+), 114 deletions(-)
 create mode 100644 Documentation/efi.rst
 create mode 100644 Documentation/linker_lists.rst
 create mode 100644 Documentation/serial.rst

diff --git a/Documentation/efi.rst b/Documentation/efi.rst
new file mode 100644
index 000..51c1de24f84
--- /dev/null
+++ b/Documentation/efi.rst
@@ -0,0 +1,16 @@
+.. SPDX-License-Identifier: GPL-2.0+
+
+EFI subsystem
+=
+
+Boot services
+-
+
+.. kernel-doc:: lib/efi_loader/efi_boottime.c
+   :internal:
+
+Runtime services
+
+
+.. kernel-doc:: lib/efi_loader/efi_runtime.c
+   :internal:
diff --git a/Documentation/index.rst b/Documentation/index.rst
index a7b0ee4e87d..0353c10a4b0 100644
--- a/Documentation/index.rst
+++ b/Documentation/index.rst
@@ -1,117 +1,11 @@
-
-U-Boot Hacker Manual
-
+.. SPDX-License-Identifier: GPL-2.0+
 
-Linker-Generated Arrays
-===
+###
+U-Boot Developer Manual
+###
 
-A linker list is constructed by grouping together linker input
-sections, each containing one entry of the list. Each input section
-contains a constant initialized variable which holds the entry's
-content. Linker list input sections are constructed from the list
-and entry names, plus a prefix which allows grouping all lists
-together. Assuming _list and _entry are the list and entry names,
-then the corresponding input section name is
+.. toctree::
 
-::
-
-  .u_boot_list_ + 2_ + @_list + _2_ + @_entry
-
-and the C variable name is
-
-::
-
-  _u_boot_list + _2_ + @_list + _2_ + @_entry
-
-This ensures uniqueness for both input section and C variable name.
-
-Note that the names differ only in the first character, "." for the
-section and "_" for the variable, so that the linker cannot confuse
-section and symbol names. From now on, both names will be referred
-to as
-
-::
-
-  %u_boot_list_ + 2_ + @_list + _2_ + @_entry
-
-Entry variables need never be referred to directly.
-
-The naming scheme for input sections allows grouping all linker lists
-into a single linker output section and grouping all entries for a
-single list.
-
-Note the two '_2_' constant components in the names: their presence
-allows putting a start and end symbols around a list, by mapping
-these symbols to sections names with components "1" (before) and
-"3" (after) instead of "2" (within).
-Start and end symbols for a list can generally be defined as
-
-::
-
-  %u_boot_list_2_ + @_list + _1_...
-  %u_boot_list_2_ + @_list + _3_...
-
-Start and end symbols for the whole of the linker lists area can be
-defined as
-
-::
-
-  %u_boot_list_1_...
-  %u_boot_list_3_...
-
-Here is an example of the sorted sections which result from a list
-"array" made up of three entries : "first", "second" and "third",
-iterated at least once.
-
-::
-
-  .u_boot_list_2_array_1
-  .u_boot_list_2_array_2_first
-  .u_boot_list_2_array_2_second
-  .u_boot_list_2_array_2_third
-  .u_boot_list_2_array_3
-
-If lists must be divided into sublists (e.g. for iterating only on
-part of a list), one can simply give the list a name of the form
-'outer_2_inner', where 'outer' is the global list name and 'inner'
-is the sub-list name. Iterators for the whole list should use the
-global list name ("outer"); iterators for only a sub-list should use
-the full sub-list name ("outer_2_inner").
-
-Here is an example of the sections generated from a global list
-named "drivers", two sub-lists named "i2c" and "pci", and iterators
-defined for the whole list and each sub-list:
-
-::
-
-  %u_boot_list_2_drivers_1
-  %u_boot_list_2_drivers_2_i2c_1
-  %u_boot_list_2_drivers_2_i2c_2_first
-  %u_boot_list_2_drivers_2_i2c_2_first
-  %u_boot_list_2_drivers_2_i2c_2_second
-  %u_boot_list_2_drivers_2_i2c_2_third
-  %u_boot_list_2_drivers_2_i2c_3
-  %u_boot_list_2_drivers_2_pci_1
-  %u_boot_list_2_drivers_2_pci_2_first
-  %u_boot_list_2_drivers_2_pci_2_second
-  %u_boot_list_2_drivers_2_pci_2_third
-  %u_boot_list_2_drivers_2_pci_3
-  %u_boot_list_2_drivers_3
-
-.. kernel-doc:: include/linker_lists.h
-   :internal:
-
-Serial system
-=
-
-.. kernel-doc:: drivers/serial/serial.c
-   :internal:
-
-The U-Boot EFI subsystem
-
-
-Boot services
--
-
-.. kernel-doc:: lib/efi_loader/efi_boottime.c
-   :internal:
+   efi
+   linker_lists
+   serial
diff --git a/Documentation/linker_lists.rst b/Documentation/linker_lists.rst
new file mode 100644
index 000..72f514e0ac0
--- /dev/null
+++ b/Documentation/linke

[U-Boot] [PATCH 1/1] doc: README.iscsi: make compatible with restructured text

2018-07-29 Thread Heinrich Schuchardt
The Sphinx documentation system uses restructured text.
Make the README.iscsi file compatible.

Signed-off-by: Heinrich Schuchardt 
---
 doc/README.iscsi | 130 +--
 1 file changed, 68 insertions(+), 62 deletions(-)

diff --git a/doc/README.iscsi b/doc/README.iscsi
index cb71c6e7446..d8880415e32 100644
--- a/doc/README.iscsi
+++ b/doc/README.iscsi
@@ -1,6 +1,8 @@
-# iSCSI booting with U-Boot and iPXE
+iSCSI booting with U-Boot and iPXE
+==
 
-## Motivation
+Motivation
+--
 
 U-Boot has only a reduced set of supported network protocols. The focus for
 network booting has been on UDP based protocols. A TCP stack and HTTP support
@@ -32,14 +34,15 @@ via HTTPS and to download any other files needed for 
booting via iSCSI from the
 same target where the operating system is installed.
 
 An alternative to implementing these protocols in U-Boot is to use an existing
-software that can run on top of U-Boot. iPXE is the "swiss army knife" of
+software that can run on top of U-Boot. iPXE[1] is the "swiss army knife" of
 network booting. It supports both HTTPS and iSCSI. It has a scripting engine 
for
 fine grained control of the boot process and can provide a command shell.
 
 iPXE can be built as an EFI application (named snp.efi) which can be loaded and
 run by U-Boot.
 
-## Boot sequence
+Boot sequence
+-
 
 U-Boot loads the EFI application iPXE snp.efi using the bootefi command. This
 application has network access via the simple network protocol offered by
@@ -56,67 +59,68 @@ For a selected iSCSI target iPXE sets up a handle with the 
block IO protocol. It
 uses the ConnectController boot service of U-Boot to request U-Boot to connect 
a
 file system driver. U-Boot reads from the iSCSI drive via the block IO protocol
 offered by iPXE. It creates the partition handles and installs the simple file
-protocol. Now iPXE can call the simple file protocol to load Grub. U-Boot uses
-the block IO protocol offered by iPXE to fulfill the request.
-
-Once Grub is started it uses the same block IO protocol to load Linux. Via
-the EFI stub Linux is called as an EFI application.
-
-```
-   ++  ++
-   || Runs ||
-   | U-Boot |=>| iPXE   |
-   | EFI|  | snp.efi|
-++ || DHCP ||
-||<||<=||
-| DHCP   | || Get IP   ||
-| Server | || Address  ||
-||>||=>||
-++ || Response ||
-   ||  ||
-   ||  ||
-++ || HTTPS||
-||<||<=||
-| HTTPS  | || Load ||
-| Server | || Script   ||
-||>||=>||
-++ ||  ||
-   ||  ||
-   ||  ||
-++ || iSCSI||
-||<||<=||
-| iSCSI  | || Auth ||
-| Server |>||=>||
-|| ||  ||
-|| || Loads||
-||<||<=||++
-|| || Grub || Runs   ||
-||>||=>||===>| Grub   |
-|| ||  ||||
-|| ||  ||||
-|| ||  || Loads  ||
-||<||<=||<===||  ++
-|| ||  || Linux  || Runs ||
-||>||=>||===>||=>| Linux  |
-|| ||  ||||  ||
-++ ++  ++++  ||
- ||
- ||
- | ~ ~ ~ ~|
-```
-
-## Security
+protocol. Now iPXE can call the simple file protocol to load GRUB[2]. U-Boot
+uses the block IO protocol offered by iPXE to fulfill the request.
+
+Once GRUB is started it uses the same block IO protocol to load Linux. Via
+the EFI stub Linux is called as an EFI application::
+
+  ++ ++
+  || Runs||
+  | U-Boot |>| iPXE   |
+  | EFI| | snp.efi|
+++|| DHCP|  

Re: [U-Boot] [BUG] qemu-x86_defconfig does not build with GCC 8.1

2018-07-29 Thread Heinrich Schuchardt
On 07/29/2018 02:40 AM, Bin Meng wrote:
> Hi Heinrich,
> 
> On Sat, Jul 28, 2018 at 11:42 PM, Heinrich Schuchardt
>  wrote:
>> Debian Buster has upgraded gcc to version 8.1.
> 
> Do you know any pre-built gcc 8.1 that can be used on other
> distributions than Debian Buster, so that I can take a look? I am
> currently on Ubuntu 16.04.
> 

Ubuntu Cosmic has gcc 8.2. Setting up a virtual machine with
virt-manager is quite easy.

>>
>> With gcc 8.1 I get an error when trying to build qemu-x86_defconfig
>>
>> {standard input}: Assembler messages:
>> {standard input}:7465: Error: junk at end of line, first unrecognized
>> character is `@'
>>
>> The problematic line in the generated assembler code is
>>
>> .long   end.6133@gotoff-start.6130@gotoff
>>
>> This difference relates to the length of a linker generated list and is
>> only needed for debugging. It is not generated when compiling without
>> option -g.
>>
> 
> Without '-g', does gcc 8.1 build?

Yes, if I remove the lines setting -g in /Makefile I have no build problem.

> 
>> Compilation on x86 works fine with gcc 7.3.
>> gcc 7.3 simply does not generate the line at all.
>>
> 
> Does gcc 8.1 on Debin Buster come with multilib support? I vaguely
> remember old version did not which would cause build error.
> 

There is also a gcc-multilib package with version 8.1 in Debian Buster.

Best regards

Heinrich

>> To generate the complete assembler code use gcc with options
>> -S -fverbose-asm.
>>
> 
> Regards,
> Bin
> 

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


[U-Boot] [PATCH 1/1] efi_loader: document runtime functions

2018-07-29 Thread Heinrich Schuchardt
Add comments for runtime service functions.

Signed-off-by: Heinrich Schuchardt 
---
 lib/efi_loader/efi_runtime.c | 153 ++-
 1 file changed, 149 insertions(+), 4 deletions(-)

diff --git a/lib/efi_loader/efi_runtime.c b/lib/efi_loader/efi_runtime.c
index 351db8d8ed5..96f652450d0 100644
--- a/lib/efi_loader/efi_runtime.c
+++ b/lib/efi_loader/efi_runtime.c
@@ -96,6 +96,20 @@ void __efi_runtime efi_update_table_header_crc32(struct 
efi_table_hdr *table)
 table->headersize);
 }
 
+/**
+ * efi_reset_system_boottime() - reset system at boottime
+ *
+ * This function implements the ResetSystem() runtime service before
+ * SetVirtualAddressMap() is called.
+ *
+ * See the Unified Extensible Firmware Interface (UEFI) specification for
+ * details.
+ *
+ * @reset_type:type of reset to perform
+ * @reset_status:  status code for the reset
+ * @data_size: size of reset_data
+ * @reset_data:information about the reset
+ */
 static void EFIAPI efi_reset_system_boottime(
enum efi_reset_type reset_type,
efi_status_t reset_status,
@@ -130,15 +144,17 @@ static void EFIAPI efi_reset_system_boottime(
 }
 
 /**
- * efi_get_time_boottime - get current time
+ * efi_get_time_boottime() - get current time at boottime
+ *
+ * This function implements the GetTime runtime service before
+ * SetVirtualAddressMap() is called.
  *
- * This function implements the GetTime runtime service.
  * See the Unified Extensible Firmware Interface (UEFI) specification
  * for details.
  *
  * @time:  pointer to structure to receive current time
  * @capabilities:  pointer to structure to receive RTC properties
- * Return Value:   status code
+ * Returns:status code
  */
 static efi_status_t EFIAPI efi_get_time_boottime(
struct efi_time *time,
@@ -191,8 +207,22 @@ out:
 #endif
 }
 
-/* Boards may override the helpers below to implement RTS functionality */
 
+/**
+ * efi_reset_system() - reset system
+ *
+ * This function implements the ResetSystem() runtime service after
+ * SetVirtualAddressMap() is called. It only executes an endless loop.
+ * Boards may override the helpers below to implement reset functionality.
+ *
+ * See the Unified Extensible Firmware Interface (UEFI) specification for
+ * details.
+ *
+ * @reset_type:type of reset to perform
+ * @reset_status:  status code for the reset
+ * @data_size: size of reset_data
+ * @reset_data:information about the reset
+ */
 void __weak __efi_runtime EFIAPI efi_reset_system(
enum efi_reset_type reset_type,
efi_status_t reset_status,
@@ -202,11 +232,30 @@ void __weak __efi_runtime EFIAPI efi_reset_system(
while (1) { }
 }
 
+/**
+ * efi_reset_system_init() - initialize the reset driver
+ *
+ * Boards may override this function to initialize the reset driver.
+ */
 efi_status_t __weak efi_reset_system_init(void)
 {
return EFI_SUCCESS;
 }
 
+/**
+ * efi_get_time() - get current time
+ *
+ * This function implements the GetTime runtime service after
+ * SetVirtualAddressMap() is called. As the U-Boot driver are not available
+ * anymore only an error code is returned.
+ *
+ * See the Unified Extensible Firmware Interface (UEFI) specification
+ * for details.
+ *
+ * @time:  pointer to structure to receive current time
+ * @capabilities:  pointer to structure to receive RTC properties
+ * Returns:status code
+ */
 efi_status_t __weak __efi_runtime EFIAPI efi_get_time(
struct efi_time *time,
struct efi_time_cap *capabilities)
@@ -353,6 +402,20 @@ void efi_runtime_relocate(ulong offset, struct 
efi_mem_desc *map)
 invalidate_icache_all();
 }
 
+/**
+ * efi_set_virtual_address_map() - change from physical to virtual mapping
+ *
+ * This function implements the SetVirtualAddressMap() runtime service.
+ *
+ * See the Unified Extensible Firmware Interface (UEFI) specification for
+ * details.
+ *
+ * @memory_map_size:   size of the virtual map
+ * @descriptor_size:   size of an entry in the map
+ * @descriptor_version:version of the map entries
+ * @virtmap:   virtual address mapping information
+ * Return: status code
+ */
 static efi_status_t EFIAPI efi_set_virtual_address_map(
unsigned long memory_map_size,
unsigned long descriptor_size,
@@ -412,6 +475,16 @@ static efi_status_t EFIAPI efi_set_virtual_address_map(
return EFI_EXIT(EFI_INVALID_PARAMETER);
 }
 
+/**
+ * efi_add_runtime_mmio() - add memory-mapped IO region
+ *
+ * This function adds a memory-mapped IO region to the memory map to make it
+ * available at runtime.
+ *
+ * @mmio_ptr:  address of the memory-mapped IO region
+ * @len:   size of them

Re: [U-Boot] [linux-sunxi] [PATCH v2 00/13] Allwinner H6 support (w/ SPL)

2018-07-29 Thread Icenowy Zheng
在 2018-07-27五的 18:48 +0530,Jagan Teki写道:
> On Thu, Jul 26, 2018 at 12:35 PM, Icenowy Zheng 
> wrote:
> > 
> > 
> > 于 2018年7月26日 GMT+08:00 下午3:02:50, Jagan Teki <
> > ja...@amarulasolutions.com> 写到:
> > > On Sat, Jul 21, 2018 at 1:50 PM, Icenowy Zheng 
> > > wrote:
> > > > This patchset trys to add support for Allwinner H6 SoC to U-
> > > > Boot.
> > > > 
> > > > Allwinner H6 is a quite new Allwinner SoC, with several parts
> > > > changed
> > > 
> > > a
> > > > lot (memory map, DRAM controller, CCU, so on). The position
> > > > which SPL
> > > > will be loaded (SRAM A1) also changed to 0x2.
> > > > 
> > > > The Pine H64 board support comes with this patchset, as this is
> > > > the
> > > > first H6 board that I can get (being early bird).
> > > > 
> > > > Icenowy Zheng (13):
> > > >   sunxi: change SUNXI_HIGH_SRAM option to SUNXI_SRAM_ADDRESS
> > > >   sunxi: add basic memory map definitions of H6 SoC
> > > >   sunxi: change RMR64's RVBAR address for H6
> > > >   sunxi: change ATF position for H6
> > > >   sunxi: add config for SPL at 0x2 on H6
> > > >   sunxi: change GIC address on H6
> > > >   sunxi: add clock code for H6
> > > >   sunxi: use sun6i-style watchdog for H6
> > > >   sunxi: add UART0 setup for H6
> > > >   sunxi: add MMC support for H6
> > > >   sunxi: add DRAM support to H6
> > > >   sunxi: add support for Allwinner H6 SoC
> > > >   sunxi: add support for Pine H64 board
> 
> Reviewed-by: Jagan Teki 

Do you consider merge it now?

> 
> > > 
> > > Observing SPL hang during relocation switch to board_init_r with
> > > orangepi board[1], will pine boot? look like both seem similar
> > > LPDDR3
> > > configs atleast from schematics.
> > 
> > Use v2.1 DRAM patch.
> 
> Thanks.
> 
> Tested-by: Jagan Teki 
> 

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


[U-Boot] [PATCH v2 00/21] dm: pci: Various fixes and test cases update

2018-07-29 Thread Bin Meng
This fixes several bugs in dm pci driver, as well as updating test
cases running on Sandbox to test dm pci.

It turns out adding test cases for v1 (3 commits) reveals more design
limitations/bugs of sandbox pci driver. Now the v2 series contains 20+
patches!

This series is available for testing at u-boot-x86/pci branch.

Changes in v2:
- Mask header_type with 0x7f

Bin Meng (21):
  pci: Remove 440ep specific macros
  dm: Correct typos in uclass_first/next_device_check()
  dm: core: Add ofnode function to read PCI vendor and device id
  dm: pci: Extract vendor/device id in child_post_bind()
  dm: pci: Fix scanning multi-function device
  test: dm: pci: Remove unnecessary steps in dm_test_pci_swapcase()
  test: dm: pci: Test more than one device on the same bus
  pci: sandbox: swap_case: Preserve space indicator bit in BAR registers
  test: dm: pci: Test more than one PCI host controller
  test: dm: pci: Add tests for configuration space access
  pci: sandbox: emul: Fix the call to pci_bus_find_devfn()
  dm: pci: Assign correct driver data when binding a driver
  pci: sandbox: Support dynamically binding device driver
  pci: sandbox: swap_case: Declare dynamic driver matching
  sandbox: Update test.dts for dynamic PCI device driver matching
  test: dm: pci: Test driver binding with driver data provided
  pci: sandbox: emul: Rename priv structure
  test: dm: pci: Add tests for mixed static and dynamic devices on the
same bus
  pci: Add all known capability and extended capability ids
  dm: pci: Add APIs to find capability and extended capability
  test: dm: pci: Add cases for finding PCI capability APIs

 arch/sandbox/dts/test.dts   |  41 +-
 arch/sandbox/include/asm/test.h |  12 +++
 doc/driver-model/pci-info.txt   |  23 ++
 drivers/core/ofnode.c   |  36 +
 drivers/misc/swap_case.c|  36 -
 drivers/pci/pci-emul-uclass.c   |  24 +++---
 drivers/pci/pci-uclass.c|  83 ++--
 drivers/pci/pci_sandbox.c   |  78 --
 include/dm/ofnode.h |  13 +++
 include/dm/uclass.h |   4 +-
 include/pci.h   |  84 
 test/dm/pci.c   | 170 ++--
 12 files changed, 551 insertions(+), 53 deletions(-)

-- 
2.7.4

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


[U-Boot] [PATCH v2 02/21] dm: Correct typos in uclass_first/next_device_check()

2018-07-29 Thread Bin Meng
Correct typos in the comment block of uclass_first/next_device_check().

Signed-off-by: Bin Meng 
---

Changes in v2: None

 include/dm/uclass.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/dm/uclass.h b/include/dm/uclass.h
index 9fbaa7d..0e882ce 100644
--- a/include/dm/uclass.h
+++ b/include/dm/uclass.h
@@ -302,7 +302,7 @@ int uclass_first_device_err(enum uclass_id id, struct 
udevice **devp);
 int uclass_next_device(struct udevice **devp);
 
 /**
- * uclass_first_device() - Get the first device in a uclass
+ * uclass_first_device_check() - Get the first device in a uclass
  *
  * The device returned is probed if necessary, and ready for use
  *
@@ -318,7 +318,7 @@ int uclass_next_device(struct udevice **devp);
 int uclass_first_device_check(enum uclass_id id, struct udevice **devp);
 
 /**
- * uclass_next_device() - Get the next device in a uclass
+ * uclass_next_device_check() - Get the next device in a uclass
  *
  * The device returned is probed if necessary, and ready for use
  *
-- 
2.7.4

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


[U-Boot] [PATCH v2 01/21] pci: Remove 440ep specific macros

2018-07-29 Thread Bin Meng
These macros should not be put in the generic pci.h header file.
Since they are not referenced anywhere, remove them completely.

Signed-off-by: Bin Meng 
---

Changes in v2: None

 include/pci.h | 15 ---
 1 file changed, 15 deletions(-)

diff --git a/include/pci.h b/include/pci.h
index 8e27cbf..427094c 100644
--- a/include/pci.h
+++ b/include/pci.h
@@ -271,21 +271,6 @@
 #define  PCI_BRIDGE_CTL_BUS_RESET 0x40 /* Secondary bus reset */
 #define  PCI_BRIDGE_CTL_FAST_BACK 0x80 /* Fast Back2Back enabled on secondary 
interface */
 
-/* From 440ep */
-#define PCI_ERREN   0x48 /* Error Enable */
-#define PCI_ERRSTS  0x49 /* Error Status */
-#define PCI_BRDGOPT10x4A /* PCI Bridge Options 1 */
-#define PCI_PLBSESR00x4C /* PCI PLB Slave Error Syndrome 0 */
-#define PCI_PLBSESR10x50 /* PCI PLB Slave Error Syndrome 1 */
-#define PCI_PLBSEAR 0x54 /* PCI PLB Slave Error Address */
-#define PCI_CAPID   0x58 /* Capability Identifier */
-#define PCI_NEXTITEMPTR 0x59 /* Next Item Pointer */
-#define PCI_PMC 0x5A /* Power Management Capabilities */
-#define PCI_PMCSR   0x5C /* Power Management Control Status */
-#define PCI_PMCSRBSE0x5E /* PMCSR PCI to PCI Bridge Support Extensions 
*/
-#define PCI_BRDGOPT20x60 /* PCI Bridge Options 2 */
-#define PCI_PMSCRR  0x64 /* Power Management State Change Request Re. 
*/
-
 /* Header type 2 (CardBus bridges) */
 #define PCI_CB_CAPABILITY_LIST 0x14
 /* 0x15 reserved */
-- 
2.7.4

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


[U-Boot] [PATCH v2 05/21] dm: pci: Fix scanning multi-function device

2018-07-29 Thread Bin Meng
The flag to control whether to scan multi-function device during
enumeration should be cleared at the beginning of each iteration
if the device's function number equals to zero.

Signed-off-by: Bin Meng 
---

Changes in v2: None

 drivers/pci/pci-uclass.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c
index b2909a3..28ea8c5 100644
--- a/drivers/pci/pci-uclass.c
+++ b/drivers/pci/pci-uclass.c
@@ -745,6 +745,8 @@ int pci_bind_bus_devices(struct udevice *bus)
struct udevice *dev;
ulong class;
 
+   if (!PCI_FUNC(bdf))
+   found_multi = false;
if (PCI_FUNC(bdf) && !found_multi)
continue;
/* Check only the first access, we don't expect problems */
-- 
2.7.4

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


[U-Boot] [PATCH v2 04/21] dm: pci: Extract vendor/device id in child_post_bind()

2018-07-29 Thread Bin Meng
Currently only devfn is extracted in child_post_bind(). Now that
we have the live-tree version API to look up PCI vendor and device
id from the compatible string, let's extract and save them too.

Signed-off-by: Bin Meng 
---

Changes in v2: None

 drivers/pci/pci-uclass.c | 11 +--
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c
index 46e9c71..b2909a3 100644
--- a/drivers/pci/pci-uclass.c
+++ b/drivers/pci/pci-uclass.c
@@ -987,19 +987,18 @@ static int pci_uclass_child_post_bind(struct udevice *dev)
if (!dev_of_valid(dev))
return 0;
 
-   /*
-* We could read vendor, device, class if available. But for now we
-* just check the address.
-*/
pplat = dev_get_parent_platdata(dev);
+
+   /* Extract vendor id and device id if available */
+   ofnode_read_pci_vendev(dev_ofnode(dev), &pplat->vendor, &pplat->device);
+
+   /* Extract the devfn from fdt_pci_addr */
ret = ofnode_read_pci_addr(dev_ofnode(dev), FDT_PCI_SPACE_CONFIG, "reg",
   &addr);
-
if (ret) {
if (ret != -ENOENT)
return -EINVAL;
} else {
-   /* extract the devfn from fdt_pci_addr */
pplat->devfn = addr.phys_hi & 0xff00;
}
 
-- 
2.7.4

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


[U-Boot] [PATCH v2 03/21] dm: core: Add ofnode function to read PCI vendor and device id

2018-07-29 Thread Bin Meng
We don't have the live-tree version of fdtdec_get_pci_vendev().
This adds the API.

Signed-off-by: Bin Meng 
---

Changes in v2: None

 drivers/core/ofnode.c | 36 
 include/dm/ofnode.h   | 13 +
 2 files changed, 49 insertions(+)

diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c
index 2937539..0cfb0fb 100644
--- a/drivers/core/ofnode.c
+++ b/drivers/core/ofnode.c
@@ -623,6 +623,42 @@ fail:
return ret;
 }
 
+int ofnode_read_pci_vendev(ofnode node, u16 *vendor, u16 *device)
+{
+   const char *list, *end;
+   int len;
+
+   list = ofnode_get_property(node, "compatible", &len);
+   if (!list)
+   return -ENOENT;
+
+   end = list + len;
+   while (list < end) {
+   len = strlen(list);
+   if (len >= strlen("pci,")) {
+   char *s = strstr(list, "pci");
+
+   /*
+* check if the string is something like pci,.RR
+* or just pci,
+*/
+   if (s && s[7] == ',' &&
+   (s[12] == '.' || s[12] == 0)) {
+   s += 3;
+   *vendor = simple_strtol(s, NULL, 16);
+
+   s += 5;
+   *device = simple_strtol(s, NULL, 16);
+
+   return 0;
+   }
+   }
+   list += (len + 1);
+   }
+
+   return -ENOENT;
+}
+
 int ofnode_read_addr_cells(ofnode node)
 {
if (ofnode_is_np(node))
diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h
index cd08a7e..ab36b74 100644
--- a/include/dm/ofnode.h
+++ b/include/dm/ofnode.h
@@ -586,6 +586,19 @@ int ofnode_read_pci_addr(ofnode node, enum fdt_pci_space 
type,
 const char *propname, struct fdt_pci_addr *addr);
 
 /**
+ * ofnode_read_pci_vendev() - look up PCI vendor and device id
+ *
+ * Look at the compatible property of a device node that represents a PCI
+ * device and extract pci vendor id and device id from it.
+ *
+ * @param node node to examine
+ * @param vendor   vendor id of the pci device
+ * @param device   device id of the pci device
+ * @return 0 if ok, negative on error
+ */
+int ofnode_read_pci_vendev(ofnode node, u16 *vendor, u16 *device);
+
+/**
  * ofnode_read_addr_cells() - Get the number of address cells for a node
  *
  * This walks back up the tree to find the closest #address-cells property
-- 
2.7.4

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


[U-Boot] [PATCH v2 06/21] test: dm: pci: Remove unnecessary steps in dm_test_pci_swapcase()

2018-07-29 Thread Bin Meng
The check on uclass_get_device() and device_active() is unnecessary
as the follow-up test operations will implicitly probe the driver.

Signed-off-by: Bin Meng 
---

Changes in v2: None

 test/dm/pci.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/test/dm/pci.c b/test/dm/pci.c
index 47b5d22..be1208c 100644
--- a/test/dm/pci.c
+++ b/test/dm/pci.c
@@ -34,14 +34,12 @@ DM_TEST(dm_test_pci_busnum, DM_TESTF_SCAN_PDATA | 
DM_TESTF_SCAN_FDT);
 /* Test that we can use the swapcase device correctly */
 static int dm_test_pci_swapcase(struct unit_test_state *uts)
 {
-   struct udevice *emul, *swap;
+   struct udevice *swap;
ulong io_addr, mem_addr;
char *ptr;
 
/* Check that asking for the device automatically fires up PCI */
-   ut_assertok(uclass_get_device(UCLASS_PCI_EMUL, 0, &emul));
ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(0, 0x1f, 0), &swap));
-   ut_assert(device_active(swap));
 
/* First test I/O */
io_addr = dm_pci_read_bar32(swap, 0);
-- 
2.7.4

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


[U-Boot] [PATCH v2 10/21] test: dm: pci: Add tests for configuration space access

2018-07-29 Thread Bin Meng
So far we missed the testing for PCI configuration space access.

Signed-off-by: Bin Meng 
---

Changes in v2: None

 test/dm/pci.c | 24 +++-
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/test/dm/pci.c b/test/dm/pci.c
index 727ec34..089b72e 100644
--- a/test/dm/pci.c
+++ b/test/dm/pci.c
@@ -6,6 +6,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -24,27 +25,32 @@ DM_TEST(dm_test_pci_base, DM_TESTF_SCAN_PDATA | 
DM_TESTF_SCAN_FDT);
 static int dm_test_pci_busdev(struct unit_test_state *uts)
 {
struct udevice *bus;
-   struct udevice *emul, *swap;
+   struct udevice *swap;
+   u16 vendor, device;
 
/* Test bus#0 and its devices */
ut_assertok(uclass_get_device_by_seq(UCLASS_PCI, 0, &bus));
 
-   ut_assertok(uclass_get_device(UCLASS_PCI_EMUL, 0, &emul));
ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(0, 0x00, 0), &swap));
-   ut_assert(device_active(swap));
-   ut_assertok(uclass_get_device(UCLASS_PCI_EMUL, 1, &emul));
+   vendor = 0;
+   ut_assertok(dm_pci_read_config16(swap, PCI_VENDOR_ID, &vendor));
+   ut_asserteq(SANDBOX_PCI_VENDOR_ID, vendor);
ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(0, 0x1f, 0), &swap));
-   ut_assert(device_active(swap));
+   device = 0;
+   ut_assertok(dm_pci_read_config16(swap, PCI_DEVICE_ID, &device));
+   ut_asserteq(SANDBOX_PCI_DEVICE_ID, device);
 
/* Test bus#1 and its devices */
ut_assertok(uclass_get_device_by_seq(UCLASS_PCI, 1, &bus));
 
-   ut_assertok(uclass_get_device(UCLASS_PCI_EMUL, 2, &emul));
ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(1, 0x08, 0), &swap));
-   ut_assert(device_active(swap));
-   ut_assertok(uclass_get_device(UCLASS_PCI_EMUL, 3, &emul));
+   vendor = 0;
+   ut_assertok(dm_pci_read_config16(swap, PCI_VENDOR_ID, &vendor));
+   ut_asserteq(SANDBOX_PCI_VENDOR_ID, vendor);
ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(1, 0x0c, 0), &swap));
-   ut_assert(device_active(swap));
+   device = 0;
+   ut_assertok(dm_pci_read_config16(swap, PCI_DEVICE_ID, &device));
+   ut_asserteq(SANDBOX_PCI_DEVICE_ID, device);
 
return 0;
 }
-- 
2.7.4

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


[U-Boot] [PATCH v2 09/21] test: dm: pci: Test more than one PCI host controller

2018-07-29 Thread Bin Meng
So far there is only one PCI host controller in the sandbox test
configuration. This is normally the case for x86, but it can be
common on other architectures like ARM/PPC to have more than one
PCI host controller in the system.

This updates the case to cover such scenario.

Signed-off-by: Bin Meng 
---

Changes in v2: None

 arch/sandbox/dts/test.dts | 28 ++--
 test/dm/pci.c | 11 +++
 2 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index 237266d..0bce6d0 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -14,7 +14,8 @@
i2c0 = "/i2c@0";
mmc0 = "/mmc0";
mmc1 = "/mmc1";
-   pci0 = &pci;
+   pci0 = &pci0;
+   pci1 = &pci1;
remoteproc1 = &rproc_1;
remoteproc2 = &rproc_2;
rtc0 = &rtc_0;
@@ -295,7 +296,7 @@
compatible = "sandbox,mmc";
};
 
-   pci: pci-controller {
+   pci0: pci-controller0 {
compatible = "sandbox,pci";
device_type = "pci";
#address-cells = <3>;
@@ -318,6 +319,29 @@
};
};
 
+   pci1: pci-controller1 {
+   compatible = "sandbox,pci";
+   device_type = "pci";
+   #address-cells = <3>;
+   #size-cells = <2>;
+   ranges = <0x0200 0 0x3000 0x3000 0 0x2000
+   0x0100 0 0x4000 0x4000 0 0x2000>;
+   pci@8,0 {
+   compatible = "pci-generic";
+   reg = <0x4000 0 0 0 0>;
+   emul@8,0 {
+   compatible = "sandbox,swap-case";
+   };
+   };
+   pci@c,0 {
+   compatible = "pci-generic";
+   reg = <0x6000 0 0 0 0>;
+   emul@c,0 {
+   compatible = "sandbox,swap-case";
+   };
+   };
+   };
+
probing {
compatible = "simple-bus";
test1 {
diff --git a/test/dm/pci.c b/test/dm/pci.c
index f2bd52a..727ec34 100644
--- a/test/dm/pci.c
+++ b/test/dm/pci.c
@@ -26,6 +26,7 @@ static int dm_test_pci_busdev(struct unit_test_state *uts)
struct udevice *bus;
struct udevice *emul, *swap;
 
+   /* Test bus#0 and its devices */
ut_assertok(uclass_get_device_by_seq(UCLASS_PCI, 0, &bus));
 
ut_assertok(uclass_get_device(UCLASS_PCI_EMUL, 0, &emul));
@@ -35,6 +36,16 @@ static int dm_test_pci_busdev(struct unit_test_state *uts)
ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(0, 0x1f, 0), &swap));
ut_assert(device_active(swap));
 
+   /* Test bus#1 and its devices */
+   ut_assertok(uclass_get_device_by_seq(UCLASS_PCI, 1, &bus));
+
+   ut_assertok(uclass_get_device(UCLASS_PCI_EMUL, 2, &emul));
+   ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(1, 0x08, 0), &swap));
+   ut_assert(device_active(swap));
+   ut_assertok(uclass_get_device(UCLASS_PCI_EMUL, 3, &emul));
+   ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(1, 0x0c, 0), &swap));
+   ut_assert(device_active(swap));
+
return 0;
 }
 DM_TEST(dm_test_pci_busdev, 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 v2 07/21] test: dm: pci: Test more than one device on the same bus

2018-07-29 Thread Bin Meng
It's quite common to have more than one device on the same PCI bus.
This updates the test case to test such scenario.

Signed-off-by: Bin Meng 
---

Changes in v2: None

 arch/sandbox/dts/test.dts |  7 +++
 test/dm/pci.c | 37 +
 2 files changed, 40 insertions(+), 4 deletions(-)

diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index 137679a..237266d 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -302,6 +302,13 @@
#size-cells = <2>;
ranges = <0x0200 0 0x1000 0x1000 0 0x2000
0x0100 0 0x2000 0x2000 0 0x2000>;
+   pci@0,0 {
+   compatible = "pci-generic";
+   reg = <0x 0 0 0 0>;
+   emul@0,0 {
+   compatible = "sandbox,swap-case";
+   };
+   };
pci@1f,0 {
compatible = "pci-generic";
reg = <0xf800 0 0 0 0>;
diff --git a/test/dm/pci.c b/test/dm/pci.c
index be1208c..f2bd52a 100644
--- a/test/dm/pci.c
+++ b/test/dm/pci.c
@@ -20,16 +20,24 @@ static int dm_test_pci_base(struct unit_test_state *uts)
 }
 DM_TEST(dm_test_pci_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
 
-/* Test that sandbox PCI bus numbering works correctly */
-static int dm_test_pci_busnum(struct unit_test_state *uts)
+/* Test that sandbox PCI bus numbering and device works correctly */
+static int dm_test_pci_busdev(struct unit_test_state *uts)
 {
struct udevice *bus;
+   struct udevice *emul, *swap;
 
ut_assertok(uclass_get_device_by_seq(UCLASS_PCI, 0, &bus));
 
+   ut_assertok(uclass_get_device(UCLASS_PCI_EMUL, 0, &emul));
+   ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(0, 0x00, 0), &swap));
+   ut_assert(device_active(swap));
+   ut_assertok(uclass_get_device(UCLASS_PCI_EMUL, 1, &emul));
+   ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(0, 0x1f, 0), &swap));
+   ut_assert(device_active(swap));
+
return 0;
 }
-DM_TEST(dm_test_pci_busnum, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+DM_TEST(dm_test_pci_busdev, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
 
 /* Test that we can use the swapcase device correctly */
 static int dm_test_pci_swapcase(struct unit_test_state *uts)
@@ -38,7 +46,28 @@ static int dm_test_pci_swapcase(struct unit_test_state *uts)
ulong io_addr, mem_addr;
char *ptr;
 
-   /* Check that asking for the device automatically fires up PCI */
+   /* Check that asking for the device 0 automatically fires up PCI */
+   ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(0, 0x00, 0), &swap));
+
+   /* First test I/O */
+   io_addr = dm_pci_read_bar32(swap, 0);
+   outb(2, io_addr);
+   ut_asserteq(2, inb(io_addr));
+
+   /*
+* Now test memory mapping - note we must unmap and remap to cause
+* the swapcase emulation to see our data and response.
+*/
+   mem_addr = dm_pci_read_bar32(swap, 1);
+   ptr = map_sysmem(mem_addr, 20);
+   strcpy(ptr, "This is a TesT");
+   unmap_sysmem(ptr);
+
+   ptr = map_sysmem(mem_addr, 20);
+   ut_asserteq_str("tHIS IS A tESt", ptr);
+   unmap_sysmem(ptr);
+
+   /* Check that asking for the device 1 automatically fires up PCI */
ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(0, 0x1f, 0), &swap));
 
/* First test I/O */
-- 
2.7.4

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


[U-Boot] [PATCH v2 19/21] pci: Add all known capability and extended capability ids

2018-07-29 Thread Bin Meng
Currently we don't have a complete list of capability and extended
capability ids. This adds them.

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

Changes in v2: None

 include/pci.h | 20 +++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/include/pci.h b/include/pci.h
index c0ae5d1..83a40a5 100644
--- a/include/pci.h
+++ b/include/pci.h
@@ -318,7 +318,21 @@
 #define  PCI_CAP_ID_SLOTID 0x04/* Slot Identification */
 #define  PCI_CAP_ID_MSI0x05/* Message Signalled Interrupts 
*/
 #define  PCI_CAP_ID_CHSWP  0x06/* CompactPCI HotSwap */
-#define  PCI_CAP_ID_EXP0x10/* PCI Express */
+#define  PCI_CAP_ID_PCIX   0x07/* PCI-X */
+#define  PCI_CAP_ID_HT 0x08/* HyperTransport */
+#define  PCI_CAP_ID_VNDR   0x09/* Vendor-Specific */
+#define  PCI_CAP_ID_DBG0x0A/* Debug port */
+#define  PCI_CAP_ID_CCRC   0x0B/* CompactPCI Central Resource Control 
*/
+#define  PCI_CAP_ID_SHPC   0x0C/* PCI Standard Hot-Plug Controller */
+#define  PCI_CAP_ID_SSVID  0x0D/* Bridge subsystem vendor/device ID */
+#define  PCI_CAP_ID_AGP3   0x0E/* AGP Target PCI-PCI bridge */
+#define  PCI_CAP_ID_SECDEV 0x0F/* Secure Device */
+#define  PCI_CAP_ID_EXP0x10/* PCI Express */
+#define  PCI_CAP_ID_MSIX   0x11/* MSI-X */
+#define  PCI_CAP_ID_SATA   0x12/* SATA Data/Index Conf. */
+#define  PCI_CAP_ID_AF 0x13/* PCI Advanced Features */
+#define  PCI_CAP_ID_EA 0x14/* PCI Enhanced Allocation */
+#define  PCI_CAP_ID_MAXPCI_CAP_ID_EA
 #define PCI_CAP_LIST_NEXT  1   /* Next capability in the list */
 #define PCI_CAP_FLAGS  2   /* Capability defined flags (16 bits) */
 #define PCI_CAP_SIZEOF 4
@@ -434,6 +448,10 @@
 #define PCI_EXT_CAP_ID_SECPCI  0x19/* Secondary PCIe Capability */
 #define PCI_EXT_CAP_ID_PMUX0x1A/* Protocol Multiplexing */
 #define PCI_EXT_CAP_ID_PASID   0x1B/* Process Address Space ID */
+#define PCI_EXT_CAP_ID_DPC 0x1D/* Downstream Port Containment */
+#define PCI_EXT_CAP_ID_L1SS0x1E/* L1 PM Substates */
+#define PCI_EXT_CAP_ID_PTM 0x1F/* Precision Time Measurement */
+#define PCI_EXT_CAP_ID_MAX PCI_EXT_CAP_ID_PTM
 
 /* Include the ID list */
 
-- 
2.7.4

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


[U-Boot] [PATCH v2 08/21] pci: sandbox: swap_case: Preserve space indicator bit in BAR registers

2018-07-29 Thread Bin Meng
With the newly added testing of more than one device, we get:

  => ut dm pci_swapcase
  Test: dm_test_pci_swapcase: pci.c
  test/dm/pci.c:88, dm_test_pci_swapcase(): "tHIS IS A tESt" = ptr:
  Expected "tHIS IS A tESt", got "this is a test"
  Test: dm_test_pci_swapcase: pci.c (flat tree)
  test/dm/pci.c:88, dm_test_pci_swapcase(): "tHIS IS A tESt" = ptr:
  Expected "tHIS IS A tESt", got "this is a test"
  Failures: 2

The failure only happens on the 2nd swap_case device on the PCI bus.
The case passes on the 1st device.

It turns out the swap_case driver does not emulate bit#0 in BAR
registers as a read-only bit. This corrects the implementation.

Signed-off-by: Bin Meng 
---

Changes in v2: None

 drivers/misc/swap_case.c | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/misc/swap_case.c b/drivers/misc/swap_case.c
index b777404..80ccb9f 100644
--- a/drivers/misc/swap_case.c
+++ b/drivers/misc/swap_case.c
@@ -142,6 +142,8 @@ static int sandbox_swap_case_write_config(struct udevice 
*emul, uint offset,
 
debug("w bar %d=%lx\n", barnum, value);
*bar = value;
+   /* space indicator (bit#0) is read-only */
+   *bar |= barinfo[barnum].type;
break;
}
}
@@ -157,11 +159,11 @@ static int sandbox_swap_case_find_bar(struct udevice 
*emul, unsigned int addr,
 
for (barnum = 0; barnum < ARRAY_SIZE(barinfo); barnum++) {
unsigned int size = barinfo[barnum].size;
+   u32 base = plat->bar[barnum] & ~PCI_BASE_ADDRESS_SPACE;
 
-   if (addr >= plat->bar[barnum] &&
-   addr < plat->bar[barnum] + size) {
+   if (addr >= base && addr < base + size) {
*barnump = barnum;
-   *offsetp = addr - plat->bar[barnum];
+   *offsetp = addr - base;
return 0;
}
}
-- 
2.7.4

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


[U-Boot] [PATCH v2 12/21] dm: pci: Assign correct driver data when binding a driver

2018-07-29 Thread Bin Meng
The correct driver data comes from the matching 'id' instead of
'find_id' in pci_find_and_bind_driver().

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

Changes in v2: None

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

diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c
index 28ea8c5..5eb6841 100644
--- a/drivers/pci/pci-uclass.c
+++ b/drivers/pci/pci-uclass.c
@@ -690,7 +690,7 @@ static int pci_find_and_bind_driver(struct udevice *parent,
if (ret)
goto error;
debug("%s: Match found: %s\n", __func__, drv->name);
-   dev->driver_data = find_id->driver_data;
+   dev->driver_data = id->driver_data;
*devp = 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 v2 18/21] test: dm: pci: Add tests for mixed static and dynamic devices on the same bus

2018-07-29 Thread Bin Meng
In the Sandbox test configuration, PCI bus#0 only has static devices
while bus#1 only has dynamic devices. Create a bus#2 that has both
types of devices and test such.

Signed-off-by: Bin Meng 
---

Changes in v2: None

 arch/sandbox/dts/test.dts | 18 ++
 test/dm/pci.c | 63 +++
 2 files changed, 81 insertions(+)

diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index 44d24f9..7035646 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -16,6 +16,7 @@
mmc1 = "/mmc1";
pci0 = &pci0;
pci1 = &pci1;
+   pci2 = &pci2;
remoteproc1 = &rproc_1;
remoteproc2 = &rproc_2;
rtc0 = &rtc_0;
@@ -330,6 +331,23 @@
0x0c 0x00 0x1234 0x5678>;
};
 
+   pci2: pci-controller2 {
+   compatible = "sandbox,pci";
+   device_type = "pci";
+   #address-cells = <3>;
+   #size-cells = <2>;
+   ranges = <0x0200 0 0x5000 0x5000 0 0x2000
+   0x0100 0 0x6000 0x6000 0 0x2000>;
+   sandbox,dev-info = <0x08 0x00 0x1234 0x5678>;
+   pci@1f,0 {
+   compatible = "pci-generic";
+   reg = <0xf800 0 0 0 0>;
+   emul@1f,0 {
+   compatible = "sandbox,swap-case";
+   };
+   };
+   };
+
probing {
compatible = "simple-bus";
test1 {
diff --git a/test/dm/pci.c b/test/dm/pci.c
index 53d2ca1..e03f6ba 100644
--- a/test/dm/pci.c
+++ b/test/dm/pci.c
@@ -125,3 +125,66 @@ static int dm_test_pci_drvdata(struct unit_test_state *uts)
return 0;
 }
 DM_TEST(dm_test_pci_drvdata, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+/* Test that devices on PCI bus#2 can be accessed correctly */
+static int dm_test_pci_mixed(struct unit_test_state *uts)
+{
+   /* PCI bus#2 has both statically and dynamic declared devices */
+   struct udevice *bus, *swap;
+   u16 vendor, device;
+   ulong io_addr, mem_addr;
+   char *ptr;
+
+   ut_assertok(uclass_get_device_by_seq(UCLASS_PCI, 2, &bus));
+
+   /* Test the dynamic device */
+   ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(2, 0x08, 0), &swap));
+   vendor = 0;
+   ut_assertok(dm_pci_read_config16(swap, PCI_VENDOR_ID, &vendor));
+   ut_asserteq(SANDBOX_PCI_VENDOR_ID, vendor);
+
+   /* First test I/O */
+   io_addr = dm_pci_read_bar32(swap, 0);
+   outb(2, io_addr);
+   ut_asserteq(2, inb(io_addr));
+
+   /*
+* Now test memory mapping - note we must unmap and remap to cause
+* the swapcase emulation to see our data and response.
+*/
+   mem_addr = dm_pci_read_bar32(swap, 1);
+   ptr = map_sysmem(mem_addr, 30);
+   strcpy(ptr, "This is a TesT oN dYNAMIc");
+   unmap_sysmem(ptr);
+
+   ptr = map_sysmem(mem_addr, 30);
+   ut_asserteq_str("tHIS IS A tESt On DynamiC", ptr);
+   unmap_sysmem(ptr);
+
+   /* Test the static device */
+   ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(2, 0x1f, 0), &swap));
+   device = 0;
+   ut_assertok(dm_pci_read_config16(swap, PCI_DEVICE_ID, &device));
+   ut_asserteq(SANDBOX_PCI_DEVICE_ID, device);
+
+   /* First test I/O */
+   io_addr = dm_pci_read_bar32(swap, 0);
+   outb(2, io_addr);
+   ut_asserteq(2, inb(io_addr));
+
+   /*
+* Now test memory mapping - note we must unmap and remap to cause
+* the swapcase emulation to see our data and response.
+*/
+   mem_addr = dm_pci_read_bar32(swap, 1);
+   ptr = map_sysmem(mem_addr, 30);
+   strcpy(ptr, "This is a TesT oN sTATIc");
+   unmap_sysmem(ptr);
+
+   ptr = map_sysmem(mem_addr, 30);
+   ut_asserteq_str("tHIS IS A tESt On StatiC", ptr);
+   unmap_sysmem(ptr);
+
+   return 0;
+}
+DM_TEST(dm_test_pci_mixed, 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 v2 16/21] test: dm: pci: Test driver binding with driver data provided

2018-07-29 Thread Bin Meng
With struct pci_device_id, it's possible to pass a driver data for
bound driver to use. This adds a test case for this functionality.

Signed-off-by: Bin Meng 
---

Changes in v2: None

 test/dm/pci.c | 17 +
 1 file changed, 17 insertions(+)

diff --git a/test/dm/pci.c b/test/dm/pci.c
index 089b72e..53d2ca1 100644
--- a/test/dm/pci.c
+++ b/test/dm/pci.c
@@ -108,3 +108,20 @@ static int dm_test_pci_swapcase(struct unit_test_state 
*uts)
return 0;
 }
 DM_TEST(dm_test_pci_swapcase, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+/* Test that we can dynamically bind the device driver correctly */
+static int dm_test_pci_drvdata(struct unit_test_state *uts)
+{
+   struct udevice *bus, *swap;
+
+   /* Check that asking for the device automatically fires up PCI */
+   ut_assertok(uclass_get_device_by_seq(UCLASS_PCI, 1, &bus));
+
+   ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(1, 0x08, 0), &swap));
+   ut_asserteq(SWAP_CASE_DRV_DATA, swap->driver_data);
+   ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(1, 0x0c, 0), &swap));
+   ut_asserteq(SWAP_CASE_DRV_DATA, swap->driver_data);
+
+   return 0;
+}
+DM_TEST(dm_test_pci_drvdata, 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 v2 14/21] pci: sandbox: swap_case: Declare dynamic driver matching

2018-07-29 Thread Bin Meng
This adds a U_BOOT_PCI_DEVICE() declaration to the swap_case driver.

Signed-off-by: Bin Meng 
---

Changes in v2: None

 arch/sandbox/include/asm/test.h | 4 
 drivers/misc/swap_case.c| 7 +++
 2 files changed, 11 insertions(+)

diff --git a/arch/sandbox/include/asm/test.h b/arch/sandbox/include/asm/test.h
index 08863bf..57aeca8 100644
--- a/arch/sandbox/include/asm/test.h
+++ b/arch/sandbox/include/asm/test.h
@@ -16,6 +16,10 @@
 #define SANDBOX_PCI_CLASS_CODE PCI_CLASS_CODE_COMM
 #define SANDBOX_PCI_CLASS_SUB_CODE PCI_CLASS_SUB_CODE_COMM_SERIAL
 
+/* Useful for PCI_VDEVICE() macro */
+#define PCI_VENDOR_ID_SANDBOX  SANDBOX_PCI_VENDOR_ID
+#define SWAP_CASE_DRV_DATA 0x55aa
+
 #define SANDBOX_CLK_RATE   32768
 
 /* System controller driver data */
diff --git a/drivers/misc/swap_case.c b/drivers/misc/swap_case.c
index 80ccb9f..790bb0c 100644
--- a/drivers/misc/swap_case.c
+++ b/drivers/misc/swap_case.c
@@ -285,3 +285,10 @@ U_BOOT_DRIVER(sandbox_swap_case_emul) = {
.priv_auto_alloc_size = sizeof(struct swap_case_priv),
.platdata_auto_alloc_size = sizeof(struct swap_case_platdata),
 };
+
+static struct pci_device_id sandbox_swap_case_supported[] = {
+   { PCI_VDEVICE(SANDBOX, SANDBOX_PCI_DEVICE_ID), SWAP_CASE_DRV_DATA },
+   {},
+};
+
+U_BOOT_PCI_DEVICE(sandbox_swap_case_emul, sandbox_swap_case_supported);
-- 
2.7.4

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


[U-Boot] [PATCH v2 15/21] sandbox: Update test.dts for dynamic PCI device driver matching

2018-07-29 Thread Bin Meng
Signed-off-by: Bin Meng 
---

Changes in v2: None

 arch/sandbox/dts/test.dts | 16 ++--
 1 file changed, 2 insertions(+), 14 deletions(-)

diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index 0bce6d0..44d24f9 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -326,20 +326,8 @@
#size-cells = <2>;
ranges = <0x0200 0 0x3000 0x3000 0 0x2000
0x0100 0 0x4000 0x4000 0 0x2000>;
-   pci@8,0 {
-   compatible = "pci-generic";
-   reg = <0x4000 0 0 0 0>;
-   emul@8,0 {
-   compatible = "sandbox,swap-case";
-   };
-   };
-   pci@c,0 {
-   compatible = "pci-generic";
-   reg = <0x6000 0 0 0 0>;
-   emul@c,0 {
-   compatible = "sandbox,swap-case";
-   };
-   };
+   sandbox,dev-info = <0x08 0x00 0x1234 0x5678
+   0x0c 0x00 0x1234 0x5678>;
};
 
probing {
-- 
2.7.4

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


[U-Boot] [PATCH v2 11/21] pci: sandbox: emul: Fix the call to pci_bus_find_devfn()

2018-07-29 Thread Bin Meng
With the newly added test cases for PCI configuration access, we get:

  => ut dm pci_busdev
  Test: dm_test_pci_busdev: pci.c
  test/dm/pci.c:49, dm_test_pci_busdev(): SANDBOX_PCI_VENDOR_ID == vendor:
  Expected 4660, got 65535
  Test: dm_test_pci_busdev: pci.c (flat tree)
  test/dm/pci.c:49, dm_test_pci_busdev(): SANDBOX_PCI_VENDOR_ID == vendor:
  Expected 4660, got 65535
  Failures: 2

The bug only shows up when bus number is not equal to zero. This is
caused by the plain find_devfn parameter is passed to function call
pci_bus_find_devfn(), inside which find_devfn is compared to devfn
in the device's pplat structure. However pplat->devfn does not carry
the bus number. Fix this by passing find_devfn with bus number masked.

Signed-off-by: Bin Meng 
---

Changes in v2: None

 drivers/pci/pci-emul-uclass.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/pci/pci-emul-uclass.c b/drivers/pci/pci-emul-uclass.c
index 79e2c14..8570a5d 100644
--- a/drivers/pci/pci-emul-uclass.c
+++ b/drivers/pci/pci-emul-uclass.c
@@ -21,7 +21,7 @@ int sandbox_pci_get_emul(struct udevice *bus, pci_dev_t 
find_devfn,
struct udevice *dev;
int ret;
 
-   ret = pci_bus_find_devfn(bus, find_devfn, &dev);
+   ret = pci_bus_find_devfn(bus, PCI_MASK_BUS(find_devfn), &dev);
if (ret) {
debug("%s: Could not find emulator for dev %x\n", __func__,
  find_devfn);
-- 
2.7.4

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


[U-Boot] [PATCH v2 13/21] pci: sandbox: Support dynamically binding device driver

2018-07-29 Thread Bin Meng
At present all emulated sandbox pci devices must be present in the
device tree in order to be used. The real world pci uclass driver
supports pci device driver matching, and we should add such support
on sandbox too.

Signed-off-by: Bin Meng 
---

Changes in v2: None

 doc/driver-model/pci-info.txt | 23 +
 drivers/pci/pci-emul-uclass.c | 14 +---
 drivers/pci/pci_sandbox.c | 78 +++
 include/pci.h |  3 +-
 4 files changed, 107 insertions(+), 11 deletions(-)

diff --git a/doc/driver-model/pci-info.txt b/doc/driver-model/pci-info.txt
index 52b4389..e67264b 100644
--- a/doc/driver-model/pci-info.txt
+++ b/doc/driver-model/pci-info.txt
@@ -133,3 +133,26 @@ When this bus is scanned we will end up with something 
like this:
 
 When accesses go to the pci@1f,0 device they are forwarded to its child, the
 emulator.
+
+The sandbox PCI drivers also support dynamic driver binding, allowing device
+driver to declare the driver binding information via U_BOOT_PCI_DEVICE(),
+eliminating the need to provide any device tree node under the host controller
+node. It is required a "sandbox,dev-info" property must be provided in the
+host controller node for this functionality to work.
+
+   pci1: pci-controller1 {
+   compatible = "sandbox,pci";
+   ...
+   sandbox,dev-info = <0x08 0x00 0x1234 0x5678
+   0x0c 0x00 0x1234 0x5678>;
+   };
+
+When this bus is scanned we will end up with something like this:
+
+ pci[ + ]   pci_sandbo  |-- pci-controller1
+ pci_emul   [   ]   sandbox_sw  |   |-- sandbox_swap_case_emul
+ pci_emul   [   ]   sandbox_sw  |   `-- sandbox_swap_case_emul
+
+Note the difference from the statically declared device nodes is that the
+device is directly attached to the host controller, instead of via a container
+device like pci@1f,0.
diff --git a/drivers/pci/pci-emul-uclass.c b/drivers/pci/pci-emul-uclass.c
index 8570a5d..e9d2f49 100644
--- a/drivers/pci/pci-emul-uclass.c
+++ b/drivers/pci/pci-emul-uclass.c
@@ -16,21 +16,27 @@ struct sandbox_pci_priv {
 };
 
 int sandbox_pci_get_emul(struct udevice *bus, pci_dev_t find_devfn,
-struct udevice **emulp)
+struct udevice **containerp, struct udevice **emulp)
 {
struct udevice *dev;
int ret;
 
+   *containerp = NULL;
ret = pci_bus_find_devfn(bus, PCI_MASK_BUS(find_devfn), &dev);
if (ret) {
debug("%s: Could not find emulator for dev %x\n", __func__,
  find_devfn);
return ret;
}
+   *containerp = dev;
 
-   ret = device_find_first_child(dev, emulp);
-   if (ret)
-   return ret;
+   if (device_get_uclass_id(dev) == UCLASS_PCI_GENERIC) {
+   ret = device_find_first_child(dev, emulp);
+   if (ret)
+   return ret;
+   } else {
+   *emulp = dev;
+   }
 
return *emulp ? 0 : -ENODEV;
 }
diff --git a/drivers/pci/pci_sandbox.c b/drivers/pci/pci_sandbox.c
index 67cd733..119a98d 100644
--- a/drivers/pci/pci_sandbox.c
+++ b/drivers/pci/pci_sandbox.c
@@ -10,15 +10,27 @@
 #include 
 #include 
 
+#define FDT_DEV_INFO_CELLS 4
+#define FDT_DEV_INFO_SIZE  (FDT_DEV_INFO_CELLS * sizeof(u32))
+
+#define SANDBOX_PCI_DEVFN(d, f)((d << 3) | f)
+
+struct sandbox_pci_priv {
+   struct {
+   u16 vendor;
+   u16 device;
+   } vendev[256];
+};
+
 static int sandbox_pci_write_config(struct udevice *bus, pci_dev_t devfn,
uint offset, ulong value,
enum pci_size_t size)
 {
struct dm_pci_emul_ops *ops;
-   struct udevice *emul;
+   struct udevice *container, *emul;
int ret;
 
-   ret = sandbox_pci_get_emul(bus, devfn, &emul);
+   ret = sandbox_pci_get_emul(bus, devfn, &container, &emul);
if (ret)
return ret == -ENODEV ? 0 : ret;
ops = pci_get_emul_ops(emul);
@@ -33,14 +45,31 @@ static int sandbox_pci_read_config(struct udevice *bus, 
pci_dev_t devfn,
   enum pci_size_t size)
 {
struct dm_pci_emul_ops *ops;
-   struct udevice *emul;
+   struct udevice *container, *emul;
+   struct sandbox_pci_priv *priv = dev_get_priv(bus);
int ret;
 
/* Prepare the default response */
*valuep = pci_get_ff(size);
-   ret = sandbox_pci_get_emul(bus, devfn, &emul);
-   if (ret)
-   return ret == -ENODEV ? 0 : ret;
+   ret = sandbox_pci_get_emul(bus, devfn, &container, &emul);
+   if (ret) {
+   if (!container) {
+   u16 vendor, device;
+
+   devfn = SANDBOX_PCI_DEVFN(PCI_DEV(devfn),
+ PCI_FUNC(devfn));
+   vendor = priv->ve

[U-Boot] [PATCH v2 20/21] dm: pci: Add APIs to find capability and extended capability

2018-07-29 Thread Bin Meng
This introduces two new APIs dm_pci_find_capability() and
dm_pci_find_ext_capability() to get PCI capability address and
PCI express extended capability address for a given PCI device.

Signed-off-by: Bin Meng 

---

Changes in v2:
- Mask header_type with 0x7f

 drivers/pci/pci-uclass.c | 68 
 include/pci.h| 46 
 2 files changed, 114 insertions(+)

diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c
index 5eb6841..e9671d9 100644
--- a/drivers/pci/pci-uclass.c
+++ b/drivers/pci/pci-uclass.c
@@ -1320,6 +1320,74 @@ 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)
+{
+   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;
+   pos &= ~3;
+   dm_pci_read_config16(dev, pos, &ent);
+
+   id = ent & 0xff;
+   if (id == 0xff)
+   break;
+   if (id == cap)
+   return pos;
+   pos = (ent >> 8);
+   }
+
+   return 0;
+}
+
+int dm_pci_find_ext_capability(struct udevice *dev, int cap)
+{
+   u32 header;
+   int ttl;
+   int pos = PCI_CFG_SPACE_SIZE;
+
+   /* minimum 8 bytes per capability */
+   ttl = (PCI_CFG_SPACE_EXP_SIZE - PCI_CFG_SPACE_SIZE) / 8;
+
+   dm_pci_read_config32(dev, pos, &header);
+   /*
+* If we have no capabilities, this is indicated by cap ID,
+* cap version and next pointer all being 0.
+*/
+   if (header == 0)
+   return 0;
+
+   while (ttl--) {
+   if (PCI_EXT_CAP_ID(header) == cap)
+   return pos;
+
+   pos = PCI_EXT_CAP_NEXT(header);
+   if (pos < PCI_CFG_SPACE_SIZE)
+   break;
+
+   dm_pci_read_config32(dev, pos, &header);
+   }
+
+   return 0;
+}
+
 UCLASS_DRIVER(pci) = {
.id = UCLASS_PCI,
.name   = "pci",
diff --git a/include/pci.h b/include/pci.h
index 83a40a5..938a839 100644
--- a/include/pci.h
+++ b/include/pci.h
@@ -17,6 +17,7 @@
  * Under PCI, each device has 256 bytes of configuration address space,
  * of which the first 64 bytes are standardized as follows:
  */
+#define PCI_STD_HEADER_SIZEOF  64
 #define PCI_VENDOR_ID  0x00/* 16 bits */
 #define PCI_DEVICE_ID  0x02/* 16 bits */
 #define PCI_COMMAND0x04/* 16 bits */
@@ -1311,6 +1312,51 @@ 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_capability() - find a capability
+ *
+ * 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
+ * @cap:   capability code
+ * @return:capability address or 0 if not supported
+ */
+int dm_pci_find_capability(struct udevice *dev, int cap);
+
+/**
+ * dm_pci_find_ext_capability() - find an extended capability
+ *
+ * Tell if a device supports a given PCI express extended capability.
+ * Returns the address of the requested extended capability structure
+ * within the device's PCI configuration space or 0 in case the device
+ * does not support it.
+ *
+ * Possible values for @cap:
+ *
+ *  %PCI_EXT_CAP_ID_ERRAdvanced Error Reporting
+ *  %PCI_EXT_CAP_ID_VC Virtual Channel
+ *  %PCI_EXT_CAP_ID_DSNDevice Serial Number
+ *  %PCI_EXT_CAP_ID_PWRPower Budgeting
+ *
+ * See PCI_EXT_CAP_ID_xxx for the complete extended capability ID codes.
+ *
+ * @dev:   PCI device to query
+ * @cap:   extended capability code
+ * @return:extended capability address or 0 if not supported
+ */
+int dm_pci_find_ext_capability(struct udevice *dev, int cap);
+
 #define dm_pci_virt_to_bus(dev, addr, flags) \
dm_pci_phys_to_bus(dev, (virt_to_phys(addr)), (

[U-Boot] [PATCH v2 17/21] pci: sandbox: emul: Rename priv structure

2018-07-29 Thread Bin Meng
We have "struct sandbox_pci_priv" in pci_sandbox driver. To avoid
confusion, rename the emul's priv to "struct sandbox_pci_emul_priv".

Signed-off-by: Bin Meng 
---

Changes in v2: None

 drivers/pci/pci-emul-uclass.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/pci/pci-emul-uclass.c b/drivers/pci/pci-emul-uclass.c
index e9d2f49..3822758 100644
--- a/drivers/pci/pci-emul-uclass.c
+++ b/drivers/pci/pci-emul-uclass.c
@@ -11,7 +11,7 @@
 #include 
 #include 
 
-struct sandbox_pci_priv {
+struct sandbox_pci_emul_priv {
int dev_count;
 };
 
@@ -43,7 +43,7 @@ int sandbox_pci_get_emul(struct udevice *bus, pci_dev_t 
find_devfn,
 
 static int sandbox_pci_emul_post_probe(struct udevice *dev)
 {
-   struct sandbox_pci_priv *priv = dev->uclass->priv;
+   struct sandbox_pci_emul_priv *priv = dev->uclass->priv;
 
priv->dev_count++;
sandbox_set_enable_pci_map(true);
@@ -53,7 +53,7 @@ static int sandbox_pci_emul_post_probe(struct udevice *dev)
 
 static int sandbox_pci_emul_pre_remove(struct udevice *dev)
 {
-   struct sandbox_pci_priv *priv = dev->uclass->priv;
+   struct sandbox_pci_emul_priv *priv = dev->uclass->priv;
 
priv->dev_count--;
sandbox_set_enable_pci_map(priv->dev_count > 0);
@@ -66,5 +66,5 @@ UCLASS_DRIVER(pci_emul) = {
.name   = "pci_emul",
.post_probe = sandbox_pci_emul_post_probe,
.pre_remove = sandbox_pci_emul_pre_remove,
-   .priv_auto_alloc_size   = sizeof(struct sandbox_pci_priv),
+   .priv_auto_alloc_size   = sizeof(struct sandbox_pci_emul_priv),
 };
-- 
2.7.4

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


[U-Boot] [PATCH v2 21/21] test: dm: pci: Add cases for finding PCI capability APIs

2018-07-29 Thread Bin Meng
Add several PCI capability and extended capability ID registers
in the swap_case driver, so that we can add test case for
dm_pci_find_capability() and dm_pci_find_ext_capability().

Signed-off-by: Bin Meng 

---

Changes in v2: None

 arch/sandbox/include/asm/test.h |  8 
 drivers/misc/swap_case.c| 21 +
 test/dm/pci.c   | 32 
 3 files changed, 61 insertions(+)

diff --git a/arch/sandbox/include/asm/test.h b/arch/sandbox/include/asm/test.h
index 57aeca8..c8ae52b 100644
--- a/arch/sandbox/include/asm/test.h
+++ b/arch/sandbox/include/asm/test.h
@@ -16,6 +16,14 @@
 #define SANDBOX_PCI_CLASS_CODE PCI_CLASS_CODE_COMM
 #define SANDBOX_PCI_CLASS_SUB_CODE PCI_CLASS_SUB_CODE_COMM_SERIAL
 
+#define PCI_CAP_ID_PM_OFFSET   0x50
+#define PCI_CAP_ID_EXP_OFFSET  0x60
+#define PCI_CAP_ID_MSIX_OFFSET 0x70
+
+#define PCI_EXT_CAP_ID_ERR_OFFSET  0x100
+#define PCI_EXT_CAP_ID_VC_OFFSET   0x200
+#define PCI_EXT_CAP_ID_DSN_OFFSET  0x300
+
 /* Useful for PCI_VDEVICE() macro */
 #define PCI_VENDOR_ID_SANDBOX  SANDBOX_PCI_VENDOR_ID
 #define SWAP_CASE_DRV_DATA 0x55aa
diff --git a/drivers/misc/swap_case.c b/drivers/misc/swap_case.c
index 790bb0c..bffb809 100644
--- a/drivers/misc/swap_case.c
+++ b/drivers/misc/swap_case.c
@@ -118,6 +118,27 @@ static int sandbox_swap_case_read_config(struct udevice 
*emul, uint offset,
*valuep = result;
break;
}
+   case PCI_CAPABILITY_LIST:
+   *valuep = PCI_CAP_ID_PM_OFFSET;
+   break;
+   case PCI_CAP_ID_PM_OFFSET:
+   *valuep = (PCI_CAP_ID_EXP_OFFSET << 8) | PCI_CAP_ID_PM;
+   break;
+   case PCI_CAP_ID_EXP_OFFSET:
+   *valuep = (PCI_CAP_ID_MSIX_OFFSET << 8) | PCI_CAP_ID_EXP;
+   break;
+   case PCI_CAP_ID_MSIX_OFFSET:
+   *valuep = PCI_CAP_ID_MSIX;
+   break;
+   case PCI_EXT_CAP_ID_ERR_OFFSET:
+   *valuep = (PCI_EXT_CAP_ID_VC_OFFSET << 20) | PCI_EXT_CAP_ID_ERR;
+   break;
+   case PCI_EXT_CAP_ID_VC_OFFSET:
+   *valuep = (PCI_EXT_CAP_ID_DSN_OFFSET << 20) | PCI_EXT_CAP_ID_VC;
+   break;
+   case PCI_EXT_CAP_ID_DSN_OFFSET:
+   *valuep = PCI_EXT_CAP_ID_DSN;
+   break;
}
 
return 0;
diff --git a/test/dm/pci.c b/test/dm/pci.c
index e03f6ba..8699700 100644
--- a/test/dm/pci.c
+++ b/test/dm/pci.c
@@ -188,3 +188,35 @@ static int dm_test_pci_mixed(struct unit_test_state *uts)
return 0;
 }
 DM_TEST(dm_test_pci_mixed, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+/* Test looking up PCI capability and extended capability */
+static int dm_test_pci_cap(struct unit_test_state *uts)
+{
+   struct udevice *bus, *swap;
+   int cap;
+
+   ut_assertok(uclass_get_device_by_seq(UCLASS_PCI, 0, &bus));
+   ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(0, 0x1f, 0), &swap));
+
+   /* look up PCI_CAP_ID_EXP */
+   cap = dm_pci_find_capability(swap, PCI_CAP_ID_EXP);
+   ut_asserteq(PCI_CAP_ID_EXP_OFFSET, cap);
+
+   /* look up PCI_CAP_ID_PCIX */
+   cap = dm_pci_find_capability(swap, PCI_CAP_ID_PCIX);
+   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));
+
+   /* look up PCI_EXT_CAP_ID_DSN */
+   cap = dm_pci_find_ext_capability(swap, PCI_EXT_CAP_ID_DSN);
+   ut_asserteq(PCI_EXT_CAP_ID_DSN_OFFSET, cap);
+
+   /* look up PCI_EXT_CAP_ID_SRIOV */
+   cap = dm_pci_find_ext_capability(swap, PCI_EXT_CAP_ID_SRIOV);
+   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] configs: omap: Remove dead config CONFIG_SYS_NAND_ADDR

2018-07-29 Thread Adam Ford
CONFIG_SYS_NAND_ADDR is defined and never referenced. This patch
removes the dead code.

Signed-off-by: Adam Ford 
---
 include/configs/am3517_crane.h  | 2 --
 include/configs/am3517_evm.h| 2 --
 include/configs/cm_t35.h| 2 --
 include/configs/cm_t3517.h  | 2 --
 include/configs/devkit8000.h| 3 ---
 include/configs/mcx.h   | 2 --
 include/configs/omap3_logic.h   | 2 --
 include/configs/omap3_overo.h   | 2 --
 include/configs/omap3_pandora.h | 2 --
 include/configs/omap3_zoom1.h   | 2 --
 include/configs/tao3530.h   | 2 --
 include/configs/tricorder.h | 3 ---
 scripts/config_whitelist.txt| 1 -
 13 files changed, 27 deletions(-)

diff --git a/include/configs/am3517_crane.h b/include/configs/am3517_crane.h
index ffe40a4160..b9a3a5079d 100644
--- a/include/configs/am3517_crane.h
+++ b/include/configs/am3517_crane.h
@@ -99,8 +99,6 @@
 /*
  * Board NAND Info.
  */
-#define CONFIG_SYS_NAND_ADDR   NAND_BASE   /* physical address */
-   /* to access nand */
 #define CONFIG_SYS_NAND_BASE   NAND_BASE   /* physical address */
/* to access */
/* nand at CS0 */
diff --git a/include/configs/am3517_evm.h b/include/configs/am3517_evm.h
index 9a20796214..c767961562 100644
--- a/include/configs/am3517_evm.h
+++ b/include/configs/am3517_evm.h
@@ -66,8 +66,6 @@
 
 /* Board NAND Info. */
 #ifdef CONFIG_NAND
-#define CONFIG_SYS_NAND_ADDR   NAND_BASE   /* physical address */
-   /* to access nand */
 #define CONFIG_SYS_NAND_5_ADDR_CYCLE
 #define CONFIG_SYS_NAND_PAGE_COUNT 64
 #define CONFIG_SYS_NAND_PAGE_SIZE  2048
diff --git a/include/configs/cm_t35.h b/include/configs/cm_t35.h
index 415924549b..adadfb29bf 100644
--- a/include/configs/cm_t35.h
+++ b/include/configs/cm_t35.h
@@ -89,8 +89,6 @@
 /*
  * Board NAND Info.
  */
-#define CONFIG_SYS_NAND_ADDR   NAND_BASE   /* physical address */
-   /* to access nand */
 #define CONFIG_SYS_NAND_BASE   NAND_BASE   /* physical address */
/* to access nand at */
/* CS0 */
diff --git a/include/configs/cm_t3517.h b/include/configs/cm_t3517.h
index 2c889d4a85..0ea70cc1bf 100644
--- a/include/configs/cm_t3517.h
+++ b/include/configs/cm_t3517.h
@@ -91,8 +91,6 @@
 /*
  * Board NAND Info.
  */
-#define CONFIG_SYS_NAND_ADDR   NAND_BASE   /* physical address */
-   /* to access nand */
 #define CONFIG_SYS_NAND_BASE   NAND_BASE   /* physical address */
/* to access nand at */
/* CS0 */
diff --git a/include/configs/devkit8000.h b/include/configs/devkit8000.h
index f36dc2dc2c..1b4e33255d 100644
--- a/include/configs/devkit8000.h
+++ b/include/configs/devkit8000.h
@@ -60,9 +60,6 @@
 #define CONFIG_TWL4030_LED 1
 
 /* Board NAND Info */
-
-#define CONFIG_SYS_NAND_ADDR   NAND_BASE   /* physical address */
-   /* to access nand */
 #define CONFIG_JFFS2_NAND
 /* nand device jffs2 lives on */
 #define CONFIG_JFFS2_DEV   "nand0"
diff --git a/include/configs/mcx.h b/include/configs/mcx.h
index 0cad187a3c..66dec07b2a 100644
--- a/include/configs/mcx.h
+++ b/include/configs/mcx.h
@@ -81,8 +81,6 @@
 /*
  * Board NAND Info.
  */
-#define CONFIG_SYS_NAND_ADDR   NAND_BASE   /* physical address */
-   /* to access nand */
 #define CONFIG_SYS_NAND_BASE   NAND_BASE   /* physical address */
/* to access */
/* nand at CS0 */
diff --git a/include/configs/omap3_logic.h b/include/configs/omap3_logic.h
index 4d811e096c..c904d289fb 100644
--- a/include/configs/omap3_logic.h
+++ b/include/configs/omap3_logic.h
@@ -43,8 +43,6 @@
 
 /* Board NAND Info. */
 #ifdef CONFIG_NAND
-#define CONFIG_SYS_NAND_ADDR   NAND_BASE /* physical address */
- /* to access nand */
 #define CONFIG_SYS_MAX_NAND_DEVICE 1 /* Max number of */
  /* NAND devices */
 #define CONFIG_SYS_NAND_5_ADDR_CYCLE
diff --git a/include/configs/omap3_overo.h b/include/configs/omap3_overo.h
index a3d0e5fcaa..bcad26b2f1 100644
--- a/include/configs/omap3_overo.h
+++ b/include/configs/omap3_overo.h
@@ -51,8 +51,6 @@
 #endif /* CONFIG_NAND */
 
 /* Board NAND Info. */
-#define CONFIG_SYS_NAND_ADDR   NAND_BASE   /*

[U-Boot] [PATCH] configs: omap3_logic: Disable NAND ID during SPL

2018-07-29 Thread Adam Ford
For these boards, the GPMC timings are more determined by
processor speed/type than the NAND/PoP memory.  This code
is never invoked, so disable the config option, so it doesn't
take the time to compile it in.

Signed-off-by: Adam Ford 

diff --git a/configs/omap3_logic_defconfig b/configs/omap3_logic_defconfig
index ed9f454a5d..77dfdfc0e5 100644
--- a/configs/omap3_logic_defconfig
+++ b/configs/omap3_logic_defconfig
@@ -3,6 +3,7 @@ CONFIG_ARCH_OMAP2PLUS=y
 CONFIG_TI_COMMON_CMD_OPTIONS=y
 CONFIG_SYS_MALLOC_F_LEN=0x2000
 CONFIG_TARGET_OMAP3_LOGIC=y
+# CONFIG_SPL_OMAP3_ID_NAND is not set
 CONFIG_SPL=y
 CONFIG_DEFAULT_DEVICE_TREE="logicpd-torpedo-37xx-devkit"
 CONFIG_DISTRO_DEFAULTS=y
-- 
2.17.1

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


[U-Boot] [GIT PULL] Kconfig changes

2018-07-29 Thread Michal Simek
Hi Tom,

I have put together that CMD_DM enabling we have discussed (and small
Kconfig changes). I have rebased it on Friday and travis also looks
good. https://travis-ci.org/michalsimek/u-boot/builds/408812930

There will be more and more collisions when new stuff is coming that's
why please consider to pull these patches to your tree.

Thanks,
Michal


The following changes since commit 2547e91dc15e5203e15d4ebde9172174743b14a7:

  tegra: Indicate that binman makes all three output files (2018-07-26
15:49:40 -0400)

are available in the git repository at:

  git://www.denx.de/git/u-boot-microblaze.git kconfig

for you to fetch changes up to 4f19bb26b78a45ce291bab587396e5fc51821690:

  kconfig: Replace spaces with tabs (2018-07-27 08:19:02 +0200)


Michal Simek (8):
  Kconfig: Remove trailing whitespaces in prompt
  common: Log should depends on DM not be selected by DM
  Kconfig: Replace spaces with tabs and missing newline
  Kconfig: Sort bool, default, select and imply options
  dm: Change CMD_DM enabling
  Kconfig: Sort bool, default, select and imply options
  fpga: Kconfig: Replace spaces with tabs
  kconfig: Replace spaces with tabs

 Kconfig   |  54
+++---
 arch/Kconfig  |  57
+---
 arch/arc/Kconfig  |  10 +++
 arch/arm/Kconfig  | 239
---
 arch/arm/cpu/armv7/ls102xa/Kconfig|  10 +++
 arch/arm/cpu/armv8/Kconfig|   4 +--
 arch/arm/mach-at91/Kconfig|  66
+-
 arch/arm/mach-davinci/Kconfig |   4 +--
 arch/arm/mach-exynos/Kconfig  |  30 ++---
 arch/arm/mach-imx/mx3/Kconfig |   2 +-
 arch/arm/mach-imx/mx5/Kconfig |  14 +-
 arch/arm/mach-imx/mx6/Kconfig | 193
---
 arch/arm/mach-imx/mx7/Kconfig |  23 +---
 arch/arm/mach-meson/Kconfig   |   2 ++
 arch/arm/mach-mvebu/Kconfig   |   6 ++---
 arch/arm/mach-omap2/Kconfig   |   6 ++---
 arch/arm/mach-omap2/am33xx/Kconfig|  64
+
 arch/arm/mach-omap2/omap3/Kconfig |  30 ++---
 arch/arm/mach-omap2/omap5/Kconfig |  12 -
 arch/arm/mach-qemu/Kconfig|   2 +-
 arch/arm/mach-rmobile/Kconfig.32  |  22 +++-
 arch/arm/mach-rockchip/rk3288/Kconfig |  20 +++---
 arch/arm/mach-socfpga/Kconfig |   4 +--
 arch/arm/mach-stm32/Kconfig   |  20 +++---
 arch/arm/mach-tegra/Kconfig   |   9 ---
 arch/arm/mach-tegra/tegra124/Kconfig  |   4 +--
 arch/arm/mach-uniphier/Kconfig|   7 ++---
 arch/microblaze/Kconfig   |   5 ++--
 arch/mips/Kconfig |  56
+--
 arch/mips/mach-ath79/Kconfig  |  10 +++
 arch/mips/mach-bmips/Kconfig  |  36 +-
 arch/mips/mach-pic32/Kconfig  |   6 ++---
 arch/powerpc/Kconfig  |   2 +-
 arch/powerpc/cpu/mpc83xx/Kconfig  |   7 ++---
 cmd/Kconfig   |  20 +++---
 common/Kconfig|   2 +-
 drivers/fpga/Kconfig  |  16 ++--
 drivers/power/pmic/Kconfig|   2 +-
 dts/Kconfig   |   2 +-
 39 files changed, 596 insertions(+), 482 deletions(-)
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot