fbcon.c 87 KB

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