xref: /freebsd/sys/powerpc/powernv/opalcall.S (revision 47dd1d1b619cc035b82b49a91a25544309ff95ae)
1/*-
2 * Copyright (C) 2015 Nathan Whitehorn
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
18 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
21 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
22 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
23 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 *
25 * $FreeBSD$
26 */
27
28#include <machine/asm.h>
29
30GLOBAL(opal_entrypoint)
31	.llong	0
32GLOBAL(opal_data)
33	.llong	0
34GLOBAL(opal_msr)
35	.llong	0
36
37TOC_ENTRY(opal_entrypoint)
38TOC_ENTRY(opal_data)
39TOC_ENTRY(opal_msr)
40
41ASENTRY(opal_call)
42	/* Args:
43	 * r3: opal token
44	 * r4-r10 opal arguments
45	 */
46
47	/* Save call stuff on stack */
48	mflr	%r0
49	std	%r0,16(%r1)
50	std	%r2,-16(%r1)
51	mfcr	%r0
52	std	%r0,8(%r1)
53
54	/* Load OPAL entry information */
55	mr	%r0,%r3
56	ld	%r3,TOC_REF(opal_entrypoint)(%r2)
57	ld	%r3,0(%r3)
58	mtctr	%r3
59
60	/* Save MSR in non-volatile scratch register and turn off translation */
61	std	%r31,-8(%r1)
62	mfmsr	%r31
63
64	/* Load last bits from the TOC */
65	ld	%r3,TOC_REF(opal_msr)(%r2)
66	ld	%r3,0(%r3)
67	ld	%r2,TOC_REF(opal_data)(%r2)
68	ld	%r2,0(%r2)
69
70	mtmsrd	%r3
71	isync
72
73	/* Shift registers over */
74	mr	%r3,%r4
75	mr	%r4,%r5
76	mr	%r5,%r6
77	mr	%r6,%r7
78	mr	%r7,%r8
79	mr	%r8,%r9
80	mr	%r9,%r10
81
82	/* Call OPAL */
83	bctrl
84
85	/* Restore MSR */
86	mtmsrd	%r31
87	isync
88	ld	%r31,-8(%r1)
89
90	/* Restore call stuff from stack */
91	ld	%r0,16(%r1)
92	mtlr	%r0
93	ld	%r2,-16(%r1)
94	ld	%r0,8(%r1)
95	mtcr	%r0
96
97	/* And return */
98	blr
99
100