From patchwork Tue Dec 8 13:28:32 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 57868 Delivered-To: patches@linaro.org Received: by 10.112.147.194 with SMTP id tm2csp26908lbb; Tue, 8 Dec 2015 05:28:56 -0800 (PST) X-Received: by 10.194.185.173 with SMTP id fd13mr3848094wjc.54.1449581336287; Tue, 08 Dec 2015 05:28:56 -0800 (PST) Return-Path: Received: from mail-wm0-x231.google.com (mail-wm0-x231.google.com. [2a00:1450:400c:c09::231]) by mx.google.com with ESMTPS id c145si30508602wmd.17.2015.12.08.05.28.56 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 Dec 2015 05:28:56 -0800 (PST) Received-SPF: pass (google.com: domain of jens.wiklander@linaro.org designates 2a00:1450:400c:c09::231 as permitted sender) client-ip=2a00:1450:400c:c09::231; Authentication-Results: mx.google.com; spf=pass (google.com: domain of jens.wiklander@linaro.org designates 2a00:1450:400c:c09::231 as permitted sender) smtp.mailfrom=jens.wiklander@linaro.org; dkim=pass header.i=@linaro-org.20150623.gappssmtp.com Received: by wmww144 with SMTP id w144so29672977wmw.0 for ; Tue, 08 Dec 2015 05:28:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=xhgob1DY900LEkhrV0XW+JUGk7yLEOpHvYVb+Px9BM4=; b=NnWBgTsub4jo1Ai7nT6FW/a5/rBvLXDgiEcUl7SZ12ZWbayrLiHheaEgyYVfOxbdYj zPuskYqp5+XdqpMyoZo1FLAMw1q+kb94t8lh/WFHEymuzVRrwksVOz09BtI+VuRULotL eCDm3+WukybweEX2bTv3xlLnQ+vpyD+ECqcLvn/e6uYNicEkQW1lBAd3bWbaVnUfh2lS as9WZ3DaQIGp1bfCYcLxNkdl+yyIv1XAD9aV7SAaDI7eSrQ19XYFBOoYChPBtQtUH2JU bYgCY8bwQQISt3FUrz+att3wFVhRfUmN7fqrCVZHzDKDC6IVZMm9UqcBLSDy4cS12i5L PYTA== 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=xhgob1DY900LEkhrV0XW+JUGk7yLEOpHvYVb+Px9BM4=; b=IywZp7PPUnPJf9auDrAgSyVRY0iq79xYh8HTf12Gudpg4sn8h1D5Z+Grnz43JUbTCc eqigW3ApggL9j4mwrSTw/y++sVB+dTn80rIJqjrAX1xy0gnwwsdyyUS5c2+5iCRONjfT yW11GE4yHI3eOLn2oxEFeQI6TazwDOaT2KplhA3TjP76jRx4m1b7zMhr1ArEbYocskes FZrsItsvW8HzY93sfVLPzmx2BYLYkWiyHWYwyc12s8EChAPgfibMDry7x3QqqQ4w5oHc 1OmRLRWlGm+8gxB53/4KU+KeiscF+5MLT3R4ZtVEfr/irZcfTqwU9B9E2Cm1cxdB+sRq bJ0A== X-Gm-Message-State: ALoCoQmggs1wCtUrpXAwfhL5rN3VL4Wvib8S/nzqxcXswccoCqG/r3BRd5BQQMP+djxun5JlLu2dlo8y/A1sgQz/A3zgxQvZqg== X-Received: by 10.194.204.166 with SMTP id kz6mr3905453wjc.174.1449581336113; Tue, 08 Dec 2015 05:28:56 -0800 (PST) Return-Path: Received: from ermac.urgonet (h-84-45.a175.priv.bahnhof.se. [79.136.84.45]) by smtp.gmail.com with ESMTPSA id d2sm3035327wjy.16.2015.12.08.05.28.54 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 08 Dec 2015 05:28:55 -0800 (PST) From: Jens Wiklander To: linux-arm-kernel@lists.infradead.org, Arnd Bergmann , Mark Rutland , Will Deacon , Catalin Marinas , Russell King , Lorenzo Pieralisi , Kevin Hilman Cc: Lars Persson , tyler.baker@linaro.org, Jens Wiklander Subject: [PATCH v5 1/4] arm/arm64: add arm-smccc Date: Tue, 8 Dec 2015 14:28:32 +0100 Message-Id: <1449581315-14519-2-git-send-email-jens.wiklander@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1449581315-14519-1-git-send-email-jens.wiklander@linaro.org> References: <1449581315-14519-1-git-send-email-jens.wiklander@linaro.org> Adds helpers to do SMC and HVC based on ARM SMC Calling Convention. CONFIG_HAVE_ARM_SMCCC is enabled for architectures that may support the SMC or HVC instruction. It's the responsibility of the caller to know if the SMC instruction is supported by the platform. This patch doesn't provide an implementation of the declared functions. Later patches will bring in implementations and set CONFIG_HAVE_ARM_SMCCC for ARM and ARM64 respectively. Signed-off-by: Jens Wiklander --- include/linux/arm-smccc.h | 98 +++++++++++++++++++++++++++++++++++++++++++++++ init/Kconfig | 3 ++ 2 files changed, 101 insertions(+) create mode 100644 include/linux/arm-smccc.h -- 1.9.1 diff --git a/include/linux/arm-smccc.h b/include/linux/arm-smccc.h new file mode 100644 index 0000000..dea68a9 --- /dev/null +++ b/include/linux/arm-smccc.h @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2015, Linaro Limited + * + * This software is licensed under the terms of the GNU General Public + * License version 2, as published by the Free Software Foundation, and + * may be copied, distributed, and modified under those terms. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ +#ifndef __LINUX_ARM_SMCCC_H +#define __LINUX_ARM_SMCCC_H + +#include +#include + +/* + * This file provides common defines for ARM SMC Calling Convention as + * specified in + * http://infocenter.arm.com/help/topic/com.arm.doc.den0028a/index.html + */ + +#define ARM_SMCCC_SMC_32 (0 << 30) +#define ARM_SMCCC_SMC_64 (1 << 30) +#define ARM_SMCCC_FAST_CALL (1 << 31) +#define ARM_SMCCC_STD_CALL (0 << 31) + +#define ARM_SMCCC_OWNER_MASK 0x3F +#define ARM_SMCCC_OWNER_SHIFT 24 + +#define ARM_SMCCC_FUNC_MASK 0xFFFF + +#define ARM_SMCCC_IS_FAST_CALL(smc_val) ((smc_val) & ARM_SMCCC_FAST_CALL) +#define ARM_SMCCC_IS_64(smc_val) ((smc_val) & ARM_SMCCC_SMC_64) +#define ARM_SMCCC_FUNC_NUM(smc_val) ((smc_val) & ARM_SMCCC_FUNC_MASK) +#define ARM_SMCCC_OWNER_NUM(smc_val) \ + (((smc_val) >> ARM_SMCCC_OWNER_SHIFT) & ARM_SMCCC_OWNER_MASK) + +#define ARM_SMCCC_CALL_VAL(type, calling_convention, owner, func_num) \ + ((type) | (calling_convention) | \ + (((owner) & ARM_SMCCC_OWNER_MASK) << ARM_SMCCC_OWNER_SHIFT) | \ + ((func_num) & ARM_SMCCC_FUNC_MASK)) + +#define ARM_SMCCC_OWNER_ARCH 0 +#define ARM_SMCCC_OWNER_CPU 1 +#define ARM_SMCCC_OWNER_SIP 2 +#define ARM_SMCCC_OWNER_OEM 3 +#define ARM_SMCCC_OWNER_STANDARD 4 +#define ARM_SMCCC_OWNER_TRUSTED_APP 48 +#define ARM_SMCCC_OWNER_TRUSTED_APP_END 49 +#define ARM_SMCCC_OWNER_TRUSTED_OS 50 +#define ARM_SMCCC_OWNER_TRUSTED_OS_END 63 + +/** + * struct arm_smccc_res - Result from SMC/HVC call + * @a0-a3 result values from registers 0 to 3 + */ +struct arm_smccc_res { + unsigned long a0; + unsigned long a1; + unsigned long a2; + unsigned long a3; +}; + +/** + * arm_smccc_smc() - make SMC calls + * @a0-a7: arguments passed in registers 0 to 7 + * @res: result values from registers 0 to 3 + * + * This function is used to make SMC calls following SMC Calling Convention. + * The content of the supplied param are copied to registers 0 to 7 prior + * to the SMC instruction. The return values are updated with the content + * from register 0 to 3 on return from the SMC instruction. + */ +asmlinkage void arm_smccc_smc(unsigned long a0, unsigned long a1, + unsigned long a2, unsigned long a3, unsigned long a4, + unsigned long a5, unsigned long a6, unsigned long a7, + struct arm_smccc_res *res); + +/** + * arm_smccc_hvc() - make HVC calls + * @a0-a7: arguments passed in registers 0 to 7 + * @res: result values from registers 0 to 3 + * + * This function is used to make HVC calls following SMC Calling + * Convention. The content of the supplied param are copied to registers 0 + * to 7 prior to the HVC instruction. The return values are updated with + * the content from register 0 to 3 on return from the HVC instruction. + */ +asmlinkage void arm_smccc_hvc(unsigned long a0, unsigned long a1, + unsigned long a2, unsigned long a3, unsigned long a4, + unsigned long a5, unsigned long a6, unsigned long a7, + struct arm_smccc_res *res); + +#endif /*__LINUX_ARM_SMCCC_H*/ diff --git a/init/Kconfig b/init/Kconfig index c24b6f7..8d5a7b0 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -2061,3 +2061,6 @@ config ASN1 functions to call on what tags. source "kernel/Kconfig.locks" + +config HAVE_ARM_SMCCC + bool