fbcon.c 87 KB

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