Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2352858pxb; Mon, 20 Sep 2021 19:50:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJywPTmCNswpQKKAlbYtoWZiogvcLq5Dchcf8HQ5sCGeTz7p7p6uKJNmT+GDPqwDcToytFVy X-Received: by 2002:a17:906:9ad0:: with SMTP id ah16mr33082902ejc.43.1632192623879; Mon, 20 Sep 2021 19:50:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632192623; cv=none; d=google.com; s=arc-20160816; b=dGOW9vg9wffMGAcEwPZUMe+zfwwTJgmEe/darCtgYeRONaor6niBnLyjd8dtfywPuo oz/BhBAUMG5bPHib/I+h+AJKEJfivACclT2GESwPaxWlQsUmEmP2lJsNf/aQ+juZl9Gs dGOYwFhuMfQirAU+3dNXgp2cbN9y4BAIC2nmTLTEAbO1vZ1Vzl/2NDqcBzICUFTXyITL p/6BMhwPX5DbK55LhdW7z8/69gRZ/s6szkbWiwS0NrNveJitSCQcePXQSvdngxmMPGKp R2mDNOuHNCViLlzVc27o1TfeyeWBmu078ymj603ROlXAYvDD2T6K+cUxLdSqw+u1ch6m xkGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=qXPdj7JsM7/PAeYBsj4rWs3jWYB59hmPSY7aBjitTTk=; b=bQZ7kNs1om2iEGNDzMw50+lZ9c1pQQs13v1jNLkCLIOTpj/ExYiub/x+U429v6upbG imEGgZztAL0IoAdgGW27o3TKscmhuwhCyyooj0cUQuWYby0DZa4GIWsmkkTN4AE7O88Y DpAoa5X2MhECgsx3u+GXMfZUFd3ruY1Xs5GDv+GOt5qmQMBqb+z/aQjUOcC7tJSpiNIU JPnYt94h6xDNOxKRwxWLEHpxb8L7OprJ4cgB79Sl1DNrJ5Q3+BVb/hoUtvXc3afkofpa bj1/CoH5jTSGYbPOgf3y3zd4gaMCdsQk1beUKsTfb0LWmIXOTSQNAQLJHnGHO/1gNx1T J1ZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Ns8Cqti5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 16si9402975ejf.565.2021.09.20.19.50.00; Mon, 20 Sep 2021 19:50:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Ns8Cqti5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381460AbhITSld (ORCPT + 99 others); Mon, 20 Sep 2021 14:41:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:52012 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380177AbhITSgY (ORCPT ); Mon, 20 Sep 2021 14:36:24 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2957161360; Mon, 20 Sep 2021 17:29:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632158961; bh=Ru+MEAzX5O2omW4RBoXa85+qcuUCRwT4xf5WvCKbfnQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ns8Cqti5fFECXWUkwtYxa3kPxxNplHRHzH0MDr6+IYQ4RcKKB6F6g1dZuIjhdtKGN c9HpcR4VgXK5+w0u44EvHJW2RQhjRbJiPFZxVRah0oowTYVZIgSCFSksI24jmM2hy0 HlRwx2UFeOdw4r89IA2/5L5nLwOkGBaoax5zvCEw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Evan Quan , Lijo Lazar , Guchun Chen , Alex Deucher , Pierre-Eric Pelloux-Prayer Subject: [PATCH 5.14 013/168] drm/amd/pm: fix runpm hang when amdgpu loaded prior to sound driver Date: Mon, 20 Sep 2021 18:42:31 +0200 Message-Id: <20210920163922.088118246@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163921.633181900@linuxfoundation.org> References: <20210920163921.633181900@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Evan Quan commit 8b514e898ee7f861eb8863c647d258f71053af40 upstream. Current RUNPM mechanism relies on PMFW to master the timing for BACO in/exit. And that needs cooperation from sound driver for dstate change notification for function 1(audio). Otherwise(on sound driver missing), BACO cannot be kicked in correctly and hang will be observed on RUNPM exit. By switching back to legacy message way on sound driver missing, we are able to fix the runpm hang observed for the scenario below: amdgpu driver loaded -> runpm suspend kicked -> sound driver loaded Signed-off-by: Evan Quan Reported-and-tested-by: Pierre-Eric Pelloux-Prayer Reviewed-by: Lijo Lazar Reviewed-by: Guchun Chen Signed-off-by: Alex Deucher Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c | 24 ++++++++++++++-- drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c | 4 +- drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c | 21 ++++++++++++++ drivers/gpu/drm/amd/pm/swsmu/smu_cmn.h | 2 + 4 files changed, 47 insertions(+), 4 deletions(-) --- a/drivers/gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c +++ b/drivers/gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c @@ -2269,7 +2269,27 @@ static int navi10_baco_enter(struct smu_ { struct amdgpu_device *adev = smu->adev; - if (adev->in_runpm) + /* + * This aims the case below: + * amdgpu driver loaded -> runpm suspend kicked -> sound driver loaded + * + * For NAVI10 and later ASICs, we rely on PMFW to handle the runpm. To + * make that possible, PMFW needs to acknowledge the dstate transition + * process for both gfx(function 0) and audio(function 1) function of + * the ASIC. + * + * The PCI device's initial runpm status is RUNPM_SUSPENDED. So as the + * device representing the audio function of the ASIC. And that means + * even if the sound driver(snd_hda_intel) was not loaded yet, it's still + * possible runpm suspend kicked on the ASIC. However without the dstate + * transition notification from audio function, pmfw cannot handle the + * BACO in/exit correctly. And that will cause driver hang on runpm + * resuming. + * + * To address this, we revert to legacy message way(driver masters the + * timing for BACO in/exit) on sound driver missing. + */ + if (adev->in_runpm && smu_cmn_is_audio_func_enabled(adev)) return smu_v11_0_baco_set_armd3_sequence(smu, BACO_SEQ_BACO); else return smu_v11_0_baco_enter(smu); @@ -2279,7 +2299,7 @@ static int navi10_baco_exit(struct smu_c { struct amdgpu_device *adev = smu->adev; - if (adev->in_runpm) { + if (adev->in_runpm && smu_cmn_is_audio_func_enabled(adev)) { /* Wait for PMFW handling for the Dstate change */ msleep(10); return smu_v11_0_baco_set_armd3_sequence(smu, BACO_SEQ_ULPS); --- a/drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c +++ b/drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c @@ -2133,7 +2133,7 @@ static int sienna_cichlid_baco_enter(str { struct amdgpu_device *adev = smu->adev; - if (adev->in_runpm) + if (adev->in_runpm && smu_cmn_is_audio_func_enabled(adev)) return smu_v11_0_baco_set_armd3_sequence(smu, BACO_SEQ_BACO); else return smu_v11_0_baco_enter(smu); @@ -2143,7 +2143,7 @@ static int sienna_cichlid_baco_exit(stru { struct amdgpu_device *adev = smu->adev; - if (adev->in_runpm) { + if (adev->in_runpm && smu_cmn_is_audio_func_enabled(adev)) { /* Wait for PMFW handling for the Dstate change */ msleep(10); return smu_v11_0_baco_set_armd3_sequence(smu, BACO_SEQ_ULPS); --- a/drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c +++ b/drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c @@ -1053,3 +1053,24 @@ int smu_cmn_set_mp1_state(struct smu_con return ret; } + +bool smu_cmn_is_audio_func_enabled(struct amdgpu_device *adev) +{ + struct pci_dev *p = NULL; + bool snd_driver_loaded; + + /* + * If the ASIC comes with no audio function, we always assume + * it is "enabled". + */ + p = pci_get_domain_bus_and_slot(pci_domain_nr(adev->pdev->bus), + adev->pdev->bus->number, 1); + if (!p) + return true; + + snd_driver_loaded = pci_is_enabled(p) ? true : false; + + pci_dev_put(p); + + return snd_driver_loaded; +} --- a/drivers/gpu/drm/amd/pm/swsmu/smu_cmn.h +++ b/drivers/gpu/drm/amd/pm/swsmu/smu_cmn.h @@ -110,5 +110,7 @@ void smu_cmn_init_soft_gpu_metrics(void int smu_cmn_set_mp1_state(struct smu_context *smu, enum pp_mp1_state mp1_state); +bool smu_cmn_is_audio_func_enabled(struct amdgpu_device *adev); + #endif #endif