base.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. #include "priv.h"
  25. void
  26. nvkm_bar_flush(struct nvkm_bar *bar)
  27. {
  28. if (bar && bar->func->flush)
  29. bar->func->flush(bar);
  30. }
  31. struct nvkm_vmm *
  32. nvkm_bar_bar1_vmm(struct nvkm_device *device)
  33. {
  34. return device->bar->func->bar1.vmm(device->bar);
  35. }
  36. struct nvkm_vmm *
  37. nvkm_bar_bar2_vmm(struct nvkm_device *device)
  38. {
  39. /* Denies access to BAR2 when it's not initialised, used by INSTMEM
  40. * to know when object access needs to go through the BAR0 window.
  41. */
  42. struct nvkm_bar *bar = device->bar;
  43. if (bar && bar->bar2)
  44. return bar->func->bar2.vmm(bar);
  45. return NULL;
  46. }
  47. void
  48. nvkm_bar_bar2_fini(struct nvkm_device *device)
  49. {
  50. struct nvkm_bar *bar = device->bar;
  51. if (bar && bar->bar2) {
  52. bar->func->bar2.fini(bar);
  53. bar->bar2 = false;
  54. }
  55. }
  56. void
  57. nvkm_bar_bar2_init(struct nvkm_device *device)
  58. {
  59. struct nvkm_bar *bar = device->bar;
  60. if (bar && bar->subdev.oneinit && !bar->bar2 && bar->func->bar2.init) {
  61. bar->func->bar2.init(bar);
  62. bar->func->bar2.wait(bar);
  63. bar->bar2 = true;
  64. }
  65. }
  66. static int
  67. nvkm_bar_fini(struct nvkm_subdev *subdev, bool suspend)
  68. {
  69. struct nvkm_bar *bar = nvkm_bar(subdev);
  70. if (bar->func->bar1.fini)
  71. bar->func->bar1.fini(bar);
  72. return 0;
  73. }
  74. static int
  75. nvkm_bar_init(struct nvkm_subdev *subdev)
  76. {
  77. struct nvkm_bar *bar = nvkm_bar(subdev);
  78. bar->func->bar1.init(bar);
  79. bar->func->bar1.wait(bar);
  80. if (bar->func->init)
  81. bar->func->init(bar);
  82. return 0;
  83. }
  84. static int
  85. nvkm_bar_oneinit(struct nvkm_subdev *subdev)
  86. {
  87. struct nvkm_bar *bar = nvkm_bar(subdev);
  88. return bar->func->oneinit(bar);
  89. }
  90. static void *
  91. nvkm_bar_dtor(struct nvkm_subdev *subdev)
  92. {
  93. struct nvkm_bar *bar = nvkm_bar(subdev);
  94. nvkm_bar_bar2_fini(subdev->device);
  95. return bar->func->dtor(bar);
  96. }
  97. static const struct nvkm_subdev_func
  98. nvkm_bar = {
  99. .dtor = nvkm_bar_dtor,
  100. .oneinit = nvkm_bar_oneinit,
  101. .init = nvkm_bar_init,
  102. .fini = nvkm_bar_fini,
  103. };
  104. void
  105. nvkm_bar_ctor(const struct nvkm_bar_func *func, struct nvkm_device *device,
  106. int index, struct nvkm_bar *bar)
  107. {
  108. nvkm_subdev_ctor(&nvkm_bar, device, index, &bar->subdev);
  109. bar->func = func;
  110. spin_lock_init(&bar->lock);
  111. }