From patchwork Thu Aug 24 07:21:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sricharan Ramabadhran X-Patchwork-Id: 9919183 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1CF8460353 for ; Thu, 24 Aug 2017 07:23:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0B57528434 for ; Thu, 24 Aug 2017 07:23:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F0F1328880; Thu, 24 Aug 2017 07:23:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7C92F28434 for ; Thu, 24 Aug 2017 07:23:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=sF1od9zZ+/jjNCE2UmWHqmRcX9dWIwJSX50SwlqRxzA=; b=ke+/q8UHxVRBa0gPGuXfYxkkGm 2qeHKilkdz6lotc5opFgHhsFNPfvDZdccXDQWHqRgLbb8jl94NJy1iPueMlqARZq9is5QXSlwCP2I NkCvybYgWOLEdaGXYs7Y13xMUZHik4KDOCl75ZO/Arha/AYCICmF6lF2w3GSJPVlEdu5t7lMWrkFb 6ukGNkOZKDwDoC89x4BV8Cx8jMmAFIyAlqlvYpK7rLnUcoIBbBEqq7KJ6XoRBUsEh0rmgPBhHe0Hh Jl3usAQsPh+5kIP9D+SW1+MwLp3KDYfdep370E0P8oX0QYDpKygHOdMfyARyf0Pzhnxk9Nbr5QFKs u6zT5N5Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dkmUX-0000rd-AM; Thu, 24 Aug 2017 07:23:49 +0000 Received: from smtp.codeaurora.org ([198.145.29.96]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dkmTI-00088s-Lo for linux-arm-kernel@lists.infradead.org; Thu, 24 Aug 2017 07:22:38 +0000 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 6197E60726; Thu, 24 Aug 2017 07:22:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1503559332; bh=F5wuKVAc22GDS+S7y7cf4o0UspSuXC6XE0TsBgF+h6Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=H5XsU7+0Nj5489eA5hZ3wM90YrguaKstInOfkc7Q6WTuwcGbosU/n7PO/H5N4OjrB h7jCw5BqINohHfS/xOwIy3FjvHXPVeOEo6oWO0Sn2qcC+1CmHGvF3X0SzFFy2Wt7IC MlSp0iXAIhpPhi68NiXsFtwtXkSmD4IrpZrcCMt8= Received: from srichara-linux.qualcomm.com (blr-c-bdr-fw-01_globalnat_allzones-outside.qualcomm.com [103.229.19.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: sricharan@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 431996071D; Thu, 24 Aug 2017 07:22:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1503559330; bh=F5wuKVAc22GDS+S7y7cf4o0UspSuXC6XE0TsBgF+h6Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bxPc2jNzAiklWZbN8vFiScZfxIqFuH+o4izfD9WdDZgAUSaikfApN0q+aGm1D87ZA Y+wZy5g+SjKUhkj7y26lpC+lt+iN4WTkuvOB9cWghVGHYr/ma2onv7kBX9wmaUKsPZ Da9InJMGJsYTLkKiYjr1VV/vgLogwTG0HqUVDq2Q= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 431996071D 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=sricharan@codeaurora.org From: Sricharan R To: ohad@wizery.com, bjorn.andersson@linaro.org, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 05/20] rpmsg: glink: Allow unaligned data access Date: Thu, 24 Aug 2017 12:51:27 +0530 Message-Id: <1503559302-3744-6-git-send-email-sricharan@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1503559302-3744-1-git-send-email-sricharan@codeaurora.org> References: <1503559302-3744-1-git-send-email-sricharan@codeaurora.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170824_002233_214754_858D35EC X-CRM114-Status: GOOD ( 14.30 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: sricharan@codeaurora.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Bjorn Andersson Glink protocol requires that each message is aligned on a 8 byte offset. This is purely a restriction from glink, so in order to support clients which do not adher to this, allow data packets of any size, but align the head index accordingly, effectively removing the alignment restriction. Signed-off-by: Bjorn Andersson Signed-off-by: Sricharan R Acked-by: Arun Kumar Neelakantam --- drivers/rpmsg/qcom_glink_native.c | 6 ------ drivers/rpmsg/qcom_glink_rpm.c | 22 +++++++++++++++++++++- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/drivers/rpmsg/qcom_glink_native.c b/drivers/rpmsg/qcom_glink_native.c index ffdf88e..a6394cd 100644 --- a/drivers/rpmsg/qcom_glink_native.c +++ b/drivers/rpmsg/qcom_glink_native.c @@ -227,9 +227,6 @@ static int qcom_glink_tx(struct qcom_glink *glink, if (tlen >= glink->tx_pipe->length) return -EINVAL; - if (WARN(tlen % 8, "Unaligned TX request")) - return -EINVAL; - ret = mutex_lock_interruptible(&glink->tx_lock); if (ret) return ret; @@ -695,9 +692,6 @@ static int __qcom_glink_send(struct glink_channel *channel, __le32 left_size; } __packed req; - if (WARN(len % 8, "RPM GLINK expects 8 byte aligned messages\n")) - return -EINVAL; - req.msg.cmd = cpu_to_le16(RPM_CMD_TX_DATA); req.msg.param1 = cpu_to_le16(channel->lcid); req.msg.param2 = cpu_to_le32(channel->rcid); diff --git a/drivers/rpmsg/qcom_glink_rpm.c b/drivers/rpmsg/qcom_glink_rpm.c index 33daa32..cc73af0 100644 --- a/drivers/rpmsg/qcom_glink_rpm.c +++ b/drivers/rpmsg/qcom_glink_rpm.c @@ -156,11 +156,31 @@ static void glink_rpm_tx_write(struct qcom_glink_pipe *glink_pipe, const void *data, size_t dlen) { struct glink_rpm_pipe *pipe = to_rpm_pipe(glink_pipe); + size_t tlen = hlen + dlen; + size_t aligned_dlen; unsigned int head; + char padding[8] = {0}; + size_t pad; + + /* Header length comes from glink native and is always 4 byte aligned */ + if (WARN(hlen % 4, "Glink Header length must be 4 bytes aligned\n")) + return; + + /* + * Move the unaligned tail of the message to the padding chunk, to + * ensure word aligned accesses + */ + aligned_dlen = ALIGN_DOWN(dlen, 4); + if (aligned_dlen != dlen) + memcpy(padding, data + aligned_dlen, dlen - aligned_dlen); head = readl(pipe->head); head = glink_rpm_tx_write_one(pipe, head, hdr, hlen); - head = glink_rpm_tx_write_one(pipe, head, data, dlen); + head = glink_rpm_tx_write_one(pipe, head, data, aligned_dlen); + + pad = ALIGN(tlen, 8) - ALIGN_DOWN(tlen, 4); + if (pad) + head = glink_rpm_tx_write_one(pipe, head, padding, pad); writel(head, pipe->head); }