FYI: misc: visconti: Toshiba Visconti Pyramid accelerator driver sample

2022-08-08 Thread Yuji Ishikawa
Hi Odded

This is a sample (wip) driver for a Pyramid accelerator found on Toshiba 
Visconti SoC.
This accelerator accepts a image (and table for scaling filter), 
then yields 4 differently scaled output images at a time.
Therefore (image-in, image-out), they say this driver should be classified to 
media driver category.
Actually, it is not easy to adapt it to v4l2 framework,
because the supported image format is different from ones commonly used in V4L2 
drivers.
There're almost no hint for handling planar RGB images nor handling multiple 
images with different resolution.

I hope this post (as well as DSPIF posted last week) will help your case-study.

Regards
Yuji Ishikawa


misc: visconti: Add Toshiba Visconti Pyramid image processing accelerator

Add support to Pyramid image processing accelerator on Toshiba Visconti ARM 
SoCs.
The accelerator takes an image and yields up to 4 resized images with different 
parameter.
Input / Output images can be either color / grayscale images.
The color channel format of the color image is planar-format (a plane for each 
color),
unlike interleaved format which is often seen in V4L2 RGB pixel format.
The visconti5 SoC has 1 unit of the accelerator.

Scaling (shrink) ratio can be x1 - x1/4.
Userland can provide the coefficients of window functions as well as using 
equipped linear filter.

The imprementation has two C sources:

* pyramid.c
  The user interface layer. It receives resize task description from userland 
library,
  manages lifecycle of DMA-BUF instances holding images,
  manages interrupt requests and updates device file status.
  Memory blocks are specified with fds + offsets of DMA-BUF instances.

* hwd_pyramid.c
  The hardware layer. It configures hardware registers following a request from 
pyramid.c
  This layer writes configuration to hardware registers (with 32bit word 
access), then kicks the hardware.
  Memory blocks are specified with 32bit-truncated phisical address.

Future plan:

* power management operations will be added, once the visconti clock framework 
driver supports the Pyramid hardware.
* When the Visconti IOMMU driver (currently under review) is accepted,
  the hardware layer will use 32bit IO virtual address mapped by the dedicated 
IOMMU.

dt-bindings: soc: visconti: Add Toshiba Visconti PYRAMID image processing 
accelerator bindings

This commit adds the Device Tree binding documentation that allows to describe
the PYRAMID image processing accelerator found in Toshiba Visconti SoCs.

Signed-off-by: Yuji Ishikawa 
---
 .../visconti/toshiba,visconti-pyramid.yaml|  52 ++
 drivers/misc/Kconfig  |   1 +
 drivers/misc/Makefile |   1 +
 drivers/misc/visconti/Kconfig |   8 +
 drivers/misc/visconti/Makefile|   6 +
 drivers/misc/visconti/pyramid/Makefile|   8 +
 drivers/misc/visconti/pyramid/hwd_pyramid.c   | 334 +++
 drivers/misc/visconti/pyramid/hwd_pyramid.h   | 129 +
 drivers/misc/visconti/pyramid/pyramid.c   | 532 ++
 include/uapi/linux/visconti-ipa.h |  87 +++
 include/uapi/linux/visconti-pyramid.h | 120 
 11 files changed, 1278 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/misc/visconti/toshiba,visconti-pyramid.yaml
 create mode 100644 drivers/misc/visconti/Kconfig
 create mode 100644 drivers/misc/visconti/Makefile
 create mode 100644 drivers/misc/visconti/pyramid/Makefile
 create mode 100644 drivers/misc/visconti/pyramid/hwd_pyramid.c
 create mode 100644 drivers/misc/visconti/pyramid/hwd_pyramid.h
 create mode 100644 drivers/misc/visconti/pyramid/pyramid.c
 create mode 100644 include/uapi/linux/visconti-ipa.h
 create mode 100644 include/uapi/linux/visconti-pyramid.h

