fbcon.c 72 KB

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