vt.c 89 KB

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