ACPI / glue: Fix build with ACPI_GLUE_DEBUG set

If ACPI_GLUE_DEBUG is different from 0 (setting this requires a
manual change of glue.c), build breaks because of a leftover
reference to dev->acpi_handle in acpi_platform_notify().  Fix this
by using ACPI_HANDLE(dev) instead as appropriate.

[rjw: Subject and changelog]
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
cpufreq: handle SW coordinated CPUs

This patch fixes a bug that occurred when we had load on a secondary CPU
and the primary CPU was sleeping. Only one sampling timer was spawned
and it was spawned as a deferred timer on the primary CPU, so when a
secondary CPU had a change in load this was not detected by the cpufreq
governor (both ondemand and conservative).

This patch make sure that deferred timers are run on all CPUs in the
case of software controlled CPUs that run on the same frequency.

Signed-off-by: Rickard Andersson <rickard.andersson@stericsson.com>
Signed-off-by: Fabio Baltieri <fabio.baltieri@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
cpufreq: star/stop cpufreq timers on cpu hotplug

Add a CPU notifier to start and stop individual core timers on CPU
hotplug events when running on CPUs with SW coordinated frequency.

Signed-off-by: Fabio Baltieri <fabio.baltieri@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
cpufreq: ondemand: call dbs_check_cpu only when necessary

Modify ondemand timer to not resample CPU utilization if recently
sampled from another SW coordinated core.

Signed-off-by: Fabio Baltieri <fabio.baltieri@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
cpufreq: conservative: call dbs_check_cpu only when necessary

Modify conservative timer to not resample CPU utilization if recently
sampled from another SW coordinated core.

Signed-off-by: Fabio Baltieri <fabio.baltieri@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
cpufreq: ondemand: use all CPUs in update_sampling_rate

Modify update_sampling_rate() to check, and eventually immediately
schedule, all CPU's do_dbs_timer delayed work.

This is required in case of software coordinated CPUs, as we now have a
separate delayed work for each CPU.

Signed-off-by: Fabio Baltieri <fabio.baltieri@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
cpufreq: Manage only online cpus

cpufreq core doesn't manage offline cpus and if driver->init() has returned
mask including offline cpus, it may result in unwanted behavior by cpufreq core
or governors.

We need to get only online cpus in this mask. There are two places to fix this
mask, cpufreq core and cpufreq driver. It makes sense to do this at common place
and hence is done in core.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
cpufreq: Notify governors when cpus are hot-[un]plugged

Because cpufreq core and governors worry only about the online cpus, if a cpu is
hot [un]plugged, we must notify governors about it, otherwise be ready to expect
something unexpected.

We already have notifiers in the form of CPUFREQ_GOV_START/CPUFREQ_GOV_STOP, we
just need to call them now.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
cpufreq: Don't use cpu removed during cpufreq_driver_unregister

This is how the core works:
cpufreq_driver_unregister()
 - subsys_interface_unregister()
   - for_each_cpu() call cpufreq_remove_dev(), i.e. 0,1,2,3,4 when we
     unregister.

cpufreq_remove_dev():
 - Remove policy node
 - Call cpufreq_add_dev() for next cpu, sharing mask with removed cpu.
   i.e. When cpu 0 is removed, we call it for cpu 1. And when called for cpu 2,
   we call it for cpu 3.
   - cpufreq_add_dev() would call cpufreq_driver->init()
   - init would return mask as AND of 2, 3 and 4 for cluster A7.
   - cpufreq core would do online_cpu && policy->cpus
     Here is the BUG(). Because cpu hasn't died but we have just unregistered
     the cpufreq driver, online cpu would still have cpu 2 in it. And so thing
     go bad again.

Solution: Keep cpumask of cpus that are registered with cpufreq core and clear
	  cpus when we get a call from subsys_interface_unregister() via
	  cpufreq_remove_dev().

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
cpufreq: Simplify __cpufreq_remove_dev()

__cpufreq_remove_dev() is called on multiple occasions: cpufreq_driver
unregister and cpu removals.

Current implementation of this routine is overly complex without much need. If
the cpu to be removed is the policy->cpu, we remove the policy first and add all
other cpus again from policy->cpus and then finally call __cpufreq_remove_dev()
again to remove the cpu to be deleted. Haahhhh..

There exist a simple solution to removal of a cpu:
- Simply use the old policy structure
- update its fields like: policy->cpu, etc.
- notify any users of cpufreq, which depend on changing policy->cpu

Hence this patch, which tries to implement the above theory. It is tested well
by myself on ARM big.LITTLE TC2 SoC, which has 5 cores (2 A15 and 3 A7). Both
A15's share same struct policy and all A7's share same policy structure.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Tested-by: Shawn Guo <shawn.guo@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
cpufreq: Simplify cpufreq_add_dev()

Currently cpufreq_add_dev() firsts allocates policy, calls driver->init() and
then checks if this cpu is already managed or not. And if it is already managed,
free its policy.

We can save all this if we somehow know cpu is managed or not in advance.
policy->related_cpus contains list of all valid sibling cpus of policy->cpu. We
can check this to know if current cpu is already managed.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Tested-by: Shawn Guo <shawn.guo@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
cpufreq: SPEAr: Fix sparse warning for cpufreq driver

