hypfs_diag0c.c 2.9 KB

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