1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 3 * Tests SIE diagnose intercepts. 4 * Mainly used as a template for SIE tests. 5 * 6 * Copyright 2021 IBM Corp. 7 * 8 * Authors: 9 * Janosch Frank <frankja@linux.ibm.com> 10 */ 11 #include <libcflat.h> 12 #include <asm/asm-offsets.h> 13 #include <asm/arch_def.h> 14 #include <asm/interrupt.h> 15 #include <asm/page.h> 16 #include <alloc_page.h> 17 #include <vmalloc.h> 18 #include <asm/facility.h> 19 #include <mmu.h> 20 #include <sclp.h> 21 #include <sie.h> 22 23 static u8 *guest; 24 static u8 *guest_instr; 25 static struct vm vm; 26 27 static void test_diag(u32 instr) 28 { 29 vm.sblk->gpsw.addr = PAGE_SIZE * 2; 30 vm.sblk->gpsw.mask = PSW_MASK_64; 31 32 memset(guest_instr, 0, PAGE_SIZE); 33 memcpy(guest_instr, &instr, 4); 34 sie(&vm); 35 report(vm.sblk->icptcode == ICPT_INST && 36 vm.sblk->ipa == instr >> 16 && vm.sblk->ipb == instr << 16, 37 "Intercept data"); 38 } 39 40 static struct { 41 const char *name; 42 u32 instr; 43 } tests[] = { 44 { "10", 0x83020010 }, 45 { "44", 0x83020044 }, 46 { "9c", 0x8302009c }, 47 { NULL, 0 } 48 }; 49 50 static void test_diags(void) 51 { 52 int i; 53 54 for (i = 0; tests[i].name; i++) { 55 report_prefix_push(tests[i].name); 56 test_diag(tests[i].instr); 57 report_prefix_pop(); 58 } 59 } 60 61 static void setup_guest(void) 62 { 63 setup_vm(); 64 65 /* Allocate 1MB as guest memory */ 66 guest = alloc_pages(8); 67 /* The first two pages are the lowcore */ 68 guest_instr = guest + PAGE_SIZE * 2; 69 70 sie_guest_create(&vm, (uint64_t)guest, HPAGE_SIZE); 71 } 72 73 int main(void) 74 { 75 report_prefix_push("sie"); 76 if (!sclp_facilities.has_sief2) { 77 report_skip("SIEF2 facility unavailable"); 78 goto done; 79 } 80 81 setup_guest(); 82 test_diags(); 83 sie_guest_destroy(&vm); 84 85 done: 86 report_prefix_pop(); 87 return report_summary(); 88 } 89