Received: by 10.223.185.111 with SMTP id b44csp862875wrg; Fri, 9 Mar 2018 15:28:17 -0800 (PST) X-Google-Smtp-Source: AG47ELvYdslqVWAjefQFF3CNRHM+dEwx1A6w26XLexEmDFy6FDAMp7E2fCRzsCL2ZTFGOXC4cmnm X-Received: by 10.98.242.6 with SMTP id m6mr192295pfh.230.1520638097627; Fri, 09 Mar 2018 15:28:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520638097; cv=none; d=google.com; s=arc-20160816; b=THMjJidOyoVqbsY76+jmLpbjJwEJaz4E5TptZQdPXImebDXJVzfhGPMvtBLYtbnGM3 2QG/toqIJbEk/5/cnFXN27K9VnyUKc4h/rlvPcuoKrv2qbxevs2JZy8kbpa/1UBFWNWc Oe8Sjs/juOiZACuhPSN32KnhlECDHu0finCiswgrwkAhhdt3HYwENmbOwMDIwIY/Pbj4 IjKl5MY2vt3jptrbkAbmhnS2yaXJSEs58U5MrwD4yOFEGMZGIlMs3HDOOPem2TQJWxCf cymIONLNwJNBPewv5J2FfKmjTc36IWq5n/Gl0iQ1W1MZoBTfO9ELTsdaBYxYGN3QF9zj D6Qw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dmarc-filter:dkim-signature:dkim-signature :arc-authentication-results; bh=Vkubz6w8sH2w4ZfetXDCnDI3phZB5muJ40ZKOHi2mAg=; b=bDBWhpdczFxcAcbiVFCx+T25QPcqWDM1+9orRqjjj8GtuOcCl3AxJ/BzO7VNahMg2m A8jx0Ov4W3pvEFo71bk5uw4UNAOL9RgDKsOjq8hQR/O3dqRQygHktx9/URaDxWtYKq3V 8o89hQI3NzPsRja/niI/EO1+cRjzlffjsWn4Uaf7KtECBLrzsB+QZ3RxMwXqF6SjqMiN ZvELT/VTttFlkEAmsdSjAheStYcC/in7/SaLGFFjeLTRt9TRLEo/G9HRZouKITsAVmW+ B+uXWtApT9J7omeEFQI91zuKbfPo66EWcyHDYryjcuONI5Rs3rbd/25hhqmStGn0lDq3 uNlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=X+92xwlB; dkim=pass header.i=@codeaurora.org header.s=default header.b=cUPdYIZx; 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 i1-v6si1643717pld.260.2018.03.09.15.28.02; Fri, 09 Mar 2018 15:28:17 -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; dkim=pass header.i=@codeaurora.org header.s=default header.b=X+92xwlB; dkim=pass header.i=@codeaurora.org header.s=default header.b=cUPdYIZx; 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 S932953AbeCIX0u (ORCPT + 99 others); Fri, 9 Mar 2018 18:26:50 -0500 Received: from smtp.codeaurora.org ([198.145.29.96]:53890 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932828AbeCIXZ7 (ORCPT ); Fri, 9 Mar 2018 18:25:59 -0500 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 442CE607EF; Fri, 9 Mar 2018 23:25:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1520637958; bh=g+97MGUCxFLlDIs0Q8rbk+kl2Ixuu+ggKFtmOSS6QbM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=X+92xwlBrCkqHxuoFHeovGkLjCN/SqMAg8Xdbkxdh8OW5DbEz5AsXDZ7wDuqEoKIN DywiQILZ/wQKxjFe5Pkay7RcvGdP9HyIb9fGfaSZvOH3XGc4vgLjQE8iFs60j0373C 7kVkoiSIFRnVCEgXTcU9GtZHEn17y3Np+jxh3Jl0= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from codeaurora.org (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: ilina@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id AB19B607E5; Fri, 9 Mar 2018 23:25:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1520637957; bh=g+97MGUCxFLlDIs0Q8rbk+kl2Ixuu+ggKFtmOSS6QbM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cUPdYIZxk7WpBKblptfo0SCSVQrmHHakMjUnNP6Orxpb91VezyVNQuAU3/Dqk8Uu2 c7t+mLwlEXU99LY100NFYGlHI6r0hoyeaT+HyZo94Wzu/IBcQ3TN8+adZ7vasxDhk0 OBKw3ctlSPqKVTAYt116g28k/kvXInUOpUmpQnUs= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org AB19B607E5 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=ilina@codeaurora.org From: Lina Iyer To: andy.gross@linaro.org, david.brown@linaro.org, linux-arm-msm@vger.kernel.org Cc: linux-soc@vger.kernel.org, rnayak@codeaurora.org, bjorn.andersson@linaro.org, linux-kernel@vger.kernel.org, sboyd@kernel.org, Lina Iyer Subject: [PATCH v4 08/10] drivers: qcom: rpmh: allow requests to be sent asynchronously Date: Fri, 9 Mar 2018 16:25:41 -0700 Message-Id: <20180309232543.24636-9-ilina@codeaurora.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180309232543.24636-1-ilina@codeaurora.org> References: <20180309232543.24636-1-ilina@codeaurora.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Platform drivers that want to send a request but do not want to block until the RPMH request completes have now a new API - rpmh_write_async(). The API allocates memory and send the requests and returns the control back to the platform driver. The tx_done callback from the controller is handled in the context of the controller's thread and frees the allocated memory. This API allows RPMH requests from atomic contexts as well. Signed-off-by: Lina Iyer --- drivers/soc/qcom/rpmh.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ include/soc/qcom/rpmh.h | 8 ++++++++ 2 files changed, 61 insertions(+) diff --git a/drivers/soc/qcom/rpmh.c b/drivers/soc/qcom/rpmh.c index b5468ef082c1..3a96e5f58302 100644 --- a/drivers/soc/qcom/rpmh.c +++ b/drivers/soc/qcom/rpmh.c @@ -35,6 +35,7 @@ .cmd = { { 0 } }, \ .completion = q, \ .rc = rc, \ + .free = NULL, \ } /** @@ -59,6 +60,7 @@ struct cache_req { * @cmd: the payload that will be part of the @msg * @completion: triggered when request is done * @err: err return from the controller + * @free: the request object to be freed at tx_done */ struct rpmh_request { struct tcs_request msg; @@ -66,6 +68,7 @@ struct rpmh_request { struct completion *completion; struct rpmh_client *rc; int err; + struct rpmh_request *free; }; /** @@ -110,6 +113,8 @@ void rpmh_tx_done(const struct tcs_request *msg, int r) "RPMH TX fail in msg addr=%#x, err=%d\n", rpm_msg->msg.cmds[0].addr, r); + kfree(rpm_msg->free); + /* Signal the blocking thread we are done */ if (compl) complete(compl); @@ -255,6 +260,54 @@ static int __rpmh_write(struct rpmh_client *rc, enum rpmh_state state, return ret; } +static struct rpmh_request *__get_rpmh_msg_async(struct rpmh_client *rc, + enum rpmh_state state, + const struct tcs_cmd *cmd, + u32 n) +{ + struct rpmh_request *req; + + if (IS_ERR_OR_NULL(rc) || !cmd || !n || n > MAX_RPMH_PAYLOAD) + return ERR_PTR(-EINVAL); + + req = kzalloc(sizeof(*req), GFP_ATOMIC); + if (!req) + return ERR_PTR(-ENOMEM); + + memcpy(req->cmd, cmd, n * sizeof(*cmd)); + + req->msg.state = state; + req->msg.cmds = req->cmd; + req->msg.num_cmds = n; + req->free = req; + + return req; +} + +/** + * rpmh_write_async: Write a set of RPMH commands + * + * @rc: The RPMh handle got from rpmh_get_client + * @state: Active/sleep set + * @cmd: The payload data + * @n: The number of elements in payload + * + * Write a set of RPMH commands, the order of commands is maintained + * and will be sent as a single shot. + */ +int rpmh_write_async(struct rpmh_client *rc, enum rpmh_state state, + const struct tcs_cmd *cmd, u32 n) +{ + struct rpmh_request *rpm_msg; + + rpm_msg = __get_rpmh_msg_async(rc, state, cmd, n); + if (IS_ERR(rpm_msg)) + return PTR_ERR(rpm_msg); + + return __rpmh_write(rc, state, rpm_msg); +} +EXPORT_SYMBOL(rpmh_write_async); + /** * rpmh_write: Write a set of RPMH commands and block until response * diff --git a/include/soc/qcom/rpmh.h b/include/soc/qcom/rpmh.h index 41a2518c46a5..9e6de09e43f0 100644 --- a/include/soc/qcom/rpmh.h +++ b/include/soc/qcom/rpmh.h @@ -15,6 +15,9 @@ struct rpmh_client; int rpmh_write(struct rpmh_client *rc, enum rpmh_state state, const struct tcs_cmd *cmd, u32 n); +int rpmh_write_async(struct rpmh_client *rc, enum rpmh_state state, + const struct tcs_cmd *cmd, u32 n); + struct rpmh_client *rpmh_get_client(struct platform_device *pdev); int rpmh_flush(struct rpmh_client *rc); @@ -32,6 +35,11 @@ static inline int rpmh_write(struct rpmh_client *rc, enum rpmh_state state, static inline struct rpmh_client *rpmh_get_client(struct platform_device *pdev) { return ERR_PTR(-ENODEV); } +static inline int rpmh_write_async(struct rpmh_client *rc, + enum rpmh_state state, + const struct tcs_cmd *cmd, u32 n) +{ return -ENODEV; } + static inline int rpmh_flush(struct rpmh_client *rc) { return -ENODEV; } -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project