nv04_fbcon.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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. static int
  123. nv04_fbcon_grobj_new(struct drm_device *dev, int class, uint32_t handle)
  124. {
  125. struct drm_nouveau_private *dev_priv = dev->dev_private;
  126. struct nouveau_gpuobj *obj = NULL;
  127. int ret;
  128. ret = nouveau_gpuobj_gr_new(dev_priv->channel, class, &obj);
  129. if (ret)
  130. return ret;
  131. ret = nouveau_ramht_insert(dev_priv->channel, handle, obj);
  132. nouveau_gpuobj_ref(NULL, &obj);
  133. return ret;
  134. }
  135. int
  136. nv04_fbcon_accel_init(struct fb_info *info)
  137. {
  138. struct nouveau_fbdev *nfbdev = info->par;
  139. struct drm_device *dev = nfbdev->dev;
  140. struct drm_nouveau_private *dev_priv = dev->dev_private;
  141. struct nouveau_channel *chan = dev_priv->channel;
  142. const int sub = NvSubCtxSurf2D;
  143. int surface_fmt, pattern_fmt, rect_fmt;
  144. int ret;
  145. switch (info->var.bits_per_pixel) {
  146. case 8:
  147. surface_fmt = 1;
  148. pattern_fmt = 3;
  149. rect_fmt = 3;
  150. break;
  151. case 16:
  152. surface_fmt = 4;
  153. pattern_fmt = 1;
  154. rect_fmt = 1;
  155. break;
  156. case 32:
  157. switch (info->var.transp.length) {
  158. case 0: /* depth 24 */
  159. case 8: /* depth 32 */
  160. break;
  161. default:
  162. return -EINVAL;
  163. }
  164. surface_fmt = 6;
  165. pattern_fmt = 3;
  166. rect_fmt = 3;
  167. break;
  168. default:
  169. return -EINVAL;
  170. }
  171. ret = nv04_fbcon_grobj_new(dev, dev_priv->card_type >= NV_10 ?
  172. 0x0062 : 0x0042, NvCtxSurf2D);
  173. if (ret)
  174. return ret;
  175. ret = nv04_fbcon_grobj_new(dev, 0x0019, NvClipRect);
  176. if (ret)
  177. return ret;
  178. ret = nv04_fbcon_grobj_new(dev, 0x0043, NvRop);
  179. if (ret)
  180. return ret;
  181. ret = nv04_fbcon_grobj_new(dev, 0x0044, NvImagePatt);
  182. if (ret)
  183. return ret;
  184. ret = nv04_fbcon_grobj_new(dev, 0x004a, NvGdiRect);
  185. if (ret)
  186. return ret;
  187. ret = nv04_fbcon_grobj_new(dev, dev_priv->chipset >= 0x11 ?
  188. 0x009f : 0x005f, NvImageBlit);
  189. if (ret)
  190. return ret;
  191. if (RING_SPACE(chan, 49)) {
  192. nouveau_fbcon_gpu_lockup(info);
  193. return 0;
  194. }
  195. BEGIN_RING(chan, sub, 0x0000, 1);
  196. OUT_RING(chan, NvCtxSurf2D);
  197. BEGIN_RING(chan, sub, 0x0184, 2);
  198. OUT_RING(chan, NvDmaFB);
  199. OUT_RING(chan, NvDmaFB);
  200. BEGIN_RING(chan, sub, 0x0300, 4);
  201. OUT_RING(chan, surface_fmt);
  202. OUT_RING(chan, info->fix.line_length | (info->fix.line_length << 16));
  203. OUT_RING(chan, info->fix.smem_start - dev->mode_config.fb_base);
  204. OUT_RING(chan, info->fix.smem_start - dev->mode_config.fb_base);
  205. BEGIN_RING(chan, sub, 0x0000, 1);
  206. OUT_RING(chan, NvRop);
  207. BEGIN_RING(chan, sub, 0x0300, 1);
  208. OUT_RING(chan, 0x55);
  209. BEGIN_RING(chan, sub, 0x0000, 1);
  210. OUT_RING(chan, NvImagePatt);
  211. BEGIN_RING(chan, sub, 0x0300, 8);
  212. OUT_RING(chan, pattern_fmt);
  213. #ifdef __BIG_ENDIAN
  214. OUT_RING(chan, 2);
  215. #else
  216. OUT_RING(chan, 1);
  217. #endif
  218. OUT_RING(chan, 0);
  219. OUT_RING(chan, 1);
  220. OUT_RING(chan, ~0);
  221. OUT_RING(chan, ~0);
  222. OUT_RING(chan, ~0);
  223. OUT_RING(chan, ~0);
  224. BEGIN_RING(chan, sub, 0x0000, 1);
  225. OUT_RING(chan, NvClipRect);
  226. BEGIN_RING(chan, sub, 0x0300, 2);
  227. OUT_RING(chan, 0);
  228. OUT_RING(chan, (info->var.yres_virtual << 16) | info->var.xres_virtual);
  229. BEGIN_RING(chan, NvSubImageBlit, 0x0000, 1);
  230. OUT_RING(chan, NvImageBlit);
  231. BEGIN_RING(chan, NvSubImageBlit, 0x019c, 1);
  232. OUT_RING(chan, NvCtxSurf2D);
  233. BEGIN_RING(chan, NvSubImageBlit, 0x02fc, 1);
  234. OUT_RING(chan, 3);
  235. BEGIN_RING(chan, NvSubGdiRect, 0x0000, 1);
  236. OUT_RING(chan, NvGdiRect);
  237. BEGIN_RING(chan, NvSubGdiRect, 0x0198, 1);
  238. OUT_RING(chan, NvCtxSurf2D);
  239. BEGIN_RING(chan, NvSubGdiRect, 0x0188, 2);
  240. OUT_RING(chan, NvImagePatt);
  241. OUT_RING(chan, NvRop);
  242. BEGIN_RING(chan, NvSubGdiRect, 0x0304, 1);
  243. OUT_RING(chan, 1);
  244. BEGIN_RING(chan, NvSubGdiRect, 0x0300, 1);
  245. OUT_RING(chan, rect_fmt);
  246. BEGIN_RING(chan, NvSubGdiRect, 0x02fc, 1);
  247. OUT_RING(chan, 3);
  248. FIRE_RING(chan);
  249. return 0;
  250. }