sisusb_con.c 38 KB

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