Re: [PATCH v5 1/7] accel/ivpu: Introduce a new DRM driver for Intel VPU

2023-01-13 Thread Jeffrey Hugo

On 1/13/2023 1:23 AM, Jacek Lawrynowicz wrote:

Hi,

On 12.01.2023 18:34, Jeffrey Hugo wrote:

On 1/9/2023 5:23 AM, Jacek Lawrynowicz wrote:

VPU stands for Versatile Processing Unit and it's a CPU-integrated
inference accelerator for Computer Vision and Deep Learning
applications.

The VPU device consist of following components:
    - Buttress - provides CPU to VPU integration, interrupt, frequency and
  power management.
    - Memory Management Unit (based on ARM MMU-600) - translates VPU to
  host DMA addresses, isolates user workloads.
    - RISC based microcontroller - executes firmware that provides job
  execution API for the kernel-mode driver
    - Neural Compute Subsystem (NCS) - does the actual work, provides
  Compute and Copy engines.
    - Network on Chip (NoC) - network fabric connecting all the components

This driver supports VPU IP v2.7 integrated into Intel Meteor Lake
client CPUs (14th generation).

Module sources are at drivers/accel/ivpu and module name is
"intel_vpu.ko".

This patch includes only very besic functionality:
    - module, PCI device and IRQ initialization
    - register definitions and low level register manipulation functions
    - SET/GET_PARAM ioctls
    - power up without firmware

Co-developed-by: Krystian Pradzynski 
Signed-off-by: Krystian Pradzynski 
Signed-off-by: Jacek Lawrynowicz 


Reviewed-by: Jeffrey Hugo 


+static const struct file_operations ivpu_fops = {
+    .owner    = THIS_MODULE,
+    .open    = accel_open,
+    .release    = drm_release,
+    .unlocked_ioctl    = drm_ioctl,
+    .compat_ioctl    = drm_compat_ioctl,
+    .poll    = drm_poll,
+    .read    = drm_read,
+    .llseek    = noop_llseek,
+    .mmap   = drm_gem_mmap
+};


Hmm DEFINE_DRM_ACCEL_FOPS is not usable here because it doesn't define .mmap
Feels like we should fix that and then simplify this.  Seems like a good todo 
item.


I think this should rather be on accel/drm TODO and not ivpu TODO list.
For the moment I can simplify the code to this:
static const struct file_operations ivpu_fops = {
.owner  = THIS_MODULE,
.mmap   = drm_gem_mmap,
DRM_ACCEL_FOPS,
};

Still not perfect but nicer.

Regards,
Jacek



Yep, it looked like you could do that simplification but it didn't seem 
worth it to spin a v6 for this.  However since you seem to be planning a 
v6 anyways, rolling in this simplification would be nice.


Also, I'm sorry, I didn't mean to imply that the DEFINE_DRM_ACCEL_FOPS 
in on the ivpu todo.  I was thinking more in general terms.


Actually, I'll take that up and post a patch next week.  We'll see what 
the reaction is.  I don't intend for it to be a dependency for you. 
Feels like a quick thing to get done so it is not something the next 
person trips over (probably me) and we can link up all the pieces when 
both FOPS and ivpu are available.


-Jeff


Re: [PATCH v5 1/7] accel/ivpu: Introduce a new DRM driver for Intel VPU

2023-01-13 Thread Jacek Lawrynowicz
Hi,

On 12.01.2023 18:34, Jeffrey Hugo wrote:
> On 1/9/2023 5:23 AM, Jacek Lawrynowicz wrote:
>> VPU stands for Versatile Processing Unit and it's a CPU-integrated
>> inference accelerator for Computer Vision and Deep Learning
>> applications.
>>
>> The VPU device consist of following components:
>>    - Buttress - provides CPU to VPU integration, interrupt, frequency and
>>  power management.
>>    - Memory Management Unit (based on ARM MMU-600) - translates VPU to
>>  host DMA addresses, isolates user workloads.
>>    - RISC based microcontroller - executes firmware that provides job
>>  execution API for the kernel-mode driver
>>    - Neural Compute Subsystem (NCS) - does the actual work, provides
>>  Compute and Copy engines.
>>    - Network on Chip (NoC) - network fabric connecting all the components
>>
>> This driver supports VPU IP v2.7 integrated into Intel Meteor Lake
>> client CPUs (14th generation).
>>
>> Module sources are at drivers/accel/ivpu and module name is
>> "intel_vpu.ko".
>>
>> This patch includes only very besic functionality:
>>    - module, PCI device and IRQ initialization
>>    - register definitions and low level register manipulation functions
>>    - SET/GET_PARAM ioctls
>>    - power up without firmware
>>
>> Co-developed-by: Krystian Pradzynski 
>> Signed-off-by: Krystian Pradzynski 
>> Signed-off-by: Jacek Lawrynowicz 
> 
> Reviewed-by: Jeffrey Hugo 
> 
>> +static const struct file_operations ivpu_fops = {
>> +    .owner    = THIS_MODULE,
>> +    .open    = accel_open,
>> +    .release    = drm_release,
>> +    .unlocked_ioctl    = drm_ioctl,
>> +    .compat_ioctl    = drm_compat_ioctl,
>> +    .poll    = drm_poll,
>> +    .read    = drm_read,
>> +    .llseek    = noop_llseek,
>> +    .mmap   = drm_gem_mmap
>> +};
> 
> Hmm DEFINE_DRM_ACCEL_FOPS is not usable here because it doesn't define .mmap
> Feels like we should fix that and then simplify this.  Seems like a good todo 
> item.

