nvc0_fbcon.c 6.9 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. nvc0_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_NVC0(chan, NvSub2D, 0x02ac, 1);
  39. OUT_RING (chan, 1);
  40. }
  41. BEGIN_NVC0(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_NVC0(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_NVC0(chan, NvSub2D, 0x02ac, 1);
  54. OUT_RING (chan, 3);
  55. }
  56. FIRE_RING(chan);
  57. return 0;
  58. }
  59. int
  60. nvc0_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_NVC0(chan, NvSub2D, 0x0110, 1);
  70. OUT_RING (chan, 0);
  71. BEGIN_NVC0(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_NVC0(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. nvc0_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_NVC0(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_NVC0(chan, NvSub2D, 0x0838, 2);
  109. OUT_RING (chan, image->width);
  110. OUT_RING (chan, image->height);
  111. BEGIN_NVC0(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_NIC0(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. nvc0_fbcon_accel_init(struct fb_info *info)
  132. {
  133. struct nouveau_fbdev *nfbdev = info->par;
  134. struct drm_device *dev = nfbdev->dev;
  135. struct nouveau_framebuffer *fb = &nfbdev->nouveau_fb;
  136. struct nouveau_drm *drm = nouveau_drm(dev);
  137. struct nouveau_channel *chan = drm->channel;
  138. int ret, format;
  139. ret = nvif_object_init(&chan->user, 0x902d, 0x902d, NULL, 0,
  140. &nfbdev->twod);
  141. if (ret)
  142. return ret;
  143. switch (info->var.bits_per_pixel) {
  144. case 8:
  145. format = 0xf3;
  146. break;
  147. case 15:
  148. format = 0xf8;
  149. break;
  150. case 16:
  151. format = 0xe8;
  152. break;
  153. case 32:
  154. switch (info->var.transp.length) {
  155. case 0: /* depth 24 */
  156. case 8: /* depth 32, just use 24.. */
  157. format = 0xe6;
  158. break;
  159. case 2: /* depth 30 */
  160. format = 0xd1;
  161. break;
  162. default:
  163. return -EINVAL;
  164. }
  165. break;
  166. default:
  167. return -EINVAL;
  168. }
  169. ret = RING_SPACE(chan, 58);
  170. if (ret) {
  171. WARN_ON(1);
  172. nouveau_fbcon_gpu_lockup(info);
  173. return ret;
  174. }
  175. BEGIN_NVC0(chan, NvSub2D, 0x0000, 1);
  176. OUT_RING (chan, nfbdev->twod.handle);
  177. BEGIN_NVC0(chan, NvSub2D, 0x0290, 1);
  178. OUT_RING (chan, 0);
  179. BEGIN_NVC0(chan, NvSub2D, 0x0888, 1);
  180. OUT_RING (chan, 1);
  181. BEGIN_NVC0(chan, NvSub2D, 0x02ac, 1);
  182. OUT_RING (chan, 3);
  183. BEGIN_NVC0(chan, NvSub2D, 0x02a0, 1);
  184. OUT_RING (chan, 0x55);
  185. BEGIN_NVC0(chan, NvSub2D, 0x08c0, 4);
  186. OUT_RING (chan, 0);
  187. OUT_RING (chan, 1);
  188. OUT_RING (chan, 0);
  189. OUT_RING (chan, 1);
  190. BEGIN_NVC0(chan, NvSub2D, 0x0580, 2);
  191. OUT_RING (chan, 4);
  192. OUT_RING (chan, format);
  193. BEGIN_NVC0(chan, NvSub2D, 0x02e8, 2);
  194. OUT_RING (chan, 2);
  195. OUT_RING (chan, 1);
  196. BEGIN_NVC0(chan, NvSub2D, 0x0804, 1);
  197. OUT_RING (chan, format);
  198. BEGIN_NVC0(chan, NvSub2D, 0x0800, 1);
  199. OUT_RING (chan, 1);
  200. BEGIN_NVC0(chan, NvSub2D, 0x0808, 3);
  201. OUT_RING (chan, 0);
  202. OUT_RING (chan, 0);
  203. OUT_RING (chan, 1);
  204. BEGIN_NVC0(chan, NvSub2D, 0x081c, 1);
  205. OUT_RING (chan, 1);
  206. BEGIN_NVC0(chan, NvSub2D, 0x0840, 4);
  207. OUT_RING (chan, 0);
  208. OUT_RING (chan, 1);
  209. OUT_RING (chan, 0);
  210. OUT_RING (chan, 1);
  211. BEGIN_NVC0(chan, NvSub2D, 0x0200, 10);
  212. OUT_RING (chan, format);
  213. OUT_RING (chan, 1);
  214. OUT_RING (chan, 0);
  215. OUT_RING (chan, 1);
  216. OUT_RING (chan, 0);
  217. OUT_RING (chan, info->fix.line_length);
  218. OUT_RING (chan, info->var.xres_virtual);
  219. OUT_RING (chan, info->var.yres_virtual);
  220. OUT_RING (chan, upper_32_bits(fb->vma.offset));
  221. OUT_RING (chan, lower_32_bits(fb->vma.offset));
  222. BEGIN_NVC0(chan, NvSub2D, 0x0230, 10);
  223. OUT_RING (chan, format);
  224. OUT_RING (chan, 1);
  225. OUT_RING (chan, 0);
  226. OUT_RING (chan, 1);
  227. OUT_RING (chan, 0);
  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. FIRE_RING (chan);
  234. return 0;
  235. }