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