module.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. static int __devinit ibmasm_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
  56. {
  57. int err, result = -ENOMEM;
  58. struct service_processor *sp;
  59. if ((err = pci_enable_device(pdev))) {
  60. printk(KERN_ERR "%s: can't enable PCI device at %s\n",
  61. DRIVER_NAME, pci_name(pdev));
  62. return err;
  63. }
  64. sp = kmalloc(sizeof(struct service_processor), GFP_KERNEL);
  65. if (sp == NULL) {
  66. dev_err(&pdev->dev, "Failed to allocate memory\n");
  67. result = -ENOMEM;
  68. goto error_kmalloc;
  69. }
  70. memset(sp, 0, sizeof(struct service_processor));
  71. pci_set_drvdata(pdev, (void *)sp);
  72. sp->dev = &pdev->dev;
  73. sp->number = pdev->bus->number;
  74. snprintf(sp->dirname, IBMASM_NAME_SIZE, "%d", sp->number);
  75. snprintf(sp->devname, IBMASM_NAME_SIZE, "%s%d", DRIVER_NAME, sp->number);
  76. if (ibmasm_event_buffer_init(sp)) {
  77. dev_err(sp->dev, "Failed to allocate event buffer\n");
  78. goto error_eventbuffer;
  79. }
  80. if (ibmasm_heartbeat_init(sp)) {
  81. dev_err(sp->dev, "Failed to allocate heartbeat command\n");
  82. goto error_heartbeat;
  83. }
  84. sp->irq = pdev->irq;
  85. sp->base_address = ioremap(pci_resource_start(pdev, 0),
  86. pci_resource_len(pdev, 0));
  87. if (sp->base_address == 0) {
  88. dev_err(sp->dev, "Failed to ioremap pci memory\n");
  89. result = -ENODEV;
  90. goto error_ioremap;
  91. }
  92. result = ibmasm_init_remote_queue(sp);
  93. if (result) {
  94. dev_err(sp->dev, "Failed to initialize remote queue\n");
  95. goto error_remote_queue;
  96. }
  97. spin_lock_init(&sp->lock);
  98. INIT_LIST_HEAD(&sp->command_queue);
  99. result = request_irq(sp->irq, ibmasm_interrupt_handler, SA_SHIRQ, sp->devname, (void*)sp);
  100. if (result) {
  101. dev_err(sp->dev, "Failed to register interrupt handler\n");
  102. goto error_request_irq;
  103. }
  104. enable_sp_interrupts(sp->base_address);
  105. disable_mouse_interrupts(sp);
  106. result = ibmasm_send_driver_vpd(sp);
  107. if (result) {
  108. dev_err(sp->dev, "Failed to send driver VPD to service processor\n");
  109. goto error_send_message;
  110. }
  111. result = ibmasm_send_os_state(sp, SYSTEM_STATE_OS_UP);
  112. if (result) {
  113. dev_err(sp->dev, "Failed to send OS state to service processor\n");
  114. goto error_send_message;
  115. }
  116. ibmasmfs_add_sp(sp);
  117. ibmasm_register_uart(sp);
  118. dev_printk(KERN_DEBUG, &pdev->dev, "WARNING: This software may not be supported or function\n");
  119. dev_printk(KERN_DEBUG, &pdev->dev, "correctly on your IBM server. Please consult the IBM\n");
  120. dev_printk(KERN_DEBUG, &pdev->dev, "ServerProven website\n");
  121. dev_printk(KERN_DEBUG, &pdev->dev, "http://www.pc.ibm.com/ww/eserver/xseries/serverproven\n");
  122. dev_printk(KERN_DEBUG, &pdev->dev, "for information on the specific driver level and support\n");
  123. dev_printk(KERN_DEBUG, &pdev->dev, "statement for your IBM server.\n");
  124. return 0;
  125. error_send_message:
  126. disable_sp_interrupts(sp->base_address);
  127. free_irq(sp->irq, (void *)sp);
  128. error_request_irq:
  129. ibmasm_free_remote_queue(sp);
  130. error_remote_queue:
  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_disable_device(pdev);
  140. return result;
  141. }
  142. static void __devexit ibmasm_remove_one(struct pci_dev *pdev)
  143. {
  144. struct service_processor *sp = (struct service_processor *)pci_get_drvdata(pdev);
  145. ibmasm_unregister_uart(sp);
  146. ibmasm_send_os_state(sp, SYSTEM_STATE_OS_DOWN);
  147. disable_sp_interrupts(sp->base_address);
  148. disable_mouse_interrupts(sp);
  149. free_irq(sp->irq, (void *)sp);
  150. ibmasm_heartbeat_exit(sp);
  151. ibmasm_free_remote_queue(sp);
  152. iounmap(sp->base_address);
  153. ibmasm_event_buffer_exit(sp);
  154. kfree(sp);
  155. pci_disable_device(pdev);
  156. }
  157. static struct pci_device_id ibmasm_pci_table[] =
  158. {
  159. { PCI_DEVICE(VENDORID_IBM, DEVICEID_RSA) },
  160. {},
  161. };
  162. static struct pci_driver ibmasm_driver = {
  163. .name = DRIVER_NAME,
  164. .id_table = ibmasm_pci_table,
  165. .probe = ibmasm_init_one,
  166. .remove = __devexit_p(ibmasm_remove_one),
  167. };
  168. static void __exit ibmasm_exit (void)
  169. {
  170. ibmasm_unregister_panic_notifier();
  171. ibmasmfs_unregister();
  172. pci_unregister_driver(&ibmasm_driver);
  173. info(DRIVER_DESC " version " DRIVER_VERSION " unloaded");
  174. }
  175. static int __init ibmasm_init(void)
  176. {
  177. int result;
  178. result = ibmasmfs_register();
  179. if (result) {
  180. err("Failed to register ibmasmfs file system");
  181. return result;
  182. }
  183. result = pci_register_driver(&ibmasm_driver);
  184. if (result) {
  185. ibmasmfs_unregister();
  186. return result;
  187. }
  188. ibmasm_register_panic_notifier();
  189. info(DRIVER_DESC " version " DRIVER_VERSION " loaded");
  190. return 0;
  191. }
  192. module_init(ibmasm_init);
  193. module_exit(ibmasm_exit);
  194. MODULE_AUTHOR(DRIVER_AUTHOR);
  195. MODULE_DESCRIPTION(DRIVER_DESC);
  196. MODULE_LICENSE("GPL");
  197. MODULE_DEVICE_TABLE(pci, ibmasm_pci_table);