module.c 6.4 KB

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