Skip to contentSkip to conversation

accel/ivpu: Changes for 6.11

PATCH Applied Jacek Lawrynowicz 1 participant 17 messages Jun 11, 2024 – Jun 14, 2024

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

cover accel/ivpu: Changes for 6.11

Power usage and security fixes along with some cleanup.

Andrzej Kacprowski (1):
accel/ivpu: Increase autosuspend delay to 100ms on 40xx

Jacek Lawrynowicz (6):
accel/ivpu: Remove suspend_reschedule_counter accel/ivpu: Implement DCT handling accel/ivpu: Make selected params read-only accel/ivpu: Disable MMU before checking for idle accel/ivpu: Remove duplicated debug messages accel/ivpu: Remove unused ivpu_rpm_get_if_active()

Maciej Falkowski (2):
accel/ivpu: Abort jobs of faulty context accel/ivpu: Add test mode flag for disabling timeouts

Wachowski, Karol (6):
accel/ivpu: Add wp0_during_power_up WA accel/ivpu: Disable disable_clock_relinquish WA for LNL B0+ accel/ivpu: Disable clock relinquish for MMIO reset accel/ivpu: Update FW BOOT API headers accel/ivpu: Make parts of FW image read-only accel/ivpu: Synchronize device unbind with recovery work

 drivers/accel/ivpu/ivpu_debugfs.c         |  39 +++++++-
 drivers/accel/ivpu/ivpu_drv.c             |  41 ++++++++-
 drivers/accel/ivpu/ivpu_drv.h             |   6 +-
 drivers/accel/ivpu/ivpu_fw.c              |  31 ++++++-
 drivers/accel/ivpu/ivpu_fw.h              |   2 +
 drivers/accel/ivpu/ivpu_hw.c              |  30 ++++--
 drivers/accel/ivpu/ivpu_hw.h              |   4 +-
 drivers/accel/ivpu/ivpu_hw_btrs.c         |  44 +++++++--
 drivers/accel/ivpu/ivpu_hw_btrs.h         |   6 +-
 drivers/accel/ivpu/ivpu_hw_btrs_lnl_reg.h |  10 +-
 drivers/accel/ivpu/ivpu_ipc.c             |   3 +-
 drivers/accel/ivpu/ivpu_ipc.h             |   4 +-
 drivers/accel/ivpu/ivpu_job.c             |  29 +++++-
 drivers/accel/ivpu/ivpu_job.h             |   4 +-
 drivers/accel/ivpu/ivpu_jsm_msg.c         |  52 +++++++----
 drivers/accel/ivpu/ivpu_jsm_msg.h         |   2 +
 drivers/accel/ivpu/ivpu_mmu.c             |  10 +-
 drivers/accel/ivpu/ivpu_mmu_context.c     |  86 ++++++++++++++++++
 drivers/accel/ivpu/ivpu_mmu_context.h     |   2 +
 drivers/accel/ivpu/ivpu_pm.c              | 106 ++++++++++++++++------
 drivers/accel/ivpu/ivpu_pm.h              |  10 +-
 drivers/accel/ivpu/vpu_boot_api.h         |  16 +++-
 22 files changed, 447 insertions(+), 90 deletions(-)

--
2.45.1

#1 lore raw

PATCH 1/15 accel/ivpu: Add wp0_during_power_up WA

From: "Wachowski, Karol" <[email protected]>

Send workpoint 0 request during power up on 37xx. This is needed in rare case where WP0 was not sent during power down due to device hang.

---
 drivers/accel/ivpu/ivpu_drv.h |  1 +
 drivers/accel/ivpu/ivpu_hw.c  | 11 +++++++++++
 2 files changed, 12 insertions(+)
drivers/accel/ivpu/ivpu_drv.h +1 -0
index 39df96a7623b..823e10c41816 100644
@@ -102,6 +102,7 @@ struct ivpu_wa_table {
 	bool interrupt_clear_with_0;
 	bool disable_clock_relinquish;
 	bool disable_d0i3_msg;
+	bool wp0_during_power_up;
 };
 
 struct ivpu_hw_info;
drivers/accel/ivpu/ivpu_hw.c +11 -0
index 9f5e3875baf1..daf1e4afb479 100644
@@ -64,10 +64,14 @@ static void wa_init(struct ivpu_device *vdev)
 	if (ivpu_device_id(vdev) == PCI_DEVICE_ID_LNL)
 		vdev->wa.disable_clock_relinquish = true;
 
+	if (ivpu_hw_ip_gen(vdev) == IVPU_HW_IP_37XX)
+		vdev->wa.wp0_during_power_up = true;
+
 	IVPU_PRINT_WA(punit_disabled);
 	IVPU_PRINT_WA(clear_runtime_mem);
 	IVPU_PRINT_WA(interrupt_clear_with_0);
 	IVPU_PRINT_WA(disable_clock_relinquish);
+	IVPU_PRINT_WA(wp0_during_power_up);
 }
 
 static void timeouts_init(struct ivpu_device *vdev)
