From patchwork Fri Jul 17 12:04:06 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 51236 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 43A9E22A90 for ; Fri, 17 Jul 2015 12:05:16 +0000 (UTC) Received: by widic2 with SMTP id ic2sf11390956wid.1 for ; Fri, 17 Jul 2015 05:05:15 -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=eF+vvewndq9iiSlyiXLktY/7mpJODOdTjFEQCjY9rKv2sPuXhKAXiHoEVCzT8v/B9M bYuhR25SSx9b5qF3kbrMcjYoxausxUFg1mPHbqmCsVp5IwmqwUf5LOH780BXAR/W3wSC TChHzC3Katxe8N26pdbxJZwQ6XPf6vH4y/t7xscDoB7is/GwAt7K8VpCF8/EhXnkHoiv 9DLoJM0K+bO1KiupLD2krMkN6lv9JEoEsfdJcTwK4l4fu0wJiT3HNvJP3elC84QBo5qn upOVX0KaNjPTcT+moJVjKYty6gU9j2SE2/qIjjnh2q5wZpYYcY5zqvOZXQDUB0ztgK8k OaEg== X-Gm-Message-State: ALoCoQlTY7G9F15nlvojiq5tufPXEOygh5k3kaDM2M7aSKHSlTvznXIYTA7JtPsmcPaZK/YhS/87 X-Received: by 10.113.11.3 with SMTP id ee3mr7372862lbd.9.1437134715502; Fri, 17 Jul 2015 05:05:15 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.25.134 with SMTP id c6ls509955lag.54.gmail; Fri, 17 Jul 2015 05:05:15 -0700 (PDT) X-Received: by 10.112.63.201 with SMTP id i9mr14163098lbs.93.1437134715353; Fri, 17 Jul 2015 05:05:15 -0700 (PDT) Received: from mail-lb0-f175.google.com (mail-lb0-f175.google.com. [209.85.217.175]) by mx.google.com with ESMTPS id k14si9743598lbh.10.2015.07.17.05.05.15 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 Jul 2015 05:05:15 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.175 as permitted sender) client-ip=209.85.217.175; Received: by lbbzr7 with SMTP id zr7so60050020lbb.1 for ; Fri, 17 Jul 2015 05:05:15 -0700 (PDT) X-Received: by 10.152.5.197 with SMTP id u5mr13011294lau.76.1437134715115; Fri, 17 Jul 2015 05:05:15 -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.108.230 with SMTP id hn6csp874162lbb; Fri, 17 Jul 2015 05:05:13 -0700 (PDT) X-Received: by 10.68.65.34 with SMTP id u2mr29210784pbs.118.1437134712657; Fri, 17 Jul 2015 05:05:12 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id nb8si18330656pdb.250.2015.07.17.05.05.11; Fri, 17 Jul 2015 05:05:12 -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 S1752654AbbGQMEw (ORCPT + 8 others); Fri, 17 Jul 2015 08:04:52 -0400 Received: from mail-wg0-f45.google.com ([74.125.82.45]:34653 "EHLO mail-wg0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757897AbbGQMEU (ORCPT ); Fri, 17 Jul 2015 08:04:20 -0400 Received: by wgkl9 with SMTP id l9so80507942wgk.1 for ; Fri, 17 Jul 2015 05:04:18 -0700 (PDT) X-Received: by 10.180.36.3 with SMTP id m3mr14975143wij.60.1437134658398; Fri, 17 Jul 2015 05:04:18 -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 js3sm18076373wjc.5.2015.07.17.05.04.17 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 17 Jul 2015 05:04:17 -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 5/6] mailbox: Add generic mechanism for testing Mailbox Controllers Date: Fri, 17 Jul 2015 13:04:06 +0100 Message-Id: <1437134647-28298-6-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1437134647-28298-1-git-send-email-lee.jones@linaro.org> References: <1437134647-28298-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.217.175 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