base.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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 "priv.h"
  25. #include <engine/fifo.h>
  26. static bool
  27. nvkm_gr_chsw_load(struct nvkm_engine *engine)
  28. {
  29. struct nvkm_gr *gr = nvkm_gr(engine);
  30. if (gr->func->chsw_load)
  31. return gr->func->chsw_load(gr);
  32. return false;
  33. }
  34. static void
  35. nvkm_gr_tile(struct nvkm_engine *engine, int region, struct nvkm_fb_tile *tile)
  36. {
  37. struct nvkm_gr *gr = nvkm_gr(engine);
  38. if (gr->func->tile)
  39. gr->func->tile(gr, region, tile);
  40. }
  41. u64
  42. nvkm_gr_units(struct nvkm_gr *gr)
  43. {
  44. if (gr->func->units)
  45. return gr->func->units(gr);
  46. return 0;
  47. }
  48. int
  49. nvkm_gr_tlb_flush(struct nvkm_gr *gr)
  50. {
  51. if (gr->func->tlb_flush)
  52. return gr->func->tlb_flush(gr);
  53. return -ENODEV;
  54. }
  55. static int
  56. nvkm_gr_oclass_get(struct nvkm_oclass *oclass, int index)
  57. {
  58. struct nvkm_gr *gr = nvkm_gr(oclass->engine);
  59. int c = 0;
  60. if (gr->func->object_get) {
  61. int ret = gr->func->object_get(gr, index, &oclass->base);
  62. if (oclass->base.oclass)
  63. return index;
  64. return ret;
  65. }
  66. while (gr->func->sclass[c].oclass) {
  67. if (c++ == index) {
  68. oclass->base = gr->func->sclass[index];
  69. return index;
  70. }
  71. }
  72. return c;
  73. }
  74. static int
  75. nvkm_gr_cclass_new(struct nvkm_fifo_chan *chan,
  76. const struct nvkm_oclass *oclass,
  77. struct nvkm_object **pobject)
  78. {
  79. struct nvkm_gr *gr = nvkm_gr(oclass->engine);
  80. if (gr->func->chan_new)
  81. return gr->func->chan_new(gr, chan, oclass, pobject);
  82. return 0;
  83. }
  84. static void
  85. nvkm_gr_intr(struct nvkm_engine *engine)
  86. {
  87. struct nvkm_gr *gr = nvkm_gr(engine);
  88. gr->func->intr(gr);
  89. }
  90. static int
  91. nvkm_gr_oneinit(struct nvkm_engine *engine)
  92. {
  93. struct nvkm_gr *gr = nvkm_gr(engine);
  94. if (gr->func->oneinit)
  95. return gr->func->oneinit(gr);
  96. return 0;
  97. }
  98. static int
  99. nvkm_gr_init(struct nvkm_engine *engine)
  100. {
  101. struct nvkm_gr *gr = nvkm_gr(engine);
  102. return gr->func->init(gr);
  103. }
  104. static int
  105. nvkm_gr_fini(struct nvkm_engine *engine, bool suspend)
  106. {
  107. struct nvkm_gr *gr = nvkm_gr(engine);
  108. if (gr->func->fini)
  109. return gr->func->fini(gr, suspend);
  110. return 0;
  111. }
  112. static void *
  113. nvkm_gr_dtor(struct nvkm_engine *engine)
  114. {
  115. struct nvkm_gr *gr = nvkm_gr(engine);
  116. if (gr->func->dtor)
  117. return gr->func->dtor(gr);
  118. return gr;
  119. }
  120. static const struct nvkm_engine_func
  121. nvkm_gr = {
  122. .dtor = nvkm_gr_dtor,
  123. .oneinit = nvkm_gr_oneinit,
  124. .init = nvkm_gr_init,
  125. .fini = nvkm_gr_fini,
  126. .intr = nvkm_gr_intr,
  127. .tile = nvkm_gr_tile,
  128. .chsw_load = nvkm_gr_chsw_load,
  129. .fifo.cclass = nvkm_gr_cclass_new,
  130. .fifo.sclass = nvkm_gr_oclass_get,
  131. };
  132. int
  133. nvkm_gr_ctor(const struct nvkm_gr_func *func, struct nvkm_device *device,
  134. int index, bool enable, struct nvkm_gr *gr)
  135. {
  136. gr->func = func;
  137. return nvkm_engine_ctor(&nvkm_gr, device, index, enable, &gr->engine);
  138. }