blob: 56519cbb165c7db9da236b4246a4fba011d8df4b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Martin Schwidefsky4b214a02009-06-16 10:30:47 +02002 * IBM/3270 Driver
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
Martin Schwidefsky4b214a02009-06-16 10:30:47 +02004 * 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
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 */
9
10#include <asm/idals.h>
11#include <asm/ioctl.h>
12
13/* ioctls for fullscreen 3270 */
14#define TUBICMD _IO('3', 3) /* set ccw command for fs reads. */
15#define TUBOCMD _IO('3', 4) /* set ccw command for fs writes. */
16#define TUBGETI _IO('3', 7) /* get ccw command for fs reads. */
17#define TUBGETO _IO('3', 8) /* get ccw command for fs writes. */
18#define TUBSETMOD _IO('3',12) /* FIXME: what does it do ?*/
19#define TUBGETMOD _IO('3',13) /* FIXME: what does it do ?*/
20
21/* Local Channel Commands */
22#define TC_WRITE 0x01 /* Write */
Richard Hitted3cb6f2005-10-30 15:00:10 -080023#define TC_RDBUF 0x02 /* Read Buffer */
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#define TC_EWRITE 0x05 /* Erase write */
25#define TC_READMOD 0x06 /* Read modified */
26#define TC_EWRITEA 0x0d /* Erase write alternate */
27#define TC_WRITESF 0x11 /* Write structured field */
28
29/* Buffer Control Orders */
30#define TO_SF 0x1d /* Start field */
31#define TO_SBA 0x11 /* Set buffer address */
32#define TO_IC 0x13 /* Insert cursor */
33#define TO_PT 0x05 /* Program tab */
34#define TO_RA 0x3c /* Repeat to address */
35#define TO_SFE 0x29 /* Start field extended */
36#define TO_EUA 0x12 /* Erase unprotected to address */
37#define TO_MF 0x2c /* Modify field */
38#define TO_SA 0x28 /* Set attribute */
39
40/* Field Attribute Bytes */
41#define TF_INPUT 0x40 /* Visible input */
42#define TF_INPUTN 0x4c /* Invisible input */
43#define TF_INMDT 0xc1 /* Visible, Set-MDT */
44#define TF_LOG 0x60
45
46/* Character Attribute Bytes */
47#define TAT_RESET 0x00
48#define TAT_FIELD 0xc0
49#define TAT_EXTHI 0x41
50#define TAT_COLOR 0x42
51#define TAT_CHARS 0x43
52#define TAT_TRANS 0x46
53
54/* Extended-Highlighting Bytes */
55#define TAX_RESET 0x00
56#define TAX_BLINK 0xf1
57#define TAX_REVER 0xf2
58#define TAX_UNDER 0xf4
59
60/* Reset value */
61#define TAR_RESET 0x00
62
63/* Color values */
64#define TAC_RESET 0x00
65#define TAC_BLUE 0xf1
66#define TAC_RED 0xf2
67#define TAC_PINK 0xf3
68#define TAC_GREEN 0xf4
69#define TAC_TURQ 0xf5
70#define TAC_YELLOW 0xf6
71#define TAC_WHITE 0xf7
72#define TAC_DEFAULT 0x00
73
74/* Write Control Characters */
75#define TW_NONE 0x40 /* No particular action */
76#define TW_KR 0xc2 /* Keyboard restore */
77#define TW_PLUSALARM 0x04 /* Add this bit for alarm */
78
Richard Hitted3cb6f2005-10-30 15:00:10 -080079#define RAW3270_FIRSTMINOR 1 /* First minor number */
80#define RAW3270_MAXDEVS 255 /* Max number of 3270 devices */
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
82/* For TUBGETMOD and TUBSETMOD. Should include. */
83struct raw3270_iocb {
84 short model;
85 short line_cnt;
86 short col_cnt;
87 short pf_cnt;
88 short re_cnt;
89 short map;
90};
91
92struct raw3270;
93struct raw3270_view;
Martin Schwidefskyc95571e2013-01-08 15:31:11 +010094extern struct class *class3270;
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
96/* 3270 CCW request */
97struct raw3270_request {
98 struct list_head list; /* list head for request queueing. */
99 struct raw3270_view *view; /* view of this request */
100 struct ccw1 ccw; /* single ccw. */
101 void *buffer; /* output buffer. */
102 size_t size; /* size of output buffer. */
103 int rescnt; /* residual count from devstat. */
104 int rc; /* return code for this request. */
105
106 /* Callback for delivering final status. */
107 void (*callback)(struct raw3270_request *, void *);
108 void *callback_data;
109};
110
111struct raw3270_request *raw3270_request_alloc(size_t size);
112struct raw3270_request *raw3270_request_alloc_bootmem(size_t size);
113void raw3270_request_free(struct raw3270_request *);
114void raw3270_request_reset(struct raw3270_request *);
115void raw3270_request_set_cmd(struct raw3270_request *, u8 cmd);
116int raw3270_request_add_data(struct raw3270_request *, void *, size_t);
117void raw3270_request_set_data(struct raw3270_request *, void *, size_t);
118void raw3270_request_set_idal(struct raw3270_request *, struct idal_buffer *);
119
120static inline int
121raw3270_request_final(struct raw3270_request *rq)
122{
123 return list_empty(&rq->list);
124}
125
126void raw3270_buffer_address(struct raw3270 *, char *, unsigned short);
127
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128/*
129 * Functions of a 3270 view.
130 */
131struct raw3270_fn {
132 int (*activate)(struct raw3270_view *);
133 void (*deactivate)(struct raw3270_view *);
Martin Schwidefsky8340ab62016-05-02 14:53:29 +0200134 void (*intv)(struct raw3270_view *,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 struct raw3270_request *, struct irb *);
136 void (*release)(struct raw3270_view *);
137 void (*free)(struct raw3270_view *);
Martin Schwidefsky4d334fd2013-01-04 14:55:13 +0100138 void (*resize)(struct raw3270_view *, int, int, int);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139};
140
141/*
142 * View structure chaining. The raw3270_view structure is meant to
143 * be embedded at the start of the real view data structure, e.g.:
144 * struct example {
145 * struct raw3270_view view;
146 * ...
147 * };
148 */
149struct raw3270_view {
150 struct list_head list;
151 spinlock_t lock;
152 atomic_t ref_count;
153 struct raw3270 *dev;
154 struct raw3270_fn *fn;
155 unsigned int model;
156 unsigned int rows, cols; /* # of rows & colums of the view */
157 unsigned char *ascebc; /* ascii -> ebcdic table */
158};
159
160int raw3270_add_view(struct raw3270_view *, struct raw3270_fn *, int);
161int raw3270_activate_view(struct raw3270_view *);
162void raw3270_del_view(struct raw3270_view *);
163void raw3270_deactivate_view(struct raw3270_view *);
164struct raw3270_view *raw3270_find_view(struct raw3270_fn *, int);
165int raw3270_start(struct raw3270_view *, struct raw3270_request *);
Richard Hitted3cb6f2005-10-30 15:00:10 -0800166int raw3270_start_locked(struct raw3270_view *, struct raw3270_request *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167int raw3270_start_irq(struct raw3270_view *, struct raw3270_request *);
Richard Hitted3cb6f2005-10-30 15:00:10 -0800168int raw3270_reset(struct raw3270_view *);
169struct raw3270_view *raw3270_view(struct raw3270_view *);
Martin Schwidefsky233faec2014-03-21 09:25:24 +0100170int raw3270_view_active(struct raw3270_view *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
172/* Reference count inliner for view structures. */
173static inline void
174raw3270_get_view(struct raw3270_view *view)
175{
176 atomic_inc(&view->ref_count);
177}
178
179extern wait_queue_head_t raw3270_wait_queue;
180
181static inline void
182raw3270_put_view(struct raw3270_view *view)
183{
184 if (atomic_dec_return(&view->ref_count) == 0)
185 wake_up(&raw3270_wait_queue);
186}
187
Sebastian Ott2253e8d2014-01-27 13:26:10 +0100188struct raw3270 *raw3270_setup_console(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189void raw3270_wait_cons_dev(struct raw3270 *);
190
191/* Notifier for device addition/removal */
Martin Schwidefskyc95571e2013-01-08 15:31:11 +0100192struct raw3270_notifier {
193 struct list_head list;
194 void (*create)(int minor);
195 void (*destroy)(int minor);
196};
197
198int raw3270_register_notifier(struct raw3270_notifier *);
199void raw3270_unregister_notifier(struct raw3270_notifier *);
Martin Schwidefsky4b214a02009-06-16 10:30:47 +0200200void raw3270_pm_unfreeze(struct raw3270_view *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
202/*
203 * Little memory allocator for string objects.
204 */
205struct string
206{
207 struct list_head list;
208 struct list_head update;
209 unsigned long size;
210 unsigned long len;
211 char string[0];
212} __attribute__ ((aligned(8)));
213
214static inline struct string *
215alloc_string(struct list_head *free_list, unsigned long len)
216{
217 struct string *cs, *tmp;
218 unsigned long size;
219
220 size = (len + 7L) & -8L;
221 list_for_each_entry(cs, free_list, list) {
222 if (cs->size < size)
223 continue;
224 if (cs->size > size + sizeof(struct string)) {
225 char *endaddr = (char *) (cs + 1) + cs->size;
226 tmp = (struct string *) (endaddr - size) - 1;
227 tmp->size = size;
228 cs->size -= size + sizeof(struct string);
229 cs = tmp;
230 } else
231 list_del(&cs->list);
232 cs->len = len;
233 INIT_LIST_HEAD(&cs->list);
234 INIT_LIST_HEAD(&cs->update);
235 return cs;
236 }
Heiko Carstensd2c993d2006-07-12 16:41:55 +0200237 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238}
239
240static inline unsigned long
241free_string(struct list_head *free_list, struct string *cs)
242{
243 struct string *tmp;
244 struct list_head *p, *left;
245
246 /* Find out the left neighbour in free memory list. */
247 left = free_list;
248 list_for_each(p, free_list) {
249 if (list_entry(p, struct string, list) > cs)
250 break;
251 left = p;
252 }
253 /* Try to merge with right neighbour = next element from left. */
254 if (left->next != free_list) {
255 tmp = list_entry(left->next, struct string, list);
256 if ((char *) (cs + 1) + cs->size == (char *) tmp) {
257 list_del(&tmp->list);
258 cs->size += tmp->size + sizeof(struct string);
259 }
260 }
261 /* Try to merge with left neighbour. */
262 if (left != free_list) {
263 tmp = list_entry(left, struct string, list);
264 if ((char *) (tmp + 1) + tmp->size == (char *) cs) {
265 tmp->size += cs->size + sizeof(struct string);
266 return tmp->size;
267 }
268 }
269 __list_add(&cs->list, left, left->next);
270 return cs->size;
271}
272
273static inline void
274add_string_memory(struct list_head *free_list, void *mem, unsigned long size)
275{
276 struct string *cs;
277
278 cs = (struct string *) mem;
279 cs->size = size - sizeof(struct string);
280 free_string(free_list, cs);
281}
282