epow: Change the logging of the FSP async messages

Right now, all the FSP initiated EPOW messages get logged. SPCN
configuration change message comes as part of the extended 1 panel
status type of FSP message all the time and fills up the log buffer
like the following.

------------Sapphire log---------------
EPOW: Received extended 1 EPOW from FSP
EPOW: Received extended 1 EPOW from FSP
EPOW: Received extended 1 EPOW from FSP
EPOW: Received extended 1 EPOW from FSP
EPOW: Received extended 1 EPOW from FSP
EPOW: Received extended 1 EPOW from FSP
EPOW: Received extended 1 EPOW from FSP
EPOW: Received extended 1 EPOW from FSP
EPOW: Received extended 1 EPOW from FSP
EPOW: Received extended 1 EPOW from FSP
EPOW: Received extended 1 EPOW from FSP
EPOW: Received extended 1 EPOW from FSP
EPOW: Received extended 1 EPOW from FSP
EPOW: Received extended 1 EPOW from FSP
EPOW: Received extended 1 EPOW from FSP
EPOW: Received extended 1 EPOW from FSP
---------------------------------------

Even without being acted upon, SPCN configuration change does not
take down the system. With this patch only the messages, which need
to be acted upon will get logged.

Signed-off-by: Anshuman Khandual <khandual@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
epow: Fix mbox command encoding to remove FSP orphan responses

This patch changes the EPOW related mbox commands encoding to
make sure FSP message response structure is allocated. So that
when the command returns from FSP, it can be handled appropriately
and orphan response will not be logged. This also adds some more
in-code documentation explaining why panel status request based
handshaking is required with the FSP.

Signed-off-by: Anshuman Khandual <khandual@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
epow: Change how the old and the new system epow status are maintained

This patch changes the way how the old and the new system epow status
are maintained. After receiving FSP EPOW async message, only reset
those parts of system EPOW status which will be updated with the
new FSP async message. This patch also fixes a problem with comparing
the contents of the new and the old system EPOW status.

Signed-off-by: Anshuman Khandual <khandual@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
slw: Extend opal_slw_set_reg to all supported sprs

Commit 95932150: "slw: patch hsprg0 for wakeup from winkle" added
OPAL call for HSPRG0 to be patched via slw.
Extend it to all the sprs supported in libpore.

Signed-off-by: Shreyas B. Prabhu <shreyas@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
ATTN: Set up attention area to handle attention

At present CPU control area ntuple in SPIRA structure is NULL.
ATTN component in Service Processor side checks for this field and if its empty,
it logs hardcoded SRC (0xBB821410) and generates SYSDUMP. So we have 1 SRC for
all failure (assert call) from OPAL side. This makes difficult to debug the issue.

Service processor provides attention area interface (FIPS PHyp Attentions spec),
so that we can pass SRC and user data (error message) to service processor.
This will helps us identify different failures in OPAL.

This patch enables attention area and provides interface (update_sp_attn_area())
to add src and user data (error message) through assert macro.

Attention SRC format:
	1st byte - Opal src type
	2-4 bytes - Holds the address of the assert function call

Signed-off-by: Aruna Balakrishnaiah <aruna@linux.vnet.ibm.com>
Signed-off-by: Vasant Hegde <hegdevasant@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
ELOG: Make sure we do not cross read buffer size

Signed-off-by: Vasant Hegde <hegdevasant@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Initial code for timestamps in log

This is the initial patch for having timestamps in the log.

It currently only wraps prerror to our prlog() function and thus only
(very slightly) modifies bootup log.

we use the timebase as an indication of the progression of time. It is
not perfect, and is indeed reset back to zero during boot, but it should
serve adequately for our needs of "approximately this much time elapsed
between log entries".

Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
replace printf() with console log, level 5 aka INFO messages

Replace the libc printf implementation with a wrapper that does
fancy log things such as display timestamp and the log level.

Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
add full suite of log priorities: EMERG through DEBUG

The idea is to use prlog(PR_EMERG|PR_ALERT|...|PR_WARNING|..|PR_TRACE)
instead of random printf() calls, so that they can be properly
filtered for different console implementations (may only want trace level
calls in memory console rather than over serial port).

We remap PR_PRINTF to PR_NOTICE (5) rather than the absolute value 5.

Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Build with -ffreestanding so we can override printf

It turns out that GCC will use a builtin printf implementation that
directly wraps vfprintf (or something), so when I tried to do my
neat trick of overriding printf() with a call to vprlog() adding the
timebase and default log level to the log message, it wouldn't work as
GCC was being helpful.

This change to compiler options will mean that other places where GCC
is being helpful and using builtins rather than our implementations will
go away, potentially helping/hurting us.

We probably want to build with -ffreestanding anyway though.

Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Use small macros for PHB debug/log messages

Save stack space, remove code and improve logging all in one handy patch.

Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Use single printf call per FSP LED rather than multiple

Means that we print things correctly in console log with timestamps.

Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Use PR_EMERG log priority when printing backtrace

If we're printing a backtrace, things have probably gone horribly,
horribly wrong - highest log priority.

Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Use PR_EMERG priority in (part of) assert()

When handling assert and we're going to fail, get the message out
with a high priority.

Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Use PR_EMERG priority in assert() codepath

Moving assert_fail() out of libc and into core/utils.c so that we can
sanely call prlog(PR_EMERG).

We shorten it from three fputs calls down to one prlog() call.

This may increase the number of cycles and stack usage for when we
hit an assert, which may not be desirable.

Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Trivial typo fix: case -> cause

Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Write log messages with log_level > PR_NOTICE only to in memory log

We modify write() (adding console_write()) which calls down to
a modified __flush_console() which can now decide if it's flushing
the added console contents to the console drivers or not.

A future patch may add support for changing PR_NOTICE to some other level

Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Make log level thresholds dynamic in debug_descriptor rather than static

This enables (advanced) users to vary what level of output they want
at runtime in the memory console and through console drivers (fsp/uart)

You can vary two things by poking in the debug descriptor:
a) what log level is printed at all
  e.g. only turn on PR_TRACE at specific points during runtime
b) what log level goes out the fsp/uart console
  defaults to PR_PRINTF

We use two 4bit numbers (1 byte) for this in debug descriptor (saving
some space, not needlessly wasting space that we may want in future).

The default is 0x75 (7=PR_DEBUG to in memory console, 5=PR_PRINTF to drivers)

If you write 0x77 you will get debug info on uart/fsp console as
well as in memory. If you write 0x95 you get PR_INSANE in memory but
still only PR_NOTICE through drivers.

People who write something like 0x1f will get a very quiet boot indeed.

A future patch would be to (when possible) peek at device tree entries
for if we should change the default.

A future patch would add an OPAL API to get/set this.

Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Preliminary in-tree documentation for console-log.

Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
FSP: Make mbx error messages more verbose

... helps figure out what the cause of the failure was.

Signed-off-by: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Acked-by: Stewart Smith <stewart@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>