fbcon.c 88 KB

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