raw3270.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  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 IBM Corp. 2003, 2009
  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_RDBUF 0x02 /* Read Buffer */
  22. #define TC_EWRITE 0x05 /* Erase write */
  23. #define TC_READMOD 0x06 /* Read modified */
  24. #define TC_EWRITEA 0x0d /* Erase write alternate */
  25. #define TC_WRITESF 0x11 /* Write structured field */
  26. /* Buffer Control Orders */
  27. #define TO_SF 0x1d /* Start field */
  28. #define TO_SBA 0x11 /* Set buffer address */
  29. #define TO_IC 0x13 /* Insert cursor */
  30. #define TO_PT 0x05 /* Program tab */
  31. #define TO_RA 0x3c /* Repeat to address */
  32. #define TO_SFE 0x29 /* Start field extended */
  33. #define TO_EUA 0x12 /* Erase unprotected to address */
  34. #define TO_MF 0x2c /* Modify field */
  35. #define TO_SA 0x28 /* Set attribute */
  36. /* Field Attribute Bytes */
  37. #define TF_INPUT 0x40 /* Visible input */
  38. #define TF_INPUTN 0x4c /* Invisible input */
  39. #define TF_INMDT 0xc1 /* Visible, Set-MDT */
  40. #define TF_LOG 0x60
  41. /* Character Attribute Bytes */
  42. #define TAT_RESET 0x00
  43. #define TAT_FIELD 0xc0
  44. #define TAT_EXTHI 0x41
  45. #define TAT_COLOR 0x42
  46. #define TAT_CHARS 0x43
  47. #define TAT_TRANS 0x46
  48. /* Extended-Highlighting Bytes */
  49. #define TAX_RESET 0x00
  50. #define TAX_BLINK 0xf1
  51. #define TAX_REVER 0xf2
  52. #define TAX_UNDER 0xf4
  53. /* Reset value */
  54. #define TAR_RESET 0x00
  55. /* Color values */
  56. #define TAC_RESET 0x00
  57. #define TAC_BLUE 0xf1
  58. #define TAC_RED 0xf2
  59. #define TAC_PINK 0xf3
  60. #define TAC_GREEN 0xf4
  61. #define TAC_TURQ 0xf5
  62. #define TAC_YELLOW 0xf6
  63. #define TAC_WHITE 0xf7
  64. #define TAC_DEFAULT 0x00
  65. /* Write Control Characters */
  66. #define TW_NONE 0x40 /* No particular action */
  67. #define TW_KR 0xc2 /* Keyboard restore */
  68. #define TW_PLUSALARM 0x04 /* Add this bit for alarm */
  69. #define RAW3270_FIRSTMINOR 1 /* First minor number */
  70. #define RAW3270_MAXDEVS 255 /* Max number of 3270 devices */
  71. /* For TUBGETMOD and TUBSETMOD. Should include. */
  72. struct raw3270_iocb {
  73. short model;
  74. short line_cnt;
  75. short col_cnt;
  76. short pf_cnt;
  77. short re_cnt;
  78. short map;
  79. };
  80. struct raw3270;
  81. struct raw3270_view;
  82. extern struct class *class3270;
  83. /* 3270 CCW request */
  84. struct raw3270_request {
  85. struct list_head list; /* list head for request queueing. */
  86. struct raw3270_view *view; /* view of this request */
  87. struct ccw1 ccw; /* single ccw. */
  88. void *buffer; /* output buffer. */
  89. size_t size; /* size of output buffer. */
  90. int rescnt; /* residual count from devstat. */
  91. int rc; /* return code for this request. */
  92. /* Callback for delivering final status. */
  93. void (*callback)(struct raw3270_request *, void *);
  94. void *callback_data;
  95. };
  96. struct raw3270_request *raw3270_request_alloc(size_t size);
  97. struct raw3270_request *raw3270_request_alloc_bootmem(size_t size);
  98. void raw3270_request_free(struct raw3270_request *);
  99. void raw3270_request_reset(struct raw3270_request *);
  100. void raw3270_request_set_cmd(struct raw3270_request *, u8 cmd);
  101. int raw3270_request_add_data(struct raw3270_request *, void *, size_t);
  102. void raw3270_request_set_data(struct raw3270_request *, void *, size_t);
  103. void raw3270_request_set_idal(struct raw3270_request *, struct idal_buffer *);
  104. static inline int
  105. raw3270_request_final(struct raw3270_request *rq)
  106. {
  107. return list_empty(&rq->list);
  108. }
  109. void raw3270_buffer_address(struct raw3270 *, char *, unsigned short);
  110. /*
  111. * Functions of a 3270 view.
  112. */
  113. struct raw3270_fn {
  114. int (*activate)(struct raw3270_view *);
  115. void (*deactivate)(struct raw3270_view *);
  116. void (*intv)(struct raw3270_view *,
  117. struct raw3270_request *, struct irb *);
  118. void (*release)(struct raw3270_view *);
  119. void (*free)(struct raw3270_view *);
  120. void (*resize)(struct raw3270_view *, int, int, int);
  121. };
  122. /*
  123. * View structure chaining. The raw3270_view structure is meant to
  124. * be embedded at the start of the real view data structure, e.g.:
  125. * struct example {
  126. * struct raw3270_view view;
  127. * ...
  128. * };
  129. */
  130. struct raw3270_view {
  131. struct list_head list;
  132. spinlock_t lock;
  133. #define RAW3270_VIEW_LOCK_IRQ 0
  134. #define RAW3270_VIEW_LOCK_BH 1
  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, 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. int raw3270_view_active(struct raw3270_view *);
  153. /* Reference count inliner for view structures. */
  154. static inline void
  155. raw3270_get_view(struct raw3270_view *view)
  156. {
  157. atomic_inc(&view->ref_count);
  158. }
  159. extern wait_queue_head_t raw3270_wait_queue;
  160. static inline void
  161. raw3270_put_view(struct raw3270_view *view)
  162. {
  163. if (atomic_dec_return(&view->ref_count) == 0)
  164. wake_up(&raw3270_wait_queue);
  165. }
  166. struct raw3270 *raw3270_setup_console(void);
  167. void raw3270_wait_cons_dev(struct raw3270 *);
  168. /* Notifier for device addition/removal */
  169. struct raw3270_notifier {
  170. struct list_head list;
  171. void (*create)(int minor);
  172. void (*destroy)(int minor);
  173. };
  174. int raw3270_register_notifier(struct raw3270_notifier *);
  175. void raw3270_unregister_notifier(struct raw3270_notifier *);
  176. void raw3270_pm_unfreeze(struct raw3270_view *);
  177. /*
  178. * Little memory allocator for string objects.
  179. */
  180. struct string
  181. {
  182. struct list_head list;
  183. struct list_head update;
  184. unsigned long size;
  185. unsigned long len;
  186. char string[0];
  187. } __attribute__ ((aligned(8)));
  188. static inline struct string *
  189. alloc_string(struct list_head *free_list, unsigned long len)
  190. {
  191. struct string *cs, *tmp;
  192. unsigned long size;
  193. size = (len + 7L) & -8L;
  194. list_for_each_entry(cs, free_list, list) {
  195. if (cs->size < size)
  196. continue;
  197. if (cs->size > size + sizeof(struct string)) {
  198. char *endaddr = (char *) (cs + 1) + cs->size;
  199. tmp = (struct string *) (endaddr - size) - 1;
  200. tmp->size = size;
  201. cs->size -= size + sizeof(struct string);
  202. cs = tmp;
  203. } else
  204. list_del(&cs->list);
  205. cs->len = len;
  206. INIT_LIST_HEAD(&cs->list);
  207. INIT_LIST_HEAD(&cs->update);
  208. return cs;
  209. }
  210. return NULL;
  211. }
  212. static inline unsigned long
  213. free_string(struct list_head *free_list, struct string *cs)
  214. {
  215. struct string *tmp;
  216. struct list_head *p, *left;
  217. /* Find out the left neighbour in free memory list. */
  218. left = free_list;
  219. list_for_each(p, free_list) {
  220. if (list_entry(p, struct string, list) > cs)
  221. break;
  222. left = p;
  223. }
  224. /* Try to merge with right neighbour = next element from left. */
  225. if (left->next != free_list) {
  226. tmp = list_entry(left->next, struct string, list);
  227. if ((char *) (cs + 1) + cs->size == (char *) tmp) {
  228. list_del(&tmp->list);
  229. cs->size += tmp->size + sizeof(struct string);
  230. }
  231. }
  232. /* Try to merge with left neighbour. */
  233. if (left != free_list) {
  234. tmp = list_entry(left, struct string, list);
  235. if ((char *) (tmp + 1) + tmp->size == (char *) cs) {
  236. tmp->size += cs->size + sizeof(struct string);
  237. return tmp->size;
  238. }
  239. }
  240. __list_add(&cs->list, left, left->next);
  241. return cs->size;
  242. }
  243. static inline void
  244. add_string_memory(struct list_head *free_list, void *mem, unsigned long size)
  245. {
  246. struct string *cs;
  247. cs = (struct string *) mem;
  248. cs->size = size - sizeof(struct string);
  249. free_string(free_list, cs);
  250. }