linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hanjun Guo <hanjun.guo@linaro.org>
To: Sudeep Holla <sudeep.holla@arm.com>,
	Catalin Marinas <Catalin.Marinas@arm.com>,
	"Rafael J. Wysocki" <rjw@rjwysocki.net>,
	Mark Rutland <Mark.Rutland@arm.com>
Cc: "graeme.gregory@linaro.org" <graeme.gregory@linaro.org>,
	Arnd Bergmann <arnd@arndb.de>, Olof Johansson <olof@lixom.net>,
	"grant.likely@linaro.org" <grant.likely@linaro.org>,
	Will Deacon <Will.Deacon@arm.com>,
	Jason Cooper <jason@lakedaemon.net>,
	Marc Zyngier <Marc.Zyngier@arm.com>,
	Bjorn Helgaas <bhelgaas@google.com>,
	Daniel Lezcano <daniel.lezcano@linaro.org>,
	Mark Brown <broonie@kernel.org>, Rob Herring <robh@kernel.org>,
	Robert Richter <rric@kernel.org>, Lv Zheng <lv.zheng@intel.com>,
	Robert Moore <robert.moore@intel.com>,
	Lorenzo Pieralisi <Lorenzo.Pieralisi@arm.com>,
	Liviu Dudau <Liviu.Dudau@arm.com>,
	Randy Dunlap <rdunlap@infradead.org>,
	Charles Garcia-Tobin <Charles.Garcia-Tobin@arm.com>,
	"linux-acpi@vger.kernel.org" <linux-acpi@vger.kernel.org>,
	"linux-arm-kernel@lists.infradead.org" 
	<linux-arm-kernel@lists.infradead.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linaro-acpi@lists.linaro.org" <linaro-acpi@lists.linaro.org>
Subject: Re: [PATCH v2 05/18] ARM64 / ACPI: Parse FADT table to get PSCI flags for PSCI init
Date: Tue, 19 Aug 2014 18:39:54 +0800	[thread overview]
Message-ID: <53F3297A.1040309@linaro.org> (raw)
In-Reply-To: <53F246D4.7040807@arm.com>

On 2014-8-19 2:32, Sudeep Holla wrote:
> On 04/08/14 16:28, Hanjun Guo wrote:
>> 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.
>>
[...]
>>
>> +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) {
> 
>                 &&

Catalin also pointed out this bug :), but && is not enough, for example,
this would not trigger of revision 4.1, although 4.1 is not exist, but
the code will still confusing people, so I updated the code as:

+       if (table->revision > 5 ||
+           (table->revision == 5 && fadt->minor_revision >= 1)) {
+               return 0;
+       } else {
+               pr_info("FADT revision is %d.%d, no PSCI support, should be 5.1
or higher\n",
+                       table->revision, fadt->minor_revision);
+               disable_acpi();
+               return -EINVAL;
+       }

> 
>> +        pr_info("FADT version is %d.%d, no PSCI support, should be 5.1 or
>> higher\n",
>> +            table->revision, fadt->minor_revision);
>> +        disable_acpi();
> 
> Instead of disabling ACPI at multiple places in the boot sequence, can't
> it be done once if acpi_boot_init failed ?
> 
>> +        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 <linux/acpi.h>
>>   #include <linux/init.h>
>>   #include <linux/of.h>
>>   #include <linux/smp.h>
>> @@ -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;
>> +}
>> +
> 
> Nit: IMO may be you can move these refactoring as separate patch before
> ACPI related changes ?

I'm ok with it, will format another patch and place it in the
beginning of this patch set.

