From patchwork Fri Mar 9 09:07:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Shi X-Patchwork-Id: 10270383 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A1AB06016D for ; Fri, 9 Mar 2018 10:23:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 84F3B29AA2 for ; Fri, 9 Mar 2018 10:23:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7998C29D72; Fri, 9 Mar 2018 10:23:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3B5B929D70 for ; Fri, 9 Mar 2018 10:23:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=pgGM11clR8WDlgon9Yrup2S6mO/RyAj0IUxKWlN+wNA=; b=uNYb9UVrfmKsdDQyS0T+cvAaPr O2PD+9w6r5JEw0aewHPZD8xpjT2flX57kTaL2/HW1a6K3NBKvmfFVM8X2V/ZcAHgWQZFLQoyRaJzQ WHJ9FF4EcQy5AbHIyaxKCQQmXjQb9D6LKMHjpIAEs4uLgIJqpKKZOKASos2GvlKZFyXlUfEKnLwnG 9+jZwzDp9JE8xK4n2AZcaUJi6ETVFzdXyK3GSu2pKMXX2c6yA5M+9h1SHBYlDYX1hASnGupWzHKS3 /X6xMjCNkTNqkwg0fe7NRbNn+NKmlisqY+BOmeBK5N8iBjHE9ErwF+exKHBCrjXrJkUpMH7UxZYiv y6ycvARw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1euFAo-00060L-7Z; Fri, 09 Mar 2018 10:22:50 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1euF7e-0002qN-LY for linux-arm-kernel@bombadil.infradead.org; Fri, 09 Mar 2018 10:19:34 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=4Vd5VHeglADw+0fG55jktK+hq9tgxcTcLfQ5W9MP/aU=; b=CoJvPq/wNoJhznCZIxGLR+ty0 tNGzYK+J0g+LLdQ1YBIASYfw6rVHHFYbugY2YQaqL3TGAsFFfqgZrgbDN+V4pcWv0u2eLoVMZeax4 drZUKcXfopr7M0bckSWMhzeRoqUFNT7AYOY6YJdoE3Uw816RDCNOda1MaGIUEJS1wIOIU74kqKihJ 1E1rN5wK9deMjZ0SqbbAHDp1QxthGkYPHTJDvvMfzoDc+Ei/robRnOKfdV7glo3nadephKJ6MbY89 gJJipnzqy6WXF4FogK9vxbmp1UaAskEt4+kd5j5Ygjc4jLyNXdt8yAvcLnuHwvXuqc+fFvoCAhGiz xdUHgYkDg==; Received: from mail-pl0-x243.google.com ([2607:f8b0:400e:c01::243]) by merlin.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1euE3e-0002gQ-Ps for linux-arm-kernel@lists.infradead.org; Fri, 09 Mar 2018 09:11:24 +0000 Received: by mail-pl0-x243.google.com with SMTP id 93-v6so4926410plc.9 for ; Fri, 09 Mar 2018 01:11:12 -0800 (PST) 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=4Vd5VHeglADw+0fG55jktK+hq9tgxcTcLfQ5W9MP/aU=; b=FjuPk5gDVW+Z4Zy3bK1OyODhY1kPnYJOpoBqLVKs7VsZGVuGkzBNv5H5rajMnuIcQL tPRlc4fm7MJOOGe1rgjoV7I+wriLJ0TbEDmvvsFz0YhB3eHJBYjBndMW7MRcDT8kAr+y bITfpTLJkgJzN6Owx9+l63qcaiH+z37pvTljU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=4Vd5VHeglADw+0fG55jktK+hq9tgxcTcLfQ5W9MP/aU=; b=SsWrwar0PdA124Kt9DHkenq+7bj+UiRDci/H1ic67x+qBz7Ms6w4zvg6QKUKFkkrKC oC4REOdzlHaz1DeQcrUpQuwUxc46cbJXNpq4egBpg5wqGUfBB0S62BoGzegmLT7oEljI ahbWOoKo/QjPKu+LH6JOrSo+P0hMY4F5sCgUGkO/dGJm8WvEZX1uCUbsbzCjMXc4O+4A 4pcTnJR1dcvf5sS7S2s08Tfj3GEwk9pYkJKBbThPOSsJKNr85fKB9sGOpCQ7b+PAsXlV drgHDsbZj7vQh/lTWNSaQ7LnQsi4XSb+mT4JsZLhjsinMYI4lMt7+jR+RaNZM8bpUrLg lQMg== X-Gm-Message-State: APf1xPA2u9vJDz7a0Eq6mpNYte87SKoQbXae+2kI7oIfN7nnNRkbIMHn b483WXcAvvTR6vUrCz2AQwe0OA== X-Google-Smtp-Source: AG47ELu4He657CJRYhElhtAuc/X1eMCCo8gJ4i8DoyWIy1ISA//I85x9/nKf97LC0U1F/oXRVywbFg== X-Received: by 2002:a17:902:5a44:: with SMTP id f4-v6mr26598203plm.116.1520586670247; Fri, 09 Mar 2018 01:11:10 -0800 (PST) Received: from localhost.localdomain (176.122.172.82.16clouds.com. [176.122.172.82]) by smtp.gmail.com with ESMTPSA id c7sm1961752pfg.36.2018.03.09.01.11.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 09 Mar 2018 01:11:09 -0800 (PST) From: Alex Shi To: Marc Zyngier , Will Deacon , Ard Biesheuvel , Catalin Marinas , broonie@linaro.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 27/39] ARM: 8478/2: arm/arm64: add arm-smccc Date: Fri, 9 Mar 2018 17:07:10 +0800 Message-Id: <20180309090722.26279-28-alex.shi@linaro.org> X-Mailer: git-send-email 2.16.2.440.gc6284da In-Reply-To: <20180309090722.26279-1-alex.shi@linaro.org> References: <20180309090722.26279-1-alex.shi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180309_041123_331684_7A056207 X-CRM114-Status: GOOD ( 22.45 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alex Shi , Russell King , Jens Wiklander MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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: Alex Shi --- drivers/firmware/Kconfig | 3 ++ include/linux/arm-smccc.h | 105 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 include/linux/arm-smccc.h diff --git a/drivers/firmware/Kconfig b/drivers/firmware/Kconfig index cf478fe6b335..49a3a1185bb6 100644 --- a/drivers/firmware/Kconfig +++ b/drivers/firmware/Kconfig @@ -173,6 +173,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..632dbb45a110 --- /dev/null +++ b/include/linux/arm-smccc.h @@ -0,0 +1,105 @@ +/* + * 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 + +/* + * 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 + +#ifndef __ASSEMBLY__ +#include +#include +/** + * 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 /*__ASSEMBLY__*/ +#endif /*__LINUX_ARM_SMCCC_H*/