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>
13 #include <asm/extable.h>
15 #include <asm/ebcdic.h>
16 #include <asm/timex.h>
20 #define DBFS_D2FC_HDR_VERSION 0
22 static char local_guest[] = " ";
23 static char all_guests[] = "* ";
24 static char *all_groups = all_guests;
25 char *diag2fc_guest_query;
27 static int diag2fc(int size, char* query, void *addr)
29 unsigned long residual_cnt;
31 struct diag2fc_parm_list parm_list;
33 memcpy(parm_list.userid, query, DIAG2FC_NAME_LEN);
34 ASCEBC(parm_list.userid, DIAG2FC_NAME_LEN);
35 memcpy(parm_list.aci_grp, all_groups, DIAG2FC_NAME_LEN);
36 ASCEBC(parm_list.aci_grp, DIAG2FC_NAME_LEN);
37 parm_list.addr = (unsigned long)addr;
38 parm_list.size = size;
42 diag_stat_inc(DIAG_STAT_X2FC);
47 : "=d" (residual_cnt), "+d" (rc) : "0" (&parm_list) : "memory");
49 if ((rc != 0 ) && (rc != -2))
56 * Allocate buffer for "query" and store diag 2fc at "offset"
58 void *diag2fc_store(char *query, unsigned int *count, int offset)
64 size = diag2fc(0, query, NULL);
66 return ERR_PTR(-EACCES);
67 data = vmalloc(size + offset);
69 return ERR_PTR(-ENOMEM);
70 if (diag2fc(size, query, data + offset) == 0)
74 *count = (size / sizeof(struct diag2fc_data));
79 void diag2fc_free(const void *data)
84 struct dbfs_d2fc_hdr {
85 u64 len; /* Length of d2fc buffer without header */
86 u16 version; /* Version of header */
87 union tod_clock tod_ext; /* TOD clock for d2fc */
88 u64 count; /* Number of VM guests in d2fc buffer */
90 } __attribute__ ((packed));
93 struct dbfs_d2fc_hdr hdr; /* 64 byte header */
94 char buf[]; /* d2fc buffer */
95 } __attribute__ ((packed));
97 static int dbfs_diag2fc_create(void **data, void **data_free_ptr, size_t *size)
99 struct dbfs_d2fc *d2fc;
102 d2fc = diag2fc_store(diag2fc_guest_query, &count, sizeof(d2fc->hdr));
104 return PTR_ERR(d2fc);
105 store_tod_clock_ext(&d2fc->hdr.tod_ext);
106 d2fc->hdr.len = count * sizeof(struct diag2fc_data);
107 d2fc->hdr.version = DBFS_D2FC_HDR_VERSION;
108 d2fc->hdr.count = count;
109 memset(&d2fc->hdr.reserved, 0, sizeof(d2fc->hdr.reserved));
111 *data_free_ptr = d2fc;
112 *size = d2fc->hdr.len + sizeof(struct dbfs_d2fc_hdr);
116 static struct hypfs_dbfs_file dbfs_file_2fc = {
118 .data_create = dbfs_diag2fc_create,
119 .data_free = diag2fc_free,
122 int hypfs_vm_init(void)
126 if (diag2fc(0, all_guests, NULL) > 0)
127 diag2fc_guest_query = all_guests;
128 else if (diag2fc(0, local_guest, NULL) > 0)
129 diag2fc_guest_query = local_guest;
132 hypfs_dbfs_create_file(&dbfs_file_2fc);
136 void hypfs_vm_exit(void)
140 hypfs_dbfs_remove_file(&dbfs_file_2fc);