Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * store hypervisor information instruction emulation functions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright IBM Corp. 2016
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Author(s): Janosch Frank <frankja@linux.vnet.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/pagemap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/vmalloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/syscalls.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <asm/asm-offsets.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <asm/sclp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <asm/diag.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <asm/sysinfo.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <asm/ebcdic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <asm/facility.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <asm/sthyi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include "entry.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #define DED_WEIGHT 0xffff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  * CP and IFL as EBCDIC strings, SP/0x40 determines the end of string
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  * as they are justified with spaces.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #define CP  0xc3d7404040404040UL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #define IFL 0xc9c6d34040404040UL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) enum hdr_flags {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	HDR_NOT_LPAR   = 0x10,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	HDR_STACK_INCM = 0x20,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	HDR_STSI_UNAV  = 0x40,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	HDR_PERF_UNAV  = 0x80,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) enum mac_validity {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	MAC_NAME_VLD = 0x20,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	MAC_ID_VLD   = 0x40,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	MAC_CNT_VLD  = 0x80,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) enum par_flag {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	PAR_MT_EN = 0x80,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) enum par_validity {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	PAR_GRP_VLD  = 0x08,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	PAR_ID_VLD   = 0x10,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	PAR_ABS_VLD  = 0x20,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	PAR_WGHT_VLD = 0x40,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	PAR_PCNT_VLD  = 0x80,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) struct hdr_sctn {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	u8 infhflg1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	u8 infhflg2; /* reserved */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	u8 infhval1; /* reserved */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	u8 infhval2; /* reserved */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	u8 reserved[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	u8 infhygct;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	u16 infhtotl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	u16 infhdln;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	u16 infmoff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	u16 infmlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	u16 infpoff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	u16 infplen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	u16 infhoff1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	u16 infhlen1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	u16 infgoff1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	u16 infglen1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	u16 infhoff2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	u16 infhlen2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	u16 infgoff2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	u16 infglen2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	u16 infhoff3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	u16 infhlen3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	u16 infgoff3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	u16 infglen3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	u8 reserved2[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) struct mac_sctn {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	u8 infmflg1; /* reserved */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	u8 infmflg2; /* reserved */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	u8 infmval1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	u8 infmval2; /* reserved */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	u16 infmscps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	u16 infmdcps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	u16 infmsifl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	u16 infmdifl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	char infmname[8];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	char infmtype[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	char infmmanu[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	char infmseq[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	char infmpman[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	u8 reserved[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) struct par_sctn {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	u8 infpflg1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	u8 infpflg2; /* reserved */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	u8 infpval1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	u8 infpval2; /* reserved */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	u16 infppnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	u16 infpscps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	u16 infpdcps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	u16 infpsifl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	u16 infpdifl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	u16 reserved;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	char infppnam[8];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	u32 infpwbcp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	u32 infpabcp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	u32 infpwbif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	u32 infpabif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	char infplgnm[8];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	u32 infplgcp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	u32 infplgif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) struct sthyi_sctns {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	struct hdr_sctn hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	struct mac_sctn mac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	struct par_sctn par;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) struct cpu_inf {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	u64 lpar_cap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	u64 lpar_grp_cap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	u64 lpar_weight;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	u64 all_weight;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	int cpu_num_ded;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	int cpu_num_shd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) struct lpar_cpu_inf {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	struct cpu_inf cp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	struct cpu_inf ifl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)  * STHYI requires extensive locking in the higher hypervisors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)  * and is very computational/memory expensive. Therefore we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)  * cache the retrieved data whose valid period is 1s.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) #define CACHE_VALID_JIFFIES	HZ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) struct sthyi_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	void *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	unsigned long end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) static DEFINE_MUTEX(sthyi_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) static struct sthyi_info sthyi_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) static inline u64 cpu_id(u8 ctidx, void *diag224_buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	return *((u64 *)(diag224_buf + (ctidx + 1) * DIAG204_CPU_NAME_LEN));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)  * Scales the cpu capping from the lpar range to the one expected in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)  * sthyi data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)  * diag204 reports a cap in hundredths of processor units.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)  * z/VM's range for one core is 0 - 0x10000.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) static u32 scale_cap(u32 in)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	return (0x10000 * in) / 100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) static void fill_hdr(struct sthyi_sctns *sctns)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	sctns->hdr.infhdln = sizeof(sctns->hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	sctns->hdr.infmoff = sizeof(sctns->hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	sctns->hdr.infmlen = sizeof(sctns->mac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	sctns->hdr.infplen = sizeof(sctns->par);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	sctns->hdr.infpoff = sctns->hdr.infhdln + sctns->hdr.infmlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	sctns->hdr.infhtotl = sctns->hdr.infpoff + sctns->hdr.infplen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) static void fill_stsi_mac(struct sthyi_sctns *sctns,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 			  struct sysinfo_1_1_1 *sysinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	sclp_ocf_cpc_name_copy(sctns->mac.infmname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	if (*(u64 *)sctns->mac.infmname != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		sctns->mac.infmval1 |= MAC_NAME_VLD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	if (stsi(sysinfo, 1, 1, 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	memcpy(sctns->mac.infmtype, sysinfo->type, sizeof(sctns->mac.infmtype));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	memcpy(sctns->mac.infmmanu, sysinfo->manufacturer, sizeof(sctns->mac.infmmanu));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	memcpy(sctns->mac.infmpman, sysinfo->plant, sizeof(sctns->mac.infmpman));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	memcpy(sctns->mac.infmseq, sysinfo->sequence, sizeof(sctns->mac.infmseq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	sctns->mac.infmval1 |= MAC_ID_VLD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) static void fill_stsi_par(struct sthyi_sctns *sctns,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 			  struct sysinfo_2_2_2 *sysinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	if (stsi(sysinfo, 2, 2, 2))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	sctns->par.infppnum = sysinfo->lpar_number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	memcpy(sctns->par.infppnam, sysinfo->name, sizeof(sctns->par.infppnam));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	sctns->par.infpval1 |= PAR_ID_VLD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) static void fill_stsi(struct sthyi_sctns *sctns)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	void *sysinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	/* Errors are handled through the validity bits in the response. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	sysinfo = (void *)__get_free_page(GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	if (!sysinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	fill_stsi_mac(sctns, sysinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	fill_stsi_par(sctns, sysinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	free_pages((unsigned long)sysinfo, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) static void fill_diag_mac(struct sthyi_sctns *sctns,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 			  struct diag204_x_phys_block *block,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 			  void *diag224_buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	for (i = 0; i < block->hdr.cpus; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		switch (cpu_id(block->cpus[i].ctidx, diag224_buf)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		case CP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 			if (block->cpus[i].weight == DED_WEIGHT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 				sctns->mac.infmdcps++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 				sctns->mac.infmscps++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		case IFL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 			if (block->cpus[i].weight == DED_WEIGHT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 				sctns->mac.infmdifl++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 				sctns->mac.infmsifl++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	sctns->mac.infmval1 |= MAC_CNT_VLD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) /* Returns a pointer to the the next partition block. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) static struct diag204_x_part_block *lpar_cpu_inf(struct lpar_cpu_inf *part_inf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 						 bool this_lpar,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 						 void *diag224_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 						 struct diag204_x_part_block *block)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	int i, capped = 0, weight_cp = 0, weight_ifl = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	struct cpu_inf *cpu_inf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	for (i = 0; i < block->hdr.rcpus; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		if (!(block->cpus[i].cflag & DIAG204_CPU_ONLINE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		switch (cpu_id(block->cpus[i].ctidx, diag224_buf)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		case CP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 			cpu_inf = &part_inf->cp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 			if (block->cpus[i].cur_weight < DED_WEIGHT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 				weight_cp |= block->cpus[i].cur_weight;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		case IFL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 			cpu_inf = &part_inf->ifl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 			if (block->cpus[i].cur_weight < DED_WEIGHT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 				weight_ifl |= block->cpus[i].cur_weight;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 		if (!this_lpar)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		capped |= block->cpus[i].cflag & DIAG204_CPU_CAPPED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		cpu_inf->lpar_cap |= block->cpus[i].cpu_type_cap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 		cpu_inf->lpar_grp_cap |= block->cpus[i].group_cpu_type_cap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 		if (block->cpus[i].weight == DED_WEIGHT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 			cpu_inf->cpu_num_ded += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 			cpu_inf->cpu_num_shd += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	if (this_lpar && capped) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		part_inf->cp.lpar_weight = weight_cp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 		part_inf->ifl.lpar_weight = weight_ifl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	part_inf->cp.all_weight += weight_cp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	part_inf->ifl.all_weight += weight_ifl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	return (struct diag204_x_part_block *)&block->cpus[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) static void fill_diag(struct sthyi_sctns *sctns)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	int i, r, pages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	bool this_lpar;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	void *diag204_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	void *diag224_buf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	struct diag204_x_info_blk_hdr *ti_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	struct diag204_x_part_block *part_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	struct diag204_x_phys_block *phys_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	struct lpar_cpu_inf lpar_inf = {};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	/* Errors are handled through the validity bits in the response. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	pages = diag204((unsigned long)DIAG204_SUBC_RSI |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 			(unsigned long)DIAG204_INFO_EXT, 0, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	if (pages <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	diag204_buf = vmalloc(array_size(pages, PAGE_SIZE));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	if (!diag204_buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	r = diag204((unsigned long)DIAG204_SUBC_STIB7 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 		    (unsigned long)DIAG204_INFO_EXT, pages, diag204_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	if (r < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	diag224_buf = (void *)__get_free_page(GFP_KERNEL | GFP_DMA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	if (!diag224_buf || diag224(diag224_buf))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	ti_hdr = diag204_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	part_block = diag204_buf + sizeof(*ti_hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	for (i = 0; i < ti_hdr->npar; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 		 * For the calling lpar we also need to get the cpu
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 		 * caps and weights. The time information block header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 		 * specifies the offset to the partition block of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 		 * caller lpar, so we know when we process its data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 		this_lpar = (void *)part_block - diag204_buf == ti_hdr->this_part;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 		part_block = lpar_cpu_inf(&lpar_inf, this_lpar, diag224_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 					  part_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	phys_block = (struct diag204_x_phys_block *)part_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	part_block = diag204_buf + ti_hdr->this_part;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	if (part_block->hdr.mtid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 		sctns->par.infpflg1 = PAR_MT_EN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	sctns->par.infpval1 |= PAR_GRP_VLD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	sctns->par.infplgcp = scale_cap(lpar_inf.cp.lpar_grp_cap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	sctns->par.infplgif = scale_cap(lpar_inf.ifl.lpar_grp_cap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	memcpy(sctns->par.infplgnm, part_block->hdr.hardware_group_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	       sizeof(sctns->par.infplgnm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	sctns->par.infpscps = lpar_inf.cp.cpu_num_shd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	sctns->par.infpdcps = lpar_inf.cp.cpu_num_ded;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	sctns->par.infpsifl = lpar_inf.ifl.cpu_num_shd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	sctns->par.infpdifl = lpar_inf.ifl.cpu_num_ded;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	sctns->par.infpval1 |= PAR_PCNT_VLD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	sctns->par.infpabcp = scale_cap(lpar_inf.cp.lpar_cap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	sctns->par.infpabif = scale_cap(lpar_inf.ifl.lpar_cap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	sctns->par.infpval1 |= PAR_ABS_VLD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	 * Everything below needs global performance data to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	 * meaningful.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	if (!(ti_hdr->flags & DIAG204_LPAR_PHYS_FLG)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 		sctns->hdr.infhflg1 |= HDR_PERF_UNAV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	fill_diag_mac(sctns, phys_block, diag224_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	if (lpar_inf.cp.lpar_weight) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 		sctns->par.infpwbcp = sctns->mac.infmscps * 0x10000 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 			lpar_inf.cp.lpar_weight / lpar_inf.cp.all_weight;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	if (lpar_inf.ifl.lpar_weight) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 		sctns->par.infpwbif = sctns->mac.infmsifl * 0x10000 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 			lpar_inf.ifl.lpar_weight / lpar_inf.ifl.all_weight;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	sctns->par.infpval1 |= PAR_WGHT_VLD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	free_page((unsigned long)diag224_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	vfree(diag204_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) static int sthyi(u64 vaddr, u64 *rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	register u64 code asm("0") = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	register u64 addr asm("2") = vaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	register u64 rcode asm("3");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	int cc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	asm volatile(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 		".insn   rre,0xB2560000,%[code],%[addr]\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 		"ipm     %[cc]\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 		"srl     %[cc],28\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 		: [cc] "=d" (cc), "=d" (rcode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 		: [code] "d" (code), [addr] "a" (addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 		: "memory", "cc");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	*rc = rcode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	return cc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) static int fill_dst(void *dst, u64 *rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	struct sthyi_sctns *sctns = (struct sthyi_sctns *)dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	 * If the facility is on, we don't want to emulate the instruction.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	 * We ask the hypervisor to provide the data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	if (test_facility(74))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 		return sthyi((u64)dst, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	fill_hdr(sctns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	fill_stsi(sctns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	fill_diag(sctns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	*rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) static int sthyi_init_cache(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	if (sthyi_cache.info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	sthyi_cache.info = (void *)get_zeroed_page(GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	if (!sthyi_cache.info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	sthyi_cache.end = jiffies - 1; /* expired */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) static int sthyi_update_cache(u64 *rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	memset(sthyi_cache.info, 0, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	r = fill_dst(sthyi_cache.info, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	if (r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 		return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	sthyi_cache.end = jiffies + CACHE_VALID_JIFFIES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456)  * sthyi_fill - Fill page with data returned by the STHYI instruction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458)  * @dst: Pointer to zeroed page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459)  * @rc:  Pointer for storing the return code of the instruction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461)  * Fills the destination with system information returned by the STHYI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462)  * instruction. The data is generated by emulation or execution of STHYI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463)  * if available. The return value is the condition code that would be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)  * returned, the rc parameter is the return code which is passed in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465)  * register R2 + 1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) int sthyi_fill(void *dst, u64 *rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	mutex_lock(&sthyi_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	r = sthyi_init_cache();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 	if (r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	if (time_is_before_jiffies(sthyi_cache.end)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 		/* cache expired */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 		r = sthyi_update_cache(rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 		if (r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	*rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	memcpy(dst, sthyi_cache.info, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	mutex_unlock(&sthyi_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 	return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) EXPORT_SYMBOL_GPL(sthyi_fill);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) SYSCALL_DEFINE4(s390_sthyi, unsigned long, function_code, void __user *, buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 		u64 __user *, return_code, unsigned long, flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 	u64 sthyi_rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	void *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 	int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 	if (flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 	if (function_code != STHYI_FC_CP_IFL_CAP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 		return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 	info = (void *)get_zeroed_page(GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 	if (!info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 	r = sthyi_fill(info, &sthyi_rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 	if (r < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 	if (return_code && put_user(sthyi_rc, return_code)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 		r = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 	if (copy_to_user(buffer, info, PAGE_SIZE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 		r = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 	free_page((unsigned long)info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 	return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) }