From patchwork Sun May 15 18:10:45 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlo Caione X-Patchwork-Id: 9096761 Return-Path: X-Original-To: patchwork-linux-arm@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 874A99F1C3 for ; Sun, 15 May 2016 18:14:09 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 48CD220220 for ; Sun, 15 May 2016 18:14:08 +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 0D4D420218 for ; Sun, 15 May 2016 18:14:07 +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 1b20WF-0004yP-9u; Sun, 15 May 2016 18:11:59 +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 1b20W8-0004wP-V3; Sun, 15 May 2016 18:11:56 +0000 Received: by mail-wm0-x241.google.com with SMTP id w143so13586611wmw.3; Sun, 15 May 2016 11:11:31 -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; bh=+EQdzmx0JgNxusIZT6RHxrtq/f7mMgce4F72cn7Wrzs=; b=Y8B3FZ8ILSHFvAqNnRljnv3BR77V9M2klsxiS7XeskRfqGYDm9su2vU1x/sYSPkQq2 jcATXiCpEG8Zc5r0CRbRwrbeglaMYwH6REm1rVt08ko0vyP/3P234y2JwRIh1qB0Wenr l4kTeNh8RfvISMRoXoL4NHmUcCtNBEP2lPxFWdhXtLNZYGnoE66WPWzwGYFeSpALZvYf klGtVq837HlslCMOtKvZ3SVpJMqFJ8V2zmwbhmCSxIYrmPsNr0gzgZZaHldgRKUaIYJH bVnQKBvamg4gWbryuIhzuJ6kYvygafyxzMDYHg0fFCwg7rKZ33CDcZqakj7fQuPrbmxZ MnJA== 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; bh=+EQdzmx0JgNxusIZT6RHxrtq/f7mMgce4F72cn7Wrzs=; b=In88GIkrLJRt5G9Mo77bd4Nvq3iF0VV7ra1iOzMO1kz3Ro9PoCT+q/+GQnVOVMjOoy ql6QhG9jIcJBgLGKg9fpj5nrB0xdNHQclU/lFqexvHwSae0zjFxsFC77KkxOGsgJOQr/ KOd8Y2LC7dY5lyB6cIYnV/q3MpWLScXR3qablWJrmN/y5kJa6Aqqq2F70FXsmyGhs0S9 IHruaoxu8jMleoX78GtctmWjYpUFsdyOi2GO1ZE/dcvhqM9FDwTkJxNcCTwzj3p/+AjK uz+XDJotwMATpuNfXhWfWHM4xqkx1Sz75dpwN1Zl+z5NWIbkHjypoN+QrKzTIzFxsimQ mbqQ== X-Gm-Message-State: AOPr4FX0Tbsy3/qHJYBUqFEqtxx/EYE+q4l/B0kCduKvl0aP0vt6/TZLfYnhTjoU+Bpc/A== X-Received: by 10.194.11.97 with SMTP id p1mr25276248wjb.159.1463335889671; Sun, 15 May 2016 11:11:29 -0700 (PDT) Received: from localhost.localdomain (2-238-57-164.ip242.fastwebnet.it. [2.238.57.164]) by smtp.gmail.com with ESMTPSA id kc2sm27608547wjb.5.2016.05.15.11.11.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 15 May 2016 11:11:28 -0700 (PDT) From: Carlo Caione To: linux-arm-kernel@lists.infradead.org, linux-amlogic@lists.infradead.org, linux@endlessm.com, khilman@baylibre.com, afaerber@suse.de, arnd@arndb.de, jens.wiklander@linaro.org, mark.rutland@arm.com Subject: [RFC PATCH] soc: Amlogic: Add secure monitor driver Date: Sun, 15 May 2016 20:10:45 +0200 Message-Id: <1463335845-23534-1-git-send-email-carlo@caione.org> X-Mailer: git-send-email 2.7.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160515_111153_328699_38A47F33 X-CRM114-Status: GOOD ( 19.96 ) 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, reboot, set USB boot, enable JTAG, etc... Signed-off-by: Carlo Caione --- arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi | 4 + drivers/soc/Kconfig | 1 + drivers/soc/Makefile | 1 + drivers/soc/amlogic/Kconfig | 8 ++ drivers/soc/amlogic/Makefile | 1 + drivers/soc/amlogic/meson_sm.c | 141 ++++++++++++++++++++++++++++ include/linux/soc/amlogic/meson_sm.h | 57 +++++++++++ 7 files changed, 213 insertions(+) create mode 100644 drivers/soc/amlogic/Kconfig create mode 100644 drivers/soc/amlogic/Makefile create mode 100644 drivers/soc/amlogic/meson_sm.c create mode 100644 include/linux/soc/amlogic/meson_sm.h diff --git a/arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi b/arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi index 76b3b6d..e4017c3 100644 --- a/arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi +++ b/arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi @@ -98,6 +98,10 @@ method = "smc"; }; + sm { + compatible = "amlogic,meson-sm"; + }; + timer { compatible = "arm,armv8-timer"; interrupts = + * + * 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 { + unsigned int cmd; + unsigned int arg0; + unsigned int arg1; + unsigned int arg2; + unsigned int arg3; + unsigned int arg4; + unsigned int 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; +} + +unsigned int meson_sm_call(unsigned int cmd, unsigned int arg0, + unsigned int arg1, unsigned int arg2, + unsigned int arg3, unsigned int 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; + + smp_call_function_single(0, __meson_sm_call, &data, 1); + + return data.ret; +} + +unsigned int meson_sm_call_read(void *buffer, unsigned int cmd, + unsigned int arg0, unsigned int arg1, + unsigned int arg2, unsigned int arg3, + unsigned int arg4) +{ + unsigned int size; + + size = meson_sm_call(cmd, arg0, arg1, arg2, arg3, arg4); + + if (size != 0) + memcpy(buffer, sm_sharemem_out_base, size); + + return size; +} + +unsigned int meson_sm_call_write(void *buffer, unsigned int size, + unsigned int cmd, unsigned int arg0, + unsigned int arg1, unsigned int arg2, + unsigned int arg3, unsigned int arg4) +{ + memcpy(sm_sharemem_in_base, buffer, size); + + return meson_sm_call(cmd, arg0, arg1, arg2, arg3, arg4); +} + +static int meson_sm_probe(struct platform_device *pdev) +{ + sm_phy_in_base = meson_sm_call(SM_GET_SHARE_MEM_INPUT_BASE, 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(SM_GET_SHARE_MEM_OUTPUT_BASE, 0, 0, 0, 0, 0); + + sm_sharemem_out_base = ioremap_cache(sm_phy_out_base, SM_MEM_SIZE); + if (!sm_sharemem_out_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/amlogic/meson_sm.h b/include/linux/soc/amlogic/meson_sm.h new file mode 100644 index 0000000..68b943f --- /dev/null +++ b/include/linux/soc/amlogic/meson_sm.h @@ -0,0 +1,57 @@ +/* + * 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_ + +#define SM_GET_SHARE_MEM_INPUT_BASE 0x82000020 +#define SM_GET_SHARE_MEM_OUTPUT_BASE 0x82000021 +#define SM_GET_REBOOT_REASON 0x82000022 +#define SM_GET_SHARE_STORAGE_IN_BASE 0x82000023 +#define SM_GET_SHARE_STORAGE_OUT_BASE 0x82000024 +#define SM_GET_SHARE_STORAGE_BLOCK_BASE 0x82000025 +#define SM_GET_SHARE_STORAGE_MESSAGE_BASE 0x82000026 +#define SM_GET_SHARE_STORAGE_BLOCK_SIZE 0x82000027 +#define SM_EFUSE_READ 0x82000030 +#define SM_EFUSE_WRITE 0x82000031 +#define SM_EFUSE_WRITE_PATTERN 0x82000032 +#define SM_EFUSE_USER_MAX 0x82000033 +#define SM_JTAG_ON 0x82000040 +#define SM_JTAG_OFF 0x82000041 +#define SM_SET_USB_BOOT_FUNC 0x82000043 +#define SM_SECURITY_KEY_QUERY 0x82000060 +#define SM_SECURITY_KEY_READ 0x82000061 +#define SM_SECURITY_KEY_WRITE 0x82000062 +#define SM_SECURITY_KEY_TELL 0x82000063 +#define SM_SECURITY_KEY_VERIFY 0x82000064 +#define SM_SECURITY_KEY_STATUS 0x82000065 +#define SM_SECURITY_KEY_NOTIFY 0x82000066 +#define SM_SECURITY_KEY_LIST 0x82000067 +#define SM_SECURITY_KEY_REMOVE 0x82000068 +#define SM_DEBUG_EFUSE_WRITE_PATTERN 0x820000F0 +#define SM_DEBUG_EFUSE_READ_PATTERN 0x820000F1 +#define SM_AML_DATA_PROCESS 0x820000FF +#define SM_PSCI_SYS_REBOOT 0x84000009 + +unsigned int meson_sm_call(unsigned int cmd, unsigned int arg0, + unsigned int arg1, unsigned int arg2, + unsigned int arg3, unsigned int arg4); +unsigned int meson_sm_call_read(void *buffer, unsigned int cmd, + unsigned int arg0, unsigned int arg1, + unsigned int arg2, unsigned int arg3, + unsigned int arg4); +unsigned int meson_sm_call_write(void *buffer, unsigned int size, + unsigned int cmd, unsigned int arg0, + unsigned int arg1, unsigned int arg2, + unsigned int arg3, unsigned int arg4); + +#endif /* _MESON_SM_H_ */