nv04_fbcon.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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. void
  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. if (info->state != FBINFO_STATE_RUNNING)
  37. return;
  38. if (!(info->flags & FBINFO_HWACCEL_DISABLED) && RING_SPACE(chan, 4)) {
  39. nouveau_fbcon_gpu_lockup(info);
  40. }
  41. if (info->flags & FBINFO_HWACCEL_DISABLED) {
  42. cfb_copyarea(info, region);
  43. return;
  44. }
  45. BEGIN_RING(chan, NvSubImageBlit, 0x0300, 3);
  46. OUT_RING(chan, (region->sy << 16) | region->sx);
  47. OUT_RING(chan, (region->dy << 16) | region->dx);
  48. OUT_RING(chan, (region->height << 16) | region->width);
  49. FIRE_RING(chan);
  50. }
  51. void
  52. nv04_fbcon_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
  53. {
  54. struct nouveau_fbdev *nfbdev = info->par;
  55. struct drm_device *dev = nfbdev->dev;
  56. struct drm_nouveau_private *dev_priv = dev->dev_private;
  57. struct nouveau_channel *chan = dev_priv->channel;
  58. if (info->state != FBINFO_STATE_RUNNING)
  59. return;
  60. if (!(info->flags & FBINFO_HWACCEL_DISABLED) && RING_SPACE(chan, 7)) {
  61. nouveau_fbcon_gpu_lockup(info);
  62. }
  63. if (info->flags & FBINFO_HWACCEL_DISABLED) {
  64. cfb_fillrect(info, rect);
  65. return;
  66. }
  67. BEGIN_RING(chan, NvSubGdiRect, 0x02fc, 1);
  68. OUT_RING(chan, (rect->rop != ROP_COPY) ? 1 : 3);
  69. BEGIN_RING(chan, NvSubGdiRect, 0x03fc, 1);
  70. if (info->fix.visual == FB_VISUAL_TRUECOLOR ||
  71. info->fix.visual == FB_VISUAL_DIRECTCOLOR)
  72. OUT_RING(chan, ((uint32_t *)info->pseudo_palette)[rect->color]);
  73. else
  74. OUT_RING(chan, rect->color);
  75. BEGIN_RING(chan, NvSubGdiRect, 0x0400, 2);
  76. OUT_RING(chan, (rect->dx << 16) | rect->dy);
  77. OUT_RING(chan, (rect->width << 16) | rect->height);
  78. FIRE_RING(chan);
  79. }
  80. void
  81. nv04_fbcon_imageblit(struct fb_info *info, const struct fb_image *image)
  82. {
  83. struct nouveau_fbdev *nfbdev = info->par;
  84. struct drm_device *dev = nfbdev->dev;
  85. struct drm_nouveau_private *dev_priv = dev->dev_private;
  86. struct nouveau_channel *chan = dev_priv->channel;
  87. uint32_t fg;
  88. uint32_t bg;
  89. uint32_t dsize;
  90. uint32_t width;
  91. uint32_t *data = (uint32_t *)image->data;
  92. if (info->state != FBINFO_STATE_RUNNING)
  93. return;
  94. if (image->depth != 1) {
  95. cfb_imageblit(info, image);
  96. return;
  97. }
  98. if (!(info->flags & FBINFO_HWACCEL_DISABLED) && RING_SPACE(chan, 8)) {
  99. nouveau_fbcon_gpu_lockup(info);
  100. }
  101. if (info->flags & FBINFO_HWACCEL_DISABLED) {
  102. cfb_imageblit(info, image);
  103. return;
  104. }
  105. width = ALIGN(image->width, 8);
  106. dsize = ALIGN(width * image->height, 32) >> 5;
  107. if (info->fix.visual == FB_VISUAL_TRUECOLOR ||
  108. info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
  109. fg = ((uint32_t *) info->pseudo_palette)[image->fg_color];
  110. bg = ((uint32_t *) info->pseudo_palette)[image->bg_color];
  111. } else {
  112. fg = image->fg_color;
  113. bg = image->bg_color;
  114. }
  115. BEGIN_RING(chan, NvSubGdiRect, 0x0be4, 7);
  116. OUT_RING(chan, (image->dy << 16) | (image->dx & 0xffff));
  117. OUT_RING(chan, ((image->dy + image->height) << 16) |
  118. ((image->dx + image->width) & 0xffff));
  119. OUT_RING(chan, bg);
  120. OUT_RING(chan, fg);
  121. OUT_RING(chan, (image->height << 16) | width);
  122. OUT_RING(chan, (image->height << 16) | image->width);
  123. OUT_RING(chan, (image->dy << 16) | (image->dx & 0xffff));
  124. while (dsize) {
  125. int iter_len = dsize > 128 ? 128 : dsize;
  126. if (RING_SPACE(chan, iter_len + 1)) {
  127. nouveau_fbcon_gpu_lockup(info);
  128. cfb_imageblit(info, image);
  129. return;
  130. }
  131. BEGIN_RING(chan, NvSubGdiRect, 0x0c00, iter_len);
  132. OUT_RINGp(chan, data, iter_len);
  133. data += iter_len;
  134. dsize -= iter_len;
  135. }
  136. FIRE_RING(chan);
  137. }
  138. static int
  139. nv04_fbcon_grobj_new(struct drm_device *dev, int class, uint32_t handle)
  140. {
  141. struct drm_nouveau_private *dev_priv = dev->dev_private;
  142. struct nouveau_gpuobj *obj = NULL;
  143. int ret;
  144. ret = nouveau_gpuobj_gr_new(dev_priv->channel, class, &obj);
  145. if (ret)
  146. return ret;
  147. ret = nouveau_ramht_insert(dev_priv->channel, handle, obj);
  148. nouveau_gpuobj_ref(NULL, &obj);
  149. return ret;
  150. }
  151. int
  152. nv04_fbcon_accel_init(struct fb_info *info)
  153. {
  154. struct nouveau_fbdev *nfbdev = info->par;
  155. struct drm_device *dev = nfbdev->dev;
  156. struct drm_nouveau_private *dev_priv = dev->dev_private;
  157. struct nouveau_channel *chan = dev_priv->channel;
  158. const int sub = NvSubCtxSurf2D;
  159. int surface_fmt, pattern_fmt, rect_fmt;
  160. int ret;
  161. switch (info->var.bits_per_pixel) {
  162. case 8:
  163. surface_fmt = 1;
  164. pattern_fmt = 3;
  165. rect_fmt = 3;
  166. break;
  167. case 16:
  168. surface_fmt = 4;
  169. pattern_fmt = 1;
  170. rect_fmt = 1;
  171. break;
  172. case 32:
  173. switch (info->var.transp.length) {
  174. case 0: /* depth 24 */
  175. case 8: /* depth 32 */
  176. break;
  177. default:
  178. return -EINVAL;
  179. }
  180. surface_fmt = 6;
  181. pattern_fmt = 3;
  182. rect_fmt = 3;
  183. break;
  184. default:
  185. return -EINVAL;
  186. }
  187. ret = nv04_fbcon_grobj_new(dev, dev_priv->card_type >= NV_10 ?
  188. 0x0062 : 0x0042, NvCtxSurf2D);
  189. if (ret)
  190. return ret;
  191. ret = nv04_fbcon_grobj_new(dev, 0x0019, NvClipRect);
  192. if (ret)
  193. return ret;
  194. ret = nv04_fbcon_grobj_new(dev, 0x0043, NvRop);
  195. if (ret)
  196. return ret;
  197. ret = nv04_fbcon_grobj_new(dev, 0x0044, NvImagePatt);
  198. if (ret)
  199. return ret;
  200. ret = nv04_fbcon_grobj_new(dev, 0x004a, NvGdiRect);
  201. if (ret)
  202. return ret;
  203. ret = nv04_fbcon_grobj_new(dev, dev_priv->chipset >= 0x11 ?
  204. 0x009f : 0x005f, NvImageBlit);
  205. if (ret)
  206. return ret;
  207. if (RING_SPACE(chan, 49)) {
  208. nouveau_fbcon_gpu_lockup(info);
  209. return 0;
  210. }
  211. BEGIN_RING(chan, sub, 0x0000, 1);
  212. OUT_RING(chan, NvCtxSurf2D);
  213. BEGIN_RING(chan, sub, 0x0184, 2);
  214. OUT_RING(chan, NvDmaFB);
  215. OUT_RING(chan, NvDmaFB);
  216. BEGIN_RING(chan, sub, 0x0300, 4);
  217. OUT_RING(chan, surface_fmt);
  218. OUT_RING(chan, info->fix.line_length | (info->fix.line_length << 16));
  219. OUT_RING(chan, info->fix.smem_start - dev->mode_config.fb_base);
  220. OUT_RING(chan, info->fix.smem_start - dev->mode_config.fb_base);
  221. BEGIN_RING(chan, sub, 0x0000, 1);
  222. OUT_RING(chan, NvRop);
  223. BEGIN_RING(chan, sub, 0x0300, 1);
  224. OUT_RING(chan, 0x55);
  225. BEGIN_RING(chan, sub, 0x0000, 1);
  226. OUT_RING(chan, NvImagePatt);
  227. BEGIN_RING(chan, sub, 0x0300, 8);
  228. OUT_RING(chan, pattern_fmt);
  229. #ifdef __BIG_ENDIAN
  230. OUT_RING(chan, 2);
  231. #else
  232. OUT_RING(chan, 1);
  233. #endif
  234. OUT_RING(chan, 0);
  235. OUT_RING(chan, 1);
  236. OUT_RING(chan, ~0);
  237. OUT_RING(chan, ~0);
  238. OUT_RING(chan, ~0);
  239. OUT_RING(chan, ~0);
  240. BEGIN_RING(chan, sub, 0x0000, 1);
  241. OUT_RING(chan, NvClipRect);
  242. BEGIN_RING(chan, sub, 0x0300, 2);
  243. OUT_RING(chan, 0);
  244. OUT_RING(chan, (info->var.yres_virtual << 16) | info->var.xres_virtual);
  245. BEGIN_RING(chan, NvSubImageBlit, 0x0000, 1);
  246. OUT_RING(chan, NvImageBlit);
  247. BEGIN_RING(chan, NvSubImageBlit, 0x019c, 1);
  248. OUT_RING(chan, NvCtxSurf2D);
  249. BEGIN_RING(chan, NvSubImageBlit, 0x02fc, 1);
  250. OUT_RING(chan, 3);
  251. BEGIN_RING(chan, NvSubGdiRect, 0x0000, 1);
  252. OUT_RING(chan, NvGdiRect);
  253. BEGIN_RING(chan, NvSubGdiRect, 0x0198, 1);
  254. OUT_RING(chan, NvCtxSurf2D);
  255. BEGIN_RING(chan, NvSubGdiRect, 0x0188, 2);
  256. OUT_RING(chan, NvImagePatt);
  257. OUT_RING(chan, NvRop);
  258. BEGIN_RING(chan, NvSubGdiRect, 0x0304, 1);
  259. OUT_RING(chan, 1);
  260. BEGIN_RING(chan, NvSubGdiRect, 0x0300, 1);
  261. OUT_RING(chan, rect_fmt);
  262. BEGIN_RING(chan, NvSubGdiRect, 0x02fc, 1);
  263. OUT_RING(chan, 3);
  264. FIRE_RING(chan);
  265. return 0;
  266. }