fbcon.c 72 KB

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