14da93626SDavid Hildenbrand /* 24da93626SDavid Hildenbrand * s390x interrupt handling 34da93626SDavid Hildenbrand * 44da93626SDavid Hildenbrand * Copyright (c) 2017 Red Hat Inc 54da93626SDavid Hildenbrand * 64da93626SDavid Hildenbrand * Authors: 74da93626SDavid Hildenbrand * David Hildenbrand <david@redhat.com> 84da93626SDavid Hildenbrand * 94da93626SDavid Hildenbrand * This code is free software; you can redistribute it and/or modify it 104da93626SDavid Hildenbrand * under the terms of the GNU Library General Public License version 2. 114da93626SDavid Hildenbrand */ 124da93626SDavid Hildenbrand #include <libcflat.h> 134da93626SDavid Hildenbrand #include <asm/interrupt.h> 144da93626SDavid Hildenbrand #include <asm/barrier.h> 154da93626SDavid Hildenbrand 164da93626SDavid Hildenbrand static bool pgm_int_expected; 174da93626SDavid Hildenbrand static struct lowcore *lc; 184da93626SDavid Hildenbrand 194da93626SDavid Hildenbrand void expect_pgm_int(void) 204da93626SDavid Hildenbrand { 214da93626SDavid Hildenbrand pgm_int_expected = true; 224da93626SDavid Hildenbrand lc->pgm_int_code = 0; 234da93626SDavid Hildenbrand mb(); 244da93626SDavid Hildenbrand } 254da93626SDavid Hildenbrand 263db880b6SDavid Hildenbrand uint16_t clear_pgm_int(void) 273db880b6SDavid Hildenbrand { 283db880b6SDavid Hildenbrand uint16_t code; 293db880b6SDavid Hildenbrand 303db880b6SDavid Hildenbrand mb(); 313db880b6SDavid Hildenbrand code = lc->pgm_int_code; 323db880b6SDavid Hildenbrand lc->pgm_int_code = 0; 333db880b6SDavid Hildenbrand pgm_int_expected = false; 343db880b6SDavid Hildenbrand return code; 353db880b6SDavid Hildenbrand } 363db880b6SDavid Hildenbrand 374da93626SDavid Hildenbrand void check_pgm_int_code(uint16_t code) 384da93626SDavid Hildenbrand { 394da93626SDavid Hildenbrand mb(); 404da93626SDavid Hildenbrand report("Program interrupt: expected(%d) == received(%d)", 414da93626SDavid Hildenbrand code == lc->pgm_int_code, code, lc->pgm_int_code); 424da93626SDavid Hildenbrand } 434da93626SDavid Hildenbrand 444da93626SDavid Hildenbrand static void fixup_pgm_int(void) 454da93626SDavid Hildenbrand { 464da93626SDavid Hildenbrand switch (lc->pgm_int_code) { 47*4ef6f57dSJanosch Frank case PGM_INT_CODE_PRIVILEGED_OPERATION: 48*4ef6f57dSJanosch Frank /* Normal operation is in supervisor state, so this exception 49*4ef6f57dSJanosch Frank * was produced intentionally and we should return to the 50*4ef6f57dSJanosch Frank * supervisor state. 51*4ef6f57dSJanosch Frank */ 52*4ef6f57dSJanosch Frank lc->pgm_old_psw.mask &= ~PSW_MASK_PSTATE; 53*4ef6f57dSJanosch Frank break; 544da93626SDavid Hildenbrand case PGM_INT_CODE_SEGMENT_TRANSLATION: 554da93626SDavid Hildenbrand case PGM_INT_CODE_PAGE_TRANSLATION: 564da93626SDavid Hildenbrand case PGM_INT_CODE_TRACE_TABLE: 574da93626SDavid Hildenbrand case PGM_INT_CODE_AFX_TRANSLATION: 584da93626SDavid Hildenbrand case PGM_INT_CODE_ASX_TRANSLATION: 594da93626SDavid Hildenbrand case PGM_INT_CODE_LX_TRANSLATION: 604da93626SDavid Hildenbrand case PGM_INT_CODE_EX_TRANSLATION: 614da93626SDavid Hildenbrand case PGM_INT_CODE_PRIMARY_AUTHORITY: 624da93626SDavid Hildenbrand case PGM_INT_CODE_SECONDARY_AUTHORITY: 634da93626SDavid Hildenbrand case PGM_INT_CODE_LFX_TRANSLATION: 644da93626SDavid Hildenbrand case PGM_INT_CODE_LSX_TRANSLATION: 654da93626SDavid Hildenbrand case PGM_INT_CODE_ALEN_TRANSLATION: 664da93626SDavid Hildenbrand case PGM_INT_CODE_ALE_SEQUENCE: 674da93626SDavid Hildenbrand case PGM_INT_CODE_ASTE_VALIDITY: 684da93626SDavid Hildenbrand case PGM_INT_CODE_ASTE_SEQUENCE: 694da93626SDavid Hildenbrand case PGM_INT_CODE_EXTENDED_AUTHORITY: 704da93626SDavid Hildenbrand case PGM_INT_CODE_LSTE_SEQUENCE: 714da93626SDavid Hildenbrand case PGM_INT_CODE_ASTE_INSTANCE: 724da93626SDavid Hildenbrand case PGM_INT_CODE_STACK_FULL: 734da93626SDavid Hildenbrand case PGM_INT_CODE_STACK_EMPTY: 744da93626SDavid Hildenbrand case PGM_INT_CODE_STACK_SPECIFICATION: 754da93626SDavid Hildenbrand case PGM_INT_CODE_STACK_TYPE: 764da93626SDavid Hildenbrand case PGM_INT_CODE_STACK_OPERATION: 774da93626SDavid Hildenbrand case PGM_INT_CODE_ASCE_TYPE: 784da93626SDavid Hildenbrand case PGM_INT_CODE_REGION_FIRST_TRANS: 794da93626SDavid Hildenbrand case PGM_INT_CODE_REGION_SECOND_TRANS: 804da93626SDavid Hildenbrand case PGM_INT_CODE_REGION_THIRD_TRANS: 814da93626SDavid Hildenbrand case PGM_INT_CODE_PER: 824da93626SDavid Hildenbrand case PGM_INT_CODE_CRYPTO_OPERATION: 834da93626SDavid Hildenbrand /* The interrupt was nullified, the old PSW points at the 844da93626SDavid Hildenbrand * responsible instruction. Forward the PSW so we don't loop. 854da93626SDavid Hildenbrand */ 864da93626SDavid Hildenbrand lc->pgm_old_psw.addr += lc->pgm_int_id; 874da93626SDavid Hildenbrand } 884da93626SDavid Hildenbrand /* suppressed/terminated/completed point already at the next address */ 894da93626SDavid Hildenbrand } 904da93626SDavid Hildenbrand 914da93626SDavid Hildenbrand void handle_pgm_int(void) 924da93626SDavid Hildenbrand { 934da93626SDavid Hildenbrand if (!pgm_int_expected) 944da93626SDavid Hildenbrand report_abort("Unexpected program interrupt: %d at %#lx, ilen %d\n", 954da93626SDavid Hildenbrand lc->pgm_int_code, lc->pgm_old_psw.addr, 964da93626SDavid Hildenbrand lc->pgm_int_id); 974da93626SDavid Hildenbrand 984da93626SDavid Hildenbrand pgm_int_expected = false; 994da93626SDavid Hildenbrand fixup_pgm_int(); 1004da93626SDavid Hildenbrand } 101