module.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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 <[email protected]>
  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_init_remote;
  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. ibmasm_free_remote_input_dev(sp);
  115. error_init_remote:
  116. disable_sp_interrupts(sp->base_address);
  117. free_irq(sp->irq, (void *)sp);
  118. error_request_irq:
  119. iounmap(sp->base_address);
  120. error_ioremap:
  121. ibmasm_heartbeat_exit(sp);
  122. error_heartbeat:
  123. ibmasm_event_buffer_exit(sp);
  124. error_eventbuffer:
  125. kfree(sp);
  126. error_kmalloc:
  127. pci_release_regions(pdev);
  128. error_resources:
  129. pci_disable_device(pdev);
  130. return result;
  131. }
  132. static void ibmasm_remove_one(struct pci_dev *pdev)
  133. {
  134. struct service_processor *sp = pci_get_drvdata(pdev);
  135. dbg("Unregistering UART\n");
  136. ibmasm_unregister_uart(sp);
  137. dbg("Sending OS down message\n");
  138. if (ibmasm_send_os_state(sp, SYSTEM_STATE_OS_DOWN))
  139. err("failed to get response to 'Send OS State' command\n");
  140. dbg("Disabling heartbeats\n");
  141. ibmasm_heartbeat_exit(sp);
  142. dbg("Disabling interrupts\n");
  143. disable_sp_interrupts(sp->base_address);
  144. dbg("Freeing SP irq\n");
  145. free_irq(sp->irq, (void *)sp);
  146. dbg("Cleaning up\n");
  147. ibmasm_free_remote_input_dev(sp);
  148. iounmap(sp->base_address);
  149. ibmasm_event_buffer_exit(sp);
  150. kfree(sp);
  151. pci_release_regions(pdev);
  152. pci_disable_device(pdev);
  153. }
  154. static struct pci_device_id ibmasm_pci_table[] =
  155. {
  156. { PCI_DEVICE(VENDORID_IBM, DEVICEID_RSA) },
  157. {},
  158. };
  159. static struct pci_driver ibmasm_driver = {
  160. .name = DRIVER_NAME,
  161. .id_table = ibmasm_pci_table,
  162. .probe = ibmasm_init_one,
  163. .remove = ibmasm_remove_one,
  164. };
  165. static void __exit ibmasm_exit (void)
  166. {
  167. ibmasm_unregister_panic_notifier();
  168. ibmasmfs_unregister();
  169. pci_unregister_driver(&ibmasm_driver);
  170. info(DRIVER_DESC " version " DRIVER_VERSION " unloaded");
  171. }
  172. static int __init ibmasm_init(void)
  173. {
  174. int result = pci_register_driver(&ibmasm_driver);
  175. if (result)
  176. return result;
  177. result = ibmasmfs_register();
  178. if (result) {
  179. pci_unregister_driver(&ibmasm_driver);
  180. err("Failed to register ibmasmfs file system");
  181. return result;
  182. }
  183. ibmasm_register_panic_notifier();
  184. info(DRIVER_DESC " version " DRIVER_VERSION " loaded");
  185. return 0;
  186. }
  187. module_init(ibmasm_init);
  188. module_exit(ibmasm_exit);
  189. MODULE_AUTHOR(DRIVER_AUTHOR);
  190. MODULE_DESCRIPTION(DRIVER_DESC);
  191. MODULE_LICENSE("GPL");
  192. MODULE_DEVICE_TABLE(pci, ibmasm_pci_table);