fbcon.c 86 KB

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