fbcon.c 76 KB

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