base.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * Copyright 2014 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 <core/memory.h>
  26. void
  27. nvkm_ltc_tags_clear(struct nvkm_device *device, u32 first, u32 count)
  28. {
  29. struct nvkm_ltc *ltc = device->ltc;
  30. const u32 limit = first + count - 1;
  31. BUG_ON((first > limit) || (limit >= ltc->num_tags));
  32. mutex_lock(&ltc->subdev.mutex);
  33. ltc->func->cbc_clear(ltc, first, limit);
  34. ltc->func->cbc_wait(ltc);
  35. mutex_unlock(&ltc->subdev.mutex);
  36. }
  37. int
  38. nvkm_ltc_zbc_color_get(struct nvkm_ltc *ltc, int index, const u32 color[4])
  39. {
  40. memcpy(ltc->zbc_color[index], color, sizeof(ltc->zbc_color[index]));
  41. ltc->func->zbc_clear_color(ltc, index, color);
  42. return index;
  43. }
  44. int
  45. nvkm_ltc_zbc_depth_get(struct nvkm_ltc *ltc, int index, const u32 depth)
  46. {
  47. ltc->zbc_depth[index] = depth;
  48. ltc->func->zbc_clear_depth(ltc, index, depth);
  49. return index;
  50. }
  51. int
  52. nvkm_ltc_zbc_stencil_get(struct nvkm_ltc *ltc, int index, const u32 stencil)
  53. {
  54. ltc->zbc_stencil[index] = stencil;
  55. ltc->func->zbc_clear_stencil(ltc, index, stencil);
  56. return index;
  57. }
  58. void
  59. nvkm_ltc_invalidate(struct nvkm_ltc *ltc)
  60. {
  61. if (ltc->func->invalidate)
  62. ltc->func->invalidate(ltc);
  63. }
  64. void
  65. nvkm_ltc_flush(struct nvkm_ltc *ltc)
  66. {
  67. if (ltc->func->flush)
  68. ltc->func->flush(ltc);
  69. }
  70. static void
  71. nvkm_ltc_intr(struct nvkm_subdev *subdev)
  72. {
  73. struct nvkm_ltc *ltc = nvkm_ltc(subdev);
  74. ltc->func->intr(ltc);
  75. }
  76. static int
  77. nvkm_ltc_oneinit(struct nvkm_subdev *subdev)
  78. {
  79. struct nvkm_ltc *ltc = nvkm_ltc(subdev);
  80. return ltc->func->oneinit(ltc);
  81. }
  82. static int
  83. nvkm_ltc_init(struct nvkm_subdev *subdev)
  84. {
  85. struct nvkm_ltc *ltc = nvkm_ltc(subdev);
  86. int i;
  87. for (i = ltc->zbc_min; i <= ltc->zbc_max; i++) {
  88. ltc->func->zbc_clear_color(ltc, i, ltc->zbc_color[i]);
  89. ltc->func->zbc_clear_depth(ltc, i, ltc->zbc_depth[i]);
  90. if (ltc->func->zbc_clear_stencil)
  91. ltc->func->zbc_clear_stencil(ltc, i, ltc->zbc_stencil[i]);
  92. }
  93. ltc->func->init(ltc);
  94. return 0;
  95. }
  96. static void *
  97. nvkm_ltc_dtor(struct nvkm_subdev *subdev)
  98. {
  99. struct nvkm_ltc *ltc = nvkm_ltc(subdev);
  100. nvkm_memory_unref(&ltc->tag_ram);
  101. return ltc;
  102. }
  103. static const struct nvkm_subdev_func
  104. nvkm_ltc = {
  105. .dtor = nvkm_ltc_dtor,
  106. .oneinit = nvkm_ltc_oneinit,
  107. .init = nvkm_ltc_init,
  108. .intr = nvkm_ltc_intr,
  109. };
  110. int
  111. nvkm_ltc_new_(const struct nvkm_ltc_func *func, struct nvkm_device *device,
  112. int index, struct nvkm_ltc **pltc)
  113. {
  114. struct nvkm_ltc *ltc;
  115. if (!(ltc = *pltc = kzalloc(sizeof(*ltc), GFP_KERNEL)))
  116. return -ENOMEM;
  117. nvkm_subdev_ctor(&nvkm_ltc, device, index, &ltc->subdev);
  118. ltc->func = func;
  119. ltc->zbc_min = 1; /* reserve 0 for disabled */
  120. ltc->zbc_max = min(func->zbc, NVKM_LTC_MAX_ZBC_CNT) - 1;
  121. return 0;
  122. }