fbcon.c 91 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762
  1. /*
  2. * linux/drivers/video/fbcon.c -- Low level frame buffer based console driver
  3. *
  4. * Copyright (C) 1995 Geert Uytterhoeven
  5. *
  6. *
  7. * This file is based on the original Amiga console driver (amicon.c):
  8. *
  9. * Copyright (C) 1993 Hamish Macdonald
  10. * Greg Harp
  11. * Copyright (C) 1994 David Carter [carter@compsci.bristol.ac.uk]
  12. *
  13. * with work by William Rucklidge (wjr@cs.cornell.edu)
  14. * Geert Uytterhoeven
  15. * Jes Sorensen (jds@kom.auc.dk)
  16. * Martin Apel
  17. *
  18. * and on the original Atari console driver (atacon.c):
  19. *
  20. * Copyright (C) 1993 Bjoern Brauel
  21. * Roman Hodek
  22. *
  23. * with work by Guenther Kelleter
  24. * Martin Schaller
  25. * Andreas Schwab
  26. *
  27. * Hardware cursor support added by Emmanuel Marty (core@ggi-project.org)
  28. * Smart redraw scrolling, arbitrary font width support, 512char font support
  29. * and software scrollback added by
  30. * Jakub Jelinek (jj@ultra.linux.cz)
  31. *
  32. * Random hacking by Martin Mares <mj@ucw.cz>
  33. *
  34. * 2001 - Documented with DocBook
  35. * - Brad Douglas <brad@neruo.com>
  36. *
  37. * The low level operations for the various display memory organizations are
  38. * now in separate source files.
  39. *
  40. * Currently the following organizations are supported:
  41. *
  42. * o afb Amiga bitplanes
  43. * o cfb{2,4,8,16,24,32} Packed pixels
  44. * o ilbm Amiga interleaved bitplanes
  45. * o iplan2p[248] Atari interleaved bitplanes
  46. * o mfb Monochrome
  47. * o vga VGA characters/attributes
  48. *
  49. * To do:
  50. *
  51. * - Implement 16 plane mode (iplan2p16)
  52. *
  53. *
  54. * This file is subject to the terms and conditions of the GNU General Public
  55. * License. See the file COPYING in the main directory of this archive for
  56. * more details.
  57. */
  58. #undef FBCONDEBUG
  59. #include <linux/module.h>
  60. #include <linux/types.h>
  61. #include <linux/fs.h>
  62. #include <linux/kernel.h>
  63. #include <linux/delay.h> /* MSch: for IRQ probe */
  64. #include <linux/console.h>
  65. #include <linux/string.h>
  66. #include <linux/kd.h>
  67. #include <linux/slab.h>
  68. #include <linux/fb.h>
  69. #include <linux/fbcon.h>
  70. #include <linux/vt_kern.h>
  71. #include <linux/selection.h>
  72. #include <linux/font.h>
  73. #include <linux/smp.h>
  74. #include <linux/init.h>
  75. #include <linux/interrupt.h>
  76. #include <linux/crc32.h> /* For counting font checksums */
  77. #include <asm/fb.h>
  78. #include <asm/irq.h>
  79. #include "fbcon.h"
  80. #ifdef FBCONDEBUG
  81. # define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __func__ , ## args)
  82. #else
  83. # define DPRINTK(fmt, args...)
  84. #endif
  85. enum {
  86. FBCON_LOGO_CANSHOW = -1, /* the logo can be shown */
  87. FBCON_LOGO_DRAW = -2, /* draw the logo to a console */
  88. FBCON_LOGO_DONTSHOW = -3 /* do not show the logo */
  89. };
  90. static struct display fb_display[MAX_NR_CONSOLES];
  91. static signed char con2fb_map[MAX_NR_CONSOLES];
  92. static signed char con2fb_map_boot[MAX_NR_CONSOLES];
  93. static int logo_lines;
  94. /* logo_shown is an index to vc_cons when >= 0; otherwise follows FBCON_LOGO
  95. enums. */
  96. static int logo_shown = FBCON_LOGO_CANSHOW;
  97. /* Software scrollback */
  98. static int fbcon_softback_size = 32768;
  99. static unsigned long softback_buf, softback_curr;
  100. static unsigned long softback_in;
  101. static unsigned long softback_top, softback_end;
  102. static int softback_lines;
  103. /* console mappings */
  104. static int first_fb_vc;
  105. static int last_fb_vc = MAX_NR_CONSOLES - 1;
  106. static int fbcon_is_default = 1;
  107. static int fbcon_has_exited;
  108. static int primary_device = -1;
  109. static int fbcon_has_console_bind;
  110. #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
  111. static int map_override;
  112. static inline void fbcon_map_override(void)
  113. {
  114. map_override = 1;
  115. }
  116. #else
  117. static inline void fbcon_map_override(void)
  118. {
  119. }
  120. #endif /* CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY */
  121. #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
  122. static bool deferred_takeover = true;
  123. #else
  124. #define deferred_takeover false
  125. #endif
  126. /* font data */
  127. static char fontname[40];
  128. /* current fb_info */
  129. static int info_idx = -1;
  130. /* console rotation */
  131. static int initial_rotation = -1;
  132. static int fbcon_has_sysfs;
  133. static int margin_color;
  134. static const struct consw fb_con;
  135. #define CM_SOFTBACK (8)
  136. #define advance_row(p, delta) (unsigned short *)((unsigned long)(p) + (delta) * vc->vc_size_row)
  137. static int fbcon_set_origin(struct vc_data *);
  138. static int fbcon_cursor_noblink;
  139. #define divides(a, b) ((!(a) || (b)%(a)) ? 0 : 1)
  140. /*
  141. * Interface used by the world
  142. */
  143. static const char *fbcon_startup(void);
  144. static void fbcon_init(struct vc_data *vc, int init);
  145. static void fbcon_deinit(struct vc_data *vc);
  146. static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
  147. int width);
  148. static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos);
  149. static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
  150. int count, int ypos, int xpos);
  151. static void fbcon_clear_margins(struct vc_data *vc, int bottom_only);
  152. static void fbcon_cursor(struct vc_data *vc, int mode);
  153. static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
  154. int height, int width);
  155. static int fbcon_switch(struct vc_data *vc);
  156. static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch);
  157. static void fbcon_set_palette(struct vc_data *vc, const unsigned char *table);
  158. /*
  159. * Internal routines
  160. */
  161. static __inline__ void ywrap_up(struct vc_data *vc, int count);
  162. static __inline__ void ywrap_down(struct vc_data *vc, int count);
  163. static __inline__ void ypan_up(struct vc_data *vc, int count);
  164. static __inline__ void ypan_down(struct vc_data *vc, int count);
  165. static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
  166. int dy, int dx, int height, int width, u_int y_break);
  167. static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
  168. int unit);
  169. static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
  170. int line, int count, int dy);
  171. static void fbcon_modechanged(struct fb_info *info);
  172. static void fbcon_set_all_vcs(struct fb_info *info);
  173. static void fbcon_start(void);
  174. static void fbcon_exit(void);
  175. static struct device *fbcon_device;
  176. #ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
  177. static inline void fbcon_set_rotation(struct fb_info *info)
  178. {
  179. struct fbcon_ops *ops = info->fbcon_par;
  180. if (!(info->flags & FBINFO_MISC_TILEBLITTING) &&
  181. ops->p->con_rotate < 4)
  182. ops->rotate = ops->p->con_rotate;
  183. else
  184. ops->rotate = 0;
  185. }
  186. static void fbcon_rotate(struct fb_info *info, u32 rotate)
  187. {
  188. struct fbcon_ops *ops= info->fbcon_par;
  189. struct fb_info *fb_info;
  190. if (!ops || ops->currcon == -1)
  191. return;
  192. fb_info = registered_fb[con2fb_map[ops->currcon]];
  193. if (info == fb_info) {
  194. struct display *p = &fb_display[ops->currcon];
  195. if (rotate < 4)
  196. p->con_rotate = rotate;
  197. else
  198. p->con_rotate = 0;
  199. fbcon_modechanged(info);
  200. }
  201. }
  202. static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
  203. {
  204. struct fbcon_ops *ops = info->fbcon_par;
  205. struct vc_data *vc;
  206. struct display *p;
  207. int i;
  208. if (!ops || ops->currcon < 0 || rotate > 3)
  209. return;
  210. for (i = first_fb_vc; i <= last_fb_vc; i++) {
  211. vc = vc_cons[i].d;
  212. if (!vc || vc->vc_mode != KD_TEXT ||
  213. registered_fb[con2fb_map[i]] != info)
  214. continue;
  215. p = &fb_display[vc->vc_num];
  216. p->con_rotate = rotate;
  217. }
  218. fbcon_set_all_vcs(info);
  219. }
  220. #else
  221. static inline void fbcon_set_rotation(struct fb_info *info)
  222. {
  223. struct fbcon_ops *ops = info->fbcon_par;
  224. ops->rotate = FB_ROTATE_UR;
  225. }
  226. static void fbcon_rotate(struct fb_info *info, u32 rotate)
  227. {
  228. return;
  229. }
  230. static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
  231. {
  232. return;
  233. }
  234. #endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
  235. static int fbcon_get_rotate(struct fb_info *info)
  236. {
  237. struct fbcon_ops *ops = info->fbcon_par;
  238. return (ops) ? ops->rotate : 0;
  239. }
  240. static inline int fbcon_is_inactive(struct vc_data *vc, struct fb_info *info)
  241. {
  242. struct fbcon_ops *ops = info->fbcon_par;
  243. return (info->state != FBINFO_STATE_RUNNING ||
  244. vc->vc_mode != KD_TEXT || ops->graphics) &&
  245. !vt_force_oops_output(vc);
  246. }
  247. static int get_color(struct vc_data *vc, struct fb_info *info,
  248. u16 c, int is_fg)
  249. {
  250. int depth = fb_get_color_depth(&info->var, &info->fix);
  251. int color = 0;
  252. if (console_blanked) {
  253. unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
  254. c = vc->vc_video_erase_char & charmask;
  255. }
  256. if (depth != 1)
  257. color = (is_fg) ? attr_fgcol((vc->vc_hi_font_mask) ? 9 : 8, c)
  258. : attr_bgcol((vc->vc_hi_font_mask) ? 13 : 12, c);
  259. switch (depth) {
  260. case 1:
  261. {
  262. int col = mono_col(info);
  263. /* 0 or 1 */
  264. int fg = (info->fix.visual != FB_VISUAL_MONO01) ? col : 0;
  265. int bg = (info->fix.visual != FB_VISUAL_MONO01) ? 0 : col;
  266. if (console_blanked)
  267. fg = bg;
  268. color = (is_fg) ? fg : bg;
  269. break;
  270. }
  271. case 2:
  272. /*
  273. * Scale down 16-colors to 4 colors. Default 4-color palette
  274. * is grayscale. However, simply dividing the values by 4
  275. * will not work, as colors 1, 2 and 3 will be scaled-down
  276. * to zero rendering them invisible. So empirically convert
  277. * colors to a sane 4-level grayscale.
  278. */
  279. switch (color) {
  280. case 0:
  281. color = 0; /* black */
  282. break;
  283. case 1 ... 6:
  284. color = 2; /* white */
  285. break;
  286. case 7 ... 8:
  287. color = 1; /* gray */
  288. break;
  289. default:
  290. color = 3; /* intense white */
  291. break;
  292. }
  293. break;
  294. case 3:
  295. /*
  296. * Last 8 entries of default 16-color palette is a more intense
  297. * version of the first 8 (i.e., same chrominance, different
  298. * luminance).
  299. */
  300. color &= 7;
  301. break;
  302. }
  303. return color;
  304. }
  305. static void fbcon_update_softback(struct vc_data *vc)
  306. {
  307. int l = fbcon_softback_size / vc->vc_size_row;
  308. if (l > 5)
  309. softback_end = softback_buf + l * vc->vc_size_row;
  310. else
  311. /* Smaller scrollback makes no sense, and 0 would screw
  312. the operation totally */
  313. softback_top = 0;
  314. }
  315. static void fb_flashcursor(struct work_struct *work)
  316. {
  317. struct fb_info *info = container_of(work, struct fb_info, queue);
  318. struct fbcon_ops *ops = info->fbcon_par;
  319. struct vc_data *vc = NULL;
  320. int c;
  321. int mode;
  322. int ret;
  323. /* FIXME: we should sort out the unbind locking instead */
  324. /* instead we just fail to flash the cursor if we can't get
  325. * the lock instead of blocking fbcon deinit */
  326. ret = console_trylock();
  327. if (ret == 0)
  328. return;
  329. if (ops && ops->currcon != -1)
  330. vc = vc_cons[ops->currcon].d;
  331. if (!vc || !con_is_visible(vc) ||
  332. registered_fb[con2fb_map[vc->vc_num]] != info ||
  333. vc->vc_deccm != 1) {
  334. console_unlock();
  335. return;
  336. }
  337. c = scr_readw((u16 *) vc->vc_pos);
  338. mode = (!ops->cursor_flash || ops->cursor_state.enable) ?
  339. CM_ERASE : CM_DRAW;
  340. ops->cursor(vc, info, mode, softback_lines, get_color(vc, info, c, 1),
  341. get_color(vc, info, c, 0));
  342. console_unlock();
  343. }
  344. static void cursor_timer_handler(struct timer_list *t)
  345. {
  346. struct fbcon_ops *ops = from_timer(ops, t, cursor_timer);
  347. struct fb_info *info = ops->info;
  348. queue_work(system_power_efficient_wq, &info->queue);
  349. mod_timer(&ops->cursor_timer, jiffies + ops->cur_blink_jiffies);
  350. }
  351. static void fbcon_add_cursor_timer(struct fb_info *info)
  352. {
  353. struct fbcon_ops *ops = info->fbcon_par;
  354. if ((!info->queue.func || info->queue.func == fb_flashcursor) &&
  355. !(ops->flags & FBCON_FLAGS_CURSOR_TIMER) &&
  356. !fbcon_cursor_noblink) {
  357. if (!info->queue.func)
  358. INIT_WORK(&info->queue, fb_flashcursor);
  359. timer_setup(&ops->cursor_timer, cursor_timer_handler, 0);
  360. mod_timer(&ops->cursor_timer, jiffies + ops->cur_blink_jiffies);
  361. ops->flags |= FBCON_FLAGS_CURSOR_TIMER;
  362. }
  363. }
  364. static void fbcon_del_cursor_timer(struct fb_info *info)
  365. {
  366. struct fbcon_ops *ops = info->fbcon_par;
  367. if (info->queue.func == fb_flashcursor &&
  368. ops->flags & FBCON_FLAGS_CURSOR_TIMER) {
  369. del_timer_sync(&ops->cursor_timer);
  370. ops->flags &= ~FBCON_FLAGS_CURSOR_TIMER;
  371. }
  372. }
  373. #ifndef MODULE
  374. static int __init fb_console_setup(char *this_opt)
  375. {
  376. char *options;
  377. int i, j;
  378. if (!this_opt || !*this_opt)
  379. return 1;
  380. while ((options = strsep(&this_opt, ",")) != NULL) {
  381. if (!strncmp(options, "font:", 5)) {
  382. strlcpy(fontname, options + 5, sizeof(fontname));
  383. continue;
  384. }
  385. if (!strncmp(options, "scrollback:", 11)) {
  386. options += 11;
  387. if (*options) {
  388. fbcon_softback_size = simple_strtoul(options, &options, 0);
  389. if (*options == 'k' || *options == 'K') {
  390. fbcon_softback_size *= 1024;
  391. }
  392. }
  393. continue;
  394. }
  395. if (!strncmp(options, "map:", 4)) {
  396. options += 4;
  397. if (*options) {
  398. for (i = 0, j = 0; i < MAX_NR_CONSOLES; i++) {
  399. if (!options[j])
  400. j = 0;
  401. con2fb_map_boot[i] =
  402. (options[j++]-'0') % FB_MAX;
  403. }
  404. fbcon_map_override();
  405. }
  406. continue;
  407. }
  408. if (!strncmp(options, "vc:", 3)) {
  409. options += 3;
  410. if (*options)
  411. first_fb_vc = simple_strtoul(options, &options, 10) - 1;
  412. if (first_fb_vc < 0)
  413. first_fb_vc = 0;
  414. if (*options++ == '-')
  415. last_fb_vc = simple_strtoul(options, &options, 10) - 1;
  416. fbcon_is_default = 0;
  417. continue;
  418. }
  419. if (!strncmp(options, "rotate:", 7)) {
  420. options += 7;
  421. if (*options)
  422. initial_rotation = simple_strtoul(options, &options, 0);
  423. if (initial_rotation > 3)
  424. initial_rotation = 0;
  425. continue;
  426. }
  427. if (!strncmp(options, "margin:", 7)) {
  428. options += 7;
  429. if (*options)
  430. margin_color = simple_strtoul(options, &options, 0);
  431. continue;
  432. }
  433. #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
  434. if (!strcmp(options, "nodefer")) {
  435. deferred_takeover = false;
  436. continue;
  437. }
  438. #endif
  439. }
  440. return 1;
  441. }
  442. __setup("fbcon=", fb_console_setup);
  443. #endif
  444. static int search_fb_in_map(int idx)
  445. {
  446. int i, retval = 0;
  447. for (i = first_fb_vc; i <= last_fb_vc; i++) {
  448. if (con2fb_map[i] == idx)
  449. retval = 1;
  450. }
  451. return retval;
  452. }
  453. static int search_for_mapped_con(void)
  454. {
  455. int i, retval = 0;
  456. for (i = first_fb_vc; i <= last_fb_vc; i++) {
  457. if (con2fb_map[i] != -1)
  458. retval = 1;
  459. }
  460. return retval;
  461. }
  462. static int do_fbcon_takeover(int show_logo)
  463. {
  464. int err, i;
  465. if (!num_registered_fb)
  466. return -ENODEV;
  467. if (!show_logo)
  468. logo_shown = FBCON_LOGO_DONTSHOW;
  469. for (i = first_fb_vc; i <= last_fb_vc; i++)
  470. con2fb_map[i] = info_idx;
  471. err = do_take_over_console(&fb_con, first_fb_vc, last_fb_vc,
  472. fbcon_is_default);
  473. if (err) {
  474. for (i = first_fb_vc; i <= last_fb_vc; i++)
  475. con2fb_map[i] = -1;
  476. info_idx = -1;
  477. } else {
  478. fbcon_has_console_bind = 1;
  479. }
  480. return err;
  481. }
  482. #ifdef MODULE
  483. static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
  484. int cols, int rows, int new_cols, int new_rows)
  485. {
  486. logo_shown = FBCON_LOGO_DONTSHOW;
  487. }
  488. #else
  489. static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
  490. int cols, int rows, int new_cols, int new_rows)
  491. {
  492. /* Need to make room for the logo */
  493. struct fbcon_ops *ops = info->fbcon_par;
  494. int cnt, erase = vc->vc_video_erase_char, step;
  495. unsigned short *save = NULL, *r, *q;
  496. int logo_height;
  497. if (info->fbops->owner) {
  498. logo_shown = FBCON_LOGO_DONTSHOW;
  499. return;
  500. }
  501. /*
  502. * remove underline attribute from erase character
  503. * if black and white framebuffer.
  504. */
  505. if (fb_get_color_depth(&info->var, &info->fix) == 1)
  506. erase &= ~0x400;
  507. logo_height = fb_prepare_logo(info, ops->rotate);
  508. logo_lines = DIV_ROUND_UP(logo_height, vc->vc_font.height);
  509. q = (unsigned short *) (vc->vc_origin +
  510. vc->vc_size_row * rows);
  511. step = logo_lines * cols;
  512. for (r = q - logo_lines * cols; r < q; r++)
  513. if (scr_readw(r) != vc->vc_video_erase_char)
  514. break;
  515. if (r != q && new_rows >= rows + logo_lines) {
  516. save = kmalloc(array3_size(logo_lines, new_cols, 2),
  517. GFP_KERNEL);
  518. if (save) {
  519. int i = cols < new_cols ? cols : new_cols;
  520. scr_memsetw(save, erase, logo_lines * new_cols * 2);
  521. r = q - step;
  522. for (cnt = 0; cnt < logo_lines; cnt++, r += i)
  523. scr_memcpyw(save + cnt * new_cols, r, 2 * i);
  524. r = q;
  525. }
  526. }
  527. if (r == q) {
  528. /* We can scroll screen down */
  529. r = q - step - cols;
  530. for (cnt = rows - logo_lines; cnt > 0; cnt--) {
  531. scr_memcpyw(r + step, r, vc->vc_size_row);
  532. r -= cols;
  533. }
  534. if (!save) {
  535. int lines;
  536. if (vc->vc_y + logo_lines >= rows)
  537. lines = rows - vc->vc_y - 1;
  538. else
  539. lines = logo_lines;
  540. vc->vc_y += lines;
  541. vc->vc_pos += lines * vc->vc_size_row;
  542. }
  543. }
  544. scr_memsetw((unsigned short *) vc->vc_origin,
  545. erase,
  546. vc->vc_size_row * logo_lines);
  547. if (con_is_visible(vc) && vc->vc_mode == KD_TEXT) {
  548. fbcon_clear_margins(vc, 0);
  549. update_screen(vc);
  550. }
  551. if (save) {
  552. q = (unsigned short *) (vc->vc_origin +
  553. vc->vc_size_row *
  554. rows);
  555. scr_memcpyw(q, save, logo_lines * new_cols * 2);
  556. vc->vc_y += logo_lines;
  557. vc->vc_pos += logo_lines * vc->vc_size_row;
  558. kfree(save);
  559. }
  560. if (logo_lines > vc->vc_bottom) {
  561. logo_shown = FBCON_LOGO_CANSHOW;
  562. printk(KERN_INFO
  563. "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
  564. } else if (logo_shown != FBCON_LOGO_DONTSHOW) {
  565. logo_shown = FBCON_LOGO_DRAW;
  566. vc->vc_top = logo_lines;
  567. }
  568. }
  569. #endif /* MODULE */
  570. #ifdef CONFIG_FB_TILEBLITTING
  571. static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
  572. {
  573. struct fbcon_ops *ops = info->fbcon_par;
  574. ops->p = &fb_display[vc->vc_num];
  575. if ((info->flags & FBINFO_MISC_TILEBLITTING))
  576. fbcon_set_tileops(vc, info);
  577. else {
  578. fbcon_set_rotation(info);
  579. fbcon_set_bitops(ops);
  580. }
  581. }
  582. static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
  583. {
  584. int err = 0;
  585. if (info->flags & FBINFO_MISC_TILEBLITTING &&
  586. info->tileops->fb_get_tilemax(info) < charcount)
  587. err = 1;
  588. return err;
  589. }
  590. #else
  591. static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
  592. {
  593. struct fbcon_ops *ops = info->fbcon_par;
  594. info->flags &= ~FBINFO_MISC_TILEBLITTING;
  595. ops->p = &fb_display[vc->vc_num];
  596. fbcon_set_rotation(info);
  597. fbcon_set_bitops(ops);
  598. }
  599. static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
  600. {
  601. return 0;
  602. }
  603. #endif /* CONFIG_MISC_TILEBLITTING */
  604. static int con2fb_acquire_newinfo(struct vc_data *vc, struct fb_info *info,
  605. int unit, int oldidx)
  606. {
  607. struct fbcon_ops *ops = NULL;
  608. int err = 0;
  609. if (!try_module_get(info->fbops->owner))
  610. err = -ENODEV;
  611. if (!err && info->fbops->fb_open &&
  612. info->fbops->fb_open(info, 0))
  613. err = -ENODEV;
  614. if (!err) {
  615. ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
  616. if (!ops)
  617. err = -ENOMEM;
  618. }
  619. if (!err) {
  620. ops->cur_blink_jiffies = HZ / 5;
  621. ops->info = info;
  622. info->fbcon_par = ops;
  623. if (vc)
  624. set_blitting_type(vc, info);
  625. }
  626. if (err) {
  627. con2fb_map[unit] = oldidx;
  628. module_put(info->fbops->owner);
  629. }
  630. return err;
  631. }
  632. static int con2fb_release_oldinfo(struct vc_data *vc, struct fb_info *oldinfo,
  633. struct fb_info *newinfo, int unit,
  634. int oldidx, int found)
  635. {
  636. struct fbcon_ops *ops = oldinfo->fbcon_par;
  637. int err = 0, ret;
  638. if (oldinfo->fbops->fb_release &&
  639. oldinfo->fbops->fb_release(oldinfo, 0)) {
  640. con2fb_map[unit] = oldidx;
  641. if (!found && newinfo->fbops->fb_release)
  642. newinfo->fbops->fb_release(newinfo, 0);
  643. if (!found)
  644. module_put(newinfo->fbops->owner);
  645. err = -ENODEV;
  646. }
  647. if (!err) {
  648. fbcon_del_cursor_timer(oldinfo);
  649. kfree(ops->cursor_state.mask);
  650. kfree(ops->cursor_data);
  651. kfree(ops->cursor_src);
  652. kfree(ops->fontbuffer);
  653. kfree(oldinfo->fbcon_par);
  654. oldinfo->fbcon_par = NULL;
  655. module_put(oldinfo->fbops->owner);
  656. /*
  657. If oldinfo and newinfo are driving the same hardware,
  658. the fb_release() method of oldinfo may attempt to
  659. restore the hardware state. This will leave the
  660. newinfo in an undefined state. Thus, a call to
  661. fb_set_par() may be needed for the newinfo.
  662. */
  663. if (newinfo && newinfo->fbops->fb_set_par) {
  664. ret = newinfo->fbops->fb_set_par(newinfo);
  665. if (ret)
  666. printk(KERN_ERR "con2fb_release_oldinfo: "
  667. "detected unhandled fb_set_par error, "
  668. "error code %d\n", ret);
  669. }
  670. }
  671. return err;
  672. }
  673. static void con2fb_init_display(struct vc_data *vc, struct fb_info *info,
  674. int unit, int show_logo)
  675. {
  676. struct fbcon_ops *ops = info->fbcon_par;
  677. int ret;
  678. ops->currcon = fg_console;
  679. if (info->fbops->fb_set_par && !(ops->flags & FBCON_FLAGS_INIT)) {
  680. ret = info->fbops->fb_set_par(info);
  681. if (ret)
  682. printk(KERN_ERR "con2fb_init_display: detected "
  683. "unhandled fb_set_par error, "
  684. "error code %d\n", ret);
  685. }
  686. ops->flags |= FBCON_FLAGS_INIT;
  687. ops->graphics = 0;
  688. fbcon_set_disp(info, &info->var, unit);
  689. if (show_logo) {
  690. struct vc_data *fg_vc = vc_cons[fg_console].d;
  691. struct fb_info *fg_info =
  692. registered_fb[con2fb_map[fg_console]];
  693. fbcon_prepare_logo(fg_vc, fg_info, fg_vc->vc_cols,
  694. fg_vc->vc_rows, fg_vc->vc_cols,
  695. fg_vc->vc_rows);
  696. }
  697. update_screen(vc_cons[fg_console].d);
  698. }
  699. /**
  700. * set_con2fb_map - map console to frame buffer device
  701. * @unit: virtual console number to map
  702. * @newidx: frame buffer index to map virtual console to
  703. * @user: user request
  704. *
  705. * Maps a virtual console @unit to a frame buffer device
  706. * @newidx.
  707. *
  708. * This should be called with the console lock held.
  709. */
  710. static int set_con2fb_map(int unit, int newidx, int user)
  711. {
  712. struct vc_data *vc = vc_cons[unit].d;
  713. int oldidx = con2fb_map[unit];
  714. struct fb_info *info = registered_fb[newidx];
  715. struct fb_info *oldinfo = NULL;
  716. int found, err = 0;
  717. WARN_CONSOLE_UNLOCKED();
  718. if (oldidx == newidx)
  719. return 0;
  720. if (!info)
  721. return -EINVAL;
  722. if (!search_for_mapped_con() || !con_is_bound(&fb_con)) {
  723. info_idx = newidx;
  724. return do_fbcon_takeover(0);
  725. }
  726. if (oldidx != -1)
  727. oldinfo = registered_fb[oldidx];
  728. found = search_fb_in_map(newidx);
  729. con2fb_map[unit] = newidx;
  730. if (!err && !found)
  731. err = con2fb_acquire_newinfo(vc, info, unit, oldidx);
  732. /*
  733. * If old fb is not mapped to any of the consoles,
  734. * fbcon should release it.
  735. */
  736. if (!err && oldinfo && !search_fb_in_map(oldidx))
  737. err = con2fb_release_oldinfo(vc, oldinfo, info, unit, oldidx,
  738. found);
  739. if (!err) {
  740. int show_logo = (fg_console == 0 && !user &&
  741. logo_shown != FBCON_LOGO_DONTSHOW);
  742. if (!found)
  743. fbcon_add_cursor_timer(info);
  744. con2fb_map_boot[unit] = newidx;
  745. con2fb_init_display(vc, info, unit, show_logo);
  746. }
  747. if (!search_fb_in_map(info_idx))
  748. info_idx = newidx;
  749. return err;
  750. }
  751. /*
  752. * Low Level Operations
  753. */
  754. /* NOTE: fbcon cannot be __init: it may be called from do_take_over_console later */
  755. static int var_to_display(struct display *disp,
  756. struct fb_var_screeninfo *var,
  757. struct fb_info *info)
  758. {
  759. disp->xres_virtual = var->xres_virtual;
  760. disp->yres_virtual = var->yres_virtual;
  761. disp->bits_per_pixel = var->bits_per_pixel;
  762. disp->grayscale = var->grayscale;
  763. disp->nonstd = var->nonstd;
  764. disp->accel_flags = var->accel_flags;
  765. disp->height = var->height;
  766. disp->width = var->width;
  767. disp->red = var->red;
  768. disp->green = var->green;
  769. disp->blue = var->blue;
  770. disp->transp = var->transp;
  771. disp->rotate = var->rotate;
  772. disp->mode = fb_match_mode(var, &info->modelist);
  773. if (disp->mode == NULL)
  774. /* This should not happen */
  775. return -EINVAL;
  776. return 0;
  777. }
  778. static void display_to_var(struct fb_var_screeninfo *var,
  779. struct display *disp)
  780. {
  781. fb_videomode_to_var(var, disp->mode);
  782. var->xres_virtual = disp->xres_virtual;
  783. var->yres_virtual = disp->yres_virtual;
  784. var->bits_per_pixel = disp->bits_per_pixel;
  785. var->grayscale = disp->grayscale;
  786. var->nonstd = disp->nonstd;
  787. var->accel_flags = disp->accel_flags;
  788. var->height = disp->height;
  789. var->width = disp->width;
  790. var->red = disp->red;
  791. var->green = disp->green;
  792. var->blue = disp->blue;
  793. var->transp = disp->transp;
  794. var->rotate = disp->rotate;
  795. }
  796. static const char *fbcon_startup(void)
  797. {
  798. const char *display_desc = "frame buffer device";
  799. struct display *p = &fb_display[fg_console];
  800. struct vc_data *vc = vc_cons[fg_console].d;
  801. const struct font_desc *font = NULL;
  802. struct module *owner;
  803. struct fb_info *info = NULL;
  804. struct fbcon_ops *ops;
  805. int rows, cols;
  806. /*
  807. * If num_registered_fb is zero, this is a call for the dummy part.
  808. * The frame buffer devices weren't initialized yet.
  809. */
  810. if (!num_registered_fb || info_idx == -1)
  811. return display_desc;
  812. /*
  813. * Instead of blindly using registered_fb[0], we use info_idx, set by
  814. * fb_console_init();
  815. */
  816. info = registered_fb[info_idx];
  817. if (!info)
  818. return NULL;
  819. owner = info->fbops->owner;
  820. if (!try_module_get(owner))
  821. return NULL;
  822. if (info->fbops->fb_open && info->fbops->fb_open(info, 0)) {
  823. module_put(owner);
  824. return NULL;
  825. }
  826. ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
  827. if (!ops) {
  828. module_put(owner);
  829. return NULL;
  830. }
  831. ops->currcon = -1;
  832. ops->graphics = 1;
  833. ops->cur_rotate = -1;
  834. ops->cur_blink_jiffies = HZ / 5;
  835. ops->info = info;
  836. info->fbcon_par = ops;
  837. p->con_rotate = initial_rotation;
  838. if (p->con_rotate == -1)
  839. p->con_rotate = info->fbcon_rotate_hint;
  840. if (p->con_rotate == -1)
  841. p->con_rotate = FB_ROTATE_UR;
  842. set_blitting_type(vc, info);
  843. if (info->fix.type != FB_TYPE_TEXT) {
  844. if (fbcon_softback_size) {
  845. if (!softback_buf) {
  846. softback_buf =
  847. (unsigned long)
  848. kmalloc(fbcon_softback_size,
  849. GFP_KERNEL);
  850. if (!softback_buf) {
  851. fbcon_softback_size = 0;
  852. softback_top = 0;
  853. }
  854. }
  855. } else {
  856. if (softback_buf) {
  857. kfree((void *) softback_buf);
  858. softback_buf = 0;
  859. softback_top = 0;
  860. }
  861. }
  862. if (softback_buf)
  863. softback_in = softback_top = softback_curr =
  864. softback_buf;
  865. softback_lines = 0;
  866. }
  867. /* Setup default font */
  868. if (!p->fontdata && !vc->vc_font.data) {
  869. if (!fontname[0] || !(font = find_font(fontname)))
  870. font = get_default_font(info->var.xres,
  871. info->var.yres,
  872. info->pixmap.blit_x,
  873. info->pixmap.blit_y);
  874. vc->vc_font.width = font->width;
  875. vc->vc_font.height = font->height;
  876. vc->vc_font.data = (void *)(p->fontdata = font->data);
  877. vc->vc_font.charcount = 256; /* FIXME Need to support more fonts */
  878. } else {
  879. p->fontdata = vc->vc_font.data;
  880. }
  881. cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
  882. rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
  883. cols /= vc->vc_font.width;
  884. rows /= vc->vc_font.height;
  885. vc_resize(vc, cols, rows);
  886. DPRINTK("mode: %s\n", info->fix.id);
  887. DPRINTK("visual: %d\n", info->fix.visual);
  888. DPRINTK("res: %dx%d-%d\n", info->var.xres,
  889. info->var.yres,
  890. info->var.bits_per_pixel);
  891. fbcon_add_cursor_timer(info);
  892. fbcon_has_exited = 0;
  893. return display_desc;
  894. }
  895. static void fbcon_init(struct vc_data *vc, int init)
  896. {
  897. struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
  898. struct fbcon_ops *ops;
  899. struct vc_data **default_mode = vc->vc_display_fg;
  900. struct vc_data *svc = *default_mode;
  901. struct display *t, *p = &fb_display[vc->vc_num];
  902. int logo = 1, new_rows, new_cols, rows, cols, charcnt = 256;
  903. int cap, ret;
  904. if (info_idx == -1 || info == NULL)
  905. return;
  906. cap = info->flags;
  907. if (vc != svc || logo_shown == FBCON_LOGO_DONTSHOW ||
  908. (info->fix.type == FB_TYPE_TEXT))
  909. logo = 0;
  910. if (var_to_display(p, &info->var, info))
  911. return;
  912. if (!info->fbcon_par)
  913. con2fb_acquire_newinfo(vc, info, vc->vc_num, -1);
  914. /* If we are not the first console on this
  915. fb, copy the font from that console */
  916. t = &fb_display[fg_console];
  917. if (!p->fontdata) {
  918. if (t->fontdata) {
  919. struct vc_data *fvc = vc_cons[fg_console].d;
  920. vc->vc_font.data = (void *)(p->fontdata =
  921. fvc->vc_font.data);
  922. vc->vc_font.width = fvc->vc_font.width;
  923. vc->vc_font.height = fvc->vc_font.height;
  924. p->userfont = t->userfont;
  925. if (p->userfont)
  926. REFCOUNT(p->fontdata)++;
  927. } else {
  928. const struct font_desc *font = NULL;
  929. if (!fontname[0] || !(font = find_font(fontname)))
  930. font = get_default_font(info->var.xres,
  931. info->var.yres,
  932. info->pixmap.blit_x,
  933. info->pixmap.blit_y);
  934. vc->vc_font.width = font->width;
  935. vc->vc_font.height = font->height;
  936. vc->vc_font.data = (void *)(p->fontdata = font->data);
  937. vc->vc_font.charcount = 256; /* FIXME Need to
  938. support more fonts */
  939. }
  940. }
  941. if (p->userfont)
  942. charcnt = FNTCHARCNT(p->fontdata);
  943. vc->vc_panic_force_write = !!(info->flags & FBINFO_CAN_FORCE_OUTPUT);
  944. vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
  945. vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
  946. if (charcnt == 256) {
  947. vc->vc_hi_font_mask = 0;
  948. } else {
  949. vc->vc_hi_font_mask = 0x100;
  950. if (vc->vc_can_do_color)
  951. vc->vc_complement_mask <<= 1;
  952. }
  953. if (!*svc->vc_uni_pagedir_loc)
  954. con_set_default_unimap(svc);
  955. if (!*vc->vc_uni_pagedir_loc)
  956. con_copy_unimap(vc, svc);
  957. ops = info->fbcon_par;
  958. ops->cur_blink_jiffies = msecs_to_jiffies(vc->vc_cur_blink_ms);
  959. p->con_rotate = initial_rotation;
  960. if (p->con_rotate == -1)
  961. p->con_rotate = info->fbcon_rotate_hint;
  962. if (p->con_rotate == -1)
  963. p->con_rotate = FB_ROTATE_UR;
  964. set_blitting_type(vc, info);
  965. cols = vc->vc_cols;
  966. rows = vc->vc_rows;
  967. new_cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
  968. new_rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
  969. new_cols /= vc->vc_font.width;
  970. new_rows /= vc->vc_font.height;
  971. /*
  972. * We must always set the mode. The mode of the previous console
  973. * driver could be in the same resolution but we are using different
  974. * hardware so we have to initialize the hardware.
  975. *
  976. * We need to do it in fbcon_init() to prevent screen corruption.
  977. */
  978. if (con_is_visible(vc) && vc->vc_mode == KD_TEXT) {
  979. if (info->fbops->fb_set_par &&
  980. !(ops->flags & FBCON_FLAGS_INIT)) {
  981. ret = info->fbops->fb_set_par(info);
  982. if (ret)
  983. printk(KERN_ERR "fbcon_init: detected "
  984. "unhandled fb_set_par error, "
  985. "error code %d\n", ret);
  986. }
  987. ops->flags |= FBCON_FLAGS_INIT;
  988. }
  989. ops->graphics = 0;
  990. if ((cap & FBINFO_HWACCEL_COPYAREA) &&
  991. !(cap & FBINFO_HWACCEL_DISABLED))
  992. p->scrollmode = SCROLL_MOVE;
  993. else /* default to something safe */
  994. p->scrollmode = SCROLL_REDRAW;
  995. /*
  996. * ++guenther: console.c:vc_allocate() relies on initializing
  997. * vc_{cols,rows}, but we must not set those if we are only
  998. * resizing the console.
  999. */
  1000. if (init) {
  1001. vc->vc_cols = new_cols;
  1002. vc->vc_rows = new_rows;
  1003. } else
  1004. vc_resize(vc, new_cols, new_rows);
  1005. if (logo)
  1006. fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows);
  1007. if (vc == svc && softback_buf)
  1008. fbcon_update_softback(vc);
  1009. if (ops->rotate_font && ops->rotate_font(info, vc)) {
  1010. ops->rotate = FB_ROTATE_UR;
  1011. set_blitting_type(vc, info);
  1012. }
  1013. ops->p = &fb_display[fg_console];
  1014. }
  1015. static void fbcon_free_font(struct display *p, bool freefont)
  1016. {
  1017. if (freefont && p->userfont && p->fontdata && (--REFCOUNT(p->fontdata) == 0))
  1018. kfree(p->fontdata - FONT_EXTRA_WORDS * sizeof(int));
  1019. p->fontdata = NULL;
  1020. p->userfont = 0;
  1021. }
  1022. static void set_vc_hi_font(struct vc_data *vc, bool set);
  1023. static void fbcon_deinit(struct vc_data *vc)
  1024. {
  1025. struct display *p = &fb_display[vc->vc_num];
  1026. struct fb_info *info;
  1027. struct fbcon_ops *ops;
  1028. int idx;
  1029. bool free_font = true;
  1030. idx = con2fb_map[vc->vc_num];
  1031. if (idx == -1)
  1032. goto finished;
  1033. info = registered_fb[idx];
  1034. if (!info)
  1035. goto finished;
  1036. if (info->flags & FBINFO_MISC_FIRMWARE)
  1037. free_font = false;
  1038. ops = info->fbcon_par;
  1039. if (!ops)
  1040. goto finished;
  1041. if (con_is_visible(vc))
  1042. fbcon_del_cursor_timer(info);
  1043. ops->flags &= ~FBCON_FLAGS_INIT;
  1044. finished:
  1045. fbcon_free_font(p, free_font);
  1046. if (free_font)
  1047. vc->vc_font.data = NULL;
  1048. if (vc->vc_hi_font_mask)
  1049. set_vc_hi_font(vc, false);
  1050. if (!con_is_bound(&fb_con))
  1051. fbcon_exit();
  1052. return;
  1053. }
  1054. /* ====================================================================== */
  1055. /* fbcon_XXX routines - interface used by the world
  1056. *
  1057. * This system is now divided into two levels because of complications
  1058. * caused by hardware scrolling. Top level functions:
  1059. *
  1060. * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
  1061. *
  1062. * handles y values in range [0, scr_height-1] that correspond to real
  1063. * screen positions. y_wrap shift means that first line of bitmap may be
  1064. * anywhere on this display. These functions convert lineoffsets to
  1065. * bitmap offsets and deal with the wrap-around case by splitting blits.
  1066. *
  1067. * fbcon_bmove_physical_8() -- These functions fast implementations
  1068. * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
  1069. * fbcon_putc_physical_8() -- (font width != 8) may be added later
  1070. *
  1071. * WARNING:
  1072. *
  1073. * At the moment fbcon_putc() cannot blit across vertical wrap boundary
  1074. * Implies should only really hardware scroll in rows. Only reason for
  1075. * restriction is simplicity & efficiency at the moment.
  1076. */
  1077. static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
  1078. int width)
  1079. {
  1080. struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
  1081. struct fbcon_ops *ops = info->fbcon_par;
  1082. struct display *p = &fb_display[vc->vc_num];
  1083. u_int y_break;
  1084. if (fbcon_is_inactive(vc, info))
  1085. return;
  1086. if (!height || !width)
  1087. return;
  1088. if (sy < vc->vc_top && vc->vc_top == logo_lines) {
  1089. vc->vc_top = 0;
  1090. /*
  1091. * If the font dimensions are not an integral of the display
  1092. * dimensions then the ops->clear below won't end up clearing
  1093. * the margins. Call clear_margins here in case the logo
  1094. * bitmap stretched into the margin area.
  1095. */
  1096. fbcon_clear_margins(vc, 0);
  1097. }
  1098. /* Split blits that cross physical y_wrap boundary */
  1099. y_break = p->vrows - p->yscroll;
  1100. if (sy < y_break && sy + height - 1 >= y_break) {
  1101. u_int b = y_break - sy;
  1102. ops->clear(vc, info, real_y(p, sy), sx, b, width);
  1103. ops->clear(vc, info, real_y(p, sy + b), sx, height - b,
  1104. width);
  1105. } else
  1106. ops->clear(vc, info, real_y(p, sy), sx, height, width);
  1107. }
  1108. static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
  1109. int count, int ypos, int xpos)
  1110. {
  1111. struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
  1112. struct display *p = &fb_display[vc->vc_num];
  1113. struct fbcon_ops *ops = info->fbcon_par;
  1114. if (!fbcon_is_inactive(vc, info))
  1115. ops->putcs(vc, info, s, count, real_y(p, ypos), xpos,
  1116. get_color(vc, info, scr_readw(s), 1),
  1117. get_color(vc, info, scr_readw(s), 0));
  1118. }
  1119. static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos)
  1120. {
  1121. unsigned short chr;
  1122. scr_writew(c, &chr);
  1123. fbcon_putcs(vc, &chr, 1, ypos, xpos);
  1124. }
  1125. static void fbcon_clear_margins(struct vc_data *vc, int bottom_only)
  1126. {
  1127. struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
  1128. struct fbcon_ops *ops = info->fbcon_par;
  1129. if (!fbcon_is_inactive(vc, info))
  1130. ops->clear_margins(vc, info, margin_color, bottom_only);
  1131. }
  1132. static void fbcon_cursor(struct vc_data *vc, int mode)
  1133. {
  1134. struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
  1135. struct fbcon_ops *ops = info->fbcon_par;
  1136. int y;
  1137. int c = scr_readw((u16 *) vc->vc_pos);
  1138. ops->cur_blink_jiffies = msecs_to_jiffies(vc->vc_cur_blink_ms);
  1139. if (fbcon_is_inactive(vc, info) || vc->vc_deccm != 1)
  1140. return;
  1141. if (vc->vc_cursor_type & 0x10)
  1142. fbcon_del_cursor_timer(info);
  1143. else
  1144. fbcon_add_cursor_timer(info);
  1145. ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1;
  1146. if (mode & CM_SOFTBACK) {
  1147. mode &= ~CM_SOFTBACK;
  1148. y = softback_lines;
  1149. } else {
  1150. if (softback_lines)
  1151. fbcon_set_origin(vc);
  1152. y = 0;
  1153. }
  1154. ops->cursor(vc, info, mode, y, get_color(vc, info, c, 1),
  1155. get_color(vc, info, c, 0));
  1156. }
  1157. static int scrollback_phys_max = 0;
  1158. static int scrollback_max = 0;
  1159. static int scrollback_current = 0;
  1160. static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
  1161. int unit)
  1162. {
  1163. struct display *p, *t;
  1164. struct vc_data **default_mode, *vc;
  1165. struct vc_data *svc;
  1166. struct fbcon_ops *ops = info->fbcon_par;
  1167. int rows, cols, charcnt = 256;
  1168. p = &fb_display[unit];
  1169. if (var_to_display(p, var, info))
  1170. return;
  1171. vc = vc_cons[unit].d;
  1172. if (!vc)
  1173. return;
  1174. default_mode = vc->vc_display_fg;
  1175. svc = *default_mode;
  1176. t = &fb_display[svc->vc_num];
  1177. if (!vc->vc_font.data) {
  1178. vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
  1179. vc->vc_font.width = (*default_mode)->vc_font.width;
  1180. vc->vc_font.height = (*default_mode)->vc_font.height;
  1181. p->userfont = t->userfont;
  1182. if (p->userfont)
  1183. REFCOUNT(p->fontdata)++;
  1184. }
  1185. if (p->userfont)
  1186. charcnt = FNTCHARCNT(p->fontdata);
  1187. var->activate = FB_ACTIVATE_NOW;
  1188. info->var.activate = var->activate;
  1189. var->yoffset = info->var.yoffset;
  1190. var->xoffset = info->var.xoffset;
  1191. fb_set_var(info, var);
  1192. ops->var = info->var;
  1193. vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
  1194. vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
  1195. if (charcnt == 256) {
  1196. vc->vc_hi_font_mask = 0;
  1197. } else {
  1198. vc->vc_hi_font_mask = 0x100;
  1199. if (vc->vc_can_do_color)
  1200. vc->vc_complement_mask <<= 1;
  1201. }
  1202. if (!*svc->vc_uni_pagedir_loc)
  1203. con_set_default_unimap(svc);
  1204. if (!*vc->vc_uni_pagedir_loc)
  1205. con_copy_unimap(vc, svc);
  1206. cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
  1207. rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
  1208. cols /= vc->vc_font.width;
  1209. rows /= vc->vc_font.height;
  1210. vc_resize(vc, cols, rows);
  1211. if (con_is_visible(vc)) {
  1212. update_screen(vc);
  1213. if (softback_buf)
  1214. fbcon_update_softback(vc);
  1215. }
  1216. }
  1217. static __inline__ void ywrap_up(struct vc_data *vc, int count)
  1218. {
  1219. struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
  1220. struct fbcon_ops *ops = info->fbcon_par;
  1221. struct display *p = &fb_display[vc->vc_num];
  1222. p->yscroll += count;
  1223. if (p->yscroll >= p->vrows) /* Deal with wrap */
  1224. p->yscroll -= p->vrows;
  1225. ops->var.xoffset = 0;
  1226. ops->var.yoffset = p->yscroll * vc->vc_font.height;
  1227. ops->var.vmode |= FB_VMODE_YWRAP;
  1228. ops->update_start(info);
  1229. scrollback_max += count;
  1230. if (scrollback_max > scrollback_phys_max)
  1231. scrollback_max = scrollback_phys_max;
  1232. scrollback_current = 0;
  1233. }
  1234. static __inline__ void ywrap_down(struct vc_data *vc, int count)
  1235. {
  1236. struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
  1237. struct fbcon_ops *ops = info->fbcon_par;
  1238. struct display *p = &fb_display[vc->vc_num];
  1239. p->yscroll -= count;
  1240. if (p->yscroll < 0) /* Deal with wrap */
  1241. p->yscroll += p->vrows;
  1242. ops->var.xoffset = 0;
  1243. ops->var.yoffset = p->yscroll * vc->vc_font.height;
  1244. ops->var.vmode |= FB_VMODE_YWRAP;
  1245. ops->update_start(info);
  1246. scrollback_max -= count;
  1247. if (scrollback_max < 0)
  1248. scrollback_max = 0;
  1249. scrollback_current = 0;
  1250. }
  1251. static __inline__ void ypan_up(struct vc_data *vc, int count)
  1252. {
  1253. struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
  1254. struct display *p = &fb_display[vc->vc_num];
  1255. struct fbcon_ops *ops = info->fbcon_par;
  1256. p->yscroll += count;
  1257. if (p->yscroll > p->vrows - vc->vc_rows) {
  1258. ops->bmove(vc, info, p->vrows - vc->vc_rows,
  1259. 0, 0, 0, vc->vc_rows, vc->vc_cols);
  1260. p->yscroll -= p->vrows - vc->vc_rows;
  1261. }
  1262. ops->var.xoffset = 0;
  1263. ops->var.yoffset = p->yscroll * vc->vc_font.height;
  1264. ops->var.vmode &= ~FB_VMODE_YWRAP;
  1265. ops->update_start(info);
  1266. fbcon_clear_margins(vc, 1);
  1267. scrollback_max += count;
  1268. if (scrollback_max > scrollback_phys_max)
  1269. scrollback_max = scrollback_phys_max;
  1270. scrollback_current = 0;
  1271. }
  1272. static __inline__ void ypan_up_redraw(struct vc_data *vc, int t, int count)
  1273. {
  1274. struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
  1275. struct fbcon_ops *ops = info->fbcon_par;
  1276. struct display *p = &fb_display[vc->vc_num];
  1277. p->yscroll += count;
  1278. if (p->yscroll > p->vrows - vc->vc_rows) {
  1279. p->yscroll -= p->vrows - vc->vc_rows;
  1280. fbcon_redraw_move(vc, p, t + count, vc->vc_rows - count, t);
  1281. }
  1282. ops->var.xoffset = 0;
  1283. ops->var.yoffset = p->yscroll * vc->vc_font.height;
  1284. ops->var.vmode &= ~FB_VMODE_YWRAP;
  1285. ops->update_start(info);
  1286. fbcon_clear_margins(vc, 1);
  1287. scrollback_max += count;
  1288. if (scrollback_max > scrollback_phys_max)
  1289. scrollback_max = scrollback_phys_max;
  1290. scrollback_current = 0;
  1291. }
  1292. static __inline__ void ypan_down(struct vc_data *vc, int count)
  1293. {
  1294. struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
  1295. struct display *p = &fb_display[vc->vc_num];
  1296. struct fbcon_ops *ops = info->fbcon_par;
  1297. p->yscroll -= count;
  1298. if (p->yscroll < 0) {
  1299. ops->bmove(vc, info, 0, 0, p->vrows - vc->vc_rows,
  1300. 0, vc->vc_rows, vc->vc_cols);
  1301. p->yscroll += p->vrows - vc->vc_rows;
  1302. }
  1303. ops->var.xoffset = 0;
  1304. ops->var.yoffset = p->yscroll * vc->vc_font.height;
  1305. ops->var.vmode &= ~FB_VMODE_YWRAP;
  1306. ops->update_start(info);
  1307. fbcon_clear_margins(vc, 1);
  1308. scrollback_max -= count;
  1309. if (scrollback_max < 0)
  1310. scrollback_max = 0;
  1311. scrollback_current = 0;
  1312. }
  1313. static __inline__ void ypan_down_redraw(struct vc_data *vc, int t, int count)
  1314. {
  1315. struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
  1316. struct fbcon_ops *ops = info->fbcon_par;
  1317. struct display *p = &fb_display[vc->vc_num];
  1318. p->yscroll -= count;
  1319. if (p->yscroll < 0) {
  1320. p->yscroll += p->vrows - vc->vc_rows;
  1321. fbcon_redraw_move(vc, p, t, vc->vc_rows - count, t + count);
  1322. }
  1323. ops->var.xoffset = 0;
  1324. ops->var.yoffset = p->yscroll * vc->vc_font.height;
  1325. ops->var.vmode &= ~FB_VMODE_YWRAP;
  1326. ops->update_start(info);
  1327. fbcon_clear_margins(vc, 1);
  1328. scrollback_max -= count;
  1329. if (scrollback_max < 0)
  1330. scrollback_max = 0;
  1331. scrollback_current = 0;
  1332. }
  1333. static void fbcon_redraw_softback(struct vc_data *vc, struct display *p,
  1334. long delta)
  1335. {
  1336. int count = vc->vc_rows;
  1337. unsigned short *d, *s;
  1338. unsigned long n;
  1339. int line = 0;
  1340. d = (u16 *) softback_curr;
  1341. if (d == (u16 *) softback_in)
  1342. d = (u16 *) vc->vc_origin;
  1343. n = softback_curr + delta * vc->vc_size_row;
  1344. softback_lines -= delta;
  1345. if (delta < 0) {
  1346. if (softback_curr < softback_top && n < softback_buf) {
  1347. n += softback_end - softback_buf;
  1348. if (n < softback_top) {
  1349. softback_lines -=
  1350. (softback_top - n) / vc->vc_size_row;
  1351. n = softback_top;
  1352. }
  1353. } else if (softback_curr >= softback_top
  1354. && n < softback_top) {
  1355. softback_lines -=
  1356. (softback_top - n) / vc->vc_size_row;
  1357. n = softback_top;
  1358. }
  1359. } else {
  1360. if (softback_curr > softback_in && n >= softback_end) {
  1361. n += softback_buf - softback_end;
  1362. if (n > softback_in) {
  1363. n = softback_in;
  1364. softback_lines = 0;
  1365. }
  1366. } else if (softback_curr <= softback_in && n > softback_in) {
  1367. n = softback_in;
  1368. softback_lines = 0;
  1369. }
  1370. }
  1371. if (n == softback_curr)
  1372. return;
  1373. softback_curr = n;
  1374. s = (u16 *) softback_curr;
  1375. if (s == (u16 *) softback_in)
  1376. s = (u16 *) vc->vc_origin;
  1377. while (count--) {
  1378. unsigned short *start;
  1379. unsigned short *le;
  1380. unsigned short c;
  1381. int x = 0;
  1382. unsigned short attr = 1;
  1383. start = s;
  1384. le = advance_row(s, 1);
  1385. do {
  1386. c = scr_readw(s);
  1387. if (attr != (c & 0xff00)) {
  1388. attr = c & 0xff00;
  1389. if (s > start) {
  1390. fbcon_putcs(vc, start, s - start,
  1391. line, x);
  1392. x += s - start;
  1393. start = s;
  1394. }
  1395. }
  1396. if (c == scr_readw(d)) {
  1397. if (s > start) {
  1398. fbcon_putcs(vc, start, s - start,
  1399. line, x);
  1400. x += s - start + 1;
  1401. start = s + 1;
  1402. } else {
  1403. x++;
  1404. start++;
  1405. }
  1406. }
  1407. s++;
  1408. d++;
  1409. } while (s < le);
  1410. if (s > start)
  1411. fbcon_putcs(vc, start, s - start, line, x);
  1412. line++;
  1413. if (d == (u16 *) softback_end)
  1414. d = (u16 *) softback_buf;
  1415. if (d == (u16 *) softback_in)
  1416. d = (u16 *) vc->vc_origin;
  1417. if (s == (u16 *) softback_end)
  1418. s = (u16 *) softback_buf;
  1419. if (s == (u16 *) softback_in)
  1420. s = (u16 *) vc->vc_origin;
  1421. }
  1422. }
  1423. static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
  1424. int line, int count, int dy)
  1425. {
  1426. unsigned short *s = (unsigned short *)
  1427. (vc->vc_origin + vc->vc_size_row * line);
  1428. while (count--) {
  1429. unsigned short *start = s;
  1430. unsigned short *le = advance_row(s, 1);
  1431. unsigned short c;
  1432. int x = 0;
  1433. unsigned short attr = 1;
  1434. do {
  1435. c = scr_readw(s);
  1436. if (attr != (c & 0xff00)) {
  1437. attr = c & 0xff00;
  1438. if (s > start) {
  1439. fbcon_putcs(vc, start, s - start,
  1440. dy, x);
  1441. x += s - start;
  1442. start = s;
  1443. }
  1444. }
  1445. console_conditional_schedule();
  1446. s++;
  1447. } while (s < le);
  1448. if (s > start)
  1449. fbcon_putcs(vc, start, s - start, dy, x);
  1450. console_conditional_schedule();
  1451. dy++;
  1452. }
  1453. }
  1454. static void fbcon_redraw_blit(struct vc_data *vc, struct fb_info *info,
  1455. struct display *p, int line, int count, int ycount)
  1456. {
  1457. int offset = ycount * vc->vc_cols;
  1458. unsigned short *d = (unsigned short *)
  1459. (vc->vc_origin + vc->vc_size_row * line);
  1460. unsigned short *s = d + offset;
  1461. struct fbcon_ops *ops = info->fbcon_par;
  1462. while (count--) {
  1463. unsigned short *start = s;
  1464. unsigned short *le = advance_row(s, 1);
  1465. unsigned short c;
  1466. int x = 0;
  1467. do {
  1468. c = scr_readw(s);
  1469. if (c == scr_readw(d)) {
  1470. if (s > start) {
  1471. ops->bmove(vc, info, line + ycount, x,
  1472. line, x, 1, s-start);
  1473. x += s - start + 1;
  1474. start = s + 1;
  1475. } else {
  1476. x++;
  1477. start++;
  1478. }
  1479. }
  1480. scr_writew(c, d);
  1481. console_conditional_schedule();
  1482. s++;
  1483. d++;
  1484. } while (s < le);
  1485. if (s > start)
  1486. ops->bmove(vc, info, line + ycount, x, line, x, 1,
  1487. s-start);
  1488. console_conditional_schedule();
  1489. if (ycount > 0)
  1490. line++;
  1491. else {
  1492. line--;
  1493. /* NOTE: We subtract two lines from these pointers */
  1494. s -= vc->vc_size_row;
  1495. d -= vc->vc_size_row;
  1496. }
  1497. }
  1498. }
  1499. static void fbcon_redraw(struct vc_data *vc, struct display *p,
  1500. int line, int count, int offset)
  1501. {
  1502. unsigned short *d = (unsigned short *)
  1503. (vc->vc_origin + vc->vc_size_row * line);
  1504. unsigned short *s = d + offset;
  1505. while (count--) {
  1506. unsigned short *start = s;
  1507. unsigned short *le = advance_row(s, 1);
  1508. unsigned short c;
  1509. int x = 0;
  1510. unsigned short attr = 1;
  1511. do {
  1512. c = scr_readw(s);
  1513. if (attr != (c & 0xff00)) {
  1514. attr = c & 0xff00;
  1515. if (s > start) {
  1516. fbcon_putcs(vc, start, s - start,
  1517. line, x);
  1518. x += s - start;
  1519. start = s;
  1520. }
  1521. }
  1522. if (c == scr_readw(d)) {
  1523. if (s > start) {
  1524. fbcon_putcs(vc, start, s - start,
  1525. line, x);
  1526. x += s - start + 1;
  1527. start = s + 1;
  1528. } else {
  1529. x++;
  1530. start++;
  1531. }
  1532. }
  1533. scr_writew(c, d);
  1534. console_conditional_schedule();
  1535. s++;
  1536. d++;
  1537. } while (s < le);
  1538. if (s > start)
  1539. fbcon_putcs(vc, start, s - start, line, x);
  1540. console_conditional_schedule();
  1541. if (offset > 0)
  1542. line++;
  1543. else {
  1544. line--;
  1545. /* NOTE: We subtract two lines from these pointers */
  1546. s -= vc->vc_size_row;
  1547. d -= vc->vc_size_row;
  1548. }
  1549. }
  1550. }
  1551. static inline void fbcon_softback_note(struct vc_data *vc, int t,
  1552. int count)
  1553. {
  1554. unsigned short *p;
  1555. if (vc->vc_num != fg_console)
  1556. return;
  1557. p = (unsigned short *) (vc->vc_origin + t * vc->vc_size_row);
  1558. while (count) {
  1559. scr_memcpyw((u16 *) softback_in, p, vc->vc_size_row);
  1560. count--;
  1561. p = advance_row(p, 1);
  1562. softback_in += vc->vc_size_row;
  1563. if (softback_in == softback_end)
  1564. softback_in = softback_buf;
  1565. if (softback_in == softback_top) {
  1566. softback_top += vc->vc_size_row;
  1567. if (softback_top == softback_end)
  1568. softback_top = softback_buf;
  1569. }
  1570. }
  1571. softback_curr = softback_in;
  1572. }
  1573. static bool fbcon_scroll(struct vc_data *vc, unsigned int t, unsigned int b,
  1574. enum con_scroll dir, unsigned int count)
  1575. {
  1576. struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
  1577. struct display *p = &fb_display[vc->vc_num];
  1578. int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK;
  1579. if (fbcon_is_inactive(vc, info))
  1580. return true;
  1581. fbcon_cursor(vc, CM_ERASE);
  1582. /*
  1583. * ++Geert: Only use ywrap/ypan if the console is in text mode
  1584. * ++Andrew: Only use ypan on hardware text mode when scrolling the
  1585. * whole screen (prevents flicker).
  1586. */
  1587. switch (dir) {
  1588. case SM_UP:
  1589. if (count > vc->vc_rows) /* Maximum realistic size */
  1590. count = vc->vc_rows;
  1591. if (softback_top)
  1592. fbcon_softback_note(vc, t, count);
  1593. if (logo_shown >= 0)
  1594. goto redraw_up;
  1595. switch (p->scrollmode) {
  1596. case SCROLL_MOVE:
  1597. fbcon_redraw_blit(vc, info, p, t, b - t - count,
  1598. count);
  1599. fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
  1600. scr_memsetw((unsigned short *) (vc->vc_origin +
  1601. vc->vc_size_row *
  1602. (b - count)),
  1603. vc->vc_video_erase_char,
  1604. vc->vc_size_row * count);
  1605. return true;
  1606. break;
  1607. case SCROLL_WRAP_MOVE:
  1608. if (b - t - count > 3 * vc->vc_rows >> 2) {
  1609. if (t > 0)
  1610. fbcon_bmove(vc, 0, 0, count, 0, t,
  1611. vc->vc_cols);
  1612. ywrap_up(vc, count);
  1613. if (vc->vc_rows - b > 0)
  1614. fbcon_bmove(vc, b - count, 0, b, 0,
  1615. vc->vc_rows - b,
  1616. vc->vc_cols);
  1617. } else if (info->flags & FBINFO_READS_FAST)
  1618. fbcon_bmove(vc, t + count, 0, t, 0,
  1619. b - t - count, vc->vc_cols);
  1620. else
  1621. goto redraw_up;
  1622. fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
  1623. break;
  1624. case SCROLL_PAN_REDRAW:
  1625. if ((p->yscroll + count <=
  1626. 2 * (p->vrows - vc->vc_rows))
  1627. && ((!scroll_partial && (b - t == vc->vc_rows))
  1628. || (scroll_partial
  1629. && (b - t - count >
  1630. 3 * vc->vc_rows >> 2)))) {
  1631. if (t > 0)
  1632. fbcon_redraw_move(vc, p, 0, t, count);
  1633. ypan_up_redraw(vc, t, count);
  1634. if (vc->vc_rows - b > 0)
  1635. fbcon_redraw_move(vc, p, b,
  1636. vc->vc_rows - b, b);
  1637. } else
  1638. fbcon_redraw_move(vc, p, t + count, b - t - count, t);
  1639. fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
  1640. break;
  1641. case SCROLL_PAN_MOVE:
  1642. if ((p->yscroll + count <=
  1643. 2 * (p->vrows - vc->vc_rows))
  1644. && ((!scroll_partial && (b - t == vc->vc_rows))
  1645. || (scroll_partial
  1646. && (b - t - count >
  1647. 3 * vc->vc_rows >> 2)))) {
  1648. if (t > 0)
  1649. fbcon_bmove(vc, 0, 0, count, 0, t,
  1650. vc->vc_cols);
  1651. ypan_up(vc, count);
  1652. if (vc->vc_rows - b > 0)
  1653. fbcon_bmove(vc, b - count, 0, b, 0,
  1654. vc->vc_rows - b,
  1655. vc->vc_cols);
  1656. } else if (info->flags & FBINFO_READS_FAST)
  1657. fbcon_bmove(vc, t + count, 0, t, 0,
  1658. b - t - count, vc->vc_cols);
  1659. else
  1660. goto redraw_up;
  1661. fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
  1662. break;
  1663. case SCROLL_REDRAW:
  1664. redraw_up:
  1665. fbcon_redraw(vc, p, t, b - t - count,
  1666. count * vc->vc_cols);
  1667. fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
  1668. scr_memsetw((unsigned short *) (vc->vc_origin +
  1669. vc->vc_size_row *
  1670. (b - count)),
  1671. vc->vc_video_erase_char,
  1672. vc->vc_size_row * count);
  1673. return true;
  1674. }
  1675. break;
  1676. case SM_DOWN:
  1677. if (count > vc->vc_rows) /* Maximum realistic size */
  1678. count = vc->vc_rows;
  1679. if (logo_shown >= 0)
  1680. goto redraw_down;
  1681. switch (p->scrollmode) {
  1682. case SCROLL_MOVE:
  1683. fbcon_redraw_blit(vc, info, p, b - 1, b - t - count,
  1684. -count);
  1685. fbcon_clear(vc, t, 0, count, vc->vc_cols);
  1686. scr_memsetw((unsigned short *) (vc->vc_origin +
  1687. vc->vc_size_row *
  1688. t),
  1689. vc->vc_video_erase_char,
  1690. vc->vc_size_row * count);
  1691. return true;
  1692. break;
  1693. case SCROLL_WRAP_MOVE:
  1694. if (b - t - count > 3 * vc->vc_rows >> 2) {
  1695. if (vc->vc_rows - b > 0)
  1696. fbcon_bmove(vc, b, 0, b - count, 0,
  1697. vc->vc_rows - b,
  1698. vc->vc_cols);
  1699. ywrap_down(vc, count);
  1700. if (t > 0)
  1701. fbcon_bmove(vc, count, 0, 0, 0, t,
  1702. vc->vc_cols);
  1703. } else if (info->flags & FBINFO_READS_FAST)
  1704. fbcon_bmove(vc, t, 0, t + count, 0,
  1705. b - t - count, vc->vc_cols);
  1706. else
  1707. goto redraw_down;
  1708. fbcon_clear(vc, t, 0, count, vc->vc_cols);
  1709. break;
  1710. case SCROLL_PAN_MOVE:
  1711. if ((count - p->yscroll <= p->vrows - vc->vc_rows)
  1712. && ((!scroll_partial && (b - t == vc->vc_rows))
  1713. || (scroll_partial
  1714. && (b - t - count >
  1715. 3 * vc->vc_rows >> 2)))) {
  1716. if (vc->vc_rows - b > 0)
  1717. fbcon_bmove(vc, b, 0, b - count, 0,
  1718. vc->vc_rows - b,
  1719. vc->vc_cols);
  1720. ypan_down(vc, count);
  1721. if (t > 0)
  1722. fbcon_bmove(vc, count, 0, 0, 0, t,
  1723. vc->vc_cols);
  1724. } else if (info->flags & FBINFO_READS_FAST)
  1725. fbcon_bmove(vc, t, 0, t + count, 0,
  1726. b - t - count, vc->vc_cols);
  1727. else
  1728. goto redraw_down;
  1729. fbcon_clear(vc, t, 0, count, vc->vc_cols);
  1730. break;
  1731. case SCROLL_PAN_REDRAW:
  1732. if ((count - p->yscroll <= p->vrows - vc->vc_rows)
  1733. && ((!scroll_partial && (b - t == vc->vc_rows))
  1734. || (scroll_partial
  1735. && (b - t - count >
  1736. 3 * vc->vc_rows >> 2)))) {
  1737. if (vc->vc_rows - b > 0)
  1738. fbcon_redraw_move(vc, p, b, vc->vc_rows - b,
  1739. b - count);
  1740. ypan_down_redraw(vc, t, count);
  1741. if (t > 0)
  1742. fbcon_redraw_move(vc, p, count, t, 0);
  1743. } else
  1744. fbcon_redraw_move(vc, p, t, b - t - count, t + count);
  1745. fbcon_clear(vc, t, 0, count, vc->vc_cols);
  1746. break;
  1747. case SCROLL_REDRAW:
  1748. redraw_down:
  1749. fbcon_redraw(vc, p, b - 1, b - t - count,
  1750. -count * vc->vc_cols);
  1751. fbcon_clear(vc, t, 0, count, vc->vc_cols);
  1752. scr_memsetw((unsigned short *) (vc->vc_origin +
  1753. vc->vc_size_row *
  1754. t),
  1755. vc->vc_video_erase_char,
  1756. vc->vc_size_row * count);
  1757. return true;
  1758. }
  1759. }
  1760. return false;
  1761. }
  1762. static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
  1763. int height, int width)
  1764. {
  1765. struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
  1766. struct display *p = &fb_display[vc->vc_num];
  1767. if (fbcon_is_inactive(vc, info))
  1768. return;
  1769. if (!width || !height)
  1770. return;
  1771. /* Split blits that cross physical y_wrap case.
  1772. * Pathological case involves 4 blits, better to use recursive
  1773. * code rather than unrolled case
  1774. *
  1775. * Recursive invocations don't need to erase the cursor over and
  1776. * over again, so we use fbcon_bmove_rec()
  1777. */
  1778. fbcon_bmove_rec(vc, p, sy, sx, dy, dx, height, width,
  1779. p->vrows - p->yscroll);
  1780. }
  1781. static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
  1782. int dy, int dx, int height, int width, u_int y_break)
  1783. {
  1784. struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
  1785. struct fbcon_ops *ops = info->fbcon_par;
  1786. u_int b;
  1787. if (sy < y_break && sy + height > y_break) {
  1788. b = y_break - sy;
  1789. if (dy < sy) { /* Avoid trashing self */
  1790. fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
  1791. y_break);
  1792. fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
  1793. height - b, width, y_break);
  1794. } else {
  1795. fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
  1796. height - b, width, y_break);
  1797. fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
  1798. y_break);
  1799. }
  1800. return;
  1801. }
  1802. if (dy < y_break && dy + height > y_break) {
  1803. b = y_break - dy;
  1804. if (dy < sy) { /* Avoid trashing self */
  1805. fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
  1806. y_break);
  1807. fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
  1808. height - b, width, y_break);
  1809. } else {
  1810. fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
  1811. height - b, width, y_break);
  1812. fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
  1813. y_break);
  1814. }
  1815. return;
  1816. }
  1817. ops->bmove(vc, info, real_y(p, sy), sx, real_y(p, dy), dx,
  1818. height, width);
  1819. }
  1820. static void updatescrollmode(struct display *p,
  1821. struct fb_info *info,
  1822. struct vc_data *vc)
  1823. {
  1824. struct fbcon_ops *ops = info->fbcon_par;
  1825. int fh = vc->vc_font.height;
  1826. int cap = info->flags;
  1827. u16 t = 0;
  1828. int ypan = FBCON_SWAP(ops->rotate, info->fix.ypanstep,
  1829. info->fix.xpanstep);
  1830. int ywrap = FBCON_SWAP(ops->rotate, info->fix.ywrapstep, t);
  1831. int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
  1832. int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual,
  1833. info->var.xres_virtual);
  1834. int good_pan = (cap & FBINFO_HWACCEL_YPAN) &&
  1835. divides(ypan, vc->vc_font.height) && vyres > yres;
  1836. int good_wrap = (cap & FBINFO_HWACCEL_YWRAP) &&
  1837. divides(ywrap, vc->vc_font.height) &&
  1838. divides(vc->vc_font.height, vyres) &&
  1839. divides(vc->vc_font.height, yres);
  1840. int reading_fast = cap & FBINFO_READS_FAST;
  1841. int fast_copyarea = (cap & FBINFO_HWACCEL_COPYAREA) &&
  1842. !(cap & FBINFO_HWACCEL_DISABLED);
  1843. int fast_imageblit = (cap & FBINFO_HWACCEL_IMAGEBLIT) &&
  1844. !(cap & FBINFO_HWACCEL_DISABLED);
  1845. p->vrows = vyres/fh;
  1846. if (yres > (fh * (vc->vc_rows + 1)))
  1847. p->vrows -= (yres - (fh * vc->vc_rows)) / fh;
  1848. if ((yres % fh) && (vyres % fh < yres % fh))
  1849. p->vrows--;
  1850. if (good_wrap || good_pan) {
  1851. if (reading_fast || fast_copyarea)
  1852. p->scrollmode = good_wrap ?
  1853. SCROLL_WRAP_MOVE : SCROLL_PAN_MOVE;
  1854. else
  1855. p->scrollmode = good_wrap ? SCROLL_REDRAW :
  1856. SCROLL_PAN_REDRAW;
  1857. } else {
  1858. if (reading_fast || (fast_copyarea && !fast_imageblit))
  1859. p->scrollmode = SCROLL_MOVE;
  1860. else
  1861. p->scrollmode = SCROLL_REDRAW;
  1862. }
  1863. }
  1864. static int fbcon_resize(struct vc_data *vc, unsigned int width,
  1865. unsigned int height, unsigned int user)
  1866. {
  1867. struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
  1868. struct fbcon_ops *ops = info->fbcon_par;
  1869. struct display *p = &fb_display[vc->vc_num];
  1870. struct fb_var_screeninfo var = info->var;
  1871. int x_diff, y_diff, virt_w, virt_h, virt_fw, virt_fh;
  1872. virt_w = FBCON_SWAP(ops->rotate, width, height);
  1873. virt_h = FBCON_SWAP(ops->rotate, height, width);
  1874. virt_fw = FBCON_SWAP(ops->rotate, vc->vc_font.width,
  1875. vc->vc_font.height);
  1876. virt_fh = FBCON_SWAP(ops->rotate, vc->vc_font.height,
  1877. vc->vc_font.width);
  1878. var.xres = virt_w * virt_fw;
  1879. var.yres = virt_h * virt_fh;
  1880. x_diff = info->var.xres - var.xres;
  1881. y_diff = info->var.yres - var.yres;
  1882. if (x_diff < 0 || x_diff > virt_fw ||
  1883. y_diff < 0 || y_diff > virt_fh) {
  1884. const struct fb_videomode *mode;
  1885. DPRINTK("attempting resize %ix%i\n", var.xres, var.yres);
  1886. mode = fb_find_best_mode(&var, &info->modelist);
  1887. if (mode == NULL)
  1888. return -EINVAL;
  1889. display_to_var(&var, p);
  1890. fb_videomode_to_var(&var, mode);
  1891. if (virt_w > var.xres/virt_fw || virt_h > var.yres/virt_fh)
  1892. return -EINVAL;
  1893. DPRINTK("resize now %ix%i\n", var.xres, var.yres);
  1894. if (con_is_visible(vc)) {
  1895. var.activate = FB_ACTIVATE_NOW |
  1896. FB_ACTIVATE_FORCE;
  1897. fb_set_var(info, &var);
  1898. }
  1899. var_to_display(p, &info->var, info);
  1900. ops->var = info->var;
  1901. }
  1902. updatescrollmode(p, info, vc);
  1903. return 0;
  1904. }
  1905. static int fbcon_switch(struct vc_data *vc)
  1906. {
  1907. struct fb_info *info, *old_info = NULL;
  1908. struct fbcon_ops *ops;
  1909. struct display *p = &fb_display[vc->vc_num];
  1910. struct fb_var_screeninfo var;
  1911. int i, ret, prev_console, charcnt = 256;
  1912. info = registered_fb[con2fb_map[vc->vc_num]];
  1913. ops = info->fbcon_par;
  1914. if (softback_top) {
  1915. if (softback_lines)
  1916. fbcon_set_origin(vc);
  1917. softback_top = softback_curr = softback_in = softback_buf;
  1918. softback_lines = 0;
  1919. fbcon_update_softback(vc);
  1920. }
  1921. if (logo_shown >= 0) {
  1922. struct vc_data *conp2 = vc_cons[logo_shown].d;
  1923. if (conp2->vc_top == logo_lines
  1924. && conp2->vc_bottom == conp2->vc_rows)
  1925. conp2->vc_top = 0;
  1926. logo_shown = FBCON_LOGO_CANSHOW;
  1927. }
  1928. prev_console = ops->currcon;
  1929. if (prev_console != -1)
  1930. old_info = registered_fb[con2fb_map[prev_console]];
  1931. /*
  1932. * FIXME: If we have multiple fbdev's loaded, we need to
  1933. * update all info->currcon. Perhaps, we can place this
  1934. * in a centralized structure, but this might break some
  1935. * drivers.
  1936. *
  1937. * info->currcon = vc->vc_num;
  1938. */
  1939. for_each_registered_fb(i) {
  1940. if (registered_fb[i]->fbcon_par) {
  1941. struct fbcon_ops *o = registered_fb[i]->fbcon_par;
  1942. o->currcon = vc->vc_num;
  1943. }
  1944. }
  1945. memset(&var, 0, sizeof(struct fb_var_screeninfo));
  1946. display_to_var(&var, p);
  1947. var.activate = FB_ACTIVATE_NOW;
  1948. /*
  1949. * make sure we don't unnecessarily trip the memcmp()
  1950. * in fb_set_var()
  1951. */
  1952. info->var.activate = var.activate;
  1953. var.vmode |= info->var.vmode & ~FB_VMODE_MASK;
  1954. fb_set_var(info, &var);
  1955. ops->var = info->var;
  1956. if (old_info != NULL && (old_info != info ||
  1957. info->flags & FBINFO_MISC_ALWAYS_SETPAR)) {
  1958. if (info->fbops->fb_set_par) {
  1959. ret = info->fbops->fb_set_par(info);
  1960. if (ret)
  1961. printk(KERN_ERR "fbcon_switch: detected "
  1962. "unhandled fb_set_par error, "
  1963. "error code %d\n", ret);
  1964. }
  1965. if (old_info != info)
  1966. fbcon_del_cursor_timer(old_info);
  1967. }
  1968. if (fbcon_is_inactive(vc, info) ||
  1969. ops->blank_state != FB_BLANK_UNBLANK)
  1970. fbcon_del_cursor_timer(info);
  1971. else
  1972. fbcon_add_cursor_timer(info);
  1973. set_blitting_type(vc, info);
  1974. ops->cursor_reset = 1;
  1975. if (ops->rotate_font && ops->rotate_font(info, vc)) {
  1976. ops->rotate = FB_ROTATE_UR;
  1977. set_blitting_type(vc, info);
  1978. }
  1979. vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
  1980. vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
  1981. if (p->userfont)
  1982. charcnt = FNTCHARCNT(vc->vc_font.data);
  1983. if (charcnt > 256)
  1984. vc->vc_complement_mask <<= 1;
  1985. updatescrollmode(p, info, vc);
  1986. switch (p->scrollmode) {
  1987. case SCROLL_WRAP_MOVE:
  1988. scrollback_phys_max = p->vrows - vc->vc_rows;
  1989. break;
  1990. case SCROLL_PAN_MOVE:
  1991. case SCROLL_PAN_REDRAW:
  1992. scrollback_phys_max = p->vrows - 2 * vc->vc_rows;
  1993. if (scrollback_phys_max < 0)
  1994. scrollback_phys_max = 0;
  1995. break;
  1996. default:
  1997. scrollback_phys_max = 0;
  1998. break;
  1999. }
  2000. scrollback_max = 0;
  2001. scrollback_current = 0;
  2002. if (!fbcon_is_inactive(vc, info)) {
  2003. ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
  2004. ops->update_start(info);
  2005. }
  2006. fbcon_set_palette(vc, color_table);
  2007. fbcon_clear_margins(vc, 0);
  2008. if (logo_shown == FBCON_LOGO_DRAW) {
  2009. logo_shown = fg_console;
  2010. /* This is protected above by initmem_freed */
  2011. fb_show_logo(info, ops->rotate);
  2012. update_region(vc,
  2013. vc->vc_origin + vc->vc_size_row * vc->vc_top,
  2014. vc->vc_size_row * (vc->vc_bottom -
  2015. vc->vc_top) / 2);
  2016. return 0;
  2017. }
  2018. return 1;
  2019. }
  2020. static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
  2021. int blank)
  2022. {
  2023. struct fb_event event;
  2024. if (blank) {
  2025. unsigned short charmask = vc->vc_hi_font_mask ?
  2026. 0x1ff : 0xff;
  2027. unsigned short oldc;
  2028. oldc = vc->vc_video_erase_char;
  2029. vc->vc_video_erase_char &= charmask;
  2030. fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
  2031. vc->vc_video_erase_char = oldc;
  2032. }
  2033. if (!lock_fb_info(info))
  2034. return;
  2035. event.info = info;
  2036. event.data = &blank;
  2037. fb_notifier_call_chain(FB_EVENT_CONBLANK, &event);
  2038. unlock_fb_info(info);
  2039. }
  2040. static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
  2041. {
  2042. struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
  2043. struct fbcon_ops *ops = info->fbcon_par;
  2044. if (mode_switch) {
  2045. struct fb_var_screeninfo var = info->var;
  2046. ops->graphics = 1;
  2047. if (!blank) {
  2048. var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
  2049. fb_set_var(info, &var);
  2050. ops->graphics = 0;
  2051. ops->var = info->var;
  2052. }
  2053. }
  2054. if (!fbcon_is_inactive(vc, info)) {
  2055. if (ops->blank_state != blank) {
  2056. ops->blank_state = blank;
  2057. fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW);
  2058. ops->cursor_flash = (!blank);
  2059. if (!(info->flags & FBINFO_MISC_USEREVENT))
  2060. if (fb_blank(info, blank))
  2061. fbcon_generic_blank(vc, info, blank);
  2062. }
  2063. if (!blank)
  2064. update_screen(vc);
  2065. }
  2066. if (mode_switch || fbcon_is_inactive(vc, info) ||
  2067. ops->blank_state != FB_BLANK_UNBLANK)
  2068. fbcon_del_cursor_timer(info);
  2069. else
  2070. fbcon_add_cursor_timer(info);
  2071. return 0;
  2072. }
  2073. static int fbcon_debug_enter(struct vc_data *vc)
  2074. {
  2075. struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
  2076. struct fbcon_ops *ops = info->fbcon_par;
  2077. ops->save_graphics = ops->graphics;
  2078. ops->graphics = 0;
  2079. if (info->fbops->fb_debug_enter)
  2080. info->fbops->fb_debug_enter(info);
  2081. fbcon_set_palette(vc, color_table);
  2082. return 0;
  2083. }
  2084. static int fbcon_debug_leave(struct vc_data *vc)
  2085. {
  2086. struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
  2087. struct fbcon_ops *ops = info->fbcon_par;
  2088. ops->graphics = ops->save_graphics;
  2089. if (info->fbops->fb_debug_leave)
  2090. info->fbops->fb_debug_leave(info);
  2091. return 0;
  2092. }
  2093. static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
  2094. {
  2095. u8 *fontdata = vc->vc_font.data;
  2096. u8 *data = font->data;
  2097. int i, j;
  2098. font->width = vc->vc_font.width;
  2099. font->height = vc->vc_font.height;
  2100. font->charcount = vc->vc_hi_font_mask ? 512 : 256;
  2101. if (!font->data)
  2102. return 0;
  2103. if (font->width <= 8) {
  2104. j = vc->vc_font.height;
  2105. for (i = 0; i < font->charcount; i++) {
  2106. memcpy(data, fontdata, j);
  2107. memset(data + j, 0, 32 - j);
  2108. data += 32;
  2109. fontdata += j;
  2110. }
  2111. } else if (font->width <= 16) {
  2112. j = vc->vc_font.height * 2;
  2113. for (i = 0; i < font->charcount; i++) {
  2114. memcpy(data, fontdata, j);
  2115. memset(data + j, 0, 64 - j);
  2116. data += 64;
  2117. fontdata += j;
  2118. }
  2119. } else if (font->width <= 24) {
  2120. for (i = 0; i < font->charcount; i++) {
  2121. for (j = 0; j < vc->vc_font.height; j++) {
  2122. *data++ = fontdata[0];
  2123. *data++ = fontdata[1];
  2124. *data++ = fontdata[2];
  2125. fontdata += sizeof(u32);
  2126. }
  2127. memset(data, 0, 3 * (32 - j));
  2128. data += 3 * (32 - j);
  2129. }
  2130. } else {
  2131. j = vc->vc_font.height * 4;
  2132. for (i = 0; i < font->charcount; i++) {
  2133. memcpy(data, fontdata, j);
  2134. memset(data + j, 0, 128 - j);
  2135. data += 128;
  2136. fontdata += j;
  2137. }
  2138. }
  2139. return 0;
  2140. }
  2141. /* set/clear vc_hi_font_mask and update vc attrs accordingly */
  2142. static void set_vc_hi_font(struct vc_data *vc, bool set)
  2143. {
  2144. if (!set) {
  2145. vc->vc_hi_font_mask = 0;
  2146. if (vc->vc_can_do_color) {
  2147. vc->vc_complement_mask >>= 1;
  2148. vc->vc_s_complement_mask >>= 1;
  2149. }
  2150. /* ++Edmund: reorder the attribute bits */
  2151. if (vc->vc_can_do_color) {
  2152. unsigned short *cp =
  2153. (unsigned short *) vc->vc_origin;
  2154. int count = vc->vc_screenbuf_size / 2;
  2155. unsigned short c;
  2156. for (; count > 0; count--, cp++) {
  2157. c = scr_readw(cp);
  2158. scr_writew(((c & 0xfe00) >> 1) |
  2159. (c & 0xff), cp);
  2160. }
  2161. c = vc->vc_video_erase_char;
  2162. vc->vc_video_erase_char =
  2163. ((c & 0xfe00) >> 1) | (c & 0xff);
  2164. vc->vc_attr >>= 1;
  2165. }
  2166. } else {
  2167. vc->vc_hi_font_mask = 0x100;
  2168. if (vc->vc_can_do_color) {
  2169. vc->vc_complement_mask <<= 1;
  2170. vc->vc_s_complement_mask <<= 1;
  2171. }
  2172. /* ++Edmund: reorder the attribute bits */
  2173. {
  2174. unsigned short *cp =
  2175. (unsigned short *) vc->vc_origin;
  2176. int count = vc->vc_screenbuf_size / 2;
  2177. unsigned short c;
  2178. for (; count > 0; count--, cp++) {
  2179. unsigned short newc;
  2180. c = scr_readw(cp);
  2181. if (vc->vc_can_do_color)
  2182. newc =
  2183. ((c & 0xff00) << 1) | (c &
  2184. 0xff);
  2185. else
  2186. newc = c & ~0x100;
  2187. scr_writew(newc, cp);
  2188. }
  2189. c = vc->vc_video_erase_char;
  2190. if (vc->vc_can_do_color) {
  2191. vc->vc_video_erase_char =
  2192. ((c & 0xff00) << 1) | (c & 0xff);
  2193. vc->vc_attr <<= 1;
  2194. } else
  2195. vc->vc_video_erase_char = c & ~0x100;
  2196. }
  2197. }
  2198. }
  2199. static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
  2200. const u8 * data, int userfont)
  2201. {
  2202. struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
  2203. struct fbcon_ops *ops = info->fbcon_par;
  2204. struct display *p = &fb_display[vc->vc_num];
  2205. int resize;
  2206. int cnt;
  2207. char *old_data = NULL;
  2208. if (con_is_visible(vc) && softback_lines)
  2209. fbcon_set_origin(vc);
  2210. resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
  2211. if (p->userfont)
  2212. old_data = vc->vc_font.data;
  2213. if (userfont)
  2214. cnt = FNTCHARCNT(data);
  2215. else
  2216. cnt = 256;
  2217. vc->vc_font.data = (void *)(p->fontdata = data);
  2218. if ((p->userfont = userfont))
  2219. REFCOUNT(data)++;
  2220. vc->vc_font.width = w;
  2221. vc->vc_font.height = h;
  2222. if (vc->vc_hi_font_mask && cnt == 256)
  2223. set_vc_hi_font(vc, false);
  2224. else if (!vc->vc_hi_font_mask && cnt == 512)
  2225. set_vc_hi_font(vc, true);
  2226. if (resize) {
  2227. int cols, rows;
  2228. cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
  2229. rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
  2230. cols /= w;
  2231. rows /= h;
  2232. vc_resize(vc, cols, rows);
  2233. if (con_is_visible(vc) && softback_buf)
  2234. fbcon_update_softback(vc);
  2235. } else if (con_is_visible(vc)
  2236. && vc->vc_mode == KD_TEXT) {
  2237. fbcon_clear_margins(vc, 0);
  2238. update_screen(vc);
  2239. }
  2240. if (old_data && (--REFCOUNT(old_data) == 0))
  2241. kfree(old_data - FONT_EXTRA_WORDS * sizeof(int));
  2242. return 0;
  2243. }
  2244. static int fbcon_copy_font(struct vc_data *vc, int con)
  2245. {
  2246. struct display *od = &fb_display[con];
  2247. struct console_font *f = &vc->vc_font;
  2248. if (od->fontdata == f->data)
  2249. return 0; /* already the same font... */
  2250. return fbcon_do_set_font(vc, f->width, f->height, od->fontdata, od->userfont);
  2251. }
  2252. /*
  2253. * User asked to set font; we are guaranteed that
  2254. * a) width and height are in range 1..32
  2255. * b) charcount does not exceed 512
  2256. * but lets not assume that, since someone might someday want to use larger
  2257. * fonts. And charcount of 512 is small for unicode support.
  2258. *
  2259. * However, user space gives the font in 32 rows , regardless of
  2260. * actual font height. So a new API is needed if support for larger fonts
  2261. * is ever implemented.
  2262. */
  2263. static int fbcon_set_font(struct vc_data *vc, struct console_font *font,
  2264. unsigned int flags)
  2265. {
  2266. struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
  2267. unsigned charcount = font->charcount;
  2268. int w = font->width;
  2269. int h = font->height;
  2270. int size;
  2271. int i, csum;
  2272. u8 *new_data, *data = font->data;
  2273. int pitch = (font->width+7) >> 3;
  2274. /* Is there a reason why fbconsole couldn't handle any charcount >256?
  2275. * If not this check should be changed to charcount < 256 */
  2276. if (charcount != 256 && charcount != 512)
  2277. return -EINVAL;
  2278. /* Make sure drawing engine can handle the font */
  2279. if (!(info->pixmap.blit_x & (1 << (font->width - 1))) ||
  2280. !(info->pixmap.blit_y & (1 << (font->height - 1))))
  2281. return -EINVAL;
  2282. /* Make sure driver can handle the font length */
  2283. if (fbcon_invalid_charcount(info, charcount))
  2284. return -EINVAL;
  2285. size = h * pitch * charcount;
  2286. new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER);
  2287. if (!new_data)
  2288. return -ENOMEM;
  2289. new_data += FONT_EXTRA_WORDS * sizeof(int);
  2290. FNTSIZE(new_data) = size;
  2291. FNTCHARCNT(new_data) = charcount;
  2292. REFCOUNT(new_data) = 0; /* usage counter */
  2293. for (i=0; i< charcount; i++) {
  2294. memcpy(new_data + i*h*pitch, data + i*32*pitch, h*pitch);
  2295. }
  2296. /* Since linux has a nice crc32 function use it for counting font
  2297. * checksums. */
  2298. csum = crc32(0, new_data, size);
  2299. FNTSUM(new_data) = csum;
  2300. /* Check if the same font is on some other console already */
  2301. for (i = first_fb_vc; i <= last_fb_vc; i++) {
  2302. struct vc_data *tmp = vc_cons[i].d;
  2303. if (fb_display[i].userfont &&
  2304. fb_display[i].fontdata &&
  2305. FNTSUM(fb_display[i].fontdata) == csum &&
  2306. FNTSIZE(fb_display[i].fontdata) == size &&
  2307. tmp->vc_font.width == w &&
  2308. !memcmp(fb_display[i].fontdata, new_data, size)) {
  2309. kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
  2310. new_data = (u8 *)fb_display[i].fontdata;
  2311. break;
  2312. }
  2313. }
  2314. return fbcon_do_set_font(vc, font->width, font->height, new_data, 1);
  2315. }
  2316. static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name)
  2317. {
  2318. struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
  2319. const struct font_desc *f;
  2320. if (!name)
  2321. f = get_default_font(info->var.xres, info->var.yres,
  2322. info->pixmap.blit_x, info->pixmap.blit_y);
  2323. else if (!(f = find_font(name)))
  2324. return -ENOENT;
  2325. font->width = f->width;
  2326. font->height = f->height;
  2327. return fbcon_do_set_font(vc, f->width, f->height, f->data, 0);
  2328. }
  2329. static u16 palette_red[16];
  2330. static u16 palette_green[16];
  2331. static u16 palette_blue[16];
  2332. static struct fb_cmap palette_cmap = {
  2333. 0, 16, palette_red, palette_green, palette_blue, NULL
  2334. };
  2335. static void fbcon_set_palette(struct vc_data *vc, const unsigned char *table)
  2336. {
  2337. struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
  2338. int i, j, k, depth;
  2339. u8 val;
  2340. if (fbcon_is_inactive(vc, info))
  2341. return;
  2342. if (!con_is_visible(vc))
  2343. return;
  2344. depth = fb_get_color_depth(&info->var, &info->fix);
  2345. if (depth > 3) {
  2346. for (i = j = 0; i < 16; i++) {
  2347. k = table[i];
  2348. val = vc->vc_palette[j++];
  2349. palette_red[k] = (val << 8) | val;
  2350. val = vc->vc_palette[j++];
  2351. palette_green[k] = (val << 8) | val;
  2352. val = vc->vc_palette[j++];
  2353. palette_blue[k] = (val << 8) | val;
  2354. }
  2355. palette_cmap.len = 16;
  2356. palette_cmap.start = 0;
  2357. /*
  2358. * If framebuffer is capable of less than 16 colors,
  2359. * use default palette of fbcon.
  2360. */
  2361. } else
  2362. fb_copy_cmap(fb_default_cmap(1 << depth), &palette_cmap);
  2363. fb_set_cmap(&palette_cmap, info);
  2364. }
  2365. static u16 *fbcon_screen_pos(struct vc_data *vc, int offset)
  2366. {
  2367. unsigned long p;
  2368. int line;
  2369. if (vc->vc_num != fg_console || !softback_lines)
  2370. return (u16 *) (vc->vc_origin + offset);
  2371. line = offset / vc->vc_size_row;
  2372. if (line >= softback_lines)
  2373. return (u16 *) (vc->vc_origin + offset -
  2374. softback_lines * vc->vc_size_row);
  2375. p = softback_curr + offset;
  2376. if (p >= softback_end)
  2377. p += softback_buf - softback_end;
  2378. return (u16 *) p;
  2379. }
  2380. static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos,
  2381. int *px, int *py)
  2382. {
  2383. unsigned long ret;
  2384. int x, y;
  2385. if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {
  2386. unsigned long offset = (pos - vc->vc_origin) / 2;
  2387. x = offset % vc->vc_cols;
  2388. y = offset / vc->vc_cols;
  2389. if (vc->vc_num == fg_console)
  2390. y += softback_lines;
  2391. ret = pos + (vc->vc_cols - x) * 2;
  2392. } else if (vc->vc_num == fg_console && softback_lines) {
  2393. unsigned long offset = pos - softback_curr;
  2394. if (pos < softback_curr)
  2395. offset += softback_end - softback_buf;
  2396. offset /= 2;
  2397. x = offset % vc->vc_cols;
  2398. y = offset / vc->vc_cols;
  2399. ret = pos + (vc->vc_cols - x) * 2;
  2400. if (ret == softback_end)
  2401. ret = softback_buf;
  2402. if (ret == softback_in)
  2403. ret = vc->vc_origin;
  2404. } else {
  2405. /* Should not happen */
  2406. x = y = 0;
  2407. ret = vc->vc_origin;
  2408. }
  2409. if (px)
  2410. *px = x;
  2411. if (py)
  2412. *py = y;
  2413. return ret;
  2414. }
  2415. /* As we might be inside of softback, we may work with non-contiguous buffer,
  2416. that's why we have to use a separate routine. */
  2417. static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt)
  2418. {
  2419. while (cnt--) {
  2420. u16 a = scr_readw(p);
  2421. if (!vc->vc_can_do_color)
  2422. a ^= 0x0800;
  2423. else if (vc->vc_hi_font_mask == 0x100)
  2424. a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) |
  2425. (((a) & 0x0e00) << 4);
  2426. else
  2427. a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) |
  2428. (((a) & 0x0700) << 4);
  2429. scr_writew(a, p++);
  2430. if (p == (u16 *) softback_end)
  2431. p = (u16 *) softback_buf;
  2432. if (p == (u16 *) softback_in)
  2433. p = (u16 *) vc->vc_origin;
  2434. }
  2435. }
  2436. static void fbcon_scrolldelta(struct vc_data *vc, int lines)
  2437. {
  2438. struct fb_info *info = registered_fb[con2fb_map[fg_console]];
  2439. struct fbcon_ops *ops = info->fbcon_par;
  2440. struct display *disp = &fb_display[fg_console];
  2441. int offset, limit, scrollback_old;
  2442. if (softback_top) {
  2443. if (vc->vc_num != fg_console)
  2444. return;
  2445. if (vc->vc_mode != KD_TEXT || !lines)
  2446. return;
  2447. if (logo_shown >= 0) {
  2448. struct vc_data *conp2 = vc_cons[logo_shown].d;
  2449. if (conp2->vc_top == logo_lines
  2450. && conp2->vc_bottom == conp2->vc_rows)
  2451. conp2->vc_top = 0;
  2452. if (logo_shown == vc->vc_num) {
  2453. unsigned long p, q;
  2454. int i;
  2455. p = softback_in;
  2456. q = vc->vc_origin +
  2457. logo_lines * vc->vc_size_row;
  2458. for (i = 0; i < logo_lines; i++) {
  2459. if (p == softback_top)
  2460. break;
  2461. if (p == softback_buf)
  2462. p = softback_end;
  2463. p -= vc->vc_size_row;
  2464. q -= vc->vc_size_row;
  2465. scr_memcpyw((u16 *) q, (u16 *) p,
  2466. vc->vc_size_row);
  2467. }
  2468. softback_in = softback_curr = p;
  2469. update_region(vc, vc->vc_origin,
  2470. logo_lines * vc->vc_cols);
  2471. }
  2472. logo_shown = FBCON_LOGO_CANSHOW;
  2473. }
  2474. fbcon_cursor(vc, CM_ERASE | CM_SOFTBACK);
  2475. fbcon_redraw_softback(vc, disp, lines);
  2476. fbcon_cursor(vc, CM_DRAW | CM_SOFTBACK);
  2477. return;
  2478. }
  2479. if (!scrollback_phys_max)
  2480. return;
  2481. scrollback_old = scrollback_current;
  2482. scrollback_current -= lines;
  2483. if (scrollback_current < 0)
  2484. scrollback_current = 0;
  2485. else if (scrollback_current > scrollback_max)
  2486. scrollback_current = scrollback_max;
  2487. if (scrollback_current == scrollback_old)
  2488. return;
  2489. if (fbcon_is_inactive(vc, info))
  2490. return;
  2491. fbcon_cursor(vc, CM_ERASE);
  2492. offset = disp->yscroll - scrollback_current;
  2493. limit = disp->vrows;
  2494. switch (disp->scrollmode) {
  2495. case SCROLL_WRAP_MOVE:
  2496. info->var.vmode |= FB_VMODE_YWRAP;
  2497. break;
  2498. case SCROLL_PAN_MOVE:
  2499. case SCROLL_PAN_REDRAW:
  2500. limit -= vc->vc_rows;
  2501. info->var.vmode &= ~FB_VMODE_YWRAP;
  2502. break;
  2503. }
  2504. if (offset < 0)
  2505. offset += limit;
  2506. else if (offset >= limit)
  2507. offset -= limit;
  2508. ops->var.xoffset = 0;
  2509. ops->var.yoffset = offset * vc->vc_font.height;
  2510. ops->update_start(info);
  2511. if (!scrollback_current)
  2512. fbcon_cursor(vc, CM_DRAW);
  2513. }
  2514. static int fbcon_set_origin(struct vc_data *vc)
  2515. {
  2516. if (softback_lines)
  2517. fbcon_scrolldelta(vc, softback_lines);
  2518. return 0;
  2519. }
  2520. static void fbcon_suspended(struct fb_info *info)
  2521. {
  2522. struct vc_data *vc = NULL;
  2523. struct fbcon_ops *ops = info->fbcon_par;
  2524. if (!ops || ops->currcon < 0)
  2525. return;
  2526. vc = vc_cons[ops->currcon].d;
  2527. /* Clear cursor, restore saved data */
  2528. fbcon_cursor(vc, CM_ERASE);
  2529. }
  2530. static void fbcon_resumed(struct fb_info *info)
  2531. {
  2532. struct vc_data *vc;
  2533. struct fbcon_ops *ops = info->fbcon_par;
  2534. if (!ops || ops->currcon < 0)
  2535. return;
  2536. vc = vc_cons[ops->currcon].d;
  2537. update_screen(vc);
  2538. }
  2539. static void fbcon_modechanged(struct fb_info *info)
  2540. {
  2541. struct fbcon_ops *ops = info->fbcon_par;
  2542. struct vc_data *vc;
  2543. struct display *p;
  2544. int rows, cols;
  2545. if (!ops || ops->currcon < 0)
  2546. return;
  2547. vc = vc_cons[ops->currcon].d;
  2548. if (vc->vc_mode != KD_TEXT ||
  2549. registered_fb[con2fb_map[ops->currcon]] != info)
  2550. return;
  2551. p = &fb_display[vc->vc_num];
  2552. set_blitting_type(vc, info);
  2553. if (con_is_visible(vc)) {
  2554. var_to_display(p, &info->var, info);
  2555. cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
  2556. rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
  2557. cols /= vc->vc_font.width;
  2558. rows /= vc->vc_font.height;
  2559. vc_resize(vc, cols, rows);
  2560. updatescrollmode(p, info, vc);
  2561. scrollback_max = 0;
  2562. scrollback_current = 0;
  2563. if (!fbcon_is_inactive(vc, info)) {
  2564. ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
  2565. ops->update_start(info);
  2566. }
  2567. fbcon_set_palette(vc, color_table);
  2568. update_screen(vc);
  2569. if (softback_buf)
  2570. fbcon_update_softback(vc);
  2571. }
  2572. }
  2573. static void fbcon_set_all_vcs(struct fb_info *info)
  2574. {
  2575. struct fbcon_ops *ops = info->fbcon_par;
  2576. struct vc_data *vc;
  2577. struct display *p;
  2578. int i, rows, cols, fg = -1;
  2579. if (!ops || ops->currcon < 0)
  2580. return;
  2581. for (i = first_fb_vc; i <= last_fb_vc; i++) {
  2582. vc = vc_cons[i].d;
  2583. if (!vc || vc->vc_mode != KD_TEXT ||
  2584. registered_fb[con2fb_map[i]] != info)
  2585. continue;
  2586. if (con_is_visible(vc)) {
  2587. fg = i;
  2588. continue;
  2589. }
  2590. p = &fb_display[vc->vc_num];
  2591. set_blitting_type(vc, info);
  2592. var_to_display(p, &info->var, info);
  2593. cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
  2594. rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
  2595. cols /= vc->vc_font.width;
  2596. rows /= vc->vc_font.height;
  2597. vc_resize(vc, cols, rows);
  2598. }
  2599. if (fg != -1)
  2600. fbcon_modechanged(info);
  2601. }
  2602. static int fbcon_mode_deleted(struct fb_info *info,
  2603. struct fb_videomode *mode)
  2604. {
  2605. struct fb_info *fb_info;
  2606. struct display *p;
  2607. int i, j, found = 0;
  2608. /* before deletion, ensure that mode is not in use */
  2609. for (i = first_fb_vc; i <= last_fb_vc; i++) {
  2610. j = con2fb_map[i];
  2611. if (j == -1)
  2612. continue;
  2613. fb_info = registered_fb[j];
  2614. if (fb_info != info)
  2615. continue;
  2616. p = &fb_display[i];
  2617. if (!p || !p->mode)
  2618. continue;
  2619. if (fb_mode_is_equal(p->mode, mode)) {
  2620. found = 1;
  2621. break;
  2622. }
  2623. }
  2624. return found;
  2625. }
  2626. #ifdef CONFIG_VT_HW_CONSOLE_BINDING
  2627. static int fbcon_unbind(void)
  2628. {
  2629. int ret;
  2630. ret = do_unbind_con_driver(&fb_con, first_fb_vc, last_fb_vc,
  2631. fbcon_is_default);
  2632. if (!ret)
  2633. fbcon_has_console_bind = 0;
  2634. return ret;
  2635. }
  2636. #else
  2637. static inline int fbcon_unbind(void)
  2638. {
  2639. return -EINVAL;
  2640. }
  2641. #endif /* CONFIG_VT_HW_CONSOLE_BINDING */
  2642. /* called with console_lock held */
  2643. static int fbcon_fb_unbind(int idx)
  2644. {
  2645. int i, new_idx = -1, ret = 0;
  2646. WARN_CONSOLE_UNLOCKED();
  2647. if (!fbcon_has_console_bind)
  2648. return 0;
  2649. for (i = first_fb_vc; i <= last_fb_vc; i++) {
  2650. if (con2fb_map[i] != idx &&
  2651. con2fb_map[i] != -1) {
  2652. new_idx = i;
  2653. break;
  2654. }
  2655. }
  2656. if (new_idx != -1) {
  2657. for (i = first_fb_vc; i <= last_fb_vc; i++) {
  2658. if (con2fb_map[i] == idx)
  2659. set_con2fb_map(i, new_idx, 0);
  2660. }
  2661. } else {
  2662. struct fb_info *info = registered_fb[idx];
  2663. /* This is sort of like set_con2fb_map, except it maps
  2664. * the consoles to no device and then releases the
  2665. * oldinfo to free memory and cancel the cursor blink
  2666. * timer. I can imagine this just becoming part of
  2667. * set_con2fb_map where new_idx is -1
  2668. */
  2669. for (i = first_fb_vc; i <= last_fb_vc; i++) {
  2670. if (con2fb_map[i] == idx) {
  2671. con2fb_map[i] = -1;
  2672. if (!search_fb_in_map(idx)) {
  2673. ret = con2fb_release_oldinfo(vc_cons[i].d,
  2674. info, NULL, i,
  2675. idx, 0);
  2676. if (ret) {
  2677. con2fb_map[i] = idx;
  2678. return ret;
  2679. }
  2680. }
  2681. }
  2682. }
  2683. ret = fbcon_unbind();
  2684. }
  2685. return ret;
  2686. }
  2687. /* called with console_lock held */
  2688. static int fbcon_fb_unregistered(struct fb_info *info)
  2689. {
  2690. int i, idx;
  2691. WARN_CONSOLE_UNLOCKED();
  2692. if (deferred_takeover)
  2693. return 0;
  2694. idx = info->node;
  2695. for (i = first_fb_vc; i <= last_fb_vc; i++) {
  2696. if (con2fb_map[i] == idx)
  2697. con2fb_map[i] = -1;
  2698. }
  2699. if (idx == info_idx) {
  2700. info_idx = -1;
  2701. for_each_registered_fb(i) {
  2702. info_idx = i;
  2703. break;
  2704. }
  2705. }
  2706. if (info_idx != -1) {
  2707. for (i = first_fb_vc; i <= last_fb_vc; i++) {
  2708. if (con2fb_map[i] == -1)
  2709. con2fb_map[i] = info_idx;
  2710. }
  2711. }
  2712. if (primary_device == idx)
  2713. primary_device = -1;
  2714. if (!num_registered_fb)
  2715. do_unregister_con_driver(&fb_con);
  2716. return 0;
  2717. }
  2718. /* called with console_lock held */
  2719. static void fbcon_remap_all(int idx)
  2720. {
  2721. int i;
  2722. WARN_CONSOLE_UNLOCKED();
  2723. if (deferred_takeover) {
  2724. for (i = first_fb_vc; i <= last_fb_vc; i++)
  2725. con2fb_map_boot[i] = idx;
  2726. fbcon_map_override();
  2727. return;
  2728. }
  2729. for (i = first_fb_vc; i <= last_fb_vc; i++)
  2730. set_con2fb_map(i, idx, 0);
  2731. if (con_is_bound(&fb_con)) {
  2732. printk(KERN_INFO "fbcon: Remapping primary device, "
  2733. "fb%i, to tty %i-%i\n", idx,
  2734. first_fb_vc + 1, last_fb_vc + 1);
  2735. info_idx = idx;
  2736. }
  2737. }
  2738. #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
  2739. static void fbcon_select_primary(struct fb_info *info)
  2740. {
  2741. if (!map_override && primary_device == -1 &&
  2742. fb_is_primary_device(info)) {
  2743. int i;
  2744. printk(KERN_INFO "fbcon: %s (fb%i) is primary device\n",
  2745. info->fix.id, info->node);
  2746. primary_device = info->node;
  2747. for (i = first_fb_vc; i <= last_fb_vc; i++)
  2748. con2fb_map_boot[i] = primary_device;
  2749. if (con_is_bound(&fb_con)) {
  2750. printk(KERN_INFO "fbcon: Remapping primary device, "
  2751. "fb%i, to tty %i-%i\n", info->node,
  2752. first_fb_vc + 1, last_fb_vc + 1);
  2753. info_idx = primary_device;
  2754. }
  2755. }
  2756. }
  2757. #else
  2758. static inline void fbcon_select_primary(struct fb_info *info)
  2759. {
  2760. return;
  2761. }
  2762. #endif /* CONFIG_FRAMEBUFFER_DETECT_PRIMARY */
  2763. /* called with console_lock held */
  2764. static int fbcon_fb_registered(struct fb_info *info)
  2765. {
  2766. int ret = 0, i, idx;
  2767. WARN_CONSOLE_UNLOCKED();
  2768. idx = info->node;
  2769. fbcon_select_primary(info);
  2770. if (deferred_takeover) {
  2771. pr_info("fbcon: Deferring console take-over\n");
  2772. return 0;
  2773. }
  2774. if (info_idx == -1) {
  2775. for (i = first_fb_vc; i <= last_fb_vc; i++) {
  2776. if (con2fb_map_boot[i] == idx) {
  2777. info_idx = idx;
  2778. break;
  2779. }
  2780. }
  2781. if (info_idx != -1)
  2782. ret = do_fbcon_takeover(1);
  2783. } else {
  2784. for (i = first_fb_vc; i <= last_fb_vc; i++) {
  2785. if (con2fb_map_boot[i] == idx)
  2786. set_con2fb_map(i, idx, 0);
  2787. }
  2788. }
  2789. return ret;
  2790. }
  2791. static void fbcon_fb_blanked(struct fb_info *info, int blank)
  2792. {
  2793. struct fbcon_ops *ops = info->fbcon_par;
  2794. struct vc_data *vc;
  2795. if (!ops || ops->currcon < 0)
  2796. return;
  2797. vc = vc_cons[ops->currcon].d;
  2798. if (vc->vc_mode != KD_TEXT ||
  2799. registered_fb[con2fb_map[ops->currcon]] != info)
  2800. return;
  2801. if (con_is_visible(vc)) {
  2802. if (blank)
  2803. do_blank_screen(0);
  2804. else
  2805. do_unblank_screen(0);
  2806. }
  2807. ops->blank_state = blank;
  2808. }
  2809. static void fbcon_new_modelist(struct fb_info *info)
  2810. {
  2811. int i;
  2812. struct vc_data *vc;
  2813. struct fb_var_screeninfo var;
  2814. const struct fb_videomode *mode;
  2815. for (i = first_fb_vc; i <= last_fb_vc; i++) {
  2816. if (registered_fb[con2fb_map[i]] != info)
  2817. continue;
  2818. if (!fb_display[i].mode)
  2819. continue;
  2820. vc = vc_cons[i].d;
  2821. display_to_var(&var, &fb_display[i]);
  2822. mode = fb_find_nearest_mode(fb_display[i].mode,
  2823. &info->modelist);
  2824. fb_videomode_to_var(&var, mode);
  2825. fbcon_set_disp(info, &var, vc->vc_num);
  2826. }
  2827. }
  2828. static void fbcon_get_requirement(struct fb_info *info,
  2829. struct fb_blit_caps *caps)
  2830. {
  2831. struct vc_data *vc;
  2832. struct display *p;
  2833. if (caps->flags) {
  2834. int i, charcnt;
  2835. for (i = first_fb_vc; i <= last_fb_vc; i++) {
  2836. vc = vc_cons[i].d;
  2837. if (vc && vc->vc_mode == KD_TEXT &&
  2838. info->node == con2fb_map[i]) {
  2839. p = &fb_display[i];
  2840. caps->x |= 1 << (vc->vc_font.width - 1);
  2841. caps->y |= 1 << (vc->vc_font.height - 1);
  2842. charcnt = (p->userfont) ?
  2843. FNTCHARCNT(p->fontdata) : 256;
  2844. if (caps->len < charcnt)
  2845. caps->len = charcnt;
  2846. }
  2847. }
  2848. } else {
  2849. vc = vc_cons[fg_console].d;
  2850. if (vc && vc->vc_mode == KD_TEXT &&
  2851. info->node == con2fb_map[fg_console]) {
  2852. p = &fb_display[fg_console];
  2853. caps->x = 1 << (vc->vc_font.width - 1);
  2854. caps->y = 1 << (vc->vc_font.height - 1);
  2855. caps->len = (p->userfont) ?
  2856. FNTCHARCNT(p->fontdata) : 256;
  2857. }
  2858. }
  2859. }
  2860. static int fbcon_event_notify(struct notifier_block *self,
  2861. unsigned long action, void *data)
  2862. {
  2863. struct fb_event *event = data;
  2864. struct fb_info *info = event->info;
  2865. struct fb_videomode *mode;
  2866. struct fb_con2fbmap *con2fb;
  2867. struct fb_blit_caps *caps;
  2868. int idx, ret = 0;
  2869. /*
  2870. * ignore all events except driver registration and deregistration
  2871. * if fbcon is not active
  2872. */
  2873. if (fbcon_has_exited && !(action == FB_EVENT_FB_REGISTERED ||
  2874. action == FB_EVENT_FB_UNREGISTERED))
  2875. goto done;
  2876. switch(action) {
  2877. case FB_EVENT_SUSPEND:
  2878. fbcon_suspended(info);
  2879. break;
  2880. case FB_EVENT_RESUME:
  2881. fbcon_resumed(info);
  2882. break;
  2883. case FB_EVENT_MODE_CHANGE:
  2884. fbcon_modechanged(info);
  2885. break;
  2886. case FB_EVENT_MODE_CHANGE_ALL:
  2887. fbcon_set_all_vcs(info);
  2888. break;
  2889. case FB_EVENT_MODE_DELETE:
  2890. mode = event->data;
  2891. ret = fbcon_mode_deleted(info, mode);
  2892. break;
  2893. case FB_EVENT_FB_UNBIND:
  2894. idx = info->node;
  2895. ret = fbcon_fb_unbind(idx);
  2896. break;
  2897. case FB_EVENT_FB_REGISTERED:
  2898. ret = fbcon_fb_registered(info);
  2899. break;
  2900. case FB_EVENT_FB_UNREGISTERED:
  2901. ret = fbcon_fb_unregistered(info);
  2902. break;
  2903. case FB_EVENT_SET_CONSOLE_MAP:
  2904. /* called with console lock held */
  2905. con2fb = event->data;
  2906. ret = set_con2fb_map(con2fb->console - 1,
  2907. con2fb->framebuffer, 1);
  2908. break;
  2909. case FB_EVENT_GET_CONSOLE_MAP:
  2910. con2fb = event->data;
  2911. con2fb->framebuffer = con2fb_map[con2fb->console - 1];
  2912. break;
  2913. case FB_EVENT_BLANK:
  2914. fbcon_fb_blanked(info, *(int *)event->data);
  2915. break;
  2916. case FB_EVENT_NEW_MODELIST:
  2917. fbcon_new_modelist(info);
  2918. break;
  2919. case FB_EVENT_GET_REQ:
  2920. caps = event->data;
  2921. fbcon_get_requirement(info, caps);
  2922. break;
  2923. case FB_EVENT_REMAP_ALL_CONSOLE:
  2924. idx = info->node;
  2925. fbcon_remap_all(idx);
  2926. break;
  2927. }
  2928. done:
  2929. return ret;
  2930. }
  2931. /*
  2932. * The console `switch' structure for the frame buffer based console
  2933. */
  2934. static const struct consw fb_con = {
  2935. .owner = THIS_MODULE,
  2936. .con_startup = fbcon_startup,
  2937. .con_init = fbcon_init,
  2938. .con_deinit = fbcon_deinit,
  2939. .con_clear = fbcon_clear,
  2940. .con_putc = fbcon_putc,
  2941. .con_putcs = fbcon_putcs,
  2942. .con_cursor = fbcon_cursor,
  2943. .con_scroll = fbcon_scroll,
  2944. .con_switch = fbcon_switch,
  2945. .con_blank = fbcon_blank,
  2946. .con_font_set = fbcon_set_font,
  2947. .con_font_get = fbcon_get_font,
  2948. .con_font_default = fbcon_set_def_font,
  2949. .con_font_copy = fbcon_copy_font,
  2950. .con_set_palette = fbcon_set_palette,
  2951. .con_scrolldelta = fbcon_scrolldelta,
  2952. .con_set_origin = fbcon_set_origin,
  2953. .con_invert_region = fbcon_invert_region,
  2954. .con_screen_pos = fbcon_screen_pos,
  2955. .con_getxy = fbcon_getxy,
  2956. .con_resize = fbcon_resize,
  2957. .con_debug_enter = fbcon_debug_enter,
  2958. .con_debug_leave = fbcon_debug_leave,
  2959. };
  2960. static struct notifier_block fbcon_event_notifier = {
  2961. .notifier_call = fbcon_event_notify,
  2962. };
  2963. static ssize_t store_rotate(struct device *device,
  2964. struct device_attribute *attr, const char *buf,
  2965. size_t count)
  2966. {
  2967. struct fb_info *info;
  2968. int rotate, idx;
  2969. char **last = NULL;
  2970. if (fbcon_has_exited)
  2971. return count;
  2972. console_lock();
  2973. idx = con2fb_map[fg_console];
  2974. if (idx == -1 || registered_fb[idx] == NULL)
  2975. goto err;
  2976. info = registered_fb[idx];
  2977. rotate = simple_strtoul(buf, last, 0);
  2978. fbcon_rotate(info, rotate);
  2979. err:
  2980. console_unlock();
  2981. return count;
  2982. }
  2983. static ssize_t store_rotate_all(struct device *device,
  2984. struct device_attribute *attr,const char *buf,
  2985. size_t count)
  2986. {
  2987. struct fb_info *info;
  2988. int rotate, idx;
  2989. char **last = NULL;
  2990. if (fbcon_has_exited)
  2991. return count;
  2992. console_lock();
  2993. idx = con2fb_map[fg_console];
  2994. if (idx == -1 || registered_fb[idx] == NULL)
  2995. goto err;
  2996. info = registered_fb[idx];
  2997. rotate = simple_strtoul(buf, last, 0);
  2998. fbcon_rotate_all(info, rotate);
  2999. err:
  3000. console_unlock();
  3001. return count;
  3002. }
  3003. static ssize_t show_rotate(struct device *device,
  3004. struct device_attribute *attr,char *buf)
  3005. {
  3006. struct fb_info *info;
  3007. int rotate = 0, idx;
  3008. if (fbcon_has_exited)
  3009. return 0;
  3010. console_lock();
  3011. idx = con2fb_map[fg_console];
  3012. if (idx == -1 || registered_fb[idx] == NULL)
  3013. goto err;
  3014. info = registered_fb[idx];
  3015. rotate = fbcon_get_rotate(info);
  3016. err:
  3017. console_unlock();
  3018. return snprintf(buf, PAGE_SIZE, "%d\n", rotate);
  3019. }
  3020. static ssize_t show_cursor_blink(struct device *device,
  3021. struct device_attribute *attr, char *buf)
  3022. {
  3023. struct fb_info *info;
  3024. struct fbcon_ops *ops;
  3025. int idx, blink = -1;
  3026. if (fbcon_has_exited)
  3027. return 0;
  3028. console_lock();
  3029. idx = con2fb_map[fg_console];
  3030. if (idx == -1 || registered_fb[idx] == NULL)
  3031. goto err;
  3032. info = registered_fb[idx];
  3033. ops = info->fbcon_par;
  3034. if (!ops)
  3035. goto err;
  3036. blink = (ops->flags & FBCON_FLAGS_CURSOR_TIMER) ? 1 : 0;
  3037. err:
  3038. console_unlock();
  3039. return snprintf(buf, PAGE_SIZE, "%d\n", blink);
  3040. }
  3041. static ssize_t store_cursor_blink(struct device *device,
  3042. struct device_attribute *attr,
  3043. const char *buf, size_t count)
  3044. {
  3045. struct fb_info *info;
  3046. int blink, idx;
  3047. char **last = NULL;
  3048. if (fbcon_has_exited)
  3049. return count;
  3050. console_lock();
  3051. idx = con2fb_map[fg_console];
  3052. if (idx == -1 || registered_fb[idx] == NULL)
  3053. goto err;
  3054. info = registered_fb[idx];
  3055. if (!info->fbcon_par)
  3056. goto err;
  3057. blink = simple_strtoul(buf, last, 0);
  3058. if (blink) {
  3059. fbcon_cursor_noblink = 0;
  3060. fbcon_add_cursor_timer(info);
  3061. } else {
  3062. fbcon_cursor_noblink = 1;
  3063. fbcon_del_cursor_timer(info);
  3064. }
  3065. err:
  3066. console_unlock();
  3067. return count;
  3068. }
  3069. static struct device_attribute device_attrs[] = {
  3070. __ATTR(rotate, S_IRUGO|S_IWUSR, show_rotate, store_rotate),
  3071. __ATTR(rotate_all, S_IWUSR, NULL, store_rotate_all),
  3072. __ATTR(cursor_blink, S_IRUGO|S_IWUSR, show_cursor_blink,
  3073. store_cursor_blink),
  3074. };
  3075. static int fbcon_init_device(void)
  3076. {
  3077. int i, error = 0;
  3078. fbcon_has_sysfs = 1;
  3079. for (i = 0; i < ARRAY_SIZE(device_attrs); i++) {
  3080. error = device_create_file(fbcon_device, &device_attrs[i]);
  3081. if (error)
  3082. break;
  3083. }
  3084. if (error) {
  3085. while (--i >= 0)
  3086. device_remove_file(fbcon_device, &device_attrs[i]);
  3087. fbcon_has_sysfs = 0;
  3088. }
  3089. return 0;
  3090. }
  3091. #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
  3092. static void fbcon_register_existing_fbs(struct work_struct *work)
  3093. {
  3094. int i;
  3095. console_lock();
  3096. for_each_registered_fb(i)
  3097. fbcon_fb_registered(registered_fb[i]);
  3098. console_unlock();
  3099. }
  3100. static struct notifier_block fbcon_output_nb;
  3101. static DECLARE_WORK(fbcon_deferred_takeover_work, fbcon_register_existing_fbs);
  3102. static int fbcon_output_notifier(struct notifier_block *nb,
  3103. unsigned long action, void *data)
  3104. {
  3105. WARN_CONSOLE_UNLOCKED();
  3106. pr_info("fbcon: Taking over console\n");
  3107. dummycon_unregister_output_notifier(&fbcon_output_nb);
  3108. deferred_takeover = false;
  3109. logo_shown = FBCON_LOGO_DONTSHOW;
  3110. /* We may get called in atomic context */
  3111. schedule_work(&fbcon_deferred_takeover_work);
  3112. return NOTIFY_OK;
  3113. }
  3114. #endif
  3115. static void fbcon_start(void)
  3116. {
  3117. WARN_CONSOLE_UNLOCKED();
  3118. #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
  3119. if (conswitchp != &dummy_con)
  3120. deferred_takeover = false;
  3121. if (deferred_takeover) {
  3122. fbcon_output_nb.notifier_call = fbcon_output_notifier;
  3123. dummycon_register_output_notifier(&fbcon_output_nb);
  3124. return;
  3125. }
  3126. #endif
  3127. if (num_registered_fb) {
  3128. int i;
  3129. for_each_registered_fb(i) {
  3130. info_idx = i;
  3131. break;
  3132. }
  3133. do_fbcon_takeover(0);
  3134. }
  3135. }
  3136. static void fbcon_exit(void)
  3137. {
  3138. struct fb_info *info;
  3139. int i, j, mapped;
  3140. if (fbcon_has_exited)
  3141. return;
  3142. #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
  3143. if (deferred_takeover) {
  3144. dummycon_unregister_output_notifier(&fbcon_output_nb);
  3145. deferred_takeover = false;
  3146. }
  3147. #endif
  3148. kfree((void *)softback_buf);
  3149. softback_buf = 0UL;
  3150. for_each_registered_fb(i) {
  3151. int pending = 0;
  3152. mapped = 0;
  3153. info = registered_fb[i];
  3154. if (info->queue.func)
  3155. pending = cancel_work_sync(&info->queue);
  3156. DPRINTK("fbcon: %s pending work\n", (pending ? "canceled" :
  3157. "no"));
  3158. for (j = first_fb_vc; j <= last_fb_vc; j++) {
  3159. if (con2fb_map[j] == i) {
  3160. mapped = 1;
  3161. break;
  3162. }
  3163. }
  3164. if (mapped) {
  3165. if (info->fbops->fb_release)
  3166. info->fbops->fb_release(info, 0);
  3167. module_put(info->fbops->owner);
  3168. if (info->fbcon_par) {
  3169. struct fbcon_ops *ops = info->fbcon_par;
  3170. fbcon_del_cursor_timer(info);
  3171. kfree(ops->cursor_src);
  3172. kfree(ops->cursor_state.mask);
  3173. kfree(info->fbcon_par);
  3174. info->fbcon_par = NULL;
  3175. }
  3176. if (info->queue.func == fb_flashcursor)
  3177. info->queue.func = NULL;
  3178. }
  3179. }
  3180. fbcon_has_exited = 1;
  3181. }
  3182. void __init fb_console_init(void)
  3183. {
  3184. int i;
  3185. console_lock();
  3186. fb_register_client(&fbcon_event_notifier);
  3187. fbcon_device = device_create(fb_class, NULL, MKDEV(0, 0), NULL,
  3188. "fbcon");
  3189. if (IS_ERR(fbcon_device)) {
  3190. printk(KERN_WARNING "Unable to create device "
  3191. "for fbcon; errno = %ld\n",
  3192. PTR_ERR(fbcon_device));
  3193. fbcon_device = NULL;
  3194. } else
  3195. fbcon_init_device();
  3196. for (i = 0; i < MAX_NR_CONSOLES; i++)
  3197. con2fb_map[i] = -1;
  3198. fbcon_start();
  3199. console_unlock();
  3200. }
  3201. #ifdef MODULE
  3202. static void __exit fbcon_deinit_device(void)
  3203. {
  3204. int i;
  3205. if (fbcon_has_sysfs) {
  3206. for (i = 0; i < ARRAY_SIZE(device_attrs); i++)
  3207. device_remove_file(fbcon_device, &device_attrs[i]);
  3208. fbcon_has_sysfs = 0;
  3209. }
  3210. }
  3211. void __exit fb_console_exit(void)
  3212. {
  3213. console_lock();
  3214. fb_unregister_client(&fbcon_event_notifier);
  3215. fbcon_deinit_device();
  3216. device_destroy(fb_class, MKDEV(0, 0));
  3217. fbcon_exit();
  3218. do_unregister_con_driver(&fb_con);
  3219. console_unlock();
  3220. }
  3221. #endif