fbcon.c 87 KB

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