Skip to contentSkip to conversation

accel/ivpu: Refactor driver code and support new hardware

PATCH In review Stanislaw Gruszka 2 participants 16 messages Jul 31, 2023 – Aug 9, 2023

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

cover accel/ivpu: Refactor driver code and support new hardware

Various code additions and refactoring in order to add support for VPU IP 4, which be included in Intel Lunar Lake CPUs.

Jacek Lawrynowicz (3):
accel/ivpu: Rename sources to use generation based names accel/ivpu: Use generation based function and registers names accel/ivpu: Switch to generation based FW names

Karol Wachowski (1):
accel/ivpu: Refactor memory ranges logic

Stanislaw Gruszka (2):
accel/ivpu: Add param ioctl to identify capabilities accel/ivpu: Add initial support for VPU 4

 drivers/accel/ivpu/Makefile                   |    3 +-
 drivers/accel/ivpu/ivpu_drv.c                 |   35 +-
 drivers/accel/ivpu/ivpu_drv.h                 |   23 +-
 drivers/accel/ivpu/ivpu_fw.c                  |   41 +-
 drivers/accel/ivpu/ivpu_gem.c                 |   10 +-
 drivers/accel/ivpu/ivpu_hw.h                  |   12 +-
 .../ivpu/{ivpu_hw_mtl.c => ivpu_hw_37xx.c}    |  485 ++++---
 drivers/accel/ivpu/ivpu_hw_37xx_reg.h         |  281 ++++
 drivers/accel/ivpu/ivpu_hw_40xx.c             | 1178 +++++++++++++++++
 drivers/accel/ivpu/ivpu_hw_40xx_reg.h         |  267 ++++
 drivers/accel/ivpu/ivpu_hw_mtl_reg.h          |  281 ----
 drivers/accel/ivpu/ivpu_mmu.c                 |   84 +-
 drivers/accel/ivpu/ivpu_mmu_context.c         |    8 +-
 include/uapi/drm/ivpu_accel.h                 |    9 +-
 14 files changed, 2109 insertions(+), 608 deletions(-)
 rename drivers/accel/ivpu/{ivpu_hw_mtl.c => ivpu_hw_37xx.c} (52%)
 create mode 100644 drivers/accel/ivpu/ivpu_hw_37xx_reg.h
 create mode 100644 drivers/accel/ivpu/ivpu_hw_40xx.c
 create mode 100644 drivers/accel/ivpu/ivpu_hw_40xx_reg.h
 delete mode 100644 drivers/accel/ivpu/ivpu_hw_mtl_reg.h
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/6 accel/ivpu: Rename sources to use generation based names

From: Jacek Lawrynowicz <[email protected]>

Given that VPU generation can be used by multiple platforms, driver should use VPU IP generation in names instead of a platform names.

Change naming for sources files.

Use 37XX format, where:
3 - major VPU IP generation version
7 - minor VPU IP generation version
XX - postfix indicating this is a architecture and not marketing name

---
 drivers/accel/ivpu/Makefile                                  | 2 +-
 drivers/accel/ivpu/{ivpu_hw_mtl.c => ivpu_hw_37xx.c}         | 2 +-
 drivers/accel/ivpu/{ivpu_hw_mtl_reg.h => ivpu_hw_37xx_reg.h} | 0
 drivers/accel/ivpu/ivpu_mmu.c                                | 2 +-
 4 files changed, 3 insertions(+), 3 deletions(-)
 rename drivers/accel/ivpu/{ivpu_hw_mtl.c => ivpu_hw_37xx.c} (99%)
 rename drivers/accel/ivpu/{ivpu_hw_mtl_reg.h => ivpu_hw_37xx_reg.h} (100%)
drivers/accel/ivpu/Makefile +1 -1
index 9858d9fea36e..3179e146e173 100644
@@ -7,7 +7,7 @@ intel_vpu-y := \
 	ivpu_fw.o \
 	ivpu_fw_log.o \
 	ivpu_gem.o \
-	ivpu_hw_mtl.o \
+	ivpu_hw_37xx.o \
 	ivpu_ipc.o \
 	ivpu_job.o \
 	ivpu_jsm_msg.o \
drivers/accel/ivpu/ivpu_hw_37xx.c renamed from drivers/accel/ivpu/ivpu_hw_mtl.c +1 -1
similarity index 99%
rename from drivers/accel/ivpu/ivpu_hw_mtl.c
rename to drivers/accel/ivpu/ivpu_hw_37xx.c
index f1211e74017d..495be81840ac 100644
@@ -5,7 +5,7 @@
 
 #include "ivpu_drv.h"
 #include "ivpu_fw.h"
-#include "ivpu_hw_mtl_reg.h"
+#include "ivpu_hw_37xx_reg.h"
 #include "ivpu_hw_reg_io.h"
 #include "ivpu_hw.h"
 #include "ivpu_ipc.h"
drivers/accel/ivpu/ivpu_hw_37xx_reg.h renamed from drivers/accel/ivpu/ivpu_hw_mtl_reg.h +0 -0
similarity index 100%
rename from drivers/accel/ivpu/ivpu_hw_mtl_reg.h
rename to drivers/accel/ivpu/ivpu_hw_37xx_reg.h
drivers/accel/ivpu/ivpu_mmu.c +1 -1
index 53878e77aad3..b64eb094343b 100644
@@ -7,7 +7,7 @@
 #include <linux/highmem.h>
 
 #include "ivpu_drv.h"
-#include "ivpu_hw_mtl_reg.h"
+#include "ivpu_hw_37xx_reg.h"
 #include "ivpu_hw_reg_io.h"
 #include "ivpu_mmu.h"
 #include "ivpu_mmu_context.h"
Signature · 1 line
2.25.1
Reviewed-by on v1 1/6
#2 lore raw

Re: [PATCH 1/6] accel/ivpu: Rename sources to use generation based names

