ACPI / dock: fix error return code in dock_add()

Fix to return -ENODEV in the acpi notify handler install error
handling case instead of 0, as done elsewhere in this function.

Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Merge branch 'acpi-cleanup-next' into bleeding-edge

* acpi-cleanup-next:
  ACPI / dock: fix error return code in dock_add()
ACPI: Cleanup sparse warning on acpi_os_initialize1()

This patch cleans up the following sparse warning:

# make C=2 drivers/acpi/osl.o
...
drivers/acpi/osl.c:1775:20: warning: symbol 'acpi_os_initialize1' was not declared. Should it be static?
...
  CC      drivers/acpi/osl.o

Signed-off-by: Lv Zheng <lv.zheng@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
ACPI / PCI: acpi_pci_irq_enable() must return an error if ACPI cannot map an IRQ.

Driver probe's currently do the following

	pci_enable_device();
	/* ... do some other init stuff, and eventually call ... */
	request_irq();

After pci_enable_device() is called it is assumed that the device's
irq value (pci_dev->irq) has been appropriately set on success.  This
value is passed into the request_irq() call.

In the case that ACPI is used to determine the irq value, it is
possible that the ACPI IRQ look up for a specific device fails and
success is returned by pci_enable_device().

The call sequence is:

pci_enable_device();
	-> pci_enable_device_flags();
		->do_pci_enable_device();
			-> pcibios_enable_device() which, if the device
			   does not use MSI calls
			   -> pcibios_enable_irq() which maps to
			      acpi_pci_irq_enable()
				-> acpi_pci_irq_lookup()

If acpi_pci_irq_lookup() cannot map the device's IRQ value it returns
NULL as an error.  The error is returned to acpi_pci_irq_enable(),
but is not propagated further.  This can result in the driver
returning success for pci_enable_device() and the driver probe
attempting to call request_irq() with dev->irq = 0.

This patch modifies acpi_pci_irq_enable() to return an error in the
case that an entry is not found in the ACPI tables.

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
ACPI / scan: Allow platform device creation without any IO resources

Currently, ACPI platform device creation is aborted when there
are no valid IO resources for the device.  This approach will not
work if the device has only GPIO as its resource or some custom
resources.

Remove zero resource check and allow platform device creation even
without any valid IO resources.

[rjw: Changelog]
Signed-off-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
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()
PM / Sleep: increase ftrace coverage in suspend/resume

Change where ftrace is disabled and re-enabled during system
suspend/resume to allow tracing of device driver pm callbacks.
Ftrace will now be turned off when suspend reaches
disable_nonboot_cpus() instead of at the very beginning of system
suspend.

Ftrace was disabled during suspend/resume back in 2008 by
Steven Rostedt as he discovered there was a conflict in the
enable_nonboot_cpus() call (see commit f42ac38 "ftrace: disable
tracing for suspend to ram").  This change preserves his fix by
disabling ftrace, but only at the function where it is known
to cause problems.

The new change allows tracing of the device level code for better
debug.

[rjw: Changelog]
Signed-off-by: Todd Brandt <todd.e.brandt@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
PM / Sleep: new trace event to print device suspend and resume times

A new trace event is added to PM events to print time it takes to
suspend and resume a device (during system suspend).  It generates a
trace message that includes device, driver, parent information in
addition to the type of PM ops invoked as well as the PM event and
error status from the PM ops.  Example trace below:

bash-2239  [000] ....   290.883035: device_pm_report_time: backlight
 acpi_video0 parent=0000:00:02.0 state=freeze ops=class nsecs=332 err=0
bash-2239  [000] ....   290.883041: device_pm_report_time: rfkill rf
kill3 parent=phy0 state=freeze ops=legacy class nsecs=216 err=0
bash-2239  [001] ....   290.973892: device_pm_report_time: ieee80211
 phy0 parent=0000:01:00.0 state=freeze ops=legacy class nsecs=90846477 err=0

bash-2239  [001] ....   293.660129: device_pm_report_time: ieee80211 phy0 parent=0000:01:00.0 state=restore ops=legacy class nsecs=101295162 err=0
bash-2239  [001] ....   293.660147: device_pm_report_time: rfkill rfkill3 parent=phy0 state=restore ops=legacy class nsecs=1804 err=0
bash-2239  [001] ....   293.660157: device_pm_report_time: backlight acpi_video0 parent=0000:00:02.0 state=restore ops=class nsecs=757 err=0

Signed-off-by: Shuah Khan <shuah.kh@samsung.com>
Reviewed-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Merge branch 'pm-sleep-next' into bleeding-edge

* pm-sleep-next:
  PM / Sleep: new trace event to print device suspend and resume times
  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 'cpufreq-tmp' into bleeding-edge

* 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()