fbcon.c 88 KB

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