vt.c 89 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776
  1. /*
  2. * linux/drivers/char/vt.c
  3. *
  4. * Copyright (C) 1991, 1992 Linus Torvalds
  5. */
  6. /*
  7. * Hopefully this will be a rather complete VT102 implementation.
  8. *
  9. * Beeping thanks to John T Kohl.
  10. *
  11. * Virtual Consoles, Screen Blanking, Screen Dumping, Color, Graphics
  12. * Chars, and VT100 enhancements by Peter MacDonald.
  13. *
  14. * Copy and paste function by Andrew Haylett,
  15. * some enhancements by Alessandro Rubini.
  16. *
  17. * Code to check for different video-cards mostly by Galen Hunt,
  18. * <g-hunt@ee.utah.edu>
  19. *
  20. * Rudimentary ISO 10646/Unicode/UTF-8 character set support by
  21. * Markus Kuhn, <mskuhn@immd4.informatik.uni-erlangen.de>.
  22. *
  23. * Dynamic allocation of consoles, aeb@cwi.nl, May 1994
  24. * Resizing of consoles, aeb, 940926
  25. *
  26. * Code for xterm like mouse click reporting by Peter Orbaek 20-Jul-94
  27. * <poe@daimi.aau.dk>
  28. *
  29. * User-defined bell sound, new setterm control sequences and printk
  30. * redirection by Martin Mares <mj@k332.feld.cvut.cz> 19-Nov-95
  31. *
  32. * APM screenblank bug fixed Takashi Manabe <manabe@roy.dsl.tutics.tut.jp>
  33. *
  34. * Merge with the abstract console driver by Geert Uytterhoeven
  35. * <geert@linux-m68k.org>, Jan 1997.
  36. *
  37. * Original m68k console driver modifications by
  38. *
  39. * - Arno Griffioen <arno@usn.nl>
  40. * - David Carter <carter@cs.bris.ac.uk>
  41. *
  42. * The abstract console driver provides a generic interface for a text
  43. * console. It supports VGA text mode, frame buffer based graphical consoles
  44. * and special graphics processors that are only accessible through some
  45. * registers (e.g. a TMS340x0 GSP).
  46. *
  47. * The interface to the hardware is specified using a special structure
  48. * (struct consw) which contains function pointers to console operations
  49. * (see <linux/console.h> for more information).
  50. *
  51. * Support for changeable cursor shape
  52. * by Pavel Machek <pavel@atrey.karlin.mff.cuni.cz>, August 1997
  53. *
  54. * Ported to i386 and con_scrolldelta fixed
  55. * by Emmanuel Marty <core@ggi-project.org>, April 1998
  56. *
  57. * Resurrected character buffers in videoram plus lots of other trickery
  58. * by Martin Mares <mj@atrey.karlin.mff.cuni.cz>, July 1998
  59. *
  60. * Removed old-style timers, introduced console_timer, made timer
  61. * deletion SMP-safe. 17Jun00, Andrew Morton <andrewm@uow.edu.au>
  62. *
  63. * Removed console_lock, enabled interrupts across all console operations
  64. * 13 March 2001, Andrew Morton
  65. */
  66. #include <linux/module.h>
  67. #include <linux/types.h>
  68. #include <linux/sched.h>
  69. #include <linux/tty.h>
  70. #include <linux/tty_flip.h>
  71. #include <linux/kernel.h>
  72. #include <linux/string.h>
  73. #include <linux/errno.h>
  74. #include <linux/kd.h>
  75. #include <linux/slab.h>
  76. #include <linux/major.h>
  77. #include <linux/mm.h>
  78. #include <linux/console.h>
  79. #include <linux/init.h>
  80. #include <linux/vt_kern.h>
  81. #include <linux/selection.h>
  82. #include <linux/tiocl.h>
  83. #include <linux/kbd_kern.h>
  84. #include <linux/consolemap.h>
  85. #include <linux/timer.h>
  86. #include <linux/interrupt.h>
  87. #include <linux/config.h>
  88. #include <linux/workqueue.h>
  89. #include <linux/bootmem.h>
  90. #include <linux/pm.h>
  91. #include <linux/font.h>
  92. #include <linux/bitops.h>
  93. #include <asm/io.h>
  94. #include <asm/system.h>
  95. #include <asm/uaccess.h>
  96. #define MAX_NR_CON_DRIVER 16
  97. #define CON_DRIVER_FLAG_MODULE 1
  98. #define CON_DRIVER_FLAG_INIT 2
  99. struct con_driver {
  100. const struct consw *con;
  101. const char *desc;
  102. struct class_device *class_dev;
  103. int node;
  104. int first;
  105. int last;
  106. int flag;
  107. };
  108. static struct con_driver registered_con_driver[MAX_NR_CON_DRIVER];
  109. const struct consw *conswitchp;
  110. /* A bitmap for codes <32. A bit of 1 indicates that the code
  111. * corresponding to that bit number invokes some special action
  112. * (such as cursor movement) and should not be displayed as a
  113. * glyph unless the disp_ctrl mode is explicitly enabled.
  114. */
  115. #define CTRL_ACTION 0x0d00ff81
  116. #define CTRL_ALWAYS 0x0800f501 /* Cannot be overridden by disp_ctrl */
  117. /*
  118. * Here is the default bell parameters: 750HZ, 1/8th of a second
  119. */
  120. #define DEFAULT_BELL_PITCH 750
  121. #define DEFAULT_BELL_DURATION (HZ/8)
  122. extern void vcs_make_devfs(struct tty_struct *tty);
  123. extern void vcs_remove_devfs(struct tty_struct *tty);
  124. extern void console_map_init(void);
  125. #ifdef CONFIG_PROM_CONSOLE
  126. extern void prom_con_init(void);
  127. #endif
  128. #ifdef CONFIG_MDA_CONSOLE
  129. extern int mda_console_init(void);
  130. #endif
  131. struct vc vc_cons [MAX_NR_CONSOLES];
  132. #ifndef VT_SINGLE_DRIVER
  133. static const struct consw *con_driver_map[MAX_NR_CONSOLES];
  134. #endif
  135. static int con_open(struct tty_struct *, struct file *);
  136. static void vc_init(struct vc_data *vc, unsigned int rows,
  137. unsigned int cols, int do_clear);
  138. static void gotoxy(struct vc_data *vc, int new_x, int new_y);
  139. static void save_cur(struct vc_data *vc);
  140. static void reset_terminal(struct vc_data *vc, int do_clear);
  141. static void con_flush_chars(struct tty_struct *tty);
  142. static void set_vesa_blanking(char __user *p);
  143. static void set_cursor(struct vc_data *vc);
  144. static void hide_cursor(struct vc_data *vc);
  145. static void console_callback(void *ignored);
  146. static void blank_screen_t(unsigned long dummy);
  147. static void set_palette(struct vc_data *vc);
  148. static int printable; /* Is console ready for printing? */
  149. /*
  150. * ignore_poke: don't unblank the screen when things are typed. This is
  151. * mainly for the privacy of braille terminal users.
  152. */
  153. static int ignore_poke;
  154. int do_poke_blanked_console;
  155. int console_blanked;
  156. static int vesa_blank_mode; /* 0:none 1:suspendV 2:suspendH 3:powerdown */
  157. static int blankinterval = 10*60*HZ;
  158. static int vesa_off_interval;
  159. static DECLARE_WORK(console_work, console_callback, NULL);
  160. /*
  161. * fg_console is the current virtual console,
  162. * last_console is the last used one,
  163. * want_console is the console we want to switch to,
  164. * kmsg_redirect is the console for kernel messages,
  165. */
  166. int fg_console;
  167. int last_console;
  168. int want_console = -1;
  169. int kmsg_redirect;
  170. /*
  171. * For each existing display, we have a pointer to console currently visible
  172. * on that display, allowing consoles other than fg_console to be refreshed
  173. * appropriately. Unless the low-level driver supplies its own display_fg
  174. * variable, we use this one for the "master display".
  175. */
  176. static struct vc_data *master_display_fg;
  177. /*
  178. * Unfortunately, we need to delay tty echo when we're currently writing to the
  179. * console since the code is (and always was) not re-entrant, so we schedule
  180. * all flip requests to process context with schedule-task() and run it from
  181. * console_callback().
  182. */
  183. /*
  184. * For the same reason, we defer scrollback to the console callback.
  185. */
  186. static int scrollback_delta;
  187. /*
  188. * Hook so that the power management routines can (un)blank
  189. * the console on our behalf.
  190. */
  191. int (*console_blank_hook)(int);
  192. static struct timer_list console_timer;
  193. static int blank_state;
  194. static int blank_timer_expired;
  195. enum {
  196. blank_off = 0,
  197. blank_normal_wait,
  198. blank_vesa_wait,
  199. };
  200. /*
  201. * Low-Level Functions
  202. */
  203. #define IS_FG(vc) ((vc)->vc_num == fg_console)
  204. #ifdef VT_BUF_VRAM_ONLY
  205. #define DO_UPDATE(vc) 0
  206. #else
  207. #define DO_UPDATE(vc) CON_IS_VISIBLE(vc)
  208. #endif
  209. static inline unsigned short *screenpos(struct vc_data *vc, int offset, int viewed)
  210. {
  211. unsigned short *p;
  212. if (!viewed)
  213. p = (unsigned short *)(vc->vc_origin + offset);
  214. else if (!vc->vc_sw->con_screen_pos)
  215. p = (unsigned short *)(vc->vc_visible_origin + offset);
  216. else
  217. p = vc->vc_sw->con_screen_pos(vc, offset);
  218. return p;
  219. }
  220. static inline void scrolldelta(int lines)
  221. {
  222. scrollback_delta += lines;
  223. schedule_console_callback();
  224. }
  225. void schedule_console_callback(void)
  226. {
  227. schedule_work(&console_work);
  228. }
  229. static void scrup(struct vc_data *vc, unsigned int t, unsigned int b, int nr)
  230. {
  231. unsigned short *d, *s;
  232. if (t+nr >= b)
  233. nr = b - t - 1;
  234. if (b > vc->vc_rows || t >= b || nr < 1)
  235. return;
  236. if (CON_IS_VISIBLE(vc) && vc->vc_sw->con_scroll(vc, t, b, SM_UP, nr))
  237. return;
  238. d = (unsigned short *)(vc->vc_origin + vc->vc_size_row * t);
  239. s = (unsigned short *)(vc->vc_origin + vc->vc_size_row * (t + nr));
  240. scr_memmovew(d, s, (b - t - nr) * vc->vc_size_row);
  241. scr_memsetw(d + (b - t - nr) * vc->vc_cols, vc->vc_video_erase_char,
  242. vc->vc_size_row * nr);
  243. }
  244. static void scrdown(struct vc_data *vc, unsigned int t, unsigned int b, int nr)
  245. {
  246. unsigned short *s;
  247. unsigned int step;
  248. if (t+nr >= b)
  249. nr = b - t - 1;
  250. if (b > vc->vc_rows || t >= b || nr < 1)
  251. return;
  252. if (CON_IS_VISIBLE(vc) && vc->vc_sw->con_scroll(vc, t, b, SM_DOWN, nr))
  253. return;
  254. s = (unsigned short *)(vc->vc_origin + vc->vc_size_row * t);
  255. step = vc->vc_cols * nr;
  256. scr_memmovew(s + step, s, (b - t - nr) * vc->vc_size_row);
  257. scr_memsetw(s, vc->vc_video_erase_char, 2 * step);
  258. }
  259. static void do_update_region(struct vc_data *vc, unsigned long start, int count)
  260. {
  261. #ifndef VT_BUF_VRAM_ONLY
  262. unsigned int xx, yy, offset;
  263. u16 *p;
  264. p = (u16 *) start;
  265. if (!vc->vc_sw->con_getxy) {
  266. offset = (start - vc->vc_origin) / 2;
  267. xx = offset % vc->vc_cols;
  268. yy = offset / vc->vc_cols;
  269. } else {
  270. int nxx, nyy;
  271. start = vc->vc_sw->con_getxy(vc, start, &nxx, &nyy);
  272. xx = nxx; yy = nyy;
  273. }
  274. for(;;) {
  275. u16 attrib = scr_readw(p) & 0xff00;
  276. int startx = xx;
  277. u16 *q = p;
  278. while (xx < vc->vc_cols && count) {
  279. if (attrib != (scr_readw(p) & 0xff00)) {
  280. if (p > q)
  281. vc->vc_sw->con_putcs(vc, q, p-q, yy, startx);
  282. startx = xx;
  283. q = p;
  284. attrib = scr_readw(p) & 0xff00;
  285. }
  286. p++;
  287. xx++;
  288. count--;
  289. }
  290. if (p > q)
  291. vc->vc_sw->con_putcs(vc, q, p-q, yy, startx);
  292. if (!count)
  293. break;
  294. xx = 0;
  295. yy++;
  296. if (vc->vc_sw->con_getxy) {
  297. p = (u16 *)start;
  298. start = vc->vc_sw->con_getxy(vc, start, NULL, NULL);
  299. }
  300. }
  301. #endif
  302. }
  303. void update_region(struct vc_data *vc, unsigned long start, int count)
  304. {
  305. WARN_CONSOLE_UNLOCKED();
  306. if (DO_UPDATE(vc)) {
  307. hide_cursor(vc);
  308. do_update_region(vc, start, count);
  309. set_cursor(vc);
  310. }
  311. }
  312. /* Structure of attributes is hardware-dependent */
  313. static u8 build_attr(struct vc_data *vc, u8 _color, u8 _intensity, u8 _blink, u8 _underline, u8 _reverse)
  314. {
  315. if (vc->vc_sw->con_build_attr)
  316. return vc->vc_sw->con_build_attr(vc, _color, _intensity, _blink, _underline, _reverse);
  317. #ifndef VT_BUF_VRAM_ONLY
  318. /*
  319. * ++roman: I completely changed the attribute format for monochrome
  320. * mode (!can_do_color). The formerly used MDA (monochrome display
  321. * adapter) format didn't allow the combination of certain effects.
  322. * Now the attribute is just a bit vector:
  323. * Bit 0..1: intensity (0..2)
  324. * Bit 2 : underline
  325. * Bit 3 : reverse
  326. * Bit 7 : blink
  327. */
  328. {
  329. u8 a = vc->vc_color;
  330. if (!vc->vc_can_do_color)
  331. return _intensity |
  332. (_underline ? 4 : 0) |
  333. (_reverse ? 8 : 0) |
  334. (_blink ? 0x80 : 0);
  335. if (_underline)
  336. a = (a & 0xf0) | vc->vc_ulcolor;
  337. else if (_intensity == 0)
  338. a = (a & 0xf0) | vc->vc_ulcolor;
  339. if (_reverse)
  340. a = ((a) & 0x88) | ((((a) >> 4) | ((a) << 4)) & 0x77);
  341. if (_blink)
  342. a ^= 0x80;
  343. if (_intensity == 2)
  344. a ^= 0x08;
  345. if (vc->vc_hi_font_mask == 0x100)
  346. a <<= 1;
  347. return a;
  348. }
  349. #else
  350. return 0;
  351. #endif
  352. }
  353. static void update_attr(struct vc_data *vc)
  354. {
  355. vc->vc_attr = build_attr(vc, vc->vc_color, vc->vc_intensity, vc->vc_blink, vc->vc_underline, vc->vc_reverse ^ vc->vc_decscnm);
  356. vc->vc_video_erase_char = (build_attr(vc, vc->vc_color, 1, vc->vc_blink, 0, vc->vc_decscnm) << 8) | ' ';
  357. }
  358. /* Note: inverting the screen twice should revert to the original state */
  359. void invert_screen(struct vc_data *vc, int offset, int count, int viewed)
  360. {
  361. unsigned short *p;
  362. WARN_CONSOLE_UNLOCKED();
  363. count /= 2;
  364. p = screenpos(vc, offset, viewed);
  365. if (vc->vc_sw->con_invert_region)
  366. vc->vc_sw->con_invert_region(vc, p, count);
  367. #ifndef VT_BUF_VRAM_ONLY
  368. else {
  369. u16 *q = p;
  370. int cnt = count;
  371. u16 a;
  372. if (!vc->vc_can_do_color) {
  373. while (cnt--) {
  374. a = scr_readw(q);
  375. a ^= 0x0800;
  376. scr_writew(a, q);
  377. q++;
  378. }
  379. } else if (vc->vc_hi_font_mask == 0x100) {
  380. while (cnt--) {
  381. a = scr_readw(q);
  382. a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) | (((a) & 0x0e00) << 4);
  383. scr_writew(a, q);
  384. q++;
  385. }
  386. } else {
  387. while (cnt--) {
  388. a = scr_readw(q);
  389. a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) | (((a) & 0x0700) << 4);
  390. scr_writew(a, q);
  391. q++;
  392. }
  393. }
  394. }
  395. #endif
  396. if (DO_UPDATE(vc))
  397. do_update_region(vc, (unsigned long) p, count);
  398. }
  399. /* used by selection: complement pointer position */
  400. void complement_pos(struct vc_data *vc, int offset)
  401. {
  402. static int old_offset = -1;
  403. static unsigned short old;
  404. static unsigned short oldx, oldy;
  405. WARN_CONSOLE_UNLOCKED();
  406. if (old_offset != -1 && old_offset >= 0 &&
  407. old_offset < vc->vc_screenbuf_size) {
  408. scr_writew(old, screenpos(vc, old_offset, 1));
  409. if (DO_UPDATE(vc))
  410. vc->vc_sw->con_putc(vc, old, oldy, oldx);
  411. }
  412. old_offset = offset;
  413. if (offset != -1 && offset >= 0 &&
  414. offset < vc->vc_screenbuf_size) {
  415. unsigned short new;
  416. unsigned short *p;
  417. p = screenpos(vc, offset, 1);
  418. old = scr_readw(p);
  419. new = old ^ vc->vc_complement_mask;
  420. scr_writew(new, p);
  421. if (DO_UPDATE(vc)) {
  422. oldx = (offset >> 1) % vc->vc_cols;
  423. oldy = (offset >> 1) / vc->vc_cols;
  424. vc->vc_sw->con_putc(vc, new, oldy, oldx);
  425. }
  426. }
  427. }
  428. static void insert_char(struct vc_data *vc, unsigned int nr)
  429. {
  430. unsigned short *p, *q = (unsigned short *)vc->vc_pos;
  431. p = q + vc->vc_cols - nr - vc->vc_x;
  432. while (--p >= q)
  433. scr_writew(scr_readw(p), p + nr);
  434. scr_memsetw(q, vc->vc_video_erase_char, nr * 2);
  435. vc->vc_need_wrap = 0;
  436. if (DO_UPDATE(vc)) {
  437. unsigned short oldattr = vc->vc_attr;
  438. vc->vc_sw->con_bmove(vc, vc->vc_y, vc->vc_x, vc->vc_y, vc->vc_x + nr, 1,
  439. vc->vc_cols - vc->vc_x - nr);
  440. vc->vc_attr = vc->vc_video_erase_char >> 8;
  441. while (nr--)
  442. vc->vc_sw->con_putc(vc, vc->vc_video_erase_char, vc->vc_y, vc->vc_x + nr);
  443. vc->vc_attr = oldattr;
  444. }
  445. }
  446. static void delete_char(struct vc_data *vc, unsigned int nr)
  447. {
  448. unsigned int i = vc->vc_x;
  449. unsigned short *p = (unsigned short *)vc->vc_pos;
  450. while (++i <= vc->vc_cols - nr) {
  451. scr_writew(scr_readw(p+nr), p);
  452. p++;
  453. }
  454. scr_memsetw(p, vc->vc_video_erase_char, nr * 2);
  455. vc->vc_need_wrap = 0;
  456. if (DO_UPDATE(vc)) {
  457. unsigned short oldattr = vc->vc_attr;
  458. vc->vc_sw->con_bmove(vc, vc->vc_y, vc->vc_x + nr, vc->vc_y, vc->vc_x, 1,
  459. vc->vc_cols - vc->vc_x - nr);
  460. vc->vc_attr = vc->vc_video_erase_char >> 8;
  461. while (nr--)
  462. vc->vc_sw->con_putc(vc, vc->vc_video_erase_char, vc->vc_y,
  463. vc->vc_cols - 1 - nr);
  464. vc->vc_attr = oldattr;
  465. }
  466. }
  467. static int softcursor_original;
  468. static void add_softcursor(struct vc_data *vc)
  469. {
  470. int i = scr_readw((u16 *) vc->vc_pos);
  471. u32 type = vc->vc_cursor_type;
  472. if (! (type & 0x10)) return;
  473. if (softcursor_original != -1) return;
  474. softcursor_original = i;
  475. i |= ((type >> 8) & 0xff00 );
  476. i ^= ((type) & 0xff00 );
  477. if ((type & 0x20) && ((softcursor_original & 0x7000) == (i & 0x7000))) i ^= 0x7000;
  478. if ((type & 0x40) && ((i & 0x700) == ((i & 0x7000) >> 4))) i ^= 0x0700;
  479. scr_writew(i, (u16 *) vc->vc_pos);
  480. if (DO_UPDATE(vc))
  481. vc->vc_sw->con_putc(vc, i, vc->vc_y, vc->vc_x);
  482. }
  483. static void hide_softcursor(struct vc_data *vc)
  484. {
  485. if (softcursor_original != -1) {
  486. scr_writew(softcursor_original, (u16 *)vc->vc_pos);
  487. if (DO_UPDATE(vc))
  488. vc->vc_sw->con_putc(vc, softcursor_original,
  489. vc->vc_y, vc->vc_x);
  490. softcursor_original = -1;
  491. }
  492. }
  493. static void hide_cursor(struct vc_data *vc)
  494. {
  495. if (vc == sel_cons)
  496. clear_selection();
  497. vc->vc_sw->con_cursor(vc, CM_ERASE);
  498. hide_softcursor(vc);
  499. }
  500. static void set_cursor(struct vc_data *vc)
  501. {
  502. if (!IS_FG(vc) || console_blanked ||
  503. vc->vc_mode == KD_GRAPHICS)
  504. return;
  505. if (vc->vc_deccm) {
  506. if (vc == sel_cons)
  507. clear_selection();
  508. add_softcursor(vc);
  509. if ((vc->vc_cursor_type & 0x0f) != 1)
  510. vc->vc_sw->con_cursor(vc, CM_DRAW);
  511. } else
  512. hide_cursor(vc);
  513. }
  514. static void set_origin(struct vc_data *vc)
  515. {
  516. WARN_CONSOLE_UNLOCKED();
  517. if (!CON_IS_VISIBLE(vc) ||
  518. !vc->vc_sw->con_set_origin ||
  519. !vc->vc_sw->con_set_origin(vc))
  520. vc->vc_origin = (unsigned long)vc->vc_screenbuf;
  521. vc->vc_visible_origin = vc->vc_origin;
  522. vc->vc_scr_end = vc->vc_origin + vc->vc_screenbuf_size;
  523. vc->vc_pos = vc->vc_origin + vc->vc_size_row * vc->vc_y + 2 * vc->vc_x;
  524. }
  525. static inline void save_screen(struct vc_data *vc)
  526. {
  527. WARN_CONSOLE_UNLOCKED();
  528. if (vc->vc_sw->con_save_screen)
  529. vc->vc_sw->con_save_screen(vc);
  530. }
  531. /*
  532. * Redrawing of screen
  533. */
  534. static void clear_buffer_attributes(struct vc_data *vc)
  535. {
  536. unsigned short *p = (unsigned short *)vc->vc_origin;
  537. int count = vc->vc_screenbuf_size / 2;
  538. int mask = vc->vc_hi_font_mask | 0xff;
  539. for (; count > 0; count--, p++) {
  540. scr_writew((scr_readw(p)&mask) | (vc->vc_video_erase_char & ~mask), p);
  541. }
  542. }
  543. void redraw_screen(struct vc_data *vc, int is_switch)
  544. {
  545. int redraw = 0;
  546. WARN_CONSOLE_UNLOCKED();
  547. if (!vc) {
  548. /* strange ... */
  549. /* printk("redraw_screen: tty %d not allocated ??\n", new_console+1); */
  550. return;
  551. }
  552. if (is_switch) {
  553. struct vc_data *old_vc = vc_cons[fg_console].d;
  554. if (old_vc == vc)
  555. return;
  556. if (!CON_IS_VISIBLE(vc))
  557. redraw = 1;
  558. *vc->vc_display_fg = vc;
  559. fg_console = vc->vc_num;
  560. hide_cursor(old_vc);
  561. if (!CON_IS_VISIBLE(old_vc)) {
  562. save_screen(old_vc);
  563. set_origin(old_vc);
  564. }
  565. } else {
  566. hide_cursor(vc);
  567. redraw = 1;
  568. }
  569. if (redraw) {
  570. int update;
  571. int old_was_color = vc->vc_can_do_color;
  572. set_origin(vc);
  573. update = vc->vc_sw->con_switch(vc);
  574. set_palette(vc);
  575. /*
  576. * If console changed from mono<->color, the best we can do
  577. * is to clear the buffer attributes. As it currently stands,
  578. * rebuilding new attributes from the old buffer is not doable
  579. * without overly complex code.
  580. */
  581. if (old_was_color != vc->vc_can_do_color) {
  582. update_attr(vc);
  583. clear_buffer_attributes(vc);
  584. }
  585. if (update && vc->vc_mode != KD_GRAPHICS)
  586. do_update_region(vc, vc->vc_origin, vc->vc_screenbuf_size / 2);
  587. }
  588. set_cursor(vc);
  589. if (is_switch) {
  590. set_leds();
  591. compute_shiftstate();
  592. }
  593. }
  594. /*
  595. * Allocation, freeing and resizing of VTs.
  596. */
  597. int vc_cons_allocated(unsigned int i)
  598. {
  599. return (i < MAX_NR_CONSOLES && vc_cons[i].d);
  600. }
  601. static void visual_init(struct vc_data *vc, int num, int init)
  602. {
  603. /* ++Geert: vc->vc_sw->con_init determines console size */
  604. if (vc->vc_sw)
  605. module_put(vc->vc_sw->owner);
  606. vc->vc_sw = conswitchp;
  607. #ifndef VT_SINGLE_DRIVER
  608. if (con_driver_map[num])
  609. vc->vc_sw = con_driver_map[num];
  610. #endif
  611. __module_get(vc->vc_sw->owner);
  612. vc->vc_num = num;
  613. vc->vc_display_fg = &master_display_fg;
  614. vc->vc_uni_pagedir_loc = &vc->vc_uni_pagedir;
  615. vc->vc_uni_pagedir = 0;
  616. vc->vc_hi_font_mask = 0;
  617. vc->vc_complement_mask = 0;
  618. vc->vc_can_do_color = 0;
  619. vc->vc_sw->con_init(vc, init);
  620. if (!vc->vc_complement_mask)
  621. vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
  622. vc->vc_s_complement_mask = vc->vc_complement_mask;
  623. vc->vc_size_row = vc->vc_cols << 1;
  624. vc->vc_screenbuf_size = vc->vc_rows * vc->vc_size_row;
  625. }
  626. int vc_allocate(unsigned int currcons) /* return 0 on success */
  627. {
  628. WARN_CONSOLE_UNLOCKED();
  629. if (currcons >= MAX_NR_CONSOLES)
  630. return -ENXIO;
  631. if (!vc_cons[currcons].d) {
  632. struct vc_data *vc;
  633. /* prevent users from taking too much memory */
  634. if (currcons >= MAX_NR_USER_CONSOLES && !capable(CAP_SYS_RESOURCE))
  635. return -EPERM;
  636. /* due to the granularity of kmalloc, we waste some memory here */
  637. /* the alloc is done in two steps, to optimize the common situation
  638. of a 25x80 console (structsize=216, screenbuf_size=4000) */
  639. /* although the numbers above are not valid since long ago, the
  640. point is still up-to-date and the comment still has its value
  641. even if only as a historical artifact. --mj, July 1998 */
  642. vc = kmalloc(sizeof(struct vc_data), GFP_KERNEL);
  643. if (!vc)
  644. return -ENOMEM;
  645. memset(vc, 0, sizeof(*vc));
  646. vc_cons[currcons].d = vc;
  647. visual_init(vc, currcons, 1);
  648. if (!*vc->vc_uni_pagedir_loc)
  649. con_set_default_unimap(vc);
  650. vc->vc_screenbuf = kmalloc(vc->vc_screenbuf_size, GFP_KERNEL);
  651. if (!vc->vc_screenbuf) {
  652. kfree(vc);
  653. vc_cons[currcons].d = NULL;
  654. return -ENOMEM;
  655. }
  656. vc->vc_kmalloced = 1;
  657. vc_init(vc, vc->vc_rows, vc->vc_cols, 1);
  658. }
  659. return 0;
  660. }
  661. static inline int resize_screen(struct vc_data *vc, int width, int height)
  662. {
  663. /* Resizes the resolution of the display adapater */
  664. int err = 0;
  665. if (vc->vc_mode != KD_GRAPHICS && vc->vc_sw->con_resize)
  666. err = vc->vc_sw->con_resize(vc, width, height);
  667. return err;
  668. }
  669. /*
  670. * Change # of rows and columns (0 means unchanged/the size of fg_console)
  671. * [this is to be used together with some user program
  672. * like resize that changes the hardware videomode]
  673. */
  674. #define VC_RESIZE_MAXCOL (32767)
  675. #define VC_RESIZE_MAXROW (32767)
  676. int vc_resize(struct vc_data *vc, unsigned int cols, unsigned int lines)
  677. {
  678. unsigned long old_origin, new_origin, new_scr_end, rlth, rrem, err = 0;
  679. unsigned int old_cols, old_rows, old_row_size, old_screen_size;
  680. unsigned int new_cols, new_rows, new_row_size, new_screen_size;
  681. unsigned int end;
  682. unsigned short *newscreen;
  683. WARN_CONSOLE_UNLOCKED();
  684. if (!vc)
  685. return -ENXIO;
  686. if (cols > VC_RESIZE_MAXCOL || lines > VC_RESIZE_MAXROW)
  687. return -EINVAL;
  688. new_cols = (cols ? cols : vc->vc_cols);
  689. new_rows = (lines ? lines : vc->vc_rows);
  690. new_row_size = new_cols << 1;
  691. new_screen_size = new_row_size * new_rows;
  692. if (new_cols == vc->vc_cols && new_rows == vc->vc_rows)
  693. return 0;
  694. newscreen = (unsigned short *) kmalloc(new_screen_size, GFP_USER);
  695. if (!newscreen)
  696. return -ENOMEM;
  697. old_rows = vc->vc_rows;
  698. old_cols = vc->vc_cols;
  699. old_row_size = vc->vc_size_row;
  700. old_screen_size = vc->vc_screenbuf_size;
  701. err = resize_screen(vc, new_cols, new_rows);
  702. if (err) {
  703. kfree(newscreen);
  704. return err;
  705. }
  706. vc->vc_rows = new_rows;
  707. vc->vc_cols = new_cols;
  708. vc->vc_size_row = new_row_size;
  709. vc->vc_screenbuf_size = new_screen_size;
  710. rlth = min(old_row_size, new_row_size);
  711. rrem = new_row_size - rlth;
  712. old_origin = vc->vc_origin;
  713. new_origin = (long) newscreen;
  714. new_scr_end = new_origin + new_screen_size;
  715. if (vc->vc_y > new_rows) {
  716. if (old_rows - vc->vc_y < new_rows) {
  717. /*
  718. * Cursor near the bottom, copy contents from the
  719. * bottom of buffer
  720. */
  721. old_origin += (old_rows - new_rows) * old_row_size;
  722. end = vc->vc_scr_end;
  723. } else {
  724. /*
  725. * Cursor is in no man's land, copy 1/2 screenful
  726. * from the top and bottom of cursor position
  727. */
  728. old_origin += (vc->vc_y - new_rows/2) * old_row_size;
  729. end = old_origin + (old_row_size * new_rows);
  730. }
  731. } else
  732. /*
  733. * Cursor near the top, copy contents from the top of buffer
  734. */
  735. end = (old_rows > new_rows) ? old_origin +
  736. (old_row_size * new_rows) :
  737. vc->vc_scr_end;
  738. update_attr(vc);
  739. while (old_origin < end) {
  740. scr_memcpyw((unsigned short *) new_origin,
  741. (unsigned short *) old_origin, rlth);
  742. if (rrem)
  743. scr_memsetw((void *)(new_origin + rlth),
  744. vc->vc_video_erase_char, rrem);
  745. old_origin += old_row_size;
  746. new_origin += new_row_size;
  747. }
  748. if (new_scr_end > new_origin)
  749. scr_memsetw((void *)new_origin, vc->vc_video_erase_char,
  750. new_scr_end - new_origin);
  751. if (vc->vc_kmalloced)
  752. kfree(vc->vc_screenbuf);
  753. vc->vc_screenbuf = newscreen;
  754. vc->vc_kmalloced = 1;
  755. vc->vc_screenbuf_size = new_screen_size;
  756. set_origin(vc);
  757. /* do part of a reset_terminal() */
  758. vc->vc_top = 0;
  759. vc->vc_bottom = vc->vc_rows;
  760. gotoxy(vc, vc->vc_x, vc->vc_y);
  761. save_cur(vc);
  762. if (vc->vc_tty) {
  763. struct winsize ws, *cws = &vc->vc_tty->winsize;
  764. memset(&ws, 0, sizeof(ws));
  765. ws.ws_row = vc->vc_rows;
  766. ws.ws_col = vc->vc_cols;
  767. ws.ws_ypixel = vc->vc_scan_lines;
  768. if ((ws.ws_row != cws->ws_row || ws.ws_col != cws->ws_col) &&
  769. vc->vc_tty->pgrp > 0)
  770. kill_pg(vc->vc_tty->pgrp, SIGWINCH, 1);
  771. *cws = ws;
  772. }
  773. if (CON_IS_VISIBLE(vc))
  774. update_screen(vc);
  775. return err;
  776. }
  777. void vc_disallocate(unsigned int currcons)
  778. {
  779. WARN_CONSOLE_UNLOCKED();
  780. if (vc_cons_allocated(currcons)) {
  781. struct vc_data *vc = vc_cons[currcons].d;
  782. vc->vc_sw->con_deinit(vc);
  783. if (vc->vc_kmalloced)
  784. kfree(vc->vc_screenbuf);
  785. if (currcons >= MIN_NR_CONSOLES)
  786. kfree(vc);
  787. vc_cons[currcons].d = NULL;
  788. }
  789. }
  790. /*
  791. * VT102 emulator
  792. */
  793. #define set_kbd(vc, x) set_vc_kbd_mode(kbd_table + (vc)->vc_num, (x))
  794. #define clr_kbd(vc, x) clr_vc_kbd_mode(kbd_table + (vc)->vc_num, (x))
  795. #define is_kbd(vc, x) vc_kbd_mode(kbd_table + (vc)->vc_num, (x))
  796. #define decarm VC_REPEAT
  797. #define decckm VC_CKMODE
  798. #define kbdapplic VC_APPLIC
  799. #define lnm VC_CRLF
  800. /*
  801. * this is what the terminal answers to a ESC-Z or csi0c query.
  802. */
  803. #define VT100ID "\033[?1;2c"
  804. #define VT102ID "\033[?6c"
  805. unsigned char color_table[] = { 0, 4, 2, 6, 1, 5, 3, 7,
  806. 8,12,10,14, 9,13,11,15 };
  807. /* the default colour table, for VGA+ colour systems */
  808. int default_red[] = {0x00,0xaa,0x00,0xaa,0x00,0xaa,0x00,0xaa,
  809. 0x55,0xff,0x55,0xff,0x55,0xff,0x55,0xff};
  810. int default_grn[] = {0x00,0x00,0xaa,0x55,0x00,0x00,0xaa,0xaa,
  811. 0x55,0x55,0xff,0xff,0x55,0x55,0xff,0xff};
  812. int default_blu[] = {0x00,0x00,0x00,0x00,0xaa,0xaa,0xaa,0xaa,
  813. 0x55,0x55,0x55,0x55,0xff,0xff,0xff,0xff};
  814. /*
  815. * gotoxy() must verify all boundaries, because the arguments
  816. * might also be negative. If the given position is out of
  817. * bounds, the cursor is placed at the nearest margin.
  818. */
  819. static void gotoxy(struct vc_data *vc, int new_x, int new_y)
  820. {
  821. int min_y, max_y;
  822. if (new_x < 0)
  823. vc->vc_x = 0;
  824. else {
  825. if (new_x >= vc->vc_cols)
  826. vc->vc_x = vc->vc_cols - 1;
  827. else
  828. vc->vc_x = new_x;
  829. }
  830. if (vc->vc_decom) {
  831. min_y = vc->vc_top;
  832. max_y = vc->vc_bottom;
  833. } else {
  834. min_y = 0;
  835. max_y = vc->vc_rows;
  836. }
  837. if (new_y < min_y)
  838. vc->vc_y = min_y;
  839. else if (new_y >= max_y)
  840. vc->vc_y = max_y - 1;
  841. else
  842. vc->vc_y = new_y;
  843. vc->vc_pos = vc->vc_origin + vc->vc_y * vc->vc_size_row + (vc->vc_x<<1);
  844. vc->vc_need_wrap = 0;
  845. }
  846. /* for absolute user moves, when decom is set */
  847. static void gotoxay(struct vc_data *vc, int new_x, int new_y)
  848. {
  849. gotoxy(vc, new_x, vc->vc_decom ? (vc->vc_top + new_y) : new_y);
  850. }
  851. void scrollback(struct vc_data *vc, int lines)
  852. {
  853. if (!lines)
  854. lines = vc->vc_rows / 2;
  855. scrolldelta(-lines);
  856. }
  857. void scrollfront(struct vc_data *vc, int lines)
  858. {
  859. if (!lines)
  860. lines = vc->vc_rows / 2;
  861. scrolldelta(lines);
  862. }
  863. static void lf(struct vc_data *vc)
  864. {
  865. /* don't scroll if above bottom of scrolling region, or
  866. * if below scrolling region
  867. */
  868. if (vc->vc_y + 1 == vc->vc_bottom)
  869. scrup(vc, vc->vc_top, vc->vc_bottom, 1);
  870. else if (vc->vc_y < vc->vc_rows - 1) {
  871. vc->vc_y++;
  872. vc->vc_pos += vc->vc_size_row;
  873. }
  874. vc->vc_need_wrap = 0;
  875. }
  876. static void ri(struct vc_data *vc)
  877. {
  878. /* don't scroll if below top of scrolling region, or
  879. * if above scrolling region
  880. */
  881. if (vc->vc_y == vc->vc_top)
  882. scrdown(vc, vc->vc_top, vc->vc_bottom, 1);
  883. else if (vc->vc_y > 0) {
  884. vc->vc_y--;
  885. vc->vc_pos -= vc->vc_size_row;
  886. }
  887. vc->vc_need_wrap = 0;
  888. }
  889. static inline void cr(struct vc_data *vc)
  890. {
  891. vc->vc_pos -= vc->vc_x << 1;
  892. vc->vc_need_wrap = vc->vc_x = 0;
  893. }
  894. static inline void bs(struct vc_data *vc)
  895. {
  896. if (vc->vc_x) {
  897. vc->vc_pos -= 2;
  898. vc->vc_x--;
  899. vc->vc_need_wrap = 0;
  900. }
  901. }
  902. static inline void del(struct vc_data *vc)
  903. {
  904. /* ignored */
  905. }
  906. static void csi_J(struct vc_data *vc, int vpar)
  907. {
  908. unsigned int count;
  909. unsigned short * start;
  910. switch (vpar) {
  911. case 0: /* erase from cursor to end of display */
  912. count = (vc->vc_scr_end - vc->vc_pos) >> 1;
  913. start = (unsigned short *)vc->vc_pos;
  914. if (DO_UPDATE(vc)) {
  915. /* do in two stages */
  916. vc->vc_sw->con_clear(vc, vc->vc_y, vc->vc_x, 1,
  917. vc->vc_cols - vc->vc_x);
  918. vc->vc_sw->con_clear(vc, vc->vc_y + 1, 0,
  919. vc->vc_rows - vc->vc_y - 1,
  920. vc->vc_cols);
  921. }
  922. break;
  923. case 1: /* erase from start to cursor */
  924. count = ((vc->vc_pos - vc->vc_origin) >> 1) + 1;
  925. start = (unsigned short *)vc->vc_origin;
  926. if (DO_UPDATE(vc)) {
  927. /* do in two stages */
  928. vc->vc_sw->con_clear(vc, 0, 0, vc->vc_y,
  929. vc->vc_cols);
  930. vc->vc_sw->con_clear(vc, vc->vc_y, 0, 1,
  931. vc->vc_x + 1);
  932. }
  933. break;
  934. case 2: /* erase whole display */
  935. count = vc->vc_cols * vc->vc_rows;
  936. start = (unsigned short *)vc->vc_origin;
  937. if (DO_UPDATE(vc))
  938. vc->vc_sw->con_clear(vc, 0, 0,
  939. vc->vc_rows,
  940. vc->vc_cols);
  941. break;
  942. default:
  943. return;
  944. }
  945. scr_memsetw(start, vc->vc_video_erase_char, 2 * count);
  946. vc->vc_need_wrap = 0;
  947. }
  948. static void csi_K(struct vc_data *vc, int vpar)
  949. {
  950. unsigned int count;
  951. unsigned short * start;
  952. switch (vpar) {
  953. case 0: /* erase from cursor to end of line */
  954. count = vc->vc_cols - vc->vc_x;
  955. start = (unsigned short *)vc->vc_pos;
  956. if (DO_UPDATE(vc))
  957. vc->vc_sw->con_clear(vc, vc->vc_y, vc->vc_x, 1,
  958. vc->vc_cols - vc->vc_x);
  959. break;
  960. case 1: /* erase from start of line to cursor */
  961. start = (unsigned short *)(vc->vc_pos - (vc->vc_x << 1));
  962. count = vc->vc_x + 1;
  963. if (DO_UPDATE(vc))
  964. vc->vc_sw->con_clear(vc, vc->vc_y, 0, 1,
  965. vc->vc_x + 1);
  966. break;
  967. case 2: /* erase whole line */
  968. start = (unsigned short *)(vc->vc_pos - (vc->vc_x << 1));
  969. count = vc->vc_cols;
  970. if (DO_UPDATE(vc))
  971. vc->vc_sw->con_clear(vc, vc->vc_y, 0, 1,
  972. vc->vc_cols);
  973. break;
  974. default:
  975. return;
  976. }
  977. scr_memsetw(start, vc->vc_video_erase_char, 2 * count);
  978. vc->vc_need_wrap = 0;
  979. }
  980. static void csi_X(struct vc_data *vc, int vpar) /* erase the following vpar positions */
  981. { /* not vt100? */
  982. int count;
  983. if (!vpar)
  984. vpar++;
  985. count = (vpar > vc->vc_cols - vc->vc_x) ? (vc->vc_cols - vc->vc_x) : vpar;
  986. scr_memsetw((unsigned short *)vc->vc_pos, vc->vc_video_erase_char, 2 * count);
  987. if (DO_UPDATE(vc))
  988. vc->vc_sw->con_clear(vc, vc->vc_y, vc->vc_x, 1, count);
  989. vc->vc_need_wrap = 0;
  990. }
  991. static void default_attr(struct vc_data *vc)
  992. {
  993. vc->vc_intensity = 1;
  994. vc->vc_underline = 0;
  995. vc->vc_reverse = 0;
  996. vc->vc_blink = 0;
  997. vc->vc_color = vc->vc_def_color;
  998. }
  999. /* console_sem is held */
  1000. static void csi_m(struct vc_data *vc)
  1001. {
  1002. int i;
  1003. for (i = 0; i <= vc->vc_npar; i++)
  1004. switch (vc->vc_par[i]) {
  1005. case 0: /* all attributes off */
  1006. default_attr(vc);
  1007. break;
  1008. case 1:
  1009. vc->vc_intensity = 2;
  1010. break;
  1011. case 2:
  1012. vc->vc_intensity = 0;
  1013. break;
  1014. case 4:
  1015. vc->vc_underline = 1;
  1016. break;
  1017. case 5:
  1018. vc->vc_blink = 1;
  1019. break;
  1020. case 7:
  1021. vc->vc_reverse = 1;
  1022. break;
  1023. case 10: /* ANSI X3.64-1979 (SCO-ish?)
  1024. * Select primary font, don't display
  1025. * control chars if defined, don't set
  1026. * bit 8 on output.
  1027. */
  1028. vc->vc_translate = set_translate(vc->vc_charset == 0
  1029. ? vc->vc_G0_charset
  1030. : vc->vc_G1_charset, vc);
  1031. vc->vc_disp_ctrl = 0;
  1032. vc->vc_toggle_meta = 0;
  1033. break;
  1034. case 11: /* ANSI X3.64-1979 (SCO-ish?)
  1035. * Select first alternate font, lets
  1036. * chars < 32 be displayed as ROM chars.
  1037. */
  1038. vc->vc_translate = set_translate(IBMPC_MAP, vc);
  1039. vc->vc_disp_ctrl = 1;
  1040. vc->vc_toggle_meta = 0;
  1041. break;
  1042. case 12: /* ANSI X3.64-1979 (SCO-ish?)
  1043. * Select second alternate font, toggle
  1044. * high bit before displaying as ROM char.
  1045. */
  1046. vc->vc_translate = set_translate(IBMPC_MAP, vc);
  1047. vc->vc_disp_ctrl = 1;
  1048. vc->vc_toggle_meta = 1;
  1049. break;
  1050. case 21:
  1051. case 22:
  1052. vc->vc_intensity = 1;
  1053. break;
  1054. case 24:
  1055. vc->vc_underline = 0;
  1056. break;
  1057. case 25:
  1058. vc->vc_blink = 0;
  1059. break;
  1060. case 27:
  1061. vc->vc_reverse = 0;
  1062. break;
  1063. case 38: /* ANSI X3.64-1979 (SCO-ish?)
  1064. * Enables underscore, white foreground
  1065. * with white underscore (Linux - use
  1066. * default foreground).
  1067. */
  1068. vc->vc_color = (vc->vc_def_color & 0x0f) | (vc->vc_color & 0xf0);
  1069. vc->vc_underline = 1;
  1070. break;
  1071. case 39: /* ANSI X3.64-1979 (SCO-ish?)
  1072. * Disable underline option.
  1073. * Reset colour to default? It did this
  1074. * before...
  1075. */
  1076. vc->vc_color = (vc->vc_def_color & 0x0f) | (vc->vc_color & 0xf0);
  1077. vc->vc_underline = 0;
  1078. break;
  1079. case 49:
  1080. vc->vc_color = (vc->vc_def_color & 0xf0) | (vc->vc_color & 0x0f);
  1081. break;
  1082. default:
  1083. if (vc->vc_par[i] >= 30 && vc->vc_par[i] <= 37)
  1084. vc->vc_color = color_table[vc->vc_par[i] - 30]
  1085. | (vc->vc_color & 0xf0);
  1086. else if (vc->vc_par[i] >= 40 && vc->vc_par[i] <= 47)
  1087. vc->vc_color = (color_table[vc->vc_par[i] - 40] << 4)
  1088. | (vc->vc_color & 0x0f);
  1089. break;
  1090. }
  1091. update_attr(vc);
  1092. }
  1093. static void respond_string(const char *p, struct tty_struct *tty)
  1094. {
  1095. while (*p) {
  1096. tty_insert_flip_char(tty, *p, 0);
  1097. p++;
  1098. }
  1099. con_schedule_flip(tty);
  1100. }
  1101. static void cursor_report(struct vc_data *vc, struct tty_struct *tty)
  1102. {
  1103. char buf[40];
  1104. sprintf(buf, "\033[%d;%dR", vc->vc_y + (vc->vc_decom ? vc->vc_top + 1 : 1), vc->vc_x + 1);
  1105. respond_string(buf, tty);
  1106. }
  1107. static inline void status_report(struct tty_struct *tty)
  1108. {
  1109. respond_string("\033[0n", tty); /* Terminal ok */
  1110. }
  1111. static inline void respond_ID(struct tty_struct * tty)
  1112. {
  1113. respond_string(VT102ID, tty);
  1114. }
  1115. void mouse_report(struct tty_struct *tty, int butt, int mrx, int mry)
  1116. {
  1117. char buf[8];
  1118. sprintf(buf, "\033[M%c%c%c", (char)(' ' + butt), (char)('!' + mrx),
  1119. (char)('!' + mry));
  1120. respond_string(buf, tty);
  1121. }
  1122. /* invoked via ioctl(TIOCLINUX) and through set_selection */
  1123. int mouse_reporting(void)
  1124. {
  1125. return vc_cons[fg_console].d->vc_report_mouse;
  1126. }
  1127. /* console_sem is held */
  1128. static void set_mode(struct vc_data *vc, int on_off)
  1129. {
  1130. int i;
  1131. for (i = 0; i <= vc->vc_npar; i++)
  1132. if (vc->vc_ques) {
  1133. switch(vc->vc_par[i]) { /* DEC private modes set/reset */
  1134. case 1: /* Cursor keys send ^[Ox/^[[x */
  1135. if (on_off)
  1136. set_kbd(vc, decckm);
  1137. else
  1138. clr_kbd(vc, decckm);
  1139. break;
  1140. case 3: /* 80/132 mode switch unimplemented */
  1141. vc->vc_deccolm = on_off;
  1142. #if 0
  1143. vc_resize(deccolm ? 132 : 80, vc->vc_rows);
  1144. /* this alone does not suffice; some user mode
  1145. utility has to change the hardware regs */
  1146. #endif
  1147. break;
  1148. case 5: /* Inverted screen on/off */
  1149. if (vc->vc_decscnm != on_off) {
  1150. vc->vc_decscnm = on_off;
  1151. invert_screen(vc, 0, vc->vc_screenbuf_size, 0);
  1152. update_attr(vc);
  1153. }
  1154. break;
  1155. case 6: /* Origin relative/absolute */
  1156. vc->vc_decom = on_off;
  1157. gotoxay(vc, 0, 0);
  1158. break;
  1159. case 7: /* Autowrap on/off */
  1160. vc->vc_decawm = on_off;
  1161. break;
  1162. case 8: /* Autorepeat on/off */
  1163. if (on_off)
  1164. set_kbd(vc, decarm);
  1165. else
  1166. clr_kbd(vc, decarm);
  1167. break;
  1168. case 9:
  1169. vc->vc_report_mouse = on_off ? 1 : 0;
  1170. break;
  1171. case 25: /* Cursor on/off */
  1172. vc->vc_deccm = on_off;
  1173. break;
  1174. case 1000:
  1175. vc->vc_report_mouse = on_off ? 2 : 0;
  1176. break;
  1177. }
  1178. } else {
  1179. switch(vc->vc_par[i]) { /* ANSI modes set/reset */
  1180. case 3: /* Monitor (display ctrls) */
  1181. vc->vc_disp_ctrl = on_off;
  1182. break;
  1183. case 4: /* Insert Mode on/off */
  1184. vc->vc_decim = on_off;
  1185. break;
  1186. case 20: /* Lf, Enter == CrLf/Lf */
  1187. if (on_off)
  1188. set_kbd(vc, lnm);
  1189. else
  1190. clr_kbd(vc, lnm);
  1191. break;
  1192. }
  1193. }
  1194. }
  1195. /* console_sem is held */
  1196. static void setterm_command(struct vc_data *vc)
  1197. {
  1198. switch(vc->vc_par[0]) {
  1199. case 1: /* set color for underline mode */
  1200. if (vc->vc_can_do_color &&
  1201. vc->vc_par[1] < 16) {
  1202. vc->vc_ulcolor = color_table[vc->vc_par[1]];
  1203. if (vc->vc_underline)
  1204. update_attr(vc);
  1205. }
  1206. break;
  1207. case 2: /* set color for half intensity mode */
  1208. if (vc->vc_can_do_color &&
  1209. vc->vc_par[1] < 16) {
  1210. vc->vc_halfcolor = color_table[vc->vc_par[1]];
  1211. if (vc->vc_intensity == 0)
  1212. update_attr(vc);
  1213. }
  1214. break;
  1215. case 8: /* store colors as defaults */
  1216. vc->vc_def_color = vc->vc_attr;
  1217. if (vc->vc_hi_font_mask == 0x100)
  1218. vc->vc_def_color >>= 1;
  1219. default_attr(vc);
  1220. update_attr(vc);
  1221. break;
  1222. case 9: /* set blanking interval */
  1223. blankinterval = ((vc->vc_par[1] < 60) ? vc->vc_par[1] : 60) * 60 * HZ;
  1224. poke_blanked_console();
  1225. break;
  1226. case 10: /* set bell frequency in Hz */
  1227. if (vc->vc_npar >= 1)
  1228. vc->vc_bell_pitch = vc->vc_par[1];
  1229. else
  1230. vc->vc_bell_pitch = DEFAULT_BELL_PITCH;
  1231. break;
  1232. case 11: /* set bell duration in msec */
  1233. if (vc->vc_npar >= 1)
  1234. vc->vc_bell_duration = (vc->vc_par[1] < 2000) ?
  1235. vc->vc_par[1] * HZ / 1000 : 0;
  1236. else
  1237. vc->vc_bell_duration = DEFAULT_BELL_DURATION;
  1238. break;
  1239. case 12: /* bring specified console to the front */
  1240. if (vc->vc_par[1] >= 1 && vc_cons_allocated(vc->vc_par[1] - 1))
  1241. set_console(vc->vc_par[1] - 1);
  1242. break;
  1243. case 13: /* unblank the screen */
  1244. poke_blanked_console();
  1245. break;
  1246. case 14: /* set vesa powerdown interval */
  1247. vesa_off_interval = ((vc->vc_par[1] < 60) ? vc->vc_par[1] : 60) * 60 * HZ;
  1248. break;
  1249. case 15: /* activate the previous console */
  1250. set_console(last_console);
  1251. break;
  1252. }
  1253. }
  1254. /* console_sem is held */
  1255. static void csi_at(struct vc_data *vc, unsigned int nr)
  1256. {
  1257. if (nr > vc->vc_cols - vc->vc_x)
  1258. nr = vc->vc_cols - vc->vc_x;
  1259. else if (!nr)
  1260. nr = 1;
  1261. insert_char(vc, nr);
  1262. }
  1263. /* console_sem is held */
  1264. static void csi_L(struct vc_data *vc, unsigned int nr)
  1265. {
  1266. if (nr > vc->vc_rows - vc->vc_y)
  1267. nr = vc->vc_rows - vc->vc_y;
  1268. else if (!nr)
  1269. nr = 1;
  1270. scrdown(vc, vc->vc_y, vc->vc_bottom, nr);
  1271. vc->vc_need_wrap = 0;
  1272. }
  1273. /* console_sem is held */
  1274. static void csi_P(struct vc_data *vc, unsigned int nr)
  1275. {
  1276. if (nr > vc->vc_cols - vc->vc_x)
  1277. nr = vc->vc_cols - vc->vc_x;
  1278. else if (!nr)
  1279. nr = 1;
  1280. delete_char(vc, nr);
  1281. }
  1282. /* console_sem is held */
  1283. static void csi_M(struct vc_data *vc, unsigned int nr)
  1284. {
  1285. if (nr > vc->vc_rows - vc->vc_y)
  1286. nr = vc->vc_rows - vc->vc_y;
  1287. else if (!nr)
  1288. nr=1;
  1289. scrup(vc, vc->vc_y, vc->vc_bottom, nr);
  1290. vc->vc_need_wrap = 0;
  1291. }
  1292. /* console_sem is held (except via vc_init->reset_terminal */
  1293. static void save_cur(struct vc_data *vc)
  1294. {
  1295. vc->vc_saved_x = vc->vc_x;
  1296. vc->vc_saved_y = vc->vc_y;
  1297. vc->vc_s_intensity = vc->vc_intensity;
  1298. vc->vc_s_underline = vc->vc_underline;
  1299. vc->vc_s_blink = vc->vc_blink;
  1300. vc->vc_s_reverse = vc->vc_reverse;
  1301. vc->vc_s_charset = vc->vc_charset;
  1302. vc->vc_s_color = vc->vc_color;
  1303. vc->vc_saved_G0 = vc->vc_G0_charset;
  1304. vc->vc_saved_G1 = vc->vc_G1_charset;
  1305. }
  1306. /* console_sem is held */
  1307. static void restore_cur(struct vc_data *vc)
  1308. {
  1309. gotoxy(vc, vc->vc_saved_x, vc->vc_saved_y);
  1310. vc->vc_intensity = vc->vc_s_intensity;
  1311. vc->vc_underline = vc->vc_s_underline;
  1312. vc->vc_blink = vc->vc_s_blink;
  1313. vc->vc_reverse = vc->vc_s_reverse;
  1314. vc->vc_charset = vc->vc_s_charset;
  1315. vc->vc_color = vc->vc_s_color;
  1316. vc->vc_G0_charset = vc->vc_saved_G0;
  1317. vc->vc_G1_charset = vc->vc_saved_G1;
  1318. vc->vc_translate = set_translate(vc->vc_charset ? vc->vc_G1_charset : vc->vc_G0_charset, vc);
  1319. update_attr(vc);
  1320. vc->vc_need_wrap = 0;
  1321. }
  1322. enum { ESnormal, ESesc, ESsquare, ESgetpars, ESgotpars, ESfunckey,
  1323. EShash, ESsetG0, ESsetG1, ESpercent, ESignore, ESnonstd,
  1324. ESpalette };
  1325. /* console_sem is held (except via vc_init()) */
  1326. static void reset_terminal(struct vc_data *vc, int do_clear)
  1327. {
  1328. vc->vc_top = 0;
  1329. vc->vc_bottom = vc->vc_rows;
  1330. vc->vc_state = ESnormal;
  1331. vc->vc_ques = 0;
  1332. vc->vc_translate = set_translate(LAT1_MAP, vc);
  1333. vc->vc_G0_charset = LAT1_MAP;
  1334. vc->vc_G1_charset = GRAF_MAP;
  1335. vc->vc_charset = 0;
  1336. vc->vc_need_wrap = 0;
  1337. vc->vc_report_mouse = 0;
  1338. vc->vc_utf = 0;
  1339. vc->vc_utf_count = 0;
  1340. vc->vc_disp_ctrl = 0;
  1341. vc->vc_toggle_meta = 0;
  1342. vc->vc_decscnm = 0;
  1343. vc->vc_decom = 0;
  1344. vc->vc_decawm = 1;
  1345. vc->vc_deccm = 1;
  1346. vc->vc_decim = 0;
  1347. set_kbd(vc, decarm);
  1348. clr_kbd(vc, decckm);
  1349. clr_kbd(vc, kbdapplic);
  1350. clr_kbd(vc, lnm);
  1351. kbd_table[vc->vc_num].lockstate = 0;
  1352. kbd_table[vc->vc_num].slockstate = 0;
  1353. kbd_table[vc->vc_num].ledmode = LED_SHOW_FLAGS;
  1354. kbd_table[vc->vc_num].ledflagstate = kbd_table[vc->vc_num].default_ledflagstate;
  1355. /* do not do set_leds here because this causes an endless tasklet loop
  1356. when the keyboard hasn't been initialized yet */
  1357. vc->vc_cursor_type = CUR_DEFAULT;
  1358. vc->vc_complement_mask = vc->vc_s_complement_mask;
  1359. default_attr(vc);
  1360. update_attr(vc);
  1361. vc->vc_tab_stop[0] = 0x01010100;
  1362. vc->vc_tab_stop[1] =
  1363. vc->vc_tab_stop[2] =
  1364. vc->vc_tab_stop[3] =
  1365. vc->vc_tab_stop[4] = 0x01010101;
  1366. vc->vc_bell_pitch = DEFAULT_BELL_PITCH;
  1367. vc->vc_bell_duration = DEFAULT_BELL_DURATION;
  1368. gotoxy(vc, 0, 0);
  1369. save_cur(vc);
  1370. if (do_clear)
  1371. csi_J(vc, 2);
  1372. }
  1373. /* console_sem is held */
  1374. static void do_con_trol(struct tty_struct *tty, struct vc_data *vc, int c)
  1375. {
  1376. /*
  1377. * Control characters can be used in the _middle_
  1378. * of an escape sequence.
  1379. */
  1380. switch (c) {
  1381. case 0:
  1382. return;
  1383. case 7:
  1384. if (vc->vc_bell_duration)
  1385. kd_mksound(vc->vc_bell_pitch, vc->vc_bell_duration);
  1386. return;
  1387. case 8:
  1388. bs(vc);
  1389. return;
  1390. case 9:
  1391. vc->vc_pos -= (vc->vc_x << 1);
  1392. while (vc->vc_x < vc->vc_cols - 1) {
  1393. vc->vc_x++;
  1394. if (vc->vc_tab_stop[vc->vc_x >> 5] & (1 << (vc->vc_x & 31)))
  1395. break;
  1396. }
  1397. vc->vc_pos += (vc->vc_x << 1);
  1398. return;
  1399. case 10: case 11: case 12:
  1400. lf(vc);
  1401. if (!is_kbd(vc, lnm))
  1402. return;
  1403. case 13:
  1404. cr(vc);
  1405. return;
  1406. case 14:
  1407. vc->vc_charset = 1;
  1408. vc->vc_translate = set_translate(vc->vc_G1_charset, vc);
  1409. vc->vc_disp_ctrl = 1;
  1410. return;
  1411. case 15:
  1412. vc->vc_charset = 0;
  1413. vc->vc_translate = set_translate(vc->vc_G0_charset, vc);
  1414. vc->vc_disp_ctrl = 0;
  1415. return;
  1416. case 24: case 26:
  1417. vc->vc_state = ESnormal;
  1418. return;
  1419. case 27:
  1420. vc->vc_state = ESesc;
  1421. return;
  1422. case 127:
  1423. del(vc);
  1424. return;
  1425. case 128+27:
  1426. vc->vc_state = ESsquare;
  1427. return;
  1428. }
  1429. switch(vc->vc_state) {
  1430. case ESesc:
  1431. vc->vc_state = ESnormal;
  1432. switch (c) {
  1433. case '[':
  1434. vc->vc_state = ESsquare;
  1435. return;
  1436. case ']':
  1437. vc->vc_state = ESnonstd;
  1438. return;
  1439. case '%':
  1440. vc->vc_state = ESpercent;
  1441. return;
  1442. case 'E':
  1443. cr(vc);
  1444. lf(vc);
  1445. return;
  1446. case 'M':
  1447. ri(vc);
  1448. return;
  1449. case 'D':
  1450. lf(vc);
  1451. return;
  1452. case 'H':
  1453. vc->vc_tab_stop[vc->vc_x >> 5] |= (1 << (vc->vc_x & 31));
  1454. return;
  1455. case 'Z':
  1456. respond_ID(tty);
  1457. return;
  1458. case '7':
  1459. save_cur(vc);
  1460. return;
  1461. case '8':
  1462. restore_cur(vc);
  1463. return;
  1464. case '(':
  1465. vc->vc_state = ESsetG0;
  1466. return;
  1467. case ')':
  1468. vc->vc_state = ESsetG1;
  1469. return;
  1470. case '#':
  1471. vc->vc_state = EShash;
  1472. return;
  1473. case 'c':
  1474. reset_terminal(vc, 1);
  1475. return;
  1476. case '>': /* Numeric keypad */
  1477. clr_kbd(vc, kbdapplic);
  1478. return;
  1479. case '=': /* Appl. keypad */
  1480. set_kbd(vc, kbdapplic);
  1481. return;
  1482. }
  1483. return;
  1484. case ESnonstd:
  1485. if (c=='P') { /* palette escape sequence */
  1486. for (vc->vc_npar = 0; vc->vc_npar < NPAR; vc->vc_npar++)
  1487. vc->vc_par[vc->vc_npar] = 0;
  1488. vc->vc_npar = 0;
  1489. vc->vc_state = ESpalette;
  1490. return;
  1491. } else if (c=='R') { /* reset palette */
  1492. reset_palette(vc);
  1493. vc->vc_state = ESnormal;
  1494. } else
  1495. vc->vc_state = ESnormal;
  1496. return;
  1497. case ESpalette:
  1498. if ( (c>='0'&&c<='9') || (c>='A'&&c<='F') || (c>='a'&&c<='f') ) {
  1499. vc->vc_par[vc->vc_npar++] = (c > '9' ? (c & 0xDF) - 'A' + 10 : c - '0');
  1500. if (vc->vc_npar == 7) {
  1501. int i = vc->vc_par[0] * 3, j = 1;
  1502. vc->vc_palette[i] = 16 * vc->vc_par[j++];
  1503. vc->vc_palette[i++] += vc->vc_par[j++];
  1504. vc->vc_palette[i] = 16 * vc->vc_par[j++];
  1505. vc->vc_palette[i++] += vc->vc_par[j++];
  1506. vc->vc_palette[i] = 16 * vc->vc_par[j++];
  1507. vc->vc_palette[i] += vc->vc_par[j];
  1508. set_palette(vc);
  1509. vc->vc_state = ESnormal;
  1510. }
  1511. } else
  1512. vc->vc_state = ESnormal;
  1513. return;
  1514. case ESsquare:
  1515. for (vc->vc_npar = 0; vc->vc_npar < NPAR; vc->vc_npar++)
  1516. vc->vc_par[vc->vc_npar] = 0;
  1517. vc->vc_npar = 0;
  1518. vc->vc_state = ESgetpars;
  1519. if (c == '[') { /* Function key */
  1520. vc->vc_state=ESfunckey;
  1521. return;
  1522. }
  1523. vc->vc_ques = (c == '?');
  1524. if (vc->vc_ques)
  1525. return;
  1526. case ESgetpars:
  1527. if (c == ';' && vc->vc_npar < NPAR - 1) {
  1528. vc->vc_npar++;
  1529. return;
  1530. } else if (c>='0' && c<='9') {
  1531. vc->vc_par[vc->vc_npar] *= 10;
  1532. vc->vc_par[vc->vc_npar] += c - '0';
  1533. return;
  1534. } else
  1535. vc->vc_state = ESgotpars;
  1536. case ESgotpars:
  1537. vc->vc_state = ESnormal;
  1538. switch(c) {
  1539. case 'h':
  1540. set_mode(vc, 1);
  1541. return;
  1542. case 'l':
  1543. set_mode(vc, 0);
  1544. return;
  1545. case 'c':
  1546. if (vc->vc_ques) {
  1547. if (vc->vc_par[0])
  1548. vc->vc_cursor_type = vc->vc_par[0] | (vc->vc_par[1] << 8) | (vc->vc_par[2] << 16);
  1549. else
  1550. vc->vc_cursor_type = CUR_DEFAULT;
  1551. return;
  1552. }
  1553. break;
  1554. case 'm':
  1555. if (vc->vc_ques) {
  1556. clear_selection();
  1557. if (vc->vc_par[0])
  1558. vc->vc_complement_mask = vc->vc_par[0] << 8 | vc->vc_par[1];
  1559. else
  1560. vc->vc_complement_mask = vc->vc_s_complement_mask;
  1561. return;
  1562. }
  1563. break;
  1564. case 'n':
  1565. if (!vc->vc_ques) {
  1566. if (vc->vc_par[0] == 5)
  1567. status_report(tty);
  1568. else if (vc->vc_par[0] == 6)
  1569. cursor_report(vc, tty);
  1570. }
  1571. return;
  1572. }
  1573. if (vc->vc_ques) {
  1574. vc->vc_ques = 0;
  1575. return;
  1576. }
  1577. switch(c) {
  1578. case 'G': case '`':
  1579. if (vc->vc_par[0])
  1580. vc->vc_par[0]--;
  1581. gotoxy(vc, vc->vc_par[0], vc->vc_y);
  1582. return;
  1583. case 'A':
  1584. if (!vc->vc_par[0])
  1585. vc->vc_par[0]++;
  1586. gotoxy(vc, vc->vc_x, vc->vc_y - vc->vc_par[0]);
  1587. return;
  1588. case 'B': case 'e':
  1589. if (!vc->vc_par[0])
  1590. vc->vc_par[0]++;
  1591. gotoxy(vc, vc->vc_x, vc->vc_y + vc->vc_par[0]);
  1592. return;
  1593. case 'C': case 'a':
  1594. if (!vc->vc_par[0])
  1595. vc->vc_par[0]++;
  1596. gotoxy(vc, vc->vc_x + vc->vc_par[0], vc->vc_y);
  1597. return;
  1598. case 'D':
  1599. if (!vc->vc_par[0])
  1600. vc->vc_par[0]++;
  1601. gotoxy(vc, vc->vc_x - vc->vc_par[0], vc->vc_y);
  1602. return;
  1603. case 'E':
  1604. if (!vc->vc_par[0])
  1605. vc->vc_par[0]++;
  1606. gotoxy(vc, 0, vc->vc_y + vc->vc_par[0]);
  1607. return;
  1608. case 'F':
  1609. if (!vc->vc_par[0])
  1610. vc->vc_par[0]++;
  1611. gotoxy(vc, 0, vc->vc_y - vc->vc_par[0]);
  1612. return;
  1613. case 'd':
  1614. if (vc->vc_par[0])
  1615. vc->vc_par[0]--;
  1616. gotoxay(vc, vc->vc_x ,vc->vc_par[0]);
  1617. return;
  1618. case 'H': case 'f':
  1619. if (vc->vc_par[0])
  1620. vc->vc_par[0]--;
  1621. if (vc->vc_par[1])
  1622. vc->vc_par[1]--;
  1623. gotoxay(vc, vc->vc_par[1], vc->vc_par[0]);
  1624. return;
  1625. case 'J':
  1626. csi_J(vc, vc->vc_par[0]);
  1627. return;
  1628. case 'K':
  1629. csi_K(vc, vc->vc_par[0]);
  1630. return;
  1631. case 'L':
  1632. csi_L(vc, vc->vc_par[0]);
  1633. return;
  1634. case 'M':
  1635. csi_M(vc, vc->vc_par[0]);
  1636. return;
  1637. case 'P':
  1638. csi_P(vc, vc->vc_par[0]);
  1639. return;
  1640. case 'c':
  1641. if (!vc->vc_par[0])
  1642. respond_ID(tty);
  1643. return;
  1644. case 'g':
  1645. if (!vc->vc_par[0])
  1646. vc->vc_tab_stop[vc->vc_x >> 5] &= ~(1 << (vc->vc_x & 31));
  1647. else if (vc->vc_par[0] == 3) {
  1648. vc->vc_tab_stop[0] =
  1649. vc->vc_tab_stop[1] =
  1650. vc->vc_tab_stop[2] =
  1651. vc->vc_tab_stop[3] =
  1652. vc->vc_tab_stop[4] = 0;
  1653. }
  1654. return;
  1655. case 'm':
  1656. csi_m(vc);
  1657. return;
  1658. case 'q': /* DECLL - but only 3 leds */
  1659. /* map 0,1,2,3 to 0,1,2,4 */
  1660. if (vc->vc_par[0] < 4)
  1661. setledstate(kbd_table + vc->vc_num,
  1662. (vc->vc_par[0] < 3) ? vc->vc_par[0] : 4);
  1663. return;
  1664. case 'r':
  1665. if (!vc->vc_par[0])
  1666. vc->vc_par[0]++;
  1667. if (!vc->vc_par[1])
  1668. vc->vc_par[1] = vc->vc_rows;
  1669. /* Minimum allowed region is 2 lines */
  1670. if (vc->vc_par[0] < vc->vc_par[1] &&
  1671. vc->vc_par[1] <= vc->vc_rows) {
  1672. vc->vc_top = vc->vc_par[0] - 1;
  1673. vc->vc_bottom = vc->vc_par[1];
  1674. gotoxay(vc, 0, 0);
  1675. }
  1676. return;
  1677. case 's':
  1678. save_cur(vc);
  1679. return;
  1680. case 'u':
  1681. restore_cur(vc);
  1682. return;
  1683. case 'X':
  1684. csi_X(vc, vc->vc_par[0]);
  1685. return;
  1686. case '@':
  1687. csi_at(vc, vc->vc_par[0]);
  1688. return;
  1689. case ']': /* setterm functions */
  1690. setterm_command(vc);
  1691. return;
  1692. }
  1693. return;
  1694. case ESpercent:
  1695. vc->vc_state = ESnormal;
  1696. switch (c) {
  1697. case '@': /* defined in ISO 2022 */
  1698. vc->vc_utf = 0;
  1699. return;
  1700. case 'G': /* prelim official escape code */
  1701. case '8': /* retained for compatibility */
  1702. vc->vc_utf = 1;
  1703. return;
  1704. }
  1705. return;
  1706. case ESfunckey:
  1707. vc->vc_state = ESnormal;
  1708. return;
  1709. case EShash:
  1710. vc->vc_state = ESnormal;
  1711. if (c == '8') {
  1712. /* DEC screen alignment test. kludge :-) */
  1713. vc->vc_video_erase_char =
  1714. (vc->vc_video_erase_char & 0xff00) | 'E';
  1715. csi_J(vc, 2);
  1716. vc->vc_video_erase_char =
  1717. (vc->vc_video_erase_char & 0xff00) | ' ';
  1718. do_update_region(vc, vc->vc_origin, vc->vc_screenbuf_size / 2);
  1719. }
  1720. return;
  1721. case ESsetG0:
  1722. if (c == '0')
  1723. vc->vc_G0_charset = GRAF_MAP;
  1724. else if (c == 'B')
  1725. vc->vc_G0_charset = LAT1_MAP;
  1726. else if (c == 'U')
  1727. vc->vc_G0_charset = IBMPC_MAP;
  1728. else if (c == 'K')
  1729. vc->vc_G0_charset = USER_MAP;
  1730. if (vc->vc_charset == 0)
  1731. vc->vc_translate = set_translate(vc->vc_G0_charset, vc);
  1732. vc->vc_state = ESnormal;
  1733. return;
  1734. case ESsetG1:
  1735. if (c == '0')
  1736. vc->vc_G1_charset = GRAF_MAP;
  1737. else if (c == 'B')
  1738. vc->vc_G1_charset = LAT1_MAP;
  1739. else if (c == 'U')
  1740. vc->vc_G1_charset = IBMPC_MAP;
  1741. else if (c == 'K')
  1742. vc->vc_G1_charset = USER_MAP;
  1743. if (vc->vc_charset == 1)
  1744. vc->vc_translate = set_translate(vc->vc_G1_charset, vc);
  1745. vc->vc_state = ESnormal;
  1746. return;
  1747. default:
  1748. vc->vc_state = ESnormal;
  1749. }
  1750. }
  1751. /* This is a temporary buffer used to prepare a tty console write
  1752. * so that we can easily avoid touching user space while holding the
  1753. * console spinlock. It is allocated in con_init and is shared by
  1754. * this code and the vc_screen read/write tty calls.
  1755. *
  1756. * We have to allocate this statically in the kernel data section
  1757. * since console_init (and thus con_init) are called before any
  1758. * kernel memory allocation is available.
  1759. */
  1760. char con_buf[CON_BUF_SIZE];
  1761. DECLARE_MUTEX(con_buf_sem);
  1762. /* acquires console_sem */
  1763. static int do_con_write(struct tty_struct *tty, const unsigned char *buf, int count)
  1764. {
  1765. #ifdef VT_BUF_VRAM_ONLY
  1766. #define FLUSH do { } while(0);
  1767. #else
  1768. #define FLUSH if (draw_x >= 0) { \
  1769. vc->vc_sw->con_putcs(vc, (u16 *)draw_from, (u16 *)draw_to - (u16 *)draw_from, vc->vc_y, draw_x); \
  1770. draw_x = -1; \
  1771. }
  1772. #endif
  1773. int c, tc, ok, n = 0, draw_x = -1;
  1774. unsigned int currcons;
  1775. unsigned long draw_from = 0, draw_to = 0;
  1776. struct vc_data *vc;
  1777. u16 himask, charmask;
  1778. const unsigned char *orig_buf = NULL;
  1779. int orig_count;
  1780. if (in_interrupt())
  1781. return count;
  1782. might_sleep();
  1783. acquire_console_sem();
  1784. vc = tty->driver_data;
  1785. if (vc == NULL) {
  1786. printk(KERN_ERR "vt: argh, driver_data is NULL !\n");
  1787. release_console_sem();
  1788. return 0;
  1789. }
  1790. currcons = vc->vc_num;
  1791. if (!vc_cons_allocated(currcons)) {
  1792. /* could this happen? */
  1793. static int error = 0;
  1794. if (!error) {
  1795. error = 1;
  1796. printk("con_write: tty %d not allocated\n", currcons+1);
  1797. }
  1798. release_console_sem();
  1799. return 0;
  1800. }
  1801. release_console_sem();
  1802. orig_buf = buf;
  1803. orig_count = count;
  1804. /* At this point 'buf' is guaranteed to be a kernel buffer
  1805. * and therefore no access to userspace (and therefore sleeping)
  1806. * will be needed. The con_buf_sem serializes all tty based
  1807. * console rendering and vcs write/read operations. We hold
  1808. * the console spinlock during the entire write.
  1809. */
  1810. acquire_console_sem();
  1811. vc = tty->driver_data;
  1812. if (vc == NULL) {
  1813. printk(KERN_ERR "vt: argh, driver_data _became_ NULL !\n");
  1814. release_console_sem();
  1815. goto out;
  1816. }
  1817. himask = vc->vc_hi_font_mask;
  1818. charmask = himask ? 0x1ff : 0xff;
  1819. /* undraw cursor first */
  1820. if (IS_FG(vc))
  1821. hide_cursor(vc);
  1822. while (!tty->stopped && count) {
  1823. int orig = *buf;
  1824. c = orig;
  1825. buf++;
  1826. n++;
  1827. count--;
  1828. /* Do no translation at all in control states */
  1829. if (vc->vc_state != ESnormal) {
  1830. tc = c;
  1831. } else if (vc->vc_utf) {
  1832. /* Combine UTF-8 into Unicode */
  1833. /* Incomplete characters silently ignored */
  1834. if(c > 0x7f) {
  1835. if (vc->vc_utf_count > 0 && (c & 0xc0) == 0x80) {
  1836. vc->vc_utf_char = (vc->vc_utf_char << 6) | (c & 0x3f);
  1837. vc->vc_utf_count--;
  1838. if (vc->vc_utf_count == 0)
  1839. tc = c = vc->vc_utf_char;
  1840. else continue;
  1841. } else {
  1842. if ((c & 0xe0) == 0xc0) {
  1843. vc->vc_utf_count = 1;
  1844. vc->vc_utf_char = (c & 0x1f);
  1845. } else if ((c & 0xf0) == 0xe0) {
  1846. vc->vc_utf_count = 2;
  1847. vc->vc_utf_char = (c & 0x0f);
  1848. } else if ((c & 0xf8) == 0xf0) {
  1849. vc->vc_utf_count = 3;
  1850. vc->vc_utf_char = (c & 0x07);
  1851. } else if ((c & 0xfc) == 0xf8) {
  1852. vc->vc_utf_count = 4;
  1853. vc->vc_utf_char = (c & 0x03);
  1854. } else if ((c & 0xfe) == 0xfc) {
  1855. vc->vc_utf_count = 5;
  1856. vc->vc_utf_char = (c & 0x01);
  1857. } else
  1858. vc->vc_utf_count = 0;
  1859. continue;
  1860. }
  1861. } else {
  1862. tc = c;
  1863. vc->vc_utf_count = 0;
  1864. }
  1865. } else { /* no utf */
  1866. tc = vc->vc_translate[vc->vc_toggle_meta ? (c | 0x80) : c];
  1867. }
  1868. /* If the original code was a control character we
  1869. * only allow a glyph to be displayed if the code is
  1870. * not normally used (such as for cursor movement) or
  1871. * if the disp_ctrl mode has been explicitly enabled.
  1872. * Certain characters (as given by the CTRL_ALWAYS
  1873. * bitmap) are always displayed as control characters,
  1874. * as the console would be pretty useless without
  1875. * them; to display an arbitrary font position use the
  1876. * direct-to-font zone in UTF-8 mode.
  1877. */
  1878. ok = tc && (c >= 32 ||
  1879. (!vc->vc_utf && !(((vc->vc_disp_ctrl ? CTRL_ALWAYS
  1880. : CTRL_ACTION) >> c) & 1)))
  1881. && (c != 127 || vc->vc_disp_ctrl)
  1882. && (c != 128+27);
  1883. if (vc->vc_state == ESnormal && ok) {
  1884. /* Now try to find out how to display it */
  1885. tc = conv_uni_to_pc(vc, tc);
  1886. if ( tc == -4 ) {
  1887. /* If we got -4 (not found) then see if we have
  1888. defined a replacement character (U+FFFD) */
  1889. tc = conv_uni_to_pc(vc, 0xfffd);
  1890. /* One reason for the -4 can be that we just
  1891. did a clear_unimap();
  1892. try at least to show something. */
  1893. if (tc == -4)
  1894. tc = c;
  1895. } else if ( tc == -3 ) {
  1896. /* Bad hash table -- hope for the best */
  1897. tc = c;
  1898. }
  1899. if (tc & ~charmask)
  1900. continue; /* Conversion failed */
  1901. if (vc->vc_need_wrap || vc->vc_decim)
  1902. FLUSH
  1903. if (vc->vc_need_wrap) {
  1904. cr(vc);
  1905. lf(vc);
  1906. }
  1907. if (vc->vc_decim)
  1908. insert_char(vc, 1);
  1909. scr_writew(himask ?
  1910. ((vc->vc_attr << 8) & ~himask) + ((tc & 0x100) ? himask : 0) + (tc & 0xff) :
  1911. (vc->vc_attr << 8) + tc,
  1912. (u16 *) vc->vc_pos);
  1913. if (DO_UPDATE(vc) && draw_x < 0) {
  1914. draw_x = vc->vc_x;
  1915. draw_from = vc->vc_pos;
  1916. }
  1917. if (vc->vc_x == vc->vc_cols - 1) {
  1918. vc->vc_need_wrap = vc->vc_decawm;
  1919. draw_to = vc->vc_pos + 2;
  1920. } else {
  1921. vc->vc_x++;
  1922. draw_to = (vc->vc_pos += 2);
  1923. }
  1924. continue;
  1925. }
  1926. FLUSH
  1927. do_con_trol(tty, vc, orig);
  1928. }
  1929. FLUSH
  1930. console_conditional_schedule();
  1931. release_console_sem();
  1932. out:
  1933. return n;
  1934. #undef FLUSH
  1935. }
  1936. /*
  1937. * This is the console switching callback.
  1938. *
  1939. * Doing console switching in a process context allows
  1940. * us to do the switches asynchronously (needed when we want
  1941. * to switch due to a keyboard interrupt). Synchronization
  1942. * with other console code and prevention of re-entrancy is
  1943. * ensured with console_sem.
  1944. */
  1945. static void console_callback(void *ignored)
  1946. {
  1947. acquire_console_sem();
  1948. if (want_console >= 0) {
  1949. if (want_console != fg_console &&
  1950. vc_cons_allocated(want_console)) {
  1951. hide_cursor(vc_cons[fg_console].d);
  1952. change_console(vc_cons[want_console].d);
  1953. /* we only changed when the console had already
  1954. been allocated - a new console is not created
  1955. in an interrupt routine */
  1956. }
  1957. want_console = -1;
  1958. }
  1959. if (do_poke_blanked_console) { /* do not unblank for a LED change */
  1960. do_poke_blanked_console = 0;
  1961. poke_blanked_console();
  1962. }
  1963. if (scrollback_delta) {
  1964. struct vc_data *vc = vc_cons[fg_console].d;
  1965. clear_selection();
  1966. if (vc->vc_mode == KD_TEXT)
  1967. vc->vc_sw->con_scrolldelta(vc, scrollback_delta);
  1968. scrollback_delta = 0;
  1969. }
  1970. if (blank_timer_expired) {
  1971. do_blank_screen(0);
  1972. blank_timer_expired = 0;
  1973. }
  1974. release_console_sem();
  1975. }
  1976. void set_console(int nr)
  1977. {
  1978. want_console = nr;
  1979. schedule_console_callback();
  1980. }
  1981. struct tty_driver *console_driver;
  1982. #ifdef CONFIG_VT_CONSOLE
  1983. /*
  1984. * Console on virtual terminal
  1985. *
  1986. * The console must be locked when we get here.
  1987. */
  1988. static void vt_console_print(struct console *co, const char *b, unsigned count)
  1989. {
  1990. struct vc_data *vc = vc_cons[fg_console].d;
  1991. unsigned char c;
  1992. static unsigned long printing;
  1993. const ushort *start;
  1994. ushort cnt = 0;
  1995. ushort myx;
  1996. /* console busy or not yet initialized */
  1997. if (!printable || test_and_set_bit(0, &printing))
  1998. return;
  1999. if (kmsg_redirect && vc_cons_allocated(kmsg_redirect - 1))
  2000. vc = vc_cons[kmsg_redirect - 1].d;
  2001. /* read `x' only after setting currcons properly (otherwise
  2002. the `x' macro will read the x of the foreground console). */
  2003. myx = vc->vc_x;
  2004. if (!vc_cons_allocated(fg_console)) {
  2005. /* impossible */
  2006. /* printk("vt_console_print: tty %d not allocated ??\n", currcons+1); */
  2007. goto quit;
  2008. }
  2009. if (vc->vc_mode != KD_TEXT)
  2010. goto quit;
  2011. /* undraw cursor first */
  2012. if (IS_FG(vc))
  2013. hide_cursor(vc);
  2014. start = (ushort *)vc->vc_pos;
  2015. /* Contrived structure to try to emulate original need_wrap behaviour
  2016. * Problems caused when we have need_wrap set on '\n' character */
  2017. while (count--) {
  2018. c = *b++;
  2019. if (c == 10 || c == 13 || c == 8 || vc->vc_need_wrap) {
  2020. if (cnt > 0) {
  2021. if (CON_IS_VISIBLE(vc))
  2022. vc->vc_sw->con_putcs(vc, start, cnt, vc->vc_y, vc->vc_x);
  2023. vc->vc_x += cnt;
  2024. if (vc->vc_need_wrap)
  2025. vc->vc_x--;
  2026. cnt = 0;
  2027. }
  2028. if (c == 8) { /* backspace */
  2029. bs(vc);
  2030. start = (ushort *)vc->vc_pos;
  2031. myx = vc->vc_x;
  2032. continue;
  2033. }
  2034. if (c != 13)
  2035. lf(vc);
  2036. cr(vc);
  2037. start = (ushort *)vc->vc_pos;
  2038. myx = vc->vc_x;
  2039. if (c == 10 || c == 13)
  2040. continue;
  2041. }
  2042. scr_writew((vc->vc_attr << 8) + c, (unsigned short *)vc->vc_pos);
  2043. cnt++;
  2044. if (myx == vc->vc_cols - 1) {
  2045. vc->vc_need_wrap = 1;
  2046. continue;
  2047. }
  2048. vc->vc_pos += 2;
  2049. myx++;
  2050. }
  2051. if (cnt > 0) {
  2052. if (CON_IS_VISIBLE(vc))
  2053. vc->vc_sw->con_putcs(vc, start, cnt, vc->vc_y, vc->vc_x);
  2054. vc->vc_x += cnt;
  2055. if (vc->vc_x == vc->vc_cols) {
  2056. vc->vc_x--;
  2057. vc->vc_need_wrap = 1;
  2058. }
  2059. }
  2060. set_cursor(vc);
  2061. quit:
  2062. clear_bit(0, &printing);
  2063. }
  2064. static struct tty_driver *vt_console_device(struct console *c, int *index)
  2065. {
  2066. *index = c->index ? c->index-1 : fg_console;
  2067. return console_driver;
  2068. }
  2069. static struct console vt_console_driver = {
  2070. .name = "tty",
  2071. .write = vt_console_print,
  2072. .device = vt_console_device,
  2073. .unblank = unblank_screen,
  2074. .flags = CON_PRINTBUFFER,
  2075. .index = -1,
  2076. };
  2077. #endif
  2078. /*
  2079. * Handling of Linux-specific VC ioctls
  2080. */
  2081. /*
  2082. * Generally a bit racy with respect to console_sem().
  2083. *
  2084. * There are some functions which don't need it.
  2085. *
  2086. * There are some functions which can sleep for arbitrary periods
  2087. * (paste_selection) but we don't need the lock there anyway.
  2088. *
  2089. * set_selection has locking, and definitely needs it
  2090. */
  2091. int tioclinux(struct tty_struct *tty, unsigned long arg)
  2092. {
  2093. char type, data;
  2094. char __user *p = (char __user *)arg;
  2095. int lines;
  2096. int ret;
  2097. if (tty->driver->type != TTY_DRIVER_TYPE_CONSOLE)
  2098. return -EINVAL;
  2099. if (current->signal->tty != tty && !capable(CAP_SYS_ADMIN))
  2100. return -EPERM;
  2101. if (get_user(type, p))
  2102. return -EFAULT;
  2103. ret = 0;
  2104. switch (type)
  2105. {
  2106. case TIOCL_SETSEL:
  2107. acquire_console_sem();
  2108. ret = set_selection((struct tiocl_selection __user *)(p+1), tty);
  2109. release_console_sem();
  2110. break;
  2111. case TIOCL_PASTESEL:
  2112. ret = paste_selection(tty);
  2113. break;
  2114. case TIOCL_UNBLANKSCREEN:
  2115. acquire_console_sem();
  2116. unblank_screen();
  2117. release_console_sem();
  2118. break;
  2119. case TIOCL_SELLOADLUT:
  2120. ret = sel_loadlut(p);
  2121. break;
  2122. case TIOCL_GETSHIFTSTATE:
  2123. /*
  2124. * Make it possible to react to Shift+Mousebutton.
  2125. * Note that 'shift_state' is an undocumented
  2126. * kernel-internal variable; programs not closely
  2127. * related to the kernel should not use this.
  2128. */
  2129. data = shift_state;
  2130. ret = __put_user(data, p);
  2131. break;
  2132. case TIOCL_GETMOUSEREPORTING:
  2133. data = mouse_reporting();
  2134. ret = __put_user(data, p);
  2135. break;
  2136. case TIOCL_SETVESABLANK:
  2137. set_vesa_blanking(p);
  2138. break;
  2139. case TIOCL_GETKMSGREDIRECT:
  2140. data = kmsg_redirect;
  2141. ret = __put_user(data, p);
  2142. break;
  2143. case TIOCL_SETKMSGREDIRECT:
  2144. if (!capable(CAP_SYS_ADMIN)) {
  2145. ret = -EPERM;
  2146. } else {
  2147. if (get_user(data, p+1))
  2148. ret = -EFAULT;
  2149. else
  2150. kmsg_redirect = data;
  2151. }
  2152. break;
  2153. case TIOCL_GETFGCONSOLE:
  2154. ret = fg_console;
  2155. break;
  2156. case TIOCL_SCROLLCONSOLE:
  2157. if (get_user(lines, (s32 __user *)(p+4))) {
  2158. ret = -EFAULT;
  2159. } else {
  2160. scrollfront(vc_cons[fg_console].d, lines);
  2161. ret = 0;
  2162. }
  2163. break;
  2164. case TIOCL_BLANKSCREEN: /* until explicitly unblanked, not only poked */
  2165. acquire_console_sem();
  2166. ignore_poke = 1;
  2167. do_blank_screen(0);
  2168. release_console_sem();
  2169. break;
  2170. case TIOCL_BLANKEDSCREEN:
  2171. ret = console_blanked;
  2172. break;
  2173. default:
  2174. ret = -EINVAL;
  2175. break;
  2176. }
  2177. return ret;
  2178. }
  2179. /*
  2180. * /dev/ttyN handling
  2181. */
  2182. static int con_write(struct tty_struct *tty, const unsigned char *buf, int count)
  2183. {
  2184. int retval;
  2185. retval = do_con_write(tty, buf, count);
  2186. con_flush_chars(tty);
  2187. return retval;
  2188. }
  2189. static void con_put_char(struct tty_struct *tty, unsigned char ch)
  2190. {
  2191. if (in_interrupt())
  2192. return; /* n_r3964 calls put_char() from interrupt context */
  2193. do_con_write(tty, &ch, 1);
  2194. }
  2195. static int con_write_room(struct tty_struct *tty)
  2196. {
  2197. if (tty->stopped)
  2198. return 0;
  2199. return 4096; /* No limit, really; we're not buffering */
  2200. }
  2201. static int con_chars_in_buffer(struct tty_struct *tty)
  2202. {
  2203. return 0; /* we're not buffering */
  2204. }
  2205. /*
  2206. * con_throttle and con_unthrottle are only used for
  2207. * paste_selection(), which has to stuff in a large number of
  2208. * characters...
  2209. */
  2210. static void con_throttle(struct tty_struct *tty)
  2211. {
  2212. }
  2213. static void con_unthrottle(struct tty_struct *tty)
  2214. {
  2215. struct vc_data *vc = tty->driver_data;
  2216. wake_up_interruptible(&vc->paste_wait);
  2217. }
  2218. /*
  2219. * Turn the Scroll-Lock LED on when the tty is stopped
  2220. */
  2221. static void con_stop(struct tty_struct *tty)
  2222. {
  2223. int console_num;
  2224. if (!tty)
  2225. return;
  2226. console_num = tty->index;
  2227. if (!vc_cons_allocated(console_num))
  2228. return;
  2229. set_vc_kbd_led(kbd_table + console_num, VC_SCROLLOCK);
  2230. set_leds();
  2231. }
  2232. /*
  2233. * Turn the Scroll-Lock LED off when the console is started
  2234. */
  2235. static void con_start(struct tty_struct *tty)
  2236. {
  2237. int console_num;
  2238. if (!tty)
  2239. return;
  2240. console_num = tty->index;
  2241. if (!vc_cons_allocated(console_num))
  2242. return;
  2243. clr_vc_kbd_led(kbd_table + console_num, VC_SCROLLOCK);
  2244. set_leds();
  2245. }
  2246. static void con_flush_chars(struct tty_struct *tty)
  2247. {
  2248. struct vc_data *vc;
  2249. if (in_interrupt()) /* from flush_to_ldisc */
  2250. return;
  2251. /* if we race with con_close(), vt may be null */
  2252. acquire_console_sem();
  2253. vc = tty->driver_data;
  2254. if (vc)
  2255. set_cursor(vc);
  2256. release_console_sem();
  2257. }
  2258. /*
  2259. * Allocate the console screen memory.
  2260. */
  2261. static int con_open(struct tty_struct *tty, struct file *filp)
  2262. {
  2263. unsigned int currcons = tty->index;
  2264. int ret = 0;
  2265. acquire_console_sem();
  2266. if (tty->driver_data == NULL) {
  2267. ret = vc_allocate(currcons);
  2268. if (ret == 0) {
  2269. struct vc_data *vc = vc_cons[currcons].d;
  2270. tty->driver_data = vc;
  2271. vc->vc_tty = tty;
  2272. if (!tty->winsize.ws_row && !tty->winsize.ws_col) {
  2273. tty->winsize.ws_row = vc_cons[currcons].d->vc_rows;
  2274. tty->winsize.ws_col = vc_cons[currcons].d->vc_cols;
  2275. }
  2276. release_console_sem();
  2277. vcs_make_devfs(tty);
  2278. return ret;
  2279. }
  2280. }
  2281. release_console_sem();
  2282. return ret;
  2283. }
  2284. /*
  2285. * We take tty_mutex in here to prevent another thread from coming in via init_dev
  2286. * and taking a ref against the tty while we're in the process of forgetting
  2287. * about it and cleaning things up.
  2288. *
  2289. * This is because vcs_remove_devfs() can sleep and will drop the BKL.
  2290. */
  2291. static void con_close(struct tty_struct *tty, struct file *filp)
  2292. {
  2293. mutex_lock(&tty_mutex);
  2294. acquire_console_sem();
  2295. if (tty && tty->count == 1) {
  2296. struct vc_data *vc = tty->driver_data;
  2297. if (vc)
  2298. vc->vc_tty = NULL;
  2299. tty->driver_data = NULL;
  2300. release_console_sem();
  2301. vcs_remove_devfs(tty);
  2302. mutex_unlock(&tty_mutex);
  2303. /*
  2304. * tty_mutex is released, but we still hold BKL, so there is
  2305. * still exclusion against init_dev()
  2306. */
  2307. return;
  2308. }
  2309. release_console_sem();
  2310. mutex_unlock(&tty_mutex);
  2311. }
  2312. static void vc_init(struct vc_data *vc, unsigned int rows,
  2313. unsigned int cols, int do_clear)
  2314. {
  2315. int j, k ;
  2316. vc->vc_cols = cols;
  2317. vc->vc_rows = rows;
  2318. vc->vc_size_row = cols << 1;
  2319. vc->vc_screenbuf_size = vc->vc_rows * vc->vc_size_row;
  2320. set_origin(vc);
  2321. vc->vc_pos = vc->vc_origin;
  2322. reset_vc(vc);
  2323. for (j=k=0; j<16; j++) {
  2324. vc->vc_palette[k++] = default_red[j] ;
  2325. vc->vc_palette[k++] = default_grn[j] ;
  2326. vc->vc_palette[k++] = default_blu[j] ;
  2327. }
  2328. vc->vc_def_color = 0x07; /* white */
  2329. vc->vc_ulcolor = 0x0f; /* bold white */
  2330. vc->vc_halfcolor = 0x08; /* grey */
  2331. init_waitqueue_head(&vc->paste_wait);
  2332. reset_terminal(vc, do_clear);
  2333. }
  2334. /*
  2335. * This routine initializes console interrupts, and does nothing
  2336. * else. If you want the screen to clear, call tty_write with
  2337. * the appropriate escape-sequence.
  2338. */
  2339. static int __init con_init(void)
  2340. {
  2341. const char *display_desc = NULL;
  2342. struct vc_data *vc;
  2343. unsigned int currcons = 0, i;
  2344. acquire_console_sem();
  2345. if (conswitchp)
  2346. display_desc = conswitchp->con_startup();
  2347. if (!display_desc) {
  2348. fg_console = 0;
  2349. release_console_sem();
  2350. return 0;
  2351. }
  2352. for (i = 0; i < MAX_NR_CON_DRIVER; i++) {
  2353. struct con_driver *con_driver = &registered_con_driver[i];
  2354. if (con_driver->con == NULL) {
  2355. con_driver->con = conswitchp;
  2356. con_driver->desc = display_desc;
  2357. con_driver->flag = CON_DRIVER_FLAG_INIT;
  2358. con_driver->first = 0;
  2359. con_driver->last = MAX_NR_CONSOLES - 1;
  2360. break;
  2361. }
  2362. }
  2363. for (i = 0; i < MAX_NR_CONSOLES; i++)
  2364. con_driver_map[i] = conswitchp;
  2365. init_timer(&console_timer);
  2366. console_timer.function = blank_screen_t;
  2367. if (blankinterval) {
  2368. blank_state = blank_normal_wait;
  2369. mod_timer(&console_timer, jiffies + blankinterval);
  2370. }
  2371. /*
  2372. * kmalloc is not running yet - we use the bootmem allocator.
  2373. */
  2374. for (currcons = 0; currcons < MIN_NR_CONSOLES; currcons++) {
  2375. vc_cons[currcons].d = vc = alloc_bootmem(sizeof(struct vc_data));
  2376. visual_init(vc, currcons, 1);
  2377. vc->vc_screenbuf = (unsigned short *)alloc_bootmem(vc->vc_screenbuf_size);
  2378. vc->vc_kmalloced = 0;
  2379. vc_init(vc, vc->vc_rows, vc->vc_cols,
  2380. currcons || !vc->vc_sw->con_save_screen);
  2381. }
  2382. currcons = fg_console = 0;
  2383. master_display_fg = vc = vc_cons[currcons].d;
  2384. set_origin(vc);
  2385. save_screen(vc);
  2386. gotoxy(vc, vc->vc_x, vc->vc_y);
  2387. csi_J(vc, 0);
  2388. update_screen(vc);
  2389. printk("Console: %s %s %dx%d",
  2390. vc->vc_can_do_color ? "colour" : "mono",
  2391. display_desc, vc->vc_cols, vc->vc_rows);
  2392. printable = 1;
  2393. printk("\n");
  2394. release_console_sem();
  2395. #ifdef CONFIG_VT_CONSOLE
  2396. register_console(&vt_console_driver);
  2397. #endif
  2398. return 0;
  2399. }
  2400. console_initcall(con_init);
  2401. static struct tty_operations con_ops = {
  2402. .open = con_open,
  2403. .close = con_close,
  2404. .write = con_write,
  2405. .write_room = con_write_room,
  2406. .put_char = con_put_char,
  2407. .flush_chars = con_flush_chars,
  2408. .chars_in_buffer = con_chars_in_buffer,
  2409. .ioctl = vt_ioctl,
  2410. .stop = con_stop,
  2411. .start = con_start,
  2412. .throttle = con_throttle,
  2413. .unthrottle = con_unthrottle,
  2414. };
  2415. int __init vty_init(void)
  2416. {
  2417. vcs_init();
  2418. console_driver = alloc_tty_driver(MAX_NR_CONSOLES);
  2419. if (!console_driver)
  2420. panic("Couldn't allocate console driver\n");
  2421. console_driver->owner = THIS_MODULE;
  2422. console_driver->devfs_name = "vc/";
  2423. console_driver->name = "tty";
  2424. console_driver->name_base = 1;
  2425. console_driver->major = TTY_MAJOR;
  2426. console_driver->minor_start = 1;
  2427. console_driver->type = TTY_DRIVER_TYPE_CONSOLE;
  2428. console_driver->init_termios = tty_std_termios;
  2429. console_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_RESET_TERMIOS;
  2430. tty_set_operations(console_driver, &con_ops);
  2431. if (tty_register_driver(console_driver))
  2432. panic("Couldn't register console driver\n");
  2433. kbd_init();
  2434. console_map_init();
  2435. #ifdef CONFIG_PROM_CONSOLE
  2436. prom_con_init();
  2437. #endif
  2438. #ifdef CONFIG_MDA_CONSOLE
  2439. mda_console_init();
  2440. #endif
  2441. return 0;
  2442. }
  2443. #ifndef VT_SINGLE_DRIVER
  2444. #include <linux/device.h>
  2445. static struct class *vtconsole_class;
  2446. static int bind_con_driver(const struct consw *csw, int first, int last,
  2447. int deflt)
  2448. {
  2449. struct module *owner = csw->owner;
  2450. const char *desc = NULL;
  2451. struct con_driver *con_driver;
  2452. int i, j = -1, k = -1, retval = -ENODEV;
  2453. if (!try_module_get(owner))
  2454. return -ENODEV;
  2455. acquire_console_sem();
  2456. /* check if driver is registered */
  2457. for (i = 0; i < MAX_NR_CON_DRIVER; i++) {
  2458. con_driver = &registered_con_driver[i];
  2459. if (con_driver->con == csw) {
  2460. desc = con_driver->desc;
  2461. retval = 0;
  2462. break;
  2463. }
  2464. }
  2465. if (retval)
  2466. goto err;
  2467. if (!(con_driver->flag & CON_DRIVER_FLAG_INIT)) {
  2468. csw->con_startup();
  2469. con_driver->flag |= CON_DRIVER_FLAG_INIT;
  2470. }
  2471. if (deflt) {
  2472. if (conswitchp)
  2473. module_put(conswitchp->owner);
  2474. __module_get(owner);
  2475. conswitchp = csw;
  2476. }
  2477. first = max(first, con_driver->first);
  2478. last = min(last, con_driver->last);
  2479. for (i = first; i <= last; i++) {
  2480. int old_was_color;
  2481. struct vc_data *vc = vc_cons[i].d;
  2482. if (con_driver_map[i])
  2483. module_put(con_driver_map[i]->owner);
  2484. __module_get(owner);
  2485. con_driver_map[i] = csw;
  2486. if (!vc || !vc->vc_sw)
  2487. continue;
  2488. j = i;
  2489. if (CON_IS_VISIBLE(vc)) {
  2490. k = i;
  2491. save_screen(vc);
  2492. }
  2493. old_was_color = vc->vc_can_do_color;
  2494. vc->vc_sw->con_deinit(vc);
  2495. vc->vc_origin = (unsigned long)vc->vc_screenbuf;
  2496. visual_init(vc, i, 0);
  2497. set_origin(vc);
  2498. update_attr(vc);
  2499. /* If the console changed between mono <-> color, then
  2500. * the attributes in the screenbuf will be wrong. The
  2501. * following resets all attributes to something sane.
  2502. */
  2503. if (old_was_color != vc->vc_can_do_color)
  2504. clear_buffer_attributes(vc);
  2505. }
  2506. printk("Console: switching ");
  2507. if (!deflt)
  2508. printk("consoles %d-%d ", first+1, last+1);
  2509. if (j >= 0) {
  2510. struct vc_data *vc = vc_cons[j].d;
  2511. printk("to %s %s %dx%d\n",
  2512. vc->vc_can_do_color ? "colour" : "mono",
  2513. desc, vc->vc_cols, vc->vc_rows);
  2514. if (k >= 0) {
  2515. vc = vc_cons[k].d;
  2516. update_screen(vc);
  2517. }
  2518. } else
  2519. printk("to %s\n", desc);
  2520. retval = 0;
  2521. err:
  2522. release_console_sem();
  2523. module_put(owner);
  2524. return retval;
  2525. };
  2526. #ifdef CONFIG_VT_HW_CONSOLE_BINDING
  2527. static int con_is_graphics(const struct consw *csw, int first, int last)
  2528. {
  2529. int i, retval = 0;
  2530. for (i = first; i <= last; i++) {
  2531. struct vc_data *vc = vc_cons[i].d;
  2532. if (vc && vc->vc_mode == KD_GRAPHICS) {
  2533. retval = 1;
  2534. break;
  2535. }
  2536. }
  2537. return retval;
  2538. }
  2539. static int unbind_con_driver(const struct consw *csw, int first, int last,
  2540. int deflt)
  2541. {
  2542. struct module *owner = csw->owner;
  2543. const struct consw *defcsw = NULL;
  2544. struct con_driver *con_driver = NULL, *con_back = NULL;
  2545. int i, retval = -ENODEV;
  2546. if (!try_module_get(owner))
  2547. return -ENODEV;
  2548. acquire_console_sem();
  2549. /* check if driver is registered and if it is unbindable */
  2550. for (i = 0; i < MAX_NR_CON_DRIVER; i++) {
  2551. con_driver = &registered_con_driver[i];
  2552. if (con_driver->con == csw &&
  2553. con_driver->flag & CON_DRIVER_FLAG_MODULE) {
  2554. retval = 0;
  2555. break;
  2556. }
  2557. }
  2558. if (retval) {
  2559. release_console_sem();
  2560. goto err;
  2561. }
  2562. retval = -ENODEV;
  2563. /* check if backup driver exists */
  2564. for (i = 0; i < MAX_NR_CON_DRIVER; i++) {
  2565. con_back = &registered_con_driver[i];
  2566. if (con_back->con &&
  2567. !(con_back->flag & CON_DRIVER_FLAG_MODULE)) {
  2568. defcsw = con_back->con;
  2569. retval = 0;
  2570. break;
  2571. }
  2572. }
  2573. if (retval) {
  2574. release_console_sem();
  2575. goto err;
  2576. }
  2577. if (!con_is_bound(csw)) {
  2578. release_console_sem();
  2579. goto err;
  2580. }
  2581. first = max(first, con_driver->first);
  2582. last = min(last, con_driver->last);
  2583. for (i = first; i <= last; i++) {
  2584. if (con_driver_map[i] == csw) {
  2585. module_put(csw->owner);
  2586. con_driver_map[i] = NULL;
  2587. }
  2588. }
  2589. if (!con_is_bound(defcsw)) {
  2590. const struct consw *defconsw = conswitchp;
  2591. defcsw->con_startup();
  2592. con_back->flag |= CON_DRIVER_FLAG_INIT;
  2593. /*
  2594. * vgacon may change the default driver to point
  2595. * to dummycon, we restore it here...
  2596. */
  2597. conswitchp = defconsw;
  2598. }
  2599. if (!con_is_bound(csw))
  2600. con_driver->flag &= ~CON_DRIVER_FLAG_INIT;
  2601. release_console_sem();
  2602. /* ignore return value, binding should not fail */
  2603. bind_con_driver(defcsw, first, last, deflt);
  2604. err:
  2605. module_put(owner);
  2606. return retval;
  2607. }
  2608. static int vt_bind(struct con_driver *con)
  2609. {
  2610. const struct consw *defcsw = NULL, *csw = NULL;
  2611. int i, more = 1, first = -1, last = -1, deflt = 0;
  2612. if (!con->con || !(con->flag & CON_DRIVER_FLAG_MODULE) ||
  2613. con_is_graphics(con->con, con->first, con->last))
  2614. goto err;
  2615. csw = con->con;
  2616. for (i = 0; i < MAX_NR_CON_DRIVER; i++) {
  2617. struct con_driver *con = &registered_con_driver[i];
  2618. if (con->con && !(con->flag & CON_DRIVER_FLAG_MODULE)) {
  2619. defcsw = con->con;
  2620. break;
  2621. }
  2622. }
  2623. if (!defcsw)
  2624. goto err;
  2625. while (more) {
  2626. more = 0;
  2627. for (i = con->first; i <= con->last; i++) {
  2628. if (con_driver_map[i] == defcsw) {
  2629. if (first == -1)
  2630. first = i;
  2631. last = i;
  2632. more = 1;
  2633. } else if (first != -1)
  2634. break;
  2635. }
  2636. if (first == 0 && last == MAX_NR_CONSOLES -1)
  2637. deflt = 1;
  2638. if (first != -1)
  2639. bind_con_driver(csw, first, last, deflt);
  2640. first = -1;
  2641. last = -1;
  2642. deflt = 0;
  2643. }
  2644. err:
  2645. return 0;
  2646. }
  2647. static int vt_unbind(struct con_driver *con)
  2648. {
  2649. const struct consw *csw = NULL;
  2650. int i, more = 1, first = -1, last = -1, deflt = 0;
  2651. if (!con->con || !(con->flag & CON_DRIVER_FLAG_MODULE) ||
  2652. con_is_graphics(con->con, con->first, con->last))
  2653. goto err;
  2654. csw = con->con;
  2655. while (more) {
  2656. more = 0;
  2657. for (i = con->first; i <= con->last; i++) {
  2658. if (con_driver_map[i] == csw) {
  2659. if (first == -1)
  2660. first = i;
  2661. last = i;
  2662. more = 1;
  2663. } else if (first != -1)
  2664. break;
  2665. }
  2666. if (first == 0 && last == MAX_NR_CONSOLES -1)
  2667. deflt = 1;
  2668. if (first != -1)
  2669. unbind_con_driver(csw, first, last, deflt);
  2670. first = -1;
  2671. last = -1;
  2672. deflt = 0;
  2673. }
  2674. err:
  2675. return 0;
  2676. }
  2677. #else
  2678. static inline int vt_bind(struct con_driver *con)
  2679. {
  2680. return 0;
  2681. }
  2682. static inline int vt_unbind(struct con_driver *con)
  2683. {
  2684. return 0;
  2685. }
  2686. #endif /* CONFIG_VT_HW_CONSOLE_BINDING */
  2687. static ssize_t store_bind(struct class_device *class_device,
  2688. const char *buf, size_t count)
  2689. {
  2690. struct con_driver *con = class_get_devdata(class_device);
  2691. int bind = simple_strtoul(buf, NULL, 0);
  2692. if (bind)
  2693. vt_bind(con);
  2694. else
  2695. vt_unbind(con);
  2696. return count;
  2697. }
  2698. static ssize_t show_bind(struct class_device *class_device, char *buf)
  2699. {
  2700. struct con_driver *con = class_get_devdata(class_device);
  2701. int bind = con_is_bound(con->con);
  2702. return snprintf(buf, PAGE_SIZE, "%i\n", bind);
  2703. }
  2704. static ssize_t show_name(struct class_device *class_device, char *buf)
  2705. {
  2706. struct con_driver *con = class_get_devdata(class_device);
  2707. return snprintf(buf, PAGE_SIZE, "%s %s\n",
  2708. (con->flag & CON_DRIVER_FLAG_MODULE) ? "(M)" : "(S)",
  2709. con->desc);
  2710. }
  2711. static struct class_device_attribute class_device_attrs[] = {
  2712. __ATTR(bind, S_IRUGO|S_IWUSR, show_bind, store_bind),
  2713. __ATTR(name, S_IRUGO, show_name, NULL),
  2714. };
  2715. static int vtconsole_init_class_device(struct con_driver *con)
  2716. {
  2717. int i;
  2718. class_set_devdata(con->class_dev, con);
  2719. for (i = 0; i < ARRAY_SIZE(class_device_attrs); i++)
  2720. class_device_create_file(con->class_dev,
  2721. &class_device_attrs[i]);
  2722. return 0;
  2723. }
  2724. static void vtconsole_deinit_class_device(struct con_driver *con)
  2725. {
  2726. int i;
  2727. for (i = 0; i < ARRAY_SIZE(class_device_attrs); i++)
  2728. class_device_remove_file(con->class_dev,
  2729. &class_device_attrs[i]);
  2730. }
  2731. /**
  2732. * con_is_bound - checks if driver is bound to the console
  2733. * @csw: console driver
  2734. *
  2735. * RETURNS: zero if unbound, nonzero if bound
  2736. *
  2737. * Drivers can call this and if zero, they should release
  2738. * all resources allocated on con_startup()
  2739. */
  2740. int con_is_bound(const struct consw *csw)
  2741. {
  2742. int i, bound = 0;
  2743. for (i = 0; i < MAX_NR_CONSOLES; i++) {
  2744. if (con_driver_map[i] == csw) {
  2745. bound = 1;
  2746. break;
  2747. }
  2748. }
  2749. return bound;
  2750. }
  2751. EXPORT_SYMBOL(con_is_bound);
  2752. /**
  2753. * register_con_driver - register console driver to console layer
  2754. * @csw: console driver
  2755. * @first: the first console to take over, minimum value is 0
  2756. * @last: the last console to take over, maximum value is MAX_NR_CONSOLES -1
  2757. *
  2758. * DESCRIPTION: This function registers a console driver which can later
  2759. * bind to a range of consoles specified by @first and @last. It will
  2760. * also initialize the console driver by calling con_startup().
  2761. */
  2762. int register_con_driver(const struct consw *csw, int first, int last)
  2763. {
  2764. struct module *owner = csw->owner;
  2765. struct con_driver *con_driver;
  2766. const char *desc;
  2767. int i, retval = 0;
  2768. if (!try_module_get(owner))
  2769. return -ENODEV;
  2770. acquire_console_sem();
  2771. for (i = 0; i < MAX_NR_CON_DRIVER; i++) {
  2772. con_driver = &registered_con_driver[i];
  2773. /* already registered */
  2774. if (con_driver->con == csw)
  2775. retval = -EINVAL;
  2776. }
  2777. if (retval)
  2778. goto err;
  2779. desc = csw->con_startup();
  2780. if (!desc)
  2781. goto err;
  2782. retval = -EINVAL;
  2783. for (i = 0; i < MAX_NR_CON_DRIVER; i++) {
  2784. con_driver = &registered_con_driver[i];
  2785. if (con_driver->con == NULL) {
  2786. con_driver->con = csw;
  2787. con_driver->desc = desc;
  2788. con_driver->node = i;
  2789. con_driver->flag = CON_DRIVER_FLAG_MODULE |
  2790. CON_DRIVER_FLAG_INIT;
  2791. con_driver->first = first;
  2792. con_driver->last = last;
  2793. retval = 0;
  2794. break;
  2795. }
  2796. }
  2797. if (retval)
  2798. goto err;
  2799. con_driver->class_dev = class_device_create(vtconsole_class, NULL,
  2800. MKDEV(0, con_driver->node),
  2801. NULL, "vtcon%i",
  2802. con_driver->node);
  2803. if (IS_ERR(con_driver->class_dev)) {
  2804. printk(KERN_WARNING "Unable to create class_device for %s; "
  2805. "errno = %ld\n", con_driver->desc,
  2806. PTR_ERR(con_driver->class_dev));
  2807. con_driver->class_dev = NULL;
  2808. } else {
  2809. vtconsole_init_class_device(con_driver);
  2810. }
  2811. err:
  2812. release_console_sem();
  2813. module_put(owner);
  2814. return retval;
  2815. }
  2816. EXPORT_SYMBOL(register_con_driver);
  2817. /**
  2818. * unregister_con_driver - unregister console driver from console layer
  2819. * @csw: console driver
  2820. *
  2821. * DESCRIPTION: All drivers that registers to the console layer must
  2822. * call this function upon exit, or if the console driver is in a state
  2823. * where it won't be able to handle console services, such as the
  2824. * framebuffer console without loaded framebuffer drivers.
  2825. *
  2826. * The driver must unbind first prior to unregistration.
  2827. */
  2828. int unregister_con_driver(const struct consw *csw)
  2829. {
  2830. int i, retval = -ENODEV;
  2831. acquire_console_sem();
  2832. /* cannot unregister a bound driver */
  2833. if (con_is_bound(csw))
  2834. goto err;
  2835. for (i = 0; i < MAX_NR_CON_DRIVER; i++) {
  2836. struct con_driver *con_driver = &registered_con_driver[i];
  2837. if (con_driver->con == csw &&
  2838. con_driver->flag & CON_DRIVER_FLAG_MODULE) {
  2839. vtconsole_deinit_class_device(con_driver);
  2840. class_device_destroy(vtconsole_class,
  2841. MKDEV(0, con_driver->node));
  2842. con_driver->con = NULL;
  2843. con_driver->desc = NULL;
  2844. con_driver->class_dev = NULL;
  2845. con_driver->node = 0;
  2846. con_driver->flag = 0;
  2847. con_driver->first = 0;
  2848. con_driver->last = 0;
  2849. retval = 0;
  2850. break;
  2851. }
  2852. }
  2853. err:
  2854. release_console_sem();
  2855. return retval;
  2856. }
  2857. EXPORT_SYMBOL(unregister_con_driver);
  2858. /*
  2859. * If we support more console drivers, this function is used
  2860. * when a driver wants to take over some existing consoles
  2861. * and become default driver for newly opened ones.
  2862. *
  2863. * take_over_console is basically a register followed by unbind
  2864. */
  2865. int take_over_console(const struct consw *csw, int first, int last, int deflt)
  2866. {
  2867. int err;
  2868. err = register_con_driver(csw, first, last);
  2869. if (!err)
  2870. bind_con_driver(csw, first, last, deflt);
  2871. return err;
  2872. }
  2873. /*
  2874. * give_up_console is a wrapper to unregister_con_driver. It will only
  2875. * work if driver is fully unbound.
  2876. */
  2877. void give_up_console(const struct consw *csw)
  2878. {
  2879. unregister_con_driver(csw);
  2880. }
  2881. static int __init vtconsole_class_init(void)
  2882. {
  2883. int i;
  2884. vtconsole_class = class_create(THIS_MODULE, "vtconsole");
  2885. if (IS_ERR(vtconsole_class)) {
  2886. printk(KERN_WARNING "Unable to create vt console class; "
  2887. "errno = %ld\n", PTR_ERR(vtconsole_class));
  2888. vtconsole_class = NULL;
  2889. }
  2890. /* Add system drivers to sysfs */
  2891. for (i = 0; i < MAX_NR_CON_DRIVER; i++) {
  2892. struct con_driver *con = &registered_con_driver[i];
  2893. if (con->con && !con->class_dev) {
  2894. con->class_dev =
  2895. class_device_create(vtconsole_class, NULL,
  2896. MKDEV(0, con->node), NULL,
  2897. "vtcon%i", con->node);
  2898. if (IS_ERR(con->class_dev)) {
  2899. printk(KERN_WARNING "Unable to create "
  2900. "class_device for %s; errno = %ld\n",
  2901. con->desc, PTR_ERR(con->class_dev));
  2902. con->class_dev = NULL;
  2903. } else {
  2904. vtconsole_init_class_device(con);
  2905. }
  2906. }
  2907. }
  2908. return 0;
  2909. }
  2910. postcore_initcall(vtconsole_class_init);
  2911. #endif
  2912. /*
  2913. * Screen blanking
  2914. */
  2915. static void set_vesa_blanking(char __user *p)
  2916. {
  2917. unsigned int mode;
  2918. get_user(mode, p + 1);
  2919. vesa_blank_mode = (mode < 4) ? mode : 0;
  2920. }
  2921. void do_blank_screen(int entering_gfx)
  2922. {
  2923. struct vc_data *vc = vc_cons[fg_console].d;
  2924. int i;
  2925. WARN_CONSOLE_UNLOCKED();
  2926. if (console_blanked) {
  2927. if (blank_state == blank_vesa_wait) {
  2928. blank_state = blank_off;
  2929. vc->vc_sw->con_blank(vc, vesa_blank_mode + 1, 0);
  2930. }
  2931. return;
  2932. }
  2933. if (blank_state != blank_normal_wait)
  2934. return;
  2935. blank_state = blank_off;
  2936. /* entering graphics mode? */
  2937. if (entering_gfx) {
  2938. hide_cursor(vc);
  2939. save_screen(vc);
  2940. vc->vc_sw->con_blank(vc, -1, 1);
  2941. console_blanked = fg_console + 1;
  2942. set_origin(vc);
  2943. return;
  2944. }
  2945. /* don't blank graphics */
  2946. if (vc->vc_mode != KD_TEXT) {
  2947. console_blanked = fg_console + 1;
  2948. return;
  2949. }
  2950. hide_cursor(vc);
  2951. del_timer_sync(&console_timer);
  2952. blank_timer_expired = 0;
  2953. save_screen(vc);
  2954. /* In case we need to reset origin, blanking hook returns 1 */
  2955. i = vc->vc_sw->con_blank(vc, vesa_off_interval ? 1 : (vesa_blank_mode + 1), 0);
  2956. console_blanked = fg_console + 1;
  2957. if (i)
  2958. set_origin(vc);
  2959. if (console_blank_hook && console_blank_hook(1))
  2960. return;
  2961. if (vesa_off_interval && vesa_blank_mode) {
  2962. blank_state = blank_vesa_wait;
  2963. mod_timer(&console_timer, jiffies + vesa_off_interval);
  2964. }
  2965. }
  2966. EXPORT_SYMBOL(do_blank_screen);
  2967. /*
  2968. * Called by timer as well as from vt_console_driver
  2969. */
  2970. void do_unblank_screen(int leaving_gfx)
  2971. {
  2972. struct vc_data *vc;
  2973. /* This should now always be called from a "sane" (read: can schedule)
  2974. * context for the sake of the low level drivers, except in the special
  2975. * case of oops_in_progress
  2976. */
  2977. if (!oops_in_progress)
  2978. might_sleep();
  2979. WARN_CONSOLE_UNLOCKED();
  2980. ignore_poke = 0;
  2981. if (!console_blanked)
  2982. return;
  2983. if (!vc_cons_allocated(fg_console)) {
  2984. /* impossible */
  2985. printk("unblank_screen: tty %d not allocated ??\n", fg_console+1);
  2986. return;
  2987. }
  2988. vc = vc_cons[fg_console].d;
  2989. if (vc->vc_mode != KD_TEXT)
  2990. return; /* but leave console_blanked != 0 */
  2991. if (blankinterval) {
  2992. mod_timer(&console_timer, jiffies + blankinterval);
  2993. blank_state = blank_normal_wait;
  2994. }
  2995. console_blanked = 0;
  2996. if (vc->vc_sw->con_blank(vc, 0, leaving_gfx))
  2997. /* Low-level driver cannot restore -> do it ourselves */
  2998. update_screen(vc);
  2999. if (console_blank_hook)
  3000. console_blank_hook(0);
  3001. set_palette(vc);
  3002. set_cursor(vc);
  3003. }
  3004. EXPORT_SYMBOL(do_unblank_screen);
  3005. /*
  3006. * This is called by the outside world to cause a forced unblank, mostly for
  3007. * oopses. Currently, I just call do_unblank_screen(0), but we could eventually
  3008. * call it with 1 as an argument and so force a mode restore... that may kill
  3009. * X or at least garbage the screen but would also make the Oops visible...
  3010. */
  3011. void unblank_screen(void)
  3012. {
  3013. do_unblank_screen(0);
  3014. }
  3015. /*
  3016. * We defer the timer blanking to work queue so it can take the console mutex
  3017. * (console operations can still happen at irq time, but only from printk which
  3018. * has the console mutex. Not perfect yet, but better than no locking
  3019. */
  3020. static void blank_screen_t(unsigned long dummy)
  3021. {
  3022. if (unlikely(!keventd_up())) {
  3023. mod_timer(&console_timer, jiffies + blankinterval);
  3024. return;
  3025. }
  3026. blank_timer_expired = 1;
  3027. schedule_work(&console_work);
  3028. }
  3029. void poke_blanked_console(void)
  3030. {
  3031. WARN_CONSOLE_UNLOCKED();
  3032. /* Add this so we quickly catch whoever might call us in a non
  3033. * safe context. Nowadays, unblank_screen() isn't to be called in
  3034. * atomic contexts and is allowed to schedule (with the special case
  3035. * of oops_in_progress, but that isn't of any concern for this
  3036. * function. --BenH.
  3037. */
  3038. might_sleep();
  3039. /* This isn't perfectly race free, but a race here would be mostly harmless,
  3040. * at worse, we'll do a spurrious blank and it's unlikely
  3041. */
  3042. del_timer(&console_timer);
  3043. blank_timer_expired = 0;
  3044. if (ignore_poke || !vc_cons[fg_console].d || vc_cons[fg_console].d->vc_mode == KD_GRAPHICS)
  3045. return;
  3046. if (console_blanked)
  3047. unblank_screen();
  3048. else if (blankinterval) {
  3049. mod_timer(&console_timer, jiffies + blankinterval);
  3050. blank_state = blank_normal_wait;
  3051. }
  3052. }
  3053. /*
  3054. * Palettes
  3055. */
  3056. static void set_palette(struct vc_data *vc)
  3057. {
  3058. WARN_CONSOLE_UNLOCKED();
  3059. if (vc->vc_mode != KD_GRAPHICS)
  3060. vc->vc_sw->con_set_palette(vc, color_table);
  3061. }
  3062. static int set_get_cmap(unsigned char __user *arg, int set)
  3063. {
  3064. int i, j, k;
  3065. WARN_CONSOLE_UNLOCKED();
  3066. for (i = 0; i < 16; i++)
  3067. if (set) {
  3068. get_user(default_red[i], arg++);
  3069. get_user(default_grn[i], arg++);
  3070. get_user(default_blu[i], arg++);
  3071. } else {
  3072. put_user(default_red[i], arg++);
  3073. put_user(default_grn[i], arg++);
  3074. put_user(default_blu[i], arg++);
  3075. }
  3076. if (set) {
  3077. for (i = 0; i < MAX_NR_CONSOLES; i++)
  3078. if (vc_cons_allocated(i)) {
  3079. for (j = k = 0; j < 16; j++) {
  3080. vc_cons[i].d->vc_palette[k++] = default_red[j];
  3081. vc_cons[i].d->vc_palette[k++] = default_grn[j];
  3082. vc_cons[i].d->vc_palette[k++] = default_blu[j];
  3083. }
  3084. set_palette(vc_cons[i].d);
  3085. }
  3086. }
  3087. return 0;
  3088. }
  3089. /*
  3090. * Load palette into the DAC registers. arg points to a colour
  3091. * map, 3 bytes per colour, 16 colours, range from 0 to 255.
  3092. */
  3093. int con_set_cmap(unsigned char __user *arg)
  3094. {
  3095. int rc;
  3096. acquire_console_sem();
  3097. rc = set_get_cmap (arg,1);
  3098. release_console_sem();
  3099. return rc;
  3100. }
  3101. int con_get_cmap(unsigned char __user *arg)
  3102. {
  3103. int rc;
  3104. acquire_console_sem();
  3105. rc = set_get_cmap (arg,0);
  3106. release_console_sem();
  3107. return rc;
  3108. }
  3109. void reset_palette(struct vc_data *vc)
  3110. {
  3111. int j, k;
  3112. for (j=k=0; j<16; j++) {
  3113. vc->vc_palette[k++] = default_red[j];
  3114. vc->vc_palette[k++] = default_grn[j];
  3115. vc->vc_palette[k++] = default_blu[j];
  3116. }
  3117. set_palette(vc);
  3118. }
  3119. /*
  3120. * Font switching
  3121. *
  3122. * Currently we only support fonts up to 32 pixels wide, at a maximum height
  3123. * of 32 pixels. Userspace fontdata is stored with 32 bytes (shorts/ints,
  3124. * depending on width) reserved for each character which is kinda wasty, but
  3125. * this is done in order to maintain compatibility with the EGA/VGA fonts. It
  3126. * is upto the actual low-level console-driver convert data into its favorite
  3127. * format (maybe we should add a `fontoffset' field to the `display'
  3128. * structure so we won't have to convert the fontdata all the time.
  3129. * /Jes
  3130. */
  3131. #define max_font_size 65536
  3132. static int con_font_get(struct vc_data *vc, struct console_font_op *op)
  3133. {
  3134. struct console_font font;
  3135. int rc = -EINVAL;
  3136. int c;
  3137. if (vc->vc_mode != KD_TEXT)
  3138. return -EINVAL;
  3139. if (op->data) {
  3140. font.data = kmalloc(max_font_size, GFP_KERNEL);
  3141. if (!font.data)
  3142. return -ENOMEM;
  3143. } else
  3144. font.data = NULL;
  3145. acquire_console_sem();
  3146. if (vc->vc_sw->con_font_get)
  3147. rc = vc->vc_sw->con_font_get(vc, &font);
  3148. else
  3149. rc = -ENOSYS;
  3150. release_console_sem();
  3151. if (rc)
  3152. goto out;
  3153. c = (font.width+7)/8 * 32 * font.charcount;
  3154. if (op->data && font.charcount > op->charcount)
  3155. rc = -ENOSPC;
  3156. if (!(op->flags & KD_FONT_FLAG_OLD)) {
  3157. if (font.width > op->width || font.height > op->height)
  3158. rc = -ENOSPC;
  3159. } else {
  3160. if (font.width != 8)
  3161. rc = -EIO;
  3162. else if ((op->height && font.height > op->height) ||
  3163. font.height > 32)
  3164. rc = -ENOSPC;
  3165. }
  3166. if (rc)
  3167. goto out;
  3168. op->height = font.height;
  3169. op->width = font.width;
  3170. op->charcount = font.charcount;
  3171. if (op->data && copy_to_user(op->data, font.data, c))
  3172. rc = -EFAULT;
  3173. out:
  3174. kfree(font.data);
  3175. return rc;
  3176. }
  3177. static int con_font_set(struct vc_data *vc, struct console_font_op *op)
  3178. {
  3179. struct console_font font;
  3180. int rc = -EINVAL;
  3181. int size;
  3182. if (vc->vc_mode != KD_TEXT)
  3183. return -EINVAL;
  3184. if (!op->data)
  3185. return -EINVAL;
  3186. if (op->charcount > 512)
  3187. return -EINVAL;
  3188. if (!op->height) { /* Need to guess font height [compat] */
  3189. int h, i;
  3190. u8 __user *charmap = op->data;
  3191. u8 tmp;
  3192. /* If from KDFONTOP ioctl, don't allow things which can be done in userland,
  3193. so that we can get rid of this soon */
  3194. if (!(op->flags & KD_FONT_FLAG_OLD))
  3195. return -EINVAL;
  3196. for (h = 32; h > 0; h--)
  3197. for (i = 0; i < op->charcount; i++) {
  3198. if (get_user(tmp, &charmap[32*i+h-1]))
  3199. return -EFAULT;
  3200. if (tmp)
  3201. goto nonzero;
  3202. }
  3203. return -EINVAL;
  3204. nonzero:
  3205. op->height = h;
  3206. }
  3207. if (op->width <= 0 || op->width > 32 || op->height > 32)
  3208. return -EINVAL;
  3209. size = (op->width+7)/8 * 32 * op->charcount;
  3210. if (size > max_font_size)
  3211. return -ENOSPC;
  3212. font.charcount = op->charcount;
  3213. font.height = op->height;
  3214. font.width = op->width;
  3215. font.data = kmalloc(size, GFP_KERNEL);
  3216. if (!font.data)
  3217. return -ENOMEM;
  3218. if (copy_from_user(font.data, op->data, size)) {
  3219. kfree(font.data);
  3220. return -EFAULT;
  3221. }
  3222. acquire_console_sem();
  3223. if (vc->vc_sw->con_font_set)
  3224. rc = vc->vc_sw->con_font_set(vc, &font, op->flags);
  3225. else
  3226. rc = -ENOSYS;
  3227. release_console_sem();
  3228. kfree(font.data);
  3229. return rc;
  3230. }
  3231. static int con_font_default(struct vc_data *vc, struct console_font_op *op)
  3232. {
  3233. struct console_font font = {.width = op->width, .height = op->height};
  3234. char name[MAX_FONT_NAME];
  3235. char *s = name;
  3236. int rc;
  3237. if (vc->vc_mode != KD_TEXT)
  3238. return -EINVAL;
  3239. if (!op->data)
  3240. s = NULL;
  3241. else if (strncpy_from_user(name, op->data, MAX_FONT_NAME - 1) < 0)
  3242. return -EFAULT;
  3243. else
  3244. name[MAX_FONT_NAME - 1] = 0;
  3245. acquire_console_sem();
  3246. if (vc->vc_sw->con_font_default)
  3247. rc = vc->vc_sw->con_font_default(vc, &font, s);
  3248. else
  3249. rc = -ENOSYS;
  3250. release_console_sem();
  3251. if (!rc) {
  3252. op->width = font.width;
  3253. op->height = font.height;
  3254. }
  3255. return rc;
  3256. }
  3257. static int con_font_copy(struct vc_data *vc, struct console_font_op *op)
  3258. {
  3259. int con = op->height;
  3260. int rc;
  3261. if (vc->vc_mode != KD_TEXT)
  3262. return -EINVAL;
  3263. acquire_console_sem();
  3264. if (!vc->vc_sw->con_font_copy)
  3265. rc = -ENOSYS;
  3266. else if (con < 0 || !vc_cons_allocated(con))
  3267. rc = -ENOTTY;
  3268. else if (con == vc->vc_num) /* nothing to do */
  3269. rc = 0;
  3270. else
  3271. rc = vc->vc_sw->con_font_copy(vc, con);
  3272. release_console_sem();
  3273. return rc;
  3274. }
  3275. int con_font_op(struct vc_data *vc, struct console_font_op *op)
  3276. {
  3277. switch (op->op) {
  3278. case KD_FONT_OP_SET:
  3279. return con_font_set(vc, op);
  3280. case KD_FONT_OP_GET:
  3281. return con_font_get(vc, op);
  3282. case KD_FONT_OP_SET_DEFAULT:
  3283. return con_font_default(vc, op);
  3284. case KD_FONT_OP_COPY:
  3285. return con_font_copy(vc, op);
  3286. }
  3287. return -ENOSYS;
  3288. }
  3289. /*
  3290. * Interface exported to selection and vcs.
  3291. */
  3292. /* used by selection */
  3293. u16 screen_glyph(struct vc_data *vc, int offset)
  3294. {
  3295. u16 w = scr_readw(screenpos(vc, offset, 1));
  3296. u16 c = w & 0xff;
  3297. if (w & vc->vc_hi_font_mask)
  3298. c |= 0x100;
  3299. return c;
  3300. }
  3301. /* used by vcs - note the word offset */
  3302. unsigned short *screen_pos(struct vc_data *vc, int w_offset, int viewed)
  3303. {
  3304. return screenpos(vc, 2 * w_offset, viewed);
  3305. }
  3306. void getconsxy(struct vc_data *vc, unsigned char *p)
  3307. {
  3308. p[0] = vc->vc_x;
  3309. p[1] = vc->vc_y;
  3310. }
  3311. void putconsxy(struct vc_data *vc, unsigned char *p)
  3312. {
  3313. hide_cursor(vc);
  3314. gotoxy(vc, p[0], p[1]);
  3315. set_cursor(vc);
  3316. }
  3317. u16 vcs_scr_readw(struct vc_data *vc, const u16 *org)
  3318. {
  3319. if ((unsigned long)org == vc->vc_pos && softcursor_original != -1)
  3320. return softcursor_original;
  3321. return scr_readw(org);
  3322. }
  3323. void vcs_scr_writew(struct vc_data *vc, u16 val, u16 *org)
  3324. {
  3325. scr_writew(val, org);
  3326. if ((unsigned long)org == vc->vc_pos) {
  3327. softcursor_original = -1;
  3328. add_softcursor(vc);
  3329. }
  3330. }
  3331. /*
  3332. * Visible symbols for modules
  3333. */
  3334. EXPORT_SYMBOL(color_table);
  3335. EXPORT_SYMBOL(default_red);
  3336. EXPORT_SYMBOL(default_grn);
  3337. EXPORT_SYMBOL(default_blu);
  3338. EXPORT_SYMBOL(update_region);
  3339. EXPORT_SYMBOL(redraw_screen);
  3340. EXPORT_SYMBOL(vc_resize);
  3341. EXPORT_SYMBOL(fg_console);
  3342. EXPORT_SYMBOL(console_blank_hook);
  3343. EXPORT_SYMBOL(console_blanked);
  3344. EXPORT_SYMBOL(vc_cons);
  3345. #ifndef VT_SINGLE_DRIVER
  3346. EXPORT_SYMBOL(take_over_console);
  3347. EXPORT_SYMBOL(give_up_console);
  3348. #endif