base.c 3.7 KB

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