From patchwork Mon May 9 15:07:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 67350 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp1644409qge; Mon, 9 May 2016 08:08:22 -0700 (PDT) X-Received: by 10.66.183.36 with SMTP id ej4mr50931513pac.53.1462806502653; Mon, 09 May 2016 08:08:22 -0700 (PDT) Return-Path: Received: from gabe.freedesktop.org (gabe.freedesktop.org. [2610:10:20:722:a800:ff:fe36:1795]) by mx.google.com with ESMTP id x190si38094628pfx.222.2016.05.09.08.08.22; Mon, 09 May 2016 08:08:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 2610:10:20:722:a800:ff:fe36:1795 as permitted sender) client-ip=2610:10:20:722:a800:ff:fe36:1795; 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 2610:10:20:722:a800:ff:fe36:1795 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 99A946E0BE; Mon, 9 May 2016 15:08:21 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x22d.google.com (mail-wm0-x22d.google.com [IPv6:2a00:1450:400c:c09::22d]) by gabe.freedesktop.org (Postfix) with ESMTPS id 22F756E097 for ; Mon, 9 May 2016 15:08:17 +0000 (UTC) Received: by mail-wm0-x22d.google.com with SMTP id n129so142050693wmn.1 for ; Mon, 09 May 2016 08:08:17 -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=Qh7a1clyMbG1tK/v47j9v5C+XR2loF0TZ5Qk0dipOTw=; b=D+AFhCt22Xt38ncTQj+rsBA85nnXs1I41jfiI+mAA7B4UcDj/699W+THOg9SBr3LEy p4Wl6wspPWZngh4nZBMCdkErMJOOXx+gbT6zZiTK/5SRtoRIFjDj2LQZEFVg3Ue064gC 1i3KKv6ZgkL2X/j/zAKcHSXcdHypcfNwX2yzI= 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=Qh7a1clyMbG1tK/v47j9v5C+XR2loF0TZ5Qk0dipOTw=; b=ivQ0SH1GLdiisK2M72PJJSimPCrWlhkHR+BPhEqekJq4tpw9wgXripuNbQNxIv8Aae Lp2XaQqEKjvXwGHC4he1mChP+EXuC+mgt+Ppw8dLRxfFQMYMfv6Y1Lw03E2SflQKm0yz Ns7YJlFkvmbm3SYID/4oFGtuAxIwguC98dPBeew1726Pimsgk3W+c0v0THFV8x092l0u HyfnoZgfnj5muh+YJF4Tc9NrM83v0CvHoTBek2ICDnwmWNGHRRLB1BdVgtfsOzQeUjYX JpwtRonyw/b6OFq5SLfAL6GriBsPHmaYD6P4jt+HEdP+gQ1FZa7EdliNIBHBPl43TB7f XuIQ== X-Gm-Message-State: AOPr4FWWqITwT8F7qeLBCd9z1hP2GvPgGKzILuTxIfS9jC93D5UyOdAQVLPvZVtt+ckhYK/s X-Received: by 10.28.16.17 with SMTP id 17mr11133944wmq.17.1462806495719; Mon, 09 May 2016 08:08:15 -0700 (PDT) Received: from lmenx321.st.com. ([80.12.51.223]) by smtp.gmail.com with ESMTPSA id u12sm25008031wmu.12.2016.05.09.08.08.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 09 May 2016 08:08:14 -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 Subject: [PATCH v7 3/3] SMAF: add fake secure module Date: Mon, 9 May 2016 17:07:39 +0200 Message-Id: <1462806459-8124-4-git-send-email-benjamin.gaignard@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1462806459-8124-1-git-send-email-benjamin.gaignard@linaro.org> References: <1462806459-8124-1-git-send-email-benjamin.gaignard@linaro.org> Cc: 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-fakesecure.c | 85 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+) create mode 100644 drivers/smaf/smaf-fakesecure.c diff --git a/drivers/smaf/Kconfig b/drivers/smaf/Kconfig index 058ec4c..fd17005 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_FAKE_SECURE + tristate "SMAF fake secure module" + depends on SMAF + help + Choose this option to enable fake secure module for test purpose diff --git a/drivers/smaf/Makefile b/drivers/smaf/Makefile index 05bab01b..00d5cd4 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_FAKE_SECURE) += smaf-fakesecure.o diff --git a/drivers/smaf/smaf-fakesecure.c b/drivers/smaf/smaf-fakesecure.c new file mode 100644 index 0000000..5f3d355 --- /dev/null +++ b/drivers/smaf/smaf-fakesecure.c @@ -0,0 +1,85 @@ +/* + * smaf-fakesecure.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 fake_private { + int magic; +}; + +static void *smaf_fakesecure_create(void) +{ + struct fake_private *priv; + + priv = kzalloc(sizeof(*priv), GFP_KERNEL); + priv->magic = MAGIC; + + return priv; +} + +static int smaf_fakesecure_destroy(void *ctx) +{ + struct fake_private *priv = (struct fake_private *)ctx; + + WARN_ON(!priv || (priv->magic != MAGIC)); + kfree(priv); + + return 0; +} + +static bool smaf_fakesecure_grant_access(void *ctx, + struct device *dev, + size_t addr, size_t size, + enum dma_data_direction direction) +{ + struct fake_private *priv = (struct fake_private *)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_fakesecure_revoke_access(void *ctx, + struct device *dev, + size_t addr, size_t size, + enum dma_data_direction direction) +{ + struct fake_private *priv = (struct fake_private *)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 fake = { + .create_ctx = smaf_fakesecure_create, + .destroy_ctx = smaf_fakesecure_destroy, + .grant_access = smaf_fakesecure_grant_access, + .revoke_access = smaf_fakesecure_revoke_access, +}; + +static int __init smaf_fakesecure_init(void) +{ + return smaf_register_secure(&fake); +} +module_init(smaf_fakesecure_init); + +static void __exit smaf_fakesecure_deinit(void) +{ + smaf_unregister_secure(&fake); +} +module_exit(smaf_fakesecure_deinit); + +MODULE_DESCRIPTION("SMAF fake secure module for test purpose"); +MODULE_LICENSE("GPL v2"); +MODULE_AUTHOR("Benjamin Gaignard ");