fbcon.c 72 KB

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