fbcon.c 86 KB

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