raw3270.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. /*
  2. * IBM/3270 Driver
  3. *
  4. * Author(s):
  5. * Original 3270 Code for 2.4 written by Richard Hitt (UTS Global)
  6. * Rewritten for 2.5 by Martin Schwidefsky <schwidefsky@de.ibm.com>
  7. * Copyright IBM Corp. 2003, 2009
  8. */
  9. #include <asm/idals.h>
  10. #include <asm/ioctl.h>
  11. /* ioctls for fullscreen 3270 */
  12. #define TUBICMD _IO('3', 3) /* set ccw command for fs reads. */
  13. #define TUBOCMD _IO('3', 4) /* set ccw command for fs writes. */
  14. #define TUBGETI _IO('3', 7) /* get ccw command for fs reads. */
  15. #define TUBGETO _IO('3', 8) /* get ccw command for fs writes. */
  16. #define TUBSETMOD _IO('3',12) /* FIXME: what does it do ?*/
  17. #define TUBGETMOD _IO('3',13) /* FIXME: what does it do ?*/
  18. /* Local Channel Commands */
  19. #define TC_WRITE 0x01 /* Write */
  20. #define TC_RDBUF 0x02 /* Read Buffer */
  21. #define TC_EWRITE 0x05 /* Erase write */
  22. #define TC_READMOD 0x06 /* Read modified */
  23. #define TC_EWRITEA 0x0d /* Erase write alternate */
  24. #define TC_WRITESF 0x11 /* Write structured field */
  25. /* Buffer Control Orders */
  26. #define TO_SF 0x1d /* Start field */
  27. #define TO_SBA 0x11 /* Set buffer address */
  28. #define TO_IC 0x13 /* Insert cursor */
  29. #define TO_PT 0x05 /* Program tab */
  30. #define TO_RA 0x3c /* Repeat to address */
  31. #define TO_SFE 0x29 /* Start field extended */
  32. #define TO_EUA 0x12 /* Erase unprotected to address */
  33. #define TO_MF 0x2c /* Modify field */
  34. #define TO_SA 0x28 /* Set attribute */
  35. /* Field Attribute Bytes */
  36. #define TF_INPUT 0x40 /* Visible input */
  37. #define TF_INPUTN 0x4c /* Invisible input */
  38. #define TF_INMDT 0xc1 /* Visible, Set-MDT */
  39. #define TF_LOG 0x60
  40. /* Character Attribute Bytes */
  41. #define TAT_RESET 0x00
  42. #define TAT_FIELD 0xc0
  43. #define TAT_EXTHI 0x41
  44. #define TAT_COLOR 0x42
  45. #define TAT_CHARS 0x43
  46. #define TAT_TRANS 0x46
  47. /* Extended-Highlighting Bytes */
  48. #define TAX_RESET 0x00
  49. #define TAX_BLINK 0xf1
  50. #define TAX_REVER 0xf2
  51. #define TAX_UNDER 0xf4
  52. /* Reset value */
  53. #define TAR_RESET 0x00
  54. /* Color values */
  55. #define TAC_RESET 0x00
  56. #define TAC_BLUE 0xf1
  57. #define TAC_RED 0xf2
  58. #define TAC_PINK 0xf3
  59. #define TAC_GREEN 0xf4
  60. #define TAC_TURQ 0xf5
  61. #define TAC_YELLOW 0xf6
  62. #define TAC_WHITE 0xf7
  63. #define TAC_DEFAULT 0x00
  64. /* Write Control Characters */
  65. #define TW_NONE 0x40 /* No particular action */
  66. #define TW_KR 0xc2 /* Keyboard restore */
  67. #define TW_PLUSALARM 0x04 /* Add this bit for alarm */
  68. #define RAW3270_FIRSTMINOR 1 /* First minor number */
  69. #define RAW3270_MAXDEVS 255 /* Max number of 3270 devices */
  70. /* For TUBGETMOD and TUBSETMOD. Should include. */
  71. struct raw3270_iocb {
  72. short model;
  73. short line_cnt;
  74. short col_cnt;
  75. short pf_cnt;
  76. short re_cnt;
  77. short map;
  78. };
  79. struct raw3270;
  80. struct raw3270_view;
  81. extern struct class *class3270;
  82. /* 3270 CCW request */
  83. struct raw3270_request {
  84. struct list_head list; /* list head for request queueing. */
  85. struct raw3270_view *view; /* view of this request */
  86. struct ccw1 ccw; /* single ccw. */
  87. void *buffer; /* output buffer. */
  88. size_t size; /* size of output buffer. */
  89. int rescnt; /* residual count from devstat. */
  90. int rc; /* return code for this request. */
  91. /* Callback for delivering final status. */
  92. void (*callback)(struct raw3270_request *, void *);
  93. void *callback_data;
  94. };
  95. struct raw3270_request *raw3270_request_alloc(size_t size);
  96. struct raw3270_request *raw3270_request_alloc_bootmem(size_t size);
  97. void raw3270_request_free(struct raw3270_request *);
  98. void raw3270_request_reset(struct raw3270_request *);
  99. void raw3270_request_set_cmd(struct raw3270_request *, u8 cmd);
  100. int raw3270_request_add_data(struct raw3270_request *, void *, size_t);
  101. void raw3270_request_set_data(struct raw3270_request *, void *, size_t);
  102. void raw3270_request_set_idal(struct raw3270_request *, struct idal_buffer *);
  103. static inline int
  104. raw3270_request_final(struct raw3270_request *rq)
  105. {
  106. return list_empty(&rq->list);
  107. }
  108. void raw3270_buffer_address(struct raw3270 *, char *, unsigned short);
  109. /* Return value of *intv (see raw3270_fn below) can be one of the following: */
  110. #define RAW3270_IO_DONE 0 /* request finished */
  111. #define RAW3270_IO_BUSY 1 /* request still active */
  112. #define RAW3270_IO_RETRY 2 /* retry current request */
  113. #define RAW3270_IO_STOP 3 /* kill current request */
  114. /*
  115. * Functions of a 3270 view.
  116. */
  117. struct raw3270_fn {
  118. int (*activate)(struct raw3270_view *);
  119. void (*deactivate)(struct raw3270_view *);
  120. int (*intv)(struct raw3270_view *,
  121. struct raw3270_request *, struct irb *);
  122. void (*release)(struct raw3270_view *);
  123. void (*free)(struct raw3270_view *);
  124. void (*resize)(struct raw3270_view *, int, int, int);
  125. };
  126. /*
  127. * View structure chaining. The raw3270_view structure is meant to
  128. * be embedded at the start of the real view data structure, e.g.:
  129. * struct example {
  130. * struct raw3270_view view;
  131. * ...
  132. * };
  133. */
  134. struct raw3270_view {
  135. struct list_head list;
  136. spinlock_t lock;
  137. atomic_t ref_count;
  138. struct raw3270 *dev;
  139. struct raw3270_fn *fn;
  140. unsigned int model;
  141. unsigned int rows, cols; /* # of rows & colums of the view */
  142. unsigned char *ascebc; /* ascii -> ebcdic table */
  143. };
  144. int raw3270_add_view(struct raw3270_view *, struct raw3270_fn *, int);
  145. int raw3270_activate_view(struct raw3270_view *);
  146. void raw3270_del_view(struct raw3270_view *);
  147. void raw3270_deactivate_view(struct raw3270_view *);
  148. struct raw3270_view *raw3270_find_view(struct raw3270_fn *, int);
  149. int raw3270_start(struct raw3270_view *, struct raw3270_request *);
  150. int raw3270_start_locked(struct raw3270_view *, struct raw3270_request *);
  151. int raw3270_start_irq(struct raw3270_view *, struct raw3270_request *);
  152. int raw3270_reset(struct raw3270_view *);
  153. struct raw3270_view *raw3270_view(struct raw3270_view *);
  154. int raw3270_view_active(struct raw3270_view *);
  155. /* Reference count inliner for view structures. */
  156. static inline void
  157. raw3270_get_view(struct raw3270_view *view)
  158. {
  159. atomic_inc(&view->ref_count);
  160. }
  161. extern wait_queue_head_t raw3270_wait_queue;
  162. static inline void
  163. raw3270_put_view(struct raw3270_view *view)
  164. {
  165. if (atomic_dec_return(&view->ref_count) == 0)
  166. wake_up(&raw3270_wait_queue);
  167. }
  168. struct raw3270 *raw3270_setup_console(void);
  169. void raw3270_wait_cons_dev(struct raw3270 *);
  170. /* Notifier for device addition/removal */
  171. struct raw3270_notifier {
  172. struct list_head list;
  173. void (*create)(int minor);
  174. void (*destroy)(int minor);
  175. };
  176. int raw3270_register_notifier(struct raw3270_notifier *);
  177. void raw3270_unregister_notifier(struct raw3270_notifier *);
  178. void raw3270_pm_unfreeze(struct raw3270_view *);
  179. /*
  180. * Little memory allocator for string objects.
  181. */
  182. struct string
  183. {
  184. struct list_head list;
  185. struct list_head update;
  186. unsigned long size;
  187. unsigned long len;
  188. char string[0];
  189. } __attribute__ ((aligned(8)));
  190. static inline struct string *
  191. alloc_string(struct list_head *free_list, unsigned long len)
  192. {
  193. struct string *cs, *tmp;
  194. unsigned long size;
  195. size = (len + 7L) & -8L;
  196. list_for_each_entry(cs, free_list, list) {
  197. if (cs->size < size)
  198. continue;
  199. if (cs->size > size + sizeof(struct string)) {
  200. char *endaddr = (char *) (cs + 1) + cs->size;
  201. tmp = (struct string *) (endaddr - size) - 1;
  202. tmp->size = size;
  203. cs->size -= size + sizeof(struct string);
  204. cs = tmp;
  205. } else
  206. list_del(&cs->list);
  207. cs->len = len;
  208. INIT_LIST_HEAD(&cs->list);
  209. INIT_LIST_HEAD(&cs->update);
  210. return cs;
  211. }
  212. return NULL;
  213. }
  214. static inline unsigned long
  215. free_string(struct list_head *free_list, struct string *cs)
  216. {
  217. struct string *tmp;
  218. struct list_head *p, *left;
  219. /* Find out the left neighbour in free memory list. */
  220. left = free_list;
  221. list_for_each(p, free_list) {
  222. if (list_entry(p, struct string, list) > cs)
  223. break;
  224. left = p;
  225. }
  226. /* Try to merge with right neighbour = next element from left. */
  227. if (left->next != free_list) {
  228. tmp = list_entry(left->next, struct string, list);
  229. if ((char *) (cs + 1) + cs->size == (char *) tmp) {
  230. list_del(&tmp->list);
  231. cs->size += tmp->size + sizeof(struct string);
  232. }
  233. }
  234. /* Try to merge with left neighbour. */
  235. if (left != free_list) {
  236. tmp = list_entry(left, struct string, list);
  237. if ((char *) (tmp + 1) + tmp->size == (char *) cs) {
  238. tmp->size += cs->size + sizeof(struct string);
  239. return tmp->size;
  240. }
  241. }
  242. __list_add(&cs->list, left, left->next);
  243. return cs->size;
  244. }
  245. static inline void
  246. add_string_memory(struct list_head *free_list, void *mem, unsigned long size)
  247. {
  248. struct string *cs;
  249. cs = (struct string *) mem;
  250. cs->size = size - sizeof(struct string);
  251. free_string(free_list, cs);
  252. }