fbcon.c 86 KB

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