1 /* 2 * CMM tests (ESSA) 3 * 4 * Copyright (c) 2018 IBM Corp 5 * 6 * Authors: 7 * Janosch Frank <frankja@linux.vnet.ibm.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 13 #include <libcflat.h> 14 #include <asm/asm-offsets.h> 15 #include <asm/interrupt.h> 16 #include <asm/page.h> 17 18 static uint8_t pagebuf[PAGE_SIZE] __attribute__((aligned(PAGE_SIZE))); 19 20 static unsigned long essa(uint8_t state, unsigned long paddr) 21 { 22 uint64_t extr_state; 23 24 asm volatile(".insn rrf,0xb9ab0000,%[extr_state],%[addr],%[new_state],0" 25 : [extr_state] "=d" (extr_state) 26 : [addr] "a" (paddr), [new_state] "i" (state)); 27 return (unsigned long)extr_state; 28 } 29 30 static void test_params(void) 31 { 32 report_prefix_push("invalid ORC 8"); 33 expect_pgm_int(); 34 essa(8, (unsigned long)pagebuf); 35 check_pgm_int_code(PGM_INT_CODE_SPECIFICATION); 36 report_prefix_pop(); 37 } 38 39 static void test_priv(void) 40 { 41 report_prefix_push("privileged"); 42 expect_pgm_int(); 43 enter_pstate(); 44 essa(0, (unsigned long)pagebuf); 45 check_pgm_int_code(PGM_INT_CODE_PRIVILEGED_OPERATION); 46 report_prefix_pop(); 47 } 48 49 /* Unfortunately the availability is not indicated by stfl bits, but 50 * we have to try to execute it and test for an operation exception. 51 */ 52 static bool test_availability(void) 53 { 54 expect_pgm_int(); 55 essa(0, (unsigned long)pagebuf); 56 return clear_pgm_int() == 0; 57 } 58 59 int main(void) 60 { 61 bool has_essa = test_availability(); 62 63 report_prefix_push("cmm"); 64 if (!has_essa) { 65 report_skip("ESSA is not available"); 66 goto done; 67 } 68 69 test_priv(); 70 test_params(); 71 done: 72 report_prefix_pop(); 73 return report_summary(); 74 } 75