nv04_fbcon.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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_fbcon.h"
  28. static void
  29. nv04_fbcon_copyarea(struct fb_info *info, const struct fb_copyarea *region)
  30. {
  31. struct nouveau_fbcon_par *par = info->par;
  32. struct drm_device *dev = par->dev;
  33. struct drm_nouveau_private *dev_priv = dev->dev_private;
  34. struct nouveau_channel *chan = dev_priv->channel;
  35. if (info->state != FBINFO_STATE_RUNNING)
  36. return;
  37. if (!(info->flags & FBINFO_HWACCEL_DISABLED) && RING_SPACE(chan, 4)) {
  38. nouveau_fbcon_gpu_lockup(info);
  39. }
  40. if (info->flags & FBINFO_HWACCEL_DISABLED) {
  41. cfb_copyarea(info, region);
  42. return;
  43. }
  44. BEGIN_RING(chan, NvSubImageBlit, 0x0300, 3);
  45. OUT_RING(chan, (region->sy << 16) | region->sx);
  46. OUT_RING(chan, (region->dy << 16) | region->dx);
  47. OUT_RING(chan, (region->height << 16) | region->width);
  48. FIRE_RING(chan);
  49. }
  50. static void
  51. nv04_fbcon_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
  52. {
  53. struct nouveau_fbcon_par *par = info->par;
  54. struct drm_device *dev = par->dev;
  55. struct drm_nouveau_private *dev_priv = dev->dev_private;
  56. struct nouveau_channel *chan = dev_priv->channel;
  57. if (info->state != FBINFO_STATE_RUNNING)
  58. return;
  59. if (!(info->flags & FBINFO_HWACCEL_DISABLED) && RING_SPACE(chan, 7)) {
  60. nouveau_fbcon_gpu_lockup(info);
  61. }
  62. if (info->flags & FBINFO_HWACCEL_DISABLED) {
  63. cfb_fillrect(info, rect);
  64. return;
  65. }
  66. BEGIN_RING(chan, NvSubGdiRect, 0x02fc, 1);
  67. OUT_RING(chan, (rect->rop != ROP_COPY) ? 1 : 3);
  68. BEGIN_RING(chan, NvSubGdiRect, 0x03fc, 1);
  69. if (info->fix.visual == FB_VISUAL_TRUECOLOR ||
  70. info->fix.visual == FB_VISUAL_DIRECTCOLOR)
  71. OUT_RING(chan, ((uint32_t *)info->pseudo_palette)[rect->color]);
  72. else
  73. OUT_RING(chan, rect->color);
  74. BEGIN_RING(chan, NvSubGdiRect, 0x0400, 2);
  75. OUT_RING(chan, (rect->dx << 16) | rect->dy);
  76. OUT_RING(chan, (rect->width << 16) | rect->height);
  77. FIRE_RING(chan);
  78. }
  79. static void
  80. nv04_fbcon_imageblit(struct fb_info *info, const struct fb_image *image)
  81. {
  82. struct nouveau_fbcon_par *par = info->par;
  83. struct drm_device *dev = par->dev;
  84. struct drm_nouveau_private *dev_priv = dev->dev_private;
  85. struct nouveau_channel *chan = dev_priv->channel;
  86. uint32_t fg;
  87. uint32_t bg;
  88. uint32_t dsize;
  89. uint32_t width;
  90. uint32_t *data = (uint32_t *)image->data;
  91. if (info->state != FBINFO_STATE_RUNNING)
  92. return;
  93. if (image->depth != 1) {
  94. cfb_imageblit(info, image);
  95. return;
  96. }
  97. if (!(info->flags & FBINFO_HWACCEL_DISABLED) && RING_SPACE(chan, 8)) {
  98. nouveau_fbcon_gpu_lockup(info);
  99. }
  100. if (info->flags & FBINFO_HWACCEL_DISABLED) {
  101. cfb_imageblit(info, image);
  102. return;
  103. }
  104. width = (image->width + 31) & ~31;
  105. dsize = (width * image->height) >> 5;
  106. if (info->fix.visual == FB_VISUAL_TRUECOLOR ||
  107. info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
  108. fg = ((uint32_t *) info->pseudo_palette)[image->fg_color];
  109. bg = ((uint32_t *) info->pseudo_palette)[image->bg_color];
  110. } else {
  111. fg = image->fg_color;
  112. bg = image->bg_color;
  113. }
  114. BEGIN_RING(chan, NvSubGdiRect, 0x0be4, 7);
  115. OUT_RING(chan, (image->dy << 16) | (image->dx & 0xffff));
  116. OUT_RING(chan, ((image->dy + image->height) << 16) |
  117. ((image->dx + image->width) & 0xffff));
  118. OUT_RING(chan, bg);
  119. OUT_RING(chan, fg);
  120. OUT_RING(chan, (image->height << 16) | image->width);
  121. OUT_RING(chan, (image->height << 16) | width);
  122. OUT_RING(chan, (image->dy << 16) | (image->dx & 0xffff));
  123. while (dsize) {
  124. int iter_len = dsize > 128 ? 128 : dsize;
  125. if (RING_SPACE(chan, iter_len + 1)) {
  126. nouveau_fbcon_gpu_lockup(info);
  127. cfb_imageblit(info, image);
  128. return;
  129. }
  130. BEGIN_RING(chan, NvSubGdiRect, 0x0c00, iter_len);
  131. OUT_RINGp(chan, data, iter_len);
  132. data += iter_len;
  133. dsize -= iter_len;
  134. }
  135. FIRE_RING(chan);
  136. }
  137. static int
  138. nv04_fbcon_grobj_new(struct drm_device *dev, int class, uint32_t handle)
  139. {
  140. struct drm_nouveau_private *dev_priv = dev->dev_private;
  141. struct nouveau_gpuobj *obj = NULL;
  142. int ret;
  143. ret = nouveau_gpuobj_gr_new(dev_priv->channel, class, &obj);
  144. if (ret)
  145. return ret;
  146. ret = nouveau_gpuobj_ref_add(dev, dev_priv->channel, handle, obj, NULL);
  147. if (ret)
  148. return ret;
  149. return 0;
  150. }
  151. int
  152. nv04_fbcon_accel_init(struct fb_info *info)
  153. {
  154. struct nouveau_fbcon_par *par = info->par;
  155. struct drm_device *dev = par->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->card_type >= NV_10 ?
  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. info->fbops->fb_fillrect = nv04_fbcon_fillrect;
  266. info->fbops->fb_copyarea = nv04_fbcon_copyarea;
  267. info->fbops->fb_imageblit = nv04_fbcon_imageblit;
  268. return 0;
  269. }