sysfs: Functions for adding/removing symlinks to/from attribute groups

The most convenient way to expose ACPI power resources lists of a
device is to put symbolic links to sysfs directories representing
those resources into special attribute groups in the device's sysfs
directory.  For this purpose, it is necessary to be able to add
symbolic links to attribute groups.

For this reason, add sysfs helper functions for adding/removing
symbolic links to/from attribute groups, sysfs_add_link_to_group()
and sysfs_remove_link_from_group(), respectively.

This change set includes a build fix from David Rientjes.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
ACPI / PM: Expose lists of device power resources to user space

Since ACPI power resources are going to be used more extensively on
new hardware platforms, it is necessary to allow user space (powertop
in particular) to look at the lists of power resources corresponding
to different power states of devices for diagnostics and control
purposes.

For this reason, for each power state of an ACPI device node using
power resources create a special attribute group under the device
node's directory in sysfs containing links to sysfs directories
representing the power resources in that list.  The names of the
new attribute groups are "power_resources_<state>", where <state>
is the state name i.e. "D0", "D1", "D2", or "D3hot".

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
ACPI / PM: Fix consistency check for power resources during resume

During system resume we check if there are power resources that have
been turned off by the BIOS, but our reference counters for them
are nonzero (they need to be turned on then).  It turns out, however,
that we also need to check the opposite, i.e. if there are power
resources that have been turned on by the BIOS, but our reference
counters for them are zero (which means that no devices are going
to need them any time soon) and we should turn them off.

Make the power resources resume code do the additional check and
turn off the unused power resources as appropriate.

This change has been tested on HP nx6325.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
ACPI / scan: Make it clear that acpi_bus_trim() cannot fail

Since acpi_bus_trim() cannot fail, change its definition to a void
function, so that its callers don't check the return value in vain
and update the callers.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Yinghai Lu <yinghai@kernel.org>
Acked-by: Yasuaki Ishimatsu <isimatu.yasuaki@jp.fujitsu.com>
Acked-by: Toshi Kani <toshi.kani@hp.com>
cpufreq / exynos: update related_cpus mask to fix hotplug dump

commit "7e6087e595d3...cpufreq: Simplify cpufreq_add_dev()" started using
related_cpus mask to check if the current cpu is already managed.

With above commit hotplug in exynos gives following dump.

/ $ echo 1 > /sys/devices/system/cpu/cpu1/online
CPU1: Booted secondary processor
------------[ cut here ]------------
WARNING: at fs/sysfs/dir.c:536 sysfs_add_one+0x88/0xbc()
sysfs: cannot create duplicate filename '/devices/system/cpu/cpu0/cpufreq'
Modules linked in:
[<c0014560>] (unwind_backtrace+0x0/0xf8) from [<c0020214>] (warn_slowpath_common+0x4c/0x64)
[<c0020214>] (warn_slowpath_common+0x4c/0x64) from [<c00202c0>] (warn_slowpath_fmt+0x30/0x40)
[<c00202c0>] (warn_slowpath_fmt+0x30/0x40) from [<c00fb548>] (sysfs_add_one+0x88/0xbc)
[<c00fb548>] (sysfs_add_one+0x88/0xbc) from [<c00fc184>] (sysfs_do_create_link+0x110/0x208)
[<c00fc184>] (sysfs_do_create_link+0x110/0x208) from [<c019a868>] (cpufreq_add_dev_interface+0x218/0x2b0)
[<c019a868>] (cpufreq_add_dev_interface+0x218/0x2b0) from [<c019ac0c>] (cpufreq_add_dev+0x30c/0x448)
[<c019ac0c>] (cpufreq_add_dev+0x30c/0x448) from [<c01bdb84>] (cpufreq_cpu_callback+0x94/0x9c)
[<c01bdb84>] (cpufreq_cpu_callback+0x94/0x9c) from [<c0040fac>] (notifier_call_chain+0x44/0x84)
[<c0040fac>] (notifier_call_chain+0x44/0x84) from [<c0023484>] (__cpu_notify+0x28/0x44)
[<c0023484>] (__cpu_notify+0x28/0x44) from [<c01bc320>] (_cpu_up+0x104/0x154)
[<c01bc320>] (_cpu_up+0x104/0x154) from [<c01bc3d4>] (cpu_up+0x64/0x84)
[<c01bc3d4>] (cpu_up+0x64/0x84) from [<c01bafc8>] (store_online+0x50/0x78)
[<c01bafc8>] (store_online+0x50/0x78) from [<c016850c>] (dev_attr_store+0x18/0x24)
[<c016850c>] (dev_attr_store+0x18/0x24) from [<c00fa12c>] (sysfs_write_file+0x168/0x198)
[<c00fa12c>] (sysfs_write_file+0x168/0x198) from [<c00a7424>] (vfs_write+0x9c/0x140)
[<c00a7424>] (vfs_write+0x9c/0x140) from [<c00a76b0>] (sys_write+0x3c/0x70)
[<c00a76b0>] (sys_write+0x3c/0x70) from [<c000e2c0>] (ret_fast_syscall+0x0/0x30)
---[ end trace 3d002b0ded69f43b ]---

This patch fixes it by updating the related_cpus mask.

Signed-off-by: Inderpal Singh <inderpal.singh@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Merge branch 'acpi-scan' into bleeding-edge

