xref: /kvm-unit-tests/lib/s390x/interrupt.c (revision 4363f1d9a646a5c7ea673bee8fc33ca6f2cddbd8)
1 /*
2  * s390x interrupt handling
3  *
4  * Copyright (c) 2017 Red Hat Inc
5  *
6  * Authors:
7  *  David Hildenbrand <david@redhat.com>
8  *
9  * This code is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU Library General Public License version 2.
11  */
12 #include <libcflat.h>
13 #include <asm/interrupt.h>
14 #include <asm/barrier.h>
15 
16 static bool pgm_int_expected;
17 static struct lowcore *lc;
18 
19 void expect_pgm_int(void)
20 {
21 	pgm_int_expected = true;
22 	lc->pgm_int_code = 0;
23 	mb();
24 }
25 
26 void check_pgm_int_code(uint16_t code)
27 {
28 	mb();
29 	report("Program interrupt: expected(%d) == received(%d)",
30 	       code == lc->pgm_int_code, code, lc->pgm_int_code);
31 }
32 
33 static void fixup_pgm_int(void)
34 {
35 	switch (lc->pgm_int_code) {
36 	case PGM_INT_CODE_SEGMENT_TRANSLATION:
37 	case PGM_INT_CODE_PAGE_TRANSLATION:
38 	case PGM_INT_CODE_TRACE_TABLE:
39 	case PGM_INT_CODE_AFX_TRANSLATION:
40 	case PGM_INT_CODE_ASX_TRANSLATION:
41 	case PGM_INT_CODE_LX_TRANSLATION:
42 	case PGM_INT_CODE_EX_TRANSLATION:
43 	case PGM_INT_CODE_PRIMARY_AUTHORITY:
44 	case PGM_INT_CODE_SECONDARY_AUTHORITY:
45 	case PGM_INT_CODE_LFX_TRANSLATION:
46 	case PGM_INT_CODE_LSX_TRANSLATION:
47 	case PGM_INT_CODE_ALEN_TRANSLATION:
48 	case PGM_INT_CODE_ALE_SEQUENCE:
49 	case PGM_INT_CODE_ASTE_VALIDITY:
50 	case PGM_INT_CODE_ASTE_SEQUENCE:
51 	case PGM_INT_CODE_EXTENDED_AUTHORITY:
52 	case PGM_INT_CODE_LSTE_SEQUENCE:
53 	case PGM_INT_CODE_ASTE_INSTANCE:
54 	case PGM_INT_CODE_STACK_FULL:
55 	case PGM_INT_CODE_STACK_EMPTY:
56 	case PGM_INT_CODE_STACK_SPECIFICATION:
57 	case PGM_INT_CODE_STACK_TYPE:
58 	case PGM_INT_CODE_STACK_OPERATION:
59 	case PGM_INT_CODE_ASCE_TYPE:
60 	case PGM_INT_CODE_REGION_FIRST_TRANS:
61 	case PGM_INT_CODE_REGION_SECOND_TRANS:
62 	case PGM_INT_CODE_REGION_THIRD_TRANS:
63 	case PGM_INT_CODE_PER:
64 	case PGM_INT_CODE_CRYPTO_OPERATION:
65 		/* The interrupt was nullified, the old PSW points at the
66 		 * responsible instruction. Forward the PSW so we don't loop.
67 		 */
68 		lc->pgm_old_psw.addr += lc->pgm_int_id;
69 	}
70 	/* suppressed/terminated/completed point already at the next address */
71 }
72 
73 void handle_pgm_int(void)
74 {
75 	if (!pgm_int_expected)
76 		report_abort("Unexpected program interrupt: %d at %#lx, ilen %d\n",
77 			     lc->pgm_int_code, lc->pgm_old_psw.addr,
78 			     lc->pgm_int_id);
79 
80 	pgm_int_expected = false;
81 	fixup_pgm_int();
82 }
83