Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp1614165rdb; Wed, 31 Jan 2024 04:15:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IGzcdmbJVzdbj7vIk7tElxHX/oit8wBeC9cBd8taQTjpmvsB+mLEwqKp9Xl64ClbJ9daB1+ X-Received: by 2002:a05:6a00:b52:b0:6da:ca92:3e2e with SMTP id p18-20020a056a000b5200b006daca923e2emr4501029pfo.7.1706703328280; Wed, 31 Jan 2024 04:15:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706703328; cv=pass; d=google.com; s=arc-20160816; b=xFzLopZYnw2QM5PwPTpyiWkIYMLozs96coK6JQpDKDatCN0lib3Hs6aVkoCiCbBuMu Zkdoam6QVpPKS0AMow4b+ctTGFeIpAICWH8zJdqlC6AoKkdaWlUXuP9ZGA94tjbI1xbW QOqNE12DomW7aolDQTRqP36HYJg2IcXqCv0Hn48DK5+dj4ulFkWJLmz39aK5lPBFA4JC LvEuoX4H5lfhirnHbAx3obog2vcGyNkMuom96Oofr+7RK94S6D4KXTrPApwjcP0OeSKo lRWdtfyVnmAVnd0Vlmz9cn5+EpjCnnMq9hi3U8wmDfbkQoHWE6CtE9gwTPo3oJzHTaT8 QSzw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :dkim-signature; bh=saoJoK9zStSfMj3STxg2WdyLizENiKtg2wNhGKTv28w=; fh=ydwSfl7iPROc2o309jjFOqJedldoYgDH1UbMlDBu0Vo=; b=ajHm7GXtZXE+Kp+2i9qPQF01F2HHqs03i5YEnHSNLqcolGwBQ0VPyHzG3xXdFQm4Xk 0ad5u/PVTW838xOlXOibGutyab5Gehl/Rlo/rQP9m8nhDRPfQV8Fzn6BneGR5eUCzz82 KZLKrKUvagEORoj5tiv+qxMPHQ64P0m4pRG0VbDn4aAeJC3uBWB0rRhcFloKnGMwz3Ir D+Po2cQZyyUaOqTJ2g9z8RaX3CdapGkfX8Yl4gR9dKBk/okC7+znZhiUy7VRoYEFfQdz DQaeOnBn3Z8/It+Foagv6sUusZRu9Htnhxd77Q3N/vYth76vm4zwhbeD3E+j19lsZ4PH A3Tw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aF2KQPn2; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-46404-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-46404-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org X-Forwarded-Encrypted: i=1; AJvYcCV09y8Ph52fp1QSLxFlSNqYg6I8Wu5KOOGfj3J8GLDrbk/0lgd65t+5YkEUX6nTXNwF7kFwy5YYv4G88+epDDPq8p8DFSRYvaBSfkAFjQ== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id y194-20020a62cecb000000b006dde26c600asi926185pfg.104.2024.01.31.04.15.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 04:15:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-46404-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aF2KQPn2; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-46404-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-46404-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id E7B5E28555B for ; Wed, 31 Jan 2024 12:12:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4309A78B66; Wed, 31 Jan 2024 12:12:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="aF2KQPn2" Received: from mail-yw1-f178.google.com (mail-yw1-f178.google.com [209.85.128.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9843B78676 for ; Wed, 31 Jan 2024 12:12:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706703160; cv=none; b=DzJ58tOGLegvuE4AOS27JBLXSAXIK3f46M+24g28bVKG+rsvCPzv2OeyLJ73ZIrkwFjHSDKl0fcrNcSujkKlsku70b4ff5EsbngOHJqhONU2SuqpfscqWntq+d92SrkWSJWbjpWuZJTHgNtZgVfwVGmgUAKbchCj99FR6p+TrYg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706703160; c=relaxed/simple; bh=/wVA/4AFAw4JgOYNgYRJpbRJX3HBAQ0JInxifG3k/Ds=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=fT0D3UpQBWC8iSDS5nlK4ZIm20INvD75uhNiS6Gz72ClJR7v7hcwnzIiCeWzHrBax+tERQ05nXStrih5wrfMXZihXdUwKOe1M8eSCImThOaVuqsFCKEY6UVbCEjw4GfHZWYJMG95gTlzReZG3GzuE9L3cyRRkU3G9KUMX+FYMEo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=aF2KQPn2; arc=none smtp.client-ip=209.85.128.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-yw1-f178.google.com with SMTP id 00721157ae682-602c714bdbeso7028987b3.1 for ; Wed, 31 Jan 2024 04:12:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1706703156; x=1707307956; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=saoJoK9zStSfMj3STxg2WdyLizENiKtg2wNhGKTv28w=; b=aF2KQPn2T7Z+qBYWgxZRVcdF8BwDapLvSGAjGUQZkETdjabKy67dop89KfZ0y4Me2T up7l1HlMyL+/ucZ4GJEmrLkn8PyeU78/Sl0K092XVz7VhmEKts7tmyv40RZE7idTgFqI pWdqz7EQeBNEHUXvS3T/+fwxeyHn0PXutFYu6zIXdXBgL6X4vwWwQTjTpj4UdMkMROGJ mrdcfZaAGVMUcDo1rcOSG9vXQcEWeFcXvNIxEphvqVTtcJAXvwkW//beAgiTS7hIrIDJ g9/y96JGGe5Tw0iycfFlLcRnd3qtXyawucs1H2zH4/ZEXYuw+OWd8Q/lx2FjB0H0vYuo PFSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706703156; x=1707307956; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=saoJoK9zStSfMj3STxg2WdyLizENiKtg2wNhGKTv28w=; b=Qz/320A5pqcN8MGGySo58MTLKNY7yX+b/oa0ZoSJfmA2PEBE5aKOcaV1U/tJV9PG1W aZFk88GduLiWSN+O2f6iNN48A9mU9+kPS1JcJEwapVuTr8V5y+NegpKDVnPPmLcANpPH TDSie+0vAOHPtZzfktxvxGVGeW9lIoc+RwGi71LhDg8W/BSZhA+X2hzxyg9WiCMAJ/E5 XWxxGEZCRPVeE4nxn2UCUAfWojKooKsGmyEHnmM938NGeDheveBwJiQdGacsWi1lKNld Hg5Svyb4gtw9WP02bTpdydmW7ypT3HspPuEUB/9jBhTpE7xiLLy5Y2/WblpHoBBDr0MD wEtQ== X-Gm-Message-State: AOJu0Yy+lyA4a54avn/L/Ji7t0tzIw7elweU1UO87HMOWhEXFjoWYeyc Woc9Gqzo2uNPZW0ZSXA2Efq6ZUt0FkQBAmq91v7+e6RaNgLPgihwz07WVHBYXfP6h4ET787Myhd m1ZYITtoTiVKlPyC1HHUfHnwfvEt1YRQTAcYMrA== X-Received: by 2002:a81:a0c3:0:b0:604:fd3:e656 with SMTP id x186-20020a81a0c3000000b006040fd3e656mr453925ywg.19.1706703156500; Wed, 31 Jan 2024 04:12:36 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240122-gdsc-hwctrl-v4-0-9061e8a7aa07@linaro.org> <20240122-gdsc-hwctrl-v4-1-9061e8a7aa07@linaro.org> In-Reply-To: From: Ulf Hansson Date: Wed, 31 Jan 2024 13:12:00 +0100 Message-ID: Subject: Re: [PATCH v4 1/5] PM: domains: Allow devices attached to genpd to be managed by HW To: Bjorn Andersson , Abel Vesa Cc: "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 Content-Type: text/plain; charset="UTF-8" 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? > > > + * > > + * @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. 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? Kind regards Uffe