1 // SPDX-License-Identifier: GPL-2.0
3 * Hypervisor filesystem for Linux on s390. z/VM implementation.
5 * Copyright IBM Corp. 2006
6 * Author(s): Michael Holzheu <holzheu@de.ibm.com>
9 #include <linux/types.h>
10 #include <linux/errno.h>
11 #include <linux/string.h>
12 #include <linux/vmalloc.h>
14 #include <asm/ebcdic.h>
15 #include <asm/timex.h>
19 #define DBFS_D2FC_HDR_VERSION 0
21 static char local_guest
[] = " ";
22 static char all_guests
[] = "* ";
23 static char *guest_query
;
46 char guest_name
[NAME_LEN
];
49 struct diag2fc_parm_list
{
50 char userid
[NAME_LEN
];
51 char aci_grp
[NAME_LEN
];
57 static int diag2fc(int size
, char* query
, void *addr
)
59 unsigned long residual_cnt
;
61 struct diag2fc_parm_list parm_list
;
63 memcpy(parm_list
.userid
, query
, NAME_LEN
);
64 ASCEBC(parm_list
.userid
, NAME_LEN
);
65 parm_list
.addr
= (unsigned long) addr
;
66 parm_list
.size
= size
;
68 memset(parm_list
.aci_grp
, 0x40, NAME_LEN
);
71 diag_stat_inc(DIAG_STAT_X2FC
);
76 : "=d" (residual_cnt
), "+d" (rc
) : "0" (&parm_list
) : "memory");
78 if ((rc
!= 0 ) && (rc
!= -2))
85 * Allocate buffer for "query" and store diag 2fc at "offset"
87 static void *diag2fc_store(char *query
, unsigned int *count
, int offset
)
93 size
= diag2fc(0, query
, NULL
);
95 return ERR_PTR(-EACCES
);
96 data
= vmalloc(size
+ offset
);
98 return ERR_PTR(-ENOMEM
);
99 if (diag2fc(size
, query
, data
+ offset
) == 0)
103 *count
= (size
/ sizeof(struct diag2fc_data
));
108 static void diag2fc_free(const void *data
)
113 #define ATTRIBUTE(dir, name, member) \
116 rc = hypfs_create_u64(dir, name, member); \
118 return PTR_ERR(rc); \
121 static int hpyfs_vm_create_guest(struct dentry
*systems_dir
,
122 struct diag2fc_data
*data
)
124 char guest_name
[NAME_LEN
+ 1] = {};
125 struct dentry
*guest_dir
, *cpus_dir
, *samples_dir
, *mem_dir
;
126 int dedicated_flag
, capped_value
;
128 capped_value
= (data
->flags
& 0x00000006) >> 1;
129 dedicated_flag
= (data
->flags
& 0x00000008) >> 3;
132 memcpy(guest_name
, data
->guest_name
, NAME_LEN
);
133 EBCASC(guest_name
, NAME_LEN
);
135 guest_dir
= hypfs_mkdir(systems_dir
, guest_name
);
136 if (IS_ERR(guest_dir
))
137 return PTR_ERR(guest_dir
);
138 ATTRIBUTE(guest_dir
, "onlinetime_us", data
->el_time
);
140 /* logical cpu information */
141 cpus_dir
= hypfs_mkdir(guest_dir
, "cpus");
142 if (IS_ERR(cpus_dir
))
143 return PTR_ERR(cpus_dir
);
144 ATTRIBUTE(cpus_dir
, "cputime_us", data
->used_cpu
);
145 ATTRIBUTE(cpus_dir
, "capped", capped_value
);
146 ATTRIBUTE(cpus_dir
, "dedicated", dedicated_flag
);
147 ATTRIBUTE(cpus_dir
, "count", data
->vcpus
);
149 * Note: The "weight_min" attribute got the wrong name.
150 * The value represents the number of non-stopped (operating)
153 ATTRIBUTE(cpus_dir
, "weight_min", data
->ocpus
);
154 ATTRIBUTE(cpus_dir
, "weight_max", data
->cpu_max
);
155 ATTRIBUTE(cpus_dir
, "weight_cur", data
->cpu_shares
);
157 /* memory information */
158 mem_dir
= hypfs_mkdir(guest_dir
, "mem");
160 return PTR_ERR(mem_dir
);
161 ATTRIBUTE(mem_dir
, "min_KiB", data
->mem_min_kb
);
162 ATTRIBUTE(mem_dir
, "max_KiB", data
->mem_max_kb
);
163 ATTRIBUTE(mem_dir
, "used_KiB", data
->mem_used_kb
);
164 ATTRIBUTE(mem_dir
, "share_KiB", data
->mem_share_kb
);
167 samples_dir
= hypfs_mkdir(guest_dir
, "samples");
168 if (IS_ERR(samples_dir
))
169 return PTR_ERR(samples_dir
);
170 ATTRIBUTE(samples_dir
, "cpu_using", data
->cpu_use_samp
);
171 ATTRIBUTE(samples_dir
, "cpu_delay", data
->cpu_delay_samp
);
172 ATTRIBUTE(samples_dir
, "mem_delay", data
->page_wait_samp
);
173 ATTRIBUTE(samples_dir
, "idle", data
->idle_samp
);
174 ATTRIBUTE(samples_dir
, "other", data
->other_samp
);
175 ATTRIBUTE(samples_dir
, "total", data
->total_samp
);
179 int hypfs_vm_create_files(struct dentry
*root
)
181 struct dentry
*dir
, *file
;
182 struct diag2fc_data
*data
;
183 unsigned int count
= 0;
186 data
= diag2fc_store(guest_query
, &count
, 0);
188 return PTR_ERR(data
);
191 dir
= hypfs_mkdir(root
, "hyp");
196 file
= hypfs_create_str(dir
, "type", "z/VM Hypervisor");
203 dir
= hypfs_mkdir(root
, "cpus");
208 file
= hypfs_create_u64(dir
, "count", data
->lcpus
);
215 dir
= hypfs_mkdir(root
, "systems");
221 for (i
= 0; i
< count
; i
++) {
222 rc
= hpyfs_vm_create_guest(dir
, &(data
[i
]));
234 struct dbfs_d2fc_hdr
{
235 u64 len
; /* Length of d2fc buffer without header */
236 u16 version
; /* Version of header */
237 char tod_ext
[STORE_CLOCK_EXT_SIZE
]; /* TOD clock for d2fc */
238 u64 count
; /* Number of VM guests in d2fc buffer */
240 } __attribute__ ((packed
));
243 struct dbfs_d2fc_hdr hdr
; /* 64 byte header */
244 char buf
[]; /* d2fc buffer */
245 } __attribute__ ((packed
));
247 static int dbfs_diag2fc_create(void **data
, void **data_free_ptr
, size_t *size
)
249 struct dbfs_d2fc
*d2fc
;
252 d2fc
= diag2fc_store(guest_query
, &count
, sizeof(d2fc
->hdr
));
254 return PTR_ERR(d2fc
);
255 get_tod_clock_ext(d2fc
->hdr
.tod_ext
);
256 d2fc
->hdr
.len
= count
* sizeof(struct diag2fc_data
);
257 d2fc
->hdr
.version
= DBFS_D2FC_HDR_VERSION
;
258 d2fc
->hdr
.count
= count
;
259 memset(&d2fc
->hdr
.reserved
, 0, sizeof(d2fc
->hdr
.reserved
));
261 *data_free_ptr
= d2fc
;
262 *size
= d2fc
->hdr
.len
+ sizeof(struct dbfs_d2fc_hdr
);
266 static struct hypfs_dbfs_file dbfs_file_2fc
= {
268 .data_create
= dbfs_diag2fc_create
,
269 .data_free
= diag2fc_free
,
272 int hypfs_vm_init(void)
276 if (diag2fc(0, all_guests
, NULL
) > 0)
277 guest_query
= all_guests
;
278 else if (diag2fc(0, local_guest
, NULL
) > 0)
279 guest_query
= local_guest
;
282 hypfs_dbfs_create_file(&dbfs_file_2fc
);
286 void hypfs_vm_exit(void)
290 hypfs_dbfs_remove_file(&dbfs_file_2fc
);