fbcon.c 88 KB

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