-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
powerpc/boot: Add OPAL console to epapr wrappers
This patch adds an OPAL console backend to the powerpc boot wrapper so that decompression failures inside the wrapper can be reported to the user. This is important since it typically indicates data corruption in the firmware and other nasty things. Currently this only works when building a little endian kernel. When compiling a 64 bit BE kernel the wrapper is always build 32 bit to be compatible with some 32 bit firmwares. BE support will be added at a later date. Another limitation of this is that only the "raw" type of OPAL console is supported, however machines that provide a hvsi console also provide a raw console so this is not an issue in practice. Actually-written-by: Benjamin Herrenschmidt <benh@kernel.crashing.org> Signed-off-by: Oliver O'Halloran <oohall@gmail.com> [mpe: Move #ifdef __powerpc64__ to avoid warnings on 32-bit] Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
- Loading branch information
Oliver O'Halloran
authored and
Michael Ellerman
committed
Jul 5, 2016
1 parent
faf7882
commit 656ad58
Showing
7 changed files
with
175 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright (c) 2016 IBM Corporation. | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; either version | ||
* 2 of the License, or (at your option) any later version. | ||
*/ | ||
|
||
#include "ppc_asm.h" | ||
#include "../include/asm/opal-api.h" | ||
|
||
.text | ||
|
||
#define OPAL_CALL(name, token) \ | ||
.globl name; \ | ||
name: \ | ||
li r0, token; \ | ||
b opal_call; | ||
|
||
opal_call: | ||
mflr r11 | ||
std r11,16(r1) | ||
mfcr r12 | ||
stw r12,8(r1) | ||
mr r13,r2 | ||
|
||
/* Set opal return address */ | ||
ld r11,opal_return@got(r2) | ||
mtlr r11 | ||
mfmsr r12 | ||
|
||
/* switch to BE when we enter OPAL */ | ||
li r11,MSR_LE | ||
andc r12,r12,r11 | ||
mtspr SPRN_HSRR1,r12 | ||
|
||
/* load the opal call entry point and base */ | ||
ld r11,opal@got(r2) | ||
ld r12,8(r11) | ||
ld r2,0(r11) | ||
mtspr SPRN_HSRR0,r12 | ||
hrfid | ||
|
||
opal_return: | ||
FIXUP_ENDIAN | ||
mr r2,r13; | ||
lwz r11,8(r1); | ||
ld r12,16(r1) | ||
mtcr r11; | ||
mtlr r12 | ||
blr | ||
|
||
OPAL_CALL(opal_console_write, OPAL_CONSOLE_WRITE); | ||
OPAL_CALL(opal_console_read, OPAL_CONSOLE_READ); | ||
OPAL_CALL(opal_console_write_buffer_space, OPAL_CONSOLE_WRITE_BUFFER_SPACE); | ||
OPAL_CALL(opal_poll_events, OPAL_POLL_EVENTS); | ||
OPAL_CALL(opal_console_flush, OPAL_CONSOLE_FLUSH); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* Copyright (c) 2016 IBM Corporation. | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; either version | ||
* 2 of the License, or (at your option) any later version. | ||
*/ | ||
|
||
#include "ops.h" | ||
#include "stdio.h" | ||
#include "io.h" | ||
#include <libfdt.h> | ||
#include "../include/asm/opal-api.h" | ||
|
||
#ifdef __powerpc64__ | ||
|
||
/* Global OPAL struct used by opal-call.S */ | ||
struct opal { | ||
u64 base; | ||
u64 entry; | ||
} opal; | ||
|
||
static u32 opal_con_id; | ||
|
||
int64_t opal_console_write(int64_t term_number, u64 *length, const u8 *buffer); | ||
int64_t opal_console_read(int64_t term_number, uint64_t *length, u8 *buffer); | ||
int64_t opal_console_write_buffer_space(uint64_t term_number, uint64_t *length); | ||
int64_t opal_console_flush(uint64_t term_number); | ||
int64_t opal_poll_events(uint64_t *outstanding_event_mask); | ||
|
||
static int opal_con_open(void) | ||
{ | ||
return 0; | ||
} | ||
|
||
static void opal_con_putc(unsigned char c) | ||
{ | ||
int64_t rc; | ||
uint64_t olen, len; | ||
|
||
do { | ||
rc = opal_console_write_buffer_space(opal_con_id, &olen); | ||
len = be64_to_cpu(olen); | ||
if (rc) | ||
return; | ||
opal_poll_events(NULL); | ||
} while (len < 1); | ||
|
||
|
||
olen = cpu_to_be64(1); | ||
opal_console_write(opal_con_id, &olen, &c); | ||
} | ||
|
||
static void opal_con_close(void) | ||
{ | ||
opal_console_flush(opal_con_id); | ||
} | ||
|
||
static void opal_init(void) | ||
{ | ||
void *opal_node; | ||
|
||
opal_node = finddevice("/ibm,opal"); | ||
if (!opal_node) | ||
return; | ||
if (getprop(opal_node, "opal-base-address", &opal.base, sizeof(u64)) < 0) | ||
return; | ||
opal.base = be64_to_cpu(opal.base); | ||
if (getprop(opal_node, "opal-entry-address", &opal.entry, sizeof(u64)) < 0) | ||
return; | ||
opal.entry = be64_to_cpu(opal.entry); | ||
} | ||
|
||
int opal_console_init(void *devp, struct serial_console_data *scdp) | ||
{ | ||
opal_init(); | ||
|
||
if (devp) { | ||
int n = getprop(devp, "reg", &opal_con_id, sizeof(u32)); | ||
if (n != sizeof(u32)) | ||
return -1; | ||
opal_con_id = be32_to_cpu(opal_con_id); | ||
} else | ||
opal_con_id = 0; | ||
|
||
scdp->open = opal_con_open; | ||
scdp->putc = opal_con_putc; | ||
scdp->close = opal_con_close; | ||
|
||
return 0; | ||
} | ||
#else | ||
int opal_console_init(void *devp, struct serial_console_data *scdp) | ||
{ | ||
return -1; | ||
} | ||
#endif /* __powerpc64__ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters