fbcon.c 82 KB

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