fbcon.c 78 KB

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