fbcon.c 87 KB

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