Linux Audio

Check our new training course

Loading...
v6.2
  1/* SPDX-License-Identifier: GPL-2.0 */
  2#ifndef _ASM_S390_ALTERNATIVE_H
  3#define _ASM_S390_ALTERNATIVE_H
  4
  5#ifndef __ASSEMBLY__
  6
  7#include <linux/types.h>
  8#include <linux/stddef.h>
  9#include <linux/stringify.h>
 10
 11struct alt_instr {
 12	s32 instr_offset;	/* original instruction */
 13	s32 repl_offset;	/* offset to replacement instruction */
 14	u16 facility;		/* facility bit set for replacement */
 15	u8  instrlen;		/* length of original instruction */
 
 16} __packed;
 17
 18void apply_alternative_instructions(void);
 19void apply_alternatives(struct alt_instr *start, struct alt_instr *end);
 20
 21/*
 22 * +---------------------------------+
 23 * |661:			     |662:
 24 * | oldinstr			     |
 25 * +---------------------------------+
 
 
 
 
 
 26 *
 27 * .altinstr_replacement section
 28 * +---------------------------------+
 29 * |6641:			     |6651:
 30 * | alternative instr 1	     |
 31 * +---------------------------------+
 32 * |6642:			     |6652:
 33 * | alternative instr 2	     |
 34 * +---------------------------------+
 
 35 *
 36 * .altinstructions section
 37 * +---------------------------------+
 38 * | alt_instr entries for each      |
 39 * | alternative instr		     |
 40 * +---------------------------------+
 41 */
 42
 43#define b_altinstr(num)		"664"#num
 44#define e_altinstr(num)		"665"#num
 
 
 45#define oldinstr_len		"662b-661b"
 
 46#define altinstr_len(num)	e_altinstr(num)"b-"b_altinstr(num)"b"
 47
 48#define OLDINSTR(oldinstr) \
 49	"661:\n\t" oldinstr "\n662:\n"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 50
 51#define ALTINSTR_ENTRY(facility, num)					\
 52	"\t.long 661b - .\n"			/* old instruction */	\
 53	"\t.long " b_altinstr(num)"b - .\n"	/* alt instruction */	\
 54	"\t.word " __stringify(facility) "\n"	/* facility bit    */	\
 55	"\t.byte " oldinstr_len "\n"		/* instruction len */	\
 56	"\t.org . - (" oldinstr_len ") + (" altinstr_len(num) ")\n"	\
 57	"\t.org . - (" altinstr_len(num) ") + (" oldinstr_len ")\n"
 58
 59#define ALTINSTR_REPLACEMENT(altinstr, num)	/* replacement */	\
 60	b_altinstr(num)":\n\t" altinstr "\n" e_altinstr(num) ":\n"
 
 61
 62/* alternative assembly primitive: */
 63#define ALTERNATIVE(oldinstr, altinstr, facility) \
 64	".pushsection .altinstr_replacement, \"ax\"\n"			\
 65	ALTINSTR_REPLACEMENT(altinstr, 1)				\
 66	".popsection\n"							\
 67	OLDINSTR(oldinstr)						\
 68	".pushsection .altinstructions,\"a\"\n"				\
 69	ALTINSTR_ENTRY(facility, 1)					\
 70	".popsection\n"
 71
 72#define ALTERNATIVE_2(oldinstr, altinstr1, facility1, altinstr2, facility2)\
 73	".pushsection .altinstr_replacement, \"ax\"\n"			\
 74	ALTINSTR_REPLACEMENT(altinstr1, 1)				\
 75	ALTINSTR_REPLACEMENT(altinstr2, 2)				\
 76	".popsection\n"							\
 77	OLDINSTR(oldinstr)						\
 78	".pushsection .altinstructions,\"a\"\n"				\
 79	ALTINSTR_ENTRY(facility1, 1)					\
 80	ALTINSTR_ENTRY(facility2, 2)					\
 81	".popsection\n"
 82
 83/*
 84 * Alternative instructions for different CPU types or capabilities.
 85 *
 86 * This allows to use optimized instructions even on generic binary
 87 * kernels.
 88 *
 89 * oldinstr is padded with jump and nops at compile time if altinstr is
 90 * longer. altinstr is padded with jump and nops at run-time during patching.
 91 *
 92 * For non barrier like inlines please define new variants
 93 * without volatile and memory clobber.
 94 */
 95#define alternative(oldinstr, altinstr, facility)			\
 96	asm_inline volatile(ALTERNATIVE(oldinstr, altinstr, facility) : : : "memory")
 97
 98#define alternative_2(oldinstr, altinstr1, facility1, altinstr2, facility2) \
 99	asm_inline volatile(ALTERNATIVE_2(oldinstr, altinstr1, facility1,   \
100				   altinstr2, facility2) ::: "memory")
101
102/* Alternative inline assembly with input. */
103#define alternative_input(oldinstr, newinstr, feature, input...)	\
104	asm_inline volatile (ALTERNATIVE(oldinstr, newinstr, feature)	\
105		: : input)
106
107/* Like alternative_input, but with a single output argument */
108#define alternative_io(oldinstr, altinstr, facility, output, input...)	\
109	asm_inline volatile(ALTERNATIVE(oldinstr, altinstr, facility)	\
110		: output : input)
111
112/* Use this macro if more than one output parameter is needed. */
113#define ASM_OUTPUT2(a...) a
114
115/* Use this macro if clobbers are needed without inputs. */
116#define ASM_NO_INPUT_CLOBBER(clobber...) : clobber
117
118#endif /* __ASSEMBLY__ */
119
120#endif /* _ASM_S390_ALTERNATIVE_H */
v5.4
  1/* SPDX-License-Identifier: GPL-2.0 */
  2#ifndef _ASM_S390_ALTERNATIVE_H
  3#define _ASM_S390_ALTERNATIVE_H
  4
  5#ifndef __ASSEMBLY__
  6
  7#include <linux/types.h>
  8#include <linux/stddef.h>
  9#include <linux/stringify.h>
 10
 11struct alt_instr {
 12	s32 instr_offset;	/* original instruction */
 13	s32 repl_offset;	/* offset to replacement instruction */
 14	u16 facility;		/* facility bit set for replacement */
 15	u8  instrlen;		/* length of original instruction */
 16	u8  replacementlen;	/* length of new instruction */
 17} __packed;
 18
 19void apply_alternative_instructions(void);
 20void apply_alternatives(struct alt_instr *start, struct alt_instr *end);
 21
 22/*
 23 * |661:       |662:	  |6620      |663:
 24 * +-----------+---------------------+
 25 * | oldinstr  | oldinstr_padding    |
 26 * |	       +----------+----------+
 27 * |	       |	  |	     |
 28 * |	       | >6 bytes |6/4/2 nops|
 29 * |	       |6 bytes jg----------->
 30 * +-----------+---------------------+
 31 *		 ^^ static padding ^^
 32 *
 33 * .altinstr_replacement section
 34 * +---------------------+-----------+
 35 * |6641:			     |6651:
 36 * | alternative instr 1	     |
 37 * +-----------+---------+- - - - - -+
 38 * |6642:		 |6652:      |
 39 * | alternative instr 2 | padding
 40 * +---------------------+- - - - - -+
 41 *			  ^ runtime ^
 42 *
 43 * .altinstructions section
 44 * +---------------------------------+
 45 * | alt_instr entries for each      |
 46 * | alternative instr		     |
 47 * +---------------------------------+
 48 */
 49
 50#define b_altinstr(num)	"664"#num
 51#define e_altinstr(num)	"665"#num
 52
 53#define e_oldinstr_pad_end	"663"
 54#define oldinstr_len		"662b-661b"
 55#define oldinstr_total_len	e_oldinstr_pad_end"b-661b"
 56#define altinstr_len(num)	e_altinstr(num)"b-"b_altinstr(num)"b"
 57#define oldinstr_pad_len(num) \
 58	"-(((" altinstr_len(num) ")-(" oldinstr_len ")) > 0) * " \
 59	"((" altinstr_len(num) ")-(" oldinstr_len "))"
 60
 61#define INSTR_LEN_SANITY_CHECK(len)					\
 62	".if " len " > 254\n"						\
 63	"\t.error \"cpu alternatives does not support instructions "	\
 64		"blocks > 254 bytes\"\n"				\
 65	".endif\n"							\
 66	".if (" len ") %% 2\n"						\
 67	"\t.error \"cpu alternatives instructions length is odd\"\n"	\
 68	".endif\n"
 69
 70#define OLDINSTR_PADDING(oldinstr, num)					\
 71	".if " oldinstr_pad_len(num) " > 6\n"				\
 72	"\tjg " e_oldinstr_pad_end "f\n"				\
 73	"6620:\n"							\
 74	"\t.fill (" oldinstr_pad_len(num) " - (6620b-662b)) / 2, 2, 0x0700\n" \
 75	".else\n"							\
 76	"\t.fill " oldinstr_pad_len(num) " / 6, 6, 0xc0040000\n"	\
 77	"\t.fill " oldinstr_pad_len(num) " %% 6 / 4, 4, 0x47000000\n"	\
 78	"\t.fill " oldinstr_pad_len(num) " %% 6 %% 4 / 2, 2, 0x0700\n"	\
 79	".endif\n"
 80
 81#define OLDINSTR(oldinstr, num)						\
 82	"661:\n\t" oldinstr "\n662:\n"					\
 83	OLDINSTR_PADDING(oldinstr, num)					\
 84	e_oldinstr_pad_end ":\n"					\
 85	INSTR_LEN_SANITY_CHECK(oldinstr_len)
 86
 87#define OLDINSTR_2(oldinstr, num1, num2)				\
 88	"661:\n\t" oldinstr "\n662:\n"					\
 89	".if " altinstr_len(num1) " < " altinstr_len(num2) "\n"		\
 90	OLDINSTR_PADDING(oldinstr, num2)				\
 91	".else\n"							\
 92	OLDINSTR_PADDING(oldinstr, num1)				\
 93	".endif\n"							\
 94	e_oldinstr_pad_end ":\n"					\
 95	INSTR_LEN_SANITY_CHECK(oldinstr_len)
 96
 97#define ALTINSTR_ENTRY(facility, num)					\
 98	"\t.long 661b - .\n"			/* old instruction */	\
 99	"\t.long " b_altinstr(num)"b - .\n"	/* alt instruction */	\
