From patchwork Wed Apr 17 08:41:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aravind Iddamsetty X-Patchwork-Id: 13632997 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 3843CC04FF9 for ; Wed, 17 Apr 2024 08:39:16 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4DE7D1132D9; Wed, 17 Apr 2024 08:39:15 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="CxMa/Ju+"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) by gabe.freedesktop.org (Postfix) with ESMTPS id A99FA1132D5; Wed, 17 Apr 2024 08:39:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1713343154; x=1744879154; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=oKDh0tCdZ35+8S2F0CA1q+1VXVUT7hkULDasdL+Utcs=; b=CxMa/Ju++L47ByUGvk77kEzneh+sT6TmHNdkKoGy/nxl2mpfNuUndhGa VAm8zoSie2C+ouBRgKkwTBVJua4aZTy6mxEcqvBlbvZWRk96jWSB7Vg90 hTN5Nr5dH1aaq3HgTaYFtFiqBn5Ka4hLh+1jTN+2vzbwEmJI8+QOp2GLe 5JF5d9HIrfv4rYDuxj9b2LYUakjIq0T0GYEL82cen4ekNPEuhBklE4DnX HEf4BE6Ln5brfvGjGDLK2VRGodBfw+6fkaDlZ72+6F5AeXMmqqK4TjMia pDomp1XpoVAB+AJKfJkp+D3F2eNdPAjVzeaEGABrzjcZKsR+S6KCUOsAn Q==; X-CSE-ConnectionGUID: sruyvyB8Q6C4F0si2kt2xA== X-CSE-MsgGUID: nj05DOwMRoqrJqWpD5z3ew== X-IronPort-AV: E=McAfee;i="6600,9927,11046"; a="12660875" X-IronPort-AV: E=Sophos;i="6.07,208,1708416000"; d="scan'208";a="12660875" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Apr 2024 01:39:14 -0700 X-CSE-ConnectionGUID: rDdMfg4JT+GfP4h7JTIS5w== X-CSE-MsgGUID: w0KMXLC/Tfin1DsgcgLluw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,208,1708416000"; d="scan'208";a="27338911" Received: from aravind-dev.iind.intel.com ([10.145.162.146]) by orviesa005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Apr 2024 01:39:06 -0700 From: Aravind Iddamsetty To: dri-devel@lists.freedesktop.org, daniel@ffwll.ch, maarten.lankhorst@linux.intel.com, airlied@gmail.com, mripard@kernel.org, tzimmermann@suse.de, rodrigo.vivi@intel.com Cc: intel-xe@lists.freedesktop.org, Thomas Hellstr_m Subject: [PATCH v2 1/4] drm: add devm release action Date: Wed, 17 Apr 2024 14:11:42 +0530 Message-Id: <20240417084145.242480-2-aravind.iddamsetty@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240417084145.242480-1-aravind.iddamsetty@linux.intel.com> References: <20240417084145.242480-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 Reviewed-by: 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 Wed Apr 17 08:41:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aravind Iddamsetty X-Patchwork-Id: 13632998 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 EDBE8C001CC for ; Wed, 17 Apr 2024 08:39:17 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EA0731132DA; Wed, 17 Apr 2024 08:39:15 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="Kpg2yR/G"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) by gabe.freedesktop.org (Postfix) with ESMTPS id D61DB1132D5; Wed, 17 Apr 2024 08:39:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1713343155; x=1744879155; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=39dw7BvvF4T9V70CGn7OdESoOYqeQyrixXBeWmfHoqs=; b=Kpg2yR/GPzby9V39jNdqESQ0T5VVpM39YnDlKj3t3gRRzr1CemSgfyzs oIoJihPKeFa0bcFGWrbjVvhbJMFh9FJ6RhmJuuc+2ZiHvFh/shkDIgANO bjPxxTWaaukTf7HULuWNc27UC6BXGQ3LSMPi42tExVcH1gusDDgNUJMEt vtl53EQ7Po6GqEesRbPyXvnX7d7VXEqnckbbgqAbMXfzEc4n6COIyGHcO fR1xFbp0XDknnOsCn/nQVE7RMQ1zEekzRfFdt3vFI19jSRDQAO04iiV+T /zhm5b2jXClyUAFLizEH4t/36SDO+/rb4RO8fKoQFaOKZO/LIERYhS8Z5 w==; X-CSE-ConnectionGUID: 6BAOZdIlRlGh8Iq7OaIvaQ== X-CSE-MsgGUID: t9QPgEZqQ4CDvzJ+xTLOAg== X-IronPort-AV: E=McAfee;i="6600,9927,11046"; a="12660885" X-IronPort-AV: E=Sophos;i="6.07,208,1708416000"; d="scan'208";a="12660885" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Apr 2024 01:39:15 -0700 X-CSE-ConnectionGUID: aAx3ONpkS8O9wL6Pm2Hjog== X-CSE-MsgGUID: JVSikCuqQnansC9PwEno3Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,208,1708416000"; d="scan'208";a="27338921" Received: from aravind-dev.iind.intel.com ([10.145.162.146]) by orviesa005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Apr 2024 01:39:12 -0700 From: Aravind Iddamsetty To: dri-devel@lists.freedesktop.org, daniel@ffwll.ch, maarten.lankhorst@linux.intel.com, airlied@gmail.com, mripard@kernel.org, tzimmermann@suse.de, rodrigo.vivi@intel.com Cc: intel-xe@lists.freedesktop.org, Lucas De Marchi Subject: [PATCH 2/4] drm/xe: Save and restore PCI state Date: Wed, 17 Apr 2024 14:11:43 +0530 Message-Id: <20240417084145.242480-3-aravind.iddamsetty@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240417084145.242480-1-aravind.iddamsetty@linux.intel.com> References: <20240417084145.242480-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 Reviewed-by: Rodrigo Vivi 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 8244b177a6a3..0a66555229e9 100644 --- a/drivers/gpu/drm/xe/xe_device_types.h +++ b/drivers/gpu/drm/xe/xe_device_types.h @@ -462,6 +462,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 fa2cc80a08a3..f9957cd16356 100644 --- a/drivers/gpu/drm/xe/xe_pci.c +++ b/drivers/gpu/drm/xe/xe_pci.c @@ -391,6 +391,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) { @@ -696,6 +731,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); } @@ -792,6 +829,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; } @@ -839,7 +879,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; @@ -863,6 +903,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; @@ -880,7 +922,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); @@ -905,7 +947,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 Wed Apr 17 08:41:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aravind Iddamsetty X-Patchwork-Id: 13632999 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 C4D7EC4345F for ; Wed, 17 Apr 2024 08:39:20 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D17141132F3; Wed, 17 Apr 2024 08:39:19 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="Tur/92lM"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) by gabe.freedesktop.org (Postfix) with ESMTPS id 20EAF1132DF; Wed, 17 Apr 2024 08:39:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1713343158; x=1744879158; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=jxwKrYdQbJjUb2NDmoKICIy8nBQdnqLRAYUq2VHXE5M=; b=Tur/92lMt8tNIS0OEWoVcsqQp3GsXqU0HJi6+Gbf1ndiMWJ4bCDUE7X+ I0cucrQVlzUxQC5lct3ws56PDowHyMA06jrJsWmC7J1nmaZyCuxNk+5XY yNV2B6WD/iqEMYJy/+dJAEZTD/fFM7tPLPY5Q41RKzHNfefsLSjronlP/ Ev5ix4kdAQGxSkghn5QfSSIFLp5FXsuajASkPCtUQzliGOXvqRbaT+Yv0 uF9C1YfYxNVLn6Uw3164BWr1zWQ9BEyOH8PkaWUsMfT2Wmcp2MUc1YcMo iwQXIOgzV2STXGtd+md3fBouKngEvTvQKDWu2xZxmyWWDJql9LP2p40GR A==; X-CSE-ConnectionGUID: DxCM6qFvT++upjbk4RTIDQ== X-CSE-MsgGUID: J0NUmrEoS/W4tHFZsg3Zfw== X-IronPort-AV: E=McAfee;i="6600,9927,11046"; a="12660894" X-IronPort-AV: E=Sophos;i="6.07,208,1708416000"; d="scan'208";a="12660894" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Apr 2024 01:39:18 -0700 X-CSE-ConnectionGUID: JRDA/b7mS9CueNkSVciaVA== X-CSE-MsgGUID: WHYUyLKYTou1Lgnz6FSM1w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,208,1708416000"; d="scan'208";a="27338931" Received: from aravind-dev.iind.intel.com ([10.145.162.146]) by orviesa005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Apr 2024 01:39:15 -0700 From: Aravind Iddamsetty To: dri-devel@lists.freedesktop.org, daniel@ffwll.ch, maarten.lankhorst@linux.intel.com, airlied@gmail.com, mripard@kernel.org, tzimmermann@suse.de, rodrigo.vivi@intel.com Cc: intel-xe@lists.freedesktop.org, Lucas De Marchi Subject: [PATCH 3/4] drm/xe: Extract xe_gt_idle() helper Date: Wed, 17 Apr 2024 14:11:44 +0530 Message-Id: <20240417084145.242480-4-aravind.iddamsetty@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240417084145.242480-1-aravind.iddamsetty@linux.intel.com> References: <20240417084145.242480-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 Reviewed-by: Rodrigo Vivi 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 Wed Apr 17 08:41:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Aravind Iddamsetty X-Patchwork-Id: 13633000 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 99EE7C4345F for ; Wed, 17 Apr 2024 08:39:25 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EAB421132DF; Wed, 17 Apr 2024 08:39:24 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="NpgbPfCm"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) by gabe.freedesktop.org (Postfix) with ESMTPS id A32021132DC; Wed, 17 Apr 2024 08:39: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=1713343164; x=1744879164; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=cWFZknpjXl6vb4XTKwA+o7P+tYEc0ClqDQapFyduSqI=; b=NpgbPfCmtk0BfTPKF7NimTxMIZGpNIkG3TOXRp4mF2NqQLwD9DukB1k2 UrqfNRYZ/uih3REri0plIO8FNgogy67che8n7keFjLy6OAmqhA5Qyzrxf RW4ks8WKAGpNDH1t+535r83oMdCC8I5wqkVDu15KEBtsnf5zr5mfqcO4c aHeJROItDapNslZ8qOXhfVfstOjdEoCSbOw5J5ef5Qvhir5oCK7hF6cPl Qz8beD828yHBgTzn/vNprgs+dkfcwpYeMw5XGF4EMAhohJVFnanpRGp8y 7LjlHHzOdSROdaatKXNXIs4TRK2Ej/DzPffTOKc1pPLdCVX4bOfvlyLbo g==; X-CSE-ConnectionGUID: +UNmAhEBS5Wbdy6RbUnkAA== X-CSE-MsgGUID: eiVN8JNmRr2tfxEYDsEn0w== X-IronPort-AV: E=McAfee;i="6600,9927,11046"; a="12660901" X-IronPort-AV: E=Sophos;i="6.07,208,1708416000"; d="scan'208";a="12660901" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Apr 2024 01:39:23 -0700 X-CSE-ConnectionGUID: +OVjRz6JQBGxkVfgE611jg== X-CSE-MsgGUID: hnIaNvQ2RCyuuYAeMNeUvA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,208,1708416000"; d="scan'208";a="27338940" Received: from aravind-dev.iind.intel.com ([10.145.162.146]) by orviesa005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Apr 2024 01:39:19 -0700 From: Aravind Iddamsetty To: dri-devel@lists.freedesktop.org, daniel@ffwll.ch, maarten.lankhorst@linux.intel.com, airlied@gmail.com, mripard@kernel.org, tzimmermann@suse.de, rodrigo.vivi@intel.com Cc: intel-xe@lists.freedesktop.org, Lucas De Marchi Subject: [PATCH v2 4/4] drm/xe/FLR: Support PCIe FLR Date: Wed, 17 Apr 2024 14:11:45 +0530 Message-Id: <20240417084145.242480-5-aravind.iddamsetty@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240417084145.242480-1-aravind.iddamsetty@linux.intel.com> References: <20240417084145.242480-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 Reviewed-by: Rodrigo Vivi 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 522bffa5c4e1..9686ea181ad1 100644 --- a/drivers/gpu/drm/xe/Makefile +++ b/drivers/gpu/drm/xe/Makefile @@ -117,6 +117,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 0a66555229e9..8c749b378a92 100644 --- a/drivers/gpu/drm/xe/xe_device_types.h +++ b/drivers/gpu/drm/xe/xe_device_types.h @@ -465,6 +465,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 521ae24f2314..6108a4dfa05f 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 f9957cd16356..d986ae7fc7f7 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" @@ -736,7 +737,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; @@ -976,6 +977,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, @@ -985,6 +991,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