Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp3916546rdh; Tue, 28 Nov 2023 07:11:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IH1immmExgFsow7rlVzl2fvqDjGirrF+HqN+iM1OB/edDVw0I0v+/RM6gMRbOLyKwChgwAE X-Received: by 2002:a17:90b:4a8f:b0:285:a118:3460 with SMTP id lp15-20020a17090b4a8f00b00285a1183460mr9483702pjb.3.1701184285189; Tue, 28 Nov 2023 07:11:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701184285; cv=none; d=google.com; s=arc-20160816; b=S9En7eJkNaIvZSCKqU8ZTR3oQkFv60Lg7+TQMYObfQ+WY12sDO7MF/K2it0AyZftaM TV9sfbcRyFsyqLLJrTfkKyvSZu9pV2a4UOQleOX8S2kD27RP2OJI5XSgHtQ/fQ0yKhpa 8CbHMTHAFOzKNKBzak424G4G/FJdROmS3AQwAuz2FsrHscxIE8erCXer+GSVuUlYAGFv Kp2F+qpXZ8PgF3nuHP/jb/onozG07g1ee5eRTQx1dxcmnf2jSqUBpkpSaebcTtawAdFw UIVerzJ35uA+B/idwBJ4E2P8gywOC9tM/VQyl+v7xRXGdsXCPglajz+nw4RYgAeiM8pE A6QQ== 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=8j1MExlsRxxT7SmvdChN13JnRvZK11DrBVwx/kPHxmE=; fh=hU76Ixc44NDFo0hzv1clQGJ0lDxwjIfhHVHdoat7LUY=; b=oyxvA9sl6Ctf5I2+6NW8cYyHCWeTzIlawqGAk3QVNrexPD5kASeOX4C7YEsSPVc0UZ SpK+J929NFrvslCoChBdtsioYq0hSdpb+9Jazge7KZBTazMXotkc1b/H6r/Y6CvKBBWi faEYC6HwUte33V5+Rwz/Q0xq2qYct2QWoLZSjyABXKn96yo9vbh/eMmQNnvxSwNM7NJW c4kMgj/0YF9rnR62KfQm64gRMj+1uuc/z1OZ2QW/rfQ8R6BvGL9U3iW/3gxoRkTvEJTt HD5uzddmGjUlwBgvf7+b8hMipUNKAQiSEtbvtoRdJGqsoZJfkQ12gqxWSPpL36n4C3xf JqHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=SIH21FmW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id h8-20020a17090acf0800b0028565890527si12261691pju.68.2023.11.28.07.11.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 07:11:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=SIH21FmW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (Postfix) with ESMTP id C499280AEB34; Tue, 28 Nov 2023 07:11:14 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345995AbjK1PKs (ORCPT + 99 others); Tue, 28 Nov 2023 10:10:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346671AbjK1PKm (ORCPT ); Tue, 28 Nov 2023 10:10:42 -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 A8515D41 for ; Tue, 28 Nov 2023 07:10:48 -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 103A766072A4; Tue, 28 Nov 2023 15:10:45 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1701184247; bh=3rcjns7Zzi1era39Xxvp1KTjKNX1ChFSbb4r4eeZBrs=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=SIH21FmWVkd+J9lf6GOQREl1wiEcMUUYUC70dlu8y3yU9/NI7p5g6/u4lrDE4DVNr pz7qpMHgAxyMIn6jJKqVjiwjBAJB4v6tPbTzTac0ppOMAjVh+X2kkmzf7Ql2/f34fl IUAgEhPieOpzKDbV+Dr2u2p3otN6dZnQC34PoXuMUt432W2qha2NQOIh7CHL4J6Zj/ rMj3OeHWmS0lRnPmeknSPPdfUxzdWl+r3qup3/w3qA93p8FbL/U2lJ8hNwiL6HNM5c et38V4nOSoWjSDENgg0Tkd6gCKhbtJ/Aabi5skZ/7kNJ6HHxb3GaH1Ru4rbUMeVUB4 U8g43zDLzx/8g== Message-ID: <6c14d90f-f9e1-4af7-877e-f000b7fa1e08@collabora.com> Date: Tue, 28 Nov 2023 16:10:43 +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> From: AngeloGioacchino Del Regno In-Reply-To: <20231128150612.17f6a095@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 howler.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 (howler.vger.email [0.0.0.0]); Tue, 28 Nov 2023 07:11:15 -0800 (PST) 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... >> 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? Cheers, Angelo