sisusb_con.c 37 KB

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