From patchwork Tue Apr 2 08:58:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aravind Iddamsetty X-Patchwork-Id: 13613558 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C554CCD1284 for ; Tue, 2 Apr 2024 08:56:22 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7D37410FB83; Tue, 2 Apr 2024 08:56:18 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="nrIhD6bZ"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4BBEF10FB80; Tue, 2 Apr 2024 08:56:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1712048177; x=1743584177; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2bh30oUIr485Sm03RHNCLxv+i4jIoW6CLcOZ3ZttdEw=; b=nrIhD6bZlce0139pCoe+J8Dg7UmK/mdYupxfUFPyWTfcxGkkUJznKV6J lWKiMdQvFDKxoreUTsnyH3mliV6ZtBDQqzH2+OfyjKt1w+e7A9VuhokN5 x9NbpIfZBYIS5x7yHSnOt8RylvLF2nsikOL/BrLdQMnFI68aIdwy8m62O qei2c7kXQVE9TPom/gJYMqCNcpADGLSPD3cSsC3bPsJLPjQmGVEnfy8F2 oJnvq3tATCVo6C7xMUE9Ah43VLG1uF4PMSk7CumwbNckFwgt1qK+/WqWK IurFLOPrVx+mqXKWxge5x+kYj7v/FDfiwuYLBL8cxciVnh/EPyOqzS07R w==; X-CSE-ConnectionGUID: +A61MZsIRpWVck/VG4DqtQ== X-CSE-MsgGUID: dlB+CVfORFGK8/oZuPylkg== X-IronPort-AV: E=McAfee;i="6600,9927,11031"; a="18654773" X-IronPort-AV: E=Sophos;i="6.07,174,1708416000"; d="scan'208";a="18654773" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Apr 2024 01:56:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,174,1708416000"; d="scan'208";a="49225971" Received: from aravind-dev.iind.intel.com ([10.145.162.146]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Apr 2024 01:56:15 -0700 From: Aravind Iddamsetty To: intel-xe@lists.freedesktop.org, thomas.hellstrom@linux.intel.com, rodrigo.vivi@intel.com, lucas.demarchi@intel.com Cc: dri-devel@lists.freedesktop.org Subject: [PATCH v2 1/4] drm: add devm release action Date: Tue, 2 Apr 2024 14:28:56 +0530 Message-Id: <20240402085859.1591264-2-aravind.iddamsetty@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240402085859.1591264-1-aravind.iddamsetty@linux.intel.com> References: <20240402085859.1591264-1-aravind.iddamsetty@linux.intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" In scenarios where drm_dev_put is directly called by driver we want to release devm_drm_dev_init_release action associated with struct drm_device. v2: Directly expose the original function, instead of introducing a helper (Rodrigo) Cc: Thomas Hellstr_m Cc: Rodrigo Vivi Signed-off-by: Aravind Iddamsetty --- drivers/gpu/drm/drm_drv.c | 6 ++++++ include/drm/drm_drv.h | 2 ++ 2 files changed, 8 insertions(+) diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c index 243cacb3575c..ba60cbb0725f 100644 --- a/drivers/gpu/drm/drm_drv.c +++ b/drivers/gpu/drm/drm_drv.c @@ -714,6 +714,12 @@ static int devm_drm_dev_init(struct device *parent, devm_drm_dev_init_release, dev); } +void devm_drm_dev_release_action(struct drm_device *dev) +{ + devm_release_action(dev->dev, devm_drm_dev_init_release, dev); +} +EXPORT_SYMBOL(devm_drm_dev_release_action); + void *__devm_drm_dev_alloc(struct device *parent, const struct drm_driver *driver, size_t size, size_t offset) diff --git a/include/drm/drm_drv.h b/include/drm/drm_drv.h index 8878260d7529..fa9123684874 100644 --- a/include/drm/drm_drv.h +++ b/include/drm/drm_drv.h @@ -444,6 +444,8 @@ struct drm_driver { const struct file_operations *fops; }; +void devm_drm_dev_release_action(struct drm_device *dev); + void *__devm_drm_dev_alloc(struct device *parent, const struct drm_driver *driver, size_t size, size_t offset); From patchwork Tue Apr 2 08:58:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aravind Iddamsetty X-Patchwork-Id: 13613559 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C3F07C6FD1F for ; Tue, 2 Apr 2024 08:56:25 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C8C4510FB88; Tue, 2 Apr 2024 08:56:20 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="TWzDV+j6"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5D07D10FB85; Tue, 2 Apr 2024 08:56:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1712048179; x=1743584179; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=TbngyseStKWjV3NchFChycJLcCbW4YQ5eyax2z1Pvwc=; b=TWzDV+j6MPo6pgNfYLjqg+201XuKbeW/MXIkrbPyL2uUX1JmYO+jOZUw rfgU59BPSdg1ja5DmZ0S5hM7vPtUCsuOa3W1vsgRi4NnqO42GuxVGevic MEqM/R74IGimoY4fI14tfnQ1KhPU5D38SxdRDudRXfObXqfQtHQ9lOBcX XapmagxnuqceYTolC0sDlmO1SmJY2XqldV5HWkcvwx4spM4F7iJSKOZOp hLhBObgGSPtslR6p6fvEVdVZcRhu4J2VNizGnh9qmX9IrcpusvUWpXhOo XFkduloztS1LfC96h72ny8RvWpi/W/N23timBhSasgUvCy30YkTQMxzhV Q==; X-CSE-ConnectionGUID: JmNPTbwvRQSrrGxTH5K95Q== X-CSE-MsgGUID: skqgL1UoRXGT4NHL6srkVQ== X-IronPort-AV: E=McAfee;i="6600,9927,11031"; a="18654777" X-IronPort-AV: E=Sophos;i="6.07,174,1708416000"; d="scan'208";a="18654777" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Apr 2024 01:56:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,174,1708416000"; d="scan'208";a="49225978" Received: from aravind-dev.iind.intel.com ([10.145.162.146]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Apr 2024 01:56:17 -0700 From: Aravind Iddamsetty To: intel-xe@lists.freedesktop.org, thomas.hellstrom@linux.intel.com, rodrigo.vivi@intel.com, lucas.demarchi@intel.com Cc: dri-devel@lists.freedesktop.org Subject: [PATCH 2/4] drm/xe: Save and restore PCI state Date: Tue, 2 Apr 2024 14:28:57 +0530 Message-Id: <20240402085859.1591264-3-aravind.iddamsetty@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240402085859.1591264-1-aravind.iddamsetty@linux.intel.com> References: <20240402085859.1591264-1-aravind.iddamsetty@linux.intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Save and restore PCI states where ever needed. Cc: Lucas De Marchi Signed-off-by: Aravind Iddamsetty --- drivers/gpu/drm/xe/xe_device_types.h | 3 ++ drivers/gpu/drm/xe/xe_pci.c | 48 ++++++++++++++++++++++++++-- drivers/gpu/drm/xe/xe_pci.h | 4 ++- 3 files changed, 51 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/xe/xe_device_types.h b/drivers/gpu/drm/xe/xe_device_types.h index 1df3dcc17d75..3bfde4b59284 100644 --- a/drivers/gpu/drm/xe/xe_device_types.h +++ b/drivers/gpu/drm/xe/xe_device_types.h @@ -455,6 +455,9 @@ struct xe_device { /** @needs_flr_on_fini: requests function-reset on fini */ bool needs_flr_on_fini; + /** @pci_state: PCI state of device */ + struct pci_saved_state *pci_state; + /* private: */ #if IS_ENABLED(CONFIG_DRM_XE_DISPLAY) diff --git a/drivers/gpu/drm/xe/xe_pci.c b/drivers/gpu/drm/xe/xe_pci.c index c401d4890386..e9e10f8d5f2b 100644 --- a/drivers/gpu/drm/xe/xe_pci.c +++ b/drivers/gpu/drm/xe/xe_pci.c @@ -383,6 +383,41 @@ MODULE_DEVICE_TABLE(pci, pciidlist); #undef INTEL_VGA_DEVICE +static bool xe_save_pci_state(struct pci_dev *pdev) +{ + struct xe_device *xe = pci_get_drvdata(pdev); + + if (pci_save_state(pdev)) + return false; + + kfree(xe->pci_state); + + xe->pci_state = pci_store_saved_state(pdev); + if (!xe->pci_state) { + drm_err(&xe->drm, "Failed to store PCI saved state\n"); + return false; + } + + return true; +} + +void xe_load_pci_state(struct pci_dev *pdev) +{ + struct xe_device *xe = pci_get_drvdata(pdev); + int ret; + + if (!xe->pci_state) + return; + + ret = pci_load_saved_state(pdev, xe->pci_state); + if (ret) { + drm_warn(&xe->drm, "Failed to load PCI state err:%d\n", ret); + return; + } + + pci_restore_state(pdev); +} + /* is device_id present in comma separated list of ids */ static bool device_id_in_list(u16 device_id, const char *devices, bool negative) { @@ -688,6 +723,8 @@ static void xe_pci_remove(struct pci_dev *pdev) xe_device_remove(xe); xe_pm_runtime_fini(xe); + + kfree(xe->pci_state); pci_set_drvdata(pdev, NULL); } @@ -786,6 +823,9 @@ static int xe_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) drm_dbg(&xe->drm, "d3cold: capable=%s\n", str_yes_no(xe->d3cold.capable)); + if (xe_save_pci_state(pdev)) + pci_restore_state(pdev); + return 0; } @@ -833,7 +873,7 @@ static int xe_pci_suspend(struct device *dev) */ d3cold_toggle(pdev, D3COLD_ENABLE); - pci_save_state(pdev); + xe_save_pci_state(pdev); pci_disable_device(pdev); return 0; @@ -857,6 +897,8 @@ static int xe_pci_resume(struct device *dev) pci_set_master(pdev); + xe_load_pci_state(pdev); + err = xe_pm_resume(pdev_to_xe_device(pdev)); if (err) return err; @@ -874,7 +916,7 @@ static int xe_pci_runtime_suspend(struct device *dev) if (err) return err; - pci_save_state(pdev); + xe_save_pci_state(pdev); if (xe->d3cold.allowed) { d3cold_toggle(pdev, D3COLD_ENABLE); @@ -899,7 +941,7 @@ static int xe_pci_runtime_resume(struct device *dev) if (err) return err; - pci_restore_state(pdev); + xe_load_pci_state(pdev); if (xe->d3cold.allowed) { err = pci_enable_device(pdev); diff --git a/drivers/gpu/drm/xe/xe_pci.h b/drivers/gpu/drm/xe/xe_pci.h index 611c1209b14c..73b90a430d1f 100644 --- a/drivers/gpu/drm/xe/xe_pci.h +++ b/drivers/gpu/drm/xe/xe_pci.h @@ -6,7 +6,9 @@ #ifndef _XE_PCI_H_ #define _XE_PCI_H_ +struct pci_dev; + int xe_register_pci_driver(void); void xe_unregister_pci_driver(void); - +void xe_load_pci_state(struct pci_dev *pdev); #endif From patchwork Tue Apr 2 08:58:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aravind Iddamsetty X-Patchwork-Id: 13613560 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0EB73CD1292 for ; Tue, 2 Apr 2024 08:56:28 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1EEB310FB8B; Tue, 2 Apr 2024 08:56:23 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="XOb1ESCx"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) by gabe.freedesktop.org (Postfix) with ESMTPS id 880DD10FB8B; Tue, 2 Apr 2024 08:56:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1712048181; x=1743584181; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=H8rPcytHIRQCdyY60iIcJf4DnLnACvWdnFvZwhhxbQw=; b=XOb1ESCxmteZrS8/DTVQi13/9OfrtRdcyk4xaASAYzz2KKVr6D8Rop+S yHnf8idezSiX5ZdCLAI6HkykTeuEnPBcKeVrgx3acJWbnQpxz0PonUZvp 1zHb6K8mbNUBKuaeKFofFJT/5S+8o0EYMBbXL6MMrp3BdaNQHIAg4gM7u cxb4xlqJqkbHVtRrzoYNGF1JT0BFx03z3YbkGIMfBRAY73Vv9N7XPqWBT abCJaDwF0g2fA3H35JsrGvqm3mmEwav1bcOInd9t3/UvAG5mY8CM2cjfD iWfv3LKgnfVFP/2KgFhaWbs7XApgG9JPLjMXNQ4zTH2FWw2nS1o1zy+65 Q==; X-CSE-ConnectionGUID: 8AWXN1ysQ3a/VX0W9nDHpw== X-CSE-MsgGUID: lkgc8Ck2RXCr75po6Iscng== X-IronPort-AV: E=McAfee;i="6600,9927,11031"; a="18654782" X-IronPort-AV: E=Sophos;i="6.07,174,1708416000"; d="scan'208";a="18654782" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Apr 2024 01:56:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,174,1708416000"; d="scan'208";a="49225986" Received: from aravind-dev.iind.intel.com ([10.145.162.146]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Apr 2024 01:56:19 -0700 From: Aravind Iddamsetty To: intel-xe@lists.freedesktop.org, thomas.hellstrom@linux.intel.com, rodrigo.vivi@intel.com, lucas.demarchi@intel.com Cc: dri-devel@lists.freedesktop.org Subject: [PATCH 3/4] drm/xe: Extract xe_gt_idle() helper Date: Tue, 2 Apr 2024 14:28:58 +0530 Message-Id: <20240402085859.1591264-4-aravind.iddamsetty@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240402085859.1591264-1-aravind.iddamsetty@linux.intel.com> References: <20240402085859.1591264-1-aravind.iddamsetty@linux.intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" This would be used in other places outside of gt_reset path. Cc: Lucas De Marchi Signed-off-by: Aravind Iddamsetty --- drivers/gpu/drm/xe/xe_gt.c | 31 +++++++++++++++++++++---------- drivers/gpu/drm/xe/xe_gt.h | 1 + 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/xe/xe_gt.c b/drivers/gpu/drm/xe/xe_gt.c index cfa5da900461..59f497d575ad 100644 --- a/drivers/gpu/drm/xe/xe_gt.c +++ b/drivers/gpu/drm/xe/xe_gt.c @@ -629,6 +629,26 @@ static int do_gt_restart(struct xe_gt *gt) return 0; } +/* Idle the GT */ +int xe_gt_idle(struct xe_gt *gt) +{ + int err; + + xe_gt_sanitize(gt); + + xe_uc_gucrc_disable(>->uc); + xe_uc_stop_prepare(>->uc); + xe_gt_pagefault_reset(gt); + + err = xe_uc_stop(>->uc); + if (err) + return err; + + xe_gt_tlb_invalidation_reset(gt); + + return err; +} + static int gt_reset(struct xe_gt *gt) { int err; @@ -645,21 +665,12 @@ static int gt_reset(struct xe_gt *gt) } xe_pm_runtime_get(gt_to_xe(gt)); - xe_gt_sanitize(gt); err = xe_force_wake_get(gt_to_fw(gt), XE_FORCEWAKE_ALL); if (err) goto err_msg; - xe_uc_gucrc_disable(>->uc); - xe_uc_stop_prepare(>->uc); - xe_gt_pagefault_reset(gt); - - err = xe_uc_stop(>->uc); - if (err) - goto err_out; - - xe_gt_tlb_invalidation_reset(gt); + xe_gt_idle(gt); err = do_gt_reset(gt); if (err) diff --git a/drivers/gpu/drm/xe/xe_gt.h b/drivers/gpu/drm/xe/xe_gt.h index ed6ea8057e35..d62af1725ff6 100644 --- a/drivers/gpu/drm/xe/xe_gt.h +++ b/drivers/gpu/drm/xe/xe_gt.h @@ -43,6 +43,7 @@ int xe_gt_resume(struct xe_gt *gt); void xe_gt_reset_async(struct xe_gt *gt); void xe_gt_sanitize(struct xe_gt *gt); void xe_gt_remove(struct xe_gt *gt); +int xe_gt_idle(struct xe_gt *gt); /** * xe_gt_any_hw_engine_by_reset_domain - scan the list of engines and return the From patchwork Tue Apr 2 08:58:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Aravind Iddamsetty X-Patchwork-Id: 13613561 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B3B83CD1284 for ; Tue, 2 Apr 2024 08:56:29 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 76CE810FB8E; Tue, 2 Apr 2024 08:56:25 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="SBnwY0Zl"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) by gabe.freedesktop.org (Postfix) with ESMTPS id AE0E510FB8D; Tue, 2 Apr 2024 08:56:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1712048184; x=1743584184; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=A2Ukw8bpcxbC50Nnad7FlhUuyAboO9/3pUwaY99IGUk=; b=SBnwY0ZlrV9OPjIoMz/OJkxIfHRu7dJJk3MjjPPd9z+coIwzvYDw6xa/ ZWK4mgj+IGIJmmeB2AHj600nbz/HUn8ckxtvfDfCSICw5ayhUmgonOH3Z 2+nS1jbDHFwOMhT6X6ar6H8XsSkhZflWrJHUSmHJzwd/+SXGAvMw0NZT/ HCHYv+isZbxWqbJOjvdILpujDSfH+v/lJaG49BYNIP38Si1kQlHP/gSv4 5OepxErrgUuyXTESwkB6BY8fJDNwsBcZcSkqxJxlWXnX4MwpvYHIoHj8z rT4vHs+hYyloBH82l9qJ2tZNNE5oXHvwqCJzatA5YNg06rfmcuDLMFGK/ A==; X-CSE-ConnectionGUID: XMpVkHnrTiOlSM+DUDbbhQ== X-CSE-MsgGUID: Nf/Tzi8uQkiqr3yke1dK1Q== X-IronPort-AV: E=McAfee;i="6600,9927,11031"; a="18654788" X-IronPort-AV: E=Sophos;i="6.07,174,1708416000"; d="scan'208";a="18654788" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Apr 2024 01:56:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,174,1708416000"; d="scan'208";a="49225998" Received: from aravind-dev.iind.intel.com ([10.145.162.146]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Apr 2024 01:56:21 -0700 From: Aravind Iddamsetty To: intel-xe@lists.freedesktop.org, thomas.hellstrom@linux.intel.com, rodrigo.vivi@intel.com, lucas.demarchi@intel.com Cc: dri-devel@lists.freedesktop.org Subject: [PATCH v2 4/4] drm/xe/FLR: Support PCIe FLR Date: Tue, 2 Apr 2024 14:28:59 +0530 Message-Id: <20240402085859.1591264-5-aravind.iddamsetty@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240402085859.1591264-1-aravind.iddamsetty@linux.intel.com> References: <20240402085859.1591264-1-aravind.iddamsetty@linux.intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" PCI subsystem provides callbacks to inform the driver about a request to do function level reset by user, initiated by writing to sysfs entry /sys/bus/pci/devices/.../reset. This will allow the driver to handle FLR without the need to do unbind and rebind as the driver needs to reinitialize the device afresh post FLR. v2: 1. separate out gt idle and pci save/restore to a separate patch (Lucas) 2. Fixed the warnings seen around xe_guc_submit_stop, xe_guc_puc_fini Cc: Rodrigo Vivi Cc: Lucas De Marchi Signed-off-by: Aravind Iddamsetty --- drivers/gpu/drm/xe/Makefile | 1 + drivers/gpu/drm/xe/xe_device_types.h | 3 + drivers/gpu/drm/xe/xe_guc_pc.c | 4 ++ drivers/gpu/drm/xe/xe_pci.c | 9 ++- drivers/gpu/drm/xe/xe_pci.h | 2 + drivers/gpu/drm/xe/xe_pci_err.c | 93 ++++++++++++++++++++++++++++ drivers/gpu/drm/xe/xe_pci_err.h | 13 ++++ 7 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/xe/xe_pci_err.c create mode 100644 drivers/gpu/drm/xe/xe_pci_err.h diff --git a/drivers/gpu/drm/xe/Makefile b/drivers/gpu/drm/xe/Makefile index 3c3e67885559..1447712fec65 100644 --- a/drivers/gpu/drm/xe/Makefile +++ b/drivers/gpu/drm/xe/Makefile @@ -114,6 +114,7 @@ xe-y += xe_bb.o \ xe_module.o \ xe_pat.o \ xe_pci.o \ + xe_pci_err.o \ xe_pcode.o \ xe_pm.o \ xe_preempt_fence.o \ diff --git a/drivers/gpu/drm/xe/xe_device_types.h b/drivers/gpu/drm/xe/xe_device_types.h index 3bfde4b59284..a58d7e14f7a0 100644 --- a/drivers/gpu/drm/xe/xe_device_types.h +++ b/drivers/gpu/drm/xe/xe_device_types.h @@ -458,6 +458,9 @@ struct xe_device { /** @pci_state: PCI state of device */ struct pci_saved_state *pci_state; + /** @pci_device_is_reset: device went through PCIe FLR */ + bool pci_device_is_reset; + /* private: */ #if IS_ENABLED(CONFIG_DRM_XE_DISPLAY) diff --git a/drivers/gpu/drm/xe/xe_guc_pc.c b/drivers/gpu/drm/xe/xe_guc_pc.c index 9c110537d135..b09cacf25094 100644 --- a/drivers/gpu/drm/xe/xe_guc_pc.c +++ b/drivers/gpu/drm/xe/xe_guc_pc.c @@ -902,6 +902,10 @@ static void xe_guc_pc_fini(struct drm_device *drm, void *arg) return; } + /* We already have done this before going through a reset, so skip here */ + if (xe->pci_device_is_reset) + return; + XE_WARN_ON(xe_force_wake_get(gt_to_fw(pc_to_gt(pc)), XE_FORCEWAKE_ALL)); XE_WARN_ON(xe_guc_pc_gucrc_disable(pc)); XE_WARN_ON(xe_guc_pc_stop(pc)); diff --git a/drivers/gpu/drm/xe/xe_pci.c b/drivers/gpu/drm/xe/xe_pci.c index e9e10f8d5f2b..3b3876318975 100644 --- a/drivers/gpu/drm/xe/xe_pci.c +++ b/drivers/gpu/drm/xe/xe_pci.c @@ -23,6 +23,7 @@ #include "xe_macros.h" #include "xe_mmio.h" #include "xe_module.h" +#include "xe_pci_err.h" #include "xe_pci_types.h" #include "xe_pm.h" #include "xe_sriov.h" @@ -728,7 +729,7 @@ static void xe_pci_remove(struct pci_dev *pdev) pci_set_drvdata(pdev, NULL); } -static int xe_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) +int xe_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) { const struct xe_device_desc *desc = (const void *)ent->driver_data; const struct xe_subplatform_desc *subplatform_desc; @@ -970,6 +971,11 @@ static const struct dev_pm_ops xe_pm_ops = { }; #endif +const struct pci_error_handlers xe_pci_err_handlers = { + .reset_prepare = xe_pci_reset_prepare, + .reset_done = xe_pci_reset_done, +}; + static struct pci_driver xe_pci_driver = { .name = DRIVER_NAME, .id_table = pciidlist, @@ -979,6 +985,7 @@ static struct pci_driver xe_pci_driver = { #ifdef CONFIG_PM_SLEEP .driver.pm = &xe_pm_ops, #endif + .err_handler = &xe_pci_err_handlers, }; int xe_register_pci_driver(void) diff --git a/drivers/gpu/drm/xe/xe_pci.h b/drivers/gpu/drm/xe/xe_pci.h index 73b90a430d1f..9faf5380a09e 100644 --- a/drivers/gpu/drm/xe/xe_pci.h +++ b/drivers/gpu/drm/xe/xe_pci.h @@ -7,8 +7,10 @@ #define _XE_PCI_H_ struct pci_dev; +struct pci_device_id; int xe_register_pci_driver(void); void xe_unregister_pci_driver(void); void xe_load_pci_state(struct pci_dev *pdev); +int xe_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent); #endif diff --git a/drivers/gpu/drm/xe/xe_pci_err.c b/drivers/gpu/drm/xe/xe_pci_err.c new file mode 100644 index 000000000000..81c440e08fbc --- /dev/null +++ b/drivers/gpu/drm/xe/xe_pci_err.c @@ -0,0 +1,93 @@ +// SPDX-License-Identifier: MIT +/* + * Copyright © 2024 Intel Corporation + */ + +#include +#include + +#include "xe_device.h" +#include "xe_gt.h" +#include "xe_gt_printk.h" +#include "xe_pci.h" +#include "xe_pci_err.h" +#include "xe_pm.h" +#include "xe_uc.h" + +/** + * xe_pci_reset_prepare - Called when user issued a PCIe reset + * via /sys/bus/pci/devices/.../reset. + * @pdev: PCI device struct + */ +void xe_pci_reset_prepare(struct pci_dev *pdev) +{ + struct xe_device *xe = pci_get_drvdata(pdev); + struct xe_gt *gt; + int id, err; + + pci_warn(pdev, "preparing for PCIe reset\n"); + + drm_warn(&xe->drm, "removing device access to userspace\n"); + drm_dev_unplug(&xe->drm); + + xe_pm_runtime_get(xe); + /* idle the GTs */ + for_each_gt(gt, xe, id) { + err = xe_force_wake_get(gt_to_fw(gt), XE_FORCEWAKE_ALL); + if (err) + goto reset; + xe_uc_reset_prepare(>->uc); + err = xe_gt_idle(gt); + if (err) { + xe_gt_err(gt, "failed to idle gt (%pe)\n", ERR_PTR(err)); + goto reset; + } + + err = xe_force_wake_put(gt_to_fw(gt), XE_FORCEWAKE_ALL); + XE_WARN_ON(err); + } + xe_pm_runtime_put(xe); + +reset: + pci_disable_device(pdev); +} + +/** + * xe_pci_reset_done - Called when PCIe reset is done. + * @pdev: PCI device struct + */ +void xe_pci_reset_done(struct pci_dev *pdev) +{ + const struct pci_device_id *ent = pci_match_id(pdev->driver->id_table, pdev); + struct xe_device *xe = pci_get_drvdata(pdev); + + dev_info(&pdev->dev, + "device went through PCIe reset, reenabling the device\n"); + + if (pci_enable_device(pdev)) { + dev_err(&pdev->dev, + "Cannot re-enable PCI device after reset\n"); + return; + } + pci_set_master(pdev); + xe_load_pci_state(pdev); + + xe->pci_device_is_reset = true; + /* + * We want to completely clean the driver and even destroy + * the xe private data and reinitialize afresh similar to + * probe + */ + pdev->driver->remove(pdev); + if (pci_dev_msi_enabled(pdev)) + pci_free_irq_vectors(pdev); + + devm_drm_dev_release_action(&xe->drm); + pci_disable_device(pdev); + + /* + * if this fails the driver might be in a stale state, only option is + * to unbind and rebind + */ + xe_pci_probe(pdev, ent); +} diff --git a/drivers/gpu/drm/xe/xe_pci_err.h b/drivers/gpu/drm/xe/xe_pci_err.h new file mode 100644 index 000000000000..95a4c8ce9cf1 --- /dev/null +++ b/drivers/gpu/drm/xe/xe_pci_err.h @@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: MIT */ +/* + * Copyright © 2024 Intel Corporation + */ + +#ifndef _XE_PCI_ERR_H_ +#define _XE_PCI_ERR_H_ + +struct pci_dev; + +void xe_pci_reset_prepare(struct pci_dev *pdev); +void xe_pci_reset_done(struct pci_dev *pdev); +#endif