fbcon.c 88 KB

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