nv04_fbcon.c 8.6 KB

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