fbcon.c 88 KB

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