xref: /freebsd/sys/powerpc/powernv/opalcall.S (revision 148a8da8)
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	addis	%r3,%r2,TOC_REF(opal_entrypoint)@ha
57	ld	%r3,TOC_REF(opal_entrypoint)@l(%r3)
58	ld	%r3,0(%r3)
59	mtctr	%r3
60
61	/* Save MSR in non-volatile scratch register and turn off translation */
62	std	%r31,-8(%r1)
63	mfmsr	%r31
64
65	/* Load last bits from the TOC */
66	addis	%r3,%r2,TOC_REF(opal_msr)@ha
67	ld	%r3,TOC_REF(opal_msr)@l(%r3)
68	ld	%r3,0(%r3)
69	addis	%r2,%r2,TOC_REF(opal_data)@ha
70	ld	%r2,TOC_REF(opal_data)@l(%r2)
71	ld	%r2,0(%r2)
72
73	mtmsrd	%r3
74	isync
75
76	/* Shift registers over */
77	mr	%r3,%r4
78	mr	%r4,%r5
79	mr	%r5,%r6
80	mr	%r6,%r7
81	mr	%r7,%r8
82	mr	%r8,%r9
83	mr	%r9,%r10
84
85	/* Call OPAL */
86	bctrl
87
88	/* Restore MSR */
89	mtmsrd	%r31
90	isync
91	ld	%r31,-8(%r1)
92
93	/* Restore call stuff from stack */
94	ld	%r0,16(%r1)
95	mtlr	%r0
96	ld	%r2,-16(%r1)
97	ld	%r0,8(%r1)
98	mtcr	%r0
99
100	/* And return */
101	blr
102
103