nv04_software.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 "nouveau_hw.h"
  29. struct nv04_software_priv {
  30. struct nouveau_software_priv base;
  31. };
  32. struct nv04_software_chan {
  33. struct nouveau_software_chan base;
  34. };
  35. static int
  36. mthd_fence(struct nouveau_channel *chan, u32 class, u32 mthd, u32 data)
  37. {
  38. atomic_set(&chan->fence.last_sequence_irq, data);
  39. return 0;
  40. }
  41. static int
  42. mthd_flip(struct nouveau_channel *chan, u32 class, u32 mthd, u32 data)
  43. {
  44. struct nouveau_page_flip_state state;
  45. if (!nouveau_finish_page_flip(chan, &state)) {
  46. nv_set_crtc_base(chan->dev, state.crtc, state.offset +
  47. state.y * state.pitch +
  48. state.x * state.bpp / 8);
  49. }
  50. return 0;
  51. }
  52. static int
  53. nv04_software_context_new(struct nouveau_channel *chan, int engine)
  54. {
  55. struct nv04_software_chan *pch;
  56. pch = kzalloc(sizeof(*pch), GFP_KERNEL);
  57. if (!pch)
  58. return -ENOMEM;
  59. nouveau_software_context_new(&pch->base);
  60. atomic_set(&chan->fence.last_sequence_irq, 0);
  61. chan->engctx[engine] = pch;
  62. return 0;
  63. }
  64. static void
  65. nv04_software_context_del(struct nouveau_channel *chan, int engine)
  66. {
  67. struct nv04_software_chan *pch = chan->engctx[engine];
  68. chan->engctx[engine] = NULL;
  69. kfree(pch);
  70. }
  71. static int
  72. nv04_software_object_new(struct nouveau_channel *chan, int engine,
  73. u32 handle, u16 class)
  74. {
  75. struct drm_device *dev = chan->dev;
  76. struct nouveau_gpuobj *obj = NULL;
  77. int ret;
  78. ret = nouveau_gpuobj_new(dev, chan, 16, 16, 0, &obj);
  79. if (ret)
  80. return ret;
  81. obj->engine = 0;
  82. obj->class = class;
  83. ret = nouveau_ramht_insert(chan, handle, obj);
  84. nouveau_gpuobj_ref(NULL, &obj);
  85. return ret;
  86. }
  87. static int
  88. nv04_software_init(struct drm_device *dev, int engine)
  89. {
  90. return 0;
  91. }
  92. static int
  93. nv04_software_fini(struct drm_device *dev, int engine, bool suspend)
  94. {
  95. return 0;
  96. }
  97. static void
  98. nv04_software_destroy(struct drm_device *dev, int engine)
  99. {
  100. struct nv04_software_priv *psw = nv_engine(dev, engine);
  101. NVOBJ_ENGINE_DEL(dev, SW);
  102. kfree(psw);
  103. }
  104. int
  105. nv04_software_create(struct drm_device *dev)
  106. {
  107. struct drm_nouveau_private *dev_priv = dev->dev_private;
  108. struct nv04_software_priv *psw;
  109. psw = kzalloc(sizeof(*psw), GFP_KERNEL);
  110. if (!psw)
  111. return -ENOMEM;
  112. psw->base.base.destroy = nv04_software_destroy;
  113. psw->base.base.init = nv04_software_init;
  114. psw->base.base.fini = nv04_software_fini;
  115. psw->base.base.context_new = nv04_software_context_new;
  116. psw->base.base.context_del = nv04_software_context_del;
  117. psw->base.base.object_new = nv04_software_object_new;
  118. nouveau_software_create(&psw->base);
  119. NVOBJ_ENGINE_ADD(dev, SW, &psw->base.base);
  120. if (dev_priv->card_type <= NV_04) {
  121. NVOBJ_CLASS(dev, 0x006e, SW);
  122. NVOBJ_MTHD (dev, 0x006e, 0x0150, mthd_fence);
  123. NVOBJ_MTHD (dev, 0x006e, 0x0500, mthd_flip);
  124. } else {
  125. NVOBJ_CLASS(dev, 0x016e, SW);
  126. NVOBJ_MTHD (dev, 0x016e, 0x0500, mthd_flip);
  127. }
  128. return 0;
  129. }