Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp512847rdb; Thu, 1 Feb 2024 15:52:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IF9qHuFvxPqn0HCDCN4MRjM+hHnsJzCv2Ea0WHPi+o58HGhwU7+vF6vheQ8joFCMCm6YEnl X-Received: by 2002:a0c:e9d0:0:b0:68c:7f05:a42f with SMTP id q16-20020a0ce9d0000000b0068c7f05a42fmr1049740qvo.18.1706831527767; Thu, 01 Feb 2024 15:52:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706831527; cv=pass; d=google.com; s=arc-20160816; b=t55vvI60o3sp7KoivxPFHk8+ybFUVSz4i7fBIQFXV1tAzF7B3lEgLTxwBd96BOTYTa Ped0pQ9yH8dkhKiI1vO9rAuyjHFyyJmsQV8y26+wW+ZJnW1oiemM3zT+Ap5pandvSwac w+6HLJdg+1xvjzyBAqyVO6JintqmRzLvV2ZOUNPj/Wwvcmron+WS9T0TGDmcPUaYJP+2 D86Cr4IJO9nCp6ulVFnfAtGQ7C38Rs6GapJy3ckpcLtYEIIjcpZSus3gA25KRoTjPUJL INumhAhrgX5J1zKGedflLQIWzegkvDy1SXPNd9c/4MAebwkylZbRgeXU1S3np+fjV445 LNNw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=VcC4rP2iLRVLHXq08Wj+3Zd9h5FhJeqpGnLNy4ftPQk=; fh=0TAaJyYDNLkTKgbN+kN5gpHretT5dGXLnmkuj5DQBgg=; b=KHYH8+sSrpK6/EafgTHSi9fG+WXLPkX1WEAq6RWhkQH13DSjLPf4+J8tSb3Vncr9kg 24XO2hPRAmyY7IcJn1sSdkGKbhpNGLZwyoMmHvQx4JxBiuqulcFXoJw6OpccmgK16j++ 6tfcH5+KQ+aeF6pzdIm+FpsB33/WSQB6QmjIWzVyzh9eWuhpbZtU08BhNI0lHmj1tmfS MmWpVBOISK7cbq8BnJhSuIfQPJnyGhtWZSBvKL187r/v6iv+BmDGcJoggVluNK6BqG53 x/kEZLJ7T1eBlrlgnmaYiBw+nt0Gs1NpJG08u+Xk/Tb9pJHB+Ms6xvQmsgSWt08P6msC fEKA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=F5EBWuJA; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-49008-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49008-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCVnIiZ0TC8B1WIeeQAC+r9wwGizqlS7c6g/Bu3kxgTAdr5/WAvmGAuhAG44j3o04JBKe8A/Ovxrr2RS4Om7kS541INSdrxv0VnUYUCUyw== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id t20-20020a0cef54000000b0068c6fed7aa3si712373qvs.161.2024.02.01.15.52.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 15:52:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49008-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=F5EBWuJA; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-49008-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49008-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 316491C212D0 for ; Thu, 1 Feb 2024 23:52:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6D4B047F79; Thu, 1 Feb 2024 23:51:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="F5EBWuJA" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4724547F59; Thu, 1 Feb 2024 23:51:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706831509; cv=none; b=bX6nH0Ib01G4QJ5Cv9yG9jc4pd7tI5I7SgEK9BpW7KobpjJjRpihgYS3yjllizYD2dUbNN3dZ8OrfDgZiR7TMI9y3kjgVLgUdV72mTwdbfMEhYq2IAu8C3mBosRtQmH9qlGMO0eAquosuhNH/qLrtgZ4N5MRkHBf9dKU8sTM73c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706831509; c=relaxed/simple; bh=FOHcufONbN0/pF2GMlGqhXYPYixKrUUq72o/McpHSq0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=pRV8y874F6DWGAB9DEH228FpY/4XwUEVWTkfNPYPeb0E77KSsz4R7Bn2auauT33lmOCYipWXAjVw1gJ50QzkhXUN7GXZbixg7ZfA2yL7vPJJSj32NZ5rnKnDTTIEpOjHjiby18RgoYkN6FBFq8dH/MH0I0uWdcf2I/4Jsh+Zu8k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=F5EBWuJA; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 08DBEC433C7; Thu, 1 Feb 2024 23:51:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706831508; bh=FOHcufONbN0/pF2GMlGqhXYPYixKrUUq72o/McpHSq0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=F5EBWuJAP/b8dmyCSFJx8XNPEJ5E1M8Dp1GohRlEGSI8SE1/pNUNHLxByQS83YTZp +kTMEBxol1rAQCSE17sCAq+awsWMGpeaDR22rbUWqjevvacu9rtP/dqQbK4c2WAlck /DIMSq2Q1PowNjSf4B0a4Lz6ZnwyJ7sgh+MPmabnDX89axYwtvdWdbtVqUqkNQMBsO 4rcJmUTLRz6TjSkVc6KS+oRPiGxp/CycgheXgB3YnOGMo96KTOgRI531EHSZLPwmzt 0WUMDoJSDuCHrb3fFel0qo8oZ1fsVssVEgkGDO2djNy9oUkvYklOLAHbuABdumDvlh +YVdi/wSh/09g== Date: Thu, 1 Feb 2024 17:51:45 -0600 From: Bjorn Andersson To: Ulf Hansson Cc: Abel Vesa , "Rafael J. Wysocki" , Kevin Hilman , Pavel Machek , Len Brown , Greg Kroah-Hartman , Andy Gross , Konrad Dybcio , Michael Turquette , Stephen Boyd , Stanimir Varbanov , Vikash Garodia , Bryan O'Donoghue , Mauro Carvalho Chehab , Taniya Das , Jagadeesh Kona , Dmitry Baryshkov , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-clk@vger.kernel.org, linux-media@vger.kernel.org Subject: Re: Re: [PATCH v4 1/5] PM: domains: Allow devices attached to genpd to be managed by HW Message-ID: References: <20240122-gdsc-hwctrl-v4-0-9061e8a7aa07@linaro.org> <20240122-gdsc-hwctrl-v4-1-9061e8a7aa07@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Wed, Jan 31, 2024 at 01:12:00PM +0100, Ulf Hansson wrote: > On Wed, 31 Jan 2024 at 02:09, Bjorn Andersson wrote: > > > > On Mon, Jan 22, 2024 at 10:47:01AM +0200, Abel Vesa wrote: > > > From: Ulf Hansson > > > > > > Some power-domains may be capable of relying on the HW to control the power > > > for a device that's hooked up to it. Typically, for these kinds of > > > configurations the consumer driver should be able to change the behavior of > > > power domain at runtime, control the power domain in SW mode for certain > > > configurations and handover the control to HW mode for other usecases. > > > > > > To allow a consumer driver to change the behaviour of the PM domain for its > > > device, let's provide a new function, dev_pm_genpd_set_hwmode(). Moreover, > > > let's add a corresponding optional genpd callback, ->set_hwmode_dev(), > > > which the genpd provider should implement if it can support switching > > > between HW controlled mode and SW controlled mode. Similarly, add the > > > dev_pm_genpd_get_hwmode() to allow consumers to read the current mode and > > > its corresponding optional genpd callback, ->get_hwmode_dev(), which the > > > genpd provider can also implement for reading back the mode from the > > > hardware. > > > > > > Signed-off-by: Ulf Hansson > > > Signed-off-by: Abel Vesa > > > Reviewed-by: Dmitry Baryshkov > > > --- > > > drivers/pmdomain/core.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++ > > > include/linux/pm_domain.h | 17 ++++++++++++ > > > 2 files changed, 86 insertions(+) > > > > > > diff --git a/drivers/pmdomain/core.c b/drivers/pmdomain/core.c > > > index a1f6cba3ae6c..41b6411d0ef5 100644 > > > --- a/drivers/pmdomain/core.c > > > +++ b/drivers/pmdomain/core.c > > > @@ -548,6 +548,75 @@ void dev_pm_genpd_synced_poweroff(struct device *dev) > > > } > > > EXPORT_SYMBOL_GPL(dev_pm_genpd_synced_poweroff); > > > > > > +/** > > > + * dev_pm_genpd_set_hwmode - Set the HW mode for the device and its PM domain. > > > > This isn't proper kernel-doc > > Sorry, I didn't quite get that. What is wrong? > https://docs.kernel.org/doc-guide/kernel-doc.html#function-documentation says that there should be () after the function name, and below there should be a Return: > > > > > + * > > > + * @dev: Device for which the HW-mode should be changed. > > > + * @enable: Value to set or unset the HW-mode. > > > + * > > > + * Some PM domains can rely on HW signals to control the power for a device. To > > > + * allow a consumer driver to switch the behaviour for its device in runtime, > > > + * which may be beneficial from a latency or energy point of view, this function > > > + * may be called. > > > + * > > > + * It is assumed that the users guarantee that the genpd wouldn't be detached > > > + * while this routine is getting called. > > > + * > > > + * Returns 0 on success and negative error values on failures. > > > + */ > > > +int dev_pm_genpd_set_hwmode(struct device *dev, bool enable) > > > +{ > > > + struct generic_pm_domain *genpd; > > > + int ret = 0; > > > + > > > + genpd = dev_to_genpd_safe(dev); > > > + if (!genpd) > > > + return -ENODEV; > > > + > > > + if (!genpd->set_hwmode_dev) > > > + return -EOPNOTSUPP; > > > + > > > + genpd_lock(genpd); > > > + > > > + if (dev_gpd_data(dev)->hw_mode == enable) > > > > Between this and the gdsc patch, the hw_mode state might not match the > > hardware state at boot. > > > > With hw_mode defaulting to false, your first dev_pm_genpd_set_hwmode(, > > false) will not bring control to SW - which might be fatal. > > Right, good point. > > I think we have two ways to deal with this: > 1) If the provider is supporting ->get_hwmode_dev(), we can let > genpd_add_device() invoke it to synchronize the state. I'd suggest that we skip the optimization for now and just let the update hit the driver on each call. > 2) If the provider doesn't support ->get_hwmode_dev() we need to call > ->set_hwmode_dev() to allow an initial state to be set. > > The question is then, if we need to allow ->get_hwmode_dev() to be > optional, if the ->set_hwmode_dev() is supported - or if we can > require it. What's your thoughts around this? > Iiuc this resource can be shared between multiple clients, and we're in either case returning the shared state. That would mean a client acting upon the returned value, is subject to races. I'm therefore inclined to say that we shouldn't have a getter, other than for debugging purposes, in which case reading the HW-state or failing would be reasonable outcomes. Regards, Bjorn