From patchwork Wed May 18 14:56:19 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlo Caione X-Patchwork-Id: 9120031 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 18523BF29F for ; Wed, 18 May 2016 14:58:59 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E6D402034F for ; Wed, 18 May 2016 14:58:57 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CA7492034E for ; Wed, 18 May 2016 14:58:56 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1b32ur-0002wK-33; Wed, 18 May 2016 14:57:41 +0000 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1b32uG-0002e5-Bn; Wed, 18 May 2016 14:57:11 +0000 Received: by mail-wm0-x241.google.com with SMTP id g17so7010348wme.2; Wed, 18 May 2016 07:56:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=aQ0pIKXPSGozvqSBn6Nsp+w2atv1J7m+AqALuiEdLPo=; b=CfsSPDbhXiZiMwxgBfaGVSod2A/MmIOafrlrgYje0XxIZLENc1t46a92fEdUWltoIy GaaxXc4imyW3eQuLgWSi5Fq6DdNUzeLYe66qBg8wTKDbRhZ0go+985Z0ItX3afwlZ1m3 epxzr4CcWSloNwJR6paQSfnDlv24y1OVxhMN01S3A8jpFCqNLHGXuZLu7gAak53USlOv /lLTRw4mUyUowXrehek666dpE1GhTHGj6/Ys1IsGeki8MLOReV1vYFbEIynfdrD4Tz5M BsCvsAOpigX04gbI13ufIsyQKkrfc6QBh6X2cWZcUZLtSCAjEstD3RtPzQ79RWduDKGg DLyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=aQ0pIKXPSGozvqSBn6Nsp+w2atv1J7m+AqALuiEdLPo=; b=ROp6fgDnxNYfJoAsaM2Fn+7gUpI8rzf7VY8Zct6DjwAloqClXn9X8J8w5nTbYm8By1 p81ifF8IVYDnvp6Q8AkBri32FKzFKWnWzc2hUK6tHWcle6xGErH5eluTL59T9YUpa1/n go4ZJD0RqrAB+gFdYA6I+I2WPA8r43jGAZ5hYIEcCbXDSk6A5hrApgSA9lEuDLPchN7f cJni5XubMVNTHG4v57VHPzgAgOnAZ69EfZGlJ0WHpCFXUXbbbilgHtvwDFQj7yV1pK4A 4DvEEpSwKKtvEzu5QTKgm6VQE/p6lC7HmJnh6jyUJ4ezFoE59nt2hTl2PlQapwPJG+L0 6qBw== X-Gm-Message-State: AOPr4FXyD52YlCuWCaLph9qwcvjWpOjvlLOX9CjJ8Og0Ha4/wa4dzWXVKmM15jjpzGvSLw== X-Received: by 10.28.72.132 with SMTP id v126mr8148016wma.49.1463583402714; Wed, 18 May 2016 07:56:42 -0700 (PDT) Received: from localhost.localdomain (2-238-57-164.ip242.fastwebnet.it. [2.238.57.164]) by smtp.gmail.com with ESMTPSA id c16sm9588283wme.16.2016.05.18.07.56.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 18 May 2016 07:56:41 -0700 (PDT) From: Carlo Caione To: linux-arm-kernel@lists.infradead.org, linux-amlogic@lists.infradead.org, linux@endlessm.com, devicetree@vger.kernel.org, khilman@baylibre.com, afaerber@suse.de, arnd@arndb.de, jens.wiklander@linaro.org, mark.rutland@arm.com, robh+dt@kernel.org Subject: [PATCH v2 1/4] soc: Amlogic: Add secure monitor driver Date: Wed, 18 May 2016 16:56:19 +0200 Message-Id: <1463583382-15614-2-git-send-email-carlo@caione.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1463583382-15614-1-git-send-email-carlo@caione.org> References: <1463583382-15614-1-git-send-email-carlo@caione.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160518_075704_759956_BE3941F7 X-CRM114-Status: GOOD ( 21.36 ) X-Spam-Score: -2.4 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Carlo Caione MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-5.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,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 From: Carlo Caione Introduce a driver to provide calls into secure monitor mode. In the Amlogic SoCs these calls are used for multiple reasons: access to NVMEM, set USB boot, enable JTAG, etc... Signed-off-by: Carlo Caione --- drivers/soc/Kconfig | 1 + drivers/soc/Makefile | 1 + drivers/soc/meson/Kconfig | 8 ++ drivers/soc/meson/Makefile | 1 + drivers/soc/meson/meson_sm.c | 155 +++++++++++++++++++++++++++++++++++++ include/linux/soc/meson/meson_sm.h | 22 ++++++ 6 files changed, 188 insertions(+) create mode 100644 drivers/soc/meson/Kconfig create mode 100644 drivers/soc/meson/Makefile create mode 100644 drivers/soc/meson/meson_sm.c create mode 100644 include/linux/soc/meson/meson_sm.h diff --git a/drivers/soc/Kconfig b/drivers/soc/Kconfig index cb58ef0..7e70b52 100644 --- a/drivers/soc/Kconfig +++ b/drivers/soc/Kconfig @@ -4,6 +4,7 @@ source "drivers/soc/bcm/Kconfig" source "drivers/soc/brcmstb/Kconfig" source "drivers/soc/fsl/qe/Kconfig" source "drivers/soc/mediatek/Kconfig" +source "drivers/soc/meson/Kconfig" source "drivers/soc/qcom/Kconfig" source "drivers/soc/rockchip/Kconfig" source "drivers/soc/samsung/Kconfig" diff --git a/drivers/soc/Makefile b/drivers/soc/Makefile index 5ade713..9024d2b 100644 --- a/drivers/soc/Makefile +++ b/drivers/soc/Makefile @@ -8,6 +8,7 @@ obj-$(CONFIG_ARCH_DOVE) += dove/ obj-$(CONFIG_MACH_DOVE) += dove/ obj-y += fsl/ obj-$(CONFIG_ARCH_MEDIATEK) += mediatek/ +obj-$(CONFIG_ARCH_MESON) += meson/ obj-$(CONFIG_ARCH_QCOM) += qcom/ obj-$(CONFIG_ARCH_ROCKCHIP) += rockchip/ obj-$(CONFIG_SOC_SAMSUNG) += samsung/ diff --git a/drivers/soc/meson/Kconfig b/drivers/soc/meson/Kconfig new file mode 100644 index 0000000..fff11a3 --- /dev/null +++ b/drivers/soc/meson/Kconfig @@ -0,0 +1,8 @@ +# +# Amlogic Secure Monitor driver +# +config MESON_SM + bool + default ARCH_MESON + help + Say y here to enable the Amlogic secure monitor driver diff --git a/drivers/soc/meson/Makefile b/drivers/soc/meson/Makefile new file mode 100644 index 0000000..9ab3884 --- /dev/null +++ b/drivers/soc/meson/Makefile @@ -0,0 +1 @@ +obj-$(CONFIG_MESON_SM) += meson_sm.o diff --git a/drivers/soc/meson/meson_sm.c b/drivers/soc/meson/meson_sm.c new file mode 100644 index 0000000..16f7e32 --- /dev/null +++ b/drivers/soc/meson/meson_sm.c @@ -0,0 +1,155 @@ +/* + * Amlogic Secure Monitor driver + * + * Copyright (C) 2016 Endless Mobile, Inc. + * Author: Carlo Caione + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 as published by the Free Software Foundation. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#define SM_MEM_SIZE 0x1000 + +/* + * To read from / write to the secure monitor we use two bounce buffers. The + * physical addresses of the two buffers are obtained by querying the secure + * monitor itself. + */ + +static u32 sm_phy_in_base; +static u32 sm_phy_out_base; + +static void __iomem *sm_sharemem_in_base; +static void __iomem *sm_sharemem_out_base; + +struct meson_sm_data { + u32 cmd; + u32 arg0; + u32 arg1; + u32 arg2; + u32 arg3; + u32 arg4; + u32 ret; +}; + +static void __meson_sm_call(void *info) +{ + struct meson_sm_data *data = info; + struct arm_smccc_res res; + + arm_smccc_smc(data->cmd, + data->arg0, data->arg1, data->arg2, + data->arg3, data->arg4, 0, 0, &res); + data->ret = res.a0; +} + +u32 meson_sm_call(u32 cmd, u32 arg0, u32 arg1, u32 arg2, u32 arg3, u32 arg4) +{ + struct meson_sm_data data; + + data.cmd = cmd; + data.arg0 = arg0; + data.arg1 = arg1; + data.arg2 = arg2; + data.arg3 = arg3; + data.arg4 = arg4; + data.ret = 0; + + __meson_sm_call(&data); + + return data.ret; +} + +u32 meson_sm_call_read(void *buffer, u32 cmd, u32 arg0, u32 arg1, + u32 arg2, u32 arg3, u32 arg4) +{ + u32 size; + + size = meson_sm_call(cmd, arg0, arg1, arg2, arg3, arg4); + + if (!size || size > SM_MEM_SIZE) + return -EINVAL; + + memcpy(buffer, sm_sharemem_out_base, size); + return size; +} + +u32 meson_sm_call_write(void *buffer, unsigned int b_size, u32 cmd, u32 arg0, + u32 arg1, u32 arg2, u32 arg3, u32 arg4) +{ + u32 size; + + if (b_size > SM_MEM_SIZE) + return -EINVAL; + + memcpy(sm_sharemem_in_base, buffer, b_size); + + size = meson_sm_call(cmd, arg0, arg1, arg2, arg3, arg4); + + if (!size) + return -EINVAL; + + return size; +} + +static int meson_sm_probe(struct platform_device *pdev) +{ + struct device_node *np = pdev->dev.of_node; + int cmd_in, cmd_out; + + if (of_property_read_u32(np, "amlogic,sm_cmd_input_base", &cmd_in)) + return -EINVAL; + + if (of_property_read_u32(np, "amlogic,sm_cmd_output_base", &cmd_out)) + return -EINVAL; + + sm_phy_in_base = meson_sm_call(cmd_in, 0, 0, 0, 0, 0); + sm_sharemem_in_base = ioremap_cache(sm_phy_in_base, SM_MEM_SIZE); + if (!sm_sharemem_in_base) + return -EINVAL; + + sm_phy_out_base = meson_sm_call(cmd_out, 0, 0, 0, 0, 0); + sm_sharemem_out_base = ioremap_cache(sm_phy_out_base, SM_MEM_SIZE); + if (!sm_sharemem_out_base) { + iounmap(sm_sharemem_in_base); + return -EINVAL; + } + + return 0; +} + +static const struct of_device_id meson_sm_ids[] = { + { .compatible = "amlogic,meson-sm" }, + { /* sentinel */}, +}; +MODULE_DEVICE_TABLE(of, meson_sm_ids); + +static struct platform_driver meson_sm_platform_driver = { + .probe = meson_sm_probe, + .driver = { + .name = "secmon", + .of_match_table = meson_sm_ids, + }, +}; +module_platform_driver(meson_sm_platform_driver); + +MODULE_AUTHOR("Carlo Caione "); +MODULE_DESCRIPTION("Amlogic secure monitor driver"); +MODULE_LICENSE("GPL"); diff --git a/include/linux/soc/meson/meson_sm.h b/include/linux/soc/meson/meson_sm.h new file mode 100644 index 0000000..6ff8317 --- /dev/null +++ b/include/linux/soc/meson/meson_sm.h @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2016 Endless Mobile, Inc. + * Author: Carlo Caione + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 as published by the Free Software Foundation. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _MESON_SM_H_ +#define _MESON_SM_H_ + +u32 meson_sm_call(u32 cmd, u32 arg0, u32 arg1, u32 arg2, u32 arg3, u32 arg4); +u32 meson_sm_call_read(void *buffer, u32 cmd, u32 arg0, u32 arg1, u32 arg2, + u32 arg3, u32 arg4); +u32 meson_sm_call_write(void *buffer, unsigned int b_size, u32 cmd, u32 arg0, + u32 arg1, u32 arg2, u32 arg3, u32 arg4); + +#endif /* _MESON_SM_H_ */