Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp3939428rdh; Tue, 28 Nov 2023 07:42:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IEklF+GPoU1GKqS2QaFvtyvrwYKS3vklgq//Xxixn9+C35J9IEJlxp10H8fIhkE1JJcOrMQ X-Received: by 2002:a05:6e02:13c9:b0:35c:9e1c:c59c with SMTP id v9-20020a056e0213c900b0035c9e1cc59cmr11007218ilj.6.1701186171134; Tue, 28 Nov 2023 07:42:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701186171; cv=none; d=google.com; s=arc-20160816; b=WT6V2ra4KBAJWECCj2S24VMX5ruPCk/JRXWH8pBcFtYWjqNOMUg8HZJYviztAwllbl u95OOaMGUJTzJFXIFkjPyg9IzN6wePw/x/zkmTdJSoO+oAxp863fw075Z7IbMjBxFq46 rBGtYnnNDB0L+NZDtYw0hghPIl6424NzU4t1qVsqkyVfKf+vlVSZ2Xr0hdMtK/81XnV9 UAlbarKZprvMp1JgFmI+n9ZpEZEMlWgQ2nmOS5a2EZBRFMArA+v6AvGmr8xw/fwuoOhR O5Ua64PTcNjg02nhLTB+TQM+EDj01C9f+cHzV+igmUbZccYEna5jfw8yFOrggAdkhNkB lW9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=JElsFj/o3Vg4LY2UC+YCf2IgPbpJ1Wl7HHl7yk3HE04=; fh=hU76Ixc44NDFo0hzv1clQGJ0lDxwjIfhHVHdoat7LUY=; b=RvKDWXWFmfbbAhSyvw0gVVNwWdQPtU08fWdbxoQMey3jf0EnIGt1/Pxg/4WKXBi8cY su4QGNmTtUgDQ8upJ2O3ptaG3lkoPz6ASg57Wqcd5KSp264thPvVxp+QzqVmlgZ3xA6R kDfb0A53oZC2e2TmkMVUgnkctHFtEzR6b60wuf3k54WrPxlRFmLI122Lgsb4zr62v6jY jWJdB5ImFNrD9l8rzkxkhGGiGf89u2Zx1v7Wg/GrLZt2flJ8XpkFkEXID5ASL6CVSmcP uOrZcUyR74ynWlKJOyuLUPkPp16ZSZm3qjCCRI4dvO3oi2Suvrxe1IQZONYp22GFTwQO W4Eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=HeN9ra9P; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id j14-20020a634a4e000000b005bd5a50b559si12077866pgl.715.2023.11.28.07.42.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 07:42:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=HeN9ra9P; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 1BF3B80A056B; Tue, 28 Nov 2023 07:42:48 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346022AbjK1Pm2 (ORCPT + 99 others); Tue, 28 Nov 2023 10:42:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345899AbjK1PmZ (ORCPT ); Tue, 28 Nov 2023 10:42:25 -0500 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D6D3D4F for ; Tue, 28 Nov 2023 07:42:30 -0800 (PST) Received: from [100.107.97.3] (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: kholk11) by madras.collabora.co.uk (Postfix) with ESMTPSA id EAA8966072A4; Tue, 28 Nov 2023 15:42:27 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1701186149; bh=8chB7Hf/7fvnKT3TALs/wJ17MCLdyGBUU/ypcCPLzg4=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=HeN9ra9Pi/G1Hcx6jSHDWUVSotuMs4/OcI5uZ1J3b74RroJB2xtAAmeXZyflFwzrL Tz3KeKogPKEGq0wUjLRd4yS/26o7MiV5WnvY0Rnqp7h9nVKfhby+pKzj0PXRsDjMuB qoeKwDIJQq6w4Bjnj1fi0Rs5hqF8GTYEgY+LUDLaELyt+r6wPhhNobDIk08+TH+qvW DfrRKk9+hYZF3twU67aNyck/7WObsTCMnOQm3lKrXjRB8hONicXo3xLudASy4jEbJB BAO9pLuJEqn0oHLekgJeHnsx2oiGX0pqEd5adn2wD5fM5r54Exn/0Jw4Ztn514stpB dd9M9OuTz7L0A== Message-ID: <34b7ae7d-c4d3-4d94-a1e9-62d3d4fc6b9a@collabora.com> Date: Tue, 28 Nov 2023 16:42:25 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 3/3] drm/panfrost: Synchronize and disable interrupts before powering off Content-Language: en-US To: Boris Brezillon Cc: robh@kernel.org, steven.price@arm.com, maarten.lankhorst@linux.intel.com, mripard@kernel.org, tzimmermann@suse.de, airlied@gmail.com, daniel@ffwll.ch, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, kernel@collabora.com, m.szyprowski@samsung.com, krzysztof.kozlowski@linaro.org References: <20231128124510.391007-1-angelogioacchino.delregno@collabora.com> <20231128124510.391007-4-angelogioacchino.delregno@collabora.com> <20231128150612.17f6a095@collabora.com> <6c14d90f-f9e1-4af7-877e-f000b7fa1e08@collabora.com> <20231128163808.094a8afa@collabora.com> From: AngeloGioacchino Del Regno In-Reply-To: <20231128163808.094a8afa@collabora.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Tue, 28 Nov 2023 07:42:48 -0800 (PST) Il 28/11/23 16:38, Boris Brezillon ha scritto: > On Tue, 28 Nov 2023 16:10:43 +0100 > AngeloGioacchino Del Regno > wrote: > >> Il 28/11/23 15:06, Boris Brezillon ha scritto: >>> On Tue, 28 Nov 2023 13:45:10 +0100 >>> AngeloGioacchino Del Regno >>> wrote: >>> >>>> To make sure that we don't unintentionally perform any unclocked and/or >>>> unpowered R/W operation on GPU registers, before turning off clocks and >>>> regulators we must make sure that no GPU, JOB or MMU ISR execution is >>>> pending: doing that required to add a mechanism to synchronize the >>>> interrupts on suspend. >>>> >>>> Add functions panfrost_{gpu,job,mmu}_suspend_irq() which will perform >>>> interrupts masking and ISR execution synchronization, and then call >>>> those in the panfrost_device_runtime_suspend() handler in the exact >>>> sequence of job (may require mmu!) -> mmu -> gpu. >>>> >>>> As a side note, JOB and MMU suspend_irq functions needed some special >>>> treatment: as their interrupt handlers will unmask interrupts, it was >>>> necessary to add a bitmap for "is_suspending" which is used to address >>>> the possible corner case of unintentional IRQ unmasking because of ISR >>>> execution after a call to synchronize_irq(). >>>> >>>> Of course, unmasking the interrupts is being done as part of the reset >>>> happening during runtime_resume(): since we're anyway resuming all of >>>> GPU, JOB, MMU, the only additional action is to zero out the newly >>>> introduced `is_suspending` bitmap directly in the resume handler, as >>>> to avoid adding panfrost_{job,mmu}_resume_irq() function just for >>>> clearing own bits, especially because it currently makes way more sense >>>> to just zero out the bitmap. >>>> >>>> Signed-off-by: AngeloGioacchino Del Regno >>>> --- >>>> drivers/gpu/drm/panfrost/panfrost_device.c | 4 ++++ >>>> drivers/gpu/drm/panfrost/panfrost_device.h | 7 +++++++ >>>> drivers/gpu/drm/panfrost/panfrost_gpu.c | 7 +++++++ >>>> drivers/gpu/drm/panfrost/panfrost_gpu.h | 1 + >>>> drivers/gpu/drm/panfrost/panfrost_job.c | 18 +++++++++++++++--- >>>> drivers/gpu/drm/panfrost/panfrost_job.h | 1 + >>>> drivers/gpu/drm/panfrost/panfrost_mmu.c | 17 ++++++++++++++--- >>>> drivers/gpu/drm/panfrost/panfrost_mmu.h | 1 + >>>> 8 files changed, 50 insertions(+), 6 deletions(-) >>>> >>>> diff --git a/drivers/gpu/drm/panfrost/panfrost_device.c b/drivers/gpu/drm/panfrost/panfrost_device.c >>>> index c90ad5ee34e7..ed34aa55a7da 100644 >>>> --- a/drivers/gpu/drm/panfrost/panfrost_device.c >>>> +++ b/drivers/gpu/drm/panfrost/panfrost_device.c >>>> @@ -407,6 +407,7 @@ static int panfrost_device_runtime_resume(struct device *dev) >>>> { >>>> struct panfrost_device *pfdev = dev_get_drvdata(dev); >>>> >>>> + bitmap_zero(pfdev->is_suspending, PANFROST_COMP_BIT_MAX); >>> >>> I would let each sub-block clear their bit in the reset path, since >>> that's where the IRQs are effectively unmasked. >>> >> >> >> Honestly I wouldn't like seeing that: the reason is that this is something that >> is done *for* suspend/resume and only for that, while reset may be called out of >> the suspend/resume handlers. >> >> I find clearing the suspend bits in the HW reset path a bit confusing, especially >> when it is possible to avoid doing it there... > > Well, I do think it's preferable to keep the irq_is_no_longer_suspended > state update where the interrupt is effectively unmasked. Note that > when you do a reset, the IRQ is silently suspended just after the > reset happens, because the xxx_INT_MASKs are restored to their default > value, so I do consider that clearing this bit in the reset path makes > sense. > Okay then, I can move it, no problem. >> >>>> panfrost_device_reset(pfdev); >>>> panfrost_devfreq_resume(pfdev); >>>> >>>> @@ -421,6 +422,9 @@ static int panfrost_device_runtime_suspend(struct device *dev) >>>> return -EBUSY; >>>> >>>> panfrost_devfreq_suspend(pfdev); >>>> + panfrost_job_suspend_irq(pfdev); >>>> + panfrost_mmu_suspend_irq(pfdev); >>>> + panfrost_gpu_suspend_irq(pfdev); >>>> panfrost_gpu_power_off(pfdev); >>>> >>>> return 0; >>>> diff --git a/drivers/gpu/drm/panfrost/panfrost_device.h b/drivers/gpu/drm/panfrost/panfrost_device.h >>>> index 54a8aad54259..29f89f2d3679 100644 >>>> --- a/drivers/gpu/drm/panfrost/panfrost_device.h >>>> +++ b/drivers/gpu/drm/panfrost/panfrost_device.h >>>> @@ -25,6 +25,12 @@ struct panfrost_perfcnt; >>>> #define NUM_JOB_SLOTS 3 >>>> #define MAX_PM_DOMAINS 5 >>>> >>>> +enum panfrost_drv_comp_bits { >>>> + PANFROST_COMP_BIT_MMU, >>>> + PANFROST_COMP_BIT_JOB, >>>> + PANFROST_COMP_BIT_MAX >>>> +}; >>>> + >>>> /** >>>> * enum panfrost_gpu_pm - Supported kernel power management features >>>> * @GPU_PM_CLK_DIS: Allow disabling clocks during system suspend >>>> @@ -109,6 +115,7 @@ struct panfrost_device { >>>> >>>> struct panfrost_features features; >>>> const struct panfrost_compatible *comp; >>>> + DECLARE_BITMAP(is_suspending, PANFROST_COMP_BIT_MAX); >>> >>> nit: Maybe s/is_suspending/suspended_irqs/, given the state remains >>> until the device is resumed. >> >> If we keep the `is_suspending` name, we can use this one more generically in >> case we ever need to, what do you think? > > I'm lost. Why would we want to reserve a name for something we don't > know about? My comment was mostly relating to the fact this bitmap > doesn't reflect the is_suspending state, but rather is_suspended, > because it remains set until the device is resumed. And we actually want > it to reflect the is_suspended state, so we can catch interrupts that > are not for us without reading regs in the hard irq handler, when the > GPU is suspended. `is_suspended` (fun story: that's the first name I gave it) looks good to me, the doubt I raised was about calling it `suspended_irqs` instead, as I would prefer to keep names "more generic", but that's just personal preference at this point anyway. Cheers, Angelo