mm: make wait_on_page_writeback() wait for multiple pending writebacks
[linux/fpc-iii.git] / arch / s390 / hypfs / hypfs_diag0c.c
blob3235e4d82f2d550c209baaa6d94c5800e73c56c3
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Hypervisor filesystem for Linux on s390
5 * Diag 0C implementation
7 * Copyright IBM Corp. 2014
8 */
10 #include <linux/slab.h>
11 #include <linux/cpu.h>
12 #include <asm/diag.h>
13 #include <asm/hypfs.h>
14 #include "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;
34 void **cpu_vec;
36 get_online_cpus();
37 cpu_count = num_online_cpus();
38 cpu_vec = kmalloc_array(num_possible_cpus(), sizeof(*cpu_vec),
39 GFP_KERNEL);
40 if (!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);
45 if (!diag0c_data)
46 goto fail_kfree_cpu_vec;
47 i = 0;
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);
55 *count = cpu_count;
56 kfree(cpu_vec);
57 put_online_cpus();
58 return diag0c_data;
60 fail_kfree_cpu_vec:
61 kfree(cpu_vec);
62 fail_put_online_cpus:
63 put_online_cpus();
64 return ERR_PTR(-ENOMEM);
68 * Hypfs DBFS callback: Free diag 0c data
70 static void dbfs_diag0c_free(const void *data)
72 kfree(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;
81 unsigned int count;
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;
91 *data = diag0c_data;
92 *data_free_ptr = diag0c_data;
93 *size = diag0c_data->hdr.len + sizeof(struct hypfs_diag0c_hdr);
94 return 0;
98 * Hypfs DBFS file structure
100 static struct hypfs_dbfs_file dbfs_file_0c = {
101 .name = "diag_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)
111 if (!MACHINE_IS_VM)
112 return 0;
113 hypfs_dbfs_create_file(&dbfs_file_0c);
114 return 0;
118 * Shutdown diag 0c interface for z/VM
120 void hypfs_diag0c_exit(void)
122 if (!MACHINE_IS_VM)
123 return;
124 hypfs_dbfs_remove_file(&dbfs_file_0c);