Skip to contentSkip to conversation

Driver of Intel(R) Gaussian & Neural Accelerator

PATCH In review Maciej Kwapulinski 8 participants 37 messages Oct 20, 2022 – Jan 24, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v5 cover Driver of Intel(R) Gaussian & Neural Accelerator

Dear kernel maintainers,

This submission is a kernel driver to support Intel(R) Gaussian & Neural Accelerator (Intel(R) GNA). Intel(R) GNA is a PCI-based neural co-processor available on multiple Intel platforms. AI developers and users can offload continuous inference workloads to an Intel(R) GNA device in order to free processor resources and save power. Noise reduction and speech recognition are the examples of the workloads Intel(R) GNA deals with while its usage is not limited to the two.

For a list of processors equipped with Intel(R) GNA device, please refer to this link:
https://docs.openvinotoolkit.org/latest/openvino_docs_IE_DG_supported_plugins_GNA.html

We think contributing this driver to the upstream kernel project is the best way for developers and users to get the latest Intel(R) GNA support in a Linux kernel, through the mainline to any Linux distributions installed on their systems. Upstreaming also enables contribution from developers around the world to the driver once it is merged.

The driver works with Intel(R) libraries in user space. The Intel(R) driver exposes a few IOCTL interfaces for use by libraries in user space. The libraries are open sourced and are available at:
https://github.com/intel/gna

---

Changelogs:

v1->v2:
- driver's new layout:
- driver name: gna -> intel_gna
- module name: gna -> intel_gna
- device file name: /dev/gnaN -> /dev/intel_gnaN
- driver's source directory: drivers/misc/gna/ -> drivers/misc/intel/gna/
- UAPI: include/uapi/misc/gna.h -> include/uapi/misc/intel/gna.h
- DOC: Documentation/misc-devices/gna.rst -> Documentation/misc-devices/intel/gna.rst
- 'MISC' device framework used
- fixes throughout GNA device's PCI management
- header files' includes and forward declarations cleanup
- ISR made static
- unused comments cleanup
- "_priv_" segment removed from function names
- tested: v5.11-rc3 -> v5.11
- number of other/minor fixes

v2->v3:
- PCI glue driver part split.
- GNA probe fail path made fully implicit.
- 'recovery_timeout' module parameter present under 'CONFIG_DEBUG_INTEL_GNA' flag only.
- build for X86_32 enabled.
- module initialization through 'module_pci_driver()'.
- gna_priv->file_list cleanup.
- 'gna_' prefix removed from source files' names.
- power management handling added.
- number of other/minor fixes
- tests performed on kernel v5.12

v3->v4:
- GNA driver adapted to DRM framework (+userspace GNA library adapted to use the driver)
- drm_managed (drmm) feature is used for objects lifetime management
- GNA memory objects use ~drm_gem_shmem_object~ objects as a base
- patches reorganized to meet symbols' usage with their declarations/definitions
- 'recovery_timeout' module parameter removed
- number of other/minor fixes from v3 review
- tests performed on kernel v6.0

v4->v5:
- indentation fixed in drivers/gpu/drm/gna/Kconfig

Maciej Kwapulinski (4):
gna: add PCI driver module
gna: add GNA DRM device
gna: add GNA_GEM_NEW and GNA_GEM_FREE ioctls
gna: add power management

Tomasz Jankowski (6):
gna: read hardware info
gna: initialize MMU
gna: add GNA_GET_PARAMETER ioctl
gna: add GNA_COMPUTE ioctl
gna: add GNA_WAIT ioctl
gna: add open and close operations on GNA device

 Documentation/gpu/drivers.rst     |   1 +
 Documentation/gpu/gna.rst         |  64 +++++
 MAINTAINERS                       |   7 +
 drivers/gpu/drm/Kconfig           |   2 +
 drivers/gpu/drm/Makefile          |   1 +
 drivers/gpu/drm/gna/Kbuild        |   5 +
 drivers/gpu/drm/gna/Kconfig       |  15 +
 drivers/gpu/drm/gna/gna_device.c  | 317 +++++++++++++++++++++
 drivers/gpu/drm/gna/gna_device.h  | 114 ++++++++
 drivers/gpu/drm/gna/gna_gem.h     |  22 ++
 drivers/gpu/drm/gna/gna_hw.c      | 110 ++++++++
 drivers/gpu/drm/gna/gna_hw.h      | 107 ++++++++
 drivers/gpu/drm/gna/gna_ioctl.c   | 208 ++++++++++++++
 drivers/gpu/drm/gna/gna_mem.c     | 249 +++++++++++++++++
 drivers/gpu/drm/gna/gna_mem.h     |  58 ++++
 drivers/gpu/drm/gna/gna_pci.c     | 148 ++++++++++
 drivers/gpu/drm/gna/gna_pci.h     |  12 +
 drivers/gpu/drm/gna/gna_request.c | 441 ++++++++++++++++++++++++++++++
 drivers/gpu/drm/gna/gna_request.h |  64 +++++
 drivers/gpu/drm/gna/gna_score.c   | 222 +++++++++++++++
 drivers/gpu/drm/gna/gna_score.h   |  11 +
 include/uapi/drm/gna_drm.h        | 169 ++++++++++++
 22 files changed, 2347 insertions(+)
 create mode 100644 Documentation/gpu/gna.rst
 create mode 100644 drivers/gpu/drm/gna/Kbuild
 create mode 100644 drivers/gpu/drm/gna/Kconfig
 create mode 100644 drivers/gpu/drm/gna/gna_device.c
 create mode 100644 drivers/gpu/drm/gna/gna_device.h
 create mode 100644 drivers/gpu/drm/gna/gna_gem.h
 create mode 100644 drivers/gpu/drm/gna/gna_hw.c
 create mode 100644 drivers/gpu/drm/gna/gna_hw.h
 create mode 100644 drivers/gpu/drm/gna/gna_ioctl.c
 create mode 100644 drivers/gpu/drm/gna/gna_mem.c
 create mode 100644 drivers/gpu/drm/gna/gna_mem.h
 create mode 100644 drivers/gpu/drm/gna/gna_pci.c
 create mode 100644 drivers/gpu/drm/gna/gna_pci.h
 create mode 100644 drivers/gpu/drm/gna/gna_request.c
 create mode 100644 drivers/gpu/drm/gna/gna_request.h
 create mode 100644 drivers/gpu/drm/gna/gna_score.c
 create mode 100644 drivers/gpu/drm/gna/gna_score.h
 create mode 100644 include/uapi/drm/gna_drm.h
Signature · 1 line
2.25.1
#1 lore raw

PATCH v5 1/10 gna: add PCI driver module

Add a new PCI driver for Intel(R) Gaussian & Neural Accelerator with basic support like module loading and unloading. The full function of the driver will be added by further changes.

---
 Documentation/gpu/drivers.rst    |  1 +
 Documentation/gpu/gna.rst        | 64 ++++++++++++++++++++++++++++++++
 MAINTAINERS                      |  6 +++
 drivers/gpu/drm/Kconfig          |  2 +
 drivers/gpu/drm/Makefile         |  1 +
 drivers/gpu/drm/gna/Kbuild       |  5 +++
 drivers/gpu/drm/gna/Kconfig      | 12 ++++++
 drivers/gpu/drm/gna/gna_device.c |  8 ++++
 drivers/gpu/drm/gna/gna_device.h |  9 +++++
 drivers/gpu/drm/gna/gna_pci.c    | 32 ++++++++++++++++
 drivers/gpu/drm/gna/gna_pci.h    | 12 ++++++
 11 files changed, 152 insertions(+)
 create mode 100644 Documentation/gpu/gna.rst
 create mode 100644 drivers/gpu/drm/gna/Kbuild
 create mode 100644 drivers/gpu/drm/gna/Kconfig
 create mode 100644 drivers/gpu/drm/gna/gna_device.c
 create mode 100644 drivers/gpu/drm/gna/gna_device.h
 create mode 100644 drivers/gpu/drm/gna/gna_pci.c
 create mode 100644 drivers/gpu/drm/gna/gna_pci.h
Documentation/gpu/drivers.rst +1 -0
index 3a52f48215a3..7238ddc576a2 100644
@@ -5,6 +5,7 @@ GPU Driver Documentation
 .. toctree::
 
    amdgpu/index
+   gna
    i915
    mcde
    meson
Documentation/gpu/gna.rst new file +64 -0

64 lines not on this page · raw message

MAINTAINERS +6 -0
index 72b9654f764c..d5b966c00155 100644
@@ -10174,6 +10174,12 @@ S:	Maintained
 F:	Documentation/fb/intelfb.rst
 F:	drivers/video/fbdev/intelfb/
 
+INTEL GNA PCI DRIVER
+M:	Maciej Kwapulinski <[email protected]>
+S:	Maintained
+F:	Documentation/gpu/gna.rst
+F:	drivers/gpu/drm/gna/*
+
 INTEL GPIO DRIVERS
 M:	Andy Shevchenko <[email protected]>
 L:	[email protected]
drivers/gpu/drm/Kconfig +2 -0
index 6c2256e8474b..3f5720b9db1f 100644
@@ -403,6 +403,8 @@ source "drivers/gpu/drm/solomon/Kconfig"
 
 source "drivers/gpu/drm/sprd/Kconfig"
 
+source "drivers/gpu/drm/gna/Kconfig"
+
 config DRM_HYPERV
 	tristate "DRM Support for Hyper-V synthetic video device"
 	depends on DRM && PCI && MMU && HYPERV
drivers/gpu/drm/Makefile +1 -0
index e7af358e6dda..e088267f349d 100644
@@ -147,3 +147,4 @@ obj-y			+= gud/
 obj-$(CONFIG_DRM_HYPERV) += hyperv/
 obj-y			+= solomon/
 obj-$(CONFIG_DRM_SPRD) += sprd/
+obj-$(CONFIG_DRM_GNA) += gna/
drivers/gpu/drm/gna/Kbuild new file +5 -0
new file mode 100644
index 000000000000..00e8d6a2c49c
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+gna-y := gna_device.o gna_pci.o
+
+obj-$(CONFIG_DRM_GNA) += gna.o
drivers/gpu/drm/gna/Kconfig new file +12 -0
new file mode 100644
index 000000000000..467f518db7fa
@@ -0,0 +1,12 @@
+#
+# Intel(R) Gaussian & Neural Accelerator (Intel(R) GNA)
+#
+
+config DRM_GNA
+	tristate "Intel(R) Gaussian & Neural Accelerator (Intel(R) GNA)"
+	depends on X86 && PCI
+	help
+	  This option enables the Intel(R) Gaussian & Neural Accelerator
+	  (Intel(R) GNA) driver: gna
+	  Information about functionality is in
+	  Documentation/gpu/gna.rst
drivers/gpu/drm/gna/gna_device.c new file +8 -0
new file mode 100644
index 000000000000..960b4341c18e
@@ -0,0 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0-only
+// Copyright(c) 2017-2022 Intel Corporation
+
+#include <linux/module.h>
+
+MODULE_AUTHOR("Intel Corporation");
+MODULE_DESCRIPTION("Intel(R) Gaussian & Neural Accelerator (Intel(R) GNA) Driver");
+MODULE_LICENSE("GPL");
drivers/gpu/drm/gna/gna_device.h new file +9 -0
new file mode 100644
index 000000000000..4cc92f27765a
@@ -0,0 +1,9 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Copyright(c) 2017-2022 Intel Corporation */
+
+#ifndef __GNA_DEVICE_H__
+#define __GNA_DEVICE_H__
+
+#define DRIVER_NAME		"gna"
+
+#endif /* __GNA_DEVICE_H__ */
drivers/gpu/drm/gna/gna_pci.c new file +32 -0
new file mode 100644
index 000000000000..6bd00c66f3a7
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: GPL-2.0-only
+// Copyright(c) 2017-2022 Intel Corporation
+
+#include <linux/module.h>
+#include <linux/pci.h>
+
+#include "gna_device.h"
+#include "gna_pci.h"
+
+int gna_pci_probe(struct pci_dev *pcidev, const struct pci_device_id *pci_id)
+{
+	int err;
+
+	err = pcim_enable_device(pcidev);
+	if (err)
+		return err;
+
+	err = pcim_iomap_regions(pcidev, BIT(0), pci_name(pcidev));
+	if (err)
+		return err;
+
+	pci_set_master(pcidev);
+
+	return 0;
+}
+
+static struct pci_driver gna_pci_driver = {
+	.name = DRIVER_NAME,
+	.probe = gna_pci_probe,
+};
+
+module_pci_driver(gna_pci_driver);
drivers/gpu/drm/gna/gna_pci.h new file +12 -0
new file mode 100644
index 000000000000..b651fa2e6ea1
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Copyright(c) 2017-2022 Intel Corporation */
+
+#ifndef __GNA_PCI_H__
+#define __GNA_PCI_H__
+
+struct pci_device_id;
+struct pci_dev;
+
+int gna_pci_probe(struct pci_dev *dev, const struct pci_device_id *id);
+
+#endif /* __GNA_PCI_H__ */
Signature · 1 line
2.25.1
#2 lore raw

Re: [PATCH v5 01/10] gna: add PCI driver module

Quoted 4 lines · Maciej Kwapulinski

Add a new PCI driver for Intel(R) Gaussian & Neural Accelerator with basic support like module loading and unloading. The full function of the driver will be added by further changes.

...

Quoted 1 line

+GNA_GEM_NEW acquires new 4KB page aligned memory region ready for DMA operations.

a new

...

Documentation/gpu/gna.rst line 58

Quoted 2 lines
Documentation/gpu/gna.rst new file +2 -0
+GNA Library can allocate any number of memory regions for GNA usage. Its number and total
+capacity are limited by the OSs’ resources. Due to GNA MMU restrictions, even when using

OSes' ?

Quoted 2 lines
Documentation/gpu/gna.rst new file +2 -0
+multiple memory regions, the sum of all the memory regions used within a single inference
+request must be no larger than 256MB.

...

drivers/gpu/drm/Kconfig source "drivers/gpu/drm/solomon/Kconfig" · line 406

Quoted 6 lines

+++ b/drivers/gpu/drm/Kconfig

drivers/gpu/drm/Kconfig +1 -0
@@ -403,6 +403,8 @@ source "drivers/gpu/drm/solomon/Kconfig"
 
 source "drivers/gpu/drm/sprd/Kconfig"
 
+source "drivers/gpu/drm/gna/Kconfig"

It looks to me that you broke the order here.

...

drivers/gpu/drm/Makefile obj-y += gud/ · line 150

Quoted 5 lines
drivers/gpu/drm/Makefile +1 -0
@@ -147,3 +147,4 @@ obj-y                       += gud/
 obj-$(CONFIG_DRM_HYPERV) += hyperv/
 obj-y                  += solomon/
 obj-$(CONFIG_DRM_SPRD) += sprd/
