Merge branch 'acpi-cleanup-next' into bleeding-edge

* acpi-cleanup-next:
  ACPI / dock: fix error return code in dock_add()
Merge branch 'acpi-assorted-next' into bleeding-edge

* acpi-assorted-next:
  ACPI / scan: Allow platform device creation without any IO resources
  ACPI / PCI: acpi_pci_irq_enable() must return an error if ACPI cannot map an IRQ.
  ACPI: Cleanup sparse warning on acpi_os_initialize1()
Merge branch 'pm-sleep-next' into bleeding-edge

* pm-sleep-next:
  PM / Sleep: increase ftrace coverage in suspend/resume
cpufreq: Fix misplaced call to cpufreq_update_policy()

The call to cpufreq_update_policy() is placed in the CPU hotplug
callback of cpufreq_stats, which has a higher priority than the CPU
hotplug callback of cpufreq-core.  As a result, during CPU_ONLINE /
CPU_ONLINE_FROZEN, we end up calling cpufreq_update_policy() *before*
calling cpufreq_add_dev()!  And for uninitialized CPUs, it just
returns silently, without doing anything.

To add to that, cpufreq_stats is not even the right place to call
cpufreq_update_policy() to begin with.  The cpufreq core ought to
handle this in its own callback, from an elegance/relevance
perspective.

So move the invocation of cpufreq_update_policy() to
cpufreq_cpu_callback, and place it *after* cpufreq_add_dev().

Signed-off-by: Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
cpufreq: Add helper to perform alloc/free of policy structure

Separate out the allocation of the cpufreq policy structure (along
with its error handling) to a helper function.  This makes the code
easier to read and also helps with some upcoming code reorganization.

Signed-off-by: Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
cpufreq: Extract non-interface related stuff from cpufreq_add_dev_interface()

cpufreq_add_dev_interface() includes the work of exposing the
interface to the device, as well as a lot of unrelated stuff.
Move the latter to cpufreq_add_dev(), where it is more appropriate.

Signed-off-by: Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
cpufreq: Extract the handover of policy CPU to a helper function

During CPU offline, when the policy->cpu is going down, some other CPU
present in the policy->cpus mask is nominated as the new policy->cpu.
Extract this functionality from __cpufreq_remove_dev() and implement
it in a helper function.  This helps in upcoming code reorganization.

Signed-off-by: Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
cpufreq: Introduce a flag ('frozen') to separate full vs temporary init/teardown

During suspend/resume we would like to do a lightweight init/teardown
of CPUs in the cpufreq subsystem and preserve certain things such as
sysfs files etc across suspend/resume transitions.  Add a flag called
'frozen' to help distinguish the full init/teardown sequence from the
lightweight one.

Signed-off-by: Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
cpufreq: Preserve policy structure across suspend/resume

To perform lightweight CPU-init and teardown in the cpufreq subsystem
during suspend/resume, we need to separate out the 2 main
functionalities of the cpufreq CPU hotplug callbacks, as outlined
below:

1. Init/tear-down of core cpufreq and CPU-specific components, which
   are critical to the correct functioning of the cpufreq subsystem.

2. Init/tear-down of cpufreq sysfs files during suspend/resume.

The first part requires accurate updates to the policy structure such
as its ->cpus and ->related_cpus masks, whereas the second part
requires that the policy->kobj structure is not released or
re-initialized during suspend/resume.

To handle both these requirements, we need to allow updates to the
policy structure throughout suspend/resume, but prevent the structure
from getting freed up.  Also, we must have a mechanism by which the
CPU-up callbacks can restore the policy structure without allocating
things afresh.  [That also helps avoid memory leaks.]

To achieve this, we use 2 schemes:
 a. Use a fallback per-cpu storage area for preserving the policy
    structures during suspend, so that they can be restored during
    resume appropriately.

 b. Use the 'frozen' flag to determine when to free or allocate the
    policy structure vs when to restore the policy from the saved
    fallback storage.  Thus we can successfully preserve the
    structure across suspend/resume.

Effectively, this helps us complete the separation of the
'lightweight' and the 'full' init/tear-down sequences in the cpufreq
subsystem, so that this can be made use of in the suspend/resume
scenario.

Signed-off-by: Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
cpufreq: Perform light-weight init/teardown during suspend/resume

Now that we have the infrastructure to perform a light-weight init/tear-down,
use that in the cpufreq CPU hotplug notifier when invoked from the
suspend/resume path.

This also ensures that the file permissions of the cpufreq sysfs files are
preserved across suspend/resume, something which commit a66b2e (cpufreq:
Preserve sysfs files across suspend/resume) originally intended to do, but
had to be reverted due to other problems.

Signed-off-by: Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Merge branch 'pm-cpufreq-tmp' into bleeding-edge

* pm-cpufreq-tmp:
  cpufreq: Perform light-weight init/teardown during suspend/resume
  cpufreq: Preserve policy structure across suspend/resume
  cpufreq: Introduce a flag ('frozen') to separate full vs temporary init/teardown
  cpufreq: Extract the handover of policy CPU to a helper function
  cpufreq: Extract non-interface related stuff from cpufreq_add_dev_interface()
  cpufreq: Add helper to perform alloc/free of policy structure
  cpufreq: Fix misplaced call to cpufreq_update_policy()