sis_accel.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * SiS 300/540/630[S]/730[S],
  4. * SiS 315[E|PRO]/550/[M]650/651/[M]661[F|M]X/740/[M]741[GX]/330/[M]760[GX],
  5. * XGI V3XT/V5/V8, Z7
  6. * frame buffer driver for Linux kernels >= 2.4.14 and >=2.6.3
  7. *
  8. * 2D acceleration part
  9. *
  10. * Based on the X driver's sis300_accel.h which is
  11. * Copyright (C) 2001-2004 by Thomas Winischhofer, Vienna, Austria
  12. * and sis310_accel.h which is
  13. * Copyright (C) 2001-2004 by Thomas Winischhofer, Vienna, Austria
  14. *
  15. * Author: Thomas Winischhofer <thomas@winischhofer.net>:
  16. * (see http://www.winischhofer.net/
  17. * for more information and updates)
  18. */
  19. #ifndef _SISFB_ACCEL_H
  20. #define _SISFB_ACCEL_H
  21. /* Guard accelerator accesses with spin_lock_irqsave? Works well without. */
  22. #undef SISFB_USE_SPINLOCKS
  23. #ifdef SISFB_USE_SPINLOCKS
  24. #include <linux/spinlock.h>
  25. #define CRITBEGIN spin_lock_irqsave(&ivideo->lockaccel, critflags);
  26. #define CRITEND spin_unlock_irqrestore(&ivideo->lockaccel, critflags);
  27. #define CRITFLAGS unsigned long critflags;
  28. #else
  29. #define CRITBEGIN
  30. #define CRITEND
  31. #define CRITFLAGS
  32. #endif
  33. /* Definitions for the SIS engine communication. */
  34. #define PATREGSIZE 384 /* Pattern register size. 384 bytes @ 0x8300 */
  35. #define BR(x) (0x8200 | (x) << 2)
  36. #define PBR(x) (0x8300 | (x) << 2)
  37. /* SiS300 engine commands */
  38. #define BITBLT 0x00000000 /* Blit */
  39. #define COLOREXP 0x00000001 /* Color expand */
  40. #define ENCOLOREXP 0x00000002 /* Enhanced color expand */
  41. #define MULTIPLE_SCANLINE 0x00000003 /* ? */
  42. #define LINE 0x00000004 /* Draw line */
  43. #define TRAPAZOID_FILL 0x00000005 /* Fill trapezoid */
  44. #define TRANSPARENT_BITBLT 0x00000006 /* Transparent Blit */
  45. /* Additional engine commands for 315 */
  46. #define ALPHA_BLEND 0x00000007 /* Alpha blend ? */
  47. #define A3D_FUNCTION 0x00000008 /* 3D command ? */
  48. #define CLEAR_Z_BUFFER 0x00000009 /* ? */
  49. #define GRADIENT_FILL 0x0000000A /* Gradient fill */
  50. /* source select */
  51. #define SRCVIDEO 0x00000000 /* source is video RAM */
  52. #define SRCSYSTEM 0x00000010 /* source is system memory */
  53. #define SRCCPUBLITBUF SRCSYSTEM /* source is CPU-driven BitBuffer (for color expand) */
  54. #define SRCAGP 0x00000020 /* source is AGP memory (?) */
  55. /* Pattern flags */
  56. #define PATFG 0x00000000 /* foreground color */
  57. #define PATPATREG 0x00000040 /* pattern in pattern buffer (0x8300) */
  58. #define PATMONO 0x00000080 /* mono pattern */
  59. /* blitting direction (300 series only) */
  60. #define X_INC 0x00010000
  61. #define X_DEC 0x00000000
  62. #define Y_INC 0x00020000
  63. #define Y_DEC 0x00000000
  64. /* Clipping flags */
  65. #define NOCLIP 0x00000000
  66. #define NOMERGECLIP 0x04000000
  67. #define CLIPENABLE 0x00040000
  68. #define CLIPWITHOUTMERGE 0x04040000
  69. /* Transparency */
  70. #define OPAQUE 0x00000000
  71. #define TRANSPARENT 0x00100000
  72. /* ? */
  73. #define DSTAGP 0x02000000
  74. #define DSTVIDEO 0x02000000
  75. /* Subfunctions for Color/Enhanced Color Expansion (315 only) */
  76. #define COLOR_TO_MONO 0x00100000
  77. #define AA_TEXT 0x00200000
  78. /* Some general registers for 315 series */
  79. #define SRC_ADDR 0x8200
  80. #define SRC_PITCH 0x8204
  81. #define AGP_BASE 0x8206 /* color-depth dependent value */
  82. #define SRC_Y 0x8208
  83. #define SRC_X 0x820A
  84. #define DST_Y 0x820C
  85. #define DST_X 0x820E
  86. #define DST_ADDR 0x8210
  87. #define DST_PITCH 0x8214
  88. #define DST_HEIGHT 0x8216
  89. #define RECT_WIDTH 0x8218
  90. #define RECT_HEIGHT 0x821A
  91. #define PAT_FGCOLOR 0x821C
  92. #define PAT_BGCOLOR 0x8220
  93. #define SRC_FGCOLOR 0x8224
  94. #define SRC_BGCOLOR 0x8228
  95. #define MONO_MASK 0x822C
  96. #define LEFT_CLIP 0x8234
  97. #define TOP_CLIP 0x8236
  98. #define RIGHT_CLIP 0x8238
  99. #define BOTTOM_CLIP 0x823A
  100. #define COMMAND_READY 0x823C
  101. #define FIRE_TRIGGER 0x8240
  102. #define PATTERN_REG 0x8300 /* 384 bytes pattern buffer */
  103. /* Transparent bitblit registers */
  104. #define TRANS_DST_KEY_HIGH PAT_FGCOLOR
  105. #define TRANS_DST_KEY_LOW PAT_BGCOLOR
  106. #define TRANS_SRC_KEY_HIGH SRC_FGCOLOR
  107. #define TRANS_SRC_KEY_LOW SRC_BGCOLOR
  108. /* Store queue length in par */
  109. #define CmdQueLen ivideo->cmdqueuelength
  110. /* ------------- SiS 300 series -------------- */
  111. /* BR(16) (0x8240):
  112. bit 31 2D engine: 1 is idle,
  113. bit 30 3D engine: 1 is idle,
  114. bit 29 Command queue: 1 is empty
  115. bits 28:24: Current CPU driven BitBlt buffer stage bit[4:0]
  116. bits 15:0: Current command queue length
  117. */
  118. #define SiS300Idle \
  119. { \
  120. while((MMIO_IN16(ivideo->mmio_vbase, BR(16)+2) & 0xE000) != 0xE000){} \
  121. while((MMIO_IN16(ivideo->mmio_vbase, BR(16)+2) & 0xE000) != 0xE000){} \
  122. while((MMIO_IN16(ivideo->mmio_vbase, BR(16)+2) & 0xE000) != 0xE000){} \
  123. CmdQueLen = MMIO_IN16(ivideo->mmio_vbase, 0x8240); \
  124. }
  125. /* (do three times, because 2D engine seems quite unsure about whether or not it's idle) */
  126. #define SiS300SetupSRCBase(base) \
  127. if(CmdQueLen <= 0) SiS300Idle;\
  128. MMIO_OUT32(ivideo->mmio_vbase, BR(0), base);\
  129. CmdQueLen--;
  130. #define SiS300SetupSRCPitch(pitch) \
  131. if(CmdQueLen <= 0) SiS300Idle;\
  132. MMIO_OUT16(ivideo->mmio_vbase, BR(1), pitch);\
  133. CmdQueLen--;
  134. #define SiS300SetupSRCXY(x,y) \
  135. if(CmdQueLen <= 0) SiS300Idle;\
  136. MMIO_OUT32(ivideo->mmio_vbase, BR(2), (x)<<16 | (y) );\
  137. CmdQueLen--;
  138. #define SiS300SetupDSTBase(base) \
  139. if(CmdQueLen <= 0) SiS300Idle;\
  140. MMIO_OUT32(ivideo->mmio_vbase, BR(4), base);\
  141. CmdQueLen--;
  142. #define SiS300SetupDSTXY(x,y) \
  143. if(CmdQueLen <= 0) SiS300Idle;\
  144. MMIO_OUT32(ivideo->mmio_vbase, BR(3), (x)<<16 | (y) );\
  145. CmdQueLen--;
  146. #define SiS300SetupDSTRect(x,y) \
  147. if(CmdQueLen <= 0) SiS300Idle;\
  148. MMIO_OUT32(ivideo->mmio_vbase, BR(5), (y)<<16 | (x) );\
  149. CmdQueLen--;
  150. #define SiS300SetupDSTColorDepth(bpp) \
  151. if(CmdQueLen <= 0) SiS300Idle;\
  152. MMIO_OUT16(ivideo->mmio_vbase, BR(1)+2, bpp);\
  153. CmdQueLen--;
  154. #define SiS300SetupRect(w,h) \
  155. if(CmdQueLen <= 0) SiS300Idle;\
  156. MMIO_OUT32(ivideo->mmio_vbase, BR(6), (h)<<16 | (w) );\
  157. CmdQueLen--;
  158. #define SiS300SetupPATFG(color) \
  159. if(CmdQueLen <= 0) SiS300Idle;\
  160. MMIO_OUT32(ivideo->mmio_vbase, BR(7), color);\
  161. CmdQueLen--;
  162. #define SiS300SetupPATBG(color) \
  163. if(CmdQueLen <= 0) SiS300Idle;\
  164. MMIO_OUT32(ivideo->mmio_vbase, BR(8), color);\
  165. CmdQueLen--;
  166. #define SiS300SetupSRCFG(color) \
  167. if(CmdQueLen <= 0) SiS300Idle;\
  168. MMIO_OUT32(ivideo->mmio_vbase, BR(9), color);\
  169. CmdQueLen--;
  170. #define SiS300SetupSRCBG(color) \
  171. if(CmdQueLen <= 0) SiS300Idle;\
  172. MMIO_OUT32(ivideo->mmio_vbase, BR(10), color);\
  173. CmdQueLen--;
  174. /* 0x8224 src colorkey high */
  175. /* 0x8228 src colorkey low */
  176. /* 0x821c dest colorkey high */
  177. /* 0x8220 dest colorkey low */
  178. #define SiS300SetupSRCTrans(color) \
  179. if(CmdQueLen <= 1) SiS300Idle;\
  180. MMIO_OUT32(ivideo->mmio_vbase, 0x8224, color);\
  181. MMIO_OUT32(ivideo->mmio_vbase, 0x8228, color);\
  182. CmdQueLen -= 2;
  183. #define SiS300SetupDSTTrans(color) \
  184. if(CmdQueLen <= 1) SiS300Idle;\
  185. MMIO_OUT32(ivideo->mmio_vbase, 0x821C, color); \
  186. MMIO_OUT32(ivideo->mmio_vbase, 0x8220, color); \
  187. CmdQueLen -= 2;
  188. #define SiS300SetupMONOPAT(p0,p1) \
  189. if(CmdQueLen <= 1) SiS300Idle;\
  190. MMIO_OUT32(ivideo->mmio_vbase, BR(11), p0);\
  191. MMIO_OUT32(ivideo->mmio_vbase, BR(12), p1);\
  192. CmdQueLen -= 2;
  193. #define SiS300SetupClipLT(left,top) \
  194. if(CmdQueLen <= 0) SiS300Idle;\
  195. MMIO_OUT32(ivideo->mmio_vbase, BR(13), ((left) & 0xFFFF) | (top)<<16 );\
  196. CmdQueLen--;
  197. #define SiS300SetupClipRB(right,bottom) \
  198. if(CmdQueLen <= 0) SiS300Idle;\
  199. MMIO_OUT32(ivideo->mmio_vbase, BR(14), ((right) & 0xFFFF) | (bottom)<<16 );\
  200. CmdQueLen--;
  201. /* General */
  202. #define SiS300SetupROP(rop) \
  203. ivideo->CommandReg = (rop) << 8;
  204. #define SiS300SetupCMDFlag(flags) \
  205. ivideo->CommandReg |= (flags);
  206. #define SiS300DoCMD \
  207. if(CmdQueLen <= 1) SiS300Idle;\
  208. MMIO_OUT32(ivideo->mmio_vbase, BR(15), ivideo->CommandReg); \
  209. MMIO_OUT32(ivideo->mmio_vbase, BR(16), 0);\
  210. CmdQueLen -= 2;
  211. /* -------------- SiS 315/330 series --------------- */
  212. /* Q_STATUS:
  213. bit 31 = 1: All engines idle and all queues empty
  214. bit 30 = 1: Hardware Queue (=HW CQ, 2D queue, 3D queue) empty
  215. bit 29 = 1: 2D engine is idle
  216. bit 28 = 1: 3D engine is idle
  217. bit 27 = 1: HW command queue empty
  218. bit 26 = 1: 2D queue empty
  219. bit 25 = 1: 3D queue empty
  220. bit 24 = 1: SW command queue empty
  221. bits 23:16: 2D counter 3
  222. bits 15:8: 2D counter 2
  223. bits 7:0: 2D counter 1
  224. */
  225. #define SiS310Idle \
  226. { \
  227. while( (MMIO_IN16(ivideo->mmio_vbase, Q_STATUS+2) & 0x8000) != 0x8000){} \
  228. while( (MMIO_IN16(ivideo->mmio_vbase, Q_STATUS+2) & 0x8000) != 0x8000){} \
  229. while( (MMIO_IN16(ivideo->mmio_vbase, Q_STATUS+2) & 0x8000) != 0x8000){} \
  230. while( (MMIO_IN16(ivideo->mmio_vbase, Q_STATUS+2) & 0x8000) != 0x8000){} \
  231. CmdQueLen = 0; \
  232. }
  233. #define SiS310SetupSRCBase(base) \
  234. if(CmdQueLen <= 0) SiS310Idle;\
  235. MMIO_OUT32(ivideo->mmio_vbase, SRC_ADDR, base);\
  236. CmdQueLen--;
  237. #define SiS310SetupSRCPitch(pitch) \
  238. if(CmdQueLen <= 0) SiS310Idle;\
  239. MMIO_OUT16(ivideo->mmio_vbase, SRC_PITCH, pitch);\
  240. CmdQueLen--;
  241. #define SiS310SetupSRCXY(x,y) \
  242. if(CmdQueLen <= 0) SiS310Idle;\
  243. MMIO_OUT32(ivideo->mmio_vbase, SRC_Y, (x)<<16 | (y) );\
  244. CmdQueLen--;
  245. #define SiS310SetupDSTBase(base) \
  246. if(CmdQueLen <= 0) SiS310Idle;\
  247. MMIO_OUT32(ivideo->mmio_vbase, DST_ADDR, base);\
  248. CmdQueLen--;
  249. #define SiS310SetupDSTXY(x,y) \
  250. if(CmdQueLen <= 0) SiS310Idle;\
  251. MMIO_OUT32(ivideo->mmio_vbase, DST_Y, (x)<<16 | (y) );\
  252. CmdQueLen--;
  253. #define SiS310SetupDSTRect(x,y) \
  254. if(CmdQueLen <= 0) SiS310Idle;\
  255. MMIO_OUT32(ivideo->mmio_vbase, DST_PITCH, (y)<<16 | (x) );\
  256. CmdQueLen--;
  257. #define SiS310SetupDSTColorDepth(bpp) \
  258. if(CmdQueLen <= 0) SiS310Idle;\
  259. MMIO_OUT16(ivideo->mmio_vbase, AGP_BASE, bpp);\
  260. CmdQueLen--;
  261. #define SiS310SetupRect(w,h) \
  262. if(CmdQueLen <= 0) SiS310Idle;\
  263. MMIO_OUT32(ivideo->mmio_vbase, RECT_WIDTH, (h)<<16 | (w) );\
  264. CmdQueLen--;
  265. #define SiS310SetupPATFG(color) \
  266. if(CmdQueLen <= 0) SiS310Idle;\
  267. MMIO_OUT32(ivideo->mmio_vbase, PAT_FGCOLOR, color);\
  268. CmdQueLen--;
  269. #define SiS310SetupPATBG(color) \
  270. if(CmdQueLen <= 0) SiS310Idle;\
  271. MMIO_OUT32(ivideo->mmio_vbase, PAT_BGCOLOR, color);\
  272. CmdQueLen--;
  273. #define SiS310SetupSRCFG(color) \
  274. if(CmdQueLen <= 0) SiS310Idle;\
  275. MMIO_OUT32(ivideo->mmio_vbase, SRC_FGCOLOR, color);\
  276. CmdQueLen--;
  277. #define SiS310SetupSRCBG(color) \
  278. if(CmdQueLen <= 0) SiS310Idle;\
  279. MMIO_OUT32(ivideo->mmio_vbase, SRC_BGCOLOR, color);\
  280. CmdQueLen--;
  281. #define SiS310SetupSRCTrans(color) \
  282. if(CmdQueLen <= 1) SiS310Idle;\
  283. MMIO_OUT32(ivideo->mmio_vbase, TRANS_SRC_KEY_HIGH, color);\
  284. MMIO_OUT32(ivideo->mmio_vbase, TRANS_SRC_KEY_LOW, color);\
  285. CmdQueLen -= 2;
  286. #define SiS310SetupDSTTrans(color) \
  287. if(CmdQueLen <= 1) SiS310Idle;\
  288. MMIO_OUT32(ivideo->mmio_vbase, TRANS_DST_KEY_HIGH, color); \
  289. MMIO_OUT32(ivideo->mmio_vbase, TRANS_DST_KEY_LOW, color); \
  290. CmdQueLen -= 2;
  291. #define SiS310SetupMONOPAT(p0,p1) \
  292. if(CmdQueLen <= 1) SiS310Idle;\
  293. MMIO_OUT32(ivideo->mmio_vbase, MONO_MASK, p0);\
  294. MMIO_OUT32(ivideo->mmio_vbase, MONO_MASK+4, p1);\
  295. CmdQueLen -= 2;
  296. #define SiS310SetupClipLT(left,top) \
  297. if(CmdQueLen <= 0) SiS310Idle;\
  298. MMIO_OUT32(ivideo->mmio_vbase, LEFT_CLIP, ((left) & 0xFFFF) | (top)<<16 );\
  299. CmdQueLen--;
  300. #define SiS310SetupClipRB(right,bottom) \
  301. if(CmdQueLen <= 0) SiS310Idle;\
  302. MMIO_OUT32(ivideo->mmio_vbase, RIGHT_CLIP, ((right) & 0xFFFF) | (bottom)<<16 );\
  303. CmdQueLen--;
  304. #define SiS310SetupROP(rop) \
  305. ivideo->CommandReg = (rop) << 8;
  306. #define SiS310SetupCMDFlag(flags) \
  307. ivideo->CommandReg |= (flags);
  308. #define SiS310DoCMD \
  309. if(CmdQueLen <= 1) SiS310Idle;\
  310. MMIO_OUT32(ivideo->mmio_vbase, COMMAND_READY, ivideo->CommandReg); \
  311. MMIO_OUT32(ivideo->mmio_vbase, FIRE_TRIGGER, 0); \
  312. CmdQueLen -= 2;
  313. int sisfb_initaccel(struct sis_video_info *ivideo);
  314. void sisfb_syncaccel(struct sis_video_info *ivideo);
  315. int fbcon_sis_sync(struct fb_info *info);
  316. void fbcon_sis_fillrect(struct fb_info *info, const struct fb_fillrect *rect);
  317. void fbcon_sis_copyarea(struct fb_info *info, const struct fb_copyarea *area);
  318. #endif