i810_accel.c 12 KB

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