ibmasm.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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/interrupt.h>
  33. #include <linux/device.h>
  34. #include <linux/input.h>
  35. /* Driver identification */
  36. #define DRIVER_NAME "ibmasm"
  37. #define DRIVER_VERSION "1.0"
  38. #define DRIVER_AUTHOR "Max Asbock <masbock@us.ibm.com>, Vernon Mauery <vernux@us.ibm.com>"
  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. extern int ibmasm_debug;
  43. #define dbg(STR, ARGS...) \
  44. do { \
  45. if (ibmasm_debug) \
  46. printk(KERN_DEBUG STR , ##ARGS); \
  47. } while (0)
  48. static inline char *get_timestamp(char *buf)
  49. {
  50. struct timeval now;
  51. do_gettimeofday(&now);
  52. sprintf(buf, "%lu.%lu", now.tv_sec, now.tv_usec);
  53. return buf;
  54. }
  55. #define IBMASM_CMD_PENDING 0
  56. #define IBMASM_CMD_COMPLETE 1
  57. #define IBMASM_CMD_FAILED 2
  58. #define IBMASM_CMD_TIMEOUT_NORMAL 45
  59. #define IBMASM_CMD_TIMEOUT_EXTRA 240
  60. #define IBMASM_CMD_MAX_BUFFER_SIZE 0x8000
  61. #define REVERSE_HEARTBEAT_TIMEOUT 120
  62. #define HEARTBEAT_BUFFER_SIZE 0x400
  63. #ifdef IA64
  64. #define IBMASM_DRIVER_VPD "Lin64 6.08 "
  65. #else
  66. #define IBMASM_DRIVER_VPD "Lin32 6.08 "
  67. #endif
  68. #define SYSTEM_STATE_OS_UP 5
  69. #define SYSTEM_STATE_OS_DOWN 4
  70. #define IBMASM_NAME_SIZE 16
  71. #define IBMASM_NUM_EVENTS 10
  72. #define IBMASM_EVENT_MAX_SIZE 2048u
  73. struct command {
  74. struct list_head queue_node;
  75. wait_queue_head_t wait;
  76. unsigned char *buffer;
  77. size_t buffer_size;
  78. int status;
  79. struct kobject kobj;
  80. spinlock_t *lock;
  81. };
  82. #define to_command(c) container_of(c, struct command, kobj)
  83. static inline void command_put(struct command *cmd)
  84. {
  85. unsigned long flags;
  86. spin_lock_irqsave(cmd->lock, flags);
  87. kobject_put(&cmd->kobj);
  88. spin_unlock_irqrestore(cmd->lock, flags);
  89. }
  90. static inline void command_get(struct command *cmd)
  91. {
  92. kobject_get(&cmd->kobj);
  93. }
  94. struct ibmasm_event {
  95. unsigned int serial_number;
  96. unsigned int data_size;
  97. unsigned char data[IBMASM_EVENT_MAX_SIZE];
  98. };
  99. struct event_buffer {
  100. struct ibmasm_event events[IBMASM_NUM_EVENTS];
  101. unsigned int next_serial_number;
  102. unsigned int next_index;
  103. struct list_head readers;
  104. };
  105. struct event_reader {
  106. int cancelled;
  107. unsigned int next_serial_number;
  108. wait_queue_head_t wait;
  109. struct list_head node;
  110. unsigned int data_size;
  111. unsigned char data[IBMASM_EVENT_MAX_SIZE];
  112. };
  113. struct reverse_heartbeat {
  114. wait_queue_head_t wait;
  115. unsigned int stopped;
  116. };
  117. struct ibmasm_remote {
  118. struct input_dev *keybd_dev;
  119. struct input_dev *mouse_dev;
  120. };
  121. struct service_processor {
  122. struct list_head node;
  123. spinlock_t lock;
  124. void __iomem *base_address;
  125. unsigned int irq;
  126. struct command *current_command;
  127. struct command *heartbeat;
  128. struct list_head command_queue;
  129. struct event_buffer *event_buffer;
  130. char dirname[IBMASM_NAME_SIZE];
  131. char devname[IBMASM_NAME_SIZE];
  132. unsigned int number;
  133. struct ibmasm_remote remote;
  134. int serial_line;
  135. struct device *dev;
  136. };
  137. /* command processing */
  138. extern struct command *ibmasm_new_command(struct service_processor *sp, size_t buffer_size);
  139. extern void ibmasm_exec_command(struct service_processor *sp, struct command *cmd);
  140. extern void ibmasm_wait_for_response(struct command *cmd, int timeout);
  141. extern void ibmasm_receive_command_response(struct service_processor *sp, void *response, size_t size);
  142. /* event processing */
  143. extern int ibmasm_event_buffer_init(struct service_processor *sp);
  144. extern void ibmasm_event_buffer_exit(struct service_processor *sp);
  145. extern void ibmasm_receive_event(struct service_processor *sp, void *data, unsigned int data_size);
  146. extern void ibmasm_event_reader_register(struct service_processor *sp, struct event_reader *reader);
  147. extern void ibmasm_event_reader_unregister(struct service_processor *sp, struct event_reader *reader);
  148. extern int ibmasm_get_next_event(struct service_processor *sp, struct event_reader *reader);
  149. extern void ibmasm_cancel_next_event(struct event_reader *reader);
  150. /* heartbeat - from SP to OS */
  151. extern void ibmasm_register_panic_notifier(void);
  152. extern void ibmasm_unregister_panic_notifier(void);
  153. extern int ibmasm_heartbeat_init(struct service_processor *sp);
  154. extern void ibmasm_heartbeat_exit(struct service_processor *sp);
  155. extern void ibmasm_receive_heartbeat(struct service_processor *sp, void *message, size_t size);
  156. /* reverse heartbeat - from OS to SP */
  157. extern void ibmasm_init_reverse_heartbeat(struct service_processor *sp, struct reverse_heartbeat *rhb);
  158. extern int ibmasm_start_reverse_heartbeat(struct service_processor *sp, struct reverse_heartbeat *rhb);
  159. extern void ibmasm_stop_reverse_heartbeat(struct reverse_heartbeat *rhb);
  160. /* dot commands */
  161. extern void ibmasm_receive_message(struct service_processor *sp, void *data, int data_size);
  162. extern int ibmasm_send_driver_vpd(struct service_processor *sp);
  163. extern int ibmasm_send_os_state(struct service_processor *sp, int os_state);
  164. /* low level message processing */
  165. extern int ibmasm_send_i2o_message(struct service_processor *sp);
  166. extern irqreturn_t ibmasm_interrupt_handler(int irq, void * dev_id, struct pt_regs *regs);
  167. /* remote console */
  168. extern void ibmasm_handle_mouse_interrupt(struct service_processor *sp, struct pt_regs *regs);
  169. extern int ibmasm_init_remote_input_dev(struct service_processor *sp);
  170. extern void ibmasm_free_remote_input_dev(struct service_processor *sp);
  171. /* file system */
  172. extern int ibmasmfs_register(void);
  173. extern void ibmasmfs_unregister(void);
  174. extern void ibmasmfs_add_sp(struct service_processor *sp);
  175. /* uart */
  176. #ifdef CONFIG_SERIAL_8250
  177. extern void ibmasm_register_uart(struct service_processor *sp);
  178. extern void ibmasm_unregister_uart(struct service_processor *sp);
  179. #else
  180. #define ibmasm_register_uart(sp) do { } while(0)
  181. #define ibmasm_unregister_uart(sp) do { } while(0)
  182. #endif