fbcon.c 71 KB

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