GNU Linux-libre 4.19.211-gnu1
[releases.git] / arch / powerpc / platforms / powernv / copy-paste.h
1 /*
2  * Copyright 2016-17 IBM Corp.
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 #include <asm/ppc-opcode.h>
10 #include <asm/reg.h>
11
12 /*
13  * Copy/paste instructions:
14  *
15  *      copy RA,RB
16  *              Copy contents of address (RA) + effective_address(RB)
17  *              to internal copy-buffer.
18  *
19  *      paste RA,RB
20  *              Paste contents of internal copy-buffer to the address
21  *              (RA) + effective_address(RB)
22  */
23 static inline int vas_copy(void *crb, int offset)
24 {
25         asm volatile(PPC_COPY(%0, %1)";"
26                 :
27                 : "b" (offset), "b" (crb)
28                 : "memory");
29
30         return 0;
31 }
32
33 static inline int vas_paste(void *paste_address, int offset)
34 {
35         u32 cr;
36
37         cr = 0;
38         asm volatile(PPC_PASTE(%1, %2)";"
39                 "mfocrf %0, 0x80;"
40                 : "=r" (cr)
41                 : "b" (offset), "b" (paste_address)
42                 : "memory", "cr0");
43
44         /* We mask with 0xE to ignore SO */
45         return (cr >> CR0_SHIFT) & 0xE;
46 }