hypfs_diag0c.c 2.9 KB

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