fbcon.c 88 KB

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