nvc0_fbcon.c 6.9 KB

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