fbcon.c 87 KB

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