fbcon.c 88 KB

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