fbcon.c 83 KB

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