fbcon.c 73 KB

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