Skip to content

Commit daea117

Browse files
committed
powerpc/powernv: Support for OPAL console
This adds a udbg and an hvc console backend for supporting a console using the OPAL console interfaces. On OPAL v1 we have hvc0 mapped to whatever console the system was configured for (network or hvsi serial port) via the service processor. On OPAL v2 we have hvcN mapped to the Nth console provided by OPAL which generally corresponds to: hvc0 : network console (raw protocol) hvc1 : serial port S1 (hvsi) hvc2 : serial port S2 (hvsi) Note: At this point, early debug console only works with OPAL v1 and shouldn't be enabled in a normal kernel. Signed-off-by: Benjamin Herrenschmidt <[email protected]>
1 parent 6e35d5d commit daea117

File tree

11 files changed

+517
-22
lines changed

11 files changed

+517
-22
lines changed

arch/powerpc/Kconfig.debug

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,27 @@ config PPC_EARLY_DEBUG_PS3GELIC
265265
Select this to enable early debugging for the PlayStation3 via
266266
UDP broadcasts sent out through the Ethernet port.
267267

268+
config PPC_EARLY_DEBUG_OPAL_RAW
269+
bool "OPAL raw console"
270+
depends on HVC_OPAL
271+
help
272+
Select this to enable early debugging for the PowerNV platform
273+
using a "raw" console
274+
275+
config PPC_EARLY_DEBUG_OPAL_HVSI
276+
bool "OPAL hvsi console"
277+
depends on HVC_OPAL
278+
help
279+
Select this to enable early debugging for the PowerNV platform
280+
using an "hvsi" console
281+
268282
endchoice
269283

284+
config PPC_EARLY_DEBUG_OPAL
285+
def_bool y
286+
depends on PPC_EARLY_DEBUG_OPAL_RAW || PPC_EARLY_DEBUG_OPAL_HVSI
287+
288+
270289
config PPC_EARLY_DEBUG_HVSI_VTERMNO
271290
hex "vterm number to use with early debug HVSI"
272291
depends on PPC_EARLY_DEBUG_LPAR_HVSI
@@ -275,6 +294,18 @@ config PPC_EARLY_DEBUG_HVSI_VTERMNO
275294
You probably want 0x30000000 for your first serial port and
276295
0x30000001 for your second one
277296

297+
config PPC_EARLY_DEBUG_OPAL_VTERMNO
298+
hex "vterm number to use with OPAL early debug"
299+
depends on PPC_EARLY_DEBUG_OPAL
300+
default "0"
301+
help
302+
This correspond to which /dev/hvcN you want to use for early
303+
debug.
304+
305+
On OPAL v1 (takeover) this should always be 0
306+
On OPAL v2, this will be 0 for network console and 1 or 2 for
307+
the machine built-in serial ports.
308+
278309
config PPC_EARLY_DEBUG_44x_PHYSLOW
279310
hex "Low 32 bits of early debug UART physical address"
280311
depends on PPC_EARLY_DEBUG_44x

arch/powerpc/include/asm/opal.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,11 @@ extern void hvc_opal_init_early(void);
425425
extern int early_init_dt_scan_opal(unsigned long node, const char *uname,
426426
int depth, void *data);
427427

428+
extern int opal_get_chars(uint32_t vtermno, char *buf, int count);
429+
extern int opal_put_chars(uint32_t vtermno, const char *buf, int total_len);
430+
431+
extern void hvc_opal_init_early(void);
432+
428433
#endif /* __ASSEMBLY__ */
429434

430435
#endif /* __OPAL_H */

arch/powerpc/include/asm/udbg.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ extern void __init udbg_init_cpm(void);
5555
extern void __init udbg_init_usbgecko(void);
5656
extern void __init udbg_init_wsp(void);
5757
extern void __init udbg_init_ps3gelic(void);
58+
extern void __init udbg_init_debug_opal_raw(void);
59+
extern void __init udbg_init_debug_opal_hvsi(void);
5860

5961
#endif /* __KERNEL__ */
6062
#endif /* _ASM_POWERPC_UDBG_H */

arch/powerpc/kernel/head_64.S

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@
5353
* 2. The kernel is entered at __start
5454
* -or- For OPAL entry:
5555
* 1. The MMU is off, processor in HV mode, primary CPU enters at 0
56-
* with device-tree in gpr3
56+
* with device-tree in gpr3. We also get OPAL base in r8 and
57+
* entry in r9 for debugging purposes
5758
* 2. Secondary processors enter at 0x60 with PIR in gpr3
5859
*
5960
* For iSeries:
@@ -335,6 +336,11 @@ _GLOBAL(__start_initialization_multiplatform)
335336
/* Save parameters */
336337
mr r31,r3
337338
mr r30,r4
339+
#ifdef CONFIG_PPC_EARLY_DEBUG_OPAL
340+
/* Save OPAL entry */
341+
mr r28,r8
342+
mr r29,r9
343+
#endif
338344

339345
#ifdef CONFIG_PPC_BOOK3E
340346
bl .start_initialization_book3e
@@ -711,6 +717,12 @@ _INIT_STATIC(start_here_multiplatform)
711717
bdnz 3b
712718
4:
713719

720+
#ifdef CONFIG_PPC_EARLY_DEBUG_OPAL
721+
/* Setup OPAL entry */
722+
std r28,0(r11);
723+
std r29,8(r11);
724+
#endif
725+
714726
#ifndef CONFIG_PPC_BOOK3E
715727
mfmsr r6
716728
ori r6,r6,MSR_RI

