sisusb_con.c 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657
  1. /*
  2. * sisusb - usb kernel driver for SiS315(E) based USB2VGA dongles
  3. *
  4. * VGA text mode console part
  5. *
  6. * Copyright (C) 2005 by Thomas Winischhofer, Vienna, Austria
  7. *
  8. * If distributed as part of the Linux kernel, this code is licensed under the
  9. * terms of the GPL v2.
  10. *
  11. * Otherwise, the following license terms apply:
  12. *
  13. * * Redistribution and use in source and binary forms, with or without
  14. * * modification, are permitted provided that the following conditions
  15. * * are met:
  16. * * 1) Redistributions of source code must retain the above copyright
  17. * * notice, this list of conditions and the following disclaimer.
  18. * * 2) Redistributions in binary form must reproduce the above copyright
  19. * * notice, this list of conditions and the following disclaimer in the
  20. * * documentation and/or other materials provided with the distribution.
  21. * * 3) The name of the author may not be used to endorse or promote products
  22. * * derived from this software without specific psisusbr written permission.
  23. * *
  24. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESSED OR
  25. * * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  26. * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  27. * * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  28. * * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  29. * * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  30. * * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  31. * * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  32. * * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  33. * * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. * Author: Thomas Winischhofer <thomas@winischhofer.net>
  36. *
  37. * Portions based on vgacon.c which are
  38. * Created 28 Sep 1997 by Geert Uytterhoeven
  39. * Rewritten by Martin Mares <mj@ucw.cz>, July 1998
  40. * based on code Copyright (C) 1991, 1992 Linus Torvalds
  41. * 1995 Jay Estabrook
  42. *
  43. * A note on using in_atomic() in here: We can't handle console
  44. * calls from non-schedulable context due to our USB-dependend
  45. * nature. For now, this driver just ignores any calls if it
  46. * detects this state.
  47. *
  48. */
  49. #include <linux/config.h>
  50. #include <linux/module.h>
  51. #include <linux/kernel.h>
  52. #include <linux/signal.h>
  53. #include <linux/sched.h>
  54. #include <linux/fs.h>
  55. #include <linux/tty.h>
  56. #include <linux/console.h>
  57. #include <linux/string.h>
  58. #include <linux/kd.h>
  59. #include <linux/init.h>
  60. #include <linux/slab.h>
  61. #include <linux/vt_kern.h>
  62. #include <linux/selection.h>
  63. #include <linux/spinlock.h>
  64. #include <linux/kref.h>
  65. #include <linux/smp_lock.h>
  66. #include <linux/ioport.h>
  67. #include <linux/interrupt.h>
  68. #include <linux/vmalloc.h>
  69. #include "sisusb.h"
  70. #ifdef INCL_SISUSB_CON
  71. extern int sisusb_setreg(struct sisusb_usb_data *, int, u8);
  72. extern int sisusb_getreg(struct sisusb_usb_data *, int, u8 *);
  73. extern int sisusb_setidxreg(struct sisusb_usb_data *, int, u8, u8);
  74. extern int sisusb_getidxreg(struct sisusb_usb_data *, int, u8, u8 *);
  75. extern int sisusb_setidxregor(struct sisusb_usb_data *, int, u8, u8);
  76. extern int sisusb_setidxregand(struct sisusb_usb_data *, int, u8, u8);
  77. extern int sisusb_setidxregandor(struct sisusb_usb_data *, int, u8, u8, u8);
  78. extern int sisusb_writeb(struct sisusb_usb_data *sisusb, u32 adr, u8 data);
  79. extern int sisusb_readb(struct sisusb_usb_data *sisusb, u32 adr, u8 *data);
  80. extern int sisusb_writew(struct sisusb_usb_data *sisusb, u32 adr, u16 data);
  81. extern int sisusb_readw(struct sisusb_usb_data *sisusb, u32 adr, u16 *data);
  82. extern int sisusb_copy_memory(struct sisusb_usb_data *sisusb, char *src,
  83. u32 dest, int length, size_t *bytes_written);
  84. extern void sisusb_delete(struct kref *kref);
  85. extern int sisusb_reset_text_mode(struct sisusb_usb_data *sisusb, int init);
  86. extern int SiSUSBSetMode(struct SiS_Private *SiS_Pr, unsigned short ModeNo);
  87. #define sisusbcon_writew(val, addr) (*(addr) = (val))
  88. #define sisusbcon_readw(addr) (*(addr))
  89. #define sisusbcon_memmovew(d, s, c) memmove(d, s, c)
  90. #define sisusbcon_memcpyw(d, s, c) memcpy(d, s, c)
  91. /* vc_data -> sisusb conversion table */
  92. static struct sisusb_usb_data *mysisusbs[MAX_NR_CONSOLES];
  93. /* Forward declaration */
  94. static const struct consw sisusb_con;
  95. extern struct semaphore disconnect_sem;
  96. static inline void
  97. sisusbcon_memsetw(u16 *s, u16 c, unsigned int count)
  98. {
  99. count /= 2;
  100. while (count--)
  101. sisusbcon_writew(c, s++);
  102. }
  103. static inline void
  104. sisusb_initialize(struct sisusb_usb_data *sisusb)
  105. {
  106. /* Reset cursor and start address */
  107. if (sisusb_setidxreg(sisusb, SISCR, 0x0c, 0x00))
  108. return;
  109. if (sisusb_setidxreg(sisusb, SISCR, 0x0d, 0x00))
  110. return;
  111. if (sisusb_setidxreg(sisusb, SISCR, 0x0e, 0x00))
  112. return;
  113. sisusb_setidxreg(sisusb, SISCR, 0x0f, 0x00);
  114. }
  115. static inline void
  116. sisusbcon_set_start_address(struct sisusb_usb_data *sisusb, struct vc_data *c)
  117. {
  118. sisusb->cur_start_addr = (c->vc_visible_origin - sisusb->scrbuf) / 2;
  119. sisusb_setidxreg(sisusb, SISCR, 0x0c, (sisusb->cur_start_addr >> 8));
  120. sisusb_setidxreg(sisusb, SISCR, 0x0d, (sisusb->cur_start_addr & 0xff));
  121. }
  122. void
  123. sisusb_set_cursor(struct sisusb_usb_data *sisusb, unsigned int location)
  124. {
  125. if (sisusb->sisusb_cursor_loc == location)
  126. return;
  127. sisusb->sisusb_cursor_loc = location;
  128. /* Hardware bug: Text cursor appears twice or not at all
  129. * at some positions. Work around it with the cursor skew
  130. * bits.
  131. */
  132. if ((location & 0x0007) == 0x0007) {
  133. sisusb->bad_cursor_pos = 1;
  134. location--;
  135. if (sisusb_setidxregandor(sisusb, SISCR, 0x0b, 0x1f, 0x20))
  136. return;
  137. } else if (sisusb->bad_cursor_pos) {
  138. if (sisusb_setidxregand(sisusb, SISCR, 0x0b, 0x1f))
  139. return;
  140. sisusb->bad_cursor_pos = 0;
  141. }
  142. if (sisusb_setidxreg(sisusb, SISCR, 0x0e, (location >> 8)))
  143. return;
  144. sisusb_setidxreg(sisusb, SISCR, 0x0f, (location & 0xff));
  145. }
  146. static inline struct sisusb_usb_data *
  147. sisusb_get_sisusb(unsigned short console)
  148. {
  149. return mysisusbs[console];
  150. }
  151. static inline int
  152. sisusb_sisusb_valid(struct sisusb_usb_data *sisusb)
  153. {
  154. if (!sisusb->present || !sisusb->ready || !sisusb->sisusb_dev)
  155. return 0;
  156. return 1;
  157. }
  158. static struct sisusb_usb_data *
  159. sisusb_get_sisusb_lock_and_check(unsigned short console)
  160. {
  161. struct sisusb_usb_data *sisusb;
  162. /* We can't handle console calls in non-schedulable
  163. * context due to our locks and the USB transport.
  164. * So we simply ignore them. This should only affect
  165. * some calls to printk.
  166. */
  167. if (in_atomic())
  168. return NULL;
  169. if (!(sisusb = sisusb_get_sisusb(console)))
  170. return NULL;
  171. down(&sisusb->lock);
  172. if (!sisusb_sisusb_valid(sisusb) ||
  173. !sisusb->havethisconsole[console]) {
  174. up(&sisusb->lock);
  175. return NULL;
  176. }
  177. return sisusb;
  178. }
  179. static int
  180. sisusb_is_inactive(struct vc_data *c, struct sisusb_usb_data *sisusb)
  181. {
  182. if (sisusb->is_gfx ||
  183. sisusb->textmodedestroyed ||
  184. c->vc_mode != KD_TEXT)
  185. return 1;
  186. return 0;
  187. }
  188. /* con_startup console interface routine */
  189. static const char *
  190. sisusbcon_startup(void)
  191. {
  192. return "SISUSBCON";
  193. }
  194. /* con_init console interface routine */
  195. static void
  196. sisusbcon_init(struct vc_data *c, int init)
  197. {
  198. struct sisusb_usb_data *sisusb;
  199. int cols, rows;
  200. /* This is called by take_over_console(),
  201. * ie by us/under our control. It is
  202. * only called after text mode and fonts
  203. * are set up/restored.
  204. */
  205. down(&disconnect_sem);
  206. if (!(sisusb = sisusb_get_sisusb(c->vc_num))) {
  207. up(&disconnect_sem);
  208. return;
  209. }
  210. down(&sisusb->lock);
  211. if (!sisusb_sisusb_valid(sisusb)) {
  212. up(&sisusb->lock);
  213. up(&disconnect_sem);
  214. return;
  215. }
  216. c->vc_can_do_color = 1;
  217. c->vc_complement_mask = 0x7700;
  218. c->vc_hi_font_mask = sisusb->current_font_512 ? 0x0800 : 0;
  219. sisusb->haveconsole = 1;
  220. sisusb->havethisconsole[c->vc_num] = 1;
  221. /* We only support 640x400 */
  222. c->vc_scan_lines = 400;
  223. c->vc_font.height = sisusb->current_font_height;
  224. /* We only support width = 8 */
  225. cols = 80;
  226. rows = c->vc_scan_lines / c->vc_font.height;
  227. /* Increment usage count for our sisusb.
  228. * Doing so saves us from upping/downing
  229. * the disconnect semaphore; we can't
  230. * lose our sisusb until this is undone
  231. * in con_deinit. For all other console
  232. * interface functions, it suffices to
  233. * use sisusb->lock and do a quick check
  234. * of sisusb for device disconnection.
  235. */
  236. kref_get(&sisusb->kref);
  237. if (!*c->vc_uni_pagedir_loc)
  238. con_set_default_unimap(c);
  239. up(&sisusb->lock);
  240. up(&disconnect_sem);
  241. if (init) {
  242. c->vc_cols = cols;
  243. c->vc_rows = rows;
  244. } else
  245. vc_resize(c, cols, rows);
  246. }
  247. /* con_deinit console interface routine */
  248. static void
  249. sisusbcon_deinit(struct vc_data *c)
  250. {
  251. struct sisusb_usb_data *sisusb;
  252. int i;
  253. /* This is called by take_over_console()
  254. * and others, ie not under our control.
  255. */
  256. down(&disconnect_sem);
  257. if (!(sisusb = sisusb_get_sisusb(c->vc_num))) {
  258. up(&disconnect_sem);
  259. return;
  260. }
  261. down(&sisusb->lock);
  262. /* Clear ourselves in mysisusbs */
  263. mysisusbs[c->vc_num] = NULL;
  264. sisusb->havethisconsole[c->vc_num] = 0;
  265. /* Free our font buffer if all consoles are gone */
  266. if (sisusb->font_backup) {
  267. for(i = 0; i < MAX_NR_CONSOLES; i++) {
  268. if (sisusb->havethisconsole[c->vc_num])
  269. break;
  270. }
  271. if (i == MAX_NR_CONSOLES) {
  272. vfree(sisusb->font_backup);
  273. sisusb->font_backup = NULL;
  274. }
  275. }
  276. up(&sisusb->lock);
  277. /* decrement the usage count on our sisusb */
  278. kref_put(&sisusb->kref, sisusb_delete);
  279. up(&disconnect_sem);
  280. }
  281. /* interface routine */
  282. static u8
  283. sisusbcon_build_attr(struct vc_data *c, u8 color, u8 intensity,
  284. u8 blink, u8 underline, u8 reverse)
  285. {
  286. u8 attr = color;
  287. if (underline)
  288. attr = (attr & 0xf0) | c->vc_ulcolor;
  289. else if (intensity == 0)
  290. attr = (attr & 0xf0) | c->vc_halfcolor;
  291. if (reverse)
  292. attr = ((attr) & 0x88) |
  293. ((((attr) >> 4) |
  294. ((attr) << 4)) & 0x77);
  295. if (blink)
  296. attr ^= 0x80;
  297. if (intensity == 2)
  298. attr ^= 0x08;
  299. return attr;
  300. }
  301. /* Interface routine */
  302. static void
  303. sisusbcon_invert_region(struct vc_data *vc, u16 *p, int count)
  304. {
  305. /* Invert a region. This is called with a pointer
  306. * to the console's internal screen buffer. So we
  307. * simply do the inversion there and rely on
  308. * a call to putc(s) to update the real screen.
  309. */
  310. while (count--) {
  311. u16 a = sisusbcon_readw(p);
  312. a = ((a) & 0x88ff) |
  313. (((a) & 0x7000) >> 4) |
  314. (((a) & 0x0700) << 4);
  315. sisusbcon_writew(a, p++);
  316. }
  317. }
  318. #define SISUSB_VADDR(x,y) \
  319. ((u16 *)c->vc_origin + \
  320. (y) * sisusb->sisusb_num_columns + \
  321. (x))
  322. #define SISUSB_HADDR(x,y) \
  323. ((u16 *)(sisusb->vrambase + (c->vc_origin - sisusb->scrbuf)) + \
  324. (y) * sisusb->sisusb_num_columns + \
  325. (x))
  326. /* Interface routine */
  327. static void
  328. sisusbcon_putc(struct vc_data *c, int ch, int y, int x)
  329. {
  330. struct sisusb_usb_data *sisusb;
  331. ssize_t written;
  332. if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
  333. return;
  334. /* sisusb->lock is down */
  335. /* Don't need to put the character into buffer ourselves,
  336. * because the vt does this BEFORE calling us.
  337. */
  338. #if 0
  339. sisusbcon_writew(ch, SISUSB_VADDR(x, y));
  340. #endif
  341. if (sisusb_is_inactive(c, sisusb)) {
  342. up(&sisusb->lock);
  343. return;
  344. }
  345. sisusb_copy_memory(sisusb, (char *)SISUSB_VADDR(x, y),
  346. (u32)SISUSB_HADDR(x, y), 2, &written);
  347. up(&sisusb->lock);
  348. }
  349. /* Interface routine */
  350. static void
  351. sisusbcon_putcs(struct vc_data *c, const unsigned short *s,
  352. int count, int y, int x)
  353. {
  354. struct sisusb_usb_data *sisusb;
  355. ssize_t written;
  356. u16 *dest;
  357. int i;
  358. if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
  359. return;
  360. /* sisusb->lock is down */
  361. /* Need to put the characters into the buffer ourselves,
  362. * because the vt does this AFTER calling us.
  363. */
  364. dest = SISUSB_VADDR(x, y);
  365. for (i = count; i > 0; i--)
  366. sisusbcon_writew(sisusbcon_readw(s++), dest++);
  367. if (sisusb_is_inactive(c, sisusb)) {
  368. up(&sisusb->lock);
  369. return;
  370. }
  371. sisusb_copy_memory(sisusb, (char *)SISUSB_VADDR(x, y),
  372. (u32)SISUSB_HADDR(x, y), count * 2, &written);
  373. up(&sisusb->lock);
  374. }
  375. /* Interface routine */
  376. static void
  377. sisusbcon_clear(struct vc_data *c, int y, int x, int height, int width)
  378. {
  379. struct sisusb_usb_data *sisusb;
  380. u16 eattr = c->vc_video_erase_char;
  381. ssize_t written;
  382. int i, length, cols;
  383. u16 *dest;
  384. if (width <= 0 || height <= 0)
  385. return;
  386. if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
  387. return;
  388. /* sisusb->lock is down */
  389. /* Need to clear buffer ourselves, because the vt does
  390. * this AFTER calling us.
  391. */
  392. dest = SISUSB_VADDR(x, y);
  393. cols = sisusb->sisusb_num_columns;
  394. if (width > cols)
  395. width = cols;
  396. if (x == 0 && width >= c->vc_cols) {
  397. sisusbcon_memsetw(dest, eattr, height * cols * 2);
  398. } else {
  399. for (i = height; i > 0; i--, dest += cols)
  400. sisusbcon_memsetw(dest, eattr, width * 2);
  401. }
  402. if (sisusb_is_inactive(c, sisusb)) {
  403. up(&sisusb->lock);
  404. return;
  405. }
  406. length = ((height * cols) - x - (cols - width - x)) * 2;
  407. sisusb_copy_memory(sisusb, (unsigned char *)SISUSB_VADDR(x, y),
  408. (u32)SISUSB_HADDR(x, y), length, &written);
  409. up(&sisusb->lock);
  410. }
  411. /* Interface routine */
  412. static void
  413. sisusbcon_bmove(struct vc_data *c, int sy, int sx,
  414. int dy, int dx, int height, int width)
  415. {
  416. struct sisusb_usb_data *sisusb;
  417. ssize_t written;
  418. int cols, length;
  419. #if 0
  420. u16 *src, *dest;
  421. int i;
  422. #endif
  423. if (width <= 0 || height <= 0)
  424. return;
  425. if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
  426. return;
  427. /* sisusb->lock is down */
  428. cols = sisusb->sisusb_num_columns;
  429. /* Don't need to move data outselves, because
  430. * vt does this BEFORE calling us.
  431. * This is only used by vt's insert/deletechar.
  432. */
  433. #if 0
  434. if (sx == 0 && dx == 0 && width >= c->vc_cols && width <= cols) {
  435. sisusbcon_memmovew(SISUSB_VADDR(0, dy), SISUSB_VADDR(0, sy),
  436. height * width * 2);
  437. } else if (dy < sy || (dy == sy && dx < sx)) {
  438. src = SISUSB_VADDR(sx, sy);
  439. dest = SISUSB_VADDR(dx, dy);
  440. for (i = height; i > 0; i--) {
  441. sisusbcon_memmovew(dest, src, width * 2);
  442. src += cols;
  443. dest += cols;
  444. }
  445. } else {
  446. src = SISUSB_VADDR(sx, sy + height - 1);
  447. dest = SISUSB_VADDR(dx, dy + height - 1);
  448. for (i = height; i > 0; i--) {
  449. sisusbcon_memmovew(dest, src, width * 2);
  450. src -= cols;
  451. dest -= cols;
  452. }
  453. }
  454. #endif
  455. if (sisusb_is_inactive(c, sisusb)) {
  456. up(&sisusb->lock);
  457. return;
  458. }
  459. length = ((height * cols) - dx - (cols - width - dx)) * 2;
  460. sisusb_copy_memory(sisusb, (unsigned char *)SISUSB_VADDR(dx, dy),
  461. (u32)SISUSB_HADDR(dx, dy), length, &written);
  462. up(&sisusb->lock);
  463. }
  464. /* interface routine */
  465. static int
  466. sisusbcon_switch(struct vc_data *c)
  467. {
  468. struct sisusb_usb_data *sisusb;
  469. ssize_t written;
  470. int length;
  471. /* Returnvalue 0 means we have fully restored screen,
  472. * and vt doesn't need to call do_update_region().
  473. * Returnvalue != 0 naturally means the opposite.
  474. */
  475. if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
  476. return 0;
  477. /* sisusb->lock is down */
  478. /* Don't write to screen if in gfx mode */
  479. if (sisusb_is_inactive(c, sisusb)) {
  480. up(&sisusb->lock);
  481. return 0;
  482. }
  483. /* That really should not happen. It would mean we are
  484. * being called while the vc is using its private buffer
  485. * as origin.
  486. */
  487. if (c->vc_origin == (unsigned long)c->vc_screenbuf) {
  488. up(&sisusb->lock);
  489. printk(KERN_DEBUG "sisusb: ASSERT ORIGIN != SCREENBUF!\n");
  490. return 0;
  491. }
  492. /* Check that we don't copy too much */
  493. length = min((int)c->vc_screenbuf_size,
  494. (int)(sisusb->scrbuf + sisusb->scrbuf_size - c->vc_origin));
  495. /* Restore the screen contents */
  496. sisusbcon_memcpyw((u16 *)c->vc_origin, (u16 *)c->vc_screenbuf,
  497. length);
  498. sisusb_copy_memory(sisusb, (unsigned char *)c->vc_origin,
  499. (u32)SISUSB_HADDR(0, 0),
  500. length, &written);
  501. up(&sisusb->lock);
  502. return 0;
  503. }
  504. /* interface routine */
  505. static void
  506. sisusbcon_save_screen(struct vc_data *c)
  507. {
  508. struct sisusb_usb_data *sisusb;
  509. int length;
  510. /* Save the current screen contents to vc's private
  511. * buffer.
  512. */
  513. if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
  514. return;
  515. /* sisusb->lock is down */
  516. if (sisusb_is_inactive(c, sisusb)) {
  517. up(&sisusb->lock);
  518. return;
  519. }
  520. /* Check that we don't copy too much */
  521. length = min((int)c->vc_screenbuf_size,
  522. (int)(sisusb->scrbuf + sisusb->scrbuf_size - c->vc_origin));
  523. /* Save the screen contents to vc's private buffer */
  524. sisusbcon_memcpyw((u16 *)c->vc_screenbuf, (u16 *)c->vc_origin,
  525. length);
  526. up(&sisusb->lock);
  527. }
  528. /* interface routine */
  529. static int
  530. sisusbcon_set_palette(struct vc_data *c, unsigned char *table)
  531. {
  532. struct sisusb_usb_data *sisusb;
  533. int i, j;
  534. /* Return value not used by vt */
  535. if (!CON_IS_VISIBLE(c))
  536. return -EINVAL;
  537. if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
  538. return -EINVAL;
  539. /* sisusb->lock is down */
  540. if (sisusb_is_inactive(c, sisusb)) {
  541. up(&sisusb->lock);
  542. return -EINVAL;
  543. }
  544. for (i = j = 0; i < 16; i++) {
  545. if (sisusb_setreg(sisusb, SISCOLIDX, table[i]))
  546. break;
  547. if (sisusb_setreg(sisusb, SISCOLDATA, c->vc_palette[j++] >> 2))
  548. break;
  549. if (sisusb_setreg(sisusb, SISCOLDATA, c->vc_palette[j++] >> 2))
  550. break;
  551. if (sisusb_setreg(sisusb, SISCOLDATA, c->vc_palette[j++] >> 2))
  552. break;
  553. }
  554. up(&sisusb->lock);
  555. return 0;
  556. }
  557. /* interface routine */
  558. static int
  559. sisusbcon_blank(struct vc_data *c, int blank, int mode_switch)
  560. {
  561. struct sisusb_usb_data *sisusb;
  562. u8 sr1, cr17, pmreg, cr63;
  563. ssize_t written;
  564. int ret = 0;
  565. if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
  566. return 0;
  567. /* sisusb->lock is down */
  568. if (mode_switch)
  569. sisusb->is_gfx = blank ? 1 : 0;
  570. if (sisusb_is_inactive(c, sisusb)) {
  571. up(&sisusb->lock);
  572. return 0;
  573. }
  574. switch (blank) {
  575. case 1: /* Normal blanking: Clear screen */
  576. case -1:
  577. sisusbcon_memsetw((u16 *)c->vc_origin,
  578. c->vc_video_erase_char,
  579. c->vc_screenbuf_size);
  580. sisusb_copy_memory(sisusb,
  581. (unsigned char *)c->vc_origin,
  582. (u32)(sisusb->vrambase +
  583. (c->vc_origin - sisusb->scrbuf)),
  584. c->vc_screenbuf_size, &written);
  585. sisusb->con_blanked = 1;
  586. ret = 1;
  587. break;
  588. default: /* VESA blanking */
  589. switch (blank) {
  590. case 0: /* Unblank */
  591. sr1 = 0x00;
  592. cr17 = 0x80;
  593. pmreg = 0x00;
  594. cr63 = 0x00;
  595. ret = 1;
  596. sisusb->con_blanked = 0;
  597. break;
  598. case VESA_VSYNC_SUSPEND + 1:
  599. sr1 = 0x20;
  600. cr17 = 0x80;
  601. pmreg = 0x80;
  602. cr63 = 0x40;
  603. break;
  604. case VESA_HSYNC_SUSPEND + 1:
  605. sr1 = 0x20;
  606. cr17 = 0x80;
  607. pmreg = 0x40;
  608. cr63 = 0x40;
  609. break;
  610. case VESA_POWERDOWN + 1:
  611. sr1 = 0x20;
  612. cr17 = 0x00;
  613. pmreg = 0xc0;
  614. cr63 = 0x40;
  615. break;
  616. default:
  617. up(&sisusb->lock);
  618. return -EINVAL;
  619. }
  620. sisusb_setidxregandor(sisusb, SISSR, 0x01, ~0x20, sr1);
  621. sisusb_setidxregandor(sisusb, SISCR, 0x17, 0x7f, cr17);
  622. sisusb_setidxregandor(sisusb, SISSR, 0x1f, 0x3f, pmreg);
  623. sisusb_setidxregandor(sisusb, SISCR, 0x63, 0xbf, cr63);
  624. }
  625. up(&sisusb->lock);
  626. return ret;
  627. }
  628. /* interface routine */
  629. static int
  630. sisusbcon_scrolldelta(struct vc_data *c, int lines)
  631. {
  632. struct sisusb_usb_data *sisusb;
  633. int margin = c->vc_size_row * 4;
  634. int ul, we, p, st;
  635. /* The return value does not seem to be used */
  636. if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
  637. return 0;
  638. /* sisusb->lock is down */
  639. if (sisusb_is_inactive(c, sisusb)) {
  640. up(&sisusb->lock);
  641. return 0;
  642. }
  643. if (!lines) /* Turn scrollback off */
  644. c->vc_visible_origin = c->vc_origin;
  645. else {
  646. if (sisusb->con_rolled_over >
  647. (c->vc_scr_end - sisusb->scrbuf) + margin) {
  648. ul = c->vc_scr_end - sisusb->scrbuf;
  649. we = sisusb->con_rolled_over + c->vc_size_row;
  650. } else {
  651. ul = 0;
  652. we = sisusb->scrbuf_size;
  653. }
  654. p = (c->vc_visible_origin - sisusb->scrbuf - ul + we) % we +
  655. lines * c->vc_size_row;
  656. st = (c->vc_origin - sisusb->scrbuf - ul + we) % we;
  657. if (st < 2 * margin)
  658. margin = 0;
  659. if (p < margin)
  660. p = 0;
  661. if (p > st - margin)
  662. p = st;
  663. c->vc_visible_origin = sisusb->scrbuf + (p + ul) % we;
  664. }
  665. sisusbcon_set_start_address(sisusb, c);
  666. up(&sisusb->lock);
  667. return 1;
  668. }
  669. /* Interface routine */
  670. static void
  671. sisusbcon_cursor(struct vc_data *c, int mode)
  672. {
  673. struct sisusb_usb_data *sisusb;
  674. int from, to, baseline;
  675. if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
  676. return;
  677. /* sisusb->lock is down */
  678. if (sisusb_is_inactive(c, sisusb)) {
  679. up(&sisusb->lock);
  680. return;
  681. }
  682. if (c->vc_origin != c->vc_visible_origin) {
  683. c->vc_visible_origin = c->vc_origin;
  684. sisusbcon_set_start_address(sisusb, c);
  685. }
  686. if (mode == CM_ERASE) {
  687. sisusb_setidxregor(sisusb, SISCR, 0x0a, 0x20);
  688. sisusb->sisusb_cursor_size_to = -1;
  689. up(&sisusb->lock);
  690. return;
  691. }
  692. sisusb_set_cursor(sisusb, (c->vc_pos - sisusb->scrbuf) / 2);
  693. baseline = c->vc_font.height - (c->vc_font.height < 10 ? 1 : 2);
  694. switch (c->vc_cursor_type & 0x0f) {
  695. case CUR_BLOCK: from = 1;
  696. to = c->vc_font.height;
  697. break;
  698. case CUR_TWO_THIRDS: from = c->vc_font.height / 3;
  699. to = baseline;
  700. break;
  701. case CUR_LOWER_HALF: from = c->vc_font.height / 2;
  702. to = baseline;
  703. break;
  704. case CUR_LOWER_THIRD: from = (c->vc_font.height * 2) / 3;
  705. to = baseline;
  706. break;
  707. case CUR_NONE: from = 31;
  708. to = 30;
  709. break;
  710. default:
  711. case CUR_UNDERLINE: from = baseline - 1;
  712. to = baseline;
  713. break;
  714. }
  715. if (sisusb->sisusb_cursor_size_from != from ||
  716. sisusb->sisusb_cursor_size_to != to) {
  717. sisusb_setidxreg(sisusb, SISCR, 0x0a, from);
  718. sisusb_setidxregandor(sisusb, SISCR, 0x0b, 0xe0, to);
  719. sisusb->sisusb_cursor_size_from = from;
  720. sisusb->sisusb_cursor_size_to = to;
  721. }
  722. up(&sisusb->lock);
  723. }
  724. static int
  725. sisusbcon_scroll_area(struct vc_data *c, struct sisusb_usb_data *sisusb,
  726. int t, int b, int dir, int lines)
  727. {
  728. int cols = sisusb->sisusb_num_columns;
  729. int length = ((b - t) * cols) * 2;
  730. u16 eattr = c->vc_video_erase_char;
  731. ssize_t written;
  732. /* sisusb->lock is down */
  733. /* Scroll an area which does not match the
  734. * visible screen's dimensions. This needs
  735. * to be done separately, as it does not
  736. * use hardware panning.
  737. */
  738. switch (dir) {
  739. case SM_UP:
  740. sisusbcon_memmovew(SISUSB_VADDR(0, t),
  741. SISUSB_VADDR(0, t + lines),
  742. (b - t - lines) * cols * 2);
  743. sisusbcon_memsetw(SISUSB_VADDR(0, b - lines), eattr,
  744. lines * cols * 2);
  745. break;
  746. case SM_DOWN:
  747. sisusbcon_memmovew(SISUSB_VADDR(0, t + lines),
  748. SISUSB_VADDR(0, t),
  749. (b - t - lines) * cols * 2);
  750. sisusbcon_memsetw(SISUSB_VADDR(0, t), eattr,
  751. lines * cols * 2);
  752. break;
  753. }
  754. sisusb_copy_memory(sisusb, (char *)SISUSB_VADDR(0, t),
  755. (u32)SISUSB_HADDR(0, t), length, &written);
  756. up(&sisusb->lock);
  757. return 1;
  758. }
  759. /* Interface routine */
  760. static int
  761. sisusbcon_scroll(struct vc_data *c, int t, int b, int dir, int lines)
  762. {
  763. struct sisusb_usb_data *sisusb;
  764. u16 eattr = c->vc_video_erase_char;
  765. ssize_t written;
  766. int copyall = 0;
  767. unsigned long oldorigin;
  768. unsigned int delta = lines * c->vc_size_row;
  769. u32 originoffset;
  770. /* Returning != 0 means we have done the scrolling successfully.
  771. * Returning 0 makes vt do the scrolling on its own.
  772. * Note that con_scroll is only called if the console is
  773. * visible. In that case, the origin should be our buffer,
  774. * not the vt's private one.
  775. */
  776. if (!lines)
  777. return 1;
  778. if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
  779. return 0;
  780. /* sisusb->lock is down */
  781. if (sisusb_is_inactive(c, sisusb)) {
  782. up(&sisusb->lock);
  783. return 0;
  784. }
  785. /* Special case */
  786. if (t || b != c->vc_rows)
  787. return sisusbcon_scroll_area(c, sisusb, t, b, dir, lines);
  788. if (c->vc_origin != c->vc_visible_origin) {
  789. c->vc_visible_origin = c->vc_origin;
  790. sisusbcon_set_start_address(sisusb, c);
  791. }
  792. /* limit amount to maximum realistic size */
  793. if (lines > c->vc_rows)
  794. lines = c->vc_rows;
  795. oldorigin = c->vc_origin;
  796. switch (dir) {
  797. case SM_UP:
  798. if (c->vc_scr_end + delta >=
  799. sisusb->scrbuf + sisusb->scrbuf_size) {
  800. sisusbcon_memcpyw((u16 *)sisusb->scrbuf,
  801. (u16 *)(oldorigin + delta),
  802. c->vc_screenbuf_size - delta);
  803. c->vc_origin = sisusb->scrbuf;
  804. sisusb->con_rolled_over = oldorigin - sisusb->scrbuf;
  805. copyall = 1;
  806. } else
  807. c->vc_origin += delta;
  808. sisusbcon_memsetw(
  809. (u16 *)(c->vc_origin + c->vc_screenbuf_size - delta),
  810. eattr, delta);
  811. break;
  812. case SM_DOWN:
  813. if (oldorigin - delta < sisusb->scrbuf) {
  814. sisusbcon_memmovew((u16 *)(sisusb->scrbuf +
  815. sisusb->scrbuf_size -
  816. c->vc_screenbuf_size +
  817. delta),
  818. (u16 *)oldorigin,
  819. c->vc_screenbuf_size - delta);
  820. c->vc_origin = sisusb->scrbuf +
  821. sisusb->scrbuf_size -
  822. c->vc_screenbuf_size;
  823. sisusb->con_rolled_over = 0;
  824. copyall = 1;
  825. } else
  826. c->vc_origin -= delta;
  827. c->vc_scr_end = c->vc_origin + c->vc_screenbuf_size;
  828. scr_memsetw((u16 *)(c->vc_origin), eattr, delta);
  829. break;
  830. }
  831. originoffset = (u32)(c->vc_origin - sisusb->scrbuf);
  832. if (copyall)
  833. sisusb_copy_memory(sisusb,
  834. (char *)c->vc_origin,
  835. (u32)(sisusb->vrambase + originoffset),
  836. c->vc_screenbuf_size, &written);
  837. else if (dir == SM_UP)
  838. sisusb_copy_memory(sisusb,
  839. (char *)c->vc_origin + c->vc_screenbuf_size - delta,
  840. (u32)sisusb->vrambase + originoffset +
  841. c->vc_screenbuf_size - delta,
  842. delta, &written);
  843. else
  844. sisusb_copy_memory(sisusb,
  845. (char *)c->vc_origin,
  846. (u32)(sisusb->vrambase + originoffset),
  847. delta, &written);
  848. c->vc_scr_end = c->vc_origin + c->vc_screenbuf_size;
  849. c->vc_visible_origin = c->vc_origin;
  850. sisusbcon_set_start_address(sisusb, c);
  851. c->vc_pos = c->vc_pos - oldorigin + c->vc_origin;
  852. up(&sisusb->lock);
  853. return 1;
  854. }
  855. /* Interface routine */
  856. static int
  857. sisusbcon_set_origin(struct vc_data *c)
  858. {
  859. struct sisusb_usb_data *sisusb;
  860. /* Returning != 0 means we were successful.
  861. * Returning 0 will vt make to use its own
  862. * screenbuffer as the origin.
  863. */
  864. if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
  865. return 0;
  866. /* sisusb->lock is down */
  867. if (sisusb_is_inactive(c, sisusb) || sisusb->con_blanked) {
  868. up(&sisusb->lock);
  869. return 0;
  870. }
  871. c->vc_origin = c->vc_visible_origin = sisusb->scrbuf;
  872. sisusbcon_set_start_address(sisusb, c);
  873. sisusb->con_rolled_over = 0;
  874. up(&sisusb->lock);
  875. return 1;
  876. }
  877. /* Interface routine */
  878. static int
  879. sisusbcon_resize(struct vc_data *c, unsigned int newcols, unsigned int newrows)
  880. {
  881. struct sisusb_usb_data *sisusb;
  882. int fh;
  883. if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
  884. return -ENODEV;
  885. fh = sisusb->current_font_height;
  886. up(&sisusb->lock);
  887. /* We are quite unflexible as regards resizing. The vt code
  888. * handles sizes where the line length isn't equal the pitch
  889. * quite badly. As regards the rows, our panning tricks only
  890. * work well if the number of rows equals the visible number
  891. * of rows.
  892. */
  893. if (newcols != 80 || c->vc_scan_lines / fh != newrows)
  894. return -EINVAL;
  895. return 0;
  896. }
  897. int
  898. sisusbcon_do_font_op(struct sisusb_usb_data *sisusb, int set, int slot,
  899. u8 *arg, int cmapsz, int ch512, int dorecalc,
  900. struct vc_data *c, int fh, int uplock)
  901. {
  902. int font_select = 0x00, i, err = 0;
  903. u32 offset = 0;
  904. u8 dummy;
  905. /* sisusb->lock is down */
  906. /*
  907. * The default font is kept in slot 0.
  908. * A user font is loaded in slot 2 (256 ch)
  909. * or 2+3 (512 ch).
  910. */
  911. if ((slot != 0 && slot != 2) || !fh) {
  912. if (uplock)
  913. up(&sisusb->lock);
  914. return -EINVAL;
  915. }
  916. if (set)
  917. sisusb->font_slot = slot;
  918. /* Default font is always 256 */
  919. if (slot == 0)
  920. ch512 = 0;
  921. else
  922. offset = 4 * cmapsz;
  923. font_select = (slot == 0) ? 0x00 : (ch512 ? 0x0e : 0x0a);
  924. err |= sisusb_setidxreg(sisusb, SISSR, 0x00, 0x01); /* Reset */
  925. err |= sisusb_setidxreg(sisusb, SISSR, 0x02, 0x04); /* Write to plane 2 */
  926. err |= sisusb_setidxreg(sisusb, SISSR, 0x04, 0x07); /* Memory mode a0-bf */
  927. err |= sisusb_setidxreg(sisusb, SISSR, 0x00, 0x03); /* Reset */
  928. if (err)
  929. goto font_op_error;
  930. err |= sisusb_setidxreg(sisusb, SISGR, 0x04, 0x03); /* Select plane read 2 */
  931. err |= sisusb_setidxreg(sisusb, SISGR, 0x05, 0x00); /* Disable odd/even */
  932. err |= sisusb_setidxreg(sisusb, SISGR, 0x06, 0x00); /* Address range a0-bf */
  933. if (err)
  934. goto font_op_error;
  935. if (arg) {
  936. if (set)
  937. for (i = 0; i < cmapsz; i++) {
  938. err |= sisusb_writeb(sisusb,
  939. sisusb->vrambase + offset + i,
  940. arg[i]);
  941. if (err)
  942. break;
  943. }
  944. else
  945. for (i = 0; i < cmapsz; i++) {
  946. err |= sisusb_readb(sisusb,
  947. sisusb->vrambase + offset + i,
  948. &arg[i]);
  949. if (err)
  950. break;
  951. }
  952. /*
  953. * In 512-character mode, the character map is not contiguous if
  954. * we want to remain EGA compatible -- which we do
  955. */
  956. if (ch512) {
  957. if (set)
  958. for (i = 0; i < cmapsz; i++) {
  959. err |= sisusb_writeb(sisusb,
  960. sisusb->vrambase + offset +
  961. (2 * cmapsz) + i,
  962. arg[cmapsz + i]);
  963. if (err)
  964. break;
  965. }
  966. else
  967. for (i = 0; i < cmapsz; i++) {
  968. err |= sisusb_readb(sisusb,
  969. sisusb->vrambase + offset +
  970. (2 * cmapsz) + i,
  971. &arg[cmapsz + i]);
  972. if (err)
  973. break;
  974. }
  975. }
  976. }
  977. if (err)
  978. goto font_op_error;
  979. err |= sisusb_setidxreg(sisusb, SISSR, 0x00, 0x01); /* Reset */
  980. err |= sisusb_setidxreg(sisusb, SISSR, 0x02, 0x03); /* Write to planes 0+1 */
  981. err |= sisusb_setidxreg(sisusb, SISSR, 0x04, 0x03); /* Memory mode a0-bf */
  982. if (set)
  983. sisusb_setidxreg(sisusb, SISSR, 0x03, font_select);
  984. err |= sisusb_setidxreg(sisusb, SISSR, 0x00, 0x03); /* Reset end */
  985. if (err)
  986. goto font_op_error;
  987. err |= sisusb_setidxreg(sisusb, SISGR, 0x04, 0x00); /* Select plane read 0 */
  988. err |= sisusb_setidxreg(sisusb, SISGR, 0x05, 0x10); /* Enable odd/even */
  989. err |= sisusb_setidxreg(sisusb, SISGR, 0x06, 0x06); /* Address range b8-bf */
  990. if (err)
  991. goto font_op_error;
  992. if ((set) && (ch512 != sisusb->current_font_512)) {
  993. /* Font is shared among all our consoles.
  994. * And so is the hi_font_mask.
  995. */
  996. for (i = 0; i < MAX_NR_CONSOLES; i++) {
  997. struct vc_data *c = vc_cons[i].d;
  998. if (c && c->vc_sw == &sisusb_con)
  999. c->vc_hi_font_mask = ch512 ? 0x0800 : 0;
  1000. }
  1001. sisusb->current_font_512 = ch512;
  1002. /* color plane enable register:
  1003. 256-char: enable intensity bit
  1004. 512-char: disable intensity bit */
  1005. sisusb_getreg(sisusb, SISINPSTAT, &dummy);
  1006. sisusb_setreg(sisusb, SISAR, 0x12);
  1007. sisusb_setreg(sisusb, SISAR, ch512 ? 0x07 : 0x0f);
  1008. sisusb_getreg(sisusb, SISINPSTAT, &dummy);
  1009. sisusb_setreg(sisusb, SISAR, 0x20);
  1010. sisusb_getreg(sisusb, SISINPSTAT, &dummy);
  1011. }
  1012. if (dorecalc) {
  1013. /*
  1014. * Adjust the screen to fit a font of a certain height
  1015. */
  1016. unsigned char ovr, vde, fsr;
  1017. int rows = 0, maxscan = 0;
  1018. if (c) {
  1019. /* Number of video rows */
  1020. rows = c->vc_scan_lines / fh;
  1021. /* Scan lines to actually display-1 */
  1022. maxscan = rows * fh - 1;
  1023. /*printk(KERN_DEBUG "sisusb recalc rows %d maxscan %d fh %d sl %d\n",
  1024. rows, maxscan, fh, c->vc_scan_lines);*/
  1025. sisusb_getidxreg(sisusb, SISCR, 0x07, &ovr);
  1026. vde = maxscan & 0xff;
  1027. ovr = (ovr & 0xbd) |
  1028. ((maxscan & 0x100) >> 7) |
  1029. ((maxscan & 0x200) >> 3);
  1030. sisusb_setidxreg(sisusb, SISCR, 0x07, ovr);
  1031. sisusb_setidxreg(sisusb, SISCR, 0x12, vde);
  1032. }
  1033. sisusb_getidxreg(sisusb, SISCR, 0x09, &fsr);
  1034. fsr = (fsr & 0xe0) | (fh - 1);
  1035. sisusb_setidxreg(sisusb, SISCR, 0x09, fsr);
  1036. sisusb->current_font_height = fh;
  1037. sisusb->sisusb_cursor_size_from = -1;
  1038. sisusb->sisusb_cursor_size_to = -1;
  1039. }
  1040. if (uplock)
  1041. up(&sisusb->lock);
  1042. if (dorecalc && c) {
  1043. int i, rows = c->vc_scan_lines / fh;
  1044. /* Now adjust our consoles' size */
  1045. for (i = 0; i < MAX_NR_CONSOLES; i++) {
  1046. struct vc_data *vc = vc_cons[i].d;
  1047. if (vc && vc->vc_sw == &sisusb_con) {
  1048. if (CON_IS_VISIBLE(vc)) {
  1049. vc->vc_sw->con_cursor(vc, CM_DRAW);
  1050. }
  1051. vc->vc_font.height = fh;
  1052. vc_resize(vc, 0, rows);
  1053. }
  1054. }
  1055. }
  1056. return 0;
  1057. font_op_error:
  1058. if (uplock)
  1059. up(&sisusb->lock);
  1060. return -EIO;
  1061. }
  1062. /* Interface routine */
  1063. static int
  1064. sisusbcon_font_set(struct vc_data *c, struct console_font *font,
  1065. unsigned flags)
  1066. {
  1067. struct sisusb_usb_data *sisusb;
  1068. unsigned charcount = font->charcount;
  1069. if (font->width != 8 || (charcount != 256 && charcount != 512))
  1070. return -EINVAL;
  1071. if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
  1072. return -ENODEV;
  1073. /* sisusb->lock is down */
  1074. /* Save the user-provided font into a buffer. This
  1075. * is used for restoring text mode after quitting
  1076. * from X and for the con_getfont routine.
  1077. */
  1078. if (sisusb->font_backup) {
  1079. if (sisusb->font_backup_size < charcount) {
  1080. vfree(sisusb->font_backup);
  1081. sisusb->font_backup = NULL;
  1082. }
  1083. }
  1084. if (!sisusb->font_backup)
  1085. sisusb->font_backup = vmalloc(charcount * 32);
  1086. if (sisusb->font_backup) {
  1087. memcpy(sisusb->font_backup, font->data, charcount * 32);
  1088. sisusb->font_backup_size = charcount;
  1089. sisusb->font_backup_height = font->height;
  1090. sisusb->font_backup_512 = (charcount == 512) ? 1 : 0;
  1091. }
  1092. /* do_font_op ups sisusb->lock */
  1093. return sisusbcon_do_font_op(sisusb, 1, 2, font->data,
  1094. 8192, (charcount == 512),
  1095. (!(flags & KD_FONT_FLAG_DONT_RECALC)) ? 1 : 0,
  1096. c, font->height, 1);
  1097. }
  1098. /* Interface routine */
  1099. static int
  1100. sisusbcon_font_get(struct vc_data *c, struct console_font *font)
  1101. {
  1102. struct sisusb_usb_data *sisusb;
  1103. if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
  1104. return -ENODEV;
  1105. /* sisusb->lock is down */
  1106. font->width = 8;
  1107. font->height = c->vc_font.height;
  1108. font->charcount = 256;
  1109. if (!font->data) {
  1110. up(&sisusb->lock);
  1111. return 0;
  1112. }
  1113. if (!sisusb->font_backup) {
  1114. up(&sisusb->lock);
  1115. return -ENODEV;
  1116. }
  1117. /* Copy 256 chars only, like vgacon */
  1118. memcpy(font->data, sisusb->font_backup, 256 * 32);
  1119. up(&sisusb->lock);
  1120. return 0;
  1121. }
  1122. /*
  1123. * The console `switch' structure for the sisusb console
  1124. */
  1125. static const struct consw sisusb_con = {
  1126. .owner = THIS_MODULE,
  1127. .con_startup = sisusbcon_startup,
  1128. .con_init = sisusbcon_init,
  1129. .con_deinit = sisusbcon_deinit,
  1130. .con_clear = sisusbcon_clear,
  1131. .con_putc = sisusbcon_putc,
  1132. .con_putcs = sisusbcon_putcs,
  1133. .con_cursor = sisusbcon_cursor,
  1134. .con_scroll = sisusbcon_scroll,
  1135. .con_bmove = sisusbcon_bmove,
  1136. .con_switch = sisusbcon_switch,
  1137. .con_blank = sisusbcon_blank,
  1138. .con_font_set = sisusbcon_font_set,
  1139. .con_font_get = sisusbcon_font_get,
  1140. .con_set_palette = sisusbcon_set_palette,
  1141. .con_scrolldelta = sisusbcon_scrolldelta,
  1142. .con_build_attr = sisusbcon_build_attr,
  1143. .con_invert_region = sisusbcon_invert_region,
  1144. .con_set_origin = sisusbcon_set_origin,
  1145. .con_save_screen = sisusbcon_save_screen,
  1146. .con_resize = sisusbcon_resize,
  1147. };
  1148. /* Our very own dummy console driver */
  1149. static const char *sisusbdummycon_startup(void)
  1150. {
  1151. return "SISUSBVGADUMMY";
  1152. }
  1153. static void sisusbdummycon_init(struct vc_data *vc, int init)
  1154. {
  1155. vc->vc_can_do_color = 1;
  1156. if (init) {
  1157. vc->vc_cols = 80;
  1158. vc->vc_rows = 25;
  1159. } else
  1160. vc_resize(vc, 80, 25);
  1161. }
  1162. static int sisusbdummycon_dummy(void)
  1163. {
  1164. return 0;
  1165. }
  1166. #define SISUSBCONDUMMY (void *)sisusbdummycon_dummy
  1167. const struct consw sisusb_dummy_con = {
  1168. .owner = THIS_MODULE,
  1169. .con_startup = sisusbdummycon_startup,
  1170. .con_init = sisusbdummycon_init,
  1171. .con_deinit = SISUSBCONDUMMY,
  1172. .con_clear = SISUSBCONDUMMY,
  1173. .con_putc = SISUSBCONDUMMY,
  1174. .con_putcs = SISUSBCONDUMMY,
  1175. .con_cursor = SISUSBCONDUMMY,
  1176. .con_scroll = SISUSBCONDUMMY,
  1177. .con_bmove = SISUSBCONDUMMY,
  1178. .con_switch = SISUSBCONDUMMY,
  1179. .con_blank = SISUSBCONDUMMY,
  1180. .con_font_set = SISUSBCONDUMMY,
  1181. .con_font_get = SISUSBCONDUMMY,
  1182. .con_font_default = SISUSBCONDUMMY,
  1183. .con_font_copy = SISUSBCONDUMMY,
  1184. .con_set_palette = SISUSBCONDUMMY,
  1185. .con_scrolldelta = SISUSBCONDUMMY,
  1186. };
  1187. int
  1188. sisusb_console_init(struct sisusb_usb_data *sisusb, int first, int last)
  1189. {
  1190. int i, ret, minor = sisusb->minor;
  1191. down(&disconnect_sem);
  1192. down(&sisusb->lock);
  1193. /* Erm.. that should not happen */
  1194. if (sisusb->haveconsole || !sisusb->SiS_Pr) {
  1195. up(&sisusb->lock);
  1196. up(&disconnect_sem);
  1197. return 1;
  1198. }
  1199. sisusb->con_first = first;
  1200. sisusb->con_last = last;
  1201. if (first > last ||
  1202. first > MAX_NR_CONSOLES ||
  1203. last > MAX_NR_CONSOLES) {
  1204. up(&sisusb->lock);
  1205. up(&disconnect_sem);
  1206. return 1;
  1207. }
  1208. /* If gfxcore not initialized or no consoles given, quit graciously */
  1209. if (!sisusb->gfxinit || first < 1 || last < 1) {
  1210. up(&sisusb->lock);
  1211. up(&disconnect_sem);
  1212. return 0;
  1213. }
  1214. sisusb->sisusb_cursor_loc = -1;
  1215. sisusb->sisusb_cursor_size_from = -1;
  1216. sisusb->sisusb_cursor_size_to = -1;
  1217. /* Set up text mode (and upload default font) */
  1218. if (sisusb_reset_text_mode(sisusb, 1)) {
  1219. up(&sisusb->lock);
  1220. up(&disconnect_sem);
  1221. printk(KERN_ERR
  1222. "sisusbvga[%d]: Failed to set up text mode\n",
  1223. minor);
  1224. return 1;
  1225. }
  1226. /* Initialize some gfx registers */
  1227. sisusb_initialize(sisusb);
  1228. for (i = first - 1; i <= last - 1; i++) {
  1229. /* Save sisusb for our interface routines */
  1230. mysisusbs[i] = sisusb;
  1231. }
  1232. /* Initial console setup */
  1233. sisusb->sisusb_num_columns = 80;
  1234. /* Use a 32K buffer (matches b8000-bffff area) */
  1235. sisusb->scrbuf_size = 32 * 1024;
  1236. /* Allocate screen buffer */
  1237. if (!(sisusb->scrbuf = (unsigned long)vmalloc(sisusb->scrbuf_size))) {
  1238. up(&sisusb->lock);
  1239. up(&disconnect_sem);
  1240. printk(KERN_ERR
  1241. "sisusbvga[%d]: Failed to allocate screen buffer\n",
  1242. minor);
  1243. return 1;
  1244. }
  1245. up(&sisusb->lock);
  1246. up(&disconnect_sem);
  1247. /* Now grab the desired console(s) */
  1248. ret = take_over_console(&sisusb_con, first - 1, last - 1, 0);
  1249. if (!ret)
  1250. sisusb->haveconsole = 1;
  1251. else {
  1252. for (i = first - 1; i <= last - 1; i++)
  1253. mysisusbs[i] = NULL;
  1254. }
  1255. return ret;
  1256. }
  1257. void
  1258. sisusb_console_exit(struct sisusb_usb_data *sisusb)
  1259. {
  1260. int i;
  1261. /* This is called if the device is disconnected
  1262. * and while disconnect and lock semaphores
  1263. * are up. This should be save because we
  1264. * can't lose our sisusb any other way but by
  1265. * disconnection (and hence, the disconnect
  1266. * sema is for protecting all other access
  1267. * functions from disconnection, not the
  1268. * other way round).
  1269. */
  1270. /* Now what do we do in case of disconnection:
  1271. * One alternative would be to simply call
  1272. * give_up_console(). Nah, not a good idea.
  1273. * give_up_console() is obviously buggy as it
  1274. * only discards the consw pointer from the
  1275. * driver_map, but doesn't adapt vc->vc_sw
  1276. * of the affected consoles. Hence, the next
  1277. * call to any of the console functions will
  1278. * eventually take a trip to oops county.
  1279. * Also, give_up_console for some reason
  1280. * doesn't decrement our module refcount.
  1281. * Instead, we switch our consoles to a private
  1282. * dummy console. This, of course, keeps our
  1283. * refcount up as well, but it works perfectly.
  1284. */
  1285. if (sisusb->haveconsole) {
  1286. for (i = 0; i < MAX_NR_CONSOLES; i++)
  1287. if (sisusb->havethisconsole[i])
  1288. take_over_console(&sisusb_dummy_con, i, i, 0);
  1289. /* At this point, con_deinit for all our
  1290. * consoles is executed by take_over_console().
  1291. */
  1292. sisusb->haveconsole = 0;
  1293. }
  1294. vfree((void *)sisusb->scrbuf);
  1295. sisusb->scrbuf = 0;
  1296. vfree(sisusb->font_backup);
  1297. sisusb->font_backup = NULL;
  1298. }
  1299. void __init sisusb_init_concode(void)
  1300. {
  1301. int i;
  1302. for (i = 0; i < MAX_NR_CONSOLES; i++)
  1303. mysisusbs[i] = NULL;
  1304. }
  1305. #endif /* INCL_CON */