I think this should rather be on accel/drm TODO and not ivpu TODO list.
For the moment I can simplify the code to this:
static const struct file_operations ivpu_fops = {
.owner  = THIS_MODULE,
.mmap   = drm_gem_mmap,
DRM_ACCEL_FOPS,
};

Still not perfect but nicer.

Regards,
Jacek



Re: [PATCH v5 1/7] accel/ivpu: Introduce a new DRM driver for Intel VPU

2023-01-12 Thread Jeffrey Hugo

On 1/9/2023 5:23 AM, Jacek Lawrynowicz wrote:

VPU stands for Versatile Processing Unit and it's a CPU-integrated
inference accelerator for Computer Vision and Deep Learning
applications.

The VPU device consist of following components:
   - Buttress - provides CPU to VPU integration, interrupt, frequency and
 power management.
   - Memory Management Unit (based on ARM MMU-600) - translates VPU to
 host DMA addresses, isolates user workloads.
   - RISC based microcontroller - executes firmware that provides job
 execution API for the kernel-mode driver
   - Neural Compute Subsystem (NCS) - does the actual work, provides
 Compute and Copy engines.
   - Network on Chip (NoC) - network fabric connecting all the components

This driver supports VPU IP v2.7 integrated into Intel Meteor Lake
client CPUs (14th generation).

Module sources are at drivers/accel/ivpu and module name is
"intel_vpu.ko".

This patch includes only very besic functionality:
   - module, PCI device and IRQ initialization
   - register definitions and low level register manipulation functions
   - SET/GET_PARAM ioctls
   - power up without firmware

Co-developed-by: Krystian Pradzynski 
Signed-off-by: Krystian Pradzynski 
Signed-off-by: Jacek Lawrynowicz 


Reviewed-by: Jeffrey Hugo 


+static const struct file_operations ivpu_fops = {
+   .owner  = THIS_MODULE,
+   .open   = accel_open,
+   .release= drm_release,
+   .unlocked_ioctl = drm_ioctl,
+   .compat_ioctl   = drm_compat_ioctl,
+   .poll   = drm_poll,
+   .read   = drm_read,
+   .llseek = noop_llseek,
+   .mmap   = drm_gem_mmap
+};


Hmm DEFINE_DRM_ACCEL_FOPS is not usable here because it doesn't define .mmap
Feels like we should fix that and then simplify this.  Seems like a good 
todo item.




[PATCH v5 1/7] accel/ivpu: Introduce a new DRM driver for Intel VPU

2023-01-09 Thread Jacek Lawrynowicz
VPU stands for Versatile Processing Unit and it's a CPU-integrated
inference accelerator for Computer Vision and Deep Learning
applications.

The VPU device consist of following components:
  - Buttress - provides CPU to VPU integration, interrupt, frequency and
power management.
  - Memory Management Unit (based on ARM MMU-600) - translates VPU to
host DMA addresses, isolates user workloads.
  - RISC based microcontroller - executes firmware that provides job
execution API for the kernel-mode driver
  - Neural Compute Subsystem (NCS) - does the actual work, provides
Compute and Copy engines.
  - Network on Chip (NoC) - network fabric connecting all the components

This driver supports VPU IP v2.7 integrated into Intel Meteor Lake
client CPUs (14th generation).

Module sources are at drivers/accel/ivpu and module name is
"intel_vpu.ko".

This patch includes only very besic functionality:
  - module, PCI device and IRQ initialization
  - register definitions and low level register manipulation functions
  - SET/GET_PARAM ioctls
  - power up without firmware

