fbcon.c 81 KB

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