Hopefully get the Kconfig PCI stuff right, finally.
[linux-2.6/linux-mips.git] / drivers / s390 / char / tubio.h
blob24fc1fa0c2c57e43144d3e99120dd1d538aaf843
1 /*
2 * IBM/3270 Driver -- Copyright (C) 2000 UTS Global LLC
4 * tubio.h -- All-Purpose header file
10 * Author: Richard Hitt
12 #include <linux/config.h>
14 #include <linux/module.h>
15 #include <linux/version.h>
16 #include <linux/tty.h>
18 #include <linux/major.h>
19 #ifndef IBM_TTY3270_MAJOR
20 # define IBM_TTY3270_MAJOR 212
21 #endif /* IBM_TTY3270_MAJOR */
22 #ifndef IBM_FS3270_MAJOR
23 # define IBM_FS3270_MAJOR 213
24 #endif /* IBM_FS3270_MAJOR */
27 #include <linux/slab.h>
28 #include <asm/irq.h>
29 #include <asm/io.h>
30 #include <asm/idals.h>
31 #include <linux/console.h>
32 #include <linux/interrupt.h>
33 #include <asm/ebcdic.h>
34 #include <asm/uaccess.h>
35 #include <linux/proc_fs.h>
36 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0))
37 #include <linux/devfs_fs_kernel.h>
38 #endif
40 #define TUB(x) (('3'<<8)|(x))
41 #define TUBICMD TUB(3)
42 #define TUBOCMD TUB(4)
43 #define TUBGETI TUB(7)
44 #define TUBGETO TUB(8)
45 #define TUBSETMOD TUB(12)
46 #define TUBGETMOD TUB(13)
47 #define TIOPOLL TUB(32)
48 #define TIOPOKE TUB(33)
49 #define TIONPOKE TUB(34)
50 #define TIOTNORM TUB(35)
52 /* Local Channel Commands */
53 #define TC_WRITE 0x01
54 #define TC_EWRITE 0x05
55 #define TC_READMOD 0x06
56 #define TC_EWRITEA 0x0d
57 #define TC_WRITESF 0x11
59 /* Buffer Control Orders */
60 #define TO_SF 0x1d
61 #define TO_SBA 0x11
62 #define TO_IC 0x13
63 #define TO_PT 0x05
64 #define TO_RA 0x3c
65 #define TO_SFE 0x29
66 #define TO_EUA 0x12
67 #define TO_MF 0x2c
68 #define TO_SA 0x28
70 /* Field Attribute Bytes */
71 #define TF_INPUT 0x40 /* Visible input */
72 #define TF_INPUTN 0x4c /* Invisible input */
73 #define TF_INMDT 0xc1 /* Visible, Set-MDT */
74 #define TF_LOG 0x60
75 #define TF_STAT 0x60
77 /* Character Attribute Bytes */
78 #define TAT_RESET 0x00
79 #define TAT_FIELD 0xc0
80 #define TAT_EXTHI 0x41
81 #define TAT_COLOR 0x42
82 #define TAT_CHARS 0x43
83 #define TAT_TRANS 0x46
85 /* Extended-Highlighting Bytes */
86 #define TAX_RESET 0x00
87 #define TAX_BLINK 0xf1
88 #define TAX_REVER 0xf2
89 #define TAX_UNDER 0xf4
91 /* Reset value */
92 #define TAR_RESET 0x00
94 /* Color values */
95 #define TAC_RESET 0x00
96 #define TAC_BLUE 0xf1
97 #define TAC_RED 0xf2
98 #define TAC_PINK 0xf3
99 #define TAC_GREEN 0xf4
100 #define TAC_TURQ 0xf5
101 #define TAC_YELLOW 0xf6
102 #define TAC_WHITE 0xf7
103 #define TAC_DEFAULT 0x00
105 /* Write Control Characters */
106 #define TW_NONE 0x40 /* No particular action */
107 #define TW_KR 0xc2 /* Keyboard restore */
108 #define TW_PLUSALARM 0x04 /* Add this bit for alarm */
110 /* Attention-ID (AID) Characters */
111 #define TA_CLEAR 0x6d
112 #define TA_PA2 0x6e
113 #define TA_ENTER 0x7d
114 /* more to come */
116 #define MIN(a, b) ((a) < (b)? (a): (b))
118 #define TUB_BUFADR(adr, cpp) \
119 tty3270_tub_bufadr(tubp, adr, cpp)
121 #define TUB_EBCASC(addr, nr) codepage_convert(tub_ebcasc, addr, nr)
122 #define TUB_ASCEBC(addr, nr) codepage_convert(tub_ascebc, addr, nr)
126 * General global values for the tube driver
129 enum tubmode {
130 TBM_LN, /* Line mode */
131 TBM_FS, /* Fullscreen mode */
132 TBM_FSLN /* Line mode shelled out of fullscreen */
134 enum tubstat { /* normal-mode status */
135 TBS_RUNNING, /* none of the following */
136 TBS_MORE, /* timed "MORE..." in status */
137 TBS_HOLD /* untimed "HOLDING" in status */
139 enum tubcmd { /* normal-mode actions to do */
140 TBC_CONOPEN, /* Erase-write the console */
141 TBC_OPEN, /* Open the tty screen */
142 TBC_UPDATE, /* Add lines to the log, clear cmdline */
143 TBC_UPDLOG, /* Add lines to log */
144 TBC_KRUPDLOG, /* Add lines to log, reset kbd */
145 TBC_CLEAR, /* Build screen from scratch */
146 TBC_CLRUPDLOG, /* Do log & status, not cmdline */
147 TBC_UPDSTAT, /* Do status update only */
148 TBC_CLRINPUT, /* Clear input area only */
149 TBC_UPDINPUT /* Update input area only */
151 enum tubwhat { /* echo what= proc actions */
152 TW_BOGUS, /* Nothing at all */
153 TW_CONFIG /* Output configuration info */
160 #define TUBMAXMINS 256
161 #define TUB_DEV MKDEV(IBM_FS3270_MAJ, 0) /* Generic /dev/3270/tub */
162 #define _GEOM_ROWS 24
163 #define _GEOM_COLS 80
164 #define GEOM_ROWS (tubp->geom_rows)
165 #define GEOM_COLS (tubp->geom_cols)
166 #define GEOM_MAXROWS 127
167 #define GEOM_MAXCOLS 132
168 #define GEOM_INPLEN (GEOM_COLS * 2 - 20)
169 #define GEOM_MAXINPLEN (GEOM_MAXCOLS * 2 - 20)
170 #define GEOM_INPUT (GEOM_COLS * (GEOM_ROWS - 2) - 1) /* input atr posn */
171 #define GEOM_STAT (GEOM_INPUT + 1 + GEOM_INPLEN)
172 #define GEOM_LOG (GEOM_COLS * GEOM_ROWS - 1) /* log atr posn */
173 #define TS_RUNNING "Linux Running "
174 #define TS_MORE "Linux More... "
175 #define DEFAULT_SCROLLTIME 5
176 #define TS_HOLD "Linux Holding "
177 /* data length used by tty3270_set_status_area: SBA (3), SF (2), data */
178 #define TS_LENGTH (sizeof TS_RUNNING + 3 + 2)
180 typedef struct {
181 int aid; /* What-to-do flags */
182 char *string; /* Optional input string */
183 } aid_t;
184 #define AIDENTRY(ch, tubp) (&((tubp)->tty_aid[(ch) & 0x3f]))
186 /* For TUBGETMOD and TUBSETMOD. Should include. */
187 typedef struct tubiocb {
188 short model;
189 short line_cnt;
190 short col_cnt;
191 short pf_cnt;
192 short re_cnt;
193 short map;
194 } tubiocb_t;
196 /* Flags that go in int aid, above */
197 #define TA_CLEARKEY 0x01 /* Key does hardware CLEAR */
198 #define TA_SHORTREAD 0x02 /* Key does hardware shortread */
199 /* If both are off, key does hardware Read Modified. */
200 #define TA_DOENTER 0x04 /* Treat key like ENTER */
201 #define TA_DOSTRING 0x08 /* Use string and ENTER */
202 #define TA_DOSTRINGD 0x10 /* Display string & set MDT */
203 #define TA_CLEARLOG 0x20 /* Make key cause clear of log */
206 * Tube driver buffer control block
208 typedef struct bcb_s {
209 char *bc_buf; /* Pointer to buffer */
210 int bc_len; /* Length of buffer */
211 int bc_cnt; /* Count of bytes buffered */
212 int bc_wr; /* Posn to write next byte into */
213 int bc_rd; /* Posn to read next byte from */
214 } bcb_t;
216 typedef struct tub_s {
217 int minor;
218 int irq;
219 int irqrc;
220 int devno;
221 int geom_rows;
222 int geom_cols;
223 tubiocb_t tubiocb;
224 int lnopen;
225 int fsopen;
226 int icmd;
227 int ocmd;
228 devstat_t devstat;
229 ccw1_t rccw;
230 ccw1_t wccw;
231 addr_t *wbuf;
232 int cswl;
233 void (*intv)(struct tub_s *, devstat_t *);
234 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0))
235 struct wait_queue *waitq;
236 #else
237 wait_queue_head_t waitq;
238 #endif
239 int dstat;
240 sense_t sense;
241 enum tubmode mode;
242 enum tubstat stat;
243 enum tubcmd cmd;
244 int flags; /* See below for values */
245 struct tasklet_struct tasklet;
247 /* Stuff for fs-driver support */
248 pid_t fs_pid; /* Pid if TBM_FS */
251 /* Stuff for tty-driver support */
252 struct tty_struct *tty;
253 char *tty_input; /* tty input area */
254 int tty_inattr; /* input-area field attribute */
255 #define TTY_OUTPUT_SIZE 1024
256 bcb_t tty_bcb; /* Output buffer control info */
257 int tty_oucol; /* Kludge */
258 int tty_nextlogx; /* next screen-log position */
259 int tty_savecursor; /* saved cursor position */
260 int tty_scrolltime; /* scrollforward wait time, sec */
261 struct timer_list tty_stimer; /* timer for scrolltime */
262 aid_t tty_aid[64]; /* Aid descriptors */
263 int tty_aidinit; /* Boolean */
264 int tty_showaidx; /* Last aid x to set_aid */
265 int tty_14bitadr; /* 14-bit bufadrs okay */
266 #define MAX_TTY_ESCA 24 /* Set-Attribute-Order array */
267 char tty_esca[MAX_TTY_ESCA]; /* SA array */
268 int tty_escx; /* Current index within it */
270 /* For command recall --- */
271 char *(*tty_rclbufs)[]; /* Array of ptrs to recall bufs */
272 int tty_rclk; /* Size of array tty_rclbufs */
273 int tty_rclp; /* Index for most-recent cmd */
274 int tty_rclb; /* Index for backscrolling */
276 /* Work area to contain the hardware write stream */
277 char (*ttyscreen)[]; /* ptr to data stream area */
278 int ttyscreenl; /* its length */
279 ccw1_t ttyccw;
280 } tub_t;
282 /* values for flags: */
283 #define TUB_WORKING 0x0001
284 #define TUB_BHPENDING 0x0002
285 #define TUB_RDPENDING 0x0004
286 #define TUB_ALARM 0x0008
287 #define TUB_SCROLLTIMING 0x0010
288 #define TUB_ATTN 0x0020
289 #define TUB_IACTIVE 0x0040
290 #define TUB_SIZED 0x0080
291 #define TUB_EXPECT_DE 0x0100
292 #define TUB_UNSOL_DE 0x0200
293 #define TUB_OPEN_STET 0x0400 /* No screen clear on open */
294 #define TUB_UE_BUSY 0x0800
295 #define TUB_INPUT_HACK 0x1000 /* Early init of command line */
297 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0))
298 #define S390_CONSOLE_DEV MKDEV(TTY_MAJOR, 64)
299 #define tub_major(x) MAJOR(x)
300 #define tub_minor(x) MINOR(x)
301 #define tub_mkdev(x, y) MKDEV(x, y)
302 #elif (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
303 #define S390_CONSOLE_DEV MKDEV(TTYAUX_MAJOR, 1)
304 #define tub_major(x) MAJOR(x)
305 #define tub_minor(x) MINOR(x)
306 #define tub_mkdev(x, y) MKDEV(x, y)
307 #else
308 #define S390_CONSOLE_DEV mk_kdev(TTYAUX_MAJOR, 1)
309 #define tub_major(x) major(x)
310 #define tub_minor(x) minor(x)
311 #define tub_mkdev(x, y) mk_kdev(x, y)
312 #endif
315 * Extra stuff for 3270 console support
317 #ifdef CONFIG_TN3270_CONSOLE
318 extern int tub3270_con_devno;
319 extern char (*tub3270_con_output)[];
320 extern int tub3270_con_outputl;
321 extern int tub3270_con_ouwr;
322 extern int tub3270_con_oucount;
323 extern int tub3270_con_irq;
324 extern tub_t *tub3270_con_tubp;
325 extern struct tty_driver tty3270_con_driver;
326 #endif /* CONFIG_TN3270_CONSOLE */
328 extern int tubnummins;
329 extern tub_t *(*tubminors)[TUBMAXMINS];
330 extern tub_t *(*(*tubirqs)[256])[256];
331 extern unsigned char tub_ascebc[256];
332 extern unsigned char tub_ebcasc[256];
333 extern unsigned char tub_ebcgraf[64];
334 extern int tubdebug;
335 extern int fs3270_major;
336 extern int tty3270_major;
337 extern int tty3270_proc_misc;
338 extern enum tubwhat tty3270_proc_what;
339 extern struct tty_driver tty3270_driver;
341 #ifndef spin_trylock_irqsave
342 #define spin_trylock_irqsave(lock, flags) \
343 ({ \
344 int success; \
345 local_irq_save(flags); \
346 success = spin_trylock(lock); \
347 if (success == 0) \
348 local_irq_restore(flags); \
349 success; \
351 #endif /* if not spin_trylock_irqsave */
353 #ifndef s390irq_spin_trylock_irqsave
354 #define s390irq_spin_trylock_irqsave(irq, flags) \
355 spin_trylock_irqsave(&(ioinfo[irq]->irq_lock), flags)
356 #endif /* if not s390irq_spin_trylock_irqsave */
358 #define TUBLOCK(irq, flags) \
359 s390irq_spin_lock_irqsave(irq, flags)
361 #define TUBTRYLOCK(irq, flags) \
362 s390irq_spin_trylock_irqsave(irq, flags)
364 #define TUBUNLOCK(irq, flags) \
365 s390irq_spin_unlock_irqrestore(irq, flags)
368 * Find tub_t * given fullscreen device's irq (subchannel number)
370 #if 0
371 extern tub_t *tubfindbyirq(int);
372 #endif
373 #define IRQ2TUB(irq) tubfindbyirq(irq)
375 * Find tub_t * given fullscreen device's inode pointer
376 * This algorithm takes into account /dev/3270/tub.
378 extern inline tub_t *INODE2TUB(struct inode *ip)
380 unsigned int minor = minor(ip->i_rdev);
381 tub_t *tubp = NULL;
382 if (minor == 0 && current->tty) {
383 if (current->tty->driver == &tty3270_driver)
384 minor = current->tty->index;
386 if (minor <= tubnummins && minor > 0)
387 tubp = (*tubminors)[minor];
388 return tubp;
392 * Find tub_t * given non-fullscreen (tty) device's tty_struct pointer
394 extern inline tub_t *TTY2TUB(struct tty_struct *tty)
396 unsigned index = tty->index;
397 tub_t *tubp = NULL;
399 if (index <= tubnummins && index > 0)
400 tubp = (*tubminors)[index];
401 return tubp;
404 extern int tub3270_movedata(bcb_t *, bcb_t *, int);
405 #if 0
406 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0))
407 extern int tubmakemin(int, dev_info_t *);
408 #else
409 extern int tubmakemin(int, s390_dev_info_t *);
410 #endif
411 #endif
412 extern int tub3270_con_copy(tub_t *);
413 extern int tty3270_rcl_init(tub_t *);
414 extern int tty3270_rcl_set(tub_t *, char *, int);
415 extern void tty3270_rcl_fini(tub_t *);
416 extern int tty3270_rcl_get(tub_t *, char *, int, int);
417 extern void tty3270_rcl_put(tub_t *, char *, int);
418 extern void tty3270_rcl_purge(tub_t *);
419 #if 0
420 /* these appear to be unused outside of tubttyrcl */
421 extern void tty3270_rcl_sync(tub_t *);
422 extern int tty3270_rcl_resize(tub_t *, int);
423 #endif
424 extern int tty3270_size(tub_t *, long *);
425 extern int tty3270_aid_init(tub_t *);
426 extern void tty3270_aid_fini(tub_t *);
427 extern void tty3270_aid_reinit(tub_t *);
428 extern int tty3270_aid_get(tub_t *, int, int *, char **);
429 extern int tty3270_aid_set(tub_t *, char *, int);
430 extern int tty3270_build(tub_t *);
431 extern void tty3270_scl_settimer(tub_t *);
432 extern void tty3270_scl_resettimer(tub_t *);
433 extern int tty3270_scl_set(tub_t *, char *, int);
434 extern int tty3270_scl_init(tub_t *tubp);
435 extern void tty3270_scl_fini(tub_t *tubp);