Received: by 10.223.185.116 with SMTP id b49csp4097680wrg; Tue, 13 Feb 2018 12:43:40 -0800 (PST) X-Google-Smtp-Source: AH8x227oETLNkTCwtNlmoRwX4WObsF+Iu6SMI0ARbfukTgtf1PS/89hFSdNV+7cM7F6wCEGZ/As3 X-Received: by 10.98.238.2 with SMTP id e2mr2452921pfi.206.1518554620464; Tue, 13 Feb 2018 12:43:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518554620; cv=none; d=google.com; s=arc-20160816; b=K3iZy8YlJq+Tbonm5cZCMUmVxJN+8wahov/9XmgH8SrmbpHHieW0BknFY21CMLdrD6 JWzardd0KSRyME0te64PPSJLYxCPaLCWQ8oR9wpb6Elkw7Qk8ryfEdC3N3mrsIFTV3Zd yjxBMPbHewWEuLoi/VlpnrG0M8DZbrb9gCTGc81eeKLWrMody8X+pNEMakojMub1cjWV o/NALZrpA1sTOcC/g92yKkuYwULqrXrhSz5G1SZ/3VBdJDb+hzTXqgtKdIFfL6XWufjj Qdlfhy+R2bDK0hc0ZH0IjiKerr6ZlCWYkfZz/eoyQw5P64T+BrswwTrt8MDHS/j6vwgf Hlbg== 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:dkim-signature:arc-authentication-results; bh=DOfes+RPwDHBf57BUv+uXRl33Nzx4HkgRS+0d6esVKk=; b=eirglE76MycyzrVGpfdoY8mEzZqomJKxJN6u1dOp/HnwhXUcTihr1sR8X5kjIEiTtS YYA8aDDXjTOrfhPEu5nzWBQ8eEiX0tMdoT/g2KBeICIN3ID6C9pDiqW3o5ElSnBVfqzS qArYkOVkBzrN7udcxmQWLs3to8GVHx+O/a/0oSYtoj9H5HaAW+shFWmHm5NNsDIqZQkh PN/trE01EYYp2evh1aUEYbb/qoQcWL7QwbJCFM23QeVUEen5cWMZUBAcbkUBkB4PnoON CADJx4zYpOTDXj0Ll+PfPTi7ncA1N2nC29ZuHkrNjx1uepGfq31Kqne1OwFTVxNf8CxM ReiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=DObPFoPH; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b3si1591516pgc.496.2018.02.13.12.43.26; Tue, 13 Feb 2018 12:43:40 -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=@broadcom.com header.s=google header.b=DObPFoPH; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965857AbeBMUl5 (ORCPT + 99 others); Tue, 13 Feb 2018 15:41:57 -0500 Received: from mail-qk0-f194.google.com ([209.85.220.194]:37361 "EHLO mail-qk0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752344AbeBMUl4 (ORCPT ); Tue, 13 Feb 2018 15:41:56 -0500 Received: by mail-qk0-f194.google.com with SMTP id c128so24047370qkb.4 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=spTrNPdBQ+2KYCIpYU/RqyXGFMWyNphIYZskLwBP0rrVCde4R6iXwlbaO/Hsg3Lyex 2TtmkOt7y/iR3LuoyDE9RuiF2s4obhjxLY5qySF67UTN5V21VpkV3CV9CDH439oSLT3m /cqmiPAD4o0oewD+EWzVFbVKAGw3cwHpsA0HR0ZwoElYvIDKAFy3LdI/IcQHErRsNK3a ys6DE3RzNoDDyPYkxh0mUpyP9oUb6YworVOBMVUrliijKFocZxYqb1EGZR188gRkNaaM K5fTE8mreSTyBBVDHYwhJDj/5CcOjhrMJjm0n9TuwbCEd+zvvK7Pgj/Z1ng/oG2+5mLh 5Srw== X-Gm-Message-State: APf1xPBvLnF6b1zCHL3snLoOPFdFgljENHr4xUqboIPmI/GQ/oLh4lHF s9IHn19/oMeSgUmWVOj0Fng88A== 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 Cc: Markus Mayer , Broadcom Kernel List , ARM Kernel List , Linux Kernel Mailing List 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> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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, -- 2.7.4