fbcon.c 83 KB

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