From patchwork Fri Nov 8 12:35:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 178890 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp2636154ilf; Fri, 8 Nov 2019 04:36:17 -0800 (PST) X-Google-Smtp-Source: APXvYqxP3/HMB0/gDbUnqdYcZ18Eu2EP9MYaEcjUx6UCCLgWsBG0oyBlzxyE2RDpT/YEWOozGJEQ X-Received: by 2002:a17:906:2ada:: with SMTP id m26mr8465327eje.87.1573216577420; Fri, 08 Nov 2019 04:36:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573216577; cv=none; d=google.com; s=arc-20160816; b=I2eiC45z/4jQbPp88ORIwirh2Fqbmcs1eOf8YOpy0DA9236gMlfNcvzL/rLeemwmEQ AeX0rpSodFZXezwZdN5N4KHBfJOe+2gA+Mzx3gYHNIc7OtPxYtpmEXBDtcWNUxZQkgKG XOfG/a4SgoNI23aAdLxrQ55ES8pFvyxOgBSXaQLBf+4mJEzw4209tnlzRZ0UOFNI4KFv lJ6xR1BB4oSf6j3+TncqJI+ERlojtZ8ELbSQ8IaOGjWds4SgQXst7zxsNS0F/yqk9mI6 +FDeQfD2PPd7k1NqVQr1W2uTAXlWzw5xKlcoqUE6Lrlzvh7WNVL01Fx6KzvazGKsSez0 CtZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=1+mGRSp6oNIjPKktzv/t5XAJ0LxFFinOwSk1WnEfNuQ=; b=QU17n7gWqCRW/XZnr66dhfUIQTrEYzLXRjJk3HgfzsH0SnVFGRdR0eWINwPw4bGzrf 1nugC0HqX4Ro4Bn7mrdFPRVu7Hn+LyPp3yVowte5QBoOwe1HuQyMlMXFV6648O7a0Lcg 60Pxq3G8kqFKo6XQ6TuNrdK5L4cbsJZySENRfSrSHdqznq5jD5TySKttJ05KcuhzMzDf QrHKUVtXgf+Sl0zK7e6mLHPQs216Y616ELTNlDUqUOQ07wnDfzIUOyBfVfT2950cvaWf TGaIF5vxTENS8D4R/VZAHek+E4WuuIKKBpAQaDWE4gWz6q7xULZig6ryFqJZM8AaWs+x kasw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2cmv5whw; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o19si3411305ejc.315.2019.11.08.04.36.17; Fri, 08 Nov 2019 04:36:17 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2cmv5whw; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726935AbfKHMgQ (ORCPT + 14 others); Fri, 8 Nov 2019 07:36:16 -0500 Received: from mail.kernel.org ([198.145.29.99]:43790 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726251AbfKHMgQ (ORCPT ); Fri, 8 Nov 2019 07:36:16 -0500 Received: from localhost.localdomain (lfbn-mar-1-550-151.w90-118.abo.wanadoo.fr [90.118.131.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 291362245B; Fri, 8 Nov 2019 12:36:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573216575; bh=pesbwD8RHiAAwRio/nd/EfhYiMJ22NjZjKXdXI/0j8M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2cmv5whwD9zXc2aSCk0I0mrFOnbIYHzKCR64ydK6yW7rdLEGGjD+eW2CKL7ej0CuV iqXB03C7bkEz02rNmx1aPK6QSQakFCALnBuzqs6eYg/psJw9cKa7RgUEa3PmCPAiHV 7BResjkCnt6hzVch3X/w9P+UoeOBm0Xl0R/YQ3eo= From: Ard Biesheuvel To: stable@vger.kernel.org Cc: linus.walleij@linaro.org, rmk+kernel@armlinux.org.uk, Jens Wiklander , Ard Biesheuvel Subject: [PATCH for-stable-4.4 02/50] ARM: 8478/2: arm/arm64: add arm-smccc Date: Fri, 8 Nov 2019 13:35:06 +0100 Message-Id: <20191108123554.29004-3-ardb@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191108123554.29004-1-ardb@kernel.org> References: <20191108123554.29004-1-ardb@kernel.org> MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Jens Wiklander Commit 98dd64f34f47ce19b388d9015f767f48393a81eb upstream. 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. Reviewed-by: Lorenzo Pieralisi Signed-off-by: Jens Wiklander Signed-off-by: Russell King Signed-off-by: Ard Biesheuvel --- drivers/firmware/Kconfig | 3 + include/linux/arm-smccc.h | 104 ++++++++++++++++++++ 2 files changed, 107 insertions(+) -- 2.20.1 diff --git a/drivers/firmware/Kconfig b/drivers/firmware/Kconfig index b0d42234fba0..cc5e79dc4cda 100644 --- a/drivers/firmware/Kconfig +++ b/drivers/firmware/Kconfig @@ -174,6 +174,9 @@ config QCOM_SCM_64 def_bool y depends on QCOM_SCM && ARM64 +config HAVE_ARM_SMCCC + bool + source "drivers/firmware/broadcom/Kconfig" source "drivers/firmware/google/Kconfig" source "drivers/firmware/efi/Kconfig" diff --git a/include/linux/arm-smccc.h b/include/linux/arm-smccc.h new file mode 100644 index 000000000000..b5abfda80465 --- /dev/null +++ b/include/linux/arm-smccc.h @@ -0,0 +1,104 @@ +/* + * 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_STD_CALL 0 +#define ARM_SMCCC_FAST_CALL 1 +#define ARM_SMCCC_TYPE_SHIFT 31 + +#define ARM_SMCCC_SMC_32 0 +#define ARM_SMCCC_SMC_64 1 +#define ARM_SMCCC_CALL_CONV_SHIFT 30 + +#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 << ARM_SMCCC_TYPE_SHIFT)) +#define ARM_SMCCC_IS_64(smc_val) \ + ((smc_val) & (ARM_SMCCC_SMC_64 << ARM_SMCCC_CALL_CONV_SHIFT)) +#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) << ARM_SMCCC_TYPE_SHIFT) | \ + ((calling_convention) << ARM_SMCCC_CALL_CONV_SHIFT) | \ + (((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*/