/drivers/misc/ibmasm/module.c

http://github.com/mirrors/linux · C · 223 lines · 155 code · 32 blank · 36 comment · 14 complexity · 70a3cf8e684a403052703905405240f8 MD5 · raw file

  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * IBM ASM Service Processor Device Driver
  4. *
  5. * Copyright (C) IBM Corporation, 2004
  6. *
  7. * Author: Max Asböck <amax@us.ibm.com>
  8. *
  9. * This driver is based on code originally written by Pete Reynolds
  10. * and others.
  11. */
  12. /*
  13. * The ASM device driver does the following things:
  14. *
  15. * 1) When loaded it sends a message to the service processor,
  16. * indicating that an OS is * running. This causes the service processor
  17. * to send periodic heartbeats to the OS.
  18. *
  19. * 2) Answers the periodic heartbeats sent by the service processor.
  20. * Failure to do so would result in system reboot.
  21. *
  22. * 3) Acts as a pass through for dot commands sent from user applications.
  23. * The interface for this is the ibmasmfs file system.
  24. *
  25. * 4) Allows user applications to register for event notification. Events
  26. * are sent to the driver through interrupts. They can be read from user
  27. * space through the ibmasmfs file system.
  28. *
  29. * 5) Allows user space applications to send heartbeats to the service
  30. * processor (aka reverse heartbeats). Again this happens through ibmasmfs.
  31. *
  32. * 6) Handles remote mouse and keyboard event interrupts and makes them
  33. * available to user applications through ibmasmfs.
  34. *
  35. */
  36. #include <linux/pci.h>
  37. #include <linux/init.h>
  38. #include <linux/slab.h>
  39. #include "ibmasm.h"
  40. #include "lowlevel.h"
  41. #include "remote.h"
  42. int ibmasm_debug = 0;
  43. module_param(ibmasm_debug, int , S_IRUGO | S_IWUSR);
  44. MODULE_PARM_DESC(ibmasm_debug, " Set debug mode on or off");
  45. static int ibmasm_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
  46. {
  47. int result;
  48. struct service_processor *sp;
  49. if ((result = pci_enable_device(pdev))) {
  50. dev_err(&pdev->dev, "Failed to enable PCI device\n");
  51. return result;
  52. }
  53. if ((result = pci_request_regions(pdev, DRIVER_NAME))) {
  54. dev_err(&pdev->dev, "Failed to allocate PCI resources\n");
  55. goto error_resources;
  56. }
  57. /* vnc client won't work without bus-mastering */
  58. pci_set_master(pdev);
  59. sp = kzalloc(sizeof(struct service_processor), GFP_KERNEL);
  60. if (sp == NULL) {
  61. dev_err(&pdev->dev, "Failed to allocate memory\n");
  62. result = -ENOMEM;
  63. goto error_kmalloc;
  64. }
  65. spin_lock_init(&sp->lock);
  66. INIT_LIST_HEAD(&sp->command_queue);
  67. pci_set_drvdata(pdev, (void *)sp);
  68. sp->dev = &pdev->dev;
  69. sp->number = pdev->bus->number;
  70. snprintf(sp->dirname, IBMASM_NAME_SIZE, "%d", sp->number);
  71. snprintf(sp->devname, IBMASM_NAME_SIZE, "%s%d", DRIVER_NAME, sp->number);
  72. result = ibmasm_event_buffer_init(sp);
  73. if (result) {
  74. dev_err(sp->dev, "Failed to allocate event buffer\n");
  75. goto error_eventbuffer;
  76. }
  77. result = ibmasm_heartbeat_init(sp);
  78. if (result) {
  79. dev_err(sp->dev, "Failed to allocate heartbeat command\n");
  80. goto error_heartbeat;
  81. }
  82. sp->irq = pdev->irq;
  83. sp->base_address = pci_ioremap_bar(pdev, 0);
  84. if (!sp->base_address) {
  85. dev_err(sp->dev, "Failed to ioremap pci memory\n");
  86. result = -ENODEV;
  87. goto error_ioremap;
  88. }
  89. result = request_irq(sp->irq, ibmasm_interrupt_handler, IRQF_SHARED, sp->devname, (void*)sp);
  90. if (result) {
  91. dev_err(sp->dev, "Failed to register interrupt handler\n");
  92. goto error_request_irq;
  93. }
  94. enable_sp_interrupts(sp->base_address);
  95. result = ibmasm_init_remote_input_dev(sp);
  96. if (result) {
  97. dev_err(sp->dev, "Failed to initialize remote queue\n");
  98. goto error_send_message;
  99. }
  100. result = ibmasm_send_driver_vpd(sp);
  101. if (result) {
  102. dev_err(sp->dev, "Failed to send driver VPD to service processor\n");
  103. goto error_send_message;
  104. }
  105. result = ibmasm_send_os_state(sp, SYSTEM_STATE_OS_UP);
  106. if (result) {
  107. dev_err(sp->dev, "Failed to send OS state to service processor\n");
  108. goto error_send_message;
  109. }
  110. ibmasmfs_add_sp(sp);
  111. ibmasm_register_uart(sp);
  112. return 0;
  113. error_send_message:
  114. disable_sp_interrupts(sp->base_address);
  115. ibmasm_free_remote_input_dev(sp);
  116. free_irq(sp->irq, (void *)sp);
  117. error_request_irq:
  118. iounmap(sp->base_address);
  119. error_ioremap:
  120. ibmasm_heartbeat_exit(sp);
  121. error_heartbeat:
  122. ibmasm_event_buffer_exit(sp);
  123. error_eventbuffer:
  124. kfree(sp);
  125. error_kmalloc:
  126. pci_release_regions(pdev);
  127. error_resources:
  128. pci_disable_device(pdev);
  129. return result;
  130. }
  131. static void ibmasm_remove_one(struct pci_dev *pdev)
  132. {
  133. struct service_processor *sp = pci_get_drvdata(pdev);
  134. dbg("Unregistering UART\n");
  135. ibmasm_unregister_uart(sp);
  136. dbg("Sending OS down message\n");
  137. if (ibmasm_send_os_state(sp, SYSTEM_STATE_OS_DOWN))
  138. err("failed to get response to 'Send OS State' command\n");
  139. dbg("Disabling heartbeats\n");
  140. ibmasm_heartbeat_exit(sp);
  141. dbg("Disabling interrupts\n");
  142. disable_sp_interrupts(sp->base_address);
  143. dbg("Freeing SP irq\n");
  144. free_irq(sp->irq, (void *)sp);
  145. dbg("Cleaning up\n");
  146. ibmasm_free_remote_input_dev(sp);
  147. iounmap(sp->base_address);
  148. ibmasm_event_buffer_exit(sp);
  149. kfree(sp);
  150. pci_release_regions(pdev);
  151. pci_disable_device(pdev);
  152. }
  153. static struct pci_device_id ibmasm_pci_table[] =
  154. {
  155. { PCI_DEVICE(VENDORID_IBM, DEVICEID_RSA) },
  156. {},
  157. };
  158. static struct pci_driver ibmasm_driver = {
  159. .name = DRIVER_NAME,
  160. .id_table = ibmasm_pci_table,
  161. .probe = ibmasm_init_one,
  162. .remove = ibmasm_remove_one,
  163. };
  164. static void __exit ibmasm_exit (void)
  165. {
  166. ibmasm_unregister_panic_notifier();
  167. ibmasmfs_unregister();
  168. pci_unregister_driver(&ibmasm_driver);
  169. info(DRIVER_DESC " version " DRIVER_VERSION " unloaded");
  170. }
  171. static int __init ibmasm_init(void)
  172. {
  173. int result = pci_register_driver(&ibmasm_driver);
  174. if (result)
  175. return result;
  176. result = ibmasmfs_register();
  177. if (result) {
  178. pci_unregister_driver(&ibmasm_driver);
  179. err("Failed to register ibmasmfs file system");
  180. return result;
  181. }
  182. ibmasm_register_panic_notifier();
  183. info(DRIVER_DESC " version " DRIVER_VERSION " loaded");
  184. return 0;
  185. }
  186. module_init(ibmasm_init);
  187. module_exit(ibmasm_exit);
  188. MODULE_AUTHOR(DRIVER_AUTHOR);
  189. MODULE_DESCRIPTION(DRIVER_DESC);
  190. MODULE_LICENSE("GPL");
  191. MODULE_DEVICE_TABLE(pci, ibmasm_pci_table);