@@ -125,6 +129,13 @@ int ivpu_hw_power_up(struct ivpu_device *vdev)
 {
 	int ret;
 
+	if (IVPU_WA(wp0_during_power_up)) {
+		/* WP requests may fail when powering down, so issue WP 0 here */
+		ret = wp_disable(vdev);
+		if (ret)
+			ivpu_warn(vdev, "Failed to disable workpoint: %d\n", ret);
+	}
+
 	ret = ivpu_hw_btrs_d0i3_disable(vdev);
 	if (ret)
 		ivpu_warn(vdev, "Failed to disable D0I3: %d\n", ret);
Signature · 1 line
2.45.1
#2 lore raw

PATCH 2/15 accel/ivpu: Abort jobs of faulty context

In reply to Jacek Lawrynowicz

From: Maciej Falkowski <[email protected]>

Abort all jobs that belong to contexts generating MMU faults in order to avoid flooding host with MMU IRQs.

Jobs are cancelled with:
- SSID_RELEASE command when OS scheduling is enabled
- DESTROY_CMDQ command when HW scheduling is enabled

---
 drivers/accel/ivpu/ivpu_drv.c     | 23 +++++++++++++++++++++++
 drivers/accel/ivpu/ivpu_drv.h     |  1 +
 drivers/accel/ivpu/ivpu_hw.h      |  3 ++-
 drivers/accel/ivpu/ivpu_ipc.c     |  3 +--
 drivers/accel/ivpu/ivpu_ipc.h     |  4 +++-
 drivers/accel/ivpu/ivpu_job.c     | 29 ++++++++++++++++++++++++++++-
 drivers/accel/ivpu/ivpu_job.h     |  4 +++-
 drivers/accel/ivpu/ivpu_jsm_msg.c |  9 +++++++--
 drivers/accel/ivpu/ivpu_mmu.c     | 10 +++++++---
 9 files changed, 75 insertions(+), 11 deletions(-)
drivers/accel/ivpu/ivpu_drv.c +23 -0
index f3e0d55f4adb..3ce12b66f699 100644
@@ -446,6 +446,26 @@ static const struct drm_driver driver = {
 	.minor = DRM_IVPU_DRIVER_MINOR,
 };
 
+static void ivpu_context_abort_invalid(struct ivpu_device *vdev)
+{
+	struct ivpu_file_priv *file_priv;
+	unsigned long ctx_id;
+
+	mutex_lock(&vdev->context_list_lock);
+
+	xa_for_each(&vdev->context_xa, ctx_id, file_priv) {
+		if (!file_priv->has_mmu_faults || file_priv->aborted)
+			continue;
+
+		mutex_lock(&file_priv->lock);
+		ivpu_context_abort_locked(file_priv);
+		file_priv->aborted = true;
+		mutex_unlock(&file_priv->lock);
+	}
+
+	mutex_unlock(&vdev->context_list_lock);
+}
+
 static irqreturn_t ivpu_irq_thread_handler(int irq, void *arg)
 {
 	struct ivpu_device *vdev = arg;
@@ -459,6 +479,9 @@ static irqreturn_t ivpu_irq_thread_handler(int irq, void *arg)
 		case IVPU_HW_IRQ_SRC_IPC:
 			ivpu_ipc_irq_thread_handler(vdev);
 			break;
+		case IVPU_HW_IRQ_SRC_MMU_EVTQ:
+			ivpu_context_abort_invalid(vdev);
+			break;
 		default:
 			ivpu_err_ratelimited(vdev, "Unknown IRQ source: %u\n", irq_src);
 			break;
drivers/accel/ivpu/ivpu_drv.h +1 -0
index 823e10c41816..dc6ad1978a3b 100644
@@ -169,6 +169,7 @@ struct ivpu_file_priv {
 	struct ivpu_bo *ms_info_bo;
 	bool has_mmu_faults;
 	bool bound;
+	bool aborted;
 };
 
 extern int ivpu_dbg_mask;
drivers/accel/ivpu/ivpu_hw.h +2 -1
index 8ddf9f93189d..1a55538aafdc 100644
@@ -1,6 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0-only */
 /*
- * Copyright (C) 2020 - 2024 Intel Corporation
+ * Copyright (C) 2020-2024 Intel Corporation
  */
 
 #ifndef __IVPU_HW_H__
@@ -15,6 +15,7 @@
 #define IVPU_HW_IRQ_FIFO_LENGTH 1024
 
 #define IVPU_HW_IRQ_SRC_IPC 1
+#define IVPU_HW_IRQ_SRC_MMU_EVTQ 2
 
 struct ivpu_addr_range {
 	resource_size_t start;
drivers/accel/ivpu/ivpu_ipc.c +1 -2
index 74ab964d229b..78b32a823241 100644
@@ -210,8 +210,7 @@ void ivpu_ipc_consumer_del(struct ivpu_device *vdev, struct ivpu_ipc_consumer *c
 	ivpu_ipc_tx_release(vdev, cons->tx_vpu_addr);
 }
 
-static int
-ivpu_ipc_send(struct ivpu_device *vdev, struct ivpu_ipc_consumer *cons, struct vpu_jsm_msg *req)
+int ivpu_ipc_send(struct ivpu_device *vdev, struct ivpu_ipc_consumer *cons, struct vpu_jsm_msg *req)
 {
 	struct ivpu_ipc_info *ipc = vdev->ipc;
 	int ret;
drivers/accel/ivpu/ivpu_ipc.h +3 -1
index 75f532428d68..4fe38141045e 100644
@@ -1,6 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0-only */
 /*
- * Copyright (C) 2020-2023 Intel Corporation
+ * Copyright (C) 2020-2024 Intel Corporation
  */
 
 #ifndef __IVPU_IPC_H__
@@ -96,6 +96,8 @@ void ivpu_ipc_consumer_add(struct ivpu_device *vdev, struct ivpu_ipc_consumer *c
 			   u32 channel, ivpu_ipc_rx_callback_t callback);
 void ivpu_ipc_consumer_del(struct ivpu_device *vdev, struct ivpu_ipc_consumer *cons);
 
+int ivpu_ipc_send(struct ivpu_device *vdev, struct ivpu_ipc_consumer *cons,
+		  struct vpu_jsm_msg *req);
 int ivpu_ipc_receive(struct ivpu_device *vdev, struct ivpu_ipc_consumer *cons,
 		     struct ivpu_ipc_hdr *ipc_buf, struct vpu_jsm_msg *jsm_msg,
 		     unsigned long timeout_ms);
drivers/accel/ivpu/ivpu_job.c +28 -1
index e4e24813fe03..be2e2bf0f43f 100644
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * Copyright (C) 2020-2023 Intel Corporation
+ * Copyright (C) 2020-2024 Intel Corporation
  */
 
 #include <drm/drm_file.h>
@@ -312,6 +312,33 @@ void ivpu_cmdq_reset_all_contexts(struct ivpu_device *vdev)
 	mutex_unlock(&vdev->context_list_lock);
 }
 
+static void ivpu_cmdq_fini_all(struct ivpu_file_priv *file_priv)
+{
+	u16 engine;
+	u8 priority;
+
+	for (engine = 0; engine < IVPU_NUM_ENGINES; engine++) {
+		for (priority = 0; priority < IVPU_NUM_PRIORITIES; priority++) {
+			int cmdq_idx = IVPU_CMDQ_INDEX(engine, priority);
+
+			if (file_priv->cmdq[cmdq_idx])
+				ivpu_cmdq_fini(file_priv, file_priv->cmdq[cmdq_idx]);
+		}
+	}
+}
+
+void ivpu_context_abort_locked(struct ivpu_file_priv *file_priv)
+{
+	struct ivpu_device *vdev = file_priv->vdev;
+
+	lockdep_assert_held(&file_priv->lock);
+
+	ivpu_cmdq_fini_all(file_priv);
+
+	if (vdev->hw->sched_mode == VPU_SCHEDULING_MODE_OS)
+		ivpu_jsm_context_release(vdev, file_priv->ctx.id);
+}
+
 static int ivpu_cmdq_push_job(struct ivpu_cmdq *cmdq, struct ivpu_job *job)
 {
 	struct ivpu_device *vdev = job->vdev;
drivers/accel/ivpu/ivpu_job.h +3 -1
index e50002b5788c..6accb94028c7 100644
@@ -1,6 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0-only */
 /*
- * Copyright (C) 2020-2023 Intel Corporation
+ * Copyright (C) 2020-2024 Intel Corporation
  */
 
 #ifndef __IVPU_JOB_H__
@@ -57,6 +57,8 @@ struct ivpu_job {
 
 int ivpu_submit_ioctl(struct drm_device *dev, void *data, struct drm_file *file);
 
+void ivpu_context_abort_locked(struct ivpu_file_priv *file_priv);
+
 void ivpu_cmdq_release_all_locked(struct ivpu_file_priv *file_priv);
 void ivpu_cmdq_reset_all_contexts(struct ivpu_device *vdev);
 
drivers/accel/ivpu/ivpu_jsm_msg.c +7 -2
index e8dd73d947e4..3179e80de1ec 100644
@@ -255,11 +255,16 @@ int ivpu_jsm_context_release(struct ivpu_device *vdev, u32 host_ssid)
 {
 	struct vpu_jsm_msg req = { .type = VPU_JSM_MSG_SSID_RELEASE };
 	struct vpu_jsm_msg resp;
+	int ret;
 
 	req.payload.ssid_release.host_ssid = host_ssid;
 
-	return ivpu_ipc_send_receive(vdev, &req, VPU_JSM_MSG_SSID_RELEASE_DONE, &resp,
-				     VPU_IPC_CHAN_ASYNC_CMD, vdev->timeout.jsm);
+	ret = ivpu_ipc_send_receive(vdev, &req, VPU_JSM_MSG_SSID_RELEASE_DONE, &resp,
+				    VPU_IPC_CHAN_ASYNC_CMD, vdev->timeout.jsm);
+	if (ret)
+		ivpu_warn_ratelimited(vdev, "Failed to release context: %d\n", ret);
+
+	return ret;
 }
 
 int ivpu_jsm_pwr_d0i3_enter(struct ivpu_device *vdev)
drivers/accel/ivpu/ivpu_mmu.c +7 -3
index 8682e6145520..c078e214b221 100644
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * Copyright (C) 2020-2023 Intel Corporation
+ * Copyright (C) 2020-2024 Intel Corporation
  */
 
 #include <linux/circ_buf.h>
@@ -878,8 +878,9 @@ static void ivpu_mmu_dump_event(struct ivpu_device *vdev, u32 *event)
 	u64 in_addr = ((u64)event[5]) << 32 | event[4];
 	u32 sid = event[1];
 
-	ivpu_err(vdev, "MMU EVTQ: 0x%x (%s) SSID: %d SID: %d, e[2] %08x, e[3] %08x, in addr: 0x%llx, fetch addr: 0x%llx\n",
-		 op, ivpu_mmu_event_to_str(op), ssid, sid, event[2], event[3], in_addr, fetch_addr);
+	ivpu_err_ratelimited(vdev, "MMU EVTQ: 0x%x (%s) SSID: %d SID: %d, e[2] %08x, e[3] %08x, in addr: 0x%llx, fetch addr: 0x%llx\n",
+			     op, ivpu_mmu_event_to_str(op), ssid, sid,
+			     event[2], event[3], in_addr, fetch_addr);
 }
 
 static u32 *ivpu_mmu_get_event(struct ivpu_device *vdev)
@@ -915,6 +916,9 @@ void ivpu_mmu_irq_evtq_handler(struct ivpu_device *vdev)
 		ivpu_mmu_user_context_mark_invalid(vdev, ssid);
 		REGV_WR32(IVPU_MMU_REG_EVTQ_CONS_SEC, vdev->mmu->evtq.cons);
 	}
+
+	if (!kfifo_put(&vdev->hw->irq.fifo, IVPU_HW_IRQ_SRC_MMU_EVTQ))
+		ivpu_err_ratelimited(vdev, "IRQ FIFO full\n");
 }
 
 void ivpu_mmu_evtq_dump(struct ivpu_device *vdev)
Signature · 1 line
2.45.1
#3 lore raw

PATCH 3/15 accel/ivpu: Remove suspend_reschedule_counter

In reply to Jacek Lawrynowicz

Don't retry runtime suspend. It is now expected to succeed on the first try. After autosuspend_delay passed, FW should already be idle and ready for warm suspend.

---
 drivers/accel/ivpu/ivpu_pm.c | 31 +++++++++++--------------------
 drivers/accel/ivpu/ivpu_pm.h |  3 +--
 2 files changed, 12 insertions(+), 22 deletions(-)
drivers/accel/ivpu/ivpu_pm.c +11 -20
index 02b4eac13f8b..9d5f500afd20 100644
@@ -237,33 +237,28 @@ int ivpu_pm_runtime_suspend_cb(struct device *dev)
 {
 	struct drm_device *drm = dev_get_drvdata(dev);
 	struct ivpu_device *vdev = to_ivpu_device(drm);
-	bool hw_is_idle = true;
-	int ret;
+	int ret, ret_d0i3;
+	bool is_idle;
 
 	drm_WARN_ON(&vdev->drm, !xa_empty(&vdev->submitted_jobs_xa));
 	drm_WARN_ON(&vdev->drm, work_pending(&vdev->pm->recovery_work));
 
 	ivpu_dbg(vdev, PM, "Runtime suspend..\n");
 
-	if (!ivpu_hw_is_idle(vdev) && vdev->pm->suspend_reschedule_counter) {
-		ivpu_dbg(vdev, PM, "Failed to enter idle, rescheduling suspend, retries left %d\n",
-			 vdev->pm->suspend_reschedule_counter);
-		pm_schedule_suspend(dev, vdev->timeout.reschedule_suspend);
-		vdev->pm->suspend_reschedule_counter--;
-		return -EAGAIN;
-	}
+	is_idle = ivpu_hw_is_idle(vdev);
+	if (!is_idle)
+		ivpu_err(vdev, "NPU is not idle before autosuspend\n");
 
-	if (!vdev->pm->suspend_reschedule_counter)
-		hw_is_idle = false;
-	else if (ivpu_jsm_pwr_d0i3_enter(vdev))
-		hw_is_idle = false;
+	ret_d0i3 = ivpu_jsm_pwr_d0i3_enter(vdev);
+	if (ret_d0i3)
+		ivpu_err(vdev, "Failed to prepare for d0i3: %d\n", ret_d0i3);
 
 	ret = ivpu_suspend(vdev);
 	if (ret)
 		ivpu_err(vdev, "Failed to suspend NPU: %d\n", ret);
 
-	if (!hw_is_idle) {
-		ivpu_err(vdev, "NPU failed to enter idle, force suspended.\n");
+	if (!is_idle || ret_d0i3) {
+		ivpu_err(vdev, "Forcing cold boot due to previous errors\n");
 		atomic_inc(&vdev->pm->reset_counter);
 		ivpu_fw_log_dump(vdev);
 		ivpu_pm_prepare_cold_boot(vdev);
@@ -271,8 +266,6 @@ int ivpu_pm_runtime_suspend_cb(struct device *dev)
 		ivpu_pm_prepare_warm_boot(vdev);
 	}
 
-	vdev->pm->suspend_reschedule_counter = PM_RESCHEDULE_LIMIT;
-
 	ivpu_dbg(vdev, PM, "Runtime suspend done.\n");
 
 	return 0;
@@ -300,8 +293,7 @@ int ivpu_rpm_get(struct ivpu_device *vdev)
 	int ret;
 
 	ret = pm_runtime_resume_and_get(vdev->drm.dev);
-	if (!drm_WARN_ON(&vdev->drm, ret < 0))
-		vdev->pm->suspend_reschedule_counter = PM_RESCHEDULE_LIMIT;
+	drm_WARN_ON(&vdev->drm, ret < 0);
 
 	return ret;
 }
@@ -365,7 +357,6 @@ void ivpu_pm_init(struct ivpu_device *vdev)
 	int delay;
 
 	pm->vdev = vdev;
-	pm->suspend_reschedule_counter = PM_RESCHEDULE_LIMIT;
 
 	init_rwsem(&pm->reset_lock);
 	atomic_set(&pm->reset_pending, 0);
drivers/accel/ivpu/ivpu_pm.h +1 -2
index ec60fbeefefc..e524412765be 100644
@@ -1,6 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0-only */
 /*
- * Copyright (C) 2020-2023 Intel Corporation
+ * Copyright (C) 2020-2024 Intel Corporation
  */
 
 #ifndef __IVPU_PM_H__
@@ -19,7 +19,6 @@ struct ivpu_pm_info {
 	atomic_t reset_counter;
 	atomic_t reset_pending;
 	bool is_warmboot;
-	u32 suspend_reschedule_counter;
 };
 
 void ivpu_pm_init(struct ivpu_device *vdev);
Signature · 1 line
2.45.1
#4 lore raw

PATCH 4/15 accel/ivpu: Disable disable_clock_relinquish WA for LNL B0+

In reply to Jacek Lawrynowicz

From: "Wachowski, Karol" <[email protected]>

This WA is only needed for LNL revision A.

---
 drivers/accel/ivpu/ivpu_drv.h | 2 ++
 drivers/accel/ivpu/ivpu_hw.c  | 3 ++-
 2 files changed, 4 insertions(+), 1 deletion(-)
drivers/accel/ivpu/ivpu_drv.h +2 -0
index dc6ad1978a3b..d340bd8d66eb 100644
@@ -32,6 +32,8 @@
 #define IVPU_HW_IP_50XX 50
 #define IVPU_HW_IP_60XX 60
 
+#define IVPU_HW_IP_REV_LNL_B0 4
+
 #define IVPU_HW_BTRS_MTL 1
 #define IVPU_HW_BTRS_LNL 2
 
drivers/accel/ivpu/ivpu_hw.c +2 -1
index daf1e4afb479..09398a17c710 100644
@@ -61,7 +61,8 @@ static void wa_init(struct ivpu_device *vdev)
 	if (ivpu_hw_btrs_gen(vdev) == IVPU_HW_BTRS_MTL)
 		vdev->wa.interrupt_clear_with_0 = ivpu_hw_btrs_irqs_clear_with_0_mtl(vdev);
 
-	if (ivpu_device_id(vdev) == PCI_DEVICE_ID_LNL)
+	if (ivpu_device_id(vdev) == PCI_DEVICE_ID_LNL &&
+	    ivpu_revision(vdev) < IVPU_HW_IP_REV_LNL_B0)
 		vdev->wa.disable_clock_relinquish = true;
 
 	if (ivpu_hw_ip_gen(vdev) == IVPU_HW_IP_37XX)
Signature · 1 line
2.45.1
#5 lore raw

PATCH 5/15 accel/ivpu: Disable clock relinquish for MMIO reset

In reply to Jacek Lawrynowicz

From: "Wachowski, Karol" <[email protected]>

It is required to disable NPU clock relinquish for the time of MMIO reset. Clock relinquish gets into default (enabled) state after MMIO reset is performed.

---
 drivers/accel/ivpu/ivpu_hw_btrs.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/accel/ivpu/ivpu_hw_btrs.c +2 -0
index 13734d1abc7d..123c1f2fd554 100644
@@ -504,6 +504,8 @@ static int ip_reset_lnl(struct ivpu_device *vdev)
 	int ret;
 	u32 val;
 
+	ivpu_hw_btrs_clock_relinquish_disable_lnl(vdev);
+
 	ret = REGB_POLL_FLD(VPU_HW_BTRS_LNL_IP_RESET, TRIGGER, 0, TIMEOUT_US);
 	if (ret) {
 		ivpu_err(vdev, "Wait for *_TRIGGER timed out\n");
Signature · 1 line
2.45.1
#6 lore raw

PATCH 6/15 accel/ivpu: Implement DCT handling

In reply to Jacek Lawrynowicz

When host system is under heavy load and the NPU is already running on the lowest frequency, PUNIT may request Duty Cycle Throttling (DCT). This will further reduce NPU power usage.

PUNIT requests DCT mode using Survabilty IRQ and mailbox register. The driver then issues a JSM message to the FW that enables the DCT mode. If the NPU resets while in DCT mode, the driver request DCT mode during FW boot.

Also add debugfs "dct" file that allows to set arbitrary DCT percentage, which is used by driver tests.

---
 drivers/accel/ivpu/ivpu_debugfs.c         | 39 ++++++++++++-
 drivers/accel/ivpu/ivpu_drv.c             | 10 +++-
 drivers/accel/ivpu/ivpu_hw.h              |  1 +
 drivers/accel/ivpu/ivpu_hw_btrs.c         | 42 ++++++++++----
 drivers/accel/ivpu/ivpu_hw_btrs.h         |  6 +-
 drivers/accel/ivpu/ivpu_hw_btrs_lnl_reg.h | 10 ++--
 drivers/accel/ivpu/ivpu_jsm_msg.c         | 23 ++++++++
 drivers/accel/ivpu/ivpu_jsm_msg.h         |  2 +
 drivers/accel/ivpu/ivpu_pm.c              | 67 ++++++++++++++++++++++-
 drivers/accel/ivpu/ivpu_pm.h              |  6 ++
 10 files changed, 186 insertions(+), 20 deletions(-)
drivers/accel/ivpu/ivpu_debugfs.c +37 -2
index 10d6408c9831..6f86f8df30db 100644
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * Copyright (C) 2020-2023 Intel Corporation
+ * Copyright (C) 2020-2024 Intel Corporation
  */
 
 #include <linux/debugfs.h>
@@ -381,6 +381,39 @@ static const struct file_operations ivpu_resume_engine_fops = {
 	.write = ivpu_resume_engine_fn,
 };
 
+static int dct_active_get(void *data, u64 *active_percent)
+{
+	struct ivpu_device *vdev = data;
+
+	*active_percent = vdev->pm->dct_active_percent;
+
+	return 0;
+}
+
+static int dct_active_set(void *data, u64 active_percent)
+{
+	struct ivpu_device *vdev = data;
+	int ret;
+
+	if (active_percent > 100)
+		return -EINVAL;
+
+	ret = ivpu_rpm_get(vdev);
+	if (ret)
+		return ret;
+
+	if (active_percent)
+		ret = ivpu_pm_dct_enable(vdev, active_percent);
+	else
+		ret = ivpu_pm_dct_disable(vdev);
+
+	ivpu_rpm_put(vdev);
+
+	return ret;
+}
+
+DEFINE_DEBUGFS_ATTRIBUTE(ivpu_dct_fops, dct_active_get, dct_active_set, "%llu\n");
+
 void ivpu_debugfs_init(struct ivpu_device *vdev)
 {
 	struct dentry *debugfs_root = vdev->drm.debugfs_root;
@@ -409,7 +442,9 @@ void ivpu_debugfs_init(struct ivpu_device *vdev)
 	debugfs_create_file("resume_engine", 0200, debugfs_root, vdev,
 			    &ivpu_resume_engine_fops);
 
-	if (ivpu_hw_ip_gen(vdev) >= IVPU_HW_IP_40XX)
+	if (ivpu_hw_ip_gen(vdev) >= IVPU_HW_IP_40XX) {
 		debugfs_create_file("fw_profiling_freq_drive", 0200,
 				    debugfs_root, vdev, &fw_profiling_freq_fops);
+		debugfs_create_file("dct", 0644, debugfs_root, vdev, &ivpu_dct_fops);
+	}
 }
drivers/accel/ivpu/ivpu_drv.c +9 -1
index 3ce12b66f699..ce91eafe5746 100644
@@ -391,8 +391,13 @@ int ivpu_boot(struct ivpu_device *vdev)
 	ivpu_hw_irq_enable(vdev);
 	ivpu_ipc_enable(vdev);
 
-	if (ivpu_fw_is_cold_boot(vdev))
+	if (ivpu_fw_is_cold_boot(vdev)) {
+		ret = ivpu_pm_dct_init(vdev);
+		if (ret)
+			return ret;
+
 		return ivpu_hw_sched_init(vdev);
+	}
 
 	return 0;
 }
@@ -482,6 +487,9 @@ static irqreturn_t ivpu_irq_thread_handler(int irq, void *arg)
 		case IVPU_HW_IRQ_SRC_MMU_EVTQ:
 			ivpu_context_abort_invalid(vdev);
 			break;
+		case IVPU_HW_IRQ_SRC_DCT:
+			ivpu_pm_dct_irq_thread_handler(vdev);
+			break;
 		default:
 			ivpu_err_ratelimited(vdev, "Unknown IRQ source: %u\n", irq_src);
 			break;
drivers/accel/ivpu/ivpu_hw.h +1 -0
index 1a55538aafdc..1c0c98e3afb8 100644
@@ -16,6 +16,7 @@
 
 #define IVPU_HW_IRQ_SRC_IPC 1
 #define IVPU_HW_IRQ_SRC_MMU_EVTQ 2
+#define IVPU_HW_IRQ_SRC_DCT 3
 
 struct ivpu_addr_range {
 	resource_size_t start;
drivers/accel/ivpu/ivpu_hw_btrs.c +32 -10

61 lines not on this page · raw message

drivers/accel/ivpu/ivpu_hw_btrs.h +5 -1
index b3e3ae2aa578..04f14f50fed6 100644
@@ -15,6 +15,9 @@
 #define PLL_PROFILING_FREQ_HIGH      400000000
 #define PLL_RATIO_TO_FREQ(x)         ((x) * PLL_REF_CLK_FREQ)
 
+#define DCT_DEFAULT_ACTIVE_PERCENT 15u
+#define DCT_PERIOD_US		   35300u
+
 int ivpu_hw_btrs_info_init(struct ivpu_device *vdev);
 void ivpu_hw_btrs_freq_ratios_init(struct ivpu_device *vdev);
 int ivpu_hw_btrs_irqs_clear_with_0_mtl(struct ivpu_device *vdev);
@@ -31,7 +34,8 @@ void ivpu_hw_btrs_ats_print_lnl(struct ivpu_device *vdev);
 void ivpu_hw_btrs_clock_relinquish_disable_lnl(struct ivpu_device *vdev);
 bool ivpu_hw_btrs_irq_handler_mtl(struct ivpu_device *vdev, int irq);
 bool ivpu_hw_btrs_irq_handler_lnl(struct ivpu_device *vdev, int irq);
-void ivpu_hw_btrs_dct_drive(struct ivpu_device *vdev, u32 dct_val);
+int ivpu_hw_btrs_dct_get_request(struct ivpu_device *vdev, bool *enable);
+void ivpu_hw_btrs_dct_set_status(struct ivpu_device *vdev, bool enable, u32 dct_percent);
 u32 ivpu_hw_btrs_pll_freq_get(struct ivpu_device *vdev);
 u32 ivpu_hw_btrs_ratio_to_freq(struct ivpu_device *vdev, u32 ratio);
 u32 ivpu_hw_btrs_telemetry_offset_get(struct ivpu_device *vdev);
drivers/accel/ivpu/ivpu_hw_btrs_lnl_reg.h +5 -5
index 93733bde02b0..fc51f3098f97 100644
@@ -44,11 +44,11 @@
 #define VPU_HW_BTRS_LNL_IMR_ERR_CFI1_HIGH			0x0000005cu
 #define VPU_HW_BTRS_LNL_IMR_ERR_CFI1_CLEAR			0x00000060u
 
-#define VPU_HW_BTRS_LNL_PCODE_MAILBOX				0x00000070u
-#define VPU_HW_BTRS_LNL_PCODE_MAILBOX_CMD_MASK			GENMASK(7, 0)
-#define VPU_HW_BTRS_LNL_PCODE_MAILBOX_PARAM1_MASK		GENMASK(15, 8)
-#define VPU_HW_BTRS_LNL_PCODE_MAILBOX_PARAM2_MASK		GENMASK(23, 16)
-#define VPU_HW_BTRS_LNL_PCODE_MAILBOX_PARAM3_MASK		GENMASK(31, 24)
+#define VPU_HW_BTRS_LNL_PCODE_MAILBOX_STATUS			0x00000070u
+#define VPU_HW_BTRS_LNL_PCODE_MAILBOX_STATUS_CMD_MASK		GENMASK(7, 0)
+#define VPU_HW_BTRS_LNL_PCODE_MAILBOX_STATUS_PARAM1_MASK	GENMASK(15, 8)
+#define VPU_HW_BTRS_LNL_PCODE_MAILBOX_STATUS_PARAM2_MASK	GENMASK(23, 16)
+#define VPU_HW_BTRS_LNL_PCODE_MAILBOX_STATUS_PARAM3_MASK	GENMASK(31, 24)
 
 #define VPU_HW_BTRS_LNL_PCODE_MAILBOX_SHADOW			0x00000074u
 #define VPU_HW_BTRS_LNL_PCODE_MAILBOX_SHADOW_CMD_MASK		GENMASK(7, 0)
drivers/accel/ivpu/ivpu_jsm_msg.c +23 -0
index 3179e80de1ec..216aa61ba209 100644
@@ -543,3 +543,26 @@ int ivpu_jsm_metric_streamer_info(struct ivpu_device *vdev, u64 metric_group_mas
 
 	return ret;
 }
+
+int ivpu_jsm_dct_enable(struct ivpu_device *vdev, u32 active_us, u32 inactive_us)
+{
+	struct vpu_jsm_msg req = { .type = VPU_JSM_MSG_DCT_ENABLE };
+	struct vpu_jsm_msg resp;
+
+	req.payload.pwr_dct_control.dct_active_us = active_us;
+	req.payload.pwr_dct_control.dct_inactive_us = inactive_us;
+
+	return ivpu_ipc_send_receive_active(vdev, &req, VPU_JSM_MSG_DCT_ENABLE_DONE,
+					    &resp, VPU_IPC_CHAN_ASYNC_CMD,
+					    vdev->timeout.jsm);
+}
+
+int ivpu_jsm_dct_disable(struct ivpu_device *vdev)
+{
+	struct vpu_jsm_msg req = { .type = VPU_JSM_MSG_DCT_DISABLE };
+	struct vpu_jsm_msg resp;
+
+	return ivpu_ipc_send_receive_active(vdev, &req, VPU_JSM_MSG_DCT_DISABLE_DONE,
+					    &resp, VPU_IPC_CHAN_ASYNC_CMD,
+					    vdev->timeout.jsm);
+}
drivers/accel/ivpu/ivpu_jsm_msg.h +2 -0
index 060363409fb3..e4e42c0ff6e6 100644
@@ -41,4 +41,6 @@ int ivpu_jsm_metric_streamer_update(struct ivpu_device *vdev, u64 metric_group_m
 				    u64 buffer_addr, u64 buffer_size, u64 *bytes_written);
 int ivpu_jsm_metric_streamer_info(struct ivpu_device *vdev, u64 metric_group_mask, u64 buffer_addr,
 				  u64 buffer_size, u32 *sample_size, u64 *info_size);
+int ivpu_jsm_dct_enable(struct ivpu_device *vdev, u32 active_us, u32 inactive_us);
+int ivpu_jsm_dct_disable(struct ivpu_device *vdev);
 #endif
drivers/accel/ivpu/ivpu_pm.c +66 -1

76 lines not on this page · raw message

drivers/accel/ivpu/ivpu_pm.h +6 -0
index e524412765be..c08a3ddf09c1 100644
@@ -19,6 +19,7 @@ struct ivpu_pm_info {
 	atomic_t reset_counter;
 	atomic_t reset_pending;
 	bool is_warmboot;
+	u8 dct_active_percent;
 };
 
 void ivpu_pm_init(struct ivpu_device *vdev);
@@ -42,4 +43,9 @@ void ivpu_pm_trigger_recovery(struct ivpu_device *vdev, const char *reason);
 void ivpu_start_job_timeout_detection(struct ivpu_device *vdev);
 void ivpu_stop_job_timeout_detection(struct ivpu_device *vdev);
 
+int ivpu_pm_dct_init(struct ivpu_device *vdev);
+int ivpu_pm_dct_enable(struct ivpu_device *vdev, u8 active_percent);
+int ivpu_pm_dct_disable(struct ivpu_device *vdev);
+void ivpu_pm_dct_irq_thread_handler(struct ivpu_device *vdev);
+
 #endif /* __IVPU_PM_H__ */
Signature · 1 line
2.45.1
#7 lore raw

PATCH 7/15 accel/ivpu: Make selected params read-only

In reply to Jacek Lawrynowicz

Make disable_mmu_cont_pages and force_snoop params read-only. It is unsafe to change these params after driver is loaded.

---
 drivers/accel/ivpu/ivpu_drv.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/accel/ivpu/ivpu_drv.c +2 -2
index ce91eafe5746..c59c6f113098 100644
@@ -58,11 +58,11 @@ module_param_named(sched_mode, ivpu_sched_mode, int, 0444);
 MODULE_PARM_DESC(sched_mode, "Scheduler mode: 0 - Default scheduler, 1 - Force HW scheduler");
 
 bool ivpu_disable_mmu_cont_pages;
-module_param_named(disable_mmu_cont_pages, ivpu_disable_mmu_cont_pages, bool, 0644);
+module_param_named(disable_mmu_cont_pages, ivpu_disable_mmu_cont_pages, bool, 0444);
 MODULE_PARM_DESC(disable_mmu_cont_pages, "Disable MMU contiguous pages optimization");
 
 bool ivpu_force_snoop;
-module_param_named(force_snoop, ivpu_force_snoop, bool, 0644);
+module_param_named(force_snoop, ivpu_force_snoop, bool, 0444);
 MODULE_PARM_DESC(force_snoop, "Force snooping for NPU host memory access");
 
 struct ivpu_file_priv *ivpu_file_priv_get(struct ivpu_file_priv *file_priv)
Signature · 1 line
2.45.1
#8 lore raw

PATCH 8/15 accel/ivpu: Update FW BOOT API headers

In reply to Jacek Lawrynowicz

From: "Wachowski, Karol" <[email protected]>

This commit bumps BOOT API version to 3.24

---
 drivers/accel/ivpu/vpu_boot_api.h | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
drivers/accel/ivpu/vpu_boot_api.h +14 -2
index 87cac7bc730a..82954b91b748 100644
@@ -27,7 +27,7 @@
  * Minor version changes when API backward compatibility is preserved.
  * Resets to 0 if Major version is incremented.
  */
-#define VPU_BOOT_API_VER_MINOR 22
+#define VPU_BOOT_API_VER_MINOR 24
 
 /*
  * API header changed (field names, documentation, formatting) but API itself has not been changed
@@ -80,6 +80,11 @@ struct vpu_firmware_header {
 	u32 preemption_buffer_2_size;
 	/* Space reserved for future preemption-related fields. */
 	u32 preemption_reserved[6];
+	/* FW image read only section start address, 4KB aligned */
+	u64 ro_section_start_address;
+	/* FW image read only section size, 4KB aligned */
+	u32 ro_section_size;
+	u32 reserved;
 };
 
 /*
@@ -333,7 +338,14 @@ struct vpu_boot_params {
 	 * The KMD is required to update this value on every VPU reset.
 	 */
 	u64 system_time_us;
-	u32 pad4[18];
+	u32 pad4[2];
+	/*
+	 * The delta between device monotonic time and the current value of the
+	 * HW timestamp register, in ticks. Written by the firmware during boot.
+	 * Can be used by the KMD to calculate device time.
+	 */
+	u64 device_time_delta_ticks;
+	u32 pad7[14];
 	/* Warm boot information: 0x400 - 0x43F */
 	u32 warm_boot_sections_count;
 	u32 warm_boot_start_address_reference;
Signature · 1 line
2.45.1
#9 lore raw

PATCH 9/15 accel/ivpu: Make parts of FW image read-only

In reply to Jacek Lawrynowicz

From: "Wachowski, Karol" <[email protected]>

Implement setting specified buffer ranges as read-only.
In case if specified range is not 64K aligned and 64K contiguous MMU600 pages are turned on, split 64K mapping to allow 4K granularity for read-only configuration.

---
 drivers/accel/ivpu/ivpu_fw.c          | 31 +++++++++-
 drivers/accel/ivpu/ivpu_fw.h          |  2 +
 drivers/accel/ivpu/ivpu_mmu_context.c | 86 +++++++++++++++++++++++++++
 drivers/accel/ivpu/ivpu_mmu_context.h |  2 +
 4 files changed, 120 insertions(+), 1 deletion(-)
drivers/accel/ivpu/ivpu_fw.c +30 -1
index 1fc4befe7461..de3d66116375 100644
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * Copyright (C) 2020-2023 Intel Corporation
+ * Copyright (C) 2020-2024 Intel Corporation
  */
 
 #include <linux/firmware.h>
@@ -123,6 +123,14 @@ ivpu_fw_check_api_ver_lt(struct ivpu_device *vdev, const struct vpu_firmware_hea
 	return false;
 }
 
+static bool is_within_range(u64 addr, size_t size, u64 range_start, size_t range_size)
+{
+	if (addr < range_start || addr + size > range_start + range_size)
+		return false;
+
+	return true;
+}
+
 static int ivpu_fw_parse(struct ivpu_device *vdev)
 {
 	struct ivpu_fw_info *fw = vdev->fw;
@@ -205,10 +213,24 @@ static int ivpu_fw_parse(struct ivpu_device *vdev)
 	fw->primary_preempt_buf_size = fw_hdr->preemption_buffer_1_size;
 	fw->secondary_preempt_buf_size = fw_hdr->preemption_buffer_2_size;
 
+	if (fw_hdr->ro_section_start_address && !is_within_range(fw_hdr->ro_section_start_address,
+								 fw_hdr->ro_section_size,
+								 fw_hdr->image_load_address,
+								 fw_hdr->image_size)) {
+		ivpu_err(vdev, "Invalid read-only section: start address 0x%llx, size %u\n",
+			 fw_hdr->ro_section_start_address, fw_hdr->ro_section_size);
+		return -EINVAL;
+	}
+
+	fw->read_only_addr = fw_hdr->ro_section_start_address;
+	fw->read_only_size = fw_hdr->ro_section_size;
+
 	ivpu_dbg(vdev, FW_BOOT, "Size: file %lu image %u runtime %u shavenn %u\n",
 		 fw->file->size, fw->image_size, fw->runtime_size, fw->shave_nn_size);
 	ivpu_dbg(vdev, FW_BOOT, "Address: runtime 0x%llx, load 0x%llx, entry point 0x%llx\n",
 		 fw->runtime_addr, image_load_addr, fw->entry_point);
+	ivpu_dbg(vdev, FW_BOOT, "Read-only section: address 0x%llx, size %u\n",
+		 fw->read_only_addr, fw->read_only_size);
 
 	return 0;
 }
@@ -270,6 +292,13 @@ static int ivpu_fw_mem_init(struct ivpu_device *vdev)
 		return -ENOMEM;
 	}
 
+	ret = ivpu_mmu_context_set_pages_ro(vdev, &vdev->gctx, fw->read_only_addr,
+					    fw->read_only_size);
+	if (ret) {
+		ivpu_err(vdev, "Failed to set firmware image read-only\n");
+		goto err_free_fw_mem;
+	}
+
 	fw->mem_log_crit = ivpu_bo_create_global(vdev, IVPU_FW_CRITICAL_BUFFER_SIZE,
 						 DRM_IVPU_BO_CACHED | DRM_IVPU_BO_MAPPABLE);
 	if (!fw->mem_log_crit) {
drivers/accel/ivpu/ivpu_fw.h +2 -0
index 66fc7da3ab0f..40d9d17be3f5 100644
@@ -30,6 +30,8 @@ struct ivpu_fw_info {
 	u32 dvfs_mode;
 	u32 primary_preempt_buf_size;
 	u32 secondary_preempt_buf_size;
+	u64 read_only_addr;
+	u32 read_only_size;
 };
 
 int ivpu_fw_init(struct ivpu_device *vdev);
drivers/accel/ivpu/ivpu_mmu_context.c +86 -0

98 lines not on this page · raw message

drivers/accel/ivpu/ivpu_mmu_context.h +2 -0
index 535db3a1fc74..7f9aaf3d10c2 100644
@@ -46,5 +46,7 @@ int ivpu_mmu_context_map_sgt(struct ivpu_device *vdev, struct ivpu_mmu_context *
 			     u64 vpu_addr, struct sg_table *sgt, bool llc_coherent);
 void ivpu_mmu_context_unmap_sgt(struct ivpu_device *vdev, struct ivpu_mmu_context *ctx,
 				u64 vpu_addr, struct sg_table *sgt);
+int ivpu_mmu_context_set_pages_ro(struct ivpu_device *vdev, struct ivpu_mmu_context *ctx,
+				  u64 vpu_addr, size_t size);
 
 #endif /* __IVPU_MMU_CONTEXT_H__ */
Signature · 1 line
2.45.1
#10 lore raw

PATCH 10/15 accel/ivpu: Add test mode flag for disabling timeouts

In reply to Jacek Lawrynowicz

From: Maciej Falkowski <[email protected]>

Add new test mode flag that will disable all timeouts defined in timeout fields of struct ivpu_device. Remove also reschedule_suspend field as it is unused.

---
 drivers/accel/ivpu/ivpu_drv.h |  2 +-
 drivers/accel/ivpu/ivpu_hw.c  | 11 +++++++----
 2 files changed, 8 insertions(+), 5 deletions(-)
drivers/accel/ivpu/ivpu_drv.h +1 -1
index d340bd8d66eb..63f13b697eed 100644
@@ -150,7 +150,6 @@ struct ivpu_device {
 		int boot;
 		int jsm;
 		int tdr;
-		int reschedule_suspend;
 		int autosuspend;
 		int d0i3_entry_msg;
 	} timeout;
@@ -188,6 +187,7 @@ extern bool ivpu_force_snoop;
 #define IVPU_TEST_MODE_D0I3_MSG_ENABLE    BIT(5)
 #define IVPU_TEST_MODE_PREEMPTION_DISABLE BIT(6)
 #define IVPU_TEST_MODE_HWS_EXTRA_EVENTS	  BIT(7)
+#define IVPU_TEST_MODE_DISABLE_TIMEOUTS   BIT(8)
 extern int ivpu_test_mode;
 
 struct ivpu_file_priv *ivpu_file_priv_get(struct ivpu_file_priv *file_priv);
drivers/accel/ivpu/ivpu_hw.c +7 -4
index 09398a17c710..a4a13ac67047 100644
@@ -77,25 +77,28 @@ static void wa_init(struct ivpu_device *vdev)
 
 static void timeouts_init(struct ivpu_device *vdev)
 {
-	if (ivpu_is_fpga(vdev)) {
+	if (ivpu_test_mode & IVPU_TEST_MODE_DISABLE_TIMEOUTS) {
+		vdev->timeout.boot = -1;
+		vdev->timeout.jsm = -1;
+		vdev->timeout.tdr = -1;
+		vdev->timeout.autosuspend = -1;
+		vdev->timeout.d0i3_entry_msg = -1;
+	} else if (ivpu_is_fpga(vdev)) {
 		vdev->timeout.boot = 100000;
 		vdev->timeout.jsm = 50000;
 		vdev->timeout.tdr = 2000000;
-		vdev->timeout.reschedule_suspend = 1000;
 		vdev->timeout.autosuspend = -1;
 		vdev->timeout.d0i3_entry_msg = 500;
 	} else if (ivpu_is_simics(vdev)) {
 		vdev->timeout.boot = 50;
 		vdev->timeout.jsm = 500;
 		vdev->timeout.tdr = 10000;
-		vdev->timeout.reschedule_suspend = 10;
 		vdev->timeout.autosuspend = -1;
 		vdev->timeout.d0i3_entry_msg = 100;
 	} else {
 		vdev->timeout.boot = 1000;
 		vdev->timeout.jsm = 500;
 		vdev->timeout.tdr = 2000;
-		vdev->timeout.reschedule_suspend = 10;
 		vdev->timeout.autosuspend = 10;
 		vdev->timeout.d0i3_entry_msg = 5;
 	}
Signature · 1 line
2.45.1
#11 lore raw

PATCH 11/15 accel/ivpu: Disable MMU before checking for idle

In reply to Jacek Lawrynowicz

Disable MMU communication before checking if NPU is idle. NPU may otherwise be woken up when adding/removing contexts.

---
 drivers/accel/ivpu/ivpu_pm.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/accel/ivpu/ivpu_pm.c +2 -0
index 602fa4e65c22..e7aed16b1a36 100644
@@ -245,6 +245,8 @@ int ivpu_pm_runtime_suspend_cb(struct device *dev)
 
 	ivpu_dbg(vdev, PM, "Runtime suspend..\n");
 
+	ivpu_mmu_disable(vdev);
+
 	is_idle = ivpu_hw_is_idle(vdev) || vdev->pm->dct_active_percent;
 	if (!is_idle)
 		ivpu_err(vdev, "NPU is not idle before autosuspend\n");
Signature · 1 line
2.45.1
#12 lore raw

PATCH 12/15 accel/ivpu: Synchronize device unbind with recovery work

In reply to Jacek Lawrynowicz

From: "Wachowski, Karol" <[email protected]>

Do not allow unbinding device in the middle of recovery flow.

---
 drivers/accel/ivpu/ivpu_drv.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/accel/ivpu/ivpu_drv.c +2 -2
index c59c6f113098..c91400ecf926 100644
@@ -695,14 +695,14 @@ static void ivpu_bo_unbind_all_user_contexts(struct ivpu_device *vdev)
 
 static void ivpu_dev_fini(struct ivpu_device *vdev)
 {
+	ivpu_jobs_abort_all(vdev);
+	ivpu_pm_cancel_recovery(vdev);
 	ivpu_pm_disable(vdev);
 	ivpu_prepare_for_reset(vdev);
 	ivpu_shutdown(vdev);
 
 	ivpu_ms_cleanup_all(vdev);
-	ivpu_jobs_abort_all(vdev);
 	ivpu_job_done_consumer_fini(vdev);
-	ivpu_pm_cancel_recovery(vdev);
 	ivpu_bo_unbind_all_user_contexts(vdev);
 
 	ivpu_ipc_fini(vdev);
Signature · 1 line
2.45.1
#13 lore raw

PATCH 13/15 accel/ivpu: Increase autosuspend delay to 100ms on 40xx

In reply to Jacek Lawrynowicz

From: Andrzej Kacprowski <[email protected]>

The new HW is more power efficient and there is no need to enter the D0i3/D3 so quickly. Increasing autosuspend delay reduces latency in certain usage scenarios.

---
 drivers/accel/ivpu/ivpu_hw.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/accel/ivpu/ivpu_hw.c +4 -1
index a4a13ac67047..27f0fe4d54e0 100644
@@ -99,7 +99,10 @@ static void timeouts_init(struct ivpu_device *vdev)
 		vdev->timeout.boot = 1000;
 		vdev->timeout.jsm = 500;
 		vdev->timeout.tdr = 2000;
-		vdev->timeout.autosuspend = 10;
+		if (ivpu_hw_ip_gen(vdev) == IVPU_HW_IP_37XX)
+			vdev->timeout.autosuspend = 10;
+		else
+			vdev->timeout.autosuspend = 100;
 		vdev->timeout.d0i3_entry_msg = 5;
 	}
 }
Signature · 1 line
2.45.1
#14 lore raw

PATCH 14/15 accel/ivpu: Remove duplicated debug messages

In reply to Jacek Lawrynowicz

Remove duplicated debug messages from ivpu_jsm_(un)register_db(). Debug messages are already printed one level higher.

---
 drivers/accel/ivpu/ivpu_jsm_msg.c | 20 ++++++--------------
 1 file changed, 6 insertions(+), 14 deletions(-)
drivers/accel/ivpu/ivpu_jsm_msg.c +6 -14
index 216aa61ba209..46ef16c3c069 100644
@@ -103,14 +103,10 @@ int ivpu_jsm_register_db(struct ivpu_device *vdev, u32 ctx_id, u32 db_id,
 
 	ret = ivpu_ipc_send_receive(vdev, &req, VPU_JSM_MSG_REGISTER_DB_DONE, &resp,
 				    VPU_IPC_CHAN_ASYNC_CMD, vdev->timeout.jsm);
-	if (ret) {
-		ivpu_err_ratelimited(vdev, "Failed to register doorbell %d: %d\n", db_id, ret);
-		return ret;
-	}
-
-	ivpu_dbg(vdev, JSM, "Doorbell %d registered to context %d\n", db_id, ctx_id);
+	if (ret)
+		ivpu_err_ratelimited(vdev, "Failed to register doorbell %u: %d\n", db_id, ret);
 
-	return 0;
+	return ret;
 }
 
 int ivpu_jsm_unregister_db(struct ivpu_device *vdev, u32 db_id)
@@ -123,14 +119,10 @@ int ivpu_jsm_unregister_db(struct ivpu_device *vdev, u32 db_id)
 
 	ret = ivpu_ipc_send_receive(vdev, &req, VPU_JSM_MSG_UNREGISTER_DB_DONE, &resp,
 				    VPU_IPC_CHAN_ASYNC_CMD, vdev->timeout.jsm);
-	if (ret) {
-		ivpu_warn_ratelimited(vdev, "Failed to unregister doorbell %d: %d\n", db_id, ret);
-		return ret;
-	}
-
-	ivpu_dbg(vdev, JSM, "Doorbell %d unregistered\n", db_id);
+	if (ret)
+		ivpu_warn_ratelimited(vdev, "Failed to unregister doorbell %u: %d\n", db_id, ret);
 
-	return 0;
+	return ret;
 }
 
 int ivpu_jsm_get_heartbeat(struct ivpu_device *vdev, u32 engine, u64 *heartbeat)
Signature · 1 line
2.45.1
#15 lore raw

PATCH 15/15 accel/ivpu: Remove unused ivpu_rpm_get_if_active()

In reply to Jacek Lawrynowicz

This is now dead code and has to be removed.

---
 drivers/accel/ivpu/ivpu_pm.c | 10 ----------
 drivers/accel/ivpu/ivpu_pm.h |  1 -
 2 files changed, 11 deletions(-)
drivers/accel/ivpu/ivpu_pm.c +0 -10
index e7aed16b1a36..59d3170f5e35 100644
@@ -300,16 +300,6 @@ int ivpu_rpm_get(struct ivpu_device *vdev)
 	return ret;
 }
 
-int ivpu_rpm_get_if_active(struct ivpu_device *vdev)
-{
-	int ret;
-
-	ret = pm_runtime_get_if_in_use(vdev->drm.dev);
-	drm_WARN_ON(&vdev->drm, ret < 0);
-
-	return ret;
-}
-
 void ivpu_rpm_put(struct ivpu_device *vdev)
 {
 	pm_runtime_mark_last_busy(vdev->drm.dev);
drivers/accel/ivpu/ivpu_pm.h +0 -1
index c08a3ddf09c1..b70efe6c36e4 100644
@@ -36,7 +36,6 @@ void ivpu_pm_reset_prepare_cb(struct pci_dev *pdev);
 void ivpu_pm_reset_done_cb(struct pci_dev *pdev);
 
 int __must_check ivpu_rpm_get(struct ivpu_device *vdev);
-int __must_check ivpu_rpm_get_if_active(struct ivpu_device *vdev);
 void ivpu_rpm_put(struct ivpu_device *vdev);
 
 void ivpu_pm_trigger_recovery(struct ivpu_device *vdev, const char *reason);
Signature · 1 line
2.45.1
author Applied
#16 lore raw
In reply to Jacek Lawrynowicz

Applied to drm-mic-next

Quoted 51 lines · Jacek Lawrynowicz

Power usage and security fixes along with some cleanup.

Andrzej Kacprowski (1):
accel/ivpu: Increase autosuspend delay to 100ms on 40xx

Jacek Lawrynowicz (6):
accel/ivpu: Remove suspend_reschedule_counter accel/ivpu: Implement DCT handling accel/ivpu: Make selected params read-only accel/ivpu: Disable MMU before checking for idle accel/ivpu: Remove duplicated debug messages accel/ivpu: Remove unused ivpu_rpm_get_if_active()

Maciej Falkowski (2):
accel/ivpu: Abort jobs of faulty context accel/ivpu: Add test mode flag for disabling timeouts

Wachowski, Karol (6):
accel/ivpu: Add wp0_during_power_up WA accel/ivpu: Disable disable_clock_relinquish WA for LNL B0+ accel/ivpu: Disable clock relinquish for MMIO reset accel/ivpu: Update FW BOOT API headers accel/ivpu: Make parts of FW image read-only accel/ivpu: Synchronize device unbind with recovery work

 drivers/accel/ivpu/ivpu_debugfs.c         |  39 +++++++-
 drivers/accel/ivpu/ivpu_drv.c             |  41 ++++++++-
 drivers/accel/ivpu/ivpu_drv.h             |   6 +-
 drivers/accel/ivpu/ivpu_fw.c              |  31 ++++++-
 drivers/accel/ivpu/ivpu_fw.h              |   2 +
 drivers/accel/ivpu/ivpu_hw.c              |  30 ++++--
 drivers/accel/ivpu/ivpu_hw.h              |   4 +-
 drivers/accel/ivpu/ivpu_hw_btrs.c         |  44 +++++++--
 drivers/accel/ivpu/ivpu_hw_btrs.h         |   6 +-
 drivers/accel/ivpu/ivpu_hw_btrs_lnl_reg.h |  10 +-
 drivers/accel/ivpu/ivpu_ipc.c             |   3 +-
 drivers/accel/ivpu/ivpu_ipc.h             |   4 +-
 drivers/accel/ivpu/ivpu_job.c             |  29 +++++-
 drivers/accel/ivpu/ivpu_job.h             |   4 +-
 drivers/accel/ivpu/ivpu_jsm_msg.c         |  52 +++++++----
 drivers/accel/ivpu/ivpu_jsm_msg.h         |   2 +
 drivers/accel/ivpu/ivpu_mmu.c             |  10 +-
 drivers/accel/ivpu/ivpu_mmu_context.c     |  86 ++++++++++++++++++
 drivers/accel/ivpu/ivpu_mmu_context.h     |   2 +
 drivers/accel/ivpu/ivpu_pm.c              | 106 ++++++++++++++++------
 drivers/accel/ivpu/ivpu_pm.h              |  10 +-
 drivers/accel/ivpu/vpu_boot_api.h         |  16 +++-
 22 files changed, 447 insertions(+), 90 deletions(-)

--
2.45.1