18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 28c2ecf20Sopenharmony_ci 38c2ecf20Sopenharmony_ci/* From asm-compat.h */ 48c2ecf20Sopenharmony_ci#define __stringify_in_c(...) #__VA_ARGS__ 58c2ecf20Sopenharmony_ci#define stringify_in_c(...) __stringify_in_c(__VA_ARGS__) " " 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci/* 88c2ecf20Sopenharmony_ci * Macros taken from arch/powerpc/include/asm/ppc-opcode.h and other 98c2ecf20Sopenharmony_ci * header files. 108c2ecf20Sopenharmony_ci */ 118c2ecf20Sopenharmony_ci#define ___PPC_RA(a) (((a) & 0x1f) << 16) 128c2ecf20Sopenharmony_ci#define ___PPC_RB(b) (((b) & 0x1f) << 11) 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci#define PPC_INST_COPY 0x7c20060c 158c2ecf20Sopenharmony_ci#define PPC_INST_PASTE 0x7c20070d 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci#define PPC_COPY(a, b) stringify_in_c(.long PPC_INST_COPY | \ 188c2ecf20Sopenharmony_ci ___PPC_RA(a) | ___PPC_RB(b)) 198c2ecf20Sopenharmony_ci#define PPC_PASTE(a, b) stringify_in_c(.long PPC_INST_PASTE | \ 208c2ecf20Sopenharmony_ci ___PPC_RA(a) | ___PPC_RB(b)) 218c2ecf20Sopenharmony_ci#define CR0_SHIFT 28 228c2ecf20Sopenharmony_ci#define CR0_MASK 0xF 238c2ecf20Sopenharmony_ci/* 248c2ecf20Sopenharmony_ci * Copy/paste instructions: 258c2ecf20Sopenharmony_ci * 268c2ecf20Sopenharmony_ci * copy RA,RB 278c2ecf20Sopenharmony_ci * Copy contents of address (RA) + effective_address(RB) 288c2ecf20Sopenharmony_ci * to internal copy-buffer. 298c2ecf20Sopenharmony_ci * 308c2ecf20Sopenharmony_ci * paste RA,RB 318c2ecf20Sopenharmony_ci * Paste contents of internal copy-buffer to the address 328c2ecf20Sopenharmony_ci * (RA) + effective_address(RB) 338c2ecf20Sopenharmony_ci */ 348c2ecf20Sopenharmony_cistatic inline int vas_copy(void *crb, int offset) 358c2ecf20Sopenharmony_ci{ 368c2ecf20Sopenharmony_ci asm volatile(PPC_COPY(%0, %1)";" 378c2ecf20Sopenharmony_ci : 388c2ecf20Sopenharmony_ci : "b" (offset), "b" (crb) 398c2ecf20Sopenharmony_ci : "memory"); 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci return 0; 428c2ecf20Sopenharmony_ci} 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_cistatic inline int vas_paste(void *paste_address, int offset) 458c2ecf20Sopenharmony_ci{ 468c2ecf20Sopenharmony_ci __u32 cr; 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci cr = 0; 498c2ecf20Sopenharmony_ci asm volatile(PPC_PASTE(%1, %2)";" 508c2ecf20Sopenharmony_ci "mfocrf %0, 0x80;" 518c2ecf20Sopenharmony_ci : "=r" (cr) 528c2ecf20Sopenharmony_ci : "b" (offset), "b" (paste_address) 538c2ecf20Sopenharmony_ci : "memory", "cr0"); 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci return (cr >> CR0_SHIFT) & CR0_MASK; 568c2ecf20Sopenharmony_ci} 57