nv04_fbcon.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. /*
  2. * Copyright 2009 Ben Skeggs
  3. * Copyright 2008 Stuart Bennett
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. * and/or sell copies of the Software, and to permit persons to whom the
  10. * Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice (including the next
  13. * paragraph) shall be included in all copies or substantial portions of the
  14. * Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  21. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  22. * DEALINGS IN THE SOFTWARE.
  23. */
  24. #include "drmP.h"
  25. #include "nouveau_drv.h"
  26. #include "nouveau_dma.h"
  27. #include "nouveau_ramht.h"
  28. #include "nouveau_fbcon.h"
  29. int
  30. nv04_fbcon_copyarea(struct fb_info *info, const struct fb_copyarea *region)
  31. {
  32. struct nouveau_fbdev *nfbdev = info->par;
  33. struct drm_device *dev = nfbdev->dev;
  34. struct drm_nouveau_private *dev_priv = dev->dev_private;
  35. struct nouveau_channel *chan = dev_priv->channel;
  36. int ret;
  37. ret = RING_SPACE(chan, 4);
  38. if (ret)
  39. return ret;
  40. BEGIN_RING(chan, NvSubImageBlit, 0x0300, 3);
  41. OUT_RING(chan, (region->sy << 16) | region->sx);
  42. OUT_RING(chan, (region->dy << 16) | region->dx);
  43. OUT_RING(chan, (region->height << 16) | region->width);
  44. FIRE_RING(chan);
  45. return 0;
  46. }
  47. int
  48. nv04_fbcon_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
  49. {
  50. struct nouveau_fbdev *nfbdev = info->par;
  51. struct drm_device *dev = nfbdev->dev;
  52. struct drm_nouveau_private *dev_priv = dev->dev_private;
  53. struct nouveau_channel *chan = dev_priv->channel;
  54. int ret;
  55. ret = RING_SPACE(chan, 7);
  56. if (ret)
  57. return ret;
  58. BEGIN_RING(chan, NvSubGdiRect, 0x02fc, 1);
  59. OUT_RING(chan, (rect->rop != ROP_COPY) ? 1 : 3);
  60. BEGIN_RING(chan, NvSubGdiRect, 0x03fc, 1);
  61. if (info->fix.visual == FB_VISUAL_TRUECOLOR ||
  62. info->fix.visual == FB_VISUAL_DIRECTCOLOR)
  63. OUT_RING(chan, ((uint32_t *)info->pseudo_palette)[rect->color]);
  64. else
  65. OUT_RING(chan, rect->color);
  66. BEGIN_RING(chan, NvSubGdiRect, 0x0400, 2);
  67. OUT_RING(chan, (rect->dx << 16) | rect->dy);
  68. OUT_RING(chan, (rect->width << 16) | rect->height);
  69. FIRE_RING(chan);
  70. return 0;
  71. }
  72. int
  73. nv04_fbcon_imageblit(struct fb_info *info, const struct fb_image *image)
  74. {
  75. struct nouveau_fbdev *nfbdev = info->par;
  76. struct drm_device *dev = nfbdev->dev;
  77. struct drm_nouveau_private *dev_priv = dev->dev_private;
  78. struct nouveau_channel *chan = dev_priv->channel;
  79. uint32_t fg;
  80. uint32_t bg;
  81. uint32_t dsize;
  82. uint32_t width;
  83. uint32_t *data = (uint32_t *)image->data;
  84. int ret;
  85. if (image->depth != 1)
  86. return -ENODEV;
  87. ret = RING_SPACE(chan, 8);
  88. if (ret)
  89. return ret;
  90. width = ALIGN(image->width, 8);
  91. dsize = ALIGN(width * image->height, 32) >> 5;
  92. if (info->fix.visual == FB_VISUAL_TRUECOLOR ||
  93. info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
  94. fg = ((uint32_t *) info->pseudo_palette)[image->fg_color];
  95. bg = ((uint32_t *) info->pseudo_palette)[image->bg_color];
  96. } else {
  97. fg = image->fg_color;
  98. bg = image->bg_color;
  99. }
  100. BEGIN_RING(chan, NvSubGdiRect, 0x0be4, 7);
  101. OUT_RING(chan, (image->dy << 16) | (image->dx & 0xffff));
  102. OUT_RING(chan, ((image->dy + image->height) << 16) |
  103. ((image->dx + image->width) & 0xffff));
  104. OUT_RING(chan, bg);
  105. OUT_RING(chan, fg);
  106. OUT_RING(chan, (image->height << 16) | width);
  107. OUT_RING(chan, (image->height << 16) | image->width);
  108. OUT_RING(chan, (image->dy << 16) | (image->dx & 0xffff));
  109. while (dsize) {
  110. int iter_len = dsize > 128 ? 128 : dsize;
  111. ret = RING_SPACE(chan, iter_len + 1);
  112. if (ret)
  113. return ret;
  114. BEGIN_RING(chan, NvSubGdiRect, 0x0c00, iter_len);
  115. OUT_RINGp(chan, data, iter_len);
  116. data += iter_len;
  117. dsize -= iter_len;
  118. }
  119. FIRE_RING(chan);
  120. return 0;
  121. }
  122. int
  123. nv04_fbcon_accel_init(struct fb_info *info)
  124. {
  125. struct nouveau_fbdev *nfbdev = info->par;
  126. struct drm_device *dev = nfbdev->dev;
  127. struct drm_nouveau_private *dev_priv = dev->dev_private;
  128. struct nouveau_channel *chan = dev_priv->channel;
  129. const int sub = NvSubCtxSurf2D;
  130. int surface_fmt, pattern_fmt, rect_fmt;
  131. int ret;
  132. switch (info->var.bits_per_pixel) {
  133. case 8:
  134. surface_fmt = 1;
  135. pattern_fmt = 3;
  136. rect_fmt = 3;
  137. break;
  138. case 16:
  139. surface_fmt = 4;
  140. pattern_fmt = 1;
  141. rect_fmt = 1;
  142. break;
  143. case 32:
  144. switch (info->var.transp.length) {
  145. case 0: /* depth 24 */
  146. case 8: /* depth 32 */
  147. break;
  148. default:
  149. return -EINVAL;
  150. }
  151. surface_fmt = 6;
  152. pattern_fmt = 3;
  153. rect_fmt = 3;
  154. break;
  155. default:
  156. return -EINVAL;
  157. }
  158. ret = nouveau_gpuobj_gr_new(chan, NvCtxSurf2D,
  159. dev_priv->card_type >= NV_10 ?
  160. 0x0062 : 0x0042);
  161. if (ret)
  162. return ret;
  163. ret = nouveau_gpuobj_gr_new(chan, NvClipRect, 0x0019);
  164. if (ret)
  165. return ret;
  166. ret = nouveau_gpuobj_gr_new(chan, NvRop, 0x0043);
  167. if (ret)
  168. return ret;
  169. ret = nouveau_gpuobj_gr_new(chan, NvImagePatt, 0x0044);
  170. if (ret)
  171. return ret;
  172. ret = nouveau_gpuobj_gr_new(chan, NvGdiRect, 0x004a);
  173. if (ret)
  174. return ret;
  175. ret = nouveau_gpuobj_gr_new(chan, NvImageBlit,
  176. dev_priv->chipset >= 0x11 ?
  177. 0x009f : 0x005f);
  178. if (ret)
  179. return ret;
  180. if (RING_SPACE(chan, 49)) {
  181. nouveau_fbcon_gpu_lockup(info);
  182. return 0;
  183. }
  184. BEGIN_RING(chan, sub, 0x0000, 1);
  185. OUT_RING(chan, NvCtxSurf2D);
  186. BEGIN_RING(chan, sub, 0x0184, 2);
  187. OUT_RING(chan, NvDmaFB);
  188. OUT_RING(chan, NvDmaFB);
  189. BEGIN_RING(chan, sub, 0x0300, 4);
  190. OUT_RING(chan, surface_fmt);
  191. OUT_RING(chan, info->fix.line_length | (info->fix.line_length << 16));
  192. OUT_RING(chan, info->fix.smem_start - dev->mode_config.fb_base);
  193. OUT_RING(chan, info->fix.smem_start - dev->mode_config.fb_base);
  194. BEGIN_RING(chan, sub, 0x0000, 1);
  195. OUT_RING(chan, NvRop);
  196. BEGIN_RING(chan, sub, 0x0300, 1);
  197. OUT_RING(chan, 0x55);
  198. BEGIN_RING(chan, sub, 0x0000, 1);
  199. OUT_RING(chan, NvImagePatt);
  200. BEGIN_RING(chan, sub, 0x0300, 8);
  201. OUT_RING(chan, pattern_fmt);
  202. #ifdef __BIG_ENDIAN
  203. OUT_RING(chan, 2);
  204. #else
  205. OUT_RING(chan, 1);
  206. #endif
  207. OUT_RING(chan, 0);
  208. OUT_RING(chan, 1);
  209. OUT_RING(chan, ~0);
  210. OUT_RING(chan, ~0);
  211. OUT_RING(chan, ~0);
  212. OUT_RING(chan, ~0);
  213. BEGIN_RING(chan, sub, 0x0000, 1);
  214. OUT_RING(chan, NvClipRect);
  215. BEGIN_RING(chan, sub, 0x0300, 2);
  216. OUT_RING(chan, 0);
  217. OUT_RING(chan, (info->var.yres_virtual << 16) | info->var.xres_virtual);
  218. BEGIN_RING(chan, NvSubImageBlit, 0x0000, 1);
  219. OUT_RING(chan, NvImageBlit);
  220. BEGIN_RING(chan, NvSubImageBlit, 0x019c, 1);
  221. OUT_RING(chan, NvCtxSurf2D);
  222. BEGIN_RING(chan, NvSubImageBlit, 0x02fc, 1);
  223. OUT_RING(chan, 3);
  224. BEGIN_RING(chan, NvSubGdiRect, 0x0000, 1);
  225. OUT_RING(chan, NvGdiRect);
  226. BEGIN_RING(chan, NvSubGdiRect, 0x0198, 1);
  227. OUT_RING(chan, NvCtxSurf2D);
  228. BEGIN_RING(chan, NvSubGdiRect, 0x0188, 2);
  229. OUT_RING(chan, NvImagePatt);
  230. OUT_RING(chan, NvRop);
  231. BEGIN_RING(chan, NvSubGdiRect, 0x0304, 1);
  232. OUT_RING(chan, 1);
  233. BEGIN_RING(chan, NvSubGdiRect, 0x0300, 1);
  234. OUT_RING(chan, rect_fmt);
  235. BEGIN_RING(chan, NvSubGdiRect, 0x02fc, 1);
  236. OUT_RING(chan, 3);
  237. FIRE_RING(chan);
  238. return 0;
  239. }