Re: [U-Boot] [PATCH 2/7] axi: Add AXI sandbox driver and simple emulator

2018-04-11 Thread Mario Six
Hi Simon,

On Fri, Mar 30, 2018 at 10:41 AM, Simon Glass  wrote:
> Hi Mario,
>
> On 28 March 2018 at 20:40, Mario Six  wrote:
>> Add test infrastructure and tests for the AXI uclass.
>>
>> Signed-off-by: Mario Six 
>> ---
>>  drivers/axi/Kconfig   |   6 +++
>>  drivers/axi/Makefile  |   3 ++
>>  drivers/axi/axi-emul-uclass.c |  68 
>>  drivers/axi/axi_sandbox.c |  61 ++
>>  drivers/axi/sandbox_store.c   | 118 
>> ++
>>  include/axi.h |  51 ++
>>  include/dm/uclass-id.h|   1 +
>>  7 files changed, 308 insertions(+)
>>  create mode 100644 drivers/axi/axi-emul-uclass.c
>>  create mode 100644 drivers/axi/axi_sandbox.c
>>  create mode 100644 drivers/axi/sandbox_store.c
>>
>> diff --git a/drivers/axi/Kconfig b/drivers/axi/Kconfig
>> index 19e1b7fd2f..a0333782cf 100644
>> --- a/drivers/axi/Kconfig
>> +++ b/drivers/axi/Kconfig
>> @@ -21,4 +21,10 @@ config IHS_AXI
>>   Support for IHS AXI bus on a gdsys IHS FPGA used to communicate 
>> with
>>   IP cores in the FPGA (e.g. video transmitter cores).
>>
>> +config AXI_SANDBOX
>> +   bool "Enable AXI sandbox driver"
>> +   depends on DM
>> +   help
>> + Support the AXI emulation for the sandbox environment.
>
> Please spell out abbreviations
>
>> +
>>  endif
>> diff --git a/drivers/axi/Makefile b/drivers/axi/Makefile
>> index 18d9380e9b..66b6c5a28f 100644
>> --- a/drivers/axi/Makefile
>> +++ b/drivers/axi/Makefile
>> @@ -7,3 +7,6 @@
>>
>>  obj-$(CONFIG_AXI) += axi-uclass.o
>>  obj-$(CONFIG_IHS_AXI) += ihs_axi.o
>> +obj-$(CONFIG_SANDBOX) += axi-emul-uclass.o
>> +obj-$(CONFIG_SANDBOX) += sandbox_store.o
>> +obj-$(CONFIG_AXI_SANDBOX) += axi_sandbox.o
>> diff --git a/drivers/axi/axi-emul-uclass.c b/drivers/axi/axi-emul-uclass.c
>> new file mode 100644
>> index 00..bf60c40518
>> --- /dev/null
>> +++ b/drivers/axi/axi-emul-uclass.c
>> @@ -0,0 +1,68 @@
>> +/*
>> + * (C) Copyright 2018
>> + * Mario Six, Guntermann & Drunck GmbH, mario@gdsys.cc
>> + *
>> + * SPDX-License-Identifier:GPL-2.0+
>> + */
>> +
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +int axi_sandbox_get_emul(struct udevice *bus, ulong address, enum 
>> axi_size_t size,
>> +struct udevice **emulp)
>> +{
>> +   struct udevice *dev;
>> +   u32 reg[2];
>> +   uint offset;
>> +
>> +   switch (size) {
>> +   case AXI_SIZE_8:
>> +   offset = 1;
>> +   break;
>> +   case AXI_SIZE_16:
>> +   offset = 2;
>> +   break;
>> +   case AXI_SIZE_32:
>> +   offset = 4;
>> +   break;
>> +   default:
>> +   offset = 0;
>> +   }
>> +
>> +   for (device_find_first_child(bus, );
>> +dev;
>> +device_find_next_child()) {
>> +   int ret;
>> +
>> +   ret = dev_read_u32_array(dev, "reg", reg, ARRAY_SIZE(reg));
>> +   if (ret)
>> +   continue;
>> +
>> +   if (address >= reg[0] && address <= reg[0] + reg[1] - 
>> offset) {
>> +   if (device_probe(dev))
>> +   return -ENODEV;
>> +
>> +   *emulp = dev;
>> +   return 0;
>> +   }
>> +   }
>> +
>> +   return -ENODEV;
>> +}
>> +
>> +int axi_get_store(struct udevice *dev, u8 **store)
>> +{
>> +   struct axi_emul_ops *ops = axi_emul_get_ops(dev);
>> +
>> +   if (!ops->get_store)
>> +   return -ENOSYS;
>> +
>> +   return ops->get_store(dev, store);
>> +}
>> +
>> +UCLASS_DRIVER(axi_emul) = {
>> +   .id = UCLASS_AXI_EMUL,
>> +   .name   = "axi_emul",
>> +};
>> diff --git a/drivers/axi/axi_sandbox.c b/drivers/axi/axi_sandbox.c
>> new file mode 100644
>> index 00..b0f24bdd9d
>> --- /dev/null
>> +++ b/drivers/axi/axi_sandbox.c
>> @@ -0,0 +1,61 @@
>> +/*
>> + * (C) Copyright 2018
>> + * Mario Six, Guntermann & Drunck GmbH, mario@gdsys.cc
>> + *
>> + * SPDX-License-Identifier:GPL-2.0+
>> + */
>> +
>> +#include 
>> +#include 
>> +#include 
>> +
>> +int axi_sandbox_read(struct udevice *bus, ulong address, void *data,
>> +enum axi_size_t size)
>> +{
>> +   struct axi_emul_ops *ops;
>> +   struct udevice *emul;
>> +   int ret;
>> +
>> +   ret = axi_sandbox_get_emul(bus, address, size, );
>> +   if (ret)
>> +   return ret == -ENODEV ? 0 : ret;
>
> Please add a comment as to why you are doing this.
>
>> +   ops = axi_emul_get_ops(emul);
>> +   if (!ops || !ops->read)
>> +   return -ENOSYS;
>> +
>> +   return ops->read(emul, address, data, size);
>> +}
>> +
>> +int axi_sandbox_write(struct udevice *bus, ulong address, void *data,
>> + enum 

Re: [U-Boot] [PATCH 2/7] axi: Add AXI sandbox driver and simple emulator

2018-03-30 Thread Simon Glass
Hi Mario,

On 28 March 2018 at 20:40, Mario Six  wrote:
> Add test infrastructure and tests for the AXI uclass.
>
> Signed-off-by: Mario Six 
> ---
>  drivers/axi/Kconfig   |   6 +++
>  drivers/axi/Makefile  |   3 ++
>  drivers/axi/axi-emul-uclass.c |  68 
>  drivers/axi/axi_sandbox.c |  61 ++
>  drivers/axi/sandbox_store.c   | 118 
> ++
>  include/axi.h |  51 ++
>  include/dm/uclass-id.h|   1 +
>  7 files changed, 308 insertions(+)
>  create mode 100644 drivers/axi/axi-emul-uclass.c
>  create mode 100644 drivers/axi/axi_sandbox.c
>  create mode 100644 drivers/axi/sandbox_store.c
>
> diff --git a/drivers/axi/Kconfig b/drivers/axi/Kconfig
> index 19e1b7fd2f..a0333782cf 100644
> --- a/drivers/axi/Kconfig
> +++ b/drivers/axi/Kconfig
> @@ -21,4 +21,10 @@ config IHS_AXI
>   Support for IHS AXI bus on a gdsys IHS FPGA used to communicate with
>   IP cores in the FPGA (e.g. video transmitter cores).
>
> +config AXI_SANDBOX
> +   bool "Enable AXI sandbox driver"
> +   depends on DM
> +   help
> + Support the AXI emulation for the sandbox environment.

Please spell out abbreviations

> +
>  endif
> diff --git a/drivers/axi/Makefile b/drivers/axi/Makefile
> index 18d9380e9b..66b6c5a28f 100644
> --- a/drivers/axi/Makefile
> +++ b/drivers/axi/Makefile
> @@ -7,3 +7,6 @@
>
>  obj-$(CONFIG_AXI) += axi-uclass.o
>  obj-$(CONFIG_IHS_AXI) += ihs_axi.o
> +obj-$(CONFIG_SANDBOX) += axi-emul-uclass.o
> +obj-$(CONFIG_SANDBOX) += sandbox_store.o
> +obj-$(CONFIG_AXI_SANDBOX) += axi_sandbox.o
> diff --git a/drivers/axi/axi-emul-uclass.c b/drivers/axi/axi-emul-uclass.c
> new file mode 100644
> index 00..bf60c40518
> --- /dev/null
> +++ b/drivers/axi/axi-emul-uclass.c
> @@ -0,0 +1,68 @@
> +/*
> + * (C) Copyright 2018
> + * Mario Six, Guntermann & Drunck GmbH, mario@gdsys.cc
> + *
> + * SPDX-License-Identifier:GPL-2.0+
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +int axi_sandbox_get_emul(struct udevice *bus, ulong address, enum axi_size_t 
> size,
> +struct udevice **emulp)
> +{
> +   struct udevice *dev;
> +   u32 reg[2];
> +   uint offset;
> +
> +   switch (size) {
> +   case AXI_SIZE_8:
> +   offset = 1;
> +   break;
> +   case AXI_SIZE_16:
> +   offset = 2;
> +   break;
> +   case AXI_SIZE_32:
> +   offset = 4;
> +   break;
> +   default:
> +   offset = 0;
> +   }
> +
> +   for (device_find_first_child(bus, );
> +dev;
> +device_find_next_child()) {
> +   int ret;
> +
> +   ret = dev_read_u32_array(dev, "reg", reg, ARRAY_SIZE(reg));
> +   if (ret)
> +   continue;
> +
> +   if (address >= reg[0] && address <= reg[0] + reg[1] - offset) 
> {
> +   if (device_probe(dev))
> +   return -ENODEV;
> +
> +   *emulp = dev;
> +   return 0;
> +   }
> +   }
> +
> +   return -ENODEV;
> +}
> +
> +int axi_get_store(struct udevice *dev, u8 **store)
> +{
> +   struct axi_emul_ops *ops = axi_emul_get_ops(dev);
> +
> +   if (!ops->get_store)
> +   return -ENOSYS;
> +
> +   return ops->get_store(dev, store);
> +}
> +
> +UCLASS_DRIVER(axi_emul) = {
> +   .id = UCLASS_AXI_EMUL,
> +   .name   = "axi_emul",
> +};
> diff --git a/drivers/axi/axi_sandbox.c b/drivers/axi/axi_sandbox.c
> new file mode 100644
> index 00..b0f24bdd9d
> --- /dev/null
> +++ b/drivers/axi/axi_sandbox.c
> @@ -0,0 +1,61 @@
> +/*
> + * (C) Copyright 2018
> + * Mario Six, Guntermann & Drunck GmbH, mario@gdsys.cc
> + *
> + * SPDX-License-Identifier:GPL-2.0+
> + */
> +
> +#include 
> +#include 
> +#include 
> +
> +int axi_sandbox_read(struct udevice *bus, ulong address, void *data,
> +enum axi_size_t size)
> +{
> +   struct axi_emul_ops *ops;
> +   struct udevice *emul;
> +   int ret;
> +
> +   ret = axi_sandbox_get_emul(bus, address, size, );
> +   if (ret)
> +   return ret == -ENODEV ? 0 : ret;

Please add a comment as to why you are doing this.

> +   ops = axi_emul_get_ops(emul);
> +   if (!ops || !ops->read)
> +   return -ENOSYS;
> +
> +   return ops->read(emul, address, data, size);
> +}
> +
> +int axi_sandbox_write(struct udevice *bus, ulong address, void *data,
> + enum axi_size_t size)
> +{
> +   struct axi_emul_ops *ops;
> +   struct udevice *emul;
> +   int ret;
> +
> +   ret = axi_sandbox_get_emul(bus, address, size, );
> +   if (ret)
> +   return ret == -ENODEV ? 0 : ret;
> +   ops = 

[U-Boot] [PATCH 2/7] axi: Add AXI sandbox driver and simple emulator

2018-03-28 Thread Mario Six
Add test infrastructure and tests for the AXI uclass.

Signed-off-by: Mario Six 
---
 drivers/axi/Kconfig   |   6 +++
 drivers/axi/Makefile  |   3 ++
 drivers/axi/axi-emul-uclass.c |  68 
 drivers/axi/axi_sandbox.c |  61 ++
 drivers/axi/sandbox_store.c   | 118 ++
 include/axi.h |  51 ++
 include/dm/uclass-id.h|   1 +
 7 files changed, 308 insertions(+)
 create mode 100644 drivers/axi/axi-emul-uclass.c
 create mode 100644 drivers/axi/axi_sandbox.c
 create mode 100644 drivers/axi/sandbox_store.c

diff --git a/drivers/axi/Kconfig b/drivers/axi/Kconfig
index 19e1b7fd2f..a0333782cf 100644
--- a/drivers/axi/Kconfig
+++ b/drivers/axi/Kconfig
@@ -21,4 +21,10 @@ config IHS_AXI
  Support for IHS AXI bus on a gdsys IHS FPGA used to communicate with
  IP cores in the FPGA (e.g. video transmitter cores).
 
+config AXI_SANDBOX
+   bool "Enable AXI sandbox driver"
+   depends on DM
+   help
+ Support the AXI emulation for the sandbox environment.
+
 endif
diff --git a/drivers/axi/Makefile b/drivers/axi/Makefile
index 18d9380e9b..66b6c5a28f 100644
--- a/drivers/axi/Makefile
+++ b/drivers/axi/Makefile
@@ -7,3 +7,6 @@
 
 obj-$(CONFIG_AXI) += axi-uclass.o
 obj-$(CONFIG_IHS_AXI) += ihs_axi.o
+obj-$(CONFIG_SANDBOX) += axi-emul-uclass.o
+obj-$(CONFIG_SANDBOX) += sandbox_store.o
+obj-$(CONFIG_AXI_SANDBOX) += axi_sandbox.o
diff --git a/drivers/axi/axi-emul-uclass.c b/drivers/axi/axi-emul-uclass.c
new file mode 100644
index 00..bf60c40518
--- /dev/null
+++ b/drivers/axi/axi-emul-uclass.c
@@ -0,0 +1,68 @@
+/*
+ * (C) Copyright 2018
+ * Mario Six, Guntermann & Drunck GmbH, mario@gdsys.cc
+ *
+ * SPDX-License-Identifier:GPL-2.0+
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+int axi_sandbox_get_emul(struct udevice *bus, ulong address, enum axi_size_t 
size,
+struct udevice **emulp)
+{
+   struct udevice *dev;
+   u32 reg[2];
+   uint offset;
+
+   switch (size) {
+   case AXI_SIZE_8:
+   offset = 1;
+   break;
+   case AXI_SIZE_16:
+   offset = 2;
+   break;
+   case AXI_SIZE_32:
+   offset = 4;
+   break;
+   default:
+   offset = 0;
+   }
+
+   for (device_find_first_child(bus, );
+dev;
+device_find_next_child()) {
+   int ret;
+
+   ret = dev_read_u32_array(dev, "reg", reg, ARRAY_SIZE(reg));
+   if (ret)
+   continue;
+
+   if (address >= reg[0] && address <= reg[0] + reg[1] - offset) {
+   if (device_probe(dev))
+   return -ENODEV;
+
+   *emulp = dev;
+   return 0;
+   }
+   }
+
+   return -ENODEV;
+}
+
+int axi_get_store(struct udevice *dev, u8 **store)
+{
+   struct axi_emul_ops *ops = axi_emul_get_ops(dev);
+
+   if (!ops->get_store)
+   return -ENOSYS;
+
+   return ops->get_store(dev, store);
+}
+
+UCLASS_DRIVER(axi_emul) = {
+   .id = UCLASS_AXI_EMUL,
+   .name   = "axi_emul",
+};
diff --git a/drivers/axi/axi_sandbox.c b/drivers/axi/axi_sandbox.c
new file mode 100644
index 00..b0f24bdd9d
--- /dev/null
+++ b/drivers/axi/axi_sandbox.c
@@ -0,0 +1,61 @@
+/*
+ * (C) Copyright 2018
+ * Mario Six, Guntermann & Drunck GmbH, mario@gdsys.cc
+ *
+ * SPDX-License-Identifier:GPL-2.0+
+ */
+
+#include 
+#include 
+#include 
+
+int axi_sandbox_read(struct udevice *bus, ulong address, void *data,
+enum axi_size_t size)
+{
+   struct axi_emul_ops *ops;
+   struct udevice *emul;
+   int ret;
+
+   ret = axi_sandbox_get_emul(bus, address, size, );
+   if (ret)
+   return ret == -ENODEV ? 0 : ret;
+   ops = axi_emul_get_ops(emul);
+   if (!ops || !ops->read)
+   return -ENOSYS;
+
+   return ops->read(emul, address, data, size);
+}
+
+int axi_sandbox_write(struct udevice *bus, ulong address, void *data,
+ enum axi_size_t size)
+{
+   struct axi_emul_ops *ops;
+   struct udevice *emul;
+   int ret;
+
+   ret = axi_sandbox_get_emul(bus, address, size, );
+   if (ret)
+   return ret == -ENODEV ? 0 : ret;
+   ops = axi_emul_get_ops(emul);
+   if (!ops || !ops->write)
+   return -ENOSYS;
+
+   return ops->write(emul, address, data, size);
+}
+
+static const struct udevice_id axi_sandbox_ids[] = {
+   { .compatible = "sandbox,axi" },
+   { /* sentinel */ }
+};
+
+static const struct axi_ops axi_sandbox_ops = {
+   .read = axi_sandbox_read,
+   .write = axi_sandbox_write,
+};
+
+U_BOOT_DRIVER(axi_sandbox_bus) = {
+   .name   = "axi_sandbox_bus",
+