arch/powerpc/kernel/udbg.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ void __init udbg_early_init(void)
6969
udbg_init_wsp();
7070
#elif defined(CONFIG_PPC_EARLY_DEBUG_PS3GELIC)
7171
udbg_init_ps3gelic();
72+
#elif defined(CONFIG_PPC_EARLY_DEBUG_OPAL_RAW)
73+
udbg_init_debug_opal_raw();
74+
#elif defined(CONFIG_PPC_EARLY_DEBUG_OPAL_HVSI)
75+
udbg_init_debug_opal_hvsi();
7276
#endif
7377

7478
#ifdef CONFIG_PPC_EARLY_DEBUG

arch/powerpc/platforms/powernv/opal.c

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ int opal_get_chars(uint32_t vtermno, char *buf, int count)
6767
u64 evt;
6868

6969
if (!opal.entry)
70-
return 0;
70+
return -ENODEV;
7171
opal_poll_events(&evt);
7272
if ((evt & OPAL_EVENT_CONSOLE_INPUT) == 0)
7373
return 0;
@@ -81,31 +81,38 @@ int opal_get_chars(uint32_t vtermno, char *buf, int count)
8181
int opal_put_chars(uint32_t vtermno, const char *data, int total_len)
8282
{
8383
int written = 0;
84-
s64 len, rc = OPAL_BUSY;
84+
s64 len, rc;
8585
unsigned long flags;
8686
u64 evt;
8787

8888
if (!opal.entry)
89-
return 0;
89+
return -ENODEV;
9090

9191
/* We want put_chars to be atomic to avoid mangling of hvsi
9292
* packets. To do that, we first test for room and return
93-
* -EAGAIN if there isn't enough
93+
* -EAGAIN if there isn't enough.
94+
*
95+
* Unfortunately, opal_console_write_buffer_space() doesn't
96+
* appear to work on opal v1, so we just assume there is
97+
* enough room and be done with it
9498
*/
9599
spin_lock_irqsave(&opal_write_lock, flags);
96-
rc = opal_console_write_buffer_space(vtermno, &len);
97-
if (rc || len < total_len) {
98-
spin_unlock_irqrestore(&opal_write_lock, flags);
99-
/* Closed -> drop characters */
100-
if (rc)
101-
return total_len;
102-
opal_poll_events(&evt);
103-
return -EAGAIN;
100+
if (firmware_has_feature(FW_FEATURE_OPALv2)) {
101+
rc = opal_console_write_buffer_space(vtermno, &len);
102+
if (rc || len < total_len) {
103+
spin_unlock_irqrestore(&opal_write_lock, flags);
104+
/* Closed -> drop characters */
105+
if (rc)
106+
return total_len;
107+
opal_poll_events(&evt);
108+
return -EAGAIN;
109+
}
104110
}
105111

106112
/* We still try to handle partial completions, though they
107113
* should no longer happen.
108114
*/
115+
rc = OPAL_BUSY;
109116
while(total_len > 0 && (rc == OPAL_BUSY ||
110117
rc == OPAL_BUSY_EVENT || rc == OPAL_SUCCESS)) {
111118
len = total_len;

arch/powerpc/platforms/powernv/setup.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,12 @@
2929
#include <asm/machdep.h>
3030
#include <asm/firmware.h>
3131
#include <asm/xics.h>
32+
#include <asm/opal.h>
3233

3334
#include "powernv.h"
3435

3536
static void __init pnv_setup_arch(void)
3637
{
37-
/* Force console to hvc for now until we have sorted out the
38-
* real console situation for the platform. This will make
39-
* hvc_udbg work at least.
40-
*/
41-
add_preferred_console("hvc", 0, NULL);
42-
4338
/* Initialize SMP */
4439
pnv_smp_init();
4540

@@ -55,7 +50,12 @@ static void __init pnv_setup_arch(void)
5550

5651
static void __init pnv_init_early(void)
5752
{
58-
/* XXX IOMMU */
53+
#ifdef CONFIG_HVC_OPAL
54+
if (firmware_has_feature(FW_FEATURE_OPAL))
55+
hvc_opal_init_early();
56+
else
57+
#endif
58+
add_preferred_console("hvc", 0, NULL);
5959
}
6060

6161
static void __init pnv_init_IRQ(void)

drivers/tty/hvc/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ config HVC_ISERIES
3434
help
3535
iSeries machines support a hypervisor virtual console.
3636

37+
config HVC_OPAL
38+
bool "OPAL Console support"
39+
depends on PPC_POWERNV
40+
select HVC_DRIVER
41+
select HVC_IRQ
42+
default y
43+
help
44+
PowerNV machines running under OPAL need that driver to get a console
45+
3746
config HVC_RTAS
3847
bool "IBM RTAS Console support"
3948
depends on PPC_RTAS

drivers/tty/hvc/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
obj-$(CONFIG_HVC_CONSOLE) += hvc_vio.o hvsi_lib.o
2+
obj-$(CONFIG_HVC_OPAL) += hvc_opal.o hvsi_lib.o
23
obj-$(CONFIG_HVC_OLD_HVSI) += hvsi.o
34
obj-$(CONFIG_HVC_ISERIES) += hvc_iseries.o
45
obj-$(CONFIG_HVC_RTAS) += hvc_rtas.o

0 commit comments

Comments
 (0)