tty3270.c 45 KB

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