From patchwork Wed Sep 7 08:24:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 9318603 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 D85616077F for ; Wed, 7 Sep 2016 08:25:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D5CD6276AE for ; Wed, 7 Sep 2016 08:25:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CA5D628871; Wed, 7 Sep 2016 08:25:21 +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=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7BA61276AE for ; Wed, 7 Sep 2016 08:25:21 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 826ED6E922; Wed, 7 Sep 2016 08:25:20 +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 A896B6E91A for ; Wed, 7 Sep 2016 08:25:18 +0000 (UTC) Received: by mail-wm0-x22d.google.com with SMTP id w12so17843842wmf.0 for ; Wed, 07 Sep 2016 01:25:18 -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=S7IhSAvA/njvPXaO/IRgCRPOWEgtEHg22YF9sJRBoMP52xkId0okscOsK4aPAJGGMT Hl2j2UxkLzL2pgPcEgn079/WcrS5Da+l7LJOJBA3hsETaM1uYKYLsmkoKhcq7DrHb7C2 Kz+AzVGXxADK8SD99pnXO9pMV6WAEJWYxK9Ko= 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=IOirwVd8irZRO1ldDXKH7cEvLyNTpUd5v1QsET+JqY3Y481CrFu/flW29nNIUFlyWw JhXk5ZBvn3asI7G+UWa9EesY4zoX7OIV2VZSCFnFwsQLQ7xzRuMLV4vC6I0G6TDoS211 eMw2fF30ezeCkodfJm3klQCEr7qrumWkyV3K7W7mpNq3JijsKVqmZZGEBfdpZxFMNwHF TTDdjc64i7aS5MoB/r/ZPtbDY88vMDwcmPO3rkIrXCs0QCiSSWaUKdNwdUtC39oNclcZ iZfP1E5aPTpyDIm3pa+3P8EliQNJ/oWoMleVyqRyHek9vCTHcfYkqIEeHL0qp3qTxGOw uhzA== X-Gm-Message-State: AE9vXwMUcncV+zeKuBslJavyX8rkIj3ExRDkcAtNzw/4EyfrrUs+UR/Vd/EL2xJ+IeNevUNH X-Received: by 10.194.72.133 with SMTP id d5mr19916418wjv.96.1473236717248; Wed, 07 Sep 2016 01:25:17 -0700 (PDT) Received: from lmenx321.st.com. ([80.215.102.222]) by smtp.gmail.com with ESMTPSA id gf4sm3662621wjb.47.2016.09.07.01.25.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 07 Sep 2016 01:25:16 -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, joakim.bech@linaro.org, dan.caprita@windriver.com, burt.lien@linaro.org Subject: [PATCH v9 3/3] SMAF: add test secure module Date: Wed, 7 Sep 2016 10:24:56 +0200 Message-Id: <1473236696-10002-4-git-send-email-benjamin.gaignard@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1473236696-10002-1-git-send-email-benjamin.gaignard@linaro.org> References: <1473236696-10002-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" 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 ");