module.c 6.4 KB

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