fbcon.c 71 KB

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