sisusb_con.c 36 KB

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