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: 9047341 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 752219F1D3 for ; Mon, 9 May 2016 15:08:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 915C720155 for ; Mon, 9 May 2016 15:08:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8BD2C2014A for ; Mon, 9 May 2016 15:08:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751076AbcEIPIY (ORCPT ); Mon, 9 May 2016 11:08:24 -0400 Received: from mail-wm0-f42.google.com ([74.125.82.42]:37190 "EHLO mail-wm0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751874AbcEIPIW (ORCPT ); Mon, 9 May 2016 11:08:22 -0400 Received: by mail-wm0-f42.google.com with SMTP id a17so192653891wme.0 for ; Mon, 09 May 2016 08:08:16 -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=Ock/89M1qk/1DozaGiH2yf9lBgjadfKDDNqOSi0PNiz7sXDkdv6ugdjKB5gL4sXlqy gYgtbqdstaHCCk7WYi9q6UPJVBfk0SOyU/S7udmiGW1ZTJ/LkrteR42BHgniJ69BY/UA 0KohI+BY/40NuB7AwRYI1fZPXHUG4kwhpdzxjT8DXJoMjDFKR7lJilNs2DeikRcNsyEB ApGB8/SS2pVAQeDNCXdLOgcCezPgwdf9LRf6/qL+zNr6OA7tytDdYHioWNXZdXn6l8vg K0lOmz2J1fBKQgVbpLzFKMz2QPaK/5qP7vB4udKLlgl5GLf6WjxzTyW7smmcYbN1H6Pu vcvw== X-Gm-Message-State: AOPr4FV/FFLNqiLOeziVNZcCeU4sh7hrr9JkfFyDwIIbo80KKWqdlVfP/jJgVvCoebHxaCFq 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 Cc: Benjamin Gaignard 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> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-8.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.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-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 ");