i810_accel.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. /*-*- linux-c -*-
  2. * linux/drivers/video/i810_accel.c -- Hardware Acceleration
  3. *
  4. * Copyright (C) 2001 Antonino Daplas<adaplas@pol.net>
  5. * All Rights Reserved
  6. *
  7. * This file is subject to the terms and conditions of the GNU General Public
  8. * License. See the file COPYING in the main directory of this archive for
  9. * more details.
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/string.h>
  13. #include <linux/fb.h>
  14. #include "i810_regs.h"
  15. #include "i810.h"
  16. #include "i810_main.h"
  17. static u32 i810fb_rop[] = {
  18. COLOR_COPY_ROP, /* ROP_COPY */
  19. XOR_ROP /* ROP_XOR */
  20. };
  21. /* Macros */
  22. #define PUT_RING(n) { \
  23. i810_writel(par->cur_tail, par->iring.virtual, n); \
  24. par->cur_tail += 4; \
  25. par->cur_tail &= RING_SIZE_MASK; \
  26. }
  27. extern void flush_cache(void);
  28. /************************************************************/
  29. /* BLT Engine Routines */
  30. static inline void i810_report_error(u8 __iomem *mmio)
  31. {
  32. printk("IIR : 0x%04x\n"
  33. "EIR : 0x%04x\n"
  34. "PGTBL_ER: 0x%04x\n"
  35. "IPEIR : 0x%04x\n"
  36. "IPEHR : 0x%04x\n",
  37. i810_readw(IIR, mmio),
  38. i810_readb(EIR, mmio),
  39. i810_readl(PGTBL_ER, mmio),
  40. i810_readl(IPEIR, mmio),
  41. i810_readl(IPEHR, mmio));
  42. }
  43. /**
  44. * wait_for_space - check ring buffer free space
  45. * @space: amount of ringbuffer space needed in bytes
  46. * @par: pointer to i810fb_par structure
  47. *
  48. * DESCRIPTION:
  49. * The function waits until a free space from the ringbuffer
  50. * is available
  51. */
  52. static inline int wait_for_space(struct fb_info *info, u32 space)
  53. {
  54. struct i810fb_par *par = info->par;
  55. u32 head, count = WAIT_COUNT, tail;
  56. u8 __iomem *mmio = par->mmio_start_virtual;
  57. tail = par->cur_tail;
  58. while (count--) {
  59. head = i810_readl(IRING + 4, mmio) & RBUFFER_HEAD_MASK;
  60. if ((tail == head) ||
  61. (tail > head &&
  62. (par->iring.size - tail + head) >= space) ||
  63. (tail < head && (head - tail) >= space)) {
  64. return 0;
  65. }
  66. }
  67. printk("ringbuffer lockup!!!\n");
  68. i810_report_error(mmio);
  69. par->dev_flags |= LOCKUP;
  70. info->pixmap.scan_align = 1;
  71. return 1;
  72. }
  73. /**
  74. * wait_for_engine_idle - waits for all hardware engines to finish
  75. * @par: pointer to i810fb_par structure
  76. *
  77. * DESCRIPTION:
  78. * This waits for lring(0), iring(1), and batch(3), etc to finish and
  79. * waits until ringbuffer is empty.
  80. */
  81. static inline int wait_for_engine_idle(struct fb_info *info)
  82. {
  83. struct i810fb_par *par = info->par;
  84. u8 __iomem *mmio = par->mmio_start_virtual;
  85. int count = WAIT_COUNT;
  86. if (wait_for_space(info, par->iring.size)) /* flush */
  87. return 1;
  88. while((i810_readw(INSTDONE, mmio) & 0x7B) != 0x7B && --count);
  89. if (count) return 0;
  90. printk("accel engine lockup!!!\n");
  91. printk("INSTDONE: 0x%04x\n", i810_readl(INSTDONE, mmio));
  92. i810_report_error(mmio);
  93. par->dev_flags |= LOCKUP;
  94. info->pixmap.scan_align = 1;
  95. return 1;
  96. }
  97. /* begin_iring - prepares the ringbuffer
  98. * @space: length of sequence in dwords
  99. * @par: pointer to i810fb_par structure
  100. *
  101. * DESCRIPTION:
  102. * Checks/waits for sufficient space in ringbuffer of size
  103. * space. Returns the tail of the buffer
  104. */
  105. static inline u32 begin_iring(struct fb_info *info, u32 space)
  106. {
  107. struct i810fb_par *par = info->par;
  108. if (par->dev_flags & ALWAYS_SYNC)
  109. wait_for_engine_idle(info);
  110. return wait_for_space(info, space);
  111. }
  112. /**
  113. * end_iring - advances the buffer
  114. * @par: pointer to i810fb_par structure
  115. *
  116. * DESCRIPTION:
  117. * This advances the tail of the ringbuffer, effectively
  118. * beginning the execution of the graphics instruction sequence.
  119. */
  120. static inline void end_iring(struct i810fb_par *par)
  121. {
  122. u8 __iomem *mmio = par->mmio_start_virtual;
  123. i810_writel(IRING, mmio, par->cur_tail);
  124. }
  125. /**
  126. * source_copy_blit - BLIT transfer operation
  127. * @dwidth: width of rectangular graphics data
  128. * @dheight: height of rectangular graphics data
  129. * @dpitch: bytes per line of destination buffer
  130. * @xdir: direction of copy (left to right or right to left)
  131. * @src: address of first pixel to read from
  132. * @dest: address of first pixel to write to
  133. * @from: source address
  134. * @where: destination address
  135. * @rop: raster operation
  136. * @blit_bpp: pixel format which can be different from the
  137. * framebuffer's pixelformat
  138. * @par: pointer to i810fb_par structure
  139. *
  140. * DESCRIPTION:
  141. * This is a BLIT operation typically used when doing
  142. * a 'Copy and Paste'
  143. */
  144. static inline void source_copy_blit(int dwidth, int dheight, int dpitch,
  145. int xdir, int src, int dest, int rop,
  146. int blit_bpp, struct fb_info *info)
  147. {
  148. struct i810fb_par *par = info->par;
  149. if (begin_iring(info, 24 + IRING_PAD)) return;
  150. PUT_RING(BLIT | SOURCE_COPY_BLIT | 4);
  151. PUT_RING(xdir | rop << 16 | dpitch | DYN_COLOR_EN | blit_bpp);
  152. PUT_RING(dheight << 16 | dwidth);
  153. PUT_RING(dest);
  154. PUT_RING(dpitch);
  155. PUT_RING(src);
  156. end_iring(par);
  157. }
  158. /**
  159. * color_blit - solid color BLIT operation
  160. * @width: width of destination
  161. * @height: height of destination
  162. * @pitch: pixels per line of the buffer
  163. * @dest: address of first pixel to write to
  164. * @where: destination
  165. * @rop: raster operation
  166. * @what: color to transfer
  167. * @blit_bpp: pixel format which can be different from the
  168. * framebuffer's pixelformat
  169. * @par: pointer to i810fb_par structure
  170. *
  171. * DESCRIPTION:
  172. * A BLIT operation which can be used for color fill/rectangular fill
  173. */
  174. static inline void color_blit(int width, int height, int pitch, int dest,
  175. int rop, int what, int blit_bpp,
  176. struct fb_info *info)
  177. {
  178. struct i810fb_par *par = info->par;
  179. if (begin_iring(info, 24 + IRING_PAD)) return;
  180. PUT_RING(BLIT | COLOR_BLT | 3);
  181. PUT_RING(rop << 16 | pitch | SOLIDPATTERN | DYN_COLOR_EN | blit_bpp);
  182. PUT_RING(height << 16 | width);
  183. PUT_RING(dest);
  184. PUT_RING(what);
  185. PUT_RING(NOP);
  186. end_iring(par);
  187. }
  188. /**
  189. * mono_src_copy_imm_blit - color expand from system memory to framebuffer
  190. * @dwidth: width of destination
  191. * @dheight: height of destination
  192. * @dpitch: pixels per line of the buffer
  193. * @dsize: size of bitmap in double words
  194. * @dest: address of first byte of pixel;
  195. * @rop: raster operation
  196. * @blit_bpp: pixelformat to use which can be different from the
  197. * framebuffer's pixelformat
  198. * @src: address of image data
  199. * @bg: backgound color
  200. * @fg: forground color
  201. * @par: pointer to i810fb_par structure
  202. *
  203. * DESCRIPTION:
  204. * A color expand operation where the source data is placed in the
  205. * ringbuffer itself. Useful for drawing text.
  206. *
  207. * REQUIREMENT:
  208. * The end of a scanline must be padded to the next word.
  209. */
  210. static inline void mono_src_copy_imm_blit(int dwidth, int dheight, int dpitch,
  211. int dsize, int blit_bpp, int rop,
  212. int dest, const u32 *src, int bg,
  213. int fg, struct fb_info *info)
  214. {
  215. struct i810fb_par *par = info->par;
  216. if (begin_iring(info, 24 + (dsize << 2) + IRING_PAD)) return;
  217. PUT_RING(BLIT | MONO_SOURCE_COPY_IMMEDIATE | (4 + dsize));
  218. PUT_RING(DYN_COLOR_EN | blit_bpp | rop << 16 | dpitch);
  219. PUT_RING(dheight << 16 | dwidth);
  220. PUT_RING(dest);
  221. PUT_RING(bg);
  222. PUT_RING(fg);
  223. while (dsize--)
  224. PUT_RING(*src++);
  225. end_iring(par);
  226. }
  227. static inline void load_front(int offset, struct fb_info *info)
  228. {
  229. struct i810fb_par *par = info->par;
  230. if (begin_iring(info, 8 + IRING_PAD)) return;
  231. PUT_RING(PARSER | FLUSH);
  232. PUT_RING(NOP);
  233. end_iring(par);
  234. if (begin_iring(info, 8 + IRING_PAD)) return;
  235. PUT_RING(PARSER | FRONT_BUFFER | ((par->pitch >> 3) << 8));
  236. PUT_RING((par->fb.offset << 12) + offset);
  237. end_iring(par);
  238. }
  239. /**
  240. * i810fb_iring_enable - enables/disables the ringbuffer
  241. * @mode: enable or disable
  242. * @par: pointer to i810fb_par structure
  243. *
  244. * DESCRIPTION:
  245. * Enables or disables the ringbuffer, effectively enabling or
  246. * disabling the instruction/acceleration engine.
  247. */
  248. static inline void i810fb_iring_enable(struct i810fb_par *par, u32 mode)
  249. {
  250. u32 tmp;
  251. u8 __iomem *mmio = par->mmio_start_virtual;
  252. tmp = i810_readl(IRING + 12, mmio);
  253. if (mode == OFF)
  254. tmp &= ~1;
  255. else
  256. tmp |= 1;
  257. flush_cache();
  258. i810_writel(IRING + 12, mmio, tmp);
  259. }
  260. void i810fb_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
  261. {
  262. struct i810fb_par *par = info->par;
  263. u32 dx, dy, width, height, dest, rop = 0, color = 0;
  264. if (!info->var.accel_flags || par->dev_flags & LOCKUP ||
  265. par->depth == 4) {
  266. cfb_fillrect(info, rect);
  267. return;
  268. }
  269. if (par->depth == 1)
  270. color = rect->color;
  271. else
  272. color = ((u32 *) (info->pseudo_palette))[rect->color];
  273. rop = i810fb_rop[rect->rop];
  274. dx = rect->dx * par->depth;
  275. width = rect->width * par->depth;
  276. dy = rect->dy;
  277. height = rect->height;
  278. dest = info->fix.smem_start + (dy * info->fix.line_length) + dx;
  279. color_blit(width, height, info->fix.line_length, dest, rop, color,
  280. par->blit_bpp, info);
  281. }
  282. void i810fb_copyarea(struct fb_info *info, const struct fb_copyarea *region)
  283. {
  284. struct i810fb_par *par = info->par;
  285. u32 sx, sy, dx, dy, pitch, width, height, src, dest, xdir;
  286. if (!info->var.accel_flags || par->dev_flags & LOCKUP ||
  287. par->depth == 4) {
  288. cfb_copyarea(info, region);
  289. return;
  290. }
  291. dx = region->dx * par->depth;
  292. sx = region->sx * par->depth;
  293. width = region->width * par->depth;
  294. sy = region->sy;
  295. dy = region->dy;
  296. height = region->height;
  297. if (dx <= sx) {
  298. xdir = INCREMENT;
  299. }
  300. else {
  301. xdir = DECREMENT;
  302. sx += width - 1;
  303. dx += width - 1;
  304. }
  305. if (dy <= sy) {
  306. pitch = info->fix.line_length;
  307. }
  308. else {
  309. pitch = (-(info->fix.line_length)) & 0xFFFF;
  310. sy += height - 1;
  311. dy += height - 1;
  312. }
  313. src = info->fix.smem_start + (sy * info->fix.line_length) + sx;
  314. dest = info->fix.smem_start + (dy * info->fix.line_length) + dx;
  315. source_copy_blit(width, height, pitch, xdir, src, dest,
  316. PAT_COPY_ROP, par->blit_bpp, info);
  317. }
  318. void i810fb_imageblit(struct fb_info *info, const struct fb_image *image)
  319. {
  320. struct i810fb_par *par = info->par;
  321. u32 fg = 0, bg = 0, size, dst;
  322. if (!info->var.accel_flags || par->dev_flags & LOCKUP ||
  323. par->depth == 4 || image->depth != 1) {
  324. cfb_imageblit(info, image);
  325. return;
  326. }
  327. switch (info->var.bits_per_pixel) {
  328. case 8:
  329. fg = image->fg_color;
  330. bg = image->bg_color;
  331. break;
  332. case 16:
  333. case 24:
  334. fg = ((u32 *)(info->pseudo_palette))[image->fg_color];
  335. bg = ((u32 *)(info->pseudo_palette))[image->bg_color];
  336. break;
  337. }
  338. dst = info->fix.smem_start + (image->dy * info->fix.line_length) +
  339. (image->dx * par->depth);
  340. size = (image->width+7)/8 + 1;
  341. size &= ~1;
  342. size *= image->height;
  343. size += 7;
  344. size &= ~7;
  345. mono_src_copy_imm_blit(image->width * par->depth,
  346. image->height, info->fix.line_length,
  347. size/4, par->blit_bpp,
  348. PAT_COPY_ROP, dst, (u32 *) image->data,
  349. bg, fg, info);
  350. }
  351. int i810fb_sync(struct fb_info *info)
  352. {
  353. struct i810fb_par *par = info->par;
  354. if (!info->var.accel_flags || par->dev_flags & LOCKUP)
  355. return 0;
  356. return wait_for_engine_idle(info);
  357. }
  358. void i810fb_load_front(u32 offset, struct fb_info *info)
  359. {
  360. struct i810fb_par *par = info->par;
  361. u8 __iomem *mmio = par->mmio_start_virtual;
  362. if (!info->var.accel_flags || par->dev_flags & LOCKUP)
  363. i810_writel(DPLYBASE, mmio, par->fb.physical + offset);
  364. else
  365. load_front(offset, info);
  366. }
  367. /**
  368. * i810fb_init_ringbuffer - initialize the ringbuffer
  369. * @par: pointer to i810fb_par structure
  370. *
  371. * DESCRIPTION:
  372. * Initializes the ringbuffer by telling the device the
  373. * size and location of the ringbuffer. It also sets
  374. * the head and tail pointers = 0
  375. */
  376. void i810fb_init_ringbuffer(struct fb_info *info)
  377. {
  378. struct i810fb_par *par = info->par;
  379. u32 tmp1, tmp2;
  380. u8 __iomem *mmio = par->mmio_start_virtual;
  381. wait_for_engine_idle(info);
  382. i810fb_iring_enable(par, OFF);
  383. i810_writel(IRING, mmio, 0);
  384. i810_writel(IRING + 4, mmio, 0);
  385. par->cur_tail = 0;
  386. tmp2 = i810_readl(IRING + 8, mmio) & ~RBUFFER_START_MASK;
  387. tmp1 = par->iring.physical;
  388. i810_writel(IRING + 8, mmio, tmp2 | tmp1);
  389. tmp1 = i810_readl(IRING + 12, mmio);
  390. tmp1 &= ~RBUFFER_SIZE_MASK;
  391. tmp2 = (par->iring.size - I810_PAGESIZE) & RBUFFER_SIZE_MASK;
  392. i810_writel(IRING + 12, mmio, tmp1 | tmp2);
  393. i810fb_iring_enable(par, ON);
  394. }