fbcon.c 72 KB

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