blob: 247b2b934728bacbcc4974ec04c3939fbc5c4764 [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>
15#include <linux/types.h>
Jonathan Corbet764a4a82008-05-15 10:01:17 -060016#include <linux/smp_lock.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
18#include <asm/ccwdev.h>
19#include <asm/cio.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <asm/ebcdic.h>
21#include <asm/idals.h>
22
23#include "raw3270.h"
24#include "ctrlchar.h"
25
Heiko Carstens2b67fc42007-02-05 21:16:47 +010026static struct raw3270_fn fs3270_fn;
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
28struct fs3270 {
29 struct raw3270_view view;
Cedric Le Goater782237a2006-10-02 02:17:28 -070030 struct pid *fs_pid; /* Pid of controlling program. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 int read_command; /* ccw command to use for reads. */
32 int write_command; /* ccw command to use for writes. */
33 int attention; /* Got attention. */
Richard Hitted3cb6f2005-10-30 15:00:10 -080034 int active; /* Fullscreen view is active. */
35 struct raw3270_request *init; /* single init request. */
36 wait_queue_head_t wait; /* Init & attention wait queue. */
37 struct idal_buffer *rdbuf; /* full-screen-deactivate buffer */
38 size_t rdbuf_size; /* size of data returned by RDBUF */
Linus Torvalds1da177e2005-04-16 15:20:36 -070039};
40
Martin Schwidefsky5cbb5f52009-12-07 12:52:20 +010041static DEFINE_MUTEX(fs3270_mutex);
42
Linus Torvalds1da177e2005-04-16 15:20:36 -070043static void
44fs3270_wake_up(struct raw3270_request *rq, void *data)
45{
46 wake_up((wait_queue_head_t *) data);
47}
48
Richard Hitted3cb6f2005-10-30 15:00:10 -080049static inline int
50fs3270_working(struct fs3270 *fp)
51{
52 /*
53 * The fullscreen view is in working order if the view
54 * has been activated AND the initial request is finished.
55 */
56 return fp->active && raw3270_request_final(fp->init);
57}
58
Linus Torvalds1da177e2005-04-16 15:20:36 -070059static int
60fs3270_do_io(struct raw3270_view *view, struct raw3270_request *rq)
61{
Richard Hitted3cb6f2005-10-30 15:00:10 -080062 struct fs3270 *fp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 int rc;
64
Richard Hitted3cb6f2005-10-30 15:00:10 -080065 fp = (struct fs3270 *) view;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 rq->callback = fs3270_wake_up;
Richard Hitted3cb6f2005-10-30 15:00:10 -080067 rq->callback_data = &fp->wait;
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
Richard Hitted3cb6f2005-10-30 15:00:10 -080069 do {
70 if (!fs3270_working(fp)) {
71 /* Fullscreen view isn't ready yet. */
72 rc = wait_event_interruptible(fp->wait,
73 fs3270_working(fp));
74 if (rc != 0)
75 break;
76 }
77 rc = raw3270_start(view, rq);
78 if (rc == 0) {
André Goddard Rosaaf901ca2009-11-14 13:09:05 -020079 /* Started successfully. Now wait for completion. */
Richard Hitted3cb6f2005-10-30 15:00:10 -080080 wait_event(fp->wait, raw3270_request_final(rq));
81 }
82 } while (rc == -EACCES);
83 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -070084}
85
86/*
87 * Switch to the fullscreen view.
88 */
Richard Hitted3cb6f2005-10-30 15:00:10 -080089static void
90fs3270_reset_callback(struct raw3270_request *rq, void *data)
91{
92 struct fs3270 *fp;
93
94 fp = (struct fs3270 *) rq->view;
95 raw3270_request_reset(rq);
96 wake_up(&fp->wait);
97}
98
99static void
100fs3270_restore_callback(struct raw3270_request *rq, void *data)
101{
102 struct fs3270 *fp;
103
104 fp = (struct fs3270 *) rq->view;
105 if (rq->rc != 0 || rq->rescnt != 0) {
106 if (fp->fs_pid)
Cedric Le Goater782237a2006-10-02 02:17:28 -0700107 kill_pid(fp->fs_pid, SIGHUP, 1);
Richard Hitted3cb6f2005-10-30 15:00:10 -0800108 }
109 fp->rdbuf_size = 0;
110 raw3270_request_reset(rq);
111 wake_up(&fp->wait);
112}
113
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114static int
115fs3270_activate(struct raw3270_view *view)
116{
117 struct fs3270 *fp;
Richard Hitted3cb6f2005-10-30 15:00:10 -0800118 char *cp;
119 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
121 fp = (struct fs3270 *) view;
Richard Hitted3cb6f2005-10-30 15:00:10 -0800122
123 /* If an old init command is still running just return. */
124 if (!raw3270_request_final(fp->init))
125 return 0;
126
127 if (fp->rdbuf_size == 0) {
128 /* No saved buffer. Just clear the screen. */
129 raw3270_request_set_cmd(fp->init, TC_EWRITEA);
130 fp->init->callback = fs3270_reset_callback;
131 } else {
132 /* Restore fullscreen buffer saved by fs3270_deactivate. */
133 raw3270_request_set_cmd(fp->init, TC_EWRITEA);
134 raw3270_request_set_idal(fp->init, fp->rdbuf);
135 fp->init->ccw.count = fp->rdbuf_size;
136 cp = fp->rdbuf->data[0];
137 cp[0] = TW_KR;
138 cp[1] = TO_SBA;
139 cp[2] = cp[6];
140 cp[3] = cp[7];
141 cp[4] = TO_IC;
142 cp[5] = TO_SBA;
143 cp[6] = 0x40;
144 cp[7] = 0x40;
145 fp->init->rescnt = 0;
146 fp->init->callback = fs3270_restore_callback;
147 }
148 rc = fp->init->rc = raw3270_start_locked(view, fp->init);
149 if (rc)
150 fp->init->callback(fp->init, NULL);
151 else
152 fp->active = 1;
153 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154}
155
156/*
157 * Shutdown fullscreen view.
158 */
159static void
Richard Hitted3cb6f2005-10-30 15:00:10 -0800160fs3270_save_callback(struct raw3270_request *rq, void *data)
161{
162 struct fs3270 *fp;
163
164 fp = (struct fs3270 *) rq->view;
165
166 /* Correct idal buffer element 0 address. */
167 fp->rdbuf->data[0] -= 5;
168 fp->rdbuf->size += 5;
169
170 /*
171 * If the rdbuf command failed or the idal buffer is
172 * to small for the amount of data returned by the
173 * rdbuf command, then we have no choice but to send
174 * a SIGHUP to the application.
175 */
176 if (rq->rc != 0 || rq->rescnt == 0) {
177 if (fp->fs_pid)
Cedric Le Goater782237a2006-10-02 02:17:28 -0700178 kill_pid(fp->fs_pid, SIGHUP, 1);
Richard Hitted3cb6f2005-10-30 15:00:10 -0800179 fp->rdbuf_size = 0;
180 } else
181 fp->rdbuf_size = fp->rdbuf->size - rq->rescnt;
182 raw3270_request_reset(rq);
183 wake_up(&fp->wait);
184}
185
186static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187fs3270_deactivate(struct raw3270_view *view)
188{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 struct fs3270 *fp;
190
191 fp = (struct fs3270 *) view;
Richard Hitted3cb6f2005-10-30 15:00:10 -0800192 fp->active = 0;
193
194 /* If an old init command is still running just return. */
195 if (!raw3270_request_final(fp->init))
196 return;
197
198 /* Prepare read-buffer request. */
199 raw3270_request_set_cmd(fp->init, TC_RDBUF);
200 /*
201 * Hackish: skip first 5 bytes of the idal buffer to make
202 * room for the TW_KR/TO_SBA/<address>/<address>/TO_IC sequence
203 * in the activation command.
204 */
205 fp->rdbuf->data[0] += 5;
206 fp->rdbuf->size -= 5;
207 raw3270_request_set_idal(fp->init, fp->rdbuf);
208 fp->init->rescnt = 0;
209 fp->init->callback = fs3270_save_callback;
210
211 /* Start I/O to read in the 3270 buffer. */
212 fp->init->rc = raw3270_start_locked(view, fp->init);
213 if (fp->init->rc)
214 fp->init->callback(fp->init, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215}
216
217static int
218fs3270_irq(struct fs3270 *fp, struct raw3270_request *rq, struct irb *irb)
219{
220 /* Handle ATTN. Set indication and wake waiters for attention. */
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200221 if (irb->scsw.cmd.dstat & DEV_STAT_ATTENTION) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 fp->attention = 1;
Richard Hitted3cb6f2005-10-30 15:00:10 -0800223 wake_up(&fp->wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 }
225
226 if (rq) {
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200227 if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 rq->rc = -EIO;
229 else
230 /* Normal end. Copy residual count. */
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200231 rq->rescnt = irb->scsw.cmd.count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 }
233 return RAW3270_IO_DONE;
234}
235
236/*
237 * Process reads from fullscreen 3270.
238 */
239static ssize_t
Heiko Carstensd2c993d2006-07-12 16:41:55 +0200240fs3270_read(struct file *filp, char __user *data, size_t count, loff_t *off)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241{
242 struct fs3270 *fp;
243 struct raw3270_request *rq;
244 struct idal_buffer *ib;
Richard Hitted3cb6f2005-10-30 15:00:10 -0800245 ssize_t rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246
247 if (count == 0 || count > 65535)
248 return -EINVAL;
249 fp = filp->private_data;
250 if (!fp)
251 return -ENODEV;
252 ib = idal_buffer_alloc(count, 0);
Richard Hitted3cb6f2005-10-30 15:00:10 -0800253 if (IS_ERR(ib))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 return -ENOMEM;
255 rq = raw3270_request_alloc(0);
256 if (!IS_ERR(rq)) {
257 if (fp->read_command == 0 && fp->write_command != 0)
258 fp->read_command = 6;
259 raw3270_request_set_cmd(rq, fp->read_command ? : 2);
260 raw3270_request_set_idal(rq, ib);
Richard Hitted3cb6f2005-10-30 15:00:10 -0800261 rc = wait_event_interruptible(fp->wait, fp->attention);
262 fp->attention = 0;
263 if (rc == 0) {
264 rc = fs3270_do_io(&fp->view, rq);
265 if (rc == 0) {
266 count -= rq->rescnt;
267 if (idal_buffer_to_user(ib, data, count) != 0)
268 rc = -EFAULT;
269 else
270 rc = count;
271
272 }
273 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 raw3270_request_free(rq);
275 } else
276 rc = PTR_ERR(rq);
277 idal_buffer_free(ib);
278 return rc;
279}
280
281/*
282 * Process writes to fullscreen 3270.
283 */
284static ssize_t
Heiko Carstensd2c993d2006-07-12 16:41:55 +0200285fs3270_write(struct file *filp, const char __user *data, size_t count, loff_t *off)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286{
287 struct fs3270 *fp;
288 struct raw3270_request *rq;
289 struct idal_buffer *ib;
290 int write_command;
Richard Hitted3cb6f2005-10-30 15:00:10 -0800291 ssize_t rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292
293 fp = filp->private_data;
294 if (!fp)
295 return -ENODEV;
296 ib = idal_buffer_alloc(count, 0);
Richard Hitted3cb6f2005-10-30 15:00:10 -0800297 if (IS_ERR(ib))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 return -ENOMEM;
299 rq = raw3270_request_alloc(0);
300 if (!IS_ERR(rq)) {
301 if (idal_buffer_from_user(ib, data, count) == 0) {
302 write_command = fp->write_command ? : 1;
303 if (write_command == 5)
304 write_command = 13;
305 raw3270_request_set_cmd(rq, write_command);
306 raw3270_request_set_idal(rq, ib);
307 rc = fs3270_do_io(&fp->view, rq);
Richard Hitted3cb6f2005-10-30 15:00:10 -0800308 if (rc == 0)
309 rc = count - rq->rescnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 } else
311 rc = -EFAULT;
312 raw3270_request_free(rq);
313 } else
314 rc = PTR_ERR(rq);
315 idal_buffer_free(ib);
316 return rc;
317}
318
319/*
320 * process ioctl commands for the tube driver
321 */
Christoph Hellwig0f75e002006-01-09 20:52:04 -0800322static long
323fs3270_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324{
325 struct fs3270 *fp;
326 struct raw3270_iocb iocb;
327 int rc;
328
329 fp = filp->private_data;
330 if (!fp)
331 return -ENODEV;
332 rc = 0;
Martin Schwidefsky5cbb5f52009-12-07 12:52:20 +0100333 mutex_lock(&fs3270_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 switch (cmd) {
335 case TUBICMD:
336 fp->read_command = arg;
337 break;
338 case TUBOCMD:
339 fp->write_command = arg;
340 break;
341 case TUBGETI:
Heiko Carstensd2c993d2006-07-12 16:41:55 +0200342 rc = put_user(fp->read_command, (char __user *) arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 break;
344 case TUBGETO:
Heiko Carstensd2c993d2006-07-12 16:41:55 +0200345 rc = put_user(fp->write_command,(char __user *) arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 break;
347 case TUBGETMOD:
348 iocb.model = fp->view.model;
349 iocb.line_cnt = fp->view.rows;
350 iocb.col_cnt = fp->view.cols;
351 iocb.pf_cnt = 24;
352 iocb.re_cnt = 20;
353 iocb.map = 0;
Heiko Carstensd2c993d2006-07-12 16:41:55 +0200354 if (copy_to_user((char __user *) arg, &iocb,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 sizeof(struct raw3270_iocb)))
356 rc = -EFAULT;
357 break;
358 }
Martin Schwidefsky5cbb5f52009-12-07 12:52:20 +0100359 mutex_unlock(&fs3270_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 return rc;
361}
362
363/*
Richard Hitted3cb6f2005-10-30 15:00:10 -0800364 * Allocate fs3270 structure.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 */
366static struct fs3270 *
367fs3270_alloc_view(void)
368{
369 struct fs3270 *fp;
370
Eric Sesterhenn88abaab2006-03-24 03:15:31 -0800371 fp = kzalloc(sizeof(struct fs3270),GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 if (!fp)
373 return ERR_PTR(-ENOMEM);
Richard Hitted3cb6f2005-10-30 15:00:10 -0800374 fp->init = raw3270_request_alloc(0);
375 if (IS_ERR(fp->init)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 kfree(fp);
377 return ERR_PTR(-ENOMEM);
378 }
379 return fp;
380}
381
382/*
Richard Hitted3cb6f2005-10-30 15:00:10 -0800383 * Free fs3270 structure.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 */
385static void
386fs3270_free_view(struct raw3270_view *view)
387{
Richard Hitted3cb6f2005-10-30 15:00:10 -0800388 struct fs3270 *fp;
389
390 fp = (struct fs3270 *) view;
391 if (fp->rdbuf)
392 idal_buffer_free(fp->rdbuf);
393 raw3270_request_free(((struct fs3270 *) view)->init);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 kfree(view);
395}
396
397/*
398 * Unlink fs3270 data structure from filp.
399 */
400static void
401fs3270_release(struct raw3270_view *view)
402{
Martin Schwidefsky4b214a02009-06-16 10:30:47 +0200403 struct fs3270 *fp;
404
405 fp = (struct fs3270 *) view;
406 if (fp->fs_pid)
407 kill_pid(fp->fs_pid, SIGHUP, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408}
409
410/* View to a 3270 device. Can be console, tty or fullscreen. */
Heiko Carstens2b67fc42007-02-05 21:16:47 +0100411static struct raw3270_fn fs3270_fn = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 .activate = fs3270_activate,
413 .deactivate = fs3270_deactivate,
414 .intv = (void *) fs3270_irq,
415 .release = fs3270_release,
416 .free = fs3270_free_view
417};
418
419/*
420 * This routine is called whenever a 3270 fullscreen device is opened.
421 */
422static int
423fs3270_open(struct inode *inode, struct file *filp)
424{
425 struct fs3270 *fp;
Richard Hitted3cb6f2005-10-30 15:00:10 -0800426 struct idal_buffer *ib;
Alan Coxa18992d2008-10-13 10:46:09 +0100427 int minor, rc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428
Josef Sipek49522c92006-12-08 02:37:34 -0800429 if (imajor(filp->f_path.dentry->d_inode) != IBM_FS3270_MAJOR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 return -ENODEV;
Josef Sipek49522c92006-12-08 02:37:34 -0800431 minor = iminor(filp->f_path.dentry->d_inode);
Richard Hitted3cb6f2005-10-30 15:00:10 -0800432 /* Check for minor 0 multiplexer. */
433 if (minor == 0) {
Alan Coxa90610e2008-10-13 10:45:52 +0100434 struct tty_struct *tty = get_current_tty();
Peter Zijlstra24ec8392006-12-08 02:36:04 -0800435 if (!tty || tty->driver->major != IBM_TTY3270_MAJOR) {
Alan Cox452a00d2008-10-13 10:39:13 +0100436 tty_kref_put(tty);
Alan Coxa18992d2008-10-13 10:46:09 +0100437 return -ENODEV;
Peter Zijlstra24ec8392006-12-08 02:36:04 -0800438 }
439 minor = tty->index + RAW3270_FIRSTMINOR;
Alan Cox452a00d2008-10-13 10:39:13 +0100440 tty_kref_put(tty);
Richard Hitted3cb6f2005-10-30 15:00:10 -0800441 }
Martin Schwidefsky5cbb5f52009-12-07 12:52:20 +0100442 mutex_lock(&fs3270_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 /* Check if some other program is already using fullscreen mode. */
444 fp = (struct fs3270 *) raw3270_find_view(&fs3270_fn, minor);
445 if (!IS_ERR(fp)) {
446 raw3270_put_view(&fp->view);
Jonathan Corbet764a4a82008-05-15 10:01:17 -0600447 rc = -EBUSY;
448 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 }
450 /* Allocate fullscreen view structure. */
451 fp = fs3270_alloc_view();
Jonathan Corbet764a4a82008-05-15 10:01:17 -0600452 if (IS_ERR(fp)) {
453 rc = PTR_ERR(fp);
454 goto out;
455 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456
Richard Hitted3cb6f2005-10-30 15:00:10 -0800457 init_waitqueue_head(&fp->wait);
Cedric Le Goater782237a2006-10-02 02:17:28 -0700458 fp->fs_pid = get_pid(task_pid(current));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 rc = raw3270_add_view(&fp->view, &fs3270_fn, minor);
460 if (rc) {
461 fs3270_free_view(&fp->view);
Jonathan Corbet764a4a82008-05-15 10:01:17 -0600462 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 }
464
Richard Hitted3cb6f2005-10-30 15:00:10 -0800465 /* Allocate idal-buffer. */
466 ib = idal_buffer_alloc(2*fp->view.rows*fp->view.cols + 5, 0);
467 if (IS_ERR(ib)) {
468 raw3270_put_view(&fp->view);
469 raw3270_del_view(&fp->view);
Roel Kluin2b310012009-12-18 17:43:19 +0100470 rc = PTR_ERR(ib);
Jonathan Corbet764a4a82008-05-15 10:01:17 -0600471 goto out;
Richard Hitted3cb6f2005-10-30 15:00:10 -0800472 }
473 fp->rdbuf = ib;
474
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 rc = raw3270_activate_view(&fp->view);
476 if (rc) {
Richard Hitted3cb6f2005-10-30 15:00:10 -0800477 raw3270_put_view(&fp->view);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 raw3270_del_view(&fp->view);
Jonathan Corbet764a4a82008-05-15 10:01:17 -0600479 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 }
481 filp->private_data = fp;
Jonathan Corbet764a4a82008-05-15 10:01:17 -0600482out:
Martin Schwidefsky5cbb5f52009-12-07 12:52:20 +0100483 mutex_unlock(&fs3270_mutex);
Alan Coxa18992d2008-10-13 10:46:09 +0100484 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485}
486
487/*
488 * This routine is called when the 3270 tty is closed. We wait
489 * for the remaining request to be completed. Then we clean up.
490 */
491static int
492fs3270_close(struct inode *inode, struct file *filp)
493{
494 struct fs3270 *fp;
495
496 fp = filp->private_data;
Heiko Carstensd2c993d2006-07-12 16:41:55 +0200497 filp->private_data = NULL;
Richard Hitted3cb6f2005-10-30 15:00:10 -0800498 if (fp) {
Cedric Le Goater782237a2006-10-02 02:17:28 -0700499 put_pid(fp->fs_pid);
500 fp->fs_pid = NULL;
Richard Hitted3cb6f2005-10-30 15:00:10 -0800501 raw3270_reset(&fp->view);
502 raw3270_put_view(&fp->view);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 raw3270_del_view(&fp->view);
Richard Hitted3cb6f2005-10-30 15:00:10 -0800504 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 return 0;
506}
507
Arjan van de Vend54b1fd2007-02-12 00:55:34 -0800508static const struct file_operations fs3270_fops = {
Christoph Hellwig0f75e002006-01-09 20:52:04 -0800509 .owner = THIS_MODULE, /* owner */
510 .read = fs3270_read, /* read */
511 .write = fs3270_write, /* write */
512 .unlocked_ioctl = fs3270_ioctl, /* ioctl */
513 .compat_ioctl = fs3270_ioctl, /* ioctl */
514 .open = fs3270_open, /* open */
515 .release = fs3270_close, /* release */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516};
517
518/*
519 * 3270 fullscreen driver initialization.
520 */
521static int __init
522fs3270_init(void)
523{
524 int rc;
525
526 rc = register_chrdev(IBM_FS3270_MAJOR, "fs3270", &fs3270_fops);
Martin Schwidefskya26182e2008-07-14 09:59:25 +0200527 if (rc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 return 0;
530}
531
532static void __exit
533fs3270_exit(void)
534{
535 unregister_chrdev(IBM_FS3270_MAJOR, "fs3270");
536}
537
538MODULE_LICENSE("GPL");
539MODULE_ALIAS_CHARDEV_MAJOR(IBM_FS3270_MAJOR);
540
541module_init(fs3270_init);
542module_exit(fs3270_exit);