fbcon.c 88 KB

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