Linux-libre 4.19.20-gnu
[librecmc/linux-libre.git] / arch / powerpc / boot / opal-calls.S
1 /*
2  * Copyright (c) 2016 IBM Corporation.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version
7  * 2 of the License, or (at your option) any later version.
8  */
9
10 #include "ppc_asm.h"
11 #include "../include/asm/opal-api.h"
12
13         .text
14
15         .globl opal_kentry
16 opal_kentry:
17         /* r3 is the fdt ptr */
18         mtctr r4
19         li      r4, 0
20         li      r5, 0
21         li      r6, 0
22         li      r7, 0
23         ld      r11,opal@got(r2)
24         ld      r8,0(r11)
25         ld      r9,8(r11)
26         bctr
27
28 #define OPAL_CALL(name, token)                          \
29         .globl name;                                    \
30 name:                                                   \
31         li      r0, token;                              \
32         b       opal_call;
33
34 opal_call:
35         mflr    r11
36         std     r11,16(r1)
37         mfcr    r12
38         stw     r12,8(r1)
39         mr      r13,r2
40
41         /* Set opal return address */
42         ld      r11,opal_return@got(r2)
43         mtlr    r11
44         mfmsr   r12
45
46         /* switch to BE when we enter OPAL */
47         li      r11,MSR_LE
48         andc    r12,r12,r11
49         mtspr   SPRN_HSRR1,r12
50
51         /* load the opal call entry point and base */
52         ld      r11,opal@got(r2)
53         ld      r12,8(r11)
54         ld      r2,0(r11)
55         mtspr   SPRN_HSRR0,r12
56         hrfid
57
58 opal_return:
59         FIXUP_ENDIAN
60         mr      r2,r13;
61         lwz     r11,8(r1);
62         ld      r12,16(r1)
63         mtcr    r11;
64         mtlr    r12
65         blr
66
67 OPAL_CALL(opal_console_write,                   OPAL_CONSOLE_WRITE);
68 OPAL_CALL(opal_console_read,                    OPAL_CONSOLE_READ);
69 OPAL_CALL(opal_console_write_buffer_space,      OPAL_CONSOLE_WRITE_BUFFER_SPACE);
70 OPAL_CALL(opal_poll_events,                     OPAL_POLL_EVENTS);
71 OPAL_CALL(opal_console_flush,                   OPAL_CONSOLE_FLUSH);