From patchwork Tue Feb 13 20:40:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Mayer X-Patchwork-Id: 10217573 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 802E96055C for ; Tue, 13 Feb 2018 20:42:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6DB9F286B9 for ; Tue, 13 Feb 2018 20:42:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6204B286CD; Tue, 13 Feb 2018 20:42:52 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.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 D5028286B9 for ; Tue, 13 Feb 2018 20:42:51 +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=m/nkOfmzp0/qMOnvNKopUk+tmuPlS2Sjs9QBquZMHw4=; b=BG0SxOCdIMMkMYfk0/q7in7dEf nYd/1ofpC7THVPyzKuDW0AGO9F20Up7uokhyKRJnVESGe3xf/WRrjGdD1Tmp/mROw1zNye0myUBsZ uWwbt1h+dthK+DWGe3Kg9dYKAttLJaRh6HmbeSqPxVAtpPcNewTXsx73jcA6K5ezynWQ4mnenap0P xPJlK4+l+q2COn3SEjWxrvP/URQgYtFS2Ba5m7r1pPnX9AUPD79e+l27HbEjWT6It9+yIwLX1MwZs Bn8Y42VroeGWUllbLlUd60QkJ8dPpxXMDa4Yz3AINpe0CorXFkGUkIxDLviApI6P7oRYnMiXlG2Kx qtD2ZwAQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1elhPQ-0001pB-Sb; Tue, 13 Feb 2018 20:42:36 +0000 Received: from mail-qk0-x241.google.com ([2607:f8b0:400d:c09::241]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1elhOw-0001GG-Il for linux-arm-kernel@lists.infradead.org; Tue, 13 Feb 2018 20:42:15 +0000 Received: by mail-qk0-x241.google.com with SMTP id c82so24053505qka.0 for ; Tue, 13 Feb 2018 12:41:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=DOfes+RPwDHBf57BUv+uXRl33Nzx4HkgRS+0d6esVKk=; b=DObPFoPHmasTzvkAmrpKClU+I+AEYoSszWIW63x/WMx2HnsFcA9q+i/h+m9bx1904j 7y6SLVtPRJxNKFhvlVCJywUaJqqlc/ToOZV9Sm2ACLrJWzTJAqaMScfOMC9ySWrf5ven hbJl+ymG9Q6YIdsVrrqIs4d09+N/W4RITIafc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=DOfes+RPwDHBf57BUv+uXRl33Nzx4HkgRS+0d6esVKk=; b=fM2tENRNNOWvgvgAeNjFT22iFa+SAhQbN7wSZfCK/mseHno1w9+Wy8mUue/nWZ8vez GaHQV1h6QRCtCJmFsnRIBFPC1FCF9kBfNOUZ6pfvQVbtwkkVqlVcket/BJlZBysmUVaX eQnZcEuY+UkbKLUe3fYIVbWFfSjBgMZzMiR8e5p6YOppfU+eVBHoFF5e+dFKOd1GUSXt MkXB5hi8KMYmv/ORs/8xwft1aNozXxgRd9ziKuwP1KjNOX2PenPdsHuylsppZi7MvMzK KBnhyrXNSw3viHtOcMU55Tl7Cxq6idrLUgvOe6SvgJzvCYeJz6Mgl/phhwfHlB/gkZjT DqjA== X-Gm-Message-State: APf1xPCqGu1I6JiYGGDE8tuxT0IXQhMlJWyEOTa7+WpkVvox/JslBa/X pRV0kk49p6oWMGcaFuS40MFb2Q== X-Google-Smtp-Source: AH8x227c6kjLhFTbRv83mDVRx+s7XFfz5blsppj4CbyjHGEciI78fHcTxsGE98YmzyPpeTFz3AbSTw== X-Received: by 10.55.49.74 with SMTP id x71mr4072114qkx.133.1518554515481; Tue, 13 Feb 2018 12:41:55 -0800 (PST) Received: from lbrmn-mmayer.igp.broadcom.net ([192.19.224.250]) by smtp.gmail.com with ESMTPSA id m28sm2907978qtc.65.2018.02.13.12.41.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 13 Feb 2018 12:41:55 -0800 (PST) From: Markus Mayer To: Brian Norris , Florian Fainelli , Gregory Fong Subject: [PATCH 3/3] memory: brcmstb: dpfe: support new way of passing data from the DCPU Date: Tue, 13 Feb 2018 12:40:40 -0800 Message-Id: <1518554440-21805-4-git-send-email-mmayer@broadcom.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1518554440-21805-1-git-send-email-mmayer@broadcom.com> References: <1518554440-21805-1-git-send-email-mmayer@broadcom.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180213_124207_036564_D9CA5679 X-CRM114-Status: GOOD ( 17.28 ) 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: Broadcom Kernel List , ARM Kernel List , Markus Mayer , Linux Kernel Mailing List 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 The DCPU can now send message data in two ways: - via the data RAM, as before (this is now message type 0) - via the message RAM (this is message type 1) In order to support both methods, we check the message type of the response (bits 31:28) and then treat the offset (bits 27:0) accordingly. Signed-off-by: Markus Mayer --- drivers/memory/brcmstb_dpfe.c | 65 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 55 insertions(+), 10 deletions(-) diff --git a/drivers/memory/brcmstb_dpfe.c b/drivers/memory/brcmstb_dpfe.c index 2013a91217a9..e9c1485c32b9 100644 --- a/drivers/memory/brcmstb_dpfe.c +++ b/drivers/memory/brcmstb_dpfe.c @@ -45,8 +45,16 @@ #define REG_TO_DCPU_MBOX 0x10 #define REG_TO_HOST_MBOX 0x14 +/* Macros to process offsets returned by the DCPU */ +#define DRAM_MSG_ADDR_OFFSET 0x0 +#define DRAM_MSG_TYPE_OFFSET 0x1c +#define DRAM_MSG_ADDR_MASK ((1UL << DRAM_MSG_TYPE_OFFSET) - 1) +#define DRAM_MSG_TYPE_MASK ((1UL << \ + (BITS_PER_LONG - DRAM_MSG_TYPE_OFFSET)) - 1) + /* Message RAM */ -#define DCPU_MSG_RAM(x) (0x100 + (x) * sizeof(u32)) +#define DCPU_MSG_RAM_START 0x100 +#define DCPU_MSG_RAM(x) (DCPU_MSG_RAM_START + (x) * sizeof(u32)) /* DRAM Info Offsets & Masks */ #define DRAM_INFO_INTERVAL 0x0 @@ -255,6 +263,40 @@ static unsigned int get_msg_chksum(const u32 msg[]) return sum; } +static void __iomem *get_msg_ptr(struct private_data *priv, u32 response, + char *buf, ssize_t *size) +{ + unsigned int msg_type; + unsigned int offset; + void __iomem *ptr = NULL; + + msg_type = (response >> DRAM_MSG_TYPE_OFFSET) & DRAM_MSG_TYPE_MASK; + offset = (response >> DRAM_MSG_ADDR_OFFSET) & DRAM_MSG_ADDR_MASK; + + /* + * msg_type == 1: the offset is relative to the message RAM + * msg_type == 0: the offset is relative to the data RAM (this is the + * previous way of passing data) + * msg_type is anything else: there's critical hardware problem + */ + switch (msg_type) { + case 1: + ptr = priv->regs + DCPU_MSG_RAM_START + offset; + break; + case 0: + ptr = priv->dmem + offset; + break; + default: + dev_emerg(priv->dev, "invalid message reply from DCPU: %#x\n", + response); + if (buf && size) + *size = sprintf(buf, + "FATAL: communication error with DCPU\n"); + } + + return ptr; +} + static int __send_command(struct private_data *priv, unsigned int cmd, u32 result[]) { @@ -528,7 +570,6 @@ static ssize_t show_refresh(struct device *dev, u32 response[MSG_FIELD_MAX]; void __iomem *info; struct private_data *priv; - unsigned int offset; u8 refresh, sr_abort, ppre, thermal_offs, tuf; u32 mr4; ssize_t ret; @@ -538,8 +579,10 @@ static ssize_t show_refresh(struct device *dev, return ret; priv = dev_get_drvdata(dev); - offset = response[MSG_ARG0]; - info = priv->dmem + offset; + + info = get_msg_ptr(priv, response[MSG_ARG0], buf, &ret); + if (!info) + return ret; mr4 = readl_relaxed(info + DRAM_INFO_MR4) & DRAM_INFO_MR4_MASK; @@ -561,7 +604,6 @@ static ssize_t store_refresh(struct device *dev, struct device_attribute *attr, u32 response[MSG_FIELD_MAX]; struct private_data *priv; void __iomem *info; - unsigned int offset; unsigned long val; int ret; @@ -574,8 +616,10 @@ static ssize_t store_refresh(struct device *dev, struct device_attribute *attr, if (ret) return ret; - offset = response[MSG_ARG0]; - info = priv->dmem + offset; + info = get_msg_ptr(priv, response[MSG_ARG0], NULL, NULL); + if (!info) + return -EIO; + writel_relaxed(val, info + DRAM_INFO_INTERVAL); return count; @@ -587,16 +631,17 @@ static ssize_t show_vendor(struct device *dev, struct device_attribute *devattr, u32 response[MSG_FIELD_MAX]; struct private_data *priv; void __iomem *info; - unsigned int offset; ssize_t ret; ret = generic_show(DPFE_CMD_GET_VENDOR, response, dev, buf); if (ret) return ret; - offset = response[MSG_ARG0]; priv = dev_get_drvdata(dev); - info = priv->dmem + offset; + + info = get_msg_ptr(priv, response[MSG_ARG0], buf, &ret); + if (!info) + return ret; return sprintf(buf, "%#x %#x %#x %#x %#x\n", readl_relaxed(info + DRAM_VENDOR_MR5) & DRAM_VENDOR_MASK,