base.c 3.3 KB

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