1 /* 2 * Copyright (c) 2017 Red Hat Inc 3 * 4 * Authors: 5 * David Hildenbrand <david@redhat.com> 6 * 7 * This code is free software; you can redistribute it and/or modify it 8 * under the terms of the GNU Library General Public License version 2. 9 */ 10 #ifndef _ASM_S390X_FACILITY_H_ 11 #define _ASM_S390X_FACILITY_H_ 12 13 #include <libcflat.h> 14 #include <asm/facility.h> 15 #include <asm/arch_def.h> 16 17 #define NB_STFL_DOUBLEWORDS 32 18 extern uint64_t stfl_doublewords[]; 19 20 static inline bool test_facility(int nr) 21 { 22 return stfl_doublewords[nr / 64] & (0x8000000000000000UL >> (nr % 64)); 23 } 24 25 static inline void stfl(void) 26 { 27 asm volatile(" stfl 0(0)\n" : : : "memory"); 28 } 29 30 static inline void stfle(uint64_t *fac, unsigned int nb_doublewords) 31 { 32 register unsigned long r0 asm("0") = nb_doublewords - 1; 33 34 asm volatile(" .insn s,0xb2b00000,0(%1)\n" 35 : "+d" (r0) : "a" (fac) : "memory", "cc"); 36 } 37 38 static inline void setup_facilities(void) 39 { 40 struct lowcore *lc = NULL; 41 42 stfl(); 43 memcpy(stfl_doublewords, &lc->stfl, sizeof(lc->stfl)); 44 if (test_facility(7)) 45 stfle(stfl_doublewords, NB_STFL_DOUBLEWORDS); 46 } 47 48 #endif 49