raw3270.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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. /* 3270 CCW request */
  82. struct raw3270_request {
  83. struct list_head list; /* list head for request queueing. */
  84. struct raw3270_view *view; /* view of this request */
  85. struct ccw1 ccw; /* single ccw. */
  86. void *buffer; /* output buffer. */
  87. size_t size; /* size of output buffer. */
  88. int rescnt; /* residual count from devstat. */
  89. int rc; /* return code for this request. */
  90. /* Callback for delivering final status. */
  91. void (*callback)(struct raw3270_request *, void *);
  92. void *callback_data;
  93. };
  94. struct raw3270_request *raw3270_request_alloc(size_t size);
  95. struct raw3270_request *raw3270_request_alloc_bootmem(size_t size);
  96. void raw3270_request_free(struct raw3270_request *);
  97. void raw3270_request_reset(struct raw3270_request *);
  98. void raw3270_request_set_cmd(struct raw3270_request *, u8 cmd);
  99. int raw3270_request_add_data(struct raw3270_request *, void *, size_t);
  100. void raw3270_request_set_data(struct raw3270_request *, void *, size_t);
  101. void raw3270_request_set_idal(struct raw3270_request *, struct idal_buffer *);
  102. static inline int
  103. raw3270_request_final(struct raw3270_request *rq)
  104. {
  105. return list_empty(&rq->list);
  106. }
  107. void raw3270_buffer_address(struct raw3270 *, char *, unsigned short);
  108. /* Return value of *intv (see raw3270_fn below) can be one of the following: */
  109. #define RAW3270_IO_DONE 0 /* request finished */
  110. #define RAW3270_IO_BUSY 1 /* request still active */
  111. #define RAW3270_IO_RETRY 2 /* retry current request */
  112. #define RAW3270_IO_STOP 3 /* kill current request */
  113. /*
  114. * Functions of a 3270 view.
  115. */
  116. struct raw3270_fn {
  117. int (*activate)(struct raw3270_view *);
  118. void (*deactivate)(struct raw3270_view *);
  119. int (*intv)(struct raw3270_view *,
  120. struct raw3270_request *, struct irb *);
  121. void (*release)(struct raw3270_view *);
  122. void (*free)(struct raw3270_view *);
  123. };
  124. /*
  125. * View structure chaining. The raw3270_view structure is meant to
  126. * be embedded at the start of the real view data structure, e.g.:
  127. * struct example {
  128. * struct raw3270_view view;
  129. * ...
  130. * };
  131. */
  132. struct raw3270_view {
  133. struct list_head list;
  134. spinlock_t lock;
  135. atomic_t ref_count;
  136. struct raw3270 *dev;
  137. struct raw3270_fn *fn;
  138. unsigned int model;
  139. unsigned int rows, cols; /* # of rows & colums of the view */
  140. unsigned char *ascebc; /* ascii -> ebcdic table */
  141. };
  142. int raw3270_add_view(struct raw3270_view *, struct raw3270_fn *, int);
  143. int raw3270_activate_view(struct raw3270_view *);
  144. void raw3270_del_view(struct raw3270_view *);
  145. void raw3270_deactivate_view(struct raw3270_view *);
  146. struct raw3270_view *raw3270_find_view(struct raw3270_fn *, int);
  147. int raw3270_start(struct raw3270_view *, struct raw3270_request *);
  148. int raw3270_start_locked(struct raw3270_view *, struct raw3270_request *);
  149. int raw3270_start_irq(struct raw3270_view *, struct raw3270_request *);
  150. int raw3270_reset(struct raw3270_view *);
  151. struct raw3270_view *raw3270_view(struct raw3270_view *);
  152. /* Reference count inliner for view structures. */
  153. static inline void
  154. raw3270_get_view(struct raw3270_view *view)
  155. {
  156. atomic_inc(&view->ref_count);
  157. }
  158. extern wait_queue_head_t raw3270_wait_queue;
  159. static inline void
  160. raw3270_put_view(struct raw3270_view *view)
  161. {
  162. if (atomic_dec_return(&view->ref_count) == 0)
  163. wake_up(&raw3270_wait_queue);
  164. }
  165. struct raw3270 *raw3270_setup_console(struct ccw_device *cdev);
  166. void raw3270_wait_cons_dev(struct raw3270 *);
  167. /* Notifier for device addition/removal */
  168. int raw3270_register_notifier(void (*notifier)(int, int));
  169. void raw3270_unregister_notifier(void (*notifier)(int, int));
  170. void raw3270_pm_unfreeze(struct raw3270_view *);
  171. /*
  172. * Little memory allocator for string objects.
  173. */
  174. struct string
  175. {
  176. struct list_head list;
  177. struct list_head update;
  178. unsigned long size;
  179. unsigned long len;
  180. char string[0];
  181. } __attribute__ ((aligned(8)));
  182. static inline struct string *
  183. alloc_string(struct list_head *free_list, unsigned long len)
  184. {
  185. struct string *cs, *tmp;
  186. unsigned long size;
  187. size = (len + 7L) & -8L;
  188. list_for_each_entry(cs, free_list, list) {
  189. if (cs->size < size)
  190. continue;
  191. if (cs->size > size + sizeof(struct string)) {
  192. char *endaddr = (char *) (cs + 1) + cs->size;
  193. tmp = (struct string *) (endaddr - size) - 1;
  194. tmp->size = size;
  195. cs->size -= size + sizeof(struct string);
  196. cs = tmp;
  197. } else
  198. list_del(&cs->list);
  199. cs->len = len;
  200. INIT_LIST_HEAD(&cs->list);
  201. INIT_LIST_HEAD(&cs->update);
  202. return cs;
  203. }
  204. return NULL;
  205. }
  206. static inline unsigned long
  207. free_string(struct list_head *free_list, struct string *cs)
  208. {
  209. struct string *tmp;
  210. struct list_head *p, *left;
  211. /* Find out the left neighbour in free memory list. */
  212. left = free_list;
  213. list_for_each(p, free_list) {
  214. if (list_entry(p, struct string, list) > cs)
  215. break;
  216. left = p;
  217. }
  218. /* Try to merge with right neighbour = next element from left. */
  219. if (left->next != free_list) {
  220. tmp = list_entry(left->next, struct string, list);
  221. if ((char *) (cs + 1) + cs->size == (char *) tmp) {
  222. list_del(&tmp->list);
  223. cs->size += tmp->size + sizeof(struct string);
  224. }
  225. }
  226. /* Try to merge with left neighbour. */
  227. if (left != free_list) {
  228. tmp = list_entry(left, struct string, list);
  229. if ((char *) (tmp + 1) + tmp->size == (char *) cs) {
  230. tmp->size += cs->size + sizeof(struct string);
  231. return tmp->size;
  232. }
  233. }
  234. __list_add(&cs->list, left, left->next);
  235. return cs->size;
  236. }
  237. static inline void
  238. add_string_memory(struct list_head *free_list, void *mem, unsigned long size)
  239. {
  240. struct string *cs;
  241. cs = (struct string *) mem;
  242. cs->size = size - sizeof(struct string);
  243. free_string(free_list, cs);
  244. }