From patchwork Mon Jul 2 11:40:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikko Perttunen X-Patchwork-Id: 10501193 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 67C1660362 for ; Mon, 2 Jul 2018 11:42:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 553D8287DB for ; Mon, 2 Jul 2018 11:42:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4944C287ED; Mon, 2 Jul 2018 11:42:27 +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.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=ham 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 80ABD287DB for ; Mon, 2 Jul 2018 11:42:26 +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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=siunjkKyub3GbXO0UidQcOY/Hyhtwj+EDGqe0kU4piQ=; b=KOUPTYXT77fWJO qheBqX/TZsLOEF6YKICip58eimaXiiY8nS3TyBFqmTNXOWrKXgWX1JISfayD+TVlSap0GfXv96KFx UUthzTolq0jrdPxc2zN5VRqAFtGyMfFIuUG7WzEHjCXcey+wnx/JpejyPdC8JIzVF4MovzQZYN7QX V6XGxOYvBntTZjTrEMh47ICQ7edWYQ6Qcq5eOuMih7W+BcdPjI08LxAr+9/DauKOaZYjvgLofrSaQ yxCfKeBW5djFn6alNVxGsMEu0f11BAAIyvCPyU+aP9wH3zVJQ0Qd59AZQVDqcoruvhIsAteJBOUW1 i1ya8YG0PNPwEkhawp/A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fZxDm-00014p-Cv; Mon, 02 Jul 2018 11:42:18 +0000 Received: from hqemgate15.nvidia.com ([216.228.121.64]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fZxDJ-0000oz-2x for linux-arm-kernel@lists.infradead.org; Mon, 02 Jul 2018 11:41:56 +0000 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqemgate15.nvidia.com (using TLS: TLSv1, AES128-SHA) id ; Mon, 02 Jul 2018 04:41:13 -0700 Received: from HQMAIL105.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Mon, 02 Jul 2018 04:41:47 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Mon, 02 Jul 2018 04:41:47 -0700 Received: from HQMAIL110.nvidia.com (172.18.146.15) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Mon, 2 Jul 2018 11:41:47 +0000 Received: from HQMAIL101.nvidia.com (172.20.187.10) by hqmail110.nvidia.com (172.18.146.15) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Mon, 2 Jul 2018 11:41:47 +0000 Received: from hqnvemgw01.nvidia.com (172.20.150.20) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1347.2 via Frontend Transport; Mon, 2 Jul 2018 11:41:47 +0000 Received: from mperttunen-lnx.Nvidia.com (Not Verified[10.21.26.144]) by hqnvemgw01.nvidia.com with Trustwave SEG (v7, 5, 8, 10121) id ; Mon, 02 Jul 2018 04:41:46 -0700 From: Mikko Perttunen To: , , , Subject: [PATCH v3 4/8] mailbox: tegra-hsp: Refactor in preparation of mailboxes Date: Mon, 2 Jul 2018 14:40:29 +0300 Message-ID: <20180702114033.15654-5-mperttunen@nvidia.com> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180702114033.15654-1-mperttunen@nvidia.com> References: <20180702114033.15654-1-mperttunen@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180702_044149_293087_5733FECA X-CRM114-Status: GOOD ( 16.05 ) 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: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Mikko Perttunen , linux-serial@vger.kernel.org, linux-tegra@vger.kernel.org, linux-arm-kernel@lists.infradead.org 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 HSP driver is currently in many places written with the assumption of only supporting doorbells. Prepare for the addition of shared mailbox support by removing these assumptions and cleaning up the code. Signed-off-by: Mikko Perttunen Reviewed-by: Jon Hunter Acked-by: Thierry Reding --- Notes: v2: - Moved fixes for some style and other issues from the next patch here, where they belong. v3: - Added Jon's Reviewed-by. drivers/mailbox/tegra-hsp.c | 123 +++++++++++++++++++++++++++++--------------- 1 file changed, 81 insertions(+), 42 deletions(-) diff --git a/drivers/mailbox/tegra-hsp.c b/drivers/mailbox/tegra-hsp.c index 0cde356c11ab..5dc21a6d01bb 100644 --- a/drivers/mailbox/tegra-hsp.c +++ b/drivers/mailbox/tegra-hsp.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2016-2018, NVIDIA CORPORATION. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -42,6 +42,7 @@ struct tegra_hsp_channel; struct tegra_hsp; struct tegra_hsp_channel { + unsigned int type; struct tegra_hsp *hsp; struct mbox_chan *chan; void __iomem *regs; @@ -55,6 +56,12 @@ struct tegra_hsp_doorbell { unsigned int index; }; +static inline struct tegra_hsp_doorbell * +channel_to_doorbell(struct tegra_hsp_channel *channel) +{ + return container_of(channel, struct tegra_hsp_doorbell, channel); +} + struct tegra_hsp_db_map { const char *name; unsigned int master; @@ -69,7 +76,7 @@ struct tegra_hsp { const struct tegra_hsp_soc *soc; struct mbox_controller mbox; void __iomem *regs; - unsigned int irq; + unsigned int doorbell_irq; unsigned int num_sm; unsigned int num_as; unsigned int num_ss; @@ -194,7 +201,7 @@ tegra_hsp_doorbell_create(struct tegra_hsp *hsp, const char *name, if (!db) return ERR_PTR(-ENOMEM); - offset = (1 + (hsp->num_sm / 2) + hsp->num_ss + hsp->num_as) << 16; + offset = (1 + (hsp->num_sm / 2) + hsp->num_ss + hsp->num_as) * SZ_64K; offset += index * 0x100; db->channel.regs = hsp->regs + offset; @@ -218,18 +225,8 @@ static void __tegra_hsp_doorbell_destroy(struct tegra_hsp_doorbell *db) kfree(db); } -static int tegra_hsp_doorbell_send_data(struct mbox_chan *chan, void *data) -{ - struct tegra_hsp_doorbell *db = chan->con_priv; - - tegra_hsp_channel_writel(&db->channel, 1, HSP_DB_TRIGGER); - - return 0; -} - -static int tegra_hsp_doorbell_startup(struct mbox_chan *chan) +static int tegra_hsp_doorbell_startup(struct tegra_hsp_doorbell *db) { - struct tegra_hsp_doorbell *db = chan->con_priv; struct tegra_hsp *hsp = db->channel.hsp; struct tegra_hsp_doorbell *ccplex; unsigned long flags; @@ -260,9 +257,8 @@ static int tegra_hsp_doorbell_startup(struct mbox_chan *chan) return 0; } -static void tegra_hsp_doorbell_shutdown(struct mbox_chan *chan) +static void tegra_hsp_doorbell_shutdown(struct tegra_hsp_doorbell *db) { - struct tegra_hsp_doorbell *db = chan->con_priv; struct tegra_hsp *hsp = db->channel.hsp; struct tegra_hsp_doorbell *ccplex; unsigned long flags; @@ -281,35 +277,60 @@ static void tegra_hsp_doorbell_shutdown(struct mbox_chan *chan) spin_unlock_irqrestore(&hsp->lock, flags); } -static const struct mbox_chan_ops tegra_hsp_doorbell_ops = { - .send_data = tegra_hsp_doorbell_send_data, - .startup = tegra_hsp_doorbell_startup, - .shutdown = tegra_hsp_doorbell_shutdown, +static int tegra_hsp_send_data(struct mbox_chan *chan, void *data) +{ + struct tegra_hsp_channel *channel = chan->con_priv; + + switch (channel->type) { + case TEGRA_HSP_MBOX_TYPE_DB: + tegra_hsp_channel_writel(channel, 1, HSP_DB_TRIGGER); + return 0; + } + + return -EINVAL; +} + +static int tegra_hsp_startup(struct mbox_chan *chan) +{ + struct tegra_hsp_channel *channel = chan->con_priv; + + switch (channel->type) { + case TEGRA_HSP_MBOX_TYPE_DB: + return tegra_hsp_doorbell_startup(channel_to_doorbell(channel)); + } + + return -EINVAL; +} + +static void tegra_hsp_shutdown(struct mbox_chan *chan) +{ + struct tegra_hsp_channel *channel = chan->con_priv; + + switch (channel->type) { + case TEGRA_HSP_MBOX_TYPE_DB: + tegra_hsp_doorbell_shutdown(channel_to_doorbell(channel)); + break; + } +} + +static const struct mbox_chan_ops tegra_hsp_ops = { + .send_data = tegra_hsp_send_data, + .startup = tegra_hsp_startup, + .shutdown = tegra_hsp_shutdown, }; -static struct mbox_chan *of_tegra_hsp_xlate(struct mbox_controller *mbox, - const struct of_phandle_args *args) +static struct mbox_chan *tegra_hsp_doorbell_xlate(struct tegra_hsp *hsp, + unsigned int master) { struct tegra_hsp_channel *channel = ERR_PTR(-ENODEV); - struct tegra_hsp *hsp = to_tegra_hsp(mbox); - unsigned int type = args->args[0]; - unsigned int master = args->args[1]; struct tegra_hsp_doorbell *db; struct mbox_chan *chan; unsigned long flags; unsigned int i; - switch (type) { - case TEGRA_HSP_MBOX_TYPE_DB: - db = tegra_hsp_doorbell_get(hsp, master); - if (db) - channel = &db->channel; - - break; - - default: - break; - } + db = tegra_hsp_doorbell_get(hsp, master); + if (db) + channel = &db->channel; if (IS_ERR(channel)) return ERR_CAST(channel); @@ -321,6 +342,7 @@ static struct mbox_chan *of_tegra_hsp_xlate(struct mbox_controller *mbox, if (!chan->con_priv) { chan->con_priv = channel; channel->chan = chan; + channel->type = TEGRA_HSP_MBOX_TYPE_DB; break; } @@ -332,6 +354,22 @@ static struct mbox_chan *of_tegra_hsp_xlate(struct mbox_controller *mbox, return chan ?: ERR_PTR(-EBUSY); } +static struct mbox_chan *of_tegra_hsp_xlate(struct mbox_controller *mbox, + const struct of_phandle_args *args) +{ + struct tegra_hsp *hsp = to_tegra_hsp(mbox); + unsigned int type = args->args[0]; + unsigned int param = args->args[1]; + + switch (type) { + case TEGRA_HSP_MBOX_TYPE_DB: + return tegra_hsp_doorbell_xlate(hsp, param); + + default: + return ERR_PTR(-EINVAL); + } +} + static void tegra_hsp_remove_doorbells(struct tegra_hsp *hsp) { struct tegra_hsp_doorbell *db, *tmp; @@ -397,14 +435,14 @@ static int tegra_hsp_probe(struct platform_device *pdev) return err; } - hsp->irq = err; + hsp->doorbell_irq = err; hsp->mbox.of_xlate = of_tegra_hsp_xlate; hsp->mbox.num_chans = 32; hsp->mbox.dev = &pdev->dev; hsp->mbox.txdone_irq = false; hsp->mbox.txdone_poll = false; - hsp->mbox.ops = &tegra_hsp_doorbell_ops; + hsp->mbox.ops = &tegra_hsp_ops; hsp->mbox.chans = devm_kcalloc(&pdev->dev, hsp->mbox.num_chans, sizeof(*hsp->mbox.chans), @@ -427,11 +465,12 @@ static int tegra_hsp_probe(struct platform_device *pdev) return err; } - err = devm_request_irq(&pdev->dev, hsp->irq, tegra_hsp_doorbell_irq, - IRQF_NO_SUSPEND, dev_name(&pdev->dev), hsp); + err = devm_request_irq(&pdev->dev, hsp->doorbell_irq, + tegra_hsp_doorbell_irq, IRQF_NO_SUSPEND, + dev_name(&pdev->dev), hsp); if (err < 0) { - dev_err(&pdev->dev, "failed to request IRQ#%u: %d\n", - hsp->irq, err); + dev_err(&pdev->dev, "failed to request doorbell IRQ#%u: %d\n", + hsp->doorbell_irq, err); return err; }