2 * Hypervisor filesystem for Linux on s390. z/VM implementation.
4 * Copyright IBM Corp. 2006
5 * Author(s): Michael Holzheu <holzheu@de.ibm.com>
8 #include <linux/types.h>
9 #include <linux/errno.h>
10 #include <linux/string.h>
11 #include <linux/vmalloc.h>
13 #include <asm/ebcdic.h>
14 #include <asm/timex.h>
18 #define DBFS_D2FC_HDR_VERSION 0
20 static char local_guest[] = " ";
21 static char all_guests[] = "* ";
22 static char *all_groups = 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 memcpy(parm_list.aci_grp, all_groups, NAME_LEN);
66 ASCEBC(parm_list.aci_grp, NAME_LEN);
67 parm_list.addr = (unsigned long)addr;
68 parm_list.size = size;
72 diag_stat_inc(DIAG_STAT_X2FC);
77 : "=d" (residual_cnt), "+d" (rc) : "0" (&parm_list) : "memory");
79 if ((rc != 0 ) && (rc != -2))
86 * Allocate buffer for "query" and store diag 2fc at "offset"
88 static void *diag2fc_store(char *query, unsigned int *count, int offset)
94 size = diag2fc(0, query, NULL);
96 return ERR_PTR(-EACCES);
97 data = vmalloc(size + offset);
99 return ERR_PTR(-ENOMEM);
100 if (diag2fc(size, query, data + offset) == 0)
104 *count = (size / sizeof(struct diag2fc_data));
109 static void diag2fc_free(const void *data)
114 #define ATTRIBUTE(dir, name, member) \
117 rc = hypfs_create_u64(dir, name, member); \
119 return PTR_ERR(rc); \
122 static int hpyfs_vm_create_guest(struct dentry *systems_dir,
123 struct diag2fc_data *data)
125 char guest_name[NAME_LEN + 1] = {};
126 struct dentry *guest_dir, *cpus_dir, *samples_dir, *mem_dir;
127 int dedicated_flag, capped_value;
129 capped_value = (data->flags & 0x00000006) >> 1;
130 dedicated_flag = (data->flags & 0x00000008) >> 3;
133 memcpy(guest_name, data->guest_name, NAME_LEN);
134 EBCASC(guest_name, NAME_LEN);
136 guest_dir = hypfs_mkdir(systems_dir, guest_name);
137 if (IS_ERR(guest_dir))
138 return PTR_ERR(guest_dir);
139 ATTRIBUTE(guest_dir, "onlinetime_us", data->el_time);
141 /* logical cpu information */
142 cpus_dir = hypfs_mkdir(guest_dir, "cpus");
143 if (IS_ERR(cpus_dir))
144 return PTR_ERR(cpus_dir);
145 ATTRIBUTE(cpus_dir, "cputime_us", data->used_cpu);
146 ATTRIBUTE(cpus_dir, "capped", capped_value);
147 ATTRIBUTE(cpus_dir, "dedicated", dedicated_flag);
148 ATTRIBUTE(cpus_dir, "count", data->vcpus);
150 * Note: The "weight_min" attribute got the wrong name.
151 * The value represents the number of non-stopped (operating)
154 ATTRIBUTE(cpus_dir, "weight_min", data->ocpus);
155 ATTRIBUTE(cpus_dir, "weight_max", data->cpu_max);
156 ATTRIBUTE(cpus_dir, "weight_cur", data->cpu_shares);
158 /* memory information */
159 mem_dir = hypfs_mkdir(guest_dir, "mem");
161 return PTR_ERR(mem_dir);
162 ATTRIBUTE(mem_dir, "min_KiB", data->mem_min_kb);
163 ATTRIBUTE(mem_dir, "max_KiB", data->mem_max_kb);
164 ATTRIBUTE(mem_dir, "used_KiB", data->mem_used_kb);
165 ATTRIBUTE(mem_dir, "share_KiB", data->mem_share_kb);
168 samples_dir = hypfs_mkdir(guest_dir, "samples");
169 if (IS_ERR(samples_dir))
170 return PTR_ERR(samples_dir);
171 ATTRIBUTE(samples_dir, "cpu_using", data->cpu_use_samp);
172 ATTRIBUTE(samples_dir, "cpu_delay", data->cpu_delay_samp);
173 ATTRIBUTE(samples_dir, "mem_delay", data->page_wait_samp);
174 ATTRIBUTE(samples_dir, "idle", data->idle_samp);
175 ATTRIBUTE(samples_dir, "other", data->other_samp);
176 ATTRIBUTE(samples_dir, "total", data->total_samp);
180 int hypfs_vm_create_files(struct dentry *root)
182 struct dentry *dir, *file;
183 struct diag2fc_data *data;
184 unsigned int count = 0;
187 data = diag2fc_store(guest_query, &count, 0);
189 return PTR_ERR(data);
192 dir = hypfs_mkdir(root, "hyp");
197 file = hypfs_create_str(dir, "type", "z/VM Hypervisor");
204 dir = hypfs_mkdir(root, "cpus");
209 file = hypfs_create_u64(dir, "count", data->lcpus);
216 dir = hypfs_mkdir(root, "systems");
222 for (i = 0; i < count; i++) {
223 rc = hpyfs_vm_create_guest(dir, &(data[i]));
235 struct dbfs_d2fc_hdr {
236 u64 len; /* Length of d2fc buffer without header */
237 u16 version; /* Version of header */
238 char tod_ext[STORE_CLOCK_EXT_SIZE]; /* TOD clock for d2fc */
239 u64 count; /* Number of VM guests in d2fc buffer */
241 } __attribute__ ((packed));
244 struct dbfs_d2fc_hdr hdr; /* 64 byte header */
245 char buf[]; /* d2fc buffer */
246 } __attribute__ ((packed));
248 static int dbfs_diag2fc_create(void **data, void **data_free_ptr, size_t *size)
250 struct dbfs_d2fc *d2fc;
253 d2fc = diag2fc_store(guest_query, &count, sizeof(d2fc->hdr));
255 return PTR_ERR(d2fc);
256 get_tod_clock_ext(d2fc->hdr.tod_ext);
257 d2fc->hdr.len = count * sizeof(struct diag2fc_data);
258 d2fc->hdr.version = DBFS_D2FC_HDR_VERSION;
259 d2fc->hdr.count = count;
260 memset(&d2fc->hdr.reserved, 0, sizeof(d2fc->hdr.reserved));
262 *data_free_ptr = d2fc;
263 *size = d2fc->hdr.len + sizeof(struct dbfs_d2fc_hdr);
267 static struct hypfs_dbfs_file dbfs_file_2fc = {
269 .data_create = dbfs_diag2fc_create,
270 .data_free = diag2fc_free,
273 int hypfs_vm_init(void)
277 if (diag2fc(0, all_guests, NULL) > 0)
278 guest_query = all_guests;
279 else if (diag2fc(0, local_guest, NULL) > 0)
280 guest_query = local_guest;
283 return hypfs_dbfs_create_file(&dbfs_file_2fc);
286 void hypfs_vm_exit(void)
290 hypfs_dbfs_remove_file(&dbfs_file_2fc);