fbcon.c 81 KB

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