xref: /openbmc/linux/arch/powerpc/boot/opal-calls.S (revision dab3b8f4)
12874c5fdSThomas Gleixner/* SPDX-License-Identifier: GPL-2.0-or-later */
2656ad58eSOliver O'Halloran/*
3656ad58eSOliver O'Halloran * Copyright (c) 2016 IBM Corporation.
4656ad58eSOliver O'Halloran */
5656ad58eSOliver O'Halloran
6656ad58eSOliver O'Halloran#include "ppc_asm.h"
7656ad58eSOliver O'Halloran#include "../include/asm/opal-api.h"
8656ad58eSOliver O'Halloran
9656ad58eSOliver O'Halloran	.text
10656ad58eSOliver O'Halloran
11a1ff5741SOliver O'Halloran	.globl opal_kentry
12a1ff5741SOliver O'Halloranopal_kentry:
13a1ff5741SOliver O'Halloran	/* r3 is the fdt ptr */
14a1ff5741SOliver O'Halloran	mtctr r4
15a1ff5741SOliver O'Halloran	li	r4, 0
16a1ff5741SOliver O'Halloran	li	r5, 0
17a1ff5741SOliver O'Halloran	li	r6, 0
18a1ff5741SOliver O'Halloran	li	r7, 0
19*dab3b8f4SNicholas Piggin	LOAD_REG_ADDR(r11, opal)
20a1ff5741SOliver O'Halloran	ld	r8,0(r11)
21a1ff5741SOliver O'Halloran	ld	r9,8(r11)
22a1ff5741SOliver O'Halloran	bctr
23a1ff5741SOliver O'Halloran
24656ad58eSOliver O'Halloran#define OPAL_CALL(name, token)				\
25656ad58eSOliver O'Halloran	.globl name;					\
26656ad58eSOliver O'Halloranname:							\
27656ad58eSOliver O'Halloran	li	r0, token;				\
28656ad58eSOliver O'Halloran	b	opal_call;
29656ad58eSOliver O'Halloran
30656ad58eSOliver O'Halloranopal_call:
31656ad58eSOliver O'Halloran	mflr	r11
32656ad58eSOliver O'Halloran	std	r11,16(r1)
33656ad58eSOliver O'Halloran	mfcr	r12
34656ad58eSOliver O'Halloran	stw	r12,8(r1)
35656ad58eSOliver O'Halloran	mr	r13,r2
36656ad58eSOliver O'Halloran
37656ad58eSOliver O'Halloran	/* Set opal return address */
38*dab3b8f4SNicholas Piggin	LOAD_REG_ADDR(r11, opal_return)
39656ad58eSOliver O'Halloran	mtlr	r11
40656ad58eSOliver O'Halloran	mfmsr	r12
41656ad58eSOliver O'Halloran
42656ad58eSOliver O'Halloran	/* switch to BE when we enter OPAL */
43656ad58eSOliver O'Halloran	li	r11,MSR_LE
44656ad58eSOliver O'Halloran	andc	r12,r12,r11
45656ad58eSOliver O'Halloran	mtspr	SPRN_HSRR1,r12
46656ad58eSOliver O'Halloran
47656ad58eSOliver O'Halloran	/* load the opal call entry point and base */
48*dab3b8f4SNicholas Piggin	LOAD_REG_ADDR(r11, opal)
49656ad58eSOliver O'Halloran	ld	r12,8(r11)
50656ad58eSOliver O'Halloran	ld	r2,0(r11)
51656ad58eSOliver O'Halloran	mtspr	SPRN_HSRR0,r12
52656ad58eSOliver O'Halloran	hrfid
53656ad58eSOliver O'Halloran
54656ad58eSOliver O'Halloranopal_return:
55656ad58eSOliver O'Halloran	FIXUP_ENDIAN
56656ad58eSOliver O'Halloran	mr	r2,r13;
57656ad58eSOliver O'Halloran	lwz	r11,8(r1);
58656ad58eSOliver O'Halloran	ld	r12,16(r1)
59656ad58eSOliver O'Halloran	mtcr	r11;
60656ad58eSOliver O'Halloran	mtlr	r12
61656ad58eSOliver O'Halloran	blr
62656ad58eSOliver O'Halloran
63656ad58eSOliver O'HalloranOPAL_CALL(opal_console_write,			OPAL_CONSOLE_WRITE);
64656ad58eSOliver O'HalloranOPAL_CALL(opal_console_read,			OPAL_CONSOLE_READ);
65656ad58eSOliver O'HalloranOPAL_CALL(opal_console_write_buffer_space,	OPAL_CONSOLE_WRITE_BUFFER_SPACE);
66656ad58eSOliver O'HalloranOPAL_CALL(opal_poll_events,			OPAL_POLL_EVENTS);
67656ad58eSOliver O'HalloranOPAL_CALL(opal_console_flush,			OPAL_CONSOLE_FLUSH);
68