dmacnv50.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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 "dmacnv50.h"
  25. #include "rootnv50.h"
  26. #include <core/client.h>
  27. #include <core/oproxy.h>
  28. #include <core/ramht.h>
  29. #include <subdev/fb.h>
  30. #include <subdev/timer.h>
  31. #include <engine/dma.h>
  32. struct nv50_disp_dmac_object {
  33. struct nvkm_oproxy oproxy;
  34. struct nv50_disp_root *root;
  35. int hash;
  36. };
  37. static void
  38. nv50_disp_dmac_child_del_(struct nvkm_oproxy *base)
  39. {
  40. struct nv50_disp_dmac_object *object =
  41. container_of(base, typeof(*object), oproxy);
  42. nvkm_ramht_remove(object->root->ramht, object->hash);
  43. }
  44. static const struct nvkm_oproxy_func
  45. nv50_disp_dmac_child_func_ = {
  46. .dtor[0] = nv50_disp_dmac_child_del_,
  47. };
  48. static int
  49. nv50_disp_dmac_child_new_(struct nv50_disp_chan *base,
  50. const struct nvkm_oclass *oclass,
  51. void *data, u32 size, struct nvkm_object **pobject)
  52. {
  53. struct nv50_disp_dmac *chan = nv50_disp_dmac(base);
  54. struct nv50_disp_root *root = chan->base.root;
  55. struct nvkm_device *device = root->disp->base.engine.subdev.device;
  56. const struct nvkm_device_oclass *sclass = oclass->priv;
  57. struct nv50_disp_dmac_object *object;
  58. int ret;
  59. if (!(object = kzalloc(sizeof(*object), GFP_KERNEL)))
  60. return -ENOMEM;
  61. nvkm_oproxy_ctor(&nv50_disp_dmac_child_func_, oclass, &object->oproxy);
  62. object->root = root;
  63. *pobject = &object->oproxy.base;
  64. ret = sclass->ctor(device, oclass, data, size, &object->oproxy.object);
  65. if (ret)
  66. return ret;
  67. object->hash = chan->func->bind(chan, object->oproxy.object,
  68. oclass->handle);
  69. if (object->hash < 0)
  70. return object->hash;
  71. return 0;
  72. }
  73. static int
  74. nv50_disp_dmac_child_get_(struct nv50_disp_chan *base, int index,
  75. struct nvkm_oclass *sclass)
  76. {
  77. struct nv50_disp_dmac *chan = nv50_disp_dmac(base);
  78. struct nv50_disp *disp = chan->base.root->disp;
  79. struct nvkm_device *device = disp->base.engine.subdev.device;
  80. const struct nvkm_device_oclass *oclass = NULL;
  81. sclass->engine = nvkm_device_engine(device, NVKM_ENGINE_DMAOBJ);
  82. if (sclass->engine && sclass->engine->func->base.sclass) {
  83. sclass->engine->func->base.sclass(sclass, index, &oclass);
  84. if (oclass) {
  85. sclass->priv = oclass;
  86. return 0;
  87. }
  88. }
  89. return -EINVAL;
  90. }
  91. static void
  92. nv50_disp_dmac_fini_(struct nv50_disp_chan *base)
  93. {
  94. struct nv50_disp_dmac *chan = nv50_disp_dmac(base);
  95. chan->func->fini(chan);
  96. }
  97. static int
  98. nv50_disp_dmac_init_(struct nv50_disp_chan *base)
  99. {
  100. struct nv50_disp_dmac *chan = nv50_disp_dmac(base);
  101. return chan->func->init(chan);
  102. }
  103. static void *
  104. nv50_disp_dmac_dtor_(struct nv50_disp_chan *base)
  105. {
  106. return nv50_disp_dmac(base);
  107. }
  108. static const struct nv50_disp_chan_func
  109. nv50_disp_dmac_func_ = {
  110. .dtor = nv50_disp_dmac_dtor_,
  111. .init = nv50_disp_dmac_init_,
  112. .fini = nv50_disp_dmac_fini_,
  113. .child_get = nv50_disp_dmac_child_get_,
  114. .child_new = nv50_disp_dmac_child_new_,
  115. };
  116. int
  117. nv50_disp_dmac_new_(const struct nv50_disp_dmac_func *func,
  118. const struct nv50_disp_chan_mthd *mthd,
  119. struct nv50_disp_root *root, int chid, int head, u64 push,
  120. const struct nvkm_oclass *oclass,
  121. struct nvkm_object **pobject)
  122. {
  123. struct nvkm_device *device = root->disp->base.engine.subdev.device;
  124. struct nvkm_client *client = oclass->client;
  125. struct nvkm_dmaobj *dmaobj;
  126. struct nv50_disp_dmac *chan;
  127. int ret;
  128. if (!(chan = kzalloc(sizeof(*chan), GFP_KERNEL)))
  129. return -ENOMEM;
  130. *pobject = &chan->base.object;
  131. chan->func = func;
  132. ret = nv50_disp_chan_ctor(&nv50_disp_dmac_func_, mthd, root,
  133. chid, chid, head, oclass, &chan->base);
  134. if (ret)
  135. return ret;
  136. dmaobj = nvkm_dma_search(device->dma, client, push);
  137. if (!dmaobj)
  138. return -ENOENT;
  139. if (dmaobj->limit - dmaobj->start != 0xfff)
  140. return -EINVAL;
  141. switch (dmaobj->target) {
  142. case NV_MEM_TARGET_VRAM:
  143. chan->push = 0x00000001 | dmaobj->start >> 8;
  144. break;
  145. case NV_MEM_TARGET_PCI_NOSNOOP:
  146. chan->push = 0x00000003 | dmaobj->start >> 8;
  147. break;
  148. default:
  149. return -EINVAL;
  150. }
  151. return 0;
  152. }
  153. int
  154. nv50_disp_dmac_bind(struct nv50_disp_dmac *chan,
  155. struct nvkm_object *object, u32 handle)
  156. {
  157. return nvkm_ramht_insert(chan->base.root->ramht, object,
  158. chan->base.chid.user, -10, handle,
  159. chan->base.chid.user << 28 |
  160. chan->base.chid.user);
  161. }
  162. static void
  163. nv50_disp_dmac_fini(struct nv50_disp_dmac *chan)
  164. {
  165. struct nv50_disp *disp = chan->base.root->disp;
  166. struct nvkm_subdev *subdev = &disp->base.engine.subdev;
  167. struct nvkm_device *device = subdev->device;
  168. int ctrl = chan->base.chid.ctrl;
  169. int user = chan->base.chid.user;
  170. /* deactivate channel */
  171. nvkm_mask(device, 0x610200 + (ctrl * 0x0010), 0x00001010, 0x00001000);
  172. nvkm_mask(device, 0x610200 + (ctrl * 0x0010), 0x00000003, 0x00000000);
  173. if (nvkm_msec(device, 2000,
  174. if (!(nvkm_rd32(device, 0x610200 + (ctrl * 0x10)) & 0x001e0000))
  175. break;
  176. ) < 0) {
  177. nvkm_error(subdev, "ch %d fini timeout, %08x\n", user,
  178. nvkm_rd32(device, 0x610200 + (ctrl * 0x10)));
  179. }
  180. /* disable error reporting and completion notifications */
  181. nvkm_mask(device, 0x610028, 0x00010001 << user, 0x00000000 << user);
  182. }
  183. static int
  184. nv50_disp_dmac_init(struct nv50_disp_dmac *chan)
  185. {
  186. struct nv50_disp *disp = chan->base.root->disp;
  187. struct nvkm_subdev *subdev = &disp->base.engine.subdev;
  188. struct nvkm_device *device = subdev->device;
  189. int ctrl = chan->base.chid.ctrl;
  190. int user = chan->base.chid.user;
  191. /* enable error reporting */
  192. nvkm_mask(device, 0x610028, 0x00010000 << user, 0x00010000 << user);
  193. /* initialise channel for dma command submission */
  194. nvkm_wr32(device, 0x610204 + (ctrl * 0x0010), chan->push);
  195. nvkm_wr32(device, 0x610208 + (ctrl * 0x0010), 0x00010000);
  196. nvkm_wr32(device, 0x61020c + (ctrl * 0x0010), ctrl);
  197. nvkm_mask(device, 0x610200 + (ctrl * 0x0010), 0x00000010, 0x00000010);
  198. nvkm_wr32(device, 0x640000 + (ctrl * 0x1000), 0x00000000);
  199. nvkm_wr32(device, 0x610200 + (ctrl * 0x0010), 0x00000013);
  200. /* wait for it to go inactive */
  201. if (nvkm_msec(device, 2000,
  202. if (!(nvkm_rd32(device, 0x610200 + (ctrl * 0x10)) & 0x80000000))
  203. break;
  204. ) < 0) {
  205. nvkm_error(subdev, "ch %d init timeout, %08x\n", user,
  206. nvkm_rd32(device, 0x610200 + (ctrl * 0x10)));
  207. return -EBUSY;
  208. }
  209. return 0;
  210. }
  211. const struct nv50_disp_dmac_func
  212. nv50_disp_dmac_func = {
  213. .init = nv50_disp_dmac_init,
  214. .fini = nv50_disp_dmac_fini,
  215. .bind = nv50_disp_dmac_bind,
  216. };