nv04_fbcon.c 7.5 KB

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