vt.c 91 KB

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