Quoted 4 lines · Stanislaw Gruszka

From: Jacek Lawrynowicz <[email protected]>

Given that VPU generation can be used by multiple platforms, driver should use VPU IP generation in names instead of a platform names.

I think just "platform." instead of "platform names" reads better.

Quoted 7 lines

Change naming for sources files.

Use 37XX format, where:
3 - major VPU IP generation version
7 - minor VPU IP generation version
XX - postfix indicating this is a architecture and not marketing name

"an architecture"

Quoted 4 lines
Quoted 55 lines
---
  drivers/accel/ivpu/Makefile                                  | 2 +-
  drivers/accel/ivpu/{ivpu_hw_mtl.c => ivpu_hw_37xx.c}         | 2 +-
  drivers/accel/ivpu/{ivpu_hw_mtl_reg.h => ivpu_hw_37xx_reg.h} | 0
  drivers/accel/ivpu/ivpu_mmu.c                                | 2 +-
  4 files changed, 3 insertions(+), 3 deletions(-)

rename drivers/accel/ivpu/{ivpu_hw_mtl.c => ivpu_hw_37xx.c} (99%) rename drivers/accel/ivpu/{ivpu_hw_mtl_reg.h => ivpu_hw_37xx_reg.h} (100%)

drivers/accel/ivpu/Makefile +1 -1
index 9858d9fea36e..3179e146e173 100644
@@ -7,7 +7,7 @@ intel_vpu-y := \
  	ivpu_fw.o \
  	ivpu_fw_log.o \
  	ivpu_gem.o \
-	ivpu_hw_mtl.o \
+	ivpu_hw_37xx.o \
  	ivpu_ipc.o \
  	ivpu_job.o \
  	ivpu_jsm_msg.o \
drivers/accel/ivpu/ivpu_hw_37xx.c renamed from drivers/accel/ivpu/ivpu_hw_mtl.c +1 -1
similarity index 99%
rename from drivers/accel/ivpu/ivpu_hw_mtl.c
rename to drivers/accel/ivpu/ivpu_hw_37xx.c
index f1211e74017d..495be81840ac 100644
@@ -5,7 +5,7 @@
 
  #include "ivpu_drv.h"
  #include "ivpu_fw.h"
-#include "ivpu_hw_mtl_reg.h"
+#include "ivpu_hw_37xx_reg.h"
  #include "ivpu_hw_reg_io.h"
  #include "ivpu_hw.h"
  #include "ivpu_ipc.h"
drivers/accel/ivpu/ivpu_hw_37xx_reg.h renamed from drivers/accel/ivpu/ivpu_hw_mtl_reg.h +0 -0
similarity index 100%
rename from drivers/accel/ivpu/ivpu_hw_mtl_reg.h
rename to drivers/accel/ivpu/ivpu_hw_37xx_reg.h
drivers/accel/ivpu/ivpu_mmu.c +1 -1
index 53878e77aad3..b64eb094343b 100644
@@ -7,7 +7,7 @@
  #include <linux/highmem.h>
 
  #include "ivpu_drv.h"
-#include "ivpu_hw_mtl_reg.h"
+#include "ivpu_hw_37xx_reg.h"
  #include "ivpu_hw_reg_io.h"
  #include "ivpu_mmu.h"
  #include "ivpu_mmu_context.h"
#3 lore raw

PATCH 2/6 accel/ivpu: Use generation based function and registers names

In reply to Stanislaw Gruszka

From: Jacek Lawrynowicz <[email protected]>

Given that VPU generation can be used by multiple platforms, driver should use VPU IP generation names instead of a platform names.

Change naming for functions and registries.

Use 37XX format, where:
3 - major VPU IP generation version
7 - minor VPU IP generation version
XX - postfix indicating this is a architecture and not marketing name

---
 drivers/accel/ivpu/ivpu_drv.c         |   6 +-
 drivers/accel/ivpu/ivpu_drv.h         |  18 +-
 drivers/accel/ivpu/ivpu_hw.h          |   2 +-
 drivers/accel/ivpu/ivpu_hw_37xx.c     | 476 +++++++++++++-------------
 drivers/accel/ivpu/ivpu_hw_37xx_reg.h | 392 ++++++++++-----------
 drivers/accel/ivpu/ivpu_mmu.c         |  82 ++---
 6 files changed, 492 insertions(+), 484 deletions(-)
drivers/accel/ivpu/ivpu_drv.c +3 -3
index 815dd9b588e9..fad607dbb2c6 100644
@@ -443,8 +443,8 @@ static int ivpu_pci_init(struct ivpu_device *vdev)
 	/* Clear any pending errors */
 	pcie_capability_clear_word(pdev, PCI_EXP_DEVSTA, 0x3f);
 
-	/* VPU MTL does not require PCI spec 10m D3hot delay */
-	if (ivpu_is_mtl(vdev))
+	/* VPU 37XX does not require 10m D3hot delay */
+	if (ivpu_hw_gen(vdev) == IVPU_HW_37XX)
 		pdev->d3hot_delay = 0;
 
 	ret = pcim_enable_device(pdev);
@@ -482,7 +482,7 @@ static int ivpu_dev_init(struct ivpu_device *vdev)
 	if (!vdev->pm)
 		return -ENOMEM;
 
-	vdev->hw->ops = &ivpu_hw_mtl_ops;
+	vdev->hw->ops = &ivpu_hw_37xx_ops;
 	vdev->hw->dma_bits = 38;
 
 	vdev->platform = IVPU_PLATFORM_INVALID;
drivers/accel/ivpu/ivpu_drv.h +13 -5
index 8fe8cda2e39d..5808a4e6bb6d 100644
@@ -24,6 +24,8 @@
 
 #define PCI_DEVICE_ID_MTL   0x7d1d
 
