18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef __ASM_PARISC_ALTERNATIVE_H
38c2ecf20Sopenharmony_ci#define __ASM_PARISC_ALTERNATIVE_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci#define ALT_COND_ALWAYS		0x80	/* always replace instruction */
68c2ecf20Sopenharmony_ci#define ALT_COND_NO_SMP		0x01	/* when running UP instead of SMP */
78c2ecf20Sopenharmony_ci#define ALT_COND_NO_DCACHE	0x02	/* if system has no d-cache  */
88c2ecf20Sopenharmony_ci#define ALT_COND_NO_ICACHE	0x04	/* if system has no i-cache  */
98c2ecf20Sopenharmony_ci#define ALT_COND_NO_SPLIT_TLB	0x08	/* if split_tlb == 0  */
108c2ecf20Sopenharmony_ci#define ALT_COND_NO_IOC_FDC	0x10	/* if I/O cache does not need flushes */
118c2ecf20Sopenharmony_ci#define ALT_COND_RUN_ON_QEMU	0x20	/* if running on QEMU */
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#define INSN_PxTLB	0x02		/* modify pdtlb, pitlb */
148c2ecf20Sopenharmony_ci#define INSN_NOP	0x08000240	/* nop */
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci#include <linux/init.h>
198c2ecf20Sopenharmony_ci#include <linux/types.h>
208c2ecf20Sopenharmony_ci#include <linux/stddef.h>
218c2ecf20Sopenharmony_ci#include <linux/stringify.h>
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_cistruct alt_instr {
248c2ecf20Sopenharmony_ci	s32 orig_offset;	/* offset to original instructions */
258c2ecf20Sopenharmony_ci	s32 len;		/* end of original instructions */
268c2ecf20Sopenharmony_ci	u32 cond;		/* see ALT_COND_XXX */
278c2ecf20Sopenharmony_ci	u32 replacement;	/* replacement instruction or code */
288c2ecf20Sopenharmony_ci};
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_civoid set_kernel_text_rw(int enable_read_write);
318c2ecf20Sopenharmony_civoid apply_alternatives_all(void);
328c2ecf20Sopenharmony_civoid apply_alternatives(struct alt_instr *start, struct alt_instr *end,
338c2ecf20Sopenharmony_ci	const char *module_name);
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci/* Alternative SMP implementation. */
368c2ecf20Sopenharmony_ci#define ALTERNATIVE(cond, replacement)		"!0:"	\
378c2ecf20Sopenharmony_ci	".section .altinstructions, \"aw\"	!"	\
388c2ecf20Sopenharmony_ci	".word (0b-4-.), 1, " __stringify(cond) ","	\
398c2ecf20Sopenharmony_ci		__stringify(replacement) "	!"	\
408c2ecf20Sopenharmony_ci	".previous"
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci#else
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci/* to replace one single instructions by a new instruction */
458c2ecf20Sopenharmony_ci#define ALTERNATIVE(from, to, cond, replacement)\
468c2ecf20Sopenharmony_ci	.section .altinstructions, "aw"	!	\
478c2ecf20Sopenharmony_ci	.word (from - .), (to - from)/4	!	\
488c2ecf20Sopenharmony_ci	.word cond, replacement		!	\
498c2ecf20Sopenharmony_ci	.previous
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci/* to replace multiple instructions by new code */
528c2ecf20Sopenharmony_ci#define ALTERNATIVE_CODE(from, num_instructions, cond, new_instr_ptr)\
538c2ecf20Sopenharmony_ci	.section .altinstructions, "aw"	!	\
548c2ecf20Sopenharmony_ci	.word (from - .), -num_instructions !	\
558c2ecf20Sopenharmony_ci	.word cond, (new_instr_ptr - .)	!	\
568c2ecf20Sopenharmony_ci	.previous
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci#endif  /*  __ASSEMBLY__  */
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci#endif /* __ASM_PARISC_ALTERNATIVE_H */
61