fbcon.c 89 KB

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