raw3270.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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. /*
  110. * Functions of a 3270 view.
  111. */
  112. struct raw3270_fn {
  113. int (*activate)(struct raw3270_view *);
  114. void (*deactivate)(struct raw3270_view *);
  115. void (*intv)(struct raw3270_view *,
  116. struct raw3270_request *, struct irb *);
  117. void (*release)(struct raw3270_view *);
  118. void (*free)(struct raw3270_view *);
  119. void (*resize)(struct raw3270_view *, int, int, int);
  120. };
  121. /*
  122. * View structure chaining. The raw3270_view structure is meant to
  123. * be embedded at the start of the real view data structure, e.g.:
  124. * struct example {
  125. * struct raw3270_view view;
  126. * ...
  127. * };
  128. */
  129. struct raw3270_view {
  130. struct list_head list;
  131. spinlock_t lock;
  132. atomic_t ref_count;
  133. struct raw3270 *dev;
  134. struct raw3270_fn *fn;
  135. unsigned int model;
  136. unsigned int rows, cols; /* # of rows & colums of the view */
  137. unsigned char *ascebc; /* ascii -> ebcdic table */
  138. };
  139. int raw3270_add_view(struct raw3270_view *, struct raw3270_fn *, int);
  140. int raw3270_activate_view(struct raw3270_view *);
  141. void raw3270_del_view(struct raw3270_view *);
  142. void raw3270_deactivate_view(struct raw3270_view *);
  143. struct raw3270_view *raw3270_find_view(struct raw3270_fn *, int);
  144. int raw3270_start(struct raw3270_view *, struct raw3270_request *);
  145. int raw3270_start_locked(struct raw3270_view *, struct raw3270_request *);
  146. int raw3270_start_irq(struct raw3270_view *, struct raw3270_request *);
  147. int raw3270_reset(struct raw3270_view *);
  148. struct raw3270_view *raw3270_view(struct raw3270_view *);
  149. int raw3270_view_active(struct raw3270_view *);
  150. /* Reference count inliner for view structures. */
  151. static inline void
  152. raw3270_get_view(struct raw3270_view *view)
  153. {
  154. atomic_inc(&view->ref_count);
  155. }
  156. extern wait_queue_head_t raw3270_wait_queue;
  157. static inline void
  158. raw3270_put_view(struct raw3270_view *view)
  159. {
  160. if (atomic_dec_return(&view->ref_count) == 0)
  161. wake_up(&raw3270_wait_queue);
  162. }
  163. struct raw3270 *raw3270_setup_console(void);
  164. void raw3270_wait_cons_dev(struct raw3270 *);
  165. /* Notifier for device addition/removal */
  166. struct raw3270_notifier {
  167. struct list_head list;
  168. void (*create)(int minor);
  169. void (*destroy)(int minor);
  170. };
  171. int raw3270_register_notifier(struct raw3270_notifier *);
  172. void raw3270_unregister_notifier(struct raw3270_notifier *);
  173. void raw3270_pm_unfreeze(struct raw3270_view *);
  174. /*
  175. * Little memory allocator for string objects.
  176. */
  177. struct string
  178. {
  179. struct list_head list;
  180. struct list_head update;
  181. unsigned long size;
  182. unsigned long len;
  183. char string[0];
  184. } __attribute__ ((aligned(8)));
  185. static inline struct string *
  186. alloc_string(struct list_head *free_list, unsigned long len)
  187. {
  188. struct string *cs, *tmp;
  189. unsigned long size;
  190. size = (len + 7L) & -8L;
  191. list_for_each_entry(cs, free_list, list) {
  192. if (cs->size < size)
  193. continue;
  194. if (cs->size > size + sizeof(struct string)) {
  195. char *endaddr = (char *) (cs + 1) + cs->size;
  196. tmp = (struct string *) (endaddr - size) - 1;
  197. tmp->size = size;
  198. cs->size -= size + sizeof(struct string);
  199. cs = tmp;
  200. } else
  201. list_del(&cs->list);
  202. cs->len = len;
  203. INIT_LIST_HEAD(&cs->list);
  204. INIT_LIST_HEAD(&cs->update);
  205. return cs;
  206. }
  207. return NULL;
  208. }
  209. static inline unsigned long
  210. free_string(struct list_head *free_list, struct string *cs)
  211. {
  212. struct string *tmp;
  213. struct list_head *p, *left;
  214. /* Find out the left neighbour in free memory list. */
  215. left = free_list;
  216. list_for_each(p, free_list) {
  217. if (list_entry(p, struct string, list) > cs)
  218. break;
  219. left = p;
  220. }
  221. /* Try to merge with right neighbour = next element from left. */
  222. if (left->next != free_list) {
  223. tmp = list_entry(left->next, struct string, list);
  224. if ((char *) (cs + 1) + cs->size == (char *) tmp) {
  225. list_del(&tmp->list);
  226. cs->size += tmp->size + sizeof(struct string);
  227. }
  228. }
  229. /* Try to merge with left neighbour. */
  230. if (left != free_list) {
  231. tmp = list_entry(left, struct string, list);
  232. if ((char *) (tmp + 1) + tmp->size == (char *) cs) {
  233. tmp->size += cs->size + sizeof(struct string);
  234. return tmp->size;
  235. }
  236. }
  237. __list_add(&cs->list, left, left->next);
  238. return cs->size;
  239. }
  240. static inline void
  241. add_string_memory(struct list_head *free_list, void *mem, unsigned long size)
  242. {
  243. struct string *cs;
  244. cs = (struct string *) mem;
  245. cs->size = size - sizeof(struct string);
  246. free_string(free_list, cs);
  247. }