fbcon.c 87 KB

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