+#define IVPU_HW_37XX	37
+
 #define IVPU_GLOBAL_CONTEXT_MMU_SSID 0
 /* SSID 1 is used by the VPU to represent invalid context */
 #define IVPU_USER_CONTEXT_MIN_SSID   2
@@ -146,11 +148,6 @@ void ivpu_file_priv_put(struct ivpu_file_priv **link);
 int ivpu_boot(struct ivpu_device *vdev);
 int ivpu_shutdown(struct ivpu_device *vdev);
 
-static inline bool ivpu_is_mtl(struct ivpu_device *vdev)
-{
-	return to_pci_dev(vdev->drm.dev)->device == PCI_DEVICE_ID_MTL;
-}
-
 static inline u8 ivpu_revision(struct ivpu_device *vdev)
 {
 	return to_pci_dev(vdev->drm.dev)->revision;
@@ -161,6 +158,17 @@ static inline u16 ivpu_device_id(struct ivpu_device *vdev)
 	return to_pci_dev(vdev->drm.dev)->device;
 }
 
+static inline int ivpu_hw_gen(struct ivpu_device *vdev)
+{
+	switch (ivpu_device_id(vdev)) {
+	case PCI_DEVICE_ID_MTL:
+		return IVPU_HW_37XX;
+	default:
+		ivpu_err(vdev, "Unknown VPU device\n");
+		return 0;
+	}
+}
+
 static inline struct ivpu_device *to_ivpu_device(struct drm_device *dev)
 {
 	return container_of(dev, struct ivpu_device, drm);
drivers/accel/ivpu/ivpu_hw.h +1 -1
index 0393901be492..335b7f707752 100644
@@ -60,7 +60,7 @@ struct ivpu_hw_info {
 	int dma_bits;
 };
 
-extern const struct ivpu_hw_ops ivpu_hw_mtl_ops;
+extern const struct ivpu_hw_ops ivpu_hw_37xx_ops;
 
 static inline int ivpu_hw_info_init(struct ivpu_device *vdev)
 {
drivers/accel/ivpu/ivpu_hw_37xx.c +238 -238

906 lines not on this page · raw message

drivers/accel/ivpu/ivpu_hw_37xx_reg.h +196 -196

432 lines not on this page · raw message

drivers/accel/ivpu/ivpu_mmu.c +41 -41

198 lines not on this page · raw message

Signature · 1 line
2.25.1
Reviewed-by on v1 2/6
#4 lore raw

Re: [PATCH 2/6] accel/ivpu: Use generation based function and registers names

Quoted 7 lines · Stanislaw Gruszka

From: Jacek Lawrynowicz <[email protected]>

Given that VPU generation can be used by multiple platforms, driver should use VPU IP generation names instead of a platform names.

Change naming for functions and registries.

Quoted 8 lines

Use 37XX format, where:
3 - major VPU IP generation version
7 - minor VPU IP generation version
XX - postfix indicating this is a architecture and not marketing name

Same nits from patch 1 apply here

#5 lore raw

PATCH 3/6 accel/ivpu: Switch to generation based FW names

In reply to Stanislaw Gruszka

From: Jacek Lawrynowicz <[email protected]>

Use VPU IP generation for naming FW instead of the platform name.

---
 drivers/accel/ivpu/ivpu_fw.c | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)
drivers/accel/ivpu/ivpu_fw.c +15 -6
index 317716482a15..7caf90a169a3 100644
@@ -43,12 +43,18 @@ static char *ivpu_firmware;
 module_param_named_unsafe(firmware, ivpu_firmware, charp, 0644);
 MODULE_PARM_DESC(firmware, "VPU firmware binary in /lib/firmware/..");
 
+/* TODO: Remove mtl_vpu.bin from names after transition to generation based FW names */
+static struct {
+	int gen;
+	const char *name;
+} fw_names[] = {
+	{ IVPU_HW_37XX, "vpu_37xx.bin" },
+	{ IVPU_HW_37XX, "mtl_vpu.bin" },
+	{ IVPU_HW_37XX, "intel/vpu/vpu_37xx_v0.0.bin" },
+};
+
 static int ivpu_fw_request(struct ivpu_device *vdev)
 {
-	static const char * const fw_names[] = {
-		"mtl_vpu.bin",
-		"intel/vpu/mtl_vpu_v0.0.bin"
-	};
 	int ret = -ENOENT;
 	int i;
 
@@ -60,9 +66,12 @@ static int ivpu_fw_request(struct ivpu_device *vdev)
 	}
 
 	for (i = 0; i < ARRAY_SIZE(fw_names); i++) {
-		ret = firmware_request_nowarn(&vdev->fw->file, fw_names[i], vdev->drm.dev);
+		if (fw_names[i].gen != ivpu_hw_gen(vdev))
+			continue;
+
+		ret = firmware_request_nowarn(&vdev->fw->file, fw_names[i].name, vdev->drm.dev);
 		if (!ret) {
-			vdev->fw->name = fw_names[i];
+			vdev->fw->name = fw_names[i].name;
 			return 0;
 		}
 	}
Signature · 1 line
2.25.1
#7 lore raw

PATCH 4/6 accel/ivpu: Add param ioctl to identify capabilities

In reply to Stanislaw Gruszka

Add DRM_IVPU_PARAM_CAPABILITIES ioctl to query driver capabilities. For now use it for identify metric streamer and new dma memory range features. Currently upstream version of intel_vpu does not have those, they will be added it the future.

---
 drivers/accel/ivpu/ivpu_drv.c | 19 +++++++++++++++++++
 include/uapi/drm/ivpu_accel.h |  4 ++++
 2 files changed, 23 insertions(+)
drivers/accel/ivpu/ivpu_drv.c +19 -0
index fad607dbb2c6..d33eb17007bf 100644
@@ -115,6 +115,22 @@ void ivpu_file_priv_put(struct ivpu_file_priv **link)
 	kref_put(&file_priv->ref, file_priv_release);
 }
 
