sclp_config.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*
  2. * Copyright IBM Corp. 2007
  3. * Author(s): Heiko Carstens <heiko.carstens@de.ibm.com>
  4. */
  5. #define KMSG_COMPONENT "sclp_config"
  6. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  7. #include <linux/init.h>
  8. #include <linux/errno.h>
  9. #include <linux/cpu.h>
  10. #include <linux/device.h>
  11. #include <linux/workqueue.h>
  12. #include <linux/slab.h>
  13. #include <linux/sysfs.h>
  14. #include <asm/smp.h>
  15. #include "sclp.h"
  16. struct conf_mgm_data {
  17. u8 reserved;
  18. u8 ev_qualifier;
  19. } __attribute__((packed));
  20. #define OFB_DATA_MAX 64
  21. struct sclp_ofb_evbuf {
  22. struct evbuf_header header;
  23. struct conf_mgm_data cm_data;
  24. char ev_data[OFB_DATA_MAX];
  25. } __packed;
  26. struct sclp_ofb_sccb {
  27. struct sccb_header header;
  28. struct sclp_ofb_evbuf ofb_evbuf;
  29. } __packed;
  30. #define EV_QUAL_CPU_CHANGE 1
  31. #define EV_QUAL_CAP_CHANGE 3
  32. #define EV_QUAL_OPEN4BUSINESS 5
  33. static struct work_struct sclp_cpu_capability_work;
  34. static struct work_struct sclp_cpu_change_work;
  35. static void sclp_cpu_capability_notify(struct work_struct *work)
  36. {
  37. int cpu;
  38. struct device *dev;
  39. s390_update_cpu_mhz();
  40. pr_info("CPU capability may have changed\n");
  41. get_online_cpus();
  42. for_each_online_cpu(cpu) {
  43. dev = get_cpu_device(cpu);
  44. kobject_uevent(&dev->kobj, KOBJ_CHANGE);
  45. }
  46. put_online_cpus();
  47. }
  48. static void __ref sclp_cpu_change_notify(struct work_struct *work)
  49. {
  50. smp_rescan_cpus();
  51. }
  52. static void sclp_conf_receiver_fn(struct evbuf_header *evbuf)
  53. {
  54. struct conf_mgm_data *cdata;
  55. cdata = (struct conf_mgm_data *)(evbuf + 1);
  56. switch (cdata->ev_qualifier) {
  57. case EV_QUAL_CPU_CHANGE:
  58. schedule_work(&sclp_cpu_change_work);
  59. break;
  60. case EV_QUAL_CAP_CHANGE:
  61. schedule_work(&sclp_cpu_capability_work);
  62. break;
  63. }
  64. }
  65. static struct sclp_register sclp_conf_register =
  66. {
  67. #ifdef CONFIG_SCLP_OFB
  68. .send_mask = EVTYP_CONFMGMDATA_MASK,
  69. #endif
  70. .receive_mask = EVTYP_CONFMGMDATA_MASK,
  71. .receiver_fn = sclp_conf_receiver_fn,
  72. };
  73. #ifdef CONFIG_SCLP_OFB
  74. static int sclp_ofb_send_req(char *ev_data, size_t len)
  75. {
  76. static DEFINE_MUTEX(send_mutex);
  77. struct sclp_ofb_sccb *sccb;
  78. int rc, response;
  79. if (len > OFB_DATA_MAX)
  80. return -EINVAL;
  81. sccb = (struct sclp_ofb_sccb *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
  82. if (!sccb)
  83. return -ENOMEM;
  84. /* Setup SCCB for Control-Program Identification */
  85. sccb->header.length = sizeof(struct sclp_ofb_sccb);
  86. sccb->ofb_evbuf.header.length = sizeof(struct sclp_ofb_evbuf);
  87. sccb->ofb_evbuf.header.type = EVTYP_CONFMGMDATA;
  88. sccb->ofb_evbuf.cm_data.ev_qualifier = EV_QUAL_OPEN4BUSINESS;
  89. memcpy(sccb->ofb_evbuf.ev_data, ev_data, len);
  90. if (!(sclp_conf_register.sclp_receive_mask & EVTYP_CONFMGMDATA_MASK))
  91. pr_warn("SCLP receiver did not register to receive "
  92. "Configuration Management Data Events.\n");
  93. mutex_lock(&send_mutex);
  94. rc = sclp_sync_request(SCLP_CMDW_WRITE_EVENT_DATA, sccb);
  95. mutex_unlock(&send_mutex);
  96. if (rc)
  97. goto out;
  98. response = sccb->header.response_code;
  99. if (response != 0x0020) {
  100. pr_err("Open for Business request failed with response code "
  101. "0x%04x\n", response);
  102. rc = -EIO;
  103. }
  104. out:
  105. free_page((unsigned long)sccb);
  106. return rc;
  107. }
  108. static ssize_t sysfs_ofb_data_write(struct file *filp, struct kobject *kobj,
  109. struct bin_attribute *bin_attr,
  110. char *buf, loff_t off, size_t count)
  111. {
  112. int rc;
  113. rc = sclp_ofb_send_req(buf, count);
  114. return rc ?: count;
  115. }
  116. static struct bin_attribute ofb_bin_attr = {
  117. .attr = {
  118. .name = "event_data",
  119. .mode = S_IWUSR,
  120. },
  121. .write = sysfs_ofb_data_write,
  122. };
  123. #endif
  124. static int __init sclp_ofb_setup(void)
  125. {
  126. #ifdef CONFIG_SCLP_OFB
  127. struct kset *ofb_kset;
  128. int rc;
  129. ofb_kset = kset_create_and_add("ofb", NULL, firmware_kobj);
  130. if (!ofb_kset)
  131. return -ENOMEM;
  132. rc = sysfs_create_bin_file(&ofb_kset->kobj, &ofb_bin_attr);
  133. if (rc) {
  134. kset_unregister(ofb_kset);
  135. return rc;
  136. }
  137. #endif
  138. return 0;
  139. }
  140. static int __init sclp_conf_init(void)
  141. {
  142. int rc;
  143. INIT_WORK(&sclp_cpu_capability_work, sclp_cpu_capability_notify);
  144. INIT_WORK(&sclp_cpu_change_work, sclp_cpu_change_notify);
  145. rc = sclp_register(&sclp_conf_register);
  146. if (rc)
  147. return rc;
  148. return sclp_ofb_setup();
  149. }
  150. __initcall(sclp_conf_init);