nv50_software.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*
  2. * Copyright 2012 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_ramht.h"
  27. #include "nouveau_software.h"
  28. #include "nv50_display.h"
  29. struct nv50_software_priv {
  30. struct nouveau_software_priv base;
  31. };
  32. struct nv50_software_chan {
  33. struct nouveau_software_chan base;
  34. struct {
  35. struct nouveau_gpuobj *object;
  36. } vblank;
  37. };
  38. static int
  39. mthd_dma_vblsem(struct nouveau_channel *chan, u32 class, u32 mthd, u32 data)
  40. {
  41. struct nv50_software_chan *pch = chan->engctx[NVOBJ_ENGINE_SW];
  42. struct nouveau_gpuobj *gpuobj;
  43. gpuobj = nouveau_ramht_find(chan, data);
  44. if (!gpuobj)
  45. return -ENOENT;
  46. if (nouveau_notifier_offset(gpuobj, NULL))
  47. return -EINVAL;
  48. pch->vblank.object = gpuobj;
  49. pch->base.vblank.offset = ~0;
  50. return 0;
  51. }
  52. static int
  53. mthd_vblsem_offset(struct nouveau_channel *chan, u32 class, u32 mthd, u32 data)
  54. {
  55. struct nv50_software_chan *pch = chan->engctx[NVOBJ_ENGINE_SW];
  56. if (nouveau_notifier_offset(pch->vblank.object, &data))
  57. return -ERANGE;
  58. pch->base.vblank.offset = data >> 2;
  59. return 0;
  60. }
  61. static int
  62. mthd_vblsem_value(struct nouveau_channel *chan, u32 class, u32 mthd, u32 data)
  63. {
  64. struct nv50_software_chan *pch = chan->engctx[NVOBJ_ENGINE_SW];
  65. pch->base.vblank.value = data;
  66. return 0;
  67. }
  68. static int
  69. mthd_vblsem_release(struct nouveau_channel *chan, u32 class, u32 mthd, u32 data)
  70. {
  71. struct nv50_software_priv *psw = nv_engine(chan->dev, NVOBJ_ENGINE_SW);
  72. struct nv50_software_chan *pch = chan->engctx[NVOBJ_ENGINE_SW];
  73. struct drm_device *dev = chan->dev;
  74. if (!pch->vblank.object || pch->base.vblank.offset == ~0 || data > 1)
  75. return -EINVAL;
  76. drm_vblank_get(dev, data);
  77. pch->base.vblank.head = data;
  78. list_add(&pch->base.vblank.list, &psw->base.vblank);
  79. return 0;
  80. }
  81. static int
  82. mthd_flip(struct nouveau_channel *chan, u32 class, u32 mthd, u32 data)
  83. {
  84. nouveau_finish_page_flip(chan, NULL);
  85. return 0;
  86. }
  87. static int
  88. nv50_software_context_new(struct nouveau_channel *chan, int engine)
  89. {
  90. struct nv50_software_priv *psw = nv_engine(chan->dev, NVOBJ_ENGINE_SW);
  91. struct nv50_display *pdisp = nv50_display(chan->dev);
  92. struct nv50_software_chan *pch;
  93. int ret = 0, i;
  94. pch = kzalloc(sizeof(*pch), GFP_KERNEL);
  95. if (!pch)
  96. return -ENOMEM;
  97. nouveau_software_context_new(&pch->base);
  98. pch->base.vblank.bo = chan->notifier_bo;
  99. chan->engctx[engine] = pch;
  100. /* dma objects for display sync channel semaphore blocks */
  101. for (i = 0; i < chan->dev->mode_config.num_crtc; i++) {
  102. struct nv50_display_crtc *dispc = &pdisp->crtc[i];
  103. struct nouveau_gpuobj *obj = NULL;
  104. ret = nouveau_gpuobj_dma_new(chan, NV_CLASS_DMA_IN_MEMORY,
  105. dispc->sem.bo->bo.offset, 0x1000,
  106. NV_MEM_ACCESS_RW,
  107. NV_MEM_TARGET_VRAM, &obj);
  108. if (ret)
  109. break;
  110. ret = nouveau_ramht_insert(chan, NvEvoSema0 + i, obj);
  111. nouveau_gpuobj_ref(NULL, &obj);
  112. }
  113. if (ret)
  114. psw->base.base.context_del(chan, engine);
  115. return ret;
  116. }
  117. static void
  118. nv50_software_context_del(struct nouveau_channel *chan, int engine)
  119. {
  120. struct nv50_software_chan *pch = chan->engctx[engine];
  121. chan->engctx[engine] = NULL;
  122. kfree(pch);
  123. }
  124. static int
  125. nv50_software_object_new(struct nouveau_channel *chan, int engine,
  126. u32 handle, u16 class)
  127. {
  128. struct drm_device *dev = chan->dev;
  129. struct nouveau_gpuobj *obj = NULL;
  130. int ret;
  131. ret = nouveau_gpuobj_new(dev, chan, 16, 16, 0, &obj);
  132. if (ret)
  133. return ret;
  134. obj->engine = 0;
  135. obj->class = class;
  136. ret = nouveau_ramht_insert(chan, handle, obj);
  137. nouveau_gpuobj_ref(NULL, &obj);
  138. return ret;
  139. }
  140. static int
  141. nv50_software_init(struct drm_device *dev, int engine)
  142. {
  143. return 0;
  144. }
  145. static int
  146. nv50_software_fini(struct drm_device *dev, int engine, bool suspend)
  147. {
  148. return 0;
  149. }
  150. static void
  151. nv50_software_destroy(struct drm_device *dev, int engine)
  152. {
  153. struct nv50_software_priv *psw = nv_engine(dev, engine);
  154. NVOBJ_ENGINE_DEL(dev, SW);
  155. kfree(psw);
  156. }
  157. int
  158. nv50_software_create(struct drm_device *dev)
  159. {
  160. struct nv50_software_priv *psw = kzalloc(sizeof(*psw), GFP_KERNEL);
  161. if (!psw)
  162. return -ENOMEM;
  163. psw->base.base.destroy = nv50_software_destroy;
  164. psw->base.base.init = nv50_software_init;
  165. psw->base.base.fini = nv50_software_fini;
  166. psw->base.base.context_new = nv50_software_context_new;
  167. psw->base.base.context_del = nv50_software_context_del;
  168. psw->base.base.object_new = nv50_software_object_new;
  169. nouveau_software_create(&psw->base);
  170. NVOBJ_ENGINE_ADD(dev, SW, &psw->base.base);
  171. NVOBJ_CLASS(dev, 0x506e, SW);
  172. NVOBJ_MTHD (dev, 0x506e, 0x018c, mthd_dma_vblsem);
  173. NVOBJ_MTHD (dev, 0x506e, 0x0400, mthd_vblsem_offset);
  174. NVOBJ_MTHD (dev, 0x506e, 0x0404, mthd_vblsem_value);
  175. NVOBJ_MTHD (dev, 0x506e, 0x0408, mthd_vblsem_release);
  176. NVOBJ_MTHD (dev, 0x506e, 0x0500, mthd_flip);
  177. return 0;
  178. }