* acpi-scan: (27 commits)
  ACPI / scan: Drop acpi_bus_add() and use acpi_bus_scan() instead
  ACPI: update ej_event interface to take acpi_device
  ACPI / scan: Add second pass to acpi_bus_trim()
  ACPI / scan: Change the implementation of acpi_bus_trim()
  ACPI / scan: Drop the second argument of acpi_bus_trim()
  ACPI / scan: Drop the second argument of acpi_device_unregister()
  ACPI: Remove the ops field from struct acpi_device
  ACPI: remove unused acpi_op_bind and acpi_op_unbind
  ACPI / scan: Fix check of device_attach() return value.
  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()
  ...
Merge branch 'acpica' into bleeding-edge

* acpica: (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-pm' into bleeding-edge

* acpi-pm: (25 commits)
  ACPI / PM: Fix device power state value after transitions to D3cold
  ACPI / PM: Use string "D3cold" to represent ACPI_STATE_D3_COLD
  ACPI / PM: Sanitize checks in acpi_power_on_resources()
  ACPI / PM: Always evaluate _PSn after setting power resources
  ACPI / PM: Introduce helper for executing _PSn methods
  ACPI / PM: Make acpi_bus_init_power() more robust
  ACPI / PM: Fix build for unusual combination of Kconfig options
  ACPI / PM: remove leading whitespace from #ifdef
  ACPI / PM: Consolidate suspend-specific and hibernate-specific code
  ACPI / PM: Move device power management functions to device_pm.c
  ACPI / PM: Common string representations of device power states
  ACPI / PM: More visible function for retrieving device power states
  ACPI / PM: Change the way power transitions to D3cold are carried out
  ACPI: Use system level attribute of wakeup power resources
  ACPI: Take power resource initialization errors into account
  ACPI / scan: Consolidate extraction of power resources lists
  ACPI / scan: Remove unnecessary initialization of local variables
  ACPI / scan: Move power state initialization to a separate routine
  ACPI / PM: Take order attribute of wakeup power resources into account
  ACPI / PM: Take order attribute of power resources into account
  ...
Merge branch 'acpi-lpss' into bleeding-edge

* acpi-lpss:
  ACPI / platform: create LPSS clocks if Lynxpoint devices are found during scan
  clk: x86: add support for Lynxpoint LPSS clocks
  x86: add support for Intel Low Power Subsystem
  ACPI / platform: fix comment about the platform device name
  ACPI: add support for CSRT table
drivers/pnp/pnpbios: remove depends on CONFIG_EXPERIMENTAL

The CONFIG_EXPERIMENTAL config item has not carried much meaning for a
while now and is almost always enabled by default. As agreed during the
Linux kernel summit, remove it from any "depends on" lines in Kconfigs.

Acked-by: Bjorn Helgaas <bhelgaas@google.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Merge branch 'pnp' into bleeding-edge

* pnp:
  drivers/pnp/pnpbios: remove depends on CONFIG_EXPERIMENTAL
Merge branch 'acpi-assorted' into bleeding-edge

* acpi-assorted:
  ACPI: fix obsolete comment in custom_method.c
  ACPI / thermal: Use mode to enable/disable kernel thermal processing
  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 'acpi-scan' into acpi-cleanup

The following commits depend on the 'acpi-scan' material.
ACPI: Remove useless type argument of driver .remove() operation

The second argument of ACPI driver .remove() operation is only used
by the ACPI processor driver and the value passed to that driver
through it is always available from the given struct acpi_device
object's removal_type field.  For this reason, the second ACPI driver
.remove() argument is in fact useless, so drop it.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Jiang Liu <jiang.liu@huawei.com>
Acked-by: Toshi Kani <toshi.kani@hp.com>
Acked-by: Yinghai Lu <yinghai@kernel.org>
ACPI: Drop device start operation that is not used

The ACPI device start operation, acpi_op_start, is never used, so
drop it.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Yinghai Lu <yinghai@kernel.org>
Acked-by: Toshi Kani <toshi.kani@hp.com>
Merge branch 'acpi-cleanup' into bleeding-edge

* acpi-cleanup:
  ACPI: Drop device start operation that is not used
  ACPI: Remove useless type argument of driver .remove() operation
PM / Domains: don't use [delayed_]work_pending()

There's no need to test whether a (delayed) work item is pending
before queueing, flushing or cancelling it, so remove work_pending()
tests used in those cases.

Signed-off-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
PM: don't use [delayed_]work_pending()

There's no need to test whether a (delayed) work item is pending
before queueing, flushing or cancelling it, so remove work_pending()
tests used in those cases.

Signed-off-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
PM / tracing: remove deprecated power trace API

The text in Documentation said it would be removed in 2.6.41;
the text in the Kconfig said removal in the 3.1 release.  Either
way you look at it, we are well past both, so push it off a cliff.

Note that the POWER_CSTATE and the POWER_PSTATE are part of the
legacy tracing API.  Remove all tracepoints which use these flags.
As can be seen from context, most already have a trace entry via
trace_cpu_idle anyways.

Also, the cpufreq/cpufreq.c PSTATE one is actually unpaired, as
compared to the CSTATE ones which all have a clear start/stop.
As part of this, the trace_power_frequency also becomes orphaned,
so it too is deleted.

Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
PM / Runtime: Add new helper function: pm_runtime_active()

This boolean function simply returns whether or not the runtime
status of the device is 'active'. The typical scenario is driver
calls pm_runtime_get firstly, then check pm_runtime_active in
atomic environment.

Also add entry to Documentation/power/runtime.txt

Signed-off-by: Yanmin Zhang <yanmin.zhang@intel.com>
Signed-off-by: ShuoX Liu <shuox.liu@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>