xref: /kvm-unit-tests/lib/s390x/asm/interrupt.h (revision 54674bae100c6840171d9df5ba98721403a5493f)
16c9f99dfSJanosch Frank /* SPDX-License-Identifier: GPL-2.0-only */
24da93626SDavid Hildenbrand /*
34da93626SDavid Hildenbrand  * Copyright (c) 2017 Red Hat Inc
44da93626SDavid Hildenbrand  *
54da93626SDavid Hildenbrand  * Authors:
64da93626SDavid Hildenbrand  *  David Hildenbrand <david@redhat.com>
74da93626SDavid Hildenbrand  */
84da93626SDavid Hildenbrand #ifndef _ASMS390X_IRQ_H_
94da93626SDavid Hildenbrand #define _ASMS390X_IRQ_H_
104da93626SDavid Hildenbrand #include <asm/arch_def.h>
114da93626SDavid Hildenbrand 
12df121a0cSJanosch Frank #define EXT_IRQ_EMERGENCY_SIG	0x1201
13df121a0cSJanosch Frank #define EXT_IRQ_EXTERNAL_CALL	0x1202
148ead801eSJanosch Frank #define EXT_IRQ_SERVICE_SIG	0x2401
158ead801eSJanosch Frank 
162652cb00SClaudio Imbrenda #define TEID_ASCE_PRIMARY	0
172652cb00SClaudio Imbrenda #define TEID_ASCE_AR		1
182652cb00SClaudio Imbrenda #define TEID_ASCE_SECONDARY	2
192652cb00SClaudio Imbrenda #define TEID_ASCE_HOME		3
202652cb00SClaudio Imbrenda 
212652cb00SClaudio Imbrenda union teid {
222652cb00SClaudio Imbrenda 	unsigned long val;
23c2c1663aSJanis Schoetterl-Glausch 	union {
24c2c1663aSJanis Schoetterl-Glausch 		/* common fields DAT exc & protection exc */
252652cb00SClaudio Imbrenda 		struct {
26c2c1663aSJanis Schoetterl-Glausch 			uint64_t addr			: 52 -  0;
27c2c1663aSJanis Schoetterl-Glausch 			uint64_t acc_exc_fetch_store	: 54 - 52;
28c2c1663aSJanis Schoetterl-Glausch 			uint64_t side_effect_acc	: 55 - 54;
29c2c1663aSJanis Schoetterl-Glausch 			uint64_t /* reserved */		: 62 - 55;
30c2c1663aSJanis Schoetterl-Glausch 			uint64_t asce_id		: 64 - 62;
31c2c1663aSJanis Schoetterl-Glausch 		};
32c2c1663aSJanis Schoetterl-Glausch 		/* DAT exc */
33c2c1663aSJanis Schoetterl-Glausch 		struct {
34c2c1663aSJanis Schoetterl-Glausch 			uint64_t /* pad */		: 61 -  0;
35c2c1663aSJanis Schoetterl-Glausch 			uint64_t dat_move_page		: 62 - 61;
36c2c1663aSJanis Schoetterl-Glausch 		};
37c2c1663aSJanis Schoetterl-Glausch 		/* suppression on protection */
38c2c1663aSJanis Schoetterl-Glausch 		struct {
39c2c1663aSJanis Schoetterl-Glausch 			uint64_t /* pad */		: 60 -  0;
40c2c1663aSJanis Schoetterl-Glausch 			uint64_t sop_acc_list		: 61 - 60;
41c2c1663aSJanis Schoetterl-Glausch 			uint64_t sop_teid_predictable	: 62 - 61;
42c2c1663aSJanis Schoetterl-Glausch 		};
43c2c1663aSJanis Schoetterl-Glausch 		/* enhanced suppression on protection 2 */
44c2c1663aSJanis Schoetterl-Glausch 		struct {
45c2c1663aSJanis Schoetterl-Glausch 			uint64_t /* pad */		: 56 -  0;
46c2c1663aSJanis Schoetterl-Glausch 			uint64_t esop2_prot_code_0	: 57 - 56;
47c2c1663aSJanis Schoetterl-Glausch 			uint64_t /* pad */		: 60 - 57;
48c2c1663aSJanis Schoetterl-Glausch 			uint64_t esop2_prot_code_1	: 61 - 60;
49c2c1663aSJanis Schoetterl-Glausch 			uint64_t esop2_prot_code_2	: 62 - 61;
502652cb00SClaudio Imbrenda 		};
512652cb00SClaudio Imbrenda 	};
52c2c1663aSJanis Schoetterl-Glausch };
53c2c1663aSJanis Schoetterl-Glausch 
54c2c1663aSJanis Schoetterl-Glausch enum prot_code {
55c2c1663aSJanis Schoetterl-Glausch 	PROT_KEY_OR_LAP,
56c2c1663aSJanis Schoetterl-Glausch 	PROT_DAT,
57c2c1663aSJanis Schoetterl-Glausch 	PROT_KEY,
58c2c1663aSJanis Schoetterl-Glausch 	PROT_ACC_LIST,
59c2c1663aSJanis Schoetterl-Glausch 	PROT_LAP,
60c2c1663aSJanis Schoetterl-Glausch 	PROT_IEP,
61c2c1663aSJanis Schoetterl-Glausch 	PROT_NUM_CODES /* Must always be last */
62c2c1663aSJanis Schoetterl-Glausch };
63c2c1663aSJanis Schoetterl-Glausch 
64c2c1663aSJanis Schoetterl-Glausch static inline enum prot_code teid_esop2_prot_code(union teid teid)
65c2c1663aSJanis Schoetterl-Glausch {
66c2c1663aSJanis Schoetterl-Glausch 	int code = (teid.esop2_prot_code_0 << 2 |
67c2c1663aSJanis Schoetterl-Glausch 		    teid.esop2_prot_code_1 << 1 |
68c2c1663aSJanis Schoetterl-Glausch 		    teid.esop2_prot_code_2);
69c2c1663aSJanis Schoetterl-Glausch 
70c2c1663aSJanis Schoetterl-Glausch 	assert(code < PROT_NUM_CODES);
71c2c1663aSJanis Schoetterl-Glausch 	return (enum prot_code)code;
72c2c1663aSJanis Schoetterl-Glausch }
732652cb00SClaudio Imbrenda 
744e5dd758SClaudio Imbrenda void register_pgm_cleanup_func(void (*f)(struct stack_frame_int *));
754e5dd758SClaudio Imbrenda void register_ext_cleanup_func(void (*f)(struct stack_frame_int *));
7636cfc0b7SJanosch Frank void handle_pgm_int(struct stack_frame_int *stack);
7736cfc0b7SJanosch Frank void handle_ext_int(struct stack_frame_int *stack);
780f87a91aSJanosch Frank void handle_mcck_int(void);
790f87a91aSJanosch Frank void handle_io_int(void);
800f87a91aSJanosch Frank void handle_svc_int(void);
814da93626SDavid Hildenbrand void expect_pgm_int(void);
82df121a0cSJanosch Frank void expect_ext_int(void);
833db880b6SDavid Hildenbrand uint16_t clear_pgm_int(void);
844da93626SDavid Hildenbrand void check_pgm_int_code(uint16_t code);
854da93626SDavid Hildenbrand 
86fedfd112SNico Boehr void irq_set_dat_mode(bool use_dat, enum address_space as);
87fedfd112SNico Boehr 
882667b05eSThomas Huth /* Activate low-address protection */
892667b05eSThomas Huth static inline void low_prot_enable(void)
902667b05eSThomas Huth {
911b2c0437SClaudio Imbrenda 	ctl_set_bit(0, CTL0_LOW_ADDR_PROT);
922667b05eSThomas Huth }
932667b05eSThomas Huth 
942667b05eSThomas Huth /* Disable low-address protection */
952667b05eSThomas Huth static inline void low_prot_disable(void)
962667b05eSThomas Huth {
971b2c0437SClaudio Imbrenda 	ctl_clear_bit(0, CTL0_LOW_ADDR_PROT);
982667b05eSThomas Huth }
992667b05eSThomas Huth 
100*54674baeSNico Boehr /**
101*54674baeSNico Boehr  * read_pgm_int_code - Get the program interruption code of the last pgm int
102*54674baeSNico Boehr  * on the current CPU.
103*54674baeSNico Boehr  *
104*54674baeSNico Boehr  * This is similar to clear_pgm_int(), except that it doesn't clear the
105*54674baeSNico Boehr  * interruption information from lowcore.
106*54674baeSNico Boehr  *
107*54674baeSNico Boehr  * Return: 0 when none occurred.
108*54674baeSNico Boehr  */
109*54674baeSNico Boehr static inline uint16_t read_pgm_int_code(void)
110*54674baeSNico Boehr {
111*54674baeSNico Boehr 	return lowcore.pgm_int_code;
112*54674baeSNico Boehr }
113*54674baeSNico Boehr 
1144da93626SDavid Hildenbrand #endif
115