Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * IBM/3270 Driver - fullscreen driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Author(s):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *   Original 3270 Code for 2.4 written by Richard Hitt (UTS Global)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *   Rewritten for 2.5/2.6 by Martin Schwidefsky <schwidefsky@de.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *     Copyright IBM Corp. 2003, 2009
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/memblock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/console.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/compat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/sched/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <asm/ccwdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <asm/cio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <asm/ebcdic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <asm/idals.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include "raw3270.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include "ctrlchar.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) static struct raw3270_fn fs3270_fn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) struct fs3270 {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	struct raw3270_view view;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	struct pid *fs_pid;		/* Pid of controlling program. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	int read_command;		/* ccw command to use for reads. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	int write_command;		/* ccw command to use for writes. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	int attention;			/* Got attention. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	int active;			/* Fullscreen view is active. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	struct raw3270_request *init;	/* single init request. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	wait_queue_head_t wait;		/* Init & attention wait queue. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	struct idal_buffer *rdbuf;	/* full-screen-deactivate buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	size_t rdbuf_size;		/* size of data returned by RDBUF */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) static DEFINE_MUTEX(fs3270_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) fs3270_wake_up(struct raw3270_request *rq, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	wake_up((wait_queue_head_t *) data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) static inline int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) fs3270_working(struct fs3270 *fp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	 * The fullscreen view is in working order if the view
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	 * has been activated AND the initial request is finished.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	return fp->active && raw3270_request_final(fp->init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) fs3270_do_io(struct raw3270_view *view, struct raw3270_request *rq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	struct fs3270 *fp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	fp = (struct fs3270 *) view;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	rq->callback = fs3270_wake_up;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	rq->callback_data = &fp->wait;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		if (!fs3270_working(fp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 			/* Fullscreen view isn't ready yet. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 			rc = wait_event_interruptible(fp->wait,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 						      fs3270_working(fp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 			if (rc != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		rc = raw3270_start(view, rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		if (rc == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 			/* Started successfully. Now wait for completion. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 			wait_event(fp->wait, raw3270_request_final(rq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	} while (rc == -EACCES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91)  * Switch to the fullscreen view.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) fs3270_reset_callback(struct raw3270_request *rq, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	struct fs3270 *fp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	fp = (struct fs3270 *) rq->view;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	raw3270_request_reset(rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	wake_up(&fp->wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) fs3270_restore_callback(struct raw3270_request *rq, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	struct fs3270 *fp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	fp = (struct fs3270 *) rq->view;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	if (rq->rc != 0 || rq->rescnt != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		if (fp->fs_pid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 			kill_pid(fp->fs_pid, SIGHUP, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	fp->rdbuf_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	raw3270_request_reset(rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	wake_up(&fp->wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) fs3270_activate(struct raw3270_view *view)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	struct fs3270 *fp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	char *cp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	fp = (struct fs3270 *) view;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	/* If an old init command is still running just return. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	if (!raw3270_request_final(fp->init))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	if (fp->rdbuf_size == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		/* No saved buffer. Just clear the screen. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		raw3270_request_set_cmd(fp->init, TC_EWRITEA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		fp->init->callback = fs3270_reset_callback;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		/* Restore fullscreen buffer saved by fs3270_deactivate. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		raw3270_request_set_cmd(fp->init, TC_EWRITEA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		raw3270_request_set_idal(fp->init, fp->rdbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		fp->init->ccw.count = fp->rdbuf_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		cp = fp->rdbuf->data[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		cp[0] = TW_KR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		cp[1] = TO_SBA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		cp[2] = cp[6];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		cp[3] = cp[7];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		cp[4] = TO_IC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		cp[5] = TO_SBA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		cp[6] = 0x40;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		cp[7] = 0x40;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		fp->init->rescnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		fp->init->callback = fs3270_restore_callback;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	rc = fp->init->rc = raw3270_start_locked(view, fp->init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		fp->init->callback(fp->init, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		fp->active = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)  * Shutdown fullscreen view.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) fs3270_save_callback(struct raw3270_request *rq, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	struct fs3270 *fp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	fp = (struct fs3270 *) rq->view;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	/* Correct idal buffer element 0 address. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	fp->rdbuf->data[0] -= 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	fp->rdbuf->size += 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	 * If the rdbuf command failed or the idal buffer is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	 * to small for the amount of data returned by the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	 * rdbuf command, then we have no choice but to send
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	 * a SIGHUP to the application.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	if (rq->rc != 0 || rq->rescnt == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		if (fp->fs_pid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 			kill_pid(fp->fs_pid, SIGHUP, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		fp->rdbuf_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		fp->rdbuf_size = fp->rdbuf->size - rq->rescnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	raw3270_request_reset(rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	wake_up(&fp->wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) fs3270_deactivate(struct raw3270_view *view)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	struct fs3270 *fp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	fp = (struct fs3270 *) view;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	fp->active = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	/* If an old init command is still running just return. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	if (!raw3270_request_final(fp->init))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	/* Prepare read-buffer request. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	raw3270_request_set_cmd(fp->init, TC_RDBUF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	 * Hackish: skip first 5 bytes of the idal buffer to make
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	 * room for the TW_KR/TO_SBA/<address>/<address>/TO_IC sequence
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	 * in the activation command.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	fp->rdbuf->data[0] += 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	fp->rdbuf->size -= 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	raw3270_request_set_idal(fp->init, fp->rdbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	fp->init->rescnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	fp->init->callback = fs3270_save_callback;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	/* Start I/O to read in the 3270 buffer. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	fp->init->rc = raw3270_start_locked(view, fp->init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	if (fp->init->rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		fp->init->callback(fp->init, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) fs3270_irq(struct fs3270 *fp, struct raw3270_request *rq, struct irb *irb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	/* Handle ATTN. Set indication and wake waiters for attention. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	if (irb->scsw.cmd.dstat & DEV_STAT_ATTENTION) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		fp->attention = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		wake_up(&fp->wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	if (rq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 			rq->rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 			/* Normal end. Copy residual count. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 			rq->rescnt = irb->scsw.cmd.count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)  * Process reads from fullscreen 3270.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) fs3270_read(struct file *filp, char __user *data, size_t count, loff_t *off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	struct fs3270 *fp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	struct raw3270_request *rq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	struct idal_buffer *ib;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	ssize_t rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	if (count == 0 || count > 65535)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	fp = filp->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	if (!fp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	ib = idal_buffer_alloc(count, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	if (IS_ERR(ib))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	rq = raw3270_request_alloc(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	if (!IS_ERR(rq)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		if (fp->read_command == 0 && fp->write_command != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 			fp->read_command = 6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		raw3270_request_set_cmd(rq, fp->read_command ? : 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		raw3270_request_set_idal(rq, ib);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		rc = wait_event_interruptible(fp->wait, fp->attention);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		fp->attention = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		if (rc == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 			rc = fs3270_do_io(&fp->view, rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 			if (rc == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 				count -= rq->rescnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 				if (idal_buffer_to_user(ib, data, count) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 					rc = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 				else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 					rc = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		raw3270_request_free(rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 		rc = PTR_ERR(rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	idal_buffer_free(ib);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)  * Process writes to fullscreen 3270.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) fs3270_write(struct file *filp, const char __user *data, size_t count, loff_t *off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	struct fs3270 *fp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	struct raw3270_request *rq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	struct idal_buffer *ib;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	int write_command;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	ssize_t rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	fp = filp->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	if (!fp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	ib = idal_buffer_alloc(count, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	if (IS_ERR(ib))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	rq = raw3270_request_alloc(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	if (!IS_ERR(rq)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 		if (idal_buffer_from_user(ib, data, count) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 			write_command = fp->write_command ? : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 			if (write_command == 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 				write_command = 13;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 			raw3270_request_set_cmd(rq, write_command);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 			raw3270_request_set_idal(rq, ib);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 			rc = fs3270_do_io(&fp->view, rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 			if (rc == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 				rc = count - rq->rescnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 			rc = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 		raw3270_request_free(rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 		rc = PTR_ERR(rq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	idal_buffer_free(ib);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)  * process ioctl commands for the tube driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) static long
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) fs3270_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	char __user *argp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	struct fs3270 *fp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	struct raw3270_iocb iocb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	fp = filp->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	if (!fp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	if (is_compat_task())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 		argp = compat_ptr(arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 		argp = (char __user *)arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	mutex_lock(&fs3270_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	case TUBICMD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 		fp->read_command = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	case TUBOCMD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 		fp->write_command = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	case TUBGETI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 		rc = put_user(fp->read_command, argp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	case TUBGETO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 		rc = put_user(fp->write_command, argp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	case TUBGETMOD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 		iocb.model = fp->view.model;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 		iocb.line_cnt = fp->view.rows;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 		iocb.col_cnt = fp->view.cols;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 		iocb.pf_cnt = 24;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 		iocb.re_cnt = 20;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 		iocb.map = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 		if (copy_to_user(argp, &iocb, sizeof(struct raw3270_iocb)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 			rc = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	mutex_unlock(&fs3270_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371)  * Allocate fs3270 structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) static struct fs3270 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) fs3270_alloc_view(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	struct fs3270 *fp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	fp = kzalloc(sizeof(struct fs3270),GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	if (!fp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 		return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	fp->init = raw3270_request_alloc(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	if (IS_ERR(fp->init)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 		kfree(fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 		return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	return fp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)  * Free fs3270 structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) fs3270_free_view(struct raw3270_view *view)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	struct fs3270 *fp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	fp = (struct fs3270 *) view;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	if (fp->rdbuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 		idal_buffer_free(fp->rdbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	raw3270_request_free(((struct fs3270 *) view)->init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	kfree(view);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)  * Unlink fs3270 data structure from filp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) fs3270_release(struct raw3270_view *view)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	struct fs3270 *fp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	fp = (struct fs3270 *) view;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	if (fp->fs_pid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 		kill_pid(fp->fs_pid, SIGHUP, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) /* View to a 3270 device. Can be console, tty or fullscreen. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) static struct raw3270_fn fs3270_fn = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	.activate = fs3270_activate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	.deactivate = fs3270_deactivate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	.intv = (void *) fs3270_irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	.release = fs3270_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	.free = fs3270_free_view
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)  * This routine is called whenever a 3270 fullscreen device is opened.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) fs3270_open(struct inode *inode, struct file *filp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	struct fs3270 *fp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	struct idal_buffer *ib;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	int minor, rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	if (imajor(file_inode(filp)) != IBM_FS3270_MAJOR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	minor = iminor(file_inode(filp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	/* Check for minor 0 multiplexer. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	if (minor == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 		struct tty_struct *tty = get_current_tty();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 		if (!tty || tty->driver->major != IBM_TTY3270_MAJOR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 			tty_kref_put(tty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 			return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 		minor = tty->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 		tty_kref_put(tty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	mutex_lock(&fs3270_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	/* Check if some other program is already using fullscreen mode. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	fp = (struct fs3270 *) raw3270_find_view(&fs3270_fn, minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	if (!IS_ERR(fp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 		raw3270_put_view(&fp->view);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 		rc = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	/* Allocate fullscreen view structure. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	fp = fs3270_alloc_view();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	if (IS_ERR(fp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 		rc = PTR_ERR(fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	init_waitqueue_head(&fp->wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	fp->fs_pid = get_pid(task_pid(current));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	rc = raw3270_add_view(&fp->view, &fs3270_fn, minor,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 			      RAW3270_VIEW_LOCK_BH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 		fs3270_free_view(&fp->view);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 	/* Allocate idal-buffer. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	ib = idal_buffer_alloc(2*fp->view.rows*fp->view.cols + 5, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	if (IS_ERR(ib)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 		raw3270_put_view(&fp->view);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 		raw3270_del_view(&fp->view);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 		rc = PTR_ERR(ib);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	fp->rdbuf = ib;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	rc = raw3270_activate_view(&fp->view);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 		raw3270_put_view(&fp->view);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 		raw3270_del_view(&fp->view);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 	stream_open(inode, filp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 	filp->private_data = fp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 	mutex_unlock(&fs3270_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497)  * This routine is called when the 3270 tty is closed. We wait
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498)  * for the remaining request to be completed. Then we clean up.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) fs3270_close(struct inode *inode, struct file *filp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	struct fs3270 *fp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 	fp = filp->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 	filp->private_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 	if (fp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 		put_pid(fp->fs_pid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 		fp->fs_pid = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 		raw3270_reset(&fp->view);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 		raw3270_put_view(&fp->view);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 		raw3270_del_view(&fp->view);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) static const struct file_operations fs3270_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 	.owner		 = THIS_MODULE,		/* owner */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 	.read		 = fs3270_read,		/* read */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 	.write		 = fs3270_write,	/* write */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 	.unlocked_ioctl	 = fs3270_ioctl,	/* ioctl */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 	.compat_ioctl	 = fs3270_ioctl,	/* ioctl */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 	.open		 = fs3270_open,		/* open */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 	.release	 = fs3270_close,	/* release */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 	.llseek		= no_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) static void fs3270_create_cb(int minor)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 	__register_chrdev(IBM_FS3270_MAJOR, minor, 1, "tub", &fs3270_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 	device_create(class3270, NULL, MKDEV(IBM_FS3270_MAJOR, minor),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 		      NULL, "3270/tub%d", minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) static void fs3270_destroy_cb(int minor)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 	device_destroy(class3270, MKDEV(IBM_FS3270_MAJOR, minor));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 	__unregister_chrdev(IBM_FS3270_MAJOR, minor, 1, "tub");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) static struct raw3270_notifier fs3270_notifier =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 	.create = fs3270_create_cb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 	.destroy = fs3270_destroy_cb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548)  * 3270 fullscreen driver initialization.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) static int __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) fs3270_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 	rc = __register_chrdev(IBM_FS3270_MAJOR, 0, 1, "fs3270", &fs3270_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 	device_create(class3270, NULL, MKDEV(IBM_FS3270_MAJOR, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 		      NULL, "3270/tub");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 	raw3270_register_notifier(&fs3270_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) static void __exit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) fs3270_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 	raw3270_unregister_notifier(&fs3270_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 	device_destroy(class3270, MKDEV(IBM_FS3270_MAJOR, 0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 	__unregister_chrdev(IBM_FS3270_MAJOR, 0, 1, "fs3270");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) MODULE_ALIAS_CHARDEV_MAJOR(IBM_FS3270_MAJOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) module_init(fs3270_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) module_exit(fs3270_exit);