From patchwork Mon May 23 08:09:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 68340 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp1091446qge; Mon, 23 May 2016 01:09:38 -0700 (PDT) X-Received: by 10.66.189.65 with SMTP id gg1mr25525931pac.148.1463990971689; Mon, 23 May 2016 01:09:31 -0700 (PDT) Return-Path: Received: from gabe.freedesktop.org (gabe.freedesktop.org. [131.252.210.177]) by mx.google.com with ESMTP id i127si50095360pfc.224.2016.05.23.01.09.31; Mon, 23 May 2016 01:09:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) client-ip=131.252.210.177; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E342C6E43F; Mon, 23 May 2016 08:09:28 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x235.google.com (mail-wm0-x235.google.com [IPv6:2a00:1450:400c:c09::235]) by gabe.freedesktop.org (Postfix) with ESMTPS id 59EBD6E43F for ; Mon, 23 May 2016 08:09:26 +0000 (UTC) Received: by mail-wm0-x235.google.com with SMTP id z87so37628326wmh.0 for ; Mon, 23 May 2016 01:09:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=uhYuwlQCyOWAaMKllsFuq+5YAvaHhhCMhp7jSYt22BI=; b=WSKyF5ciMPxjmAgxvfwX/NvaFkC5NRulnezjMYt/vGHGhbwLMYMs+dChiWjtFX9rPw xdtOQlogtV6IDh4za17I481AReILHOqNwAC7wkBvFTaklJTa2vgAh97lIYxn9uVwsg/K HvqvmMQZRTqMtZ/Rd8d/xJ3+RhjpEVSgTr1BA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=uhYuwlQCyOWAaMKllsFuq+5YAvaHhhCMhp7jSYt22BI=; b=JxE9Q8C1qfdoHb4ZE9zpZayjmyR+y9SrGI7tUWm4NqdCDUV6Gxcw/GIac51L2FMLMe MhavgFw7m8uvtNMV2nXlSBHhgV+mpqcTqorvwFHOBbLkKBrhJSREzrjk/qbK65Tpq9nK RkcncZI16V2zEVlRbJXT8ijdIP8MUbin/EsXn5I6O7jvMyMlwjk8VcagBLDC01Qp7Qu7 qbETtd21Nqh9kdNh1zlorM5e9uC/EB9Jnpon0I6WkmYjntBtGiYJV7rwhNBCzGvC8L6l SqADhMhhptdp0Q1F8ugSim+wsndv6C7tFK9laozsSJEh8JdjT0uI9uQx3OuJ18ChHVgD BQmA== X-Gm-Message-State: AOPr4FWiOu827LnWFPV9hYL/P2aiMmW7W5oNpN60XBxIyfmC5LQt3JP/hvmiXossSGIVg4ox X-Received: by 10.194.203.135 with SMTP id kq7mr15201104wjc.46.1463990964398; Mon, 23 May 2016 01:09:24 -0700 (PDT) Received: from lmenx321.st.com. ([80.12.38.51]) by smtp.gmail.com with ESMTPSA id d20sm12303269wmd.12.2016.05.23.01.09.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 23 May 2016 01:09:23 -0700 (PDT) From: Benjamin Gaignard To: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, zoltan.kuscsik@linaro.org, sumit.semwal@linaro.org, cc.ma@mediatek.com, pascal.brand@linaro.org, joakim.bech@linaro.org, dan.caprita@windriver.com, emil.l.velikov@gmail.com Subject: [PATCH v8 3/3] SMAF: add test secure module Date: Mon, 23 May 2016 10:09:03 +0200 Message-Id: <1463990943-10068-4-git-send-email-benjamin.gaignard@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1463990943-10068-1-git-send-email-benjamin.gaignard@linaro.org> References: <1463990943-10068-1-git-send-email-benjamin.gaignard@linaro.org> Cc: linaro-mm-sig@lists.linaro.org, Benjamin Gaignard X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" This module is allow testing secure calls of SMAF. Signed-off-by: Benjamin Gaignard --- drivers/smaf/Kconfig | 6 +++ drivers/smaf/Makefile | 1 + drivers/smaf/smaf-testsecure.c | 90 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+) create mode 100644 drivers/smaf/smaf-testsecure.c diff --git a/drivers/smaf/Kconfig b/drivers/smaf/Kconfig index 058ec4c..aad1f05 100644 --- a/drivers/smaf/Kconfig +++ b/drivers/smaf/Kconfig @@ -9,3 +9,9 @@ config SMAF_CMA depends on SMAF && HAVE_DMA_ATTRS help Choose this option to enable CMA allocation within SMAF + +config SMAF_TEST_SECURE + tristate "SMAF secure module for test" + depends on SMAF + help + Choose this option to enable secure module for test purpose diff --git a/drivers/smaf/Makefile b/drivers/smaf/Makefile index 05bab01b..bca6b9c 100644 --- a/drivers/smaf/Makefile +++ b/drivers/smaf/Makefile @@ -1,2 +1,3 @@ obj-$(CONFIG_SMAF) += smaf-core.o obj-$(CONFIG_SMAF_CMA) += smaf-cma.o +obj-$(CONFIG_SMAF_TEST_SECURE) += smaf-testsecure.o diff --git a/drivers/smaf/smaf-testsecure.c b/drivers/smaf/smaf-testsecure.c new file mode 100644 index 0000000..823d0dc --- /dev/null +++ b/drivers/smaf/smaf-testsecure.c @@ -0,0 +1,90 @@ +/* + * smaf-testsecure.c + * + * Copyright (C) Linaro SA 2015 + * Author: Benjamin Gaignard for Linaro. + * License terms: GNU General Public License (GPL), version 2 + */ +#include +#include +#include + +#define MAGIC 0xDEADBEEF + +struct test_private { + int magic; +}; + +#define to_priv(x) (struct test_private *)(x) + +static void *smaf_testsecure_create(void) +{ + struct test_private *priv; + + priv = kzalloc(sizeof(*priv), GFP_KERNEL); + if (!priv) + return NULL; + + priv->magic = MAGIC; + + return priv; +} + +static int smaf_testsecure_destroy(void *ctx) +{ + struct test_private *priv = to_priv(ctx); + + WARN_ON(!priv || (priv->magic != MAGIC)); + kfree(priv); + + return 0; +} + +static bool smaf_testsecure_grant_access(void *ctx, + struct device *dev, + size_t addr, size_t size, + enum dma_data_direction direction) +{ + struct test_private *priv = to_priv(ctx); + + WARN_ON(!priv || (priv->magic != MAGIC)); + pr_debug("grant requested by device %s\n", + dev->driver ? dev->driver->name : "cpu"); + + return priv->magic == MAGIC; +} + +static void smaf_testsecure_revoke_access(void *ctx, + struct device *dev, + size_t addr, size_t size, + enum dma_data_direction direction) +{ + struct test_private *priv = to_priv(ctx); + + WARN_ON(!priv || (priv->magic != MAGIC)); + pr_debug("revoke requested by device %s\n", + dev->driver ? dev->driver->name : "cpu"); +} + +static struct smaf_secure test = { + .create_ctx = smaf_testsecure_create, + .destroy_ctx = smaf_testsecure_destroy, + .grant_access = smaf_testsecure_grant_access, + .revoke_access = smaf_testsecure_revoke_access, +}; + +static int __init smaf_testsecure_init(void) +{ + return smaf_register_secure(&test); +} +module_init(smaf_testsecure_init); + +static void __exit smaf_testsecure_deinit(void) +{ + smaf_unregister_secure(&test); +} +module_exit(smaf_testsecure_deinit); + +MODULE_DESCRIPTION("SMAF secure module for test purpose"); +MODULE_LICENSE("GPL v2"); +MODULE_AUTHOR("Benjamin Gaignard ");