xref: /linux/drivers/s390/char/raw3270.h (revision 45d8b572fac3aa8b49d53c946b3685eaf78a2824)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * IBM/3270 Driver
4  *
5  * Author(s):
6  *   Original 3270 Code for 2.4 written by Richard Hitt (UTS Global)
7  *   Rewritten for 2.5 by Martin Schwidefsky <schwidefsky@de.ibm.com>
8  *     Copyright IBM Corp. 2003, 2009
9  */
10 
11 #include <uapi/asm/raw3270.h>
12 #include <asm/idals.h>
13 #include <asm/ioctl.h>
14 
15 struct raw3270;
16 struct raw3270_view;
17 extern const struct class class3270;
18 
19 /* 3270 CCW request */
20 struct raw3270_request {
21 	struct list_head list;		/* list head for request queueing. */
22 	struct raw3270_view *view;	/* view of this request */
23 	struct ccw1 ccw;		/* single ccw. */
24 	void *buffer;			/* output buffer. */
25 	size_t size;			/* size of output buffer. */
26 	int rescnt;			/* residual count from devstat. */
27 	int rc;				/* return code for this request. */
28 
29 	/* Callback for delivering final status. */
30 	void (*callback)(struct raw3270_request *rq, void *data);
31 	void *callback_data;
32 };
33 
34 struct raw3270_request *raw3270_request_alloc(size_t size);
35 void raw3270_request_free(struct raw3270_request *rq);
36 int raw3270_request_reset(struct raw3270_request *rq);
37 void raw3270_request_set_cmd(struct raw3270_request *rq, u8 cmd);
38 int  raw3270_request_add_data(struct raw3270_request *rq, void *data, size_t size);
39 void raw3270_request_set_data(struct raw3270_request *rq, void *data, size_t size);
40 void raw3270_request_set_idal(struct raw3270_request *rq, struct idal_buffer *ib);
41 
42 static inline int
43 raw3270_request_final(struct raw3270_request *rq)
44 {
45 	return list_empty(&rq->list);
46 }
47 
48 void raw3270_buffer_address(struct raw3270 *, char *, int, int);
49 
50 /*
51  * Functions of a 3270 view.
52  */
53 struct raw3270_fn {
54 	int  (*activate)(struct raw3270_view *rq);
55 	void (*deactivate)(struct raw3270_view *rq);
56 	void (*intv)(struct raw3270_view *view,
57 		     struct raw3270_request *rq, struct irb *ib);
58 	void (*release)(struct raw3270_view *view);
59 	void (*free)(struct raw3270_view *view);
60 	void (*resize)(struct raw3270_view *view,
61 		       int new_model, int new_cols, int new_rows,
62 		       int old_model, int old_cols, int old_rows);
63 };
64 
65 /*
66  * View structure chaining. The raw3270_view structure is meant to
67  * be embedded at the start of the real view data structure, e.g.:
68  *   struct example {
69  *     struct raw3270_view view;
70  *     ...
71  *   };
72  */
73 struct raw3270_view {
74 	struct list_head list;
75 	spinlock_t lock; /* protects members of view */
76 #define RAW3270_VIEW_LOCK_IRQ	0
77 #define RAW3270_VIEW_LOCK_BH	1
78 	atomic_t ref_count;
79 	struct raw3270 *dev;
80 	struct raw3270_fn *fn;
81 	unsigned int model;
82 	unsigned int rows, cols;	/* # of rows & colums of the view */
83 	unsigned char *ascebc;		/* ascii -> ebcdic table */
84 };
85 
86 int raw3270_add_view(struct raw3270_view *view, struct raw3270_fn *fn, int minor, int subclass);
87 int raw3270_view_lock_unavailable(struct raw3270_view *view);
88 int raw3270_activate_view(struct raw3270_view *view);
89 void raw3270_del_view(struct raw3270_view *view);
90 void raw3270_deactivate_view(struct raw3270_view *view);
91 struct raw3270_view *raw3270_find_view(struct raw3270_fn *fn, int minor);
92 int raw3270_start(struct raw3270_view *view, struct raw3270_request *rq);
93 int raw3270_start_locked(struct raw3270_view *view, struct raw3270_request *rq);
94 int raw3270_start_irq(struct raw3270_view *view, struct raw3270_request *rq);
95 int raw3270_reset(struct raw3270_view *view);
96 struct raw3270_view *raw3270_view(struct raw3270_view *view);
97 int raw3270_view_active(struct raw3270_view *view);
98 int raw3270_start_request(struct raw3270_view *view, struct raw3270_request *rq,
99 			  int cmd, void *data, size_t len);
100 void raw3270_read_modified_cb(struct raw3270_request *rq, void *data);
101 
102 /* Reference count inliner for view structures. */
103 static inline void
104 raw3270_get_view(struct raw3270_view *view)
105 {
106 	atomic_inc(&view->ref_count);
107 }
108 
109 extern wait_queue_head_t raw3270_wait_queue;
110 
111 static inline void
112 raw3270_put_view(struct raw3270_view *view)
113 {
114 	if (atomic_dec_return(&view->ref_count) == 0)
115 		wake_up(&raw3270_wait_queue);
116 }
117 
118 struct raw3270 *raw3270_setup_console(void);
119 void raw3270_wait_cons_dev(struct raw3270 *rp);
120 
121 /* Notifier for device addition/removal */
122 struct raw3270_notifier {
123 	struct list_head list;
124 	void (*create)(int minor);
125 	void (*destroy)(int minor);
126 };
127 
128 int raw3270_register_notifier(struct raw3270_notifier *notifier);
129 void raw3270_unregister_notifier(struct raw3270_notifier *notifier);
130