nv50_fbcon.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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 width, 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. width = ALIGN(image->width, 32);
  100. dwords = (width * image->height) >> 5;
  101. BEGIN_NV04(chan, NvSub2D, 0x0814, 2);
  102. if (info->fix.visual == FB_VISUAL_TRUECOLOR ||
  103. info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
  104. OUT_RING(chan, palette[image->bg_color] | mask);
  105. OUT_RING(chan, palette[image->fg_color] | mask);
  106. } else {
  107. OUT_RING(chan, image->bg_color);
  108. OUT_RING(chan, image->fg_color);
  109. }
  110. BEGIN_NV04(chan, NvSub2D, 0x0838, 2);
  111. OUT_RING(chan, image->width);
  112. OUT_RING(chan, image->height);
  113. BEGIN_NV04(chan, NvSub2D, 0x0850, 4);
  114. OUT_RING(chan, 0);
  115. OUT_RING(chan, image->dx);
  116. OUT_RING(chan, 0);
  117. OUT_RING(chan, image->dy);
  118. while (dwords) {
  119. int push = dwords > 2047 ? 2047 : dwords;
  120. ret = RING_SPACE(chan, push + 1);
  121. if (ret)
  122. return ret;
  123. dwords -= push;
  124. BEGIN_NI04(chan, NvSub2D, 0x0860, push);
  125. OUT_RINGp(chan, data, push);
  126. data += push;
  127. }
  128. FIRE_RING(chan);
  129. return 0;
  130. }
  131. int
  132. nv50_fbcon_accel_init(struct fb_info *info)
  133. {
  134. struct nouveau_fbdev *nfbdev = info->par;
  135. struct nouveau_framebuffer *fb = &nfbdev->nouveau_fb;
  136. struct drm_device *dev = nfbdev->dev;
  137. struct nouveau_drm *drm = nouveau_drm(dev);
  138. struct nouveau_channel *chan = drm->channel;
  139. int ret, format;
  140. switch (info->var.bits_per_pixel) {
  141. case 8:
  142. format = 0xf3;
  143. break;
  144. case 15:
  145. format = 0xf8;
  146. break;
  147. case 16:
  148. format = 0xe8;
  149. break;
  150. case 32:
  151. switch (info->var.transp.length) {
  152. case 0: /* depth 24 */
  153. case 8: /* depth 32, just use 24.. */
  154. format = 0xe6;
  155. break;
  156. case 2: /* depth 30 */
  157. format = 0xd1;
  158. break;
  159. default:
  160. return -EINVAL;
  161. }
  162. break;
  163. default:
  164. return -EINVAL;
  165. }
  166. ret = nvif_object_init(chan->object, NULL, 0x502d, 0x502d, NULL, 0,
  167. &nfbdev->twod);
  168. if (ret)
  169. return ret;
  170. ret = RING_SPACE(chan, 59);
  171. if (ret) {
  172. nouveau_fbcon_gpu_lockup(info);
  173. return ret;
  174. }
  175. BEGIN_NV04(chan, NvSub2D, 0x0000, 1);
  176. OUT_RING(chan, nfbdev->twod.handle);
  177. BEGIN_NV04(chan, NvSub2D, 0x0184, 3);
  178. OUT_RING(chan, chan->vram.handle);
  179. OUT_RING(chan, chan->vram.handle);
  180. OUT_RING(chan, chan->vram.handle);
  181. BEGIN_NV04(chan, NvSub2D, 0x0290, 1);
  182. OUT_RING(chan, 0);
  183. BEGIN_NV04(chan, NvSub2D, 0x0888, 1);
  184. OUT_RING(chan, 1);
  185. BEGIN_NV04(chan, NvSub2D, 0x02ac, 1);
  186. OUT_RING(chan, 3);
  187. BEGIN_NV04(chan, NvSub2D, 0x02a0, 1);
  188. OUT_RING(chan, 0x55);
  189. BEGIN_NV04(chan, NvSub2D, 0x08c0, 4);
  190. OUT_RING(chan, 0);
  191. OUT_RING(chan, 1);
  192. OUT_RING(chan, 0);
  193. OUT_RING(chan, 1);
  194. BEGIN_NV04(chan, NvSub2D, 0x0580, 2);
  195. OUT_RING(chan, 4);
  196. OUT_RING(chan, format);
  197. BEGIN_NV04(chan, NvSub2D, 0x02e8, 2);
  198. OUT_RING(chan, 2);
  199. OUT_RING(chan, 1);
  200. BEGIN_NV04(chan, NvSub2D, 0x0804, 1);
  201. OUT_RING(chan, format);
  202. BEGIN_NV04(chan, NvSub2D, 0x0800, 1);
  203. OUT_RING(chan, 1);
  204. BEGIN_NV04(chan, NvSub2D, 0x0808, 3);
  205. OUT_RING(chan, 0);
  206. OUT_RING(chan, 0);
  207. OUT_RING(chan, 1);
  208. BEGIN_NV04(chan, NvSub2D, 0x081c, 1);
  209. OUT_RING(chan, 1);
  210. BEGIN_NV04(chan, NvSub2D, 0x0840, 4);
  211. OUT_RING(chan, 0);
  212. OUT_RING(chan, 1);
  213. OUT_RING(chan, 0);
  214. OUT_RING(chan, 1);
  215. BEGIN_NV04(chan, NvSub2D, 0x0200, 2);
  216. OUT_RING(chan, format);
  217. OUT_RING(chan, 1);
  218. BEGIN_NV04(chan, NvSub2D, 0x0214, 5);
  219. OUT_RING(chan, info->fix.line_length);
  220. OUT_RING(chan, info->var.xres_virtual);
  221. OUT_RING(chan, info->var.yres_virtual);
  222. OUT_RING(chan, upper_32_bits(fb->vma.offset));
  223. OUT_RING(chan, lower_32_bits(fb->vma.offset));
  224. BEGIN_NV04(chan, NvSub2D, 0x0230, 2);
  225. OUT_RING(chan, format);
  226. OUT_RING(chan, 1);
  227. BEGIN_NV04(chan, NvSub2D, 0x0244, 5);
  228. OUT_RING(chan, info->fix.line_length);
  229. OUT_RING(chan, info->var.xres_virtual);
  230. OUT_RING(chan, info->var.yres_virtual);
  231. OUT_RING(chan, upper_32_bits(fb->vma.offset));
  232. OUT_RING(chan, lower_32_bits(fb->vma.offset));
  233. return 0;
  234. }