From patchwork Wed Aug 16 17:18:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sricharan Ramabadhran X-Patchwork-Id: 9904511 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 BC0186038C for ; Wed, 16 Aug 2017 18:51:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AD6B528A4D for ; Wed, 16 Aug 2017 18:51:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A233128A4F; Wed, 16 Aug 2017 18:51:34 +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 22C2228A4D for ; Wed, 16 Aug 2017 18:51:33 +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=z/5cT8MF4WHKwzXbaH2OIp9bfWRDUjBCeOjq542ffr4=; b=WncQaeycZZg22PUA+HjDxciAi4 m52AhcJTbLPGNbkMbojek/dUmhW8gWAzPj6BJ6zujJm5ycLtjb1jtHJMZcDnhvqum6P3N7TmhgC6O NUtFLFpjfdd8h1WwFVx76CVFFbZD4WrkCttU3dDbEYT0EU1EyQey4RPbdQzkMZIvcxjCTYbblVv3W ombJS8kU+ZfphhFK5lS2N3lPOusX0itiIJTx1QRaVeD33rD52DkXDyEzn3hD2O2SxySmfExr5DnBj 5LomcKJMNU/95B3vO+9ZU0GGGLBdxKLgx0BZnOa4o7CNpqMirgdI9weUlymDu9XwS7abk9oLfYoav G8+nFXCQ==; 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 1di3PX-00070X-6P; Wed, 16 Aug 2017 18:51:23 +0000 Received: from merlin.infradead.org ([205.233.59.134]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1di3PV-00070R-9k for linux-arm-kernel@bombadil.infradead.org; Wed, 16 Aug 2017 18:51:21 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=ZQbsV1Gnl2dUNNOQ8qF7y0yQUn568Bwf7HQj9cyXgGc=; b=V5HsjTywBYtusyzJR/W5QUx/r QAB21TVmb2hFrfde2HjDTfRPsmqzGsWerxGRyoIqxlsLAJZFKXgt1RPtEazgn3TgYy9R8jtI4x7Ca slUsKsoRCrsC/WTuHYB8/Z37l9sDyJHq+lsvKRt0X60pJA2JF/hU7qVtdy8hu5m79m2HjZ9SYF4ll RmkcS2Y+YCiyTzShCDSNwfcxWh5dx0gyOLMqg7Wd/EMs1kEMv5Bkc5GDFTLGj069kWx029hDbt/f6 HTA9xU1q7qFyzpAxkoShJANGw2tI1wa9KuP23GP0yKhe3dHBrX7yonPwyYUp8BAZwC73Eu64uoWC9 Hli5u1H4w==; Received: from smtp.codeaurora.org ([198.145.29.96]) by merlin.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1di1zH-0005aW-9J for linux-arm-kernel@lists.infradead.org; Wed, 16 Aug 2017 17:20:12 +0000 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 3F47560708; Wed, 16 Aug 2017 17:19:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1502903991; bh=o1jj8dkET8+SXLJ2x8jXeKjbKkB1fWvz9RW/5fZ//9M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Gh8GMoBX5ceHUEoG+VpCrgbTYJPvNdzfdqtCb8HpML2h1cheE7pktJd2CKb3TvQmh 00ZiscDPQn6KZlWGMy5UE9MIurzzsndmR4xNOe5kdfXP62UJbeqRGlFvgAnyvJgLbD I9H7iQpE/Eon/YWbFvEJCCtccicQMroq8P94Uz8g= 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 8CBC660766; Wed, 16 Aug 2017 17:19:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1502903983; bh=o1jj8dkET8+SXLJ2x8jXeKjbKkB1fWvz9RW/5fZ//9M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IfZHq43lQliyw5WaXkHDdwIt5CBDwCQ9NN97WSOGgIj5pDVZM6/VHabDEE1dHOnxI hLg0g1tbcyMiCaVqwGjBReaBp/y37a/P5WxoA/a2BwUyHbOlExxhDk6vFbIDsW+0Rp aOj4Syc2FfYpCKwh8AJ7vO5ffjBkbQnPDM8aVVZo= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 8CBC660766 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 05/18] rpmsg: glink: Allow unaligned data access Date: Wed, 16 Aug 2017 22:48:58 +0530 Message-Id: <1502903951-5403-6-git-send-email-sricharan@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1502903951-5403-1-git-send-email-sricharan@codeaurora.org> References: <1502903951-5403-1-git-send-email-sricharan@codeaurora.org> 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 --- 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 04afbb2..1aa92daf 100644 --- a/drivers/rpmsg/qcom_glink_native.c +++ b/drivers/rpmsg/qcom_glink_native.c @@ -226,9 +226,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; @@ -694,9 +691,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); }