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: 9361635 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6D30C60752 for ; Tue, 4 Oct 2016 11:48:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5DAD528851 for ; Tue, 4 Oct 2016 11:48:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5247628B1C; Tue, 4 Oct 2016 11:48:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E46FD28851 for ; Tue, 4 Oct 2016 11:48:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753627AbcJDLsH (ORCPT ); Tue, 4 Oct 2016 07:48:07 -0400 Received: from mail-wm0-f46.google.com ([74.125.82.46]:37304 "EHLO mail-wm0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753307AbcJDLrp (ORCPT ); Tue, 4 Oct 2016 07:47:45 -0400 Received: by mail-wm0-f46.google.com with SMTP id b201so139750175wmb.0 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=XaDFUTt1ZHqWkH9iMTYd+hg8ouioGZb2Nnrh0ValKITSJ9oNSFvVe5QrfXi7n78XeN WC9h8/fmNh+MGHEriFBXy+iC5QVGm7OCiWu3c1Agnz+1j+GMlhkYZnYbfw+FqtFxkmtK x3wgelsTCGX7ens4YNKuM6ANhFGvOH4XKNKcJXsIc+w8P/U/MvFj8eaezgX4KxrkgkWJ Or39l9wbtekr5H6IaQJxMyFgWe20vK7LmdahBd6tiHucUkllhM3PownJkdfiqNVqPuen 9efYUU2WeqFPLMaUv36hi1nLmOYvA6Vbw0rn0rSGcg5A+ciz+L2EigiUhZ/oaoOCaxol +pnA== X-Gm-Message-State: AA6/9Rm2pIcRvWOvY81QWabP8W5fkZlcL3+DRUvRDdvMaA6LThr3U8RZh0wX8WTBjeNPLrQS 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 Cc: linaro-mm-sig@lists.linaro.org, linaro-kernel@lists.linaro.org, Benjamin Gaignard 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> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 ");