nv50_fbcon.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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. #define NVIF_DEBUG_PRINT_DISABLE
  25. #include "nouveau_drv.h"
  26. #include "nouveau_dma.h"
  27. #include "nouveau_fbcon.h"
  28. #include "nouveau_vmm.h"
  29. #include <nvif/push206e.h>
  30. #include <nvhw/class/cl502d.h>
  31. int
  32. nv50_fbcon_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
  33. {
  34. struct nouveau_fbdev *nfbdev = info->par;
  35. struct nouveau_drm *drm = nouveau_drm(nfbdev->helper.dev);
  36. struct nouveau_channel *chan = drm->channel;
  37. struct nvif_push *push = chan->chan.push;
  38. u32 colour;
  39. int ret;
  40. if (info->fix.visual == FB_VISUAL_TRUECOLOR ||
  41. info->fix.visual == FB_VISUAL_DIRECTCOLOR)
  42. colour = ((uint32_t *)info->pseudo_palette)[rect->color];
  43. else
  44. colour = rect->color;
  45. ret = PUSH_WAIT(push, rect->rop == ROP_COPY ? 7 : 11);
  46. if (ret)
  47. return ret;
  48. if (rect->rop != ROP_COPY) {
  49. PUSH_MTHD(push, NV502D, SET_OPERATION,
  50. NVDEF(NV502D, SET_OPERATION, V, ROP_AND));
  51. }
  52. PUSH_MTHD(push, NV502D, SET_RENDER_SOLID_PRIM_COLOR, colour);
  53. PUSH_MTHD(push, NV502D, RENDER_SOLID_PRIM_POINT_SET_X(0), rect->dx,
  54. RENDER_SOLID_PRIM_POINT_Y(0), rect->dy,
  55. RENDER_SOLID_PRIM_POINT_SET_X(1), rect->dx + rect->width,
  56. RENDER_SOLID_PRIM_POINT_Y(1), rect->dy + rect->height);
  57. if (rect->rop != ROP_COPY) {
  58. PUSH_MTHD(push, NV502D, SET_OPERATION,
  59. NVDEF(NV502D, SET_OPERATION, V, SRCCOPY));
  60. }
  61. PUSH_KICK(push);
  62. return 0;
  63. }
  64. int
  65. nv50_fbcon_copyarea(struct fb_info *info, const struct fb_copyarea *region)
  66. {
  67. struct nouveau_fbdev *nfbdev = info->par;
  68. struct nouveau_drm *drm = nouveau_drm(nfbdev->helper.dev);
  69. struct nouveau_channel *chan = drm->channel;
  70. struct nvif_push *push = chan->chan.push;
  71. int ret;
  72. ret = PUSH_WAIT(push, 12);
  73. if (ret)
  74. return ret;
  75. PUSH_MTHD(push, NV502D, WAIT_FOR_IDLE, 0);
  76. PUSH_MTHD(push, NV502D, SET_PIXELS_FROM_MEMORY_DST_X0, region->dx,
  77. SET_PIXELS_FROM_MEMORY_DST_Y0, region->dy,
  78. SET_PIXELS_FROM_MEMORY_DST_WIDTH, region->width,
  79. SET_PIXELS_FROM_MEMORY_DST_HEIGHT, region->height);
  80. PUSH_MTHD(push, NV502D, SET_PIXELS_FROM_MEMORY_SRC_X0_FRAC, 0,
  81. SET_PIXELS_FROM_MEMORY_SRC_X0_INT, region->sx,
  82. SET_PIXELS_FROM_MEMORY_SRC_Y0_FRAC, 0,
  83. PIXELS_FROM_MEMORY_SRC_Y0_INT, region->sy);
  84. PUSH_KICK(push);
  85. return 0;
  86. }
  87. int
  88. nv50_fbcon_imageblit(struct fb_info *info, const struct fb_image *image)
  89. {
  90. struct nouveau_fbdev *nfbdev = info->par;
  91. struct nouveau_drm *drm = nouveau_drm(nfbdev->helper.dev);
  92. struct nouveau_channel *chan = drm->channel;
  93. struct nvif_push *push = chan->chan.push;
  94. uint32_t dwords, *data = (uint32_t *)image->data;
  95. uint32_t mask = ~(~0 >> (32 - info->var.bits_per_pixel));
  96. uint32_t *palette = info->pseudo_palette, bg, fg;
  97. int ret;
  98. if (image->depth != 1)
  99. return -ENODEV;
  100. if (info->fix.visual == FB_VISUAL_TRUECOLOR ||
  101. info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
  102. bg = palette[image->bg_color] | mask;
  103. fg = palette[image->fg_color] | mask;
  104. } else {
  105. bg = image->bg_color;
  106. fg = image->fg_color;
  107. }
  108. ret = PUSH_WAIT(push, 11);
  109. if (ret)
  110. return ret;
  111. PUSH_MTHD(push, NV502D, SET_PIXELS_FROM_CPU_COLOR0, bg,
  112. SET_PIXELS_FROM_CPU_COLOR1, fg);
  113. PUSH_MTHD(push, NV502D, SET_PIXELS_FROM_CPU_SRC_WIDTH, image->width,
  114. SET_PIXELS_FROM_CPU_SRC_HEIGHT, image->height);
  115. PUSH_MTHD(push, NV502D, SET_PIXELS_FROM_CPU_DST_X0_FRAC, 0,
  116. SET_PIXELS_FROM_CPU_DST_X0_INT, image->dx,
  117. SET_PIXELS_FROM_CPU_DST_Y0_FRAC, 0,
  118. SET_PIXELS_FROM_CPU_DST_Y0_INT, image->dy);
  119. dwords = ALIGN(ALIGN(image->width, 8) * image->height, 32) >> 5;
  120. while (dwords) {
  121. int count = dwords > 2047 ? 2047 : dwords;
  122. ret = PUSH_WAIT(push, count + 1);
  123. if (ret)
  124. return ret;
  125. dwords -= count;
  126. PUSH_NINC(push, NV502D, PIXELS_FROM_CPU_DATA, data, count);
  127. data += count;
  128. }
  129. PUSH_KICK(push);
  130. return 0;
  131. }
  132. int
  133. nv50_fbcon_accel_init(struct fb_info *info)
  134. {
  135. struct nouveau_fbdev *nfbdev = info->par;
  136. struct drm_device *dev = nfbdev->helper.dev;
  137. struct nouveau_drm *drm = nouveau_drm(dev);
  138. struct nouveau_channel *chan = drm->channel;
  139. struct nvif_push *push = chan->chan.push;
  140. int ret, format;
  141. switch (info->var.bits_per_pixel) {
  142. case 8:
  143. format = NV502D_SET_DST_FORMAT_V_Y8;
  144. break;
  145. case 15:
  146. format = NV502D_SET_DST_FORMAT_V_X1R5G5B5;
  147. break;
  148. case 16:
  149. format = NV502D_SET_DST_FORMAT_V_R5G6B5;
  150. break;
  151. case 32:
  152. switch (info->var.transp.length) {
  153. case 0: /* depth 24 */
  154. case 8: /* depth 32, just use 24.. */
  155. format = NV502D_SET_DST_FORMAT_V_X8R8G8B8;
  156. break;
  157. case 2: /* depth 30 */
  158. format = NV502D_SET_DST_FORMAT_V_A2B10G10R10;
  159. break;
  160. default:
  161. return -EINVAL;
  162. }
  163. break;
  164. default:
  165. return -EINVAL;
  166. }
  167. ret = nvif_object_ctor(&chan->user, "fbconTwoD", 0x502d, 0x502d,
  168. NULL, 0, &nfbdev->twod);
  169. if (ret)
  170. return ret;
  171. ret = PUSH_WAIT(push, 56);
  172. if (ret) {
  173. nouveau_fbcon_gpu_lockup(info);
  174. return ret;
  175. }
  176. PUSH_MTHD(push, NV502D, SET_OBJECT, nfbdev->twod.handle);
  177. PUSH_MTHD(push, NV502D, SET_DST_CONTEXT_DMA, chan->vram.handle,
  178. SET_SRC_CONTEXT_DMA, chan->vram.handle,
  179. SET_SEMAPHORE_CONTEXT_DMA, chan->vram.handle);
  180. PUSH_MTHD(push, NV502D, SET_DST_FORMAT,
  181. NVVAL(NV502D, SET_DST_FORMAT, V, format),
  182. SET_DST_MEMORY_LAYOUT,
  183. NVDEF(NV502D, SET_DST_MEMORY_LAYOUT, V, PITCH));
  184. PUSH_MTHD(push, NV502D, SET_DST_PITCH, info->fix.line_length,
  185. SET_DST_WIDTH, info->var.xres_virtual,
  186. SET_DST_HEIGHT, info->var.yres_virtual,
  187. SET_DST_OFFSET_UPPER,
  188. NVVAL(NV502D, SET_DST_OFFSET_UPPER, V, upper_32_bits(nfbdev->vma->addr)),
  189. SET_DST_OFFSET_LOWER,
  190. NVVAL(NV502D, SET_DST_OFFSET_LOWER, V, lower_32_bits(nfbdev->vma->addr)));
  191. PUSH_MTHD(push, NV502D, SET_SRC_FORMAT,
  192. NVVAL(NV502D, SET_SRC_FORMAT, V, format),
  193. SET_SRC_MEMORY_LAYOUT,
  194. NVDEF(NV502D, SET_SRC_MEMORY_LAYOUT, V, PITCH));
  195. PUSH_MTHD(push, NV502D, SET_SRC_PITCH, info->fix.line_length,
  196. SET_SRC_WIDTH, info->var.xres_virtual,
  197. SET_SRC_HEIGHT, info->var.yres_virtual,
  198. SET_SRC_OFFSET_UPPER,
  199. NVVAL(NV502D, SET_SRC_OFFSET_UPPER, V, upper_32_bits(nfbdev->vma->addr)),
  200. SET_SRC_OFFSET_LOWER,
  201. NVVAL(NV502D, SET_SRC_OFFSET_LOWER, V, lower_32_bits(nfbdev->vma->addr)));
  202. PUSH_MTHD(push, NV502D, SET_CLIP_ENABLE,
  203. NVDEF(NV502D, SET_CLIP_ENABLE, V, FALSE));
  204. PUSH_MTHD(push, NV502D, SET_ROP,
  205. NVVAL(NV502D, SET_ROP, V, 0x55));
  206. PUSH_MTHD(push, NV502D, SET_OPERATION,
  207. NVDEF(NV502D, SET_OPERATION, V, SRCCOPY));
  208. PUSH_MTHD(push, NV502D, SET_MONOCHROME_PATTERN_COLOR_FORMAT,
  209. NVDEF(NV502D, SET_MONOCHROME_PATTERN_COLOR_FORMAT, V, A8R8G8B8),
  210. SET_MONOCHROME_PATTERN_FORMAT,
  211. NVDEF(NV502D, SET_MONOCHROME_PATTERN_FORMAT, V, LE_M1));
  212. PUSH_MTHD(push, NV502D, RENDER_SOLID_PRIM_MODE,
  213. NVDEF(NV502D, RENDER_SOLID_PRIM_MODE, V, RECTS),
  214. SET_RENDER_SOLID_PRIM_COLOR_FORMAT,
  215. NVVAL(NV502D, SET_RENDER_SOLID_PRIM_COLOR_FORMAT, V, format));
  216. PUSH_MTHD(push, NV502D, SET_PIXELS_FROM_CPU_DATA_TYPE,
  217. NVDEF(NV502D, SET_PIXELS_FROM_CPU_DATA_TYPE, V, INDEX),
  218. SET_PIXELS_FROM_CPU_COLOR_FORMAT,
  219. NVVAL(NV502D, SET_PIXELS_FROM_CPU_COLOR_FORMAT, V, format),
  220. SET_PIXELS_FROM_CPU_INDEX_FORMAT,
  221. NVDEF(NV502D, SET_PIXELS_FROM_CPU_INDEX_FORMAT, V, I1),
  222. SET_PIXELS_FROM_CPU_MONO_FORMAT,
  223. NVDEF(NV502D, SET_PIXELS_FROM_CPU_MONO_FORMAT, V, CGA6_M1),
  224. SET_PIXELS_FROM_CPU_WRAP,
  225. NVDEF(NV502D, SET_PIXELS_FROM_CPU_WRAP, V, WRAP_BYTE));
  226. PUSH_MTHD(push, NV502D, SET_PIXELS_FROM_CPU_MONO_OPACITY,
  227. NVDEF(NV502D, SET_PIXELS_FROM_CPU_MONO_OPACITY, V, OPAQUE));
  228. PUSH_MTHD(push, NV502D, SET_PIXELS_FROM_CPU_DX_DU_FRAC, 0,
  229. SET_PIXELS_FROM_CPU_DX_DU_INT, 1,
  230. SET_PIXELS_FROM_CPU_DY_DV_FRAC, 0,
  231. SET_PIXELS_FROM_CPU_DY_DV_INT, 1);
  232. PUSH_MTHD(push, NV502D, SET_PIXELS_FROM_MEMORY_SAFE_OVERLAP,
  233. NVDEF(NV502D, SET_PIXELS_FROM_MEMORY_SAFE_OVERLAP, V, TRUE));
  234. PUSH_MTHD(push, NV502D, SET_PIXELS_FROM_MEMORY_DU_DX_FRAC, 0,
  235. SET_PIXELS_FROM_MEMORY_DU_DX_INT, 1,
  236. SET_PIXELS_FROM_MEMORY_DV_DY_FRAC, 0,
  237. SET_PIXELS_FROM_MEMORY_DV_DY_INT, 1);
  238. PUSH_KICK(push);
  239. return 0;
  240. }