fbcon.c 81 KB

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