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 diag0c(((void **)data)[smp_processor_id()]);
27 * Allocate buffer and store diag 0c data
29 static void *diag0c_store(unsigned int *count)
31 struct hypfs_diag0c_data *diag0c_data;
32 unsigned int cpu_count, cpu, i;
36 cpu_count = num_online_cpus();
37 cpu_vec = kmalloc_array(num_possible_cpus(), sizeof(*cpu_vec),
40 goto fail_unlock_cpus;
41 /* Note: Diag 0c needs 8 byte alignment and real storage */
42 diag0c_data = kzalloc(struct_size(diag0c_data, entry, cpu_count),
43 GFP_KERNEL | GFP_DMA);
45 goto fail_kfree_cpu_vec;
47 /* Fill CPU vector for each online CPU */
48 for_each_online_cpu(cpu) {
49 diag0c_data->entry[i].cpu = cpu;
50 cpu_vec[cpu] = &diag0c_data->entry[i++];
52 /* Collect data all CPUs */
53 on_each_cpu(diag0c_fn, cpu_vec, 1);
63 return ERR_PTR(-ENOMEM);
67 * Hypfs DBFS callback: Free diag 0c data
69 static void dbfs_diag0c_free(const void *data)
75 * Hypfs DBFS callback: Create diag 0c data
77 static int dbfs_diag0c_create(void **data, void **data_free_ptr, size_t *size)
79 struct hypfs_diag0c_data *diag0c_data;
82 diag0c_data = diag0c_store(&count);
83 if (IS_ERR(diag0c_data))
84 return PTR_ERR(diag0c_data);
85 memset(&diag0c_data->hdr, 0, sizeof(diag0c_data->hdr));
86 store_tod_clock_ext((union tod_clock *)diag0c_data->hdr.tod_ext);
87 diag0c_data->hdr.len = count * sizeof(struct hypfs_diag0c_entry);
88 diag0c_data->hdr.version = DBFS_D0C_HDR_VERSION;
89 diag0c_data->hdr.count = count;
91 *data_free_ptr = diag0c_data;
92 *size = diag0c_data->hdr.len + sizeof(struct hypfs_diag0c_hdr);
97 * Hypfs DBFS file structure
99 static struct hypfs_dbfs_file dbfs_file_0c = {
101 .data_create = dbfs_diag0c_create,
102 .data_free = dbfs_diag0c_free,
106 * Initialize diag 0c interface for z/VM
108 int __init hypfs_diag0c_init(void)
112 hypfs_dbfs_create_file(&dbfs_file_0c);
117 * Shutdown diag 0c interface for z/VM
119 void hypfs_diag0c_exit(void)
123 hypfs_dbfs_remove_file(&dbfs_file_0c);