epow: Enable Environment and Power Warning support in FSP machines

EPOW informs about the environmental and power situation regarding the system, so
thet corrective action can be taken if required. Sapphire interacts in two distinct
ways with respect to EPOW events with FSP. FSP sends notification regarding changes
in system-panel status (classified as normal ,extended_1, extended_2 depending on
information contained). These intimations carry details regarding the prevailing EPOW
situation which triggered the notification in the first place. Sapphire can also query
about these system-panel status synchronously with FSP, independent of these explicit
notifications.

This patch enables processing of these explicit FSP notifications related to EPOW events
and map them to generic OPAL EPOW events which in turn get communicated to the host above.
Host communication has been implemented with OPAL message event interface with OPAL_MSG_EPOW
class messages. Host gets notified about the presence of valid EPOW status in the system
and subsequently calls for the complete EPOW system status through an exclussive OPAL calls
with the token OPAL_GET_EPOW_STATUS. This delivers the entire array of system EPOW status which
can then be processed in the host kernel to be forwarded up the stack.

Signed-off-by: Anshuman Khandual <khandual@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
sleep: Add workarounds for fast sleep

Add OPAL calls to setup xscom before and after sleep

V1:https://w3-01.ibm.com/stg/linux/ltc/mailinglists/pipermail/sapphire/2014-July/003170.html

Changes in V2:

1.Store L2 Fir Action register contents in primary thread's pointer
2.Enable secondary threads also to call opal, now that the synchronization
across threads of a core will be taken care of by the kernel. We can
hence safely call fastsleep in smt on mode.

Signed-off-by: Vaidyanathan Srinivasan <svaidy@linux.vnet.ibm.com>
Signed-off-by: Preeti U Murthy <preeti@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
slw: Enable fast sleep and deep winkle while initializing core

Power8 hardware supports deep idle states like sleep and winkle.
Both sleep and winkle have fast/deep modes.

Behaviour of each mode -
Fast sleep
	Stop clocks to Core and L2 cache.
	Drop Core & L2 voltage to retention.
	Leave shared L3 cache running

Deep sleep
	Power OFF the core and private L2 cache.
	Leave shared L3 cache running.

Fast winkle
	Stop clocks to entire chiplet.
	Drop chiplet voltage to retention.

Deep winkle
	Power OFF the entire chiplet.
	Requires restore/re-init to wakeup.

PM GP1 register allows us to select fast/deep modes for sleep and winkle.
Currently we are setting PM GP1 register to use fast sleep and fast winkle.
Change it such that, sleep will use fast mode and winkle will use deep mode.

With deep winkle enabled, hotplug framework in kernel can send cores to winkle
when cpus are offlined.

Signed-off-by: Shreyas B. Prabhu <shreyas@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
slw: Add winkle to cpuidle states in device tree

Clean up current implementation of adding idle states to device tree,
to make it more generic.

Add winkle to list of cpu-idle states if slw image is intact.

Signed-off-by: Shreyas B. Prabhu <shreyas@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
slw: patch hsprg0 for wakeup from winkle

Entering winkle results in hypervisor state loss. We can use PORE to
restore hypervisor registers. This opal call adds support for that.

This patch adds support for restoring HSPRG0. It can be extended to
restore other SPRs.

Signed-off-by: Shreyas B. Prabhu <shreyas@linux.vnet.ibm.com>
Signed-off-by: Vaidyanathan Srinivasan <svaidy@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
chiptod: Improvement to make quicker recovery from TOD errors.

When we get an HMI for TOD errors, chip TOD is generally not in running state.
Before we fix TOD state we need to do a quick check whether it is running or
not. But in current implementation instead of doing a quick check we do a
poll check for TOD running. This delays the process of fixing TOD state and
on a system with more cores per chip we may see soft lockup's even after
successful recovery. This patch fixes this issue by introducing a quick check
for TOD running state and provides quicker/faster recovery from TOD errors.

Signed-off-by: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
epow: Add a device-node to represent EPOW functionality

Which includes a list of the supported EPOW classes

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
slw: Small cleanup of state definitions

Don't bother writing 0*constant for the non-relevant instruction
bits in the various states and keep the "normal" sleep case in
add_cpu_idle_state_properties() so we don't have to add it back
later when we have a CPU that doesn't require the workaround.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
slw: Fix indication of whether sleep is supported

Don't enable it if HB doesn't allow it and fix backward logic in
the code that was supposed to disable it. Also print out more
diagnostic info.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>