From patchwork Mon Jul 27 09:44:31 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 51498 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f199.google.com (mail-lb0-f199.google.com [209.85.217.199]) by patches.linaro.org (Postfix) with ESMTPS id D07E722918 for ; Mon, 27 Jul 2015 09:44:53 +0000 (UTC) Received: by lbcjj5 with SMTP id jj5sf25698897lbc.1 for ; Mon, 27 Jul 2015 02:44:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=xCtZcedVD8fTFzntXMh2h3+4h+xaEjue7zSl2o68tPg=; b=b1RzpD+pfQLoWdgh08WE8P4ZCO4S+M9sQ6qyulUSvYggM8jssEHYAqKyrjslkafO1f 8F66e6vpYWQyKw60gfRb/Oqb1k2iJz8gk9qacwuQn1OBr1TZRM9P5TnIodnhItxZtdkM qMM5t9KgMqEm+WWBnEhXK5uhuOo8zsaa1EKL0snWhj+EuuOVGu0HGERzeYygvSTR2Z5j 9OTE2aATHZlpQnfSboPbNEHbmG60sPKxE1YCJxm3onqcgnoTcrgtyJrzzBpnDAxVakI6 k21e0YTkQx5HAKkBYvobVeDfaRvDWZXFkpvqxlxPNTEXMr0HPsqgrjEx9XWxTW3HLbub wU7A== X-Gm-Message-State: ALoCoQlgQbw5cPhHXmLj7kqhukPdMaLF5U0X+UJuXNbU+X0s7aVtSpgRsjDLuEG95CMNQAtSW5Ax X-Received: by 10.180.35.162 with SMTP id i2mr4960051wij.6.1437990292823; Mon, 27 Jul 2015 02:44:52 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.9.232 with SMTP id d8ls630489lab.13.gmail; Mon, 27 Jul 2015 02:44:52 -0700 (PDT) X-Received: by 10.152.197.2 with SMTP id iq2mr26204339lac.103.1437990292647; Mon, 27 Jul 2015 02:44:52 -0700 (PDT) Received: from mail-la0-f46.google.com (mail-la0-f46.google.com. [209.85.215.46]) by mx.google.com with ESMTPS id ci10si14857164lad.24.2015.07.27.02.44.52 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 Jul 2015 02:44:52 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.46 as permitted sender) client-ip=209.85.215.46; Received: by laah7 with SMTP id h7so45502493laa.0 for ; Mon, 27 Jul 2015 02:44:52 -0700 (PDT) X-Received: by 10.112.219.70 with SMTP id pm6mr25612971lbc.41.1437990292461; Mon, 27 Jul 2015 02:44:52 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.7.198 with SMTP id l6csp1421788lba; Mon, 27 Jul 2015 02:44:51 -0700 (PDT) X-Received: by 10.66.116.81 with SMTP id ju17mr66772135pab.35.1437990290409; Mon, 27 Jul 2015 02:44:50 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e13si42918590pat.73.2015.07.27.02.44.49; Mon, 27 Jul 2015 02:44:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754031AbbG0Jop (ORCPT + 8 others); Mon, 27 Jul 2015 05:44:45 -0400 Received: from mail-wi0-f176.google.com ([209.85.212.176]:34313 "EHLO mail-wi0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754024AbbG0Joo (ORCPT ); Mon, 27 Jul 2015 05:44:44 -0400 Received: by wibud3 with SMTP id ud3so132191017wib.1 for ; Mon, 27 Jul 2015 02:44:43 -0700 (PDT) X-Received: by 10.194.77.97 with SMTP id r1mr50589659wjw.98.1437990283186; Mon, 27 Jul 2015 02:44:43 -0700 (PDT) Received: from localhost.localdomain (host81-129-173-55.range81-129.btcentralplus.com. [81.129.173.55]) by smtp.gmail.com with ESMTPSA id gw7sm12650522wib.15.2015.07.27.02.44.42 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 27 Jul 2015 02:44:42 -0700 (PDT) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: kernel@stlinux.com, jassisinghbrar@gmail.com, devicetree@vger.kernel.org, Lee Jones Subject: [PATCH v2 5/6] mailbox: Add generic mechanism for testing Mailbox Controllers Date: Mon, 27 Jul 2015 10:44:31 +0100 Message-Id: <1437990272-23111-6-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1437990272-23111-1-git-send-email-lee.jones@linaro.org> References: <1437990272-23111-1-git-send-email-lee.jones@linaro.org> Sender: devicetree-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: devicetree@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: lee.jones@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.46 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , This particular Client implementation uses shared memory in order to pass messages between Mailbox users; however, it can be easily hacked to support any type of Controller. Signed-off-by: Lee Jones --- drivers/mailbox/Kconfig | 7 ++ drivers/mailbox/Makefile | 2 + drivers/mailbox/mailbox-test.c | 210 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 219 insertions(+) create mode 100644 drivers/mailbox/mailbox-test.c diff --git a/drivers/mailbox/Kconfig b/drivers/mailbox/Kconfig index 2cc4c39..7720bde 100644 --- a/drivers/mailbox/Kconfig +++ b/drivers/mailbox/Kconfig @@ -77,4 +77,11 @@ config STI_MBOX Mailbox implementation for STMicroelectonics family chips with hardware for interprocessor communication. +config MAILBOX_TEST + tristate "Mailbox Test Client" + depends on OF + help + Test client to help with testing new Controller driver + implementations. + endif diff --git a/drivers/mailbox/Makefile b/drivers/mailbox/Makefile index 7cb4766..92435ef 100644 --- a/drivers/mailbox/Makefile +++ b/drivers/mailbox/Makefile @@ -2,6 +2,8 @@ obj-$(CONFIG_MAILBOX) += mailbox.o +obj-$(CONFIG_MAILBOX_TEST) += mailbox-test.o + obj-$(CONFIG_ARM_MHU) += arm_mhu.o obj-$(CONFIG_PL320_MBOX) += pl320-ipc.o diff --git a/drivers/mailbox/mailbox-test.c b/drivers/mailbox/mailbox-test.c new file mode 100644 index 0000000..10bfe3a --- /dev/null +++ b/drivers/mailbox/mailbox-test.c @@ -0,0 +1,210 @@ +/* + * Copyright (C) 2015 ST Microelectronics + * + * Author: Lee Jones + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define MBOX_MAX_MSG_LEN 128 + +static struct dentry *root_debugfs_dir; + +struct mbox_test_device { + struct device *dev; + struct mbox_chan *tx_channel; + struct mbox_chan *rx_channel; + void __iomem *mmio; + +}; + +static ssize_t mbox_test_write(struct file *filp, + const char __user *userbuf, + size_t count, loff_t *ppos) +{ + struct mbox_test_device *tdev = filp->private_data; + char *message; + int ret; + + if (count > MBOX_MAX_MSG_LEN) { + dev_err(tdev->dev, + "Message length %d greater than max allowed %d\n", + count, MBOX_MAX_MSG_LEN); + return -EINVAL; + } + + message = kzalloc(count, GFP_KERNEL); + if (!message) + return -ENOMEM; + + ret = copy_from_user(message, userbuf, count); + if (ret) + return -EFAULT; + + print_hex_dump(KERN_ERR, "Client: Sending: ", DUMP_PREFIX_ADDRESS, + 16, 1, message, 16, true); + + ret = mbox_send_message(tdev->tx_channel, message); + if (ret < 0) + dev_err(tdev->dev, "Failed to send message via mailbox\n"); + + kfree(message); + + return ret < 0 ? ret : count; +} + +static const struct file_operations mbox_test_ops = { + .write = mbox_test_write, + .open = simple_open, + .llseek = generic_file_llseek, +}; + +static int mbox_test_add_debugfs(struct platform_device *pdev, + struct mbox_test_device *tdev) +{ + if (!debugfs_initialized()) + return 0; + + root_debugfs_dir = debugfs_create_dir("mailbox", NULL); + if (!root_debugfs_dir) { + dev_err(&pdev->dev, "Failed to create Mailbox debugfs\n"); + return -EINVAL; + } + + debugfs_create_file("send-message", 0200, root_debugfs_dir, + tdev, &mbox_test_ops); + + return 0; +} + +static void mbox_test_receive_message(struct mbox_client *client, void *message) +{ + struct mbox_test_device *tdev = dev_get_drvdata(client->dev); + + if (!tdev->mmio) { + dev_info(tdev->dev, "Client: Recived something [read mmio]\n"); + return; + } + + print_hex_dump(KERN_ERR, "Client: from co-proc: ", DUMP_PREFIX_ADDRESS, + 16, 1, tdev->mmio, MBOX_MAX_MSG_LEN, true); +} + +static void mbox_test_prepare_message(struct mbox_client *client, void *message) +{ + struct mbox_test_device *tdev = dev_get_drvdata(client->dev); + + if (tdev->mmio) + memcpy(tdev->mmio, message, MBOX_MAX_MSG_LEN); +} + +static void mbox_test_message_sent(struct mbox_client *client, + void *message, int r) +{ + if (r) + dev_warn(client->dev, + "Client: Message could not be sent: %d\n", r); + else + dev_info(client->dev, + "Client: Message sent\n"); +} + +static struct mbox_chan * +mbox_test_request_channel(struct platform_device *pdev, const char *name) +{ + struct mbox_client *client; + + client = devm_kzalloc(&pdev->dev, sizeof(*client), GFP_KERNEL); + if (!client) + return ERR_PTR(-ENOMEM); + + client->dev = &pdev->dev; + client->rx_callback = mbox_test_receive_message; + client->tx_prepare = mbox_test_prepare_message; + client->tx_done = mbox_test_message_sent; + client->tx_block = true; + client->knows_txdone = false; + client->tx_tout = 500; + + return mbox_request_channel_byname(client, name); +} + +static int mbox_test_probe(struct platform_device *pdev) +{ + struct mbox_test_device *tdev; + struct resource *res; + int ret; + + tdev = devm_kzalloc(&pdev->dev, sizeof(*tdev), GFP_KERNEL); + if (!tdev) + return -ENOMEM; + + /* It's okay for MMIO to be NULL */ + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + tdev->mmio = devm_ioremap_resource(&pdev->dev, res); + if (IS_ERR(tdev->mmio)) + tdev->mmio = NULL; + + tdev->tx_channel = mbox_test_request_channel(pdev, "tx"); + if (IS_ERR(tdev->tx_channel)) + return PTR_ERR(tdev->tx_channel); + + tdev->rx_channel = mbox_test_request_channel(pdev, "rx"); + if (IS_ERR(tdev->rx_channel)) + return PTR_ERR(tdev->rx_channel); + + tdev->dev = &pdev->dev; + platform_set_drvdata(pdev, tdev); + + ret = mbox_test_add_debugfs(pdev, tdev); + if (ret) + return ret; + + dev_info(&pdev->dev, "Successfully registered\n"); + + return 0; +} + +static int mbox_test_remove(struct platform_device *pdev) +{ + struct mbox_test_device *tdev = platform_get_drvdata(pdev); + + debugfs_remove_recursive(root_debugfs_dir); + + mbox_free_channel(tdev->tx_channel); + mbox_free_channel(tdev->rx_channel); + + return 0; +} + +static const struct of_device_id mbox_test_match[] = { + { .compatible = "mailbox_test" }, + {}, +}; + +static struct platform_driver mbox_test_driver = { + .driver = { + .name = "mailbox_sti_test", + .of_match_table = mbox_test_match, + }, + .probe = mbox_test_probe, + .remove = mbox_test_remove, +}; +module_platform_driver(mbox_test_driver); + +MODULE_DESCRIPTION("Generic Mailbox Testing Facility"); +MODULE_AUTHOR("Lee Jones