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 * Execute diagnose 0c in 31 bit mode
21 static void diag0c(struct hypfs_diag0c_entry
*entry
)
23 diag_stat_inc(DIAG_STAT_X00C
);
28 : /* no output register */
34 * Get hypfs_diag0c_entry from CPU vector and store diag0c data
36 static void diag0c_fn(void *data
)
38 diag0c(((void **) data
)[smp_processor_id()]);
42 * Allocate buffer and store diag 0c data
44 static void *diag0c_store(unsigned int *count
)
46 struct hypfs_diag0c_data
*diag0c_data
;
47 unsigned int cpu_count
, cpu
, i
;
51 cpu_count
= num_online_cpus();
52 cpu_vec
= kmalloc_array(num_possible_cpus(), sizeof(*cpu_vec
),
55 goto fail_put_online_cpus
;
56 /* Note: Diag 0c needs 8 byte alignment and real storage */
57 diag0c_data
= kzalloc(sizeof(struct hypfs_diag0c_hdr
) +
58 cpu_count
* sizeof(struct hypfs_diag0c_entry
),
59 GFP_KERNEL
| GFP_DMA
);
61 goto fail_kfree_cpu_vec
;
63 /* Fill CPU vector for each online CPU */
64 for_each_online_cpu(cpu
) {
65 diag0c_data
->entry
[i
].cpu
= cpu
;
66 cpu_vec
[cpu
] = &diag0c_data
->entry
[i
++];
68 /* Collect data all CPUs */
69 on_each_cpu(diag0c_fn
, cpu_vec
, 1);
79 return ERR_PTR(-ENOMEM
);
83 * Hypfs DBFS callback: Free diag 0c data
85 static void dbfs_diag0c_free(const void *data
)
91 * Hypfs DBFS callback: Create diag 0c data
93 static int dbfs_diag0c_create(void **data
, void **data_free_ptr
, size_t *size
)
95 struct hypfs_diag0c_data
*diag0c_data
;
98 diag0c_data
= diag0c_store(&count
);
99 if (IS_ERR(diag0c_data
))
100 return PTR_ERR(diag0c_data
);
101 memset(&diag0c_data
->hdr
, 0, sizeof(diag0c_data
->hdr
));
102 get_tod_clock_ext(diag0c_data
->hdr
.tod_ext
);
103 diag0c_data
->hdr
.len
= count
* sizeof(struct hypfs_diag0c_entry
);
104 diag0c_data
->hdr
.version
= DBFS_D0C_HDR_VERSION
;
105 diag0c_data
->hdr
.count
= count
;
107 *data_free_ptr
= diag0c_data
;
108 *size
= diag0c_data
->hdr
.len
+ sizeof(struct hypfs_diag0c_hdr
);
113 * Hypfs DBFS file structure
115 static struct hypfs_dbfs_file dbfs_file_0c
= {
117 .data_create
= dbfs_diag0c_create
,
118 .data_free
= dbfs_diag0c_free
,
122 * Initialize diag 0c interface for z/VM
124 int __init
hypfs_diag0c_init(void)
128 return hypfs_dbfs_create_file(&dbfs_file_0c
);
132 * Shutdown diag 0c interface for z/VM
134 void hypfs_diag0c_exit(void)
138 hypfs_dbfs_remove_file(&dbfs_file_0c
);