> 
>>   /*
>>    * 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)
> 
> May be this can be renamed psci_acpi_init and called from setup directly
> instead of calling from DT function with acpi_disabled check.

Also suggested by Catalin, will do it :)

> 
>> +{
>> +    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();
>> +
> 
> As mentioned above you need not modify this.
> 
>>       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();
>> +
> 
> Check for the return error here and disable ACPI once rather than at
> multiple places all over.

ok.

Thanks
Hanjun


  reply	other threads:[~2014-08-19 10:41 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-04 15:28 [PATCH v2 00/18] Introduce ACPI for ARM64 based on ACPI 5.1 Hanjun Guo
2014-08-04 15:28 ` [PATCH v2 01/18] ARM64: Move the init of cpu_logical_map(0) before unflatten_device_tree() Hanjun Guo
2014-08-04 15:28 ` [PATCH v2 02/18] ARM64 / ACPI: Get RSDP and ACPI boot-time tables Hanjun Guo
2014-08-18 18:30   ` Sudeep Holla
2014-08-19  9:35     ` Hanjun Guo
2014-08-19  9:47       ` Sudeep Holla
2014-08-04 15:28 ` [PATCH v2 03/18] ARM64 / ACPI: Introduce lowlevel suspend function Hanjun Guo
2014-08-04 15:28 ` [PATCH v2 04/18] ARM64 / ACPI: Make PCI optional for ACPI on ARM64 Hanjun Guo
2014-08-04 15:28 ` [PATCH v2 05/18] ARM64 / ACPI: Parse FADT table to get PSCI flags for PSCI init Hanjun Guo
2014-08-18 18:32   ` Sudeep Holla
2014-08-19 10:39     ` Hanjun Guo [this message]
2014-08-19 11:07       ` Sudeep Holla
     [not found]   ` <20140818142721.GR20043@localhost>
2014-08-19  3:50     ` Hanjun Guo
2014-08-19 11:10       ` Mark Rutland
2014-08-19 12:13         ` Hanjun Guo
2014-08-19 22:55           ` Moore, Robert
2014-08-20  4:12             ` Hanjun Guo
2014-08-04 15:28 ` [PATCH v2 06/18] ARM64 / ACPI: Parse MADT to map logical cpu to MPIDR and get cpu_possible/present_map Hanjun Guo
2014-08-18 18:33   ` Sudeep Holla
2014-08-19 11:00     ` Hanjun Guo
2014-08-19 16:46       ` [Linaro-acpi] " Zi Shen Lim
2014-08-20  3:24         ` Hanjun Guo
     [not found]   ` <20140818142728.GS20043@localhost>
2014-08-19  7:36     ` Hanjun Guo
2014-08-20 14:38       ` Catalin Marinas
2014-08-21  2:51         ` Hanjun Guo
2014-08-04 15:28 ` [PATCH v2 07/18] ACPI / table: Print GIC information when MADT is parsed Hanjun Guo
2014-08-04 15:28 ` [PATCH v2 08/18] ARM64 / ACPI: Get the enable method for SMP initialization in ACPI way Hanjun Guo
2014-08-18 18:34   ` Sudeep Holla
2014-08-19 11:26     ` Hanjun Guo
2014-08-18 18:56   ` Geoff Levand
2014-08-19 12:11     ` Hanjun Guo
2014-08-19 19:25       ` Geoff Levand
2014-08-20  3:25         ` Hanjun Guo
     [not found]   ` <20140818142733.GT20043@localhost>
2014-08-19  8:32     ` Hanjun Guo
2014-08-20 14:52       ` Catalin Marinas
2014-08-21  3:06         ` Hanjun Guo
2014-08-04 15:28 ` [PATCH v2 09/18] ACPI / processor: Make it possible to get CPU hardware ID via GICC Hanjun Guo
2014-08-18 18:34   ` Sudeep Holla
2014-08-19 11:29     ` Hanjun Guo
     [not found]   ` <20140818142740.GU20043@localhost>
2014-08-19  8:37     ` Hanjun Guo
2014-08-20 14:56       ` Catalin Marinas
2014-08-21  3:25         ` Hanjun Guo
2014-08-04 15:28 ` [PATCH v2 10/18] ARM64 / ACPI: Introduce ACPI_IRQ_MODEL_GIC and register device's gsi Hanjun Guo
2014-08-18 18:34   ` Sudeep Holla
2014-08-19 11:36     ` Hanjun Guo
2014-08-04 15:28 ` [PATCH v2 11/18] ACPI / table: Add new function to get table entries Hanjun Guo
2014-08-04 15:28 ` [PATCH v2 12/18] ARM64 / ACPI: Add GICv2 specific ACPI boot support Hanjun Guo
2014-08-04 15:28 ` [PATCH v2 13/18] ARM64 / ACPI: Parse GTDT to initialize arch timer Hanjun Guo
2014-08-04 15:28 ` [PATCH v2 14/18] ARM64 / ACPI: Select ACPI_REDUCED_HARDWARE_ONLY if ACPI is enabled on ARM64 Hanjun Guo
2014-08-04 15:28 ` [PATCH v2 15/18] ARM64 / ACPI: Introduce early_param for "acpi" and set ACPI default off Hanjun Guo
2014-08-04 15:28 ` [PATCH v2 16/18] ARM64 / ACPI: If we chose to boot from acpi then disable FDT Hanjun Guo
2014-08-04 15:28 ` [PATCH v2 17/18] ARM64 / ACPI: Enable ARM64 in Kconfig Hanjun Guo
     [not found]   ` <20140818142745.GV20043@localhost>
2014-08-19  8:38     ` Hanjun Guo
2014-08-04 15:28 ` [PATCH v2 18/18] Documentation: ACPI for ARM64 Hanjun Guo
2014-08-04 20:48   ` Randy Dunlap
2014-08-05  3:36     ` Hanjun Guo
     [not found] ` <CAJRNFK+UfJhGR65tOecy=X+YdHQHiNPZ4p_p8LUxhRL3GW5gFw@mail.gmail.com>
2014-08-05  3:34   ` [Linaro-acpi] [PATCH v2 00/18] Introduce ACPI for ARM64 based on ACPI 5.1 Hanjun Guo
2014-08-18 17:08     ` Alexander Spyridakis
2014-08-18 18:11       ` Graeme Gregory

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=53F3297A.1040309@linaro.org \
    --to=hanjun.guo@linaro.org \
    --cc=Catalin.Marinas@arm.com \
    --cc=Charles.Garcia-Tobin@arm.com \
    --cc=Liviu.Dudau@arm.com \
    --cc=Lorenzo.Pieralisi@arm.com \
    --cc=Marc.Zyngier@arm.com \
    --cc=Mark.Rutland@arm.com \
    --cc=Will.Deacon@arm.com \
    --cc=arnd@arndb.de \
    --cc=bhelgaas@google.com \
    --cc=broonie@kernel.org \
    --cc=daniel.lezcano@linaro.org \
    --cc=graeme.gregory@linaro.org \
    --cc=grant.likely@linaro.org \
    --cc=jason@lakedaemon.net \
    --cc=linaro-acpi@lists.linaro.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lv.zheng@intel.com \
    --cc=olof@lixom.net \
    --cc=rdunlap@infradead.org \
    --cc=rjw@rjwysocki.net \
    --cc=robert.moore@intel.com \
    --cc=robh@kernel.org \
    --cc=rric@kernel.org \
    --cc=sudeep.holla@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).