100	"\t.word " __stringify(facility) "\n"	/* facility bit    */	\
101	"\t.byte " oldinstr_total_len "\n"	/* source len	   */	\
102	"\t.byte " altinstr_len(num) "\n"	/* alt instruction len */
 
103
104#define ALTINSTR_REPLACEMENT(altinstr, num)	/* replacement */	\
105	b_altinstr(num)":\n\t" altinstr "\n" e_altinstr(num) ":\n"	\
106	INSTR_LEN_SANITY_CHECK(altinstr_len(num))
107
108/* alternative assembly primitive: */
109#define ALTERNATIVE(oldinstr, altinstr, facility) \
110	".pushsection .altinstr_replacement, \"ax\"\n"			\
111	ALTINSTR_REPLACEMENT(altinstr, 1)				\
112	".popsection\n"							\
113	OLDINSTR(oldinstr, 1)						\
114	".pushsection .altinstructions,\"a\"\n"				\
115	ALTINSTR_ENTRY(facility, 1)					\
116	".popsection\n"
117
118#define ALTERNATIVE_2(oldinstr, altinstr1, facility1, altinstr2, facility2)\
119	".pushsection .altinstr_replacement, \"ax\"\n"			\
120	ALTINSTR_REPLACEMENT(altinstr1, 1)				\
121	ALTINSTR_REPLACEMENT(altinstr2, 2)				\
122	".popsection\n"							\
123	OLDINSTR_2(oldinstr, 1, 2)					\
124	".pushsection .altinstructions,\"a\"\n"				\
125	ALTINSTR_ENTRY(facility1, 1)					\
126	ALTINSTR_ENTRY(facility2, 2)					\
127	".popsection\n"
128
129/*
130 * Alternative instructions for different CPU types or capabilities.
131 *
132 * This allows to use optimized instructions even on generic binary
133 * kernels.
134 *
135 * oldinstr is padded with jump and nops at compile time if altinstr is
136 * longer. altinstr is padded with jump and nops at run-time during patching.
137 *
138 * For non barrier like inlines please define new variants
139 * without volatile and memory clobber.
140 */
141#define alternative(oldinstr, altinstr, facility)			\
142	asm volatile(ALTERNATIVE(oldinstr, altinstr, facility) : : : "memory")
143
144#define alternative_2(oldinstr, altinstr1, facility1, altinstr2, facility2) \
145	asm volatile(ALTERNATIVE_2(oldinstr, altinstr1, facility1,	    \
146				   altinstr2, facility2) ::: "memory")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147
148#endif /* __ASSEMBLY__ */
149
150#endif /* _ASM_S390_ALTERNATIVE_H */