diff --git 
a/Documentation/devicetree/bindings/misc/visconti/toshiba,visconti-pyramid.yaml 
b/Documentation/devicetree/bindings/misc/visconti/toshiba,visconti-pyramid.yaml
new file mode 100644
index 0..be0168a6a
--- /dev/null
+++ 
b/Documentation/devicetree/bindings/misc/visconti/toshiba,visconti-pyramid.yaml
@@ -0,0 +1,52 @@
+# SPDX-LIcense-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/soc/visconti/toshiba,visconti-pyramid.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Toshiba Visconti PYRAMID image processing accelerator
+
+maintainers:
+  - Nobuhiro Iwamatsu 
+
+description: |
+  Toshiba Visconti PYRAMID image processing accelerator accepts a picture with 
up to 3 planes
+  and yields up to 4 pictures with different scaling parameters.
+
+properties:
+  compatible:
+items:
+  - const: toshiba,visconti-pyramid
+
+  reg:
+maxItems: 1
+
+  interrupts:
+maxItems: 1
+
+  index:
+const: 0
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - index
+
+additionalProperties: false
+
+examples:
+  - |
+#include 
+#include 
+
+soc {
+#address-cells = <2>;
+   

FYI: misc: visconti: Toshiba Visconti DSP accelerator driver sample

2022-08-05 Thread Yuji Ishikawa
Hello Odded

This is a sample (wip) driver for a DSP found on Toshiba Visconti SoC.
The DSP typically accepts some images, apply an algorithm on them and yields 
resulting one.
Therefore (image-in, image-out), they say this driver should be classified to 
media driver category.
However, it can handle various data format (wider than v4l2 officially 
supports) 
if userland provide firmware (=algorithm) for its own.

Yes, this rough implementation is the first step only our staff could go.
I'm not for sure whether we could carry out experiments earlier if we chose to 
use existing frameworks,
instead of writing our own routine for handling DMA-BUFs and interrupts.
I hope this post will help your case-study.

Regards
Yuji Ishikawa


misc: visconti: Add Toshiba Visconti DSPIF image processing accelerator

Add support to DSPIF image processing accelerator on Toshiba Visconti ARM SoCs.
The accelerator accepts a task description and a firmware, provides various 
filter / image processing algorithm.
Currently, DSP firmware is fixed one loaded by bootloader.
And the phisical address of the firmware is specified from userland, not 
hard-coded nor loaded from device tree.

CPU and DSP share following communication media to manage tasks.

* DSP registers: 32bit word access registers to specify DSP firmware address 
and several parameters.
* shared mem: a part of DRAM to pass task description (struct hwd_dspif_msg). 
The DSP busmaster interface is little endian.
* interrupt controller (DCOMM): to notify start event (CPU->DSP) and finish 
event (DSP->CPU).

The implementation has two C sources:

* dspif.c
  The user interface. It receives inference task description from userlan 
library.
  manages lifecycle of DMA-BUF instances holding input/output data,
  managegs interrupt requests and updates device file status.
  Memory blocks are specified with fds + offsets of DMA-BUF instances.

* hwd_dspif.c
  The hardware layer. It configures hardware registers following a request from 
dspif.c.
  This layer communicate with DSP hardware via registers, shared memory and 
dedicated interrupt controller.
  Memory blocks are specified with 32bit-truncated phisical address

Future plan:
* Power management operations will be added, once the visconti clock framework 
driver supports the DSP hardware.
* When the visconti IOMMU driver (currently under review) is accepted,
  the hardware layer will use 32bit IO virutal address mapped by the dedicated 
IOMMU.
* Better way to load / specify DSP firmware.

dt-bindings: misc: visconti: Add Toshiba Visconti DSPIF image processing 
accelerator bindings

Also, here's a Device Tree binding documentation that allows to describe
the DSPIF image processing accelerator found in Toshiba Visconti SoCs.

Signed-off-by: Yuji Ishikawa 
---
 .../misc/visconti/toshiba,visconti-dspif.yaml |  61 ++
 drivers/misc/Kconfig  |   1 +
 drivers/misc/Makefile |   1 +
 drivers/misc/visconti/Kconfig |   8 +
 drivers/misc/visconti/Makefile|   7 +
 drivers/misc/visconti/dspif/Makefile  |   8 +
 drivers/misc/visconti/dspif/dspif.c   | 547 ++
 drivers/misc/visconti/dspif/hwd_dspif.c   | 275 +
 drivers/misc/visconti/dspif/hwd_dspif.h   | 100 
 include/uapi/linux/visconti-dspif.h   |  85 +++
 include/uapi/linux/visconti-ipa.h |  87 +++
 11 files changed, 1180 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/misc/visconti/toshiba,visconti-dspif.yaml
 create mode 100644 drivers/misc/visconti/Kconfig
 create mode 100644 drivers/misc/visconti/Makefile
 create mode 100644 drivers/misc/visconti/dspif/Makefile
 create mode 100644 drivers/misc/visconti/dspif/dspif.c
 create mode 100644 drivers/misc/visconti/dspif/hwd_dspif.c
 create mode 100644 drivers/misc/visconti/dspif/hwd_dspif.h
 create mode 100644 include/uapi/linux/visconti-dspif.h
 create mode 100644 include/uapi/linux/visconti-ipa.h

diff --git 
a/Documentation/devicetree/bindings/misc/visconti/toshiba,visconti-dspif.yaml 
b/Documentation/devicetree/bindings/misc/visconti/toshiba,visconti-dspif.yaml
new file mode 100644
index 0..7c10e28dc
--- /dev/null
+++ 
b/Documentation/devicetree/bindings/misc/visconti/toshiba,visconti-dspif.yaml
@@ -0,0 +1,61 @@
+# SPDX-LIcense-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/soc/visconti/toshiba,visconti-dspif.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Toshiba Visconti DSPIF image processing accerelator
+
+maintainers:
+  - Nobuhiro Iwamatsu 
+
+description: |
+  Toshiba Visconti DSPIF image processing accelerator provides various 
operation on images.
+  Visconti5 have up to 4 DSP units.
+
+properties:
+  compatible:
+items:
+  - const: toshiba,visconti-dspif
+
+  reg:
+items:
+  - description: DSP control register
+  - description: DCOMM int

[PATCH v2 5/5] Documentation: driver-api: visconti: add a description of DNN driver.

2022-07-22 Thread Yuji Ishikawa
Signed-off-by: Yuji Ishikawa 
---
v1 -> v2:
  - newly added documents
---
 Documentation/driver-api/visconti/common.rst | 115 ++
 Documentation/driver-api/visconti/dnn.rst| 394 +++
 2 files changed, 509 insertions(+)
 create mode 100644 Documentation/driver-api/visconti/common.rst
 create mode 100644 Documentation/driver-api/visconti/dnn.rst

diff --git a/Documentation/driver-api/visconti/common.rst 
b/Documentation/driver-api/visconti/common.rst
new file mode 100644
index 0..cc2d3f6cd
--- /dev/null
+++ b/Documentation/driver-api/visconti/common.rst
@@ -0,0 +1,115 @@
+==
+Common interfaces for Visconti IPA Drivers
+==
+
+file operation
+==
+
+IPA driver expose thair function to userspace with device files.
+
+* The device file has specific name, such as /dev/dnn0
+* device file provides some operations
+
+ - open / close
+ - two ioctls operations to control IPA 
+ - poll to wait for the finish of IPA
+
+IOCTLs
+==
+
+All IPA drivers have following two IOCTL requests.
+See individual documents of IPA drivers for detail.
+
+.. c:macro:: IOC_IPA_START
+
+starts IPA processing.
+
+.. c:macro:: IOC_IPA_GET_STATUS
+
+get the status of IPA driver
+
+IPA Addresses
+=
+
+IPA drivers assume that the buffers for IPA HW processing are DMA-BUF
+which are phisically contiguous memory block  allocated with DMA-BUF heaps.
+The heap area is defined with a reserved-memory element in device tree 
description.
+See Documentation/devicetree/bindings/reserved-memory/reserved-memory.txt for 
further information.
+
+Two structures are used to describe DMA-BUF instances.
+
+* :c:type:`drv_ipa_buffer_info`
+* :c:type:`drv_ipa_addr`
+
+Note that allocation size of DMA-BUF instances should be power of two.
+This is mainly because IOMMUs have very limited number of entries for 
translation.
+
+
+drv_ipa_buffer_info
+---
+
+Information about the buffer allocated with DMA-BUF heaps.
+Applications specify the array of drv_ipa_buffer_info to the driver.
+
+drv_ipa_addr
+
+
+Application specify the region to be processed with two information; index for 
the array of drv_ipa_buffer_info and offset.
+
+.. c:macro:: IPA_INVALID_ADDR
+
+When a buffer is an optional parameter for an API, application can use 
:c:macro:`IPA_INVALID_ADDR` instead of NULL.
+
+For example:
+
+.. code-block:: c
+
+   struct drv_ipa_addr null_addr = IPA_INVALID_ADDR;
+
+Code exampe
+---
+
+.. code-block:: c
+
+   /* hogehoge */
+   /* hogehoge */
+
+Structures
+==
+
+.. kernel-doc:: drivers/soc/visconti/uapi/ipa.h
+
+Further description of addressing
+=
+
+DRAM addressing space
+-
+
+Visconti5 (TMPV770x) SoCs have 2 DDR controllers.
+Each space for a controller is mapped in 36bit address space as follows:
+
+* DDR0: 0x0_8000_ - 0x0__
+* DDR1: 0x8_8000_ - 0x8__
+
+IPAs have dedicated IOMMUs (visconti ioatu) which translate 32bit IOVA to 
36bit physical address.
+Note that address registers of IPA core hardware only accept 32bit values.
+When IOMMUs are absent (by removing their description from device tree), DDR1 
address must not be used for IPA.
+
+Coherent access among CPUs / IPAs
+-
+
+Bus master of IPAs has two connections; direct access to DRAM and 
cache-coherent connection with CPU clusters.
+The bit 34 of 64bit address is used to distinguish direct access or coherent 
acccess.
+
+* DDR0 (direct):   0x0_8000_ - 0x0__
+* DDR0 (coherent): 0x4_8000_ - 0x4__
+* DDR1 (direct):   0x8_8000_ - 0x8__
+* DDR1 (coherent): 0xC_8000_ - 0xC__
+
+If the whole system should run coherent mode, make following changes in device 
tree description:
+
+* set coherent address for all memory and reserved-memory elements
+* set dma_coherent property to all IPA elements
+
+It is strongly recommended not to use both direct and coherent address at the 
same time.
+
diff --git a/Documentation/driver-api/visconti/dnn.rst 
b/Documentation/driver-api/visconti/dnn.rst
new file mode 100644
index 0..1abdd6c7c
--- /dev/null
+++ b/Documentation/driver-api/visconti/dnn.rst
@@ -0,0 +1,394 @@
+===
+Visconti DNN IPA driver
+===
+
+Hardware overview
+=
+
+Visconti DNN IPA is a proprietary CNN/DCNN accelerator developed by Toshiba.
+This IPA integrates large scaled parallel MAC units and dedicated function 
units to accelerate
+inference operation of well known neural network layers. It also has dedicated 
DMA unit to make accesses to DRAM.
+Visconti5 SoC has 2 instances of DNN accelerator hardware.
+
+WORDS:
+
+* IPA: Image Processing Accelerator
+* CNN: Convolutional Neural Network
+* DCNN: Deep Convolutional Neural Network
+
+Software architecture
+=
+
+The operat

[PATCH v2 4/5] MAINTAINERS: Add entries for Toshiba Visconti DNN image processing accelerator

2022-07-22 Thread Yuji Ishikawa
---
 MAINTAINERS | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index dd36acc87..a2e2bd719 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2796,12 +2796,14 @@ F:  
Documentation/devicetree/bindings/net/toshiba,visconti-dwmac.yaml
 F: Documentation/devicetree/bindings/gpio/toshiba,gpio-visconti.yaml
 F: Documentation/devicetree/bindings/pci/toshiba,visconti-pcie.yaml
 F: Documentation/devicetree/bindings/pinctrl/toshiba,visconti-pinctrl.yaml
+F: Documentation/devicetree/bindings/soc/visconti/
 F: Documentation/devicetree/bindings/watchdog/toshiba,visconti-wdt.yaml
 F: arch/arm64/boot/dts/toshiba/
 F: drivers/net/ethernet/stmicro/stmmac/dwmac-visconti.c
 F: drivers/gpio/gpio-visconti.c
 F: drivers/pci/controller/dwc/pcie-visconti.c
 F: drivers/pinctrl/visconti/
+F: drivers/soc/visconti/
 F: drivers/watchdog/visconti_wdt.c
 N: visconti
 
-- 
2.17.1




[PATCH v2 3/5] soc: visconti: Add Toshiba Visconti DNN image processing accelerator

2022-07-22 Thread Yuji Ishikawa
Add support to DNN image processing accelerator on Toshiba Visconti ARM SoCs.
The accelerator is applicable to DNN inference tasks.

Signed-off-by: Yuji Ishikawa 
Reviewed-by: Nobuhiro Iwamatsu 
---
v1 -> v2:
  - applied checkpatch.pl --strict
  - removed unused code
---
 drivers/soc/visconti/Kconfig   |   6 +
 drivers/soc/visconti/Makefile  |   2 +
 drivers/soc/visconti/dnn/Makefile  |   6 +
 drivers/soc/visconti/dnn/dnn.c | 523 +
 drivers/soc/visconti/dnn/hwd_dnn.c | 183 +
 drivers/soc/visconti/dnn/hwd_dnn.h |  68 
 drivers/soc/visconti/dnn/hwd_dnn_reg.h | 228 +++
 drivers/soc/visconti/uapi/dnn.h|  77 
 8 files changed, 1093 insertions(+)
 create mode 100644 drivers/soc/visconti/dnn/Makefile
 create mode 100644 drivers/soc/visconti/dnn/dnn.c
 create mode 100644 drivers/soc/visconti/dnn/hwd_dnn.c
 create mode 100644 drivers/soc/visconti/dnn/hwd_dnn.h
 create mode 100644 drivers/soc/visconti/dnn/hwd_dnn_reg.h
 create mode 100644 drivers/soc/visconti/uapi/dnn.h

diff --git a/drivers/soc/visconti/Kconfig b/drivers/soc/visconti/Kconfig
index 8b1378917..a25287d0c 100644
--- a/drivers/soc/visconti/Kconfig
+++ b/drivers/soc/visconti/Kconfig
@@ -1 +1,7 @@
+if ARCH_VISCONTI
+
+config VISCONTI_DNN
+bool "Visconti DNN driver"
+
+endif
 
diff --git a/drivers/soc/visconti/Makefile b/drivers/soc/visconti/Makefile
index 8d710da08..b9bd0f7e2 100644
--- a/drivers/soc/visconti/Makefile
+++ b/drivers/soc/visconti/Makefile
@@ -4,3 +4,5 @@
 #
 
 obj-y += ipa_common.o
+
+obj-$(CONFIG_VISCONTI_DNN) += dnn/
diff --git a/drivers/soc/visconti/dnn/Makefile 
b/drivers/soc/visconti/dnn/Makefile
new file mode 100644
index 0..52d57b60d
--- /dev/null
+++ b/drivers/soc/visconti/dnn/Makefile
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Makefile for the Visconti DNN driver
+#
+
+obj-y += dnn.o hwd_dnn.o
diff --git a/drivers/soc/visconti/dnn/dnn.c b/drivers/soc/visconti/dnn/dnn.c
new file mode 100644
index 0..08dcc4e77
--- /dev/null
+++ b/drivers/soc/visconti/dnn/dnn.c
@@ -0,0 +1,523 @@
+// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause
+/* Toshiba Visconti DNN Accelerator Support
+ *
+ * (C) Copyright 2022 TOSHIBA CORPORATION
+ * (C) Copyright 2022 Toshiba Electronic Devices & Storage Corporation
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "../ipa_common.h"
+#include "../uapi/dnn.h"
+#include "hwd_dnn.h"
+
+struct dnn_priv {
+   struct device *dev;
+   struct miscdevice miscdev;
+   struct mutex lock;
+   void __iomem *regs;
+   int irq;
+   wait_queue_head_t waitq;
+   enum drv_ipa_state status;
+   unsigned int poll_event;
+   int id;
+   char name[16];
+   struct hwd_dnn_status hwd_status;
+
+   u32 *list_vaddr[DRV_DNN_BASE_ADDR_NUM];
+   dma_addr_t list_paddr[DRV_DNN_BASE_ADDR_NUM];
+   unsigned int err_flags[HWD_DNN_EER_FLAG_NUM];
+
+   struct dma_buf_attachment *dba[DRV_DNN_BUFFER_INDEX_MAX];
+   struct sg_table *sgt[DRV_DNN_BUFFER_INDEX_MAX];
+   enum dma_data_direction dma_dir[DRV_DNN_BUFFER_INDEX_MAX];
+   unsigned int dma_count;
+
+   dma_addr_t buffer_iova[DRV_DNN_BUFFER_INDEX_MAX];
+
+   struct drv_ipa_addr temp_list[HWD_DNN_LIST_NUM_MAX];
+};
+
+static uint32_t dnn_ipa_addr_to_iova(struct dnn_priv *priv, struct 
drv_ipa_addr addr)
+{
+   u32 iova = 0;
+
+   if (addr.buffer_index < priv->dma_count &&
+   addr.offset < priv->dba[addr.buffer_index]->dmabuf->size)
+   iova = priv->buffer_iova[addr.buffer_index] + addr.offset;
+   return iova;
+}
+
+static int dnn_attach_dma_buf(struct dnn_priv *priv, unsigned int buffer_index,
+ struct drv_ipa_buffer_info 
buffer_info[DRV_DNN_BUFFER_INDEX_MAX])
+{
+   int ret = 0;
+   dma_addr_t addr;
+
+   if (buffer_index >= DRV_DNN_BUFFER_INDEX_MAX) {
+   dev_err(priv->dev, "Buffer index invalid: index=%d\n", 
buffer_index);
+   return -EINVAL;
+   }
+
+   switch (buffer_info[buffer_index].direction) {
+   case DRV_IPA_DIR_NONE:
+   priv->dma_dir[priv->dma_count] = DMA_NONE;
+   break;
+   case DRV_IPA_DIR_TO_DEVICE:
+   priv->dma_dir[priv->dma_count] = DMA_TO_DEVICE;
+   break;
+   case DRV_IPA_DIR_FROM_DEVICE:
+   priv->dma_dir[priv->dma_count] = DMA_FROM_DEVICE;
+   break;
+   case DRV_IPA_DIR_BIDIRECTION:
+   priv->dma_dir[priv->dma_count] = DMA_BIDIRECTIONAL;
+   break;
+   default:
+   dev_err(priv->dev, "DMA direction invalid: index=%d dir=%d\n", 
buffer_index,
+   buffer_info[buffer_index

[PATCH v2 2/5] soc: visconti: Add Toshiba Visconti image processing accelerator common source

2022-07-22 Thread Yuji Ishikawa
This commit adds common definitions shared among image processing accelerator 
drivers
for Toshiba Visconti SoCs.

Signed-off-by: Yuji Ishikawa 
Reviewed-by: Nobuhiro Iwamatsu 
---
v1 -> v2:
  - applied checkpatch.pl --strict
---
 drivers/soc/Kconfig   |  1 +
 drivers/soc/Makefile  |  1 +
 drivers/soc/visconti/Kconfig  |  1 +
 drivers/soc/visconti/Makefile |  6 +++
 drivers/soc/visconti/ipa_common.c | 55 +++
 drivers/soc/visconti/ipa_common.h | 18 +++
 drivers/soc/visconti/uapi/ipa.h   | 90 +++
 7 files changed, 172 insertions(+)
 create mode 100644 drivers/soc/visconti/Kconfig
 create mode 100644 drivers/soc/visconti/Makefile
 create mode 100644 drivers/soc/visconti/ipa_common.c
 create mode 100644 drivers/soc/visconti/ipa_common.h
 create mode 100644 drivers/soc/visconti/uapi/ipa.h

diff --git a/drivers/soc/Kconfig b/drivers/soc/Kconfig
index e8a30c4c5..c99139aa8 100644
--- a/drivers/soc/Kconfig
+++ b/drivers/soc/Kconfig
@@ -22,6 +22,7 @@ source "drivers/soc/tegra/Kconfig"
 source "drivers/soc/ti/Kconfig"
 source "drivers/soc/ux500/Kconfig"
 source "drivers/soc/versatile/Kconfig"
+source "drivers/soc/visconti/Kconfig"
 source "drivers/soc/xilinx/Kconfig"
 
 endmenu
diff --git a/drivers/soc/Makefile b/drivers/soc/Makefile
index a05e9fbcd..455b993c2 100644
--- a/drivers/soc/Makefile
+++ b/drivers/soc/Makefile
@@ -28,4 +28,5 @@ obj-$(CONFIG_ARCH_TEGRA)  += tegra/
 obj-y  += ti/
 obj-$(CONFIG_ARCH_U8500)   += ux500/
 obj-$(CONFIG_PLAT_VERSATILE)   += versatile/
+obj-$(CONFIG_ARCH_VISCONTI)+= visconti/
 obj-y  += xilinx/
diff --git a/drivers/soc/visconti/Kconfig b/drivers/soc/visconti/Kconfig
new file mode 100644
index 0..8b1378917
--- /dev/null
+++ b/drivers/soc/visconti/Kconfig
@@ -0,0 +1 @@
+
diff --git a/drivers/soc/visconti/Makefile b/drivers/soc/visconti/Makefile
new file mode 100644
index 0..8d710da08
--- /dev/null
+++ b/drivers/soc/visconti/Makefile
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Makefile for the Visconti specific device drivers.
+#
+
+obj-y += ipa_common.o
diff --git a/drivers/soc/visconti/ipa_common.c 
b/drivers/soc/visconti/ipa_common.c
new file mode 100644
index 0..6345f33c5
--- /dev/null
+++ b/drivers/soc/visconti/ipa_common.c
@@ -0,0 +1,55 @@
+// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause
+/* Toshiba Visconti Image Processing Accelerator Support
+ *
+ * (C) Copyright 2022 TOSHIBA CORPORATION
+ * (C) Copyright 2022 Toshiba Electronic Devices & Storage Corporation
+ */
+
+#include "ipa_common.h"
+
+int ipa_attach_dmabuf(struct device *dev, int fd, struct dma_buf_attachment 
**a,
+ struct sg_table **s, dma_addr_t *addr, enum 
dma_data_direction dma_dir)
+{
+   struct dma_buf_attachment *attachment;
+   struct dma_buf *dmabuf;
+   struct sg_table *sgt;
+   int ret;
+
+   dmabuf = dma_buf_get(fd);
+   if (IS_ERR(dmabuf)) {
+   dev_err(dev, "Invalid dmabuf FD\n");
+   return PTR_ERR(dmabuf);
+   }
+   attachment = dma_buf_attach(dmabuf, dev);
+
+   if (IS_ERR(attachment)) {
+   dev_err(dev, "Failed to attach dmabuf\n");
+   ret = PTR_ERR(attachment);
+   goto err_put;
+   }
+   sgt = dma_buf_map_attachment(attachment, dma_dir);
+   if (IS_ERR(sgt)) {
+   dev_err(dev, "Failed to get dmabufs sg_table\n");
+   ret = PTR_ERR(sgt);
+   goto err_detach;
+   }
+   if (sgt->nents != 1) {
+   dev_err(dev, "Sparse DMA region is unsupported\n");
+   ret = -EINVAL;
+   goto err_unmap;
+   }
+
+   *addr = sg_dma_address(sgt->sgl);
+   *a = attachment;
+   *s = sgt;
+
+   return 0;
+
+err_unmap:
+   dma_buf_unmap_attachment(attachment, sgt, dma_dir);
+err_detach:
+   dma_buf_detach(dmabuf, attachment);
+err_put:
+   dma_buf_put(dmabuf);
+   return ret;
+}
diff --git a/drivers/soc/visconti/ipa_common.h 
b/drivers/soc/visconti/ipa_common.h
new file mode 100644
index 0..786988c52
--- /dev/null
+++ b/drivers/soc/visconti/ipa_common.h
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause */
+/* Toshiba Visconti Image Processing Accelerator Support
+ *
+ * (C) Copyright 2022 TOSHIBA CORPORATION
+ * (C) Copyright 2022 Toshiba Electronic Devices & Storage Corporation
+ */
+
+#include 
+#include 
+
+#define COHERENT_ADDRESS_BIT   (0x4ULL)
+#define IPA_POLL_EVENT_NONE(0)
+#define IPA_POLL_EVENT_DONE(1)
+#define IPA_POLL_EVENT_ERROR   (2)
+#define IPA_WAKEUP_RETRY_DELAY (300 * 1000) /*usec*/
+
+int ipa_attach_dmabuf(struct device *dev, int fd, struct dma_buf_attachment 
**a,
+ struct sg_table **s, dma_addr

[PATCH v2 1/5] dt-bindings: soc: visconti: Add Toshiba Visconti DNN image processing accelerator bindings

2022-07-22 Thread Yuji Ishikawa
This commit adds the Device Tree binding documentation that allows to describe
the DNN image processing accelerator found in Toshiba Visconti SoCs.

Signed-off-by: Yuji Ishikawa 
Reviewed-by: Nobuhiro Iwamatsu 
---
 .../soc/visconti/toshiba,visconti-dnn.yaml| 54 +++
 1 file changed, 54 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/soc/visconti/toshiba,visconti-dnn.yaml

diff --git 
a/Documentation/devicetree/bindings/soc/visconti/toshiba,visconti-dnn.yaml 
b/Documentation/devicetree/bindings/soc/visconti/toshiba,visconti-dnn.yaml
new file mode 100644
index 0..28576a55e
--- /dev/null
+++ b/Documentation/devicetree/bindings/soc/visconti/toshiba,visconti-dnn.yaml
@@ -0,0 +1,54 @@
+# SPDX-LIcense-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/soc/visconti/toshiba,visconti-dnn.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Toshiba Visconti DNN image processing accelerator
+
+maintainers:
+  - Nobuhiro Iwamatsu 
+
+description: |
+  Toshiba Visconti DNN image processing accelerator.
+  Visconti5 have up to 2 DNN units.
+
+properties:
+  compatible:
+items:
+  - const: toshiba,visconti-dnn
+
+  reg:
+maxItems: 1
+
+  interrupts:
+maxItems: 1
+
+  index:
+enum: [0, 1]
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - index
+
+additionalProperties: false
+
+examples:
+  - |
+#include 
+#include 
+
+soc {
+#address-cells = <2>;
+#size-cells = <2>;
+
+dnn0: dnn@1428 {
+compatible = "toshiba,visconti-dnn";
+reg = <0 0x1428 0 0x8000>;
+interrupts = ;
+index = <0>;
+status = "disabled";
+};
+};
-- 
2.17.1




[PATCH v2 0/5] Add Toshiba Visconti DNN image processing accelerator driver

2022-07-22 Thread Yuji Ishikawa
This series is the DNN image processing accelerator driver for Toshiba's ARM 
SoC, Visconti[0].
This provides DT binding documentation, device driver, MAINTAINER files and 
documents.

Best regards,
Yuji

[0]: 
https://toshiba.semicon-storage.com/ap-en/semiconductor/product/image-recognition-processors-visconti.html

dt-bindings: soc: visconti: Add Toshiba Visconti DNN image processing 
accelerator bindings
  v1 -> v2:
- No update

soc: visconti: Add Toshiba Visconti image processing accelerator common source
  v1 -> v2:
- checked with checkpatch.pl --strict

soc: visconti: Add Toshiba Visconti DNN image processing accelerator
  v1 -> v2:
- checked with checkpatch.pl --strict
- removed unused code

MAINTAINERS: Add entries for Toshiba Visconti DNN image processing
  v1 -> v2:
- No update

Documentation: driver-api: visconti: add a description of DNN driver.
  v1 -> v2:
- newly added documents

Yuji Ishikawa (5):
  dt-bindings: soc: visconti: Add Toshiba Visconti DNN image processing
accelerator bindings
  soc: visconti: Add Toshiba Visconti image processing accelerator
common source
  soc: visconti: Add Toshiba Visconti DNN image processing accelerator
  MAINTAINERS: Add entries for Toshiba Visconti DNN image processing
accelerator
  Documentation: driver-api: visconti: add a description of DNN driver.

 .../soc/visconti/toshiba,visconti-dnn.yaml|  54 ++
 Documentation/driver-api/visconti/common.rst  | 115 
 Documentation/driver-api/visconti/dnn.rst | 394 +
 MAINTAINERS   |   2 +
 drivers/soc/Kconfig   |   1 +
 drivers/soc/Makefile  |   1 +
 drivers/soc/visconti/Kconfig  |   7 +
 drivers/soc/visconti/Makefile |   8 +
 drivers/soc/visconti/dnn/Makefile |   6 +
 drivers/soc/visconti/dnn/dnn.c| 523 ++
 drivers/soc/visconti/dnn/hwd_dnn.c| 183 ++
 drivers/soc/visconti/dnn/hwd_dnn.h|  68 +++
 drivers/soc/visconti/dnn/hwd_dnn_reg.h| 228 
 drivers/soc/visconti/ipa_common.c |  55 ++
 drivers/soc/visconti/ipa_common.h |  18 +
 drivers/soc/visconti/uapi/dnn.h   |  77 +++
 drivers/soc/visconti/uapi/ipa.h   |  90 +++
 17 files changed, 1830 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/soc/visconti/toshiba,visconti-dnn.yaml
 create mode 100644 Documentation/driver-api/visconti/common.rst
 create mode 100644 Documentation/driver-api/visconti/dnn.rst
 create mode 100644 drivers/soc/visconti/Kconfig
 create mode 100644 drivers/soc/visconti/Makefile
 create mode 100644 drivers/soc/visconti/dnn/Makefile
 create mode 100644 drivers/soc/visconti/dnn/dnn.c
 create mode 100644 drivers/soc/visconti/dnn/hwd_dnn.c
 create mode 100644 drivers/soc/visconti/dnn/hwd_dnn.h
 create mode 100644 drivers/soc/visconti/dnn/hwd_dnn_reg.h
 create mode 100644 drivers/soc/visconti/ipa_common.c
 create mode 100644 drivers/soc/visconti/ipa_common.h
 create mode 100644 drivers/soc/visconti/uapi/dnn.h
 create mode 100644 drivers/soc/visconti/uapi/ipa.h

-- 
2.17.1




[PATCH 4/4] MAINTAINERS: Add entries for Toshiba Visconti DNN image processing accelerator

2022-04-28 Thread Yuji Ishikawa
---
 MAINTAINERS | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index dd36acc87..a2e2bd719 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2796,12 +2796,14 @@ F:  
Documentation/devicetree/bindings/net/toshiba,visconti-dwmac.yaml
 F: Documentation/devicetree/bindings/gpio/toshiba,gpio-visconti.yaml
 F: Documentation/devicetree/bindings/pci/toshiba,visconti-pcie.yaml
 F: Documentation/devicetree/bindings/pinctrl/toshiba,visconti-pinctrl.yaml
+F: Documentation/devicetree/bindings/soc/visconti/
 F: Documentation/devicetree/bindings/watchdog/toshiba,visconti-wdt.yaml
 F: arch/arm64/boot/dts/toshiba/
 F: drivers/net/ethernet/stmicro/stmmac/dwmac-visconti.c
 F: drivers/gpio/gpio-visconti.c
 F: drivers/pci/controller/dwc/pcie-visconti.c
 F: drivers/pinctrl/visconti/
+F: drivers/soc/visconti/
 F: drivers/watchdog/visconti_wdt.c
 N: visconti
 
-- 
2.17.1




[PATCH 3/4] soc: visconti: Add Toshiba Visconti DNN image processing accelerator

2022-04-28 Thread Yuji Ishikawa
Add support to DNN image processing accelerator on Toshiba Visconti ARM SoCs.
The accelerator is applicable to DNN inference tasks.

Signed-off-by: Yuji Ishikawa 
Reviewed-by: Nobuhiro Iwamatsu 
---
 drivers/soc/visconti/Kconfig   |   6 +
 drivers/soc/visconti/Makefile  |   2 +
 drivers/soc/visconti/dnn/Makefile  |   6 +
 drivers/soc/visconti/dnn/dnn.c | 533 +
 drivers/soc/visconti/dnn/hwd_dnn.c | 183 +
 drivers/soc/visconti/dnn/hwd_dnn.h |  68 
 drivers/soc/visconti/dnn/hwd_dnn_reg.h | 228 +++
 drivers/soc/visconti/uapi/dnn.h|  77 
 8 files changed, 1103 insertions(+)
 create mode 100644 drivers/soc/visconti/dnn/Makefile
 create mode 100644 drivers/soc/visconti/dnn/dnn.c
 create mode 100644 drivers/soc/visconti/dnn/hwd_dnn.c
 create mode 100644 drivers/soc/visconti/dnn/hwd_dnn.h
 create mode 100644 drivers/soc/visconti/dnn/hwd_dnn_reg.h
 create mode 100644 drivers/soc/visconti/uapi/dnn.h

diff --git a/drivers/soc/visconti/Kconfig b/drivers/soc/visconti/Kconfig
index 8b1378917..a25287d0c 100644
--- a/drivers/soc/visconti/Kconfig
+++ b/drivers/soc/visconti/Kconfig
@@ -1 +1,7 @@
+if ARCH_VISCONTI
+
+config VISCONTI_DNN
+bool "Visconti DNN driver"
+
+endif
 
diff --git a/drivers/soc/visconti/Makefile b/drivers/soc/visconti/Makefile
index 8d710da08..b9bd0f7e2 100644
--- a/drivers/soc/visconti/Makefile
+++ b/drivers/soc/visconti/Makefile
@@ -4,3 +4,5 @@
 #
 
 obj-y += ipa_common.o
+
+obj-$(CONFIG_VISCONTI_DNN) += dnn/
diff --git a/drivers/soc/visconti/dnn/Makefile 
b/drivers/soc/visconti/dnn/Makefile
new file mode 100644
index 0..52d57b60d
--- /dev/null
+++ b/drivers/soc/visconti/dnn/Makefile
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Makefile for the Visconti DNN driver
+#
+
+obj-y += dnn.o hwd_dnn.o
diff --git a/drivers/soc/visconti/dnn/dnn.c b/drivers/soc/visconti/dnn/dnn.c
new file mode 100644
index 0..aeff92037
--- /dev/null
+++ b/drivers/soc/visconti/dnn/dnn.c
@@ -0,0 +1,533 @@
+// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause
+/* Toshiba Visconti DNN Accelerator Support
+ *
+ * (C) Copyright 2022 TOSHIBA CORPORATION
+ * (C) Copyright 2022 Toshiba Electronic Devices & Storage Corporation
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "../ipa_common.h"
+#include "../uapi/dnn.h"
+#include "hwd_dnn.h"
+
+struct dnn_priv {
+   struct device *dev;
+   struct miscdevice miscdev;
+   struct mutex lock;
+   void __iomem *regs;
+   int irq;
+   wait_queue_head_t waitq;
+   enum drv_ipa_state status;
+   unsigned int poll_event;
+   int id;
+   char name[16];
+   bool dma_coherent;
+   struct hwd_dnn_status hwd_status;
+
+   u32 *list_vaddr[DRV_DNN_BASE_ADDR_NUM];
+   dma_addr_t list_paddr[DRV_DNN_BASE_ADDR_NUM];
+   unsigned int err_flags[HWD_DNN_EER_FLAG_NUM];
+
+   struct dma_buf_attachment *dba[DRV_DNN_BUFFER_INDEX_MAX];
+   struct sg_table *sgt[DRV_DNN_BUFFER_INDEX_MAX];
+   enum dma_data_direction dma_dir[DRV_DNN_BUFFER_INDEX_MAX];
+   unsigned int dma_count;
+
+   dma_addr_t buffer_iova[DRV_DNN_BUFFER_INDEX_MAX];
+
+   struct drv_ipa_addr temp_list[HWD_DNN_LIST_NUM_MAX];
+};
+
+static uint32_t dnn_ipa_addr_to_iova(struct dnn_priv *priv, struct 
drv_ipa_addr addr)
+{
+   u32 iova = 0;
+
+   if (addr.buffer_index < priv->dma_count &&
+   addr.offset < priv->dba[addr.buffer_index]->dmabuf->size)
+   iova = priv->buffer_iova[addr.buffer_index] + addr.offset;
+   return iova;
+}
+
+static int dnn_attach_dma_buf(struct dnn_priv *priv, unsigned int buffer_index,
+ struct drv_ipa_buffer_info 
buffer_info[DRV_DNN_BUFFER_INDEX_MAX])
+{
+   int ret = 0;
+   dma_addr_t addr;
+
+   if (buffer_index >= DRV_DNN_BUFFER_INDEX_MAX) {
+   dev_err(priv->dev, "Buffer index invalid: index=%d\n", 
buffer_index);
+   return -EINVAL;
+   }
+
+   switch (buffer_info[buffer_index].direction) {
+   case DRV_IPA_DIR_NONE:
+   priv->dma_dir[priv->dma_count] = DMA_NONE;
+   break;
+   case DRV_IPA_DIR_TO_DEVICE:
+   priv->dma_dir[priv->dma_count] = DMA_TO_DEVICE;
+   break;
+   case DRV_IPA_DIR_FROM_DEVICE:
+   priv->dma_dir[priv->dma_count] = DMA_FROM_DEVICE;
+   break;
+   case DRV_IPA_DIR_BIDIRECTION:
+   priv->dma_dir[priv->dma_count] = DMA_BIDIRECTIONAL;
+   break;
+   default:
+   dev_err(priv->dev, "DMA direction invalid: index=%d dir=%d\n", 
buffer_index,
+   buffer_info[buffer_index].direction);
+   return -EINVAL;
+   }
+
+   if (

[PATCH 2/4] soc: visconti: Add Toshiba Visconti image processing accelerator common source

2022-04-28 Thread Yuji Ishikawa
This commit adds common definitions shared among image processing accelerator 
drivers
for Toshiba Visconti SoCs.

Signed-off-by: Yuji Ishikawa 
Reviewed-by: Nobuhiro Iwamatsu 
---
 drivers/soc/Kconfig   |  1 +
 drivers/soc/Makefile  |  1 +
 drivers/soc/visconti/Kconfig  |  1 +
 drivers/soc/visconti/Makefile |  6 +++
 drivers/soc/visconti/ipa_common.c | 55 +++
 drivers/soc/visconti/ipa_common.h | 18 +++
 drivers/soc/visconti/uapi/ipa.h   | 88 +++
 7 files changed, 170 insertions(+)
 create mode 100644 drivers/soc/visconti/Kconfig
 create mode 100644 drivers/soc/visconti/Makefile
 create mode 100644 drivers/soc/visconti/ipa_common.c
 create mode 100644 drivers/soc/visconti/ipa_common.h
 create mode 100644 drivers/soc/visconti/uapi/ipa.h

diff --git a/drivers/soc/Kconfig b/drivers/soc/Kconfig
index e8a30c4c5..c99139aa8 100644
--- a/drivers/soc/Kconfig
+++ b/drivers/soc/Kconfig
@@ -22,6 +22,7 @@ source "drivers/soc/tegra/Kconfig"
 source "drivers/soc/ti/Kconfig"
 source "drivers/soc/ux500/Kconfig"
 source "drivers/soc/versatile/Kconfig"
+source "drivers/soc/visconti/Kconfig"
 source "drivers/soc/xilinx/Kconfig"
 
 endmenu
diff --git a/drivers/soc/Makefile b/drivers/soc/Makefile
index a05e9fbcd..455b993c2 100644
--- a/drivers/soc/Makefile
+++ b/drivers/soc/Makefile
@@ -28,4 +28,5 @@ obj-$(CONFIG_ARCH_TEGRA)  += tegra/
 obj-y  += ti/
 obj-$(CONFIG_ARCH_U8500)   += ux500/
 obj-$(CONFIG_PLAT_VERSATILE)   += versatile/
+obj-$(CONFIG_ARCH_VISCONTI)+= visconti/
 obj-y  += xilinx/
diff --git a/drivers/soc/visconti/Kconfig b/drivers/soc/visconti/Kconfig
new file mode 100644
index 0..8b1378917
--- /dev/null
+++ b/drivers/soc/visconti/Kconfig
@@ -0,0 +1 @@
+
diff --git a/drivers/soc/visconti/Makefile b/drivers/soc/visconti/Makefile
new file mode 100644
index 0..8d710da08
--- /dev/null
+++ b/drivers/soc/visconti/Makefile
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Makefile for the Visconti specific device drivers.
+#
+
+obj-y += ipa_common.o
diff --git a/drivers/soc/visconti/ipa_common.c 
b/drivers/soc/visconti/ipa_common.c
new file mode 100644
index 0..6345f33c5
--- /dev/null
+++ b/drivers/soc/visconti/ipa_common.c
@@ -0,0 +1,55 @@
+// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause
+/* Toshiba Visconti Image Processing Accelerator Support
+ *
+ * (C) Copyright 2022 TOSHIBA CORPORATION
+ * (C) Copyright 2022 Toshiba Electronic Devices & Storage Corporation
+ */
+
+#include "ipa_common.h"
+
+int ipa_attach_dmabuf(struct device *dev, int fd, struct dma_buf_attachment 
**a,
+ struct sg_table **s, dma_addr_t *addr, enum 
dma_data_direction dma_dir)
+{
+   struct dma_buf_attachment *attachment;
+   struct dma_buf *dmabuf;
+   struct sg_table *sgt;
+   int ret;
+
+   dmabuf = dma_buf_get(fd);
+   if (IS_ERR(dmabuf)) {
+   dev_err(dev, "Invalid dmabuf FD\n");
+   return PTR_ERR(dmabuf);
+   }
+   attachment = dma_buf_attach(dmabuf, dev);
+
+   if (IS_ERR(attachment)) {
+   dev_err(dev, "Failed to attach dmabuf\n");
+   ret = PTR_ERR(attachment);
+   goto err_put;
+   }
+   sgt = dma_buf_map_attachment(attachment, dma_dir);
+   if (IS_ERR(sgt)) {
+   dev_err(dev, "Failed to get dmabufs sg_table\n");
+   ret = PTR_ERR(sgt);
+   goto err_detach;
+   }
+   if (sgt->nents != 1) {
+   dev_err(dev, "Sparse DMA region is unsupported\n");
+   ret = -EINVAL;
+   goto err_unmap;
+   }
+
+   *addr = sg_dma_address(sgt->sgl);
+   *a = attachment;
+   *s = sgt;
+
+   return 0;
+
+err_unmap:
+   dma_buf_unmap_attachment(attachment, sgt, dma_dir);
+err_detach:
+   dma_buf_detach(dmabuf, attachment);
+err_put:
+   dma_buf_put(dmabuf);
+   return ret;
+}
diff --git a/drivers/soc/visconti/ipa_common.h 
b/drivers/soc/visconti/ipa_common.h
new file mode 100644
index 0..786988c52
--- /dev/null
+++ b/drivers/soc/visconti/ipa_common.h
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause */
+/* Toshiba Visconti Image Processing Accelerator Support
+ *
+ * (C) Copyright 2022 TOSHIBA CORPORATION
+ * (C) Copyright 2022 Toshiba Electronic Devices & Storage Corporation
+ */
+
+#include 
+#include 
+
+#define COHERENT_ADDRESS_BIT   (0x4ULL)
+#define IPA_POLL_EVENT_NONE(0)
+#define IPA_POLL_EVENT_DONE(1)
+#define IPA_POLL_EVENT_ERROR   (2)
+#define IPA_WAKEUP_RETRY_DELAY (300 * 1000) /*usec*/
+
+int ipa_attach_dmabuf(struct device *dev, int fd, struct dma_buf_attachment 
**a,
+ struct sg_table **s, dma_addr_t *addr, enum 
dma_data_direction dma_dir);
di

[PATCH 1/4] dt-bindings: soc: visconti: Add Toshiba Visconti DNN image processing accelerator bindings

2022-04-28 Thread Yuji Ishikawa
This commit adds the Device Tree binding documentation that allows to describe
the DNN image processing accelerator found in Toshiba Visconti SoCs.

Signed-off-by: Yuji Ishikawa 
Reviewed-by: Nobuhiro Iwamatsu 
---
 .../soc/visconti/toshiba,visconti-dnn.yaml| 54 +++
 1 file changed, 54 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/soc/visconti/toshiba,visconti-dnn.yaml

diff --git 
a/Documentation/devicetree/bindings/soc/visconti/toshiba,visconti-dnn.yaml 
b/Documentation/devicetree/bindings/soc/visconti/toshiba,visconti-dnn.yaml
new file mode 100644
index 0..28576a55e
--- /dev/null
+++ b/Documentation/devicetree/bindings/soc/visconti/toshiba,visconti-dnn.yaml
@@ -0,0 +1,54 @@
+# SPDX-LIcense-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/soc/visconti/toshiba,visconti-dnn.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Toshiba Visconti DNN image processing accelerator
+
+maintainers:
+  - Nobuhiro Iwamatsu 
+
+description: |
+  Toshiba Visconti DNN image processing accelerator.
+  Visconti5 have up to 2 DNN units.
+
+properties:
+  compatible:
+items:
+  - const: toshiba,visconti-dnn
+
+  reg:
+maxItems: 1
+
+  interrupts:
+maxItems: 1
+
+  index:
+enum: [0, 1]
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - index
+
+additionalProperties: false
+
+examples:
+  - |
+#include 
+#include 
+
+soc {
+#address-cells = <2>;
+#size-cells = <2>;
+
+dnn0: dnn@1428 {
+compatible = "toshiba,visconti-dnn";
+reg = <0 0x1428 0 0x8000>;
+interrupts = ;
+index = <0>;
+status = "disabled";
+};
+};
-- 
2.17.1




[PATCH 0/4] Add Toshiba Visconti DNN image processing accelerator driver

2022-04-28 Thread Yuji Ishikawa
This series is the DNN image processing accelerator driver for Toshiba's ARM 
SoC, Visconti[0].
This provides DT binding documentation, device driver, MAINTAINER files.

The second patch "soc: visconti: Add Toshiba Visconti image processing 
accelerator common source"
and the fourth patch "MAINTAINERS: ..." are the same as the ones in the 
preceding post for affine driver.

Best regards,
Yuji

[0]: 
https://toshiba.semicon-storage.com/ap-en/semiconductor/product/image-recognition-processors-visconti.html

Yuji Ishikawa (4):
  dt-bindings: soc: visconti: Add Toshiba Visconti DNN image processing
accelerator bindings
  soc: visconti: Add Toshiba Visconti image processing accelerator
common source
  soc: visconti: Add Toshiba Visconti DNN image processing accelerator
  MAINTAINERS: Add entries for Toshiba Visconti DNN image processing
accelerator

 .../soc/visconti/toshiba,visconti-dnn.yaml|  54 ++
 MAINTAINERS   |   2 +
 drivers/soc/Kconfig   |   1 +
 drivers/soc/Makefile  |   1 +
 drivers/soc/visconti/Kconfig  |   7 +
 drivers/soc/visconti/Makefile |   8 +
 drivers/soc/visconti/dnn/Makefile |   6 +
 drivers/soc/visconti/dnn/dnn.c| 533 ++
 drivers/soc/visconti/dnn/hwd_dnn.c| 183 ++
 drivers/soc/visconti/dnn/hwd_dnn.h|  68 +++
 drivers/soc/visconti/dnn/hwd_dnn_reg.h| 228 
 drivers/soc/visconti/ipa_common.c |  55 ++
 drivers/soc/visconti/ipa_common.h |  18 +
 drivers/soc/visconti/uapi/dnn.h   |  77 +++
 drivers/soc/visconti/uapi/ipa.h   |  88 +++
 15 files changed, 1329 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/soc/visconti/toshiba,visconti-dnn.yaml
 create mode 100644 drivers/soc/visconti/Kconfig
 create mode 100644 drivers/soc/visconti/Makefile
 create mode 100644 drivers/soc/visconti/dnn/Makefile
 create mode 100644 drivers/soc/visconti/dnn/dnn.c
 create mode 100644 drivers/soc/visconti/dnn/hwd_dnn.c
 create mode 100644 drivers/soc/visconti/dnn/hwd_dnn.h
 create mode 100644 drivers/soc/visconti/dnn/hwd_dnn_reg.h
 create mode 100644 drivers/soc/visconti/ipa_common.c
 create mode 100644 drivers/soc/visconti/ipa_common.h
 create mode 100644 drivers/soc/visconti/uapi/dnn.h
 create mode 100644 drivers/soc/visconti/uapi/ipa.h

-- 
2.17.1




[PATCH v2 3/4] soc: visconti: Add Toshiba Visconti AFFINE image processing accelerator

2022-04-27 Thread Yuji Ishikawa
Adds support to AFFINE image processing accelerator on Toshiba Visconti ARM 
SoCs.
This accelerator supoorts affine transform, lens undistortion and LUT transform.

Signed-off-by: Yuji Ishikawa 
Reviewed-by: Nobuhiro Iwamatsu 
---
v1 -> v2:
  - apply checkpatch.pl --strict
  - renamed identifiers; hwd_AFFINE_ to hwd_affine_
---
 drivers/soc/visconti/Kconfig |   6 +
 drivers/soc/visconti/Makefile|   2 +
 drivers/soc/visconti/affine/Makefile |   6 +
 drivers/soc/visconti/affine/affine.c | 451 +++
 drivers/soc/visconti/affine/hwd_affine.c | 206 +
 drivers/soc/visconti/affine/hwd_affine.h |  83 
 drivers/soc/visconti/affine/hwd_affine_reg.h |  45 ++
 drivers/soc/visconti/uapi/affine.h   |  87 
 8 files changed, 886 insertions(+)
 create mode 100644 drivers/soc/visconti/affine/Makefile
 create mode 100644 drivers/soc/visconti/affine/affine.c
 create mode 100644 drivers/soc/visconti/affine/hwd_affine.c
 create mode 100644 drivers/soc/visconti/affine/hwd_affine.h
 create mode 100644 drivers/soc/visconti/affine/hwd_affine_reg.h
 create mode 100644 drivers/soc/visconti/uapi/affine.h

diff --git a/drivers/soc/visconti/Kconfig b/drivers/soc/visconti/Kconfig
index 8b1378917..01583d407 100644
--- a/drivers/soc/visconti/Kconfig
+++ b/drivers/soc/visconti/Kconfig
@@ -1 +1,7 @@
+if ARCH_VISCONTI
+
+config VISCONTI_AFFINE
+bool "Visconti Affine driver"
+
+endif
 
diff --git a/drivers/soc/visconti/Makefile b/drivers/soc/visconti/Makefile
index 8d710da08..b25a726c3 100644
--- a/drivers/soc/visconti/Makefile
+++ b/drivers/soc/visconti/Makefile
@@ -4,3 +4,5 @@
 #
 
 obj-y += ipa_common.o
+
+obj-$(CONFIG_VISCONTI_AFFINE) += affine/
diff --git a/drivers/soc/visconti/affine/Makefile 
b/drivers/soc/visconti/affine/Makefile
new file mode 100644
index 0..82f83b2d6
--- /dev/null
+++ b/drivers/soc/visconti/affine/Makefile
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Makefile for the Visconti AFFINE driver
+#
+
+obj-y += affine.o hwd_affine.o
diff --git a/drivers/soc/visconti/affine/affine.c 
b/drivers/soc/visconti/affine/affine.c
new file mode 100644
index 0..eea045dcf
--- /dev/null
+++ b/drivers/soc/visconti/affine/affine.c
@@ -0,0 +1,451 @@
+// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause
+/* Toshiba Visconti Affine Accelerator Support
+ *
+ * (C) Copyright 2022 TOSHIBA CORPORATION
+ * (C) Copyright 2022 Toshiba Electronic Devices & Storage Corporation
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "hwd_affine.h"
+#include "../ipa_common.h"
+#include "../uapi/affine.h"
+
+struct affine_priv {
+   struct device *dev;
+   struct miscdevice miscdev;
+   struct mutex lock;
+   void __iomem *regs;
+   int irq;
+   wait_queue_head_t waitq;
+   enum drv_ipa_state status;
+   unsigned int hwd_event;
+   unsigned int poll_event;
+   int id;
+   char name[16];
+   bool dma_coherent;
+   struct hwd_affine_status hwd_status;
+
+   struct dma_buf_attachment *dba[DRV_AFFINE_BUFFER_INDEX_MAX];
+   struct sg_table *sgt[DRV_AFFINE_BUFFER_INDEX_MAX];
+   enum dma_data_direction dma_dir[DRV_AFFINE_BUFFER_INDEX_MAX];
+   unsigned int dma_count;
+
+   dma_addr_t buffer_iova[DRV_AFFINE_BUFFER_INDEX_MAX];
+};
+
+static u32 affine_ipa_addr_to_iova(struct affine_priv *priv, struct 
drv_ipa_addr addr)
+{
+   u32 iova = 0;
+
+   if (addr.buffer_index < priv->dma_count &&
+   addr.offset < priv->dba[addr.buffer_index]->dmabuf->size)
+   iova = priv->buffer_iova[addr.buffer_index] + addr.offset;
+   return iova;
+}
+
+static int affine_attach_dma_buf(struct affine_priv *priv, unsigned int 
buffer_index,
+struct drv_ipa_buffer_info *buffer_info)
+{
+   int ret = 0;
+   dma_addr_t addr;
+
+   if (buffer_index >= DRV_AFFINE_BUFFER_INDEX_MAX) {
+   dev_err(priv->dev, "Buffer index invalid: index=%d\n", 
buffer_index);
+   return -EINVAL;
+   }
+
+   switch (buffer_info[buffer_index].direction) {
+   case DRV_IPA_DIR_NONE:
+   priv->dma_dir[priv->dma_count] = DMA_NONE;
+   break;
+   case DRV_IPA_DIR_TO_DEVICE:
+   priv->dma_dir[priv->dma_count] = DMA_TO_DEVICE;
+   break;
+   case DRV_IPA_DIR_FROM_DEVICE:
+   priv->dma_dir[priv->dma_count] = DMA_FROM_DEVICE;
+   break;
+   case DRV_IPA_DIR_BIDIRECTION:
+   priv->dma_dir[priv->dma_count] = DMA_BIDIRECTIONAL;
+   break;
+   default:
+   dev_err(priv->dev, "DMA direction invalid: index=%d dir=%d\n", 
buffer_index,
+   

[PATCH v2 4/4] MAINTAINERS: Add entries for Toshiba Visconti AFFINE image processing accelerator

2022-04-27 Thread Yuji Ishikawa
Signed-off-by: Yuji Ishikawa 
Reviewed-by: Nobuhiro Iwamatsu 
---
 MAINTAINERS | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index dd36acc87..231b2c6f9 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2796,12 +2796,14 @@ F:  
Documentation/devicetree/bindings/net/toshiba,visconti-dwmac.yaml
 F: Documentation/devicetree/bindings/gpio/toshiba,gpio-visconti.yaml
 F: Documentation/devicetree/bindings/pci/toshiba,visconti-pcie.yaml
 F: Documentation/devicetree/bindings/pinctrl/toshiba,visconti-pinctrl.yaml
+F:  Documentation/devicetree/bindings/soc/visconti/
 F: Documentation/devicetree/bindings/watchdog/toshiba,visconti-wdt.yaml
 F: arch/arm64/boot/dts/toshiba/
 F: drivers/net/ethernet/stmicro/stmmac/dwmac-visconti.c
 F: drivers/gpio/gpio-visconti.c
 F: drivers/pci/controller/dwc/pcie-visconti.c
 F: drivers/pinctrl/visconti/
+F: drivers/soc/visconti/
 F: drivers/watchdog/visconti_wdt.c
 N: visconti
 
-- 
2.17.1




[PATCH v2 1/4] dt-bindings: soc: visconti: Add Toshiba Visconti AFFINE image processing accelerator bindings

2022-04-27 Thread Yuji Ishikawa
Adds the Device Tree binding documentation that allows to describe
the AFFINE image processing accelerator found in Toshiba Visconti SoCs.

Signed-off-by: Yuji Ishikawa 
Reviewed-by: Nobuhiro Iwamatsu 
---
 .../soc/visconti/toshiba,visconti-affine.yaml | 53 +++
 1 file changed, 53 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/soc/visconti/toshiba,visconti-affine.yaml

diff --git 
a/Documentation/devicetree/bindings/soc/visconti/toshiba,visconti-affine.yaml 
b/Documentation/devicetree/bindings/soc/visconti/toshiba,visconti-affine.yaml
new file mode 100644
index 0..a446e1c4f
--- /dev/null
+++ 
b/Documentation/devicetree/bindings/soc/visconti/toshiba,visconti-affine.yaml
@@ -0,0 +1,53 @@
+# SPDX-LIcense-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/soc/visconti/toshiba,visconti-affine.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Toshiba Visconti AFFINE image processing accelerator
+
+maintainers:
+  - Nobuhiro Iwamatsu 
+
+description: |
+  Toshiba Visconti AFFINE image processing accelerator provides affine 
transform, lens undistortion and LUT transform.
+  Visconti5 have up to 2 AFFINE units.
+
+properties:
+  compatible:
+items:
+  - const: toshiba,visconti-affine
+
+  reg:
+maxItems: 1
+
+  interrupts:
+maxItems: 1
+
+  index:
+enum: [0, 1]
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - index
+
+additionalProperties: false
+
+examples:
+  - |
+#include 
+#include 
+
+soc {
+#address-cells = <2>;
+#size-cells = <2>;
+affine0: affine@1400 {
+compatible = "toshiba,visconti-affine";
+reg = <0 0x1400 0 0x8000>;
+interrupts = ;
+index = <0>;
+status = "disabled";
+};
+};
-- 
2.17.1




[PATCH v2 2/4] soc: visconti: Add Toshiba Visconti image processing accelerator common source

2022-04-27 Thread Yuji Ishikawa
Adds common operations for image processing accelerator drivers
including dma-buf control and ioctl definitiion

Signed-off-by: Yuji Ishikawa 
Reviewed-by: Nobuhiro Iwamatsu 
---
v1 -> v2:
  - apply checkpatch.pl --strict
---
 drivers/soc/Kconfig   |  1 +
 drivers/soc/Makefile  |  1 +
 drivers/soc/visconti/Kconfig  |  1 +
 drivers/soc/visconti/Makefile |  6 +++
 drivers/soc/visconti/ipa_common.c | 55 +++
 drivers/soc/visconti/ipa_common.h | 18 +++
 drivers/soc/visconti/uapi/ipa.h   | 88 +++
 7 files changed, 170 insertions(+)
 create mode 100644 drivers/soc/visconti/Kconfig
 create mode 100644 drivers/soc/visconti/Makefile
 create mode 100644 drivers/soc/visconti/ipa_common.c
 create mode 100644 drivers/soc/visconti/ipa_common.h
 create mode 100644 drivers/soc/visconti/uapi/ipa.h

diff --git a/drivers/soc/Kconfig b/drivers/soc/Kconfig
index e8a30c4c5..c99139aa8 100644
--- a/drivers/soc/Kconfig
+++ b/drivers/soc/Kconfig
@@ -22,6 +22,7 @@ source "drivers/soc/tegra/Kconfig"
 source "drivers/soc/ti/Kconfig"
 source "drivers/soc/ux500/Kconfig"
 source "drivers/soc/versatile/Kconfig"
+source "drivers/soc/visconti/Kconfig"
 source "drivers/soc/xilinx/Kconfig"
 
 endmenu
diff --git a/drivers/soc/Makefile b/drivers/soc/Makefile
index a05e9fbcd..455b993c2 100644
--- a/drivers/soc/Makefile
+++ b/drivers/soc/Makefile
@@ -28,4 +28,5 @@ obj-$(CONFIG_ARCH_TEGRA)  += tegra/
 obj-y  += ti/
 obj-$(CONFIG_ARCH_U8500)   += ux500/
 obj-$(CONFIG_PLAT_VERSATILE)   += versatile/
+obj-$(CONFIG_ARCH_VISCONTI)+= visconti/
 obj-y  += xilinx/
diff --git a/drivers/soc/visconti/Kconfig b/drivers/soc/visconti/Kconfig
new file mode 100644
index 0..8b1378917
--- /dev/null
+++ b/drivers/soc/visconti/Kconfig
@@ -0,0 +1 @@
+
diff --git a/drivers/soc/visconti/Makefile b/drivers/soc/visconti/Makefile
new file mode 100644
index 0..8d710da08
--- /dev/null
+++ b/drivers/soc/visconti/Makefile
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Makefile for the Visconti specific device drivers.
+#
+
+obj-y += ipa_common.o
diff --git a/drivers/soc/visconti/ipa_common.c 
b/drivers/soc/visconti/ipa_common.c
new file mode 100644
index 0..6345f33c5
--- /dev/null
+++ b/drivers/soc/visconti/ipa_common.c
@@ -0,0 +1,55 @@
+// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause
+/* Toshiba Visconti Image Processing Accelerator Support
+ *
+ * (C) Copyright 2022 TOSHIBA CORPORATION
+ * (C) Copyright 2022 Toshiba Electronic Devices & Storage Corporation
+ */
+
+#include "ipa_common.h"
+
+int ipa_attach_dmabuf(struct device *dev, int fd, struct dma_buf_attachment 
**a,
+ struct sg_table **s, dma_addr_t *addr, enum 
dma_data_direction dma_dir)
+{
+   struct dma_buf_attachment *attachment;
+   struct dma_buf *dmabuf;
+   struct sg_table *sgt;
+   int ret;
+
+   dmabuf = dma_buf_get(fd);
+   if (IS_ERR(dmabuf)) {
+   dev_err(dev, "Invalid dmabuf FD\n");
+   return PTR_ERR(dmabuf);
+   }
+   attachment = dma_buf_attach(dmabuf, dev);
+
+   if (IS_ERR(attachment)) {
+   dev_err(dev, "Failed to attach dmabuf\n");
+   ret = PTR_ERR(attachment);
+   goto err_put;
+   }
+   sgt = dma_buf_map_attachment(attachment, dma_dir);
+   if (IS_ERR(sgt)) {
+   dev_err(dev, "Failed to get dmabufs sg_table\n");
+   ret = PTR_ERR(sgt);
+   goto err_detach;
+   }
+   if (sgt->nents != 1) {
+   dev_err(dev, "Sparse DMA region is unsupported\n");
+   ret = -EINVAL;
+   goto err_unmap;
+   }
+
+   *addr = sg_dma_address(sgt->sgl);
+   *a = attachment;
+   *s = sgt;
+
+   return 0;
+
+err_unmap:
+   dma_buf_unmap_attachment(attachment, sgt, dma_dir);
+err_detach:
+   dma_buf_detach(dmabuf, attachment);
+err_put:
+   dma_buf_put(dmabuf);
+   return ret;
+}
diff --git a/drivers/soc/visconti/ipa_common.h 
b/drivers/soc/visconti/ipa_common.h
new file mode 100644
index 0..786988c52
--- /dev/null
+++ b/drivers/soc/visconti/ipa_common.h
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause */
+/* Toshiba Visconti Image Processing Accelerator Support
+ *
+ * (C) Copyright 2022 TOSHIBA CORPORATION
+ * (C) Copyright 2022 Toshiba Electronic Devices & Storage Corporation
+ */
+
+#include 
+#include 
+
+#define COHERENT_ADDRESS_BIT   (0x4ULL)
+#define IPA_POLL_EVENT_NONE(0)
+#define IPA_POLL_EVENT_DONE(1)
+#define IPA_POLL_EVENT_ERROR   (2)
+#define IPA_WAKEUP_RETRY_DELAY (300 * 1000) /*usec*/
+
+int ipa_attach_dmabuf(struct device *dev, int fd, struct dma_buf_attachment 
**a,
+ struct sg_table **s, dma_addr_t *a

[PATCH v2 0/4] Add Toshiba Visconti AFFINE image processing accelerator driver

2022-04-27 Thread Yuji Ishikawa
This series is the AFFINE image processing accelerator driver for Toshiba's ARM 
SoC, Visconti[0].
This provides DT binding documentation, device driver, MAINTAINER files.

The second patch "soc: visconti: Add Toshiba Visconti image processing 
accelerator common source"
is commonly used among acclerator drivers (affine, dnn, dspif, pyramid).

Best regards,
Yuji

[0]: 
https://toshiba.semicon-storage.com/ap-en/semiconductor/product/image-recognition-processors-visconti.html
  
  dt-bindings: soc: visconti: Add Toshiba Visconti AFFINE image
v1 -> v2:
  - No update

  soc: visconti: Add Toshiba Visconti image processing accelerator common source
v1 -> v2:
  - apply checkpatch.pl --strict
  
  soc: visconti: Add Toshiba Visconti AFFINE image processing accelerator
v1 -> v2:
  - apply checkpatch.pl --strict
  - rename hwd_AFFINE_ to hwd_affine_

  MAINTAINERS: Add entries for Toshiba Visconti AFFINE image processing 
accelerator
v1 -> v2:
  - No update

Change in V2:
  - apply checkpatch.pl --strict
  - rename hwd_AFFINE_xxxx to hwd_affine_

Yuji Ishikawa (4):
  dt-bindings: soc: visconti: Add Toshiba Visconti AFFINE image
processing accelerator bindings
  soc: visconti: Add Toshiba Visconti image processing accelerator
common source
  soc: visconti: Add Toshiba Visconti AFFINE image processing
accelerator
  MAINTAINERS: Add entries for Toshiba Visconti AFFINE image processing
accelerator

 .../soc/visconti/toshiba,visconti-affine.yaml |  53 ++
 MAINTAINERS   |   2 +
 drivers/soc/Kconfig   |   1 +
 drivers/soc/Makefile  |   1 +
 drivers/soc/visconti/Kconfig  |   7 +
 drivers/soc/visconti/Makefile |   8 +
 drivers/soc/visconti/affine/Makefile  |   6 +
 drivers/soc/visconti/affine/affine.c  | 451 ++
 drivers/soc/visconti/affine/hwd_affine.c  | 206 
 drivers/soc/visconti/affine/hwd_affine.h  |  83 
 drivers/soc/visconti/affine/hwd_affine_reg.h  |  45 ++
 drivers/soc/visconti/ipa_common.c |  55 +++
 drivers/soc/visconti/ipa_common.h |  18 +
 drivers/soc/visconti/uapi/affine.h|  87 
 drivers/soc/visconti/uapi/ipa.h   |  88 
 15 files changed,  insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/soc/visconti/toshiba,visconti-affine.yaml
 create mode 100644 drivers/soc/visconti/Kconfig
 create mode 100644 drivers/soc/visconti/Makefile
 create mode 100644 drivers/soc/visconti/affine/Makefile
 create mode 100644 drivers/soc/visconti/affine/affine.c
 create mode 100644 drivers/soc/visconti/affine/hwd_affine.c
 create mode 100644 drivers/soc/visconti/affine/hwd_affine.h
 create mode 100644 drivers/soc/visconti/affine/hwd_affine_reg.h
 create mode 100644 drivers/soc/visconti/ipa_common.c
 create mode 100644 drivers/soc/visconti/ipa_common.h
 create mode 100644 drivers/soc/visconti/uapi/affine.h
 create mode 100644 drivers/soc/visconti/uapi/ipa.h

-- 
2.17.1




[PATCH 3/4] soc: visconti: Add Toshiba Visconti AFFINE image processing accelerator

2022-04-19 Thread Yuji Ishikawa
Adds support to AFFINE image processing accelerator on Toshiba Visconti ARM 
SoCs.
This accelerator supoorts affine transform, lens undistortion and LUT transform.

Signed-off-by: Yuji Ishikawa 
Reviewed-by: Nobuhiro Iwamatsu 
---
 drivers/soc/visconti/Kconfig |   6 +
 drivers/soc/visconti/Makefile|   2 +
 drivers/soc/visconti/affine/Makefile |   6 +
 drivers/soc/visconti/affine/affine.c | 451 +++
 drivers/soc/visconti/affine/hwd_affine.c | 207 +
 drivers/soc/visconti/affine/hwd_affine.h |  83 
 drivers/soc/visconti/affine/hwd_affine_reg.h |  45 ++
 drivers/soc/visconti/uapi/affine.h   |  87 
 8 files changed, 887 insertions(+)
 create mode 100644 drivers/soc/visconti/affine/Makefile
 create mode 100644 drivers/soc/visconti/affine/affine.c
 create mode 100644 drivers/soc/visconti/affine/hwd_affine.c
 create mode 100644 drivers/soc/visconti/affine/hwd_affine.h
 create mode 100644 drivers/soc/visconti/affine/hwd_affine_reg.h
 create mode 100644 drivers/soc/visconti/uapi/affine.h

diff --git a/drivers/soc/visconti/Kconfig b/drivers/soc/visconti/Kconfig
index 8b1378917..01583d407 100644
--- a/drivers/soc/visconti/Kconfig
+++ b/drivers/soc/visconti/Kconfig
@@ -1 +1,7 @@
+if ARCH_VISCONTI
+
+config VISCONTI_AFFINE
+bool "Visconti Affine driver"
+
+endif
 
diff --git a/drivers/soc/visconti/Makefile b/drivers/soc/visconti/Makefile
index 8d710da08..b25a726c3 100644
--- a/drivers/soc/visconti/Makefile
+++ b/drivers/soc/visconti/Makefile
@@ -4,3 +4,5 @@
 #
 
 obj-y += ipa_common.o
+
+obj-$(CONFIG_VISCONTI_AFFINE) += affine/
diff --git a/drivers/soc/visconti/affine/Makefile 
b/drivers/soc/visconti/affine/Makefile
new file mode 100644
index 0..82f83b2d6
--- /dev/null
+++ b/drivers/soc/visconti/affine/Makefile
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Makefile for the Visconti AFFINE driver
+#
+
+obj-y += affine.o hwd_affine.o
diff --git a/drivers/soc/visconti/affine/affine.c 
b/drivers/soc/visconti/affine/affine.c
new file mode 100644
index 0..3b31e41c8
--- /dev/null
+++ b/drivers/soc/visconti/affine/affine.c
@@ -0,0 +1,451 @@
+// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause
+/* Toshiba Visconti Affine Accelerator Support
+ *
+ * (C) Copyright 2022 TOSHIBA CORPORATION
+ * (C) Copyright 2022 Toshiba Electronic Devices & Storage Corporation
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "hwd_affine.h"
+#include "../ipa_common.h"
+#include "../uapi/affine.h"
+
+struct affine_priv {
+   struct device *dev;
+   struct miscdevice miscdev;
+   struct mutex lock;
+   void __iomem *regs;
+   int irq;
+   wait_queue_head_t waitq;
+   enum drv_ipa_state status;
+   unsigned int hwd_event;
+   unsigned int poll_event;
+   int id;
+   char name[16];
+   bool dma_coherent;
+   struct hwd_affine_status hwd_status;
+
+   struct dma_buf_attachment *dba[DRV_AFFINE_BUFFER_INDEX_MAX];
+   struct sg_table *sgt[DRV_AFFINE_BUFFER_INDEX_MAX];
+   enum dma_data_direction dma_dir[DRV_AFFINE_BUFFER_INDEX_MAX];
+   unsigned int dma_count;
+
+   dma_addr_t buffer_iova[DRV_AFFINE_BUFFER_INDEX_MAX];
+};
+
+static uint32_t affine_ipa_addr_to_iova(struct affine_priv *priv, struct 
drv_ipa_addr addr)
+{
+   uint32_t iova = 0;
+
+   if ((addr.buffer_index < priv->dma_count) &&
+   (addr.offset < priv->dba[addr.buffer_index]->dmabuf->size))
+   iova = priv->buffer_iova[addr.buffer_index] + addr.offset;
+   return iova;
+}
+
+static int affine_attach_dma_buf(struct affine_priv *priv, unsigned int 
buffer_index,
+struct drv_ipa_buffer_info *buffer_info)
+{
+   int ret = 0;
+   dma_addr_t addr;
+
+   if (buffer_index >= DRV_AFFINE_BUFFER_INDEX_MAX) {
+   dev_err(priv->dev, "Buffer index invalid: index=%d\n", 
buffer_index);
+   return -EINVAL;
+   }
+
+   switch (buffer_info[buffer_index].direction) {
+   case DRV_IPA_DIR_NONE:
+   priv->dma_dir[priv->dma_count] = DMA_NONE;
+   break;
+   case DRV_IPA_DIR_TO_DEVICE:
+   priv->dma_dir[priv->dma_count] = DMA_TO_DEVICE;
+   break;
+   case DRV_IPA_DIR_FROM_DEVICE:
+   priv->dma_dir[priv->dma_count] = DMA_FROM_DEVICE;
+   break;
+   case DRV_IPA_DIR_BIDIRECTION:
+   priv->dma_dir[priv->dma_count] = DMA_BIDIRECTIONAL;
+   break;
+   default:
+   dev_err(priv->dev, "DMA direction invalid: index=%d dir=%d\n", 
buffer_index,
+   buffer_info[buffer_index].direction);
+   return -EINVAL;
+   }
+
+   if (buffer_i

[PATCH 1/4] dt-bindings: soc: visconti: Add Toshiba Visconti AFFINE image processing accelerator bindings

2022-04-19 Thread Yuji Ishikawa
Adds the Device Tree binding documentation that allows to describe
the AFFINE image processing accelerator found in Toshiba Visconti SoCs.

Signed-off-by: Yuji Ishikawa 
Reviewed-by: Nobuhiro Iwamatsu 
---
 .../soc/visconti/toshiba,visconti-affine.yaml | 53 +++
 1 file changed, 53 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/soc/visconti/toshiba,visconti-affine.yaml

diff --git 
a/Documentation/devicetree/bindings/soc/visconti/toshiba,visconti-affine.yaml 
b/Documentation/devicetree/bindings/soc/visconti/toshiba,visconti-affine.yaml
new file mode 100644
index 0..a446e1c4f
--- /dev/null
+++ 
b/Documentation/devicetree/bindings/soc/visconti/toshiba,visconti-affine.yaml
@@ -0,0 +1,53 @@
+# SPDX-LIcense-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/soc/visconti/toshiba,visconti-affine.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Toshiba Visconti AFFINE image processing accelerator
+
+maintainers:
+  - Nobuhiro Iwamatsu 
+
+description: |
+  Toshiba Visconti AFFINE image processing accelerator provides affine 
transform, lens undistortion and LUT transform.
+  Visconti5 have up to 2 AFFINE units.
+
+properties:
+  compatible:
+items:
+  - const: toshiba,visconti-affine
+
+  reg:
+maxItems: 1
+
+  interrupts:
+maxItems: 1
+
+  index:
+enum: [0, 1]
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - index
+
+additionalProperties: false
+
+examples:
+  - |
+#include 
+#include 
+
+soc {
+#address-cells = <2>;
+#size-cells = <2>;
+affine0: affine@1400 {
+compatible = "toshiba,visconti-affine";
+reg = <0 0x1400 0 0x8000>;
+interrupts = ;
+index = <0>;
+status = "disabled";
+};
+};
-- 
2.17.1




[PATCH 0/4] Add Toshiba Visconti AFFINE image processing accelerator driver

2022-04-19 Thread Yuji Ishikawa
This series is the AFFINE image processing accelerator driver for Toshiba's ARM 
SoC, Visconti[0].
This provides DT binding documentation, device driver, MAINTAINER files.

Best regards,
Yuji

[0]: 
https://toshiba.semicon-storage.com/ap-en/semiconductor/product/image-recognition-processors-visconti.html

Yuji Ishikawa (4):
  dt-bindings: soc: visconti: Add Toshiba Visconti AFFINE image
processing accelerator bindings
  soc: visconti: Add Toshiba Visconti image processing accelerator
common source
  soc: visconti: Add Toshiba Visconti AFFINE image processing
accelerator
  MAINTAINERS: Add entries for Toshiba Visconti AFFINE image processing
accelerator

 .../soc/visconti/toshiba,visconti-affine.yaml |  53 ++
 MAINTAINERS   |   2 +
 drivers/soc/Kconfig   |   1 +
 drivers/soc/Makefile  |   1 +
 drivers/soc/visconti/Kconfig  |   7 +
 drivers/soc/visconti/Makefile |   8 +
 drivers/soc/visconti/affine/Makefile  |   6 +
 drivers/soc/visconti/affine/affine.c  | 451 ++
 drivers/soc/visconti/affine/hwd_affine.c  | 207 
 drivers/soc/visconti/affine/hwd_affine.h  |  83 
 drivers/soc/visconti/affine/hwd_affine_reg.h  |  45 ++
 drivers/soc/visconti/ipa_common.c |  55 +++
 drivers/soc/visconti/ipa_common.h |  19 +
 drivers/soc/visconti/uapi/affine.h|  87 
 drivers/soc/visconti/uapi/ipa.h   |  87 
 15 files changed, 1112 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/soc/visconti/toshiba,visconti-affine.yaml
 create mode 100644 drivers/soc/visconti/Kconfig
 create mode 100644 drivers/soc/visconti/Makefile
 create mode 100644 drivers/soc/visconti/affine/Makefile
 create mode 100644 drivers/soc/visconti/affine/affine.c
 create mode 100644 drivers/soc/visconti/affine/hwd_affine.c
 create mode 100644 drivers/soc/visconti/affine/hwd_affine.h
 create mode 100644 drivers/soc/visconti/affine/hwd_affine_reg.h
 create mode 100644 drivers/soc/visconti/ipa_common.c
 create mode 100644 drivers/soc/visconti/ipa_common.h
 create mode 100644 drivers/soc/visconti/uapi/affine.h
 create mode 100644 drivers/soc/visconti/uapi/ipa.h

-- 
2.17.1




[PATCH 4/4] MAINTAINERS: Add entries for Toshiba Visconti AFFINE image processing accelerator

2022-04-19 Thread Yuji Ishikawa
Signed-off-by: Yuji Ishikawa 
Reviewed-by: Nobuhiro Iwamatsu 
---
 MAINTAINERS | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index dd36acc87..231b2c6f9 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2796,12 +2796,14 @@ F:  
Documentation/devicetree/bindings/net/toshiba,visconti-dwmac.yaml
 F: Documentation/devicetree/bindings/gpio/toshiba,gpio-visconti.yaml
 F: Documentation/devicetree/bindings/pci/toshiba,visconti-pcie.yaml
 F: Documentation/devicetree/bindings/pinctrl/toshiba,visconti-pinctrl.yaml
+F:  Documentation/devicetree/bindings/soc/visconti/
 F: Documentation/devicetree/bindings/watchdog/toshiba,visconti-wdt.yaml
 F: arch/arm64/boot/dts/toshiba/
 F: drivers/net/ethernet/stmicro/stmmac/dwmac-visconti.c
 F: drivers/gpio/gpio-visconti.c
 F: drivers/pci/controller/dwc/pcie-visconti.c
 F: drivers/pinctrl/visconti/
+F: drivers/soc/visconti/
 F: drivers/watchdog/visconti_wdt.c
 N: visconti
 
-- 
2.17.1




[PATCH 2/4] soc: visconti: Add Toshiba Visconti image processing accelerator common source

2022-04-19 Thread Yuji Ishikawa
Adds common operations for image processing accelerator drivers
including dma-buf control and ioctl definitiion

Signed-off-by: Yuji Ishikawa 
Reviewed-by: Nobuhiro Iwamatsu 
---
 drivers/soc/Kconfig   |  1 +
 drivers/soc/Makefile  |  1 +
 drivers/soc/visconti/Kconfig  |  1 +
 drivers/soc/visconti/Makefile |  6 +++
 drivers/soc/visconti/ipa_common.c | 55 +++
 drivers/soc/visconti/ipa_common.h | 19 +++
 drivers/soc/visconti/uapi/ipa.h   | 87 +++
 7 files changed, 170 insertions(+)
 create mode 100644 drivers/soc/visconti/Kconfig
 create mode 100644 drivers/soc/visconti/Makefile
 create mode 100644 drivers/soc/visconti/ipa_common.c
 create mode 100644 drivers/soc/visconti/ipa_common.h
 create mode 100644 drivers/soc/visconti/uapi/ipa.h

diff --git a/drivers/soc/Kconfig b/drivers/soc/Kconfig
index e8a30c4c5..c99139aa8 100644
--- a/drivers/soc/Kconfig
+++ b/drivers/soc/Kconfig
@@ -22,6 +22,7 @@ source "drivers/soc/tegra/Kconfig"
 source "drivers/soc/ti/Kconfig"
 source "drivers/soc/ux500/Kconfig"
 source "drivers/soc/versatile/Kconfig"
+source "drivers/soc/visconti/Kconfig"
 source "drivers/soc/xilinx/Kconfig"
 
 endmenu
diff --git a/drivers/soc/Makefile b/drivers/soc/Makefile
index a05e9fbcd..455b993c2 100644
--- a/drivers/soc/Makefile
+++ b/drivers/soc/Makefile
@@ -28,4 +28,5 @@ obj-$(CONFIG_ARCH_TEGRA)  += tegra/
 obj-y  += ti/
 obj-$(CONFIG_ARCH_U8500)   += ux500/
 obj-$(CONFIG_PLAT_VERSATILE)   += versatile/
+obj-$(CONFIG_ARCH_VISCONTI)+= visconti/
 obj-y  += xilinx/
diff --git a/drivers/soc/visconti/Kconfig b/drivers/soc/visconti/Kconfig
new file mode 100644
index 0..8b1378917
--- /dev/null
+++ b/drivers/soc/visconti/Kconfig
@@ -0,0 +1 @@
+
diff --git a/drivers/soc/visconti/Makefile b/drivers/soc/visconti/Makefile
new file mode 100644
index 0..8d710da08
--- /dev/null
+++ b/drivers/soc/visconti/Makefile
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Makefile for the Visconti specific device drivers.
+#
+
+obj-y += ipa_common.o
diff --git a/drivers/soc/visconti/ipa_common.c 
b/drivers/soc/visconti/ipa_common.c
new file mode 100644
index 0..6345f33c5
--- /dev/null
+++ b/drivers/soc/visconti/ipa_common.c
@@ -0,0 +1,55 @@
+// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause
+/* Toshiba Visconti Image Processing Accelerator Support
+ *
+ * (C) Copyright 2022 TOSHIBA CORPORATION
+ * (C) Copyright 2022 Toshiba Electronic Devices & Storage Corporation
+ */
+
+#include "ipa_common.h"
+
+int ipa_attach_dmabuf(struct device *dev, int fd, struct dma_buf_attachment 
**a,
+ struct sg_table **s, dma_addr_t *addr, enum 
dma_data_direction dma_dir)
+{
+   struct dma_buf_attachment *attachment;
+   struct dma_buf *dmabuf;
+   struct sg_table *sgt;
+   int ret;
+
+   dmabuf = dma_buf_get(fd);
+   if (IS_ERR(dmabuf)) {
+   dev_err(dev, "Invalid dmabuf FD\n");
+   return PTR_ERR(dmabuf);
+   }
+   attachment = dma_buf_attach(dmabuf, dev);
+
+   if (IS_ERR(attachment)) {
+   dev_err(dev, "Failed to attach dmabuf\n");
+   ret = PTR_ERR(attachment);
+   goto err_put;
+   }
+   sgt = dma_buf_map_attachment(attachment, dma_dir);
+   if (IS_ERR(sgt)) {
+   dev_err(dev, "Failed to get dmabufs sg_table\n");
+   ret = PTR_ERR(sgt);
+   goto err_detach;
+   }
+   if (sgt->nents != 1) {
+   dev_err(dev, "Sparse DMA region is unsupported\n");
+   ret = -EINVAL;
+   goto err_unmap;
+   }
+
+   *addr = sg_dma_address(sgt->sgl);
+   *a = attachment;
+   *s = sgt;
+
+   return 0;
+
+err_unmap:
+   dma_buf_unmap_attachment(attachment, sgt, dma_dir);
+err_detach:
+   dma_buf_detach(dmabuf, attachment);
+err_put:
+   dma_buf_put(dmabuf);
+   return ret;
+}
diff --git a/drivers/soc/visconti/ipa_common.h 
b/drivers/soc/visconti/ipa_common.h
new file mode 100644
index 0..2c3b64837
--- /dev/null
+++ b/drivers/soc/visconti/ipa_common.h
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause */
+/* Toshiba Visconti Image Processing Accelerator Support
+ *
+ * (C) Copyright 2022 TOSHIBA CORPORATION
+ * (C) Copyright 2022 Toshiba Electronic Devices & Storage Corporation
+ */
+
+#include 
+#include 
+
+#define COHERENT_ADDRESS_BIT   (0x4ULL)
+#define IPA_POLL_EVENT_NONE(0)
+#define IPA_POLL_EVENT_DONE(1)
+#define IPA_POLL_EVENT_ERROR   (2)
+#define IPA_WAKEUP_RETRY_DELAY (300 * 1000) /*usec*/
+
+extern int ipa_attach_dmabuf(struct device *dev, int fd, struct 
dma_buf_attachment **a,
+struct sg_table **s, dma_addr_t *addr,
+en