raw3270.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. /*
  2. * drivers/s390/char/raw3270.h
  3. * IBM/3270 Driver
  4. *
  5. * Author(s):
  6. * Original 3270 Code for 2.4 written by Richard Hitt (UTS Global)
  7. * Rewritten for 2.5 by Martin Schwidefsky <schwidefsky@de.ibm.com>
  8. * -- Copyright (C) 2003 IBM Deutschland Entwicklung GmbH, IBM Corporation
  9. */
  10. #include <asm/idals.h>
  11. #include <asm/ioctl.h>
  12. /* ioctls for fullscreen 3270 */
  13. #define TUBICMD _IO('3', 3) /* set ccw command for fs reads. */
  14. #define TUBOCMD _IO('3', 4) /* set ccw command for fs writes. */
  15. #define TUBGETI _IO('3', 7) /* get ccw command for fs reads. */
  16. #define TUBGETO _IO('3', 8) /* get ccw command for fs writes. */
  17. #define TUBSETMOD _IO('3',12) /* FIXME: what does it do ?*/
  18. #define TUBGETMOD _IO('3',13) /* FIXME: what does it do ?*/
  19. /* Local Channel Commands */
  20. #define TC_WRITE 0x01 /* Write */
  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_MAXDEVS 256
  69. /* For TUBGETMOD and TUBSETMOD. Should include. */
  70. struct raw3270_iocb {
  71. short model;
  72. short line_cnt;
  73. short col_cnt;
  74. short pf_cnt;
  75. short re_cnt;
  76. short map;
  77. };
  78. struct raw3270;
  79. struct raw3270_view;
  80. /* 3270 CCW request */
  81. struct raw3270_request {
  82. struct list_head list; /* list head for request queueing. */
  83. struct raw3270_view *view; /* view of this request */
  84. struct ccw1 ccw; /* single ccw. */
  85. void *buffer; /* output buffer. */
  86. size_t size; /* size of output buffer. */
  87. int rescnt; /* residual count from devstat. */
  88. int rc; /* return code for this request. */
  89. /* Callback for delivering final status. */
  90. void (*callback)(struct raw3270_request *, void *);
  91. void *callback_data;
  92. };
  93. struct raw3270_request *raw3270_request_alloc(size_t size);
  94. struct raw3270_request *raw3270_request_alloc_bootmem(size_t size);
  95. void raw3270_request_free(struct raw3270_request *);
  96. void raw3270_request_reset(struct raw3270_request *);
  97. void raw3270_request_set_cmd(struct raw3270_request *, u8 cmd);
  98. int raw3270_request_add_data(struct raw3270_request *, void *, size_t);
  99. void raw3270_request_set_data(struct raw3270_request *, void *, size_t);
  100. void raw3270_request_set_idal(struct raw3270_request *, struct idal_buffer *);
  101. static inline int
  102. raw3270_request_final(struct raw3270_request *rq)
  103. {
  104. return list_empty(&rq->list);
  105. }
  106. void raw3270_buffer_address(struct raw3270 *, char *, unsigned short);
  107. /* Return value of *intv (see raw3270_fn below) can be one of the following: */
  108. #define RAW3270_IO_DONE 0 /* request finished */
  109. #define RAW3270_IO_BUSY 1 /* request still active */
  110. #define RAW3270_IO_RETRY 2 /* retry current request */
  111. #define RAW3270_IO_STOP 3 /* kill current request */
  112. /*
  113. * Functions of a 3270 view.
  114. */
  115. struct raw3270_fn {
  116. int (*activate)(struct raw3270_view *);
  117. void (*deactivate)(struct raw3270_view *);
  118. int (*intv)(struct raw3270_view *,
  119. struct raw3270_request *, struct irb *);
  120. void (*release)(struct raw3270_view *);
  121. void (*free)(struct raw3270_view *);
  122. };
  123. /*
  124. * View structure chaining. The raw3270_view structure is meant to
  125. * be embedded at the start of the real view data structure, e.g.:
  126. * struct example {
  127. * struct raw3270_view view;
  128. * ...
  129. * };
  130. */
  131. struct raw3270_view {
  132. struct list_head list;
  133. spinlock_t lock;
  134. atomic_t ref_count;
  135. struct raw3270 *dev;
  136. struct raw3270_fn *fn;
  137. unsigned int model;
  138. unsigned int rows, cols; /* # of rows & colums of the view */
  139. unsigned char *ascebc; /* ascii -> ebcdic table */
  140. };
  141. int raw3270_add_view(struct raw3270_view *, struct raw3270_fn *, int);
  142. int raw3270_activate_view(struct raw3270_view *);
  143. void raw3270_del_view(struct raw3270_view *);
  144. void raw3270_deactivate_view(struct raw3270_view *);
  145. struct raw3270_view *raw3270_find_view(struct raw3270_fn *, int);
  146. int raw3270_start(struct raw3270_view *, struct raw3270_request *);
  147. int raw3270_start_irq(struct raw3270_view *, struct raw3270_request *);
  148. /* Reference count inliner for view structures. */
  149. static inline void
  150. raw3270_get_view(struct raw3270_view *view)
  151. {
  152. atomic_inc(&view->ref_count);
  153. }
  154. extern wait_queue_head_t raw3270_wait_queue;
  155. static inline void
  156. raw3270_put_view(struct raw3270_view *view)
  157. {
  158. if (atomic_dec_return(&view->ref_count) == 0)
  159. wake_up(&raw3270_wait_queue);
  160. }
  161. struct raw3270 *raw3270_setup_console(struct ccw_device *cdev);
  162. void raw3270_wait_cons_dev(struct raw3270 *);
  163. /* Notifier for device addition/removal */
  164. int raw3270_register_notifier(void (*notifier)(int, int));
  165. void raw3270_unregister_notifier(void (*notifier)(int, int));
  166. /*
  167. * Little memory allocator for string objects.
  168. */
  169. struct string
  170. {
  171. struct list_head list;
  172. struct list_head update;
  173. unsigned long size;
  174. unsigned long len;
  175. char string[0];
  176. } __attribute__ ((aligned(8)));
  177. static inline struct string *
  178. alloc_string(struct list_head *free_list, unsigned long len)
  179. {
  180. struct string *cs, *tmp;
  181. unsigned long size;
  182. size = (len + 7L) & -8L;
  183. list_for_each_entry(cs, free_list, list) {
  184. if (cs->size < size)
  185. continue;
  186. if (cs->size > size + sizeof(struct string)) {
  187. char *endaddr = (char *) (cs + 1) + cs->size;
  188. tmp = (struct string *) (endaddr - size) - 1;
  189. tmp->size = size;
  190. cs->size -= size + sizeof(struct string);
  191. cs = tmp;
  192. } else
  193. list_del(&cs->list);
  194. cs->len = len;
  195. INIT_LIST_HEAD(&cs->list);
  196. INIT_LIST_HEAD(&cs->update);
  197. return cs;
  198. }
  199. return 0;
  200. }
  201. static inline unsigned long
  202. free_string(struct list_head *free_list, struct string *cs)
  203. {
  204. struct string *tmp;
  205. struct list_head *p, *left;
  206. /* Find out the left neighbour in free memory list. */
  207. left = free_list;
  208. list_for_each(p, free_list) {
  209. if (list_entry(p, struct string, list) > cs)
  210. break;
  211. left = p;
  212. }
  213. /* Try to merge with right neighbour = next element from left. */
  214. if (left->next != free_list) {
  215. tmp = list_entry(left->next, struct string, list);
  216. if ((char *) (cs + 1) + cs->size == (char *) tmp) {
  217. list_del(&tmp->list);
  218. cs->size += tmp->size + sizeof(struct string);
  219. }
  220. }
  221. /* Try to merge with left neighbour. */
  222. if (left != free_list) {
  223. tmp = list_entry(left, struct string, list);
  224. if ((char *) (tmp + 1) + tmp->size == (char *) cs) {
  225. tmp->size += cs->size + sizeof(struct string);
  226. return tmp->size;
  227. }
  228. }
  229. __list_add(&cs->list, left, left->next);
  230. return cs->size;
  231. }
  232. static inline void
  233. add_string_memory(struct list_head *free_list, void *mem, unsigned long size)
  234. {
  235. struct string *cs;
  236. cs = (struct string *) mem;
  237. cs->size = size - sizeof(struct string);
  238. free_string(free_list, cs);
  239. }