blob: f6489eb7e976a8c0aa1851ebbb21901d689030c1 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Martin Schwidefsky4b214a02009-06-16 10:30:47 +02002 * IBM/3270 Driver - fullscreen 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/2.6 by Martin Schwidefsky <schwidefsky@de.ibm.com>
7 * Copyright IBM Corp. 2003, 2009
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 */
9
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/bootmem.h>
11#include <linux/console.h>
12#include <linux/init.h>
13#include <linux/interrupt.h>
14#include <linux/list.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090015#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/types.h>
17
Heiko Carstens16e1a572010-01-13 20:44:32 +010018#include <asm/compat.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <asm/ccwdev.h>
20#include <asm/cio.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <asm/ebcdic.h>
22#include <asm/idals.h>
23
24#include "raw3270.h"
25#include "ctrlchar.h"
26
Heiko Carstens2b67fc42007-02-05 21:16:47 +010027static struct raw3270_fn fs3270_fn;
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
29struct fs3270 {
30 struct raw3270_view view;
Cedric Le Goater782237a2006-10-02 02:17:28 -070031 struct pid *fs_pid; /* Pid of controlling program. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070032 int read_command; /* ccw command to use for reads. */
33 int write_command; /* ccw command to use for writes. */
34 int attention; /* Got attention. */
Richard Hitted3cb6f2005-10-30 15:00:10 -080035 int active; /* Fullscreen view is active. */
36 struct raw3270_request *init; /* single init request. */
37 wait_queue_head_t wait; /* Init & attention wait queue. */
38 struct idal_buffer *rdbuf; /* full-screen-deactivate buffer */
39 size_t rdbuf_size; /* size of data returned by RDBUF */
Linus Torvalds1da177e2005-04-16 15:20:36 -070040};
41
Martin Schwidefsky5cbb5f52009-12-07 12:52:20 +010042static DEFINE_MUTEX(fs3270_mutex);
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044static void
45fs3270_wake_up(struct raw3270_request *rq, void *data)
46{
47 wake_up((wait_queue_head_t *) data);
48}
49
Richard Hitted3cb6f2005-10-30 15:00:10 -080050static inline int
51fs3270_working(struct fs3270 *fp)
52{
53 /*
54 * The fullscreen view is in working order if the view
55 * has been activated AND the initial request is finished.
56 */
57 return fp->active && raw3270_request_final(fp->init);
58}
59
Linus Torvalds1da177e2005-04-16 15:20:36 -070060static int
61fs3270_do_io(struct raw3270_view *view, struct raw3270_request *rq)
62{
Richard Hitted3cb6f2005-10-30 15:00:10 -080063 struct fs3270 *fp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 int rc;
65
Richard Hitted3cb6f2005-10-30 15:00:10 -080066 fp = (struct fs3270 *) view;
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 rq->callback = fs3270_wake_up;
Richard Hitted3cb6f2005-10-30 15:00:10 -080068 rq->callback_data = &fp->wait;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
Richard Hitted3cb6f2005-10-30 15:00:10 -080070 do {
71 if (!fs3270_working(fp)) {
72 /* Fullscreen view isn't ready yet. */
73 rc = wait_event_interruptible(fp->wait,
74 fs3270_working(fp));
75 if (rc != 0)
76 break;
77 }
78 rc = raw3270_start(view, rq);
79 if (rc == 0) {
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020080 /* Started successfully. Now wait for completion. */
Richard Hitted3cb6f2005-10-30 15:00:10 -080081 wait_event(fp->wait, raw3270_request_final(rq));
82 }
83 } while (rc == -EACCES);
84 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -070085}
86
87/*
88 * Switch to the fullscreen view.
89 */
Richard Hitted3cb6f2005-10-30 15:00:10 -080090static void
91fs3270_reset_callback(struct raw3270_request *rq, void *data)
92{
93 struct fs3270 *fp;
94
95 fp = (struct fs3270 *) rq->view;
96 raw3270_request_reset(rq);
97 wake_up(&fp->wait);
98}
99
100static void
101fs3270_restore_callback(struct raw3270_request *rq, void *data)
102{
103 struct fs3270 *fp;
104
105 fp = (struct fs3270 *) rq->view;
106 if (rq->rc != 0 || rq->rescnt != 0) {
107 if (fp->fs_pid)
Cedric Le Goater782237a2006-10-02 02:17:28 -0700108 kill_pid(fp->fs_pid, SIGHUP, 1);
Richard Hitted3cb6f2005-10-30 15:00:10 -0800109 }
110 fp->rdbuf_size = 0;
111 raw3270_request_reset(rq);
112 wake_up(&fp->wait);
113}
114
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115static int
116fs3270_activate(struct raw3270_view *view)
117{
118 struct fs3270 *fp;
Richard Hitted3cb6f2005-10-30 15:00:10 -0800119 char *cp;
120 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
122 fp = (struct fs3270 *) view;
Richard Hitted3cb6f2005-10-30 15:00:10 -0800123
124 /* If an old init command is still running just return. */
125 if (!raw3270_request_final(fp->init))
126 return 0;
127
128 if (fp->rdbuf_size == 0) {
129 /* No saved buffer. Just clear the screen. */
130 raw3270_request_set_cmd(fp->init, TC_EWRITEA);
131 fp->init->callback = fs3270_reset_callback;
132 } else {
133 /* Restore fullscreen buffer saved by fs3270_deactivate. */
134 raw3270_request_set_cmd(fp->init, TC_EWRITEA);
135 raw3270_request_set_idal(fp->init, fp->rdbuf);
136 fp->init->ccw.count = fp->rdbuf_size;
137 cp = fp->rdbuf->data[0];
138 cp[0] = TW_KR;
139 cp[1] = TO_SBA;
140 cp[2] = cp[6];
141 cp[3] = cp[7];
142 cp[4] = TO_IC;
143 cp[5] = TO_SBA;
144 cp[6] = 0x40;
145 cp[7] = 0x40;
146 fp->init->rescnt = 0;
147 fp->init->callback = fs3270_restore_callback;
148 }
149 rc = fp->init->rc = raw3270_start_locked(view, fp->init);
150 if (rc)
151 fp->init->callback(fp->init, NULL);
152 else
153 fp->active = 1;
154 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155}
156
157/*
158 * Shutdown fullscreen view.
159 */
160static void
Richard Hitted3cb6f2005-10-30 15:00:10 -0800161fs3270_save_callback(struct raw3270_request *rq, void *data)
162{
163 struct fs3270 *fp;
164
165 fp = (struct fs3270 *) rq->view;
166
167 /* Correct idal buffer element 0 address. */
168 fp->rdbuf->data[0] -= 5;
169 fp->rdbuf->size += 5;
170
171 /*
172 * If the rdbuf command failed or the idal buffer is
173 * to small for the amount of data returned by the
174 * rdbuf command, then we have no choice but to send
175 * a SIGHUP to the application.
176 */
177 if (rq->rc != 0 || rq->rescnt == 0) {
178 if (fp->fs_pid)
Cedric Le Goater782237a2006-10-02 02:17:28 -0700179 kill_pid(fp->fs_pid, SIGHUP, 1);
Richard Hitted3cb6f2005-10-30 15:00:10 -0800180 fp->rdbuf_size = 0;
181 } else
182 fp->rdbuf_size = fp->rdbuf->size - rq->rescnt;
183 raw3270_request_reset(rq);
184 wake_up(&fp->wait);
185}
186
187static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188fs3270_deactivate(struct raw3270_view *view)
189{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 struct fs3270 *fp;
191
192 fp = (struct fs3270 *) view;
Richard Hitted3cb6f2005-10-30 15:00:10 -0800193 fp->active = 0;
194
195 /* If an old init command is still running just return. */
196 if (!raw3270_request_final(fp->init))
197 return;
198
199 /* Prepare read-buffer request. */
200 raw3270_request_set_cmd(fp->init, TC_RDBUF);
201 /*
202 * Hackish: skip first 5 bytes of the idal buffer to make
203 * room for the TW_KR/TO_SBA/<address>/<address>/TO_IC sequence
204 * in the activation command.
205 */
206 fp->rdbuf->data[0] += 5;
207 fp->rdbuf->size -= 5;
208 raw3270_request_set_idal(fp->init, fp->rdbuf);
209 fp->init->rescnt = 0;
210 fp->init->callback = fs3270_save_callback;
211
212 /* Start I/O to read in the 3270 buffer. */
213 fp->init->rc = raw3270_start_locked(view, fp->init);
214 if (fp->init->rc)
215 fp->init->callback(fp->init, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216}
217
218static int
219fs3270_irq(struct fs3270 *fp, struct raw3270_request *rq, struct irb *irb)
220{
221 /* Handle ATTN. Set indication and wake waiters for attention. */
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200222 if (irb->scsw.cmd.dstat & DEV_STAT_ATTENTION) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 fp->attention = 1;
Richard Hitted3cb6f2005-10-30 15:00:10 -0800224 wake_up(&fp->wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 }
226
227 if (rq) {
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200228 if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 rq->rc = -EIO;
230 else
231 /* Normal end. Copy residual count. */
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200232 rq->rescnt = irb->scsw.cmd.count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 }
234 return RAW3270_IO_DONE;
235}
236
237/*
238 * Process reads from fullscreen 3270.
239 */
240static ssize_t
Heiko Carstensd2c993d2006-07-12 16:41:55 +0200241fs3270_read(struct file *filp, char __user *data, size_t count, loff_t *off)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242{
243 struct fs3270 *fp;
244 struct raw3270_request *rq;
245 struct idal_buffer *ib;
Richard Hitted3cb6f2005-10-30 15:00:10 -0800246 ssize_t rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247
248 if (count == 0 || count > 65535)
249 return -EINVAL;
250 fp = filp->private_data;
251 if (!fp)
252 return -ENODEV;
253 ib = idal_buffer_alloc(count, 0);
Richard Hitted3cb6f2005-10-30 15:00:10 -0800254 if (IS_ERR(ib))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 return -ENOMEM;
256 rq = raw3270_request_alloc(0);
257 if (!IS_ERR(rq)) {
258 if (fp->read_command == 0 && fp->write_command != 0)
259 fp->read_command = 6;
260 raw3270_request_set_cmd(rq, fp->read_command ? : 2);
261 raw3270_request_set_idal(rq, ib);
Richard Hitted3cb6f2005-10-30 15:00:10 -0800262 rc = wait_event_interruptible(fp->wait, fp->attention);
263 fp->attention = 0;
264 if (rc == 0) {
265 rc = fs3270_do_io(&fp->view, rq);
266 if (rc == 0) {
267 count -= rq->rescnt;
268 if (idal_buffer_to_user(ib, data, count) != 0)
269 rc = -EFAULT;
270 else
271 rc = count;
272
273 }
274 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 raw3270_request_free(rq);
276 } else
277 rc = PTR_ERR(rq);
278 idal_buffer_free(ib);
279 return rc;
280}
281
282/*
283 * Process writes to fullscreen 3270.
284 */
285static ssize_t
Heiko Carstensd2c993d2006-07-12 16:41:55 +0200286fs3270_write(struct file *filp, const char __user *data, size_t count, loff_t *off)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287{
288 struct fs3270 *fp;
289 struct raw3270_request *rq;
290 struct idal_buffer *ib;
291 int write_command;
Richard Hitted3cb6f2005-10-30 15:00:10 -0800292 ssize_t rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293
294 fp = filp->private_data;
295 if (!fp)
296 return -ENODEV;
297 ib = idal_buffer_alloc(count, 0);
Richard Hitted3cb6f2005-10-30 15:00:10 -0800298 if (IS_ERR(ib))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 return -ENOMEM;
300 rq = raw3270_request_alloc(0);
301 if (!IS_ERR(rq)) {
302 if (idal_buffer_from_user(ib, data, count) == 0) {
303 write_command = fp->write_command ? : 1;
304 if (write_command == 5)
305 write_command = 13;
306 raw3270_request_set_cmd(rq, write_command);
307 raw3270_request_set_idal(rq, ib);
308 rc = fs3270_do_io(&fp->view, rq);
Richard Hitted3cb6f2005-10-30 15:00:10 -0800309 if (rc == 0)
310 rc = count - rq->rescnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 } else
312 rc = -EFAULT;
313 raw3270_request_free(rq);
314 } else
315 rc = PTR_ERR(rq);
316 idal_buffer_free(ib);
317 return rc;
318}
319
320/*
321 * process ioctl commands for the tube driver
322 */
Christoph Hellwig0f75e002006-01-09 20:52:04 -0800323static long
324fs3270_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325{
Heiko Carstens16e1a572010-01-13 20:44:32 +0100326 char __user *argp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 struct fs3270 *fp;
328 struct raw3270_iocb iocb;
329 int rc;
330
331 fp = filp->private_data;
332 if (!fp)
333 return -ENODEV;
Heiko Carstens16e1a572010-01-13 20:44:32 +0100334 if (is_compat_task())
335 argp = compat_ptr(arg);
336 else
337 argp = (char __user *)arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 rc = 0;
Martin Schwidefsky5cbb5f52009-12-07 12:52:20 +0100339 mutex_lock(&fs3270_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 switch (cmd) {
341 case TUBICMD:
342 fp->read_command = arg;
343 break;
344 case TUBOCMD:
345 fp->write_command = arg;
346 break;
347 case TUBGETI:
Heiko Carstens16e1a572010-01-13 20:44:32 +0100348 rc = put_user(fp->read_command, argp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 break;
350 case TUBGETO:
Heiko Carstens16e1a572010-01-13 20:44:32 +0100351 rc = put_user(fp->write_command, argp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 break;
353 case TUBGETMOD:
354 iocb.model = fp->view.model;
355 iocb.line_cnt = fp->view.rows;
356 iocb.col_cnt = fp->view.cols;
357 iocb.pf_cnt = 24;
358 iocb.re_cnt = 20;
359 iocb.map = 0;
Heiko Carstens16e1a572010-01-13 20:44:32 +0100360 if (copy_to_user(argp, &iocb, sizeof(struct raw3270_iocb)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 rc = -EFAULT;
362 break;
363 }
Martin Schwidefsky5cbb5f52009-12-07 12:52:20 +0100364 mutex_unlock(&fs3270_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 return rc;
366}
367
368/*
Richard Hitted3cb6f2005-10-30 15:00:10 -0800369 * Allocate fs3270 structure.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 */
371static struct fs3270 *
372fs3270_alloc_view(void)
373{
374 struct fs3270 *fp;
375
Eric Sesterhenn88abaab2006-03-24 03:15:31 -0800376 fp = kzalloc(sizeof(struct fs3270),GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 if (!fp)
378 return ERR_PTR(-ENOMEM);
Richard Hitted3cb6f2005-10-30 15:00:10 -0800379 fp->init = raw3270_request_alloc(0);
380 if (IS_ERR(fp->init)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 kfree(fp);
382 return ERR_PTR(-ENOMEM);
383 }
384 return fp;
385}
386
387/*
Richard Hitted3cb6f2005-10-30 15:00:10 -0800388 * Free fs3270 structure.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 */
390static void
391fs3270_free_view(struct raw3270_view *view)
392{
Richard Hitted3cb6f2005-10-30 15:00:10 -0800393 struct fs3270 *fp;
394
395 fp = (struct fs3270 *) view;
396 if (fp->rdbuf)
397 idal_buffer_free(fp->rdbuf);
398 raw3270_request_free(((struct fs3270 *) view)->init);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 kfree(view);
400}
401
402/*
403 * Unlink fs3270 data structure from filp.
404 */
405static void
406fs3270_release(struct raw3270_view *view)
407{
Martin Schwidefsky4b214a02009-06-16 10:30:47 +0200408 struct fs3270 *fp;
409
410 fp = (struct fs3270 *) view;
411 if (fp->fs_pid)
412 kill_pid(fp->fs_pid, SIGHUP, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413}
414
415/* View to a 3270 device. Can be console, tty or fullscreen. */
Heiko Carstens2b67fc42007-02-05 21:16:47 +0100416static struct raw3270_fn fs3270_fn = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 .activate = fs3270_activate,
418 .deactivate = fs3270_deactivate,
419 .intv = (void *) fs3270_irq,
420 .release = fs3270_release,
421 .free = fs3270_free_view
422};
423
424/*
425 * This routine is called whenever a 3270 fullscreen device is opened.
426 */
427static int
428fs3270_open(struct inode *inode, struct file *filp)
429{
430 struct fs3270 *fp;
Richard Hitted3cb6f2005-10-30 15:00:10 -0800431 struct idal_buffer *ib;
Alan Coxa18992d2008-10-13 10:46:09 +0100432 int minor, rc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433
Josef Sipek49522c92006-12-08 02:37:34 -0800434 if (imajor(filp->f_path.dentry->d_inode) != IBM_FS3270_MAJOR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 return -ENODEV;
Josef Sipek49522c92006-12-08 02:37:34 -0800436 minor = iminor(filp->f_path.dentry->d_inode);
Richard Hitted3cb6f2005-10-30 15:00:10 -0800437 /* Check for minor 0 multiplexer. */
438 if (minor == 0) {
Alan Coxa90610e2008-10-13 10:45:52 +0100439 struct tty_struct *tty = get_current_tty();
Peter Zijlstra24ec8392006-12-08 02:36:04 -0800440 if (!tty || tty->driver->major != IBM_TTY3270_MAJOR) {
Alan Cox452a00d2008-10-13 10:39:13 +0100441 tty_kref_put(tty);
Alan Coxa18992d2008-10-13 10:46:09 +0100442 return -ENODEV;
Peter Zijlstra24ec8392006-12-08 02:36:04 -0800443 }
444 minor = tty->index + RAW3270_FIRSTMINOR;
Alan Cox452a00d2008-10-13 10:39:13 +0100445 tty_kref_put(tty);
Richard Hitted3cb6f2005-10-30 15:00:10 -0800446 }
Martin Schwidefsky5cbb5f52009-12-07 12:52:20 +0100447 mutex_lock(&fs3270_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 /* Check if some other program is already using fullscreen mode. */
449 fp = (struct fs3270 *) raw3270_find_view(&fs3270_fn, minor);
450 if (!IS_ERR(fp)) {
451 raw3270_put_view(&fp->view);
Jonathan Corbet764a4a82008-05-15 10:01:17 -0600452 rc = -EBUSY;
453 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 }
455 /* Allocate fullscreen view structure. */
456 fp = fs3270_alloc_view();
Jonathan Corbet764a4a82008-05-15 10:01:17 -0600457 if (IS_ERR(fp)) {
458 rc = PTR_ERR(fp);
459 goto out;
460 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461
Richard Hitted3cb6f2005-10-30 15:00:10 -0800462 init_waitqueue_head(&fp->wait);
Cedric Le Goater782237a2006-10-02 02:17:28 -0700463 fp->fs_pid = get_pid(task_pid(current));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 rc = raw3270_add_view(&fp->view, &fs3270_fn, minor);
465 if (rc) {
466 fs3270_free_view(&fp->view);
Jonathan Corbet764a4a82008-05-15 10:01:17 -0600467 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 }
469
Richard Hitted3cb6f2005-10-30 15:00:10 -0800470 /* Allocate idal-buffer. */
471 ib = idal_buffer_alloc(2*fp->view.rows*fp->view.cols + 5, 0);
472 if (IS_ERR(ib)) {
473 raw3270_put_view(&fp->view);
474 raw3270_del_view(&fp->view);
Roel Kluin2b310012009-12-18 17:43:19 +0100475 rc = PTR_ERR(ib);
Jonathan Corbet764a4a82008-05-15 10:01:17 -0600476 goto out;
Richard Hitted3cb6f2005-10-30 15:00:10 -0800477 }
478 fp->rdbuf = ib;
479
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 rc = raw3270_activate_view(&fp->view);
481 if (rc) {
Richard Hitted3cb6f2005-10-30 15:00:10 -0800482 raw3270_put_view(&fp->view);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 raw3270_del_view(&fp->view);
Jonathan Corbet764a4a82008-05-15 10:01:17 -0600484 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 }
Martin Schwidefsky58ea91c2010-05-17 10:00:07 +0200486 nonseekable_open(inode, filp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 filp->private_data = fp;
Jonathan Corbet764a4a82008-05-15 10:01:17 -0600488out:
Martin Schwidefsky5cbb5f52009-12-07 12:52:20 +0100489 mutex_unlock(&fs3270_mutex);
Alan Coxa18992d2008-10-13 10:46:09 +0100490 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491}
492
493/*
494 * This routine is called when the 3270 tty is closed. We wait
495 * for the remaining request to be completed. Then we clean up.
496 */
497static int
498fs3270_close(struct inode *inode, struct file *filp)
499{
500 struct fs3270 *fp;
501
502 fp = filp->private_data;
Heiko Carstensd2c993d2006-07-12 16:41:55 +0200503 filp->private_data = NULL;
Richard Hitted3cb6f2005-10-30 15:00:10 -0800504 if (fp) {
Cedric Le Goater782237a2006-10-02 02:17:28 -0700505 put_pid(fp->fs_pid);
506 fp->fs_pid = NULL;
Richard Hitted3cb6f2005-10-30 15:00:10 -0800507 raw3270_reset(&fp->view);
508 raw3270_put_view(&fp->view);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 raw3270_del_view(&fp->view);
Richard Hitted3cb6f2005-10-30 15:00:10 -0800510 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 return 0;
512}
513
Arjan van de Vend54b1fd2007-02-12 00:55:34 -0800514static const struct file_operations fs3270_fops = {
Christoph Hellwig0f75e002006-01-09 20:52:04 -0800515 .owner = THIS_MODULE, /* owner */
516 .read = fs3270_read, /* read */
517 .write = fs3270_write, /* write */
518 .unlocked_ioctl = fs3270_ioctl, /* ioctl */
519 .compat_ioctl = fs3270_ioctl, /* ioctl */
Heiko Carstens16e1a572010-01-13 20:44:32 +0100520 .open = fs3270_open, /* open */
521 .release = fs3270_close, /* release */
Arnd Bergmann6038f372010-08-15 18:52:59 +0200522 .llseek = no_llseek,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523};
524
525/*
526 * 3270 fullscreen driver initialization.
527 */
528static int __init
529fs3270_init(void)
530{
531 int rc;
532
533 rc = register_chrdev(IBM_FS3270_MAJOR, "fs3270", &fs3270_fops);
Martin Schwidefskya26182e2008-07-14 09:59:25 +0200534 if (rc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 return 0;
537}
538
539static void __exit
540fs3270_exit(void)
541{
542 unregister_chrdev(IBM_FS3270_MAJOR, "fs3270");
543}
544
545MODULE_LICENSE("GPL");
546MODULE_ALIAS_CHARDEV_MAJOR(IBM_FS3270_MAJOR);
547
548module_init(fs3270_init);
549module_exit(fs3270_exit);