nv04_fbcon.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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. 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. NV_ERROR(dev, "GPU lockup - switching to software fbcon\n");
  209. info->flags |= FBINFO_HWACCEL_DISABLED;
  210. return 0;
  211. }
  212. BEGIN_RING(chan, 1, 0x0000, 1);
  213. OUT_RING(chan, NvCtxSurf2D);
  214. BEGIN_RING(chan, 1, 0x0184, 2);
  215. OUT_RING(chan, NvDmaFB);
  216. OUT_RING(chan, NvDmaFB);
  217. BEGIN_RING(chan, 1, 0x0300, 4);
  218. OUT_RING(chan, surface_fmt);
  219. OUT_RING(chan, info->fix.line_length | (info->fix.line_length << 16));
  220. OUT_RING(chan, info->fix.smem_start - dev->mode_config.fb_base);
  221. OUT_RING(chan, info->fix.smem_start - dev->mode_config.fb_base);
  222. BEGIN_RING(chan, 1, 0x0000, 1);
  223. OUT_RING(chan, NvRop);
  224. BEGIN_RING(chan, 1, 0x0300, 1);
  225. OUT_RING(chan, 0x55);
  226. BEGIN_RING(chan, 1, 0x0000, 1);
  227. OUT_RING(chan, NvImagePatt);
  228. BEGIN_RING(chan, 1, 0x0300, 8);
  229. OUT_RING(chan, pattern_fmt);
  230. #ifdef __BIG_ENDIAN
  231. OUT_RING(chan, 2);
  232. #else
  233. OUT_RING(chan, 1);
  234. #endif
  235. OUT_RING(chan, 0);
  236. OUT_RING(chan, 1);
  237. OUT_RING(chan, ~0);
  238. OUT_RING(chan, ~0);
  239. OUT_RING(chan, ~0);
  240. OUT_RING(chan, ~0);
  241. BEGIN_RING(chan, 1, 0x0000, 1);
  242. OUT_RING(chan, NvClipRect);
  243. BEGIN_RING(chan, 1, 0x0300, 2);
  244. OUT_RING(chan, 0);
  245. OUT_RING(chan, (info->var.yres_virtual << 16) | info->var.xres_virtual);
  246. BEGIN_RING(chan, NvSubImageBlit, 0x0000, 1);
  247. OUT_RING(chan, NvImageBlit);
  248. BEGIN_RING(chan, NvSubImageBlit, 0x019c, 1);
  249. OUT_RING(chan, NvCtxSurf2D);
  250. BEGIN_RING(chan, NvSubImageBlit, 0x02fc, 1);
  251. OUT_RING(chan, 3);
  252. BEGIN_RING(chan, NvSubGdiRect, 0x0000, 1);
  253. OUT_RING(chan, NvGdiRect);
  254. BEGIN_RING(chan, NvSubGdiRect, 0x0198, 1);
  255. OUT_RING(chan, NvCtxSurf2D);
  256. BEGIN_RING(chan, NvSubGdiRect, 0x0188, 2);
  257. OUT_RING(chan, NvImagePatt);
  258. OUT_RING(chan, NvRop);
  259. BEGIN_RING(chan, NvSubGdiRect, 0x0304, 1);
  260. OUT_RING(chan, 1);
  261. BEGIN_RING(chan, NvSubGdiRect, 0x0300, 1);
  262. OUT_RING(chan, rect_fmt);
  263. BEGIN_RING(chan, NvSubGdiRect, 0x02fc, 1);
  264. OUT_RING(chan, 3);
  265. FIRE_RING(chan);
  266. info->fbops->fb_fillrect = nv04_fbcon_fillrect;
  267. info->fbops->fb_copyarea = nv04_fbcon_copyarea;
  268. info->fbops->fb_imageblit = nv04_fbcon_imageblit;
  269. return 0;
  270. }