From patchwork Tue Oct 4 11:47:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 77248 Delivered-To: patch@linaro.org Received: by 10.140.106.72 with SMTP id d66csp2169832qgf; Tue, 4 Oct 2016 04:47:50 -0700 (PDT) X-Received: by 10.66.192.134 with SMTP id hg6mr4442500pac.64.1475581670606; Tue, 04 Oct 2016 04:47:50 -0700 (PDT) Return-Path: Received: from gabe.freedesktop.org (gabe.freedesktop.org. [131.252.210.177]) by mx.google.com with ESMTPS id y127si15600116pfg.99.2016.10.04.04.47.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Oct 2016 04:47:50 -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 179556E625; Tue, 4 Oct 2016 11:47:47 +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 C28796E624 for ; Tue, 4 Oct 2016 11:47:45 +0000 (UTC) Received: by mail-wm0-x22d.google.com with SMTP id k125so202284478wma.1 for ; Tue, 04 Oct 2016 04:47:45 -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=YLtv3yjw34qajDNQ7mPKfe90ofRKkV8gC5TCkp2ZnJA=; b=Hfl01DQyqgwlHg5Uh26nMDpRvVFvFHj/Y5DR094vZ/GuRKkngaXyav8RdhXB3ccTnX h062TM7LN/w3YIB9nlB/y1Tg2M09nc8A/qYE42acrrqEQiUlcsCS0BLCf827+whxDoea vrMuby2VCrubY5ZA1xpMbjYHE66UcVTnh6MCY= 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=YLtv3yjw34qajDNQ7mPKfe90ofRKkV8gC5TCkp2ZnJA=; b=cj9LYWSvytW+LEkmzaovkHs3AuK85gYM473ruix7NySBhqT9NDbD7WLM9Nc7gPCdOF +RJgAPS5KxFkkdpSkg29/dXmCrmPkqsYPV3vFrYICCjdHtfR2BqS78ESjYYr9k0Og1mL n4O1qqar9xJLl0N1OXXEhsNwUGRmOg+IqYA4wZJnjYw6MPXSs81jVOtPXmWTwScCk5/P Yf7z5PdsHTcB1GbALwGJs6lmvMt48UtbeBle8C2DAfxOm/vLuLsQLNcRZu6lFek4Y1k0 RhSb/g8MGvRsDvSIB5AKha766MaOf/Z/1VVxIAus8+jdiLgcGcczdWcoSu6QGe6oAkU4 jqBA== X-Gm-Message-State: AA6/9RkIqWuJCD8jWbGbDv/tQwQ9UbMOXsfiqwxIt4B2o3MLo9pGCV/Slbf8zFZXG+VZ/73c X-Received: by 10.195.3.4 with SMTP id bs4mr2584154wjd.193.1475581664155; Tue, 04 Oct 2016 04:47:44 -0700 (PDT) Received: from lmenx321.st.com. ([80.215.15.251]) by smtp.gmail.com with ESMTPSA id lf3sm3146627wjc.15.2016.10.04.04.47.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 04 Oct 2016 04:47:43 -0700 (PDT) From: Benjamin Gaignard To: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, cc.ma@mediatek.com, joakim.bech@linaro.org, burt.lien@linaro.org, linus.walleij@linaro.org Subject: [PATCH v10 3/3] SMAF: add test secure module Date: Tue, 4 Oct 2016 13:47:24 +0200 Message-Id: <1475581644-10600-4-git-send-email-benjamin.gaignard@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1475581644-10600-1-git-send-email-benjamin.gaignard@linaro.org> References: <1475581644-10600-1-git-send-email-benjamin.gaignard@linaro.org> Cc: linaro-mm-sig@lists.linaro.org, linaro-kernel@lists.linaro.org 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 cfdfffd..73f2ebf 100644 --- a/drivers/smaf/Kconfig +++ b/drivers/smaf/Kconfig @@ -9,3 +9,9 @@ config SMAF_CMA depends on SMAF 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 ");