ibmasm.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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. */
  23. #include <linux/kernel.h>
  24. #include <linux/types.h>
  25. #include <linux/errno.h>
  26. #include <linux/list.h>
  27. #include <linux/wait.h>
  28. #include <linux/spinlock.h>
  29. #include <linux/slab.h>
  30. #include <linux/config.h>
  31. #include <linux/module.h>
  32. #include <linux/version.h>
  33. #include <linux/interrupt.h>
  34. #include <linux/device.h>
  35. /* Driver identification */
  36. #define DRIVER_NAME "ibmasm"
  37. #define DRIVER_VERSION "0.4"
  38. #define DRIVER_AUTHOR "Max Asbock"
  39. #define DRIVER_DESC "IBM ASM Service Processor Driver"
  40. #define err(msg) printk(KERN_ERR "%s: " msg "\n", DRIVER_NAME)
  41. #define info(msg) printk(KERN_INFO "%s: " msg "\n", DRIVER_NAME)
  42. #define IBMASM_CMD_PENDING 0
  43. #define IBMASM_CMD_COMPLETE 1
  44. #define IBMASM_CMD_FAILED 2
  45. #define IBMASM_CMD_TIMEOUT_NORMAL 45
  46. #define IBMASM_CMD_TIMEOUT_EXTRA 240
  47. #define IBMASM_CMD_MAX_BUFFER_SIZE 0x8000
  48. #define REVERSE_HEARTBEAT_TIMEOUT 120
  49. #define HEARTBEAT_BUFFER_SIZE 0x400
  50. #ifdef IA64
  51. #define IBMASM_DRIVER_VPD "Lin64 6.08 "
  52. #else
  53. #define IBMASM_DRIVER_VPD "Lin32 6.08 "
  54. #endif
  55. #define SYSTEM_STATE_OS_UP 5
  56. #define SYSTEM_STATE_OS_DOWN 4
  57. #define IBMASM_NAME_SIZE 16
  58. #define IBMASM_NUM_EVENTS 10
  59. #define IBMASM_EVENT_MAX_SIZE 2048u
  60. struct command {
  61. struct list_head queue_node;
  62. wait_queue_head_t wait;
  63. unsigned char *buffer;
  64. size_t buffer_size;
  65. int status;
  66. struct kobject kobj;
  67. };
  68. #define to_command(c) container_of(c, struct command, kobj)
  69. static inline void command_put(struct command *cmd)
  70. {
  71. kobject_put(&cmd->kobj);
  72. }
  73. static inline void command_get(struct command *cmd)
  74. {
  75. kobject_get(&cmd->kobj);
  76. }
  77. struct ibmasm_event {
  78. unsigned int serial_number;
  79. unsigned int data_size;
  80. unsigned char data[IBMASM_EVENT_MAX_SIZE];
  81. };
  82. struct event_buffer {
  83. struct ibmasm_event events[IBMASM_NUM_EVENTS];
  84. unsigned int next_serial_number;
  85. unsigned int next_index;
  86. struct list_head readers;
  87. };
  88. struct event_reader {
  89. int cancelled;
  90. unsigned int next_serial_number;
  91. wait_queue_head_t wait;
  92. struct list_head node;
  93. unsigned int data_size;
  94. unsigned char data[IBMASM_EVENT_MAX_SIZE];
  95. };
  96. struct reverse_heartbeat {
  97. wait_queue_head_t wait;
  98. unsigned int stopped;
  99. };
  100. /* remote console events */
  101. struct mouse_event {
  102. long x;
  103. long y;
  104. unsigned char buttons;
  105. unsigned char transitions;
  106. };
  107. struct keyboard_event {
  108. unsigned long key_code;
  109. unsigned char key_down;
  110. };
  111. struct remote_event {
  112. unsigned long type;
  113. union {
  114. struct mouse_event mouse;
  115. struct keyboard_event keyboard;
  116. } data;
  117. };
  118. #define DRIVER_REMOTE_QUEUE_SIZE 240
  119. struct remote_queue {
  120. struct remote_event *start;
  121. struct remote_event *end;
  122. struct remote_event *reader;
  123. struct remote_event *writer;
  124. unsigned int size;
  125. int open;
  126. wait_queue_head_t wait;
  127. };
  128. struct service_processor {
  129. struct list_head node;
  130. spinlock_t lock;
  131. void __iomem *base_address;
  132. unsigned int irq;
  133. struct command *current_command;
  134. struct command *heartbeat;
  135. struct list_head command_queue;
  136. struct event_buffer *event_buffer;
  137. char dirname[IBMASM_NAME_SIZE];
  138. char devname[IBMASM_NAME_SIZE];
  139. unsigned int number;
  140. struct remote_queue remote_queue;
  141. int serial_line;
  142. struct device *dev;
  143. };
  144. /* command processing */
  145. extern struct command *ibmasm_new_command(size_t buffer_size);
  146. extern void ibmasm_exec_command(struct service_processor *sp, struct command *cmd);
  147. extern void ibmasm_wait_for_response(struct command *cmd, int timeout);
  148. extern void ibmasm_receive_command_response(struct service_processor *sp, void *response, size_t size);
  149. /* event processing */
  150. extern int ibmasm_event_buffer_init(struct service_processor *sp);
  151. extern void ibmasm_event_buffer_exit(struct service_processor *sp);
  152. extern void ibmasm_receive_event(struct service_processor *sp, void *data, unsigned int data_size);
  153. extern void ibmasm_event_reader_register(struct service_processor *sp, struct event_reader *reader);
  154. extern void ibmasm_event_reader_unregister(struct service_processor *sp, struct event_reader *reader);
  155. extern int ibmasm_get_next_event(struct service_processor *sp, struct event_reader *reader);
  156. extern void ibmasm_cancel_next_event(struct event_reader *reader);
  157. /* heartbeat - from SP to OS */
  158. extern void ibmasm_register_panic_notifier(void);
  159. extern void ibmasm_unregister_panic_notifier(void);
  160. extern int ibmasm_heartbeat_init(struct service_processor *sp);
  161. extern void ibmasm_heartbeat_exit(struct service_processor *sp);
  162. extern void ibmasm_receive_heartbeat(struct service_processor *sp, void *message, size_t size);
  163. /* reverse heartbeat - from OS to SP */
  164. extern void ibmasm_init_reverse_heartbeat(struct service_processor *sp, struct reverse_heartbeat *rhb);
  165. extern int ibmasm_start_reverse_heartbeat(struct service_processor *sp, struct reverse_heartbeat *rhb);
  166. extern void ibmasm_stop_reverse_heartbeat(struct reverse_heartbeat *rhb);
  167. /* dot commands */
  168. extern void ibmasm_receive_message(struct service_processor *sp, void *data, int data_size);
  169. extern int ibmasm_send_driver_vpd(struct service_processor *sp);
  170. extern int ibmasm_send_os_state(struct service_processor *sp, int os_state);
  171. /* low level message processing */
  172. extern int ibmasm_send_i2o_message(struct service_processor *sp);
  173. extern irqreturn_t ibmasm_interrupt_handler(int irq, void * dev_id, struct pt_regs *regs);
  174. /* remote console */
  175. extern void ibmasm_handle_mouse_interrupt(struct service_processor *sp);
  176. extern int ibmasm_init_remote_queue(struct service_processor *sp);
  177. extern void ibmasm_free_remote_queue(struct service_processor *sp);
  178. extern void ibmasm_advance_reader(struct remote_queue *q, unsigned int n);
  179. extern size_t ibmasm_events_available(struct remote_queue *q);
  180. /* file system */
  181. extern int ibmasmfs_register(void);
  182. extern void ibmasmfs_unregister(void);
  183. extern void ibmasmfs_add_sp(struct service_processor *sp);
  184. /* uart */
  185. #ifdef CONFIG_SERIAL_8250
  186. extern void ibmasm_register_uart(struct service_processor *sp);
  187. extern void ibmasm_unregister_uart(struct service_processor *sp);
  188. #else
  189. #define ibmasm_register_uart(sp) do { } while(0)
  190. #define ibmasm_unregister_uart(sp) do { } while(0)
  191. #endif