fbcon.c 81 KB

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