nv04.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. #define nv04_sw_chan(p) container_of((p), struct nv04_sw_chan, base)
  25. #include "priv.h"
  26. #include "chan.h"
  27. #include "nvsw.h"
  28. #include <nvif/class.h>
  29. #include <nvif/ioctl.h>
  30. #include <nvif/unpack.h>
  31. struct nv04_sw_chan {
  32. struct nvkm_sw_chan base;
  33. atomic_t ref;
  34. };
  35. /*******************************************************************************
  36. * software object classes
  37. ******************************************************************************/
  38. static int
  39. nv04_nvsw_mthd_get_ref(struct nvkm_nvsw *nvsw, void *data, u32 size)
  40. {
  41. struct nv04_sw_chan *chan = nv04_sw_chan(nvsw->chan);
  42. union {
  43. struct nv04_nvsw_get_ref_v0 v0;
  44. } *args = data;
  45. int ret;
  46. if (nvif_unpack(args->v0, 0, 0, false)) {
  47. args->v0.ref = atomic_read(&chan->ref);
  48. }
  49. return ret;
  50. }
  51. static int
  52. nv04_nvsw_mthd(struct nvkm_nvsw *nvsw, u32 mthd, void *data, u32 size)
  53. {
  54. switch (mthd) {
  55. case NV04_NVSW_GET_REF:
  56. return nv04_nvsw_mthd_get_ref(nvsw, data, size);
  57. default:
  58. break;
  59. }
  60. return -EINVAL;
  61. }
  62. static const struct nvkm_nvsw_func
  63. nv04_nvsw = {
  64. .mthd = nv04_nvsw_mthd,
  65. };
  66. static int
  67. nv04_nvsw_new(struct nvkm_sw_chan *chan, const struct nvkm_oclass *oclass,
  68. void *data, u32 size, struct nvkm_object **pobject)
  69. {
  70. return nvkm_nvsw_new_(&nv04_nvsw, chan, oclass, data, size, pobject);
  71. }
  72. /*******************************************************************************
  73. * software context
  74. ******************************************************************************/
  75. static bool
  76. nv04_sw_chan_mthd(struct nvkm_sw_chan *base, int subc, u32 mthd, u32 data)
  77. {
  78. struct nv04_sw_chan *chan = nv04_sw_chan(base);
  79. switch (mthd) {
  80. case 0x0150:
  81. atomic_set(&chan->ref, data);
  82. return true;
  83. default:
  84. break;
  85. }
  86. return false;
  87. }
  88. static const struct nvkm_sw_chan_func
  89. nv04_sw_chan = {
  90. .mthd = nv04_sw_chan_mthd,
  91. };
  92. static int
  93. nv04_sw_chan_new(struct nvkm_sw *sw, struct nvkm_fifo_chan *fifo,
  94. const struct nvkm_oclass *oclass, struct nvkm_object **pobject)
  95. {
  96. struct nv04_sw_chan *chan;
  97. if (!(chan = kzalloc(sizeof(*chan), GFP_KERNEL)))
  98. return -ENOMEM;
  99. atomic_set(&chan->ref, 0);
  100. *pobject = &chan->base.object;
  101. return nvkm_sw_chan_ctor(&nv04_sw_chan, sw, fifo, oclass, &chan->base);
  102. }
  103. /*******************************************************************************
  104. * software engine/subdev functions
  105. ******************************************************************************/
  106. static const struct nvkm_sw_func
  107. nv04_sw = {
  108. .chan_new = nv04_sw_chan_new,
  109. .sclass = {
  110. { nv04_nvsw_new, { -1, -1, NVIF_IOCTL_NEW_V0_SW_NV04 } },
  111. {}
  112. }
  113. };
  114. int
  115. nv04_sw_new(struct nvkm_device *device, int index, struct nvkm_sw **psw)
  116. {
  117. return nvkm_sw_new_(&nv04_sw, device, index, psw);
  118. }