Co-developed-by: Krystian Pradzynski 
Signed-off-by: Krystian Pradzynski 
Signed-off-by: Jacek Lawrynowicz 
---
 MAINTAINERS  |9 +
 drivers/Makefile |1 +
 drivers/accel/Kconfig|2 +
 drivers/accel/Makefile   |3 +
 drivers/accel/ivpu/Kconfig   |   15 +
 drivers/accel/ivpu/Makefile  |8 +
 drivers/accel/ivpu/TODO  |9 +
 drivers/accel/ivpu/ivpu_drv.c|  359 +
 drivers/accel/ivpu/ivpu_drv.h|  162 
 drivers/accel/ivpu/ivpu_hw.h |  170 +
 drivers/accel/ivpu/ivpu_hw_mtl.c | 1048 ++
 drivers/accel/ivpu/ivpu_hw_mtl_reg.h |  280 +++
 drivers/accel/ivpu/ivpu_hw_reg_io.h  |  115 +++
 include/uapi/drm/ivpu_accel.h|   95 +++
 14 files changed, 2276 insertions(+)
 create mode 100644 drivers/accel/Makefile
 create mode 100644 drivers/accel/ivpu/Kconfig
 create mode 100644 drivers/accel/ivpu/Makefile
 create mode 100644 drivers/accel/ivpu/TODO
 create mode 100644 drivers/accel/ivpu/ivpu_drv.c
 create mode 100644 drivers/accel/ivpu/ivpu_drv.h
 create mode 100644 drivers/accel/ivpu/ivpu_hw.h
 create mode 100644 drivers/accel/ivpu/ivpu_hw_mtl.c
 create mode 100644 drivers/accel/ivpu/ivpu_hw_mtl_reg.h
 create mode 100644 drivers/accel/ivpu/ivpu_hw_reg_io.h
 create mode 100644 include/uapi/drm/ivpu_accel.h

diff --git a/MAINTAINERS b/MAINTAINERS
index a47d963af3b8..a994c39e1118 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -6915,6 +6915,15 @@ T:   git 
https://git.kernel.org/pub/scm/linux/kernel/git/ogabbay/accel.git
 F: Documentation/accel/
 F: drivers/accel/
 
+DRM ACCEL DRIVERS FOR INTEL VPU
+M: Jacek Lawrynowicz 
+M: Stanislaw Gruszka 
+L: dri-devel@lists.freedesktop.org
+S: Supported
+T: git git://anongit.freedesktop.org/drm/drm-misc
+F: drivers/accel/ivpu/
+F: include/uapi/drm/ivpu_drm.h
+
 DRM DRIVERS FOR ALLWINNER A10
 M: Maxime Ripard 
 M: Chen-Yu Tsai 
diff --git a/drivers/Makefile b/drivers/Makefile
index bdf1c66141c9..f0972e2226c9 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -189,3 +189,4 @@ obj-$(CONFIG_COUNTER)   += counter/
 obj-$(CONFIG_MOST) += most/
 obj-$(CONFIG_PECI) += peci/
 obj-$(CONFIG_HTE)  += hte/
+obj-$(CONFIG_DRM_ACCEL)+= accel/
\ No newline at end of file
diff --git a/drivers/accel/Kconfig b/drivers/accel/Kconfig
index c9ce849b2984..4989376e5938 100644
--- a/drivers/accel/Kconfig
+++ b/drivers/accel/Kconfig
@@ -22,3 +22,5 @@ menuconfig DRM_ACCEL
  major number than GPUs, and will be exposed to user-space using
  different device files, called accel/accel* (in /dev, sysfs
  and debugfs).
+
+source "drivers/accel/ivpu/Kconfig"
diff --git a/drivers/accel/Makefile b/drivers/accel/Makefile
new file mode 100644
index ..b1036dbc0ba4
--- /dev/null
+++ b/drivers/accel/Makefile
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+obj-y  += ivpu/
diff --git a/drivers/accel/ivpu/Kconfig b/drivers/accel/ivpu/Kconfig
new file mode 100644
index ..110a6b921135
--- /dev/null
+++ b/drivers/accel/ivpu/Kconfig
@@ -0,0 +1,15 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+config DRM_ACCEL_IVPU
+   tristate "Intel VPU for Meteor Lake and newer"
+   depends on DRM_ACCEL
+   depends on X86_64
+   depends on PCI && PCI_MSI
+   select FW_LOADER
+   select SHMEM
+   help
+ Choose this option if you have a system that has an 14th generation 
Intel CPU
+ or newer. VPU stands for Versatile Processing Unit and it's a 
CPU-integrated
+ inference accelerator for Computer Vision and Deep Learning 
applications.
+
+ If "M" is selected, the module will be called intel_vpu.
diff --git a/drivers/accel/ivpu/Makefile b/drivers/accel/ivpu/Makefile