module.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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 "ibmasm.h"
  53. #include "lowlevel.h"
  54. #include "remote.h"
  55. int ibmasm_debug = 0;
  56. module_param(ibmasm_debug, int , S_IRUGO | S_IWUSR);
  57. MODULE_PARM_DESC(ibmasm_debug, " Set debug mode on or off");
  58. static int __devinit ibmasm_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
  59. {
  60. int result;
  61. struct service_processor *sp;
  62. if ((result = pci_enable_device(pdev))) {
  63. dev_err(&pdev->dev, "Failed to enable PCI device\n");
  64. return result;
  65. }
  66. if ((result = pci_request_regions(pdev, DRIVER_NAME))) {
  67. dev_err(&pdev->dev, "Failed to allocate PCI resources\n");
  68. goto error_resources;
  69. }
  70. /* vnc client won't work without bus-mastering */
  71. pci_set_master(pdev);
  72. sp = kmalloc(sizeof(struct service_processor), GFP_KERNEL);
  73. if (sp == NULL) {
  74. dev_err(&pdev->dev, "Failed to allocate memory\n");
  75. result = -ENOMEM;
  76. goto error_kmalloc;
  77. }
  78. memset(sp, 0, sizeof(struct service_processor));
  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 = ioremap(pci_resource_start(pdev, 0),
  96. pci_resource_len(pdev, 0));
  97. if (sp->base_address == 0) {
  98. dev_err(sp->dev, "Failed to ioremap pci memory\n");
  99. result = -ENODEV;
  100. goto error_ioremap;
  101. }
  102. result = request_irq(sp->irq, ibmasm_interrupt_handler, IRQF_SHARED, sp->devname, (void*)sp);
  103. if (result) {
  104. dev_err(sp->dev, "Failed to register interrupt handler\n");
  105. goto error_request_irq;
  106. }
  107. enable_sp_interrupts(sp->base_address);
  108. result = ibmasm_init_remote_input_dev(sp);
  109. if (result) {
  110. dev_err(sp->dev, "Failed to initialize remote queue\n");
  111. goto error_send_message;
  112. }
  113. result = ibmasm_send_driver_vpd(sp);
  114. if (result) {
  115. dev_err(sp->dev, "Failed to send driver VPD to service processor\n");
  116. goto error_send_message;
  117. }
  118. result = ibmasm_send_os_state(sp, SYSTEM_STATE_OS_UP);
  119. if (result) {
  120. dev_err(sp->dev, "Failed to send OS state to service processor\n");
  121. goto error_send_message;
  122. }
  123. ibmasmfs_add_sp(sp);
  124. ibmasm_register_uart(sp);
  125. return 0;
  126. error_send_message:
  127. disable_sp_interrupts(sp->base_address);
  128. ibmasm_free_remote_input_dev(sp);
  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. pci_set_drvdata(pdev, NULL);
  138. kfree(sp);
  139. error_kmalloc:
  140. pci_release_regions(pdev);
  141. error_resources:
  142. pci_disable_device(pdev);
  143. return result;
  144. }
  145. static void __devexit ibmasm_remove_one(struct pci_dev *pdev)
  146. {
  147. struct service_processor *sp = (struct service_processor *)pci_get_drvdata(pdev);
  148. dbg("Unregistering UART\n");
  149. ibmasm_unregister_uart(sp);
  150. dbg("Sending OS down message\n");
  151. if (ibmasm_send_os_state(sp, SYSTEM_STATE_OS_DOWN))
  152. err("failed to get repsonse to 'Send OS State' command\n");
  153. dbg("Disabling heartbeats\n");
  154. ibmasm_heartbeat_exit(sp);
  155. dbg("Disabling interrupts\n");
  156. disable_sp_interrupts(sp->base_address);
  157. dbg("Freeing SP irq\n");
  158. free_irq(sp->irq, (void *)sp);
  159. dbg("Cleaning up\n");
  160. ibmasm_free_remote_input_dev(sp);
  161. iounmap(sp->base_address);
  162. ibmasm_event_buffer_exit(sp);
  163. pci_set_drvdata(pdev, NULL);
  164. kfree(sp);
  165. pci_release_regions(pdev);
  166. pci_disable_device(pdev);
  167. }
  168. static struct pci_device_id ibmasm_pci_table[] =
  169. {
  170. { PCI_DEVICE(VENDORID_IBM, DEVICEID_RSA) },
  171. {},
  172. };
  173. static struct pci_driver ibmasm_driver = {
  174. .name = DRIVER_NAME,
  175. .id_table = ibmasm_pci_table,
  176. .probe = ibmasm_init_one,
  177. .remove = __devexit_p(ibmasm_remove_one),
  178. };
  179. static void __exit ibmasm_exit (void)
  180. {
  181. ibmasm_unregister_panic_notifier();
  182. ibmasmfs_unregister();
  183. pci_unregister_driver(&ibmasm_driver);
  184. info(DRIVER_DESC " version " DRIVER_VERSION " unloaded");
  185. }
  186. static int __init ibmasm_init(void)
  187. {
  188. int result;
  189. result = ibmasmfs_register();
  190. if (result) {
  191. err("Failed to register ibmasmfs file system");
  192. return result;
  193. }
  194. result = pci_register_driver(&ibmasm_driver);
  195. if (result) {
  196. ibmasmfs_unregister();
  197. return result;
  198. }
  199. ibmasm_register_panic_notifier();
  200. info(DRIVER_DESC " version " DRIVER_VERSION " loaded");
  201. return 0;
  202. }
  203. module_init(ibmasm_init);
  204. module_exit(ibmasm_exit);
  205. MODULE_AUTHOR(DRIVER_AUTHOR);
  206. MODULE_DESCRIPTION(DRIVER_DESC);
  207. MODULE_LICENSE("GPL");
  208. MODULE_DEVICE_TABLE(pci, ibmasm_pci_table);