fbcon.c 81 KB

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