fbcon.c 87 KB

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