nv50_software.c 5.4 KB

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