nv04_fbcon.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. /*
  2. * Copyright 2009 Ben Skeggs
  3. * Copyright 2008 Stuart Bennett
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. * and/or sell copies of the Software, and to permit persons to whom the
  10. * Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice (including the next
  13. * paragraph) shall be included in all copies or substantial portions of the
  14. * Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  21. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  22. * DEALINGS IN THE SOFTWARE.
  23. */
  24. #define NVIF_DEBUG_PRINT_DISABLE
  25. #include "nouveau_drv.h"
  26. #include "nouveau_dma.h"
  27. #include "nouveau_fbcon.h"
  28. #include <nvif/push006c.h>
  29. int
  30. nv04_fbcon_copyarea(struct fb_info *info, const struct fb_copyarea *region)
  31. {
  32. struct nouveau_fbdev *nfbdev = info->par;
  33. struct nouveau_drm *drm = nouveau_drm(nfbdev->helper.dev);
  34. struct nouveau_channel *chan = drm->channel;
  35. struct nvif_push *push = chan->chan.push;
  36. int ret;
  37. ret = PUSH_WAIT(push, 4);
  38. if (ret)
  39. return ret;
  40. PUSH_NVSQ(push, NV05F, 0x0300, (region->sy << 16) | region->sx,
  41. 0x0304, (region->dy << 16) | region->dx,
  42. 0x0308, (region->height << 16) | region->width);
  43. PUSH_KICK(push);
  44. return 0;
  45. }
  46. int
  47. nv04_fbcon_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
  48. {
  49. struct nouveau_fbdev *nfbdev = info->par;
  50. struct nouveau_drm *drm = nouveau_drm(nfbdev->helper.dev);
  51. struct nouveau_channel *chan = drm->channel;
  52. struct nvif_push *push = chan->chan.push;
  53. int ret;
  54. ret = PUSH_WAIT(push, 7);
  55. if (ret)
  56. return ret;
  57. PUSH_NVSQ(push, NV04A, 0x02fc, (rect->rop != ROP_COPY) ? 1 : 3);
  58. if (info->fix.visual == FB_VISUAL_TRUECOLOR ||
  59. info->fix.visual == FB_VISUAL_DIRECTCOLOR)
  60. PUSH_NVSQ(push, NV04A, 0x03fc, ((uint32_t *)info->pseudo_palette)[rect->color]);
  61. else
  62. PUSH_NVSQ(push, NV04A, 0x03fc, rect->color);
  63. PUSH_NVSQ(push, NV04A, 0x0400, (rect->dx << 16) | rect->dy,
  64. 0x0404, (rect->width << 16) | rect->height);
  65. PUSH_KICK(push);
  66. return 0;
  67. }
  68. int
  69. nv04_fbcon_imageblit(struct fb_info *info, const struct fb_image *image)
  70. {
  71. struct nouveau_fbdev *nfbdev = info->par;
  72. struct nouveau_drm *drm = nouveau_drm(nfbdev->helper.dev);
  73. struct nouveau_channel *chan = drm->channel;
  74. struct nvif_push *push = chan->chan.push;
  75. uint32_t fg;
  76. uint32_t bg;
  77. uint32_t dsize;
  78. uint32_t *data = (uint32_t *)image->data;
  79. int ret;
  80. if (image->depth != 1)
  81. return -ENODEV;
  82. ret = PUSH_WAIT(push, 8);
  83. if (ret)
  84. return ret;
  85. if (info->fix.visual == FB_VISUAL_TRUECOLOR ||
  86. info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
  87. fg = ((uint32_t *) info->pseudo_palette)[image->fg_color];
  88. bg = ((uint32_t *) info->pseudo_palette)[image->bg_color];
  89. } else {
  90. fg = image->fg_color;
  91. bg = image->bg_color;
  92. }
  93. PUSH_NVSQ(push, NV04A, 0x0be4, (image->dy << 16) | (image->dx & 0xffff),
  94. 0x0be8, ((image->dy + image->height) << 16) |
  95. ((image->dx + image->width) & 0xffff),
  96. 0x0bec, bg,
  97. 0x0bf0, fg,
  98. 0x0bf4, (image->height << 16) | ALIGN(image->width, 8),
  99. 0x0bf8, (image->height << 16) | image->width,
  100. 0x0bfc, (image->dy << 16) | (image->dx & 0xffff));
  101. dsize = ALIGN(ALIGN(image->width, 8) * image->height, 32) >> 5;
  102. while (dsize) {
  103. int iter_len = dsize > 128 ? 128 : dsize;
  104. ret = PUSH_WAIT(push, iter_len + 1);
  105. if (ret)
  106. return ret;
  107. PUSH_NVSQ(push, NV04A, 0x0c00, data, iter_len);
  108. data += iter_len;
  109. dsize -= iter_len;
  110. }
  111. PUSH_KICK(push);
  112. return 0;
  113. }
  114. int
  115. nv04_fbcon_accel_init(struct fb_info *info)
  116. {
  117. struct nouveau_fbdev *nfbdev = info->par;
  118. struct drm_device *dev = nfbdev->helper.dev;
  119. struct nouveau_drm *drm = nouveau_drm(dev);
  120. struct nouveau_channel *chan = drm->channel;
  121. struct nvif_device *device = &drm->client.device;
  122. struct nvif_push *push = chan->chan.push;
  123. int surface_fmt, pattern_fmt, rect_fmt;
  124. int ret;
  125. switch (info->var.bits_per_pixel) {
  126. case 8:
  127. surface_fmt = 1;
  128. pattern_fmt = 3;
  129. rect_fmt = 3;
  130. break;
  131. case 16:
  132. surface_fmt = 4;
  133. pattern_fmt = 1;
  134. rect_fmt = 1;
  135. break;
  136. case 32:
  137. switch (info->var.transp.length) {
  138. case 0: /* depth 24 */
  139. case 8: /* depth 32 */
  140. break;
  141. default:
  142. return -EINVAL;
  143. }
  144. surface_fmt = 6;
  145. pattern_fmt = 3;
  146. rect_fmt = 3;
  147. break;
  148. default:
  149. return -EINVAL;
  150. }
  151. ret = nvif_object_ctor(&chan->user, "fbconCtxSurf2d", 0x0062,
  152. device->info.family >= NV_DEVICE_INFO_V0_CELSIUS ?
  153. 0x0062 : 0x0042, NULL, 0, &nfbdev->surf2d);
  154. if (ret)
  155. return ret;
  156. ret = nvif_object_ctor(&chan->user, "fbconCtxClip", 0x0019, 0x0019,
  157. NULL, 0, &nfbdev->clip);
  158. if (ret)
  159. return ret;
  160. ret = nvif_object_ctor(&chan->user, "fbconCtxRop", 0x0043, 0x0043,
  161. NULL, 0, &nfbdev->rop);
  162. if (ret)
  163. return ret;
  164. ret = nvif_object_ctor(&chan->user, "fbconCtxPatt", 0x0044, 0x0044,
  165. NULL, 0, &nfbdev->patt);
  166. if (ret)
  167. return ret;
  168. ret = nvif_object_ctor(&chan->user, "fbconGdiRectText", 0x004a, 0x004a,
  169. NULL, 0, &nfbdev->gdi);
  170. if (ret)
  171. return ret;
  172. ret = nvif_object_ctor(&chan->user, "fbconImageBlit", 0x005f,
  173. device->info.chipset >= 0x11 ? 0x009f : 0x005f,
  174. NULL, 0, &nfbdev->blit);
  175. if (ret)
  176. return ret;
  177. if (PUSH_WAIT(push, 49 + (device->info.chipset >= 0x11 ? 4 : 0))) {
  178. nouveau_fbcon_gpu_lockup(info);
  179. return 0;
  180. }
  181. PUSH_NVSQ(push, NV042, 0x0000, nfbdev->surf2d.handle);
  182. PUSH_NVSQ(push, NV042, 0x0184, chan->vram.handle,
  183. 0x0188, chan->vram.handle);
  184. PUSH_NVSQ(push, NV042, 0x0300, surface_fmt,
  185. 0x0304, info->fix.line_length | (info->fix.line_length << 16),
  186. 0x0308, info->fix.smem_start - dev->mode_config.fb_base,
  187. 0x030c, info->fix.smem_start - dev->mode_config.fb_base);
  188. PUSH_NVSQ(push, NV043, 0x0000, nfbdev->rop.handle);
  189. PUSH_NVSQ(push, NV043, 0x0300, 0x55);
  190. PUSH_NVSQ(push, NV044, 0x0000, nfbdev->patt.handle);
  191. PUSH_NVSQ(push, NV044, 0x0300, pattern_fmt,
  192. #ifdef __BIG_ENDIAN
  193. 0x0304, 2,
  194. #else
  195. 0x0304, 1,
  196. #endif
  197. 0x0308, 0,
  198. 0x030c, 1,
  199. 0x0310, ~0,
  200. 0x0314, ~0,
  201. 0x0318, ~0,
  202. 0x031c, ~0);
  203. PUSH_NVSQ(push, NV019, 0x0000, nfbdev->clip.handle);
  204. PUSH_NVSQ(push, NV019, 0x0300, 0,
  205. 0x0304, (info->var.yres_virtual << 16) | info->var.xres_virtual);
  206. PUSH_NVSQ(push, NV05F, 0x0000, nfbdev->blit.handle);
  207. PUSH_NVSQ(push, NV05F, 0x019c, nfbdev->surf2d.handle);
  208. PUSH_NVSQ(push, NV05F, 0x02fc, 3);
  209. if (nfbdev->blit.oclass == 0x009f) {
  210. PUSH_NVSQ(push, NV09F, 0x0120, 0,
  211. 0x0124, 1,
  212. 0x0128, 2);
  213. }
  214. PUSH_NVSQ(push, NV04A, 0x0000, nfbdev->gdi.handle);
  215. PUSH_NVSQ(push, NV04A, 0x0198, nfbdev->surf2d.handle);
  216. PUSH_NVSQ(push, NV04A, 0x0188, nfbdev->patt.handle,
  217. 0x018c, nfbdev->rop.handle);
  218. PUSH_NVSQ(push, NV04A, 0x0304, 1);
  219. PUSH_NVSQ(push, NV04A, 0x0300, rect_fmt);
  220. PUSH_NVSQ(push, NV04A, 0x02fc, 3);
  221. PUSH_KICK(push);
  222. return 0;
  223. }