tty3270.c 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918
  1. /*
  2. * IBM/3270 Driver - tty functions.
  3. *
  4. * Author(s):
  5. * Original 3270 Code for 2.4 written by Richard Hitt (UTS Global)
  6. * Rewritten for 2.5 by Martin Schwidefsky <schwidefsky@de.ibm.com>
  7. * -- Copyright IBM Corp. 2003
  8. */
  9. #include <linux/module.h>
  10. #include <linux/types.h>
  11. #include <linux/kdev_t.h>
  12. #include <linux/tty.h>
  13. #include <linux/vt_kern.h>
  14. #include <linux/init.h>
  15. #include <linux/console.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/workqueue.h>
  18. #include <linux/slab.h>
  19. #include <linux/bootmem.h>
  20. #include <linux/compat.h>
  21. #include <asm/ccwdev.h>
  22. #include <asm/cio.h>
  23. #include <asm/ebcdic.h>
  24. #include <asm/uaccess.h>
  25. #include "raw3270.h"
  26. #include "tty3270.h"
  27. #include "keyboard.h"
  28. #define TTY3270_CHAR_BUF_SIZE 256
  29. #define TTY3270_OUTPUT_BUFFER_SIZE 1024
  30. #define TTY3270_STRING_PAGES 5
  31. struct tty_driver *tty3270_driver;
  32. static int tty3270_max_index;
  33. static struct raw3270_fn tty3270_fn;
  34. struct tty3270_cell {
  35. unsigned char character;
  36. unsigned char highlight;
  37. unsigned char f_color;
  38. };
  39. struct tty3270_line {
  40. struct tty3270_cell *cells;
  41. int len;
  42. };
  43. #define ESCAPE_NPAR 8
  44. /*
  45. * The main tty view data structure.
  46. * FIXME:
  47. * 1) describe line orientation & lines list concept against screen
  48. * 2) describe conversion of screen to lines
  49. * 3) describe line format.
  50. */
  51. struct tty3270 {
  52. struct raw3270_view view;
  53. struct tty_port port;
  54. void **freemem_pages; /* Array of pages used for freemem. */
  55. struct list_head freemem; /* List of free memory for strings. */
  56. /* Output stuff. */
  57. struct list_head lines; /* List of lines. */
  58. struct list_head update; /* List of lines to update. */
  59. unsigned char wcc; /* Write control character. */
  60. int nr_lines; /* # lines in list. */
  61. int nr_up; /* # lines up in history. */
  62. unsigned long update_flags; /* Update indication bits. */
  63. struct string *status; /* Lower right of display. */
  64. struct raw3270_request *write; /* Single write request. */
  65. struct timer_list timer; /* Output delay timer. */
  66. /* Current tty screen. */
  67. unsigned int cx, cy; /* Current output position. */
  68. unsigned int highlight; /* Blink/reverse/underscore */
  69. unsigned int f_color; /* Foreground color */
  70. struct tty3270_line *screen;
  71. unsigned int n_model, n_cols, n_rows; /* New model & size */
  72. struct work_struct resize_work;
  73. /* Input stuff. */
  74. struct string *prompt; /* Output string for input area. */
  75. struct string *input; /* Input string for read request. */
  76. struct raw3270_request *read; /* Single read request. */
  77. struct raw3270_request *kreset; /* Single keyboard reset request. */
  78. unsigned char inattr; /* Visible/invisible input. */
  79. int throttle, attn; /* tty throttle/unthrottle. */
  80. struct tasklet_struct readlet; /* Tasklet to issue read request. */
  81. struct kbd_data *kbd; /* key_maps stuff. */
  82. /* Escape sequence parsing. */
  83. int esc_state, esc_ques, esc_npar;
  84. int esc_par[ESCAPE_NPAR];
  85. unsigned int saved_cx, saved_cy;
  86. unsigned int saved_highlight, saved_f_color;
  87. /* Command recalling. */
  88. struct list_head rcl_lines; /* List of recallable lines. */
  89. struct list_head *rcl_walk; /* Point in rcl_lines list. */
  90. int rcl_nr, rcl_max; /* Number/max number of rcl_lines. */
  91. /* Character array for put_char/flush_chars. */
  92. unsigned int char_count;
  93. char char_buf[TTY3270_CHAR_BUF_SIZE];
  94. };
  95. /* tty3270->update_flags. See tty3270_update for details. */
  96. #define TTY_UPDATE_ERASE 1 /* Use EWRITEA instead of WRITE. */
  97. #define TTY_UPDATE_LIST 2 /* Update lines in tty3270->update. */
  98. #define TTY_UPDATE_INPUT 4 /* Update input line. */
  99. #define TTY_UPDATE_STATUS 8 /* Update status line. */
  100. #define TTY_UPDATE_ALL 16 /* Recreate screen. */
  101. static void tty3270_update(struct tty3270 *);
  102. static void tty3270_resize_work(struct work_struct *work);
  103. /*
  104. * Setup timeout for a device. On timeout trigger an update.
  105. */
  106. static void tty3270_set_timer(struct tty3270 *tp, int expires)
  107. {
  108. mod_timer(&tp->timer, jiffies + expires);
  109. }
  110. /*
  111. * The input line are the two last lines of the screen.
  112. */
  113. static void
  114. tty3270_update_prompt(struct tty3270 *tp, char *input, int count)
  115. {
  116. struct string *line;
  117. unsigned int off;
  118. line = tp->prompt;
  119. if (count != 0)
  120. line->string[5] = TF_INMDT;
  121. else
  122. line->string[5] = tp->inattr;
  123. if (count > tp->view.cols * 2 - 11)
  124. count = tp->view.cols * 2 - 11;
  125. memcpy(line->string + 6, input, count);
  126. line->string[6 + count] = TO_IC;
  127. /* Clear to end of input line. */
  128. if (count < tp->view.cols * 2 - 11) {
  129. line->string[7 + count] = TO_RA;
  130. line->string[10 + count] = 0;
  131. off = tp->view.cols * tp->view.rows - 9;
  132. raw3270_buffer_address(tp->view.dev, line->string+count+8, off);
  133. line->len = 11 + count;
  134. } else
  135. line->len = 7 + count;
  136. tp->update_flags |= TTY_UPDATE_INPUT;
  137. }
  138. static void
  139. tty3270_create_prompt(struct tty3270 *tp)
  140. {
  141. static const unsigned char blueprint[] =
  142. { TO_SBA, 0, 0, 0x6e, TO_SF, TF_INPUT,
  143. /* empty input string */
  144. TO_IC, TO_RA, 0, 0, 0 };
  145. struct string *line;
  146. unsigned int offset;
  147. line = alloc_string(&tp->freemem,
  148. sizeof(blueprint) + tp->view.cols * 2 - 9);
  149. tp->prompt = line;
  150. tp->inattr = TF_INPUT;
  151. /* Copy blueprint to status line */
  152. memcpy(line->string, blueprint, sizeof(blueprint));
  153. line->len = sizeof(blueprint);
  154. /* Set output offsets. */
  155. offset = tp->view.cols * (tp->view.rows - 2);
  156. raw3270_buffer_address(tp->view.dev, line->string + 1, offset);
  157. offset = tp->view.cols * tp->view.rows - 9;
  158. raw3270_buffer_address(tp->view.dev, line->string + 8, offset);
  159. /* Allocate input string for reading. */
  160. tp->input = alloc_string(&tp->freemem, tp->view.cols * 2 - 9 + 6);
  161. }
  162. /*
  163. * The status line is the last line of the screen. It shows the string
  164. * "Running"/"Holding" in the lower right corner of the screen.
  165. */
  166. static void
  167. tty3270_update_status(struct tty3270 * tp)
  168. {
  169. char *str;
  170. str = (tp->nr_up != 0) ? "History" : "Running";
  171. memcpy(tp->status->string + 8, str, 7);
  172. codepage_convert(tp->view.ascebc, tp->status->string + 8, 7);
  173. tp->update_flags |= TTY_UPDATE_STATUS;
  174. }
  175. static void
  176. tty3270_create_status(struct tty3270 * tp)
  177. {
  178. static const unsigned char blueprint[] =
  179. { TO_SBA, 0, 0, TO_SF, TF_LOG, TO_SA, TAT_COLOR, TAC_GREEN,
  180. 0, 0, 0, 0, 0, 0, 0, TO_SF, TF_LOG, TO_SA, TAT_COLOR,
  181. TAC_RESET };
  182. struct string *line;
  183. unsigned int offset;
  184. line = alloc_string(&tp->freemem,sizeof(blueprint));
  185. tp->status = line;
  186. /* Copy blueprint to status line */
  187. memcpy(line->string, blueprint, sizeof(blueprint));
  188. /* Set address to start of status string (= last 9 characters). */
  189. offset = tp->view.cols * tp->view.rows - 9;
  190. raw3270_buffer_address(tp->view.dev, line->string + 1, offset);
  191. }
  192. /*
  193. * Set output offsets to 3270 datastream fragment of a tty string.
  194. * (TO_SBA offset at the start and TO_RA offset at the end of the string)
  195. */
  196. static void
  197. tty3270_update_string(struct tty3270 *tp, struct string *line, int nr)
  198. {
  199. unsigned char *cp;
  200. raw3270_buffer_address(tp->view.dev, line->string + 1,
  201. tp->view.cols * nr);
  202. cp = line->string + line->len - 4;
  203. if (*cp == TO_RA)
  204. raw3270_buffer_address(tp->view.dev, cp + 1,
  205. tp->view.cols * (nr + 1));
  206. }
  207. /*
  208. * Rebuild update list to print all lines.
  209. */
  210. static void
  211. tty3270_rebuild_update(struct tty3270 *tp)
  212. {
  213. struct string *s, *n;
  214. int line, nr_up;
  215. /*
  216. * Throw away update list and create a new one,
  217. * containing all lines that will fit on the screen.
  218. */
  219. list_for_each_entry_safe(s, n, &tp->update, update)
  220. list_del_init(&s->update);
  221. line = tp->view.rows - 3;
  222. nr_up = tp->nr_up;
  223. list_for_each_entry_reverse(s, &tp->lines, list) {
  224. if (nr_up > 0) {
  225. nr_up--;
  226. continue;
  227. }
  228. tty3270_update_string(tp, s, line);
  229. list_add(&s->update, &tp->update);
  230. if (--line < 0)
  231. break;
  232. }
  233. tp->update_flags |= TTY_UPDATE_LIST;
  234. }
  235. /*
  236. * Alloc string for size bytes. If there is not enough room in
  237. * freemem, free strings until there is room.
  238. */
  239. static struct string *
  240. tty3270_alloc_string(struct tty3270 *tp, size_t size)
  241. {
  242. struct string *s, *n;
  243. s = alloc_string(&tp->freemem, size);
  244. if (s)
  245. return s;
  246. list_for_each_entry_safe(s, n, &tp->lines, list) {
  247. BUG_ON(tp->nr_lines <= tp->view.rows - 2);
  248. list_del(&s->list);
  249. if (!list_empty(&s->update))
  250. list_del(&s->update);
  251. tp->nr_lines--;
  252. if (free_string(&tp->freemem, s) >= size)
  253. break;
  254. }
  255. s = alloc_string(&tp->freemem, size);
  256. BUG_ON(!s);
  257. if (tp->nr_up != 0 &&
  258. tp->nr_up + tp->view.rows - 2 >= tp->nr_lines) {
  259. tp->nr_up = tp->nr_lines - tp->view.rows + 2;
  260. tty3270_rebuild_update(tp);
  261. tty3270_update_status(tp);
  262. }
  263. return s;
  264. }
  265. /*
  266. * Add an empty line to the list.
  267. */
  268. static void
  269. tty3270_blank_line(struct tty3270 *tp)
  270. {
  271. static const unsigned char blueprint[] =
  272. { TO_SBA, 0, 0, TO_SA, TAT_EXTHI, TAX_RESET,
  273. TO_SA, TAT_COLOR, TAC_RESET, TO_RA, 0, 0, 0 };
  274. struct string *s;
  275. s = tty3270_alloc_string(tp, sizeof(blueprint));
  276. memcpy(s->string, blueprint, sizeof(blueprint));
  277. s->len = sizeof(blueprint);
  278. list_add_tail(&s->list, &tp->lines);
  279. tp->nr_lines++;
  280. if (tp->nr_up != 0)
  281. tp->nr_up++;
  282. }
  283. /*
  284. * Write request completion callback.
  285. */
  286. static void
  287. tty3270_write_callback(struct raw3270_request *rq, void *data)
  288. {
  289. struct tty3270 *tp = container_of(rq->view, struct tty3270, view);
  290. if (rq->rc != 0) {
  291. /* Write wasn't successful. Refresh all. */
  292. tp->update_flags = TTY_UPDATE_ALL;
  293. tty3270_set_timer(tp, 1);
  294. }
  295. raw3270_request_reset(rq);
  296. xchg(&tp->write, rq);
  297. }
  298. /*
  299. * Update 3270 display.
  300. */
  301. static void
  302. tty3270_update(struct tty3270 *tp)
  303. {
  304. static char invalid_sba[2] = { 0xff, 0xff };
  305. struct raw3270_request *wrq;
  306. unsigned long updated;
  307. struct string *s, *n;
  308. char *sba, *str;
  309. int rc, len;
  310. wrq = xchg(&tp->write, 0);
  311. if (!wrq) {
  312. tty3270_set_timer(tp, 1);
  313. return;
  314. }
  315. spin_lock(&tp->view.lock);
  316. updated = 0;
  317. if (tp->update_flags & TTY_UPDATE_ALL) {
  318. tty3270_rebuild_update(tp);
  319. tty3270_update_status(tp);
  320. tp->update_flags = TTY_UPDATE_ERASE | TTY_UPDATE_LIST |
  321. TTY_UPDATE_INPUT | TTY_UPDATE_STATUS;
  322. }
  323. if (tp->update_flags & TTY_UPDATE_ERASE) {
  324. /* Use erase write alternate to erase display. */
  325. raw3270_request_set_cmd(wrq, TC_EWRITEA);
  326. updated |= TTY_UPDATE_ERASE;
  327. } else
  328. raw3270_request_set_cmd(wrq, TC_WRITE);
  329. raw3270_request_add_data(wrq, &tp->wcc, 1);
  330. tp->wcc = TW_NONE;
  331. /*
  332. * Update status line.
  333. */
  334. if (tp->update_flags & TTY_UPDATE_STATUS)
  335. if (raw3270_request_add_data(wrq, tp->status->string,
  336. tp->status->len) == 0)
  337. updated |= TTY_UPDATE_STATUS;
  338. /*
  339. * Write input line.
  340. */
  341. if (tp->update_flags & TTY_UPDATE_INPUT)
  342. if (raw3270_request_add_data(wrq, tp->prompt->string,
  343. tp->prompt->len) == 0)
  344. updated |= TTY_UPDATE_INPUT;
  345. sba = invalid_sba;
  346. if (tp->update_flags & TTY_UPDATE_LIST) {
  347. /* Write strings in the update list to the screen. */
  348. list_for_each_entry_safe(s, n, &tp->update, update) {
  349. str = s->string;
  350. len = s->len;
  351. /*
  352. * Skip TO_SBA at the start of the string if the
  353. * last output position matches the start address
  354. * of this line.
  355. */
  356. if (s->string[1] == sba[0] && s->string[2] == sba[1])
  357. str += 3, len -= 3;
  358. if (raw3270_request_add_data(wrq, str, len) != 0)
  359. break;
  360. list_del_init(&s->update);
  361. sba = s->string + s->len - 3;
  362. }
  363. if (list_empty(&tp->update))
  364. updated |= TTY_UPDATE_LIST;
  365. }
  366. wrq->callback = tty3270_write_callback;
  367. rc = raw3270_start(&tp->view, wrq);
  368. if (rc == 0) {
  369. tp->update_flags &= ~updated;
  370. if (tp->update_flags)
  371. tty3270_set_timer(tp, 1);
  372. } else {
  373. raw3270_request_reset(wrq);
  374. xchg(&tp->write, wrq);
  375. }
  376. spin_unlock(&tp->view.lock);
  377. }
  378. /*
  379. * Command recalling.
  380. */
  381. static void
  382. tty3270_rcl_add(struct tty3270 *tp, char *input, int len)
  383. {
  384. struct string *s;
  385. tp->rcl_walk = NULL;
  386. if (len <= 0)
  387. return;
  388. if (tp->rcl_nr >= tp->rcl_max) {
  389. s = list_entry(tp->rcl_lines.next, struct string, list);
  390. list_del(&s->list);
  391. free_string(&tp->freemem, s);
  392. tp->rcl_nr--;
  393. }
  394. s = tty3270_alloc_string(tp, len);
  395. memcpy(s->string, input, len);
  396. list_add_tail(&s->list, &tp->rcl_lines);
  397. tp->rcl_nr++;
  398. }
  399. static void
  400. tty3270_rcl_backward(struct kbd_data *kbd)
  401. {
  402. struct tty3270 *tp = container_of(kbd->port, struct tty3270, port);
  403. struct string *s;
  404. spin_lock_bh(&tp->view.lock);
  405. if (tp->inattr == TF_INPUT) {
  406. if (tp->rcl_walk && tp->rcl_walk->prev != &tp->rcl_lines)
  407. tp->rcl_walk = tp->rcl_walk->prev;
  408. else if (!list_empty(&tp->rcl_lines))
  409. tp->rcl_walk = tp->rcl_lines.prev;
  410. s = tp->rcl_walk ?
  411. list_entry(tp->rcl_walk, struct string, list) : NULL;
  412. if (tp->rcl_walk) {
  413. s = list_entry(tp->rcl_walk, struct string, list);
  414. tty3270_update_prompt(tp, s->string, s->len);
  415. } else
  416. tty3270_update_prompt(tp, NULL, 0);
  417. tty3270_set_timer(tp, 1);
  418. }
  419. spin_unlock_bh(&tp->view.lock);
  420. }
  421. /*
  422. * Deactivate tty view.
  423. */
  424. static void
  425. tty3270_exit_tty(struct kbd_data *kbd)
  426. {
  427. struct tty3270 *tp = container_of(kbd->port, struct tty3270, port);
  428. raw3270_deactivate_view(&tp->view);
  429. }
  430. /*
  431. * Scroll forward in history.
  432. */
  433. static void
  434. tty3270_scroll_forward(struct kbd_data *kbd)
  435. {
  436. struct tty3270 *tp = container_of(kbd->port, struct tty3270, port);
  437. int nr_up;
  438. spin_lock_bh(&tp->view.lock);
  439. nr_up = tp->nr_up - tp->view.rows + 2;
  440. if (nr_up < 0)
  441. nr_up = 0;
  442. if (nr_up != tp->nr_up) {
  443. tp->nr_up = nr_up;
  444. tty3270_rebuild_update(tp);
  445. tty3270_update_status(tp);
  446. tty3270_set_timer(tp, 1);
  447. }
  448. spin_unlock_bh(&tp->view.lock);
  449. }
  450. /*
  451. * Scroll backward in history.
  452. */
  453. static void
  454. tty3270_scroll_backward(struct kbd_data *kbd)
  455. {
  456. struct tty3270 *tp = container_of(kbd->port, struct tty3270, port);
  457. int nr_up;
  458. spin_lock_bh(&tp->view.lock);
  459. nr_up = tp->nr_up + tp->view.rows - 2;
  460. if (nr_up + tp->view.rows - 2 > tp->nr_lines)
  461. nr_up = tp->nr_lines - tp->view.rows + 2;
  462. if (nr_up != tp->nr_up) {
  463. tp->nr_up = nr_up;
  464. tty3270_rebuild_update(tp);
  465. tty3270_update_status(tp);
  466. tty3270_set_timer(tp, 1);
  467. }
  468. spin_unlock_bh(&tp->view.lock);
  469. }
  470. /*
  471. * Pass input line to tty.
  472. */
  473. static void
  474. tty3270_read_tasklet(struct raw3270_request *rrq)
  475. {
  476. static char kreset_data = TW_KR;
  477. struct tty3270 *tp = container_of(rrq->view, struct tty3270, view);
  478. char *input;
  479. int len;
  480. spin_lock_bh(&tp->view.lock);
  481. /*
  482. * Two AID keys are special: For 0x7d (enter) the input line
  483. * has to be emitted to the tty and for 0x6d the screen
  484. * needs to be redrawn.
  485. */
  486. input = NULL;
  487. len = 0;
  488. if (tp->input->string[0] == 0x7d) {
  489. /* Enter: write input to tty. */
  490. input = tp->input->string + 6;
  491. len = tp->input->len - 6 - rrq->rescnt;
  492. if (tp->inattr != TF_INPUTN)
  493. tty3270_rcl_add(tp, input, len);
  494. if (tp->nr_up > 0) {
  495. tp->nr_up = 0;
  496. tty3270_rebuild_update(tp);
  497. tty3270_update_status(tp);
  498. }
  499. /* Clear input area. */
  500. tty3270_update_prompt(tp, NULL, 0);
  501. tty3270_set_timer(tp, 1);
  502. } else if (tp->input->string[0] == 0x6d) {
  503. /* Display has been cleared. Redraw. */
  504. tp->update_flags = TTY_UPDATE_ALL;
  505. tty3270_set_timer(tp, 1);
  506. }
  507. spin_unlock_bh(&tp->view.lock);
  508. /* Start keyboard reset command. */
  509. raw3270_request_reset(tp->kreset);
  510. raw3270_request_set_cmd(tp->kreset, TC_WRITE);
  511. raw3270_request_add_data(tp->kreset, &kreset_data, 1);
  512. raw3270_start(&tp->view, tp->kreset);
  513. while (len-- > 0)
  514. kbd_keycode(tp->kbd, *input++);
  515. /* Emit keycode for AID byte. */
  516. kbd_keycode(tp->kbd, 256 + tp->input->string[0]);
  517. raw3270_request_reset(rrq);
  518. xchg(&tp->read, rrq);
  519. raw3270_put_view(&tp->view);
  520. }
  521. /*
  522. * Read request completion callback.
  523. */
  524. static void
  525. tty3270_read_callback(struct raw3270_request *rq, void *data)
  526. {
  527. struct tty3270 *tp = container_of(rq->view, struct tty3270, view);
  528. raw3270_get_view(rq->view);
  529. /* Schedule tasklet to pass input to tty. */
  530. tasklet_schedule(&tp->readlet);
  531. }
  532. /*
  533. * Issue a read request. Call with device lock.
  534. */
  535. static void
  536. tty3270_issue_read(struct tty3270 *tp, int lock)
  537. {
  538. struct raw3270_request *rrq;
  539. int rc;
  540. rrq = xchg(&tp->read, 0);
  541. if (!rrq)
  542. /* Read already scheduled. */
  543. return;
  544. rrq->callback = tty3270_read_callback;
  545. rrq->callback_data = tp;
  546. raw3270_request_set_cmd(rrq, TC_READMOD);
  547. raw3270_request_set_data(rrq, tp->input->string, tp->input->len);
  548. /* Issue the read modified request. */
  549. if (lock) {
  550. rc = raw3270_start(&tp->view, rrq);
  551. } else
  552. rc = raw3270_start_irq(&tp->view, rrq);
  553. if (rc) {
  554. raw3270_request_reset(rrq);
  555. xchg(&tp->read, rrq);
  556. }
  557. }
  558. /*
  559. * Switch to the tty view.
  560. */
  561. static int
  562. tty3270_activate(struct raw3270_view *view)
  563. {
  564. struct tty3270 *tp = container_of(view, struct tty3270, view);
  565. tp->update_flags = TTY_UPDATE_ALL;
  566. tty3270_set_timer(tp, 1);
  567. return 0;
  568. }
  569. static void
  570. tty3270_deactivate(struct raw3270_view *view)
  571. {
  572. struct tty3270 *tp = container_of(view, struct tty3270, view);
  573. del_timer(&tp->timer);
  574. }
  575. static int
  576. tty3270_irq(struct tty3270 *tp, struct raw3270_request *rq, struct irb *irb)
  577. {
  578. /* Handle ATTN. Schedule tasklet to read aid. */
  579. if (irb->scsw.cmd.dstat & DEV_STAT_ATTENTION) {
  580. if (!tp->throttle)
  581. tty3270_issue_read(tp, 0);
  582. else
  583. tp->attn = 1;
  584. }
  585. if (rq) {
  586. if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK)
  587. rq->rc = -EIO;
  588. else
  589. /* Normal end. Copy residual count. */
  590. rq->rescnt = irb->scsw.cmd.count;
  591. }
  592. return RAW3270_IO_DONE;
  593. }
  594. /*
  595. * Allocate tty3270 structure.
  596. */
  597. static struct tty3270 *
  598. tty3270_alloc_view(void)
  599. {
  600. struct tty3270 *tp;
  601. int pages;
  602. tp = kzalloc(sizeof(struct tty3270), GFP_KERNEL);
  603. if (!tp)
  604. goto out_err;
  605. tp->freemem_pages =
  606. kmalloc(sizeof(void *) * TTY3270_STRING_PAGES, GFP_KERNEL);
  607. if (!tp->freemem_pages)
  608. goto out_tp;
  609. INIT_LIST_HEAD(&tp->freemem);
  610. INIT_LIST_HEAD(&tp->lines);
  611. INIT_LIST_HEAD(&tp->update);
  612. INIT_LIST_HEAD(&tp->rcl_lines);
  613. tp->rcl_max = 20;
  614. for (pages = 0; pages < TTY3270_STRING_PAGES; pages++) {
  615. tp->freemem_pages[pages] = (void *)
  616. __get_free_pages(GFP_KERNEL|GFP_DMA, 0);
  617. if (!tp->freemem_pages[pages])
  618. goto out_pages;
  619. add_string_memory(&tp->freemem,
  620. tp->freemem_pages[pages], PAGE_SIZE);
  621. }
  622. tp->write = raw3270_request_alloc(TTY3270_OUTPUT_BUFFER_SIZE);
  623. if (IS_ERR(tp->write))
  624. goto out_pages;
  625. tp->read = raw3270_request_alloc(0);
  626. if (IS_ERR(tp->read))
  627. goto out_write;
  628. tp->kreset = raw3270_request_alloc(1);
  629. if (IS_ERR(tp->kreset))
  630. goto out_read;
  631. tp->kbd = kbd_alloc();
  632. if (!tp->kbd)
  633. goto out_reset;
  634. tty_port_init(&tp->port);
  635. setup_timer(&tp->timer, (void (*)(unsigned long)) tty3270_update,
  636. (unsigned long) tp);
  637. tasklet_init(&tp->readlet,
  638. (void (*)(unsigned long)) tty3270_read_tasklet,
  639. (unsigned long) tp->read);
  640. INIT_WORK(&tp->resize_work, tty3270_resize_work);
  641. return tp;
  642. out_reset:
  643. raw3270_request_free(tp->kreset);
  644. out_read:
  645. raw3270_request_free(tp->read);
  646. out_write:
  647. raw3270_request_free(tp->write);
  648. out_pages:
  649. while (pages--)
  650. free_pages((unsigned long) tp->freemem_pages[pages], 0);
  651. kfree(tp->freemem_pages);
  652. tty_port_destroy(&tp->port);
  653. out_tp:
  654. kfree(tp);
  655. out_err:
  656. return ERR_PTR(-ENOMEM);
  657. }
  658. /*
  659. * Free tty3270 structure.
  660. */
  661. static void
  662. tty3270_free_view(struct tty3270 *tp)
  663. {
  664. int pages;
  665. kbd_free(tp->kbd);
  666. raw3270_request_free(tp->kreset);
  667. raw3270_request_free(tp->read);
  668. raw3270_request_free(tp->write);
  669. for (pages = 0; pages < TTY3270_STRING_PAGES; pages++)
  670. free_pages((unsigned long) tp->freemem_pages[pages], 0);
  671. kfree(tp->freemem_pages);
  672. tty_port_destroy(&tp->port);
  673. kfree(tp);
  674. }
  675. /*
  676. * Allocate tty3270 screen.
  677. */
  678. static struct tty3270_line *
  679. tty3270_alloc_screen(unsigned int rows, unsigned int cols)
  680. {
  681. struct tty3270_line *screen;
  682. unsigned long size;
  683. int lines;
  684. size = sizeof(struct tty3270_line) * (rows - 2);
  685. screen = kzalloc(size, GFP_KERNEL);
  686. if (!screen)
  687. goto out_err;
  688. for (lines = 0; lines < rows - 2; lines++) {
  689. size = sizeof(struct tty3270_cell) * cols;
  690. screen[lines].cells = kzalloc(size, GFP_KERNEL);
  691. if (!screen[lines].cells)
  692. goto out_screen;
  693. }
  694. return screen;
  695. out_screen:
  696. while (lines--)
  697. kfree(screen[lines].cells);
  698. kfree(screen);
  699. out_err:
  700. return ERR_PTR(-ENOMEM);
  701. }
  702. /*
  703. * Free tty3270 screen.
  704. */
  705. static void
  706. tty3270_free_screen(struct tty3270_line *screen, unsigned int rows)
  707. {
  708. int lines;
  709. for (lines = 0; lines < rows - 2; lines++)
  710. kfree(screen[lines].cells);
  711. kfree(screen);
  712. }
  713. /*
  714. * Resize tty3270 screen
  715. */
  716. static void tty3270_resize_work(struct work_struct *work)
  717. {
  718. struct tty3270 *tp = container_of(work, struct tty3270, resize_work);
  719. struct tty3270_line *screen, *oscreen;
  720. struct tty_struct *tty;
  721. unsigned int orows;
  722. struct winsize ws;
  723. screen = tty3270_alloc_screen(tp->n_rows, tp->n_cols);
  724. if (IS_ERR(screen))
  725. return;
  726. /* Switch to new output size */
  727. spin_lock_bh(&tp->view.lock);
  728. oscreen = tp->screen;
  729. orows = tp->view.rows;
  730. tp->view.model = tp->n_model;
  731. tp->view.rows = tp->n_rows;
  732. tp->view.cols = tp->n_cols;
  733. tp->screen = screen;
  734. free_string(&tp->freemem, tp->prompt);
  735. free_string(&tp->freemem, tp->status);
  736. tty3270_create_prompt(tp);
  737. tty3270_create_status(tp);
  738. tp->nr_up = 0;
  739. while (tp->nr_lines < tp->view.rows - 2)
  740. tty3270_blank_line(tp);
  741. tp->update_flags = TTY_UPDATE_ALL;
  742. spin_unlock_bh(&tp->view.lock);
  743. tty3270_free_screen(oscreen, orows);
  744. tty3270_set_timer(tp, 1);
  745. /* Informat tty layer about new size */
  746. tty = tty_port_tty_get(&tp->port);
  747. if (!tty)
  748. return;
  749. ws.ws_row = tp->view.rows - 2;
  750. ws.ws_col = tp->view.cols;
  751. tty_do_resize(tty, &ws);
  752. }
  753. static void
  754. tty3270_resize(struct raw3270_view *view, int model, int rows, int cols)
  755. {
  756. struct tty3270 *tp = container_of(view, struct tty3270, view);
  757. tp->n_model = model;
  758. tp->n_rows = rows;
  759. tp->n_cols = cols;
  760. schedule_work(&tp->resize_work);
  761. }
  762. /*
  763. * Unlink tty3270 data structure from tty.
  764. */
  765. static void
  766. tty3270_release(struct raw3270_view *view)
  767. {
  768. struct tty3270 *tp = container_of(view, struct tty3270, view);
  769. struct tty_struct *tty = tty_port_tty_get(&tp->port);
  770. if (tty) {
  771. tty->driver_data = NULL;
  772. tty_port_tty_set(&tp->port, NULL);
  773. tty_hangup(tty);
  774. raw3270_put_view(&tp->view);
  775. tty_kref_put(tty);
  776. }
  777. }
  778. /*
  779. * Free tty3270 data structure
  780. */
  781. static void
  782. tty3270_free(struct raw3270_view *view)
  783. {
  784. struct tty3270 *tp = container_of(view, struct tty3270, view);
  785. del_timer_sync(&tp->timer);
  786. tty3270_free_screen(tp->screen, tp->view.rows);
  787. tty3270_free_view(tp);
  788. }
  789. /*
  790. * Delayed freeing of tty3270 views.
  791. */
  792. static void
  793. tty3270_del_views(void)
  794. {
  795. int i;
  796. for (i = RAW3270_FIRSTMINOR; i <= tty3270_max_index; i++) {
  797. struct raw3270_view *view = raw3270_find_view(&tty3270_fn, i);
  798. if (!IS_ERR(view))
  799. raw3270_del_view(view);
  800. }
  801. }
  802. static struct raw3270_fn tty3270_fn = {
  803. .activate = tty3270_activate,
  804. .deactivate = tty3270_deactivate,
  805. .intv = (void *) tty3270_irq,
  806. .release = tty3270_release,
  807. .free = tty3270_free,
  808. .resize = tty3270_resize
  809. };
  810. /*
  811. * This routine is called whenever a 3270 tty is opened first time.
  812. */
  813. static int tty3270_install(struct tty_driver *driver, struct tty_struct *tty)
  814. {
  815. struct raw3270_view *view;
  816. struct tty3270 *tp;
  817. int i, rc;
  818. /* Check if the tty3270 is already there. */
  819. view = raw3270_find_view(&tty3270_fn, tty->index + RAW3270_FIRSTMINOR);
  820. if (!IS_ERR(view)) {
  821. tp = container_of(view, struct tty3270, view);
  822. tty->driver_data = tp;
  823. tty->winsize.ws_row = tp->view.rows - 2;
  824. tty->winsize.ws_col = tp->view.cols;
  825. tp->port.low_latency = 0;
  826. /* why to reassign? */
  827. tty_port_tty_set(&tp->port, tty);
  828. tp->inattr = TF_INPUT;
  829. return tty_port_install(&tp->port, driver, tty);
  830. }
  831. if (tty3270_max_index < tty->index + 1)
  832. tty3270_max_index = tty->index + 1;
  833. /* Allocate tty3270 structure on first open. */
  834. tp = tty3270_alloc_view();
  835. if (IS_ERR(tp))
  836. return PTR_ERR(tp);
  837. rc = raw3270_add_view(&tp->view, &tty3270_fn,
  838. tty->index + RAW3270_FIRSTMINOR);
  839. if (rc) {
  840. tty3270_free_view(tp);
  841. return rc;
  842. }
  843. tp->screen = tty3270_alloc_screen(tp->view.rows, tp->view.cols);
  844. if (IS_ERR(tp->screen)) {
  845. rc = PTR_ERR(tp->screen);
  846. raw3270_put_view(&tp->view);
  847. raw3270_del_view(&tp->view);
  848. tty3270_free_view(tp);
  849. return rc;
  850. }
  851. tty_port_tty_set(&tp->port, tty);
  852. tp->port.low_latency = 0;
  853. tty->winsize.ws_row = tp->view.rows - 2;
  854. tty->winsize.ws_col = tp->view.cols;
  855. tty3270_create_prompt(tp);
  856. tty3270_create_status(tp);
  857. tty3270_update_status(tp);
  858. /* Create blank line for every line in the tty output area. */
  859. for (i = 0; i < tp->view.rows - 2; i++)
  860. tty3270_blank_line(tp);
  861. tp->kbd->port = &tp->port;
  862. tp->kbd->fn_handler[KVAL(K_INCRCONSOLE)] = tty3270_exit_tty;
  863. tp->kbd->fn_handler[KVAL(K_SCROLLBACK)] = tty3270_scroll_backward;
  864. tp->kbd->fn_handler[KVAL(K_SCROLLFORW)] = tty3270_scroll_forward;
  865. tp->kbd->fn_handler[KVAL(K_CONS)] = tty3270_rcl_backward;
  866. kbd_ascebc(tp->kbd, tp->view.ascebc);
  867. raw3270_activate_view(&tp->view);
  868. rc = tty_port_install(&tp->port, driver, tty);
  869. if (rc) {
  870. raw3270_put_view(&tp->view);
  871. return rc;
  872. }
  873. tty->driver_data = tp;
  874. return 0;
  875. }
  876. /*
  877. * This routine is called whenever a 3270 tty is opened.
  878. */
  879. static int
  880. tty3270_open(struct tty_struct *tty, struct file *filp)
  881. {
  882. struct tty3270 *tp = tty->driver_data;
  883. struct tty_port *port = &tp->port;
  884. port->count++;
  885. tty_port_tty_set(port, tty);
  886. return 0;
  887. }
  888. /*
  889. * This routine is called when the 3270 tty is closed. We wait
  890. * for the remaining request to be completed. Then we clean up.
  891. */
  892. static void
  893. tty3270_close(struct tty_struct *tty, struct file * filp)
  894. {
  895. struct tty3270 *tp = tty->driver_data;
  896. if (tty->count > 1)
  897. return;
  898. if (tp) {
  899. tty->driver_data = NULL;
  900. tty_port_tty_set(&tp->port, NULL);
  901. }
  902. }
  903. static void tty3270_cleanup(struct tty_struct *tty)
  904. {
  905. struct tty3270 *tp = tty->driver_data;
  906. if (tp)
  907. raw3270_put_view(&tp->view);
  908. }
  909. /*
  910. * We always have room.
  911. */
  912. static int
  913. tty3270_write_room(struct tty_struct *tty)
  914. {
  915. return INT_MAX;
  916. }
  917. /*
  918. * Insert character into the screen at the current position with the
  919. * current color and highlight. This function does NOT do cursor movement.
  920. */
  921. static void tty3270_put_character(struct tty3270 *tp, char ch)
  922. {
  923. struct tty3270_line *line;
  924. struct tty3270_cell *cell;
  925. line = tp->screen + tp->cy;
  926. if (line->len <= tp->cx) {
  927. while (line->len < tp->cx) {
  928. cell = line->cells + line->len;
  929. cell->character = tp->view.ascebc[' '];
  930. cell->highlight = tp->highlight;
  931. cell->f_color = tp->f_color;
  932. line->len++;
  933. }
  934. line->len++;
  935. }
  936. cell = line->cells + tp->cx;
  937. cell->character = tp->view.ascebc[(unsigned int) ch];
  938. cell->highlight = tp->highlight;
  939. cell->f_color = tp->f_color;
  940. }
  941. /*
  942. * Convert a tty3270_line to a 3270 data fragment usable for output.
  943. */
  944. static void
  945. tty3270_convert_line(struct tty3270 *tp, int line_nr)
  946. {
  947. struct tty3270_line *line;
  948. struct tty3270_cell *cell;
  949. struct string *s, *n;
  950. unsigned char highlight;
  951. unsigned char f_color;
  952. char *cp;
  953. int flen, i;
  954. /* Determine how long the fragment will be. */
  955. flen = 3; /* Prefix (TO_SBA). */
  956. line = tp->screen + line_nr;
  957. flen += line->len;
  958. highlight = TAX_RESET;
  959. f_color = TAC_RESET;
  960. for (i = 0, cell = line->cells; i < line->len; i++, cell++) {
  961. if (cell->highlight != highlight) {
  962. flen += 3; /* TO_SA to switch highlight. */
  963. highlight = cell->highlight;
  964. }
  965. if (cell->f_color != f_color) {
  966. flen += 3; /* TO_SA to switch color. */
  967. f_color = cell->f_color;
  968. }
  969. }
  970. if (highlight != TAX_RESET)
  971. flen += 3; /* TO_SA to reset hightlight. */
  972. if (f_color != TAC_RESET)
  973. flen += 3; /* TO_SA to reset color. */
  974. if (line->len < tp->view.cols)
  975. flen += 4; /* Postfix (TO_RA). */
  976. /* Find the line in the list. */
  977. i = tp->view.rows - 2 - line_nr;
  978. list_for_each_entry_reverse(s, &tp->lines, list)
  979. if (--i <= 0)
  980. break;
  981. /*
  982. * Check if the line needs to get reallocated.
  983. */
  984. if (s->len != flen) {
  985. /* Reallocate string. */
  986. n = tty3270_alloc_string(tp, flen);
  987. list_add(&n->list, &s->list);
  988. list_del_init(&s->list);
  989. if (!list_empty(&s->update))
  990. list_del_init(&s->update);
  991. free_string(&tp->freemem, s);
  992. s = n;
  993. }
  994. /* Write 3270 data fragment. */
  995. cp = s->string;
  996. *cp++ = TO_SBA;
  997. *cp++ = 0;
  998. *cp++ = 0;
  999. highlight = TAX_RESET;
  1000. f_color = TAC_RESET;
  1001. for (i = 0, cell = line->cells; i < line->len; i++, cell++) {
  1002. if (cell->highlight != highlight) {
  1003. *cp++ = TO_SA;
  1004. *cp++ = TAT_EXTHI;
  1005. *cp++ = cell->highlight;
  1006. highlight = cell->highlight;
  1007. }
  1008. if (cell->f_color != f_color) {
  1009. *cp++ = TO_SA;
  1010. *cp++ = TAT_COLOR;
  1011. *cp++ = cell->f_color;
  1012. f_color = cell->f_color;
  1013. }
  1014. *cp++ = cell->character;
  1015. }
  1016. if (highlight != TAX_RESET) {
  1017. *cp++ = TO_SA;
  1018. *cp++ = TAT_EXTHI;
  1019. *cp++ = TAX_RESET;
  1020. }
  1021. if (f_color != TAC_RESET) {
  1022. *cp++ = TO_SA;
  1023. *cp++ = TAT_COLOR;
  1024. *cp++ = TAC_RESET;
  1025. }
  1026. if (line->len < tp->view.cols) {
  1027. *cp++ = TO_RA;
  1028. *cp++ = 0;
  1029. *cp++ = 0;
  1030. *cp++ = 0;
  1031. }
  1032. if (tp->nr_up + line_nr < tp->view.rows - 2) {
  1033. /* Line is currently visible on screen. */
  1034. tty3270_update_string(tp, s, line_nr);
  1035. /* Add line to update list. */
  1036. if (list_empty(&s->update)) {
  1037. list_add_tail(&s->update, &tp->update);
  1038. tp->update_flags |= TTY_UPDATE_LIST;
  1039. }
  1040. }
  1041. }
  1042. /*
  1043. * Do carriage return.
  1044. */
  1045. static void
  1046. tty3270_cr(struct tty3270 *tp)
  1047. {
  1048. tp->cx = 0;
  1049. }
  1050. /*
  1051. * Do line feed.
  1052. */
  1053. static void
  1054. tty3270_lf(struct tty3270 *tp)
  1055. {
  1056. struct tty3270_line temp;
  1057. int i;
  1058. tty3270_convert_line(tp, tp->cy);
  1059. if (tp->cy < tp->view.rows - 3) {
  1060. tp->cy++;
  1061. return;
  1062. }
  1063. /* Last line just filled up. Add new, blank line. */
  1064. tty3270_blank_line(tp);
  1065. temp = tp->screen[0];
  1066. temp.len = 0;
  1067. for (i = 0; i < tp->view.rows - 3; i++)
  1068. tp->screen[i] = tp->screen[i+1];
  1069. tp->screen[tp->view.rows - 3] = temp;
  1070. tty3270_rebuild_update(tp);
  1071. }
  1072. static void
  1073. tty3270_ri(struct tty3270 *tp)
  1074. {
  1075. if (tp->cy > 0) {
  1076. tty3270_convert_line(tp, tp->cy);
  1077. tp->cy--;
  1078. }
  1079. }
  1080. /*
  1081. * Insert characters at current position.
  1082. */
  1083. static void
  1084. tty3270_insert_characters(struct tty3270 *tp, int n)
  1085. {
  1086. struct tty3270_line *line;
  1087. int k;
  1088. line = tp->screen + tp->cy;
  1089. while (line->len < tp->cx) {
  1090. line->cells[line->len].character = tp->view.ascebc[' '];
  1091. line->cells[line->len].highlight = TAX_RESET;
  1092. line->cells[line->len].f_color = TAC_RESET;
  1093. line->len++;
  1094. }
  1095. if (n > tp->view.cols - tp->cx)
  1096. n = tp->view.cols - tp->cx;
  1097. k = min_t(int, line->len - tp->cx, tp->view.cols - tp->cx - n);
  1098. while (k--)
  1099. line->cells[tp->cx + n + k] = line->cells[tp->cx + k];
  1100. line->len += n;
  1101. if (line->len > tp->view.cols)
  1102. line->len = tp->view.cols;
  1103. while (n-- > 0) {
  1104. line->cells[tp->cx + n].character = tp->view.ascebc[' '];
  1105. line->cells[tp->cx + n].highlight = tp->highlight;
  1106. line->cells[tp->cx + n].f_color = tp->f_color;
  1107. }
  1108. }
  1109. /*
  1110. * Delete characters at current position.
  1111. */
  1112. static void
  1113. tty3270_delete_characters(struct tty3270 *tp, int n)
  1114. {
  1115. struct tty3270_line *line;
  1116. int i;
  1117. line = tp->screen + tp->cy;
  1118. if (line->len <= tp->cx)
  1119. return;
  1120. if (line->len - tp->cx <= n) {
  1121. line->len = tp->cx;
  1122. return;
  1123. }
  1124. for (i = tp->cx; i + n < line->len; i++)
  1125. line->cells[i] = line->cells[i + n];
  1126. line->len -= n;
  1127. }
  1128. /*
  1129. * Erase characters at current position.
  1130. */
  1131. static void
  1132. tty3270_erase_characters(struct tty3270 *tp, int n)
  1133. {
  1134. struct tty3270_line *line;
  1135. struct tty3270_cell *cell;
  1136. line = tp->screen + tp->cy;
  1137. while (line->len > tp->cx && n-- > 0) {
  1138. cell = line->cells + tp->cx++;
  1139. cell->character = ' ';
  1140. cell->highlight = TAX_RESET;
  1141. cell->f_color = TAC_RESET;
  1142. }
  1143. tp->cx += n;
  1144. tp->cx = min_t(int, tp->cx, tp->view.cols - 1);
  1145. }
  1146. /*
  1147. * Erase line, 3 different cases:
  1148. * Esc [ 0 K Erase from current position to end of line inclusive
  1149. * Esc [ 1 K Erase from beginning of line to current position inclusive
  1150. * Esc [ 2 K Erase entire line (without moving cursor)
  1151. */
  1152. static void
  1153. tty3270_erase_line(struct tty3270 *tp, int mode)
  1154. {
  1155. struct tty3270_line *line;
  1156. struct tty3270_cell *cell;
  1157. int i;
  1158. line = tp->screen + tp->cy;
  1159. if (mode == 0)
  1160. line->len = tp->cx;
  1161. else if (mode == 1) {
  1162. for (i = 0; i < tp->cx; i++) {
  1163. cell = line->cells + i;
  1164. cell->character = ' ';
  1165. cell->highlight = TAX_RESET;
  1166. cell->f_color = TAC_RESET;
  1167. }
  1168. if (line->len <= tp->cx)
  1169. line->len = tp->cx + 1;
  1170. } else if (mode == 2)
  1171. line->len = 0;
  1172. tty3270_convert_line(tp, tp->cy);
  1173. }
  1174. /*
  1175. * Erase display, 3 different cases:
  1176. * Esc [ 0 J Erase from current position to bottom of screen inclusive
  1177. * Esc [ 1 J Erase from top of screen to current position inclusive
  1178. * Esc [ 2 J Erase entire screen (without moving the cursor)
  1179. */
  1180. static void
  1181. tty3270_erase_display(struct tty3270 *tp, int mode)
  1182. {
  1183. int i;
  1184. if (mode == 0) {
  1185. tty3270_erase_line(tp, 0);
  1186. for (i = tp->cy + 1; i < tp->view.rows - 2; i++) {
  1187. tp->screen[i].len = 0;
  1188. tty3270_convert_line(tp, i);
  1189. }
  1190. } else if (mode == 1) {
  1191. for (i = 0; i < tp->cy; i++) {
  1192. tp->screen[i].len = 0;
  1193. tty3270_convert_line(tp, i);
  1194. }
  1195. tty3270_erase_line(tp, 1);
  1196. } else if (mode == 2) {
  1197. for (i = 0; i < tp->view.rows - 2; i++) {
  1198. tp->screen[i].len = 0;
  1199. tty3270_convert_line(tp, i);
  1200. }
  1201. }
  1202. tty3270_rebuild_update(tp);
  1203. }
  1204. /*
  1205. * Set attributes found in an escape sequence.
  1206. * Esc [ <attr> ; <attr> ; ... m
  1207. */
  1208. static void
  1209. tty3270_set_attributes(struct tty3270 *tp)
  1210. {
  1211. static unsigned char f_colors[] = {
  1212. TAC_DEFAULT, TAC_RED, TAC_GREEN, TAC_YELLOW, TAC_BLUE,
  1213. TAC_PINK, TAC_TURQ, TAC_WHITE, 0, TAC_DEFAULT
  1214. };
  1215. int i, attr;
  1216. for (i = 0; i <= tp->esc_npar; i++) {
  1217. attr = tp->esc_par[i];
  1218. switch (attr) {
  1219. case 0: /* Reset */
  1220. tp->highlight = TAX_RESET;
  1221. tp->f_color = TAC_RESET;
  1222. break;
  1223. /* Highlight. */
  1224. case 4: /* Start underlining. */
  1225. tp->highlight = TAX_UNDER;
  1226. break;
  1227. case 5: /* Start blink. */
  1228. tp->highlight = TAX_BLINK;
  1229. break;
  1230. case 7: /* Start reverse. */
  1231. tp->highlight = TAX_REVER;
  1232. break;
  1233. case 24: /* End underlining */
  1234. if (tp->highlight == TAX_UNDER)
  1235. tp->highlight = TAX_RESET;
  1236. break;
  1237. case 25: /* End blink. */
  1238. if (tp->highlight == TAX_BLINK)
  1239. tp->highlight = TAX_RESET;
  1240. break;
  1241. case 27: /* End reverse. */
  1242. if (tp->highlight == TAX_REVER)
  1243. tp->highlight = TAX_RESET;
  1244. break;
  1245. /* Foreground color. */
  1246. case 30: /* Black */
  1247. case 31: /* Red */
  1248. case 32: /* Green */
  1249. case 33: /* Yellow */
  1250. case 34: /* Blue */
  1251. case 35: /* Magenta */
  1252. case 36: /* Cyan */
  1253. case 37: /* White */
  1254. case 39: /* Black */
  1255. tp->f_color = f_colors[attr - 30];
  1256. break;
  1257. }
  1258. }
  1259. }
  1260. static inline int
  1261. tty3270_getpar(struct tty3270 *tp, int ix)
  1262. {
  1263. return (tp->esc_par[ix] > 0) ? tp->esc_par[ix] : 1;
  1264. }
  1265. static void
  1266. tty3270_goto_xy(struct tty3270 *tp, int cx, int cy)
  1267. {
  1268. int max_cx = max(0, cx);
  1269. int max_cy = max(0, cy);
  1270. tp->cx = min_t(int, tp->view.cols - 1, max_cx);
  1271. cy = min_t(int, tp->view.rows - 3, max_cy);
  1272. if (cy != tp->cy) {
  1273. tty3270_convert_line(tp, tp->cy);
  1274. tp->cy = cy;
  1275. }
  1276. }
  1277. /*
  1278. * Process escape sequences. Known sequences:
  1279. * Esc 7 Save Cursor Position
  1280. * Esc 8 Restore Cursor Position
  1281. * Esc [ Pn ; Pn ; .. m Set attributes
  1282. * Esc [ Pn ; Pn H Cursor Position
  1283. * Esc [ Pn ; Pn f Cursor Position
  1284. * Esc [ Pn A Cursor Up
  1285. * Esc [ Pn B Cursor Down
  1286. * Esc [ Pn C Cursor Forward
  1287. * Esc [ Pn D Cursor Backward
  1288. * Esc [ Pn G Cursor Horizontal Absolute
  1289. * Esc [ Pn X Erase Characters
  1290. * Esc [ Ps J Erase in Display
  1291. * Esc [ Ps K Erase in Line
  1292. * // FIXME: add all the new ones.
  1293. *
  1294. * Pn is a numeric parameter, a string of zero or more decimal digits.
  1295. * Ps is a selective parameter.
  1296. */
  1297. static void
  1298. tty3270_escape_sequence(struct tty3270 *tp, char ch)
  1299. {
  1300. enum { ESnormal, ESesc, ESsquare, ESgetpars };
  1301. if (tp->esc_state == ESnormal) {
  1302. if (ch == 0x1b)
  1303. /* Starting new escape sequence. */
  1304. tp->esc_state = ESesc;
  1305. return;
  1306. }
  1307. if (tp->esc_state == ESesc) {
  1308. tp->esc_state = ESnormal;
  1309. switch (ch) {
  1310. case '[':
  1311. tp->esc_state = ESsquare;
  1312. break;
  1313. case 'E':
  1314. tty3270_cr(tp);
  1315. tty3270_lf(tp);
  1316. break;
  1317. case 'M':
  1318. tty3270_ri(tp);
  1319. break;
  1320. case 'D':
  1321. tty3270_lf(tp);
  1322. break;
  1323. case 'Z': /* Respond ID. */
  1324. kbd_puts_queue(&tp->port, "\033[?6c");
  1325. break;
  1326. case '7': /* Save cursor position. */
  1327. tp->saved_cx = tp->cx;
  1328. tp->saved_cy = tp->cy;
  1329. tp->saved_highlight = tp->highlight;
  1330. tp->saved_f_color = tp->f_color;
  1331. break;
  1332. case '8': /* Restore cursor position. */
  1333. tty3270_convert_line(tp, tp->cy);
  1334. tty3270_goto_xy(tp, tp->saved_cx, tp->saved_cy);
  1335. tp->highlight = tp->saved_highlight;
  1336. tp->f_color = tp->saved_f_color;
  1337. break;
  1338. case 'c': /* Reset terminal. */
  1339. tp->cx = tp->saved_cx = 0;
  1340. tp->cy = tp->saved_cy = 0;
  1341. tp->highlight = tp->saved_highlight = TAX_RESET;
  1342. tp->f_color = tp->saved_f_color = TAC_RESET;
  1343. tty3270_erase_display(tp, 2);
  1344. break;
  1345. }
  1346. return;
  1347. }
  1348. if (tp->esc_state == ESsquare) {
  1349. tp->esc_state = ESgetpars;
  1350. memset(tp->esc_par, 0, sizeof(tp->esc_par));
  1351. tp->esc_npar = 0;
  1352. tp->esc_ques = (ch == '?');
  1353. if (tp->esc_ques)
  1354. return;
  1355. }
  1356. if (tp->esc_state == ESgetpars) {
  1357. if (ch == ';' && tp->esc_npar < ESCAPE_NPAR - 1) {
  1358. tp->esc_npar++;
  1359. return;
  1360. }
  1361. if (ch >= '0' && ch <= '9') {
  1362. tp->esc_par[tp->esc_npar] *= 10;
  1363. tp->esc_par[tp->esc_npar] += ch - '0';
  1364. return;
  1365. }
  1366. }
  1367. tp->esc_state = ESnormal;
  1368. if (ch == 'n' && !tp->esc_ques) {
  1369. if (tp->esc_par[0] == 5) /* Status report. */
  1370. kbd_puts_queue(&tp->port, "\033[0n");
  1371. else if (tp->esc_par[0] == 6) { /* Cursor report. */
  1372. char buf[40];
  1373. sprintf(buf, "\033[%d;%dR", tp->cy + 1, tp->cx + 1);
  1374. kbd_puts_queue(&tp->port, buf);
  1375. }
  1376. return;
  1377. }
  1378. if (tp->esc_ques)
  1379. return;
  1380. switch (ch) {
  1381. case 'm':
  1382. tty3270_set_attributes(tp);
  1383. break;
  1384. case 'H': /* Set cursor position. */
  1385. case 'f':
  1386. tty3270_goto_xy(tp, tty3270_getpar(tp, 1) - 1,
  1387. tty3270_getpar(tp, 0) - 1);
  1388. break;
  1389. case 'd': /* Set y position. */
  1390. tty3270_goto_xy(tp, tp->cx, tty3270_getpar(tp, 0) - 1);
  1391. break;
  1392. case 'A': /* Cursor up. */
  1393. case 'F':
  1394. tty3270_goto_xy(tp, tp->cx, tp->cy - tty3270_getpar(tp, 0));
  1395. break;
  1396. case 'B': /* Cursor down. */
  1397. case 'e':
  1398. case 'E':
  1399. tty3270_goto_xy(tp, tp->cx, tp->cy + tty3270_getpar(tp, 0));
  1400. break;
  1401. case 'C': /* Cursor forward. */
  1402. case 'a':
  1403. tty3270_goto_xy(tp, tp->cx + tty3270_getpar(tp, 0), tp->cy);
  1404. break;
  1405. case 'D': /* Cursor backward. */
  1406. tty3270_goto_xy(tp, tp->cx - tty3270_getpar(tp, 0), tp->cy);
  1407. break;
  1408. case 'G': /* Set x position. */
  1409. case '`':
  1410. tty3270_goto_xy(tp, tty3270_getpar(tp, 0), tp->cy);
  1411. break;
  1412. case 'X': /* Erase Characters. */
  1413. tty3270_erase_characters(tp, tty3270_getpar(tp, 0));
  1414. break;
  1415. case 'J': /* Erase display. */
  1416. tty3270_erase_display(tp, tp->esc_par[0]);
  1417. break;
  1418. case 'K': /* Erase line. */
  1419. tty3270_erase_line(tp, tp->esc_par[0]);
  1420. break;
  1421. case 'P': /* Delete characters. */
  1422. tty3270_delete_characters(tp, tty3270_getpar(tp, 0));
  1423. break;
  1424. case '@': /* Insert characters. */
  1425. tty3270_insert_characters(tp, tty3270_getpar(tp, 0));
  1426. break;
  1427. case 's': /* Save cursor position. */
  1428. tp->saved_cx = tp->cx;
  1429. tp->saved_cy = tp->cy;
  1430. tp->saved_highlight = tp->highlight;
  1431. tp->saved_f_color = tp->f_color;
  1432. break;
  1433. case 'u': /* Restore cursor position. */
  1434. tty3270_convert_line(tp, tp->cy);
  1435. tty3270_goto_xy(tp, tp->saved_cx, tp->saved_cy);
  1436. tp->highlight = tp->saved_highlight;
  1437. tp->f_color = tp->saved_f_color;
  1438. break;
  1439. }
  1440. }
  1441. /*
  1442. * String write routine for 3270 ttys
  1443. */
  1444. static void
  1445. tty3270_do_write(struct tty3270 *tp, struct tty_struct *tty,
  1446. const unsigned char *buf, int count)
  1447. {
  1448. int i_msg, i;
  1449. spin_lock_bh(&tp->view.lock);
  1450. for (i_msg = 0; !tty->stopped && i_msg < count; i_msg++) {
  1451. if (tp->esc_state != 0) {
  1452. /* Continue escape sequence. */
  1453. tty3270_escape_sequence(tp, buf[i_msg]);
  1454. continue;
  1455. }
  1456. switch (buf[i_msg]) {
  1457. case 0x07: /* '\a' -- Alarm */
  1458. tp->wcc |= TW_PLUSALARM;
  1459. break;
  1460. case 0x08: /* Backspace. */
  1461. if (tp->cx > 0) {
  1462. tp->cx--;
  1463. tty3270_put_character(tp, ' ');
  1464. }
  1465. break;
  1466. case 0x09: /* '\t' -- Tabulate */
  1467. for (i = tp->cx % 8; i < 8; i++) {
  1468. if (tp->cx >= tp->view.cols) {
  1469. tty3270_cr(tp);
  1470. tty3270_lf(tp);
  1471. break;
  1472. }
  1473. tty3270_put_character(tp, ' ');
  1474. tp->cx++;
  1475. }
  1476. break;
  1477. case 0x0a: /* '\n' -- New Line */
  1478. tty3270_cr(tp);
  1479. tty3270_lf(tp);
  1480. break;
  1481. case 0x0c: /* '\f' -- Form Feed */
  1482. tty3270_erase_display(tp, 2);
  1483. tp->cx = tp->cy = 0;
  1484. break;
  1485. case 0x0d: /* '\r' -- Carriage Return */
  1486. tp->cx = 0;
  1487. break;
  1488. case 0x0f: /* SuSE "exit alternate mode" */
  1489. break;
  1490. case 0x1b: /* Start escape sequence. */
  1491. tty3270_escape_sequence(tp, buf[i_msg]);
  1492. break;
  1493. default: /* Insert normal character. */
  1494. if (tp->cx >= tp->view.cols) {
  1495. tty3270_cr(tp);
  1496. tty3270_lf(tp);
  1497. }
  1498. tty3270_put_character(tp, buf[i_msg]);
  1499. tp->cx++;
  1500. break;
  1501. }
  1502. }
  1503. /* Convert current line to 3270 data fragment. */
  1504. tty3270_convert_line(tp, tp->cy);
  1505. /* Setup timer to update display after 1/10 second */
  1506. if (!timer_pending(&tp->timer))
  1507. tty3270_set_timer(tp, HZ/10);
  1508. spin_unlock_bh(&tp->view.lock);
  1509. }
  1510. /*
  1511. * String write routine for 3270 ttys
  1512. */
  1513. static int
  1514. tty3270_write(struct tty_struct * tty,
  1515. const unsigned char *buf, int count)
  1516. {
  1517. struct tty3270 *tp;
  1518. tp = tty->driver_data;
  1519. if (!tp)
  1520. return 0;
  1521. if (tp->char_count > 0) {
  1522. tty3270_do_write(tp, tty, tp->char_buf, tp->char_count);
  1523. tp->char_count = 0;
  1524. }
  1525. tty3270_do_write(tp, tty, buf, count);
  1526. return count;
  1527. }
  1528. /*
  1529. * Put single characters to the ttys character buffer
  1530. */
  1531. static int tty3270_put_char(struct tty_struct *tty, unsigned char ch)
  1532. {
  1533. struct tty3270 *tp;
  1534. tp = tty->driver_data;
  1535. if (!tp || tp->char_count >= TTY3270_CHAR_BUF_SIZE)
  1536. return 0;
  1537. tp->char_buf[tp->char_count++] = ch;
  1538. return 1;
  1539. }
  1540. /*
  1541. * Flush all characters from the ttys characeter buffer put there
  1542. * by tty3270_put_char.
  1543. */
  1544. static void
  1545. tty3270_flush_chars(struct tty_struct *tty)
  1546. {
  1547. struct tty3270 *tp;
  1548. tp = tty->driver_data;
  1549. if (!tp)
  1550. return;
  1551. if (tp->char_count > 0) {
  1552. tty3270_do_write(tp, tty, tp->char_buf, tp->char_count);
  1553. tp->char_count = 0;
  1554. }
  1555. }
  1556. /*
  1557. * Returns the number of characters in the output buffer. This is
  1558. * used in tty_wait_until_sent to wait until all characters have
  1559. * appeared on the screen.
  1560. */
  1561. static int
  1562. tty3270_chars_in_buffer(struct tty_struct *tty)
  1563. {
  1564. return 0;
  1565. }
  1566. static void
  1567. tty3270_flush_buffer(struct tty_struct *tty)
  1568. {
  1569. }
  1570. /*
  1571. * Check for visible/invisible input switches
  1572. */
  1573. static void
  1574. tty3270_set_termios(struct tty_struct *tty, struct ktermios *old)
  1575. {
  1576. struct tty3270 *tp;
  1577. int new;
  1578. tp = tty->driver_data;
  1579. if (!tp)
  1580. return;
  1581. spin_lock_bh(&tp->view.lock);
  1582. if (L_ICANON(tty)) {
  1583. new = L_ECHO(tty) ? TF_INPUT: TF_INPUTN;
  1584. if (new != tp->inattr) {
  1585. tp->inattr = new;
  1586. tty3270_update_prompt(tp, NULL, 0);
  1587. tty3270_set_timer(tp, 1);
  1588. }
  1589. }
  1590. spin_unlock_bh(&tp->view.lock);
  1591. }
  1592. /*
  1593. * Disable reading from a 3270 tty
  1594. */
  1595. static void
  1596. tty3270_throttle(struct tty_struct * tty)
  1597. {
  1598. struct tty3270 *tp;
  1599. tp = tty->driver_data;
  1600. if (!tp)
  1601. return;
  1602. tp->throttle = 1;
  1603. }
  1604. /*
  1605. * Enable reading from a 3270 tty
  1606. */
  1607. static void
  1608. tty3270_unthrottle(struct tty_struct * tty)
  1609. {
  1610. struct tty3270 *tp;
  1611. tp = tty->driver_data;
  1612. if (!tp)
  1613. return;
  1614. tp->throttle = 0;
  1615. if (tp->attn)
  1616. tty3270_issue_read(tp, 1);
  1617. }
  1618. /*
  1619. * Hang up the tty device.
  1620. */
  1621. static void
  1622. tty3270_hangup(struct tty_struct *tty)
  1623. {
  1624. // FIXME: implement
  1625. }
  1626. static void
  1627. tty3270_wait_until_sent(struct tty_struct *tty, int timeout)
  1628. {
  1629. }
  1630. static int tty3270_ioctl(struct tty_struct *tty, unsigned int cmd,
  1631. unsigned long arg)
  1632. {
  1633. struct tty3270 *tp;
  1634. tp = tty->driver_data;
  1635. if (!tp)
  1636. return -ENODEV;
  1637. if (tty->flags & (1 << TTY_IO_ERROR))
  1638. return -EIO;
  1639. return kbd_ioctl(tp->kbd, cmd, arg);
  1640. }
  1641. #ifdef CONFIG_COMPAT
  1642. static long tty3270_compat_ioctl(struct tty_struct *tty,
  1643. unsigned int cmd, unsigned long arg)
  1644. {
  1645. struct tty3270 *tp;
  1646. tp = tty->driver_data;
  1647. if (!tp)
  1648. return -ENODEV;
  1649. if (tty->flags & (1 << TTY_IO_ERROR))
  1650. return -EIO;
  1651. return kbd_ioctl(tp->kbd, cmd, (unsigned long)compat_ptr(arg));
  1652. }
  1653. #endif
  1654. static const struct tty_operations tty3270_ops = {
  1655. .install = tty3270_install,
  1656. .cleanup = tty3270_cleanup,
  1657. .open = tty3270_open,
  1658. .close = tty3270_close,
  1659. .write = tty3270_write,
  1660. .put_char = tty3270_put_char,
  1661. .flush_chars = tty3270_flush_chars,
  1662. .write_room = tty3270_write_room,
  1663. .chars_in_buffer = tty3270_chars_in_buffer,
  1664. .flush_buffer = tty3270_flush_buffer,
  1665. .throttle = tty3270_throttle,
  1666. .unthrottle = tty3270_unthrottle,
  1667. .hangup = tty3270_hangup,
  1668. .wait_until_sent = tty3270_wait_until_sent,
  1669. .ioctl = tty3270_ioctl,
  1670. #ifdef CONFIG_COMPAT
  1671. .compat_ioctl = tty3270_compat_ioctl,
  1672. #endif
  1673. .set_termios = tty3270_set_termios
  1674. };
  1675. static void tty3270_create_cb(int minor)
  1676. {
  1677. tty_register_device(tty3270_driver, minor - RAW3270_FIRSTMINOR, NULL);
  1678. }
  1679. static void tty3270_destroy_cb(int minor)
  1680. {
  1681. tty_unregister_device(tty3270_driver, minor - RAW3270_FIRSTMINOR);
  1682. }
  1683. static struct raw3270_notifier tty3270_notifier =
  1684. {
  1685. .create = tty3270_create_cb,
  1686. .destroy = tty3270_destroy_cb,
  1687. };
  1688. /*
  1689. * 3270 tty registration code called from tty_init().
  1690. * Most kernel services (incl. kmalloc) are available at this poimt.
  1691. */
  1692. static int __init tty3270_init(void)
  1693. {
  1694. struct tty_driver *driver;
  1695. int ret;
  1696. driver = tty_alloc_driver(RAW3270_MAXDEVS,
  1697. TTY_DRIVER_REAL_RAW |
  1698. TTY_DRIVER_DYNAMIC_DEV |
  1699. TTY_DRIVER_RESET_TERMIOS);
  1700. if (IS_ERR(driver))
  1701. return PTR_ERR(driver);
  1702. /*
  1703. * Initialize the tty_driver structure
  1704. * Entries in tty3270_driver that are NOT initialized:
  1705. * proc_entry, set_termios, flush_buffer, set_ldisc, write_proc
  1706. */
  1707. driver->driver_name = "tty3270";
  1708. driver->name = "3270/tty";
  1709. driver->major = IBM_TTY3270_MAJOR;
  1710. driver->minor_start = RAW3270_FIRSTMINOR;
  1711. driver->name_base = RAW3270_FIRSTMINOR;
  1712. driver->type = TTY_DRIVER_TYPE_SYSTEM;
  1713. driver->subtype = SYSTEM_TYPE_TTY;
  1714. driver->init_termios = tty_std_termios;
  1715. tty_set_operations(driver, &tty3270_ops);
  1716. ret = tty_register_driver(driver);
  1717. if (ret) {
  1718. put_tty_driver(driver);
  1719. return ret;
  1720. }
  1721. tty3270_driver = driver;
  1722. raw3270_register_notifier(&tty3270_notifier);
  1723. return 0;
  1724. }
  1725. static void __exit
  1726. tty3270_exit(void)
  1727. {
  1728. struct tty_driver *driver;
  1729. raw3270_unregister_notifier(&tty3270_notifier);
  1730. driver = tty3270_driver;
  1731. tty3270_driver = NULL;
  1732. tty_unregister_driver(driver);
  1733. put_tty_driver(driver);
  1734. tty3270_del_views();
  1735. }
  1736. MODULE_LICENSE("GPL");
  1737. MODULE_ALIAS_CHARDEV_MAJOR(IBM_TTY3270_MAJOR);
  1738. module_init(tty3270_init);
  1739. module_exit(tty3270_exit);