nv04_fbcon.c 8.7 KB

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