]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - arch/s390/hypfs/hypfs_diag0c.c
Merge tag 'perf-urgent-for-mingo-4.10-20170104' of git://git.kernel.org/pub/scm/linux...
[mirror_ubuntu-artful-kernel.git] / arch / s390 / hypfs / hypfs_diag0c.c
CommitLineData
34c0dad7
MH
1/*
2 * Hypervisor filesystem for Linux on s390
3 *
4 * Diag 0C implementation
5 *
6 * Copyright IBM Corp. 2014
7 */
8
9#include <linux/slab.h>
10#include <linux/cpu.h>
1ec2772e 11#include <asm/diag.h>
34c0dad7
MH
12#include <asm/hypfs.h>
13#include "hypfs.h"
14
15#define DBFS_D0C_HDR_VERSION 0
16
17/*
18 * Execute diagnose 0c in 31 bit mode
19 */
20static void diag0c(struct hypfs_diag0c_entry *entry)
21{
1ec2772e 22 diag_stat_inc(DIAG_STAT_X00C);
34c0dad7 23 asm volatile (
34c0dad7
MH
24 " sam31\n"
25 " diag %0,%0,0x0c\n"
26 " sam64\n"
34c0dad7
MH
27 : /* no output register */
28 : "a" (entry)
29 : "memory");
30}
31
32/*
33 * Get hypfs_diag0c_entry from CPU vector and store diag0c data
34 */
35static void diag0c_fn(void *data)
36{
37 diag0c(((void **) data)[smp_processor_id()]);
38}
39
40/*
41 * Allocate buffer and store diag 0c data
42 */
43static void *diag0c_store(unsigned int *count)
44{
45 struct hypfs_diag0c_data *diag0c_data;
46 unsigned int cpu_count, cpu, i;
47 void **cpu_vec;
48
49 get_online_cpus();
50 cpu_count = num_online_cpus();
51 cpu_vec = kmalloc(sizeof(*cpu_vec) * num_possible_cpus(), GFP_KERNEL);
52 if (!cpu_vec)
53 goto fail_put_online_cpus;
54 /* Note: Diag 0c needs 8 byte alignment and real storage */
55 diag0c_data = kzalloc(sizeof(struct hypfs_diag0c_hdr) +
56 cpu_count * sizeof(struct hypfs_diag0c_entry),
57 GFP_KERNEL | GFP_DMA);
58 if (!diag0c_data)
59 goto fail_kfree_cpu_vec;
60 i = 0;
61 /* Fill CPU vector for each online CPU */
62 for_each_online_cpu(cpu) {
63 diag0c_data->entry[i].cpu = cpu;
64 cpu_vec[cpu] = &diag0c_data->entry[i++];
65 }
66 /* Collect data all CPUs */
67 on_each_cpu(diag0c_fn, cpu_vec, 1);
68 *count = cpu_count;
69 kfree(cpu_vec);
70 put_online_cpus();
71 return diag0c_data;
72
73fail_kfree_cpu_vec:
74 kfree(cpu_vec);
75fail_put_online_cpus:
76 put_online_cpus();
77 return ERR_PTR(-ENOMEM);
78}
79
80/*
81 * Hypfs DBFS callback: Free diag 0c data
82 */
83static void dbfs_diag0c_free(const void *data)
84{
85 kfree(data);
86}
87
88/*
89 * Hypfs DBFS callback: Create diag 0c data
90 */
91static int dbfs_diag0c_create(void **data, void **data_free_ptr, size_t *size)
92{
93 struct hypfs_diag0c_data *diag0c_data;
94 unsigned int count;
95
96 diag0c_data = diag0c_store(&count);
97 if (IS_ERR(diag0c_data))
98 return PTR_ERR(diag0c_data);
99 memset(&diag0c_data->hdr, 0, sizeof(diag0c_data->hdr));
100 get_tod_clock_ext(diag0c_data->hdr.tod_ext);
101 diag0c_data->hdr.len = count * sizeof(struct hypfs_diag0c_entry);
102 diag0c_data->hdr.version = DBFS_D0C_HDR_VERSION;
103 diag0c_data->hdr.count = count;
104 *data = diag0c_data;
105 *data_free_ptr = diag0c_data;
106 *size = diag0c_data->hdr.len + sizeof(struct hypfs_diag0c_hdr);
107 return 0;
108}
109
110/*
111 * Hypfs DBFS file structure
112 */
113static struct hypfs_dbfs_file dbfs_file_0c = {
114 .name = "diag_0c",
115 .data_create = dbfs_diag0c_create,
116 .data_free = dbfs_diag0c_free,
117};
118
119/*
120 * Initialize diag 0c interface for z/VM
121 */
122int __init hypfs_diag0c_init(void)
123{
124 if (!MACHINE_IS_VM)
125 return 0;
126 return hypfs_dbfs_create_file(&dbfs_file_0c);
127}
128
129/*
130 * Shutdown diag 0c interface for z/VM
131 */
132void hypfs_diag0c_exit(void)
133{
134 if (!MACHINE_IS_VM)
135 return;
136 hypfs_dbfs_remove_file(&dbfs_file_0c);
137}