fbcon.c 87 KB

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