nv04_fbcon.c 7.7 KB

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