[PATCH] W1: w1_netlink: New init/fini netlink callbacks.
[linux-2.6/verdex.git] / drivers / s390 / char / raw3270.h
blobed5d4eb9f623114508e7a2587508e41c84af766c
1 /*
2 * drivers/s390/char/raw3270.h
3 * IBM/3270 Driver
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 */
11 #include <asm/idals.h>
12 #include <asm/ioctl.h>
14 /* ioctls for fullscreen 3270 */
15 #define TUBICMD _IO('3', 3) /* set ccw command for fs reads. */
16 #define TUBOCMD _IO('3', 4) /* set ccw command for fs writes. */
17 #define TUBGETI _IO('3', 7) /* get ccw command for fs reads. */
18 #define TUBGETO _IO('3', 8) /* get ccw command for fs writes. */
19 #define TUBSETMOD _IO('3',12) /* FIXME: what does it do ?*/
20 #define TUBGETMOD _IO('3',13) /* FIXME: what does it do ?*/
22 /* Local Channel Commands */
23 #define TC_WRITE 0x01 /* Write */
24 #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 */
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 */
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
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
54 /* Extended-Highlighting Bytes */
55 #define TAX_RESET 0x00
56 #define TAX_BLINK 0xf1
57 #define TAX_REVER 0xf2
58 #define TAX_UNDER 0xf4
60 /* Reset value */
61 #define TAR_RESET 0x00
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
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 */
79 #define RAW3270_MAXDEVS 256
81 /* For TUBGETMOD and TUBSETMOD. Should include. */
82 struct raw3270_iocb {
83 short model;
84 short line_cnt;
85 short col_cnt;
86 short pf_cnt;
87 short re_cnt;
88 short map;
91 struct raw3270;
92 struct raw3270_view;
94 /* 3270 CCW request */
95 struct raw3270_request {
96 struct list_head list; /* list head for request queueing. */
97 struct raw3270_view *view; /* view of this request */
98 struct ccw1 ccw; /* single ccw. */
99 void *buffer; /* output buffer. */
100 size_t size; /* size of output buffer. */
101 int rescnt; /* residual count from devstat. */
102 int rc; /* return code for this request. */
104 /* Callback for delivering final status. */
105 void (*callback)(struct raw3270_request *, void *);
106 void *callback_data;
109 struct raw3270_request *raw3270_request_alloc(size_t size);
110 struct raw3270_request *raw3270_request_alloc_bootmem(size_t size);
111 void raw3270_request_free(struct raw3270_request *);
112 void raw3270_request_reset(struct raw3270_request *);
113 void raw3270_request_set_cmd(struct raw3270_request *, u8 cmd);
114 int raw3270_request_add_data(struct raw3270_request *, void *, size_t);
115 void raw3270_request_set_data(struct raw3270_request *, void *, size_t);
116 void raw3270_request_set_idal(struct raw3270_request *, struct idal_buffer *);
118 static inline int
119 raw3270_request_final(struct raw3270_request *rq)
121 return list_empty(&rq->list);
124 void raw3270_buffer_address(struct raw3270 *, char *, unsigned short);
126 /* Return value of *intv (see raw3270_fn below) can be one of the following: */
127 #define RAW3270_IO_DONE 0 /* request finished */
128 #define RAW3270_IO_BUSY 1 /* request still active */
129 #define RAW3270_IO_RETRY 2 /* retry current request */
130 #define RAW3270_IO_STOP 3 /* kill current request */
133 * Functions of a 3270 view.
135 struct raw3270_fn {
136 int (*activate)(struct raw3270_view *);
137 void (*deactivate)(struct raw3270_view *);
138 int (*intv)(struct raw3270_view *,
139 struct raw3270_request *, struct irb *);
140 void (*release)(struct raw3270_view *);
141 void (*free)(struct raw3270_view *);
145 * View structure chaining. The raw3270_view structure is meant to
146 * be embedded at the start of the real view data structure, e.g.:
147 * struct example {
148 * struct raw3270_view view;
149 * ...
150 * };
152 struct raw3270_view {
153 struct list_head list;
154 spinlock_t lock;
155 atomic_t ref_count;
156 struct raw3270 *dev;
157 struct raw3270_fn *fn;
158 unsigned int model;
159 unsigned int rows, cols; /* # of rows & colums of the view */
160 unsigned char *ascebc; /* ascii -> ebcdic table */
163 int raw3270_add_view(struct raw3270_view *, struct raw3270_fn *, int);
164 int raw3270_activate_view(struct raw3270_view *);
165 void raw3270_del_view(struct raw3270_view *);
166 void raw3270_deactivate_view(struct raw3270_view *);
167 struct raw3270_view *raw3270_find_view(struct raw3270_fn *, int);
168 int raw3270_start(struct raw3270_view *, struct raw3270_request *);
169 int raw3270_start_irq(struct raw3270_view *, struct raw3270_request *);
171 /* Reference count inliner for view structures. */
172 static inline void
173 raw3270_get_view(struct raw3270_view *view)
175 atomic_inc(&view->ref_count);
178 extern wait_queue_head_t raw3270_wait_queue;
180 static inline void
181 raw3270_put_view(struct raw3270_view *view)
183 if (atomic_dec_return(&view->ref_count) == 0)
184 wake_up(&raw3270_wait_queue);
187 struct raw3270 *raw3270_setup_console(struct ccw_device *cdev);
188 void raw3270_wait_cons_dev(struct raw3270 *);
190 /* Notifier for device addition/removal */
191 int raw3270_register_notifier(void (*notifier)(int, int));
192 void raw3270_unregister_notifier(void (*notifier)(int, int));
195 * Little memory allocator for string objects.
197 struct string
199 struct list_head list;
200 struct list_head update;
201 unsigned long size;
202 unsigned long len;
203 char string[0];
204 } __attribute__ ((aligned(8)));
206 static inline struct string *
207 alloc_string(struct list_head *free_list, unsigned long len)
209 struct string *cs, *tmp;
210 unsigned long size;
212 size = (len + 7L) & -8L;
213 list_for_each_entry(cs, free_list, list) {
214 if (cs->size < size)
215 continue;
216 if (cs->size > size + sizeof(struct string)) {
217 char *endaddr = (char *) (cs + 1) + cs->size;
218 tmp = (struct string *) (endaddr - size) - 1;
219 tmp->size = size;
220 cs->size -= size + sizeof(struct string);
221 cs = tmp;
222 } else
223 list_del(&cs->list);
224 cs->len = len;
225 INIT_LIST_HEAD(&cs->list);
226 INIT_LIST_HEAD(&cs->update);
227 return cs;
229 return 0;
232 static inline unsigned long
233 free_string(struct list_head *free_list, struct string *cs)
235 struct string *tmp;
236 struct list_head *p, *left;
238 /* Find out the left neighbour in free memory list. */
239 left = free_list;
240 list_for_each(p, free_list) {
241 if (list_entry(p, struct string, list) > cs)
242 break;
243 left = p;
245 /* Try to merge with right neighbour = next element from left. */
246 if (left->next != free_list) {
247 tmp = list_entry(left->next, struct string, list);
248 if ((char *) (cs + 1) + cs->size == (char *) tmp) {
249 list_del(&tmp->list);
250 cs->size += tmp->size + sizeof(struct string);
253 /* Try to merge with left neighbour. */
254 if (left != free_list) {
255 tmp = list_entry(left, struct string, list);
256 if ((char *) (tmp + 1) + tmp->size == (char *) cs) {
257 tmp->size += cs->size + sizeof(struct string);
258 return tmp->size;
261 __list_add(&cs->list, left, left->next);
262 return cs->size;
265 static inline void
266 add_string_memory(struct list_head *free_list, void *mem, unsigned long size)
268 struct string *cs;
270 cs = (struct string *) mem;
271 cs->size = size - sizeof(struct string);
272 free_string(free_list, cs);