Received: by 10.223.185.116 with SMTP id b49csp2644263wrg; Mon, 5 Mar 2018 06:30:57 -0800 (PST) X-Google-Smtp-Source: AG47ELtedZF10LNh/gT3QiIRSq9vVdoz1o6SAkKF9gR2sB+4/pd2reVxVNbJYq61xEVtyy8gOUTw X-Received: by 10.99.149.24 with SMTP id p24mr12399220pgd.122.1520260257699; Mon, 05 Mar 2018 06:30:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520260257; cv=none; d=google.com; s=arc-20160816; b=bJQFGjfVUYUm6s+neRwEQ1EIVAkbzVCLVUcx41fJx/voad8B3UkiQNhUm0r5dSA9cs t5v8aNRwqWZ1ARw3SpFg5WqnLPgS5xYyXtYhs9MGXJjVLlnS5FfY6hba6Ha16P+vuu4n n7D0AmAnwSQ0gABDbM6nPFY1jygf7rx9GVmB/zt+qGx8WHmR3TDB6xxBDjomXI2yiWTz LAir9cXDR22YX8DEoYnDC9mARbSk3dowU46GOu5i59j1xTC2Dn0RDxgNG4R8R5tF/cvx hieYanOm2BCxJjRIleu5RAvjseNwonlrs+u9ni9hUK7jpBplJqwgtolXlnyvR3y93lEi bvUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :arc-authentication-results; bh=uS5BIiaLfQjYpTRIYoSkre9uS+HKRs4ZqIfPKKwAmNo=; b=n2O68bgkhcVNPuizEHBzVptDyZM9aaqa0CyPSAk4IhLMvpDGpq/GUGGuofUPYvvf8X wrrTl7RwBaWIA3aJDyLokZAyMRYygisLdWQ272HLAIJSgXTs9NGOk99n2ZmmqpYEWHbs +y5/fHi7MYYPk7WOvL5ekwQh90vXoEABKi7XtHzhFhcmXC/RJw/D1yaVAs33/1mXdDdI ymV2FSfQfxApN8IU+Twst5+bgaL80TUvOgyMag2uV2bVhcaDpOGea1HxEYKI+tGjd/lk Q+YZQDl+gKh3vtg7jrQ6ib3+SALg6FWnI1qD97XTxnWgKlD6ccyEwNCKjwveyNciBe77 43rA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 5si10291592pfx.208.2018.03.05.06.30.42; Mon, 05 Mar 2018 06:30:57 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751980AbeCEO3g (ORCPT + 99 others); Mon, 5 Mar 2018 09:29:36 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:5704 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751878AbeCEO3e (ORCPT ); Mon, 5 Mar 2018 09:29:34 -0500 Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id CA910C4ABEC59; Mon, 5 Mar 2018 22:29:15 +0800 (CST) Received: from localhost (10.202.226.43) by DGGEMS410-HUB.china.huawei.com (10.3.19.210) with Microsoft SMTP Server (TLS) id 14.3.361.1; Mon, 5 Mar 2018 22:29:12 +0800 Date: Mon, 5 Mar 2018 14:29:03 +0000 From: Jonathan Cameron To: Sudeep Holla CC: ALKML , LKML , DTML , "Alexey Klimov" , Greg Kroah-Hartman , Arnd Bergmann Subject: Re: [PATCH v6 06/20] firmware: arm_scmi: add initial support for performance protocol Message-ID: <20180305152903.0000417e@huawei.com> In-Reply-To: <1519403030-21189-7-git-send-email-sudeep.holla@arm.com> References: <1519403030-21189-1-git-send-email-sudeep.holla@arm.com> <1519403030-21189-7-git-send-email-sudeep.holla@arm.com> X-Mailer: Claws Mail 3.16.0 (GTK+ 2.24.31; i686-w64-mingw32) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.202.226.43] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 23 Feb 2018 16:23:36 +0000 Sudeep Holla wrote: > The performance protocol is intended for the performance management of > group(s) of device(s) that run in the same performance domain. It > includes even the CPUs. A performance domain is defined by a set of > devices that always have to run at the same performance level. > For example, a set of CPUs that share a voltage domain, and have a > common frequency control, is said to be in the same performance domain. > > The commands in this protocol provide functionality to describe the > protocol version, describe various attribute flags, set and get the > performance level of a domain. It also supports discovery of the list > of performance levels supported by a performance domain, and the > properties of each performance level. > > + > +static int scmi_perf_attributes_get(const struct scmi_handle *handle, > + struct scmi_perf_info *pi) > +{ > + int ret; > + struct scmi_xfer *t; > + struct scmi_msg_resp_perf_attributes *attr; > + > + ret = scmi_one_xfer_init(handle, PROTOCOL_ATTRIBUTES, > + SCMI_PROTOCOL_PERF, 0, sizeof(*attr), &t); > + if (ret) > + return ret; > + > + attr = t->rx.buf; > + > + ret = scmi_do_xfer(handle, t); > + if (!ret) { Use a goto for the error path rather than indenting all this good path stuff. The same would help readability in various other places. > + u16 flags = le16_to_cpu(attr->flags); > + > + pi->num_domains = le16_to_cpu(attr->num_domains); > + pi->power_scale_mw = POWER_SCALE_IN_MILLIWATT(flags); > + pi->stats_addr = le32_to_cpu(attr->stats_addr_low) | > + (u64)le32_to_cpu(attr->stats_addr_high) << 32; > + pi->stats_size = le32_to_cpu(attr->stats_size); > + } > + > + scmi_one_xfer_put(handle, t); > + return ret; > +} > + ... > + > +static struct scmi_perf_ops perf_ops = { > + .limits_set = scmi_perf_limits_set, > + .limits_get = scmi_perf_limits_get, > + .level_set = scmi_perf_level_set, > + .level_get = scmi_perf_level_get, > + .device_domain_id = scmi_dev_domain_id, > + .get_transition_latency = scmi_dvfs_get_transition_latency, > + .add_opps_to_device = scmi_dvfs_add_opps_to_device, > + .freq_set = scmi_dvfs_freq_set, > + .freq_get = scmi_dvfs_freq_get, > +}; > + > +static int scmi_perf_protocol_init(struct scmi_handle *handle) > +{ > + int domain; > + u32 version; > + struct scmi_perf_info *pinfo; > + > + scmi_version_get(handle, SCMI_PROTOCOL_PERF, &version); > + > + dev_dbg(handle->dev, "Performance Version %d.%d\n", > + PROTOCOL_REV_MAJOR(version), PROTOCOL_REV_MINOR(version)); > + > + pinfo = devm_kzalloc(handle->dev, sizeof(*pinfo), GFP_KERNEL); > + if (!pinfo) > + return -ENOMEM; > + > + scmi_perf_attributes_get(handle, pinfo); > + > + pinfo->dom_info = devm_kcalloc(handle->dev, pinfo->num_domains, > + sizeof(*pinfo->dom_info), GFP_KERNEL); > + if (!pinfo->dom_info) > + return -ENOMEM; > + > + for (domain = 0; domain < pinfo->num_domains; domain++) { > + struct perf_dom_info *dom = pinfo->dom_info + domain; > + > + scmi_perf_domain_attributes_get(handle, domain, dom); > + scmi_perf_describe_levels_get(handle, domain, dom); > + } > + > + handle->perf_ops = &perf_ops; > + handle->perf_priv = pinfo; > + > + return 0; > +} > + > +static int __init scmi_perf_init(void) > +{ > + return scmi_protocol_register(SCMI_PROTOCOL_PERF, > + &scmi_perf_protocol_init); > +} > +subsys_initcall(scmi_perf_init); > diff --git a/include/linux/scmi_protocol.h b/include/linux/scmi_protocol.h > index db995126134d..d80f4c9a0fad 100644 > --- a/include/linux/scmi_protocol.h > +++ b/include/linux/scmi_protocol.h > @@ -44,15 +44,57 @@ struct scmi_revision_info { > char sub_vendor_id[SCMI_MAX_STR_SIZE]; > }; > > +struct scmi_handle; > + > +/** > + * struct scmi_perf_ops - represents the various operations provided > + * by SCMI Performance Protocol > + * > + * @limits_set: sets limits on the performance level of a domain > + * @limits_get: gets limits on the performance level of a domain > + * @level_set: sets the performance level of a domain > + * @level_get: gets the performance level of a domain > + * @device_domain_id: gets the scmi domain id for a given device > + * @get_transition_latency: gets the DVFS transition latency for a given device > + * @add_opps_to_device: adds all the OPPs for a given device > + * @freq_set: sets the frequency for a given device using sustained frequency > + * to sustained performance level mapping > + * @freq_get: gets the frequency for a given device using sustained frequency > + * to sustained performance level mapping > + */ > +struct scmi_perf_ops { > + int (*limits_set)(const struct scmi_handle *handle, u32 domain, > + u32 max_perf, u32 min_perf); > + int (*limits_get)(const struct scmi_handle *handle, u32 domain, > + u32 *max_perf, u32 *min_perf); > + int (*level_set)(const struct scmi_handle *handle, u32 domain, > + u32 level); > + int (*level_get)(const struct scmi_handle *handle, u32 domain, > + u32 *level); > + int (*device_domain_id)(struct device *dev); > + int (*get_transition_latency)(const struct scmi_handle *handle, > + struct device *dev); Naming consistency would improve this. transition_latency_get for example. > + int (*add_opps_to_device)(const struct scmi_handle *handle, > + struct device *dev); > + int (*freq_set)(const struct scmi_handle *handle, u32 domain, > + unsigned long rate); > + int (*freq_get)(const struct scmi_handle *handle, u32 domain, > + unsigned long *rate); > +}; > + > /** > * struct scmi_handle - Handle returned to ARM SCMI clients for usage. > * > * @dev: pointer to the SCMI device > * @version: pointer to the structure containing SCMI version information > + * @perf_ops: pointer to set of performance protocol operations > */ > struct scmi_handle { > struct device *dev; > struct scmi_revision_info *version; > + struct scmi_perf_ops *perf_ops; > + /* for protocol internal use */ > + void *perf_priv; > }; > > enum scmi_std_protocol {