This patch fixes following sparse warning:

drivers/cpufreq/spear-cpufreq.c:33:5: warning: symbol 'spear_cpufreq_verify' was
not declared. Should it be static?

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Merge branch 'fixes-next' into linux-next

* fixes-next:
  ACPI / glue: Fix build with ACPI_GLUE_DEBUG set
  cpuidle: fix number of initialized/destroyed states
Merge branch 'acpi-scan' into linux-next

* acpi-scan:
  ACPI / scan: Treat power resources in a special way
  ACPI: Remove unused struct acpi_pci_root.id member
  ACPI: Drop ACPI device .bind() and .unbind() callbacks
  ACPI / PCI: Move the _PRT setup and cleanup code to pci-acpi.c
  ACPI / PCI: Rework the setup and cleanup of device wakeup
  ACPI: Add .setup() and .cleanup() callbacks to struct acpi_bus_type
  ACPI: Make acpi_bus_scan() and acpi_bus_add() take only one argument
  ACPI: Replace ACPI device add_type field with a match_driver flag
  ACPI: Drop the second argument of acpi_bus_scan()
  ACPI: Remove the arguments of acpi_bus_add() that are not used
  ACPI: Remove acpi_start_single_object() and acpi_bus_start()
  ACPI / PCI: Fold acpi_pci_root_start() into acpi_pci_root_add()
  ACPI: Change the ordering of acpi_bus_check_add()
  ACPI: Replace struct acpi_bus_ops with enum type
  ACPI: Reduce the usage of struct acpi_bus_ops
  ACPI: Make acpi_bus_add() and acpi_bus_start() visibly different
  ACPI: Change the ordering of PCI root bridge driver registrarion
  ACPI: Separate adding ACPI device objects from probing ACPI drivers
Merge branch 'acpi-scan-next' into linux-next

* acpi-scan-next:
  ACPI / scan: Fix check of device_attach() return value.
Merge branch 'acpica-next' into linux-next

* acpica-next: (49 commits)
  ACPICA: Cleanup table handler naming conflicts.
  ACPICA: Source restructuring: split large files into 8 new files.
  ACPICA: Cleanup PM_TIMER_FREQUENCY definition.
  ACPICA: Cleanup ACPI_DEBUG_PRINT macros to fix potential build breakages.
  ACPICA: Update version to 20121220.
  ACPICA: Interpreter: Fix Store() when implicit conversion is not possible.
  ACPICA: Resources: Split interrupt share/wake bits into two fields.
  ACPICA: Resources: Support for ACPI 5 wake bit in ExtendedInterrupt descriptor.
  ACPICA: Interpreter: Add warning if 64-bit constant appears in 32-bit table.
  ACPICA: Update ACPICA initialization messages.
  ACPICA: Namespace: Eliminate dot...dot output during initialization.
  ACPICA: Resource manager: Add support for ACPI 5 wake bit in IRQ descriptor.
  ACPICA: Fix possible memory leak in dispatcher error path.
  ACPICA: Update for non-configured ACPI_IS_DEBUG_ENABLED macro.
  ACPICA: iASL: Finish support for the TPM2 table.
  ACPICA: iASL: Finish support for CSRT table.
  ACPICA: Merge all debug output macros into a single file, acoutput.
  ACPICA: Deploy new ACPI_IS_DEBUG_ENABLED macro in debug output code.
  ACPICA: Update ACPI_IS_DEBUG_ENABLED macro.
  ACPICA: Eliminate superfluous return_UINT8 and return_UINT32 macros.
  ...
Merge branch 'acpi-assorted-next' into linux-next

* acpi-assorted-next:
  ACPI thermal: remove unnecessary newline from exception message
  ACPI sysfs: remove unnecessary newline from exception
  ACPI video: remove unnecessary newline from error messages
  ACPI: SRAT: report non-volatile memory in debug
  ACPI: Rework acpi_get_child() to be more efficient
Merge branch 'pnp-next' into linux-next

* pnp-next:
  PNPACPI: Use _CRS buffer directly as _SRS template
Merge branch 'pm-cpufreq-next' into linux-next

* pm-cpufreq-next:
  cpufreq: SPEAr: Fix sparse warning for cpufreq driver
  cpufreq: Simplify cpufreq_add_dev()
  cpufreq: Simplify __cpufreq_remove_dev()
  cpufreq: Don't use cpu removed during cpufreq_driver_unregister
  cpufreq: Notify governors when cpus are hot-[un]plugged
  cpufreq: Manage only online cpus
  cpufreq: ondemand: use all CPUs in update_sampling_rate
  cpufreq: conservative: call dbs_check_cpu only when necessary
  cpufreq: ondemand: call dbs_check_cpu only when necessary
  cpufreq: star/stop cpufreq timers on cpu hotplug
  cpufreq: handle SW coordinated CPUs
Merge branch 'pm-assorted-next' into linux-next

* pm-assorted-next:
  PM / tracing: remove deprecated power trace API
  PM: don't use [delayed_]work_pending()
  PM / Domains: don't use [delayed_]work_pending()