From patchwork Mon Aug 4 15:28:12 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanjun Guo X-Patchwork-Id: 34862 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f69.google.com (mail-pa0-f69.google.com [209.85.220.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id DA44E21F5F for ; Mon, 4 Aug 2014 15:29:59 +0000 (UTC) Received: by mail-pa0-f69.google.com with SMTP id kx10sf51432956pab.8 for ; Mon, 04 Aug 2014 08:29:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=PlArp2ew8BdsNCnQV1kkEXZINIqO0wdAbksiF+HySW8=; b=j3dZf/kghLYEFilyXt9ahIO3rcbewFxSWV6vc4JtReuVtNP1rfCnc2rulki+5JdV0m HDZCrRcDz4aKcUJKNB+NJbWyO1LDu3e5LnZxI0Suw1Bv2k1CrO6rH2/HwKmxKrhPqhEg 5HVsEq6TYMAZw1Ne7uGjeLSZhFZD8lakkfM/XB1U8A78DGIliS9Vafi074ByX69vfvPl bIO1Sfta66lAXhn9W1xZfARoiAQr6/SVgAnJIMVZ73WUtFwK5eNCUsKn34KMN9x7KtZ+ JcFf6hQnvQDJnmvB9KOnBXQgUoEOBGThEqt0iyNQd/xj2Ck+lbZ9wa9ASJlrwDpguDjX /OMg== X-Gm-Message-State: ALoCoQlJ4Fb20UeP0tFFmlFtyZ+LR87Bjesx9vHvcls/9oDlL6+r0ooQrPEsiVz6huFWCzcpFUuf X-Received: by 10.66.252.6 with SMTP id zo6mr9403684pac.40.1407166199208; Mon, 04 Aug 2014 08:29:59 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.51.78 with SMTP id t72ls2340409qga.87.gmail; Mon, 04 Aug 2014 08:29:59 -0700 (PDT) X-Received: by 10.220.133.13 with SMTP id d13mr2630698vct.66.1407166199058; Mon, 04 Aug 2014 08:29:59 -0700 (PDT) Received: from mail-vc0-f171.google.com (mail-vc0-f171.google.com [209.85.220.171]) by mx.google.com with ESMTPS id fx7si11175609vec.92.2014.08.04.08.29.58 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 04 Aug 2014 08:29:58 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.171 as permitted sender) client-ip=209.85.220.171; Received: by mail-vc0-f171.google.com with SMTP id hq11so11354718vcb.30 for ; Mon, 04 Aug 2014 08:29:58 -0700 (PDT) X-Received: by 10.220.50.8 with SMTP id x8mr24365429vcf.18.1407166198551; Mon, 04 Aug 2014 08:29:58 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp313279vcb; Mon, 4 Aug 2014 08:29:57 -0700 (PDT) X-Received: by 10.68.220.170 with SMTP id px10mr24660439pbc.33.1407166196768; Mon, 04 Aug 2014 08:29:56 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id yc7si17987159pab.174.2014.08.04.08.29.56 for ; Mon, 04 Aug 2014 08:29:56 -0700 (PDT) Received-SPF: none (google.com: linux-acpi-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753054AbaHDP3m (ORCPT + 8 others); Mon, 4 Aug 2014 11:29:42 -0400 Received: from mail-pa0-f54.google.com ([209.85.220.54]:52341 "EHLO mail-pa0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753043AbaHDP3k (ORCPT ); Mon, 4 Aug 2014 11:29:40 -0400 Received: by mail-pa0-f54.google.com with SMTP id fa1so10119895pad.41 for ; Mon, 04 Aug 2014 08:29:39 -0700 (PDT) X-Received: by 10.70.63.74 with SMTP id e10mr24617788pds.87.1407166179810; Mon, 04 Aug 2014 08:29:39 -0700 (PDT) Received: from localhost ([39.182.20.233]) by mx.google.com with ESMTPSA id x15sm17807468pbt.52.2014.08.04.08.29.32 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 04 Aug 2014 08:29:39 -0700 (PDT) From: Hanjun Guo To: Catalin Marinas , "Rafael J. Wysocki" , Mark Rutland Cc: Graeme Gregory , Arnd Bergmann , Olof Johansson , Grant Likely , Sudeep Holla , Will Deacon , Jason Cooper , Marc Zyngier , Bjorn Helgaas , Daniel Lezcano , Mark Brown , Rob Herring , Robert Richter , Lv Zheng , Robert Moore , Lorenzo Pieralisi , Liviu Dudau , Randy Dunlap , Charles.Garcia-Tobin@arm.com, linux-acpi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linaro-acpi@lists.linaro.org, Hanjun Guo Subject: [PATCH v2 05/18] ARM64 / ACPI: Parse FADT table to get PSCI flags for PSCI init Date: Mon, 4 Aug 2014 23:28:12 +0800 Message-Id: <1407166105-17675-6-git-send-email-hanjun.guo@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1407166105-17675-1-git-send-email-hanjun.guo@linaro.org> References: <1407166105-17675-1-git-send-email-hanjun.guo@linaro.org> Sender: linux-acpi-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: hanjun.guo@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.171 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , There are two flags: PSCI_COMPLIANT and PSCI_USE_HVC. When set, the former signals to the OS that the hardware is PSCI compliant. The latter selects the appropriate conduit for PSCI calls by toggling between Hypervisor Calls (HVC) and Secure Monitor Calls (SMC). FADT table contains such information, parse FADT to get the flags for PSCI init. Since ACPI 5.1 doesn't support self defined PSCI function IDs, which means that only PSCI 0.2+ is supported in ACPI. At the same time, only ACPI 5.1 or higher verison supports PSCI, and FADT Major.Minor version was introduced in ACPI 5.1, so we will check the version and only parse FADT table with version >= 5.1. If firmware provides ACPI tables with ACPI version less than 5.1, OS will be messed up with those information and have no way to bring up secondery CPUs, so disable ACPI if we get an FADT table with version less that 5.1. Signed-off-by: Hanjun Guo Signed-off-by: Graeme Gregory --- arch/arm64/include/asm/acpi.h | 12 ++++++ arch/arm64/kernel/acpi.c | 37 +++++++++++++++++ arch/arm64/kernel/psci.c | 89 ++++++++++++++++++++++++++++++----------- arch/arm64/kernel/setup.c | 2 + 4 files changed, 117 insertions(+), 23 deletions(-) diff --git a/arch/arm64/include/asm/acpi.h b/arch/arm64/include/asm/acpi.h index 6400312..6e04868 100644 --- a/arch/arm64/include/asm/acpi.h +++ b/arch/arm64/include/asm/acpi.h @@ -19,6 +19,18 @@ extern int acpi_disabled; extern int acpi_noirq; extern int acpi_pci_disabled; +/* 1 to indicate PSCI 0.2+ is implemented */ +static inline bool acpi_psci_present(void) +{ + return !!(acpi_gbl_FADT.arm_boot_flags & ACPI_FADT_PSCI_COMPLIANT); +} + +/* 1 to indicate HVC must be used instead of SMC as the PSCI conduit */ +static inline bool acpi_psci_use_hvc(void) +{ + return !!(acpi_gbl_FADT.arm_boot_flags & ACPI_FADT_PSCI_USE_HVC); +} + static inline void disable_acpi(void) { acpi_disabled = 1; diff --git a/arch/arm64/kernel/acpi.c b/arch/arm64/kernel/acpi.c index 9cf9127..69a315d 100644 --- a/arch/arm64/kernel/acpi.c +++ b/arch/arm64/kernel/acpi.c @@ -11,6 +11,8 @@ * published by the Free Software Foundation. */ +#define pr_fmt(fmt) "ACPI: " fmt + #include #include #include @@ -47,6 +49,26 @@ void __init __acpi_unmap_table(char *map, unsigned long size) early_memunmap(map, size); } +static int __init acpi_parse_fadt(struct acpi_table_header *table) +{ + struct acpi_table_fadt *fadt = (struct acpi_table_fadt *)table; + + /* + * Revision in table header is the FADT Major version, + * and there is a minor version of FADT which was introduced + * by ACPI 5.1, we only deal with ACPI 5.1 or higher version + * to get arm boot flags, or we will disable ACPI. + */ + if (table->revision < 5 || fadt->minor_revision < 1) { + pr_info("FADT version is %d.%d, no PSCI support, should be 5.1 or higher\n", + table->revision, fadt->minor_revision); + disable_acpi(); + return -EINVAL; + } + + return 0; +} + /* * acpi_boot_table_init() called from setup_arch(), always. * 1. find RSDP and get its address, and then find XSDT @@ -68,6 +90,21 @@ void __init acpi_boot_table_init(void) } } +int __init acpi_boot_init(void) +{ + int err = 0; + + /* If acpi_disabled, bail out */ + if (acpi_disabled) + return -ENODEV; + + err = acpi_table_parse(ACPI_SIG_FADT, acpi_parse_fadt); + if (err) + pr_err("Can't find FADT\n"); + + return err; +} + /* * acpi_suspend_lowlevel() - save kernel state and suspend. * diff --git a/arch/arm64/kernel/psci.c b/arch/arm64/kernel/psci.c index 9e9798f..2ad2084 100644 --- a/arch/arm64/kernel/psci.c +++ b/arch/arm64/kernel/psci.c @@ -15,6 +15,7 @@ #define pr_fmt(fmt) "psci: " fmt +#include #include #include #include @@ -231,6 +232,33 @@ static void psci_sys_poweroff(void) invoke_psci_fn(PSCI_0_2_FN_SYSTEM_OFF, 0, 0, 0); } +static void psci_0_2_set_functions(void) +{ + pr_info("Using standard PSCI v0.2 function IDs\n"); + psci_function_id[PSCI_FN_CPU_SUSPEND] = PSCI_0_2_FN64_CPU_SUSPEND; + psci_ops.cpu_suspend = psci_cpu_suspend; + + psci_function_id[PSCI_FN_CPU_OFF] = PSCI_0_2_FN_CPU_OFF; + psci_ops.cpu_off = psci_cpu_off; + + psci_function_id[PSCI_FN_CPU_ON] = PSCI_0_2_FN64_CPU_ON; + psci_ops.cpu_on = psci_cpu_on; + + psci_function_id[PSCI_FN_MIGRATE] = PSCI_0_2_FN64_MIGRATE; + psci_ops.migrate = psci_migrate; + + psci_function_id[PSCI_FN_AFFINITY_INFO] = PSCI_0_2_FN64_AFFINITY_INFO; + psci_ops.affinity_info = psci_affinity_info; + + psci_function_id[PSCI_FN_MIGRATE_INFO_TYPE] = + PSCI_0_2_FN_MIGRATE_INFO_TYPE; + psci_ops.migrate_info_type = psci_migrate_info_type; + + arm_pm_restart = psci_sys_reset; + + pm_power_off = psci_sys_poweroff; +} + /* * PSCI Function IDs for v0.2+ are well defined so use * standard values. @@ -264,29 +292,7 @@ static int psci_0_2_init(struct device_node *np) } } - pr_info("Using standard PSCI v0.2 function IDs\n"); - psci_function_id[PSCI_FN_CPU_SUSPEND] = PSCI_0_2_FN64_CPU_SUSPEND; - psci_ops.cpu_suspend = psci_cpu_suspend; - - psci_function_id[PSCI_FN_CPU_OFF] = PSCI_0_2_FN_CPU_OFF; - psci_ops.cpu_off = psci_cpu_off; - - psci_function_id[PSCI_FN_CPU_ON] = PSCI_0_2_FN64_CPU_ON; - psci_ops.cpu_on = psci_cpu_on; - - psci_function_id[PSCI_FN_MIGRATE] = PSCI_0_2_FN64_MIGRATE; - psci_ops.migrate = psci_migrate; - - psci_function_id[PSCI_FN_AFFINITY_INFO] = PSCI_0_2_FN64_AFFINITY_INFO; - psci_ops.affinity_info = psci_affinity_info; - - psci_function_id[PSCI_FN_MIGRATE_INFO_TYPE] = - PSCI_0_2_FN_MIGRATE_INFO_TYPE; - psci_ops.migrate_info_type = psci_migrate_info_type; - - arm_pm_restart = psci_sys_reset; - - pm_power_off = psci_sys_poweroff; + psci_0_2_set_functions(); out_put_node: of_node_put(np); @@ -333,6 +339,40 @@ out_put_node: return err; } +#ifdef CONFIG_ACPI +static int get_set_conduit_method_acpi(void) +{ + pr_info("probing for conduit method from ACPI.\n"); + + if (acpi_psci_use_hvc()) + invoke_psci_fn = __invoke_psci_fn_hvc; + else + invoke_psci_fn = __invoke_psci_fn_smc; + + return 0; +} + +/* We use PSCI 0.2+ when ACPI is deployed */ +static int psci_0_2_init_acpi(void) +{ + if (!acpi_psci_present()) { + pr_info("is not implemented in ACPI.\n"); + return -EOPNOTSUPP; + } + + get_set_conduit_method_acpi(); + + psci_0_2_set_functions(); + + return 0; +} +#else +static inline int psci_0_2_init_acpi(void) +{ + return -ENODEV; +} +#endif + static const struct of_device_id psci_of_match[] __initconst = { { .compatible = "arm,psci", .data = psci_0_1_init}, { .compatible = "arm,psci-0.2", .data = psci_0_2_init}, @@ -345,6 +385,9 @@ int __init psci_init(void) const struct of_device_id *matched_np; psci_initcall_t init_fn; + if (!acpi_disabled) + return psci_0_2_init_acpi(); + np = of_find_matching_node_and_match(NULL, psci_of_match, &matched_np); if (!np) diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c index 85c6326..dfc4e4f3 100644 --- a/arch/arm64/kernel/setup.c +++ b/arch/arm64/kernel/setup.c @@ -395,6 +395,8 @@ void __init setup_arch(char **cmdline_p) efi_idmap_init(); cpu_logical_map(0) = read_cpuid_mpidr() & MPIDR_HWID_BITMASK; + acpi_boot_init(); + unflatten_device_tree(); psci_init();