nv50_fbcon.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. /*
  2. * Copyright 2010 Red Hat Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. * Authors: Ben Skeggs
  23. */
  24. #include "nouveau_drm.h"
  25. #include "nouveau_dma.h"
  26. #include "nouveau_fbcon.h"
  27. int
  28. nv50_fbcon_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
  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, rect->rop == ROP_COPY ? 7 : 11);
  35. if (ret)
  36. return ret;
  37. if (rect->rop != ROP_COPY) {
  38. BEGIN_NV04(chan, NvSub2D, 0x02ac, 1);
  39. OUT_RING(chan, 1);
  40. }
  41. BEGIN_NV04(chan, NvSub2D, 0x0588, 1);
  42. if (info->fix.visual == FB_VISUAL_TRUECOLOR ||
  43. info->fix.visual == FB_VISUAL_DIRECTCOLOR)
  44. OUT_RING(chan, ((uint32_t *)info->pseudo_palette)[rect->color]);
  45. else
  46. OUT_RING(chan, rect->color);
  47. BEGIN_NV04(chan, NvSub2D, 0x0600, 4);
  48. OUT_RING(chan, rect->dx);
  49. OUT_RING(chan, rect->dy);
  50. OUT_RING(chan, rect->dx + rect->width);
  51. OUT_RING(chan, rect->dy + rect->height);
  52. if (rect->rop != ROP_COPY) {
  53. BEGIN_NV04(chan, NvSub2D, 0x02ac, 1);
  54. OUT_RING(chan, 3);
  55. }
  56. FIRE_RING(chan);
  57. return 0;
  58. }
  59. int
  60. nv50_fbcon_copyarea(struct fb_info *info, const struct fb_copyarea *region)
  61. {
  62. struct nouveau_fbdev *nfbdev = info->par;
  63. struct nouveau_drm *drm = nouveau_drm(nfbdev->dev);
  64. struct nouveau_channel *chan = drm->channel;
  65. int ret;
  66. ret = RING_SPACE(chan, 12);
  67. if (ret)
  68. return ret;
  69. BEGIN_NV04(chan, NvSub2D, 0x0110, 1);
  70. OUT_RING(chan, 0);
  71. BEGIN_NV04(chan, NvSub2D, 0x08b0, 4);
  72. OUT_RING(chan, region->dx);
  73. OUT_RING(chan, region->dy);
  74. OUT_RING(chan, region->width);
  75. OUT_RING(chan, region->height);
  76. BEGIN_NV04(chan, NvSub2D, 0x08d0, 4);
  77. OUT_RING(chan, 0);
  78. OUT_RING(chan, region->sx);
  79. OUT_RING(chan, 0);
  80. OUT_RING(chan, region->sy);
  81. FIRE_RING(chan);
  82. return 0;
  83. }
  84. int
  85. nv50_fbcon_imageblit(struct fb_info *info, const struct fb_image *image)
  86. {
  87. struct nouveau_fbdev *nfbdev = info->par;
  88. struct nouveau_drm *drm = nouveau_drm(nfbdev->dev);
  89. struct nouveau_channel *chan = drm->channel;
  90. uint32_t dwords, *data = (uint32_t *)image->data;
  91. uint32_t mask = ~(~0 >> (32 - info->var.bits_per_pixel));
  92. uint32_t *palette = info->pseudo_palette;
  93. int ret;
  94. if (image->depth != 1)
  95. return -ENODEV;
  96. ret = RING_SPACE(chan, 11);
  97. if (ret)
  98. return ret;
  99. BEGIN_NV04(chan, NvSub2D, 0x0814, 2);
  100. if (info->fix.visual == FB_VISUAL_TRUECOLOR ||
  101. info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
  102. OUT_RING(chan, palette[image->bg_color] | mask);
  103. OUT_RING(chan, palette[image->fg_color] | mask);
  104. } else {
  105. OUT_RING(chan, image->bg_color);
  106. OUT_RING(chan, image->fg_color);
  107. }
  108. BEGIN_NV04(chan, NvSub2D, 0x0838, 2);
  109. OUT_RING(chan, image->width);
  110. OUT_RING(chan, image->height);
  111. BEGIN_NV04(chan, NvSub2D, 0x0850, 4);
  112. OUT_RING(chan, 0);
  113. OUT_RING(chan, image->dx);
  114. OUT_RING(chan, 0);
  115. OUT_RING(chan, image->dy);
  116. dwords = ALIGN(ALIGN(image->width, 8) * image->height, 32) >> 5;
  117. while (dwords) {
  118. int push = dwords > 2047 ? 2047 : dwords;
  119. ret = RING_SPACE(chan, push + 1);
  120. if (ret)
  121. return ret;
  122. dwords -= push;
  123. BEGIN_NI04(chan, NvSub2D, 0x0860, push);
  124. OUT_RINGp(chan, data, push);
  125. data += push;
  126. }
  127. FIRE_RING(chan);
  128. return 0;
  129. }
  130. int
  131. nv50_fbcon_accel_init(struct fb_info *info)
  132. {
  133. struct nouveau_fbdev *nfbdev = info->par;
  134. struct nouveau_framebuffer *fb = &nfbdev->nouveau_fb;
  135. struct drm_device *dev = nfbdev->dev;
  136. struct nouveau_drm *drm = nouveau_drm(dev);
  137. struct nouveau_channel *chan = drm->channel;
  138. int ret, format;
  139. switch (info->var.bits_per_pixel) {
  140. case 8:
  141. format = 0xf3;
  142. break;
  143. case 15:
  144. format = 0xf8;
  145. break;
  146. case 16:
  147. format = 0xe8;
  148. break;
  149. case 32:
  150. switch (info->var.transp.length) {
  151. case 0: /* depth 24 */
  152. case 8: /* depth 32, just use 24.. */
  153. format = 0xe6;
  154. break;
  155. case 2: /* depth 30 */
  156. format = 0xd1;
  157. break;
  158. default:
  159. return -EINVAL;
  160. }
  161. break;
  162. default:
  163. return -EINVAL;
  164. }
  165. ret = nvif_object_init(&chan->user, 0x502d, 0x502d, NULL, 0,
  166. &nfbdev->twod);
  167. if (ret)
  168. return ret;
  169. ret = RING_SPACE(chan, 58);
  170. if (ret) {
  171. nouveau_fbcon_gpu_lockup(info);
  172. return ret;
  173. }
  174. BEGIN_NV04(chan, NvSub2D, 0x0000, 1);
  175. OUT_RING(chan, nfbdev->twod.handle);
  176. BEGIN_NV04(chan, NvSub2D, 0x0184, 3);
  177. OUT_RING(chan, chan->vram.handle);
  178. OUT_RING(chan, chan->vram.handle);
  179. OUT_RING(chan, chan->vram.handle);
  180. BEGIN_NV04(chan, NvSub2D, 0x0290, 1);
  181. OUT_RING(chan, 0);
  182. BEGIN_NV04(chan, NvSub2D, 0x0888, 1);
  183. OUT_RING(chan, 1);
  184. BEGIN_NV04(chan, NvSub2D, 0x02ac, 1);
  185. OUT_RING(chan, 3);
  186. BEGIN_NV04(chan, NvSub2D, 0x02a0, 1);
  187. OUT_RING(chan, 0x55);
  188. BEGIN_NV04(chan, NvSub2D, 0x08c0, 4);
  189. OUT_RING(chan, 0);
  190. OUT_RING(chan, 1);
  191. OUT_RING(chan, 0);
  192. OUT_RING(chan, 1);
  193. BEGIN_NV04(chan, NvSub2D, 0x0580, 2);
  194. OUT_RING(chan, 4);
  195. OUT_RING(chan, format);
  196. BEGIN_NV04(chan, NvSub2D, 0x02e8, 2);
  197. OUT_RING(chan, 2);
  198. OUT_RING(chan, 1);
  199. BEGIN_NV04(chan, NvSub2D, 0x0804, 1);
  200. OUT_RING(chan, format);
  201. BEGIN_NV04(chan, NvSub2D, 0x0800, 1);
  202. OUT_RING(chan, 1);
  203. BEGIN_NV04(chan, NvSub2D, 0x0808, 3);
  204. OUT_RING(chan, 0);
  205. OUT_RING(chan, 0);
  206. OUT_RING(chan, 1);
  207. BEGIN_NV04(chan, NvSub2D, 0x081c, 1);
  208. OUT_RING(chan, 1);
  209. BEGIN_NV04(chan, NvSub2D, 0x0840, 4);
  210. OUT_RING(chan, 0);
  211. OUT_RING(chan, 1);
  212. OUT_RING(chan, 0);
  213. OUT_RING(chan, 1);
  214. BEGIN_NV04(chan, NvSub2D, 0x0200, 2);
  215. OUT_RING(chan, format);
  216. OUT_RING(chan, 1);
  217. BEGIN_NV04(chan, NvSub2D, 0x0214, 5);
  218. OUT_RING(chan, info->fix.line_length);
  219. OUT_RING(chan, info->var.xres_virtual);
  220. OUT_RING(chan, info->var.yres_virtual);
  221. OUT_RING(chan, upper_32_bits(fb->vma.offset));
  222. OUT_RING(chan, lower_32_bits(fb->vma.offset));
  223. BEGIN_NV04(chan, NvSub2D, 0x0230, 2);
  224. OUT_RING(chan, format);
  225. OUT_RING(chan, 1);
  226. BEGIN_NV04(chan, NvSub2D, 0x0244, 5);
  227. OUT_RING(chan, info->fix.line_length);
  228. OUT_RING(chan, info->var.xres_virtual);
  229. OUT_RING(chan, info->var.yres_virtual);
  230. OUT_RING(chan, upper_32_bits(fb->vma.offset));
  231. OUT_RING(chan, lower_32_bits(fb->vma.offset));
  232. FIRE_RING(chan);
  233. return 0;
  234. }