nv50_fbcon.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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 "drmP.h"
  25. #include "nouveau_drv.h"
  26. #include "nouveau_dma.h"
  27. #include "nouveau_ramht.h"
  28. #include "nouveau_fbcon.h"
  29. #include "nouveau_mm.h"
  30. int
  31. nv50_fbcon_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
  32. {
  33. struct nouveau_fbdev *nfbdev = info->par;
  34. struct drm_device *dev = nfbdev->dev;
  35. struct drm_nouveau_private *dev_priv = dev->dev_private;
  36. struct nouveau_channel *chan = dev_priv->channel;
  37. int ret;
  38. ret = RING_SPACE(chan, rect->rop == ROP_COPY ? 7 : 11);
  39. if (ret)
  40. return ret;
  41. if (rect->rop != ROP_COPY) {
  42. BEGIN_RING(chan, NvSub2D, 0x02ac, 1);
  43. OUT_RING(chan, 1);
  44. }
  45. BEGIN_RING(chan, NvSub2D, 0x0588, 1);
  46. if (info->fix.visual == FB_VISUAL_TRUECOLOR ||
  47. info->fix.visual == FB_VISUAL_DIRECTCOLOR)
  48. OUT_RING(chan, ((uint32_t *)info->pseudo_palette)[rect->color]);
  49. else
  50. OUT_RING(chan, rect->color);
  51. BEGIN_RING(chan, NvSub2D, 0x0600, 4);
  52. OUT_RING(chan, rect->dx);
  53. OUT_RING(chan, rect->dy);
  54. OUT_RING(chan, rect->dx + rect->width);
  55. OUT_RING(chan, rect->dy + rect->height);
  56. if (rect->rop != ROP_COPY) {
  57. BEGIN_RING(chan, NvSub2D, 0x02ac, 1);
  58. OUT_RING(chan, 3);
  59. }
  60. FIRE_RING(chan);
  61. return 0;
  62. }
  63. int
  64. nv50_fbcon_copyarea(struct fb_info *info, const struct fb_copyarea *region)
  65. {
  66. struct nouveau_fbdev *nfbdev = info->par;
  67. struct drm_device *dev = nfbdev->dev;
  68. struct drm_nouveau_private *dev_priv = dev->dev_private;
  69. struct nouveau_channel *chan = dev_priv->channel;
  70. int ret;
  71. ret = RING_SPACE(chan, 12);
  72. if (ret)
  73. return ret;
  74. BEGIN_RING(chan, NvSub2D, 0x0110, 1);
  75. OUT_RING(chan, 0);
  76. BEGIN_RING(chan, NvSub2D, 0x08b0, 4);
  77. OUT_RING(chan, region->dx);
  78. OUT_RING(chan, region->dy);
  79. OUT_RING(chan, region->width);
  80. OUT_RING(chan, region->height);
  81. BEGIN_RING(chan, NvSub2D, 0x08d0, 4);
  82. OUT_RING(chan, 0);
  83. OUT_RING(chan, region->sx);
  84. OUT_RING(chan, 0);
  85. OUT_RING(chan, region->sy);
  86. FIRE_RING(chan);
  87. return 0;
  88. }
  89. int
  90. nv50_fbcon_imageblit(struct fb_info *info, const struct fb_image *image)
  91. {
  92. struct nouveau_fbdev *nfbdev = info->par;
  93. struct drm_device *dev = nfbdev->dev;
  94. struct drm_nouveau_private *dev_priv = dev->dev_private;
  95. struct nouveau_channel *chan = dev_priv->channel;
  96. uint32_t width, dwords, *data = (uint32_t *)image->data;
  97. uint32_t mask = ~(~0 >> (32 - info->var.bits_per_pixel));
  98. uint32_t *palette = info->pseudo_palette;
  99. int ret;
  100. if (image->depth != 1)
  101. return -ENODEV;
  102. ret = RING_SPACE(chan, 11);
  103. if (ret)
  104. return ret;
  105. width = ALIGN(image->width, 32);
  106. dwords = (width * image->height) >> 5;
  107. BEGIN_RING(chan, NvSub2D, 0x0814, 2);
  108. if (info->fix.visual == FB_VISUAL_TRUECOLOR ||
  109. info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
  110. OUT_RING(chan, palette[image->bg_color] | mask);
  111. OUT_RING(chan, palette[image->fg_color] | mask);
  112. } else {
  113. OUT_RING(chan, image->bg_color);
  114. OUT_RING(chan, image->fg_color);
  115. }
  116. BEGIN_RING(chan, NvSub2D, 0x0838, 2);
  117. OUT_RING(chan, image->width);
  118. OUT_RING(chan, image->height);
  119. BEGIN_RING(chan, NvSub2D, 0x0850, 4);
  120. OUT_RING(chan, 0);
  121. OUT_RING(chan, image->dx);
  122. OUT_RING(chan, 0);
  123. OUT_RING(chan, image->dy);
  124. while (dwords) {
  125. int push = dwords > 2047 ? 2047 : dwords;
  126. ret = RING_SPACE(chan, push + 1);
  127. if (ret)
  128. return ret;
  129. dwords -= push;
  130. BEGIN_RING(chan, NvSub2D, 0x40000860, push);
  131. OUT_RINGp(chan, data, push);
  132. data += push;
  133. }
  134. FIRE_RING(chan);
  135. return 0;
  136. }
  137. int
  138. nv50_fbcon_accel_init(struct fb_info *info)
  139. {
  140. struct nouveau_fbdev *nfbdev = info->par;
  141. struct drm_device *dev = nfbdev->dev;
  142. struct drm_nouveau_private *dev_priv = dev->dev_private;
  143. struct nouveau_channel *chan = dev_priv->channel;
  144. struct nouveau_framebuffer *fb = &nfbdev->nouveau_fb;
  145. int ret, format;
  146. switch (info->var.bits_per_pixel) {
  147. case 8:
  148. format = 0xf3;
  149. break;
  150. case 15:
  151. format = 0xf8;
  152. break;
  153. case 16:
  154. format = 0xe8;
  155. break;
  156. case 32:
  157. switch (info->var.transp.length) {
  158. case 0: /* depth 24 */
  159. case 8: /* depth 32, just use 24.. */
  160. format = 0xe6;
  161. break;
  162. case 2: /* depth 30 */
  163. format = 0xd1;
  164. break;
  165. default:
  166. return -EINVAL;
  167. }
  168. break;
  169. default:
  170. return -EINVAL;
  171. }
  172. ret = nouveau_gpuobj_gr_new(dev_priv->channel, Nv2D, 0x502d);
  173. if (ret)
  174. return ret;
  175. ret = RING_SPACE(chan, 59);
  176. if (ret) {
  177. nouveau_fbcon_gpu_lockup(info);
  178. return ret;
  179. }
  180. BEGIN_RING(chan, NvSub2D, 0x0000, 1);
  181. OUT_RING(chan, Nv2D);
  182. BEGIN_RING(chan, NvSub2D, 0x0180, 4);
  183. OUT_RING(chan, NvNotify0);
  184. OUT_RING(chan, chan->vram_handle);
  185. OUT_RING(chan, chan->vram_handle);
  186. OUT_RING(chan, chan->vram_handle);
  187. BEGIN_RING(chan, NvSub2D, 0x0290, 1);
  188. OUT_RING(chan, 0);
  189. BEGIN_RING(chan, NvSub2D, 0x0888, 1);
  190. OUT_RING(chan, 1);
  191. BEGIN_RING(chan, NvSub2D, 0x02ac, 1);
  192. OUT_RING(chan, 3);
  193. BEGIN_RING(chan, NvSub2D, 0x02a0, 1);
  194. OUT_RING(chan, 0x55);
  195. BEGIN_RING(chan, NvSub2D, 0x08c0, 4);
  196. OUT_RING(chan, 0);
  197. OUT_RING(chan, 1);
  198. OUT_RING(chan, 0);
  199. OUT_RING(chan, 1);
  200. BEGIN_RING(chan, NvSub2D, 0x0580, 2);
  201. OUT_RING(chan, 4);
  202. OUT_RING(chan, format);
  203. BEGIN_RING(chan, NvSub2D, 0x02e8, 2);
  204. OUT_RING(chan, 2);
  205. OUT_RING(chan, 1);
  206. BEGIN_RING(chan, NvSub2D, 0x0804, 1);
  207. OUT_RING(chan, format);
  208. BEGIN_RING(chan, NvSub2D, 0x0800, 1);
  209. OUT_RING(chan, 1);
  210. BEGIN_RING(chan, NvSub2D, 0x0808, 3);
  211. OUT_RING(chan, 0);
  212. OUT_RING(chan, 0);
  213. OUT_RING(chan, 1);
  214. BEGIN_RING(chan, NvSub2D, 0x081c, 1);
  215. OUT_RING(chan, 1);
  216. BEGIN_RING(chan, NvSub2D, 0x0840, 4);
  217. OUT_RING(chan, 0);
  218. OUT_RING(chan, 1);
  219. OUT_RING(chan, 0);
  220. OUT_RING(chan, 1);
  221. BEGIN_RING(chan, NvSub2D, 0x0200, 2);
  222. OUT_RING(chan, format);
  223. OUT_RING(chan, 1);
  224. BEGIN_RING(chan, NvSub2D, 0x0214, 5);
  225. OUT_RING(chan, info->fix.line_length);
  226. OUT_RING(chan, info->var.xres_virtual);
  227. OUT_RING(chan, info->var.yres_virtual);
  228. OUT_RING(chan, upper_32_bits(fb->vma.offset));
  229. OUT_RING(chan, lower_32_bits(fb->vma.offset));
  230. BEGIN_RING(chan, NvSub2D, 0x0230, 2);
  231. OUT_RING(chan, format);
  232. OUT_RING(chan, 1);
  233. BEGIN_RING(chan, NvSub2D, 0x0244, 5);
  234. OUT_RING(chan, info->fix.line_length);
  235. OUT_RING(chan, info->var.xres_virtual);
  236. OUT_RING(chan, info->var.yres_virtual);
  237. OUT_RING(chan, upper_32_bits(fb->vma.offset));
  238. OUT_RING(chan, lower_32_bits(fb->vma.offset));
  239. return 0;
  240. }