fbcon.c 70 KB

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