1/*
2 * PowerNV OPAL API wrappers
3 *
4 * Copyright 2011 IBM Corp.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 */
11
12#include <linux/jump_label.h>
13#include <asm/ppc_asm.h>
14#include <asm/hvcall.h>
15#include <asm/asm-offsets.h>
16#include <asm/opal.h>
17#include <asm/asm-compat.h>
18#include <asm/feature-fixups.h>
19
20	.section ".text"
21
22/*
23 * r3-r10		- OPAL call arguments
24 * STK_PARAM(R11)	- OPAL opcode
25 * STK_PARAM(R12)	- MSR to restore
26 */
27_GLOBAL_TOC(__opal_call)
28	mflr	r0
29	std	r0,PPC_LR_STKOFF(r1)
30	ld	r12,STK_PARAM(R12)(r1)
31	li	r0,MSR_IR|MSR_DR|MSR_LE
32	andc	r12,r12,r0
33	LOAD_REG_ADDR(r11, opal_return)
34	mtlr	r11
35	LOAD_REG_ADDR(r11, opal)
36	ld	r2,0(r11)
37	ld	r11,8(r11)
38	mtspr	SPRN_HSRR0,r11
39	mtspr	SPRN_HSRR1,r12
40	/* set token to r0 */
41	ld	r0,STK_PARAM(R11)(r1)
42	hrfid
43opal_return:
44	/*
45	 * Restore MSR on OPAL return. The MSR is set to big-endian.
46	 */
47#ifdef __BIG_ENDIAN__
48	ld	r11,STK_PARAM(R12)(r1)
49	mtmsrd	r11
50#else
51	/* Endian can only be switched with rfi, must byte reverse MSR load */
52	.short 0x4039	 /* li r10,STK_PARAM(R12)		*/
53	.byte (STK_PARAM(R12) >> 8) & 0xff
54	.byte STK_PARAM(R12) & 0xff
55
56	.long 0x280c6a7d /* ldbrx r11,r10,r1			*/
57	.long 0x05009f42 /* bcl 20,31,$+4			*/
58	.long 0xa602487d /* mflr r10				*/
59	.long 0x14004a39 /* addi r10,r10,20			*/
60	.long 0xa64b5a7d /* mthsrr0 r10				*/
61	.long 0xa64b7b7d /* mthsrr1 r11				*/
62	.long 0x2402004c /* hrfid				*/
63#endif
64	ld	r2,PACATOC(r13)
65	ld	r0,PPC_LR_STKOFF(r1)
66	mtlr	r0
67	blr
68