Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * Hypervisor filesystem for Linux on s390
0004  *
0005  * Diag 0C implementation
0006  *
0007  * Copyright IBM Corp. 2014
0008  */
0009 
0010 #include <linux/slab.h>
0011 #include <linux/cpu.h>
0012 #include <asm/diag.h>
0013 #include <asm/hypfs.h>
0014 #include "hypfs.h"
0015 
0016 #define DBFS_D0C_HDR_VERSION 0
0017 
0018 /*
0019  * Get hypfs_diag0c_entry from CPU vector and store diag0c data
0020  */
0021 static void diag0c_fn(void *data)
0022 {
0023     diag_stat_inc(DIAG_STAT_X00C);
0024     diag_amode31_ops.diag0c(((void **)data)[smp_processor_id()]);
0025 }
0026 
0027 /*
0028  * Allocate buffer and store diag 0c data
0029  */
0030 static void *diag0c_store(unsigned int *count)
0031 {
0032     struct hypfs_diag0c_data *diag0c_data;
0033     unsigned int cpu_count, cpu, i;
0034     void **cpu_vec;
0035 
0036     cpus_read_lock();
0037     cpu_count = num_online_cpus();
0038     cpu_vec = kmalloc_array(num_possible_cpus(), sizeof(*cpu_vec),
0039                 GFP_KERNEL);
0040     if (!cpu_vec)
0041         goto fail_unlock_cpus;
0042     /* Note: Diag 0c needs 8 byte alignment and real storage */
0043     diag0c_data = kzalloc(struct_size(diag0c_data, entry, cpu_count),
0044                   GFP_KERNEL | GFP_DMA);
0045     if (!diag0c_data)
0046         goto fail_kfree_cpu_vec;
0047     i = 0;
0048     /* Fill CPU vector for each online CPU */
0049     for_each_online_cpu(cpu) {
0050         diag0c_data->entry[i].cpu = cpu;
0051         cpu_vec[cpu] = &diag0c_data->entry[i++];
0052     }
0053     /* Collect data all CPUs */
0054     on_each_cpu(diag0c_fn, cpu_vec, 1);
0055     *count = cpu_count;
0056     kfree(cpu_vec);
0057     cpus_read_unlock();
0058     return diag0c_data;
0059 
0060 fail_kfree_cpu_vec:
0061     kfree(cpu_vec);
0062 fail_unlock_cpus:
0063     cpus_read_unlock();
0064     return ERR_PTR(-ENOMEM);
0065 }
0066 
0067 /*
0068  * Hypfs DBFS callback: Free diag 0c data
0069  */
0070 static void dbfs_diag0c_free(const void *data)
0071 {
0072     kfree(data);
0073 }
0074 
0075 /*
0076  * Hypfs DBFS callback: Create diag 0c data
0077  */
0078 static int dbfs_diag0c_create(void **data, void **data_free_ptr, size_t *size)
0079 {
0080     struct hypfs_diag0c_data *diag0c_data;
0081     unsigned int count;
0082 
0083     diag0c_data = diag0c_store(&count);
0084     if (IS_ERR(diag0c_data))
0085         return PTR_ERR(diag0c_data);
0086     memset(&diag0c_data->hdr, 0, sizeof(diag0c_data->hdr));
0087     store_tod_clock_ext((union tod_clock *)diag0c_data->hdr.tod_ext);
0088     diag0c_data->hdr.len = count * sizeof(struct hypfs_diag0c_entry);
0089     diag0c_data->hdr.version = DBFS_D0C_HDR_VERSION;
0090     diag0c_data->hdr.count = count;
0091     *data = diag0c_data;
0092     *data_free_ptr = diag0c_data;
0093     *size = diag0c_data->hdr.len + sizeof(struct hypfs_diag0c_hdr);
0094     return 0;
0095 }
0096 
0097 /*
0098  * Hypfs DBFS file structure
0099  */
0100 static struct hypfs_dbfs_file dbfs_file_0c = {
0101     .name       = "diag_0c",
0102     .data_create    = dbfs_diag0c_create,
0103     .data_free  = dbfs_diag0c_free,
0104 };
0105 
0106 /*
0107  * Initialize diag 0c interface for z/VM
0108  */
0109 int __init hypfs_diag0c_init(void)
0110 {
0111     if (!MACHINE_IS_VM)
0112         return 0;
0113     hypfs_dbfs_create_file(&dbfs_file_0c);
0114     return 0;
0115 }
0116 
0117 /*
0118  * Shutdown diag 0c interface for z/VM
0119  */
0120 void hypfs_diag0c_exit(void)
0121 {
0122     if (!MACHINE_IS_VM)
0123         return;
0124     hypfs_dbfs_remove_file(&dbfs_file_0c);
0125 }