fbcon.c 89 KB

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