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