From patchwork Wed May 12 14:26:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrey Grodzovsky X-Patchwork-Id: 12253875 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7B98FC43462 for ; Wed, 12 May 2021 14:27:25 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id BCB6961411 for ; Wed, 12 May 2021 14:27:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BCB6961411 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=amd.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id F1B996E529; Wed, 12 May 2021 14:27:18 +0000 (UTC) Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam08on2081.outbound.protection.outlook.com [40.107.102.81]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0A1226E079; Wed, 12 May 2021 14:27:17 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Qwf5r8AfWrRbfO0kWP9Z3w8tP55sHFPhLqGDcbohMp+jzONLHzbCS9jBtPViP5BZgtzyKMFh936Qr2TEGpcxhm8/W/wOqk2i/PA6U19R8vERL8JKCNwXA1QiHanTQ2IWeky972pD+i4i8cjzIuoQxhgX6Z7yAozQ3jzjJUeT+Hrbg/WFsKRacWUW4IxhtPZJnzXxeBpkO6XVGR2tY33gxCj0oS9jXyhll/SgV/TolY8/AXXXMnHpcIjCeWC3/U8nUQr7BguWSeK3dO/Ztnkx/5bJLvq/FRHqRwfZzwnIUGj1VW44SJkxVagD9DH1PBZghspawgcrdUAfrypdIAcq8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4f76bDjmlOpO1JyP2h+5eU+QH8A/4mNsiKFTRoZXVXM=; b=L0HTceAVIYPoSOgcP0SamgoUazIyguYMCkCC2mpBgTmejK7ankvtEE035z8fFBy892Cfe1CSMwHZdk7m7Ff1yb1Av0s449et6RFzANLGYEgjrHkO3OhNagyL2wRXRp0EddC+Ho04BgOhpA9h8rx/sPuNFQIr6uasAA9O3H14scpRqu0ritQIG0DRorDWP1q1E+Yat9DhaydHa46u4Yam024VYt4lUkUzPQUDHqxWU+oHY5E3mTD3UHVDlPOuVd+JfW3wByw2cvX+DGvbGkSoUA3B+uPmlsII0edKZ0ZAjwxV2RRKlcZAcW+sewi4D/7gg54SePjXT3/YGa9ct2uQcQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4f76bDjmlOpO1JyP2h+5eU+QH8A/4mNsiKFTRoZXVXM=; b=1hkQt4g3bDxNe3an6O7ZbvX4PCX8YOw7/a/4xupN0RkJ4KXfNxS3duWx1pP3BAm6BVbZa59uPViFrglbn5rTqRdC6djZJ6wTawo6smnUa7+GOciuKDktw4ap63JuTc+VIQodbixvzQUgfPnztPPf1DtJgVz6BvP9ziTJNUZdzP8= Authentication-Results: lists.freedesktop.org; dkim=none (message not signed) header.d=none; lists.freedesktop.org; dmarc=none action=none header.from=amd.com; Received: from SN6PR12MB4623.namprd12.prod.outlook.com (2603:10b6:805:e9::17) by SA0PR12MB4576.namprd12.prod.outlook.com (2603:10b6:806:93::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.27; Wed, 12 May 2021 14:27:15 +0000 Received: from SN6PR12MB4623.namprd12.prod.outlook.com ([fe80::ad51:8c49:b171:856c]) by SN6PR12MB4623.namprd12.prod.outlook.com ([fe80::ad51:8c49:b171:856c%7]) with mapi id 15.20.4129.026; Wed, 12 May 2021 14:27:15 +0000 From: Andrey Grodzovsky To: dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org, linux-pci@vger.kernel.org, ckoenig.leichtzumerken@gmail.com, daniel.vetter@ffwll.ch, Harry.Wentland@amd.com Subject: [PATCH v7 04/16] drm/amdgpu: Add early fini callback Date: Wed, 12 May 2021 10:26:36 -0400 Message-Id: <20210512142648.666476-5-andrey.grodzovsky@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210512142648.666476-1-andrey.grodzovsky@amd.com> References: <20210512142648.666476-1-andrey.grodzovsky@amd.com> X-Originating-IP: [2607:fea8:3edf:49b0:7576:4f76:97d8:1487] X-ClientProxiedBy: YTOPR0101CA0032.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b00:15::45) To SN6PR12MB4623.namprd12.prod.outlook.com (2603:10b6:805:e9::17) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from agrodzovsky-All-Series.hitronhub.home (2607:fea8:3edf:49b0:7576:4f76:97d8:1487) by YTOPR0101CA0032.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b00:15::45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.30 via Frontend Transport; Wed, 12 May 2021 14:27:14 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9392f4b3-d6d9-4062-2df4-08d915520a42 X-MS-TrafficTypeDiagnostic: SA0PR12MB4576: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: UFHUdEwcyTwLchxUswSHmi1j6WFGVrMRTJi4PnqCwCNZLAgRZl+JbFPbLhoeX2crB47CQgIaYHThMZrTjg1kyyv3gNSkC3MydPKkELX4pm1KsVYUNlNyZwUUU0DIPImE8ulpkfOsr7vAtLQ4uVTS9/l7PXXvloFuX15RTVSZD5URfAfPNwzscvttYRcs2E1wX7ILqUByPyRLJXwcVFlYwWZEfUvALbWmmjce+5nskBV5V9/RhUtppQG6rrgB7QxfZfH3aVzm/EeWRAeQFwHUiyposg3FQ4YaYsYXxd3yP43nzjWOzLQExIjWPQk8ABqy7U/8yh8Zp5YAJwWTbGijeLl1ZjSOFC0BNfgOrfxjIiKSPbdcKR4BpRhRfG9zLyQGEmMWhVPZ08bBwsNNawg0iqlSMLrQ70o/k/tPwkO4D5HJ2zZHzGts/xwZBdV3WBEiw9/AoSC8r8zNL8utBZmyTWBxlO3jmVgttKiAu11V/3eulXUhMZBLmloqOMgzPSKQ9bJI+3WDssyprQ9exGgylvQUmHWS6aAh0W5j8K8L0BeacsDlz6WscYGFl0r8h4yNBwID2oTWgSjhpWTJiQjayw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SN6PR12MB4623.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(376002)(39860400002)(366004)(346002)(396003)(136003)(66574015)(38100700002)(5660300002)(1076003)(6666004)(186003)(316002)(16526019)(8676002)(83380400001)(66476007)(2906002)(6636002)(86362001)(52116002)(36756003)(54906003)(2616005)(66946007)(66556008)(8936002)(6512007)(6506007)(44832011)(478600001)(4326008)(6486002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?ijmZxnt0/xf6z6sRkuYnoGr2CBTrvM?= =?utf-8?q?Jgv8xDl9IvL115cpgtz6rBb7r87nNSoyRWsP4jtl80rZB1F+Jenjb0x76V4pFwYgH?= =?utf-8?q?++jTfySs7fr3flakJiy7WrmZuMtHn8aApJSI9Xeo8AcHpY0qOeKdqh47TjU8BuidC?= =?utf-8?q?yurp+87swhPR9asuOgPCzgUcSykIehjmOG2rCJgO5wt0xQbQjVVCtVV2L5mJt3yhZ?= =?utf-8?q?5JlY4FapYcZv2WbOZz7bQEgYWUEqY6XjXlVfeGRE9+8nLzL2fsmUxVhlpc/IlHwSN?= =?utf-8?q?vuMv40NpiqqMkrnLSZLgEF4bp84nT15Djk6idHRS14s+Rt+qWPbj4MyJ/UUK2tLJm?= =?utf-8?q?XINtrmwnXAu8iQdgBAw/BIhbzWqfVA89GBhPrilU2OBT1zKCwYoefyYvaDzFUghnm?= =?utf-8?q?lxxN/DvZy87mHHsUTcl/WtpMJenFwJQh81ndus1ut2no/d/OifzmEAxP85F44eJsN?= =?utf-8?q?xxyqBZNkWykvpI5x8RNsqkR/Hrw29RN7pXNb1rCKCODb5szWFmTJ5FweORBEvAABi?= =?utf-8?q?nGC7QUKZjxY55kcT38hs08YPOXdPmDWYCHGh9lz4cSAa7EhUuwsst9yG+bcSVwrkr?= =?utf-8?q?nfrFE2HJZcEebiDnwYJNThHQJHYjfHkjdv0GT00wj1+/zE37S4Mb8I9bET0cFuM0+?= =?utf-8?q?hGxP1PVvXK6dwd5l06317tHnvfR92JUY/eFJbklMEsoDZNw++u6tVAwsJxpYeresQ?= =?utf-8?q?nW13x+/RiE0w1PheQ7ztdw/azhNNYyW8wAPla8G7zVHogmr1WHn8OKOinkx3m25AC?= =?utf-8?q?7ADC34BwXCp17VuC5tqWHrnP2s4CuMHHecC6J6wZlgA8FbeEAyWMtfYFT2Mtkq4Vl?= =?utf-8?q?3EnPsDJhv/Kx21IzYQGK1hJL793CXJ99etbme9cRsHzwEdsk3dKVKNAh2VufY4Kv+?= =?utf-8?q?luV7CTM148XtL31I2dvMIturgeZeBQL4p+R+uA7VH/u1bSbHE67huIve8FRSDIqED?= =?utf-8?q?ELnddKdb6LnMVZzQGDCtnnflLYJkWienJw8kJpHJ6eQX6Xt+EThjf9M4sXj33bIlP?= =?utf-8?q?tgYXD5QE3gyoj0WIgOAOaFhfiuDjbb2m9uuZaSonXs3bg8vN0hiAqMvZr5QJn21uV?= =?utf-8?q?qAMk0bvBP4rD1D/JPU3jhZTAaWZM6RvoJSz7sXrF59yGy/VKKST6e1H6uTPXfdGMY?= =?utf-8?q?gabWk1DMdFz7F+68pZL7NaexcHXr/wt0eG0RdQvSsHyDnzr696dFbxrp1Xd7BvQgy?= =?utf-8?q?nbZYheh/Si24VTogF24oUq1VLA6r+bLvvRaYYfuNLY1aJXi/5SqC3HcGJvWNDIhnC?= =?utf-8?q?V9/tOm0XcYUHXdY4hiI0dIhJg0Heb4OXHl0f1y6poG2jy3keFw5NGSiHnYq2aLV/P?= =?utf-8?q?kTmFweeTIOdmVL7NwOqKEZhTDxs/sAfp3Lw=3D=3D?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9392f4b3-d6d9-4062-2df4-08d915520a42 X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB4623.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 May 2021 14:27:15.4885 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: liFYfae1W6+s8/aIwfxYDzjFQSW5hCvgMd17cUKymWclMlydyqDz4/6rAhmhL9ZeOwG8Q1tLnq/uByJjuLgvNg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4576 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: , Cc: gregkh@linuxfoundation.org, Felix.Kuehling@amd.com, helgaas@kernel.org, Alexander.Deucher@amd.com, =?utf-8?q?Christian_K=C3=B6nig?= Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Use it to call disply code dependent on device->drv_data before it's set to NULL on device unplug v5: Move HW finilization into this callback to prevent MMIO accesses post cpi remove. Signed-off-by: Andrey Grodzovsky Acked-by: Christian König --- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 59 +++++++++++++------ .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 12 +++- drivers/gpu/drm/amd/include/amd_shared.h | 2 + 3 files changed, 52 insertions(+), 21 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c index 3760ce7d8ff8..18598eda18f6 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c @@ -2558,34 +2558,26 @@ static int amdgpu_device_ip_late_init(struct amdgpu_device *adev) return 0; } -/** - * amdgpu_device_ip_fini - run fini for hardware IPs - * - * @adev: amdgpu_device pointer - * - * Main teardown pass for hardware IPs. The list of all the hardware - * IPs that make up the asic is walked and the hw_fini and sw_fini callbacks - * are run. hw_fini tears down the hardware associated with each IP - * and sw_fini tears down any software state associated with each IP. - * Returns 0 on success, negative error code on failure. - */ -static int amdgpu_device_ip_fini(struct amdgpu_device *adev) +static int amdgpu_device_ip_fini_early(struct amdgpu_device *adev) { int i, r; - if (amdgpu_sriov_vf(adev) && adev->virt.ras_init_done) - amdgpu_virt_release_ras_err_handler_data(adev); + for (i = 0; i < adev->num_ip_blocks; i++) { + if (!adev->ip_blocks[i].version->funcs->early_fini) + continue; - amdgpu_ras_pre_fini(adev); + r = adev->ip_blocks[i].version->funcs->early_fini((void *)adev); + if (r) { + DRM_DEBUG("early_fini of IP block <%s> failed %d\n", + adev->ip_blocks[i].version->funcs->name, r); + } + } - if (adev->gmc.xgmi.num_physical_nodes > 1) - amdgpu_xgmi_remove_device(adev); + amdgpu_amdkfd_suspend(adev, false); amdgpu_device_set_pg_state(adev, AMD_PG_STATE_UNGATE); amdgpu_device_set_cg_state(adev, AMD_CG_STATE_UNGATE); - amdgpu_amdkfd_device_fini(adev); - /* need to disable SMC first */ for (i = 0; i < adev->num_ip_blocks; i++) { if (!adev->ip_blocks[i].status.hw) @@ -2616,6 +2608,33 @@ static int amdgpu_device_ip_fini(struct amdgpu_device *adev) adev->ip_blocks[i].status.hw = false; } + return 0; +} + +/** + * amdgpu_device_ip_fini - run fini for hardware IPs + * + * @adev: amdgpu_device pointer + * + * Main teardown pass for hardware IPs. The list of all the hardware + * IPs that make up the asic is walked and the hw_fini and sw_fini callbacks + * are run. hw_fini tears down the hardware associated with each IP + * and sw_fini tears down any software state associated with each IP. + * Returns 0 on success, negative error code on failure. + */ +static int amdgpu_device_ip_fini(struct amdgpu_device *adev) +{ + int i, r; + + if (amdgpu_sriov_vf(adev) && adev->virt.ras_init_done) + amdgpu_virt_release_ras_err_handler_data(adev); + + amdgpu_ras_pre_fini(adev); + + if (adev->gmc.xgmi.num_physical_nodes > 1) + amdgpu_xgmi_remove_device(adev); + + amdgpu_amdkfd_device_fini_sw(adev); for (i = adev->num_ip_blocks - 1; i >= 0; i--) { if (!adev->ip_blocks[i].status.sw) @@ -3683,6 +3702,8 @@ void amdgpu_device_fini_hw(struct amdgpu_device *adev) amdgpu_fbdev_fini(adev); amdgpu_irq_fini_hw(adev); + + amdgpu_device_ip_fini_early(adev); } void amdgpu_device_fini_sw(struct amdgpu_device *adev) diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c index 296704ce3768..6c2c6a51ce6c 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c @@ -1251,6 +1251,15 @@ static int amdgpu_dm_init(struct amdgpu_device *adev) return -EINVAL; } +static int amdgpu_dm_early_fini(void *handle) +{ + struct amdgpu_device *adev = (struct amdgpu_device *)handle; + + amdgpu_dm_audio_fini(adev); + + return 0; +} + static void amdgpu_dm_fini(struct amdgpu_device *adev) { int i; @@ -1259,8 +1268,6 @@ static void amdgpu_dm_fini(struct amdgpu_device *adev) drm_encoder_cleanup(&adev->dm.mst_encoders[i].base); } - amdgpu_dm_audio_fini(adev); - amdgpu_dm_destroy_drm_device(&adev->dm); #if defined(CONFIG_DRM_AMD_SECURE_DISPLAY) @@ -2298,6 +2305,7 @@ static const struct amd_ip_funcs amdgpu_dm_funcs = { .late_init = dm_late_init, .sw_init = dm_sw_init, .sw_fini = dm_sw_fini, + .early_fini = amdgpu_dm_early_fini, .hw_init = dm_hw_init, .hw_fini = dm_hw_fini, .suspend = dm_suspend, diff --git a/drivers/gpu/drm/amd/include/amd_shared.h b/drivers/gpu/drm/amd/include/amd_shared.h index 43ed6291b2b8..1ad56da486e4 100644 --- a/drivers/gpu/drm/amd/include/amd_shared.h +++ b/drivers/gpu/drm/amd/include/amd_shared.h @@ -240,6 +240,7 @@ enum amd_dpm_forced_level; * @late_init: sets up late driver/hw state (post hw_init) - Optional * @sw_init: sets up driver state, does not configure hw * @sw_fini: tears down driver state, does not configure hw + * @early_fini: tears down stuff before dev detached from driver * @hw_init: sets up the hw state * @hw_fini: tears down the hw state * @late_fini: final cleanup @@ -268,6 +269,7 @@ struct amd_ip_funcs { int (*late_init)(void *handle); int (*sw_init)(void *handle); int (*sw_fini)(void *handle); + int (*early_fini)(void *handle); int (*hw_init)(void *handle); int (*hw_fini)(void *handle); void (*late_fini)(void *handle);