+static int ivpu_get_capabilities(struct ivpu_device *vdev, struct drm_ivpu_param *args)
+{
+	switch (args->index) {
+	case DRM_IVPU_CAP_METRIC_STREAMER:
+		args->value = 0;
+		break;
+	case DRM_IVPU_CAP_DMA_MEMORY_RANGE:
+		args->value = 0;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
 static int ivpu_get_param_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
 {
 	struct ivpu_file_priv *file_priv = file->driver_priv;
@@ -174,6 +190,9 @@ static int ivpu_get_param_ioctl(struct drm_device *dev, void *data, struct drm_f
 	case DRM_IVPU_PARAM_SKU:
 		args->value = vdev->hw->sku;
 		break;
+	case DRM_IVPU_PARAM_CAPABILITIES:
+		ret = ivpu_get_capabilities(vdev, args);
+		break;
 	default:
 		ret = -EINVAL;
 		break;
include/uapi/drm/ivpu_accel.h +4 -0
index 839820aed87e..3e99b74eef04 100644
@@ -60,6 +60,7 @@ extern "C" {
 #define DRM_IVPU_PARAM_UNIQUE_INFERENCE_ID  10
 #define DRM_IVPU_PARAM_TILE_CONFIG	    11
 #define DRM_IVPU_PARAM_SKU		    12
+#define DRM_IVPU_PARAM_CAPABILITIES	    13
 
 #define DRM_IVPU_PLATFORM_TYPE_SILICON	    0
 
@@ -68,6 +69,9 @@ extern "C" {
 #define DRM_IVPU_CONTEXT_PRIORITY_FOCUS	    2
 #define DRM_IVPU_CONTEXT_PRIORITY_REALTIME  3
 
+#define DRM_IVPU_CAP_METRIC_STREAMER	    1
+#define DRM_IVPU_CAP_DMA_MEMORY_RANGE       2
+
 /**
  * struct drm_ivpu_param - Get/Set VPU parameters
  */
Signature · 1 line
2.25.1
#8 lore raw

Re: [PATCH 4/6] accel/ivpu: Add param ioctl to identify capabilities

Quoted 4 lines · Stanislaw Gruszka

Add DRM_IVPU_PARAM_CAPABILITIES ioctl to query driver capabilities. For now use it for identify metric streamer and new dma memory range features. Currently upstream version of intel_vpu does not have those, they will be added it the future.

Hmm. So I happened to remember this from Oded in the reviews for the first iVPU series -

"btw, I talked to Daniel about this and he told me this major/minor/patchlevel is legacy in drm and should be deprecated, so I'm going to send a patch to document that it is deprecated and how to use getcap ioctl to find out the features the driver support."

So, I went to look at DRM_IOCTL_GET_CAP and it feels like something you should be using as it fits the purpose I see in this patch, but also I don't see how given that it doesn't hook to the driver.

I suspect at some point, QAIC would have its own need for a "getcap" API. Feels like something we should have a common entry in uAPI for (ACCEL_IOCTL_GET_CAP ? ), but I don't yet see that we'll have a lot a commonality of the capabilities across Accel drivers. I don't think the DRM method of globally defined caps is useful for Accel.

Does it make sense to have a framework level ioctl, but something that calls into the drivers and would allow the drivers to advertise custom capabilities?

Seems like we might want to decide this now, because if we define a iVPU specific ioctl as proposed here, but then switch to an Accel-wide mechanism later, iVPU is going to be stuck supporting both.

What do you think?

Oded, am I misunderstanding your earlier comment?

-Jeff

#9 lore raw

Re: [PATCH 4/6] accel/ivpu: Add param ioctl to identify capabilities

Hi

Quoted 9 lines · Jeffrey Hugo
Quoted 4 lines · Stanislaw Gruszka

Add DRM_IVPU_PARAM_CAPABILITIES ioctl to query driver capabilities. For now use it for identify metric streamer and new dma memory range features. Currently upstream version of intel_vpu does not have those, they will be added it the future.

Hmm. So I happened to remember this from Oded in the reviews for the first iVPU series -

Quoted 8 lines

"btw, I talked to Daniel about this and he told me this major/minor/patchlevel is legacy in drm and should be deprecated, so I'm going to send a patch to document that it is deprecated and how to use getcap ioctl to find out the features the driver support."

So, I went to look at DRM_IOCTL_GET_CAP and it feels like something you should be using as it fits the purpose I see in this patch, but also I don't see how given that it doesn't hook to the driver.

Indeed it does not have such extension. I considered DRM_IOCTL_GET_CAP, but did not use it because of that. Seems that DRM drivers that need provide set of capabilities just create own "getcap" ioctl.

Quoted 9 lines

I suspect at some point, QAIC would have its own need for a "getcap" API. Feels like something we should have a common entry in uAPI for (ACCEL_IOCTL_GET_CAP ? ), but I don't yet see that we'll have a lot a commonality of the capabilities across Accel drivers. I don't think the DRM method of globally defined caps is useful for Accel.

Does it make sense to have a framework level ioctl, but something that calls into the drivers and would allow the drivers to advertise custom capabilities?

Perhaps such thing would make sense, resembles to me ethtool for network devices. But not sure, maybe just having separate ioctls per driver and one common for common features is simpler.

Quoted 3 lines

Seems like we might want to decide this now, because if we define a iVPU specific ioctl as proposed here, but then switch to an Accel-wide mechanism later, iVPU is going to be stuck supporting both.

For the record, we do not add new ioctl in this patch, we just extend existing DRM_IOCTL_IVPU_GET_PARAM one.

Quoted 1 line

What do you think?

My understating was that this is more like design patter, i.e. drivers that have to advertise supported features should not use minor/major numbers but "getcap" ioctl. And that not necessary mean we should have common ioctl for that for all ACCEL/DRM drivers.

Regards
Stanislaw

#10 lore raw

Re: [PATCH 4/6] accel/ivpu: Add param ioctl to identify capabilities

Quoted 6 lines · Stanislaw Gruszka
Quoted 3 lines

Seems like we might want to decide this now, because if we define a iVPU specific ioctl as proposed here, but then switch to an Accel-wide mechanism later, iVPU is going to be stuck supporting both.

For the record, we do not add new ioctl in this patch, we just extend existing DRM_IOCTL_IVPU_GET_PARAM one.

To avoid confusion, I'll change the topic and commit massage before applying:

accel/ivpu: Extend get_param ioctl to identify capabilities

Add DRM_IVPU_PARAM_CAPABILITIES parameters to get_param ioctl to query driver capabilities. For now use it for identify metric streamer and new dma memory range features. Currently upstream version of intel_vpu does not have those, they will be added it the future.

Regards
Stanislaw

#11 lore raw

Re: [PATCH 4/6] accel/ivpu: Add param ioctl to identify capabilities

Quoted 11 lines · Stanislaw Gruszka
Quoted 6 lines · Stanislaw Gruszka
Quoted 3 lines

Seems like we might want to decide this now, because if we define a iVPU specific ioctl as proposed here, but then switch to an Accel-wide mechanism later, iVPU is going to be stuck supporting both.

For the record, we do not add new ioctl in this patch, we just extend existing DRM_IOCTL_IVPU_GET_PARAM one.

To avoid confusion, I'll change the topic and commit massage before applying:

Quoted 6 lines

accel/ivpu: Extend get_param ioctl to identify capabilities

Add DRM_IVPU_PARAM_CAPABILITIES parameters to get_param ioctl to query driver capabilities. For now use it for identify metric streamer and new dma memory range features. Currently upstream version of intel_vpu does not have those, they will be added it the future.

This is perhaps slightly better. I didn't find the original one confusing.

Seems like no opinions on pushing this up to the framework. You did point out DRM drivers have driver level ones, so carry-on I guess.

Seems ok to me. I'd prefer to see some comments in the uapi header describing what the DRM_IVPU_CAP_* values mean. A bit more than "device has metric streamer support" - what is metric streamer, and why might userspace care?

However, as a uAPI change, is Oded's Ack not required? I thought that was the rule.

-Jeff

#12 lore raw

Re: [PATCH 4/6] accel/ivpu: Add param ioctl to identify capabilities

Hi

Quoted 21 lines · Jeffrey Hugo
Quoted 11 lines · Stanislaw Gruszka
Quoted 6 lines · Stanislaw Gruszka
Quoted 3 lines

Seems like we might want to decide this now, because if we define a iVPU specific ioctl as proposed here, but then switch to an Accel-wide mechanism later, iVPU is going to be stuck supporting both.

For the record, we do not add new ioctl in this patch, we just extend existing DRM_IOCTL_IVPU_GET_PARAM one.

To avoid confusion, I'll change the topic and commit massage before applying:

Quoted 6 lines

accel/ivpu: Extend get_param ioctl to identify capabilities

Add DRM_IVPU_PARAM_CAPABILITIES parameters to get_param ioctl to query driver capabilities. For now use it for identify metric streamer and new dma memory range features. Currently upstream version of intel_vpu does not have those, they will be added it the future.

This is perhaps slightly better. I didn't find the original one confusing.

Quoted 7 lines

Seems like no opinions on pushing this up to the framework. You did point out DRM drivers have driver level ones, so carry-on I guess.

Seems ok to me. I'd prefer to see some comments in the uapi header describing what the DRM_IVPU_CAP_* values mean. A bit more than "device has metric streamer support" - what is metric streamer, and why might userspace care?

You have right, this should be documented. I'll send separate patch for this.

Quoted 2 lines

However, as a uAPI change, is Oded's Ack not required? I thought that was the rule.

I looked at git log from files in include/uapi/drm/ and seems that individual driver uAPI changes are up to the driver maintainer for drm misc drivers.

At least there is no NACK from Oded so far :-) so I'm going to apply this, since want the changes to be merged in 6.6 merge window.

Regards
Stanislaw

#13 lore raw

Re: [PATCH 4/6] accel/ivpu: Add param ioctl to identify capabilities

Quoted 27 lines · Stanislaw Gruszka

Hi

Quoted 24 lines · Jeffrey Hugo
Quoted 11 lines · Stanislaw Gruszka
Quoted 6 lines · Stanislaw Gruszka
Quoted 3 lines

Seems like we might want to decide this now, because if we define a iVPU specific ioctl as proposed here, but then switch to an Accel-wide mechanism later, iVPU is going to be stuck supporting both.

For the record, we do not add new ioctl in this patch, we just extend existing DRM_IOCTL_IVPU_GET_PARAM one.

To avoid confusion, I'll change the topic and commit massage before applying:

Quoted 6 lines

accel/ivpu: Extend get_param ioctl to identify capabilities

Add DRM_IVPU_PARAM_CAPABILITIES parameters to get_param ioctl to query driver capabilities. For now use it for identify metric streamer and new dma memory range features. Currently upstream version of intel_vpu does not have those, they will be added it the future.

This is perhaps slightly better. I didn't find the original one confusing.

Seems like no opinions on pushing this up to the framework. You did point out DRM drivers have driver level ones, so carry-on I guess.

Quoted 7 lines
Quoted 4 lines

Seems ok to me. I'd prefer to see some comments in the uapi header describing what the DRM_IVPU_CAP_* values mean. A bit more than "device has metric streamer support" - what is metric streamer, and why might userspace care?

You have right, this should be documented. I'll send separate patch for this.

Sounds good.

If you like, Reviewed-by: Jeffrey Hugo <[email protected]>

Quoted 6 lines
Quoted 3 lines

However, as a uAPI change, is Oded's Ack not required? I thought that was the rule.

I looked at git log from files in include/uapi/drm/ and seems that individual driver uAPI changes are up to the driver maintainer for drm misc drivers.

I was referencing this -

"<snip> bugfixes for the qaic driver can be pushed directly by the qaic team. Still with acks/r-b requirements as per usual, and I guess for anything bigger/new uapi an ack from oded is needed."

https://lore.kernel.org/dri-devel/[email protected]/

Maybe that is qaic specific rules since we are rather new to the community and still learning.

Quoted 5 lines

At least there is no NACK from Oded so far :-) so I'm going to apply this, since want the changes to be merged in 6.6 merge window.

Regards
Stanislaw

#14 lore raw

PATCH 5/6 accel/ivpu: Refactor memory ranges logic

In reply to Stanislaw Gruszka

From: Karol Wachowski <[email protected]>

Add new dma range and change naming convention for virtual address memory ranges managed by KMD.

New available ranges are named as follows:
* global range - global context accessible by FW
* aliased range - user context accessible by FW
* dma range - user context accessible by DMA
* shave range - user context accessible by shaves
* global shave range - global context accessible by shave nn

---
 drivers/accel/ivpu/ivpu_drv.c         |  4 ++--
 drivers/accel/ivpu/ivpu_fw.c          | 18 ++++++++----------
 drivers/accel/ivpu/ivpu_gem.c         | 10 ++++++----
 drivers/accel/ivpu/ivpu_hw.h          |  9 ++++-----
 drivers/accel/ivpu/ivpu_hw_37xx.c     |  9 ++++-----
 drivers/accel/ivpu/ivpu_mmu_context.c |  8 ++++----
 include/uapi/drm/ivpu_accel.h         |  5 ++++-
 7 files changed, 32 insertions(+), 31 deletions(-)
drivers/accel/ivpu/ivpu_drv.c +2 -2
index d33eb17007bf..3da15890bc59 100644
@@ -122,7 +122,7 @@ static int ivpu_get_capabilities(struct ivpu_device *vdev, struct drm_ivpu_param
 		args->value = 0;
 		break;
 	case DRM_IVPU_CAP_DMA_MEMORY_RANGE:
-		args->value = 0;
+		args->value = 1;
 		break;
 	default:
 		return -EINVAL;
@@ -160,7 +160,7 @@ static int ivpu_get_param_ioctl(struct drm_device *dev, void *data, struct drm_f
 		args->value = ivpu_get_context_count(vdev);
 		break;
 	case DRM_IVPU_PARAM_CONTEXT_BASE_ADDRESS:
-		args->value = vdev->hw->ranges.user_low.start;
+		args->value = vdev->hw->ranges.user.start;
 		break;
 	case DRM_IVPU_PARAM_CONTEXT_PRIORITY:
 		args->value = file_priv->priority;
drivers/accel/ivpu/ivpu_fw.c +8 -10
index 7caf90a169a3..7e75439dec60 100644
@@ -204,7 +204,7 @@ static int ivpu_fw_update_global_range(struct ivpu_device *vdev)
 		return -EINVAL;
 	}
 
-	ivpu_hw_init_range(&vdev->hw->ranges.global_low, start, size);
+	ivpu_hw_init_range(&vdev->hw->ranges.global, start, size);
 	return 0;
 }
 
@@ -245,7 +245,7 @@ static int ivpu_fw_mem_init(struct ivpu_device *vdev)
 	}
 
 	if (fw->shave_nn_size) {
-		fw->mem_shave_nn = ivpu_bo_alloc_internal(vdev, vdev->hw->ranges.global_high.start,
+		fw->mem_shave_nn = ivpu_bo_alloc_internal(vdev, vdev->hw->ranges.shave.start,
 							  fw->shave_nn_size, DRM_IVPU_BO_UNCACHED);
 		if (!fw->mem_shave_nn) {
 			ivpu_err(vdev, "Failed to allocate shavenn buffer\n");
@@ -443,9 +443,9 @@ void ivpu_fw_boot_params_setup(struct ivpu_device *vdev, struct vpu_boot_params
 	 * Uncached region of VPU address space, covers IPC buffers, job queues
 	 * and log buffers, programmable to L2$ Uncached by VPU MTRR
 	 */
-	boot_params->shared_region_base = vdev->hw->ranges.global_low.start;
-	boot_params->shared_region_size = vdev->hw->ranges.global_low.end -
-					  vdev->hw->ranges.global_low.start;
+	boot_params->shared_region_base = vdev->hw->ranges.global.start;
+	boot_params->shared_region_size = vdev->hw->ranges.global.end -
+					  vdev->hw->ranges.global.start;
 
 	boot_params->ipc_header_area_start = ipc_mem_rx->vpu_addr;
 	boot_params->ipc_header_area_size = ipc_mem_rx->base.size / 2;
@@ -453,10 +453,8 @@ void ivpu_fw_boot_params_setup(struct ivpu_device *vdev, struct vpu_boot_params
 	boot_params->ipc_payload_area_start = ipc_mem_rx->vpu_addr + ipc_mem_rx->base.size / 2;
 	boot_params->ipc_payload_area_size = ipc_mem_rx->base.size / 2;
 
-	boot_params->global_aliased_pio_base =
-		vdev->hw->ranges.global_aliased_pio.start;
-	boot_params->global_aliased_pio_size =
-		ivpu_hw_range_size(&vdev->hw->ranges.global_aliased_pio);
+	boot_params->global_aliased_pio_base = vdev->hw->ranges.user.start;
+	boot_params->global_aliased_pio_size = ivpu_hw_range_size(&vdev->hw->ranges.user);
 
 	/* Allow configuration for L2C_PAGE_TABLE with boot param value */
 	boot_params->autoconfig = 1;
@@ -464,7 +462,7 @@ void ivpu_fw_boot_params_setup(struct ivpu_device *vdev, struct vpu_boot_params
 	/* Enable L2 cache for first 2GB of high memory */
 	boot_params->cache_defaults[VPU_BOOT_L2_CACHE_CFG_NN].use = 1;
 	boot_params->cache_defaults[VPU_BOOT_L2_CACHE_CFG_NN].cfg =
-		ADDR_TO_L2_CACHE_CFG(vdev->hw->ranges.global_high.start);
+		ADDR_TO_L2_CACHE_CFG(vdev->hw->ranges.shave.start);
 
 	if (vdev->fw->mem_shave_nn)
 		boot_params->shave_nn_fw_base = vdev->fw->mem_shave_nn->vpu_addr;
drivers/accel/ivpu/ivpu_gem.c +6 -4
index 52b339aefadc..2981bb32c755 100644
@@ -279,10 +279,12 @@ ivpu_bo_alloc_vpu_addr(struct ivpu_bo *bo, struct ivpu_mmu_context *ctx,
 	int ret;
 
 	if (!range) {
-		if (bo->flags & DRM_IVPU_BO_HIGH_MEM)
-			range = &vdev->hw->ranges.user_high;
+		if (bo->flags & DRM_IVPU_BO_SHAVE_MEM)
+			range = &vdev->hw->ranges.shave;
+		else if (bo->flags & DRM_IVPU_BO_DMA_MEM)
+			range = &vdev->hw->ranges.dma;
 		else
-			range = &vdev->hw->ranges.user_low;
+			range = &vdev->hw->ranges.user;
 	}
 
 	mutex_lock(&ctx->lock);
@@ -570,7 +572,7 @@ ivpu_bo_alloc_internal(struct ivpu_device *vdev, u64 vpu_addr, u64 size, u32 fla
 		fixed_range.end = vpu_addr + size;
 		range = &fixed_range;
 	} else {
-		range = &vdev->hw->ranges.global_low;
+		range = &vdev->hw->ranges.global;
 	}
 
 	bo = ivpu_bo_alloc(vdev, &vdev->gctx, size, flags, &internal_ops, range, 0);
drivers/accel/ivpu/ivpu_hw.h +4 -5
index 335b7f707752..69e52d21cd10 100644
@@ -38,11 +38,10 @@ struct ivpu_addr_range {
 struct ivpu_hw_info {
 	const struct ivpu_hw_ops *ops;
 	struct {
-		struct ivpu_addr_range global_low;
-		struct ivpu_addr_range global_high;
-		struct ivpu_addr_range user_low;
-		struct ivpu_addr_range user_high;
-		struct ivpu_addr_range global_aliased_pio;
+		struct ivpu_addr_range global;
+		struct ivpu_addr_range user;
+		struct ivpu_addr_range shave;
+		struct ivpu_addr_range dma;
 	} ranges;
 	struct {
 		u8 min_ratio;
drivers/accel/ivpu/ivpu_hw_37xx.c +4 -5
index 2cda8e4c4a3d..9eae1c241bc0 100644
@@ -620,11 +620,10 @@ static int ivpu_hw_37xx_info_init(struct ivpu_device *vdev)
 
 	ivpu_pll_init_frequency_ratios(vdev);
 
-	ivpu_hw_init_range(&hw->ranges.global_low, 0x80000000, SZ_512M);
-	ivpu_hw_init_range(&hw->ranges.global_high, 0x180000000, SZ_2M);
-	ivpu_hw_init_range(&hw->ranges.user_low, 0xc0000000, 255 * SZ_1M);
-	ivpu_hw_init_range(&hw->ranges.user_high, 0x180000000, SZ_2G);
-	hw->ranges.global_aliased_pio = hw->ranges.user_low;
+	ivpu_hw_init_range(&hw->ranges.global, 0x80000000, SZ_512M);
+	ivpu_hw_init_range(&hw->ranges.user,   0xc0000000, 255 * SZ_1M);
+	ivpu_hw_init_range(&hw->ranges.shave, 0x180000000, SZ_2G);
+	ivpu_hw_init_range(&hw->ranges.dma,   0x200000000, SZ_8G);
 
 	return 0;
 }
drivers/accel/ivpu/ivpu_mmu_context.c +4 -4
index 465a82298476..1d2e554e2c4a 100644
@@ -431,11 +431,11 @@ ivpu_mmu_context_init(struct ivpu_device *vdev, struct ivpu_mmu_context *ctx, u3
 		return ret;
 
 	if (!context_id) {
-		start = vdev->hw->ranges.global_low.start;
-		end = vdev->hw->ranges.global_high.end;
+		start = vdev->hw->ranges.global.start;
+		end = vdev->hw->ranges.shave.end;
 	} else {
-		start = vdev->hw->ranges.user_low.start;
-		end = vdev->hw->ranges.user_high.end;
+		start = vdev->hw->ranges.user.start;
+		end = vdev->hw->ranges.dma.end;
 	}
 
 	drm_mm_init(&ctx->mm, start, end - start);
include/uapi/drm/ivpu_accel.h +4 -1
index 3e99b74eef04..a58a14c9f222 100644
@@ -133,8 +133,10 @@ struct drm_ivpu_param {
 	__u64 value;
 };
 
-#define DRM_IVPU_BO_HIGH_MEM   0x00000001
+#define DRM_IVPU_BO_SHAVE_MEM  0x00000001
+#define DRM_IVPU_BO_HIGH_MEM   DRM_IVPU_BO_SHAVE_MEM
 #define DRM_IVPU_BO_MAPPABLE   0x00000002
+#define DRM_IVPU_BO_DMA_MEM    0x00000004
 
 #define DRM_IVPU_BO_CACHED     0x00000000
 #define DRM_IVPU_BO_UNCACHED   0x00010000
@@ -144,6 +146,7 @@ struct drm_ivpu_param {
 #define DRM_IVPU_BO_FLAGS \
 	(DRM_IVPU_BO_HIGH_MEM | \
 	 DRM_IVPU_BO_MAPPABLE | \
+	 DRM_IVPU_BO_DMA_MEM | \
 	 DRM_IVPU_BO_CACHE_MASK)
 
 /**
Signature · 1 line
2.25.1
#15 lore raw

PATCH 6/6 accel/ivpu: Add initial support for VPU 4

In reply to Stanislaw Gruszka

Add support VPU 4 - new generation of VPU IP with various hardware design improvements. From driver point of view, it differs in register set, initialization process and MMU memory ranges.

---
 drivers/accel/ivpu/Makefile           |    1 +
 drivers/accel/ivpu/ivpu_drv.c         |   10 +-
 drivers/accel/ivpu/ivpu_drv.h         |    5 +
 drivers/accel/ivpu/ivpu_fw.c          |    2 +
 drivers/accel/ivpu/ivpu_hw.h          |    1 +
 drivers/accel/ivpu/ivpu_hw_40xx.c     | 1178 +++++++++++++++++++++++++
 drivers/accel/ivpu/ivpu_hw_40xx_reg.h |  267 ++++++
 7 files changed, 1462 insertions(+), 2 deletions(-)
 create mode 100644 drivers/accel/ivpu/ivpu_hw_40xx.c
 create mode 100644 drivers/accel/ivpu/ivpu_hw_40xx_reg.h
drivers/accel/ivpu/Makefile +1 -0
index 3179e146e173..e4328b430564 100644
@@ -8,6 +8,7 @@ intel_vpu-y := \
 	ivpu_fw_log.o \
 	ivpu_gem.o \
 	ivpu_hw_37xx.o \
+	ivpu_hw_40xx.o \
 	ivpu_ipc.o \
 	ivpu_job.o \
 	ivpu_jsm_msg.o \
drivers/accel/ivpu/ivpu_drv.c +8 -2
index 3da15890bc59..ba79f397c9e8 100644
@@ -501,8 +501,13 @@ static int ivpu_dev_init(struct ivpu_device *vdev)
 	if (!vdev->pm)
 		return -ENOMEM;
 
-	vdev->hw->ops = &ivpu_hw_37xx_ops;
-	vdev->hw->dma_bits = 38;
+	if (ivpu_hw_gen(vdev) >= IVPU_HW_40XX) {
+		vdev->hw->ops = &ivpu_hw_40xx_ops;
+		vdev->hw->dma_bits = 48;
+	} else {
+		vdev->hw->ops = &ivpu_hw_37xx_ops;
+		vdev->hw->dma_bits = 38;
+	}
 
 	vdev->platform = IVPU_PLATFORM_INVALID;
 	vdev->context_xa_limit.min = IVPU_USER_CONTEXT_MIN_SSID;
@@ -629,6 +634,7 @@ static void ivpu_dev_fini(struct ivpu_device *vdev)
 
 static struct pci_device_id ivpu_pci_ids[] = {
 	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_MTL) },
+	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_LNL) },
 	{ }
 };
 MODULE_DEVICE_TABLE(pci, ivpu_pci_ids);
drivers/accel/ivpu/ivpu_drv.h +5 -0
index 5808a4e6bb6d..9e8c075fe9ef 100644
@@ -23,8 +23,10 @@
 #define DRIVER_DATE "20230117"
 
 #define PCI_DEVICE_ID_MTL   0x7d1d
+#define PCI_DEVICE_ID_LNL   0x643e
 
 #define IVPU_HW_37XX	37
+#define IVPU_HW_40XX	40
 
 #define IVPU_GLOBAL_CONTEXT_MMU_SSID 0
 /* SSID 1 is used by the VPU to represent invalid context */
@@ -78,6 +80,7 @@ struct ivpu_wa_table {
 	bool clear_runtime_mem;
 	bool d3hot_after_power_off;
 	bool interrupt_clear_with_0;
+	bool disable_clock_relinquish;
 };
 
 struct ivpu_hw_info;
@@ -163,6 +166,8 @@ static inline int ivpu_hw_gen(struct ivpu_device *vdev)
 	switch (ivpu_device_id(vdev)) {
 	case PCI_DEVICE_ID_MTL:
 		return IVPU_HW_37XX;
+	case PCI_DEVICE_ID_LNL:
+		return IVPU_HW_40XX;
 	default:
 		ivpu_err(vdev, "Unknown VPU device\n");
 		return 0;
drivers/accel/ivpu/ivpu_fw.c +2 -0
index 7e75439dec60..9827ea4d7b83 100644
@@ -51,6 +51,8 @@ static struct {
 	{ IVPU_HW_37XX, "vpu_37xx.bin" },
 	{ IVPU_HW_37XX, "mtl_vpu.bin" },
 	{ IVPU_HW_37XX, "intel/vpu/vpu_37xx_v0.0.bin" },
+	{ IVPU_HW_40XX, "vpu_40xx.bin" },
+	{ IVPU_HW_40XX, "intel/vpu/vpu_40xx_v0.0.bin" },
 };
 
 static int ivpu_fw_request(struct ivpu_device *vdev)
drivers/accel/ivpu/ivpu_hw.h +1 -0
index 69e52d21cd10..ab341237bcf9 100644
@@ -60,6 +60,7 @@ struct ivpu_hw_info {
 };
 
 extern const struct ivpu_hw_ops ivpu_hw_37xx_ops;
+extern const struct ivpu_hw_ops ivpu_hw_40xx_ops;
 
 static inline int ivpu_hw_info_init(struct ivpu_device *vdev)
 {
drivers/accel/ivpu/ivpu_hw_40xx.c new file +1178 -0

1,178 lines not on this page · raw message

drivers/accel/ivpu/ivpu_hw_40xx_reg.h new file +267 -0

267 lines not on this page · raw message

Signature · 1 line
2.25.1