xref: /kvm-unit-tests/lib/s390x/asm/mem.h (revision d935296e8ff912fc8ff8061bf69c689f9d0e28d1)
1 /*
2  * Physical memory management related functions and definitions.
3  *
4  * Copyright IBM Corp. 2018
5  * Author(s): Janosch Frank <frankja@de.ibm.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_S390_MEM_H
11 #define _ASM_S390_MEM_H
12 
13 union skey {
14 	struct {
15 		uint8_t acc : 4;
16 		uint8_t fp : 1;
17 		uint8_t rf : 1;
18 		uint8_t ch : 1;
19 		uint8_t pad : 1;
20 	} str;
21 	uint8_t val;
22 };
23 
24 static inline void set_storage_key(unsigned long addr,
25 				   unsigned char skey,
26 				   int nq)
27 {
28 	if (nq)
29 		asm volatile(".insn rrf,0xb22b0000,%0,%1,8,0"
30 			     : : "d" (skey), "a" (addr));
31 	else
32 		asm volatile("sske %0,%1" : : "d" (skey), "a" (addr));
33 }
34 
35 static inline unsigned long set_storage_key_mb(unsigned long addr,
36 					       unsigned char skey)
37 {
38 	assert(test_facility(8));
39 
40 	asm volatile(".insn rrf,0xb22b0000,%[skey],%[addr],1,0"
41 		     : [addr] "+a" (addr) : [skey] "d" (skey));
42 	return addr;
43 }
44 
45 static inline unsigned char get_storage_key(unsigned long addr)
46 {
47 	unsigned char skey;
48 
49 	asm volatile("iske %0,%1" : "=d" (skey) : "a" (addr));
50 	return skey;
51 }
52 #endif
53