fbcon.c 85 KB

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