1 // SPDX-License-Identifier: GPL-2.0
3 * Hypervisor filesystem for Linux on s390
5 * Diag 0C implementation
7 * Copyright IBM Corp. 2014
10 #include <linux/slab.h>
11 #include <linux/cpu.h>
13 #include <asm/hypfs.h>
16 #define DBFS_D0C_HDR_VERSION 0
19 * Get hypfs_diag0c_entry from CPU vector and store diag0c data
21 static void diag0c_fn(void *data
)
23 diag_stat_inc(DIAG_STAT_X00C
);
24 diag_dma_ops
.diag0c(((void **) data
)[smp_processor_id()]);
28 * Allocate buffer and store diag 0c data
30 static void *diag0c_store(unsigned int *count
)
32 struct hypfs_diag0c_data
*diag0c_data
;
33 unsigned int cpu_count
, cpu
, i
;
37 cpu_count
= num_online_cpus();
38 cpu_vec
= kmalloc_array(num_possible_cpus(), sizeof(*cpu_vec
),
41 goto fail_put_online_cpus
;
42 /* Note: Diag 0c needs 8 byte alignment and real storage */
43 diag0c_data
= kzalloc(struct_size(diag0c_data
, entry
, cpu_count
),
44 GFP_KERNEL
| GFP_DMA
);
46 goto fail_kfree_cpu_vec
;
48 /* Fill CPU vector for each online CPU */
49 for_each_online_cpu(cpu
) {
50 diag0c_data
->entry
[i
].cpu
= cpu
;
51 cpu_vec
[cpu
] = &diag0c_data
->entry
[i
++];
53 /* Collect data all CPUs */
54 on_each_cpu(diag0c_fn
, cpu_vec
, 1);
64 return ERR_PTR(-ENOMEM
);
68 * Hypfs DBFS callback: Free diag 0c data
70 static void dbfs_diag0c_free(const void *data
)
76 * Hypfs DBFS callback: Create diag 0c data
78 static int dbfs_diag0c_create(void **data
, void **data_free_ptr
, size_t *size
)
80 struct hypfs_diag0c_data
*diag0c_data
;
83 diag0c_data
= diag0c_store(&count
);
84 if (IS_ERR(diag0c_data
))
85 return PTR_ERR(diag0c_data
);
86 memset(&diag0c_data
->hdr
, 0, sizeof(diag0c_data
->hdr
));
87 get_tod_clock_ext(diag0c_data
->hdr
.tod_ext
);
88 diag0c_data
->hdr
.len
= count
* sizeof(struct hypfs_diag0c_entry
);
89 diag0c_data
->hdr
.version
= DBFS_D0C_HDR_VERSION
;
90 diag0c_data
->hdr
.count
= count
;
92 *data_free_ptr
= diag0c_data
;
93 *size
= diag0c_data
->hdr
.len
+ sizeof(struct hypfs_diag0c_hdr
);
98 * Hypfs DBFS file structure
100 static struct hypfs_dbfs_file dbfs_file_0c
= {
102 .data_create
= dbfs_diag0c_create
,
103 .data_free
= dbfs_diag0c_free
,
107 * Initialize diag 0c interface for z/VM
109 int __init
hypfs_diag0c_init(void)
113 hypfs_dbfs_create_file(&dbfs_file_0c
);
118 * Shutdown diag 0c interface for z/VM
120 void hypfs_diag0c_exit(void)
124 hypfs_dbfs_remove_file(&dbfs_file_0c
);