+obj-$(CONFIG_DRM_GNA) += gna/

Ditto.

...

drivers/gpu/drm/gna/Kconfig line 7

Quoted 3 lines
drivers/gpu/drm/gna/Kconfig new file +3 -0
+config DRM_GNA
+       tristate "Intel(R) Gaussian & Neural Accelerator (Intel(R) GNA)"
+       depends on X86 && PCI

No compile test for the rest of possible options?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#3 lore raw

Re: [PATCH v5 01/10] gna: add PCI driver module

In reply to Maciej Kwapulinski
Quoted 6 lines · Maciej Kwapulinski
(quoted diff) +6 -0
+IOCTL
+-----
+Intel(R) GNA driver controls the device through IOCTL interfaces.
+Following IOCTL commands - handled by DRM framework - are supported:
+
+GNA_GET_PARAMETER gets driver and device capabilities.

Review

Quoted 10 lines
(quoted diff) +10 -0
+
+GNA_GEM_NEW acquires new 4KB page aligned memory region ready for DMA operations.
+
+GNA_GEM_FREE frees memory region back to system.
+
+GNA_COMPUTE submits a request to the device queue.
+            Memory regions acquired by GNA_GEM_NEW are part of request.
+
+GNA_WAIT blocks and waits on the submitted request.
+

Use bullet lists for ioctl list above (with minor wording improv on the whole section):

---- >8 ----

Documentation/gpu/gna.rst +10 -9
index 7f3b7ce7e8f722..9a896664a3c29f 100644
@@ -32,21 +32,22 @@ Multiple processes can independently file many requests to the driver. These req
 processed in a FIFO manner. The hardware can process one request at a time by using a FIFO
 queue.
 
-IOCTL
+ioctl
 -----
-Intel(R) GNA driver controls the device through IOCTL interfaces.
-Following IOCTL commands - handled by DRM framework - are supported:
+Intel(R) GNA driver controls the device through ioctl interfaces.
+The following commands (handled by DRM framework) are supported:
 
-GNA_GET_PARAMETER gets driver and device capabilities.
+  * GNA_GET_PARAMETER gets driver and device capabilities.
 
-GNA_GEM_NEW acquires new 4KB page aligned memory region ready for DMA operations.
+  * GNA_GEM_NEW allocates new 4KB page of aligned memory region ready for DMA
+    operations.
 
-GNA_GEM_FREE frees memory region back to system.
+  * GNA_GEM_FREE frees memory region back to system.
 
-GNA_COMPUTE submits a request to the device queue.
-            Memory regions acquired by GNA_GEM_NEW are part of request.
+  * GNA_COMPUTE submits a request to the device queue. Memory regions allocated
+    by GNA_GEM_NEW become part of the request payload.
 
-GNA_WAIT blocks and waits on the submitted request.
+  * GNA_WAIT blocks and waits on the submitted request.
 
 GNA MMU
 -------

Thanks.

Signature · 1 line
An old man doll... just what I always wanted! - Clara
#4 lore raw

Re: [PATCH v5 01/10] gna: add PCI driver module

In reply to Maciej Kwapulinski
Quoted 1 line · Maciej Kwapulinski

Add a new PCI driver for Intel(R) Gaussian & Neural Accelerator

Please drop all of the (R) stuff in here, and in the Kconfig file and in the .c files. If your lawyers insist on it, please point them at me and I will be glad to discuss it with them.

Quoted 2 lines
 Documentation/gpu/drivers.rst    |  1 +
 Documentation/gpu/gna.rst        | 64 ++++++++++++++++++++++++++++++++

Why not just put the tiny documentation file in the .c code itself? That way it stays up to date and might actually be noticed?

drivers/gpu/drm/gna/Kconfig line 2

Quoted 5 lines
drivers/gpu/drm/gna/Kconfig new file +2 -0
@@ -0,0 +1,12 @@
+#
+# Intel(R) Gaussian & Neural Accelerator (Intel(R) GNA)

Again, drop the (R) stuff.

And no SPDX line?

drivers/gpu/drm/gna/Kconfig line 7

Quoted 5 lines
drivers/gpu/drm/gna/Kconfig new file +5 -0
+#
+
+config DRM_GNA
+	tristate "Intel(R) Gaussian & Neural Accelerator (Intel(R) GNA)"
+	depends on X86 && PCI

Why is this x86 only? Please let it build on other arches.

drivers/gpu/drm/gna/Kconfig line 12

Quoted 5 lines
drivers/gpu/drm/gna/Kconfig new file +5 -0
+	help
+	  This option enables the Intel(R) Gaussian & Neural Accelerator
+	  (Intel(R) GNA) driver: gna
+	  Information about functionality is in
+	  Documentation/gpu/gna.rst

