chan.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * Copyright 2015 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 <bskeggs@redhat.com>
  23. */
  24. #include "chan.h"
  25. #include <core/notify.h>
  26. #include <engine/fifo.h>
  27. #include <nvif/event.h>
  28. #include <nvif/unpack.h>
  29. bool
  30. nvkm_sw_chan_mthd(struct nvkm_sw_chan *chan, int subc, u32 mthd, u32 data)
  31. {
  32. switch (mthd) {
  33. case 0x0000:
  34. return true;
  35. case 0x0500:
  36. nvkm_event_send(&chan->event, 1, 0, NULL, 0);
  37. return true;
  38. default:
  39. if (chan->func->mthd)
  40. return chan->func->mthd(chan, subc, mthd, data);
  41. break;
  42. }
  43. return false;
  44. }
  45. static int
  46. nvkm_sw_chan_event_ctor(struct nvkm_object *object, void *data, u32 size,
  47. struct nvkm_notify *notify)
  48. {
  49. union {
  50. struct nvif_notify_uevent_req none;
  51. } *req = data;
  52. int ret = -ENOSYS;
  53. if (!(ret = nvif_unvers(ret, &data, &size, req->none))) {
  54. notify->size = sizeof(struct nvif_notify_uevent_rep);
  55. notify->types = 1;
  56. notify->index = 0;
  57. }
  58. return ret;
  59. }
  60. static const struct nvkm_event_func
  61. nvkm_sw_chan_event = {
  62. .ctor = nvkm_sw_chan_event_ctor,
  63. };
  64. static void *
  65. nvkm_sw_chan_dtor(struct nvkm_object *object)
  66. {
  67. struct nvkm_sw_chan *chan = nvkm_sw_chan(object);
  68. struct nvkm_sw *sw = chan->sw;
  69. unsigned long flags;
  70. void *data = chan;
  71. if (chan->func->dtor)
  72. data = chan->func->dtor(chan);
  73. nvkm_event_fini(&chan->event);
  74. spin_lock_irqsave(&sw->engine.lock, flags);
  75. list_del(&chan->head);
  76. spin_unlock_irqrestore(&sw->engine.lock, flags);
  77. return data;
  78. }
  79. static const struct nvkm_object_func
  80. nvkm_sw_chan = {
  81. .dtor = nvkm_sw_chan_dtor,
  82. };
  83. int
  84. nvkm_sw_chan_ctor(const struct nvkm_sw_chan_func *func, struct nvkm_sw *sw,
  85. struct nvkm_fifo_chan *fifo, const struct nvkm_oclass *oclass,
  86. struct nvkm_sw_chan *chan)
  87. {
  88. unsigned long flags;
  89. nvkm_object_ctor(&nvkm_sw_chan, oclass, &chan->object);
  90. chan->func = func;
  91. chan->sw = sw;
  92. chan->fifo = fifo;
  93. spin_lock_irqsave(&sw->engine.lock, flags);
  94. list_add(&chan->head, &sw->chan);
  95. spin_unlock_irqrestore(&sw->engine.lock, flags);
  96. return nvkm_event_init(&nvkm_sw_chan_event, 1, 1, &chan->event);
  97. }