sisusb_con.c 37 KB

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