See, you changed this from the first v5 version you sent :(

Also, this needs a lot more information, including the module name that will be built and you can drop the documentation line.

Quoted 6 lines
drivers/gpu/drm/gna/gna_device.c new file +0 -0
new file mode 100644
index 000000000000..960b4341c18e

drivers/gpu/drm/gna/gna_device.c line 8

Quoted 8 lines
drivers/gpu/drm/gna/gna_device.c new file +8 -0
@@ -0,0 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0-only
+// Copyright(c) 2017-2022 Intel Corporation
+
+#include <linux/module.h>
+
+MODULE_AUTHOR("Intel Corporation");
+MODULE_DESCRIPTION("Intel(R) Gaussian & Neural Accelerator (Intel(R) GNA) Driver");
+MODULE_LICENSE("GPL");

No, that's not ok. Don't add a file that does nothing. Only add it when you need it.

drivers/gpu/drm/gna/gna_device.h line 7

Quoted 13 lines
drivers/gpu/drm/gna/gna_device.h new file +7 -0
new file mode 100644
index 000000000000..4cc92f27765a
@@ -0,0 +1,9 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Copyright(c) 2017-2022 Intel Corporation */
+
+#ifndef __GNA_DEVICE_H__
+#define __GNA_DEVICE_H__
+
+#define DRIVER_NAME		"gna"

This can be KBUILD_MODNAME and then the file isn't needed at all.

Quoted 46 lines
drivers/gpu/drm/gna/gna_device.h new file +2 -0
+
+#endif /* __GNA_DEVICE_H__ */
drivers/gpu/drm/gna/gna_pci.c new file +32 -0
new file mode 100644
index 000000000000..6bd00c66f3a7
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: GPL-2.0-only
+// Copyright(c) 2017-2022 Intel Corporation
+
+#include <linux/module.h>
+#include <linux/pci.h>
+
+#include "gna_device.h"
+#include "gna_pci.h"
+
+int gna_pci_probe(struct pci_dev *pcidev, const struct pci_device_id *pci_id)
+{
+	int err;
+
+	err = pcim_enable_device(pcidev);
+	if (err)
+		return err;
+
+	err = pcim_iomap_regions(pcidev, BIT(0), pci_name(pcidev));
+	if (err)
+		return err;
+
+	pci_set_master(pcidev);
+
+	return 0;
+}
+
+static struct pci_driver gna_pci_driver = {
+	.name = DRIVER_NAME,
+	.probe = gna_pci_probe,
+};
+
+module_pci_driver(gna_pci_driver);
drivers/gpu/drm/gna/gna_pci.h new file +0 -0
new file mode 100644
index 000000000000..b651fa2e6ea1

drivers/gpu/drm/gna/gna_pci.h line 10

Quoted 10 lines
drivers/gpu/drm/gna/gna_pci.h new file +10 -0
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Copyright(c) 2017-2022 Intel Corporation */
+
+#ifndef __GNA_PCI_H__
+#define __GNA_PCI_H__
+
+struct pci_device_id;
+struct pci_dev;
+
+int gna_pci_probe(struct pci_dev *dev, const struct pci_device_id *id);

This is not exported, nor should it be, so you do not need it in the .h file.

This whole patch can be one .c file, not this mess of tiny ones.

thanks,

greg k-h

#5 lore raw

Re: [PATCH v5 01/10] gna: add PCI driver module

Quoted 7 lines · Greg Kroah-Hartman
Quoted 1 line · Maciej Kwapulinski

Add a new PCI driver for Intel(R) Gaussian & Neural Accelerator

Please drop all of the (R) stuff in here, and in the Kconfig file and in the .c files. If your lawyers insist on it, please point them at me and I will be glad to discuss it with them.

Quoted 6 lines
Quoted 2 lines
 Documentation/gpu/drivers.rst    |  1 +
 Documentation/gpu/gna.rst        | 64 ++++++++++++++++++++++++++++++++

Why not just put the tiny documentation file in the .c code itself? That way it stays up to date and might actually be noticed?

I think the documentation should be on separate patch.

Signature · 1 line
An old man doll... just what I always wanted! - Clara
#6 lore raw

Re: [PATCH v5 01/10] gna: add PCI driver module

Quoted 8 lines · Bagas Sanjaya
Quoted 7 lines · Greg Kroah-Hartman
Quoted 1 line · Maciej Kwapulinski

Add a new PCI driver for Intel(R) Gaussian & Neural Accelerator

Please drop all of the (R) stuff in here, and in the Kconfig file and in the .c files. If your lawyers insist on it, please point them at me and I will be glad to discuss it with them.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
 Documentation/gpu/drivers.rst    |  1 +
 Documentation/gpu/gna.rst        | 64 ++++++++++++++++++++++++++++++++

Why not just put the tiny documentation file in the .c code itself? That way it stays up to date and might actually be noticed?

I think the documentation should be on separate patch.

Not if it is in the .c file.

#7 lore raw

Re: [PATCH v5 01/10] gna: add PCI driver module

In reply to Greg Kroah-Hartman
Quoted 27 lines · Greg Kroah-Hartman
Quoted 1 line · Maciej Kwapulinski

Add a new PCI driver for Intel(R) Gaussian & Neural Accelerator

Please drop all of the (R) stuff in here, and in the Kconfig file and in the .c files. If your lawyers insist on it, please point them at me and I will be glad to discuss it with them.

Quoted 2 lines
 Documentation/gpu/drivers.rst    |  1 +
 Documentation/gpu/gna.rst        | 64 ++++++++++++++++++++++++++++++++

Why not just put the tiny documentation file in the .c code itself? That way it stays up to date and might actually be noticed?

drivers/gpu/drm/gna/Kconfig line 2

Quoted 5 lines
drivers/gpu/drm/gna/Kconfig new file +2 -0
@@ -0,0 +1,12 @@
+#
+# Intel(R) Gaussian & Neural Accelerator (Intel(R) GNA)

Again, drop the (R) stuff.

And no SPDX line?

drivers/gpu/drm/gna/Kconfig line 7

Quoted 5 lines
drivers/gpu/drm/gna/Kconfig new file +5 -0
+#
+
+config DRM_GNA
+	tristate "Intel(R) Gaussian & Neural Accelerator (Intel(R) GNA)"
+	depends on X86 && PCI

Why is this x86 only? Please let it build on other arches.

Quoted 6 lines

drivers/gpu/drm/gna/Kconfig line 12

Quoted 5 lines
drivers/gpu/drm/gna/Kconfig new file +5 -0
+	help
+	  This option enables the Intel(R) Gaussian & Neural Accelerator
+	  (Intel(R) GNA) driver: gna
+	  Information about functionality is in
+	  Documentation/gpu/gna.rst

See, you changed this from the first v5 version you sent :(

actually I've sent patch v4 (once) and patch v5 (once).  according to change log in cover letter:

·v4->v5:$ ·-·indentation·fixed·in·drivers/gpu/drm/gna/Kconfig$

Quoted 4 lines

Also, this needs a lot more information, including the module name that will be built and you can drop the documentation line.

Quoted 16 lines
Quoted 6 lines
drivers/gpu/drm/gna/gna_device.c new file +0 -0
new file mode 100644
index 000000000000..960b4341c18e

drivers/gpu/drm/gna/gna_device.c line 8

Quoted 8 lines
drivers/gpu/drm/gna/gna_device.c new file +8 -0
@@ -0,0 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0-only
+// Copyright(c) 2017-2022 Intel Corporation
+
+#include <linux/module.h>
+
+MODULE_AUTHOR("Intel Corporation");
+MODULE_DESCRIPTION("Intel(R) Gaussian & Neural Accelerator (Intel(R) GNA) Driver");
+MODULE_LICENSE("GPL");

No, that's not ok. Don't add a file that does nothing. Only add it when you need it.

well, it provides metadata

Quoted 76 lines
Quoted 8 lines
drivers/gpu/drm/gna/gna_device.h new file +0 -0
new file mode 100644
index 000000000000..4cc92f27765a

drivers/gpu/drm/gna/gna_device.h line 7

Quoted 7 lines
drivers/gpu/drm/gna/gna_device.h new file +7 -0
@@ -0,0 +1,9 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Copyright(c) 2017-2022 Intel Corporation */
+
+#ifndef __GNA_DEVICE_H__
+#define __GNA_DEVICE_H__
+
+#define DRIVER_NAME		"gna"

This can be KBUILD_MODNAME and then the file isn't needed at all.

Quoted 46 lines
drivers/gpu/drm/gna/gna_device.h new file +2 -0
+
+#endif /* __GNA_DEVICE_H__ */
drivers/gpu/drm/gna/gna_pci.c new file +32 -0
new file mode 100644
index 000000000000..6bd00c66f3a7
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: GPL-2.0-only
+// Copyright(c) 2017-2022 Intel Corporation
+
+#include <linux/module.h>
+#include <linux/pci.h>
+
+#include "gna_device.h"
+#include "gna_pci.h"
+
+int gna_pci_probe(struct pci_dev *pcidev, const struct pci_device_id *pci_id)
+{
+	int err;
+
+	err = pcim_enable_device(pcidev);
+	if (err)
+		return err;
+
+	err = pcim_iomap_regions(pcidev, BIT(0), pci_name(pcidev));
+	if (err)
+		return err;
+
+	pci_set_master(pcidev);
+
+	return 0;
+}
+
+static struct pci_driver gna_pci_driver = {
+	.name = DRIVER_NAME,
+	.probe = gna_pci_probe,
+};
+
+module_pci_driver(gna_pci_driver);
drivers/gpu/drm/gna/gna_pci.h new file +0 -0
new file mode 100644
index 000000000000..b651fa2e6ea1

drivers/gpu/drm/gna/gna_pci.h line 10

Quoted 10 lines
drivers/gpu/drm/gna/gna_pci.h new file +10 -0
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Copyright(c) 2017-2022 Intel Corporation */
+
+#ifndef __GNA_PCI_H__
+#define __GNA_PCI_H__
+
+struct pci_device_id;
+struct pci_dev;
+
+int gna_pci_probe(struct pci_dev *dev, const struct pci_device_id *id);

This is not exported, nor should it be, so you do not need it in the .h file.

Quoted 1 line

This whole patch can be one .c file, not this mess of tiny ones.

I just wanted to have file's final render from very beginning.

#8 lore raw

PATCH v5 2/10 gna: add GNA DRM device

In reply to Maciej Kwapulinski
---
 drivers/gpu/drm/gna/Kconfig      |  1 +
 drivers/gpu/drm/gna/gna_device.c | 65 ++++++++++++++++++++++++++++++++
 drivers/gpu/drm/gna/gna_device.h | 21 +++++++++++
 drivers/gpu/drm/gna/gna_hw.h     | 17 +++++++++
 drivers/gpu/drm/gna/gna_pci.c    | 11 ++++++
 5 files changed, 115 insertions(+)
 create mode 100644 drivers/gpu/drm/gna/gna_hw.h
drivers/gpu/drm/gna/Kconfig +1 -0
index 467f518db7fa..820dc8424045 100644
@@ -5,6 +5,7 @@
 config DRM_GNA
 	tristate "Intel(R) Gaussian & Neural Accelerator (Intel(R) GNA)"
 	depends on X86 && PCI
+	depends on DRM
 	help
 	  This option enables the Intel(R) Gaussian & Neural Accelerator
 	  (Intel(R) GNA) driver: gna
drivers/gpu/drm/gna/gna_device.c +65 -0

73 lines not on this page · raw message

drivers/gpu/drm/gna/gna_device.h +21 -0
index 4cc92f27765a..d269f7da5c5e 100644
@@ -4,6 +4,27 @@
 #ifndef __GNA_DEVICE_H__
 #define __GNA_DEVICE_H__
 
+#include <drm/drm_device.h>
+
+#include "gna_hw.h"
+
 #define DRIVER_NAME		"gna"
+#define DRIVER_DESC		"Intel(R) Gaussian & Neural Accelerator (Intel(R) GNA)"
+#define DRIVER_DATE		"20211201"
+
+#define DRIVER_MAJOR		1
+#define DRIVER_MINOR		0
+#define DRIVER_PATCHLEVEL	0
+
+struct device;
+
+struct gna_device {
+	struct drm_device drm;
+
+	/* device related resources */
+	void __iomem *iobase;
+	struct gna_dev_info info;
+};
 
+int gna_probe(struct device *parent, struct gna_dev_info *dev_info, void __iomem *iobase);
 #endif /* __GNA_DEVICE_H__ */
drivers/gpu/drm/gna/gna_hw.h new file +17 -0
new file mode 100644
index 000000000000..3ca801096fd1
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Copyright(c) 2017-2022 Intel Corporation */
+
+#ifndef __GNA_HW_H__
+#define __GNA_HW_H__
+
+#include <linux/mm_types.h>
+
+struct gna_dev_info {
+	u32 hwid;
+	u32 num_pagetables;
+	u32 num_page_entries;
+	u32 max_layer_count;
+	u64 max_hw_mem;
+};
+
+#endif // __GNA_HW_H__
drivers/gpu/drm/gna/gna_pci.c +11 -0
index 6bd00c66f3a7..14f8b34e5f5c 100644
@@ -5,10 +5,13 @@
 #include <linux/pci.h>
 
 #include "gna_device.h"
+#include "gna_hw.h"
 #include "gna_pci.h"
 
 int gna_pci_probe(struct pci_dev *pcidev, const struct pci_device_id *pci_id)
 {
+	struct gna_dev_info *dev_info;
+	void __iomem *iobase;
 	int err;
 
 	err = pcim_enable_device(pcidev);
@@ -19,8 +22,16 @@ int gna_pci_probe(struct pci_dev *pcidev, const struct pci_device_id *pci_id)
 	if (err)
 		return err;
 
+	iobase = pcim_iomap_table(pcidev)[0];
+
 	pci_set_master(pcidev);
 
+	dev_info = (struct gna_dev_info *)pci_id->driver_data;
+
+	err = gna_probe(&pcidev->dev, dev_info, iobase);
+	if (err)
+		return err;
+
 	return 0;
 }
 
Signature · 1 line
2.25.1
#9 lore raw

Re: [PATCH v5 02/10] gna: add GNA DRM device

On Thu, Oct 20, 2022 at 8:57 PM Maciej Kwapulinski <[email protected]> wrote:

Missed commit message.

Quoted 2 lines

...

Quoted 1 line

+ if (!(sizeof(dma_addr_t) > 4) ||

Do you really need this?

drivers/gpu/drm/gna/gna_device.c line 59

Quoted 5 lines
drivers/gpu/drm/gna/gna_device.c +4 -0
+               dma_set_mask(parent, DMA_BIT_MASK(64))) {
 
+               err = dma_set_mask(parent, DMA_BIT_MASK(32));
+               if (err)
+                       return err;

IIRC if the 64-bit dma_set_mask() fails, there is no need to check 32-bit, i.e. it will fail.

Quoted 1 line

+ }

...

Quoted 1 line

+#define DRIVER_DATE "20211201"

Really?

...

Quoted 1 line

+#include <linux/mm_types.h>

Are you sure?

Quoted 7 lines
drivers/gpu/drm/gna/gna_hw.h new file +7 -0
+struct gna_dev_info {
+       u32 hwid;
+       u32 num_pagetables;
+       u32 num_page_entries;
+       u32 max_layer_count;
+       u64 max_hw_mem;
+};
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#11 lore raw

PATCH v5 3/10 gna: read hardware info

In reply to Maciej Kwapulinski

From: Tomasz Jankowski <[email protected]>

Get the hardware information from register MMIO_IBUFFS

---
 drivers/gpu/drm/gna/gna_device.c | 4 ++++
 drivers/gpu/drm/gna/gna_device.h | 9 +++++++++
 drivers/gpu/drm/gna/gna_hw.h     | 7 +++++++
 3 files changed, 20 insertions(+)
drivers/gpu/drm/gna/gna_device.c +4 -0
index b8620b7da205..1f357221a603 100644
@@ -42,6 +42,7 @@ int gna_probe(struct device *parent, struct gna_dev_info *dev_info, void __iomem
 {
 	struct gna_device *gna_priv;
 	struct drm_device *drm_dev;
+	u32 bld_reg;
 	int err;
 
 	gna_priv = devm_drm_dev_alloc(parent, &gna_drm_driver, struct gna_device, drm);
@@ -59,6 +60,9 @@ int gna_probe(struct device *parent, struct gna_dev_info *dev_info, void __iomem
 			return err;
 	}
 
+	bld_reg = gna_reg_read(gna_priv, GNA_MMIO_IBUFFS);
+	gna_priv->hw_info.in_buf_s = bld_reg & GENMASK(7, 0);
+
 	dev_set_drvdata(parent, drm_dev);
 
 	err = gna_drm_dev_init(drm_dev);
drivers/gpu/drm/gna/gna_device.h +9 -0
index d269f7da5c5e..e42f167b62a0 100644
@@ -6,6 +6,9 @@
 
 #include <drm/drm_device.h>
 
+#include <linux/io.h>
+#include <linux/types.h>
+
 #include "gna_hw.h"
 
 #define DRIVER_NAME		"gna"
@@ -24,7 +27,13 @@ struct gna_device {
 	/* device related resources */
 	void __iomem *iobase;
 	struct gna_dev_info info;
+	struct gna_hw_info hw_info;
 };
 
 int gna_probe(struct device *parent, struct gna_dev_info *dev_info, void __iomem *iobase);
+static inline u32 gna_reg_read(struct gna_device *gna_priv, u32 reg)
+{
+	return readl(gna_priv->iobase + reg);
+}
+
 #endif /* __GNA_DEVICE_H__ */
drivers/gpu/drm/gna/gna_hw.h +7 -0
index 3ca801096fd1..e858b76606fc 100644
@@ -6,6 +6,13 @@
 
 #include <linux/mm_types.h>
 
+/* GNA MMIO registers */
+#define GNA_MMIO_IBUFFS		0xB4
+
+struct gna_hw_info {
+	u8 in_buf_s;
+};
+
 struct gna_dev_info {
 	u32 hwid;
 	u32 num_pagetables;
Signature · 1 line
2.25.1
#12 lore raw

Re: [PATCH v5 03/10] gna: read hardware info

Quoted 3 lines · Maciej Kwapulinski

From: Tomasz Jankowski <[email protected]>

Get the hardware information from register MMIO_IBUFFS

Please read our documentation for how to write good changelog texts. This tiny line says nothing about why we would want this patch at all.

Would you want to review a change that only had this in it?

greg k-h

#13 lore raw

Re: [PATCH v5 03/10] gna: read hardware info

In reply to Maciej Kwapulinski

Hi Maciej,

thanks for your patch!

Overall I really appreciate the attempt to use DRM, this looks so much smoother than the previous iterations.

Quoted 12 lines · Maciej Kwapulinski

From: Tomasz Jankowski <[email protected]>

Get the hardware information from register MMIO_IBUFFS

drivers/gpu/drm/gna/gna_device.h struct gna_device { · line 37

Quoted 4 lines
drivers/gpu/drm/gna/gna_device.h +4 -0
+static inline u32 gna_reg_read(struct gna_device *gna_priv, u32 reg)
+{
+       return readl(gna_priv->iobase + reg);
+}

If you are consistently using functions like this to read/write registers, you are just re-implmeneting regmap-mmio, see drivers/base/regmap/regmap-mmio.c
or look in drivers selecting REGMAP_MMIO and the neat tricks they do to read/write and update registers with regmap.

Yours,
Linus Walleij

#14 lore raw

PATCH v5 4/10 gna: initialize MMU

In reply to Maciej Kwapulinski

From: Tomasz Jankowski <[email protected]>

Setup MMU in the driver with a new memory component.

---
 drivers/gpu/drm/gna/Kbuild       |  2 +-
 drivers/gpu/drm/gna/gna_device.c |  7 +++
 drivers/gpu/drm/gna/gna_device.h |  8 ++++
 drivers/gpu/drm/gna/gna_hw.h     | 53 ++++++++++++++++++++++
 drivers/gpu/drm/gna/gna_mem.c    | 78 ++++++++++++++++++++++++++++++++
 drivers/gpu/drm/gna/gna_mem.h    | 50 ++++++++++++++++++++
 drivers/gpu/drm/gna/gna_pci.c    | 70 ++++++++++++++++++++++++++++
 7 files changed, 267 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/gna/gna_mem.c
 create mode 100644 drivers/gpu/drm/gna/gna_mem.h
drivers/gpu/drm/gna/Kbuild +1 -1
index 00e8d6a2c49c..2bda61c61f45 100644
@@ -1,5 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0-only
 
-gna-y := gna_device.o gna_pci.o
+gna-y := gna_device.o gna_mem.o gna_pci.o
 
 obj-$(CONFIG_DRM_GNA) += gna.o
drivers/gpu/drm/gna/gna_device.c +7 -0
index 1f357221a603..f1724cbe3963 100644
@@ -63,6 +63,13 @@ int gna_probe(struct device *parent, struct gna_dev_info *dev_info, void __iomem
 	bld_reg = gna_reg_read(gna_priv, GNA_MMIO_IBUFFS);
 	gna_priv->hw_info.in_buf_s = bld_reg & GENMASK(7, 0);
 
+	err = gna_mmu_init(gna_priv);
+	if (err)
+		return err;
+
+	dev_dbg(parent, "maximum memory size %llu num pd %d\n",
+		gna_priv->info.max_hw_mem, gna_priv->info.num_pagetables);
+
 	dev_set_drvdata(parent, drm_dev);
 
 	err = gna_drm_dev_init(drm_dev);
drivers/gpu/drm/gna/gna_device.h +8 -0
index e42f167b62a0..d2357954b245 100644
@@ -10,6 +10,7 @@
 #include <linux/types.h>
 
 #include "gna_hw.h"
+#include "gna_mem.h"
 
 #define DRIVER_NAME		"gna"
 #define DRIVER_DESC		"Intel(R) Gaussian & Neural Accelerator (Intel(R) GNA)"
@@ -28,6 +29,8 @@ struct gna_device {
 	void __iomem *iobase;
 	struct gna_dev_info info;
 	struct gna_hw_info hw_info;
+
+	struct gna_mmu_object mmu;
 };
 
 int gna_probe(struct device *parent, struct gna_dev_info *dev_info, void __iomem *iobase);
@@ -36,4 +39,9 @@ static inline u32 gna_reg_read(struct gna_device *gna_priv, u32 reg)
 	return readl(gna_priv->iobase + reg);
 }
 
+static inline struct device *gna_dev(struct gna_device *gna_priv)
+{
+	return gna_priv->drm.dev;
+}
+
 #endif /* __GNA_DEVICE_H__ */
drivers/gpu/drm/gna/gna_hw.h +53 -0

68 lines not on this page · raw message

drivers/gpu/drm/gna/gna_mem.c new file +78 -0

78 lines not on this page · raw message

drivers/gpu/drm/gna/gna_mem.h new file +50 -0

50 lines not on this page · raw message

drivers/gpu/drm/gna/gna_pci.c +70 -0

83 lines not on this page · raw message

Signature · 1 line
2.25.1
#15 lore raw

Re: [PATCH v5 04/10] gna: initialize MMU

Quoted 4 lines · Maciej Kwapulinski

From: Tomasz Jankowski <[email protected]>

Setup MMU in the driver with a new memory component.

...

drivers/gpu/drm/gna/gna_hw.h line 10

Quoted 2 lines
drivers/gpu/drm/gna/gna_hw.h +2 -0
+#define GNA_FEATURES                                           \
+       .max_hw_mem = 256 * 1024 * 1024,                        \

SZ_256M ?

Quoted 4 lines
drivers/gpu/drm/gna/gna_hw.h +4 -0
+               .num_pagetables = 64,                           \
+               .num_page_entries = PAGE_SIZE / sizeof(u32),    \
+               /* desc_info all in bytes */                    \
+               .desc_info = {                                  \

drivers/gpu/drm/gna/gna_hw.h

Quoted 10 lines
drivers/gpu/drm/gna/gna_hw.h +9 -0
+               .rsvd_size = 256,                               \
+               .cfg_size = 256,                                \
+               .desc_size = 784,                               \
+               .mmu_info = {                                   \
+                       .vamax_size = 4,                        \
+                       .rsvd_size = 12,                        \
+                       .pd_size = 4 * 64,                      \
+               },                                              \
 
+       }

Broken indentation?

...

drivers/gpu/drm/gna/gna_hw.h line 42

Quoted 10 lines
drivers/gpu/drm/gna/gna_hw.h +10 -0
+#define GNA_DEV_HWID_CNL       0x5A11
+#define GNA_DEV_HWID_EHL       0x4511
+#define GNA_DEV_HWID_GLK       0x3190
+#define GNA_DEV_HWID_ICL       0x8A11
+#define GNA_DEV_HWID_JSL       0x4E11
+#define GNA_DEV_HWID_TGL       0x9A11
+#define GNA_DEV_HWID_RKL       0x4C11
+#define GNA_DEV_HWID_ADL       0x464F
+#define GNA_DEV_HWID_RPL       0xA74F
+#define GNA_DEV_HWID_MTL       0x7E4C

Keep them sorted?

...

drivers/gpu/drm/gna/gna_mem.c line 27

Quoted 3 lines
drivers/gpu/drm/gna/gna_mem.c new file +3 -0
+       for (i = 0; i < mmu->num_pagetables; i++) {
+               pagetable_dma = mmu->pagetables_dma[i];
+               pgdirn[i] = pagetable_dma >> PAGE_SHIFT;

PFN_DOWN()

Quoted 1 line

+ }

...

Quoted 1 line

+ desc_size = round_up(gna_priv->info.desc_info.desc_size, PAGE_SIZE);

PFN_UP() ?

...

drivers/gpu/drm/gna/gna_mem.c line 64

Quoted 3 lines
drivers/gpu/drm/gna/gna_mem.c new file +2 -0
+       mmu->pagetables = drmm_kmalloc_array(&gna_priv->drm, mmu->num_pagetables, sizeof(*mmu->pagetables), GFP_KERNEL);
 
+

Redundant blank line.

Quoted 2 lines
(quoted diff) +2 -0
+       if (!mmu->pagetables)
+               return -ENOMEM;

...

drivers/gpu/drm/gna/gna_pci.c line 13

Quoted 3 lines
drivers/gpu/drm/gna/gna_pci.c +3 -0
+static const struct gna_dev_info cnl_dev_info = {
+       .hwid = GNA_DEV_HWID_CNL,
+       GNA_GEN1_FEATURES

Leave a comma at the end. Same for all similar declarations.

Quoted 1 line

+};

...

drivers/gpu/drm/gna/gna_pci.c line 62

Quoted 2 lines
drivers/gpu/drm/gna/gna_pci.c +2 -0
+#define INTEL_GNA_DEVICE(hwid, info)                           \
+       { PCI_VDEVICE(INTEL, hwid), (kernel_ulong_t)(info) }

Drop this and use PCI_DEVICE_DATA() instead.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#16 lore raw

Re: [PATCH v5 04/10] gna: initialize MMU

Quoted 2 lines · Andy Shevchenko

On Thu, Oct 20, 2022 at 8:57 PM Maciej Kwapulinski <[email protected]> wrote:

...

Quoted 3 lines
Quoted 1 line

+ desc_size = round_up(gna_priv->info.desc_info.desc_size, PAGE_SIZE);

PFN_UP() ?

Or PFN_ALIGN() ?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#17 lore raw

PATCH v5 5/10 gna: add GNA_GET_PARAMETER ioctl

In reply to Maciej Kwapulinski

From: Tomasz Jankowski <[email protected]>

As this is first ioctl in the series, the patch also adds common bits for remaining ioctls

---
 MAINTAINERS                      |  1 +
 drivers/gpu/drm/gna/Kbuild       |  2 +-
 drivers/gpu/drm/gna/Kconfig      |  3 +-
 drivers/gpu/drm/gna/gna_device.c | 58 ++++++++++++++++++++++++++++++++
 drivers/gpu/drm/gna/gna_device.h | 14 ++++++++
 drivers/gpu/drm/gna/gna_ioctl.c  | 18 ++++++++++
 include/uapi/drm/gna_drm.h       | 40 ++++++++++++++++++++++
 7 files changed, 134 insertions(+), 2 deletions(-)
 create mode 100644 drivers/gpu/drm/gna/gna_ioctl.c
 create mode 100644 include/uapi/drm/gna_drm.h
MAINTAINERS +1 -0
index d5b966c00155..458ee5ad765d 100644
@@ -10179,6 +10179,7 @@ M:	Maciej Kwapulinski <[email protected]>
 S:	Maintained
 F:	Documentation/gpu/gna.rst
 F:	drivers/gpu/drm/gna/*
+F:	include/uapi/drm/gna_drm.h
 
 INTEL GPIO DRIVERS
 M:	Andy Shevchenko <[email protected]>
drivers/gpu/drm/gna/Kbuild +1 -1
index 2bda61c61f45..101880869dc4 100644
@@ -1,5 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0-only
 
-gna-y := gna_device.o gna_mem.o gna_pci.o
+gna-y := gna_device.o gna_ioctl.o gna_mem.o gna_pci.o
 
 obj-$(CONFIG_DRM_GNA) += gna.o
drivers/gpu/drm/gna/Kconfig +2 -1
index 820dc8424045..e56b933458dc 100644
@@ -9,5 +9,6 @@ config DRM_GNA
 	help
 	  This option enables the Intel(R) Gaussian & Neural Accelerator
 	  (Intel(R) GNA) driver: gna
-	  Information about functionality is in
+	  User space interface is defined in include/uapi/drm/gna_drm.h, while
+	  information about functionality is in
 	  Documentation/gpu/gna.rst
drivers/gpu/drm/gna/gna_device.c +58 -0

89 lines not on this page · raw message

drivers/gpu/drm/gna/gna_device.h +14 -0
index d2357954b245..035c627e33b7 100644
@@ -20,11 +20,15 @@
 #define DRIVER_MINOR		0
 #define DRIVER_PATCHLEVEL	0
 
+union gna_parameter;
+struct drm_file;
 struct device;
 
 struct gna_device {
 	struct drm_device drm;
 
+	int recovery_timeout_jiffies;
+
 	/* device related resources */
 	void __iomem *iobase;
 	struct gna_dev_info info;
@@ -34,6 +38,11 @@ struct gna_device {
 };
 
 int gna_probe(struct device *parent, struct gna_dev_info *dev_info, void __iomem *iobase);
+int gna_getparam(struct gna_device *gna_priv, union gna_parameter *param);
+
+int gna_getparam_ioctl(struct drm_device *dev, void *data,
+		struct drm_file *file);
+
 static inline u32 gna_reg_read(struct gna_device *gna_priv, u32 reg)
 {
 	return readl(gna_priv->iobase + reg);
@@ -44,4 +53,9 @@ static inline struct device *gna_dev(struct gna_device *gna_priv)
 	return gna_priv->drm.dev;
 }
 
+static inline struct gna_device *to_gna_device(struct drm_device *dev)
+{
+	return container_of(dev, struct gna_device, drm);
+}
+
 #endif /* __GNA_DEVICE_H__ */
drivers/gpu/drm/gna/gna_ioctl.c new file +18 -0
new file mode 100644
index 000000000000..21eb7aae4ad2
@@ -0,0 +1,18 @@
+// SPDX-License-Identifier: GPL-2.0-only
+// Copyright(c) 2017-2022 Intel Corporation
+
+#include <drm/drm_device.h>
+#include <drm/drm_file.h>
+
+#include <uapi/drm/gna_drm.h>
+
+#include "gna_device.h"
+
+int gna_getparam_ioctl(struct drm_device *dev, void *data,
+		struct drm_file *file)
+{
+	struct gna_device *gna_priv = to_gna_device(dev);
+	union gna_parameter *param = data;
+
+	return gna_getparam(gna_priv, param);
+}
include/uapi/drm/gna_drm.h new file +40 -0
new file mode 100644
index 000000000000..5a7cfd7e5df2
@@ -0,0 +1,40 @@
+/* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */
+/* Copyright(c) 2017-2022 Intel Corporation */
+
+#ifndef _GNA_DRM_H_
+#define _GNA_DRM_H_
+
+#include <linux/types.h>
+
+#include "drm.h"
+
+#define GNA_DDI_VERSION_3 3
+
+#define GNA_PARAM_RECOVERY_TIMEOUT	1
+#define GNA_PARAM_DEVICE_TYPE		2
+#define GNA_PARAM_INPUT_BUFFER_S	3
+#define GNA_PARAM_DDI_VERSION		4
+
+#define GNA_DEV_TYPE_0_9	0x09
+#define GNA_DEV_TYPE_1_0	0x10
+#define GNA_DEV_TYPE_2_0	0x20
+#define GNA_DEV_TYPE_3_0	0x30
+#define GNA_DEV_TYPE_3_5	0x35
+
+typedef __u64 gna_param_id;
+
+union gna_parameter {
+	struct {
+		gna_param_id id;
+	} in;
+
+	struct {
+		__u64 value;
+	} out;
+};
+
+#define DRM_GNA_GET_PARAMETER		0x00
+
+#define DRM_IOCTL_GNA_GET_PARAMETER	DRM_IOWR(DRM_COMMAND_BASE + DRM_GNA_GET_PARAMETER, union gna_parameter)
+
+#endif /* _GNA_DRM_H_ */
Signature · 1 line
2.25.1
#18 lore raw

Re: [PATCH v5 05/10] gna: add GNA_GET_PARAMETER ioctl

Quoted 4 lines · Maciej Kwapulinski

From: Tomasz Jankowski <[email protected]>

As this is first ioctl in the series, the patch also adds common bits for remaining ioctls

Again, please read the documentation for what to do here, this is not helpful at all.

drivers/gpu/drm/gna/gna_ioctl.c line 17

Quoted 7 lines
drivers/gpu/drm/gna/gna_ioctl.c new file +7 -0
+int gna_getparam_ioctl(struct drm_device *dev, void *data,
+		struct drm_file *file)
+{
+	struct gna_device *gna_priv = to_gna_device(dev);
+	union gna_parameter *param = data;
+
+	return gna_getparam(gna_priv, param);

Wrong error value returned if you have an invalid ioctl :(

greg k-h

#19 lore raw

PATCH v5 6/10 gna: add GNA_GEM_NEW and GNA_GEM_FREE ioctls

In reply to Maciej Kwapulinski

drm_gem_shmem_object is base for memory objects provided by the patch

---
 drivers/gpu/drm/gna/Kconfig      |  1 +
 drivers/gpu/drm/gna/gna_device.c | 27 +++++++++++-
 drivers/gpu/drm/gna/gna_device.h | 13 ++++++
 drivers/gpu/drm/gna/gna_gem.h    | 15 +++++++
 drivers/gpu/drm/gna/gna_ioctl.c  | 70 ++++++++++++++++++++++++++++++++
 include/uapi/drm/gna_drm.h       | 23 +++++++++++
 6 files changed, 148 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/gna/gna_gem.h
drivers/gpu/drm/gna/Kconfig +1 -0
index e56b933458dc..6c32716bf43a 100644
@@ -6,6 +6,7 @@ config DRM_GNA
 	tristate "Intel(R) Gaussian & Neural Accelerator (Intel(R) GNA)"
 	depends on X86 && PCI
 	depends on DRM
+	select DRM_GEM_SHMEM_HELPER
 	help
 	  This option enables the Intel(R) Gaussian & Neural Accelerator
 	  (Intel(R) GNA) driver: gna
drivers/gpu/drm/gna/gna_device.c +26 -1
index 592478bca526..ab9e16121dcf 100644
@@ -3,20 +3,27 @@
 
 #include <drm/drm_drv.h>
 #include <drm/drm_file.h>
+#include <drm/drm_gem.h>
 #include <drm/drm_ioctl.h>
 #include <drm/drm_managed.h>
 
 #include <linux/device.h>
 #include <linux/dma-mapping.h>
 #include <linux/module.h>
+#include <linux/slab.h>
 
 #include <uapi/drm/gna_drm.h>
 
 #include "gna_device.h"
+#include "gna_gem.h"
 #define GNA_DDI_VERSION_CURRENT GNA_DDI_VERSION_3
 
+DEFINE_DRM_GEM_FOPS(gna_drm_fops);
+
 static const struct drm_ioctl_desc gna_drm_ioctls[] = {
 	DRM_IOCTL_DEF_DRV(GNA_GET_PARAMETER, gna_getparam_ioctl, DRM_RENDER_ALLOW),
+	DRM_IOCTL_DEF_DRV(GNA_GEM_NEW, gna_gem_new_ioctl, DRM_RENDER_ALLOW),
+	DRM_IOCTL_DEF_DRV(GNA_GEM_FREE, gna_gem_free_ioctl, DRM_RENDER_ALLOW),
 };
 
 
@@ -36,10 +43,28 @@ static int gna_drm_dev_init(struct drm_device *dev)
 	return drmm_add_action_or_reset(dev, gna_drm_dev_fini, NULL);
 }
 
+static struct drm_gem_object *gna_create_gem_object(struct drm_device *dev,
+						size_t size)
+{
+	struct drm_gem_shmem_object *dshmem;
+	struct gna_gem_object *shmem;
+
+	shmem = kzalloc(sizeof(*shmem), GFP_KERNEL);
+	if (!shmem)
+		return NULL;
+
+	dshmem = &shmem->base;
+
+	return &dshmem->base;
+}
+
 static const struct drm_driver gna_drm_driver = {
-	.driver_features = DRIVER_RENDER,
+	.driver_features = DRIVER_GEM | DRIVER_RENDER,
+	.gem_create_object = gna_create_gem_object,
+
 	.ioctls = gna_drm_ioctls,
 	.num_ioctls = ARRAY_SIZE(gna_drm_ioctls),
+	.fops = &gna_drm_fops,
 
 	.name = DRIVER_NAME,
 	.desc = DRIVER_DESC,
drivers/gpu/drm/gna/gna_device.h +13 -0
index 035c627e33b7..329729f392d8 100644
@@ -5,10 +5,12 @@
 #define __GNA_DEVICE_H__
 
 #include <drm/drm_device.h>
+#include <drm/drm_gem_shmem_helper.h>
 
 #include <linux/io.h>
 #include <linux/types.h>
 
+#include "gna_gem.h"
 #include "gna_hw.h"
 #include "gna_mem.h"
 
@@ -43,6 +45,12 @@ int gna_getparam(struct gna_device *gna_priv, union gna_parameter *param);
 int gna_getparam_ioctl(struct drm_device *dev, void *data,
 		struct drm_file *file);
 
+int gna_gem_new_ioctl(struct drm_device *dev, void *data,
+		struct drm_file *file);
+
+int gna_gem_free_ioctl(struct drm_device *dev, void *data,
+		struct drm_file *file);
+
 static inline u32 gna_reg_read(struct gna_device *gna_priv, u32 reg)
 {
 	return readl(gna_priv->iobase + reg);
@@ -58,4 +66,9 @@ static inline struct gna_device *to_gna_device(struct drm_device *dev)
 	return container_of(dev, struct gna_device, drm);
 }
 
+static inline struct gna_gem_object *to_gna_gem_obj(struct drm_gem_shmem_object *drm_gem_shmem)
+{
+	return container_of(drm_gem_shmem, struct gna_gem_object, base);
+}
+
 #endif /* __GNA_DEVICE_H__ */
drivers/gpu/drm/gna/gna_gem.h new file +15 -0
new file mode 100644
index 000000000000..f8fa6f35a788
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Copyright(c) 2017-2022 Intel Corporation */
+
+#ifndef __GNA_GEM_H__
+#define __GNA_GEM_H__
+
+#include <drm/drm_gem_shmem_helper.h>
+
+struct gna_gem_object {
+	struct drm_gem_shmem_object base;
+
+	uint32_t handle;
+};
+
+#endif /* __GNA_GEM_H__ */
drivers/gpu/drm/gna/gna_ioctl.c +70 -0

84 lines not on this page · raw message

include/uapi/drm/gna_drm.h +23 -0
index 5a7cfd7e5df2..5391446bad7d 100644
@@ -33,8 +33,31 @@ union gna_parameter {
 	} out;
 };
 
+struct gna_mem_id {
+	__u32 handle;
+	__u32 pad;
+	__u64 vma_fake_offset;
+	__u64 size_granted;
+};
+
+union gna_gem_new {
+	struct {
+		__u64 size;
+	} in;
+
+	struct gna_mem_id out;
+};
+
+struct gna_gem_free {
+	__u32 handle;
+};
+
 #define DRM_GNA_GET_PARAMETER		0x00
+#define DRM_GNA_GEM_NEW			0x01
+#define DRM_GNA_GEM_FREE		0x02
 
 #define DRM_IOCTL_GNA_GET_PARAMETER	DRM_IOWR(DRM_COMMAND_BASE + DRM_GNA_GET_PARAMETER, union gna_parameter)
+#define DRM_IOCTL_GNA_GEM_NEW		DRM_IOWR(DRM_COMMAND_BASE + DRM_GNA_GEM_NEW, union gna_gem_new)
+#define DRM_IOCTL_GNA_GEM_FREE		DRM_IOWR(DRM_COMMAND_BASE + DRM_GNA_GEM_FREE, struct gna_gem_free)
 
 #endif /* _GNA_DRM_H_ */
Signature · 1 line
2.25.1
#20 lore raw

Re: [PATCH v5 06/10] gna: add GNA_GEM_NEW and GNA_GEM_FREE ioctls

Quoted 2 lines · Maciej Kwapulinski

drm_gem_shmem_object is base for memory objects provided by the patch

Here and in some other commit messages don't forget English punctuation, like trailing period.

...

drivers/gpu/drm/gna/gna_gem.h line 12

Quoted 4 lines
drivers/gpu/drm/gna/gna_gem.h new file +4 -0
+struct gna_gem_object {
+       struct drm_gem_shmem_object base;
+
+       uint32_t handle;

Not u32 or __u32? Is it a subsystem requirement to have uint32_t? Or your driver, then why are you not using similar types elsewhere?

Quoted 1 line

+};

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#21 lore raw

PATCH v5 7/10 gna: add GNA_COMPUTE ioctl

In reply to Maciej Kwapulinski

From: Tomasz Jankowski <[email protected]>

This is the ioctl context part of score request + "do nothing" work queue implementation. Work queue context actual part will be added by next patch.

---
 drivers/gpu/drm/gna/Kbuild        |   2 +-
 drivers/gpu/drm/gna/gna_device.c  |  33 +++
 drivers/gpu/drm/gna/gna_device.h  |  21 ++
 drivers/gpu/drm/gna/gna_gem.h     |   4 +
 drivers/gpu/drm/gna/gna_ioctl.c   |  27 +++
 drivers/gpu/drm/gna/gna_mem.c     |  43 ++++
 drivers/gpu/drm/gna/gna_mem.h     |   2 +
 drivers/gpu/drm/gna/gna_request.c | 338 ++++++++++++++++++++++++++++++
 drivers/gpu/drm/gna/gna_request.h |  47 +++++
 include/uapi/drm/gna_drm.h        |  57 +++++
 10 files changed, 573 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/gna/gna_request.c
 create mode 100644 drivers/gpu/drm/gna/gna_request.h
drivers/gpu/drm/gna/Kbuild +1 -1
index 101880869dc4..15c5e4fe7e4d 100644
@@ -1,5 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0-only
 
-gna-y := gna_device.o gna_ioctl.o gna_mem.o gna_pci.o
+gna-y := gna_device.o gna_ioctl.o gna_mem.o gna_pci.o gna_request.o
 
 obj-$(CONFIG_DRM_GNA) += gna.o
drivers/gpu/drm/gna/gna_device.c +33 -0
index ab9e16121dcf..0f8ec5a9dde4 100644
@@ -11,11 +11,14 @@
 #include <linux/dma-mapping.h>
 #include <linux/module.h>
 #include <linux/slab.h>
+#include <linux/workqueue.h>
 
 #include <uapi/drm/gna_drm.h>
 
 #include "gna_device.h"
 #include "gna_gem.h"
+#include "gna_request.h"
+
 #define GNA_DDI_VERSION_CURRENT GNA_DDI_VERSION_3
 
 DEFINE_DRM_GEM_FOPS(gna_drm_fops);
@@ -24,6 +27,7 @@ static const struct drm_ioctl_desc gna_drm_ioctls[] = {
 	DRM_IOCTL_DEF_DRV(GNA_GET_PARAMETER, gna_getparam_ioctl, DRM_RENDER_ALLOW),
 	DRM_IOCTL_DEF_DRV(GNA_GEM_NEW, gna_gem_new_ioctl, DRM_RENDER_ALLOW),
 	DRM_IOCTL_DEF_DRV(GNA_GEM_FREE, gna_gem_free_ioctl, DRM_RENDER_ALLOW),
+	DRM_IOCTL_DEF_DRV(GNA_COMPUTE, gna_score_ioctl, DRM_RENDER_ALLOW),
 };
 
 
@@ -43,6 +47,24 @@ static int gna_drm_dev_init(struct drm_device *dev)
 	return drmm_add_action_or_reset(dev, gna_drm_dev_fini, NULL);
 }
 
+static void gna_workqueue_fini(struct drm_device *drm, void *data)
+{
+	struct workqueue_struct *request_wq = data;
+
+	destroy_workqueue(request_wq);
+}
+
+static int gna_workqueue_init(struct gna_device *gna_priv)
+{
+	const char *name = gna_name(gna_priv);
+
+	gna_priv->request_wq = create_singlethread_workqueue(name);
+	if (!gna_priv->request_wq)
+		return -EFAULT;
+
+	return drmm_add_action_or_reset(&gna_priv->drm, gna_workqueue_fini, gna_priv->request_wq);
+}
+
 static struct drm_gem_object *gna_create_gem_object(struct drm_device *dev,
 						size_t size)
 {
@@ -90,6 +112,8 @@ int gna_probe(struct device *parent, struct gna_dev_info *dev_info, void __iomem
 	gna_priv->iobase = iobase;
 	gna_priv->info = *dev_info;
 
+	atomic_set(&gna_priv->enqueued_requests, 0);
+
 	if (!(sizeof(dma_addr_t) > 4) ||
 		dma_set_mask(parent, DMA_BIT_MASK(64))) {
 		err = dma_set_mask(parent, DMA_BIT_MASK(32));
@@ -106,6 +130,15 @@ int gna_probe(struct device *parent, struct gna_dev_info *dev_info, void __iomem
 
 	dev_dbg(parent, "maximum memory size %llu num pd %d\n",
 		gna_priv->info.max_hw_mem, gna_priv->info.num_pagetables);
+	atomic_set(&gna_priv->request_count, 0);
+
+	mutex_init(&gna_priv->reqlist_lock);
+	INIT_LIST_HEAD(&gna_priv->request_list);
+
+	err = gna_workqueue_init(gna_priv);
+	if (err)
+		return err;
+
 
 	dev_set_drvdata(parent, drm_dev);
 
drivers/gpu/drm/gna/gna_device.h +21 -0
index 329729f392d8..b628ffa9970f 100644
@@ -7,7 +7,10 @@
 #include <drm/drm_device.h>
 #include <drm/drm_gem_shmem_helper.h>
 
+#include <linux/atomic.h>
 #include <linux/io.h>
+#include <linux/list.h>
+#include <linux/mutex.h>
 #include <linux/types.h>
 
 #include "gna_gem.h"
@@ -22,6 +25,7 @@
 #define DRIVER_MINOR		0
 #define DRIVER_PATCHLEVEL	0
 
+struct workqueue_struct;
 union gna_parameter;
 struct drm_file;
 struct device;
@@ -37,6 +41,15 @@ struct gna_device {
 	struct gna_hw_info hw_info;
 
 	struct gna_mmu_object mmu;
+
+	struct list_head request_list;
+	/* protects request_list */
+	struct mutex reqlist_lock;
+	struct workqueue_struct *request_wq;
+	atomic_t request_count;
+
+	/* requests that are in queue to be run +1 for currently processed one */
+	atomic_t enqueued_requests;
 };
 
 int gna_probe(struct device *parent, struct gna_dev_info *dev_info, void __iomem *iobase);
@@ -51,11 +64,19 @@ int gna_gem_new_ioctl(struct drm_device *dev, void *data,
 int gna_gem_free_ioctl(struct drm_device *dev, void *data,
 		struct drm_file *file);
 
+int gna_score_ioctl(struct drm_device *dev, void *data,
+		struct drm_file *file);
+
 static inline u32 gna_reg_read(struct gna_device *gna_priv, u32 reg)
 {
 	return readl(gna_priv->iobase + reg);
 }
 
+static inline const char *gna_name(struct gna_device *gna_priv)
+{
+	return gna_priv->drm.unique;
+}
+
 static inline struct device *gna_dev(struct gna_device *gna_priv)
 {
 	return gna_priv->drm.dev;
drivers/gpu/drm/gna/gna_gem.h +4 -0
index f8fa6f35a788..18ffa8245380 100644
@@ -6,10 +6,14 @@
 
 #include <drm/drm_gem_shmem_helper.h>
 
+#include <linux/workqueue.h>
+
 struct gna_gem_object {
 	struct drm_gem_shmem_object base;
 
 	uint32_t handle;
+
+	struct work_struct work;
 };
 
 #endif /* __GNA_GEM_H__ */
drivers/gpu/drm/gna/gna_ioctl.c +27 -0
index 5051e9af6b06..ab3a2b789589 100644
@@ -5,10 +5,33 @@
 #include <drm/drm_gem_shmem_helper.h>
 #include <drm/drm_file.h>
 
+#include <linux/workqueue.h>
+
 #include <uapi/drm/gna_drm.h>
 
 #include "gna_device.h"
 #include "gna_gem.h"
+#include "gna_request.h"
+
+int gna_score_ioctl(struct drm_device *dev, void *data,
+		struct drm_file *file)
+{
+	union gna_compute *score_args = data;
+	u64 request_id;
+	int ret;
+
+	ret = gna_validate_score_config(&score_args->in.config, to_gna_device(dev));
+	if (ret)
+		return ret;
+
+	ret = gna_enqueue_request(&score_args->in.config, file, &request_id);
+	if (ret)
+		return ret;
+
+	score_args->out.request_id = request_id;
+
+	return 0;
+}
 
 int gna_gem_free_ioctl(struct drm_device *dev, void *data,
 		struct drm_file *file)
@@ -25,6 +48,9 @@ int gna_gem_free_ioctl(struct drm_device *dev, void *data,
 
 	gnagemo = to_gna_gem_obj(to_drm_gem_shmem_obj(drmgemo));
 
+	queue_work(gna_priv->request_wq, &gnagemo->work);
+	cancel_work_sync(&gnagemo->work);
+
 	ret = drm_gem_handle_delete(file, args->handle);
 
 	drm_gem_object_put(drmgemo);
@@ -84,5 +110,6 @@ int gna_gem_new_ioctl(struct drm_device *dev, void *data,
 	gnagemo = to_gna_gem_obj(drmgemshm);
 	gnagemo->handle = args->out.handle;
 
+	INIT_WORK(&gnagemo->work, gna_gem_obj_release_work);
 	return 0;
 }
drivers/gpu/drm/gna/gna_mem.c +43 -0

61 lines not on this page · raw message

drivers/gpu/drm/gna/gna_mem.h +2 -0
index f9b8dcb1399f..9d8251900231 100644
@@ -47,4 +47,6 @@ struct gna_mmu_object {
 
 int gna_mmu_init(struct gna_device *gna_priv);
 
+void gna_gem_obj_release_work(struct work_struct *work);
+
 #endif // __GNA_MEM_H__
drivers/gpu/drm/gna/gna_request.c new file +338 -0

338 lines not on this page · raw message

drivers/gpu/drm/gna/gna_request.h new file +47 -0

47 lines not on this page · raw message

include/uapi/drm/gna_drm.h +57 -0

90 lines not on this page · raw message

Signature · 1 line
2.25.1
#22 lore raw

Re: [PATCH v5 07/10] gna: add GNA_COMPUTE ioctl

Hi Maciej,

thanks for your patch!

Quoted 5 lines · Maciej Kwapulinski

From: Tomasz Jankowski <[email protected]>

This is the ioctl context part of score request + "do nothing" work queue implementation. Work queue context actual part will be added by next patch.

Quoted 8 lines

This patch start to introduce the actual work processing IIUC.

So there is some funny lingo used here that should be in the commit message:

- Patches
- Processes
- Scores

These terms are used without any explanation of what it is and what the purpose is.

"Patches" is especially problematic for kernel developers since we use it for our development work.

Musicians may start to think about the patch cables used on an old analog synthesizer and they call the diffferent sound settings "patches" in analogy with that.

In this case I suspect that "patches" in this context is unrelated to either concept and rather a new name for "computer program executing in funny processor", the same way that graphics people insist in calling their computer programs "shaders". I guess a "process" is one such "patch" executing in the accelerator? I am just guessing. I need to be explained to.

If this is accepted lingo then so be it, but bums like me need to have it spelled out to understand what is going on.

Some examples of patces, processes and scores will be needed in the commit message.

Yours,
Linus Walleij

#23 lore raw

Re: [PATCH v5 07/10] gna: add GNA_COMPUTE ioctl

Quoted 1 line · Linus Walleij

Hi Maciej,

Hi Walleij

Quoted 19 lines

thanks for your patch!

Quoted 5 lines · Maciej Kwapulinski

From: Tomasz Jankowski <[email protected]>

This is the ioctl context part of score request + "do nothing" work queue implementation. Work queue context actual part will be added by next patch.

Quoted 8 lines
Quoted 8 lines

This patch start to introduce the actual work processing IIUC.

So there is some funny lingo used here that should be in the commit message:

- Patches
- Processes
- Scores

patching operation here is in fact the operation of modifying the set of memory cells described by offsets (provided in score request during ioctl) with some values (also provided in the same score request during ioctl). memory cells pointed by offsets belong to memory regions (also being the part of the same score request).

Score requests are put by ioctl to gna_device::request_list FIFO queue and are later processed by gna_device::request_wq work thread one by one. request_wq is the entity that sends requests to GNA device, and just before doing so it 'PATCHES' the memory in a manner described by score request.  request_wq has exclusive access to GNA device.

'Score' is term taken from AI, but from the perspective above, where driver does not (have to) know what is passed to GNA device, maybe we should not use the term 'score' at all. Also, maybe 'patch' should also be renamed on something more agnostic/generic.

#24 lore raw

Re: [PATCH v5 07/10] gna: add GNA_COMPUTE ioctl

Quoted 3 lines · Maciej Kwapulinski
Quoted 1 line · Linus Walleij

Hi Maciej,

Hi Walleij

oo sorry,  hi Linus

I should say

#25 lore raw

PATCH v5 8/10 gna: add GNA_WAIT ioctl

In reply to Maciej Kwapulinski

From: Tomasz Jankowski <[email protected]>

Although the patch adds GNA_WAIT ioctl, it's main purpose is to provide FIFO work-queue logic, which offloads each score operation in sequence to GNA accelerator. When it's done, process(es) WAITing for score to be finished are woken up.

---
 drivers/gpu/drm/gna/Kbuild        |   2 +-
 drivers/gpu/drm/gna/gna_device.c  |  26 +++-
 drivers/gpu/drm/gna/gna_device.h  |  18 ++-
 drivers/gpu/drm/gna/gna_gem.h     |   3 +
 drivers/gpu/drm/gna/gna_hw.c      | 110 +++++++++++++++
 drivers/gpu/drm/gna/gna_hw.h      |  30 ++++
 drivers/gpu/drm/gna/gna_ioctl.c   |  93 +++++++++++++
 drivers/gpu/drm/gna/gna_mem.c     | 128 +++++++++++++++++
 drivers/gpu/drm/gna/gna_mem.h     |   6 +
 drivers/gpu/drm/gna/gna_pci.c     |  34 ++++-
 drivers/gpu/drm/gna/gna_request.c |  88 ++++++++++++
 drivers/gpu/drm/gna/gna_request.h |  17 +++
 drivers/gpu/drm/gna/gna_score.c   | 222 ++++++++++++++++++++++++++++++
 drivers/gpu/drm/gna/gna_score.h   |  11 ++
 include/uapi/drm/gna_drm.h        |  49 +++++++
 15 files changed, 833 insertions(+), 4 deletions(-)
 create mode 100644 drivers/gpu/drm/gna/gna_hw.c
 create mode 100644 drivers/gpu/drm/gna/gna_score.c
 create mode 100644 drivers/gpu/drm/gna/gna_score.h
drivers/gpu/drm/gna/Kbuild +1 -1
index 15c5e4fe7e4d..d799c9530f79 100644
@@ -1,5 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0-only
 
-gna-y := gna_device.o gna_ioctl.o gna_mem.o gna_pci.o gna_request.o
+gna-y := gna_device.o gna_hw.o gna_ioctl.o gna_mem.o gna_pci.o gna_request.o gna_score.o
 
 obj-$(CONFIG_DRM_GNA) += gna.o
drivers/gpu/drm/gna/gna_device.c +25 -1
index 0f8ec5a9dde4..2ef5be16dc9a 100644
@@ -9,6 +9,7 @@
 
 #include <linux/device.h>
 #include <linux/dma-mapping.h>
+#include <linux/interrupt.h>
 #include <linux/module.h>
 #include <linux/slab.h>
 #include <linux/workqueue.h>
@@ -28,6 +29,7 @@ static const struct drm_ioctl_desc gna_drm_ioctls[] = {
 	DRM_IOCTL_DEF_DRV(GNA_GEM_NEW, gna_gem_new_ioctl, DRM_RENDER_ALLOW),
 	DRM_IOCTL_DEF_DRV(GNA_GEM_FREE, gna_gem_free_ioctl, DRM_RENDER_ALLOW),
 	DRM_IOCTL_DEF_DRV(GNA_COMPUTE, gna_score_ioctl, DRM_RENDER_ALLOW),
+	DRM_IOCTL_DEF_DRV(GNA_WAIT, gna_wait_ioctl, DRM_RENDER_ALLOW),
 };
 
 
@@ -47,6 +49,16 @@ static int gna_drm_dev_init(struct drm_device *dev)
 	return drmm_add_action_or_reset(dev, gna_drm_dev_fini, NULL);
 }
 
+static irqreturn_t gna_interrupt(int irq, void *priv)
+{
+	struct gna_device *gna_priv;
+
+	gna_priv = (struct gna_device *)priv;
+	gna_priv->dev_busy = false;
+	wake_up(&gna_priv->dev_busy_waitq);
+	return IRQ_HANDLED;
+}
+
 static void gna_workqueue_fini(struct drm_device *drm, void *data)
 {
 	struct workqueue_struct *request_wq = data;
@@ -96,7 +108,7 @@ static const struct drm_driver gna_drm_driver = {
 	.patchlevel = DRIVER_PATCHLEVEL,
 };
 
-int gna_probe(struct device *parent, struct gna_dev_info *dev_info, void __iomem *iobase)
+int gna_probe(struct device *parent, struct gna_dev_info *dev_info, void __iomem *iobase, int irq)
 {
 	struct gna_device *gna_priv;
 	struct drm_device *drm_dev;
@@ -130,15 +142,27 @@ int gna_probe(struct device *parent, struct gna_dev_info *dev_info, void __iomem
 
 	dev_dbg(parent, "maximum memory size %llu num pd %d\n",
 		gna_priv->info.max_hw_mem, gna_priv->info.num_pagetables);
+	dev_dbg(parent, "desc rsvd size %d mmu vamax size %d\n",
+		gna_priv->info.desc_info.rsvd_size,
+		gna_priv->info.desc_info.mmu_info.vamax_size);
+
+	mutex_init(&gna_priv->mmu_lock);
+
 	atomic_set(&gna_priv->request_count, 0);
 
 	mutex_init(&gna_priv->reqlist_lock);
 	INIT_LIST_HEAD(&gna_priv->request_list);
 
+	init_waitqueue_head(&gna_priv->dev_busy_waitq);
+
 	err = gna_workqueue_init(gna_priv);
 	if (err)
 		return err;
 
+	err = devm_request_irq(parent, irq, gna_interrupt,
+			IRQF_SHARED, gna_name(gna_priv), gna_priv);
+	if (err)
+		return err;
 
 	dev_set_drvdata(parent, drm_dev);
 
drivers/gpu/drm/gna/gna_device.h +17 -1
index b628ffa9970f..ffdc3d1d1f87 100644
@@ -35,12 +35,20 @@ struct gna_device {
 
 	int recovery_timeout_jiffies;
 
+	/* hardware status set by interrupt handler */
+	u32 hw_status;
+
 	/* device related resources */
 	void __iomem *iobase;
 	struct gna_dev_info info;
 	struct gna_hw_info hw_info;
 
 	struct gna_mmu_object mmu;
+	struct mutex mmu_lock;
+
+	/* if true, then gna device is processing */
+	bool dev_busy;
+	struct wait_queue_head dev_busy_waitq;
 
 	struct list_head request_list;
 	/* protects request_list */
@@ -52,7 +60,7 @@ struct gna_device {
 	atomic_t enqueued_requests;
 };
 
-int gna_probe(struct device *parent, struct gna_dev_info *dev_info, void __iomem *iobase);
+int gna_probe(struct device *parent, struct gna_dev_info *dev_info, void __iomem *iobase, int irq);
 int gna_getparam(struct gna_device *gna_priv, union gna_parameter *param);
 
 int gna_getparam_ioctl(struct drm_device *dev, void *data,
@@ -67,11 +75,19 @@ int gna_gem_free_ioctl(struct drm_device *dev, void *data,
 int gna_score_ioctl(struct drm_device *dev, void *data,
 		struct drm_file *file);
 
+int gna_wait_ioctl(struct drm_device *dev, void *data,
+		struct drm_file *file);
+
 static inline u32 gna_reg_read(struct gna_device *gna_priv, u32 reg)
 {
 	return readl(gna_priv->iobase + reg);
 }
 
+static inline void gna_reg_write(struct gna_device *gna_priv, u32 reg, u32 val)
+{
+	writel(val, gna_priv->iobase + reg);
+}
+
 static inline const char *gna_name(struct gna_device *gna_priv)
 {
 	return gna_priv->drm.unique;
drivers/gpu/drm/gna/gna_gem.h +3 -0
index 18ffa8245380..92372fc93718 100644
@@ -6,6 +6,7 @@
 
 #include <drm/drm_gem_shmem_helper.h>
 
+#include <linux/wait.h>
 #include <linux/workqueue.h>
 
 struct gna_gem_object {
@@ -14,6 +15,8 @@ struct gna_gem_object {
 	uint32_t handle;
 
 	struct work_struct work;
+
+	struct wait_queue_head waitq;
 };
 
 #endif /* __GNA_GEM_H__ */
drivers/gpu/drm/gna/gna_hw.c new file +110 -0

110 lines not on this page · raw message

drivers/gpu/drm/gna/gna_hw.h +30 -0
index 514166a87c4d..97338e1be3b6 100644
@@ -4,8 +4,12 @@
 #ifndef __GNA_HW_H__
 #define __GNA_HW_H__
 
+#include <linux/bits.h>
 #include <linux/mm_types.h>
 
+struct gna_compute_cfg;
+struct gna_device;
+
 #define GNA_FEATURES						\
 	.max_hw_mem = 256 * 1024 * 1024,			\
 		.num_pagetables = 64,				\
@@ -42,11 +46,30 @@
 #define GNA_DEV_HWID_MTL	0x7E4C
 
 /* GNA MMIO registers */
+#define GNA_MMIO_STS		0x80
+#define GNA_MMIO_CTRL		0x84
+#define GNA_MMIO_PTC		0x8C
+#define GNA_MMIO_PSC		0x90
+#define GNA_MMIO_D0I3C		0xA8
+#define GNA_MMIO_DESBASE	0xB0
 #define GNA_MMIO_IBUFFS		0xB4
 
+#define GNA_PT_ENTRY_SIZE		4
+/* there are up to 1024 32-bit pointers in one page in Page Table (L1) */
+#define GNA_PT_LENGTH           (PAGE_SIZE / GNA_PT_ENTRY_SIZE)
+
 #define GNA_PGDIRN_LEN			64
+#define GNA_PGDIR_ENTRIES		1024 /* 32-bit page addresses */
 #define GNA_PGDIR_INVALID		1
 
+#define GNA_CTRL_START_ACCEL		BIT(0)
+#define GNA_CTRL_ACTIVE_LIST_EN		BIT(1)
+#define GNA_CTRL_ABORT_CLR_ACCEL	BIT(2)
+#define GNA_CTRL_OP_MODE		GENMASK(6, 5)
+#define GNA_CTRL_COMP_INT_EN		BIT(8)
+#define GNA_CTRL_ERR_INT_EN		BIT(10)
+#define GNA_CTRL_COMP_STATS_EN		GENMASK(15, 12)
+
 struct gna_mmu_info {
 	u32 vamax_size;
 	u32 rsvd_size;
@@ -74,4 +97,11 @@ struct gna_dev_info {
 	struct gna_desc_info desc_info;
 };
 
+int gna_abort_hw(struct gna_device *gna_priv);
+bool gna_hw_perf_enabled(struct gna_device *gna_priv);
+int gna_parse_hw_status(struct gna_device *gna_priv, u32 hw_status);
+void gna_print_error_status(struct gna_device *gna_priv, u32 hw_status);
+void gna_start_scoring(struct gna_device *gna_priv,
+		struct gna_compute_cfg *compute_cfg);
+
 #endif // __GNA_HW_H__
drivers/gpu/drm/gna/gna_ioctl.c +93 -0

120 lines not on this page · raw message

drivers/gpu/drm/gna/gna_mem.c +128 -0

150 lines not on this page · raw message

drivers/gpu/drm/gna/gna_mem.h +6 -0
index 9d8251900231..92193f9d608d 100644
@@ -47,6 +47,12 @@ struct gna_mmu_object {
 
 int gna_mmu_init(struct gna_device *gna_priv);
 
+void gna_mmu_add(struct gna_device *gna_priv, struct drm_gem_shmem_object *drmshmemo);
+
+void gna_mmu_clear(struct gna_device *gna_priv);
+
+bool gna_gem_object_put_pages_sgt(struct gna_gem_object *gna_obj);
+
 void gna_gem_obj_release_work(struct work_struct *work);
 
 #endif // __GNA_MEM_H__
drivers/gpu/drm/gna/gna_pci.c +33 -1
index 9a6c82362e32..034554b417a8 100644
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0-only
 // Copyright(c) 2017-2022 Intel Corporation
 
+#include <linux/device.h>
 #include <linux/module.h>
 #include <linux/pci.h>
 
@@ -75,10 +76,33 @@ static const struct pci_device_id gna_pci_ids[] = {
 	{ }
 };
 
+static void gna_irq_vectors_fini(void *data)
+{
+	struct pci_dev *pcidev = data;
+
+	pci_free_irq_vectors(pcidev);
+}
+
+static int gna_irq_vectors_init(struct pci_dev *pcidev)
+{
+	int ret;
+
+	ret = pci_alloc_irq_vectors(pcidev, 1, 1, PCI_IRQ_ALL_TYPES);
+	if (ret < 0)
+		return ret;
+
+	ret = devm_add_action(&pcidev->dev, gna_irq_vectors_fini, pcidev);
+	if (ret)
+		gna_irq_vectors_fini(pcidev);
+
+	return ret;
+}
+
 int gna_pci_probe(struct pci_dev *pcidev, const struct pci_device_id *pci_id)
 {
 	struct gna_dev_info *dev_info;
 	void __iomem *iobase;
+	int irq;
 	int err;
 
 	err = pcim_enable_device(pcidev);
@@ -93,9 +117,17 @@ int gna_pci_probe(struct pci_dev *pcidev, const struct pci_device_id *pci_id)
 
 	pci_set_master(pcidev);
 
+	err = gna_irq_vectors_init(pcidev);
+	if (err < 0)
+		return err;
+
+	irq = pci_irq_vector(pcidev, 0);
+	if (irq < 0)
+		return irq;
+
 	dev_info = (struct gna_dev_info *)pci_id->driver_data;
 
-	err = gna_probe(&pcidev->dev, dev_info, iobase);
+	err = gna_probe(&pcidev->dev, dev_info, iobase, irq);
 	if (err)
 		return err;
 
drivers/gpu/drm/gna/gna_request.c +88 -0

130 lines not on this page · raw message

drivers/gpu/drm/gna/gna_request.h +17 -0
index 432c30863e7e..d056e70fb369 100644
@@ -6,6 +6,7 @@
 
 #include <linux/kref.h>
 #include <linux/types.h>
+#include <linux/wait.h>
 #include <linux/workqueue.h>
 
 #include <uapi/drm/gna_drm.h>
@@ -14,6 +15,12 @@ struct gna_device;
 struct gna_gem_object;
 struct drm_file;
 
+enum gna_request_state {
+	NEW,
+	ACTIVE,
+	DONE,
+};
+
 struct gna_buffer_with_object {
 	struct gna_buffer gna;
 	struct gna_gem_object *gem;
@@ -26,6 +33,15 @@ struct gna_request {
 
 	struct drm_file *drm_f;
 
+	u32 hw_status;
+
+	enum gna_request_state state;
+
+	int status;
+
+	struct gna_hw_perf hw_perf;
+	struct gna_drv_perf drv_perf;
+
 	struct list_head node;
 
 	struct gna_compute_cfg compute_cfg;
@@ -34,6 +50,7 @@ struct gna_request {
 	u64 buffer_count;
 
 	struct work_struct work;
+	struct wait_queue_head waitq;
 };
 
 int gna_validate_score_config(struct gna_compute_cfg *compute_cfg,
drivers/gpu/drm/gna/gna_score.c new file +222 -0

222 lines not on this page · raw message

drivers/gpu/drm/gna/gna_score.h new file +11 -0
new file mode 100644
index 000000000000..5b154d3623e0
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Copyright(c) 2017-2022 Intel Corporation */
+
+#ifndef __GNA_SCORE_H__
+#define __GNA_SCORE_H__
+
+struct gna_request;
+
+int gna_score(struct gna_request *score_request);
+
+#endif // __GNA_SCORE_H__
include/uapi/drm/gna_drm.h +49 -0

77 lines not on this page · raw message

Signature · 1 line
2.25.1
#26 lore raw

Re: [PATCH v5 08/10] gna: add GNA_WAIT ioctl

Quoted 6 lines · Maciej Kwapulinski

From: Tomasz Jankowski <[email protected]>

Although the patch adds GNA_WAIT ioctl, it's main purpose is to provide FIFO work-queue logic, which offloads each score operation in sequence to GNA accelerator. When it's done, process(es) WAITing for score to be finished are woken up.

I do not understand the "Although" here at all :(

drivers/gpu/drm/gna/gna_device.c static int gna_drm_dev_init(struct drm_device *dev) · line 60

Quoted 9 lines
drivers/gpu/drm/gna/gna_device.c +9 -0
+static irqreturn_t gna_interrupt(int irq, void *priv)
+{
+	struct gna_device *gna_priv;
+
+	gna_priv = (struct gna_device *)priv;
+	gna_priv->dev_busy = false;
+	wake_up(&gna_priv->dev_busy_waitq);
+	return IRQ_HANDLED;
+}

irq handling, nice! Why wan't that discussed in the changelog?

{sigh}

I'm stopping here, this needs lots of work to make it reviewable to understand what is going on at all.

Please take the time and get proper internal-Intel review first, before asking community members to take their time to tell you the things that they should have already told you.

thanks,

greg k-h

#27 lore raw

PATCH v5 9/10 gna: add power management

In reply to Maciej Kwapulinski

Implement power management in GNA driver

---
 drivers/gpu/drm/gna/gna_device.c  | 47 +++++++++++++++++++++++++++++++
 drivers/gpu/drm/gna/gna_device.h  |  3 ++
 drivers/gpu/drm/gna/gna_pci.c     |  3 ++
 drivers/gpu/drm/gna/gna_request.c | 15 ++++++++++
 4 files changed, 68 insertions(+)
drivers/gpu/drm/gna/gna_device.c +47 -0
index 2ef5be16dc9a..aee409e3b4ea 100644
@@ -32,6 +32,32 @@ static const struct drm_ioctl_desc gna_drm_ioctls[] = {
 	DRM_IOCTL_DEF_DRV(GNA_WAIT, gna_wait_ioctl, DRM_RENDER_ALLOW),
 };
 
+static int __maybe_unused gna_runtime_suspend(struct device *dev)
+{
+	struct drm_device *drm_dev = dev_get_drvdata(dev);
+	struct gna_device *gna_priv = to_gna_device(drm_dev);
+	u32 val = gna_reg_read(gna_priv, GNA_MMIO_D0I3C);
+
+	dev_dbg(dev, "%s D0I3, reg %.8x\n", __func__, val);
+
+	return 0;
+}
+
+static int __maybe_unused gna_runtime_resume(struct device *dev)
+{
+	struct drm_device *drm_dev = dev_get_drvdata(dev);
+	struct gna_device *gna_priv = to_gna_device(drm_dev);
+	u32 val = gna_reg_read(gna_priv, GNA_MMIO_D0I3C);
+
+	dev_dbg(dev, "%s D0I3, reg %.8x\n", __func__, val);
+
+	return 0;
+}
+
+const struct dev_pm_ops __maybe_unused gna_pm = {
+	SET_RUNTIME_PM_OPS(gna_runtime_suspend, gna_runtime_resume, NULL)
+};
+
 
 static void gna_drm_dev_fini(struct drm_device *dev, void *ptr)
 {
@@ -49,6 +75,22 @@ static int gna_drm_dev_init(struct drm_device *dev)
 	return drmm_add_action_or_reset(dev, gna_drm_dev_fini, NULL);
 }
 
+static void gna_pm_init(struct device *dev)
+{
+	pm_runtime_set_autosuspend_delay(dev, 2000);
+	pm_runtime_use_autosuspend(dev);
+	pm_runtime_mark_last_busy(dev);
+	pm_runtime_allow(dev);
+	pm_runtime_put_noidle(dev);
+}
+
+static void gna_pm_fini(struct drm_device *drm, void *data)
+{
+	struct device *dev = data;
+
+	pm_runtime_get_noresume(dev);
+}
+
 static irqreturn_t gna_interrupt(int irq, void *priv)
 {
 	struct gna_device *gna_priv;
@@ -170,6 +212,11 @@ int gna_probe(struct device *parent, struct gna_dev_info *dev_info, void __iomem
 	if (err)
 		return err;
 
+	gna_pm_init(parent);
+	err = drmm_add_action(drm_dev, gna_pm_fini, parent);
+	if (err)
+		return err;
+
 	return 0;
 }
 
drivers/gpu/drm/gna/gna_device.h +3 -0
index ffdc3d1d1f87..6eae0f2f44df 100644
@@ -11,6 +11,7 @@
 #include <linux/io.h>
 #include <linux/list.h>
 #include <linux/mutex.h>
+#include <linux/pm_runtime.h>
 #include <linux/types.h>
 
 #include "gna_gem.h"
@@ -78,6 +79,8 @@ int gna_score_ioctl(struct drm_device *dev, void *data,
 int gna_wait_ioctl(struct drm_device *dev, void *data,
 		struct drm_file *file);
 
+extern const struct dev_pm_ops __maybe_unused gna_pm;
+
 static inline u32 gna_reg_read(struct gna_device *gna_priv, u32 reg)
 {
 	return readl(gna_priv->iobase + reg);
drivers/gpu/drm/gna/gna_pci.c +3 -0
index 034554b417a8..eaae42142bfb 100644
@@ -138,6 +138,9 @@ static struct pci_driver gna_pci_driver = {
 	.name = DRIVER_NAME,
 	.id_table = gna_pci_ids,
 	.probe = gna_pci_probe,
+	.driver = {
+		.pm = &gna_pm,
+	},
 };
 
 module_pci_driver(gna_pci_driver);
drivers/gpu/drm/gna/gna_request.c +15 -0
index 9efaea61ac68..1d9572bedcc2 100644
@@ -11,6 +11,7 @@
 #include <linux/list.h>
 #include <linux/math.h>
 #include <linux/mutex.h>
+#include <linux/pm_runtime.h>
 #include <linux/slab.h>
 #include <linux/timekeeping.h>
 #include <linux/uaccess.h>
@@ -110,6 +111,14 @@ static void gna_request_process(struct work_struct *work)
 
 	score_request->drv_perf.pre_processing = ktime_get_ns();
 
+	ret = pm_runtime_get_sync(gna_dev(gna_priv));
+	if (ret < 0 && ret != -EACCES) {
+		dev_warn(gna_dev(gna_priv), "pm_runtime_get_sync() failed: %d\n", ret);
+		score_request->status = -ENODEV;
+		pm_runtime_put_noidle(gna_dev(gna_priv));
+		goto tail;
+	}
+
 	/* Set busy flag before kicking off HW. The isr will clear it and wake up us. There is
 	 * no difference if isr is missed in a timeout situation of the last request. We just
 	 * always set it busy and let the wait_event_timeout check the reset.
@@ -120,6 +129,8 @@ static void gna_request_process(struct work_struct *work)
 
 	ret = gna_score(score_request);
 	if (ret) {
+		if (pm_runtime_put(gna_dev(gna_priv)) < 0)
+			dev_warn(gna_dev(gna_priv), "pm_runtime_put() failed: %d\n", ret);
 		score_request->status = ret;
 		goto tail;
 	}
@@ -142,6 +153,10 @@ static void gna_request_process(struct work_struct *work)
 	if (ret < 0 && score_request->status == 0)
 		score_request->status = ret; // -ETIMEDOUT
 
+	ret = pm_runtime_put(gna_dev(gna_priv));
+	if (ret < 0)
+		dev_warn(gna_dev(gna_priv), "pm_runtime_put() failed: %d\n", ret);
+
 	gna_mmu_clear(gna_priv);
 
 	for (i = 0, buffer = score_request->buffer_list; i < score_request->buffer_count; i++, buffer++)
Signature · 1 line
2.25.1
#28 lore raw

Re: [PATCH v5 09/10] gna: add power management

Quoted 8 lines · Maciej Kwapulinski

Implement power management in GNA driver

You probably want Rafael Wysocki to review this patch so you get (runtime) PM absolutely right.

Yours,
Linus Walleij

#29 lore raw

PATCH v5 10/10 gna: add open and close operations on GNA device

In reply to Maciej Kwapulinski

From: Tomasz Jankowski <[email protected]>

---
 drivers/gpu/drm/gna/gna_device.c | 46 ++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)
drivers/gpu/drm/gna/gna_device.c +46 -0
index aee409e3b4ea..4ce08bf313c3 100644
@@ -58,6 +58,49 @@ const struct dev_pm_ops __maybe_unused gna_pm = {
 	SET_RUNTIME_PM_OPS(gna_runtime_suspend, gna_runtime_resume, NULL)
 };
 
+static int gna_open(struct drm_device *dev, struct drm_file *file)
+{
+	struct gna_device *gna_priv;
+
+	gna_priv = to_gna_device(dev);
+
+	file->driver_priv = gna_priv;
+
+	return 0;
+}
+
+static void gna_delete_file_requests(struct drm_file *file, struct gna_device *gna_priv)
+{
+	struct gna_request *req, *temp_req;
+	struct list_head *reqs_list;
+
+	mutex_lock(&gna_priv->reqlist_lock);
+
+	reqs_list = &gna_priv->request_list;
+	if (!list_empty(reqs_list)) {
+		list_for_each_entry_safe(req, temp_req, reqs_list, node) {
+			if (req->drm_f == file) {
+				bool is_pending;
+
+				list_del_init(&req->node);
+				is_pending = cancel_work_sync(&req->work);
+				if (is_pending)
+					atomic_dec(&gna_priv->enqueued_requests);
+				kref_put(&req->refcount, gna_request_release);
+				break;
+			}
+		}
+	}
+
+	mutex_unlock(&gna_priv->reqlist_lock);
+}
+
+static void gna_close(struct drm_device *dev, struct drm_file *file)
+{
+	struct gna_device *gna_priv = (struct gna_device *)file->driver_priv;
+
+	gna_delete_file_requests(file, gna_priv);
+}
 
 static void gna_drm_dev_fini(struct drm_device *dev, void *ptr)
 {
@@ -136,6 +179,9 @@ static struct drm_gem_object *gna_create_gem_object(struct drm_device *dev,
 
 static const struct drm_driver gna_drm_driver = {
 	.driver_features = DRIVER_GEM | DRIVER_RENDER,
+	.open = gna_open,
+	.postclose = gna_close,
+
 	.gem_create_object = gna_create_gem_object,
 
 	.ioctls = gna_drm_ioctls,
Signature · 1 line
2.25.1
#30 lore raw

Re: [PATCH v5 10/10] gna: add open and close operations on GNA device

Quoted 8 lines · Maciej Kwapulinski

From: Tomasz Jankowski <[email protected]>

That's a lot of people who missed that there is nothing described here at all :(

Please please please work with the Intel internal kernel developers and get this all reviewed properly first before sending anything out again. I want to see their signed-off-by or reviewed-by on them before anything is sent out again.

thanks,

greg k-h

#31 lore raw

Re: [PATCH v5 10/10] gna: add open and close operations on GNA device

Quoted 11 lines · Greg Kroah-Hartman
Quoted 8 lines · Maciej Kwapulinski

From: Tomasz Jankowski <[email protected]>

Quoted 7 lines

That's a lot of people who missed that there is nothing described here at all :(

Please please please work with the Intel internal kernel developers and get this all reviewed properly first before sending anything out again. I want to see their signed-off-by or reviewed-by on them before anything is sent out again.

This is partially on me, because I'm asking everyone (including intel folks) to ditch internal review for dri-devel patches and submit directly.

Of course that means you can get stuff like this which isn't really reviewable.

This part here is for the gna folks, not for Greg.

Now the other side of dri-devel review is that generally subsystem maintainers never ever look at the patches, and instead we fully rely on peer review.

This means:
- you review other people's driver patches, ideally also in the accel/render space and not so much display drm drivers (there's plenty of everything)
- you ask these people to review your patches
- usually one of them has commit rights already and can push the stuff, if not _then_ and only then ask maintainers to land things

Quick search on lore says that gna posts on dri-devel have been rather one-way thus far. Someone has to pay for upstream/community review of your gna patches, and tit-for-tat economy is about the best we've figured out thus far. Also tit-for-tat will get rid of unreviewable patches real fast in my opinion because suddenly it becomes very important that you're not squandering the painfully acquired review credits you have on pointless stuff.

If you need help in figuring out what other patches you can review please show up on #dri-devel irc on oftc, there's tons of people there usually and we have enormous piles of patches inflight at any moment.

Back to Greg: I much appreciate you reviewing all the various (occasionally nonsense) patches dri-devel comes up with, but maybe it's best if you set the gna (and vpu too I guess) driver efforts onto your ignore lists? I assume you very much want to stay up to date on the patches that come out of the accel bof discussion from Oded, and I guess i915 folks having questions about driver/pm changes is also good. But for the random oddball drivers intel's pushing I think it's just net negative on your time here.

Plan B is that we also put stern limits into place for intel patches to dri-devel, but looking at gna+vpu we already seem to have a one-way dumping ground going on, so I really don't want to encourage intel to be even more a silo and disappear behind the company firewall.

Cheers, Daniel

Quoted 4 lines

thanks,

greg k-h

--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

#32 lore raw
In reply to Maciej Kwapulinski
Quoted 15 lines · Maciej Kwapulinski

Dear kernel maintainers,

This submission is a kernel driver to support Intel(R) Gaussian & Neural Accelerator (Intel(R) GNA). Intel(R) GNA is a PCI-based neural co-processor available on multiple Intel platforms. AI developers and users can offload continuous inference workloads to an Intel(R) GNA device in order to free processor resources and save power. Noise reduction and speech recognition are the examples of the workloads Intel(R) GNA deals with while its usage is not limited to the two.

For a list of processors equipped with Intel(R) GNA device, please refer to this link:
https://docs.openvinotoolkit.org/latest/openvino_docs_IE_DG_supported_plugins_GNA.html

Quoted 5 lines

We think contributing this driver to the upstream kernel project is the best way for developers and users to get the latest Intel(R) GNA support in a Linux kernel, through the mainline to any Linux distributions installed on their systems. Upstreaming also enables contribution from developers around the world to the driver once it is merged.

Can you replace all those dev_dbg():s by trace events/points?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#34 lore raw
Quoted 7 lines · Greg Kroah-Hartman
Quoted 1 line · Maciej Kwapulinski

Dear kernel maintainers,

<snip>

This really is v6, not v5, right? Why send 2 v5 out?

greg k-h

what do you mean?

#35 lore raw
In reply to Maciej Kwapulinski

Hi

Am 20.10.22 um 19:53 schrieb Maciej Kwapulinski:

Quoted 20 lines

Dear kernel maintainers,

This submission is a kernel driver to support Intel(R) Gaussian & Neural Accelerator (Intel(R) GNA). Intel(R) GNA is a PCI-based neural co-processor available on multiple Intel platforms. AI developers and users can offload continuous inference workloads to an Intel(R) GNA device in order to free processor resources and save power. Noise reduction and speech recognition are the examples of the workloads Intel(R) GNA deals with while its usage is not limited to the two.

For a list of processors equipped with Intel(R) GNA device, please refer to this link:
https://docs.openvinotoolkit.org/latest/openvino_docs_IE_DG_supported_plugins_GNA.html

We think contributing this driver to the upstream kernel project is the best way for developers and users to get the latest Intel(R) GNA support in a Linux kernel, through the mainline to any Linux distributions installed on their systems. Upstreaming also enables contribution from developers around the world to the driver once it is merged.

Quoted 4 lines

The driver works with Intel(R) libraries in user space. The Intel(R) driver exposes a few IOCTL interfaces for use by libraries in user space. The libraries are open sourced and are available at:
https://github.com/intel/gna

This driver appears to be a candidate for the accel subsystem that has been proposed here. [1] At a minimum, you'd now get standardized file names. Longterm, I'd expect dedicated helpers for accel devices.

Best regards
Thomas

[1] https://lore.kernel.org/dri-devel/[email protected]/T/#m977efaeb39fc5be581ae05e1dccbd896546db943

Quoted 103 lines

---

Changelogs:

v1->v2:
- driver's new layout:
- driver name: gna -> intel_gna
- module name: gna -> intel_gna
- device file name: /dev/gnaN -> /dev/intel_gnaN
- driver's source directory: drivers/misc/gna/ -> drivers/misc/intel/gna/
- UAPI: include/uapi/misc/gna.h -> include/uapi/misc/intel/gna.h
- DOC: Documentation/misc-devices/gna.rst -> Documentation/misc-devices/intel/gna.rst
- 'MISC' device framework used
- fixes throughout GNA device's PCI management
- header files' includes and forward declarations cleanup
- ISR made static
- unused comments cleanup
- "_priv_" segment removed from function names
- tested: v5.11-rc3 -> v5.11
- number of other/minor fixes

v2->v3:
- PCI glue driver part split.
- GNA probe fail path made fully implicit.
- 'recovery_timeout' module parameter present under 'CONFIG_DEBUG_INTEL_GNA' flag only.
- build for X86_32 enabled.
- module initialization through 'module_pci_driver()'.
- gna_priv->file_list cleanup.
- 'gna_' prefix removed from source files' names.
- power management handling added.
- number of other/minor fixes
- tests performed on kernel v5.12

v3->v4:
- GNA driver adapted to DRM framework (+userspace GNA library adapted to use the driver)
- drm_managed (drmm) feature is used for objects lifetime management
- GNA memory objects use ~drm_gem_shmem_object~ objects as a base
- patches reorganized to meet symbols' usage with their declarations/definitions
- 'recovery_timeout' module parameter removed
- number of other/minor fixes from v3 review
- tests performed on kernel v6.0

v4->v5:
- indentation fixed in drivers/gpu/drm/gna/Kconfig

Maciej Kwapulinski (4):
gna: add PCI driver module
gna: add GNA DRM device
gna: add GNA_GEM_NEW and GNA_GEM_FREE ioctls
gna: add power management

Tomasz Jankowski (6):
gna: read hardware info
gna: initialize MMU
gna: add GNA_GET_PARAMETER ioctl
gna: add GNA_COMPUTE ioctl
gna: add GNA_WAIT ioctl
gna: add open and close operations on GNA device

  Documentation/gpu/drivers.rst     |   1 +
  Documentation/gpu/gna.rst         |  64 +++++
  MAINTAINERS                       |   7 +
  drivers/gpu/drm/Kconfig           |   2 +
  drivers/gpu/drm/Makefile          |   1 +
  drivers/gpu/drm/gna/Kbuild        |   5 +
  drivers/gpu/drm/gna/Kconfig       |  15 +
  drivers/gpu/drm/gna/gna_device.c  | 317 +++++++++++++++++++++
  drivers/gpu/drm/gna/gna_device.h  | 114 ++++++++
  drivers/gpu/drm/gna/gna_gem.h     |  22 ++
  drivers/gpu/drm/gna/gna_hw.c      | 110 ++++++++
  drivers/gpu/drm/gna/gna_hw.h      | 107 ++++++++
  drivers/gpu/drm/gna/gna_ioctl.c   | 208 ++++++++++++++
  drivers/gpu/drm/gna/gna_mem.c     | 249 +++++++++++++++++
  drivers/gpu/drm/gna/gna_mem.h     |  58 ++++
  drivers/gpu/drm/gna/gna_pci.c     | 148 ++++++++++
  drivers/gpu/drm/gna/gna_pci.h     |  12 +
  drivers/gpu/drm/gna/gna_request.c | 441 ++++++++++++++++++++++++++++++
  drivers/gpu/drm/gna/gna_request.h |  64 +++++
  drivers/gpu/drm/gna/gna_score.c   | 222 +++++++++++++++
  drivers/gpu/drm/gna/gna_score.h   |  11 +
  include/uapi/drm/gna_drm.h        | 169 ++++++++++++
  22 files changed, 2347 insertions(+)

create mode 100644 Documentation/gpu/gna.rst create mode 100644 drivers/gpu/drm/gna/Kbuild create mode 100644 drivers/gpu/drm/gna/Kconfig create mode 100644 drivers/gpu/drm/gna/gna_device.c create mode 100644 drivers/gpu/drm/gna/gna_device.h create mode 100644 drivers/gpu/drm/gna/gna_gem.h create mode 100644 drivers/gpu/drm/gna/gna_hw.c create mode 100644 drivers/gpu/drm/gna/gna_hw.h create mode 100644 drivers/gpu/drm/gna/gna_ioctl.c create mode 100644 drivers/gpu/drm/gna/gna_mem.c create mode 100644 drivers/gpu/drm/gna/gna_mem.h create mode 100644 drivers/gpu/drm/gna/gna_pci.c create mode 100644 drivers/gpu/drm/gna/gna_pci.h create mode 100644 drivers/gpu/drm/gna/gna_request.c create mode 100644 drivers/gpu/drm/gna/gna_request.h create mode 100644 drivers/gpu/drm/gna/gna_score.c create mode 100644 drivers/gpu/drm/gna/gna_score.h create mode 100644 include/uapi/drm/gna_drm.h

Signature · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev
#36 lore raw
Quoted 144 lines · Thomas Zimmermann

Hi

Am 20.10.22 um 19:53 schrieb Maciej Kwapulinski:

Quoted 20 lines

Dear kernel maintainers,

This submission is a kernel driver to support Intel(R) Gaussian & Neural Accelerator (Intel(R) GNA). Intel(R) GNA is a PCI-based neural co-processor available on multiple Intel platforms. AI developers and users can offload continuous inference workloads to an Intel(R) GNA device in order to free processor resources and save power. Noise reduction and speech recognition are the examples of the workloads Intel(R) GNA deals with while its usage is not limited to the two.

For a list of processors equipped with Intel(R) GNA device, please refer to this link:
https://docs.openvinotoolkit.org/latest/openvino_docs_IE_DG_supported_plugins_GNA.html

We think contributing this driver to the upstream kernel project is the best way for developers and users to get the latest Intel(R) GNA support in a Linux kernel, through the mainline to any Linux distributions installed on their systems. Upstreaming also enables contribution from developers around the world to the driver once it is merged.

Quoted 4 lines

The driver works with Intel(R) libraries in user space. The Intel(R) driver exposes a few IOCTL interfaces for use by libraries in user space. The libraries are open sourced and are available at:
https://github.com/intel/gna

This driver appears to be a candidate for the accel subsystem that has been proposed here. [1] At a minimum, you'd now get standardized file names. Longterm, I'd expect dedicated helpers for accel devices.

Best regards
Thomas

[1]
https://lore.kernel.org/dri-devel/[email protected]/T/#m977efaeb39fc5be581ae05e1dccbd896546db943

Quoted 94 lines

---

Changelogs:

v1->v2:
- driver's new layout:
- driver name: gna -> intel_gna
- module name: gna -> intel_gna
- device file name: /dev/gnaN -> /dev/intel_gnaN
- driver's source directory: drivers/misc/gna/ -> drivers/misc/intel/gna/
- UAPI: include/uapi/misc/gna.h -> include/uapi/misc/intel/gna.h
- DOC: Documentation/misc-devices/gna.rst -> Documentation/misc-devices/intel/gna.rst
- 'MISC' device framework used
- fixes throughout GNA device's PCI management
- header files' includes and forward declarations cleanup
- ISR made static
- unused comments cleanup
- "_priv_" segment removed from function names
- tested: v5.11-rc3 -> v5.11
- number of other/minor fixes

v2->v3:
- PCI glue driver part split.
- GNA probe fail path made fully implicit.
- 'recovery_timeout' module parameter present under 'CONFIG_DEBUG_INTEL_GNA' flag only.
- build for X86_32 enabled.
- module initialization through 'module_pci_driver()'.
- gna_priv->file_list cleanup.
- 'gna_' prefix removed from source files' names.
- power management handling added.
- number of other/minor fixes
- tests performed on kernel v5.12

v3->v4:
- GNA driver adapted to DRM framework (+userspace GNA library adapted to use the driver)
- drm_managed (drmm) feature is used for objects lifetime management
- GNA memory objects use ~drm_gem_shmem_object~ objects as a base
- patches reorganized to meet symbols' usage with their declarations/definitions
- 'recovery_timeout' module parameter removed
- number of other/minor fixes from v3 review
- tests performed on kernel v6.0

v4->v5:
- indentation fixed in drivers/gpu/drm/gna/Kconfig

Maciej Kwapulinski (4):
gna: add PCI driver module
gna: add GNA DRM device
gna: add GNA_GEM_NEW and GNA_GEM_FREE ioctls
gna: add power management

Tomasz Jankowski (6):
gna: read hardware info
gna: initialize MMU
gna: add GNA_GET_PARAMETER ioctl
gna: add GNA_COMPUTE ioctl
gna: add GNA_WAIT ioctl
gna: add open and close operations on GNA device

  Documentation/gpu/drivers.rst     |   1 +
  Documentation/gpu/gna.rst         |  64 +++++
  MAINTAINERS                       |   7 +
  drivers/gpu/drm/Kconfig           |   2 +
  drivers/gpu/drm/Makefile          |   1 +
  drivers/gpu/drm/gna/Kbuild        |   5 +
  drivers/gpu/drm/gna/Kconfig       |  15 +
  drivers/gpu/drm/gna/gna_device.c  | 317 +++++++++++++++++++++
  drivers/gpu/drm/gna/gna_device.h  | 114 ++++++++
  drivers/gpu/drm/gna/gna_gem.h     |  22 ++
  drivers/gpu/drm/gna/gna_hw.c      | 110 ++++++++
  drivers/gpu/drm/gna/gna_hw.h      | 107 ++++++++
  drivers/gpu/drm/gna/gna_ioctl.c   | 208 ++++++++++++++
  drivers/gpu/drm/gna/gna_mem.c     | 249 +++++++++++++++++
  drivers/gpu/drm/gna/gna_mem.h     |  58 ++++
  drivers/gpu/drm/gna/gna_pci.c     | 148 ++++++++++
  drivers/gpu/drm/gna/gna_pci.h     |  12 +
  drivers/gpu/drm/gna/gna_request.c | 441 ++++++++++++++++++++++++++++++
  drivers/gpu/drm/gna/gna_request.h |  64 +++++
  drivers/gpu/drm/gna/gna_score.c   | 222 +++++++++++++++
  drivers/gpu/drm/gna/gna_score.h   |  11 +
  include/uapi/drm/gna_drm.h        | 169 ++++++++++++
  22 files changed, 2347 insertions(+)

create mode 100644 Documentation/gpu/gna.rst create mode 100644 drivers/gpu/drm/gna/Kbuild create mode 100644 drivers/gpu/drm/gna/Kconfig create mode 100644 drivers/gpu/drm/gna/gna_device.c create mode 100644 drivers/gpu/drm/gna/gna_device.h create mode 100644 drivers/gpu/drm/gna/gna_gem.h create mode 100644 drivers/gpu/drm/gna/gna_hw.c create mode 100644 drivers/gpu/drm/gna/gna_hw.h create mode 100644 drivers/gpu/drm/gna/gna_ioctl.c create mode 100644 drivers/gpu/drm/gna/gna_mem.c

Quoted 9 lines

create mode 100644 drivers/gpu/drm/gna/gna_mem.h create mode 100644 drivers/gpu/drm/gna/gna_pci.c create mode 100644 drivers/gpu/drm/gna/gna_pci.h create mode 100644 drivers/gpu/drm/gna/gna_request.c create mode 100644 drivers/gpu/drm/gna/gna_request.h create mode 100644 drivers/gpu/drm/gna/gna_score.c create mode 100644 drivers/gpu/drm/gna/gna_score.h create mode 100644 include/uapi/drm/gna_drm.h

Quoted 7 lines

--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev

Hi Maciej,
I just wanted to touch base with you about gna, asking whether you are going (or maybe started) to port the gna to the accel subsystem ? fyi, ivpu driver was just merged to the accel subsystem, so we already have our first driver tested & merged.

Thanks,
Oded