fbcon.c 74 KB

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