Received: by 10.223.185.116 with SMTP id b49csp533186wrg; Fri, 16 Feb 2018 03:07:44 -0800 (PST) X-Google-Smtp-Source: AH8x224aSwYWH9UfWq1QCwnBuQK6qJj3Z9dPuVltFuybZdgBqmhYwK5dsrZmry/xsg+80a5GBYcW X-Received: by 2002:a17:902:2823:: with SMTP id e32-v6mr5595495plb.44.1518779264521; Fri, 16 Feb 2018 03:07:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518779264; cv=none; d=google.com; s=arc-20160816; b=K4bxjGya+ntKtyAFriPi7yEFofsbpYXJEUXDSLuNZ24fo1OrqhZox4zXzujo7zluZo +GPPeY0D8EhLgE9t123b6pTAgp5hOSiSx45j75eEQBfhSdDfhiSBBP0S85A+nDTgRJPQ kiLA8F2N8Qv4egWiDhatGKwvLDpMlMJP7nq9saRPFMOPVm/tgmDF97F0roTVE7xRQmQm u6TFwtIV2Z/Wc4Vej9J3VVOBIQz4ytjAAPmcu+LyFnJZdeo3mxJpYMx7pBE/YFkA45kz U3lokYuodQ36pVHB8A5Fug3wxV9uIvGEhV/GuF264edRHP73J+sJBaOd+iHkdU5nkCof 7bFg== 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=ZNfxJOjXqFBXYaiZBsBIdN8iy+m4e8SCgY/ER0X/qfo=; b=cVuR0Ad7i3UbaVFx2/4dNcb2CnmraJApULpd8XpE2vMZ03ftoYAV7qqRZM6ZKFzj3t hxAf4q7kmtbKGk9+YrS0PbZJWSfCMzhMO0MzD2gEsYiDJmWpcSDDloooDivBDx2OiF6e c0G515Vj+iJHC7ahZ2nCCjaFuNM4e5JN7/U6H7YPRSHoKl8Oo3hT+5b943uyhBXLzqxe 25vfGNInR7R9S/z56DULYNO3Ow4iIoUMuL59KcHc3jywcVmcNSjs4BoU/aIRCInMKKo9 znQkz5G9ZKDaihJBOwCklEELHx0SBemkM25jSUdcoTsgN7cvi4hwTPLskhjlr+FtIj9g UxEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=o5RFzq0C; dkim=pass header.i=@codeaurora.org header.s=default header.b=o5RFzq0C; 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 w5si5245108pgs.259.2018.02.16.03.07.29; Fri, 16 Feb 2018 03:07:44 -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=o5RFzq0C; dkim=pass header.i=@codeaurora.org header.s=default header.b=o5RFzq0C; 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 S1945984AbeBORgV (ORCPT + 99 others); Thu, 15 Feb 2018 12:36:21 -0500 Received: from smtp.codeaurora.org ([198.145.29.96]:43494 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1427402AbeBORf1 (ORCPT ); Thu, 15 Feb 2018 12:35:27 -0500 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id E1A7860960; Thu, 15 Feb 2018 17:35:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1518716126; bh=/mDxE8uaR01HdHb70eUYYY39EEcS5GnqJCqnE/rzvbg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o5RFzq0CdIZWh/VLZ89DwdS7+7/kSiEuQdZefNtC5mkUnhkaT0edv6M8MG/uENAPy KW4+qz6S9ME0LZoE1Xy5SJACVs3Kzh0Ya/CJhk5Wqma9bCvZs5De3FY3bp44KL67oG cXGFRKJvX/4HZKIiAP/KSdRND2qDvQoH1tB8Otj4= 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 B24476079C; Thu, 15 Feb 2018 17:35:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1518716126; bh=/mDxE8uaR01HdHb70eUYYY39EEcS5GnqJCqnE/rzvbg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o5RFzq0CdIZWh/VLZ89DwdS7+7/kSiEuQdZefNtC5mkUnhkaT0edv6M8MG/uENAPy KW4+qz6S9ME0LZoE1Xy5SJACVs3Kzh0Ya/CJhk5Wqma9bCvZs5De3FY3bp44KL67oG cXGFRKJvX/4HZKIiAP/KSdRND2qDvQoH1tB8Otj4= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org B24476079C 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, linux-soc@vger.kernel.org Cc: rnayak@codeaurora.org, bjorn.andersson@linaro.org, linux-kernel@vger.kernel.org, Lina Iyer Subject: [PATCH v2 08/10] drivers: qcom: rpmh: allow requests to be sent asynchronously Date: Thu, 15 Feb 2018 10:35:05 -0700 Message-Id: <20180215173507.10989-9-ilina@codeaurora.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180215173507.10989-1-ilina@codeaurora.org> References: <20180215173507.10989-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 | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ include/soc/qcom/rpmh.h | 8 ++++++++ 2 files changed, 60 insertions(+) diff --git a/drivers/soc/qcom/rpmh.c b/drivers/soc/qcom/rpmh.c index 671bc03ad77a..dff4c46be3af 100644 --- a/drivers/soc/qcom/rpmh.c +++ b/drivers/soc/qcom/rpmh.c @@ -35,6 +35,7 @@ .completion = q, \ .wait_count = c, \ .rc = rc, \ + .free = NULL, \ } @@ -61,6 +62,7 @@ struct cache_req { * @completion: triggered when request is done * @wait_count: count of waiters for this completion * @err: err return from the controller + * @free: the request object to be freed at tx_done */ struct rpmh_request { struct tcs_request msg; @@ -69,6 +71,7 @@ struct rpmh_request { atomic_t *wait_count; struct rpmh_client *rc; int err; + struct rpmh_request *free; }; /** @@ -114,6 +117,8 @@ void rpmh_tx_done(struct tcs_request *msg, int r) "RPMH TX fail in msg addr 0x%x, err=%d\n", rpm_msg->msg.payload[0].addr, r); + kfree(rpm_msg->free); + /* Signal the blocking thread we are done */ if (wc && atomic_dec_and_test(wc) && compl) complete(compl); @@ -257,6 +262,53 @@ 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, + struct tcs_cmd *cmd, int n) +{ + struct rpmh_request *req; + + if (IS_ERR_OR_NULL(rc) || !cmd || n <= 0 || n > MAX_RPMH_PAYLOAD) + return ERR_PTR(-EINVAL); + + req = kcalloc(1, sizeof(*req), GFP_ATOMIC); + if (!req) + return ERR_PTR(-ENOMEM); + + memcpy(req->cmd, cmd, n * sizeof(*cmd)); + + req->msg.state = state; + req->msg.payload = req->cmd; + req->msg.num_payload = n; + req->free = req; + + return req; +} + +/** + * rpmh_write_async: Write a set of RPMH commands + * + * @rc: The RPMh handle got from rpmh_get_dev_channel + * @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, + struct tcs_cmd *cmd, int 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 a3f1246ce49a..172a649f1a1c 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, struct tcs_cmd *cmd, int n); +int rpmh_write_async(struct rpmh_client *rc, enum rpmh_state state, + struct tcs_cmd *cmd, int 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, + struct tcs_cmd *cmd, int 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